Changeset View
Changeset View
Standalone View
Standalone View
bin/dd/dd.c
Show First 20 Lines • Show All 158 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) | |||||
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)) | ||||
out.fd = open(out.name, O_RDWR | OFLAGS, DEFFILEMODE); | out.fd = open(out.name, O_RDWR | OFLAGS, DEFFILEMODE); | ||||
▲ Show 20 Lines • Show All 324 Lines • ▼ Show 20 Lines | dd_close(void) | ||||
/* | /* | ||||
* If the file ends with a hole, ftruncate it to extend its size | * If the file ends with a hole, ftruncate it to extend its size | ||||
* up to the end of the hole (without having to write any data). | * up to the end of the hole (without having to write any data). | ||||
*/ | */ | ||||
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 (fsync(out.fd) == -1) | |||||
err(1, "fsyncing %s", out.name); | |||||
imp: do you also need to check close(2) calls? | |||||
freqlabsAuthorUnsubmitted Done Inline ActionsIt's in the stack: https://reviews.freebsd.org/D21376 freqlabs: It's in the stack: https://reviews.freebsd.org/D21376 | |||||
} | } | ||||
} | } | ||||
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 |
do you also need to check close(2) calls?