fs: add rename() function on fx-CG

This commit is contained in:
Lephe 2022-08-22 15:25:14 +02:00
parent 4f9b141b79
commit 9924dc4684
No known key found for this signature in database
GPG key ID: 1BBA026E13FC0495
6 changed files with 56 additions and 0 deletions

View file

@ -50,6 +50,7 @@ set(SOURCES_COMMON
src/fs/pwrite.c src/fs/pwrite.c
src/fs/read.c src/fs/read.c
src/fs/readdir.c src/fs/readdir.c
src/fs/rename.c
src/fs/rewinddir.c src/fs/rewinddir.c
src/fs/rmdir.c src/fs/rmdir.c
src/fs/seekdir.c src/fs/seekdir.c
@ -64,6 +65,7 @@ set(SOURCES_COMMON
src/fs/fugue/fugue_open.c src/fs/fugue/fugue_open.c
src/fs/fugue/fugue_mkdir.c src/fs/fugue/fugue_mkdir.c
src/fs/fugue/fugue_stat.c src/fs/fugue/fugue_stat.c
src/fs/fugue/fugue_rename.c
src/fs/fugue/fugue_rmdir.c src/fs/fugue/fugue_rmdir.c
src/fs/fugue/fugue_unlink.c src/fs/fugue/fugue_unlink.c
src/fs/fugue/util.c src/fs/fugue/util.c

View file

@ -73,6 +73,9 @@ extern "C" {
/* Remove a file or folder (also works if the entry does not exist). */ /* Remove a file or folder (also works if the entry does not exist). */
int BFile_Remove(uint16_t const *path); 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_File 1
#define BFile_Folder 5 #define BFile_Folder 5

View file

@ -25,6 +25,8 @@ int fugue_open(char const *path, int flags, mode_t mode);
int fugue_unlink(char const *path); 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_mkdir(char const *path, mode_t mode);
int fugue_rmdir(char const *path); int fugue_rmdir(char const *path);

View file

@ -0,0 +1,38 @@
#include <gint/hardware.h>
#include <gint/bfile.h>
#include <gint/fs.h>
#include <errno.h>
#include <sys/stat.h>
#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;
}

8
src/fs/rename.c Normal file
View file

@ -0,0 +1,8 @@
#include <stdio.h>
#include "fugue/fugue.h"
int rename(char const *oldpath, char const *newpath)
{
/* Standard rename() is the Fugue filesystem only */
return fugue_rename(oldpath, newpath);
}

View file

@ -19,6 +19,7 @@
/* Bfile driver */ /* Bfile driver */
.global _BFile_Remove .global _BFile_Remove
.global _BFile_Rename
.global _BFile_Create .global _BFile_Create
.global _BFile_Open .global _BFile_Open
.global _BFile_Close .global _BFile_Close
@ -131,6 +132,8 @@ ___realloc:
_BFile_Remove: _BFile_Remove:
syscall(0x1db4) syscall(0x1db4)
_BFile_Rename:
syscall(0x1db3)
_BFile_Create: _BFile_Create:
syscall(0x1dae) syscall(0x1dae)
_BFile_Open: _BFile_Open: