Skip to content

Commit 833379c

Browse files
committed
Standardized FileSystem init/deinit/reset to match KVStore API
Standardized: FileSystem::mount -> FileSystem::init FileSystem::unmount -> FileSystem::deinit FileSystem::reformat -> FileSystem::reset Note that init/reset no longer accept BlockDevice arguments. This paves the way to standardizing classes to be configured only at construction time. To make this work, recursive init/deinit functions were needed similar to the BlockDevices, and these init/deinit functions are lazily called during the first filesystem operations to match the existing behavior where init/deinit are ignored completely.
1 parent 0404701 commit 833379c

File tree

6 files changed

+429
-136
lines changed

6 files changed

+429
-136
lines changed

features/storage/filesystem/FileSystem.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,31 @@ FileSystem::FileSystem(const char *name)
2626
{
2727
}
2828

29+
int FileSystem::init()
30+
{
31+
return 0;
32+
}
33+
34+
int FileSystem::deinit()
35+
{
36+
return 0;
37+
}
38+
39+
int FileSystem::mount(BlockDevice *bd)
40+
{
41+
return -ENOSYS;
42+
}
43+
44+
int FileSystem::unmount()
45+
{
46+
return -ENOSYS;
47+
}
48+
49+
int FileSystem::reset()
50+
{
51+
return -ENOSYS;
52+
}
53+
2954
int FileSystem::reformat(BlockDevice *bd)
3055
{
3156
return -ENOSYS;

features/storage/filesystem/FileSystem.h

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,44 @@ class FileSystem : public FileSystemLike {
7171
*/
7272
static FileSystem *get_default_instance();
7373

74+
/** Initializes the file system
75+
*
76+
* The init function may be called multiple times recursively as long
77+
* as each init has a matching deinit. If not called, the file system
78+
* will be mounted on the first file system operation.
79+
*
80+
* @return 0 on success, negative error code on failure
81+
*/
82+
virtual int init();
83+
84+
/** Deinitializes the file system
85+
*
86+
* @return 0 on success, negative error code on failure
87+
*/
88+
virtual int deinit();
89+
90+
/** Reformats the underlying filesystem
91+
*
92+
* @return 0 on success, negative error code on failure
93+
*/
94+
virtual int reset();
95+
7496
/** Mounts a filesystem to a block device
7597
*
7698
* @param bd BlockDevice to mount to
7799
* @return 0 on success, negative error code on failure
100+
* @deprecated Replaced by FileSystem::init for consistency with other storage APIs
78101
*/
79-
virtual int mount(BlockDevice *bd) = 0;
102+
MBED_DEPRECATED_SINCE("mbed-os-5.11", "Replaced by FileSystem::init for consistency with other storage APIs")
103+
virtual int mount(BlockDevice *bd);
80104

81105
/** Unmounts a filesystem from the underlying block device
82106
*
83107
* @return 0 on success, negative error code on failure
108+
* @deprecated Replaced by FileSystem::deinit for consistency with other storage APIs
84109
*/
85-
virtual int unmount() = 0;
110+
MBED_DEPRECATED_SINCE("mbed-os-5.11", "Replaced by FileSystem::deinit for consistency with other storage APIs")
111+
virtual int unmount();
86112

87113
/** Reformats a filesystem, results in an empty and mounted filesystem
88114
*
@@ -91,7 +117,9 @@ class FileSystem : public FileSystemLike {
91117
* Note: if mount fails, bd must be provided.
92118
* Default: NULL
93119
* @return 0 on success, negative error code on failure
120+
* @deprecated Replaced by FileSystem::reset for consistency with other storage APIs
94121
*/
122+
MBED_DEPRECATED_SINCE("mbed-os-5.11", "Replaced by FileSystem::reset for consistency with other storage APIs")
95123
virtual int reformat(BlockDevice *bd = NULL);
96124

97125
/** Remove a file from the filesystem.

0 commit comments

Comments
 (0)