]>
Commit | Line | Data |
---|---|---|
7282a033 GH |
1 | #include "qemu-common.h" |
2 | #include "qemu-option.h" | |
3 | #include "qemu-config.h" | |
4 | ||
5 | QemuOptsList qemu_drive_opts = { | |
6 | .name = "drive", | |
7 | .head = TAILQ_HEAD_INITIALIZER(qemu_drive_opts.head), | |
8 | .desc = { | |
9 | { | |
10 | .name = "bus", | |
11 | .type = QEMU_OPT_NUMBER, | |
12 | .help = "bus number", | |
13 | },{ | |
14 | .name = "unit", | |
15 | .type = QEMU_OPT_NUMBER, | |
16 | .help = "unit number (i.e. lun for scsi)", | |
17 | },{ | |
18 | .name = "if", | |
19 | .type = QEMU_OPT_STRING, | |
20 | .help = "interface (ide, scsi, sd, mtd, floppy, pflash, virtio)", | |
21 | },{ | |
22 | .name = "index", | |
23 | .type = QEMU_OPT_NUMBER, | |
24 | },{ | |
25 | .name = "cyls", | |
26 | .type = QEMU_OPT_NUMBER, | |
27 | .help = "number of cylinders (ide disk geometry)", | |
28 | },{ | |
29 | .name = "heads", | |
30 | .type = QEMU_OPT_NUMBER, | |
31 | .help = "number of heads (ide disk geometry)", | |
32 | },{ | |
33 | .name = "secs", | |
34 | .type = QEMU_OPT_NUMBER, | |
35 | .help = "number of sectors (ide disk geometry)", | |
36 | },{ | |
37 | .name = "trans", | |
38 | .type = QEMU_OPT_STRING, | |
39 | .help = "chs translation (auto, lba. none)", | |
40 | },{ | |
41 | .name = "media", | |
42 | .type = QEMU_OPT_STRING, | |
43 | .help = "media type (disk, cdrom)", | |
44 | },{ | |
45 | .name = "snapshot", | |
46 | .type = QEMU_OPT_BOOL, | |
47 | },{ | |
48 | .name = "file", | |
49 | .type = QEMU_OPT_STRING, | |
50 | .help = "disk image", | |
51 | },{ | |
52 | .name = "cache", | |
53 | .type = QEMU_OPT_STRING, | |
54 | .help = "host cache usage (none, writeback, writethrough)", | |
55 | },{ | |
56 | .name = "format", | |
57 | .type = QEMU_OPT_STRING, | |
58 | .help = "disk format (raw, qcow2, ...)", | |
59 | },{ | |
60 | .name = "serial", | |
61 | .type = QEMU_OPT_STRING, | |
62 | },{ | |
63 | .name = "werror", | |
64 | .type = QEMU_OPT_STRING, | |
65 | },{ | |
66 | .name = "addr", | |
67 | .type = QEMU_OPT_STRING, | |
68 | .help = "pci address (virtio only)", | |
69 | }, | |
70 | { /* end if list */ } | |
71 | }, | |
72 | }; | |
73 | ||
f31d07d1 GH |
74 | QemuOptsList qemu_device_opts = { |
75 | .name = "device", | |
76 | .head = TAILQ_HEAD_INITIALIZER(qemu_device_opts.head), | |
77 | .desc = { | |
78 | /* | |
79 | * no elements => accept any | |
80 | * sanity checking will happen later | |
81 | * when setting device properties | |
82 | */ | |
83 | { /* end if list */ } | |
84 | }, | |
85 | }; | |
86 | ||
d058fe03 GH |
87 | static QemuOptsList *lists[] = { |
88 | &qemu_drive_opts, | |
f31d07d1 | 89 | &qemu_device_opts, |
d058fe03 GH |
90 | NULL, |
91 | }; | |
92 | ||
93 | int qemu_set_option(const char *str) | |
94 | { | |
95 | char group[64], id[64], arg[64]; | |
96 | QemuOpts *opts; | |
97 | int i, rc, offset; | |
98 | ||
99 | rc = sscanf(str, "%63[^.].%63[^.].%63[^=]%n", group, id, arg, &offset); | |
100 | if (rc < 3 || str[offset] != '=') { | |
101 | fprintf(stderr, "can't parse: \"%s\"\n", str); | |
102 | return -1; | |
103 | } | |
104 | ||
105 | for (i = 0; lists[i] != NULL; i++) { | |
106 | if (strcmp(lists[i]->name, group) == 0) | |
107 | break; | |
108 | } | |
109 | if (lists[i] == NULL) { | |
110 | fprintf(stderr, "there is no option group \"%s\"\n", group); | |
111 | return -1; | |
112 | } | |
113 | ||
114 | opts = qemu_opts_find(lists[i], id); | |
115 | if (!opts) { | |
116 | fprintf(stderr, "there is no %s \"%s\" defined\n", | |
117 | lists[i]->name, id); | |
118 | return -1; | |
119 | } | |
120 | ||
121 | if (-1 == qemu_opt_set(opts, arg, str+offset+1)) { | |
122 | fprintf(stderr, "failed to set \"%s\" for %s \"%s\"\n", | |
123 | arg, lists[i]->name, id); | |
124 | return -1; | |
125 | } | |
126 | return 0; | |
127 | } | |
128 |