From 3ad3bb245579a1a85d98ab67c8fd68936423dd89 Mon Sep 17 00:00:00 2001 From: Piotr Bartman Date: Thu, 30 Nov 2023 02:32:37 +0100 Subject: [PATCH] q-dev: add data to qubesdb needed by new API 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 --- udev/udev-block-add-change | 7 +++++++ udev/udev-block-remove | 1 + udev/udev-usb-add-change | 16 ++++++++-------- udev/udev-usb-remove | 1 + 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/udev/udev-block-add-change b/udev/udev-block-add-change index 37c73194..7add05c0 100755 --- a/udev/udev-block-add-change +++ b/udev/udev-block-add-change @@ -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 diff --git a/udev/udev-block-remove b/udev/udev-block-remove index ed826d08..8fbfffb1 100755 --- a/udev/udev-block-remove +++ b/udev/udev-block-remove @@ -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 diff --git a/udev/udev-usb-add-change b/udev/udev-usb-add-change index 1e0aa384..36144441 100755 --- a/udev/udev-usb-add-change +++ b/udev/udev-usb-add-change @@ -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 .` @@ -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 diff --git a/udev/udev-usb-remove b/udev/udev-usb-remove index 5fbb46e1..a639488f 100755 --- a/udev/udev-usb-remove +++ b/udev/udev-usb-remove @@ -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 ''