Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion udev/udev-block-add-change
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ NAME=${DEVNAME#/dev/}
DESC="`echo "${ID_MODEL} (${ID_FS_LABEL})" | iconv -f utf8 -t ascii//TRANSLIT`"
SIZE=$[ $(cat /sys/$DEVPATH/size) * 512 ]
MODE=w
QDB_KEY="/qubes-block-devices/$NAME"
QDB_KEY="/qubes-block-devices/$QNAME"

xs_remove() {
if is_attached /sys$DEVPATH; then
Expand Down
2 changes: 1 addition & 1 deletion udev/udev-block-remove
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

NAME=${DEVNAME#/dev/}
QDB_KEY="/qubes-block-devices/$NAME"
QDB_KEY="/qubes-block-devices/$QNAME"
# Trailing slash is intentional - it will remove the whole directory, instead of
# a single base entry
qubesdb-rm "$QDB_KEY/"
Expand Down
15 changes: 15 additions & 0 deletions udev/udev-qubes-block.rules
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ KERNEL=="dm-*", ENV{DM_NAME}=="snapshot-*", GOTO="qubes_block_end"
KERNEL=="dm-*", ENV{DM_NAME}=="origin-*", GOTO="qubes_block_end"
KERNEL=="dm-*", ENV{DM_NAME}=="", GOTO="qubes_block_end"

# generate cropped uuid and populate qname variable
ACTION=="add", ENV{ID_SERIAL}=="?*", PROGRAM="/usr/bin/uuidgen -s -n @oid -N $env{ID_SERIAL}$env{PARTN}", ENV{QNAME}="$result"

# check if device already exist in qubesdb
ACTION=="add", ENV{QNAME}=="?*", PROGRAM="/bin/sh -c '/usr/bin/qubesdb-read -q /qubes-block-devices/$env{QNAME}/desc || echo 1'", RESULT=="1", GOTO="skip_qname_fallback"

# fallback for duplicates
ACTION=="add", PROGRAM="/usr/bin/basename $env{DEVNAME}", ENV{QNAME}="$result"

LABEL="skip_qname_fallback"

ACTION=="add", SYMLINK+="$env{QNAME}"

IMPORT{db}="QNAME"

ACTION=="add", RUN+="/usr/lib/qubes/udev-block-add-change"
ACTION=="change", RUN+="/usr/lib/qubes/udev-block-add-change"
ACTION=="remove", RUN+="/usr/lib/qubes/udev-block-remove"
Expand Down
13 changes: 13 additions & 0 deletions udev/udev-qubes-usb.rules
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ SUBSYSTEM!="usb", GOTO="qubes_usb_end"
# ignore qemu emulated devices in HVM
ENV{ID_VENDOR}=="QEMU", GOTO="qubes_usb_end"

# use vendor and model ids to set qname variable
ACTION=="add", ENV{ID_VENDOR_ID}=="?*", ENV{ID_MODEL_ID}=="?*", ENV{QNAME}="0x$env{ID_VENDOR_ID}_0x$env{ID_MODEL_ID}"

# check if device already exist in qubesdb
ACTION=="add", ENV{QNAME}=="?*", PROGRAM="/bin/sh -c '/usr/bin/qubesdb-read -q /qubes-usb-devices/$env{QNAME}/desc || echo 1'", RESULT=="1", GOTO="skip_qname_fallback"

# fallback for device duplicates
ACTION=="add", PROGRAM="sh -c 'basename $env{DEVPATH} | tr . _'", ENV{QNAME}="$result"

LABEL="skip_qname_fallback"

IMPORT{db}="QNAME"

ACTION=="add", IMPORT{program}="/usr/lib/qubes/udev-usb-add-change"
ACTION=="change", IMPORT{program}="/usr/lib/qubes/udev-usb-add-change"
ACTION=="remove", RUN+="/usr/lib/qubes/udev-usb-remove"
Expand Down
5 changes: 1 addition & 4 deletions udev/udev-usb-add-change
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
[ "`echo $TYPE | cut -f1 -d/`" = "9" ] && exit 0
[ "$DEVTYPE" != "usb_device" ] && exit 0

# 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.
Expand All @@ -29,7 +26,7 @@ if echo $DEVPATH | grep -q /vhci_hcd; then
exit 0
fi

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

qubesdb-write "$QDB_KEY/desc" "$DESC"
qubesdb-write "$QDB_KEY/usb-ver" "$VERSION"
Expand Down
3 changes: 1 addition & 2 deletions udev/udev-usb-remove
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
# FIXME: Ignore USB hubs.
[ "`echo $TYPE | cut -f1 -d/`" = "9" ] && exit 0

NAME=`basename ${DEVPATH} | tr . _`
QDB_KEY="/qubes-usb-devices/$NAME/"
QDB_KEY="/qubes-usb-devices/$QNAME/"

qubesdb-rm "$QDB_KEY"
qubesdb-write /qubes-usb-devices ''