feat: vfs - add dynamic filesystem mounts and safe unmount lifecycle
This commit is contained in:
@@ -11,7 +11,8 @@
|
||||
|
||||
namespace filemanager {
|
||||
|
||||
inline constexpr int FM_MAX_DRIVES = 16;
|
||||
// Matches Fs::Vfs::MaxDrives; sizes the buffer passed to montauk::drivelist().
|
||||
inline constexpr int FM_MAX_DRIVES = 64;
|
||||
|
||||
enum FileManagerEntryType : int {
|
||||
FM_ENTRY_FILE = 0,
|
||||
|
||||
@@ -238,18 +238,12 @@ void filemanager_read_drives(FileManagerState* fm) {
|
||||
for (int di = 0; di < driveCount; di++) {
|
||||
int d = drives[di];
|
||||
char probe[8];
|
||||
if (d < 10) {
|
||||
probe[0] = '0' + d;
|
||||
probe[1] = ':';
|
||||
probe[2] = '/';
|
||||
probe[3] = '\0';
|
||||
} else {
|
||||
probe[0] = '1';
|
||||
probe[1] = '0' + (d - 10);
|
||||
probe[2] = ':';
|
||||
probe[3] = '/';
|
||||
probe[4] = '\0';
|
||||
}
|
||||
int pi = 0;
|
||||
if (d >= 10) probe[pi++] = (char)('0' + (d / 10));
|
||||
probe[pi++] = (char)('0' + (d % 10));
|
||||
probe[pi++] = ':';
|
||||
probe[pi++] = '/';
|
||||
probe[pi] = '\0';
|
||||
char label[64];
|
||||
montauk::strcpy(label, "Drive ");
|
||||
str_append(label, probe, 64);
|
||||
|
||||
@@ -42,9 +42,11 @@ constexpr int GRID_CELL_H = 80;
|
||||
constexpr int GRID_ICON = 48;
|
||||
constexpr int GRID_PAD = 4;
|
||||
|
||||
constexpr int MAX_ENTRIES = 64;
|
||||
constexpr int MAX_HISTORY = 16;
|
||||
constexpr int MAX_DRIVES = 16;
|
||||
// Matches Fs::Vfs::MaxDrives; sizes the buffer passed to montauk::drivelist().
|
||||
constexpr int MAX_DRIVES = 64;
|
||||
// The drives root can contain all drives plus the six special home folders.
|
||||
constexpr int MAX_ENTRIES = MAX_DRIVES + 6;
|
||||
constexpr int BUTTON_H = 30;
|
||||
constexpr int BUTTON_W = 88;
|
||||
|
||||
|
||||
@@ -150,7 +150,33 @@ void do_mount_partition() {
|
||||
|
||||
int global_idx = part_indices[dt.selected_part];
|
||||
int driveNum = 1 + global_idx;
|
||||
if (driveNum >= 16) driveNum = 15;
|
||||
|
||||
int mountedDrives[MAX_DRIVES];
|
||||
int mountedCount = montauk::drivelist(mountedDrives, MAX_DRIVES);
|
||||
bool occupied[MAX_DRIVES] = {};
|
||||
for (int i = 0; i < mountedCount; i++) {
|
||||
int mountedDrive = mountedDrives[i];
|
||||
if (mountedDrive >= 0 && mountedDrive < MAX_DRIVES) {
|
||||
occupied[mountedDrive] = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Preserve the stable partition-to-drive mapping when it is available.
|
||||
// Otherwise use the lowest free non-ramdisk drive in the full namespace.
|
||||
if (driveNum >= MAX_DRIVES || occupied[driveNum]) {
|
||||
driveNum = -1;
|
||||
for (int candidate = 1; candidate < MAX_DRIVES; candidate++) {
|
||||
if (!occupied[candidate]) {
|
||||
driveNum = candidate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (driveNum < 0) {
|
||||
set_status("Mount failed (no free drive slot)");
|
||||
return;
|
||||
}
|
||||
|
||||
int r = montauk::fs_mount(global_idx, driveNum);
|
||||
if (r < 0) {
|
||||
|
||||
@@ -32,6 +32,8 @@ static constexpr int MAP_H = 48;
|
||||
static constexpr int MAP_PAD = 16;
|
||||
static constexpr int MAX_PARTS = 32;
|
||||
static constexpr int MAX_DISKS = 32;
|
||||
// Matches Fs::Vfs::MaxDrives; used for selecting a free mount target.
|
||||
static constexpr int MAX_DRIVES = 64;
|
||||
static constexpr int STATUS_H = 44;
|
||||
|
||||
static constexpr int TB_BTN_Y = 7;
|
||||
|
||||
Reference in New Issue
Block a user