📄 filesys.c
字号:
(inbuf[10] != inbuf[17]) || (inbuf[11] != inbuf[16]) || (inbuf[12] != inbuf[15]) || (inbuf[13] != inbuf[14]) || (temp1 == temp2));}/* * Compute iso9660_endCDtime. * * "begin" is in MM:SS:FF format */int iso9660_endCDtime(int begin, int size){ if (size < 0) { return (begin); } return(adjCDtime(begin, logical2physical(size), 1));}#ifdef RE_SORT /* enable to customize sorting *//* "insort" ==> insert & sort.. * for adding to pre-sorted iso9660_file array */void iso9660_insort(int reset, int end){ int i,j; struct DIR_REC tmp; static unsigned short last_index; if (reset) { last_index = end; return; } else if (end==last_index) return; /* first file in directory */ /* find out where new file should be inserted.. * between "begin" and "end". */ for (j = end-1; j >= last_index; j--) { if (strncmp(iso9660_file[end].name, iso9660_file[j].name, 8) >= 0) { break; } } j++; /* insertion point */ if (j == end) return; /* already in correct position..*/ /* new file inserted at "j" position */ memcpy(&tmp, &iso9660_file[end], DIR_REC_LEN); for (i = end; i > j; i--) { memcpy(&iso9660_file[i], &iso9660_file[i-1], DIR_REC_LEN); asm("nop"); /* tight loop */ } memcpy(&iso9660_file[j], &tmp, DIR_REC_LEN);}#endif /* RE_SORT */#if NOT_USED /* use library *//* * ASCII character set for reference... * * PRINTABLE ASCII CHARACTER CODES: * Character Hex Char Hex Char Hex * ---------------- ----------- ----------- * SPACE 20 @ 40 $ 60 * ! 21 A 41 a 61 * " 22 B 42 b 62 * # 23 C 43 c 63 * $ 24 D 44 d 64 * % 25 E 45 e 65 * & 26 F 46 f 66 * ' 27 G 47 g 67 * ( 28 H 48 h 68 * ) 29 I 49 i 69 * * 2A J 4A j 6A * + 2B K 4B k 6B * , 2C L 4C l 6C * - 2D M 4D m 6D * . 2E N 4E n 6E * / 2F O 4F o 6F * 0 30 P 50 p 70 * 1 31 Q 51 q 71 * 2 32 R 52 r 72 * 3 33 S 53 s 73 * 4 34 T 54 t 74 * 5 35 U 55 u 75 * 6 36 V 56 v 76 * 7 37 W 57 w 77 * 8 38 X 58 x 78 * 9 39 Y 59 y 79 * : 3A Z 5A z 7A * ; 3B [ 5B { 7B * < 3C \ 5C | 7C * = 3D ] 5D } 7D * > 3E ^ 5E ~ 7E * ? 3F _ 5F * ---------------------------------------------------- * END OF PRINTABLE CODES */#define TO_UPPER 1 /* convert lower-case to upper-case */ #define TO_LOWER 0 /* convert upper-case to lower-case */ int strncmp(char *s1, char *s2, int n){ int i, val1, val2, return_val; char *src1, *src2; src1=s1; src2=s2; for (i = 0; i < n; i++) { val1 = *src1; val2 = *src2; #if TO_UPPER if (val1 >= 'a' && val1 <= 'z') val1 -= 0x20; if (val2 >= 'a' && val2 <= 'z') val2 -= 0x20;#endif#if TO_LOWER if (val1 >= 'A' && val1 <= 'Z') val1 += 0x20; if (val2 >= 'A' && val2 <= 'Z') val2 += 0x20;#endif if (val1 && val2) { return_val = val1 - val2; if (return_val) break; } else { if (!(val1) && !(val2)) return_val = 0; else { return_val = (val1) ? 1 : -1; } break; } src1++;src2++; } return (return_val);}/* Function: Used as "scan function" in scan_getnsector(). Parses current dir/file records for specified file location. input: size: number of sectors to scan. cptr: "file name" output: 0: failed to find file. loc: location(msf) of file, if successful. last_val: not used.*/static int FS_find_file_loc(int size, uchar *cptr, int *last_val){ struct iso_directory_record *pdir; char *curBuf, *nxtBuf; char *begBuf, *endBuf; int reclen, namelen; unsigned int flags; int loc, sz, search_cnt=0; int last_record = 0; int clen, temp; uchar filename[MAX_JOLIET_STRING+1];#ifdef UDF struct UDF_FileIdentDesc *pudir;#endif /* clear buffer */ memcpy(filename, (uchar *)dram(PCM_zero_start), MAX_JOLIET_STRING); clen = strlen(cptr); /* target filename length */ begBuf = nxtBuf = (char *)dram(VBV_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 = -1; /* 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); /* for case insensitive match of "file name" */ 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++ > sizeof(struct iso_directory_record)) { last_record = -1; /* quit */ break; } else continue; } search_cnt = 0; pdir = (struct iso_directory_record *)curBuf; reclen = pdir->length[0]; /* < 256 (8bits) */ loc = get_litend32(pdir->extent, 4); sz = get_litend32(pdir->size, 4); /* in bytes */ if ((reclen<=0) || (reclen>=100) || (loc<=0) || (sz<=0)) { CPRINTF("INVALID SIZE", loc); break;/* impossible..but don't quit */ } loc = logical2physical(loc + 150); /* LBA to MSF */ flags = *pdir->flags; nxtBuf = curBuf + reclen; namelen = *pdir->name_len; if ((namelen==1) && ((pdir->name[0] == 0) || (pdir->name[0] == 1))) continue; /* skip . */ /* for case insensitive match of "file name" */ FS_process_name(pdir->name, filename, namelen, sec_vol_table); CPRINTF(filename, 0); } if (!(flags & 0x2)){ /* case insensitive match of "file name" */ if (!strncmp(filename, cptr, clen)) return (loc); } } while (1); return(last_record);}#endif NOT_USED#ifdef PARSE_ASSOC_FILE_AS_DIR/* * This function searches the input string for '.' or ';'. * * ISO9660 specifies that file-records shall contain '.' and ';' * in their filename. * * NOTE: using SVD (Joliet) nullifies the above rules.. * effectively making the checks in this function useless! * (In other words, enable "PARSE_ASSOC_FILE_AS_DIR" at your * own risk!) */ int iso9660_filename(char *str, int file_len){ int i; char tmp; for (i = 0; i < file_len; i++) tmp = str[i]; if ((tmp == '.') || (tmp == ';')) return (1); return (0);}#endif /* PARSE_ASSOC_FILE_AS_DIR */#ifdef JPEG_DEC/* Function: Check Info.cd file for Kodak PictureCD identifier. input: file_msf: "Info.cd" file location. output: 0: failed to find Kodak PictureCD ID. non-zero: found Kodak PictureCD ID.*/static int FS_check_infocd(unsigned int file_msf){ char *begBuf; /* getSectors() data to ABV */ if (!getSectors(file_msf, 1, 0)) return(0); begBuf = (unsigned char *)dram(ABV_start); return (!strncmp(begBuf, MSG_kodakID, 23));}#define MALLOC_MAX 200typedef struct MallocHeader { char *addr; int size; int flag;} MallocHeader;/* the last buffer is always free */static int malloc_start;static int malloc_end;void init_GX_malloc(int heap_start, int heap_end){ int i; MallocHeader *curr; malloc_start = heap_start; malloc_end = heap_end; curr = (MallocHeader*) dram(malloc_start); curr->size = (malloc_end - malloc_start)*4 - (MALLOC_MAX+1)*sizeof(MallocHeader); curr->addr = (char*)curr + (MALLOC_MAX+1)*sizeof(MallocHeader); curr->flag = 0; for (i=1;i<=MALLOC_MAX;i++) { curr[i].addr=0; curr[i].size=0; curr[i].flag=0; }}char *GX_malloc(int nbytes) { int i,j,k; MallocHeader *curr; nbytes = ((nbytes-1)/4+1)*4; curr = (MallocHeader*) dram(malloc_start); for (i=0;i<MALLOC_MAX;i++) { if (curr[i].flag==0 && curr[i].size>=nbytes) { if (curr[i].size>nbytes) { /* insert a free buffer for extra free space */ for (k=i+1;k<MALLOC_MAX;k++) if (curr[k].flag==0) break; for (j=k;j>i+1;j++) curr[j]=curr[j-1]; curr[i+1].addr=curr[i].addr+nbytes; curr[i+1].size=curr[i].size-nbytes; } curr[i].size = nbytes; curr[i].flag = 1; return curr[i].addr; } } return 0;}void malloc_gc() { int i,j, sz, nf; MallocHeader *curr; curr = (MallocHeader*) dram(malloc_start); curr[MALLOC_MAX].addr=0; curr[MALLOC_MAX].flag=0; curr[MALLOC_MAX].size=0; for (i=0;i<MALLOC_MAX;i++) { if (curr[i].flag==1 && curr[i].size>0) continue; if (curr[i].size<=0) continue; sz = curr[i].size; nf = 0; for (j=i+1;j<MALLOC_MAX;j++) { if (curr[j].flag==1 && curr[j].size>0) break; if (curr[j].size<=0) break; sz += curr[j].size; nf++; } if (nf>0) { curr[i].size = sz; for (j=i+nf+1;j<=MALLOC_MAX;j++) { curr[j-nf]=curr[j]; } } }}#ifdef DEBUGvoid malloc_check() { int i; int yp=20; int len; char buf[16]; char cl; MallocHeader *curr; curr = (MallocHeader*) dram(start); cl = FindNearestColorIndex(0xff); GPClearScrn(cl); cl = FindNearestColorIndex(0xff0000); for (i=0;i<MALLOC_MAX;i++) { if (curr[i].size<=0) continue; len=sprint_x(buf,i); GPDrawStringAtPosition(40,yp, buf,len, cl, 1); len=sprint_x(buf,curr[i].flag); GPDrawStringAtPosition(60,yp, buf,len, cl, 1); len=sprint_x(buf,curr[i].addr); GPDrawStringAtPosition(80,yp, buf,len, cl, 1); len=sprint_x(buf,curr[i].size); GPDrawStringAtPosition(160,yp, buf,len, cl, 1); yp += 20; } ShowPage(); delay(4);}#endifvoid GX_free(void* in_addr) { int i; char *addr=in_addr; MallocHeader *curr; curr = (MallocHeader*) dram(malloc_start); for (i=0;i<MALLOC_MAX;i++) { if (curr[i].flag==0) continue; if (curr[i].size<=0) continue; if (addr>=curr[i].addr && addr<curr[i].addr+curr[i].size) { curr[i].flag=0; /* Garbage cleaning here */ malloc_gc(); break; } }}#endif /* JPEG_DEC */#ifdef UDF/************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -