Author: alexander
Date: 2006-03-31 20:37:43 -0700 (Fri, 31 Mar 2006)
New Revision: 1456

Added:
   branches/udev_update/packages/udev/90-cdrom.rules
   branches/udev_update/packages/udev/92-cdalias-generator.rules
   branches/udev_update/packages/udev/cdalias-generator
Modified:
   branches/udev_update/packages/udev/Makefile
Log:
Testing persistent CD aliases

Added: branches/udev_update/packages/udev/90-cdrom.rules
===================================================================
--- branches/udev_update/packages/udev/90-cdrom.rules                           
(rev 0)
+++ branches/udev_update/packages/udev/90-cdrom.rules   2006-04-01 03:37:43 UTC 
(rev 1456)
@@ -0,0 +1,3 @@
+BUS=="ide", KERNEL=="hd[a-z]|pcd[0-9]*", DRIVER=="ide-cdrom|pcd", 
IMPORT{program}="/sbin/cdrom_id --export $tempnode"
+KERNEL=="scd[0-9]*", IMPORT{program}="/sbin/cdrom_id --export $tempnode"
+ENV{ID_CDROM}=="?*", GROUP="cdrom"

Added: branches/udev_update/packages/udev/92-cdalias-generator.rules
===================================================================
--- branches/udev_update/packages/udev/92-cdalias-generator.rules               
                (rev 0)
+++ branches/udev_update/packages/udev/92-cdalias-generator.rules       
2006-04-01 03:37:43 UTC (rev 1456)
@@ -0,0 +1,7 @@
+ACTION!="add",                         GOTO="cd_aliases_generator_end"
+SUBSYSTEM!="block",                    GOTO="cd_aliases_generator_end"
+ENV{GENERATED}=="?*",                  GOTO="cd_aliases_generator_end"
+
+ENV{ID_CDROM}=="?*", PROGRAM="cdalias-generator", SYMLINK+="%c"
+
+LABEL="cd_aliases_generator_end"

Modified: branches/udev_update/packages/udev/Makefile
===================================================================
--- branches/udev_update/packages/udev/Makefile 2006-03-27 13:25:06 UTC (rev 
1455)
+++ branches/udev_update/packages/udev/Makefile 2006-04-01 03:37:43 UTC (rev 
1456)
@@ -32,11 +32,12 @@
         EXTRAS="`echo extras/*/`"
 endif
        make DESTDIR=/ EXTRAS="`echo extras/*/`" install
-       cp $(SRC)/$(CONFIG1) /etc/udev/rules.d/25-lfs.rules
-       # FIXME: cdrom symlink
+       grep -v cdrom $(SRC)/$(CONFIG1) >/etc/udev/rules.d/25-lfs.rules
        cp ../10-wait_for_sysfs.rules /etc/udev/rules.d/
        echo 'ACTION=="add", BUS=="pci", SYSFS{class}=="0x030000", 
RUN+="detect-video"' >/etc/udev/rules.d/30-video.rules
        cp ../50-network.rules /etc/udev/rules.d/
+       cp ../90-cdrom.rules /etc/udev/rules.d/
+       cp ../92-cdalias-generator.rules /etc/udev/rules.d/
        # Debug, remove before release
        gcc -o bug ../bug.c
        install -m755 bug /lib/udev
@@ -49,6 +50,7 @@
        ln -nsf /proc/self/fd/2 /lib/udev/devices/stderr
        ln -nsf /proc/kcore /lib/udev/devices/core
        install ../detect-video /lib/udev
+       install ../cdalias-generator /lib/udev
        install -m644 -D docs/writing_udev_rules/index.html \
         /usr/share/doc/$(DIR)/index.html
 

Added: branches/udev_update/packages/udev/cdalias-generator
===================================================================
--- branches/udev_update/packages/udev/cdalias-generator                        
        (rev 0)
