-
Notifications
You must be signed in to change notification settings - Fork 0
VFS Layer
The in-memory Virtual File System that unifies all mounted filesystems into a single namespace, exposing standard Java
Fileoperations.
JNode implements a Virtual File System (VFS) as an in-memory tree that aggregates all mounted filesystems. The VFS lives entirely in Java and is integrated with the standard Java I/O APIs via a custom FileSystem implementation. When an application calls new FileInputStream("/hd0a/data/file.txt"), the path is resolved through the VFS to find the appropriate filesystem driver.
| Class/File | Location | Purpose |
|---|---|---|
FileSystemPlugin |
fs/src/fs/org/jnode/fs/service/def/ |
Plugin entry point; registers VFS as a service via InitialNaming
|
FileSystemService |
fs/src/fs/org/jnode/fs/service/ |
Interface for filesystem registration, mount points, and lookup |
FileSystemManager |
fs/src/fs/org/jnode/fs/service/def/ |
Tracks registered FileSystem instances by device |
FileSystemTypeManager |
fs/src/fs/org/jnode/fs/service/def/ |
Manages registered FileSystemType plugins (via extension point) |
FileSystemMounter |
fs/src/fs/org/jnode/fs/service/def/ |
Auto-mounts filesystems from plugin extensions at startup |
VirtualFS |
fs/src/fs/org/jnode/fs/service/def/ |
The VFS itself; implements FileSystem<VirtualDirEntry>
|
VirtualDirEntry |
fs/src/fs/org/jnode/fs/service/def/ |
A directory node in the VFS tree; contains a TreeMap of child entries |
VirtualMountEntry |
fs/src/fs/org/jnode/fs/service/def/ |
A VFS entry that delegates to a mounted filesystem's root or subdirectory |
FileSystemType |
fs/src/fs/org/jnode/fs/ |
Interface: factory for creating FileSystem instances from a Device
|
FileSystem |
fs/src/fs/org/jnode/fs/ |
Interface: represents a mounted filesystem (root entry, space info, device) |
FSEntry |
fs/src/fs/org/jnode/fs/ |
Interface: a file or directory entry in a filesystem |
FSDirectory |
fs/src/fs/org/jnode/fs/ |
Interface: directory node (iterator, getEntry, addDirectory, flush) |
FSFile |
fs/src/fs/org/jnode/fs/ |
Interface: file read/write operations |
The VFS is built when FileSystemPlugin.startPlugin() is called:
-
FileSystemPlugincreates aVirtualFSDeviceand registers it with theDeviceManager. - It creates a
VirtualFSinstance backed by this device. -
FileSystemMounterscans plugin extensions for thetypesextension point. - For each
FileSystemTypeextension, the mounter probes the corresponding block device. - If a valid filesystem signature is detected, a
FileSysteminstance is created and mounted. -
VirtualDirEntry.addMount(name, fs, path)creates aVirtualMountEntryin the VFS tree.
The VFS namespace is exposed to the VM via VMIOUtils.setAPI(getApi(), this), wiring JNode's FileSystemService into the standard Java I/O layer.
FileSystemType is the factory interface that every filesystem driver implements:
public interface FileSystemType<T extends FileSystem<?>> {
String getName();
T create(Device device, boolean readOnly) throws FileSystemException;
}Each concrete filesystem (e.g., FatFileSystemType) extends FileSystemType<FSDirectory> and:
- Declares a plugin extension in its descriptor XML via the
typesextension point. - Implements
create()to probe the device for a filesystem signature, then instantiate the driver.
FileSystemTypeManager loads these extensions at plugin startup and provides getSystemType(Class<T>) for lookup by type.
When a Java application opens a file:
- The standard Java
FileAPI delegates to JNode'sVMFileSystemAPI. -
FileSystemServicereceives the absolute path (e.g.,/hd0a/data/file.txt). - The path is tokenized:
["hd0a", "data", "file.txt"]. -
VirtualFS.getRootEntry()returns the VFS root (VirtualDirEntryat/). -
getEntry("hd0a")returns aVirtualMountEntrypointing to the physical filesystem's root. -
getEntry("data")delegates into the mounted filesystem'sFSDirectory, returning the actual directory entry. -
getEntry("file.txt")resolves to the fileFSEntry.
flowchart TD
Java["new FileInputStream('/hd0a/data/file.txt')"]
VMIO["VMIOUtils → FileSystemService"]
VFS["VirtualFS root /"]
VME["VirtualMountEntry 'hd0a'"]
FS["FatFileSystem on /dev/hd0a"]
Sub["FSDirectory 'data'"]
File["FSFile 'file.txt'"]
Java --> VMIO --> VFS
VFS -->|getEntry("hd0a")| VME
VME -->|delegates| FS
FS -->|getEntry("data")| Sub
Sub -->|getEntry("file.txt")| File
A typical filesystem driver follows this pattern:
-
SPI package (
org.jnode.fs.spi.*): ProvidesAbstractFSObject,AbstractFSDirectory,AbstractFSFile,AbstractFSEntrybase classes that implement the JNode FS interfaces. -
Concrete package (e.g.,
org.jnode.fs.fat): Contains theFatFileSystemType,FatFileSystem,FatDirectory,FatFileclasses.
public class FatFileSystemType extends FileSystemType<FSDirectory> {
public String getName() { return "fat"; }
public FatFileSystem create(Device device, boolean readOnly) throws FileSystemException {
return new FatFileSystem(device, readOnly);
}
}- The VFS tree is completely in-memory. Rebooting clears all mounted state. Filesystems are re-mounted automatically at each boot via
FileSystemMounterscanning plugin extensions. -
VirtualMountEntryoptionally supports mounting a subdirectory of the target filesystem (thefsPathparameter inmount()). This allows mounting/dev/hd0a/bootat/bootin the VFS namespace. -
VirtualDirEntryuses aTreeMap<String, FSEntry>for child entries, enforcing alphabetical ordering. This provides deterministic iteration but limits scalability for very large directories. - Path resolution is string-based; there is no symbolic link support in the VFS layer itself (symbolic links are handled by individual filesystem drivers if supported).
-
FileSystemPluginbinds itself toInitialNamingasFileSystemService.class. Services that need filesystem access look it up viaInitialNaming.get(NAME, FileSystemService.class).
- Filesystem-Layer — Overview of the entire FS stack (block drivers → partitions → filesystems → VFS)
- Driver-Framework — How block devices are registered with the DeviceManager
-
Plugin-System — How
FileSystemTypeplugins are declared and loaded - FileHandle-Implementation — File handle tracking and position management
- FSEntry-Cache — Caching layer for FSEntry objects to reduce filesystem lookups