Changeset View
Changeset View
Standalone View
Standalone View
bin/dd/dd.c
Show First 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | |||||
static void getfdtype(IO *); | static void getfdtype(IO *); | ||||
static void setup(void); | static void setup(void); | ||||
IO in, out; /* input/output state */ | IO in, out; /* input/output state */ | ||||
STAT st; /* statistics */ | STAT st; /* statistics */ | ||||
void (*cfunc)(void); /* conversion function */ | void (*cfunc)(void); /* conversion function */ | ||||
uintmax_t cpy_cnt; /* # of blocks to copy */ | uintmax_t cpy_cnt; /* # of blocks to copy */ | ||||
static off_t pending = 0; /* pending seek if sparse */ | static off_t pending = 0; /* pending seek if sparse */ | ||||
u_int ddflags = 0; /* conversion options */ | uint64_t ddflags = 0; /* conversion options */ | ||||
size_t cbsz; /* conversion block size */ | size_t cbsz; /* conversion block size */ | ||||
uintmax_t files_cnt = 1; /* # of files to copy */ | uintmax_t files_cnt = 1; /* # of files to copy */ | ||||
const u_char *ctab; /* conversion table */ | const u_char *ctab; /* conversion table */ | ||||
char fill_char; /* Character to fill with if defined */ | char fill_char; /* Character to fill with if defined */ | ||||
size_t speed = 0; /* maximum speed, in bytes per second */ | size_t speed = 0; /* maximum speed, in bytes per second */ | ||||
volatile sig_atomic_t need_summary; | volatile sig_atomic_t need_summary; | ||||
volatile sig_atomic_t need_progress; | volatile sig_atomic_t need_progress; | ||||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | setup(void) | ||||
cap_rights_init(&rights, CAP_READ, CAP_SEEK); | cap_rights_init(&rights, CAP_READ, CAP_SEEK); | ||||
if (caph_rights_limit(in.fd, &rights) == -1) | if (caph_rights_limit(in.fd, &rights) == -1) | ||||
err(1, "unable to limit capability rights"); | err(1, "unable to limit capability rights"); | ||||
if (files_cnt > 1 && !(in.flags & ISTAPE)) | if (files_cnt > 1 && !(in.flags & ISTAPE)) | ||||
errx(1, "files is not supported for non-tape devices"); | errx(1, "files is not supported for non-tape devices"); | ||||
cap_rights_set(&rights, CAP_FTRUNCATE, CAP_IOCTL, CAP_WRITE); | cap_rights_set(&rights, CAP_FTRUNCATE, CAP_IOCTL, CAP_WRITE); | ||||
if (ddflags & C_FSYNC) | if (ddflags & (C_FDATASYNC | C_FSYNC)) | ||||
cap_rights_set(&rights, CAP_FSYNC); | cap_rights_set(&rights, CAP_FSYNC); | ||||
if (out.name == NULL) { | if (out.name == NULL) { | ||||
/* No way to check for read access here. */ | /* No way to check for read access here. */ | ||||
out.fd = STDOUT_FILENO; | out.fd = STDOUT_FILENO; | ||||
out.name = "stdout"; | out.name = "stdout"; | ||||
} else { | } else { | ||||
#define OFLAGS \ | #define OFLAGS \ | ||||
(O_CREAT | (ddflags & (C_SEEK | C_NOTRUNC) ? 0 : O_TRUNC)) | (O_CREAT | (ddflags & (C_SEEK | C_NOTRUNC) ? 0 : O_TRUNC)) | ||||
▲ Show 20 Lines • Show All 330 Lines • ▼ Show 20 Lines | dd_close(void) | ||||
if (out.seek_offset > 0 && (out.flags & ISTRUNC)) { | if (out.seek_offset > 0 && (out.flags & ISTRUNC)) { | ||||
if (ftruncate(out.fd, out.seek_offset) == -1) | if (ftruncate(out.fd, out.seek_offset) == -1) | ||||
err(1, "truncating %s", out.name); | err(1, "truncating %s", out.name); | ||||
} | } | ||||
if (ddflags & C_FSYNC) { | if (ddflags & C_FSYNC) { | ||||
if (fsync(out.fd) == -1) | if (fsync(out.fd) == -1) | ||||
err(1, "fsyncing %s", out.name); | err(1, "fsyncing %s", out.name); | ||||
} else if (ddflags & C_FDATASYNC) { | |||||
if (fdatasync(out.fd) == -1) | |||||
err(1, "fdatasyncing %s", out.name); | |||||
} | } | ||||
} | } | ||||
void | void | ||||
dd_out(int force) | dd_out(int force) | ||||
{ | { | ||||
u_char *outp; | u_char *outp; | ||||
size_t cnt, n; | size_t cnt, n; | ||||
▲ Show 20 Lines • Show All 99 Lines • Show Last 20 Lines |