Lines Matching refs:fs

43 #define ENTER_FF(fs)        do { if (!lock_fs(fs)) return FR_TIMEOUT; } while (0)

44 #define LEAVE_FF(fs, res) do { unlock_fs(fs, res); return res; } while (0)
46 #define ENTER_FF(fs)
47 #define LEAVE_FF(fs, res) return (res)
67 FATFS *fs = obj->fs;
85 for (i = 0; i < fs->vir_amount; i++) {
86 if (!CHILDFS(fs, i)) {
89 if (memcmp((CHILDFS(fs, i))->namelabel, keyword, _MAX_ENTRYLENGTH + 1) == 0) {
90 obj->fs = CHILDFS(fs, i);
102 FATFS fs;
106 (void)memset_s(&fs, sizeof(fs), 0, sizeof(fs));
107 dj.obj.fs = &fs;
108 INIT_NAMBUF(&fs);
133 FATFS *fs = NULL;
135 fs = NULL;
137 fs = FatFs[vol];
139 return fs;
142 static FRESULT FatfsCheckBoundParam(FATFS *fs, DWORD clust)
144 if (fs->st_clst <= 2 || (fs->st_clst + fs->ct_clst) > fs->n_fatent) {
147 if (clust < 2 || clust > fs->n_fatent) {
150 if (clust >= (fs->st_clst + fs->ct_clst) || clust < fs->st_clst) {
165 FRESULT f_boundary(FATFS *fs, DWORD clust)
169 obj.fs = fs;
170 if (fs == NULL) {
173 if (fs->fs_type != FS_FAT32) {
176 ENTER_FF(fs);
178 res = FatfsCheckBoundParam(fs, clust);
180 LEAVE_FF(fs, res);
185 LEAVE_FF(fs, FR_DISK_ERR);
190 if (clust < 2 || clust >= fs->n_fatent) {
191 LEAVE_FF(fs, FR_INT_ERR);
193 if (clust >= (fs->st_clst + fs->ct_clst) || clust < fs->st_clst) {
194 LEAVE_FF(fs, FR_CHAIN_ERR);
198 LEAVE_FF(fs, FR_OK);
208 FRESULT f_disvirfs(FATFS *fs)
210 if (ISCHILD(fs)) {
214 if (fs->vir_amount > _MAX_VIRVOLUMES) {
218 ENTER_FF(fs);
220 (void)f_unregvirfs(fs);
221 LEAVE_FF(fs, FR_OK);
224 FRESULT f_unregvirfs(FATFS *fs)
228 if (fs == NULL || ISCHILD(fs)) {
232 fs->vir_avail = FS_VIRDISABLE;
234 if (fs->child_fs != NULL) {
236 for (i = 0; i < fs->vir_amount; i++) {
237 if (CHILDFS(fs, i) != NULL) {
238 ff_memfree(CHILDFS(fs, i));
242 ff_memfree(fs->child_fs);
243 fs->child_fs = NULL;
244 fs->vir_amount = 0xFFFFFFFF;
250 static void FatfsSetParentFs(FATFS *pfs, FATFS *fs)
252 pfs->fs_type = fs->fs_type; /* Copy the feild info from PARENT FATFS object */
253 pfs->pdrv = fs->pdrv;
254 pfs->n_fats = fs->n_fats;
255 pfs->id = fs->id;
256 pfs->n_rootdir = fs->n_rootdir;
257 pfs->csize = fs->csize;
259 pfs->ssize = fs->ssize;
261 pfs->sobj = fs->sobj;
266 pfs->n_fatent = fs->n_fatent;
267 pfs->fsize = fs->fsize;
268 pfs->volbase = fs->volbase;
269 pfs->fatbase = fs->fatbase;
270 pfs->dirbase = fs->dirbase;
271 pfs->database = fs->database;
278 pfs->parent_fs = (void *)fs; /* Link to the PARENT object */
296 FRESULT f_regvirfs(FATFS *fs)
301 if (fs == NULL || ISCHILD(fs)) {
305 if (fs->vir_amount > _MAX_VIRVOLUMES) {
309 fs->parent_fs = (void *)fs; /* Relink to itself */
311 fs->st_clst = 0xFFFFFFFF;
312 fs->ct_clst = 0xFFFFFFFF;
314 fs->child_fs = (void **)ff_memalloc(fs->vir_amount * sizeof(void *));
315 if (fs->child_fs == NULL) {
318 fs->vir_avail = FS_VIRENABLE; /* Mark the PARENT object is enable for now */
321 for (i = 0; i < fs->vir_amount; i++) {
326 FatfsSetParentFs(pfs, fs);
327 *(fs->child_fs + i) = (void *)pfs;
334 ff_memfree(*(fs->child_fs + i));
336 ff_memfree(fs->child_fs);
337 fs->child_fs = NULL;
342 static FRESULT FatfsCheckScanFatParam(FATFS *fs)
344 if (fs == NULL) {
348 if (ISNORMAL(fs)) {
352 if (fs->fs_type != FS_FAT32 || ISPARENT(fs)) {
356 if (fs->st_clst < 3 || fs->st_clst >= fs->n_fatent) {
360 if (fs->ct_clst == 0 || fs->ct_clst > (fs->n_fatent - 3)) {
364 if ((fs->st_clst + fs->ct_clst) > fs->n_fatent || (fs->st_clst + fs->ct_clst) < 3) {
383 FRESULT f_scanfat(FATFS *fs)
390 res = FatfsCheckScanFatParam(fs);
395 ENTER_FF(fs);
397 obj.fs = fs;
399 fs->free_clst = fs->ct_clst;
400 for (clst = fs->st_clst; clst < fs->st_clst + fs->ct_clst; clst++) {
403 LEAVE_FF(fs, FR_DISK_ERR);
408 fs->free_clst--;
410 fs->last_clst = fs->st_clst - 1;
412 LEAVE_FF(fs, res);
415 static FRESULT FatfsCheckStart(BYTE *work, FATFS *fs, BYTE vol)
427 if (work[VR_PartitionFSType] != fs->fs_type) {
439 if (ld_word(work + VR_PartitionClstSz) != fs->csize) {
443 if (ld_dword(work + VR_PartitionCtClst) != fs->n_fatent) {
454 static FRESULT FatfsCheckPercent(FATFS *fs, WORD i)
456 if ((CHILDFS(fs, i))->st_clst + (CHILDFS(fs, i))->ct_clst < fs->n_fatent) {
457 fs->st_clst = (CHILDFS(fs, i))->st_clst + (CHILDFS(fs, i))->ct_clst;
458 fs->ct_clst = fs->n_fatent - ((CHILDFS(fs, i))->st_clst + (CHILDFS(fs, i))->ct_clst);
459 } else if ((CHILDFS(fs, i))->st_clst + (CHILDFS(fs, i))->ct_clst == fs->n_fatent) {
460 fs->st_clst = 0xFFFFFFFF;
461 fs->ct_clst = 0xFFFFFFFF;
463 (void)f_unregvirfs(fs);
470 static FRESULT FatfsCheckPartClst(FATFS *fs, WORD i)
474 if ((CHILDFS(fs, i))->st_clst != 3) {
475 (void)f_unregvirfs(fs);
480 if ((CHILDFS(fs, i))->st_clst != (CHILDFS(fs, (i - 1))->st_clst + CHILDFS(fs, (i - 1))->ct_clst)) {
481 (void)f_unregvirfs(fs);
489 static void FatfsSetChildClst(BYTE *work, FATFS *fs, WORD i)
491 (CHILDFS(fs, i))->st_clst = ld_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_StartClust);
492 (CHILDFS(fs, i))->ct_clst = ld_dword(work + VR_PARTITION + i * VR_ITEMSIZE + VR_CountClust);
512 FRESULT f_checkvirpart(FATFS *fs, const TCHAR *path, BYTE vol)
523 if (fs == NULL || (disk_status(fs->pdrv) & STA_NOINIT)) {
528 res = mount_volume(&path, &fs, FA_WRITE); /* Update the filesystem info to the parent fs */
530 LEAVE_FF(fs, res);
533 if (ISCHILD(fs)) {
534 LEAVE_FF(fs, FR_INT_ERR);
537 virSect = fs->fatbase - 1;
541 work = (BYTE *)ff_memalloc(SS(fs));
543 LEAVE_FF(fs, FR_NOT_ENOUGH_CORE);
551 res = FatfsCheckStart(work, fs, vol);
556 fs->vir_amount = work[VR_PartitionCnt];
557 res = f_regvirfs(fs);
565 (void)f_unregvirfs(fs);
571 (void)f_unregvirfs(fs);
591 (void)f_unregvirfs(fs);
595 (void)memcpy_s((CHILDFS(fs, i))->namelabel, _MAX_ENTRYLENGTH + 1, label, _MAX_ENTRYLENGTH + 1);
597 FatfsSetChildClst(work, fs, i);
600 if ((QWORD)(CHILDFS(fs, i))->st_clst + (QWORD)((CHILDFS(fs, i))->ct_clst) > (QWORD)fs->n_fatent) {
601 (void)f_unregvirfs(fs);
606 res = FatfsCheckPartClst(fs, i);
615 res = FatfsCheckPercent(fs, i);
623 LEAVE_FF(fs, res);
626 static void FatfsClacPartInfo(FATFS *fs, DOUBLE virpartper, UINT i)
629 (CHILDFS(fs, i))->st_clst = 3;
630 (CHILDFS(fs, i))->ct_clst = (DWORD)((fs->n_fatent - 3) *
633 fs->st_clst = (CHILDFS(fs, i))->st_clst + (CHILDFS(fs, i))->ct_clst;
634 fs->ct_clst = fs->n_fatent - fs->st_clst;
635 } else if (i != (fs->vir_amount - 1)) {
636 (CHILDFS(fs, i))->st_clst = (CHILDFS(fs, (i - 1)))->st_clst + (CHILDFS(fs, (i - 1)))->ct_clst;
637 (CHILDFS(fs, i))->ct_clst = (DWORD)((fs->n_fatent - 3) *
640 (CHILDFS(fs, i))->st_clst = (CHILDFS(fs, (i - 1)))->st_clst + (CHILDFS(fs, (i - 1)))->ct_clst;
642 (CHILDFS(fs, i))->ct_clst = fs->n_fatent - (CHILDFS(fs, i))->st_clst;
643 fs->st_clst = 0xFFFFFFFF;
644 fs->ct_clst = 0xFFFFFFFF;
646 (CHILDFS(fs, i))->ct_clst = (DWORD)((fs->n_fatent - 3) *
648 fs->st_clst = (CHILDFS(fs, i))->st_clst + (CHILDFS(fs, i))->ct_clst;
649 fs->ct_clst = fs->n_fatent - fs->st_clst;
668 FRESULT f_makevirpart(FATFS *fs, const TCHAR *path, BYTE vol)
681 if (fs == NULL || (disk_status(fs->pdrv) & STA_NOINIT)) {
686 res = mount_volume(&path, &fs, FA_WRITE); /* Update the filesystem info to the parent fs */
688 LEAVE_FF(fs, res);
692 if (ISCHILD(fs)) {
693 LEAVE_FF(fs, FR_INVAILD_FATFS);
696 virSect = fs->fatbase - 1;
697 /* Search the fs index, which same as the volume index */
702 fs->vir_amount = g_fatVirPart.virtualinfo.virpartnum;
703 res = f_regvirfs(fs);
705 LEAVE_FF(fs, res);
708 work = (BYTE *)ff_memalloc(SS(fs));
710 LEAVE_FF(fs, FR_NOT_ENOUGH_CORE);
715 (void)memset_s(work, SS(fs), 0, SS(fs));
717 for (i = 0; i < fs->vir_amount; i++) {
733 (void)memcpy_s((CHILDFS(fs, i))->namelabel, _MAX_ENTRYLENGTH + 1, g_fatVirPart.virtualinfo.virpartname[i],
735 FatfsClacPartInfo(fs, virpartper, i);
736 (CHILDFS(fs, i))->last_clst = (CHILDFS(fs, i))->st_clst - 1;
741 work[VR_PartitionCnt] = fs->vir_amount;
742 work[VR_PartitionFSType] = fs->fs_type;
745 st_word(work + VR_PartitionClstSz, fs->csize);
746 st_dword(work + VR_PartitionCtClst, fs->n_fatent);
747 for (i = 0; i < fs->vir_amount; i++) {
749 (CHILDFS(fs, i))->st_clst);
751 (CHILDFS(fs, i))->ct_clst);
759 (void)f_unregvirfs(fs);
764 LEAVE_FF(fs, res);
769 FATFS *fs = NULL;
777 res = mount_volume(&path, &fs, 0);
779 LEAVE_FF(fs, res);
783 dj.obj.fs = fs;
784 if (ISVIRPART(fs)) {
785 /* Check the virtual partition top directory, and match the virtual fs */
788 LEAVE_FF(fs, res);
791 fs = dj.obj.fs;
795 LEAVE_FF(fs, FR_DENIED);
799 if (ISCHILD(fs)) {
801 if (fs->free_clst > fs->ct_clst) {
802 dj.obj.fs = fs;
803 fs->free_clst = fs->ct_clst;
804 for (clst = fs->st_clst; clst < fs->st_clst + fs->ct_clst; clst++) {
809 fs->free_clst--;
812 *nclst = fs->free_clst;
813 *cclst = fs->ct_clst;
814 LEAVE_FF(fs, FR_OK);
817 if (fs->ct_clst == 0xFFFFFFFF) {
818 LEAVE_FF(fs, FR_DENIED);
820 for (i = 0; i < fs->vir_amount; i++) {
821 if (CHILDFS(fs, i)->free_clst > CHILDFS(fs, i)->ct_clst) {
822 dj.obj.fs = CHILDFS(fs, i);
823 CHILDFS(fs, i)->free_clst = CHILDFS(fs, i)->ct_clst;
824 for (clst = CHILDFS(fs, i)->st_clst; clst < CHILDFS(fs, i)->st_clst + CHILDFS(fs, i)->ct_clst; clst++) {
829 CHILDFS(fs, i)->free_clst--;
832 nfree += CHILDFS(fs, i)->free_clst;
834 *nclst = fs->free_clst - nfree;
835 *cclst = fs->ct_clst;
836 LEAVE_FF(fs, FR_OK);