Skip to content

Commit 8b63749

Browse files
committed
Filesystem: Integrate error handling between c++/posix layers
1 parent 8d03303 commit 8b63749

File tree

7 files changed

+225
-129
lines changed

7 files changed

+225
-129
lines changed

features/filesystem/Dir.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "Dir.h"
1818
#include "mbed.h"
19+
#include <errno.h>
1920

2021

2122
Dir::Dir()
@@ -39,7 +40,7 @@ Dir::~Dir()
3940
int Dir::open(FileSystem *fs, const char *path)
4041
{
4142
if (_fs) {
42-
return FS_ERROR_PARAMETER;
43+
return -EINVAL;
4344
}
4445

4546
_fs = fs;
@@ -49,7 +50,7 @@ int Dir::open(FileSystem *fs, const char *path)
4950
int Dir::close()
5051
{
5152
if (!_fs) {
52-
return FS_ERROR_PARAMETER;
53+
return -EINVAL;
5354
}
5455

5556
int err = _fs->dir_close(_dir);

features/filesystem/File.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "File.h"
1818
#include "mbed.h"
19+
#include <errno.h>
1920

2021

2122
File::File()
@@ -39,7 +40,7 @@ File::~File()
3940
int File::open(FileSystem *fs, const char *path, int flags)
4041
{
4142
if (_fs) {
42-
return FS_ERROR_PARAMETER;
43+
return -EINVAL;
4344
}
4445

4546
int err = fs->file_open(&_file, path, flags);
@@ -53,7 +54,7 @@ int File::open(FileSystem *fs, const char *path, int flags)
5354
int File::close()
5455
{
5556
if (!_fs) {
56-
return FS_ERROR_PARAMETER;
57+
return -EINVAL;
5758
}
5859

5960
int err = _fs->file_close(_file);

features/filesystem/FileSystem.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "mbed.h"
1919
#include "filesystem/FileSystem.h"
20+
#include <errno.h>
2021

2122

2223
FileSystem::FileSystem(const char *name)
@@ -54,22 +55,22 @@ size_t FileSystem::file_size(fs_file_t file)
5455

5556
int FileSystem::mkdir(const char *path, mode_t mode)
5657
{
57-
return FS_ERROR_UNSUPPORTED;
58+
return -ENOSYS;
5859
}
5960

6061
int FileSystem::dir_open(fs_dir_t *dir, const char *path)
6162
{
62-
return FS_ERROR_UNSUPPORTED;
63+
return -ENOSYS;
6364
}
6465

6566
int FileSystem::dir_close(fs_dir_t dir)
6667
{
67-
return FS_ERROR_UNSUPPORTED;
68+
return -ENOSYS;
6869
}
6970

7071
ssize_t FileSystem::dir_read(fs_dir_t dir, char *path, size_t len)
7172
{
72-
return FS_ERROR_UNSUPPORTED;
73+
return -ENOSYS;
7374
}
7475

7576
ssize_t FileSystem::dir_read(fs_dir_t dir, char *path, size_t len, uint8_t *type)

features/filesystem/FileSystem.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,11 @@ namespace mbed {
2626
/** \addtogroup filesystem */
2727
/** @{*/
2828

29-
/** Enum of standardized error codes
30-
*
31-
* Valid error codes have negative values and may
32-
* be returned by any network operation
33-
*/
34-
enum fs_error {
35-
FS_ERROR_OK = 0, ///< no error
36-
FS_ERROR_UNSUPPORTED = -5001, ///< unsupported functionality
37-
FS_ERROR_PARAMETER = -5002, ///< invalid parameter
38-
};
3929

4030
// Opaque pointer representing files and directories
4131
typedef void *fs_file_t;
4232
typedef void *fs_dir_t;
4333

44-
45-
4634
/** A filesystem-like object is one that can be used to open files
4735
* though it by fopen("/name/filename", flags)
4836
*

0 commit comments

Comments
 (0)