summaryrefslogtreecommitdiffhomepage
path: root/Private
diff options
context:
space:
mode:
Diffstat (limited to 'Private')
-rw-r--r--Private/FSKit/NewFS.hxx51
-rw-r--r--Private/KernelKit/PEF.hpp8
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx6
-rw-r--r--Private/NewBoot/Source/HEL/PowerPC/BootEPM.cxx6
-rw-r--r--Private/Source/FS/NewFS.cxx92
-rw-r--r--Private/Source/KernelHeap.cxx54
-rw-r--r--Private/Source/NewFS+FileManager.cxx4
-rw-r--r--Private/Source/NewFS+IO.cxx20
-rw-r--r--Private/Source/NewFS+Journal.cxx55
-rw-r--r--Private/makefile2
10 files changed, 179 insertions, 119 deletions
diff --git a/Private/FSKit/NewFS.hxx b/Private/FSKit/NewFS.hxx
index 6c4be37f..04e68cc6 100644
--- a/Private/FSKit/NewFS.hxx
+++ b/Private/FSKit/NewFS.hxx
@@ -38,8 +38,8 @@
/// @brief Partition GUID on EPM and GPT disks.
#define kNewFSUUID "@{DD997393-9CCE-4288-A8D5-C0FDE3908DBE}"
-#define kNewFSVersionInteger 0x121
-#define kNewFSVerionString "1.2.1"
+#define kNewFSVersionInteger 0x122
+#define kNewFSVerionString "1.2.2"
/// @brief Standard fork types.
#define kNewFSDataFork "data"
@@ -87,8 +87,8 @@
#define kPartLen 32
#define kNewFSFlagDeleted 0xF0
-#define kNewFSFlagUnallocated 0x0F
-#define kNewFSFlagCatalog 0xFF
+#define kNewFSFlagUnallocated 0x00
+#define kNewFSFlagCreated 0x0F
typedef NewOS::Char NewCharType;
@@ -156,22 +156,37 @@ struct PACKED NewPartitionBlock final {
};
namespace NewOS {
+
+enum {
+ kNewFSSubDriveA,
+ kNewFSSubDriveB,
+ kNewFSSubDriveC,
+ kNewFSSubDriveD,
+ kNewFSSubDriveInvalid,
+ kNewFSSubDriveCount,
+};
+
+
///
/// \name NewFSParser
/// \brief NewFS parser class. (catalog creation, remove removal, root, forks...)
/// Designed like the DOM, detects the filesystem automatically.
///
-class NewFSParser {
+class NewFSParser final {
public:
explicit NewFSParser() = default;
- virtual ~NewFSParser() = default;
+ ~NewFSParser() = default;
public:
NEWOS_COPY_DEFAULT(NewFSParser);
public:
- virtual _Output NewFork* CreateFork(_Input NewCatalog* catalog, _Input NewFork& theFork) = 0;
+ /// @brief Creates a new fork inside the New filesystem partition.
+ /// @param catalog it's catalog
+ /// @param theFork the fork itself.
+ /// @return the fork
+ _Output NewFork* CreateFork(_Input NewCatalog* catalog, _Input NewFork& theFork);
virtual _Output NewFork* FindFork(_Input NewCatalog* catalog, _Input const Char* name) = 0;
@@ -214,6 +229,10 @@ class NewFSParser {
/// @param drive The drive to write on.
/// @return If it was sucessful, see DbgLastError().
virtual bool Format(_Input _Output DriveTrait* drive) = 0;
+
+public:
+ Int32 fDriveIndex{ kNewFSSubDriveA };
+
};
///
@@ -228,26 +247,22 @@ class NewFilesystemHelper final {
static const char Separator();
};
-enum {
- kHCFSSubDriveA,
- kHCFSSubDriveB,
- kHCFSSubDriveC,
- kHCFSSubDriveD,
- kHCFSSubDriveInvalid,
- kHCFSSubDriveCount,
-};
-
/// @brief Write to newfs disk.
/// @param Mnt mounted interface.
/// @param DrvTrait drive info
/// @param DrvIndex drive index.
/// @return
-Int32 fs_newfs_write_raw(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex);
+Int32 fs_newfs_write(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex);
/// @brief Read from newfs disk.
/// @param Mnt mounted interface.
/// @param DrvTrait drive info
/// @param DrvIndex drive index.
/// @return
-Int32 fs_newfs_read_raw(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex);
+Int32 fs_newfs_read(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex);
+
+namespace Detail
+{
+Boolean fs_init_newfs(Void) noexcept;
+} // namespace Detail
} // namespace NewOS
diff --git a/Private/KernelKit/PEF.hpp b/Private/KernelKit/PEF.hpp
index a86cd154..7009d5d8 100644
--- a/Private/KernelKit/PEF.hpp
+++ b/Private/KernelKit/PEF.hpp
@@ -26,11 +26,7 @@
#define kPefVersion 1
#define kPefNameLen 64
-/// @brief Preferred Executable Format, a format designed
-/// for RISC/CISC Von-neumann processor types.
-
-/// The PEF also uses the x64 PE calling convention and ABI.
-/// It's just that the container are different.
+/// @brief Preferred Executable Format.
namespace NewOS {
enum {
@@ -94,7 +90,7 @@ enum {
#define kPefDebugExt ".dbg"
// NewOS System Binary Interface.
-#define kPefAbi (0xDEAD2)
+#define kPefAbi (0x5046)
#define kPefStart "__start"
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx b/Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx
index b474cb72..133429c5 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx
@@ -7,7 +7,7 @@
#include <BootKit/BootKit.hxx>
#include <FSKit/NewFS.hxx>
-#define kSwapSize MIB(16)
+#define kEPMSwapSize MIB(16)
#define kEPMGPTStartLba 30
// {310E1FC7-2060-425D-BE7B-75A37CC679BC}
@@ -81,7 +81,7 @@ EXTERN_C Boolean boot_write_epm_partition(const Char* namePart, SizeT namePartLe
}
partBlock->SectorSz = kATASectorSize;
- partBlock->LbaStart = kEPMStartPartitionBlk + kSwapSize;
+ partBlock->LbaStart = kEPMStartPartitionBlk + kEPMSwapSize;
partBlock->Version = kNewFSVersionInteger;
partBlock->Kind = kNewFSPartitionTypeStandard;
partBlock->LbaEnd = 0UL; ///! grows on the disk.
@@ -105,7 +105,7 @@ EXTERN_C Boolean boot_write_epm_partition(const Char* namePart, SizeT namePartLe
swapBlock->LbaStart = kEPMStartPartitionBlk;
swapBlock->Version = kNewFSVersionInteger;
swapBlock->Kind = kNewFSPartitionTypePage;
- swapBlock->LbaEnd = kSwapSize; /// 4 MIB swap partition.
+ swapBlock->LbaEnd = kEPMSwapSize; /// 4 MIB swap partition.
bootDev->Write(buf, 1);
diff --git a/Private/NewBoot/Source/HEL/PowerPC/BootEPM.cxx b/Private/NewBoot/Source/HEL/PowerPC/BootEPM.cxx
index 55e334f7..2e35b0dc 100644
--- a/Private/NewBoot/Source/HEL/PowerPC/BootEPM.cxx
+++ b/Private/NewBoot/Source/HEL/PowerPC/BootEPM.cxx
@@ -9,7 +9,7 @@
#define kEPMSectorSize 1024
-#define kSwapSize MIB(16)
+#define kEPMSwapSize MIB(16)
// {310E1FC7-2060-425D-BE7B-75A37CC679BC}
STATIC const BlockGUID kEPMGuid = {
@@ -82,7 +82,7 @@ EXTERN_C Boolean boot_write_epm_partition(const Char* namePart, SizeT namePartLe
}
partBlock->SectorSz = kEPMSectorSize;
- partBlock->LbaStart = kEPMStartPartitionBlk + kSwapSize;
+ partBlock->LbaStart = kEPMStartPartitionBlk + kEPMSwapSize;
partBlock->Version = kNewFSVersionInteger;
partBlock->Kind = kNewFSPartitionTypeStandard;
partBlock->LbaEnd = 0UL; ///! grows on the disk.
@@ -106,7 +106,7 @@ EXTERN_C Boolean boot_write_epm_partition(const Char* namePart, SizeT namePartLe
swapBlock->LbaStart = kEPMStartPartitionBlk;
swapBlock->Version = kNewFSVersionInteger;
swapBlock->Kind = kNewFSPartitionTypePage;
- swapBlock->LbaEnd = kSwapSize; /// 4 MIB swap partition.
+ swapBlock->LbaEnd = kEPMSwapSize; /// 4 MIB swap partition.
bootDev->Write(buf, 1);
diff --git a/Private/Source/FS/NewFS.cxx b/Private/Source/FS/NewFS.cxx
new file mode 100644
index 00000000..f497c2af
--- /dev/null
+++ b/Private/Source/FS/NewFS.cxx
@@ -0,0 +1,92 @@
+/* -------------------------------------------
+
+ Copyright Mahrouss Logic
+
+------------------------------------------- */
+
+#ifdef __FSKIT_NEWFS__
+
+#include <FSKit/NewFS.hxx>
+#include <NewKit/Utils.hpp>
+
+using namespace NewOS;
+
+STATIC Lba ke_find_fork(SizeT sz);
+STATIC Lba ke_find_catalog(SizeT sz);
+STATIC Lba ke_find_data(SizeT sz);
+
+STATIC MountpointInterface sMountpointInterface;
+
+/// @brief Creates a new fork inside the New filesystem partition.
+/// @param catalog it's catalog
+/// @param theFork the fork itself.
+/// @return the fork
+_Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog, _Input NewFork& theFork)
+{
+ if (catalog &&
+ theFork.Name[0] != 0 &&
+ theFork.DataSize > 0) {
+ Lba whereFork = 0;
+
+ theFork.DataOffset = ke_find_fork(theFork.DataSize);
+ theFork.Flags |= kNewFSFlagCreated;
+
+ if (catalog->FirstFork == 0) {
+ catalog->FirstFork = whereFork;
+ } else {
+ if (catalog->LastFork == 0) {
+ theFork.PreviousSibling = catalog->FirstFork;
+ }
+ }
+
+ if (catalog->LastFork == 0) {
+ catalog->LastFork = whereFork;
+ } else {
+ theFork.PreviousSibling = catalog->LastFork;
+ }
+
+ if (!sMountpointInterface.GetAddressOf(this->fDriveIndex) ||
+ !*sMountpointInterface.GetAddressOf(this->fDriveIndex))
+ return nullptr;
+
+ auto drv = *sMountpointInterface.GetAddressOf(this->fDriveIndex);
+
+ drv->fPacket.fLba = whereFork;
+ drv->fPacket.fPacketSize = theFork.DataSize;
+ drv->fPacket.fPacketContent = (VoidPtr)&theFork;
+
+ rt_copy_memory((VoidPtr)"fs/newfs-packet", drv->fPacket.fPacketMime, 16);
+
+ if (auto res = fs_newfs_write(&sMountpointInterface, *drv, this->fDriveIndex);
+ res) {
+ switch (res)
+ {
+ case 1:
+ DbgLastError() = kErrorDiskReadOnly;
+ break;
+ case 2:
+ DbgLastError() = kErrorDiskIsFull;
+ break;
+ DbgLastError() = kErrorNoSuchDisk;
+ break;
+
+ default:
+ break;
+ }
+ return nullptr;
+ }
+
+ /// Also update catalog.
+ this->WriteCatalog(catalog, nullptr);
+
+ return &theFork;
+ }
+
+ return nullptr;
+}
+
+STATIC Lba ke_find_fork(SizeT sz) {}
+STATIC Lba ke_find_catalog(SizeT sz) {}
+STATIC Lba ke_find_data(SizeT sz) {}
+
+#endif // ifdef __FSKIT_NEWFS__ \ No newline at end of file
diff --git a/Private/Source/KernelHeap.cxx b/Private/Source/KernelHeap.cxx
index d47b6931..0f2f57dd 100644
--- a/Private/Source/KernelHeap.cxx
+++ b/Private/Source/KernelHeap.cxx
@@ -13,8 +13,8 @@
//! @file KernelHeap.cxx
//! @brief Kernel allocator.
-#define kHeapMagic (0xD4D7D5)
-#define kHeapHeaderPaddingSz (16U)
+#define kKernelHeapMagic (0xD4D7D5)
+#define kKernelHeapHeaderPaddingSz (16U)
namespace NewOS {
STATIC SizeT kHeapCount = 0UL;
@@ -26,16 +26,16 @@ namespace Detail {
/// | HIB | ADDRESS |
struct PACKED HeapInformationBlock final {
///! @brief 32-bit value which contains the magic number of the executable.
- UInt32 hMagic;
+ UInt32 fMagic;
///! @brief Boolean value which tells if the pointer is allocated.
- Boolean hPresent;
+ Boolean fPresent;
///! @brief 32-bit CRC checksum
- UInt32 hCRC32;
+ UInt32 fCRC32;
/// @brief 64-bit pointer size.
- SizeT hSizePtr;
+ SizeT fTargetPtrSize;
/// @brief 64-bit target pointer.
- UIntPtr hTargetPtr;
- UInt8 hPadding[kHeapHeaderPaddingSz];
+ UIntPtr fTargetPtr;
+ UInt8 fPadding[kKernelHeapHeaderPaddingSz];
};
typedef HeapInformationBlock *HeapInformationBlockPtr;
@@ -55,10 +55,10 @@ VoidPtr ke_new_ke_heap(SizeT sz, const bool rw, const bool user) {
reinterpret_cast<Detail::HeapInformationBlockPtr>(
wrapper.VirtualAddress());
- heapInfo->hSizePtr = sz;
- heapInfo->hMagic = kHeapMagic;
- heapInfo->hCRC32 = 0; // dont fill it for now.
- heapInfo->hTargetPtr = wrapper.VirtualAddress();
+ heapInfo->fTargetPtrSize = sz;
+ heapInfo->fMagic = kKernelHeapMagic;
+ heapInfo->fCRC32 = 0; // dont fill it for now.
+ heapInfo->fTargetPtr = wrapper.VirtualAddress();
++kHeapCount;
@@ -76,24 +76,24 @@ Int32 ke_delete_ke_heap(VoidPtr heapPtr) {
reinterpret_cast<Detail::HeapInformationBlockPtr>(
(UIntPtr)heapPtr - sizeof(Detail::HeapInformationBlock));
- if (virtualAddress && virtualAddress->hMagic == kHeapMagic) {
- if (!virtualAddress->hPresent) {
+ if (virtualAddress && virtualAddress->fMagic == kKernelHeapMagic) {
+ if (!virtualAddress->fPresent) {
return -kErrorHeapNotPresent;
}
- if (virtualAddress->hCRC32 != 0) {
- if (virtualAddress->hCRC32 !=
- ke_calculate_crc32((Char *)virtualAddress->hTargetPtr,
- virtualAddress->hSizePtr)) {
+ if (virtualAddress->fCRC32 != 0) {
+ if (virtualAddress->fCRC32 !=
+ ke_calculate_crc32((Char *)virtualAddress->fTargetPtr,
+ virtualAddress->fTargetPtrSize)) {
ke_stop(RUNTIME_CHECK_POINTER);
}
}
- virtualAddress->hSizePtr = 0UL;
- virtualAddress->hPresent = false;
- virtualAddress->hTargetPtr = 0;
- virtualAddress->hCRC32 = 0;
- virtualAddress->hMagic = 0;
+ virtualAddress->fTargetPtrSize = 0UL;
+ virtualAddress->fPresent = false;
+ virtualAddress->fTargetPtr = 0;
+ virtualAddress->fCRC32 = 0;
+ virtualAddress->fMagic = 0;
PTEWrapper pageWrapper(false, false, false, (UIntPtr)virtualAddress);
Ref<PTEWrapper*> pteAddress{ &pageWrapper };
@@ -118,7 +118,7 @@ Boolean ke_is_valid_heap(VoidPtr heapPtr) {
reinterpret_cast<Detail::HeapInformationBlockPtr>(
(UIntPtr)heapPtr - sizeof(Detail::HeapInformationBlock));
- if (virtualAddress->hPresent && virtualAddress->hMagic == kHeapMagic) {
+ if (virtualAddress->fPresent && virtualAddress->fMagic == kKernelHeapMagic) {
return true;
}
}
@@ -135,9 +135,9 @@ Boolean ke_protect_ke_heap(VoidPtr heapPtr) {
reinterpret_cast<Detail::HeapInformationBlockPtr>(
(UIntPtr)heapPtr - sizeof(Detail::HeapInformationBlock));
- if (virtualAddress->hPresent && virtualAddress->hMagic == kHeapMagic) {
- virtualAddress->hCRC32 =
- ke_calculate_crc32((Char *)heapPtr, virtualAddress->hSizePtr);
+ if (virtualAddress->fPresent && virtualAddress->fMagic == kKernelHeapMagic) {
+ virtualAddress->fCRC32 =
+ ke_calculate_crc32((Char *)heapPtr, virtualAddress->fTargetPtrSize);
return true;
}
}
diff --git a/Private/Source/NewFS+FileManager.cxx b/Private/Source/NewFS+FileManager.cxx
index 4ba95d89..7227c2e2 100644
--- a/Private/Source/NewFS+FileManager.cxx
+++ b/Private/Source/NewFS+FileManager.cxx
@@ -13,7 +13,9 @@
namespace NewOS {
/// @brief C++ constructor
-NewFilesystemManager::NewFilesystemManager() = default;
+NewFilesystemManager::NewFilesystemManager() {
+ MUST_PASS(Detail::fs_init_newfs());
+}
NewFilesystemManager::~NewFilesystemManager() = default;
diff --git a/Private/Source/NewFS+IO.cxx b/Private/Source/NewFS+IO.cxx
index 63db9b1a..a7acb63b 100644
--- a/Private/Source/NewFS+IO.cxx
+++ b/Private/Source/NewFS+IO.cxx
@@ -34,25 +34,25 @@ using namespace NewOS;
/// @param DrvTrait drive info
/// @param DrvIndex drive index.
/// @return
-Int32 fs_newfs_read_raw(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex) {
+Int32 fs_newfs_read(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex) {
if (!Mnt) return -1;
DrvTrait.fPacket.fPacketGood = false;
switch (DrvIndex) {
- case kHCFSSubDriveA: {
+ case kNewFSSubDriveA: {
NEWFS_READ(A, DrvTrait.fPacket, Mnt);
break;
}
- case kHCFSSubDriveB: {
+ case kNewFSSubDriveB: {
NEWFS_READ(B, DrvTrait.fPacket, Mnt);
break;
}
- case kHCFSSubDriveC: {
+ case kNewFSSubDriveC: {
NEWFS_READ(C, DrvTrait.fPacket, Mnt);
break;
}
- case kHCFSSubDriveD: {
+ case kNewFSSubDriveD: {
NEWFS_READ(D, DrvTrait.fPacket, Mnt);
break;
}
@@ -66,25 +66,25 @@ Int32 fs_newfs_read_raw(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 Dr
/// @param DrvTrait drive info
/// @param DrvIndex drive index.
/// @return
-Int32 fs_newfs_write_raw(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex) {
+Int32 fs_newfs_write(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex) {
if (!Mnt) return -1;
DrvTrait.fPacket.fPacketGood = false;
switch (DrvIndex) {
- case kHCFSSubDriveA: {
+ case kNewFSSubDriveA: {
NEWFS_WRITE(A, DrvTrait.fPacket, Mnt);
break;
}
- case kHCFSSubDriveB: {
+ case kNewFSSubDriveB: {
NEWFS_WRITE(B, DrvTrait.fPacket, Mnt);
break;
}
- case kHCFSSubDriveC: {
+ case kNewFSSubDriveC: {
NEWFS_WRITE(C, DrvTrait.fPacket, Mnt);
break;
}
- case kHCFSSubDriveD: {
+ case kNewFSSubDriveD: {
NEWFS_WRITE(D, DrvTrait.fPacket, Mnt);
break;
}
diff --git a/Private/Source/NewFS+Journal.cxx b/Private/Source/NewFS+Journal.cxx
index ce04785e..bb44f7cd 100644
--- a/Private/Source/NewFS+Journal.cxx
+++ b/Private/Source/NewFS+Journal.cxx
@@ -9,57 +9,12 @@
#ifdef __FSKIT_NEWFS__
-//! BUGS: 0
-//! @brief Journaling for NewFS.
+///! BUGS: 0
+///! @file NewFS+Journal.cxx
+///! @brief Journaling for NewFS.
-#define kNewFSOpLog (4)
-
-namespace NewOS::Detail {
-typedef Boolean (*NewFSRunnerType)(VoidPtr delegate);
-
-/// @brief Journal thread class.
-class NewFSJournalRunner final {
- private:
- NewFSRunnerType fLoadRoutine{nullptr};
- NewFSRunnerType fCacheRoutine{nullptr};
- NewFSRunnerType fUnloadRoutine{nullptr};
-
- public:
- explicit NewFSJournalRunner(NewFSRunnerType load_runner)
- : fLoadRoutine(load_runner) {
- MUST_PASS(fLoadRoutine);
-
- // load runner
- if (fLoadRoutine) fLoadRoutine(this);
- }
-
- /// @brief Unload journal runner
- ~NewFSJournalRunner() noexcept {
- if (fUnloadRoutine) fUnloadRoutine(this);
- }
-
- NEWOS_COPY_DEFAULT(NewFSJournalRunner);
-
- public:
- Boolean Run(const Int32& operation, VoidPtr classPtr) {
- switch (operation) {
- case kNewFSOpLog: {
- if (!classPtr) {
- kcout << "NewOS: Miss for classPtr at "
- "NewFSJournalManager::Run(classPtr) "
- << __FILE__ << "\n";
- return false;
- }
-
- MUST_PASS(fCacheRoutine);
- return fCacheRoutine(classPtr);
- }
- };
-
- return false;
- }
-};
-} // namespace NewOS::Detail
+namespace NewOS::Journal {
+} // namespace NewOS::Journal
using namespace NewOS;
diff --git a/Private/makefile b/Private/makefile
index 4ef4cd81..b73bcb02 100644
--- a/Private/makefile
+++ b/Private/makefile
@@ -44,7 +44,7 @@ MOVEALL=./MoveAll.sh
.PHONY: newos-amd64-epm
newos-amd64-epm: clean
windres KernelRsrc.rsrc -O coff -o KernelRsrc.obj
- $(CC) $(CCFLAGS) $(DISKDRIVER) $(DEBUG) $(wildcard Source/*.cxx HALKit/AMD64/Storage/*.cxx) $(wildcard HALKit/AMD64/PCI/*.cxx) $(wildcard Source/Network/*.cxx) $(wildcard Source/Storage/*.cxx) $(wildcard HALKit/AMD64/*.cxx) $(wildcard HALKit/AMD64/*.cpp) $(wildcard HALKit/AMD64/*.s)
+ $(CC) $(CCFLAGS) $(DISKDRIVER) $(DEBUG) $(wildcard Source/*.cxx) $(wildcard Source/FS/*.cxx) $(wildcard HALKit/AMD64/Storage/*.cxx) $(wildcard HALKit/AMD64/PCI/*.cxx) $(wildcard Source/Network/*.cxx) $(wildcard Source/Storage/*.cxx) $(wildcard HALKit/AMD64/*.cxx) $(wildcard HALKit/AMD64/*.cpp) $(wildcard HALKit/AMD64/*.s)
$(ASM) $(ASMFLAGS) HALKit/AMD64/HalInterruptAPI.asm
$(ASM) $(ASMFLAGS) HALKit/AMD64/HalSMPCoreManager.asm
$(ASM) $(ASMFLAGS) HALKit/AMD64/HalNewBoot.asm