Merge pull request #352 from wheremyfoodat/zep

Filesystem fixes
This commit is contained in:
wheremyfoodat
2023-12-17 21:09:45 +02:00
committed by GitHub
2 changed files with 29 additions and 0 deletions

View File

@@ -148,6 +148,11 @@ void Kernel::writeFile(u32 messagePointer, Handle fileHandle) {
IOFile f(file->fd); IOFile f(file->fd);
auto [success, bytesWritten] = f.writeBytes(data.get(), size); 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)); mem.write32(messagePointer, IPC::responseHeader(0x0803, 2, 2));
if (!success) { if (!success) {
Helpers::panic("Kernel::WriteFile failed"); Helpers::panic("Kernel::WriteFile failed");

View File

@@ -179,6 +179,30 @@ u32 Kernel::getTLSPointer() {
// Result CloseHandle(Handle handle) // Result CloseHandle(Handle handle)
void Kernel::svcCloseHandle() { void Kernel::svcCloseHandle() {
logSVC("CloseHandle(handle = %d) (Unimplemented)\n", regs[0]); 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; regs[0] = Result::Success;
} }