From owner-svn-src-stable@freebsd.org Mon Jul 16 03:59:42 2018 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2C70B103C215; Mon, 16 Jul 2018 03:59:42 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id D00597D6C9; Mon, 16 Jul 2018 03:59:41 +0000 (UTC) (envelope-from delphij@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 B101017597; Mon, 16 Jul 2018 03:59:41 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w6G3xfMP010470; Mon, 16 Jul 2018 03:59:41 GMT (envelope-from delphij@FreeBSD.org) Received: (from delphij@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w6G3xeDb010466; Mon, 16 Jul 2018 03:59:40 GMT (envelope-from delphij@FreeBSD.org) Message-Id: <201807160359.w6G3xeDb010466@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: delphij set sender to delphij@FreeBSD.org using -f From: Xin LI Date: Mon, 16 Jul 2018 03:59:40 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r336328 - stable/11/sbin/newfs_msdos X-SVN-Group: stable-11 X-SVN-Commit-Author: delphij X-SVN-Commit-Paths: stable/11/sbin/newfs_msdos X-SVN-Commit-Revision: 336328 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Jul 2018 03:59:42 -0000 Author: delphij Date: Mon Jul 16 03:59:40 2018 New Revision: 336328 URL: https://svnweb.freebsd.org/changeset/base/336328 Log: MFC r318355,318366: add -T (timestamp) option for reproducible builds Modified: stable/11/sbin/newfs_msdos/mkfs_msdos.c stable/11/sbin/newfs_msdos/mkfs_msdos.h stable/11/sbin/newfs_msdos/newfs_msdos.8 stable/11/sbin/newfs_msdos/newfs_msdos.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sbin/newfs_msdos/mkfs_msdos.c ============================================================================== --- stable/11/sbin/newfs_msdos/mkfs_msdos.c Mon Jul 16 02:48:59 2018 (r336327) +++ stable/11/sbin/newfs_msdos/mkfs_msdos.c Mon Jul 16 03:59:40 2018 (r336328) @@ -573,9 +573,17 @@ mkfs_msdos(const char *fname, const char *dtype, const } print_bpb(&bpb); if (!o.no_create) { - gettimeofday(&tv, NULL); - now = tv.tv_sec; - tm = localtime(&now); + if (o.timestamp_set) { + tv.tv_sec = now = o.timestamp; + tv.tv_usec = 0; + tm = gmtime(&now); + } else { + gettimeofday(&tv, NULL); + now = tv.tv_sec; + tm = localtime(&now); + } + + if (!(img = malloc(bpb.bpbBytesPerSec))) { warn(NULL); goto done; Modified: stable/11/sbin/newfs_msdos/mkfs_msdos.h ============================================================================== --- stable/11/sbin/newfs_msdos/mkfs_msdos.h Mon Jul 16 02:48:59 2018 (r336327) +++ stable/11/sbin/newfs_msdos/mkfs_msdos.h Mon Jul 16 03:59:40 2018 (r336328) @@ -42,6 +42,7 @@ AOPT('L', const char *, volume_label, -1, "Volume Labe AOPT('N', bool, no_create, -2, "Don't create filesystem, print params only") \ AOPT('O', const char *, OEM_string, -1, "OEM string") \ AOPT('S', uint16_t, bytes_per_sector, 1, "Bytes per sector") \ +AOPT('T', time_t, timestamp, 0, "Timestamp") \ AOPT('a', uint32_t, sectors_per_fat, 1, "Sectors per FAT") \ AOPT('b', uint32_t, block_size, 1, "Block size") \ AOPT('c', uint8_t, sectors_per_cluster, 1, "Sectors per cluster") \ @@ -61,6 +62,7 @@ struct msdos_options { #define AOPT(_opt, _type, _name, _min, _desc) _type _name; ALLOPTS #undef AOPT + uint32_t timestamp_set:1; uint32_t volume_id_set:1; uint32_t media_descriptor_set:1; uint32_t hidden_sectors_set:1; Modified: stable/11/sbin/newfs_msdos/newfs_msdos.8 ============================================================================== --- stable/11/sbin/newfs_msdos/newfs_msdos.8 Mon Jul 16 02:48:59 2018 (r336327) +++ stable/11/sbin/newfs_msdos/newfs_msdos.8 Mon Jul 16 03:59:40 2018 (r336328) @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd April 9, 2015 +.Dd May 16, 2017 .Dt NEWFS_MSDOS 8 .Os .Sh NAME @@ -38,10 +38,11 @@ .Op Fl B Ar boot .Op Fl C Ar create-size .Op Fl F Ar FAT-type -.Op Fl I Ar VolumeId +.Op Fl I Ar VolumeID .Op Fl L Ar label .Op Fl O Ar OEM .Op Fl S Ar sector-size +.Op Fl T Ar timestamp .Op Fl a Ar FAT-size .Op Fl b Ar block-size .Op Fl c Ar cluster-size @@ -117,6 +118,14 @@ The default is Number of bytes per sector. Acceptable values are powers of 2 in the range 512 through 32768, inclusive. +.It Fl T Ar timestamp +Create the filesystem as though the current time is +.Ar timestamp . +The default filesystem volume ID is derived from the time. +.Ar timestamp +can be a pathname (where the timestamp is derived from +that file) or an integer value interpreted +as the number of seconds since the Epoch. .It Fl a Ar FAT-size Number of sectors per FAT. .It Fl b Ar block-size @@ -163,7 +172,7 @@ File system size. Number of sectors per track. .El .Sh NOTES -If some parameters (e.g. size, number of sectors, etc.) are not specified +If some parameters (e.g., size, number of sectors, etc.) are not specified through options or disktype, the program tries to generate them automatically. In particular, the size is determined as the device or file size minus the offset specified with the Modified: stable/11/sbin/newfs_msdos/newfs_msdos.c ============================================================================== --- stable/11/sbin/newfs_msdos/newfs_msdos.c Mon Jul 16 02:48:59 2018 (r336327) +++ stable/11/sbin/newfs_msdos/newfs_msdos.c Mon Jul 16 03:59:40 2018 (r336328) @@ -33,7 +33,7 @@ static const char rcsid[] = #endif /* not lint */ #include - +#include #include #include #include @@ -53,13 +53,30 @@ static u_int argtou(const char *, u_int, u_int, const static off_t argtooff(const char *, const char *); static void usage(void); +static time_t +get_tstamp(const char *b) +{ + struct stat st; + char *eb; + long long l; + + if (stat(b, &st) != -1) + return (time_t)st.st_mtime; + + errno = 0; + l = strtoll(b, &eb, 0); + if (b == eb || *eb || errno) + errx(EXIT_FAILURE, "Can't parse timestamp '%s'", b); + return (time_t)l; +} + /* * Construct a FAT12, FAT16, or FAT32 file system. */ int main(int argc, char *argv[]) { - static const char opts[] = "@:NB:C:F:I:L:O:S:a:b:c:e:f:h:i:k:m:n:o:r:s:u:"; + static const char opts[] = "@:NB:C:F:I:L:O:S:a:b:c:e:f:h:i:k:m:n:o:r:s:T:u:"; struct msdos_options o; const char *fname, *dtype; char buf[MAXPATHLEN]; @@ -143,6 +160,10 @@ main(int argc, char *argv[]) break; case 's': o.size = argto4(optarg, 1, "file system size"); + break; + case 'T': + o.timestamp_set = 1; + o.timestamp = get_tstamp(optarg); break; case 'u': o.sectors_per_track = argto2(optarg, 1, "sectors/track");