Created an unified errors header.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15273 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
Giovanni Di Sirio 2021-12-28 13:09:43 +00:00
parent 5a0129b5ac
commit 4b9b255235
18 changed files with 165 additions and 151 deletions

View File

@ -98,6 +98,8 @@ DEPDIR := ./.dep
include $(CHIBIOS)/os/license/license.mk
# Startup files.
include $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32g4xx.mk
# Common files.
include $(CHIBIOS)/os/common/utils/utils.mk
# HAL-OSAL files (optional).
include $(CHIBIOS)/os/hal/hal.mk
include $(CHIBIOS)/os/hal/ports/STM32/STM32G4xx/platform.mk
@ -107,6 +109,9 @@ include $(CHIBIOS)/os/hal/osal/rt-nil/osal.mk
include $(CHIBIOS)/os/rt/rt.mk
include $(CHIBIOS)/os/common/ports/ARMv7-M-ALT/compilers/GCC/mk/port.mk
include $(CHIBIOS)/os/sb/host/compilers/GCC/sbhost.mk
# VFS files (optional).
include $(CHIBIOS)/os/vfs/vfs.mk
#include $(CHIBIOS)/os/vfs/vfs_syscalls.mk
# Auto-build files in ./source recursively.
include $(CHIBIOS)/tools/mk/autobuild.mk
# Other files (optional).

View File

@ -45,6 +45,13 @@
#define SB_CFG_ENABLE_VFS TRUE
#endif
/**
* @brief Number of file descriptors for each sandbox.
*/
#if !defined(SB_CFG_FD_NUM) || defined(__DOXYGEN__)
#define SB_CFG_FD_NUM 12
#endif
#endif /* SBCONF_H */
/** @} */

View File

