From patchwork Fri Mar 8 16:56:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lei Li X-Patchwork-Id: 226165 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 E91172C0357 for ; Sat, 9 Mar 2013 03:58:47 +1100 (EST) Received: from localhost ([::1]:36544 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UE0d4-0006Ap-9P for incoming@patchwork.ozlabs.org; Fri, 08 Mar 2013 11:58:46 -0500 Received: from eggs.gnu.org ([208.118.235.92]:55419) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UE0bx-0004cl-Gs for qemu-devel@nongnu.org; Fri, 08 Mar 2013 11:57:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UE0bq-0004Oo-1l for qemu-devel@nongnu.org; Fri, 08 Mar 2013 11:57:37 -0500 Received: from e23smtp09.au.ibm.com ([202.81.31.142]:40156) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UE0bp-0004JT-Hr for qemu-devel@nongnu.org; Fri, 08 Mar 2013 11:57:30 -0500 Received: from /spool/local by e23smtp09.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sat, 9 Mar 2013 02:49:26 +1000 Received: from d23dlp01.au.ibm.com (202.81.31.203) by e23smtp09.au.ibm.com (202.81.31.206) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Sat, 9 Mar 2013 02:49:24 +1000 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [9.190.234.120]) by d23dlp01.au.ibm.com (Postfix) with ESMTP id B3DED2CE804C for ; Sat, 9 Mar 2013 03:57:05 +1100 (EST) Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r28GiOCv9109840 for ; Sat, 9 Mar 2013 03:44:26 +1100 Received: from d23av03.au.ibm.com (loopback [127.0.0.1]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r28Gv3fa002335 for ; Sat, 9 Mar 2013 03:57:03 +1100 Received: from localhost.localdomain ([9.77.181.150]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r28Guw5W002225; Sat, 9 Mar 2013 03:57:02 +1100 From: Lei Li To: qemu-devel@nongnu.org Date: Sat, 9 Mar 2013 00:56:46 +0800 Message-Id: <1362761807-32475-2-git-send-email-lilei@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1362761807-32475-1-git-send-email-lilei@linux.vnet.ibm.com> References: <1362761807-32475-1-git-send-email-lilei@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13030816-3568-0000-0000-0000034331B2 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 202.81.31.142 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 Reviewed-by: Eric Blake --- qga/commands-win32.c | 32 ++++++++++++++++++++++++++++++++ 1 files changed, 32 insertions(+), 0 deletions(-) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 7e8ecb3..0a2bb34 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; @@ -108,6 +114,32 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err) } } +int64_t qmp_guest_get_time(Error **errp) +{ + SYSTEMTIME *ts = g_malloc0(sizeof(SYSTEMTIME)); + int64_t time_ns; + union { + UINT64 ns100; + FILETIME tf; + } time; + + GetSystemTime(ts); + if (!ts) { + slog("guest-get-time failed: %d", GetLastError()); + error_setg_errno(errp, errno, "Failed to get time"); + return -1; + } + + if (!SystemTimeToFileTime(ts, &time.tf)) { + error_setg_errno(errp, errno, "Failed to convert system time"); + return -1; + } + + time_ns = (int64_t)((time.ns100 - W32_FT_OFFSET) * 100); + + return time_ns; +} + int64_t qmp_guest_file_open(const char *path, bool has_mode, const char *mode, Error **err) { error_set(err, QERR_UNSUPPORTED);