Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / afsd / afs_rtsymtab.pl.sgi_53
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 5.3 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 5.3 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(), idbg_addfunc(),
81 qprintf(), 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(), doass(), in_cksum(), convoff(), debug(), copyinstr(),
87 stime(), sysent(), syscallsw() ;";
88 #
89 # For each member of @NewSymtabEntries, an entry of the following type must be
90 # added (if one does not exist) to the rtsymtab[] array.
91 #
92 # {(long) &time, "time"}, /* DDI/DKI */
93 #
94 @NewSymtabEntries = (
95 "time",
96 "vmonitor",
97 "pmonitor",
98 "rmonitor",
99 "amonitor",
100 "spunlock_psema",
101 "spunlockspl_psema",
102 "vn_rele",
103 "vn_hold",
104 "vn_rdwr",
105 "vn_initlist",
106 "ptossvp",
107 "cleanlocks",
108 "crget",
109 "crdup",
110 "crhold",
111 "crfree",
112 "remapf",
113 "lookupname",
114 "exit",
115 "sys_cred",
116 "vfs_devsearch",
117 "iget",
118 "iput",
119 "efs_ialloc",
120 "falloc",
121 "iunlock",
122 "fready",
123 "vrelvm",
124 "settime",
125 "wtodc",
126 "socreate",
127 "soreserve",
128 "sobind",
129 "soclose",
130 "xdr_string",
131 "xdr_u_long",
132 "xdr_char",
133 "xdr_long",
134 "xdr_short",
135 "xdr_bytes",
136 "xdr_opaque",
137 "xdr_u_short",
138 "xdr_u_int",
139 "xdr_int",
140 "xdr_array",
141 "inetdomain",
142 "udpcksum",
143 "ifcksum",
144 "ip_stripoptions",
145 "in_cksum",
146 "stime",
147 "sysent",
148 "syscallsw",
149 "estgroups",
150 "setgroups",
151 "setgroupsp",
152 "afs_vfsopsp",
153 "afs_vnodeopsp",
154 "afsidestroyp",
155 "afsdptoipp",
156 "afsiptodpp",
157 "idbg_prafsnodep",
158 "idbg_afsvfslistp",
159 "idbg_addfunc",
160 "initmonitor",
161 "pflushinvalvp",
162 "pflushvp",
163 "pdflush",
164 "ngroups_max",
165 "pinvalfree",
166 "fs_setfl",
167 "fs_cmp",
168 "fs_nosys",
169 "fs_poll",
170 "fs_pathconf",
171 "fs_frlock",
172 "convoff",
173 "__ll_rem",
174 "chunkread",
175 "getchunk",
176 "debug",
177 "bp_mapin",
178 "bawrite",
179 "bwrite",
180 "fs_map_subr",
181 "cpsema",
182 "qprintf",
183 "copyinstr",
184 "checkauth",
185 "imon_event",
186 "imon_enabled",
187 "exported_lock",
188 "rfsdisptab_v3",
189 "getvfs",
190 "mrunlock",
191 "vattr_to_wcc_data",
192 "vattr_to_wcc_attr",
193 "vattr_to_fattr3",
194 "hostintable",
195 "puterrno3",
196 "makefh3",
197 "vsync"
198 );
199
200 #
201 # Check that /var/sysgen/master.d/rtsymtab exists and does not contain
202 # AFS symbols
203 #
204
205 die ("\n\tError: Cannot find $FILE\n" .
206 "\tCheck your Operating System installation documentation.\n")
207 if (! -f $FILE);
208 if (! $force && ! system("/bin/grep afs_vnodeops $FILE > /dev/null")) {
209 die ("\n\tError: It looks like $FILE has already been
210 modified for dynamically loading AFS. If this is incorrect, run
211 this script again with the -force flag\n\n");
212 }
213
214 #
215 # Read all the symbols in the rtsymtab[] table from $FILE
216 # and mark them in an associative array indexed by the symbol name.
217 #
218
219 open(SYMTAB, "<$FILE") || die("\nError: failed to open $FILE: $!\n");
220 $found = 0;
221 while (<SYMTAB>) { # Skip ahead to rtsymtab definition
222 last if /rtsymtab\[\]/;
223 }
224 while (<SYMTAB>) { # Extract the name of each symbol
225 if (/{.*,.*"(.*)"}/) {
226 $OldSymtabEntries{$1} = 1;
227 $found++;
228 }
229 }
230 #
231 # Make sure that the above loop worked!
232 #
233 die("Error: Could not locate the rtsymtab\[\] table in $FILE\n\n")
234 if (! $found);
235
236 close(SYMTAB);
237
238
239 #
240 # Check if any of the new symbols that we need to add exist in the rtsymtab
241 # table. Keep track of all symbols that we delete from NewSymtabEntries.
242 #
243
244 $offset=0;
245 for $var (@NewSymtabEntries) {
246 if ($OldSymtabEntries{$var}) {
247 $del = splice(@NewSymtabEntries,$offset,1);
248 push(@DelSymtabEntries, $del);
249 #print "debug: $var exists\n";
250 }
251 $offset++;
252 }
253
254 #
255 # Create the new rtsymtab file.
256 # Place the new extern definitions just before the rtsymtab[] table
257 # definition. Append new entries to the rtsymtab table to the end
258 # of the file.
259 #
260
261 open(NEWSYMTAB, ">$FILE.new") || die("Error: Could not open $File.new: $!\n");
262 open(OLDSYMTAB, "<$FILE") || die("Error: Could not open $FILE: $!\n");
263
264 print "Creating $FILE.new\n";
265
266 while (<OLDSYMTAB>) {
267 if (/rtsymtab\[\] = {/) {
268 print NEWSYMTAB "\n /*\n * The following extern definitions";
269 print NEWSYMTAB " are required by AFS\n */\n";
270 print NEWSYMTAB "$ExternHeaders\n\n";
271 print NEWSYMTAB "$ExternDefns\n\n";
272 print NEWSYMTAB "#define DEBUG 1 /* Required by AFS */\n\n";
273 print NEWSYMTAB $_;
274 } else {
275 print NEWSYMTAB $_;
276 }
277 }
278
279 #
280 # Append the new rtsymtab[] entries to the end of the file
281 #
282
283 print NEWSYMTAB "\t/*\n\t * The following symbols are required by AFS\n";
284 print NEWSYMTAB "\t */\n\n";
285
286 foreach $var (@NewSymtabEntries) {
287 printf(NEWSYMTAB "\t {(long) &%s,%15s},\t\t%s\n",
288 $var, "\"$var\"", "/* DDI/DDK */");
289 }
290
291 close(NEWSYMTAB);
292 close(OLDSYMTAB);
293
294 #
295 # Replace $FILE with $FILE.new
296 #
297 #print "NOT renaming files!\n";
298
299 die ("Error: Could not move $FILE to $FILE.orig: $!\n")
300 if (! rename($FILE, "$FILE.orig"));
301 print "Moved $FILE to $FILE.orig\n";
302 die ("Error: Could not move $FILE.new to $FILE: $!\n")
303 if (! rename("$FILE.new", $FILE));
304 print "Moved $FILE.new to $FILE\n";
305
306
307 #
308 # List rtsymtab[] entries that were not added to the new file.
309 #
310
311 if ($#DelSymtabEntries >= 0) {
312
313 open(LOGFILE,">$LOG") || die("Error: Could not open $LOG: $!");
314
315 print LOGFILE "\n\n\tThe following entries were already defined
316 in the rtsymtab\[\] table in $FILE.
317 View $FILE and verify the correctness of these entries.
318 Make sure that these entries are correctly defined for this
319 machine. \n\n";
320
321 for $var (@DelSymtabEntries) {
322 printf(LOGFILE "\t {(long) &%s,%15s},\t\t%s\n",
323 $var, "\"$var\"", "/* DDI/DDK */");
324 }
325 print LOGFILE "\n\tNOTE: This message has been saved in $LOG\n";
326 close(LOGFILE);
327 system("/bin/cat $LOG");
328 }
329
330 print "\n$scriptname Done. $FILE has been modified to allow
331 AFS 3.4 kernel extentions to be dynamically loaded using /sbin/ml.\n\n";
332