Class Kernel
Implements
- Kernel
Index
Constructors
Properties
Accessors
Methods
Constructors
constructor
-
Parameters
- _options: KernelOptions = DefaultKernelOptions
Returns Kernel
Properties
Readonlyauth
Readonlychannel
Broadcast channel for inter-kernel communication
Readonlycomponents
Web Components manager
Readonlydevices
Map of registered devices and their drivers
Readonlydom
DOM manipulation service
Readonlyevents
Event management system
Readonlyfilesystem
Virtual filesystem
Readonlyframebuffers
The framebuffers (/dev/fb<N>), each drawing in a window
Readonlyfstypes
The filesystem types mount -t knows: the built-in ones and those modules add
Readonlyhost
The environment this kernel runs in (browser or Node)
Readonlyi18n
Internationalization service
Readonlyid
Unique identifier for this kernel instance
Readonlyinit
pid 1: /sbin/init, which runs /etc/inittab, supervises its daemons and reaps orphans.
Readonlyintervals
Interval management service
Readonlykeyboard
Keyboard interface
Readonlykmodules
Loads and unloads modules (insmod, rmmod) and keeps their symbols
Readonlylog
Logging system
Readonlymachine
The machine this kernel runs (?machine=NAME); undefined is the default one. See lib/machine.ts.
Readonlymemory
Memory management service
Optional Readonlymodcatalog
The in-tree modules that are fetched when first asked for; undefined when options.modules is false
Readonlymodprobe
ReadonlymoduleBinfmts
The program formats modules added, which the shell asks about a file it does not know
Readonlymodules
The loaded modules, @zenfs/linux's list that /proc/modules shows
Readonlyname
Name of the kernel
Readonlyoptions
Configuration options passed to the kernel
Readonlypackages
Map of loaded packages
Readonlyprotocol
Protocol handler service
Readonlyscreensavers
string,
{
default: (options: { terminal: Terminal }) => Promise<void>;
exit: () => Promise<void>;
},
>
Map of available screensavers
Readonlyservice
Service management system
Readonlyshell
Shell for command interpretation and execution
Readonlysockets
Socket connection management service
Readonlystorage
Storage provider interface
Readonlysystem
The kernel's own shell, root's whoever is logged in: what runs init scripts, fstab mounts and cron jobs. No user's session is ever lent to the kernel for these. It shows on the console (TTY 0) but is not its shell.
Readonlytelemetry
Telemetry service for OpenTelemetry tracing
Readonlyterminal
Terminal interface for user interaction
Readonlyusers
User management service
Readonlyversion
Version string of the kernel
Readonlywasm
WebAssembly service
Readonlywindows
Window management service
Readonlyworkers
Web Worker management service
Accessors
activeTty
-
get activeTty(): number
Currently active TTY number
Returns number
addEventListener
context
-
get context(): KernelContext
The cross-cutting primitives a subsystem or driver may depend on, with no back-reference to the Kernel itself
Returns KernelContext
guest
-
get guest(): boolean
Whether this tab runs a guest session (a scratch machine in memory, nothing saved)
Returns boolean
hotplug
-
get hotplug(): {}
Nodes made and removed at runtime, for a package whose devices come and go.
addgivesdriverits node (the major is registered if no driver of the package's had it at boot), and the function it returns takes the node away: a file still open on it getsENODEV, as on Linux, until a device takes the minor again.Returns {}
pipeProcess
-
get pipeProcess(): Process
The kernel's own process, whose table holds the pipe ends no program does: bridges, and sockets' connections
Returns Process
programsRunAsUser
-
get programsRunAsUser(): boolean
Whether a user's programs run with that user's credentials, rather than all as root (see
canRunProgramsAsUser)Returns boolean
ready
-
get ready(): boolean
True once
whenReadyhas resolved.Returns boolean
removeEventListener
rescue
-
get rescue(): boolean
Booted in rescue mode (
KernelOptions.rescue,?rescue): a root shell and nothing elseReturns boolean
shells
state
-
get state(): KernelState
Current state of the kernel
Returns KernelState
Methods
applyTimeZone
-
Makes
name(an IANA zone, or undefined for the browser's) the system's zone: theTZthe kernel's shells give what they start from now on. A program already running, and a shell that set its ownTZ, keep theirs.Parameters
- name: string | undefined
Returns Promise<void>
attachStream
-
attachStream(
proc: Process,
direction: "read" | "write",
stream:
| ReadableStream<Uint8Array<ArrayBufferLike>>
| WritableStream<Uint8Array<ArrayBufferLike>>,
): { done: Promise<void>; fd: number; stop: () => void }Gives
proca new descriptor (lowest free from 3) that is one end of a pipe pumped againststream, and returns its number;'read'yields whatstreamproduces,'write'delivers to it. Used for kernel-side resources such as sockets.Parameters
- proc: Process
- direction: "read" | "write"
- stream:
| ReadableStream<Uint8Array<ArrayBufferLike>>
| WritableStream<Uint8Array<ArrayBufferLike>>
Returns { done: Promise<void>; fd: number; stop: () => void }
beginLogin
-
First half of a login on
ttyNumberfor/sbin/getty: tries a passkey. True whenusernameis already authenticated and no password is needed.Parameters
- ttyNumber: number
- username: string
Returns Promise<boolean>
boot
-
Boots the kernel and initializes all core services.
Parameters
- options: BootOptions = DefaultBootOptions
Boot configuration options
Returns Promise<void>
- options: BootOptions = DefaultBootOptions
configure
-
Configures kernel subsystems with the provided options
Parameters
- options: KernelOptions
Configuration options for kernel subsystems
Returns Promise<void>
- options: KernelOptions
createShell
endLogin
-
A login on
ttyNumberhas ended: the session record goes, and the shell holds no user until the next login.Parameters
- ttyNumber: number
Returns Promise<void>
execute
executeViaExecve
-
Runs a plain JS/ESM file as an isolated process through
@zenfs/linux'sexecve, with/bin/nodeas interpreter. Redirected stdio is wired throughbridgeStdio. A program cannot import modules itself.Parameters
- options: KernelExecuteOptions
the file path and shell
Returns Promise<number>
the process's exit code
- options: KernelExecuteOptions
finishLogin
-
finishLogin(
ttyNumber: number,
username: string,
password: string,
): Promise<
{
env: Record<string, string>;
gid: number;
groups: number[];
home: string;
shell: string;
uid: number;
username: string;
},
>Second half: authenticates (the passkey from
beginLogin, orpassword) and starts the session on the tty's shell. Resolves to what getty needs to run the user's shell; rejects with the message to show.Parameters
- ttyNumber: number
- username: string
- password: string
Returns Promise<
{
env: Record<string, string>;
gid: number;
groups: number[];
home: string;
shell: string;
uid: number;
username: string;
},
>
getPackageMainExport
-
Gets the main entry file path from a package.json
Parameters
- pkgData: JSONSchemaForNPMPackageJsonFiles
The parsed package.json data
Returns string | null
The main entry file path or null if not found
- pkgData: JSONSchemaForNPMPackageJsonFiles
getShell
-
Gets a shell by TTY number
Parameters
- ttyNumber: number
TTY number (0-7)
Returns Shell | undefined
Shell instance or undefined if not found
- ttyNumber: number
hasDisplay
-
Whether a display is attached to
ttyParameters
- tty: number
Returns boolean
linkProcesses
-
A directed
create_pipebetween two processes with no pump. A loopback socket connection is two of these, one per direction. Both ends are created onpipeProcessand eachHandlemoves to its process's table at the lowest free fd.Parameters
- fromProc: Process
- toProc: Process
Returns { readerFd: number; writerFd: number }
loadFstab
-
Loads and processes fstab entries from /etc/fstab.
Returns Promise<void>
A promise that resolves when fstab is processed.
loadQuotas
-
Reads
/etc/quotaand applies it (seelib/quota.ts); a bad line is reported and skipped. Returns the problems found.Returns Promise<string[]>
loginShell
notify
-
Shows a system notification if permissions are granted
Parameters
- title: string
Notification title
- options: NotificationOptions = {}
Notification options
Returns Promise<void | Notification>
The created notification or void if permissions denied
- title: string
off
-
Removes an event listener from the kernel.
Parameters
- event: KernelEvents
The event to remove the listener from.
- listener: EventCallback
The listener to remove.
Returns void
- event: KernelEvents
on
-
Adds an event listener to the kernel.
Parameters
- event: KernelEvents
The event to listen for.
- listener: EventCallback
The listener to add.
Returns void
- event: KernelEvents
openSession
-
openSession(
options: {
cols?: number;
onEnd?: () => void;
rows?: number;
username: string;
write: (data: string | Uint8Array<ArrayBufferLike>) => void;
},
): Promise<KernelSession>Opens a login on a terminal with no page, for a user already authenticated (by key, over a peer link). Takes the lowest free TTY of 1 to 7, starts the session and runs the built-in shell until
exit. Output goes tooptions.write; the caller feeds input tosession.terminal.Parameters
- options: {
cols?: number;
onEnd?: () => void;
rows?: number;
username: string;
write: (data: string | Uint8Array<ArrayBufferLike>) => void;
}
Returns Promise<KernelSession>
- options: {
openTerminalWindow
-
A window with a terminal emulator running a program (a login shell by default) on a pty; see
openTerminalWindow.Parameters
- options: TerminalWindowOptions
Returns Promise<TerminalWindow>
presentOnDisplay
-
presentOnDisplay(
tty: number,
kind: string,
params: Record<string, unknown>,
): RemoteCall | undefinedHas a browser call done by the display the user is at on
tty;undefinedwhen none is attached (seelib/remote-display.ts)Parameters
- tty: number
- kind: string
- params: Record<string, unknown>
Returns RemoteCall | undefined
processContext
-
The context a program started from
shellruns in: the shell's own user, orundefined(root) for a root shell or when the installed@zenfs/corecannot run programs as another user (seecanRunProgramsAsUser).Parameters
- shell: Shell
- cwd: string
Optionalprogram: string
Returns BoundContext | undefined
ptyLogin
-
ptyLogin(
username: string,
password: string,
): Promise<
{
env: Record<string, string>;
gid: number;
groups: number[];
home: string;
shell: string;
uid: number;
username: string;
},
>A login on a pty, for
/bin/login -p: authenticates and resolves to what the login needs to start the user's shell on the terminal it already has. There is noShellbehind a pty, so no session record and no startup files here; the login shell reads its own.Parameters
- username: string
- password: string
Returns Promise<
{
env: Record<string, string>;
gid: number;
groups: number[];
home: string;
shell: string;
uid: number;
username: string;
},
>
readFileHeader
-
Reads and parses a file header to determine its type
Parameters
- filePath: string
Path to the file
Optionalshell: ShellOptional shell instance to use for filesystem operations
Returns Promise<FileHeader | null>
Parsed header information or null if invalid
- filePath: string
reboot
-
Reboots the kernel by performing a shutdown and page reload
Returns Promise<void>
registerCommands
-
Registers the terminal commands.
Returns Promise<void>
A promise that resolves when the terminal commands are registered.
registerDevices
-
Registers the devices.
char_dev.registerclaims a whole major for oneFileOperations, so packages returning several KernelCharDevices under one major are registered once, with a dispatcher that routes by minor.Returns Promise<void>
registerEvents
-
Registers the kernel events.
Returns Promise<void>
A promise that resolves when the events are registered.
registerPackages
-
Registers the packages from /etc/packages that should be auto-loaded on boot.
Returns Promise<void>
A promise that resolves when the packages are registered.
registerScreensavers
-
Discovers the built-in screensavers. An
import.meta.globresolved at build time relative to this file, so it cannot move out ofKernelthe waystartScreensaverDaemondid.Returns void
replaceImports
-
Replaces imports in a script with SWAPI URLs (import maps cannot be dynamic).
Parameters
- contents: string
the script contents
- packagePath: string
Returns Promise<string>
- contents: string
requestModule
-
request_module: the kernel asks for a module by alias (fs-zipwhenmount -t zipmeets a type nobody has) andmodprobeloads it, as root, whoever asked. True if the alias named a module and it loaded.Parameters
- alias: string
Returns Promise<boolean>
requestReboot
-
Asks init to reboot, the way the
rebootcommand does, so everything is stopped in order first. Straight to reboot when init is not running, or when it has not taken the system down within 15 seconds, so a wedged init cannot make the keyboard shortcut useless.Returns void
runDetached
-
Runs a program as a user on a pty nothing watches; see
runDetached.Parameters
- options: DetachedOptions
Returns Promise<number>
shellAsProcess
-
shellAsProcess(
proc: {
context: { credentials: Credentials; pwd: string };
env: Record<string, string | undefined>;
},
): ShellA shell that acts as the user of
proc, for a DOM app that process started from a shell of its own (su, a login's child): the app runs its commands through this, so they run as that user and not as the kernel's root shell. It has no terminal of its own; what it runs writes where the app tells it to.Parameters
- proc: {
context: { credentials: Credentials; pwd: string };
env: Record<string, string | undefined>;
}
Returns Shell
- proc: {
shellForTty
shellOfPid
-
The shell whose own process is
pid(what$$names), if any.Parameters
- pid: number
Returns Shell | undefined
shutdown
spawnOnPty
startScreensaverDaemon
-
Starts the idle screensaver daemon: shows
localStorage['screensaver'](defaultmatrix) afterlocalStorage['screensaver-timeout']ms (default 60000) of inactivity. Started by/boot/initthroughscreensaver-daemon.Returns (() => void) | undefined
a function that stops the daemon, or undefined if the screensaver is not registered
startSession
-
startSession(
shell: Shell,
user: User,
cred: Credentials,
options?: { startupFiles?: boolean },
): Promise<void>Makes
userthe login onshell: credentials, bound context, identity variables, the session record, the home directory, then the startup files in order. The one place a login takes effect, shared by the built-in login prompt, auto-login, and/sbin/gettythroughlogin_session.Parameters
- shell: Shell
- user: User
- cred: Credentials
Optionaloptions: { startupFiles?: boolean }
Returns Promise<void>
stop
-
What init does last:
rebootshuts down and reloads the page,haltonly shuts down,poweroffshuts down and then tries to close the page (best effort; browsers only close windows a script opened).Parameters
- mode: "reboot" | "halt" | "poweroff"
Returns Promise<void>
switchTty
-
Switches to a different TTY
Parameters
- ttyNumber: number
TTY number to switch to (0-7)
Returns Promise<void>
- ttyNumber: number
tryPasskeyLogin
-
tryPasskeyLogin(
terminal: { writeln(text: string): void },
username: string,
): Promise<{ cred: Credentials; user: User } | null>The passkey half of a login: when
usernamehas passkeys and the browser supports them, asks for one and returns the session it yields. Null means "ask for a password" (no such user, no passkey, or the attempt was cancelled or failed, which is said onterminal).Parameters
- terminal: { writeln(text: string): void }
- username: string
Returns Promise<{ cred: Credentials; user: User } | null>
whenProgramsReady
-
Resolves when the catalog's programs are installed (or have failed), which boot does not wait for. Until then a program not installed before is a placeholder that waits for it.
Returns Promise<void>
whenReady
-
Resolves when boot has finished, including the first-boot prompts a login prompt must not interleave with.
Returns Promise<void>
Authentication and authorization service