NSH: Add readlink command.

This commit is contained in:
Gregory Nutt 2017-02-05 10:35:11 -06:00
parent bb81a3d11d
commit 7a0e08c37b
5 changed files with 65 additions and 8 deletions

View File

@ -1,4 +1,5 @@
#
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
@ -318,7 +319,8 @@ config NSH_DISABLE_LOSMART
config NSH_DISABLE_LN
bool "Disable ln"
default n
default y if DEFAULT_SMALL
default n if !DEFAULT_SMALL
depends on PSEUDOFS_SOFTLINKS
config NSH_DISABLE_LS
@ -434,6 +436,12 @@ config NSH_DISABLE_PWD
bool "Disable pwd"
default n
config NSH_DISABLE_READLINK
bool "Disable readlink"
default y if DEFAULT_SMALL
default n if !DEFAULT_SMALL
depends on PSEUDOFS_SOFTLINKS
config NSH_DISABLE_REBOOT
bool "Disable reboot"
default n if !DEFAULT_SMALL && !BOARDCTL_POWEROFF

View File

@ -947,6 +947,10 @@ o pwd
/dev
nsh>
o readlink <link>
Show target of a soft link.
o reboot
Reset and reboot the system immediately. This command depends on hardware
@ -1228,6 +1232,7 @@ Command Dependencies on Configuration Settings
ps CONFIG_FS_PROCFS && !CONFIG_FS_PROCFS_EXCLUDE_PROC
put CONFIG_NET && CONFIG_NET_UDP && CONFIG_NFILE_DESCRIPTORS > 0 && MTU >= 558 (see note 1,2)
pwd !CONFIG_DISABLE_ENVIRON && CONFIG_NFILE_DESCRIPTORS > 0
readlink CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_PSEUDOFS_SOFTLINK
reboot CONFIG_BOARDCTL_RESET
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)
@ -1278,13 +1283,13 @@ also allow it to squeeze into very small memory footprints.
CONFIG_NSH_DISABLE_MW, CONFIG_NSH_DISABLE_MV, CONFIG_NSH_DISABLE_NFSMOUNT,
CONFIG_NSH_DISABLE_NSLOOKUP, CONFIG_NSH_DISABLE_PASSWD, CONFIG_NSH_DISABLE_PING,
CONFIG_NSH_DISABLE_PING6, CONFIG_NSH_DISABLE_POWEROFF, CONFIG_NSH_DISABLE_PS,
CONFIG_NSH_DISABLE_PUT, CONFIG_NSH_DISABLE_PWD, CONFIG_NSH_DISABLE_REBOOT,
CONFIG_NSH_DISABLE_RM, CONFIG_NSH_DISABLE_RMDIR, CONFIG_NSH_DISABLE_SET,
CONFIG_NSH_DISABLE_SH, CONFIG_NSH_DISABLE_SHUTDOWN, CONFIG_NSH_DISABLE_SLEEP,
CONFIG_NSH_DISABLE_TEST, CONFIG_NSH_DIABLE_TIME, CONFIG_NSH_DISABLE_UMOUNT,
CONFIG_NSH_DISABLE_UNSET, CONFIG_NSH_DISABLE_URLDECODE, CONFIG_NSH_DISABLE_URLENCODE,
CONFIG_NSH_DISABLE_USERADD, CONFIG_NSH_DISABLE_USERDEL, CONFIG_NSH_DISABLE_USLEEP,
CONFIG_NSH_DISABLE_WGET, CONFIG_NSH_DISABLE_XD
CONFIG_NSH_DISABLE_PUT, CONFIG_NSH_DISABLE_PWD, CONFIG_NSH_DISABLE_READLINK,
CONFIG_NSH_DISABLE_REBOOT, CONFIG_NSH_DISABLE_RM, CONFIG_NSH_DISABLE_RMDIR,
CONFIG_NSH_DISABLE_SET, CONFIG_NSH_DISABLE_SH, CONFIG_NSH_DISABLE_SHUTDOWN,
CONFIG_NSH_DISABLE_SLEEP, CONFIG_NSH_DISABLE_TEST, CONFIG_NSH_DIABLE_TIME,
CONFIG_NSH_DISABLE_UMOUNT, CONFIG_NSH_DISABLE_UNSET, CONFIG_NSH_DISABLE_URLDECODE,
CONFIG_NSH_DISABLE_URLENCODE, CONFIG_NSH_DISABLE_USERADD, CONFIG_NSH_DISABLE_USERDEL,
CONFIG_NSH_DISABLE_USLEEP, CONFIG_NSH_DISABLE_WGET, CONFIG_NSH_DISABLE_XD
Verbose help output can be suppressed by defining CONFIG_NSH_HELP_TERSE. In that
case, the help command is still available but will be slightly smaller.

View File

@ -1017,6 +1017,9 @@ int cmd_lsmod(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
# if defined(CONFIG_RAMLOG_SYSLOG) && !defined(CONFIG_NSH_DISABLE_DMESG)
int cmd_dmesg(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
# endif
# if !defined(CONFIG_NSH_DISABLE_READLINK) && defined(CONFIG_PSEUDOFS_SOFTLINKS)
int cmd_readlink(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
# endif
# if CONFIG_NFILE_STREAMS > 0 && !defined(CONFIG_NSH_DISABLESCRIPT)
# ifndef CONFIG_NSH_DISABLE_SH
int cmd_sh(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);

View File

@ -410,6 +410,12 @@ static const struct cmdmap_s g_cmdmap[] =
# endif
#endif
#if CONFIG_NFILE_DESCRIPTORS > 0
# if !defined(CONFIG_NSH_DISABLE_READLINK) && defined(CONFIG_PSEUDOFS_SOFTLINKS)
{ "readlink", cmd_readlink, 2, 2, "<link>" },
# endif
#endif
#if defined(CONFIG_BOARDCTL_RESET) && !defined(CONFIG_NSH_DISABLE_REBOOT)
{ "reboot", cmd_reboot, 1, 1, NULL },
#endif

View File

@ -1542,6 +1542,41 @@ errout_with_oldpath:
#endif
#endif
/****************************************************************************
* Name: cmd_readlink
****************************************************************************/
#if CONFIG_NFILE_DESCRIPTORS > 0
# if !defined(CONFIG_NSH_DISABLE_READLINK) && defined(CONFIG_PSEUDOFS_SOFTLINKS)
int cmd_readlink(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{
FAR char *fullpath;
ssize_t len;
/* readlink <link> */
/* Get the fullpath to the directory */
fullpath = nsh_getfullpath(vtbl, argv[1]);
if (!fullpath)
{
return ERROR;
}
len = readlink(fullpath, vtbl->iobuffer, IOBUFFERSIZE);
nsh_freefullpath(fullpath);
if (len < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, "ls", "readlink", NSH_ERRNO);
return ERROR;
}
nsh_output(vtbl, "%s\n", vtbl->iobuffer);
return OK;
}
#endif
#endif
/****************************************************************************
* Name: cmd_rm
****************************************************************************/