]> git.proxmox.com Git - mirror_qemu.git/commitdiff
vl: extract softmmu/datadir.c
authorPaolo Bonzini <pbonzini@redhat.com>
Wed, 28 Oct 2020 11:36:57 +0000 (07:36 -0400)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 10 Dec 2020 17:15:18 +0000 (12:15 -0500)
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
48 files changed:
hw/alpha/dp264.c
hw/arm/boot.c
hw/arm/digic_boards.c
hw/arm/highbank.c
hw/arm/npcm7xx_boards.c
hw/arm/sbsa-ref.c
hw/arm/vexpress.c
hw/arm/virt.c
hw/avr/boot.c
hw/core/loader.c
hw/display/cg3.c
hw/display/tcx.c
hw/hppa/machine.c
hw/i386/x86.c
hw/lm32/milkymist.c
hw/m68k/mcf5208.c
hw/m68k/q800.c
hw/microblaze/boot.c
hw/mips/fuloong2e.c
hw/mips/jazz.c
hw/mips/malta.c
hw/mips/mipssim.c
hw/nios2/boot.c
hw/nvram/fw_cfg.c
hw/pci-host/prep.c
hw/pci/pci.c
hw/ppc/e500.c
hw/ppc/mac_newworld.c
hw/ppc/mac_oldworld.c
hw/ppc/pnv.c
hw/ppc/ppc405_boards.c
hw/ppc/ppc440_bamboo.c
hw/ppc/sam460ex.c
hw/ppc/spapr.c
hw/ppc/virtex_ml507.c
hw/riscv/boot.c
hw/s390x/ipl.c
hw/sparc/leon3.c
hw/sparc/sun4m.c
hw/sparc64/sun4u.c
include/qemu-common.h
include/qemu/datadir.h [new file with mode: 0644]
include/sysemu/sysemu.h
softmmu/datadir.c [new file with mode: 0644]
softmmu/meson.build
softmmu/vl.c
tests/qtest/fuzz/fuzz.c
ui/keymaps.c

index c4d407a9f156c91385d2c02f360def76df1885b4..c8e300d93f61346952a84dae12adc14ea7327a6d 100644 (file)
@@ -21,6 +21,7 @@
 #include "hw/dma/i8257.h"
 #include "net/net.h"
 #include "qemu/cutils.h"
+#include "qemu/datadir.h"
 #include "net/net.h"
 
 #define MAX_IDE_BUS 2
index cf97600a9158999a6cbad43c55fd5425015e0a07..4d9d47ba1c24e136c8880df852d3998d581e5902 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
 #include <libfdt.h>
index fd228fa96f9763fc3f4cfadd26c8b87f896071bc..be12873673bd7dc89608da2975454d9b0590b1ae 100644 (file)
@@ -26,6 +26,7 @@
 #include "qemu/osdep.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "cpu.h"
 #include "hw/boards.h"
 #include "exec/address-spaces.h"
index fd3429720ef5f03cb24864a28c3aebd3df274d45..bf7b8f4c6483be40c70f1ec2c0c62d63d24155d8 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "qapi/error.h"
 #include "hw/sysbus.h"
 #include "migration/vmstate.h"
index 9821013bc61b364594e132bdcbd464a80b690aa1..306260fa671e9e7bb62e0c58c04ca5f5fb7ac8fa 100644 (file)
@@ -23,6 +23,7 @@
 #include "hw/qdev-properties.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "qemu/units.h"
 #include "sysemu/sysemu.h"
 
index 8272983664ab059adc7d0413e974859a9e5fbce1..9f7073515310a5d61b3079acf935b9dfb3ca9166 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "qapi/error.h"
 #include "qemu/error-report.h"
 #include "qemu/units.h"
index 1adb663d77d3c3136617fa7f619db2c34ac7beb2..ac098375c181cd4f40d18795868f31174b12d1e5 100644 (file)
@@ -24,6 +24,7 @@
 #include "qemu/osdep.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "cpu.h"
 #include "hw/sysbus.h"
 #include "hw/arm/boot.h"
index d09124832d1af10c60920e910c13268894bf5f2e..556592012ee0230031bfcd932d08d76c514cdf2b 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "qemu/units.h"
 #include "qemu/option.h"
 #include "monitor/qdev.h"
