Added VFS-related commands to the shell, disabled by default.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15198 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
parent
5ccde8d4ed
commit
7d76e688a7
|
@ -129,69 +129,15 @@ static const drv_stream_element_t streams[] = {
|
|||
{NULL, NULL}
|
||||
};
|
||||
|
||||
/* Generic large buffer.*/
|
||||
static char pathbuf[1024];
|
||||
|
||||
static void scan_nodes(BaseSequentialStream *chp, char *path) {
|
||||
msg_t res;
|
||||
vfs_directory_node_c *dirp;
|
||||
static vfs_node_info_t ni;
|
||||
|
||||
chprintf(chp, "%s\r\n", path);
|
||||
res = vfsOpenDirectory(path, &dirp);
|
||||
if (res == VFS_RET_SUCCESS) {
|
||||
size_t i = strlen(path);
|
||||
|
||||
while (true) {
|
||||
char *fn = ni.name;
|
||||
res = vfsReadDirectoryNext(dirp, &ni);
|
||||
if (res != VFS_RET_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
|
||||
fn = ni.name;
|
||||
if (ni.attr & VFS_NODE_ATTR_ISDIR) {
|
||||
strcpy(path + i, fn);
|
||||
strcat(path + i, "/");
|
||||
scan_nodes(chp, path);
|
||||
path[i] = '\0';
|
||||
}
|
||||
else {
|
||||
chprintf(chp, "%s%s\r\n", path, fn);
|
||||
}
|
||||
}
|
||||
|
||||
vfsCloseDirectory(dirp);
|
||||
}
|
||||
}
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Command line related. */
|
||||
/*===========================================================================*/
|
||||
|
||||
#define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(2048)
|
||||
|
||||
static void cmd_tree(BaseSequentialStream *chp, int argc, char *argv[]) {
|
||||
|
||||
(void)argv;
|
||||
|
||||
if (argc > 0) {
|
||||
chprintf(chp, "Usage: tree\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
strcpy(pathbuf, "/");
|
||||
scan_nodes(chp, (char *)pathbuf);
|
||||
}
|
||||
|
||||
static const ShellCommand commands[] = {
|
||||
{"tree", cmd_tree},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
static ShellConfig shell_cfg1 = {
|
||||
NULL,
|
||||
commands
|
||||
NULL
|
||||
};
|
||||
|
||||
/*===========================================================================*/
|
||||
|
|
|
@ -158,7 +158,7 @@ CPPWARN = -Wall -Wextra -Wundef
|
|||
#
|
||||
|
||||
# List all user C define here, like -D_DEBUG=1
|
||||
UDEFS =
|
||||
UDEFS = -DSHELL_CMD_FILES_ENABLED=1
|
||||
|
||||
# Define ASM defines here
|
||||
UADEFS =
|
||||
|
|
|
@ -158,7 +158,7 @@ CPPWARN = -Wall -Wextra -Wundef
|
|||
#
|
||||
|
||||
# List all user C define here, like -D_DEBUG=1
|
||||
UDEFS =
|
||||
UDEFS = -DSHELL_CMD_FILES_ENABLED=1
|
||||
|
||||
# Define ASM defines here
|
||||
UADEFS =
|
||||
|
|
|
@ -30,6 +30,10 @@
|
|||
#include "shell_cmd.h"
|
||||
#include "chprintf.h"
|
||||
|
||||
#if (SHELL_CMD_FILES_ENABLED == TRUE) || defined(__DOXYGEN__)
|
||||
#include "vfs.h"
|
||||
#endif
|
||||
|
||||
#if (SHELL_CMD_TEST_ENABLED == TRUE) || defined(__DOXYGEN__)
|
||||
#include "rt_test_root.h"
|
||||
#include "oslib_test_root.h"
|
||||
|
@ -226,6 +230,75 @@ static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
|
|||
}
|
||||
#endif
|
||||
|
||||
#if (SHELL_CMD_FILES_ENABLED == TRUE) || defined(__DOXYGEN__)
|
||||
static void scan_nodes(BaseSequentialStream *chp,
|
||||
char *path,
|
||||
vfs_node_info_t *nip) {
|
||||
msg_t res;
|
||||
vfs_directory_node_c *dirp;
|
||||
|
||||
chprintf(chp, "%s\r\n", path);
|
||||
res = vfsOpenDirectory(path, &dirp);
|
||||
if (res == VFS_RET_SUCCESS) {
|
||||
size_t i = strlen(path);
|
||||
|
||||
while (true) {
|
||||
char *fn = nip->name;
|
||||
res = vfsReadDirectoryNext(dirp, nip);
|
||||
if (res != VFS_RET_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
|
||||
fn = nip->name;
|
||||
if (nip->attr & VFS_NODE_ATTR_ISDIR) {
|
||||
strcpy(path + i, fn);
|
||||
strcat(path + i, "/");
|
||||
scan_nodes(chp, path, nip);
|
||||
path[i] = '\0';
|
||||
}
|
||||
else {
|
||||
chprintf(chp, "%s%s\r\n", path, fn);
|
||||
}
|
||||
}
|
||||
|
||||
vfsCloseDirectory(dirp);
|
||||
}
|
||||
}
|
||||
|
||||
static void cmd_tree(BaseSequentialStream *chp, int argc, char *argv[]) {
|
||||
char *pathbuf = NULL;
|
||||
vfs_node_info_t *nip = NULL;
|
||||
|
||||
(void)argv;
|
||||
|
||||
if (argc > 0) {
|
||||
chprintf(chp, "Usage: tree\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
do {
|
||||
pathbuf = (char *)chHeapAlloc(NULL, 1024);
|
||||
nip = (vfs_node_info_t *)chHeapAlloc(NULL, 1024);
|
||||
if ((pathbuf == NULL) || (nip == NULL)) {
|
||||
chprintf(chp, "Out of memory\r\n");
|
||||
break;
|
||||
}
|
||||
|
||||
strcpy(pathbuf, "/");
|
||||
scan_nodes(chp, pathbuf, nip);
|
||||
}
|
||||
while (false);
|
||||
|
||||
if (pathbuf != NULL) {
|
||||
chHeapFree((void *)pathbuf);
|
||||
}
|
||||
|
||||
if (nip != NULL) {
|
||||
chHeapFree((void *)nip);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Module exported functions. */
|
||||
/*===========================================================================*/
|
||||
|
@ -252,6 +325,9 @@ const ShellCommand shell_local_commands[] = {
|
|||
#if SHELL_CMD_THREADS_ENABLED == TRUE
|
||||
{"threads", cmd_threads},
|
||||
#endif
|
||||
#if SHELL_CMD_FILES_ENABLED == TRUE
|
||||
{"tree", cmd_tree},
|
||||
#endif
|
||||
#if SHELL_CMD_TEST_ENABLED == TRUE
|
||||
{"test", cmd_test},
|
||||
#endif
|
||||
|
|
|
@ -61,6 +61,10 @@
|
|||
#define SHELL_CMD_TEST_ENABLED TRUE
|
||||
#endif
|
||||
|
||||
#if !defined(SHELL_CMD_FILES_ENABLED) || defined(__DOXYGEN__)
|
||||
#define SHELL_CMD_FILES_ENABLED FALSE
|
||||
#endif
|
||||
|
||||
#if !defined(SHELL_CMD_TEST_WA_SIZE) || defined(__DOXYGEN__)
|
||||
#define SHELL_CMD_TEST_WA_SIZE THD_WORKING_AREA_SIZE(512)
|
||||
#endif
|
||||
|
|
|
@ -78,6 +78,7 @@
|
|||
in chsem.c.
|
||||
- TODO: Implement pointers check everywhere in RT replacing assertions for
|
||||
NULL pointers.
|
||||
- NEW: Added VFS-related commands to the shell, disabled by default.
|
||||
- NEW: Added a new VFS subsystem (Virtual File System), it allows to assemble
|
||||
trees of files from multiple "File System Drivers" into a single tree
|
||||
and access it as a whole.
|
||||
|
|
Loading…
Reference in New Issue