Skip to content

EarlyMount Plugin

opencode-agent[bot] edited this page Nov 29, 2026 · 1 revision

Early Mount Plugin

org.jnode.fs.earlymount.EarlyMountPlugin mounts one configured partition synchronously during plugin startup, so the mount exists before the shell and jnode.ini run.

Overview

FileSystemMounter auto-mounts partitions from a deviceStarted listener, which fires on the worker thread that registers the partition device. That path is timing dependent: it has no replay and no retry, so whether a given partition is mounted before the shell starts depends on how the asynchronous PCI scan and device registration interleave.

EarlyMountPlugin (fs/src/fs/org/jnode/fs/earlymount/EarlyMountPlugin.java) removes that race for one particular filesystem. It is an auto-start plugin whose startPlugin() polls for a deterministic device id, creates a JFAT filesystem, mounts it at a stable mount point, and returns only when the mount is in place. Because plugin startup is on the boot path, the mount is guaranteed before the shell (and therefore jnode.ini).

The plugin was added in 2026-11 together with a claim registry (EarlyMountClaims) and a serialization change in FileSystemMounter, so the plugin's mount is the first and only attempt for the claimed device.

Key Components

Class / File Role
fs/src/fs/org/jnode/fs/earlymount/EarlyMountPlugin.java Polls for the device, creates/mounts a JFAT filesystem, parses configuration
fs/src/fs/org/jnode/fs/service/def/EarlyMountClaims.java Static set of claimed device ids; claim/release/isClaimed
fs/src/fs/org/jnode/fs/service/def/FileSystemMounter.java Auto-mounter; tryToMount skips claimed devices and serializes on the device monitor
fs/src/fs/org/jnode/fs/service/def/FileSystemAPIImpl.java mountPoints is a synchronized map so concurrent mounts cannot interleave
fs/descriptors/org.jnode.fs.earlymount.xml Auto-start plugin descriptor, requires org.jnode.fs.jfat, exports org.jnode.fs.earlymount.*
all/conf/default-plugin-list.xml Adds the plugin to the default set
fs/src/test/org/jnode/fs/earlymount/EarlyMountPluginTest.java 7 tests: claim lifecycle, bounded wait, type selection, mount, legacy replacement, cmdline config
fs/src/test/org/jnode/fs/earlymount/EarlyMountClaimsTest.java 4 tests for the claim registry
fs/src/test/org/jnode/fs/service/def/FileSystemMounterClaimTest.java 2 tests for the mounter's claim skip

How It Works

Configuration

No configuration means the plugin is a no-op. Configuration comes from the kernel command line or system properties:

Source Meaning
Kernel token earlymount=<device>[:<mountpoint>] e.g. earlymount=hda0:/data; the mount point defaults to /mnt/<device>
jnode.earlymount.device Overrides the command-line device
jnode.earlymount.mountpoint Overrides the command-line mount point
jnode.earlymount.readonly Mount read-only (default false)
jnode.earlymount.required If true, a missing device or failed mount fails plugin startup (default false)
jnode.earlymount.timeout Device-wait timeout in seconds (default 30)

Config.parse() reads the properties first, then falls back to the earlymount= token split at the first :. Paths are normalized to an absolute form without a trailing slash. The descriptor grants read access to jnode.cmdline and jnode.earlymount.* plus RuntimePermission getClassLoader.

The device-claim protocol

Device discovery is asynchronous: requiring org.jnode.driver.finder only guarantees the finder plugin has run, not that devices exist, because the PCI scan itself runs on a WorkManager worker thread. The mounter's deviceStarted listener would normally win the race against startPlugin().

To make the early mount first, startPlugin() claims the device id before the device can appear:

EarlyMountClaims.claim(cfg.deviceId);
try {
    doMount(cfg);
} finally {
    EarlyMountClaims.release(cfg.deviceId);
}

FileSystemMounter.tryToMount checks EarlyMountClaims.isClaimed(deviceId) and skips a claimed device, so its own attempt never fires. The claim is held only for the duration of startPlugin(); once the plugin has mounted or given up, later device starts fall back to normal mounter behaviour.

Bounded device wait

doMount() polls DeviceManager.getDevice(deviceId) every POLL_INTERVAL_MS = 100 ms until the device appears or the deadline passes:

  • The deadline is now + getTimeoutMs(), where DEFAULT_TIMEOUT_SECS = 30 and jnode.earlymount.timeout overrides it when it parses as a positive number.
  • The first miss logs EarlyMount: waiting for device …; the first success logs EarlyMount: device … appeared.
  • A timeout throws DeviceNotFoundException, which becomes a warning (or a PluginException when required=true).

Blocking inside startPlugin() is safe: the scan continues on the worker threads while the boot thread waits. In practice the device appears within ~1–2 s under both QEMU TCG and VBox; the 30 s default only matters when the device is genuinely absent.

Mounting

doMount() synchronizes on the Device object — the same monitor FileSystemMounter.tryToMount uses — so the check-create-register-mount sequence cannot interleave with the auto-mounter:

  1. Look up an existing filesystem for the device (fss.getFileSystem(dev)) and its current mount point (fss.getDeviceMountPoints()).
  2. If an existing filesystem is not JFAT (the legacy fat driver claimed a FAT12/16 partition), unmount it if mounted, unregister it, and discard the instance.
  3. If no filesystem exists, create one through FatFileSystemType.create(dev, readOnly) and register it.
  4. If the device is already mounted at the configured path, log and return; otherwise mkdirs() the parent path and fss.mount(mountPoint, fs, null).

The result is deterministic: the mounted filesystem is always JFAT, even when the legacy FAT driver got there first. stopPlugin() deliberately does nothing — unmounting on plugin stop would break everything already using the filesystem.

Concurrency fix in the mounter

FileSystemMounter.tryToMount now serializes its check-create-register-mount sequence on the device object, and FileSystemAPIImpl.mountPoints is a synchronized map. Without that, concurrent mounts (for example USB hub-monitor threads) could create two filesystem instances on one device. The early-mount plugin relies on the same device monitor.

Gotchas & Non-Obvious Behavior

  • The claim must be registered before the device exists. If the device is already present and the mounter has fired, the claim is too late; the plugin then reuses the mounter's instance and mounts it at the configured path as well.
  • One filesystem instance can have two mount points. When a device is mounted both at /devices/hda0 and the configured path, unmounting either path closes it for both.
  • The mount point defaults to /mnt/<device>. A device id is not a path; do not pass hda0 where a mount point is expected without the : separator.
  • required=false hides failures. A missing device only logs an error and the boot continues; set jnode.earlymount.required=true when the mount is load-bearing.
  • Only JFAT is forced. The plugin is not a general filesystem mount point; it always creates a FatFileSystemType instance.
  • Polling, not event replay. There is no listener registration; the plugin repeatedly calls getDevice until the deadline.
  • stopPlugin() does not unmount. The mount outlives the plugin.

Related Pages

Clone this wiki locally