From ecbc77840e4af96e19a2ef837c8cb9c3b6e431e3 Mon Sep 17 00:00:00 2001 From: fincs Date: Sat, 21 Sep 2019 19:54:21 +0200 Subject: [PATCH] fs: Update names of enum/flag types for style consistency and correctness --- nx/include/switch/services/fs.h | 59 +++++++++++++++------------ nx/source/runtime/devices/fs_dev.c | 38 ++++++++--------- nx/source/runtime/devices/romfs_dev.c | 6 +-- nx/source/services/fs.c | 16 ++++---- 4 files changed, 62 insertions(+), 57 deletions(-) diff --git a/nx/include/switch/services/fs.h b/nx/include/switch/services/fs.h index 16cd8b7e..fd3ff8aa 100644 --- a/nx/include/switch/services/fs.h +++ b/nx/include/switch/services/fs.h @@ -58,7 +58,7 @@ typedef struct { char name[FS_MAX_PATH]; ///< Entry name. u8 pad[3]; - s8 type; ///< See FsEntryType. + s8 type; ///< See FsDirEntryType. u8 pad2[3]; ///< ? u64 fileSize; ///< File size. } FsDirectoryEntry; @@ -127,40 +127,45 @@ typedef struct u8 padding[7]; } FsTimeStampRaw; +/// Returned by fsFsGetEntryType. typedef enum { - ENTRYTYPE_DIR = 0, - ENTRYTYPE_FILE = 1, -} FsEntryType; + FsDirEntryType_Dir = 0, ///< Entry is a directory. + FsDirEntryType_File = 1, ///< Entry is a file. +} FsDirEntryType; +/// For use with fsFsOpenFile. typedef enum { - FS_OPEN_READ = BIT(0), ///< Open for reading. - FS_OPEN_WRITE = BIT(1), ///< Open for writing. - FS_OPEN_APPEND = BIT(2), ///< Append file. -} FsFileFlags; + FsOpenMode_Read = BIT(0), ///< Open for reading. + FsOpenMode_Write = BIT(1), ///< Open for writing. + FsOpenMode_Append = BIT(2), ///< Append file. +} FsOpenMode; +/// For use with fsFsCreateFile. typedef enum { - FS_CREATE_BIG_FILE = BIT(0), ///< Creates a ConcatenationFile (dir with archive bit) instead of file. -} FsFileCreateFlags; + FsCreateOption_BigFile = BIT(0), ///< Creates a ConcatenationFile (dir with archive bit) instead of file. +} FsCreateOption; /// For use with fsFsOpenDirectory. typedef enum { - FS_DIROPEN_DIRECTORY = BIT(0), ///< Enable reading directory entries. - FS_DIROPEN_FILE = BIT(1), ///< Enable reading file entries. - FS_DIROPEN_NO_FILE_SIZE = BIT(31), ///< Causes result entries to not contain filesize information (always 0). -} FsDirectoryFlags; + FsDirOpenMode_ReadDirs = BIT(0), ///< Enable reading directory entries. + FsDirOpenMode_ReadFiles = BIT(1), ///< Enable reading file entries. + FsDirOpenMode_NoFileSize = BIT(31), ///< Causes result entries to not contain filesize information (always 0). +} FsDirOpenMode; +/// For use with fsFileRead. typedef enum { - FS_READOPTION_NONE = 0, ///< No Option. + FsReadOption_None = 0, ///< No option. } FsReadOption; +/// For use with fsFileWrite. typedef enum { - FS_WRITEOPTION_NONE = 0, ///< No option. - FS_WRITEOPTION_FLUSH = BIT(0), ///< Forces a flush after write. + FsWriteOption_None = 0, ///< No option. + FsWriteOption_Flush = BIT(0), ///< Forces a flush after write. } FsWriteOption; typedef enum @@ -175,9 +180,9 @@ typedef enum typedef enum { - FS_CONTENTSTORAGEID_NandSystem = 0, - FS_CONTENTSTORAGEID_NandUser = 1, - FS_CONTENTSTORAGEID_SdCard = 2, + FsContentStorageId_NandSystem = 0, + FsContentStorageId_NandUser = 1, + FsContentStorageId_SdCard = 2, } FsContentStorageId; typedef enum @@ -214,9 +219,9 @@ typedef enum { } FsSaveDataFlags; typedef enum { - FsGameCardAttribute_AutoBoot = (1 << 0), ///< Causes the cartridge to automatically start on bootup - FsGameCardAttribute_ForceError = (1 << 1), ///< Causes NS to throw an error on attempt to load the cartridge - FsGameCardAttribute_Repair = (1 << 2), ///< Indicates that this gamecard is a repair tool. + FsGameCardAttribute_AutoBoot = BIT(0), ///< Causes the cartridge to automatically start on bootup + FsGameCardAttribute_ForceError = BIT(1), ///< Causes NS to throw an error on attempt to load the cartridge + FsGameCardAttribute_Repair = BIT(2), ///< Indicates that this gamecard is a repair tool. } FsGameCardAttribute; typedef enum { @@ -350,16 +355,16 @@ Result fsOpenFileSystemWithId(FsFileSystem* out, u64 titleId, FsFileSystemType f Result fsOpenFileSystemWithPatch(FsFileSystem* out, u64 titleId, FsFileSystemType fsType); /// [2.0.0+], like OpenFileSystemWithId but without content path. // IFileSystem -Result fsFsCreateFile(FsFileSystem* fs, const char* path, u64 size, u32 flags); +Result fsFsCreateFile(FsFileSystem* fs, const char* path, u64 size, u32 option); Result fsFsDeleteFile(FsFileSystem* fs, const char* path); Result fsFsCreateDirectory(FsFileSystem* fs, const char* path); Result fsFsDeleteDirectory(FsFileSystem* fs, const char* path); Result fsFsDeleteDirectoryRecursively(FsFileSystem* fs, const char* path); Result fsFsRenameFile(FsFileSystem* fs, const char* cur_path, const char* new_path); Result fsFsRenameDirectory(FsFileSystem* fs, const char* cur_path, const char* new_path); -Result fsFsGetEntryType(FsFileSystem* fs, const char* path, FsEntryType* out); -Result fsFsOpenFile(FsFileSystem* fs, const char* path, u32 flags, FsFile* out); -Result fsFsOpenDirectory(FsFileSystem* fs, const char* path, u32 flags, FsDir* out); +Result fsFsGetEntryType(FsFileSystem* fs, const char* path, FsDirEntryType* out); +Result fsFsOpenFile(FsFileSystem* fs, const char* path, u32 mode, FsFile* out); +Result fsFsOpenDirectory(FsFileSystem* fs, const char* path, u32 mode, FsDir* out); Result fsFsCommit(FsFileSystem* fs); Result fsFsGetFreeSpace(FsFileSystem* fs, const char* path, u64* out); Result fsFsGetTotalSpace(FsFileSystem* fs, const char* path, u64* out); diff --git a/nx/source/runtime/devices/fs_dev.c b/nx/source/runtime/devices/fs_dev.c index c14b0f02..e02a8c0f 100644 --- a/nx/source/runtime/devices/fs_dev.c +++ b/nx/source/runtime/devices/fs_dev.c @@ -555,7 +555,7 @@ fsdev_open(struct _reent *r, { /* read-only: do not allow O_APPEND */ case O_RDONLY: - fsdev_flags |= FS_OPEN_READ; + fsdev_flags |= FsOpenMode_Read; if(flags & O_APPEND) { r->_errno = EINVAL; @@ -565,12 +565,12 @@ fsdev_open(struct _reent *r, /* write-only */ case O_WRONLY: - fsdev_flags |= FS_OPEN_WRITE | FS_OPEN_APPEND; + fsdev_flags |= FsOpenMode_Write | FsOpenMode_Append; break; /* read and write */ case O_RDWR: - fsdev_flags |= (FS_OPEN_READ | FS_OPEN_WRITE | FS_OPEN_APPEND); + fsdev_flags |= (FsOpenMode_Read | FsOpenMode_Write | FsOpenMode_Append); break; /* an invalid option was supplied */ @@ -690,7 +690,7 @@ fsdev_write(struct _reent *r, } } - rc = fsFileWrite(&file->fd, file->offset, ptr, len, FS_WRITEOPTION_NONE); + rc = fsFileWrite(&file->fd, file->offset, ptr, len, FsWriteOption_None); if(rc == 0xD401) return fsdev_write_safe(r, fd, ptr, len); if(R_FAILED(rc)) @@ -744,7 +744,7 @@ fsdev_write_safe(struct _reent *r, memcpy(tmp_buffer, ptr, toWrite); /* write the data */ - rc = fsFileWrite(&file->fd, file->offset, tmp_buffer, toWrite, FS_WRITEOPTION_NONE); + rc = fsFileWrite(&file->fd, file->offset, tmp_buffer, toWrite, FsWriteOption_None); if(R_FAILED(rc)) { @@ -799,7 +799,7 @@ fsdev_read(struct _reent *r, } /* read the data */ - rc = fsFileRead(&file->fd, file->offset, ptr, len, FS_READOPTION_NONE, &bytes); + rc = fsFileRead(&file->fd, file->offset, ptr, len, FsReadOption_None, &bytes); if(rc == 0xD401) return fsdev_read_safe(r, fd, ptr, len); if(R_SUCCEEDED(rc)) @@ -846,7 +846,7 @@ fsdev_read_safe(struct _reent *r, toRead = sizeof(tmp_buffer); /* read the data */ - rc = fsFileRead(&file->fd, file->offset, tmp_buffer, toRead, FS_READOPTION_NONE, &bytes); + rc = fsFileRead(&file->fd, file->offset, tmp_buffer, toRead, FsReadOption_None, &bytes); if(bytes > toRead) bytes = toRead; @@ -998,7 +998,7 @@ fsdev_stat(struct _reent *r, char fs_path[FS_MAX_PATH]; fsdev_fsdevice *device = NULL; FsTimeStampRaw timestamps = {0}; - FsEntryType type; + FsDirEntryType type; if(fsdev_getfspath(r, file, &device, fs_path)==-1) return -1; @@ -1006,9 +1006,9 @@ fsdev_stat(struct _reent *r, rc = fsFsGetEntryType(&device->fs, fs_path, &type); if(R_SUCCEEDED(rc)) { - if(type == ENTRYTYPE_DIR) + if(type == FsDirEntryType_Dir) { - if(R_SUCCEEDED(rc = fsFsOpenDirectory(&device->fs, fs_path, FS_DIROPEN_DIRECTORY | FS_DIROPEN_FILE, &fdir))) + if(R_SUCCEEDED(rc = fsFsOpenDirectory(&device->fs, fs_path, FsDirOpenMode_ReadDirs | FsDirOpenMode_ReadFiles, &fdir))) { memset(st, 0, sizeof(struct stat)); st->st_nlink = 1; @@ -1017,9 +1017,9 @@ fsdev_stat(struct _reent *r, return 0; } } - else if(type == ENTRYTYPE_FILE) + else if(type == FsDirEntryType_File) { - if(R_SUCCEEDED(rc = fsFsOpenFile(&device->fs, fs_path, FS_OPEN_READ, &fd))) + if(R_SUCCEEDED(rc = fsFsOpenFile(&device->fs, fs_path, FsOpenMode_Read, &fd))) { fsdev_file_t tmpfd = { .fd = fd }; ret = fsdev_fstat(r, &tmpfd, st); @@ -1115,7 +1115,7 @@ fsdev_chdir(struct _reent *r, if(fsdev_getfspath(r, name, &device, fs_path)==-1) return -1; - rc = fsFsOpenDirectory(&device->fs, fs_path, FS_DIROPEN_DIRECTORY | FS_DIROPEN_FILE, &fd); + rc = fsFsOpenDirectory(&device->fs, fs_path, FsDirOpenMode_ReadDirs | FsDirOpenMode_ReadFiles, &fd); if(R_SUCCEEDED(rc)) { fsDirClose(&fd); @@ -1153,7 +1153,7 @@ fsdev_rename(struct _reent *r, const char *newName) { Result rc; - FsEntryType type; + FsDirEntryType type; fsdev_fsdevice *device_old = NULL, *device_new = NULL; char fs_path_old[FS_MAX_PATH]; char fs_path_new[FS_MAX_PATH]; @@ -1173,13 +1173,13 @@ fsdev_rename(struct _reent *r, rc = fsFsGetEntryType(&device_old->fs, fs_path_old, &type); if(R_SUCCEEDED(rc)) { - if(type == ENTRYTYPE_DIR) + if(type == FsDirEntryType_Dir) { rc = fsFsRenameDirectory(&device_old->fs, fs_path_old, fs_path_new); if(R_SUCCEEDED(rc)) return 0; } - else if(type == ENTRYTYPE_FILE) + else if(type == FsDirEntryType_File) { rc = fsFsRenameFile(&device_old->fs, fs_path_old, fs_path_new); if(R_SUCCEEDED(rc)) @@ -1251,7 +1251,7 @@ fsdev_diropen(struct _reent *r, fsdev_dir_t *dir = (fsdev_dir_t*)(dirState->dirStruct); /* open the directory */ - rc = fsFsOpenDirectory(&device->fs, fs_path, FS_DIROPEN_DIRECTORY | FS_DIROPEN_FILE, &fd); + rc = fsFsOpenDirectory(&device->fs, fs_path, FsDirOpenMode_ReadDirs | FsDirOpenMode_ReadFiles, &fd); if(R_SUCCEEDED(rc)) { dir->magic = FSDEV_DIRITER_MAGIC; @@ -1342,9 +1342,9 @@ fsdev_dirnext(struct _reent *r, /* fill in the stat info */ filestat->st_ino = 0; - if(entry->type == ENTRYTYPE_DIR) + if(entry->type == FsDirEntryType_Dir) filestat->st_mode = S_IFDIR; - else if(entry->type == ENTRYTYPE_FILE) + else if(entry->type == FsDirEntryType_File) { filestat->st_mode = S_IFREG; filestat->st_size = entry->fileSize; diff --git a/nx/source/runtime/devices/romfs_dev.c b/nx/source/runtime/devices/romfs_dev.c index 96b8c6cc..459f6f63 100644 --- a/nx/source/runtime/devices/romfs_dev.c +++ b/nx/source/runtime/devices/romfs_dev.c @@ -56,7 +56,7 @@ static ssize_t _romfs_read(romfs_mount *mount, u64 offset, void* buffer, u64 siz Result rc = 0; if(mount->fd_type == RomfsSource_FsFile) { - rc = fsFileRead(&mount->fd, pos, buffer, size, FS_READOPTION_NONE, &read); + rc = fsFileRead(&mount->fd, pos, buffer, size, FsReadOption_None, &read); } else if(mount->fd_type == RomfsSource_FsStorage) { @@ -244,7 +244,7 @@ Result romfsMount(const char *name) return 2; } - Result rc = fsFsOpenFile(sdfs, filename, FS_OPEN_READ, &mount->fd); + Result rc = fsFsOpenFile(sdfs, filename, FsOpenMode_Read, &mount->fd); if (R_FAILED(rc)) { romfs_free(mount); @@ -344,7 +344,7 @@ Result romfsMountFromFsdev(const char *path, u64 offset, const char *name) mount->fd_type = RomfsSource_FsFile; mount->offset = offset; - Result rc = fsFsOpenFile(tmpfs, filepath, FS_OPEN_READ, &mount->fd); + Result rc = fsFsOpenFile(tmpfs, filepath, FsOpenMode_Read, &mount->fd); if (R_FAILED(rc)) { romfs_free(mount); diff --git a/nx/source/services/fs.c b/nx/source/services/fs.c index 8fb1611b..d4c1b307 100644 --- a/nx/source/services/fs.c +++ b/nx/source/services/fs.c @@ -530,11 +530,11 @@ Result fsOpenFileSystemWithPatch(FsFileSystem* out, u64 titleId, FsFileSystemTyp // IFileSystem //----------------------------------------------------------------------------- -Result fsFsCreateFile(FsFileSystem* fs, const char* path, u64 size, u32 flags) { +Result fsFsCreateFile(FsFileSystem* fs, const char* path, u64 size, u32 option) { const struct { - u32 flags; + u32 option; u64 size; - } in = { flags, size }; + } in = { option, size }; return _fsObjectDispatchIn(&fs->s, 0, in, .buffer_attrs = { SfBufferAttr_HipcPointer | SfBufferAttr_In }, @@ -586,7 +586,7 @@ Result fsFsRenameDirectory(FsFileSystem* fs, const char* cur_path, const char* n return _fsFsCmdWithTwoInPaths(fs, cur_path, new_path, 6); } -Result fsFsGetEntryType(FsFileSystem* fs, const char* path, FsEntryType* out) { +Result fsFsGetEntryType(FsFileSystem* fs, const char* path, FsDirEntryType* out) { return _fsObjectDispatchOut(&fs->s, 7, *out, .buffer_attrs = { SfBufferAttr_HipcPointer | SfBufferAttr_In }, .buffers = { { path, FS_MAX_PATH } }, @@ -602,12 +602,12 @@ static Result _fsFsOpenCommon(FsFileSystem* fs, const char* path, u32 flags, Ser ); } -Result fsFsOpenFile(FsFileSystem* fs, const char* path, u32 flags, FsFile* out) { - return _fsFsOpenCommon(fs, path, flags, &out->s, 8); +Result fsFsOpenFile(FsFileSystem* fs, const char* path, u32 mode, FsFile* out) { + return _fsFsOpenCommon(fs, path, mode, &out->s, 8); } -Result fsFsOpenDirectory(FsFileSystem* fs, const char* path, u32 flags, FsDir* out) { - return _fsFsOpenCommon(fs, path, flags, &out->s, 9); +Result fsFsOpenDirectory(FsFileSystem* fs, const char* path, u32 mode, FsDir* out) { + return _fsFsOpenCommon(fs, path, mode, &out->s, 9); } Result fsFsCommit(FsFileSystem* fs) {