mirror of https://github.com/rusefi/ChibiOS.git
Fixes and parser improvements.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15139 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
parent
31d49e9170
commit
aaf5fd78ad
|
@ -100,36 +100,42 @@ msg_t vfs_parse_match_end(const char **pathp) {
|
||||||
* @param[out] fname extracted file name
|
* @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 = VFS_RET_INVALID_PATH;
|
|
||||||
size_t n;
|
size_t n;
|
||||||
const char *p = *pathp;
|
const char *p;
|
||||||
|
|
||||||
|
p = *pathp;
|
||||||
n = 0U;
|
n = 0U;
|
||||||
while (true) {
|
while (true) {
|
||||||
char c = *p;
|
char c = *p;
|
||||||
|
|
||||||
/* Valid characters for path names.*/
|
/* File names must be terminated by a separator or an end-of-string.*/
|
||||||
if (!isalnum(c) && (c != '_') && (c != '-') && (c != '.')) {
|
if ((c == '/') || (c == '\0')) {
|
||||||
break;
|
|
||||||
|
/* Consecutive separators are not valid.*/
|
||||||
|
if (n == 0U) {
|
||||||
|
return VFS_RET_INVALID_PATH;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((c == '/') || (c == '\0')) {
|
/* Advancing the path pointer past the file name in the path and
|
||||||
|
closing the file name string.*/
|
||||||
*pathp = p;
|
*pathp = p;
|
||||||
*fname = '\0';
|
*fname = '\0';
|
||||||
err = VFS_RET_SUCCESS;
|
return VFS_RET_SUCCESS;
|
||||||
break;
|
}
|
||||||
|
|
||||||
|
/* Valid characters for path names.*/
|
||||||
|
if (!isalnum(c) && (c != '_') && (c != '-') && (c != '.')) {
|
||||||
|
return VFS_RET_INVALID_PATH;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n > VFS_CFG_MAX_NAMELEN) {
|
if (n > VFS_CFG_MAX_NAMELEN) {
|
||||||
break;
|
return VFS_RET_INVALID_PATH;
|
||||||
}
|
}
|
||||||
|
|
||||||
*fname++ = c;
|
*fname++ = c;
|
||||||
p++;
|
p++;
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -143,13 +143,14 @@ static msg_t root_open_dir(void *instance,
|
||||||
const char *path,
|
const char *path,
|
||||||
vfs_directory_node_t **vdnpp) {
|
vfs_directory_node_t **vdnpp) {
|
||||||
msg_t err;
|
msg_t err;
|
||||||
vfs_root_driver_t *rootp = (vfs_root_driver_t *)instance;
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
err = vfs_parse_match_separator(&path);
|
err = vfs_parse_match_separator(&path);
|
||||||
VFS_BREAK_ON_ERROR(err);
|
VFS_BREAK_ON_ERROR(err);
|
||||||
|
|
||||||
if (*path == '\0') {
|
if (*path == '\0') {
|
||||||
|
vfs_root_driver_t *rootp = (vfs_root_driver_t *)instance;
|
||||||
|
|
||||||
/* Creating a root directory node.*/
|
/* Creating a root directory node.*/
|
||||||
vfs_root_dir_node_t *rdnp = chPoolAlloc(&rootp->dir_nodes_pool);
|
vfs_root_dir_node_t *rdnp = chPoolAlloc(&rootp->dir_nodes_pool);
|
||||||
if (rdnp != NULL) {
|
if (rdnp != NULL) {
|
||||||
|
@ -184,16 +185,26 @@ static msg_t root_open_file(void *instance,
|
||||||
vfs_file_node_t **vfnpp) {
|
vfs_file_node_t **vfnpp) {
|
||||||
msg_t err;
|
msg_t err;
|
||||||
|
|
||||||
(void)instance;
|
|
||||||
(void)vfnpp;
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
err = vfs_parse_match_separator(&path);
|
err = vfs_parse_match_separator(&path);
|
||||||
VFS_BREAK_ON_ERROR(err);
|
VFS_BREAK_ON_ERROR(err);
|
||||||
|
|
||||||
|
if (*path == '\0') {
|
||||||
|
(void)instance;
|
||||||
|
|
||||||
/* Always not found, there are no files in the root.*/
|
/* Always not found, there are no files in the root.*/
|
||||||
err = VFS_RET_NOT_FOUND;
|
err = VFS_RET_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
vfs_driver_t *dp;
|
||||||
|
|
||||||
|
/* Delegating node creation to a registered driver.*/
|
||||||
|
err = match_driver(&path, &dp);
|
||||||
|
VFS_BREAK_ON_ERROR(err);
|
||||||
|
|
||||||
|
err = dp->vmt->open_file((void *)dp, path, vfnpp);
|
||||||
|
}
|
||||||
|
}
|
||||||
while (false);
|
while (false);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
|
@ -295,39 +306,8 @@ msg_t vfsRegisterDriver(vfs_driver_t *vdp) {
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
msg_t vfsOpenDirectory(const char *path, vfs_directory_node_t **vdnpp) {
|
msg_t vfsOpenDirectory(const char *path, vfs_directory_node_t **vdnpp) {
|
||||||
msg_t err;
|
|
||||||
vfs_driver_t *dp;
|
|
||||||
|
|
||||||
do {
|
return vfs.vmt->open_dir((vfs_driver_t *)&vfs, path, vdnpp);
|
||||||
err = vfs_parse_match_separator(&path);
|
|
||||||
VFS_BREAK_ON_ERROR(err);
|
|
||||||
|
|
||||||
if (*path == '\0') {
|
|
||||||
/* Creating a root directory node.*/
|
|
||||||
vfs_root_dir_node_t *rdnp = chPoolAlloc(&vfs.dir_nodes_pool);
|
|
||||||
if (rdnp != NULL) {
|
|
||||||
|
|
||||||
/* Node object initialization.*/
|
|
||||||
rdnp->vmt = &root_dir_node_vmt;
|
|
||||||
rdnp->refs = 1U;
|
|
||||||
rdnp->driver = (vfs_driver_t *)&vfs;
|
|
||||||
rdnp->index = 0U;
|
|
||||||
|
|
||||||
*vdnpp = (vfs_directory_node_t *)rdnp;
|
|
||||||
return VFS_RET_SUCCESS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
/* Delegating node creation to a registered driver.*/
|
|
||||||
err = match_driver(&path, &dp);
|
|
||||||
VFS_BREAK_ON_ERROR(err);
|
|
||||||
|
|
||||||
err = dp->vmt->open_dir((void *)dp, path, vdnpp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (false);
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -390,21 +370,8 @@ msg_t vfsReadDirectoryNext(vfs_directory_node_t *vdnp,
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
msg_t vfsOpenFile(const char *path, vfs_file_node_t **vfnpp) {
|
msg_t vfsOpenFile(const char *path, vfs_file_node_t **vfnpp) {
|
||||||
msg_t err;
|
|
||||||
vfs_driver_t *dp;
|
|
||||||
|
|
||||||
do {
|
return vfs.vmt->open_file((vfs_driver_t *)&vfs, path, vfnpp);
|
||||||
err = vfs_parse_match_separator(&path);
|
|
||||||
VFS_BREAK_ON_ERROR(err);
|
|
||||||
|
|
||||||
err = match_driver(&path, &dp);
|
|
||||||
VFS_BREAK_ON_ERROR(err);
|
|
||||||
|
|
||||||
err = dp->vmt->open_file((void *)dp, path, vfnpp);
|
|
||||||
}
|
|
||||||
while (false);
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue