aboutsummaryrefslogtreecommitdiff
path: root/qga
diff options
context:
space:
mode:
authorLei Li <lilei@linux.vnet.ibm.com>2013-03-15 17:29:04 +0800
committerMichael Roth <mdroth@linux.vnet.ibm.com>2013-04-02 09:06:11 -0500
commit3f2a6087de291dc96a2c4975139da27649cf32ff (patch)
tree59b87baddf7cb212bc15f1bb0b0b2ebf25bc327b /qga
parent5d45de9796539f95eb6b1201588362981f8cb2d4 (diff)
qga: add windows implementation for guest-get-time
Signed-off-by: Lei Li <lilei@linux.vnet.ibm.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com> Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Diffstat (limited to 'qga')
-rw-r--r--qga/commands-win32.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index b19be9db48..d98e3eeff0 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -22,6 +22,12 @@
#define SHTDN_REASON_FLAG_PLANNED 0x80000000
#endif
+/* multiple of 100 nanoseconds elapsed between windows baseline
+ * (1/1/1601) and Unix Epoch (1/1/1970), accounting for leap years */
+#define W32_FT_OFFSET (10000000ULL * 60 * 60 * 24 * \
+ (365 * (1970 - 1601) + \
+ (1970 - 1601) / 4 - 3))
+
static void acquire_privilege(const char *name, Error **err)
{
HANDLE token;
@@ -280,8 +286,25 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **err)
int64_t qmp_guest_get_time(Error **errp)
{
- error_set(errp, QERR_UNSUPPORTED);
- return -1;
+ SYSTEMTIME ts = {0};
+ int64_t time_ns;
+ FILETIME tf;
+
+ GetSystemTime(&ts);
+ if (ts.wYear < 1601 || ts.wYear > 30827) {
+ error_setg(errp, "Failed to get time");
+ return -1;
+ }
+
+ if (!SystemTimeToFileTime(&ts, &tf)) {
+ error_setg(errp, "Failed to convert system time: %d", (int)GetLastError());
+ return -1;
+ }
+
+ time_ns = ((((int64_t)tf.dwHighDateTime << 32) | tf.dwLowDateTime)
+ - W32_FT_OFFSET) * 100;
+
+ return time_ns;
}
void qmp_guest_set_time(int64_t time_ns, Error **errp)