Skip to content

Commit

Permalink
Merge pull request #352 from wheremyfoodat/zep
Browse files Browse the repository at this point in the history
Filesystem fixes
  • Loading branch information
wheremyfoodat authored Dec 17, 2023
2 parents 03292b5 + a82c033 commit 6dc75db
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/core/kernel/file_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ void Kernel::writeFile(u32 messagePointer, Handle fileHandle) {
IOFile f(file->fd);
auto [success, bytesWritten] = f.writeBytes(data.get(), size);

// TODO: Should this check only the byte?
if (writeOption) {
f.flush();
}

mem.write32(messagePointer, IPC::responseHeader(0x0803, 2, 2));
if (!success) {
Helpers::panic("Kernel::WriteFile failed");
Expand Down
24 changes: 24 additions & 0 deletions src/core/kernel/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,30 @@ u32 Kernel::getTLSPointer() {
// Result CloseHandle(Handle handle)
void Kernel::svcCloseHandle() {
logSVC("CloseHandle(handle = %d) (Unimplemented)\n", regs[0]);
const Handle handle = regs[0];

KernelObject* object = getObject(handle);
if (object != nullptr) {
switch (object->type) {
// Close file descriptor when closing a file to prevent leaks and properly flush file contents
case KernelObjectType::File: {
FileSession* file = object->getData<FileSession>();
if (file->isOpen) {
file->isOpen = false;

if (file->fd != nullptr) {
fclose(file->fd);
file->fd = nullptr;
}
}
break;
}

default: break;
}
}

// Stub to always succeed for now
regs[0] = Result::Success;
}

Expand Down

0 comments on commit 6dc75db

Please sign in to comment.