Skip to content

Commit 1b113bd

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

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
@@ -62,6 +62,23 @@ trap cleanup EXIT
6262

6363
base_device=$(base "${BLOCK_DEVICE}")
6464
if [ -n "${SYS_DIR}" ] && [ -n "${base_device}" ] ; then
65+
if [ -z "${base_device##loop[0-9]*}" ] ; then
66+
if [ -e "${SYS_DIR}"/"${base_device}"/loop/backing_file ] ; then
67+
backingfile=$(cat "${SYS_DIR}"/"${base_device}"/loop/backing_file)
68+
parent_devices=$(findmnt -n -o source --target "$backingfile")
69+
70+
# Set loop device to read-write, will be set to readonly later if need be
71+
blockdev --setrw "${BLOCK_DEVICE}"
72+
73+
# Check if either the backing file's block device or filesystem are read-only
74+
if is_ro "$parent_devices" || findmnt -n -o OPTIONS --target "$backingfile" | grep -E '^ro,|,ro,|,ro$'; then
75+
blockdev --setro "${BLOCK_DEVICE}"
76+
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"
77+
fi
78+
exit 0
79+
fi
80+
fi
81+
6582
tmp_parents="$(readlink -f "${SYS_DIR}"/*/"${base_device}")"
6683
if [ -z "${tmp_parents}" ]; then
6784
tmp_parents=

0 commit comments

Comments
 (0)