diff --git a/dissect/target/plugins/os/unix/_os.py b/dissect/target/plugins/os/unix/_os.py index 81710ecc5..385404538 100644 --- a/dissect/target/plugins/os/unix/_os.py +++ b/dissect/target/plugins/os/unix/_os.py @@ -202,8 +202,9 @@ def _add_mounts(self) -> None: fs_id = None fs_subvol = None fs_subvolid = None - fs_volume_name = fs.volume.name if fs.volume and not isinstance(fs.volume, list) else None fs_last_mount = None + fs_volume_name = None + vol_volume_name = fs.volume.name if fs.volume and not isinstance(fs.volume, list) else None if fs.__type__ == "xfs": fs_id = fs.xfs.uuid @@ -224,8 +225,9 @@ def _add_mounts(self) -> None: 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 (fs_last_mount and (fs_last_mount == mount_point)) + or (fs_volume_name and (fs_volume_name == volume_name)) + or (vol_volume_name and (vol_volume_name == volume_name)) ): self.target.log.debug("Mounting %s (%s) at %s", fs, fs.volume, mount_point) self.target.fs.mount(mount_point, fs) diff --git a/tests/plugins/os/unix/test__os.py b/tests/plugins/os/unix/test__os.py index b14754b73..da1296a8a 100644 --- a/tests/plugins/os/unix/test__os.py +++ b/tests/plugins/os/unix/test__os.py @@ -1,12 +1,13 @@ import tempfile from io import BytesIO from pathlib import Path +from unittest.mock import Mock, patch from uuid import UUID import pytest from dissect.target.filesystem import VirtualFilesystem -from dissect.target.plugins.os.unix._os import parse_fstab +from dissect.target.plugins.os.unix._os import UnixPlugin, parse_fstab from dissect.target.target import Target FSTAB_CONTENT = """ @@ -44,7 +45,7 @@ """ # noqa -def test_parse_fstab(tmp_path): +def test_parse_fstab(tmp_path: Path) -> None: with tempfile.NamedTemporaryFile(dir=tmp_path, delete=False) as tf: tf.write(FSTAB_CONTENT.encode("ascii")) tf.close() @@ -71,6 +72,29 @@ def test_parse_fstab(tmp_path): } +def test_mount_volume_name_regression(fs_unix: VirtualFilesystem) -> None: + mock_fs = Mock() + mock_vol = Mock() + + mock_vol.name = "test-volume" + + mock_fs.__type__ = "ext" + mock_fs.extfs.volume_name = "ext-volume" + mock_fs.volume = mock_vol + mock_fs.exists.return_value = False + + for expected_volume_name in ["test-volume", "ext-volume"]: + with patch( + "dissect.target.plugins.os.unix._os.parse_fstab", + return_value=[(None, expected_volume_name, "/mnt", "auto", "default")], + ): + target = Target() + target.filesystems.add(mock_fs) + UnixPlugin.create(target, fs_unix) + + assert target.fs.mounts["/mnt"] == mock_fs + + @pytest.mark.parametrize( "path, expected_hostname, expected_domain, file_content", [