Received: from eggs.gnu.org ([2001:4830:134:3::10]:43331) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bUTUl-0003AC-LZ for qemu-devel@nongnu.org; Tue, 02 Aug 2016 02:48:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bUTUg-0001jJ-Ah for qemu-devel@nongnu.org; Tue, 02 Aug 2016 02:48:07 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:36830) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bUTUg-0001iy-3R for qemu-devel@nongnu.org; Tue, 02 Aug 2016 02:48:02 -0400 Received: by mail-wm0-x243.google.com with SMTP id x83so29120340wma.3 for ; Mon, 01 Aug 2016 23:48:01 -0700 (PDT) Sender: Paolo Bonzini References: <1470114877-1466-1-git-send-email-sw@weilnetz.de> From: Paolo Bonzini Message-ID: <212c9f2c-9f83-b30a-ef2e-1148aad7dd6b@redhat.com> Date: Tue, 2 Aug 2016 08:47:58 +0200 MIME-Version: 1.0 In-Reply-To: <1470114877-1466-1-git-send-email-sw@weilnetz.de> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2 for-2.7] wxx: Fix handling of files used for character devices List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Weil , QEMU Developer Cc: Peter Maydell , Benjamin David Lunt On 02/08/2016 07:14, Stefan Weil wrote: > On Windows, such files were not truncated like on all other hosts. > Now we also test whether truncation is needed when running on Windows. > > The append case was also incorrect because it needs a different value > for the desired access mode. > > Reported-by: Benjamin David Lunt > Signed-off-by: Stefan Weil > --- > > This patch supersedes my previous patch for qemu-char which only > fixed the truncate case. Paolo gave the hint to the wrong access mode > (see also commit 52074d0f662fc51293d4cde8077631f754784405). > > Regards > Stefan > > qemu-char.c | 16 ++++++++++++++-- > 1 file changed, 14 insertions(+), 2 deletions(-) > > diff --git a/qemu-char.c b/qemu-char.c > index e4b8448..e7d3399 100644 > --- a/qemu-char.c > +++ b/qemu-char.c > @@ -4197,14 +4197,26 @@ static CharDriverState *qmp_chardev_open_file(const char *id, > ChardevFile *file = backend->u.file.data; > ChardevCommon *common = qapi_ChardevFile_base(file); > HANDLE out; > + DWORD accessmode; > + DWORD flags; > > if (file->has_in) { > error_setg(errp, "input file not supported"); > return NULL; > } > > - out = CreateFile(file->out, GENERIC_WRITE, FILE_SHARE_READ, NULL, > - OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); > + if (file->has_append && file->append) { > + /* Append to file if it already exists. */ > + accessmode = FILE_GENERIC_WRITE & ~FILE_WRITE_DATA; > + flags = OPEN_ALWAYS; > + } else { > + /* Truncate file if it already exists. */ > + accessmode = GENERIC_WRITE; > + flags = CREATE_ALWAYS; > + } > + > + out = CreateFile(file->out, accessmode, FILE_SHARE_READ, NULL, flags, > + FILE_ATTRIBUTE_NORMAL, NULL); > if (out == INVALID_HANDLE_VALUE) { > error_setg(errp, "open %s failed", file->out); > return NULL; > Matches the access mode and flags for qemu-ga. Reviewed-by: Paolo Bonzini Thanks!