diff --git a/nx/include/switch/devices/fs_dev.h b/nx/include/switch/devices/fs_dev.h index 95ca5785..4fa2f5ad 100644 --- a/nx/include/switch/devices/fs_dev.h +++ b/nx/include/switch/devices/fs_dev.h @@ -18,10 +18,10 @@ typedef struct FsDirectoryEntry entry_data[32]; /*! Temporary storage for reading entries */ } fsdev_dir_t; -/// Initializes the FS driver. +/// 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. +/// Exits the FS driver. Any devices still mounted are unmounted. Result fsdevExit(void); /// Mounts the input fs with the specified device name. fsdev will handle closing the fs when required, including when fsdevMountDevice() fails. @@ -31,3 +31,7 @@ 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 is not used automatically at device unmount. +Result fsdevCommitDevice(const char *name); + diff --git a/nx/source/devices/fs_dev.c b/nx/source/devices/fs_dev.c index 6fbaaa62..e078d0d3 100644 --- a/nx/source/devices/fs_dev.c +++ b/nx/source/devices/fs_dev.c @@ -328,14 +328,15 @@ static int _fsdevUnmountDeviceStruct(fsdev_fsdevice *device) RemoveDevice(name); fsFsClose(&device->fs); - memset(device, 0, sizeof(fsdev_fsdevice)); - if(device->id == fsdev_fsdevice_default) fsdev_fsdevice_default = -1; if(device->id == fsdev_fsdevice_cwd) fsdev_fsdevice_cwd = fsdev_fsdevice_default; + device->setup = 0; + memset(device->name, 0, sizeof(device->name)); + return 0; } @@ -350,6 +351,17 @@ int fsdevUnmountDevice(const char *name) return _fsdevUnmountDeviceStruct(device); } +Result fsdevCommitDevice(const char *name) +{ + fsdev_fsdevice *device; + + device = fsdevFindDevice(name); + if(device==NULL) + return MAKERESULT(MODULE_LIBNX, LIBNX_NOTFOUND); + + return fsFsCommit(&device->fs); +} + /*! Initialize SDMC device */ Result fsdevInit(void) { @@ -377,6 +389,9 @@ Result fsdevInit(void) fsdevInitialised = true; } + if(fsdevFindDevice("sdmc")) + return 0; + rc = fsMountSdcard(&fs); if(R_SUCCEEDED(rc)) {