Skip to content

Commit 5ab4bf1

Browse files
committed
fs: Added FileSystem::get_block_device
Required for accessing the underlying block device. This can be used to modify the state of the block device outside of the filesystem. The best example is if you are reformatting a filesystem: BlockDevice *bd = fs.get_block_device(); fs.unmount(); FATFileSystem::format(bd); fs.mount(bd);
1 parent 1c94828 commit 5ab4bf1

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

features/filesystem/FileSystem.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ int FileSystem::mkdir(const char *path, mode_t mode)
4444
return -ENOSYS;
4545
}
4646

47+
BlockDevice *FileSystem::get_block_device() const
48+
{
49+
return NULL;
50+
}
51+
4752
int FileSystem::file_sync(fs_file_t file)
4853
{
4954
return 0;

features/filesystem/FileSystem.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ class FileSystem : public FileSystemLike {
9999
*/
100100
virtual int mkdir(const char *path, mode_t mode);
101101

102+
/** Get the underlying block device
103+
*
104+
* @return The underlying block device, or NULL if no block
105+
* device has been mounted
106+
*/
107+
virtual BlockDevice *get_block_device() const;
108+
102109
protected:
103110
friend class File;
104111
friend class Dir;

features/filesystem/fat/FATFileSystem.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,15 @@ int FATFileSystem::unmount()
293293
return fat_error_remap(res);
294294
}
295295

296+
BlockDevice *FATFileSystem::get_block_device() const
297+
{
298+
if (_id != -1) {
299+
return _ffs[_id];
300+
} else {
301+
return NULL;
302+
}
303+
}
304+
296305
/* See http://elm-chan.org/fsw/ff/en/mkfs.html for details of f_mkfs() and
297306
* associated arguments. */
298307
int FATFileSystem::format(BlockDevice *bd, int allocation_unit) {

features/filesystem/fat/FATFileSystem.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ class FATFileSystem : public FileSystem {
106106
*/
107107
virtual int mkdir(const char *path, mode_t mode);
108108

109+
/** Get the underlying block device
110+
*
111+
* @return The underlying block device, or NULL if no block
112+
* device has been mounted
113+
*/
114+
virtual BlockDevice *get_block_device() const;
115+
109116
protected:
110117
/** Open a file on the filesystem
111118
*

0 commit comments

Comments
 (0)