File: hotplug-pcmcia.sh

package info (click to toggle)
ddetect 1.14
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 736 kB
  • ctags: 112
  • sloc: sh: 872; ansic: 533; makefile: 93
file content (82 lines) | stat: -rwxr-xr-x 2,060 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/sh
#
# hotplug-pcmcia.sh - Handle hotplug events for PCMCIA devices during detection
#

log () {
	logger -t hotplug-pcmcia "$@"
}

TYPE="$1"

case $TYPE in
	net)
		if [ "$INTERFACE" = "" ]; then
			log "Got net event without interface"
			exit 1
		fi

		log "Detected PCMCIA network interface $INTERFACE"
		echo $INTERFACE >>/etc/network/devhotplug
	;;

	# PCI hotplugging for Cardbus cards on 2.4 kernels only
	pci)
		if [ "$PCI_SLOT_NAME" = "" ]; then
			log "Got pci event without slot name"
			exit 1
		fi

		# Sanity check
		if ! [ -f /tmp/pcmcia-discover-snapshot ]; then
			log "Got PCI event but have no discover snapshot! 2.6 kernel?"
			exit 1
		fi

		log "Detected Cardbus device at $PCI_SLOT_NAME"

		# Take another snapshot of discover information and compare it
		# with the old one to find out the module for the new device

		log "Searching for module..."

		modules_before=`cat /tmp/pcmcia-discover-snapshot`

		DISCOVER_TEST=$(discover --version 2> /dev/null) || true
		if expr "$DISCOVER_TEST" : 'discover 2.*' > /dev/null 2>&1; then
			dpath=linux/module/name
			dver=`uname -r|cut -d. -f1,2` # Kernel version (e.g. 2.4)
			dflags="-d all -e pci scsi fixeddisk modem network removabledisk"
	    
			echo `discover --data-path=$dpath --data-version=$dver $dflags` \
				| sed 's/ $//' >/tmp/pcmcia-discover-snapshot
		else
			discover --format="%m " --disable-all --enable=pci \
				scsi ide ethernet \
				| sed 's/ $//' >/tmp/pcmcia-discover-snapshot
		fi
	    
		modules_after=`cat /tmp/pcmcia-discover-snapshot`
		module=`echo "${modules_after#$modules_before}" | sed 's/^ //'`

		if [ -n "$module" ]; then
			log "Found module $module, loading"
			if modprobe $module >/dev/null 2>&1; then
				log "Module $module loaded successfully"
			else
				log "Failed loading $module (queuing)"
				echo "$module" >>/etc/pcmcia/cb_mod_queue
			fi
		else
			log "No module found for Cardbus device at $PCI_SLOT_NAME"
		fi
	;;

	pcmcia_socket)
		log "Got pcmcia_socket event"
	;;
	
	*)
		log "Got unsupported event type \"$TYPE\""
	;;
esac