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"
|
|
|
|
|
|
|
|
# Ignore mounted...
|
|
|
|
if fgrep -q $DEVNAME /proc/mounts; then
|
|
|
|
xenstore-rm "$XS_KEY"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
# ... and used by device-mapper
|
|
|
|
if [ -n "`ls -A /sys/$DEVPATH/holders 2> /dev/null`" ]; then
|
|
|
|
xenstore-rm "$XS_KEY"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# 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
|
|
|
|
xenstore-rm "$XS_KEY"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
MODE=r
|
|
|
|
fi
|
|
|
|
xenstore-write "$XS_KEY/desc" "$DESC" "$XS_KEY/size" "$SIZE" "$XS_KEY/mode" "$MODE"
|
2011-09-29 13:56:29 +02:00
|
|
|
|
|
|
|
# Make sure that block backend is loaded
|
|
|
|
modprobe xen-blkback 2> /dev/null || modprobe blkbk
|