Skip to content
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM ghcr.io/wiiu-env/devkitppc:20241128
FROM ghcr.io/wiiu-env/devkitppc:20260225

COPY --from=ghcr.io/wiiu-env/libfunctionpatcher:20230621 /artifacts $DEVKITPRO
COPY --from=ghcr.io/wiiu-env/wiiumodulesystem:20250208 /artifacts $DEVKITPRO
COPY --from=ghcr.io/wiiu-env/libcontentredirection:20250208 /artifacts $DEVKITPRO
COPY --from=ghcr.io/wiiu-env/libfunctionpatcher:20260331 /artifacts $DEVKITPRO
COPY --from=ghcr.io/wiiu-env/wiiumodulesystem:20260418 /artifacts $DEVKITPRO
COPY --from=ghcr.io/wiiu-env/libcontentredirection:20260418 /artifacts $DEVKITPRO

WORKDIR project
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ INCLUDES := src
#-------------------------------------------------------------------------------
# options for code generation
#-------------------------------------------------------------------------------
CFLAGS := -Wall -Wextra -Os -ffunction-sections\
CFLAGS := -Wall -Werror -Wextra -O2 -ffunction-sections\
$(MACHDEP)

CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__
Expand Down
30 changes: 15 additions & 15 deletions src/FSWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ FSError FSWrapper::FSReadDirWrapper(const FSDirectoryHandle handle, FSDirectoryE
DIR *dir = dirHandle->dir;

FSError result = FS_ERROR_END_OF_DIR;
DEBUG_FUNCTION_LINE_VERBOSE("[%s] readdir %08X (handle %08X)", getName().c_str(), dir, handle);
DEBUG_FUNCTION_LINE_VERBOSE("[%s] readdir %p (handle %08X)", getName().c_str(), dir, handle);
do {
errno = 0;
struct dirent *entry_ = readdir(dir);
Expand All @@ -86,7 +86,7 @@ FSError FSWrapper::FSReadDirWrapper(const FSDirectoryHandle handle, FSDirectoryE
continue;
}
entry->name[0] = '\0';
strncat(entry->name, entry_->d_name, sizeof(entry->name) - 1);
strlcpy(entry->name, entry_->d_name, sizeof(entry->name));
entry->info.mode = (FSMode) FS_MODE_READ_OWNER;
if (entry_->d_type == DT_DIR) {
entry->info.flags = (FSStatFlags) ((uint32_t) FS_STAT_DIRECTORY);
Expand Down Expand Up @@ -128,7 +128,7 @@ FSError FSWrapper::FSReadDirWrapper(const FSDirectoryHandle handle, FSDirectoryE
} else {
auto err = errno;
if (err != 0) {
DEBUG_FUNCTION_LINE_ERR("[%s] Failed to read dir %08X (handle %08X). errno %d (%s)", getName().c_str(), dir, handle, err, strerror(err));
DEBUG_FUNCTION_LINE_ERR("[%s] Failed to read dir %p (handle %08X). errno %d (%s)", getName().c_str(), dir, handle, err, strerror(err));
result = FS_ERROR_MEDIA_ERROR;
}
}
Expand All @@ -146,9 +146,9 @@ FSError FSWrapper::FSCloseDirWrapper(const FSDirectoryHandle handle) {
DIR *dir = dirHandle->dir;

FSError result = FS_ERROR_OK;
DEBUG_FUNCTION_LINE_VERBOSE("[%s] closedir %08X (handle %08X)", getName().c_str(), dir, handle);
DEBUG_FUNCTION_LINE_VERBOSE("[%s] closedir %p (handle %08X)", getName().c_str(), dir, handle);
if (closedir(dir) < 0) {
DEBUG_FUNCTION_LINE_ERR("[%s] Failed to close dir %08X (handle %08X)", getName().c_str(), dir, handle);
DEBUG_FUNCTION_LINE_ERR("[%s] Failed to close dir %p (handle %08X)", getName().c_str(), dir, handle);
result = FS_ERROR_MEDIA_ERROR;
}
dirHandle->dir = nullptr;
Expand All @@ -164,7 +164,7 @@ FSError FSWrapper::FSRewindDirWrapper(const FSDirectoryHandle handle) {

DIR *dir = dirHandle->dir;

DEBUG_FUNCTION_LINE_VERBOSE("[%s] rewinddir %08X (handle %08X)", getName().c_str(), dir, handle);
DEBUG_FUNCTION_LINE_VERBOSE("[%s] rewinddir %p (handle %08X)", getName().c_str(), dir, handle);
rewinddir(dir);

return FS_ERROR_OK;
Expand Down Expand Up @@ -249,7 +249,7 @@ FSError FSWrapper::FSOpenFileWrapper(const char *path, const char *mode, FSFileH
if (fd >= 0) {
auto fileHandle = getNewFileHandle();
if (fileHandle) {
std::lock_guard<std::mutex> lock(openFilesMutex);
std::lock_guard lock(openFilesMutex);

fileHandle->handle = (((uint32_t) fileHandle.get()) & 0x0FFFFFFF) | 0x30000000;
*handle = fileHandle->handle;
Expand Down Expand Up @@ -397,7 +397,7 @@ FSError FSWrapper::FSReadFileWrapper(void *buffer, const uint32_t size, const ui
auto fileHandle = getFileFromHandle(handle);
int real_fd = fileHandle->fd;

DEBUG_FUNCTION_LINE_VERBOSE("[%s] Read %u bytes of fd %08X (FSFileHandle %08X) to buffer %08X", getName().c_str(), size * count, real_fd, handle, buffer);
DEBUG_FUNCTION_LINE_VERBOSE("[%s] Read %u bytes of fd %08X (FSFileHandle %08X) to buffer %p", getName().c_str(), size * count, real_fd, handle, buffer);
int64_t read = readIntoBuffer(real_fd, buffer, size, count);

FSError result;
Expand Down Expand Up @@ -468,7 +468,7 @@ FSError FSWrapper::FSGetPosFileWrapper(const FSFileHandle handle, uint32_t *pos)
DEBUG_FUNCTION_LINE_VERBOSE("[%s] lseek fd %08X (FSFileHandle %08X) to get current position for truncation", getName().c_str(), real_fd, handle);
off_t currentPos = lseek(real_fd, (off_t) 0, SEEK_CUR);
if (currentPos == -1) {
DEBUG_FUNCTION_LINE_ERR("[%s] Failed to get current position (res: %lld) of fd (handle %08X) to check EoF", getName().c_str(), currentPos, real_fd, handle);
DEBUG_FUNCTION_LINE_ERR("[%s] Failed to get current position (res: %lld) of fd %08X (handle %08X) to check EoF", getName().c_str(), currentPos, real_fd, handle);
result = FS_ERROR_MEDIA_ERROR;
} else {
*pos = currentPos;
Expand All @@ -493,7 +493,7 @@ FSError FSWrapper::FSIsEofWrapper(const FSFileHandle handle) {

if (currentPos == -1 || endPos == -1) {
// TODO: check errno
DEBUG_FUNCTION_LINE_ERR("[%s] Failed to get current position (res: %lld) or endPos (res: %lld) of fd (handle %08X) to check EoF", getName().c_str(), currentPos, endPos, real_fd, handle);
DEBUG_FUNCTION_LINE_ERR("[%s] Failed to get current position (res: %lld) or endPos (res: %lld) of fd %08X (handle %08X) to check EoF", getName().c_str(), currentPos, endPos, real_fd, handle);
result = FS_ERROR_MEDIA_ERROR;
} else if (currentPos == endPos) {
DEBUG_FUNCTION_LINE_VERBOSE("[%s] FSIsEof END for %d\n", getName().c_str(), real_fd);
Expand All @@ -512,7 +512,7 @@ FSError FSWrapper::FSTruncateFileWrapper(const FSFileHandle handle) {
return FS_ERROR_FORCE_PARENT_LAYER;
}

if (!pIsWriteable) {
if (pIsWriteable) {
DEBUG_FUNCTION_LINE_VERBOSE("[%s] Tried to truncate fd %d (handle %08X) but layer is not writeable", getName().c_str(), getFileFromHandle(handle)->fd, handle);
return FS_ERROR_ACCESS_ERROR;
}
Expand All @@ -527,7 +527,7 @@ FSError FSWrapper::FSTruncateFileWrapper(const FSFileHandle handle) {
off_t currentPos = lseek(real_fd, (off_t) 0, SEEK_CUR);
if (currentPos == -1) {
// TODO check errno
DEBUG_FUNCTION_LINE_ERR("[%s] Failed to get current position of fd (handle %08X) to truncate file", getName().c_str(), real_fd, handle);
DEBUG_FUNCTION_LINE_ERR("[%s] Failed to get current position of fd %08X (handle %08X) to truncate file", getName().c_str(), real_fd, handle);
result = FS_ERROR_MEDIA_ERROR;
} else {
DEBUG_FUNCTION_LINE_VERBOSE("[%s] Truncate fd %08X (FSFileHandle %08X) to %lld bytes ", getName().c_str(), real_fd, handle, currentPos);
Expand All @@ -554,11 +554,11 @@ FSError FSWrapper::FSWriteFileWrapper(const uint8_t *buffer, const uint32_t size

int real_fd = fileHandle->fd;

DEBUG_FUNCTION_LINE_VERBOSE("[%s] Write %u bytes to fd %08X (FSFileHandle %08X) from buffer %08X", getName().c_str(), count * size, real_fd, handle, buffer);
DEBUG_FUNCTION_LINE_VERBOSE("[%s] Write %u bytes to fd %08X (FSFileHandle %08X) from buffer %p", getName().c_str(), count * size, real_fd, handle, buffer);
auto writeRes = writeFromBuffer(real_fd, buffer, size, count);
if (writeRes < 0) {
auto err = errno;
DEBUG_FUNCTION_LINE_ERR("[%s] Write failed %u bytes to fd %08X (FSFileHandle %08X) from buffer %08X errno %d", getName().c_str(), count * size, real_fd, handle, buffer, err);
DEBUG_FUNCTION_LINE_ERR("[%s] Write failed %u bytes to fd %08X (FSFileHandle %08X) from buffer %p errno %d", getName().c_str(), count * size, real_fd, handle, buffer, err);
if (err == EFBIG) {
result = FS_ERROR_FILE_TOO_BIG;
} else if (err == EACCES) {
Expand Down Expand Up @@ -640,7 +640,7 @@ FSError FSWrapper::FSFlushFileWrapper(const FSFileHandle handle) {
const auto fileHandle = getFileFromHandle(handle);
const int real_fd = fileHandle->fd;

DEBUG_FUNCTION_LINE_VERBOSE("[%s] fsync fd %08X (FSFileHandle %08X)", real_fd, handle);
DEBUG_FUNCTION_LINE_VERBOSE("[%s] fsync fd %08X (FSFileHandle %08X)", getName().c_str(), real_fd, handle);
FSError result = FS_ERROR_OK;
if (fsync(real_fd) < 0) {
DEBUG_FUNCTION_LINE_ERR("[%s] fsync failed for fd %08X (FSFileHandle %08X)", getName().c_str(), real_fd, handle);
Expand Down
4 changes: 2 additions & 2 deletions src/FSWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ class FSWrapper : public IFSWrapper {
std::string pPathToReplace;
std::string pReplacePathWith;
bool pIsWriteable = false;
std::mutex openFilesMutex;
std::mutex openDirsMutex;
std::recursive_mutex openFilesMutex;
std::recursive_mutex openDirsMutex;
std::vector<std::shared_ptr<FileInfo>> openFiles;
std::vector<std::shared_ptr<DirInfoBase>> openDirs;
};
6 changes: 3 additions & 3 deletions src/FSWrapperMergeDirsWithParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ FSError FSWrapperMergeDirsWithParent::FSReadDirWrapper(FSADirectoryHandle handle
if (dirHandle->readResultCapacity == 0) {
dirHandle->readResult = (FSDirectoryEntryEx *) malloc(sizeof(FSDirectoryEntryEx));
if (dirHandle->readResult == nullptr) {
DEBUG_FUNCTION_LINE_ERR("[%s] Failed to alloc memory for %08X (handle %08X)", getName().c_str(), dirHandle.get(), handle);
DEBUG_FUNCTION_LINE_ERR("[%s] Failed to alloc memory for %p (handle %08X)", getName().c_str(), dirHandle.get(), handle);
OSFatal("ContentRedirectionModule: Failed to alloc memory for read result");
}
dirHandle->readResultCapacity = 1;
Expand All @@ -79,7 +79,7 @@ FSError FSWrapperMergeDirsWithParent::FSReadDirWrapper(FSADirectoryHandle handle
dirHandle->readResult = (FSDirectoryEntryEx *) realloc(dirHandle->readResult, newCapacity * sizeof(FSDirectoryEntryEx));
dirHandle->readResultCapacity = newCapacity;
if (dirHandle->readResult == nullptr) {
DEBUG_FUNCTION_LINE_ERR("[%s] Failed to realloc memory for %08X (handle %08X)", getName().c_str(), dirHandle.get(), handle);
DEBUG_FUNCTION_LINE_ERR("[%s] Failed to realloc memory for %p (handle %08X)", getName().c_str(), dirHandle.get(), handle);
OSFatal("ContentRedirectionModule: Failed to alloc memory for read result");
}
}
Expand Down Expand Up @@ -242,7 +242,7 @@ FSWrapperMergeDirsWithParent::~FSWrapperMergeDirsWithParent() {
if (mClientHandle) {
FSError res;
if ((res = FSADelClient(mClientHandle)) != FS_ERROR_OK) {
DEBUG_FUNCTION_LINE_ERR("[%s] FSADelClient failed: %s (%d)", FSAGetStatusStr(res), res);
DEBUG_FUNCTION_LINE_ERR("[%s] FSADelClient failed: %s (%d)", pName.c_str(), FSAGetStatusStr(res), res);
}
mClientHandle = 0;
}
Expand Down
4 changes: 2 additions & 2 deletions src/FSWrapperReplaceSingleFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ FSWrapperReplaceSingleFile::FSWrapperReplaceSingleFile(const std::string &name,
FSWrapperReplaceSingleFile::~FSWrapperReplaceSingleFile() {
if (mClientHandle) {
if (const FSError res = FSADelClient(mClientHandle); res != FS_ERROR_OK) {
DEBUG_FUNCTION_LINE_ERR("[%s] FSADelClient failed: %s (%d)", FSAGetStatusStr(res), res);
DEBUG_FUNCTION_LINE_ERR("[%s] FSADelClient failed: %s (%d)", pName.c_str(), FSAGetStatusStr(res), res);
}
mClientHandle = 0;
}
Expand Down Expand Up @@ -115,7 +115,7 @@ FSError FSWrapperReplaceSingleFile::FSReadDirWrapper(const FSADirectoryHandle ha
continue;
}
translate_stat(&path_stat, &dirHandle->directoryEntry.info);
strncpy(dirHandle->directoryEntry.name, mFileNameToReplace.c_str(), sizeof(dirHandle->directoryEntry.name));
strncpy(dirHandle->directoryEntry.name, mFileNameToReplace.c_str(), sizeof(dirHandle->directoryEntry.name) - 1);
memcpy(entry, &dirHandle->directoryEntry, sizeof(FSADirectoryEntry));

dirHandle->entryReadSuccess = true;
Expand Down
18 changes: 9 additions & 9 deletions src/FileUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
#include <unistd.h>

namespace {
std::mutex sWorkingDirMutex;
std::recursive_mutex sWorkingDirMutex;
std::map<FSAClientHandle, std::string> sWorkingDirs;
} // namespace

std::mutex gFSLayerMutex;
std::recursive_mutex gFSLayerMutex;
std::vector<std::unique_ptr<IFSWrapper>> gFSLayers;

std::string getFullPathGeneric(const FSAClientHandle client, const char *path, std::mutex &mutex, const std::map<FSAClientHandle, std::string> &map) {
std::string getFullPathGeneric(const FSAClientHandle client, const char *path, std::recursive_mutex &mutex, const std::map<FSAClientHandle, std::string> &map) {
std::lock_guard workingDirLock(mutex);

std::string res;
Expand All @@ -39,7 +39,7 @@ std::string getFullPathGeneric(const FSAClientHandle client, const char *path, s
return res;
}

void setWorkingDirGeneric(const FSAClientHandle client, const char *path, std::mutex &mutex, std::map<FSAClientHandle, std::string> &map) {
void setWorkingDirGeneric(const FSAClientHandle client, const char *path, std::recursive_mutex &mutex, std::map<FSAClientHandle, std::string> &map) {
if (!path) {
DEBUG_FUNCTION_LINE_WARN("Path was NULL");
return;
Expand Down Expand Up @@ -209,10 +209,10 @@ FSError doForLayer(FSShimWrapper *param) {

auto *request = &param->shim->request.readFile;
if (request->readFlags == FSA_READ_FLAG_NONE) {
DEBUG_FUNCTION_LINE_VERBOSE("[%s] ReadFile: buffer %08X size %08X count %08X handle %08X", layer->getName().c_str(), request->buffer, request->size, request->count, request->handle);
DEBUG_FUNCTION_LINE_VERBOSE("[%s] ReadFile: buffer %p size %08X count %08X handle %08X", layer->getName().c_str(), request->buffer, request->size, request->count, request->handle);
layerResult = layer->FSReadFileWrapper(request->buffer, request->size, request->count, request->handle, 0);
} else if (request->readFlags == FSA_READ_FLAG_READ_WITH_POS) {
DEBUG_FUNCTION_LINE_VERBOSE("[%s] ReadFileWithPos: buffer %08X size %08X count %08X pos %08X handle %08X", layer->getName().c_str(), request->buffer, request->size, request->count, request->pos, request->handle);
DEBUG_FUNCTION_LINE_VERBOSE("[%s] ReadFileWithPos: buffer %p size %08X count %08X pos %08X handle %08X", layer->getName().c_str(), request->buffer, request->size, request->count, request->pos, request->handle);
layerResult = layer->FSReadFileWithPosWrapper(request->buffer, request->size, request->count, request->pos, request->handle, 0);
}
break;
Expand Down Expand Up @@ -250,10 +250,10 @@ FSError doForLayer(FSShimWrapper *param) {

auto *request = &param->shim->request.writeFile;
if (request->writeFlags == FSA_WRITE_FLAG_NONE) {
DEBUG_FUNCTION_LINE_VERBOSE("[%s] WriteFile: buffer %08X size %08X count %08X handle %08X", layer->getName().c_str(), request->buffer, request->size, request->count, request->handle);
DEBUG_FUNCTION_LINE_VERBOSE("[%s] WriteFile: buffer %p size %08X count %08X handle %08X", layer->getName().c_str(), request->buffer, request->size, request->count, request->handle);
layerResult = layer->FSWriteFileWrapper(request->buffer, request->size, request->count, request->handle, 0);
} else if (request->writeFlags == FSA_WRITE_FLAG_READ_WITH_POS) {
DEBUG_FUNCTION_LINE_VERBOSE("[%s] WriteFileWithPos: buffer %08X size %08X count %08X pos %08X handle %08X", layer->getName().c_str(), request->buffer, request->size, request->count, request->pos, request->handle);
DEBUG_FUNCTION_LINE_VERBOSE("[%s] WriteFileWithPos: buffer %p size %08X count %08X pos %08X handle %08X", layer->getName().c_str(), request->buffer, request->size, request->count, request->pos, request->handle);
layerResult = layer->FSWriteFileWithPosWrapper(request->buffer, request->size, request->count, request->pos, request->handle, 0);
}
break;
Expand Down Expand Up @@ -527,7 +527,7 @@ void startFSIOThreads() {
continue;
}
threadData->stack = (uint8_t *) memalign(0x20, stackSize);
if (!threadData->thread) {
if (!threadData->stack) {
free(threadData->thread);
DEBUG_FUNCTION_LINE_ERR("Failed to allocate threadData stack");
OSFatal("ContentRedirectionModule: Failed to allocate IO Thread stack");
Expand Down
4 changes: 2 additions & 2 deletions src/FileUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct FSIOThreadData {
OSThread *thread;
void *stack;
OSMessageQueue queue;
OSMessage messages[0x10];
OSMessage messages[0x40];
bool setup;
char threadName[0x50];
};
Expand Down Expand Up @@ -55,7 +55,7 @@ struct FSShimWrapperMessage {

extern bool gThreadsRunning;
extern FSIOThreadData gThreadData[3];
extern std::mutex gFSLayerMutex;
extern std::recursive_mutex gFSLayerMutex;
extern std::vector<std::unique_ptr<IFSWrapper>> gFSLayers;

#define fsaShimPrepareRequestReadFile ((FSError(*)(FSAShimBuffer * shim, IOSHandle clientHandle, uint8_t * buffer, uint32_t size, uint32_t count, uint32_t pos, FSFileHandle handle, FSAReadFlag readFlags))(0x101C400 + 0x436cc))
Expand Down
Loading
Loading