FreeBSD Bugzilla – Attachment 206684 Details for
Bug 229616
bin/dd: add conv=fsync, handle errors in close(2)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch against head/bin/dd
dd-head-conv-fsync.diff (text/plain), 2.47 KB, created by
Thomas Hurst
on 2019-08-19 02:39:20 UTC
(
hide
)
Description:
Patch against head/bin/dd
Filename:
MIME Type:
Creator:
Thomas Hurst
Created:
2019-08-19 02:39:20 UTC
Size:
2.47 KB
patch
obsolete
>Index: args.c >=================================================================== >--- args.c (revision 351202) >+++ args.c (working copy) >@@ -320,6 +320,7 @@ > { "ascii", C_ASCII, C_EBCDIC, e2a_POSIX }, > { "block", C_BLOCK, C_UNBLOCK, NULL }, > { "ebcdic", C_EBCDIC, C_ASCII, a2e_POSIX }, >+ { "fsync", C_FSYNC, 0, NULL}, > { "ibm", C_EBCDIC, C_ASCII, a2ibm_POSIX }, > { "lcase", C_LCASE, C_UCASE, NULL }, > { "noerror", C_NOERROR, 0, NULL }, >Index: dd.1 >=================================================================== >--- dd.1 (revision 351202) >+++ dd.1 (working copy) >@@ -252,6 +252,14 @@ > and > .No pre- Ns Bx 4.3 reno > systems. >+.It Cm fsync >+Call >+.Xr fsync 2 >+on the output before >+.Xr close 2 >+to ensure it is on stable storage when >+.Nm >+exits. > .It Cm lcase > Transform uppercase characters into lowercase characters. > .It Cm pareven , parnone , parodd , parset >Index: dd.c >=================================================================== >--- dd.c (revision 351202) >+++ dd.c (working copy) >@@ -119,12 +119,27 @@ > > dd_close(); > /* >+ * If output is stdout, it may be shared with another process, >+ * leading to close(2) merely decrementing a reference count. >+ * >+ * This could mask errors it would otherwise have reported. >+ */ >+ if ((ddflags & C_FSYNC || out.fd == STDOUT_FILENO) && >+ fsync(out.fd) == -1 && errno != EINVAL) { >+ err(1, "fsync"); >+ } >+ /* > * Some devices such as cfi(4) may perform significant amounts > * of work when a write descriptor is closed. Close the out > * descriptor explicitly so that the summary handler (called > * from an atexit() hook) includes this work. >+ * >+ * As implied by this work, close(2) may fail, so ensure we >+ * report any such errors. > */ >- close(out.fd); >+ if (close(out.fd) == -1 && errno != EINTR) { >+ err(1, "close"); >+ } > exit(0); > } > >@@ -163,7 +178,7 @@ > if (files_cnt > 1 && !(in.flags & ISTAPE)) > 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_FSYNC, CAP_FTRUNCATE, CAP_IOCTL, CAP_WRITE); > if (out.name == NULL) { > /* No way to check for read access here. */ > out.fd = STDOUT_FILENO; >Index: dd.h >=================================================================== >--- dd.h (revision 351202) >+++ dd.h (working copy) >@@ -101,6 +101,7 @@ > #define C_NOXFER 0x10000000 > #define C_NOINFO 0x20000000 > #define C_PROGRESS 0x40000000 >+#define C_FSYNC 0x80000000 > > #define C_PARITY (C_PAREVEN | C_PARODD | C_PARNONE | C_PARSET) >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 229616
:
204530
| 206684 |
206685