From patchwork Tue Mar 12 09:08:25 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lei Li X-Patchwork-Id: 226845 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 F15072C0291 for ; Tue, 12 Mar 2013 20:09:28 +1100 (EST) Received: from localhost ([::1]:34576 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UFLD3-00017t-QZ for incoming@patchwork.ozlabs.org; Tue, 12 Mar 2013 05:09:25 -0400 Received: from eggs.gnu.org ([208.118.235.92]:43976) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UFLCa-00013N-7y for qemu-devel@nongnu.org; Tue, 12 Mar 2013 05:08:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UFLCV-0000QR-Ux for qemu-devel@nongnu.org; Tue, 12 Mar 2013 05:08:56 -0400 Received: from e23smtp08.au.ibm.com ([202.81.31.141]:36133) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UFLCU-0000Oi-Lp for qemu-devel@nongnu.org; Tue, 12 Mar 2013 05:08:51 -0400 Received: from /spool/local by e23smtp08.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 12 Mar 2013 19:06:50 +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; Tue, 12 Mar 2013 19:06:49 +1000 Received: from d23relay03.au.ibm.com (d23relay03.au.ibm.com [9.190.235.21]) by d23dlp02.au.ibm.com (Postfix) with ESMTP id 37AD62BB0023 for ; Tue, 12 Mar 2013 20:08:43 +1100 (EST) Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r2C98dr04981168 for ; Tue, 12 Mar 2013 20:08:39 +1100 Received: from d23av04.au.ibm.com (loopback [127.0.0.1]) by d23av04.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r2C98g6i020731 for ; Tue, 12 Mar 2013 20:08:43 +1100 Received: from localhost.cn.ibm.com ([9.115.122.212]) by d23av04.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r2C98c2a020621; Tue, 12 Mar 2013 20:08:41 +1100 From: Lei Li To: qemu-devel@nongnu.org Date: Tue, 12 Mar 2013 17:08:25 +0800 Message-Id: <1363079306-27589-2-git-send-email-lilei@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1363079306-27589-1-git-send-email-lilei@linux.vnet.ibm.com> References: <1363079306-27589-1-git-send-email-lilei@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13031209-5140-0000-0000-000002E14552 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 | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) 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);