Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/disk.py
diff options
context:
space:
mode:
authorAnton Hvornum <anton@hvornum.se>2021-06-14 18:53:34 +0200
committerAnton Hvornum <anton@hvornum.se>2021-06-14 18:53:34 +0200
commit2ac1f453cf2f12baeb562b0ff47911e1358d988d (patch)
tree9bc507a6641c52feb7858ec5c3037dada5f27e71 /archinstall/lib/disk.py
parenteb4c134c8001888dc775e7af5dad419fa77bc134 (diff)
Added BlockDevice.largest_free_space and BlockDevice.free_space (iterator). Also added additional supported filesystems to parted. Apparently the online manpages doesn't agree with the local manpages, my previous statement that these gets ignored is false so added those in and removed some that isn't supported by my local manpages, 'ufs' for instance.
Diffstat (limited to 'archinstall/lib/disk.py')
-rw-r--r--archinstall/lib/disk.py38
1 files changed, 34 insertions, 4 deletions
diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py
index aa52c7af..1911110a 100644
--- a/archinstall/lib/disk.py
+++ b/archinstall/lib/disk.py
@@ -15,16 +15,27 @@ MBR = 0b00000010
def valid_fs_type(fstype :str) -> bool:
# https://www.gnu.org/software/parted/manual/html_node/mkpart.html
+ # Above link doesn't agree with `man parted` /mkpart documentation:
+ """
+ fs-type can
+ be one of "btrfs", "ext2",
+ "ext3", "ext4", "fat16",
+ "fat32", "hfs", "hfs+",
+ "linux-swap", "ntfs", "reis‐
+ erfs", "udf", or "xfs".
+ """
return fstype in [
+ "btrfs",
"ext2",
+ "ext3", "ext4", # `man parted` allows these
"fat16", "fat32",
- "hfs", "hfs+", "hfsx",
+ "hfs", "hfs+", # "hfsx", not included in `man parted`
"linux-swap",
- "NTFS",
+ "ntfs",
"reiserfs",
- "ufs",
- "btrfs",
+ "udf", # "ufs", not included in `man parted`
+ "xfs", # `man parted` allows this
]
@@ -335,6 +346,25 @@ class BlockDevice:
for device in output['blockdevices']:
return device['rota'] is True
+ @property
+ def free_space(self):
+ for line in SysCommand(f"parted --machine {self.path} print free"):
+ if 'free' in (free_space := line.decode('UTF-8')):
+ _, start, end, size, *_ = free_space.strip('\r\n;').split(':')
+ yield (start, end, size)
+
+ @property
+ def largest_free_space(self):
+ info = None
+ for space_info in self.free_space:
+ if not info:
+ info = space_info
+ else:
+ # [-1] = size
+ if space_info[-1] > info[-1]:
+ info = space_info
+ return info
+
def has_partitions(self):
return len(self.partitions)