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
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("%s: detected as %s, fstab says %s" % (mountpoint, dtype, ftype)) del ftype del dtype if hasattr(device.format, "mountpoint"): device.format.mountpoint = mountpoint device.format.options = options return device