📄 dir.lst
字号:
248 */
249 euint32 dir_findinDir(FileSystem *fs, eint8* fatname,euint32 firstcluster, FileLocation *loc, euint8 mode
-)
250 {
251 1 euint32 c=0,cluster;
252 1 ClusterChain Cache;
253 1
ARM COMPILER V2.42, dir 27/03/06 10:45:48 PAGE 5
254 1 Cache.DiscCluster = Cache.FirstCluster = firstcluster;
255 1 Cache.LogicCluster = Cache.LastCluster = Cache.Linear = 0;
256 1
257 1 if(firstcluster <= 1){
258 2 return(dir_findinRootArea(fs,fatname,loc,mode));
259 2 }
260 1
261 1 while(!fat_LogicToDiscCluster(fs,&Cache,c++)){
262 2 if((cluster=dir_findinCluster(fs,Cache.DiscCluster,fatname,loc,mode))){
263 3 return(cluster);
264 3 }
265 2 }
266 1 return(0);
267 1 }
268
269 /* ****************************************************************************
270 * euint32 dir_findinDir(FileSystem *fs, eint8* fatname,euint32 firstcluster, FileLocation *loc, euint8 m
-ode)
271 * This function will search for an existing (fatname) or free directory entry
272 * in the rootdirectory-area of a FAT12/FAT16 filesystem.
273 * Return value: 0 on failure, firstcluster on finding file, and 1 on finding free spot.
274 */
275 euint32 dir_findinRootArea(FileSystem *fs,eint8* fatname, FileLocation *loc, euint8 mode)
276 {
277 1 euint32 c,fclus;
278 1 euint8 *buf=0;
279 1
280 1 if((fs->type != FAT12) && (fs->type != FAT16))return(0);
281 1
282 1 for(c=fs->FirstSectorRootDir;c<(fs->FirstSectorRootDir+fs->volumeId.RootEntryCount/32);c++){
283 2 buf = part_getSect(fs->part,c,IOM_MODE_READONLY);
284 2 if((fclus=dir_findinBuf(buf,fatname,loc,mode))){
285 3 if(loc)loc->Sector=c;
286 3 part_relSect(fs->part,buf);
287 3 return(fclus);
288 3 }
289 2 part_relSect(fs->part,buf);
290 2 }
291 1 part_relSect(fs->part,buf);
292 1 return(0);
293 1 }
294
295 /* ****************************************************************************
296 * esint8 dir_getFatFileName(eint8* filename, eint8* fatfilename)
297 * This function will take a full directory path, and strip off all leading
298 * dirs and characters, leaving you with the MS-DOS notation of the actual filename.
299 * Return value: 1 on success, 0 on not being able to produca a filename
300 */
301 esint8 dir_getFatFileName(eint8* filename, eint8* fatfilename)
302 {
303 1 eint8 ffnamec[11],*next,nn=0;
304 1
305 1 memClr(ffnamec,11); memClr(fatfilename,11);
306 1 next = filename;
307 1
308 1 if(*filename=='/')next++;
309 1
310 1 while((next=file_normalToFatName(next,ffnamec))){
311 2 memCpy(ffnamec,fatfilename,11);
312 2 nn++;
313 2 }
314 1 if(nn)return(1);
315 1 return(0);
316 1 }
317
318 /* ****************************************************************************
ARM COMPILER V2.42, dir 27/03/06 10:45:48 PAGE 6
319 * esint8 dir_addCluster(FileSystem *fs,euint32 firstCluster)
320 * This function extends a directory by 1 cluster + optional the number of
321 * clusters you want pre-allocated. It will also delete the contents of that
322 * cluster. (or clusters)
323 * Return value: 0 on success, -1 on fail
324 */
325 esint8 dir_addCluster(FileSystem *fs,euint32 firstCluster)
326 {
327 1 euint32 lastc,logicalc;
328 1 ClusterChain cache;
329 1
330 1 fs_initClusterChain(fs,&cache,firstCluster);
331 1 if(fat_allocClusterChain(fs,&cache,1)){
332 2 return(-1);
333 2 }
334 1 lastc = fs_getLastCluster(fs,&cache);
335 1 if(CLUSTER_PREALLOC_DIRECTORY){
336 2 if(fat_allocClusterChain(fs,&cache,CLUSTER_PREALLOC_DIRECTORY)){
337 3 return(-1);
338 3 }
339 2 logicalc = fat_DiscToLogicCluster(fs,firstCluster,lastc);
340 2 while(!fat_LogicToDiscCluster(fs,&cache,++logicalc)){
341 3 fs_clearCluster(fs,cache.DiscCluster);
342 3 }
343 2 }else{
344 2 fs_clearCluster(fs,lastc);
345 2 }
346 1 return(0);
347 1 }
348
349
ARM COMPILER V2.42, dir 27/03/06 10:45:48 PAGE 7
ASSEMBLY LISTING OF GENERATED OBJECT CODE
*** EXTERNALS:
EXTERN CODE16 (strMatch?T)
EXTERN CODE16 (memCpy?T)
EXTERN CODE16 (memClr?T)
EXTERN CODE16 (part_getSect?T)
EXTERN CODE16 (part_relSect?T)
EXTERN CODE16 (fs_clusterToSector?T)
EXTERN CODE16 (fs_getLastCluster?T)
EXTERN CODE16 (fs_initClusterChain?T)
EXTERN CODE16 (fs_clearCluster?T)
EXTERN CODE16 (file_normalToFatName?T)
EXTERN CODE16 (fat_LogicToDiscCluster?T)
EXTERN CODE16 (fat_allocClusterChain?T)
EXTERN CODE16 (fat_DiscToLogicCluster?T)
EXTERN CODE16 (?C?SDIV?T)
*** PUBLICS:
PUBLIC dir_getFileStructure?T
PUBLIC dir_createDirectoryEntry?T
PUBLIC dir_createDefaultEntry?T
PUBLIC dir_setFirstCluster?T
PUBLIC dir_setFileSize?T
PUBLIC dir_findinDir?T
PUBLIC dir_findinBuf?T
PUBLIC dir_findinCluster?T
PUBLIC dir_findinRootArea?T
PUBLIC dir_getFatFileName?T
PUBLIC dir_updateDirectoryEntry?T
PUBLIC dir_addCluster?T
PUBLIC dir_findFileinBuf?T
PUBLIC dir_findFreeEntryinBuf?T
*** CODE SEGMENT '?PR?dir_getFileStructure?T?dir':
33: void dir_getFileStructure(FileSystem *fs,FileRecord *filerec,FileLocation *loc)
00000000 B5F0 PUSH {R4-R7,LR}
00000002 1C17 MOV R7,R2 ; loc
00000004 ---- Variable 'loc' assigned to Register 'R7' ----
00000004 1C0E MOV R6,R1 ; filerec
00000006 ---- Variable 'filerec' assigned to Register 'R6' ----
00000006 1C05 MOV R5,R0 ; fs
00000008 ---- Variable 'fs' assigned to Register 'R5' ----
34: {
00000008 ; SCOPE-START
37: buf=part_getSect(fs->part,loc->Sector,IOM_MODE_READONLY);
00000008 1C28 MOV R0,R5 ; fs
0000000A 6800 LDR R0,[R0,#0x0] ; fs
0000000C 1C39 MOV R1,R7 ; loc
0000000E 6809 LDR R1,[R1,#0x0] ; loc
00000010 2201 MOV R2,#0x1
00000012 F7FF BL part_getSect?T ; T=0x0001 (1)
00000014 FFF5 BL part_getSect?T ; T=0x0001 (2)
00000016 1C04 MOV R4,R0 ; buf
00000018 ---- Variable 'buf' assigned to Register 'R4' ----
38: *filerec=*(((FileRecord*)buf)+loc->Offset);
00000018 1C38 MOV R0,R7 ; loc
0000001A 7900 LDRB R0,[R0,#0x4]
0000001C 0140 LSL R0,R0,#0x5
0000001E 1C21 MOV R1,R4 ; buf
00000020 1809 ADD R1,R0 ; buf
00000022 1C30 MOV R0,R6 ; filerec
00000024 2208 MOV R2,#0x8
00000026 L_70:
00000026 C908 LDMIA R1!,{R3}
ARM COMPILER V2.42, dir 27/03/06 10:45:48 PAGE 8
00000028 C008 STMIA R0!,{R3}
0000002A 1E52 SUB R2,R2,#0x1
0000002C D1FB BNE L_70 ; T=0x00000026
39: part_relSect(fs->part,buf);
0000002E 1C28 MOV R0,R5 ; fs
00000030 6800 LDR R0,[R0,#0x0] ; fs
00000032 1C21 MOV R1,R4 ; buf
00000034 F7FF BL part_relSect?T ; T=0x0001 (1)
00000036 FFE4 BL part_relSect?T ; T=0x0001 (2)
00000038 ; SCOPE-END
40: }
00000038 BCF0 POP {R4-R7}
0000003A BC08 POP {R3}
0000003C 4718 BX R3
0000003E ENDP ; 'dir_getFileStructure?T'
*** CODE SEGMENT '?PR?dir_createDirectoryEntry?T?dir':
50: void dir_createDirectoryEntry(FileSystem *fs,FileRecord *filerec,FileLocation *loc)
00000000 B5F0 PUSH {R4-R7,LR}
00000002 1C17 MOV R7,R2 ; loc
00000004 ---- Variable 'loc' assigned to Register 'R7' ----
00000004 1C0E MOV R6,R1 ; filerec
00000006 ---- Variable 'filerec' assigned to Register 'R6' ----
00000006 1C05 MOV R5,R0 ; fs
00000008 ---- Variable 'fs' assigned to Register 'R5' ----
51: {
00000008 ; SCOPE-START
54: buf = part_getSect(fs->part,loc->Sector,IOM_MODE_READWRITE);
00000008 1C28 MOV R0,R5 ; fs
0000000A 6800 LDR R0,[R0,#0x0] ; fs
0000000C 1C39 MOV R1,R7 ; loc
0000000E 6809 LDR R1,[R1,#0x0] ; loc
00000010 2202 MOV R2,#0x2
00000012 F7FF BL part_getSect?T ; T=0x0001 (1)
00000014 FFF5 BL part_getSect?T ; T=0x0001 (2)
00000016 1C04 MOV R4,R0 ; buf
00000018 ---- Variable 'buf' assigned to Register 'R4' ----
55: memCpy(filerec,buf+(loc->Offset*sizeof(*filerec)),sizeof(*filerec));
00000018 1C38 MOV R0,R7 ; loc
0000001A 7900 LDRB R0,[R0,#0x4]
0000001C 0140 LSL R0,R0,#0x5
0000001E 1C21 MOV R1,R4 ; buf
00000020 1809 ADD R1,R0 ; buf
00000022 1C30 MOV R0,R6 ; filerec
00000024 2220 MOV R2,#0x20
00000026 F7FF BL memCpy?T ; T=0x0001 (1)
00000028 FFEB BL memCpy?T ; T=0x0001 (2)
56: part_relSect(fs->part,buf);
0000002A 1C28 MOV R0,R5 ; fs
0000002C 6800 LDR R0,[R0,#0x0] ; fs
0000002E 1C21 MOV R1,R4 ; buf
00000030 F7FF BL part_relSect?T ; T=0x0001 (1)
00000032 FFE6 BL part_relSect?T ; T=0x0001 (2)
00000034 ; SCOPE-END
57: }
00000034 BCF0 POP {R4-R7}
00000036 BC08 POP {R3}
00000038 4718 BX R3
0000003A ENDP ; 'dir_createDirectoryEntry?T'
*** CODE SEGMENT '?PR?dir_createDefaultEntry?T?dir':
67: void dir_createDefaultEntry(FileSystem *fs,FileRecord *filerec,eint8* fatfilename)
00000000 B510 PUSH {R4,LR}
00000002 ---- Variable 'fatfilename' assigned to Register 'R2' ----
00000002 1C0C MOV R4,R1 ; filerec
00000004 ---- Variable 'filerec' assigned to Register 'R4' ----
69: memCpy(fatfilename,filerec->FileName,11);
00000004 1C10 MOV R0,R2 ; fatfilename
ARM COMPILER V2.42, dir 27/03/06 10:45:48 PAGE 9
00000006 1C21 MOV R1,R4 ; filerec
00000008 220B MOV R2,#0xB
0000000A F7FF BL memCpy?T ; T=0x0001 (1)
0000000C FFF9 BL memCpy?T ; T=0x0001 (2)
70: filerec->Attribute=0x00;
0000000E 2000 MOV R0,#0x0
00000010 1C21 MOV R1,R4 ; filerec
00000012 72C8 STRB R0,[R1,#0xB]
71: filerec->NTReserved=0x00;
00000014 2000 MOV R0,#0x0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -