* [Qemu-devel] [PATCH v2 for-2.7] wxx: Fix handling of files used for character devices
@ 2016-08-02 5:14 Stefan Weil
2016-08-02 6:47 ` Paolo Bonzini
0 siblings, 1 reply; 3+ messages in thread
From: Stefan Weil @ 2016-08-02 5:14 UTC (permalink / raw)
To: QEMU Developer
Cc: Peter Maydell, Paolo Bonzini, Benjamin David Lunt, Stefan Weil
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 <fys@fysnet.net>
Signed-off-by: Stefan Weil <sw@weilnetz.de>
---
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;
--
2.1.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH v2 for-2.7] wxx: Fix handling of files used for character devices
2016-08-02 5:14 [Qemu-devel] [PATCH v2 for-2.7] wxx: Fix handling of files used for character devices Stefan Weil
@ 2016-08-02 6:47 ` Paolo Bonzini
2016-08-05 14:12 ` Peter Maydell
0 siblings, 1 reply; 3+ messages in thread
From: Paolo Bonzini @ 2016-08-02 6:47 UTC (permalink / raw)
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 <fys@fysnet.net>
> Signed-off-by: Stefan Weil <sw@weilnetz.de>
> ---
>
> 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 <pbonzini@redhat.com>
Thanks!
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH v2 for-2.7] wxx: Fix handling of files used for character devices
2016-08-02 6:47 ` Paolo Bonzini
@ 2016-08-05 14:12 ` Peter Maydell
0 siblings, 0 replies; 3+ messages in thread
From: Peter Maydell @ 2016-08-05 14:12 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: Stefan Weil, QEMU Developer, Benjamin David Lunt
On 2 August 2016 at 07:47, Paolo Bonzini <pbonzini@redhat.com> wrote:
>
>
> 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 <fys@fysnet.net>
>> Signed-off-by: Stefan Weil <sw@weilnetz.de>
>> ---
>>
>> 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 <pbonzini@redhat.com>
Applied to master, thanks.
-- PMM
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-08-05 14:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-02 5:14 [Qemu-devel] [PATCH v2 for-2.7] wxx: Fix handling of files used for character devices Stefan Weil
2016-08-02 6:47 ` Paolo Bonzini
2016-08-05 14:12 ` Peter Maydell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).