summaryrefslogtreecommitdiff
path: root/nuttx/examples
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-09-06 13:29:14 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-09-06 13:29:14 +0000
commitbf15faf28c3826541af41632784beaefdb9a2254 (patch)
tree693df9115f41cfdf1df8985ab608e34db7c5dc44 /nuttx/examples
parent0d247e402ea9508b15e37fdd16d96e7d5ddd5498 (diff)
downloadpx4-nuttx-bf15faf28c3826541af41632784beaefdb9a2254.tar.gz
px4-nuttx-bf15faf28c3826541af41632784beaefdb9a2254.tar.bz2
px4-nuttx-bf15faf28c3826541af41632784beaefdb9a2254.zip
Add NSH command to create RAMDISK
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@884 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/examples')
-rw-r--r--nuttx/examples/README.txt2
-rw-r--r--nuttx/examples/nsh/README.txt42
-rw-r--r--nuttx/examples/nsh/nsh.h1
-rw-r--r--nuttx/examples/nsh/nsh_fscmds.c96
-rw-r--r--nuttx/examples/nsh/nsh_main.c1
5 files changed, 139 insertions, 3 deletions
diff --git a/nuttx/examples/README.txt b/nuttx/examples/README.txt
index 138653653..ba6051e16 100644
--- a/nuttx/examples/README.txt
+++ b/nuttx/examples/README.txt
@@ -39,7 +39,7 @@ examples/mount
^^^^^^^^^^^^^^
This contains a simple test of filesystem mountpoints.
-
+
* CONFIG_EXAMPLES_MOUNT_DEVNAME
The name of the user-provided block device to mount.
If CONFIG_EXAMPLES_MOUNT_DEVNAME is not provided, then
diff --git a/nuttx/examples/nsh/README.txt b/nuttx/examples/nsh/README.txt
index 1972b2b13..0c0bc2eba 100644
--- a/nuttx/examples/nsh/README.txt
+++ b/nuttx/examples/nsh/README.txt
@@ -325,6 +325,45 @@ o mkfifo <path>
brw-rw-rw- 0 ram0
nsh>
+o mkrd [-m <minor>] [-s <sector-size>] <nsectors>
+
+ Create a ramdisk consisting of <nsectors>, each of size
+ <sector-size> (or 512 bytes if <sector-size> is not specified.
+ The ramdisk will be registered as /dev/ram<n> (if <n> is not
+ specified, mkrd will attempt to register the ramdisk as
+ /dev/ram0.
+
+ Example:
+ ^^^^^^^^
+
+ nsh> ls /dev
+ /dev:
+ console
+ null
+ ttyS0
+ ttyS1
+ nsh> mkrd 1024
+ nsh> ls /dev
+ /dev:
+ console
+ null
+ ram0
+ ttyS0
+ ttyS1
+ nsh>
+
+ Once the ramdisk has been created, it may be formatted using
+ the mkfatfs command and mounted using the mount command.
+
+ Example:
+ ^^^^^^^^
+ nsh> mkrd 1024
+ nsh> mkfatfs /dev/ram0
+ nsh> mount -t vfat /dev/ram0 /tmp
+ nsh> ls /tmp
+ /tmp:
+ nsh>
+
o mount -t <fstype> <block-device> <dir-path>
The 'mount' command mounts a file system in the NuttX psuedo
@@ -543,7 +582,8 @@ Command Dependencies on Configuration Settings
mem ---
mkdir !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0
mkfatfs !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_FAT
- mkfifo !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0
+ mkfifo CONFIG_NFILE_DESCRIPTORS > 0
+ mkrd !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_FAT
mount !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_FAT
ping CONFIG_NET && CONFIG_NET_ICMP && CONFIG_NET_ICMP_PING && !CONFIG_DISABLE_CLOCK && !CONFIG_DISABLE_SIGNALS
ps --
diff --git a/nuttx/examples/nsh/nsh.h b/nuttx/examples/nsh/nsh.h
index f468a264a..c69aa2342 100644
--- a/nuttx/examples/nsh/nsh.h
+++ b/nuttx/examples/nsh/nsh.h
@@ -284,6 +284,7 @@ extern int cmd_lbracket(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
# ifndef CONFIG_DISABLE_MOUNTPOINT
extern int cmd_mkdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
extern int cmd_mkfifo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
+ extern int cmd_mkrd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
extern int cmd_rm(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
extern int cmd_rmdir(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
# ifdef CONFIG_FS_FAT
diff --git a/nuttx/examples/nsh/nsh_fscmds.c b/nuttx/examples/nsh/nsh_fscmds.c
index 458f1130e..cd02ca576 100644
--- a/nuttx/examples/nsh/nsh_fscmds.c
+++ b/nuttx/examples/nsh/nsh_fscmds.c
@@ -48,6 +48,7 @@
# include <sys/mount.h>
# include <nuttx/mkfatfs.h>
# endif
+# include <nuttx/ramdisk.h>
#endif
#endif
@@ -756,7 +757,7 @@ int cmd_mkfatfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
* Name: cmd_mkfifo
****************************************************************************/
-#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0
+#if CONFIG_NFILE_DESCRIPTORS > 0
int cmd_mkfifo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{
char *fullpath = nsh_getfullpath(vtbl, argv[1]);
@@ -776,6 +777,99 @@ int cmd_mkfifo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
#endif
/****************************************************************************
+ * Name: cmd_mkrd
+ ****************************************************************************/
+
+#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0
+int cmd_mkrd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
+{
+ const char *fmt;
+ ubyte *buffer;
+ uint32 nsectors;
+ int sectsize = 512;
+ int minor = 0;
+ int ret;
+
+ /* Get the mount options */
+
+ int option;
+ while ((option = getopt(argc, argv, ":m:s:")) != ERROR)
+ {
+ switch (option)
+ {
+ case 'm':
+ minor = atoi(optarg);
+ if (minor < 0 || minor > 255)
+ {
+ fmt = g_fmtargrange;
+ goto errout_with_fmt;
+ }
+ break;
+
+ case 's':
+ sectsize = atoi(optarg);
+ if (minor < 0 || minor > 16384)
+ {
+ fmt = g_fmtargrange;
+ goto errout_with_fmt;
+ }
+ break;
+
+ case ':':
+ fmt = g_fmtargrequired;
+ goto errout_with_fmt;
+
+ case '?':
+ default:
+ fmt = g_fmtarginvalid;
+ goto errout_with_fmt;
+ }
+ }
+
+ /* There should be exactly on parameter left on the command-line */
+
+ if (optind == argc-1)
+ {
+ nsectors = (uint32)atoi(argv[optind]);
+ }
+ else if (optind >= argc)
+ {
+ fmt = g_fmttoomanyargs;
+ goto errout_with_fmt;
+ }
+ else
+ {
+ fmt = g_fmtargrequired;
+ goto errout_with_fmt;
+ }
+
+ /* Allocate the memory backing up the ramdisk */
+
+ buffer = (ubyte*)malloc(sectsize * nsectors);
+ if (!buffer)
+ {
+ fmt = g_fmtcmdoutofmemory;
+ goto errout_with_fmt;
+ }
+
+ /* Then register the ramdisk */
+
+ ret = rd_register(minor, buffer, nsectors, sectsize, TRUE);
+ if (ret < 0)
+ {
+ nsh_output(vtbl, g_fmtcmdfailed, argv[0], "rd_register", NSH_ERRNO_OF(-ret));
+ free(buffer);
+ return ERROR;
+ }
+ return ret;
+
+errout_with_fmt:
+ nsh_output(vtbl, fmt, argv[0]);
+ return ERROR;
+}
+#endif
+
+/****************************************************************************
* Name: cmd_mount
****************************************************************************/
diff --git a/nuttx/examples/nsh/nsh_main.c b/nuttx/examples/nsh/nsh_main.c
index f2890159c..e58836fcc 100644
--- a/nuttx/examples/nsh/nsh_main.c
+++ b/nuttx/examples/nsh/nsh_main.c
@@ -163,6 +163,7 @@ static const struct cmdmap_s g_cmdmap[] =
{ "mkfatfs", cmd_mkfatfs, 2, 2, "<path>" },
#endif
{ "mkfifo", cmd_mkfifo, 2, 2, "<path>" },
+ { "mkrd", cmd_mkrd, 2, 6, "[-m <minor>] [-s <sector-size>] <nsectors>" },
#endif
{ "mh", cmd_mh, 2, 3, "<hex-address>[=<hex-value>][ <hex-byte-count>]" },
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0