Skip to content

Commit

Permalink
wutdevoptab: Actually store the fullpath in __wut_fsa_file_t->fullPath
Browse files Browse the repository at this point in the history
  • Loading branch information
Maschell committed Apr 8, 2023
1 parent 65053c3 commit d6760fb
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
2 changes: 2 additions & 0 deletions libraries/wutdevoptab/devoptab_fsa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ FSError __init_wut_devoptab() {

__wut_fsa_device_data.isSDCard = true;
__wut_fsa_device_data.mounted = true;
__wut_fsa_device_data.cwd[0] = '/';
__wut_fsa_device_data.cwd[1] = '\0';
chdir("fs:/vol/external01");

FSADeviceInfo deviceInfo;
Expand Down
1 change: 1 addition & 0 deletions libraries/wutdevoptab/devoptab_fsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ typedef struct FSADeviceData {
bool isSDCard;
char name[32];
char mountPath[0x80];
char cwd[FS_MAX_PATH + 1];
FSAClientHandle clientHandle;
uint64_t deviceSizeInSectors;
uint32_t deviceSectorSize;
Expand Down
11 changes: 11 additions & 0 deletions libraries/wutdevoptab/devoptab_fsa_chdir.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <cstdio>
#include "devoptab_fsa.h"

int
Expand Down Expand Up @@ -25,6 +26,16 @@ __wut_fsa_chdir(struct _reent *r,
r->_errno = __wut_fsa_translate_error(status);
return -1;
}

// Remove trailing '/'
if (fixedPath[0] != '\0') {
if (fixedPath[strlen(fixedPath) - 1] == '/') {
fixedPath[strlen(fixedPath) - 1] = 0;
}
}

snprintf(deviceData->cwd, sizeof(deviceData->cwd), "%s", fixedPath);

free(fixedPath);

return 0;
Expand Down
22 changes: 15 additions & 7 deletions libraries/wutdevoptab/devoptab_fsa_open.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,17 @@ __wut_fsa_open(struct _reent *r,
}

file = (__wut_fsa_file_t *) fileStruct;
strncpy(file->fullPath, fixedPath, sizeof(file->fullPath) - 1);
deviceData = (__wut_fsa_device_t *) r->deviceData;

if (fixedPath[0] != '\0' && fixedPath[0] != '\\' && fixedPath[0] != '/') {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-truncation"
snprintf(file->fullPath, sizeof(file->fullPath), "%s/%s", deviceData->cwd, fixedPath);
#pragma GCC diagnostic pop
} else {
snprintf(file->fullPath, sizeof(file->fullPath), "%s", fixedPath);
}

free(fixedPath);

// Prepare flags
Expand All @@ -77,8 +87,6 @@ __wut_fsa_open(struct _reent *r,
file->mutex.init(file->fullPath);
std::lock_guard<MutexWrapper> lock(file->mutex);

deviceData = (__wut_fsa_device_t *) r->deviceData;

if (createFileIfNotFound || failIfFileNotFound || (flags & (O_EXCL | O_CREAT)) == (O_EXCL | O_CREAT)) {
// Check if file exists
FSAStat stat;
Expand Down Expand Up @@ -115,10 +123,10 @@ __wut_fsa_open(struct _reent *r,

status = FSAOpenFileEx(deviceData->clientHandle, file->fullPath, fsMode, translatedMode, openFlags, preAllocSize, &fd);
if (status < 0) {
if(status != FS_ERROR_NOT_FOUND) {
WUT_DEBUG_REPORT("FSAOpenFileEx(0x%08X, %s, %s, 0x%X, 0x%08X, 0x%08X, 0x%08X) failed: %s\n",
deviceData->clientHandle, file->fullPath, fsMode, translatedMode, openFlags, preAllocSize, &fd,
FSAGetStatusStr(status));
if (status != FS_ERROR_NOT_FOUND) {
WUT_DEBUG_REPORT("FSAOpenFileEx(0x%08X, %s, %s, 0x%X, 0x%08X, 0x%08X, 0x%08X) failed: %s\n",
deviceData->clientHandle, file->fullPath, fsMode, translatedMode, openFlags, preAllocSize, &fd,
FSAGetStatusStr(status));
}
r->_errno = __wut_fsa_translate_error(status);
return -1;
Expand Down

0 comments on commit d6760fb

Please sign in to comment.