summaryrefslogtreecommitdiffstats
path: root/usr.sbin/makefs
diff options
context:
space:
mode:
authornatano <natano@openbsd.org>2016-10-22 19:17:47 +0000
committernatano <natano@openbsd.org>2016-10-22 19:17:47 +0000
commitbc67c994a83a243b8b3a2b2e2e18cd6a813ceaa1 (patch)
tree1ca647b7dd1a1269c61869efc6a63cfe07e0f499 /usr.sbin/makefs
parentWhen checking ownership and modes of files in /var/mail/, (diff)
downloadwireguard-openbsd-bc67c994a83a243b8b3a2b2e2e18cd6a813ceaa1.tar.xz
wireguard-openbsd-bc67c994a83a243b8b3a2b2e2e18cd6a813ceaa1.zip
Clean up timestamp handling code to be less confusing.
Diffstat (limited to 'usr.sbin/makefs')
-rw-r--r--usr.sbin/makefs/cd9660.c10
-rw-r--r--usr.sbin/makefs/ffs.c34
-rw-r--r--usr.sbin/makefs/makefs.c27
-rw-r--r--usr.sbin/makefs/makefs.h6
-rw-r--r--usr.sbin/makefs/walk.c16
5 files changed, 45 insertions, 48 deletions
diff --git a/usr.sbin/makefs/cd9660.c b/usr.sbin/makefs/cd9660.c
index 9ce68699b17..61f6f32d6c8 100644
--- a/usr.sbin/makefs/cd9660.c
+++ b/usr.sbin/makefs/cd9660.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cd9660.c,v 1.8 2016/10/22 18:17:14 natano Exp $ */
+/* $OpenBSD: cd9660.c,v 1.9 2016/10/22 19:17:47 natano Exp $ */
/* $NetBSD: cd9660.c,v 1.52 2015/12/24 15:52:37 christos Exp $ */
/*
@@ -624,7 +624,7 @@ typedef int (*cd9660node_func)(cd9660node *);
static void
cd9660_finalize_PVD(iso9660_disk *diskStructure)
{
- time_t tstamp = stampst.st_ino ? stampst.st_mtime : time(NULL);
+ time_t tstamp = Tflag ? stampts : time(NULL);
/* root should be a fixed size of 34 bytes since it has no name */
memcpy(diskStructure->primaryDescriptor.root_directory_record,
@@ -784,7 +784,7 @@ cd9660_fill_extended_attribute_record(cd9660node *node)
static int
cd9660_translate_node_common(iso9660_disk *diskStructure, cd9660node *newnode)
{
- time_t tstamp = stampst.st_ino ? stampst.st_mtime : time(NULL);
+ time_t tstamp = Tflag ? stampts : time(NULL);
u_char flag;
char temp[ISO_FILENAME_MAXLENGTH_WITH_PADDING];
@@ -846,7 +846,7 @@ cd9660_translate_node(iso9660_disk *diskStructure, fsnode *node,
/* Finally, overwrite some of the values that are set by default */
cd9660_time_915(newnode->isoDirRecord->date,
- stampst.st_ino ? stampst.st_mtime : node->inode->st.st_mtime);
+ Tflag ? stampts : node->inode->st.st_mtime);
return 1;
}
@@ -1245,7 +1245,7 @@ cd9660_rrip_move_directory(iso9660_disk *diskStructure, cd9660node *dir)
if (diskStructure->rr_moved_dir == NULL)
return 0;
cd9660_time_915(diskStructure->rr_moved_dir->isoDirRecord->date,
- stampst.st_ino ? stampst.st_mtime : start_time.tv_sec);
+ Tflag ? stampts : start_time.tv_sec);
}
/* Create a file with the same ORIGINAL name */
diff --git a/usr.sbin/makefs/ffs.c b/usr.sbin/makefs/ffs.c
index a0f3e9cc297..0b932ca960e 100644
--- a/usr.sbin/makefs/ffs.c
+++ b/usr.sbin/makefs/ffs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ffs.c,v 1.14 2016/10/22 18:17:14 natano Exp $ */
+/* $OpenBSD: ffs.c,v 1.15 2016/10/22 19:17:47 natano Exp $ */
/* $NetBSD: ffs.c,v 1.66 2015/12/21 00:58:08 christos Exp $ */
/*
@@ -418,9 +418,9 @@ ffs_create_image(const char *image, fsinfo_t *fsopts)
free(buf);
/* make the file system */
- if (stampst.st_ino == 1) {
- tstamp = stampst.st_ctime;
- srandom_deterministic(tstamp);
+ if (Tflag) {
+ tstamp = stampts;
+ srandom_deterministic(stampts);
} else
tstamp = start_time.tv_sec;
@@ -501,7 +501,6 @@ ffs_build_dinode1(struct ufs1_dinode *dinp, dirbuf_t *dbufp, fsnode *cur,
{
size_t slen;
void *membuf;
- struct stat *st = stampst.st_ino == 1 ? &stampst : &cur->inode->st;
memset(dinp, 0, sizeof(*dinp));
dinp->di_mode = cur->inode->st.st_mode;
@@ -512,12 +511,12 @@ ffs_build_dinode1(struct ufs1_dinode *dinp, dirbuf_t *dbufp, fsnode *cur,
dinp->di_uid = cur->inode->st.st_uid;
dinp->di_gid = cur->inode->st.st_gid;
- dinp->di_atime = st->st_atime;
- dinp->di_mtime = st->st_mtime;
- dinp->di_ctime = st->st_ctime;
- dinp->di_atimensec = st->st_atimensec;
- dinp->di_mtimensec = st->st_mtimensec;
- dinp->di_ctimensec = st->st_ctimensec;
+ dinp->di_atime = cur->inode->st.st_atime;
+ dinp->di_mtime = cur->inode->st.st_mtime;
+ dinp->di_ctime = cur->inode->st.st_ctime;
+ dinp->di_atimensec = cur->inode->st.st_atimensec;
+ dinp->di_mtimensec = cur->inode->st.st_mtimensec;
+ dinp->di_ctimensec = cur->inode->st.st_ctimensec;
/* not set: di_db, di_ib, di_blocks, di_spare */
membuf = NULL;
@@ -545,7 +544,6 @@ ffs_build_dinode2(struct ufs2_dinode *dinp, dirbuf_t *dbufp, fsnode *cur,
{
size_t slen;
void *membuf;
- struct stat *st = stampst.st_ino == 1 ? &stampst : &cur->inode->st;
memset(dinp, 0, sizeof(*dinp));
dinp->di_mode = cur->inode->st.st_mode;
@@ -556,12 +554,12 @@ ffs_build_dinode2(struct ufs2_dinode *dinp, dirbuf_t *dbufp, fsnode *cur,
dinp->di_uid = cur->inode->st.st_uid;
dinp->di_gid = cur->inode->st.st_gid;
- dinp->di_atime = st->st_atime;
- dinp->di_mtime = st->st_mtime;
- dinp->di_ctime = st->st_ctime;
- dinp->di_atimensec = st->st_atimensec;
- dinp->di_mtimensec = st->st_mtimensec;
- dinp->di_ctimensec = st->st_ctimensec;
+ dinp->di_atime = cur->inode->st.st_atime;
+ dinp->di_mtime = cur->inode->st.st_mtime;
+ dinp->di_ctime = cur->inode->st.st_ctime;
+ dinp->di_atimensec = cur->inode->st.st_atimensec;
+ dinp->di_mtimensec = cur->inode->st.st_mtimensec;
+ dinp->di_ctimensec = cur->inode->st.st_ctimensec;
/* not set: di_db, di_ib, di_blocks, di_spare */
membuf = NULL;
diff --git a/usr.sbin/makefs/makefs.c b/usr.sbin/makefs/makefs.c
index 295c67dc506..2a720d2d7b4 100644
--- a/usr.sbin/makefs/makefs.c
+++ b/usr.sbin/makefs/makefs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: makefs.c,v 1.12 2016/10/22 18:17:14 natano Exp $ */
+/* $OpenBSD: makefs.c,v 1.13 2016/10/22 19:17:47 natano Exp $ */
/* $NetBSD: makefs.c,v 1.53 2015/11/27 15:10:32 joerg Exp $ */
/*
@@ -71,11 +71,12 @@ static fstype_t fstypes[] = {
{ .type = NULL },
};
+int Tflag;
+time_t stampts;
struct timespec start_time;
-struct stat stampst;
static fstype_t *get_fstype(const char *);
-static int get_tstamp(const char *, struct stat *);
+static time_t get_tstamp(const char *);
static long long strsuftoll(const char *, const char *, long long, long long);
static void usage(fstype_t *, fsinfo_t *) __dead;
@@ -183,9 +184,8 @@ main(int argc, char *argv[])
break;
case 'T':
- if (get_tstamp(optarg, &stampst) == -1)
- errx(1, "Cannot get timestamp from `%s'",
- optarg);
+ Tflag = 1;
+ stampts = get_tstamp(optarg);
break;
case '?':
@@ -308,20 +308,19 @@ copy_opts(const option_t *o)
return memcpy(ecalloc(i, sizeof(*o)), o, i * sizeof(*o));
}
-static int
-get_tstamp(const char *b, struct stat *st)
+static time_t
+get_tstamp(const char *b)
{
time_t when;
char *eb;
errno = 0;
when = strtoll(b, &eb, 0);
- if (b == eb || *eb || errno)
- return -1;
-
- st->st_ino = 1;
- st->st_mtime = st->st_ctime = st->st_atime = when;
- return 0;
+ if (b == eb || *eb || errno) {
+ errx(1, "Cannot get timestamp from `%s'",
+ optarg);
+ }
+ return when;
}
/* XXX */
diff --git a/usr.sbin/makefs/makefs.h b/usr.sbin/makefs/makefs.h
index 1f82c2ccaa3..7e40e2cc0d2 100644
--- a/usr.sbin/makefs/makefs.h
+++ b/usr.sbin/makefs/makefs.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: makefs.h,v 1.7 2016/10/22 18:17:14 natano Exp $ */
+/* $OpenBSD: makefs.h,v 1.8 2016/10/22 19:17:47 natano Exp $ */
/* $NetBSD: makefs.h,v 1.36 2015/11/25 00:48:49 christos Exp $ */
/*
@@ -178,9 +178,9 @@ DECLARE_FUN(ffs);
DECLARE_FUN(cd9660);
DECLARE_FUN(msdos);
-extern u_int debug;
+extern int Tflag;
+extern time_t stampts;
extern struct timespec start_time;
-extern struct stat stampst;
#ifndef DEFAULT_FSTYPE
diff --git a/usr.sbin/makefs/walk.c b/usr.sbin/makefs/walk.c
index 5bc57e59abd..0759ea41258 100644
--- a/usr.sbin/makefs/walk.c
+++ b/usr.sbin/makefs/walk.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: walk.c,v 1.6 2016/10/22 18:17:14 natano Exp $ */
+/* $OpenBSD: walk.c,v 1.7 2016/10/22 19:17:47 natano Exp $ */
/* $NetBSD: walk.c,v 1.29 2015/11/25 00:48:49 christos Exp $ */
/*
@@ -203,13 +203,13 @@ create_fsnode(const char *root, const char *path, const char *name,
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;
- cur->inode->st.st_atimensec = stampst.st_atimensec;
- cur->inode->st.st_mtimensec = stampst.st_mtimensec;
- cur->inode->st.st_ctimensec = stampst.st_ctimensec;
+ if (Tflag) {
+ cur->inode->st.st_atime = stampts;
+ cur->inode->st.st_mtime = stampts;
+ cur->inode->st.st_ctime = stampts;
+ cur->inode->st.st_atimensec = 0;
+ cur->inode->st.st_mtimensec = 0;
+ cur->inode->st.st_ctimensec = 0;
}
return (cur);
}