index d16bb3dbe1bcc18f15b70725b55e40ee2797942e..cbede775cee2d359a3710c3a3755d28214fe071a 100644 (file)
@@ -10,6 +10,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "hw/loader.h"
 #include "elf.h"
 #include "boot.h"
index 8bbb1797a4c9c3ae084a2a2d87da3d18c60920eb..fea22d265c7f6aa6a86202dd48b824b6b101e140 100644 (file)
@@ -44,6 +44,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "qapi/error.h"
 #include "trace.h"
 #include "hw/hw.h"
index 42fcf40010207eac5a389bdee61048904ccee5a1..4b7e78d91924491b7ffb0a9236e4bc0fe074fd7b 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "qapi/error.h"
 #include "qemu/error-report.h"
 #include "ui/console.h"
index 3799d29b75923d7bc6314fc3499d74be3f85d9a1..965f92ff6b7efcab21f8d31a39d298ffba890a7a 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "qapi/error.h"
 #include "ui/console.h"
 #include "ui/pixel_ops.h"
index 7e41cb2462f9989b4c7738f90e87bd65b8f974ad..f2b71db9bd79bb967ddd12dbd53a52b21f983854 100644 (file)
@@ -5,6 +5,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "cpu.h"
 #include "elf.h"
 #include "hw/loader.h"
index f86f6dbbec491ba0e73c0d03d70743f06bbe0640..49e1d419b2ceb2a067e7f355fe58df38d5e4601c 100644 (file)
@@ -26,6 +26,7 @@
 #include "qemu/cutils.h"
 #include "qemu/units.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "qapi/error.h"
 #include "qapi/qmp/qerror.h"
 #include "qapi/qapi-visit-common.h"
index 93ca8bc2acc44a78b98fe21158489607f89e096e..72d1326531a9d12fba8a9eae35b2f46122893799 100644 (file)
@@ -21,6 +21,7 @@
 #include "qemu/units.h"
 #include "qemu/error-report.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "cpu.h"
 #include "hw/sysbus.h"
 #include "hw/irq.h"
index 2205145ecc61726324f8ae2ff9e8a2084a14df3b..7a03c71059b72b0c5554ef948d11b5c3cc2598bb 100644 (file)
@@ -12,6 +12,7 @@
 #include "qemu/log.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "cpu.h"
 #include "hw/irq.h"
 #include "hw/m68k/mcf.h"
index 6ebcddcfb2c1d62952c40c85a64e90303a1d1bf3..4db2b9bbc7b4dd46b7757655c1f1dc9412f5b408 100644 (file)
@@ -23,6 +23,7 @@
 #include "qemu/osdep.h"
 #include "qemu/units.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "sysemu/sysemu.h"
 #include "cpu.h"
 #include "hw/hw.h"
index e1f56f83f9d10337cf9189aab8bd9e4576adf74f..6715ba2ff96b3114166d769f81d3abc599f99eef 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "cpu.h"
 #include "qemu/option.h"
 #include "qemu/config-file.h"
index 84a2132f85833cfa8fa62e5a79b7e96b7beb70b0..45c596f4fe5c4d033d283b418634736554c05f21 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "qemu/units.h"
 #include "qapi/error.h"
 #include "cpu.h"
index aa95c6a3d3b29650c5ff25217617cbc50946ce5c..f9442731ddea9ea4ce202789143cb72edb5024bc 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "hw/clock.h"
 #include "hw/mips/mips.h"
 #include "hw/mips/cpudevs.h"
index 467b21849e6e6a67683fa13cf7d2261f7016d596..5c11eecec11a2d70b3c846c4f8cdc3b613c44146 100644 (file)
@@ -25,6 +25,7 @@
 #include "qemu/osdep.h"
 #include "qemu/units.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "cpu.h"
 #include "hw/clock.h"
 #include "hw/southbridge/piix.h"
index cc9b0934b341c8d5a4bcacf34ffbff6c6ba8d1a8..f2e627352555071348db5d7f5fc563eb5a700b0b 100644 (file)
@@ -28,6 +28,7 @@
 #include "qemu/osdep.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "cpu.h"
 #include "hw/clock.h"
 #include "hw/mips/mips.h"
