From: Gabriel Dalimonte <gabriel.dalimonte@gmail.com>
To: u-boot@lists.denx.de
Cc: Gabriel Dalimonte <gabriel.dalimonte@gmail.com>,
Heinrich Schuchardt <xypron.glpk@gmx.de>,
Ilias Apalodimas <ilias.apalodimas@linaro.org>,
Simon Glass <sjg@chromium.org>, Tom Rini <trini@konsulko.com>
Subject: [PATCH v2 6/6] efi_loader: support file rename in SetInfo()
Date: Mon, 17 Feb 2025 13:26:47 -0500 [thread overview]
Message-ID: <20250217182648.31294-7-gabriel.dalimonte@gmail.com> (raw)
In-Reply-To: <20250217182648.31294-1-gabriel.dalimonte@gmail.com>
Following the UEFI specification. The specification did not seem to
delineate if file_name was explicitly a file name only, or could
include paths to move the file to a different directory. The more
generous interpretation of supporting paths was selected.
Signed-off-by: Gabriel Dalimonte <gabriel.dalimonte@gmail.com>
---
Changes in v2:
- simplify freeing of new_file_name and new_path
---
lib/efi_loader/efi_file.c | 45 +++++++++++++++++++++++++++++++++------
1 file changed, 39 insertions(+), 6 deletions(-)
diff --git a/lib/efi_loader/efi_file.c b/lib/efi_loader/efi_file.c
index 6b15c1f3d27..7d81da8f2d8 100644
--- a/lib/efi_loader/efi_file.c
+++ b/lib/efi_loader/efi_file.c
@@ -954,6 +954,7 @@ static efi_status_t EFIAPI efi_file_setinfo(struct efi_file_handle *file,
{
struct file_handle *fh = to_fh(file);
efi_status_t ret = EFI_UNSUPPORTED;
+ char *new_file_name = NULL, *new_path = NULL;
EFI_ENTRY("%p, %pUs, %zu, %p", file, info_type, buffer_size, buffer);
@@ -983,13 +984,43 @@ static efi_status_t EFIAPI efi_file_setinfo(struct efi_file_handle *file,
pos = new_file_name;
utf16_utf8_strcpy(&pos, info->file_name);
if (strcmp(new_file_name, filename)) {
- /* TODO: we do not support renaming */
- EFI_PRINT("Renaming not supported\n");
- free(new_file_name);
- ret = EFI_ACCESS_DENIED;
- goto out;
+ int dlen;
+ int rv;
+
+ if (set_blk_dev(fh)) {
+ ret = EFI_DEVICE_ERROR;
+ goto out;
+ }
+ dlen = filename - fh->path;
+ new_path = calloc(1, dlen + strlen(new_file_name) + 1);
+ if (!new_path) {
+ ret = EFI_OUT_OF_RESOURCES;
+ goto out;
+ }
+ memcpy(new_path, fh->path, dlen);
+ strcpy(new_path + dlen, new_file_name);
+ sanitize_path(new_path);
+ rv = fs_exists(new_path);
+ if (rv) {
+ ret = EFI_ACCESS_DENIED;
+ goto out;
+ }
+ /* fs_exists() calls fs_close(), so open file system again */
+ if (set_blk_dev(fh)) {
+ ret = EFI_DEVICE_ERROR;
+ goto out;
+ }
+ rv = fs_rename(fh->path, new_path);
+ if (rv) {
+ ret = EFI_ACCESS_DENIED;
+ goto out;
+ }
+ free(fh->path);
+ fh->path = new_path;
+ /* Prevent new_path from being freed on out */
+ new_path = NULL;
+ ret = EFI_SUCCESS;
}
- free(new_file_name);
/* Check for truncation */
if (!fh->isdir) {
ret = efi_get_file_size(fh, &file_size);
@@ -1012,6 +1043,8 @@ static efi_status_t EFIAPI efi_file_setinfo(struct efi_file_handle *file,
ret = EFI_UNSUPPORTED;
}
out:
+ free(new_path);
+ free(new_file_name);
return EFI_EXIT(ret);
}
--
2.34.1
next prev parent reply other threads:[~2025-02-18 5:37 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-17 18:26 [PATCH v2 0/6] This series adds support for file renaming to EFI_FILE_PROTOCOL.SetInfo() Gabriel Dalimonte
2025-02-17 18:26 ` [PATCH v2 1/6] fs: fat: factor out dentry link create/delete Gabriel Dalimonte
2025-02-17 18:26 ` [PATCH v2 2/6] fs: add rename infrastructure Gabriel Dalimonte
2025-02-20 7:33 ` Ilias Apalodimas
2025-02-17 18:26 ` [PATCH v2 3/6] fs: fat: add rename Gabriel Dalimonte
2025-02-17 18:26 ` [PATCH v2 4/6] fs: fat: update parent dirs metadata on dentry create/delete Gabriel Dalimonte
2025-02-17 18:26 ` [PATCH v2 5/6] efi_loader: move path out of file_handle Gabriel Dalimonte
2025-02-20 7:55 ` Ilias Apalodimas
2025-03-04 2:30 ` Gabriel D'Alimonte
2025-02-17 18:26 ` Gabriel Dalimonte [this message]
2025-02-20 8:21 ` [PATCH v2 6/6] efi_loader: support file rename in SetInfo() Ilias Apalodimas
2025-02-20 8:30 ` Ilias Apalodimas
2025-03-08 14:04 ` [PATCH v2 0/6] This series adds support for file renaming to EFI_FILE_PROTOCOL.SetInfo() Tom Rini
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=20250217182648.31294-7-gabriel.dalimonte@gmail.com \
--to=gabriel.dalimonte@gmail.com \
--cc=ilias.apalodimas@linaro.org \
--cc=sjg@chromium.org \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
--cc=xypron.glpk@gmx.de \
/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