Use a dedicated FSAClient instead of the wut_devoptab_fs_client.

This commit is contained in:
Maschell 2022-08-02 10:25:12 +02:00
parent c8a687950f
commit f09f8f2b29
6 changed files with 33 additions and 21 deletions

View File

@ -37,7 +37,7 @@ GMPartitionsDumperState::GMPartitionsDumperState(eDumpTarget pTargetDevice) : ta
GMPartitionsDumperState::~GMPartitionsDumperState() {
if (this->oddFd != -1) {
FSAEx_RawClose(__wut_devoptab_fs_client, this->oddFd);
FSAEx_RawCloseEx(gFSAClientHandle, this->oddFd);
this->oddFd = -1;
}
free(this->sectorBuf);
@ -182,7 +182,7 @@ ApplicationState::eSubState GMPartitionsDumperState::update(Input *input) {
}
if (this->state == STATE_OPEN_ODD1) {
auto ret = FSAEx_RawOpen(__wut_devoptab_fs_client, "/dev/odd01", &(this->oddFd));
auto ret = FSAEx_RawOpenEx(gFSAClientHandle, "/dev/odd01", &(this->oddFd));
if (ret >= 0) {
if (this->sectorBuf == nullptr) {
this->sectorBuf = (void *) memalign(0x100, this->sectorBufSize);
@ -200,13 +200,13 @@ ApplicationState::eSubState GMPartitionsDumperState::update(Input *input) {
return ApplicationState::SUBSTATE_RETURN;
}
} else if (this->state == STATE_READ_DISC_INFO) {
if (FSAEx_RawRead(__wut_devoptab_fs_client, this->sectorBuf, READ_SECTOR_SIZE, 1, 0, this->oddFd) >= 0) {
if (FSAEx_RawReadEx(gFSAClientHandle, this->sectorBuf, READ_SECTOR_SIZE, 1, 0, this->oddFd) >= 0) {
this->discId[10] = '\0';
memcpy(this->discId.data(), sectorBuf, 10);
this->state = STATE_READ_DISC_INFO_DONE;
return ApplicationState::SUBSTATE_RUNNING;
}
FSAEx_RawClose(__wut_devoptab_fs_client, this->oddFd);
FSAEx_RawCloseEx(gFSAClientHandle, this->oddFd);
this->oddFd = -1;
this->setError(ERROR_READ_FIRST_SECTOR);

View File

@ -31,13 +31,13 @@ DiscReaderDiscDrive::DiscReaderDiscDrive() : DiscReader() {
return;
}
auto ret = FSAEx_RawOpen(__wut_devoptab_fs_client, "/dev/odd01", &device_handle);
auto ret = FSAEx_RawOpenEx(gFSAClientHandle, "/dev/odd01", &device_handle);
if (ret < 0) {
free(sector_buf);
return;
}
auto res = FSAEx_RawRead(__wut_devoptab_fs_client, sector_buf, READ_SECTOR_SIZE, 1, 3, device_handle);
auto res = FSAEx_RawReadEx(gFSAClientHandle, sector_buf, READ_SECTOR_SIZE, 1, 3, device_handle);
if (res >= 0) {
if (((uint32_t *) sector_buf)[0] != WiiUDiscContentsHeader::MAGIC) {
uint8_t iv[16];
@ -75,7 +75,7 @@ DiscReaderDiscDrive::DiscReaderDiscDrive() : DiscReader() {
}
bool DiscReaderDiscDrive::readEncryptedSector(uint8_t *buffer, uint32_t block_cnt, uint32_t block_offset) const {
if (FSAEx_RawRead(__wut_devoptab_fs_client, buffer, READ_SECTOR_SIZE, block_cnt, block_offset, device_handle) < 0) {
if (FSAEx_RawReadEx(gFSAClientHandle, buffer, READ_SECTOR_SIZE, block_cnt, block_offset, device_handle) < 0) {
return false;
}
return true;
@ -87,7 +87,7 @@ bool DiscReaderDiscDrive::IsReady() {
DiscReaderDiscDrive::~DiscReaderDiscDrive() {
if (device_handle != -1) {
FSAEx_RawClose(__wut_devoptab_fs_client, device_handle);
FSAEx_RawCloseEx(gFSAClientHandle, device_handle);
device_handle = -1;
}
}
@ -102,7 +102,7 @@ bool DiscReaderDiscDrive::readEncrypted(uint8_t *buf, uint64_t offset, uint32_t
}
uint32_t block_cnt = size >> 15;
uint32_t offset_in_sectors = offset >> 15;
if (FSAEx_RawRead(__wut_devoptab_fs_client, buf, 0x8000, block_cnt, offset_in_sectors, device_handle) < 0) {
if (FSAEx_RawReadEx(gFSAClientHandle, buf, 0x8000, block_cnt, offset_in_sectors, device_handle) < 0) {
DEBUG_FUNCTION_LINE_ERR("Failed to read from Disc");
return false;
}

View File

@ -35,7 +35,7 @@ WUDDumperState::WUDDumperState(WUDDumperState::eDumpTargetFormat pTargetFormat,
WUDDumperState::~WUDDumperState() {
if (this->oddFd >= 0) {
FSAEx_RawClose(__wut_devoptab_fs_client, oddFd);
FSAEx_RawCloseEx(gFSAClientHandle, oddFd);
}
free(sectorBuf);
free(emptySector);
@ -51,7 +51,7 @@ ApplicationState::eSubState WUDDumperState::update(Input *input) {
}
if (this->state == STATE_OPEN_ODD1) {
if (this->currentSector > 0) {
auto ret = FSAEx_RawOpen(__wut_devoptab_fs_client, "/dev/odd01", &(this->oddFd));
auto ret = FSAEx_RawOpenEx(gFSAClientHandle, "/dev/odd01", &(this->oddFd));
if (ret >= 0) {
// continue!
this->state = STATE_DUMP_DISC;
@ -65,7 +65,7 @@ ApplicationState::eSubState WUDDumperState::update(Input *input) {
this->state = STATE_PLEASE_INSERT_DISC;
return ApplicationState::SUBSTATE_RUNNING;
}
auto ret = FSAEx_RawOpen(__wut_devoptab_fs_client, "/dev/odd01", &(this->oddFd));
auto ret = FSAEx_RawOpenEx(gFSAClientHandle, "/dev/odd01", &(this->oddFd));
if (ret >= 0) {
if (this->sectorBuf == nullptr) {
this->sectorBuf = (void *) memalign(0x100, this->sectorBufSize);
@ -83,7 +83,7 @@ ApplicationState::eSubState WUDDumperState::update(Input *input) {
return SUBSTATE_RETURN;
}
} else if (this->state == STATE_READ_DISC_INFO) {
if (FSAEx_RawRead(__wut_devoptab_fs_client, this->sectorBuf, READ_SECTOR_SIZE, 1, 0, this->oddFd) >= 0) {
if (FSAEx_RawReadEx(gFSAClientHandle, this->sectorBuf, READ_SECTOR_SIZE, 1, 0, this->oddFd) >= 0) {
this->discId[10] = '\0';
memcpy(this->discId.data(), sectorBuf, 10);
this->state = STATE_READ_DISC_INFO_DONE;
@ -96,7 +96,7 @@ ApplicationState::eSubState WUDDumperState::update(Input *input) {
this->state = STATE_DUMP_DISC_KEY;
} else if (this->state == STATE_DUMP_DISC_KEY) {
// Read the WiiUDiscContentsHeader to determine if we need disckey and if it's the correct one.
auto res = FSAEx_RawRead(__wut_devoptab_fs_client, this->sectorBuf, READ_SECTOR_SIZE, 1, 3, this->oddFd);
auto res = FSAEx_RawReadEx(gFSAClientHandle, this->sectorBuf, READ_SECTOR_SIZE, 1, 3, this->oddFd);
WUDDiscKey discKey;
bool hasDiscKey = false;
if (res >= 0) {
@ -151,7 +151,7 @@ ApplicationState::eSubState WUDDumperState::update(Input *input) {
}
size_t numSectors = this->currentSector + READ_NUM_SECTORS > this->totalSectorCount ? this->totalSectorCount - this->currentSector : READ_NUM_SECTORS;
if ((this->readResult = FSAEx_RawRead(__wut_devoptab_fs_client, sectorBuf, READ_SECTOR_SIZE, numSectors, this->currentSector, this->oddFd)) >= 0) {
if ((this->readResult = FSAEx_RawReadEx(gFSAClientHandle, sectorBuf, READ_SECTOR_SIZE, numSectors, this->currentSector, this->oddFd)) >= 0) {
auto curWrittenSectors = fileHandle->writeSector((const uint8_t *) this->sectorBuf, numSectors);
if (curWrittenSectors < 0) {
this->setError(ERROR_WRITE_FAILED);
@ -180,7 +180,7 @@ ApplicationState::eSubState WUDDumperState::update(Input *input) {
} else {
this->state = STATE_WAIT_USER_ERROR_CONFIRM;
if (this->oddFd >= 0) {
FSAEx_RawClose(__wut_devoptab_fs_client, this->oddFd);
FSAEx_RawCloseEx(gFSAClientHandle, this->oddFd);
this->oddFd = -1;
}
return ApplicationState::SUBSTATE_RUNNING;
@ -203,7 +203,7 @@ ApplicationState::eSubState WUDDumperState::update(Input *input) {
} else if (this->state == STATE_WAIT_USER_ERROR_CONFIRM) {
if (this->autoSkipOnError) {
if (this->oddFd >= 0) {
FSAEx_RawClose(__wut_devoptab_fs_client, this->oddFd);
FSAEx_RawCloseEx(gFSAClientHandle, this->oddFd);
this->oddFd = -1;
}
}

View File

@ -4,3 +4,4 @@ int ntfs_mount_count = 0;
BOOL gRunFromHBL = false;
BOOL gBlockHomeButton = false;
uint32_t gBlockHomeButtonCooldown = 0;
FSAClientHandle gFSAClientHandle = 0;

View File

@ -1,5 +1,6 @@
#pragma once
#include <coreinit/filesystem_fsa.h>
#include <ntfs.h>
#include <wut.h>
@ -9,12 +10,13 @@
extern ntfs_md *ntfs_mounts;
extern int ntfs_mount_count;
extern "C" FSClient *__wut_devoptab_fs_client;
extern FSAClientHandle gFSAClientHandle;
extern BOOL gRunFromHBL;
extern BOOL gBlockHomeButton;
extern uint32_t gBlockHomeButtonCooldown;
enum eDumpTarget {
TARGET_SD,
TARGET_NTFS

View File

@ -53,9 +53,7 @@ int main(int argc, char **argv) {
ProcUIClearCallbacks();
ProcUIRegisterCallback(PROCUI_CALLBACK_HOME_BUTTON_DENIED,
&procHomeButtonDeniedCustom, NULL, 100);
&procHomeButtonDeniedCustom, nullptr, 100);
} else {
gRunFromHBL = false;
}
@ -76,8 +74,19 @@ int main(int argc, char **argv) {
WPADInput::init();
gFSAClientHandle = FSAAddClient(nullptr);
if (!gFSAClientHandle) {
OSFatal("FSAAddClient failed");
}
if (Mocha_UnlockFSClientEx(gFSAClientHandle) != MOCHA_RESULT_SUCCESS) {
OSFatal("Failed to unlock FSAClientHandle");
}
main_loop();
FSADelClient(gFSAClientHandle);
WPADInput::close();
if (ntfs_mounts != nullptr) {