Skip to content

Commit 3f69d1a

Browse files
author
deepikabhavnani
committed
Filesystem Class added to mbed namespace
1 parent 0346d22 commit 3f69d1a

File tree

4 files changed

+46
-42
lines changed

4 files changed

+46
-42
lines changed

features/filesystem/fat/FATFileSystem.cpp

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
#include <errno.h>
3030
#include <stdlib.h>
3131

32-
////// Error handling /////
33-
using namespace mbed;
32+
namespace mbed {
3433

3534
static int fat_error_remap(FRESULT res)
3635
{
@@ -136,16 +135,14 @@ static Deferred<const char*> fat_path_prefix(int id, const char *path)
136135
return Deferred<const char*>(buffer, dodelete);
137136
}
138137

139-
140138
////// Disk operations //////
141139

142140
// Global access to block device from FAT driver
143-
static BlockDevice *_ffs[FF_VOLUMES] = {0};
141+
static mbed::BlockDevice *_ffs[FF_VOLUMES] = {0};
144142
static SingletonPtr<PlatformMutex> _ffs_mutex;
145143

146-
147144
// FAT driver functions
148-
DWORD get_fattime(void)
145+
extern "C" DWORD get_fattime(void)
149146
{
150147
time_t rawtime;
151148
time(&rawtime);
@@ -158,12 +155,12 @@ DWORD get_fattime(void)
158155
| (DWORD)(ptm->tm_sec/2 );
159156
}
160157

161-
void *ff_memalloc(UINT size)
158+
extern "C" void *ff_memalloc(UINT size)
162159
{
163160
return malloc(size);
164161
}
165162

166-
void ff_memfree(void *p)
163+
extern "C" void ff_memfree(void *p)
167164
{
168165
free(p);
169166
}
@@ -189,34 +186,34 @@ static DWORD disk_get_sector_count(BYTE pdrv)
189186
return scount;
190187
}
191188

192-
DSTATUS disk_status(BYTE pdrv)
189+
extern "C" DSTATUS disk_status(BYTE pdrv)
193190
{
194191
debug_if(FFS_DBG, "disk_status on pdrv [%d]\n", pdrv);
195192
return RES_OK;
196193
}
197194

198-
DSTATUS disk_initialize(BYTE pdrv)
195+
extern "C" DSTATUS disk_initialize(BYTE pdrv)
199196
{
200197
debug_if(FFS_DBG, "disk_initialize on pdrv [%d]\n", pdrv);
201198
return (DSTATUS)_ffs[pdrv]->init();
202199
}
203200

204-
DRESULT disk_read(BYTE pdrv, BYTE *buff, DWORD sector, UINT count)
201+
extern "C" DRESULT disk_read(BYTE pdrv, BYTE *buff, DWORD sector, UINT count)
205202
{
206203
debug_if(FFS_DBG, "disk_read(sector %d, count %d) on pdrv [%d]\n", sector, count, pdrv);
207204
DWORD ssize = disk_get_sector_size(pdrv);
208-
bd_addr_t addr = (bd_addr_t)sector*ssize;
209-
bd_size_t size = (bd_size_t)count*ssize;
205+
mbed::bd_addr_t addr = (mbed::bd_addr_t)sector*ssize;
206+
mbed::bd_size_t size = (mbed::bd_size_t)count*ssize;
210207
int err = _ffs[pdrv]->read(buff, addr, size);
211208
return err ? RES_PARERR : RES_OK;
212209
}
213210

214-
DRESULT disk_write(BYTE pdrv, const BYTE *buff, DWORD sector, UINT count)
211+
extern "C" DRESULT disk_write(BYTE pdrv, const BYTE *buff, DWORD sector, UINT count)
215212
{
216213
debug_if(FFS_DBG, "disk_write(sector %d, count %d) on pdrv [%d]\n", sector, count, pdrv);
217214
DWORD ssize = disk_get_sector_size(pdrv);
218-
bd_addr_t addr = (bd_addr_t)sector*ssize;
219-
bd_size_t size = (bd_size_t)count*ssize;
215+
mbed::bd_addr_t addr = (mbed::bd_addr_t)sector*ssize;
216+
mbed::bd_size_t size = (mbed::bd_size_t)count*ssize;
220217
int err = _ffs[pdrv]->erase(addr, size);
221218
if (err) {
222219
return RES_PARERR;
@@ -230,7 +227,7 @@ DRESULT disk_write(BYTE pdrv, const BYTE *buff, DWORD sector, UINT count)
230227
return RES_OK;
231228
}
232229

233-
DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff)
230+
extern "C" DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff)
234231
{
235232
debug_if(FFS_DBG, "disk_ioctl(%d)\n", cmd);
236233
switch (cmd) {
@@ -263,8 +260,8 @@ DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff)
263260
} else {
264261
DWORD *sectors = (DWORD*)buff;
265262
DWORD ssize = disk_get_sector_size(pdrv);
266-
bd_addr_t addr = (bd_addr_t)sectors[0]*ssize;
267-
bd_size_t size = (bd_size_t)(sectors[1]-sectors[0]+1)*ssize;
263+
mbed::bd_addr_t addr = (mbed::bd_addr_t)sectors[0]*ssize;
264+
mbed::bd_size_t size = (mbed::bd_size_t)(sectors[1]-sectors[0]+1)*ssize;
268265
int err = _ffs[pdrv]->trim(addr, size);
269266
return err ? RES_PARERR : RES_OK;
270267
}
@@ -273,7 +270,6 @@ DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff)
273270
return RES_PARERR;
274271
}
275272

