diff options
author | jilles <jilles@FreeBSD.org> | 2015-03-14 13:45:43 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2015-03-14 13:45:43 +0000 |
commit | 238e0c50012e6d47c6ff241647b85c624558039e (patch) | |
tree | 96582113fd54b1c0e8a4956f2ce0f91a229e15cb /sbin/restore | |
parent | 470fe38d1f7205106865f5e7622c7a08d45eb0a2 (diff) | |
download | FreeBSD-src-238e0c50012e6d47c6ff241647b85c624558039e.zip FreeBSD-src-238e0c50012e6d47c6ff241647b85c624558039e.tar.gz |
restore: Preserve timestamps to the nanosecond.
The restore utility already knows the full-resolution timestamps, so the
only thing to do is to stop converting the timespecs to timevals and use
futimens() and utimensat().
Differential Revision: https://reviews.freebsd.org/D2020
Reviewed by: jhb
Diffstat (limited to 'sbin/restore')
-rw-r--r-- | sbin/restore/dirs.c | 16 | ||||
-rw-r--r-- | sbin/restore/tape.c | 28 |
2 files changed, 23 insertions, 21 deletions
diff --git a/sbin/restore/dirs.c b/sbin/restore/dirs.c index b2cd8fd..7b308cd 100644 --- a/sbin/restore/dirs.c +++ b/sbin/restore/dirs.c @@ -80,8 +80,8 @@ static struct inotab *inotab[HASHSIZE]; */ struct modeinfo { ino_t ino; - struct timeval ctimep[2]; - struct timeval mtimep[2]; + struct timespec ctimep[2]; + struct timespec mtimep[2]; mode_t mode; uid_t uid; gid_t gid; @@ -656,8 +656,8 @@ setdirmodes(int flags) else (void) chown(cp, node.uid, node.gid); (void) chmod(cp, node.mode); - utimes(cp, node.ctimep); - utimes(cp, node.mtimep); + utimensat(AT_FDCWD, cp, node.ctimep, 0); + utimensat(AT_FDCWD, cp, node.mtimep, 0); (void) chflags(cp, node.flags); } ep->e_flags &= ~NEW; @@ -746,13 +746,13 @@ allocinotab(struct context *ctxp, long seekpt) return (itp); node.ino = ctxp->ino; node.mtimep[0].tv_sec = ctxp->atime_sec; - node.mtimep[0].tv_usec = ctxp->atime_nsec / 1000; + node.mtimep[0].tv_nsec = ctxp->atime_nsec; node.mtimep[1].tv_sec = ctxp->mtime_sec; - node.mtimep[1].tv_usec = ctxp->mtime_nsec / 1000; + node.mtimep[1].tv_nsec = ctxp->mtime_nsec; node.ctimep[0].tv_sec = ctxp->atime_sec; - node.ctimep[0].tv_usec = ctxp->atime_nsec / 1000; + node.ctimep[0].tv_nsec = ctxp->atime_nsec; node.ctimep[1].tv_sec = ctxp->birthtime_sec; - node.ctimep[1].tv_usec = ctxp->birthtime_nsec / 1000; + node.ctimep[1].tv_nsec = ctxp->birthtime_nsec; node.extsize = ctxp->extsize; node.mode = ctxp->mode; node.flags = ctxp->file_flags; diff --git a/sbin/restore/tape.c b/sbin/restore/tape.c index 225fe32..9c9890f 100644 --- a/sbin/restore/tape.c +++ b/sbin/restore/tape.c @@ -569,20 +569,20 @@ extractfile(char *name) gid_t gid; mode_t mode; int extsize; - struct timeval mtimep[2], ctimep[2]; + struct timespec mtimep[2], ctimep[2]; struct entry *ep; char *buf; curfile.name = name; curfile.action = USING; mtimep[0].tv_sec = curfile.atime_sec; - mtimep[0].tv_usec = curfile.atime_nsec / 1000; + mtimep[0].tv_nsec = curfile.atime_nsec; mtimep[1].tv_sec = curfile.mtime_sec; - mtimep[1].tv_usec = curfile.mtime_nsec / 1000; + mtimep[1].tv_nsec = curfile.mtime_nsec; ctimep[0].tv_sec = curfile.atime_sec; - ctimep[0].tv_usec = curfile.atime_nsec / 1000; + ctimep[0].tv_nsec = curfile.atime_nsec; ctimep[1].tv_sec = curfile.birthtime_sec; - ctimep[1].tv_usec = curfile.birthtime_nsec / 1000; + ctimep[1].tv_nsec = curfile.birthtime_nsec; extsize = curfile.extsize; uid = getuid(); if (uid == 0) @@ -628,8 +628,10 @@ extractfile(char *name) set_extattr_link(name, buf, extsize); (void) lchown(name, uid, gid); (void) lchmod(name, mode); - (void) lutimes(name, ctimep); - (void) lutimes(name, mtimep); + (void) utimensat(AT_FDCWD, name, ctimep, + AT_SYMLINK_NOFOLLOW); + (void) utimensat(AT_FDCWD, name, mtimep, + AT_SYMLINK_NOFOLLOW); (void) lchflags(name, flags); return (GOOD); } @@ -658,8 +660,8 @@ extractfile(char *name) } (void) chown(name, uid, gid); (void) chmod(name, mode); - (void) utimes(name, ctimep); - (void) utimes(name, mtimep); + (void) utimensat(AT_FDCWD, name, ctimep, 0); + (void) utimensat(AT_FDCWD, name, mtimep, 0); (void) chflags(name, flags); return (GOOD); @@ -688,8 +690,8 @@ extractfile(char *name) } (void) chown(name, uid, gid); (void) chmod(name, mode); - (void) utimes(name, ctimep); - (void) utimes(name, mtimep); + (void) utimensat(AT_FDCWD, name, ctimep, 0); + (void) utimensat(AT_FDCWD, name, mtimep, 0); (void) chflags(name, flags); return (GOOD); @@ -714,8 +716,8 @@ extractfile(char *name) set_extattr_fd(ofile, name, buf, extsize); (void) fchown(ofile, uid, gid); (void) fchmod(ofile, mode); - (void) futimes(ofile, ctimep); - (void) futimes(ofile, mtimep); + (void) futimens(ofile, ctimep); + (void) futimens(ofile, mtimep); (void) fchflags(ofile, flags); (void) close(ofile); return (GOOD); |