Skip to content

Commit 2f30c9e

Browse files
committed
scripts/forensic-mark-readonly: Add support for loop devices
Signed-off-by: Glenn Washburn <[email protected]>
1 parent 4a99995 commit 2f30c9e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

config/files/GRMLBASE/etc/udev/scripts/forensic-mark-readonly

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,23 @@ trap cleanup ERR 2>/dev/null ||:
6363

6464
base_device=$(base "${BLOCK_DEVICE}")
6565
if [ -n "${SYS_DIR}" ] && [ -n "${base_device}" ] ; then
66+
if [ -z "${base_device##loop[0-9]*}" ] ; then
67+
if [ -e "${SYS_DIR}"/"${base_device}"/loop/backing_file ] ; then
68+
backingfile=$(cat "${SYS_DIR}"/"${base_device}"/loop/backing_file)
69+
parent_devices=$(findmnt -n -o source --target "$backingfile")
70+
71+
# Set loop device to read-write, will be set to readonly later if need be
72+
blockdev --setrw "${BLOCK_DEVICE}"
73+
74+
# Check if either the backing file's block device or filesystem are read-only
75+
if is_ro "$parent_devices" || findmnt -n -o OPTIONS --target "$backingfile" | grep -E '^ro,|,ro,|,ro$'; then
76+
blockdev --setro "${BLOCK_DEVICE}"
77+
logger -t forensic-mark-readonly "setting '${BLOCK_DEVICE}' with backing file (${backingfile}) (parent devices: '${parent_devices}') to read-only as its parent is present or mount point ($(findmnt -n -o TARGET --target "$backingfile")) is read-only"
78+
fi
79+
exit 0
80+
fi
81+
fi
82+
6683
tmp_parents="$(readlink -f "${SYS_DIR}"/*/"${base_device}")"
6784
if [ -z "${tmp_parents}" ]; then
6885
tmp_parents=

0 commit comments

Comments
 (0)