# these rules generate rules for the /dev/{cdrom,dvd,...} symlinks
-# the path of removable devices changes frequently
-ACTION=="add", SUBSYSTEM=="block", SUBSYSTEMS=="usb|ieee1394", ENV{ID_CDROM}=="?*", ENV{GENERATED}!="?*", PROGRAM="write_cd_rules by-id", SYMLINK+="%c"
+# the "path" of usb/ieee1394 devices changes frequently, use "id"
+ACTION=="add", SUBSYSTEM=="block", SUBSYSTEMS=="usb|ieee1394", ENV{ID_CDROM}=="?*", ENV{GENERATED}!="?*", \
+ PROGRAM="write_cd_rules by-id", SYMLINK+="%c", GOTO="persistent_cd_end"
ACTION=="add", SUBSYSTEM=="block", ENV{ID_CDROM}=="?*", ENV{GENERATED}!="?*", PROGRAM="write_cd_rules", SYMLINK+="%c"
+
+LABEL="persistent_cd_end"
link_num=$(find_next_available 'cdrom[0-9]*')
-match="ENV{ID_CDROM}==\"?*\", $RULE"
+match="SUBSYSTEM==\"block\", ENV{ID_CDROM}==\"?*\", $RULE"
comment="$ID_MODEL ($ID_PATH)"
write_rule "$match" "dvd$link_num"
[ "$ID_CDROM_DVD_R" -o "$ID_CDROM_DVD_RW" -o "$ID_CDROM_DVD_RAM" ] && \
write_rule "$match" "dvdrw$link_num"
+echo >> $RULES_FILE
unlock_rules_file