Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
logvol_data.luks_version = logvol_data.luks_version or storage.default_luks_version
pbkdf_args = get_pbkdf_args(
luks_version=logvol_data.luks_version,
pbkdf_type=logvol_data.pbkdf,
max_memory_kb=logvol_data.pbkdf_memory,
iterations=logvol_data.pbkdf_iterations,
time_ms=logvol_data.pbkdf_time
)
if pbkdf_args and not luks_data.pbkdf_args:
luks_data.pbkdf_args = pbkdf_args
if logvol_data.preexist:
luksformat = fmt
device.format = get_format(
"luks",
passphrase=passphrase,
device=device.path,
cipher=logvol_data.cipher,
escrow_cert=cert,
add_backup_passphrase=logvol_data.backuppassphrase,
luks_version=logvol_data.luks_version,
pbkdf_args=pbkdf_args
)
luksdev = LUKSDevice(
"luks%d" % storage.next_id,
fmt=luksformat,
parents=device
)
else:
luksformat = request.format
def _check_valid_luks_version(self, version):
get_format("luks", luks_version=version)
fmt=get_format(fstype,
device=devspec,
exists=True),
exists=True)
elif fstype == "bind" or "bind" in options:
# bind mount... set fstype so later comparison won't
# turn up false positives
fstype = "bind"
# This is probably not going to do anything useful, so we'll
# make sure to try again from FSSet.mount_filesystems. The bind
# mount targets should be accessible by the time we try to do
# the bind mount from there.
parents = get_containing_device(devspec, self.devicetree)
device = DirectoryDevice(devspec, parents=parents, exists=True)
device.format = get_format("bind",
device=device.path,
exists=True)
elif mountpoint in ("/proc", "/sys", "/dev/shm", "/dev/pts",
"/sys/fs/selinux", "/proc/bus/usb", "/sys/firmware/efi/efivars"):
# drop these now -- we'll recreate later
return None
else:
# nodev filesystem -- preserve or drop completely?
fmt = get_format(fstype)
fmt_class = get_device_format_class("nodev")
if devspec == "none" or \
(fmt_class and isinstance(fmt, fmt_class)):
device = NoDevice(fmt=fmt)
if device is None:
log.error("failed to resolve %s (%s) from fstab", devspec,
return None
else:
# nodev filesystem -- preserve or drop completely?
fmt = get_format(fstype)
fmt_class = get_device_format_class("nodev")
if devspec == "none" or \
(fmt_class and isinstance(fmt, fmt_class)):
device = NoDevice(fmt=fmt)
if device is None:
log.error("failed to resolve %s (%s) from fstab", devspec,
fstype)
raise UnrecognizedFSTabEntryError()
device.setup()
fmt = get_format(fstype, device=device.path, exists=True)
if fstype != "auto" and None in (device.format.type, fmt.type):
log.info("Unrecognized filesystem type for %s (%s)",
device.name, fstype)
device.teardown()
raise UnrecognizedFSTabEntryError()
# make sure, if we're using a device from the tree, that
# the device's format we found matches what's in the fstab
ftype = getattr(fmt, "mount_type", fmt.type)
dtype = getattr(device.format, "mount_type", device.format.type)
if hasattr(fmt, "test_mount") and fstype != "auto" and ftype != dtype:
log.info("fstab says %s at %s is %s", dtype, mountpoint, ftype)
if fmt.test_mount(): # pylint: disable=no-member
device.format = fmt
else:
device.teardown()
)
self._blivet.create_device(btrfs)
storagetree[('btrfs', name)] = btrfs
for mountpoint, attrs in expr['fileSystems'].items():
uuid = attrs['storage']['uuid']
if for_mounting:
device = self._blivet.devicetree.get_device_by_uuid(uuid)
if device is not None:
device.format.mountpoint = mountpoint
continue
if attrs['storage']['type'] == 'btrfs':
continue
target = storagetree.get(self.devspec2tuple(attrs['storage']))
fmt = blivet.formats.get_format(attrs['fsType'],
device=target.path,
uuid=uuid)
label = attrs.get('label')
if label is not None:
fmt.label = label
self._blivet.format_device(target, fmt)
fmt_args = {}
dev = storage.new_partition(fmt_type=fmt_type,
fmt_args=fmt_args,
size=request.size,
grow=request.grow,
maxsize=request.max_size,
mountpoint=request.mountpoint,
parents=disks,
weight=request.weight)
# schedule the device for creation
storage.create_device(dev)
if request.encrypted and storage.encrypted_autopart:
luks_fmt = get_format(request.fstype,
device=dev.path,
mountpoint=request.mountpoint)
luks_dev = LUKSDevice("luks-%s" % dev.name,
fmt=luks_fmt,
size=dev.size,
parents=dev)
storage.create_device(luks_dev)
if storage.do_autopart and \
storage.autopart_type in (AUTOPART_TYPE_LVM, AUTOPART_TYPE_LVM_THINP,
AUTOPART_TYPE_BTRFS):
# doing LVM/BTRFS -- make sure the newly created partition fits in some
# free space together with one of the implicitly requested partitions
smallest_implicit = sorted(implicit_devices, key=lambda d: d.size)[0]
if (request.size + smallest_implicit.size) > all_free[0]:
# not enough space to allocate the smallest implicit partition
def new_partition(self, *args, **kwargs):
""" Return a new (unallocated) PartitionDevice instance.
:keyword fmt_type: format type
:type fmt_type: str
:keyword fmt_args: arguments for format constructor
:type fmt_args: dict
:keyword mountpoint: mountpoint for format (filesystem)
:type mountpoint: str
All other arguments are passed on to the
:class:`~.devices.PartitionDevice` constructor.
"""
if 'fmt_type' in kwargs:
kwargs["fmt"] = get_format(kwargs.pop("fmt_type"),
mountpoint=kwargs.pop("mountpoint",
None),
**kwargs.pop("fmt_args", {}))
if 'name' in kwargs:
name = kwargs.pop("name")
else:
name = "req%d" % self.next_id
if "weight" not in kwargs:
fmt = kwargs.get("fmt")
if fmt:
mountpoint = getattr(fmt, "mountpoint", None)
kwargs["weight"] = _platform.weight(mountpoint=mountpoint,
fstype=fmt.type)
def populate_mountpoint_store(store, used_mountpoints):
# sure, add whatever you want to this list. this is just a start.
paths = ["/", "/boot", "/home", "/var"] + \
platform.boot_stage1_constraint_dict["mountpoints"]
# Sort the list now so all the real mountpoints go to the front, then
# add all the pseudo mountpoints we have.
paths.sort()
paths += ["swap"]
for fmt in ["appleboot", "biosboot", "prepboot"]:
if get_format(fmt).supported:
paths += [fmt]
for path in paths:
if path not in used_mountpoints:
store.append([path])
def _check_valid_fstype(self, newtype):
""" Check the fstype to see if it is valid
Raise ValueError on invalid input.
"""
fmt = get_format(newtype)
if fmt.type is None:
raise ValueError("unrecognized value %s for new default fs type" % newtype)
if (not fmt.mountable or not fmt.formattable or not fmt.supported or
not fmt.linux_native):
log.debug("invalid default fstype (%s): %r", newtype, fmt)
raise ValueError("new value %s is not valid as a default fs type" % newtype)
self._default_fstype = newtype # pylint: disable=attribute-defined-outside-init