diff --git a/nx/include/switch/runtime/devices/fs_dev.h b/nx/include/switch/runtime/devices/fs_dev.h index de3e05c3..c4f9d548 100644 --- a/nx/include/switch/runtime/devices/fs_dev.h +++ b/nx/include/switch/runtime/devices/fs_dev.h @@ -22,11 +22,8 @@ typedef struct FsDirectoryEntry entry_data[32]; ///< Temporary storage for reading entries } fsdev_dir_t; -/// Initializes the FS driver. Automatically initializes the sdmc device if accessible. If called again, sdmc mounting will be attempted again if it's not mounted. -Result fsdevInit(void); - -/// Exits the FS driver. Any devices still mounted are unmounted. -Result fsdevExit(void); +/// Initializes and mounts the sdmc device if accessible. Also initializes current working directory to point to the folder containing the path to the executable (argv[0]), if it is provided by the environment. +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. @@ -41,3 +38,6 @@ Result fsdevCommitDevice(const char *name); /// Returns the FsFileSystem for the default device (SD card), if mounted. Used internally by romfs_dev. FsFileSystem* fsdevGetDefaultFileSystem(void); + +/// Unmounts all devices and cleans up any resources used by the FS driver. +Result fsdevUnmountAll(void); diff --git a/nx/source/runtime/devices/fs_dev.c b/nx/source/runtime/devices/fs_dev.c index e4d787ef..6ab3cfe7 100644 --- a/nx/source/runtime/devices/fs_dev.c +++ b/nx/source/runtime/devices/fs_dev.c @@ -97,6 +97,7 @@ typedef struct char name[32]; } fsdev_fsdevice; +static bool fsdev_initialised = false; static s32 fsdev_fsdevice_default = -1; static s32 fsdev_fsdevice_cwd = -1; static fsdev_fsdevice fsdev_fsdevices[32]; @@ -113,6 +114,9 @@ static fsdev_fsdevice *fsdevFindDevice(const char *name) u32 total = sizeof(fsdev_fsdevices) / sizeof(fsdev_fsdevice); fsdev_fsdevice *device = NULL; + if(!fsdev_initialised) + return NULL; + if(name && name[0] == '/') //Return the default device. { if(fsdev_fsdevice_default==-1) @@ -273,7 +277,26 @@ static ssize_t fsdev_convertfromfspath(uint8_t *out, uint8_t *in, size_t len) extern int __system_argc; extern char** __system_argv; -static bool fsdevInitialised = false; +static void _fsdevInit(void) +{ + u32 i; + u32 total = sizeof(fsdev_fsdevices) / sizeof(fsdev_fsdevice); + + if(!fsdev_initialised) + { + memset(fsdev_fsdevices, 0, sizeof(fsdev_fsdevices)); + + for(i=0; i