feat: GPT, FAT32 driver, disks app, userspace adapted for multiple drives, and more

This commit is contained in:
2026-03-07 15:58:27 +01:00
parent 8c5c259f5d
commit 4d0177d55e
48 changed files with 5777 additions and 873 deletions
File diff suppressed because it is too large Load Diff
+29
View File
@@ -0,0 +1,29 @@
/*
* Fat32.hpp
* FAT32 filesystem driver
* Copyright (c) 2026 Daniel Hammer
*/
#pragma once
#include <cstdint>
#include <Fs/Vfs.hpp>
namespace Fs::Fat32 {
// Try to mount a FAT32 filesystem at the given partition range.
// Returns a FsDriver* on success, nullptr if not a valid FAT32 volume.
Vfs::FsDriver* Mount(int blockDevIndex, uint64_t startLba, uint64_t sectorCount);
// Register Fat32::Mount as a filesystem probe with FsProbe.
void RegisterProbe();
// Format a partition as FAT32.
// blockDevIndex: which block device the partition is on
// startLba: first LBA of the partition
// sectorCount: number of sectors in the partition
// volumeLabel: up to 11-char volume label (null-terminated)
// Returns 0 on success, -1 on error.
int Format(int blockDevIndex, uint64_t startLba, uint64_t sectorCount,
const char* volumeLabel);
};
+70
View File
@@ -0,0 +1,70 @@
/*
* FsProbe.cpp
* Filesystem probe registry
* Copyright (c) 2026 Daniel Hammer
*/
#include "FsProbe.hpp"
#include <Drivers/Storage/Gpt.hpp>
#include <Terminal/Terminal.hpp>
namespace Fs::FsProbe {
static ProbeFn g_probes[MaxProbes] = {};
static int g_probeCount = 0;
void Register(ProbeFn fn) {
if (g_probeCount < MaxProbes && fn) {
g_probes[g_probeCount++] = fn;
}
}
void MountPartitions(int firstDrive) {
int partCount = Drivers::Storage::Gpt::GetPartitionCount();
if (partCount == 0 || g_probeCount == 0) return;
int driveNum = firstDrive;
for (int i = 0; i < partCount && driveNum < Vfs::MaxDrives; i++) {
auto* part = Drivers::Storage::Gpt::GetPartition(i);
if (!part) continue;
for (int p = 0; p < g_probeCount; p++) {
Vfs::FsDriver* driver = g_probes[p](
part->BlockDevIndex, part->StartLba, part->SectorCount);
if (driver) {
Vfs::RegisterDrive(driveNum, driver);
Kt::KernelLogStream(Kt::OK, "FsProbe") << "Mounted partition "
<< i << " as drive " << driveNum;
driveNum++;
break;
}
}
}
}
int MountPartition(int partIndex, int driveNum) {
if (driveNum < 0 || driveNum >= Vfs::MaxDrives) return -1;
if (g_probeCount == 0) return -1;
auto* part = Drivers::Storage::Gpt::GetPartition(partIndex);
if (!part) return -1;
for (int p = 0; p < g_probeCount; p++) {
Vfs::FsDriver* driver = g_probes[p](
part->BlockDevIndex, part->StartLba, part->SectorCount);
if (driver) {
Vfs::RegisterDrive(driveNum, driver);
Kt::KernelLogStream(Kt::OK, "FsProbe") << "Mounted partition "
<< partIndex << " as drive " << driveNum;
return 0;
}
}
Kt::KernelLogStream(Kt::WARNING, "FsProbe") << "No filesystem recognized on partition " << partIndex;
return -1;
}
};
+29
View File
@@ -0,0 +1,29 @@
/*
* FsProbe.hpp
* Filesystem probe registry
* Copyright (c) 2026 Daniel Hammer
*/
#pragma once
#include <Fs/Vfs.hpp>
namespace Fs::FsProbe {
static constexpr int MaxProbes = 8;
// A probe function attempts to mount a filesystem on the given partition.
// Returns a FsDriver* on success, nullptr if the filesystem is not recognized.
using ProbeFn = Vfs::FsDriver* (*)(int blockDevIndex, uint64_t startLba, uint64_t sectorCount);
// Register a filesystem probe function (called once per FS driver at init).
void Register(ProbeFn fn);
// Probe all discovered GPT partitions and auto-mount recognized filesystems.
// Assigns VFS drive numbers starting from firstDrive.
void MountPartitions(int firstDrive = 1);
// Try to mount a single partition (by global partition index) as the given VFS drive.
// Returns 0 on success, -1 if no probe recognized the filesystem.
int MountPartition(int partIndex, int driveNum);
};
+13
View File
@@ -163,6 +163,19 @@ namespace Fs::Vfs {
return globalHandle;
}
int VfsDelete(const char* path) {
int drive;
const char* localPath;
if (!ParsePath(path, drive, localPath)) return -1;
if (drive < 0 || drive >= MaxDrives || driveTable[drive] == nullptr) return -1;
if (driveTable[drive]->Delete == nullptr) return -1;
return driveTable[drive]->Delete(localPath);
}
int VfsReadDir(const char* path, const char** outNames, int maxEntries) {
int drive;
const char* localPath;
+2
View File
@@ -21,6 +21,7 @@ namespace Fs::Vfs {
int (*ReadDir)(const char* path, const char** outNames, int maxEntries);
int (*Write)(int handle, const uint8_t* buffer, uint64_t offset, uint64_t size);
int (*Create)(const char* path);
int (*Delete)(const char* path);
};
void Initialize();
@@ -30,6 +31,7 @@ namespace Fs::Vfs {
int VfsRead(int handle, uint8_t* buffer, uint64_t offset, uint64_t size);
int VfsWrite(int handle, const uint8_t* buffer, uint64_t offset, uint64_t size);
int VfsCreate(const char* path);
int VfsDelete(const char* path);
uint64_t VfsGetSize(int handle);
void VfsClose(int handle);
int VfsReadDir(const char* path, const char** outNames, int maxEntries);