FatFS/documents/res/app5.c
savelij13 7cb0c2d1e6 fatfs v0.13c October 14, 2018:
- Supported stdint.h for C99 and later. (integer.h was included in ff.h)
- Fixed reading a directory gets infinite loop when the last directory entry is not empty. (appeared at R0.12)
- Fixed creating a sub-directory in the fragmented sub-directory on the exFAT volume collapses FAT chain of the parent directory. (appeared at R0.12)
- Fixed f_getcwd() cause output buffer overrun when the buffer has a valid drive number. (appeared at R0.13b)
2025-09-11 10:35:10 +03:00

39 lines
1.3 KiB
C

/*----------------------------------------------------------------------/
/ Test if the file is contiguous /
/----------------------------------------------------------------------*/
FRESULT test_contiguous_file (
FIL* fp, /* [IN] Open file object to be checked */
int* cont /* [OUT] 1:Contiguous, 0:Fragmented or zero-length */
)
{
DWORD clst, clsz, step;
FSIZE_t fsz;
FRESULT fr;
*cont = 0;
fr = f_lseek(fp, 0); /* Validates and prepares the file */
if (fr != FR_OK) return fr;
#if FF_MAX_SS == FF_MIN_SS
clsz = (DWORD)fp->obj.fs->csize * FF_MAX_SS; /* Cluster size */
#else
clsz = (DWORD)fp->obj.fs->csize * fp->obj.fs->ssize;
#endif
fsz = fp->obj.objsize;
if (fsz > 0) {
clst = fp->obj.sclust - 1; /* A cluster leading the first cluster for first test */
while (fsz) {
step = (fsz >= clsz) ? clsz : (DWORD)fsz;
fr = f_lseek(fp, f_tell(fp) + step); /* Advances file pointer a cluster */
if (fr != FR_OK) return fr;
if (clst + 1 != fp->clust) break; /* Is not the cluster next to previous one? */
clst = fp->clust; fsz -= step; /* Get current cluster for next test */
}
if (fsz == 0) *cont = 1; /* All done without fail? */
}
return FR_OK;
}