diff options
28 files changed, 256 insertions, 164 deletions
diff --git a/Private/Drivers/Bonjour/Bonjour.c b/Private/Drivers/Bonjour/Bonjour.c index dba649c9..c06ab0b3 100644 --- a/Private/Drivers/Bonjour/Bonjour.c +++ b/Private/Drivers/Bonjour/Bonjour.c @@ -8,11 +8,11 @@ #include <DriverKit/KernelPrint.h> int __ImageStart(void) { - kernelPrintStr("Bonjour: Starting up zeroconf...\r\n"); + kernelPrintStr("Bonjour: Starting up zeroconf...\r"); return 0; } int __ImageEnd(void) { - kernelPrintStr("Bonjour: Shutting down zeroconf...\r\n"); + kernelPrintStr("Bonjour: Shutting down zeroconf...\r"); return 0; } diff --git a/Private/Drivers/MahroussUpdate/MahroussUpdate.cc b/Private/Drivers/MahroussUpdate/MahroussUpdate.cc index c8741ed0..ea628263 100644 --- a/Private/Drivers/MahroussUpdate/MahroussUpdate.cc +++ b/Private/Drivers/MahroussUpdate/MahroussUpdate.cc @@ -10,7 +10,7 @@ #include <Drivers/MahroussUpdate/MahroussUpdate.hxx> DK_EXTERN int __ImageStart(void) { - kernelPrintStr("Mahrouss Update: Looking for updates...\r\n"); + kernelPrintStr("Mahrouss Update: Looking for updates...\r"); UpdateRequest req("mup://release-mahrouss.logic/newos/"); return 0; diff --git a/Private/Drivers/SampleDriver/SampleDriver.c b/Private/Drivers/SampleDriver/SampleDriver.c index 4481d480..35e5347c 100644 --- a/Private/Drivers/SampleDriver/SampleDriver.c +++ b/Private/Drivers/SampleDriver/SampleDriver.c @@ -8,12 +8,12 @@ #include <DriverKit/KernelPrint.h> int __ImageStart(void) { - kernelPrintStr("SampleDriver: Starting up...\r\n"); + kernelPrintStr("SampleDriver: Starting up...\r"); return 0; } int __ImageEnd(void) { - kernelPrintStr("SampleDriver: Shutting down...\r\n"); + kernelPrintStr("SampleDriver: Shutting down...\r"); return 0; } diff --git a/Private/FSKit/NewFS.hxx b/Private/FSKit/NewFS.hxx index 619c6c6b..2a499ab7 100644 --- a/Private/FSKit/NewFS.hxx +++ b/Private/FSKit/NewFS.hxx @@ -92,9 +92,9 @@ default. #define kConfigLen 64 #define kPartLen 32 -#define kNewFSFlagDeleted 0xF0 -#define kNewFSFlagUnallocated 0x00 -#define kNewFSFlagCreated 0x0F +#define kNewFSFlagDeleted 70 +#define kNewFSFlagUnallocated 00 +#define kNewFSFlagCreated 71 #define kNewFSMimeNameLen (200) @@ -114,7 +114,9 @@ struct PACKED NewCatalog final { NewCharType Name[kNewFSNodeNameLen]; NewCharType Mime[kNewFSMimeNameLen]; + /// Catalog status flag. NewOS::Int32 Flags; + /// Catalog kind. NewOS::Int32 Kind; /// Size of the data fork. @@ -235,14 +237,14 @@ class NewFSParser final { bool WriteCatalog(_Input _Output NewCatalog* catalog, voidPtr data, SizeT sizeOfData); - VoidPtr ReadCatalog(_Input _Output NewCatalog* catalog, + VoidPtr ReadCatalog(_Input _Output const char* catalogName, SizeT dataSz); bool Seek(_Input _Output NewCatalog* catalog, SizeT off); SizeT Tell(_Input _Output NewCatalog* catalog); - bool RemoveCatalog(_Input _Output NewCatalog* catalog); + bool RemoveCatalog(_Input const Char* catalog); bool CloseCatalog(_InOut NewCatalog* catalog); diff --git a/Private/FirmwareKit/EFI/API.hxx b/Private/FirmwareKit/EFI/API.hxx index 4cf8e603..b17e7afd 100644 --- a/Private/FirmwareKit/EFI/API.hxx +++ b/Private/FirmwareKit/EFI/API.hxx @@ -67,7 +67,7 @@ inline UInt32 Platform() noexcept { return kPEMachineAMD64; } inline void ThrowError(const EfiCharType *ErrorCode, const EfiCharType *Reason) noexcept { #ifdef __DEBUG__ - ST->ConOut->OutputString(ST->ConOut, L"\r\n*** STOP ***\r\n"); + ST->ConOut->OutputString(ST->ConOut, L"\r*** STOP ***\r"); ST->ConOut->OutputString(ST->ConOut, L"*** Error: "); ST->ConOut->OutputString(ST->ConOut, ErrorCode); @@ -75,7 +75,7 @@ inline void ThrowError(const EfiCharType *ErrorCode, ST->ConOut->OutputString(ST->ConOut, L", Reason: "); ST->ConOut->OutputString(ST->ConOut, Reason); - ST->ConOut->OutputString(ST->ConOut, L" ***\r\n"); + ST->ConOut->OutputString(ST->ConOut, L" ***\r"); #endif // ifdef __DEBUG__ #ifdef __NEWBOOT__ diff --git a/Private/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp b/Private/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp index 99a66532..288462ab 100644 --- a/Private/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp +++ b/Private/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp @@ -35,7 +35,7 @@ EXTERN_C void idt_handle_scheduler(NewOS::UIntPtr rsp) { /// schedule another process. if (!NewOS::ProcessHelper::StartScheduling()) { - NewOS::kcout << "New OS: Continue schedule this process...\r\n"; + NewOS::kcout << "New OS: Continue schedule this process...\r"; } } diff --git a/Private/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp b/Private/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp index 5c845812..917af45d 100644 --- a/Private/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp +++ b/Private/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp @@ -93,13 +93,13 @@ STATIC MadtType* kApicInfoBlock = nullptr; /////////////////////////////////////////////////////////////////////////////////////// void hal_system_get_cores(voidPtr rsdPtr) { - kcout << "New OS: Constructing ACPIFactoryInterface...\r\n"; + kcout << "New OS: Constructing ACPIFactoryInterface...\r"; auto acpi = ACPIFactoryInterface(rsdPtr); kApicMadt = acpi.Find(kApicSignature).Leak().Leak(); if (kApicMadt) { - kcout << "New OS: Successfuly fetched the MADT!\r\n"; + kcout << "New OS: Successfuly fetched the MADT!\r"; kApicInfoBlock = (MadtType*)kApicMadt; } else { MUST_PASS(false); diff --git a/Private/HALKit/AMD64/HalDebugOutput.cxx b/Private/HALKit/AMD64/HalDebugOutput.cxx index ed247875..95f6a3ce 100644 --- a/Private/HALKit/AMD64/HalDebugOutput.cxx +++ b/Private/HALKit/AMD64/HalDebugOutput.cxx @@ -68,7 +68,10 @@ EXTERN_C void ke_io_write(const char* bytes) { SizeT len = rt_string_len(bytes, 256); while (index < len) { - HAL::Out8(Detail::PORT, bytes[index]); + if (bytes[index] == '\r') + HAL::Out8(Detail::PORT, '\r'); + + HAL::Out8(Detail::PORT, bytes[index] == '\r' ? '\n' : bytes[index]); ++index; } diff --git a/Private/HALKit/AMD64/PCI/Dma.cxx b/Private/HALKit/AMD64/PCI/Dma.cxx index f0a10eb9..96063b14 100644 --- a/Private/HALKit/AMD64/PCI/Dma.cxx +++ b/Private/HALKit/AMD64/PCI/Dma.cxx @@ -52,7 +52,7 @@ OwnPtr<IOBuf<Char *>> DMAFactory::Construct(OwnPtr<DMAWrapper> &dma) { if (!dmaOwnPtr) return {}; - kcout << "Returning the new OwnPtr<IOBuf<Char*>>!\r\n"; + kcout << "Returning the new OwnPtr<IOBuf<Char*>>!\r"; return dmaOwnPtr; } diff --git a/Private/HALKit/AMD64/Storage/AHCI.cxx b/Private/HALKit/AMD64/Storage/AHCI.cxx index 80224d89..7c2bc0f6 100644 --- a/Private/HALKit/AMD64/Storage/AHCI.cxx +++ b/Private/HALKit/AMD64/Storage/AHCI.cxx @@ -36,7 +36,7 @@ NewOS::Boolean drv_std_init(NewOS::UInt16& PortsImplemented) { iterator[devIndex].Leak().EnableMmio(); /// enable the memory i/o for this ahci device. kAhciDevice = iterator[devIndex].Leak(); /// and then leak the reference. - kcout << "New Kernel: [PCI] Found AHCI controller.\r\n"; + kcout << "New Kernel: [PCI] Found AHCI controller.\r"; return true; } diff --git a/Private/HALKit/AMD64/Storage/ATA-PIO.cxx b/Private/HALKit/AMD64/Storage/ATA-PIO.cxx index 9b37e248..6dafb5e5 100644 --- a/Private/HALKit/AMD64/Storage/ATA-PIO.cxx +++ b/Private/HALKit/AMD64/Storage/ATA-PIO.cxx @@ -123,6 +123,8 @@ Void drv_std_read(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, Buf[IndexOff] = In16(IO + ATA_REG_DATA); drv_std_wait_io(IO); } + + drv_std_wait_io(IO); } Void drv_std_write(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, @@ -153,6 +155,8 @@ Void drv_std_write(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, Out16(IO + ATA_REG_DATA, Buf[IndexOff]); drv_std_wait_io(IO); } + + drv_std_wait_io(IO); } /// @brief is ATA detected? diff --git a/Private/KernelKit/DebugOutput.hpp b/Private/KernelKit/DebugOutput.hpp index 6c4da58e..f6b1b9e1 100644 --- a/Private/KernelKit/DebugOutput.hpp +++ b/Private/KernelKit/DebugOutput.hpp @@ -45,7 +45,7 @@ class TerminalDevice final : public DeviceInterface<const Char *> { inline TerminalDevice end_line() { TerminalDevice selfTerm = TerminalDevice::Shared(); - selfTerm << "\r\n"; + selfTerm << "\r"; return selfTerm; } diff --git a/Private/NetworkKit/NetworkDevice.inl b/Private/NetworkKit/NetworkDevice.inl index 30b65f55..6c5b88ee 100644 --- a/Private/NetworkKit/NetworkDevice.inl +++ b/Private/NetworkKit/NetworkDevice.inl @@ -13,7 +13,7 @@ NetworkDevice::NetworkDevice(void (*out)(NetworkDeviceCommand), void (*in)(NetworkDeviceCommand), void (*on_cleanup)(void)) : DeviceInterface<NetworkDeviceCommand>(out, in), fCleanup(on_cleanup) { - kcout << "NK: NetworkDevice initialize.\r\n"; + kcout << "NK: NetworkDevice initialize.\r"; MUST_PASS(out && in && on_cleanup); } @@ -21,7 +21,7 @@ NetworkDevice::NetworkDevice(void (*out)(NetworkDeviceCommand), NetworkDevice::~NetworkDevice() { MUST_PASS(fCleanup); - kcout << "NK: NetworkDevice cleanup.\r\n"; + kcout << "NK: NetworkDevice cleanup.\r"; if (fCleanup) fCleanup(); } -} // namespace NewOS
\ No newline at end of file +} // namespace NewOS diff --git a/Private/NewBoot/BootKit/BootKit.hxx b/Private/NewBoot/BootKit/BootKit.hxx index ca6f56ac..c916978f 100644 --- a/Private/NewBoot/BootKit/BootKit.hxx +++ b/Private/NewBoot/BootKit/BootKit.hxx @@ -225,7 +225,7 @@ public: return false; } - writer.Write(L"Device Size: ").Write(this->fDiskDev.GetDiskSize()).Write(L"\r\n"); + writer.Write(L"Device Size: ").Write(this->fDiskDev.GetDiskSize()).Write(L"\r"); if (blockPart->DiskSize != this->fDiskDev.GetDiskSize() || blockPart->DiskSize < 1 || @@ -236,7 +236,7 @@ public: EFI::ThrowError(L"Invalid-Partition-Name", L"Invalid disk partition."); } - writer.Write(L"Device Partition: ").Write(blockPart->PartitionName).Write(L" is healthy.\r\n"); + writer.Write(L"Device Partition: ").Write(blockPart->PartitionName).Write(L" is healthy.\r"); return true; } @@ -300,7 +300,7 @@ private: SizeT cur = 0UL; writer.Write((catalogKind->Kind == kNewFSCatalogKindFile) ? L"New Boot: Write-File: " : - L"New Boot: Write-Directory: " ).Write(blob->fFileName).Write(L"\r\n"); + L"New Boot: Write-Directory: " ).Write(blob->fFileName).Write(L"\r"); /// Set disk cursor here. @@ -396,7 +396,7 @@ inline Boolean BDiskFormatFactory<BootDev>::Format(const char* partName, fDiskDev.Write(buf, sectorSz); BTextWriter writer; - writer.Write(L"New Boot: Write-Partition, OK.\r\n"); + writer.Write(L"New Boot: Write-Partition, OK.\r"); return true; } else { diff --git a/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx b/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx index d6b5542c..edfbaed8 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx @@ -73,7 +73,7 @@ ATAInit_Retry: if (statRdy & ATA_SR_ERR) { writer.Write( - L"New Boot: ATA: Select error, not an IDE based hard-drive.\r\n"); + L"New Boot: ATA: Select error, not an IDE based hard-drive.\r"); return false; } diff --git a/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx b/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx index b2d728ae..e01d0b96 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx @@ -52,12 +52,12 @@ BFileReader::BFileReader(const CharacterTypeUTF16* path, EfiGUID guidImg = EfiGUID(EFI_LOADED_IMAGE_PROTOCOL_GUID); if (BS->HandleProtocol(ImageHandle, &guidImg, (void**)&img) != kEfiOk) { - mWriter.Write(L"New Boot: Fetch-Protocol: No-Such-Protocol").Write(L"\r\n"); + mWriter.Write(L"New Boot: Fetch-Protocol: No-Such-Protocol").Write(L"\r"); this->mErrorCode = kNotSupported; } if (BS->HandleProtocol(img->DeviceHandle, &guidEfp, (void**)&efp) != kEfiOk) { - mWriter.Write(L"New Boot: Fetch-Protocol: No-Such-Protocol").Write(L"\r\n"); + mWriter.Write(L"New Boot: Fetch-Protocol: No-Such-Protocol").Write(L"\r"); this->mErrorCode = kNotSupported; return; } @@ -65,7 +65,7 @@ BFileReader::BFileReader(const CharacterTypeUTF16* path, /// Start doing disk I/O if (efp->OpenVolume(efp, &rootFs) != kEfiOk) { - mWriter.Write(L"New Boot: Fetch-Protocol: No-Such-Volume").Write(L"\r\n"); + mWriter.Write(L"New Boot: Fetch-Protocol: No-Such-Volume").Write(L"\r"); EFI::ThrowError(L"NoSuchVolume", L"No Such volume."); this->mErrorCode = kNotSupported; return; @@ -77,7 +77,7 @@ BFileReader::BFileReader(const CharacterTypeUTF16* path, kEfiOk) { mWriter.Write(L"New Boot: Fetch-Protocol: No-Such-Path: ") .Write(mPath) - .Write(L"\r\n"); + .Write(L"\r"); EFI::ThrowError(L"NoSuchPath", L"No Such file on filesystem."); this->mErrorCode = kNotSupported; return; @@ -109,7 +109,7 @@ Void BFileReader::ReadAll(SizeT until, SizeT chunk) { if (mBlob == nullptr) { if (auto err = BS->AllocatePool(EfiLoaderCode, until, (VoidPtr*)&mBlob) != kEfiOk) { - mWriter.Write(L"*** EFI-Code: ").Write(err).Write(L" ***\r\n"); + mWriter.Write(L"*** EFI-Code: ").Write(err).Write(L" ***\r"); EFI::ThrowError(L"OutOfMemory", L"Allocation error."); } } diff --git a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx index 96999df8..1462115a 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx @@ -65,9 +65,9 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, writer.Write(L"Mahrouss-Logic (R) New Boot: ") .Write(BVersionString::Shared()); - writer.Write(L"\r\nNew Boot: Firmware Vendor: ") + writer.Write(L"\rNew Boot: Firmware Vendor: ") .Write(SystemTable->FirmwareVendor) - .Write(L"\r\n"); + .Write(L"\r"); UInt32* MapKey = new UInt32(); UInt32* SizePtr = new UInt32(); @@ -151,7 +151,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, writer.WriteCharacter(buf[i]); } } else - writer.Write(L"\r\n"); + writer.Write(L"\r"); } } diff --git a/Private/NewBoot/Source/HEL/AMD64/BootTextWriter.cxx b/Private/NewBoot/Source/HEL/AMD64/BootTextWriter.cxx index fc91a02a..2a92ce6d 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootTextWriter.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootTextWriter.cxx @@ -26,12 +26,28 @@ BTextWriter &BTextWriter::Write(const CharacterTypeUTF16 *str) { #ifdef __DEBUG__ if (!str || *str == 0) return *this; - ST->ConOut->OutputString(ST->ConOut, str); + CharacterTypeUTF16 strTmp[2]; + strTmp[1] = 0; + + for (size_t i = 0; str[i] != 0; i++) { + if (str[i] == '\r') { + strTmp[0] = str[i]; + ST->ConOut->OutputString(ST->ConOut, strTmp); + + strTmp[0] = '\n'; + ST->ConOut->OutputString(ST->ConOut, strTmp); + } else { + strTmp[0] = str[i]; + ST->ConOut->OutputString(ST->ConOut, strTmp); + } + } #endif // ifdef __DEBUG__ return *this; } +/// @brief UTF-8 equivalent of Write (UTF-16). +/// @param str the input string. BTextWriter &BTextWriter::Write(const Char *str) { #ifdef __DEBUG__ if (!str || *str == 0) return *this; @@ -40,8 +56,16 @@ BTextWriter &BTextWriter::Write(const Char *str) { strTmp[1] = 0; for (size_t i = 0; str[i] != 0; i++) { - strTmp[0] = str[i]; - ST->ConOut->OutputString(ST->ConOut, strTmp); + if (str[i] == '\r') { + strTmp[0] = str[i]; + ST->ConOut->OutputString(ST->ConOut, strTmp); + + strTmp[0] = '\n'; + ST->ConOut->OutputString(ST->ConOut, strTmp); + } else { + strTmp[0] = str[i]; + ST->ConOut->OutputString(ST->ConOut, strTmp); + } } #endif // ifdef __DEBUG__ diff --git a/Private/NewKit/Array.hpp b/Private/NewKit/Array.hpp index 6724d8a9..68ca9bfc 100644 --- a/Private/NewKit/Array.hpp +++ b/Private/NewKit/Array.hpp @@ -11,7 +11,7 @@ namespace NewOS { -template <typename T, Size N> +template <typename T, Size N> class Array final { public: @@ -26,7 +26,7 @@ public: if (At > N) return {}; - kcout << "Returning element\r\n"; + kcout << "Returning element\r"; return ErrorOr<T>(fArray[At]); } @@ -65,6 +65,6 @@ public: private: T fArray[N]; - + }; } // namespace NewOS diff --git a/Private/Source/AppMain.cxx b/Private/Source/AppMain.cxx index 6a23e20d..8fb9a4ba 100644 --- a/Private/Source/AppMain.cxx +++ b/Private/Source/AppMain.cxx @@ -34,6 +34,8 @@ EXTERN_C NewOS::Void AppMain(NewOS::Void) { NewCatalog* newKernelCatalog = newFS->GetImpl()->CreateCatalog("/Boot/System/ExampleTextFile"); + NewOS::kcout << NewOS::hex_number(newKernelCatalog->Flags) << NewOS::endl; + if (newKernelCatalog) NewOS::kcout << "Catalog-Path-Name: " << newKernelCatalog->Name << NewOS::endl; @@ -43,14 +45,8 @@ EXTERN_C NewOS::Void AppMain(NewOS::Void) { constexpr auto cDataSz = 512; NewOS::Char theData[cDataSz] = { - "THIS FORK\rCONTAINS DATA\rAS\rYOU\rCAN\rSEE...THIS FORK\rCONTAINS " - "DATA\rAS\rYOU\rCAN\rSEE..THIS FORK\rCONTAINS " - "DATA\rAS\rYOU\rCAN\rSEE..THIS FORK\rCONTAINS " - "DATA\rAS\rYOU\rCAN\rSEE..THIS FORK\rCONTAINS " - "DATA\rAS\rYOU\rCAN\rSEE..THIS FORK\rCONTAINS " - "DATA\rAS\rYOU\rCAN\rSEE..THIS FORK\rCONTAINS " - "DATA\rAS\rYOU\rCAN\rSEE..THIS FORK\rCONTAINS " - "DATA\rAS\rYOU\rCAN\rSEE.."}; + "About NewKernel...\rNewKernel is the System behind " + "NewOS.\rFeaturing modern common features, yet innovative.\r"}; NewFork theFork{0}; NewOS::rt_copy_memory((NewOS::VoidPtr) "EditableText", @@ -63,6 +59,17 @@ EXTERN_C NewOS::Void AppMain(NewOS::Void) { newFS->GetImpl()->CreateFork(newKernelCatalog, theFork); newFS->GetImpl()->WriteCatalog(newKernelCatalog, theData, cDataSz); + //newFS->GetImpl()->RemoveCatalog("/Boot/System/ExampleTextFile"); + + + + char* buf = nullptr; + + buf = + (NewOS::Char*)newFS->GetImpl()->ReadCatalog("/Boot/System/ExampleTextFile", 512); + + NewOS::kcout << buf << NewOS::endl; + delete newKernelCatalog; delete mountCatalog; } else { diff --git a/Private/Source/FS/NewFS.cxx b/Private/Source/FS/NewFS.cxx index 57f61cd2..fe208389 100644 --- a/Private/Source/FS/NewFS.cxx +++ b/Private/Source/FS/NewFS.cxx @@ -31,7 +31,7 @@ _Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog, if (lba <= kNewFSCatalogStartAddress) return nullptr; - theFork.DataOffset = lba + sizeof(NewFork); + theFork.DataOffset = lba + sizeof(NewCatalog) + sizeof(NewFork); if (!sMountpointInterface.GetAddressOf(this->fDriveIndex)) return nullptr; @@ -195,9 +195,8 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, catalogChild->NextSibling = 0UL; catalogChild->PrevSibling = outLba; - catalogChild->Flags = flags; catalogChild->Kind = kind; - catalogChild->Flags |= kNewFSFlagCreated; + catalogChild->Flags = kNewFSFlagCreated; rt_copy_memory((VoidPtr)name, (VoidPtr)catalogChild->Name, rt_string_len(name)); @@ -227,72 +226,64 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, } /// allocation or reallocation or catalog... - if ((nextSibling->Name[0] == 0 && - nextSibling->Flags != kNewFSFlagCreated)) { + if (nextSibling->Name[0] == 0 && nextSibling->Flags != kNewFSFlagCreated) { catalogChild->DataFork = startFree + sizeof(NewCatalog); catalogChild->ResourceFork = startFree + sizeof(NewCatalog) + catalogChild->DataForkSize; - if ((nextSibling->Flags != kNewFSFlagCreated)) { - nextSibling->Flags = kNewFSFlagCreated; - - drive->fPacket.fPacketContent = catalogChild; - drive->fPacket.fPacketSize = sizeof(NewCatalog); - drive->fPacket.fLba = startFree; + if (catalogChild->Kind == kNewFSCatalogKindFile) { + rt_copy_memory((VoidPtr) "x-kind/file", (VoidPtr)catalogChild->Mime, + rt_string_len("x-kind/file")); + } else { + rt_copy_memory((VoidPtr) "x-kind/dir", (VoidPtr)catalogChild->Mime, + rt_string_len("x-kind/dir")); + } - if (catalogChild->Kind == kNewFSCatalogKindFile) { - rt_copy_memory((VoidPtr) "x-kind/file", (VoidPtr)catalogChild->Mime, - rt_string_len("x-kind/file")); - } else { - rt_copy_memory((VoidPtr) "x-kind/dir", (VoidPtr)catalogChild->Mime, - rt_string_len("x-kind/dir")); - } + catalogChild->NextSibling = sizeof(NewCatalog) + + catalogChild->DataForkSize + + catalogChild->ResourceForkOverallSize; - catalogChild->NextSibling = sizeof(NewCatalog) + - catalogChild->DataForkSize + - catalogChild->ResourceForkOverallSize; + drive->fPacket.fPacketContent = catalogChild; + drive->fPacket.fPacketSize = sizeof(NewCatalog); + drive->fPacket.fLba = startFree; - drive->fOutput(&drive->fPacket); + drive->fOutput(&drive->fPacket); - kcout << "New OS: Create new catalog successfully!\r\n"; + kcout << "New OS: Create new catalog successfully!\r"; - Char sectBuf[sizeof(NewCatalog)] = {0}; + Char sectBuf[sizeof(NewCatalog)] = {0}; - drive->fPacket.fPacketContent = sectBuf; - drive->fPacket.fPacketSize = sizeof(NewCatalog); - drive->fPacket.fLba = catalogChild->PrevSibling; + drive->fPacket.fPacketContent = sectBuf; + drive->fPacket.fPacketSize = sizeof(NewCatalog); + drive->fPacket.fLba = catalogChild->PrevSibling; - drive->fInput(&drive->fPacket); + drive->fInput(&drive->fPacket); - NewCatalog* prevCatalog = (NewCatalog*)sectBuf; - prevCatalog->NextSibling = startFree; + NewCatalog* prevCatalog = (NewCatalog*)sectBuf; + prevCatalog->NextSibling = startFree; - drive->fOutput(&drive->fPacket); + drive->fOutput(&drive->fPacket); - kcout << "Edit-Catalog: " << prevCatalog->Name << endl; + kcout << "Edit-Catalog: " << prevCatalog->Name << endl; - Char sectorBufPartBlock[kNewFSMinimumSectorSz] = {0}; + Char sectorBufPartBlock[kNewFSMinimumSectorSz] = {0}; - drive->fPacket.fPacketContent = sectorBufPartBlock; - drive->fPacket.fPacketSize = kNewFSMinimumSectorSz; - drive->fPacket.fLba = kNewFSAddressAsLba; + drive->fPacket.fPacketContent = sectorBufPartBlock; + drive->fPacket.fPacketSize = kNewFSMinimumSectorSz; + drive->fPacket.fLba = kNewFSAddressAsLba; - drive->fInput(&drive->fPacket); + drive->fInput(&drive->fPacket); - NewPartitionBlock* partBlock = (NewPartitionBlock*)sectorBufPartBlock; + NewPartitionBlock* partBlock = (NewPartitionBlock*)sectorBufPartBlock; - partBlock->SectorCount -= 1; - partBlock->CatalogCount += 1; - partBlock->FreeCatalog -= 1; + partBlock->SectorCount -= 1; + partBlock->CatalogCount += 1; + partBlock->FreeCatalog -= 1; - drive->fOutput(&drive->fPacket); + drive->fOutput(&drive->fPacket); - delete catalog; - return catalogChild; - } else { - delete catalog; - return nullptr; - } + delete catalog; + return catalogChild; } //// @note that's how we find the next catalog in the partition block. @@ -369,10 +360,19 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive) { drive->fOutput(&drive->fPacket); + kcout << "Drive-Kind: " << drive->fDriveKind() << endl; + + kcout << "Partition-Name: " << partBlock->PartitionName << endl; + kcout << "Start-Catalog: " << number(partBlock->StartCatalog) << endl; + kcout << "Catalog-Count: " << number(partBlock->CatalogCount) << endl; + kcout << "Free-Catalog: " << number(partBlock->FreeCatalog) << endl; + kcout << "Free-Sectors: " << number(partBlock->FreeSectors) << endl; + kcout << "Sector-Size: " << number(partBlock->SectorSize) << endl; + return true; } - kcout << "New OS: PartitionBlock already exists.\r\n"; + kcout << "New OS: PartitionBlock already exists.\r"; /// return success as well, do not ignore that partition. return true; @@ -450,15 +450,6 @@ _Output NewCatalog* NewFSParser::FindCatalog(_Input const char* catalogName, NewPartitionBlock* part = (NewPartitionBlock*)sectorBuf; - kcout << "Drive-Kind: " << drive->fDriveKind() << endl; - - kcout << "Partition-Name: " << part->PartitionName << endl; - kcout << "Start-Catalog: " << number(part->StartCatalog) << endl; - kcout << "Catalog-Count: " << number(part->CatalogCount) << endl; - kcout << "Free-Catalog: " << number(part->FreeCatalog) << endl; - kcout << "Free-Sectors: " << number(part->FreeSectors) << endl; - kcout << "Sector-Size: " << number(part->SectorSize) << endl; - auto start = part->StartCatalog; drive->fPacket.fLba = start; @@ -470,7 +461,16 @@ _Output NewCatalog* NewFSParser::FindCatalog(_Input const char* catalogName, while (drive->fPacket.fPacketGood) { NewCatalog* catalog = (NewCatalog*)sectorBuf; + kcout << "Catalog-Name: " << catalog->Name << endl; + kcout << "Catalog-Flags: " << hex_number(catalog->Flags) << endl; + if (StringBuilder::Equals(catalogName, catalog->Name)) { + /// ignore unallocated catalog, break + if (catalog->Flags != kNewFSFlagCreated) { + + goto _NewFSContinueSearch; + } + NewCatalog* catalogPtr = new NewCatalog(); rt_copy_memory(catalog, catalogPtr, sizeof(NewCatalog)); @@ -479,8 +479,11 @@ _Output NewCatalog* NewFSParser::FindCatalog(_Input const char* catalogName, return catalogPtr; } + _NewFSContinueSearch: start = catalog->NextSibling; + kcout << "Catalog-Next: " << number(start) << endl; + if (start <= kNewFSAddressAsLba) break; drive->fPacket.fLba = start; @@ -521,15 +524,32 @@ Boolean NewFSParser::CloseCatalog(_Input _Output NewCatalog* catalog) { /// @brief Mark catalog as removed. /// @param catalog The catalog structure. /// @return -Boolean NewFSParser::RemoveCatalog(_Input _Output NewCatalog* catalog) { - if (!catalog) { - DbgLastError() = kErrorFileNotFound; +Boolean NewFSParser::RemoveCatalog(_Input const Char* catalogName) { + if (!catalogName) { + DbgLastError() = kErrorInternal; return false; } - catalog->Flags |= kNewFSFlagDeleted; - this->WriteCatalog(catalog, nullptr, 0); + Lba outLba = 0; + auto catalog = this->FindCatalog(catalogName, outLba); + + if (outLba >= kNewFSCatalogStartAddress || + catalog->Flags == kNewFSFlagCreated) { + catalog->Flags = kNewFSFlagDeleted; + + auto drive = sMountpointInterface.GetAddressOf(this->fDriveIndex); + + drive->fPacket.fLba = outLba; // the catalog position. + drive->fPacket.fPacketSize = + sizeof(NewCatalog); // size of catalog. roughly the sector size. + drive->fPacket.fPacketContent = catalog; // the catalog itself. + + drive->fOutput(&drive->fPacket); // send packet. + + return true; + } + delete catalog; return false; } @@ -541,19 +561,54 @@ Boolean NewFSParser::RemoveCatalog(_Input _Output NewCatalog* catalog) { /// @param catalog /// @param dataSz /// @return -VoidPtr NewFSParser::ReadCatalog(_Input _Output NewCatalog* catalog, +VoidPtr NewFSParser::ReadCatalog(_Input _Output const char* catalogName, SizeT dataSz) { - if (!catalog) { + if (!catalogName) { DbgLastError() = kErrorFileNotFound; return nullptr; } - return nullptr; + if (!sMountpointInterface.GetAddressOf(this->fDriveIndex)) return nullptr; + + NewCatalog* catalog = this->GetCatalog(catalogName); + + if (!catalog) return nullptr; + + Char* sectorBuf = new Char[sizeof(NewFork)]; + auto drive = sMountpointInterface.GetAddressOf(this->fDriveIndex); + + drive->fPacket.fLba = catalog->DataFork; + drive->fPacket.fPacketSize = sizeof(NewFork); + drive->fPacket.fPacketContent = sectorBuf; + + drive->fInput(&drive->fPacket); + + NewFork* forkData = (NewFork*)sectorBuf; + + kcout << forkData->Name << " " << hex_number(forkData->DataOffset) << endl; + + if (dataSz > forkData->DataSize) { + delete[] sectorBuf; + + return nullptr; + } + + Char* forkBuf = new Char[dataSz]; + + drive->fPacket.fLba = forkData->DataOffset; + drive->fPacket.fPacketSize = dataSz; + drive->fPacket.fPacketContent = forkBuf; + + drive->fInput(&drive->fPacket); + + delete[] sectorBuf; + + return forkBuf; } /// @brief Seek in the data fork. -/// @param catalog -/// @param off +/// @param catalog the catalog offset. +/// @param off where to seek. /// @return bool NewFSParser::Seek(_Input _Output NewCatalog* catalog, SizeT off) { if (!catalog) { @@ -561,7 +616,7 @@ bool NewFSParser::Seek(_Input _Output NewCatalog* catalog, SizeT off) { return false; } - return false; + return true; } /// @brief Tell where we are inside the data fork. @@ -570,7 +625,7 @@ bool NewFSParser::Seek(_Input _Output NewCatalog* catalog, SizeT off) { SizeT NewFSParser::Tell(_Input _Output NewCatalog* catalog) { if (!catalog) { DbgLastError() = kErrorFileNotFound; - return false; + return 0; } return 0; diff --git a/Private/Source/FileManager.cxx b/Private/Source/FileManager.cxx index aab3cff0..c7d0bf41 100644 --- a/Private/Source/FileManager.cxx +++ b/Private/Source/FileManager.cxx @@ -88,7 +88,7 @@ Void NewFilesystemManager::Write(NodePtr node, VoidPtr data, /// @return VoidPtr NewFilesystemManager::Read(NodePtr node, Int32 flags, SizeT sz) { if ((reinterpret_cast<NewCatalog*>(node))->Kind == kNewFSCatalogKindFile) - return fImpl->ReadCatalog(reinterpret_cast<NewCatalog*>(node), sz); + return fImpl->ReadCatalog(reinterpret_cast<NewCatalog*>(node)->Name, sz); return nullptr; } diff --git a/Private/Source/KernelCheck.cxx b/Private/Source/KernelCheck.cxx index d649ef35..516230ea 100644 --- a/Private/Source/KernelCheck.cxx +++ b/Private/Source/KernelCheck.cxx @@ -21,61 +21,61 @@ extern "C" [[noreturn]] void ke_wait_for_debugger() { namespace NewOS { void ke_stop(const NewOS::Int &id) { - kcout << "*** STOP *** \r\n"; - kcout << "*** NewKernel.exe has trigerred a runtime stop. *** \r\n"; + kcout << "*** STOP *** \r"; + kcout << "*** NewKernel.exe has trigerred a runtime stop. *** \r"; switch (id) { case RUNTIME_CHECK_PROCESS: { - kcout << "*** CAUSE: RUNTIME_CHECK_PROCESS *** \r\n"; - kcout << "*** WHAT: BAD DRIVER. *** \r\n"; + kcout << "*** CAUSE: RUNTIME_CHECK_PROCESS *** \r"; + kcout << "*** WHAT: BAD DRIVER. *** \r"; break; } case RUNTIME_CHECK_ACPI: { - kcout << "*** CAUSE: RUNTIME_CHECK_ACPI *** \r\n"; - kcout << "*** WHAT: ACPI ERROR, UNSTABLE STATE. *** \r\n"; + kcout << "*** CAUSE: RUNTIME_CHECK_ACPI *** \r"; + kcout << "*** WHAT: ACPI ERROR, UNSTABLE STATE. *** \r"; break; } case RUNTIME_CHECK_POINTER: { - kcout << "*** CAUSE: RUNTIME_CHECK_POINTER *** \r\n"; - kcout << "*** WHAT: HEAP CRC32 ERROR, UNSTABLE STATE. *** \r\n"; + kcout << "*** CAUSE: RUNTIME_CHECK_POINTER *** \r"; + kcout << "*** WHAT: HEAP CRC32 ERROR, UNSTABLE STATE. *** \r"; break; } case RUNTIME_CHECK_BAD_BEHAVIOR: { - kcout << "*** CAUSE: RUNTIME_CHECK_BAD_BEHAVIOR *** \r\n"; - kcout << "*** WHAT: KERNEL BECAME UNSTABLE. *** \r\n"; + kcout << "*** CAUSE: RUNTIME_CHECK_BAD_BEHAVIOR *** \r"; + kcout << "*** WHAT: KERNEL BECAME UNSTABLE. *** \r"; break; } case RUNTIME_CHECK_BOOTSTRAP: { - kcout << "*** CAUSE: RUNTIME_CHECK_BOOTSTRAP *** \r\n"; - kcout << "*** WHAT: INVALID BOOT SEQUENCE. *** \r\n"; + kcout << "*** CAUSE: RUNTIME_CHECK_BOOTSTRAP *** \r"; + kcout << "*** WHAT: INVALID BOOT SEQUENCE. *** \r"; break; } case RUNTIME_CHECK_HANDSHAKE: { - kcout << "*** CAUSE: RUNTIME_CHECK_HANDSHAKE *** \r\n"; - kcout << "*** WHAT: BAD HANDSHAKE. *** \r\n"; + kcout << "*** CAUSE: RUNTIME_CHECK_HANDSHAKE *** \r"; + kcout << "*** WHAT: BAD HANDSHAKE. *** \r"; break; } case RUNTIME_CHECK_IPC: { - kcout << "*** CAUSE: RUNTIME_CHECK_IPC *** \r\n"; - kcout << "*** WHAT: RICH CALL VIOLATION. *** \r\n"; + kcout << "*** CAUSE: RUNTIME_CHECK_IPC *** \r"; + kcout << "*** WHAT: RICH CALL VIOLATION. *** \r"; break; } case RUNTIME_CHECK_INVALID_PRIVILEGE: { - kcout << "*** CAUSE: RUNTIME_CHECK_INVALID_PRIVILEGE *** \r\n"; - kcout << "*** WHAT: HYPERVISOR POLICY VIOLATION. *** \r\n"; + kcout << "*** CAUSE: RUNTIME_CHECK_INVALID_PRIVILEGE *** \r"; + kcout << "*** WHAT: HYPERVISOR POLICY VIOLATION. *** \r"; break; case RUNTIME_CHECK_UNEXCPECTED: { - kcout << "*** CAUSE: RUNTIME_CHECK_UNEXCPECTED *** \r\n"; - kcout << "*** WHAT: CATASROPHIC FAILURE! *** \r\n"; + kcout << "*** CAUSE: RUNTIME_CHECK_UNEXCPECTED *** \r"; + kcout << "*** WHAT: CATASROPHIC FAILURE! *** \r"; break; } case RUNTIME_CHECK_FAILED: { - kcout << "*** CAUSE: RUNTIME_CHECK_FAILED *** \r\n"; - kcout << "*** WHAT: ASSERTION FAILED! *** \r\n"; + kcout << "*** CAUSE: RUNTIME_CHECK_FAILED *** \r"; + kcout << "*** WHAT: ASSERTION FAILED! *** \r"; break; } default: { - kcout << "*** CAUSE: RUNTIME_CHECK_GENERIC *** \r\n"; + kcout << "*** CAUSE: RUNTIME_CHECK_GENERIC *** \r"; break; } } @@ -91,8 +91,8 @@ void ke_stop(const NewOS::Int &id) { void ke_runtime_check(bool expr, const char *file, const char *line) { if (!expr) { #ifdef __DEBUG__ - kcout << "New Kernel: File: " << file << "\r\n"; - kcout << "New Kernel: Line: " << line << "\r\n"; + kcout << "New Kernel: File: " << file << "\r"; + kcout << "New Kernel: Line: " << line << "\r"; #endif // __DEBUG__ diff --git a/Private/Source/Network/IP.cxx b/Private/Source/Network/IP.cxx index 06421c21..b3107f17 100644 --- a/Private/Source/Network/IP.cxx +++ b/Private/Source/Network/IP.cxx @@ -29,7 +29,7 @@ bool RawIPAddress::operator!=(const RawIPAddress& ipv4) { } char& RawIPAddress::operator[](const Size& index) { - kcout << "[RawIPAddress::operator[]] Fetching Index...\r\n"; + kcout << "[RawIPAddress::operator[]] Fetching Index...\r"; static char IP_PLACEHOLDER = '0'; if (index > 4) return IP_PLACEHOLDER; @@ -42,7 +42,7 @@ RawIPAddress6::RawIPAddress6(char bytes[8]) { } char& RawIPAddress6::operator[](const Size& index) { - kcout << "[RawIPAddress6::operator[]] Fetching Index...\r\n"; + kcout << "[RawIPAddress6::operator[]] Fetching Index...\r"; static char IP_PLACEHOLDER = '0'; if (index > 8) return IP_PLACEHOLDER; diff --git a/Private/Source/NewFS+FileManager.cxx b/Private/Source/NewFS+FileManager.cxx index 910ec841..27beb9e0 100644 --- a/Private/Source/NewFS+FileManager.cxx +++ b/Private/Source/NewFS+FileManager.cxx @@ -20,9 +20,9 @@ NewFilesystemManager::NewFilesystemManager() { } NewFilesystemManager::~NewFilesystemManager() { - if (fImpl) { - delete fImpl; - } + if (fImpl) { + delete fImpl; + } } /// @brief Removes a node from the filesystem. @@ -31,10 +31,7 @@ NewFilesystemManager::~NewFilesystemManager() { bool NewFilesystemManager::Remove(const char* fileName) { if (fileName == nullptr || *fileName == 0) return false; - if (auto catalog = fImpl->GetCatalog(fileName); catalog) - return fImpl->RemoveCatalog(catalog); - - return false; + return fImpl->RemoveCatalog(fileName); } /// @brief Creates a node with the specified. diff --git a/Private/Source/ProcessScheduler.cxx b/Private/Source/ProcessScheduler.cxx index 69236c18..3cd5f885 100644 --- a/Private/Source/ProcessScheduler.cxx +++ b/Private/Source/ProcessScheduler.cxx @@ -34,7 +34,7 @@ const Int32 &rt_get_exit_code() noexcept { return kExitCode; } /***********************************************************************************/ void ProcessHeader::Crash() { - kcout << "ProcessScheduler: Crashed, ExitCode: -1.\r\n"; + kcout << "ProcessScheduler: Crashed, ExitCode: -1.\r"; MUST_PASS(ke_bug_check()); this->Exit(-1); @@ -162,7 +162,7 @@ SizeT ProcessScheduler::Add(Ref<ProcessHeader> &process) { if (process.Leak().Ring != (Int32)ProcessSelector::kRingKernel) return -1; - kcout << "ProcessScheduler::Add(Ref<ProcessHeader>& process)\r\n"; + kcout << "ProcessScheduler::Add(Ref<ProcessHeader>& process)\r"; /// Create heap according to type of process. if (process.Leak().Kind == ProcessHeader::kUserKind) @@ -188,7 +188,7 @@ SizeT ProcessScheduler::Add(Ref<ProcessHeader> &process) { bool ProcessScheduler::Remove(SizeT process) { if (process > mTeam.AsArray().Count()) return false; - kcout << "ProcessScheduler::Remove(SizeT process)\r\n"; + kcout << "ProcessScheduler::Remove(SizeT process)\r"; return mTeam.AsArray().Remove(process); } @@ -234,7 +234,7 @@ Ref<ProcessScheduler> ProcessScheduler::Shared() { Ref<ProcessHeader> &ProcessScheduler::GetCurrent() { return mTeam.AsRef(); } PID &ProcessHelper::GetCurrentPID() { - kcout << "ProcessHelper::GetCurrentPID: Leaking ProcessId...\r\n"; + kcout << "ProcessHelper::GetCurrentPID: Leaking ProcessId...\r"; return ProcessScheduler::Shared().Leak().GetCurrent().Leak().ProcessId; } @@ -275,7 +275,7 @@ bool ProcessHelper::StartScheduling() { SizeT ret = processRef.Run(); kcout << StringBuilder::FromInt( - "ProcessHelper::StartScheduling() Iterated over {%} jobs inside team.\r\n", ret); + "ProcessHelper::StartScheduling() Iterated over {%} jobs inside team.\r", ret); return true; } diff --git a/Private/Source/ThreadLocalStorage.cxx b/Private/Source/ThreadLocalStorage.cxx index 8d3281e3..05e0dbe9 100644 --- a/Private/Source/ThreadLocalStorage.cxx +++ b/Private/Source/ThreadLocalStorage.cxx @@ -31,7 +31,7 @@ Boolean tls_check_tib(ThreadInformationBlock* tib) { Encoder encoder; const char* tibAsBytes = encoder.AsBytes(tib); - kcout << "New OS: Checking for a valid cookie...\r\n"; + kcout << "New OS: Checking for a valid cookie...\r"; return tibAsBytes[0] == kCookieMag0 && tibAsBytes[1] == kCookieMag1 && tibAsBytes[2] == kCookieMag2; @@ -46,9 +46,9 @@ EXTERN_C Void tls_check_syscall_impl(NewOS::HAL::StackFramePtr stackPtr) noexcep ThreadInformationBlock* tib = (ThreadInformationBlock*)stackPtr->Gs; if (!tls_check_tib(tib)) { - kcout << "New OS: Verification failed, Crashing...\r\n"; + kcout << "New OS: Verification failed, Crashing...\r"; ProcessScheduler::Shared().Leak().GetCurrent().Leak().Crash(); } - kcout << "New OS: Verification succeeded! Keeping on...\r\n"; + kcout << "New OS: Verification succeeded! Keeping on...\r"; } diff --git a/Private/Source/UserHeap.cxx b/Private/Source/UserHeap.cxx index 5f092102..9580c814 100644 --- a/Private/Source/UserHeap.cxx +++ b/Private/Source/UserHeap.cxx @@ -74,7 +74,7 @@ STATIC VoidPtr ke_find_unused_heap(Int32 flags) { !UserHeapManager::The()[index].Leak().Leak().Present()) { UserHeapManager::Leak().Leak().TogglePresent( UserHeapManager::The()[index].Leak().Leak(), true); - kcout << "[ke_find_unused_heap] Done, trying to make a pool now...\r\n"; + kcout << "[ke_find_unused_heap] Done, trying to make a pool now...\r"; return ke_make_heap_internal( (VoidPtr)UserHeapManager::The()[index].Leak().Leak().VirtualAddress(), @@ -129,7 +129,7 @@ STATIC Void ke_free_heap_internal(VoidPtr virtualAddress) { poolHdr->fFree = true; poolHdr->fFlags = 0; - kcout << "[ke_free_heap_internal] Successfully marked header as free!\r\n"; + kcout << "[ke_free_heap_internal] Successfully marked header as free!\r"; } } |
