c83e71e6c1e68ffbdcda984258cf8b27be06dfe3
[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_DARWIN60_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 static void
345 iparam32_to_iparam(const struct iparam32 *src, struct iparam *dst)
346 {
347     dst->param1 = (iparmtype)(uintptr_t)src->param1;
348     dst->param2 = (iparmtype)(uintptr_t)src->param2;
349     dst->param3 = (iparmtype)(uintptr_t)src->param3;
350     dst->param4 = (iparmtype)(uintptr_t)src->param4;
351 }
352 #endif
353
354 /*
355  * If you need to change copyin_iparam(), you may also need to change
356  * copyin_afs_ioctl().
357  *
358  * This function is needed only for icreate, meaning, only on platforms
359  * providing the inode fileserver.
360  */
361
362 static int
363 copyin_iparam(caddr_t cmarg, struct iparam *dst)
364 {
365     int code;
366
367 #if defined(AFS_HPUX_64BIT_ENV)
368     struct iparam32 dst32;
369
370     if (is_32bit(u.u_procp)) {  /* is_32bit() in proc_iface.h */
371         AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
372         if (!code)
373             iparam32_to_iparam(&dst32, dst);
374         return code;
375     }
376 #endif /* AFS_HPUX_64BIT_ENV */
377
378 #if defined(AFS_SUN57_64BIT_ENV)
379     struct iparam32 dst32;
380
381     if (get_udatamodel() == DATAMODEL_ILP32) {
382         AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
383         if (!code)
384             iparam32_to_iparam(&dst32, dst);
385         return code;
386     }
387 #endif /* AFS_SUN57_64BIT_ENV */
388
389 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)
390     struct iparam32 dst32;
391
392 #ifdef AFS_SPARC64_LINUX26_ENV
393     if (test_thread_flag(TIF_32BIT))
394 #elif defined(AFS_SPARC64_LINUX24_ENV)
395     if (current->thread.flags & SPARC_FLAG_32BIT)
396 #elif defined(AFS_SPARC64_LINUX20_ENV)
397     if (current->tss.flags & SPARC_FLAG_32BIT)
398
399 #elif defined(AFS_AMD64_LINUX26_ENV)
400     if (test_thread_flag(TIF_IA32))
401 #elif defined(AFS_AMD64_LINUX20_ENV)
402     if (current->thread.flags & THREAD_IA32)
403
404 #elif defined(AFS_PPC64_LINUX26_ENV)
405 #if defined(STRUCT_TASK_STRUCT_HAS_THREAD_INFO)
406     if (current->thread_info->flags & _TIF_32BIT) 
407 #else
408     if (task_thread_info(current)->flags & _TIF_32BIT) 
409 #endif      
410 #elif defined(AFS_PPC64_LINUX20_ENV)
411     if (current->thread.flags & PPC_FLAG_32BIT) 
412
413 #elif defined(AFS_S390X_LINUX26_ENV)
414     if (test_thread_flag(TIF_31BIT))
415 #elif defined(AFS_S390X_LINUX20_ENV)
416     if (current->thread.flags & S390_FLAG_31BIT) 
417
418 #else
419 #error iparam32 not done for this linux platform
420 #endif
421     {
422         AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
423         if (!code)
424             iparam32_to_iparam(&dst32, dst);
425         return code;
426     }
427 #endif /* AFS_LINUX_64BIT_KERNEL */
428
429     AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code);
430     return code;
431 }
432
433 /* Main entry of all afs system calls */
434 #ifdef  AFS_SUN5_ENV
435 extern int afs_sinited;
436
437 /** The 32 bit OS expects the members of this structure to be 32 bit
438  * quantities and the 64 bit OS expects them as 64 bit quanties. Hence
439  * to accomodate both, *long* is used instead of afs_int32
440  */
441
442 # ifdef AFS_SUN57_ENV
443 struct afssysa {
444     long syscall;
445     long parm1;
446     long parm2;
447     long parm3;
448     long parm4;
449     long parm5;
450     long parm6;
451 };
452 # else
453 struct afssysa {
454     afs_int32 syscall;
455     afs_int32 parm1;
456     afs_int32 parm2;
457     afs_int32 parm3;
458     afs_int32 parm4;
459     afs_int32 parm5;
460     afs_int32 parm6;
461 };
462 # endif
463
464 Afs_syscall(register struct afssysa *uap, rval_t * rvp)
465 {
466     int *retval = &rvp->r_val1;
467 #elif defined(AFS_DARWIN100_ENV)
468 struct afssysa {
469     afs_int32 syscall;
470     afs_int32 parm1;
471     afs_int32 parm2;
472     afs_int32 parm3;
473     afs_int32 parm4;
474     afs_int32 parm5;
475     afs_int32 parm6;
476 };
477 struct afssysa64 {
478     afs_int64 parm1;
479     afs_int64 parm2;
480     afs_int64 parm3;
481     afs_int64 parm4;
482     afs_int64 parm5;
483     afs_int64 parm6;
484     afs_int32 syscall;
485 };
486 int
487 afs3_syscall(afs_proc_t *p, void *args, unsigned int *retval)
488 {
489     struct afssysa64 *uap64 = NULL;
490     struct afssysa *uap = NULL;
491 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
492 int
493 afs3_syscall(p, args, retval)
494 # ifdef AFS_FBSD50_ENV
495      struct thread *p;
496 # else
497      afs_proc_t *p;
498 # endif
499      void *args;
500      long *retval;
501 {
502     register struct a {
503         long syscall;
504         long parm1;
505         long parm2;
506         long parm3;
507         long parm4;
508         long parm5;
509         long parm6;
510     } *uap = (struct a *)args;
511 #elif defined(AFS_LINUX20_ENV)
512 struct afssysargs {
513     long syscall;
514     long parm1;
515     long parm2;
516     long parm3;
517     long parm4;
518     long parm5;
519     long parm6;                 /* not actually used - should be removed */
520 };
521 /* Linux system calls only set up for 5 arguments. */
522 asmlinkage long
523 afs_syscall(long syscall, long parm1, long parm2, long parm3, long parm4)
524 {
525     struct afssysargs args, *uap = &args;
526     long linux_ret = 0;
527     long *retval = &linux_ret;
528     long eparm[4];              /* matches AFSCALL_ICL in fstrace.c */
529 # ifdef AFS_SPARC64_LINUX24_ENV
530     afs_int32 eparm32[4];
531 # endif
532     /* eparm is also used by AFSCALL_CALL in afsd.c */
533 #else
534 # if defined(UKERNEL)
535 int
536 Afs_syscall()
537 {
538     register struct a {
539         long syscall;
540         long parm1;
541         long parm2;
542         long parm3;
543         long parm4;
544         long parm5;
545         long parm6;
546     } *uap = (struct a *)u.u_ap;
547 # else /* UKERNEL */
548 int
549 Afs_syscall()
550 {
551     register struct a {
552         long syscall;
553         long parm1;
554         long parm2;
555         long parm3;
556         long parm4;
557         long parm5;
558         long parm6;
559     } *uap = (struct a *)u.u_ap;
560 # endif /* UKERNEL */
561 # if defined(AFS_HPUX_ENV)
562     long *retval = &u.u_rval1;
563 # else
564     int *retval = &u.u_rval1;
565 # endif
566 #endif
567     register int code = 0;
568
569     AFS_STATCNT(afs_syscall);
570 #ifdef        AFS_SUN5_ENV
571     rvp->r_vals = 0;
572     if (!afs_sinited) {
573         return (ENODEV);
574     }
575 #endif
576 #ifdef AFS_LINUX20_ENV
577     lock_kernel();
578     /* setup uap for use below - pull out the magic decoder ring to know
579      * which syscalls have folded argument lists.
580      */
581     uap->syscall = syscall;
582     uap->parm1 = parm1;
583     uap->parm2 = parm2;
584     uap->parm3 = parm3;
585     if (syscall == AFSCALL_ICL || syscall == AFSCALL_CALL) {
586 #ifdef AFS_SPARC64_LINUX24_ENV
587 /* from arch/sparc64/kernel/sys_sparc32.c */
588 #define AA(__x)                                \
589 ({     unsigned long __ret;            \
590        __asm__ ("srl   %0, 0, %0"      \
591                 : "=r" (__ret)         \
592                 : "0" (__x));          \
593        __ret;                          \
594 })
595
596
597 #ifdef AFS_SPARC64_LINUX26_ENV
598         if (test_thread_flag(TIF_32BIT))
599 #else
600         if (current->thread.flags & SPARC_FLAG_32BIT)
601 #endif
602         {
603             AFS_COPYIN((char *)parm4, (char *)eparm32, sizeof(eparm32), code);
604             eparm[0] = AA(eparm32[0]);
605             eparm[1] = AA(eparm32[1]);
606             eparm[2] = AA(eparm32[2]);
607 #undef AA
608         } else
609 #endif
610             AFS_COPYIN((char *)parm4, (char *)eparm, sizeof(eparm), code);
611         uap->parm4 = eparm[0];
612         uap->parm5 = eparm[1];
613         uap->parm6 = eparm[2];
614     } else {
615         uap->parm4 = parm4;
616         uap->parm5 = 0;
617         uap->parm6 = 0;
618     }
619 #endif
620 #if defined(AFS_DARWIN80_ENV)
621     get_vfs_context();
622     osi_Assert(*retval == 0);
623 #ifdef AFS_DARWIN100_ENV
624     if (proc_is64bit(p)) {
625         uap64 = (struct afssysa64 *)args;
626         if (uap64->syscall == AFSCALL_CALL) {
627             code =
628                 afs_syscall64_call(uap64->parm1, uap64->parm2, uap64->parm3,
629                                    uap64->parm4, uap64->parm5, uap64->parm6);
630         } else if (uap64->syscall == AFSCALL_SETPAG) {
631             AFS_GLOCK();
632             code = afs_setpag(p, args, retval);
633             AFS_GUNLOCK();
634         } else if (uap64->syscall == AFSCALL_PIOCTL) {
635             AFS_GLOCK();
636             code =
637                 afs_syscall64_pioctl(uap64->parm1, (unsigned int)uap64->parm2,
638                                      uap64->parm3, (int)uap64->parm4,
639                                      kauth_cred_get());
640             AFS_GUNLOCK();
641         } else if (uap64->syscall == AFSCALL_ICL) {
642             AFS_GLOCK();
643             code =
644                 Afscall64_icl(uap64->parm1, uap64->parm2, uap64->parm3,
645                             uap64->parm4, uap64->parm5, retval);
646             AFS_GUNLOCK();
647         } else
648             code = EINVAL;
649         if (uap64->syscall != AFSCALL_CALL)
650             put_vfs_context();
651     } else { /* and the default case for 32 bit procs */
652 #endif
653         uap = (struct afssysa *)args;
654 #endif
655 #if defined(AFS_HPUX_ENV)
656     /*
657      * There used to be code here (duplicated from osi_Init()) for
658      * initializing the semaphore used by AFS_GLOCK().  Was the
659      * duplication to handle the case of a dynamically loaded kernel
660      * module?
661      */
662         osi_InitGlock();
663 #endif
664         if (uap->syscall == AFSCALL_CALL) {
665             code =
666                 afs_syscall_call(uap->parm1, uap->parm2, uap->parm3,
667                                  uap->parm4, uap->parm5, uap->parm6);
668         } else if (uap->syscall == AFSCALL_SETPAG) {
669 #ifdef  AFS_SUN5_ENV
670             register proc_t *procp;
671
672             procp = ttoproc(curthread);
673             AFS_GLOCK();
674             code = afs_setpag(&procp->p_cred);
675             AFS_GUNLOCK();
676 #else
677             AFS_GLOCK();
678 #if     defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
679             code = afs_setpag(p, args, retval);
680 #else /* AFS_DARWIN_ENV || AFS_XBSD_ENV */
681             code = afs_setpag();
682 #endif
683             AFS_GUNLOCK();
684 #endif
685         } else if (uap->syscall == AFSCALL_PIOCTL) {
686             AFS_GLOCK();
687 #if defined(AFS_SUN5_ENV)
688             code =
689                 afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3,
690                                    uap->parm4, rvp, CRED());
691 #elif defined(AFS_FBSD50_ENV)
692             code =
693                 afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3,
694                                    uap->parm4, p->td_ucred);
695 #elif defined(AFS_DARWIN80_ENV)
696             code =
697                 afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3,
698                                    uap->parm4, kauth_cred_get());
699 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
700             code =
701                 afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3,
702                                    uap->parm4, p->p_cred->pc_ucred);
703 #else
704             code =
705                 afs_syscall_pioctl((char *)uap->parm1,
706                                    (unsigned int)uap->parm2,
707                                    (caddr_t)uap->parm3,
708                                    (int) uap->parm4);
709 #endif
710             AFS_GUNLOCK();
711         } else if (uap->syscall == AFSCALL_ICREATE) {
712             struct iparam iparams;
713
714             code = copyin_iparam((char *)uap->parm3, &iparams);
715             if (code) {
716 #if defined(KERNEL_HAVE_UERROR)
717                 setuerror(code);
718 #endif
719             } else {
720 #ifdef  AFS_SUN5_ENV
721                 code =
722                     afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1,
723                                         iparams.param2, iparams.param3,
724                                         iparams.param4, rvp, CRED());
725 #else
726                 code =
727                     afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1,
728                                         iparams.param2, iparams.param3,
729                                         iparams.param4
730 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
731                                         , retval
732 #endif
733                         );
734 #endif /* AFS_SUN5_ENV */
735             }
736         } else if (uap->syscall == AFSCALL_IOPEN) {
737 #ifdef  AFS_SUN5_ENV
738             code =
739                 afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, rvp,
740                                   CRED());
741 #else
742             code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3
743 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
744                                      , retval
745 #endif
746                 );
747 #endif /* AFS_SUN5_ENV */
748         } else if (uap->syscall == AFSCALL_IDEC) {
749             code =
750                 afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1
751 #ifdef  AFS_SUN5_ENV
752                                     , rvp, CRED()
753 #endif
754                     );
755         } else if (uap->syscall == AFSCALL_IINC) {
756             code =
757                 afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1
758 #ifdef  AFS_SUN5_ENV
759                                     , rvp, CRED()
760 #endif
761                     );
762         } else if (uap->syscall == AFSCALL_ICL) {
763             AFS_GLOCK();
764             code =
765                 Afscall_icl(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
766                             uap->parm5, (long *)retval);
767             AFS_GUNLOCK();
768 #ifdef AFS_LINUX20_ENV
769             if (!code) {
770                 /* ICL commands can return values. */
771                 code = -linux_ret;      /* Gets negated again at exit below */
772             }
773 #else
774             if (code) {
775 #if defined(KERNEL_HAVE_UERROR)
776                 setuerror(code);
777 #endif
778             }
779 #endif /* !AFS_LINUX20_ENV */
780         } else {
781 #if defined(KERNEL_HAVE_UERROR)
782             setuerror(EINVAL);
783 #else
784             code = EINVAL;
785 #endif
786         }
787 #if defined(AFS_DARWIN80_ENV)
788         if (uap->syscall != AFSCALL_CALL)
789             put_vfs_context();
790 #ifdef AFS_DARWIN100_ENV
791     } /* 32 bit procs */
792 #endif
793 #endif
794 #ifdef AFS_LINUX20_ENV
795     code = -code;
796     unlock_kernel();
797 #endif
798     return code;
799 }
800 #endif /* AFS_SGI_ENV */
801 #endif /* !AFS_AIX32_ENV */