Add dd command to NSH
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@1241 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
parent
f43bb76fa5
commit
b2a511f7dc
|
@ -552,4 +552,5 @@
|
|||
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.
|
||||
|
||||
* Added strcasecmp() and strncasecmp()
|
||||
* NSH: Added 'dd' command
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<tr align="center" bgcolor="#e4e4e4">
|
||||
<td>
|
||||
<h1><big><font color="#3c34ec"><i>NuttShell (NSH)</i></font></big></h1>
|
||||
<p>Last Updated: October 15, 2008</p>
|
||||
<p>Last Updated: November 15, 2008</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -107,163 +107,169 @@
|
|||
<tr>
|
||||
<td><br></td>
|
||||
<td>
|
||||
<a href="#cmdecho">2.5 Echo Strings and Variables (echo)</a>
|
||||
<a href="#cmddd">2.5 Copy and Convert Files (dd)</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><br></td>
|
||||
<td>
|
||||
<a href="#cmdexec">2.6 Execute User Code (exec)</a>
|
||||
<a href="#cmdecho">2.6 Echo Strings and Variables (echo)</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><br></td>
|
||||
<td>
|
||||
<a href="#cmdget">2.7 Get File Via TFTP (get)</a>
|
||||
<a href="#cmdexec">2.7 Execute User Code (exec)</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><br></td>
|
||||
<td>
|
||||
<a href="#cmdexit">2.8 Exit NSH (exit)</a>
|
||||
<a href="#cmdget">2.8 Get File Via TFTP (get)</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><br></td>
|
||||
<td>
|
||||
<a href="#cmdhelp">2.9 Show Usage Command Usage (help)</a>
|
||||
<a href="#cmdexit">2.9 Exit NSH (exit)</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><br></td>
|
||||
<td>
|
||||
<a href="#cmdifconfig">2.10 Show Network Configuration (ifconfig)</a>
|
||||
<a href="#cmdhelp">2.10 Show Usage Command Usage (help)</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><br></td>
|
||||
<td>
|
||||
<a href="#cmdls">2.11 List Directory Contents (ls)</a>
|
||||
<a href="#cmdifconfig">2.11 Show Network Configuration (ifconfig)</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><br></td>
|
||||
<td>
|
||||
<a href="#cmdmbhw">2.12 Access Memory (mb, mh, and mw)</a>
|
||||
<a href="#cmdls">2.12 List Directory Contents (ls)</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><br></td>
|
||||
<td>
|
||||
<a href="#cmdmem">2.13 Show Memory Manager Status (mem)</a>
|
||||
<a href="#cmdmbhw">2.13 Access Memory (mb, mh, and mw)</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><br></td>
|
||||
<td>
|
||||
<a href="#cmdps">2.14 Show Current Tasks and Threads (ps)</a>
|
||||
<a href="#cmdmem">2.14 Show Memory Manager Status (mem)</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><br></td>
|
||||
<td>
|
||||
<a href="#cmdmkdir">2.15 Create a Directory (mkdir)</a>
|
||||
<a href="#cmdps">2.15 Show Current Tasks and Threads (ps)</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><br></td>
|
||||
<td>
|
||||
<a href="#cmdmkfatfs">2.16 Create a FAT Filesystem (mkfatfs)</a>
|
||||
<a href="#cmdmkdir">2.16 Create a Directory (mkdir)</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><br></td>
|
||||
<td>
|
||||
<a href="#cmdmkfifo">2.17 Create a FIFO (mkfifo)</a>
|
||||
<a href="#cmdmkfatfs">2.17 Create a FAT Filesystem (mkfatfs)</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><br></td>
|
||||
<td>
|
||||
<a href="#cmdmkrd">2.18 Create a RAMDISK (mkrd)</a>
|
||||
<a href="#cmdmkfifo">2.18 Create a FIFO (mkfifo)</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><br></td>
|
||||
<td>
|
||||
<a href="#cmdmount">2.19 Mount a File System (mount)</a>
|
||||
<a href="#cmdmkrd">2.19 Create a RAMDISK (mkrd)</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><br></td>
|
||||
<td>
|
||||
<a href="#cmdping">2.20 Check Network Peer (ping)</a>
|
||||
<a href="#cmdmount">2.20 Mount a File System (mount)</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><br></td>
|
||||
<td>
|
||||
<a href="#cmdput">2.21 Send File Via TFTP (put)</a>
|
||||
<a href="#cmdping">2.21 Check Network Peer (ping)</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><br></td>
|
||||
<td>
|
||||
<a href="#cmdpwd">2.22 Show Current Working Directory (pwd)</a>
|
||||
<a href="#cmdput">2.22 Send File Via TFTP (put)</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><br></td>
|
||||
<td>
|
||||
<a href="#cmdrm">2.23 Remove a File (rm)</a>
|
||||
<a href="#cmdpwd">2.23 Show Current Working Directory (pwd)</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><br></td>
|
||||
<td>
|
||||
<a href="#cmdrmdir">2.24 Remove a Directory (rmdir)</a>
|
||||
<a href="#cmdrm">2.24 Remove a File (rm)</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><br></td>
|
||||
<td>
|
||||
<a href="#cmdset">2.25 Set an Environment Variable (set)</a>
|
||||
<a href="#cmdrmdir">2.25 Remove a Directory (rmdir)</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><br></td>
|
||||
<td>
|
||||
<a href="#cmdsh">2.26 Execute an NSH Script (sh)</a>
|
||||
<a href="#cmdset">2.26 Set an Environment Variable (set)</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><br></td>
|
||||
<td>
|
||||
<a href="#cmdsleep">2.27 Wait for Seconds (sleep)</a>
|
||||
<a href="#cmdsh">2.27 Execute an NSH Script (sh)</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><br></td>
|
||||
<td>
|
||||
<a href="#cmdunmount">2.28 Unmount a File System (umount)</a>
|
||||
<a href="#cmdsleep">2.28 Wait for Seconds (sleep)</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><br></td>
|
||||
<td>
|
||||
<a href="#cmdunset">2.29 Unset an Environment Variable (unset)</a>
|
||||
<a href="#cmdunmount">2.29 Unmount a File System (umount)</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><br></td>
|
||||
<td>
|
||||
<a href="#cmdusleep">2.30 Wait for Microseconds (usleep)</a>
|
||||
<a href="#cmdunset">2.30 Unset an Environment Variable (unset)</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><br></td>
|
||||
<td>
|
||||
<a href="#cmdxd">2.31 Hexadecimal Dump (xd)</a>
|
||||
<a href="#cmdusleep">2.31 Wait for Microseconds (usleep)</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><br></td>
|
||||
<td>
|
||||
<a href="#cmdxd">2.32 Hexadecimal Dump (xd)</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
@ -730,14 +736,37 @@ cp <source-path> <dest-path>
|
|||
</pre></ul>
|
||||
<p>
|
||||
<b>Synopsis</b>.
|
||||
Copy of the contents of the file at <code><source-path<</code> to the location
|
||||
in the filesystem indicated by <code><path-path></code>.
|
||||
Copy of the contents of the file at <code><source-path></code> to the location
|
||||
in the filesystem indicated by <code><dest-path></code>.
|
||||
</p>
|
||||
|
||||
<table width ="100%">
|
||||
<tr bgcolor="#e4e4e4">
|
||||
<td>
|
||||
<a name="cmdecho"><h2>2.5 Echo Strings and Variables (echo)</h2></a>
|
||||
<a name="cmddd"><h2>2.5 Copy and Convert Files (dd)</h2></a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<a <p><b>Command Syntax:</b></p>
|
||||
<ul><pre>
|
||||
dd if=<infile> of=<outfile> [bs=<sectsize>] [count=<sectors>] [skip=<sectors>]
|
||||
</pre></ul>
|
||||
<p>
|
||||
<b>Synopsis</b>.
|
||||
Copy blocks from <infile> to <outfile>. As an example:
|
||||
<ul><pre>
|
||||
nsh> dd if=/dev/zero of=/tmp/zeros bs=64 count=16
|
||||
nsh> ls -l /tmp
|
||||
/tmp:
|
||||
-rw-rw-rw- 1024 ZEROS
|
||||
</pre></ul>
|
||||
</p>
|
||||
|
||||
<table width ="100%">
|
||||
<tr bgcolor="#e4e4e4">
|
||||
<td>
|
||||
<a name="cmdecho"><h2>2.6 Echo Strings and Variables (echo)</h2></a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -755,7 +784,7 @@ echo [<string|$name> [<string|$name>...]]
|
|||
<table width ="100%">
|
||||
<tr bgcolor="#e4e4e4">
|
||||
<td>
|
||||
<a name="cmdexec"><h2>2.6 Execute User Code (exec)</h2></a>
|
||||
<a name="cmdexec"><h2>2.7 Execute User Code (exec)</h2></a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -774,7 +803,7 @@ exec <hex-address>
|
|||
<table width ="100%">
|
||||
<tr bgcolor="#e4e4e4">
|
||||
<td>
|
||||
<a name="cmdget"><h2>2.7 Get File Via TFTP (get)</h2></a>
|
||||
<a name="cmdget"><h2>2.8 Get File Via TFTP (get)</h2></a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -809,7 +838,7 @@ get [-b|-n] [-f <local-path>] -h <ip-address> <remote-path>
|
|||
<table width ="100%">
|
||||
<tr bgcolor="#e4e4e4">
|
||||
<td>
|
||||
<a name="cmdexit"><h2>2.8 Exit NSH (exit)</h2></a>
|
||||
<a name="cmdexit"><h2>2.9 Exit NSH (exit)</h2></a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -828,7 +857,7 @@ exit
|
|||
<table width ="100%">
|
||||
<tr bgcolor="#e4e4e4">
|
||||
<td>
|
||||
<a name="cmdhelp"><h2>2.9 Show Usage Command Usage (help)</h2></a>
|
||||
<a name="cmdhelp"><h2>2.10 Show Usage Command Usage (help)</h2></a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -845,7 +874,7 @@ help
|
|||
<table width ="100%">
|
||||
<tr bgcolor="#e4e4e4">
|
||||
<td>
|
||||
<a name="cmdifconfig"><h2>2.10 Show Network Configuration (ifconfig)</h2></a>
|
||||
<a name="cmdifconfig"><h2>2.11 Show Network Configuration (ifconfig)</h2></a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -871,7 +900,7 @@ eth0 HWaddr 00:18:11:80:10:06
|
|||
<table width ="100%">
|
||||
<tr bgcolor="#e4e4e4">
|
||||
<td>
|
||||
<a name="cmdls"><h2>2.11 List Directory Contents (ls)</h2></a>
|
||||
<a name="cmdls"><h2>2.12 List Directory Contents (ls)</h2></a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -908,7 +937,7 @@ ls [-lRs] <dir-path>
|
|||
<table width ="100%">
|
||||
<tr bgcolor="#e4e4e4">
|
||||
<td>
|
||||
<a name="cmdmbhw"><h2>2.12 Access Memory (mb, mh, and mw)</h2></a>
|
||||
<a name="cmdmbhw"><h2>2.13 Access Memory (mb, mh, and mw)</h2></a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -962,7 +991,7 @@ nsh>
|
|||
<table width ="100%">
|
||||
<tr bgcolor="#e4e4e4">
|
||||
<td>
|
||||
<a name="cmdmem"><h2>2.13 Show Memory Manager Status (mem)</h2></a>
|
||||
<a name="cmdmem"><h2>2.14 Show Memory Manager Status (mem)</h2></a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -1011,7 +1040,7 @@ nsh>
|
|||
<table width ="100%">
|
||||
<tr bgcolor="#e4e4e4">
|
||||
<td>
|
||||
<a name="cmdps"><h2>2.14 Show Current Tasks and Threads (ps)</h2></a>
|
||||
<a name="cmdps"><h2>2.15 Show Current Tasks and Threads (ps)</h2></a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -1037,7 +1066,7 @@ nsh>
|
|||
<table width ="100%">
|
||||
<tr bgcolor="#e4e4e4">
|
||||
<td>
|
||||
<a name="cmdmkdir"><h2>2.15 Create a Directory (mkdir)</h2></a>
|
||||
<a name="cmdmkdir"><h2>2.16 Create a Directory (mkdir)</h2></a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -1072,7 +1101,7 @@ nsh>
|
|||
<table width ="100%">
|
||||
<tr bgcolor="#e4e4e4">
|
||||
<td>
|
||||
<a name="cmdmkfatfs"><h2>2.16 Create a FAT Filesystem (mkfatfs)</h2></a>
|
||||
<a name="cmdmkfatfs"><h2>2.17 Create a FAT Filesystem (mkfatfs)</h2></a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -1092,7 +1121,7 @@ mkfatfs <path>
|
|||
<table width ="100%">
|
||||
<tr bgcolor="#e4e4e4">
|
||||
<td>
|
||||
<a name="cmdmkfifo"><h2>2.17 Create a FIFO (mkfifo)</h2></a>
|
||||
<a name="cmdmkfifo"><h2>2.18 Create a FIFO (mkfifo)</h2></a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -1130,7 +1159,7 @@ nsh>
|
|||
<table width ="100%">
|
||||
<tr bgcolor="#e4e4e4">
|
||||
<td>
|
||||
<a name="cmdmkrd"><h2>2.18 Create a RAMDISK (mkrd)</h2></a>
|
||||
<a name="cmdmkrd"><h2>2.19 Create a RAMDISK (mkrd)</h2></a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -1181,7 +1210,7 @@ nsh>
|
|||
<table width ="100%">
|
||||
<tr bgcolor="#e4e4e4">
|
||||
<td>
|
||||
<a name="cmdmount"><h2>2.19 Mount a File System (mount)</h2></a>
|
||||
<a name="cmdmount"><h2>2.20 Mount a File System (mount)</h2></a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -1248,7 +1277,7 @@ nsh>
|
|||
<table width ="100%">
|
||||
<tr bgcolor="#e4e4e4">
|
||||
<td>
|
||||
<a name="cmdping"><h2>2.20 Check Network Peer (ping)</h2></a>
|
||||
<a name="cmdping"><h2>2.21 Check Network Peer (ping)</h2></a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -1281,7 +1310,7 @@ nsh>
|
|||
<table width ="100%">
|
||||
<tr bgcolor="#e4e4e4">
|
||||
<td>
|
||||
<a name="cmdput"><h2>2.21 Send File Via TFTP (put)</h2></a>
|
||||
<a name="cmdput"><h2>2.22 Send File Via TFTP (put)</h2></a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -1316,7 +1345,7 @@ put [-b|-n] [-f <remote-path>] -h <ip-address> <local-path>
|
|||
<table width ="100%">
|
||||
<tr bgcolor="#e4e4e4">
|
||||
<td>
|
||||
<a name="cmdpwd"><h2>2.22 Show Current Working Directory (pwd)</h2></a>
|
||||
<a name="cmdpwd"><h2>2.23 Show Current Working Directory (pwd)</h2></a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -1346,7 +1375,7 @@ nsh>
|
|||
<table width ="100%">
|
||||
<tr bgcolor="#e4e4e4">
|
||||
<td>
|
||||
<a name="cmdrm"><h2>2.23 Remove a File (rm)</h2></a>
|
||||
<a name="cmdrm"><h2>2.24 Remove a File (rm)</h2></a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -1380,7 +1409,7 @@ nsh>
|
|||
<table width ="100%">
|
||||
<tr bgcolor="#e4e4e4">
|
||||
<td>
|
||||
<a name="cmdrmdir"><h2>2.24 Remove a Directory (rmdir)</h2></a>
|
||||
<a name="cmdrmdir"><h2>2.25 Remove a Directory (rmdir)</h2></a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -1415,7 +1444,7 @@ nsh>
|
|||
<table width ="100%">
|
||||
<tr bgcolor="#e4e4e4">
|
||||
<td>
|
||||
<a name="cmdset"><h2>2.25 Set an Environment Variable (set)</h2></a>
|
||||
<a name="cmdset"><h2>2.26 Set an Environment Variable (set)</h2></a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -1441,7 +1470,7 @@ nsh>
|
|||
<table width ="100%">
|
||||
<tr bgcolor="#e4e4e4">
|
||||
<td>
|
||||
<a name="cmdsh"><h2>2.26 Execute an NSH Script (sh)</h2></a>
|
||||
<a name="cmdsh"><h2>2.27 Execute an NSH Script (sh)</h2></a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -1459,7 +1488,7 @@ sh <script-path>
|
|||
<table width ="100%">
|
||||
<tr bgcolor="#e4e4e4">
|
||||
<td>
|
||||
<a name="cmdsleep"><h2>2.27 Wait for Seconds (sleep)</h2></a>
|
||||
<a name="cmdsleep"><h2>2.28 Wait for Seconds (sleep)</h2></a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -1476,7 +1505,7 @@ sleep <sec>
|
|||
<table width ="100%">
|
||||
<tr bgcolor="#e4e4e4">
|
||||
<td>
|
||||
<a name="cmdunmount"><h2>2.28 Unmount a File System (umount)</h2></a>
|
||||
<a name="cmdunmount"><h2>2.29 Unmount a File System (umount)</h2></a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -1506,7 +1535,7 @@ nsh>
|
|||
<table width ="100%">
|
||||
<tr bgcolor="#e4e4e4">
|
||||
<td>
|
||||
<a name="cmdunset"><h2>2.29 Unset an Environment Variable (unset)</h2></a>
|
||||
<a name="cmdunset"><h2>2.30 Unset an Environment Variable (unset)</h2></a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -1532,7 +1561,7 @@ nsh>
|
|||
<table width ="100%">
|
||||
<tr bgcolor="#e4e4e4">
|
||||
<td>
|
||||
<a name="cmdusleep"><h2>2.30 Wait for Microseconds (usleep)</h2></a>
|
||||
<a name="cmdusleep"><h2>2.31 Wait for Microseconds (usleep)</h2></a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -1549,7 +1578,7 @@ usleep <usec>
|
|||
<table width ="100%">
|
||||
<tr bgcolor="#e4e4e4">
|
||||
<td>
|
||||
<a name="cmdxd"><h2>2.31 Hexadecimal dump (xd)</h2></a>
|
||||
<a name="cmdxd"><h2>2.32 Hexadecimal dump (xd)</h2></a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -1632,6 +1661,11 @@ nsh>
|
|||
<td><code>CONFIG_NFILE_DESCRIPTORS</code> > 0</td>
|
||||
<td><code>CONFIG_EXAMPLES_NSH_DISABLE_CP</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><b><code>dd</code></b></td>
|
||||
<td><code>CONFIG_NFILE_DESCRIPTORS</code> > 0</td>
|
||||
<td><code>CONFIG_EXAMPLES_NSH_DISABLE_DD</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><b><code>echo</code></b></td>
|
||||
<td><br></td>
|
||||
|
@ -2076,6 +2110,7 @@ nsh>
|
|||
<li><a href="#nshconfiguration">Configuration settings, NSH-specific</a></li>
|
||||
<li><a href="#cmdcp"><code>cp</code></a></li>
|
||||
<li><a href="#currentwd">Current working directory</a></li>
|
||||
<li><a href="#cmddd"><code>dd</code></a></li>
|
||||
<li><a href="#cmdecho"><code>echo</code></a></li>
|
||||
<li><a href="#environvars">Environment Variables</a></li>
|
||||
<li><a href="#startupscript"><code>/etc/init.d/rcS</code></a>
|
||||
|
|
|
@ -1195,6 +1195,7 @@ 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
|
||||
|
||||
pascal-0.1.3 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
-include $(TOPDIR)/Make.defs
|
||||
|
||||
ASRCS =
|
||||
CSRCS = nsh_main.c nsh_fscmds.c nsh_proccmds.c nsh_envcmds.c nsh_dbgcmds.c
|
||||
CSRCS = nsh_main.c nsh_fscmds.c nsh_ddcmd.c nsh_proccmds.c nsh_envcmds.c nsh_dbgcmds.c
|
||||
|
||||
ifeq ($(CONFIG_EXAMPLES_NSH_ROMFSETC),y)
|
||||
CSRCS += nsh_romfsetc.c
|
||||
|
|
|
@ -250,6 +250,17 @@ o cp <source-path> <dest-path>
|
|||
Copy of the contents of the file at <source-path> to the location
|
||||
in the filesystem indicated by <path-path>
|
||||
|
||||
o dd if=<infile> of=<outfile> [bs=<sectsize>] [count=<sectors>] [skip=<sectors>]
|
||||
|
||||
Copy blocks from <infile> to <outfile>.
|
||||
|
||||
Example:
|
||||
|
||||
nsh> dd if=/dev/zero of=/tmp/zeros bs=64 count=16
|
||||
nsh> ls -l /tmp
|
||||
/tmp:
|
||||
-rw-rw-rw- 1024 ZEROS
|
||||
|
||||
o echo [<string|$name> [<string|$name>...]]
|
||||
|
||||
Copy the sequence of strings and expanded environment variables to
|
||||
|
@ -680,6 +691,7 @@ Command Dependencies on Configuration Settings
|
|||
cat CONFIG_NFILE_DESCRIPTORS > 0
|
||||
cd !CONFIG_DISABLE_ENVIRON && CONFIG_NFILE_DESCRIPTORS > 0
|
||||
cp CONFIG_NFILE_DESCRIPTORS > 0
|
||||
dd CONFIG_NFILE_DESCRIPTORS > 0
|
||||
echo --
|
||||
exec --
|
||||
exit --
|
||||
|
@ -724,17 +736,18 @@ In addition, each NSH command can be individually disabled via one of the follow
|
|||
settings. All of these settings make the configuration of NSH potentially complex but
|
||||
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_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_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
|
||||
|
||||
NSH-Specific Configuration Settings
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
|
@ -366,6 +366,9 @@ extern int cmd_lbracket(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
|||
# ifndef CONFIG_EXAMPLES_NSH_DISABLE_CP
|
||||
extern int cmd_cp(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
# endif
|
||||
# ifndef CONFIG_EXAMPLES_NSH_DISABLE_DD
|
||||
extern int cmd_dd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
# endif
|
||||
# ifndef CONFIG_EXAMPLES_NSH_DISABLE_LS
|
||||
extern int cmd_ls(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
# endif
|
||||
|
|
|
@ -0,0 +1,600 @@
|
|||
/****************************************************************************
|
||||
* examples/nsh/nsh_ddcmd.c
|
||||
*
|
||||
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/fs.h>
|
||||
#include "nsh.h"
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_EXAMPLES_NSH_DISABLE_DD)
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* If no sector size is specified wity BS=, then the following default value
|
||||
* is used.
|
||||
*/
|
||||
|
||||
#define DEFAULT_SECTSIZE 512
|
||||
|
||||
/* At present, piping of input and output are not support, i.e., both of=
|
||||
* and if= arguments are required.
|
||||
*/
|
||||
|
||||
#undef CAN_PIPE_FROM_STD
|
||||
|
||||
/* Function pointer calls are only need if block drivers are supported
|
||||
* (or, rather, if mount points are supported in the file system)
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_DISABLE_MOUNTPOINT
|
||||
# define DD_INFD ((dd)->inf.fd)
|
||||
# define DD_INHANDLE ((dd)->inf.handle)
|
||||
# define DD_OUTFD ((dd)->outf.fd)
|
||||
# define DD_OUTHANDLE ((dd)->outf.handle)
|
||||
# define DD_READ(dd) ((dd)->infread(dd))
|
||||
# define DD_WRITE(dd) ((dd)->outfwrite(dd))
|
||||
# define DD_INCLOSE(dd) ((dd)->infclose(dd))
|
||||
# define DD_OUTCLOSE(dd) ((dd)->outfclose(dd))
|
||||
#else
|
||||
# define DD_INFD ((dd)->infd)
|
||||
# undef DD_INHANDLE
|
||||
# define DD_OUTFD ((dd)->outfd)
|
||||
# undef DD_OUTHANDLE
|
||||
# define DD_READ(dd) dd_readch(dd)
|
||||
# define DD_WRITE(dd) dd_writech(dd)
|
||||
# define DD_INCLOSE(dd) dd_infclosech(dd)
|
||||
# define DD_OUTCLOSE(dd) dd_outfclosech(dd)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
struct dd_s
|
||||
{
|
||||
FAR struct nsh_vtbl_s *vtbl;
|
||||
|
||||
#ifndef CONFIG_DISABLE_MOUNTPOINT
|
||||
union
|
||||
{
|
||||
FAR void *handle; /* BCH lib handle for block device*/
|
||||
int fd; /* File descriptor of the character device */
|
||||
} inf;
|
||||
#else
|
||||
int infd; /* File descriptor of the input device */
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_DISABLE_MOUNTPOINT
|
||||
union
|
||||
{
|
||||
FAR void *handle; /* BCH lib handle for block device*/
|
||||
int fd; /* File descriptor of the character device */
|
||||
} outf;
|
||||
#else
|
||||
int outfd; /* File descriptor of the output device */
|
||||
#endif
|
||||
|
||||
uint32 nsectors; /* Number of sectors to transfer */
|
||||
uint32 sector; /* The current sector number */
|
||||
uint32 skip; /* The number of sectors skipped on input */
|
||||
boolean eof; /* TRUE: The of the input or output file has been hit */
|
||||
uint16 sectsize; /* Size of one sector */
|
||||
uint16 nbytes; /* Number of valid bytes in the buffer */
|
||||
ubyte *buffer; /* Buffer of data to write to the output file */
|
||||
|
||||
/* Function pointers to handle differences between block and character devices */
|
||||
|
||||
#ifndef CONFIG_DISABLE_MOUNTPOINT
|
||||
int (*infread)(struct dd_s *dd);
|
||||
void (*infclose)(struct dd_s *dd);
|
||||
int (*outfwrite)(struct dd_s *dd);
|
||||
void (*outfclose)(struct dd_s *dd);
|
||||
#endif
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static const char g_dd[] = "dd";
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dd_outfcloseblk
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_DISABLE_MOUNTPOINT
|
||||
static void dd_outfcloseblk(struct dd_s *dd)
|
||||
{
|
||||
(void)bchlib_teardown(DD_OUTHANDLE);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dd_outfclosech
|
||||
****************************************************************************/
|
||||
|
||||
static void dd_outfclosech(struct dd_s *dd)
|
||||
{
|
||||
(void)close(DD_OUTFD);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dd_infcloseblk
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_DISABLE_MOUNTPOINT
|
||||
static void dd_infcloseblk(struct dd_s *dd)
|
||||
{
|
||||
(void)bchlib_teardown(DD_INHANDLE);
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dd_infclosech
|
||||
****************************************************************************/
|
||||
|
||||
static void dd_infclosech(struct dd_s *dd)
|
||||
{
|
||||
(void)close(DD_INFD);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dd_writeblk
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_DISABLE_MOUNTPOINT
|
||||
static int dd_writeblk(struct dd_s *dd)
|
||||
{
|
||||
ssize_t nbytes;
|
||||
off_t offset = (dd->sector - dd->skip) * dd->sectsize;
|
||||
|
||||
nbytes = bchlib_write(DD_OUTHANDLE, (char*)dd->buffer, offset, dd->sectsize);
|
||||
if (nbytes < 0)
|
||||
{
|
||||
nsh_output(dd->vtbl, g_fmtcmdfailed, g_dd, "bshlib_write", NSH_ERRNO);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dd_writech
|
||||
****************************************************************************/
|
||||
|
||||
static int dd_writech(struct dd_s *dd)
|
||||
{
|
||||
ubyte *buffer = dd->buffer;
|
||||
uint16 written ;
|
||||
ssize_t nbytes;
|
||||
|
||||
/* Is the out buffer full (or is this the last one)? */
|
||||
|
||||
written = 0;
|
||||
do
|
||||
{
|
||||
nbytes = write(DD_OUTFD, buffer, dd->sectsize - written);
|
||||
if (nbytes < 0)
|
||||
{
|
||||
nsh_output(dd->vtbl, g_fmtcmdfailed, g_dd, "write", NSH_ERRNO);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
written += nbytes;
|
||||
buffer += nbytes;
|
||||
}
|
||||
while (written < dd->sectsize);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dd_readblk
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_DISABLE_MOUNTPOINT
|
||||
static int dd_readblk(struct dd_s *dd)
|
||||
{
|
||||
ssize_t nbytes;
|
||||
off_t offset = dd->sector * dd->sectsize;
|
||||
|
||||
nbytes = bchlib_read(DD_INHANDLE, (char*)dd->buffer, offset, dd->sectsize);
|
||||
if (nbytes < 0)
|
||||
{
|
||||
nsh_output(dd->vtbl, g_fmtcmdfailed, g_dd, "bshlib_read", NSH_ERRNO);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
dd->nbytes = nbytes;
|
||||
return OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dd_readch
|
||||
****************************************************************************/
|
||||
|
||||
static int dd_readch(struct dd_s *dd)
|
||||
{
|
||||
ubyte *buffer = dd->buffer;
|
||||
ssize_t nbytes;
|
||||
|
||||
dd->nbytes = 0;
|
||||
do
|
||||
{
|
||||
nbytes = read(DD_INFD, buffer, dd->sectsize - dd->nbytes);
|
||||
if (nbytes < 0)
|
||||
{
|
||||
nsh_output(dd->vtbl, g_fmtcmdfailed, g_dd, "read", NSH_ERRNO);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
dd->nbytes += nbytes;
|
||||
buffer += nbytes;
|
||||
}
|
||||
while (dd->nbytes < dd->sectsize && nbytes > 0);
|
||||
|
||||
dd->eof |= (dd->nbytes == 0);
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dd_infopen
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_DISABLE_MOUNTPOINT
|
||||
static int dd_filetype(const char *filename)
|
||||
{
|
||||
struct stat sb;
|
||||
int ret;
|
||||
|
||||
/* Get the type of the file */
|
||||
|
||||
ret = stat(filename, &sb);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ERROR; /* Return -1 on failure */
|
||||
}
|
||||
|
||||
return S_ISBLK(sb.st_mode); /* Return TRUE(1) if block, FALSE(0) if char */
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dd_infopen
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_DISABLE_MOUNTPOINT
|
||||
static inline int dd_infopen(const char *name, struct dd_s *dd)
|
||||
{
|
||||
int ret;
|
||||
int type;
|
||||
|
||||
/* Get the type of the input file */
|
||||
|
||||
type = dd_filetype(name);
|
||||
if (type < 0)
|
||||
{
|
||||
nsh_output(dd->vtbl, g_fmtcmdfailed, g_dd, "stat", NSH_ERRNO);
|
||||
return type;
|
||||
}
|
||||
|
||||
/* Open the input file */
|
||||
|
||||
if (!type)
|
||||
{
|
||||
DD_INFD = open(name, O_RDONLY);
|
||||
if (DD_INFD < 0)
|
||||
{
|
||||
nsh_output(dd->vtbl, g_fmtcmdfailed, g_dd, "open", NSH_ERRNO);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
dd->infread = dd_readch; /* Character oriented read */
|
||||
dd->infclose = dd_infclosech;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = bchlib_setup(name, TRUE, &DD_INHANDLE);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
dd->infread = dd_readblk;
|
||||
dd->infclose = dd_infcloseblk;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
#else
|
||||
static inline int dd_infopen(const char *name, struct dd_s *dd)
|
||||
{
|
||||
DD_INFD = open(name, O_RDONLY);
|
||||
if (DD_INFD < 0)
|
||||
{
|
||||
nsh_output(dd->vtbl, g_fmtcmdfailed, g_dd, "open", NSH_ERRNO);
|
||||
return ERROR;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: dd_outfopen
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_DISABLE_MOUNTPOINT
|
||||
static inline int dd_outfopen(const char *name, struct dd_s *dd)
|
||||
{
|
||||
int type;
|
||||
int ret = OK;
|
||||
|
||||
/* Get the type of the output file */
|
||||
|
||||
type = dd_filetype(name);
|
||||
|
||||
/* Open the block driver for input */
|
||||
|
||||
if (type == TRUE)
|
||||
{
|
||||
ret = bchlib_setup(name, TRUE, &DD_OUTHANDLE);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
dd->outfwrite = dd_writeblk; /* Block oriented write */
|
||||
dd->outfclose = dd_outfcloseblk;
|
||||
}
|
||||
|
||||
/* Otherwise, the file is character oriented or does not exist */
|
||||
|
||||
else
|
||||
{
|
||||
DD_OUTFD = open(name, O_WRONLY|O_CREAT|O_TRUNC, 0644);
|
||||
if (DD_OUTFD < 0)
|
||||
{
|
||||
nsh_output(dd->vtbl, g_fmtcmdfailed, g_dd, "open", NSH_ERRNO);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
dd->outfwrite = dd_writech; /* Character oriented write */
|
||||
dd->outfclose = dd_outfclosech;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
#else
|
||||
static inline int dd_outfopen(const char *name, struct dd_s *dd)
|
||||
{
|
||||
DD_OUTFD = open(name, O_WRONLY|O_CREAT|O_TRUNC, 0644);
|
||||
if (DD_OUTFD < 0)
|
||||
{
|
||||
nsh_output(dd->vtbl, g_fmtcmdfailed, g_dd, "open", NSH_ERRNO);
|
||||
return ERROR;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: cmd_dd
|
||||
****************************************************************************/
|
||||
|
||||
int cmd_dd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
struct dd_s dd;
|
||||
const char *infile = NULL;
|
||||
const char *outfile = NULL;
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
/* Initialize the dd structure */
|
||||
|
||||
memset(&dd, 0, sizeof(struct dd_s));
|
||||
dd.vtbl = vtbl; /* For nsh_output */
|
||||
dd.sectsize = DEFAULT_SECTSIZE; /* Sector size if 'bs=' not provided */
|
||||
dd.nsectors = 0xffffffff; /* MAX_UINT32 */
|
||||
|
||||
/* If no IF= option is provided on the command line, then read
|
||||
* from stdin.
|
||||
*/
|
||||
|
||||
#ifdef CAN_PIPE_FROM_STD
|
||||
DD_INFD = 0; /* stdin */
|
||||
#ifndef CONFIG_EXAMPLES_NSH_DISABLE_DD
|
||||
dd.infread = readch; /* Character oriented read */
|
||||
dd.infclose = noclose; /* Don't close stdin */
|
||||
#endif
|
||||
#endif
|
||||
/* If no OF= option is provided on the command line, then write
|
||||
* to stdout.
|
||||
*/
|
||||
|
||||
#ifdef CAN_PIPE_FROM_STD
|
||||
DD_OUTDF = 1; /* stdout */
|
||||
#ifndef CONFIG_EXAMPLES_NSH_DISABLE_DD
|
||||
dd.outfwrite = writech; /* Character oriented write */
|
||||
dd.outfclose = noclose; /* Don't close stdout */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Parse command line parameters */
|
||||
|
||||
for (i = 1; i < argc; i++)
|
||||
{
|
||||
if (strncmp(argv[i], "if=", 3) == 0)
|
||||
{
|
||||
infile = &argv[i][3];
|
||||
}
|
||||
else if (strncmp(argv[i], "of=", 3) == 0)
|
||||
{
|
||||
outfile = &argv[i][3];
|
||||
}
|
||||
else if (strncmp(argv[i], "bs=", 3) == 0)
|
||||
{
|
||||
dd.sectsize = atoi(&argv[i][3]);
|
||||
}
|
||||
else if (strncmp(argv[i], "count=", 6) == 0)
|
||||
{
|
||||
dd.nsectors = atoi(&argv[i][6]);
|
||||
}
|
||||
else if (strncmp(argv[i], "skip=", 5) == 0)
|
||||
{
|
||||
dd.skip = atoi(&argv[i][5]);
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef CAN_PIPE_FROM_STD
|
||||
if (!infile || !outfile)
|
||||
{
|
||||
nsh_output(vtbl, g_fmtargrequired, g_dd);
|
||||
return ERROR;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (dd.skip < 0 || dd.skip > dd.nsectors)
|
||||
{
|
||||
nsh_output(vtbl, g_fmtarginvalid, g_dd);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* Allocate the I/O buffer */
|
||||
|
||||
dd.buffer = malloc(dd.sectsize);
|
||||
if (!dd.buffer)
|
||||
{
|
||||
nsh_output(vtbl, g_fmtcmdoutofmemory, g_dd);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* Open the input file */
|
||||
|
||||
ret = dd_infopen(infile, &dd);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Open the output file */
|
||||
|
||||
ret = dd_outfopen(outfile, &dd);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto errout_with_inf;
|
||||
}
|
||||
|
||||
/* Then perform the data transfer */
|
||||
|
||||
dd.sector = 0;
|
||||
while (!dd.eof && dd.nsectors > 0)
|
||||
{
|
||||
/* Read one sector from from the input */
|
||||
|
||||
ret = DD_READ(&dd);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto errout_with_outf;
|
||||
}
|
||||
|
||||
/* Pad with zero if necessary (at the end of file only) */
|
||||
|
||||
for (i = dd.nbytes; i < dd.sectsize; i++)
|
||||
{
|
||||
dd.buffer[i] = 0;
|
||||
}
|
||||
|
||||
/* Write one sector to the output file */
|
||||
|
||||
if (dd.sector >= dd.skip)
|
||||
{
|
||||
ret = DD_WRITE(&dd);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto errout_with_outf;
|
||||
}
|
||||
|
||||
/* Decrement to show that a sector was written */
|
||||
|
||||
dd.nsectors--;
|
||||
}
|
||||
|
||||
/* Increment the sector number */
|
||||
|
||||
dd.sector++;
|
||||
}
|
||||
|
||||
errout_with_outf:
|
||||
DD_INCLOSE(&dd);
|
||||
errout_with_inf:
|
||||
DD_OUTCLOSE(&dd);
|
||||
free(dd.buffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NFILE_DESCRIPTORS && !CONFIG_EXAMPLES_NSH_DISABLE_DD */
|
|
@ -151,6 +151,12 @@ static const struct cmdmap_s g_cmdmap[] =
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
# ifndef CONFIG_EXAMPLES_NSH_DISABLE_LS
|
||||
{ "dd", cmd_dd, 3, 6, "if=<infile> of=<outfile> [bs=<sectsize>] [count=<sectors>] [skip=<sectors>]" },
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NSH_DISABLE_ECHO
|
||||
# ifndef CONFIG_DISABLE_ENVIRON
|
||||
{ "echo", cmd_echo, 0, NSH_MAX_ARGUMENTS, "[<string|$name> [<string|$name>...]]" },
|
||||
|
|
|
@ -67,6 +67,8 @@ EXTERN char *strcat(char *, const char *);
|
|||
EXTERN char *strncat(char *, const char *, size_t);
|
||||
EXTERN int strcmp(const char *, const char *);
|
||||
EXTERN int strncmp(const char *, const char *, size_t);
|
||||
EXTERN int strcasecmp(const char *, const char *);
|
||||
EXTERN int strncasecmp(const char *, const char *, size_t);
|
||||
EXTERN char *strcpy(char *dest, const char *src);
|
||||
EXTERN char *strncpy(char *, const char *, size_t);
|
||||
EXTERN char *strpbrk(const char *, const char *);
|
||||
|
|
Loading…
Reference in New Issue