12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- #!/bin/bash
- HOTPLUG_STORE="/var/run/xen-hotplug/${XENBUS_PATH//\//-}"
- hd_arr[10]=a
- hd_arr[11]=b
- hd_arr[12]=c
- hd_arr[13]=d
- hd_arr[14]=e
- hd_arr[15]=f
- hexdigit()
- {
- if [ $1 -lt 10 ] ; then
- RET=$1
- else
- RET=${hd_arr[$1]}
- fi
- }
- hexnumber()
- {
- hexdigit $(($1/16))
- ret2=$RET
- hexdigit $(($1%16))
- HEXNUMBER="$ret2"$RET
- }
- process()
- {
- if ! [ "x""$1" = "xfile" ] ; then
- exec flock /var/run/qubes/hotplug-block /etc/xen/scripts/block $ORIG_ARGS
- fi
- while true ; do
- dev=$(losetup -f --show $2)
- if [ -n "$dev" ] ; then break ; fi
- done
- hexnumber ${dev:9:70}
- xenstore-write "$XENBUS_PATH/node" "$dev" \
- "$XENBUS_PATH/physical-device" "7:"$HEXNUMBER \
- "$XENBUS_PATH/hotplug-status" connected
- echo "$dev" > "$HOTPLUG_STORE-node"
- echo "file" > "$HOTPLUG_STORE-type"
- }
- #exec 2>>/tmp/block.$$
- #set -x
- export PATH="/sbin:/bin:/usr/bin:/usr/sbin:$PATH"
- XENBUS_PATH="${XENBUS_PATH:?}"
- if ! [ "$1" = "add" ] || ! [ -f /var/run/qubes/fast-block-attach ] ; then
- script=$(xenstore-read "$XENBUS_PATH/script")
- exec flock /var/run/qubes/hotplug-block $script "$@"
- fi
- ORIG_ARGS="$@"
-
- vars=$(xenstore-read "$XENBUS_PATH/type" "$XENBUS_PATH/params")
- process $vars
- exit 0
|