Skip to content

FileSystemType

opencode-agent[bot] edited this page May 10, 2026 · 1 revision

FileSystemType Interface

Interface for filesystem driver plugins with mount/detection.

Overview

FileSystemType is the core plugin interface that all filesystem drivers must implement to integrate with JNode's VFS layer. It serves as both a factory for creating filesystem instances and, through its subinterface BlockDeviceFileSystemType, a mechanism for automatic filesystem detection on block devices.

The interface defines two key operations: providing a unique filesystem name, and creating a filesystem instance from a device. Implementations are loaded via JNode's plugin system, registered with the FileSystemTypeManager, and used by the FileSystemMounter during boot to automatically detect and mount filesystems.

Key Components

Class / FileLocationPurpose
FileSystemTypefs/src/fs/org/jnode/fs/FileSystemType.javaCore interface: factory for filesystem instances
BlockDeviceFileSystemTypefs/src/fs/org/jnode/fs/BlockDeviceFileSystemType.javaSubinterface for block devices with detection
FileSystemTypeManagerfs/src/fs/org/jnode/fs/service/def/FileSystemTypeManager.javaManages registered FileSystemType plugins
FileSystemMounterfs/src/fs/org/jnode/fs/service/def/FileSystemMounter.javaUses FileSystemType for auto-mount at boot
FileSystemPluginfs/src/fs/org/jnode/fs/service/def/FileSystemPlugin.javaPlugin entry point that loads FileSystemTypes
AbstractFileSystemfs/src/fs/org/jnode/fs/spi/AbstractFileSystem.javaBase class for filesystem implementations

How It Works

Core Interface

The FileSystemType interface is minimal by design:

publicinterfaceFileSystemType<TextendsFileSystem<?>> {
StringgetName();
Tcreate(Devicedevice, booleanreadOnly) throwsFileSystemException;
}

The getName() method returns a unique identifier for the filesystem (e.g., "fat", "ext2", "ntfs"). The create() method is called to instantiate the filesystem driver, typically after successful detection on a device.

Block Device Filesystem Detection

For filesystems that reside on block devices (hard drives, USB sticks, etc.), the BlockDeviceFileSystemType subinterface adds detection capability:

publicinterfaceBlockDeviceFileSystemType<TextendsFileSystem<?>> extendsFileSystemType<T> {
booleansupports(PartitionTableEntrypte, byte[] firstSector, FSBlockDeviceAPIdevApi);
}

The supports() method examines the first sector of a partition to determine if the filesystem can operate on it. This typically involves checking for magic bytes or specific on-disk structures (e.g., FAT boot sector signature, ext2 superblock magic).

Plugin Registration

Filesystem drivers declare themselves as plugin extensions:

<extensionpoint="org.jnode.fs.service.fs types">
<typename="fat"class="org.jnode.fs.fat.FatFileSystemType"/>
<typename="ext2"class="org.jnode.fs.ext2.Ext2FileSystemType"/>
<typename="ntfs"class="org.jnode.fs.ntfs.NTFSFileSystemType"/>
</extension>

At plugin startup, FileSystemTypeManager loads these extensions and makes them available for filesystem mounting operations.

Auto-Mount Workflow

During boot, FileSystemMounter performs automatic filesystem detection:

  1. Iterates through all registered FileSystemType instances
  2. For BlockDeviceFileSystemType, calls supports() with the partition's first sector
  3. If detection succeeds, calls create() to instantiate the filesystem
  4. Mounts the filesystem into the VFS namespace

This enables transparent mounting of all supported filesystems without manual configuration.

Implementation Pattern

Concrete filesystems extend either FileSystemType directly (for virtual/network filesystems) or BlockDeviceFileSystemType (for block device filesystems):

// Virtual filesystem (RAM disk, network mount)publicclassRAMFileSystemTypeimplementsFileSystemType<RAMFileSystem> {
publicstaticfinalClass<RAMFileSystemType> ID = RAMFileSystemType.class;
publicStringgetName() { return"ramfs"; }
publicRAMFileSystemcreate(Devicedevice, booleanreadOnly) throwsFileSystemException {
returnnewRAMFileSystem(device, readOnly, DEFAULT_MAX_SIZE, this);
}
}
// Block device filesystempublicclassFatFileSystemTypeimplementsBlockDeviceFileSystemType<FatFileSystem> {
publicstaticfinalClass<FatFileSystemType> ID = FatFileSystemType.class;
publicStringgetName() { return"fat"; }
publicbooleansupports(PartitionTableEntrypte, byte[] firstSector, FSBlockDeviceAPIdevApi) {
// Check FAT boot sector signature (0x55AA at offset 510)returnfirstSector[510] == (byte)0x55 && firstSector[511] == (byte)0xAA;
}
publicFatFileSystemcreate(Devicedevice, booleanreadOnly) throwsFileSystemException {
returnnewFatFileSystem(device, readOnly, this);
}
}

Implemented Filesystems

JNode includes filesystem drivers for:

FilesystemClassType
FAT12/16/32FatFileSystemTypeBlockDevice
ext2/ext3Ext2FileSystemTypeBlockDevice
NTFSNTFSFileSystemTypeBlockDevice
ISO 9660ISO9660FileSystemTypeBlockDevice
exFATExFatFileSystemTypeBlockDevice
HFS+HfsPlusFileSystemTypeBlockDevice
RAM FSRAMFileSystemTypeVirtual
JIFS (JavaJIFileSystemTypeVirtual
JAR FSJarFileSystemTypeVirtual
NFSNFS2FileSystemTypeNetwork
SMB/CIFSSMBFileSystemTypeNetwork
FTPFTPFileSystemTypeNetwork

Gotchas

  • Detection reliability: The supports() method must be fast and deterministic. It should only return true if the filesystem is almost certainly present, as incorrect detection can corrupt data.
  • Multiple filesystem support: Several filesystems may support the same media type. The detection order in FileSystemMounter determines which takes precedence.
  • Plugin loading order: Filesystem plugins must load early in the boot sequence to ensure filesystems are available for mounting root and other critical paths.
  • Type parameter safety: The generic type parameter T extends FileSystem<?> ensures type-safe filesystem creation but requires careful implementation to avoid ClassCastException.
  • Network filesystems: Non-block filesystems (NFS, SMB, FTP) don't use BlockDeviceFileSystemType and must be mounted explicitly rather than auto-detected.

Related Pages

Clone this wiki locally