sparc64-linux-20060113
[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 #ifdef AFS_SPARC64_LINUX20_ENV
30 #include <linux/ioctl32.h>
31 #endif
32
33 #include <linux/proc_fs.h>
34 #include <linux/slab.h>
35 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
36 #include <linux/init.h>
37 #include <linux/sched.h>
38 #include <linux/kernel.h>
39 #endif
40
41 #ifdef HAVE_KERNEL_LINUX_SEQ_FILE_H
42 #include <linux/seq_file.h>
43 #endif
44
45 extern struct file_system_type afs_fs_type;
46
47 #if !defined(AFS_LINUX24_ENV)
48 static long get_page_offset(void);
49 #endif
50
51 #if defined(AFS_LINUX24_ENV)
52 DECLARE_MUTEX(afs_global_lock);
53 #else
54 struct semaphore afs_global_lock = MUTEX;
55 #endif
56 int afs_global_owner = 0;
57 #if !defined(AFS_LINUX24_ENV)
58 unsigned long afs_linux_page_offset = 0;        /* contains the PAGE_OFFSET value */
59 #endif
60
61 static inline int afs_ioctl(struct inode *, struct file *, unsigned int,
62                      unsigned long);
63 #if defined(HAVE_UNLOCKED_IOCTL) || defined(HAVE_COMPAT_IOCTL)
64 static long afs_unlocked_ioctl(struct file *, unsigned int, unsigned long);
65 #endif
66
67 static struct file_operations afs_syscall_fops = {
68 #ifdef HAVE_UNLOCKED_IOCTL
69     .unlocked_ioctl = afs_unlocked_ioctl,
70 #else
71     .ioctl = afs_ioctl,
72 #endif
73 #ifdef HAVE_COMPAT_IOCTL
74     .compat_ioctl = afs_unlocked_ioctl,
75 #endif
76 };
77
78 #ifdef HAVE_KERNEL_LINUX_SEQ_FILE_H
79 static void *c_start(struct seq_file *m, loff_t *pos)
80 {
81         struct afs_q *cq, *tq;
82         loff_t n = 0;
83
84         ObtainReadLock(&afs_xcell);
85         for (cq = CellLRU.next; cq != &CellLRU; cq = tq) {
86                 tq = QNext(cq);
87
88                 if (n++ == *pos)
89                         break;
90         }
91         if (cq == &CellLRU)
92                 return NULL;
93
94         return cq;
95 }
96
97 static void *c_next(struct seq_file *m, void *p, loff_t *pos)
98 {
99         struct afs_q *cq = p, *tq;
100
101         (*pos)++;
102         tq = QNext(cq);
103
104         if (tq == &CellLRU)
105                 return NULL;
106
107         return tq;
108 }
109
110 static void c_stop(struct seq_file *m, void *p)
111 {
112         ReleaseReadLock(&afs_xcell);
113 }
114
115 static int c_show(struct seq_file *m, void *p)
116 {
117         struct afs_q *cq = p;
118         struct cell *tc = QTOC(cq);
119         int j;
120
121         seq_printf(m, ">%s #(%d/%d)\n", tc->cellName,
122                    tc->cellNum, tc->cellIndex);
123
124         for (j = 0; j < MAXCELLHOSTS; j++) {
125                 afs_uint32 addr;
126
127                 if (!tc->cellHosts[j]) break;
128
129                 addr = tc->cellHosts[j]->addr->sa_ip;
130                 seq_printf(m, "%u.%u.%u.%u #%u.%u.%u.%u\n",
131                            NIPQUAD(addr), NIPQUAD(addr));
132         }
133
134         return 0;
135 }
136
137 static struct seq_operations afs_csdb_op = {
138         .start          = c_start,
139         .next           = c_next,
140         .stop           = c_stop,
141         .show           = c_show,
142 };
143
144 static int afs_csdb_open(struct inode *inode, struct file *file)
145 {
146         return seq_open(file, &afs_csdb_op);
147 }
148
149 static struct file_operations afs_csdb_operations = {
150         .open           = afs_csdb_open,
151         .read           = seq_read,
152         .llseek         = seq_lseek,
153         .release        = seq_release,
154 };
155
156 #else /* HAVE_KERNEL_LINUX_SEQ_FILE_H */
157
158 int
159 csdbproc_info(char *buffer, char **start, off_t offset, int
160 length)
161 {
162     int len = 0;
163     off_t pos = 0;
164     int cnt;
165     struct afs_q *cq, *tq;
166     struct cell *tc;
167     char tbuffer[16];
168     /* 90 - 64 cellname, 10 for 32 bit num and index, plus
169        decor */
170     char temp[91];
171     afs_uint32 addr;
172     
173     ObtainReadLock(&afs_xcell);
174
175     for (cq = CellLRU.next; cq != &CellLRU; cq = tq) {
176         tc = QTOC(cq); tq = QNext(cq);
177
178         pos += 90;
179
180         if (pos <= offset) {
181             len = 0;
182         } else {
183             sprintf(temp, ">%s #(%d/%d)\n", tc->cellName, 
184                     tc->cellNum, tc->cellIndex);
185             sprintf(buffer + len, "%-89s\n", temp);
186             len += 90;
187             if (pos >= offset+length) {
188                 ReleaseReadLock(&afs_xcell);
189                 goto done;
190             }
191         }
192
193         for (cnt = 0; cnt < MAXCELLHOSTS; cnt++) {
194             if (!tc->cellHosts[cnt]) break;
195             pos += 90;
196             if (pos <= offset) {
197                 len = 0;
198             } else {
199                 addr = ntohl(tc->cellHosts[cnt]->addr->sa_ip);
200                 sprintf(tbuffer, "%d.%d.%d.%d", 
201                         (int)((addr>>24) & 0xff),
202 (int)((addr>>16) & 0xff),
203                         (int)((addr>>8)  & 0xff), (int)( addr & 0xff));
204                 sprintf(temp, "%s #%s\n", tbuffer, tbuffer);
205                 sprintf(buffer + len, "%-89s\n", temp);
206                 len += 90;
207                 if (pos >= offset+length) {
208                     ReleaseReadLock(&afs_xcell);
209                     goto done;
210                 }
211             }
212         }
213     }
214
215     ReleaseReadLock(&afs_xcell);
216     
217 done:
218     *start = buffer + len - (pos - offset);
219     len = pos - offset;
220     if (len > length)
221         len = length;
222     return len;
223 }
224
225 #endif /* HAVE_KERNEL_LINUX_SEQ_FILE_H */
226
227 int
228 peerproc_read(char *buffer, char **start, off_t offset, int count,
229               int *eof, void *data)
230 {
231     int len, i, j;
232     struct rx_peer *sep;
233     
234     len = 0;
235     for (i = 0, j = 0; i < 256; i++) {
236         for (sep = rx_peerHashTable[i]; sep; sep = sep->next, j++) {
237             len += sprintf(buffer + len, "%lx: next=0x%lx, host=0x%x, ", (unsigned long)sep,
238                    (unsigned long)sep->next, sep->host);
239             len += sprintf(buffer + len, "ifMTU=%d, natMTU=%d, maxMTU=%d\n", sep->ifMTU,
240                    sep->natMTU, sep->maxMTU);
241             len += sprintf(buffer + len, "\trtt=%d:%d, timeout(%d:%d), nSent=%d, reSends=%d\n",
242                    sep->rtt, sep->rtt_dev, sep->timeout.sec,
243                    sep->timeout.usec, sep->nSent, sep->reSends);
244             len += sprintf(buffer + len, "\trefCount=%d, port=%d, idleWhen=0x%x\n",
245                    sep->refCount, sep->port, sep->idleWhen);
246             len += sprintf(buffer + len, "\tCongestionQueue (0x%lx:0x%lx), inPacketSkew=0x%x, outPacketSkew=0x%x\n",
247                  (unsigned long)sep->congestionQueue.prev, (unsigned long)sep->congestionQueue.next,
248                  sep->inPacketSkew, sep->outPacketSkew);
249 #ifdef RX_ENABLE_LOCKS
250             len += sprintf(buffer + len, "\tpeer_lock=%d\n", sep->peer_lock);
251 #endif /* RX_ENABLE_LOCKS */
252         }
253     }
254     
255     if (offset >= len) {
256         *start = buffer;
257         *eof = 1;
258         return 0;
259     }
260     *start = buffer + offset;
261     if ((len -= offset) > count)
262         return count;
263     *eof = 1;
264     return len;
265 }
266
267 int
268 rxstatsproc_read(char *buffer, char **start, off_t offset, int count,
269               int *eof, void *data)
270 {
271     int len, i;
272     
273     len = 0;
274     len += sprintf(buffer + len, "packetRequests = %d\n", rx_stats.packetRequests);
275     len += sprintf(buffer + len, "noPackets[%d] = %d\n", RX_PACKET_CLASS_RECEIVE,
276            rx_stats.receivePktAllocFailures);
277     len += sprintf(buffer + len, "noPackets[%d] = %d\n", RX_PACKET_CLASS_SEND,
278            rx_stats.sendPktAllocFailures);
279     len += sprintf(buffer + len, "noPackets[%d] = %d\n", RX_PACKET_CLASS_SPECIAL,
280            rx_stats.specialPktAllocFailures);
281     len += sprintf(buffer + len, "noPackets[%d] = %d\n", RX_PACKET_CLASS_RECV_CBUF,
282            rx_stats.receiveCbufPktAllocFailures);
283     len += sprintf(buffer + len, "noPackets[%d] = %d\n", RX_PACKET_CLASS_SEND_CBUF,
284            rx_stats.sendCbufPktAllocFailures);
285     len += sprintf(buffer + len, "socketGreedy = %d\n", rx_stats.socketGreedy);
286     len += sprintf(buffer + len, "bogusPacketOnRead = %d\n", rx_stats.bogusPacketOnRead);
287     len += sprintf(buffer + len, "bogusHost = %d\n", rx_stats.bogusHost);
288     len += sprintf(buffer + len, "noPacketOnRead = %d\n", rx_stats.noPacketOnRead);
289     len += sprintf(buffer + len, "noPacketBuffersOnRead = %d\n",
290            rx_stats.noPacketBuffersOnRead);
291     len += sprintf(buffer + len, "selects = %d\n", rx_stats.selects);
292     len += sprintf(buffer + len, "sendSelects = %d\n", rx_stats.sendSelects);
293     for (i = 0; i < RX_N_PACKET_TYPES; i++)
294         len += sprintf(buffer + len, "packetsRead[%d] = %d\n", i, rx_stats.packetsRead[i]);
295     len += sprintf(buffer + len, "dataPacketsRead = %d\n", rx_stats.dataPacketsRead);
296     len += sprintf(buffer + len, "ackPacketsRead = %d\n", rx_stats.ackPacketsRead);
297     len += sprintf(buffer + len, "dupPacketsRead = %d\n", rx_stats.dupPacketsRead);
298     len += sprintf(buffer + len, "spuriousPacketsRead = %d\n", rx_stats.spuriousPacketsRead);
299     for (i = 0; i < RX_N_PACKET_TYPES; i++)
300         len += sprintf(buffer + len, "packetsSent[%d] = %d\n", i, rx_stats.packetsSent[i]);
301     len += sprintf(buffer + len, "ackPacketsSent = %d\n", rx_stats.ackPacketsSent);
302     len += sprintf(buffer + len, "pingPacketsSent = %d\n", rx_stats.pingPacketsSent);
303     len += sprintf(buffer + len, "abortPacketsSent = %d\n", rx_stats.abortPacketsSent);
304     len += sprintf(buffer + len, "busyPacketsSent = %d\n", rx_stats.busyPacketsSent);
305     len += sprintf(buffer + len, "dataPacketsSent = %d\n", rx_stats.dataPacketsSent);
306     len += sprintf(buffer + len, "dataPacketsReSent = %d\n", rx_stats.dataPacketsReSent);
307     len += sprintf(buffer + len, "dataPacketsPushed = %d\n", rx_stats.dataPacketsPushed);
308     len += sprintf(buffer + len, "ignoreAckedPacket = %d\n", rx_stats.ignoreAckedPacket);
309     len += sprintf(buffer + len, "totalRtt = %d sec, %d usec\n", rx_stats.totalRtt.sec,
310            rx_stats.totalRtt.usec);
311     len += sprintf(buffer + len, "minRtt = %d sec, %d usec\n", rx_stats.minRtt.sec,
312            rx_stats.minRtt.usec);
313     len += sprintf(buffer + len, "maxRtt = %d sec, %d usec\n", rx_stats.maxRtt.sec,
314            rx_stats.maxRtt.usec);
315     len += sprintf(buffer + len, "nRttSamples = %d\n", rx_stats.nRttSamples);
316     len += sprintf(buffer + len, "nServerConns = %d\n", rx_stats.nServerConns);
317     len += sprintf(buffer + len, "nClientConns = %d\n", rx_stats.nClientConns);
318     len += sprintf(buffer + len, "nPeerStructs = %d\n", rx_stats.nPeerStructs);
319     len += sprintf(buffer + len, "nCallStructs = %d\n", rx_stats.nCallStructs);
320     len += sprintf(buffer + len, "nFreeCallStructs = %d\n", rx_stats.nFreeCallStructs);
321     len += sprintf(buffer + len, "netSendFailures  = %d\n", rx_stats.netSendFailures);
322     len += sprintf(buffer + len, "fatalErrors      = %d\n", rx_stats.fatalErrors);
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 rxproc_read(char *buffer, char **start, off_t offset, int count,
338               int *eof, void *data)
339 {
340     int len, i;
341     
342     len = 0;
343     len += sprintf(buffer + len, "rx_extraQuota = %d\n", rx_extraQuota);
344     len += sprintf(buffer + len, "rx_extraPackets = %d\n", rx_extraPackets);
345     len += sprintf(buffer + len, "rx_stackSize = %d\n", rx_stackSize);
346     len += sprintf(buffer + len, "rx_connDeadTime = %d\n", rx_connDeadTime);
347     len += sprintf(buffer + len, "rx_idleConnectionTime = %d\n", rx_idleConnectionTime);
348     len += sprintf(buffer + len, "rx_idlePeerTime = %d\n", rx_idlePeerTime);
349     len += sprintf(buffer + len, "rx_initSendWindow = %d\n", rx_initSendWindow);
350     len += sprintf(buffer + len, "rxi_nSendFrags = %d\n", rxi_nSendFrags);
351     len += sprintf(buffer + len, "rx_nPackets = %d\n", rx_nPackets);
352     len += sprintf(buffer + len, "rx_nFreePackets = %d\n", rx_nFreePackets);
353     len += sprintf(buffer + len, "rx_socket = 0x%lx\n", (unsigned long)rx_socket);
354     len += sprintf(buffer + len, "rx_Port = %d\n", rx_port);
355     for (i = 0; i < RX_N_PACKET_CLASSES; i++)
356         len += sprintf(buffer + len, "\trx_packetQuota[%d] = %d\n", i, rx_packetQuota[i]);
357
358     len += sprintf(buffer + len, "rx_nextCid = 0x%x\n", rx_nextCid);
359     len += sprintf(buffer + len, "rx_epoch = 0u%u\n", rx_epoch);
360     len += sprintf(buffer + len, "rx_waitingForPackets = %x\n", rx_waitingForPackets);
361     len += sprintf(buffer + len, "rxi_nCalls = %d\n", rxi_nCalls);
362     len += sprintf(buffer + len, "rxi_dataQuota = %d\n", rxi_dataQuota);
363     len += sprintf(buffer + len, "rxi_availProcs = %d\n", rxi_availProcs);
364     len += sprintf(buffer + len, "rxi_totalMin = %d\n", rxi_totalMin);
365     len += sprintf(buffer + len, "rxi_minDeficit = %d\n", rxi_minDeficit);
366
367     len += sprintf(buffer + len, "rxevent_nFree = %d\nrxevent_nPosted = %d\n", rxevent_nFree, rxevent_nPosted);
368     
369     if (offset >= len) {
370         *start = buffer;
371         *eof = 1;
372         return 0;
373     }
374     *start = buffer + offset;
375     if ((len -= offset) > count)
376         return count;
377     *eof = 1;
378     return len;
379 }
380
381 int
382 connproc_read(char *buffer, char **start, off_t offset, int count,
383               int *eof, void *data)
384 {
385     int len, i, j;
386     struct rx_connection *sep;
387     
388     len = 0;
389     for (i = 0, j = 0; i < 256; i++) {
390         for (sep = rx_connHashTable[i]; sep; sep = sep->next, j++) {
391             len += sprintf(buffer + len, "%lx: next=0x%lx, peer=0x%lx, epoch=0x%x, cid=0x%x, ackRate=%d\n",
392                            (unsigned long)sep, (unsigned long)sep->next, (unsigned long)sep->peer,
393                            sep->epoch, sep->cid, sep->ackRate);
394             len += sprintf(buffer + len, "\tcall[%lx=%d, %lx=%d, %lx=%d, %lx=%d]\n", 
395                            (unsigned long)sep->call[0], sep->callNumber[0],
396                            (unsigned long)sep->call[1], sep->callNumber[1],
397                            (unsigned long)sep->call[2], sep->callNumber[2],
398                            (unsigned long)sep->call[3], sep->callNumber[3]);
399             len += sprintf(buffer + len, "\ttimeout=%d, flags=0x%x, type=0x%x, serviceId=%d, service=0x%lx, refCount=%d\n",
400                            sep->timeout, sep->flags, sep->type, 
401                            sep->serviceId, (unsigned long)sep->service, sep->refCount);
402             len += sprintf(buffer + len, "\tserial=%d, lastSerial=%d, secsUntilDead=%d, secsUntilPing=%d, secIndex=%d\n",
403                            sep->serial, sep->lastSerial, sep->secondsUntilDead,
404                            sep->secondsUntilPing, sep->securityIndex);
405             len += sprintf(buffer + len, "\terror=%d, secObject=0x%lx, secData=0x%lx, secHeaderSize=%d, secmaxTrailerSize=%d\n",
406                            sep->error, (unsigned long)sep->securityObject,
407                            (unsigned long)sep->securityData,
408                            sep->securityHeaderSize, sep->securityMaxTrailerSize);
409             len += sprintf(buffer + len, "\tchallEvent=0x%lx, lastSendTime=0x%x, maxSerial=%d, hardDeadTime=%d\n",
410                            (unsigned long)sep->challengeEvent, sep->lastSendTime, 
411                            sep->maxSerial, sep->hardDeadTime);
412             if (sep->flags & RX_CONN_MAKECALL_WAITING)
413                 len += sprintf(buffer + len, "\t***** Conn in RX_CONN_MAKECALL_WAITING state *****\n");
414 #ifdef RX_ENABLE_LOCKS
415             len += sprintf(buffer + len, "\tcall_lock=%d, call_cv=%d, data_lock=%d, refCount=%d\n",
416                            sep->conn_call_lock, sep->conn_call_cv, 
417                            sep->conn_data_lock, sep->refCount);
418 #endif /* RX_ENABLE_LOCKS */
419         }
420     }
421     
422     if (offset >= len) {
423         *start = buffer;
424         *eof = 1;
425         return 0;
426     }
427     *start = buffer + offset;
428     if ((len -= offset) > count)
429         return count;
430     *eof = 1;
431     return len;
432 }
433
434 int
435 servicesproc_read(char *buffer, char **start, off_t offset, int count,
436               int *eof, void *data)
437 {
438     int len, i, j;
439     struct rx_service *sentry;
440     
441     len = 0;
442     for (i = 0, j = 0; i < RX_MAX_SERVICES; i++) {
443         if ((sentry = rx_services[i])) {
444             j++;
445             len += sprintf(buffer + len,
446                            "\t%lx: serviceId=%d, port=%d, serviceName=%s, socket=0x%lx\n",
447                            (unsigned long)sentry, sentry->serviceId, sentry->servicePort,
448                            sentry->serviceName, (unsigned long)sentry->socket);
449             len += sprintf(buffer + len,
450                            "\t\tnSecObj=%d, nReqRunning=%d, maxProcs=%d, minProcs=%d, connDeadTime=%d, idleDeadTime=%d\n",
451                            sentry->nSecurityObjects, sentry->nRequestsRunning,
452                            sentry->maxProcs, sentry->minProcs, 
453                            sentry->connDeadTime, sentry->idleDeadTime);
454         }
455     }
456     
457     if (offset >= len) {
458         *start = buffer;
459         *eof = 1;
460         return 0;
461     }
462     *start = buffer + offset;
463     if ((len -= offset) > count)
464         return count;
465     *eof = 1;
466     return len;
467 }
468
469 int
470 callproc_read(char *buffer, char **start, off_t offset, int count,
471               int *eof, void *data)
472 {
473     int len, i, j, k;
474     struct rx_connection *sep;
475     
476     len = 0;
477     for (i = 0, j = 0; i < 256; i++) {
478         for (sep = rx_connHashTable[i]; sep; sep = sep->next) {
479             for (k = 0; k < RX_MAXCALLS; k++) {
480                 struct rx_call *call = sep->call[k];
481                 if (call) {
482                     j++;
483                     len += sprintf(buffer + len,
484                                    "%lx: conn=0x%lx, qiheader(0x%lx:0x%lx), tq(0x%lx:0x%lx), rq(0x%lx:0x%lx)\n",
485                                    (unsigned long)call, (unsigned long)call->conn,
486                                    (unsigned long)call->queue_item_header.prev,
487                                    (unsigned long)call->queue_item_header.next,
488                                    (unsigned long)call->tq.prev, (unsigned long)call->tq.next,
489                                    (unsigned long)call->rq.prev, (unsigned long)call->rq.next);
490                     len += sprintf(buffer + len, 
491                                    "\t: curvec=%d, curpos=%lx, nLeft=%d, nFree=%d, currPacket=0x%lx, callNumber=0x%lx\n",
492                                    call->curvec, (unsigned long)call->curpos, call->nLeft,
493                                    call->nFree, (unsigned long)call->currentPacket,
494                                    (unsigned long)call->callNumber);
495                     len += sprintf(buffer + len,
496                                    "\t: channel=%d, state=0x%x, mode=0x%x, flags=0x%x, localStatus=0x%x, remStatus=0x%x\n",
497                                    call->channel, call->state, call->mode,
498                                    call->flags, call->localStatus,
499                                    call->remoteStatus);
500                     len += sprintf(buffer + len,
501                                    "\t: error=%d, timeout=0x%x, rnext=0x%x, rprev=0x%x, rwind=0x%x, tfirst=0x%x, tnext=0x%x\n",
502                                    call->error, call->timeout, call->rnext,
503                                    call->rprev, call->rwind, call->tfirst,
504                                    call->tnext);
505                     len += sprintf(buffer + len,
506                                    "\t: twind=%d, resendEvent=0x%lx, timeoutEvent=0x%lx, keepAliveEvent=0x%lx, delayedAckEvent=0x%lx\n",
507                                    call->twind, (unsigned long)call->resendEvent,
508                                    (unsigned long)call->timeoutEvent,
509                                    (unsigned long)call->keepAliveEvent,
510                                    (unsigned long)call->delayedAckEvent);
511                     len += sprintf(buffer + len,
512                                    "\t: lastSendTime=0x%x, lastReceiveTime=0x%x, lastAcked=0x%x, startTime=0x%x, startWait=0x%x\n",
513                                    call->lastSendTime, call->lastReceiveTime,
514                                    call->lastAcked, call->startTime.sec,
515                                    call->startWait);
516                     if (call->flags & RX_CALL_WAIT_PROC)
517                         len += sprintf(buffer + len,
518                                        "\t******** Call in RX_CALL_WAIT_PROC state **********\n");
519                     if (call->flags & RX_CALL_WAIT_WINDOW_ALLOC)
520                         len += sprintf(buffer + len,
521                                        "\t******** Call in RX_CALL_WAIT_WINDOW_ALLOC state **********\n");
522                     if (call->flags & RX_CALL_READER_WAIT)
523                         len += sprintf(buffer + len,
524                                        "\t******** Conn in RX_CALL_READER_WAIT state **********\n");
525                     if (call->flags & RX_CALL_WAIT_PACKETS)
526                         len += sprintf(buffer + len,
527                                        "\t******** Conn in RX_CALL_WAIT_PACKETS state **********\n");
528 #ifdef RX_ENABLE_LOCKS
529                     len += sprintf(buffer + len,
530                                    "\t: lock=0x%x, cv_twind=0x%x, cv_rq=0x%x, refCount= %d\n",
531                                    call->lock, call->cv_twind, call->cv_rq,
532                                    call->refCount);
533 #endif /* RX_ENABLE_LOCKS */
534                     len += sprintf(buffer + len, "\t: MTU=%d\n", call->MTU);
535                 }
536             }
537         }
538     }
539     
540     if (offset >= len) {
541         *start = buffer;
542         *eof = 1;
543         return 0;
544     }
545     *start = buffer + offset;
546     if ((len -= offset) > count)
547         return count;
548     *eof = 1;
549     return len;
550 }
551
552 static struct proc_dir_entry *openafs_procfs;
553 #if defined(NEED_IOCTL32) && !defined(HAVE_COMPAT_IOCTL)
554 static int ioctl32_done;
555 #endif
556
557 #ifdef AFS_LINUX24_ENV
558 static int
559 afsproc_init(void)
560 {
561     struct proc_dir_entry *entry2;
562     struct proc_dir_entry *entry1;
563     struct proc_dir_entry *entry;
564
565     openafs_procfs = proc_mkdir(PROC_FSDIRNAME, proc_root_fs);
566     entry1 = create_proc_entry(PROC_SYSCALL_NAME, 0666, openafs_procfs);
567
568     entry1->proc_fops = &afs_syscall_fops;
569
570     entry1->owner = THIS_MODULE;
571
572 #ifdef HAVE_KERNEL_LINUX_SEQ_FILE_H
573     entry2 = create_proc_entry(PROC_CELLSERVDB_NAME, 0, openafs_procfs);
574     if (entry2)
575         entry2->proc_fops = &afs_csdb_operations;
576 #else
577     entry2 = create_proc_info_entry(PROC_CELLSERVDB_NAME, (S_IFREG|S_IRUGO), openafs_procfs, csdbproc_info);
578 #endif
579
580     entry = create_proc_read_entry(PROC_PEER_NAME, (S_IFREG|S_IRUGO), openafs_procfs, peerproc_read, NULL);
581
582     entry = create_proc_read_entry(PROC_CONN_NAME, (S_IFREG|S_IRUGO), openafs_procfs, connproc_read, NULL);
583
584     entry = create_proc_read_entry(PROC_CALL_NAME, (S_IFREG|S_IRUGO), openafs_procfs, connproc_read, NULL);
585
586     entry = create_proc_read_entry(PROC_RX_NAME, (S_IFREG|S_IRUGO), openafs_procfs, rxproc_read, NULL);
587
588     entry = create_proc_read_entry(PROC_SERVICES_NAME, (S_IFREG|S_IRUGO), openafs_procfs, servicesproc_read, NULL);
589
590     entry = create_proc_read_entry(PROC_RXSTATS_NAME, (S_IFREG|S_IRUGO), openafs_procfs, rxstatsproc_read, NULL);
591 #if defined(NEED_IOCTL32) && !defined(HAVE_COMPAT_IOCTL)
592     if (register_ioctl32_conversion(VIOC_SYSCALL32, NULL) == 0) 
593             ioctl32_done = 1;
594 #endif
595
596     return 0;
597 }
598
599 static void
600 afsproc_exit(void)
601 {
602     remove_proc_entry(PROC_RXSTATS_NAME, openafs_procfs);
603     remove_proc_entry(PROC_SERVICES_NAME, openafs_procfs);
604     remove_proc_entry(PROC_RX_NAME, openafs_procfs);
605     remove_proc_entry(PROC_CALL_NAME, openafs_procfs);
606     remove_proc_entry(PROC_CONN_NAME, openafs_procfs);
607     remove_proc_entry(PROC_PEER_NAME, openafs_procfs);
608     remove_proc_entry(PROC_CELLSERVDB_NAME, openafs_procfs);
609     remove_proc_entry(PROC_SYSCALL_NAME, openafs_procfs);
610     remove_proc_entry(PROC_FSDIRNAME, proc_root_fs);
611 #if defined(NEED_IOCTL32) && !defined(HAVE_COMPAT_IOCTL)
612     if (ioctl32_done)
613             unregister_ioctl32_conversion(VIOC_SYSCALL32);
614 #endif
615 }
616 #endif
617
618 extern asmlinkage long
619 afs_syscall(long syscall, long parm1, long parm2, long parm3, long parm4);
620
621 static int
622 afs_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
623           unsigned long arg)
624 {
625
626     struct afsprocdata sysargs;
627 #ifdef NEED_IOCTL32
628     struct afsprocdata32 sysargs32;
629 #endif
630
631     if (cmd != VIOC_SYSCALL && cmd != VIOC_SYSCALL32) return -EINVAL;
632
633 #ifdef NEED_IOCTL32
634 #ifdef AFS_LINUX26_ENV 
635 #ifdef AFS_S390X_LINUX26_ENV
636     if (test_thread_flag(TIF_31BIT))
637 #else
638     if (test_thread_flag(TIF_32BIT))
639 #endif /* AFS_S390X_LINUX26_ENV */
640 #else
641 #ifdef AFS_SPARC64_LINUX24_ENV
642     if (current->thread.flags & SPARC_FLAG_32BIT)
643 #elif defined(AFS_SPARC64_LINUX20_ENV)
644     if (current->tss.flags & SPARC_FLAG_32BIT)
645 #elif defined(AFS_AMD64_LINUX20_ENV)
646     if (current->thread.flags & THREAD_IA32)
647 #elif defined(AFS_PPC64_LINUX20_ENV)
648     if (current->thread.flags & PPC_FLAG_32BIT)
649 #elif defined(AFS_S390X_LINUX20_ENV)
650     if (current->thread.flags & S390_FLAG_31BIT)
651 #else
652 #error Not done for this linux type
653 #endif /* AFS_LINUX26_ENV */
654 #endif /* NEED_IOCTL32 */
655     {
656         if (copy_from_user(&sysargs32, (void *)arg,
657                            sizeof(struct afsprocdata32)))
658             return -EFAULT;
659
660         return afs_syscall((unsigned long)sysargs32.syscall,
661                            (unsigned long)sysargs32.param1,
662                            (unsigned long)sysargs32.param2,
663                            (unsigned long)sysargs32.param3,
664                            (unsigned long)sysargs32.param4);
665     } else
666 #endif
667     {
668         if (copy_from_user(&sysargs, (void *)arg, sizeof(struct afsprocdata)))
669             return -EFAULT;
670
671         return afs_syscall(sysargs.syscall, sysargs.param1,
672                            sysargs.param2, sysargs.param3, sysargs.param4);
673     }
674 }
675
676 #if defined(HAVE_UNLOCKED_IOCTL) || defined(HAVE_COMPAT_IOCTL)
677 static long afs_unlocked_ioctl(struct file *file, unsigned int cmd,
678                                unsigned long arg) {
679     return afs_ioctl(FILE_INODE(file), file, cmd, arg);
680 }
681 #endif
682
683 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
684 int __init
685 afs_init(void)
686 #else
687 int
688 init_module(void)
689 #endif
690 {
691     int err;
692     RWLOCK_INIT(&afs_xosi, "afs_xosi");
693
694 #if !defined(AFS_LINUX24_ENV)
695     /* obtain PAGE_OFFSET value */
696     afs_linux_page_offset = get_page_offset();
697
698 #ifndef AFS_S390_LINUX22_ENV
699     if (afs_linux_page_offset == 0) {
700         /* couldn't obtain page offset so can't continue */
701         printf("afs: Unable to obtain PAGE_OFFSET. Exiting..");
702         return -EIO;
703     }
704 #endif /* AFS_S390_LINUX22_ENV */
705 #endif /* !defined(AFS_LINUX24_ENV) */
706
707     osi_Init();
708
709     err = osi_syscall_init();
710     if (err)
711         return err;
712     err = afs_init_inodecache();
713     if (err)
714         return err;
715     register_filesystem(&afs_fs_type);
716     osi_sysctl_init();
717 #ifdef AFS_LINUX24_ENV
718     afsproc_init();
719 #endif
720
721     return 0;
722 }
723
724 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
725 void __exit
726 afs_cleanup(void)
727 #else
728 void
729 cleanup_module(void)
730 #endif
731 {
732     osi_sysctl_clean();
733     osi_syscall_clean();
734     unregister_filesystem(&afs_fs_type);
735
736     afs_destroy_inodecache();
737     osi_linux_free_afs_memory();
738
739 #ifdef AFS_LINUX24_ENV
740     afsproc_exit();
741 #endif
742     return;
743 }
744
745 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
746 MODULE_LICENSE("http://www.openafs.org/dl/license10.html");
747 module_init(afs_init);
748 module_exit(afs_cleanup);
749 #endif
750
751
752 #if !defined(AFS_LINUX24_ENV)
753 static long
754 get_page_offset(void)
755 {
756 #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)
757     return PAGE_OFFSET;
758 #else
759     struct task_struct *p, *q;
760
761     /* search backward thru the circular list */
762 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
763     read_lock(&tasklist_lock);
764 #endif
765     /* search backward thru the circular list */
766 #ifdef DEFINED_PREV_TASK
767     for (q = current; p = q; q = prev_task(p)) {
768 #else
769     for (p = current; p; p = p->prev_task) {
770 #endif
771         if (p->pid == 1) {
772 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
773             read_unlock(&tasklist_lock);
774 #endif
775             return p->addr_limit.seg;
776         }
777     }
778
779 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
780     read_unlock(&tasklist_lock);
781 #endif
782     return 0;
783 #endif
784 }
785 #endif /* !AFS_LINUX24_ENV */