- 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:
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.
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).
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.
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)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);
}
}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