From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:43980) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UFLCa-000141-PP 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 1UFLCZ-0000R4-4k for qemu-devel@nongnu.org; Tue, 12 Mar 2013 05:08:56 -0400 Received: from e23smtp02.au.ibm.com ([202.81.31.144]:49301) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UFLCY-0000Qb-B3 for qemu-devel@nongnu.org; Tue, 12 Mar 2013 05:08:55 -0400 Received: from /spool/local by e23smtp02.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 12 Mar 2013 19:02:12 +1000 Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [9.190.235.152]) by d23dlp03.au.ibm.com (Postfix) with ESMTP id 060ED3578051 for ; Tue, 12 Mar 2013 20:08:49 +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 r2C8tu1e22020120 for ; Tue, 12 Mar 2013 19:55:56 +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 r2C98mhm020929 for ; Tue, 12 Mar 2013 20:08:48 +1100 From: Lei Li Date: Tue, 12 Mar 2013 17:08:26 +0800 Message-Id: <1363079306-27589-3-git-send-email-lilei@linux.vnet.ibm.com> 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> Subject: [Qemu-devel] [PATCH 2/2] qga: add windows implementation for guest-set-time List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aliguori@us.ibm.com, mdroth@linux.vnet.ibm.com, Lei Li Signed-off-by: Lei Li --- qga/commands-win32.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 0a2bb34..e000324 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -140,6 +140,40 @@ 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; + + acquire_privilege(SE_SYSTEMTIME_NAME, errp); + if (error_is_set(errp)) { + error_setg(errp, "Failed to acquire privilege"); + return; + } + + if (time_ns < 0 || time_ns / 100 > INT64_MAX - W32_FT_OFFSET) { + error_setg(errp, "Time %" PRId64 "is invalid", time_ns); + 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); -- 1.7.11.7