From 979bc3e2d5308da2b43a555a908032cee8030ca7 Mon Sep 17 00:00:00 2001 From: neilt6 Date: Wed, 30 Jul 2014 10:22:23 -0600 Subject: [PATCH] Added mount/unmount to FATFileSystem Added virtual mount()/unmount() methods to FATFileSystem to allow users to swap removable disks. --- libraries/fs/fat/FATFileSystem.cpp | 12 ++++++++++++ libraries/fs/fat/FATFileSystem.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/libraries/fs/fat/FATFileSystem.cpp b/libraries/fs/fat/FATFileSystem.cpp index ee7172c0a8..fb0eb5253f 100644 --- a/libraries/fs/fat/FATFileSystem.cpp +++ b/libraries/fs/fat/FATFileSystem.cpp @@ -130,3 +130,15 @@ int FATFileSystem::mkdir(const char *name, mode_t mode) { FRESULT res = f_mkdir(name); return res == 0 ? 0 : -1; } + +int FATFileSystem::mount() { + FRESULT res = f_mount(_fsid, &_fs); + return res == 0 ? 0 : -1; +} + +int FATFileSystem::unmount() { + if (disk_sync()) + return -1; + FRESULT res = f_mount(_fsid, NULL); + return res == 0 ? 0 : -1; +} diff --git a/libraries/fs/fat/FATFileSystem.h b/libraries/fs/fat/FATFileSystem.h index 492b470d18..1d8f56d9b5 100644 --- a/libraries/fs/fat/FATFileSystem.h +++ b/libraries/fs/fat/FATFileSystem.h @@ -44,6 +44,8 @@ public: virtual int format(); virtual DirHandle *opendir(const char *name); virtual int mkdir(const char *name, mode_t mode); + virtual int mount(); + virtual int unmount(); virtual int disk_initialize() { return 0; } virtual int disk_status() { return 0; }