Skip to content

Commit

Permalink
q-dev: add data to qubesdb needed by new API
Browse files Browse the repository at this point in the history
include interface number in parent info
add usb interfaces to qubesdb
add parent of block device
add explanation comments
add usb vendor_enc
vendor_enc contains name of vendor submitted directly by the device
  • Loading branch information
piotrbartman committed May 8, 2024
1 parent 5582539 commit 3ad3bb2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
7 changes: 7 additions & 0 deletions udev/udev-block-add-change
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,18 @@ if [ -n "$DM_NAME" ]; then
DESC="$DM_NAME"
fi

if [ -f /sys$DEVPATH/partition ]; then
parent=$(basename "$(dirname "$DEVPATH")")
elif echo "$DEVPATH" | grep -q '/host'; then
parent=$(basename "$(sed 's|/host.*$||' <<< "$DEVPATH")")
fi

# The last one is meant to trigger watches
qubesdb-write \
"$QDB_KEY/desc" "$DESC" \
"$QDB_KEY/size" "$SIZE" \
"$QDB_KEY/mode" "$MODE" \
"$QDB_KEY/parent" "$parent" \
/qubes-block-devices ''

# Make sure that block backend is loaded
Expand Down
1 change: 1 addition & 0 deletions udev/udev-block-remove
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ QDB_KEY="/qubes-block-devices/$NAME"
# Trailing slash is intentional - it will remove the whole directory, instead of
# a single base entry
qubesdb-rm "$QDB_KEY/"
# This is meant to trigger watches
qubesdb-write /qubes-block-devices ''

if [ -r /run/qubes/block-slave-cache-$NAME ]; then
Expand Down
16 changes: 8 additions & 8 deletions udev/udev-usb-add-change
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@
# qubesdb doesn't allow dot in key name
XSNAME=`basename ${DEVPATH} | tr . _`

# FIXME: For some devices (my Cherry keyboard) ID_SERIAL does not
# contain proper human-readable name, should find better method to
# build devide description.
#DESC=`python -c "dev='%d-%d' % (int('${BUSNUM}'.lstrip('0')), (int('${DEVNUM}'.lstrip('0'))-1)); from xen.util import vusb_util; print vusb_util.get_usbdevice_info(dev);"`
DESC="${ID_VENDOR_ID}:${ID_MODEL_ID} ${ID_SERIAL}"
# in general ID_SERIAL = "${ID_VENDOR}_${ID_MODEL}_${ID_SERIAL_SHORT}"
DESC="${ID_VENDOR_ID}:${ID_MODEL_ID} ${ID_VENDOR_ENC} ${ID_MODEL_ENC} ${ID_SERIAL_SHORT}"

VERSION=`cat /sys/$DEVPATH/version | tr -d ' '|cut -f 1 -d .`

Expand All @@ -31,9 +28,12 @@ fi

QDB_KEY="/qubes-usb-devices/$XSNAME"

qubesdb-write "$QDB_KEY/desc" "$DESC"
qubesdb-write "$QDB_KEY/usb-ver" "$VERSION"
qubesdb-write /qubes-usb-devices ''
# The last one is meant to trigger watches
qubesdb-write \
"$QDB_KEY/desc" "$DESC" \
"$QDB_KEY/usb-ver" "$VERSION" \
"$QDB_KEY/interfaces" "$ID_USB_INTERFACES" \
/qubes-usb-devices ''

# Make sure PVUSB backend driver is loaded.
/sbin/modprobe xen-usbback 2> /dev/null || true
1 change: 1 addition & 0 deletions udev/udev-usb-remove
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ NAME=`basename ${DEVPATH} | tr . _`
QDB_KEY="/qubes-usb-devices/$NAME/"

qubesdb-rm "$QDB_KEY"
# This is meant to trigger watches
qubesdb-write /qubes-usb-devices ''

0 comments on commit 3ad3bb2

Please sign in to comment.