From b39d96202162b5d431f175c5ee4aa3fa23d473c1 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 2 Feb 2017 17:11:08 -0600 Subject: [PATCH] Soft links: Update Documentation, rename file, add system calls --- Documentation/NuttShell.html | 198 ++++++++++++++++------------ arch/sim/src/nuttx-names.dat | 1 + fs/Makefile | 2 +- fs/vfs/Make.defs | 6 +- fs/vfs/{fs_softlink.c => fs_link.c} | 21 +-- include/nuttx/fs/fs.h | 2 +- include/sys/syscall.h | 15 ++- syscall/syscall.csv | 1 + syscall/syscall_lookup.h | 4 + syscall/syscall_stublookup.c | 2 + 10 files changed, 147 insertions(+), 105 deletions(-) rename fs/vfs/{fs_softlink.c => fs_link.c} (90%) diff --git a/Documentation/NuttShell.html b/Documentation/NuttShell.html index 1d284dbea7a..8e4b2957d33 100644 --- a/Documentation/NuttShell.html +++ b/Documentation/NuttShell.html @@ -8,7 +8,7 @@

NuttShell (NSH)

-

Last Updated: August 4, 2016

+

Last Updated: February 2, 2017

@@ -263,223 +263,229 @@
- 2.30 List Directory Contents (ls) + 2.30 List to a File or Directory (ln)
- 2.31 Show information about installed OS modules (lsmod) + 2.31 List Directory Contents (ls)
- 2.32 Calculate MD5 (md5) + 2.32 Show information about installed OS modules (lsmod)
- 2.33 Access Memory (mb, mh, and mw) + 2.33 Calculate MD5 (md5)
- 2.34 Show Current Tasks and Threads (ps) + 2.34 Access Memory (mb, mh, and mw)
- 2.35 Create a Directory (mkdir) + 2.35 Show Current Tasks and Threads (ps)
- 2.36 Create a FAT Filesystem (mkfatfs) + 2.36 Create a Directory (mkdir)
- 2.37 Create a FIFO (mkfifo) + 2.37 Create a FAT Filesystem (mkfatfs)
- 2.38 Create a RAMDISK (mkrd) + 2.38 Create a FIFO (mkfifo)
- 2.39 Mount a File System (mount) + 2.39 Create a RAMDISK (mkrd)
- 2.40 Rename a File (mv) + 2.40 Mount a File System (mount)
- 2.41 Mount an NFS file system (nfsmount) + 2.41 Rename a File (mv)
- 2.42 Lookup a network address (nslookup) + 2.42 Mount an NFS file system (nfsmount)
- 2.43 Change a User's Password (passwd) + 2.43 Lookup a network address (nslookup)
- 2.44 Check Network Peer (ping/ping6) + 2.44 Change a User's Password (passwd)
- 2.45 Shut the system down (poweroff) + 2.45 Check Network Peer (ping/ping6)
- 2.46 Send File Via TFTP (put) + 2.46 Shut the system down (poweroff)
- 2.47 Show Current Working Directory (pwd) + 2.47 Send File Via TFTP (put)
- 2.48 Reset and reboot the system (reboot) + 2.48 Show Current Working Directory (pwd)
- 2.49 Remove a File (rm) + 2.49 Reset and reboot the system (reboot)
- 2.50 Remove a Directory (rmdir) + 2.50 Remove a File (rm)
- 2.51 Remove on OS Module (rmmod) + 2.51 Remove a Directory (rmdir)
- 2.52 Set an Environment Variable (set) + 2.52 Remove on OS Module (rmmod)
- 2.53 Execute an NSH Script (sh) + 2.53 Set an Environment Variable (set)
- 2.54 Shut the system down (shutdown) + 2.54 Execute an NSH Script (sh)
- 2.55 Wait for Seconds (sleep) + 2.55 Shut the system down (shutdown)
- 2.56 Time execution of another command (time) + 2.56 Wait for Seconds (sleep)
- 2.57 Unmount a File System (umount) + 2.57 Time execution of another command (time)
- 2.58 Print system information (uname) + 2.58 Unmount a File System (umount)
- 2.59 Unset an Environment Variable (unset) + 2.59 Print system information (uname)
- 2.60 URL Decode (urldecode) + 2.60 Unset an Environment Variable (unset)
- 2.61 URL Encode (urlencode) + 2.61 URL Decode (urldecode)
- 2.62 Add a New User (useradd) + 2.62 URL Encode (urlencode)
- 2.63 Delete a user (userdel) + 2.63 Add a New User (useradd)
- 2.64 Wait for Microseconds (usleep) + 2.64 Delete a user (userdel)
- 2.65 Get File Via HTTP (wget) + 2.65 Wait for Microseconds (usleep)
- 2.66 Hexadecimal Dump of Memory (xd) + 2.66 Get File Via HTTP (wget) + + + +
+ + 2.67 Hexadecimal Dump of Memory (xd) @@ -1681,13 +1687,6 @@ hexdump <file or device> Dump data in hexadecimal format from a file or character device.

