Õâ¸öÓï¾äʲôÒâ˼
[CODE] # try parsing by shell scripts if no luck yetif [ "$DRIVERS" = "" ]; then
[COLOR=Blue]${TYPE}_map_modules < $FILENAME[/COLOR]
fi
[/CODE]
$FILENAMEÊÇÒ»¸öÎļþ
$TYPEÊÇisa it's just like:[code]
$ cat < /a/file[/code] »¹ÊÇû¿´¶®£¬ÊÇʲôÒâʶ£¿ ¾ÍÊÇÕÒ²»µ½Õâ¸ö ${TYPE}_map_modules³ÌÐò
[code]
#
# Setup and BASH utility functions for use in hotplug agents
#
# Most essential parameters are passed from the kernel using
# environment variables. For more information, see the docs
# on-line at http://linux-hotplug.sourceforge.net or the
# sources for each hotplug-aware kernel subsystem.
#
# $Id: hotplug.functions,v 1.27 2004/09/20 23:12:07 kroah Exp $
#
#
#DEBUG=yes; export DEBUG
PATH=/bin:/sbin:/usr/sbin:/usr/bin
KERNEL=`uname -r`
MODULE_DIR=/lib/modules/$KERNEL
HOTPLUG_DIR=/etc/hotplug
if [ -f /etc/sysconfig/hotplug ]; then
. /etc/sysconfig/hotplug
fi
if [ -x /usr/bin/logger ]; then
LOGGER=/usr/bin/logger
elif [ -x /bin/logger ]; then
LOGGER=/bin/logger
else
unset LOGGER
fi
#
# for diagnostics
#
if [ -t 1 -o -z "$LOGGER" ]; then
mesg () {
echo "$@"
}
else
mesg () {
$LOGGER -t $(basename $0)"[$$]" "$@"
}
fi
debug_mesg () {
test "$DEBUG" = "" -o "$DEBUG" = no && return
mesg "$@"
}
#
# Not "modprobe --autoclean" ... one driver module can handle many
# devices. Unloading should be done when no devices are present.
# Autocleaning happens if none of the devices are open, once any of
# them gets opened; wrong timing.
#
MODPROBE="/sbin/modprobe -s -q"
#MODPROBE="/sbin/modprobe -vs"
####################################################################
#
# usage: load_driver type filename description
#
# modprobes driver module(s) if appropriate, and optionally
# invokes a driver-specific setup script (or user-mode driver).
#
# the "modules.*map" format file is guaranteed to exist
#
load_drivers ()
{
local LOADED TYPE FILENAME DESCRIPTION LISTER
DRIVERS=""
# make this routine more readable
TYPE=$1
FILENAME=$2
DESCRIPTION=$3
# should we use usbmodules, pcimodules? not on 2.5+, because sysfs
# ought to expose the data we need to find all candidate drivers.
# (on 2.5.48 it does for usb; but maybe not yet for pci.)
case "$KERNEL" in
2.2*|2.3*|2.4*) LISTER=`which ${TYPE}modules` ;;
*) LISTER="" ;;
esac
if [ "$LISTER" != "" ]; then
# lister programs MIGHT be preferable to parsing from shell scripts:
# - usbmodules used for (a) multi-interface devices, (b) coldplug
# - pcimodules used only for coldplug
case $TYPE in
usb)
# "usbutils-0.8" (or later) is needed in $PATH
# only works if we have usbfs
# ... reads more descriptors than are passed in env
# ... doesn't handle comment syntax either
if [ "$DEVICE" = "" -o ! -f "$DEVICE" ]; then
LISTER=
else
DRIVERS=`$LISTER --mapfile $FILENAME --device $DEVICE`
fi ;;
pci)
debug_mesg "pcimodules is scanning more than $PCI_SLOT ..."
DRIVERS=`$LISTER`
;;
esac
fi
# try parsing by shell scripts if no luck yet
if [ "$DRIVERS" = "" ]; then
${TYPE}_map_modules < $FILENAME
fi
# FIXME remove dups and blacklisted modules from $DRIVERS here
if [ "$DRIVERS" = "" ]; then
return
fi
# Note that DRIVERS aren't all going to be modules.
# For USB, some user-mode drivers or setup scripts may be listed.
debug_mesg Setup $DRIVERS for $DESCRIPTION
# either kernel or user mode drivers may need to be set up
for MODULE in $DRIVERS
do
# maybe driver modules need loading
LOADED=false
if ! lsmod | grep -q "^$(echo $MODULE|sed -e 's/-/_/g') " > /dev/null 2>&1; then
if grep -q "^$(echo $MODULE|sed -e 's/[-_]/[-_]/g')\$" $HOTPLUG_DIR/blacklist \
$HOTPLUG_DIR/blacklist.d/* \
>/dev/null 2>&1; then
debug_mesg "... blacklisted module: $MODULE"
continue
fi
# statically linked modules aren't shown by 'lsmod',
# and user mode drivers will ONLY have a setup script;
# it's not an error if a module doesn't exist or won't load.
if $MODPROBE -n $MODULE >/dev/null 2>&1 &&
! $MODPROBE $MODULE >/dev/null 2>&1 ; then
mesg "... can't load module $MODULE"
else
# /etc/modules.conf may have set non-default module
# parameters ... handle per-device parameters in apps
# (ioctls etc) not in setup scripts or modules.conf
LOADED=true
fi
else
# This module is already loaded
LOADED=true
fi
# always run setup scripts after any matching kernel code has had
# a chance to do its thing, no matter whether it was dynamically
# or statically linked, or if there is only a user mode driver.
# the script might re-enumerate usb devices after firmware download,
# giving kernel code another chance.
if [ -x $HOTPLUG_DIR/$TYPE/$MODULE ]; then
debug_mesg Module setup $MODULE for $DESCRIPTION
$HOTPLUG_DIR/$TYPE/$MODULE
LOADED=true
fi
if [ "$LOADED" = "false" ]; then
mesg "missing kernel or user mode driver $MODULE "
fi
if echo "$MODULE" | grep -q "usb-storage" > /dev/null 2>&1 ; then
[ -x /usr/sbin/updfstab ] && /usr/sbin/updfstab
fi
done
}
####################################################################
#
# usage: log_to_stdout filename
#
# writes a copy of the current hotplug event to stdout.
# add buffering, to avoid interleaving reports!
#
log_to_stdout ()
{
if [ -x /bin/date ]; then
echo "HOTPLUG_TIME='$(/bin/date)'"
fi
env | egrep -v '^PATH=|^PWD=|^_=|^OLDPWD=|^SHLVL=|^HOME='
echo ''
# empty line terminates events
}
# vim:syntax=sh
[/code] ${TYPE}_map_modules µÄÖµÊÇ isapnp_map_modules
$FILENAME µÄÖµÊÇ /etc/hotplug/pnp.distmap ¾ÍÊÇÆÕͨµÄÊäÈëÖØ¶¨Ïò°¡, ¿´²»³öÓÐÊ²Ã´ÌØ±ðµÄµØ·½À´ :( ¾ÍÊÇûÓÐÕÒµ½isapnp_map_modulesÕâ¸öÃüÁî¡£ [code]
#!/bin/sh
# vim: syntax=sh
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Copyright (C) 2004 Alexander E. Patrakov (patrakov@ums.usu.ru)
# Copyright (C) 2004 Simone Gotti (simone.gotti@email.it)
# All Rights Reserved.
#
# Based on scripts by Simone Gotti, from:
# [url]http://members.xoom.virgilio.it/motaboy/hotplug-isapnp-0.2.1.tar.bz2[/url]
#
PATH=/sbin:/bin:/usr/sbin:/usr/bin
if [ "$(echo /sys/bus/pnp/devices/*)" = "/sys/bus/pnp/devices/*" ]
then
exit 0
fi
cd /etc/hotplug
. ./hotplug.functions
MAP_CURRENT=$MODULE_DIR/modules.isapnpmap
DRIVERS=
# WARNING: od and printf are in /usr/bin
decode_isapnp_vendor() {
echo -n $1 | od -A n -t d1 | ( read A B C
printf '%x\n' $(( ( ( $A & 0x3f ) << 2) | \
( ( $B & 0x18 ) >> 3) | \
( ( $B & 0x07 ) <<13) | \
( ( $C & 0x1f ) << 8) )) )
}
hex_swab() {
echo `echo $1 | cut -b3-4``echo $1 | cut -b1-2`
}
#
# stdin is "modules.isapnpmap" syntax
# on return, ONE matching module was added to $DRIVERS
#
isapnp_map_modules ()
{
local module ignored
CHECKED_ID="0x`echo $ISAPNP_ID | cut -b1-4`0x`echo $ISAPNP_ID | cut -b5-8`"
# comment line lists (current) isapnp_device_id field names
read ignored
while read module cardvendor carddevice driver_data therest
do
# comments are lines that start with "#" ...
# be careful, they still get parsed by bash!
case "$module" in
\#*) continue ;;
esac
: checkmatch $module
set $therest
while [ $# -gt 0 ]
do
id_temp=$2$1
if [ "$id_temp" = "$CHECKED_ID" ] ; then
DRIVERS="$module $DRIVERS"
: drivers $DRIVERS
break
fi
shift
shift
done
done
}
isapnp_boot_events ()
{
cd /sys/bus/pnp/devices/
for ISAPNP_DEVICE in * ; do
ISAPNP_STRINGS=`cat $ISAPNP_DEVICE/id`
for ISAPNP_STRING in $ISAPNP_STRINGS ; do
rawcardvendor=`echo $ISAPNP_STRING | cut -b1-3`
rawcarddevice=`echo $ISAPNP_STRING | cut -b4-7`
cardvendor=`decode_isapnp_vendor $rawcardvendor`
carddevice=`hex_swab $rawcarddevice`
ISAPNP_ID=$carddevice$cardvendor
LABEL="ISAPNP id $ISAPNP_ID"
load_drivers isapnp $MAP_CURRENT "$LABEL"
load_drivers isapnp /etc/hotplug/pnp.distmap "$LABEL"
done
done
return 0
}
# See how we were called.
case "$1" in
start)
isapnp_boot_events
;;
stop)
# echo $"isapnp stop -- ignored"
;;
status)
# echo $"isapnp status -- ignored"
;;
restart)
# always invoke by absolute path, else PATH=$PATH:
$0 stop && $0 start
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
exit 1
esac
[/code]
ÔÀ´ÊǺ¯Êý¡£ αÎÊÌâ :(
Ò³:
[1]