@@ -131,7 +131,7 @@ static Deferred<const char*> fat_path_prefix(int id, const char *path)
131
131
// //// Disk operations //////
132
132
133
133
// Global access to block device from FAT driver
134
- static BlockDevice *_ffs[_VOLUMES ] = {0 };
134
+ static BlockDevice *_ffs[FF_VOLUMES ] = {0 };
135
135
static SingletonPtr<PlatformMutex> _ffs_mutex;
136
136
137
137
@@ -167,7 +167,7 @@ static WORD disk_get_sector_size(BYTE pdrv)
167
167
ssize = 512 ;
168
168
}
169
169
170
- MBED_ASSERT (ssize >= _MIN_SS && ssize <= _MAX_SS );
170
+ MBED_ASSERT (ssize >= FF_MIN_SS && ssize <= FF_MAX_SS );
171
171
MBED_ASSERT (_ffs[pdrv]->get_read_size () <= _ffs[pdrv]->get_erase_size ());
172
172
MBED_ASSERT (_ffs[pdrv]->get_program_size () <= _ffs[pdrv]->get_erase_size ());
173
173
return ssize;
@@ -287,7 +287,7 @@ int FATFileSystem::mount(BlockDevice *bd, bool mount) {
287
287
return -EINVAL;
288
288
}
289
289
290
- for (int i = 0 ; i < _VOLUMES ; i++) {
290
+ for (int i = 0 ; i < FF_VOLUMES ; i++) {
291
291
if (!_ffs[i]) {
292
292
_id = i;
293
293
_ffs[_id] = bd;
@@ -331,7 +331,7 @@ int FATFileSystem::format(BlockDevice *bd, bd_size_t cluster_size) {
331
331
332
332
// Logical drive number, Partitioning rule, Allocation unit size (bytes per cluster)
333
333
fs.lock ();
334
- FRESULT res = f_mkfs (fs._fsid , 1 , cluster_size);
334
+ FRESULT res = f_mkfs (fs._fsid , FM_ANY , cluster_size, NULL , 0 );
335
335
fs.unlock ();
336
336
if (res != FR_OK) {
337
337
return fat_error_remap (res);
@@ -467,6 +467,7 @@ int FATFileSystem::file_open(fs_file_t *file, const char *path, int flags) {
467
467
} else {
468
468
openmode = FA_READ;
469
469
}
470
+
470
471
if (flags & O_CREAT) {
471
472
if (flags & O_TRUNC) {
472
473
openmode |= FA_CREATE_ALWAYS;
@@ -475,6 +476,10 @@ int FATFileSystem::file_open(fs_file_t *file, const char *path, int flags) {
475
476
}
476
477
}
477
478
479
+ if (flags & O_APPEND) {
480
+ openmode |= FA_OPEN_APPEND;
481
+ }
482
+
478
483
lock ();
479
484
FRESULT res = f_open (fh, fpath, openmode);
480
485
@@ -485,9 +490,6 @@ int FATFileSystem::file_open(fs_file_t *file, const char *path, int flags) {
485
490
return fat_error_remap (res);
486
491
}
487
492
488
- if (flags & O_APPEND) {
489
- f_lseek (fh, fh->fsize );
490
- }
491
493
unlock ();
492
494
493
495
*file = fh;
@@ -555,9 +557,9 @@ off_t FATFileSystem::file_seek(fs_file_t file, off_t offset, int whence) {
555
557
556
558
lock ();
557
559
if (whence == SEEK_END) {
558
- offset += fh-> fsize ;
560
+ offset += f_size (fh) ;
559
561
} else if (whence==SEEK_CUR) {
560
- offset += fh-> fptr ;
562
+ offset += f_tell (fh) ;
561
563
}
562
564
563
565
FRESULT res = f_lseek (fh, offset);
@@ -576,7 +578,7 @@ off_t FATFileSystem::file_tell(fs_file_t file) {
576
578
FIL *fh = static_cast <FIL*>(file);
577
579
578
580
lock ();
579
- off_t res = fh-> fptr ;
581
+ off_t res = f_tell (fh) ;
580
582
unlock ();
581
583
582
584
return res;
@@ -586,7 +588,7 @@ off_t FATFileSystem::file_size(fs_file_t file) {
586
588
FIL *fh = static_cast <FIL*>(file);
587
589
588
590
lock ();
589
- off_t res = fh-> fsize ;
591
+ off_t res = f_size (fh) ;
590
592
unlock ();
591
593
592
594
return res;
@@ -627,11 +629,6 @@ ssize_t FATFileSystem::dir_read(fs_dir_t dir, struct dirent *ent) {
627
629
FATFS_DIR *dh = static_cast <FATFS_DIR*>(dir);
628
630
FILINFO finfo;
629
631
630
- #if _USE_LFN
631
- finfo.lfname = ent->d_name ;
632
- finfo.lfsize = NAME_MAX;
633
- #endif // _USE_LFN
634
-
635
632
lock ();
636
633
FRESULT res = f_readdir (dh, &finfo);
637
634
unlock ();
@@ -644,13 +641,13 @@ ssize_t FATFileSystem::dir_read(fs_dir_t dir, struct dirent *ent) {
644
641
645
642
ent->d_type = (finfo.fattrib & AM_DIR) ? DT_DIR : DT_REG;
646
643
647
- #if _USE_LFN
644
+ #if FF_USE_LFN
648
645
if (ent->d_name [0 ] == 0 ) {
649
646
// No long filename so use short filename.
650
- strncpy (ent->d_name , finfo.fname , NAME_MAX );
647
+ strncpy (ent->d_name , finfo.fname , FF_LFN_BUF );
651
648
}
652
649
#else
653
- strncpy (end ->d_name , finfo.fname , len );
650
+ strncpy (ent ->d_name , finfo.fname , FF_SFN_BUF );
654
651
#endif
655
652
656
653
return 1 ;
@@ -660,17 +657,14 @@ void FATFileSystem::dir_seek(fs_dir_t dir, off_t offset) {
660
657
FATFS_DIR *dh = static_cast <FATFS_DIR*>(dir);
661
658
662
659
lock ();
663
- if (offset < dh->index ) {
660
+
661
+ if (offset < dh->dptr ) {
664
662
f_rewinddir (dh);
665
663
}
666
- while (dh->index < offset) {
664
+ while (dh->dptr < offset) {
667
665
FILINFO finfo;
668
666
FRESULT res;
669
- #if _USE_LFN
670
- char lfname[NAME_MAX];
671
- finfo.lfname = lfname;
672
- finfo.lfsize = NAME_MAX;
673
- #endif // _USE_LFN
667
+
674
668
res = f_readdir (dh, &finfo);
675
669
if (res != FR_OK) {
676
670
break ;
@@ -685,7 +679,7 @@ off_t FATFileSystem::dir_tell(fs_dir_t dir) {
685
679
FATFS_DIR *dh = static_cast <FATFS_DIR*>(dir);
686
680
687
681
lock ();
688
- off_t offset = dh->index ;
682
+ off_t offset = dh->dptr ;
689
683
unlock ();
690
684
691
685
return offset;
0 commit comments