From nobody Tue Jul 29 12:49:09 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4brwC974qGz62xQr; Tue, 29 Jul 2025 12:49:09 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4brwC954DJz3lSs; Tue, 29 Jul 2025 12:49:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1753793349; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=fKz3XhMk18ZZ74YqDAOufgX0tXNPTnFYAcoxjewXFOY=; b=pMsg8X98ayA0J7yoqPzQxpc9TFKV8MUFAl8KSMje66YNefYUHV8wqVDDBmWB4XDO+ORPmF Oju3jWCxO/LsDnMNUiUe3uZs8RfDw7iGla+j3/eS3r5yPhcMOXTmWw76Ez7yas+uo8VIA1 BsfNv7rh7JcKXVrUqXUvMUhpAC6L6yh98gRmI01GkazwaczEzpmYqUNeQ+rwnJ/L07jegk RxNXE9vpN+wy0uVkaLEJEA6HlQQ4Q7ALsD+3yp3ZE9eeskN5FP/NWDvXcLVjADhCFDYGX2 NNqsq1hdKta3iNauxK3p8Rr+OU67/d/y7CoOzsBr+YcCiSbFKUzVCHF0009fJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1753793349; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=fKz3XhMk18ZZ74YqDAOufgX0tXNPTnFYAcoxjewXFOY=; b=uwwtuXntQNVrdB8xxfthGUR+WJEDSmoQb0mO2NtBdgPmPRe27PYDpNk5jmkc/btiyAcS14 hejVzdBYVbas44tKTqrkd6h6GMRRAEpqMRm4d9EguN2cdnX+0T/xS1xtInle2cjMkOjH9W IhfPNQChOyW8nuP4p2FtfTF/8bPpkM6w+n1/FUCtmF0puH4K1VVpqigzfQWm2JXufi8B94 cwN7pyawBWQECLq0yFyydqa4HK6/uOEin3ujbgOtCPVovchjJvRQ+QmQETJj0HlUiEAsNE 90nOEPWA2mm5uSAyWYaA5HH8axevmSVvSqDPcYHb0n0xBV15/toylarK0Nyvaw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1753793349; a=rsa-sha256; cv=none; b=gyIGatPbFQPEVwWXIBWNpTBwXXzMmFU2KOSs8l177vI/onbX5BjLvGHBvc4lymHOksAvWo T0kabF0F/lYfWAY9FBv3j36QGO+wXjORRvV1/W88ud12Hv51MxMf7mSqkIYo6EucrDONpo he2G8hsnKvCt6Y/gjI7sEyl+MxyxrADlPZx+XwDriq13yBm48T4JoVaOv1WgD9TYbe6i4N 7WLR37eAkl9A8eqkerWCD/SihOiEkl6bnIeQAISvBvTlqmThRhquFub53eWfCKhbEKg8X4 +tG5g/ENZ30LopEZRsibVXMUEQX9KT5mJh8FFZH+jHQMXzJgJhU7EPw20nfNDA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4brwC93vydzXNy; Tue, 29 Jul 2025 12:49:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 56TCn9Jh033535; Tue, 29 Jul 2025 12:49:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 56TCn9Y4033532; Tue, 29 Jul 2025 12:49:09 GMT (envelope-from git) Date: Tue, 29 Jul 2025 12:49:09 GMT Message-Id: <202507291249.56TCn9Y4033532@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 414a01b9e62b - stable/14 - mkimg: Add a reproducible mode List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 414a01b9e62bdd6b10bbae87b0df52983bf4ca14 Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=414a01b9e62bdd6b10bbae87b0df52983bf4ca14 commit 414a01b9e62bdd6b10bbae87b0df52983bf4ca14 Author: Mark Johnston AuthorDate: 2025-06-26 14:28:14 +0000 Commit: Mark Johnston CommitDate: 2025-07-29 12:08:32 +0000 mkimg: Add a reproducible mode mkimg embeds a UUID in the GPT header and uses the current time of day to generate it, so its output is not reproducible by default. Add a -R flag to ask it to use a fixed time for UUID generation. Merge the FreeBSD-specific implementation of osdep_uuidgen() with that of Linux, as the use of uuidgen(2) is incompatible with reproducible output mode. Reviewed by: bnovkov MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D49716 (cherry picked from commit 95ac5b0e27e9070ba91c28f9a6ecbed743d148cb) --- usr.bin/mkimg/mkimg.1 | 8 +++++++- usr.bin/mkimg/mkimg.c | 10 +++++++++- usr.bin/mkimg/mkimg.h | 3 +++ usr.bin/mkimg/uuid.c | 19 +++++-------------- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/usr.bin/mkimg/mkimg.1 b/usr.bin/mkimg/mkimg.1 index 82bbee53a267..f6b151d2d5c7 100644 --- a/usr.bin/mkimg/mkimg.1 +++ b/usr.bin/mkimg/mkimg.1 @@ -22,7 +22,7 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd March 12, 2024 +.Dd June 25, 2025 .Dt MKIMG 1 .Os .Sh NAME @@ -41,6 +41,7 @@ .Op Fl f Ar format .Op Fl o Ar outfile .Op Fl a Ar active +.Op Fl R .Op Fl v .Op Fl y .Op Fl s Ar scheme Op Fl p Ar partition ... @@ -138,6 +139,11 @@ option is a shorthand to specify the minimum and maximum capacity at the same time. .Pp The +.Fl R +option enables reproducible mode: any timestamps or random identifiers will +be fixed so as to ensure consistent output. +.Pp +The .Fl v option increases the level of output that the .Nm diff --git a/usr.bin/mkimg/mkimg.c b/usr.bin/mkimg/mkimg.c index f3bb9cb05708..58bf90fd5ad4 100644 --- a/usr.bin/mkimg/mkimg.c +++ b/usr.bin/mkimg/mkimg.c @@ -62,6 +62,8 @@ static struct option longopts[] = { static uint64_t min_capacity = 0; static uint64_t max_capacity = 0; +bool reproducible = false; + struct partlisthead partlist = TAILQ_HEAD_INITIALIZER(partlist); u_int nparts = 0; @@ -562,7 +564,7 @@ main(int argc, char *argv[]) bcfd = -1; outfd = 1; /* Write to stdout by default */ - while ((c = getopt_long(argc, argv, "a:b:c:C:f:o:p:s:vyH:P:S:T:", + while ((c = getopt_long(argc, argv, "a:b:c:C:f:o:p:s:vyH:P:RS:T:", longopts, NULL)) != -1) { switch (c) { case 'a': /* ACTIVE PARTITION, if supported */ @@ -607,6 +609,9 @@ main(int argc, char *argv[]) if (error) errc(EX_DATAERR, error, "partition"); break; + case 'R': + reproducible = true; + break; case 's': /* SCHEME */ if (scheme_selected() != NULL) usage("multiple schemes given"); @@ -676,6 +681,9 @@ main(int argc, char *argv[]) if (max_capacity != 0 && min_capacity > max_capacity) usage("minimum capacity cannot be larger than the maximum one"); + if (reproducible) + srandom(42); + if (secsz > blksz) { if (blksz != 0) errx(EX_DATAERR, "the physical block size cannot " diff --git a/usr.bin/mkimg/mkimg.h b/usr.bin/mkimg/mkimg.h index e85f77de0ec7..608de458e83c 100644 --- a/usr.bin/mkimg/mkimg.h +++ b/usr.bin/mkimg/mkimg.h @@ -29,6 +29,9 @@ #include #include +#include + +extern bool reproducible; /* Generate reproducible output. */ struct part { TAILQ_ENTRY(part) link; diff --git a/usr.bin/mkimg/uuid.c b/usr.bin/mkimg/uuid.c index 470d92c76293..f3415a8c1111 100644 --- a/usr.bin/mkimg/uuid.c +++ b/usr.bin/mkimg/uuid.c @@ -45,20 +45,9 @@ osdep_uuidgen(mkimg_uuid_t *uuid) } #endif /* __APPLE__ */ -#ifdef __FreeBSD__ -#include - -static void -osdep_uuidgen(mkimg_uuid_t *uuid) -{ - - uuidgen((void *)uuid, 1); -} -#endif /* __FreeBSD__ */ - -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD__) +#include #include -#include static void osdep_uuidgen(mkimg_uuid_t *uuid) @@ -68,7 +57,9 @@ osdep_uuidgen(mkimg_uuid_t *uuid) u_int i; uint16_t seq; - if (gettimeofday(&tv, NULL) == -1) + if (reproducible) + memset(&tv, 0, sizeof(tv)); + else if (gettimeofday(&tv, NULL) == -1) abort(); time += (uint64_t)tv.tv_sec * 10000000LL;