From ddd1d3d1ff2fecb3b58ce152a65095abaf634491 Mon Sep 17 00:00:00 2001 From: Tomohiro Kusumi Date: Tue, 18 Apr 2023 00:30:26 -0700 Subject: [PATCH] usr.sbin/makefs/hammer2: Derive timestamp from source inodes makefs(8) HAMMER2 has been using current time for inode's ctime/mtime. Change hammer2_update_time() to use current fsnode's timestamp. Also support -T option. Note that both hammer2_curnode (current fsnode) and stampst (-T option) are global variables. --- usr.sbin/makefs/hammer2.c | 5 +++++ usr.sbin/makefs/hammer2/hammer2.h | 5 ++++- usr.sbin/makefs/hammer2/hammer2_inode.c | 4 ++-- usr.sbin/makefs/hammer2/hammer2_subr.c | 14 ++++++++------ usr.sbin/makefs/hammer2/hammer2_vnops.c | 12 ++++++------ 5 files changed, 25 insertions(+), 15 deletions(-) diff --git a/usr.sbin/makefs/hammer2.c b/usr.sbin/makefs/hammer2.c index 73f30609dc..9cd77b753c 100644 --- a/usr.sbin/makefs/hammer2.c +++ b/usr.sbin/makefs/hammer2.c @@ -66,6 +66,8 @@ static void hammer2_validate(const char *, fsnode *, fsinfo_t *); static void hammer2_size_dir(fsnode *, fsinfo_t *); static int hammer2_write_file(struct m_vnode *, const char *, fsnode *); +fsnode *hammer2_curnode; + void hammer2_prep_opts(fsinfo_t *fsopts) { @@ -685,6 +687,9 @@ hammer2_populate_dir(struct m_vnode *dvp, const char *dir, fsnode *root, errx(1, "no such dir %s", dir); for (cur = root->next; cur != NULL; cur = cur->next) { + /* global variable for HAMMER2 vnops */ + hammer2_curnode = cur; + /* construct source path */ if (cur->contents) { path = cur->contents; diff --git a/usr.sbin/makefs/hammer2/hammer2.h b/usr.sbin/makefs/hammer2/hammer2.h index 73973c4c88..3af76025d0 100644 --- a/usr.sbin/makefs/hammer2/hammer2.h +++ b/usr.sbin/makefs/hammer2/hammer2.h @@ -137,6 +137,7 @@ #include #include "hammer2_compat.h" +#include "makefs.h" struct hammer2_io; struct hammer2_chain; @@ -1497,7 +1498,7 @@ int hammer2_getradix(size_t bytes); int hammer2_calc_logical(hammer2_inode_t *ip, hammer2_off_t uoff, hammer2_key_t *lbasep, hammer2_key_t *leofp); int hammer2_calc_physical(hammer2_inode_t *ip, hammer2_key_t lbase); -void hammer2_update_time(uint64_t *timep); +void hammer2_update_time(uint64_t *timep, bool is_mtime); void hammer2_adjreadcounter(int btype, size_t bytes); void hammer2_adjwritecounter(int btype, size_t bytes); @@ -2089,5 +2090,7 @@ hammer2_iocom_uninit(hammer2_dev_t *hmp) { } +extern fsnode *hammer2_curnode; + //#endif /* !_KERNEL */ #endif /* !_VFS_HAMMER2_HAMMER2_H_ */ diff --git a/usr.sbin/makefs/hammer2/hammer2_inode.c b/usr.sbin/makefs/hammer2/hammer2_inode.c index 470d15cb75..9b17af1ded 100644 --- a/usr.sbin/makefs/hammer2/hammer2_inode.c +++ b/usr.sbin/makefs/hammer2/hammer2_inode.c @@ -1048,7 +1048,7 @@ hammer2_inode_create_pfs(hammer2_pfs_t *spmp, xop->meta.comp_algo = pip_comp_algo; xop->meta.check_algo = pip_check_algo; xop->meta.version = HAMMER2_INODE_VERSION_ONE; - hammer2_update_time(&xop->meta.ctime); + hammer2_update_time(&xop->meta.ctime, false); xop->meta.mtime = xop->meta.ctime; xop->meta.mode = 0755; xop->meta.nlinks = 1; @@ -1172,7 +1172,7 @@ hammer2_inode_create_normal(hammer2_inode_t *pip, nip->meta.comp_algo = pip_comp_algo; nip->meta.check_algo = pip_check_algo; nip->meta.version = HAMMER2_INODE_VERSION_ONE; - hammer2_update_time(&nip->meta.ctime); + hammer2_update_time(&nip->meta.ctime, false); nip->meta.mtime = nip->meta.ctime; nip->meta.mode = vap->va_mode; nip->meta.nlinks = 1; diff --git a/usr.sbin/makefs/hammer2/hammer2_subr.c b/usr.sbin/makefs/hammer2/hammer2_subr.c index e49c80a447..bcfa4fd6ec 100644 --- a/usr.sbin/makefs/hammer2/hammer2_subr.c +++ b/usr.sbin/makefs/hammer2/hammer2_subr.c @@ -309,14 +309,16 @@ hammer2_calc_physical(hammer2_inode_t *ip, hammer2_key_t lbase) } void -hammer2_update_time(uint64_t *timep) +hammer2_update_time(uint64_t *timep, bool is_mtime) { - struct timeval ts; - int error; + struct timespec *ts; + struct stat *st; - error = gettimeofday(&ts, NULL); - KKASSERT(error == 0); - *timep = (unsigned long)ts.tv_sec * 1000000 + ts.tv_usec; + assert(hammer2_curnode); + st = stampst.st_ino != 0 ? &stampst : &hammer2_curnode->inode->st; + ts = is_mtime ? &st->st_mtim : &st->st_ctim; + + *timep = (uint64_t)ts->tv_sec * 1000000 + ts->tv_nsec / 1000; } void diff --git a/usr.sbin/makefs/hammer2/hammer2_vnops.c b/usr.sbin/makefs/hammer2/hammer2_vnops.c index e00f6215a9..e57546c7a9 100644 --- a/usr.sbin/makefs/hammer2/hammer2_vnops.c +++ b/usr.sbin/makefs/hammer2/hammer2_vnops.c @@ -1300,7 +1300,7 @@ hammer2_write_file(hammer2_inode_t *ip, struct uio *uio, } */ } else { - hammer2_update_time(&ip->meta.mtime); + hammer2_update_time(&ip->meta.mtime, true); vclrflags(vp, VLASTWRITETS); } @@ -1628,7 +1628,7 @@ hammer2_vop_nmkdir(struct vop_nmkdir_args *ap) uint64_t mtime; /*hammer2_inode_lock(dip, HAMMER2_RESOLVE_SHARED);*/ - hammer2_update_time(&mtime); + hammer2_update_time(&mtime, true); hammer2_inode_modify(dip); dip->meta.mtime = mtime; /*hammer2_inode_unlock(dip);*/ @@ -1773,7 +1773,7 @@ hammer2_vop_nlink(struct vop_nlink_args *ap) */ hammer2_inode_lock4(tdip, ip, NULL, NULL); - hammer2_update_time(&cmtime); + hammer2_update_time(&cmtime, true); /* * Create the directory entry and bump nlinks. @@ -1894,7 +1894,7 @@ hammer2_vop_ncreate(struct vop_ncreate_args *ap) uint64_t mtime; /*hammer2_inode_lock(dip, HAMMER2_RESOLVE_SHARED);*/ - hammer2_update_time(&mtime); + hammer2_update_time(&mtime, true); hammer2_inode_modify(dip); dip->meta.mtime = mtime; /*hammer2_inode_unlock(dip);*/ @@ -2000,7 +2000,7 @@ hammer2_vop_nmknod(struct vop_nmknod_args *ap) uint64_t mtime; /*hammer2_inode_lock(dip, HAMMER2_RESOLVE_SHARED);*/ - hammer2_update_time(&mtime); + hammer2_update_time(&mtime, true); hammer2_inode_modify(dip); dip->meta.mtime = mtime; /*hammer2_inode_unlock(dip);*/ @@ -2138,7 +2138,7 @@ hammer2_vop_nsymlink(struct vop_nsymlink_args *ap) uint64_t mtime; /*hammer2_inode_lock(dip, HAMMER2_RESOLVE_SHARED);*/ - hammer2_update_time(&mtime); + hammer2_update_time(&mtime, true); hammer2_inode_modify(dip); dip->meta.mtime = mtime; /*hammer2_inode_unlock(dip);*/ -- 2.11.4.GIT