NSH: Add support for the 'ln' command.
This commit is contained in:
parent
3ab2aec4e8
commit
2ac55ec4e7
@ -316,6 +316,11 @@ config NSH_DISABLE_LOSMART
|
||||
default y if DEFAULT_SMALL || !MTD_SMART
|
||||
default n if !DEFAULT_SMALL && MTD_SMART
|
||||
|
||||
config NSH_DISABLE_LN
|
||||
bool "Disable ln"
|
||||
default n
|
||||
depends on PSEUDOFS_SOFTLINKS
|
||||
|
||||
config NSH_DISABLE_LS
|
||||
bool "Disable ls"
|
||||
default n
|
||||
|
@ -613,6 +613,19 @@ o losetup [-d <dev-path>] | [[-o <offset>] [-r] <ldev-path> <file-path>]
|
||||
This is a test
|
||||
nsh>
|
||||
|
||||
o ln [-s] <target> <link>
|
||||
|
||||
The link command will create a new symbolic link at <link> for the
|
||||
existing file or directory, <target>. This implementation is simplied
|
||||
for use with NuttX in these ways:
|
||||
|
||||
- Links may be created only within the NuttX top-level, pseudo file
|
||||
system. No file system currently supported by NuttX provides
|
||||
symbolic links.
|
||||
- For the same reason, only soft links are implemented.
|
||||
- File privileges are ignored.
|
||||
- c_time is not updated.
|
||||
|
||||
o ls [-lRs] <dir-path>
|
||||
|
||||
Show the contents of the directory at <dir-path>. NOTE:
|
||||
@ -1195,6 +1208,7 @@ Command Dependencies on Configuration Settings
|
||||
insmod CONFIG_MODULE
|
||||
kill !CONFIG_DISABLE_SIGNALS
|
||||
losetup !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_DEV_LOOP
|
||||
ln CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_PSEUDOFS_SOFTLINK
|
||||
ls CONFIG_NFILE_DESCRIPTORS > 0
|
||||
lsmod CONFIG_MODULE && CONFIG_FS_PROCFS && !CONFIG_FS_PROCFS_EXCLUDE_MODULE
|
||||
md5 CONFIG_NETUTILS_CODECS && CONFIG_CODECS_HASH_MD5
|
||||
@ -1257,20 +1271,20 @@ also allow it to squeeze into very small memory footprints.
|
||||
CONFIG_NSH_DISABLE_EXEC, CONFIG_NSH_DISABLE_EXIT, CONFIG_NSH_DISABLE_FREE,
|
||||
CONFIG_NSH_DISABLE_GET, CONFIG_NSH_DISABLE_HELP, CONFIG_NSH_DISABLE_HEXDUMP,
|
||||
CONFIG_NSH_DISABLE_IFCONFIG, CONFIG_NSH_DISABLE_IFUPDOWN, CONFIG_NSH_DISABLE_KILL,
|
||||
CONFIG_NSH_DISABLE_LOSETUP, CONFIG_NSH_DISABLE_LS, CONFIG_NSH_DISABLE_MD5,
|
||||
CONFIG_NSH_DISABLE_MB, CONFIG_NSH_DISABLE_MKDIR, CONFIG_NSH_DISABLE_MKFATFS,
|
||||
CONFIG_NSH_DISABLE_MKFIFO, CONFIG_NSH_DISABLE_MKRD, CONFIG_NSH_DISABLE_MH,
|
||||
CONFIG_NSH_DISABLE_MODCMDS, CONFIG_NSH_DISABLE_MOUNT, 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_LOSETUP, CONFIG_NSH_DISABLE_LN, CONFIG_NSH_DISABLE_LS,
|
||||
CONFIG_NSH_DISABLE_MD5, CONFIG_NSH_DISABLE_MB, CONFIG_NSH_DISABLE_MKDIR,
|
||||
CONFIG_NSH_DISABLE_MKFATFS, CONFIG_NSH_DISABLE_MKFIFO, CONFIG_NSH_DISABLE_MKRD,
|
||||
CONFIG_NSH_DISABLE_MH, CONFIG_NSH_DISABLE_MODCMDS, CONFIG_NSH_DISABLE_MOUNT,
|
||||
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
|
||||
|
||||
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.
|
||||
|
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* apps/nshlib/nsh.h
|
||||
*
|
||||
* Copyright (C) 2007-2016 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2007-2017 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -1008,6 +1008,9 @@ int cmd_lsmod(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
# ifndef CONFIG_NSH_DISABLE_HEXDUMP
|
||||
int cmd_hexdump(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
# endif
|
||||
# if !defined(CONFIG_NSH_DISABLE_LN) && defined(CONFIG_PSEUDOFS_SOFTLINKS)
|
||||
int cmd_ln(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
# endif
|
||||
# ifndef CONFIG_NSH_DISABLE_LS
|
||||
int cmd_ls(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
# endif
|
||||
|
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* apps/nshlib/nsh_command.c
|
||||
*
|
||||
* Copyright (C) 2007-2016 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2007-2017 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -270,6 +270,12 @@ static const struct cmdmap_s g_cmdmap[] =
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
# if !defined(CONFIG_NSH_DISABLE_LN) && defined(CONFIG_PSEUDOFS_SOFTLINKS)
|
||||
{ "ln", cmd_ln, 3, 4, "[-s] <target> <link>" },
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
# ifndef CONFIG_NSH_DISABLE_LS
|
||||
{ "ls", cmd_ls, 1, 5, "[-lRs] <dir-path>" },
|
||||
@ -278,7 +284,7 @@ static const struct cmdmap_s g_cmdmap[] =
|
||||
|
||||
#if defined(CONFIG_MODULE) && !defined(CONFIG_NSH_DISABLE_MODCMDS)
|
||||
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE)
|
||||
{ "lsmod", cmd_lsmod, 1, 1, NULL },
|
||||
{ "lsmod", cmd_lsmod, 1, 1, NULL },
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* apps/nshlib/nsh_fscmds.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2011-2014 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2007-2009, 2011-2014, 2017 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -936,6 +936,59 @@ errout_with_paths:
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: cmd_ln
|
||||
****************************************************************************/
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
# if !defined(CONFIG_NSH_DISABLE_LN) && defined(CONFIG_PSEUDOFS_SOFTLINKS)
|
||||
int cmd_ln(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
FAR char *fullpath;
|
||||
FAR char *target;
|
||||
int ndx;
|
||||
int ret;
|
||||
|
||||
/* ln [-s] <target> <link> */
|
||||
|
||||
if (argc == 4)
|
||||
{
|
||||
if (strcmp(argv[1], "-s") != 0)
|
||||
{
|
||||
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
ndx = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
ndx = 1;
|
||||
}
|
||||
|
||||
/* Get the fullpath to the directory */
|
||||
|
||||
target = argv[ndx];
|
||||
fullpath = nsh_getfullpath(vtbl, argv[ndx + 1]);
|
||||
|
||||
if (!fullpath)
|
||||
{
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
ret = link(target, fullpath);
|
||||
if (ret < 0)
|
||||
{
|
||||
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "link", NSH_ERRNO);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
nsh_freefullpath(fullpath);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: cmd_ls
|
||||
****************************************************************************/
|
||||
@ -945,9 +998,9 @@ errout_with_paths:
|
||||
int cmd_ls(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
struct stat st;
|
||||
const char *relpath;
|
||||
FAR const char *relpath;
|
||||
unsigned int lsflags = 0;
|
||||
char *fullpath;
|
||||
FAR char *fullpath;
|
||||
bool badarg = false;
|
||||
int len;
|
||||
int ret;
|
||||
@ -1083,6 +1136,7 @@ int cmd_mkdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
|
||||
nsh_freefullpath(fullpath);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user