index 3cb864914b814ddc8664b3527edf559491de42bf..95a8697906aeecef204af72afccf50c4c566205c 100644 (file)
@@ -31,6 +31,7 @@
 #include "qemu/osdep.h"
 #include "qemu/units.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "cpu.h"
 #include "qemu/option.h"
 #include "qemu/config-file.h"
index 282ba93e2e93c02a5d1285778d1196e023b55151..44cb274a326ad41f6b1f358b8a5b91f214da054b 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/dma.h"
 #include "sysemu/reset.h"
index d0323fefb10f3fb8b053025440a560b87fb55366..0469db8c1d47f151f0451c893addb9478f26b8ba 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "qemu/units.h"
 #include "qapi/error.h"
 #include "hw/pci/pci.h"
index 0131d9d02c16ad02044d8658af83631e3b09bb92..9424231542c7e2477c66b0d057a49e44837e64c3 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "hw/irq.h"
 #include "hw/pci/pci.h"
 #include "hw/pci/pci_bridge.h"
index 153a74c98c4747853f1a6c52bdb8b7e6a7e10012..6a64eb31abac037464edaebf8c08004a824ba2b6 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "qemu/units.h"
 #include "qapi/error.h"
 #include "e500.h"
index 61c63819df29c1975b533918965afb811ff697e0..c0accda5924dcbdb67f69b79f087d88dd905c420 100644 (file)
@@ -48,6 +48,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "qapi/error.h"
 #include "hw/ppc/ppc.h"
 #include "hw/qdev-properties.h"
index 11623e8e671c38af722f3683426c23afb431b40a..04f98a4d818645ea6fc00d55dfd7675316a6328f 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "qemu/units.h"
 #include "qapi/error.h"
 #include "hw/ppc/ppc.h"
index 53a5121cab860c5dfb870d364ef530360177deeb..14fc9758a9730811bebb674cd75970f3e38a7405 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "qemu/units.h"
 #include "qapi/error.h"
 #include "sysemu/qtest.h"
index c867e463308b03ed2c226de326c0911e5444118b..b7249f21cf2e119389fd2bdadd32ea54cba07201 100644 (file)
@@ -26,6 +26,7 @@
 #include "qemu/units.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "cpu.h"
 #include "hw/ppc/ppc.h"
 #include "hw/qdev-properties.h"
index 74028dc986120cea79571948d2899f470173fdb6..665bc1784e1be3e315ac725093a861af9114e170 100644 (file)
@@ -15,6 +15,7 @@
 #include "qemu/units.h"
 #include "qemu/error-report.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "qemu/error-report.h"
 #include "net/net.h"
 #include "hw/pci/pci.h"
index 7e59a91981a882d50120a1903529c07a8bf52744..14e6583eb0dc7da797ffab9b80a9dc8d03f6f264 100644 (file)
@@ -14,6 +14,7 @@
 #include "qemu/osdep.h"
 #include "qemu/units.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
 #include "hw/boards.h"
index e87a3b8557db65600c66c62cfee1aa3220a3297a..3f5b0d01596cc07538b3032fa78b15320f2175ca 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "qapi/error.h"
 #include "qapi/visitor.h"
 #include "sysemu/sysemu.h"
index c790c1113f076b0f464a8d2d57a13def8c52c884..7f1bca928c18db8f27bbdf9fb1b6cef590c54f73 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "qemu/units.h"
 #include "cpu.h"
 #include "hw/sysbus.h"
index 70a9bf8f5d60674b5454ad64f5d74c6477fa4009..d62f3dc7581ef3f1cf3df33ccb570a3dcd53d8d7 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "qemu/units.h"
 #include "qemu/error-report.h"
 #include "exec/cpu-defs.h"
index bddbaffac6744d9f6098383750708c0332aeb6ab..ff6b55e8167dda8870da7b384811a322584638fb 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "qapi/error.h"
 #include "sysemu/reset.h"
 #include "sysemu/runstate.h"
index 1c50b02f815166d1ffb6f19f46b8c39f0860438f..4bc4ebea84125fce3ebc0cdf89227eee304c1fa3 100644 (file)
@@ -27,6 +27,7 @@
 #include "qemu/error-report.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "cpu.h"
 #include "hw/irq.h"
 #include "qemu/timer.h"
