summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-05-01 07:22:14 +0200
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-05-01 07:22:14 +0200
commit56d756fe73e9c206b333276f0cde1c1dc13999c2 (patch)
treeb5e16ad794a95a5c007aad8a613cab0e02399fee
parent39252db4317b2e53eee59217ca7bb42a0b531443 (diff)
kernel: Fixes and improvements.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
-rw-r--r--Private/Builtins/AHCI/AHCI.hxx5
-rw-r--r--Private/Builtins/ATA/ATA.hxx4
-rw-r--r--Private/FSKit/NewFS.hxx56
-rw-r--r--Private/Source/AppMain.cxx47
-rw-r--r--Private/Source/FS/NewFS.cxx33
5 files changed, 90 insertions, 55 deletions
diff --git a/Private/Builtins/AHCI/AHCI.hxx b/Private/Builtins/AHCI/AHCI.hxx
index b79299e7..6a21dbfd 100644
--- a/Private/Builtins/AHCI/AHCI.hxx
+++ b/Private/Builtins/AHCI/AHCI.hxx
@@ -347,5 +347,10 @@ NewOS::SizeT drv_std_get_sector_count();
/// @brief get device size.
NewOS::SizeT drv_std_get_drv_size();
+/// @brief get sector count.
+NewOS::SizeT drv_std_get_sector_count();
+
+/// @brief get device size.
+NewOS::SizeT drv_std_get_drv_size();
#endif // ifdef __KERNEL__
diff --git a/Private/Builtins/ATA/ATA.hxx b/Private/Builtins/ATA/ATA.hxx
index ed9d275a..b9c0a9f7 100644
--- a/Private/Builtins/ATA/ATA.hxx
+++ b/Private/Builtins/ATA/ATA.hxx
@@ -148,9 +148,11 @@ NewOS::Void drv_std_read(NewOS::UInt64 Lba, NewOS::UInt16 IO, NewOS::UInt8 Maste
NewOS::Void drv_std_write(NewOS::UInt64 Lba, NewOS::UInt16 IO, NewOS::UInt8 Master, NewOS::Char* Buf,
NewOS::SizeT SectorSz, NewOS::SizeT Size);
+/// @brief get sector count.
NewOS::SizeT drv_std_get_sector_count();
+/// @brief get device size.
NewOS::SizeT drv_std_get_drv_size();
#endif // ifdef __KERNEL__
-#endif // ifndef __AHCI__
+#endif // ifndef __ATA_PIO__ || __AHCI__
diff --git a/Private/FSKit/NewFS.hxx b/Private/FSKit/NewFS.hxx
index b099a2c4..3867c765 100644
--- a/Private/FSKit/NewFS.hxx
+++ b/Private/FSKit/NewFS.hxx
@@ -26,47 +26,47 @@ default.
@author Amlal EL Mahrouss
*/
-#define kNewFSInvalidFork -1
-#define kNewFSInvalidCatalog -1
-#define kNewFSNodeNameLen 256
+#define kNewFSInvalidFork (-1)
+#define kNewFSInvalidCatalog (-1)
+#define kNewFSNodeNameLen (256)
#define kNewFSSectorSz (512)
-#define kNewFSIdentLen 8
+#define kNewFSIdentLen (8)
#define kNewFSIdent " NewFS"
-#define kNewFSPadLen 400
+#define kNewFSPadLen (400)
/// @brief Partition GUID on EPM and GPT disks.
#define kNewFSUUID "@{DD997393-9CCE-4288-A8D5-C0FDE3908DBE}"
-#define kNewFSVersionInteger 0x125
+#define kNewFSVersionInteger (0x125)
#define kNewFSVerionString "1.25"
/// @brief Standard fork types.
#define kNewFSDataFork "data"
#define kNewFSResourceFork "rsrc"
-#define kNewFSCatalogKindFile 1
-#define kNewFSCatalogKindDir 2
-#define kNewFSCatalogKindAlias 3
+#define kNewFSCatalogKindFile (1)
+#define kNewFSCatalogKindDir (2)
+#define kNewFSCatalogKindAlias (3)
#define kNewFSForkSize (8192)
//! shared between network or
//! other filesystems. Export forks as .zip when copying.
-#define kNewFSCatalogKindShared 4
+#define kNewFSCatalogKindShared (4)
-#define kNewFSCatalogKindResource 5
-#define kNewFSCatalogKindExecutable 6
+#define kNewFSCatalogKindResource (5)
+#define kNewFSCatalogKindExecutable (6)
-#define kNewFSCatalogKindPage 8
+#define kNewFSCatalogKindPage (8)
-#define kNewFSPartitionTypeStandard 7
-#define kNewFSPartitionTypePage 8
-#define kNewFSPartitionTypeBoot 9
+#define kNewFSPartitionTypeStandard (7)
+#define kNewFSPartitionTypePage (8)
+#define kNewFSPartitionTypeBoot (9)
-#define kNewFSCatalogKindDevice 9
-#define kNewFSCatalogKindLock 10
+#define kNewFSCatalogKindDevice (9)
+#define kNewFSCatalogKindLock (10)
#define kNewFSSeparator '/'
@@ -83,19 +83,21 @@ default.
#define kNewFSAddressAsLba (512)
#define kNewFSCatalogStartAddress (1024 + sizeof(NewPartitionBlock) + sizeof(NewCatalog))
-#define kResourceTypeDialog 10
-#define kResourceTypeString 11
-#define kResourceTypeMenu 12
+#define kResourceTypeDialog (10)
+#define kResourceTypeString (11)
+#define kResourceTypeMenu (12)
-#define kConfigLen 64
-#define kPartLen 32
+#define kConfigLen (64)
+#define kPartLen (32)
-#define kNewFSFlagDeleted 70
-#define kNewFSFlagUnallocated 00
-#define kNewFSFlagCreated 71
+#define kNewFSFlagDeleted (70)
+#define kNewFSFlagUnallocated (0)
+#define kNewFSFlagCreated (71)
#define kNewFSMimeNameLen (200)
+#define kNewFSForkNameLen (200U)
+
typedef NewOS::Char NewCharType;
enum {
@@ -132,8 +134,6 @@ struct PACKED NewCatalog final {
NewOS::Lba PrevSibling;
};
-#define kNewFSForkNameLen (200U)
-
/// @brief Fork type, contains a data page.
/// @note The way we store is way different than how other filesystems do, specific chunk of code are
/// written into either the data fork or resource fork, the resource fork is reserved for file metadata.
diff --git a/Private/Source/AppMain.cxx b/Private/Source/AppMain.cxx
index 6dc2a3ff..c113958a 100644
--- a/Private/Source/AppMain.cxx
+++ b/Private/Source/AppMain.cxx
@@ -40,16 +40,6 @@ class FilesystemAutomountProvider final {
NewOS::FilesystemManagerInterface::Mount(fNewFS);
- constexpr auto sanitizerSize = 512;
-
- /// Sample AMD64 program,
- /// mov rax, 0x0
- /// ret
- /// @note there was a 0xc1 before, to delimit the program, but I removed
- /// it. We don't need that now.
- NewOS::UInt8 sanitizerBytes[sanitizerSize] = {
- "\x48\xC7\xC0\x00\x00\x00\x00\xC3"};
-
if (fNewFS->GetImpl()) {
NewCatalog* sanitizerCatalog = nullptr;
@@ -62,7 +52,44 @@ class FilesystemAutomountProvider final {
kNewFSCatalogKindDir);
delete fNewFS->GetImpl()->CreateCatalog("/Applications/", 0,
kNewFSCatalogKindDir);
+
+ NewFork theFork{0};
+
+ const NewOS::Char* cSrcName = "FolderInfo";
+
+ NewOS::rt_copy_memory((NewOS::VoidPtr)(cSrcName),
+ theFork.ForkName,
+ NewOS::rt_string_len(cSrcName));
+
+ 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/");
+
+ fNewFS->GetImpl()->CreateFork(catalogSystem, theFork);
+
+ fNewFS->GetImpl()->WriteCatalog(catalogSystem,
+ (NewOS::VoidPtr)(metadataFolder),
+ metadataSz, "FolderInfo");
+
+ delete catalogSystem;
+
+ catalogSystem = fNewFS->GetImpl()->GetCatalog("/Support/");
+
+ fNewFS->GetImpl()->CreateFork(catalogSystem, theFork);
+
+ fNewFS->GetImpl()->WriteCatalog(catalogSystem,
+ (NewOS::VoidPtr)(metadataFolder),
+ metadataSz, "FolderInfo");
}
+
+ NewOS::kcout << (NewOS::Char*)fNewFS->GetImpl()->ReadCatalog(fNewFS->GetImpl()->GetCatalog("/System/"), 512, "FolderInfo");
}
}
}
diff --git a/Private/Source/FS/NewFS.cxx b/Private/Source/FS/NewFS.cxx
index d3d75fb2..9074b348 100644
--- a/Private/Source/FS/NewFS.cxx
+++ b/Private/Source/FS/NewFS.cxx
@@ -31,7 +31,7 @@ _Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog,
Lba lba = (theFork.Kind == kNewFSDataForkKind) ? catalog->DataFork
: catalog->ResourceFork;
- kcout << "Data-Fork-Lba: " << hex_number(lba) << endl;
+ kcout << "Fork-Lba: " << hex_number(lba) << endl;
if (lba <= kNewFSCatalogStartAddress) return nullptr;
@@ -41,29 +41,29 @@ _Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog,
rt_copy_memory((VoidPtr) "fs/newfs-packet", drv->fPacket.fPacketMime,
rt_string_len("fs/newfs-packet"));
- NewFork cpyFork{0};
+ NewFork curFork{0};
NewFork prevFork{0};
Lba lbaOfPreviousFork = lba;
- while (cpyFork.ForkName[0] == 0) {
+ while (curFork.ForkName[0] == 0) {
if (lba <= kNewFSCatalogStartAddress) break;
drv->fPacket.fLba = lba;
drv->fPacket.fPacketSize = sizeof(NewFork);
- drv->fPacket.fPacketContent = &cpyFork;
+ drv->fPacket.fPacketContent = &curFork;
drv->fInput(&drv->fPacket);
- kcout << "New OS: Next-Fork: " << hex_number(cpyFork.NextSibling) << endl;
+ kcout << "New OS: Next-Fork: " << hex_number(curFork.NextSibling) << endl;
- if (cpyFork.Flags == kNewFSFlagCreated) {
+ if (curFork.Flags == kNewFSFlagCreated) {
kcout << "New OS: Fork already exists.\r";
- if (StringBuilder::Equals(cpyFork.ForkName, theFork.ForkName)) return nullptr;
+ if (StringBuilder::Equals(curFork.ForkName, theFork.ForkName)) return nullptr;
lbaOfPreviousFork = lba;
- lba = cpyFork.NextSibling;
+ lba = curFork.NextSibling;
- prevFork = cpyFork;
+ prevFork = curFork;
} else {
/// This is a check that we have, in order to link the previous fork
/// entry.
@@ -153,16 +153,16 @@ _Output NewFork* NewFSParser::FindFork(_Input NewCatalog* catalog,
/// @brief Simpler factory to create a catalog (assumes you want to create a
/// file.)
/// @param name
-/// @return
+/// @return catalog pointer.
_Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name) {
return this->CreateCatalog(name, 0, kNewFSCatalogKindFile);
}
-/// @brief
-/// @param name
-/// @param flags
-/// @param kind
-/// @return
+/// @brief Creates a new catalog into the disk.
+/// @param name the catalog name.
+/// @param flags the flags of the catalog.
+/// @param kind the catalog kind.
+/// @return catalog pointer.
_Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name,
_Input const Int32& flags,
_Input const Int32& kind) {
@@ -208,7 +208,7 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name,
// mandatory / character.
parentName[--indexReverseCopy] = 0;
- while (parentName[indexReverseCopy] != '/') {
+ while (parentName[indexReverseCopy] != NewFilesystemHelper::Separator()) {
parentName[indexReverseCopy] = 0;
--indexReverseCopy;
}
@@ -323,6 +323,7 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name,
partBlock->SectorCount -= 1;
partBlock->CatalogCount += 1;
partBlock->FreeCatalog -= 1;
+ partBlock->FreeCatalog = catalogChild->NextSibling;
drive->fOutput(&drive->fPacket);