-
Notifications
You must be signed in to change notification settings - Fork 0
Partition Tables
Partition table parsing and creation for different disk formats.
JNode supports multiple partition table formats, enabling compatibility with disks partitioned by various operating systems. The partition table system provides a unified interface for detecting, reading, and traversing partitions regardless of the underlying format.
The three main partition table formats supported are:
- IBM MBR (Master Boot Record) - The traditional PC partition scheme, supporting up to 4 primary partitions or 3 primary + 1 extended partition
- GPT (GUID Partition Table) - The modern standard for UEFI-based systems, supporting practically unlimited partitions and larger disks
- APM (Apple Partition Map) - Used by older Mac systems
Partition tables are discovered and parsed through the PartitionTableType interface, which provides a plugin-based mechanism for supporting new formats.
| Class / File | Role |
|---|---|
fs/src/partitions/org/jnode/partitions/PartitionTable.java |
Generic interface for all partition tables |
fs/src/partitions/org/jnode/partitions/PartitionTableEntry.java |
Interface for partition entries |
fs/src/partitions/org/jnode/partitions/PartitionTableType.java |
Interface for partition table type detection/creation |
fs/src/partitions/org/jnode/partitions/ibm/IBMPartitionTable.java |
IBM MBR partition table implementation |
fs/src/partitions/org/jnode/partitions/ibm/IBMPartitionTableEntry.java |
IBM MBR partition entry |
fs/src/partitions/org/jnode/partitions/ibm/IBMPartitionTableType.java |
IBM MBR type detection |
fs/src/partitions/org/jnode/partitions/ibm/IBMPartitionTypes.java |
MBR partition type constants |
fs/src/partitions/org/jnode/partitions/gpt/GptPartitionTable.java |
GPT partition table implementation |
fs/src/partitions/org/jnode/partitions/gpt/GptPartitionTableEntry.java |
GPT partition entry |
fs/src/partitions/org/jnode/partitions/gpt/GptPartitionTableType.java |
GPT type detection |
fs/src/partitions/org/jnode/partitions/apm/ApmPartitionTable.java |
Apple Partition Map implementation |
fs/src/partitions/org/jnode/partitions/apm/ApmPartitionTableEntry.java |
APM partition entry |
fs/src/partitions/org/jnode/partitions/service/def/PartitionTablePlugin.java |
Plugin exposing partition services |
The partition table system follows a plugin-based architecture:
PartitionTableType (interface)
├── IBMPartitionTableType
├── GptPartitionTableType
└── ApmPartitionTableType
Each PartitionTableType implementation provides:
-
getName()- Unique identifier for the partition type -
supports(byte[] firstSectors, BlockDeviceAPI)- Detection whether a disk uses this format -
create(byte[] firstSectors, Device)- Creates aPartitionTableinstance
The MBR is stored in the first sector (512 bytes) of a disk. Detection checks for multiple signatures:
-
Magic number:
0xAA55at offset 510 - Extended signatures: Various vendor-specific signatures (AST, Disk Manager, LILO, HP, etc.)
- Error message strings: DOS/Windows/BSD/GRUB boot code error messages
- Fallback: If no signature matches, validates that partition entries don't overlap and at least one is valid
// From IBMPartitionTable.containsPartitionTable()
if (LittleEndian.getUInt16(bootSector, 510) != 0xaa55) {
return false;
}
// ... check extended signatures ...
// ... check boot code strings ...
// ... validate partition entries ...MBR supports:
- 4 primary partition entries (16 bytes each at offsets 446-509)
- Extended partitions via linked EBR (Extended Boot Record) chains
- Partition types identified by 1-byte system indicator
GPT uses a protective MBR in sector 0 followed by the GPT header:
-
Protective MBR: Contains a single partition of type
0xEE(EFI GPT) - GPT Header: Located at LBA 1, starts with "EFI PART" signature
- Partition Array: Follows header, contains 128-byte entry blocks
// From GptPartitionTable.detectBlockSize()
String signature = new String(signatureBytes, Charset.forName("US-ASCII"));
if ("EFI PART".equals(signature)) {
return blockSize;
}GPT requires reading the first 16KB of disk to detect and parse partitions.
All partition entries implement PartitionTableEntry:
public interface PartitionTableEntry {
boolean isValid();
boolean hasChildPartitionTable();
PartitionTable<?> getChildPartitionTable();
}This enables recursive partition traversal - useful for extended MBR partitions and LVM-style nested partition tables.
-
GPT requires larger initial read: Unlike MBR (512 bytes), GPT detection requires reading at least 16KB to access the partition array.
-
Protective MBR: GPT disks still contain a protective MBR for backward compatibility with legacy BIOS. The
GptPartitionTable.containsPartitionTable()method can optionally require this protective MBR. -
Extended partition chain: MBR extended partitions form a linked chain where each EBR points to the next. The
IBMPartitionTablerecursively traverses this chain inhandleExtended(). -
Multiple detection signatures: The MBR detector checks for ~20 different signatures. A disk with boot code can still have a valid partition table.
-
Partition type vs filesystem: MBR partition type (system indicator) identifies the partition scheme, not the filesystem. A type of
0x83(Linux) doesn't guarantee ext2/ext3 - it's just a convention. -
Overlapping partition detection: The MBR validator explicitly checks for overlapping entries and rejects the table if found.
-
APM structure: APM stores partition entries starting at offset 0x200, with a counter at 0x204 indicating the number of entries.
- BlockDeviceLayer - Block device abstraction, partition mapping
- Filesystem-Layer - Filesystem drivers, partition tables integration
- VFS-Layer - Virtual filesystem, mount mechanism
- IDEDisk-Driver - ATA/IDE disk driver, partition detection
- Boot-Sequence - Boot process, how partitions are used during boot