summaryrefslogtreecommitdiffhomepage
path: root/Private
diff options
context:
space:
mode:
Diffstat (limited to 'Private')
-rw-r--r--Private/Builtins/ATA/ATA.hxx4
-rw-r--r--Private/FSKit/NewFS.hxx6
-rw-r--r--Private/HALKit/AMD64/Storage/ATA-PIO.cxx18
-rw-r--r--Private/NewBoot/BootKit/BootKit.hxx11
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootMain.cxx2
-rw-r--r--Private/Source/FS/NewFS.cxx95
6 files changed, 102 insertions, 34 deletions
diff --git a/Private/Builtins/ATA/ATA.hxx b/Private/Builtins/ATA/ATA.hxx
index a2ce79ba..ed9d275a 100644
--- a/Private/Builtins/ATA/ATA.hxx
+++ b/Private/Builtins/ATA/ATA.hxx
@@ -148,5 +148,9 @@ 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);
+NewOS::SizeT drv_std_get_sector_count();
+
+NewOS::SizeT drv_std_get_drv_size();
+
#endif // ifdef __KERNEL__
#endif // ifndef __AHCI__
diff --git a/Private/FSKit/NewFS.hxx b/Private/FSKit/NewFS.hxx
index d3b72803..f66d7afb 100644
--- a/Private/FSKit/NewFS.hxx
+++ b/Private/FSKit/NewFS.hxx
@@ -117,8 +117,8 @@ struct PACKED NewCatalog final {
NewOS::Int32 Flags;
NewOS::Int32 Kind;
- NewOS::Lba FirstFork;
- NewOS::Lba LastFork;
+ NewOS::Lba DataFork;
+ NewOS::Lba ResourceFork;
NewOS::Lba NextSibling;
NewOS::Lba PrevSibling;
@@ -208,7 +208,7 @@ class NewFSParser {
/// @param name the fork name.
/// @return the fork.
_Output NewFork* FindFork(_Input NewCatalog* catalog,
- _Input const Char* name);
+ _Input const Char* name, Boolean dataOrRsrc);
virtual _Output Void RemoveFork(_Input NewFork* fork) = 0;
diff --git a/Private/HALKit/AMD64/Storage/ATA-PIO.cxx b/Private/HALKit/AMD64/Storage/ATA-PIO.cxx
index beb113d3..7f1cc11a 100644
--- a/Private/HALKit/AMD64/Storage/ATA-PIO.cxx
+++ b/Private/HALKit/AMD64/Storage/ATA-PIO.cxx
@@ -134,6 +134,8 @@ Void drv_std_read(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf,
SizeT SectorSz, SizeT Size) {
UInt8 Command = ((!Master )? 0xE0 : 0xF0);
+ Lba /= SectorSz;
+
Out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0x0F));
Out8(IO + ATA_REG_SEC_COUNT0, 1);
@@ -157,6 +159,8 @@ Void drv_std_write(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf,
SizeT SectorSz, SizeT Size) {
UInt8 Command = ((!Master) ? 0xE0 : 0xF0);
+ Lba /= SectorSz;
+
Out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0x0F));
Out8(IO + ATA_REG_SEC_COUNT0, 1);
@@ -175,7 +179,19 @@ Void drv_std_write(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf,
}
}
-/// @check is ATA detected?
+/// @brief is ATA detected?
Boolean drv_std_detected(Void) { return kATADetected; }
+/***
+ @brief Getter, gets the number of sectors inside the drive.
+*/
+NewOS::SizeT drv_std_get_sector_count() {
+ return (kATAData[61] << 16)| kATAData[60];
+}
+
+/// @brief Get the drive size.
+NewOS::SizeT drv_std_get_drv_size() {
+ return drv_std_get_sector_count() * kATASectorSize;
+}
+
#endif /* ifdef __ATA_PIO__ */
diff --git a/Private/NewBoot/BootKit/BootKit.hxx b/Private/NewBoot/BootKit/BootKit.hxx
index e2e371dd..26c6c755 100644
--- a/Private/NewBoot/BootKit/BootKit.hxx
+++ b/Private/NewBoot/BootKit/BootKit.hxx
@@ -268,8 +268,11 @@ private:
catalogKind->Kind = blob->fKind;
/// Allocate fork for blob.
- catalogKind->FirstFork = (startLba + sizeof(NewCatalog));
- catalogKind->LastFork = catalogKind->FirstFork;
+ if (catalogKind->Kind == kNewFSDataForkKind) {
+ catalogKind->DataFork = (startLba + sizeof(NewCatalog));
+ } else {
+ catalogKind->ResourceFork = (startLba + sizeof(NewCatalog));
+ }
NewFork* forkKind = new NewFork();
memset(forkKind, 0, sizeof(NewFork));
@@ -284,8 +287,8 @@ private:
forkKind->ResourceKind = 0;
/// We're the only fork here.
- forkKind->NextSibling = catalogKind->FirstFork;
- forkKind->PreviousSibling = catalogKind->FirstFork;
+ forkKind->NextSibling = forkKind->Kind == kNewFSDataForkKind ? catalogKind->DataFork : catalogKind->ResourceFork;
+ forkKind->PreviousSibling = kNewFSDataForkKind ? catalogKind->DataFork : catalogKind->ResourceFork;
forkKind->DataOffset = (startLba + sizeof(NewCatalog) + sizeof(NewFork));
forkKind->DataSize = blob->fBlobSz;
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
index 558bf001..226d5bff 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
@@ -170,6 +170,8 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle,
BDiskFormatFactory<BootDeviceATA> diskFormatter;
+ /// if not formated yet, then format it with the following folders:
+ /// /, /Boot, /Applications.
if (!diskFormatter) {
BDiskFormatFactory<BootDeviceATA>::BFileDescriptor rootDesc{0};
diff --git a/Private/Source/FS/NewFS.cxx b/Private/Source/FS/NewFS.cxx
index 7eb79d10..9dbb32e0 100644
--- a/Private/Source/FS/NewFS.cxx
+++ b/Private/Source/FS/NewFS.cxx
@@ -11,11 +11,14 @@
#include <NewKit/Crc32.hpp>
#include <NewKit/Utils.hpp>
+#include <Builtins/ATA/ATA.hxx>
+#include <Builtins/AHCI/AHCI.hxx>
+
using namespace NewOS;
/// forward decl.
-STATIC Lba ke_find_free_fork(SizeT sz, Int32 drv, NewCatalog* catalog);
+STATIC Lba ke_find_free_fork(SizeT sz, Int32 drv, NewCatalog* catalog, Boolean isDataFork);
STATIC Lba ke_find_free_catalog(SizeT kind, Int32 drv);
STATIC MountpointInterface sMountpointInterface;
@@ -30,21 +33,30 @@ _Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog,
Lba whereFork = 0;
theFork.DataOffset =
- ke_find_free_fork(theFork.DataSize, this->fDriveIndex, catalog);
+ ke_find_free_fork(theFork.DataSize, this->fDriveIndex, catalog, theFork.Kind == kNewFSDataForkKind);
theFork.Flags |= kNewFSFlagCreated;
+ Lba lba = theFork.Kind == kNewFSDataForkKind ? catalog->DataFork : catalog->ResourceFork;
- if (catalog->FirstFork == 0) {
- catalog->FirstFork = whereFork;
+ if (lba == 0) {
+ lba = whereFork;
} else {
- if (catalog->LastFork == 0) {
- theFork.PreviousSibling = catalog->FirstFork;
+ if (lba == 0) {
+ theFork.PreviousSibling = lba;
}
}
- if (catalog->LastFork == 0) {
- catalog->LastFork = whereFork;
+ if (theFork.Kind == kNewFSDataForkKind) {
+ if (catalog->DataFork == 0) {
+ catalog->DataFork = whereFork;
+ } else {
+ theFork.PreviousSibling = catalog->DataFork;
+ }
} else {
- theFork.PreviousSibling = catalog->LastFork;
+ if (catalog->ResourceFork == 0) {
+ catalog->ResourceFork = whereFork;
+ } else {
+ theFork.PreviousSibling = catalog->ResourceFork;
+ }
}
if (!sMountpointInterface.GetAddressOf(this->fDriveIndex) ||
@@ -92,10 +104,10 @@ _Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog,
/// @param name the fork name.
/// @return the fork.
_Output NewFork* NewFSParser::FindFork(_Input NewCatalog* catalog,
- _Input const Char* name) {
+ _Input const Char* name, Boolean isDataFork) {
auto drv = *sMountpointInterface.GetAddressOf(this->fDriveIndex);
NewFork* theFork = nullptr;
- Lba lba = catalog->FirstFork;
+ Lba lba = isDataFork ? catalog->DataFork : catalog->ResourceFork;
while (lba != 0) {
drv->fPacket.fLba = lba;
@@ -184,15 +196,15 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive) {
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"));
+ rt_copy_memory((VoidPtr) "Untitled HD\0", (VoidPtr)partBlock->PartitionName,
+ rt_string_len("Untitled HD\0"));
SizeT catalogCount = 0;
- SizeT sectorCount = 0;
- SizeT diskSize = 0;
+ SizeT sectorCount = drv_std_get_sector_count();
+ SizeT diskSize = drv_std_get_drv_size();
partBlock->Kind = kNewFSPartitionTypeStandard;
- partBlock->StartCatalog = sizeof(NewPartitionBlock) + kNewFSAddressAsLba;
+ partBlock->StartCatalog = kNewFSCatalogStartAddress;;
partBlock->CatalogCount = catalogCount;
partBlock->SectorCount = sectorCount;
partBlock->DiskSize = diskSize;
@@ -236,20 +248,32 @@ _Output NewCatalog* NewFSParser::FindCatalog(_Input const char* catalogName) {
/// @param name
/// @return
_Output NewCatalog* NewFSParser::GetCatalog(_Input const char* name) {
- return nullptr;
+ return this->FindCatalog(name);
}
/// @brief
/// @param catalog
/// @return
Boolean NewFSParser::CloseCatalog(_Input _Output NewCatalog* catalog) {
- return true;
+ if (this->WriteCatalog(catalog, nullptr)) {
+ delete catalog;
+ catalog = nullptr;
+
+ return true;
+ }
+
+ return false;
}
/// @brief Mark catalog as removed.
/// @param catalog The catalog structure.
/// @return
Boolean NewFSParser::RemoveCatalog(_Input _Output NewCatalog* catalog) {
+ if (!catalog) {
+ DbgLastError() = kErrorFileNotFound;
+ return false;
+ }
+
catalog->Flags |= kNewFSFlagDeleted;
this->WriteCatalog(catalog, nullptr);
@@ -260,32 +284,51 @@ Boolean NewFSParser::RemoveCatalog(_Input _Output NewCatalog* catalog) {
/// Reading,Seek,Tell are unimplemented on catalogs, refer to forks I/O instead.
/// ***************************************************************** ///
-/// @brief
+/// @brief Read the catalog data fork.
/// @param catalog
/// @param dataSz
/// @return
VoidPtr NewFSParser::ReadCatalog(_Input _Output NewCatalog* catalog,
SizeT dataSz) {
- return nullptr;
+ if (!catalog) {
+ DbgLastError() = kErrorFileNotFound;
+ return nullptr;
+ }
+
+
+
+ return nullptr;
}
-/// @brief
+/// @brief Seek in the data fork.
/// @param catalog
/// @param off
/// @return
bool NewFSParser::Seek(_Input _Output NewCatalog* catalog, SizeT off) {
- return false;
+ if (!catalog) {
+ DbgLastError() = kErrorFileNotFound;
+ return false;
+ }
+
+ return false;
}
-/// @brief
+/// @brief Tell where we are inside the data fork.
/// @param catalog
/// @return
-SizeT NewFSParser::Tell(_Input _Output NewCatalog* catalog) { return 0; }
+SizeT NewFSParser::Tell(_Input _Output NewCatalog* catalog) {
+ if (!catalog) {
+ DbgLastError() = kErrorFileNotFound;
+ return false;
+ }
+
+ 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) {
+STATIC Lba ke_find_free_fork(SizeT sz, Int32 drv, NewCatalog* catalog, Boolean isDataFork) {
auto drive = *sMountpointInterface.GetAddressOf(drv);
if (drive) {
@@ -293,7 +336,7 @@ STATIC Lba ke_find_free_fork(SizeT sz, Int32 drv, NewCatalog* catalog) {
bool done = false;
bool error = false;
- Lba lba = catalog->LastFork;
+ Lba lba = isDataFork ? catalog->DataFork : catalog->ResourceFork;
while (!done) {
Char sectorBuf[kNewFSMinimumSectorSz] = {0};