# /usr/share/doc/bilibop-rules/examples/90-internal-drives.rules

  ┌───────────────────────────────────────────────────────────────┐
  │  THIS FILE IS NOW OUT OF DATE. SEE 90-insidev.rules INSTEAD.  │
  └───────────────────────────────────────────────────────────────┘


# ==============================================================================
# 1. Filters:
#    ========
SUBSYSTEM!="block",		GOTO="end_internal-drives_rules"
KERNEL!="sd*",			GOTO="end_internal-drives_rules"
SUBSYSTEMS=="usb|firewire",	GOTO="end_internal-drives_rules"

# At this step, following rules should be applied only on block devices
# hosted by internal drives of the computer.

# Those internal drives cannot be removed:
KERNEL=="sd?", ACTION=="remove", GOTO="end_internal-drives_rules"

# If this rules file is orphaned, go away:
TEST!="/lib/udev/bilibop_disk", GOTO="end_internal-drives_rules"

# If bilibop-rules is installed on an internal drive, skip it too:
PROGRAM=="bilibop_disk --test $tempnode", GOTO="end_internal-drives_rules"


# ==============================================================================
# 2. Tag the device:
#    ===============
#    This is a convenient way to update its udev properties with:
#    'udevadm trigger --tag-match=INTERNAL --action=add'
#    'udevadm trigger --tag-match=INTERNAL --action=change'
#    after this file has been modified.
TAG+="INTERNAL"


# ==============================================================================
# 3. Examples:
#    =========
#    Here are some examples of actions to perform, or properties to set.


# A. Uncomment the following line if you want to set the whole disk and
#    each of its partitions as read-only. This can avoid big mistakes
#    on your friend's computer.
#ACTION=="add|change", RUN+="/sbin/blockdev --setro $tempnode"
#
#    This is a variant using a boot parameter: diskaccess. If this keyword
#    IS NOT present in the boot commandline, devices are set readonly:
#ACTION=="add|change", PROGRAM!="/bin/grep -q '\sdiskaccess\(\s\|$$\)' /proc/cmdline", RUN+="/sbin/blockdev --setro $tempnode"
#
#    This is a variant using a boot parameter: nodiskaccess. If this keyword
#    IS present in the boot commandline, devices are set readonly:
#ACTION=="add|change", PROGRAM=="/bin/grep -q '\snodiskaccess\(\s\|$$\)' /proc/cmdline", RUN+="/sbin/blockdev --setro $tempnode"


# B. Uncomment the following line if you want the disk and its partitions
#    to be hidden to the user (works only for udisks-based applications):
#ACTION=="add|change", TEST=="/lib/udev/rules.d/80-udisks.rules", ENV{UDISKS_PRESENTATION_HIDE}:="1"


# C. Uncomment the following line if you want that the user be able to
#    mount the partitions. Dangerous: use with care.
#ACTION=="add|change", ATTR{partition}=="?*", TEST=="/lib/udev/rules.d/80-udisks.rules", ENV{UDISKS_SYSTEM_INTERNAL}:="0"
#
#    This is a variant using a boot parameter (diskaccess):
#ACTION=="add|change", ATTR{partition}=="?*", PROGRAM=="/bin/grep -q '\sdiskaccess\(\s\|$$\)' /proc/cmdline", TEST=="/lib/udev/rules.d/80-udisks.rules", ENV{UDISKS_SYSTEM_INTERNAL}:="0"


# D. Uncomment the following lines if you want to automatically setup
#    encrypted swap devices from internal partitions. Experimental: use
#    with care.
#ACTION=="add", \
#	PROGRAM!="/bin/grep -q '\sno\(diskaccess\|swap\)\(\s\|$\)' /proc/cmdline", \
#	ENV{ID_FS_TYPE}=="swap", ENV{ID_PART_ENTRY_TYPE}=="0x82", \
#	PROGRAM=="/sbin/blockdev --setrw $tempnode", \
#	TEST!="%r/mapper/encswap_%k", \
#	PROGRAM=="/sbin/cryptsetup --key-file=%r/urandom --offset=8 create encswap_%k $tempnode", \
#	RUN+="/sbin/mkswap -f %r/mapper/encswap_%k", \
#	RUN+="/sbin/swapon %r/mapper/encswap_%k"


LABEL="end_internal-drives_rules"