276-
277273
////// Generic filesystem operations //////
278274

279275
// Filesystem implementation (See FATFilySystem.h)
@@ -825,3 +821,4 @@ void FATFileSystem::dir_rewind(fs_dir_t dir)
825821
unlock();
826822
}
827823

824+
} // namespace mbed

features/filesystem/fat/FATFileSystem.h

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,19 @@
2929
#include <stdint.h>
3030
#include "PlatformMutex.h"
3131

32+
namespace mbed {
33+
3234
/**
3335
* FATFileSystem based on ChaN's Fat Filesystem library v0.8
3436
*/
35-
class FATFileSystem : public mbed::FileSystem {
37+
class FATFileSystem : public FileSystem {
3638
public:
3739
/** Lifetime of the FATFileSystem
3840
*
3941
* @param name Name to add filesystem to tree as
4042
* @param bd BlockDevice to mount, may be passed instead to mount call
4143
*/
42-
FATFileSystem(const char *name = NULL, mbed::BlockDevice *bd = NULL);
44+
FATFileSystem(const char *name = NULL, BlockDevice *bd = NULL);
4345
virtual ~FATFileSystem();
4446

4547
/** Formats a logical drive, FDISK partitioning rule.
@@ -58,14 +60,14 @@ class FATFileSystem : public mbed::FileSystem {
5860
*
5961
* @return 0 on success, negative error code on failure
6062
*/
61-
static int format(mbed::BlockDevice *bd, mbed::bd_size_t cluster_size = 0);
63+
static int format(BlockDevice *bd, bd_size_t cluster_size = 0);
6264

6365
/** Mounts a filesystem to a block device
6466
*
6567
* @param bd BlockDevice to mount to
6668
* @return 0 on success, negative error code on failure
6769
*/
68-
virtual int mount(mbed::BlockDevice *bd);
70+
virtual int mount(BlockDevice *bd);
6971

7072
/** Unmounts a filesystem from the underlying block device
7173
*
@@ -90,7 +92,7 @@ class FATFileSystem : public mbed::FileSystem {
9092
*
9193
* @return 0 on success, negative error code on failure
9294
*/
93-
virtual int reformat(mbed::BlockDevice *bd, int allocation_unit);
95+
virtual int reformat(BlockDevice *bd, int allocation_unit);
9496

9597
/** Reformats a filesystem, results in an empty and mounted filesystem
9698
*
@@ -100,7 +102,7 @@ class FATFileSystem : public mbed::FileSystem {
100102
* Default: NULL
101103
* @return 0 on success, negative error code on failure
102104
*/
103-
virtual int reformat(mbed::BlockDevice *bd = NULL)
105+
virtual int reformat(BlockDevice *bd = NULL)
104106
{
105107
// required for virtual inheritance shenanigans
106108
return reformat(bd, 0);
@@ -154,14 +156,14 @@ class FATFileSystem : public mbed::FileSystem {
154156
* bitwise or'd with one of O_CREAT, O_TRUNC, O_APPEND
155157
* @return 0 on success, negative error code on failure
156158
*/
157-
virtual int file_open(mbed::fs_file_t *file, const char *path, int flags);
159+
virtual int file_open(fs_file_t *file, const char *path, int flags);
158160

159161
/** Close a file
160162
*
161163
* @param file File handle
162164
* @return 0 on success, negative error code on failure
163165
*/
164-
virtual int file_close(mbed::fs_file_t file);
166+
virtual int file_close(fs_file_t file);
165167

166168
/** Read the contents of a file into a buffer
167169
*
@@ -170,7 +172,7 @@ class FATFileSystem : public mbed::FileSystem {
170172
* @param len The number of bytes to read
171173
* @return The number of bytes read, 0 at end of file, negative error on failure
172174
*/
173-
virtual ssize_t file_read(mbed::fs_file_t file, void *buffer, size_t len);
175+
virtual ssize_t file_read(fs_file_t file, void *buffer, size_t len);
174176

175177
/** Write the contents of a buffer to a file
176178
*
@@ -179,14 +181,14 @@ class FATFileSystem : public mbed::FileSystem {
179181
* @param len The number of bytes to write
180182
* @return The number of bytes written, negative error on failure
181183
*/
182-
virtual ssize_t file_write(mbed::fs_file_t file, const void *buffer, size_t len);
184+
virtual ssize_t file_write(fs_file_t file, const void *buffer, size_t len);
183185

184186
/** Flush any buffers associated with the file
185187
*
186188
* @param file File handle
187189
* @return 0 on success, negative error code on failure
188190
*/
189-
virtual int file_sync(mbed::fs_file_t file);
191+
virtual int file_sync(fs_file_t file);
190192

191193
/** Move the file position to a given offset from from a given location
192194
*
@@ -198,65 +200,65 @@ class FATFileSystem : public mbed::FileSystem {
198200
* SEEK_END to start from end of file
199201
* @return The new offset of the file
200202
*/
201-
virtual off_t file_seek(mbed::fs_file_t file, off_t offset, int whence);
203+
virtual off_t file_seek(fs_file_t file, off_t offset, int whence);
202204

203205
/** Get the file position of the file
204206
*
205207
* @param file File handle
206208
* @return The current offset in the file
207209
*/
208-
virtual off_t file_tell(mbed::fs_file_t file);
210+
virtual off_t file_tell(fs_file_t file);
209211

210212
/** Get the size of the file
211213
*
212214
* @param file File handle
213215
* @return Size of the file in bytes
214216
*/
215-
virtual off_t file_size(mbed::fs_file_t file);
217+
virtual off_t file_size(fs_file_t file);
216218

217219
/** Open a directory on the filesystem
218220
*
219221
* @param dir Destination for the handle to the directory
220222
* @param path Name of the directory to open
221223
* @return 0 on success, negative error code on failure
222224
*/
223-
virtual int dir_open(mbed::fs_dir_t *dir, const char *path);
225+
virtual int dir_open(fs_dir_t *dir, const char *path);
224226

225227
/** Close a directory
226228
*
227229
* @param dir Dir handle
228230
* @return 0 on success, negative error code on failure
229231
*/
230-
virtual int dir_close(mbed::fs_dir_t dir);
232+
virtual int dir_close(fs_dir_t dir);
231233

232234
/** Read the next directory entry
233235
*
234236
* @param dir Dir handle
235237
* @param ent The directory entry to fill out
236238
* @return 1 on reading a filename, 0 at end of directory, negative error on failure
237239
*/
238-
virtual ssize_t dir_read(mbed::fs_dir_t dir, struct dirent *ent);
240+
virtual ssize_t dir_read(fs_dir_t dir, struct dirent *ent);
239241

240242
/** Set the current position of the directory
241243
*
242244
* @param dir Dir handle
243245
* @param offset Offset of the location to seek to,
244246
* must be a value returned from dir_tell
245247
*/
246-
virtual void dir_seek(mbed::fs_dir_t dir, off_t offset);
248+
virtual void dir_seek(fs_dir_t dir, off_t offset);
247249

248250
/** Get the current position of the directory
249251
*
250252
* @param dir Dir handle
251253
* @return Position of the directory that can be passed to dir_rewind
252254
*/
253-
virtual off_t dir_tell(mbed::fs_dir_t dir);
255+
virtual off_t dir_tell(fs_dir_t dir);
254256

255257
/** Rewind the current position to the beginning of the directory
256258
*
257259
* @param dir Dir handle
258260
*/
259-
virtual void dir_rewind(mbed::fs_dir_t dir);
261+
virtual void dir_rewind(fs_dir_t dir);
260262

261263
private:
262264
FATFS _fs; // Work area (file system object) for logical drive
@@ -266,7 +268,9 @@ class FATFileSystem : public mbed::FileSystem {
266268
protected:
267269
virtual void lock();
268270
virtual void unlock();
269-
virtual int mount(mbed::BlockDevice *bd, bool mount);
271+
virtual int mount(BlockDevice *bd, bool mount);
270272
};
271273

274+
} // namespace mbed
275+
272276
#endif

features/filesystem/littlefs/LittleFileSystem.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extern "C" {
2121
#include "lfs_util.h"
2222
}
2323

24-
using namespace mbed;
24+
namespace mbed {
2525

2626
////// Conversion functions //////
2727
static int lfs_toerror(int err)
@@ -540,3 +540,4 @@ void LittleFileSystem::dir_rewind(fs_dir_t dir)
540540
_mutex.unlock();
541541
}
542542

543+
} // namespace mbed

features/filesystem/littlefs/LittleFileSystem.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ extern "C" {
2323
#include "lfs.h"
2424
}
2525

26+
namespace mbed {
2627

2728
/**
2829
* LittleFileSystem, a little filesystem
@@ -279,5 +280,6 @@ class LittleFileSystem : public mbed::FileSystem {
279280
PlatformMutex _mutex;
280281
};
281282

283+
} // namespace mbed
282284

283285
#endif

0 commit comments

Comments
 (0)