summaryrefslogtreecommitdiffhomepage
path: root/Private/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Private/Source')
-rw-r--r--Private/Source/AppMain.cxx (renamed from Private/Source/RuntimeMain.cxx)7
-rw-r--r--Private/Source/CxxAbi.cxx2
-rw-r--r--Private/Source/FS/NewFS.cxx251
-rw-r--r--Private/Source/IndexableProperty.cxx2
-rw-r--r--Private/Source/KernelHeap.cxx4
-rw-r--r--Private/Source/PEFCodeManager.cxx15
-rw-r--r--Private/Source/ThreadLocalStorage.cxx6
-rw-r--r--Private/Source/URL.cxx5
8 files changed, 230 insertions, 62 deletions
diff --git a/Private/Source/RuntimeMain.cxx b/Private/Source/AppMain.cxx
index 5bbee3b2..87705393 100644
--- a/Private/Source/RuntimeMain.cxx
+++ b/Private/Source/AppMain.cxx
@@ -5,7 +5,6 @@
------------------------------------------- */
#include <ArchKit/ArchKit.hpp>
-#include <Builtins/Toolbox/Rsrc/Splash.rsrc>
#include <Builtins/Toolbox/Toolbox.hxx>
#include <FirmwareKit/Handover.hxx>
#include <KernelKit/FileManager.hpp>
@@ -18,15 +17,15 @@
/// @file Main microkernel entrypoint.
-EXTERN_C void RuntimeMain(void) {
+EXTERN_C NewOS::Void AppMain(NewOS::Void) {
///! Mounts a NewFS block.
NewOS::NewFilesystemManager* newFS = new NewOS::NewFilesystemManager();
NewOS::ke_protect_ke_heap(newFS);
NewOS::FilesystemManagerInterface::Mount(newFS);
-
+
while (NewOS::ProcessScheduler::Shared().Leak().Run() > 0);
///! we're done, unmount.
delete newFS;
-} \ No newline at end of file
+}
diff --git a/Private/Source/CxxAbi.cxx b/Private/Source/CxxAbi.cxx
index d79d688c..452c4383 100644
--- a/Private/Source/CxxAbi.cxx
+++ b/Private/Source/CxxAbi.cxx
@@ -13,7 +13,7 @@ atexit_func_entry_t __atexit_funcs[kDSOMaxObjects];
uarch_t __atexit_func_count;
extern "C" void __cxa_pure_virtual() {
- NewOS::kcout << "NewOS: C++ placeholder method.\n";
+ NewOS::kcout << "New OS: C++ placeholder method.\n";
}
extern "C" void ___chkstk_ms() {
diff --git a/Private/Source/FS/NewFS.cxx b/Private/Source/FS/NewFS.cxx
index 1d7d3621..7eb79d10 100644
--- a/Private/Source/FS/NewFS.cxx
+++ b/Private/Source/FS/NewFS.cxx
@@ -7,13 +7,16 @@
#ifdef __FSKIT_NEWFS__
#include <FSKit/NewFS.hxx>
+#include <KernelKit/HError.hpp>
+#include <NewKit/Crc32.hpp>
#include <NewKit/Utils.hpp>
using namespace NewOS;
-STATIC Lba ke_find_free_fork(SizeT sz);
-STATIC Lba ke_find_free_catalog(SizeT sz);
-STATIC Lba ke_find_free_data(SizeT sz);
+/// forward decl.
+
+STATIC Lba ke_find_free_fork(SizeT sz, Int32 drv, NewCatalog* catalog);
+STATIC Lba ke_find_free_catalog(SizeT kind, Int32 drv);
STATIC MountpointInterface sMountpointInterface;
@@ -26,7 +29,8 @@ _Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog,
if (catalog && theFork.Name[0] != 0 && theFork.DataSize > 0) {
Lba whereFork = 0;
- theFork.DataOffset = ke_find_free_fork(theFork.DataSize);
+ theFork.DataOffset =
+ ke_find_free_fork(theFork.DataSize, this->fDriveIndex, catalog);
theFork.Flags |= kNewFSFlagCreated;
if (catalog->FirstFork == 0) {
@@ -161,7 +165,55 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive) {
return false;
}
- return true;
+ Char sectorBuf[kNewFSMinimumSectorSz] = {0};
+
+ drive->fPacket.fPacketContent = sectorBuf;
+ drive->fPacket.fPacketSize = kNewFSMinimumSectorSz;
+ drive->fPacket.fLba = kNewFSAddressAsLba;
+
+ drive->fInput(&drive->fPacket);
+
+ /// disk isnt faulty and data has been fetched.
+ if (drive->fPacket.fPacketGood) {
+ NewPartitionBlock* partBlock = (NewPartitionBlock*)sectorBuf;
+
+ /// check for an empty partition here.
+ if (partBlock->PartitionName[0] == 0 &&
+ rt_string_cmp(partBlock->Ident, kNewFSIdent, kNewFSIdentLen)) {
+ /// partition is free and valid.
+
+ rt_copy_memory((VoidPtr)kNewFSIdent, (VoidPtr)partBlock->Ident,
+ kNewFSIdentLen);
+ rt_copy_memory((VoidPtr) "New OS\0", (VoidPtr)partBlock->PartitionName,
+ rt_string_len("New OS\0"));
+
+ SizeT catalogCount = 0;
+ SizeT sectorCount = 0;
+ SizeT diskSize = 0;
+
+ partBlock->Kind = kNewFSPartitionTypeStandard;
+ partBlock->StartCatalog = sizeof(NewPartitionBlock) + kNewFSAddressAsLba;
+ partBlock->CatalogCount = catalogCount;
+ partBlock->SectorCount = sectorCount;
+ partBlock->DiskSize = diskSize;
+ partBlock->FreeCatalog = partBlock->StartCatalog;
+
+ drive->fPacket.fPacketContent = sectorBuf;
+ drive->fPacket.fPacketSize = kNewFSMinimumSectorSz;
+ drive->fPacket.fLba = kNewFSAddressAsLba;
+
+ drive->fOutput(&drive->fPacket);
+
+ return true;
+ }
+
+ kcout << "New OS: Partition already exists.\r\n";
+
+ /// return success as well, do not ignore that partition.
+ return true;
+ }
+
+ return false;
}
/// @brief
@@ -173,73 +225,186 @@ bool NewFSParser::WriteCatalog(_Input _Output NewCatalog* catalog,
return false;
}
-/// @brief
-/// @param catalogName
-/// @return
+/// @brief
+/// @param catalogName
+/// @return
_Output NewCatalog* NewFSParser::FindCatalog(_Input const char* catalogName) {
return nullptr;
}
-/// @brief
-/// @param name
-/// @return
+/// @brief
+/// @param name
+/// @return
_Output NewCatalog* NewFSParser::GetCatalog(_Input const char* name) {
return nullptr;
}
-/// @brief
-/// @param catalog
-/// @return
+/// @brief
+/// @param catalog
+/// @return
Boolean NewFSParser::CloseCatalog(_Input _Output NewCatalog* catalog) {
- return false;
+ return true;
}
-/// @brief
-/// @param catalog
-/// @return
+/// @brief Mark catalog as removed.
+/// @param catalog The catalog structure.
+/// @return
Boolean NewFSParser::RemoveCatalog(_Input _Output NewCatalog* catalog) {
+ catalog->Flags |= kNewFSFlagDeleted;
+ this->WriteCatalog(catalog, nullptr);
+
return false;
}
-/// @brief
-/// @param catalog
-/// @param dataSz
-/// @return
+/// ***************************************************************** ///
+/// Reading,Seek,Tell are unimplemented on catalogs, refer to forks I/O instead.
+/// ***************************************************************** ///
+
+/// @brief
+/// @param catalog
+/// @param dataSz
+/// @return
VoidPtr NewFSParser::ReadCatalog(_Input _Output NewCatalog* catalog,
SizeT dataSz) {
return nullptr;
}
-/// @brief
-/// @param catalog
-/// @param off
-/// @return
+/// @brief
+/// @param catalog
+/// @param off
+/// @return
bool NewFSParser::Seek(_Input _Output NewCatalog* catalog, SizeT off) {
return false;
}
-/// @brief
-/// @param catalog
-/// @return
+/// @brief
+/// @param catalog
+/// @return
SizeT NewFSParser::Tell(_Input _Output NewCatalog* catalog) { return 0; }
-/// @brief
-/// @param sz
-/// @return
-STATIC Lba ke_find_free_fork(SizeT sz) { return 0; }
+/// @brief Find a free fork inside the filesystem.
+/// @param sz the size of the fork to set.
+/// @return the valid lba.
+STATIC Lba ke_find_free_fork(SizeT sz, Int32 drv, NewCatalog* catalog) {
+ auto drive = *sMountpointInterface.GetAddressOf(drv);
-/// @brief
-/// @param sz
-/// @return
-STATIC Lba ke_find_free_catalog(SizeT sz) { return 0; }
+ if (drive) {
+ /// prepare packet.
+ bool done = false;
+ bool error = false;
-/// @brief
-/// @param sz
-/// @return
-STATIC Lba ke_find_free_data(SizeT sz) { return 0; }
+ Lba lba = catalog->LastFork;
+
+ while (!done) {
+ Char sectorBuf[kNewFSMinimumSectorSz] = {0};
+
+ drive->fPacket.fPacketContent = sectorBuf;
+ drive->fPacket.fPacketSize = kNewFSMinimumSectorSz;
+ drive->fPacket.fLba = lba;
+
+ drive->fInput(&drive->fPacket);
+
+ if (!drive->fPacket.fPacketGood) {
+ ///! not a lot of choices, disk has become unreliable.
+ if (ke_calculate_crc32(sectorBuf, kNewFSMinimumSectorSz) !=
+ drive->fPacket.fPacketCRC32) {
+ DbgLastError() = kErrorDiskIsCorrupted;
+ }
+
+ error = true;
+ break;
+ }
+
+ NewFork* fork = (NewFork*)sectorBuf;
+
+ if (fork->DataSize == 0 && fork->Name[0] == 0 &&
+ (fork->Flags == kNewFSFlagDeleted ||
+ fork->Flags == kNewFSFlagUnallocated)) {
+ fork->DataSize = sz;
+ fork->Flags |= kNewFSFlagCreated;
+
+ drive->fOutput(&drive->fPacket);
+
+ /// here it's either a read-only filesystem or something bad happened.'
+ if (!drive->fPacket.fPacketGood) {
+ DbgLastError() = kErrorDiskReadOnly;
+
+ return 0;
+ }
+
+ return lba;
+ }
+
+ lba += sizeof(NewFork);
+ }
+
+ if (error) {
+ DbgLastError() = kErrorDisk;
+ return 0;
+ }
+ }
+
+ return 0;
+}
+
+/// @brief find a free catalog.
+/// @param kind the catalog kind.
+/// @return the valid lba.
+STATIC Lba ke_find_free_catalog(SizeT kind, Int32 drv) {
+ auto drive = *sMountpointInterface.GetAddressOf(drv);
+
+ if (drive) {
+ Char sectorBuf[kNewFSMinimumSectorSz] = {0};
+
+ /// prepare packet.
+
+ drive->fPacket.fPacketContent = sectorBuf;
+ drive->fPacket.fPacketSize = kNewFSMinimumSectorSz;
+ drive->fPacket.fLba = kNewFSAddressAsLba;
+
+ drive->fInput(&drive->fPacket);
+
+ NewPartitionBlock* partBlock = (NewPartitionBlock*)sectorBuf;
+
+ /// check for a valid partition.
+ if (partBlock->PartitionName[0] != 0 &&
+ rt_string_cmp(partBlock->Ident, kNewFSIdent, kNewFSIdentLen) == 0) {
+ auto startLba = partBlock->FreeCatalog;
+
+ if (startLba == 0) {
+ DbgLastError() = kErrorDiskIsFull;
+ return 1;
+ } else {
+ while (startLba != 0) {
+ drive->fPacket.fPacketContent = sectorBuf;
+ drive->fPacket.fPacketSize = kNewFSMinimumSectorSz;
+ drive->fPacket.fLba = startLba;
+
+ drive->fInput(&drive->fPacket);
+
+ NewCatalog* catalog = (NewCatalog*)sectorBuf;
+
+ if (catalog->Flags == kNewFSFlagUnallocated ||
+ catalog->Flags == kNewFSFlagDeleted) {
+ catalog->Flags |= kNewFSFlagCreated;
+ catalog->Kind |= kind;
+
+ return startLba;
+ }
+
+ startLba = catalog->NextSibling;
+ }
+
+ return 0;
+ }
+ }
+ }
+
+ return 0;
+}
namespace NewOS::Detail {
-Boolean fs_init_newfs(Void) noexcept { return false; }
+Boolean fs_init_newfs(Void) noexcept { return true; }
} // namespace NewOS::Detail
-#endif // ifdef __FSKIT_NEWFS__ \ No newline at end of file
+#endif // ifdef __FSKIT_NEWFS__
diff --git a/Private/Source/IndexableProperty.cxx b/Private/Source/IndexableProperty.cxx
index c3978fe9..dba56c74 100644
--- a/Private/Source/IndexableProperty.cxx
+++ b/Private/Source/IndexableProperty.cxx
@@ -34,7 +34,7 @@ Void fs_index_file(const Char* filename, SizeT filenameLen, IndexableProperty& i
indexer.AddFlag(kIndexerClaimed);
rt_copy_memory((VoidPtr)indexer.LeakProperty().Path, (VoidPtr)filename, filenameLen);
- kcout << "NewOS: FSKit: index new file: " << filename << endl;
+ kcout << "New OS: FSKit: index new file: " << filename << endl;
}
}
} // namespace Indexer
diff --git a/Private/Source/KernelHeap.cxx b/Private/Source/KernelHeap.cxx
index 72d291a8..3b77ebb6 100644
--- a/Private/Source/KernelHeap.cxx
+++ b/Private/Source/KernelHeap.cxx
@@ -97,7 +97,7 @@ Int32 ke_delete_ke_heap(VoidPtr heapPtr) {
PTEWrapper pageWrapper(false, false, false, (UIntPtr)virtualAddress);
Ref<PTEWrapper*> pteAddress{ &pageWrapper };
-
+
kHeapPageManager.Free(pteAddress);
--kHeapCount;
@@ -126,7 +126,7 @@ Boolean ke_is_valid_heap(VoidPtr heapPtr) {
return false;
}
-/// @brief Protect the heap pointer with a CRC32.
+/// @brief Protect the heap with a CRC value.
/// @param heapPtr HIB pointer.
/// @return if it valid: point has crc now., otherwise fail.
Boolean ke_protect_ke_heap(VoidPtr heapPtr) {
diff --git a/Private/Source/PEFCodeManager.cxx b/Private/Source/PEFCodeManager.cxx
index f8616a8c..2f60f085 100644
--- a/Private/Source/PEFCodeManager.cxx
+++ b/Private/Source/PEFCodeManager.cxx
@@ -17,6 +17,7 @@
namespace NewOS {
namespace Detail {
+/// @brief Get the PEF platform signature according to the compiled backebnd
UInt32 rt_get_pef_platform(void) noexcept {
#ifdef __32x0__
return kPefArch32x0;
@@ -33,7 +34,7 @@ UInt32 rt_get_pef_platform(void) noexcept {
} // namespace Detail
/// @brief PEF loader constructor w/ blob.
-/// @param blob
+/// @param blob
PEFLoader::PEFLoader(const VoidPtr blob) : fCachedBlob(nullptr) {
fCachedBlob = blob;
fBad = false;
@@ -42,11 +43,11 @@ PEFLoader::PEFLoader(const VoidPtr blob) : fCachedBlob(nullptr) {
}
/// @brief PEF loader constructor.
-/// @param path
-PEFLoader::PEFLoader(const char *path) : fCachedBlob(nullptr), fBad(false) {
- OwnPtr<FileStream<char>> file;
+/// @param path the filesystem path.
+PEFLoader::PEFLoader(const Char* path) : fCachedBlob(nullptr), fBad(false) {
+ OwnPtr<FileStream<Char>> file;
- file.New(const_cast<Char *>(path), kRestrictRB);
+ file.New(const_cast<Char*>(path), kRestrictRB);
if (StringBuilder::Equals(file->MIME(), this->MIME())) {
fPath = StringBuilder::Construct(path).Leak();
@@ -131,7 +132,7 @@ VoidPtr PEFLoader::FindSymbol(const char *name, Int32 kind) {
}
/// @brief Finds the executable entrypoint.
-/// @return
+/// @return
ErrorOr<VoidPtr> PEFLoader::FindStart() {
if (auto sym = this->FindSymbol(kPefStart, kPefCode); sym)
return ErrorOr<VoidPtr>(sym);
@@ -140,7 +141,7 @@ ErrorOr<VoidPtr> PEFLoader::FindStart() {
}
/// @brief Tells if the executable is loaded or not.
-/// @return
+/// @return
bool PEFLoader::IsLoaded() noexcept { return !fBad && fCachedBlob; }
#define kPefAppnameCommandHdr "PefAppName"
diff --git a/Private/Source/ThreadLocalStorage.cxx b/Private/Source/ThreadLocalStorage.cxx
index d3e31a1c..8d3281e3 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 << "NewOS: Checking for a valid cookie...\r\n";
+ kcout << "New OS: Checking for a valid cookie...\r\n";
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 << "NewOS: Verification failed, Crashing...\r\n";
+ kcout << "New OS: Verification failed, Crashing...\r\n";
ProcessScheduler::Shared().Leak().GetCurrent().Leak().Crash();
}
- kcout << "NewOS: Verification succeeded! Keeping on...\r\n";
+ kcout << "New OS: Verification succeeded! Keeping on...\r\n";
}
diff --git a/Private/Source/URL.cxx b/Private/Source/URL.cxx
index 090c7c66..4983a34c 100644
--- a/Private/Source/URL.cxx
+++ b/Private/Source/URL.cxx
@@ -15,12 +15,15 @@ URL::URL(StringView &strUrl) : fUrlView(strUrl, false) {}
URL::~URL() = default;
+/// @brief internal and reserved protocols by kernel.
constexpr const char *kURLProtocols[] = {
"file", // Filesystem protocol
+ "mup", // Mahrouss update protocol
+ "param", // Mahrouss parameter protocol.
};
constexpr const int kUrlOutSz = 1; //! such as: ://
-constexpr const int kProtosCount = 4;
+constexpr const int kProtosCount = 3;
constexpr const int kRangeSz = 4096;
ErrorOr<StringView> url_extract_location(const char *url) {