diff --git a/README.md b/README.md index 9671da0..bcc158d 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ The [share/wut.cmake](share/wut.cmake) file provides several helpers for your bu - `wut_enable_newlib(target)` - Links against the wut implementation of newlib, this is useful for using any function from the C standard library - `wut_enable_stdcpp(target)` - Links against the wut implementation of stdcpp, this is useful for using any function from the C++ standard library. This will call wut_enable_newlib if you have not already done so. - `wut_default_malloc(target)` - By default newlib will allocate 90% of the default heap for use with sbrk & malloc, if this is unacceptable to you then you should use this as it replaces the newlib malloc functions which ones which redirect to the CafeOS default heap functions such as MEMAllocFromDefaultHeap. -- `wut_enable_devoptab_sd(target)` - This links in wutdevoptab_sd which is useful for using the libc file functions with paths such as `fopen("sd:/file.txt", "r")` to read files from the sd card +- `wut_enable_devoptab(target)` - This links in wutdevoptab which is useful for using the libc file functions with paths such as `fopen("sd:/file.txt", "r")` to read files from the sd card A minimal CMakeLists.txt file for a C++ project might look like: ``` diff --git a/libraries/CMakeLists.txt b/libraries/CMakeLists.txt index 25d6dca..4c1b83f 100644 --- a/libraries/CMakeLists.txt +++ b/libraries/CMakeLists.txt @@ -11,7 +11,7 @@ add_subdirectory(libgfd) add_subdirectory(libwhb) add_subdirectory(nn_swkbd) add_subdirectory(wutcrt) -add_subdirectory(wutdevoptab_sd) +add_subdirectory(wutdevoptab) add_subdirectory(wutmalloc) add_subdirectory(wutnewlib) add_subdirectory(wutstdc++) diff --git a/libraries/wutcrt/wut_crt.c b/libraries/wutcrt/wut_crt.c index ad62a10..21b6fa4 100644 --- a/libraries/wutcrt/wut_crt.c +++ b/libraries/wutcrt/wut_crt.c @@ -1,8 +1,8 @@ -extern void __init_wut_devoptab_sd() __attribute__((weak)); extern void __init_wut_newlib() __attribute__((weak)); +extern void __init_wut_devoptab() __attribute__((weak)); extern void __init_wut_stdcpp() __attribute__((weak)); -extern void __fini_wut_devoptab_sd() __attribute__((weak)); +extern void __fini_wut_devoptab() __attribute__((weak)); extern void __fini_wut_newlib() __attribute__((weak)); extern void __fini_wut_stdcpp() __attribute__((weak)); @@ -13,8 +13,8 @@ __init_wut() __init_wut_newlib(); } - if (__init_wut_devoptab_sd) { - __init_wut_devoptab_sd(); + if (__init_wut_devoptab) { + __init_wut_devoptab(); } if (__init_wut_stdcpp) { @@ -29,8 +29,8 @@ __fini_wut() __fini_wut_stdcpp(); } - if (__fini_wut_devoptab_sd) { - __fini_wut_devoptab_sd(); + if (__fini_wut_devoptab) { + __fini_wut_devoptab(); } if (__fini_wut_newlib) { diff --git a/libraries/wutdevoptab/CMakeLists.txt b/libraries/wutdevoptab/CMakeLists.txt new file mode 100644 index 0000000..cdd1f3b --- /dev/null +++ b/libraries/wutdevoptab/CMakeLists.txt @@ -0,0 +1,34 @@ +cmake_minimum_required(VERSION 3.2) +project(wutdevoptab C) + +add_library(wutdevoptab + devoptab_fs.c + devoptab_fs_chdir.c + devoptab_fs_chmod.c + devoptab_fs_close.c + devoptab_fs_dirclose.c + devoptab_fs_dirnext.c + devoptab_fs_diropen.c + devoptab_fs_dirreset.c + devoptab_fs_fchmod.c + devoptab_fs_fstat.c + devoptab_fs_fsync.c + devoptab_fs_getmtime.c + devoptab_fs_link.c + devoptab_fs_mkdir.c + devoptab_fs_open.c + devoptab_fs_read.c + devoptab_fs_rename.c + devoptab_fs_rmdir.c + devoptab_fs_seek.c + devoptab_fs_stat.c + devoptab_fs_statvfs.c + devoptab_fs_truncate.c + devoptab_fs_unlink.c + devoptab_fs_utils.c + devoptab_fs_write.c) + +target_include_directories(wutdevoptab PRIVATE "${WUT_ROOT}/include") + +install(TARGETS wutdevoptab + ARCHIVE DESTINATION "${CMAKE_INSTALL_PREFIX}/lib") diff --git a/libraries/wutdevoptab_sd/devoptab_sd.c b/libraries/wutdevoptab/devoptab_fs.c similarity index 74% rename from libraries/wutdevoptab_sd/devoptab_sd.c rename to libraries/wutdevoptab/devoptab_fs.c index 7677d6f..e40e09b 100644 --- a/libraries/wutdevoptab_sd/devoptab_sd.c +++ b/libraries/wutdevoptab/devoptab_fs.c @@ -1,9 +1,9 @@ -#include "devoptab_sd.h" +#include "devoptab_fs.h" static devoptab_t __wut_fs_devoptab = { - .name = "sd", + .name = "fs", .structSize = sizeof(__wut_fs_file_t), .open_r = __wut_fs_open, .close_r = __wut_fs_close, @@ -29,18 +29,16 @@ __wut_fs_devoptab = .chmod_r = __wut_fs_chmod, .fchmod_r = __wut_fs_fchmod, .rmdir_r = __wut_fs_rmdir, - // .lstat_r - // .utimes_r }; FSClient * -__wut_devoptab_sd_client = NULL; +__wut_devoptab_fs_client = NULL; static BOOL __wut_fs_initialised = FALSE; FSStatus -__init_wut_devoptab_sd() +__init_wut_devoptab() { FSStatus rc = 0; @@ -48,17 +46,17 @@ __init_wut_devoptab_sd() return rc; } - __wut_devoptab_sd_client = memalign(0x20, sizeof(FSClient)); + __wut_devoptab_fs_client = memalign(0x20, sizeof(FSClient)); FSCmdBlock fsCmd; FSMountSource mountSource; char mountPath[0x80]; char workDir[0x83]; FSInit(); - rc = FSAddClient(__wut_devoptab_sd_client, -1); + rc = FSAddClient(__wut_devoptab_fs_client, -1); if (rc < 0) { - free(__wut_devoptab_sd_client); + free(__wut_devoptab_fs_client); return rc; } @@ -72,23 +70,23 @@ __init_wut_devoptab_sd() __wut_fs_initialised = TRUE; // Mount the SD card - rc = FSGetMountSource(__wut_devoptab_sd_client, &fsCmd, FS_MOUNT_SOURCE_SD, &mountSource, -1); + rc = FSGetMountSource(__wut_devoptab_fs_client, &fsCmd, FS_MOUNT_SOURCE_SD, &mountSource, -1); if (rc < 0) { return rc; } - rc = FSMount(__wut_devoptab_sd_client, &fsCmd, &mountSource, mountPath, 0x80, -1); + rc = FSMount(__wut_devoptab_fs_client, &fsCmd, &mountSource, mountPath, 0x80, -1); if (rc >= 0) { // chdir to SD root for general use - strcpy(workDir, "sd:"); + strcpy(workDir, "fs:"); strcat(workDir, mountPath); chdir(workDir); } } else { - FSDelClient(__wut_devoptab_sd_client, -1); - free(__wut_devoptab_sd_client); + FSDelClient(__wut_devoptab_fs_client, -1); + free(__wut_devoptab_fs_client); return dev; } } @@ -97,7 +95,7 @@ __init_wut_devoptab_sd() } FSStatus -__fini_wut_devoptab_sd() +__fini_wut_devoptab() { FSStatus rc = 0; @@ -105,7 +103,7 @@ __fini_wut_devoptab_sd() return rc; } - FSDelClient(__wut_devoptab_sd_client, -1); - free(__wut_devoptab_sd_client); + FSDelClient(__wut_devoptab_fs_client, -1); + free(__wut_devoptab_fs_client); return rc; } diff --git a/libraries/wutdevoptab_sd/devoptab_sd.h b/libraries/wutdevoptab/devoptab_fs.h similarity index 98% rename from libraries/wutdevoptab_sd/devoptab_sd.h rename to libraries/wutdevoptab/devoptab_fs.h index 7a36faa..a1274ed 100644 --- a/libraries/wutdevoptab_sd/devoptab_sd.h +++ b/libraries/wutdevoptab/devoptab_fs.h @@ -46,7 +46,7 @@ typedef struct #define FS_DIRITER_MAGIC 0x77696975 extern FSClient * -__wut_devoptab_sd_client; +__wut_devoptab_fs_client; int __wut_fs_open(struct _reent *r, void *fileStruct, const char *path, int flags, int mode); @@ -78,6 +78,6 @@ int __wut_fs_chmod(struct _reent *r, const char *path, mode_t mode); int __wut_fs_fchmod(struct _reent *r, void *fd, mode_t mode); int __wut_fs_rmdir(struct _reent *r, const char *name); -// devoptab_sd_utils.c +// devoptab_fs_utils.c char * __wut_fs_fixpath(struct _reent *r, const char *path); int __wut_fs_translate_error(FSStatus error); diff --git a/libraries/wutdevoptab_sd/devoptab_sd_chdir.c b/libraries/wutdevoptab/devoptab_fs_chdir.c similarity index 83% rename from libraries/wutdevoptab_sd/devoptab_sd_chdir.c rename to libraries/wutdevoptab/devoptab_fs_chdir.c index 7378c1d..7458909 100644 --- a/libraries/wutdevoptab_sd/devoptab_sd_chdir.c +++ b/libraries/wutdevoptab/devoptab_fs_chdir.c @@ -1,4 +1,4 @@ -#include "devoptab_sd.h" +#include "devoptab_fs.h" int __wut_fs_chdir(struct _reent *r, @@ -21,7 +21,7 @@ __wut_fs_chdir(struct _reent *r, FSCmdBlock fsCmd; FSInitCmdBlock(&fsCmd); - rc = FSChangeDir(__wut_devoptab_sd_client, &fsCmd, path, -1); + rc = FSChangeDir(__wut_devoptab_fs_client, &fsCmd, path, -1); free(path); if (rc >= 0) { diff --git a/libraries/wutdevoptab_sd/devoptab_sd_chmod.c b/libraries/wutdevoptab/devoptab_fs_chmod.c similarity index 83% rename from libraries/wutdevoptab_sd/devoptab_sd_chmod.c rename to libraries/wutdevoptab/devoptab_fs_chmod.c index 7983387..4b891f7 100644 --- a/libraries/wutdevoptab_sd/devoptab_sd_chmod.c +++ b/libraries/wutdevoptab/devoptab_fs_chmod.c @@ -1,4 +1,4 @@ -#include "devoptab_sd.h" +#include "devoptab_fs.h" int __wut_fs_chmod(struct _reent *r, @@ -17,7 +17,7 @@ __wut_fs_chmod(struct _reent *r, FSCmdBlock fsCmd; FSInitCmdBlock(&fsCmd); - rc = FSChangeMode(__wut_devoptab_sd_client, &fsCmd, path_fix, (FSMode)mode, -1); + rc = FSChangeMode(__wut_devoptab_fs_client, &fsCmd, path_fix, (FSMode)mode, -1); free(path_fix); if (rc >= 0) { diff --git a/libraries/wutdevoptab_sd/devoptab_sd_close.c b/libraries/wutdevoptab/devoptab_fs_close.c similarity index 77% rename from libraries/wutdevoptab_sd/devoptab_sd_close.c rename to libraries/wutdevoptab/devoptab_fs_close.c index 0f74505..8ad28fa 100644 --- a/libraries/wutdevoptab_sd/devoptab_sd_close.c +++ b/libraries/wutdevoptab/devoptab_fs_close.c @@ -1,4 +1,4 @@ -#include "devoptab_sd.h" +#include "devoptab_fs.h" int __wut_fs_close(struct _reent *r, @@ -11,7 +11,7 @@ __wut_fs_close(struct _reent *r, FSCmdBlock fsCmd; FSInitCmdBlock(&fsCmd); - rc = FSCloseFile(__wut_devoptab_sd_client, &fsCmd, file->fd, -1); + rc = FSCloseFile(__wut_devoptab_fs_client, &fsCmd, file->fd, -1); if (rc >= 0) { return 0; diff --git a/libraries/wutdevoptab_sd/devoptab_sd_dirclose.c b/libraries/wutdevoptab/devoptab_fs_dirclose.c similarity index 79% rename from libraries/wutdevoptab_sd/devoptab_sd_dirclose.c rename to libraries/wutdevoptab/devoptab_fs_dirclose.c index be3e303..adde150 100644 --- a/libraries/wutdevoptab_sd/devoptab_sd_dirclose.c +++ b/libraries/wutdevoptab/devoptab_fs_dirclose.c @@ -1,4 +1,4 @@ -#include "devoptab_sd.h" +#include "devoptab_fs.h" int __wut_fs_dirclose(struct _reent *r, @@ -11,7 +11,7 @@ __wut_fs_dirclose(struct _reent *r, FSInitCmdBlock(&fsCmd); __wut_fs_dir_t *dir = (__wut_fs_dir_t *)(dirState->dirStruct); - rc = FSCloseDir(__wut_devoptab_sd_client, &fsCmd, dir->fd, -1); + rc = FSCloseDir(__wut_devoptab_fs_client, &fsCmd, dir->fd, -1); if (rc >= 0) { return 0; diff --git a/libraries/wutdevoptab_sd/devoptab_sd_dirnext.c b/libraries/wutdevoptab/devoptab_fs_dirnext.c similarity index 92% rename from libraries/wutdevoptab_sd/devoptab_sd_dirnext.c rename to libraries/wutdevoptab/devoptab_fs_dirnext.c index 200a127..1b01306 100644 --- a/libraries/wutdevoptab_sd/devoptab_sd_dirnext.c +++ b/libraries/wutdevoptab/devoptab_fs_dirnext.c @@ -1,4 +1,4 @@ -#include "devoptab_sd.h" +#include "devoptab_fs.h" int __wut_fs_dirnext(struct _reent *r, @@ -15,7 +15,7 @@ __wut_fs_dirnext(struct _reent *r, // Fetch the next dir memset(&dir->entry_data, 0, sizeof(dir->entry_data)); - rc = FSReadDir(__wut_devoptab_sd_client, &fsCmd, dir->fd, &dir->entry_data, -1); + rc = FSReadDir(__wut_devoptab_fs_client, &fsCmd, dir->fd, &dir->entry_data, -1); if (rc < 0) { // There are no more entries; ENOENT signals end-of-directory diff --git a/libraries/wutdevoptab_sd/devoptab_sd_diropen.c b/libraries/wutdevoptab/devoptab_fs_diropen.c similarity index 89% rename from libraries/wutdevoptab_sd/devoptab_sd_diropen.c rename to libraries/wutdevoptab/devoptab_fs_diropen.c index 950653d..2af0ea3 100644 --- a/libraries/wutdevoptab_sd/devoptab_sd_diropen.c +++ b/libraries/wutdevoptab/devoptab_fs_diropen.c @@ -1,4 +1,4 @@ -#include "devoptab_sd.h" +#include "devoptab_fs.h" DIR_ITER * __wut_fs_diropen(struct _reent *r, @@ -24,7 +24,7 @@ __wut_fs_diropen(struct _reent *r, FSInitCmdBlock(&fsCmd); __wut_fs_dir_t *dir = (__wut_fs_dir_t *)(dirState->dirStruct); - rc = FSOpenDir(__wut_devoptab_sd_client, &fsCmd, path_fixed, &fd, -1); + rc = FSOpenDir(__wut_devoptab_fs_client, &fsCmd, path_fixed, &fd, -1); if (rc >= 0) { dir->magic = FS_DIRITER_MAGIC; diff --git a/libraries/wutdevoptab_sd/devoptab_sd_dirreset.c b/libraries/wutdevoptab/devoptab_fs_dirreset.c similarity index 79% rename from libraries/wutdevoptab_sd/devoptab_sd_dirreset.c rename to libraries/wutdevoptab/devoptab_fs_dirreset.c index ab7b1b4..36d3384 100644 --- a/libraries/wutdevoptab_sd/devoptab_sd_dirreset.c +++ b/libraries/wutdevoptab/devoptab_fs_dirreset.c @@ -1,4 +1,4 @@ -#include "devoptab_sd.h" +#include "devoptab_fs.h" int __wut_fs_dirreset(struct _reent *r, @@ -11,7 +11,7 @@ __wut_fs_dirreset(struct _reent *r, FSInitCmdBlock(&fsCmd); __wut_fs_dir_t *dir = (__wut_fs_dir_t *)(dirState->dirStruct); - rc = FSRewindDir(__wut_devoptab_sd_client, &fsCmd, dir->fd, -1); + rc = FSRewindDir(__wut_devoptab_fs_client, &fsCmd, dir->fd, -1); if (rc >= 0) { return 0; diff --git a/libraries/wutdevoptab_sd/devoptab_sd_fchmod.c b/libraries/wutdevoptab/devoptab_fs_fchmod.c similarity index 87% rename from libraries/wutdevoptab_sd/devoptab_sd_fchmod.c rename to libraries/wutdevoptab/devoptab_fs_fchmod.c index 0579ba8..ecab35a 100644 --- a/libraries/wutdevoptab_sd/devoptab_sd_fchmod.c +++ b/libraries/wutdevoptab/devoptab_fs_fchmod.c @@ -1,4 +1,4 @@ -#include "devoptab_sd.h" +#include "devoptab_fs.h" int __wut_fs_fchmod(struct _reent *r, diff --git a/libraries/wutdevoptab_sd/devoptab_sd_fstat.c b/libraries/wutdevoptab/devoptab_fs_fstat.c similarity index 86% rename from libraries/wutdevoptab_sd/devoptab_sd_fstat.c rename to libraries/wutdevoptab/devoptab_fs_fstat.c index f1da0fa..4da5021 100644 --- a/libraries/wutdevoptab_sd/devoptab_sd_fstat.c +++ b/libraries/wutdevoptab/devoptab_fs_fstat.c @@ -1,4 +1,4 @@ -#include "devoptab_sd.h" +#include "devoptab_fs.h" int __wut_fs_fstat(struct _reent *r, @@ -13,7 +13,7 @@ __wut_fs_fstat(struct _reent *r, FSCmdBlock fsCmd; FSInitCmdBlock(&fsCmd); - rc = FSGetStatFile(__wut_devoptab_sd_client, &fsCmd, file->fd, &fsstat, -1); + rc = FSGetStatFile(__wut_devoptab_fs_client, &fsCmd, file->fd, &fsstat, -1); if (rc >= 0) { memset(st, 0, sizeof(struct stat)); diff --git a/libraries/wutdevoptab_sd/devoptab_sd_fsync.c b/libraries/wutdevoptab/devoptab_fs_fsync.c similarity index 77% rename from libraries/wutdevoptab_sd/devoptab_sd_fsync.c rename to libraries/wutdevoptab/devoptab_fs_fsync.c index da0e35d..76bc8e5 100644 --- a/libraries/wutdevoptab_sd/devoptab_sd_fsync.c +++ b/libraries/wutdevoptab/devoptab_fs_fsync.c @@ -1,4 +1,4 @@ -#include "devoptab_sd.h" +#include "devoptab_fs.h" int __wut_fs_fsync(struct _reent *r, @@ -11,7 +11,7 @@ __wut_fs_fsync(struct _reent *r, FSCmdBlock fsCmd; FSInitCmdBlock(&fsCmd); - rc = FSFlushFile(__wut_devoptab_sd_client, &fsCmd, file->fd, -1); + rc = FSFlushFile(__wut_devoptab_fs_client, &fsCmd, file->fd, -1); if (rc >= 0) { return 0; diff --git a/libraries/wutdevoptab_sd/devoptab_sd_getmtime.c b/libraries/wutdevoptab/devoptab_fs_getmtime.c similarity index 86% rename from libraries/wutdevoptab_sd/devoptab_sd_getmtime.c rename to libraries/wutdevoptab/devoptab_fs_getmtime.c index c283b8e..c590b74 100644 --- a/libraries/wutdevoptab_sd/devoptab_sd_getmtime.c +++ b/libraries/wutdevoptab/devoptab_fs_getmtime.c @@ -1,4 +1,4 @@ -#include "devoptab_sd.h" +#include "devoptab_fs.h" int __wut_fs_getmtime(const char *name, diff --git a/libraries/wutdevoptab_sd/devoptab_sd_link.c b/libraries/wutdevoptab/devoptab_fs_link.c similarity index 85% rename from libraries/wutdevoptab_sd/devoptab_sd_link.c rename to libraries/wutdevoptab/devoptab_fs_link.c index edb8c6c..da772fe 100644 --- a/libraries/wutdevoptab_sd/devoptab_sd_link.c +++ b/libraries/wutdevoptab/devoptab_fs_link.c @@ -1,4 +1,4 @@ -#include "devoptab_sd.h" +#include "devoptab_fs.h" int __wut_fs_link(struct _reent *r, diff --git a/libraries/wutdevoptab_sd/devoptab_sd_mkdir.c b/libraries/wutdevoptab/devoptab_fs_mkdir.c similarity index 87% rename from libraries/wutdevoptab_sd/devoptab_sd_mkdir.c rename to libraries/wutdevoptab/devoptab_fs_mkdir.c index d5a7bfb..9bdc331 100644 --- a/libraries/wutdevoptab_sd/devoptab_sd_mkdir.c +++ b/libraries/wutdevoptab/devoptab_fs_mkdir.c @@ -1,4 +1,4 @@ -#include "devoptab_sd.h" +#include "devoptab_fs.h" int __wut_fs_mkdir(struct _reent *r, @@ -23,7 +23,7 @@ __wut_fs_mkdir(struct _reent *r, FSInitCmdBlock(&fsCmd); // TODO: Use mode to set directory attributes. - rc = FSMakeDir(__wut_devoptab_sd_client, &fsCmd, path_fix, -1); + rc = FSMakeDir(__wut_devoptab_fs_client, &fsCmd, path_fix, -1); free(path_fix); if (rc == FS_ERROR_ALREADY_EXISTS) { diff --git a/libraries/wutdevoptab_sd/devoptab_sd_open.c b/libraries/wutdevoptab/devoptab_fs_open.c similarity index 89% rename from libraries/wutdevoptab_sd/devoptab_sd_open.c rename to libraries/wutdevoptab/devoptab_fs_open.c index a24afe9..813e219 100644 --- a/libraries/wutdevoptab_sd/devoptab_sd_open.c +++ b/libraries/wutdevoptab/devoptab_fs_open.c @@ -1,4 +1,4 @@ -#include "devoptab_sd.h" +#include "devoptab_fs.h" int __wut_fs_open(struct _reent *r, @@ -48,12 +48,12 @@ __wut_fs_open(struct _reent *r, FSInitCmdBlock(&fsCmd); // Open the file - rc = FSOpenFile(__wut_devoptab_sd_client, &fsCmd, path_fixed, fs_mode, &fd, -1); + rc = FSOpenFile(__wut_devoptab_fs_client, &fsCmd, path_fixed, fs_mode, &fd, -1); if (rc >= 0) { file->fd = fd; file->flags = (flags & (O_ACCMODE|O_APPEND|O_SYNC)); - FSGetPosFile(__wut_devoptab_sd_client, &fsCmd, fd, &file->offset, -1); + FSGetPosFile(__wut_devoptab_fs_client, &fsCmd, fd, &file->offset, -1); free(path_fixed); return 0; } diff --git a/libraries/wutdevoptab_sd/devoptab_sd_read.c b/libraries/wutdevoptab/devoptab_fs_read.c similarity index 89% rename from libraries/wutdevoptab_sd/devoptab_sd_read.c rename to libraries/wutdevoptab/devoptab_fs_read.c index 00a09fb..e17c886 100644 --- a/libraries/wutdevoptab_sd/devoptab_sd_read.c +++ b/libraries/wutdevoptab/devoptab_fs_read.c @@ -1,4 +1,4 @@ -#include "devoptab_sd.h" +#include "devoptab_fs.h" ssize_t __wut_fs_read(struct _reent *r, @@ -21,7 +21,7 @@ __wut_fs_read(struct _reent *r, FSInitCmdBlock(&fsCmd); FSStat fsstat; - rc = FSGetStatFile(__wut_devoptab_sd_client, &fsCmd, file->fd, &fsstat, -1); + rc = FSGetStatFile(__wut_devoptab_fs_client, &fsCmd, file->fd, &fsstat, -1); if(rc < 0) { r->_errno = __wut_fs_translate_error(rc); @@ -39,7 +39,7 @@ __wut_fs_read(struct _reent *r, } // Write the data - rc = FSReadFile(__wut_devoptab_sd_client, &fsCmd, tmp_buffer, 1, toRead, file->fd, 0, -1); + rc = FSReadFile(__wut_devoptab_fs_client, &fsCmd, tmp_buffer, 1, toRead, file->fd, 0, -1); if(rc <= 0) { diff --git a/libraries/wutdevoptab_sd/devoptab_sd_rename.c b/libraries/wutdevoptab/devoptab_fs_rename.c similarity index 88% rename from libraries/wutdevoptab_sd/devoptab_sd_rename.c rename to libraries/wutdevoptab/devoptab_fs_rename.c index 09d266a..3d13715 100644 --- a/libraries/wutdevoptab_sd/devoptab_sd_rename.c +++ b/libraries/wutdevoptab/devoptab_fs_rename.c @@ -1,4 +1,4 @@ -#include "devoptab_sd.h" +#include "devoptab_fs.h" int __wut_fs_rename(struct _reent *r, @@ -33,7 +33,7 @@ __wut_fs_rename(struct _reent *r, FSCmdBlock fsCmd; FSInitCmdBlock(&fsCmd); - rc = FSRename(__wut_devoptab_sd_client, &fsCmd, path_old, path_new, -1); + rc = FSRename(__wut_devoptab_fs_client, &fsCmd, path_old, path_new, -1); free(path_old); free(path_new); diff --git a/libraries/wutdevoptab_sd/devoptab_sd_rmdir.c b/libraries/wutdevoptab/devoptab_fs_rmdir.c similarity index 83% rename from libraries/wutdevoptab_sd/devoptab_sd_rmdir.c rename to libraries/wutdevoptab/devoptab_fs_rmdir.c index c72b609..32e98c1 100644 --- a/libraries/wutdevoptab_sd/devoptab_sd_rmdir.c +++ b/libraries/wutdevoptab/devoptab_fs_rmdir.c @@ -1,4 +1,4 @@ -#include "devoptab_sd.h" +#include "devoptab_fs.h" int __wut_fs_rmdir(struct _reent *r, @@ -21,7 +21,7 @@ __wut_fs_rmdir(struct _reent *r, FSCmdBlock fsCmd; FSInitCmdBlock(&fsCmd); - rc = FSRemove(__wut_devoptab_sd_client, &fsCmd, path_fix, -1); + rc = FSRemove(__wut_devoptab_fs_client, &fsCmd, path_fix, -1); free(path_fix); if (rc >= 0) { diff --git a/libraries/wutdevoptab_sd/devoptab_sd_seek.c b/libraries/wutdevoptab/devoptab_fs_seek.c similarity index 89% rename from libraries/wutdevoptab_sd/devoptab_sd_seek.c rename to libraries/wutdevoptab/devoptab_fs_seek.c index b1629f7..740da48 100644 --- a/libraries/wutdevoptab_sd/devoptab_sd_seek.c +++ b/libraries/wutdevoptab/devoptab_fs_seek.c @@ -1,4 +1,4 @@ -#include "devoptab_sd.h" +#include "devoptab_fs.h" off_t __wut_fs_seek(struct _reent *r, @@ -15,7 +15,7 @@ __wut_fs_seek(struct _reent *r, FSInitCmdBlock(&fsCmd); FSStat fsstat; - rc = FSGetStatFile(__wut_devoptab_sd_client, &fsCmd, file->fd, &fsstat, -1); + rc = FSGetStatFile(__wut_devoptab_fs_client, &fsCmd, file->fd, &fsstat, -1); if (rc < 0) { r->_errno = __wut_fs_translate_error(rc); @@ -54,7 +54,7 @@ __wut_fs_seek(struct _reent *r, // Update the current offset file->offset = offset + pos; - FSStatus result = FSSetPosFile(__wut_devoptab_sd_client, &fsCmd, file->fd, file->offset, -1); + FSStatus result = FSSetPosFile(__wut_devoptab_fs_client, &fsCmd, file->fd, file->offset, -1); if (result < 0) { return result; diff --git a/libraries/wutdevoptab_sd/devoptab_sd_stat.c b/libraries/wutdevoptab/devoptab_fs_stat.c similarity index 72% rename from libraries/wutdevoptab_sd/devoptab_sd_stat.c rename to libraries/wutdevoptab/devoptab_fs_stat.c index d37ee48..472eeaf 100644 --- a/libraries/wutdevoptab_sd/devoptab_sd_stat.c +++ b/libraries/wutdevoptab/devoptab_fs_stat.c @@ -1,4 +1,4 @@ -#include "devoptab_sd.h" +#include "devoptab_fs.h" int __wut_fs_stat(struct _reent *r, @@ -17,23 +17,23 @@ __wut_fs_stat(struct _reent *r, FSInitCmdBlock(&fsCmd); // First try open as file - rc = FSOpenFile(__wut_devoptab_sd_client, &fsCmd, file, "r", (FSFileHandle*)&fd, -1); + rc = FSOpenFile(__wut_devoptab_fs_client, &fsCmd, file, "r", (FSFileHandle*)&fd, -1); if (rc >= 0) { __wut_fs_file_t tmpfd = { .fd = fd }; rc = __wut_fs_fstat(r, &tmpfd, st); - FSCloseFile(__wut_devoptab_sd_client, &fsCmd, fd, -1); + FSCloseFile(__wut_devoptab_fs_client, &fsCmd, fd, -1); return rc; } // File failed, so lets try open as directory - rc = FSOpenDir(__wut_devoptab_sd_client, &fsCmd, file, (FSDirectoryHandle*)&fd, -1); + rc = FSOpenDir(__wut_devoptab_fs_client, &fsCmd, file, (FSDirectoryHandle*)&fd, -1); if (rc >= 0) { memset(st, 0, sizeof(struct stat)); st->st_nlink = 1; st->st_mode = S_IFDIR | S_IRWXU | S_IRWXG | S_IRWXO; - FSCloseDir(__wut_devoptab_sd_client, &fsCmd, fd, -1); + FSCloseDir(__wut_devoptab_fs_client, &fsCmd, fd, -1); return 0; } diff --git a/libraries/wutdevoptab_sd/devoptab_sd_statvfs.c b/libraries/wutdevoptab/devoptab_fs_statvfs.c similarity index 93% rename from libraries/wutdevoptab_sd/devoptab_sd_statvfs.c rename to libraries/wutdevoptab/devoptab_fs_statvfs.c index b823b23..6eddd2f 100644 --- a/libraries/wutdevoptab_sd/devoptab_sd_statvfs.c +++ b/libraries/wutdevoptab/devoptab_fs_statvfs.c @@ -1,4 +1,4 @@ -#include "devoptab_sd.h" +#include "devoptab_fs.h" int __wut_fs_statvfs(struct _reent *r, diff --git a/libraries/wutdevoptab_sd/devoptab_sd_truncate.c b/libraries/wutdevoptab/devoptab_fs_truncate.c similarity index 77% rename from libraries/wutdevoptab_sd/devoptab_sd_truncate.c rename to libraries/wutdevoptab/devoptab_fs_truncate.c index d776f0c..5c546c9 100644 --- a/libraries/wutdevoptab_sd/devoptab_sd_truncate.c +++ b/libraries/wutdevoptab/devoptab_fs_truncate.c @@ -1,4 +1,4 @@ -#include "devoptab_sd.h" +#include "devoptab_fs.h" int __wut_fs_ftruncate(struct _reent *r, @@ -19,13 +19,13 @@ __wut_fs_ftruncate(struct _reent *r, FSInitCmdBlock(&fsCmd); // Set the new file size - rc = FSSetPosFile(__wut_devoptab_sd_client, &fsCmd, file->fd, len, -1); + rc = FSSetPosFile(__wut_devoptab_fs_client, &fsCmd, file->fd, len, -1); if (rc >= 0) { return 0; } - rc = FSTruncateFile(__wut_devoptab_sd_client, &fsCmd, file->fd, -1); + rc = FSTruncateFile(__wut_devoptab_fs_client, &fsCmd, file->fd, -1); if (rc >= 0) { return 0; diff --git a/libraries/wutdevoptab_sd/devoptab_sd_unlink.c b/libraries/wutdevoptab/devoptab_fs_unlink.c similarity index 83% rename from libraries/wutdevoptab_sd/devoptab_sd_unlink.c rename to libraries/wutdevoptab/devoptab_fs_unlink.c index 7cb0f5c..ce5a40b 100644 --- a/libraries/wutdevoptab_sd/devoptab_sd_unlink.c +++ b/libraries/wutdevoptab/devoptab_fs_unlink.c @@ -1,4 +1,4 @@ -#include "devoptab_sd.h" +#include "devoptab_fs.h" int __wut_fs_unlink(struct _reent *r, @@ -21,7 +21,7 @@ __wut_fs_unlink(struct _reent *r, FSCmdBlock fsCmd; FSInitCmdBlock(&fsCmd); - rc = FSRemove(__wut_devoptab_sd_client, &fsCmd, path_fix, -1); + rc = FSRemove(__wut_devoptab_fs_client, &fsCmd, path_fix, -1); free(path_fix); if (rc >= 0) { diff --git a/libraries/wutdevoptab_sd/devoptab_fs_utils.c b/libraries/wutdevoptab/devoptab_fs_utils.c similarity index 97% rename from libraries/wutdevoptab_sd/devoptab_fs_utils.c rename to libraries/wutdevoptab/devoptab_fs_utils.c index 1200acd..7c126ad 100644 --- a/libraries/wutdevoptab_sd/devoptab_fs_utils.c +++ b/libraries/wutdevoptab/devoptab_fs_utils.c @@ -1,4 +1,4 @@ -#include "devoptab_sd.h" +#include "devoptab_fs.h" char * __wut_fs_fixpath(struct _reent *r, diff --git a/libraries/wutdevoptab_sd/devoptab_sd_write.c b/libraries/wutdevoptab/devoptab_fs_write.c similarity index 93% rename from libraries/wutdevoptab_sd/devoptab_sd_write.c rename to libraries/wutdevoptab/devoptab_fs_write.c index 5edaa87..62161f0 100644 --- a/libraries/wutdevoptab_sd/devoptab_sd_write.c +++ b/libraries/wutdevoptab/devoptab_fs_write.c @@ -1,4 +1,4 @@ -#include "devoptab_sd.h" +#include "devoptab_fs.h" ssize_t __wut_fs_write(struct _reent *r, @@ -34,7 +34,7 @@ __wut_fs_write(struct _reent *r, FSInitCmdBlock(&fsCmd); // Write the data - rc = FSWriteFile(__wut_devoptab_sd_client, &fsCmd, tmp_buffer, 1, toWrite, file->fd, 0, -1); + rc = FSWriteFile(__wut_devoptab_fs_client, &fsCmd, tmp_buffer, 1, toWrite, file->fd, 0, -1); if (rc < 0) { free(tmp_buffer); diff --git a/libraries/wutdevoptab_sd/CMakeLists.txt b/libraries/wutdevoptab_sd/CMakeLists.txt deleted file mode 100644 index 3d0b4b0..0000000 --- a/libraries/wutdevoptab_sd/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -cmake_minimum_required(VERSION 3.2) -project(wutdevoptab_sd C) - -add_library(wutdevoptab_sd - devoptab_sd.c - devoptab_sd_chdir.c - devoptab_sd_chmod.c - devoptab_sd_close.c - devoptab_sd_dirclose.c - devoptab_sd_dirnext.c - devoptab_sd_diropen.c - devoptab_sd_dirreset.c - devoptab_sd_fchmod.c - devoptab_sd_fstat.c - devoptab_sd_fsync.c - devoptab_sd_getmtime.c - devoptab_sd_link.c - devoptab_sd_mkdir.c - devoptab_sd_open.c - devoptab_sd_read.c - devoptab_sd_rename.c - devoptab_sd_rmdir.c - devoptab_sd_seek.c - devoptab_sd_stat.c - devoptab_sd_statvfs.c - devoptab_sd_truncate.c - devoptab_sd_unlink.c - devoptab_sd_utils.c - devoptab_sd_write.c) - -target_include_directories(wutdevoptab_sd PRIVATE "${WUT_ROOT}/include") - -install(TARGETS wutdevoptab_sd - ARCHIVE DESTINATION "${CMAKE_INSTALL_PREFIX}/lib") diff --git a/libraries/wutdevoptab_sd/devoptab_sd_utils.c b/libraries/wutdevoptab_sd/devoptab_sd_utils.c deleted file mode 100644 index cbcfd68..0000000 --- a/libraries/wutdevoptab_sd/devoptab_sd_utils.c +++ /dev/null @@ -1,47 +0,0 @@ -#include "devoptab_sd.h" - -char * -__wut_fs_fixpath(struct _reent *r, - const char *path) -{ - char *p = strchr(path, ':')+1; - - if(!strchr(path, ':')) { - p = (char*)path; - } - - if (strlen(p) > PATH_MAX) { - r->_errno = ENAMETOOLONG; - return NULL; - } - - char *__fixedpath = memalign(0x40, PATH_MAX+1); - - if (__fixedpath == NULL) { - return NULL; - } - - // cwd is handled by coreinit, so just strip the 'fs:' if it exists - strcpy(__fixedpath, p); - return __fixedpath; -} - -int -__wut_fs_translate_error(FSStatus error) -{ - switch (error) { - case FS_STATUS_CANCELLED: - return EINVAL; - case FS_STATUS_EXISTS: - return EEXIST; - case FS_STATUS_NOT_FOUND: - return ENOENT; - case FS_STATUS_STORAGE_FULL: - return ENOSPC; - case FS_ERROR_INVALID_PATH: - return ENAMETOOLONG; - default: - return (int)error; - } -} - diff --git a/share/wut.cmake b/share/wut.cmake index cdcc0f8..37cd3e7 100644 --- a/share/wut.cmake +++ b/share/wut.cmake @@ -25,14 +25,14 @@ macro(wut_enable_stdcpp target) endif() endmacro() -# Links against devoptab_sd -macro(wut_enable_devoptab_sd target) - get_property(ENABLED_DEVOPTAB_SD TARGET ${target} PROPERTY WUT_ENABLE_DEVOPTAB_SD) - if(NOT DEFINED ENABLED_DEVOPTAB_SD) +# Links against devoptab +macro(wut_enable_devoptab target) + get_property(ENABLED_DEVOPTAB TARGET ${target} PROPERTY WUT_ENABLE_DEVOPTAB) + if(NOT DEFINED ENABLED_DEVOPTAB) target_link_libraries(${target} - -Wl,--whole-archive wutdevoptab_sd -Wl,--no-whole-archive) + -Wl,--whole-archive wutdevoptab -Wl,--no-whole-archive) - set_target_properties(${target} PROPERTIES WUT_ENABLE_DEVOPTAB_SD 1) + set_target_properties(${target} PROPERTIES WUT_ENABLE_DEVOPTAB 1) endif() endmacro()