# Provide user, group, and mode information for devices.  If a regex matches
# the device name provided by sysfs, use the appropriate user:group and mode
# instead of the default 0:0 660.
#
# Syntax:
# [-][ENVVAR=regex;]...devicename_regex user:group mode [=path]|[>path]|[!] [@|$|*cmd args...]
# [-][ENVVAR=regex;]...@maj,min[-min2]  user:group mode [=path]|[>path]|[!] [@|$|*cmd args...]
# [-]$ENVVAR=regex                      user:group mode [=path]|[>path]|[!] [@|$|*cmd args...]
#
# note: $ENVVAR for single check like $MODALIAS,
# but ENVVAR if combined with any other criteria!
#
# Leading minus in 1st field means "don't stop on this line", otherwise
# search is stopped after the first match.
#
# =: move, >: move and create a symlink from match to new name
# if lhs is regex: %1..%9 are backrefs to captures
# !: don't create node (but run scripts)
# @|$|*: run $cmd on ACTION=delete, @cmd ACTION=add, *cmd in all cases
# cmd also gets $SUBSYSTEM and $MDEV

# for limited(!) debugging just touch /dev/mdev.log and mdev
# will log action/subsystem/devname/devpath and rule matching
# this fuller debugging mechanism captures all uevent args
# -.*    root:root	0666 *{ date; set; echo; } >>/tmp/log

# automount cdrom if possible
-ACTION=change;DISK_MEDIA_CHANGE=1;sr[0-9]+ root:cdrom  0660 */etc/mdev/cdrom.agent

sr([0-9]+)	 root:cdrom	0660	>scd%1 @/bin/ln -sf "$MDEV" cdrom; /bin/ln -sf "$MDEV" dvd
hda	 	 root:cdrom	0660	@/bin/ln -sf "$MDEV" cdrom; /bin/ln -sf "$MDEV" dvd

$DEVNAME=bus/usb/([0-9]+)/([0-9]+)	root:plugdev	0660	=bus/usb/%1/%2

# disk id links in /dev/disks
-$SUBSYSTEM=block root:disk 660 */etc/mdev/diskidlinks "$MDEV"

# block devices: add to md arrays (needed for superblock 1.x)
-$SUBSYSTEM=block root:disk 0660 */sbin/mdadm --incremental "$MDEV"

# start/stop bluetooth software with the hardware
-$SUBSYSTEM=bluetooth	root:root 0660	 	*/etc/mdev/bluetooth.agent

# automount disks if usb-connected
-DEVPATH=usb;sd.*	root:disk 0660		*/etc/mdev/block.agent

rfkill.*	root:root 0660		*/etc/mdev/rfkill.agent

# support module loading on hotplug
$MODALIAS=.+            root:root       660 ! @/sbin/modprobe -b "$MODALIAS"

# null may already exist; therefore ownership has to be changed with command
null                    root:root       666 @/bin/chmod 666 "$MDEV"
zero                    root:root       666
full                    root:root       666
random                  root:root       666
urandom                 root:root       666
hwrandom                root:root       666

kmem                    root:kmem       640
kmsg                    root:root       600
mem                     root:kmem       640
port                    root:kmem       640

# console may already exist; therefore ownership has to be changed with command
console                 root:tty        600 @/bin/chmod 600 "$MDEV"
ptmx                    root:tty        666
pty.*                   root:tty        666
tty[a-z][0-9a-f]	root:tty        666

cpu([0-9]+)		root:root       600 =cpu/%1/cpuid
msr([0-9]+)             root:root       600 =cpu/%1/msr
microcode               root:root       600 =cpu/

# Typical devices
tty                     root:tty        666
tty[0-9]		root:tty        620
vcsa?[0-9]*             root:tty        620
ttyS[0-9]+              root:dialout    660

# block devices
ram[0-9]+		root:disk       660
loop[0-9]+		root:disk	660
sd[a-z].*               root:disk       660
hd[a-z].*		root:disk       660
md[0-9]+                root:disk       660
mmcblk[0-9](p[0-9])?						root:disk				660

sr([0-9]+)		root:cdrom      660 >scd%1
bsg/.*                  root:root       600

# packet writing for cd/dvd
pktcdvd([0-9]+)		root:cdrom	660 =pktcdvd/%1
pktcdvd			root:cdrom	660 =pktcdvd/control

# alsa sound devices and audio stuff: DEVNAME now incl. dir
snd/.*		root:audio 660


# net and misc
net/tun[0-9]*		root:root	660
net/tap[0-9]*		root:root	660
dri/.*			root:video 	660
i2c-([0-9]+)            root:root       600 >i2c/%1
i2c([0-9]+)             root:root       600 >i2c/%1
rtc0			root:root       600 @/bin/ln -sf $MDEV rtc
fuse                    root:fuse	660
mapper/control		root:root	600

# v4l stuff
video[0-9]+	root:video 660

# input stuff, now also with dir in devname
input/event[0-9]+	root:plugdev 660 
input/mice		root:plugdev 660 
input/mouse[0-9]+	root:plugdev 660
input/ts[0-9]		root:plugdev 660
input/js[0-9]		root:plugdev 660

ttyUSB[0-9]+	root:dialout 660
ttyACM[0-9]+	root:plugdev 660
