Revision 3ab651fc
b/hmp.c | ||
---|---|---|
677 | 677 |
{ |
678 | 678 |
uint32_t size = qdict_get_int(qdict, "size"); |
679 | 679 |
const char *chardev = qdict_get_str(qdict, "device"); |
680 |
MemCharRead *meminfo;
|
|
680 |
char *data;
|
|
681 | 681 |
Error *errp = NULL; |
682 | 682 |
|
683 |
meminfo = qmp_memchar_read(chardev, size, false, 0, &errp);
|
|
683 |
data = qmp_memchar_read(chardev, size, false, 0, &errp);
|
|
684 | 684 |
if (errp) { |
685 | 685 |
monitor_printf(mon, "%s\n", error_get_pretty(errp)); |
686 | 686 |
error_free(errp); |
687 | 687 |
return; |
688 | 688 |
} |
689 | 689 |
|
690 |
if (meminfo->count > 0) { |
|
691 |
monitor_printf(mon, "%s\n", meminfo->data); |
|
692 |
} |
|
693 |
|
|
694 |
qapi_free_MemCharRead(meminfo); |
|
690 |
monitor_printf(mon, "%s\n", data); |
|
691 |
g_free(data); |
|
695 | 692 |
} |
696 | 693 |
|
697 | 694 |
static void hmp_cont_cb(void *opaque, int err) |
b/qapi-schema.json | ||
---|---|---|
361 | 361 |
'*format': 'DataFormat'} } |
362 | 362 |
|
363 | 363 |
## |
364 |
# @MemCharRead |
|
365 |
# |
|
366 |
# Result of QMP command memchar-read. |
|
367 |
# |
|
368 |
# @data: The data read from memchar as string. |
|
369 |
# |
|
370 |
# @count: The numbers of bytes read from. |
|
371 |
# |
|
372 |
# Since: 1.4 |
|
373 |
## |
|
374 |
{ 'type': 'MemCharRead', |
|
375 |
'data': { 'data': 'str', 'count': 'int' } } |
|
376 |
|
|
377 |
## |
|
378 | 364 |
# @memchar-read: |
379 | 365 |
# |
380 | 366 |
# Provide read interface for memchardev. Read from the char |
... | ... | |
387 | 373 |
# @format: #optional the format of the data want to read from |
388 | 374 |
# memchardev, by default is 'utf8'. |
389 | 375 |
# |
390 |
# Returns: @MemCharRead
|
|
376 |
# Returns: data read from the device
|
|
391 | 377 |
# If @device is not a valid memchr device, DeviceNotFound |
392 | 378 |
# |
393 | 379 |
# Since: 1.4 |
394 | 380 |
## |
395 | 381 |
{ 'command': 'memchar-read', |
396 | 382 |
'data': {'device': 'str', 'size': 'int', '*format': 'DataFormat'}, |
397 |
'returns': 'MemCharRead' }
|
|
383 |
'returns': 'str' }
|
|
398 | 384 |
|
399 | 385 |
## |
400 | 386 |
# @CommandInfo: |
b/qemu-char.c | ||
---|---|---|
2788 | 2788 |
} |
2789 | 2789 |
} |
2790 | 2790 |
|
2791 |
MemCharRead *qmp_memchar_read(const char *device, int64_t size,
|
|
2792 |
bool has_format, enum DataFormat format,
|
|
2793 |
Error **errp)
|
|
2791 |
char *qmp_memchar_read(const char *device, int64_t size,
|
|
2792 |
bool has_format, enum DataFormat format, |
|
2793 |
Error **errp) |
|
2794 | 2794 |
{ |
2795 | 2795 |
CharDriverState *chr; |
2796 | 2796 |
guchar *read_data; |
2797 |
MemCharRead *meminfo; |
|
2798 | 2797 |
size_t count; |
2798 |
char *data; |
|
2799 | 2799 |
|
2800 | 2800 |
chr = qemu_chr_find(device); |
2801 | 2801 |
if (!chr) { |
... | ... | |
2813 | 2813 |
return NULL; |
2814 | 2814 |
} |
2815 | 2815 |
|
2816 |
meminfo = g_malloc0(sizeof(MemCharRead)); |
|
2817 |
|
|
2818 | 2816 |
count = qemu_chr_cirmem_count(chr); |
2819 | 2817 |
if (count == 0) { |
2820 |
meminfo->data = g_strdup(""); |
|
2821 |
return meminfo; |
|
2818 |
return g_strdup(""); |
|
2822 | 2819 |
} |
2823 | 2820 |
|
2824 | 2821 |
size = size > count ? count : size; |
2825 | 2822 |
read_data = g_malloc0(size + 1); |
2826 | 2823 |
|
2827 |
meminfo->count = cirmem_chr_read(chr, read_data, size);
|
|
2824 |
cirmem_chr_read(chr, read_data, size); |
|
2828 | 2825 |
|
2829 | 2826 |
if (has_format && (format == DATA_FORMAT_BASE64)) { |
2830 |
meminfo->data = g_base64_encode(read_data, (size_t)meminfo->count);
|
|
2827 |
data = g_base64_encode(read_data, size);
|
|
2831 | 2828 |
} else { |
2832 |
meminfo->data = (char *)read_data;
|
|
2829 |
data = (char *)read_data; |
|
2833 | 2830 |
} |
2834 | 2831 |
|
2835 |
return meminfo;
|
|
2832 |
return data;
|
|
2836 | 2833 |
} |
2837 | 2834 |
|
2838 | 2835 |
QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename) |
b/qmp-commands.hx | ||
---|---|---|
525 | 525 |
"arguments": { "device": foo, |
526 | 526 |
"size": 1000, |
527 | 527 |
"format": "utf8" } } |
528 |
<- { "return": { "data": "data string...", "count": 1000 } }
|
|
528 |
<- {"return": "abcdefgh"}
|
|
529 | 529 |
|
530 | 530 |
EQMP |
531 | 531 |
|
Also available in: Unified diff