|
37 | 37 | #include "qemu/queue.h"
|
38 | 38 | #include "qemu/host-utils.h"
|
39 | 39 | #include "qemu/base64.h"
|
| 40 | +#include "commands-common.h" |
40 | 41 |
|
41 | 42 | #ifndef SHTDN_REASON_FLAG_PLANNED
|
42 | 43 | #define SHTDN_REASON_FLAG_PLANNED 0x80000000
|
|
50 | 51 |
|
51 | 52 | #define INVALID_SET_FILE_POINTER ((DWORD)-1)
|
52 | 53 |
|
53 |
| -typedef struct GuestFileHandle { |
| 54 | +struct GuestFileHandle { |
54 | 55 | int64_t id;
|
55 | 56 | HANDLE fh;
|
56 | 57 | QTAILQ_ENTRY(GuestFileHandle) next;
|
57 |
| -} GuestFileHandle; |
| 58 | +}; |
58 | 59 |
|
59 | 60 | static struct {
|
60 | 61 | QTAILQ_HEAD(, GuestFileHandle) filehandles;
|
@@ -126,7 +127,7 @@ static int64_t guest_file_handle_add(HANDLE fh, Error **errp)
|
126 | 127 | return handle;
|
127 | 128 | }
|
128 | 129 |
|
129 |
| -static GuestFileHandle *guest_file_handle_find(int64_t id, Error **errp) |
| 130 | +GuestFileHandle *guest_file_handle_find(int64_t id, Error **errp) |
130 | 131 | {
|
131 | 132 | GuestFileHandle *gfh;
|
132 | 133 | QTAILQ_FOREACH(gfh, &guest_file_state.filehandles, next) {
|
@@ -321,39 +322,19 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **errp)
|
321 | 322 | }
|
322 | 323 | }
|
323 | 324 |
|
324 |
| -GuestFileRead *qmp_guest_file_read(int64_t handle, bool has_count, |
325 |
| - int64_t count, Error **errp) |
| 325 | +GuestFileRead *guest_file_read_unsafe(GuestFileHandle *gfh, |
| 326 | + int64_t count, Error **errp) |
326 | 327 | {
|
327 | 328 | GuestFileRead *read_data = NULL;
|
328 | 329 | guchar *buf;
|
329 |
| - HANDLE fh; |
| 330 | + HANDLE fh = gfh->fh; |
330 | 331 | bool is_ok;
|
331 | 332 | DWORD read_count;
|
332 |
| - GuestFileHandle *gfh = guest_file_handle_find(handle, errp); |
333 |
| - |
334 |
| - if (!gfh) { |
335 |
| - return NULL; |
336 |
| - } |
337 |
| - if (!has_count) { |
338 |
| - count = QGA_READ_COUNT_DEFAULT; |
339 |
| - } else if (count < 0 || count >= UINT32_MAX) { |
340 |
| - error_setg(errp, "value '%" PRId64 |
341 |
| - "' is invalid for argument count", count); |
342 |
| - return NULL; |
343 |
| - } |
344 | 333 |
|
345 |
| - fh = gfh->fh; |
346 |
| - buf = g_try_malloc0(count + 1); |
347 |
| - if (!buf) { |
348 |
| - error_setg(errp, |
349 |
| - "failed to allocate sufficient memory " |
350 |
| - "to complete the requested service"); |
351 |
| - return NULL; |
352 |
| - } |
| 334 | + buf = g_malloc0(count + 1); |
353 | 335 | is_ok = ReadFile(fh, buf, count, &read_count, NULL);
|
354 | 336 | if (!is_ok) {
|
355 | 337 | error_setg_win32(errp, GetLastError(), "failed to read file");
|
356 |
| - slog("guest-file-read failed, handle %" PRId64, handle); |
357 | 338 | } else {
|
358 | 339 | buf[read_count] = 0;
|
359 | 340 | read_data = g_new0(GuestFileRead, 1);
|
|
0 commit comments