summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Private/Source/AppMain.cxx86
-rw-r--r--Private/Source/FS/NewFS.cxx46
-rw-r--r--Private/Source/ProcessScheduler.cxx12
3 files changed, 84 insertions, 60 deletions
diff --git a/Private/Source/AppMain.cxx b/Private/Source/AppMain.cxx
index 5618c574..663a6775 100644
--- a/Private/Source/AppMain.cxx
+++ b/Private/Source/AppMain.cxx
@@ -20,19 +20,20 @@
#include <NewKit/Json.hpp>
#include <NewKit/KernelCheck.hpp>
#include <NewKit/Utils.hpp>
+#include <NewKit/String.hpp>
namespace Detail {
/// @brief Filesystem auto mounter, additional checks are also done by the
/// class.
-class FilesystemAutomountProvider final {
+class FilesystemWizard final {
NewOS::NewFilesystemManager* fNewFS{nullptr};
public:
- explicit FilesystemAutomountProvider() {
+ explicit FilesystemWizard() {
if (NewOS::FilesystemManagerInterface::GetMounted()) {
/// Mounted partition, cool!
NewOS::kcout
- << "New OS: Not need to mount for a NewFS partition here...\r";
+ << "New OS: No need to create for a NewFS partition here...\r";
} else {
/// Not mounted partition, auto-mount.
///! Mounts a NewFS block.
@@ -41,69 +42,68 @@ class FilesystemAutomountProvider final {
NewOS::FilesystemManagerInterface::Mount(fNewFS);
if (fNewFS->GetImpl()) {
- NewCatalog* sanitizerCatalog = nullptr;
-
- if (!fNewFS->GetImpl()->GetCatalog("/System/")) {
- delete fNewFS->GetImpl()->CreateCatalog("/System/", 0,
- kNewFSCatalogKindDir);
- delete fNewFS->GetImpl()->CreateCatalog("/Boot/", 0,
- kNewFSCatalogKindDir);
- delete fNewFS->GetImpl()->CreateCatalog("/Support/", 0,
- kNewFSCatalogKindDir);
- delete fNewFS->GetImpl()->CreateCatalog("/Applications/", 0,
- kNewFSCatalogKindDir);
+ constexpr auto cFolderInfo = "Metadata";
+ const auto cDirCount = 7;
+ const char* cDirStr[cDirCount] = {
+ "/Boot/", "/System/", "/Support/", "/Applications/",
+ "/Users/", "/Library/", "/Mount/"};
+
+ for (NewOS::SizeT dirIndx = 0UL; dirIndx < cDirCount; ++dirIndx) {
+ auto catalogDir = fNewFS->GetImpl()->GetCatalog(cDirStr[dirIndx]);
+
+ if (catalogDir) {
+ delete catalogDir;
+ continue;
+ }
+
+ catalogDir = fNewFS->GetImpl()->CreateCatalog(
+ cDirStr[dirIndx], 0, kNewFSCatalogKindDir);
NewFork theFork{0};
- const NewOS::Char* cSrcName = "FolderInfo";
+ const NewOS::Char* cSrcName = cFolderInfo;
- NewOS::rt_copy_memory((NewOS::VoidPtr)(cSrcName),
- theFork.ForkName,
+ NewOS::rt_copy_memory((NewOS::VoidPtr)(cSrcName), theFork.ForkName,
NewOS::rt_string_len(cSrcName));
+ NewOS::rt_copy_memory((NewOS::VoidPtr)(catalogDir->Name),
+ theFork.CatalogName,
+ NewOS::rt_string_len(catalogDir->Name));
+
+ delete catalogDir;
+
theFork.DataSize = kNewFSForkSize;
theFork.ResourceId = 0;
theFork.ResourceKind = NewOS::kNewFSRsrcForkKind;
theFork.Kind = NewOS::kNewFSDataForkKind;
- const NewOS::Char metadataFolder[kNewFSSectorSz] =
- "<p>Kind: folder</p>\r<p>Created by: system</p>\r";
- const NewOS::SizeT metadataSz = kNewFSSectorSz;
-
- auto catalogSystem = fNewFS->GetImpl()->GetCatalog("/System/");
+ NewOS::StringView metadataFolder(kNewFSSectorSz);
- fNewFS->GetImpl()->CreateFork(catalogSystem, theFork);
+ metadataFolder +=
+ "<p>Kind: folder</p>\r<p>Created by: system</p>\r<p>Edited by: "
+ "system</p>\r<p>Volume Type: New OS Standard</p>\r";
- fNewFS->GetImpl()->WriteCatalog(catalogSystem,
- (NewOS::VoidPtr)(metadataFolder),
- metadataSz, "FolderInfo");
+ metadataFolder += "<p>File name: ";
+ metadataFolder += cDirStr[dirIndx];
+ metadataFolder += "</p>\r";
- delete catalogSystem;
+ const NewOS::SizeT metadataSz = kNewFSSectorSz;
- catalogSystem = fNewFS->GetImpl()->GetCatalog("/Support/");
+ auto catalogSystem = fNewFS->GetImpl()->GetCatalog(cDirStr[dirIndx]);
fNewFS->GetImpl()->CreateFork(catalogSystem, theFork);
fNewFS->GetImpl()->WriteCatalog(catalogSystem,
- (NewOS::VoidPtr)(metadataFolder),
- metadataSz, "FolderInfo");
- }
-
- auto systemFolder = fNewFS->GetImpl()->GetCatalog("/System/");
- auto buf = fNewFS->GetImpl()->ReadCatalog(systemFolder, 512, "FolderInfo");
- NewOS::kcout << (NewOS::Char*)buf;
+ (NewOS::VoidPtr)(metadataFolder.CData()),
+ metadataSz, cFolderInfo);
- delete (NewOS::Char*) buf;
- delete systemFolder;
-
- systemFolder = fNewFS->GetImpl()->GetCatalog("/Boot/");
-
- NewOS::kcout << systemFolder->Name << NewOS::endl;
+ delete catalogSystem;
+ }
}
}
}
- ~FilesystemAutomountProvider() { delete fNewFS; }
+ ~FilesystemWizard() { delete fNewFS; }
};
} // namespace Detail
@@ -111,7 +111,7 @@ class FilesystemAutomountProvider final {
EXTERN_C NewOS::Void AppMain(NewOS::Void) {
/// Now run kernel loop, until no process are running.
- Detail::FilesystemAutomountProvider mounter;
+ Detail::FilesystemWizard mounter;
while (NewOS::ProcessScheduler::Shared().Leak().Run() > 0) {
;
diff --git a/Private/Source/FS/NewFS.cxx b/Private/Source/FS/NewFS.cxx
index 34a89d5d..fdbbda6d 100644
--- a/Private/Source/FS/NewFS.cxx
+++ b/Private/Source/FS/NewFS.cxx
@@ -17,6 +17,12 @@
using namespace NewOS;
+///! BUGS: 0
+
+/***********************************************************************************/
+/* This file implement the New File System.
+/***********************************************************************************/
+
STATIC MountpointInterface sMountpointInterface;
/// @brief Creates a new fork inside the New filesystem partition.
@@ -27,11 +33,12 @@ _Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog,
_Input NewFork& theFork) {
if (!sMountpointInterface.GetAddressOf(this->fDriveIndex)) return nullptr;
- if (catalog && theFork.ForkName[0] != 0 && theFork.DataSize == kNewFSForkSize) {
+ if (catalog && theFork.ForkName[0] != 0 &&
+ theFork.DataSize == kNewFSForkSize) {
Lba lba = (theFork.Kind == kNewFSDataForkKind) ? catalog->DataFork
: catalog->ResourceFork;
- kcout << "Fork-Lba: " << hex_number(lba) << endl;
+ kcout << "Fork Lba: " << hex_number(lba) << endl;
if (lba <= kNewFSCatalogStartAddress) return nullptr;
@@ -45,7 +52,8 @@ _Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog,
NewFork prevFork{0};
Lba lbaOfPreviousFork = lba;
- while (curFork.ForkName[0] == 0) {
+ /// do not check for anything. Loop until we get what we want, that is a free fork zone.
+ while (true) {
if (lba <= kNewFSCatalogStartAddress) break;
drv->fPacket.fLba = lba;
@@ -58,7 +66,13 @@ _Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog,
if (curFork.Flags == kNewFSFlagCreated) {
kcout << "New OS: Fork already exists.\r";
- if (StringBuilder::Equals(curFork.ForkName, theFork.ForkName)) return nullptr;
+
+ /// sanity check.
+ if (StringBuilder::Equals(curFork.ForkName, theFork.ForkName) &&
+ StringBuilder::Equals(curFork.CatalogName, catalog->Name))
+ return nullptr;
+
+ kcout << "Next-Fork: " << hex_number(curFork.NextSibling) << endl;
lbaOfPreviousFork = lba;
lba = curFork.NextSibling;
@@ -68,6 +82,10 @@ _Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog,
/// This is a check that we have, in order to link the previous fork
/// entry.
if (lba >= kNewFSCatalogStartAddress) {
+ drv->fPacket.fLba = lbaOfPreviousFork;
+ drv->fPacket.fPacketSize = sizeof(NewFork);
+ drv->fPacket.fPacketContent = &prevFork;
+
prevFork.NextSibling = lba;
/// write to disk.
@@ -78,7 +96,8 @@ _Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog,
}
}
- constexpr auto cForkPadding = 4;
+ constexpr auto cForkPadding =
+ 4; /// this value gives us space for the data offset.
theFork.Flags = kNewFSFlagCreated;
theFork.DataOffset = lba - sizeof(NewFork) * cForkPadding;
@@ -94,6 +113,7 @@ _Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog,
/// log what we have now.
kcout << "New OS: Wrote fork data at: " << hex_number(theFork.DataOffset)
<< endl;
+
kcout << "New OS: Wrote fork at: " << hex_number(lba) << endl;
return &theFork;
@@ -286,8 +306,8 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name,
NewPartitionBlock* partBlock = (NewPartitionBlock*)sectorBufPartBlock;
if (partBlock->FreeCatalog < 1) {
- delete catalogChild;
- return nullptr;
+ delete catalogChild;
+ return nullptr;
}
catalogChild->DataFork = partBlock->DiskSize - partBlock->StartCatalog;
@@ -462,6 +482,7 @@ bool NewFSParser::WriteCatalog(_Input _Output NewCatalog* catalog, voidPtr data,
drive->fPacket.fLba = startFork;
drive->fInput(&drive->fPacket);
+
kcout << "Fork-Name: " << forkData->ForkName << endl;
/// sanity check the fork.
@@ -476,7 +497,8 @@ bool NewFSParser::WriteCatalog(_Input _Output NewCatalog* catalog, voidPtr data,
if (forkData->Flags != kNewFSFlagUnallocated &&
forkData->Flags != kNewFSFlagDeleted &&
- StringBuilder::Equals(forkData->ForkName, forkName)) {
+ StringBuilder::Equals(forkData->ForkName, forkName) &&
+ StringBuilder::Equals(forkData->CatalogName, catalog->Name)) {
drive->fPacket.fPacketContent = data;
drive->fPacket.fPacketSize = sizeOfData;
drive->fPacket.fLba = forkData->DataOffset;
@@ -621,7 +643,7 @@ Boolean NewFSParser::RemoveCatalog(_Input const Char* catalogName) {
drive->fOutput(&drive->fPacket); // send packet.
- Char partitonBlockBuf[sizeof(NewPartitionBlock)] = { 0 };
+ Char partitonBlockBuf[sizeof(NewPartitionBlock)] = {0};
drive->fPacket.fLba = kNewFSAddressAsLba;
drive->fPacket.fPacketContent = partitonBlockBuf;
@@ -629,7 +651,8 @@ Boolean NewFSParser::RemoveCatalog(_Input const Char* catalogName) {
drive->fInput(&drive->fPacket);
- NewPartitionBlock* partBlock = reinterpret_cast<NewPartitionBlock*>(partitonBlockBuf);
+ NewPartitionBlock* partBlock =
+ reinterpret_cast<NewPartitionBlock*>(partitonBlockBuf);
++partBlock->FreeCatalog;
--partBlock->CatalogCount;
@@ -694,7 +717,8 @@ VoidPtr NewFSParser::ReadCatalog(_Input _Output NewCatalog* catalog,
return nullptr;
}
- if (StringBuilder::Equals(forkName, forkData->ForkName)) break;
+ if (StringBuilder::Equals(forkName, forkData->ForkName) &&
+ StringBuilder::Equals(catalog->Name, forkData->CatalogName)) break;
dataForkLba = forkData->NextSibling;
}
diff --git a/Private/Source/ProcessScheduler.cxx b/Private/Source/ProcessScheduler.cxx
index a21e7dd4..5ac253cb 100644
--- a/Private/Source/ProcessScheduler.cxx
+++ b/Private/Source/ProcessScheduler.cxx
@@ -6,7 +6,7 @@
/***********************************************************************************/
/// @file ProcessScheduler.cxx
-/// @brief Process scheduler.
+/// @brief MicroKernel process scheduler.
/***********************************************************************************/
#include <KernelKit/ProcessScheduler.hpp>
@@ -15,7 +15,7 @@
#include <NewKit/String.hpp>
#include <KernelKit/HError.hpp>
-///! bugs = 0
+///! BUGS: 0
/***********************************************************************************/
/* This file handles the process scheduling.
@@ -23,14 +23,14 @@
namespace NewOS {
/***********************************************************************************/
-/// Exit Code stuff
+/// @brief Exit Code global
/***********************************************************************************/
-STATIC Int32 kExitCode = 0U;
+STATIC Int32 kLastExitCode = 0U;
/// @brief Gets the latest exit code.
/// @note Not thread-safe.
-const Int32 &rt_get_exit_code() noexcept { return kExitCode; }
+const Int32 &rt_get_exit_code() noexcept { return kLastExitCode; }
/***********************************************************************************/
@@ -133,7 +133,7 @@ void ProcessHeader::Exit(Int32 exit_code) {
ProcessScheduler::Shared().Leak().GetCurrent().Leak().Ring > 0)
ke_stop(RUNTIME_CHECK_PROCESS);
- kExitCode = exit_code;
+ kLastExitCode = exit_code;
if (this->Ring != (Int32)ProcessSelector::kRingDriver) {
if (this->HeapPtr) rt_free_heap(this->HeapPtr);