block_add_change 774 B

1234567891011121314151617181920212223242526272829303132
  1. #!/bin/bash
  2. NAME=${DEVNAME#/dev/}
  3. DESC="${ID_MODEL} (${ID_FS_LABEL})"
  4. SIZE=$[ $(cat /sys/$DEVPATH/size) * 512 ]
  5. MODE=w
  6. XS_KEY="qubes-block-devices/$NAME"
  7. # Ignore mounted...
  8. if fgrep -q $DEVNAME /proc/mounts; then
  9. xenstore-rm "$XS_KEY"
  10. exit 0
  11. fi
  12. # ... and used by device-mapper
  13. if [ -n "`ls -A /sys/$DEVPATH/holders 2> /dev/null`" ]; then
  14. xenstore-rm "$XS_KEY"
  15. exit 0
  16. fi
  17. # Special case for CD
  18. if [ "$ID_TYPE" = "cd" ]; then
  19. if [ "$ID_CDROM_MEDIA" != "1" ]; then
  20. # Hide empty cdrom drive
  21. xenstore-rm "$XS_KEY"
  22. exit 0
  23. fi
  24. MODE=r
  25. fi
  26. xenstore-write "$XS_KEY/desc" "$DESC" "$XS_KEY/size" "$SIZE" "$XS_KEY/mode" "$MODE"
  27. # Make sure that block backend is loaded
  28. /sbin/modprobe xen-blkback 2> /dev/null || /sbin/modprobe blkbk