diff --git a/usr.sbin/makefs/makefs.h b/usr.sbin/makefs/makefs.h --- a/usr.sbin/makefs/makefs.h +++ b/usr.sbin/makefs/makefs.h @@ -188,6 +188,7 @@ 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/makefs.8 b/usr.sbin/makefs/makefs.8 --- a/usr.sbin/makefs/makefs.8 +++ b/usr.sbin/makefs/makefs.8 @@ -259,9 +259,13 @@ .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 --- a/usr.sbin/makefs/makefs.c +++ b/usr.sbin/makefs/makefs.c @@ -436,6 +436,22 @@ 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/mtree.c b/usr.sbin/makefs/mtree.c --- a/usr.sbin/makefs/mtree.c +++ b/usr.sbin/makefs/mtree.c @@ -631,6 +631,9 @@ } /* 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 @@ 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 @@ 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 --- a/usr.sbin/makefs/walk.c +++ b/usr.sbin/makefs/walk.c @@ -248,20 +248,8 @@ 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); }