diff --git a/os/vfs/drivers/streams/drvstreams.h b/os/vfs/drivers/streams/drvstreams.h new file mode 100644 index 000000000..559328da5 --- /dev/null +++ b/os/vfs/drivers/streams/drvstreams.h @@ -0,0 +1,106 @@ +/* + ChibiOS - Copyright (C) 2006,2007,2008,2009,2010,2011,2012,2013,2014, + 2015,2016,2017,2018,2019,2020,2021 Giovanni Di Sirio. + + This file is part of ChibiOS. + + ChibiOS is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation version 3 of the License. + + ChibiOS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +/** + * @file vfs/drivers/drvstreams.h + * @brief HAL streams VFS driver header. + * + * @addtogroup VFS_DRV_STREAMS + * @details Exposes HAL streams as VFS files. + * @{ + */ + +#ifndef DRVSTREAMS_H +#define DRVSTREAMS_H + +#include "vfs.h" + +/*===========================================================================*/ +/* Module constants. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module pre-compile time settings. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Derived constants and error checks. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module data structures and types. */ +/*===========================================================================*/ + +/** + * @brief Type of a structure representing a VFS driver. + */ +typedef struct vfs_drv_streams vfs_drv_streams_t; + +/** + * @brief @p vfs_node_t specific methods. + */ +#define __vfs_drv_streams_methods \ + __vfs_driver_methods + +/** + * @brief @p vfs_node_t specific data. + */ +#define __vfs_drv_streams_data \ + __vfs_driver_data + +/** + * @brief @p vfs_node_t virtual methods table. + */ +struct vfs_drv_stream_vmt { + __vfs_drv_streams_methods +}; + +/** + * @brief TStructure representing a VFS driver. + */ +struct vfs_drv_streams { + /** + * @brief Virtual Methods Table. + */ + const struct vfs_drv_streams_vmt *vmt; + __vfs_drv_streams_data +}; + +/*===========================================================================*/ +/* Module macros. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +/*===========================================================================*/ +/* Module inline functions. */ +/*===========================================================================*/ + +#endif /* DRVSTREAMS_H */ + +/** @} */ diff --git a/os/vfs/include/vfschecks.h b/os/vfs/include/vfschecks.h index 270b919ba..8be1a243d 100644 --- a/os/vfs/include/vfschecks.h +++ b/os/vfs/include/vfschecks.h @@ -73,6 +73,14 @@ /* External declarations. */ /*===========================================================================*/ +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + /*===========================================================================*/ /* Module inline functions. */ /*===========================================================================*/ diff --git a/os/vfs/include/vfsdrivers.h b/os/vfs/include/vfsdrivers.h index fad69c093..bc057bf0c 100644 --- a/os/vfs/include/vfsdrivers.h +++ b/os/vfs/include/vfsdrivers.h @@ -99,6 +99,10 @@ extern "C" { } #endif +/*===========================================================================*/ +/* Module inline functions. */ +/*===========================================================================*/ + #endif /* VFSDRIVERS_H */ /** @} */ diff --git a/os/vfs/include/vfserrors.h b/os/vfs/include/vfserrors.h index 65870ab32..7b2515c08 100644 --- a/os/vfs/include/vfserrors.h +++ b/os/vfs/include/vfserrors.h @@ -76,6 +76,10 @@ extern "C" { } #endif +/*===========================================================================*/ +/* Module inline functions. */ +/*===========================================================================*/ + #endif /* VFSERRORS_H */ /** @} */ diff --git a/os/vfs/include/vfsnodes.h b/os/vfs/include/vfsnodes.h index 0c3797717..cec55a791 100644 --- a/os/vfs/include/vfsnodes.h +++ b/os/vfs/include/vfsnodes.h @@ -222,6 +222,10 @@ extern "C" { } #endif +/*===========================================================================*/ +/* Module inline functions. */ +/*===========================================================================*/ + #endif /* VFSNODES_H */ /** @} */ diff --git a/os/vfs/include/vfsparser.h b/os/vfs/include/vfsparser.h index 2d2e0a106..f7202f940 100644 --- a/os/vfs/include/vfsparser.h +++ b/os/vfs/include/vfsparser.h @@ -61,6 +61,10 @@ extern "C" { } #endif +/*===========================================================================*/ +/* Module inline functions. */ +/*===========================================================================*/ + #endif /* VFSPARSE_H */ /** @} */ diff --git a/os/vfs/include/vfssystem.h b/os/vfs/include/vfssystem.h index d0c411138..5a3cbb765 100644 --- a/os/vfs/include/vfssystem.h +++ b/os/vfs/include/vfssystem.h @@ -130,6 +130,10 @@ extern "C" { } #endif +/*===========================================================================*/ +/* Module inline functions. */ +/*===========================================================================*/ + #endif /* VFSSYSTEM_H */ /** @} */ diff --git a/os/vfs/src/vfsparser.c b/os/vfs/src/vfsparser.c index 92b47abce..c1a1acf78 100644 --- a/os/vfs/src/vfsparser.c +++ b/os/vfs/src/vfsparser.c @@ -53,6 +53,11 @@ /* Module exported functions. */ /*===========================================================================*/ +/** + * @brief Parses a path separator. + * + * @param[in, out] pathp pointer to the path under parsing + */ msg_t vfs_parse_separator(const char **pathp) { msg_t err; const char *p = *pathp; @@ -68,16 +73,35 @@ msg_t vfs_parse_separator(const char **pathp) { return err; } - +/** + * @brief Parses a filename element using the restricted Posix set. + * @note Consumes the next path separator, if any. + * + * @param[in, out] pathp pointer to the path under parsing + * @param[out] fname extracted file name + */ msg_t vfs_parse_filename(const char **pathp, char *fname) { - msg_t err; + msg_t err = VFS_RET_INVALID_PATH; size_t n; const char *p = *pathp; n = 0U; while (true) { char c = *p++; - if ((c == '\0') || (c == '/')) { + + /* Valid characters for path names.*/ + if (!isalnum(c) && (c != '_') && (c != '-') && (c != '.')) { + break; + } + + if (c == '/') { + *pathp = p + 1; + *fname = '\0'; + err = VFS_RET_SUCCESS; + break; + } + + if (c == '\0') { *pathp = p; *fname = '\0'; err = VFS_RET_SUCCESS; @@ -85,7 +109,6 @@ msg_t vfs_parse_filename(const char **pathp, char *fname) { } if (n > VFS_CFG_MAX_NAMELEN) { - err = VFS_RET_INVALID_PATH; break; }