2 * Copyright 2000, International Business Machines Corporation and others.
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
10 #include <afsconfig.h>
11 #include "afs/param.h"
13 #ifdef IGNORE_SOME_GCC_WARNINGS
14 # pragma GCC diagnostic warning "-Wold-style-definition"
15 # pragma GCC diagnostic warning "-Wstrict-prototypes"
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)
25 #include "h/hashing.h"
27 #if !defined(AFS_HPUX110_ENV) && !defined(AFS_DARWIN60_ENV)
28 #include "netinet/in_var.h"
30 #endif /* !defined(UKERNEL) */
31 #ifdef AFS_LINUX22_ENV
32 #include "h/smp_lock.h"
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)
37 afs_ioctl32_to_afs_ioctl(const struct afs_ioctl32 *src, struct afs_ioctl *dst)
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;
47 * If you need to change copyin_afs_ioctl(), you may also need to change
52 #ifdef AFS_DARWIN100_ENV
53 copyin_afs_ioctl(user_addr_t cmarg, struct afs_ioctl *dst)
55 copyin_afs_ioctl(caddr_t cmarg, struct afs_ioctl *dst)
59 #if defined(AFS_DARWIN100_ENV)
60 struct afs_ioctl32 dst32;
62 if (!proc_is64bit(current_proc())) {
63 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
65 afs_ioctl32_to_afs_ioctl(&dst32, dst);
69 #if defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)
70 struct afs_ioctl32 dst32;
73 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
75 afs_ioctl32_to_afs_ioctl(&dst32, dst);
78 #endif /* defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL) */
81 #if defined(AFS_HPUX_64BIT_ENV)
82 struct afs_ioctl32 dst32;
84 if (is_32bit(u.u_procp)) { /* is_32bit() in proc_iface.h */
85 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
87 afs_ioctl32_to_afs_ioctl(&dst32, dst);
90 #endif /* defined(AFS_HPUX_64BIT_ENV) */
92 #if defined(AFS_SUN57_64BIT_ENV)
93 struct afs_ioctl32 dst32;
95 if (get_udatamodel() == DATAMODEL_ILP32) {
96 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
98 afs_ioctl32_to_afs_ioctl(&dst32, dst);
101 #endif /* defined(AFS_SUN57_64BIT_ENV) */
103 #if defined(AFS_SGI_ENV) && (_MIPS_SZLONG==64)
104 struct afs_ioctl32 dst32;
106 if (!ABI_IS_64BIT(get_current_abi())) {
107 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
109 afs_ioctl32_to_afs_ioctl(&dst32, dst);
112 #endif /* defined(AFS_SGI_ENV) && (_MIPS_SZLONG==64) */
114 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)
115 struct afs_ioctl32 dst32;
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)
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)
129 #elif defined(AFS_PPC64_LINUX26_ENV)
130 #if defined(STRUCT_TASK_STRUCT_HAS_THREAD_INFO)
131 if (current->thread_info->flags & _TIF_32BIT)
133 if (task_thread_info(current)->flags & _TIF_32BIT)
135 #elif defined(AFS_PPC64_LINUX20_ENV)
136 if (current->thread.flags & PPC_FLAG_32BIT)
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)
144 #error pioctl32 not done for this linux
147 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
149 afs_ioctl32_to_afs_ioctl(&dst32, dst);
152 #endif /* defined(AFS_LINUX_64BIT_KERNEL) */
154 AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code);
161 #include "sys/lockl.h"
164 * syscall - this is the VRMIX system call entry point.
167 * THIS SHOULD BE CHANGED TO afs_syscall(), but requires
168 * all the user-level calls to `syscall' to change.
170 syscall(syscall, p1, p2, p3, p4, p5, p6)
172 register rval1 = 0, code;
175 #ifndef AFS_AIX41_ENV
176 extern lock_t kernel_lock;
177 monster = lockl(&kernel_lock, LOCK_SHORT);
178 #endif /* !AFS_AIX41_ENV */
180 AFS_STATCNT(syscall);
184 rval1 = afs_syscall_call(p1, p2, p3, p4, p5, p6);
189 rval1 = afs_setpag();
195 rval1 = afs_syscall_pioctl(p1, p2, p3, p4);
199 case AFSCALL_ICREATE:
200 rval1 = afs_syscall_icreate(p1, p2, p3, p4, p5, p6);
204 rval1 = afs_syscall_iopen(p1, p2, p3);
208 rval1 = afs_syscall_iincdec(p1, p2, p3, -1);
212 rval1 = afs_syscall_iincdec(p1, p2, p3, 1);
217 code = Afscall_icl(p1, p2, p3, p4, p5, &retval);
232 #ifndef AFS_AIX41_ENV
233 if (monster != LOCK_NEST)
234 unlockl(&kernel_lock);
235 #endif /* !AFS_AIX41_ENV */
236 return getuerror()? -1 : rval1;
240 * lsetpag - interface to afs_setpag().
246 AFS_STATCNT(lsetpag);
247 return syscall(AFSCALL_SETPAG, 0, 0, 0, 0, 0);
251 * lpioctl - interface to pioctl()
254 lpioctl(char *path, int cmd, void *cmarg, int follow)
257 AFS_STATCNT(lpioctl);
258 return syscall(AFSCALL_PIOCTL, path, cmd, cmarg, follow);
261 #else /* !AFS_AIX32_ENV */
263 #if defined(AFS_SGI_ENV)
275 Afs_syscall(struct afsargs *uap, rval_t * rvp)
280 AFS_STATCNT(afs_syscall);
281 switch (uap->syscall) {
286 Afscall_icl(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
287 uap->parm5, &retval);
289 rvp->r_val1 = retval;
291 #ifdef AFS_SGI_XFS_IOPS_ENV
294 afs_syscall_idec64(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
299 afs_syscall_iinc64(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
302 case AFSCALL_ILISTINODE64:
304 afs_syscall_ilistinode64(uap->parm1, uap->parm2, uap->parm3,
305 uap->parm4, uap->parm5);
307 case AFSCALL_ICREATENAME64:
309 afs_syscall_icreatename64(uap->parm1, uap->parm2, uap->parm3,
310 uap->parm4, uap->parm5);
313 #ifdef AFS_SGI_VNODE_GLUE
314 case AFSCALL_INIT_KERNEL_CONFIG:
315 error = afs_init_kernel_config(uap->parm1);
320 afs_syscall_call(uap->syscall, uap->parm1, uap->parm2, uap->parm3,
321 uap->parm4, uap->parm5);
326 #else /* AFS_SGI_ENV */
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)
345 iparam32_to_iparam(const struct iparam32 *src, struct iparam *dst)
347 dst->param1 = src->param1;
348 dst->param2 = src->param2;
349 dst->param3 = src->param3;
350 dst->param4 = src->param4;
355 * If you need to change copyin_iparam(), you may also need to change
356 * copyin_afs_ioctl().
358 * This function is needed only for icreate, meaning, only on platforms
359 * providing the inode fileserver.
363 copyin_iparam(caddr_t cmarg, struct iparam *dst)
367 #if defined(AFS_HPUX_64BIT_ENV)
368 struct iparam32 dst32;
370 if (is_32bit(u.u_procp)) { /* is_32bit() in proc_iface.h */
371 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
373 iparam32_to_iparam(&dst32, dst);
376 #endif /* AFS_HPUX_64BIT_ENV */
378 #if defined(AFS_SUN57_64BIT_ENV)
379 struct iparam32 dst32;
381 if (get_udatamodel() == DATAMODEL_ILP32) {
382 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
384 iparam32_to_iparam(&dst32, dst);
387 #endif /* AFS_SUN57_64BIT_ENV */
389 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)
390 struct iparam32 dst32;
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)
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)
404 #elif defined(AFS_PPC64_LINUX26_ENV)
405 #if defined(STRUCT_TASK_STRUCT_HAS_THREAD_INFO)
406 if (current->thread_info->flags & _TIF_32BIT)
408 if (task_thread_info(current)->flags & _TIF_32BIT)
410 #elif defined(AFS_PPC64_LINUX20_ENV)
411 if (current->thread.flags & PPC_FLAG_32BIT)
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)
419 #error iparam32 not done for this linux platform
422 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
424 iparam32_to_iparam(&dst32, dst);
427 #endif /* AFS_LINUX_64BIT_KERNEL */
429 AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code);
433 /* Main entry of all afs system calls */
435 extern int afs_sinited;
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
464 Afs_syscall(register struct afssysa *uap, rval_t * rvp)
466 int *retval = &rvp->r_val1;
467 #else /* AFS_SUN5_ENV */
468 #ifdef AFS_DARWIN100_ENV
488 afs3_syscall(AFS_PROC *p, void *args, unsigned int *retval)
490 struct afssysa64 *uap64 = NULL;
491 struct afssysa *uap = NULL;
492 #elif defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
494 afs3_syscall(p, args, retval)
495 #ifdef AFS_FBSD50_ENV
511 } *uap = (struct a *)args;
512 #else /* AFS_OSF_ENV */
513 #ifdef AFS_LINUX20_ENV
521 long parm6; /* not actually used - should be removed */
523 /* Linux system calls only set up for 5 arguments. */
525 afs_syscall(long syscall, long parm1, long parm2, long parm3, long parm4)
527 struct afssysargs args, *uap = &args;
529 long *retval = &linux_ret;
530 long eparm[4]; /* matches AFSCALL_ICL in fstrace.c */
531 #ifdef AFS_SPARC64_LINUX24_ENV
532 afs_int32 eparm32[4];
534 /* eparm is also used by AFSCALL_CALL in afsd.c */
548 } *uap = (struct a *)u.u_ap;
561 } *uap = (struct a *)u.u_ap;
563 #if defined(AFS_HPUX_ENV)
564 long *retval = &u.u_rval1;
566 int *retval = &u.u_rval1;
568 #endif /* AFS_LINUX20_ENV */
569 #endif /* AFS_OSF_ENV */
570 #endif /* AFS_SUN5_ENV */
571 register int code = 0;
573 AFS_STATCNT(afs_syscall);
580 #ifdef AFS_LINUX20_ENV
582 /* setup uap for use below - pull out the magic decoder ring to know
583 * which syscalls have folded argument lists.
585 uap->syscall = syscall;
589 if (syscall == AFSCALL_ICL || syscall == AFSCALL_CALL) {
590 #ifdef AFS_SPARC64_LINUX24_ENV
591 /* from arch/sparc64/kernel/sys_sparc32.c */
593 ({ unsigned long __ret; \
594 __asm__ ("srl %0, 0, %0" \
601 #ifdef AFS_SPARC64_LINUX26_ENV
602 if (test_thread_flag(TIF_32BIT))
604 if (current->thread.flags & SPARC_FLAG_32BIT)
607 AFS_COPYIN((char *)parm4, (char *)eparm32, sizeof(eparm32), code);
608 eparm[0] = AA(eparm32[0]);
609 eparm[1] = AA(eparm32[1]);
610 eparm[2] = AA(eparm32[2]);
614 AFS_COPYIN((char *)parm4, (char *)eparm, sizeof(eparm), code);
615 uap->parm4 = eparm[0];
616 uap->parm5 = eparm[1];
617 uap->parm6 = eparm[2];
624 #if defined(AFS_DARWIN80_ENV)
626 osi_Assert(*retval == 0);
627 #ifdef AFS_DARWIN100_ENV
628 if (proc_is64bit(p)) {
629 uap64 = (struct afssysa64 *)args;
630 if (uap64->syscall == AFSCALL_CALL) {
632 afs_syscall64_call(uap64->parm1, uap64->parm2, uap64->parm3,
633 uap64->parm4, uap64->parm5, uap64->parm6);
634 } else if (uap64->syscall == AFSCALL_SETPAG) {
636 code = afs_setpag(p, args, retval);
638 } else if (uap64->syscall == AFSCALL_PIOCTL) {
641 afs_syscall64_pioctl(uap64->parm1, (unsigned int)uap64->parm2,
642 uap64->parm3, (int)uap64->parm4,
645 } else if (uap64->syscall == AFSCALL_ICL) {
648 Afscall64_icl(uap64->parm1, uap64->parm2, uap64->parm3,
649 uap64->parm4, uap64->parm5, retval);
653 if (uap64->syscall != AFSCALL_CALL)
655 } else { /* and the default case for 32 bit procs */
657 uap = (struct afssysa *)args;
659 #if defined(AFS_HPUX_ENV)
661 * There used to be code here (duplicated from osi_Init()) for
662 * initializing the semaphore used by AFS_GLOCK(). Was the
663 * duplication to handle the case of a dynamically loaded kernel
668 if (uap->syscall == AFSCALL_CALL) {
670 afs_syscall_call(uap->parm1, uap->parm2, uap->parm3,
671 uap->parm4, uap->parm5, uap->parm6);
672 } else if (uap->syscall == AFSCALL_SETPAG) {
674 register proc_t *procp;
676 procp = ttoproc(curthread);
678 code = afs_setpag(&procp->p_cred);
682 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
683 code = afs_setpag(p, args, retval);
684 #else /* AFS_OSF_ENV */
689 } else if (uap->syscall == AFSCALL_PIOCTL) {
691 #if defined(AFS_SUN5_ENV)
693 afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3,
694 uap->parm4, rvp, CRED());
695 #elif defined(AFS_FBSD50_ENV)
697 afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3,
698 uap->parm4, p->td_ucred);
699 #elif defined(AFS_DARWIN80_ENV)
701 afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3,
702 uap->parm4, kauth_cred_get());
703 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
705 afs_syscall_pioctl(uap->parm1, uap->parm2, uap->parm3,
706 uap->parm4, p->p_cred->pc_ucred);
709 afs_syscall_pioctl((char *)uap->parm1,
710 (unsigned int)uap->parm2,
715 } else if (uap->syscall == AFSCALL_ICREATE) {
716 struct iparam iparams;
718 code = copyin_iparam((char *)uap->parm3, &iparams);
720 #if defined(KERNEL_HAVE_UERROR)
726 afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1,
727 iparams.param2, iparams.param3,
728 iparams.param4, rvp, CRED());
731 afs_syscall_icreate(uap->parm1, uap->parm2, iparams.param1,
732 iparams.param2, iparams.param3,
734 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
738 #endif /* AFS_SUN5_ENV */
740 } else if (uap->syscall == AFSCALL_IOPEN) {
743 afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3, rvp,
746 code = afs_syscall_iopen(uap->parm1, uap->parm2, uap->parm3
747 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
751 #endif /* AFS_SUN5_ENV */
752 } else if (uap->syscall == AFSCALL_IDEC) {
754 afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, -1
759 } else if (uap->syscall == AFSCALL_IINC) {
761 afs_syscall_iincdec(uap->parm1, uap->parm2, uap->parm3, 1
766 } else if (uap->syscall == AFSCALL_ICL) {
769 Afscall_icl(uap->parm1, uap->parm2, uap->parm3, uap->parm4,
770 uap->parm5, (long *)retval);
772 #ifdef AFS_LINUX20_ENV
774 /* ICL commands can return values. */
775 code = -linux_ret; /* Gets negated again at exit below */
779 #if defined(KERNEL_HAVE_UERROR)
783 #endif /* !AFS_LINUX20_ENV */
785 #if defined(KERNEL_HAVE_UERROR)
791 #if defined(AFS_DARWIN80_ENV)
792 if (uap->syscall != AFSCALL_CALL)
794 #ifdef AFS_DARWIN100_ENV
798 #ifdef AFS_LINUX20_ENV
804 #endif /* AFS_SGI_ENV */
805 #endif /* !AFS_AIX32_ENV */