From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:34226) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UG2Gx-0003QO-9h for qemu-devel@nongnu.org; Thu, 14 Mar 2013 03:08:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UG2Gw-0005dD-1F for qemu-devel@nongnu.org; Thu, 14 Mar 2013 03:08:19 -0400 Received: from e28smtp01.in.ibm.com ([122.248.162.1]:51670) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UG2Gv-0005cj-EP for qemu-devel@nongnu.org; Thu, 14 Mar 2013 03:08:17 -0400 Received: from /spool/local by e28smtp01.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 14 Mar 2013 12:34:43 +0530 Received: from d28relay02.in.ibm.com (d28relay02.in.ibm.com [9.184.220.59]) by d28dlp02.in.ibm.com (Postfix) with ESMTP id 69E12394004F for ; Thu, 14 Mar 2013 12:38:11 +0530 (IST) Received: from d28av03.in.ibm.com (d28av03.in.ibm.com [9.184.220.65]) by d28relay02.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r2E7883921692434 for ; Thu, 14 Mar 2013 12:38:08 +0530 Received: from d28av03.in.ibm.com (loopback [127.0.0.1]) by d28av03.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r2E78A2U029254 for ; Thu, 14 Mar 2013 18:08:10 +1100 From: Lei Li Date: Thu, 14 Mar 2013 15:07:51 +0800 Message-Id: <1363244871-11973-3-git-send-email-lilei@linux.vnet.ibm.com> In-Reply-To: <1363244871-11973-1-git-send-email-lilei@linux.vnet.ibm.com> References: <1363244871-11973-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 | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index e24fb4a..8064c3a 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -141,6 +141,39 @@ out: return -1; } +void qmp_guest_set_time(int64_t time_ns, Error **errp) +{ + SYSTEMTIME ts; + FILETIME tf; + LONGLONG time; + + 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; + } + + acquire_privilege(SE_SYSTEMTIME_NAME, errp); + if (error_is_set(errp)) { + error_setg(errp, "Failed to acquire privilege"); + return; + } + + if (!SetSystemTime(&ts)) { + error_setg(errp, "Failed to set time to guest: %d", (int)GetLastError()); + 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