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(PGetVnodeXStatus2);
75 DECL_PIOCTL(PSetSysName);
76 DECL_PIOCTL(PSetSPrefs);
77 DECL_PIOCTL(PSetSPrefs33);
78 DECL_PIOCTL(PGetSPrefs);
79 DECL_PIOCTL(PExportAfs);
81 DECL_PIOCTL(PTwiddleRx);
82 DECL_PIOCTL(PGetInitParams);
83 DECL_PIOCTL(PGetRxkcrypt);
84 DECL_PIOCTL(PSetRxkcrypt);
85 DECL_PIOCTL(PGetCPrefs);
86 DECL_PIOCTL(PSetCPrefs);
87 DECL_PIOCTL(PFlushMount);
88 DECL_PIOCTL(PRxStatProc);
89 DECL_PIOCTL(PRxStatPeer);
90 DECL_PIOCTL(PPrefetchFromTape);
91 DECL_PIOCTL(PResidencyCmd);
92 DECL_PIOCTL(PCallBackAddr);
93 DECL_PIOCTL(PNFSNukeCreds);
96 * A macro that says whether we're going to need HandleClientContext().
97 * This is currently used only by the nfs translator.
99 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
100 #define AFS_NEED_CLIENTCONTEXT
103 /* Prototypes for private routines */
104 #ifdef AFS_NEED_CLIENTCONTEXT
105 static int HandleClientContext(struct afs_ioctl *ablob, int *com,
106 struct AFS_UCRED **acred,
107 struct AFS_UCRED *credp);
109 int HandleIoctl(register struct vcache *avc, register afs_int32 acom,
110 struct afs_ioctl *adata);
111 int afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
112 register struct afs_ioctl *ablob, int afollow,
113 struct AFS_UCRED **acred);
114 static int Prefetch(char *apath, struct afs_ioctl *adata, int afollow,
115 struct AFS_UCRED *acred);
118 static int (*(VpioctlSw[])) () = {
123 PGetVolumeStatus, /* 4 */
124 PSetVolumeStatus, /* 5 */
129 PCheckServers, /* 10 */
130 PCheckVolNames, /* 11 */
132 PBogus, /* 13 -- used to be quick check time */
133 PFindVolume, /* 14 */
134 PBogus, /* 15 -- prefetch is now special-cased; see pioctl code! */
135 PBogus, /* 16 -- used to be testing code */
136 PNoop, /* 17 -- used to be enable group */
137 PNoop, /* 18 -- used to be disable group */
138 PBogus, /* 19 -- used to be list group */
139 PViceAccess, /* 20 */
140 PUnlog, /* 21 -- unlog *is* unpag in this system */
141 PGetFID, /* 22 -- get file ID */
142 PBogus, /* 23 -- used to be waitforever */
143 PSetCacheSize, /* 24 */
144 PRemoveCallBack, /* 25 -- flush only the callback */
147 PRemoveMount, /* 28 -- delete mount point */
148 PNewStatMount, /* 29 -- new style mount point stat */
149 PGetFileCell, /* 30 -- get cell name for input file */
150 PGetWSCell, /* 31 -- get cell name for workstation */
151 PMariner, /* 32 - set/get mariner host */
152 PGetUserCell, /* 33 -- get cell name for user */
153 PVenusLogging, /* 34 -- Enable/Disable logging */
154 PGetCellStatus, /* 35 */
155 PSetCellStatus, /* 36 */
156 PFlushVolumeData, /* 37 -- flush all data from a volume */
157 PSetSysName, /* 38 - Set system name */
158 PExportAfs, /* 39 - Export Afs to remote nfs clients */
159 PGetCacheSize, /* 40 - get cache size and usage */
160 PGetVnodeXStatus, /* 41 - get vcache's special status */
161 PSetSPrefs33, /* 42 - Set CM Server preferences... */
162 PGetSPrefs, /* 43 - Get CM Server preferences... */
163 PGag, /* 44 - turn off/on all CM messages */
164 PTwiddleRx, /* 45 - adjust some RX params */
165 PSetSPrefs, /* 46 - Set CM Server preferences... */
166 PStoreBehind, /* 47 - set degree of store behind to be done */
167 PGCPAGs, /* 48 - disable automatic pag gc-ing */
168 PGetInitParams, /* 49 - get initial cm params */
169 PGetCPrefs, /* 50 - get client interface addresses */
170 PSetCPrefs, /* 51 - set client interface addresses */
171 PFlushMount, /* 52 - flush mount symlink data */
172 PRxStatProc, /* 53 - control process RX statistics */
173 PRxStatPeer, /* 54 - control peer RX statistics */
174 PGetRxkcrypt, /* 55 -- Get rxkad encryption flag */
175 PSetRxkcrypt, /* 56 -- Set rxkad encryption flag */
176 PBogus, /* 57 -- arla: set file prio */
177 PBogus, /* 58 -- arla: fallback getfh */
178 PBogus, /* 59 -- arla: fallback fhopen */
179 PBogus, /* 60 -- arla: controls xfsdebug */
180 PBogus, /* 61 -- arla: controls arla debug */
181 PBogus, /* 62 -- arla: debug interface */
182 PBogus, /* 63 -- arla: print xfs status */
183 PBogus, /* 64 -- arla: force cache check */
184 PBogus, /* 65 -- arla: break callback */
185 PPrefetchFromTape, /* 66 -- MR-AFS: prefetch file from tape */
186 PResidencyCmd, /* 67 -- MR-AFS: generic commnd interface */
187 PBogus, /* 68 -- arla: fetch stats */
188 PGetVnodeXStatus2, /* 69 - get caller access and some vcache status */
191 static int (*(CpioctlSw[])) () = {
193 PNewAlias, /* 1 -- create new cell alias */
194 PListAliases, /* 2 -- list cell aliases */
195 PCallBackAddr, /* 3 -- request addr for callback rxcon */
198 static int (*(OpioctlSw[])) () = {
200 PNFSNukeCreds, /* 1 -- nuke all creds for NFS client */
203 #define PSetClientContext 99 /* Special pioctl to setup caller's creds */
204 int afs_nobody = NFS_NOBODY;
207 HandleIoctl(register struct vcache *avc, register afs_int32 acom,
208 struct afs_ioctl *adata)
210 register afs_int32 code;
213 AFS_STATCNT(HandleIoctl);
215 switch (acom & 0xff) {
217 avc->states |= CSafeStore;
221 /* case 2 used to be abort store, but this is no longer provided,
222 * since it is impossible to implement under normal Unix.
226 /* return the name of the cell this file is open on */
227 register struct cell *tcell;
228 register afs_int32 i;
230 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
232 i = strlen(tcell->cellName) + 1; /* bytes to copy out */
234 if (i > adata->out_size) {
235 /* 0 means we're not interested in the output */
236 if (adata->out_size != 0)
240 AFS_COPYOUT(tcell->cellName, adata->out, i, code);
242 afs_PutCell(tcell, READ_LOCK);
248 case 49: /* VIOC_GETINITPARAMS */
249 if (adata->out_size < sizeof(struct cm_initparams)) {
252 AFS_COPYOUT(&cm_initParams, adata->out,
253 sizeof(struct cm_initparams), code);
265 return code; /* so far, none implemented */
270 /* For aix we don't temporarily bypass ioctl(2) but rather do our
271 * thing directly in the vnode layer call, VNOP_IOCTL; thus afs_ioctl
272 * is now called from afs_gn_ioctl.
275 afs_ioctl(struct vcache *tvc, int cmd, int arg)
277 struct afs_ioctl data;
280 AFS_STATCNT(afs_ioctl);
281 if (((cmd >> 8) & 0xff) == 'V') {
282 /* This is a VICEIOCTL call */
283 AFS_COPYIN(arg, (caddr_t) & data, sizeof(data), error);
286 error = HandleIoctl(tvc, cmd, &data);
289 /* No-op call; just return. */
293 #endif /* AFS_AIX_ENV */
295 #if defined(AFS_SGI_ENV)
296 afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
299 , struct vopbd * vbds
303 struct afs_ioctl data;
309 AFS_STATCNT(afs_ioctl);
310 if (((cmd >> 8) & 0xff) == 'V') {
311 /* This is a VICEIOCTL call */
312 error = copyin_afs_ioctl(arg, &data);
315 locked = ISAFS_GLOCK();
318 error = HandleIoctl(tvc, cmd, &data);
323 /* No-op call; just return. */
327 #endif /* AFS_SGI_ENV */
329 /* unlike most calls here, this one uses u.u_error to return error conditions,
330 since this is really an intercepted chapter 2 call, rather than a vnode
333 /* AFS_HPUX102 and up uses VNODE ioctl instead */
334 #if !defined(AFS_HPUX102_ENV) && !defined(AFS_DARWIN80_ENV)
335 #if !defined(AFS_SGI_ENV)
339 kioctl(fdes, com, arg, ext, arg2, arg3)
340 #else /* __64BIT__ */
341 kioctl32(fdes, com, arg, ext, arg2, arg3)
342 #endif /* __64BIT__ */
345 kioctl(fdes, com, arg, ext)
356 } u_uap, *uap = &u_uap;
358 #if defined(AFS_SUN5_ENV)
360 struct afs_ioctl_sys {
367 struct afs_ioctl_sys *uap;
370 #elif defined(AFS_OSF_ENV)
371 afs_xioctl(p, args, retval)
380 } *uap = (struct a *)args;
381 #elif defined(AFS_FBSD50_ENV)
384 afs_xioctl(td, uap, retval)
386 register struct ioctl_args *uap;
389 struct proc *p = td->td_proc;
390 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
398 afs_xioctl(p, uap, retval)
400 register struct ioctl_args *uap;
403 #elif defined(AFS_LINUX22_ENV)
404 struct afs_ioctl_sys {
409 afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
412 struct afs_ioctl_sys ua, *uap = &ua;
421 } *uap = (struct a *)u.u_ap;
422 #endif /* AFS_SUN5_ENV */
424 #if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
426 #elif !defined(AFS_LINUX22_ENV)
427 register struct file *fd;
429 #if defined(AFS_XBSD_ENV)
430 register struct filedesc *fdp;
432 register struct vcache *tvc;
433 register int ioctlDone = 0, code = 0;
435 AFS_STATCNT(afs_xioctl);
436 #if defined(AFS_DARWIN_ENV)
437 if ((code = fdgetf(p, uap->fd, &fd)))
439 #elif defined(AFS_XBSD_ENV)
441 if ((u_int) uap->fd >= fdp->fd_nfiles
442 || (fd = fdp->fd_ofiles[uap->fd]) == NULL)
444 if ((fd->f_flag & (FREAD | FWRITE)) == 0)
446 #elif defined(AFS_LINUX22_ENV)
449 #elif defined(AFS_AIX32_ENV)
457 if (setuerror(getf(uap->fd, &fd))) {
460 #elif defined(AFS_OSF_ENV)
462 if (code = getf(&fd, uap->fd, FILE_FLAGS_NULL, &u.u_file_state))
464 #elif defined(AFS_SUN5_ENV)
465 # if defined(AFS_SUN57_ENV)
469 # elif defined(AFS_SUN54_ENV)
474 if (code = getf(uap->fd, &fd)) {
477 # endif /* AFS_SUN57_ENV */
483 /* first determine whether this is any sort of vnode */
484 #if defined(AFS_LINUX22_ENV)
489 if (fd->f_vnode->v_type == VREG || fd->f_vnode->v_type == VDIR) {
491 if (fd->f_type == DTYPE_VNODE) {
493 /* good, this is a vnode; next see if it is an AFS vnode */
494 #if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV)
495 tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */
496 #elif defined(AFS_OBSD_ENV)
498 IsAfsVnode((struct vnode *)fd->
499 f_data) ? VTOAFS((struct vnode *)fd->f_data) : NULL;
501 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
503 #endif /* AFS_LINUX22_ENV */
504 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
505 /* This is an AFS vnode */
506 if (((uap->com >> 8) & 0xff) == 'V') {
507 register struct afs_ioctl *datap;
510 (struct afs_ioctl *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
511 code=copyin_afs_ioctl((char *)uap->arg, datap);
513 osi_FreeSmallSpace(datap);
515 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
518 #if defined(AFS_SUN5_ENV)
533 #else /* AFS_OSF_ENV */
537 #ifdef AFS_LINUX22_ENV
547 code = HandleIoctl(tvc, uap->com, datap);
548 osi_FreeSmallSpace(datap);
562 #if defined(AFS_LINUX22_ENV)
574 code = okioctl(fdes, com, arg, ext, arg2, arg3);
575 #else /* __64BIT__ */
576 code = okioctl32(fdes, com, arg, ext, arg2, arg3);
577 #endif /* __64BIT__ */
578 #else /* !AFS_AIX51_ENV */
579 code = okioctl(fdes, com, arg, ext);
580 #endif /* AFS_AIX51_ENV */
582 #else /* !AFS_AIX41_ENV */
584 okioctl(fdes, com, arg, ext);
585 #elif defined(AFS_SUN5_ENV)
586 #if defined(AFS_SUN57_ENV)
588 #elif defined(AFS_SUN54_ENV)
593 code = ioctl(uap, rvp);
594 #elif defined(AFS_FBSD50_ENV)
595 return ioctl(td, uap);
596 #elif defined(AFS_FBSD_ENV)
597 return ioctl(p, uap);
598 #elif defined(AFS_OBSD_ENV)
599 code = sys_ioctl(p, uap, retval);
600 #elif defined(AFS_DARWIN_ENV)
601 return ioctl(p, uap, retval);
602 #elif defined(AFS_OSF_ENV)
603 code = ioctl(p, args, retval);
610 #elif !defined(AFS_LINUX22_ENV)
624 #ifdef AFS_LINUX22_ENV
627 #if defined(KERNEL_HAVE_UERROR)
630 #if defined(AFS_AIX32_ENV) && !defined(AFS_AIX41_ENV)
631 return (getuerror()? -1 : u.u_ioctlrv);
633 return getuerror()? -1 : 0;
636 #endif /* AFS_LINUX22_ENV */
637 #endif /* AFS_SUN5_ENV */
638 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
642 #endif /* AFS_SGI_ENV */
643 #endif /* AFS_HPUX102_ENV */
645 #if defined(AFS_SGI_ENV)
646 /* "pioctl" system call entry point; just pass argument to the parameterized
655 afs_pioctl(struct pioctlargs *uap, rval_t * rvp)
659 AFS_STATCNT(afs_pioctl);
661 code = afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow);
670 #elif defined(AFS_OSF_ENV)
671 afs_pioctl(p, args, retval)
681 } *uap = (struct a *)args;
683 AFS_STATCNT(afs_pioctl);
684 return (afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow));
687 #elif defined(AFS_FBSD50_ENV)
689 afs_pioctl(td, args, retval)
699 } *uap = (struct a *)args;
701 AFS_STATCNT(afs_pioctl);
702 return (afs_syscall_pioctl
703 (uap->path, uap->cmd, uap->cmarg, uap->follow, td->td_ucred));
706 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
708 afs_pioctl(p, args, retval)
718 } *uap = (struct a *)args;
720 AFS_STATCNT(afs_pioctl);
721 #ifdef AFS_DARWIN80_ENV
722 return (afs_syscall_pioctl
723 (uap->path, uap->cmd, uap->cmarg, uap->follow,
726 return (afs_syscall_pioctl
727 (uap->path, uap->cmd, uap->cmarg, uap->follow,
728 p->p_cred->pc_ucred));
734 /* macro to avoid adding any more #ifdef's to pioctl code. */
735 #if defined(AFS_LINUX22_ENV) || defined(AFS_AIX41_ENV)
736 #define PIOCTL_FREE_CRED() crfree(credp)
738 #define PIOCTL_FREE_CRED()
743 afs_syscall_pioctl(path, com, cmarg, follow, rvp, credp)
745 struct AFS_UCRED *credp;
747 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
748 afs_syscall_pioctl(path, com, cmarg, follow, credp)
749 struct AFS_UCRED *credp;
751 afs_syscall_pioctl(path, com, cmarg, follow)
759 struct afs_ioctl data;
760 #ifdef AFS_NEED_CLIENTCONTEXT
761 struct AFS_UCRED *tmpcred = NULL;
763 struct AFS_UCRED *foreigncreds = NULL;
764 register afs_int32 code = 0;
765 struct vnode *vp = NULL;
767 struct ucred *credp = crref(); /* don't free until done! */
769 #ifdef AFS_LINUX22_ENV
770 cred_t *credp = crref(); /* don't free until done! */
774 AFS_STATCNT(afs_syscall_pioctl);
776 follow = 1; /* compat. with old venus */
777 code = copyin_afs_ioctl(cmarg, &data);
780 #if defined(KERNEL_HAVE_UERROR)
785 if ((com & 0xff) == PSetClientContext) {
786 #ifdef AFS_NEED_CLIENTCONTEXT
787 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV)
788 code = HandleClientContext(&data, &com, &foreigncreds, credp);
790 code = HandleClientContext(&data, &com, &foreigncreds, osi_curcred());
794 crfree(foreigncreds);
797 #if defined(KERNEL_HAVE_UERROR)
798 return (setuerror(code), code);
803 #else /* AFS_NEED_CLIENTCONTEXT */
805 #endif /* AFS_NEED_CLIENTCONTEXT */
807 #ifdef AFS_NEED_CLIENTCONTEXT
810 * We could have done without temporary setting the u.u_cred below
811 * (foreigncreds could be passed as param the pioctl modules)
812 * but calls such as afs_osi_suser() doesn't allow that since it
813 * references u.u_cred directly. We could, of course, do something
814 * like afs_osi_suser(cred) which, I think, is better since it
815 * generalizes and supports multi cred environments...
817 #if defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
819 credp = foreigncreds;
820 #elif defined(AFS_AIX41_ENV)
821 tmpcred = crref(); /* XXX */
823 #elif defined(AFS_HPUX101_ENV)
824 tmpcred = p_cred(u.u_procp);
825 set_p_cred(u.u_procp, foreigncreds);
826 #elif defined(AFS_SGI_ENV)
827 tmpcred = OSI_GET_CURRENT_CRED();
828 OSI_SET_CURRENT_CRED(foreigncreds);
831 u.u_cred = foreigncreds;
834 #endif /* AFS_NEED_CLIENTCONTEXT */
835 if ((com & 0xff) == 15) {
836 /* special case prefetch so entire pathname eval occurs in helper process.
837 * otherwise, the pioctl call is essentially useless */
838 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
840 Prefetch(path, &data, follow,
841 foreigncreds ? foreigncreds : credp);
843 code = Prefetch(path, &data, follow, osi_curcred());
846 #if defined(KERNEL_HAVE_UERROR)
855 lookupname(path, USR, follow, NULL, &vp,
856 foreigncreds ? foreigncreds : credp);
858 #ifdef AFS_LINUX22_ENV
859 code = gop_lookupname(path, AFS_UIOUSER, follow, &dp);
861 vp = (struct vnode *)dp->d_inode;
863 code = gop_lookupname(path, AFS_UIOUSER, follow, &vp);
864 #endif /* AFS_LINUX22_ENV */
865 #endif /* AFS_AIX41_ENV */
869 #if defined(KERNEL_HAVE_UERROR)
877 #if defined(AFS_SUN510_ENV)
878 if (vp && !IsAfsVnode(vp)) {
879 struct vnode *realvp;
881 if (VOP_REALVP(vp, &realvp) == 0) {
882 struct vnode *oldvp = vp;
890 /* now make the call if we were passed no file, or were passed an AFS file */
891 if (!vp || IsAfsVnode(vp)) {
892 #if defined(AFS_SUN5_ENV)
893 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
894 #elif defined(AFS_AIX41_ENV)
896 struct ucred *cred1, *cred2;
899 cred1 = cred2 = foreigncreds;
901 cred1 = cred2 = credp;
903 code = afs_HandlePioctl(vp, com, &data, follow, &cred1);
904 if (cred1 != cred2) {
905 /* something changed the creds */
909 #elif defined(AFS_HPUX101_ENV)
911 struct ucred *cred = p_cred(u.u_procp);
912 code = afs_HandlePioctl(vp, com, &data, follow, &cred);
914 #elif defined(AFS_SGI_ENV)
917 credp = OSI_GET_CURRENT_CRED();
918 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
920 #elif defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
921 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
923 code = afs_HandlePioctl(vp, com, &data, follow, &u.u_cred);
926 #if defined(KERNEL_HAVE_UERROR)
929 code = EINVAL; /* not in /afs */
934 #if defined(AFS_NEED_CLIENTCONTEXT)
937 crset(tmpcred); /* restore original credentials */
939 #if defined(AFS_HPUX101_ENV)
940 set_p_cred(u.u_procp, tmpcred); /* restore original credentials */
941 #elif defined(AFS_SGI_ENV)
942 OSI_SET_CURRENT_CRED(tmpcred); /* restore original credentials */
943 #elif defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
944 credp = tmpcred; /* restore original credentials */
946 osi_curcred() = tmpcred; /* restore original credentials */
947 #endif /* AFS_HPUX101_ENV */
948 crfree(foreigncreds);
951 #endif /* AFS_NEED_CLIENTCONTEXT */
953 #ifdef AFS_LINUX22_ENV
956 AFS_RELE(vp); /* put vnode back */
960 #if defined(KERNEL_HAVE_UERROR)
963 return (getuerror());
969 #define MAXPIOCTLTOKENLEN \
970 (3*sizeof(afs_int32)+MAXKTCTICKETLEN+sizeof(struct ClearToken)+MAXKTCREALMLEN)
973 afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
974 register struct afs_ioctl *ablob, int afollow,
975 struct AFS_UCRED **acred)
978 struct vrequest treq;
979 register afs_int32 code;
980 register afs_int32 function, device;
981 afs_int32 inSize, outSize, outSizeMax;
982 char *inData, *outData;
983 int (*(*pioctlSw)) ();
985 struct afs_fakestat_state fakestate;
987 avc = avp ? VTOAFS(avp) : NULL;
988 afs_Trace3(afs_iclSetp, CM_TRACE_PIOCTL, ICL_TYPE_INT32, acom & 0xff,
989 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, afollow);
990 AFS_STATCNT(HandlePioctl);
991 if ((code = afs_InitReq(&treq, *acred)))
993 afs_InitFakeStat(&fakestate);
995 code = afs_EvalFakeStat(&avc, &fakestate, &treq);
997 afs_PutFakeStat(&fakestate);
1001 device = (acom & 0xff00) >> 8;
1003 case 'V': /* Original pioctls */
1004 pioctlSw = VpioctlSw;
1005 pioctlSwSize = sizeof(VpioctlSw);
1007 case 'C': /* Coordinated/common pioctls */
1008 pioctlSw = CpioctlSw;
1009 pioctlSwSize = sizeof(CpioctlSw);
1011 case 'O': /* Coordinated/common pioctls */
1012 pioctlSw = OpioctlSw;
1013 pioctlSwSize = sizeof(OpioctlSw);
1016 afs_PutFakeStat(&fakestate);
1019 function = acom & 0xff;
1020 if (function >= (pioctlSwSize / sizeof(char *))) {
1021 afs_PutFakeStat(&fakestate);
1022 return EINVAL; /* out of range */
1024 inSize = ablob->in_size;
1026 /* Do all range checking before continuing */
1027 if (inSize > MAXPIOCTLTOKENLEN || inSize < 0 || ablob->out_size < 0)
1030 /* Note that we use osi_Alloc for large allocs and osi_AllocLargeSpace for small ones */
1031 if (inSize > AFS_LRALLOCSIZ) {
1032 inData = osi_Alloc(inSize + 1);
1034 inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1039 AFS_COPYIN(ablob->in, inData, inSize, code);
1040 inData[inSize] = '\0';
1044 if (inSize > AFS_LRALLOCSIZ) {
1045 osi_Free(inData, inSize + 1);
1047 osi_FreeLargeSpace(inData);
1049 afs_PutFakeStat(&fakestate);
1052 if (function == 8 && device == 'V') { /* PGetTokens */
1053 outSizeMax = MAXPIOCTLTOKENLEN;
1054 outData = osi_Alloc(outSizeMax);
1056 outSizeMax = AFS_LRALLOCSIZ;
1057 outData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1060 if (inSize > AFS_LRALLOCSIZ) {
1061 osi_Free(inData, inSize + 1);
1063 osi_FreeLargeSpace(inData);
1065 afs_PutFakeStat(&fakestate);
1070 (*pioctlSw[function]) (avc, function, &treq, inData, outData, inSize,
1072 if (inSize > AFS_LRALLOCSIZ) {
1073 osi_Free(inData, inSize + 1);
1075 osi_FreeLargeSpace(inData);
1077 if (code == 0 && ablob->out_size > 0) {
1078 if (outSize > ablob->out_size) {
1079 code = E2BIG; /* data wont fit in user buffer */
1080 } else if (outSize) {
1081 AFS_COPYOUT(outData, ablob->out, outSize, code);
1084 if (outSizeMax > AFS_LRALLOCSIZ) {
1085 osi_Free(outData, outSizeMax);
1087 osi_FreeLargeSpace(outData);
1089 afs_PutFakeStat(&fakestate);
1090 return afs_CheckCode(code, &treq, 41);
1093 DECL_PIOCTL(PGetFID)
1095 AFS_STATCNT(PGetFID);
1098 memcpy(aout, (char *)&avc->fid, sizeof(struct VenusFid));
1099 *aoutSize = sizeof(struct VenusFid);
1103 DECL_PIOCTL(PSetAcl)
1105 register afs_int32 code;
1107 struct AFSOpaque acl;
1108 struct AFSVolSync tsync;
1109 struct AFSFetchStatus OutStatus;
1112 AFS_STATCNT(PSetAcl);
1115 if ((acl.AFSOpaque_len = strlen(ain) + 1) > 1024 /* AFSOPAQUEMAX */)
1118 acl.AFSOpaque_val = ain;
1120 tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1122 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREACL);
1125 RXAFS_StoreACL(tconn->id, (struct AFSFid *)&avc->fid.Fid,
1126 &acl, &OutStatus, &tsync);
1131 } while (afs_Analyze
1132 (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_STOREACL,
1133 SHARED_LOCK, NULL));
1135 /* now we've forgotten all of the access info */
1136 ObtainWriteLock(&afs_xcbhash, 455);
1138 afs_DequeueCallback(avc);
1139 avc->states &= ~(CStatd | CUnique);
1140 ReleaseWriteLock(&afs_xcbhash);
1141 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
1142 osi_dnlc_purgedp(avc);
1146 int afs_defaultAsynchrony = 0;
1148 DECL_PIOCTL(PStoreBehind)
1151 struct sbstruct *sbr;
1153 sbr = (struct sbstruct *)ain;
1154 if (sbr->sb_default != -1) {
1155 if (afs_osi_suser(*acred))
1156 afs_defaultAsynchrony = sbr->sb_default;
1161 if (avc && (sbr->sb_thisfile != -1)) {
1163 (avc, PRSFS_WRITE | PRSFS_ADMINISTER, areq, DONT_CHECK_MODE_BITS))
1164 avc->asynchrony = sbr->sb_thisfile;
1169 *aoutSize = sizeof(struct sbstruct);
1170 sbr = (struct sbstruct *)aout;
1171 sbr->sb_default = afs_defaultAsynchrony;
1173 sbr->sb_thisfile = avc->asynchrony;
1179 DECL_PIOCTL(PGCPAGs)
1181 if (!afs_osi_suser(*acred)) {
1184 afs_gcpags = AFS_GCPAGS_USERDISABLED;
1188 DECL_PIOCTL(PGetAcl)
1190 struct AFSOpaque acl;
1191 struct AFSVolSync tsync;
1192 struct AFSFetchStatus OutStatus;
1198 AFS_STATCNT(PGetAcl);
1201 Fid.Volume = avc->fid.Fid.Volume;
1202 Fid.Vnode = avc->fid.Fid.Vnode;
1203 Fid.Unique = avc->fid.Fid.Unique;
1204 if (avc->states & CForeign) {
1206 * For a dfs xlator acl we have a special hack so that the
1207 * xlator will distinguish which type of acl will return. So
1208 * we currently use the top 2-bytes (vals 0-4) to tell which
1209 * type of acl to bring back. Horrible hack but this will
1210 * cause the least number of changes to code size and interfaces.
1212 if (Fid.Vnode & 0xc0000000)
1214 Fid.Vnode |= (ainSize << 30);
1216 acl.AFSOpaque_val = aout;
1218 tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1221 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHACL);
1223 code = RXAFS_FetchACL(tconn->id, &Fid, &acl, &OutStatus, &tsync);
1228 } while (afs_Analyze
1229 (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_FETCHACL,
1230 SHARED_LOCK, NULL));
1233 *aoutSize = (acl.AFSOpaque_len == 0 ? 1 : acl.AFSOpaque_len);
1246 AFS_STATCNT(PBogus);
1250 DECL_PIOCTL(PGetFileCell)
1252 register struct cell *tcell;
1254 AFS_STATCNT(PGetFileCell);
1257 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
1260 strcpy(aout, tcell->cellName);
1261 afs_PutCell(tcell, READ_LOCK);
1262 *aoutSize = strlen(aout) + 1;
1266 DECL_PIOCTL(PGetWSCell)
1268 struct cell *tcell = NULL;
1270 AFS_STATCNT(PGetWSCell);
1271 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1272 return EIO; /* Inappropriate ioctl for device */
1274 tcell = afs_GetPrimaryCell(READ_LOCK);
1275 if (!tcell) /* no primary cell? */
1277 strcpy(aout, tcell->cellName);
1278 *aoutSize = strlen(aout) + 1;
1279 afs_PutCell(tcell, READ_LOCK);
1283 DECL_PIOCTL(PGetUserCell)
1285 register afs_int32 i;
1286 register struct unixuser *tu;
1287 register struct cell *tcell;
1289 AFS_STATCNT(PGetUserCell);
1290 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1291 return EIO; /* Inappropriate ioctl for device */
1293 /* return the cell name of the primary cell for this user */
1294 i = UHash(areq->uid);
1295 ObtainWriteLock(&afs_xuser, 224);
1296 for (tu = afs_users[i]; tu; tu = tu->next) {
1297 if (tu->uid == areq->uid && (tu->states & UPrimary)) {
1299 ReleaseWriteLock(&afs_xuser);
1304 tcell = afs_GetCell(tu->cell, READ_LOCK);
1305 afs_PutUser(tu, WRITE_LOCK);
1309 strcpy(aout, tcell->cellName);
1310 afs_PutCell(tcell, READ_LOCK);
1311 *aoutSize = strlen(aout) + 1; /* 1 for the null */
1314 ReleaseWriteLock(&afs_xuser);
1321 DECL_PIOCTL(PSetTokens)
1324 register struct unixuser *tu;
1325 struct ClearToken clear;
1326 register struct cell *tcell;
1329 struct vrequest treq;
1330 afs_int32 flag, set_parent_pag = 0;
1332 AFS_STATCNT(PSetTokens);
1333 if (!afs_resourceinit_flag) {
1336 memcpy((char *)&i, ain, sizeof(afs_int32));
1337 ain += sizeof(afs_int32);
1338 stp = ain; /* remember where the ticket is */
1339 if (i < 0 || i > MAXKTCTICKETLEN)
1340 return EINVAL; /* malloc may fail */
1342 ain += i; /* skip over ticket */
1343 memcpy((char *)&i, ain, sizeof(afs_int32));
1344 ain += sizeof(afs_int32);
1345 if (i != sizeof(struct ClearToken)) {
1348 memcpy((char *)&clear, ain, sizeof(struct ClearToken));
1349 if (clear.AuthHandle == -1)
1350 clear.AuthHandle = 999; /* more rxvab compat stuff */
1351 ain += sizeof(struct ClearToken);
1352 if (ainSize != 2 * sizeof(afs_int32) + stLen + sizeof(struct ClearToken)) {
1353 /* still stuff left? we've got primary flag and cell name. Set these */
1354 memcpy((char *)&flag, ain, sizeof(afs_int32)); /* primary id flag */
1355 ain += sizeof(afs_int32); /* skip id field */
1356 /* rest is cell name, look it up */
1357 /* some versions of gcc appear to need != 0 in order to get this right */
1358 if ((flag & 0x8000) != 0) { /* XXX Use Constant XXX */
1362 tcell = afs_GetCellByName(ain, READ_LOCK);
1366 /* default to primary cell, primary id */
1367 flag = 1; /* primary id */
1368 tcell = afs_GetPrimaryCell(READ_LOCK);
1373 afs_PutCell(tcell, READ_LOCK);
1374 if (set_parent_pag) {
1376 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1377 #if defined(AFS_DARWIN_ENV)
1378 struct proc *p = current_proc(); /* XXX */
1380 struct proc *p = curproc; /* XXX */
1382 #ifndef AFS_DARWIN80_ENV
1383 uprintf("Process %d (%s) tried to change pags in PSetTokens\n",
1384 p->p_pid, p->p_comm);
1386 if (!setpag(p, acred, -1, &pag, 1)) {
1389 if (!setpag(u.u_procp, acred, -1, &pag, 1)) { /* XXX u.u_procp is a no-op XXX */
1391 if (!setpag(acred, -1, &pag, 1)) {
1394 afs_InitReq(&treq, *acred);
1398 /* now we just set the tokens */
1399 tu = afs_GetUser(areq->uid, i, WRITE_LOCK); /* i has the cell # */
1400 tu->vid = clear.ViceId;
1401 if (tu->stp != NULL) {
1402 afs_osi_Free(tu->stp, tu->stLen);
1404 tu->stp = (char *)afs_osi_Alloc(stLen);
1406 memcpy(tu->stp, stp, stLen);
1409 afs_stats_cmfullperf.authent.TicketUpdates++;
1410 afs_ComputePAGStats();
1411 #endif /* AFS_NOSTATS */
1412 tu->states |= UHasTokens;
1413 tu->states &= ~UTokensBad;
1414 afs_SetPrimary(tu, flag);
1415 tu->tokenTime = osi_Time();
1416 afs_ResetUserConns(tu);
1417 afs_PutUser(tu, WRITE_LOCK);
1432 DECL_PIOCTL(PGetVolumeStatus)
1435 char *offLineMsg = afs_osi_Alloc(256);
1436 char *motd = afs_osi_Alloc(256);
1437 register struct conn *tc;
1438 register afs_int32 code = 0;
1439 struct AFSFetchVolumeStatus volstat;
1441 char *Name, *OfflineMsg, *MOTD;
1444 AFS_STATCNT(PGetVolumeStatus);
1450 OfflineMsg = offLineMsg;
1453 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1455 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS);
1458 RXAFS_GetVolumeStatus(tc->id, avc->fid.Fid.Volume, &volstat,
1459 &Name, &OfflineMsg, &MOTD);
1464 } while (afs_Analyze
1465 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS,
1466 SHARED_LOCK, NULL));
1470 /* Copy all this junk into msg->im_data, keeping track of the lengths. */
1472 memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
1473 cp += sizeof(VolumeStatus);
1474 strcpy(cp, volName);
1475 cp += strlen(volName) + 1;
1476 strcpy(cp, offLineMsg);
1477 cp += strlen(offLineMsg) + 1;
1479 cp += strlen(motd) + 1;
1480 *aoutSize = (cp - aout);
1482 afs_osi_Free(offLineMsg, 256);
1483 afs_osi_Free(motd, 256);
1487 DECL_PIOCTL(PSetVolumeStatus)
1490 char *offLineMsg = afs_osi_Alloc(256);
1491 char *motd = afs_osi_Alloc(256);
1492 register struct conn *tc;
1493 register afs_int32 code = 0;
1494 struct AFSFetchVolumeStatus volstat;
1495 struct AFSStoreVolumeStatus storeStat;
1496 register struct volume *tvp;
1500 AFS_STATCNT(PSetVolumeStatus);
1506 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
1508 if (tvp->states & (VRO | VBackup)) {
1509 afs_PutVolume(tvp, READ_LOCK);
1513 afs_PutVolume(tvp, READ_LOCK);
1518 /* Copy the junk out, using cp as a roving pointer. */
1520 memcpy((char *)&volstat, cp, sizeof(AFSFetchVolumeStatus));
1521 cp += sizeof(AFSFetchVolumeStatus);
1522 if (strlen(cp) >= sizeof(volName)) {
1526 strcpy(volName, cp);
1527 cp += strlen(volName) + 1;
1528 if (strlen(cp) >= sizeof(offLineMsg)) {
1532 strcpy(offLineMsg, cp);
1533 cp += strlen(offLineMsg) + 1;
1534 if (strlen(cp) >= sizeof(motd)) {
1540 if (volstat.MinQuota != -1) {
1541 storeStat.MinQuota = volstat.MinQuota;
1542 storeStat.Mask |= AFS_SETMINQUOTA;
1544 if (volstat.MaxQuota != -1) {
1545 storeStat.MaxQuota = volstat.MaxQuota;
1546 storeStat.Mask |= AFS_SETMAXQUOTA;
1549 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1551 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS);
1554 RXAFS_SetVolumeStatus(tc->id, avc->fid.Fid.Volume, &storeStat,
1555 volName, offLineMsg, motd);
1560 } while (afs_Analyze
1561 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS,
1562 SHARED_LOCK, NULL));
1566 /* we are sending parms back to make compat. with prev system. should
1567 * change interface later to not ask for current status, just set new status */
1569 memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
1570 cp += sizeof(VolumeStatus);
1571 strcpy(cp, volName);
1572 cp += strlen(volName) + 1;
1573 strcpy(cp, offLineMsg);
1574 cp += strlen(offLineMsg) + 1;
1576 cp += strlen(motd) + 1;
1577 *aoutSize = cp - aout;
1579 afs_osi_Free(offLineMsg, 256);
1580 afs_osi_Free(motd, 256);
1586 AFS_STATCNT(PFlush);
1589 #ifdef AFS_BOZONLOCK_ENV
1590 afs_BozonLock(&avc->pvnLock, avc); /* Since afs_TryToSmush will do a pvn_vptrunc */
1592 ObtainWriteLock(&avc->lock, 225);
1593 ObtainWriteLock(&afs_xcbhash, 456);
1594 afs_DequeueCallback(avc);
1595 avc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
1596 ReleaseWriteLock(&afs_xcbhash);
1597 /* now find the disk cache entries */
1598 afs_TryToSmush(avc, *acred, 1);
1599 osi_dnlc_purgedp(avc);
1600 if (avc->linkData && !(avc->states & CCore)) {
1601 afs_osi_Free(avc->linkData, strlen(avc->linkData) + 1);
1602 avc->linkData = NULL;
1604 ReleaseWriteLock(&avc->lock);
1605 #ifdef AFS_BOZONLOCK_ENV
1606 afs_BozonUnlock(&avc->pvnLock, avc);
1611 DECL_PIOCTL(PNewStatMount)
1613 register afs_int32 code;
1614 register struct vcache *tvc;
1615 register struct dcache *tdc;
1616 struct VenusFid tfid;
1618 struct sysname_info sysState;
1619 afs_size_t offset, len;
1621 AFS_STATCNT(PNewStatMount);
1624 code = afs_VerifyVCache(avc, areq);
1627 if (vType(avc) != VDIR) {
1630 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
1633 Check_AtSys(avc, ain, &sysState, areq);
1634 ObtainReadLock(&tdc->lock);
1636 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
1637 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
1638 ReleaseReadLock(&tdc->lock);
1639 afs_PutDCache(tdc); /* we're done with the data */
1640 bufp = sysState.name;
1644 tfid.Cell = avc->fid.Cell;
1645 tfid.Fid.Volume = avc->fid.Fid.Volume;
1646 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
1647 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
1649 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
1655 if (tvc->mvstat != 1) {
1660 ObtainWriteLock(&tvc->lock, 226);
1661 code = afs_HandleLink(tvc, areq);
1663 if (tvc->linkData) {
1664 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
1667 /* we have the data */
1668 strcpy(aout, tvc->linkData);
1669 *aoutSize = strlen(tvc->linkData) + 1;
1674 ReleaseWriteLock(&tvc->lock);
1677 if (sysState.allocked)
1678 osi_FreeLargeSpace(bufp);
1682 DECL_PIOCTL(PGetTokens)
1684 register struct cell *tcell;
1685 register afs_int32 i;
1686 register struct unixuser *tu;
1691 AFS_STATCNT(PGetTokens);
1692 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1693 return EIO; /* Inappropriate ioctl for device */
1695 /* weird interface. If input parameter is present, it is an integer and
1696 * we're supposed to return the parm'th tokens for this unix uid.
1697 * If not present, we just return tokens for cell 1.
1698 * If counter out of bounds, return EDOM.
1699 * If no tokens for the particular cell, return ENOTCONN.
1700 * Also, if this mysterious parm is present, we return, along with the
1701 * tokens, the primary cell indicator (an afs_int32 0) and the cell name
1702 * at the end, in that order.
1704 if ((newStyle = (ainSize > 0))) {
1705 memcpy((char *)&iterator, ain, sizeof(afs_int32));
1707 i = UHash(areq->uid);
1708 ObtainReadLock(&afs_xuser);
1709 for (tu = afs_users[i]; tu; tu = tu->next) {
1711 if (tu->uid == areq->uid && (tu->states & UHasTokens)) {
1712 if (iterator-- == 0)
1713 break; /* are we done yet? */
1716 if (tu->uid == areq->uid && afs_IsPrimaryCellNum(tu->cell))
1722 * No need to hold a read lock on each user entry
1726 ReleaseReadLock(&afs_xuser);
1731 if (((tu->states & UHasTokens) == 0)
1732 || (tu->ct.EndTimestamp < osi_Time())) {
1733 tu->states |= (UTokensBad | UNeedsReset);
1734 afs_PutUser(tu, READ_LOCK);
1737 /* use iterator for temp */
1739 iterator = tu->stLen; /* for compat, we try to return 56 byte tix if they fit */
1741 iterator = 56; /* # of bytes we're returning */
1742 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1743 cp += sizeof(afs_int32);
1744 memcpy(cp, tu->stp, tu->stLen); /* copy out st */
1746 iterator = sizeof(struct ClearToken);
1747 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1748 cp += sizeof(afs_int32);
1749 memcpy(cp, (char *)&tu->ct, sizeof(struct ClearToken));
1750 cp += sizeof(struct ClearToken);
1752 /* put out primary id and cell name, too */
1753 iterator = (tu->states & UPrimary ? 1 : 0);
1754 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1755 cp += sizeof(afs_int32);
1756 tcell = afs_GetCell(tu->cell, READ_LOCK);
1758 strcpy(cp, tcell->cellName);
1759 cp += strlen(tcell->cellName) + 1;
1760 afs_PutCell(tcell, READ_LOCK);
1764 *aoutSize = cp - aout;
1765 afs_PutUser(tu, READ_LOCK);
1771 register afs_int32 i;
1772 register struct unixuser *tu;
1774 AFS_STATCNT(PUnlog);
1775 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1776 return EIO; /* Inappropriate ioctl for device */
1778 i = UHash(areq->uid);
1779 ObtainWriteLock(&afs_xuser, 227);
1780 for (tu = afs_users[i]; tu; tu = tu->next) {
1781 if (tu->uid == areq->uid) {
1783 tu->states &= ~UHasTokens;
1784 /* security is not having to say you're sorry */
1785 memset((char *)&tu->ct, 0, sizeof(struct ClearToken));
1787 ReleaseWriteLock(&afs_xuser);
1788 /* We have to drop the lock over the call to afs_ResetUserConns, since
1789 * it obtains the afs_xvcache lock. We could also keep the lock, and
1790 * modify ResetUserConns to take parm saying we obtained the lock
1791 * already, but that is overkill. By keeping the "tu" pointer
1792 * held over the released lock, we guarantee that we won't lose our
1793 * place, and that we'll pass over every user conn that existed when
1794 * we began this call.
1796 afs_ResetUserConns(tu);
1798 ObtainWriteLock(&afs_xuser, 228);
1800 /* set the expire times to 0, causes
1801 * afs_GCUserData to remove this entry
1803 tu->ct.EndTimestamp = 0;
1805 #endif /* UKERNEL */
1808 ReleaseWriteLock(&afs_xuser);
1812 DECL_PIOCTL(PMariner)
1814 afs_int32 newHostAddr;
1815 afs_int32 oldHostAddr;
1817 AFS_STATCNT(PMariner);
1819 memcpy((char *)&oldHostAddr, (char *)&afs_marinerHost,
1822 oldHostAddr = 0xffffffff; /* disabled */
1824 memcpy((char *)&newHostAddr, ain, sizeof(afs_int32));
1825 if (newHostAddr == 0xffffffff) {
1826 /* disable mariner operations */
1828 } else if (newHostAddr) {
1830 afs_marinerHost = newHostAddr;
1832 memcpy(aout, (char *)&oldHostAddr, sizeof(afs_int32));
1833 *aoutSize = sizeof(afs_int32);
1837 DECL_PIOCTL(PCheckServers)
1839 register char *cp = 0;
1841 register struct server *ts;
1842 afs_int32 temp, *lp = (afs_int32 *) ain, havecell = 0;
1844 struct chservinfo *pcheck;
1846 AFS_STATCNT(PCheckServers);
1848 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1849 return EIO; /* Inappropriate ioctl for device */
1851 if (*lp == 0x12345678) { /* For afs3.3 version */
1852 pcheck = (struct chservinfo *)ain;
1853 if (pcheck->tinterval >= 0) {
1855 memcpy(cp, (char *)&afs_probe_interval, sizeof(afs_int32));
1856 *aoutSize = sizeof(afs_int32);
1857 if (pcheck->tinterval > 0) {
1858 if (!afs_osi_suser(*acred))
1860 afs_probe_interval = pcheck->tinterval;
1866 temp = pcheck->tflags;
1867 cp = pcheck->tbuffer;
1868 } else { /* For pre afs3.3 versions */
1869 memcpy((char *)&temp, ain, sizeof(afs_int32));
1870 cp = ain + sizeof(afs_int32);
1871 if (ainSize > sizeof(afs_int32))
1876 * 1: fast check, don't contact servers.
1877 * 2: local cell only.
1880 /* have cell name, too */
1881 cellp = afs_GetCellByName(cp, READ_LOCK);
1886 if (!cellp && (temp & 2)) {
1887 /* use local cell */
1888 cellp = afs_GetPrimaryCell(READ_LOCK);
1890 if (!(temp & 1)) { /* if not fast, call server checker routine */
1891 afs_CheckServers(1, cellp); /* check down servers */
1892 afs_CheckServers(0, cellp); /* check up servers */
1894 /* now return the current down server list */
1896 ObtainReadLock(&afs_xserver);
1897 for (i = 0; i < NSERVERS; i++) {
1898 for (ts = afs_servers[i]; ts; ts = ts->next) {
1899 if (cellp && ts->cell != cellp)
1900 continue; /* cell spec'd and wrong */
1901 if ((ts->flags & SRVR_ISDOWN)
1902 && ts->addr->sa_portal != ts->cell->vlport) {
1903 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
1904 cp += sizeof(afs_int32);
1908 ReleaseReadLock(&afs_xserver);
1910 afs_PutCell(cellp, READ_LOCK);
1911 *aoutSize = cp - aout;
1915 DECL_PIOCTL(PCheckVolNames)
1917 AFS_STATCNT(PCheckVolNames);
1918 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1919 return EIO; /* Inappropriate ioctl for device */
1921 afs_CheckRootVolume();
1922 afs_CheckVolumeNames(AFS_VOLCHECK_FORCE | AFS_VOLCHECK_EXPIRED |
1923 AFS_VOLCHECK_BUSY | AFS_VOLCHECK_MTPTS);
1927 DECL_PIOCTL(PCheckAuth)
1932 struct unixuser *tu;
1935 AFS_STATCNT(PCheckAuth);
1936 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1937 return EIO; /* Inappropriate ioctl for device */
1940 tu = afs_GetUser(areq->uid, 1, READ_LOCK); /* check local cell authentication */
1944 /* we have a user */
1945 ObtainReadLock(&afs_xsrvAddr);
1946 ObtainReadLock(&afs_xconn);
1948 /* any tokens set? */
1949 if ((tu->states & UHasTokens) == 0)
1951 /* all connections in cell 1 working? */
1952 for (i = 0; i < NSERVERS; i++) {
1953 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
1954 for (tc = sa->conns; tc; tc = tc->next) {
1955 if (tc->user == tu && (tu->states & UTokensBad))
1960 ReleaseReadLock(&afs_xsrvAddr);
1961 ReleaseReadLock(&afs_xconn);
1962 afs_PutUser(tu, READ_LOCK);
1964 memcpy(aout, (char *)&retValue, sizeof(afs_int32));
1965 *aoutSize = sizeof(afs_int32);
1970 Prefetch(char *apath, struct afs_ioctl *adata, int afollow,
1971 struct AFS_UCRED *acred)
1974 register afs_int32 code;
1975 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1981 AFS_STATCNT(Prefetch);
1984 tp = osi_AllocLargeSpace(1024);
1985 AFS_COPYINSTR(apath, tp, 1024, &bufferSize, code);
1987 osi_FreeLargeSpace(tp);
1990 if (afs_BBusy()) { /* do this as late as possible */
1991 osi_FreeLargeSpace(tp);
1992 return EWOULDBLOCK; /* pretty close */
1994 afs_BQueue(BOP_PATH, (struct vcache *)0, 0, 0, acred, (afs_size_t) 0,
1995 (afs_size_t) 0, tp);
1999 DECL_PIOCTL(PFindVolume)
2001 register struct volume *tvp;
2002 register struct server *ts;
2003 register afs_int32 i;
2006 AFS_STATCNT(PFindVolume);
2009 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
2012 for (i = 0; i < MAXHOSTS; i++) {
2013 ts = tvp->serverHost[i];
2016 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
2017 cp += sizeof(afs_int32);
2020 /* still room for terminating NULL, add it on */
2021 ainSize = 0; /* reuse vbl */
2022 memcpy(cp, (char *)&ainSize, sizeof(afs_int32));
2023 cp += sizeof(afs_int32);
2025 *aoutSize = cp - aout;
2026 afs_PutVolume(tvp, READ_LOCK);
2032 DECL_PIOCTL(PViceAccess)
2034 register afs_int32 code;
2037 AFS_STATCNT(PViceAccess);
2040 code = afs_VerifyVCache(avc, areq);
2043 memcpy((char *)&temp, ain, sizeof(afs_int32));
2044 code = afs_AccessOK(avc, temp, areq, CHECK_MODE_BITS);
2051 DECL_PIOCTL(PSetCacheSize)
2056 AFS_STATCNT(PSetCacheSize);
2057 if (!afs_osi_suser(*acred))
2059 /* too many things are setup initially in mem cache version */
2060 if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
2062 memcpy((char *)&newValue, ain, sizeof(afs_int32));
2064 afs_cacheBlocks = afs_stats_cmperf.cacheBlocksOrig;
2066 if (newValue < afs_min_cache)
2067 afs_cacheBlocks = afs_min_cache;
2069 afs_cacheBlocks = newValue;
2071 afs_stats_cmperf.cacheBlocksTotal = afs_cacheBlocks;
2072 afs_ComputeCacheParms(); /* recompute basic cache parameters */
2073 afs_MaybeWakeupTruncateDaemon();
2074 while (waitcnt++ < 100 && afs_cacheBlocks < afs_blocksUsed) {
2075 afs_osi_Wait(1000, 0, 0);
2076 afs_MaybeWakeupTruncateDaemon();
2081 #define MAXGCSTATS 16
2082 DECL_PIOCTL(PGetCacheSize)
2084 afs_int32 results[MAXGCSTATS];
2086 register struct dcache * tdc;
2089 AFS_STATCNT(PGetCacheSize);
2091 if (sizeof(afs_int32) == ainSize){
2092 memcpy((char *)&flags, ain, sizeof(afs_int32));
2093 } else if (0 == ainSize){
2099 memset((char *)results, 0, sizeof(results));
2100 results[0] = afs_cacheBlocks;
2101 results[1] = afs_blocksUsed;
2102 results[2] = afs_cacheFiles;
2105 for (i = 0; i < afs_cacheFiles; i++) {
2106 if (afs_indexFlags[i] & IFFree) results[3]++;
2108 } else if (2 == flags){
2109 for (i = 0; i < afs_cacheFiles; i++) {
2110 if (afs_indexFlags[i] & IFFree) results[3]++;
2111 if (afs_indexFlags[i] & IFEverUsed) results[4]++;
2112 if (afs_indexFlags[i] & IFDataMod) results[5]++;
2113 if (afs_indexFlags[i] & IFDirtyPages) results[6]++;
2114 if (afs_indexFlags[i] & IFAnyPages) results[7]++;
2115 if (afs_indexFlags[i] & IFDiscarded) results[8]++;
2117 tdc = afs_indexTable[i];
2120 size = tdc->validPos;
2121 if ( 0 < size && size < (1<<12) ) results[10]++;
2122 else if (size < (1<<14) ) results[11]++;
2123 else if (size < (1<<16) ) results[12]++;
2124 else if (size < (1<<18) ) results[13]++;
2125 else if (size < (1<<20) ) results[14]++;
2126 else if (size >= (1<<20) ) results[15]++;
2130 memcpy(aout, (char *)results, sizeof(results));
2131 *aoutSize = sizeof(results);
2135 DECL_PIOCTL(PRemoveCallBack)
2137 register struct conn *tc;
2138 register afs_int32 code = 0;
2139 struct AFSCallBack CallBacks_Array[1];
2140 struct AFSCBFids theFids;
2141 struct AFSCBs theCBs;
2144 AFS_STATCNT(PRemoveCallBack);
2147 if (avc->states & CRO)
2148 return 0; /* read-only-ness can't change */
2149 ObtainWriteLock(&avc->lock, 229);
2150 theFids.AFSCBFids_len = 1;
2151 theCBs.AFSCBs_len = 1;
2152 theFids.AFSCBFids_val = (struct AFSFid *)&avc->fid.Fid;
2153 theCBs.AFSCBs_val = CallBacks_Array;
2154 CallBacks_Array[0].CallBackType = CB_DROPPED;
2155 if (avc->callback) {
2157 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2159 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
2161 code = RXAFS_GiveUpCallBacks(tc->id, &theFids, &theCBs);
2165 /* don't set code on failure since we wouldn't use it */
2166 } while (afs_Analyze
2167 (tc, code, &avc->fid, areq,
2168 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK, NULL));
2170 ObtainWriteLock(&afs_xcbhash, 457);
2171 afs_DequeueCallback(avc);
2173 avc->states &= ~(CStatd | CUnique);
2174 ReleaseWriteLock(&afs_xcbhash);
2175 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
2176 osi_dnlc_purgedp(avc);
2178 ReleaseWriteLock(&avc->lock);
2182 DECL_PIOCTL(PNewCell)
2184 /* create a new cell */
2185 afs_int32 cellHosts[MAXCELLHOSTS], *lp, magic = 0;
2186 char *newcell = 0, *linkedcell = 0, *tp = ain;
2187 register afs_int32 code, linkedstate = 0, ls;
2188 u_short fsport = 0, vlport = 0;
2191 AFS_STATCNT(PNewCell);
2192 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2193 return EIO; /* Inappropriate ioctl for device */
2195 if (!afs_osi_suser(*acred))
2198 memcpy((char *)&magic, tp, sizeof(afs_int32));
2199 tp += sizeof(afs_int32);
2200 if (magic != 0x12345678)
2203 /* A 3.4 fs newcell command will pass an array of MAXCELLHOSTS
2204 * server addresses while the 3.5 fs newcell command passes
2205 * MAXHOSTS. To figure out which is which, check if the cellname
2208 newcell = tp + (MAXCELLHOSTS + 3) * sizeof(afs_int32);
2209 scount = ((newcell[0] != '\0') ? MAXCELLHOSTS : MAXHOSTS);
2211 /* MAXCELLHOSTS (=8) is less than MAXHOSTS (=13) */
2212 memcpy((char *)cellHosts, tp, MAXCELLHOSTS * sizeof(afs_int32));
2213 tp += (scount * sizeof(afs_int32));
2215 lp = (afs_int32 *) tp;
2219 fsport = 0; /* Privileged ports not allowed */
2221 vlport = 0; /* Privileged ports not allowed */
2222 tp += (3 * sizeof(afs_int32));
2224 if ((ls = *lp) & 1) {
2225 linkedcell = tp + strlen(newcell) + 1;
2226 linkedstate |= CLinkedCell;
2229 linkedstate |= CNoSUID; /* setuid is disabled by default for fs newcell */
2231 afs_NewCell(newcell, cellHosts, linkedstate, linkedcell, fsport,
2236 DECL_PIOCTL(PNewAlias)
2238 /* create a new cell alias */
2240 register afs_int32 code;
2241 char *realName, *aliasName;
2243 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2244 return EIO; /* Inappropriate ioctl for device */
2246 if (!afs_osi_suser(*acred))
2250 tp += strlen(aliasName) + 1;
2253 code = afs_NewCellAlias(aliasName, realName);
2258 DECL_PIOCTL(PListCells)
2260 afs_int32 whichCell;
2261 register struct cell *tcell = 0;
2262 register afs_int32 i;
2263 register char *cp, *tp = ain;
2265 AFS_STATCNT(PListCells);
2266 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2267 return EIO; /* Inappropriate ioctl for device */
2269 memcpy((char *)&whichCell, tp, sizeof(afs_int32));
2270 tp += sizeof(afs_int32);
2271 tcell = afs_GetCellByIndex(whichCell, READ_LOCK);
2274 memset(cp, 0, MAXCELLHOSTS * sizeof(afs_int32));
2275 for (i = 0; i < MAXCELLHOSTS; i++) {
2276 if (tcell->cellHosts[i] == 0)
2278 memcpy(cp, (char *)&tcell->cellHosts[i]->addr->sa_ip,
2280 cp += sizeof(afs_int32);
2282 cp = aout + MAXCELLHOSTS * sizeof(afs_int32);
2283 strcpy(cp, tcell->cellName);
2284 cp += strlen(tcell->cellName) + 1;
2285 *aoutSize = cp - aout;
2286 afs_PutCell(tcell, READ_LOCK);
2294 DECL_PIOCTL(PListAliases)
2296 afs_int32 whichAlias;
2297 register struct cell_alias *tcalias = 0;
2298 register char *cp, *tp = ain;
2300 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2301 return EIO; /* Inappropriate ioctl for device */
2302 if (ainSize < sizeof(afs_int32))
2305 memcpy((char *)&whichAlias, tp, sizeof(afs_int32));
2306 tp += sizeof(afs_int32);
2308 tcalias = afs_GetCellAlias(whichAlias);
2311 strcpy(cp, tcalias->alias);
2312 cp += strlen(tcalias->alias) + 1;
2313 strcpy(cp, tcalias->cell);
2314 cp += strlen(tcalias->cell) + 1;
2315 *aoutSize = cp - aout;
2316 afs_PutCellAlias(tcalias);
2324 DECL_PIOCTL(PRemoveMount)
2326 register afs_int32 code;
2328 struct sysname_info sysState;
2329 afs_size_t offset, len;
2330 register struct conn *tc;
2331 register struct dcache *tdc;
2332 register struct vcache *tvc;
2333 struct AFSFetchStatus OutDirStatus;
2334 struct VenusFid tfid;
2335 struct AFSVolSync tsync;
2339 /* "ain" is the name of the file in this dir to remove */
2341 AFS_STATCNT(PRemoveMount);
2344 code = afs_VerifyVCache(avc, areq);
2347 if (vType(avc) != VDIR)
2350 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1); /* test for error below */
2353 Check_AtSys(avc, ain, &sysState, areq);
2354 ObtainReadLock(&tdc->lock);
2356 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
2357 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
2358 ReleaseReadLock(&tdc->lock);
2359 bufp = sysState.name;
2364 tfid.Cell = avc->fid.Cell;
2365 tfid.Fid.Volume = avc->fid.Fid.Volume;
2366 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
2367 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
2369 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
2376 if (tvc->mvstat != 1) {
2382 ObtainWriteLock(&tvc->lock, 230);
2383 code = afs_HandleLink(tvc, areq);
2385 if (tvc->linkData) {
2386 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
2391 ReleaseWriteLock(&tvc->lock);
2392 osi_dnlc_purgedp(tvc);
2398 ObtainWriteLock(&avc->lock, 231);
2399 osi_dnlc_remove(avc, bufp, tvc);
2401 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2403 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE);
2406 RXAFS_RemoveFile(tc->id, (struct AFSFid *)&avc->fid.Fid, bufp,
2407 &OutDirStatus, &tsync);
2412 } while (afs_Analyze
2413 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_REMOVEFILE,
2414 SHARED_LOCK, NULL));
2419 ReleaseWriteLock(&avc->lock);
2423 /* we have the thing in the cache */
2424 ObtainWriteLock(&tdc->lock, 661);
2425 if (afs_LocalHero(avc, tdc, &OutDirStatus, 1)) {
2426 /* we can do it locally */
2427 code = afs_dir_Delete(tdc, bufp);
2429 ZapDCE(tdc); /* surprise error -- invalid value */
2433 ReleaseWriteLock(&tdc->lock);
2434 afs_PutDCache(tdc); /* drop ref count */
2436 avc->states &= ~CUnique; /* For the dfs xlator */
2437 ReleaseWriteLock(&avc->lock);
2440 if (sysState.allocked)
2441 osi_FreeLargeSpace(bufp);
2445 DECL_PIOCTL(PVenusLogging)
2447 return EINVAL; /* OBSOLETE */
2450 DECL_PIOCTL(PGetCellStatus)
2452 register struct cell *tcell;
2455 AFS_STATCNT(PGetCellStatus);
2456 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2457 return EIO; /* Inappropriate ioctl for device */
2459 tcell = afs_GetCellByName(ain, READ_LOCK);
2462 temp = tcell->states;
2463 afs_PutCell(tcell, READ_LOCK);
2464 memcpy(aout, (char *)&temp, sizeof(afs_int32));
2465 *aoutSize = sizeof(afs_int32);
2469 DECL_PIOCTL(PSetCellStatus)
2471 register struct cell *tcell;
2474 if (!afs_osi_suser(*acred))
2476 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2477 return EIO; /* Inappropriate ioctl for device */
2479 tcell = afs_GetCellByName(ain + 2 * sizeof(afs_int32), WRITE_LOCK);
2482 memcpy((char *)&temp, ain, sizeof(afs_int32));
2484 tcell->states |= CNoSUID;
2486 tcell->states &= ~CNoSUID;
2487 afs_PutCell(tcell, WRITE_LOCK);
2491 DECL_PIOCTL(PFlushVolumeData)
2493 register afs_int32 i;
2494 register struct dcache *tdc;
2495 register struct vcache *tvc;
2496 register struct volume *tv;
2497 afs_int32 cell, volume;
2498 struct afs_q *tq, *uq;
2499 #ifdef AFS_DARWIN80_ENV
2503 AFS_STATCNT(PFlushVolumeData);
2506 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2507 return EIO; /* Inappropriate ioctl for device */
2509 volume = avc->fid.Fid.Volume; /* who to zap */
2510 cell = avc->fid.Cell;
2513 * Clear stat'd flag from all vnodes from this volume; this will invalidate all
2514 * the vcaches associated with the volume.
2517 ObtainReadLock(&afs_xvcache);
2518 i = VCHashV(&avc->fid);
2519 for (tq = afs_vhashTV[i].prev; tq != &afs_vhashTV[i]; tq = uq) {
2522 if (tvc->fid.Fid.Volume == volume && tvc->fid.Cell == cell) {
2523 if (tvc->states & CVInit) {
2524 ReleaseReadLock(&afs_xvcache);
2525 afs_osi_Sleep(&tvc->states);
2528 #ifdef AFS_DARWIN80_ENV
2529 if (tvc->states & CDeadVnode) {
2530 ReleaseReadLock(&afs_xvcache);
2531 afs_osi_Sleep(&tvc->states);
2535 #if defined(AFS_SGI_ENV) || defined(AFS_OSF_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
2536 VN_HOLD(AFSTOV(tvc));
2538 #ifdef AFS_DARWIN80_ENV
2542 if (vnode_ref(vp)) {
2549 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2552 VREFCOUNT_INC(tvc); /* AIX, apparently */
2556 ReleaseReadLock(&afs_xvcache);
2557 #ifdef AFS_BOZONLOCK_ENV
2558 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
2560 ObtainWriteLock(&tvc->lock, 232);
2562 ObtainWriteLock(&afs_xcbhash, 458);
2563 afs_DequeueCallback(tvc);
2564 tvc->states &= ~(CStatd | CDirty);
2565 ReleaseWriteLock(&afs_xcbhash);
2566 if (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
2567 osi_dnlc_purgedp(tvc);
2568 afs_TryToSmush(tvc, *acred, 1);
2569 ReleaseWriteLock(&tvc->lock);
2570 #ifdef AFS_BOZONLOCK_ENV
2571 afs_BozonUnlock(&tvc->pvnLock, tvc);
2573 #ifdef AFS_DARWIN80_ENV
2574 vnode_put(AFSTOV(tvc));
2576 ObtainReadLock(&afs_xvcache);
2578 /* our tvc ptr is still good until now */
2582 ReleaseReadLock(&afs_xvcache);
2585 MObtainWriteLock(&afs_xdcache, 328); /* needed if you're going to flush any stuff */
2586 for (i = 0; i < afs_cacheFiles; i++) {
2587 if (!(afs_indexFlags[i] & IFEverUsed))
2588 continue; /* never had any data */
2589 tdc = afs_GetDSlot(i, NULL);
2590 if (tdc->refCount <= 1) { /* too high, in use by running sys call */
2591 ReleaseReadLock(&tdc->tlock);
2592 if (tdc->f.fid.Fid.Volume == volume && tdc->f.fid.Cell == cell) {
2593 if (!(afs_indexFlags[i] & IFDataMod)) {
2594 /* if the file is modified, but has a ref cnt of only 1, then
2595 * someone probably has the file open and is writing into it.
2596 * Better to skip flushing such a file, it will be brought back
2597 * immediately on the next write anyway.
2599 * If we *must* flush, then this code has to be rearranged to call
2600 * afs_storeAllSegments() first */
2601 afs_FlushDCache(tdc);
2605 ReleaseReadLock(&tdc->tlock);
2607 afs_PutDCache(tdc); /* bumped by getdslot */
2609 MReleaseWriteLock(&afs_xdcache);
2611 ObtainReadLock(&afs_xvolume);
2612 for (i = 0; i < NVOLS; i++) {
2613 for (tv = afs_volumes[i]; tv; tv = tv->next) {
2614 if (tv->volume == volume) {
2615 afs_ResetVolumeInfo(tv);
2620 ReleaseReadLock(&afs_xvolume);
2622 /* probably, a user is doing this, probably, because things are screwed up.
2623 * maybe it's the dnlc's fault? */
2630 DECL_PIOCTL(PGetVnodeXStatus)
2632 register afs_int32 code;
2633 struct vcxstat stat;
2636 /* AFS_STATCNT(PGetVnodeXStatus); */
2639 code = afs_VerifyVCache(avc, areq);
2642 if (vType(avc) == VDIR)
2643 mode = PRSFS_LOOKUP;
2646 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
2649 memset(&stat, 0, sizeof(struct vcxstat));
2650 stat.fid = avc->fid;
2651 hset32(stat.DataVersion, hgetlo(avc->m.DataVersion));
2652 stat.lock = avc->lock;
2653 stat.parentVnode = avc->parentVnode;
2654 stat.parentUnique = avc->parentUnique;
2655 hset(stat.flushDV, avc->flushDV);
2656 hset(stat.mapDV, avc->mapDV);
2657 stat.truncPos = avc->truncPos;
2658 { /* just grab the first two - won't break anything... */
2659 struct axscache *ac;
2661 for (i = 0, ac = avc->Access; ac && i < CPSIZE; i++, ac = ac->next) {
2662 stat.randomUid[i] = ac->uid;
2663 stat.randomAccess[i] = ac->axess;
2666 stat.callback = afs_data_pointer_to_int32(avc->callback);
2667 stat.cbExpires = avc->cbExpires;
2668 stat.anyAccess = avc->anyAccess;
2669 stat.opens = avc->opens;
2670 stat.execsOrWriters = avc->execsOrWriters;
2671 stat.flockCount = avc->flockCount;
2672 stat.mvstat = avc->mvstat;
2673 stat.states = avc->states;
2674 memcpy(aout, (char *)&stat, sizeof(struct vcxstat));
2675 *aoutSize = sizeof(struct vcxstat);
2680 DECL_PIOCTL(PGetVnodeXStatus2)
2682 register afs_int32 code;
2683 struct vcxstat2 stat;
2688 code = afs_VerifyVCache(avc, areq);
2691 if (vType(avc) == VDIR)
2692 mode = PRSFS_LOOKUP;
2695 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
2698 memset(&stat, 0, sizeof(struct vcxstat2));
2700 stat.cbExpires = avc->cbExpires;
2701 stat.anyAccess = avc->anyAccess;
2702 stat.mvstat = avc->mvstat;
2703 stat.callerAccess = afs_GetAccessBits(avc, ~0, areq);
2705 memcpy(aout, (char *)&stat, sizeof(struct vcxstat2));
2706 *aoutSize = sizeof(struct vcxstat2);
2710 /* We require root for local sysname changes, but not for remote */
2711 /* (since we don't really believe remote uids anyway) */
2712 /* outname[] shouldn't really be needed- this is left as an excercise */
2713 /* for the reader. */
2714 DECL_PIOCTL(PSetSysName)
2716 char *cp, *cp2 = NULL, inname[MAXSYSNAME], outname[MAXSYSNAME];
2717 int setsysname, foundname = 0;
2718 register struct afs_exporter *exporter;
2719 register struct unixuser *au;
2720 register afs_int32 pag, error;
2721 int t, count, num = 0, allpags = 0;
2724 AFS_STATCNT(PSetSysName);
2725 if (!afs_globalVFS) {
2726 /* Afsd is NOT running; disable it */
2727 #if defined(KERNEL_HAVE_UERROR)
2728 return (setuerror(EINVAL), EINVAL);
2733 memset(inname, 0, MAXSYSNAME);
2734 memcpy((char *)&setsysname, ain, sizeof(afs_int32));
2735 ain += sizeof(afs_int32);
2736 if (setsysname & 0x8000) {
2738 setsysname &= ~0x8000;
2743 if (setsysname < 0 || setsysname > MAXNUMSYSNAMES)
2746 for (cp = ain, count = 0; count < setsysname; count++) {
2747 /* won't go past end of ain since maxsysname*num < ain length */
2749 if (t >= MAXSYSNAME || t <= 0)
2751 /* check for names that can shoot us in the foot */
2752 if (*cp == '.' && (cp[1] == 0 || (cp[1] == '.' && cp[2] == 0)))
2758 /* inname gets first entry in case we're being a translator */
2760 memcpy(inname, ain, t + 1); /* include terminating null */
2764 if ((*acred)->cr_gid == RMTUSER_REQ ||
2765 (*acred)->cr_gid == RMTUSER_REQ_PRIV) { /* Handles all exporters */
2766 if (allpags && (*acred)->cr_gid != RMTUSER_REQ_PRIV) {
2769 pag = PagInCred(*acred);
2771 return EINVAL; /* Better than panicing */
2773 if (!(au = afs_FindUser(pag, -1, READ_LOCK))) {
2774 return EINVAL; /* Better than panicing */
2776 if (!(exporter = au->exporter)) {
2777 afs_PutUser(au, READ_LOCK);
2778 return EINVAL; /* Better than panicing */
2780 error = EXP_SYSNAME(exporter, (setsysname ? cp2 : NULL), &sysnamelist,
2783 if (error == ENODEV)
2784 foundname = 0; /* sysname not set yet! */
2786 afs_PutUser(au, READ_LOCK);
2791 strcpy(outname, sysnamelist[0]);
2793 afs_PutUser(au, READ_LOCK);
2797 /* Not xlating, so local case */
2799 osi_Panic("PSetSysName: !afs_sysname\n");
2800 if (!setsysname) { /* user just wants the info */
2801 strcpy(outname, afs_sysname);
2802 foundname = afs_sysnamecount;
2803 sysnamelist = afs_sysnamelist;
2804 } else { /* Local guy; only root can change sysname */
2805 if (!afs_osi_suser(*acred))
2808 /* allpags makes no sense for local use */
2812 /* clear @sys entries from the dnlc, once afs_lookup can
2813 * do lookups of @sys entries and thinks it can trust them */
2814 /* privs ok, store the entry, ... */
2815 strcpy(afs_sysname, inname);
2816 if (setsysname > 1) { /* ... or list */
2818 for (count = 1; count < setsysname; ++count) {
2819 if (!afs_sysnamelist[count])
2821 ("PSetSysName: no afs_sysnamelist entry to write\n");
2823 memcpy(afs_sysnamelist[count], cp, t + 1); /* include null */
2827 afs_sysnamecount = setsysname;
2832 cp = aout; /* not changing so report back the count and ... */
2833 memcpy(cp, (char *)&foundname, sizeof(afs_int32));
2834 cp += sizeof(afs_int32);
2836 strcpy(cp, outname); /* ... the entry, ... */
2837 cp += strlen(outname) + 1;
2838 for (count = 1; count < foundname; ++count) { /* ... or list. */
2839 if (!sysnamelist[count])
2841 ("PSetSysName: no afs_sysnamelist entry to read\n");
2842 t = strlen(sysnamelist[count]);
2843 if (t >= MAXSYSNAME)
2844 osi_Panic("PSetSysName: sysname entry garbled\n");
2845 strcpy(cp, sysnamelist[count]);
2849 *aoutSize = cp - aout;
2854 /* sequential search through the list of touched cells is not a good
2855 * long-term solution here. For small n, though, it should be just
2856 * fine. Should consider special-casing the local cell for large n.
2857 * Likewise for PSetSPrefs.
2859 * s - number of ids in array l[] -- NOT index of last id
2860 * l - array of cell ids which have volumes that need to be sorted
2861 * vlonly - sort vl servers or file servers?
2864 ReSortCells_cb(struct cell *cell, void *arg)
2866 afs_int32 *p = (afs_int32 *) arg;
2867 afs_int32 *l = p + 1;
2870 for (i = 0; i < s; i++) {
2871 if (l[i] == cell->cellNum) {
2872 ObtainWriteLock(&cell->lock, 690);
2873 afs_SortServers(cell->cellHosts, MAXCELLHOSTS);
2874 ReleaseWriteLock(&cell->lock);
2882 ReSortCells(int s, afs_int32 * l, int vlonly)
2890 p = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * (s + 1));
2892 memcpy(p + 1, l, s * sizeof(afs_int32));
2893 afs_TraverseCells(&ReSortCells_cb, p);
2894 afs_osi_Free(p, sizeof(afs_int32) * (s + 1));
2898 ObtainReadLock(&afs_xvolume);
2899 for (i = 0; i < NVOLS; i++) {
2900 for (j = afs_volumes[i]; j; j = j->next) {
2901 for (k = 0; k < s; k++)
2902 if (j->cell == l[k]) {
2903 ObtainWriteLock(&j->lock, 233);
2904 afs_SortServers(j->serverHost, MAXHOSTS);
2905 ReleaseWriteLock(&j->lock);
2910 ReleaseReadLock(&afs_xvolume);
2914 static int debugsetsp = 0;
2916 afs_setsprefs(sp, num, vlonly)
2919 unsigned int vlonly;
2922 int i, j, k, matches, touchedSize;
2923 struct server *srvr = NULL;
2924 afs_int32 touched[34];
2928 for (k = 0; k < num; sp++, k++) {
2930 printf("sp host=%x, rank=%d\n", sp->host.s_addr, sp->rank);
2933 ObtainReadLock(&afs_xserver);
2935 i = SHash(sp->host.s_addr);
2936 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2937 if (sa->sa_ip == sp->host.s_addr) {
2939 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
2940 || (sa->sa_portal == AFS_FSPORT);
2941 if ((!vlonly && isfs) || (vlonly && !isfs)) {
2948 if (sa && matches) { /* found one! */
2950 printf("sa ip=%x, ip_rank=%d\n", sa->sa_ip, sa->sa_iprank);
2952 sa->sa_iprank = sp->rank + afs_randomMod15();
2953 afs_SortOneServer(sa->server);
2956 /* if we don't know yet what cell it's in, this is moot */
2957 for (j = touchedSize - 1;
2958 j >= 0 && touched[j] != srvr->cell->cellNum; j--)
2959 /* is it in our list of touched cells ? */ ;
2960 if (j < 0) { /* no, it's not */
2961 touched[touchedSize++] = srvr->cell->cellNum;
2962 if (touchedSize >= 32) { /* watch for ovrflow */
2963 ReleaseReadLock(&afs_xserver);
2964 ReSortCells(touchedSize, touched, vlonly);
2966 ObtainReadLock(&afs_xserver);
2972 ReleaseReadLock(&afs_xserver);
2973 /* if we didn't find one, start to create one. */
2974 /* Note that it doesn't have a cell yet... */
2976 afs_uint32 temp = sp->host.s_addr;
2978 afs_GetServer(&temp, 1, 0, (vlonly ? AFS_VLPORT : AFS_FSPORT),
2979 WRITE_LOCK, (afsUUID *) 0, 0);
2980 srvr->addr->sa_iprank = sp->rank + afs_randomMod15();
2981 afs_PutServer(srvr, WRITE_LOCK);
2983 } /* for all cited preferences */
2985 ReSortCells(touchedSize, touched, vlonly);
2989 /* Note that this may only be performed by the local root user.
2991 DECL_PIOCTL(PSetSPrefs)
2993 struct setspref *ssp;
2994 AFS_STATCNT(PSetSPrefs);
2996 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2997 return EIO; /* Inappropriate ioctl for device */
2999 if (!afs_osi_suser(*acred))
3002 if (ainSize < sizeof(struct setspref))
3005 ssp = (struct setspref *)ain;
3006 if (ainSize < sizeof(struct spref) * ssp->num_servers)
3009 afs_setsprefs(&(ssp->servers[0]), ssp->num_servers,
3010 (ssp->flags & DBservers));
3014 DECL_PIOCTL(PSetSPrefs33)
3017 AFS_STATCNT(PSetSPrefs);
3018 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3019 return EIO; /* Inappropriate ioctl for device */
3022 if (!afs_osi_suser(*acred))
3025 sp = (struct spref *)ain;
3026 afs_setsprefs(sp, ainSize / (sizeof(struct spref)), 0 /*!vlonly */ );
3030 /* some notes on the following code...
3031 * in the hash table of server structs, all servers with the same IP address
3032 * will be on the same overflow chain.
3033 * This could be sped slightly in some circumstances by having it cache the
3034 * immediately previous slot in the hash table and some supporting information
3035 * Only reports file servers now.
3037 DECL_PIOCTL(PGetSPrefs)
3039 struct sprefrequest *spin; /* input */
3040 struct sprefinfo *spout; /* output */
3041 struct spref *srvout; /* one output component */
3042 int i, j; /* counters for hash table traversal */
3043 struct server *srvr; /* one of CM's server structs */
3045 int vlonly; /* just return vlservers ? */
3048 AFS_STATCNT(PGetSPrefs);
3049 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3050 return EIO; /* Inappropriate ioctl for device */
3053 if (ainSize < sizeof(struct sprefrequest_33)) {
3056 spin = ((struct sprefrequest *)ain);
3059 if (ainSize > sizeof(struct sprefrequest_33)) {
3060 vlonly = (spin->flags & DBservers);
3064 /* struct sprefinfo includes 1 server struct... that size gets added
3065 * in during the loop that follows.
3067 *aoutSize = sizeof(struct sprefinfo) - sizeof(struct spref);
3068 spout = (struct sprefinfo *)aout;
3069 spout->next_offset = spin->offset;
3070 spout->num_servers = 0;
3071 srvout = spout->servers;
3073 ObtainReadLock(&afs_xserver);
3074 for (i = 0, j = 0; j < NSERVERS; j++) { /* sift through hash table */
3075 for (sa = afs_srvAddrs[j]; sa; sa = sa->next_bkt, i++) {
3076 if (spin->offset > (unsigned short)i) {
3077 continue; /* catch up to where we left off */
3079 spout->next_offset++;
3082 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
3083 || (sa->sa_portal == AFS_FSPORT);
3085 if ((vlonly && isfs) || (!vlonly && !isfs)) {
3086 /* only report ranks for vl servers */
3090 srvout->host.s_addr = sa->sa_ip;
3091 srvout->rank = sa->sa_iprank;
3092 *aoutSize += sizeof(struct spref);
3093 spout->num_servers++;
3096 if (*aoutSize > (PIGGYSIZE - sizeof(struct spref))) {
3097 ReleaseReadLock(&afs_xserver); /* no more room! */
3102 ReleaseReadLock(&afs_xserver);
3104 spout->next_offset = 0; /* start over from the beginning next time */
3108 /* Enable/Disable the specified exporter. Must be root to disable an exporter */
3109 int afs_NFSRootOnly = 1;
3110 DECL_PIOCTL(PExportAfs)
3112 afs_int32 export, newint =
3113 0, type, changestate, handleValue, convmode, pwsync, smounts;
3114 afs_int32 rempags = 0, pagcb = 0;
3115 register struct afs_exporter *exporter;
3117 AFS_STATCNT(PExportAfs);
3118 memcpy((char *)&handleValue, ain, sizeof(afs_int32));
3119 type = handleValue >> 24;
3124 exporter = exporter_find(type);
3126 export = handleValue & 3;
3127 changestate = handleValue & 0xfff;
3128 smounts = (handleValue >> 2) & 3;
3129 pwsync = (handleValue >> 4) & 3;
3130 convmode = (handleValue >> 6) & 3;
3131 rempags = (handleValue >> 8) & 3;
3132 pagcb = (handleValue >> 10) & 3;
3134 changestate = (handleValue >> 16) & 0x1;
3135 convmode = (handleValue >> 16) & 0x2;
3136 pwsync = (handleValue >> 16) & 0x4;
3137 smounts = (handleValue >> 16) & 0x8;
3138 export = handleValue & 0xff;
3141 /* Failed finding desired exporter; */
3145 handleValue = exporter->exp_states;
3146 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3147 *aoutSize = sizeof(afs_int32);
3149 if (!afs_osi_suser(*acred))
3150 return EACCES; /* Only superuser can do this */
3154 exporter->exp_states |= EXP_EXPORTED;
3156 exporter->exp_states &= ~EXP_EXPORTED;
3160 exporter->exp_states |= EXP_UNIXMODE;
3162 exporter->exp_states &= ~EXP_UNIXMODE;
3166 exporter->exp_states |= EXP_PWSYNC;
3168 exporter->exp_states &= ~EXP_PWSYNC;
3172 afs_NFSRootOnly = 0;
3173 exporter->exp_states |= EXP_SUBMOUNTS;
3175 afs_NFSRootOnly = 1;
3176 exporter->exp_states &= ~EXP_SUBMOUNTS;
3181 exporter->exp_states |= EXP_CLIPAGS;
3183 exporter->exp_states &= ~EXP_CLIPAGS;
3187 exporter->exp_states |= EXP_CALLBACK;
3189 exporter->exp_states &= ~EXP_CALLBACK;
3191 handleValue = exporter->exp_states;
3192 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3193 *aoutSize = sizeof(afs_int32);
3196 exporter->exp_states |= EXP_EXPORTED;
3198 exporter->exp_states &= ~EXP_EXPORTED;
3200 exporter->exp_states |= EXP_UNIXMODE;
3202 exporter->exp_states &= ~EXP_UNIXMODE;
3204 exporter->exp_states |= EXP_PWSYNC;
3206 exporter->exp_states &= ~EXP_PWSYNC;
3208 afs_NFSRootOnly = 0;
3209 exporter->exp_states |= EXP_SUBMOUNTS;
3211 afs_NFSRootOnly = 1;
3212 exporter->exp_states &= ~EXP_SUBMOUNTS;
3222 struct gaginfo *gagflags;
3224 if (!afs_osi_suser(*acred))
3227 gagflags = (struct gaginfo *)ain;
3228 afs_showflags = gagflags->showflags;
3234 DECL_PIOCTL(PTwiddleRx)
3236 struct rxparams *rxp;
3238 if (!afs_osi_suser(*acred))
3241 rxp = (struct rxparams *)ain;
3243 if (rxp->rx_initReceiveWindow)
3244 rx_initReceiveWindow = rxp->rx_initReceiveWindow;
3245 if (rxp->rx_maxReceiveWindow)
3246 rx_maxReceiveWindow = rxp->rx_maxReceiveWindow;
3247 if (rxp->rx_initSendWindow)
3248 rx_initSendWindow = rxp->rx_initSendWindow;
3249 if (rxp->rx_maxSendWindow)
3250 rx_maxSendWindow = rxp->rx_maxSendWindow;
3251 if (rxp->rxi_nSendFrags)
3252 rxi_nSendFrags = rxp->rxi_nSendFrags;
3253 if (rxp->rxi_nRecvFrags)
3254 rxi_nRecvFrags = rxp->rxi_nRecvFrags;
3255 if (rxp->rxi_OrphanFragSize)
3256 rxi_OrphanFragSize = rxp->rxi_OrphanFragSize;
3257 if (rxp->rx_maxReceiveSize) {
3258 rx_maxReceiveSize = rxp->rx_maxReceiveSize;
3259 rx_maxReceiveSizeUser = rxp->rx_maxReceiveSize;
3261 if (rxp->rx_MyMaxSendSize)
3262 rx_MyMaxSendSize = rxp->rx_MyMaxSendSize;
3267 DECL_PIOCTL(PGetInitParams)
3269 if (sizeof(struct cm_initparams) > PIGGYSIZE)
3272 memcpy(aout, (char *)&cm_initParams, sizeof(struct cm_initparams));
3273 *aoutSize = sizeof(struct cm_initparams);
3277 #ifdef AFS_SGI65_ENV
3278 /* They took crget() from us, so fake it. */
3283 cr = crdup(get_current_cred());
3284 memset((char *)cr, 0, sizeof(cred_t));
3285 #if CELL || CELL_PREPARE
3292 DECL_PIOCTL(PGetRxkcrypt)
3294 memcpy(aout, (char *)&cryptall, sizeof(afs_int32));
3295 *aoutSize = sizeof(afs_int32);
3299 DECL_PIOCTL(PSetRxkcrypt)
3303 if (!afs_osi_suser(*acred))
3305 if (ainSize != sizeof(afs_int32) || ain == NULL)
3307 memcpy((char *)&tmpval, ain, sizeof(afs_int32));
3308 /* if new mappings added later this will need to be changed */
3309 if (tmpval != 0 && tmpval != 1)
3315 #ifdef AFS_NEED_CLIENTCONTEXT
3317 * Create new credentials to correspond to a remote user with given
3318 * <hostaddr, uid, g0, g1>. This allows a server running as root to
3319 * provide pioctl (and other) services to foreign clients (i.e. nfs
3320 * clients) by using this call to `become' the client.
3323 #define PIOCTL_HEADER 6
3325 HandleClientContext(struct afs_ioctl *ablob, int *com,
3326 struct AFS_UCRED **acred, struct AFS_UCRED *credp)
3329 afs_uint32 hostaddr;
3330 afs_int32 uid, g0, g1, i, code, pag, exporter_type, isroot = 0;
3331 struct afs_exporter *exporter, *outexporter;
3332 struct AFS_UCRED *newcred;
3333 struct unixuser *au;
3335 #if defined(AFS_SGIMP_ENV)
3336 osi_Assert(ISAFS_GLOCK());
3338 AFS_STATCNT(HandleClientContext);
3339 if (ablob->in_size < PIOCTL_HEADER * sizeof(afs_int32)) {
3340 /* Must at least include the PIOCTL_HEADER header words required by the protocol */
3341 return EINVAL; /* Too small to be good */
3343 ain = inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
3344 AFS_COPYIN(ablob->in, ain, PIOCTL_HEADER * sizeof(afs_int32), code);
3346 osi_FreeLargeSpace(inData);
3350 /* Extract information for remote user */
3351 hostaddr = *((afs_uint32 *) ain);
3352 ain += sizeof(hostaddr);
3353 uid = *((afs_uint32 *) ain);
3355 g0 = *((afs_uint32 *) ain);
3357 g1 = *((afs_uint32 *) ain);
3359 *com = *((afs_uint32 *) ain);
3360 ain += sizeof(afs_int32);
3361 exporter_type = *((afs_uint32 *) ain); /* In case we support more than NFS */
3364 * Of course, one must be root for most of these functions, but
3365 * we'll allow (for knfs) you to set things if the pag is 0 and
3366 * you're setting tokens or unlogging.
3369 if (!afs_osi_suser(credp)) {
3370 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
3371 /* Since SGI's suser() returns explicit failure after the call.. */
3374 /* check for acceptable opcodes for normal folks, which are, so far,
3375 * set tokens and unlog.
3377 if (i != 9 && i != 3 && i != 38 && i != 8) {
3378 osi_FreeLargeSpace(inData);
3383 ablob->in_size -= PIOCTL_HEADER * sizeof(afs_int32);
3384 ablob->in += PIOCTL_HEADER * sizeof(afs_int32);
3385 osi_FreeLargeSpace(inData);
3388 * We map uid 0 to nobody to match the mapping that the nfs
3389 * server does and to ensure that the suser() calls in the afs
3390 * code fails for remote client roots.
3392 uid = afs_nobody; /* NFS_NOBODY == -2 */
3396 #ifdef AFS_AIX41_ENV
3399 newcred->cr_gid = isroot ? RMTUSER_REQ_PRIV : RMTUSER_REQ;
3400 #ifdef AFS_AIX51_ENV
3401 newcred->cr_groupset.gs_union.un_groups[0] = g0;
3402 newcred->cr_groupset.gs_union.un_groups[1] = g1;
3403 #elif defined(AFS_LINUX26_ENV)
3404 newcred->cr_group_info = groups_alloc(2);
3405 GROUP_AT(newcred->cr_group_info, 0) = g0;
3406 GROUP_AT(newcred->cr_group_info, 1) = g1;
3408 newcred->cr_groups[0] = g0;
3409 newcred->cr_groups[1] = g1;
3412 newcred->cr_ngrps = 2;
3413 #elif !defined(AFS_LINUX26_ENV)
3414 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
3415 newcred->cr_ngroups = 2;
3417 for (i = 2; i < NGROUPS; i++)
3418 newcred->cr_groups[i] = NOGROUP;
3421 #if !defined(AFS_OSF_ENV)
3422 afs_nfsclient_init(); /* before looking for exporter, ensure one exists */
3424 if (!(exporter = exporter_find(exporter_type))) {
3425 /* Exporter wasn't initialized or an invalid exporter type */
3429 if (exporter->exp_states & EXP_PWSYNC) {
3430 if (uid != credp->cr_uid) {
3432 return ENOEXEC; /* XXX Find a better errno XXX */
3435 newcred->cr_uid = uid; /* Only temporary */
3436 code = EXP_REQHANDLER(exporter, &newcred, hostaddr, &pag, &outexporter);
3437 /* The client's pag is the only unique identifier for it */
3438 newcred->cr_uid = pag;
3440 if (!code && *com == PSETPAG) {
3441 /* Special case for 'setpag' */
3442 afs_uint32 pagvalue = genpag();
3444 au = afs_GetUser(pagvalue, -1, WRITE_LOCK); /* a new unixuser struct */
3446 * Note that we leave the 'outexporter' struct held so it won't
3449 au->exporter = outexporter;
3450 if (ablob->out_size >= 4) {
3451 AFS_COPYOUT((char *)&pagvalue, ablob->out, sizeof(afs_int32),
3454 afs_PutUser(au, WRITE_LOCK);
3457 return PSETPAG; /* Special return for setpag */
3459 EXP_RELE(outexporter);
3463 #endif /* AFS_NEED_CLIENTCONTEXT */
3465 /* get all interface addresses of this client */
3467 DECL_PIOCTL(PGetCPrefs)
3469 struct sprefrequest *spin; /* input */
3470 struct sprefinfo *spout; /* output */
3471 struct spref *srvout; /* one output component */
3475 AFS_STATCNT(PGetCPrefs);
3476 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3477 return EIO; /* Inappropriate ioctl for device */
3479 if (ainSize < sizeof(struct sprefrequest))
3482 spin = (struct sprefrequest *)ain;
3483 spout = (struct sprefinfo *)aout;
3485 maxNumber = spin->num_servers; /* max addrs this time */
3486 srvout = spout->servers;
3488 ObtainReadLock(&afs_xinterface);
3490 /* copy out the client interface information from the
3491 ** kernel data structure "interface" to the output buffer
3493 for (i = spin->offset, j = 0; (i < afs_cb_interface.numberOfInterfaces)
3494 && (j < maxNumber); i++, j++, srvout++)
3495 srvout->host.s_addr = afs_cb_interface.addr_in[i];
3497 spout->num_servers = j;
3498 *aoutSize = sizeof(struct sprefinfo) + (j - 1) * sizeof(struct spref);
3500 if (i >= afs_cb_interface.numberOfInterfaces)
3501 spout->next_offset = 0; /* start from beginning again */
3503 spout->next_offset = spin->offset + j;
3505 ReleaseReadLock(&afs_xinterface);
3509 DECL_PIOCTL(PSetCPrefs)
3511 struct setspref *sin;
3514 AFS_STATCNT(PSetCPrefs);
3515 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3516 return EIO; /* Inappropriate ioctl for device */
3518 sin = (struct setspref *)ain;
3520 if (ainSize < sizeof(struct setspref))
3522 #if 0 /* num_servers is unsigned */
3523 if (sin->num_servers < 0)
3526 if (sin->num_servers > AFS_MAX_INTERFACE_ADDR)
3529 ObtainWriteLock(&afs_xinterface, 412);
3530 afs_cb_interface.numberOfInterfaces = sin->num_servers;
3531 for (i = 0; (unsigned short)i < sin->num_servers; i++)
3532 afs_cb_interface.addr_in[i] = sin->servers[i].host.s_addr;
3534 ReleaseWriteLock(&afs_xinterface);
3538 DECL_PIOCTL(PFlushMount)
3540 register afs_int32 code;
3541 register struct vcache *tvc;
3542 register struct dcache *tdc;
3543 struct VenusFid tfid;
3545 struct sysname_info sysState;
3546 afs_size_t offset, len;
3548 AFS_STATCNT(PFlushMount);
3551 code = afs_VerifyVCache(avc, areq);
3554 if (vType(avc) != VDIR) {
3557 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
3560 Check_AtSys(avc, ain, &sysState, areq);
3561 ObtainReadLock(&tdc->lock);
3563 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
3564 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
3565 ReleaseReadLock(&tdc->lock);
3566 afs_PutDCache(tdc); /* we're done with the data */
3567 bufp = sysState.name;
3571 tfid.Cell = avc->fid.Cell;
3572 tfid.Fid.Volume = avc->fid.Fid.Volume;
3573 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
3574 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
3576 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3582 if (tvc->mvstat != 1) {
3587 #ifdef AFS_BOZONLOCK_ENV
3588 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
3590 ObtainWriteLock(&tvc->lock, 649);
3591 ObtainWriteLock(&afs_xcbhash, 650);
3592 afs_DequeueCallback(tvc);
3593 tvc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
3594 ReleaseWriteLock(&afs_xcbhash);
3595 /* now find the disk cache entries */
3596 afs_TryToSmush(tvc, *acred, 1);
3597 osi_dnlc_purgedp(tvc);
3598 if (tvc->linkData && !(tvc->states & CCore)) {
3599 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
3600 tvc->linkData = NULL;
3602 ReleaseWriteLock(&tvc->lock);
3603 #ifdef AFS_BOZONLOCK_ENV
3604 afs_BozonUnlock(&tvc->pvnLock, tvc);
3608 if (sysState.allocked)
3609 osi_FreeLargeSpace(bufp);
3613 DECL_PIOCTL(PRxStatProc)
3618 if (!afs_osi_suser(*acred)) {
3622 if (ainSize != sizeof(afs_int32)) {
3626 memcpy((char *)&flags, ain, sizeof(afs_int32));
3627 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3631 if (flags & AFSCALL_RXSTATS_ENABLE) {
3632 rx_enableProcessRPCStats();
3634 if (flags & AFSCALL_RXSTATS_DISABLE) {
3635 rx_disableProcessRPCStats();
3637 if (flags & AFSCALL_RXSTATS_CLEAR) {
3638 rx_clearProcessRPCStats(AFS_RX_STATS_CLEAR_ALL);
3646 DECL_PIOCTL(PRxStatPeer)
3651 if (!afs_osi_suser(*acred)) {
3655 if (ainSize != sizeof(afs_int32)) {
3659 memcpy((char *)&flags, ain, sizeof(afs_int32));
3660 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3664 if (flags & AFSCALL_RXSTATS_ENABLE) {
3665 rx_enablePeerRPCStats();
3667 if (flags & AFSCALL_RXSTATS_DISABLE) {
3668 rx_disablePeerRPCStats();
3670 if (flags & AFSCALL_RXSTATS_CLEAR) {
3671 rx_clearPeerRPCStats(AFS_RX_STATS_CLEAR_ALL);
3678 DECL_PIOCTL(PPrefetchFromTape)
3680 register afs_int32 code, code1;
3683 struct rx_call *tcall;
3684 struct AFSVolSync tsync;
3685 struct AFSFetchStatus OutStatus;
3686 struct AFSCallBack CallBack;
3687 struct VenusFid tfid;
3691 AFS_STATCNT(PSetAcl);
3695 if (ain && (ainSize == 3 * sizeof(afs_int32)))
3696 Fid = (struct AFSFid *)ain;
3698 Fid = &avc->fid.Fid;
3699 tfid.Cell = avc->fid.Cell;
3700 tfid.Fid.Volume = Fid->Volume;
3701 tfid.Fid.Vnode = Fid->Vnode;
3702 tfid.Fid.Unique = Fid->Unique;
3704 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3706 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3707 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &avc->fid);
3710 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3711 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &tvc->fid);
3714 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3718 tcall = rx_NewCall(tc->id);
3720 StartRXAFS_FetchData(tcall, (struct AFSFid *)&tvc->fid.Fid, 0,
3723 bytes = rx_Read(tcall, (char *)aout, sizeof(afs_int32));
3725 EndRXAFS_FetchData(tcall, &OutStatus, &CallBack, &tsync);
3727 code1 = rx_EndCall(tcall, code);
3731 } while (afs_Analyze
3732 (tc, code, &tvc->fid, areq, AFS_STATS_FS_RPCIDX_RESIDENCYRPCS,
3733 SHARED_LOCK, NULL));
3734 /* This call is done only to have the callback things handled correctly */
3735 afs_FetchStatus(tvc, &tfid, areq, &OutStatus);
3739 *aoutSize = sizeof(afs_int32);
3744 DECL_PIOCTL(PResidencyCmd)
3746 register afs_int32 code;
3749 struct ResidencyCmdInputs *Inputs;
3750 struct ResidencyCmdOutputs *Outputs;
3751 struct VenusFid tfid;
3754 Inputs = (struct ResidencyCmdInputs *)ain;
3755 Outputs = (struct ResidencyCmdOutputs *)aout;
3758 if (!ain || ainSize != sizeof(struct ResidencyCmdInputs))
3763 Fid = &avc->fid.Fid;
3765 tfid.Cell = avc->fid.Cell;
3766 tfid.Fid.Volume = Fid->Volume;
3767 tfid.Fid.Vnode = Fid->Vnode;
3768 tfid.Fid.Unique = Fid->Unique;
3770 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3771 afs_Trace3(afs_iclSetp, CM_TRACE_RESIDCMD, ICL_TYPE_POINTER, tvc,
3772 ICL_TYPE_INT32, Inputs->command, ICL_TYPE_FID, &tfid);
3776 if (Inputs->command) {
3778 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3782 RXAFS_ResidencyCmd(tc->id, Fid, Inputs,
3783 (struct ResidencyCmdOutputs *)aout);
3787 } while (afs_Analyze
3788 (tc, code, &tvc->fid, areq,
3789 AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK, NULL));
3790 /* This call is done to have the callback things handled correctly */
3791 afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3792 } else { /* just a status request, return also link data */
3794 Outputs->code = afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3795 Outputs->chars[0] = 0;
3796 if (vType(tvc) == VLNK) {
3797 ObtainWriteLock(&tvc->lock, 555);
3798 if (afs_HandleLink(tvc, areq) == 0)
3799 strncpy((char *)&Outputs->chars, tvc->linkData, MAXCMDCHARS);
3800 ReleaseWriteLock(&tvc->lock);
3807 *aoutSize = sizeof(struct ResidencyCmdOutputs);
3812 DECL_PIOCTL(PCallBackAddr)
3815 afs_uint32 addr, code;
3821 struct unixuser *tu;
3822 struct srvAddr **addrs;
3824 /*AFS_STATCNT(PCallBackAddr); */
3825 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
3826 return EIO; /* Inappropriate ioctl for device */
3828 if (!afs_osi_suser(acred))
3831 if (ainSize < sizeof(afs_int32))
3834 memcpy(&addr, ain, sizeof(afs_int32));
3836 ObtainReadLock(&afs_xinterface);
3837 for (i = 0; (unsigned short)i < afs_cb_interface.numberOfInterfaces; i++) {
3838 if (afs_cb_interface.addr_in[i] == addr)
3842 ReleaseWriteLock(&afs_xinterface);
3844 if (afs_cb_interface.addr_in[i] != addr)
3847 ObtainReadLock(&afs_xserver); /* Necessary? */
3848 ObtainReadLock(&afs_xsrvAddr);
3851 for (i = 0; i < NSERVERS; i++) {
3852 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3857 addrs = afs_osi_Alloc(srvAddrCount * sizeof(*addrs));
3859 for (i = 0; i < NSERVERS; i++) {
3860 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3861 if (j >= srvAddrCount)
3867 ReleaseReadLock(&afs_xsrvAddr);
3868 ReleaseReadLock(&afs_xserver);
3870 for (i = 0; i < j; i++) {
3876 /* vlserver has no callback conn */
3877 if (sa->sa_portal == AFS_VLPORT) {
3881 if (!ts->cell) /* not really an active server, anyway, it must */
3882 continue; /* have just been added by setsprefs */
3884 /* get a connection, even if host is down; bumps conn ref count */
3885 tu = afs_GetUser(areq->uid, ts->cell->cellNum, SHARED_LOCK);
3886 tc = afs_ConnBySA(sa, ts->cell->fsport, ts->cell->cellNum, tu,
3887 1 /*force */ , 1 /*create */ , SHARED_LOCK);
3888 afs_PutUser(tu, SHARED_LOCK);
3892 if ((sa->sa_flags & SRVADDR_ISDOWN) || afs_HaveCallBacksFrom(ts)) {
3893 if (sa->sa_flags & SRVADDR_ISDOWN) {
3894 rx_SetConnDeadTime(tc->id, 3);
3896 #ifdef RX_ENABLE_LOCKS
3898 #endif /* RX_ENABLE_LOCKS */
3899 code = RXAFS_CallBackRxConnAddr(tc->id, &addr);
3900 #ifdef RX_ENABLE_LOCKS
3902 #endif /* RX_ENABLE_LOCKS */
3904 afs_PutConn(tc, SHARED_LOCK); /* done with it now */
3905 } /* Outer loop over addrs */
3906 #endif /* UKERNEL */
3910 DECL_PIOCTL(PNFSNukeCreds)
3912 afs_uint32 addr, code;
3913 register afs_int32 i;
3914 register struct unixuser *tu;
3916 AFS_STATCNT(PUnlog);
3917 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3918 return EIO; /* Inappropriate ioctl for device */
3920 if (ainSize < sizeof(afs_int32))
3922 memcpy(&addr, ain, sizeof(afs_int32));
3924 if ((*acred)->cr_gid == RMTUSER_REQ_PRIV && !addr) {
3925 tu = afs_GetUser(areq->uid, -1, SHARED_LOCK);
3926 if (!tu->exporter || !(addr = EXP_GETHOST(tu->exporter))) {
3927 afs_PutUser(tu, SHARED_LOCK);
3930 afs_PutUser(tu, SHARED_LOCK);
3931 } else if (!afs_osi_suser(acred)) {
3935 ObtainWriteLock(&afs_xuser, 227);
3936 for (i = 0; i < NUSERS; i++) {
3937 for (tu = afs_users[i]; tu; tu = tu->next) {
3938 if (tu->exporter && EXP_CHECKHOST(tu->exporter, addr)) {
3940 tu->states &= ~UHasTokens;
3941 /* security is not having to say you're sorry */
3942 memset((char *)&tu->ct, 0, sizeof(struct ClearToken));
3944 ReleaseWriteLock(&afs_xuser);
3945 afs_ResetUserConns(tu);
3947 ObtainWriteLock(&afs_xuser, 228);
3949 /* set the expire times to 0, causes
3950 * afs_GCUserData to remove this entry
3952 tu->ct.EndTimestamp = 0;
3954 #endif /* UKERNEL */
3958 ReleaseWriteLock(&afs_xuser);