diff --git a/ChangeLog b/ChangeLog index 99b3df08f56..04d47cfc1b6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -553,4 +553,5 @@ * Added a block to character (BCH) driver. This is kind of the reverse of the loop device; it allows you access a block device like a character device. * Added strcasecmp() and strncasecmp() - * NSH: Added 'dd' command + * NSH: Added the 'dd' command + * NSH: Added the 'losetup' command diff --git a/Documentation/NuttShell.html b/Documentation/NuttShell.html index 9418056eb9e..c873c79b95f 100644 --- a/Documentation/NuttShell.html +++ b/Documentation/NuttShell.html @@ -1,6 +1,6 @@ -NuttX +NuttShell

@@ -149,127 +149,133 @@
- 2.12 List Directory Contents (ls) + 2.12 Setup/teardown the Loop Device (losetup)
- 2.13 Access Memory (mb, mh, and mw) + 2.13 List Directory Contents (ls)
- 2.14 Show Memory Manager Status (mem) + 2.14 Access Memory (mb, mh, and mw)
- 2.15 Show Current Tasks and Threads (ps) + 2.15 Show Memory Manager Status (mem)
- 2.16 Create a Directory (mkdir) + 2.16 Show Current Tasks and Threads (ps)
- 2.17 Create a FAT Filesystem (mkfatfs) + 2.17 Create a Directory (mkdir)
- 2.18 Create a FIFO (mkfifo) + 2.18 Create a FAT Filesystem (mkfatfs)
- 2.19 Create a RAMDISK (mkrd) + 2.19 Create a FIFO (mkfifo)
- 2.20 Mount a File System (mount) + 2.20 Create a RAMDISK (mkrd)
- 2.21 Check Network Peer (ping) + 2.21 Mount a File System (mount)
- 2.22 Send File Via TFTP (put) + 2.22 Check Network Peer (ping)
- 2.23 Show Current Working Directory (pwd) + 2.23 Send File Via TFTP (put)
- 2.24 Remove a File (rm) + 2.24 Show Current Working Directory (pwd)
- 2.25 Remove a Directory (rmdir) + 2.25 Remove a File (rm)
- 2.26 Set an Environment Variable (set) + 2.26 Remove a Directory (rmdir)
- 2.27 Execute an NSH Script (sh) + 2.27 Set an Environment Variable (set)
- 2.28 Wait for Seconds (sleep) + 2.28 Execute an NSH Script (sh)
- 2.29 Unmount a File System (umount) + 2.29 Wait for Seconds (sleep)
- 2.30 Unset an Environment Variable (unset) + 2.30 Unmount a File System (umount)
- 2.31 Wait for Microseconds (usleep) + 2.31 Unset an Environment Variable (unset)
- 2.32 Hexadecimal Dump (xd) + 2.32 Wait for Microseconds (usleep) + + + +
+ + 2.33 Hexadecimal Dump (xd) @@ -936,7 +942,33 @@ eth0 HWaddr 00:18:11:80:10:06 + +
-

2.12 List Directory Contents (ls)

+

2.12 Setup/teardown the Loop Device (losetup)

+
+ +Command Syntax 1:

+ +

+ Synopsis. + Setup the loop device at <dev-path> to access the file at <file-path> as a block device: +

+ +
Command Syntax 2:

+ +

+ Synopsis. + Teardown the setup for the loop device at <dev-path>. +

+ + + +
+

2.13 List Directory Contents (ls)

@@ -973,7 +1005,7 @@ ls [-lRs] <dir-path>
-

2.13 Access Memory (mb, mh, and mw)

+

2.14 Access Memory (mb, mh, and mw)

@@ -1027,7 +1059,7 @@ nsh>
-

2.14 Show Memory Manager Status (mem)

+

2.15 Show Memory Manager Status (mem)

@@ -1076,7 +1108,7 @@ nsh>
-

2.15 Show Current Tasks and Threads (ps)

+

2.16 Show Current Tasks and Threads (ps)

@@ -1102,7 +1134,7 @@ nsh>
-

2.16 Create a Directory (mkdir)

+

2.17 Create a Directory (mkdir)

@@ -1137,7 +1169,7 @@ nsh>
-

2.17 Create a FAT Filesystem (mkfatfs)

+

2.18 Create a FAT Filesystem (mkfatfs)

@@ -1157,7 +1189,7 @@ mkfatfs <path>
-

2.18 Create a FIFO (mkfifo)

