The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=95ac5b0e27e9070ba91c28f9a6ecbed743d148cb
commit 95ac5b0e27e9070ba91c28f9a6ecbed743d148cb Author: Mark Johnston <ma...@freebsd.org> AuthorDate: 2025-06-26 14:28:14 +0000 Commit: Mark Johnston <ma...@freebsd.org> CommitDate: 2025-06-26 14:44:01 +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 --- 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 3cd9b03c06e9..c8872ebb1bc6 100644 --- a/usr.bin/mkimg/mkimg.c +++ b/usr.bin/mkimg/mkimg.c @@ -61,6 +61,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; @@ -561,7 +563,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 */ @@ -606,6 +608,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"); @@ -675,6 +680,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 <sys/queue.h> #include <sys/types.h> +#include <stdbool.h> + +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 <sys/uuid.h> - -static void -osdep_uuidgen(mkimg_uuid_t *uuid) -{ - - uuidgen((void *)uuid, 1); -} -#endif /* __FreeBSD__ */ - -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD__) +#include <sys/time.h> #include <stdlib.h> -#include <time.h> 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;