feat: added Files app USB medium detection
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
|
||||
#pragma once
|
||||
#include <Fs/Vfs.hpp>
|
||||
#include <Fs/FsProbe.hpp>
|
||||
#include <Drivers/Storage/BlockDevice.hpp>
|
||||
#include <Sched/Scheduler.hpp>
|
||||
#include <Memory/PageFrameAllocator.hpp>
|
||||
#include <Memory/HHDM.hpp>
|
||||
@@ -126,4 +128,11 @@ namespace Montauk {
|
||||
static int Sys_DriveLabel(int driveNumber, char* outLabel, int maxLen) {
|
||||
return Fs::Vfs::VfsDriveLabel(driveNumber, outLabel, maxLen);
|
||||
}
|
||||
|
||||
static int Sys_DriveKind(int driveNumber) {
|
||||
int blockDev = Fs::FsProbe::GetBlockDeviceForDrive(driveNumber);
|
||||
if (blockDev < 0) return 0;
|
||||
auto* dev = Drivers::Storage::GetBlockDevice(blockDev);
|
||||
return dev ? (int)dev->Kind : 0;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -217,6 +217,8 @@ namespace Montauk {
|
||||
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_DRIVEKIND:
|
||||
return (int64_t)Sys_DriveKind((int)frame->arg1);
|
||||
case SYS_TERMSCALE:
|
||||
return Sys_TermScale(frame->arg1, frame->arg2);
|
||||
case SYS_RESOLVE:
|
||||
|
||||
@@ -225,6 +225,7 @@ namespace Montauk {
|
||||
|
||||
/* Filesystem.hpp */
|
||||
static constexpr uint64_t SYS_DRIVELABEL = 124;
|
||||
static constexpr uint64_t SYS_DRIVEKIND = 127;
|
||||
|
||||
/* Net.hpp */
|
||||
static constexpr uint64_t SYS_NETSTATUS = 125;
|
||||
|
||||
@@ -142,6 +142,18 @@ namespace Fs::FsProbe {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int GetBlockDeviceForDrive(int driveNum) {
|
||||
if (driveNum < 0) return -1;
|
||||
int partCount = Drivers::Storage::Gpt::GetPartitionCount();
|
||||
for (int i = 0; i < partCount && i < Drivers::Storage::Gpt::MaxPartitions; i++) {
|
||||
if (g_mounted[i] && g_driveForPart[i] == driveNum) {
|
||||
auto* part = Drivers::Storage::Gpt::GetPartition(i);
|
||||
if (part) return part->BlockDevIndex;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int UnmountPartitionsForBlockDevice(int blockDevIndex) {
|
||||
int partCount = Drivers::Storage::Gpt::GetPartitionCount();
|
||||
int unmounted = 0;
|
||||
|
||||
@@ -34,4 +34,8 @@ namespace Fs::FsProbe {
|
||||
// mount bookkeeping to match Gpt::RemovePartitionsForBlockDevice().
|
||||
int UnmountPartitionsForBlockDevice(int blockDevIndex);
|
||||
|
||||
// Return the block-device index backing a mounted VFS drive, or -1 if the
|
||||
// drive isn't backed by a partition (e.g. ramdisk).
|
||||
int GetBlockDeviceForDrive(int driveNum);
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user