From nobody Tue May 20 09:50:52 2025 X-Original-To: dev-commits-src-main@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 4b1qYm3Bmsz5w87j; Tue, 20 May 2025 09:50:52 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4b1qYm2gVHz3D8n; Tue, 20 May 2025 09:50:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1747734652; 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=xPPKJvaooddnVWkTVGE6ihazAQoQtjzGr6gs6HY+v9c=; b=U9q/KCJMKxhFUL5zlGqjV0Dzp6uG5psfVXRB9xWq/HdD7AEbamOC9uyrSu8SEZ+hZlH2FE i9c/Y30Dti7m0voZ2bhc8k7PNJFqq7f2LUVmc/gBDFrYbeBeGnMsDmOo4HjjjHupwfXwyA IGcfnHOM8U1x6MObABXLvRUg6SnJ2bHyg0RKdOwzcK7ZF9+8hTnX18gQikx+avhYQzLawO gV9QJayjLWObUpFqMksXJEPch9VgKP6LfoGG4EmCYDghPRqoxvb3o7eAWw2lEPhJpHigTD 6SrT0kTjPYnlczA/lvEOjHH+GGSlM/aCRDr4U2xu6UDGaXFFr6c4t6X9GxTwLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1747734652; 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=xPPKJvaooddnVWkTVGE6ihazAQoQtjzGr6gs6HY+v9c=; b=N5TYzfHt7gfIUIBiDRh7RM9QNrVCwhTFAwhFP9s4/LM6ICZ/cAkchSDFDQBHIGdDWdABVR gC/tIciTmnRHY6wB3b4FOey1uLhYbafdEEpUWWE2DMESK+4ye/di+FoefbNL5RZcumbag9 1v56eWu4owe5oJfm1Onwj0MjUjeQj2h/0ZMp+NBALtMkUw7+0V+Pc4R5URG50jlttKz0K2 5OYASyOIXfMd3M2tfZkvnyV6UwshlZvtzuu7RKUGf2RoSJ99jNjOFtO2VT89dbkMVuZB+x e01BZQ2XC01d1+/rtLcQI2DLaq4Ob/0VXzGb3Hv/m9BuiV4y0Cqg4eB+88weJg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1747734652; a=rsa-sha256; cv=none; b=LhMWxSyPW47gD36nKnfFnFXQ8n5FRleWKnArlXqnXbTZnc0FRwMWkPsoh6UX1ZcRi1stys TKNAqKv4XUxNaxqVjfwjfSdoUKyeXux4RkkajSGs+xf75RYJNu/ka+DEniWEZUt2ulngBy DnhCdXoSq3XUWGEemeM+NySxxxRexA/oE1EgdWng50w5mfDg5XsLVs8VRy/4tPTGoAhpek jnutrBr3z/ZpQXPnKlHJry4nIJTaUi8MRpt4mPGaPGGCO3anXY74EGmjTER4+JF3llZFgv kdhE+wtYFFTeiRrGopiH/wksq5KN5rYrlm+a3i7kEAzY79f0bjYQTs5OtYhWJA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4b1qYm2Ft2zlRY; Tue, 20 May 2025 09:50:52 +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 54K9oqjH085664; Tue, 20 May 2025 09:50:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 54K9oqon085661; Tue, 20 May 2025 09:50:52 GMT (envelope-from git) Date: Tue, 20 May 2025 09:50:52 GMT Message-Id: <202505200950.54K9oqon085661@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Bojan =?utf-8?Q?Novkovi=C4=87?= Subject: git: fba91af3b09b - main - makefs: Honor -T timestamps when creating images from mtree manifests List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bnovkov X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: fba91af3b09b0cb021a50da2bc78e44dfd49b69a Auto-Submitted: auto-generated The branch main has been updated by bnovkov: URL: https://cgit.FreeBSD.org/src/commit/?id=fba91af3b09b0cb021a50da2bc78e44dfd49b69a commit fba91af3b09b0cb021a50da2bc78e44dfd49b69a Author: Bojan Novković AuthorDate: 2025-03-24 15:47:35 +0000 Commit: Bojan Novković CommitDate: 2025-05-20 09:50:22 +0000 makefs: Honor -T timestamps when creating images from mtree manifests makefs backends rely on the fsnode structure to derive most of the information about the underlying filesystem objects. Depending on how the image is built, the fsnode structures are initialized in the walk_dir or read_mtree functions. However, read_mtree fails to take timestamps passed by -T into account, leading to nonreproducible images in backends that do not check for -T. Fix this and make -T backend-agnostic by adding an appropriate check in read_mtree_keywords while making sure that mtree entries can still override -T timestamps. PR: 285630 Sponsored by: Klara, Inc. Sponsored by: The FreeBSD Foundation Reviewed by: markj, emaste Differential Revision: https://reviews.freebsd.org/D49531 --- usr.sbin/makefs/makefs.8 | 8 ++++++-- usr.sbin/makefs/makefs.c | 16 ++++++++++++++++ usr.sbin/makefs/makefs.h | 1 + usr.sbin/makefs/mtree.c | 19 ++++++++++++++++--- usr.sbin/makefs/walk.c | 16 ++-------------- 5 files changed, 41 insertions(+), 19 deletions(-) diff --git a/usr.sbin/makefs/makefs.8 b/usr.sbin/makefs/makefs.8 index ae11309953e4..a11eaf8206e9 100644 --- a/usr.sbin/makefs/makefs.8 +++ b/usr.sbin/makefs/makefs.8 @@ -259,9 +259,13 @@ can be a .Pa pathname , where the timestamps are derived from that file, or an integer value interpreted as the number of seconds from the Epoch. -Note that timestamps specified in an +Timestamps in a .Xr mtree 5 -spec file, override the default timestamp. +specfile (specified with +.Fl F ) +are used even if a default timestamp is specified. +However, the timestamps in an mtree manifest are ignored +if a default timestamp is specified. .It Fl t Ar fs-type Create an .Ar fs-type diff --git a/usr.sbin/makefs/makefs.c b/usr.sbin/makefs/makefs.c index d85b9c2668e7..46e513e22b25 100644 --- a/usr.sbin/makefs/makefs.c +++ b/usr.sbin/makefs/makefs.c @@ -436,6 +436,22 @@ set_option_var(const option_t *options, const char *var, const char *val, return -1; } +void +set_tstamp(fsnode *cur) +{ + cur->inode->st.st_atime = stampst.st_atime; + cur->inode->st.st_mtime = stampst.st_mtime; + cur->inode->st.st_ctime = stampst.st_ctime; +#if HAVE_STRUCT_STAT_ST_MTIMENSEC + cur->inode->st.st_atimensec = stampst.st_atimensec; + cur->inode->st.st_mtimensec = stampst.st_mtimensec; + cur->inode->st.st_ctimensec = stampst.st_ctimensec; +#endif +#if HAVE_STRUCT_STAT_BIRTHTIME + cur->inode->st.st_birthtime = stampst.st_birthtime; + cur->inode->st.st_birthtimensec = stampst.st_birthtimensec; +#endif +} static fstype_t * get_fstype(const char *type) diff --git a/usr.sbin/makefs/makefs.h b/usr.sbin/makefs/makefs.h index 62c7e430a00c..3cd56a036670 100644 --- a/usr.sbin/makefs/makefs.h +++ b/usr.sbin/makefs/makefs.h @@ -188,6 +188,7 @@ fsnode * read_mtree(const char *, fsnode *); int set_option(const option_t *, const char *, char *, size_t); int set_option_var(const option_t *, const char *, const char *, char *, size_t); +void set_tstamp(fsnode *); fsnode * walk_dir(const char *, const char *, fsnode *, fsnode *); void free_fsnodes(fsnode *); option_t * copy_opts(const option_t *); diff --git a/usr.sbin/makefs/mtree.c b/usr.sbin/makefs/mtree.c index 83e207b07402..4f3c3f85dcc3 100644 --- a/usr.sbin/makefs/mtree.c +++ b/usr.sbin/makefs/mtree.c @@ -631,6 +631,9 @@ read_mtree_keywords(FILE *fp, fsnode *node) } /* Ignore. */ } else if (strcmp(keyword, "time") == 0) { + /* Ignore if a default timestamp is present. */ + if (stampst.st_ino != 0) + break; if (value == NULL) { error = ENOATTR; break; @@ -720,7 +723,9 @@ read_mtree_keywords(FILE *fp, fsnode *node) return (error); st->st_mode = (st->st_mode & ~S_IFMT) | node->type; - + /* Store default timestamp, if present. */ + if (stampst.st_ino != 0) + set_tstamp(node); /* Nothing more to do for the global defaults. */ if (node->name == NULL) return (0); @@ -1051,8 +1056,16 @@ read_mtree(const char *fname, fsnode *node) mtree_global.inode = &mtree_global_inode; mtree_global_inode.nlink = 1; mtree_global_inode.st.st_nlink = 1; - mtree_global_inode.st.st_atime = mtree_global_inode.st.st_ctime = - mtree_global_inode.st.st_mtime = time(NULL); + if (stampst.st_ino != 0) { + set_tstamp(&mtree_global); + } else { +#if HAVE_STRUCT_STAT_BIRTHTIME + mtree_global_inode.st.st_birthtime = +#endif + mtree_global_inode.st.st_atime = + mtree_global_inode.st.st_ctime = + mtree_global_inode.st.st_mtime = time(NULL); + } errors = warnings = 0; setgroupent(1); diff --git a/usr.sbin/makefs/walk.c b/usr.sbin/makefs/walk.c index dc03a16cf2c6..65ba3f41fe02 100644 --- a/usr.sbin/makefs/walk.c +++ b/usr.sbin/makefs/walk.c @@ -248,20 +248,8 @@ create_fsnode(const char *root, const char *path, const char *name, cur->type = stbuf->st_mode & S_IFMT; cur->inode->nlink = 1; cur->inode->st = *stbuf; - if (stampst.st_ino) { - cur->inode->st.st_atime = stampst.st_atime; - cur->inode->st.st_mtime = stampst.st_mtime; - cur->inode->st.st_ctime = stampst.st_ctime; -#if HAVE_STRUCT_STAT_ST_MTIMENSEC - cur->inode->st.st_atimensec = stampst.st_atimensec; - cur->inode->st.st_mtimensec = stampst.st_mtimensec; - cur->inode->st.st_ctimensec = stampst.st_ctimensec; -#endif -#if HAVE_STRUCT_STAT_BIRTHTIME - cur->inode->st.st_birthtime = stampst.st_birthtime; - cur->inode->st.st_birthtimensec = stampst.st_birthtimensec; -#endif - } + if (stampst.st_ino != 0) + set_tstamp(cur); return (cur); }