mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-03 07:43:54 -06:00
qga: Extract qmp_guest_file_read() to common commands.c
Extract the common code shared by both POSIX/Win32 implementations. Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
This commit is contained in:
parent
5d3586b834
commit
ead83a136d
4 changed files with 35 additions and 36 deletions
|
@ -322,33 +322,19 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **errp)
|
|||
}
|
||||
}
|
||||
|
||||
GuestFileRead *qmp_guest_file_read(int64_t handle, bool has_count,
|
||||
int64_t count, Error **errp)
|
||||
GuestFileRead *guest_file_read_unsafe(GuestFileHandle *gfh,
|
||||
int64_t count, Error **errp)
|
||||
{
|
||||
GuestFileRead *read_data = NULL;
|
||||
guchar *buf;
|
||||
HANDLE fh;
|
||||
HANDLE fh = gfh->fh;
|
||||
bool is_ok;
|
||||
DWORD read_count;
|
||||
GuestFileHandle *gfh = guest_file_handle_find(handle, errp);
|
||||
|
||||
if (!gfh) {
|
||||
return NULL;
|
||||
}
|
||||
if (!has_count) {
|
||||
count = QGA_READ_COUNT_DEFAULT;
|
||||
} else if (count < 0 || count >= UINT32_MAX) {
|
||||
error_setg(errp, "value '%" PRId64
|
||||
"' is invalid for argument count", count);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fh = gfh->fh;
|
||||
buf = g_malloc0(count + 1);
|
||||
is_ok = ReadFile(fh, buf, count, &read_count, NULL);
|
||||
if (!is_ok) {
|
||||
error_setg_win32(errp, GetLastError(), "failed to read file");
|
||||
slog("guest-file-read failed, handle %" PRId64, handle);
|
||||
} else {
|
||||
buf[read_count] = 0;
|
||||
read_data = g_new0(GuestFileRead, 1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue