git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15226 27425a3e-05d8-49a3-a47f-9c15f0e5edd8

This commit is contained in:
Giovanni Di Sirio 2021-12-09 15:51:39 +00:00
parent 4b0248ca33
commit e3c3e9916a
6 changed files with 41 additions and 6 deletions

View File

@ -157,9 +157,11 @@ static msg_t translate_error(FRESULT res) {
break; break;
case FR_NO_FILE: case FR_NO_FILE:
case FR_NO_PATH: case FR_NO_PATH:
case FR_INVALID_NAME:
msg = VFS_RET_ENOENT; msg = VFS_RET_ENOENT;
break; break;
case FR_INVALID_NAME:
msg = VFS_RET_ENAMETOOLONG;
break;
case FR_DENIED: case FR_DENIED:
case FR_WRITE_PROTECTED: case FR_WRITE_PROTECTED:
msg = VFS_RET_EACCES; msg = VFS_RET_EACCES;

View File

@ -94,7 +94,7 @@ static msg_t match_driver(vfs_overlay_driver_c *odp,
vfs_driver_c **pp; vfs_driver_c **pp;
do { do {
err = vfs_parse_filename(pathp, fname); err = vfs_parse_get_fname(pathp, fname);
VFS_BREAK_ON_ERROR(err); VFS_BREAK_ON_ERROR(err);
/* Searching among registered drivers.*/ /* Searching among registered drivers.*/

View File

@ -162,7 +162,7 @@ static msg_t drv_open_file(void *instance,
err = vfs_parse_match_separator(&path); err = vfs_parse_match_separator(&path);
VFS_BREAK_ON_ERROR(err); VFS_BREAK_ON_ERROR(err);
err = vfs_parse_filename(&path, fname); err = vfs_parse_get_fname(&path, fname);
VFS_BREAK_ON_ERROR(err); VFS_BREAK_ON_ERROR(err);
err = vfs_parse_match_end(&path); err = vfs_parse_match_end(&path);

View File

@ -73,6 +73,7 @@
#define VFS_RET_ENOSPC (-32 - ENOSPC) /* No space left on device */ #define VFS_RET_ENOSPC (-32 - ENOSPC) /* No space left on device */
#define VFS_RET_ESPIPE (-32 - ESPIPE) /* Illegal seek */ #define VFS_RET_ESPIPE (-32 - ESPIPE) /* Illegal seek */
#define VFS_RET_EROFS (-32 - EROFS) /* Read-only file system */ #define VFS_RET_EROFS (-32 - EROFS) /* Read-only file system */
#define VFS_RET_ENAMETOOLONG (-32 - ENAMETOOLONG)/* File or path name too long */
/** @} */ /** @} */
/*===========================================================================*/ /*===========================================================================*/

View File

@ -57,7 +57,8 @@ extern "C" {
#endif #endif
msg_t vfs_parse_match_separator(const char **pathp); msg_t vfs_parse_match_separator(const char **pathp);
msg_t vfs_parse_match_end(const char **pathp); msg_t vfs_parse_match_end(const char **pathp);
msg_t vfs_parse_filename(const char **pathp, char *fname); msg_t vfs_parse_get_fname(const char **pathp, char *fname);
msg_t vfs_parse_copy_with_separator(char *dst, const char *src);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -90,13 +90,13 @@ msg_t vfs_parse_match_end(const char **pathp) {
} }
/** /**
* @brief Parses a path element using the restricted Posix set. * @brief Fetches the next path element.
* @note Consumes the next path separator, if any. * @note Consumes the next path separator, if any.
* *
* @param[in, out] pathp pointer to the path under parsing * @param[in, out] pathp pointer to the path under parsing
* @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_get_fname(const char **pathp, char *fname) {
size_t size; size_t size;
const char *p; const char *p;
@ -136,4 +136,35 @@ msg_t vfs_parse_filename(const char **pathp, char *fname) {
} }
} }
msg_t vfs_parse_copy_with_separator(char *dst, const char *src) {
size_t n = 0U;
char lc = '\0';
/* Copying the path.*/
while ((*dst = *src) != '\0') {
if (n > VFS_CFG_PATHLEN_MAX) {
return VFS_RET_ENAMETOOLONG;
}
lc = *src++;
dst++;
n++;
}
/* Checking if it is terminated by a separator, if not then adding it.*/
if (lc != '/') {
if (n > VFS_CFG_PATHLEN_MAX) {
return VFS_RET_ENAMETOOLONG;
}
*dst++ = '/';
*dst = '\0';
n++;
}
return (msg_t)n;
}
/** @} */ /** @} */