From owner-svn-src-head@freebsd.org Tue Sep 3 18:35:56 2019 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id C8597D0448; Tue, 3 Sep 2019 18:35:56 +0000 (UTC) (envelope-from mmacy@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46NFyN4zS7z42Sr; Tue, 3 Sep 2019 18:35:56 +0000 (UTC) (envelope-from mmacy@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 8F799729D; Tue, 3 Sep 2019 18:35:56 +0000 (UTC) (envelope-from mmacy@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x83IZuPE019706; Tue, 3 Sep 2019 18:35:56 GMT (envelope-from mmacy@FreeBSD.org) Received: (from mmacy@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x83IZtsw019703; Tue, 3 Sep 2019 18:35:55 GMT (envelope-from mmacy@FreeBSD.org) Message-Id: <201909031835.x83IZtsw019703@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mmacy set sender to mmacy@FreeBSD.org using -f From: Matt Macy Date: Tue, 3 Sep 2019 18:35:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r351770 - head/bin/dd X-SVN-Group: head X-SVN-Commit-Author: mmacy X-SVN-Commit-Paths: head/bin/dd X-SVN-Commit-Revision: 351770 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Sep 2019 18:35:56 -0000 Author: mmacy Date: Tue Sep 3 18:35:55 2019 New Revision: 351770 URL: https://svnweb.freebsd.org/changeset/base/351770 Log: 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. Modified: head/bin/dd/args.c head/bin/dd/dd.1 head/bin/dd/dd.c head/bin/dd/dd.h Modified: head/bin/dd/args.c ============================================================================== --- head/bin/dd/args.c Tue Sep 3 18:32:29 2019 (r351769) +++ head/bin/dd/args.c Tue Sep 3 18:35:55 2019 (r351770) @@ -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 }, Modified: head/bin/dd/dd.1 ============================================================================== --- head/bin/dd/dd.1 Tue Sep 3 18:32:29 2019 (r351769) +++ head/bin/dd/dd.1 Tue Sep 3 18:35:55 2019 (r351770) @@ -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 Modified: head/bin/dd/dd.c ============================================================================== --- head/bin/dd/dd.c Tue Sep 3 18:32:29 2019 (r351769) +++ head/bin/dd/dd.c Tue Sep 3 18:35:55 2019 (r351770) @@ -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; @@ -504,6 +506,11 @@ dd_close(void) if (out.seek_offset > 0 && (out.flags & ISTRUNC)) { 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); } } Modified: head/bin/dd/dd.h ============================================================================== --- head/bin/dd/dd.h Tue Sep 3 18:32:29 2019 (r351769) +++ head/bin/dd/dd.h Tue Sep 3 18:35:55 2019 (r351770) @@ -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)