📄 fs.lst
字号:
261 2 fs->volumeId.RootEntryCount/16;
262 2 }
263 1 return(((sector-base)-((sector-base)%fs->volumeId.SectorsPerCluster))/fs->volumeId.SectorsPerCluster+2 )
-;
264 1 }
265 /*****************************************************************************/
266
267 /* ****************************************************************************
268 * euint32 fs_getNextFreeCluster(FileSystem *fs,euint32 startingcluster)
269 * Description: This functions searches for a free cluster, starting it's search at
270 * cluster startingcluster. This allow to speed up searches and try to avoid
271 * fragmentation. Implementing rollover search is still to be done.
272 * Return value: If a free cluster is found it's number is returned. If none is
273 * found 0 is returned.
274 */
275 euint32 fs_getNextFreeCluster(FileSystem *fs,euint32 startingcluster)
276 {
277 1 euint32 r;
278 1
279 1 while(startingcluster<fs->DataClusterCount){
280 2 r=fat_getNextClusterAddress(fs,startingcluster,0);
281 2 if(r==0){
282 3 return(startingcluster);
283 3 }
284 2 startingcluster++;
285 2 }
286 1 return(0);
287 1 }
288 /*****************************************************************************/
289
290 /* ****************************************************************************
291 * euint32 fs_giveFreeClusterHint(FileSystem *fs)
292 *
293 * Description: This function should return a clusternumber that is free or
294 * lies close before free clusters. The result MUST be checked to see if
295 * it is free! Implementationhint: search the largest clusternumber in the
296 * files in the rootdirectory.
297 *
298 * Return value: Returns it's best guess.
299 */
300 euint32 fs_giveFreeClusterHint(FileSystem *fs)
301 {
302 1 return(2); /* Now THIS is a hint ;) */
303 1 }
*** WARNING C47 IN LINE 300 OF SRC\FS.C: 'fs': unreferenced parameter
304 /*****************************************************************************/
305
306 /* ****************************************************************************
307 * esint8 fs_findFile(FileSystem *fs,eint8* filename,FileLocation *loc,euint32 *lastDir)
308 *
309 * Description: This function looks if the given filename is on the given fs
310 * and, if found, fills in its location in loc.
311 * The function will first check if the pathname starts with a slash. If so it will
312 * set the starting directory to the rootdirectory. Else, it will take the firstcluster-
313 * currentdir (That you can change with chdir()) as startingpoint.
314 * The lastdir pointer will be the first cluster of the last directory fs_findfile
315 * enters. It starts out at the root/current dir and then traverses the path along with
316 * fs_findFile.
317 * It is set to 0 in case of errors (like dir/dir/dir/file/dir/dir...)
318 * Return value: Returns 0 when nothing was found, 1 when the thing found
319 * was a file and 2 if the thing found was a directory.
ARM COMPILER V2.42, fs 27/03/06 10:45:50 PAGE 6
320 */
321
322 esint8 fs_findFile(FileSystem *fs,eint8* filename,FileLocation *loc,euint32 *lastDir)
323 {
324 1 euint32 fccd,tmpclus;
325 1 eint8 ffname[11],*next,it=0,filefound=0;
326 1
327 1 if(*filename=='/'){
328 2 fccd = fs_getFirstClusterRootDir(fs);
329 2 filename++;
330 2 if(!*filename){
331 3 if(lastDir)*lastDir=fccd;
332 3 return(2);
333 3 }
334 2 }else{
335 2 fccd = fs->FirstClusterCurrentDir;
336 2 }
337 1
338 1 if(lastDir)*lastDir=fccd;
339 1
340 1 while((next=file_normalToFatName(filename,ffname))!=0){
341 2 if((tmpclus=dir_findinDir(fs,ffname,fccd,loc,DIRFIND_FILE))==0)return(0);
342 2 it++;
343 2 if(loc->attrib&ATTR_DIRECTORY){
344 3 fccd = tmpclus;
345 3 filename = next;
346 3 if(lastDir)*lastDir=fccd;
347 3 if(filefound)*lastDir=0;
348 3 }else{
349 3 filefound=1;
350 3 if((file_normalToFatName(next,ffname))!=0){
351 4 return(0);
352 4 }else{
353 4 filename=next;
354 4 }
355 3 }
356 2 }
357 1
358 1 if(it==0)return(0);
359 1 if(loc->attrib&ATTR_DIRECTORY || !filefound)return(2);
360 1 return(1);
361 1 }
362 /*****************************************************************************/
363
364 esint16 fs_findFreeFile(FileSystem *fs,eint8* filename,FileLocation *loc,euint8 mode)
365 {
366 1 euint32 targetdir=0;
367 1 eint8 ffname[11];
368 1
369 1 if(fs_findFile(fs,filename,loc,&targetdir))return(0);
370 1 if(!dir_getFatFileName(filename,ffname))return(0);
371 1 if(dir_findinDir(fs,ffname,targetdir,loc,DIRFIND_FREE)){
372 2 return(1);
373 2 }else{
374 2 if(dir_addCluster(fs,targetdir)){
375 3 return(0);
376 3 }else{
377 3 if(dir_findinDir(fs,ffname,targetdir,loc,DIRFIND_FREE)){
378 4 return(1);
379 4 }
380 3 }
381 2 }
382 1
383 1 return(0);
384 1 }
*** WARNING C47 IN LINE 364 OF SRC\FS.C: 'mode': unreferenced parameter
ARM COMPILER V2.42, fs 27/03/06 10:45:50 PAGE 7
385 /*****************************************************************************/
386
387 /* ****************************************************************************
388 * euint32 fs_getLastCluster(FileSystem *fs,ClusterChain *Cache)
389 * Description: This function searches the last cluster of a chain.
390 * Return value: The LastCluster (also stored in cache);
391 */
392 euint32 fs_getLastCluster(FileSystem *fs,ClusterChain *Cache)
393 {
394 1 if(Cache->DiscCluster==0){
395 2 Cache->DiscCluster=Cache->FirstCluster;
396 2 Cache->LogicCluster=0;
397 2 }
398 1
399 1 if(Cache->LastCluster==0)
400 1 {
401 2 while(fat_getNextClusterChain(fs, Cache)==0)
402 2 {
403 3 Cache->LogicCluster+=Cache->Linear;
404 3 Cache->DiscCluster+=Cache->Linear;
405 3 Cache->Linear=0;
406 3 }
407 2 }
408 1 return(Cache->LastCluster);
409 1 }
410 /*****************************************************************************/
411
412 euint32 fs_getFirstClusterRootDir(FileSystem *fs)
413 {
414 1 switch(fs->type){
415 2 case FAT32:
416 2 return(fs->volumeId.RootCluster);
417 2 break;
418 2 default:
419 2 return(1);
420 2 break;
421 2 }
422 1 }
423 /*****************************************************************************/
424
425 void fs_initClusterChain(FileSystem *fs,ClusterChain *cache,euint32 cluster_addr)
426 {
427 1 cache->FirstCluster=cluster_addr;
428 1 cache->DiscCluster=cluster_addr;
429 1 cache->LogicCluster=0;
430 1 cache->LastCluster=0; /* Warning flag here */
431 1 cache->Linear=0;
432 1 cache->ClusterCount=0; /* 0 means NOT known */
433 1 }
*** WARNING C47 IN LINE 425 OF SRC\FS.C: 'fs': unreferenced parameter
434 /*****************************************************************************/
435
436 void fs_setFirstClusterInDirEntry(FileRecord *rec,euint32 cluster_addr)
437 {
438 1 rec->FirstClusterHigh=cluster_addr>>16;
439 1 rec->FirstClusterLow=cluster_addr&0xFFFF;
440 1 }
441 /*****************************************************************************/
442
443 esint8 fs_flushFs(FileSystem *fs)
444 {
445 1 return(part_flushPart(fs->part,0,fs->SectorCount));
446 1 }
447 /*****************************************************************************/
448
449 esint8 fs_umount(FileSystem *fs)
ARM COMPILER V2.42, fs 27/03/06 10:45:50 PAGE 8
450 {
451 1 return(fs_flushFs(fs));
452 1 }
453 /*****************************************************************************/
454
455 esint8 fs_clearCluster(FileSystem *fs,euint32 cluster)
456 {
457 1 euint16 c;
458 1 euint8* buf;
459 1
460 1 for(c=0;c<(fs->volumeId.SectorsPerCluster);c++){
461 2 buf = part_getSect(fs->part,fs_clusterToSector(fs,cluster)+c,IOM_MODE_READWRITE);
462 2 memClr(buf,512);
463 2 part_relSect(fs->part,buf);
464 2 }
465 1 return(0);
466 1 }
467
468 esint8 fs_getFsInfo(FileSystem *fs,euint8 force_update)
469 {
470 1 euint8 *buf;
471 1
472 1 if(!fs->type==FAT32)return(0);
473 1 buf = part_getSect(fs->part,FS_INFO_SECTOR,IOM_MODE_READONLY);
474 1 if(ex_getb32(buf,0)!=FSINFO_MAGIC_BEGIN || ex_getb32(buf,508)!=FSINFO_MAGIC_END){
475 2 part_relSect(fs->part,buf);
476 2 return(-1);
477 2 }
478 1 fs->FreeClusterCount = ex_getb32(buf,488);
479 1 fs->NextFreeCluster = ex_getb32(buf,492);
480 1 part_relSect(fs->part,buf);
481 1 if(force_update){
482 2 fs->FreeClusterCount=fat_countFreeClusters(fs);
483 2 }
484 1 return(0);
485 1 }
486
487 esint8 fs_setFsInfo(FileSystem *fs)
488 {
489 1 euint8* buf;
490 1
491 1 if(!fs->type==FAT32)return(0);
492 1 buf = part_getSect(fs->part,FS_INFO_SECTOR,IOM_MODE_READWRITE);
493 1 if(ex_getb32(buf,0)!=FSINFO_MAGIC_BEGIN || ex_getb32(buf,508)!=FSINFO_MAGIC_END){
494 2 part_relSect(fs->part,buf);
495 2 return(-1);
496 2 }
497 1 ex_setb32(buf,488,fs->FreeClusterCount);
498 1 ex_setb32(buf,492,fs->NextFreeCluster);
499 1 part_relSect(fs->part,buf);
500 1 return(0);
501 1 }
502
ARM COMPILER V2.42, fs 27/03/06 10:45:50 PAGE 9
ASSEMBLY LISTING OF GENERATED OBJECT CODE
*** EXTERNALS:
EXTERN CODE16 (memClr?T)
EXTERN CODE16 (ex_getb16?T)
EXTERN CODE16 (ex_getb32?T)
EXTERN CODE16 (ex_setb32?T)
EXTERN CODE16 (part_getSect?T)
EXTERN CODE16 (part_relSect?T)
EXTERN CODE16 (part_flushPart?T)
EXTERN CODE16 (dir_findinDir?T)
EXTERN CODE16 (dir_getFatFileName?T)
EXTERN CODE16 (dir_addCluster?T)
EXTERN CODE16 (file_normalToFatName?T)
EXTERN CODE16 (fat_getNextClusterAddress?T)
EXTERN CODE16 (fat_getNextClusterChain?T)
EXTERN CODE16 (fat_countFreeClusters?T)
EXTERN CODE16 (?C?UDIV?T)
EXTERN CODE16 (?C?SDIV?T)
*** PUBLICS:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -