feat: expose drive labels to userspace, render in Files
This commit is contained in:
@@ -122,4 +122,8 @@ namespace Montauk {
|
||||
static int Sys_DriveList(int* outDrives, int maxEntries) {
|
||||
return Fs::Vfs::VfsDriveList(outDrives, maxEntries);
|
||||
}
|
||||
|
||||
static int Sys_DriveLabel(int driveNumber, char* outLabel, int maxLen) {
|
||||
return Fs::Vfs::VfsDriveLabel(driveNumber, outLabel, maxLen);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -209,6 +209,10 @@ namespace Montauk {
|
||||
if ((int64_t)frame->arg2 < 0) return -1;
|
||||
if (!UserMemory::Range(frame->arg1, (uint64_t)frame->arg2 * sizeof(int), true)) return -1;
|
||||
return (int64_t)Sys_DriveList((int*)frame->arg1, (int)frame->arg2);
|
||||
case SYS_DRIVELABEL:
|
||||
if ((int64_t)frame->arg3 <= 0) return -1;
|
||||
if (!UserMemory::Range(frame->arg2, frame->arg3, true)) return -1;
|
||||
return (int64_t)Sys_DriveLabel((int)frame->arg1, (char*)frame->arg2, (int)frame->arg3);
|
||||
case SYS_TERMSCALE:
|
||||
return Sys_TermScale(frame->arg1, frame->arg2);
|
||||
case SYS_RESOLVE:
|
||||
|
||||
@@ -222,6 +222,9 @@ namespace Montauk {
|
||||
/* Input.hpp */
|
||||
static constexpr uint64_t SYS_INPUT_WAIT = 123;
|
||||
|
||||
/* Filesystem.hpp */
|
||||
static constexpr uint64_t SYS_DRIVELABEL = 124;
|
||||
|
||||
static constexpr uint32_t CLIPBOARD_MAX_TEXT_BYTES = 256 * 1024;
|
||||
|
||||
static constexpr uint32_t IPC_SIGNAL_READABLE = 1u << 0;
|
||||
|
||||
@@ -65,6 +65,7 @@ namespace Fs {
|
||||
Ramdisk::Delete,
|
||||
Ramdisk::Mkdir,
|
||||
Ramdisk::Rename,
|
||||
Ramdisk::GetLabel,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1592,6 +1592,11 @@ namespace Fs::Ext2 {
|
||||
// Template thunks — generate unique function pointers per instance
|
||||
// =========================================================================
|
||||
|
||||
static const char* GetLabelImpl(int inst) {
|
||||
if (inst < 0 || inst >= g_instanceCount || !g_instances[inst].active) return nullptr;
|
||||
return g_instances[inst].volumeLabel[0] ? g_instances[inst].volumeLabel : nullptr;
|
||||
}
|
||||
|
||||
template<int N> struct Thunks {
|
||||
static int Open(const char* p) { return OpenImpl(N, p); }
|
||||
static int Read(int h, uint8_t* b, uint64_t o, uint64_t s) { return ReadImpl(N, h, b, o, s); }
|
||||
@@ -1603,6 +1608,7 @@ namespace Fs::Ext2 {
|
||||
static int Delete(const char* p) { return DeleteImpl(N, p); }
|
||||
static int Mkdir(const char* p) { return MkdirImpl(N, p); }
|
||||
static int Rename(const char* o, const char* n) { return RenameImpl(N, o, n); }
|
||||
static const char* GetLabel() { return GetLabelImpl(N); }
|
||||
};
|
||||
|
||||
template<int N>
|
||||
@@ -1618,6 +1624,7 @@ namespace Fs::Ext2 {
|
||||
Thunks<N>::Delete,
|
||||
Thunks<N>::Mkdir,
|
||||
Thunks<N>::Rename,
|
||||
Thunks<N>::GetLabel,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1748,6 +1748,14 @@ namespace Fs::Fat32 {
|
||||
// Template thunks — generate unique function pointers per instance
|
||||
// =========================================================================
|
||||
|
||||
static const char* GetLabelImpl(int inst) {
|
||||
if (inst < 0 || inst >= g_instanceCount || !g_instances[inst].active) return nullptr;
|
||||
|
||||
const char* label = g_instances[inst].volumeLabel;
|
||||
if (label[0] == '\0' || StrEqualNoCase(label, "NO NAME")) return nullptr;
|
||||
return label;
|
||||
}
|
||||
|
||||
template<int N> struct Thunks {
|
||||
static int Open(const char* p) { return OpenImpl(N, p); }
|
||||
static int Read(int h, uint8_t* b, uint64_t o, uint64_t s) { return ReadImpl(N, h, b, o, s); }
|
||||
@@ -1759,6 +1767,7 @@ namespace Fs::Fat32 {
|
||||
static int Delete(const char* p) { return DeleteImpl(N, p); }
|
||||
static int Mkdir(const char* p) { return MkdirImpl(N, p); }
|
||||
static int Rename(const char* o, const char* n) { return RenameImpl(N, o, n); }
|
||||
static const char* GetLabel() { return GetLabelImpl(N); }
|
||||
};
|
||||
|
||||
template<int N>
|
||||
@@ -1774,6 +1783,7 @@ namespace Fs::Fat32 {
|
||||
Thunks<N>::Delete,
|
||||
Thunks<N>::Mkdir,
|
||||
Thunks<N>::Rename,
|
||||
Thunks<N>::GetLabel,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,10 @@ namespace Fs::Ramdisk {
|
||||
return n;
|
||||
}
|
||||
|
||||
const char* GetLabel() {
|
||||
return "Ramdisk";
|
||||
}
|
||||
|
||||
static bool StartsWith(const char* str, const char* prefix) {
|
||||
while (*prefix) {
|
||||
if (*str != *prefix) return false;
|
||||
|
||||
@@ -35,6 +35,7 @@ namespace Fs::Ramdisk {
|
||||
int Delete(const char* path);
|
||||
int Mkdir(const char* path);
|
||||
int Rename(const char* oldPath, const char* newPath);
|
||||
const char* GetLabel();
|
||||
int GetFileCount();
|
||||
|
||||
}
|
||||
|
||||
@@ -208,6 +208,38 @@ namespace Fs::Vfs {
|
||||
return count;
|
||||
}
|
||||
|
||||
int VfsDriveLabel(int driveNumber, char* outLabel, int maxLen) {
|
||||
if (outLabel == nullptr || maxLen <= 0) return -1;
|
||||
outLabel[0] = '\0';
|
||||
|
||||
vfsLock.Acquire();
|
||||
if (driveNumber < 0 || driveNumber >= MaxDrives || driveTable[driveNumber] == nullptr) {
|
||||
vfsLock.Release();
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (driveTable[driveNumber]->GetLabel == nullptr) {
|
||||
vfsLock.Release();
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char* label = driveTable[driveNumber]->GetLabel();
|
||||
if (label == nullptr || label[0] == '\0') {
|
||||
vfsLock.Release();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int copied = 0;
|
||||
while (label[copied] != '\0' && copied < maxLen - 1) {
|
||||
outLabel[copied] = label[copied];
|
||||
copied++;
|
||||
}
|
||||
outLabel[copied] = '\0';
|
||||
|
||||
vfsLock.Release();
|
||||
return copied;
|
||||
}
|
||||
|
||||
int VfsRename(const char* oldPath, const char* newPath) {
|
||||
int oldDrive, newDrive;
|
||||
const char* oldLocal;
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace Fs::Vfs {
|
||||
int (*Delete)(const char* path);
|
||||
int (*Mkdir)(const char* path);
|
||||
int (*Rename)(const char* oldPath, const char* newPath);
|
||||
const char* (*GetLabel)();
|
||||
};
|
||||
|
||||
void Initialize();
|
||||
@@ -48,5 +49,6 @@ namespace Fs::Vfs {
|
||||
|
||||
// Returns number of registered drives, fills outDrives[] with their indices
|
||||
int VfsDriveList(int* outDrives, int maxEntries);
|
||||
int VfsDriveLabel(int driveNumber, char* outLabel, int maxLen);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user