Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from .. import udev
from .. import util
from ..flags import flags
from ..i18n import _, N_
from . import DeviceFormat, register_device_format
from ..size import Size
import logging
log = logging.getLogger("blivet")
class DiskLabel(DeviceFormat):
""" Disklabel """
_type = "disklabel"
_name = N_("partition table")
_formattable = True # can be formatted
_default_label_type = None
def __init__(self, **kwargs):
"""
:keyword device: full path to the block device node
:type device: str
:keyword str uuid: disklabel UUID
:keyword label_type: type of disklabel to create
:type label_type: str
:keyword exists: whether the formatting exists
:type exists: bool
"""
log_method_call(self, **kwargs)
DeviceFormat.__init__(self, **kwargs)
class EFI(Platform):
_boot_stage1_format_types = ["efi"]
_boot_stage1_device_types = ["partition", "mdarray"]
_boot_stage1_mountpoints = ["/boot/efi"]
_boot_stage1_raid_levels = [raid.RAID1]
_boot_stage1_raid_metadata = ["1.0"]
_boot_efi_description = N_("EFI System Partition")
_boot_descriptions = {"partition": _boot_efi_description,
"mdarray": Platform._boot_raid_description}
# XXX hpfs, if reported by blkid/udev, will end up with a type of None
_non_linux_format_types = ["vfat", "ntfs", "hpfs"]
_boot_stage1_missing_error = N_("For a UEFI installation, you must include "
"an EFI System Partition on a GPT-formatted "
"disk, mounted at /boot/efi.")
def set_platform_bootloader_reqs(self):
ret = Platform.set_platform_bootloader_reqs(self)
ret.append(PartSpec(mountpoint="/boot/efi", fstype="efi",
size=Size("20MiB"), max_size=Size("200MiB"),
grow=True))
return ret
class MacEFI(EFI):
_boot_stage1_format_types = ["macefi"]
_boot_efi_description = N_("Apple EFI Boot Partition")
_non_linux_format_types = ["macefi"]
_packages = ["mactel-boot"]
_formattable = True
_min_size = Size("1 MiB")
_max_size = Size("2 TiB")
_check = True
parted_system = fileSystemType["hfs+"]
_fsck_class = fsck.HFSPlusFSCK
_mkfs_class = fsmkfs.HFSPlusMkfs
_mount_class = fsmount.HFSPlusMount
register_device_format(HFSPlus)
class MacEFIFS(HFSPlus):
_type = "macefi"
_name = N_("Linux HFS+ ESP")
_udev_types = []
_min_size = Size("50 MiB")
_supported = True
@property
def supported(self):
return super(MacEFIFS, self).supported and arch.is_efi() and arch.is_mactel()
def __init__(self, **kwargs):
if "label" not in kwargs:
kwargs["label"] = self._name
super(MacEFIFS, self).__init__(**kwargs)
register_device_format(MacEFIFS)
_boot_stage1_missing_error = N_("You must include at least one MBR-formatted "
"disk as an install target.")
@property
def arm_machine(self):
if not self._arm_machine:
self._arm_machine = arch.get_arm_machine()
return self._arm_machine
class omapARM(ARM):
_boot_stage1_format_types = ["vfat"]
_boot_stage1_device_types = ["partition"]
_boot_stage1_mountpoints = ["/boot/uboot"]
_boot_uboot_description = N_("U-Boot Partition")
_boot_descriptions = {"partition": _boot_uboot_description}
_boot_stage1_missing_error = N_("You must include a U-Boot Partition on a "
"FAT-formatted disk, mounted at /boot/uboot.")
def set_platform_bootloader_reqs(self):
"""Return the ARM-OMAP platform-specific partitioning information."""
ret = [PartSpec(mountpoint="/boot/uboot", fstype="vfat",
size=Size("20MiB"), max_size=Size("200MiB"),
grow=True)]
return ret
def set_default_partitioning(self):
ret = ARM.set_default_partitioning(self)
ret.append(PartSpec(mountpoint="/", fstype="ext4",
size=Size("2GiB"), max_size=Size("3GiB")))
return ret
# DeviceTree
class DeviceTreeError(StorageError):
pass
class NoSlavesError(DeviceTreeError):
pass
class DeviceNotFoundError(StorageError):
pass
class UnusableConfigurationError(StorageError):
""" User has an unusable initial storage configuration. """
suggestion = ""
class DiskLabelScanError(UnusableConfigurationError):
suggestion = N_("For some reason we were unable to locate a disklabel on a "
"disk that the kernel is reporting partitions on. It is "
"unclear what the exact problem is. Please file a bug at "
"http://bugzilla.redhat.com")
class CorruptGPTError(UnusableConfigurationError):
suggestion = N_("Either restore the disklabel to a completely working "
"state or remove it completely.\n"
"Hint: parted can restore it or wipefs can remove it.")
class DuplicateVGError(UnusableConfigurationError):
suggestion = N_("Rename one of the volume groups so the names are "
"distinct.\n"
"Hint 1: vgrename accepts UUID in place of the old name.\n"
"Hint 2: You can get the VG UUIDs by running "
"'pvs -o +vg_uuid'.")
from decimal import ROUND_DOWN, ROUND_UP, ROUND_HALF_UP
import six
from .errors import SizePlacesError
from .i18n import _, N_
from .util import stringize, unicodeize
ROUND_DEFAULT = ROUND_HALF_UP
# Container for size unit prefix information
_Prefix = namedtuple("Prefix", ["factor", "prefix", "abbr"])
_DECIMAL_FACTOR = 10 ** 3
_BINARY_FACTOR = 2 ** 10
_BYTES_SYMBOL = N_("B")
_BYTES_WORDS = (N_("bytes"), N_("byte"))
# Symbolic constants for units
B = _Prefix(1, "", "")
KB = _Prefix(_DECIMAL_FACTOR ** 1, N_("kilo"), N_("k"))
MB = _Prefix(_DECIMAL_FACTOR ** 2, N_("mega"), N_("M"))
GB = _Prefix(_DECIMAL_FACTOR ** 3, N_("giga"), N_("G"))
TB = _Prefix(_DECIMAL_FACTOR ** 4, N_("tera"), N_("T"))
PB = _Prefix(_DECIMAL_FACTOR ** 5, N_("peta"), N_("P"))
EB = _Prefix(_DECIMAL_FACTOR ** 6, N_("exa"), N_("E"))
ZB = _Prefix(_DECIMAL_FACTOR ** 7, N_("zetta"), N_("Z"))
YB = _Prefix(_DECIMAL_FACTOR ** 8, N_("yotta"), N_("Y"))
KiB = _Prefix(_BINARY_FACTOR ** 1, N_("kibi"), N_("Ki"))
MiB = _Prefix(_BINARY_FACTOR ** 2, N_("mebi"), N_("Mi"))
import six
from .errors import SizePlacesError
from .i18n import _, N_
from .util import stringize, unicodeize
ROUND_DEFAULT = ROUND_HALF_UP
# Container for size unit prefix information
_Prefix = namedtuple("Prefix", ["factor", "prefix", "abbr"])
_DECIMAL_FACTOR = 10 ** 3
_BINARY_FACTOR = 2 ** 10
_BYTES_SYMBOL = N_("B")
_BYTES_WORDS = (N_("bytes"), N_("byte"))
# Symbolic constants for units
B = _Prefix(1, "", "")
KB = _Prefix(_DECIMAL_FACTOR ** 1, N_("kilo"), N_("k"))
MB = _Prefix(_DECIMAL_FACTOR ** 2, N_("mega"), N_("M"))
GB = _Prefix(_DECIMAL_FACTOR ** 3, N_("giga"), N_("G"))
TB = _Prefix(_DECIMAL_FACTOR ** 4, N_("tera"), N_("T"))
PB = _Prefix(_DECIMAL_FACTOR ** 5, N_("peta"), N_("P"))
EB = _Prefix(_DECIMAL_FACTOR ** 6, N_("exa"), N_("E"))
ZB = _Prefix(_DECIMAL_FACTOR ** 7, N_("zetta"), N_("Z"))
YB = _Prefix(_DECIMAL_FACTOR ** 8, N_("yotta"), N_("Y"))
KiB = _Prefix(_BINARY_FACTOR ** 1, N_("kibi"), N_("Ki"))
MiB = _Prefix(_BINARY_FACTOR ** 2, N_("mebi"), N_("Mi"))
GiB = _Prefix(_BINARY_FACTOR ** 3, N_("gibi"), N_("Gi"))
MB = _Prefix(_DECIMAL_FACTOR ** 2, N_("mega"), N_("M"))
GB = _Prefix(_DECIMAL_FACTOR ** 3, N_("giga"), N_("G"))
TB = _Prefix(_DECIMAL_FACTOR ** 4, N_("tera"), N_("T"))
PB = _Prefix(_DECIMAL_FACTOR ** 5, N_("peta"), N_("P"))
EB = _Prefix(_DECIMAL_FACTOR ** 6, N_("exa"), N_("E"))
ZB = _Prefix(_DECIMAL_FACTOR ** 7, N_("zetta"), N_("Z"))
YB = _Prefix(_DECIMAL_FACTOR ** 8, N_("yotta"), N_("Y"))
KiB = _Prefix(_BINARY_FACTOR ** 1, N_("kibi"), N_("Ki"))
MiB = _Prefix(_BINARY_FACTOR ** 2, N_("mebi"), N_("Mi"))
GiB = _Prefix(_BINARY_FACTOR ** 3, N_("gibi"), N_("Gi"))
TiB = _Prefix(_BINARY_FACTOR ** 4, N_("tebi"), N_("Ti"))
PiB = _Prefix(_BINARY_FACTOR ** 5, N_("pebi"), N_("Pi"))
EiB = _Prefix(_BINARY_FACTOR ** 6, N_("exbi"), N_("Ei"))
ZiB = _Prefix(_BINARY_FACTOR ** 7, N_("zebi"), N_("Zi"))
YiB = _Prefix(_BINARY_FACTOR ** 8, N_("yobi"), N_("Yi"))
# Categories of symbolic constants
_DECIMAL_PREFIXES = [KB, MB, GB, TB, PB, EB, ZB, YB]
_BINARY_PREFIXES = [KiB, MiB, GiB, TiB, PiB, EiB, ZiB, YiB]
_EMPTY_PREFIX = B
if six.PY2:
_ASCIIlower_table = string.maketrans(string.ascii_uppercase, string.ascii_lowercase) # pylint: disable=no-member
else:
_ASCIIlower_table = str.maketrans(string.ascii_uppercase, string.ascii_lowercase) # pylint: disable=no-member
def _lowerASCII(s):
"""Convert a string to lowercase using only ASCII character definitions.
:param s: string instance to convert
:type s: str or bytes
_BYTES_WORDS = (N_("bytes"), N_("byte"))
# Symbolic constants for units
B = _Prefix(1, "", "")
KB = _Prefix(_DECIMAL_FACTOR ** 1, N_("kilo"), N_("k"))
MB = _Prefix(_DECIMAL_FACTOR ** 2, N_("mega"), N_("M"))
GB = _Prefix(_DECIMAL_FACTOR ** 3, N_("giga"), N_("G"))
TB = _Prefix(_DECIMAL_FACTOR ** 4, N_("tera"), N_("T"))
PB = _Prefix(_DECIMAL_FACTOR ** 5, N_("peta"), N_("P"))
EB = _Prefix(_DECIMAL_FACTOR ** 6, N_("exa"), N_("E"))
ZB = _Prefix(_DECIMAL_FACTOR ** 7, N_("zetta"), N_("Z"))
YB = _Prefix(_DECIMAL_FACTOR ** 8, N_("yotta"), N_("Y"))
KiB = _Prefix(_BINARY_FACTOR ** 1, N_("kibi"), N_("Ki"))
MiB = _Prefix(_BINARY_FACTOR ** 2, N_("mebi"), N_("Mi"))
GiB = _Prefix(_BINARY_FACTOR ** 3, N_("gibi"), N_("Gi"))
TiB = _Prefix(_BINARY_FACTOR ** 4, N_("tebi"), N_("Ti"))
PiB = _Prefix(_BINARY_FACTOR ** 5, N_("pebi"), N_("Pi"))
EiB = _Prefix(_BINARY_FACTOR ** 6, N_("exbi"), N_("Ei"))
ZiB = _Prefix(_BINARY_FACTOR ** 7, N_("zebi"), N_("Zi"))
YiB = _Prefix(_BINARY_FACTOR ** 8, N_("yobi"), N_("Yi"))
# Categories of symbolic constants
_DECIMAL_PREFIXES = [KB, MB, GB, TB, PB, EB, ZB, YB]
_BINARY_PREFIXES = [KiB, MiB, GiB, TiB, PiB, EiB, ZiB, YiB]
_EMPTY_PREFIX = B
if six.PY2:
_ASCIIlower_table = string.maketrans(string.ascii_uppercase, string.ascii_lowercase) # pylint: disable=no-member
else:
_ASCIIlower_table = str.maketrans(string.ascii_uppercase, string.ascii_lowercase) # pylint: disable=no-member
B = _Prefix(1, "", "")
KB = _Prefix(_DECIMAL_FACTOR ** 1, N_("kilo"), N_("k"))
MB = _Prefix(_DECIMAL_FACTOR ** 2, N_("mega"), N_("M"))
GB = _Prefix(_DECIMAL_FACTOR ** 3, N_("giga"), N_("G"))
TB = _Prefix(_DECIMAL_FACTOR ** 4, N_("tera"), N_("T"))
PB = _Prefix(_DECIMAL_FACTOR ** 5, N_("peta"), N_("P"))
EB = _Prefix(_DECIMAL_FACTOR ** 6, N_("exa"), N_("E"))
ZB = _Prefix(_DECIMAL_FACTOR ** 7, N_("zetta"), N_("Z"))
YB = _Prefix(_DECIMAL_FACTOR ** 8, N_("yotta"), N_("Y"))
KiB = _Prefix(_BINARY_FACTOR ** 1, N_("kibi"), N_("Ki"))
MiB = _Prefix(_BINARY_FACTOR ** 2, N_("mebi"), N_("Mi"))
GiB = _Prefix(_BINARY_FACTOR ** 3, N_("gibi"), N_("Gi"))
TiB = _Prefix(_BINARY_FACTOR ** 4, N_("tebi"), N_("Ti"))
PiB = _Prefix(_BINARY_FACTOR ** 5, N_("pebi"), N_("Pi"))
EiB = _Prefix(_BINARY_FACTOR ** 6, N_("exbi"), N_("Ei"))
ZiB = _Prefix(_BINARY_FACTOR ** 7, N_("zebi"), N_("Zi"))
YiB = _Prefix(_BINARY_FACTOR ** 8, N_("yobi"), N_("Yi"))
# Categories of symbolic constants
_DECIMAL_PREFIXES = [KB, MB, GB, TB, PB, EB, ZB, YB]
_BINARY_PREFIXES = [KiB, MiB, GiB, TiB, PiB, EiB, ZiB, YiB]
_EMPTY_PREFIX = B
if six.PY2:
_ASCIIlower_table = string.maketrans(string.ascii_uppercase, string.ascii_lowercase) # pylint: disable=no-member
else:
_ASCIIlower_table = str.maketrans(string.ascii_uppercase, string.ascii_lowercase) # pylint: disable=no-member
def _lowerASCII(s):
"""Convert a string to lowercase using only ASCII character definitions.