@ -177,7 +177,7 @@ static void InsertHandler(eventid_t id) {
#endif
err = drvFatFSMount("0:", 1);
if (err != VFS_RET_SUCCESS) {
if (CH_IS_ERROR(err)) {
#if HAL_USE_SDC
sdcDisconnect(&PORTAB_SDCD1);
#else
@ -288,13 +288,13 @@ int main(void) {
msg = drvOverlayRegisterDriver(&root_overlay_driver,
drvStreamsObjectInit(&dev_driver, &streams[0]),
"dev");
if (VFS_IS_ERROR(msg)) {
if (CH_IS_ERROR(msg)) {
chSysHalt("VFS");
}
/* Opening a file for shell I/O.*/
msg = vfsOpenFile("/dev/VSD1", VO_RDWR, &file);
if (VFS_IS_ERROR(msg)) {
if (CH_IS_ERROR(msg)) {
chSysHalt("VFS");
}
shell_cfg1.sc_channel = vfsGetFileStream(file);

View File

@ -18,15 +18,15 @@
*/
/**
* @file vfs/include/vfserrors.h
* @brief VFS erors header file.
* @file errcodes.h
* @brief Errors handling header file.
*
* @addtogroup VFS_ERRORS
* @addtogroup UTILS_ERRCODES
* @{
*/
#ifndef VFSERRORS_H
#define VFSERRORS_H
#ifndef ERRCODES_H
#define ERRCODES_H
#include <errno.h>
@ -35,37 +35,36 @@
/*===========================================================================*/
/**
* @name VFS error codes
* @name Error codes
* @{
*/
#define VFS_RET_SUCCESS (msg_t)MSG_OK /* Success */
#define VFS_RET_TIMEOUT (msg_t)MSG_TIMEOUT /* Timeout */
#define VFS_RET_EOF (msg_t)-3 /* End-of-file */
#define VFS_RET_INNER_ERROR (msg_t)-4 /* Unexpected condition */
#define CH_RET_SUCCESS (msg_t)MSG_OK /* Success */
#define CH_RET_TIMEOUT (msg_t)MSG_TIMEOUT /* Timeout */
#define CH_RET_INNER_ERROR (msg_t)-3 /* Unexpected condition */
/** @} */
/**
* @name Error codes compatible with Posix
* @name Extra error codes mapped on Posix errors
* @{
*/
#define VFS_RET_ENOENT VFS_ERROR(ENOENT) /* No such file or directory */
#define VFS_RET_EIO VFS_ERROR(EIO) /* I/O error */
#define VFS_RET_EBADF VFS_ERROR(EBADF) /* Bad file number */
#define VFS_RET_ENOMEM VFS_ERROR(ENOMEM) /* Not enough space */
#define VFS_RET_EACCES VFS_ERROR(EACCES) /* Permission denied */
#define VFS_RET_EEXIST VFS_ERROR(EEXIST) /* File exists */
#define VFS_RET_ENOTDIR VFS_ERROR(ENOTDIR) /* Not a directory */
#define VFS_RET_EISDIR VFS_ERROR(EISDIR) /* Is a directory */
#define VFS_RET_EINVAL VFS_ERROR(EINVAL) /* Invalid argument */
#define VFS_RET_EMFILE VFS_ERROR(EMFILE) /* Too many open files in process */
#define VFS_RET_ENFILE VFS_ERROR(ENFILE) /* Too many open files in system */
#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)
#define CH_RET_ENOENT CH_ENCODE_ERROR(ENOENT) /* No such file or directory */
#define CH_RET_EIO CH_ENCODE_ERROR(EIO) /* I/O error */
#define CH_RET_EBADF CH_ENCODE_ERROR(EBADF) /* Bad file number */
#define CH_RET_ENOMEM CH_ENCODE_ERROR(ENOMEM) /* Not enough space */
#define CH_RET_EACCES CH_ENCODE_ERROR(EACCES) /* Permission denied */
#define CH_RET_EEXIST CH_ENCODE_ERROR(EEXIST) /* File exists */
#define CH_RET_ENOTDIR CH_ENCODE_ERROR(ENOTDIR) /* Not a directory */
#define CH_RET_EISDIR CH_ENCODE_ERROR(EISDIR) /* Is a directory */
#define CH_RET_EINVAL CH_ENCODE_ERROR(EINVAL) /* Invalid argument */
#define CH_RET_EMFILE CH_ENCODE_ERROR(EMFILE) /* Too many open files in process */
#define CH_RET_ENFILE CH_ENCODE_ERROR(ENFILE) /* Too many open files in system */
#define CH_RET_EFBIG CH_ENCODE_ERROR(EFBIG) /* File too large */
#define CH_RET_ENOSPC CH_ENCODE_ERROR(ENOSPC) /* No space left on device */
#define CH_RET_ESPIPE CH_ENCODE_ERROR(ESPIPE) /* Illegal seek */
#define CH_RET_EROFS CH_ENCODE_ERROR(EROFS) /* Read-only file system */
#define CH_RET_ERANGE CH_ENCODE_ERROR(ERANGE) /* Result too large */
#define CH_RET_ENAMETOOLONG CH_ENCODE_ERROR(ENAMETOOLONG)/* File or path name too long */
#define CH_RET_ENOSYS CH_ENCODE_ERROR(ENOSYS) /* Syscall not implemented */
/** @} */
/*===========================================================================*/
@ -88,16 +87,17 @@
* @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 CH_ERRORS_MASK (msg_t)0xFF
#define CH_ENCODE_ERROR(posixerr) (~CH_ERRORS_MASK | (msg_t)(posixerr))
#define CH_DECODE_ERROR(err) ((msg_t)(err) & CH_ERRORS_MASK)
#define CH_IS_ERROR(x) (((msg_t)(x) & ~CH_ERRORS_MASK) == ~CH_ERRORS_MASK)
#define VFS_BREAK_ON_ERROR(err) \
if (VFS_IS_ERROR(err)) break
#define CH_BREAK_ON_ERROR(err) \
if (CH_IS_ERROR(err)) break
#define VFS_RETURN_ON_ERROR(err) do { \
#define CH_RETURN_ON_ERROR(err) do { \
msg_t __ret = (err); \
if (VFS_IS_ERROR(__ret)) { \
if (CH_IS_ERROR(__ret)) { \
return __ret; \
} \
} while (false)
@ -119,6 +119,6 @@ extern "C" {
/* Module inline functions. */
/*===========================================================================*/
#endif /* VFSERRORS_H */
#endif /* ERRCODES_H */
/** @} */

View File

@ -1,7 +1,7 @@
# List of the ChibiOS OOP module.
UTILSSRC =
UTILSINC = ${CHIBIOS}/os/common/utils/oop/include
UTILSINC = ${CHIBIOS}/os/common/utils/include
# Shared variables
ALLCSRC += $(UTILSSRC)

View File

@ -240,13 +240,13 @@ static void scan_nodes(BaseSequentialStream *chp,
chprintf(chp, "%s" SHELL_NEWLINE_STR, path);
res = vfsOpenDirectory(path, &dirp);
if (res == VFS_RET_SUCCESS) {
if (res == CH_RET_SUCCESS) {
size_t i = strlen(path);
while (true) {
char *fn = dip->name;
res = vfsReadDirectoryNext(dirp, dip);
if (res != VFS_RET_SUCCESS) {
if (res < (msg_t)1) {
break;
}
@ -347,7 +347,7 @@ static void cmd_cd(BaseSequentialStream *chp, int argc, char *argv[]) {
msg_t res;
res = vfsChangeCurrentDirectory(argv[0]);
if (VFS_IS_ERROR(res)) {
if (CH_IS_ERROR(res)) {
chprintf(chp, "failed (%d)" SHELL_NEWLINE_STR, res);
}
}
@ -374,9 +374,9 @@ static void cmd_ls(BaseSequentialStream *chp, int argc, char *argv[]) {
/* Opening the (un)specified directory.*/
res = vfsOpenDirectory(argc == 1 ? argv[0] : ".", &dirp);
if (!VFS_IS_ERROR(res)) {
if (!CH_IS_ERROR(res)) {
while (!VFS_IS_ERROR(vfsReadDirectoryNext(dirp, dip))) {
while (vfsReadDirectoryNext(dirp, dip) > (msg_t)0) {
chprintf(chp, "%s" SHELL_NEWLINE_STR, dip->name);
}
@ -413,7 +413,7 @@ static void cmd_pwd(BaseSequentialStream *chp, int argc, char *argv[]) {
}
res = vfsGetCurrentDirectory(buf, VFS_CFG_PATHLEN_MAX + 1);
if (VFS_IS_ERROR(res)) {
if (CH_IS_ERROR(res)) {
chprintf(chp, "Failed (%d)" SHELL_NEWLINE_STR, res);
}
else {

View File

@ -142,39 +142,39 @@ static msg_t translate_error(FRESULT res) {
switch (res) {
case FR_OK:
msg = VFS_RET_SUCCESS;
msg = CH_RET_SUCCESS;
break;
case FR_TIMEOUT:
msg = VFS_RET_TIMEOUT;
msg = CH_RET_TIMEOUT;
break;
case FR_NOT_ENOUGH_CORE:
msg = VFS_RET_ENOMEM;
msg = CH_RET_ENOMEM;
break;
case FR_TOO_MANY_OPEN_FILES:
msg = VFS_RET_ENFILE;
msg = CH_RET_ENFILE;
break;
case FR_DISK_ERR:
case FR_NOT_READY:
case FR_INVALID_DRIVE:
case FR_NO_FILESYSTEM:
msg = VFS_RET_EIO;
msg = CH_RET_EIO;
break;
case FR_NO_FILE:
case FR_NO_PATH:
msg = VFS_RET_ENOENT;
msg = CH_RET_ENOENT;
break;
case FR_INVALID_NAME:
msg = VFS_RET_ENAMETOOLONG;
msg = CH_RET_ENAMETOOLONG;
break;
case FR_DENIED:
case FR_WRITE_PROTECTED:
msg = VFS_RET_EACCES;
msg = CH_RET_EACCES;
break;
case FR_EXIST:
msg = VFS_RET_EEXIST;
msg = CH_RET_EEXIST;
break;
default:
msg = VFS_RET_INNER_ERROR;
msg = CH_RET_INNER_ERROR;
break;
}
@ -218,10 +218,10 @@ static msg_t drv_set_cwd(void *instance, const char *path) {
(void)instance;
if (strcmp(path, "/") != 0) {
return VFS_RET_ENOENT;
return CH_RET_ENOENT;
}
return VFS_RET_SUCCESS;
return CH_RET_SUCCESS;
#endif
}
@ -236,13 +236,13 @@ static msg_t drv_get_cwd(void *instance, char *buf, size_t size) {
(void)instance;
if (size < 2) {
return VFS_RET_ERANGE;
return CH_RET_ERANGE;
}
buf[0] = '/';
buf[1] = '\0';
return VFS_RET_SUCCESS;
return CH_RET_SUCCESS;
#endif
}
@ -266,7 +266,7 @@ static msg_t drv_open_dir(void *instance,
res = f_opendir(&ffdnp->dir, (TCHAR *)path);
if (res == FR_OK) {
*vdnpp = (vfs_directory_node_c *)ffdnp;
err = VFS_RET_SUCCESS;
err = CH_RET_SUCCESS;
break;
}
@ -294,7 +294,7 @@ static msg_t drv_open_file(void *instance,
mode = translate_oflag(flags);
if (mode == (BYTE)0) {
err = VFS_RET_EINVAL;
err = CH_RET_EINVAL;
break;
}
@ -309,7 +309,7 @@ static msg_t drv_open_file(void *instance,
res = f_open(&fffnp->file, (TCHAR *)path, mode);
if (res == FR_OK) {
*vfnpp = (vfs_file_node_c *)fffnp;
err = VFS_RET_SUCCESS;
err = CH_RET_SUCCESS;
break;
}
@ -363,14 +363,14 @@ static msg_t node_dir_next(void *instance, vfs_direntry_info_t *dip) {
res = f_readdir(&ffdnp->dir, fip);
if (res == FR_OK) {
if (fip->fname[0] == '\0') {
err = VFS_RET_EOF;
err = (msg_t)0;
}
else {
dip->attr = (vfs_nodeattr_t)fip->fattrib;
dip->size = (vfs_offset_t)fip->fsize;
strncpy(dip->name, fip->fname, VFS_CFG_NAMELEN_MAX);
dip->name[VFS_CFG_NAMELEN_MAX] = '\0';
err = VFS_RET_SUCCESS;
err = (msg_t)1;
}
}
else {
@ -447,7 +447,7 @@ static msg_t node_file_getstat(void *instance, vfs_file_stat_t *fsp) {
fsp->attr = (vfs_nodeattr_t)fffnp->file.obj.attr;
fsp->size = (vfs_offset_t)fffnp->file.obj.objsize;
return VFS_RET_SUCCESS;
return CH_RET_SUCCESS;
}
static size_t file_stream_write(void *instance, const uint8_t *bp, size_t n) {
@ -456,7 +456,7 @@ static size_t file_stream_write(void *instance, const uint8_t *bp, size_t n) {
msg_t msg;
msg = fffnp->vmt->file_write((void *)fffnp, bp, n);
if (msg < VFS_RET_SUCCESS) {
if (msg < CH_RET_SUCCESS) {
return (size_t)0;
}
@ -470,7 +470,7 @@ static size_t file_stream_read(void *instance, uint8_t *bp, size_t n) {
msg_t msg;
msg = fffnp->vmt->file_read((void *)fffnp, bp, n);
if (msg < VFS_RET_SUCCESS) {
if (msg < CH_RET_SUCCESS) {
return (size_t)0;
}
@ -484,7 +484,7 @@ static msg_t file_stream_put(void *instance, uint8_t b) {
msg_t msg;
msg = fffnp->vmt->file_write((void *)fffnp, &b, (size_t)1);
if (msg < VFS_RET_SUCCESS) {
if (msg < CH_RET_SUCCESS) {
return STM_TIMEOUT;
}
@ -499,7 +499,7 @@ static msg_t file_stream_get(void *instance) {
uint8_t b;
msg = fffnp->vmt->file_read((void *)fffnp, &b, (size_t)1);
if (msg < VFS_RET_SUCCESS) {
if (msg < CH_RET_SUCCESS) {
return STM_TIMEOUT;
}
@ -574,7 +574,7 @@ msg_t drvFatFSMount(const char *name, bool mountnow) {
if (fs == NULL) {
fs = chPoolAlloc(&vfs_fatfs_driver_static.fs_nodes_pool);
if (fs == NULL) {
return VFS_RET_ENOMEM;
return CH_RET_ENOMEM;
}
}
@ -595,7 +595,7 @@ msg_t drvFatFSUnmount(const char *name) {
fs = f_getfs(name);
if (fs == NULL) {
return VFS_RET_EINVAL;
return CH_RET_EINVAL;
}
res = f_unmount(name);

View File

@ -100,20 +100,20 @@ static msg_t match_driver(vfs_overlay_driver_c *odp,
unsigned i;
err = vfs_parse_get_fname(pathp, fname, VFS_CFG_PATHLEN_MAX);
VFS_BREAK_ON_ERROR(err);
CH_BREAK_ON_ERROR(err);
/* Searching among registered drivers.*/
i = 0U;
while (i < odp->next_driver) {
if (strncmp(fname, odp->names[i], VFS_CFG_NAMELEN_MAX) == 0) {
*vdpp = odp->drivers[i];
return VFS_RET_SUCCESS;
return CH_RET_SUCCESS;
}
i++;
}
err = VFS_RET_ENOENT;
err = CH_RET_ENOENT;
}
while (false);
@ -146,12 +146,12 @@ static msg_t build_absolute_path(vfs_overlay_driver_c *drvp,
ret = vfs_path_append(buf,
get_current_directory(drvp),
VFS_CFG_PATHLEN_MAX);
VFS_BREAK_ON_ERROR(ret);
CH_BREAK_ON_ERROR(ret);
}
/* Adding the specified path.*/
ret = vfs_path_append(buf, path, VFS_CFG_PATHLEN_MAX);
VFS_BREAK_ON_ERROR(ret);
CH_BREAK_ON_ERROR(ret);
/* Normalization of the absolute path.*/
ret = vfs_path_normalize(buf, buf, VFS_CFG_PATHLEN_MAX);
@ -171,7 +171,7 @@ static msg_t open_absolute_dir(vfs_overlay_driver_c *drvp,
/* Making sure there is a final separator.*/
err = vfs_path_add_separator(path, VFS_CFG_PATHLEN_MAX + 1);
VFS_BREAK_ON_ERROR(err);
CH_BREAK_ON_ERROR(err);
/* Initial separator is expected, skipping it.*/
scanpath = path + 1;
@ -199,7 +199,7 @@ static msg_t open_absolute_dir(vfs_overlay_driver_c *drvp,
}
*vdnpp = (vfs_directory_node_c *)odnp;
err = VFS_RET_SUCCESS;
err = CH_RET_SUCCESS;
break;
}
}
@ -208,7 +208,7 @@ static msg_t open_absolute_dir(vfs_overlay_driver_c *drvp,
/* Searching for a match among registered overlays.*/
err = match_driver(drvp, &scanpath, &dp);
if (!VFS_IS_ERROR(err)) {
if (!CH_IS_ERROR(err)) {
/* Delegating node creation to a registered driver.*/
err = dp->vmt->open_dir((void *)dp,
scanpath,
@ -226,7 +226,7 @@ static msg_t open_absolute_dir(vfs_overlay_driver_c *drvp,
err = vfs_path_prepend(path,
drvp->path_prefix,
VFS_CFG_PATHLEN_MAX + 1);
VFS_BREAK_ON_ERROR(err);
CH_BREAK_ON_ERROR(err);
path_offset = (size_t)err;
}
else {
@ -237,7 +237,7 @@ static msg_t open_absolute_dir(vfs_overlay_driver_c *drvp,
err = drvp->overlaid_drv->vmt->open_dir((void *)drvp->overlaid_drv,
path,
vdnpp);
VFS_BREAK_ON_ERROR(err);
CH_BREAK_ON_ERROR(err);
err = (msg_t)path_offset;
}
@ -265,14 +265,14 @@ static msg_t open_absolute_file(vfs_overlay_driver_c *drvp,
if (*scanpath == '\0') {
/* Always not found, root is not a file.*/
err = VFS_RET_ENOENT;
err = CH_RET_ENOENT;
}
else {
vfs_driver_c *dp;
/* Searching for a match among registered overlays.*/
err = match_driver(drvp, &scanpath, &dp);
if (!VFS_IS_ERROR(err)) {
if (!CH_IS_ERROR(err)) {
/* Delegating node creation to a registered driver.*/
err = dp->vmt->open_file((void *)dp, scanpath, oflag, vfnpp);
}
@ -286,7 +286,7 @@ static msg_t open_absolute_file(vfs_overlay_driver_c *drvp,
err = vfs_path_prepend(path,
drvp->path_prefix,
VFS_CFG_PATHLEN_MAX + 1);
VFS_BREAK_ON_ERROR(err);
CH_BREAK_ON_ERROR(err);
}
/* Passing the combined path to the overlaid driver.*/
@ -316,12 +316,12 @@ static msg_t drv_set_cwd(void *instance, const char *path) {
buf = vfs_buffer_take();
ret = build_absolute_path(drvp, buf, path);
VFS_BREAK_ON_ERROR(ret);
CH_BREAK_ON_ERROR(ret);
/* Trying to access the directory in order to validate the
combined path. Note, it can modify the path in the buffer.*/
ret = open_absolute_dir(drvp, buf, &vdnp);
VFS_BREAK_ON_ERROR(ret);
CH_BREAK_ON_ERROR(ret);
vdnp->vmt->release((void *)vdnp);
path_offset = (size_t)ret;
@ -330,7 +330,7 @@ static msg_t drv_set_cwd(void *instance, const char *path) {
if (drvp->path_cwd == NULL) {
drvp->path_cwd = chCoreAlloc(VFS_CFG_PATHLEN_MAX + 1);
if (drvp->path_cwd == NULL) {
ret = VFS_RET_ENOMEM;
ret = CH_RET_ENOMEM;
break;
}
}
@ -367,13 +367,13 @@ static msg_t drv_open_dir(void *instance,
/* Building the absolute path based on current directory.*/
err = build_absolute_path(drvp, buf, path);
VFS_BREAK_ON_ERROR(err);
CH_BREAK_ON_ERROR(err);
err = open_absolute_dir(drvp, buf, vdnpp);
VFS_BREAK_ON_ERROR(err);
CH_BREAK_ON_ERROR(err);
/* Required because the offset returned by open_absolute_dir().*/
err = VFS_RET_SUCCESS;
err = CH_RET_SUCCESS;
} while (false);
/* Buffer returned.*/
@ -397,7 +397,7 @@ static msg_t drv_open_file(void *instance,
/* Building the absolute path based on current directory.*/
err = build_absolute_path(drvp, buf, path);
VFS_BREAK_ON_ERROR(err);
CH_BREAK_ON_ERROR(err);
err = open_absolute_file(drvp, buf, flags, vfnpp);
} while (false);
@ -441,7 +441,7 @@ static msg_t node_dir_next(void *instance, vfs_direntry_info_t *dip) {
odnp->index++;
return VFS_RET_SUCCESS;
return (msg_t)1;
}
if (odnp->overlaid_root != NULL) {
if (odnp->index == drvp->next_driver) {
@ -458,7 +458,7 @@ static msg_t node_dir_next(void *instance, vfs_direntry_info_t *dip) {
}
}
return VFS_RET_EOF;
return (msg_t)0;
}
/*===========================================================================*/
@ -524,13 +524,13 @@ msg_t drvOverlayRegisterDriver(vfs_overlay_driver_c *vodp,
msg_t err;
if (vodp->next_driver >= DRV_CFG_OVERLAY_DRV_MAX) {
err = VFS_RET_ENOMEM;
err = CH_RET_ENOMEM;
}
else {
vodp->names[vodp->next_driver] = name;
vodp->drivers[vodp->next_driver] = vdp;
vodp->next_driver++;
err = VFS_RET_SUCCESS;
err = CH_RET_SUCCESS;
}
return err;

View File

@ -121,10 +121,10 @@ static msg_t drv_set_cwd(void *instance, const char *path) {
(void)instance;
if (strcmp(path, "/") != 0) {
return VFS_RET_ENOENT;
return CH_RET_ENOENT;
}
return VFS_RET_SUCCESS;
return CH_RET_SUCCESS;
}
static msg_t drv_get_cwd(void *instance, char *buf, size_t size) {
@ -132,13 +132,13 @@ static msg_t drv_get_cwd(void *instance, char *buf, size_t size) {
(void)instance;
if (size < 2) {
return VFS_RET_ERANGE;
return CH_RET_ERANGE;
}
buf[0] = '/';
buf[1] = '\0';
return VFS_RET_SUCCESS;
return CH_RET_SUCCESS;
}
static msg_t drv_open_dir(void *instance,
@ -151,10 +151,10 @@ static msg_t drv_open_dir(void *instance,
vfs_streams_dir_node_c *sdnp;
err = vfs_parse_match_separator(&path);
VFS_BREAK_ON_ERROR(err);
CH_BREAK_ON_ERROR(err);
err = vfs_parse_match_end(&path);
VFS_BREAK_ON_ERROR(err);
CH_BREAK_ON_ERROR(err);
sdnp = chPoolAlloc(&vfs_streams_driver_static.dir_nodes_pool);
if (sdnp != NULL) {
@ -165,10 +165,10 @@ static msg_t drv_open_dir(void *instance,
sdnp->index = 0U;
*vdnpp = (vfs_directory_node_c *)sdnp;
return VFS_RET_SUCCESS;
return CH_RET_SUCCESS;
}
err = VFS_RET_ENOMEM;
err = CH_RET_ENOMEM;
}
while (false);
@ -189,13 +189,13 @@ static msg_t drv_open_file(void *instance,
char fname[VFS_CFG_NAMELEN_MAX + 1];
err = vfs_parse_match_separator(&path);
VFS_BREAK_ON_ERROR(err);
CH_BREAK_ON_ERROR(err);
err = vfs_parse_get_fname(&path, fname, VFS_CFG_PATHLEN_MAX);
VFS_BREAK_ON_ERROR(err);
CH_BREAK_ON_ERROR(err);
err = vfs_parse_match_end(&path);
VFS_BREAK_ON_ERROR(err);
CH_BREAK_ON_ERROR(err);
dsep = &drvp->streams[0];
while (dsep->name != NULL) {
@ -211,16 +211,16 @@ static msg_t drv_open_file(void *instance,
sfnp->stream = dsep->stream;
*vfnpp = (vfs_file_node_c *)sfnp;
return VFS_RET_SUCCESS;
return CH_RET_SUCCESS;
}
return VFS_RET_ENOMEM;
return CH_RET_ENOMEM;
}
dsep++;
}
err = VFS_RET_ENOENT;
err = CH_RET_ENOENT;
}
while (false);
@ -257,10 +257,10 @@ static msg_t node_dir_next(void *instance, vfs_direntry_info_t *dip) {
sdnp->index++;
return VFS_RET_SUCCESS;
return (msg_t)1;
}
return VFS_RET_EOF;
return (msg_t)0;
}
static void node_file_release(void *instance) {
@ -296,7 +296,7 @@ static msg_t node_file_setpos(void *instance, vfs_offset_t offset) {
(void)instance;
(void)offset;
return VFS_RET_ENOSYS;
return CH_RET_ENOSYS;
}
static vfs_offset_t node_file_getpos(void *instance) {
@ -311,7 +311,7 @@ static msg_t node_file_getstat(void *instance, vfs_file_stat_t *fsp) {
(void)instance;
(void)fsp;
return VFS_RET_ENOSYS;
return CH_RET_ENOSYS;
}
/*===========================================================================*/

View File

@ -70,6 +70,7 @@
/* Dependencies.*/
#include "ch.h"
#include "errcodes.h"
#include "oop_base_object.h"
#include "oop_referenced_object.h"
#include "oop_synchronized_object.h"
@ -84,7 +85,6 @@
#include "vfschecks.h"
/* Base VFS headers.*/
#include "vfserrors.h"
#include "vfsparser.h"
#include "vfspaths.h"
#include "vfsbuffers.h"

View File

@ -136,6 +136,8 @@ void vfsCloseDirectory(vfs_directory_node_c *vdnp) {
* @param[in] vdnp Pointer to the @p vfs_directory_node_c object.
* @param[out] dip Pointer to a @p vfs_direntry_info_t structure.
* @return The operation result.
* @retval 0 Zero entries read, end-of-directory condition.
* @retval 1 One directory entry read.
*
* @api
*/
@ -153,6 +155,8 @@ msg_t vfsReadDirectoryFirst(vfs_directory_node_c *vdnp,
* @param[in] vdnp Pointer to the @p vfs_directory_node_c object..
* @param[out] dip Pointer to a @p vfs_direntry_info_t structure
* @return The operation result.
* @retval 0 Zero entries read, end-of-directory condition.
* @retval 1 One directory entry read.
*
* @api
*/

View File

@ -61,10 +61,10 @@ msg_t vfs_parse_match_separator(const char **pathp) {
const char *p = *pathp;
if (!vfs_parse_is_separator(*p++)) {
err = VFS_RET_ENOENT;
err = CH_RET_ENOENT;
}
else {
err = VFS_RET_SUCCESS;
err = CH_RET_SUCCESS;
*pathp = p;
}
@ -80,10 +80,10 @@ msg_t vfs_parse_match_end(const char **pathp) {
msg_t err;
if (**pathp != '\0') {
err = VFS_RET_ENOENT;
err = CH_RET_ENOENT;
}
else {
err = VFS_RET_SUCCESS;
err = CH_RET_SUCCESS;
}
return err;
@ -119,12 +119,12 @@ msg_t vfs_parse_copy_fname(const char **pathp, char *fname, size_t n) {
/* Valid characters for path names.*/
if (!vfs_parse_is_filechar(c)) {
return VFS_RET_EINVAL;
return CH_RET_EINVAL;
}
/* Exceeding the maximum length.*/
if (size > n) {
return VFS_RET_ENAMETOOLONG;
return CH_RET_ENAMETOOLONG;
}
*fname++ = c;
@ -146,7 +146,7 @@ msg_t vfs_parse_get_fname(const char **pathp, char *fname, size_t n) {
msg_t ret;
ret = vfs_parse_copy_fname(pathp, fname, n);
VFS_RETURN_ON_ERROR(ret);
CH_RETURN_ON_ERROR(ret);
fname[ret] = '\0';

View File

@ -58,7 +58,7 @@
* @param[in] src The source path.
* @param[in[ size Destination buffer size.
* @return The operation status.
* @retval VFS_RET_ERANGE If the path size exceeded the buffer size.
* @retval CH_RET_ERANGE If the path size exceeded the buffer size.
*/
msg_t vfs_path_append(char *dst, const char *src, size_t size) {
size_t n;
@ -66,7 +66,7 @@ msg_t vfs_path_append(char *dst, const char *src, size_t size) {
/* Current path length.*/
n = strnlen(dst, size);
if (n >= size) {
return VFS_RET_ERANGE;
return CH_RET_ERANGE;
}
/* Making sure to start with a separator in place.*/
@ -92,13 +92,13 @@ msg_t vfs_path_append(char *dst, const char *src, size_t size) {
n++;
if (n > size) {
return VFS_RET_ERANGE;
return CH_RET_ERANGE;
}
}
*dst = '\0';
return VFS_RET_SUCCESS;
return CH_RET_SUCCESS;
}
/**
@ -108,7 +108,7 @@ msg_t vfs_path_append(char *dst, const char *src, size_t size) {
* @param[in] src The source path.
* @param[in[ size Destination buffer size.
* @return The operation status.
* @retval VFS_RET_ERANGE If the path size exceeded the buffer size.
* @retval CH_RET_ERANGE If the path size exceeded the buffer size.
*/
msg_t vfs_path_prepend(char *dst, const char *src, size_t size) {
size_t dn, sn;
@ -117,7 +117,7 @@ msg_t vfs_path_prepend(char *dst, const char *src, size_t size) {
sn = strnlen(src, size - 1U);
if (dn + sn >= size) {
return VFS_RET_ERANGE;
return CH_RET_ERANGE;
}
/* Making space for the prefix, including the final zero in the move.*/
@ -135,7 +135,7 @@ msg_t vfs_path_prepend(char *dst, const char *src, size_t size) {
* @param[in] dst The destination path.
* @param[in[ size Destination buffer size.
* @return The operation status.
* @retval VFS_RET_ERANGE If the path size exceeded the buffer size.
* @retval CH_RET_ERANGE If the path size exceeded the buffer size.
*/
msg_t vfs_path_add_separator(char *dst, size_t size) {
size_t dn;
@ -149,7 +149,7 @@ msg_t vfs_path_add_separator(char *dst, size_t size) {
else {
if (!vfs_parse_is_separator(dst[dn - 1])) {
if (dn >= size - 1) {
return VFS_RET_ERANGE;
return CH_RET_ERANGE;
}
dst[dn] = '/';
@ -168,12 +168,12 @@ msg_t vfs_path_add_separator(char *dst, size_t size) {
* @param[in] src The source path.
* @param[in[ size Destination buffer size.
* @return The operation status.
* @retval VFS_RET_ERANGE If the path size exceeded the buffer size.
* @retval CH_RET_ERANGE If the path size exceeded the buffer size.
*/
msg_t vfs_path_normalize(char *dst, const char *src, size_t size) {
size_t n;
VFS_RETURN_ON_ERROR(vfs_parse_match_separator(&src));
CH_RETURN_ON_ERROR(vfs_parse_match_separator(&src));
*dst++ = '/';
n = 1U;
@ -188,7 +188,7 @@ msg_t vfs_path_normalize(char *dst, const char *src, size_t size) {
/* Getting next element from the input path and copying it to
the output path.*/
ret = vfs_parse_copy_fname(&src, dst, size - n);
VFS_RETURN_ON_ERROR(ret);
CH_RETURN_ON_ERROR(ret);
if ((size_t)ret == 0U) {

View File

@ -28,13 +28,6 @@
static vfs_file_node_c *fds[SYSCALL_MAX_FDS];
static int translate_error(msg_t err) {
err = -err - 32;
return (int)err;
}
/***************************************************************************/
__attribute__((used))
@ -46,8 +39,8 @@ int _open_r(struct _reent *r, const char *p, int oflag, int mode) {
(void)mode;
err = vfsOpenFile(p, oflag, &vfnp);
if (err < VFS_RET_SUCCESS) {
__errno_r(r) = translate_error(err);
if (err < CH_RET_SUCCESS) {
__errno_r(r) = CH_DECODE_ERROR(err);
return -1;
}
@ -61,7 +54,7 @@ int _open_r(struct _reent *r, const char *p, int oflag, int mode) {
vfsCloseFile(vfnp);
__errno_r(r) = translate_error(VFS_RET_EMFILE);
__errno_r(r) = EMFILE;
return -1;
}
@ -71,7 +64,7 @@ __attribute__((used))
int _close_r(struct _reent *r, int file) {
if ((file < 0) || (file >= SYSCALL_MAX_FDS) || (fds[file] == NULL)) {
__errno_r(r) = translate_error(VFS_RET_EBADF);
__errno_r(r) = EBADF;
return -1;
}
@ -88,13 +81,13 @@ int _read_r(struct _reent *r, int file, char *ptr, int len) {
ssize_t nr;
if ((file < 0) || (file >= SYSCALL_MAX_FDS) || (fds[file] == NULL)) {
__errno_r(r) = translate_error(VFS_RET_EBADF);
__errno_r(r) = EBADF;
return -1;
}
nr = vfsReadFile(fds[file], (uint8_t *)ptr, (size_t)len);
if (nr < VFS_RET_SUCCESS) {
__errno_r(r) = translate_error((msg_t)nr);
if (CH_IS_ERROR(nr)) {
__errno_r(r) = CH_DECODE_ERROR(nr);
return -1;
}
@ -108,13 +101,13 @@ int _write_r(struct _reent *r, int file, const char *ptr, int len) {
ssize_t nw;
if ((file < 0) || (file >= SYSCALL_MAX_FDS) || (fds[file] == NULL)) {
__errno_r(r) = translate_error(VFS_RET_EBADF);
__errno_r(r) = EBADF;
return -1;
}
nw = vfsWriteFile(fds[file], (const uint8_t *)ptr, (size_t)len);
if (nw < VFS_RET_SUCCESS) {
__errno_r(r) = translate_error((msg_t)nw);
if (CH_IS_ERROR(nw)) {
__errno_r(r) = CH_DECODE_ERROR(nw);
return -1;
}

View File

@ -74,6 +74,11 @@
*****************************************************************************
*** Next ***
- NEW: Added a centralized errors handler under /os/common/utils. It will
replace those in HAL and SB and will be shared among multiple subsystems.
- NEW: Added a new OOP model under /os/common/utils. It will replace the
one in HAL and will be shared among multiple subsystems.
- NEW: Changed SB configuration options names to be prefixed with SB_CFG_.
- NEW: Added a new CH_CFG_HARDENING_LEVEL option to RT.
- NEW: Added a chXXXDispose() function to all objects in NIL.
- NEW: Added a chXXXDispose() function to all objects in RT.