Skip to content

Commit adbd029

Browse files
committed
Added implementation of FileSystem::reformat
1 parent 11440f6 commit adbd029

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

LittleFileSystem.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,31 @@ int LittleFileSystem::format(BlockDevice *bd,
223223
return 0;
224224
}
225225

226+
int LittleFileSystem::reformat(BlockDevice *bd) {
227+
if (_bd) {
228+
if (!bd) {
229+
bd = _bd;
230+
}
231+
232+
int err = unmount();
233+
if (err) {
234+
return err;
235+
}
236+
}
237+
238+
if (!bd) {
239+
return -ENODEV;
240+
}
241+
242+
int err = LittleFileSystem::format(bd,
243+
_read_size, _prog_size, _block_size, _lookahead);
244+
if (err) {
245+
return err;
246+
}
247+
248+
return mount(bd);
249+
}
250+
226251
int LittleFileSystem::remove(const char *filename) {
227252
int err = lfs_remove(&_lfs, filename);
228253
return lfs_toerror(err);

LittleFileSystem.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class LittleFileSystem : public FileSystem {
6565
lfs_size_t lookahead=MBED_LFS_LOOKAHEAD);
6666
virtual ~LittleFileSystem();
6767

68-
/** Formats a logical drive, FDISK partitioning rule.
68+
/** Formats a block device with the LittleFileSystem
6969
*
7070
* The block device to format should be mounted when this function is called.
7171
*
@@ -107,6 +107,18 @@ class LittleFileSystem : public FileSystem {
107107
*/
108108
virtual int unmount();
109109

110+
/** Reformats a filesystem, results in an empty and mounted filesystem
111+
*
112+
* @param bd
113+
* BlockDevice to reformat and mount. If NULL, the mounted
114+
* block device will be used.
115+
* Note: if mount fails, bd must be provided.
116+
* Default: NULL
117+
*
118+
* @return 0 on success, negative error code on failure
119+
*/
120+
virtual int reformat(BlockDevice *bd);
121+
110122
/** Remove a file from the filesystem.
111123
*
112124
* @param path The name of the file to remove.

0 commit comments

Comments
 (0)