fs: Update names of enum/flag types for style consistency and correctness

This commit is contained in:
fincs 2019-09-21 19:54:21 +02:00
parent 77888f8b1f
commit ecbc77840e
No known key found for this signature in database
GPG Key ID: 62C7609ADA219C60
4 changed files with 62 additions and 57 deletions

View File

@ -58,7 +58,7 @@ typedef struct
{ {
char name[FS_MAX_PATH]; ///< Entry name. char name[FS_MAX_PATH]; ///< Entry name.
u8 pad[3]; u8 pad[3];
s8 type; ///< See FsEntryType. s8 type; ///< See FsDirEntryType.
u8 pad2[3]; ///< ? u8 pad2[3]; ///< ?
u64 fileSize; ///< File size. u64 fileSize; ///< File size.
} FsDirectoryEntry; } FsDirectoryEntry;
@ -127,40 +127,45 @@ typedef struct
u8 padding[7]; u8 padding[7];
} FsTimeStampRaw; } FsTimeStampRaw;
/// Returned by fsFsGetEntryType.
typedef enum { typedef enum {
ENTRYTYPE_DIR = 0, FsDirEntryType_Dir = 0, ///< Entry is a directory.
ENTRYTYPE_FILE = 1, FsDirEntryType_File = 1, ///< Entry is a file.
} FsEntryType; } FsDirEntryType;
/// For use with fsFsOpenFile.
typedef enum typedef enum
{ {
FS_OPEN_READ = BIT(0), ///< Open for reading. FsOpenMode_Read = BIT(0), ///< Open for reading.
FS_OPEN_WRITE = BIT(1), ///< Open for writing. FsOpenMode_Write = BIT(1), ///< Open for writing.
FS_OPEN_APPEND = BIT(2), ///< Append file. FsOpenMode_Append = BIT(2), ///< Append file.
} FsFileFlags; } FsOpenMode;
/// For use with fsFsCreateFile.
typedef enum typedef enum
{ {
FS_CREATE_BIG_FILE = BIT(0), ///< Creates a ConcatenationFile (dir with archive bit) instead of file. FsCreateOption_BigFile = BIT(0), ///< Creates a ConcatenationFile (dir with archive bit) instead of file.
} FsFileCreateFlags; } FsCreateOption;
/// For use with fsFsOpenDirectory. /// For use with fsFsOpenDirectory.
typedef enum typedef enum
{ {
FS_DIROPEN_DIRECTORY = BIT(0), ///< Enable reading directory entries. FsDirOpenMode_ReadDirs = BIT(0), ///< Enable reading directory entries.
FS_DIROPEN_FILE = BIT(1), ///< Enable reading file entries. FsDirOpenMode_ReadFiles = BIT(1), ///< Enable reading file entries.
FS_DIROPEN_NO_FILE_SIZE = BIT(31), ///< Causes result entries to not contain filesize information (always 0). FsDirOpenMode_NoFileSize = BIT(31), ///< Causes result entries to not contain filesize information (always 0).
} FsDirectoryFlags; } FsDirOpenMode;
/// For use with fsFileRead.
typedef enum typedef enum
{ {
FS_READOPTION_NONE = 0, ///< No Option. FsReadOption_None = 0, ///< No option.
} FsReadOption; } FsReadOption;
/// For use with fsFileWrite.
typedef enum typedef enum
{ {
FS_WRITEOPTION_NONE = 0, ///< No option. FsWriteOption_None = 0, ///< No option.
FS_WRITEOPTION_FLUSH = BIT(0), ///< Forces a flush after write. FsWriteOption_Flush = BIT(0), ///< Forces a flush after write.
} FsWriteOption; } FsWriteOption;
typedef enum typedef enum
@ -175,9 +180,9 @@ typedef enum
typedef enum typedef enum
{ {
FS_CONTENTSTORAGEID_NandSystem = 0, FsContentStorageId_NandSystem = 0,
FS_CONTENTSTORAGEID_NandUser = 1, FsContentStorageId_NandUser = 1,
FS_CONTENTSTORAGEID_SdCard = 2, FsContentStorageId_SdCard = 2,
} FsContentStorageId; } FsContentStorageId;
typedef enum typedef enum
@ -214,9 +219,9 @@ typedef enum {
} FsSaveDataFlags; } FsSaveDataFlags;
typedef enum { typedef enum {
FsGameCardAttribute_AutoBoot = (1 << 0), ///< Causes the cartridge to automatically start on bootup FsGameCardAttribute_AutoBoot = BIT(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_ForceError = BIT(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_Repair = BIT(2), ///< Indicates that this gamecard is a repair tool.
} FsGameCardAttribute; } FsGameCardAttribute;
typedef enum { 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. Result fsOpenFileSystemWithPatch(FsFileSystem* out, u64 titleId, FsFileSystemType fsType); /// [2.0.0+], like OpenFileSystemWithId but without content path.
// IFileSystem // 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 fsFsDeleteFile(FsFileSystem* fs, const char* path);
Result fsFsCreateDirectory(FsFileSystem* fs, const char* path); Result fsFsCreateDirectory(FsFileSystem* fs, const char* path);
Result fsFsDeleteDirectory(FsFileSystem* fs, const char* path); Result fsFsDeleteDirectory(FsFileSystem* fs, const char* path);
Result fsFsDeleteDirectoryRecursively(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 fsFsRenameFile(FsFileSystem* fs, const char* cur_path, const char* new_path);
Result fsFsRenameDirectory(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 fsFsGetEntryType(FsFileSystem* fs, const char* path, FsDirEntryType* out);
Result fsFsOpenFile(FsFileSystem* fs, const char* path, u32 flags, FsFile* out); Result fsFsOpenFile(FsFileSystem* fs, const char* path, u32 mode, FsFile* out);
Result fsFsOpenDirectory(FsFileSystem* fs, const char* path, u32 flags, FsDir* out); Result fsFsOpenDirectory(FsFileSystem* fs, const char* path, u32 mode, FsDir* out);
Result fsFsCommit(FsFileSystem* fs); Result fsFsCommit(FsFileSystem* fs);
Result fsFsGetFreeSpace(FsFileSystem* fs, const char* path, u64* out); Result fsFsGetFreeSpace(FsFileSystem* fs, const char* path, u64* out);
Result fsFsGetTotalSpace(FsFileSystem* fs, const char* path, u64* out); Result fsFsGetTotalSpace(FsFileSystem* fs, const char* path, u64* out);

View File

@ -555,7 +555,7 @@ fsdev_open(struct _reent *r,
{ {
/* read-only: do not allow O_APPEND */ /* read-only: do not allow O_APPEND */
case O_RDONLY: case O_RDONLY:
fsdev_flags |= FS_OPEN_READ; fsdev_flags |= FsOpenMode_Read;
if(flags & O_APPEND) if(flags & O_APPEND)
{ {
r->_errno = EINVAL; r->_errno = EINVAL;
@ -565,12 +565,12 @@ fsdev_open(struct _reent *r,
/* write-only */ /* write-only */
case O_WRONLY: case O_WRONLY:
fsdev_flags |= FS_OPEN_WRITE | FS_OPEN_APPEND; fsdev_flags |= FsOpenMode_Write | FsOpenMode_Append;
break; break;
/* read and write */ /* read and write */
case O_RDWR: case O_RDWR:
fsdev_flags |= (FS_OPEN_READ | FS_OPEN_WRITE | FS_OPEN_APPEND); fsdev_flags |= (FsOpenMode_Read | FsOpenMode_Write | FsOpenMode_Append);
break; break;
/* an invalid option was supplied */ /* 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) if(rc == 0xD401)
return fsdev_write_safe(r, fd, ptr, len); return fsdev_write_safe(r, fd, ptr, len);
if(R_FAILED(rc)) if(R_FAILED(rc))
@ -744,7 +744,7 @@ fsdev_write_safe(struct _reent *r,
memcpy(tmp_buffer, ptr, toWrite); memcpy(tmp_buffer, ptr, toWrite);
/* write the data */ /* 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)) if(R_FAILED(rc))
{ {
@ -799,7 +799,7 @@ fsdev_read(struct _reent *r,
} }
/* read the data */ /* 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) if(rc == 0xD401)
return fsdev_read_safe(r, fd, ptr, len); return fsdev_read_safe(r, fd, ptr, len);
if(R_SUCCEEDED(rc)) if(R_SUCCEEDED(rc))
@ -846,7 +846,7 @@ fsdev_read_safe(struct _reent *r,
toRead = sizeof(tmp_buffer); toRead = sizeof(tmp_buffer);
/* read the data */ /* 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) if(bytes > toRead)
bytes = toRead; bytes = toRead;
@ -998,7 +998,7 @@ fsdev_stat(struct _reent *r,
char fs_path[FS_MAX_PATH]; char fs_path[FS_MAX_PATH];
fsdev_fsdevice *device = NULL; fsdev_fsdevice *device = NULL;
FsTimeStampRaw timestamps = {0}; FsTimeStampRaw timestamps = {0};
FsEntryType type; FsDirEntryType type;
if(fsdev_getfspath(r, file, &device, fs_path)==-1) if(fsdev_getfspath(r, file, &device, fs_path)==-1)
return -1; return -1;
@ -1006,9 +1006,9 @@ fsdev_stat(struct _reent *r,
rc = fsFsGetEntryType(&device->fs, fs_path, &type); rc = fsFsGetEntryType(&device->fs, fs_path, &type);
if(R_SUCCEEDED(rc)) 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)); memset(st, 0, sizeof(struct stat));
st->st_nlink = 1; st->st_nlink = 1;
@ -1017,9 +1017,9 @@ fsdev_stat(struct _reent *r,
return 0; 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 }; fsdev_file_t tmpfd = { .fd = fd };
ret = fsdev_fstat(r, &tmpfd, st); ret = fsdev_fstat(r, &tmpfd, st);
@ -1115,7 +1115,7 @@ fsdev_chdir(struct _reent *r,
if(fsdev_getfspath(r, name, &device, fs_path)==-1) if(fsdev_getfspath(r, name, &device, fs_path)==-1)
return -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)) if(R_SUCCEEDED(rc))
{ {
fsDirClose(&fd); fsDirClose(&fd);
@ -1153,7 +1153,7 @@ fsdev_rename(struct _reent *r,
const char *newName) const char *newName)
{ {
Result rc; Result rc;
FsEntryType type; FsDirEntryType type;
fsdev_fsdevice *device_old = NULL, *device_new = NULL; fsdev_fsdevice *device_old = NULL, *device_new = NULL;
char fs_path_old[FS_MAX_PATH]; char fs_path_old[FS_MAX_PATH];
char fs_path_new[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); rc = fsFsGetEntryType(&device_old->fs, fs_path_old, &type);
if(R_SUCCEEDED(rc)) if(R_SUCCEEDED(rc))
{ {
if(type == ENTRYTYPE_DIR) if(type == FsDirEntryType_Dir)
{ {
rc = fsFsRenameDirectory(&device_old->fs, fs_path_old, fs_path_new); rc = fsFsRenameDirectory(&device_old->fs, fs_path_old, fs_path_new);
if(R_SUCCEEDED(rc)) if(R_SUCCEEDED(rc))
return 0; return 0;
} }
else if(type == ENTRYTYPE_FILE) else if(type == FsDirEntryType_File)
{ {
rc = fsFsRenameFile(&device_old->fs, fs_path_old, fs_path_new); rc = fsFsRenameFile(&device_old->fs, fs_path_old, fs_path_new);
if(R_SUCCEEDED(rc)) if(R_SUCCEEDED(rc))
@ -1251,7 +1251,7 @@ fsdev_diropen(struct _reent *r,
fsdev_dir_t *dir = (fsdev_dir_t*)(dirState->dirStruct); fsdev_dir_t *dir = (fsdev_dir_t*)(dirState->dirStruct);
/* open the directory */ /* 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)) if(R_SUCCEEDED(rc))
{ {
dir->magic = FSDEV_DIRITER_MAGIC; dir->magic = FSDEV_DIRITER_MAGIC;
@ -1342,9 +1342,9 @@ fsdev_dirnext(struct _reent *r,
/* fill in the stat info */ /* fill in the stat info */
filestat->st_ino = 0; filestat->st_ino = 0;
if(entry->type == ENTRYTYPE_DIR) if(entry->type == FsDirEntryType_Dir)
filestat->st_mode = S_IFDIR; filestat->st_mode = S_IFDIR;
else if(entry->type == ENTRYTYPE_FILE) else if(entry->type == FsDirEntryType_File)
{ {
filestat->st_mode = S_IFREG; filestat->st_mode = S_IFREG;
filestat->st_size = entry->fileSize; filestat->st_size = entry->fileSize;

View File

@ -56,7 +56,7 @@ static ssize_t _romfs_read(romfs_mount *mount, u64 offset, void* buffer, u64 siz
Result rc = 0; Result rc = 0;
if(mount->fd_type == RomfsSource_FsFile) 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) else if(mount->fd_type == RomfsSource_FsStorage)
{ {
@ -244,7 +244,7 @@ Result romfsMount(const char *name)
return 2; 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)) if (R_FAILED(rc))
{ {
romfs_free(mount); romfs_free(mount);
@ -344,7 +344,7 @@ Result romfsMountFromFsdev(const char *path, u64 offset, const char *name)
mount->fd_type = RomfsSource_FsFile; mount->fd_type = RomfsSource_FsFile;
mount->offset = offset; 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)) if (R_FAILED(rc))
{ {
romfs_free(mount); romfs_free(mount);

View File

@ -530,11 +530,11 @@ Result fsOpenFileSystemWithPatch(FsFileSystem* out, u64 titleId, FsFileSystemTyp
// IFileSystem // 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 { const struct {
u32 flags; u32 option;
u64 size; u64 size;
} in = { flags, size }; } in = { option, size };
return _fsObjectDispatchIn(&fs->s, 0, in, return _fsObjectDispatchIn(&fs->s, 0, in,
.buffer_attrs = { SfBufferAttr_HipcPointer | SfBufferAttr_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); 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, return _fsObjectDispatchOut(&fs->s, 7, *out,
.buffer_attrs = { SfBufferAttr_HipcPointer | SfBufferAttr_In }, .buffer_attrs = { SfBufferAttr_HipcPointer | SfBufferAttr_In },
.buffers = { { path, FS_MAX_PATH } }, .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) { Result fsFsOpenFile(FsFileSystem* fs, const char* path, u32 mode, FsFile* out) {
return _fsFsOpenCommon(fs, path, flags, &out->s, 8); return _fsFsOpenCommon(fs, path, mode, &out->s, 8);
} }
Result fsFsOpenDirectory(FsFileSystem* fs, const char* path, u32 flags, FsDir* out) { Result fsFsOpenDirectory(FsFileSystem* fs, const char* path, u32 mode, FsDir* out) {
return _fsFsOpenCommon(fs, path, flags, &out->s, 9); return _fsFsOpenCommon(fs, path, mode, &out->s, 9);
} }
Result fsFsCommit(FsFileSystem* fs) { Result fsFsCommit(FsFileSystem* fs) {