mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 15:23:53 -06:00
qga: Support enum names in guest-file-seek
Magic constants are a pain to use, especially when we run the risk that our choice of '1' for QGA_SEEK_CUR might differ from the host or guest's choice of SEEK_CUR. Better is to use an enum value, via a qapi alternate type for back-compatibility. With this, {"command":"guest-file-seek", "arguments":{"handle":1, "offset":0, "whence":"cur"}} becomes a synonym for the older {"command":"guest-file-seek", "arguments":{"handle":1, "offset":0, "whence":1}} Signed-off-by: Eric Blake <eblake@redhat.com> Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com> Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
This commit is contained in:
parent
774ae4254d
commit
0b4b49387c
6 changed files with 70 additions and 40 deletions
|
@ -385,7 +385,8 @@ done:
|
|||
}
|
||||
|
||||
GuestFileSeek *qmp_guest_file_seek(int64_t handle, int64_t offset,
|
||||
int64_t whence_code, Error **errp)
|
||||
GuestFileWhence *whence_code,
|
||||
Error **errp)
|
||||
{
|
||||
GuestFileHandle *gfh;
|
||||
GuestFileSeek *seek_data;
|
||||
|
@ -394,6 +395,7 @@ GuestFileSeek *qmp_guest_file_seek(int64_t handle, int64_t offset,
|
|||
off_pos.QuadPart = offset;
|
||||
BOOL res;
|
||||
int whence;
|
||||
Error *err = NULL;
|
||||
|
||||
gfh = guest_file_handle_find(handle, errp);
|
||||
if (!gfh) {
|
||||
|
@ -401,18 +403,9 @@ GuestFileSeek *qmp_guest_file_seek(int64_t handle, int64_t offset,
|
|||
}
|
||||
|
||||
/* We stupidly exposed 'whence':'int' in our qapi */
|
||||
switch (whence_code) {
|
||||
case QGA_SEEK_SET:
|
||||
whence = SEEK_SET;
|
||||
break;
|
||||
case QGA_SEEK_CUR:
|
||||
whence = SEEK_CUR;
|
||||
break;
|
||||
case QGA_SEEK_END:
|
||||
whence = SEEK_END;
|
||||
break;
|
||||
default:
|
||||
error_setg(errp, "invalid whence code %"PRId64, whence_code);
|
||||
whence = ga_parse_whence(whence_code, &err);
|
||||
if (err) {
|
||||
error_propagate(errp, err);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue