Class Disklabel
java.lang.Object
oshi.driver.common.unix.bsd.disk.Disklabel
Utility class parsing partition information from the BSD
disklabel command. Shared by OpenBSD and NetBSD,
which produce the same disklabel output format.-
Method Summary
Modifier and TypeMethodDescriptiongetDiskParams(String diskName) Gets disk and partition information by runningdisklabeland parsing its output.parseDfFallback(String diskName, List<String> dfLines, BiFunction<String, String, Pair<Integer, Integer>> majorMinorLookup) Parsesdfoutput as a fallback whendisklabelreturns no partitions (typically because the caller lacks root privileges).parseDiskParams(String diskName, List<String> disklabelLines, BiFunction<String, String, Pair<Integer, Integer>> majorMinorLookup) Parsesdisklabel -noutput to extract disk metadata and partitions.
-
Method Details
-
getDiskParams
Gets disk and partition information by runningdisklabeland parsing its output. Falls back todfif no partitions are returned (e.g., when not running as root).- Parameters:
diskName- The disk to fetch partition information from- Returns:
- A quartet containing the disk's name/label, DUID, size, and a list of partitions
-
parseDiskParams
public static Quartet<String, String, Long, List<HWPartition>> parseDiskParams(String diskName, List<String> disklabelLines, BiFunction<String, String, Pair<Integer, Integer>> majorMinorLookup) Parsesdisklabel -noutput to extract disk metadata and partitions.- Parameters:
diskName- the disk being labeleddisklabelLines- raw output fromdisklabel -n <diskName>majorMinorLookup- function that resolves a (disk, partition-letter) pair to a (major, minor) device number pair; tests may pass a stub that returns (0,0) without invokingstat.- Returns:
- A quartet of label, DUID, size in bytes, and partitions. An empty partition list signals the caller
should fall back to
parseDfFallback(String, List, BiFunction).
-
parseDfFallback
public static Quartet<String, String, Long, List<HWPartition>> parseDfFallback(String diskName, List<String> dfLines, BiFunction<String, String, Pair<Integer, Integer>> majorMinorLookup) Parsesdfoutput as a fallback whendisklabelreturns no partitions (typically because the caller lacks root privileges).- Parameters:
diskName- the disk whose partitions are being enumerateddfLines- raw output fromdfmajorMinorLookup- function that resolves a (disk, partition-letter) pair to a (major, minor) device number pair- Returns:
- A quartet of UNKNOWN label/DUID, 0 size, and partitions discovered from
df. Callers that already have disklabel header metadata should combine it with the partition list from this result.
-