From: Pingfan Liu <piliu@redhat.com>
To: kexec@lists.infradead.org
Cc: Pingfan Liu <piliu@redhat.com>, Simon Horman <horms@kernel.org>,
Philipp Rudo <prudo@redhat.com>
Subject: [PATCH 1/3] UKI: Split out the routine to create temporary fd
Date: Tue, 5 Nov 2024 11:57:05 +0800 [thread overview]
Message-ID: <20241105035710.11384-2-piliu@redhat.com> (raw)
In-Reply-To: <20241105035710.11384-1-piliu@redhat.com>
The process of creating temporary fd for initrd can be reused. Hence
splitting it out for later use.
Signed-off-by: Pingfan Liu <piliu@redhat.com>
Cc: Simon Horman <horms@kernel.org>
To: kexec@lists.infradead.org
---
kexec/kexec-uki.c | 53 +++++++++++++++++++++++++++--------------------
1 file changed, 30 insertions(+), 23 deletions(-)
diff --git a/kexec/kexec-uki.c b/kexec/kexec-uki.c
index 210ebb6..8a7d349 100644
--- a/kexec/kexec-uki.c
+++ b/kexec/kexec-uki.c
@@ -35,6 +35,34 @@ static int get_pehdr_offset(const char *buf)
return pe_hdr_offset;
}
+static int create_tmpfd(const char *template, char *buf, int buf_sz, int *tmpfd)
+{
+ char *fname;
+ int fd = -1;
+
+ if (!(fname = strdup(template))) {
+ dbgprintf("%s: Can't duplicate strings\n", __func__);
+ return -1;
+ }
+
+ if ((fd = mkstemp(fname)) < 0) {
+ dbgprintf("%s: Can't open file %s\n", __func__, fname);
+ return -1;
+ }
+
+ if (write(fd, buf, buf_sz) != buf_sz) {
+ dbgprintf("%s: Can't write the compressed file %s\n",
+ __func__, fname);
+ close(fd);
+ return -1;
+ } else {
+ *tmpfd = open(fname, O_RDONLY);
+ close(fd);
+ }
+
+ return 0;
+}
+
int uki_image_probe(const char *file_buf, off_t buf_sz)
{
struct pe_hdr *pe_hdr;
@@ -42,8 +70,6 @@ int uki_image_probe(const char *file_buf, off_t buf_sz)
struct section_header *sect_hdr;
int pe_hdr_offset, section_nr, linux_sz = -1;
char *pe_part_buf, *linux_src;
- char *initrd_fname = NULL;
- int initrd_fd = -1;
pe_hdr_offset = get_pehdr_offset(file_buf);
pe_part_buf = (char *)file_buf + pe_hdr_offset;
@@ -63,28 +89,9 @@ int uki_image_probe(const char *file_buf, off_t buf_sz)
linux_sz = sect_hdr->raw_data_size;
} else if (!strcmp(sect_hdr->name, UKI_INITRD_SECTION)) {
- if (!(initrd_fname = strdup(FILENAME_UKI_INITRD))) {
- dbgprintf("%s: Can't duplicate strings\n", __func__);
- goto next;
- }
-
- if ((initrd_fd = mkstemp(initrd_fname)) < 0) {
- dbgprintf("%s: Can't open file %s\n", __func__, initrd_fname);
- goto next;
- }
-
- if (write(initrd_fd, (char *)file_buf + sect_hdr->data_addr,
- sect_hdr->raw_data_size) != sect_hdr->raw_data_size) {
- dbgprintf("%s: Can't write the compressed file %s\n",
- __func__, initrd_fname);
- close(initrd_fd);
- goto next;
- } else {
- implicit_initrd_fd = open(initrd_fname, O_RDONLY);
- close(initrd_fd);
- }
+ create_tmpfd(FILENAME_UKI_INITRD, (char *)file_buf + sect_hdr->data_addr,
+ sect_hdr->raw_data_size, &implicit_initrd_fd);
}
-next:
sect_hdr++;
}
--
2.41.0
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
next prev parent reply other threads:[~2024-11-05 3:57 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-05 3:57 [PATCH 0/3] Enable UKI image load on x86_64 Pingfan Liu
2024-11-05 3:57 ` Pingfan Liu [this message]
2024-11-05 3:57 ` [PATCH 2/3] kexec: Create a temporary file to hold .linux section in uki_probe() Pingfan Liu
2024-11-05 3:57 ` [PATCH 3/3] x86_64: Support UKI image format Pingfan Liu
2024-11-22 2:12 ` [PATCH 0/3] Enable UKI image load on x86_64 Dave Young
2024-12-02 13:06 ` Simon Horman
2024-12-02 13:34 ` Simon Horman
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=20241105035710.11384-2-piliu@redhat.com \
--to=piliu@redhat.com \
--cc=horms@kernel.org \
--cc=kexec@lists.infradead.org \
--cc=prudo@redhat.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox