Changeset View
Changeset View
Standalone View
Standalone View
bin/dd/dd.c
Context not available. | |||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/stat.h> | #include <sys/stat.h> | ||||
#include <sys/conf.h> | #include <sys/conf.h> | ||||
#include <sys/disk.h> | |||||
#include <sys/disklabel.h> | #include <sys/disklabel.h> | ||||
#include <sys/filio.h> | #include <sys/filio.h> | ||||
Context not available. | |||||
} | } | ||||
} | } | ||||
static ssize_t | |||||
dsk_trim(int d_fd, size_t size) | |||||
{ | |||||
off_t ioarg[2], npos; | |||||
int eval; | |||||
ioarg[0] = lseek(d_fd, (off_t)0, SEEK_CUR); | |||||
if (ioarg[0] < 0) | |||||
return (ioarg[0]); | |||||
ioarg[1] = size; | |||||
eval = ioctl(d_fd, DIOCGDELETE, ioarg); | |||||
if (eval != 0) | |||||
return (-1); | |||||
npos = lseek(d_fd, size, SEEK_CUR); | |||||
if (npos < 0) | |||||
return (npos); | |||||
danfe: Why explicit cast to `off_t` is needed for zero? | |||||
Done Inline ActionsENOIDEA. :) I just copied code from some other place in the dd.c. I can only guess it's perhaps used to workaround some early cc(1) idiosyncrasy. sobomax: ENOIDEA. :) I just copied code from some other place in the dd.c. I can only guess it's perhaps… | |||||
Not Done Inline ActionsIt's because this code is old. K&R required you cast all long args. off_t is a long arg, so it has to be cast. It hasn't been required since we've had a ANSI compiler in the tree (so ~30 years, eg 4.4BSD could have ditched it). imp: It's because this code is old. K&R required you cast all long args. off_t is a long arg, so it… | |||||
return (npos - ioarg[0]); | |||||
} | |||||
void | void | ||||
dd_out(int force) | dd_out(int force) | ||||
{ | { | ||||
Context not available. | |||||
cnt = n; | cnt = n; | ||||
do { | do { | ||||
sparse = 0; | sparse = 0; | ||||
if (ddflags & C_SPARSE) { | if (ddflags & (C_SPARSE | C_TRIM)) { | ||||
/* Is buffer sparse? */ | /* Is buffer sparse? */ | ||||
sparse = BISZERO(outp, cnt); | sparse = BISZERO(outp, cnt); | ||||
} | } | ||||
if (sparse && !force) { | if (sparse && !force && !(ddflags & C_TRIM)) { | ||||
pending += cnt; | pending += cnt; | ||||
nw = cnt; | nw = cnt; | ||||
} else { | } else { | ||||
Done Inline ActionsHere sparse is checked as boolean (no != 0)... danfe: Here `sparse` is checked as boolean (no `!= 0`)... | |||||
Context not available. | |||||
pending = 0; | pending = 0; | ||||
} | } | ||||
if (cnt) { | if (cnt) { | ||||
nw = write(out.fd, outp, cnt); | if (!sparse || !(ddflags & C_TRIM)) { | ||||
out.seek_offset = 0; | nw = write(out.fd, outp, cnt); | ||||
} else { | |||||
nw = dsk_trim(out.fd, cnt); | |||||
} | |||||
} else { | } else { | ||||
return; | return; | ||||
} | } | ||||
Context not available. | |||||
Done Inline Actions... yet here, it is checked correctly (as int). Also, since it is ||, the order does not matter, and sparse can also be checked before ddflags like in the expression above? danfe: ... yet here, it is checked correctly (as int). Also, since it is `||`, the order does not… |
Why explicit cast to off_t is needed for zero?