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