fsdev: add way of getting last returned result. (#276)

Adds fsdevGetLastResult, which returns a thread local Result updated by every call to fsdev_translate_error.

Also changes fsdev_translate_error to return EIO instead of raw results, when not translatable.
This commit is contained in:
SciresM 2019-05-08 07:44:17 -07:00 committed by fincs
parent e359010e75
commit e114a361be
2 changed files with 14 additions and 1 deletions

View File

@ -53,3 +53,6 @@ Result fsdevDeleteDirectoryRecursively(const char *path);
/// Unmounts all devices and cleans up any resources used by the FS driver. /// Unmounts all devices and cleans up any resources used by the FS driver.
Result fsdevUnmountAll(void); Result fsdevUnmountAll(void);
/// Retrieves the last native result code generated during a failed fsdev operation.
Result fsdevGetLastResult(void);

View File

@ -101,6 +101,7 @@ typedef struct
static bool fsdev_initialised = false; static bool fsdev_initialised = false;
static s32 fsdev_fsdevice_default = -1; static s32 fsdev_fsdevice_default = -1;
static s32 fsdev_fsdevice_cwd = -1; static s32 fsdev_fsdevice_cwd = -1;
static __thread Result fsdev_last_result = 0;
static fsdev_fsdevice fsdev_fsdevices[32]; static fsdev_fsdevice fsdev_fsdevices[32];
/*! @endcond */ /*! @endcond */
@ -1647,6 +1648,7 @@ error_cmp(const void *p1, const void *p2)
static int static int
fsdev_translate_error(Result error) fsdev_translate_error(Result error)
{ {
fsdev_last_result = error;
error_map_t key = { .fs_error = error }; error_map_t key = { .fs_error = error };
const error_map_t *rc = bsearch(&key, error_table, num_errors, const error_map_t *rc = bsearch(&key, error_table, num_errors,
sizeof(error_map_t), error_cmp); sizeof(error_map_t), error_cmp);
@ -1654,6 +1656,14 @@ fsdev_translate_error(Result error)
if(rc != NULL) if(rc != NULL)
return rc->error; return rc->error;
return (int)error; return EIO;
}
/*! Getter for last error code translated to errno by fsdev library.
*
* @returns result
*/
Result fsdevGetLastResult(void) {
return fsdev_last_result;
} }