amd64-linux-dewarn-20041202
[openafs.git] / src / afs / LINUX / osi_module.c
1 /*
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
10 /*
11  * Linux module support routines.
12  *
13  */
14 #include <afsconfig.h>
15 #include "afs/param.h"
16
17 RCSID
18     ("$Header$");
19
20 #include <linux/module.h> /* early to avoid printf->printk mapping */
21 #include "afs/sysincludes.h"
22 #include "afsincludes.h"
23 #include "h/unistd.h"           /* For syscall numbers. */
24 #include "h/mm.h"
25
26 #ifdef AFS_AMD64_LINUX20_ENV
27 #include "../asm/ia32_unistd.h"
28 #endif
29
30 #include <linux/proc_fs.h>
31 #include <linux/slab.h>
32 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
33 #include <linux/init.h>
34 #include <linux/sched.h>
35 #endif
36 #if !defined(EXPORTED_SYS_CALL_TABLE) && defined(HAVE_KERNEL_LINUX_SYSCALL_H)
37 #include <linux/syscall.h>
38 #endif
39
40 #ifdef AFS_SPARC64_LINUX24_ENV
41 #define __NR_setgroups32      82        /* This number is not exported for some bizarre reason. */
42 #endif
43
44 #if !defined(AFS_LINUX24_ENV)
45 asmlinkage int (*sys_settimeofdayp) (struct timeval * tv,
46                                      struct timezone * tz);
47 #endif
48 asmlinkage long (*sys_setgroupsp) (int gidsetsize, gid_t * grouplist);
49 #ifdef EXPORTED_SYS_CALL_TABLE
50 #if defined(AFS_SPARC64_LINUX20_ENV) || defined(AFS_S390X_LINUX24_ENV)
51 extern unsigned int sys_call_table[];   /* changed to uint because SPARC64 and S390X have syscalltable of 32bit items */
52 #else
53 extern void *sys_call_table[];  /* safer for other linuces */
54 #endif
55 #else /* EXPORTED_SYS_CALL_TABLE */
56 #if defined(AFS_SPARC64_LINUX20_ENV) || defined(AFS_S390X_LINUX24_ENV)
57 static unsigned int *sys_call_table;    /* changed to uint because SPARC64 and S390X have syscalltable of 32bit items */
58 #else
59 static void **sys_call_table;   /* safer for other linuces */
60 #endif
61 #endif
62
63 #if defined(AFS_S390X_LINUX24_ENV)
64 #define _S(x) ((x)<<1)
65 #else
66 #define _S(x) x
67 #endif
68
69 extern struct file_system_type afs_fs_type;
70
71 #if !defined(AFS_LINUX24_ENV)
72 static long get_page_offset(void);
73 #endif
74
75 #if defined(AFS_LINUX24_ENV)
76 DECLARE_MUTEX(afs_global_lock);
77 #else
78 struct semaphore afs_global_lock = MUTEX;
79 #endif
80 int afs_global_owner = 0;
81 #if !defined(AFS_LINUX24_ENV)
82 unsigned long afs_linux_page_offset = 0;        /* contains the PAGE_OFFSET value */
83 #endif
84
85 /* Since sys_ni_syscall is not exported, I need to cache it in order to restore
86  * it.
87  */
88 #if defined(AFS_SPARC64_LINUX20_ENV) || defined(AFS_S390X_LINUX24_ENV)
89 static unsigned int afs_ni_syscall = 0;
90 #else
91 static void *afs_ni_syscall = 0;
92 #endif
93
94 #ifdef AFS_AMD64_LINUX20_ENV
95 #ifdef EXPORTED_IA32_SYS_CALL_TABLE
96 extern void *ia32_sys_call_table[];
97 #else
98 static void **ia32_sys_call_table;
99 #endif
100
101 static void *ia32_ni_syscall = 0;
102 asmlinkage long (*sys32_setgroupsp) (int gidsetsize, u16 * grouplist);
103 #if defined(__NR_ia32_setgroups32)
104 asmlinkage long (*sys32_setgroups32p) (int gidsetsize, gid_t * grouplist);
105 #endif /* __NR_ia32_setgroups32 */
106 #endif /* AFS_AMD64_LINUX20_ENV */
107
108 #ifdef AFS_PPC64_LINUX20_ENV
109 asmlinkage long (*sys32_setgroupsp)(int gidsetsize, gid_t *grouplist);
110 #endif /* AFS_AMD64_LINUX20_ENV */
111
112 #ifdef AFS_SPARC64_LINUX20_ENV
113 static unsigned int afs_ni_syscall32 = 0;
114 asmlinkage int (*sys32_setgroupsp) (int gidsetsize,
115                                     __kernel_gid_t32 * grouplist);
116 #if defined(__NR_setgroups32)
117 asmlinkage int (*sys32_setgroups32p) (int gidsetsize,
118                                       __kernel_gid_t32 * grouplist);
119 #endif /* __NR_setgroups32 */
120 #ifdef EXPORTED_SYS_CALL_TABLE
121 extern unsigned int sys_call_table32[];
122 #else /* EXPORTED_SYS_CALL_TABLE */
123 static unsigned int *sys_call_table32;
124 #endif /* EXPORTED_SYS_CALL_TABLE */
125
126 asmlinkage int
127 afs_syscall32(long syscall, long parm1, long parm2, long parm3, long parm4,
128               long parm5)
129 {
130     __asm__ __volatile__("srl %o4, 0, %o4\n\t" "mov %o7, %i7\n\t"
131                          "call afs_syscall\n\t" "srl %o5, 0, %o5\n\t"
132                          "ret\n\t" "nop");
133 }
134 #endif /* AFS_SPARC64_LINUX20_ENV */
135
136 static int afs_ioctl(struct inode *, struct file *, unsigned int,
137                      unsigned long);
138
139 static struct file_operations afs_syscall_fops = {
140     .ioctl = afs_ioctl,
141 };
142
143 int
144 csdbproc_read(char *buffer, char **start, off_t offset, int count,
145               int *eof, void *data)
146 {
147     int len, j;
148     struct afs_q *cq, *tq;
149     struct cell *tc;
150     char tbuffer[16];
151     afs_uint32 addr;
152     
153     len = 0;
154     ObtainReadLock(&afs_xcell);
155     for (cq = CellLRU.next; cq != &CellLRU; cq = tq) {
156         tc = QTOC(cq); tq = QNext(cq);
157         len += sprintf(buffer + len, ">%s #(%d/%d)\n", tc->cellName, 
158                        tc->cellNum, tc->cellIndex);
159         for (j = 0; j < MAXCELLHOSTS; j++) {
160             if (!tc->cellHosts[j]) break;
161             addr = ntohl(tc->cellHosts[j]->addr->sa_ip);
162             sprintf(tbuffer, "%d.%d.%d.%d", 
163                     (int)((addr>>24) & 0xff), (int)((addr>>16) & 0xff),
164                     (int)((addr>>8)  & 0xff), (int)( addr      & 0xff));
165             len += sprintf(buffer + len, "%s #%s\n", tbuffer, tbuffer);
166         }
167     }
168     ReleaseReadLock(&afs_xcell);
169     
170     if (offset >= len) {
171         *start = buffer;
172         *eof = 1;
173         return 0;
174     }
175     *start = buffer + offset;
176     if ((len -= offset) > count)
177         return count;
178     *eof = 1;
179     return len;
180 }
181
182 int
183 peerproc_read(char *buffer, char **start, off_t offset, int count,
184               int *eof, void *data)
185 {
186     int len, i, j;
187     struct rx_peer *sep;
188     
189     len = 0;
190     for (i = 0, j = 0; i < 256; i++) {
191         for (sep = rx_peerHashTable[i]; sep; sep = sep->next, j++) {
192             len += sprintf(buffer + len, "%lx: next=0x%lx, host=0x%x, ", (unsigned long)sep,
193                    (unsigned long)sep->next, sep->host);
194             len += sprintf(buffer + len, "ifMTU=%d, natMTU=%d, maxMTU=%d\n", sep->ifMTU,
195                    sep->natMTU, sep->maxMTU);
196             len += sprintf(buffer + len, "\trtt=%d:%d, timeout(%d:%d), nSent=%d, reSends=%d\n",
197                    sep->rtt, sep->rtt_dev, sep->timeout.sec,
198                    sep->timeout.usec, sep->nSent, sep->reSends);
199             len += sprintf(buffer + len, "\trefCount=%d, port=%d, idleWhen=0x%x\n",
200                    sep->refCount, sep->port, sep->idleWhen);
201             len += sprintf(buffer + len, "\tCongestionQueue (0x%lx:0x%lx), inPacketSkew=0x%x, outPacketSkew=0x%x\n",
202                  (unsigned long)sep->congestionQueue.prev, (unsigned long)sep->congestionQueue.next,
203                  sep->inPacketSkew, sep->outPacketSkew);
204 #ifdef RX_ENABLE_LOCKS
205             len += sprintf(buffer + len, "\tpeer_lock=%d\n", sep->peer_lock);
206 #endif /* RX_ENABLE_LOCKS */
207         }
208     }
209     
210     if (offset >= len) {
211         *start = buffer;
212         *eof = 1;
213         return 0;
214     }
215     *start = buffer + offset;
216     if ((len -= offset) > count)
217         return count;
218     *eof = 1;
219     return len;
220 }
221
222 int
223 rxstatsproc_read(char *buffer, char **start, off_t offset, int count,
224               int *eof, void *data)
225 {
226     int len, i;
227     
228     len = 0;
229     len += sprintf(buffer + len, "packetRequests = %d\n", rx_stats.packetRequests);
230     len += sprintf(buffer + len, "noPackets[%d] = %d\n", RX_PACKET_CLASS_RECEIVE,
231            rx_stats.receivePktAllocFailures);
232     len += sprintf(buffer + len, "noPackets[%d] = %d\n", RX_PACKET_CLASS_SEND,
233            rx_stats.sendPktAllocFailures);
234     len += sprintf(buffer + len, "noPackets[%d] = %d\n", RX_PACKET_CLASS_SPECIAL,
235            rx_stats.specialPktAllocFailures);
236     len += sprintf(buffer + len, "noPackets[%d] = %d\n", RX_PACKET_CLASS_RECV_CBUF,
237            rx_stats.receiveCbufPktAllocFailures);
238     len += sprintf(buffer + len, "noPackets[%d] = %d\n", RX_PACKET_CLASS_SEND_CBUF,
239            rx_stats.sendCbufPktAllocFailures);
240     len += sprintf(buffer + len, "socketGreedy = %d\n", rx_stats.socketGreedy);
241     len += sprintf(buffer + len, "bogusPacketOnRead = %d\n", rx_stats.bogusPacketOnRead);
242     len += sprintf(buffer + len, "bogusHost = %d\n", rx_stats.bogusHost);
243     len += sprintf(buffer + len, "noPacketOnRead = %d\n", rx_stats.noPacketOnRead);
244     len += sprintf(buffer + len, "noPacketBuffersOnRead = %d\n",
245            rx_stats.noPacketBuffersOnRead);
246     len += sprintf(buffer + len, "selects = %d\n", rx_stats.selects);
247     len += sprintf(buffer + len, "sendSelects = %d\n", rx_stats.sendSelects);
248     for (i = 0; i < RX_N_PACKET_TYPES; i++)
249         len += sprintf(buffer + len, "packetsRead[%d] = %d\n", i, rx_stats.packetsRead[i]);
250     len += sprintf(buffer + len, "dataPacketsRead = %d\n", rx_stats.dataPacketsRead);
251     len += sprintf(buffer + len, "ackPacketsRead = %d\n", rx_stats.ackPacketsRead);
252     len += sprintf(buffer + len, "dupPacketsRead = %d\n", rx_stats.dupPacketsRead);
253     len += sprintf(buffer + len, "spuriousPacketsRead = %d\n", rx_stats.spuriousPacketsRead);
254     for (i = 0; i < RX_N_PACKET_TYPES; i++)
255         len += sprintf(buffer + len, "packetsSent[%d] = %d\n", i, rx_stats.packetsSent[i]);
256     len += sprintf(buffer + len, "ackPacketsSent = %d\n", rx_stats.ackPacketsSent);
257     len += sprintf(buffer + len, "pingPacketsSent = %d\n", rx_stats.pingPacketsSent);
258     len += sprintf(buffer + len, "abortPacketsSent = %d\n", rx_stats.abortPacketsSent);
259     len += sprintf(buffer + len, "busyPacketsSent = %d\n", rx_stats.busyPacketsSent);
260     len += sprintf(buffer + len, "dataPacketsSent = %d\n", rx_stats.dataPacketsSent);
261     len += sprintf(buffer + len, "dataPacketsReSent = %d\n", rx_stats.dataPacketsReSent);
262     len += sprintf(buffer + len, "dataPacketsPushed = %d\n", rx_stats.dataPacketsPushed);
263     len += sprintf(buffer + len, "ignoreAckedPacket = %d\n", rx_stats.ignoreAckedPacket);
264     len += sprintf(buffer + len, "totalRtt = %d sec, %d usec\n", rx_stats.totalRtt.sec,
265            rx_stats.totalRtt.usec);
266     len += sprintf(buffer + len, "minRtt = %d sec, %d usec\n", rx_stats.minRtt.sec,
267            rx_stats.minRtt.usec);
268     len += sprintf(buffer + len, "maxRtt = %d sec, %d usec\n", rx_stats.maxRtt.sec,
269            rx_stats.maxRtt.usec);
270     len += sprintf(buffer + len, "nRttSamples = %d\n", rx_stats.nRttSamples);
271     len += sprintf(buffer + len, "nServerConns = %d\n", rx_stats.nServerConns);
272     len += sprintf(buffer + len, "nClientConns = %d\n", rx_stats.nClientConns);
273     len += sprintf(buffer + len, "nPeerStructs = %d\n", rx_stats.nPeerStructs);
274     len += sprintf(buffer + len, "nCallStructs = %d\n", rx_stats.nCallStructs);
275     len += sprintf(buffer + len, "nFreeCallStructs = %d\n", rx_stats.nFreeCallStructs);
276     len += sprintf(buffer + len, "netSendFailures  = %d\n", rx_stats.netSendFailures);
277     len += sprintf(buffer + len, "fatalErrors      = %d\n", rx_stats.fatalErrors);
278     
279     if (offset >= len) {
280         *start = buffer;
281         *eof = 1;
282         return 0;
283     }
284     *start = buffer + offset;
285     if ((len -= offset) > count)
286         return count;
287     *eof = 1;
288     return len;
289 }
290
291 int
292 rxproc_read(char *buffer, char **start, off_t offset, int count,
293               int *eof, void *data)
294 {
295     int len, i;
296     
297     len = 0;
298     len += sprintf(buffer + len, "rx_extraQuota = %d\n", rx_extraQuota);
299     len += sprintf(buffer + len, "rx_extraPackets = %d\n", rx_extraPackets);
300     len += sprintf(buffer + len, "rx_stackSize = %d\n", rx_stackSize);
301     len += sprintf(buffer + len, "rx_connDeadTime = %d\n", rx_connDeadTime);
302     len += sprintf(buffer + len, "rx_idleConnectionTime = %d\n", rx_idleConnectionTime);
303     len += sprintf(buffer + len, "rx_idlePeerTime = %d\n", rx_idlePeerTime);
304     len += sprintf(buffer + len, "rx_initSendWindow = %d\n", rx_initSendWindow);
305     len += sprintf(buffer + len, "rxi_nSendFrags = %d\n", rxi_nSendFrags);
306     len += sprintf(buffer + len, "rx_nPackets = %d\n", rx_nPackets);
307     len += sprintf(buffer + len, "rx_nFreePackets = %d\n", rx_nFreePackets);
308     len += sprintf(buffer + len, "rx_socket = 0x%lx\n", (unsigned long)rx_socket);
309     len += sprintf(buffer + len, "rx_Port = %d\n", rx_port);
310     for (i = 0; i < RX_N_PACKET_CLASSES; i++)
311         len += sprintf(buffer + len, "\trx_packetQuota[%d] = %d\n", i, rx_packetQuota[i]);
312
313     len += sprintf(buffer + len, "rx_nextCid = 0x%x\n", rx_nextCid);
314     len += sprintf(buffer + len, "rx_epoch = 0u%u\n", rx_epoch);
315     len += sprintf(buffer + len, "rx_waitingForPackets = %x\n", rx_waitingForPackets);
316     len += sprintf(buffer + len, "rxi_nCalls = %d\n", rxi_nCalls);
317     len += sprintf(buffer + len, "rxi_dataQuota = %d\n", rxi_dataQuota);
318     len += sprintf(buffer + len, "rxi_availProcs = %d\n", rxi_availProcs);
319     len += sprintf(buffer + len, "rxi_totalMin = %d\n", rxi_totalMin);
320     len += sprintf(buffer + len, "rxi_minDeficit = %d\n", rxi_minDeficit);
321
322     len += sprintf(buffer + len, "rxevent_nFree = %d\nrxevent_nPosted = %d\n", rxevent_nFree, rxevent_nPosted);
323     
324     if (offset >= len) {
325         *start = buffer;
326         *eof = 1;
327         return 0;
328     }
329     *start = buffer + offset;
330     if ((len -= offset) > count)
331         return count;
332     *eof = 1;
333     return len;
334 }
335
336 int
337 connproc_read(char *buffer, char **start, off_t offset, int count,
338               int *eof, void *data)
339 {
340     int len, i, j;
341     struct rx_connection *sep;
342     
343     len = 0;
344     for (i = 0, j = 0; i < 256; i++) {
345         for (sep = rx_connHashTable[i]; sep; sep = sep->next, j++) {
346             len += sprintf(buffer + len, "%lx: next=0x%lx, peer=0x%lx, epoch=0x%x, cid=0x%x, ackRate=%d\n",
347                            (unsigned long)sep, (unsigned long)sep->next, (unsigned long)sep->peer,
348                            sep->epoch, sep->cid, sep->ackRate);
349             len += sprintf(buffer + len, "\tcall[%lx=%d, %lx=%d, %lx=%d, %lx=%d]\n", 
350                            (unsigned long)sep->call[0], sep->callNumber[0],
351                            (unsigned long)sep->call[1], sep->callNumber[1],
352                            (unsigned long)sep->call[2], sep->callNumber[2],
353                            (unsigned long)sep->call[3], sep->callNumber[3]);
354             len += sprintf(buffer + len, "\ttimeout=%d, flags=0x%x, type=0x%x, serviceId=%d, service=0x%lx, refCount=%d\n",
355                            sep->timeout, sep->flags, sep->type, 
356                            sep->serviceId, (unsigned long)sep->service, sep->refCount);
357             len += sprintf(buffer + len, "\tserial=%d, lastSerial=%d, secsUntilDead=%d, secsUntilPing=%d, secIndex=%d\n",
358                            sep->serial, sep->lastSerial, sep->secondsUntilDead,
359                            sep->secondsUntilPing, sep->securityIndex);
360             len += sprintf(buffer + len, "\terror=%d, secObject=0x%lx, secData=0x%lx, secHeaderSize=%d, secmaxTrailerSize=%d\n",
361                            sep->error, (unsigned long)sep->securityObject,
362                            (unsigned long)sep->securityData,
363                            sep->securityHeaderSize, sep->securityMaxTrailerSize);
364             len += sprintf(buffer + len, "\tchallEvent=0x%lx, lastSendTime=0x%x, maxSerial=%d, hardDeadTime=%d\n",
365                            (unsigned long)sep->challengeEvent, sep->lastSendTime, 
366                            sep->maxSerial, sep->hardDeadTime);
367             if (sep->flags & RX_CONN_MAKECALL_WAITING)
368                 len += sprintf(buffer + len, "\t***** Conn in RX_CONN_MAKECALL_WAITING state *****\n");
369 #ifdef RX_ENABLE_LOCKS
370             len += sprintf(buffer + len, "\tcall_lock=%d, call_cv=%d, data_lock=%d, refCount=%d\n",
371                            sep->conn_call_lock, sep->conn_call_cv, 
372                            sep->conn_data_lock, sep->refCount);
373 #endif /* RX_ENABLE_LOCKS */
374         }
375     }
376     
377     if (offset >= len) {
378         *start = buffer;
379         *eof = 1;
380         return 0;
381     }
382     *start = buffer + offset;
383     if ((len -= offset) > count)
384         return count;
385     *eof = 1;
386     return len;
387 }
388
389 int
390 servicesproc_read(char *buffer, char **start, off_t offset, int count,
391               int *eof, void *data)
392 {
393     int len, i, j;
394     struct rx_service *sentry;
395     
396     len = 0;
397     for (i = 0, j = 0; i < RX_MAX_SERVICES; i++) {
398         if ((sentry = rx_services[i])) {
399             j++;
400             len += sprintf(buffer + len,
401                            "\t%lx: serviceId=%d, port=%d, serviceName=%s, socket=0x%lx\n",
402                            (unsigned long)sentry, sentry->serviceId, sentry->servicePort,
403                            sentry->serviceName, (unsigned long)sentry->socket);
404             len += sprintf(buffer + len,
405                            "\t\tnSecObj=%d, nReqRunning=%d, maxProcs=%d, minProcs=%d, connDeadTime=%d, idleDeadTime=%d\n",
406                            sentry->nSecurityObjects, sentry->nRequestsRunning,
407                            sentry->maxProcs, sentry->minProcs, 
408                            sentry->connDeadTime, sentry->idleDeadTime);
409         }
410     }
411     
412     if (offset >= len) {
413         *start = buffer;
414         *eof = 1;
415         return 0;
416     }
417     *start = buffer + offset;
418     if ((len -= offset) > count)
419         return count;
420     *eof = 1;
421     return len;
422 }
423
424 int
425 callproc_read(char *buffer, char **start, off_t offset, int count,
426               int *eof, void *data)
427 {
428     int len, i, j, k;
429     struct rx_connection *sep;
430     
431     len = 0;
432     for (i = 0, j = 0; i < 256; i++) {
433         for (sep = rx_connHashTable[i]; sep; sep = sep->next) {
434             for (k = 0; k < RX_MAXCALLS; k++) {
435                 struct rx_call *call = sep->call[k];
436                 if (call) {
437                     j++;
438                     len += sprintf(buffer + len,
439                                    "%lx: conn=0x%lx, qiheader(0x%lx:0x%lx), tq(0x%lx:0x%lx), rq(0x%lx:0x%lx)\n",
440                                    (unsigned long)call, (unsigned long)call->conn,
441                                    (unsigned long)call->queue_item_header.prev,
442                                    (unsigned long)call->queue_item_header.next,
443                                    (unsigned long)call->tq.prev, (unsigned long)call->tq.next,
444                                    (unsigned long)call->rq.prev, (unsigned long)call->rq.next);
445                     len += sprintf(buffer + len, 
446                                    "\t: curvec=%d, curpos=%lx, nLeft=%d, nFree=%d, currPacket=0x%lx, callNumber=0x%lx\n",
447                                    call->curvec, (unsigned long)call->curpos, call->nLeft,
448                                    call->nFree, (unsigned long)call->currentPacket,
449                                    (unsigned long)call->callNumber);
450                     len += sprintf(buffer + len,
451                                    "\t: channel=%d, state=0x%x, mode=0x%x, flags=0x%x, localStatus=0x%x, remStatus=0x%x\n",
452                                    call->channel, call->state, call->mode,
453                                    call->flags, call->localStatus,
454                                    call->remoteStatus);
455                     len += sprintf(buffer + len,
456                                    "\t: error=%d, timeout=0x%x, rnext=0x%x, rprev=0x%x, rwind=0x%x, tfirst=0x%x, tnext=0x%x\n",
457                                    call->error, call->timeout, call->rnext,
458                                    call->rprev, call->rwind, call->tfirst,
459                                    call->tnext);
460                     len += sprintf(buffer + len,
461                                    "\t: twind=%d, resendEvent=0x%lx, timeoutEvent=0x%lx, keepAliveEvent=0x%lx, delayedAckEvent=0x%lx\n",
462                                    call->twind, (unsigned long)call->resendEvent,
463                                    (unsigned long)call->timeoutEvent,
464                                    (unsigned long)call->keepAliveEvent,
465                                    (unsigned long)call->delayedAckEvent);
466                     len += sprintf(buffer + len,
467                                    "\t: lastSendTime=0x%x, lastReceiveTime=0x%x, lastAcked=0x%x, startTime=0x%x, startWait=0x%x\n",
468                                    call->lastSendTime, call->lastReceiveTime,
469                                    call->lastAcked, call->startTime.sec,
470                                    call->startWait);
471                     if (call->flags & RX_CALL_WAIT_PROC)
472                         len += sprintf(buffer + len,
473                                        "\t******** Call in RX_CALL_WAIT_PROC state **********\n");
474                     if (call->flags & RX_CALL_WAIT_WINDOW_ALLOC)
475                         len += sprintf(buffer + len,
476                                        "\t******** Call in RX_CALL_WAIT_WINDOW_ALLOC state **********\n");
477                     if (call->flags & RX_CALL_READER_WAIT)
478                         len += sprintf(buffer + len,
479                                        "\t******** Conn in RX_CALL_READER_WAIT state **********\n");
480                     if (call->flags & RX_CALL_WAIT_PACKETS)
481                         len += sprintf(buffer + len,
482                                        "\t******** Conn in RX_CALL_WAIT_PACKETS state **********\n");
483 #ifdef RX_ENABLE_LOCKS
484                     len += sprintf(buffer + len,
485                                    "\t: lock=0x%x, cv_twind=0x%x, cv_rq=0x%x, refCount= %d\n",
486                                    call->lock, call->cv_twind, call->cv_rq,
487                                    call->refCount);
488 #endif /* RX_ENABLE_LOCKS */
489                     len += sprintf(buffer + len, "\t: MTU=%d\n", call->MTU);
490                 }
491             }
492         }
493     }
494     
495     if (offset >= len) {
496         *start = buffer;
497         *eof = 1;
498         return 0;
499     }
500     *start = buffer + offset;
501     if ((len -= offset) > count)
502         return count;
503     *eof = 1;
504     return len;
505 }
506
507 static struct proc_dir_entry *openafs_procfs;
508
509 static int
510 afsproc_init()
511 {
512     struct proc_dir_entry *entry1;
513     struct proc_dir_entry *entry;
514
515     openafs_procfs = proc_mkdir(PROC_FSDIRNAME, proc_root_fs);
516     entry1 = create_proc_entry(PROC_SYSCALL_NAME, 0666, openafs_procfs);
517
518     entry1->proc_fops = &afs_syscall_fops;
519
520     entry1->owner = THIS_MODULE;
521
522     entry = create_proc_read_entry(PROC_CELLSERVDB_NAME, (S_IFREG|S_IRUGO), openafs_procfs, csdbproc_read, NULL);
523
524     entry = create_proc_read_entry(PROC_PEER_NAME, (S_IFREG|S_IRUGO), openafs_procfs, peerproc_read, NULL);
525
526     entry = create_proc_read_entry(PROC_CONN_NAME, (S_IFREG|S_IRUGO), openafs_procfs, connproc_read, NULL);
527
528     entry = create_proc_read_entry(PROC_CALL_NAME, (S_IFREG|S_IRUGO), openafs_procfs, connproc_read, NULL);
529
530     entry = create_proc_read_entry(PROC_RX_NAME, (S_IFREG|S_IRUGO), openafs_procfs, rxproc_read, NULL);
531
532     entry = create_proc_read_entry(PROC_SERVICES_NAME, (S_IFREG|S_IRUGO), openafs_procfs, servicesproc_read, NULL);
533
534     entry = create_proc_read_entry(PROC_RXSTATS_NAME, (S_IFREG|S_IRUGO), openafs_procfs, rxstatsproc_read, NULL);
535
536     return 0;
537 }
538
539 static void
540 afsproc_exit()
541 {
542     remove_proc_entry(PROC_RXSTATS_NAME, openafs_procfs);
543     remove_proc_entry(PROC_SERVICES_NAME, openafs_procfs);
544     remove_proc_entry(PROC_RX_NAME, openafs_procfs);
545     remove_proc_entry(PROC_CALL_NAME, openafs_procfs);
546     remove_proc_entry(PROC_CONN_NAME, openafs_procfs);
547     remove_proc_entry(PROC_PEER_NAME, openafs_procfs);
548     remove_proc_entry(PROC_CELLSERVDB_NAME, openafs_procfs);
549     remove_proc_entry(PROC_SYSCALL_NAME, openafs_procfs);
550     remove_proc_entry(PROC_FSDIRNAME, proc_root_fs);
551 }
552
553 extern asmlinkage long
554 afs_syscall(long syscall, long parm1, long parm2, long parm3, long parm4);
555
556 static int
557 afs_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
558           unsigned long arg)
559 {
560
561     struct afsprocdata sysargs;
562
563     if (cmd != VIOC_SYSCALL) return -EINVAL;
564
565     if (copy_from_user(&sysargs, (void *)arg, sizeof(struct afsprocdata)))
566         return -EFAULT;
567
568     return afs_syscall(sysargs.syscall, sysargs.param1,
569                        sysargs.param2, sysargs.param3, sysargs.param4);
570 }
571
572 #ifdef AFS_IA64_LINUX20_ENV
573
574 asmlinkage long
575 afs_syscall_stub(int r0, int r1, long r2, long r3, long r4, long gp)
576 {
577     __asm__ __volatile__("alloc r42 = ar.pfs, 8, 3, 6, 0\n\t" "mov r41 = b0\n\t"        /* save rp */
578                          "mov out0 = in0\n\t" "mov out1 = in1\n\t" "mov out2 = in2\n\t" "mov out3 = in3\n\t" "mov out4 = in4\n\t" "mov out5 = gp\n\t"   /* save gp */
579                          ";;\n" ".L1:    mov r3 = ip\n\t" ";;\n\t" "addl r15=.fptr_afs_syscall-.L1,r3\n\t" ";;\n\t" "ld8 r15=[r15]\n\t" ";;\n\t" "ld8 r16=[r15],8\n\t" ";;\n\t" "ld8 gp=[r15]\n\t" "mov b6=r16\n\t" "br.call.sptk.many b0 = b6\n\t" ";;\n\t" "mov ar.pfs = r42\n\t" "mov b0 = r41\n\t" "mov gp = r48\n\t"       /* restore gp */
580                          "br.ret.sptk.many b0\n" ".fptr_afs_syscall:\n\t"
581                          "data8 @fptr(afs_syscall)");
582 }
583
584 asmlinkage long
585 afs_xsetgroups_stub(int r0, int r1, long r2, long r3, long r4, long gp)
586 {
587     __asm__ __volatile__("alloc r42 = ar.pfs, 8, 3, 6, 0\n\t" "mov r41 = b0\n\t"        /* save rp */
588                          "mov out0 = in0\n\t" "mov out1 = in1\n\t" "mov out2 = in2\n\t" "mov out3 = in3\n\t" "mov out4 = in4\n\t" "mov out5 = gp\n\t"   /* save gp */
589                          ";;\n" ".L2:    mov r3 = ip\n\t" ";;\n\t" "addl r15=.fptr_afs_xsetgroups - .L2,r3\n\t" ";;\n\t" "ld8 r15=[r15]\n\t" ";;\n\t" "ld8 r16=[r15],8\n\t" ";;\n\t" "ld8 gp=[r15]\n\t" "mov b6=r16\n\t" "br.call.sptk.many b0 = b6\n\t" ";;\n\t" "mov ar.pfs = r42\n\t" "mov b0 = r41\n\t" "mov gp = r48\n\t"  /* restore gp */
590                          "br.ret.sptk.many b0\n" ".fptr_afs_xsetgroups:\n\t"
591                          "data8 @fptr(afs_xsetgroups)");
592 }
593
594 struct fptr {
595     void *ip;
596     unsigned long gp;
597 };
598
599 #endif /* AFS_IA64_LINUX20_ENV */
600
601 #ifdef AFS_LINUX24_ENV
602 asmlinkage int (*sys_setgroups32p) (int gidsetsize,
603                                     __kernel_gid32_t * grouplist);
604 #endif /* AFS_LINUX24_ENV */
605
606 #if defined(AFS_SPARC64_LINUX20_ENV) || defined(AFS_S390X_LINUX24_ENV)
607 #define POINTER2SYSCALL (unsigned int)(unsigned long)
608 #define SYSCALL2POINTER (void *)(long)
609 #else
610 #define POINTER2SYSCALL (void *)
611 #define SYSCALL2POINTER (void *)
612 #endif
613
614
615 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
616 int __init
617 afs_init(void)
618 #else
619 int
620 init_module(void)
621 #endif
622 {
623 #if defined(AFS_IA64_LINUX20_ENV)
624     unsigned long kernel_gp = 0;
625     static struct fptr sys_setgroups;
626 #endif /* defined(AFS_IA64_LINUX20_ENV) */
627     extern long afs_xsetgroups();
628 #if defined(__NR_setgroups32)
629     extern int afs_xsetgroups32();
630 #endif /* __NR_setgroups32 */
631 #if defined(AFS_SPARC64_LINUX20_ENV) || defined (AFS_AMD64_LINUX20_ENV) || defined(AFS_PPC64_LINUX20_ENV)
632     extern int afs32_xsetgroups();
633 #if (defined(__NR_setgroups32) && defined(AFS_SPARC64_LINUX20_ENV))
634     extern int afs32_xsetgroups32();
635 #endif /* defined(__NR_setgroups32) && defined(AFS_SPARC64_LINUX20_ENV) */
636 #if (defined(__NR_ia32_setgroups32) && defined(AFS_AMD64_LINUX20_ENV))
637     extern int afs32_xsetgroups32();
638 #endif /* (defined(__NR_ia32_setgroups32) && defined(AFS_AMD64_LINUX20_ENV) */
639 #endif /* AFS_SPARC64_LINUX20_ENV || AFS_AMD64_LINUX20_ENV || AFS_PPC64_LINUX20_ENV */
640
641 #if !defined(EXPORTED_SYS_CALL_TABLE) || (defined(AFS_AMD64_LINUX20_ENV) && !defined(EXPORTED_IA32_SYS_CALL_TABLE))
642     unsigned long *ptr;
643     unsigned long offset=0;
644     unsigned long datalen=0;
645 #if defined(EXPORTED_KALLSYMS_SYMBOL)
646     unsigned long token=0;
647 #endif
648 #if defined(EXPORTED_KALLSYMS_SYMBOL) || defined(EXPORTED_KALLSYMS_ADDRESS)
649     int ret;
650     char *mod_name;
651     unsigned long mod_start=0;
652     unsigned long mod_end=0;
653     char *sec_name;
654     unsigned long sec_start=0;
655     unsigned long sec_end=0;
656     char *sym_name;
657     unsigned long sym_start=0;
658     unsigned long sym_end=0;
659 #endif
660 #endif /* EXPORTED_SYS_CALL_TABLE */
661
662     RWLOCK_INIT(&afs_xosi, "afs_xosi");
663
664 #if !defined(AFS_LINUX24_ENV)
665     /* obtain PAGE_OFFSET value */
666     afs_linux_page_offset = get_page_offset();
667
668 #ifndef AFS_S390_LINUX22_ENV
669     if (afs_linux_page_offset == 0) {
670         /* couldn't obtain page offset so can't continue */
671         printf("afs: Unable to obtain PAGE_OFFSET. Exiting..");
672         return -EIO;
673     }
674 #endif /* AFS_S390_LINUX22_ENV */
675 #endif /* !defined(AFS_LINUX24_ENV) */
676
677 #ifndef EXPORTED_SYS_CALL_TABLE
678     sys_call_table = 0;
679
680 #ifdef EXPORTED_KALLSYMS_SYMBOL
681     ret = 1;
682     token = 0;
683     while (ret) {
684         sym_start = 0;
685         ret =
686             kallsyms_symbol_to_address("sys_call_table", &token, &mod_name,
687                                        &mod_start, &mod_end, &sec_name,
688                                        &sec_start, &sec_end, &sym_name,
689                                        &sym_start, &sym_end);
690         if (ret && !strcmp(mod_name, "kernel"))
691             break;
692     }
693     if (ret && sym_start) {
694         sys_call_table = sym_start;
695     }
696 #elif defined(EXPORTED_KALLSYMS_ADDRESS)
697     ret =
698         kallsyms_address_to_symbol((unsigned long)&init_mm, &mod_name,
699                                    &mod_start, &mod_end, &sec_name,
700                                    &sec_start, &sec_end, &sym_name,
701                                    &sym_start, &sym_end);
702     ptr = (unsigned long *)sec_start;
703     datalen = (sec_end - sec_start) / sizeof(unsigned long);
704 #elif defined(AFS_IA64_LINUX20_ENV)
705     ptr = (unsigned long *)(&sys_close - 0x180000);
706     datalen = 0x180000 / sizeof(ptr);
707 #elif defined(AFS_AMD64_LINUX20_ENV)
708     ptr = (unsigned long *)&init_mm;
709     datalen = 0x360000 / sizeof(ptr);
710 #else
711     ptr = (unsigned long *)&init_mm;
712     datalen = 16384;
713 #endif
714     for (offset = 0; offset < datalen; ptr++, offset++) {
715 #if defined(AFS_IA64_LINUX20_ENV)
716         unsigned long close_ip =
717             (unsigned long)((struct fptr *)&sys_close)->ip;
718         unsigned long chdir_ip =
719             (unsigned long)((struct fptr *)&sys_chdir)->ip;
720         unsigned long write_ip =
721             (unsigned long)((struct fptr *)&sys_write)->ip;
722         if (ptr[0] == close_ip && ptr[__NR_chdir - __NR_close] == chdir_ip
723             && ptr[__NR_write - __NR_close] == write_ip) {
724             sys_call_table = (void *)&(ptr[-1 * (__NR_close - 1024)]);
725             break;
726         }
727 #elif defined(EXPORTED_SYS_WAIT4) && defined(EXPORTED_SYS_CLOSE)
728         if (ptr[0] == (unsigned long)&sys_close
729             && ptr[__NR_wait4 - __NR_close] == (unsigned long)&sys_wait4) {
730             sys_call_table = ptr - __NR_close;
731             break;
732         }
733 #elif defined(EXPORTED_SYS_CHDIR) && defined(EXPORTED_SYS_CLOSE)
734         if (ptr[0] == (unsigned long)&sys_close
735             && ptr[__NR_chdir - __NR_close] == (unsigned long)&sys_chdir) {
736             sys_call_table = ptr - __NR_close;
737             break;
738         }
739 #elif defined(EXPORTED_SYS_OPEN)
740         if (ptr[0] == (unsigned long)&sys_exit
741             && ptr[__NR_open - __NR_exit] == (unsigned long)&sys_open) {
742             sys_call_table = ptr - __NR_exit;
743             break;
744         }
745 #else /* EXPORTED_SYS_OPEN */
746         break;
747 #endif /* EXPORTED_KALLSYMS_ADDRESS */
748     }
749 #ifdef EXPORTED_KALLSYMS_ADDRESS
750     ret =
751         kallsyms_address_to_symbol((unsigned long)sys_call_table, &mod_name,
752                                    &mod_start, &mod_end, &sec_name,
753                                    &sec_start, &sec_end, &sym_name,
754                                    &sym_start, &sym_end);
755     if (ret && strcmp(sym_name, "sys_call_table"))
756         sys_call_table = 0;
757 #endif /* EXPORTED_KALLSYMS_ADDRESS */
758     if (!sys_call_table) {
759         printf("Failed to find address of sys_call_table\n");
760     } else {
761         printf("Found sys_call_table at %lx\n", (unsigned long)sys_call_table);
762 #if defined(AFS_SPARC64_LINUX20_ENV) || defined(AFS_S390X_LINUX24_ENV)
763         error cant support this yet.;
764 #endif /* AFS_SPARC64_LINUX20_ENV */
765 #endif /* EXPORTED_SYS_CALL_TABLE */
766
767 #ifdef AFS_AMD64_LINUX20_ENV
768 #ifndef EXPORTED_IA32_SYS_CALL_TABLE
769         ia32_sys_call_table = 0;
770 #ifdef EXPORTED_KALLSYMS_SYMBOL
771         ret = 1;
772         token = 0;
773         while (ret) {
774             sym_start = 0;
775             ret = kallsyms_symbol_to_address("ia32_sys_call_table", &token,
776                                              &mod_name, &mod_start, &mod_end,
777                                              &sec_name, &sec_start, &sec_end,
778                                              &sym_name, &sym_start, &sym_end);
779             if (ret && !strcmp(mod_name, "kernel"))
780                 break;
781         }
782         if (ret && sym_start) {
783             ia32_sys_call_table = sym_start;
784         }
785 #else /* EXPORTED_KALLSYMS_SYMBOL */
786 #ifdef EXPORTED_KALLSYMS_ADDRESS
787         ret = kallsyms_address_to_symbol((unsigned long)
788                                          &interruptible_sleep_on,
789                                          &mod_name, &mod_start, &mod_end,
790                                          &sec_name, &sec_start, &sec_end,
791                                          &sym_name, &sym_start, &sym_end);
792         ptr = (unsigned long *)sec_start;
793         datalen = (sec_end - sec_start) / sizeof(unsigned long);
794 #else /* EXPORTED_KALLSYMS_ADDRESS */
795 #if defined(AFS_AMD64_LINUX20_ENV)
796         ptr = (unsigned long *)&interruptible_sleep_on;
797         datalen = 0x180000 / sizeof(ptr);
798 #else /* AFS_AMD64_LINUX20_ENV */
799         ptr = (unsigned long *)&interruptible_sleep_on;
800         datalen = 16384;
801 #endif /* AFS_AMD64_LINUX20_ENV */
802 #endif /* EXPORTED_KALLSYMS_ADDRESS */
803         for (offset = 0; offset < datalen; ptr++, offset++) {
804             if (ptr[0] == (unsigned long)&sys_exit
805                 && ptr[__NR_ia32_open - __NR_ia32_exit] ==
806                 (unsigned long)&sys_open) {
807                     ia32_sys_call_table = ptr - __NR_ia32_exit;
808                     break;
809             }
810         }
811 #ifdef EXPORTED_KALLSYMS_ADDRESS
812         ret = kallsyms_address_to_symbol((unsigned long)ia32_sys_call_table,
813                                          &mod_name, &mod_start, &mod_end,
814                                          &sec_name, &sec_start, &sec_end,
815                                          &sym_name, &sym_start, &sym_end);
816         if (ret && strcmp(sym_name, "ia32_sys_call_table"))
817             ia32_sys_call_table = 0;
818 #endif /* EXPORTED_KALLSYMS_ADDRESS */
819 #endif /* EXPORTED_KALLSYMS_SYMBOL */
820         if (!ia32_sys_call_table) {
821             printf("Warning: Failed to find address of ia32_sys_call_table\n");
822         } else {
823             printf("Found ia32_sys_call_table at %lx\n", (unsigned long)ia32_sys_call_table);
824         }
825 #else
826         printf("Found ia32_sys_call_table at %lx\n", (unsigned long)ia32_sys_call_table);
827 #endif /* IA32_SYS_CALL_TABLE */
828 #endif
829
830         /* Initialize pointers to kernel syscalls. */
831 #if !defined(AFS_LINUX24_ENV)
832         sys_settimeofdayp = SYSCALL2POINTER sys_call_table[_S(__NR_settimeofday)];
833 #endif /* AFS_IA64_LINUX20_ENV */
834
835         /* setup AFS entry point. */
836         if (
837 #if defined(AFS_IA64_LINUX20_ENV)
838                 SYSCALL2POINTER sys_call_table[__NR_afs_syscall - 1024]
839 #else
840                 SYSCALL2POINTER sys_call_table[_S(__NR_afs_syscall)]
841 #endif
842                 == afs_syscall) {
843             printf("AFS syscall entry point already in use!\n");
844             return -EBUSY;
845         }
846 #if defined(AFS_IA64_LINUX20_ENV)
847         afs_ni_syscall = sys_call_table[__NR_afs_syscall - 1024];
848         sys_call_table[__NR_afs_syscall - 1024] =
849                 POINTER2SYSCALL((struct fptr *)afs_syscall_stub)->ip;
850 #else /* AFS_IA64_LINUX20_ENV */
851         afs_ni_syscall = sys_call_table[_S(__NR_afs_syscall)];
852         sys_call_table[_S(__NR_afs_syscall)] = POINTER2SYSCALL afs_syscall;
853 #ifdef AFS_SPARC64_LINUX20_ENV
854         afs_ni_syscall32 = sys_call_table32[__NR_afs_syscall];
855         sys_call_table32[__NR_afs_syscall] = POINTER2SYSCALL afs_syscall32;
856 #endif
857 #endif /* AFS_IA64_LINUX20_ENV */
858 #ifdef AFS_AMD64_LINUX20_ENV
859         if (ia32_sys_call_table) {
860             ia32_ni_syscall = ia32_sys_call_table[__NR_ia32_afs_syscall];
861             ia32_sys_call_table[__NR_ia32_afs_syscall] =
862                     POINTER2SYSCALL afs_syscall;
863         }
864 #endif /* AFS_S390_LINUX22_ENV */
865 #ifndef EXPORTED_SYS_CALL_TABLE
866     }
867 #endif /* EXPORTED_SYS_CALL_TABLE */
868     osi_Init();
869     register_filesystem(&afs_fs_type);
870
871     /* Intercept setgroups calls */
872     if (sys_call_table) {
873 #if defined(AFS_IA64_LINUX20_ENV)
874     sys_setgroupsp = (void *)&sys_setgroups;
875
876     ((struct fptr *)sys_setgroupsp)->ip =
877         SYSCALL2POINTER sys_call_table[__NR_setgroups - 1024];
878     ((struct fptr *)sys_setgroupsp)->gp = kernel_gp;
879
880     sys_call_table[__NR_setgroups - 1024] =
881         POINTER2SYSCALL((struct fptr *)afs_xsetgroups_stub)->ip;
882 #else /* AFS_IA64_LINUX20_ENV */
883     sys_setgroupsp = SYSCALL2POINTER sys_call_table[_S(__NR_setgroups)];
884     sys_call_table[_S(__NR_setgroups)] = POINTER2SYSCALL afs_xsetgroups;
885 #ifdef AFS_SPARC64_LINUX20_ENV
886     sys32_setgroupsp = SYSCALL2POINTER sys_call_table32[__NR_setgroups];
887     sys_call_table32[__NR_setgroups] = POINTER2SYSCALL afs32_xsetgroups;
888 #endif /* AFS_SPARC64_LINUX20_ENV */
889 #if defined(__NR_setgroups32)
890     sys_setgroups32p = SYSCALL2POINTER sys_call_table[__NR_setgroups32];
891     sys_call_table[__NR_setgroups32] = POINTER2SYSCALL afs_xsetgroups32;
892 #ifdef AFS_SPARC64_LINUX20_ENV
893         sys32_setgroups32p =
894             SYSCALL2POINTER sys_call_table32[__NR_setgroups32];
895         sys_call_table32[__NR_setgroups32] =
896             POINTER2SYSCALL afs32_xsetgroups32;
897 #endif /* AFS_SPARC64_LINUX20_ENV */
898 #endif /* __NR_setgroups32 */
899 #ifdef AFS_AMD64_LINUX20_ENV
900     if (ia32_sys_call_table) {
901         sys32_setgroupsp =
902             SYSCALL2POINTER ia32_sys_call_table[__NR_ia32_setgroups];
903         ia32_sys_call_table[__NR_ia32_setgroups] =
904             POINTER2SYSCALL afs32_xsetgroups;
905 #if defined(__NR_ia32_setgroups32)
906         sys32_setgroups32p =
907             SYSCALL2POINTER ia32_sys_call_table[__NR_ia32_setgroups32];
908         ia32_sys_call_table[__NR_ia32_setgroups32] =
909             POINTER2SYSCALL afs32_xsetgroups32;
910 #endif /* __NR_ia32_setgroups32 */
911     }
912 #endif /* AFS_AMD64_LINUX20_ENV */
913 #endif /* AFS_IA64_LINUX20_ENV */
914
915     }
916
917     osi_sysctl_init();
918     afsproc_init();
919
920     return 0;
921 }
922
923 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
924 void __exit
925 afs_cleanup(void)
926 #else
927 void
928 cleanup_module(void)
929 #endif
930 {
931     osi_sysctl_clean();
932     if (sys_call_table) {
933 #if defined(AFS_IA64_LINUX20_ENV)
934     sys_call_table[__NR_setgroups - 1024] =
935         POINTER2SYSCALL((struct fptr *)sys_setgroupsp)->ip;
936     sys_call_table[__NR_afs_syscall - 1024] = afs_ni_syscall;
937 #else /* AFS_IA64_LINUX20_ENV */
938     sys_call_table[_S(__NR_setgroups)] = POINTER2SYSCALL sys_setgroupsp;
939     sys_call_table[_S(__NR_afs_syscall)] = afs_ni_syscall;
940 # ifdef AFS_SPARC64_LINUX20_ENV
941     sys_call_table32[__NR_setgroups] = POINTER2SYSCALL sys32_setgroupsp;
942     sys_call_table32[__NR_afs_syscall] = afs_ni_syscall32;
943 # endif
944 # if defined(__NR_setgroups32)
945     sys_call_table[__NR_setgroups32] = POINTER2SYSCALL sys_setgroups32p;
946 # ifdef AFS_SPARC64_LINUX20_ENV
947         sys_call_table32[__NR_setgroups32] =
948             POINTER2SYSCALL sys32_setgroups32p;
949 # endif
950 # endif
951 #endif /* AFS_IA64_LINUX20_ENV */
952 #ifdef AFS_AMD64_LINUX20_ENV
953     if (ia32_sys_call_table) {
954         ia32_sys_call_table[__NR_ia32_setgroups] =
955             POINTER2SYSCALL sys32_setgroupsp;
956         ia32_sys_call_table[__NR_ia32_afs_syscall] =
957             POINTER2SYSCALL ia32_ni_syscall;
958 # if defined(__NR_setgroups32)
959         ia32_sys_call_table[__NR_ia32_setgroups32] =
960             POINTER2SYSCALL sys32_setgroups32p;
961 #endif
962     }
963 #endif
964     }
965     unregister_filesystem(&afs_fs_type);
966
967     osi_linux_free_inode_pages();       /* Invalidate all pages using AFS inodes. */
968     osi_linux_free_afs_memory();
969
970     afsproc_exit();
971     return;
972 }
973
974 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
975 module_init(afs_init);
976 module_exit(afs_cleanup);
977 #endif
978
979
980 #if !defined(AFS_LINUX24_ENV)
981 static long
982 get_page_offset(void)
983 {
984 #if defined(AFS_PPC_LINUX22_ENV) || defined(AFS_SPARC64_LINUX20_ENV) || defined(AFS_SPARC_LINUX20_ENV) || defined(AFS_ALPHA_LINUX20_ENV) || defined(AFS_S390_LINUX22_ENV) || defined(AFS_IA64_LINUX20_ENV) || defined(AFS_PARISC_LINUX24_ENV) || defined(AFS_AMD64_LINUX20_ENV) || defined(AFS_PPC64_LINUX20_ENV)
985     return PAGE_OFFSET;
986 #else
987     struct task_struct *p, *q;
988
989     /* search backward thru the circular list */
990 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
991     read_lock(&tasklist_lock);
992 #endif
993     /* search backward thru the circular list */
994 #ifdef DEFINED_PREV_TASK
995     for (q = current; p = q; q = prev_task(p)) {
996 #else
997     for (p = current; p; p = p->prev_task) {
998 #endif
999         if (p->pid == 1) {
1000 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1001             read_unlock(&tasklist_lock);
1002 #endif
1003             return p->addr_limit.seg;
1004         }
1005     }
1006
1007 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1008     read_unlock(&tasklist_lock);
1009 #endif
1010     return 0;
1011 #endif
1012 }
1013 #endif /* !AFS_LINUX24_ENV */