summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorMatt Macy <mmacy@FreeBSD.org>2019-09-03 18:35:55 +0000
committerMatt Macy <mmacy@FreeBSD.org>2019-09-03 18:35:55 +0000
commitce1b19d8c8d160353397ced6a971cc5126da8867 (patch)
tree2b8a7fb221bd7b887be606c22f200eab2294d4a2 /bin
parentaef64c62c2a6a059e175b3a8b57a61aa4f3f2db8 (diff)
downloadsrc-test-ce1b19d8c8d160353397ced6a971cc5126da8867.tar.gz
src-test-ce1b19d8c8d160353397ced6a971cc5126da8867.zip
Add conv=fsync flag to dd
The fsync flag performs an fsync(2) on the output file before closing it. This will be useful for the ZFS test suite. Submitted by: ryan@ixsystems.com Reviewed by: jilles@, imp@ MFC after: 1 week Sponsored by: iXsystems, Inc.
Notes
Notes: svn path=/head/; revision=351770
Diffstat (limited to 'bin')
-rw-r--r--bin/dd/args.c1
-rw-r--r--bin/dd/dd.14
-rw-r--r--bin/dd/dd.c7
-rw-r--r--bin/dd/dd.h1
4 files changed, 13 insertions, 0 deletions
diff --git a/bin/dd/args.c b/bin/dd/args.c
index f58551dec6a58..8e83c6cc608c5 100644
--- a/bin/dd/args.c
+++ b/bin/dd/args.c
@@ -320,6 +320,7 @@ static const struct conv {
{ "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 },
diff --git a/bin/dd/dd.1 b/bin/dd/dd.1
index 352c85072d38f..539e448b28b9a 100644
--- a/bin/dd/dd.1
+++ b/bin/dd/dd.1
@@ -252,6 +252,10 @@ are maps used in historic
and
.No pre- Ns Bx 4.3 reno
systems.
+.It Cm fsync
+Perform an
+.Xr fsync 2
+on the output file before closing it.
.It Cm lcase
Transform uppercase characters into lowercase characters.
.It Cm pareven , parnone , parodd , parset
diff --git a/bin/dd/dd.c b/bin/dd/dd.c
index 46175fa4c8f20..3db678b850047 100644
--- a/bin/dd/dd.c
+++ b/bin/dd/dd.c
@@ -164,6 +164,8 @@ setup(void)
errx(1, "files is not supported for non-tape devices");
cap_rights_set(&rights, CAP_FTRUNCATE, CAP_IOCTL, CAP_WRITE);
+ if (ddflags & C_FSYNC)
+ cap_rights_set(&rights, CAP_FSYNC);
if (out.name == NULL) {
/* No way to check for read access here. */
out.fd = STDOUT_FILENO;
@@ -505,6 +507,11 @@ dd_close(void)
if (ftruncate(out.fd, out.seek_offset) == -1)
err(1, "truncating %s", out.name);
}
+
+ if (ddflags & C_FSYNC) {
+ if (fsync(out.fd) == -1)
+ err(1, "fsyncing %s", out.name);
+ }
}
void
diff --git a/bin/dd/dd.h b/bin/dd/dd.h
index 8090252923fd0..8c01cb4d17cca 100644
--- a/bin/dd/dd.h
+++ b/bin/dd/dd.h
@@ -101,6 +101,7 @@ typedef struct {
#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)