static DEVICE_IMAGE_LOAD(cdrom) { dev_cdrom_t *cdrom = get_safe_token(&image.device()); chd_error err = (chd_error)0; chd_file *chd = NULL; astring tempstring; if (image.software_entry() == NULL) { err = chd_open_file( image.image_core_file(), CHD_OPEN_READ, NULL, &chd ); /* CDs are never writeable */ if ( err ) goto error; } else { chd = get_disk_handle(image.device().machine, image.device().subtag(tempstring,"cdrom")); } /* open the CHD file */ cdrom->cdrom_handle = cdrom_open( chd ); if ( ! cdrom->cdrom_handle ) goto error; return IMAGE_INIT_PASS; error: if ( chd ) chd_close( chd ); if ( err ) image.seterror( IMAGE_ERROR_UNSPECIFIED, chd_get_error_string( err ) ); return IMAGE_INIT_FAIL; }
static int internal_load_mess_cd(mess_image *image, const char *metadata) { chd_error err = 0; struct mess_cd *cd; chd_file *chd; int id = image_index_in_device(image); cd = get_drive(image); /* open the CHD file */ err = chdcd_open_ref(image, CHD_OPEN_READ, NULL, &chd); /* CDs are never writable */ if (err) goto error; /* open the CD-ROM file */ cd->cdrom_handle = cdrom_open(chd); if (!cd->cdrom_handle) goto error; drive_handles[id] = cd->cdrom_handle; return INIT_PASS; error: if (chd) chd_close(chd); if (err) image_seterror(image, IMAGE_ERROR_UNSPECIFIED, chd_get_error_string(err)); return INIT_FAIL; }
void cdrom_image_device::device_start() { // try to locate the CHD from a DISK_REGION chd_file *chd = get_disk_handle( machine(), owner()->tag() ); if( chd != NULL ) { m_cdrom_handle = cdrom_open( chd ); } else { m_cdrom_handle = NULL; } }
bool cdrom_image_device::call_load() { chd_error err = (chd_error)0; chd_file *chd = NULL; astring tempstring; if (m_cdrom_handle) cdrom_close(m_cdrom_handle); if (software_entry() == NULL) { if (strstr(m_image_name,".chd") && is_loaded()) { err = m_self_chd.open( *image_core_file() ); /* CDs are never writeable */ if ( err ) goto error; chd = &m_self_chd; } } else { chd = get_disk_handle(device().machine(), device().subtag(tempstring,"cdrom")); } /* open the CHD file */ if (chd) { m_cdrom_handle = cdrom_open( chd ); } else { m_cdrom_handle = cdrom_open( m_image_name ); } if ( ! m_cdrom_handle ) goto error; return IMAGE_INIT_PASS; error: if ( chd && chd == &m_self_chd ) m_self_chd.close( ); if ( err ) seterror( IMAGE_ERROR_UNSPECIFIED, chd_file::error_string( err ) ); return IMAGE_INIT_FAIL; }
void cdrom_image_device::device_start() { // try to locate the CHD from a DISK_REGION chd_file *chd = machine().rom_load().get_disk_handle(owner()->tag().c_str()); if( chd != nullptr ) { m_cdrom_handle = cdrom_open( chd ); } else { m_cdrom_handle = nullptr; } }
image_init_result cdrom_image_device::call_load() { chd_error err = (chd_error)0; chd_file *chd = nullptr; if (m_cdrom_handle) cdrom_close(m_cdrom_handle); if (software_entry() == nullptr) { if (is_filetype("chd") && is_loaded()) { err = m_self_chd.open( image_core_file() ); /* CDs are never writeable */ if ( err ) goto error; chd = &m_self_chd; } } else { chd = device().machine().rom_load().get_disk_handle(device().subtag("cdrom").c_str()); } /* open the CHD file */ if (chd) { m_cdrom_handle = cdrom_open( chd ); } else { m_cdrom_handle = cdrom_open(m_image_name.c_str()); } if ( ! m_cdrom_handle ) goto error; return image_init_result::PASS; error: if ( chd && chd == &m_self_chd ) m_self_chd.close( ); if ( err ) seterror( IMAGE_ERROR_UNSPECIFIED, chd_file::error_string( err ) ); return image_init_result::FAIL; }
bool cdrom_media_present(const char *devpath) { int fd, rc; fd = cdrom_open(devpath, __func__); if (fd < 0) return false; rc = ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT); close(fd); return rc == CDS_DISC_OK; }
int main(int argc, char *argv[]) { int randomReps = RANDOM_ACCESS_MAX_REPS; srand(time(NULL)); output = fopen("results.csv", "w"); cdrom_init(&cd); cdrom_open(&cd, "/dev/sr0"); if(strcmp(argv[1], "speed") == 0) { speedTest(NULL); } else if(strcmp(argv[1], "random") == 0) { randomReps = atoi(argv[2]); if(randomReps <= RANDOM_ACCESS_MAX_REPS) { if(randomReps > 20) { randomAccessTest(randomReps, FALSE); } else { randomAccessTest(randomReps, TRUE); } } else { g_print("Too Many Reps\n"); } } else if(strcmp(argv[1], "seek") == 0) { seekTest(); } else { g_print("Usage: eaa (speed|random count)\n"); } fclose(output); cdrom_close(&cd); return 0; }
// global functions void stvcd_reset(void) { state = STATE_UNK; hirqmask = 0xffff; hirqreg = 0; cr1 = 'C'; cr2 = ('D'<<8) | 'B'; cr3 = ('L'<<8) | 'O'; cr4 = ('C'<<8) | 'K'; cd_stat = 0; if (curdir != (direntryT *)NULL) free((void *)curdir); curdir = (direntryT *)NULL; // no directory yet // reset flag vars buffull = sectorstore = 0; freeblocks = 200; // open device if (cdrom) { cdrom_close(cdrom); cdrom = (cdrom_file *)NULL; } #ifdef MESS cdrom = mess_cd_get_cdrom_file_by_number(0); #else cdrom = cdrom_open(get_disk_handle(0)); #endif memset(databuf, 0, (512*1024)); dbufptr = 0; dbuflen = 0; wordsread = 0; if (cdrom) { logerror("Opened CD-ROM successfully, reading root directory\n"); read_new_dir(0xffffff); // read root directory } }
void cdrom_init(const char *devpath) { int fd, rc; fd = cdrom_open(devpath, __func__); if (fd < 0) return; /* We disable autoclose so that any attempted mount() operation doesn't * close the tray, and disable CDO_LOCK to prevent the lock status * changing on open()/close() */ rc = ioctl(fd, CDROM_CLEAR_OPTIONS, CDO_LOCK | CDO_AUTO_CLOSE); if (rc < 0) pb_debug("%s: CLEAR CDO_LOCK|CDO_AUTO_CLOSE failed: %s\n", __func__, strerror(errno)); close(fd); }
void cdrom_eject(const char *devpath) { int fd, rc; fd = cdrom_open(devpath, __func__); if (fd < 0) return; /* unlock cdrom device */ rc = ioctl(fd, CDROM_LOCKDOOR, 0); if (rc < 0) pb_log("%s: CDROM_LOCKDOOR(unlock) failed: %s\n", __func__, strerror(errno)); rc = ioctl(fd, CDROMEJECT, 0); if (rc < 0) pb_log("%s: CDROM_EJECT failed: %s\n", __func__, strerror(errno)); close(fd); }
void SysMediaArrived(const char *path, int type) { // Replace the "cdrom" entry (we are polling, it's unique) if (type == MEDIA_CD && !PrefsFindBool("nocdrom")) PrefsReplaceString("cdrom", path); // Wait for media to be available for reading if (open_su_file_handles) { const int MAX_WAIT = 5; for (int i = 0; i < MAX_WAIT; i++) { if (access(path, R_OK) == 0) break; switch (errno) { case ENOENT: // Unlikely case EACCES: // MacOS X is mounting the media sleep(1); continue; } printf("WARNING: Cannot access %s (%s)\n", path, strerror(errno)); return; } } for (open_su_file_handle *p = open_su_file_handles; p != NULL; p = p->next) { su_file_handle * const fh = p->fh; // Re-open CD-ROM device if (fh->is_cdrom && type == MEDIA_CD) { cdrom_close(fh); if (cdrom_open(fh, path)) { fh->is_media_present = true; MountVolume(fh); } } } }
static int mcdx_block_open(struct inode *inode, struct file *file) { struct s_drive_stuff *p = inode->i_bdev->bd_disk->private_data; return cdrom_open(&p->info, inode, file); }
static int mcd_block_open(struct inode *inode, struct file *file) { return cdrom_open(&mcd_info, inode, file); }
static int parsechd (struct cdunit *cdu, struct zfile *zcue, const TCHAR *img) { chd_error err; struct cdrom_file *cdf; struct zfile *f = zfile_dup (zcue); if (!f) return 0; chd_file *cf = new chd_file(); err = cf->open(f, false, NULL); if (err != CHDERR_NONE) { write_log (_T("CHD '%s' err=%d\n"), zfile_getname (zcue), err); zfile_fclose (f); return 0; } if (!(cdf = cdrom_open (cf))) { write_log (_T("Couldn't open CHD '%s' as CD\n"), zfile_getname (zcue)); cf->close (); zfile_fclose (f); return 0; } cdu->chd_f = cf; cdu->chd_cdf = cdf; const cdrom_toc *stoc = cdrom_get_toc (cdf); cdu->tracks = stoc->numtrks; uae_u32 hunkcnt = cf->hunk_count (); uae_u32 hunksize = cf->hunk_bytes (); uae_u32 cbytes; chd_codec_type compr; for (int i = 0; i <cdu->tracks; i++) { int size; const cdrom_track_info *strack = &stoc->tracks[i]; struct cdtoc *dtrack = &cdu->toc[i]; dtrack->address = strack->physframeofs; dtrack->offset = strack->chdframeofs; dtrack->adr = cdrom_get_adr_control (cdf, i) >> 4; dtrack->ctrl = cdrom_get_adr_control (cdf, i) & 15; switch (strack->trktype) { case CD_TRACK_MODE1: case CD_TRACK_MODE2_FORM1: size = 2048; break; case CD_TRACK_MODE1_RAW: case CD_TRACK_MODE2_RAW: case CD_TRACK_AUDIO: default: size = 2352; break; case CD_TRACK_MODE2: case CD_TRACK_MODE2_FORM_MIX: size = 2336; break; case CD_TRACK_MODE2_FORM2: size = 2324; break; } dtrack->suboffset = size; dtrack->subcode = strack->subtype == CD_SUB_NONE ? 0 : strack->subtype == CD_SUB_RAW ? 1 : 2; dtrack->chdtrack = strack; dtrack->size = size; dtrack->enctype = ENC_CHD; dtrack->fname = my_strdup (zfile_getname (zcue)); dtrack->filesize = cf->logical_bytes (); dtrack->track = i + 1; dtrack[1].address = dtrack->address + strack->frames; if (cf->hunk_info(dtrack->offset * CD_FRAME_SIZE / hunksize, compr, cbytes) == CHDERR_NONE) { TCHAR tmp[100]; uae_u32 c = (uae_u32)compr; for (int j = 0; j < 4; j++) { uae_u8 b = c >> ((3 - j) * 8); if (c < 10) { b += '0'; } if (b < ' ' || b >= 127) b = '.'; tmp[j] = b; } tmp[4] = 0; dtrack->extrainfo = my_strdup (tmp); } }