- -
- - - - - + + + + + - + @@ -5165,10 +5194,10 @@ xxd -i romfs_img >nsh_romfsimg.h
  • CONFIG_NSH_ROMFSETC
  • CONFIG_NSH_ARCHROMFS
  • CONFIG_NSH_ROMFSMOUNTPT
  • +
  • CONFIG_NSH_ROMFSSECTSIZE
  • @@ -1937,7 +1936,32 @@ losetup d <dev-path> + +
    -

    2.30 List Directory Contents (ls)

    +

    2.30 List to a File or Directory (ln)

    +
    + +

    Command Syntax:

    +
      +link [-s] <target> <link>
      +
    +

    + Synopsis. + 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.
    • +
    + + + +
    +

    2.31 List Directory Contents (ls)

    @@ -1975,7 +1999,7 @@ ls [-lRs] <dir-path>
    -

    2.31 Show information about installed OS modules (lsmod)

    +

    2.32 Show information about installed OS modules (lsmod)

    @@ -2008,7 +2032,7 @@ mydriver 20404659 20404625 0 20404580 552 204047a8 0
    -

    2.32 Calculate MD5 (md5)

    +

    2.33 Calculate MD5 (md5)

    @@ -2025,7 +2049,7 @@ md5 [-f] <string or filepath>
    -

    2.33 Access Memory (mb, mh, and mw)

    +

    2.34 Access Memory (mb, mh, and mw)

    @@ -2079,7 +2103,7 @@ nsh>
    -

    2.34 Show Current Tasks and Threads (ps)

    +

    2.35 Show Current Tasks and Threads (ps)

    @@ -2113,7 +2137,7 @@ nsh> mount -t procfs /proc
    -

    2.35 Create a Directory (mkdir)

    +

    2.36 Create a Directory (mkdir)

    @@ -2148,7 +2172,7 @@ nsh>
    -

    2.36 Create a FAT Filesystem (mkfatfs)

    +

    2.37 Create a FAT Filesystem (mkfatfs)

    @@ -2173,7 +2197,7 @@ mkfatfs [-F <fatsize>] <block-driver>
    -

    2.37 Create a FIFO (mkfifo)

    +

    2.38 Create a FIFO (mkfifo)

    @@ -2211,7 +2235,7 @@ nsh>
    -

    2.38 Create a RAMDISK (mkrd)

    +

    2.39 Create a RAMDISK (mkrd)

    @@ -2262,7 +2286,7 @@ nsh>
    -

    2.39 Mount a File System (mount)

    +

    2.40 Mount a File System (mount)

    @@ -2341,7 +2365,7 @@ nsh> mount
    -

    2.40 Rename a File (mv)

    +

    2.41 Rename a File (mv)

    @@ -2359,7 +2383,7 @@ mv <old-path> <new-path>
    -

    2.41 Mount an NFS file system (nfsmount)

    +

    2.42 Mount an NFS file system (nfsmount)

    @@ -2378,7 +2402,7 @@ nfsmount <server-address> <mount-point> <remote-path>
    -

    2.42 Lookup a network address (nslookup)

    +

    2.43 Lookup a network address (nslookup)

    @@ -2395,7 +2419,7 @@ nslookup <host-name>
    -

    2.43 Change a User's Password (passwd)

    +

    2.44 Change a User's Password (passwd)

    @@ -2412,7 +2436,7 @@ passwd <username> <password>
    -

    2.44 Check Network Peer (ping/ping6)

    +

    2.45 Check Network Peer (ping/ping6)

    @@ -2449,7 +2473,7 @@ nsh>
    -

    2.45 Shut the system down (poweroff)

    +

    2.46 Shut the system down (poweroff)

    @@ -2471,7 +2495,7 @@ poweroff
    -

    2.46 Send File Via TFTP (put)

    +

    2.47 Send File Via TFTP (put)

    @@ -2506,7 +2530,7 @@ put [-b|-n] [-f <remote-path>] -h <ip-address> <local-path>
    -

    2.47 Show Current Working Directory (pwd)

    +

    2.48 Show Current Working Directory (pwd)

    @@ -2536,7 +2560,7 @@ nsh>
    -

    2.48 Reboot the system (reboot)

    +

    2.49 Reboot the system (reboot)

    @@ -2558,7 +2582,7 @@ reboot
    -

    2.49 Remove a File (rm)

    +

    2.50 Remove a File (rm)

    @@ -2592,7 +2616,7 @@ nsh>
    -

    2.50 Remove a Directory (rmdir)

    +

    2.51 Remove a Directory (rmdir)

    @@ -2627,7 +2651,7 @@ nsh>
    -

    2.51 Remove on OS Module (rmmod)

    +

    2.52 Remove on OS Module (rmmod)

    @@ -2655,7 +2679,7 @@ nsh>
    -

    2.52 Set an Environment Variable (set)

    +

    2.53 Set an Environment Variable (set)

    @@ -2681,7 +2705,7 @@ nsh>
    -

    2.53 Execute an NSH Script (sh)

    +

    2.54 Execute an NSH Script (sh)

    @@ -2700,7 +2724,7 @@ sh <script-path>
    -

    2.54 Shut the system down (shutdown)

    +

    2.55 Shut the system down (shutdown)

    @@ -2721,7 +2745,7 @@ shutdown [--reboot]
    -

    2.55 Wait for Seconds (sleep)

    +

    2.56 Wait for Seconds (sleep)

    @@ -2738,7 +2762,7 @@ sleep <sec>
    -

    2.56 Time execution of another command (time)

    +

    2.57 Time execution of another command (time)

    @@ -2797,7 +2821,7 @@ nsh>
    -

    2.57 Unmount a File System (umount)

    +

    2.58 Unmount a File System (umount)

    @@ -2827,7 +2851,7 @@ nsh>
    -

    2.58 Print system information (uname)

    +

    2.59 Print system information (uname)

    @@ -2894,7 +2918,7 @@ uname [-a | -imnoprsv]
    -

    2.59 Unset an Environment Variable (unset)

    +

    2.60 Unset an Environment Variable (unset)

    @@ -2920,7 +2944,7 @@ nsh>
    -

    2.60 URL Decode (urldecode)

    +

    2.61 URL Decode (urldecode)

    @@ -2937,7 +2961,7 @@ urldecode [-f] <string or filepath>
    -

    2.61 URL Encode (urlencode)

    +

    2.62 URL Encode (urlencode)

    @@ -2954,7 +2978,7 @@ urlencode [-f] <string or filepath>
    -

    2.62 Add a New User (useradd)

    +

    2.63 Add a New User (useradd)

    @@ -2971,7 +2995,7 @@ useradd <username> <password>
    -

    2.63 Delete a user (userdel)

    +

    2.64 Delete a user (userdel)

    @@ -2988,7 +3012,7 @@ userdel <username>
    -

    2.64 Wait for Microseconds (usleep)

    +

    2.65 Wait for Microseconds (usleep)

    @@ -3005,7 +3029,7 @@ usleep <usec>
    -

    2.65 Get File Via HTTP (wget)

    +

    2.66 Get File Via HTTP (wget)

    @@ -3032,7 +3056,7 @@ wget [-o <local-path>] <url>
    -

    2.66 Hexadecimal Dump of Memory (xd)

    +

    2.67 Hexadecimal Dump of Memory (xd)

    @@ -3241,10 +3265,15 @@ nsh>
    !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_DEV_LOOP CONFIG_NSH_DISABLE_LOSETUP
    lnCONFIG_NFILE_DESCRIPTORS > 0CONFIG_NSH_DISABLE_LL
    ls CONFIG_NFILE_DESCRIPTORS > 0CONFIG_NSH_DISABLE_LSCONFIG_NSH_DISABLE_LS && CONFIG_PSEUDOFS_SOFTLINKS
    lsmod
      -
    • CONFIG_NSH_ROMFSSECTSIZE
    • CONFIG_NSH_STRERROR
    • CONFIG_NSH_TELNET
    • CONFIG_NSH_TMPDIR
    • @@ -5218,6 +5247,7 @@ xxd -i romfs_img >nsh_romfsimg.h
    • insmod
    • kill
    • losetup
    • +
    • ln
    • ls
    • mb
    • Login
    • diff --git a/arch/sim/src/nuttx-names.dat b/arch/sim/src/nuttx-names.dat index f1373f1d9c1..bfede730667 100644 --- a/arch/sim/src/nuttx-names.dat +++ b/arch/sim/src/nuttx-names.dat @@ -32,6 +32,7 @@ gettimeofday NXgettimeofday ioctl NXioctl isatty NXisatty kill NXkill +link NXlink listen NXlisten lseek NXlseek mallinfo NXmallinfo diff --git a/fs/Makefile b/fs/Makefile index 5ef45f84ee2..6ab682d28f2 100644 --- a/fs/Makefile +++ b/fs/Makefile @@ -1,7 +1,7 @@ ############################################################################ # fs/Makefile # -# Copyright (C) 2007, 2008, 2011-2014, 2016 Gregory Nutt. All rights reserved. +# Copyright (C) 2007, 2008, 2011-2014, 2016-2017 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without diff --git a/fs/vfs/Make.defs b/fs/vfs/Make.defs index 9b5e6911afb..9209da62983 100644 --- a/fs/vfs/Make.defs +++ b/fs/vfs/Make.defs @@ -43,10 +43,6 @@ ifneq ($(CONFIG_NSOCKET_DESCRIPTORS),0) CSRCS += fs_close.c fs_read.c fs_write.c fs_ioctl.c -ifneq ($(CONFIG_PSEUDOFS_SOFTLINKS),0) -CSRCS += fs_softlink.c -endif - # Stream support ifneq ($(CONFIG_NFILE_STREAMS),0) @@ -91,7 +87,7 @@ endif CSRCS += fs_pread.c fs_pwrite.c ifneq ($(CONFIG_PSEUDOFS_SOFTLINKS),0) -CSRCS += fs_softlink.c +CSRCS += fs_link.c endif # Stream support diff --git a/fs/vfs/fs_softlink.c b/fs/vfs/fs_link.c similarity index 90% rename from fs/vfs/fs_softlink.c rename to fs/vfs/fs_link.c index b40a5ea9727..285db3bae8c 100644 --- a/fs/vfs/fs_softlink.c +++ b/fs/vfs/fs_link.c @@ -1,5 +1,5 @@ /**************************************************************************** - * fs/vfs/fs_softlink.c + * fs/vfs/fs_link.c * * Copyright (C) 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -64,7 +65,7 @@ * * Description: * The link() function will create a new link (directory entry) for the - * existing file, path1. This implementation is simplied for use with + * existing file, path2. This implementation is simplied for use with * NuttX in these ways: * * - Links may be created only within the NuttX top-level, pseudo file @@ -90,21 +91,21 @@ int link(FAR const char *path1, FAR const char *path2) int errcode; int ret; - /* Both paths must be absolute. We need only check path2 here. path1 will + /* Both paths must be absolute. We need only check path1 here. path2 will * be checked by inode find. */ - if (path2 == NULL || *path2 != '/') + if (path1 == NULL || *path1 != '/') { errcode = EINVAL; goto errout; } - /* Check that no inode exists at the 'path2' and that the path up to 'path2' + /* Check that no inode exists at the 'path1' and that the path up to 'path1' * does not lie on a mounted volume. */ - inode = inode_find(path1, NULL); + inode = inode_find(path2, NULL); if (inode != NULL) { #ifndef CONFIG_DISABLE_MOUNTPOINT @@ -119,7 +120,7 @@ int link(FAR const char *path1, FAR const char *path2) else #endif { - /* A node already exists in the pseudofs at 'path2' */ + /* A node already exists in the pseudofs at 'path1' */ errcode = EEXIST; } @@ -133,9 +134,9 @@ int link(FAR const char *path1, FAR const char *path2) else { - /* Copy path2 */ + /* Copy path1 */ - FAR char *newpath2 = strdup(path2); + FAR char *newpath2 = strdup(path1); if (newpath2 == NULL) { errcode = ENOMEM; @@ -148,7 +149,7 @@ int link(FAR const char *path1, FAR const char *path2) */ inode_semtake(); - ret = inode_reserve(path1, &inode); + ret = inode_reserve(path2, &inode); inode_semgive(); if (ret < 0) diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h index 584ccef287f..955d1b2c111 100644 --- a/include/nuttx/fs/fs.h +++ b/include/nuttx/fs/fs.h @@ -328,7 +328,7 @@ union inode_ops_u FAR struct mqueue_inode_s *i_mqueue; /* POSIX message queue */ #endif #ifdef CONFIG_PSEUDOFS_SOFTLINKS - FAR char *i_link; /* Full path to link */ + FAR char *i_link; /* Full path to link target */ #endif }; diff --git a/include/sys/syscall.h b/include/sys/syscall.h index eb53fdf9787..ac1dde570bf 100644 --- a/include/sys/syscall.h +++ b/include/sys/syscall.h @@ -323,11 +323,18 @@ # define SYS_statfs (__SYS_filedesc+12) # define SYS_telldir (__SYS_filedesc+13) -# if defined(CONFIG_PIPES) && CONFIG_DEV_PIPE_SIZE > 0 -# define SYS_pipe2 (__SYS_filedesc+14) -# define __SYS_mkfifo2 (__SYS_filedesc+15) +# if defined(CONFIG_PSEUDOFS_SOFTLINKS) +# define SYS_link (__SYS_filedesc+14) +# define __SYS_pipes (__SYS_filedesc+15) # else -# define __SYS_mkfifo2 (__SYS_filedesc+14) +# define __SYS_pipes (__SYS_filedesc+14) +# endif + +# if defined(CONFIG_PIPES) && CONFIG_DEV_PIPE_SIZE > 0 +# define SYS_pipe2 (__SYS_pipes+0) +# define __SYS_mkfifo2 (__SYS_pipes+1) +# else +# define __SYS_mkfifo2 (__SYS_pipes+0) # endif # if defined(CONFIG_PIPES) && CONFIG_DEV_FIFO_SIZE > 0 diff --git a/syscall/syscall.csv b/syscall/syscall.csv index 1b6917d5f38..d8ff96cf034 100644 --- a/syscall/syscall.csv +++ b/syscall/syscall.csv @@ -32,6 +32,7 @@ "insmod","nuttx/module.h","defined(CONFIG_MODULE)","FAR void *","FAR const char *","FAR const char *" "ioctl","sys/ioctl.h","!defined(CONFIG_LIBC_IOCTL_VARIADIC) && (CONFIG_NSOCKET_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0)","int","int","int","unsigned long" "kill","signal.h","!defined(CONFIG_DISABLE_SIGNALS)","int","pid_t","int" +"link","unistd.h","defined(CONFIG_PSEUDOFS_SOFTLINKS)","int","FAR const char *","FAR const char *" "listen","sys/socket.h","CONFIG_NSOCKET_DESCRIPTORS > 0 && defined(CONFIG_NET)","int","int","int" "lseek","unistd.h","CONFIG_NFILE_DESCRIPTORS > 0","off_t","int","off_t","int" "mkdir","sys/stat.h","CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT)","int","FAR const char*","mode_t" diff --git a/syscall/syscall_lookup.h b/syscall/syscall_lookup.h index f8286ca6b1d..b302a928296 100644 --- a/syscall/syscall_lookup.h +++ b/syscall/syscall_lookup.h @@ -232,6 +232,10 @@ SYSCALL_LOOKUP(up_assert, 2, STUB_up_assert) SYSCALL_LOOKUP(statfs, 2, STUB_statfs) SYSCALL_LOOKUP(telldir, 1, STUB_telldir) +# if defined(CONFIG_PSEUDOFS_SOFTLINKS) + SYSCALL_LOOKUP(link, 2, STUB_link) +# endif + # if defined(CONFIG_PIPES) && CONFIG_DEV_PIPE_SIZE > 0 SYSCALL_LOOKUP(pipe2, 2, STUB_pipe2) # endif diff --git a/syscall/syscall_stublookup.c b/syscall/syscall_stublookup.c index 59c4515ac40..950553c7425 100644 --- a/syscall/syscall_stublookup.c +++ b/syscall/syscall_stublookup.c @@ -238,6 +238,8 @@ uintptr_t STUB_stat(int nbr, uintptr_t parm1, uintptr_t parm2); uintptr_t STUB_statfs(int nbr, uintptr_t parm1, uintptr_t parm2); uintptr_t STUB_telldir(int nbr, uintptr_t parm1); +uintptr_t STUB_link(int nbr, uintptr_t parm1, uintptr_t parm2); + uintptr_t STUB_pipe2(int nbr, uintptr_t parm1, uintptr_t parm2); uintptr_t STUB_mkfifo2(int nbr, uintptr_t parm1, uintptr_t parm2, uintptr_t parm3);