diff --git a/os/rt/src/chsem.c b/os/rt/src/chsem.c index d8ab711ef..4b6ed3c27 100644 --- a/os/rt/src/chsem.c +++ b/os/rt/src/chsem.c @@ -110,9 +110,10 @@ void chSemObjectInit(semaphore_t *sp, cnt_t n) { * performing checks that make sure that the object is in a * state compatible with operations stop. * @note If the option @p CH_CFG_ENABLE_HARDENING is enabled then the - * object is cleared, attempts to use the object would likely + * object is also cleared, attempts to use the object would likely * result in a clean memory access violation because dereferencing - * of @p NULL pointers. + * of @p NULL pointers rather than dereferencing previously valid + * pointers. * * @param[in] sp pointer to a @p semaphore_t structure * @@ -120,9 +121,7 @@ void chSemObjectInit(semaphore_t *sp, cnt_t n) { */ void chSemObjectDispose(semaphore_t *sp) { - chDbgAssert(chMemIsAreaWritableX((void *)sp, - sizeof (semaphore_t), - MEM_NATURAL_ALIGN), "pointer error"); + chDbgCheck(chMemIsAreaWritableX((void *)sp, sizeof (semaphore_t), MEM_NATURAL_ALIGN)); chDbgAssert(ch_queue_isempty(&sp->queue), "object in use"); #if 0 /*CH_CFG_ENABLE_HARDENING == TRUE*/ diff --git a/os/vfs/drivers/fatfs/drvfatfs.c b/os/vfs/drivers/fatfs/drvfatfs.c index dd47bef56..052564f54 100644 --- a/os/vfs/drivers/fatfs/drvfatfs.c +++ b/os/vfs/drivers/fatfs/drvfatfs.c @@ -120,28 +120,28 @@ static msg_t translate_error(FRESULT res) { msg = VFS_RET_TIMEOUT; break; case FR_NOT_ENOUGH_CORE: + msg = VFS_RET_ENOMEM; + break; case FR_TOO_MANY_OPEN_FILES: - msg = VFS_RET_NO_RESOURCE; + msg = VFS_RET_ENFILE; break; case FR_DISK_ERR: case FR_NOT_READY: case FR_INVALID_DRIVE: case FR_NO_FILESYSTEM: - msg = VFS_RET_MEDIA_ERROR; + msg = VFS_RET_EIO; break; case FR_NO_FILE: - msg = VFS_RET_NOT_FOUND; - break; case FR_NO_PATH: case FR_INVALID_NAME: - msg = VFS_RET_INVALID_PATH; + msg = VFS_RET_ENOENT; break; case FR_DENIED: case FR_WRITE_PROTECTED: - msg = VFS_RET_ACCESS_DENIED; + msg = VFS_RET_EACCES; break; case FR_EXIST: - msg = VFS_RET_EXIST; + msg = VFS_RET_EEXIST; break; default: msg = VFS_RET_INNER_ERROR; @@ -226,7 +226,7 @@ static msg_t drv_open_file(void *instance, mode = translate_oflag(oflag); if (mode == (BYTE)0) { - err = VFS_RET_INVALID_MODE; + err = VFS_RET_EINVAL; break; } @@ -499,7 +499,7 @@ msg_t drvFatFSMount(const char *name, bool mountnow) { if (fs == NULL) { fs = chPoolAlloc(&vfs_fatfs.fs_nodes_pool); if (fs == NULL) { - return VFS_RET_NO_RESOURCE; + return VFS_RET_ENOMEM; } } @@ -520,7 +520,7 @@ msg_t drvFatFSUnmount(const char *name) { fs = f_getfs(name); if (fs == NULL) { - return VFS_RET_MEDIA_ERROR; + return VFS_RET_EINVAL; } res = f_unmount(name); diff --git a/os/vfs/drivers/overlay/drvoverlay.c b/os/vfs/drivers/overlay/drvoverlay.c index 0586eb75e..78940b1b1 100644 --- a/os/vfs/drivers/overlay/drvoverlay.c +++ b/os/vfs/drivers/overlay/drvoverlay.c @@ -95,7 +95,7 @@ static msg_t match_driver(vfs_overlay_driver_t *odp, pp++; } - err = VFS_RET_NO_DRIVER; + err = VFS_RET_ENOENT; } while (false); @@ -180,7 +180,7 @@ static msg_t drv_open_file(void *instance, (void)instance; /* Always not found, there are no files in the root.*/ - err = VFS_RET_NOT_FOUND; + err = VFS_RET_ENOENT; } else { vfs_driver_t *dp; @@ -300,7 +300,7 @@ msg_t drvOverlayRegisterDriver(vfs_overlay_driver_t *vodp, msg_t err; if (vodp->next_driver >= DRV_CFG_OVERLAY_DRV_MAX) { - err = VFS_RET_NO_RESOURCE; + err = VFS_RET_ENOMEM; } else { vodp->drivers[vodp->next_driver++] = vdp; diff --git a/os/vfs/drivers/streams/drvstreams.c b/os/vfs/drivers/streams/drvstreams.c index bc7b3e6bc..857f4a8bd 100644 --- a/os/vfs/drivers/streams/drvstreams.c +++ b/os/vfs/drivers/streams/drvstreams.c @@ -119,7 +119,7 @@ static msg_t drv_open_dir(void *instance, return VFS_RET_SUCCESS; } - err = VFS_RET_NO_RESOURCE; + err = VFS_RET_ENOMEM; } while (false); @@ -166,13 +166,13 @@ static msg_t drv_open_file(void *instance, return VFS_RET_SUCCESS; } - return VFS_RET_NO_RESOURCE; + return VFS_RET_ENOMEM; } dsep++; } - err = VFS_RET_NOT_FOUND; + err = VFS_RET_ENOENT; } while (false); diff --git a/os/vfs/include/vfserrors.h b/os/vfs/include/vfserrors.h index b556511ec..36b8789a4 100644 --- a/os/vfs/include/vfserrors.h +++ b/os/vfs/include/vfserrors.h @@ -28,14 +28,17 @@ #ifndef VFSERRORS_H #define VFSERRORS_H +#include + /*===========================================================================*/ /* Module constants. */ /*===========================================================================*/ /** - * @name Error codes compatible with HAL streams + * @name Error codes compatible with HAL and Posix * @{ */ +#if 0 #define VFS_RET_SUCCESS 0 #define VFS_RET_TIMEOUT -1 #define VFS_RET_EOF -2 @@ -49,6 +52,26 @@ #define VFS_RET_MEDIA_ERROR -10 #define VFS_RET_INNER_ERROR -11 #define VFS_RET_INVALID_MODE -12 +#endif +#define VFS_RET_SUCCESS 0 /* Success */ +#define VFS_RET_TIMEOUT -1 /* Timeout */ +#define VFS_RET_EOF -2 /* End-of-file */ +#define VFS_RET_NOT_IMPLEMENTED -3 /* Not implemented functionality */ +#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 */ +#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_ENOTDIR (-32 - ENOTDIR) /* Not a directory */ +#define VFS_RET_EISDIR (-32 - EISDIR) /* Is a directory */ +#define VFS_RET_EINVAL (-32 - EINVAL) /* Invalid argument */ +#define VFS_RET_ENFILE (-32 - ENFILE) /* Too many open files in system */ +#define VFS_RET_EFBIG (-32 - EFBIG) /* File too large */ +#define VFS_RET_ENOSPC (-32 - ENOSPC) /* No space left on device */ +#define VFS_RET_ESPIPE (-32 - ESPIPE) /* Illegal seek */ +#define VFS_RET_EROFS (-32 - EROFS) /* Read-only file system */ /** @} */ /*===========================================================================*/ diff --git a/os/vfs/src/vfsparser.c b/os/vfs/src/vfsparser.c index 629209ff5..0e164dcd1 100644 --- a/os/vfs/src/vfsparser.c +++ b/os/vfs/src/vfsparser.c @@ -64,7 +64,7 @@ msg_t vfs_parse_match_separator(const char **pathp) { const char *p = *pathp; if (*p++ != '/') { - err = VFS_RET_INVALID_PATH; + err = VFS_RET_ENOENT; } else { err = VFS_RET_SUCCESS; @@ -83,7 +83,7 @@ msg_t vfs_parse_match_end(const char **pathp) { msg_t err; if (**pathp != '\0') { - err = VFS_RET_INVALID_PATH; + err = VFS_RET_ENOENT; } else { err = VFS_RET_SUCCESS; @@ -113,7 +113,7 @@ msg_t vfs_parse_filename(const char **pathp, char *fname) { /* Consecutive separators are not valid.*/ if (n == 0U) { - return VFS_RET_INVALID_PATH; + return VFS_RET_ENOENT; } /* Advancing the path pointer past the file name in the path and @@ -125,11 +125,11 @@ msg_t vfs_parse_filename(const char **pathp, char *fname) { /* Valid characters for path names.*/ if (!isalnum(c) && (c != '_') && (c != '-') && (c != '.')) { - return VFS_RET_INVALID_PATH; + return VFS_RET_ENOENT; } if (n > VFS_CFG_MAX_NAMELEN) { - return VFS_RET_INVALID_PATH; + return VFS_RET_ENOENT; } *fname++ = c;