diff --git a/ChangeLog b/ChangeLog index a3ebf96e79772af53df87ff3d77f8315c9c7a836..0fb5348d7eb39e8566dfec90b09f9bfb0236a5f9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -451,4 +451,6 @@ * NSH: Created an HTML document and a more detailed README file describing NSH. * Added basic TFTP client logic (netutils/tftpc). Untested as of initial check-in. * NSH: Add get and put commands to support TFTP get and put operations. + * NSH: Added a mkrd command that will create a RAMDISK that can be formatted + and mounted. diff --git a/Documentation/NuttShell.html b/Documentation/NuttShell.html index 2c8d8e2fb1962cee2e91dec4fe6c17bfc8e44a9e..fa8003a17c07d82cd18347fd013a9b6ae6b7891b 100644 --- a/Documentation/NuttShell.html +++ b/Documentation/NuttShell.html @@ -179,73 +179,79 @@ <tr> <td><br></td> <td> - <a href="#cmdmount">2.18 Mount a File System (mount)</a> + <a href="#cmdmkrd">2.18 Create a RAMDISK (mkrd)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdping">2.19 Check Network Peer (ping)</a> + <a href="#cmdmount">2.19 Mount a File System (mount)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdput">2.20 Send File Via TFTP (put)</a> + <a href="#cmdping">2.20 Check Network Peer (ping)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdpwd">2.21 Show Current Working Directory (pwd)</a> + <a href="#cmdput">2.21 Send File Via TFTP (put)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdrm">2.22 Remove a File (rm)</a> + <a href="#cmdpwd">2.22 Show Current Working Directory (pwd)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdrmdir">2.23 Remove a Directory (rmdir)</a> + <a href="#cmdrm">2.23 Remove a File (rm)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdset">2.24 Set an Environment Variable (set)</a> + <a href="#cmdrmdir">2.24 Remove a Directory (rmdir)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdsh">2.25 Execute an NSH Script (sh)</a> + <a href="#cmdset">2.25 Set an Environment Variable (set)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdsleep">2.26 Wait for Seconds (sleep)</a> + <a href="#cmdsh">2.26 Execute an NSH Script (sh)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdunmount">2.27 Unmount a File System (umount)</a> + <a href="#cmdsleep">2.27 Wait for Seconds (sleep)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdunset">2.28 Unset an Environment Variable (unset)</a> + <a href="#cmdunmount">2.28 Unmount a File System (umount)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdusleep">2.29 Wait for Microseconds (usleep)</a> + <a href="#cmdunset">2.29 Unset an Environment Variable (unset)</a> + </td> +</tr> +<tr> + <td><br></td> + <td> + <a href="#cmdusleep">2.30 Wait for Microseconds (usleep)</a> </td> </tr> <tr> @@ -989,7 +995,58 @@ nsh> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdmount"><h2>2.18 Mount a File System (mount)</h2></a> + <a name="cmdmkrd"><h2>2.18 Create a RAMDISK (mkrd)</h2></a> + </td> +</tr> +</table> + +<p><b>Command Syntax:</b></p> +<ul><pre> +mkrd [-m <minor>] [-s <sector-size>] <nsectors> +</pre></ul> +<p> + <b>Synopsis</b>. + Create a ramdisk consisting of <code><nsectors></code>, each of size + <code><sector-size></code> (or 512 bytes if <code><sector-size></code> is not specified. + The ramdisk will be registered as <code>/dev/ram<n></code> (if <code><n></code> is not + specified, mkrd will attempt to register the ramdisk as <code>/dev/ram0</code>. +</p> +<p><b>Example</b></p> +<ul><pre> +nsh> ls /dev +/dev: + console + null + ttyS0 + ttyS1 +nsh> mkrd 1024 +nsh> ls /dev +/dev: + console + null + ram0 + ttyS0 + ttyS1 +nsh> +</pre></ul> +<p> + Once the ramdisk has been created, it may be formatted using + the <code>mkfatfs</code> command and mounted using the <code>mount</code> command. +</p> +<p><b>Example</b></p> +<ul><pre> +nsh> mkrd 1024 +nsh> mkfatfs /dev/ram0 +nsh> mount -t vfat /dev/ram0 /tmp +nsh> ls /tmp +/tmp: +nsh> +</pre></ul> + +<table width ="100%"> + <tr bgcolor="#e4e4e4"> + <td> + <a name="cmdmount"><h2>2.19 Mount a File System (mount)</h2></a> </td> </tr> </table> @@ -1056,7 +1113,7 @@ nsh> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdping"><h2>2.19 Check Network Peer (ping)</h2></a> + <a name="cmdping"><h2>2.20 Check Network Peer (ping)</h2></a> </td> </tr> </table> @@ -1089,7 +1146,7 @@ nsh> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdput"><h2>2.20 Send File Via TFTP (put)</h2></a> + <a name="cmdput"><h2>2.21 Send File Via TFTP (put)</h2></a> </td> </tr> </table> @@ -1124,7 +1181,7 @@ put [-b|-n] [-f <remote-path>] -h <ip-address> <local-path> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdpwd"><h2>2.21 Show Current Working Directory (pwd)</h2></a> + <a name="cmdpwd"><h2>2.22 Show Current Working Directory (pwd)</h2></a> </td> </tr> </table> @@ -1154,7 +1211,7 @@ nsh> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdrm"><h2>2.22 Remove a File (rm)</h2></a> + <a name="cmdrm"><h2>2.23 Remove a File (rm)</h2></a> </td> </tr> </table> @@ -1188,7 +1245,7 @@ nsh> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdrmdir"><h2>2.23 Remove a Directory (rmdir)</h2></a> + <a name="cmdrmdir"><h2>2.24 Remove a Directory (rmdir)</h2></a> </td> </tr> </table> @@ -1223,7 +1280,7 @@ nsh> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdset"><h2>2.24 Set an Environment Variable (set)</h2></a> + <a name="cmdset"><h2>2.25 Set an Environment Variable (set)</h2></a> </td> </tr> </table> @@ -1249,7 +1306,7 @@ nsh> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdsh"><h2>2.25 Execute an NSH Script (sh)</h2></a> + <a name="cmdsh"><h2>2.26 Execute an NSH Script (sh)</h2></a> </td> </tr> </table> @@ -1267,7 +1324,7 @@ sh <script-path> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdsleep"><h2>2.26 Wait for Seconds (sleep)</h2></a> + <a name="cmdsleep"><h2>2.27 Wait for Seconds (sleep)</h2></a> </td> </tr> </table> @@ -1284,7 +1341,7 @@ sleep <sec> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdunmount"><h2>2.27 Unmount a File System (umount)</h2></a> + <a name="cmdunmount"><h2>2.28 Unmount a File System (umount)</h2></a> </td> </tr> </table> @@ -1314,7 +1371,7 @@ nsh> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdunset"><h2>2.28 Unset an Environment Variable (unset)</h2></a> + <a name="cmdunset"><h2>2.29 Unset an Environment Variable (unset)</h2></a> </td> </tr> </table> @@ -1340,7 +1397,7 @@ nsh> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdusleep"><h2>2.29 Wait for Microseconds (usleep)</h2></a> + <a name="cmdusleep"><h2>2.30 Wait for Microseconds (usleep)</h2></a> </td> </tr> </table> @@ -1448,7 +1505,11 @@ usleep <usec> </tr> <tr> <td><b><code>mkfifo</code></b></td> - <td>!<code>CONFIG_DISABLE_MOUNTPOINT</code> && <code>CONFIG_NFILE_DESCRIPTORS</code> > 0</td> + <td><code>CONFIG_NFILE_DESCRIPTORS</code> > 0</td> + </tr> + <tr> + <td><b><code>mkrd</code></b></td> + <td>!<code>CONFIG_DISABLE_MOUNTPOINT</code> && <code>CONFIG_NFILE_DESCRIPTORS</code> > 0 && <code>CONFIG_FS_FAT</code></td> </tr> <tr> <td><b><code>mount</code></b></td> @@ -1711,6 +1772,7 @@ usleep <usec> <li><a href="#cmdmkdir"><code>mkdir</code></a></li> <li><a href="#cmdmkfatfs"><code>mkfatfs</code></a></li> <li><a href="#cmdmkfifo"><code>mkfifo</code></a></li> + <li><a href="#cmdmkrd"><code>mkrd</code></a></li> <li><a href="#cmdmount"><code>mount</code></a></li> <li><a href="#cmdoverview"><code>nice</code></a></li> <li><a href="#environvars"><code>OLDPWD</code></a></li> diff --git a/Documentation/NuttX.html b/Documentation/NuttX.html index 2e936dee9e2514831c6ba4212511d6a448a4ca7b..59f2afdf97bc4f76405b9289ea4adaa646fac007 100644 --- a/Documentation/NuttX.html +++ b/Documentation/NuttX.html @@ -8,7 +8,7 @@ <tr align="center" bgcolor="#e4e4e4"> <td> <h1><big><font color="#3c34ec"><i>NuttX RTOS</i></font></big></h1> - <p>Last Updated: September 5, 2008</p> + <p>Last Updated: September 6, 2008</p> </td> </tr> </table> @@ -1078,6 +1078,8 @@ nuttx-0.3.14 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> * NSH: Created an HTML document and a more detailed README file describing NSH. * Added basic TFTP client logic (netutils/tftpc). Untested as of initial check-in. * NSH: Add get and put commands to support TFTP get and put operations. + * NSH: Added a mkrd command that will create a RAMDISK that can be formatted + and mounted. pascal-0.1.3 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> diff --git a/arch/arm/src/common/up_exit.c b/arch/arm/src/common/up_exit.c index 2660ed80bbb047cc4370946c4e2be54c84957e2d..79ff212183814ced728c7c1d45cdee0f06bb82ab 100644 --- a/arch/arm/src/common/up_exit.c +++ b/arch/arm/src/common/up_exit.c @@ -78,21 +78,21 @@ static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) int i; #endif - dbg(" TCB=%p name=%s\n", tcb, tcb->argv[0]); + sdbg(" TCB=%p name=%s\n", tcb, tcb->argv[0]); #if CONFIG_NFILE_DESCRIPTORS > 0 if (tcb->filelist) { - dbg(" filelist refcount=%d\n", - tcb->filelist->fl_crefs); + sdbg(" filelist refcount=%d\n", + tcb->filelist->fl_crefs); for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++) { struct inode *inode = tcb->filelist->fl_files[i].f_inode; if (inode) { - dbg(" fd=%d refcount=%d\n", - i, inode->i_crefs); + sdbg(" fd=%d refcount=%d\n", + i, inode->i_crefs); } } } @@ -101,8 +101,8 @@ static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) #if CONFIG_NFILE_STREAMS > 0 if (tcb->streams) { - dbg(" streamlist refcount=%d\n", - tcb->streams->sl_crefs); + sdbg(" streamlist refcount=%d\n", + tcb->streams->sl_crefs); for (i = 0; i < CONFIG_NFILE_STREAMS; i++) { @@ -110,11 +110,11 @@ static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) if (filep->fs_filedes >= 0) { #if CONFIG_STDIO_BUFFER_SIZE > 0 - dbg(" fd=%d nbytes=%d\n", - filep->fs_filedes, + sdbg(" fd=%d nbytes=%d\n", + filep->fs_filedes, filep->fs_bufpos - filep->fs_bufstart); #else - dbg(" fd=%d\n", filep->fs_filedes); + sdbg(" fd=%d\n", filep->fs_filedes); #endif } } @@ -148,10 +148,10 @@ void _exit(int status) (void)irqsave(); - lldbg("TCB=%p exitting\n", tcb); + slldbg("TCB=%p exitting\n", tcb); #if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG) - lldbg("Other tasks:\n"); + slldbg("Other tasks:\n"); sched_foreach(_up_dumponexit, NULL); #endif @@ -164,7 +164,7 @@ void _exit(int status) */ tcb = (_TCB*)g_readytorun.head; - lldbg("New Active Task TCB=%p\n", tcb); + slldbg("New Active Task TCB=%p\n", tcb); /* Then switch contexts */ diff --git a/arch/arm/src/common/up_initialize.c b/arch/arm/src/common/up_initialize.c index 0f70fcca5cd17573e68dcff7c88df913725476e8..583142ec05dd2d665bd48f8cd58cbf50181dd2f8 100644 --- a/arch/arm/src/common/up_initialize.c +++ b/arch/arm/src/common/up_initialize.c @@ -75,12 +75,12 @@ static void up_calibratedelay(void) { int i; - lldbg("Beginning 100s delay\n"); + slldbg("Beginning 100s delay\n"); for (i = 0; i < 100; i++) { up_mdelay(1000); } - lldbg("End 100s delay\n"); + slldbg("End 100s delay\n"); } #else # define up_calibratedelay() diff --git a/arch/arm/src/common/up_releasepending.c b/arch/arm/src/common/up_releasepending.c index 7f8016d53a0fc25b8d717bb78ed018621bdeff55..44b36590f4166dd45307824b08171a7faf9cd6a6 100644 --- a/arch/arm/src/common/up_releasepending.c +++ b/arch/arm/src/common/up_releasepending.c @@ -76,7 +76,7 @@ void up_release_pending(void) { _TCB *rtcb = (_TCB*)g_readytorun.head; - lldbg("From TCB=%p\n", rtcb); + slldbg("From TCB=%p\n", rtcb); /* Merge the g_pendingtasks list into the g_readytorun task list */ @@ -101,7 +101,7 @@ void up_release_pending(void) */ rtcb = (_TCB*)g_readytorun.head; - lldbg("New Active Task TCB=%p\n", rtcb); + slldbg("New Active Task TCB=%p\n", rtcb); /* Then switch contexts */ @@ -121,7 +121,7 @@ void up_release_pending(void) */ rtcb = (_TCB*)g_readytorun.head; - lldbg("New Active Task TCB=%p\n", rtcb); + slldbg("New Active Task TCB=%p\n", rtcb); /* Then switch contexts */ diff --git a/arch/arm/src/common/up_reprioritizertr.c b/arch/arm/src/common/up_reprioritizertr.c index 1f589b73fa9a98b5c6a32420e2657e13f110c7ea..13081958220cd28ae6ab6606178889ad03a33dde 100644 --- a/arch/arm/src/common/up_reprioritizertr.c +++ b/arch/arm/src/common/up_reprioritizertr.c @@ -97,7 +97,7 @@ void up_reprioritize_rtr(_TCB *tcb, ubyte priority) _TCB *rtcb = (_TCB*)g_readytorun.head; boolean switch_needed; - lldbg("TCB=%p PRI=%d\n", tcb, priority); + slldbg("TCB=%p PRI=%d\n", tcb, priority); /* Remove the tcb task from the ready-to-run list. * sched_removereadytorun will return TRUE if we just @@ -149,7 +149,7 @@ void up_reprioritize_rtr(_TCB *tcb, ubyte priority) */ rtcb = (_TCB*)g_readytorun.head; - lldbg("New Active Task TCB=%p\n", rtcb); + slldbg("New Active Task TCB=%p\n", rtcb); /* Then switch contexts */ @@ -168,7 +168,7 @@ void up_reprioritize_rtr(_TCB *tcb, ubyte priority) */ rtcb = (_TCB*)g_readytorun.head; - lldbg("New Active Task TCB=%p\n", rtcb); + slldbg("New Active Task TCB=%p\n", rtcb); /* Then switch contexts */ diff --git a/arch/arm/src/common/up_schedulesigaction.c b/arch/arm/src/common/up_schedulesigaction.c index 6b56cc3b67b637d40567cd6f354e01d97fd46926..1dbecc8e76e63f0b51aa081b895d2a6322e3b8cd 100644 --- a/arch/arm/src/common/up_schedulesigaction.c +++ b/arch/arm/src/common/up_schedulesigaction.c @@ -99,7 +99,7 @@ void up_schedule_sigaction(_TCB *tcb, sig_deliver_t sigdeliver) { /* Refuse to handle nested signal actions */ - dbg("tcb=0x%p sigdeliver=0x%p\n", tcb, sigdeliver); + sdbg("tcb=0x%p sigdeliver=0x%p\n", tcb, sigdeliver); if (!tcb->xcp.sigdeliver) { @@ -113,7 +113,7 @@ void up_schedule_sigaction(_TCB *tcb, sig_deliver_t sigdeliver) * being delivered to the currently executing task. */ - dbg("rtcb=0x%p current_regs=0x%p\n", g_readytorun.head, current_regs); + sdbg("rtcb=0x%p current_regs=0x%p\n", g_readytorun.head, current_regs); if (tcb == (_TCB*)g_readytorun.head) { diff --git a/arch/arm/src/common/up_sigdeliver.c b/arch/arm/src/common/up_sigdeliver.c index 31d798b93565fa9789919b02226943c02d4cc3fa..4b2f1c27b6cbb0c7c663d885b4e1cc498bf368d7 100644 --- a/arch/arm/src/common/up_sigdeliver.c +++ b/arch/arm/src/common/up_sigdeliver.c @@ -90,8 +90,8 @@ void up_sigdeliver(void) up_ledon(LED_SIGNAL); - dbg("rtcb=%p sigdeliver=%p sigpendactionq.head=%p\n", - rtcb, rtcb->xcp.sigdeliver, rtcb->sigpendactionq.head); + sdbg("rtcb=%p sigdeliver=%p sigpendactionq.head=%p\n", + rtcb, rtcb->xcp.sigdeliver, rtcb->sigpendactionq.head); ASSERT(rtcb->xcp.sigdeliver != NULL); /* Save the real return state on the stack. */ @@ -124,7 +124,7 @@ void up_sigdeliver(void) * (it is probably EINTR). */ - dbg("Resuming\n"); + sdbg("Resuming\n"); rtcb->pterrno = saved_errno; /* Then restore the correct state for this thread of diff --git a/examples/README.txt b/examples/README.txt index 13865365347b09ed86515efc6244af2811bc9174..ba6051e16f538816327f631a7d892c1630ae71ef 100644 --- a/examples/README.txt +++ b/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/examples/nsh/README.txt b/examples/nsh/README.txt index 1972b2b1364ce34268dad3795f7523ff8d460ba4..0c0bc2eba4e2090f1fae6ecd35aa4f2e039574a2 100644 --- a/examples/nsh/README.txt +++ b/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/examples/nsh/nsh.h b/examples/nsh/nsh.h index f468a264a4086137cca427dbced9014c8d0b6c0d..c69aa2342d303c759278e417fd59996974cc7227 100644 --- a/examples/nsh/nsh.h +++ b/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/examples/nsh/nsh_fscmds.c b/examples/nsh/nsh_fscmds.c index 458f1130e9d16154020b7a749161ee92e9670e35..cd02ca576ee731b4de3370717bb0e540f6594224 100644 --- a/examples/nsh/nsh_fscmds.c +++ b/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]); @@ -775,6 +776,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/examples/nsh/nsh_main.c b/examples/nsh/nsh_main.c index f2890159c66a18e4076aeab790317d6f5e4a856d..e58836fccee946551323214b8c2308dc6306fb59 100644 --- a/examples/nsh/nsh_main.c +++ b/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