Directory-related commands apparently working now, file commands to be reworked.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15253 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
Giovanni Di Sirio 2021-12-26 08:16:26 +00:00
parent a43c553ce0
commit 7480e1eb3d
4 changed files with 43 additions and 5 deletions

View File

@ -354,13 +354,13 @@ static void cmd_cd(BaseSequentialStream *chp, int argc, char *argv[]) {
while (false); while (false);
} }
static void cmd_cwd(BaseSequentialStream *chp, int argc, char *argv[]) { static void cmd_pwd(BaseSequentialStream *chp, int argc, char *argv[]) {
char *buf = NULL; char *buf = NULL;
(void)argv; (void)argv;
if (argc != 0) { if (argc != 0) {
chprintf(chp, "Usage: cwd" SHELL_NEWLINE_STR); chprintf(chp, "Usage: pwd" SHELL_NEWLINE_STR);
return; return;
} }
@ -419,7 +419,7 @@ const ShellCommand shell_local_commands[] = {
{"tree", cmd_tree}, {"tree", cmd_tree},
{"cat", cmd_cat}, {"cat", cmd_cat},
{"cd", cmd_cd}, {"cd", cmd_cd},
{"cwd", cmd_cwd}, {"pwd", cmd_pwd},
#endif #endif
#if SHELL_CMD_TEST_ENABLED == TRUE #if SHELL_CMD_TEST_ENABLED == TRUE
{"test", cmd_test}, {"test", cmd_test},

View File

@ -195,8 +195,14 @@ static msg_t open_absolute_dir(vfs_overlay_driver_c *drvp,
msg_t err; msg_t err;
do { do {
/* Initial separator is expected, skipping.*/ const char *scanpath;
const char *scanpath = path + 1;
/* Making sure there is a final separator.*/
err = vfs_path_add_separator(path, VFS_CFG_PATHLEN_MAX + 1);
VFS_BREAK_ON_ERROR(err);
/* Initial separator is expected, skipping it.*/
scanpath = path + 1;
/* If it is the root.*/ /* If it is the root.*/
if (*scanpath == '\0') { if (*scanpath == '\0') {

View File

@ -57,6 +57,7 @@ extern "C" {
#endif #endif
msg_t vfs_path_append(char *dst, const char *src, size_t size); msg_t vfs_path_append(char *dst, const char *src, size_t size);
msg_t vfs_path_prepend(char *dst, const char *src, size_t size); msg_t vfs_path_prepend(char *dst, const char *src, size_t size);
msg_t vfs_path_add_separator(char *dst, size_t size);
msg_t vfs_path_normalize(char *dst, const char *src, size_t size); msg_t vfs_path_normalize(char *dst, const char *src, size_t size);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -129,6 +129,37 @@ msg_t vfs_path_prepend(char *dst, const char *src, size_t size) {
return (msg_t)sn; return (msg_t)sn;
} }
/**
* @brief Adds a separator to the end of a path if it is missing.
*
* @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.
*/
msg_t vfs_path_add_separator(char *dst, size_t size) {
size_t dn;
dn = strnlen(dst, size - 1U);
if (dn == 0U) {
dst[0] = '/';
dst[1] = '\0';
}
else {
if (!vfs_parse_is_separator(dst[dn - 1])) {
if (dn >= size - 1) {
return VFS_RET_ERANGE;
}
dst[dn] = '/';
dst[dn + 1] = '\0';
}
}
return dn + 1;
}
/** /**
* @brief Normalizes an absolute path. * @brief Normalizes an absolute path.
* @note The destination buffer can be the same of the source buffer. * @note The destination buffer can be the same of the source buffer.