mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-24 13:52:53 +02:00
Revise fsdev initialization, see details:
- Removed fsdevInit/Exit - Now automatically initializing fsdev state on first mount - Added fsdevMountSdmc (replaces fsdevInit) - Added fsdevUnmountAll (replaces fsdevExit)
This commit is contained in:
parent
b2b8e1ec67
commit
2818c99dea
@ -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);
|
||||
|
@ -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<total; i++)
|
||||
{
|
||||
memcpy(&fsdev_fsdevices[i].device, &fsdev_devoptab, sizeof(fsdev_devoptab));
|
||||
fsdev_fsdevices[i].device.name = fsdev_fsdevices[i].name;
|
||||
fsdev_fsdevices[i].id = i;
|
||||
}
|
||||
|
||||
fsdev_fsdevice_default = -1;
|
||||
fsdev_initialised = true;
|
||||
}
|
||||
}
|
||||
|
||||
static int _fsdevMountDevice(const char *name, FsFileSystem fs, fsdev_fsdevice **out_device)
|
||||
{
|
||||
@ -285,6 +308,7 @@ static int _fsdevMountDevice(const char *name, FsFileSystem fs, fsdev_fsdevice *
|
||||
return -1;
|
||||
}
|
||||
|
||||
_fsdevInit(); //Ensure fsdev is initialized
|
||||
device = fsdevFindDevice(NULL);
|
||||
if(device==NULL)
|
||||
{
|
||||
@ -365,7 +389,7 @@ Result fsdevCommitDevice(const char *name)
|
||||
}
|
||||
|
||||
/*! Initialize SDMC device */
|
||||
Result fsdevInit(void)
|
||||
Result fsdevMountSdmc(void)
|
||||
{
|
||||
ssize_t units;
|
||||
uint32_t code;
|
||||
@ -373,23 +397,6 @@ Result fsdevInit(void)
|
||||
Result rc = 0;
|
||||
FsFileSystem fs;
|
||||
fsdev_fsdevice *device = NULL;
|
||||
u32 i;
|
||||
u32 total = sizeof(fsdev_fsdevices) / sizeof(fsdev_fsdevice);
|
||||
|
||||
if(!fsdevInitialised)
|
||||
{
|
||||
memset(fsdev_fsdevices, 0, sizeof(fsdev_fsdevices));
|
||||
|
||||
for(i=0; i<total; i++)
|
||||
{
|
||||
memcpy(&fsdev_fsdevices[i].device, &fsdev_devoptab, sizeof(fsdev_devoptab));
|
||||
fsdev_fsdevices[i].device.name = fsdev_fsdevices[i].name;
|
||||
fsdev_fsdevices[i].id = i;
|
||||
}
|
||||
|
||||
fsdev_fsdevice_default = -1;
|
||||
fsdevInitialised = true;
|
||||
}
|
||||
|
||||
if(fsdevFindDevice("sdmc"))
|
||||
return 0;
|
||||
@ -451,26 +458,27 @@ Result fsdevInit(void)
|
||||
}
|
||||
|
||||
/*! Clean up fsdev devices */
|
||||
Result fsdevExit(void)
|
||||
Result fsdevUnmountAll(void)
|
||||
{
|
||||
u32 i;
|
||||
u32 total = sizeof(fsdev_fsdevices) / sizeof(fsdev_fsdevice);
|
||||
Result rc=0;
|
||||
|
||||
if(!fsdevInitialised) return rc;
|
||||
if(!fsdev_initialised) return rc;
|
||||
|
||||
for(i=0; i<total; i++)
|
||||
{
|
||||
_fsdevUnmountDeviceStruct(&fsdev_fsdevices[i]);
|
||||
}
|
||||
|
||||
fsdevInitialised = false;
|
||||
fsdev_initialised = false;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
FsFileSystem* fsdevGetDefaultFileSystem(void)
|
||||
{
|
||||
if(!fsdev_initialised) return NULL;
|
||||
if(fsdev_fsdevice_default==-1) return NULL;
|
||||
|
||||
return &fsdev_fsdevices[fsdev_fsdevice_default].fs;
|
||||
|
@ -110,13 +110,13 @@ void __attribute__((weak)) __appInit(void)
|
||||
if (R_FAILED(rc))
|
||||
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_FS));
|
||||
|
||||
fsdevInit();
|
||||
fsdevMountSdmc();
|
||||
}
|
||||
|
||||
void __attribute__((weak)) __appExit(void)
|
||||
{
|
||||
// Cleanup default services.
|
||||
fsdevExit();
|
||||
fsdevUnmountAll();
|
||||
fsExit();
|
||||
timeExit();
|
||||
hidExit();
|
||||
|
Loading…
Reference in New Issue
Block a user