The EFI API supports file renaming, which is required by systemd-stub for its bootcounting implementation.
Signed-off-by: Daniel Venzin <daniel.ven...@mt.com> --- (no changes since v2) Changes in v2: - Adapt variable names for better consistency - Add missing rename hooks fs/fs.c | 30 ++++++++++++++++++++++++++++++ include/fs.h | 9 +++++++++ 2 files changed, 39 insertions(+) diff --git a/fs/fs.c b/fs/fs.c index 99ddcc5e37b..b746d05ebcd 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_filename, + const char *new_filename) +{ + return -1; +} + struct fstype_info { int fstype; char *name; @@ -182,6 +188,7 @@ struct fstype_info { void (*closedir)(struct fs_dir_stream *dirs); int (*unlink)(const char *filename); int (*mkdir)(const char *dirname); + int (*rename)(const char *old_filename, const char *new_filename); int (*ln)(const char *filename, const char *target); }; @@ -201,10 +208,12 @@ static struct fstype_info fstypes[] = { .write = file_fat_write, .unlink = fat_unlink, .mkdir = fat_mkdir, + .rename = fs_rename_unsupported, #else .write = fs_write_unsupported, .unlink = fs_unlink_unsupported, .mkdir = fs_mkdir_unsupported, + .rename = fs_rename_unsupported, #endif .uuid = fat_uuid, .opendir = fat_opendir, @@ -238,6 +247,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) @@ -256,6 +266,7 @@ static struct fstype_info fstypes[] = { .opendir = fs_opendir_unsupported, .unlink = fs_unlink_unsupported, .mkdir = fs_mkdir_unsupported, + .rename = fs_rename_unsupported, .ln = fs_ln_unsupported, }, #endif @@ -275,6 +286,7 @@ static struct fstype_info fstypes[] = { .opendir = fs_opendir_unsupported, .unlink = fs_unlink_unsupported, .mkdir = fs_mkdir_unsupported, + .rename = fs_rename_unsupported, .ln = fs_ln_unsupported, }, #endif @@ -295,6 +307,7 @@ static struct fstype_info fstypes[] = { .opendir = fs_opendir_unsupported, .unlink = fs_unlink_unsupported, .mkdir = fs_mkdir_unsupported, + .rename = fs_rename_unsupported, .ln = fs_ln_unsupported, }, #endif @@ -316,6 +329,7 @@ static struct fstype_info fstypes[] = { .opendir = fs_opendir_unsupported, .unlink = fs_unlink_unsupported, .mkdir = fs_mkdir_unsupported, + .rename = fs_rename_unsupported, .ln = fs_ln_unsupported, }, #endif @@ -339,6 +353,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 +375,7 @@ static struct fstype_info fstypes[] = { .ln = fs_ln_unsupported, .unlink = fs_unlink_unsupported, .mkdir = fs_mkdir_unsupported, + .rename = fs_rename_unsupported, }, #endif { @@ -377,6 +393,7 @@ static struct fstype_info fstypes[] = { .opendir = fs_opendir_unsupported, .unlink = fs_unlink_unsupported, .mkdir = fs_mkdir_unsupported, + .rename = fs_rename_unsupported, .ln = fs_ln_unsupported, }, }; @@ -697,6 +714,19 @@ int fs_mkdir(const char *dirname) return ret; } +int fs_rename(const char *old_filename, const char *new_filename) +{ + int ret; + + struct fstype_info *info = fs_get_info(fs_type); + + ret = info->rename(old_filename, new_filename); + + fs_close(); + + return ret; +} + int fs_ln(const char *fname, const char *target) { struct fstype_info *info = fs_get_info(fs_type); diff --git a/include/fs.h b/include/fs.h index 2474880385d..8c1aa9c1a7b 100644 --- a/include/fs.h +++ b/include/fs.h @@ -270,6 +270,15 @@ int fs_unlink(const char *filename); */ int fs_mkdir(const char *filename); +/* + * fs_rename - Rename a file + * + * @old_filename: Name of the file to rename + * @new_filename: New name for the file + * Return: 0 on success, -1 on error conditions + */ +int fs_rename(const char *old_filename, const char *new_filename); + /* * Common implementation for various filesystem commands, optionally limited * to a specific filesystem type via the fstype parameter. -- 2.39.5