Parser improvements, streams adapter driver header.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15128 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
parent
6c1ff11e02
commit
09747ca593
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @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 */
|
||||||
|
|
||||||
|
/** @} */
|
|
@ -73,6 +73,14 @@
|
||||||
/* External declarations. */
|
/* External declarations. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/* Module inline functions. */
|
/* Module inline functions. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
|
@ -99,6 +99,10 @@ extern "C" {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*===========================================================================*/
|
||||||
|
/* Module inline functions. */
|
||||||
|
/*===========================================================================*/
|
||||||
|
|
||||||
#endif /* VFSDRIVERS_H */
|
#endif /* VFSDRIVERS_H */
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -76,6 +76,10 @@ extern "C" {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*===========================================================================*/
|
||||||
|
/* Module inline functions. */
|
||||||
|
/*===========================================================================*/
|
||||||
|
|
||||||
#endif /* VFSERRORS_H */
|
#endif /* VFSERRORS_H */
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -222,6 +222,10 @@ extern "C" {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*===========================================================================*/
|
||||||
|
/* Module inline functions. */
|
||||||
|
/*===========================================================================*/
|
||||||
|
|
||||||
#endif /* VFSNODES_H */
|
#endif /* VFSNODES_H */
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -61,6 +61,10 @@ extern "C" {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*===========================================================================*/
|
||||||
|
/* Module inline functions. */
|
||||||
|
/*===========================================================================*/
|
||||||
|
|
||||||
#endif /* VFSPARSE_H */
|
#endif /* VFSPARSE_H */
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -130,6 +130,10 @@ extern "C" {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*===========================================================================*/
|
||||||
|
/* Module inline functions. */
|
||||||
|
/*===========================================================================*/
|
||||||
|
|
||||||
#endif /* VFSSYSTEM_H */
|
#endif /* VFSSYSTEM_H */
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -53,6 +53,11 @@
|
||||||
/* Module exported functions. */
|
/* 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 vfs_parse_separator(const char **pathp) {
|
||||||
msg_t err;
|
msg_t err;
|
||||||
const char *p = *pathp;
|
const char *p = *pathp;
|
||||||
|
@ -68,16 +73,35 @@ msg_t vfs_parse_separator(const char **pathp) {
|
||||||
return err;
|
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 vfs_parse_filename(const char **pathp, char *fname) {
|
||||||
msg_t err;
|
msg_t err = VFS_RET_INVALID_PATH;
|
||||||
size_t n;
|
size_t n;
|
||||||
const char *p = *pathp;
|
const char *p = *pathp;
|
||||||
|
|
||||||
n = 0U;
|
n = 0U;
|
||||||
while (true) {
|
while (true) {
|
||||||
char c = *p++;
|
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;
|
*pathp = p;
|
||||||
*fname = '\0';
|
*fname = '\0';
|
||||||
err = VFS_RET_SUCCESS;
|
err = VFS_RET_SUCCESS;
|
||||||
|
@ -85,7 +109,6 @@ msg_t vfs_parse_filename(const char **pathp, char *fname) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n > VFS_CFG_MAX_NAMELEN) {
|
if (n > VFS_CFG_MAX_NAMELEN) {
|
||||||
err = VFS_RET_INVALID_PATH;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue