]> xenbits.xensource.com Git - freebsd.git/commitdiff
Add conv=fsync flag to dd
authormmacy <mmacy@FreeBSD.org>
Tue, 3 Sep 2019 18:35:55 +0000 (18:35 +0000)
committermmacy <mmacy@FreeBSD.org>
Tue, 3 Sep 2019 18:35:55 +0000 (18:35 +0000)
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.

bin/dd/args.c
bin/dd/dd.1
bin/dd/dd.c
bin/dd/dd.h

index f58551dec6a58e55d397a8fce261d79b6b9b59a9..8e83c6cc608c5c60611e6153be57660e7952aeda 100644 (file)
@@ -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 },
index 352c85072d38ffbf166980da4fcfafa7b1003707..539e448b28b9a6d4e6b107d53c9107898464c47a 100644 (file)
@@ -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
index 46175fa4c8f20fc18511a992f20cefddb462d0e2..3db678b850047cd2c6cd1a69f91d325dbe8bd993 100644 (file)
@@ -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
index 8090252923fd047413e8536a500e608a4ab0152e..8c01cb4d17cca83fe71bf687a8768609c7876a9a 100644 (file)
@@ -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)