Skip to content

Commit

Permalink
Use a dedicated FSAClient instead of the wut_devoptab_fs_client.
Browse files Browse the repository at this point in the history
  • Loading branch information
Maschell committed Aug 3, 2022
1 parent c8a6879 commit f09f8f2
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 21 deletions.
8 changes: 4 additions & 4 deletions source/GMPartitionsDumperState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions source/WUD/DiscReaderDiscDrive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
}
Expand All @@ -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;
}
Expand Down
16 changes: 8 additions & 8 deletions source/WUDDumperState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
}
Expand Down
1 change: 1 addition & 0 deletions source/common/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ int ntfs_mount_count = 0;
BOOL gRunFromHBL = false;
BOOL gBlockHomeButton = false;
uint32_t gBlockHomeButtonCooldown = 0;
FSAClientHandle gFSAClientHandle = 0;
4 changes: 3 additions & 1 deletion source/common/common.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <coreinit/filesystem_fsa.h>
#include <ntfs.h>
#include <wut.h>

Expand All @@ -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
Expand Down
15 changes: 12 additions & 3 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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) {
Expand Down

0 comments on commit f09f8f2

Please sign in to comment.