From 2ab777fecd6d1f2be9d76d8071e9331f682604a5 Mon Sep 17 00:00:00 2001 From: wheremyfoodat Date: Fri, 10 Mar 2023 01:27:30 +0200 Subject: [PATCH] [Kernel] Implement File::SetPriority --- include/fs/archive_base.hpp | 5 +++-- include/kernel/kernel.hpp | 1 + src/core/kernel/file_operations.cpp | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/include/fs/archive_base.hpp b/include/fs/archive_base.hpp index 4391e3ed..b80154b0 100644 --- a/include/fs/archive_base.hpp +++ b/include/fs/archive_base.hpp @@ -91,14 +91,15 @@ struct FileSession { FILE* fd = nullptr; // File descriptor for file sessions that require them. FSPath path; FSPath archivePath; + u32 priority = 0; // TODO: What does this even do bool isOpen; FileSession(ArchiveBase* archive, const FSPath& filePath, const FSPath& archivePath, FILE* fd, bool isOpen = true) : - archive(archive), path(filePath), archivePath(archivePath), fd(fd), isOpen(isOpen) {} + archive(archive), path(filePath), archivePath(archivePath), fd(fd), isOpen(isOpen), priority(0) {} // For cloning a file session FileSession(const FileSession& other) : archive(other.archive), path(other.path), - archivePath(other.archivePath), fd(other.fd), isOpen(other.isOpen) {} + archivePath(other.archivePath), fd(other.fd), isOpen(other.isOpen), priority(other.priority) {} }; struct ArchiveSession { diff --git a/include/kernel/kernel.hpp b/include/kernel/kernel.hpp index 7a4a74b6..b953db8c 100644 --- a/include/kernel/kernel.hpp +++ b/include/kernel/kernel.hpp @@ -127,6 +127,7 @@ private: void writeFile(u32 messagePointer, Handle file); void getFileSize(u32 messagePointer, Handle file); void openLinkFile(u32 messagePointer, Handle file); + void setFilePriority(u32 messagePointer, Handle file); public: Kernel(CPU& cpu, Memory& mem, GPU& gpu); diff --git a/src/core/kernel/file_operations.cpp b/src/core/kernel/file_operations.cpp index 25bfbdc4..62111283 100644 --- a/src/core/kernel/file_operations.cpp +++ b/src/core/kernel/file_operations.cpp @@ -6,6 +6,7 @@ namespace FileOps { Write = 0x08030102, GetSize = 0x08040000, Close = 0x08080000, + SetPriority = 0x080A0040, OpenLinkFile = 0x080C0000 }; } @@ -24,6 +25,7 @@ void Kernel::handleFileOperation(u32 messagePointer, Handle file) { case FileOps::GetSize: getFileSize(messagePointer, file); break; case FileOps::OpenLinkFile: openLinkFile(messagePointer, file); break; case FileOps::Read: readFile(messagePointer, file); break; + case FileOps::SetPriority: setFilePriority(messagePointer, file); break; case FileOps::Write: writeFile(messagePointer, file); break; default: Helpers::panic("Unknown file operation: %08X", cmd); } @@ -182,4 +184,22 @@ void Kernel::openLinkFile(u32 messagePointer, Handle fileHandle) { mem.write32(messagePointer + 4, Result::Success); mem.write32(messagePointer + 12, handle); +} + +void Kernel::setFilePriority(u32 messagePointer, Handle fileHandle) { + const u32 priority = mem.read32(messagePointer + 4); + logFileIO("Setting priority of file %X to %d\n", fileHandle, priority); + + const auto p = getObject(fileHandle, KernelObjectType::File); + if (p == nullptr) [[unlikely]] { + Helpers::panic("Called GetFileSize on non-existent file"); + } + + FileSession* file = p->getData(); + if (!file->isOpen) { + Helpers::panic("Tried to clone closed file"); + } + file->priority = priority; + + mem.write32(messagePointer + 4, Result::Success); } \ No newline at end of file