From patchwork Fri Mar 15 09:29:04 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lei Li X-Patchwork-Id: 227908 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 0144A2C00DA for ; Fri, 15 Mar 2013 20:29:55 +1100 (EST) Received: from localhost ([::1]:45189 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UGQxV-0003dE-UW for incoming@patchwork.ozlabs.org; Fri, 15 Mar 2013 05:29:53 -0400 Received: from eggs.gnu.org ([208.118.235.92]:39426) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UGQxA-0003d2-Kv for qemu-devel@nongnu.org; Fri, 15 Mar 2013 05:29:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UGQx9-0008Hb-Fe for qemu-devel@nongnu.org; Fri, 15 Mar 2013 05:29:32 -0400 Received: from e23smtp08.au.ibm.com ([202.81.31.141]:53165) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UGQx8-0008H7-RY for qemu-devel@nongnu.org; Fri, 15 Mar 2013 05:29:31 -0400 Received: from /spool/local by e23smtp08.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 15 Mar 2013 19:27:30 +1000 Received: from d23dlp02.au.ibm.com (202.81.31.213) by e23smtp08.au.ibm.com (202.81.31.205) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 15 Mar 2013 19:27:27 +1000 Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [9.190.235.152]) by d23dlp02.au.ibm.com (Postfix) with ESMTP id D9A052BB0050 for ; Fri, 15 Mar 2013 20:29:23 +1100 (EST) Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay05.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r2F9GR8h3473754 for ; Fri, 15 Mar 2013 20:16:27 +1100 Received: from d23av01.au.ibm.com (loopback [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r2F9TMVt011249 for ; Fri, 15 Mar 2013 20:29:23 +1100 Received: from localhost.cn.ibm.com ([9.115.122.48]) by d23av01.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r2F9TIoo011101; Fri, 15 Mar 2013 20:29:21 +1100 From: Lei Li To: qemu-devel@nongnu.org Date: Fri, 15 Mar 2013 17:29:04 +0800 Message-Id: <1363339745-15639-2-git-send-email-lilei@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1363339745-15639-1-git-send-email-lilei@linux.vnet.ibm.com> References: <1363339745-15639-1-git-send-email-lilei@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13031509-5140-0000-0000-000002E58F00 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 202.81.31.141 Cc: aliguori@us.ibm.com, mdroth@linux.vnet.ibm.com, Lei Li Subject: [Qemu-devel] [PATCH 1/2] qga: add windows implementation for guest-get-time X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Lei Li --- qga/commands-win32.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index b19be9d..d98e3ee 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)