0486d6e4dab115bec1673c3a79691cd562e022b9
[openafs.git] / src / afs / afs_syscall.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 #include <afsconfig.h>
11 #include "afs/param.h"
12
13 #ifdef IGNORE_SOME_GCC_WARNINGS
14 # pragma GCC diagnostic warning "-Wold-style-definition"
15 # pragma GCC diagnostic warning "-Wstrict-prototypes"
16 #endif
17
18 #include "afs/sysincludes.h"    /* Standard vendor system headers */
19 #include "afsincludes.h"        /* Afs-based standard headers */
20 #include "afs/afs_stats.h"
21 #include "rx/rx_globals.h"
22 #if !defined(UKERNEL) && !defined(AFS_LINUX20_ENV)
23 #include "net/if.h"
24 #ifdef AFS_SGI62_ENV
25 #include "h/hashing.h"
26 #endif
27 #if !defined(AFS_HPUX110_ENV) && !defined(AFS_DARWIN_ENV)
28 #include "netinet/in_var.h"
29 #endif
30 #endif /* !defined(UKERNEL) */
31 #ifdef AFS_LINUX22_ENV
32 #include "h/smp_lock.h"
33 #endif
34
35 #if (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)) || defined(AFS_HPUX_64BIT_ENV) || defined(AFS_SUN57_64BIT_ENV) || (defined(AFS_SGI_ENV) && (_MIPS_SZLONG==64)) || defined(NEED_IOCTL32)
36 static void
37 afs_ioctl32_to_afs_ioctl(const struct afs_ioctl32 *src, struct afs_ioctl *dst)
38 {
39     dst->in = (char *)(unsigned long)src->in;
40     dst->out = (char *)(unsigned long)src->out;
41     dst->in_size = src->in_size;
42     dst->out_size = src->out_size;
43 }
44 #endif
45
46 /*
47  * If you need to change copyin_afs_ioctl(), you may also need to change
48  * copyin_iparam().
49  */
50
51 int
52 #ifdef AFS_DARWIN100_ENV
53 copyin_afs_ioctl(user_addr_t cmarg, struct afs_ioctl *dst)
54 #else
55 copyin_afs_ioctl(caddr_t cmarg, struct afs_ioctl *dst)
56 #endif
57 {
58     int code;
59 #if defined(AFS_DARWIN100_ENV)
60     struct afs_ioctl32 dst32;
61     
62     if (!proc_is64bit(current_proc())) {
63         AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
64         if (!code)
65             afs_ioctl32_to_afs_ioctl(&dst32, dst);
66         return code;
67     }
68 #endif
69 #if defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)
70     struct afs_ioctl32 dst32;
71
72     if (!(IS64U)) {
73         AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
74         if (!code)
75             afs_ioctl32_to_afs_ioctl(&dst32, dst);
76         return code;
77     }
78 #endif /* defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL) */
79
80
81 #if defined(AFS_HPUX_64BIT_ENV)
82     struct afs_ioctl32 dst32;
83
84     if (is_32bit(u.u_procp)) {  /* is_32bit() in proc_iface.h */
85         AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
86         if (!code)
87             afs_ioctl32_to_afs_ioctl(&dst32, dst);
88         return code;
89     }
90 #endif /* defined(AFS_HPUX_64BIT_ENV) */
91
92 #if defined(AFS_SUN57_64BIT_ENV)
93     struct afs_ioctl32 dst32;
94
95     if (get_udatamodel() == DATAMODEL_ILP32) {
96         AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
97         if (!code)
98             afs_ioctl32_to_afs_ioctl(&dst32, dst);
99         return code;
100     }
101 #endif /* defined(AFS_SUN57_64BIT_ENV) */
102
103 #if defined(AFS_SGI_ENV) && (_MIPS_SZLONG==64)
104     struct afs_ioctl32 dst32;
105
106     if (!ABI_IS_64BIT(get_current_abi())) {
107         AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
108         if (!code)
109             afs_ioctl32_to_afs_ioctl(&dst32, dst);
110         return code;
111     }
112 #endif /* defined(AFS_SGI_ENV) && (_MIPS_SZLONG==64) */
113
114 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)
115     struct afs_ioctl32 dst32;
116
117 #ifdef AFS_SPARC64_LINUX26_ENV
118     if (test_thread_flag(TIF_32BIT))
119 #elif defined(AFS_SPARC64_LINUX24_ENV)
120     if (current->thread.flags & SPARC_FLAG_32BIT)
121 #elif defined(AFS_SPARC64_LINUX20_ENV)
122     if (current->tss.flags & SPARC_FLAG_32BIT)
123
124 #elif defined(AFS_AMD64_LINUX26_ENV)
125     if (test_thread_flag(TIF_IA32))
126 #elif defined(AFS_AMD64_LINUX20_ENV)
127     if (current->thread.flags & THREAD_IA32)
128
129 #elif defined(AFS_PPC64_LINUX26_ENV)
130 #if defined(STRUCT_TASK_STRUCT_HAS_THREAD_INFO)
131     if (current->thread_info->flags & _TIF_32BIT) 
132 #else
133     if (task_thread_info(current)->flags & _TIF_32BIT) 
134 #endif      
135 #elif defined(AFS_PPC64_LINUX20_ENV)
136     if (current->thread.flags & PPC_FLAG_32BIT)
137
138 #elif defined(AFS_S390X_LINUX26_ENV)
139     if (test_thread_flag(TIF_31BIT))
140 #elif defined(AFS_S390X_LINUX20_ENV)
141     if (current->thread.flags & S390_FLAG_31BIT)
142
143 #else
144 #error pioctl32 not done for this linux
145 #endif
146     {
147         AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
148         if (!code)
149             afs_ioctl32_to_afs_ioctl(&dst32, dst);
150         return code;
151     }
152 #endif /* defined(AFS_LINUX_64BIT_KERNEL) */
153
154     AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code);
155     return code;
156 }
157
158
159 #ifdef AFS_AIX32_ENV
160
161 #include "sys/lockl.h"
162
163 /*
164  * syscall -    this is the VRMIX system call entry point.
165  *
166  * NOTE:
167  *      THIS SHOULD BE CHANGED TO afs_syscall(), but requires
168  *      all the user-level calls to `syscall' to change.
169  */
170 syscall(syscall, p1, p2, p3, p4, p5, p6)
171 {
172     register rval1 = 0, code;
173     register monster;
174     int retval = 0;
175 #ifndef AFS_AIX41_ENV
176     extern lock_t kernel_lock;
177     monster = lockl(&kernel_lock, LOCK_SHORT);
178 #endif /* !AFS_AIX41_ENV */
179
180     AFS_STATCNT(syscall);
181     setuerror(0);
182     switch (syscall) {
183     case AFSCALL_CALL:
184         rval1 = afs_syscall_call(p1, p2, p3, p4, p5, p6);
185         break;
186
187     case AFSCALL_SETPAG:
188         AFS_GLOCK();
189         rval1 = afs_setpag();
190         AFS_GUNLOCK();
191         break;
192
193     case AFSCALL_PIOCTL:
194         AFS_GLOCK();
195         rval1 = afs_syscall_pioctl(p1, p2, p3, p4);
196         AFS_GUNLOCK();
197         break;
198
199     case AFSCALL_ICREATE:
200         rval1 = afs_syscall_icreate(p1, p2, p3, p4, p5, p6);
201         break;
202
203     case AFSCALL_IOPEN:
204         rval1 = afs_syscall_iopen(p1, p2, p3);
205         break;
206
207     case AFSCALL_IDEC:
208         rval1 = afs_syscall_iincdec(p1, p2, p3, -1);
209         break;
210
211     case AFSCALL_IINC:
212         rval1 = afs_syscall_iincdec(p1, p2, p3, 1);
213         break;
214
215     case AFSCALL_ICL:
216         AFS_GLOCK();
217         code = Afscall_icl(p1, p2, p3, p4, p5, &retval);
218         AFS_GUNLOCK();
219         if (!code)
220             rval1 = retval;
221         if (!rval1)
222             rval1 = code;
223         break;
224
225     default:
226         rval1 = EINVAL;
227         setuerror(EINVAL);
228         break;
229     }
230
231   out:
232 #ifndef AFS_AIX41_ENV
233     if (monster != LOCK_NEST)
234         unlockl(&kernel_lock);
235 #endif /* !AFS_AIX41_ENV */
236     return getuerror()? -1 : rval1;
237 }
238
239 /*
240  * lsetpag -    interface to afs_setpag().
241  */
242 int
243 lsetpag(void)
244 {
245
246     AFS_STATCNT(lsetpag);
247     return syscall(AFSCALL_SETPAG, 0, 0, 0, 0, 0);
248 }
249
250 /*
251  * lpioctl -    interface to pioctl()
252  */
253 int
254 lpioctl(char *path, int cmd, void *cmarg, int follow)
255 {
256
257     AFS_STATCNT(lpioctl);
258     return syscall(AFSCALL_PIOCTL, path, cmd, cmarg, follow);
259 }
260
261 #else /* !AFS_AIX32_ENV       */
262
263 #if defined(AFS_SGI_ENV)
264 struct afsargs {
265     sysarg_t syscall;
266     sysarg_t parm1;
267     sysarg_t parm2;
268     sysarg_t parm3;
269     sysarg_t parm4;
270     sysarg_t parm5;
271 };
272
273
274 int
275 Afs_syscall(struct afsargs *uap, rval_t * rvp)
276 {
277     int error;
278     long retval;
279
280     AFS_STATCNT(afs_syscall);
281     switch (uap->syscall) {
282     case AFSCALL_ICL:
283         retval = 0;
284         AFS_GLOCK();
285         error =
286             Afscall_icl(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
287                         uap->parm5, &retval);
288         AFS_GUNLOCK();
289         rvp->r_val1 = retval;
290         break;
291 #ifdef AFS_SGI_XFS_IOPS_ENV
292     case AFSCALL_IDEC64:
293         error =
294             afs_syscall_idec64(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
295                                uap->parm5);
296         break;
297     case AFSCALL_IINC64:
298         error =
299             afs_syscall_iinc64(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
300                                uap->parm5);
301         break;
302     case AFSCALL_ILISTINODE64:
303         error =
304             afs_syscall_ilistinode64(uap->parm1, uap->parm2, uap->parm3,
305                                      uap->parm4, uap->parm5);
306         break;
307     case AFSCALL_ICREATENAME64:
308         error =
309             afs_syscall_icreatename64(uap->parm1, uap->parm2, uap->parm3,
310                                       uap->parm4, uap->parm5);
311         break;
312 #endif
313 #ifdef AFS_SGI_VNODE_GLUE
314     case AFSCALL_INIT_KERNEL_CONFIG:
315         error = afs_init_kernel_config(uap->parm1);
316         break;
317 #endif
318     default:
319         error =
320             afs_syscall_call(uap->syscall, uap->parm1, uap->parm2, uap->parm3,
321                              uap->parm4, uap->parm5);
322     }
323     return error;
324 }
325
326 #else /* AFS_SGI_ENV */
327
328 struct iparam {
329     iparmtype param1;
330     iparmtype param2;
331     iparmtype param3;
332     iparmtype param4;
333 };
334
335 struct iparam32 {
336     int param1;
337     int param2;
338     int param3;
339     int param4;
340 };
341
342
343 #if defined(AFS_HPUX_64BIT_ENV) || defined(AFS_SUN57_64BIT_ENV) || (defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)) || defined(NEED_IOCTL32)
344 #if SIZEOF_VOID_P == SIZEOF_UNSIGNED_INT
345 # define uintptrsz unsigned int
346 #elif SIZEOF_VOID_P == SIZEOF_UNSIGNED_LONG
347 # define uintptrsz unsigned long
348 #elif SIZEOF_VOID_P == SIZEOF_UNSIGNED_LONG_LONG
349 # define uintptrsz unsigned long long
350 #else
351 # error "Unable to determine casting for pointers"
352 #endif
353 static void
354 iparam32_to_iparam(const struct iparam32 *src, struct iparam *dst)
355 {
356     dst->param1 = (iparmtype)(uintptrsz)src->param1;
357     dst->param2 = (iparmtype)(uintptrsz)src->param2;
358     dst->param3 = (iparmtype)(uintptrsz)src->param3;
359     dst->param4 = (iparmtype)(uintptrsz)src->param4;
360 }
361 #endif
362
363 /*
364  * If you need to change copyin_iparam(), you may also need to change
365  * copyin_afs_ioctl().
366  *
367  * This function is needed only for icreate, meaning, only on platforms
368  * providing the inode fileserver.
369  */
370
371 static int
372 copyin_iparam(caddr_t cmarg, struct iparam *dst)
373 {
374     int code;
375
376 #if defined(AFS_HPUX_64BIT_ENV)
377     struct iparam32 dst32;
378
379     if (is_32bit(u.u_procp)) {  /* is_32bit() in proc_iface.h */
380         AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
381         if (!code)
382             iparam32_to_iparam(&dst32, dst);
383         return code;
384     }
385 #endif /* AFS_HPUX_64BIT_ENV */
386
387 #if defined(AFS_SUN57_64BIT_ENV)
388     struct iparam32 dst32;
389
390     if (get_udatamodel() == DATAMODEL_ILP32) {
391         AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
392         if (!code)
393             iparam32_to_iparam(&dst32, dst);
394         return code;
395     }
396 #endif /* AFS_SUN57_64BIT_ENV */
397
398 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)
399     struct iparam32 dst32;
400
401 #ifdef AFS_SPARC64_LINUX26_ENV
402     if (test_thread_flag(TIF_32BIT))
403 #elif defined(AFS_SPARC64_LINUX24_ENV)
404     if (current->thread.flags & SPARC_FLAG_32BIT)
405 #elif defined(AFS_SPARC64_LINUX20_ENV)
406     if (current->tss.flags & SPARC_FLAG_32BIT)
407
408 #elif defined(AFS_AMD64_LINUX26_ENV)
409     if (test_thread_flag(TIF_IA32))
410 #elif defined(AFS_AMD64_LINUX20_ENV)
411     if (current->thread.flags & THREAD_IA32)
412
413 #elif defined(AFS_PPC64_LINUX26_ENV)
414 #if defined(STRUCT_TASK_STRUCT_HAS_THREAD_INFO)
415     if (current->thread_info->flags & _TIF_32BIT) 
416 #else
417     if (task_thread_info(current)->flags & _TIF_32BIT) 
418 #endif      
419 #elif defined(AFS_PPC64_LINUX20_ENV)
420     if (current->thread.flags & PPC_FLAG_32BIT) 
421
422 #elif defined(AFS_S390X_LINUX26_ENV)
423     if (test_thread_flag(TIF_31BIT))
424 #elif defined(AFS_S390X_LINUX20_ENV)
425     if (current->thread.flags & S390_FLAG_31BIT) 
426
427 #else
428 #error iparam32 not done for this linux platform
429 #endif
430     {
431         AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
432         if (!code)
433             iparam32_to_iparam(&dst32, dst);
434         return code;
435     }
436 #endif /* AFS_LINUX_64BIT_KERNEL */
437
438     AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code);
439     return code;
440 }
441
442 /* Main entry of all afs system calls */
443 #ifdef  AFS_SUN5_ENV
444 extern int afs_sinited;
445
446 /** The 32 bit OS expects the members of this structure to be 32 bit
447  * quantities and the 64 bit OS expects them as 64 bit quanties. Hence
448  * to accomodate both, *long* is used instead of afs_int32
449  */
450
451 # ifdef AFS_SUN57_ENV
452 struct afssysa {
453     long syscall;
454     long parm1;
455     long parm2;
456     long parm3;
457     long parm4;
458     long parm5;
459     long parm6;
460 };
461 # else
462 struct afssysa {
463     afs_int32 syscall;
464     afs_int32 parm1;
465     afs_int32 parm2;
466     afs_int32 parm3;
467     afs_int32 parm4;
468     afs_int32 parm5;
469     afs_int32 parm6;
470 };
471 # endif
472
473 Afs_syscall(register struct afssysa *uap, rval_t * rvp)
474 {
475     int *retval = &rvp->r_val1;
476 #elif defined(AFS_DARWIN100_ENV)
477 struct afssysa {
478     afs_int32 syscall;
479     afs_int32 parm1;
480     afs_int32 parm2;
481     afs_int32 parm3;
482     afs_int32 parm4;
483     afs_int32 parm5;
484     afs_int32 parm6;
485 };
486 struct afssysa64 {
487     afs_int64 parm1;
488     afs_int64 parm2;
489     afs_int64 parm3;
490     afs_int64 parm4;
491     afs_int64 parm5;
492     afs_int64 parm6;
493     afs_int32 syscall;
494 };
495 int
496 afs3_syscall(afs_proc_t *p, void *args, unsigned int *retval)
497 {
498     struct afssysa64 *uap64 = NULL;
499     struct afssysa *uap = NULL;
500 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
501 int
502 afs3_syscall(p, args, retval)
503 # ifdef AFS_FBSD50_ENV
504      struct thread *p;
505 # else
506      afs_proc_t *p;
507 # endif
508      void *args;
509      long *retval;
510 {
511     register struct a {
512         long syscall;
513         long parm1;
514         long parm2;
515         long parm3;
516         long parm4;
517         long parm5;
518         long parm6;
519     } *uap = (struct a *)args;
520 #elif defined(AFS_LINUX20_ENV)
521 struct afssysargs {
522     long syscall;
523     long parm1;
524     long parm2;
525     long parm3;
526     long parm4;
527     long parm5;
528     long parm6;                 /* not actually used - should be removed */
529 };
530 /* Linux system calls only set up for 5 arguments. */
531 asmlinkage long
532 afs_syscall(long syscall, long parm1, long parm2, long parm3, long parm4)
533 {
534     struct afssysargs args, *uap = &args;
535     long linux_ret = 0;
536     long *retval = &linux_ret;
537     long eparm[4];              /* matches AFSCALL_ICL in fstrace.c */
538 # ifdef AFS_SPARC64_LINUX24_ENV
539     afs_int32 eparm32[4];
540 # endif
541     /* eparm is also used by AFSCALL_CALL in afsd.c */
542 #else
543 # if defined(UKERNEL)
544 int
545 Afs_syscall()
546 {
547     register struct a {
548         long syscall;
549         long parm1;
550         long parm2;
551         long parm3;
552         long parm4;
553         long parm5;
554         long parm6;
555     } *uap = (struct a *)get_user_struct()->u_ap;
556 # else /* UKERNEL */
557 int
558 Afs_syscall()
559 {
560     register struct a {
561         long syscall;
562         long parm1;
563         long parm2;
564         long parm3;
565         long parm4;
566         long parm5;
567         long parm6;
568     } *uap = (struct a *)u.u_ap;
569 # endif /* UKERNEL */
570 # if defined(AFS_HPUX_ENV)
571     long *retval = &u.u_rval1;
572 # elif defined(UKERNEL)
573     int *retval = &(get_user_struct()->u_rval1);
574 # else
575     int *retval = &u.u_rval1;
576 # endif
577 #endif
578     register int code = 0;
579
580     AFS_STATCNT(afs_syscall);
581 #ifdef        AFS_SUN5_ENV
582     rvp->r_vals = 0;
583     if (!afs_sinited) {
584         return (ENODEV);
585     }
586 #endif
587 #ifdef AFS_LINUX20_ENV
588     lock_kernel();
589     /* setup uap for use below - pull out the magic decoder ring to know
590      * which syscalls have folded argument lists.
591      */
592     uap->syscall = syscall;
593     uap->parm1 = parm1;
594     uap->parm2 = parm2;
595     uap->parm3 = parm3;
596     if (syscall == AFSCALL_ICL || syscall == AFSCALL_CALL) {
597 #ifdef AFS_SPARC64_LINUX24_ENV
598 /* from arch/sparc64/kernel/sys_sparc32.c */
599 #define AA(__x)                                \
600 ({     unsigned long __ret;            \
601        __asm__ ("srl   %0, 0, %0"      \
602                 : "=r" (__ret)         \
603                 : "0" (__x));          \
604        __ret;                          \
605 })
606
607
608 #ifdef AFS_SPARC64_LINUX26_ENV
609         if (test_thread_flag(TIF_32BIT))
610 #else
611         if (current->thread.flags & SPARC_FLAG_32BIT)
612 #endif
613         {
614             AFS_COPYIN((char *)parm4, (char *)eparm32, sizeof(eparm32), code);
615             eparm[0] = AA(eparm32[0]);
616             eparm[1] = AA(eparm32[1]);
617             eparm[2] = AA(eparm32[2]);
618 #undef AA
619         } else
620 #endif
621             AFS_COPYIN((char *)parm4, (char *)eparm, sizeof(eparm), code);
622         uap->parm4 = eparm[0];
623         uap->parm5 = eparm[1];
624         uap->parm6 = eparm[2];
625     } else {
626         uap->parm4 = parm4;
627         uap->parm5 = 0;
628         uap->parm6 = 0;
629     }
630 #endif
631 #if defined(AFS_DARWIN80_ENV)
632     get_vfs_context();
633     osi_Assert(*retval == 0);
634 #ifdef AFS_DARWIN100_ENV
635     if (proc_is64bit(p)) {
636         uap64 = (struct afssysa64 *)args;
637         if (uap64->syscall == AFSCALL_CALL) {
638             code =
639                 afs_syscall64_call(uap64->parm1, uap64->parm2, uap64->parm3,
640                                    uap64->parm4, uap64->parm5, uap64->parm6);
641             /* pass back the code as syscall retval */
642             if (code < 0) {
643                 *retval = code;
644                 code = 0;
645             }
646         } else if (uap64->syscall == AFSCALL_SETPAG) {
647             AFS_GLOCK();
648             code = afs_setpag(p, args, retval);
649             AFS_GUNLOCK();
650         } else if (uap64->syscall == AFSCALL_PIOCTL) {
651             AFS_GLOCK();
652             code =
653                 afs_syscall64_pioctl(uap64->parm1, (unsigned int)uap64->parm2,
654                                      uap64->parm3, (int)uap64->parm4,
655                                      kauth_cred_get());
656             AFS_GUNLOCK();
657         } else if (uap64->syscall == AFSCALL_ICL) {
658             AFS_GLOCK();
659             code =
660                 Afscall64_icl(uap64->parm1, uap64->parm2, uap64->parm3,
661                             uap64->parm4, uap64->parm5, retval);
662             AFS_GUNLOCK();
663         } else
664             code = EINVAL;
665         if (uap64->syscall != AFSCALL_CALL)
666             put_vfs_context();
667     } else { /* and the default case for 32 bit procs */
668 #endif
669         uap = (struct afssysa *)args;
670 #endif
671 #if defined(AFS_HPUX_ENV)
672     /*
673      * There used to be code here (duplicated from osi_Init()) for
674      * initializing the semaphore used by AFS_GLOCK().  Was the
675      * duplication to handle the case of a dynamically loaded kernel
676      * module?
677      */
678         osi_InitGlock();
679 #endif
680         if (uap->syscall == AFSCALL_CALL) {
681             code =
682                 afs_syscall_call(uap->parm1, uap->parm2, uap->parm3,
683                                  uap->parm4, uap->parm5, uap->parm6);
684 #ifdef AFS_DARWIN_ENV
685             /* pass back the code as syscall retval */
686             if (code < 0) {
687                 *retval = code;
688                 code = 0;
689             }
690 #endif
691         } else if (uap->syscall == AFSCALL_SETPAG) {
692 #ifdef  AFS_SUN5_ENV
693             register proc_t *procp;
694
695             procp = ttoproc(curthread);
696             AFS_GLOCK();
697             code = afs_setpag(&procp->p_cred);
698             AFS_GUNLOCK();
699 #else
700             AFS_GLOCK();
701 #if     defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
702             code = afs_setpag(p, args, retval);
703 #else /* AFS_DARWIN_ENV || AFS_XBSD_ENV */
704             code = afs_setpag();
705 #endif
706             AFS_GUNLOCK();
707 #endif
708         } else if (uap->syscall == AFSCALL_PIOCTL) {
709             AFS_GLOCK();
710 #if defined(AFS_SUN5_ENV)
711             code =
712                 afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3,
713                                    uap->parm4, rvp, CRED());
714 #elif defined(AFS_FBSD50_ENV)
715             code =
716                 afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3,
717                                    uap->parm4, p->td_ucred);
718 #elif defined(AFS_DARWIN80_ENV)
719             code =
720                 afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3,
721                                    uap->parm4, kauth_cred_get());
722 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
723             code =
724                 afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3,
725                                    uap->parm4, p->p_cred->pc_ucred);
726 #else
727             code =
728                 afs_syscall_pioctl((char *)uap->parm1,
729                                    (unsigned int)uap->parm2,
730                                    (caddr_t)uap->parm3,
731                                    (int) uap->parm4);
732 #endif
733             AFS_GUNLOCK();
734         } else if (uap->syscall == AFSCALL_ICREATE) {
735             struct iparam iparams;
736
737             code = copyin_iparam((char *)uap->parm3, &iparams);
738             if (code) {
739 #if defined(KERNEL_HAVE_UERROR)
740                 setuerror(code);
741 #endif
742             } else {
743 #ifdef  AFS_SUN5_ENV
744                 code =
745                     afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1,
746                                         iparams.param2, iparams.param3,
747                                         iparams.param4, rvp, CRED());
748 #else
749                 code =
750                     afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1,
751                                         iparams.param2, iparams.param3,
752                                         iparams.param4
753 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
754                                         , retval
755 #endif
756                         );
757 #endif /* AFS_SUN5_ENV */
758             }
759         } else if (uap->syscall == AFSCALL_IOPEN) {
760 #ifdef  AFS_SUN5_ENV
761             code =
762                 afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, rvp,
763                                   CRED());
764 #else
765             code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3
766 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
767                                      , retval
768 #endif
769                 );
770 #endif /* AFS_SUN5_ENV */
771         } else if (uap->syscall == AFSCALL_IDEC) {
772             code =
773                 afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1
774 #ifdef  AFS_SUN5_ENV
775                                     , rvp, CRED()
776 #endif
777                     );
778         } else if (uap->syscall == AFSCALL_IINC) {
779             code =
780                 afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1
781 #ifdef  AFS_SUN5_ENV
782                                     , rvp, CRED()
783 #endif
784                     );
785         } else if (uap->syscall == AFSCALL_ICL) {
786             AFS_GLOCK();
787             code =
788                 Afscall_icl(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
789                             uap->parm5, (long *)retval);
790             AFS_GUNLOCK();
791 #ifdef AFS_LINUX20_ENV
792             if (!code) {
793                 /* ICL commands can return values. */
794                 code = -linux_ret;      /* Gets negated again at exit below */
795             }
796 #else
797             if (code) {
798 #if defined(KERNEL_HAVE_UERROR)
799                 setuerror(code);
800 #endif
801             }
802 #endif /* !AFS_LINUX20_ENV */
803         } else {
804 #if defined(KERNEL_HAVE_UERROR)
805             setuerror(EINVAL);
806 #else
807             code = EINVAL;
808 #endif
809         }
810 #if defined(AFS_DARWIN80_ENV)
811         if (uap->syscall != AFSCALL_CALL)
812             put_vfs_context();
813 #ifdef AFS_DARWIN100_ENV
814     } /* 32 bit procs */
815 #endif
816 #endif
817 #ifdef AFS_LINUX20_ENV
818     code = -code;
819     unlock_kernel();
820 #endif
821     return code;
822 }
823 #endif /* AFS_SGI_ENV */
824 #endif /* !AFS_AIX32_ENV */