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>,
Nam Cao <namcao@linutronix.de>, Simon Glass <sjg@chromium.org>,
Sughosh Ganu <sughosh.ganu@linaro.org>,
Tom Rini <trini@konsulko.com>
Subject: [PATCH 2/6] fs: add rename infrastructure
Date: Wed, 22 Jan 2025 00:32:27 -0500 [thread overview]
Message-ID: <20250122053232.17365-3-gabriel.dalimonte@gmail.com> (raw)
In-Reply-To: <20250122053232.17365-1-gabriel.dalimonte@gmail.com>
Signed-off-by: Gabriel Dalimonte <gabriel.dalimonte@gmail.com>
---
fs/fs.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
include/fs.h | 13 +++++++++++++
2 files changed, 60 insertions(+)
diff --git a/fs/fs.c b/fs/fs.c
index 99ddcc5e37..160a43c957 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -143,6 +143,12 @@ static inline int fs_mkdir_unsupported(const char *dirname)
return -1;
}
+static inline int fs_rename_unsupported(const char *old_path,
+ const char *new_path)
+{
+ return -1;
+}
+
struct fstype_info {
int fstype;
char *name;
@@ -183,6 +189,7 @@ struct fstype_info {
int (*unlink)(const char *filename);
int (*mkdir)(const char *dirname);
int (*ln)(const char *filename, const char *target);
+ int (*rename)(const char *old_path, const char *new_path);
};
static struct fstype_info fstypes[] = {
@@ -206,6 +213,7 @@ static struct fstype_info fstypes[] = {
.unlink = fs_unlink_unsupported,
.mkdir = fs_mkdir_unsupported,
#endif
+ .rename = fs_rename_unsupported,
.uuid = fat_uuid,
.opendir = fat_opendir,
.readdir = fat_readdir,
@@ -238,6 +246,7 @@ static struct fstype_info fstypes[] = {
.closedir = ext4fs_closedir,
.unlink = fs_unlink_unsupported,
.mkdir = fs_mkdir_unsupported,
+ .rename = fs_rename_unsupported,
},
#endif
#if IS_ENABLED(CONFIG_SANDBOX) && !IS_ENABLED(CONFIG_XPL_BUILD)
@@ -257,6 +266,7 @@ static struct fstype_info fstypes[] = {
.unlink = fs_unlink_unsupported,
.mkdir = fs_mkdir_unsupported,
.ln = fs_ln_unsupported,
+ .rename = fs_rename_unsupported,
},
#endif
#if CONFIG_IS_ENABLED(SEMIHOSTING)
@@ -276,6 +286,7 @@ static struct fstype_info fstypes[] = {
.unlink = fs_unlink_unsupported,
.mkdir = fs_mkdir_unsupported,
.ln = fs_ln_unsupported,
+ .rename = fs_rename_unsupported,
},
#endif
#ifndef CONFIG_XPL_BUILD
@@ -296,6 +307,7 @@ static struct fstype_info fstypes[] = {
.unlink = fs_unlink_unsupported,
.mkdir = fs_mkdir_unsupported,
.ln = fs_ln_unsupported,
+ .rename = fs_rename_unsupported,
},
#endif
#endif
@@ -317,6 +329,7 @@ static struct fstype_info fstypes[] = {
.unlink = fs_unlink_unsupported,
.mkdir = fs_mkdir_unsupported,
.ln = fs_ln_unsupported,
+ .rename = fs_rename_unsupported,
},
#endif
#endif
@@ -339,6 +352,7 @@ static struct fstype_info fstypes[] = {
.ln = fs_ln_unsupported,
.unlink = fs_unlink_unsupported,
.mkdir = fs_mkdir_unsupported,
+ .rename = fs_rename_unsupported,
},
#endif
#if IS_ENABLED(CONFIG_FS_EROFS)
@@ -360,6 +374,7 @@ static struct fstype_info fstypes[] = {
.ln = fs_ln_unsupported,
.unlink = fs_unlink_unsupported,
.mkdir = fs_mkdir_unsupported,
+ .rename = fs_rename_unsupported,
},
#endif
{
@@ -378,6 +393,7 @@ static struct fstype_info fstypes[] = {
.unlink = fs_unlink_unsupported,
.mkdir = fs_mkdir_unsupported,
.ln = fs_ln_unsupported,
+ .rename = fs_rename_unsupported,
},
};
@@ -713,6 +729,22 @@ int fs_ln(const char *fname, const char *target)
return ret;
}
+int fs_rename(const char *old_path, const char *new_path)
+{
+ struct fstype_info *info = fs_get_info(fs_type);
+ int ret;
+
+ ret = info->rename(old_path, new_path);
+
+ if (ret < 0) {
+ log_err("** Unable to rename %s -> %s **\n", old_path, new_path);
+ ret = -1;
+ }
+ fs_close();
+
+ return ret;
+}
+
int do_size(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
int fstype)
{
@@ -975,6 +1007,21 @@ int do_ln(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
return 0;
}
+int do_rename(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
+ int fstype)
+{
+ if (argc != 5)
+ return CMD_RET_USAGE;
+
+ if (fs_set_blk_dev(argv[1], argv[2], fstype))
+ return 1;
+
+ if (fs_rename(argv[3], argv[4]))
+ return 1;
+
+ return 0;
+}
+
int do_fs_types(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[])
{
struct fstype_info *drv = fstypes;
diff --git a/include/fs.h b/include/fs.h
index 2474880385..24b121f55d 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -270,6 +270,17 @@ int fs_unlink(const char *filename);
*/
int fs_mkdir(const char *filename);
+/**
+ * fs_rename - rename a file or directory
+ *
+ * @old_path: existing path of the file/directory to rename
+ * @new_path: new path of the file/directory. If this points to an existing
+ * file or empty directory, the existing file/directory will be unlinked.
+ *
+ * Return: 0 on success, -1 on error conditions
+ */
+int fs_rename(const char *old_path, const char *new_path);
+
/*
* Common implementation for various filesystem commands, optionally limited
* to a specific filesystem type via the fstype parameter.
@@ -290,6 +301,8 @@ int do_mkdir(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
int fstype);
int do_ln(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
int fstype);
+int do_rename(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
+ int fstype);
/*
* Determine the UUID of the specified filesystem and print it. Optionally it is
--
2.34.1
next prev parent reply other threads:[~2025-01-22 13:23 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-22 5:32 [PATCH 0/6] add support for renaming to EFI_FILE_PROTOCOL.SetInfo() Gabriel Dalimonte
2025-01-22 5:32 ` [PATCH 1/6] fs: fat: factor out dentry link create/delete Gabriel Dalimonte
2025-01-22 7:08 ` Heinrich Schuchardt
2025-01-26 4:34 ` Gabriel D'Alimonte
2025-01-22 5:32 ` Gabriel Dalimonte [this message]
2025-01-22 8:10 ` [PATCH 2/6] fs: add rename infrastructure Heinrich Schuchardt
2025-01-22 9:18 ` Heinrich Schuchardt
2025-01-26 4:38 ` Gabriel D'Alimonte
2025-01-22 5:32 ` [PATCH 3/6] fs: fat: add rename Gabriel Dalimonte
2025-01-22 8:41 ` Heinrich Schuchardt
2025-01-22 5:32 ` [PATCH 4/6] fs: fat: update parent dirs metadata on rename Gabriel Dalimonte
2025-01-22 9:00 ` Heinrich Schuchardt
2025-01-26 4:39 ` Gabriel D'Alimonte
2025-01-22 5:32 ` [PATCH 5/6] efi_loader: move path out of file_handle Gabriel Dalimonte
2025-01-22 5:32 ` [PATCH 6/6] efi_loader: support file rename in SetInfo() Gabriel Dalimonte
2025-02-04 12:53 ` Ilias Apalodimas
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=20250122053232.17365-3-gabriel.dalimonte@gmail.com \
--to=gabriel.dalimonte@gmail.com \
--cc=ilias.apalodimas@linaro.org \
--cc=namcao@linutronix.de \
--cc=sjg@chromium.org \
--cc=sughosh.ganu@linaro.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