📄 filesys.c
字号:
* -1: failed dsa_go() or servo problem * 0: no sync pattern * 1: if successful */ if (status == -2) { /* status: -2 */ return (-1); /* abort */ } else if (status < 1) { /* status: 0, -1 */ break; /* update file info..if any */ } /* good */ #ifdef ABNORMAL_VCD if (fs_scan_mode) { mp3 |= search_dir_file("EXT", "SCANDATA.DAT", get_size, dir); } else #endif {#ifdef JPEG_DEC if(dir == 0 ) is_FUJI_cd(get_size);#endif mp3 |= rec_dir_file(get_size, dir); } if (mp3 & 0xf0) { /* check if processed last record */ mp3 &= 0x0f; /* mask out "last record" info */ break; /* update file info */ } /* prepare for next getSectors */ dram_clear(VBV_start, MAX_SECTORS*512); size -= MAX_SECTORS; loc = adjCDtime(loc, logical2physical(get_size), 1); } while (size > 0); if (mp3 & 1) { /* record number of MP3 files in one directory */#ifdef MULTI_EXT_FILE iso9660_dir[dir].dir = dir_file_cnt;#else iso9660_dir[dir].dir = iso9660_file_cnt - dir_file_cnt;#endif real_track_cnt++; } return(0);}/* * Copy the name in psrc to pdst. In the process, map lower to upper case. * Also change non-alphanumerics to '_'. * * If there is no name... * 1) for directories, show directory number. (NOTE: we only list * directories containing "valid" files,i.e. MP3. Therefore, the * "numbered" directories may not be ordered consecutively) * 2) for files, show file number relative to current directory. * * input: * psrc: source string * pdst: destination buffer * cnt: directory flag[11:8] | relative file/directory count[7:0] * namelen: size of string in bytes * * output: */static void iso9660_assign_name(psrc, pdst, cnt, namelen)char *psrc, *pdst;int cnt, namelen;{ int k; int loop, max_len, ch_cnt = 0; unsigned short tmp; max_len = (namelen>DIR_REC_NAME_LENGTH) ? DIR_REC_NAME_LENGTH : namelen; /* find last "dot" location */ loop = -1; for (k = 0; k < max_len; k++) { if (!*(psrc+k)) break; if (*(psrc+k) == '.') loop = k; } /* in case we don't find "." in name */ if (k && (loop<0)) loop = k; for (k = 0; k < loop; k++, pdst++) { tmp = psrc[k]; /* We only have fonts between 'A' and 'Z' */ if ((tmp > 'Z') || (tmp < '0') || ((tmp > '9') && (tmp <'A'))){ /* show '_' for non-alphanumeric character */ if (tmp != ' ') tmp = '_'; /* underscore */ if (k==0 || k==1) ch_cnt++; } if (ch_cnt >=2) { k = 0; pdst -= 1; break; } *pdst = tmp; } /* If there is no name... * 1) for directories, show directory number. (NOTE: we only list * directories containing "valid" files,i.e. MP3. Therefore, the * "numbered" directories may not be ordered consecutively) * 2) for files, show file number relative to current directory. */ if (!k) { if (cnt & 0x8000) { /* directory flag */ memcpy(pdst, MSG_dir, 6); } else { memcpy(pdst, MSG_file, 6); } pdst=hex2string(pdst+5, (cnt&0xff)); } *pdst = 0;}/* input: dir_index - directory index. 0 for root. output: (last_record[7:4]|MP3_found[3:0]) MP3_found - 0: no MP3. 1: found MP3 files 2: found subdirectories 3: found MP3 files and subdirectories last_record - 1: indicates last record found.*/ static int rec_dir_file(int size, int dir_index){ static uchar multi_ext_rec; /* for MULTI_EXT_FILE */ struct iso_directory_record *pdir; char *curBuf, *nxtBuf; char *begBuf, *endBuf; int namelen; unsigned int flags, reclen; int loc, sz, bsz, temp; int MP3_found = 0; int last_record = 0; int search_cnt = 0; uchar filename[MAX_JOLIET_STRING+1];#ifdef UDF struct UDF_FileIdentDesc *pudir;#endif begBuf = nxtBuf = (char *)dram(GETSECTOR_DATA_START); endBuf = begBuf + (size<<11); do{ curBuf = nxtBuf;#ifdef UDF if (fs_type == UDF_FS) { if (curBuf>=endBuf) break; /* reached end of current buffer */ pudir = (struct UDF_FileIdentDesc *)curBuf; /* Check File ID before parsing */ temp = pudir->descTag[0] | (pudir->descTag[1]<<8); if (temp != 0x0101) { CPRINTF("FIX DIR", iso9660_dir[dir_index].loc); nxtBuf = curBuf + 1; if (search_cnt++ > sizeof(struct UDF_FileIdentDesc)) { last_record = 0x10; /* quit */ break; } else continue; } search_cnt = 0; namelen = pudir->lengthFileIdent[0]; CPRINTF("NAMELEN",namelen); temp = pudir->lengthOfImpUse[0] | (pudir->lengthOfImpUse[1]<<8); CPRINTF("IMPUSE LENGTH",temp); reclen = 4*((int)(namelen + temp + 38 +3)/4); CPRINTF("REC LENGTH",reclen); if (reclen<=0 || reclen>=0x400) break; flags = pudir->fileCharacteristics[0] & 0x2; CPRINTF("FILE FLAGS",flags); nxtBuf = curBuf + reclen; if ((namelen<3) && ((pudir->fileIdent[temp+2] < 0x20)|| (pudir->fileIdent[temp+2] > 0x7e))) continue; /* skip . */ loc=get_bigend32(pudir->icb_extLocation_LBN, 0)+partition_start; UDF_read_ICB(loc, &loc, &sz); loc = logical2physical(loc+150); CPRINTF("LOCATION", loc); CPRINTF("SIZE", sz); /* clear buffer */ memcpy(filename, (uchar *)dram(PCM_zero_start), MAX_JOLIET_STRING); FS_process_name(pudir->fileIdent+temp+1, filename, namelen, 1); namelen>>=1; CPRINTF(filename, 0); } else #endif UDF { /* Sanity check for "iso_directory_record" */ if(bad_iso_directory_record(curBuf)) { CPRINTF("FIX DIR", iso9660_dir[dir_index].loc); nxtBuf = curBuf + 1; if (nxtBuf>=endBuf) break; /* reached end of current buffer */ if (search_cnt++ > 0xff) { /* rec_len max */ last_record = 0x10; /* quit */ break; } else continue; } search_cnt = 0; pdir = (struct iso_directory_record *)curBuf; reclen = pdir->length[0]; /* < 256 (8bits data) */ loc = get_litend32(pdir->extent, 4); sz = get_litend32(pdir->size, 4); flags = *pdir->flags; nxtBuf = curBuf + reclen; if (loc<=0) { CPRINTF("INVALID LOC", loc); continue;/* impossible..but don't quit */ } else { loc = logical2physical(loc + 150); /* LBA to MSF */ if (loc == xMAX_CDTIME) continue; } namelen = *pdir->name_len; if ((namelen==1) && ((pdir->name[0] == 0) || (pdir->name[0] == 1))) continue; /* skip . */ if (namelen > MAX_JOLIET_STRING) namelen = MAX_JOLIET_STRING; /* clear buffer */ memcpy(filename, (uchar *)dram(PCM_zero_start), MAX_JOLIET_STRING); FS_process_name(pdir->name, filename, namelen, sec_vol_table); if (sec_vol_table) namelen >>= 1; CPRINTF(filename, 0); } bsz = sz; /* Bytes */ /* add 2047 to avoid truncation from bytes to sectors conversion * NOTE: for ID3 tag info, should dump the last 2 sectors of MP3 * file! */ sz = (sz + 2047) >> 11; /* Sectors */#ifdef PARSE_ASSOC_FILE_AS_DIR /* To support rare discs that set directories as * "associated file", we are checking the associated files * as directories. * For safety, we also add a check to make sure that the record * is really not a file-record. * * NOTE: * The "filename" check is not 100% reliable. Consequently, * the side-effect is that some standard discs will take MUCH, * MUCH longer to initialize. */ if ((flags & 0x4) && !iso9660_filename(filename,namelen)) { flags = 0x2; }#endif /* PARSE_ASSOC_FILE_AS_DIR */ if (flags & 0x2){ /* directory */#ifdef DATA_CD if (iso9660_dir_cnt < MAX_DIR_CNT) { #ifdef JPEG_DEC if(is_Kodak_pictureCD && (strncmp(filename, MSG_pictures, 8))) { /* only care about "PICTURES" directory */ continue; } if(dir_index == 0){ if((is_fuji_cd&0xF0)==0xE0 || (is_fuji_cd&0xA3)>=0xA2 ){ if( strncmp(filename, "DCIM", 4) ) continue; } }else { if((is_fuji_cd&0xF0)==0xE0) if( !strncmp(filename, "LOW_RES", 7) ) { namelen = 8; /* force to use previous dir name */ strcpy(filename, iso9660_dir[dir_index].name); } } #endif iso9660_dir[iso9660_dir_cnt].loc = loc; iso9660_dir[iso9660_dir_cnt].size = sz; iso9660_dir[iso9660_dir_cnt].dir = -1; /* it is dir */#if (defined (JPEG_DEC) || defined (GAMEBOY)) iso9660_dir[iso9660_dir_cnt].bsize = bsz;#endif #ifdef HOST_SLAVE iso9660_dir[iso9660_dir_cnt].parent_dir = dir_index;#endif iso9660_assign_name(filename, iso9660_dir[iso9660_dir_cnt].name, iso9660_dir_cnt|0x8000, namelen); iso9660_dir_cnt++; MP3_found |= 2; /* found subdirectory */ }#endif /* DATA_CD */ } else{ /* file */ if (namelen > 3){ /* check MP3 and JPEG */#ifdef JPEG_DEC if ((num_of_session > 1) && !strncmp(filename, MSG_infocd, 7)) { is_Kodak_pictureCD = FS_check_infocd(loc); } if((is_fuji_cd&0xF0)==0xE0 ) if( strncmp(filename,"FL",2) && strncmp(filename,"DL",2) ) continue;#endif JPEG_DEC#ifdef FLASH_UPDATE#if defined(UPDATE_FLASH_LOGO) if (!strncmp(filename, logo4update, 8)) { update_logo(loc, bsz); }#elif defined(UPDATE_FLASH_ALL) if (!strncmp(filename, rom4update, 8)) { update_flash(loc, bsz); }#endif#endif /* FLASH_UPDATE */#ifdef DATA_CD if (iso9660_file_cnt < MAX_FILE_CNT) { /* for suffix matching, only need to specify upper-case patterns. NOTE: add new suffixes to suffix_filter[] when needed. */ reclen = (uint)FS_filter_filename(filename, namelen); /* use "reclen" for ID */ if (reclen) {#ifdef MP3CDG if (reclen == MP3CDG_ID) { temp = mp3cdg_file_cnt; iso9660_file[temp].mp3cdg_loc=loc|(MP3CDG_ID<<24); iso9660_file[temp].mp3cdg_size = sz; mp3cdg_file_cnt++; /* don't save as an individual record */ continue; } else#endif { iso9660_file[iso9660_file_cnt].loc = loc|(reclen<<24);#ifdef GAMEBOY /* game uses sector size not end msf */ if (reclen & (GAME_GB_ID|GAME_NES_ID)) temp = sz; else#endif temp = iso9660_endCDtime(loc, sz); iso9660_file[iso9660_file_cnt].size = temp; } #ifdef JPEG_DEC if (reclen == JPEG_ID) { iso9660_file[iso9660_file_cnt].bsize = bsz;#ifdef JPEG_DGST /* last jpg file is more useful */ jpg_file_cnt = iso9660_file_cnt+1;#endif }#endif /* JPEG_DEC */ /* common file processing */ /* parent dir */ iso9660_file[iso9660_file_cnt].dir = (multi_ext_rec<<8)|dir_index;#ifdef MULTI_EXT_FILE iso9660_assign_name(filename, iso9660_file[iso9660_file_cnt].name, dir_file_cnt, namelen);#else iso9660_assign_name(filename, iso9660_file[iso9660_file_cnt].name, iso9660_file_cnt - dir_file_cnt, namelen);#endif#ifdef RE_SORT /* before incrementing iso9660_file_cnt! */ iso9660_insort(0,iso9660_file_cnt);#endif iso9660_file_cnt++; /* file records */#ifdef MULTI_EXT_FILE if (flags & 0x80) { multi_ext_rec++; } else { /* last record of multi-ext file */ multi_ext_rec = 0; /* reset */ num_of_track++; /* total individual files */ dir_file_cnt++; /* files in current dir */ }#endif /* MULTI_EXT_FILE */ real_track[real_track_cnt] = dir_index; MP3_found |= 1; if (iso9660_file_cnt==1) { CDinfo.type = CD_DATA;#ifdef JPEG_DEC if (is_Kodak_pictureCD) OUTOSD(1, MSG_pictureCD, MSG_pictureCD, 5); else #endif JPEG_DEC { OUTOSD(1, MSG_data, MSG_data, 5); } } } }#endif /* DATAT_CD */ } } } while (1); return(last_record | MP3_found);}static int bad_iso_directory_record(char *inbuf){ int temp1, temp2; temp1 = get_litend32(inbuf, 6); /* extent */ temp2 = get_litend32(inbuf, 10); /* size..reversed byte-order */ /* Sanity checks for "iso_directory_record": * 1. Length of Directory Record should be non-zero. * 2. "extent" and "size" fields should be * "Both-Byte order" format. * 3. check for invalid "extent" and "size". */ return ((inbuf[0] == 0) || (inbuf[2] != inbuf[9]) || (inbuf[3] != inbuf[8]) || (inbuf[4] != inbuf[7]) || (inbuf[5] != inbuf[6]) ||
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -