summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Private/Drivers/Bonjour/Bonjour.c4
-rw-r--r--Private/Drivers/MahroussUpdate/MahroussUpdate.cc2
-rw-r--r--Private/Drivers/SampleDriver/SampleDriver.c4
-rw-r--r--Private/FSKit/NewFS.hxx18
-rw-r--r--Private/FirmwareKit/EFI/API.hxx4
-rw-r--r--Private/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp2
-rw-r--r--Private/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp4
-rw-r--r--Private/HALKit/AMD64/HalDebugOutput.cxx5
-rw-r--r--Private/HALKit/AMD64/PCI/Dma.cxx2
-rw-r--r--Private/HALKit/AMD64/Storage/AHCI.cxx2
-rw-r--r--Private/HALKit/AMD64/Storage/ATA-PIO.cxx4
-rw-r--r--Private/KernelKit/DebugOutput.hpp2
-rw-r--r--Private/NetworkKit/NetworkDevice.inl6
-rw-r--r--Private/NewBoot/BootKit/BootKit.hxx8
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootATA.cxx2
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx10
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootMain.cxx6
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootTextWriter.cxx30
-rw-r--r--Private/NewBoot/Source/makefile2
-rw-r--r--Private/NewKit/Array.hpp6
-rw-r--r--Private/NewKit/Utils.hpp2
-rw-r--r--Private/Source/AppMain.cxx68
-rw-r--r--Private/Source/FS/NewFS.cxx321
-rw-r--r--Private/Source/KernelCheck.cxx50
-rw-r--r--Private/Source/Network/IP.cxx4
-rw-r--r--Private/Source/NewFS+FileManager.cxx11
-rw-r--r--Private/Source/ProcessScheduler.cxx10
-rw-r--r--Private/Source/ThreadLocalStorage.cxx6
-rw-r--r--Private/Source/UserHeap.cxx4
-rw-r--r--Private/Source/Utils.cxx2
30 files changed, 349 insertions, 252 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..b461666d 100644
--- a/Private/FSKit/NewFS.hxx
+++ b/Private/FSKit/NewFS.hxx
@@ -43,8 +43,8 @@ default.
/// @brief Partition GUID on EPM and GPT disks.
#define kNewFSUUID "@{DD997393-9CCE-4288-A8D5-C0FDE3908DBE}"
-#define kNewFSVersionInteger 0x123
-#define kNewFSVerionString "1.23"
+#define kNewFSVersionInteger 0x124
+#define kNewFSVerionString "1.24"
/// @brief Standard fork types.
#define kNewFSDataFork "data"
@@ -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,11 @@ struct PACKED NewCatalog final {
NewCharType Name[kNewFSNodeNameLen];
NewCharType Mime[kNewFSMimeNameLen];
- NewOS::Int32 Flags;
+ /// Catalog status flag.
+ NewOS::UInt16 Flags;
+ /// Custom catalog flags.
+ NewOS::UInt16 FileFlags;
+ /// Catalog kind.
NewOS::Int32 Kind;
/// Size of the data fork.
@@ -242,7 +246,7 @@ class NewFSParser final {
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/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile
index 9018623f..df913031 100644
--- a/Private/NewBoot/Source/makefile
+++ b/Private/NewBoot/Source/makefile
@@ -75,7 +75,7 @@ run-efi-amd64:
.PHONY: epm-img
epm-img:
- qemu-img create -f raw $(IMG) 1G
+ qemu-img create -f raw $(IMG) 4G
qemu-img create -f raw $(IMG_2) 512M
.PHONY: download-edk
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/NewKit/Utils.hpp b/Private/NewKit/Utils.hpp
index 749e15ba..c9503479 100644
--- a/Private/NewKit/Utils.hpp
+++ b/Private/NewKit/Utils.hpp
@@ -24,5 +24,5 @@ Boolean is_space(Char chr);
Int rt_to_uppercase(Int c);
Int rt_to_lower(Int c);
voidPtr rt_string_in_string(const char *in, const char *needle);
-char *rt_string_frofchar(char *str, const char chr);
+char *rt_string_has_char(char *str, const char chr);
} // namespace NewOS
diff --git a/Private/Source/AppMain.cxx b/Private/Source/AppMain.cxx
index 6a23e20d..966172df 100644
--- a/Private/Source/AppMain.cxx
+++ b/Private/Source/AppMain.cxx
@@ -26,48 +26,36 @@ EXTERN_C NewOS::Void AppMain(NewOS::Void) {
NewOS::FilesystemManagerInterface::Mount(newFS);
if (newFS->GetImpl()) {
- NewCatalog* mountCatalog = newFS->GetImpl()->GetCatalog("/Boot/");
-
- if (mountCatalog) {
- delete newFS->GetImpl()->CreateCatalog("/Boot/System/", 0,
- kNewFSCatalogKindDir);
- NewCatalog* newKernelCatalog =
- newFS->GetImpl()->CreateCatalog("/Boot/System/ExampleTextFile");
-
- if (newKernelCatalog)
- NewOS::kcout << "Catalog-Path-Name: " << newKernelCatalog->Name
- << NewOS::endl;
-
- NewOS::kcout << "Catalog-Path-Name: " << mountCatalog->Name
- << NewOS::endl;
-
- 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.."};
-
- NewFork theFork{0};
- NewOS::rt_copy_memory((NewOS::VoidPtr) "EditableText",
- (NewOS::VoidPtr)theFork.Name,
- NewOS::rt_string_len("EditableText"));
-
- theFork.Kind = NewOS::kNewFSDataForkKind;
- theFork.DataSize = cDataSz;
-
- newFS->GetImpl()->CreateFork(newKernelCatalog, theFork);
- newFS->GetImpl()->WriteCatalog(newKernelCatalog, theData, cDataSz);
-
- delete newKernelCatalog;
- delete mountCatalog;
+ NewCatalog* textCatalog = nullptr;
+
+ if (!newFS->GetImpl()->GetCatalog("/EditableText")) {
+ constexpr auto cDataSz = 512;
+ NewOS::Char theData[cDataSz] = {
+ "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",
+ (NewOS::VoidPtr)theFork.Name,
+ NewOS::rt_string_len("EditableText"));
+
+ theFork.Kind = NewOS::kNewFSDataForkKind;
+ theFork.DataSize = cDataSz;
+
+ textCatalog = newFS->GetImpl()->CreateCatalog("/EditableText");
+
+ newFS->GetImpl()->CreateFork(textCatalog, theFork);
+ newFS->GetImpl()->WriteCatalog(textCatalog, theData, cDataSz);
} else {
- delete newFS->GetImpl()->CreateCatalog("/Boot/", 0, kNewFSCatalogKindDir);
+ NewOS::kcout << "Catalog already exists.\r";
}
+
+ char* buf = nullptr;
+
+ buf = (NewOS::Char*)newFS->GetImpl()->ReadCatalog(newFS->GetImpl()->GetCatalog("/EditableText"), 512);
+
+ NewOS::kcout << buf << NewOS::endl;
}
while (NewOS::ProcessScheduler::Shared().Leak().Run() > 0)
diff --git a/Private/Source/FS/NewFS.cxx b/Private/Source/FS/NewFS.cxx
index 57f61cd2..2a85d394 100644
--- a/Private/Source/FS/NewFS.cxx
+++ b/Private/Source/FS/NewFS.cxx
@@ -11,6 +11,7 @@
#include <FSKit/NewFS.hxx>
#include <KernelKit/HError.hpp>
#include <NewKit/Crc32.hpp>
+#include <NewKit/KernelCheck.hpp>
#include <NewKit/String.hpp>
#include <NewKit/Utils.hpp>
@@ -24,41 +25,32 @@ STATIC MountpointInterface sMountpointInterface;
/// @return the fork
_Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog,
_Input NewFork& theFork) {
+ if (!sMountpointInterface.GetAddressOf(this->fDriveIndex)) return nullptr;
+
if (catalog && theFork.Name[0] != 0 && theFork.DataSize > 0) {
- theFork.Flags = kNewFSFlagCreated;
Lba lba = (theFork.Kind == kNewFSDataForkKind) ? catalog->DataFork
: catalog->ResourceFork;
- if (lba <= kNewFSCatalogStartAddress) return nullptr;
+ kcout << "Data-Fork-LBA: " << hex_number(lba) << endl;
- theFork.DataOffset = lba + sizeof(NewFork);
+ if (lba <= kNewFSCatalogStartAddress) return nullptr;
- if (!sMountpointInterface.GetAddressOf(this->fDriveIndex)) return nullptr;
+ theFork.DataOffset = lba - sizeof(NewFork);
auto drv = sMountpointInterface.GetAddressOf(this->fDriveIndex);
- Char cpyFork[sizeof(NewFork)] = {0};
-
- drv->fPacket.fLba = lba + sizeof(NewCatalog);
- drv->fPacket.fPacketSize = sizeof(NewFork);
- drv->fPacket.fPacketContent = (VoidPtr)cpyFork;
-
- drv->fInput(&drv->fPacket);
-
- NewFork* cpyForkStruct = (NewFork*)cpyFork;
-
- if (cpyForkStruct->Flags == kNewFSFlagCreated) return nullptr;
-
/// special treatment.
rt_copy_memory((VoidPtr) "fs/newfs-packet", drv->fPacket.fPacketMime,
rt_string_len("fs/newfs-packet"));
drv->fPacket.fLba = lba;
drv->fPacket.fPacketSize = sizeof(NewFork);
- drv->fPacket.fPacketContent = (VoidPtr)&theFork;
+ drv->fPacket.fPacketContent = &theFork;
drv->fOutput(&drv->fPacket);
+ kcout << "New OS: Wrote fork data at: " << hex_number(theFork.DataOffset) << endl;
+
return &theFork;
}
@@ -74,6 +66,7 @@ _Output NewFork* NewFSParser::FindFork(_Input NewCatalog* catalog,
Boolean isDataFork) {
auto drv = sMountpointInterface.GetAddressOf(this->fDriveIndex);
NewFork* theFork = nullptr;
+
Lba lba = isDataFork ? catalog->DataFork : catalog->ResourceFork;
while (lba != 0) {
@@ -147,35 +140,35 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name,
return checkForCpy;
}
- char copyName[kNewFSNodeNameLen] = {0};
+ char parentName[kNewFSNodeNameLen] = {0};
for (SizeT indexName = 0UL; indexName < rt_string_len(name); ++indexName) {
- copyName[indexName] = name[indexName];
+ parentName[indexName] = name[indexName];
}
- if (*copyName == 0) {
+ if (*parentName == 0) {
DbgLastError() = kErrorFileNotFound;
return nullptr;
}
for (SizeT indexFill = 0; indexFill < rt_string_len(name); ++indexFill) {
- copyName[indexFill] = name[indexFill];
+ parentName[indexFill] = name[indexFill];
}
- SizeT indexReverseCopy = rt_string_len(copyName);
+ SizeT indexReverseCopy = rt_string_len(parentName);
// zero character.
- copyName[--indexReverseCopy] = 0;
+ parentName[--indexReverseCopy] = 0;
// mandatory / character.
- copyName[--indexReverseCopy] = 0;
+ parentName[--indexReverseCopy] = 0;
- while (copyName[indexReverseCopy] != '/') {
- copyName[indexReverseCopy] = 0;
+ while (parentName[indexReverseCopy] != '/') {
+ parentName[indexReverseCopy] = 0;
--indexReverseCopy;
}
- NewCatalog* catalog = this->FindCatalog(copyName, outLba);
+ NewCatalog* catalog = this->FindCatalog(parentName, outLba);
if (!catalog) {
return nullptr;
@@ -186,7 +179,7 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name,
return nullptr;
}
- constexpr SizeT cDefaultForkSize = 8192;
+ constexpr SizeT cDefaultForkSize = 8196;
NewCatalog* catalogChild = new NewCatalog();
@@ -195,29 +188,33 @@ _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));
- UInt16 sectorBuf[kNewFSMinimumSectorSz] = {0};
+ UInt16 catalogBuf[kNewFSMinimumSectorSz] = {0};
auto drive = sMountpointInterface.GetAddressOf(this->fDriveIndex);
Lba startFree = catalogChild->PrevSibling + catalog->NextSibling;
- kcout << "Next-Catalog: " << hex_number(startFree) << endl;
+ kcout << "Free-Catalog: " << hex_number(startFree) << endl;
+ kcout << "New-Catalog: " << name << endl;
+ kcout << "Parent-Catalog: " << parentName << endl;
- drive->fPacket.fPacketContent = sectorBuf;
+ rt_copy_memory((VoidPtr) "fs/newfs-packet", drive->fPacket.fPacketMime,
+ rt_string_len("fs/newfs-packet"));
+
+ drive->fPacket.fPacketContent = catalogBuf;
drive->fPacket.fPacketSize = kNewFSMinimumSectorSz;
drive->fPacket.fLba = startFree;
drive->fInput(&drive->fPacket);
while (drive->fPacket.fPacketGood) {
- NewCatalog* nextSibling = (NewCatalog*)sectorBuf;
+ NewCatalog* nextSibling = (NewCatalog*)catalogBuf;
if (startFree <= kNewFSAddressAsLba) {
delete catalogChild;
@@ -227,80 +224,82 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name,
}
/// allocation or reallocation or catalog...
- if ((nextSibling->Name[0] == 0 &&
- nextSibling->Flags != kNewFSFlagCreated)) {
- catalogChild->DataFork = startFree + sizeof(NewCatalog);
- catalogChild->ResourceFork =
- startFree + sizeof(NewCatalog) + catalogChild->DataForkSize;
+ if (nextSibling->Flags != kNewFSFlagCreated) {
+ Char sectorBufPartBlock[kNewFSMinimumSectorSz] = {0};
- if ((nextSibling->Flags != kNewFSFlagCreated)) {
- nextSibling->Flags = kNewFSFlagCreated;
+ drive->fPacket.fPacketContent = sectorBufPartBlock;
+ drive->fPacket.fPacketSize = kNewFSMinimumSectorSz;
+ drive->fPacket.fLba = kNewFSAddressAsLba;
- drive->fPacket.fPacketContent = catalogChild;
- drive->fPacket.fPacketSize = sizeof(NewCatalog);
- drive->fPacket.fLba = startFree;
+ drive->fInput(&drive->fPacket);
- 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"));
- }
+ NewPartitionBlock* partBlock = (NewPartitionBlock*)sectorBufPartBlock;
- catalogChild->NextSibling = sizeof(NewCatalog) +
- catalogChild->DataForkSize +
- catalogChild->ResourceForkOverallSize;
+ catalogChild->DataFork =
+ partBlock->DiskSize - startFree - sizeof(NewCatalog);
- drive->fOutput(&drive->fPacket);
+ kcout << "DataFork: " << hex_number(catalogChild->DataFork) << endl;
- kcout << "New OS: Create new catalog successfully!\r\n";
+ catalogChild->ResourceFork = catalogChild->DataFork;
- Char sectBuf[sizeof(NewCatalog)] = {0};
+ 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"));
+ }
- drive->fPacket.fPacketContent = sectBuf;
- drive->fPacket.fPacketSize = sizeof(NewCatalog);
- drive->fPacket.fLba = catalogChild->PrevSibling;
+ catalogChild->NextSibling = sizeof(NewCatalog) +
+ catalogChild->DataForkSize +
+ catalogChild->ResourceForkOverallSize;
- drive->fInput(&drive->fPacket);
+ rt_copy_memory(catalogChild, catalogBuf, sizeof(NewCatalog));
- NewCatalog* prevCatalog = (NewCatalog*)sectBuf;
- prevCatalog->NextSibling = startFree;
+ drive->fPacket.fPacketContent = catalogBuf;
+ drive->fPacket.fPacketSize = sizeof(NewCatalog);
+ drive->fPacket.fLba = startFree;
- drive->fOutput(&drive->fPacket);
+ drive->fOutput(&drive->fPacket);
- kcout << "Edit-Catalog: " << prevCatalog->Name << endl;
+ kcout << "New OS: Create new catalog, status: "
+ << hex_number(nextSibling->Flags) << endl;
- Char sectorBufPartBlock[kNewFSMinimumSectorSz] = {0};
+ Char sectBuf[sizeof(NewCatalog)] = {0};
- drive->fPacket.fPacketContent = sectorBufPartBlock;
- drive->fPacket.fPacketSize = kNewFSMinimumSectorSz;
- drive->fPacket.fLba = kNewFSAddressAsLba;
+ drive->fPacket.fPacketContent = sectBuf;
+ drive->fPacket.fPacketSize = sizeof(NewCatalog);
+ drive->fPacket.fLba = catalogChild->PrevSibling;
- drive->fInput(&drive->fPacket);
+ drive->fInput(&drive->fPacket);
- NewPartitionBlock* partBlock = (NewPartitionBlock*)sectorBufPartBlock;
+ NewCatalog* prevCatalog = (NewCatalog*)sectBuf;
+ prevCatalog->NextSibling = startFree;
- partBlock->SectorCount -= 1;
- partBlock->CatalogCount += 1;
- partBlock->FreeCatalog -= 1;
+ drive->fOutput(&drive->fPacket);
- drive->fOutput(&drive->fPacket);
+ kcout << "Edit-Catalog: " << prevCatalog->Name << endl;
- delete catalog;
- return catalogChild;
- } else {
- delete catalog;
- return nullptr;
- }
+ drive->fPacket.fPacketContent = sectorBufPartBlock;
+ drive->fPacket.fPacketSize = kNewFSMinimumSectorSz;
+ drive->fPacket.fLba = kNewFSAddressAsLba;
+
+ drive->fInput(&drive->fPacket);
+
+ partBlock->SectorCount -= 1;
+ partBlock->CatalogCount += 1;
+ partBlock->FreeCatalog -= 1;
+
+ drive->fOutput(&drive->fPacket);
+
+ delete catalog;
+ return catalogChild;
}
//// @note that's how we find the next catalog in the partition block.
- startFree += sizeof(NewFork) + sizeof(NewCatalog) +
- nextSibling->DataForkSize +
- nextSibling->ResourceForkOverallSize;
+ startFree += sizeof(NewFork) + sizeof(NewCatalog) + cDefaultForkSize;
- drive->fPacket.fPacketContent = sectorBuf;
+ drive->fPacket.fPacketContent = catalogBuf;
drive->fPacket.fPacketSize = kNewFSMinimumSectorSz;
drive->fPacket.fLba = startFree;
@@ -318,6 +317,9 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive) {
/// verify disk.
drive->fVerify(&drive->fPacket);
+ rt_copy_memory((VoidPtr) "fs/newfs-packet", drive->fPacket.fPacketMime,
+ rt_string_len("fs/newfs-packet"));
+
/// if disk isn't good, then error out.
if (false == drive->fPacket.fPacketGood) {
DbgLastError() = kErrorDiskIsCorrupted;
@@ -357,7 +359,7 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive) {
partBlock->Kind = kNewFSPartitionTypeStandard;
partBlock->StartCatalog = kNewFSCatalogStartAddress;
- partBlock->Flags |= kNewFSPartitionTypeStandard;
+ partBlock->Flags = kNewFSPartitionTypeStandard;
partBlock->CatalogCount = sectorCount / sizeof(NewCatalog);
partBlock->SectorCount = sectorCount;
partBlock->DiskSize = diskSize;
@@ -369,10 +371,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: " << hex_number(partBlock->StartCatalog) << endl;
+ kcout << "Catalog-Count: " << hex_number(partBlock->CatalogCount) << endl;
+ kcout << "Free-Catalog: " << hex_number(partBlock->FreeCatalog) << endl;
+ kcout << "Free-Sectors: " << hex_number(partBlock->FreeSectors) << endl;
+ kcout << "Sector-Size: " << hex_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;
@@ -391,9 +402,13 @@ bool NewFSParser::WriteCatalog(_Input _Output NewCatalog* catalog, voidPtr data,
if (!sMountpointInterface.GetAddressOf(this->fDriveIndex)) return false;
NewFork* forkData = new NewFork();
+ rt_set_memory(forkData, 0, sizeof(NewFork));
auto drive = sMountpointInterface.GetAddressOf(this->fDriveIndex);
+ rt_copy_memory((VoidPtr) "fs/newfs-packet", drive->fPacket.fPacketMime,
+ rt_string_len("fs/newfs-packet"));
+
auto startFork = catalog->DataFork;
/// sanity check of the fork position as the condition to run the loop.
@@ -404,18 +419,12 @@ bool NewFSParser::WriteCatalog(_Input _Output NewCatalog* catalog, voidPtr data,
drive->fInput(&drive->fPacket);
- /// check if fork even exists.
- if (forkData->Flags != kNewFSFlagCreated) {
- DbgLastError() = kErrorDiskIsCorrupted;
-
- delete forkData;
- return false;
- }
-
/// sanity check the fork.
if (forkData->DataOffset <= kNewFSCatalogStartAddress) {
DbgLastError() = kErrorDiskIsCorrupted;
+ kcout << "New OS: Invalid fork offset.\r";
+
delete forkData;
return false;
}
@@ -433,8 +442,8 @@ bool NewFSParser::WriteCatalog(_Input _Output NewCatalog* catalog, voidPtr data,
}
/// @brief
-/// @param catalogName
-/// @return
+/// @param catalogName the catalog name.
+/// @return the newly found catalog.
_Output NewCatalog* NewFSParser::FindCatalog(_Input const char* catalogName,
Lba& outLba) {
if (!sMountpointInterface.GetAddressOf(this->fDriveIndex)) return nullptr;
@@ -442,6 +451,9 @@ _Output NewCatalog* NewFSParser::FindCatalog(_Input const char* catalogName,
Char* sectorBuf = new Char[sizeof(NewPartitionBlock)];
auto drive = sMountpointInterface.GetAddressOf(this->fDriveIndex);
+ rt_copy_memory((VoidPtr) "fs/newfs-packet", drive->fPacket.fPacketMime,
+ rt_string_len("fs/newfs-packet"));
+
drive->fPacket.fPacketContent = sectorBuf;
drive->fPacket.fPacketSize = sizeof(NewPartitionBlock);
drive->fPacket.fLba = kNewFSAddressAsLba;
@@ -450,15 +462,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,17 +473,30 @@ _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));
+ kcout << "New OS: Found catalog at: " << hex_number(start) << endl;
+
outLba = start;
delete[] sectorBuf;
return catalogPtr;
}
+ _NewFSContinueSearch:
start = catalog->NextSibling;
+ kcout << "Catalog-Next: " << hex_number(start) << endl;
+
if (start <= kNewFSAddressAsLba) break;
drive->fPacket.fLba = start;
@@ -508,28 +524,46 @@ _Output NewCatalog* NewFSParser::GetCatalog(_Input const char* name) {
/// @param catalog
/// @return
Boolean NewFSParser::CloseCatalog(_Input _Output NewCatalog* catalog) {
- if (this->WriteCatalog(catalog, nullptr, 0)) {
- delete catalog;
- catalog = nullptr;
+ if (!catalog) return false;
- return true;
- }
+ delete catalog;
+ catalog = nullptr;
- return false;
+ return true;
}
/// @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);
+ rt_copy_memory((VoidPtr) "fs/newfs-packet", drive->fPacket.fPacketMime,
+ rt_string_len("fs/newfs-packet"));
+
+ 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;
}
@@ -548,12 +582,55 @@ VoidPtr NewFSParser::ReadCatalog(_Input _Output NewCatalog* catalog,
return nullptr;
}
- return nullptr;
+ if (!sMountpointInterface.GetAddressOf(this->fDriveIndex)) return nullptr;
+
+ Lba dataForkLba = catalog->DataFork;
+ Size dataForkSize = catalog->DataForkSize;
+
+ kcout << "Found-Catalog: " << catalog->Name
+ << ", Data-Fork: " << hex_number(dataForkLba) << endl;
+
+ Char* sectorBuf = new Char[sizeof(NewFork)];
+ auto drive = sMountpointInterface.GetAddressOf(this->fDriveIndex);
+
+ rt_copy_memory((VoidPtr) "fs/newfs-packet", drive->fPacket.fPacketMime,
+ rt_string_len("fs/newfs-packet"));
+
+ drive->fPacket.fLba = dataForkLba;
+ drive->fPacket.fPacketSize = sizeof(NewFork);
+ drive->fPacket.fPacketContent = sectorBuf;
+
+ drive->fInput(&drive->fPacket);
+
+ NewFork* forkData = (NewFork*)sectorBuf;
+
+ kcout << "Fork-Name: " << forkData->Name << endl;
+
+ if (forkData->DataOffset <= kNewFSCatalogStartAddress ||
+ dataSz > forkData->DataSize) {
+ delete[] sectorBuf;
+
+ kcout << "Fail-Data-Offset: " << hex_number(forkData->DataOffset) << endl;
+
+ 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 +638,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 +647,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/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";
}
}
diff --git a/Private/Source/Utils.cxx b/Private/Source/Utils.cxx
index 11b7129a..8eeb8cea 100644
--- a/Private/Source/Utils.cxx
+++ b/Private/Source/Utils.cxx
@@ -157,7 +157,7 @@ voidPtr rt_string_in_string(const char *in, const char *needle) {
// @brief Checks for a string start at the character.
-char *rt_string_frofchar(char *str, const char chr) {
+char *rt_string_has_char(char *str, const char chr) {
while (*str != chr) {
++str;