Skip to contentSkip to conversation

wxx: Truncate files used for character devices

PATCH Superseded Stefan Weil 2 participants 3 messages Jul 26, 2016 – Aug 2, 2016

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 wxx: Truncate 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.

---
 qemu-char.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
qemu-char.c +10 -1
index e4b8448..7de63c8 100644
@@ -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,
-                     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;
Signature · 1 line
2.1.4
#1 lore raw
Quoted 23 lines · 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.

---
 qemu-char.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
qemu-char.c +1 -0
index e4b8448..7de63c8 100644
@@ -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;
     }

qemu-char.c static CharDriverState *qmp_chardev_open_file(const char *id, · line 4215

Quoted 10 lines
qemu-char.c +8 -0
 
+    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

Quoted 6 lines
qemu-char.c +1 -1
-                     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;
#2 lore raw

Am 01.08.2016 um 10:31 schrieb Paolo Bonzini:

Quoted 40 lines · Stefan Weil
Quoted 23 lines

On Windows, such files were not truncated like on all other hosts. Now we also test whether truncation is needed when running on Windows.

---
 qemu-char.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
qemu-char.c +1 -0
index e4b8448..7de63c8 100644
@@ -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;
     }

qemu-char.c static CharDriverState *qmp_chardev_open_file(const char *id, · line 4215

Quoted 10 lines
qemu-char.c +8 -0
 
+    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.

Quoted 3 lines

Thanks,

Paolo

Thanks for the hint.

That's a second problem of the old code. I'll send a new patch which addresses both problems.

Stefan