Updated fs_dev.h comments, etc. Fixed _fsdevUnmountDeviceStruct(). Added fsdevCommitDevice(). Check whether sdmc is already mounted in fsdevInit().

This commit is contained in:
yellows8 2017-11-30 13:00:47 -05:00
parent 0c5efe5f9c
commit 7da25ba40f
2 changed files with 23 additions and 4 deletions

View File

@ -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);

View File

@ -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))
{