File tree 6 files changed +65
-0
lines changed
6 files changed +65
-0
lines changed Original file line number Diff line number Diff line change @@ -212,6 +212,8 @@ void setup(){
212
212
renameFile (SD, " /hello.txt" , " /foo.txt" );
213
213
readFile (SD, " /foo.txt" );
214
214
testFileIO (SD, " /test.txt" );
215
+ Serial.printf (" Total space: %lluMB\n " , SD.totalBytes () / (1024 * 1024 ));
216
+ Serial.printf (" Used space: %lluMB\n " , SD.usedBytes () / (1024 * 1024 ));
215
217
}
216
218
217
219
void loop (){
Original file line number Diff line number Diff line change 14
14
15
15
#include " vfs_api.h"
16
16
#include " sd_diskio.h"
17
+ #include " ff.h"
17
18
#include " FS.h"
18
19
#include " SD.h"
19
20
@@ -73,4 +74,32 @@ uint64_t SDFS::cardSize()
73
74
return (uint64_t )sectors * sectorSize;
74
75
}
75
76
77
+ uint64_t SDFS::totalBytes ()
78
+ {
79
+ FATFS* fsinfo;
80
+ DWORD fre_clust;
81
+ if (f_getfree (" 0:" ,&fre_clust,&fsinfo)!= 0 ) return 0 ;
82
+ uint64_t size = (fsinfo->csize )*(fsinfo->n_fatent - 2 )
83
+ #if _MAX_SS != 512
84
+ *(fsinfo->ssize );
85
+ #else
86
+ *512 ;
87
+ #endif
88
+ return size;
89
+ }
90
+
91
+ uint64_t SDFS::usedBytes ()
92
+ {
93
+ FATFS* fsinfo;
94
+ DWORD fre_clust;
95
+ if (f_getfree (" 0:" ,&fre_clust,&fsinfo)!= 0 ) return 0 ;
96
+ uint64_t size = (fsinfo->csize )*((fsinfo->n_fatent - 2 ) - (fsinfo->free_clst ))
97
+ #if _MAX_SS != 512
98
+ *(fsinfo->ssize );
99
+ #else
100
+ *512 ;
101
+ #endif
102
+ return size;
103
+ }
104
+
76
105
SDFS SD = SDFS(FSImplPtr(new VFSImpl()));
Original file line number Diff line number Diff line change @@ -32,6 +32,8 @@ class SDFS : public FS
32
32
void end ();
33
33
sdcard_type_t cardType ();
34
34
uint64_t cardSize ();
35
+ uint64_t totalBytes ();
36
+ uint64_t usedBytes ();
35
37
};
36
38
37
39
}
Original file line number Diff line number Diff line change @@ -209,6 +209,8 @@ void setup(){
209
209
renameFile (SD_MMC, " /hello.txt" , " /foo.txt" );
210
210
readFile (SD_MMC, " /foo.txt" );
211
211
testFileIO (SD_MMC, " /test.txt" );
212
+ Serial.printf (" Total space: %lluMB\n " , SD_MMC.totalBytes () / (1024 * 1024 ));
213
+ Serial.printf (" Used space: %lluMB\n " , SD_MMC.usedBytes () / (1024 * 1024 ));
212
214
}
213
215
214
216
void loop (){
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ extern "C" {
23
23
#include " driver/sdmmc_defs.h"
24
24
#include " sdmmc_cmd.h"
25
25
}
26
+ #include " ff.h"
26
27
#include " SD_MMC.h"
27
28
28
29
using namespace fs ;
@@ -98,5 +99,32 @@ uint64_t SDMMCFS::cardSize()
98
99
return (uint64_t )_card->csd .capacity * _card->csd .sector_size ;
99
100
}
100
101
102
+ uint64_t SDMMCFS::totalBytes ()
103
+ {
104
+ FATFS* fsinfo;
105
+ DWORD fre_clust;
106
+ if (f_getfree (" 0:" ,&fre_clust,&fsinfo)!= 0 ) return 0 ;
107
+ uint64_t size = (fsinfo->csize )*(fsinfo->n_fatent - 2 )
108
+ #if _MAX_SS != 512
109
+ *(fsinfo->ssize );
110
+ #else
111
+ *512 ;
112
+ #endif
113
+ return size;
114
+ }
115
+
116
+ uint64_t SDMMCFS::usedBytes ()
117
+ {
118
+ FATFS* fsinfo;
119
+ DWORD fre_clust;
120
+ if (f_getfree (" 0:" ,&fre_clust,&fsinfo)!= 0 ) return 0 ;
121
+ uint64_t size = (fsinfo->csize )*((fsinfo->n_fatent - 2 ) - (fsinfo->free_clst ))
122
+ #if _MAX_SS != 512
123
+ *(fsinfo->ssize );
124
+ #else
125
+ *512 ;
126
+ #endif
127
+ return size;
128
+ }
101
129
102
130
SDMMCFS SD_MMC = SDMMCFS(FSImplPtr(new VFSImpl()));
Original file line number Diff line number Diff line change @@ -32,6 +32,8 @@ class SDMMCFS : public FS
32
32
void end ();
33
33
sdcard_type_t cardType ();
34
34
uint64_t cardSize ();
35
+ uint64_t totalBytes ();
36
+ uint64_t usedBytes ();
35
37
};
36
38
37
39
}
You can’t perform that action at this time.
0 commit comments