index 0f9cd2bf5290e82af10208fda57a16fce3a768c8..8686371318262c6094bfd616fd0bb01583305eed 100644 (file)
@@ -25,6 +25,7 @@
 #include "qemu/osdep.h"
 #include "qemu/units.h"
 #include "qapi/error.h"
+#include "qemu/datadir.h"
 #include "qemu-common.h"
 #include "cpu.h"
 #include "hw/sysbus.h"
index 8bee7dd2f43b000f8c74afdee1f773196a34050c..0fa13a733020616ea8f7af29bd4797718870a66e 100644 (file)
@@ -27,6 +27,7 @@
 #include "qemu/error-report.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "cpu.h"
 #include "hw/pci/pci.h"
 #include "hw/pci/pci_bridge.h"
index fda7dc6ca77b88f4e381622e3a29e8e18fd1b90f..654621444ecf77f2159f29d9e87a484586f8d998 100644 (file)
@@ -108,27 +108,6 @@ void qemu_progress_end(void);
 void qemu_progress_print(float delta, int max);
 const char *qemu_get_vm_name(void);
 
-#define QEMU_FILE_TYPE_BIOS   0
-#define QEMU_FILE_TYPE_KEYMAP 1
-/**
- * qemu_find_file:
- * @type: QEMU_FILE_TYPE_BIOS (for BIOS, VGA BIOS)
- *        or QEMU_FILE_TYPE_KEYMAP (for keymaps).
- * @name: Relative or absolute file name
- *
- * If @name exists on disk as an absolute path, or a path relative
- * to the current directory, then returns @name unchanged.
- * Otherwise searches for @name file in the data directories, either
- * configured at build time (DATADIR) or registered with the -L command
- * line option.
- *
- * The caller must use g_free() to free the returned data when it is
- * no longer required.
- *
- * Returns: a path that can access @name, or NULL if no matching file exists.
- */
-char *qemu_find_file(int type, const char *name);
-
 /* OS specific functions */
 void os_setup_early_signal_handling(void);
 int os_parse_cmd_args(int index, const char *optarg);
diff --git a/include/qemu/datadir.h b/include/qemu/datadir.h
new file mode 100644 (file)
index 0000000..21f9097
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef QEMU_DATADIR_H
+#define QEMU_DATADIR_H
+
+#define QEMU_FILE_TYPE_BIOS   0
+#define QEMU_FILE_TYPE_KEYMAP 1
+/**
+ * qemu_find_file:
+ * @type: QEMU_FILE_TYPE_BIOS (for BIOS, VGA BIOS)
+ *        or QEMU_FILE_TYPE_KEYMAP (for keymaps).
+ * @name: Relative or absolute file name
+ *
+ * If @name exists on disk as an absolute path, or a path relative
+ * to the current directory, then returns @name unchanged.
+ * Otherwise searches for @name file in the data directories, either
+ * configured at build time (DATADIR) or registered with the -L command
+ * line option.
+ *
+ * The caller must use g_free() to free the returned data when it is
+ * no longer required.
+ *
+ * Returns: a path that can access @name, or NULL if no matching file exists.
+ */
+char *qemu_find_file(int type, const char *name);
+void qemu_add_default_firmwarepath(void);
+void qemu_add_data_dir(char *path);
+void qemu_list_data_dirs(void);
+
+#endif
index 1336b4264ae5dd7d03a2b9255dedd102f4e96457..c94b2e7159d38f77384d36eaa237818b82d33d81 100644 (file)
@@ -13,8 +13,6 @@ extern const char *qemu_name;
 extern QemuUUID qemu_uuid;
 extern bool qemu_uuid_set;
 
-void qemu_add_data_dir(char *path);
-
 void qemu_add_exit_notifier(Notifier *notify);
 void qemu_remove_exit_notifier(Notifier *notify);
 
