int SDL_SYS_CDInit(void) { char *SDLcdrom; struct stat stbuf; /* Fill in our driver capabilities */ SDL_CDcaps.Name = SDL_SYS_CDName; SDL_CDcaps.Open = SDL_SYS_CDOpen; SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; SDL_CDcaps.Status = SDL_SYS_CDStatus; SDL_CDcaps.Play = SDL_SYS_CDPlay; SDL_CDcaps.Pause = SDL_SYS_CDPause; SDL_CDcaps.Resume = SDL_SYS_CDResume; SDL_CDcaps.Stop = SDL_SYS_CDStop; SDL_CDcaps.Eject = SDL_SYS_CDEject; SDL_CDcaps.Close = SDL_SYS_CDClose; /* Look in the environment for our CD-ROM drive list */ SDLcdrom = getenv("SDL_CDROM"); /* ':' separated list of devices */ if ( SDLcdrom != NULL ) { char *cdpath, *delim; cdpath = malloc(strlen(SDLcdrom)+1); if ( cdpath != NULL ) { strcpy(cdpath, SDLcdrom); SDLcdrom = cdpath; do { delim = strchr(SDLcdrom, ':'); if ( delim ) { *delim++ = '\0'; } #ifdef DEBUG_CDROM fprintf(stderr, "Checking CD-ROM drive from SDL_CDROM: %s\n", SDLcdrom); #endif if ( CheckDrive(SDLcdrom, &stbuf) > 0 ) { AddDrive(SDLcdrom, &stbuf); } if ( delim ) { SDLcdrom = delim; } else { SDLcdrom = NULL; } } while ( SDLcdrom ); free(cdpath); } /* If we found our drives, there's nothing left to do */ if ( SDL_numcds > 0 ) { return(0); } } CheckMounts(); CheckNonmounts(); return 0; }
int SDL_SYS_CDInit(void) { /* checklist: /dev/cdrom, /dev/hd?, /dev/scd? /dev/sr? */ static char *checklist[] = { "cdrom", "?a hd?", "?0 scd?", "?0 sr?", NULL }; char *SDLcdrom; int i, j, exists; char drive[32]; struct stat stbuf; /* Fill in our driver capabilities */ SDL_CDcaps.Name = SDL_SYS_CDName; SDL_CDcaps.Open = SDL_SYS_CDOpen; SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; SDL_CDcaps.Status = SDL_SYS_CDStatus; SDL_CDcaps.Play = SDL_SYS_CDPlay; SDL_CDcaps.Pause = SDL_SYS_CDPause; SDL_CDcaps.Resume = SDL_SYS_CDResume; SDL_CDcaps.Stop = SDL_SYS_CDStop; SDL_CDcaps.Eject = SDL_SYS_CDEject; SDL_CDcaps.Close = SDL_SYS_CDClose; /* Look in the environment for our CD-ROM drive list */ SDLcdrom = getenv("SDL_CDROM"); /* ':' separated list of devices */ if ( SDLcdrom != NULL ) { char *cdpath, *delim; cdpath = malloc(strlen(SDLcdrom)+1); if ( cdpath != NULL ) { strcpy(cdpath, SDLcdrom); SDLcdrom = cdpath; do { delim = strchr(SDLcdrom, ':'); if ( delim ) { *delim++ = '\0'; } #ifdef DEBUG_CDROM fprintf(stderr, "Checking CD-ROM drive from SDL_CDROM: %s\n", SDLcdrom); #endif if ( CheckDrive(SDLcdrom, NULL, &stbuf) > 0 ) { AddDrive(SDLcdrom, &stbuf); } if ( delim ) { SDLcdrom = delim; } else { SDLcdrom = NULL; } } while ( SDLcdrom ); free(cdpath); } /* If we found our drives, there's nothing left to do */ if ( SDL_numcds > 0 ) { return(0); } } #ifdef USE_MNTENT /* Check /dev/cdrom first :-) */ if (CheckDrive("/dev/cdrom", NULL, &stbuf) > 0) { AddDrive("/dev/cdrom", &stbuf); } /* Now check the currently mounted CD drives */ CheckMounts(_PATH_MOUNTED); /* Finally check possible mountable drives in /etc/fstab */ CheckMounts(_PATH_MNTTAB); /* If we found our drives, there's nothing left to do */ if ( SDL_numcds > 0 ) { return(0); } #endif /* USE_MNTENT */ /* Scan the system for CD-ROM drives. Not always 100% reliable, so use the USE_MNTENT code above first. */ for ( i=0; checklist[i]; ++i ) { if ( checklist[i][0] == '?' ) { char *insert; exists = 1; for ( j=checklist[i][1]; exists; ++j ) { sprintf(drive, "/dev/%s", &checklist[i][3]); insert = strchr(drive, '?'); if ( insert != NULL ) { *insert = j; } #ifdef DEBUG_CDROM fprintf(stderr, "Checking possible CD-ROM drive: %s\n", drive); #endif switch (CheckDrive(drive, NULL, &stbuf)) { /* Drive exists and is a CD-ROM */ case 1: AddDrive(drive, &stbuf); break; /* Drive exists, but isn't a CD-ROM */ case 0: break; /* Drive doesn't exist */ case -1: exists = 0; break; } } } else { sprintf(drive, "/dev/%s", checklist[i]); #ifdef DEBUG_CDROM fprintf(stderr, "Checking possible CD-ROM drive: %s\n", drive); #endif if ( CheckDrive(drive, NULL, &stbuf) > 0 ) { AddDrive(drive, &stbuf); } } } return(0); }
const char *CdromDriverLinux::DeviceName(int drive) { if (!drives_scanned) { /* checklist: /dev/cdrom, /dev/hd?, /dev/scd? /dev/sr? */ static const char *const checklist[] = { "cdrom", "?a hd?", "?0 scd?", "?0 sr?", NULL }; struct stat stbuf; #ifdef USE_MNTENT /* Check /dev/cdrom first :-) */ if (CheckDrive("/dev/cdrom", NULL, &stbuf) > 0) { AddDrive("/dev/cdrom", &stbuf); } /* Now check the currently mounted CD drives */ CheckMounts(_PATH_MOUNTED); /* Finally check possible mountable drives in /etc/fstab */ CheckMounts(_PATH_MNTTAB); /* If we found our drives, there's nothing left to do */ #endif /* USE_MNTENT */ if ( numcds == 0 ) { char drive[32]; int i, j, exists; /* Scan the system for CD-ROM drives. Not always 100% reliable, so use the USE_MNTENT code above first. */ for ( i=0; checklist[i]; ++i ) { if ( checklist[i][0] == '?' ) { char *insert; exists = 1; for ( j=checklist[i][1]; exists; ++j ) { sprintf(drive, "/dev/%s", &checklist[i][3]); insert = strchr(drive, '?'); if ( insert != NULL ) { *insert = j; } switch (CheckDrive(drive, NULL, &stbuf)) { /* Drive exists and is a CD-ROM */ case 1: AddDrive(drive, &stbuf); break; /* Drive exists, but isn't a CD-ROM */ case 0: break; /* Drive doesn't exist */ case -1: exists = 0; break; } } } else { sprintf(drive, "/dev/%s", checklist[i]); if ( CheckDrive(drive, NULL, &stbuf) > 0 ) { AddDrive(drive, &stbuf); } } } } drives_scanned = true; } return cddrives[drive].device; }