|
|
1.1 root 1: # Shell version to provide a more friendly interface to the 'devadm' system
2: # to enable a device.
3:
4: ##################### FUNCTION DEFINITIONS #######################
5:
6: # Call with the $0 of the script as a parameter; this commands writes the
7: # name of the directory containing the script to standard output.
8: # Example:
9: # conf_path $0
10:
11: conf_path () {
12: set `which $1 2>/dev/null` X
13: if [ $# -ne 2 ]; then
14: echo . # Assume the current directory.
15: return 1
16: fi
17: set `expr $1 : '\(.*\)/.*'` X
18: if [ $# -ne 2 ]; then
19: echo . # Must be in the current directory.
20: else
21: echo $1
22: fi
23: return 0
24: }
25:
26: # Report a usage message to standard output, with the name of the script
27: # passed as the argument to this function.
28:
29: usage () {
30: echo $1 ":" Enable device entries
31: echo "usage:\t[-f] [file ...] [[-e file ...] [-d file ...]] ..."
32: echo "\tBy default, enable the named devices, reporting conflicts"
33: echo "\t-d specifies that subsequent device names are to be disabled"
34: echo "\t-e specifies that subsequent device names are to be enabled"
35: echo "\t-f specifies that conflicting devices be automatically disabled"
36: }
37:
38: # Confirm whether a value is set to a yes
39:
40: isyes () {
41: [ $1 = y -o $1 = Y ]
42: return $?
43: }
44:
45: # Read the 'sdevice' parameters for a device into shell globals
46:
47: read_sdevice () {
48: grep ^$1 $CONF_DIR/sdevice 2>/dev/null 1>&2
49: if [ $? -ne 0 ]; then
50: echo There is no 'sdevice' entry for $1 1>&2
51: return 1
52: fi
53:
54: # set `grep ^$1 $CONF_DIR/mdevice 2>/dev/null`
55: # shift
56: # MDEV_FUNCS=$1
57: # MDEV_FLAGS=$2
58: # MDEV_PREFIX=$3
59: # MDEV_BLOCK_MAJ=$4
60: # MDEV_CHAR_MAJ=$5
61: # MDEV_MIN_MIN=$6
62: # MDEV_MIN_MAX=$7
63: # MDEV_DMA_CHAN=$8
64: # MDEV_CPU_ID=$9
65:
66: set `grep ^$1 $CONF_DIR/sdevice 2>/dev/null`
67: shift
68: SDEV_CONFIG=$1
69: SDEV_UNIT=$2
70: SDEV_INT_PRI=$3
71: SDEV_INT_TYPE=$4
72: SDEV_INT_VECT=$5
73: SDEV_IOA_LO=$6
74: SDEV_IOA_HI=$7
75: SDEV_CMA_LO=$8
76: SDEV_CMA_HI=$9
77:
78: OLD_SDEV_CONFIG=$SDEV_CONFIG
79: shift
80: OLD_SDEV_INFO="$*"
81: return 0
82: }
83:
84: # Update the value of an sdevice entry parameter
85:
86: set_enable_sdevice () {
87: if isyes $OLD_SDEV_CONFIG; then
88: if isyes $2; then
89: return 0 # No effect
90: fi
91: # Disabling an entry is always legal...
92: elif isyes $2; then
93: # Verify that there is nothing conflicting with us
94: BAD="`$HOME_DIR/devadm -I $CONF_DIR \
95: -S"$1 $2 $OLD_SDEV_INFO" -r`"
96: if [ -n "$BAD" ]; then
97: if [ -n "$FORCE_ENABLE" ]; then
98: $HOME_DIR/idenable -d $BAD
99: BAD="`$HOME_DIR/devadm -I $CONF_DIR \
100: -S"$1 $2 $OLD_SDEV_INFO" -r`"
101: fi
102: if [ -n "$BAD" ]; then
103: echo Enabling $1 will conflict with $BAD
104: return 1
105: fi
106: fi
107: else
108: return 0 # No effect
109: fi
110:
111: $HOME_DIR/devadm -I $CONF_DIR -S"$1 $2 $OLD_SDEV_INFO" -W
112: }
113:
114: HOME_DIR=`conf_path $0`
115: CONF_DIR=$HOME_DIR/..
116:
117: if [ $# -lt 1 ]; then
118: usage $0 1>&2
119: exit 100
120: fi
121:
122: ENABLE=y
123:
124: while [ $# -gt 0 ]; do
125: ARG=$1; shift
126: case $ARG in
127: -d) ENABLE=n
128: ;;
129:
130: -e) ENABLE=y
131: ;;
132:
133: -f) FORCE_ENABLE=1
134: ;;
135:
136: *) read_sdevice $ARG || exit 1
137: set_enable_sdevice $ARG $ENABLE
138: ;;
139: esac
140: done
141:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.