# Udev rules for Archlinux by Tobias Powalowski <tpowa@archlinux.org>
#
# This ruleset should provide a DevFS-compatible device tree.
#
# There are a number of modifiers that are allowed to be used in some
# of the different fields. They provide the following subsitutions:
#
# %n the "kernel number" of the device.
#    For example, 'sda3' has a "kernel number" of '3'
# %k the kernel name for the device.
# %M the kernel major number for the device
# %m the kernel minor number for the device
# %b the bus id for the device
# %c the string returned by the PROGRAM
# %s{filename} the content of a sysfs attribute.
# %% the '%' char itself.
#
# There are a number of modifiers that are allowed to be used in some of the
# fields.  See the udev man page for a full description of them.
# global stuff
#

#####################################
# Early rules - begin
#####################################
# wait for sysfs
ACTION=="add", DEVPATH=="/devices/*", ENV{PHYSDEVBUS}=="?*", WAIT_FOR_SYSFS="bus"
ACTION=="add", SUBSYSTEM=="scsi", WAIT_FOR_SYSFS="ioerr_cnt"

#####################################
# Early rules -end
#####################################

#####################################
###### Hotplug rules - begin
#####################################
# check if the device has already been claimed by a driver
ENV{PHYSDEVDRIVER}=="?*", GOTO="hotplug_driver_loaded"

# Modaliases to load
ACTION=="add", ENV{MODALIAS}=="?*", RUN+="/lib/udev/load-modules.sh $env{MODALIAS}"
# SCSI addon modules
ACTION=="add", SUBSYSTEM=="scsi", SYSFS{type}=="[07]", RUN+="/lib/udev/load-modules.sh sd_mod"
ACTION=="add", SUBSYSTEM=="scsi", SYSFS{type}=="14", RUN+="/lib/udev/load-modules.sh sd_mod"
ACTION=="add", SUBSYSTEM=="scsi", SYSFS{type}=="[45]", RUN+="/lib/udev/load-modules.sh sr_mod"
ACTION=="add", SUBSYSTEM=="scsi", SYSFS{type}=="1", SYSFS{vendor}=="Onstream", SYSFS{model}!="ADR*", RUN+="/lib/udev/load-modules.sh osst"
ACTION=="add", SUBSYSTEM=="scsi", SYSFS{type}=="1", SYSFS{vendor}=="Onstream", SYSFS{model}=="ADR*", RUN+="/lib/udev/load-modules.sh st"
ACTION=="add", SUBSYSTEM=="scsi", SYSFS{type}=="1", SYSFS{vendor}!="Onstream", RUN+="/lib/udev/load-modules.sh st"
ACTION=="add", SUBSYSTEM=="scsi", SYSFS{type}=="[23689]", RUN+="/lib/udev/load-modules.sh sg"

LABEL="hotplug_driver_loaded"

# FIRMWARE
ACTION=="add", SUBSYSTEM=="firmware", ENV{FIRMWARE}=="?*", RUN+="/lib/udev/firmware.sh"
#####################################
##### Hotplug rules - end
#####################################

#####################################
###### CD/DVD symlinks - begin
#####################################
ACTION=="add", BUS=="ide", KERNEL=="hd[a-z]", IMPORT="/lib/udev/cdrom_id --export $tempnode"
ACTION=="add", BUS=="scsi",	KERNEL=="sr[0-9]*", IMPORT="/lib/udev/cdrom_id --export $tempnode"
ACTION=="add", BUS=="scsi",	KERNEL=="scd[a-z]", IMPORT="/lib/udev/cdrom_id --export $tempnode"
ENV{ID_CDROM}=="?*", SYMLINK+="cd/cdrom-%b"
ENV{ID_CDROM_CD_RW}=="?*", SYMLINK+="cd/cdrw-%b"
ENV{ID_CDROM_DVD}=="?*", SYMLINK+="cd/dvd-%b"
ENV{ID_CDROM_DVD_R}=="?*", SYMLINK+="cd/dvd-%b"
#####################################
###### CD/DVD symlinks - end
#####################################
