qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH for-2.7] wxx: Truncate files used for character


From: Paolo Bonzini
Subject: Re: [Qemu-devel] [PATCH for-2.7] wxx: Truncate files used for character devices
Date: Mon, 1 Aug 2016 10:31:14 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1


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.
> 
> Reported-by: Benjamin David Lunt <address@hidden>
> Signed-off-by: Stefan Weil <address@hidden>
> ---
>  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,

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 == INVALID_HANDLE_VALUE) {
>          error_setg(errp, "open %s failed", file->out);
>          return NULL;
> 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]