From 2bc6d67866968913fde41a22d58eba0c1d4b02fa Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 20 Feb 2014 18:14:02 -0600 Subject: [PATCH] unlink/rm can now be used on nodes in the pseudo-filesystem. There is new configuration option to suppress these costly and mostly useless operations on the pseudo-filesystem --- ChangeLog.txt | 10 +++++++-- nshlib/Kconfig | 5 +++-- nshlib/README.txt | 12 +++++------ nshlib/nsh.h | 51 +++++++++++++++++++++++++++++++++----------- nshlib/nsh_command.c | 14 ++++++------ nshlib/nsh_fscmds.c | 10 ++++----- nshlib/nsh_parse.c | 2 +- 7 files changed, 68 insertions(+), 36 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index cd58a46c7..be52ac6b4 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -798,7 +798,7 @@ (2014-1-17). * apps/nshlib/Kconfig, README.txt, nsh.h, nsh_command.c, and nsh_script.c: Add an option to conditionally compile out support for - loop and for if-then-else-fi sequence (2014-1-17). + loop and for if-then-else-fi sequence (2014-1-17). * apps/nshlib/nsh.h, nsh_command.c, and nsh_parse.c: Add a break command that can be executed with a loop to terminate the loop immediately (2014-1-17). @@ -831,6 +831,12 @@ * apps/nshlib: 'mkdir' can now be used in the pseudo-filesystem. Hence, the command needs to be available even if there are no write-able filesystem enabled (2014-2-19). - * apps/nshlib: 'rename' can now be used in the pseudo-filesystem. Hence, + * apps/nshlib: 'mv' can now be used in the pseudo-filesystem. Hence, the 'mv' command needs to be available even if there are no write-able filesystem enabled (2014-2-19). + * apps/nshlib: 'rm' can now be used to remove nodes frm the pseudo- + filesystem. Hence, the 'rm' command needs to be available even if there + are no write-able filesystem enabled (2014-2-20). + * CONFIG_DISABLE_PSEUDOFS_OPERATIONS: This new configuration setting + basically backs out the recent changes to mv, rm, mkdir, and rmdir + (2014-2-20). diff --git a/nshlib/Kconfig b/nshlib/Kconfig index 1a9de1068..4167b9e4d 100644 --- a/nshlib/Kconfig +++ b/nshlib/Kconfig @@ -304,6 +304,7 @@ config NSH_DISABLE_SEMICOLON config NSH_CMDPARMS bool "Enable commands as parameters" default n + depends on !DISABLE_MOUNTPOINT ---help--- If selected, then the output from commands, from file applications, and from NSH built-in commands can be used as arguments to other @@ -316,7 +317,7 @@ config NSH_CMDPARMS environment variable BAR. The value of the environment variable FOO is then set output of myprogram on stdout. - Because this feature commits significant resourse, it is disabled by + Because this feature commits significant resources, it is disabled by default. config NSH_TMPDIR @@ -464,7 +465,7 @@ config NSH_ROMFSDEVNO int "ROMFS block device minor number" default 0 ---help--- - This is the minor number of the ROMFS block device. The default is + This is the minor number of the ROMFS block device. The default is '0' corresponding to /dev/ram0. config NSH_ROMFSSECTSIZE diff --git a/nshlib/README.txt b/nshlib/README.txt index 6e112846f..b7a01beb9 100644 --- a/nshlib/README.txt +++ b/nshlib/README.txt @@ -307,7 +307,7 @@ o break until loop, between the do and done tokens. Outside of a loop, break command does nothing. If the break command is executed within the body of a loop, the loop will immediately terminate and execution will - continue with the next command immediately following the done token. + continue with the next command immediately following the done token. o cat [ [ ...]] @@ -955,7 +955,7 @@ Command Dependencies on Configuration Settings cd !CONFIG_DISABLE_ENVIRON && CONFIG_NFILE_DESCRIPTORS > 0 cp CONFIG_NFILE_DESCRIPTORS > 0 dd CONFIG_NFILE_DESCRIPTORS > 0 - delrout CONFIG_NET && CONFIG_NET_ROUTE + delrout CONFIG_NET && CONFIG_NET_ROUTE df !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_READABLE (see note 3) echo -- exec -- @@ -972,19 +972,19 @@ Command Dependencies on Configuration Settings ls CONFIG_NFILE_DESCRIPTORS > 0 md5 CONFIG_NETUTILS_CODECS && CONFIG_CODECS_HASH_MD5 mb,mh,mw --- - mkdir CONFIG_NFILE_DESCRIPTORS > 0 + mkdir (((!CONFIG_DISABLE_MOUNTPOINT && CONFIG_FS_WRITABLE) || !CONFIG_DISABLE_PSEUDOFS_OPERATIONS) && CONFIG_NFILE_DESCRIPTORS > 0) mkfatfs !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_FAT mkfifo CONFIG_NFILE_DESCRIPTORS > 0 mkrd !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_WRITABLE (see note 4) mount !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_READABLE (see note 3) - mv !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_WRITABLE (see note 4) + mv (((!CONFIG_DISABLE_MOUNTPOINT && CONFIG_FS_WRITABLE) || !CONFIG_DISABLE_PSEUDOFS_OPERATIONS) && CONFIG_NFILE_DESCRIPTORS > 0) (see note 4) nfsmount !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NET && CONFIG_NFS ping CONFIG_NET && CONFIG_NET_ICMP && CONFIG_NET_ICMP_PING && !CONFIG_DISABLE_CLOCK && !CONFIG_DISABLE_SIGNALS ps -- put CONFIG_NET && CONFIG_NET_UDP && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NET_BUFSIZE >= 558 (see note 1,2) pwd !CONFIG_DISABLE_ENVIRON && CONFIG_NFILE_DESCRIPTORS > 0 - rm !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_WRITABLE (see note 4) - rmdir CONFIG_NFILE_DESCRIPTORS > 0 + rm (((!CONFIG_DISABLE_MOUNTPOINT && CONFIG_FS_WRITABLE) || !CONFIG_DISABLE_PSEUDOFS_OPERATIONS) && CONFIG_NFILE_DESCRIPTORS > 0) + rmdir (((!CONFIG_DISABLE_MOUNTPOINT && CONFIG_FS_WRITABLE) || !CONFIG_DISABLE_PSEUDOFS_OPERATIONS) && CONFIG_NFILE_DESCRIPTORS > 0) set !CONFIG_DISABLE_ENVIRON sh CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0 && !CONFIG_NSH_DISABLESCRIPT sleep !CONFIG_DISABLE_SIGNALS diff --git a/nshlib/nsh.h b/nshlib/nsh.h index 223799b41..059513e77 100644 --- a/nshlib/nsh.h +++ b/nshlib/nsh.h @@ -75,6 +75,27 @@ # undef CONFIG_NSH_CMDPARMS #endif +/* rmdir, mkdir, rm, and mv are only available if mountpoints are enabled + * AND there is a writeable file system OR if these operations on the + * pseudo-filesystem are not disabled. + */ + +#undef NSH_HAVE_WRITABLE_MOUNTPOINT +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_WRITABLE) && \ + CONFIG_NFILE_STREAMS > 0 +# define NSH_HAVE_WRITABLE_MOUNTPOINT 1 +#endif + +#undef NSH_HAVE_PSEUDOFS_OPERATIONS +#if !defined(CONFIG_DISABLE_PSEUDOFS_OPERATIONS) && CONFIG_NFILE_STREAMS > 0 +# define NSH_HAVE_PSEUDOFS_OPERATIONS 1 +#endif + +#undef NSH_HAVE_DIROPTS +#if defined(NSH_HAVE_WRITABLE_MOUNTPOINT) || defined(NSH_HAVE_PSEUDOFS_OPERATIONS) +# define NSH_HAVE_DIROPTS 1 +#endif + /* If CONFIG_NSH_CMDPARMS is selected, then the path to a directory to * hold temporary files must be provided. */ @@ -661,7 +682,7 @@ void nsh_usbtrace(void); #if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_LOOPS) int cmd_break(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -#endif +#endif #ifndef CONFIG_NSH_DISABLE_ECHO int cmd_echo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); #endif @@ -717,15 +738,6 @@ void nsh_usbtrace(void); # ifndef CONFIG_NSH_DISABLE_LS int cmd_ls(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); # endif -# ifndef CONFIG_NSH_DISABLE_MKDIR - int cmd_mkdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -# ifndef CONFIG_NSH_DISABLE_MV - int cmd_mv(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif -# ifndef CONFIG_NSH_DISABLE_RMDIR - int cmd_rmdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif # if defined(CONFIG_SYSLOG) && defined(CONFIG_RAMLOG_SYSLOG) && !defined(CONFIG_NSH_DISABLE_DMESG) int cmd_dmesg(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); # endif @@ -734,6 +746,22 @@ void nsh_usbtrace(void); int cmd_sh(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); # endif # endif /* CONFIG_NFILE_STREAMS && !CONFIG_NSH_DISABLESCRIPT */ + +# ifdef NSH_HAVE_DIROPTS +# ifndef CONFIG_NSH_DISABLE_MKDIR + int cmd_mkdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +# ifndef CONFIG_NSH_DISABLE_MV + int cmd_mv(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +# ifndef CONFIG_NSH_DISABLE_RM + int cmd_rm(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +# ifndef CONFIG_NSH_DISABLE_RMDIR + int cmd_rmdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif +# endif /* CONFIG_NFILE_STREAMS && NSH_HAVE_DIROPTS */ + # ifndef CONFIG_DISABLE_MOUNTPOINT # ifndef CONFIG_NSH_DISABLE_LOSETUP int cmd_losetup(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); @@ -755,9 +783,6 @@ void nsh_usbtrace(void); # ifndef CONFIG_NSH_DISABLE_MKRD int cmd_mkrd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); # endif -# ifndef CONFIG_NSH_DISABLE_RM - int cmd_rm(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -# endif # endif /* CONFIG_FS_WRITABLE */ # endif /* CONFIG_FS_READABLE */ # ifdef CONFIG_FS_FAT diff --git a/nshlib/nsh_command.c b/nshlib/nsh_command.c index a52a91d4a..2c043aa5c 100644 --- a/nshlib/nsh_command.c +++ b/nshlib/nsh_command.c @@ -121,7 +121,7 @@ static const struct cmdmap_s g_cmdmap[] = #if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_LOOPS) { "break", cmd_break, 1, 1, NULL }, -#endif +#endif #if CONFIG_NFILE_DESCRIPTORS > 0 # ifndef CONFIG_NSH_DISABLE_CAT @@ -252,7 +252,7 @@ static const struct cmdmap_s g_cmdmap[] = # endif #endif -#if CONFIG_NFILE_DESCRIPTORS > 0 +#ifdef NSH_HAVE_DIROPTS # ifndef CONFIG_NSH_DISABLE_MKDIR { "mkdir", cmd_mkdir, 2, 2, "" }, # endif @@ -270,7 +270,7 @@ static const struct cmdmap_s g_cmdmap[] = # endif #endif -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_WRITABLE) +#ifdef NSH_HAVE_WRITABLE_MOUNTPOINT # ifndef CONFIG_NSH_DISABLE_MKRD { "mkrd", cmd_mkrd, 2, 6, "[-m ] [-s ] " }, # endif @@ -300,7 +300,7 @@ static const struct cmdmap_s g_cmdmap[] = # endif #endif -#if CONFIG_NFILE_DESCRIPTORS > 0 +#ifdef NSH_HAVE_DIROPTS # ifndef CONFIG_NSH_DISABLE_MV { "mv", cmd_mv, 3, 3, " " }, # endif @@ -340,13 +340,13 @@ static const struct cmdmap_s g_cmdmap[] = # endif #endif -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_WRITABLE) +#ifdef NSH_HAVE_DIROPTS # ifndef CONFIG_NSH_DISABLE_RM { "rm", cmd_rm, 2, 2, "" }, # endif -# endif +#endif -#if CONFIG_NFILE_DESCRIPTORS > 0 +#ifdef NSH_HAVE_DIROPTS # ifndef CONFIG_NSH_DISABLE_RMDIR { "rmdir", cmd_rmdir, 2, 2, "" }, # endif diff --git a/nshlib/nsh_fscmds.c b/nshlib/nsh_fscmds.c index c56be9497..778d2d584 100644 --- a/nshlib/nsh_fscmds.c +++ b/nshlib/nsh_fscmds.c @@ -995,7 +995,7 @@ int cmd_ls(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) * Name: cmd_mkdir ****************************************************************************/ -#if CONFIG_NFILE_DESCRIPTORS > 0 +#ifdef NSH_HAVE_DIROPTS #ifndef CONFIG_NSH_DISABLE_MKDIR int cmd_mkdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { @@ -1136,7 +1136,7 @@ int cmd_mkfifo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) * Name: cmd_mkrd ****************************************************************************/ -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_WRITABLE) +#ifdef NSH_HAVE_WRITABLE_MOUNTPOINT #ifndef CONFIG_NSH_DISABLE_MKRD int cmd_mkrd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { @@ -1298,7 +1298,7 @@ int cmd_mksmartfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) * Name: cmd_mv ****************************************************************************/ -#if CONFIG_NFILE_DESCRIPTORS > 0 +#ifdef NSH_HAVE_DIROPTS #ifndef CONFIG_NSH_DISABLE_MV int cmd_mv(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { @@ -1342,7 +1342,7 @@ int cmd_mv(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) * Name: cmd_rm ****************************************************************************/ -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_WRITABLE) +#ifdef NSH_HAVE_DIROPTS #ifndef CONFIG_NSH_DISABLE_RM int cmd_rm(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { @@ -1369,7 +1369,7 @@ int cmd_rm(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) * Name: cmd_rmdir ****************************************************************************/ -#if CONFIG_NFILE_DESCRIPTORS > 0 +#ifdef NSH_HAVE_DIROPTS #ifndef CONFIG_NSH_DISABLE_RMDIR int cmd_rmdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { diff --git a/nshlib/nsh_parse.c b/nshlib/nsh_parse.c index 45e3b8508..a83fbe79f 100644 --- a/nshlib/nsh_parse.c +++ b/nshlib/nsh_parse.c @@ -2298,4 +2298,4 @@ int cmd_break(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) return OK; } -#endif +#endif