@@ -27,7 +27,12 @@ dir() {
2727}
2828
2929is_ro () {
30- [ " $( blockdev --getro " $1 " ) " = " 1" ] && return 0 || return 1
30+ # ASSUMPTION: Device paths can not contain spaces
31+ while [ " $# " -gt 0 ]; do
32+ [ " $( blockdev --getro " $1 " ) " = " 1" ] && return 0
33+ shift
34+ done
35+ return 1
3136}
3237
3338if [ -z " ${1:- } " ] ; then
4752
4853SYS_DIR=" $( get_blockdev_dir) "
4954
55+ patternsfile=
56+ cleanup () {
57+ if [ -f " $patternsfile " ] ; then
58+ rm " $patternsfile "
59+ fi
60+ }
61+ trap cleanup EXIT
62+
5063base_device=$( base " ${BLOCK_DEVICE} " )
5164if [ -n " ${SYS_DIR} " ] && [ -n " ${base_device} " ] ; then
52- tmp_parent=" $( readlink -f " ${SYS_DIR} " /* /" ${base_device} " ) "
53- if [ -z " ${tmp_parent} " ]; then
54- tmp_parent=$( dir " ${SYS_DIR} " /* /holders/" ${base_device} " )
65+ tmp_parents=" $( readlink -f " ${SYS_DIR} " /* /" ${base_device} " ) "
66+ if [ -z " ${tmp_parents} " ]; then
67+ tmp_parents=
68+ for DEV in " ${SYS_DIR} " /* /holders/" ${base_device} " ; do
69+ [ -d " $DEV " ] && tmp_parents=" ${tmp_parents: +${tmp_parents} } $( dir " $DEV " ) "
70+ done
5571 fi
56- if [ -d " ${tmp_parent} " ] ; then
57- parent_device=$( dir " ${tmp_parent} " )
58- parent_device=$( base " ${parent_device} " )
59- parent_device=" /dev/${parent_device} "
60- fi
61- unset tmp_parent
72+ # ASSUMPTION: There should be no spaces in device names.
73+ parent_devices=
74+ for tmp_parent in ${tmp_parents} ; do
75+ if [ -d " ${tmp_parent} " ] ; then
76+ tmp_parent=$( dir " ${tmp_parent} " )
77+ tmp_parent=$( base " ${tmp_parent} " )
78+ tmp_parent=" /dev/${tmp_parent} "
79+ parent_devices=" ${parent_devices: +${parent_devices} }${tmp_parent} "
80+ fi
81+ done
82+ unset tmp_parent tmp_parents
6283fi
6384
6485# support configuration file
@@ -75,9 +96,11 @@ if [ -r /etc/grml/forensic.conf ] ; then
7596 fi
7697
7798 if [ -n " ${READONLY_IGNORE:- } " ] ; then
78- if [ -n " ${parent_device} " ] ; then
79- if echo " ${READONLY_IGNORE:- } " | grep -qw " ${parent_device} " ; then
80- logger -t forensic-mark-readonly " not setting '${BLOCK_DEVICE} ' (parent device: '${parent_device} ') to read-only as its parent is present in ignore list"
99+ if [ -n " ${parent_devices} " ] ; then
100+ patternsfile=$( mktemp /dev/shm/forensic-mark-readonly.patterns.XXXXXX)
101+ echo " ${parent_devices} " | sed " s| |\n|" > " ${patternsfile} "
102+ if echo " ${READONLY_IGNORE:- } " | grep -qw -F " $patternsfile " ; then
103+ logger -t forensic-mark-readonly " not setting '${BLOCK_DEVICE} ' (parent devices: '${parent_devices} ') to read-only as its parent is present in ignore list"
81104 exit 0
82105 fi
83106 fi
90113
91114if is_ro " ${BLOCK_DEVICE} " ; then
92115 logger -t forensic-mark-readonly " device ${BLOCK_DEVICE} already set to read-only mode, nothing to do"
93- elif [ -n " ${parent_device } " ] && ! is_ro " ${parent_device } " ; then
94- logger -t forensic-mark-readonly " parent device ${parent_device} is set read-write, not modifying"
116+ elif [ -n " ${parent_devices } " ] && ! is_ro " ${parent_devices } " ; then
117+ logger -t forensic-mark-readonly " all parent devices ( ${parent_devices} ) are set read-write, not modifying"
95118 logger -t forensic-mark-readonly " use blockdev --setro ${BLOCK_DEVICE} to set it manually"
96119else
97120 logger -t forensic-mark-readonly " setting ${BLOCK_DEVICE} [${ID_SERIAL} ] to read-only"
0 commit comments