Exemplo n.º 1
0
/* Check a drive to see if it is a CD-ROM */
static int CheckDrive(char *drive, struct stat *stbuf)
{
	int is_cd, cdfd;
	struct ioc_read_subchannel info;

	/* If it doesn't exist, return -1 */
	if ( stat(drive, stbuf) < 0 ) {
		return(-1);
	}

	/* If it does exist, verify that it's an available CD-ROM */
	is_cd = 0;
	if ( S_ISCHR(stbuf->st_mode) || S_ISBLK(stbuf->st_mode) ) {
		cdfd = open(drive, (O_RDONLY|O_EXCL|O_NONBLOCK), 0);
		if ( cdfd >= 0 ) {
			info.address_format = CD_MSF_FORMAT;
			info.data_format = CD_CURRENT_POSITION;
			info.data_len = 0;
			info.data = NULL;
			/* Under Linux, EIO occurs when a disk is not present.
			   This isn't 100% reliable, so we use the USE_MNTENT
			   code above instead.
			 */
			if ( (ioctl(cdfd, CDIOCREADSUBCHANNEL, &info) == 0) ||
						ERRNO_TRAYEMPTY(errno) ) {
				is_cd = 1;
			}
			close(cdfd);
		}
		else if (ERRNO_TRAYEMPTY(errno))
			is_cd = 1;
	}
	return(is_cd);
}
Exemplo n.º 2
0
/* Check a drive to see if it is a CD-ROM */
static int CheckDrive(char *drive, char *mnttype, struct stat *stbuf)
{
	int is_cd, cdfd;
	struct cdrom_subchnl info;

	/* If it doesn't exist, return -1 */
	if ( stat(drive, stbuf) < 0 ) {
		return(-1);
	}

	/* If it does exist, verify that it's an available CD-ROM */
	is_cd = 0;
	if ( S_ISCHR(stbuf->st_mode) || S_ISBLK(stbuf->st_mode) ) {
		cdfd = open(drive, (O_RDONLY|O_NONBLOCK), 0);
		if ( cdfd >= 0 ) {
			info.cdsc_format = CDROM_MSF;
			/* Under Linux, EIO occurs when a disk is not present.
			 */
			if ( (ioctl(cdfd, CDROMSUBCHNL, &info) == 0) ||
						ERRNO_TRAYEMPTY(errno) ) {
				is_cd = 1;
			}
			close(cdfd);
		}
#ifdef USE_MNTENT
		/* Even if we can't read it, it might be mounted */
		else if ( mnttype && (SDL_strcmp(mnttype, MNTTYPE_CDROM) == 0) ) {
			is_cd = 1;
		}
#endif
	}
	return(is_cd);
}
Exemplo n.º 3
0
static int CheckDrive(char *drive, char *mnttype, struct stat *stbuf)
{
	int is_cd, cdfd;
	struct cdrom_subchnl info;

	
	if ( stat(drive, stbuf) < 0 ) {
		return(-1);
	}

	
	is_cd = 0;
	if ( S_ISCHR(stbuf->st_mode) || S_ISBLK(stbuf->st_mode) ) {
		cdfd = open(drive, (O_RDONLY|O_NONBLOCK), 0);
		if ( cdfd >= 0 ) {
			info.cdsc_format = CDROM_MSF;
			if ( (ioctl(cdfd, CDROMSUBCHNL, &info) == 0) ||
						ERRNO_TRAYEMPTY(errno) ) {
				is_cd = 1;
			}
			close(cdfd);
		}
#ifdef USE_MNTENT
		
		else if ( mnttype && (SDL_strcmp(mnttype, MNTTYPE_CDROM) == 0) ) {
			is_cd = 1;
		}
#endif
	}
	return(is_cd);
}
Exemplo n.º 4
0
int SDL_SYS_CDInit(void)
{
	metainit_t	metainit={0,0,0,0};
	metaopen_t	metaopen;
	int i, handle;
	struct cdrom_subchnl info;

	SDL_numcds = 0;
	SDL_memset(metados_drives, 0, sizeof(metados_drives));

	Metainit(&metainit);
	if (metainit.version == NULL) {
#ifdef DEBUG_CDROM
		fprintf(stderr, "MetaDOS not installed\n");
#endif
		return 0;
	}

	if (metainit.drives_map == 0) {
#ifdef DEBUG_CDROM
		fprintf(stderr, "No MetaDOS devices present\n");
#endif
		return 0;
	}

	for (i='A'; i<='Z'; i++) {
		metados_drives[SDL_numcds].device[0] = 0;
		metados_drives[SDL_numcds].device[1] = ':';
		metados_drives[SDL_numcds].device[2] = 0;

		if (metainit.drives_map & (1<<(i-'A'))) {
			handle = Metaopen(i, &metaopen);
			if (handle == 0) {

				info.cdsc_format = CDROM_MSF;
				if ( (Metaioctl(i, METADOS_IOCTL_MAGIC, CDROMSUBCHNL, &info) == 0) || ERRNO_TRAYEMPTY(errno) ) {
					metados_drives[SDL_numcds].device[0] = i;
					++SDL_numcds;
				}

				Metaclose(i);
			}
		}
	}

	/* Fill in our driver capabilities */
	SDL_CDcaps.Name = SDL_SYS_CDName;
	SDL_CDcaps.Open = SDL_SYS_CDOpen;
	SDL_CDcaps.Close = SDL_SYS_CDClose;

	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;

	return 0;
}
Exemplo n.º 5
0
/* Get CD-ROM status */
static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position)
{
	CDstatus status;
	struct cdrom_tochdr toc;
	struct cdrom_subchnl info;

	info.cdsc_format = CDROM_MSF;
	if ( SDL_SYS_CDioctl(cdrom->id, CDROMSUBCHNL, &info) < 0 ) {
		if ( ERRNO_TRAYEMPTY(errno) ) {
			status = CD_TRAYEMPTY;
		} else {
			status = CD_ERROR;
		}
	} else {
		switch (info.cdsc_audiostatus) {
			case CDROM_AUDIO_INVALID:
			case CDROM_AUDIO_NO_STATUS:
				/* Try to determine if there's a CD available */
				if (SDL_SYS_CDioctl(cdrom->id, CDROMREADTOCHDR, &toc)==0) {
					status = CD_STOPPED;
				} else {
					status = CD_TRAYEMPTY;
				}
				break;
			case CDROM_AUDIO_COMPLETED:
				status = CD_STOPPED;
				break;
			case CDROM_AUDIO_PLAY:
				status = CD_PLAYING;
				break;
			case CDROM_AUDIO_PAUSED:
				/* Workaround buggy CD-ROM drive */
				if ( info.cdsc_trk == CDROM_LEADOUT ) {
					status = CD_STOPPED;
				} else {
					status = CD_PAUSED;
				}
				break;
			default:
				status = CD_ERROR;
				break;
		}
	}
	if ( position ) {
		if ( status == CD_PLAYING || (status == CD_PAUSED) ) {
			*position = MSF_TO_FRAMES(
					info.cdsc_absaddr.msf.minute,
					info.cdsc_absaddr.msf.second,
					info.cdsc_absaddr.msf.frame);
		} else {
			*position = 0;
		}
	}
	return(status);
}
Exemplo n.º 6
0
/* Get CD-ROM status */
static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position)
{
	CDstatus status;
	struct ioc_toc_header toc;
	struct ioc_read_subchannel info;
	struct cd_sub_channel_info data;

	info.address_format = CD_MSF_FORMAT;
	info.data_format = CD_CURRENT_POSITION;
	info.track = 0;
	info.data_len = sizeof(data);
	info.data = &data;
	if ( ioctl(cdrom->id, CDIOCREADSUBCHANNEL, &info) < 0 ) {
		if ( ERRNO_TRAYEMPTY(errno) ) {
			status = CD_TRAYEMPTY;
		} else {
			status = CD_ERROR;
		}
	} else {
		switch (data.header.audio_status) {
			case CD_AS_AUDIO_INVALID:
			case CD_AS_NO_STATUS:
				/* Try to determine if there's a CD available */
				if (ioctl(cdrom->id,CDIOREADTOCHEADER,&toc)==0)
					status = CD_STOPPED;
				else
					status = CD_TRAYEMPTY;
				break;
			case CD_AS_PLAY_COMPLETED:
				status = CD_STOPPED;
				break;
			case CD_AS_PLAY_IN_PROGRESS:
				status = CD_PLAYING;
				break;
			case CD_AS_PLAY_PAUSED:
				status = CD_PAUSED;
				break;
			default:
				status = CD_ERROR;
				break;
		}
	}
	if ( position ) {
		if ( status == CD_PLAYING || (status == CD_PAUSED) ) {
			*position = MSF_TO_FRAMES(
					data.what.position.absaddr.msf.minute,
					data.what.position.absaddr.msf.second,
					data.what.position.absaddr.msf.frame);
		} else {
			*position = 0;
		}
	}
	return(status);
}
Exemplo n.º 7
0
/* Caution!! Not tested. */ 
static int CheckDrive(char *drive, struct stat *stbuf)
{
    int is_cd, cdfd;
    struct cd_sub_channel info;

    /* If it doesn't exist, return -1 */
    if ( stat(drive, stbuf) < 0 ) {
	return(-1);
    }

    /* If it does exist, verify that it's an available CD-ROM */
    is_cd = 0;
    if ( S_ISCHR(stbuf->st_mode) || S_ISBLK(stbuf->st_mode) ) {
	cdfd = open(drive, (O_RDWR|O_NDELAY), 0);
	if ( cdfd >= 0 ) {
	    info.sch_address_format = CDROM_MSF_FORMAT;
	    info.sch_data_format = CDROM_CURRENT_POSITION;
	    info.sch_alloc_length = 0;
	    info.sch_track_number = 0;
	    info.sch_buffer = NULL;
	    /*
	     *
	     * Under Linux, EIO occurs when a disk is not present.
	     * This isn't 100% reliable, so we use the USE_MNTENT
	     * code above instead.
	     *
	     */
	    if ( (ioctl(cdfd, CDROM_READ_SUBCHANNEL, &info) == 0) ||
		    ERRNO_TRAYEMPTY(errno) ) {
		is_cd = 1;
	    }

	    close(cdfd);
	}
    }

    return(is_cd);
}