diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a60b5ed..89b341e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -37,7 +37,7 @@ pip install -e ".[dev]" `ffmpeg` and `ffprobe` on `PATH` are optional — the suite runs without them. ```sh -pytest # 916 tests, about 20s +pytest # 1311 tests, about 20s pytest --fuzz # property tests at 3000 examples each, about 3 min ruff check src tests pytest --cov=offloader --cov-report=term-missing diff --git a/README.md b/README.md index 69126c6..60a9778 100644 --- a/README.md +++ b/README.md @@ -635,13 +635,13 @@ Full verification only when every present destination was hashed. ```sh pip install -e ".[dev]" -pytest # 916 tests, ~20s +pytest # 1311 tests, ~20s pytest --fuzz # same suite, 3000 examples per property (~3 min) ruff check src tests pytest --cov=offloader --cov-report=term-missing ``` -916 tests at 89% line coverage. They cover formatting against the reference's +1311 tests at 88% line coverage. They cover formatting against the reference's exact strings, checksum vectors and streaming equivalence, copy/verify behaviour including simulated destination corruption, pause/resume/cancel concurrency, retry discrimination, BRAW container parsing, ffprobe parsing, diff --git a/src/offloader/volumes.py b/src/offloader/volumes.py index f2fba89..4b39b5d 100644 --- a/src/offloader/volumes.py +++ b/src/offloader/volumes.py @@ -8,6 +8,7 @@ import os import platform +import re import shutil import string from concurrent.futures import ThreadPoolExecutor @@ -221,11 +222,154 @@ def _posix_probe(root: Path, drive_type: str) -> Volume | None: ) +#: Linux filesystems that are not storage: kernel interfaces, containers, snap +#: loop images, and per-user FUSE plumbing (gvfs, portals). +_LINUX_PSEUDO_FS = { + "proc", "sysfs", "devtmpfs", "devpts", "tmpfs", "ramfs", "cgroup", "cgroup2", + "overlay", "squashfs", "autofs", "securityfs", "debugfs", "tracefs", "fusectl", + "configfs", "pstore", "bpf", "mqueue", "hugetlbfs", "binfmt_misc", "rpc_pipefs", + "efivarfs", "nsfs", "fuse.gvfsd-fuse", "fuse.portal", "fuse.snapfuse", + "fuse.lxcfs", "fuse.gvfs-fuse-daemon", +} +_LINUX_NETWORK_FS = { + "nfs", "nfs4", "cifs", "smb3", "smbfs", "9p", "ceph", "glusterfs", "afs", + "davfs", "fuse.sshfs", "fuse.rclone", +} +_LINUX_OPTICAL_FS = {"iso9660", "udf"} +_MOUNTINFO = "/proc/self/mountinfo" + +#: Mounts under these belong to the OS, not to a person plugging something in. +_LINUX_SYSTEM_PREFIXES = ( + "/boot", "/snap", "/var/snap", "/var/lib", "/usr", "/etc", "/proc", "/sys", + "/dev", "/run", +) +#: Where udisks and friends put removable media. Exempt from the list above, +#: because /run/media sits under /run. +_LINUX_MEDIA_PREFIXES = ("/media", "/run/media", "/mnt") + + +def _unescape_mountinfo(field: str) -> str: + """mountinfo writes space, tab, newline and backslash as octal escapes.""" + return re.sub(r"\\([0-7]{3})", lambda m: chr(int(m.group(1), 8)), field) + + +def _under(path: str, prefixes: tuple[str, ...]) -> bool: + return any(path == p or path.startswith(p + "/") for p in prefixes) + + +def _linux_device_is_removable(major_minor: str) -> bool: + """Whether the block device behind a mount reports itself as removable. + + A partition's `removable` flag lives on its parent disk. Device-mapper + devices (LUKS) have none, and read as not removable. + """ + try: + device = (Path("/sys/dev/block") / major_minor).resolve() + except OSError: + return False + for candidate in (device, device.parent): + try: + return (candidate / "removable").read_text().strip() == "1" + except OSError: + continue + return False + + +def _linux_table() -> list[tuple[str, str, str]]: + """(device numbers, mount point, filesystem) for each line of the + kernel's mount table. Raises OSError where there is no /proc.""" + with open(_MOUNTINFO, encoding="utf-8", errors="replace") as handle: + lines = handle.read().splitlines() + + table: list[tuple[str, str, str]] = [] + for line in lines: + head, separator, tail = line.partition(" - ") + left, right = head.split(), tail.split() + if not separator or len(left) < 5 or len(right) < 2: + continue + table.append((left[2], _unescape_mountinfo(left[4]), right[0])) + return table + + +def _linux_mounts() -> list[tuple[Path, str, str]]: + """(mount point, drive type, filesystem) for each mount worth listing. + + Cards mount at /media//