Received: from eggs.gnu.org ([2001:4830:134:3::10]:56240) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bU8dB-00033a-8V for qemu-devel@nongnu.org; Mon, 01 Aug 2016 04:31:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bU8d6-0002jn-6A for qemu-devel@nongnu.org; Mon, 01 Aug 2016 04:31:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54070) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bU8d6-0002jR-0q for qemu-devel@nongnu.org; Mon, 01 Aug 2016 04:31:20 -0400 References: <1469553069-15350-1-git-send-email-sw@weilnetz.de> From: Paolo Bonzini Message-ID: <4da2c2a1-4124-e861-210b-2713e63e3a14@redhat.com> Date: Mon, 1 Aug 2016 10:31:14 +0200 MIME-Version: 1.0 In-Reply-To: <1469553069-15350-1-git-send-email-sw@weilnetz.de> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH for-2.7] wxx: Truncate 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 26/07/2016 19:11, 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. >=20 > Reported-by: Benjamin David Lunt > Signed-off-by: Stefan Weil > --- > qemu-char.c | 11 ++++++++++- > 1 file changed, 10 insertions(+), 1 deletion(-) >=20 > 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(c= onst char *id, > ChardevFile *file =3D backend->u.file.data; > ChardevCommon *common =3D qapi_ChardevFile_base(file); > HANDLE out; > + DWORD flags; > =20 > if (file->has_in) { > error_setg(errp, "input file not supported"); > return NULL; > } > =20 > + if (file->has_append && file->append) { > + /* Append to file if it already exists. */ > + flags =3D OPEN_ALWAYS; > + } else { > + /* Truncate file if it already exists. */ > + flags =3D CREATE_ALWAYS; > + } > + > out =3D CreateFile(file->out, GENERIC_WRITE, FILE_SHARE_READ, NULL= , GENERIC_WRITE does not include FILE_APPEND_DATA. You should also change the access rights to FILE_GENERIC_WRITE & ~FILE_WRITE_DATA in the append case; see commit 52074d0f662fc51293d4cde8077631f754784405 for a similar case in qemu-ga. Thanks, Paolo > - OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); > + flags, FILE_ATTRIBUTE_NORMAL, NULL); > if (out =3D=3D INVALID_HANDLE_VALUE) { > error_setg(errp, "open %s failed", file->out); > return NULL; >=20