src/cdrom/bsdi/SDL_syscdrom.c
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1635 92947e3a18db
child 1668 4da1ee79c9af
     1.1 --- a/src/cdrom/bsdi/SDL_syscdrom.c	Sun May 21 17:27:13 2006 +0000
     1.2 +++ b/src/cdrom/bsdi/SDL_syscdrom.c	Sun May 28 13:04:16 2006 +0000
     1.3 @@ -52,491 +52,501 @@
     1.4  #define	FRAMES_PER_MINUTE	(FRAMES_PER_SECOND * 60)
     1.5  
     1.6  int
     1.7 -msf_to_frame(int minute, int second, int frame)
     1.8 -	{
     1.9 -	return(minute * FRAMES_PER_MINUTE + second * FRAMES_PER_SECOND + frame);
    1.10 -	}
    1.11 +msf_to_frame (int minute, int second, int frame)
    1.12 +{
    1.13 +    return (minute * FRAMES_PER_MINUTE + second * FRAMES_PER_SECOND + frame);
    1.14 +}
    1.15  
    1.16  void
    1.17 -frame_to_msf(int frame, int *minp, int *secp, int *framep)
    1.18 -	{
    1.19 -	*minp = frame / FRAMES_PER_MINUTE;
    1.20 -	*secp = (frame % FRAMES_PER_MINUTE) / FRAMES_PER_SECOND;
    1.21 -	*framep = frame % FRAMES_PER_SECOND;
    1.22 -	}
    1.23 +frame_to_msf (int frame, int *minp, int *secp, int *framep)
    1.24 +{
    1.25 +    *minp = frame / FRAMES_PER_MINUTE;
    1.26 +    *secp = (frame % FRAMES_PER_MINUTE) / FRAMES_PER_SECOND;
    1.27 +    *framep = frame % FRAMES_PER_SECOND;
    1.28 +}
    1.29  
    1.30  /* The maximum number of CD-ROM drives we'll detect */
    1.31 -#define MAX_DRIVES	16	
    1.32 +#define MAX_DRIVES	16
    1.33  
    1.34  /* A list of available CD-ROM drives */
    1.35  static char *SDL_cdlist[MAX_DRIVES];
    1.36  static dev_t SDL_cdmode[MAX_DRIVES];
    1.37  
    1.38  /* The system-dependent CD control functions */
    1.39 -static const char *SDL_SYS_CDName(int drive);
    1.40 -static int SDL_SYS_CDOpen(int drive);
    1.41 -static int SDL_SYS_CDGetTOC(SDL_CD *cdrom);
    1.42 -static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position);
    1.43 -static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length);
    1.44 -static int SDL_SYS_CDPause(SDL_CD *cdrom);
    1.45 -static int SDL_SYS_CDResume(SDL_CD *cdrom);
    1.46 -static int SDL_SYS_CDStop(SDL_CD *cdrom);
    1.47 -static int SDL_SYS_CDEject(SDL_CD *cdrom);
    1.48 -static void SDL_SYS_CDClose(SDL_CD *cdrom);
    1.49 +static const char *SDL_SYS_CDName (int drive);
    1.50 +static int SDL_SYS_CDOpen (int drive);
    1.51 +static int SDL_SYS_CDGetTOC (SDL_CD * cdrom);
    1.52 +static CDstatus SDL_SYS_CDStatus (SDL_CD * cdrom, int *position);
    1.53 +static int SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length);
    1.54 +static int SDL_SYS_CDPause (SDL_CD * cdrom);
    1.55 +static int SDL_SYS_CDResume (SDL_CD * cdrom);
    1.56 +static int SDL_SYS_CDStop (SDL_CD * cdrom);
    1.57 +static int SDL_SYS_CDEject (SDL_CD * cdrom);
    1.58 +static void SDL_SYS_CDClose (SDL_CD * cdrom);
    1.59  
    1.60 -typedef	struct	scsi_cdb cdb_t;
    1.61 +typedef struct scsi_cdb cdb_t;
    1.62  
    1.63 -static int scsi_cmd(int fd,
    1.64 -		struct scsi_cdb *cdb,
    1.65 -		int cdblen, 
    1.66 -		int rw,
    1.67 -		caddr_t data,
    1.68 -		int datalen,
    1.69 -		struct scsi_user_cdb *sus)
    1.70 -	{
    1.71 -	int	scsistatus;
    1.72 -	unsigned char	*cp;
    1.73 -	struct	scsi_user_cdb suc;
    1.74 +static int
    1.75 +scsi_cmd (int fd,
    1.76 +          struct scsi_cdb *cdb,
    1.77 +          int cdblen,
    1.78 +          int rw, caddr_t data, int datalen, struct scsi_user_cdb *sus)
    1.79 +{
    1.80 +    int scsistatus;
    1.81 +    unsigned char *cp;
    1.82 +    struct scsi_user_cdb suc;
    1.83  
    1.84      /* safety checks */
    1.85 -	if	(!cdb) return(-1);
    1.86 -	if	(rw != SUC_READ && rw != SUC_WRITE) return(-1);
    1.87 +    if (!cdb)
    1.88 +        return (-1);
    1.89 +    if (rw != SUC_READ && rw != SUC_WRITE)
    1.90 +        return (-1);
    1.91  
    1.92 -	suc.suc_flags = rw;
    1.93 -	suc.suc_cdblen = cdblen;
    1.94 -	bcopy(cdb, suc.suc_cdb, cdblen);
    1.95 -	suc.suc_datalen = datalen;
    1.96 -	suc.suc_data = data;
    1.97 -	suc.suc_timeout = 10;		/* 10 secs max for TUR or SENSE */
    1.98 -	if	(ioctl(fd, SCSIRAWCDB, &suc) == -1)
    1.99 -		return(-11);
   1.100 -	scsistatus = suc.suc_sus.sus_status;
   1.101 -	cp = suc.suc_sus.sus_sense;
   1.102 +    suc.suc_flags = rw;
   1.103 +    suc.suc_cdblen = cdblen;
   1.104 +    bcopy (cdb, suc.suc_cdb, cdblen);
   1.105 +    suc.suc_datalen = datalen;
   1.106 +    suc.suc_data = data;
   1.107 +    suc.suc_timeout = 10;       /* 10 secs max for TUR or SENSE */
   1.108 +    if (ioctl (fd, SCSIRAWCDB, &suc) == -1)
   1.109 +        return (-11);
   1.110 +    scsistatus = suc.suc_sus.sus_status;
   1.111 +    cp = suc.suc_sus.sus_sense;
   1.112  
   1.113  /*
   1.114   * If a place to copy the sense data back to has been provided then the
   1.115   * caller is responsible for checking the errors and printing any information
   1.116   * out if the status was not successful.
   1.117  */
   1.118 -	if	(scsistatus != 0 && !sus)
   1.119 -		{
   1.120 -		fprintf(stderr,"scsistatus = %x cmd = %x\n",
   1.121 -			scsistatus, cdb[0]);
   1.122 -		fprintf(stderr, "sense %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x\n", 
   1.123 -			cp[0], cp[1], cp[2], cp[3], cp[4], cp[5],
   1.124 -			cp[6], cp[7], cp[8], cp[9], cp[10], cp[11],
   1.125 -			cp[12], cp[13], cp[14], cp[15]);
   1.126 -		return(1);
   1.127 -		}
   1.128 -	if	(sus)
   1.129 -		bcopy(&suc, sus, sizeof (struct scsi_user_cdb));
   1.130 -	if	(scsistatus)
   1.131 -		return(1);	/* Return non-zero for unsuccessful status */
   1.132 -	return(0);
   1.133 -	}
   1.134 +    if (scsistatus != 0 && !sus) {
   1.135 +        fprintf (stderr, "scsistatus = %x cmd = %x\n", scsistatus, cdb[0]);
   1.136 +        fprintf (stderr,
   1.137 +                 "sense %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x\n",
   1.138 +                 cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], cp[6], cp[7],
   1.139 +                 cp[8], cp[9], cp[10], cp[11], cp[12], cp[13], cp[14],
   1.140 +                 cp[15]);
   1.141 +        return (1);
   1.142 +    }
   1.143 +    if (sus)
   1.144 +        bcopy (&suc, sus, sizeof (struct scsi_user_cdb));
   1.145 +    if (scsistatus)
   1.146 +        return (1);             /* Return non-zero for unsuccessful status */
   1.147 +    return (0);
   1.148 +}
   1.149  
   1.150  /* request vendor brand and model */
   1.151 -unsigned char *Inquiry(int fd)
   1.152 -	{
   1.153 -	static struct scsi_cdb6 cdb = 
   1.154 -		{
   1.155 -		0x12, 
   1.156 -		0, 0, 0,
   1.157 -		56,
   1.158 -		0
   1.159 -		};
   1.160 -	static unsigned char Inqbuffer[56];
   1.161 +unsigned char *
   1.162 +Inquiry (int fd)
   1.163 +{
   1.164 +    static struct scsi_cdb6 cdb = {
   1.165 +        0x12,
   1.166 +        0, 0, 0,
   1.167 +        56,
   1.168 +        0
   1.169 +    };
   1.170 +    static unsigned char Inqbuffer[56];
   1.171  
   1.172 -	if	(scsi_cmd(fd, (cdb_t *)&cdb, 6, SUC_READ, Inqbuffer, 
   1.173 -			sizeof(Inqbuffer), 0))
   1.174 -		return("\377");
   1.175 -	return(Inqbuffer);
   1.176 -	}
   1.177 +    if (scsi_cmd (fd, (cdb_t *) & cdb, 6, SUC_READ, Inqbuffer,
   1.178 +                  sizeof (Inqbuffer), 0))
   1.179 +        return ("\377");
   1.180 +    return (Inqbuffer);
   1.181 +}
   1.182  
   1.183  #define ADD_SENSECODE 12
   1.184  #define ADD_SC_QUALIFIER 13
   1.185  
   1.186 -int TestForMedium(int fd)
   1.187 -	{
   1.188 -	int	sts, asc, ascq;
   1.189 -	struct	scsi_user_cdb sus;
   1.190 -	static struct scsi_cdb6 cdb =
   1.191 -		{
   1.192 -		CMD_TEST_UNIT_READY, /* command */
   1.193 -		0,	/* reserved */
   1.194 -		0,	/* reserved */
   1.195 -		0,	/* reserved */
   1.196 -		0,	/* reserved */
   1.197 -		0	/* reserved */
   1.198 -		};
   1.199 +int
   1.200 +TestForMedium (int fd)
   1.201 +{
   1.202 +    int sts, asc, ascq;
   1.203 +    struct scsi_user_cdb sus;
   1.204 +    static struct scsi_cdb6 cdb = {
   1.205 +        CMD_TEST_UNIT_READY,    /* command */
   1.206 +        0,                      /* reserved */
   1.207 +        0,                      /* reserved */
   1.208 +        0,                      /* reserved */
   1.209 +        0,                      /* reserved */
   1.210 +        0                       /* reserved */
   1.211 +    };
   1.212  
   1.213 -again:	sts = scsi_cmd(fd, (cdb_t *)&cdb, 6, SUC_READ, 0, 0, &sus);
   1.214 -	asc = sus.suc_sus.sus_sense[ADD_SENSECODE];
   1.215 -	ascq = sus.suc_sus.sus_sense[ADD_SC_QUALIFIER];
   1.216 -	if	(asc == 0x3a && ascq == 0x0)	/* no medium */
   1.217 -		return(0);
   1.218 -	if	(asc == 0x28 && ascq == 0x0)	/* medium changed */
   1.219 -		goto again;
   1.220 -	if	(asc == 0x4 && ascq == 0x1 )	/* coming ready */
   1.221 -		{
   1.222 -		sleep(2);
   1.223 -		goto again;
   1.224 -		}
   1.225 -	return(1);
   1.226 -	}
   1.227 +  again:sts = scsi_cmd (fd, (cdb_t *) & cdb, 6, SUC_READ, 0, 0, &sus);
   1.228 +    asc = sus.suc_sus.sus_sense[ADD_SENSECODE];
   1.229 +    ascq = sus.suc_sus.sus_sense[ADD_SC_QUALIFIER];
   1.230 +    if (asc == 0x3a && ascq == 0x0)     /* no medium */
   1.231 +        return (0);
   1.232 +    if (asc == 0x28 && ascq == 0x0)     /* medium changed */
   1.233 +        goto again;
   1.234 +    if (asc == 0x4 && ascq == 0x1) {    /* coming ready */
   1.235 +        sleep (2);
   1.236 +        goto again;
   1.237 +    }
   1.238 +    return (1);
   1.239 +}
   1.240  
   1.241  /* Check a drive to see if it is a CD-ROM */
   1.242 -static int CheckDrive(char *drive, struct stat *stbuf)
   1.243 +static int
   1.244 +CheckDrive (char *drive, struct stat *stbuf)
   1.245  {
   1.246 -	int is_cd = 0, cdfd;
   1.247 -	char *p;
   1.248 +    int is_cd = 0, cdfd;
   1.249 +    char *p;
   1.250  
   1.251 -	/* If it doesn't exist, return -1 */
   1.252 -	if ( stat(drive, stbuf) < 0 ) {
   1.253 -		return(-1);
   1.254 -	}
   1.255 +    /* If it doesn't exist, return -1 */
   1.256 +    if (stat (drive, stbuf) < 0) {
   1.257 +        return (-1);
   1.258 +    }
   1.259  
   1.260 -	/* If it does exist, verify that it's an available CD-ROM */
   1.261 -	cdfd = open(drive, (O_RDONLY|O_EXCL|O_NONBLOCK), 0);
   1.262 -	if ( cdfd >= 0 ) {
   1.263 -		p = Inquiry(cdfd);
   1.264 -		if (*p == TYPE_ROM)
   1.265 -			is_cd = 1;
   1.266 -		close(cdfd);
   1.267 -	}
   1.268 -	return(is_cd);
   1.269 +    /* If it does exist, verify that it's an available CD-ROM */
   1.270 +    cdfd = open (drive, (O_RDONLY | O_EXCL | O_NONBLOCK), 0);
   1.271 +    if (cdfd >= 0) {
   1.272 +        p = Inquiry (cdfd);
   1.273 +        if (*p == TYPE_ROM)
   1.274 +            is_cd = 1;
   1.275 +        close (cdfd);
   1.276 +    }
   1.277 +    return (is_cd);
   1.278  }
   1.279  
   1.280  /* Add a CD-ROM drive to our list of valid drives */
   1.281 -static void AddDrive(char *drive, struct stat *stbuf)
   1.282 +static void
   1.283 +AddDrive (char *drive, struct stat *stbuf)
   1.284  {
   1.285 -	int i;
   1.286 +    int i;
   1.287  
   1.288 -	if ( SDL_numcds < MAX_DRIVES ) {
   1.289 -		/* Check to make sure it's not already in our list.
   1.290 -	 	   This can happen when we see a drive via symbolic link.
   1.291 -		 */
   1.292 -		for ( i=0; i<SDL_numcds; ++i ) {
   1.293 -			if ( stbuf->st_rdev == SDL_cdmode[i] ) {
   1.294 +    if (SDL_numcds < MAX_DRIVES) {
   1.295 +        /* Check to make sure it's not already in our list.
   1.296 +           This can happen when we see a drive via symbolic link.
   1.297 +         */
   1.298 +        for (i = 0; i < SDL_numcds; ++i) {
   1.299 +            if (stbuf->st_rdev == SDL_cdmode[i]) {
   1.300  #ifdef DEBUG_CDROM
   1.301 -  fprintf(stderr, "Duplicate drive detected: %s == %s\n", drive, SDL_cdlist[i]);
   1.302 +                fprintf (stderr, "Duplicate drive detected: %s == %s\n",
   1.303 +                         drive, SDL_cdlist[i]);
   1.304  #endif
   1.305 -				return;
   1.306 -			}
   1.307 -		}
   1.308 +                return;
   1.309 +            }
   1.310 +        }
   1.311  
   1.312 -		/* Add this drive to our list */
   1.313 -		i = SDL_numcds;
   1.314 -		SDL_cdlist[i] = SDL_strdup(drive);
   1.315 -		if ( SDL_cdlist[i] == NULL ) {
   1.316 -			SDL_OutOfMemory();
   1.317 -			return;
   1.318 -		}
   1.319 -		SDL_cdmode[i] = stbuf->st_rdev;
   1.320 -		++SDL_numcds;
   1.321 +        /* Add this drive to our list */
   1.322 +        i = SDL_numcds;
   1.323 +        SDL_cdlist[i] = SDL_strdup (drive);
   1.324 +        if (SDL_cdlist[i] == NULL) {
   1.325 +            SDL_OutOfMemory ();
   1.326 +            return;
   1.327 +        }
   1.328 +        SDL_cdmode[i] = stbuf->st_rdev;
   1.329 +        ++SDL_numcds;
   1.330  #ifdef DEBUG_CDROM
   1.331 -  fprintf(stderr, "Added CD-ROM drive: %s\n", drive);
   1.332 +        fprintf (stderr, "Added CD-ROM drive: %s\n", drive);
   1.333  #endif
   1.334 -	}
   1.335 +    }
   1.336  }
   1.337  
   1.338 -int  SDL_SYS_CDInit(void)
   1.339 +int
   1.340 +SDL_SYS_CDInit (void)
   1.341  {
   1.342 -	/* checklist: /dev/rsr?c */
   1.343 -	static char *checklist[] = {
   1.344 -	"?0 rsr?", NULL
   1.345 -	};
   1.346 -	char *SDLcdrom;
   1.347 -	int i, j, exists;
   1.348 -	char drive[32];
   1.349 -	struct stat stbuf;
   1.350 +    /* checklist: /dev/rsr?c */
   1.351 +    static char *checklist[] = {
   1.352 +        "?0 rsr?", NULL
   1.353 +    };
   1.354 +    char *SDLcdrom;
   1.355 +    int i, j, exists;
   1.356 +    char drive[32];
   1.357 +    struct stat stbuf;
   1.358  
   1.359 -	/* Fill in our driver capabilities */
   1.360 -	SDL_CDcaps.Name = SDL_SYS_CDName;
   1.361 -	SDL_CDcaps.Open = SDL_SYS_CDOpen;
   1.362 -	SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
   1.363 -	SDL_CDcaps.Status = SDL_SYS_CDStatus;
   1.364 -	SDL_CDcaps.Play = SDL_SYS_CDPlay;
   1.365 -	SDL_CDcaps.Pause = SDL_SYS_CDPause;
   1.366 -	SDL_CDcaps.Resume = SDL_SYS_CDResume;
   1.367 -	SDL_CDcaps.Stop = SDL_SYS_CDStop;
   1.368 -	SDL_CDcaps.Eject = SDL_SYS_CDEject;
   1.369 -	SDL_CDcaps.Close = SDL_SYS_CDClose;
   1.370 +    /* Fill in our driver capabilities */
   1.371 +    SDL_CDcaps.Name = SDL_SYS_CDName;
   1.372 +    SDL_CDcaps.Open = SDL_SYS_CDOpen;
   1.373 +    SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
   1.374 +    SDL_CDcaps.Status = SDL_SYS_CDStatus;
   1.375 +    SDL_CDcaps.Play = SDL_SYS_CDPlay;
   1.376 +    SDL_CDcaps.Pause = SDL_SYS_CDPause;
   1.377 +    SDL_CDcaps.Resume = SDL_SYS_CDResume;
   1.378 +    SDL_CDcaps.Stop = SDL_SYS_CDStop;
   1.379 +    SDL_CDcaps.Eject = SDL_SYS_CDEject;
   1.380 +    SDL_CDcaps.Close = SDL_SYS_CDClose;
   1.381  
   1.382 -	/* Look in the environment for our CD-ROM drive list */
   1.383 -	SDLcdrom = SDL_getenv("SDL_CDROM");	/* ':' separated list of devices */
   1.384 -	if ( SDLcdrom != NULL ) {
   1.385 -		char *cdpath, *delim;
   1.386 -		size_t len = SDL_strlen(SDLcdrom)+1;
   1.387 -		cdpath = SDL_stack_alloc(char, len);
   1.388 -		if ( cdpath != NULL ) {
   1.389 -			SDL_strlcpy(cdpath, SDLcdrom, len);
   1.390 -			SDLcdrom = cdpath;
   1.391 -			do {
   1.392 -				delim = SDL_strchr(SDLcdrom, ':');
   1.393 -				if ( delim ) {
   1.394 -					*delim++ = '\0';
   1.395 -				}
   1.396 -				if ( CheckDrive(SDLcdrom, &stbuf) > 0 ) {
   1.397 -					AddDrive(SDLcdrom, &stbuf);
   1.398 -				}
   1.399 -				if ( delim ) {
   1.400 -					SDLcdrom = delim;
   1.401 -				} else {
   1.402 -					SDLcdrom = NULL;
   1.403 -				}
   1.404 -			} while ( SDLcdrom );
   1.405 -			SDL_stack_free(cdpath);
   1.406 -		}
   1.407 +    /* Look in the environment for our CD-ROM drive list */
   1.408 +    SDLcdrom = SDL_getenv ("SDL_CDROM");        /* ':' separated list of devices */
   1.409 +    if (SDLcdrom != NULL) {
   1.410 +        char *cdpath, *delim;
   1.411 +        size_t len = SDL_strlen (SDLcdrom) + 1;
   1.412 +        cdpath = SDL_stack_alloc (char, len);
   1.413 +        if (cdpath != NULL) {
   1.414 +            SDL_strlcpy (cdpath, SDLcdrom, len);
   1.415 +            SDLcdrom = cdpath;
   1.416 +            do {
   1.417 +                delim = SDL_strchr (SDLcdrom, ':');
   1.418 +                if (delim) {
   1.419 +                    *delim++ = '\0';
   1.420 +                }
   1.421 +                if (CheckDrive (SDLcdrom, &stbuf) > 0) {
   1.422 +                    AddDrive (SDLcdrom, &stbuf);
   1.423 +                }
   1.424 +                if (delim) {
   1.425 +                    SDLcdrom = delim;
   1.426 +                } else {
   1.427 +                    SDLcdrom = NULL;
   1.428 +                }
   1.429 +            }
   1.430 +            while (SDLcdrom);
   1.431 +            SDL_stack_free (cdpath);
   1.432 +        }
   1.433  
   1.434 -		/* If we found our drives, there's nothing left to do */
   1.435 -		if ( SDL_numcds > 0 ) {
   1.436 -			return(0);
   1.437 -		}
   1.438 -	}
   1.439 +        /* If we found our drives, there's nothing left to do */
   1.440 +        if (SDL_numcds > 0) {
   1.441 +            return (0);
   1.442 +        }
   1.443 +    }
   1.444  
   1.445 -	/* Scan the system for CD-ROM drives */
   1.446 -	for ( i=0; checklist[i]; ++i ) {
   1.447 -		if ( checklist[i][0] == '?' ) {
   1.448 -			char *insert;
   1.449 -			exists = 1;
   1.450 -			for ( j=checklist[i][1]; exists; ++j ) {
   1.451 -				SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%sc", &checklist[i][3]);
   1.452 -				insert = SDL_strchr(drive, '?');
   1.453 -				if ( insert != NULL ) {
   1.454 -					*insert = j;
   1.455 -				}
   1.456 -				switch (CheckDrive(drive, &stbuf)) {
   1.457 -					/* Drive exists and is a CD-ROM */
   1.458 -					case 1:
   1.459 -						AddDrive(drive, &stbuf);
   1.460 -						break;
   1.461 -					/* Drive exists, but isn't a CD-ROM */
   1.462 -					case 0:
   1.463 -						break;
   1.464 -					/* Drive doesn't exist */
   1.465 -					case -1:
   1.466 -						exists = 0;
   1.467 -						break;
   1.468 -				}
   1.469 -			}
   1.470 -		} else {
   1.471 -			SDL_snprintf(drive, SDL_arraysize(drive), "/dev/%s", checklist[i]);
   1.472 -			if ( CheckDrive(drive, &stbuf) > 0 ) {
   1.473 -				AddDrive(drive, &stbuf);
   1.474 -			}
   1.475 -		}
   1.476 -	}
   1.477 -	return(0);
   1.478 +    /* Scan the system for CD-ROM drives */
   1.479 +    for (i = 0; checklist[i]; ++i) {
   1.480 +        if (checklist[i][0] == '?') {
   1.481 +            char *insert;
   1.482 +            exists = 1;
   1.483 +            for (j = checklist[i][1]; exists; ++j) {
   1.484 +                SDL_snprintf (drive, SDL_arraysize (drive), "/dev/%sc",
   1.485 +                              &checklist[i][3]);
   1.486 +                insert = SDL_strchr (drive, '?');
   1.487 +                if (insert != NULL) {
   1.488 +                    *insert = j;
   1.489 +                }
   1.490 +                switch (CheckDrive (drive, &stbuf)) {
   1.491 +                    /* Drive exists and is a CD-ROM */
   1.492 +                case 1:
   1.493 +                    AddDrive (drive, &stbuf);
   1.494 +                    break;
   1.495 +                    /* Drive exists, but isn't a CD-ROM */
   1.496 +                case 0:
   1.497 +                    break;
   1.498 +                    /* Drive doesn't exist */
   1.499 +                case -1:
   1.500 +                    exists = 0;
   1.501 +                    break;
   1.502 +                }
   1.503 +            }
   1.504 +        } else {
   1.505 +            SDL_snprintf (drive, SDL_arraysize (drive), "/dev/%s",
   1.506 +                          checklist[i]);
   1.507 +            if (CheckDrive (drive, &stbuf) > 0) {
   1.508 +                AddDrive (drive, &stbuf);
   1.509 +            }
   1.510 +        }
   1.511 +    }
   1.512 +    return (0);
   1.513  }
   1.514  
   1.515 -static const char *SDL_SYS_CDName(int drive)
   1.516 +static const char *
   1.517 +SDL_SYS_CDName (int drive)
   1.518  {
   1.519 -	return(SDL_cdlist[drive]);
   1.520 +    return (SDL_cdlist[drive]);
   1.521  }
   1.522  
   1.523 -static int SDL_SYS_CDOpen(int drive)
   1.524 +static int
   1.525 +SDL_SYS_CDOpen (int drive)
   1.526  {
   1.527 -	return(open(SDL_cdlist[drive], O_RDONLY | O_NONBLOCK | O_EXCL, 0));
   1.528 +    return (open (SDL_cdlist[drive], O_RDONLY | O_NONBLOCK | O_EXCL, 0));
   1.529  }
   1.530  
   1.531 -static int SDL_SYS_CDGetTOC(SDL_CD *cdrom)
   1.532 -	{
   1.533 -	u_char cdb[10], buf[4], *p, *toc;
   1.534 -	struct scsi_user_cdb sus;
   1.535 -	int i, sts, first_track, last_track, ntracks, toc_size;
   1.536 +static int
   1.537 +SDL_SYS_CDGetTOC (SDL_CD * cdrom)
   1.538 +{
   1.539 +    u_char cdb[10], buf[4], *p, *toc;
   1.540 +    struct scsi_user_cdb sus;
   1.541 +    int i, sts, first_track, last_track, ntracks, toc_size;
   1.542  
   1.543 -	bzero(cdb, sizeof (cdb));
   1.544 -	cdb[0] = 0x43;		/* Read TOC */
   1.545 -	cdb[1] = 0x2;		/* MSF */
   1.546 -	cdb[8] = 4;		/* size TOC header */
   1.547 -	sts = scsi_cmd(cdrom->id, (cdb_t *)cdb, 10, SUC_READ, buf, 4, &sus);
   1.548 -	if	(sts < 0)
   1.549 -		return(-1);
   1.550 -	first_track = buf[2];
   1.551 -	last_track = buf[3];
   1.552 -	ntracks = last_track - first_track + 1;
   1.553 -	cdrom->numtracks = ntracks;
   1.554 -	toc_size = 4 + (ntracks + 1) * 8;
   1.555 -	toc = (u_char *)SDL_malloc(toc_size);
   1.556 -	if	(toc == NULL)
   1.557 -		return(-1);
   1.558 -	bzero(cdb, sizeof (cdb));
   1.559 -	cdb[0] = 0x43;
   1.560 -	cdb[1] = 0x2;
   1.561 -	cdb[6] = first_track;
   1.562 -	cdb[7] = toc_size >> 8;
   1.563 -	cdb[8] = toc_size & 0xff;
   1.564 -	sts = scsi_cmd(cdrom->id, (cdb_t *)cdb, 10, SUC_READ, toc, toc_size, 
   1.565 -			&sus);
   1.566 -	if	(sts < 0)
   1.567 -		{
   1.568 -		SDL_free(toc);
   1.569 -		return(-1);
   1.570 -		}
   1.571 +    bzero (cdb, sizeof (cdb));
   1.572 +    cdb[0] = 0x43;              /* Read TOC */
   1.573 +    cdb[1] = 0x2;               /* MSF */
   1.574 +    cdb[8] = 4;                 /* size TOC header */
   1.575 +    sts = scsi_cmd (cdrom->id, (cdb_t *) cdb, 10, SUC_READ, buf, 4, &sus);
   1.576 +    if (sts < 0)
   1.577 +        return (-1);
   1.578 +    first_track = buf[2];
   1.579 +    last_track = buf[3];
   1.580 +    ntracks = last_track - first_track + 1;
   1.581 +    cdrom->numtracks = ntracks;
   1.582 +    toc_size = 4 + (ntracks + 1) * 8;
   1.583 +    toc = (u_char *) SDL_malloc (toc_size);
   1.584 +    if (toc == NULL)
   1.585 +        return (-1);
   1.586 +    bzero (cdb, sizeof (cdb));
   1.587 +    cdb[0] = 0x43;
   1.588 +    cdb[1] = 0x2;
   1.589 +    cdb[6] = first_track;
   1.590 +    cdb[7] = toc_size >> 8;
   1.591 +    cdb[8] = toc_size & 0xff;
   1.592 +    sts = scsi_cmd (cdrom->id, (cdb_t *) cdb, 10, SUC_READ, toc, toc_size,
   1.593 +                    &sus);
   1.594 +    if (sts < 0) {
   1.595 +        SDL_free (toc);
   1.596 +        return (-1);
   1.597 +    }
   1.598  
   1.599 -	for	(i = 0, p = toc+4; i <= ntracks; i++, p+= 8)
   1.600 -		{
   1.601 -		if	(i == ntracks)
   1.602 -			cdrom->track[i].id = 0xAA;	/* Leadout */
   1.603 -		else
   1.604 -			cdrom->track[i].id = first_track + i;
   1.605 -		if	(p[1] & 0x20)
   1.606 -			cdrom->track[i].type = SDL_DATA_TRACK;
   1.607 -		else
   1.608 -			cdrom->track[i].type = SDL_AUDIO_TRACK;
   1.609 -		cdrom->track[i].offset = msf_to_frame(p[5], p[6], p[7]);
   1.610 -		cdrom->track[i].length = 0;
   1.611 -		if	(i > 0)
   1.612 -			cdrom->track[i-1].length = cdrom->track[i].offset -
   1.613 -						   cdrom->track[i-1].offset;
   1.614 -		}
   1.615 -	SDL_free(toc);
   1.616 -	return(0);
   1.617 -	}
   1.618 +    for (i = 0, p = toc + 4; i <= ntracks; i++, p += 8) {
   1.619 +        if (i == ntracks)
   1.620 +            cdrom->track[i].id = 0xAA;  /* Leadout */
   1.621 +        else
   1.622 +            cdrom->track[i].id = first_track + i;
   1.623 +        if (p[1] & 0x20)
   1.624 +            cdrom->track[i].type = SDL_DATA_TRACK;
   1.625 +        else
   1.626 +            cdrom->track[i].type = SDL_AUDIO_TRACK;
   1.627 +        cdrom->track[i].offset = msf_to_frame (p[5], p[6], p[7]);
   1.628 +        cdrom->track[i].length = 0;
   1.629 +        if (i > 0)
   1.630 +            cdrom->track[i - 1].length = cdrom->track[i].offset -
   1.631 +                cdrom->track[i - 1].offset;
   1.632 +    }
   1.633 +    SDL_free (toc);
   1.634 +    return (0);
   1.635 +}
   1.636  
   1.637  /* Get CD-ROM status */
   1.638 -static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position)
   1.639 -	{
   1.640 -	CDstatus status;
   1.641 -	u_char	cdb[10], buf[16];
   1.642 -	int	sts;
   1.643 -	struct	scsi_user_cdb sus;
   1.644 +static CDstatus
   1.645 +SDL_SYS_CDStatus (SDL_CD * cdrom, int *position)
   1.646 +{
   1.647 +    CDstatus status;
   1.648 +    u_char cdb[10], buf[16];
   1.649 +    int sts;
   1.650 +    struct scsi_user_cdb sus;
   1.651  
   1.652 -	bzero(cdb, sizeof (cdb));
   1.653 -	cdb[0] = 0x42;		/* read subq */
   1.654 -	cdb[1] = 0x2;		/* MSF */
   1.655 -	cdb[2] = 0x40;		/* q channel */
   1.656 -	cdb[3] = 1;		/* current pos */
   1.657 -	cdb[7] = sizeof (buf) >> 8;
   1.658 -	cdb[8] = sizeof (buf) & 0xff;
   1.659 -	sts = scsi_cmd(cdrom->id, (cdb_t *)cdb, 10, SUC_READ, buf, sizeof (buf),
   1.660 -			&sus);
   1.661 -	if	(sts < 0)
   1.662 -		return(-1);
   1.663 -	if	(sts)
   1.664 -		{
   1.665 -		if	(TestForMedium(cdrom->id) == 0)
   1.666 -			status = CD_TRAYEMPTY;
   1.667 -		else
   1.668 -			status = CD_ERROR;
   1.669 -		}
   1.670 -	else
   1.671 -		{
   1.672 -		switch	(buf[1])
   1.673 -			{
   1.674 -			case	0x11:
   1.675 -				status = CD_PLAYING;
   1.676 -				break;
   1.677 -			case	0x12:
   1.678 -				status = CD_PAUSED;
   1.679 -				break;
   1.680 -			case	0x13:
   1.681 -			case	0x14:
   1.682 -			case	0x15:
   1.683 -				status = CD_STOPPED;
   1.684 -				break;
   1.685 -			default:
   1.686 -				status = CD_ERROR;
   1.687 -				break;
   1.688 -			}
   1.689 -		}
   1.690 -	if	(position)
   1.691 -		{
   1.692 -		if	( status == CD_PLAYING || (status == CD_PAUSED) )
   1.693 -			*position = msf_to_frame(buf[9], buf[10], buf[11]);
   1.694 -		else
   1.695 -			*position = 0;
   1.696 -		}
   1.697 -	return(status);
   1.698 -	}
   1.699 +    bzero (cdb, sizeof (cdb));
   1.700 +    cdb[0] = 0x42;              /* read subq */
   1.701 +    cdb[1] = 0x2;               /* MSF */
   1.702 +    cdb[2] = 0x40;              /* q channel */
   1.703 +    cdb[3] = 1;                 /* current pos */
   1.704 +    cdb[7] = sizeof (buf) >> 8;
   1.705 +    cdb[8] = sizeof (buf) & 0xff;
   1.706 +    sts = scsi_cmd (cdrom->id, (cdb_t *) cdb, 10, SUC_READ, buf, sizeof (buf),
   1.707 +                    &sus);
   1.708 +    if (sts < 0)
   1.709 +        return (-1);
   1.710 +    if (sts) {
   1.711 +        if (TestForMedium (cdrom->id) == 0)
   1.712 +            status = CD_TRAYEMPTY;
   1.713 +        else
   1.714 +            status = CD_ERROR;
   1.715 +    } else {
   1.716 +        switch (buf[1]) {
   1.717 +        case 0x11:
   1.718 +            status = CD_PLAYING;
   1.719 +            break;
   1.720 +        case 0x12:
   1.721 +            status = CD_PAUSED;
   1.722 +            break;
   1.723 +        case 0x13:
   1.724 +        case 0x14:
   1.725 +        case 0x15:
   1.726 +            status = CD_STOPPED;
   1.727 +            break;
   1.728 +        default:
   1.729 +            status = CD_ERROR;
   1.730 +            break;
   1.731 +        }
   1.732 +    }
   1.733 +    if (position) {
   1.734 +        if (status == CD_PLAYING || (status == CD_PAUSED))
   1.735 +            *position = msf_to_frame (buf[9], buf[10], buf[11]);
   1.736 +        else
   1.737 +            *position = 0;
   1.738 +    }
   1.739 +    return (status);
   1.740 +}
   1.741  
   1.742  /* Start play */
   1.743 -static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length)
   1.744 -	{
   1.745 -	u_char	cdb[10];
   1.746 -	int	sts, minute, second, frame, eminute, esecond, eframe;
   1.747 -	struct	scsi_user_cdb sus;
   1.748 +static int
   1.749 +SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length)
   1.750 +{
   1.751 +    u_char cdb[10];
   1.752 +    int sts, minute, second, frame, eminute, esecond, eframe;
   1.753 +    struct scsi_user_cdb sus;
   1.754  
   1.755 -	bzero(cdb, sizeof(cdb));
   1.756 -	cdb[0] = 0x47;		/* Play */
   1.757 -	frame_to_msf(start, &minute, &second, &frame);
   1.758 -	frame_to_msf(start + length, &eminute, &esecond, &eframe);
   1.759 -	cdb[3] = minute;
   1.760 -	cdb[4] = second;
   1.761 -	cdb[5] = frame;
   1.762 -	cdb[6] = eminute;
   1.763 -	cdb[7] = esecond;
   1.764 -	cdb[8] = eframe;
   1.765 -	sts = scsi_cmd(cdrom->id, (cdb_t *)cdb, 10, SUC_READ, 0, 0, &sus);
   1.766 -	return(sts);
   1.767 -	}
   1.768 +    bzero (cdb, sizeof (cdb));
   1.769 +    cdb[0] = 0x47;              /* Play */
   1.770 +    frame_to_msf (start, &minute, &second, &frame);
   1.771 +    frame_to_msf (start + length, &eminute, &esecond, &eframe);
   1.772 +    cdb[3] = minute;
   1.773 +    cdb[4] = second;
   1.774 +    cdb[5] = frame;
   1.775 +    cdb[6] = eminute;
   1.776 +    cdb[7] = esecond;
   1.777 +    cdb[8] = eframe;
   1.778 +    sts = scsi_cmd (cdrom->id, (cdb_t *) cdb, 10, SUC_READ, 0, 0, &sus);
   1.779 +    return (sts);
   1.780 +}
   1.781  
   1.782 -static	int
   1.783 -pauseresume(SDL_CD *cdrom, int flag)
   1.784 -	{
   1.785 -	u_char	cdb[10];
   1.786 -	struct	scsi_user_cdb sus;
   1.787 +static int
   1.788 +pauseresume (SDL_CD * cdrom, int flag)
   1.789 +{
   1.790 +    u_char cdb[10];
   1.791 +    struct scsi_user_cdb sus;
   1.792  
   1.793 -	bzero(cdb, sizeof (cdb));
   1.794 -	cdb[0] = 0x4b;
   1.795 -	cdb[8] = flag & 0x1;
   1.796 -	return(scsi_cmd(cdrom->id, (cdb_t *)cdb, 10, SUC_READ, 0, 0, &sus));
   1.797 -	}
   1.798 +    bzero (cdb, sizeof (cdb));
   1.799 +    cdb[0] = 0x4b;
   1.800 +    cdb[8] = flag & 0x1;
   1.801 +    return (scsi_cmd (cdrom->id, (cdb_t *) cdb, 10, SUC_READ, 0, 0, &sus));
   1.802 +}
   1.803  
   1.804  /* Pause play */
   1.805 -static int SDL_SYS_CDPause(SDL_CD *cdrom)
   1.806 +static int
   1.807 +SDL_SYS_CDPause (SDL_CD * cdrom)
   1.808  {
   1.809 -	return(pauseresume(cdrom, 0));
   1.810 +    return (pauseresume (cdrom, 0));
   1.811  }
   1.812  
   1.813  /* Resume play */
   1.814 -static int SDL_SYS_CDResume(SDL_CD *cdrom)
   1.815 +static int
   1.816 +SDL_SYS_CDResume (SDL_CD * cdrom)
   1.817  {
   1.818 -	return(pauseresume(cdrom, 1));
   1.819 +    return (pauseresume (cdrom, 1));
   1.820  }
   1.821  
   1.822  /* Stop play */
   1.823 -static int SDL_SYS_CDStop(SDL_CD *cdrom)
   1.824 +static int
   1.825 +SDL_SYS_CDStop (SDL_CD * cdrom)
   1.826  {
   1.827 -	u_char cdb[6];
   1.828 -	struct	scsi_user_cdb sus;
   1.829 +    u_char cdb[6];
   1.830 +    struct scsi_user_cdb sus;
   1.831  
   1.832 -	bzero(cdb, sizeof (cdb));
   1.833 -	cdb[0] = 0x1b;		/* stop */
   1.834 -	cdb[1] = 1;		/* immediate */
   1.835 -	return(scsi_cmd(cdrom->id, (cdb_t *)cdb, 6, SUC_READ, 0, 0, &sus));
   1.836 +    bzero (cdb, sizeof (cdb));
   1.837 +    cdb[0] = 0x1b;              /* stop */
   1.838 +    cdb[1] = 1;                 /* immediate */
   1.839 +    return (scsi_cmd (cdrom->id, (cdb_t *) cdb, 6, SUC_READ, 0, 0, &sus));
   1.840  }
   1.841  
   1.842  /* Eject the CD-ROM */
   1.843 -static int SDL_SYS_CDEject(SDL_CD *cdrom)
   1.844 +static int
   1.845 +SDL_SYS_CDEject (SDL_CD * cdrom)
   1.846  {
   1.847 -	u_char cdb[6];
   1.848 -	struct	scsi_user_cdb sus;
   1.849 +    u_char cdb[6];
   1.850 +    struct scsi_user_cdb sus;
   1.851  
   1.852 -	bzero(cdb, sizeof (cdb));
   1.853 -	cdb[0] = 0x1b;		/* stop */
   1.854 -	cdb[1] = 1;		/* immediate */
   1.855 -	cdb[4] = 2;		/* eject */
   1.856 -	return(scsi_cmd(cdrom->id, (cdb_t *)cdb, 6, SUC_READ, 0, 0, &sus));
   1.857 +    bzero (cdb, sizeof (cdb));
   1.858 +    cdb[0] = 0x1b;              /* stop */
   1.859 +    cdb[1] = 1;                 /* immediate */
   1.860 +    cdb[4] = 2;                 /* eject */
   1.861 +    return (scsi_cmd (cdrom->id, (cdb_t *) cdb, 6, SUC_READ, 0, 0, &sus));
   1.862  }
   1.863  
   1.864  /* Close the CD-ROM handle */
   1.865 -static void SDL_SYS_CDClose(SDL_CD *cdrom)
   1.866 -	{
   1.867 -	close(cdrom->id);
   1.868 -	}
   1.869 +static void
   1.870 +SDL_SYS_CDClose (SDL_CD * cdrom)
   1.871 +{
   1.872 +    close (cdrom->id);
   1.873 +}
   1.874  
   1.875 -void SDL_SYS_CDQuit(void)
   1.876 +void
   1.877 +SDL_SYS_CDQuit (void)
   1.878  {
   1.879 -	int i;
   1.880 +    int i;
   1.881  
   1.882 -	if ( SDL_numcds > 0 ) {
   1.883 -		for ( i=0; i<SDL_numcds; ++i ) {
   1.884 -			SDL_free(SDL_cdlist[i]);
   1.885 -			}
   1.886 -		}
   1.887 -	SDL_numcds = 0;
   1.888 +    if (SDL_numcds > 0) {
   1.889 +        for (i = 0; i < SDL_numcds; ++i) {
   1.890 +            SDL_free (SDL_cdlist[i]);
   1.891 +        }
   1.892 +    }
   1.893 +    SDL_numcds = 0;
   1.894  }
   1.895  
   1.896  #endif /* SDL_CDROM_BSDI */
   1.897 +/* vi: set ts=4 sw=4 expandtab: */