diff --git a/softmmu/datadir.c b/softmmu/datadir.c
new file mode 100644 (file)
index 0000000..504c466
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ * QEMU firmware and keymap file search
+ *
+ * Copyright (c) 2003-2020 QEMU contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+#include "qemu/datadir.h"
+#include "qemu/cutils.h"
+#include "trace.h"
+
+static const char *data_dir[16];
+static int data_dir_idx;
+
+char *qemu_find_file(int type, const char *name)
+{
+    int i;
+    const char *subdir;
+    char *buf;
+
+    /* Try the name as a straight path first */
+    if (access(name, R_OK) == 0) {
+        trace_load_file(name, name);
+        return g_strdup(name);
+    }
+
+    switch (type) {
+    case QEMU_FILE_TYPE_BIOS:
+        subdir = "";
+        break;
+    case QEMU_FILE_TYPE_KEYMAP:
+        subdir = "keymaps/";
+        break;
+    default:
+        abort();
+    }
+
+    for (i = 0; i < data_dir_idx; i++) {
+        buf = g_strdup_printf("%s/%s%s", data_dir[i], subdir, name);
+        if (access(buf, R_OK) == 0) {
+            trace_load_file(name, buf);
+            return buf;
+        }
+        g_free(buf);
+    }
+    return NULL;
+}
+
+void qemu_add_data_dir(char *path)
+{
+    int i;
+
+    if (path == NULL) {
+        return;
+    }
+    if (data_dir_idx == ARRAY_SIZE(data_dir)) {
+        return;
+    }
+    for (i = 0; i < data_dir_idx; i++) {
+        if (strcmp(data_dir[i], path) == 0) {
+            g_free(path); /* duplicate */
+            return;
+        }
+    }
+    data_dir[data_dir_idx++] = path;
+}
+
+/*
+ * Find a likely location for support files using the location of the binary.
+ * When running from the build tree this will be "$bindir/pc-bios".
+ * Otherwise, this is CONFIG_QEMU_DATADIR (possibly relocated).
+ *
+ * The caller must use g_free() to free the returned data when it is
+ * no longer required.
+ */
+static char *find_datadir(void)
+{
+    g_autofree char *dir = NULL;
+
+    dir = g_build_filename(qemu_get_exec_dir(), "pc-bios", NULL);
+    if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
+        return g_steal_pointer(&dir);
+    }
+
+    return get_relocated_path(CONFIG_QEMU_DATADIR);
+}
+
+void qemu_add_default_firmwarepath(void)
+{
+    char **dirs;
+    size_t i;
+
+    /* add configured firmware directories */
+    dirs = g_strsplit(CONFIG_QEMU_FIRMWAREPATH, G_SEARCHPATH_SEPARATOR_S, 0);
+    for (i = 0; dirs[i] != NULL; i++) {
+        qemu_add_data_dir(get_relocated_path(dirs[i]));
+    }
+    g_strfreev(dirs);
+
+    /* try to find datadir relative to the executable path */
+    qemu_add_data_dir(find_datadir());
+}
+
+void qemu_list_data_dirs(void)
+{
+    int i;
+    for (i = 0; i < data_dir_idx; i++) {
+        printf("%s\n", data_dir[i]);
+    }
+}
index 8f7210b4f076a6568256644697552224a3fba5c3..7b52339e7accdcc4f35562c53dde543720d47c69 100644 (file)
@@ -3,6 +3,7 @@ specific_ss.add(when: 'CONFIG_SOFTMMU', if_true: [files(
   'balloon.c',
   'cpus.c',
   'cpu-throttle.c',
+  'datadir.c',
   'physmem.c',
   'ioport.c',
   'memory.c',
index dc8a47efcb0cbd10bb488ff3d6fe0ac4c91ec0ec..28aafc1101c62024ca5407321002d414e05b0599 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "qemu/units.h"
 #include "hw/boards.h"
 #include "hw/qdev-properties.h"
@@ -128,8 +129,6 @@ typedef struct BlockdevOptionsQueueEntry {
 typedef QSIMPLEQ_HEAD(, BlockdevOptionsQueueEntry) BlockdevOptionsQueue;
 
 static const char *cpu_option;
-static const char *data_dir[16];
-static int data_dir_idx;
 static const char *mem_path;
 static const char *boot_order;
 static const char *boot_once;
@@ -1994,59 +1993,6 @@ static void parse_display(const char *p)
     }
 }
 
-char *qemu_find_file(int type, const char *name)
-{
-    int i;
-    const char *subdir;
-    char *buf;
-
-    /* Try the name as a straight path first */
-    if (access(name, R_OK) == 0) {
-        trace_load_file(name, name);
-        return g_strdup(name);
-    }
-
-    switch (type) {
-    case QEMU_FILE_TYPE_BIOS:
-        subdir = "";
-        break;
-    case QEMU_FILE_TYPE_KEYMAP:
-        subdir = "keymaps/";
-        break;
-    default:
-        abort();
-    }
-
-    for (i = 0; i < data_dir_idx; i++) {
-        buf = g_strdup_printf("%s/%s%s", data_dir[i], subdir, name);
-        if (access(buf, R_OK) == 0) {
-            trace_load_file(name, buf);
-            return buf;
-        }
-        g_free(buf);
-    }
-    return NULL;
-}
-
-void qemu_add_data_dir(char *path)
-{
-    int i;
-
-    if (path == NULL) {
-        return;
-    }
-    if (data_dir_idx == ARRAY_SIZE(data_dir)) {
-        return;
-    }
-    for (i = 0; i < data_dir_idx; i++) {
-        if (strcmp(data_dir[i], path) == 0) {
-            g_free(path); /* duplicate */
-            return;
-        }
-    }
-    data_dir[data_dir_idx++] = path;
-}
-
 static inline bool nonempty_str(const char *str)
 {
     return str && *str;
@@ -3187,26 +3133,6 @@ static void create_default_memdev(MachineState *ms, const char *path)
                             &error_fatal);
 }
 
-/*
- * Find a likely location for support files using the location of the binary.
- * When running from the build tree this will be "$bindir/pc-bios".
- * Otherwise, this is CONFIG_QEMU_DATADIR (possibly relocated).
- *
- * The caller must use g_free() to free the returned data when it is
- * no longer required.
- */
-static char *find_datadir(void)
-{
-    g_autofree char *dir = NULL;
-
-    dir = g_build_filename(qemu_get_exec_dir(), "pc-bios", NULL);
-    if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
-        return g_steal_pointer(&dir);
-    }
-
-    return get_relocated_path(CONFIG_QEMU_DATADIR);
-}
-
 static void qemu_validate_options(void)
 {
     QemuOpts *machine_opts = qemu_get_machine_opts();
@@ -3266,9 +3192,6 @@ static void qemu_process_sugar_options(void)
 
 static void qemu_process_early_options(void)
 {
-    char **dirs;
-    int i;
-
 #ifdef CONFIG_SECCOMP
     QemuOptsList *olist = qemu_find_opts_err("sandbox", NULL);
     if (olist) {
@@ -3306,21 +3229,11 @@ static void qemu_process_early_options(void)
         qemu_set_log(0);
     }
 
-    /* add configured firmware directories */
-    dirs = g_strsplit(CONFIG_QEMU_FIRMWAREPATH, G_SEARCHPATH_SEPARATOR_S, 0);
-    for (i = 0; dirs[i] != NULL; i++) {
-        qemu_add_data_dir(get_relocated_path(dirs[i]));
-    }
-    g_strfreev(dirs);
-
-    /* try to find datadir relative to the executable path */
-    qemu_add_data_dir(find_datadir());
+    qemu_add_default_firmwarepath();
 }
 
 static void qemu_process_help_options(void)
 {
-    int i;
-
     /*
      * Check for -cpu help and -device help before we call select_machine(),
      * which will return an error if the architecture has no default machine
@@ -3339,9 +3252,7 @@ static void qemu_process_help_options(void)
 
     /* -L help lists the data directories and exits. */
     if (list_data_dirs) {
-        for (i = 0; i < data_dir_idx; i++) {
-            printf("%s\n", data_dir[i]);
-        }
+        qemu_list_data_dirs();
         exit(0);
     }
 }
index 7be7226bc07db74809ce16f954fe56546300363c..238866a0370e0815105f2b6903e312170a6bff15 100644 (file)
@@ -15,6 +15,7 @@
 
 #include <wordexp.h>
 
+#include "qemu/datadir.h"
 #include "sysemu/qtest.h"
 #include "sysemu/runstate.h"
 #include "sysemu/sysemu.h"
index 4e5fca57a801cf62f0df2e9acfd22fa16a54cb8d..d4a647464bbf2a6e848dc866b77d32ba2763d4b4 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu-common.h"
+#include "qemu/datadir.h"
 #include "keymaps.h"
 #include "trace.h"
 #include "qemu/ctype.h"