]>
Commit | Line | Data |
---|---|---|
7282a033 GH |
1 | #include "qemu-common.h" |
2 | #include "qemu-option.h" | |
3 | #include "qemu-config.h" | |
a861c453 | 4 | #include "sysemu.h" |
7282a033 GH |
5 | |
6 | QemuOptsList qemu_drive_opts = { | |
7 | .name = "drive", | |
72cf2d4f | 8 | .head = QTAILQ_HEAD_INITIALIZER(qemu_drive_opts.head), |
7282a033 GH |
9 | .desc = { |
10 | { | |
11 | .name = "bus", | |
12 | .type = QEMU_OPT_NUMBER, | |
13 | .help = "bus number", | |
14 | },{ | |
15 | .name = "unit", | |
16 | .type = QEMU_OPT_NUMBER, | |
17 | .help = "unit number (i.e. lun for scsi)", | |
18 | },{ | |
19 | .name = "if", | |
20 | .type = QEMU_OPT_STRING, | |
21 | .help = "interface (ide, scsi, sd, mtd, floppy, pflash, virtio)", | |
22 | },{ | |
23 | .name = "index", | |
24 | .type = QEMU_OPT_NUMBER, | |
25 | },{ | |
26 | .name = "cyls", | |
27 | .type = QEMU_OPT_NUMBER, | |
28 | .help = "number of cylinders (ide disk geometry)", | |
29 | },{ | |
30 | .name = "heads", | |
31 | .type = QEMU_OPT_NUMBER, | |
32 | .help = "number of heads (ide disk geometry)", | |
33 | },{ | |
34 | .name = "secs", | |
35 | .type = QEMU_OPT_NUMBER, | |
36 | .help = "number of sectors (ide disk geometry)", | |
37 | },{ | |
38 | .name = "trans", | |
39 | .type = QEMU_OPT_STRING, | |
40 | .help = "chs translation (auto, lba. none)", | |
41 | },{ | |
42 | .name = "media", | |
43 | .type = QEMU_OPT_STRING, | |
44 | .help = "media type (disk, cdrom)", | |
45 | },{ | |
46 | .name = "snapshot", | |
47 | .type = QEMU_OPT_BOOL, | |
48 | },{ | |
49 | .name = "file", | |
50 | .type = QEMU_OPT_STRING, | |
51 | .help = "disk image", | |
52 | },{ | |
53 | .name = "cache", | |
54 | .type = QEMU_OPT_STRING, | |
55 | .help = "host cache usage (none, writeback, writethrough)", | |
5c6c3a6c CH |
56 | },{ |
57 | .name = "aio", | |
58 | .type = QEMU_OPT_STRING, | |
59 | .help = "host AIO implementation (threads, native)", | |
7282a033 GH |
60 | },{ |
61 | .name = "format", | |
62 | .type = QEMU_OPT_STRING, | |
63 | .help = "disk format (raw, qcow2, ...)", | |
64 | },{ | |
65 | .name = "serial", | |
66 | .type = QEMU_OPT_STRING, | |
67 | },{ | |
68 | .name = "werror", | |
69 | .type = QEMU_OPT_STRING, | |
70 | },{ | |
71 | .name = "addr", | |
72 | .type = QEMU_OPT_STRING, | |
73 | .help = "pci address (virtio only)", | |
74 | }, | |
75 | { /* end if list */ } | |
76 | }, | |
77 | }; | |
78 | ||
191bc01b GH |
79 | QemuOptsList qemu_chardev_opts = { |
80 | .name = "chardev", | |
72cf2d4f | 81 | .head = QTAILQ_HEAD_INITIALIZER(qemu_chardev_opts.head), |
191bc01b | 82 | .desc = { |
7d31544f GH |
83 | { |
84 | .name = "backend", | |
85 | .type = QEMU_OPT_STRING, | |
86 | },{ | |
87 | .name = "path", | |
88 | .type = QEMU_OPT_STRING, | |
aeb2c47a GH |
89 | },{ |
90 | .name = "host", | |
91 | .type = QEMU_OPT_STRING, | |
92 | },{ | |
93 | .name = "port", | |
94 | .type = QEMU_OPT_STRING, | |
7e1b35b4 GH |
95 | },{ |
96 | .name = "localaddr", | |
97 | .type = QEMU_OPT_STRING, | |
98 | },{ | |
99 | .name = "localport", | |
100 | .type = QEMU_OPT_STRING, | |
aeb2c47a GH |
101 | },{ |
102 | .name = "to", | |
103 | .type = QEMU_OPT_NUMBER, | |
104 | },{ | |
105 | .name = "ipv4", | |
106 | .type = QEMU_OPT_BOOL, | |
107 | },{ | |
108 | .name = "ipv6", | |
109 | .type = QEMU_OPT_BOOL, | |
110 | },{ | |
111 | .name = "wait", | |
112 | .type = QEMU_OPT_BOOL, | |
113 | },{ | |
114 | .name = "server", | |
115 | .type = QEMU_OPT_BOOL, | |
116 | },{ | |
117 | .name = "delay", | |
118 | .type = QEMU_OPT_BOOL, | |
119 | },{ | |
120 | .name = "telnet", | |
121 | .type = QEMU_OPT_BOOL, | |
6ea314d9 GH |
122 | },{ |
123 | .name = "width", | |
124 | .type = QEMU_OPT_NUMBER, | |
125 | },{ | |
126 | .name = "height", | |
127 | .type = QEMU_OPT_NUMBER, | |
128 | },{ | |
129 | .name = "cols", | |
130 | .type = QEMU_OPT_NUMBER, | |
131 | },{ | |
132 | .name = "rows", | |
133 | .type = QEMU_OPT_NUMBER, | |
c845f401 GH |
134 | },{ |
135 | .name = "mux", | |
136 | .type = QEMU_OPT_BOOL, | |
7d31544f | 137 | }, |
191bc01b GH |
138 | { /* end if list */ } |
139 | }, | |
140 | }; | |
141 | ||
f31d07d1 GH |
142 | QemuOptsList qemu_device_opts = { |
143 | .name = "device", | |
72cf2d4f | 144 | .head = QTAILQ_HEAD_INITIALIZER(qemu_device_opts.head), |
f31d07d1 GH |
145 | .desc = { |
146 | /* | |
147 | * no elements => accept any | |
148 | * sanity checking will happen later | |
149 | * when setting device properties | |
150 | */ | |
151 | { /* end if list */ } | |
152 | }, | |
153 | }; | |
154 | ||
a1ea458f MM |
155 | QemuOptsList qemu_netdev_opts = { |
156 | .name = "netdev", | |
157 | .head = QTAILQ_HEAD_INITIALIZER(qemu_netdev_opts.head), | |
158 | .desc = { | |
159 | /* | |
160 | * no elements => accept any params | |
161 | * validation will happen later | |
162 | */ | |
163 | { /* end of list */ } | |
164 | }, | |
165 | }; | |
166 | ||
8119b33d MM |
167 | QemuOptsList qemu_net_opts = { |
168 | .name = "net", | |
169 | .head = QTAILQ_HEAD_INITIALIZER(qemu_net_opts.head), | |
170 | .desc = { | |
171 | /* | |
172 | * no elements => accept any params | |
173 | * validation will happen later | |
174 | */ | |
175 | { /* end of list */ } | |
176 | }, | |
177 | }; | |
178 | ||
1ed2fc1f JK |
179 | QemuOptsList qemu_rtc_opts = { |
180 | .name = "rtc", | |
181 | .head = QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts.head), | |
182 | .desc = { | |
183 | { | |
184 | .name = "base", | |
185 | .type = QEMU_OPT_STRING, | |
6875204c JK |
186 | },{ |
187 | .name = "clock", | |
188 | .type = QEMU_OPT_STRING, | |
1ed2fc1f JK |
189 | #ifdef TARGET_I386 |
190 | },{ | |
191 | .name = "driftfix", | |
192 | .type = QEMU_OPT_STRING, | |
193 | #endif | |
194 | }, | |
195 | { /* end if list */ } | |
196 | }, | |
197 | }; | |
198 | ||
d058fe03 GH |
199 | static QemuOptsList *lists[] = { |
200 | &qemu_drive_opts, | |
191bc01b | 201 | &qemu_chardev_opts, |
f31d07d1 | 202 | &qemu_device_opts, |
a1ea458f | 203 | &qemu_netdev_opts, |
8119b33d | 204 | &qemu_net_opts, |
5fdfbf7e | 205 | &qemu_rtc_opts, |
d058fe03 GH |
206 | NULL, |
207 | }; | |
208 | ||
209 | int qemu_set_option(const char *str) | |
210 | { | |
211 | char group[64], id[64], arg[64]; | |
212 | QemuOpts *opts; | |
213 | int i, rc, offset; | |
214 | ||
215 | rc = sscanf(str, "%63[^.].%63[^.].%63[^=]%n", group, id, arg, &offset); | |
216 | if (rc < 3 || str[offset] != '=') { | |
a861c453 | 217 | qemu_error("can't parse: \"%s\"\n", str); |
d058fe03 GH |
218 | return -1; |
219 | } | |
220 | ||
221 | for (i = 0; lists[i] != NULL; i++) { | |
222 | if (strcmp(lists[i]->name, group) == 0) | |
223 | break; | |
224 | } | |
225 | if (lists[i] == NULL) { | |
a861c453 | 226 | qemu_error("there is no option group \"%s\"\n", group); |
d058fe03 GH |
227 | return -1; |
228 | } | |
229 | ||
230 | opts = qemu_opts_find(lists[i], id); | |
231 | if (!opts) { | |
a861c453 | 232 | qemu_error("there is no %s \"%s\" defined\n", |
d058fe03 GH |
233 | lists[i]->name, id); |
234 | return -1; | |
235 | } | |
236 | ||
3df04ac3 | 237 | if (qemu_opt_set(opts, arg, str+offset+1) == -1) { |
d058fe03 GH |
238 | return -1; |
239 | } | |
240 | return 0; | |
241 | } | |
242 |