2011-09-29 13:49:52 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
NAME=${DEVNAME#/dev/}
|
|
|
|
DESC="${ID_MODEL} (${ID_FS_LABEL})"
|
2011-10-01 02:55:51 +02:00
|
|
|
SIZE=$[ $(cat /sys/$DEVPATH/size) * 512 ]
|
2011-09-29 13:49:52 +02:00
|
|
|
MODE=w
|
|
|
|
XS_KEY="qubes-block-devices/$NAME"
|
|
|
|
|
2012-06-06 02:12:10 +02:00
|
|
|
xs_remove() {
|
|
|
|
if [ "$QUBES_EXPOSED" == "1" ]; then
|
|
|
|
xenstore-rm "$XS_KEY"
|
|
|
|
fi
|
|
|
|
echo QUBES_EXPOSED=0
|
|
|
|
}
|
|
|
|
|
2011-09-29 13:49:52 +02:00
|
|
|
# Ignore mounted...
|
|
|
|
if fgrep -q $DEVNAME /proc/mounts; then
|
2012-06-06 02:12:10 +02:00
|
|
|
xs_remove
|
2011-09-29 13:49:52 +02:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
# ... and used by device-mapper
|
|
|
|
if [ -n "`ls -A /sys/$DEVPATH/holders 2> /dev/null`" ]; then
|
2012-06-06 02:12:10 +02:00
|
|
|
xs_remove
|
2011-09-29 13:49:52 +02:00
|
|
|
exit 0
|
|
|
|
fi
|
2012-03-26 20:29:49 +02:00
|
|
|
# ... and "empty" loop devices
|
|
|
|
if [ "$MAJOR" -eq 7 -a ! -d /sys/$DEVPATH/loop ]; then
|
2012-06-06 02:12:10 +02:00
|
|
|
xs_remove
|
2012-03-26 20:29:49 +02:00
|
|
|
exit 0
|
|
|
|
fi
|
2011-09-29 13:49:52 +02:00
|
|
|
|
|
|
|
# Special case for CD
|
|
|
|
if [ "$ID_TYPE" = "cd" ]; then
|
2011-09-30 11:20:03 +02:00
|
|
|
if [ "$ID_CDROM_MEDIA" != "1" ]; then
|
2011-09-29 13:49:52 +02:00
|
|
|
# Hide empty cdrom drive
|
2012-06-06 02:12:10 +02:00
|
|
|
xs_remove
|
2011-09-29 13:49:52 +02:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
MODE=r
|
|
|
|
fi
|
2012-03-26 20:29:49 +02:00
|
|
|
|
|
|
|
# Special description for loop devices
|
|
|
|
if [ -d /sys/$DEVPATH/loop ]; then
|
|
|
|
DESC=$(cat /sys/$DEVPATH/loop/backing_file)
|
|
|
|
fi
|
2013-01-27 00:02:30 +01:00
|
|
|
|
|
|
|
# Get lock only in dom0 - there are so many block devices so it causes xenstore
|
|
|
|
# deadlocks sometimes.
|
|
|
|
if [ -f /etc/qubes-release ]; then
|
|
|
|
# Skip xenstore-write if cannot obtain lock. This can mean very early system startup
|
|
|
|
# stage without /run mounted (or populated). Devices will be rediscovered later
|
|
|
|
# by qubes-core startup script.
|
|
|
|
exec 9>>/var/run/qubes/block-xenstore.lock || exit 0
|
|
|
|
flock 9
|
|
|
|
fi
|
|
|
|
|
2011-09-29 13:49:52 +02:00
|
|
|
xenstore-write "$XS_KEY/desc" "$DESC" "$XS_KEY/size" "$SIZE" "$XS_KEY/mode" "$MODE"
|
2012-06-06 02:12:10 +02:00
|
|
|
echo QUBES_EXPOSED=1
|
2011-09-29 13:56:29 +02:00
|
|
|
|
|
|
|
# Make sure that block backend is loaded
|
2011-12-27 17:31:15 +01:00
|
|
|
/sbin/modprobe xen-blkback 2> /dev/null || /sbin/modprobe blkbk
|