Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mount by LABEL= for ext filesystems #532

Merged
merged 2 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 21 additions & 19 deletions dissect/target/plugins/os/unix/_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,29 +203,29 @@
fs_subvol = None
fs_subvolid = None
fs_volume_name = fs.volume.name if fs.volume and not isinstance(fs.volume, list) else None
last_mount = None

if dev_id:
if fs.__type__ == "xfs":
fs_id = fs.xfs.uuid
elif fs.__type__ == "ext":
fs_id = fs.extfs.uuid
last_mount = fs.extfs.last_mount
elif fs.__type__ == "btrfs":
fs_id = fs.btrfs.uuid
fs_subvol = fs.subvolume.path
fs_subvolid = fs.subvolume.objectid
elif fs.__type__ == "fat":
fs_id = fs.fatfs.volume_id
# This normalizes fs_id to comply with libblkid generated UUIDs
# This is needed because FAT filesystems don't have a real UUID,
# but instead a volume_id which is not case-sensitive
fs_id = fs_id[:4].upper() + "-" + fs_id[4:].upper()
fs_last_mount = None

Check warning on line 206 in dissect/target/plugins/os/unix/_os.py

View check run for this annotation

Codecov / codecov/patch

dissect/target/plugins/os/unix/_os.py#L206

Added line #L206 was not covered by tests

if fs.__type__ == "xfs":
fs_id = fs.xfs.uuid
elif fs.__type__ == "ext":
fs_id = fs.extfs.uuid
fs_last_mount = fs.extfs.last_mount
fs_volume_name = fs.extfs.volume_name
elif fs.__type__ == "btrfs":
fs_id = fs.btrfs.uuid
fs_subvol = fs.subvolume.path
fs_subvolid = fs.subvolume.objectid
elif fs.__type__ == "fat":
fs_id = fs.fatfs.volume_id

Check warning on line 219 in dissect/target/plugins/os/unix/_os.py

View check run for this annotation

Codecov / codecov/patch

dissect/target/plugins/os/unix/_os.py#L208-L219

Added lines #L208 - L219 were not covered by tests
# This normalizes fs_id to comply with libblkid generated UUIDs
# This is needed because FAT filesystems don't have a real UUID,
# but instead a volume_id which is not case-sensitive
fs_id = fs_id[:4].upper() + "-" + fs_id[4:].upper()

Check warning on line 223 in dissect/target/plugins/os/unix/_os.py

View check run for this annotation

Codecov / codecov/patch

dissect/target/plugins/os/unix/_os.py#L223

Added line #L223 was not covered by tests

if (
(fs_id and (fs_id == dev_id and (subvol == fs_subvol or subvolid == fs_subvolid)))
or (fs_volume_name and (fs_volume_name == volume_name))
or (last_mount and (last_mount == mount_point))
or (fs_last_mount and (fs_last_mount == mount_point))
):
self.target.log.debug("Mounting %s (%s) at %s", fs, fs.volume, mount_point)
self.target.fs.mount(mount_point, fs)
Expand Down Expand Up @@ -353,6 +353,8 @@
volume_name = "-".join(part.replace("-", "--") for part in dev.rsplit("/")[-2:])
elif dev.startswith("UUID="):
dev_id = dev.split("=")[1]
elif dev.startswith("LABEL="):
volume_name = dev.split("=")[1]
else:
log.warning("Unsupported mount device: %s %s", dev, mount_point)
continue
Expand Down
3 changes: 3 additions & 0 deletions tests/plugins/os/unix/test__os.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
/dev/vg-main/lv-data /data auto default 0 2

/dev/disk/by-uuid/af0b9707-0945-499a-a37d-4da23d8dd245 /moredata auto default 0 2

LABEL=foo /foo auto default 0 2
""" # noqa


Expand All @@ -65,6 +67,7 @@ def test_parse_fstab(tmp_path):
("F631-BECA", None, "/boot/efi", "vfat", "defaults,discard,umask=0077"),
(None, "vg--main-lv--var", "/var", "auto", "default"),
(None, "vg--main-lv--data", "/data", "auto", "default"),
(None, "foo", "/foo", "auto", "default"),
}


Expand Down
Loading