From 3b3b36dcc6542e203475fe1d50ed89799e3f3fc6 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 25 Mar 2024 20:17:53 +0100 Subject: Kernel: implement some tickets, improved stuff. Signed-off-by: Amlal El Mahrouss --- Public/Developer/System.Core/Headers/File.hxx | 105 ++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 Public/Developer/System.Core/Headers/File.hxx (limited to 'Public/Developer/System.Core/Headers/File.hxx') diff --git a/Public/Developer/System.Core/Headers/File.hxx b/Public/Developer/System.Core/Headers/File.hxx new file mode 100644 index 00000000..06c2a22e --- /dev/null +++ b/Public/Developer/System.Core/Headers/File.hxx @@ -0,0 +1,105 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#ifndef __FILE_API__ +#define __FILE_API__ + +#include + +namespace System { +class FileInterface; +class DirectoryInterface; + +typedef IntPtrType SymlinkType; +typedef IntPtrType FileType; +typedef IntPtrType DirectoryType; +typedef IntPtrType FSRef; + +enum { + kErrorNoSuchPath = -44, + kErrorNotAFile = -45, + kErrorNotADirectory = -46, + kErrorDirectory = -47, + kErrorBrokenSymlink = -48, +}; + +/// @brief System file interface + +class FileInterface final { + public: + explicit FileInterface(const char *path) { + mHandle = kApplicationObject->Invoke(kApplicationObject, kProcessCallOpenHandle, + 0, path); + } + + ~FileInterface() { + kApplicationObject->Invoke(kApplicationObject, kProcessCallCloseHandle, 0, + mHandle); + } + + public: + CA_COPY_DEFAULT(FileInterface); + + public: + PtrVoidType Read(UIntPtrType off, SizeType sz) { + return (PtrVoidType)kApplicationObject->Invoke(kApplicationObject, mHandle, 2, + off, sz); + } + PtrVoidType Read(SizeType sz) { + return (PtrVoidType)kApplicationObject->Invoke(kApplicationObject, mHandle, 3, + sz); + } + + void Write(PtrVoidType buf, UIntPtrType off, SizeType sz) { + kApplicationObject->Invoke(kApplicationObject, mHandle, 4, buf, off, sz); + } + void Write(PtrVoidType buf, SizeType sz) { + kApplicationObject->Invoke(kApplicationObject, mHandle, 5, buf, sz); + } + + void Seek(UIntPtrType off) { + kApplicationObject->Invoke(kApplicationObject, mHandle, 5); + } + void Rewind() { kApplicationObject->Invoke(kApplicationObject, mHandle, 6); } + + public: + const char *MIME(); + void MIME(const char *mime); + + private: + FileType mHandle; +}; + +typedef FileInterface *FilePtr; + +/// @brief file exception +/// Throws when the file isn't found or invalid. +class FileException : public SystemException { + public: + explicit FileException() = default; + virtual ~FileException() = default; + + public: + CA_COPY_DEFAULT(FileException); + + public: + const char *Name() override { return "FileException"; } + const char *Reason() override { return mReason; } + + private: + const char *mReason{"System.Core: FileException: Catastrophic failure!"}; +}; + +inline IntPtrType MakeSymlink(const char *from, const char *outputWhere) { + CA_MUST_PASS(from); + CA_MUST_PASS(outputWhere); + + return kApplicationObject->Invoke(kApplicationObject, kProcessCallOpenHandle, 1, + from); +} +} // namespace System + +#endif // ifndef __FILE_API__ -- cgit v1.2.3