diff options
| author | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-03-28 20:54:33 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-03-28 20:54:33 +0100 |
| commit | b2c7b8604ed3a4c209a15a9ffd718a43163dd9b4 (patch) | |
| tree | 851d79e3a9b1c676b48ec8dfcd2b989f4da45c9b /Private | |
| parent | 215518ae55a54973a1ae18f572ca5bf0ac2a499e (diff) | |
NewKernel: Add PowerPC partition type inside EPM, add Leak() FileStream method. and documentation.
SystemLib: Start implementing the API.
Signed-off-by: Amlal El Mahrouss <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'Private')
| -rw-r--r-- | Private/FSKit/NewFS.hxx | 18 | ||||
| -rw-r--r-- | Private/FirmwareKit/EPM.hxx | 4 | ||||
| -rw-r--r-- | Private/KernelKit/FileManager.hpp | 46 | ||||
| -rw-r--r-- | Private/Source/NewFS+FileManager.cxx | 2 | ||||
| -rw-r--r-- | Private/StorageKit/AHCI.hpp | 21 | ||||
| -rw-r--r-- | Private/StorageKit/ATA.hpp | 43 | ||||
| -rw-r--r-- | Private/StorageKit/Storage.hpp | 2 | ||||
| -rw-r--r-- | Private/StorageKit/StorageCore.inl | 41 |
8 files changed, 106 insertions, 71 deletions
diff --git a/Private/FSKit/NewFS.hxx b/Private/FSKit/NewFS.hxx index 43596d62..6b852f73 100644 --- a/Private/FSKit/NewFS.hxx +++ b/Private/FSKit/NewFS.hxx @@ -171,17 +171,21 @@ class NewFSParser { HCORE_COPY_DEFAULT(NewFSParser); public: - virtual void CreateFork(_Input NewCatalog& catalog, _Input NewFork& theFork) = 0; + virtual _Output NewFork* CreateFork(_Input NewCatalog* catalog, _Input NewFork& theFork) = 0; - virtual _Output NewFork* FindFork(_Input NewCatalog& catalog, _Input const Char* name) = 0; + virtual _Output NewFork* FindFork(_Input NewCatalog* catalog, _Input const Char* name) = 0; + + virtual _Output Void RemoveFork(_Input NewFork* fork) = 0; + + virtual _Output Void CloseFork(_Input NewFork* fork) = 0; virtual _Output NewCatalog* FindCatalog(const char* catalogName) = 0; virtual _Output NewCatalog* RootCatalog() = 0; - virtual _Output NewCatalog* NextCatalog(_Input _Output NewCatalog& cur) = 0; + virtual _Output NewCatalog* NextCatalog(_Input _Output NewCatalog* cur) = 0; - virtual _Output NewCatalog* PrevCatalog(_Input _Output NewCatalog& cur) = 0; + virtual _Output NewCatalog* PrevCatalog(_Input _Output NewCatalog* cur) = 0; virtual _Output NewCatalog* GetCatalog(_Input const char* name) = 0; @@ -191,15 +195,15 @@ class NewFSParser { virtual _Output NewCatalog* CreateCatalog(_Input const char* name) = 0; - virtual bool WriteCatalog(_Input _Output NewCatalog& catalog, + virtual bool WriteCatalog(_Input _Output NewCatalog* catalog, voidPtr data) = 0; - virtual bool RemoveCatalog(_Input _Output NewCatalog& catalog) = 0; + virtual bool RemoveCatalog(_Input _Output NewCatalog* catalog) = 0; /// @brief Make a EPM+NewFS drive out of the disk. /// @param drive The drive to write on. /// @return If it was sucessful, see DbgLastError(). - virtual bool Format(_Input _Output DriveTrait& drive) = 0; + virtual bool Format(_Input _Output DriveTrait* drive) = 0; }; /// diff --git a/Private/FirmwareKit/EPM.hxx b/Private/FirmwareKit/EPM.hxx index 5657fb06..34346a97 100644 --- a/Private/FirmwareKit/EPM.hxx +++ b/Private/FirmwareKit/EPM.hxx @@ -71,6 +71,10 @@ struct PACKED PartitionBlock { #define kEPMMagic32k "EPM32" +/* @brief PowerPC magic for EPM */ + +#define kEPMMagicPPC "EPMPC" + /* @brief Invalid magic for EPM */ #define kEPMMagicError "EPM??" diff --git a/Private/KernelKit/FileManager.hpp b/Private/KernelKit/FileManager.hpp index 1ce8d629..9f7249cd 100644 --- a/Private/KernelKit/FileManager.hpp +++ b/Private/KernelKit/FileManager.hpp @@ -38,6 +38,7 @@ /// refer to first enum. #define kFileOpsCount 4 +#define kFileMimeGeneric "application-type/*" namespace NewOS { enum { @@ -63,8 +64,17 @@ class FilesystemManagerInterface { HCORE_COPY_DEFAULT(FilesystemManagerInterface); public: - static bool Mount(FilesystemManagerInterface *pMount); + /// @brief Mounts a new filesystem into an active state. + /// @param interface the filesystem interface + /// @return + static bool Mount(FilesystemManagerInterface *interface); + + /// @brief Unmounts the active filesystem + /// @return static FilesystemManagerInterface *Unmount(); + + /// @brief Getter, gets the active filesystem. + /// @return static FilesystemManagerInterface *GetMounted(); public: @@ -79,8 +89,10 @@ class FilesystemManagerInterface { virtual NodePtr Open(_Input const char *path, _Input const char *r) = 0; public: - virtual void Write(_Input NodePtr node, _Input VoidPtr data, _Input Int32 flags) = 0; - virtual _Output VoidPtr Read(_Input NodePtr node, _Input Int32 flags, _Input SizeT sz) = 0; + virtual Void Write(_Input NodePtr node, _Input VoidPtr data, + _Input Int32 flags) = 0; + virtual _Output VoidPtr Read(_Input NodePtr node, _Input Int32 flags, + _Input SizeT sz) = 0; public: virtual bool Seek(_Input NodePtr node, _Input SizeT off) = 0; @@ -95,7 +107,8 @@ class FilesystemManagerInterface { #ifdef __FSKIT_NEWFS__ /** - * @brief Based of FilesystemManagerInterface, takes care of managing NewFS disks. + * @brief Based of FilesystemManagerInterface, takes care of managing NewFS + * disks. */ class NewFilesystemManager final : public FilesystemManagerInterface { public: @@ -127,6 +140,12 @@ class NewFilesystemManager final : public FilesystemManagerInterface { this->Write(node, data, flags); } + public: + /** + * NOTE: Write and Read are implemented using a custom NodePtr, retrieved + * using OpenFork. + */ + VoidPtr Read(NodePtr node, Int32 flags, SizeT sz) override { return this->Read(node, flags, sz); } @@ -162,7 +181,8 @@ class NewFilesystemManager final : public FilesystemManagerInterface { * @tparam Encoding file encoding (char, wchar_t...) * @tparam FSClass Filesystem contract who takes care of it. */ -template <typename Encoding = char, typename FSClass = FilesystemManagerInterface> +template <typename Encoding = char, + typename FSClass = FilesystemManagerInterface> class FileStream final { public: explicit FileStream(const Encoding *path, const Encoding *restrict_type); @@ -210,7 +230,7 @@ class FileStream final { return nullptr; } - void Write(SizeT offset, voidPtr data, SizeT sz) { + Void Write(SizeT offset, voidPtr data, SizeT sz) { auto man = FSClass::GetMounted(); if (man) { @@ -219,21 +239,25 @@ class FileStream final { } } + /// @brief Leak node pointer. + /// @return The node pointer. + NodePtr Leak() { return fFile; } + public: char *MIME() noexcept { return const_cast<char *>(fMime); } private: NodePtr fFile; - const Char *fMime{"application-type/*"}; + const Char *fMime{kFileMimeGeneric}; }; -#define kRestrictRW "r+" -#define kRestrictRWB "r+b" #define kRestrictR "r" #define kRestrictRB "rb" +#define kRestrictW "w" +#define kRestrictRW "rw" -using FileStreamUTF8 = FileStream<char>; -using FileStreamUTF16 = FileStream<wchar_t>; +using FileStreamUTF8 = FileStream<Char>; +using FileStreamUTF16 = FileStream<WideChar>; typedef UInt64 CursorType; diff --git a/Private/Source/NewFS+FileManager.cxx b/Private/Source/NewFS+FileManager.cxx index 2b5abf27..171f0c6f 100644 --- a/Private/Source/NewFS+FileManager.cxx +++ b/Private/Source/NewFS+FileManager.cxx @@ -20,7 +20,7 @@ bool NewFilesystemManager::Remove(const char* node_name) { if (node_name == nullptr || *node_name == 0) return false; if (auto catalog = fImpl->GetCatalog(node_name); catalog) - return fImpl->RemoveCatalog(*catalog); + return fImpl->RemoveCatalog(catalog); return false; } diff --git a/Private/StorageKit/AHCI.hpp b/Private/StorageKit/AHCI.hpp index 20cddf3f..6f5b5a90 100644 --- a/Private/StorageKit/AHCI.hpp +++ b/Private/StorageKit/AHCI.hpp @@ -14,8 +14,9 @@ class AHCIPacket; class AHCIDeviceInterface : public DeviceInterface<AHCIPacket> { public: - explicit AHCIDeviceInterface(void (*Out)(AHCIPacket outpacket), - void (*In)(AHCIPacket inpacket), void (*Cleanup)(void)); + explicit AHCIDeviceInterface(void (*Out)(AHCIPacket outpacket), + void (*In)(AHCIPacket inpacket), + void (*Cleanup)(void)); virtual ~AHCIDeviceInterface(); @@ -25,16 +26,18 @@ class AHCIDeviceInterface : public DeviceInterface<AHCIPacket> { const char *Name() const override; - private: + private: + void (*fOut)(AHCIPacket); + void (*fIn)(AHCIPacket); void (*fCleanup)(void); }; class AHCIPacket final { UIntPtr DataPtr; - SizeT DataSz; - UInt8 PortId; - UInt8 PortRdy; - Lba Begin; - Lba End; + SizeT DataSz; + UInt8 PortId; + UInt8 PortRdy; + Lba BeginLba; + Lba SectorCnt; }; -} // namespace NewOS
\ No newline at end of file +} // namespace NewOS
\ No newline at end of file diff --git a/Private/StorageKit/ATA.hpp b/Private/StorageKit/ATA.hpp new file mode 100644 index 00000000..5ad5a2d4 --- /dev/null +++ b/Private/StorageKit/ATA.hpp @@ -0,0 +1,43 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + +#include <KernelKit/DeviceManager.hpp> +#include <NewKit/OwnPtr.hpp> + +namespace NewOS { +class ATAPacket; + +class ATADeviceInterface : public DeviceInterface<ATAPacket> { + public: + explicit ATADeviceInterface(void (*Out)(ATAPacket outpacket), + void (*In)(ATAPacket inpacket), + void (*Cleanup)(void)); + + virtual ~ATADeviceInterface(); + + public: + ATADeviceInterface &operator=(const ATADeviceInterface &) = default; + ATADeviceInterface(const ATADeviceInterface &) = default; + + const char *Name() const override; + + private: + void (*fOut)(ATAPacket); + void (*fIn)(ATAPacket); + void (*fCleanup)(void); +}; + +class ATAPacket final { + UIntPtr DataPtr; + SizeT DataSz; + UInt8 PortId; + UInt8 PortRdy; + Lba BeginLba; + Lba SectorCnt; +}; +} // namespace NewOS
\ No newline at end of file diff --git a/Private/StorageKit/Storage.hpp b/Private/StorageKit/Storage.hpp index 6654c62b..8e7614e6 100644 --- a/Private/StorageKit/Storage.hpp +++ b/Private/StorageKit/Storage.hpp @@ -20,5 +20,3 @@ extern const SKScsiPacket kCDRomPacketTemplate; #define f_kDriveSize(LAST_LBA) ((LAST_LBA + 1) * f_kDriveSectorSize) -#include <StorageKit/StorageCore.inl> - diff --git a/Private/StorageKit/StorageCore.inl b/Private/StorageKit/StorageCore.inl deleted file mode 100644 index 8a7ca0b9..00000000 --- a/Private/StorageKit/StorageCore.inl +++ /dev/null @@ -1,41 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#ifndef __STORAGEKIT_STORAGECORE_INL__ -#define __STORAGEKIT_STORAGECORE_INL__ - -#include <NewKit/Defines.hpp> - -/// @file StorageCore.inl -/// @brief Storage Management API. - -namespace NewOS { -typedef Char* SKStr; - -///! @brief Storage context, reads and write file according to the descriptor -///layout. -class StorageInterface { - public: - explicit StorageInterface() = default; - virtual ~StorageInterface() = default; - - StorageInterface& operator=(const StorageInterface&) = default; - StorageInterface(const StorageInterface&) = default; - - public: - struct PacketDescriptor final { - VoidPtr fFilePtr; - SizeT fFilePtrSz; - Lba fBase; - UInt32 fDriveId; - }; - - virtual PacketDescriptor* Read(const SKStr name) = 0; - virtual Int32 Write(PacketDescriptor* packet, const SKStr name) = 0; -}; -} // namespace NewOS - -#endif /* ifndef __STORAGEKIT_STORAGECORE_INL__ */ |
