diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2008-09-11 21:54:23 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2008-09-11 21:54:23 +0000 |
commit | 97d11b18c99ba683fbe91fc3ad5d9b897de27c81 (patch) | |
tree | 221d07773f3a6dfb6f566eacf2c97e15e77e935f /nuttx/examples/nsh/nsh_fscmds.c | |
parent | c89a814396a9e542f05bc8b204b0b6c00dc1bf83 (diff) | |
download | px4-nuttx-97d11b18c99ba683fbe91fc3ad5d9b897de27c81.tar.gz px4-nuttx-97d11b18c99ba683fbe91fc3ad5d9b897de27c81.tar.bz2 px4-nuttx-97d11b18c99ba683fbe91fc3ad5d9b897de27c81.zip |
Add /etc via ROMFS and /tmp via FAT FS to NSH
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@910 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/examples/nsh/nsh_fscmds.c')
-rw-r--r-- | nuttx/examples/nsh/nsh_fscmds.c | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/nuttx/examples/nsh/nsh_fscmds.c b/nuttx/examples/nsh/nsh_fscmds.c index d38d9b720..33d1ae6d2 100644 --- a/nuttx/examples/nsh/nsh_fscmds.c +++ b/nuttx/examples/nsh/nsh_fscmds.c @@ -218,6 +218,17 @@ static int foreach_direntry(FAR struct nsh_vtbl_s *vtbl, const char *cmd, const #endif /**************************************************************************** + * Name: ls_specialdir + ****************************************************************************/ + +static inline int ls_specialdir(const char *dir) +{ + /* '.' and '..' directories are not listed like normal directories */ + + return (strcmp(dir, ".") == 0 || strcmp(dir, "..") == 0); +} + +/**************************************************************************** * Name: ls_handler ****************************************************************************/ @@ -322,7 +333,7 @@ static int ls_handler(FAR struct nsh_vtbl_s *vtbl, const char *dirpath, struct d nsh_output(vtbl, " %s", entryp->d_name); #endif - if (DIRENT_ISDIRECTORY(entryp->d_type)) + if (DIRENT_ISDIRECTORY(entryp->d_type) && !ls_specialdir(entryp->d_name)) { nsh_output(vtbl, "/\n"); } @@ -339,12 +350,14 @@ static int ls_handler(FAR struct nsh_vtbl_s *vtbl, const char *dirpath, struct d ****************************************************************************/ #if CONFIG_NFILE_DESCRIPTORS > 0 -static int ls_recursive(FAR struct nsh_vtbl_s *vtbl, const char *dirpath, struct dirent *entryp, void *pvarg) +static int ls_recursive(FAR struct nsh_vtbl_s *vtbl, const char *dirpath, + struct dirent *entryp, void *pvarg) { int ret = OK; - /* Is this entry a directory? */ - if (DIRENT_ISDIRECTORY(entryp->d_type)) + /* Is this entry a directory (and not one of the special directories, . and ..)? */ + + if (DIRENT_ISDIRECTORY(entryp->d_type) && !ls_specialdir(entryp->d_name)) { /* Yes.. */ @@ -354,6 +367,9 @@ static int ls_recursive(FAR struct nsh_vtbl_s *vtbl, const char *dirpath, struct /* List the directory contents */ nsh_output(vtbl, "%s:\n", newpath); + + /* Traverse the directory */ + ret = foreach_direntry(vtbl, "ls", newpath, ls_handler, pvarg); if (ret == 0) { @@ -1002,11 +1018,11 @@ int cmd_rmdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) #endif /**************************************************************************** - * Name: cmd_sh + * Name: nsh_script ****************************************************************************/ #if CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0 && !defined(CONFIG_EXAMPLES_NSH_DISABLESCRIPT) -int cmd_sh(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) +int nsh_script(FAR struct nsh_vtbl_s *vtbl, const char *cmd, const char *path) { char *fullpath; FILE *stream; @@ -1016,7 +1032,7 @@ int cmd_sh(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) /* The path to the script may be relative to the current working directory */ - fullpath = nsh_getfullpath(vtbl, argv[1]); + fullpath = nsh_getfullpath(vtbl, path); if (!fullpath) { return ERROR; @@ -1032,7 +1048,7 @@ int cmd_sh(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) stream = fopen(fullpath, "r"); if (!stream) { - nsh_output(vtbl, g_fmtcmdfailed, argv[0], "fopen", NSH_ERRNO); + nsh_output(vtbl, g_fmtcmdfailed, cmd, "fopen", NSH_ERRNO); nsh_freefullpath(fullpath); return ERROR; } @@ -1067,6 +1083,17 @@ int cmd_sh(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) #endif /**************************************************************************** + * Name: cmd_sh + ****************************************************************************/ + +#if CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0 && !defined(CONFIG_EXAMPLES_NSH_DISABLESCRIPT) +int cmd_sh(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) +{ + return nsh_script(vtbl, argv[0], argv[1]); +} +#endif + +/**************************************************************************** * Name: cmd_umount ****************************************************************************/ |