summaryrefslogtreecommitdiff
path: root/fs/fs.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/fs.c')
-rw-r--r--fs/fs.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/fs/fs.c b/fs/fs.c
index 99ddcc5e37b..fdff83719b1 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_debug("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)
{