Changeset View
Changeset View
Standalone View
Standalone View
head/bin/dd/dd.c
Show First 20 Lines • Show All 402 Lines • ▼ Show 20 Lines | if (ddflags & C_SYNC) { | ||||
if (ddflags & C_FILL) | if (ddflags & C_FILL) | ||||
memset(in.dbp, fill_char, in.dbsz); | memset(in.dbp, fill_char, in.dbsz); | ||||
else if (ddflags & (C_BLOCK | C_UNBLOCK)) | else if (ddflags & (C_BLOCK | C_UNBLOCK)) | ||||
memset(in.dbp, ' ', in.dbsz); | memset(in.dbp, ' ', in.dbsz); | ||||
else | else | ||||
memset(in.dbp, 0, in.dbsz); | memset(in.dbp, 0, in.dbsz); | ||||
} | } | ||||
n = read(in.fd, in.dbp, in.dbsz); | |||||
if (n == 0) { | |||||
in.dbrcnt = 0; | in.dbrcnt = 0; | ||||
fill: | |||||
n = read(in.fd, in.dbp + in.dbrcnt, in.dbsz - in.dbrcnt); | |||||
/* EOF */ | |||||
if (n == 0 && in.dbrcnt == 0) | |||||
return; | return; | ||||
} | |||||
/* Read error. */ | /* Read error */ | ||||
if (n == -1) { | if (n == -1) { | ||||
/* | /* | ||||
* If noerror not specified, die. POSIX requires that | * If noerror not specified, die. POSIX requires that | ||||
* the warning message be followed by an I/O display. | * the warning message be followed by an I/O display. | ||||
*/ | */ | ||||
if (!(ddflags & C_NOERROR)) | if (!(ddflags & C_NOERROR)) | ||||
err(1, "%s", in.name); | err(1, "%s", in.name); | ||||
warn("%s", in.name); | warn("%s", in.name); | ||||
summary(); | summary(); | ||||
/* | /* | ||||
* If it's a seekable file descriptor, seek past the | * If it's a seekable file descriptor, seek past the | ||||
* error. If your OS doesn't do the right thing for | * error. If your OS doesn't do the right thing for | ||||
* raw disks this section should be modified to re-read | * raw disks this section should be modified to re-read | ||||
* in sector size chunks. | * in sector size chunks. | ||||
*/ | */ | ||||
if (in.flags & ISSEEK && | if (in.flags & ISSEEK && | ||||
lseek(in.fd, (off_t)in.dbsz, SEEK_CUR)) | lseek(in.fd, (off_t)in.dbsz, SEEK_CUR)) | ||||
warn("%s", in.name); | warn("%s", in.name); | ||||
/* If sync not specified, omit block and continue. */ | /* If sync not specified, omit block and continue. */ | ||||
if (!(ddflags & C_SYNC)) | if (!(ddflags & C_SYNC)) | ||||
continue; | continue; | ||||
} | |||||
/* Read errors count as full blocks. */ | /* If conv=sync, use the entire block. */ | ||||
in.dbcnt += in.dbrcnt = in.dbsz; | if (ddflags & C_SYNC) | ||||
++st.in_full; | n = in.dbsz; | ||||
/* Handle full input blocks. */ | /* Count the bytes read for this block. */ | ||||
} else if ((size_t)n == (size_t)in.dbsz) { | in.dbrcnt += n; | ||||
in.dbcnt += in.dbrcnt = n; | |||||
++st.in_full; | |||||
/* Handle partial input blocks. */ | /* Count the number of full and partial blocks. */ | ||||
} else { | if (in.dbrcnt == in.dbsz) | ||||
/* If sync, use the entire block. */ | ++st.in_full; | ||||
if (ddflags & C_SYNC) | else if (ddflags & C_IFULLBLOCK && n != 0) | ||||
in.dbcnt += in.dbrcnt = in.dbsz; | goto fill; /* these don't count */ | ||||
else | else | ||||
in.dbcnt += in.dbrcnt = n; | |||||
++st.in_part; | ++st.in_part; | ||||
} | |||||
/* Count the total bytes read for this file. */ | |||||
in.dbcnt += in.dbrcnt; | |||||
/* | /* | ||||
* POSIX states that if bs is set and no other conversions | * POSIX states that if bs is set and no other conversions | ||||
* than noerror, notrunc or sync are specified, the block | * than noerror, notrunc or sync are specified, the block | ||||
* is output without buffering as it is read. | * is output without buffering as it is read. | ||||
*/ | */ | ||||
if ((ddflags & ~(C_NOERROR | C_NOTRUNC | C_SYNC)) == C_BS) { | if ((ddflags & ~(C_NOERROR | C_NOTRUNC | C_SYNC)) == C_BS) { | ||||
out.dbcnt = in.dbcnt; | out.dbcnt = in.dbcnt; | ||||
dd_out(1); | dd_out(1); | ||||
in.dbcnt = 0; | in.dbcnt = 0; | ||||
continue; | continue; | ||||
} | } | ||||
if (ddflags & C_SWAB) { | if (ddflags & C_SWAB) { | ||||
if ((n = in.dbrcnt) & 1) { | if ((n = in.dbrcnt) & 1) { | ||||
++st.swab; | ++st.swab; | ||||
--n; | --n; | ||||
} | } | ||||
swapbytes(in.dbp, (size_t)n); | swapbytes(in.dbp, (size_t)n); | ||||
} | } | ||||
/* Advance to the next block. */ | |||||
in.dbp += in.dbrcnt; | in.dbp += in.dbrcnt; | ||||
(*cfunc)(); | (*cfunc)(); | ||||
if (need_summary) | if (need_summary) | ||||
summary(); | summary(); | ||||
if (need_progress) | if (need_progress) | ||||
progress(); | progress(); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 148 Lines • Show Last 20 Lines |