src/cdrom/osf/SDL_syscdrom.c
changeset 873 89666943c598
parent 654 e92bcf2573cb
child 874 9719e7f51a3a
     1.1 --- a/src/cdrom/osf/SDL_syscdrom.c	Sat Mar 06 02:58:06 2004 +0000
     1.2 +++ b/src/cdrom/osf/SDL_syscdrom.c	Sun Mar 07 16:40:15 2004 +0000
     1.3 @@ -59,46 +59,45 @@
     1.4  static int         SDL_SYS_CDEject(SDL_CD *cdrom);
     1.5  static void        SDL_SYS_CDClose(SDL_CD *cdrom);
     1.6  
     1.7 -/* Some ioctl() errno values which occur when the tray is empty */
     1.8 -#define ERRNO_TRAYEMPTY(errno)	\
     1.9 -    ((errno == EIO) || (errno == ENOENT) || (errno == EINVAL))
    1.10 -
    1.11  /* Check a drive to see if it is a CD-ROM */
    1.12  /* Caution!! Not tested. */ 
    1.13  static int CheckDrive(char *drive, struct stat *stbuf)
    1.14  {
    1.15 -    int is_cd, cdfd;
    1.16 -    struct cd_sub_channel info;
    1.17 +    int cdfd, is_cd = 0;
    1.18 +    struct mode_sel_sns_params msp;
    1.19 +    struct inquiry_info inq;
    1.20 +
    1.21 +#ifdef DEBUG_CDROM
    1.22 +    char *devtype[] = {"Disk", "Tape", "Printer", "Processor", "WORM",
    1.23 +	"CD-ROM", "Scanner", "Optical", "Changer", "Comm", "Unknown"};
    1.24 +#endif
    1.25 +
    1.26 +    bzero(&msp, sizeof(msp));
    1.27 +    bzero(&inq, sizeof(inq));
    1.28  
    1.29      /* If it doesn't exist, return -1 */
    1.30      if ( stat(drive, stbuf) < 0 ) {
    1.31  	return(-1);
    1.32      }
    1.33  
    1.34 -    /* If it does exist, verify that it's an available CD-ROM */
    1.35 -    is_cd = 0;
    1.36 -    if ( S_ISCHR(stbuf->st_mode) || S_ISBLK(stbuf->st_mode) ) {
    1.37 -	cdfd = open(drive, (O_RDWR|O_NDELAY), 0);
    1.38 -	if ( cdfd >= 0 ) {
    1.39 -	    info.sch_address_format = CDROM_MSF_FORMAT;
    1.40 -	    info.sch_data_format = CDROM_CURRENT_POSITION;
    1.41 -	    info.sch_alloc_length = 0;
    1.42 -	    info.sch_track_number = 0;
    1.43 -	    info.sch_buffer = NULL;
    1.44 -	    /*
    1.45 -	     *
    1.46 -	     * Under Linux, EIO occurs when a disk is not present.
    1.47 -	     * This isn't 100% reliable, so we use the USE_MNTENT
    1.48 -	     * code above instead.
    1.49 -	     *
    1.50 -	     */
    1.51 -	    if ( (ioctl(cdfd, CDROM_READ_SUBCHANNEL, &info) == 0) ||
    1.52 -		    ERRNO_TRAYEMPTY(errno) ) {
    1.53 -		is_cd = 1;
    1.54 -	    }
    1.55 +    if ( (cdfd = open(drive, (O_RDWR|O_NDELAY), 0)) >= 0 ) {
    1.56 +	msp.msp_addr   =   (caddr_t) &inq;
    1.57 +	msp.msp_pgcode =                0;
    1.58 +	msp.msp_pgctrl =                0;
    1.59 +	msp.msp_length =      sizeof(inq);
    1.60 +	msp.msp_setps  =                0;
    1.61  
    1.62 -	    close(cdfd);
    1.63 -	}
    1.64 +	if ( ioctl(cdfd, SCSI_GET_INQUIRY_DATA, &msp) )
    1.65 +	    return (0);
    1.66 +
    1.67 +#ifdef DEBUG_CDROM
    1.68 +	fprintf(stderr, "Device Type: %s\n", devtype[inq.perfdt]);
    1.69 +	fprintf(stderr, "Vendor: %.8s\n", inq.vndrid);
    1.70 +	fprintf(stderr, "Product: %.8s\n", inq.prodid);
    1.71 +	fprintf(stderr, "Revision: %.8s\n", inq.revlvl);
    1.72 +#endif
    1.73 +	if ( inq.perfdt == DTYPE_RODIRECT )
    1.74 +	    is_cd = 1;
    1.75      }
    1.76  
    1.77      return(is_cd);
    1.78 @@ -113,7 +112,7 @@
    1.79  	/* Check to make sure it's not already in our list.
    1.80  	 * This can happen when we see a drive via symbolic link.
    1.81  	 *
    1.82 -	 * /
    1.83 +	 */
    1.84  	for ( i=0; i<SDL_numcds; ++i ) {
    1.85  	    if ( stbuf->st_rdev == SDL_cdmode[i] ) {
    1.86  #ifdef DEBUG_CDROM
    1.87 @@ -142,8 +141,7 @@
    1.88  
    1.89  int  SDL_SYS_CDInit(void)
    1.90  {
    1.91 -    /* checklist: /dev/cdrom,/dev/cd?c /dev/acd?c
    1.92 -     * /dev/matcd?c /dev/mcd?c /dev/scd?c
    1.93 +    /* checklist: /dev/rdisk/cdrom?c
    1.94       *
    1.95       */
    1.96      static char *checklist[] = {
    1.97 @@ -287,28 +285,28 @@
    1.98  	return -1;
    1.99      }
   1.100  
   1.101 -    (char *)cdte = toc.toc_buffer + sizeof(hdr);
   1.102 -	for (i=0; i <= cdrom->numtracks; ++i) {
   1.103 -	    if (i == cdrom->numtracks ) {
   1.104 -		cdrom->track[i].id = 0xAA;;
   1.105 -	    } else {
   1.106 -		cdrom->track[i].id = hdr.th_starting_track + i;
   1.107 -	    }
   1.108 +    cdte =(struct cd_toc_entry *) ((char *) toc.toc_buffer + sizeof(hdr));
   1.109 +    for (i=0; i <= cdrom->numtracks; ++i) {
   1.110 +	if (i == cdrom->numtracks ) {
   1.111 +	    cdrom->track[i].id = 0xAA;;
   1.112 +	} else {
   1.113 +	    cdrom->track[i].id = hdr.th_starting_track + i;
   1.114 +	}
   1.115  
   1.116 -	    cdrom->track[i].type =
   1.117 -		cdte[i].te_control & CDROM_DATA_TRACK;
   1.118 -	    cdrom->track[i].offset =
   1.119 -		cdte[i].te_absaddr.lba.addr3 << 24 |
   1.120 -		cdte[i].te_absaddr.lba.addr2 << 16 |
   1.121 -		cdte[i].te_absaddr.lba.addr1 << 8  |
   1.122 -		cdte[i].te_absaddr.lba.addr0;
   1.123 -	    cdrom->track[i].length = 0;
   1.124 -	    if ( i > 0 ) {
   1.125 -		cdrom->track[i - 1].length =
   1.126 -		    cdrom->track[i].offset -
   1.127 -		    cdrom->track[i - 1].offset;
   1.128 -	    }
   1.129 +	cdrom->track[i].type =
   1.130 +	    cdte[i].te_control & CDROM_DATA_TRACK;
   1.131 +	cdrom->track[i].offset =
   1.132 +	    cdte[i].te_absaddr.lba.addr3 << 24 |
   1.133 +	    cdte[i].te_absaddr.lba.addr2 << 16 |
   1.134 +	    cdte[i].te_absaddr.lba.addr1 << 8  |
   1.135 +	    cdte[i].te_absaddr.lba.addr0;
   1.136 +	cdrom->track[i].length = 0;
   1.137 +	if ( i > 0 ) {
   1.138 +	    cdrom->track[i - 1].length =
   1.139 +		cdrom->track[i].offset -
   1.140 +		cdrom->track[i - 1].offset;
   1.141  	}
   1.142 +    }
   1.143  #ifdef DEBUG_CDROM
   1.144    for (i = 0; i <= cdrom->numtracks; i++) {
   1.145      fprintf(stderr,"toc_entry[%d].te_track_number = %d\n",
   1.146 @@ -388,13 +386,14 @@
   1.147  /* Start play */
   1.148  static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length)
   1.149  {
   1.150 -/* Play MSF
   1.151 - *
   1.152 +/*
   1.153 + * Play MSF
   1.154   */
   1.155      struct cd_play_audio_msf msf;
   1.156      int end;
   1.157  
   1.158      bzero(&msf, sizeof(msf));
   1.159 +    start += 150; /* Some CD-ROM drives cannot play the first 150 frames. */
   1.160      end = start +length;
   1.161      FRAMES_TO_MSF(start,
   1.162  		  &msf.msf_starting_M_unit,
   1.163 @@ -450,4 +449,3 @@
   1.164      }
   1.165  }
   1.166  
   1.167 -