Added implementation of FileSystem::reformat

pull/5538/head
Christopher Haster 2017-10-26 17:09:56 -05:00
parent 11440f6018
commit adbd0290f8
2 changed files with 38 additions and 1 deletions

View File

@ -223,6 +223,31 @@ int LittleFileSystem::format(BlockDevice *bd,
return 0;
}
int LittleFileSystem::reformat(BlockDevice *bd) {
if (_bd) {
if (!bd) {
bd = _bd;
}
int err = unmount();
if (err) {
return err;
}
}
if (!bd) {
return -ENODEV;
}
int err = LittleFileSystem::format(bd,
_read_size, _prog_size, _block_size, _lookahead);
if (err) {
return err;
}
return mount(bd);
}
int LittleFileSystem::remove(const char *filename) {
int err = lfs_remove(&_lfs, filename);
return lfs_toerror(err);

View File

@ -65,7 +65,7 @@ public:
lfs_size_t lookahead=MBED_LFS_LOOKAHEAD);
virtual ~LittleFileSystem();
/** Formats a logical drive, FDISK partitioning rule.
/** Formats a block device with the LittleFileSystem
*
* The block device to format should be mounted when this function is called.
*
@ -107,6 +107,18 @@ public:
*/
virtual int unmount();
/** Reformats a filesystem, results in an empty and mounted filesystem
*
* @param bd
* BlockDevice to reformat and mount. If NULL, the mounted
* block device will be used.
* Note: if mount fails, bd must be provided.
* Default: NULL
*
* @return 0 on success, negative error code on failure
*/
virtual int reformat(BlockDevice *bd);
/** Remove a file from the filesystem.
*
* @param path The name of the file to remove.