mirror of
https://github.com/wiiu-env/libmocha.git
synced 2024-11-16 00:35:04 +01:00
Fixes
This commit is contained in:
parent
11f76790e4
commit
93c5b25648
@ -35,7 +35,7 @@ static const devoptab_t fsa_default_devoptab = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static bool fsa_initialised = false;
|
static bool fsa_initialised = false;
|
||||||
static FSADeviceData fsa_mounts[8];
|
static FSADeviceData fsa_mounts[0x10];
|
||||||
|
|
||||||
static void fsaResetMount(FSADeviceData *mount, uint32_t id) {
|
static void fsaResetMount(FSADeviceData *mount, uint32_t id) {
|
||||||
*mount = {};
|
*mount = {};
|
||||||
@ -86,12 +86,12 @@ static void fsa_free(FSADeviceData *mount) {
|
|||||||
FSError res;
|
FSError res;
|
||||||
if (mount->mounted) {
|
if (mount->mounted) {
|
||||||
if ((res = FSAUnmount(mount->clientHandle, mount->mount_path, FSA_UNMOUNT_FLAG_FORCE)) < 0) {
|
if ((res = FSAUnmount(mount->clientHandle, mount->mount_path, FSA_UNMOUNT_FLAG_FORCE)) < 0) {
|
||||||
DEBUG_FUNCTION_LINE_ERR("FSAUnmount %s for %s failed: %s", mount->mount_path, mount->name, FSAGetStatusStr(res));
|
DEBUG_FUNCTION_LINE_WARN("FSAUnmount %s for %s failed: %s", mount->mount_path, mount->name, FSAGetStatusStr(res));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res = FSADelClient(mount->clientHandle);
|
res = FSADelClient(mount->clientHandle);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
DEBUG_FUNCTION_LINE_ERR("FSADelClient for %s failed: %d", mount->name, FSAGetStatusStr(res));
|
DEBUG_FUNCTION_LINE_WARN("FSADelClient for %s failed: %s", mount->name, FSAGetStatusStr(res));
|
||||||
}
|
}
|
||||||
fsaResetMount(mount, mount->id);
|
fsaResetMount(mount, mount->id);
|
||||||
}
|
}
|
||||||
@ -117,7 +117,7 @@ MochaUtilsStatus Mocha_UnmountFS(const char *virt_name) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG_FUNCTION_LINE_ERR("Failed to find fsa mount data for %s", virt_name);
|
DEBUG_FUNCTION_LINE_WARN("Failed to find fsa mount data for %s", virt_name);
|
||||||
return MOCHA_RESULT_NOT_FOUND;
|
return MOCHA_RESULT_NOT_FOUND;
|
||||||
}
|
}
|
||||||
extern int mochaInitDone;
|
extern int mochaInitDone;
|
||||||
@ -141,7 +141,7 @@ MochaUtilsStatus Mocha_MountFSEx(const char *virt_name, const char *dev_path, co
|
|||||||
if (mount == nullptr) {
|
if (mount == nullptr) {
|
||||||
DEBUG_FUNCTION_LINE_ERR("fsa_alloc() failed");
|
DEBUG_FUNCTION_LINE_ERR("fsa_alloc() failed");
|
||||||
OSMemoryBarrier();
|
OSMemoryBarrier();
|
||||||
return MOCHA_RESULT_OUT_OF_MEMORY;
|
return MOCHA_RESULT_MAX_CLIENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
mount->clientHandle = FSAAddClient(nullptr);
|
mount->clientHandle = FSAAddClient(nullptr);
|
||||||
@ -151,8 +151,9 @@ MochaUtilsStatus Mocha_MountFSEx(const char *virt_name, const char *dev_path, co
|
|||||||
return MOCHA_RESULT_MAX_CLIENT;
|
return MOCHA_RESULT_MAX_CLIENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Mocha_UnlockFSClientEx(mount->clientHandle) != MOCHA_RESULT_SUCCESS) {
|
MochaUtilsStatus status;
|
||||||
DEBUG_FUNCTION_LINE_ERR("Mocha_UnlockFSClientEx failed");
|
if ((status = Mocha_UnlockFSClientEx(mount->clientHandle)) != MOCHA_RESULT_SUCCESS) {
|
||||||
|
DEBUG_FUNCTION_LINE_ERR("Mocha_UnlockFSClientEx failed: %s", Mocha_GetStatusStr(status));
|
||||||
return MOCHA_RESULT_UNSUPPORTED_COMMAND;
|
return MOCHA_RESULT_UNSUPPORTED_COMMAND;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,7 +165,7 @@ MochaUtilsStatus Mocha_MountFSEx(const char *virt_name, const char *dev_path, co
|
|||||||
if (dev_path) {
|
if (dev_path) {
|
||||||
res = FSAMount(mount->clientHandle, dev_path, mount_path, mountFlags, mountArgBuf, mountArgBufLen);
|
res = FSAMount(mount->clientHandle, dev_path, mount_path, mountFlags, mountArgBuf, mountArgBufLen);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
DEBUG_FUNCTION_LINE_ERR("FSAMount(0x%08X, %s, %s, FSA_MOUNT_FLAG_GLOBAL_MOUNT, nullptr, 0) failed: %s", mount->clientHandle, dev_path, mount_path, FSAGetStatusStr(res));
|
DEBUG_FUNCTION_LINE_ERR("FSAMount(0x%08X, %s, %s, %08X, %08X, %08X) failed: %s", mount->clientHandle, dev_path, mount_path, mountFlags, mountArgBuf, mountArgBufLen, FSAGetStatusStr(res));
|
||||||
fsa_free(mount);
|
fsa_free(mount);
|
||||||
if (res == FS_ERROR_ALREADY_EXISTS) {
|
if (res == FS_ERROR_ALREADY_EXISTS) {
|
||||||
return MOCHA_RESULT_ALREADY_EXISTS;
|
return MOCHA_RESULT_ALREADY_EXISTS;
|
||||||
@ -177,7 +178,7 @@ MochaUtilsStatus Mocha_MountFSEx(const char *virt_name, const char *dev_path, co
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((res = FSAChangeDir(mount->clientHandle, mount->mount_path)) < 0) {
|
if ((res = FSAChangeDir(mount->clientHandle, mount->mount_path)) < 0) {
|
||||||
DEBUG_FUNCTION_LINE_ERR("FSAChangeDir(0x%08X, %s) failed: %s", mount->clientHandle, mount->mount_path, FSAGetStatusStr(res));
|
DEBUG_FUNCTION_LINE_WARN("FSAChangeDir(0x%08X, %s) failed: %s", mount->clientHandle, mount->mount_path, FSAGetStatusStr(res));
|
||||||
}
|
}
|
||||||
|
|
||||||
FSADeviceInfo deviceInfo;
|
FSADeviceInfo deviceInfo;
|
||||||
@ -187,7 +188,7 @@ MochaUtilsStatus Mocha_MountFSEx(const char *virt_name, const char *dev_path, co
|
|||||||
} else {
|
} else {
|
||||||
mount->deviceSizeInSectors = 0xFFFFFFFF;
|
mount->deviceSizeInSectors = 0xFFFFFFFF;
|
||||||
mount->deviceSectorSize = 512;
|
mount->deviceSectorSize = 512;
|
||||||
DEBUG_FUNCTION_LINE_ERR("Failed to get DeviceInfo for %s: %s", mount_path, FSAGetStatusStr(res));
|
DEBUG_FUNCTION_LINE_WARN("Failed to get DeviceInfo for %s: %s", mount_path, FSAGetStatusStr(res));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (AddDevice(&mount->device) < 0) {
|
if (AddDevice(&mount->device) < 0) {
|
||||||
|
@ -2,8 +2,10 @@
|
|||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
// Use this extended hidden flag value to provide FS_OPEN_FLAG_ENCRYPTED in underlying FSOpenFileEx() call
|
// Extended "magic" value that allows opening files with FS_OPEN_FLAG_UNENCRYPTED in underlying FSOpenFileEx() call similar to O_DIRECTORY
|
||||||
#define O_ENCRYPTED 0x4000000
|
#ifndef O_UNENCRYPTED
|
||||||
|
#define O_UNENCRYPTED 0x4000000
|
||||||
|
#endif
|
||||||
|
|
||||||
int __fsa_open(struct _reent *r,
|
int __fsa_open(struct _reent *r,
|
||||||
void *fileStruct,
|
void *fileStruct,
|
||||||
@ -21,29 +23,19 @@ int __fsa_open(struct _reent *r,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Map flags to open modes
|
// Map flags to open modes
|
||||||
if ((flags & O_ACCMODE) == O_RDONLY) {
|
int commonFlagMask = O_CREAT | O_TRUNC | O_APPEND;
|
||||||
|
if (((flags & O_ACCMODE) == O_RDONLY) && !(flags & commonFlagMask)) {
|
||||||
fsMode = "r";
|
fsMode = "r";
|
||||||
if (flags & O_APPEND) {
|
} else if (((flags & O_ACCMODE) == O_RDWR) && !(flags & commonFlagMask)) {
|
||||||
r->_errno = EINVAL;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
} else if ((flags & O_ACCMODE) == O_WRONLY) {
|
|
||||||
if (flags & O_APPEND) {
|
|
||||||
fsMode = "a";
|
|
||||||
} else if (flags & O_TRUNC) {
|
|
||||||
fsMode = "w";
|
|
||||||
} else {
|
|
||||||
r->_errno = EINVAL;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
} else if ((flags & O_ACCMODE) == O_RDWR) {
|
|
||||||
if (flags & O_APPEND) {
|
|
||||||
fsMode = "a+";
|
|
||||||
} else if (flags & O_TRUNC) {
|
|
||||||
fsMode = "w+";
|
|
||||||
} else {
|
|
||||||
fsMode = "r+";
|
fsMode = "r+";
|
||||||
}
|
} else if (((flags & O_ACCMODE) == O_WRONLY) && ((flags & commonFlagMask) == (O_CREAT | O_TRUNC))) {
|
||||||
|
fsMode = "w";
|
||||||
|
} else if (((flags & O_ACCMODE) == O_RDWR) && ((flags & commonFlagMask) == (O_CREAT | O_TRUNC))) {
|
||||||
|
fsMode = "w+";
|
||||||
|
} else if (((flags & O_ACCMODE) == O_WRONLY) && ((flags & commonFlagMask) == (O_CREAT | O_APPEND))) {
|
||||||
|
fsMode = "a";
|
||||||
|
} else if (((flags & O_ACCMODE) == O_RDWR) && ((flags & commonFlagMask) == (O_CREAT | O_APPEND))) {
|
||||||
|
fsMode = "a+";
|
||||||
} else {
|
} else {
|
||||||
r->_errno = EINVAL;
|
r->_errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
@ -56,7 +48,7 @@ int __fsa_open(struct _reent *r,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Open the file
|
// Open the file
|
||||||
FSOpenFileFlags openFlags = (mode & O_ENCRYPTED) ? FS_OPEN_FLAG_ENCRYPTED : FS_OPEN_FLAG_NONE;
|
FSOpenFileFlags openFlags = (mode & O_UNENCRYPTED) ? FS_OPEN_FLAG_ENCRYPTED : FS_OPEN_FLAG_NONE;
|
||||||
|
|
||||||
auto *deviceData = (FSADeviceData *) r->deviceData;
|
auto *deviceData = (FSADeviceData *) r->deviceData;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user