fs: add rename infrastructure

The selection for *rename as the name for the rename/move operation
derives from the POSIX specification where they name the function
rename/renameat. [1] This aligns with Linux where the syscalls for
renaming/moving also use the rename/renameat naming.

[1] https://pubs.opengroup.org/onlinepubs/9799919799/functions/rename.html

Signed-off-by: Gabriel Dalimonte <gabriel.dalimonte@gmail.com>
Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
This commit is contained in:
Gabriel Dalimonte
2025-02-17 13:26:43 -05:00
committed by Simon Glass
parent ac6cb92467
commit fa10e79519
2 changed files with 45 additions and 1 deletions

View File

@@ -86,7 +86,7 @@ int fs_set_blk_dev_with_part(struct blk_desc *desc, int part);
*
* Many file functions implicitly call fs_close(), e.g. fs_closedir(),
* fs_exist(), fs_ln(), fs_ls(), fs_mkdir(), fs_read(), fs_size(), fs_write(),
* fs_unlink().
* fs_unlink(), fs_rename().
*/
void fs_close(void);
@@ -270,6 +270,18 @@ int fs_unlink(const char *filename);
*/
int fs_mkdir(const char *filename);
/**
* fs_rename - rename/move 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.
* If this points to a non-empty directory, the rename will fail.
*
* 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.