From patchwork Tue Jul 26 17:11:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Weil X-Patchwork-Id: 652848 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rzPmx1lyFz9sdn for ; Wed, 27 Jul 2016 03:12:01 +1000 (AEST) Received: from localhost ([::1]:41338 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bS5tf-0006GT-7M for incoming@patchwork.ozlabs.org; Tue, 26 Jul 2016 13:11:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51428) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bS5t3-0005zO-N3 for qemu-devel@nongnu.org; Tue, 26 Jul 2016 13:11:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bS5sw-0005g9-Hf for qemu-devel@nongnu.org; Tue, 26 Jul 2016 13:11:20 -0400 Received: from qemu.weilnetz.de ([2a03:4000:2:362::1]:54055) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bS5sw-0005f3-B7 for qemu-devel@nongnu.org; Tue, 26 Jul 2016 13:11:14 -0400 Received: by qemu.weilnetz.de (Postfix, from userid 1000) id 3653C17F705; Tue, 26 Jul 2016 19:11:10 +0200 (CEST) From: Stefan Weil To: QEMU Developer Date: Tue, 26 Jul 2016 19:11:09 +0200 Message-Id: <1469553069-15350-1-git-send-email-sw@weilnetz.de> X-Mailer: git-send-email 2.1.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a03:4000:2:362::1 Subject: [Qemu-devel] [PATCH for-2.7] wxx: Truncate files used for character devices X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Stefan Weil , Benjamin David Lunt , Paolo Bonzini Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" On Windows, such files were not truncated like on all other hosts. Now we also test whether truncation is needed when running on Windows. Reported-by: Benjamin David Lunt Signed-off-by: Stefan Weil --- qemu-char.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/qemu-char.c b/qemu-char.c index e4b8448..7de63c8 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -4197,14 +4197,23 @@ static CharDriverState *qmp_chardev_open_file(const char *id, ChardevFile *file = backend->u.file.data; ChardevCommon *common = qapi_ChardevFile_base(file); HANDLE out; + DWORD flags; if (file->has_in) { error_setg(errp, "input file not supported"); return NULL; } + if (file->has_append && file->append) { + /* Append to file if it already exists. */ + flags = OPEN_ALWAYS; + } else { + /* Truncate file if it already exists. */ + flags = CREATE_ALWAYS; + } + out = CreateFile(file->out, GENERIC_WRITE, FILE_SHARE_READ, NULL, - OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + flags, FILE_ATTRIBUTE_NORMAL, NULL); if (out == INVALID_HANDLE_VALUE) { error_setg(errp, "open %s failed", file->out); return NULL;