From 3f69d1a00d4f2b8c744f210c732feb3f700c2aaa Mon Sep 17 00:00:00 2001 From: deepikabhavnani Date: Thu, 9 Aug 2018 12:06:58 -0500 Subject: [PATCH] Filesystem Class added to mbed namespace --- features/filesystem/fat/FATFileSystem.cpp | 37 +++++++-------- features/filesystem/fat/FATFileSystem.h | 46 ++++++++++--------- .../filesystem/littlefs/LittleFileSystem.cpp | 3 +- .../filesystem/littlefs/LittleFileSystem.h | 2 + 4 files changed, 46 insertions(+), 42 deletions(-) diff --git a/features/filesystem/fat/FATFileSystem.cpp b/features/filesystem/fat/FATFileSystem.cpp index ecb4151b32a..14d0c438444 100644 --- a/features/filesystem/fat/FATFileSystem.cpp +++ b/features/filesystem/fat/FATFileSystem.cpp @@ -29,8 +29,7 @@ #include #include -////// Error handling ///// -using namespace mbed; +namespace mbed { static int fat_error_remap(FRESULT res) { @@ -136,16 +135,14 @@ static Deferred fat_path_prefix(int id, const char *path) return Deferred(buffer, dodelete); } - ////// Disk operations ////// // Global access to block device from FAT driver -static BlockDevice *_ffs[FF_VOLUMES] = {0}; +static mbed::BlockDevice *_ffs[FF_VOLUMES] = {0}; static SingletonPtr _ffs_mutex; - // FAT driver functions -DWORD get_fattime(void) +extern "C" DWORD get_fattime(void) { time_t rawtime; time(&rawtime); @@ -158,12 +155,12 @@ DWORD get_fattime(void) | (DWORD)(ptm->tm_sec/2 ); } -void *ff_memalloc(UINT size) +extern "C" void *ff_memalloc(UINT size) { return malloc(size); } -void ff_memfree(void *p) +extern "C" void ff_memfree(void *p) { free(p); } @@ -189,34 +186,34 @@ static DWORD disk_get_sector_count(BYTE pdrv) return scount; } -DSTATUS disk_status(BYTE pdrv) +extern "C" DSTATUS disk_status(BYTE pdrv) { debug_if(FFS_DBG, "disk_status on pdrv [%d]\n", pdrv); return RES_OK; } -DSTATUS disk_initialize(BYTE pdrv) +extern "C" DSTATUS disk_initialize(BYTE pdrv) { debug_if(FFS_DBG, "disk_initialize on pdrv [%d]\n", pdrv); return (DSTATUS)_ffs[pdrv]->init(); } -DRESULT disk_read(BYTE pdrv, BYTE *buff, DWORD sector, UINT count) +extern "C" DRESULT disk_read(BYTE pdrv, BYTE *buff, DWORD sector, UINT count) { debug_if(FFS_DBG, "disk_read(sector %d, count %d) on pdrv [%d]\n", sector, count, pdrv); DWORD ssize = disk_get_sector_size(pdrv); - bd_addr_t addr = (bd_addr_t)sector*ssize; - bd_size_t size = (bd_size_t)count*ssize; + mbed::bd_addr_t addr = (mbed::bd_addr_t)sector*ssize; + mbed::bd_size_t size = (mbed::bd_size_t)count*ssize; int err = _ffs[pdrv]->read(buff, addr, size); return err ? RES_PARERR : RES_OK; } -DRESULT disk_write(BYTE pdrv, const BYTE *buff, DWORD sector, UINT count) +extern "C" DRESULT disk_write(BYTE pdrv, const BYTE *buff, DWORD sector, UINT count) { debug_if(FFS_DBG, "disk_write(sector %d, count %d) on pdrv [%d]\n", sector, count, pdrv); DWORD ssize = disk_get_sector_size(pdrv); - bd_addr_t addr = (bd_addr_t)sector*ssize; - bd_size_t size = (bd_size_t)count*ssize; + mbed::bd_addr_t addr = (mbed::bd_addr_t)sector*ssize; + mbed::bd_size_t size = (mbed::bd_size_t)count*ssize; int err = _ffs[pdrv]->erase(addr, size); if (err) { return RES_PARERR; @@ -230,7 +227,7 @@ DRESULT disk_write(BYTE pdrv, const BYTE *buff, DWORD sector, UINT count) return RES_OK; } -DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff) +extern "C" DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff) { debug_if(FFS_DBG, "disk_ioctl(%d)\n", cmd); switch (cmd) { @@ -263,8 +260,8 @@ DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff) } else { DWORD *sectors = (DWORD*)buff; DWORD ssize = disk_get_sector_size(pdrv); - bd_addr_t addr = (bd_addr_t)sectors[0]*ssize; - bd_size_t size = (bd_size_t)(sectors[1]-sectors[0]+1)*ssize; + mbed::bd_addr_t addr = (mbed::bd_addr_t)sectors[0]*ssize; + mbed::bd_size_t size = (mbed::bd_size_t)(sectors[1]-sectors[0]+1)*ssize; int err = _ffs[pdrv]->trim(addr, size); return err ? RES_PARERR : RES_OK; } @@ -273,7 +270,6 @@ DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff) return RES_PARERR; } - ////// Generic filesystem operations ////// // Filesystem implementation (See FATFilySystem.h) @@ -825,3 +821,4 @@ void FATFileSystem::dir_rewind(fs_dir_t dir) unlock(); } +} // namespace mbed diff --git a/features/filesystem/fat/FATFileSystem.h b/features/filesystem/fat/FATFileSystem.h index 0bbe1a9d74e..bfdc63a78fc 100644 --- a/features/filesystem/fat/FATFileSystem.h +++ b/features/filesystem/fat/FATFileSystem.h @@ -29,17 +29,19 @@ #include #include "PlatformMutex.h" +namespace mbed { + /** * FATFileSystem based on ChaN's Fat Filesystem library v0.8 */ -class FATFileSystem : public mbed::FileSystem { +class FATFileSystem : public FileSystem { public: /** Lifetime of the FATFileSystem * * @param name Name to add filesystem to tree as * @param bd BlockDevice to mount, may be passed instead to mount call */ - FATFileSystem(const char *name = NULL, mbed::BlockDevice *bd = NULL); + FATFileSystem(const char *name = NULL, BlockDevice *bd = NULL); virtual ~FATFileSystem(); /** Formats a logical drive, FDISK partitioning rule. @@ -58,14 +60,14 @@ class FATFileSystem : public mbed::FileSystem { * * @return 0 on success, negative error code on failure */ - static int format(mbed::BlockDevice *bd, mbed::bd_size_t cluster_size = 0); + static int format(BlockDevice *bd, bd_size_t cluster_size = 0); /** Mounts a filesystem to a block device * * @param bd BlockDevice to mount to * @return 0 on success, negative error code on failure */ - virtual int mount(mbed::BlockDevice *bd); + virtual int mount(BlockDevice *bd); /** Unmounts a filesystem from the underlying block device * @@ -90,7 +92,7 @@ class FATFileSystem : public mbed::FileSystem { * * @return 0 on success, negative error code on failure */ - virtual int reformat(mbed::BlockDevice *bd, int allocation_unit); + virtual int reformat(BlockDevice *bd, int allocation_unit); /** Reformats a filesystem, results in an empty and mounted filesystem * @@ -100,7 +102,7 @@ class FATFileSystem : public mbed::FileSystem { * Default: NULL * @return 0 on success, negative error code on failure */ - virtual int reformat(mbed::BlockDevice *bd = NULL) + virtual int reformat(BlockDevice *bd = NULL) { // required for virtual inheritance shenanigans return reformat(bd, 0); @@ -154,14 +156,14 @@ class FATFileSystem : public mbed::FileSystem { * bitwise or'd with one of O_CREAT, O_TRUNC, O_APPEND * @return 0 on success, negative error code on failure */ - virtual int file_open(mbed::fs_file_t *file, const char *path, int flags); + virtual int file_open(fs_file_t *file, const char *path, int flags); /** Close a file * * @param file File handle * @return 0 on success, negative error code on failure */ - virtual int file_close(mbed::fs_file_t file); + virtual int file_close(fs_file_t file); /** Read the contents of a file into a buffer * @@ -170,7 +172,7 @@ class FATFileSystem : public mbed::FileSystem { * @param len The number of bytes to read * @return The number of bytes read, 0 at end of file, negative error on failure */ - virtual ssize_t file_read(mbed::fs_file_t file, void *buffer, size_t len); + virtual ssize_t file_read(fs_file_t file, void *buffer, size_t len); /** Write the contents of a buffer to a file * @@ -179,14 +181,14 @@ class FATFileSystem : public mbed::FileSystem { * @param len The number of bytes to write * @return The number of bytes written, negative error on failure */ - virtual ssize_t file_write(mbed::fs_file_t file, const void *buffer, size_t len); + virtual ssize_t file_write(fs_file_t file, const void *buffer, size_t len); /** Flush any buffers associated with the file * * @param file File handle * @return 0 on success, negative error code on failure */ - virtual int file_sync(mbed::fs_file_t file); + virtual int file_sync(fs_file_t file); /** Move the file position to a given offset from from a given location * @@ -198,21 +200,21 @@ class FATFileSystem : public mbed::FileSystem { * SEEK_END to start from end of file * @return The new offset of the file */ - virtual off_t file_seek(mbed::fs_file_t file, off_t offset, int whence); + virtual off_t file_seek(fs_file_t file, off_t offset, int whence); /** Get the file position of the file * * @param file File handle * @return The current offset in the file */ - virtual off_t file_tell(mbed::fs_file_t file); + virtual off_t file_tell(fs_file_t file); /** Get the size of the file * * @param file File handle * @return Size of the file in bytes */ - virtual off_t file_size(mbed::fs_file_t file); + virtual off_t file_size(fs_file_t file); /** Open a directory on the filesystem * @@ -220,14 +222,14 @@ class FATFileSystem : public mbed::FileSystem { * @param path Name of the directory to open * @return 0 on success, negative error code on failure */ - virtual int dir_open(mbed::fs_dir_t *dir, const char *path); + virtual int dir_open(fs_dir_t *dir, const char *path); /** Close a directory * * @param dir Dir handle * @return 0 on success, negative error code on failure */ - virtual int dir_close(mbed::fs_dir_t dir); + virtual int dir_close(fs_dir_t dir); /** Read the next directory entry * @@ -235,7 +237,7 @@ class FATFileSystem : public mbed::FileSystem { * @param ent The directory entry to fill out * @return 1 on reading a filename, 0 at end of directory, negative error on failure */ - virtual ssize_t dir_read(mbed::fs_dir_t dir, struct dirent *ent); + virtual ssize_t dir_read(fs_dir_t dir, struct dirent *ent); /** Set the current position of the directory * @@ -243,20 +245,20 @@ class FATFileSystem : public mbed::FileSystem { * @param offset Offset of the location to seek to, * must be a value returned from dir_tell */ - virtual void dir_seek(mbed::fs_dir_t dir, off_t offset); + virtual void dir_seek(fs_dir_t dir, off_t offset); /** Get the current position of the directory * * @param dir Dir handle * @return Position of the directory that can be passed to dir_rewind */ - virtual off_t dir_tell(mbed::fs_dir_t dir); + virtual off_t dir_tell(fs_dir_t dir); /** Rewind the current position to the beginning of the directory * * @param dir Dir handle */ - virtual void dir_rewind(mbed::fs_dir_t dir); + virtual void dir_rewind(fs_dir_t dir); private: FATFS _fs; // Work area (file system object) for logical drive @@ -266,7 +268,9 @@ class FATFileSystem : public mbed::FileSystem { protected: virtual void lock(); virtual void unlock(); - virtual int mount(mbed::BlockDevice *bd, bool mount); + virtual int mount(BlockDevice *bd, bool mount); }; +} // namespace mbed + #endif diff --git a/features/filesystem/littlefs/LittleFileSystem.cpp b/features/filesystem/littlefs/LittleFileSystem.cpp index 3143b131c2d..8dd701091c8 100644 --- a/features/filesystem/littlefs/LittleFileSystem.cpp +++ b/features/filesystem/littlefs/LittleFileSystem.cpp @@ -21,7 +21,7 @@ extern "C" { #include "lfs_util.h" } -using namespace mbed; +namespace mbed { ////// Conversion functions ////// static int lfs_toerror(int err) @@ -540,3 +540,4 @@ void LittleFileSystem::dir_rewind(fs_dir_t dir) _mutex.unlock(); } +} // namespace mbed diff --git a/features/filesystem/littlefs/LittleFileSystem.h b/features/filesystem/littlefs/LittleFileSystem.h index cbd33a71ec9..5fe5793bb6b 100644 --- a/features/filesystem/littlefs/LittleFileSystem.h +++ b/features/filesystem/littlefs/LittleFileSystem.h @@ -23,6 +23,7 @@ extern "C" { #include "lfs.h" } +namespace mbed { /** * LittleFileSystem, a little filesystem @@ -279,5 +280,6 @@ class LittleFileSystem : public mbed::FileSystem { PlatformMutex _mutex; }; +} // namespace mbed #endif