+

2.19 Create a FIFO (mkfifo)

@@ -1195,7 +1227,7 @@ nsh>
-

2.19 Create a RAMDISK (mkrd)

+

2.20 Create a RAMDISK (mkrd)

@@ -1246,7 +1278,7 @@ nsh>
-

2.20 Mount a File System (mount)

+

2.21 Mount a File System (mount)

@@ -1313,7 +1345,7 @@ nsh>
-

2.21 Check Network Peer (ping)

+

2.22 Check Network Peer (ping)

@@ -1346,7 +1378,7 @@ nsh>
-

2.22 Send File Via TFTP (put)

+

2.23 Send File Via TFTP (put)

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

2.23 Show Current Working Directory (pwd)

+

2.24 Show Current Working Directory (pwd)

@@ -1411,7 +1443,7 @@ nsh>
-

2.24 Remove a File (rm)

+

2.25 Remove a File (rm)

@@ -1445,7 +1477,7 @@ nsh>
-

2.25 Remove a Directory (rmdir)

+

2.26 Remove a Directory (rmdir)

@@ -1480,7 +1512,7 @@ nsh>
-

2.26 Set an Environment Variable (set)

+

2.27 Set an Environment Variable (set)

@@ -1506,7 +1538,7 @@ nsh>
-

2.27 Execute an NSH Script (sh)

+

2.28 Execute an NSH Script (sh)

@@ -1524,7 +1556,7 @@ sh <script-path>
-

2.28 Wait for Seconds (sleep)

+

2.29 Wait for Seconds (sleep)

@@ -1541,7 +1573,7 @@ sleep <sec>
-

2.29 Unmount a File System (umount)

+

2.30 Unmount a File System (umount)

@@ -1571,7 +1603,7 @@ nsh>
-

2.30 Unset an Environment Variable (unset)

+

2.31 Unset an Environment Variable (unset)

@@ -1597,7 +1629,7 @@ nsh>
-

2.31 Wait for Microseconds (usleep)

+

2.32 Wait for Microseconds (usleep)

@@ -1614,7 +1646,7 @@ usleep <usec>
-

2.32 Hexadecimal dump (xd)

+

2.33 Hexadecimal dump (xd)

