import of upstream 2.4.34.4 from kernel.org
[linux-2.4.git] / Documentation / rmdev_dyn.cciss
1 #!/bin/sh 
2 #
3 # Author: Francis Wiran <Francis.Wiran@hp.com>
4 #
5 # Script to remove device nodes for SMART Array controllers. This will
6 # be the device nodes with major numbers which are dynamically allocated
7 # by the kernel. This script will not attempt to remove the device
8 # nodes with major number 104 thru 111 (c0 thru c7), which are 
9 # the major numbers that's allocated for cciss controllers by kernel.org.
10 #
11 # Usage:
12 # rmdev_dyn.cciss [ctlr num]
13 #
14 # With no arguments, the script will check to see if there are any nodes
15 # under /dev/cciss, whose major number no longer shows in /proc/partitions,
16 # or to be exact, no longer shows to be owned by cciss driver.
17 # If there is, then it will be removed.
18 #
19 # Note that it is a good idea to run rmdev_dyn.cciss script if you remove
20 # those controllers (the ones which major numbers were dynamically allocated)
21 # This will unclutter /dev, as well as preventing possible problems due to
22 # referenced devices and major numbers no longer available or taken by
23 # other non-cciss drivers.
24 #
25 # Passing arguments:
26 # If you know that one of your controllers, say cciss8, has been removed
27 # and the nodes are no longer valid, you could do
28 #
29 # rmdev_dyn.cciss 8 
30 #
31 # This is the same as doing `rm -f /dev/cciss/c8*` 
32
33 # Inputs
34 NR_CTLR=${1}
35
36 echo_usage()
37 {
38         echo "Usage: rmdev_dyn.cciss [ctlr num]"
39         echo "The script will not attempt to remove nodes for controllers"
40         echo "0 thru 7, therefore if you want to pass an argument,"
41         echo "make sure that ctlr num is equal or greater than 8"
42 }
43
44 rm_nod1()
45 {
46         if [ $1 -lt 8 ]; then
47                 echo_usage;
48                 exit
49         else
50                 rm -f /dev/cciss/c${1}*
51                 echo "removed /dev/cciss/c${1}*"
52         fi
53 }
54
55 rm_nod2()
56 {
57         for X in `ls -l /dev/cciss/c* |\
58                 awk '{print $5-i}' |\
59                 uniq`; do
60                 if [ \( $X -ge 104 \) -a \( $X -le 111 \) ]; then
61                         :
62                 elif [ `cat /proc/devices |\
63                         grep cciss |\
64                         grep $X |\
65                         wc -l` -eq 0 ]; then
66
67                         Y=`ls -l /dev/cciss/ |\
68                                 awk '{print $5-i ":"  $10}'|\
69                                 tr d ':' |\
70                                 grep $X |\
71                                 awk -F: '{print $2}' |\
72                                 uniq`
73
74                         Z="/dev/cciss/${Y}*"
75
76                         rm -f $Z
77                         echo "removed $Z"
78                 fi
79         done
80 }
81
82 # Start here
83 if [ $# -gt 0 ]; then
84         rm_nod1 $NR_CTLR;
85 else
86         rm_nod2;
87 fi