1 /*----------------------------------------------------------------------/ 2 / Test if the file is contiguous / 3 /----------------------------------------------------------------------*/ 4 test_contiguous_file(FIL * fp,int * cont)5FRESULT test_contiguous_file ( 6 FIL* fp, /* [IN] Open file object to be checked */ 7 int* cont /* [OUT] 1:Contiguous, 0:Fragmented or zero-length */ 8 ) 9 { 10 DWORD clst, clsz, step; 11 FSIZE_t fsz; 12 FRESULT fr; 13 14 15 *cont = 0; 16 fr = f_lseek(fp, 0); /* Validates and prepares the file */ 17 if (fr != FR_OK) return fr; 18 19 #if FF_MAX_SS == FF_MIN_SS 20 clsz = (DWORD)fp->obj.fs->csize * FF_MAX_SS; /* Cluster size */ 21 #else 22 clsz = (DWORD)fp->obj.fs->csize * fp->obj.fs->ssize; 23 #endif 24 fsz = fp->obj.objsize; 25 if (fsz > 0) { 26 clst = fp->obj.sclust - 1; /* A cluster leading the first cluster for first test */ 27 while (fsz) { 28 step = (fsz >= clsz) ? clsz : (DWORD)fsz; 29 fr = f_lseek(fp, f_tell(fp) + step); /* Advances file pointer a cluster */ 30 if (fr != FR_OK) return fr; 31 if (clst + 1 != fp->clust) break; /* Is not the cluster next to previous one? */ 32 clst = fp->clust; fsz -= step; /* Get current cluster for next test */ 33 } 34 if (fsz == 0) *cont = 1; /* All done without fail? */ 35 } 36 37 return FR_OK; 38 } 39