All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wei Liu <wei.liu2@citrix.com>
To: xen-devel@lists.xen.org
Cc: Wei Liu <wei.liu2@citrix.com>,
	ian.jackson@eu.citrix.com,
	Andrei Lifchits <andrei.lifchits@citrix.com>
Subject: [PATCH] libvhd: use UTC for VHD timestamp
Date: Fri, 30 Aug 2013 14:07:20 +0100	[thread overview]
Message-ID: <1377868040-13668-1-git-send-email-wei.liu2@citrix.com> (raw)

[ported from xapi-project/blktap a79ac2c05f9 ("XOP-289: use UTC for VHD
timestamps")]

Currently, the local timezone is factored into VHD timestamps due to the
use of mktime(). This breaks "vhd-util check" for VHDs created in one
timezone and then moved westward, which results in "primary footer
invalid: creation time in future" errors.

Signed-off-by: Andrei Lifchits <andrei.lifchits@citrix.com>

---
Add SoB for Andrei Lifchits.
Remove unused variable "tm".

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
 tools/blktap2/vhd/lib/libvhd.c |   33 +++++++++------------------------
 1 file changed, 9 insertions(+), 24 deletions(-)

diff --git a/tools/blktap2/vhd/lib/libvhd.c b/tools/blktap2/vhd/lib/libvhd.c
index 3511cb4..95eb5d6 100644
--- a/tools/blktap2/vhd/lib/libvhd.c
+++ b/tools/blktap2/vhd/lib/libvhd.c
@@ -41,6 +41,10 @@
 #include "libvhd.h"
 #include "relative-path.h"
 
+/* VHD uses an epoch of 12:00AM, Jan 1, 2000. This is the Unix timestamp for
+ * the start of the VHD epoch. */
+#define VHD_EPOCH_START 946684800
+
 static int libvhd_dbg = 0;
 
 void
@@ -694,19 +698,10 @@ vhd_end_of_data(vhd_context_t *ctx, off_t *end)
 	return 0;
 }
 
-uint32_t
+uint32_t inline
 vhd_time(time_t time)
 {
-	struct tm tm;
-	time_t micro_epoch;
-
-	memset(&tm, 0, sizeof(struct tm));
-	tm.tm_year   = 100;
-	tm.tm_mon    = 0;
-	tm.tm_mday   = 1;
-	micro_epoch  = mktime(&tm);
-
-	return (uint32_t)(time - micro_epoch);
+	return (uint32_t)(time - VHD_EPOCH_START);
 }
 
 /* 
@@ -717,20 +712,10 @@ size_t
 vhd_time_to_string(uint32_t timestamp, char *target)
 {
 	char *cr;
-	struct tm tm;
-	time_t t1, t2;
-
-	memset(&tm, 0, sizeof(struct tm));
-
-	/* VHD uses an epoch of 12:00AM, Jan 1, 2000.         */
-	/* Need to adjust this to the expected epoch of 1970. */
-	tm.tm_year  = 100;
-	tm.tm_mon   = 0;
-	tm.tm_mday  = 1;
+	time_t unix_timestamp;
 
-	t1 = mktime(&tm);
-	t2 = t1 + (time_t)timestamp;
-	ctime_r(&t2, target);
+	unix_timestamp = (time_t)timestamp + VHD_EPOCH_START;
+	ctime_r(&unix_timestamp, target);
 
 	/* handle mad ctime_r newline appending. */
 	if ((cr = strchr(target, '\n')) != NULL)
-- 
1.7.10.4

             reply	other threads:[~2013-08-30 13:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-30 13:07 Wei Liu [this message]
2013-08-30 15:50 ` [PATCH] libvhd: use UTC for VHD timestamp Wei Liu
2013-08-30 15:52   ` Ian Jackson
2013-09-03 16:32     ` Ian Campbell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1377868040-13668-1-git-send-email-wei.liu2@citrix.com \
    --to=wei.liu2@citrix.com \
    --cc=andrei.lifchits@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.