Permalink
Browse files

FL-34: changes to mdev

  • Loading branch information...
1 parent fcc232a commit 0e7bdb76317bd7aaaa3e356d8cb5f1daa27abd88 @angryvincent angryvincent committed May 18, 2013
@@ -3,49 +3,6 @@
umask 022
-usb_device() {
- case "${MDEV}" in
- # Our devices are like 2-1.5, 1-1, 2-2 etc.
- [0-9]*-[0-9]*)
- case "${ACTION}" in
- 'add')
- [ "${BUSNUM}" ] || return 1
- [ "${DEVNUM}" ] || return 1
- [ "${MAJOR}" ] || return 1
- [ "${MINOR}" ] || return 1
- mkdir -p "/dev/bus/usb/${BUSNUM}"
- mv "/dev/${MDEV}" "/dev/bus/usb/${BUSNUM}/${DEVNUM}"
-
- # Catch most of the Android Phones.
- [ "${DEVPATH}" ] || return 1
- if [ -f "/sys/${DEVPATH}/product" ]; then
- idVendor="$(cat /sys/${DEVPATH}/idVendor)"
- case "${idVendor}" in
- '0bb4'|'18d1'|'22b8'|'0fce'|'19d2'|'04e8')
- chgrp 'plugdev' "/dev/bus/usb/${BUSNUM}/${DEVNUM}" 2>/dev/null && chmod 660 "/dev/bus/usb/${BUSNUM}/${DEVNUM}"
- ;;
- esac
- fi
- ;;
- 'remove')
- [ "${BUSNUM}" ] || return 1
- [ "${DEVNUM}" ] || return 1
- [ "${MAJOR}" ] || return 1
- [ "${MINOR}" ] || return 1
- rm "/dev/bus/usb/${BUSNUM}/${DEVNUM}"
- rmdir "/dev/bus/usb/${BUSNUM}" 2>/dev/null
- rmdir "/dev/bus/usb" 2>/dev/null
- ;;
- esac
- ;;
- esac
-}
-
-if [ "${SUBSYSTEM}" = 'usb' ] && [ "${DEVTYPE}" = 'usb_device' ]; then
- usb_device
- exit
-fi
-
# Log unknown event so we can debug it later.
# We hit this part of script if nothing above matched.
exit
@@ -1,10 +1,14 @@
# mdev-like-a-boss
# Syntax:
-# [-]devicename_regex user:group mode [>|=path] [@|$|*cmd args...]
+# [-]devicename_regex user:group mode [=path]|[>path]|[!] [@|$|*cmd args...]
+# [-]$ENVVAR=regex user:group mode [=path]|[>path]|[!] [@|$|*cmd args...]
+# [-]@maj,min[-min2] user:group mode [=path]|[>path]|[!] [@|$|*cmd args...]
#
+# [-]: do not stop on this match, continue reading mdev.conf
# =: move, >: move and create a symlink
-# @|$|*: run $cmd on delete, @cmd on create, *cmd on both
+# !: do not create device node
+# @|$|*: run cmd if $ACTION=remove, @cmd if $ACTION=add, *cmd in all cases
# support module loading on hotplug
$MODALIAS=.* root:root 660 @modprobe "$MODALIAS"
@@ -19,7 +23,7 @@ hwrandom root:root 444
grsec root:root 660
# Kernel-based Virtual Machine.
-#kvm root:kvm 660
+kvm root:kvm 660
kmem root:root 640
mem root:root 640
@@ -50,16 +54,13 @@ fd[0-9]* root:floppy 660
# Run settle-nics every time new NIC appear.
# If you don't want to auto-populate /etc/mactab with NICs, run 'settle-nis' without '--write-mactab' param.
--net/.* root:root 600 @/etc/mdev/settle-nics --write-mactab
-tun[0-9]* root:kvm 660 =net/
-tap[0-9]* root:root 600 =net/
+-SUBSYSTEM=net;DEVPATH=.*/net/.*;.* root:root 600 @/etc/mdev/settle-nics --write-mactab
+
+net/tun[0-9]* root:kvm 660
+net/tap[0-9]* root:root 600
# alsa sound devices and audio stuff
-pcm.* root:audio 660 =snd/
-control.* root:audio 660 =snd/
-midi.* root:audio 660 =snd/
-seq root:audio 660 =snd/
-timer root:audio 660 =snd/
+SUBSYSTEM=sound;.* root:audio 660
adsp root:audio 660 >sound/
audio root:audio 660 >sound/
@@ -83,10 +84,7 @@ psaux root:root 660 >misc/
rtc root:root 664 >misc/
# input stuff
-event[0-9]+ root:root 640 =input/
-mice root:root 640 =input/
-mouse[0-9] root:root 640 =input/
-ts[0-9] root:root 600 =input/
+#SUBSYSTEM=input;.* root:root 600
# v4l stuff
vbi[0-9] root:video 660 >v4l/
@@ -101,12 +99,13 @@ usbdev[0-9].[0-9]* root:root 660 !
# Stop creating x:x:x:x which looks like /dev/dm-*
[0-9]+\:[0-9]+\:[0-9]+\:[0-9]+ root:root 660 !
-
# /dev/cpu support.
microcode root:root 600 =cpu/
cpu([0-9]+) root:root 600 =cpu/%1/cpuid
msr([0-9]+) root:root 600 =cpu/%1/msr
-# Catch-all other devices, the script will
-# populate /dev/bus/usb etc...
-.* root:root 660 */etc/mdev/catch-all
+# Populate /proc/bus/usb.
+SUBSYSTEM=usb;DEVTYPE=usb_device;.* root:root 660 */etc/mdev/proc-bus-usb
+
+# Catch-all other devices, Right now useful only for debuging.
+#.* root:root 660 */opt/mdev/helpers/catch-all
@@ -50,7 +50,7 @@ start()
fi
ebegin "Loading kernel modules for detected hardware"
- /sbin/mdev -s
+ env -i /sbin/mdev -s
# mdev -s does not poke network interfaces or usb devices so we need to do it here.
for i in /sys/class/net/*/uevent; do printf 'add' > "$i"; done 2>/dev/null; unset i
for i in /sys/bus/usb/devices/*; do
@@ -0,0 +1,33 @@
+#!/bin/sh
+
+umask 022
+
+case "${ACTION}" in
+ 'add')
+ [ "${BUSNUM}" ] || return 1
+ [ "${DEVNUM}" ] || return 1
+ [ "${MAJOR}" ] || return 1
+ [ "${MINOR}" ] || return 1
+ mkdir -p "/dev/bus/usb/${BUSNUM}"
+ [ "/dev/${MDEV}" != "/dev/bus/usb/${BUSNUM}/${DEVNUM}" ] && mv "/dev/${MDEV}" "/dev/bus/usb/${BUSNUM}/${DEVNUM}"
+ [ "${DEVPATH}" ] || return 1
+ # Catch most of the Android Phones.
+ if [ -f "/sys/${DEVPATH}/product" ]; then
+ idVendor="$(cat /sys/${DEVPATH}/idVendor)"
+ case "${idVendor}" in
+ '0bb4'|'18d1'|'22b8'|'0fce'|'19d2'|'04e8')
+ chgrp 'plugdev' "/dev/bus/usb/${BUSNUM}/${DEVNUM}" 2>/dev/null && chmod 660 "/dev/bus/usb/${BUSNUM}/${DEVNUM}"
+ ;;
+ esac
+ fi
+ ;;
+ 'remove')
+ [ "${BUSNUM}" ] || return 1
+ [ "${DEVNUM}" ] || return 1
+ [ "${MAJOR}" ] || return 1
+ [ "${MINOR}" ] || return 1
+ rm "/dev/bus/usb/${BUSNUM}/${DEVNUM}"
+ rmdir "/dev/bus/usb/${BUSNUM}" 2>/dev/null
+ rmdir "/dev/bus/usb" 2>/dev/null
+ ;;
+esac
@@ -38,7 +38,7 @@
umask 077
-storage_dir="/dev/.mdev"
+storage_dir="/dev/.mdev-like-a-boss"
[ -d "${storage_dir}" ] || mkdir "${storage_dir}"
[ "${MDEV}" ] || exit 2
@@ -54,23 +54,12 @@ create_uuid_label_symlink() {
add_symlinks() {
if command -v blkid >/dev/null 2>&1; then
- local field name value
- for field in $(blkid "/dev/${MDEV}"); do
- case "${field}" in
- 'UUID="'*'"')
- value="${field#UUID=\"}"
- value="${value%\"}"
- create_uuid_label_symlink 'uuid' "${value}"
- ;;
- 'LABEL="'*'"')
- value="${field#LABEL=\"}"
- value="${value%\"}"
- create_uuid_label_symlink 'label' "${value}"
- ;;
- *)
- ;;
- esac
- done
+ local field name value UUID LABEL TYPE PTTYPE PARTLABEL PARTUUID
+ local blkid_output="$(blkid "/dev/${MDEV}")"
+ eval "${blkid_output#*: }"
+
+ [ "${UUID}" ] && create_uuid_label_symlink 'uuid' "${UUID}"
+ [ "${LABEL}" ] && create_uuid_label_symlink 'label' "${LABEL}"
fi
if [ -f "/sys/block/${MDEV}/dm/name" ]; then
@@ -69,6 +69,7 @@ src_install() {
doexe "${FILESDIR}"/catch-all || die
doexe "${FILESDIR}"/settle-nics || die
doexe "${FILESDIR}"/storage-device || die
+ doexe "${FILESDIR}"/proc-bus-usb || die
newinitd "${FILESDIR}"/mdev.init mdev || die
}
add_init() {

0 comments on commit 0e7bdb7

Please sign in to comment.