linux-rc-file-cleanup-20011008
[openafs.git] / src / afsd / afs_rtsymtab.pl.sgi_61
1 #!/bin/perl
2 # Copyright 2000, International Business Machines Corporation and others.
3 # All Rights Reserved.
4
5 # This software has been released under the terms of the IBM Public
6 # License.  For details, see the LICENSE file in the top-level source
7 # directory or online at http://www.openafs.org/dl/license10.html
8
9 # afs_rtsymtab.pl       (For IRIX 6.1 only)
10 #       This script modifies /var/sysgen/master.d/rtsymtab file so that 
11 # AFS kernel extentions can be dynamically loaded using /sbin/ml.
12 # The original version of rtsymtab is saved as 
13 # /var/sysgen/master.d/rtsymtab.orig. This script must be run only 
14 # once on each SGI IRIX 5.3 machine that is to be an AFS 3.4 client.
15
16 # Usage: afs_rtsymtab.pl -run [-force] [-help]
17 #
18
19
20
21 @scriptnameparts = split('/', $0);
22 $scriptname = pop @scriptnameparts;
23
24 $FILE = "/var/sysgen/master.d/rtsymtab";
25 $LOG = "/tmp/$scriptname.log";
26
27 #
28 # This script must be run by the superuser
29
30 die ("\n$scriptname: Sorry, this script must be run by root.\n\n") 
31         if ($< != 0);
32
33 $USAGE="\nUsage: $scriptname -run [-force] [-help]
34
35         This script modifies $FILE in IRIX 6.1 so that 
36         AFS 3.4 kernel extentions may be dynamically loaded using 
37         /sbin/ml. A copy of $FILE is saved 
38         as $FILE.orig before it is changed. 
39         You will need to run this script only once after you install 
40         AFS 3.4 on your clients. 
41
42         This script will exit if it determines that 
43         $FILE has already been modifed for AFS. 
44         If this is incorrect, run this script again with the 
45         -force flag.\n\n";
46         
47 #
48 # Parse command line
49 #
50 $run = $force = 0;
51 for $_ (@ARGV) {
52         if (/-run/) {
53                 $run = 1;
54         } elsif (/-force/) {
55                 $force = 1;
56         } else {
57                 die $USAGE      
58         }
59 }
60 die $USAGE if (! $run);
61
62 #
63 # The following extern definitions are required by AFS and 
64 # must be added to $FILE
65 # These headers are part of the mimimal OS configuration. They should always
66 # be present on the system.
67 #
68 $ExternHeaders = 
69 "#include <sys/vnode.h>
70 #include <sys/file.h>
71 #include <netinet/in.h>
72 #include <netinet/ip_var.h>
73 #include <sys/fs_subr.h>
74 #include <sys/sema.h>";
75
76 $ExternDefns =
77 "extern time(), remapf(), exit(), iget(), iput(), efs_ialloc(),
78         iunlock(), estgroups(), setgroups(), setgroupsp(), afs_vfsopsp(),
79         afs_vnodeopsp(), afsidestroyp(), afsdptoipp(), afsiptodpp(),
80         hostintable(), idbg_prafsnodep(), idbg_afsvfslistp(), 
81         checkauth(), __ll_rem(), exported_lock(), rfsdisptab_v3(),
82         vattr_to_wcc_data(), vattr_to_wcc_attr(), vattr_to_fattr3(),
83         puterrno3(), makefh3(), xdr_string(), xdr_u_long(), xdr_char(),
84         xdr_long(), xdr_short(), xdr_bytes(), xdr_opaque(), xdr_u_short(),
85         xdr_u_int(), xdr_int(), xdr_array(), vsync(),
86         assfail(), in_cksum(), convoff(), debug(),
87         stime(), sysent(), syscallsw(), wtodc(), in_ifaddr();";
88
89 #
90 # For each member of @NewSymtabEntries, an entry of the following type must be
91 # added (if one does not exist) to the rtsymtab[] array.
92 #
93 #  {(long) &time,         "time"},                /* DDI/DKI */
94 #
95 @NewSymtabEntries = (
96 "assfail",
97 "time",
98 "vmonitor",
99 "doass",
100 "pmonitor",
101 "rmonitor",
102 "amonitor",
103 "vn_rele",
104 "vn_hold",
105 "vn_rdwr",
106 "vn_initlist",
107 "ptossvp",
108 "cleanlocks",
109 "crget",
110 "crdup",
111 "crhold",
112 "crfree",
113 "lookupname",
114 "sys_cred",
115 "vfs_devsearch",
116 "iget",
117 "iput",
118 "efs_ialloc",
119 "falloc",
120 "iunlock",
121 "fready",
122 "vrelvm",
123 "settime",
124 "wtodc",
125 "socreate",
126 "soreserve",
127 "sobind",
128 "soclose",
129 "xdr_string",
130 "xdr_u_long",
131 "xdr_char",
132 "xdr_long",
133 "xdr_short",
134 "xdr_bytes",
135 "xdr_opaque",
136 "xdr_u_short",
137 "xdr_u_int",
138 "xdr_int",
139 "xdr_array",
140 "inetdomain",
141 "udpcksum",
142 "ifcksum",
143 "ip_stripoptions",
144 "in_cksum",
145 "stime",
146 "sysent",
147 "syscallsw",
148 "estgroups",
149 "setgroups",
150 "setgroupsp",
151 "afs_vfsopsp",
152 "afs_vnodeopsp",
153 "afsidestroyp",
154 "afsdptoipp",
155 "afsiptodpp",
156 "idbg_prafsnodep",
157 "idbg_afsvfslistp",
158 "initmonitor",
159 "pflushinvalvp",
160 "pflushvp",
161 "pdflush",
162 "ngroups_max",
163 "pinvalfree",
164 "fs_setfl",
165 "fs_cmp",
166 "fs_nosys",
167 "fs_poll",
168 "fs_pathconf",
169 "fs_frlock",
170 "convoff",
171 "chunkread",
172 "getchunk",
173 "bp_mapin",
174 "bawrite",
175 "bwrite",
176 "fs_map_subr",
177 "checkauth",
178 "imon_event",
179 "imon_enabled",
180 "exported_lock",
181 "rfsdisptab_v3",
182 "getvfs",
183 "vattr_to_wcc_data",
184 "vattr_to_wcc_attr",
185 "vattr_to_fattr3",
186 "hostintable",
187 "puterrno3",
188 "makefh3",
189 "vsync",
190 "in_ifaddr",
191 "irix5_microtime"
192 );
193
194 #
195 # Check that /var/sysgen/master.d/rtsymtab exists and does not contain
196 # AFS symbols
197 #
198
199 die ("\n\tError: Cannot find $FILE\n" .
200      "\tCheck your Operating System installation documentation.\n") 
201     if (! -f $FILE); 
202 if (! $force && ! system("/bin/grep afs_vnodeops $FILE > /dev/null")) {
203         die ("\n\tError: It looks like $FILE has already been 
204         modified for dynamically loading AFS. If this is incorrect, run 
205         this script again with the -force flag\n\n");
206 }
207
208 #
209 # Read all the symbols in the rtsymtab[] table from  $FILE
210 # and mark them in an associative array indexed by the symbol name.
211 #
212
213 open(SYMTAB, "<$FILE") || die("\nError: failed to open $FILE: $!\n");
214 $found = 0;
215 while (<SYMTAB>) {              # Skip ahead to rtsymtab definition
216         last if /rtsymtab\[\]/;
217 }
218 while (<SYMTAB>) {              # Extract the name of each symbol
219         if (/{.*,.*"(.*)"}/) {
220                 $OldSymtabEntries{$1} = 1;
221                 $found++;
222         }
223 }
224 #
225 # Make sure that the above loop worked! 
226 #
227 die("Error: Could not locate the rtsymtab\[\] table in $FILE\n\n")
228         if (! $found); 
229
230 close(SYMTAB);
231
232
233 #
234 # Check if any of the new symbols that we need to add exist in the rtsymtab
235 # table. Keep track of all symbols that we delete from NewSymtabEntries.
236 #
237
238 $offset=0;
239 # This section of code does not work. If a variable is already in the list
240 # the following variable is not tested. We don't need this anyway, since
241 # it's ok for an item to be in the list more than once.
242 #for $var (@NewSymtabEntries) {
243 #        print "@@@: var: $var\n";
244 #       if ($OldSymtabEntries{$var}) {
245 #               $del = splice(@NewSymtabEntries,$offset,1);
246 #               push(@DelSymtabEntries, $del);
247 #               print "debug: $var exists\n";
248 #       }
249 #        $offset++;
250 #}
251
252 #
253 # Create the new rtsymtab file.
254 # Place the new extern definitions just before the rtsymtab[] table 
255 # definition. Append new entries to the rtsymtab table to the end 
256 # of the file.
257 #
258
259 open(NEWSYMTAB, ">$FILE.new") || die("Error: Could not open $File.new: $!\n");
260 open(OLDSYMTAB, "<$FILE") || die("Error: Could not open $FILE: $!\n");
261
262 print "Creating $FILE.new\n";
263
264 while (<OLDSYMTAB>) {
265         if (/rtsymtab\[\] = {/) {
266                 print NEWSYMTAB "\n /*\n  * The following extern definitions";
267                 print NEWSYMTAB " are required by AFS\n  */\n";
268                 print NEWSYMTAB "$ExternHeaders\n\n";
269                 print NEWSYMTAB "$ExternDefns\n\n";
270                 print NEWSYMTAB $_;
271         } else {
272                 print NEWSYMTAB $_;
273         }
274
275
276 #
277 # Append the new rtsymtab[] entries to the end of the file
278 #
279
280 print NEWSYMTAB "\t/*\n\t  * The following symbols are required by AFS\n";
281 print NEWSYMTAB "\t  */\n\n";
282
283 foreach $var (@NewSymtabEntries) {
284         printf(NEWSYMTAB "\t {(long) &%s,%15s},\t\t%s\n",
285                         $var, "\"$var\"", "/* DDI/DDK */");
286 }
287
288 close(NEWSYMTAB);
289 close(OLDSYMTAB);
290
291 #
292 # Replace $FILE with $FILE.new
293
294 #print "NOT renaming files!\n";
295
296 die ("Error: Could not move $FILE to $FILE.orig: $!\n")
297         if (! rename($FILE, "$FILE.orig"));
298 print "Moved $FILE to $FILE.orig\n";
299 die ("Error: Could not move $FILE.new to $FILE: $!\n")
300         if (! rename("$FILE.new", $FILE));
301 print "Moved $FILE.new to $FILE\n";
302
303
304 #
305 # List rtsymtab[] entries that were not added to the new file.
306
307
308 if ($#DelSymtabEntries >= 0) {
309
310         open(LOGFILE,">$LOG") || die("Error: Could not open $LOG: $!");
311
312         print LOGFILE "\n\n\tThe following entries were already defined 
313         in the rtsymtab\[\] table in $FILE.
314         View $FILE and verify the correctness of these entries.
315         Make sure that these entries are correctly defined for this 
316         machine. \n\n";
317
318         for $var (@DelSymtabEntries) {
319                 printf(LOGFILE "\t {(long) &%s,%15s},\t\t%s\n",
320                                 $var, "\"$var\"", "/* DDI/DDK */");
321         }
322         print LOGFILE "\n\tNOTE: This message has been saved in $LOG\n";
323         close(LOGFILE);
324         system("/bin/cat $LOG");
325 }
326
327 print "\n$scriptname Done. $FILE has been modified to allow 
328 AFS 3.4 kernel extentions to be dynamically loaded using /sbin/ml.\n\n"; 
329