Beispiel #1
0
 def efivars(self):
     if not self._efivars:
         self._efivars = NoDevice(
             fmt=get_format("efivarfs",
                            device="efivarfs",
                            mountpoint="/sys/firmware/efi/efivars"))
     return self._efivars
Beispiel #2
0
def get_system_filesystems(devicetree):
    """Get system filesystems.

    :param devicetree: a model of the storage
    :return: a list of new devices
    """
    devices = [
        DirectoryDevice(
            "/dev",
            exists=True,
            fmt=get_format("bind",
                           device="/dev",
                           mountpoint="/dev",
                           exists=True),
        ),
        NoDevice(
            fmt=get_format("tmpfs", device="tmpfs", mountpoint="/dev/shm")),
        NoDevice(
            fmt=get_format("devpts", device="devpts", mountpoint="/dev/pts")),
        NoDevice(fmt=get_format("sysfs", device="sysfs", mountpoint="/sys")),
        NoDevice(fmt=get_format("proc", device="proc", mountpoint="/proc")),
        NoDevice(fmt=get_format(
            "selinuxfs", device="selinuxfs", mountpoint="/sys/fs/selinux")),
        NoDevice(fmt=get_format(
            "usbfs", device="usbfs", mountpoint="/proc/bus/usb")),
        DirectoryDevice("/run",
                        exists=True,
                        fmt=get_format("bind",
                                       device="/run",
                                       mountpoint="/run",
                                       exists=True))
    ]

    if isinstance(platform, EFI):
        device = NoDevice(
            fmt=get_format("efivarfs",
                           device="efivarfs",
                           mountpoint="/sys/firmware/efi/efivars"))
        devices.append(device)

    if "/tmp" not in devicetree.mountpoints:
        device = NoDevice(
            fmt=get_format("tmpfs", device="tmpfs", mountpoint="/tmp"))
        devices.append(device)

    return devices
Beispiel #3
0
    def _parse_one_line(self, devspec, mountpoint, fstype, options, _dump="0", _passno="0"):
        """Parse an fstab entry for a device, return the corresponding device.

        The parameters correspond to the items in a single entry in the
        order in which they occur in the entry.

        :return: the device corresponding to the entry
        :rtype: :class:`blivet.devices.Device`
        """

        # no sense in doing any legwork for a noauto entry
        if "noauto" in options.split(","):
            log.info("ignoring noauto entry")
            raise UnrecognizedFSTabEntryError()

        # find device in the tree
        device = self.devicetree.resolve_device(devspec,
                                                crypt_tab=self.crypt_tab,
                                                blkid_tab=self.blkid_tab,
                                                options=options)

        if device:
            # fall through to the bottom of this block
            pass
        elif devspec.startswith("/dev/loop"):
            # FIXME: create devices.LoopDevice
            log.warning("completely ignoring your loop mount")
        elif ":" in devspec and fstype.startswith("nfs"):
            # NFS -- preserve but otherwise ignore
            device = NFSDevice(devspec,
                               fmt=get_format(fstype,
                                              exists=True,
                                              device=devspec))
        elif devspec.startswith("/") and fstype == "swap":
            # swap file
            device = FileDevice(devspec,
                                parents=get_containing_device(devspec, self.devicetree),
                                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,
                      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()
                raise FSTabTypeMismatchError(_(
                    "There is an entry in your /etc/fstab file that contains "
                    "an invalid or incorrect file system type. The file says that "
                    "{detected_type} at {mount_point} is {fstab_type}.").format(
                    detected_type=dtype,
                    mount_point=mountpoint,
                    fstab_type=ftype
                ))

        del ftype
        del dtype

        if hasattr(device.format, "mountpoint"):
            device.format.mountpoint = mountpoint

        device.format.options = options

        return device
Beispiel #4
0
 def selinux(self):
     if not self._selinux:
         self._selinux = NoDevice(fmt=get_format("selinuxfs", device="selinuxfs", mountpoint="/sys/fs/selinux"))
     return self._selinux
Beispiel #5
0
 def usb(self):
     if not self._usb:
         self._usb = NoDevice(fmt=get_format("usbfs", device="usbfs", mountpoint="/proc/bus/usb"))
     return self._usb
Beispiel #6
0
 def devshm(self):
     if not self._devshm:
         self._devshm = NoDevice(fmt=get_format("tmpfs", device="tmpfs", mountpoint="/dev/shm"))
     return self._devshm
Beispiel #7
0
 def proc(self):
     if not self._proc:
         self._proc = NoDevice(fmt=get_format("proc", device="proc", mountpoint="/proc"))
     return self._proc
Beispiel #8
0
 def devpts(self):
     if not self._devpts:
         self._devpts = NoDevice(fmt=get_format("devpts", device="devpts", mountpoint="/dev/pts"))
     return self._devpts
Beispiel #9
0
 def sysfs(self):
     if not self._sysfs:
         self._sysfs = NoDevice(fmt=get_format("sysfs", device="sysfs", mountpoint="/sys"))
     return self._sysfs