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 / File Location Purpose
FileSystemType fs/src/fs/org/jnode/fs/FileSystemType.java Core interface: factory for filesystem instances
BlockDeviceFileSystemType fs/src/fs/org/jnode/fs/BlockDeviceFileSystemType.java Subinterface for block devices with detection
FileSystemTypeManager fs/src/fs/org/jnode/fs/service/def/FileSystemTypeManager.java Manages registered FileSystemType plugins
FileSystemMounter fs/src/fs/org/jnode/fs/service/def/FileSystemMounter.java Uses FileSystemType for auto-mount at boot
FileSystemPlugin fs/src/fs/org/jnode/fs/service/def/FileSystemPlugin.java Plugin entry point that loads FileSystemTypes
AbstractFileSystem fs/src/fs/org/jnode/fs/spi/AbstractFileSystem.java Base class for filesystem implementations

How It Works

Core Interface

The FileSystemType interface is minimal by design:

public interface FileSystemType<T extends FileSystem<?>> {
    String getName();
    T create(Device device, boolean readOnly) throws FileSystemException;
}

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:

public interface BlockDeviceFileSystemType<T extends FileSystem<?>> extends FileSystemType<T> {
    boolean supports(PartitionTableEntry pte, byte[] firstSector, FSBlockDeviceAPI devApi);
}

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:

<extension point="org.jnode.fs.service.fs types">
    <type name="fat" class="org.jnode.fs.fat.FatFileSystemType"/>
    <type name="ext2" class="org.jnode.fs.ext2.Ext2FileSystemType"/>
    <type name="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)
public class RAMFileSystemType implements FileSystemType<RAMFileSystem> {
    public static final Class<RAMFileSystemType> ID = RAMFileSystemType.class;
    
    public String getName() { return "ramfs"; }
    
    public RAMFileSystem create(Device device, boolean readOnly) throws FileSystemException {
        return new RAMFileSystem(device, readOnly, DEFAULT_MAX_SIZE, this);
    }
}

// Block device filesystem
public class FatFileSystemType implements BlockDeviceFileSystemType<FatFileSystem> {
    public static final Class<FatFileSystemType> ID = FatFileSystemType.class;
    
    public String getName() { return "fat"; }
    
    public boolean supports(PartitionTableEntry pte, byte[] firstSector, FSBlockDeviceAPI devApi) {
        // Check FAT boot sector signature (0x55AA at offset 510)
        return firstSector[510] == (byte)0x55 && firstSector[511] == (byte)0xAA;
    }
    
    public FatFileSystem create(Device device, boolean readOnly) throws FileSystemException {
        return new FatFileSystem(device, readOnly, this);
    }
}

Implemented Filesystems

JNode includes filesystem drivers for:

Filesystem Class Type
FAT12/16/32 FatFileSystemType BlockDevice
ext2/ext3 Ext2FileSystemType BlockDevice
NTFS NTFSFileSystemType BlockDevice
ISO 9660 ISO9660FileSystemType BlockDevice
exFAT ExFatFileSystemType BlockDevice
HFS+ HfsPlusFileSystemType BlockDevice
RAM FS RAMFileSystemType Virtual
JIFS (Java JIFileSystemType Virtual
JAR FS JarFileSystemType Virtual
NFS NFS2FileSystemType Network
SMB/CIFS SMBFileSystemType Network
FTP FTPFileSystemType Network

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