2011-03-18 20:46:25 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* apps/nshlib/nsh_ddcmd.c
|
|
|
|
*
|
2021-06-10 16:34:12 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2011-03-18 20:46:25 +01:00
|
|
|
*
|
2021-06-10 16:34:12 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-03-18 20:46:25 +01:00
|
|
|
*
|
2021-06-10 16:34:12 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2011-03-18 20:46:25 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2023-02-21 23:08:13 +01:00
|
|
|
#include <nuttx/clock.h>
|
|
|
|
|
2011-03-18 20:46:25 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2012-02-02 17:04:09 +01:00
|
|
|
|
2023-07-26 09:07:34 +02:00
|
|
|
#include <stdio.h>
|
2011-03-18 20:46:25 +01:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <debug.h>
|
|
|
|
#include <errno.h>
|
2016-12-20 01:33:34 +01:00
|
|
|
#include <time.h>
|
2011-03-18 20:46:25 +01:00
|
|
|
|
|
|
|
#include "nsh.h"
|
2012-02-02 17:04:09 +01:00
|
|
|
#include "nsh_console.h"
|
2011-03-18 20:46:25 +01:00
|
|
|
|
2019-02-11 20:10:10 +01:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_DD
|
2011-03-18 20:46:25 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
2014-09-07 18:46:06 +02:00
|
|
|
* Pre-processor Definitions
|
2011-03-18 20:46:25 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2017-05-11 15:46:08 +02:00
|
|
|
/* If no sector size is specified with BS=, then the following default value
|
2011-03-18 20:46:25 +01:00
|
|
|
* 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
|
|
|
|
|
2023-06-08 13:37:31 +02:00
|
|
|
#define g_dd "dd"
|
|
|
|
|
2011-03-18 20:46:25 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
struct dd_s
|
|
|
|
{
|
|
|
|
FAR struct nsh_vtbl_s *vtbl;
|
|
|
|
|
2022-09-22 05:38:12 +02:00
|
|
|
int infd; /* File descriptor of the input device */
|
|
|
|
int outfd; /* File descriptor of the output device */
|
|
|
|
uint32_t nsectors; /* Number of sectors to transfer */
|
|
|
|
uint32_t skip; /* The number of sectors skipped on input */
|
|
|
|
bool eof; /* true: The end of the input or output file has been hit */
|
2022-11-08 04:53:33 +01:00
|
|
|
bool verify; /* true: Verify infile and outfile correctness */
|
2023-06-26 03:42:20 +02:00
|
|
|
size_t sectsize; /* Size of one sector */
|
|
|
|
size_t nbytes; /* Number of valid bytes in the buffer */
|
2022-09-22 05:38:12 +02:00
|
|
|
FAR uint8_t *buffer; /* Buffer of data to write to the output file */
|
2011-03-18 20:46:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2015-11-21 18:57:41 +01:00
|
|
|
* Name: dd_write
|
2011-03-18 20:46:25 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2019-06-03 17:19:09 +02:00
|
|
|
static int dd_write(FAR struct dd_s *dd)
|
2011-03-18 20:46:25 +01:00
|
|
|
{
|
2019-06-03 17:19:09 +02:00
|
|
|
FAR uint8_t *buffer = dd->buffer;
|
2023-06-26 03:42:20 +02:00
|
|
|
size_t written;
|
2011-03-18 20:46:25 +01:00
|
|
|
ssize_t nbytes;
|
|
|
|
|
|
|
|
/* Is the out buffer full (or is this the last one)? */
|
|
|
|
|
|
|
|
written = 0;
|
|
|
|
do
|
|
|
|
{
|
2022-02-21 10:39:09 +01:00
|
|
|
nbytes = write(dd->outfd, buffer, dd->nbytes - written);
|
2011-03-18 20:46:25 +01:00
|
|
|
if (nbytes < 0)
|
|
|
|
{
|
2020-10-29 10:17:32 +01:00
|
|
|
FAR struct nsh_vtbl_s *vtbl = dd->vtbl;
|
|
|
|
nsh_error(vtbl, g_fmtcmdfailed, g_dd, "write",
|
|
|
|
NSH_ERRNO_OF(-nbytes));
|
|
|
|
return ERROR;
|
2011-03-18 20:46:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
written += nbytes;
|
|
|
|
buffer += nbytes;
|
|
|
|
}
|
2022-02-21 10:39:09 +01:00
|
|
|
while (written < dd->nbytes);
|
2011-03-18 20:46:25 +01:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2015-11-21 18:57:41 +01:00
|
|
|
* Name: dd_read
|
2011-03-18 20:46:25 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2019-06-03 17:19:09 +02:00
|
|
|
static int dd_read(FAR struct dd_s *dd)
|
2011-03-18 20:46:25 +01:00
|
|
|
{
|
2019-06-03 17:19:09 +02:00
|
|
|
FAR uint8_t *buffer = dd->buffer;
|
2011-03-18 20:46:25 +01:00
|
|
|
ssize_t nbytes;
|
|
|
|
|
|
|
|
dd->nbytes = 0;
|
|
|
|
do
|
|
|
|
{
|
2015-11-21 18:57:41 +01:00
|
|
|
nbytes = read(dd->infd, buffer, dd->sectsize - dd->nbytes);
|
2011-03-18 20:46:25 +01:00
|
|
|
if (nbytes < 0)
|
|
|
|
{
|
2020-10-29 10:17:32 +01:00
|
|
|
FAR struct nsh_vtbl_s *vtbl = dd->vtbl;
|
|
|
|
nsh_error(vtbl, g_fmtcmdfailed, g_dd, "read",
|
|
|
|
NSH_ERRNO_OF(-nbytes));
|
|
|
|
return ERROR;
|
2011-03-18 20:46:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
dd->nbytes += nbytes;
|
|
|
|
buffer += nbytes;
|
|
|
|
}
|
|
|
|
while (dd->nbytes < dd->sectsize && nbytes > 0);
|
|
|
|
|
|
|
|
dd->eof |= (dd->nbytes == 0);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: dd_infopen
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-06-03 17:19:09 +02:00
|
|
|
static inline int dd_infopen(FAR const char *name, FAR struct dd_s *dd)
|
2011-03-18 20:46:25 +01:00
|
|
|
{
|
2015-11-21 18:57:41 +01:00
|
|
|
dd->infd = open(name, O_RDONLY);
|
|
|
|
if (dd->infd < 0)
|
2011-03-18 20:46:25 +01:00
|
|
|
{
|
|
|
|
FAR struct nsh_vtbl_s *vtbl = dd->vtbl;
|
2018-12-09 01:53:54 +01:00
|
|
|
nsh_error(vtbl, g_fmtcmdfailed, g_dd, "open", NSH_ERRNO);
|
2011-03-18 20:46:25 +01:00
|
|
|
return ERROR;
|
|
|
|
}
|
2014-01-11 16:50:54 +01:00
|
|
|
|
2011-03-18 20:46:25 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: dd_outfopen
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-06-03 17:19:09 +02:00
|
|
|
static inline int dd_outfopen(FAR const char *name, FAR struct dd_s *dd)
|
2011-03-18 20:46:25 +01:00
|
|
|
{
|
2022-11-08 04:53:33 +01:00
|
|
|
dd->outfd = open(name, (dd->verify ? O_RDWR : O_WRONLY) |
|
|
|
|
O_CREAT | O_TRUNC, 0644);
|
2015-11-21 18:57:41 +01:00
|
|
|
if (dd->outfd < 0)
|
2011-03-18 20:46:25 +01:00
|
|
|
{
|
2019-06-03 19:32:56 +02:00
|
|
|
FAR struct nsh_vtbl_s *vtbl = dd->vtbl;
|
|
|
|
nsh_error(vtbl, g_fmtcmdfailed, g_dd, "open", NSH_ERRNO);
|
2011-03-18 20:46:25 +01:00
|
|
|
return ERROR;
|
|
|
|
}
|
2014-01-11 16:50:54 +01:00
|
|
|
|
2011-03-18 20:46:25 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2022-11-08 04:53:33 +01:00
|
|
|
static int dd_verify(FAR const char *infile, FAR const char *outfile,
|
|
|
|
FAR struct dd_s *dd)
|
|
|
|
{
|
|
|
|
FAR uint8_t *buffer;
|
2023-01-29 20:40:51 +01:00
|
|
|
unsigned sector = 0;
|
2022-11-08 04:53:33 +01:00
|
|
|
int ret = OK;
|
|
|
|
|
2023-01-29 20:40:51 +01:00
|
|
|
UNUSED(infile);
|
|
|
|
UNUSED(outfile);
|
|
|
|
|
2022-11-08 04:53:33 +01:00
|
|
|
ret = lseek(dd->infd, dd->skip ? dd->skip * dd->sectsize : 0, SEEK_SET);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
nsh_error(dd->vtbl, g_fmtcmdfailed, g_dd, "lseek", NSH_ERRNO);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
dd->eof = 0;
|
|
|
|
ret = lseek(dd->outfd, 0, SEEK_SET);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
nsh_error(dd->vtbl, g_fmtcmdfailed, g_dd, "lseek", NSH_ERRNO);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer = malloc(dd->sectsize);
|
|
|
|
if (buffer == NULL)
|
|
|
|
{
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!dd->eof && sector < dd->nsectors)
|
|
|
|
{
|
|
|
|
ret = dd_read(dd);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = read(dd->outfd, buffer, dd->nbytes);
|
|
|
|
if (ret != dd->nbytes)
|
|
|
|
{
|
|
|
|
nsh_error(dd->vtbl, g_fmtcmdfailed, g_dd, "read", NSH_ERRNO);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (memcmp(dd->buffer, buffer, dd->nbytes) != 0)
|
|
|
|
{
|
2023-07-26 09:07:34 +02:00
|
|
|
char msg[32];
|
|
|
|
snprintf(msg, sizeof(msg), "infile sector %d", sector);
|
|
|
|
nsh_dumpbuffer(dd->vtbl, msg, dd->buffer, dd->nbytes);
|
|
|
|
snprintf(msg, sizeof(msg), "\noutfile sector %d", sector);
|
|
|
|
nsh_dumpbuffer(dd->vtbl, msg, buffer, dd->nbytes);
|
2022-11-08 04:53:33 +01:00
|
|
|
nsh_output(dd->vtbl, "\n");
|
|
|
|
ret = ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
sector++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
nsh_error(dd->vtbl, g_fmtcmdfailed, g_dd, "dd_verify", ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(buffer);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-03-18 20:46:25 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: cmd_dd
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-09-22 05:38:12 +02:00
|
|
|
int cmd_dd(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
|
2011-03-18 20:46:25 +01:00
|
|
|
{
|
|
|
|
struct dd_s dd;
|
2019-06-03 17:19:09 +02:00
|
|
|
FAR char *infile = NULL;
|
|
|
|
FAR char *outfile = NULL;
|
2016-12-20 01:33:34 +01:00
|
|
|
#ifdef CONFIG_NSH_CMDOPT_DD_STATS
|
|
|
|
struct timespec ts0;
|
|
|
|
struct timespec ts1;
|
|
|
|
uint64_t elapsed;
|
|
|
|
uint64_t total;
|
|
|
|
#endif
|
2022-11-08 08:22:11 +01:00
|
|
|
uint32_t sector = 0;
|
2011-03-18 20:46:25 +01:00
|
|
|
int ret = ERROR;
|
|
|
|
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
|
2015-11-21 18:57:41 +01:00
|
|
|
dd->infd = 0; /* stdin */
|
2011-03-18 20:46:25 +01:00
|
|
|
#endif
|
2015-11-21 18:57:41 +01:00
|
|
|
|
2011-03-18 20:46:25 +01:00
|
|
|
/* If no OF= option is provided on the command line, then write
|
|
|
|
* to stdout.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef CAN_PIPE_FROM_STD
|
2015-11-21 18:57:41 +01:00
|
|
|
dd->outfd = 1; /* stdout */
|
2011-03-18 20:46:25 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Parse command line parameters */
|
|
|
|
|
|
|
|
for (i = 1; i < argc; i++)
|
|
|
|
{
|
|
|
|
if (strncmp(argv[i], "if=", 3) == 0)
|
|
|
|
{
|
2017-09-25 15:34:34 +02:00
|
|
|
if (infile != NULL)
|
|
|
|
{
|
|
|
|
free(infile);
|
|
|
|
}
|
|
|
|
|
2011-03-18 20:46:25 +01:00
|
|
|
infile = nsh_getfullpath(vtbl, &argv[i][3]);
|
|
|
|
}
|
|
|
|
else if (strncmp(argv[i], "of=", 3) == 0)
|
|
|
|
{
|
2017-09-25 15:34:34 +02:00
|
|
|
if (outfile != NULL)
|
|
|
|
{
|
|
|
|
free(outfile);
|
|
|
|
}
|
|
|
|
|
2011-03-18 20:46:25 +01:00
|
|
|
outfile = nsh_getfullpath(vtbl, &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]);
|
|
|
|
}
|
2022-11-08 04:53:33 +01:00
|
|
|
else if (strncmp(argv[i], "verify", 6) == 0)
|
|
|
|
{
|
|
|
|
dd.verify = true;
|
|
|
|
}
|
2011-03-18 20:46:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef CAN_PIPE_FROM_STD
|
2017-09-25 15:34:34 +02:00
|
|
|
if (infile == NULL || outfile == NULL)
|
2011-03-18 20:46:25 +01:00
|
|
|
{
|
2018-12-09 01:53:54 +01:00
|
|
|
nsh_error(vtbl, g_fmtargrequired, g_dd);
|
2011-03-18 20:46:25 +01:00
|
|
|
goto errout_with_paths;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Allocate the I/O buffer */
|
|
|
|
|
|
|
|
dd.buffer = malloc(dd.sectsize);
|
|
|
|
if (!dd.buffer)
|
|
|
|
{
|
2018-12-09 01:53:54 +01:00
|
|
|
nsh_error(vtbl, g_fmtcmdoutofmemory, g_dd);
|
2011-03-18 20:46:25 +01:00
|
|
|
goto errout_with_paths;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Open the input file */
|
|
|
|
|
|
|
|
ret = dd_infopen(infile, &dd);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2023-05-16 11:39:35 +02:00
|
|
|
goto errout_with_alloc;
|
2011-03-18 20:46:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Open the output file */
|
|
|
|
|
|
|
|
ret = dd_outfopen(outfile, &dd);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
goto errout_with_inf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Then perform the data transfer */
|
|
|
|
|
2016-12-20 01:33:34 +01:00
|
|
|
#ifdef CONFIG_NSH_CMDOPT_DD_STATS
|
2020-01-02 13:09:50 +01:00
|
|
|
clock_gettime(CLOCK_MONOTONIC, &ts0);
|
2016-12-20 01:33:34 +01:00
|
|
|
#endif
|
|
|
|
|
2022-11-08 08:22:11 +01:00
|
|
|
if (dd.skip)
|
|
|
|
{
|
|
|
|
ret = lseek(dd.infd, dd.skip * dd.sectsize, SEEK_SET);
|
|
|
|
if (ret < -1)
|
|
|
|
{
|
|
|
|
nsh_error(vtbl, g_fmtcmdfailed, g_dd, "lseek", NSH_ERRNO);
|
|
|
|
ret = ERROR;
|
|
|
|
goto errout_with_outf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!dd.eof && sector < dd.nsectors)
|
2011-03-18 20:46:25 +01:00
|
|
|
{
|
|
|
|
/* Read one sector from from the input */
|
|
|
|
|
2015-11-21 18:57:41 +01:00
|
|
|
ret = dd_read(&dd);
|
2011-03-18 20:46:25 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
goto errout_with_outf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Has the incoming data stream ended? */
|
|
|
|
|
|
|
|
if (!dd.eof)
|
|
|
|
{
|
|
|
|
/* Write one sector to the output file */
|
|
|
|
|
2022-11-08 08:22:11 +01:00
|
|
|
ret = dd_write(&dd);
|
|
|
|
if (ret < 0)
|
2011-03-18 20:46:25 +01:00
|
|
|
{
|
2022-11-08 08:22:11 +01:00
|
|
|
goto errout_with_outf;
|
2011-03-18 20:46:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Increment the sector number */
|
|
|
|
|
2022-11-08 08:22:11 +01:00
|
|
|
sector++;
|
2011-03-18 20:46:25 +01:00
|
|
|
}
|
|
|
|
}
|
2014-01-11 16:50:54 +01:00
|
|
|
|
2011-03-18 20:46:25 +01:00
|
|
|
ret = OK;
|
|
|
|
|
2016-12-20 01:33:34 +01:00
|
|
|
#ifdef CONFIG_NSH_CMDOPT_DD_STATS
|
2020-01-02 13:09:50 +01:00
|
|
|
clock_gettime(CLOCK_MONOTONIC, &ts1);
|
2016-12-20 01:33:34 +01:00
|
|
|
|
|
|
|
elapsed = (((uint64_t)ts1.tv_sec * NSEC_PER_SEC) + ts1.tv_nsec);
|
|
|
|
elapsed -= (((uint64_t)ts0.tv_sec * NSEC_PER_SEC) + ts0.tv_nsec);
|
2022-07-15 10:23:39 +02:00
|
|
|
elapsed /= NSEC_PER_USEC; /* usec */
|
2016-12-20 01:33:34 +01:00
|
|
|
|
2022-11-08 08:22:11 +01:00
|
|
|
total = ((uint64_t)sector * (uint64_t)dd.sectsize);
|
2016-12-20 01:33:34 +01:00
|
|
|
|
2022-07-15 10:23:39 +02:00
|
|
|
nsh_output(vtbl, "%llu bytes copied, %u usec, ",
|
2016-12-20 01:33:34 +01:00
|
|
|
total, (unsigned int)elapsed);
|
|
|
|
nsh_output(vtbl, "%u KB/s\n" ,
|
2022-07-15 10:23:39 +02:00
|
|
|
(unsigned int)(((double)total / 1024)
|
|
|
|
/ ((double)elapsed / USEC_PER_SEC)));
|
2016-12-20 01:33:34 +01:00
|
|
|
#endif
|
|
|
|
|
2022-11-08 04:53:33 +01:00
|
|
|
if (ret == 0 && dd.verify)
|
|
|
|
{
|
|
|
|
ret = dd_verify(infile, outfile, &dd);
|
|
|
|
}
|
|
|
|
|
2011-03-18 20:46:25 +01:00
|
|
|
errout_with_outf:
|
2020-01-02 13:09:50 +01:00
|
|
|
close(dd.outfd);
|
2014-01-11 16:50:54 +01:00
|
|
|
|
2011-03-18 20:46:25 +01:00
|
|
|
errout_with_inf:
|
2020-01-02 13:09:50 +01:00
|
|
|
close(dd.infd);
|
2023-05-16 11:39:35 +02:00
|
|
|
|
|
|
|
errout_with_alloc:
|
2011-03-18 20:46:25 +01:00
|
|
|
free(dd.buffer);
|
2014-01-11 16:50:54 +01:00
|
|
|
|
2011-03-18 20:46:25 +01:00
|
|
|
errout_with_paths:
|
|
|
|
if (infile)
|
|
|
|
{
|
2015-12-02 17:54:55 +01:00
|
|
|
nsh_freefullpath(infile);
|
2011-03-18 20:46:25 +01:00
|
|
|
}
|
2014-01-11 16:50:54 +01:00
|
|
|
|
2011-03-18 20:46:25 +01:00
|
|
|
if (outfile)
|
|
|
|
{
|
2015-12-02 17:54:55 +01:00
|
|
|
nsh_freefullpath(outfile);
|
2011-03-18 20:46:25 +01:00
|
|
|
}
|
2014-01-11 16:50:54 +01:00
|
|
|
|
2011-03-18 20:46:25 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-02-11 20:10:10 +01:00
|
|
|
#endif /* !CONFIG_NSH_DISABLE_DD */
|