diff --git a/CMakeLists.txt b/CMakeLists.txt index 71869e0..1b9fe08 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,7 @@ set(SOURCES_COMMON src/fs/pwrite.c src/fs/read.c src/fs/readdir.c + src/fs/rename.c src/fs/rewinddir.c src/fs/rmdir.c src/fs/seekdir.c @@ -64,6 +65,7 @@ set(SOURCES_COMMON src/fs/fugue/fugue_open.c src/fs/fugue/fugue_mkdir.c src/fs/fugue/fugue_stat.c + src/fs/fugue/fugue_rename.c src/fs/fugue/fugue_rmdir.c src/fs/fugue/fugue_unlink.c src/fs/fugue/util.c diff --git a/include/gint/bfile.h b/include/gint/bfile.h index 9008c6c..fecab0e 100644 --- a/include/gint/bfile.h +++ b/include/gint/bfile.h @@ -73,6 +73,9 @@ extern "C" { /* Remove a file or folder (also works if the entry does not exist). */ int BFile_Remove(uint16_t const *path); +/* Rename a file (can move folders; Fugue only). */ +int BFile_Rename(uint16_t const *oldpath, uint16_t const *newpath); + #define BFile_File 1 #define BFile_Folder 5 diff --git a/src/fs/fugue/fugue.h b/src/fs/fugue/fugue.h index 1a4d4d8..54e659c 100644 --- a/src/fs/fugue/fugue.h +++ b/src/fs/fugue/fugue.h @@ -25,6 +25,8 @@ int fugue_open(char const *path, int flags, mode_t mode); int fugue_unlink(char const *path); +int fugue_rename(char const *oldpath, char const *newpath); + int fugue_mkdir(char const *path, mode_t mode); int fugue_rmdir(char const *path); diff --git a/src/fs/fugue/fugue_rename.c b/src/fs/fugue/fugue_rename.c new file mode 100644 index 0000000..6eaded6 --- /dev/null +++ b/src/fs/fugue/fugue_rename.c @@ -0,0 +1,38 @@ +#include +#include +#include +#include +#include +#include "util.h" + +int fugue_rename(char const *oldpath, char const *newpath) +{ + ENOTSUP_IF_NOT_FUGUE(-1); + int rc = -1; + + uint16_t *fcpath_1 = NULL; + uint16_t *fcpath_2 = NULL; + + fcpath_1 = fs_path_normalize_fc(oldpath); + if(!fcpath_1) { + errno = ENOMEM; + goto end; + } + fcpath_2 = fs_path_normalize_fc(newpath); + if(!fcpath_2) { + errno = ENOMEM; + goto end; + } + + rc = BFile_Rename(fcpath_1, fcpath_2); + if(rc < 0) { + errno = bfile_error_to_errno(rc); + rc = -1; + } + else rc = 0; + +end: + free(fcpath_1); + free(fcpath_2); + return rc; +} diff --git a/src/fs/rename.c b/src/fs/rename.c new file mode 100644 index 0000000..3c20b88 --- /dev/null +++ b/src/fs/rename.c @@ -0,0 +1,8 @@ +#include +#include "fugue/fugue.h" + +int rename(char const *oldpath, char const *newpath) +{ + /* Standard rename() is the Fugue filesystem only */ + return fugue_rename(oldpath, newpath); +} diff --git a/src/kernel/syscalls.S b/src/kernel/syscalls.S index 7a489d4..12b0325 100644 --- a/src/kernel/syscalls.S +++ b/src/kernel/syscalls.S @@ -19,6 +19,7 @@ /* Bfile driver */ .global _BFile_Remove +.global _BFile_Rename .global _BFile_Create .global _BFile_Open .global _BFile_Close @@ -131,6 +132,8 @@ ___realloc: _BFile_Remove: syscall(0x1db4) +_BFile_Rename: + syscall(0x1db3) _BFile_Create: syscall(0x1dae) _BFile_Open: