Skip to content

Commit

Permalink
qga: fix append file open modes for win32
Browse files Browse the repository at this point in the history
For append file open modes, use FILE_APPEND_DATA for the desired access
for writing at the end of the file.

Version 2:
For "a+", "ab+", and "a+b" modes use FILE_APPEND_DATA|GENERIC_READ.
ORing in GENERIC_READ starts a read at the begining of the file.  All
writes will append to the end fo the file.

Added white space to maintain the alignment of the guest_file_open_modes[].

Signed-off-by: Kirk Allan <kallan@suse.com>
Cc: qemu-stable@nongnu.org
* use FILE_GENERIC_APPEND macro, which provides same semantics as
  FILE_APPEND_DATA, but retains other flags from GENERIC_WRITE
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
  • Loading branch information
kirkallan authored and mdroth committed Nov 11, 2015
1 parent 3c07587 commit 52074d0
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions qga/commands-win32.c
Expand Up @@ -59,27 +59,28 @@ static struct {
.filehandles = QTAILQ_HEAD_INITIALIZER(guest_file_state.filehandles),
};

#define FILE_GENERIC_APPEND (FILE_GENERIC_WRITE & ~FILE_WRITE_DATA)

typedef struct OpenFlags {
const char *forms;
DWORD desired_access;
DWORD creation_disposition;
} OpenFlags;
static OpenFlags guest_file_open_modes[] = {
{"r", GENERIC_READ, OPEN_EXISTING},
{"rb", GENERIC_READ, OPEN_EXISTING},
{"w", GENERIC_WRITE, CREATE_ALWAYS},
{"wb", GENERIC_WRITE, CREATE_ALWAYS},
{"a", GENERIC_WRITE, OPEN_ALWAYS },
{"r+", GENERIC_WRITE|GENERIC_READ, OPEN_EXISTING},
{"rb+", GENERIC_WRITE|GENERIC_READ, OPEN_EXISTING},
{"r+b", GENERIC_WRITE|GENERIC_READ, OPEN_EXISTING},
{"w+", GENERIC_WRITE|GENERIC_READ, CREATE_ALWAYS},
{"wb+", GENERIC_WRITE|GENERIC_READ, CREATE_ALWAYS},
{"w+b", GENERIC_WRITE|GENERIC_READ, CREATE_ALWAYS},
{"a+", GENERIC_WRITE|GENERIC_READ, OPEN_ALWAYS },
{"ab+", GENERIC_WRITE|GENERIC_READ, OPEN_ALWAYS },
{"a+b", GENERIC_WRITE|GENERIC_READ, OPEN_ALWAYS }
{"r", GENERIC_READ, OPEN_EXISTING},
{"rb", GENERIC_READ, OPEN_EXISTING},
{"w", GENERIC_WRITE, CREATE_ALWAYS},
{"wb", GENERIC_WRITE, CREATE_ALWAYS},
{"a", FILE_GENERIC_APPEND, OPEN_ALWAYS },
{"r+", GENERIC_WRITE|GENERIC_READ, OPEN_EXISTING},
{"rb+", GENERIC_WRITE|GENERIC_READ, OPEN_EXISTING},
{"r+b", GENERIC_WRITE|GENERIC_READ, OPEN_EXISTING},
{"w+", GENERIC_WRITE|GENERIC_READ, CREATE_ALWAYS},
{"wb+", GENERIC_WRITE|GENERIC_READ, CREATE_ALWAYS},
{"w+b", GENERIC_WRITE|GENERIC_READ, CREATE_ALWAYS},
{"a+", FILE_GENERIC_APPEND|GENERIC_READ, OPEN_ALWAYS },
{"ab+", FILE_GENERIC_APPEND|GENERIC_READ, OPEN_ALWAYS },
{"a+b", FILE_GENERIC_APPEND|GENERIC_READ, OPEN_ALWAYS }
};

static OpenFlags *find_open_flag(const char *mode_str)
Expand Down

0 comments on commit 52074d0

Please sign in to comment.