projects
/
grml-udev-config.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
8dce736
)
Only set device to read-only if parent is also read-only
author
Ulrich Dangel
<uli@spamt.net>
Thu, 11 Mar 2010 19:57:43 +0000
(20:57 +0100)
committer
Michael Prokop
<mika@grml.org>
Fri, 19 Mar 2010 00:41:19 +0000
(
01:41
+0100)
scripts/forensic-mark-readonly
patch
|
blob
|
history
diff --git
a/scripts/forensic-mark-readonly
b/scripts/forensic-mark-readonly
index
299c661
..
909a512
100755
(executable)
--- a/
scripts/forensic-mark-readonly
+++ b/
scripts/forensic-mark-readonly
@@
-6,12
+6,45
@@
# License: This file is licensed under the GPL v2 or any later version.
################################################################################
# License: This file is licensed under the GPL v2 or any later version.
################################################################################
+function get_blockdev_dir() {
+ for dir in /sys/subsystem/block/ /sys/class/block/ /sys/block/ ; do
+ [ -d $dir ] && echo $dir && return
+ done
+}
+
+function base() {
+ echo ${1##*/}
+}
+function dir() {
+ echo ${1%/*}
+}
+
+function is_ro() {
+ [ "$(blockdev --getro $1)" = "1" ] && return 0 || return 1
+
+
+}
# check for forensic/readonly bootoption
# check for forensic/readonly bootoption
-if
grep -qe forensic -qe readonly /proc/cmdline
; then
+if
:
; then
# we get $DEVNAME via udev's environment
if [ -n "$DEVNAME" ] ; then
# we get $DEVNAME via udev's environment
if [ -n "$DEVNAME" ] ; then
- if [ "$(blockdev --getro $DEVNAME)" = "1" ] ; then
+ NAME=$(base $DEVNAME)
+ SYS_DIR=$(get_blockdev_dir)
+
+ if [ -n $SYS_DIR ] && [ -n $NAME ] ; then
+ DEVICE=$SYS_DIR/*/$NAME
+ if [ -d $DEVICE ] ; then
+ PARENT=$(dir $DEVICE)
+ PARENT=$(base $PARENT)
+ PARENT=/dev/$PARENT
+ fi
+ fi
+
+ if is_ro "$DEVNAME" ; then
logger "forensic mode: device $DEVNAME already set to readonly mode, nothing to do"
logger "forensic mode: device $DEVNAME already set to readonly mode, nothing to do"
+ elif [ -n "$PARENT" ] && ! is_ro "$PARENT" ; then
+ logger "forensic mode: parent device $PARENT is set readwrite, not modifying"
+ logger "forensic mode: use blockdev --setro $DEVNAME to set it manually"
else
logger "forensic mode: setting $DEVNAME [$ID_SERIAL] to readonly"
if blockdev --setro "$DEVNAME" ; then
else
logger "forensic mode: setting $DEVNAME [$ID_SERIAL] to readonly"
if blockdev --setro "$DEVNAME" ; then