MCPcopy Create free account
hub / github.com/ading2210/linuxpdf / virt_machine_parse_config

Function virt_machine_parse_config

tinyemu/machine.c:223–404  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

221}
222
223static int virt_machine_parse_config(VirtMachineParams *p,
224 char *config_file_str, int len)
225{
226 int version, val;
227 const char *tag_name, *str;
228 char buf1[256];
229 JSONValue cfg, obj, el;
230
231 cfg = json_parse_value_len(config_file_str, len);
232 if (json_is_error(cfg)) {
233 vm_error("error: %s\n", json_get_error(cfg));
234 json_free(cfg);
235 return -1;
236 }
237
238 if (vm_get_int(cfg, "version", &version) < 0)
239 goto tag_fail;
240 if (version != VM_CONFIG_VERSION) {
241 if (version > VM_CONFIG_VERSION) {
242 vm_error("The emulator is too old to run this VM: please upgrade\n");
243 return -1;
244 } else {
245 vm_error("The VM configuration file is too old for this emulator version: please upgrade the VM configuration file\n");
246 return -1;
247 }
248 }
249
250 if (vm_get_str(cfg, "machine", &str) < 0)
251 goto tag_fail;
252 p->machine_name = strdup(str);
253 p->vmc = virt_machine_find_class(p->machine_name);
254 if (!p->vmc) {
255 vm_error("Unknown machine name: %s\n", p->machine_name);
256 goto tag_fail;
257 }
258 p->vmc->virt_machine_set_defaults(p);
259
260 tag_name = "memory_size";
261 if (vm_get_int(cfg, tag_name, &val) < 0)
262 goto tag_fail;
263 p->ram_size = (uint64_t)val << 20;
264
265 tag_name = "bios";
266 if (vm_get_str_opt(cfg, tag_name, &str) < 0)
267 goto tag_fail;
268 if (str) {
269 p->files[VM_FILE_BIOS].filename = strdup(str);
270 }
271
272 tag_name = "kernel";
273 if (vm_get_str_opt(cfg, tag_name, &str) < 0)
274 goto tag_fail;
275 if (str) {
276 p->files[VM_FILE_KERNEL].filename = strdup(str);
277 }
278
279 tag_name = "initrd";
280 if (vm_get_str_opt(cfg, tag_name, &str) < 0)

Callers 1

config_file_loadedFunction · 0.85

Calls 13

json_parse_value_lenFunction · 0.85
json_is_errorFunction · 0.85
vm_errorFunction · 0.85
json_get_errorFunction · 0.85
json_freeFunction · 0.85
vm_get_intFunction · 0.85
vm_get_strFunction · 0.85
virt_machine_find_classFunction · 0.85
vm_get_str_optFunction · 0.85
cmdline_substFunction · 0.85
json_object_getFunction · 0.85
json_is_undefinedFunction · 0.85

Tested by

no test coverage detected