Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

FL-34: update mdev, support uuid,label, cpu microcode, clean-up scripts

  • Loading branch information...
commit ec56c1e21074df14cfdfe9de36b4a4d9f4bc5031 1 parent 312b0b9
@angryvincent angryvincent authored
View
2  sys-fs/mdev-bb/Manifest
@@ -1 +1 @@
-DIST busybox-1.20.2.tar.bz2 2186738 RMD160 9c10d5285eb56f738225b90ea891b6393b1251ff SHA1 dd2e3684b13c0071d480e97b569041e69538e798 SHA256 eb13ff01dae5618ead2ef6f92ba879e9e0390f9583bd545d8789d27cf39b6882
+DIST busybox-1.20.2.tar.bz2 2186738 SHA256 eb13ff01dae5618ead2ef6f92ba879e9e0390f9583bd545d8789d27cf39b6882
View
29 sys-fs/mdev-bb/files/device-mapper
@@ -1,29 +0,0 @@
-#!/bin/sh
-# Copyright (c) 2012, Piotr Karbowski <piotr.karbowski@gmail.com>
-
-# This script intend to create proper /dev/mapper/ symlinks to /dev/dm-* devices.
-
-umask 077
-
-### debug
-#exec >> /run/debug-mdev 2>&1
-#set -x
-#echo '### ENV:'
-#env
-#echo '### CODE:'
-
-if [ -z "${MDEV}" ]; then exit 1; fi
-
-case "$ACTION" in
- add|'')
- test -d /dev/mapper || mkdir /dev/mapper
- if ! test -c /dev/mapper/control; then
- dmminor="$(awk '$2 == "device-mapper" { print $1; exit; }' /proc/misc)"
- mknod '/dev/mapper/control' c 10 "${dmminor}"
- fi
-
- if [ -f "/sys/block/${MDEV}/dm/name" ]; then
- _name="$(cat /sys/block/${MDEV}/dm/name)"
- ln -sf "/dev/${MDEV}" "/dev/mapper/${_name}"
- fi
-esac
View
29 sys-fs/mdev-bb/files/devicemapper.sh
@@ -1,29 +0,0 @@
-#!/bin/sh
-# Copyright (c) 2012, Piotr Karbowski <piotr.karbowski@gmail.com>
-
-# This script intend to create proper /dev/mapper/ symlinks to /dev/dm-* devices.
-
-umask 077
-
-### debug
-#exec >> /run/debug-mdev 2>&1
-#set -x
-#echo '### ENV:'
-#env
-#echo '### CODE:'
-
-if [ -z "${MDEV}" ]; then exit 1; fi
-
-case "$ACTION" in
- add|'')
- test -d /dev/mapper || mkdir /dev/mapper
- if ! test -c /dev/mapper/control; then
- dmminor="$(awk '$2 == "device-mapper" { print $1; exit; }' /proc/misc)"
- mknod '/dev/mapper/control' c 10 "${dmminor}"
- fi
-
- if [ -f "/sys/block/${MDEV}/dm/name" ]; then
- _name="$(cat /sys/block/${MDEV}/dm/name)"
- ln -sf "/dev/${MDEV}" "/dev/mapper/${_name}"
- fi
-esac
View
33 sys-fs/mdev-bb/files/mdev.conf
@@ -1,11 +1,5 @@
-#
-# This is a sample mdev.conf
-#
+# mdev-like-a-boss
-# 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:
# [-]devicename_regex user:group mode [>|=path] [@|$|*cmd args...]
#
@@ -43,14 +37,16 @@ vcsa*[0-9]* root:tty 660
ttyS[0-9]* root:uucp 660
# block devices
-ram([0-9]*) root:disk 660 >rd/%1
+ram([0-9]*) root:disk 660 >rd/%1
loop([0-9]+) root:disk 660 >loop/%1
-sd[a-z].* root:disk 660
-vd[a-z][0-9]* root:disk 660
-hd[a-z][0-9]* root:disk 660
-md[0-9]* root:disk 660
-sr[0-9]* root:cdrom 660 @ln -sf $MDEV cdrom
-fd[0-9]* root:floppy 660
+sd[a-z].* root:disk 660 */etc/mdev/storage-device
+vd[a-z].* root:disk 660 */etc/mdev/storage-device
+hd[a-z].* root:disk 660 */etc/mdev/storage-device
+md[0-9]* root:disk 660 */etc/mdev/storage-device
+dm-[0-9]* root:disk 660 */etc/mdev/storage-device
+mmcblk[0-9].* root:disk 660 */etc/mdev/storage-device
+sr[0-9]* root:cdrom 660 @ln -sf $MDEV cdrom
+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.
@@ -99,15 +95,18 @@ video[0-9] root:video 660 >v4l/
# dvb stuff
dvb.* root:video 660
-# Device mapper support, populate /dev/mapper with symlinks as well.
-dm-[0-9]* root:disk 660 @/etc/mdev/device-mapper
-
# Don't create old usbdev* devices.
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
View
21 sys-fs/mdev-bb/files/mdev.init
@@ -8,6 +8,10 @@ depend()
start()
{
ebegin "Mounting /dev (mdev)"
+ # First umount /dev and friends if it is already mounted.
+ # It may be leftover from initramfs mount --move, we don't
+ # want to use it.
+ umount /dev/pts /dev/shm /dev >/dev/null 2>&1
if fstabinfo --quiet /dev ; then
mount -n /dev
else
@@ -45,6 +49,7 @@ start()
eend 0
fi
+ ebegin "Loading kernel modules for detected hardware"
/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
@@ -56,21 +61,21 @@ start()
esac
done; unset i
# Load kernel modules, run twice.
- find /sys -name 'modalias' -type f -exec sort -u '{}' \; | xargs modprobe -b -a 2>/dev/null
- find /sys -name 'modalias' -type f -exec sort -u '{}' \; | xargs modprobe -b -a 2>/dev/null
+ find /sys -name 'modalias' -type f -exec cat '{}' + | sort -u | xargs modprobe -b -a 2>/dev/null
+ find /sys -name 'modalias' -type f -exec cat '{}' + | sort -u | xargs modprobe -b -a 2>/dev/null
eend 0
- if ! mountinfo -q /dev/pts && ! fstabinfo --mount /dev/pts; then
- ebegin "Mounting /dev/pts"
+ ebegin "Mounting /dev/pts"
+ if ! fstabinfo --mount /dev/pts; then
mount -n -t devpts -o noexec,nosuid,gid=5,mode=0620 devpts /dev/pts
- eend "$?"
fi
+ eend "$?"
- if ! mountinfo -q /dev/shm && ! fstabinfo --mount /dev/shm; then
- ebegin "Mounting /dev/shm"
+ ebegin "Mounting /dev/shm"
+ if ! fstabinfo --mount /dev/shm; then
mount -n -t tmpfs -o noexec,nosuid,nodev,mode=1777 shm-tmpfs /dev/shm
- eend "$?"
fi
+ eend "$?"
}
View
4 sys-fs/mdev-bb/files/settle-nics
@@ -30,7 +30,7 @@
# Next it will parse old /etc/mactab and copy all interfaces which wasnt added in step two.
# On the end, it will replace /etc/mactab with the new one.
-# Info: Step two will only care about eth*, wlan*, ath*, wifi*, ra* and usb* interfaces.
+# Info: Step two will only care about eth*, wlan*, ath*, wifi* and ra* interfaces.
umask 077
@@ -141,7 +141,7 @@ for i in /sys/class/net/*; do
case "${device}" in
*_tmp)
;;
- eth[0-9]*|wlan[0-9]*|ath[0-9]*|wifi[0-9]*|ra[0-9]*|usb[0-9]*)
+ eth[0-9]*|wlan[0-9]*|ath[0-9]*|wifi[0-9]*|ra[0-9]*)
macaddr="$(cat /sys/class/net/${device}/address 2>/dev/null)"
if [ -n "${macaddr}" ] && ! in_comma_list "${macaddr}" "${inconf_macs}" && ! in_comma_list "${device}" "${inconf_nics}"; then
detected_nics="${detected_nics},${device}"
View
114 sys-fs/mdev-bb/files/storage-device
@@ -0,0 +1,114 @@
+#!/bin/sh
+# Copyright (c) 2012, Piotr Karbowski <piotr.karbowski@gmail.com>
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without modification, are
+# permitted provided that the following conditions are met:
+#
+# * Redistributions of source code must retain the above copyright notice, this list
+# of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright notice, this list
+# of conditions and the following disclaimer in the documentation and/or other
+# materials provided with the distribution.
+# * Neither the name of the Piotr Karbowski nor the names of its contributors may be
+# used to endorse or promote products derived from this software without specific
+# prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE US
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+# This script meant to create /dev/disk/by-* and /dev/mapper/* symlinks.
+# and remove them after storage device is removed.
+# the /dev/disk/by-* handling based on the idea and proof of concept from BitJam.
+
+# debug
+#exec >> /run/debug-mdev 2>&1
+#set -x
+#echo '### ENV:'
+#env
+#echo '### CODE:'
+#
+
+umask 077
+
+storage_dir="/dev/.mdev"
+[ -d "${storage_dir}" ] || mkdir "${storage_dir}"
+
+[ "${MDEV}" ] || exit 2
+
+create_uuid_label_symlink() {
+ local target_dir="/dev/disk/by-${1}"
+ local target_symlink="${target_dir}/${2}"
+ [ -e "${target_symlink}" ] && return
+ mkdir -p "${target_dir}"
+ ln -s "/dev/${MDEV}" "${target_symlink}"
+ echo "${target_symlink}" >"${storage_dir}/storage_symlink_${1}_${MDEV}"
+}
+
+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
+ fi
+
+ if [ -f "/sys/block/${MDEV}/dm/name" ]; then
+ [ -d '/dev/mapper' ] || mkdir '/dev/mapper'
+ if ! [ -c '/dev/mapper/control' ]; then
+ awk '$2 == "device-mapper" { foo = system("mknod /dev/mapper/control c 10 " $1); exit foo }' /proc/misc || exit 1
+ fi
+ local dmname="$(cat "/sys/block/${MDEV}/dm/name")"
+ if [ "${dmname}" ]; then
+ local target_symlink="/dev/mapper/${dmname}"
+ [ -e "${target_symlink}" ] && return
+ ln -s "/dev/${MDEV}" "${target_symlink}"
+ echo "${target_symlink}" >"${storage_dir}/storage_symlink_mapper_${MDEV}"
+ fi
+ fi
+}
+
+drop_symlinks() {
+ local type
+ for type in uuid label mapper; do
+ [ -f "${storage_dir}/storage_symlink_${type}_${MDEV}" ] || continue
+ local target_symlink="$(cat "${storage_dir}/storage_symlink_${type}_${MDEV}" 2>/dev/null)"
+ [ "${target_symlink}" ] || continue
+
+ local target_symlink_device="$(readlink "${target_symlink}")"
+ if [ "${target_symlink_device}" = "/dev/${MDEV}" ]; then
+ rm "${target_symlink}"
+ fi
+ rm "${storage_dir}/storage_symlink_${type}_${MDEV}"
+ done
+}
+
+case "${ACTION}" in
+ 'add'|'')
+ add_symlinks
+ ;;
+ 'remove')
+ drop_symlinks
+ ;;
+esac
+
View
3  sys-fs/mdev-bb/mdev-bb-1.20.2.ebuild
@@ -21,6 +21,7 @@ DEPEND="${RDEPEND}
>=sys-kernel/linux-headers-2.6.39"
S=${WORKDIR}/${MY_P}
+QA_PRESTRIPPED="/sbin/mdev"
src_configure() {
cat >"${S}/tmp.config" <<-END_OF_CONFIG
@@ -68,6 +69,6 @@ src_install() {
exeinto /etc/mdev
doexe "${FILESDIR}"/catch-all || die
doexe "${FILESDIR}"/settle-nics || die
- doexe "${FILESDIR}"/device-mapper || die
+ doexe "${FILESDIR}"/storage-device || die
newinitd "${FILESDIR}"/mdev.init mdev || die
}
Please sign in to comment.
Something went wrong with that request. Please try again.