[USERSPACE 1/4] pcmcia: hotplug scripts

Dominik Brodowski linux at dominikbrodowski.net
Sun Feb 27 05:11:57 EST 2005


Attached are the four hotplug scripts needed for PCMICA -- pcmcia sockets
and pcmcia devices, .rc and .agent. For the pcmcia.* scripts to work
properly a patch to modprobe is needed.

	Dominik
-------------- next part --------------
#!/bin/sh
#
# PCMCIA-specific hotplug policy agent
#
# $Id$
#

#DEBUG=yes; export DEBUG
SYSFS=/sys

cd /etc/hotplug
. ./hotplug.functions

if [ "$ACTION" = "" ]; then
    mesg Bad PCMCIA agent invocation, no action
    exit 1
fi

debug_mesg $SOCKET_NO $DEVICE_NO $MODNAME $DEVPATH

case $ACTION in

add)
	modprobe $MODNAME

	# check whether the CIS is completely broken
	if [ ! -h $SYSFS$DEVPATH/driver ]; then
		CISFILE=$(pcmcia-check-broken-cis $SOCKET_NO)
		debug_mesg $CISFILE;
		if [ ! -z $CISFILE ]; then
			if [ -f /etc/pcmcia/cis/$CISFILE ]; then
				cat /etc/pcmcia/cis/$CISFILE > /sys/class/pcmcia_socket/pcmcia_socket$(SOCKET_NO)/cis
			elif [ -f /lib/firmware/cis/$CISFILE ]; then
				cat /lib/firmware/cis/$CISFILE > /sys/class/pcmcia_socket/pcmcia_socket$(SOCKET_NO)/cis
			fi;
		fi;
	fi;

	# allow a match solely based on the "function ID" field
	if [ ! -h $SYSFS$DEVPATH/driver ]; then
		if [ -w $SYSFS$DEVPATH/allow_func_id_match ]; then
			debug_mesg allowing func_id based match for PCMCIA device $SOCKET_NO.$DEVICE_NO
			echo -n "42" > $SYSFS$DEVPATH/allow_func_id_match;
		fi;
	fi;
	;;
remove)
	;;
*)
	debug_mesg "PCMCIA '$ACTION' event not supported"
	;;

esac
-------------- next part --------------
#!/bin/sh
# vim: syntax=sh
#
# pcmcia.rc	recover lost boot-time pcmcia_socket hotplug events
#
# $Id: $
#

PATH=/sbin:/bin:/usr/sbin:/usr/bin
#DEBUG=yes; export DEBUG

cd /etc/hotplug
. ./hotplug.functions

pcmcia_boot_events ()
{
    if [ -d /sys/bus/pcmcia/devices/ ]; then
	# 2.6 kernels
	cd /sys/bus/pcmcia/devices/
	for PCMCIA_DEVICE in *; do
	    if [ $PCMCIA_DEVICE == \* ]; then
		continue;
	    fi;
	    MODNAME=$(pcmcia-modalias $PCMCIA_DEVICE)
	    debug_mesg $MODNAME $PCMICA_DEVICE
	    if [ -z $MODNAME ]; then
		continue;
	    fi;
	    ACTION=add
	    export MODNAME ACTION
	    /sbin/hotplug pcmcia
	done;
    fi;

    return 0
}

# See how we were called.
case "$1" in
  start)
	pcmcia_boot_events
        ;;
  stop)
	# echo $"pcmcia stop -- ignored"
        ;;
  restart)
	# always invoke by absolute path, else PATH=$PATH:
	$0 stop && $0 start
	;;
  *)
        echo $"Usage: $0 {start|stop|restart}"
        exit 1
esac
-------------- next part --------------
#!/bin/sh
#
# PCMCIA-socket-specific hotplug policy agent
#
# $Id$
#

#DEBUG=yes; export DEBUG

cd /etc/hotplug
. ./hotplug.functions

if [ "$ACTION" = "" ]; then
    mesg Bad PCMCIA socket agent invocation, no action
    exit 1
fi

debug_mesg socket number: $SOCKET_NO

case $ACTION in

add)
	sleep 1;
	pcmcia-socket-startup $SOCKET_NO
	DONE_FILE=/sys/class/pcmcia_socket/pcmcia_socket$SOCKET_NO/available_resources_setup_done
	if [ -f  $DONE_FILE ]; then
	    if [ -w $DONE_FILE ]; then
		echo -n "42" > $DONE_FILE
	    fi;
	fi;
	;;
remove)
	;;
*)
	debug_mesg "PCMCIA socket '$ACTION' event not supported"
	;;

esac
-------------- next part --------------
#!/bin/sh
# vim: syntax=sh
#
# pcmcia.rc	recover lost boot-time pcmcia_socket hotplug events
#
# $Id: $
#

PATH=/sbin:/bin:/usr/sbin:/usr/bin
#DEBUG=yes; export DEBUG

cd /etc/hotplug
. ./hotplug.functions

pcmcia_boot_events ()
{
    if [ -d /sys/class/pcmcia_socket/ ]; then
	# 2.6 kernels
	cd /sys/class/pcmcia_socket/
	for PCMCIA_SOCKET in *; do
	    if [ $PCMCIA_SOCKET == \* ]; then
		continue;
	    fi;
	    SOCKET_NO=$(echo $PCMCIA_SOCKET | cut -b14-)
	    ACTION=add
	    export SOCKET_NO ACTION
	    /sbin/hotplug pcmcia_socket
	done;
    fi;

    return 0
}

# See how we were called.
case "$1" in
  start)
	pcmcia_boot_events
        ;;
  stop)
	# echo $"pcmcia stop -- ignored"
        ;;
  restart)
	# always invoke by absolute path, else PATH=$PATH:
	$0 stop && $0 start
	;;
  *)
        echo $"Usage: $0 {start|stop|restart}"
        exit 1
esac


More information about the linux-pcmcia mailing list