From e114a361beeb4273da4a81983e302f87fc7dea55 Mon Sep 17 00:00:00 2001 From: SciresM Date: Wed, 8 May 2019 07:44:17 -0700 Subject: [PATCH] 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. --- nx/include/switch/runtime/devices/fs_dev.h | 3 +++ nx/source/runtime/devices/fs_dev.c | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/nx/include/switch/runtime/devices/fs_dev.h b/nx/include/switch/runtime/devices/fs_dev.h index 0c2af7bd..5f4b9e99 100644 --- a/nx/include/switch/runtime/devices/fs_dev.h +++ b/nx/include/switch/runtime/devices/fs_dev.h @@ -53,3 +53,6 @@ Result fsdevDeleteDirectoryRecursively(const char *path); /// Unmounts all devices and cleans up any resources used by the FS driver. Result fsdevUnmountAll(void); + +/// Retrieves the last native result code generated during a failed fsdev operation. +Result fsdevGetLastResult(void); diff --git a/nx/source/runtime/devices/fs_dev.c b/nx/source/runtime/devices/fs_dev.c index c93ad498..88fd29a6 100644 --- a/nx/source/runtime/devices/fs_dev.c +++ b/nx/source/runtime/devices/fs_dev.c @@ -101,6 +101,7 @@ typedef struct static bool fsdev_initialised = false; static s32 fsdev_fsdevice_default = -1; static s32 fsdev_fsdevice_cwd = -1; +static __thread Result fsdev_last_result = 0; static fsdev_fsdevice fsdev_fsdevices[32]; /*! @endcond */ @@ -1647,6 +1648,7 @@ error_cmp(const void *p1, const void *p2) static int fsdev_translate_error(Result error) { + fsdev_last_result = error; error_map_t key = { .fs_error = error }; const error_map_t *rc = bsearch(&key, error_table, num_errors, sizeof(error_map_t), error_cmp); @@ -1654,6 +1656,14 @@ fsdev_translate_error(Result error) if(rc != NULL) 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; }