- Bump ctx API to 1.31.0; extend /proc/bare_os/syscalls.json schema 4 (fdModel, signalModel) - Add /mirror/aux* routing for auxiliary Hyperdrives; optional BLAKE2b-keyed /bin cache (BARE_OS_VFS_BIN_CACHE_BLAKE2B) - Wire seeder snapshotHintsJson from BARE_OS_SEED_* env; add seeder unit tests - Shell: trap -p; docs for jobs/bg/trap; sync schemas, examples, compatibility matrix, handbook ch.9 - Coreutils: Issue 7 man option rows for cp/mv/ln/find/grep/sed/awk/tar/test/true; xcu-issue7-sweep tests - Docs: env appendix, vault-threat-model, node-vs-bare-host-matrix, test:bare, CHANGELOG 1.31.0
52 lines
1.7 KiB
JavaScript
52 lines
1.7 KiB
JavaScript
/**
|
|
* Best-effort Hyperdrive → statvfs-like counters for `/proc/bare_os_resources` and `df`.
|
|
* Hyperdrive versions differ; probes are defensive.
|
|
*/
|
|
import b4a from 'b4a'
|
|
|
|
/**
|
|
* @param {unknown} drive
|
|
* @returns {{ f_bsize: number, f_frsize: number, f_blocks: number, f_bfree: number, f_bavail: number, f_files: number | null, f_ffree: number | null, f_namemax: number, fsidPrefixHex?: string } | null}
|
|
*/
|
|
export function bareOsStatvfsFromHyperdrive(drive) {
|
|
if (!drive || typeof drive !== 'object') return null
|
|
const bsize = 4096
|
|
/** @type {number} */
|
|
let usedBytes = 0
|
|
try {
|
|
const c = /** @type {{ byteLength?: number, tree?: { byteLength?: number, length?: number } }} */ (
|
|
drive
|
|
).core
|
|
if (c && typeof c.byteLength === 'number') usedBytes = c.byteLength
|
|
else if (c && c.tree && typeof c.tree.byteLength === 'number')
|
|
usedBytes = c.tree.byteLength
|
|
else if (c && c.tree && typeof c.tree.length === 'number')
|
|
usedBytes = Math.max(usedBytes, (c.tree.length | 0) * 256)
|
|
} catch {
|
|
return null
|
|
}
|
|
if (!Number.isFinite(usedBytes) || usedBytes < 0) return null
|
|
const usedBlocks = Math.max(1, Math.ceil(usedBytes / bsize))
|
|
const headroom = Math.max(4096, usedBlocks)
|
|
const blocks = usedBlocks + headroom
|
|
const bfree = Math.max(0, blocks - usedBlocks)
|
|
let fsidPrefixHex
|
|
try {
|
|
const k = /** @type {{ key?: Uint8Array }} */ (drive).key
|
|
if (k && k.byteLength) fsidPrefixHex = b4a.toString(k, 'hex').slice(0, 16)
|
|
} catch {
|
|
/* optional */
|
|
}
|
|
return {
|
|
f_bsize: bsize,
|
|
f_frsize: bsize,
|
|
f_blocks: blocks,
|
|
f_bfree: bfree,
|
|
f_bavail: bfree,
|
|
f_files: null,
|
|
f_ffree: null,
|
|
f_namemax: 255,
|
|
fsidPrefixHex
|
|
}
|
|
}
|