static int mp3cue_readcue(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) { log_debug2("enter with %s", path); cue_t *cue = mp3cue_readcue_in_hash(path, false); char *fullpath = make_path(path); char *cuefile = isCueFile(fullpath); struct stat st; stat(cuefile, &st); MK_READONLY(st); if (cue != NULL && cue_valid(cue)) { int i, N; for (i = 0, N = cue_count(cue); i < N; i++) { cue_entry_t *entry = cue_entry(cue, i); data_entry_t *d = datahash_get(DATA, fullpath); if (d != NULL) { filler(buf, cue_entry_vfile(entry), d->st, 0); } else { filler(buf, cue_entry_vfile(entry), &st, 0); } } } cue_destroy(cue); mc_free(cuefile); mc_free(fullpath); return 0; }
static int mp3cue_getattr(const char *path, struct stat *stbuf) { log_debug2("mp3cue_getattr %s", path); char *fullpath = make_path(path); char *cue = isCueFile(fullpath); if (cue != NULL) { log_debug2("mp3cue_getattr cue=%s", cue); int ret = stat(cue, stbuf); PMK_READONLY(stbuf); stbuf->st_mode -= S_IFREG; stbuf->st_mode += S_IFDIR; mc_free(fullpath); mc_free(cue); DE_MONITOR( cue_t *cue=mp3cue_readcue_in_hash(path, false); cue_destroy(cue); );
PICO_INTERNAL int Load_CD_Image(const char *cd_img_name, cd_img_type type) { int i, j, num_track, Cur_LBA, index, ret; int iso_name_len, missed, cd_img_sectors; _scd_track *Tracks = Pico_mcd->TOC.Tracks; char tmp_name[256], tmp_ext[10], tmp_ext_u[10]; cue_data_t *cue_data = NULL; pm_file *pmf; static const char *exts[] = { "%02d.mp3", " %02d.mp3", "-%02d.mp3", "_%02d.mp3", " - %02d.mp3", "%d.mp3", " %d.mp3", "-%d.mp3", "_%d.mp3", " - %d.mp3", }; if (PicoCDLoadProgressCB != NULL) PicoCDLoadProgressCB(cd_img_name, 1); Unload_ISO(); /* is this a .cue? */ cue_data = cue_parse(cd_img_name); if (cue_data != NULL) { cd_img_name = cue_data->tracks[1].fname; Tracks[0].ftype = cue_data->tracks[1].type; } else Tracks[0].ftype = type == CIT_BIN ? CT_BIN : CT_ISO; Tracks[0].F = pmf = pm_open(cd_img_name); if (Tracks[0].F == NULL) { Tracks[0].ftype = 0; Tracks[0].Length = 0; if (cue_data != NULL) cue_destroy(cue_data); return -1; } if (Tracks[0].ftype == CT_ISO) cd_img_sectors = pmf->size >>= 11; // size in sectors else cd_img_sectors = pmf->size /= 2352;
/* checks if fname points to valid MegaCD image */ int PicoCdCheck(const char *fname_in, int *pregion) { const char *fname = fname_in; unsigned char buf[32]; pm_file *cd_f; int region = 4; // 1: Japan, 4: US, 8: Europe char ext[5]; cue_track_type type = CT_UNKNOWN; cue_data_t *cue_data = NULL; // opens a cue, or searches for one cue_data = cue_parse(fname_in); if (cue_data != NULL) { fname = cue_data->tracks[1].fname; type = cue_data->tracks[1].type; } else { get_ext(fname_in, ext); if (strcasecmp(ext, ".cue") == 0) return -1; } cd_f = pm_open(fname); if (cue_data != NULL) cue_destroy(cue_data); if (cd_f == NULL) return 0; // let the upper level handle this if (pm_read(buf, 32, cd_f) != 32) { pm_close(cd_f); return -1; } if (!strncasecmp("SEGADISCSYSTEM", (char *)buf+0x00, 14)) { if (type && type != CT_ISO) elprintf(EL_STATUS, ".cue has wrong type: %i", type); type = CT_ISO; // Sega CD (ISO) } if (!strncasecmp("SEGADISCSYSTEM", (char *)buf+0x10, 14)) { if (type && type != CT_BIN) elprintf(EL_STATUS, ".cue has wrong type: %i", type); type = CT_BIN; // Sega CD (BIN) } if (type == CT_UNKNOWN) { pm_close(cd_f); return 0; } pm_seek(cd_f, (type == CT_ISO) ? 0x100 : 0x110, SEEK_SET); pm_read(media_id_header, sizeof(media_id_header), cd_f); /* it seems we have a CD image here. Try to detect region now.. */ pm_seek(cd_f, (type == CT_ISO) ? 0x100+0x10B : 0x110+0x10B, SEEK_SET); pm_read(buf, 1, cd_f); pm_close(cd_f); if (buf[0] == 0x64) region = 8; // EU if (buf[0] == 0xa1) region = 1; // JAP lprintf("detected %s Sega/Mega CD image with %s region\n", type == CT_BIN ? "BIN" : "ISO", region != 4 ? (region == 8 ? "EU" : "JAP") : "USA"); if (pregion != NULL) *pregion = region; return type; }