summaryrefslogtreecommitdiff
path: root/nuttx/examples/nsh
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-11-15 17:42:49 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-11-15 17:42:49 +0000
commit1e6c726b328b77d54c11e91f965386f33dae19c0 (patch)
treee6a69479b45c26fdc47ece6f821d87eaa6e8776d /nuttx/examples/nsh
parent9334df87efdf6925fc6289cdca69e3e5ec81f118 (diff)
downloadpx4-nuttx-1e6c726b328b77d54c11e91f965386f33dae19c0.tar.gz
px4-nuttx-1e6c726b328b77d54c11e91f965386f33dae19c0.tar.bz2
px4-nuttx-1e6c726b328b77d54c11e91f965386f33dae19c0.zip
Add losetup to NSH
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1243 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/examples/nsh')
-rw-r--r--nuttx/examples/nsh/README.txt32
-rw-r--r--nuttx/examples/nsh/nsh.h3
-rw-r--r--nuttx/examples/nsh/nsh_fscmds.c122
-rw-r--r--nuttx/examples/nsh/nsh_main.c6
4 files changed, 154 insertions, 9 deletions
diff --git a/nuttx/examples/nsh/README.txt b/nuttx/examples/nsh/README.txt
index 9ea046409..a34b03da9 100644
--- a/nuttx/examples/nsh/README.txt
+++ b/nuttx/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 <dev-path>] | [[-o <offset>] [-r] <ldev-path> <file-path>]
+
+ Setup or teardown the loop device:
+
+ 1. Teardown the setup for the loop device at <dev-path>:
+
+ losetup d <dev-path>
+
+ 2. Setup the loop device at <dev-path> to access the file at <file-path>
+ as a block device:
+
+ losetup [-o <offset>] [-r] <dev-path> <file-path>
+
o ls [-lRs] <dir-path>
Show the contents of the directory at <dir-path>. 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/nuttx/examples/nsh/nsh.h b/nuttx/examples/nsh/nsh.h
index 825ea6554..32a0c934d 100644
--- a/nuttx/examples/nsh/nsh.h
+++ b/nuttx/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/nuttx/examples/nsh/nsh_fscmds.c b/nuttx/examples/nsh/nsh_fscmds.c
index 8dcf90372..301abddbb 100644
--- a/nuttx/examples/nsh/nsh_fscmds.c
+++ b/nuttx/examples/nsh/nsh_fscmds.c
@@ -648,6 +648,128 @@ errout:
#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 <loop-device>
+ * losetup [-o <offset>] [-r] <loop-device> <filename>
+ *
+ * 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/nuttx/examples/nsh/nsh_main.c b/nuttx/examples/nsh/nsh_main.c
index 14b1afb55..db116b5c0 100644
--- a/nuttx/examples/nsh/nsh_main.c
+++ b/nuttx/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 <dev-path>] | [[-o <offset>] [-r] <dev-path> <file-path>]" },
+# endif
+#endif
+
#if CONFIG_NFILE_DESCRIPTORS > 0
# ifndef CONFIG_EXAMPLES_NSH_DISABLE_LS
{ "ls", cmd_ls, 1, 5, "[-lRs] <dir-path>" },