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"
16 #include "afs/sysincludes.h" /* Standard vendor system headers */
18 #include "h/syscallargs.h"
21 #include "h/sysproto.h"
23 #include "afsincludes.h" /* Afs-based standard headers */
24 #include "afs/afs_stats.h" /* afs statistics */
26 #include "rx/rx_globals.h"
28 struct VenusFid afs_rootFid;
29 afs_int32 afs_waitForever = 0;
30 short afs_waitForeverCount = 0;
31 afs_int32 afs_showflags = GAGUSER | GAGCONSOLE; /* show all messages */
33 #define DECL_PIOCTL(x) static int x(struct vcache *avc, int afun, struct vrequest *areq, \
34 char *ain, char *aout, afs_int32 ainSize, afs_int32 *aoutSize, \
35 struct AFS_UCRED **acred)
37 /* Prototypes for pioctl routines */
40 DECL_PIOCTL(PStoreBehind);
45 DECL_PIOCTL(PGetFileCell);
46 DECL_PIOCTL(PGetWSCell);
47 DECL_PIOCTL(PGetUserCell);
48 DECL_PIOCTL(PSetTokens);
49 DECL_PIOCTL(PGetVolumeStatus);
50 DECL_PIOCTL(PSetVolumeStatus);
52 DECL_PIOCTL(PNewStatMount);
53 DECL_PIOCTL(PGetTokens);
55 DECL_PIOCTL(PMariner);
56 DECL_PIOCTL(PCheckServers);
57 DECL_PIOCTL(PCheckVolNames);
58 DECL_PIOCTL(PCheckAuth);
59 DECL_PIOCTL(PFindVolume);
60 DECL_PIOCTL(PViceAccess);
61 DECL_PIOCTL(PSetCacheSize);
62 DECL_PIOCTL(PGetCacheSize);
63 DECL_PIOCTL(PRemoveCallBack);
64 DECL_PIOCTL(PNewCell);
65 DECL_PIOCTL(PNewAlias);
66 DECL_PIOCTL(PListCells);
67 DECL_PIOCTL(PListAliases);
68 DECL_PIOCTL(PRemoveMount);
69 DECL_PIOCTL(PVenusLogging);
70 DECL_PIOCTL(PGetCellStatus);
71 DECL_PIOCTL(PSetCellStatus);
72 DECL_PIOCTL(PFlushVolumeData);
73 DECL_PIOCTL(PGetVnodeXStatus);
74 DECL_PIOCTL(PSetSysName);
75 DECL_PIOCTL(PSetSPrefs);
76 DECL_PIOCTL(PSetSPrefs33);
77 DECL_PIOCTL(PGetSPrefs);
78 DECL_PIOCTL(PExportAfs);
80 DECL_PIOCTL(PTwiddleRx);
81 DECL_PIOCTL(PGetInitParams);
82 DECL_PIOCTL(PGetRxkcrypt);
83 DECL_PIOCTL(PSetRxkcrypt);
84 DECL_PIOCTL(PGetCPrefs);
85 DECL_PIOCTL(PSetCPrefs);
86 DECL_PIOCTL(PFlushMount);
87 DECL_PIOCTL(PRxStatProc);
88 DECL_PIOCTL(PRxStatPeer);
89 DECL_PIOCTL(PPrefetchFromTape);
90 DECL_PIOCTL(PResidencyCmd);
91 DECL_PIOCTL(PCallBackAddr);
94 * A macro that says whether we're going to need HandleClientContext().
95 * This is currently used only by the nfs translator.
97 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
98 #define AFS_NEED_CLIENTCONTEXT
101 /* Prototypes for private routines */
102 #ifdef AFS_NEED_CLIENTCONTEXT
103 static int HandleClientContext(struct afs_ioctl *ablob, int *com,
104 struct AFS_UCRED **acred,
105 struct AFS_UCRED *credp);
107 int HandleIoctl(register struct vcache *avc, register afs_int32 acom,
108 struct afs_ioctl *adata);
109 int afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
110 register struct afs_ioctl *ablob, int afollow,
111 struct AFS_UCRED **acred);
112 static int Prefetch(char *apath, struct afs_ioctl *adata, int afollow,
113 struct AFS_UCRED *acred);
116 static int (*(VpioctlSw[])) () = {
121 PGetVolumeStatus, /* 4 */
122 PSetVolumeStatus, /* 5 */
127 PCheckServers, /* 10 */
128 PCheckVolNames, /* 11 */
130 PBogus, /* 13 -- used to be quick check time */
131 PFindVolume, /* 14 */
132 PBogus, /* 15 -- prefetch is now special-cased; see pioctl code! */
133 PBogus, /* 16 -- used to be testing code */
134 PNoop, /* 17 -- used to be enable group */
135 PNoop, /* 18 -- used to be disable group */
136 PBogus, /* 19 -- used to be list group */
137 PViceAccess, /* 20 */
138 PUnlog, /* 21 -- unlog *is* unpag in this system */
139 PGetFID, /* 22 -- get file ID */
140 PBogus, /* 23 -- used to be waitforever */
141 PSetCacheSize, /* 24 */
142 PRemoveCallBack, /* 25 -- flush only the callback */
145 PRemoveMount, /* 28 -- delete mount point */
146 PNewStatMount, /* 29 -- new style mount point stat */
147 PGetFileCell, /* 30 -- get cell name for input file */
148 PGetWSCell, /* 31 -- get cell name for workstation */
149 PMariner, /* 32 - set/get mariner host */
150 PGetUserCell, /* 33 -- get cell name for user */
151 PVenusLogging, /* 34 -- Enable/Disable logging */
152 PGetCellStatus, /* 35 */
153 PSetCellStatus, /* 36 */
154 PFlushVolumeData, /* 37 -- flush all data from a volume */
155 PSetSysName, /* 38 - Set system name */
156 PExportAfs, /* 39 - Export Afs to remote nfs clients */
157 PGetCacheSize, /* 40 - get cache size and usage */
158 PGetVnodeXStatus, /* 41 - get vcache's special status */
159 PSetSPrefs33, /* 42 - Set CM Server preferences... */
160 PGetSPrefs, /* 43 - Get CM Server preferences... */
161 PGag, /* 44 - turn off/on all CM messages */
162 PTwiddleRx, /* 45 - adjust some RX params */
163 PSetSPrefs, /* 46 - Set CM Server preferences... */
164 PStoreBehind, /* 47 - set degree of store behind to be done */
165 PGCPAGs, /* 48 - disable automatic pag gc-ing */
166 PGetInitParams, /* 49 - get initial cm params */
167 PGetCPrefs, /* 50 - get client interface addresses */
168 PSetCPrefs, /* 51 - set client interface addresses */
169 PFlushMount, /* 52 - flush mount symlink data */
170 PRxStatProc, /* 53 - control process RX statistics */
171 PRxStatPeer, /* 54 - control peer RX statistics */
172 PGetRxkcrypt, /* 55 -- Get rxkad encryption flag */
173 PSetRxkcrypt, /* 56 -- Set rxkad encryption flag */
174 PBogus, /* 57 -- arla: set file prio */
175 PBogus, /* 58 -- arla: fallback getfh */
176 PBogus, /* 59 -- arla: fallback fhopen */
177 PBogus, /* 60 -- arla: controls xfsdebug */
178 PBogus, /* 61 -- arla: controls arla debug */
179 PBogus, /* 62 -- arla: debug interface */
180 PBogus, /* 63 -- arla: print xfs status */
181 PBogus, /* 64 -- arla: force cache check */
182 PBogus, /* 65 -- arla: break callback */
183 PPrefetchFromTape, /* 66 -- MR-AFS: prefetch file from tape */
184 PResidencyCmd, /* 67 -- MR-AFS: generic commnd interface */
185 PBogus, /* 68 -- arla: fetch stats */
188 static int (*(CpioctlSw[])) () = {
190 PNewAlias, /* 1 -- create new cell alias */
191 PListAliases, /* 2 -- list cell aliases */
192 PCallBackAddr, /* 3 -- request addr for callback rxcon */
195 #define PSetClientContext 99 /* Special pioctl to setup caller's creds */
196 int afs_nobody = NFS_NOBODY;
198 #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(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV) && !defined(AFS_AMD64_LINUX20_ENV))
200 afs_ioctl32_to_afs_ioctl(const struct afs_ioctl32 *src, struct afs_ioctl *dst)
202 dst->in = (char *)(unsigned long)src->in;
203 dst->out = (char *)(unsigned long)src->out;
204 dst->in_size = src->in_size;
205 dst->out_size = src->out_size;
210 * If you need to change copyin_afs_ioctl(), you may also need to change
215 copyin_afs_ioctl(caddr_t cmarg, struct afs_ioctl *dst)
218 #if defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)
219 struct afs_ioctl32 dst32;
222 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
224 afs_ioctl32_to_afs_ioctl(&dst32, dst);
227 #endif /* defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL) */
230 #if defined(AFS_HPUX_64BIT_ENV)
231 struct afs_ioctl32 dst32;
233 if (is_32bit(u.u_procp)) { /* is_32bit() in proc_iface.h */
234 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
236 afs_ioctl32_to_afs_ioctl(&dst32, dst);
239 #endif /* defined(AFS_HPUX_64BIT_ENV) */
241 #if defined(AFS_SUN57_64BIT_ENV)
242 struct afs_ioctl32 dst32;
244 if (get_udatamodel() == DATAMODEL_ILP32) {
245 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
247 afs_ioctl32_to_afs_ioctl(&dst32, dst);
250 #endif /* defined(AFS_SUN57_64BIT_ENV) */
252 #if defined(AFS_SGI_ENV) && (_MIPS_SZLONG==64)
253 struct afs_ioctl32 dst32;
255 if (!ABI_IS_64BIT(get_current_abi())) {
256 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
258 afs_ioctl32_to_afs_ioctl(&dst32, dst);
261 #endif /* defined(AFS_SGI_ENV) && (_MIPS_SZLONG==64) */
263 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV) && !defined(AFS_AMD64_LINUX20_ENV)
264 struct afs_ioctl32 dst32;
266 #ifdef AFS_SPARC64_LINUX24_ENV
267 if (current->thread.flags & SPARC_FLAG_32BIT)
268 #elif defined(AFS_SPARC64_LINUX20_ENV)
269 if (current->tss.flags & SPARC_FLAG_32BIT)
270 #elif defined(AFS_AMD64_LINUX20_ENV)
271 if (current->thread.flags & THREAD_IA32)
272 #elif defined(AFS_PPC64_LINUX20_ENV)
273 #ifdef AFS_PPC64_LINUX26_ENV
274 if (current->thread_info->flags & _TIF_32BIT)
276 if (current->thread.flags & PPC_FLAG_32BIT)
278 #elif defined(AFS_S390X_LINUX20_ENV)
279 if (current->thread.flags & S390_FLAG_31BIT)
281 #error Not done for this linux type
284 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
286 afs_ioctl32_to_afs_ioctl(&dst32, dst);
289 #endif /* defined(AFS_LINUX_64BIT_KERNEL) */
291 AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code);
296 HandleIoctl(register struct vcache *avc, register afs_int32 acom,
297 struct afs_ioctl *adata)
299 register afs_int32 code;
302 AFS_STATCNT(HandleIoctl);
304 switch (acom & 0xff) {
306 avc->states |= CSafeStore;
310 /* case 2 used to be abort store, but this is no longer provided,
311 * since it is impossible to implement under normal Unix.
315 /* return the name of the cell this file is open on */
316 register struct cell *tcell;
317 register afs_int32 i;
319 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
321 i = strlen(tcell->cellName) + 1; /* bytes to copy out */
323 if (i > adata->out_size) {
324 /* 0 means we're not interested in the output */
325 if (adata->out_size != 0)
329 AFS_COPYOUT(tcell->cellName, adata->out, i, code);
331 afs_PutCell(tcell, READ_LOCK);
337 case 49: /* VIOC_GETINITPARAMS */
338 if (adata->out_size < sizeof(struct cm_initparams)) {
341 AFS_COPYOUT(&cm_initParams, adata->out,
342 sizeof(struct cm_initparams), code);
354 return code; /* so far, none implemented */
359 /* For aix we don't temporarily bypass ioctl(2) but rather do our
360 * thing directly in the vnode layer call, VNOP_IOCTL; thus afs_ioctl
361 * is now called from afs_gn_ioctl.
364 afs_ioctl(struct vcache *tvc, int cmd, int arg)
366 struct afs_ioctl data;
369 AFS_STATCNT(afs_ioctl);
370 if (((cmd >> 8) & 0xff) == 'V') {
371 /* This is a VICEIOCTL call */
372 AFS_COPYIN(arg, (caddr_t) & data, sizeof(data), error);
375 error = HandleIoctl(tvc, cmd, &data);
378 /* No-op call; just return. */
382 #endif /* AFS_AIX_ENV */
384 #if defined(AFS_SGI_ENV)
385 afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
388 , struct vopbd * vbds
392 struct afs_ioctl data;
398 AFS_STATCNT(afs_ioctl);
399 if (((cmd >> 8) & 0xff) == 'V') {
400 /* This is a VICEIOCTL call */
401 error = copyin_afs_ioctl(arg, &data);
404 locked = ISAFS_GLOCK();
407 error = HandleIoctl(tvc, cmd, &data);
412 /* No-op call; just return. */
416 #endif /* AFS_SGI_ENV */
418 /* unlike most calls here, this one uses u.u_error to return error conditions,
419 since this is really an intercepted chapter 2 call, rather than a vnode
422 /* AFS_HPUX102 and up uses VNODE ioctl instead */
423 #ifndef AFS_HPUX102_ENV
424 #if !defined(AFS_SGI_ENV)
428 kioctl(fdes, com, arg, ext, arg2, arg3)
429 #else /* __64BIT__ */
430 kioctl32(fdes, com, arg, ext, arg2, arg3)
431 #endif /* __64BIT__ */
434 kioctl(fdes, com, arg, ext)
445 } u_uap, *uap = &u_uap;
447 #if defined(AFS_SUN5_ENV)
449 struct afs_ioctl_sys {
456 struct afs_ioctl_sys *uap;
459 #elif defined(AFS_OSF_ENV)
460 afs_xioctl(p, args, retval)
469 } *uap = (struct a *)args;
470 #elif defined(AFS_FBSD50_ENV)
473 afs_xioctl(td, uap, retval)
475 register struct ioctl_args *uap;
478 struct proc *p = td->td_proc;
479 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
487 afs_xioctl(p, uap, retval)
489 register struct ioctl_args *uap;
492 #elif defined(AFS_LINUX22_ENV)
493 struct afs_ioctl_sys {
498 afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
501 struct afs_ioctl_sys ua, *uap = &ua;
510 } *uap = (struct a *)u.u_ap;
511 #endif /* AFS_SUN5_ENV */
513 #if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
515 #elif !defined(AFS_LINUX22_ENV)
516 register struct file *fd;
518 #if defined(AFS_XBSD_ENV)
519 register struct filedesc *fdp;
521 register struct vcache *tvc;
522 register int ioctlDone = 0, code = 0;
524 AFS_STATCNT(afs_xioctl);
525 #if defined(AFS_XBSD_ENV)
527 if ((u_int) uap->fd >= fdp->fd_nfiles
528 || (fd = fdp->fd_ofiles[uap->fd]) == NULL)
530 if ((fd->f_flag & (FREAD | FWRITE)) == 0)
532 #elif defined(AFS_DARWIN_ENV)
533 if ((code = fdgetf(p, uap->fd, &fd)))
535 #elif defined(AFS_LINUX22_ENV)
538 #elif defined(AFS_AIX32_ENV)
546 if (setuerror(getf(uap->fd, &fd))) {
549 #elif defined(AFS_OSF_ENV)
551 if (code = getf(&fd, uap->fd, FILE_FLAGS_NULL, &u.u_file_state))
553 #elif defined(AFS_SUN5_ENV)
554 # if defined(AFS_SUN57_ENV)
558 # elif defined(AFS_SUN54_ENV)
563 if (code = getf(uap->fd, &fd)) {
566 # endif /* AFS_SUN57_ENV */
572 /* first determine whether this is any sort of vnode */
573 #if defined(AFS_LINUX22_ENV)
578 if (fd->f_vnode->v_type == VREG || fd->f_vnode->v_type == VDIR) {
580 if (fd->f_type == DTYPE_VNODE) {
582 /* good, this is a vnode; next see if it is an AFS vnode */
583 #if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV)
584 tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */
585 #elif defined(AFS_OBSD_ENV)
587 IsAfsVnode((struct vnode *)fd->
588 f_data) ? VTOAFS((struct vnode *)fd->f_data) : NULL;
590 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
592 #endif /* AFS_LINUX22_ENV */
593 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
595 tvc = VTOAFS(afs_gntovn((struct gnode *)tvc));
596 if (!tvc) { /* shouldn't happen with held gnodes */
601 /* This is an AFS vnode */
602 if (((uap->com >> 8) & 0xff) == 'V') {
603 register struct afs_ioctl *datap;
606 (struct afs_ioctl *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
607 AFS_COPYIN((char *)uap->arg, (caddr_t) datap,
608 sizeof(struct afs_ioctl), code);
610 osi_FreeSmallSpace(datap);
612 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
615 #if defined(AFS_SUN5_ENV)
630 #else /* AFS_OSF_ENV */
634 #ifdef AFS_LINUX22_ENV
644 code = HandleIoctl(tvc, uap->com, datap);
645 osi_FreeSmallSpace(datap);
659 #if defined(AFS_LINUX22_ENV)
671 code = okioctl(fdes, com, arg, ext, arg2, arg3);
672 #else /* __64BIT__ */
673 code = okioctl32(fdes, com, arg, ext, arg2, arg3);
674 #endif /* __64BIT__ */
675 #else /* !AFS_AIX51_ENV */
676 code = okioctl(fdes, com, arg, ext);
677 #endif /* AFS_AIX51_ENV */
679 #else /* !AFS_AIX41_ENV */
681 okioctl(fdes, com, arg, ext);
682 #elif defined(AFS_SUN5_ENV)
683 #if defined(AFS_SUN57_ENV)
685 #elif defined(AFS_SUN54_ENV)
690 code = ioctl(uap, rvp);
691 #elif defined(AFS_FBSD50_ENV)
692 return ioctl(td, uap);
693 #elif defined(AFS_FBSD_ENV)
694 return ioctl(p, uap);
695 #elif defined(AFS_OBSD_ENV)
696 code = sys_ioctl(p, uap, retval);
697 #elif defined(AFS_DARWIN_ENV)
698 return ioctl(p, uap, retval);
699 #elif defined(AFS_OSF_ENV)
700 code = ioctl(p, args, retval);
707 #elif !defined(AFS_LINUX22_ENV)
721 #ifdef AFS_LINUX22_ENV
724 #if defined(KERNEL_HAVE_UERROR)
727 #if defined(AFS_AIX32_ENV) && !defined(AFS_AIX41_ENV)
728 return (getuerror()? -1 : u.u_ioctlrv);
730 return getuerror()? -1 : 0;
733 #endif /* AFS_LINUX22_ENV */
734 #endif /* AFS_SUN5_ENV */
735 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
739 #endif /* AFS_SGI_ENV */
740 #endif /* AFS_HPUX102_ENV */
742 #if defined(AFS_SGI_ENV)
743 /* "pioctl" system call entry point; just pass argument to the parameterized
752 afs_pioctl(struct pioctlargs *uap, rval_t * rvp)
756 AFS_STATCNT(afs_pioctl);
758 code = afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow);
767 #elif defined(AFS_OSF_ENV)
768 afs_pioctl(p, args, retval)
778 } *uap = (struct a *)args;
780 AFS_STATCNT(afs_pioctl);
781 return (afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow));
784 #elif defined(AFS_FBSD50_ENV)
786 afs_pioctl(td, args, retval)
796 } *uap = (struct a *)args;
798 AFS_STATCNT(afs_pioctl);
799 return (afs_syscall_pioctl
800 (uap->path, uap->cmd, uap->cmarg, uap->follow, td->td_ucred));
803 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
805 afs_pioctl(p, args, retval)
815 } *uap = (struct a *)args;
817 AFS_STATCNT(afs_pioctl);
818 return (afs_syscall_pioctl
819 (uap->path, uap->cmd, uap->cmarg, uap->follow,
820 p->p_cred->pc_ucred));
825 /* macro to avoid adding any more #ifdef's to pioctl code. */
826 #if defined(AFS_LINUX22_ENV) || defined(AFS_AIX41_ENV)
827 #define PIOCTL_FREE_CRED() crfree(credp)
829 #define PIOCTL_FREE_CRED()
834 afs_syscall_pioctl(path, com, cmarg, follow, rvp, credp)
836 struct AFS_UCRED *credp;
838 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
839 afs_syscall_pioctl(path, com, cmarg, follow, credp)
840 struct AFS_UCRED *credp;
842 afs_syscall_pioctl(path, com, cmarg, follow)
850 struct afs_ioctl data;
851 #ifdef AFS_NEED_CLIENTCONTEXT
852 struct AFS_UCRED *tmpcred;
854 struct AFS_UCRED *foreigncreds = NULL;
855 register afs_int32 code = 0;
856 struct vnode *vp = NULL;
861 struct ucred *credp = crref(); /* don't free until done! */
863 #ifdef AFS_LINUX22_ENV
864 cred_t *credp = crref(); /* don't free until done! */
868 AFS_STATCNT(afs_syscall_pioctl);
870 follow = 1; /* compat. with old venus */
871 code = copyin_afs_ioctl(cmarg, &data);
874 #if defined(KERNEL_HAVE_UERROR)
879 if ((com & 0xff) == PSetClientContext) {
880 #ifdef AFS_NEED_CLIENTCONTEXT
881 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV)
882 code = HandleClientContext(&data, &com, &foreigncreds, credp);
884 code = HandleClientContext(&data, &com, &foreigncreds, osi_curcred());
888 crfree(foreigncreds);
891 #if defined(KERNEL_HAVE_UERROR)
892 return (setuerror(code), code);
897 #else /* AFS_NEED_CLIENTCONTEXT */
899 #endif /* AFS_NEED_CLIENTCONTEXT */
901 #ifdef AFS_NEED_CLIENTCONTEXT
904 * We could have done without temporary setting the u.u_cred below
905 * (foreigncreds could be passed as param the pioctl modules)
906 * but calls such as afs_osi_suser() doesn't allow that since it
907 * references u.u_cred directly. We could, of course, do something
908 * like afs_osi_suser(cred) which, I think, is better since it
909 * generalizes and supports multi cred environments...
913 credp = foreigncreds;
914 #elif defined(AFS_AIX41_ENV)
915 tmpcred = crref(); /* XXX */
917 #elif defined(AFS_HPUX101_ENV)
918 tmpcred = p_cred(u.u_procp);
919 set_p_cred(u.u_procp, foreigncreds);
920 #elif defined(AFS_SGI_ENV)
921 tmpcred = OSI_GET_CURRENT_CRED();
922 OSI_SET_CURRENT_CRED(foreigncreds);
925 u.u_cred = foreigncreds;
928 #endif /* AFS_NEED_CLIENTCONTEXT */
929 if ((com & 0xff) == 15) {
930 /* special case prefetch so entire pathname eval occurs in helper process.
931 * otherwise, the pioctl call is essentially useless */
932 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
934 Prefetch(path, &data, follow,
935 foreigncreds ? foreigncreds : credp);
937 code = Prefetch(path, &data, follow, osi_curcred());
940 #if defined(KERNEL_HAVE_UERROR)
949 lookupname(path, USR, follow, NULL, &vp,
950 foreigncreds ? foreigncreds : credp);
952 #ifdef AFS_LINUX22_ENV
953 code = gop_lookupname(path, AFS_UIOUSER, follow, NULL, &dp);
955 vp = (struct vnode *)dp->d_inode;
957 code = gop_lookupname(path, AFS_UIOUSER, follow, NULL, &vp);
958 #endif /* AFS_LINUX22_ENV */
959 #endif /* AFS_AIX41_ENV */
963 #if defined(KERNEL_HAVE_UERROR)
971 /* now make the call if we were passed no file, or were passed an AFS file */
972 if (!vp || IsAfsVnode(vp)) {
973 #if defined(AFS_DEC_ENV)
974 /* Ultrix 4.0: can't get vcache entry unless we've got an AFS gnode.
975 * So, we must test in this part of the code. Also, must arrange to
976 * GRELE the original gnode pointer when we're done, since in Ultrix 4.0,
977 * we hold gnodes, whose references hold our vcache entries.
980 gp = vp; /* remember for "put" */
981 vp = (struct vnode *)afs_gntovn(vp); /* get vcache from gp */
984 #elif defined(AFS_SUN5_ENV)
985 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
986 #elif defined(AFS_AIX41_ENV)
988 struct ucred *cred1, *cred2;
991 cred1 = cred2 = foreigncreds;
993 cred1 = cred2 = credp;
995 code = afs_HandlePioctl(vp, com, &data, follow, &cred1);
996 if (cred1 != cred2) {
997 /* something changed the creds */
1001 #elif defined(AFS_HPUX101_ENV)
1003 struct ucred *cred = p_cred(u.u_procp);
1004 code = afs_HandlePioctl(vp, com, &data, follow, &cred);
1006 #elif defined(AFS_SGI_ENV)
1009 credp = OSI_GET_CURRENT_CRED();
1010 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1012 #elif defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1013 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1015 code = afs_HandlePioctl(vp, com, &data, follow, &u.u_cred);
1018 #if defined(KERNEL_HAVE_UERROR)
1021 code = EINVAL; /* not in /afs */
1032 #if defined(AFS_NEED_CLIENTCONTEXT)
1034 #ifdef AFS_AIX41_ENV
1035 crset(tmpcred); /* restore original credentials */
1037 #if defined(AFS_HPUX101_ENV)
1038 set_p_cred(u.u_procp, tmpcred); /* restore original credentials */
1039 #elif defined(AFS_SGI_ENV)
1040 OSI_SET_CURRENT_CRED(tmpcred); /* restore original credentials */
1041 #elif !defined(AFS_SUN5_ENV)
1042 osi_curcred() = tmpcred; /* restore original credentials */
1043 #endif /* AFS_HPUX101_ENV */
1044 crfree(foreigncreds);
1047 #endif /* AFS_NEED_CLIENTCONTEXT */
1049 #ifdef AFS_LINUX22_ENV
1052 AFS_RELE(vp); /* put vnode back */
1056 #if defined(KERNEL_HAVE_UERROR)
1059 return (getuerror());
1065 #define MAXPIOCTLTOKENLEN \
1066 (3*sizeof(afs_int32)+MAXKTCTICKETLEN+sizeof(struct ClearToken)+MAXKTCREALMLEN)
1069 afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
1070 register struct afs_ioctl *ablob, int afollow,
1071 struct AFS_UCRED **acred)
1074 struct vrequest treq;
1075 register afs_int32 code;
1076 register afs_int32 function, device;
1077 afs_int32 inSize, outSize, outSizeMax;
1078 char *inData, *outData;
1079 int (*(*pioctlSw)) ();
1081 struct afs_fakestat_state fakestate;
1083 avc = avp ? VTOAFS(avp) : NULL;
1084 afs_Trace3(afs_iclSetp, CM_TRACE_PIOCTL, ICL_TYPE_INT32, acom & 0xff,
1085 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, afollow);
1086 AFS_STATCNT(HandlePioctl);
1087 if ((code = afs_InitReq(&treq, *acred)))
1089 afs_InitFakeStat(&fakestate);
1091 code = afs_EvalFakeStat(&avc, &fakestate, &treq);
1093 afs_PutFakeStat(&fakestate);
1097 device = (acom & 0xff00) >> 8;
1099 case 'V': /* Original pioctls */
1100 pioctlSw = VpioctlSw;
1101 pioctlSwSize = sizeof(VpioctlSw);
1103 case 'C': /* Coordinated/common pioctls */
1104 pioctlSw = CpioctlSw;
1105 pioctlSwSize = sizeof(CpioctlSw);
1108 afs_PutFakeStat(&fakestate);
1111 function = acom & 0xff;
1112 if (function >= (pioctlSwSize / sizeof(char *))) {
1113 afs_PutFakeStat(&fakestate);
1114 return EINVAL; /* out of range */
1116 inSize = ablob->in_size;
1118 /* Do all range checking before continuing */
1119 if (inSize > MAXPIOCTLTOKENLEN || inSize < 0 || ablob->out_size < 0)
1122 if (inSize > AFS_LRALLOCSIZ) {
1123 inData = osi_AllocLargeSpace(inSize + 1);
1125 inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1130 AFS_COPYIN(ablob->in, inData, inSize, code);
1131 inData[inSize] = '\0';
1135 if (inSize > AFS_LRALLOCSIZ) {
1136 osi_Free(inData, inSize + 1);
1138 osi_FreeLargeSpace(inData);
1140 afs_PutFakeStat(&fakestate);
1143 if (function == 8 && device == 'V') { /* PGetTokens */
1144 outSizeMax = MAXPIOCTLTOKENLEN;
1145 outData = osi_Alloc(outSizeMax);
1147 outSizeMax = AFS_LRALLOCSIZ;
1148 outData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1151 if (inSize > AFS_LRALLOCSIZ) {
1152 osi_Free(inData, inSize + 1);
1154 osi_FreeLargeSpace(inData);
1160 (*pioctlSw[function]) (avc, function, &treq, inData, outData, inSize,
1162 if (inSize > AFS_LRALLOCSIZ) {
1163 osi_Free(inData, inSize + 1);
1165 osi_FreeLargeSpace(inData);
1167 if (code == 0 && ablob->out_size > 0) {
1168 if (outSize > ablob->out_size) {
1169 code = E2BIG; /* data wont fit in user buffer */
1170 } else if (outSize) {
1171 AFS_COPYOUT(outData, ablob->out, outSize, code);
1174 if (outSizeMax > AFS_LRALLOCSIZ) {
1175 osi_Free(outData, outSizeMax);
1177 osi_FreeLargeSpace(outData);
1179 afs_PutFakeStat(&fakestate);
1180 return afs_CheckCode(code, &treq, 41);
1183 DECL_PIOCTL(PGetFID)
1185 AFS_STATCNT(PGetFID);
1188 memcpy(aout, (char *)&avc->fid, sizeof(struct VenusFid));
1189 *aoutSize = sizeof(struct VenusFid);
1193 DECL_PIOCTL(PSetAcl)
1195 register afs_int32 code;
1197 struct AFSOpaque acl;
1198 struct AFSVolSync tsync;
1199 struct AFSFetchStatus OutStatus;
1202 AFS_STATCNT(PSetAcl);
1205 if ((acl.AFSOpaque_len = strlen(ain) + 1) > 1000)
1208 acl.AFSOpaque_val = ain;
1210 tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1212 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREACL);
1215 RXAFS_StoreACL(tconn->id, (struct AFSFid *)&avc->fid.Fid,
1216 &acl, &OutStatus, &tsync);
1221 } while (afs_Analyze
1222 (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_STOREACL,
1223 SHARED_LOCK, NULL));
1225 /* now we've forgotten all of the access info */
1226 ObtainWriteLock(&afs_xcbhash, 455);
1228 afs_DequeueCallback(avc);
1229 avc->states &= ~(CStatd | CUnique);
1230 ReleaseWriteLock(&afs_xcbhash);
1231 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
1232 osi_dnlc_purgedp(avc);
1236 int afs_defaultAsynchrony = 0;
1238 DECL_PIOCTL(PStoreBehind)
1241 struct sbstruct *sbr;
1243 sbr = (struct sbstruct *)ain;
1244 if (sbr->sb_default != -1) {
1245 if (afs_osi_suser(*acred))
1246 afs_defaultAsynchrony = sbr->sb_default;
1251 if (avc && (sbr->sb_thisfile != -1)) {
1253 (avc, PRSFS_WRITE | PRSFS_ADMINISTER, areq, DONT_CHECK_MODE_BITS))
1254 avc->asynchrony = sbr->sb_thisfile;
1259 *aoutSize = sizeof(struct sbstruct);
1260 sbr = (struct sbstruct *)aout;
1261 sbr->sb_default = afs_defaultAsynchrony;
1263 sbr->sb_thisfile = avc->asynchrony;
1269 DECL_PIOCTL(PGCPAGs)
1271 if (!afs_osi_suser(*acred)) {
1274 afs_gcpags = AFS_GCPAGS_USERDISABLED;
1278 DECL_PIOCTL(PGetAcl)
1280 struct AFSOpaque acl;
1281 struct AFSVolSync tsync;
1282 struct AFSFetchStatus OutStatus;
1288 AFS_STATCNT(PGetAcl);
1291 Fid.Volume = avc->fid.Fid.Volume;
1292 Fid.Vnode = avc->fid.Fid.Vnode;
1293 Fid.Unique = avc->fid.Fid.Unique;
1294 if (avc->states & CForeign) {
1296 * For a dfs xlator acl we have a special hack so that the
1297 * xlator will distinguish which type of acl will return. So
1298 * we currently use the top 2-bytes (vals 0-4) to tell which
1299 * type of acl to bring back. Horrible hack but this will
1300 * cause the least number of changes to code size and interfaces.
1302 if (Fid.Vnode & 0xc0000000)
1304 Fid.Vnode |= (ainSize << 30);
1306 acl.AFSOpaque_val = aout;
1308 tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1311 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHACL);
1313 code = RXAFS_FetchACL(tconn->id, &Fid, &acl, &OutStatus, &tsync);
1318 } while (afs_Analyze
1319 (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_FETCHACL,
1320 SHARED_LOCK, NULL));
1323 *aoutSize = (acl.AFSOpaque_len == 0 ? 1 : acl.AFSOpaque_len);
1336 AFS_STATCNT(PBogus);
1340 DECL_PIOCTL(PGetFileCell)
1342 register struct cell *tcell;
1344 AFS_STATCNT(PGetFileCell);
1347 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
1350 strcpy(aout, tcell->cellName);
1351 afs_PutCell(tcell, READ_LOCK);
1352 *aoutSize = strlen(aout) + 1;
1356 DECL_PIOCTL(PGetWSCell)
1358 struct cell *tcell = NULL;
1360 AFS_STATCNT(PGetWSCell);
1361 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1362 return EIO; /* Inappropriate ioctl for device */
1364 tcell = afs_GetPrimaryCell(READ_LOCK);
1365 if (!tcell) /* no primary cell? */
1367 strcpy(aout, tcell->cellName);
1368 *aoutSize = strlen(aout) + 1;
1369 afs_PutCell(tcell, READ_LOCK);
1373 DECL_PIOCTL(PGetUserCell)
1375 register afs_int32 i;
1376 register struct unixuser *tu;
1377 register struct cell *tcell;
1379 AFS_STATCNT(PGetUserCell);
1380 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1381 return EIO; /* Inappropriate ioctl for device */
1383 /* return the cell name of the primary cell for this user */
1384 i = UHash(areq->uid);
1385 ObtainWriteLock(&afs_xuser, 224);
1386 for (tu = afs_users[i]; tu; tu = tu->next) {
1387 if (tu->uid == areq->uid && (tu->states & UPrimary)) {
1389 ReleaseWriteLock(&afs_xuser);
1394 tcell = afs_GetCell(tu->cell, READ_LOCK);
1395 afs_PutUser(tu, WRITE_LOCK);
1399 strcpy(aout, tcell->cellName);
1400 afs_PutCell(tcell, READ_LOCK);
1401 *aoutSize = strlen(aout) + 1; /* 1 for the null */
1404 ReleaseWriteLock(&afs_xuser);
1411 DECL_PIOCTL(PSetTokens)
1414 register struct unixuser *tu;
1415 struct ClearToken clear;
1416 register struct cell *tcell;
1419 struct vrequest treq;
1420 afs_int32 flag, set_parent_pag = 0;
1422 AFS_STATCNT(PSetTokens);
1423 if (!afs_resourceinit_flag) {
1426 memcpy((char *)&i, ain, sizeof(afs_int32));
1427 ain += sizeof(afs_int32);
1428 stp = ain; /* remember where the ticket is */
1429 if (i < 0 || i > MAXKTCTICKETLEN)
1430 return EINVAL; /* malloc may fail */
1432 ain += i; /* skip over ticket */
1433 memcpy((char *)&i, ain, sizeof(afs_int32));
1434 ain += sizeof(afs_int32);
1435 if (i != sizeof(struct ClearToken)) {
1438 memcpy((char *)&clear, ain, sizeof(struct ClearToken));
1439 if (clear.AuthHandle == -1)
1440 clear.AuthHandle = 999; /* more rxvab compat stuff */
1441 ain += sizeof(struct ClearToken);
1442 if (ainSize != 2 * sizeof(afs_int32) + stLen + sizeof(struct ClearToken)) {
1443 /* still stuff left? we've got primary flag and cell name. Set these */
1444 memcpy((char *)&flag, ain, sizeof(afs_int32)); /* primary id flag */
1445 ain += sizeof(afs_int32); /* skip id field */
1446 /* rest is cell name, look it up */
1447 /* some versions of gcc appear to need != 0 in order to get this right */
1448 if ((flag & 0x8000) != 0) { /* XXX Use Constant XXX */
1452 tcell = afs_GetCellByName(ain, READ_LOCK);
1456 /* default to primary cell, primary id */
1457 flag = 1; /* primary id */
1458 tcell = afs_GetPrimaryCell(READ_LOCK);
1463 afs_PutCell(tcell, READ_LOCK);
1464 if (set_parent_pag) {
1466 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1467 #if defined(AFS_DARWIN_ENV)
1468 struct proc *p = current_proc(); /* XXX */
1470 struct proc *p = curproc; /* XXX */
1472 uprintf("Process %d (%s) tried to change pags in PSetTokens\n",
1473 p->p_pid, p->p_comm);
1474 if (!setpag(p, acred, -1, &pag, 1)) {
1477 if (!setpag(u.u_procp, acred, -1, &pag, 1)) { /* XXX u.u_procp is a no-op XXX */
1479 if (!setpag(acred, -1, &pag, 1)) {
1482 afs_InitReq(&treq, *acred);
1486 /* now we just set the tokens */
1487 tu = afs_GetUser(areq->uid, i, WRITE_LOCK); /* i has the cell # */
1488 tu->vid = clear.ViceId;
1489 if (tu->stp != NULL) {
1490 afs_osi_Free(tu->stp, tu->stLen);
1492 tu->stp = (char *)afs_osi_Alloc(stLen);
1494 memcpy(tu->stp, stp, stLen);
1497 afs_stats_cmfullperf.authent.TicketUpdates++;
1498 afs_ComputePAGStats();
1499 #endif /* AFS_NOSTATS */
1500 tu->states |= UHasTokens;
1501 tu->states &= ~UTokensBad;
1502 afs_SetPrimary(tu, flag);
1503 tu->tokenTime = osi_Time();
1504 afs_ResetUserConns(tu);
1505 afs_PutUser(tu, WRITE_LOCK);
1520 DECL_PIOCTL(PGetVolumeStatus)
1523 char *offLineMsg = afs_osi_Alloc(256);
1524 char *motd = afs_osi_Alloc(256);
1525 register struct conn *tc;
1526 register afs_int32 code = 0;
1527 struct AFSFetchVolumeStatus volstat;
1529 char *Name, *OfflineMsg, *MOTD;
1532 AFS_STATCNT(PGetVolumeStatus);
1538 OfflineMsg = offLineMsg;
1541 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1543 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS);
1546 RXAFS_GetVolumeStatus(tc->id, avc->fid.Fid.Volume, &volstat,
1547 &Name, &OfflineMsg, &MOTD);
1552 } while (afs_Analyze
1553 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS,
1554 SHARED_LOCK, NULL));
1558 /* Copy all this junk into msg->im_data, keeping track of the lengths. */
1560 memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
1561 cp += sizeof(VolumeStatus);
1562 strcpy(cp, volName);
1563 cp += strlen(volName) + 1;
1564 strcpy(cp, offLineMsg);
1565 cp += strlen(offLineMsg) + 1;
1567 cp += strlen(motd) + 1;
1568 *aoutSize = (cp - aout);
1570 afs_osi_Free(offLineMsg, 256);
1571 afs_osi_Free(motd, 256);
1575 DECL_PIOCTL(PSetVolumeStatus)
1578 char *offLineMsg = afs_osi_Alloc(256);
1579 char *motd = afs_osi_Alloc(256);
1580 register struct conn *tc;
1581 register afs_int32 code = 0;
1582 struct AFSFetchVolumeStatus volstat;
1583 struct AFSStoreVolumeStatus storeStat;
1584 register struct volume *tvp;
1588 AFS_STATCNT(PSetVolumeStatus);
1594 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
1596 if (tvp->states & (VRO | VBackup)) {
1597 afs_PutVolume(tvp, READ_LOCK);
1601 afs_PutVolume(tvp, READ_LOCK);
1606 /* Copy the junk out, using cp as a roving pointer. */
1608 memcpy((char *)&volstat, cp, sizeof(AFSFetchVolumeStatus));
1609 cp += sizeof(AFSFetchVolumeStatus);
1610 if (strlen(cp) >= sizeof(volName)) {
1614 strcpy(volName, cp);
1615 cp += strlen(volName) + 1;
1616 if (strlen(cp) >= sizeof(offLineMsg)) {
1620 strcpy(offLineMsg, cp);
1621 cp += strlen(offLineMsg) + 1;
1622 if (strlen(cp) >= sizeof(motd)) {
1628 if (volstat.MinQuota != -1) {
1629 storeStat.MinQuota = volstat.MinQuota;
1630 storeStat.Mask |= AFS_SETMINQUOTA;
1632 if (volstat.MaxQuota != -1) {
1633 storeStat.MaxQuota = volstat.MaxQuota;
1634 storeStat.Mask |= AFS_SETMAXQUOTA;
1637 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1639 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS);
1642 RXAFS_SetVolumeStatus(tc->id, avc->fid.Fid.Volume, &storeStat,
1643 volName, offLineMsg, motd);
1648 } while (afs_Analyze
1649 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS,
1650 SHARED_LOCK, NULL));
1654 /* we are sending parms back to make compat. with prev system. should
1655 * change interface later to not ask for current status, just set new status */
1657 memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
1658 cp += sizeof(VolumeStatus);
1659 strcpy(cp, volName);
1660 cp += strlen(volName) + 1;
1661 strcpy(cp, offLineMsg);
1662 cp += strlen(offLineMsg) + 1;
1664 cp += strlen(motd) + 1;
1665 *aoutSize = cp - aout;
1667 afs_osi_Free(offLineMsg, 256);
1668 afs_osi_Free(motd, 256);
1674 AFS_STATCNT(PFlush);
1677 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
1678 afs_BozonLock(&avc->pvnLock, avc); /* Since afs_TryToSmush will do a pvn_vptrunc */
1680 ObtainWriteLock(&avc->lock, 225);
1681 ObtainWriteLock(&afs_xcbhash, 456);
1682 afs_DequeueCallback(avc);
1683 avc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
1684 ReleaseWriteLock(&afs_xcbhash);
1685 /* now find the disk cache entries */
1686 afs_TryToSmush(avc, *acred, 1);
1687 osi_dnlc_purgedp(avc);
1688 afs_symhint_inval(avc);
1689 if (avc->linkData && !(avc->states & CCore)) {
1690 afs_osi_Free(avc->linkData, strlen(avc->linkData) + 1);
1691 avc->linkData = NULL;
1693 ReleaseWriteLock(&avc->lock);
1694 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
1695 afs_BozonUnlock(&avc->pvnLock, avc);
1700 DECL_PIOCTL(PNewStatMount)
1702 register afs_int32 code;
1703 register struct vcache *tvc;
1704 register struct dcache *tdc;
1705 struct VenusFid tfid;
1707 struct sysname_info sysState;
1708 afs_size_t offset, len;
1710 AFS_STATCNT(PNewStatMount);
1713 code = afs_VerifyVCache(avc, areq);
1716 if (vType(avc) != VDIR) {
1719 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
1722 Check_AtSys(avc, ain, &sysState, areq);
1723 ObtainReadLock(&tdc->lock);
1725 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
1726 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
1727 ReleaseReadLock(&tdc->lock);
1728 afs_PutDCache(tdc); /* we're done with the data */
1729 bufp = sysState.name;
1733 tfid.Cell = avc->fid.Cell;
1734 tfid.Fid.Volume = avc->fid.Fid.Volume;
1735 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
1736 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
1738 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
1744 if (tvc->mvstat != 1) {
1749 ObtainWriteLock(&tvc->lock, 226);
1750 code = afs_HandleLink(tvc, areq);
1752 if (tvc->linkData) {
1753 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
1756 /* we have the data */
1757 strcpy(aout, tvc->linkData);
1758 *aoutSize = strlen(tvc->linkData) + 1;
1763 ReleaseWriteLock(&tvc->lock);
1766 if (sysState.allocked)
1767 osi_FreeLargeSpace(bufp);
1771 DECL_PIOCTL(PGetTokens)
1773 register struct cell *tcell;
1774 register afs_int32 i;
1775 register struct unixuser *tu;
1780 AFS_STATCNT(PGetTokens);
1781 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1782 return EIO; /* Inappropriate ioctl for device */
1784 /* weird interface. If input parameter is present, it is an integer and
1785 * we're supposed to return the parm'th tokens for this unix uid.
1786 * If not present, we just return tokens for cell 1.
1787 * If counter out of bounds, return EDOM.
1788 * If no tokens for the particular cell, return ENOTCONN.
1789 * Also, if this mysterious parm is present, we return, along with the
1790 * tokens, the primary cell indicator (an afs_int32 0) and the cell name
1791 * at the end, in that order.
1793 if ((newStyle = (ainSize > 0))) {
1794 memcpy((char *)&iterator, ain, sizeof(afs_int32));
1796 i = UHash(areq->uid);
1797 ObtainReadLock(&afs_xuser);
1798 for (tu = afs_users[i]; tu; tu = tu->next) {
1800 if (tu->uid == areq->uid && (tu->states & UHasTokens)) {
1801 if (iterator-- == 0)
1802 break; /* are we done yet? */
1805 if (tu->uid == areq->uid && afs_IsPrimaryCellNum(tu->cell))
1811 * No need to hold a read lock on each user entry
1815 ReleaseReadLock(&afs_xuser);
1820 if (((tu->states & UHasTokens) == 0)
1821 || (tu->ct.EndTimestamp < osi_Time())) {
1822 tu->states |= (UTokensBad | UNeedsReset);
1823 afs_PutUser(tu, READ_LOCK);
1826 /* use iterator for temp */
1828 iterator = tu->stLen; /* for compat, we try to return 56 byte tix if they fit */
1830 iterator = 56; /* # of bytes we're returning */
1831 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1832 cp += sizeof(afs_int32);
1833 memcpy(cp, tu->stp, tu->stLen); /* copy out st */
1835 iterator = sizeof(struct ClearToken);
1836 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1837 cp += sizeof(afs_int32);
1838 memcpy(cp, (char *)&tu->ct, sizeof(struct ClearToken));
1839 cp += sizeof(struct ClearToken);
1841 /* put out primary id and cell name, too */
1842 iterator = (tu->states & UPrimary ? 1 : 0);
1843 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1844 cp += sizeof(afs_int32);
1845 tcell = afs_GetCell(tu->cell, READ_LOCK);
1847 strcpy(cp, tcell->cellName);
1848 cp += strlen(tcell->cellName) + 1;
1849 afs_PutCell(tcell, READ_LOCK);
1853 *aoutSize = cp - aout;
1854 afs_PutUser(tu, READ_LOCK);
1860 register afs_int32 i;
1861 register struct unixuser *tu;
1863 AFS_STATCNT(PUnlog);
1864 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1865 return EIO; /* Inappropriate ioctl for device */
1867 i = UHash(areq->uid);
1868 ObtainWriteLock(&afs_xuser, 227);
1869 for (tu = afs_users[i]; tu; tu = tu->next) {
1870 if (tu->uid == areq->uid) {
1872 tu->states &= ~UHasTokens;
1873 /* security is not having to say you're sorry */
1874 memset((char *)&tu->ct, 0, sizeof(struct ClearToken));
1876 ReleaseWriteLock(&afs_xuser);
1877 /* We have to drop the lock over the call to afs_ResetUserConns, since
1878 * it obtains the afs_xvcache lock. We could also keep the lock, and
1879 * modify ResetUserConns to take parm saying we obtained the lock
1880 * already, but that is overkill. By keeping the "tu" pointer
1881 * held over the released lock, we guarantee that we won't lose our
1882 * place, and that we'll pass over every user conn that existed when
1883 * we began this call.
1885 afs_ResetUserConns(tu);
1887 ObtainWriteLock(&afs_xuser, 228);
1889 /* set the expire times to 0, causes
1890 * afs_GCUserData to remove this entry
1892 tu->ct.EndTimestamp = 0;
1894 #endif /* UKERNEL */
1897 ReleaseWriteLock(&afs_xuser);
1901 DECL_PIOCTL(PMariner)
1903 afs_int32 newHostAddr;
1904 afs_int32 oldHostAddr;
1906 AFS_STATCNT(PMariner);
1908 memcpy((char *)&oldHostAddr, (char *)&afs_marinerHost,
1911 oldHostAddr = 0xffffffff; /* disabled */
1913 memcpy((char *)&newHostAddr, ain, sizeof(afs_int32));
1914 if (newHostAddr == 0xffffffff) {
1915 /* disable mariner operations */
1917 } else if (newHostAddr) {
1919 afs_marinerHost = newHostAddr;
1921 memcpy(aout, (char *)&oldHostAddr, sizeof(afs_int32));
1922 *aoutSize = sizeof(afs_int32);
1926 DECL_PIOCTL(PCheckServers)
1928 register char *cp = 0;
1930 register struct server *ts;
1931 afs_int32 temp, *lp = (afs_int32 *) ain, havecell = 0;
1933 struct chservinfo *pcheck;
1935 AFS_STATCNT(PCheckServers);
1937 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1938 return EIO; /* Inappropriate ioctl for device */
1940 if (*lp == 0x12345678) { /* For afs3.3 version */
1941 pcheck = (struct chservinfo *)ain;
1942 if (pcheck->tinterval >= 0) {
1944 memcpy(cp, (char *)&PROBE_INTERVAL, sizeof(afs_int32));
1945 *aoutSize = sizeof(afs_int32);
1946 if (pcheck->tinterval > 0) {
1947 if (!afs_osi_suser(*acred))
1949 PROBE_INTERVAL = pcheck->tinterval;
1955 temp = pcheck->tflags;
1956 cp = pcheck->tbuffer;
1957 } else { /* For pre afs3.3 versions */
1958 memcpy((char *)&temp, ain, sizeof(afs_int32));
1959 cp = ain + sizeof(afs_int32);
1960 if (ainSize > sizeof(afs_int32))
1965 * 1: fast check, don't contact servers.
1966 * 2: local cell only.
1969 /* have cell name, too */
1970 cellp = afs_GetCellByName(cp, READ_LOCK);
1975 if (!cellp && (temp & 2)) {
1976 /* use local cell */
1977 cellp = afs_GetPrimaryCell(READ_LOCK);
1979 if (!(temp & 1)) { /* if not fast, call server checker routine */
1980 afs_CheckServers(1, cellp); /* check down servers */
1981 afs_CheckServers(0, cellp); /* check up servers */
1983 /* now return the current down server list */
1985 ObtainReadLock(&afs_xserver);
1986 for (i = 0; i < NSERVERS; i++) {
1987 for (ts = afs_servers[i]; ts; ts = ts->next) {
1988 if (cellp && ts->cell != cellp)
1989 continue; /* cell spec'd and wrong */
1990 if ((ts->flags & SRVR_ISDOWN)
1991 && ts->addr->sa_portal != ts->cell->vlport) {
1992 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
1993 cp += sizeof(afs_int32);
1997 ReleaseReadLock(&afs_xserver);
1999 afs_PutCell(cellp, READ_LOCK);
2000 *aoutSize = cp - aout;
2004 DECL_PIOCTL(PCheckVolNames)
2006 AFS_STATCNT(PCheckVolNames);
2007 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2008 return EIO; /* Inappropriate ioctl for device */
2010 afs_CheckRootVolume();
2011 afs_CheckVolumeNames(AFS_VOLCHECK_FORCE | AFS_VOLCHECK_EXPIRED |
2012 AFS_VOLCHECK_BUSY | AFS_VOLCHECK_MTPTS);
2016 DECL_PIOCTL(PCheckAuth)
2021 struct unixuser *tu;
2024 AFS_STATCNT(PCheckAuth);
2025 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2026 return EIO; /* Inappropriate ioctl for device */
2029 tu = afs_GetUser(areq->uid, 1, READ_LOCK); /* check local cell authentication */
2033 /* we have a user */
2034 ObtainReadLock(&afs_xsrvAddr);
2035 ObtainReadLock(&afs_xconn);
2037 /* any tokens set? */
2038 if ((tu->states & UHasTokens) == 0)
2040 /* all connections in cell 1 working? */
2041 for (i = 0; i < NSERVERS; i++) {
2042 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2043 for (tc = sa->conns; tc; tc = tc->next) {
2044 if (tc->user == tu && (tu->states & UTokensBad))
2049 ReleaseReadLock(&afs_xsrvAddr);
2050 ReleaseReadLock(&afs_xconn);
2051 afs_PutUser(tu, READ_LOCK);
2053 memcpy(aout, (char *)&retValue, sizeof(afs_int32));
2054 *aoutSize = sizeof(afs_int32);
2059 Prefetch(char *apath, struct afs_ioctl *adata, int afollow,
2060 struct AFS_UCRED *acred)
2063 register afs_int32 code;
2064 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2070 AFS_STATCNT(Prefetch);
2073 tp = osi_AllocLargeSpace(1024);
2074 AFS_COPYINSTR(apath, tp, 1024, &bufferSize, code);
2076 osi_FreeLargeSpace(tp);
2079 if (afs_BBusy()) { /* do this as late as possible */
2080 osi_FreeLargeSpace(tp);
2081 return EWOULDBLOCK; /* pretty close */
2083 afs_BQueue(BOP_PATH, (struct vcache *)0, 0, 0, acred, (afs_size_t) 0,
2084 (afs_size_t) 0, tp);
2088 DECL_PIOCTL(PFindVolume)
2090 register struct volume *tvp;
2091 register struct server *ts;
2092 register afs_int32 i;
2095 AFS_STATCNT(PFindVolume);
2098 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
2101 for (i = 0; i < MAXHOSTS; i++) {
2102 ts = tvp->serverHost[i];
2105 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
2106 cp += sizeof(afs_int32);
2109 /* still room for terminating NULL, add it on */
2110 ainSize = 0; /* reuse vbl */
2111 memcpy(cp, (char *)&ainSize, sizeof(afs_int32));
2112 cp += sizeof(afs_int32);
2114 *aoutSize = cp - aout;
2115 afs_PutVolume(tvp, READ_LOCK);
2121 DECL_PIOCTL(PViceAccess)
2123 register afs_int32 code;
2126 AFS_STATCNT(PViceAccess);
2129 code = afs_VerifyVCache(avc, areq);
2132 memcpy((char *)&temp, ain, sizeof(afs_int32));
2133 code = afs_AccessOK(avc, temp, areq, CHECK_MODE_BITS);
2140 DECL_PIOCTL(PSetCacheSize)
2145 AFS_STATCNT(PSetCacheSize);
2146 if (!afs_osi_suser(*acred))
2148 /* too many things are setup initially in mem cache version */
2149 if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
2151 memcpy((char *)&newValue, ain, sizeof(afs_int32));
2153 afs_cacheBlocks = afs_stats_cmperf.cacheBlocksOrig;
2155 if (newValue < afs_min_cache)
2156 afs_cacheBlocks = afs_min_cache;
2158 afs_cacheBlocks = newValue;
2160 afs_stats_cmperf.cacheBlocksTotal = afs_cacheBlocks;
2161 afs_ComputeCacheParms(); /* recompute basic cache parameters */
2162 afs_MaybeWakeupTruncateDaemon();
2163 while (waitcnt++ < 100 && afs_cacheBlocks < afs_blocksUsed) {
2164 afs_osi_Wait(1000, 0, 0);
2165 afs_MaybeWakeupTruncateDaemon();
2170 #define MAXGCSTATS 16
2171 DECL_PIOCTL(PGetCacheSize)
2173 afs_int32 results[MAXGCSTATS];
2175 AFS_STATCNT(PGetCacheSize);
2176 memset((char *)results, 0, sizeof(results));
2177 results[0] = afs_cacheBlocks;
2178 results[1] = afs_blocksUsed;
2179 memcpy(aout, (char *)results, sizeof(results));
2180 *aoutSize = sizeof(results);
2184 DECL_PIOCTL(PRemoveCallBack)
2186 register struct conn *tc;
2187 register afs_int32 code = 0;
2188 struct AFSCallBack CallBacks_Array[1];
2189 struct AFSCBFids theFids;
2190 struct AFSCBs theCBs;
2193 AFS_STATCNT(PRemoveCallBack);
2196 if (avc->states & CRO)
2197 return 0; /* read-only-ness can't change */
2198 ObtainWriteLock(&avc->lock, 229);
2199 theFids.AFSCBFids_len = 1;
2200 theCBs.AFSCBs_len = 1;
2201 theFids.AFSCBFids_val = (struct AFSFid *)&avc->fid.Fid;
2202 theCBs.AFSCBs_val = CallBacks_Array;
2203 CallBacks_Array[0].CallBackType = CB_DROPPED;
2204 if (avc->callback) {
2206 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2208 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
2210 code = RXAFS_GiveUpCallBacks(tc->id, &theFids, &theCBs);
2214 /* don't set code on failure since we wouldn't use it */
2215 } while (afs_Analyze
2216 (tc, code, &avc->fid, areq,
2217 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK, NULL));
2219 ObtainWriteLock(&afs_xcbhash, 457);
2220 afs_DequeueCallback(avc);
2222 avc->states &= ~(CStatd | CUnique);
2223 ReleaseWriteLock(&afs_xcbhash);
2224 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
2225 osi_dnlc_purgedp(avc);
2227 ReleaseWriteLock(&avc->lock);
2231 DECL_PIOCTL(PNewCell)
2233 /* create a new cell */
2234 afs_int32 cellHosts[MAXCELLHOSTS], *lp, magic = 0;
2235 char *newcell = 0, *linkedcell = 0, *tp = ain;
2236 register afs_int32 code, linkedstate = 0, ls;
2237 u_short fsport = 0, vlport = 0;
2240 AFS_STATCNT(PNewCell);
2241 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2242 return EIO; /* Inappropriate ioctl for device */
2244 if (!afs_osi_suser(*acred))
2247 memcpy((char *)&magic, tp, sizeof(afs_int32));
2248 tp += sizeof(afs_int32);
2249 if (magic != 0x12345678)
2252 /* A 3.4 fs newcell command will pass an array of MAXCELLHOSTS
2253 * server addresses while the 3.5 fs newcell command passes
2254 * MAXHOSTS. To figure out which is which, check if the cellname
2257 newcell = tp + (MAXCELLHOSTS + 3) * sizeof(afs_int32);
2258 scount = ((newcell[0] != '\0') ? MAXCELLHOSTS : MAXHOSTS);
2260 /* MAXCELLHOSTS (=8) is less than MAXHOSTS (=13) */
2261 memcpy((char *)cellHosts, tp, MAXCELLHOSTS * sizeof(afs_int32));
2262 tp += (scount * sizeof(afs_int32));
2264 lp = (afs_int32 *) tp;
2268 fsport = 0; /* Privileged ports not allowed */
2270 vlport = 0; /* Privileged ports not allowed */
2271 tp += (3 * sizeof(afs_int32));
2273 if ((ls = *lp) & 1) {
2274 linkedcell = tp + strlen(newcell) + 1;
2275 linkedstate |= CLinkedCell;
2278 linkedstate |= CNoSUID; /* setuid is disabled by default for fs newcell */
2280 afs_NewCell(newcell, cellHosts, linkedstate, linkedcell, fsport,
2285 DECL_PIOCTL(PNewAlias)
2287 /* create a new cell alias */
2289 register afs_int32 code;
2290 char *realName, *aliasName;
2292 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2293 return EIO; /* Inappropriate ioctl for device */
2295 if (!afs_osi_suser(*acred))
2299 tp += strlen(aliasName) + 1;
2302 code = afs_NewCellAlias(aliasName, realName);
2307 DECL_PIOCTL(PListCells)
2309 afs_int32 whichCell;
2310 register struct cell *tcell = 0;
2311 register afs_int32 i;
2312 register char *cp, *tp = ain;
2314 AFS_STATCNT(PListCells);
2315 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2316 return EIO; /* Inappropriate ioctl for device */
2318 memcpy((char *)&whichCell, tp, sizeof(afs_int32));
2319 tp += sizeof(afs_int32);
2320 tcell = afs_GetCellByIndex(whichCell, READ_LOCK);
2323 memset(cp, 0, MAXCELLHOSTS * sizeof(afs_int32));
2324 for (i = 0; i < MAXCELLHOSTS; i++) {
2325 if (tcell->cellHosts[i] == 0)
2327 memcpy(cp, (char *)&tcell->cellHosts[i]->addr->sa_ip,
2329 cp += sizeof(afs_int32);
2331 cp = aout + MAXCELLHOSTS * sizeof(afs_int32);
2332 strcpy(cp, tcell->cellName);
2333 cp += strlen(tcell->cellName) + 1;
2334 *aoutSize = cp - aout;
2335 afs_PutCell(tcell, READ_LOCK);
2343 DECL_PIOCTL(PListAliases)
2345 afs_int32 whichAlias;
2346 register struct cell_alias *tcalias = 0;
2347 register char *cp, *tp = ain;
2349 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2350 return EIO; /* Inappropriate ioctl for device */
2351 if (ainSize < sizeof(afs_int32))
2354 memcpy((char *)&whichAlias, tp, sizeof(afs_int32));
2355 tp += sizeof(afs_int32);
2357 tcalias = afs_GetCellAlias(whichAlias);
2360 strcpy(cp, tcalias->alias);
2361 cp += strlen(tcalias->alias) + 1;
2362 strcpy(cp, tcalias->cell);
2363 cp += strlen(tcalias->cell) + 1;
2364 *aoutSize = cp - aout;
2365 afs_PutCellAlias(tcalias);
2373 DECL_PIOCTL(PRemoveMount)
2375 register afs_int32 code;
2377 struct sysname_info sysState;
2378 afs_size_t offset, len;
2379 register struct conn *tc;
2380 register struct dcache *tdc;
2381 register struct vcache *tvc;
2382 struct AFSFetchStatus OutDirStatus;
2383 struct VenusFid tfid;
2384 struct AFSVolSync tsync;
2388 /* "ain" is the name of the file in this dir to remove */
2390 AFS_STATCNT(PRemoveMount);
2393 code = afs_VerifyVCache(avc, areq);
2396 if (vType(avc) != VDIR)
2399 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1); /* test for error below */
2402 Check_AtSys(avc, ain, &sysState, areq);
2403 ObtainReadLock(&tdc->lock);
2405 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
2406 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
2407 ReleaseReadLock(&tdc->lock);
2408 bufp = sysState.name;
2413 tfid.Cell = avc->fid.Cell;
2414 tfid.Fid.Volume = avc->fid.Fid.Volume;
2415 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
2416 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
2418 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
2425 if (tvc->mvstat != 1) {
2431 ObtainWriteLock(&tvc->lock, 230);
2432 code = afs_HandleLink(tvc, areq);
2434 if (tvc->linkData) {
2435 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
2440 ReleaseWriteLock(&tvc->lock);
2441 osi_dnlc_purgedp(tvc);
2447 ObtainWriteLock(&avc->lock, 231);
2448 osi_dnlc_remove(avc, bufp, tvc);
2450 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2452 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE);
2455 RXAFS_RemoveFile(tc->id, (struct AFSFid *)&avc->fid.Fid, bufp,
2456 &OutDirStatus, &tsync);
2461 } while (afs_Analyze
2462 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_REMOVEFILE,
2463 SHARED_LOCK, NULL));
2468 ReleaseWriteLock(&avc->lock);
2472 /* we have the thing in the cache */
2473 ObtainWriteLock(&tdc->lock, 661);
2474 if (afs_LocalHero(avc, tdc, &OutDirStatus, 1)) {
2475 /* we can do it locally */
2476 code = afs_dir_Delete(tdc, bufp);
2478 ZapDCE(tdc); /* surprise error -- invalid value */
2482 ReleaseWriteLock(&tdc->lock);
2483 afs_PutDCache(tdc); /* drop ref count */
2485 avc->states &= ~CUnique; /* For the dfs xlator */
2486 ReleaseWriteLock(&avc->lock);
2489 if (sysState.allocked)
2490 osi_FreeLargeSpace(bufp);
2494 DECL_PIOCTL(PVenusLogging)
2496 return EINVAL; /* OBSOLETE */
2499 DECL_PIOCTL(PGetCellStatus)
2501 register struct cell *tcell;
2504 AFS_STATCNT(PGetCellStatus);
2505 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2506 return EIO; /* Inappropriate ioctl for device */
2508 tcell = afs_GetCellByName(ain, READ_LOCK);
2511 temp = tcell->states;
2512 afs_PutCell(tcell, READ_LOCK);
2513 memcpy(aout, (char *)&temp, sizeof(afs_int32));
2514 *aoutSize = sizeof(afs_int32);
2518 DECL_PIOCTL(PSetCellStatus)
2520 register struct cell *tcell;
2523 if (!afs_osi_suser(*acred))
2525 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2526 return EIO; /* Inappropriate ioctl for device */
2528 tcell = afs_GetCellByName(ain + 2 * sizeof(afs_int32), WRITE_LOCK);
2531 memcpy((char *)&temp, ain, sizeof(afs_int32));
2533 tcell->states |= CNoSUID;
2535 tcell->states &= ~CNoSUID;
2536 afs_PutCell(tcell, WRITE_LOCK);
2540 DECL_PIOCTL(PFlushVolumeData)
2542 register afs_int32 i;
2543 register struct dcache *tdc;
2544 register struct vcache *tvc;
2545 register struct volume *tv;
2546 afs_int32 cell, volume;
2548 AFS_STATCNT(PFlushVolumeData);
2551 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2552 return EIO; /* Inappropriate ioctl for device */
2554 volume = avc->fid.Fid.Volume; /* who to zap */
2555 cell = avc->fid.Cell;
2558 * Clear stat'd flag from all vnodes from this volume; this will invalidate all
2559 * the vcaches associated with the volume.
2561 ObtainReadLock(&afs_xvcache);
2562 for (i = 0; i < VCSIZE; i++) {
2563 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2564 if (tvc->fid.Fid.Volume == volume && tvc->fid.Cell == cell) {
2565 #if defined(AFS_SGI_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
2566 VN_HOLD(AFSTOV(tvc));
2568 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2574 ReleaseReadLock(&afs_xvcache);
2575 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
2576 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
2578 ObtainWriteLock(&tvc->lock, 232);
2580 ObtainWriteLock(&afs_xcbhash, 458);
2581 afs_DequeueCallback(tvc);
2582 tvc->states &= ~(CStatd | CDirty);
2583 ReleaseWriteLock(&afs_xcbhash);
2584 if (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
2585 osi_dnlc_purgedp(tvc);
2586 afs_TryToSmush(tvc, *acred, 1);
2587 ReleaseWriteLock(&tvc->lock);
2588 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
2589 afs_BozonUnlock(&tvc->pvnLock, tvc);
2591 ObtainReadLock(&afs_xvcache);
2592 /* our tvc ptr is still good until now */
2597 ReleaseReadLock(&afs_xvcache);
2600 MObtainWriteLock(&afs_xdcache, 328); /* needed if you're going to flush any stuff */
2601 for (i = 0; i < afs_cacheFiles; i++) {
2602 if (!(afs_indexFlags[i] & IFEverUsed))
2603 continue; /* never had any data */
2604 tdc = afs_GetDSlot(i, NULL);
2605 if (tdc->refCount <= 1) { /* too high, in use by running sys call */
2606 ReleaseReadLock(&tdc->tlock);
2607 if (tdc->f.fid.Fid.Volume == volume && tdc->f.fid.Cell == cell) {
2608 if (!(afs_indexFlags[i] & IFDataMod)) {
2609 /* if the file is modified, but has a ref cnt of only 1, then
2610 * someone probably has the file open and is writing into it.
2611 * Better to skip flushing such a file, it will be brought back
2612 * immediately on the next write anyway.
2614 * If we *must* flush, then this code has to be rearranged to call
2615 * afs_storeAllSegments() first */
2616 afs_FlushDCache(tdc);
2620 ReleaseReadLock(&tdc->tlock);
2622 afs_PutDCache(tdc); /* bumped by getdslot */
2624 MReleaseWriteLock(&afs_xdcache);
2626 ObtainReadLock(&afs_xvolume);
2627 for (i = 0; i < NVOLS; i++) {
2628 for (tv = afs_volumes[i]; tv; tv = tv->next) {
2629 if (tv->volume == volume) {
2630 afs_ResetVolumeInfo(tv);
2635 ReleaseReadLock(&afs_xvolume);
2637 /* probably, a user is doing this, probably, because things are screwed up.
2638 * maybe it's the dnlc's fault? */
2645 DECL_PIOCTL(PGetVnodeXStatus)
2647 register afs_int32 code;
2648 struct vcxstat stat;
2651 /* AFS_STATCNT(PGetVnodeXStatus); */
2654 code = afs_VerifyVCache(avc, areq);
2657 if (vType(avc) == VDIR)
2658 mode = PRSFS_LOOKUP;
2661 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
2663 stat.fid = avc->fid;
2664 hset32(stat.DataVersion, hgetlo(avc->m.DataVersion));
2665 stat.lock = avc->lock;
2666 stat.parentVnode = avc->parentVnode;
2667 stat.parentUnique = avc->parentUnique;
2668 hset(stat.flushDV, avc->flushDV);
2669 hset(stat.mapDV, avc->mapDV);
2670 stat.truncPos = avc->truncPos;
2671 { /* just grab the first two - won't break anything... */
2672 struct axscache *ac;
2674 for (i = 0, ac = avc->Access; ac && i < CPSIZE; i++, ac = ac->next) {
2675 stat.randomUid[i] = ac->uid;
2676 stat.randomAccess[i] = ac->axess;
2679 stat.callback = afs_data_pointer_to_int32(avc->callback);
2680 stat.cbExpires = avc->cbExpires;
2681 stat.anyAccess = avc->anyAccess;
2682 stat.opens = avc->opens;
2683 stat.execsOrWriters = avc->execsOrWriters;
2684 stat.flockCount = avc->flockCount;
2685 stat.mvstat = avc->mvstat;
2686 stat.states = avc->states;
2687 memcpy(aout, (char *)&stat, sizeof(struct vcxstat));
2688 *aoutSize = sizeof(struct vcxstat);
2693 /* We require root for local sysname changes, but not for remote */
2694 /* (since we don't really believe remote uids anyway) */
2695 /* outname[] shouldn't really be needed- this is left as an excercise */
2696 /* for the reader. */
2697 DECL_PIOCTL(PSetSysName)
2699 char *cp, *cp2 = NULL, inname[MAXSYSNAME], outname[MAXSYSNAME];
2700 int setsysname, foundname = 0;
2701 register struct afs_exporter *exporter;
2702 register struct unixuser *au;
2703 register afs_int32 pag, error;
2704 int t, count, num = 0;
2705 char **sysnamelist[MAXSYSNAME];
2707 AFS_STATCNT(PSetSysName);
2708 if (!afs_globalVFS) {
2709 /* Afsd is NOT running; disable it */
2710 #if defined(KERNEL_HAVE_UERROR)
2711 return (setuerror(EINVAL), EINVAL);
2716 memset(inname, 0, MAXSYSNAME);
2717 memcpy((char *)&setsysname, ain, sizeof(afs_int32));
2718 ain += sizeof(afs_int32);
2722 if (setsysname < 0 || setsysname > MAXNUMSYSNAMES)
2725 for (cp = ain, count = 0; count < setsysname; count++) {
2726 /* won't go past end of ain since maxsysname*num < ain length */
2728 if (t >= MAXSYSNAME || t <= 0)
2730 /* check for names that can shoot us in the foot */
2731 if (*cp == '.' && (cp[1] == 0 || (cp[1] == '.' && cp[2] == 0)))
2737 /* inname gets first entry in case we're being a translator */
2739 memcpy(inname, ain, t + 1); /* include terminating null */
2743 if ((*acred)->cr_gid == RMTUSER_REQ) { /* Handles all exporters */
2744 pag = PagInCred(*acred);
2746 return EINVAL; /* Better than panicing */
2748 if (!(au = afs_FindUser(pag, -1, READ_LOCK))) {
2749 return EINVAL; /* Better than panicing */
2751 if (!(exporter = au->exporter)) {
2752 afs_PutUser(au, READ_LOCK);
2753 return EINVAL; /* Better than panicing */
2755 error = EXP_SYSNAME(exporter, (setsysname ? cp2 : NULL), sysnamelist,
2758 if (error == ENODEV)
2759 foundname = 0; /* sysname not set yet! */
2761 afs_PutUser(au, READ_LOCK);
2766 strcpy(outname, (*sysnamelist)[0]);
2768 afs_PutUser(au, READ_LOCK);
2770 /* Not xlating, so local case */
2772 osi_Panic("PSetSysName: !afs_sysname\n");
2773 if (!setsysname) { /* user just wants the info */
2774 strcpy(outname, afs_sysname);
2775 foundname = afs_sysnamecount;
2776 *sysnamelist = afs_sysnamelist;
2777 } else { /* Local guy; only root can change sysname */
2778 if (!afs_osi_suser(*acred))
2781 /* clear @sys entries from the dnlc, once afs_lookup can
2782 * do lookups of @sys entries and thinks it can trust them */
2783 /* privs ok, store the entry, ... */
2784 strcpy(afs_sysname, inname);
2785 if (setsysname > 1) { /* ... or list */
2787 for (count = 1; count < setsysname; ++count) {
2788 if (!afs_sysnamelist[count])
2790 ("PSetSysName: no afs_sysnamelist entry to write\n");
2792 memcpy(afs_sysnamelist[count], cp, t + 1); /* include null */
2796 afs_sysnamecount = setsysname;
2800 cp = aout; /* not changing so report back the count and ... */
2801 memcpy(cp, (char *)&foundname, sizeof(afs_int32));
2802 cp += sizeof(afs_int32);
2804 strcpy(cp, outname); /* ... the entry, ... */
2805 cp += strlen(outname) + 1;
2806 for (count = 1; count < foundname; ++count) { /* ... or list. */
2807 if (!(*sysnamelist)[count])
2809 ("PSetSysName: no afs_sysnamelist entry to read\n");
2810 t = strlen((*sysnamelist)[count]);
2811 if (t >= MAXSYSNAME)
2812 osi_Panic("PSetSysName: sysname entry garbled\n");
2813 strcpy(cp, (*sysnamelist)[count]);
2817 *aoutSize = cp - aout;
2822 /* sequential search through the list of touched cells is not a good
2823 * long-term solution here. For small n, though, it should be just
2824 * fine. Should consider special-casing the local cell for large n.
2825 * Likewise for PSetSPrefs.
2827 * s - number of ids in array l[] -- NOT index of last id
2828 * l - array of cell ids which have volumes that need to be sorted
2829 * vlonly - sort vl servers or file servers?
2832 ReSortCells_cb(struct cell *cell, void *arg)
2834 afs_int32 *p = (afs_int32 *) arg;
2835 afs_int32 *l = p + 1;
2838 for (i = 0; i < s; i++) {
2839 if (l[i] == cell->cellNum) {
2840 ObtainWriteLock(&cell->lock, 690);
2841 afs_SortServers(cell->cellHosts, MAXCELLHOSTS);
2842 ReleaseWriteLock(&cell->lock);
2850 ReSortCells(int s, afs_int32 * l, int vlonly)
2858 p = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * (s + 1));
2860 memcpy(p + 1, l, s * sizeof(afs_int32));
2861 afs_TraverseCells(&ReSortCells_cb, p);
2862 afs_osi_Free(p, sizeof(afs_int32) * (s + 1));
2866 ObtainReadLock(&afs_xvolume);
2867 for (i = 0; i < NVOLS; i++) {
2868 for (j = afs_volumes[i]; j; j = j->next) {
2869 for (k = 0; k < s; k++)
2870 if (j->cell == l[k]) {
2871 ObtainWriteLock(&j->lock, 233);
2872 afs_SortServers(j->serverHost, MAXHOSTS);
2873 ReleaseWriteLock(&j->lock);
2878 ReleaseReadLock(&afs_xvolume);
2882 static int debugsetsp = 0;
2884 afs_setsprefs(sp, num, vlonly)
2887 unsigned int vlonly;
2890 int i, j, k, matches, touchedSize;
2891 struct server *srvr = NULL;
2892 afs_int32 touched[34];
2896 for (k = 0; k < num; sp++, k++) {
2898 printf("sp host=%x, rank=%d\n", sp->host.s_addr, sp->rank);
2901 ObtainReadLock(&afs_xserver);
2903 i = SHash(sp->host.s_addr);
2904 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2905 if (sa->sa_ip == sp->host.s_addr) {
2907 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
2908 || (sa->sa_portal == AFS_FSPORT);
2909 if ((!vlonly && isfs) || (vlonly && !isfs)) {
2916 if (sa && matches) { /* found one! */
2918 printf("sa ip=%x, ip_rank=%d\n", sa->sa_ip, sa->sa_iprank);
2920 sa->sa_iprank = sp->rank + afs_randomMod15();
2921 afs_SortOneServer(sa->server);
2924 /* if we don't know yet what cell it's in, this is moot */
2925 for (j = touchedSize - 1;
2926 j >= 0 && touched[j] != srvr->cell->cellNum; j--)
2927 /* is it in our list of touched cells ? */ ;
2928 if (j < 0) { /* no, it's not */
2929 touched[touchedSize++] = srvr->cell->cellNum;
2930 if (touchedSize >= 32) { /* watch for ovrflow */
2931 ReleaseReadLock(&afs_xserver);
2932 ReSortCells(touchedSize, touched, vlonly);
2934 ObtainReadLock(&afs_xserver);
2940 ReleaseReadLock(&afs_xserver);
2941 /* if we didn't find one, start to create one. */
2942 /* Note that it doesn't have a cell yet... */
2944 afs_uint32 temp = sp->host.s_addr;
2946 afs_GetServer(&temp, 1, 0, (vlonly ? AFS_VLPORT : AFS_FSPORT),
2947 WRITE_LOCK, (afsUUID *) 0, 0);
2948 srvr->addr->sa_iprank = sp->rank + afs_randomMod15();
2949 afs_PutServer(srvr, WRITE_LOCK);
2951 } /* for all cited preferences */
2953 ReSortCells(touchedSize, touched, vlonly);
2957 /* Note that this may only be performed by the local root user.
2959 DECL_PIOCTL(PSetSPrefs)
2961 struct setspref *ssp;
2962 AFS_STATCNT(PSetSPrefs);
2964 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2965 return EIO; /* Inappropriate ioctl for device */
2967 if (!afs_osi_suser(*acred))
2970 if (ainSize < sizeof(struct setspref))
2973 ssp = (struct setspref *)ain;
2974 if (ainSize < sizeof(struct spref) * ssp->num_servers)
2977 afs_setsprefs(&(ssp->servers[0]), ssp->num_servers,
2978 (ssp->flags & DBservers));
2982 DECL_PIOCTL(PSetSPrefs33)
2985 AFS_STATCNT(PSetSPrefs);
2986 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2987 return EIO; /* Inappropriate ioctl for device */
2990 if (!afs_osi_suser(*acred))
2993 sp = (struct spref *)ain;
2994 afs_setsprefs(sp, ainSize / (sizeof(struct spref)), 0 /*!vlonly */ );
2998 /* some notes on the following code...
2999 * in the hash table of server structs, all servers with the same IP address
3000 * will be on the same overflow chain.
3001 * This could be sped slightly in some circumstances by having it cache the
3002 * immediately previous slot in the hash table and some supporting information
3003 * Only reports file servers now.
3005 DECL_PIOCTL(PGetSPrefs)
3007 struct sprefrequest *spin; /* input */
3008 struct sprefinfo *spout; /* output */
3009 struct spref *srvout; /* one output component */
3010 int i, j; /* counters for hash table traversal */
3011 struct server *srvr; /* one of CM's server structs */
3013 int vlonly; /* just return vlservers ? */
3016 AFS_STATCNT(PGetSPrefs);
3017 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3018 return EIO; /* Inappropriate ioctl for device */
3021 if (ainSize < sizeof(struct sprefrequest_33)) {
3024 spin = ((struct sprefrequest *)ain);
3027 if (ainSize > sizeof(struct sprefrequest_33)) {
3028 vlonly = (spin->flags & DBservers);
3032 /* struct sprefinfo includes 1 server struct... that size gets added
3033 * in during the loop that follows.
3035 *aoutSize = sizeof(struct sprefinfo) - sizeof(struct spref);
3036 spout = (struct sprefinfo *)aout;
3037 spout->next_offset = spin->offset;
3038 spout->num_servers = 0;
3039 srvout = spout->servers;
3041 ObtainReadLock(&afs_xserver);
3042 for (i = 0, j = 0; j < NSERVERS; j++) { /* sift through hash table */
3043 for (sa = afs_srvAddrs[j]; sa; sa = sa->next_bkt, i++) {
3044 if (spin->offset > (unsigned short)i) {
3045 continue; /* catch up to where we left off */
3047 spout->next_offset++;
3050 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
3051 || (sa->sa_portal == AFS_FSPORT);
3053 if ((vlonly && isfs) || (!vlonly && !isfs)) {
3054 /* only report ranks for vl servers */
3058 srvout->host.s_addr = sa->sa_ip;
3059 srvout->rank = sa->sa_iprank;
3060 *aoutSize += sizeof(struct spref);
3061 spout->num_servers++;
3064 if (*aoutSize > (PIGGYSIZE - sizeof(struct spref))) {
3065 ReleaseReadLock(&afs_xserver); /* no more room! */
3070 ReleaseReadLock(&afs_xserver);
3072 spout->next_offset = 0; /* start over from the beginning next time */
3076 /* Enable/Disable the specified exporter. Must be root to disable an exporter */
3077 int afs_NFSRootOnly = 1;
3078 DECL_PIOCTL(PExportAfs)
3080 afs_int32 export, newint =
3081 0, type, changestate, handleValue, convmode, pwsync, smounts;
3082 register struct afs_exporter *exporter;
3084 AFS_STATCNT(PExportAfs);
3085 memcpy((char *)&handleValue, ain, sizeof(afs_int32));
3086 type = handleValue >> 24;
3091 exporter = exporter_find(type);
3093 export = handleValue & 3;
3094 changestate = handleValue & 0xff;
3095 smounts = (handleValue >> 2) & 3;
3096 pwsync = (handleValue >> 4) & 3;
3097 convmode = (handleValue >> 6) & 3;
3099 changestate = (handleValue >> 16) & 0x1;
3100 convmode = (handleValue >> 16) & 0x2;
3101 pwsync = (handleValue >> 16) & 0x4;
3102 smounts = (handleValue >> 16) & 0x8;
3103 export = handleValue & 0xff;
3106 /* Failed finding desired exporter; */
3110 handleValue = exporter->exp_states;
3111 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3112 *aoutSize = sizeof(afs_int32);
3114 if (!afs_osi_suser(*acred))
3115 return EACCES; /* Only superuser can do this */
3119 exporter->exp_states |= EXP_EXPORTED;
3121 exporter->exp_states &= ~EXP_EXPORTED;
3125 exporter->exp_states |= EXP_UNIXMODE;
3127 exporter->exp_states &= ~EXP_UNIXMODE;
3131 exporter->exp_states |= EXP_PWSYNC;
3133 exporter->exp_states &= ~EXP_PWSYNC;
3137 afs_NFSRootOnly = 0;
3138 exporter->exp_states |= EXP_SUBMOUNTS;
3140 afs_NFSRootOnly = 1;
3141 exporter->exp_states &= ~EXP_SUBMOUNTS;
3144 handleValue = exporter->exp_states;
3145 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3146 *aoutSize = sizeof(afs_int32);
3149 exporter->exp_states |= EXP_EXPORTED;
3151 exporter->exp_states &= ~EXP_EXPORTED;
3153 exporter->exp_states |= EXP_UNIXMODE;
3155 exporter->exp_states &= ~EXP_UNIXMODE;
3157 exporter->exp_states |= EXP_PWSYNC;
3159 exporter->exp_states &= ~EXP_PWSYNC;
3161 afs_NFSRootOnly = 0;
3162 exporter->exp_states |= EXP_SUBMOUNTS;
3164 afs_NFSRootOnly = 1;
3165 exporter->exp_states &= ~EXP_SUBMOUNTS;
3175 struct gaginfo *gagflags;
3177 if (!afs_osi_suser(*acred))
3180 gagflags = (struct gaginfo *)ain;
3181 afs_showflags = gagflags->showflags;
3187 DECL_PIOCTL(PTwiddleRx)
3189 struct rxparams *rxp;
3191 if (!afs_osi_suser(*acred))
3194 rxp = (struct rxparams *)ain;
3196 if (rxp->rx_initReceiveWindow)
3197 rx_initReceiveWindow = rxp->rx_initReceiveWindow;
3198 if (rxp->rx_maxReceiveWindow)
3199 rx_maxReceiveWindow = rxp->rx_maxReceiveWindow;
3200 if (rxp->rx_initSendWindow)
3201 rx_initSendWindow = rxp->rx_initSendWindow;
3202 if (rxp->rx_maxSendWindow)
3203 rx_maxSendWindow = rxp->rx_maxSendWindow;
3204 if (rxp->rxi_nSendFrags)
3205 rxi_nSendFrags = rxp->rxi_nSendFrags;
3206 if (rxp->rxi_nRecvFrags)
3207 rxi_nRecvFrags = rxp->rxi_nRecvFrags;
3208 if (rxp->rxi_OrphanFragSize)
3209 rxi_OrphanFragSize = rxp->rxi_OrphanFragSize;
3210 if (rxp->rx_maxReceiveSize) {
3211 rx_maxReceiveSize = rxp->rx_maxReceiveSize;
3212 rx_maxReceiveSizeUser = rxp->rx_maxReceiveSize;
3214 if (rxp->rx_MyMaxSendSize)
3215 rx_MyMaxSendSize = rxp->rx_MyMaxSendSize;
3220 DECL_PIOCTL(PGetInitParams)
3222 if (sizeof(struct cm_initparams) > PIGGYSIZE)
3225 memcpy(aout, (char *)&cm_initParams, sizeof(struct cm_initparams));
3226 *aoutSize = sizeof(struct cm_initparams);
3230 #ifdef AFS_SGI65_ENV
3231 /* They took crget() from us, so fake it. */
3236 cr = crdup(get_current_cred());
3237 memset((char *)cr, 0, sizeof(cred_t));
3238 #if CELL || CELL_PREPARE
3245 DECL_PIOCTL(PGetRxkcrypt)
3247 memcpy(aout, (char *)&cryptall, sizeof(afs_int32));
3248 *aoutSize = sizeof(afs_int32);
3252 DECL_PIOCTL(PSetRxkcrypt)
3256 if (!afs_osi_suser(*acred))
3258 if (ainSize != sizeof(afs_int32) || ain == NULL)
3260 memcpy((char *)&tmpval, ain, sizeof(afs_int32));
3261 /* if new mappings added later this will need to be changed */
3262 if (tmpval != 0 && tmpval != 1)
3268 #ifdef AFS_NEED_CLIENTCONTEXT
3270 * Create new credentials to correspond to a remote user with given
3271 * <hostaddr, uid, g0, g1>. This allows a server running as root to
3272 * provide pioctl (and other) services to foreign clients (i.e. nfs
3273 * clients) by using this call to `become' the client.
3276 #define PIOCTL_HEADER 6
3278 HandleClientContext(struct afs_ioctl *ablob, int *com,
3279 struct AFS_UCRED **acred, struct AFS_UCRED *credp)
3282 afs_uint32 hostaddr;
3283 afs_int32 uid, g0, g1, i, code, pag, exporter_type;
3284 struct afs_exporter *exporter, *outexporter;
3285 struct AFS_UCRED *newcred;
3286 struct unixuser *au;
3288 #if defined(AFS_SGIMP_ENV)
3289 osi_Assert(ISAFS_GLOCK());
3291 AFS_STATCNT(HandleClientContext);
3292 if (ablob->in_size < PIOCTL_HEADER * sizeof(afs_int32)) {
3293 /* Must at least include the PIOCTL_HEADER header words required by the protocol */
3294 return EINVAL; /* Too small to be good */
3296 ain = inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
3297 AFS_COPYIN(ablob->in, ain, PIOCTL_HEADER * sizeof(afs_int32), code);
3299 osi_FreeLargeSpace(inData);
3303 /* Extract information for remote user */
3304 hostaddr = *((afs_uint32 *) ain);
3305 ain += sizeof(hostaddr);
3306 uid = *((afs_uint32 *) ain);
3308 g0 = *((afs_uint32 *) ain);
3310 g1 = *((afs_uint32 *) ain);
3312 *com = *((afs_uint32 *) ain);
3313 ain += sizeof(afs_int32);
3314 exporter_type = *((afs_uint32 *) ain); /* In case we support more than NFS */
3317 * Of course, one must be root for most of these functions, but
3318 * we'll allow (for knfs) you to set things if the pag is 0 and
3319 * you're setting tokens or unlogging.
3322 if (!afs_osi_suser(credp)) {
3323 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
3324 /* Since SGI's suser() returns explicit failure after the call.. */
3327 /* check for acceptable opcodes for normal folks, which are, so far,
3328 * set tokens and unlog.
3330 if (i != 9 && i != 3 && i != 38 && i != 8) {
3331 osi_FreeLargeSpace(inData);
3336 ablob->in_size -= PIOCTL_HEADER * sizeof(afs_int32);
3337 ablob->in += PIOCTL_HEADER * sizeof(afs_int32);
3338 osi_FreeLargeSpace(inData);
3341 * We map uid 0 to nobody to match the mapping that the nfs
3342 * server does and to ensure that the suser() calls in the afs
3343 * code fails for remote client roots.
3345 uid = afs_nobody; /* NFS_NOBODY == -2 */
3348 #ifdef AFS_AIX41_ENV
3351 newcred->cr_gid = RMTUSER_REQ;
3352 #ifdef AFS_AIX51_ENV
3353 newcred->cr_groupset.gs_union.un_groups[0] = g0;
3354 newcred->cr_groupset.gs_union.un_groups[1] = g1;
3356 newcred->cr_groups[0] = g0;
3357 newcred->cr_groups[1] = g1;
3360 newcred->cr_ngrps = 2;
3362 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV)
3363 newcred->cr_ngroups = 2;
3365 for (i = 2; i < NGROUPS; i++)
3366 newcred->cr_groups[i] = NOGROUP;
3369 #if !defined(AFS_OSF_ENV) && !defined(AFS_DEC_ENV)
3370 afs_nfsclient_init(); /* before looking for exporter, ensure one exists */
3372 if (!(exporter = exporter_find(exporter_type))) {
3373 /* Exporter wasn't initialized or an invalid exporter type */
3377 if (exporter->exp_states & EXP_PWSYNC) {
3378 if (uid != credp->cr_uid) {
3380 return ENOEXEC; /* XXX Find a better errno XXX */
3383 newcred->cr_uid = uid; /* Only temporary */
3384 code = EXP_REQHANDLER(exporter, &newcred, hostaddr, &pag, &outexporter);
3385 /* The client's pag is the only unique identifier for it */
3386 newcred->cr_uid = pag;
3388 if (!code && *com == PSETPAG) {
3389 /* Special case for 'setpag' */
3390 afs_uint32 pagvalue = genpag();
3392 au = afs_GetUser(pagvalue, -1, WRITE_LOCK); /* a new unixuser struct */
3394 * Note that we leave the 'outexporter' struct held so it won't
3397 au->exporter = outexporter;
3398 if (ablob->out_size >= 4) {
3399 AFS_COPYOUT((char *)&pagvalue, ablob->out, sizeof(afs_int32),
3402 afs_PutUser(au, WRITE_LOCK);
3405 return PSETPAG; /* Special return for setpag */
3407 EXP_RELE(outexporter);
3411 #endif /* AFS_NEED_CLIENTCONTEXT */
3413 /* get all interface addresses of this client */
3415 DECL_PIOCTL(PGetCPrefs)
3417 struct sprefrequest *spin; /* input */
3418 struct sprefinfo *spout; /* output */
3419 struct spref *srvout; /* one output component */
3423 AFS_STATCNT(PGetCPrefs);
3424 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3425 return EIO; /* Inappropriate ioctl for device */
3427 if (ainSize < sizeof(struct sprefrequest))
3430 spin = (struct sprefrequest *)ain;
3431 spout = (struct sprefinfo *)aout;
3433 maxNumber = spin->num_servers; /* max addrs this time */
3434 srvout = spout->servers;
3436 ObtainReadLock(&afs_xinterface);
3438 /* copy out the client interface information from the
3439 ** kernel data structure "interface" to the output buffer
3441 for (i = spin->offset, j = 0; (i < afs_cb_interface.numberOfInterfaces)
3442 && (j < maxNumber); i++, j++, srvout++)
3443 srvout->host.s_addr = afs_cb_interface.addr_in[i];
3445 spout->num_servers = j;
3446 *aoutSize = sizeof(struct sprefinfo) + (j - 1) * sizeof(struct spref);
3448 if (i >= afs_cb_interface.numberOfInterfaces)
3449 spout->next_offset = 0; /* start from beginning again */
3451 spout->next_offset = spin->offset + j;
3453 ReleaseReadLock(&afs_xinterface);
3457 DECL_PIOCTL(PSetCPrefs)
3459 struct setspref *sin;
3462 AFS_STATCNT(PSetCPrefs);
3463 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3464 return EIO; /* Inappropriate ioctl for device */
3466 sin = (struct setspref *)ain;
3468 if (ainSize < sizeof(struct setspref))
3470 #if 0 /* num_servers is unsigned */
3471 if (sin->num_servers < 0)
3474 if (sin->num_servers > AFS_MAX_INTERFACE_ADDR)
3477 ObtainWriteLock(&afs_xinterface, 412);
3478 afs_cb_interface.numberOfInterfaces = sin->num_servers;
3479 for (i = 0; (unsigned short)i < sin->num_servers; i++)
3480 afs_cb_interface.addr_in[i] = sin->servers[i].host.s_addr;
3482 ReleaseWriteLock(&afs_xinterface);
3486 DECL_PIOCTL(PFlushMount)
3488 register afs_int32 code;
3489 register struct vcache *tvc;
3490 register struct dcache *tdc;
3491 struct VenusFid tfid;
3493 struct sysname_info sysState;
3494 afs_size_t offset, len;
3496 AFS_STATCNT(PFlushMount);
3499 code = afs_VerifyVCache(avc, areq);
3502 if (vType(avc) != VDIR) {
3505 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
3508 Check_AtSys(avc, ain, &sysState, areq);
3509 ObtainReadLock(&tdc->lock);
3511 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
3512 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
3513 ReleaseReadLock(&tdc->lock);
3514 afs_PutDCache(tdc); /* we're done with the data */
3515 bufp = sysState.name;
3519 tfid.Cell = avc->fid.Cell;
3520 tfid.Fid.Volume = avc->fid.Fid.Volume;
3521 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
3522 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
3524 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3530 if (tvc->mvstat != 1) {
3535 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
3536 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
3538 ObtainWriteLock(&tvc->lock, 649);
3539 ObtainWriteLock(&afs_xcbhash, 650);
3540 afs_DequeueCallback(tvc);
3541 tvc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
3542 ReleaseWriteLock(&afs_xcbhash);
3543 /* now find the disk cache entries */
3544 afs_TryToSmush(tvc, *acred, 1);
3545 osi_dnlc_purgedp(tvc);
3546 afs_symhint_inval(tvc);
3547 if (tvc->linkData && !(tvc->states & CCore)) {
3548 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
3549 tvc->linkData = NULL;
3551 ReleaseWriteLock(&tvc->lock);
3552 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
3553 afs_BozonUnlock(&tvc->pvnLock, tvc);
3557 if (sysState.allocked)
3558 osi_FreeLargeSpace(bufp);
3562 DECL_PIOCTL(PRxStatProc)
3567 if (!afs_osi_suser(*acred)) {
3571 if (ainSize != sizeof(afs_int32)) {
3575 memcpy((char *)&flags, ain, sizeof(afs_int32));
3576 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3580 if (flags & AFSCALL_RXSTATS_ENABLE) {
3581 rx_enableProcessRPCStats();
3583 if (flags & AFSCALL_RXSTATS_DISABLE) {
3584 rx_disableProcessRPCStats();
3586 if (flags & AFSCALL_RXSTATS_CLEAR) {
3587 rx_clearProcessRPCStats(AFS_RX_STATS_CLEAR_ALL);
3595 DECL_PIOCTL(PRxStatPeer)
3600 if (!afs_osi_suser(*acred)) {
3604 if (ainSize != sizeof(afs_int32)) {
3608 memcpy((char *)&flags, ain, sizeof(afs_int32));
3609 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3613 if (flags & AFSCALL_RXSTATS_ENABLE) {
3614 rx_enablePeerRPCStats();
3616 if (flags & AFSCALL_RXSTATS_DISABLE) {
3617 rx_disablePeerRPCStats();
3619 if (flags & AFSCALL_RXSTATS_CLEAR) {
3620 rx_clearPeerRPCStats(AFS_RX_STATS_CLEAR_ALL);
3627 DECL_PIOCTL(PPrefetchFromTape)
3629 register afs_int32 code, code1;
3632 struct rx_call *tcall;
3633 struct AFSVolSync tsync;
3634 struct AFSFetchStatus OutStatus;
3635 struct AFSCallBack CallBack;
3636 struct VenusFid tfid;
3640 AFS_STATCNT(PSetAcl);
3644 if (ain && (ainSize == 3 * sizeof(afs_int32)))
3645 Fid = (struct AFSFid *)ain;
3647 Fid = &avc->fid.Fid;
3648 tfid.Cell = avc->fid.Cell;
3649 tfid.Fid.Volume = Fid->Volume;
3650 tfid.Fid.Vnode = Fid->Vnode;
3651 tfid.Fid.Unique = Fid->Unique;
3653 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3655 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3656 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &avc->fid);
3659 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3660 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &tvc->fid);
3663 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3667 tcall = rx_NewCall(tc->id);
3669 StartRXAFS_FetchData(tcall, (struct AFSFid *)&tvc->fid.Fid, 0,
3672 bytes = rx_Read(tcall, (char *)aout, sizeof(afs_int32));
3674 EndRXAFS_FetchData(tcall, &OutStatus, &CallBack, &tsync);
3676 code1 = rx_EndCall(tcall, code);
3680 } while (afs_Analyze
3681 (tc, code, &tvc->fid, areq, AFS_STATS_FS_RPCIDX_RESIDENCYRPCS,
3682 SHARED_LOCK, NULL));
3683 /* This call is done only to have the callback things handled correctly */
3684 afs_FetchStatus(tvc, &tfid, areq, &OutStatus);
3688 *aoutSize = sizeof(afs_int32);
3693 DECL_PIOCTL(PResidencyCmd)
3695 register afs_int32 code;
3698 struct ResidencyCmdInputs *Inputs;
3699 struct ResidencyCmdOutputs *Outputs;
3700 struct VenusFid tfid;
3703 Inputs = (struct ResidencyCmdInputs *)ain;
3704 Outputs = (struct ResidencyCmdOutputs *)aout;
3707 if (!ain || ainSize != sizeof(struct ResidencyCmdInputs))
3712 Fid = &avc->fid.Fid;
3714 tfid.Cell = avc->fid.Cell;
3715 tfid.Fid.Volume = Fid->Volume;
3716 tfid.Fid.Vnode = Fid->Vnode;
3717 tfid.Fid.Unique = Fid->Unique;
3719 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3720 afs_Trace3(afs_iclSetp, CM_TRACE_RESIDCMD, ICL_TYPE_POINTER, tvc,
3721 ICL_TYPE_INT32, Inputs->command, ICL_TYPE_FID, &tfid);
3725 if (Inputs->command) {
3727 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3731 RXAFS_ResidencyCmd(tc->id, Fid, Inputs,
3732 (struct ResidencyCmdOutputs *)aout);
3736 } while (afs_Analyze
3737 (tc, code, &tvc->fid, areq,
3738 AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK, NULL));
3739 /* This call is done to have the callback things handled correctly */
3740 afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3741 } else { /* just a status request, return also link data */
3743 Outputs->code = afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3744 Outputs->chars[0] = 0;
3745 if (vType(tvc) == VLNK) {
3746 ObtainWriteLock(&tvc->lock, 555);
3747 if (afs_HandleLink(tvc, areq) == 0)
3748 strncpy((char *)&Outputs->chars, tvc->linkData, MAXCMDCHARS);
3749 ReleaseWriteLock(&tvc->lock);
3756 *aoutSize = sizeof(struct ResidencyCmdOutputs);
3761 DECL_PIOCTL(PCallBackAddr)
3764 afs_uint32 addr, code;
3770 struct unixuser *tu;
3771 struct srvAddr **addrs;
3773 /*AFS_STATCNT(PCallBackAddr); */
3774 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
3775 return EIO; /* Inappropriate ioctl for device */
3777 if (!afs_osi_suser(acred))
3780 if (ainSize < sizeof(afs_int32))
3783 memcpy(&addr, ain, sizeof(afs_int32));
3785 ObtainReadLock(&afs_xinterface);
3786 for (i = 0; (unsigned short)i < afs_cb_interface.numberOfInterfaces; i++) {
3787 if (afs_cb_interface.addr_in[i] == addr)
3791 ReleaseWriteLock(&afs_xinterface);
3793 if (afs_cb_interface.addr_in[i] != addr)
3796 ObtainReadLock(&afs_xserver); /* Necessary? */
3797 ObtainReadLock(&afs_xsrvAddr);
3800 for (i = 0; i < NSERVERS; i++) {
3801 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3806 addrs = afs_osi_Alloc(srvAddrCount * sizeof(*addrs));
3808 for (i = 0; i < NSERVERS; i++) {
3809 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3810 if (j >= srvAddrCount)
3816 ReleaseReadLock(&afs_xsrvAddr);
3817 ReleaseReadLock(&afs_xserver);
3819 for (i = 0; i < j; i++) {
3825 /* vlserver has no callback conn */
3826 if (sa->sa_portal == AFS_VLPORT) {
3830 if (!ts->cell) /* not really an active server, anyway, it must */
3831 continue; /* have just been added by setsprefs */
3833 /* get a connection, even if host is down; bumps conn ref count */
3834 tu = afs_GetUser(areq->uid, ts->cell->cellNum, SHARED_LOCK);
3835 tc = afs_ConnBySA(sa, ts->cell->fsport, ts->cell->cellNum, tu,
3836 1 /*force */ , 1 /*create */ , SHARED_LOCK);
3837 afs_PutUser(tu, SHARED_LOCK);
3841 if ((sa->sa_flags & SRVADDR_ISDOWN) || afs_HaveCallBacksFrom(ts)) {
3842 if (sa->sa_flags & SRVADDR_ISDOWN) {
3843 rx_SetConnDeadTime(tc->id, 3);
3845 #ifdef RX_ENABLE_LOCKS
3847 #endif /* RX_ENABLE_LOCKS */
3848 code = RXAFS_CallBackRxConnAddr(tc->id, &addr);
3849 #ifdef RX_ENABLE_LOCKS
3851 #endif /* RX_ENABLE_LOCKS */
3853 afs_PutConn(tc, SHARED_LOCK); /* done with it now */
3854 } /* Outer loop over addrs */
3855 #endif /* UKERNEL */