From patchwork Wed Mar 6 12:57:45 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lei Li X-Patchwork-Id: 225490 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 238442C0334 for ; Wed, 6 Mar 2013 23:59:21 +1100 (EST) Received: from localhost ([::1]:57656 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UDDwF-0005aL-F3 for incoming@patchwork.ozlabs.org; Wed, 06 Mar 2013 07:59:19 -0500 Received: from eggs.gnu.org ([208.118.235.92]:50846) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UDDvk-0005QG-4x for qemu-devel@nongnu.org; Wed, 06 Mar 2013 07:58:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UDDvi-00085f-2p for qemu-devel@nongnu.org; Wed, 06 Mar 2013 07:58:48 -0500 Received: from e23smtp07.au.ibm.com ([202.81.31.140]:48575) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UDDvh-00082B-Gq for qemu-devel@nongnu.org; Wed, 06 Mar 2013 07:58:46 -0500 Received: from /spool/local by e23smtp07.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 6 Mar 2013 22:50:31 +1000 Received: from d23dlp01.au.ibm.com (202.81.31.203) by e23smtp07.au.ibm.com (202.81.31.204) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 6 Mar 2013 22:50:23 +1000 Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [9.190.235.152]) by d23dlp01.au.ibm.com (Postfix) with ESMTP id 190AB2CE804C for ; Wed, 6 Mar 2013 23:58:11 +1100 (EST) Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay05.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r26CjPmK10289652 for ; Wed, 6 Mar 2013 23:45:25 +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 r26CwA7G032393 for ; Wed, 6 Mar 2013 23:58:10 +1100 Received: from localhost.localdomain ([9.77.180.221]) by d23av04.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r26Cw2El032309; Wed, 6 Mar 2013 23:58:08 +1100 From: Lei Li To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2013 20:57:45 +0800 Message-Id: <1362574665-4709-3-git-send-email-lilei@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1362574665-4709-1-git-send-email-lilei@linux.vnet.ibm.com> References: <1362574665-4709-1-git-send-email-lilei@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13030612-0260-0000-0000-000002A12378 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 202.81.31.140 Cc: aliguori@us.ibm.com, mdroth@linux.vnet.ibm.com, Lei Li Subject: [Qemu-devel] [PATCH 4/4] qga: add windows implementation for guest-set-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 | 35 +++++++++++++++++++++++++++++++++++ 1 files changed, 35 insertions(+), 0 deletions(-) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 4febec7..1a90aa7 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -136,6 +136,41 @@ int64_t qmp_guest_get_time(Error **errp) return time_ns; } +void qmp_guest_set_time(int64_t time_ns, Error **errp) +{ + SYSTEMTIME ts; + FILETIME tf; + LONGLONG time; + + /* year-2038 will overflow in case time_t is 32bit */ + if (time_ns / 1000000000 != (time_t)(time_ns / 1000000000)) { + error_setg(errp, "Time %" PRId64 " is too large", time_ns); + return; + } + + acquire_privilege(SE_SYSTEMTIME_NAME, errp); + if (error_is_set(errp)) { + error_setg(errp, "Failed to acquire privilege"); + return; + } + + time = time_ns / 100 + _W32_FT_OFFSET; + + tf.dwLowDateTime = (DWORD) time; + tf.dwHighDateTime = (DWORD) (time >> 32); + + if (!FileTimeToSystemTime(&tf, &ts)) { + error_setg(errp, "Failed to convert system time"); + return; + } + + if (!SetSystemTime(&ts)) { + slog("guest-set-time failed: %d", GetLastError()); + error_setg_errno(errp, errno, "Failed to set time to guest"); + return; + } +} + int64_t qmp_guest_file_open(const char *path, bool has_mode, const char *mode, Error **err) { error_set(err, QERR_UNSUPPORTED);