linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* write_cd_rules: identity-based persistence
@ 2006-11-24 18:58 Bryan Kadzban
  2006-11-26 14:31 ` Marco d'Itri
  2006-11-26 19:13 ` Bryan Kadzban
  0 siblings, 2 replies; 3+ messages in thread
From: Bryan Kadzban @ 2006-11-24 18:58 UTC (permalink / raw)
  To: linux-hotplug


[-- Attachment #1.1.1: Type: text/plain, Size: 738 bytes --]

This is a sort of follow-up of my path-based persistence patch for net
devices; it's the opposite type of addition for CD symlinks.  Passing
by-path or by-id to the write_cd_rules script tells it to generate the
original path-based rules, or ID-based rules.

(ID-based rules use $ID_SERIAL if available, and the combination of
$ID_MODEL and $ID_REVISION otherwise.  All are provided by ata_id, if
they're provided by the CD drive, so ata_id needs to be run before
write_cd_rules.)

If no $1 is provided, it gets set to by-path, which avoids having to
change distros' current rules files.  I've also changed the
75-cd-aliases-generator.rules file in this patch, but this change is not
strictly necessary for the script to work.

Comments?

[-- Attachment #1.1.2: udev-103-cd-by-id.patch --]
[-- Type: text/plain, Size: 1690 bytes --]

--- udev-103/extras/rule_generator/75-cd-aliases-generator.rules	2006-10-20 08:43:35.000000000 -0400
+++ udev-103-patched/extras/rule_generator/75-cd-aliases-generator.rules	2006-11-24 13:49:08.000000000 -0500
@@ -1,3 +1,3 @@
 # these rules generate rules for the /dev/{cdrom,dvd,...} symlinks
 
-ACTION=="add", SUBSYSTEM=="block", ENV{ID_CDROM}=="?*", ENV{GENERATED}!="?*", PROGRAM="write_cd_rules", SYMLINK+="%c"
+ACTION=="add", SUBSYSTEM=="block", ENV{ID_CDROM}=="?*", ENV{GENERATED}!="?*", PROGRAM="write_cd_rules by-path", SYMLINK+="%c"
--- udev-103/extras/rule_generator/write_cd_rules	2006-10-20 08:43:35.000000000 -0400
+++ udev-103-patched/extras/rule_generator/write_cd_rules	2006-11-24 13:45:43.000000000 -0500
@@ -50,6 +50,35 @@
 	exit 1
 fi
 
+[ -z "$1" ] && set -- "by-path"
+
+case "$1" in
+	by-path)
+		if [ -z "$ID_PATH" ]; then
+			echo "$DEVPATH not supported by path_id.  by-id may work." >&2
+			exit 1
+		fi
+
+		RULE="ENV{ID_PATH}==\"$ID_PATH\""
+		;;
+	by-id)
+		if [ "$ID_SERIAL" ]; then
+			RULE="ENV{ID_SERIAL}==\"$ID_SERIAL\""
+		else
+			if [ -z "$ID_MODEL" -o -z "$ID_REVISION" ]; then
+				echo "$DEVPATH not supported by ata_id.  by-path may work." >&2
+				exit 1
+			fi
+
+			RULE="ENV{ID_MODEL}==\"$ID_MODEL\", ENV{ID_REVISION}==\"$ID_REVISION\""
+		fi
+		;;
+	*)
+		echo "Invalid first argument (must be either by-path or by-id)." >&2
+		exit 1
+		;;
+esac
+
 # Prevent concurrent processes from modifying the file at the same time.
 lock_rules_file
 
@@ -58,7 +87,7 @@
 
 link_num=$(find_next_available 'cdrom[0-9]*')
 
-match="ENV{ID_CDROM}==\"?*\", ENV{ID_PATH}==\"$ID_PATH\""
+match="ENV{ID_CDROM}==\"?*\", $RULE"
 
 comment="$ID_MODEL ($ID_PATH)"
 

[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 258 bytes --]

[-- Attachment #2: Type: text/plain, Size: 347 bytes --]

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

[-- Attachment #3: Type: text/plain, Size: 226 bytes --]

_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-11-26 19:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-11-24 18:58 write_cd_rules: identity-based persistence Bryan Kadzban
2006-11-26 14:31 ` Marco d'Itri
2006-11-26 19:13 ` Bryan Kadzban

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).