summaryrefslogtreecommitdiff
path: root/apps/nshlib
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-01-16 19:08:23 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-01-16 19:08:23 +0000
commit357d086cf3b85cded5221dab092c917a3fa3c285 (patch)
treef5ccbefcedc52e86e0b48f906c6b2167ec2128d2 /apps/nshlib
parent880aa24ce3cb2bae6decbbdb2650f91a2547ba53 (diff)
downloadpx4-nuttx-357d086cf3b85cded5221dab092c917a3fa3c285.tar.gz
px4-nuttx-357d086cf3b85cded5221dab092c917a3fa3c285.tar.bz2
px4-nuttx-357d086cf3b85cded5221dab092c917a3fa3c285.zip
Add a binary 'loader' so that builtin applications can be executed from the BINFS file system
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5525 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps/nshlib')
-rw-r--r--apps/nshlib/Kconfig2
-rw-r--r--apps/nshlib/nsh_mntcmds.c72
-rw-r--r--apps/nshlib/nsh_parse.c2
3 files changed, 53 insertions, 23 deletions
diff --git a/apps/nshlib/Kconfig b/apps/nshlib/Kconfig
index 9cfc020a5..e60e9c480 100644
--- a/apps/nshlib/Kconfig
+++ b/apps/nshlib/Kconfig
@@ -15,7 +15,7 @@ if NSH_LIBRARY
config NSH_BUILTIN_APPS
bool "Enable built-in applications"
default y
- select BUILTIN
+ depends on BUILTIN
---help---
Support external registered, "built-in" applications that can be
executed from the NSH command line (see apps/README.txt for
diff --git a/apps/nshlib/nsh_mntcmds.c b/apps/nshlib/nsh_mntcmds.c
index b16ba8465..f8e3a142a 100644
--- a/apps/nshlib/nsh_mntcmds.c
+++ b/apps/nshlib/nsh_mntcmds.c
@@ -133,7 +133,7 @@ static int mount_handler(FAR const char *mountpoint,
#ifdef CONFIG_FS_BINFS
case BINFS_MAGIC:
- fstype = "bindir";
+ fstype = "binfs";
break;
#endif
@@ -198,9 +198,11 @@ int cmd_df(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_MOUNT)
int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{
- FAR char *source;
- FAR char *target;
- FAR char *filesystem = NULL;
+ FAR const char *source;
+ FAR char *fullsource;
+ FAR const char *target;
+ FAR char *fulltarget;
+ FAR const char *filesystem = NULL;
bool badarg = false;
int option;
int ret;
@@ -248,19 +250,32 @@ int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
return ERROR;
}
- /* There are two required arguments after the options: the source and target
- * paths.
+ /* There may be one or two required arguments after the options: the source
+ * and target paths. Some file systems do not require the source parameter
+ * so if there is only one parameter left, it must be the target.
*/
- if (optind + 2 < argc)
+ if (optind >= argc)
{
- nsh_output(vtbl, g_fmttoomanyargs, argv[0]);
+ nsh_output(vtbl, g_fmtargrequired, argv[0]);
return ERROR;
}
- else if (optind + 2 > argc)
+
+ source = NULL;
+ target = argv[optind];
+ optind++;
+
+ if (optind < argc)
{
- nsh_output(vtbl, g_fmtargrequired, argv[0]);
- return ERROR;
+ source = target;
+ target = argv[optind];
+ optind++;
+
+ if (optind < argc)
+ {
+ nsh_output(vtbl, g_fmttoomanyargs, argv[0]);
+ return ERROR;
+ }
}
/* While the above parsing for the -t argument looks nice, the -t argument
@@ -277,29 +292,44 @@ int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
* working directory.
*/
- source = nsh_getfullpath(vtbl, argv[optind]);
- if (!source)
+ fullsource = NULL;
+ fulltarget = NULL;
+
+ if (source)
{
- return ERROR;
+ fullsource = nsh_getfullpath(vtbl, source);
+ if (!fullsource)
+ {
+ return ERROR;
+ }
}
- target = nsh_getfullpath(vtbl, argv[optind+1]);
- if (!target)
+ fulltarget = nsh_getfullpath(vtbl, target);
+ if (!fulltarget)
{
- nsh_freefullpath(source);
- return ERROR;
+ ret = ERROR;
+ goto errout;
}
/* Perform the mount */
- ret = mount(source, target, filesystem, 0, NULL);
+ ret = mount(fullsource, fulltarget, filesystem, 0, NULL);
if (ret < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "mount", NSH_ERRNO);
}
- nsh_freefullpath(source);
- nsh_freefullpath(target);
+errout:
+ if (fullsource)
+ {
+ nsh_freefullpath(fullsource);
+ }
+
+ if (fulltarget)
+ {
+ nsh_freefullpath(fulltarget);
+ }
+
return ret;
}
#endif
diff --git a/apps/nshlib/nsh_parse.c b/apps/nshlib/nsh_parse.c
index c36724372..ef4125a63 100644
--- a/apps/nshlib/nsh_parse.c
+++ b/apps/nshlib/nsh_parse.c
@@ -301,7 +301,7 @@ static const struct cmdmap_s g_cmdmap[] =
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_READABLE)
# ifndef CONFIG_NSH_DISABLE_MOUNT
- { "mount", cmd_mount, 1, 5, "[-t <fstype> <block-device> <mount-point>]" },
+ { "mount", cmd_mount, 1, 5, "[-t <fstype> [<block-device>] <mount-point>]" },
# endif
#endif