All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Sertonix" <sertonix@posteo.net>
To: <qemu-devel@nongnu.org>
Subject: [PATCH] hw/i386: Use qemu_open_old for kernel/initrd
Date: Sun, 19 Apr 2026 19:35:45 +0000	[thread overview]
Message-ID: <DHXDTYTOFYVL.3H531B0BJOQ22@posteo.net> (raw)


Allows using "-kernel /dev/fdset/0" and "-initrd /dev/fdset/1" (if the
file descriptors are opened read-only).

For the sake of consistency it would be best to do the same change in
the other hw/* subdirectories as well but I lack the means to test all
of them.

---
 hw/i386/x86-common.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/hw/i386/x86-common.c b/hw/i386/x86-common.c
index fde05fa7d7..5d8be30f4d 100644
--- a/hw/i386/x86-common.c
+++ b/hw/i386/x86-common.c
@@ -651,6 +651,7 @@ void x86_load_linux(X86MachineState *x86ms,
     uint8_t header[8192], *setup, *kernel;
     hwaddr real_addr, prot_addr, cmdline_addr, initrd_addr = 0;
     FILE *f;
+    int fd;
     const char *vmode;
     MachineState *machine = MACHINE(x86ms);
     struct setup_data *setup_data;
@@ -664,8 +665,8 @@ void x86_load_linux(X86MachineState *x86ms,
     cmdline_size = (strlen(kernel_cmdline) + 16) & ~15;
 
     /* load the kernel header */
-    f = fopen(kernel_filename, "rb");
-    if (!f) {
+    fd = qemu_open_old(kernel_filename, O_RDONLY);
+    if (fd < 0 || !(f = fdopen(fd, "rb"))) {
         fprintf(stderr, "qemu: could not open kernel file '%s': %s\n",
                 kernel_filename, strerror(errno));
         exit(1);
@@ -719,12 +720,14 @@ void x86_load_linux(X86MachineState *x86ms,
 
             /* load initrd */
             if (initrd_filename) {
+                int mapped_file_fd;
                 GMappedFile *mapped_file;
                 gsize initrd_size;
                 gchar *initrd_data;
                 GError *gerr = NULL;
 
-                mapped_file = g_mapped_file_new(initrd_filename, false, &gerr);
+                mapped_file_fd = qemu_open_old(initrd_filename, O_RDONLY);
+                mapped_file = g_mapped_file_new_from_fd(mapped_file_fd, false, &gerr);
                 if (!mapped_file) {
                     fprintf(stderr, "qemu: error reading initrd %s: %s\n",
                             initrd_filename, gerr->message);
@@ -860,6 +863,7 @@ void x86_load_linux(X86MachineState *x86ms,
 
     /* load initrd */
     if (initrd_filename) {
+        int mapped_file_fd;
         GMappedFile *mapped_file;
         gsize initrd_size;
         gchar *initrd_data;
@@ -870,7 +874,8 @@ void x86_load_linux(X86MachineState *x86ms,
             exit(1);
         }
 
-        mapped_file = g_mapped_file_new(initrd_filename, false, &gerr);
+        mapped_file_fd = qemu_open_old(initrd_filename, O_RDONLY);
+        mapped_file = g_mapped_file_new_from_fd(mapped_file_fd, false, &gerr);
         if (!mapped_file) {
             fprintf(stderr, "qemu: error reading initrd %s: %s\n",
                     initrd_filename, gerr->message);
-- 
2.53.0



             reply	other threads:[~2026-04-19 19:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-19 19:35 Sertonix [this message]
2026-04-20 20:12 ` [PATCH] hw/i386: Use qemu_open_old for kernel/initrd Philippe Mathieu-Daudé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DHXDTYTOFYVL.3H531B0BJOQ22@posteo.net \
    --to=sertonix@posteo.net \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.