/* BARE_OS_BIN_API 1.0.0 — bump when staged /bin script semantics change (see developer guide). */ /** Shared helpers for drive-resident /bin scripts (prepended before each command). */ function bareStdin(ctx) { return typeof ctx.shellStdin === 'string' ? ctx.shellStdin : '' } /** @param {number} mode @param {'file' | 'directory' | 'symlink'} type */ function bareFormatModeString(mode, type) { const typeChar = type === 'directory' ? 'd' : type === 'symlink' ? 'l' : '-' const perm = mode & 0o777 const r = (bit) => (perm & bit ? 'r' : '-') const w = (bit) => (perm & bit ? 'w' : '-') const x = (bit) => (perm & bit ? 'x' : '-') return ( typeChar + r(0o400) + w(0o200) + x(0o100) + r(0o040) + w(0o020) + x(0o010) + r(0o004) + w(0o002) + x(0o001) ) } /** @param {number} mtimeMs @param {number} [nowMs] */ function bareFormatLsMtime(mtimeMs, nowMs) { const now = nowMs != null ? nowMs : Date.now() const d = new Date(mtimeMs) const months = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ] const mon = months[d.getMonth()] const day = String(d.getDate()).padStart(2, ' ') const sixMo = 180 * 24 * 3600 * 1000 if (Math.abs(now - mtimeMs) > sixMo) { const yr = String(d.getFullYear()).padStart(4, ' ') return mon + ' ' + day + ' ' + yr } const hh = String(d.getHours()).padStart(2, '0') const mm = String(d.getMinutes()).padStart(2, '0') return mon + ' ' + day + ' ' + hh + ':' + mm } /** @param {number} size */ function barePosixBlocks(size) { return Math.ceil(Number(size) / 512) || 0 } /** * Subset of POSIX.1-2017 getconf — fixed values for Bare OS (no host sysconf). * Unknown names exit with status 1 (matches common getconf for invalid var). */ const CONF = { PATH_MAX: '4096', NAME_MAX: '255', /** POSIX minimum for ARG_MAX; Bare uses a conservative cap for runBinCommand argv. */ _POSIX_ARG_MAX: '4096', ARG_MAX: '262144', LINE_MAX: '2048', /** POSIX.1-2008 */ _POSIX_VERSION: '200809', _POSIX2_VERSION: '200809', NGROUPS_MAX: '32', OPEN_MAX: '256', STREAM_MAX: '256', TZNAME_MAX: '32', _POSIX_CHOWN_RESTRICTED: '1', _POSIX_NO_TRUNC: '1', _POSIX_VDISABLE: '0', _POSIX_JOB_CONTROL: '0', _POSIX_SAVED_IDS: '0', /** Bare shell line length (reasonable REPL limit, not a hard kernel cap). */ BARE_OS_INPUT_LINE_MAX: '8192' } async function run(ctx, argv) { const args = argv.slice(1).filter((a) => a !== '--') let dumpAll = false let name = null for (const a of args) { if (a === '-a') dumpAll = true else if (!a.startsWith('-')) name = a else { ctx.console.error('getconf: unknown option: ' + a) ctx.exitCode = 1 return } } if (dumpAll) { for (const k of Object.keys(CONF).sort()) { ctx.console.log(k + '\n' + CONF[k]) } ctx.exitCode = 0 return } if (!name) { ctx.console.error('usage: getconf [-a] system_var') ctx.exitCode = 1 return } if (Object.prototype.hasOwnProperty.call(CONF, name)) { ctx.console.log(CONF[name]) ctx.exitCode = 0 return } ctx.console.error('getconf: ' + name + ': unknown variable') ctx.exitCode = 1 }