diff options
author | Stefan Weil <sw@weilnetz.de> | 2016-08-02 07:14:37 +0200 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2016-08-05 14:15:14 +0100 |
commit | c025f689a13d1301b277ee4a0914e90810982d24 (patch) | |
tree | 1db270701b657b0e20022adc963db1af394ed65a | |
parent | bd8eda537fbe6f28a94db30e8facab2bf528b204 (diff) |
wxx: Fix handling of files used for character devices
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>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-id: 1470114877-1466-1-git-send-email-sw@weilnetz.de
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
-rw-r--r-- | qemu-char.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/qemu-char.c b/qemu-char.c index a50b8fb3a3..27f2dbbbb5 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -4234,14 +4234,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; |