Skip to content

Commit

Permalink
Rework partition flag (#2895)
Browse files Browse the repository at this point in the history
  • Loading branch information
codefiles authored Nov 20, 2024
1 parent 3453816 commit 83d222c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
38 changes: 32 additions & 6 deletions archinstall/lib/disk/device_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ def parse_arg(cls, disk_config: dict[str, Any]) -> DiskLayoutConfiguration | Non
device_partitions: list[PartitionModification] = []

for partition in entry.get('partitions', []):
flags = [
flag for f in partition.get('flags', [])
if (flag := PartitionFlag.from_string(f))
]

device_partition = PartitionModification(
status=ModificationStatus(partition['status']),
fs_type=FilesystemType(partition['fs_type']) if partition.get('fs_type') else None,
Expand All @@ -120,7 +125,7 @@ def parse_arg(cls, disk_config: dict[str, Any]) -> DiskLayoutConfiguration | Non
mountpoint=Path(partition['mountpoint']) if partition['mountpoint'] else None,
dev_path=Path(partition['dev_path']) if partition['dev_path'] else None,
type=PartitionType(partition['type']),
flags=[PartitionFlag[f] for f in partition.get('flags', [])],
flags=flags,
btrfs_subvols=SubvolumeModification.parse_args(partition.get('btrfs', [])),
)
# special 'invisible attr to internally identify the part mod
Expand Down Expand Up @@ -388,7 +393,7 @@ def from_partition(
btrfs_subvol_infos: list[_BtrfsSubvolumeInfo] = []
) -> _PartitionInfo:
partition_type = PartitionType.get_type_from_code(partition.type)
flags = [f for f in PartitionFlag if partition.getFlag(f.value)]
flags = [f for f in PartitionFlag if partition.getFlag(f.flag_id)]

start = Size(
partition.geometry.start,
Expand Down Expand Up @@ -579,11 +584,32 @@ def get_partition_code(self) -> int | None:
return None


class PartitionFlag(Enum):
@dataclass(frozen=True)
class PartitionFlagDataMixin:
flag_id: int
alias: str | None = None


class PartitionFlag(PartitionFlagDataMixin, Enum):
Boot = parted.PARTITION_BOOT
XBOOTLDR = parted.PARTITION_BLS_BOOT # Note: parted calls this bls_boot
XBOOTLDR = parted.PARTITION_BLS_BOOT, "bls_boot"
ESP = parted.PARTITION_ESP

@property
def description(self) -> str:
return self.alias or self.name.lower()

@classmethod
def from_string(cls, s: str) -> PartitionFlag | None:
s = s.lower()

for partition_flag in cls:
if s in (partition_flag.name.lower(), partition_flag.alias):
return partition_flag

debug(f'Partition flag not supported: {s}')
return None


class PartitionGUID(Enum):
"""
Expand Down Expand Up @@ -829,7 +855,7 @@ def json(self) -> dict[str, Any]:
'fs_type': self.fs_type.value if self.fs_type else None,
'mountpoint': str(self.mountpoint) if self.mountpoint else None,
'mount_options': self.mount_options,
'flags': [f.name for f in self.flags],
'flags': [f.description for f in self.flags],
'dev_path': str(self.dev_path) if self.dev_path else None,
'btrfs': [vol.json() for vol in self.btrfs_subvols]
}
Expand All @@ -848,7 +874,7 @@ def table_data(self) -> dict[str, Any]:
'FS type': self.fs_type.value if self.fs_type else 'Unknown',
'Mountpoint': self.mountpoint if self.mountpoint else '',
'Mount options': ', '.join(self.mount_options),
'Flags': ', '.join([f.name for f in self.flags]),
'Flags': ', '.join([f.description for f in self.flags]),
}

if self.btrfs_subvols:
Expand Down
2 changes: 1 addition & 1 deletion docs/cli_parameters/config/disk_config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ FAT32
{
"btrfs": [],
"flags": [
"Boot"
"boot"
],
"fs_type": "fat32",
"length": {
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/python.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ After running ``python -m archinstall test_installer`` it should print something
start=Size(value=2048, unit=<Unit.sectors: 'sectors'>, sector_size=SectorSize(value=512, unit=<Unit.B: 1>)),
length=Size(value=535822336, unit=<Unit.B: 1>, sector_size=SectorSize(value=512, unit=<Unit.B: 1>)),
flags=[
<PartitionFlag.Boot: 1>,
<PartitionFlag.ESP: 18>
<PartitionFlag.Boot: flag_id=1, alias=None>,
<PartitionFlag.ESP: flag_id=18, alias=None>
],
partn=1,
partuuid='a26be943-c193-41f4-9930-9341cf5f6b19',
Expand Down
2 changes: 1 addition & 1 deletion docs/installing/guided.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ The contents of :code:`https://domain.lan/config.json`:
{
"btrfs": [],
"flags": [
"Boot"
"boot"
],
"fs_type": "fat32",
"length": {
Expand Down
2 changes: 1 addition & 1 deletion examples/config-sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{
"btrfs": [],
"flags": [
"Boot"
"boot"
],
"fs_type": "fat32",
"size": {
Expand Down

0 comments on commit 83d222c

Please sign in to comment.