home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************
- * *
- * file: cdrom.c *
- * *
- *************************************************************/
-
- /*
- * Copyright (C) 1988, 1989 Sun Microsystems, Inc.
- */
-
- #ifndef lint
- static char sccsid[] = "@(#)cdrom.c 1.4 89/12/05 Copyr 1989 Sun Microsystem, Inc.";
- #endif
-
- /*
- * This file contains the routine to interface with the cdrom player.
- */
-
- #include <stdio.h>
- #include <sys/file.h>
- #include <sys/types.h>
- #include <sys/param.h>
- #include <sys/stat.h>
- #include <mntent.h>
- #include <string.h>
- #include <sun/dkio.h>
-
- #include <sys/buf.h>
- #ifdef sun4c
- #include <scsi/targets/srdef.h>
- #else
- #include <sundev/srreg.h>
- #endif
-
- #include <sys/time.h>
-
- #include "cdrom.h"
-
- int
- cdrom_get_relinfo(fd, track, min, sec, frame)
- int fd;
- int *track, *min, *sec, *frame;
- {
- struct cdrom_subchnl sc;
-
- sc.cdsc_format = CDROM_MSF;
- if (ioctl(fd, CDROMSUBCHNL, (struct cdrom_subchnl *)&sc) < 0) {
- return 0;
- }
- *track = sc.cdsc_trk;
- *min = sc.cdsc_reladdr.msf.minute;
- *sec = sc.cdsc_reladdr.msf.second;
- *frame = sc.cdsc_reladdr.msf.frame;
- return 1;
- }
-
- int
- cdrom_get_absinfo(fd, track, min, sec, frame)
- int fd;
- int *track, *min, *sec, *frame;
- {
- struct cdrom_subchnl sc;
-
- sc.cdsc_format = CDROM_MSF;
- if (ioctl(fd, CDROMSUBCHNL, (struct cdrom_subchnl *)&sc) < 0) {
- return 0;
- }
- *track = sc.cdsc_trk;
- *min = sc.cdsc_absaddr.msf.minute;
- *sec = sc.cdsc_absaddr.msf.second;
- *frame = sc.cdsc_absaddr.msf.frame;
- return 1;
- }
-
- int
- cdrom_play_msf(fd, msf)
- int fd;
- struct cdrom_msf msf;
- {
- if (ioctl(fd, CDROMPLAYMSF, (struct cdrom_msf *) &msf) < 0) {
- return 0;
- }
- return 1;
- }
-
- int
- cdrom_play_track(fd, play_track, end_track)
- int fd;
- int play_track;
- int end_track;
- {
- struct cdrom_ti ti;
-
- ti.cdti_trk0 = play_track;
- ti.cdti_ind0 = 1;
- ti.cdti_trk1 = end_track;
- ti.cdti_ind1 = 1;
- if (ioctl(fd, CDROMPLAYTRKIND, (struct cdrom_ti *)&ti) < 0) {
- return 0;
- }
- return 1;
- }
-
- int
- cdrom_start(fd)
- int fd;
- {
- if (ioctl(fd, CDROMSTART) < 0) {
- return 0;
- }
- return 1;
- }
-
- int
- cdrom_stop(fd)
- int fd;
- {
- if (ioctl(fd, CDROMSTOP) < 0) {
- return 0;
- }
- return 1;
- }
-
- int
- cdrom_eject(fd)
- int fd;
- {
- if (ioctl(fd, CDROMEJECT) < 0) {
- return 0;
- }
- return 1;
- }
-
- int
- cdrom_read_tocentry(fd, entry)
- int fd;
- struct cdrom_tocentry *entry;
- {
- if (ioctl(fd, CDROMREADTOCENTRY, entry) < 0) {
- return 0;
- }
- return 1;
- }
-
- int
- cdrom_read_tochdr(fd, hdr)
- int fd;
- struct cdrom_tochdr *hdr;
- {
- if (ioctl(fd, CDROMREADTOCHDR, hdr) < 0) {
- return 0;
- }
- return 1;
- }
-
- int
- cdrom_pause(fd)
- int fd;
- {
- if (ioctl(fd, CDROMPAUSE) < 0) {
- return 0;
- }
- return 1;
- }
-
- int
- cdrom_resume(fd)
- int fd;
- {
- if (ioctl(fd, CDROMRESUME) < 0) {
- return 0;
- }
- return 1;
- }
-
- int
- cdrom_volume(fd, left_vol, right_vol)
- int fd;
- int left_vol;
- int right_vol;
- {
- struct cdrom_volctrl vol;
-
- vol.channel0 = left_vol;
- vol.channel1 = right_vol;
- if (ioctl(fd, CDROMVOLCTRL, (struct cdrom_volctrl *)&vol) < 0) {
- return 0;
- }
- return 1;
- }
-
- int
- cdrom_get_relmsf(fd, tmp)
- int fd;
- struct tm *tmp;
- {
- struct cdrom_subchnl sc;
-
- sc.cdsc_format = CDROM_MSF;
- if (ioctl(fd, CDROMSUBCHNL, (struct cdrom_subchnl *)&sc) < 0) {
- return 0;
- }
- tmp->tm_sec = sc.cdsc_reladdr.msf.second;
- tmp->tm_min = sc.cdsc_reladdr.msf.minute;
- return 1;
- }
-
- int
- cdrom_playing(fd, track)
- int fd;
- int *track;
- {
- struct cdrom_subchnl sc;
-
- sc.cdsc_format = CDROM_MSF;
- if (ioctl(fd, CDROMSUBCHNL, (struct cdrom_subchnl *)&sc) < 0) {
- return 0;
- }
- *track = sc.cdsc_trk;
- if (sc.cdsc_audiostatus == CDROM_AUDIO_PLAY) {
- return 1;
- }
- else {
- return 0;
- }
- }
-
- int
- cdrom_paused(fd, track)
- int fd;
- int *track;
- {
- struct cdrom_subchnl sc;
-
- sc.cdsc_format = CDROM_MSF;
- if (ioctl(fd, CDROMSUBCHNL, (struct cdrom_subchnl *)&sc) < 0) {
- return 0;
- }
- *track = sc.cdsc_trk;
- printf("in pause, status is %d\n", sc.cdsc_audiostatus);
- if (sc.cdsc_audiostatus == CDROM_AUDIO_PAUSED) {
- return 1;
- }
- else {
- return 0;
- }
- }
-
- int
- mounted(rawd)
- char *rawd;
- {
- char buf[MAXPATHLEN], *cp;
- struct stat st;
- dev_t bdevno;
- FILE *fp;
- struct mntent *mnt;
-
- /*
- * Get the block device corresponding to the raw device opened,
- * and find its device number.
- */
- if (stat(rawd, &st) != 0) {
- (void)fprintf(stderr, "Couldn't stat \"%s\": ", rawd);
- perror("");
- return (UNMOUNTED);
- }
- /*
- * If this is a raw device, we have to build the block device name.
- */
- if ((st.st_mode & S_IFMT) == S_IFCHR) {
- cp = strchr(rawd, 'r');
- cp = (cp == NULL) ? NULL : ++cp;
- (void)sprintf(buf, "/dev/%s", cp);
- if (stat(buf, &st) != 0) {
- (void)fprintf(stderr, "Couldn't stat \"%s\": ", buf);
- perror("");
- return (UNMOUNTED);
- }
- }
- if ((st.st_mode & S_IFMT) != S_IFBLK) {
- /*
- * What is this thing? Ferget it!
- */
- return (UNMOUNTED);
- }
- bdevno = st.st_rdev & (dev_t)(~0x07); /* Mask out partition. */
-
- /*
- * Now go through the mtab, looking at all hsfs filesystems.
- * Compare the device mounted with our bdevno.
- */
- if ((fp = setmntent(MOUNTED, "r")) == NULL) {
- (void)fprintf(stderr, "Couldn't open \"%s\"\n", MOUNTED);
- return (UNMOUNTED);
- }
- while ((mnt = getmntent(fp)) != NULL) {
- /* avoid obvious excess stat(2)'s */
- if (strcmp(mnt->mnt_type, "hsfs") != 0) {
- continue;
- }
- if (stat(mnt->mnt_fsname, &st) != 0) {
- continue;
- }
- if (((st.st_mode & S_IFMT) == S_IFBLK) &&
- ((st.st_rdev & (dev_t)(~0x07)) == bdevno)) {
- (void)endmntent(fp);
- return (STILL_MOUNTED);
- }
- }
- (void)endmntent(fp);
- return (UNMOUNTED);
- }
-