summaryrefslogtreecommitdiffhomepage
path: root/dev/Kernel/src
diff options
context:
space:
mode:
authorAmlal <amlal.elmahrouss@icloud.com>2025-01-17 21:53:27 +0100
committerAmlal <amlal.elmahrouss@icloud.com>2025-01-17 21:53:27 +0100
commit595a52436c86b4cdc37f26d9562cd55ccdb1a4ec (patch)
tree55797470d1cf124a89ea08a84a63d51c2543d96e /dev/Kernel/src
parent3ef6ff432581766cf16223ed2492a8bd20f2d836 (diff)
META: Tweaks and patches applied to mostly the kernel.
Signed-off-by: Amlal <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/Kernel/src')
-rw-r--r--dev/Kernel/src/DriveMgr.cc60
-rw-r--r--dev/Kernel/src/FS/NeFS.cc58
2 files changed, 36 insertions, 82 deletions
diff --git a/dev/Kernel/src/DriveMgr.cc b/dev/Kernel/src/DriveMgr.cc
index 09702351..cccfebfe 100644
--- a/dev/Kernel/src/DriveMgr.cc
+++ b/dev/Kernel/src/DriveMgr.cc
@@ -29,30 +29,15 @@ namespace Kernel
/// @return
Void io_drv_input(DriveTrait::DrivePacket* pckt)
{
- if (!pckt || !pckt->fPacketDrive)
+ if (!pckt)
{
return;
}
- if (!StringBuilder::Equals("fs/detect-packet", pckt->fPacketMime) &&
- pckt->fPacketDrive->fLbaStart > 0 && pckt->fPacketDrive->fLbaEnd > 0)
- {
- if (pckt->fPacketLba > pckt->fPacketDrive->fLbaEnd)
- {
- pckt->fPacketGood = NO;
- return;
- }
- else if (pckt->fPacketLba < pckt->fPacketDrive->fLbaStart)
- {
- pckt->fPacketGood = NO;
- return;
- }
- }
-
#ifdef __AHCI__
- drv_std_read(pckt->fPacketLba, (Char*)pckt->fPacketContent, pckt->fPacketDrive->fSectorSz, pckt->fPacketSize);
+ drv_std_read(pckt->fPacketLba, (Char*)pckt->fPacketContent, pckt->fSectorSz, pckt->fPacketSize);
#elif defined(__ATA_PIO__) || defined(__ATA_DMA__)
- drv_std_read(pckt->fPacketLba, kATAIO, kATAMaster, (Char*)pckt->fPacketContent, pckt->fPacketDrive->fSectorSz, pckt->fPacketSize);
+ drv_std_read(pckt->fPacketLba, kATAIO, kATAMaster, (Char*)pckt->fPacketContent, pckt->fSectorSz, pckt->fPacketSize);
#endif
}
@@ -61,7 +46,7 @@ namespace Kernel
/// @return
Void io_drv_output(DriveTrait::DrivePacket* pckt)
{
- if (!pckt || !pckt->fPacketDrive)
+ if (!pckt)
{
return;
}
@@ -72,25 +57,10 @@ namespace Kernel
return;
}
- if (!StringBuilder::Equals("fs/detect-packet", pckt->fPacketMime) &&
- pckt->fPacketDrive->fLbaStart > 0 && pckt->fPacketDrive->fLbaEnd > 0)
- {
- if (pckt->fPacketLba > pckt->fPacketDrive->fLbaEnd)
- {
- pckt->fPacketGood = NO;
- return;
- }
- else if (pckt->fPacketLba < pckt->fPacketDrive->fLbaStart)
- {
- pckt->fPacketGood = NO;
- return;
- }
- }
-
#ifdef __AHCI__
- drv_std_write(pckt->fPacketLba, (Char*)pckt->fPacketContent, pckt->fPacketDrive->fSectorSz, pckt->fPacketSize);
+ drv_std_write(pckt->fPacketLba, (Char*)pckt->fPacketContent, pckt->fSectorSz, pckt->fPacketSize);
#elif defined(__ATA_PIO__) || defined(__ATA_DMA__)
- drv_std_write(pckt->fPacketLba, kATAIO, kATAMaster, (Char*)pckt->fPacketContent, pckt->fPacketDrive->fSectorSz, pckt->fPacketSize);
+ drv_std_write(pckt->fPacketLba, kATAIO, kATAMaster, (Char*)pckt->fPacketContent, pckt->fSectorSz, pckt->fPacketSize);
#endif
}
@@ -104,7 +74,7 @@ namespace Kernel
return;
}
-#if defined( __ATA_PIO__ ) || defined( __ATA_DMA__ )
+#if defined(__ATA_PIO__) || defined(__ATA_DMA__)
kATAMaster = 0;
kATAIO = 0;
#endif
@@ -168,7 +138,6 @@ namespace Kernel
/// @brief Unimplemented drive function.
/// @param pckt the packet to read.
- /// @return
Void io_drv_unimplemented(DriveTrait::DrivePacket* pckt) noexcept
{
ZKA_UNUSED(pckt);
@@ -200,15 +169,6 @@ namespace Kernel
{
EPM_PART_BLOCK block_struct;
- trait.fPacket.fPacketDrive = &trait;
-
-#ifdef __ATA_PIO__
- trait.fSectorSz = kATASectorSize;
-#elif defined(__AHCI__)
- trait.fSectorSz = kAHCISectorSize;
-#else
- trait.fSectorSz = 512;
-#endif
trait.fPacket.fPacketLba = kEPMBootBlockLba;
trait.fPacket.fPacketSize = sizeof(EPM_PART_BLOCK);
trait.fPacket.fPacketContent = &block_struct;
@@ -227,11 +187,11 @@ namespace Kernel
kcout << "Formatted Disk is EPM (Mass Storage)\r";
- trait.fSectorSz = block_struct.SectorSz;
+ trait.fPacket.fSectorSz = block_struct.SectorSz;
trait.fLbaEnd = block_struct.LbaEnd;
trait.fLbaStart = block_struct.LbaStart;
- if (trait.fSectorSz == 0)
+ if (trait.fPacket.fSectorSz == 0)
{
ke_panic(RUNTIME_CHECK_FAILED, "Invalid EPM partition!");
}
@@ -244,7 +204,7 @@ namespace Kernel
kcout << "Scheme Found: " << block_struct.Name << endl;
if (block_struct.Name[0] == 0)
- kcout << "Disk partition is unknown (Read Only)\r";
+ kcout << "Disk partition is empty (Read Only)\r";
}
rt_copy_memory((VoidPtr) "*/*", trait.fPacket.fPacketMime,
diff --git a/dev/Kernel/src/FS/NeFS.cc b/dev/Kernel/src/FS/NeFS.cc
index 0dad44f8..531c852e 100644
--- a/dev/Kernel/src/FS/NeFS.cc
+++ b/dev/Kernel/src/FS/NeFS.cc
@@ -60,45 +60,41 @@ STATIC MountpointInterface kMountpoint;
/// @param the_fork the fork itself.
/// @return the fork
/***********************************************************************************/
-_Output BOOL NeFileSystemParser::CreateFork(_Input NFS_CATALOG_STRUCT* catalog,
- _Input NFS_FORK_STRUCT& the_fork)
+_Output BOOL NeFileSystemParser::CreateFork(_Input NFS_FORK_STRUCT& the_fork)
{
- if (catalog && the_fork.ForkName[0] != 0 &&
- the_fork.DataSize > 0)
+ if (the_fork.ForkName[0] != 0 &&
+ the_fork.CatalogName[0] != 0 &&
+ the_fork.DataSize > 0)
{
- Lba lba = (the_fork.Kind == kNeFSDataForkKind) ? catalog->DataFork
- : catalog->ResourceFork;
+ auto catalog = this->GetCatalog(the_fork.CatalogName);
- kcout << "Fork lba: " << hex_number(lba) << endl;
+ if (!catalog)
+ return NO;
+
+ Lba lba = catalog->DataFork;
+
+ kcout << "Fork LBA: " << hex_number(lba) << endl;
if (lba < kNeFSCatalogStartAddress)
return NO;
auto drv = kMountpoint.A();
- /// special treatment.
- rt_copy_memory((VoidPtr) "fs/nefs-packet", drv.fPacket.fPacketMime,
- rt_string_len("fs/nefs-packet"));
-
- NFS_FORK_STRUCT curFork{0};
- NFS_FORK_STRUCT prevFork{0};
Lba lbaOfPreviousFork = lba;
+ NFS_FORK_STRUCT prevFork;
+
/// do not check for anything. Loop until we get what we want, that is a free fork zone.
- while (YES)
+ while (drv.fPacket.fPacketGood)
{
- drv.fPacket.fPacketLba = lba;
+ NFS_FORK_STRUCT curFork;
+
+ drv.fPacket.fPacketLba = lba;
drv.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT);
drv.fPacket.fPacketContent = &curFork;
drv.fInput(&drv.fPacket);
- if (curFork.NextSibling > kBadAddress)
- {
- kcout << "Bad fork: " << hex_number(curFork.NextSibling) << endl;
- return NO;
- }
-
kcout << "Next fork: " << hex_number(curFork.NextSibling) << endl;
if (curFork.Flags & kNeFSFlagCreated)
@@ -107,8 +103,8 @@ _Output BOOL NeFileSystemParser::CreateFork(_Input NFS_CATALOG_STRUCT* catalog,
/// sanity check.
if (StringBuilder::Equals(curFork.ForkName, the_fork.ForkName) &&
- StringBuilder::Equals(curFork.CatalogName, catalog->Name))
- return NO;
+ StringBuilder::Equals(curFork.CatalogName, the_fork.CatalogName))
+ break;
kcout << "Next fork: " << hex_number(curFork.NextSibling) << endl;
@@ -137,18 +133,17 @@ _Output BOOL NeFileSystemParser::CreateFork(_Input NFS_CATALOG_STRUCT* catalog,
}
}
- constexpr auto kForkPadding =
- 4; /// this value gives us space for the data offset.
-
the_fork.Flags |= kNeFSFlagCreated;
the_fork.DataOffset = lba - sizeof(NFS_FORK_STRUCT);
the_fork.PreviousSibling = lbaOfPreviousFork;
- the_fork.NextSibling = (the_fork.DataOffset - the_fork.DataSize - sizeof(NFS_FORK_STRUCT)) * kForkPadding;
+ the_fork.NextSibling = (the_fork.DataOffset - the_fork.DataSize - sizeof(NFS_FORK_STRUCT));
drv.fPacket.fPacketLba = lba;
drv.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT);
drv.fPacket.fPacketContent = &the_fork;
+ kcout << "Writing fork...\r";
+
drv.fOutput(&drv.fPacket);
/// log what we have now.
@@ -170,8 +165,8 @@ _Output BOOL NeFileSystemParser::CreateFork(_Input NFS_CATALOG_STRUCT* catalog,
/// @return the fork.
/***********************************************************************************/
_Output NFS_FORK_STRUCT* NeFileSystemParser::FindFork(_Input NFS_CATALOG_STRUCT* catalog,
- _Input const Char* name,
- Boolean isDataFork)
+ _Input const Char* name,
+ Boolean isDataFork)
{
auto drive = kMountpoint.A();
NFS_FORK_STRUCT* the_fork = nullptr;
@@ -236,7 +231,7 @@ _Output NFS_CATALOG_STRUCT* NeFileSystemParser::CreateCatalog(_Input const Char*
/// @param kind the catalog kind.
/// @return catalog pointer.
/***********************************************************************************/
-_Output NFS_CATALOG_STRUCT* NeFileSystemParser::CreateCatalog(_Input const Char* name,
+_Output NFS_CATALOG_STRUCT* NeFileSystemParser::CreateCatalog(_Input const Char* name,
_Input const Int32& flags,
_Input const Int32& kind)
{
@@ -939,7 +934,7 @@ Boolean NeFileSystemParser::RemoveCatalog(_Input const Char* catalog_name)
VoidPtr NeFileSystemParser::ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog,
_Input Bool is_rsrc_fork,
_Input SizeT dataSz,
- _Input const Char* forkName)
+ _Input const Char* forkName)
{
if (!catalog)
{
@@ -1037,7 +1032,6 @@ namespace Kernel::NeFS
kcout << "Creating A:\r";
kMountpoint.A() = io_construct_main_drive();
- kMountpoint.A().fPacket.fPacketDrive = &kMountpoint.A();
kcout << "Creating A: [ OK ]\r";