-
Notifications
You must be signed in to change notification settings - Fork 0
FileSystemType
Interface for filesystem driver plugins with mount/detection.
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.
| 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 |
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.
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).
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.
During boot, FileSystemMounter performs automatic filesystem detection:
- Iterates through all registered
FileSystemTypeinstances - For
BlockDeviceFileSystemType, callssupports()with the partition's first sector - If detection succeeds, calls
create()to instantiate the filesystem - Mounts the filesystem into the VFS namespace
This enables transparent mounting of all supported filesystems without manual configuration.
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);
}
}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 |
-
Detection reliability: The
supports()method must be fast and deterministic. It should only returntrueif 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
FileSystemMounterdetermines 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 avoidClassCastException. -
Network filesystems: Non-block filesystems (NFS, SMB, FTP) don't use
BlockDeviceFileSystemTypeand must be mounted explicitly rather than auto-detected.
- VFS-Layer — How FileSystemType integrates with the Virtual File System
- Filesystem-Layer — Overview of the entire filesystem stack
- Plugin-System — How filesystem plugins are declared and loaded
- FAT-Filesystem — Example block device filesystem implementation
- Ext2-Ext3-Filesystem — Another block device filesystem example
- Block-Device-Layer — Block device drivers that provide devices to FileSystemType