block.qubes 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/bin/bash
  2. HOTPLUG_STORE="/var/run/xen-hotplug/${XENBUS_PATH//\//-}"
  3. hd_arr[10]=a
  4. hd_arr[11]=b
  5. hd_arr[12]=c
  6. hd_arr[13]=d
  7. hd_arr[14]=e
  8. hd_arr[15]=f
  9. hexdigit()
  10. {
  11. if [ $1 -lt 10 ] ; then
  12. RET=$1
  13. else
  14. RET=${hd_arr[$1]}
  15. fi
  16. }
  17. hexnumber()
  18. {
  19. hexdigit $(($1/16))
  20. ret2=$RET
  21. hexdigit $(($1%16))
  22. HEXNUMBER="$ret2"$RET
  23. }
  24. process()
  25. {
  26. if ! [ "x""$1" = "xfile" ] ; then
  27. exec flock /var/run/qubes/hotplug-block /etc/xen/scripts/block $ORIG_ARGS
  28. fi
  29. while true ; do
  30. dev=$(losetup -f --show $2)
  31. if [ -n "$dev" ] ; then break ; fi
  32. done
  33. hexnumber ${dev:9:70}
  34. xenstore-write "$XENBUS_PATH/node" "$dev" \
  35. "$XENBUS_PATH/physical-device" "7:"$HEXNUMBER \
  36. "$XENBUS_PATH/hotplug-status" connected
  37. echo "$dev" > "$HOTPLUG_STORE-node"
  38. echo "file" > "$HOTPLUG_STORE-type"
  39. }
  40. #exec 2>>/tmp/block.$$
  41. #set -x
  42. export PATH="/sbin:/bin:/usr/bin:/usr/sbin:$PATH"
  43. XENBUS_PATH="${XENBUS_PATH:?}"
  44. if ! [ "$1" = "add" ] || ! [ -f /var/run/qubes/fast-block-attach ] ; then
  45. exec flock /var/run/qubes/hotplug-block /etc/xen/scripts/block "$@"
  46. fi
  47. ORIG_ARGS="$@"
  48. vars=$(xenstore-read "$XENBUS_PATH/type" "$XENBUS_PATH/params")
  49. process $vars
  50. exit 0