@@ -275,12 +275,14 @@ FATFileSystem::~FATFileSystem()
275
275
unmount ();
276
276
}
277
277
278
- int FATFileSystem::mount (BlockDevice *bd) {
278
+ int FATFileSystem::mount (BlockDevice *bd)
279
+ {
279
280
// requires duplicate definition to allow virtual overload to work
280
281
return mount (bd, true );
281
282
}
282
283
283
- int FATFileSystem::mount (BlockDevice *bd, bool mount) {
284
+ int FATFileSystem::mount (BlockDevice *bd, bool mount)
285
+ {
284
286
lock ();
285
287
if (_id != -1 ) {
286
288
unlock ();
@@ -322,7 +324,8 @@ int FATFileSystem::unmount()
322
324
323
325
/* See http://elm-chan.org/fsw/ff/en/mkfs.html for details of f_mkfs() and
324
326
* associated arguments. */
325
- int FATFileSystem::format (BlockDevice *bd, bd_size_t cluster_size) {
327
+ int FATFileSystem::format (BlockDevice *bd, bd_size_t cluster_size)
328
+ {
326
329
FATFileSystem fs;
327
330
int err = fs.mount (bd, false );
328
331
if (err) {
@@ -345,7 +348,8 @@ int FATFileSystem::format(BlockDevice *bd, bd_size_t cluster_size) {
345
348
return 0 ;
346
349
}
347
350
348
- int FATFileSystem::reformat (BlockDevice *bd, int allocation_unit) {
351
+ int FATFileSystem::reformat (BlockDevice *bd, int allocation_unit)
352
+ {
349
353
lock ();
350
354
if (_id != -1 ) {
351
355
if (!bd) {
@@ -375,7 +379,8 @@ int FATFileSystem::reformat(BlockDevice *bd, int allocation_unit) {
375
379
return err;
376
380
}
377
381
378
- int FATFileSystem::remove (const char *path) {
382
+ int FATFileSystem::remove (const char *path)
383
+ {
379
384
Deferred<const char *> fpath = fat_path_prefix (_id, path);
380
385
381
386
lock ();
@@ -388,7 +393,8 @@ int FATFileSystem::remove(const char *path) {
388
393
return fat_error_remap (res);
389
394
}
390
395
391
- int FATFileSystem::rename (const char *oldpath, const char *newpath) {
396
+ int FATFileSystem::rename (const char *oldpath, const char *newpath)
397
+ {
392
398
Deferred<const char *> oldfpath = fat_path_prefix (_id, oldpath);
393
399
Deferred<const char *> newfpath = fat_path_prefix (_id, newpath);
394
400
@@ -402,7 +408,8 @@ int FATFileSystem::rename(const char *oldpath, const char *newpath) {
402
408
return fat_error_remap (res);
403
409
}
404
410
405
- int FATFileSystem::mkdir (const char *path, mode_t mode) {
411
+ int FATFileSystem::mkdir (const char *path, mode_t mode)
412
+ {
406
413
Deferred<const char *> fpath = fat_path_prefix (_id, path);
407
414
408
415
lock ();
@@ -415,7 +422,8 @@ int FATFileSystem::mkdir(const char *path, mode_t mode) {
415
422
return fat_error_remap (res);
416
423
}
417
424
418
- int FATFileSystem::stat (const char *path, struct stat *st) {
425
+ int FATFileSystem::stat (const char *path, struct stat *st)
426
+ {
419
427
Deferred<const char *> fpath = fat_path_prefix (_id, path);
420
428
421
429
lock ();
@@ -442,17 +450,49 @@ int FATFileSystem::stat(const char *path, struct stat *st) {
442
450
return 0 ;
443
451
}
444
452
445
- void FATFileSystem::lock () {
453
+ int FATFileSystem::statvfs (const char *path, struct statvfs *buf)
454
+ {
455
+
456
+ memset (buf, 0 , sizeof (struct statvfs ));
457
+ FATFS *fs;
458
+ DWORD fre_clust;
459
+
460
+ lock ();
461
+ FRESULT res = f_getfree (_fsid, &fre_clust, &fs);
462
+ if (res != FR_OK) {
463
+ unlock ();
464
+ return fat_error_remap (res);
465
+ }
466
+
467
+ buf->f_bsize = fs->ssize ;
468
+ buf->f_frsize = fs->ssize ;
469
+ buf->f_blocks = (fs->n_fatent - 2 ) * fs->csize ;
470
+ buf->f_bfree = fre_clust * fs->csize ;
471
+ buf->f_bavail = buf->f_bfree ;
472
+ #if FF_USE_LFN
473
+ buf->f_namemax = FF_LFN_BUF;
474
+ #else
475
+ buf->f_namemax = FF_SFN_BUF;
476
+ #endif
477
+
478
+ unlock ();
479
+ return 0 ;
480
+ }
481
+
482
+ void FATFileSystem::lock ()
483
+ {
446
484
_ffs_mutex->lock ();
447
485
}
448
486
449
- void FATFileSystem::unlock () {
487
+ void FATFileSystem::unlock ()
488
+ {
450
489
_ffs_mutex->unlock ();
451
490
}
452
491
453
492
454
493
// //// File operations //////
455
- int FATFileSystem::file_open (fs_file_t *file, const char *path, int flags) {
494
+ int FATFileSystem::file_open (fs_file_t *file, const char *path, int flags)
495
+ {
456
496
debug_if (FFS_DBG, " open(%s) on filesystem [%s], drv [%s]\n " , path, getName (), _id);
457
497
458
498
FIL *fh = new FIL;
@@ -496,7 +536,8 @@ int FATFileSystem::file_open(fs_file_t *file, const char *path, int flags) {
496
536
return 0 ;
497
537
}
498
538
499
- int FATFileSystem::file_close (fs_file_t file) {
539
+ int FATFileSystem::file_close (fs_file_t file)
540
+ {
500
541
FIL *fh = static_cast <FIL*>(file);
501
542
502
543
lock ();
@@ -507,7 +548,8 @@ int FATFileSystem::file_close(fs_file_t file) {
507
548
return fat_error_remap (res);
508
549
}
509
550
510
- ssize_t FATFileSystem::file_read (fs_file_t file, void *buffer, size_t len) {
551
+ ssize_t FATFileSystem::file_read (fs_file_t file, void *buffer, size_t len)
552
+ {
511
553
FIL *fh = static_cast <FIL*>(file);
512
554
513
555
lock ();
@@ -523,7 +565,8 @@ ssize_t FATFileSystem::file_read(fs_file_t file, void *buffer, size_t len) {
523
565
}
524
566
}
525
567
526
- ssize_t FATFileSystem::file_write (fs_file_t file, const void *buffer, size_t len) {
568
+ ssize_t FATFileSystem::file_write (fs_file_t file, const void *buffer, size_t len)
569
+ {
527
570
FIL *fh = static_cast <FIL*>(file);
528
571
529
572
lock ();
@@ -539,7 +582,8 @@ ssize_t FATFileSystem::file_write(fs_file_t file, const void *buffer, size_t len
539
582
}
540
583
}
541
584
542
- int FATFileSystem::file_sync (fs_file_t file) {
585
+ int FATFileSystem::file_sync (fs_file_t file)
586
+ {
543
587
FIL *fh = static_cast <FIL*>(file);
544
588
545
589
lock ();
@@ -552,7 +596,8 @@ int FATFileSystem::file_sync(fs_file_t file) {
552
596
return fat_error_remap (res);
553
597
}
554
598
555
- off_t FATFileSystem::file_seek (fs_file_t file, off_t offset, int whence) {
599
+ off_t FATFileSystem::file_seek (fs_file_t file, off_t offset, int whence)
600
+ {
556
601
FIL *fh = static_cast <FIL*>(file);
557
602
558
603
lock ();
@@ -574,7 +619,8 @@ off_t FATFileSystem::file_seek(fs_file_t file, off_t offset, int whence) {
574
619
}
575
620
}
576
621
577
- off_t FATFileSystem::file_tell (fs_file_t file) {
622
+ off_t FATFileSystem::file_tell (fs_file_t file)
623
+ {
578
624
FIL *fh = static_cast <FIL*>(file);
579
625
580
626
lock ();
@@ -584,7 +630,8 @@ off_t FATFileSystem::file_tell(fs_file_t file) {
584
630
return res;
585
631
}
586
632
587
- off_t FATFileSystem::file_size (fs_file_t file) {
633
+ off_t FATFileSystem::file_size (fs_file_t file)
634
+ {
588
635
FIL *fh = static_cast <FIL*>(file);
589
636
590
637
lock ();
@@ -596,7 +643,8 @@ off_t FATFileSystem::file_size(fs_file_t file) {
596
643
597
644
598
645
// //// Dir operations //////
599
- int FATFileSystem::dir_open (fs_dir_t *dir, const char *path) {
646
+ int FATFileSystem::dir_open (fs_dir_t *dir, const char *path)
647
+ {
600
648
FATFS_DIR *dh = new FATFS_DIR;
601
649
Deferred<const char *> fpath = fat_path_prefix (_id, path);
602
650
@@ -614,7 +662,8 @@ int FATFileSystem::dir_open(fs_dir_t *dir, const char *path) {
614
662
return 0 ;
615
663
}
616
664
617
- int FATFileSystem::dir_close (fs_dir_t dir) {
665
+ int FATFileSystem::dir_close (fs_dir_t dir)
666
+ {
618
667
FATFS_DIR *dh = static_cast <FATFS_DIR*>(dir);
619
668
620
669
lock ();
@@ -625,7 +674,8 @@ int FATFileSystem::dir_close(fs_dir_t dir) {
625
674
return fat_error_remap (res);
626
675
}
627
676
628
- ssize_t FATFileSystem::dir_read (fs_dir_t dir, struct dirent *ent) {
677
+ ssize_t FATFileSystem::dir_read (fs_dir_t dir, struct dirent *ent)
678
+ {
629
679
FATFS_DIR *dh = static_cast <FATFS_DIR*>(dir);
630
680
FILINFO finfo;
631
681
@@ -653,7 +703,8 @@ ssize_t FATFileSystem::dir_read(fs_dir_t dir, struct dirent *ent) {
653
703
return 1 ;
654
704
}
655
705
656
- void FATFileSystem::dir_seek (fs_dir_t dir, off_t offset) {
706
+ void FATFileSystem::dir_seek (fs_dir_t dir, off_t offset)
707
+ {
657
708
FATFS_DIR *dh = static_cast <FATFS_DIR*>(dir);
658
709
659
710
lock ();
@@ -675,7 +726,8 @@ void FATFileSystem::dir_seek(fs_dir_t dir, off_t offset) {
675
726
unlock ();
676
727
}
677
728
678
- off_t FATFileSystem::dir_tell (fs_dir_t dir) {
729
+ off_t FATFileSystem::dir_tell (fs_dir_t dir)
730
+ {
679
731
FATFS_DIR *dh = static_cast <FATFS_DIR*>(dir);
680
732
681
733
lock ();
@@ -685,7 +737,8 @@ off_t FATFileSystem::dir_tell(fs_dir_t dir) {
685
737
return offset;
686
738
}
687
739
688
- void FATFileSystem::dir_rewind (fs_dir_t dir) {
740
+ void FATFileSystem::dir_rewind (fs_dir_t dir)
741
+ {
689
742
FATFS_DIR *dh = static_cast <FATFS_DIR*>(dir);
690
743
691
744
lock ();
0 commit comments