Better mapping of Posix error codes.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15268 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
Giovanni Di Sirio 2021-12-27 13:25:13 +00:00
parent 6810ebca2d
commit 6c35d59058
3 changed files with 39 additions and 26 deletions

View File

@ -163,9 +163,9 @@ extern "C" {
/*===========================================================================*/ /*===========================================================================*/
#include "sberr.h" #include "sberr.h"
#include "sbposix.h"
#include "sbhost.h" #include "sbhost.h"
#include "sbapi.h" #include "sbapi.h"
#include "sbposix.h"
#endif /* SBHOST_H */ #endif /* SBHOST_H */

View File

@ -296,7 +296,7 @@ static msg_t node_file_setpos(void *instance, vfs_offset_t offset) {
(void)instance; (void)instance;
(void)offset; (void)offset;
return VFS_RET_NOT_IMPLEMENTED; return VFS_RET_ENOSYS;
} }
static vfs_offset_t node_file_getpos(void *instance) { static vfs_offset_t node_file_getpos(void *instance) {

View File

@ -35,31 +35,37 @@
/*===========================================================================*/ /*===========================================================================*/
/** /**
* @name Error codes compatible with HAL and Posix * @name VFS error codes
* @{ * @{
*/ */
#define VFS_RET_SUCCESS 0 /* Success */ #define VFS_RET_SUCCESS (msg_t)MSG_OK /* Success */
#define VFS_RET_TIMEOUT -1 /* Timeout */ #define VFS_RET_TIMEOUT (msg_t)MSG_TIMEOUT /* Timeout */
#define VFS_RET_EOF -2 /* End-of-file */ #define VFS_RET_EOF (msg_t)-3 /* End-of-file */
#define VFS_RET_NOT_IMPLEMENTED -3 /* Not implemented functionality */ #define VFS_RET_INNER_ERROR (msg_t)-4 /* Unexpected condition */
#define VFS_RET_INNER_ERROR -4 /* Unspecified error */ /** @} */
#define VFS_RET_ENOENT (-32 - ENOENT) /* No such file or directory */
#define VFS_RET_EIO (-32 - EIO) /* I/O error */ /**
#define VFS_RET_EBADF (-32 - EBADF) /* Bad file number */ * @name Error codes compatible with Posix
#define VFS_RET_ENOMEM (-32 - ENOMEM) /* Not enough space */ * @{
#define VFS_RET_EACCES (-32 - EACCES) /* Permission denied */ */
#define VFS_RET_EEXIST (-32 - EEXIST) /* File exists */ #define VFS_RET_ENOENT VFS_ERROR(ENOENT) /* No such file or directory */
#define VFS_RET_ENOTDIR (-32 - ENOTDIR) /* Not a directory */ #define VFS_RET_EIO VFS_ERROR(EIO) /* I/O error */
#define VFS_RET_EISDIR (-32 - EISDIR) /* Is a directory */ #define VFS_RET_EBADF VFS_ERROR(EBADF) /* Bad file number */
#define VFS_RET_EINVAL (-32 - EINVAL) /* Invalid argument */ #define VFS_RET_ENOMEM VFS_ERROR(ENOMEM) /* Not enough space */
#define VFS_RET_EMFILE (-32 - EMFILE) /* Too many open files in process */ #define VFS_RET_EACCES VFS_ERROR(EACCES) /* Permission denied */
#define VFS_RET_ENFILE (-32 - ENFILE) /* Too many open files in system */ #define VFS_RET_EEXIST VFS_ERROR(EEXIST) /* File exists */
#define VFS_RET_EFBIG (-32 - EFBIG) /* File too large */ #define VFS_RET_ENOTDIR VFS_ERROR(ENOTDIR) /* Not a directory */
#define VFS_RET_ENOSPC (-32 - ENOSPC) /* No space left on device */ #define VFS_RET_EISDIR VFS_ERROR(EISDIR) /* Is a directory */
#define VFS_RET_ESPIPE (-32 - ESPIPE) /* Illegal seek */ #define VFS_RET_EINVAL VFS_ERROR(EINVAL) /* Invalid argument */
#define VFS_RET_EROFS (-32 - EROFS) /* Read-only file system */ #define VFS_RET_EMFILE VFS_ERROR(EMFILE) /* Too many open files in process */
#define VFS_RET_ERANGE (-32 - ERANGE) /* Result too large */ #define VFS_RET_ENFILE VFS_ERROR(ENFILE) /* Too many open files in system */
#define VFS_RET_ENAMETOOLONG (-32 - ENAMETOOLONG)/* File or path name too long */ #define VFS_RET_EFBIG VFS_ERROR(EFBIG) /* File too large */
#define VFS_RET_ENOSPC VFS_ERROR(ENOSPC) /* No space left on device */
#define VFS_RET_ESPIPE VFS_ERROR(ESPIPE) /* Illegal seek */
#define VFS_RET_EROFS VFS_ERROR(EROFS) /* Read-only file system */
#define VFS_RET_ERANGE VFS_ERROR(ERANGE) /* Result too large */
#define VFS_RET_ENAMETOOLONG VFS_ERROR(ENAMETOOLONG)/* File or path name too long */
#define VFS_RET_ENOSYS VFS_ERROR(ENOSYS)
/** @} */ /** @} */
/*===========================================================================*/ /*===========================================================================*/
@ -78,7 +84,13 @@
/* Module macros. */ /* Module macros. */
/*===========================================================================*/ /*===========================================================================*/
#define VFS_IS_ERROR(err) ((msg_t)(err) < VFS_RET_SUCCESS) /**
* @name Errors handling macros
* @{
*/
#define VFS_ERRORS_MASK (msg_t)((msg_t)-1 & ~(msg_t)0xFF)
#define VFS_ERROR(posixerr) (VFS_ERRORS_MASK | (msg_t)(posixerr))
#define VFS_IS_ERROR(x) (((msg_t)(x) & VFS_ERRORS_MASK) == VFS_ERRORS_MASK)
#define VFS_BREAK_ON_ERROR(err) \ #define VFS_BREAK_ON_ERROR(err) \
if (VFS_IS_ERROR(err)) break if (VFS_IS_ERROR(err)) break
@ -89,6 +101,7 @@
return __ret; \ return __ret; \
} \ } \
} while (false) } while (false)
/** @} */
/*===========================================================================*/ /*===========================================================================*/
/* External declarations. */ /* External declarations. */