From 4ad8d73326f5120275499b44420f87f72f35b1e7 Mon Sep 17 00:00:00 2001 From: Marcel Moolenaar Date: Sat, 5 Nov 2016 16:23:33 +0000 Subject: [PATCH] Assign a random number to di_gen (for FFS), instead of extracting it from struct stat. We don't necessarily have permissions to see the generation number and the host OS may not have st_gen in struct stat anyway. Since the kernel assigns random numbers, there's nothing meaningful about the generation that requires us to preserve it when the file system image is created. With this change, all generation numbers come from random() and that makes it easier to add support for reproducible builds at some time in the future (i.e. by adding an argument to makefs that changes the behaviour of random() so that it always returns 0 or some predictable sequence). Differential Revision: https://reviews.freebsd.org/D8418 --- usr.sbin/makefs/Makefile | 1 - usr.sbin/makefs/ffs.c | 8 ++------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/usr.sbin/makefs/Makefile b/usr.sbin/makefs/Makefile index a02458044d25..ac59e3c58a3d 100644 --- a/usr.sbin/makefs/Makefile +++ b/usr.sbin/makefs/Makefile @@ -20,7 +20,6 @@ WARNS?= 2 .include "${SRCDIR}/ffs/Makefile.inc" CFLAGS+=-DHAVE_STRUCT_STAT_ST_FLAGS=1 -CFLAGS+=-DHAVE_STRUCT_STAT_ST_GEN=1 .PATH: ${SRCTOP}/contrib/mtree CFLAGS+=-I${SRCTOP}/contrib/mtree diff --git a/usr.sbin/makefs/ffs.c b/usr.sbin/makefs/ffs.c index 8ed7f1f11259..16d60b495bd6 100644 --- a/usr.sbin/makefs/ffs.c +++ b/usr.sbin/makefs/ffs.c @@ -666,9 +666,7 @@ ffs_build_dinode1(struct ufs1_dinode *dinp, dirbuf_t *dbufp, fsnode *cur, #if HAVE_STRUCT_STAT_ST_FLAGS dinp->di_flags = cur->inode->st.st_flags; #endif -#if HAVE_STRUCT_STAT_ST_GEN - dinp->di_gen = cur->inode->st.st_gen; -#endif + dinp->di_gen = random(); dinp->di_uid = cur->inode->st.st_uid; dinp->di_gid = cur->inode->st.st_gid; @@ -716,9 +714,7 @@ ffs_build_dinode2(struct ufs2_dinode *dinp, dirbuf_t *dbufp, fsnode *cur, #if HAVE_STRUCT_STAT_ST_FLAGS dinp->di_flags = cur->inode->st.st_flags; #endif -#if HAVE_STRUCT_STAT_ST_GEN - dinp->di_gen = cur->inode->st.st_gen; -#endif + dinp->di_gen = random(); dinp->di_uid = cur->inode->st.st_uid; dinp->di_gid = cur->inode->st.st_gid;