dd: make it recognize not only 'k' but 'K' too;
make it (partially) CONFIG_LFS-aware
This commit is contained in:
@@ -17,6 +17,7 @@ static const struct suffix_mult dd_suffixes[] = {
|
|||||||
{ "b", 512 },
|
{ "b", 512 },
|
||||||
{ "kD", 1000 },
|
{ "kD", 1000 },
|
||||||
{ "k", 1024 },
|
{ "k", 1024 },
|
||||||
|
{ "K", 1024 }, // compat with coreutils dd
|
||||||
{ "MD", 1000000 },
|
{ "MD", 1000000 },
|
||||||
{ "M", 1048576 },
|
{ "M", 1048576 },
|
||||||
{ "GD", 1000000000 },
|
{ "GD", 1000000000 },
|
||||||
@@ -24,13 +25,14 @@ static const struct suffix_mult dd_suffixes[] = {
|
|||||||
{ NULL, 0 }
|
{ NULL, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
static size_t out_full, out_part, in_full, in_part;
|
static FILEOFF_TYPE out_full, out_part, in_full, in_part;
|
||||||
|
|
||||||
static void dd_output_status(int ATTRIBUTE_UNUSED cur_signal)
|
static void dd_output_status(int ATTRIBUTE_UNUSED cur_signal)
|
||||||
{
|
{
|
||||||
bb_fprintf(stderr, "%ld+%ld records in\n%ld+%ld records out\n",
|
bb_fprintf(stderr, FILEOFF_FMT"+"FILEOFF_FMT" records in\n"
|
||||||
(long)in_full, (long)in_part,
|
FILEOFF_FMT"+"FILEOFF_FMT" records out\n",
|
||||||
(long)out_full, (long)out_part);
|
in_full, in_part,
|
||||||
|
out_full, out_part);
|
||||||
}
|
}
|
||||||
|
|
||||||
int dd_main(int argc, char **argv)
|
int dd_main(int argc, char **argv)
|
||||||
@@ -40,9 +42,9 @@ int dd_main(int argc, char **argv)
|
|||||||
#define trunc_flag (1<<2)
|
#define trunc_flag (1<<2)
|
||||||
#define twobufs_flag (1<<3)
|
#define twobufs_flag (1<<3)
|
||||||
int flags = trunc_flag;
|
int flags = trunc_flag;
|
||||||
size_t count = -1, oc = 0, ibs = 512, obs = 512;
|
size_t oc = 0, ibs = 512, obs = 512;
|
||||||
ssize_t n;
|
ssize_t n;
|
||||||
off_t seek = 0, skip = 0;
|
FILEOFF_TYPE seek = 0, skip = 0, count = MAX_FILEOFF_TYPE;
|
||||||
int oflag, ifd, ofd;
|
int oflag, ifd, ofd;
|
||||||
const char *infile = NULL, *outfile = NULL;
|
const char *infile = NULL, *outfile = NULL;
|
||||||
char *ibuf, *obuf;
|
char *ibuf, *obuf;
|
||||||
@@ -58,6 +60,7 @@ int dd_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (n = 1; n < argc; n++) {
|
for (n = 1; n < argc; n++) {
|
||||||
|
// FIXME: make them capable of eating LARGE numbers
|
||||||
if (ENABLE_FEATURE_DD_IBS_OBS && !strncmp("ibs=", argv[n], 4)) {
|
if (ENABLE_FEATURE_DD_IBS_OBS && !strncmp("ibs=", argv[n], 4)) {
|
||||||
ibs = bb_xparse_number(argv[n]+4, dd_suffixes);
|
ibs = bb_xparse_number(argv[n]+4, dd_suffixes);
|
||||||
flags |= twobufs_flag;
|
flags |= twobufs_flag;
|
||||||
@@ -80,7 +83,7 @@ int dd_main(int argc, char **argv)
|
|||||||
ibuf = argv[n]+5;
|
ibuf = argv[n]+5;
|
||||||
while (1) {
|
while (1) {
|
||||||
if (!strncmp("notrunc", ibuf, 7)) {
|
if (!strncmp("notrunc", ibuf, 7)) {
|
||||||
flags ^= trunc_flag;
|
flags &= ~trunc_flag;
|
||||||
ibuf += 7;
|
ibuf += 7;
|
||||||
} else if (!strncmp("sync", ibuf, 4)) {
|
} else if (!strncmp("sync", ibuf, 4)) {
|
||||||
flags |= sync_flag;
|
flags |= sync_flag;
|
||||||
@@ -105,14 +108,14 @@ int dd_main(int argc, char **argv)
|
|||||||
obuf = ibuf;
|
obuf = ibuf;
|
||||||
|
|
||||||
if (infile != NULL)
|
if (infile != NULL)
|
||||||
ifd = xopen(infile, O_RDONLY);
|
ifd = xopen(infile, O_RDONLY | (O_LARGEFILE * ENABLE_LFS));
|
||||||
else {
|
else {
|
||||||
ifd = STDIN_FILENO;
|
ifd = STDIN_FILENO;
|
||||||
infile = bb_msg_standard_input;
|
infile = bb_msg_standard_input;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outfile != NULL) {
|
if (outfile != NULL) {
|
||||||
oflag = O_WRONLY | O_CREAT;
|
oflag = O_WRONLY | O_CREAT | (O_LARGEFILE * ENABLE_LFS);
|
||||||
|
|
||||||
if (!seek && (flags & trunc_flag))
|
if (!seek && (flags & trunc_flag))
|
||||||
oflag |= O_TRUNC;
|
oflag |= O_TRUNC;
|
||||||
@@ -134,7 +137,7 @@ int dd_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (skip) {
|
if (skip) {
|
||||||
if (lseek(ifd, skip * ibs, SEEK_CUR) < 0) {
|
if (LSEEK(ifd, skip * ibs, SEEK_CUR) < 0) {
|
||||||
while (skip-- > 0) {
|
while (skip-- > 0) {
|
||||||
n = safe_read(ifd, ibuf, ibs);
|
n = safe_read(ifd, ibuf, ibs);
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
@@ -146,7 +149,7 @@ int dd_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (seek) {
|
if (seek) {
|
||||||
if (lseek(ofd, seek * obs, SEEK_CUR) < 0)
|
if (LSEEK(ofd, seek * obs, SEEK_CUR) < 0)
|
||||||
goto die_outfile;
|
goto die_outfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -53,14 +53,6 @@ static unsigned long af;
|
|||||||
static unsigned long rf;
|
static unsigned long rf;
|
||||||
static unsigned long sf;
|
static unsigned long sf;
|
||||||
|
|
||||||
#ifdef CONFIG_LFS
|
|
||||||
# define LSTAT lstat64
|
|
||||||
# define STRUCT_STAT struct stat64
|
|
||||||
#else
|
|
||||||
# define LSTAT lstat
|
|
||||||
# define STRUCT_STAT struct stat
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct flags_char {
|
struct flags_char {
|
||||||
unsigned long flag;
|
unsigned long flag;
|
||||||
char optchar;
|
char optchar;
|
||||||
|
@@ -41,14 +41,6 @@
|
|||||||
#define OPT_GENERATION 16
|
#define OPT_GENERATION 16
|
||||||
static int flags;
|
static int flags;
|
||||||
|
|
||||||
#ifdef CONFIG_LFS
|
|
||||||
# define LSTAT lstat64
|
|
||||||
# define STRUCT_STAT struct stat64
|
|
||||||
#else
|
|
||||||
# define LSTAT lstat
|
|
||||||
# define STRUCT_STAT struct stat
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void list_attributes(const char *name)
|
static void list_attributes(const char *name)
|
||||||
{
|
{
|
||||||
unsigned long fsflags;
|
unsigned long fsflags;
|
||||||
|
@@ -33,13 +33,8 @@ void proceed_question(void)
|
|||||||
void check_plausibility(const char *device, int force)
|
void check_plausibility(const char *device, int force)
|
||||||
{
|
{
|
||||||
int val;
|
int val;
|
||||||
#ifdef CONFIG_LFS
|
STRUCT_STAT s;
|
||||||
struct stat64 s;
|
val = STAT(device, &s);
|
||||||
val = stat64(device, &s);
|
|
||||||
#else
|
|
||||||
struct stat s;
|
|
||||||
val = stat(device, &s);
|
|
||||||
#endif
|
|
||||||
if (force)
|
if (force)
|
||||||
return;
|
return;
|
||||||
if(val == -1)
|
if(val == -1)
|
||||||
|
@@ -61,6 +61,31 @@
|
|||||||
#define PATH_MAX 256
|
#define PATH_MAX 256
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Large file support */
|
||||||
|
#ifdef CONFIG_LFS
|
||||||
|
# define FILEOFF_TYPE off64_t
|
||||||
|
# define FILEOFF_FMT "%lld"
|
||||||
|
# define LSEEK lseek64
|
||||||
|
# define STAT stat64
|
||||||
|
# define LSTAT lstat64
|
||||||
|
# define STRUCT_STAT struct stat64
|
||||||
|
# define STRTOOFF strtoll
|
||||||
|
# define SAFE_STRTOOFF safe_strtoll
|
||||||
|
#else
|
||||||
|
# define FILEOFF_TYPE off_t
|
||||||
|
# define FILEOFF_FMT "%ld"
|
||||||
|
# define LSEEK lseek
|
||||||
|
# define STAT stat
|
||||||
|
# define LSTAT lstat
|
||||||
|
# define STRUCT_STAT struct stat
|
||||||
|
# define STRTOOFF strtol
|
||||||
|
# define SAFE_STRTOOFF safe_strtol
|
||||||
|
/* Do we need to undefine O_LARGEFILE? */
|
||||||
|
#endif
|
||||||
|
/* scary. better ideas? (but do *test* them first!) */
|
||||||
|
#define MAX_FILEOFF_TYPE \
|
||||||
|
((FILEOFF_TYPE)~((FILEOFF_TYPE)1 << (sizeof(FILEOFF_TYPE)*8-1)))
|
||||||
|
|
||||||
/* Some useful definitions */
|
/* Some useful definitions */
|
||||||
#undef FALSE
|
#undef FALSE
|
||||||
#define FALSE ((int) 0)
|
#define FALSE ((int) 0)
|
||||||
|
@@ -97,14 +97,6 @@ static const char default_path_httpd_conf[] = "/etc";
|
|||||||
static const char httpd_conf[] = "httpd.conf";
|
static const char httpd_conf[] = "httpd.conf";
|
||||||
static const char home[] = "./";
|
static const char home[] = "./";
|
||||||
|
|
||||||
#if ENABLE_LFS
|
|
||||||
# define cont_l_fmt "%lld"
|
|
||||||
# define cont_l_type (long long)
|
|
||||||
#else
|
|
||||||
# define cont_l_fmt "%ld"
|
|
||||||
# define cont_l_type (long)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define TIMEOUT 60
|
#define TIMEOUT 60
|
||||||
|
|
||||||
// Note: busybox xfuncs are not used because we want the server to keep running
|
// Note: busybox xfuncs are not used because we want the server to keep running
|
||||||
@@ -927,8 +919,8 @@ static int sendHeaders(HttpResponseNum responseNum)
|
|||||||
|
|
||||||
if (config->ContentLength != -1) { /* file */
|
if (config->ContentLength != -1) { /* file */
|
||||||
strftime(timeStr, sizeof(timeStr), RFC1123FMT, gmtime(&config->last_mod));
|
strftime(timeStr, sizeof(timeStr), RFC1123FMT, gmtime(&config->last_mod));
|
||||||
len += sprintf(buf+len, "Last-Modified: %s\r\n%s " cont_l_fmt "\r\n",
|
len += sprintf(buf+len, "Last-Modified: %s\r\n%s "FILEOFF_FMT"\r\n",
|
||||||
timeStr, Content_length, cont_l_type config->ContentLength);
|
timeStr, Content_length, (FILEOFF_TYPE) config->ContentLength);
|
||||||
}
|
}
|
||||||
strcat(buf, "\r\n");
|
strcat(buf, "\r\n");
|
||||||
len += 2;
|
len += 2;
|
||||||
|
@@ -13,22 +13,6 @@
|
|||||||
#include "busybox.h"
|
#include "busybox.h"
|
||||||
#include <getopt.h> /* for struct option */
|
#include <getopt.h> /* for struct option */
|
||||||
|
|
||||||
#ifdef CONFIG_LFS
|
|
||||||
# define FILEOFF_TYPE off64_t
|
|
||||||
# define FILEOFF_FMT "%lld"
|
|
||||||
# define LSEEK lseek64
|
|
||||||
# define STRTOOFF strtoll
|
|
||||||
# define SAFE_STRTOOFF safe_strtoll
|
|
||||||
/* stat64 etc as needed... */
|
|
||||||
#else
|
|
||||||
# define FILEOFF_TYPE off_t
|
|
||||||
# define FILEOFF_FMT "%ld"
|
|
||||||
# define LSEEK lseek
|
|
||||||
# define STRTOOFF strtol
|
|
||||||
# define SAFE_STRTOOFF safe_strtol
|
|
||||||
/* Do we need to undefine O_LARGEFILE? */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct host_info {
|
struct host_info {
|
||||||
// May be used if we ever will want to free() all xstrdup()s...
|
// May be used if we ever will want to free() all xstrdup()s...
|
||||||
/* char *allocated; */
|
/* char *allocated; */
|
||||||
|
Reference in New Issue
Block a user