Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 29 Jan 2009 22:25:13 -0800
From:      Tim Kientzle <kientzle@freebsd.org>
To:        "'current@FreeBSD.org'" <current@freebsd.org>
Subject:   RFC: Change mtree nsec handling?
Message-ID:  <49829D49.10306@freebsd.org>

next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------040708020804040103060208
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

In looking at interoperability between libarchive's
mtree support and the mtree(8) program, I found
that mtree formats timestamps rather strangely.

For example, a timestamp of 1233295862.000001
(1233295682 seconds and 1000 nanoseconds)
will be printed like this by mtree:
    time=1233295862.1000
Unsurprisingly, the mtree parsing works the same
way in reverse.

Basically, mtree is printing (and reading) the time
as whole seconds and nanoseconds separated by a period,
which 90% of the time is the same as a decimal
floating-point number of seconds, but not the other
10% of the time.  This is not documented in mtree.8.
I was quite surprised by it.

The attached patch changes this to use a more conventional
notation (although the patch could use a little more tweaking
to handle >9 digits after the decimal point).

Any concerns about this?

Tim

--------------040708020804040103060208
Content-Type: text/x-patch;
 name="mtree_nsec.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="mtree_nsec.patch"

Index: create.c
===================================================================
--- create.c	(revision 187909)
+++ create.c	(working copy)
@@ -212,7 +212,7 @@
 		output(indent, &offset, "size=%jd",
 		    (intmax_t)p->fts_statp->st_size);
 	if (keys & F_TIME)
-		output(indent, &offset, "time=%ld.%ld",
+		output(indent, &offset, "time=%ld.%09ld",
 		    (long)p->fts_statp->st_mtimespec.tv_sec,
 		    p->fts_statp->st_mtimespec.tv_nsec);
 	if (keys & F_CKSUM && S_ISREG(p->fts_statp->st_mode)) {
Index: spec.c
===================================================================
--- spec.c	(revision 187910)
+++ spec.c	(working copy)
@@ -172,6 +172,7 @@
 	mode_t *m;
 	int value;
 	char *ep;
+	int i;
 
 	for (; (kw = strtok(t, "= \t\n")); t = NULL) {
 		ip->flags |= type = parsekey(kw, &value);
@@ -258,6 +259,8 @@
 				val = ep + 1;
 				ip->st_mtimespec.tv_nsec
 				    = strtoul(val, &ep, 10);
+				for (i = ep - val; i < 9; ++i)
+					ip->st_mtimespec.tv_nsec *= 10;
 			} else
 				ip->st_mtimespec.tv_nsec = 0;
 			if (*ep)

--------------040708020804040103060208--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?49829D49.10306>