+++ branches/udev_update/packages/udev/cdalias-generator        2006-04-01 
03:37:43 UTC (rev 1456)
@@ -0,0 +1,124 @@
+#!/bin/sh -e
+# Origin: 
http://marc.theaimsgroup.com/?l=linux-hotplug-devel&m=114363313617910&w=2
+
+RULES_FILE="/etc/udev/rules.d/91-cdalias.rules"
+
+##############################################################################
+lock_rules_file() {
+  RULES_LOCK="/dev/.udev/.lock-${RULES_FILE##*/}"
+
+  retry=30
+  while ! mkdir $RULES_LOCK 2> /dev/null; do
+    if [ $retry -eq 0 ]; then
+       echo "Cannot lock $RULES_FILE!" >&2
+       exit 2
+    fi
+    sleep 1
+    retry=$(($retry - 1))
+  done
+}
+
+unlock_rules_file() {
+  rmdir $RULES_LOCK || true
+}
+
+# returns true if a directory is writeable
+writeable() {
+  if ln -s check $1/.is-writeable 2> /dev/null; then
+    rm -f $1/.is-writeable
+    return 0
+  else
+    return 1
+  fi
+}
+
+choose_rules_file() {
+  [ -e "$RULES_FILE" ] || PRINT_HEADER=1
+  if writeable ${RULES_FILE%/*}; then
+    RO_RULES_FILE='/dev/null'
+  else
+    RO_RULES_FILE=$RULES_FILE
+    RULES_FILE="/dev/.udev/tmp-rules--${RULES_FILE##*/}"
+  fi
+}
+
+##############################################################################
+find_next_available() {
+  local links="$(find_all_symlinks $1)"
+
+  local basename=${links%%[0-9]*}
+  local max=-1
+  for name in $links; do
+    local num=${name#$basename}
+    [ "$num" ] || num=0
+    [ $num -gt $max ] && max=$num
+  done
+
+  max=$(($max + 1))
+  # "name0" actually is just "name"
+  [ $max -eq 0 ] && return
+  echo "$max"
+}
+
+find_all_symlinks() {
+  local linkre="$1"
+  local match="$2"
+
+  [ -e $RULES_FILE ] || return
+
+  local 
search='.*[[:space:],]SYMLINK+="\('"$linkre"'\)"[[:space:]]*\(,.*\|\\\|\)$'
+
+  sed -n -e "${match}s/${search}/\1/p" $RO_RULES_FILE $RULES_FILE
+}
+
+write_rule() {
+  local match="$1"
+  local link="$2"
+
+  {
+  if [ "$PRINT_HEADER" ]; then
+    PRINT_HEADER=
+    echo "# This file was automatically generated by the $0"
+    echo "# program, probably run by the cd-aliases-generator.rules rules 
file."
+    echo "#"
+    echo "# You can modify it, as long as you keep each rule on a single line"
+    echo "# and set the \$GENERATED variable."
+    echo ""
+  fi
+
+  echo "ACTION==\"add\", ENV{ID_CDROM}==\"?*\", $match, SYMLINK+=\"$link\", 
ENV{GENERATED}=\"1\""
+  } >> $RULES_FILE
+  SYMLINKS="$SYMLINKS $link"
+}
+
+##############################################################################
+if [ -z "$DEVPATH" ]; then
+  echo "Missing \$DEVPATH." >&2
+  exit 1
+fi
+if [ -z "$ID_CDROM" ]; then
+  echo "$DEVPATH is not a CD reader." >&2
+  exit 1
+fi
+
+# Prevent parallel processes from modifying the file at the same time.
+lock_rules_file
+
+# Check if the rules file is writeable.
+choose_rules_file
+
+link_num=$(find_next_available 'cdrom[0-9]*')
+
+id=${PHYSDEVPATH##*/}
+match="BUS==\"$PHYSDEVBUS\", ID==\"$id\""
+
+  write_rule "$match" "cdrom$link_num"
+[ "$ID_CDROM_CD_RW" ]  && write_rule "$match"
+[ "$ID_CDROM_DVD" ]    && write_rule "$match"
+[ "$ID_CDROM_DVD_RW" ] && write_rule "$match"
+
+unlock_rules_file
+
+echo $SYMLINKS
+
+exit 0


Property changes on: branches/udev_update/packages/udev/cdalias-generator
___________________________________________________________________
Name: svn:executable
   + *

-- 
http://linuxfromscratch.org/mailman/listinfo/livecd
FAQ: http://www.linuxfromscratch.org/faq/
Unsubscribe: See the above information page

Reply via email to