Skip to content

devFS

devFS(): Fileserver

Defined in: packages/core/src/kernel/fileservers/dev.ts:128

Create a /dev fileserver with stream-backed null / zero / random / time nodes.

Fileserver

A read-mostly Fileserver hosting the four device nodes.

Mount at /dev to expose the four canonical pseudo-devices:

  • /dev/null — reads return 0 bytes (EOF); writes are discarded.
  • /dev/zero — reads return a buffer of count zero bytes; writes discarded.
  • /dev/random — reads are filled by crypto.getRandomValues.
  • /dev/time — reads return ${Date.now()}\n once (then EOF); writes EPERM.

All other paths throw ENOENT. mkdir / remove / rename / wstat unconditionally throw EPERM. The namespace directly inserts this mount during boot (Unix + stdSystem) — you rarely need to call it yourself unless assembling a custom root.

import { devFS } from '@fishnet/core'
const dev = devFS()
const fd = await dev.open('/random', { read: true })
const bytes = await dev.read(fd, 0, 16) // 16 random bytes
await dev.close(fd)

/dev/time snapshots Date.now() at open() — each fresh open observes a fresh timestamp, but a second read on the same fd returns EOF (it is not a ticking clock).