Module Name: src Committed By: christos Date: Thu Feb 16 18:49:31 UTC 2017
Modified Files: src/sbin/newfs_msdos: mkfs_msdos.c mkfs_msdos.h newfs_msdos.8 newfs_msdos.c Log Message: add -T for reproducible builds (used in makefs) To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/sbin/newfs_msdos/mkfs_msdos.c cvs rdiff -u -r1.3 -r1.4 src/sbin/newfs_msdos/mkfs_msdos.h cvs rdiff -u -r1.21 -r1.22 src/sbin/newfs_msdos/newfs_msdos.8 cvs rdiff -u -r1.43 -r1.44 src/sbin/newfs_msdos/newfs_msdos.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sbin/newfs_msdos/mkfs_msdos.c diff -u src/sbin/newfs_msdos/mkfs_msdos.c:1.10 src/sbin/newfs_msdos/mkfs_msdos.c:1.11 --- src/sbin/newfs_msdos/mkfs_msdos.c:1.10 Sun Apr 3 07:00:13 2016 +++ src/sbin/newfs_msdos/mkfs_msdos.c Thu Feb 16 13:49:31 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: mkfs_msdos.c,v 1.10 2016/04/03 11:00:13 mlelstv Exp $ */ +/* $NetBSD: mkfs_msdos.c,v 1.11 2017/02/16 18:49:31 christos Exp $ */ /* * Copyright (c) 1998 Robert Nordier @@ -37,7 +37,7 @@ static const char rcsid[] = "$FreeBSD: src/sbin/newfs_msdos/newfs_msdos.c,v 1.15 2000/10/10 01:49:37 wollman Exp $"; #else -__RCSID("$NetBSD: mkfs_msdos.c,v 1.10 2016/04/03 11:00:13 mlelstv Exp $"); +__RCSID("$NetBSD: mkfs_msdos.c,v 1.11 2017/02/16 18:49:31 christos Exp $"); #endif #endif /* not lint */ @@ -621,9 +621,15 @@ mkfs_msdos(const char *fname, const char printf("MBR type: %d\n", ch); print_bpb(&bpb); if (!o.no_create) { - gettimeofday(&tv, NULL); - now = tv.tv_sec; - tm = localtime(&now); + if (o.timestamp) { + 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.bps))) err(1, NULL); dir = bpb.res + (bpb.spf ? bpb.spf : bpb.bspf) * bpb.nft; Index: src/sbin/newfs_msdos/mkfs_msdos.h diff -u src/sbin/newfs_msdos/mkfs_msdos.h:1.3 src/sbin/newfs_msdos/mkfs_msdos.h:1.4 --- src/sbin/newfs_msdos/mkfs_msdos.h:1.3 Fri Oct 16 13:38:17 2015 +++ src/sbin/newfs_msdos/mkfs_msdos.h Thu Feb 16 13:49:31 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: mkfs_msdos.h,v 1.3 2015/10/16 17:38:17 christos Exp $ */ +/* $NetBSD: mkfs_msdos.h,v 1.4 2017/02/16 18:49:31 christos Exp $ */ /*- * Copyright (c) 2013 The NetBSD Foundation, Inc. @@ -60,6 +60,7 @@ struct msdos_options { #define AOPT(_opt, _type, _name, _min, _desc) _type _name; ALLOPTS #undef AOPT + time_t timestamp; uint32_t volume_id_set:1; uint32_t media_descriptor_set:1; uint32_t hidden_sectors_set:1; Index: src/sbin/newfs_msdos/newfs_msdos.8 diff -u src/sbin/newfs_msdos/newfs_msdos.8:1.21 src/sbin/newfs_msdos/newfs_msdos.8:1.22 --- src/sbin/newfs_msdos/newfs_msdos.8:1.21 Mon Sep 12 01:09:39 2016 +++ src/sbin/newfs_msdos/newfs_msdos.8 Thu Feb 16 13:49:31 2017 @@ -1,4 +1,4 @@ -.\" $NetBSD: newfs_msdos.8,v 1.21 2016/09/12 05:09:39 sevan Exp $ +.\" $NetBSD: newfs_msdos.8,v 1.22 2017/02/16 18:49:31 christos Exp $ .\" .\" Copyright (c) 1998 Robert Nordier .\" All rights reserved. @@ -27,7 +27,7 @@ .\" .\" From: $FreeBSD: src/sbin/newfs_msdos/newfs_msdos.8,v 1.13 2001/08/14 10:01:48 ru Exp $ .\" -.Dd September 12, 2016 +.Dd February 16, 2017 .Dt NEWFS_MSDOS 8 .Os .Sh NAME @@ -57,6 +57,7 @@ .Op Fl o Ar hidden .Op Fl r Ar reserved .Op Fl s Ar total +.Op Fl T Ar timestamp .Op Fl u Ar track-size .Ar special .Op Ar disktype @@ -147,6 +148,13 @@ Number of hidden sectors. Number of reserved sectors. .It Fl s Ar total File system size. +.It Fl T At timestamp +Specify a timestamp to be used for filesystem creation so that +it can be consistent for reproducible builds. +The timestamp can be a pathname, where the timestamps are derived from +that file, a parseable date for parsedate(3) (this option is not +yet available in the tools build), or an integer value interpreted +as the number of seconds from the Epoch. .It Fl u Ar track-size Number of sectors per track. .El Index: src/sbin/newfs_msdos/newfs_msdos.c diff -u src/sbin/newfs_msdos/newfs_msdos.c:1.43 src/sbin/newfs_msdos/newfs_msdos.c:1.44 --- src/sbin/newfs_msdos/newfs_msdos.c:1.43 Thu Apr 23 09:27:14 2015 +++ src/sbin/newfs_msdos/newfs_msdos.c Thu Feb 16 13:49:31 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: newfs_msdos.c,v 1.43 2015/04/23 13:27:14 abs Exp $ */ +/* $NetBSD: newfs_msdos.c,v 1.44 2017/02/16 18:49:31 christos Exp $ */ /* * Copyright (c) 1998 Robert Nordier @@ -33,11 +33,12 @@ static const char rcsid[] = "$FreeBSD: src/sbin/newfs_msdos/newfs_msdos.c,v 1.15 2000/10/10 01:49:37 wollman Exp $"; #else -__RCSID("$NetBSD: newfs_msdos.c,v 1.43 2015/04/23 13:27:14 abs Exp $"); +__RCSID("$NetBSD: newfs_msdos.c,v 1.44 2017/02/16 18:49:31 christos Exp $"); #endif #endif /* not lint */ #include <sys/param.h> +#include <sys/stat.h> #include <stdio.h> #include <string.h> #include <err.h> @@ -45,6 +46,7 @@ __RCSID("$NetBSD: newfs_msdos.c,v 1.43 2 #include <unistd.h> #include <paths.h> #include <errno.h> +#include <util.h> #include "mkfs_msdos.h" @@ -57,13 +59,38 @@ __dead static void usage(void); static u_int argtou(const char *, u_int, u_int, const char *); static off_t argtooff(const char *, const char *); +static time_t +get_tstamp(const char *b) +{ + struct stat st; + char *eb; + long long l; +#ifndef HAVE_NBTOOL_CONFIG_H + time_t when; +#endif + + if (stat(b, &st) != -1) + return (time_t)st.st_mtime; + +#ifndef HAVE_NBTOOL_CONFIG_H + errno = 0; + if ((when = parsedate(b, NULL, NULL)) != -1 || errno == 0) + return when; +#endif + 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; char *fname, *dtype; char buf[MAXPATHLEN]; @@ -142,6 +169,9 @@ main(int argc, char *argv[]) case 's': o.size = argto4(optarg, 1, "file system size"); break; + case 'T': + o.timestamp = get_tstamp(optarg); + break; case 'u': o.sectors_per_track = argto2(optarg, 1, "sectors/track"); break;