From aef38baf44fe0e394084f3951ef4a948aeda104a Mon Sep 17 00:00:00 2001 From: Caoruihong Date: Fri, 11 Sep 2020 17:21:26 +0800 Subject: [PATCH] =?UTF-8?q?!2=20=E3=80=90=E8=BD=BB=E9=87=8F=E7=BA=A7=20PR?= =?UTF-8?q?=E3=80=91=EF=BC=9A#I1UT4S=20=20=E6=8E=92=E7=89=88=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20Merge=20pull=20request=20!2=20from=20Caoruihong/N/A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fs/fat/virpart/src/virpartff.c | 1112 ++++++++++++++++---------------- 1 file changed, 556 insertions(+), 556 deletions(-) diff --git a/fs/fat/virpart/src/virpartff.c b/fs/fat/virpart/src/virpartff.c index 1bed9afc..4f0e5da3 100755 --- a/fs/fat/virpart/src/virpartff.c +++ b/fs/fat/virpart/src/virpartff.c @@ -96,95 +96,95 @@ extern FATFS *FatFs[FF_VOLUMES]; */ FRESULT follow_virentry(FFOBJID *obj, const TCHAR *path) { -TCHAR keyword[FF_MAX_LFN + 1] = {0}; -FATFS *fs = obj->fs; -INT len; -UINT i; - -(void)memset_s(keyword, sizeof(keyword), 0, sizeof(keyword)); -/* Search and copy the first segment in path */ -for (len = 0; *path != '/' && *path != '\\' && *path != '\0' && len < FF_MAX_LFN; path++, len++) { -keyword[len] = *path; -} + TCHAR keyword[FF_MAX_LFN + 1] = {0}; + FATFS *fs = obj->fs; + INT len; + UINT i; + + (void)memset_s(keyword, sizeof(keyword), 0, sizeof(keyword)); + /* Search and copy the first segment in path */ + for (len = 0; *path != '/' && *path != '\\' && *path != '\0' && len < FF_MAX_LFN; path++, len++) { + keyword[len] = *path; + } -if (len == 0 || len > _MAX_ENTRYLENGTH) { -return FR_DENIED; -} + if (len == 0 || len > _MAX_ENTRYLENGTH) { + return FR_DENIED; + } -/* -* Compare the segment does match one for virtual partitions' entry or not, -* replace the FATFS if the result is positive -*/ -for (i = 0; i < fs->vir_amount; i++) { -if (!CHILDFS(fs, i)) { - return FR_INT_ERR; -} -if (memcmp((CHILDFS(fs, i))->namelabel, keyword, _MAX_ENTRYLENGTH + 1) == 0) { - obj->fs = CHILDFS(fs, i); - return FR_OK; -} -} + /* + * Compare the segment does match one for virtual partitions' entry or not, + * replace the FATFS if the result is positive + */ + for (i = 0; i < fs->vir_amount; i++) { + if (!CHILDFS(fs, i)) { + return FR_INT_ERR; + } + if (memcmp((CHILDFS(fs, i))->namelabel, keyword, _MAX_ENTRYLENGTH + 1) == 0) { + obj->fs = CHILDFS(fs, i); + return FR_OK; + } + } -return FR_DENIED; + return FR_DENIED; } FRESULT f_checkname(const TCHAR *path) { -FRESULT res; -DIR dj; -FATFS fs; -TCHAR *label = (TCHAR *)path; -DEF_NAMBUF - -(void)memset_s(&fs, sizeof(fs), 0, sizeof(fs)); -dj.obj.fs = &fs; -INIT_NAMBUF(&fs); -res = create_name(&dj, &path); -/* the last byte of file name can't be a space */ -if (res == FR_OK && dj.fn[11] == 0x20) { -res = FR_INVALID_NAME; -return res; -} + FRESULT res; + DIR dj; + FATFS fs; + TCHAR *label = (TCHAR *)path; + DEF_NAMBUF + + (void)memset_s(&fs, sizeof(fs), 0, sizeof(fs)); + dj.obj.fs = &fs; + INIT_NAMBUF(&fs); + res = create_name(&dj, &path); + /* the last byte of file name can't be a space */ + if (res == FR_OK && dj.fn[11] == 0x20) { + res = FR_INVALID_NAME; + return res; + } -FREE_NAMBUF(); + FREE_NAMBUF(); -for (; *label != '\0'; label++) { -if (label - path > _MAX_ENTRYLENGTH) { - res = FR_INVALID_NAME; - return res; -} -if (*label == '/' || *label == '\\') { - res = FR_INVALID_NAME; + for (; *label != '\0'; label++) { + if (label - path > _MAX_ENTRYLENGTH) { + res = FR_INVALID_NAME; + return res; + } + if (*label == '/' || *label == '\\') { + res = FR_INVALID_NAME; + return res; + } + } return res; } -} -return res; -} FATFS *f_getfatfs(int vol) { -FATFS *fs = NULL; -if (vol < 0 || vol >= FF_VOLUMES) { -fs = NULL; -} else { -fs = FatFs[vol]; -} -return fs; + FATFS *fs = NULL; + if (vol < 0 || vol >= FF_VOLUMES) { + fs = NULL; + } else { + fs = FatFs[vol]; + } + return fs; } static FRESULT FatfsCheckBoundParam(FATFS *fs, DWORD clust) { -if (fs->st_clst <= 2 || (fs->st_clst + fs->ct_clst) > fs->n_fatent) { -return FR_INT_ERR; -} -if (clust < 2 || clust > fs->n_fatent) { -return FR_INT_ERR; -} -if (clust >= (fs->st_clst + fs->ct_clst) || clust < fs->st_clst) { -return FR_CHAIN_ERR; -} + if (fs->st_clst <= 2 || (fs->st_clst + fs->ct_clst) > fs->n_fatent) { + return FR_INT_ERR; + } + if (clust < 2 || clust > fs->n_fatent) { + return FR_INT_ERR; + } + if (clust >= (fs->st_clst + fs->ct_clst) || clust < fs->st_clst) { + return FR_CHAIN_ERR; + } -return FR_OK; + return FR_OK; } /* @@ -197,38 +197,38 @@ return FR_OK; */ FRESULT f_boundary(FATFS *fs, DWORD clust) { -FFOBJID obj; -FRESULT res; -obj.fs = fs; -if (fs == NULL) { -return FR_INT_ERR; -} -if (fs->fs_type != FS_FAT32) { -return FR_INVAILD_FATFS; -} -ENTER_FF(fs); + FFOBJID obj; + FRESULT res; + obj.fs = fs; + if (fs == NULL) { + return FR_INT_ERR; + } + if (fs->fs_type != FS_FAT32) { + return FR_INVAILD_FATFS; + } + ENTER_FF(fs); -res = FatfsCheckBoundParam(fs, clust); -if (res != FR_OK) { -LEAVE_FF(fs, res); -} -for (; ;) { -clust = get_fat(&obj, clust); -if (clust == 0xFFFFFFFF) { - LEAVE_FF(fs, FR_DISK_ERR); -} -if (clust == 0x0FFFFFFF) { - break; -} -if (clust < 2 || clust >= fs->n_fatent) { - LEAVE_FF(fs, FR_INT_ERR); -} -if (clust >= (fs->st_clst + fs->ct_clst) || clust < fs->st_clst) { - LEAVE_FF(fs, FR_CHAIN_ERR); -} -} + res = FatfsCheckBoundParam(fs, clust); + if (res != FR_OK) { + LEAVE_FF(fs, res); + } + for (;;) { + clust = get_fat(&obj, clust); + if (clust == 0xFFFFFFFF) { + LEAVE_FF(fs, FR_DISK_ERR); + } + if (clust == 0x0FFFFFFF) { + break; + } + if (clust < 2 || clust >= fs->n_fatent) { + LEAVE_FF(fs, FR_INT_ERR); + } + if (clust >= (fs->st_clst + fs->ct_clst) || clust < fs->st_clst) { + LEAVE_FF(fs, FR_CHAIN_ERR); + } + } -LEAVE_FF(fs, FR_OK); + LEAVE_FF(fs, FR_OK); } /* @@ -240,76 +240,76 @@ LEAVE_FF(fs, FR_OK); */ FRESULT f_disvirfs(FATFS *fs) { -if (ISCHILD(fs)) { -return FR_INVAILD_FATFS; -} + if (ISCHILD(fs)) { + return FR_INVAILD_FATFS; + } -if (fs->vir_amount > _MAX_VIRVOLUMES) { -return FR_INT_ERR; -} + if (fs->vir_amount > _MAX_VIRVOLUMES) { + return FR_INT_ERR; + } -ENTER_FF(fs); + ENTER_FF(fs); -(void)f_unregvirfs(fs); -LEAVE_FF(fs, FR_OK); + (void)f_unregvirfs(fs); + LEAVE_FF(fs, FR_OK); } FRESULT f_unregvirfs(FATFS *fs) { -UINT i; + UINT i; -if (fs == NULL || ISCHILD(fs)) { -return FR_INVAILD_FATFS; -} + if (fs == NULL || ISCHILD(fs)) { + return FR_INVAILD_FATFS; + } -fs->vir_avail = FS_VIRDISABLE; -/* PARENT FATFS has linked to CHILD FATFS already */ -if (fs->child_fs != NULL) { -/* Followed the CHILD FATFS and free the memory */ -for (i = 0; i < fs->vir_amount; i++) { - if (CHILDFS(fs, i) != NULL) { - ff_memfree(CHILDFS(fs, i)); + fs->vir_avail = FS_VIRDISABLE; + /* PARENT FATFS has linked to CHILD FATFS already */ + if (fs->child_fs != NULL) { + /* Followed the CHILD FATFS and free the memory */ + for (i = 0; i < fs->vir_amount; i++) { + if (CHILDFS(fs, i) != NULL) { + ff_memfree(CHILDFS(fs, i)); + } + } + /* Free the 'child_fs' feild */ + ff_memfree(fs->child_fs); + fs->child_fs = NULL; + fs->vir_amount = 0xFFFFFFFF; } -} -/* Free the 'child_fs' feild */ -ff_memfree(fs->child_fs); -fs->child_fs = NULL; -fs->vir_amount = 0xFFFFFFFF; -} -return FR_OK; + return FR_OK; } static void FatfsSetParentFs(FATFS *pfs, FATFS *fs) { -pfs->fs_type = fs->fs_type; /* Copy the feild info from PARENT FATFS object */ -pfs->pdrv = fs->pdrv; -pfs->n_fats = fs->n_fats; -pfs->id = fs->id; -pfs->n_rootdir = fs->n_rootdir; -pfs->csize = fs->csize; + pfs->fs_type = fs->fs_type; /* Copy the feild info from PARENT FATFS object */ + pfs->pdrv = fs->pdrv; + pfs->n_fats = fs->n_fats; + pfs->id = fs->id; + pfs->n_rootdir = fs->n_rootdir; + pfs->csize = fs->csize; #if FF_MAX_SS != FF_MIN_SS -pfs->ssize = fs->ssize; + pfs->ssize = fs->ssize; #endif -pfs->sobj = fs->sobj; + pfs->sobj = fs->sobj; #if FF_FS_RPATH != 0 -pfs->cdir = 0; + pfs->cdir = 0; #endif -pfs->n_fatent = fs->n_fatent; -pfs->fsize = fs->fsize; -pfs->volbase = fs->volbase; -pfs->fatbase = fs->fatbase; -pfs->dirbase = fs->dirbase; -pfs->database = fs->database; -pfs->last_clst = 0xFFFFFFFF; /* Mark the 'last_clst' and 'free_clst' in CHILD FATFS is not been updated for now */ -pfs->free_clst = 0xFFFFFFFF; -pfs->st_clst = 0xFFFFFFFF; /* Mark the 'st_clst' and 'ct_clst' in CHILD FATFS is not been update for now. */ -pfs->ct_clst = 0xFFFFFFFF; -pfs->vir_flag = FS_CHILD; /* Mark the FATFS object is a CHILD */ -pfs->vir_avail = FS_VIRENABLE; /* Mark the CHILD object is enable for now */ -pfs->parent_fs = (void *)fs; /* Link to the PARENT object */ -pfs->child_fs = (void *)NULL; /* Link the unrelated feild to NULL */ + pfs->n_fatent = fs->n_fatent; + pfs->fsize = fs->fsize; + pfs->volbase = fs->volbase; + pfs->fatbase = fs->fatbase; + pfs->dirbase = fs->dirbase; + pfs->database = fs->database; + pfs->last_clst = 0xFFFFFFFF; /* Mark the 'last_clst' and 'free_clst' in CHILD FATFS is not been updated for now */ + pfs->free_clst = 0xFFFFFFFF; + pfs->st_clst = 0xFFFFFFFF; /* Mark the 'st_clst' and 'ct_clst' in CHILD FATFS is not been update for now. */ + pfs->ct_clst = 0xFFFFFFFF; + pfs->vir_flag = FS_CHILD; /* Mark the FATFS object is a CHILD */ + pfs->vir_avail = FS_VIRENABLE; /* Mark the CHILD object is enable for now */ + pfs->parent_fs = (void *)fs; /* Link to the PARENT object */ + pfs->child_fs = (void *)NULL; /* Link the unrelated feild to NULL */ } /* @@ -328,77 +328,77 @@ pfs->child_fs = (void *)NULL; /* Link the unrelated feild to NULL */ */ FRESULT f_regvirfs(FATFS *fs) { -UINT i; -FATFS *pfs = NULL; + UINT i; + FATFS *pfs = NULL; -if (fs == NULL || ISCHILD(fs)) { -return FR_INVAILD_FATFS; -} + if (fs == NULL || ISCHILD(fs)) { + return FR_INVAILD_FATFS; + } -if (fs->vir_amount > _MAX_VIRVOLUMES) { -return FR_INT_ERR; -} + if (fs->vir_amount > _MAX_VIRVOLUMES) { + return FR_INT_ERR; + } -fs->parent_fs = (void *)fs; /* Relink to itself */ -/* Mark the FATFS object is PARENT */ -fs->st_clst = 0xFFFFFFFF; -fs->ct_clst = 0xFFFFFFFF; -/* Allocate a space for linking to the child FATFS */ -fs->child_fs = (void **)ff_memalloc(fs->vir_amount * sizeof(void *)); -if (fs->child_fs == NULL) { -return FR_NOT_ENOUGH_CORE; -} -fs->vir_avail = FS_VIRENABLE; /* Mark the PARENT object is enable for now */ + fs->parent_fs = (void *)fs; /* Relink to itself */ + /* Mark the FATFS object is PARENT */ + fs->st_clst = 0xFFFFFFFF; + fs->ct_clst = 0xFFFFFFFF; + /* Allocate a space for linking to the child FATFS */ + fs->child_fs = (void **)ff_memalloc(fs->vir_amount * sizeof(void *)); + if (fs->child_fs == NULL) { + return FR_NOT_ENOUGH_CORE; + } + fs->vir_avail = FS_VIRENABLE; /* Mark the PARENT object is enable for now */ -/* Set the CHILD object field */ -for (i = 0; i < fs->vir_amount; i++) { -pfs = ff_memalloc(sizeof(FATFS)); /* Allocate a memeory for current child FATFS object */ -if (pfs == NULL) { /* If allocate failed, must call 'f_unregvirfs' to free the previous FATFS object memory */ - goto ERROUT; -} -FatfsSetParentFs(pfs, fs); -*(fs->child_fs + i) = (void *)pfs; -} + /* Set the CHILD object field */ + for (i = 0; i < fs->vir_amount; i++) { + pfs = ff_memalloc(sizeof(FATFS)); /* Allocate a memeory for current child FATFS object */ + if (pfs == NULL) { /* If allocate failed, must call 'f_unregvirfs' to free the previous FATFS object memory */ + goto ERROUT; + } + FatfsSetParentFs(pfs, fs); + *(fs->child_fs + i) = (void *)pfs; + } -return FR_OK; + return FR_OK; ERROUT: -while (i > 0) { ---i; -ff_memfree(*(fs->child_fs + i)); -} -ff_memfree(fs->child_fs); -fs->child_fs = NULL; + while (i > 0) { + --i; + ff_memfree(*(fs->child_fs + i)); + } + ff_memfree(fs->child_fs); + fs->child_fs = NULL; -return FR_NOT_ENOUGH_CORE; + return FR_NOT_ENOUGH_CORE; } static FRESULT FatfsCheckScanFatParam(FATFS *fs) { -if (fs == NULL) { -return FR_INVAILD_FATFS; -} + if (fs == NULL) { + return FR_INVAILD_FATFS; + } -if (ISNORMAL(fs)) { -return FR_DENIED; -} + if (ISNORMAL(fs)) { + return FR_DENIED; + } -if (fs->fs_type != FS_FAT32 || ISPARENT(fs)) { -return FR_INVAILD_FATFS; -} + if (fs->fs_type != FS_FAT32 || ISPARENT(fs)) { + return FR_INVAILD_FATFS; + } -if (fs->st_clst < 3 || fs->st_clst >= fs->n_fatent) { -return FR_INVAILD_FATFS; -} + if (fs->st_clst < 3 || fs->st_clst >= fs->n_fatent) { + return FR_INVAILD_FATFS; + } -if (fs->ct_clst == 0 || fs->ct_clst > (fs->n_fatent - 3)) { -return FR_INVAILD_FATFS; -} + if (fs->ct_clst == 0 || fs->ct_clst > (fs->n_fatent - 3)) { + return FR_INVAILD_FATFS; + } -if ((fs->st_clst + fs->ct_clst) > fs->n_fatent || (fs->st_clst + fs->ct_clst) < 3) { -return FR_INVAILD_FATFS; -} + if ((fs->st_clst + fs->ct_clst) > fs->n_fatent || (fs->st_clst + fs->ct_clst) < 3) { + return FR_INVAILD_FATFS; + } -return FR_OK; + return FR_OK; } /* @@ -415,114 +415,114 @@ return FR_OK; */ FRESULT f_scanfat(FATFS *fs) { -FRESULT res; -DWORD clst; -DWORD link; -FFOBJID obj; - -res = FatfsCheckScanFatParam(fs); -if (res != FR_OK) { -return res; -} + FRESULT res; + DWORD clst; + DWORD link; + FFOBJID obj; -ENTER_FF(fs); -res = FR_OK; -obj.fs = fs; + res = FatfsCheckScanFatParam(fs); + if (res != FR_OK) { + return res; + } -fs->free_clst = fs->ct_clst; -for (clst = fs->st_clst; clst < fs->st_clst + fs->ct_clst; clst++) { -link = get_fat(&obj, clst); -if (link == 0xFFFFFFFF) { - LEAVE_FF(fs, FR_DISK_ERR); -} -if (link == 0) { - continue; -} -fs->free_clst--; -} -fs->last_clst = fs->st_clst - 1; + ENTER_FF(fs); + res = FR_OK; + obj.fs = fs; -LEAVE_FF(fs, res); + fs->free_clst = fs->ct_clst; + for (clst = fs->st_clst; clst < fs->st_clst + fs->ct_clst; clst++) { + link = get_fat(&obj, clst); + if (link == 0xFFFFFFFF) { + LEAVE_FF(fs, FR_DISK_ERR); + } + if (link == 0) { + continue; + } + fs->free_clst--; + } + fs->last_clst = fs->st_clst - 1; + + LEAVE_FF(fs, res); } static FRESULT FatfsCheckStart(BYTE *work, FATFS *fs, BYTE vol) { -DWORD startBaseSect, countBaseSect; + DWORD startBaseSect, countBaseSect; -countBaseSect = LD2PC(vol); /* Volume Base Sectors Count */ -startBaseSect = LD2PS(vol); /* Volume Base Start Sector */ + countBaseSect = LD2PC(vol); /* Volume Base Sectors Count */ + startBaseSect = LD2PS(vol); /* Volume Base Start Sector */ -/* Check ASCII for Keyword "LITE" */ -if (ld_dword(work + VR_VertifyString) != 0x4C495445) { -return FR_NOVIRPART; -} -/* Check whether filesystem has been changed or not */ -if (work[VR_PartitionFSType] != fs->fs_type) { -return FR_MODIFIED; -} -/* Check whether volume base sector has benn changed or not */ -if (ld_dword(work + VR_PartitionStSec) != startBaseSect) { -return FR_MODIFIED; -} -/* Check whether volume base size hase been changed or not */ -if (ld_dword(work + VR_PartitionCtSec) != countBaseSect) { -return FR_MODIFIED; -} -/* Check whether volume cluster size has been changed or not */ -if (ld_word(work + VR_PartitionClstSz) != fs->csize) { -return FR_MODIFIED; -} -/* Check whether volume start cluster is cluster #3 or not */ -if (ld_dword(work + VR_PartitionCtClst) != fs->n_fatent) { -return FR_MODIFIED; -} -/* Check whether virtual partition overlimit */ -if (work[VR_PartitionCnt] > _MAX_VIRVOLUMES) { -return FR_MODIFIED; -} + /* Check ASCII for Keyword "LITE" */ + if (ld_dword(work + VR_VertifyString) != 0x4C495445) { + return FR_NOVIRPART; + } + /* Check whether filesystem has been changed or not */ + if (work[VR_PartitionFSType] != fs->fs_type) { + return FR_MODIFIED; + } + /* Check whether volume base sector has benn changed or not */ + if (ld_dword(work + VR_PartitionStSec) != startBaseSect) { + return FR_MODIFIED; + } + /* Check whether volume base size hase been changed or not */ + if (ld_dword(work + VR_PartitionCtSec) != countBaseSect) { + return FR_MODIFIED; + } + /* Check whether volume cluster size has been changed or not */ + if (ld_word(work + VR_PartitionClstSz) != fs->csize) { + return FR_MODIFIED; + } + /* Check whether volume start cluster is cluster #3 or not */ + if (ld_dword(work + VR_PartitionCtClst) != fs->n_fatent) { + return FR_MODIFIED; + } + /* Check whether virtual partition overlimit */ + if (work[VR_PartitionCnt] > _MAX_VIRVOLUMES) { + return FR_MODIFIED; + } -return FR_OK; + return FR_OK; } static FRESULT FatfsCheckPercent(FATFS *fs, WORD i) { -if ((CHILDFS(fs, i))->st_clst + (CHILDFS(fs, i))->ct_clst < fs->n_fatent) { -fs->st_clst = (CHILDFS(fs, i))->st_clst + (CHILDFS(fs, i))->ct_clst; -fs->ct_clst = fs->n_fatent - ((CHILDFS(fs, i))->st_clst + (CHILDFS(fs, i))->ct_clst); -} else if ((CHILDFS(fs, i))->st_clst + (CHILDFS(fs, i))->ct_clst == fs->n_fatent) { -fs->st_clst = 0xFFFFFFFF; -fs->ct_clst = 0xFFFFFFFF; -} else { -(void)f_unregvirfs(fs); -return FR_MODIFIED; -} + if ((CHILDFS(fs, i))->st_clst + (CHILDFS(fs, i))->ct_clst < fs->n_fatent) { + fs->st_clst = (CHILDFS(fs, i))->st_clst + (CHILDFS(fs, i))->ct_clst; + fs->ct_clst = fs->n_fatent - ((CHILDFS(fs, i))->st_clst + (CHILDFS(fs, i))->ct_clst); + } else if ((CHILDFS(fs, i))->st_clst + (CHILDFS(fs, i))->ct_clst == fs->n_fatent) { + fs->st_clst = 0xFFFFFFFF; + fs->ct_clst = 0xFFFFFFFF; + } else { + (void)f_unregvirfs(fs); + return FR_MODIFIED; + } -return FR_OK; + return FR_OK; } static FRESULT FatfsCheckPartClst(FATFS *fs, WORD i) { -if (i == 0) { -/* First virtual partition must start at cluster #3 */ -if ((CHILDFS(fs, i))->st_clst != 3) { - (void)f_unregvirfs(fs); - return FR_MODIFIED; -} -} else { -/* Check whether the current virtual partition is closely next to the previous virtual partition */ -if ((CHILDFS(fs, i))->st_clst != (CHILDFS(fs, (i - 1))->st_clst + CHILDFS(fs, (i - 1))->ct_clst)) { - (void)f_unregvirfs(fs); - return FR_MODIFIED; -} -} + if (i == 0) { + /* First virtual partition must start at cluster #3 */ + if ((CHILDFS(fs, i))->st_clst != 3) { + (void)f_unregvirfs(fs); + return FR_MODIFIED; + } + } else { + /* Check whether the current virtual partition is closely next to the previous virtual partition */ + if ((CHILDFS(fs, i))->st_clst != (CHILDFS(fs, (i - 1))->st_clst + CHILDFS(fs, (i - 1))->ct_clst)) { + (void)f_unregvirfs(fs); + return FR_MODIFIED; + } + } -return FR_OK; + return FR_OK; } static void FatfsSetChildClst(BYTE *work, FATFS *fs, WORD i) { -(CHILDFS(fs, i))->st_clst = ld_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_StartClust); -(CHILDFS(fs, i))->ct_clst = ld_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_CountClust); + (CHILDFS(fs, i))->st_clst = ld_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_StartClust); + (CHILDFS(fs, i))->ct_clst = ld_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_CountClust); } /* @@ -544,144 +544,144 @@ static void FatfsSetChildClst(BYTE *work, FATFS *fs, WORD i) */ FRESULT f_checkvirpart(FATFS *fs, const TCHAR *path, BYTE vol) { -FRESULT res; -WORD i; -DWORD virSect; -DWORD tmp; -BYTE pdrv; -BYTE *work = NULL; -CHAR label[_MAX_ENTRYLENGTH + 1]; -DWORD *labelTmp = NULL; /* to clear the compilation warning */ - -if (fs == NULL || (disk_status(fs->pdrv) & STA_NOINIT)) { -return FR_INVAILD_FATFS; /* The object is invalid */ -} + FRESULT res; + WORD i; + DWORD virSect; + DWORD tmp; + BYTE pdrv; + BYTE *work = NULL; + CHAR label[_MAX_ENTRYLENGTH + 1]; + DWORD *labelTmp = NULL; /* to clear the compilation warning */ + + if (fs == NULL || (disk_status(fs->pdrv) & STA_NOINIT)) { + return FR_INVAILD_FATFS; /* The object is invalid */ + } -/* Lock the filesystem object */ -res = find_volume(&path, &fs, FA_WRITE); /* Update the filesystem info to the parent fs */ -if (res != FR_OK) { -LEAVE_FF(fs, res); -} + /* Lock the filesystem object */ + res = find_volume(&path, &fs, FA_WRITE); /* Update the filesystem info to the parent fs */ + if (res != FR_OK) { + LEAVE_FF(fs, res); + } -if (ISCHILD(fs)) { -LEAVE_FF(fs, FR_INT_ERR); -} -/* Data will be save at the last reserve sector ,which is the front one of the fat base sector */ -virSect = fs->fatbase - 1; + if (ISCHILD(fs)) { + LEAVE_FF(fs, FR_INT_ERR); + } + /* Data will be save at the last reserve sector ,which is the front one of the fat base sector */ + virSect = fs->fatbase - 1; -pdrv = LD2PD(vol); /* Driver index */ + pdrv = LD2PD(vol); /* Driver index */ -work = (BYTE *)ff_memalloc(SS(fs)); -if (work == NULL) { -LEAVE_FF(fs, FR_NOT_ENOUGH_CORE); -} -/* Check and vertify partition information */ -if (disk_read(pdrv, work, virSect, 1) != RES_OK) { -res = FR_DISK_ERR; -goto EXIT; -} /* Load VBR */ - -res = FatfsCheckStart(work, fs, vol); -if (res != FR_OK) { -goto EXIT; -} -/* Check the virtual parition amount if matched current setting or not */ -fs->vir_amount = work[VR_PartitionCnt]; -res = f_regvirfs(fs); -if (res != FR_OK) { -goto EXIT; -} + work = (BYTE *)ff_memalloc(SS(fs)); + if (work == NULL) { + LEAVE_FF(fs, FR_NOT_ENOUGH_CORE); + } + /* Check and vertify partition information */ + if (disk_read(pdrv, work, virSect, 1) != RES_OK) { + res = FR_DISK_ERR; + goto EXIT; + } /* Load VBR */ -for (i = 0; i < _MAX_VIRVOLUMES; i++) { -if (i < work[VR_PartitionCnt]) { - if (work[VR_PARTITION + i * VR_ITEMSIZE + VR_Available] != 0x80) { - (void)f_unregvirfs(fs); - res = FR_MODIFIED; + res = FatfsCheckStart(work, fs, vol); + if (res != FR_OK) { goto EXIT; } -} else { - if (work[VR_PARTITION + i * VR_ITEMSIZE + VR_Available] != 0x00) { - (void)f_unregvirfs(fs); - res = FR_MODIFIED; + /* Check the virtual parition amount if matched current setting or not */ + fs->vir_amount = work[VR_PartitionCnt]; + res = f_regvirfs(fs); + if (res != FR_OK) { goto EXIT; } - break; -} - -(void)memset_s(label, sizeof(label), 0, sizeof(label)); -tmp = ld_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 0); -labelTmp = (DWORD *)label; -*labelTmp = tmp; -tmp = ld_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 4); -*((DWORD *)(label + 4)) = tmp; -tmp = ld_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 8); -*((DWORD *)(label + 8)) = tmp; -tmp = ld_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 12); -*((DWORD *)(label + 12)) = tmp; + for (i = 0; i < _MAX_VIRVOLUMES; i++) { + if (i < work[VR_PartitionCnt]) { + if (work[VR_PARTITION + i * VR_ITEMSIZE + VR_Available] != 0x80) { + (void)f_unregvirfs(fs); + res = FR_MODIFIED; + goto EXIT; + } + } else { + if (work[VR_PARTITION + i * VR_ITEMSIZE + VR_Available] != 0x00) { + (void)f_unregvirfs(fs); + res = FR_MODIFIED; + goto EXIT; + } + break; + } -if (f_checkname(label) != FR_OK) { - (void)f_unregvirfs(fs); - res = FR_MODIFIED; - goto EXIT; -} -(void)memcpy_s((CHILDFS(fs, i))->namelabel, _MAX_ENTRYLENGTH + 1, label, _MAX_ENTRYLENGTH + 1); + (void)memset_s(label, sizeof(label), 0, sizeof(label)); + + tmp = ld_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 0); + labelTmp = (DWORD *)label; + *labelTmp = tmp; + tmp = ld_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 4); + *((DWORD * )(label + 4)) = tmp; + tmp = ld_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 8); + *((DWORD * )(label + 8)) = tmp; + tmp = ld_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 12); + *((DWORD * )(label + 12)) = tmp; + + if (f_checkname(label) != FR_OK) { + (void)f_unregvirfs(fs); + res = FR_MODIFIED; + goto EXIT; + } + (void)memcpy_s((CHILDFS(fs, i))->namelabel, _MAX_ENTRYLENGTH + 1, label, _MAX_ENTRYLENGTH + 1); -FatfsSetChildClst(work, fs, i); + FatfsSetChildClst(work, fs, i); -/* External SD setting has overlimit the whole partition cluster amount */ -if ((QWORD)(CHILDFS(fs, i))->st_clst + (QWORD)((CHILDFS(fs, i))->ct_clst) > (QWORD)fs->n_fatent) { - (void)f_unregvirfs(fs); - res = FR_MODIFIED; - goto EXIT; -} + /* External SD setting has overlimit the whole partition cluster amount */ + if ((QWORD)(CHILDFS(fs, i))->st_clst + (QWORD)((CHILDFS(fs, i))->ct_clst) > (QWORD)fs->n_fatent) { + (void)f_unregvirfs(fs); + res = FR_MODIFIED; + goto EXIT; + } -res = FatfsCheckPartClst(fs, i); -if (res != FR_OK) { - goto EXIT; -} -if (i == (work[VR_PartitionCnt] - 1)) { - /* - * If the external SD virtual partition percent exceeds the error tolerance based on current virtual - * partition percent setting - */ - res = FatfsCheckPercent(fs, i); - if (res != FR_OK) { - goto EXIT; + res = FatfsCheckPartClst(fs, i); + if (res != FR_OK) { + goto EXIT; + } + if (i == (work[VR_PartitionCnt] - 1)) { + /* + * If the external SD virtual partition percent exceeds the error tolerance based on current virtual + * partition percent setting + */ + res = FatfsCheckPercent(fs, i); + if (res != FR_OK) { + goto EXIT; + } + } } -} -} EXIT: -ff_memfree(work); -LEAVE_FF(fs, res); + ff_memfree(work); + LEAVE_FF(fs, res); } static void FatfsClacPartInfo(FATFS *fs, DOUBLE virpartper, UINT i) { -if (i == 0) { -(CHILDFS(fs, i))->st_clst = 3; -(CHILDFS(fs, i))->ct_clst = (DWORD)((fs->n_fatent - 3) * - g_fatVirPart.virtualinfo.virpartpercent[i]); - -fs->st_clst = (CHILDFS(fs, i))->st_clst + (CHILDFS(fs, i))->ct_clst; -fs->ct_clst = fs->n_fatent - fs->st_clst; -} else if (i != (fs->vir_amount - 1)) { -(CHILDFS(fs, i))->st_clst = (CHILDFS(fs, (i - 1)))->st_clst + (CHILDFS(fs, (i - 1)))->ct_clst; -(CHILDFS(fs, i))->ct_clst = (DWORD)((fs->n_fatent - 3) * - g_fatVirPart.virtualinfo.virpartpercent[i]); -} else { -(CHILDFS(fs, i))->st_clst = (CHILDFS(fs, (i - 1)))->st_clst + (CHILDFS(fs, (i - 1)))->ct_clst; -if (virpartper <= (1 + _FLOAT_ACC) && virpartper >= (1 - _FLOAT_ACC)) { - (CHILDFS(fs, i))->ct_clst = fs->n_fatent - (CHILDFS(fs, i))->st_clst; - fs->st_clst = 0xFFFFFFFF; - fs->ct_clst = 0xFFFFFFFF; -} else { - (CHILDFS(fs, i))->ct_clst = (DWORD)((fs->n_fatent - 3) * - g_fatVirPart.virtualinfo.virpartpercent[i]); - fs->st_clst = (CHILDFS(fs, i))->st_clst + (CHILDFS(fs, i))->ct_clst; - fs->ct_clst = fs->n_fatent - fs->st_clst; -} -} + if (i == 0) { + (CHILDFS(fs, i))->st_clst = 3; + (CHILDFS(fs, i))->ct_clst = (DWORD)((fs->n_fatent - 3) * + g_fatVirPart.virtualinfo.virpartpercent[i]); + + fs->st_clst = (CHILDFS(fs, i))->st_clst + (CHILDFS(fs, i))->ct_clst; + fs->ct_clst = fs->n_fatent - fs->st_clst; + } else if (i != (fs->vir_amount - 1)) { + (CHILDFS(fs, i))->st_clst = (CHILDFS(fs, (i - 1)))->st_clst + (CHILDFS(fs, (i - 1)))->ct_clst; + (CHILDFS(fs, i))->ct_clst = (DWORD)((fs->n_fatent - 3) * + g_fatVirPart.virtualinfo.virpartpercent[i]); + } else { + (CHILDFS(fs, i))->st_clst = (CHILDFS(fs, (i - 1)))->st_clst + (CHILDFS(fs, (i - 1)))->ct_clst; + if (virpartper <= (1 + _FLOAT_ACC) && virpartper >= (1 - _FLOAT_ACC)) { + (CHILDFS(fs, i))->ct_clst = fs->n_fatent - (CHILDFS(fs, i))->st_clst; + fs->st_clst = 0xFFFFFFFF; + fs->ct_clst = 0xFFFFFFFF; + } else { + (CHILDFS(fs, i))->ct_clst = (DWORD)((fs->n_fatent - 3) * + g_fatVirPart.virtualinfo.virpartpercent[i]); + fs->st_clst = (CHILDFS(fs, i))->st_clst + (CHILDFS(fs, i))->ct_clst; + fs->ct_clst = fs->n_fatent - fs->st_clst; + } + } } /* @@ -700,173 +700,173 @@ if (virpartper <= (1 + _FLOAT_ACC) && virpartper >= (1 - _FLOAT_ACC)) { */ FRESULT f_makevirpart(FATFS *fs, const TCHAR *path, BYTE vol) { -FRESULT res; -DWORD virSect; -DWORD startBaseSect, countBaseSect; -DWORD tmp; -CHAR label[_MAX_ENTRYLENGTH + 1]; -DWORD *labelTmp = NULL; /* to clear the compilation warning */ -UINT i; -BYTE pdrv; -BYTE *work = NULL; -DOUBLE virpartper = 0.0; - -if (fs == NULL || (disk_status(fs->pdrv) & STA_NOINIT)) { -return FR_INVAILD_FATFS; /* The object is invalid */ -} + FRESULT res; + DWORD virSect; + DWORD startBaseSect, countBaseSect; + DWORD tmp; + CHAR label[_MAX_ENTRYLENGTH + 1]; + DWORD *labelTmp = NULL; /* to clear the compilation warning */ + UINT i; + BYTE pdrv; + BYTE *work = NULL; + DOUBLE virpartper = 0.0; + + if (fs == NULL || (disk_status(fs->pdrv) & STA_NOINIT)) { + return FR_INVAILD_FATFS; /* The object is invalid */ + } -/* Lock the filesystem object */ -res = find_volume(&path, &fs, FA_WRITE); /* Update the filesystem info to the parent fs */ -if (res != FR_OK) { -LEAVE_FF(fs, res); -} + /* Lock the filesystem object */ + res = find_volume(&path, &fs, FA_WRITE); /* Update the filesystem info to the parent fs */ + if (res != FR_OK) { + LEAVE_FF(fs, res); + } -/* Only available in FAT32 filesystem */ -if (ISCHILD(fs)) { -LEAVE_FF(fs, FR_INVAILD_FATFS); -} -/* Data will be save at the last reserve sector,which is the front one of the fat base sector */ -virSect = fs->fatbase - 1; -/* Search the fs index, which same as the volume index */ -pdrv = LD2PD(vol); /* Driver index */ -countBaseSect = LD2PC(vol); /* Volume Base Sectors Count */ -startBaseSect = LD2PS(vol); /* Volume Base Start Sector */ - -fs->vir_amount = g_fatVirPart.virtualinfo.virpartnum; -res = f_regvirfs(fs); -if (res != FR_OK) { -LEAVE_FF(fs, res); -} + /* Only available in FAT32 filesystem */ + if (ISCHILD(fs)) { + LEAVE_FF(fs, FR_INVAILD_FATFS); + } + /* Data will be save at the last reserve sector,which is the front one of the fat base sector */ + virSect = fs->fatbase - 1; + /* Search the fs index, which same as the volume index */ + pdrv = LD2PD(vol); /* Driver index */ + countBaseSect = LD2PC(vol); /* Volume Base Sectors Count */ + startBaseSect = LD2PS(vol); /* Volume Base Start Sector */ + + fs->vir_amount = g_fatVirPart.virtualinfo.virpartnum; + res = f_regvirfs(fs); + if (res != FR_OK) { + LEAVE_FF(fs, res); + } -work = (BYTE *)ff_memalloc(SS(fs)); -if (work == NULL) { -LEAVE_FF(fs, FR_NOT_ENOUGH_CORE); -} -/* Data Cluster is begin from the Cluster #3 to the last cluster */ -/* Cluster #0 #1 is for VBR, reserve sectors and fat */ -/* Cluster #2 is for root directory */ -(void)memset_s(work, SS(fs), 0, SS(fs)); - -for (i = 0; i < fs->vir_amount; i++) { -/* Copy the Entry label and write to work sector's buffer */ -(void)memset_s(label, sizeof(label), 0, sizeof(label)); -(void)memcpy_s(label, _MAX_ENTRYLENGTH + 1, g_fatVirPart.virtualinfo.virpartname[i], _MAX_ENTRYLENGTH + 1); -labelTmp = (DWORD *)label; -tmp = *labelTmp; -st_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 0, tmp); -tmp = *((DWORD *)(label + 4)); -st_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 4, tmp); -tmp = *((DWORD *)(label + 8)); -st_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 8, tmp); -tmp = *((DWORD *)(label + 12)); -st_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 12, tmp); - -virpartper += g_fatVirPart.virtualinfo.virpartpercent[i]; - -(void)memcpy_s((CHILDFS(fs, i))->namelabel, _MAX_ENTRYLENGTH + 1, g_fatVirPart.virtualinfo.virpartname[i], - _MAX_ENTRYLENGTH + 1); -FatfsClacPartInfo(fs, virpartper, i); -(CHILDFS(fs, i))->last_clst = (CHILDFS(fs, i))->st_clst - 1; -work[VR_PARTITION + i * VR_ITEMSIZE + VR_Available] = 0x80; -} + work = (BYTE *)ff_memalloc(SS(fs)); + if (work == NULL) { + LEAVE_FF(fs, FR_NOT_ENOUGH_CORE); + } + /* Data Cluster is begin from the Cluster #3 to the last cluster */ + /* Cluster #0 #1 is for VBR, reserve sectors and fat */ + /* Cluster #2 is for root directory */ + (void)memset_s(work, SS(fs), 0, SS(fs)); + + for (i = 0; i < fs->vir_amount; i++) { + /* Copy the Entry label and write to work sector's buffer */ + (void)memset_s(label, sizeof(label), 0, sizeof(label)); + (void)memcpy_s(label, _MAX_ENTRYLENGTH + 1, g_fatVirPart.virtualinfo.virpartname[i], _MAX_ENTRYLENGTH + 1); + labelTmp = (DWORD *)label; + tmp = *labelTmp; + st_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 0, tmp); + tmp = *((DWORD * )(label + 4)); + st_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 4, tmp); + tmp = *((DWORD * )(label + 8)); + st_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 8, tmp); + tmp = *((DWORD * )(label + 12)); + st_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_Entry + 12, tmp); + + virpartper += g_fatVirPart.virtualinfo.virpartpercent[i]; + + (void)memcpy_s((CHILDFS(fs, i))->namelabel, _MAX_ENTRYLENGTH + 1, g_fatVirPart.virtualinfo.virpartname[i], + _MAX_ENTRYLENGTH + 1); + FatfsClacPartInfo(fs, virpartper, i); + (CHILDFS(fs, i))->last_clst = (CHILDFS(fs, i))->st_clst - 1; + work[VR_PARTITION + i * VR_ITEMSIZE + VR_Available] = 0x80; + } -/* Set the data to sector */ -work[VR_PartitionCnt] = fs->vir_amount; -work[VR_PartitionFSType] = fs->fs_type; -st_dword(work + VR_PartitionStSec, startBaseSect); -st_dword(work + VR_PartitionCtSec, countBaseSect); -st_word(work + VR_PartitionClstSz, fs->csize); -st_dword(work + VR_PartitionCtClst, fs->n_fatent); -for (i = 0; i < fs->vir_amount; i++) { -st_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_StartClust, - (CHILDFS(fs, i))->st_clst); -st_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_CountClust, - (CHILDFS(fs, i))->ct_clst); -} + /* Set the data to sector */ + work[VR_PartitionCnt] = fs->vir_amount; + work[VR_PartitionFSType] = fs->fs_type; + st_dword(work + VR_PartitionStSec, startBaseSect); + st_dword(work + VR_PartitionCtSec, countBaseSect); + st_word(work + VR_PartitionClstSz, fs->csize); + st_dword(work + VR_PartitionCtClst, fs->n_fatent); + for (i = 0; i < fs->vir_amount; i++) { + st_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_StartClust, + (CHILDFS(fs, i))->st_clst); + st_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_CountClust, + (CHILDFS(fs, i))->ct_clst); + } -/* ASCII for Keyword "LITE" */ -st_dword(work + VR_VertifyString, 0x4C495445); + /* ASCII for Keyword "LITE" */ + st_dword(work + VR_VertifyString, 0x4C495445); -/* Write into the data area */ -if (disk_write(pdrv, work, virSect, 1) != RES_OK) { -(void)f_unregvirfs(fs); -res = FR_DISK_ERR; -} + /* Write into the data area */ + if (disk_write(pdrv, work, virSect, 1) != RES_OK) { + (void)f_unregvirfs(fs); + res = FR_DISK_ERR; + } -ff_memfree(work); -LEAVE_FF(fs, res); + ff_memfree(work); + LEAVE_FF(fs, res); } FRESULT f_getvirfree(const TCHAR *path, DWORD *nclst, DWORD *cclst) { -FATFS *fs = NULL; -FRESULT res; -DWORD clst, link; -DWORD nfree; -UINT i; -DIR dj; - -/* Find volume to Update the global FSINFO */ -res = find_volume(&path, &fs, 0); -if (res != FR_OK) { -LEAVE_FF(fs, res); -} - -/* Following the entry keyword, decide to replace the PARENT FATFS to CHILD FATFS or not */ -dj.obj.fs = fs; -if (ISVIRPART(fs)) { -/* Check the virtual partition top directory, and match the virtual fs */ -res = follow_virentry(&dj.obj, path); -if (res == FR_INT_ERR) { - LEAVE_FF(fs, res); -} -if (res == FR_OK) { - fs = dj.obj.fs; -} -} else { -/* Virtual Partition Feature was off, deny this operation */ -LEAVE_FF(fs, FR_DENIED); -} + FATFS *fs = NULL; + FRESULT res; + DWORD clst, link; + DWORD nfree; + UINT i; + DIR dj; + + /* Find volume to Update the global FSINFO */ + res = find_volume(&path, &fs, 0); + if (res != FR_OK) { + LEAVE_FF(fs, res); + } -/* If current FATFS is a CHILD FATFS */ -if (ISCHILD(fs)) { -/* If CHILD FATFS' free_clst is invaild, the scan the FAT and update it */ -if (fs->free_clst > fs->ct_clst) { + /* Following the entry keyword, decide to replace the PARENT FATFS to CHILD FATFS or not */ dj.obj.fs = fs; - fs->free_clst = fs->ct_clst; - for (clst = fs->st_clst; clst < fs->st_clst + fs->ct_clst; clst++) { - link = get_fat(&dj.obj, clst); - if (link == 0) { - continue; + if (ISVIRPART(fs)) { + /* Check the virtual partition top directory, and match the virtual fs */ + res = follow_virentry(&dj.obj, path); + if (res == FR_INT_ERR) { + LEAVE_FF(fs, res); } - fs->free_clst--; + if (res == FR_OK) { + fs = dj.obj.fs; + } + } else { + /* Virtual Partition Feature was off, deny this operation */ + LEAVE_FF(fs, FR_DENIED); } -} -*nclst = fs->free_clst; -*cclst = fs->ct_clst; -LEAVE_FF(fs, FR_OK); -} else { -nfree = 0; -if (fs->ct_clst == 0xFFFFFFFF) { - LEAVE_FF(fs, FR_DENIED); -} -for (i = 0; i < fs->vir_amount; i++) { - if (CHILDFS(fs, i)->free_clst > CHILDFS(fs, i)->ct_clst) { - dj.obj.fs = CHILDFS(fs, i); - CHILDFS(fs, i)->free_clst = CHILDFS(fs, i)->ct_clst; - for (clst = CHILDFS(fs, i)->st_clst; clst < CHILDFS(fs, i)->st_clst + CHILDFS(fs, i)->ct_clst; clst++) { - link = get_fat(&dj.obj, clst); - if (link == 0) { - continue; + + /* If current FATFS is a CHILD FATFS */ + if (ISCHILD(fs)) { + /* If CHILD FATFS' free_clst is invaild, the scan the FAT and update it */ + if (fs->free_clst > fs->ct_clst) { + dj.obj.fs = fs; + fs->free_clst = fs->ct_clst; + for (clst = fs->st_clst; clst < fs->st_clst + fs->ct_clst; clst++) { + link = get_fat(&dj.obj, clst); + if (link == 0) { + continue; + } + fs->free_clst--; + } + } + *nclst = fs->free_clst; + *cclst = fs->ct_clst; + LEAVE_FF(fs, FR_OK); + } else { + nfree = 0; + if (fs->ct_clst == 0xFFFFFFFF) { + LEAVE_FF(fs, FR_DENIED); + } + for (i = 0; i < fs->vir_amount; i++) { + if (CHILDFS(fs, i)->free_clst > CHILDFS(fs, i)->ct_clst) { + dj.obj.fs = CHILDFS(fs, i); + CHILDFS(fs, i)->free_clst = CHILDFS(fs, i)->ct_clst; + for (clst = CHILDFS(fs, i)->st_clst; clst < CHILDFS(fs, i)->st_clst + CHILDFS(fs, i)->ct_clst; clst++) { + link = get_fat(&dj.obj, clst); + if (link == 0) { + continue; + } + CHILDFS(fs, i)->free_clst--; + } } - CHILDFS(fs, i)->free_clst--; + nfree += CHILDFS(fs, i)->free_clst; } + *nclst = fs->free_clst - nfree; + *cclst = fs->ct_clst; + LEAVE_FF(fs, FR_OK); } - nfree += CHILDFS(fs, i)->free_clst; -} -*nclst = fs->free_clst - nfree; -*cclst = fs->ct_clst; -LEAVE_FF(fs, FR_OK); -} } #endif -- GitLab