@@ -1733,6 +1765,11 @@ nsh> CONFIG_NET CONFIG_EXAMPLES_NSH_DISABLE_IFCONFIG + + losetup + !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 + CONFIG_EXAMPLES_NSH_DISABLE_LOSETUP + ls CONFIG_NFILE_DESCRIPTORS > 0 @@ -2159,6 +2196,7 @@ nsh>
  • help
  • if-then[-else]-fi
  • ifconfig
  • +
  • losetup
  • ls
  • mb
  • mh
  • diff --git a/Documentation/NuttX.html b/Documentation/NuttX.html index a26f2e55e8c..6bb9c58c3d6 100644 --- a/Documentation/NuttX.html +++ b/Documentation/NuttX.html @@ -1195,7 +1195,8 @@ nuttx-0.3.18 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> into very small memory footprints. * Added a block to character (BCH) driver. This is kind of the reverse of the loop device; it allows you access a block device like a character device. - * NSH: Added 'dd' command + * NSH: Added the 'dd' command + * NSH: Added the 'losetup' command pascal-0.1.3 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> diff --git a/examples/nsh/README.txt b/examples/nsh/README.txt index 9ea04640993..a34b03da971 100644 --- a/examples/nsh/README.txt +++ b/examples/nsh/README.txt @@ -328,6 +328,19 @@ o ifconfig if uIP statistics are enabled (CONFIG_NET_STATISTICS), then this command will also show the detailed state of uIP. +o losetup [-d ] | [[-o ] [-r] ] + + Setup or teardown the loop device: + + 1. Teardown the setup for the loop device at : + + losetup d + + 2. Setup the loop device at to access the file at + as a block device: + + losetup [-o ] [-r] + o ls [-lRs] Show the contents of the directory at . NOTE: @@ -721,6 +734,7 @@ Command Dependencies on Configuration Settings get CONFIG_NET && CONFIG_NET_UDP && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NET_BUFSIZE >= 558 (see note 1) help -- ifconfig CONFIG_NET + losetup !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 ls CONFIG_NFILE_DESCRIPTORS > 0 mb,mh,mw --- mem --- @@ -762,15 +776,15 @@ also allow it to squeeze into very small memory footprints. CONFIG_EXAMPLES_NSH_DISABLE_CAT, CONFIG_EXAMPLES_NSH_DISABLE_CD, CONFIG_EXAMPLES_NSH_DISABLE_CP, CONFIG_EXAMPLES_NSH_DISABLE_DD, CONFIG_EXAMPLES_NSH_DISABLE_ECHO, CONFIG_EXAMPLES_NSH_DISABLE_EXEC, CONFIG_EXAMPLES_NSH_DISABLE_EXIT, CONFIG_EXAMPLES_NSH_DISABLE_GET, CONFIG_EXAMPLES_NSH_DISABLE_HELP, - CONFIG_EXAMPLES_NSH_DISABLE_IFCONFIG, CONFIG_EXAMPLES_NSH_DISABLE_LS, CONFIG_EXAMPLES_NSH_DISABLE_MB, - CONFIG_EXAMPLES_NSH_DISABLE_MEM, CONFIG_EXAMPLES_NSH_DISABLE_MKDIR, CONFIG_EXAMPLES_NSH_DISABLE_MKFATFS, - CONFIG_EXAMPLES_NSH_DISABLE_MKFIFO, CONFIG_EXAMPLES_NSH_DISABLE_MKRD, CONFIG_EXAMPLES_NSH_DISABLE_MH, - CONFIG_EXAMPLES_NSH_DISABLE_MOUNT, CONFIG_EXAMPLES_NSH_DISABLE_MW, CONFIG_EXAMPLES_NSH_DISABLE_PS, - CONFIG_EXAMPLES_NSH_DISABLE_PING, CONFIG_EXAMPLES_NSH_DISABLE_PUT, CONFIG_EXAMPLES_NSH_DISABLE_PWD, - CONFIG_EXAMPLES_NSH_DISABLE_RM, CONFIG_EXAMPLES_NSH_DISABLE_RMDIR, CONFIG_EXAMPLES_NSH_DISABLE_SET, - CONFIG_EXAMPLES_NSH_DISABLE_SH, CONFIG_EXAMPLES_NSH_DISABLE_SLEEP, CONFIG_EXAMPLES_NSH_DISABLE_TEST, - CONFIG_EXAMPLES_NSH_DISABLE_UMOUNT, CONFIG_EXAMPLES_NSH_DISABLE_UNSET, CONFIG_EXAMPLES_NSH_DISABLE_USLEEP, - CONFIG_EXAMPLES_NSH_DISABLE_XD + CONFIG_EXAMPLES_NSH_DISABLE_IFCONFIG, CONFIG_EXAMPLES_NSH_DISABLE_LOSETUP, CONFIG_EXAMPLES_NSH_DISABLE_LS, + CONFIG_EXAMPLES_NSH_DISABLE_MB, CONFIG_EXAMPLES_NSH_DISABLE_MEM, CONFIG_EXAMPLES_NSH_DISABLE_MKDIR, + CONFIG_EXAMPLES_NSH_DISABLE_MKFATFS, CONFIG_EXAMPLES_NSH_DISABLE_MKFIFO, CONFIG_EXAMPLES_NSH_DISABLE_MKRD, + CONFIG_EXAMPLES_NSH_DISABLE_MH, CONFIG_EXAMPLES_NSH_DISABLE_MOUNT, CONFIG_EXAMPLES_NSH_DISABLE_MW, + CONFIG_EXAMPLES_NSH_DISABLE_PS, CONFIG_EXAMPLES_NSH_DISABLE_PING, CONFIG_EXAMPLES_NSH_DISABLE_PUT, + CONFIG_EXAMPLES_NSH_DISABLE_PWD, CONFIG_EXAMPLES_NSH_DISABLE_RM, CONFIG_EXAMPLES_NSH_DISABLE_RMDIR, + CONFIG_EXAMPLES_NSH_DISABLE_SET, CONFIG_EXAMPLES_NSH_DISABLE_SH, CONFIG_EXAMPLES_NSH_DISABLE_SLEEP, + CONFIG_EXAMPLES_NSH_DISABLE_TEST, CONFIG_EXAMPLES_NSH_DISABLE_UMOUNT, CONFIG_EXAMPLES_NSH_DISABLE_UNSET, + CONFIG_EXAMPLES_NSH_DISABLE_USLEEP, CONFIG_EXAMPLES_NSH_DISABLE_XD NSH-Specific Configuration Settings ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/examples/nsh/nsh.h b/examples/nsh/nsh.h index 825ea6554ff..32a0c934d59 100644 --- a/examples/nsh/nsh.h +++ b/examples/nsh/nsh.h @@ -378,6 +378,9 @@ extern int cmd_lbracket(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); # endif # endif /* CONFIG_NFILE_STREAMS && !CONFIG_EXAMPLES_NSH_DISABLESCRIPT */ # ifndef CONFIG_DISABLE_MOUNTPOINT +# ifndef CONFIG_EXAMPLES_NSH_DISABLE_LOSETUP + extern int cmd_losetup(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +# endif # ifndef CONFIG_EXAMPLES_NSH_DISABLE_MKFIFO extern int cmd_mkfifo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); # endif diff --git a/examples/nsh/nsh_fscmds.c b/examples/nsh/nsh_fscmds.c index 8dcf9037217..301abddbb1c 100644 --- a/examples/nsh/nsh_fscmds.c +++ b/examples/nsh/nsh_fscmds.c @@ -647,6 +647,128 @@ errout: #endif #endif +/**************************************************************************** + * Name: cmd_losetup + ****************************************************************************/ + +#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) +#ifndef CONFIG_EXAMPLES_NSH_DISABLE_LOSETUP +int cmd_losetup(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) +{ + char *loopdev = NULL; + char *filepath = NULL; + boolean teardown = FALSE; + boolean readonly = FALSE; + off_t offset = 0; + int ret = ERROR; + int option; + + /* Get the losetup options: Two forms are supported: + * + * losetup -d + * losetup [-o ] [-r] + * + * NOTE that the -o and -r options are accepted with the -d option, but + * will be ignored. + */ + + while ((option = getopt(argc, argv, "d:o:r")) != ERROR) + { + switch (option) + { + case 'd': + loopdev = nsh_getfullpath(vtbl, optarg); + teardown = TRUE; + break; + + case 'o': + offset = atoi(optarg); + break; + + case 'r': + readonly = TRUE; + break; + + case '?': + default: + nsh_output(vtbl, g_fmtarginvalid, argv[0]); + return ERROR; + } + } + + /* If this is not a tear down operation, then additional command line + * parameters are required. + */ + + if (!teardown) + { + /* There must be two arguments on the command line after the options */ + + if (optind + 1 < argc) + { + loopdev = nsh_getfullpath(vtbl, argv[optind]); + optind++; + + filepath = nsh_getfullpath(vtbl, argv[optind]); + optind++; + } + else + { + nsh_output(vtbl, g_fmtargrequired, argv[0]); + goto errout_with_paths; + } + } + + /* There should be nothing else on the command line */ + + if (optind < argc) + { + nsh_output(vtbl, g_fmttoomanyargs, argv[0]); + goto errout_with_paths; + } + + /* Perform the teardown operation */ + + if (teardown) + { + /* Tear down the loop device. */ + + ret = loteardown(loopdev); + if (ret < 0) + { + nsh_output(vtbl, g_fmtcmdfailed, argv[0], "loteardown", NSH_ERRNO_OF(-ret)); + goto errout_with_paths; + } + } + else + { + /* Set up the loop device */ + + ret = losetup(loopdev, filepath, 512, offset, readonly); + if (ret < 0) + { + nsh_output(vtbl, g_fmtcmdfailed, argv[0], "losetup", NSH_ERRNO_OF(-ret)); + goto errout_with_paths; + } + } + + /* Free memory */ + +errout_with_paths: + if (loopdev) + { + free(loopdev); + } + + if (filepath) + { + free(filepath); + } + return ret; +} +#endif +#endif + /**************************************************************************** * Name: cmd_ls ****************************************************************************/ diff --git a/examples/nsh/nsh_main.c b/examples/nsh/nsh_main.c index 14b1afb55bd..db116b5c055 100644 --- a/examples/nsh/nsh_main.c +++ b/examples/nsh/nsh_main.c @@ -188,6 +188,12 @@ static const struct cmdmap_s g_cmdmap[] = # endif #endif +#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) +# ifndef CONFIG_EXAMPLES_NSH_DISABLE_LOSETUP + { "losetup", cmd_losetup, 3, 6, "[-d ] | [[-o ] [-r] ]" }, +# endif +#endif + #if CONFIG_NFILE_DESCRIPTORS > 0 # ifndef CONFIG_EXAMPLES_NSH_DISABLE_LS { "ls", cmd_ls, 1, 5, "[-lRs] " },