feat: add 'vol' command
This commit is contained in:
1 parent
420a7c996c
commit
80b5beb17d
17 files changed
+284
-17
No files matched your search
@@ -262,6 +262,9 @@ namespace montauk::abi {
|
||||
// The caller's own capability masks.
|
||||
static constexpr uint64_t SYS_GETCAPS = 189; // (SpawnCapabilities*) -> 0, -1 bad pointer
|
||||
|
||||
/* Storage.hpp */
|
||||
static constexpr uint64_t SYS_VOLINFO = 190; // (VolInfo*, maxCount) -> count, -1 bad pointer
|
||||
|
||||
/* Kernel-owned process capabilities. User identities may namespace
|
||||
per-user resources, but never participate in authorization decisions. */
|
||||
static constexpr uint64_t CAP_PROCESS_ADMIN = 1ULL << 0;
|
||||
@@ -603,6 +606,28 @@ namespace montauk::abi {
|
||||
char typeName[24]; // human-readable type name
|
||||
};
|
||||
|
||||
// One mounted volume (returned by SYS_VOLINFO). A volume is a single
|
||||
// mounted filesystem, which is what a drive number names: one physical
|
||||
// disk with three partitions occupies three drive numbers.
|
||||
//
|
||||
// A volume with no backing partition -- the boot ramdisk -- reports
|
||||
// blockDev and partIndex as -1 and leaves the geometry fields zero.
|
||||
struct VolInfo {
|
||||
int32_t drive; // VFS drive number ("N:/")
|
||||
int32_t blockDev; // backing block device index, -1 if none
|
||||
int32_t partIndex; // global GPT partition index, -1 if none
|
||||
uint32_t kind; // BlockDeviceKind: 0=none/ramdisk, 1=SATA, 2=SATAPI, 3=NVMe, 4=USB MSC
|
||||
uint64_t startLba; // partition start LBA, 0 if none
|
||||
uint64_t sectorCount; // partition length in sectors, 0 if none
|
||||
uint32_t sectorSize; // logical sector size in bytes, 0 if none
|
||||
uint32_t _pad0;
|
||||
char label[36]; // filesystem volume label, "" if unset
|
||||
char fsType[12]; // "ext2", "FAT32", "ramdisk", "" if unknown
|
||||
char partName[72]; // GPT partition name, "" if none
|
||||
char model[41]; // backing disk model, "" if none
|
||||
char _pad1[3];
|
||||
};
|
||||
|
||||
struct GptAddParams {
|
||||
int32_t blockDev;
|
||||
uint32_t _pad0;
|
||||
|
||||
@@ -213,6 +213,7 @@ extern "C" {
|
||||
#define MTK_SYS_ALLOC_EAGER 187
|
||||
#define MTK_SYS_BATTERYINFO 188
|
||||
#define MTK_SYS_GETCAPS 189
|
||||
#define MTK_SYS_VOLINFO 190
|
||||
/* @SYSCALLS-END */
|
||||
|
||||
#define MTK_SOCK_TCP 1
|
||||
|
||||
@@ -514,6 +514,10 @@ namespace montauk {
|
||||
inline int partlist(montauk::abi::PartInfo* buf, int max) {
|
||||
return (int)syscall2(montauk::abi::SYS_PARTLIST, (uint64_t)buf, (uint64_t)max);
|
||||
}
|
||||
// One entry per mounted volume (one filesystem, i.e. one drive number).
|
||||
inline int volinfo(montauk::abi::VolInfo* buf, int max) {
|
||||
return (int)syscall2(montauk::abi::SYS_VOLINFO, (uint64_t)buf, (uint64_t)max);
|
||||
}
|
||||
|
||||
// Raw block device I/O (driver-agnostic)
|
||||
inline int64_t disk_read(int blockDev, uint64_t lba, uint32_t sectorCount, void* buf) {
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
.TH VOL 1
|
||||
.SH NAME
|
||||
vol - list mounted volumes
|
||||
|
||||
.SH SYNOPSIS
|
||||
vol
|
||||
|
||||
.SH DESCRIPTION
|
||||
Prints information about volumes present on the system.
|
||||
|
||||
Drive numbers (column "Vol") represent volumes rather than physical disk devices.
|
||||
|
||||
The boot ramdisk, if present, reports "-" for its size, disk, and partition.
|
||||
|
||||
.SH OUTPUT
|
||||
Vol Type Label Size Disk Part Partition
|
||||
0:/ ramdisk MontaukOS - - - -
|
||||
1:/ ext2 Montauk 118.4 GiB 0 0 Montauk
|
||||
2:/ FAT32 EFI 512.0 MiB 0 1 EFI System
|
||||
|
||||
Disks:
|
||||
0 NVMe Samsung SSD 990 PRO 1TB
|
||||
|
||||
.SH COLUMNS
|
||||
Vol Drive number, as written in paths ("1:/file.txt").
|
||||
Type Filesystem type (ext2, FAT32, ramdisk).
|
||||
Label Filesystem volume label, or "-" if unset.
|
||||
Size Partition size, binary prefixes.
|
||||
Disk Block device index (see disk legend below the table).
|
||||
Part Partition index on that disk.
|
||||
Partition GPT partition name, or "-" if unset.
|
||||
|
||||
.SH SEE ALSO
|
||||
disks(1), shell(1), syscalls(2)
|
||||
@@ -62,6 +62,7 @@ void cmd_help() {
|
||||
montauk::print(" edit [file] Text editor\n");
|
||||
montauk::print(" whoami Print current username\n");
|
||||
montauk::print(" info Show system information\n");
|
||||
montauk::print(" vol List mounted volumes\n");
|
||||
montauk::print(" date Show current date and time\n");
|
||||
montauk::print(" uptime Show uptime\n");
|
||||
montauk::print(" clear Clear the screen\n");
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* main.cpp
|
||||
* vol - List mounted volumes and the disks they live on
|
||||
* Copyright (c) 2026 Daniel Hammer
|
||||
*/
|
||||
|
||||
#include <montauk/syscall.h>
|
||||
#include <libc/stdio.h>
|
||||
|
||||
static constexpr int MaxVolumes = 64;
|
||||
|
||||
static const char* kind_name(unsigned kind) {
|
||||
switch (kind) {
|
||||
case 1: return "SATA";
|
||||
case 2: return "SATAPI";
|
||||
case 3: return "NVMe";
|
||||
case 4: return "USB";
|
||||
default: return "-";
|
||||
}
|
||||
}
|
||||
|
||||
static void format_size(uint64_t bytes, char* out, int outMax) {
|
||||
static const char* units[] = { "B", "KiB", "MiB", "GiB", "TiB", "PiB" };
|
||||
int unit = 0;
|
||||
uint64_t whole = bytes;
|
||||
uint64_t rem = 0;
|
||||
|
||||
while (whole >= 1024 && unit < 5) {
|
||||
rem = whole % 1024;
|
||||
whole /= 1024;
|
||||
unit++;
|
||||
}
|
||||
|
||||
if (unit == 0) {
|
||||
snprintf(out, outMax, "%llu B", (unsigned long long)whole);
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned tenths = (unsigned)((rem * 10) / 1024);
|
||||
snprintf(out, outMax, "%llu.%u %s", (unsigned long long)whole, tenths, units[unit]);
|
||||
}
|
||||
|
||||
extern "C" void _start() {
|
||||
montauk::abi::VolInfo vols[MaxVolumes] = {};
|
||||
int n = montauk::volinfo(vols, MaxVolumes);
|
||||
|
||||
if (n <= 0) {
|
||||
montauk::print("No volumes are mounted.\n");
|
||||
montauk::exit(n < 0 ? 1 : 0);
|
||||
}
|
||||
|
||||
printf("%-5s %-8s %-18s %10s %5s %5s %s\n",
|
||||
"Vol", "Type", "Label", "Size", "Disk", "Part", "Partition");
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
const montauk::abi::VolInfo& v = vols[i];
|
||||
|
||||
char drive[8];
|
||||
snprintf(drive, sizeof(drive), "%d:/", v.drive);
|
||||
|
||||
char size[16];
|
||||
if (v.sectorCount != 0 && v.sectorSize != 0) {
|
||||
format_size(v.sectorCount * (uint64_t)v.sectorSize, size, sizeof(size));
|
||||
} else {
|
||||
snprintf(size, sizeof(size), "-");
|
||||
}
|
||||
|
||||
char disk[8];
|
||||
char part[8];
|
||||
if (v.blockDev >= 0) snprintf(disk, sizeof(disk), "%d", v.blockDev);
|
||||
else snprintf(disk, sizeof(disk), "-");
|
||||
if (v.partIndex >= 0) snprintf(part, sizeof(part), "%d", v.partIndex);
|
||||
else snprintf(part, sizeof(part), "-");
|
||||
|
||||
printf("%-5s %-8s %-18s %10s %5s %5s %s\n",
|
||||
drive,
|
||||
v.fsType[0] ? v.fsType : "-",
|
||||
v.label[0] ? v.label : "-",
|
||||
size, disk, part,
|
||||
v.partName[0] ? v.partName : "-");
|
||||
}
|
||||
|
||||
bool printedHeader = false;
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (vols[i].blockDev < 0) continue;
|
||||
|
||||
bool seen = false;
|
||||
for (int j = 0; j < i; j++) {
|
||||
if (vols[j].blockDev == vols[i].blockDev) { seen = true; break; }
|
||||
}
|
||||
if (seen) continue;
|
||||
|
||||
if (!printedHeader) {
|
||||
montauk::print("\nDisks:\n");
|
||||
printedHeader = true;
|
||||
}
|
||||
|
||||
printf(" %d %-6s %s\n",
|
||||
vols[i].blockDev,
|
||||
kind_name(vols[i].kind),
|
||||
vols[i].model[0] ? vols[i].model : "(unknown)");
|
||||
}
|
||||
|
||||
montauk::exit(0);
|
||||
}
|
||||
Reference in new issue
Block a user