libnx/nx/include/switch/runtime/devices/fs_dev.h
fincs c77b88d868
Major cleanup and refactor of fsdev and romfsdev, see details:
fsdev:
- Removed fsdevGetDefaultFileSystem and default-fs handling
- Refactored CWD support to have (dynamically allocated) per-device CWDs
  (CWD support as a whole can be turned off with __nx_fsdev_support_cwd)
- Optimized calls by passing pointer to device through r->deviceData
- Use the per-thread path buffer directly as the argument to FS functions
- Removed redundant cross-device check in fsdev_rename
- Fixed string comparison logic in fsdevFindDevice
- fsdev_fixpath now accepts an input device in order to skip device
  lookup (extensively used along with r->deviceData)
- Mounting a filesystem now automatically sets the default device
  if there wasn't any previous default device (or if it's stdnull)
- fsdevMountSdmc no longer sets cwd to the folder containing the
  executable - this logic was moved to a new internal function
  called on startup by default (and it is now disabled for NSOs)
- Other miscellaneous optimizations

romfsdev:
- Cleaned up romfsMount* functions, removed unused/unnecessary logic
- Changed romfsMount* functions to return real result codes
- Renamed romfsMount to romfsMountSelf and improved documentation
- Removed romfsInitFromFile and romfsInitFromStorage (use Mount instead)
- Added documentation for romfsInit and romfsExit
2019-10-20 22:22:04 +02:00

64 lines
2.4 KiB
C

/**
* @file fs_dev.h
* @brief FS driver, using devoptab.
* @author yellows8
* @author mtheall
* @copyright libnx Authors
*/
#pragma once
#include <sys/types.h>
#include "../../services/fs.h"
#define FSDEV_DIRITER_MAGIC 0x66736476 ///< "fsdv"
/// Open directory struct
typedef struct
{
u32 magic; ///< "fsdv"
FsDir fd; ///< File descriptor
ssize_t index; ///< Current entry index
size_t size; ///< Current batch size
} fsdev_dir_t;
/// Retrieves a pointer to temporary stage for reading entries
NX_CONSTEXPR FsDirectoryEntry* fsdevDirGetEntries(fsdev_dir_t *dir)
{
return (FsDirectoryEntry*)(void*)(dir+1);
}
/// Initializes and mounts the sdmc device if accessible.
Result fsdevMountSdmc(void);
/// Mounts the input fs with the specified device name. fsdev will handle closing the fs when required, including when fsdevMountDevice() fails.
/// Returns -1 when any errors occur.
int fsdevMountDevice(const char *name, FsFileSystem fs);
/// Unmounts the specified device.
int fsdevUnmountDevice(const char *name);
/// Uses fsFsCommit() with the specified device. This must be used after any savedata-write operations(not just file-write). This should be used after each file-close where file-writing was done.
/// This is not used automatically at device unmount.
Result fsdevCommitDevice(const char *name);
/// Returns the FsFileSystem for the specified device. Returns NULL when the specified device isn't found.
FsFileSystem* fsdevGetDeviceFileSystem(const char *name);
/// Writes the FS-path to outpath (which has buffer size FS_MAX_PATH), for the input path (as used in stdio). The FsFileSystem is also written to device when not NULL.
int fsdevTranslatePath(const char *path, FsFileSystem** device, char *outpath);
/// This calls fsFsSetArchiveBit on the filesystem specified by the input path (as used in stdio).
Result fsdevSetArchiveBit(const char *path);
/// This calls fsFsCreateFile on the filesystem specified by the input path (as used in stdio).
Result fsdevCreateFile(const char* path, size_t size, u32 flags);
/// Recursively deletes the directory specified by the input path (as used in stdio).
Result fsdevDeleteDirectoryRecursively(const char *path);
/// Unmounts all devices and cleans up any resources used by the FS driver.
Result fsdevUnmountAll(void);
/// Retrieves the last native result code generated during a failed fsdev operation.
Result fsdevGetLastResult(void);