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);
94 DECL_PIOCTL(PNewUuid);
97 * A macro that says whether we're going to need HandleClientContext().
98 * This is currently used only by the nfs translator.
100 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
101 #define AFS_NEED_CLIENTCONTEXT
104 /* Prototypes for private routines */
105 #ifdef AFS_NEED_CLIENTCONTEXT
106 static int HandleClientContext(struct afs_ioctl *ablob, int *com,
107 struct AFS_UCRED **acred,
108 struct AFS_UCRED *credp);
110 int HandleIoctl(register struct vcache *avc, register afs_int32 acom,
111 struct afs_ioctl *adata);
112 int afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
113 register struct afs_ioctl *ablob, int afollow,
114 struct AFS_UCRED **acred);
115 static int Prefetch(char *apath, struct afs_ioctl *adata, int afollow,
116 struct AFS_UCRED *acred);
119 static int (*(VpioctlSw[])) () = {
124 PGetVolumeStatus, /* 4 */
125 PSetVolumeStatus, /* 5 */
130 PCheckServers, /* 10 */
131 PCheckVolNames, /* 11 */
133 PBogus, /* 13 -- used to be quick check time */
134 PFindVolume, /* 14 */
135 PBogus, /* 15 -- prefetch is now special-cased; see pioctl code! */
136 PBogus, /* 16 -- used to be testing code */
137 PNoop, /* 17 -- used to be enable group */
138 PNoop, /* 18 -- used to be disable group */
139 PBogus, /* 19 -- used to be list group */
140 PViceAccess, /* 20 */
141 PUnlog, /* 21 -- unlog *is* unpag in this system */
142 PGetFID, /* 22 -- get file ID */
143 PBogus, /* 23 -- used to be waitforever */
144 PSetCacheSize, /* 24 */
145 PRemoveCallBack, /* 25 -- flush only the callback */
148 PRemoveMount, /* 28 -- delete mount point */
149 PNewStatMount, /* 29 -- new style mount point stat */
150 PGetFileCell, /* 30 -- get cell name for input file */
151 PGetWSCell, /* 31 -- get cell name for workstation */
152 PMariner, /* 32 - set/get mariner host */
153 PGetUserCell, /* 33 -- get cell name for user */
154 PVenusLogging, /* 34 -- Enable/Disable logging */
155 PGetCellStatus, /* 35 */
156 PSetCellStatus, /* 36 */
157 PFlushVolumeData, /* 37 -- flush all data from a volume */
158 PSetSysName, /* 38 - Set system name */
159 PExportAfs, /* 39 - Export Afs to remote nfs clients */
160 PGetCacheSize, /* 40 - get cache size and usage */
161 PGetVnodeXStatus, /* 41 - get vcache's special status */
162 PSetSPrefs33, /* 42 - Set CM Server preferences... */
163 PGetSPrefs, /* 43 - Get CM Server preferences... */
164 PGag, /* 44 - turn off/on all CM messages */
165 PTwiddleRx, /* 45 - adjust some RX params */
166 PSetSPrefs, /* 46 - Set CM Server preferences... */
167 PStoreBehind, /* 47 - set degree of store behind to be done */
168 PGCPAGs, /* 48 - disable automatic pag gc-ing */
169 PGetInitParams, /* 49 - get initial cm params */
170 PGetCPrefs, /* 50 - get client interface addresses */
171 PSetCPrefs, /* 51 - set client interface addresses */
172 PFlushMount, /* 52 - flush mount symlink data */
173 PRxStatProc, /* 53 - control process RX statistics */
174 PRxStatPeer, /* 54 - control peer RX statistics */
175 PGetRxkcrypt, /* 55 -- Get rxkad encryption flag */
176 PSetRxkcrypt, /* 56 -- Set rxkad encryption flag */
177 PBogus, /* 57 -- arla: set file prio */
178 PBogus, /* 58 -- arla: fallback getfh */
179 PBogus, /* 59 -- arla: fallback fhopen */
180 PBogus, /* 60 -- arla: controls xfsdebug */
181 PBogus, /* 61 -- arla: controls arla debug */
182 PBogus, /* 62 -- arla: debug interface */
183 PBogus, /* 63 -- arla: print xfs status */
184 PBogus, /* 64 -- arla: force cache check */
185 PBogus, /* 65 -- arla: break callback */
186 PPrefetchFromTape, /* 66 -- MR-AFS: prefetch file from tape */
187 PResidencyCmd, /* 67 -- MR-AFS: generic commnd interface */
188 PBogus, /* 68 -- arla: fetch stats */
189 PGetVnodeXStatus2, /* 69 - get caller access and some vcache status */
192 static int (*(CpioctlSw[])) () = {
194 PNewAlias, /* 1 -- create new cell alias */
195 PListAliases, /* 2 -- list cell aliases */
196 PCallBackAddr, /* 3 -- request addr for callback rxcon */
205 static int (*(OpioctlSw[])) () = {
207 PNFSNukeCreds, /* 1 -- nuke all creds for NFS client */
210 #define PSetClientContext 99 /* Special pioctl to setup caller's creds */
211 int afs_nobody = NFS_NOBODY;
214 HandleIoctl(register struct vcache *avc, register afs_int32 acom,
215 struct afs_ioctl *adata)
217 register afs_int32 code;
220 AFS_STATCNT(HandleIoctl);
222 switch (acom & 0xff) {
224 avc->states |= CSafeStore;
228 /* case 2 used to be abort store, but this is no longer provided,
229 * since it is impossible to implement under normal Unix.
233 /* return the name of the cell this file is open on */
234 register struct cell *tcell;
235 register afs_int32 i;
237 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
239 i = strlen(tcell->cellName) + 1; /* bytes to copy out */
241 if (i > adata->out_size) {
242 /* 0 means we're not interested in the output */
243 if (adata->out_size != 0)
247 AFS_COPYOUT(tcell->cellName, adata->out, i, code);
249 afs_PutCell(tcell, READ_LOCK);
255 case 49: /* VIOC_GETINITPARAMS */
256 if (adata->out_size < sizeof(struct cm_initparams)) {
259 AFS_COPYOUT(&cm_initParams, adata->out,
260 sizeof(struct cm_initparams), code);
272 return code; /* so far, none implemented */
277 /* For aix we don't temporarily bypass ioctl(2) but rather do our
278 * thing directly in the vnode layer call, VNOP_IOCTL; thus afs_ioctl
279 * is now called from afs_gn_ioctl.
282 afs_ioctl(struct vcache *tvc, int cmd, int arg)
284 struct afs_ioctl data;
287 AFS_STATCNT(afs_ioctl);
288 if (((cmd >> 8) & 0xff) == 'V') {
289 /* This is a VICEIOCTL call */
290 AFS_COPYIN(arg, (caddr_t) & data, sizeof(data), error);
293 error = HandleIoctl(tvc, cmd, &data);
296 /* No-op call; just return. */
300 #endif /* AFS_AIX_ENV */
302 #if defined(AFS_SGI_ENV)
303 afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
306 , struct vopbd * vbds
310 struct afs_ioctl data;
316 AFS_STATCNT(afs_ioctl);
317 if (((cmd >> 8) & 0xff) == 'V') {
318 /* This is a VICEIOCTL call */
319 error = copyin_afs_ioctl(arg, &data);
322 locked = ISAFS_GLOCK();
325 error = HandleIoctl(tvc, cmd, &data);
330 /* No-op call; just return. */
334 #endif /* AFS_SGI_ENV */
336 /* unlike most calls here, this one uses u.u_error to return error conditions,
337 since this is really an intercepted chapter 2 call, rather than a vnode
340 /* AFS_HPUX102 and up uses VNODE ioctl instead */
341 #if !defined(AFS_HPUX102_ENV) && !defined(AFS_DARWIN80_ENV)
342 #if !defined(AFS_SGI_ENV)
346 kioctl(fdes, com, arg, ext, arg2, arg3)
347 #else /* __64BIT__ */
348 kioctl32(fdes, com, arg, ext, arg2, arg3)
349 #endif /* __64BIT__ */
352 kioctl(fdes, com, arg, ext)
363 } u_uap, *uap = &u_uap;
365 #if defined(AFS_SUN5_ENV)
367 struct afs_ioctl_sys {
374 struct afs_ioctl_sys *uap;
377 #elif defined(AFS_OSF_ENV)
378 afs_xioctl(p, args, retval)
387 } *uap = (struct a *)args;
388 #elif defined(AFS_FBSD50_ENV)
391 afs_xioctl(td, uap, retval)
393 register struct ioctl_args *uap;
396 struct proc *p = td->td_proc;
397 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
405 afs_xioctl(p, uap, retval)
407 register struct ioctl_args *uap;
410 #elif defined(AFS_LINUX22_ENV)
411 struct afs_ioctl_sys {
416 afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
419 struct afs_ioctl_sys ua, *uap = &ua;
428 } *uap = (struct a *)u.u_ap;
429 #endif /* AFS_SUN5_ENV */
431 #if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
433 #elif !defined(AFS_LINUX22_ENV)
434 register struct file *fd;
436 #if defined(AFS_XBSD_ENV)
437 register struct filedesc *fdp;
439 register struct vcache *tvc;
440 register int ioctlDone = 0, code = 0;
442 AFS_STATCNT(afs_xioctl);
443 #if defined(AFS_DARWIN_ENV)
444 if ((code = fdgetf(p, uap->fd, &fd)))
446 #elif defined(AFS_XBSD_ENV)
448 if ((u_int) uap->fd >= fdp->fd_nfiles
449 || (fd = fdp->fd_ofiles[uap->fd]) == NULL)
451 if ((fd->f_flag & (FREAD | FWRITE)) == 0)
453 #elif defined(AFS_LINUX22_ENV)
456 #elif defined(AFS_AIX32_ENV)
464 if (setuerror(getf(uap->fd, &fd))) {
467 #elif defined(AFS_OSF_ENV)
469 if (code = getf(&fd, uap->fd, FILE_FLAGS_NULL, &u.u_file_state))
471 #elif defined(AFS_SUN5_ENV)
472 # if defined(AFS_SUN57_ENV)
476 # elif defined(AFS_SUN54_ENV)
481 if (code = getf(uap->fd, &fd)) {
484 # endif /* AFS_SUN57_ENV */
490 /* first determine whether this is any sort of vnode */
491 #if defined(AFS_LINUX22_ENV)
496 if (fd->f_vnode->v_type == VREG || fd->f_vnode->v_type == VDIR) {
498 if (fd->f_type == DTYPE_VNODE) {
500 /* good, this is a vnode; next see if it is an AFS vnode */
501 #if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV)
502 tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */
503 #elif defined(AFS_OBSD_ENV)
505 IsAfsVnode((struct vnode *)fd->
506 f_data) ? VTOAFS((struct vnode *)fd->f_data) : NULL;
508 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
510 #endif /* AFS_LINUX22_ENV */
511 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
512 /* This is an AFS vnode */
513 if (((uap->com >> 8) & 0xff) == 'V') {
514 register struct afs_ioctl *datap;
517 (struct afs_ioctl *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
518 code=copyin_afs_ioctl((char *)uap->arg, datap);
520 osi_FreeSmallSpace(datap);
522 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
525 #if defined(AFS_SUN5_ENV)
540 #else /* AFS_OSF_ENV */
544 #ifdef AFS_LINUX22_ENV
554 code = HandleIoctl(tvc, uap->com, datap);
555 osi_FreeSmallSpace(datap);
569 #if defined(AFS_LINUX22_ENV)
581 code = okioctl(fdes, com, arg, ext, arg2, arg3);
582 #else /* __64BIT__ */
583 code = okioctl32(fdes, com, arg, ext, arg2, arg3);
584 #endif /* __64BIT__ */
585 #else /* !AFS_AIX51_ENV */
586 code = okioctl(fdes, com, arg, ext);
587 #endif /* AFS_AIX51_ENV */
589 #else /* !AFS_AIX41_ENV */
591 okioctl(fdes, com, arg, ext);
592 #elif defined(AFS_SUN5_ENV)
593 #if defined(AFS_SUN57_ENV)
595 #elif defined(AFS_SUN54_ENV)
600 code = ioctl(uap, rvp);
601 #elif defined(AFS_FBSD50_ENV)
602 return ioctl(td, uap);
603 #elif defined(AFS_FBSD_ENV)
604 return ioctl(p, uap);
605 #elif defined(AFS_OBSD_ENV)
606 code = sys_ioctl(p, uap, retval);
607 #elif defined(AFS_DARWIN_ENV)
608 return ioctl(p, uap, retval);
609 #elif defined(AFS_OSF_ENV)
610 code = ioctl(p, args, retval);
617 #elif !defined(AFS_LINUX22_ENV)
631 #ifdef AFS_LINUX22_ENV
634 #if defined(KERNEL_HAVE_UERROR)
637 #if defined(AFS_AIX32_ENV) && !defined(AFS_AIX41_ENV)
638 return (getuerror()? -1 : u.u_ioctlrv);
640 return getuerror()? -1 : 0;
643 #endif /* AFS_LINUX22_ENV */
644 #endif /* AFS_SUN5_ENV */
645 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
649 #endif /* AFS_SGI_ENV */
650 #endif /* AFS_HPUX102_ENV */
652 #if defined(AFS_SGI_ENV)
653 /* "pioctl" system call entry point; just pass argument to the parameterized
662 afs_pioctl(struct pioctlargs *uap, rval_t * rvp)
666 AFS_STATCNT(afs_pioctl);
668 code = afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow);
677 #elif defined(AFS_OSF_ENV)
678 afs_pioctl(p, args, retval)
688 } *uap = (struct a *)args;
690 AFS_STATCNT(afs_pioctl);
691 return (afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow));
694 #elif defined(AFS_FBSD50_ENV)
696 afs_pioctl(td, args, retval)
706 } *uap = (struct a *)args;
708 AFS_STATCNT(afs_pioctl);
709 return (afs_syscall_pioctl
710 (uap->path, uap->cmd, uap->cmarg, uap->follow, td->td_ucred));
713 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
715 afs_pioctl(p, args, retval)
725 } *uap = (struct a *)args;
727 AFS_STATCNT(afs_pioctl);
728 #ifdef AFS_DARWIN80_ENV
729 return (afs_syscall_pioctl
730 (uap->path, uap->cmd, uap->cmarg, uap->follow,
733 return (afs_syscall_pioctl
734 (uap->path, uap->cmd, uap->cmarg, uap->follow,
735 p->p_cred->pc_ucred));
741 /* macro to avoid adding any more #ifdef's to pioctl code. */
742 #if defined(AFS_LINUX22_ENV) || defined(AFS_AIX41_ENV)
743 #define PIOCTL_FREE_CRED() crfree(credp)
745 #define PIOCTL_FREE_CRED()
750 afs_syscall_pioctl(path, com, cmarg, follow, rvp, credp)
752 struct AFS_UCRED *credp;
754 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
755 afs_syscall_pioctl(path, com, cmarg, follow, credp)
756 struct AFS_UCRED *credp;
758 afs_syscall_pioctl(path, com, cmarg, follow)
766 struct afs_ioctl data;
767 #ifdef AFS_NEED_CLIENTCONTEXT
768 struct AFS_UCRED *tmpcred = NULL;
770 struct AFS_UCRED *foreigncreds = NULL;
771 register afs_int32 code = 0;
772 struct vnode *vp = NULL;
774 struct ucred *credp = crref(); /* don't free until done! */
776 #ifdef AFS_LINUX22_ENV
777 cred_t *credp = crref(); /* don't free until done! */
781 AFS_STATCNT(afs_syscall_pioctl);
783 follow = 1; /* compat. with old venus */
784 code = copyin_afs_ioctl(cmarg, &data);
787 #if defined(KERNEL_HAVE_UERROR)
792 if ((com & 0xff) == PSetClientContext) {
793 #ifdef AFS_NEED_CLIENTCONTEXT
794 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV)
795 code = HandleClientContext(&data, &com, &foreigncreds, credp);
797 code = HandleClientContext(&data, &com, &foreigncreds, osi_curcred());
801 crfree(foreigncreds);
804 #if defined(KERNEL_HAVE_UERROR)
805 return (setuerror(code), code);
810 #else /* AFS_NEED_CLIENTCONTEXT */
812 #endif /* AFS_NEED_CLIENTCONTEXT */
814 #ifdef AFS_NEED_CLIENTCONTEXT
817 * We could have done without temporary setting the u.u_cred below
818 * (foreigncreds could be passed as param the pioctl modules)
819 * but calls such as afs_osi_suser() doesn't allow that since it
820 * references u.u_cred directly. We could, of course, do something
821 * like afs_osi_suser(cred) which, I think, is better since it
822 * generalizes and supports multi cred environments...
824 #if defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
826 credp = foreigncreds;
827 #elif defined(AFS_AIX41_ENV)
828 tmpcred = crref(); /* XXX */
830 #elif defined(AFS_HPUX101_ENV)
831 tmpcred = p_cred(u.u_procp);
832 set_p_cred(u.u_procp, foreigncreds);
833 #elif defined(AFS_SGI_ENV)
834 tmpcred = OSI_GET_CURRENT_CRED();
835 OSI_SET_CURRENT_CRED(foreigncreds);
838 u.u_cred = foreigncreds;
841 #endif /* AFS_NEED_CLIENTCONTEXT */
842 if ((com & 0xff) == 15) {
843 /* special case prefetch so entire pathname eval occurs in helper process.
844 * otherwise, the pioctl call is essentially useless */
845 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
847 Prefetch(path, &data, follow,
848 foreigncreds ? foreigncreds : credp);
850 code = Prefetch(path, &data, follow, osi_curcred());
853 #if defined(KERNEL_HAVE_UERROR)
862 lookupname(path, USR, follow, NULL, &vp,
863 foreigncreds ? foreigncreds : credp);
865 #ifdef AFS_LINUX22_ENV
866 code = gop_lookupname(path, AFS_UIOUSER, follow, &dp);
868 vp = (struct vnode *)dp->d_inode;
870 code = gop_lookupname(path, AFS_UIOUSER, follow, &vp);
871 #endif /* AFS_LINUX22_ENV */
872 #endif /* AFS_AIX41_ENV */
876 #if defined(KERNEL_HAVE_UERROR)
884 #if defined(AFS_SUN510_ENV)
885 if (vp && !IsAfsVnode(vp)) {
886 struct vnode *realvp;
888 if (VOP_REALVP(vp, &realvp) == 0) {
889 struct vnode *oldvp = vp;
897 /* now make the call if we were passed no file, or were passed an AFS file */
898 if (!vp || IsAfsVnode(vp)) {
899 #if defined(AFS_SUN5_ENV)
900 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
901 #elif defined(AFS_AIX41_ENV)
903 struct ucred *cred1, *cred2;
906 cred1 = cred2 = foreigncreds;
908 cred1 = cred2 = credp;
910 code = afs_HandlePioctl(vp, com, &data, follow, &cred1);
911 if (cred1 != cred2) {
912 /* something changed the creds */
916 #elif defined(AFS_HPUX101_ENV)
918 struct ucred *cred = p_cred(u.u_procp);
919 code = afs_HandlePioctl(vp, com, &data, follow, &cred);
921 #elif defined(AFS_SGI_ENV)
924 credp = OSI_GET_CURRENT_CRED();
925 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
927 #elif defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
928 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
930 code = afs_HandlePioctl(vp, com, &data, follow, &u.u_cred);
933 #if defined(KERNEL_HAVE_UERROR)
936 code = EINVAL; /* not in /afs */
941 #if defined(AFS_NEED_CLIENTCONTEXT)
944 crset(tmpcred); /* restore original credentials */
946 #if defined(AFS_HPUX101_ENV)
947 set_p_cred(u.u_procp, tmpcred); /* restore original credentials */
948 #elif defined(AFS_SGI_ENV)
949 OSI_SET_CURRENT_CRED(tmpcred); /* restore original credentials */
950 #elif defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
951 credp = tmpcred; /* restore original credentials */
953 osi_curcred() = tmpcred; /* restore original credentials */
954 #endif /* AFS_HPUX101_ENV */
955 crfree(foreigncreds);
958 #endif /* AFS_NEED_CLIENTCONTEXT */
960 #ifdef AFS_LINUX22_ENV
963 AFS_RELE(vp); /* put vnode back */
967 #if defined(KERNEL_HAVE_UERROR)
970 return (getuerror());
976 #define MAXPIOCTLTOKENLEN \
977 (3*sizeof(afs_int32)+MAXKTCTICKETLEN+sizeof(struct ClearToken)+MAXKTCREALMLEN)
980 afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
981 register struct afs_ioctl *ablob, int afollow,
982 struct AFS_UCRED **acred)
985 struct vrequest treq;
986 register afs_int32 code;
987 register afs_int32 function, device;
988 afs_int32 inSize, outSize, outSizeMax;
989 char *inData, *outData;
990 int (*(*pioctlSw)) ();
992 struct afs_fakestat_state fakestate;
994 avc = avp ? VTOAFS(avp) : NULL;
995 afs_Trace3(afs_iclSetp, CM_TRACE_PIOCTL, ICL_TYPE_INT32, acom & 0xff,
996 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, afollow);
997 AFS_STATCNT(HandlePioctl);
998 if ((code = afs_InitReq(&treq, *acred)))
1000 afs_InitFakeStat(&fakestate);
1002 code = afs_EvalFakeStat(&avc, &fakestate, &treq);
1004 afs_PutFakeStat(&fakestate);
1008 device = (acom & 0xff00) >> 8;
1010 case 'V': /* Original pioctls */
1011 pioctlSw = VpioctlSw;
1012 pioctlSwSize = sizeof(VpioctlSw);
1014 case 'C': /* Coordinated/common pioctls */
1015 pioctlSw = CpioctlSw;
1016 pioctlSwSize = sizeof(CpioctlSw);
1018 case 'O': /* Coordinated/common pioctls */
1019 pioctlSw = OpioctlSw;
1020 pioctlSwSize = sizeof(OpioctlSw);
1023 afs_PutFakeStat(&fakestate);
1026 function = acom & 0xff;
1027 if (function >= (pioctlSwSize / sizeof(char *))) {
1028 afs_PutFakeStat(&fakestate);
1029 return EINVAL; /* out of range */
1031 inSize = ablob->in_size;
1033 /* Do all range checking before continuing */
1034 if (inSize > MAXPIOCTLTOKENLEN || inSize < 0 || ablob->out_size < 0)
1037 /* Note that we use osi_Alloc for large allocs and osi_AllocLargeSpace for small ones */
1038 if (inSize > AFS_LRALLOCSIZ) {
1039 inData = osi_Alloc(inSize + 1);
1041 inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1046 AFS_COPYIN(ablob->in, inData, inSize, code);
1047 inData[inSize] = '\0';
1051 if (inSize > AFS_LRALLOCSIZ) {
1052 osi_Free(inData, inSize + 1);
1054 osi_FreeLargeSpace(inData);
1056 afs_PutFakeStat(&fakestate);
1059 if (function == 8 && device == 'V') { /* PGetTokens */
1060 outSizeMax = MAXPIOCTLTOKENLEN;
1061 outData = osi_Alloc(outSizeMax);
1063 outSizeMax = AFS_LRALLOCSIZ;
1064 outData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1067 if (inSize > AFS_LRALLOCSIZ) {
1068 osi_Free(inData, inSize + 1);
1070 osi_FreeLargeSpace(inData);
1072 afs_PutFakeStat(&fakestate);
1077 (*pioctlSw[function]) (avc, function, &treq, inData, outData, inSize,
1079 if (inSize > AFS_LRALLOCSIZ) {
1080 osi_Free(inData, inSize + 1);
1082 osi_FreeLargeSpace(inData);
1084 if (code == 0 && ablob->out_size > 0) {
1085 if (outSize > ablob->out_size) {
1086 code = E2BIG; /* data wont fit in user buffer */
1087 } else if (outSize) {
1088 AFS_COPYOUT(outData, ablob->out, outSize, code);
1091 if (outSizeMax > AFS_LRALLOCSIZ) {
1092 osi_Free(outData, outSizeMax);
1094 osi_FreeLargeSpace(outData);
1096 afs_PutFakeStat(&fakestate);
1097 return afs_CheckCode(code, &treq, 41);
1100 DECL_PIOCTL(PGetFID)
1102 AFS_STATCNT(PGetFID);
1105 memcpy(aout, (char *)&avc->fid, sizeof(struct VenusFid));
1106 *aoutSize = sizeof(struct VenusFid);
1110 DECL_PIOCTL(PSetAcl)
1112 register afs_int32 code;
1114 struct AFSOpaque acl;
1115 struct AFSVolSync tsync;
1116 struct AFSFetchStatus OutStatus;
1119 AFS_STATCNT(PSetAcl);
1122 if ((acl.AFSOpaque_len = strlen(ain) + 1) > 1024 /* AFSOPAQUEMAX */)
1125 acl.AFSOpaque_val = ain;
1127 tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1129 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREACL);
1132 RXAFS_StoreACL(tconn->id, (struct AFSFid *)&avc->fid.Fid,
1133 &acl, &OutStatus, &tsync);
1138 } while (afs_Analyze
1139 (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_STOREACL,
1140 SHARED_LOCK, NULL));
1142 /* now we've forgotten all of the access info */
1143 ObtainWriteLock(&afs_xcbhash, 455);
1145 afs_DequeueCallback(avc);
1146 avc->states &= ~(CStatd | CUnique);
1147 ReleaseWriteLock(&afs_xcbhash);
1148 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
1149 osi_dnlc_purgedp(avc);
1153 int afs_defaultAsynchrony = 0;
1155 DECL_PIOCTL(PStoreBehind)
1158 struct sbstruct *sbr;
1160 sbr = (struct sbstruct *)ain;
1161 if (sbr->sb_default != -1) {
1162 if (afs_osi_suser(*acred))
1163 afs_defaultAsynchrony = sbr->sb_default;
1168 if (avc && (sbr->sb_thisfile != -1)) {
1170 (avc, PRSFS_WRITE | PRSFS_ADMINISTER, areq, DONT_CHECK_MODE_BITS))
1171 avc->asynchrony = sbr->sb_thisfile;
1176 *aoutSize = sizeof(struct sbstruct);
1177 sbr = (struct sbstruct *)aout;
1178 sbr->sb_default = afs_defaultAsynchrony;
1180 sbr->sb_thisfile = avc->asynchrony;
1186 DECL_PIOCTL(PGCPAGs)
1188 if (!afs_osi_suser(*acred)) {
1191 afs_gcpags = AFS_GCPAGS_USERDISABLED;
1195 DECL_PIOCTL(PGetAcl)
1197 struct AFSOpaque acl;
1198 struct AFSVolSync tsync;
1199 struct AFSFetchStatus OutStatus;
1205 AFS_STATCNT(PGetAcl);
1208 Fid.Volume = avc->fid.Fid.Volume;
1209 Fid.Vnode = avc->fid.Fid.Vnode;
1210 Fid.Unique = avc->fid.Fid.Unique;
1211 if (avc->states & CForeign) {
1213 * For a dfs xlator acl we have a special hack so that the
1214 * xlator will distinguish which type of acl will return. So
1215 * we currently use the top 2-bytes (vals 0-4) to tell which
1216 * type of acl to bring back. Horrible hack but this will
1217 * cause the least number of changes to code size and interfaces.
1219 if (Fid.Vnode & 0xc0000000)
1221 Fid.Vnode |= (ainSize << 30);
1223 acl.AFSOpaque_val = aout;
1225 tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1228 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHACL);
1230 code = RXAFS_FetchACL(tconn->id, &Fid, &acl, &OutStatus, &tsync);
1235 } while (afs_Analyze
1236 (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_FETCHACL,
1237 SHARED_LOCK, NULL));
1240 *aoutSize = (acl.AFSOpaque_len == 0 ? 1 : acl.AFSOpaque_len);
1253 AFS_STATCNT(PBogus);
1257 DECL_PIOCTL(PGetFileCell)
1259 register struct cell *tcell;
1261 AFS_STATCNT(PGetFileCell);
1264 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
1267 strcpy(aout, tcell->cellName);
1268 afs_PutCell(tcell, READ_LOCK);
1269 *aoutSize = strlen(aout) + 1;
1273 DECL_PIOCTL(PGetWSCell)
1275 struct cell *tcell = NULL;
1277 AFS_STATCNT(PGetWSCell);
1278 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1279 return EIO; /* Inappropriate ioctl for device */
1281 tcell = afs_GetPrimaryCell(READ_LOCK);
1282 if (!tcell) /* no primary cell? */
1284 strcpy(aout, tcell->cellName);
1285 *aoutSize = strlen(aout) + 1;
1286 afs_PutCell(tcell, READ_LOCK);
1290 DECL_PIOCTL(PGetUserCell)
1292 register afs_int32 i;
1293 register struct unixuser *tu;
1294 register struct cell *tcell;
1296 AFS_STATCNT(PGetUserCell);
1297 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1298 return EIO; /* Inappropriate ioctl for device */
1300 /* return the cell name of the primary cell for this user */
1301 i = UHash(areq->uid);
1302 ObtainWriteLock(&afs_xuser, 224);
1303 for (tu = afs_users[i]; tu; tu = tu->next) {
1304 if (tu->uid == areq->uid && (tu->states & UPrimary)) {
1306 ReleaseWriteLock(&afs_xuser);
1311 tcell = afs_GetCell(tu->cell, READ_LOCK);
1312 afs_PutUser(tu, WRITE_LOCK);
1316 strcpy(aout, tcell->cellName);
1317 afs_PutCell(tcell, READ_LOCK);
1318 *aoutSize = strlen(aout) + 1; /* 1 for the null */
1321 ReleaseWriteLock(&afs_xuser);
1328 DECL_PIOCTL(PSetTokens)
1331 register struct unixuser *tu;
1332 struct ClearToken clear;
1333 register struct cell *tcell;
1336 struct vrequest treq;
1337 afs_int32 flag, set_parent_pag = 0;
1339 AFS_STATCNT(PSetTokens);
1340 if (!afs_resourceinit_flag) {
1343 memcpy((char *)&i, ain, sizeof(afs_int32));
1344 ain += sizeof(afs_int32);
1345 stp = ain; /* remember where the ticket is */
1346 if (i < 0 || i > MAXKTCTICKETLEN)
1347 return EINVAL; /* malloc may fail */
1349 ain += i; /* skip over ticket */
1350 memcpy((char *)&i, ain, sizeof(afs_int32));
1351 ain += sizeof(afs_int32);
1352 if (i != sizeof(struct ClearToken)) {
1355 memcpy((char *)&clear, ain, sizeof(struct ClearToken));
1356 if (clear.AuthHandle == -1)
1357 clear.AuthHandle = 999; /* more rxvab compat stuff */
1358 ain += sizeof(struct ClearToken);
1359 if (ainSize != 2 * sizeof(afs_int32) + stLen + sizeof(struct ClearToken)) {
1360 /* still stuff left? we've got primary flag and cell name. Set these */
1361 memcpy((char *)&flag, ain, sizeof(afs_int32)); /* primary id flag */
1362 ain += sizeof(afs_int32); /* skip id field */
1363 /* rest is cell name, look it up */
1364 /* some versions of gcc appear to need != 0 in order to get this right */
1365 if ((flag & 0x8000) != 0) { /* XXX Use Constant XXX */
1369 tcell = afs_GetCellByName(ain, READ_LOCK);
1373 /* default to primary cell, primary id */
1374 flag = 1; /* primary id */
1375 tcell = afs_GetPrimaryCell(READ_LOCK);
1380 afs_PutCell(tcell, READ_LOCK);
1381 if (set_parent_pag) {
1383 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1384 #if defined(AFS_DARWIN_ENV)
1385 struct proc *p = current_proc(); /* XXX */
1387 struct proc *p = curproc; /* XXX */
1389 #ifndef AFS_DARWIN80_ENV
1390 uprintf("Process %d (%s) tried to change pags in PSetTokens\n",
1391 p->p_pid, p->p_comm);
1393 if (!setpag(p, acred, -1, &pag, 1)) {
1396 if (!setpag(u.u_procp, acred, -1, &pag, 1)) { /* XXX u.u_procp is a no-op XXX */
1398 if (!setpag(acred, -1, &pag, 1)) {
1401 afs_InitReq(&treq, *acred);
1405 /* now we just set the tokens */
1406 tu = afs_GetUser(areq->uid, i, WRITE_LOCK); /* i has the cell # */
1407 tu->vid = clear.ViceId;
1408 if (tu->stp != NULL) {
1409 afs_osi_Free(tu->stp, tu->stLen);
1411 tu->stp = (char *)afs_osi_Alloc(stLen);
1413 memcpy(tu->stp, stp, stLen);
1416 afs_stats_cmfullperf.authent.TicketUpdates++;
1417 afs_ComputePAGStats();
1418 #endif /* AFS_NOSTATS */
1419 tu->states |= UHasTokens;
1420 tu->states &= ~UTokensBad;
1421 afs_SetPrimary(tu, flag);
1422 tu->tokenTime = osi_Time();
1423 afs_ResetUserConns(tu);
1424 afs_PutUser(tu, WRITE_LOCK);
1439 DECL_PIOCTL(PGetVolumeStatus)
1442 char *offLineMsg = afs_osi_Alloc(256);
1443 char *motd = afs_osi_Alloc(256);
1444 register struct conn *tc;
1445 register afs_int32 code = 0;
1446 struct AFSFetchVolumeStatus volstat;
1448 char *Name, *OfflineMsg, *MOTD;
1451 AFS_STATCNT(PGetVolumeStatus);
1457 OfflineMsg = offLineMsg;
1460 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1462 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS);
1465 RXAFS_GetVolumeStatus(tc->id, avc->fid.Fid.Volume, &volstat,
1466 &Name, &OfflineMsg, &MOTD);
1471 } while (afs_Analyze
1472 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS,
1473 SHARED_LOCK, NULL));
1477 /* Copy all this junk into msg->im_data, keeping track of the lengths. */
1479 memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
1480 cp += sizeof(VolumeStatus);
1481 strcpy(cp, volName);
1482 cp += strlen(volName) + 1;
1483 strcpy(cp, offLineMsg);
1484 cp += strlen(offLineMsg) + 1;
1486 cp += strlen(motd) + 1;
1487 *aoutSize = (cp - aout);
1489 afs_osi_Free(offLineMsg, 256);
1490 afs_osi_Free(motd, 256);
1494 DECL_PIOCTL(PSetVolumeStatus)
1497 char *offLineMsg = afs_osi_Alloc(256);
1498 char *motd = afs_osi_Alloc(256);
1499 register struct conn *tc;
1500 register afs_int32 code = 0;
1501 struct AFSFetchVolumeStatus volstat;
1502 struct AFSStoreVolumeStatus storeStat;
1503 register struct volume *tvp;
1507 AFS_STATCNT(PSetVolumeStatus);
1513 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
1515 if (tvp->states & (VRO | VBackup)) {
1516 afs_PutVolume(tvp, READ_LOCK);
1520 afs_PutVolume(tvp, READ_LOCK);
1525 /* Copy the junk out, using cp as a roving pointer. */
1527 memcpy((char *)&volstat, cp, sizeof(AFSFetchVolumeStatus));
1528 cp += sizeof(AFSFetchVolumeStatus);
1529 if (strlen(cp) >= sizeof(volName)) {
1533 strcpy(volName, cp);
1534 cp += strlen(volName) + 1;
1535 if (strlen(cp) >= sizeof(offLineMsg)) {
1539 strcpy(offLineMsg, cp);
1540 cp += strlen(offLineMsg) + 1;
1541 if (strlen(cp) >= sizeof(motd)) {
1547 if (volstat.MinQuota != -1) {
1548 storeStat.MinQuota = volstat.MinQuota;
1549 storeStat.Mask |= AFS_SETMINQUOTA;
1551 if (volstat.MaxQuota != -1) {
1552 storeStat.MaxQuota = volstat.MaxQuota;
1553 storeStat.Mask |= AFS_SETMAXQUOTA;
1556 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1558 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS);
1561 RXAFS_SetVolumeStatus(tc->id, avc->fid.Fid.Volume, &storeStat,
1562 volName, offLineMsg, motd);
1567 } while (afs_Analyze
1568 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS,
1569 SHARED_LOCK, NULL));
1573 /* we are sending parms back to make compat. with prev system. should
1574 * change interface later to not ask for current status, just set new status */
1576 memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
1577 cp += sizeof(VolumeStatus);
1578 strcpy(cp, volName);
1579 cp += strlen(volName) + 1;
1580 strcpy(cp, offLineMsg);
1581 cp += strlen(offLineMsg) + 1;
1583 cp += strlen(motd) + 1;
1584 *aoutSize = cp - aout;
1586 afs_osi_Free(offLineMsg, 256);
1587 afs_osi_Free(motd, 256);
1593 AFS_STATCNT(PFlush);
1596 #ifdef AFS_BOZONLOCK_ENV
1597 afs_BozonLock(&avc->pvnLock, avc); /* Since afs_TryToSmush will do a pvn_vptrunc */
1599 ObtainWriteLock(&avc->lock, 225);
1600 ObtainWriteLock(&afs_xcbhash, 456);
1601 afs_DequeueCallback(avc);
1602 avc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
1603 ReleaseWriteLock(&afs_xcbhash);
1604 /* now find the disk cache entries */
1605 afs_TryToSmush(avc, *acred, 1);
1606 osi_dnlc_purgedp(avc);
1607 if (avc->linkData && !(avc->states & CCore)) {
1608 afs_osi_Free(avc->linkData, strlen(avc->linkData) + 1);
1609 avc->linkData = NULL;
1611 ReleaseWriteLock(&avc->lock);
1612 #ifdef AFS_BOZONLOCK_ENV
1613 afs_BozonUnlock(&avc->pvnLock, avc);
1618 DECL_PIOCTL(PNewStatMount)
1620 register afs_int32 code;
1621 register struct vcache *tvc;
1622 register struct dcache *tdc;
1623 struct VenusFid tfid;
1625 struct sysname_info sysState;
1626 afs_size_t offset, len;
1628 AFS_STATCNT(PNewStatMount);
1631 code = afs_VerifyVCache(avc, areq);
1634 if (vType(avc) != VDIR) {
1637 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
1640 Check_AtSys(avc, ain, &sysState, areq);
1641 ObtainReadLock(&tdc->lock);
1643 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
1644 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
1645 ReleaseReadLock(&tdc->lock);
1646 afs_PutDCache(tdc); /* we're done with the data */
1647 bufp = sysState.name;
1651 tfid.Cell = avc->fid.Cell;
1652 tfid.Fid.Volume = avc->fid.Fid.Volume;
1653 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
1654 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
1656 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
1662 if (tvc->mvstat != 1) {
1667 ObtainWriteLock(&tvc->lock, 226);
1668 code = afs_HandleLink(tvc, areq);
1670 if (tvc->linkData) {
1671 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
1674 /* we have the data */
1675 strcpy(aout, tvc->linkData);
1676 *aoutSize = strlen(tvc->linkData) + 1;
1681 ReleaseWriteLock(&tvc->lock);
1684 if (sysState.allocked)
1685 osi_FreeLargeSpace(bufp);
1689 DECL_PIOCTL(PGetTokens)
1691 register struct cell *tcell;
1692 register afs_int32 i;
1693 register struct unixuser *tu;
1698 AFS_STATCNT(PGetTokens);
1699 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1700 return EIO; /* Inappropriate ioctl for device */
1702 /* weird interface. If input parameter is present, it is an integer and
1703 * we're supposed to return the parm'th tokens for this unix uid.
1704 * If not present, we just return tokens for cell 1.
1705 * If counter out of bounds, return EDOM.
1706 * If no tokens for the particular cell, return ENOTCONN.
1707 * Also, if this mysterious parm is present, we return, along with the
1708 * tokens, the primary cell indicator (an afs_int32 0) and the cell name
1709 * at the end, in that order.
1711 if ((newStyle = (ainSize > 0))) {
1712 memcpy((char *)&iterator, ain, sizeof(afs_int32));
1714 i = UHash(areq->uid);
1715 ObtainReadLock(&afs_xuser);
1716 for (tu = afs_users[i]; tu; tu = tu->next) {
1718 if (tu->uid == areq->uid && (tu->states & UHasTokens)) {
1719 if (iterator-- == 0)
1720 break; /* are we done yet? */
1723 if (tu->uid == areq->uid && afs_IsPrimaryCellNum(tu->cell))
1729 * No need to hold a read lock on each user entry
1733 ReleaseReadLock(&afs_xuser);
1738 if (((tu->states & UHasTokens) == 0)
1739 || (tu->ct.EndTimestamp < osi_Time())) {
1740 tu->states |= (UTokensBad | UNeedsReset);
1741 afs_PutUser(tu, READ_LOCK);
1744 /* use iterator for temp */
1746 iterator = tu->stLen; /* for compat, we try to return 56 byte tix if they fit */
1748 iterator = 56; /* # of bytes we're returning */
1749 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1750 cp += sizeof(afs_int32);
1751 memcpy(cp, tu->stp, tu->stLen); /* copy out st */
1753 iterator = sizeof(struct ClearToken);
1754 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1755 cp += sizeof(afs_int32);
1756 memcpy(cp, (char *)&tu->ct, sizeof(struct ClearToken));
1757 cp += sizeof(struct ClearToken);
1759 /* put out primary id and cell name, too */
1760 iterator = (tu->states & UPrimary ? 1 : 0);
1761 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1762 cp += sizeof(afs_int32);
1763 tcell = afs_GetCell(tu->cell, READ_LOCK);
1765 strcpy(cp, tcell->cellName);
1766 cp += strlen(tcell->cellName) + 1;
1767 afs_PutCell(tcell, READ_LOCK);
1771 *aoutSize = cp - aout;
1772 afs_PutUser(tu, READ_LOCK);
1778 register afs_int32 i;
1779 register struct unixuser *tu;
1781 AFS_STATCNT(PUnlog);
1782 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1783 return EIO; /* Inappropriate ioctl for device */
1785 i = UHash(areq->uid);
1786 ObtainWriteLock(&afs_xuser, 227);
1787 for (tu = afs_users[i]; tu; tu = tu->next) {
1788 if (tu->uid == areq->uid) {
1790 tu->states &= ~UHasTokens;
1791 /* security is not having to say you're sorry */
1792 memset((char *)&tu->ct, 0, sizeof(struct ClearToken));
1794 ReleaseWriteLock(&afs_xuser);
1795 /* We have to drop the lock over the call to afs_ResetUserConns, since
1796 * it obtains the afs_xvcache lock. We could also keep the lock, and
1797 * modify ResetUserConns to take parm saying we obtained the lock
1798 * already, but that is overkill. By keeping the "tu" pointer
1799 * held over the released lock, we guarantee that we won't lose our
1800 * place, and that we'll pass over every user conn that existed when
1801 * we began this call.
1803 afs_ResetUserConns(tu);
1805 ObtainWriteLock(&afs_xuser, 228);
1807 /* set the expire times to 0, causes
1808 * afs_GCUserData to remove this entry
1810 tu->ct.EndTimestamp = 0;
1812 #endif /* UKERNEL */
1815 ReleaseWriteLock(&afs_xuser);
1819 DECL_PIOCTL(PMariner)
1821 afs_int32 newHostAddr;
1822 afs_int32 oldHostAddr;
1824 AFS_STATCNT(PMariner);
1826 memcpy((char *)&oldHostAddr, (char *)&afs_marinerHost,
1829 oldHostAddr = 0xffffffff; /* disabled */
1831 memcpy((char *)&newHostAddr, ain, sizeof(afs_int32));
1832 if (newHostAddr == 0xffffffff) {
1833 /* disable mariner operations */
1835 } else if (newHostAddr) {
1837 afs_marinerHost = newHostAddr;
1839 memcpy(aout, (char *)&oldHostAddr, sizeof(afs_int32));
1840 *aoutSize = sizeof(afs_int32);
1844 DECL_PIOCTL(PCheckServers)
1846 register char *cp = 0;
1848 register struct server *ts;
1849 afs_int32 temp, *lp = (afs_int32 *) ain, havecell = 0;
1851 struct chservinfo *pcheck;
1853 AFS_STATCNT(PCheckServers);
1855 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1856 return EIO; /* Inappropriate ioctl for device */
1858 if (*lp == 0x12345678) { /* For afs3.3 version */
1859 pcheck = (struct chservinfo *)ain;
1860 if (pcheck->tinterval >= 0) {
1862 memcpy(cp, (char *)&afs_probe_interval, sizeof(afs_int32));
1863 *aoutSize = sizeof(afs_int32);
1864 if (pcheck->tinterval > 0) {
1865 if (!afs_osi_suser(*acred))
1867 afs_probe_interval = pcheck->tinterval;
1873 temp = pcheck->tflags;
1874 cp = pcheck->tbuffer;
1875 } else { /* For pre afs3.3 versions */
1876 memcpy((char *)&temp, ain, sizeof(afs_int32));
1877 cp = ain + sizeof(afs_int32);
1878 if (ainSize > sizeof(afs_int32))
1883 * 1: fast check, don't contact servers.
1884 * 2: local cell only.
1887 /* have cell name, too */
1888 cellp = afs_GetCellByName(cp, READ_LOCK);
1893 if (!cellp && (temp & 2)) {
1894 /* use local cell */
1895 cellp = afs_GetPrimaryCell(READ_LOCK);
1897 if (!(temp & 1)) { /* if not fast, call server checker routine */
1898 afs_CheckServers(1, cellp); /* check down servers */
1899 afs_CheckServers(0, cellp); /* check up servers */
1901 /* now return the current down server list */
1903 ObtainReadLock(&afs_xserver);
1904 for (i = 0; i < NSERVERS; i++) {
1905 for (ts = afs_servers[i]; ts; ts = ts->next) {
1906 if (cellp && ts->cell != cellp)
1907 continue; /* cell spec'd and wrong */
1908 if ((ts->flags & SRVR_ISDOWN)
1909 && ts->addr->sa_portal != ts->cell->vlport) {
1910 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
1911 cp += sizeof(afs_int32);
1915 ReleaseReadLock(&afs_xserver);
1917 afs_PutCell(cellp, READ_LOCK);
1918 *aoutSize = cp - aout;
1922 DECL_PIOCTL(PCheckVolNames)
1924 AFS_STATCNT(PCheckVolNames);
1925 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1926 return EIO; /* Inappropriate ioctl for device */
1928 afs_CheckRootVolume();
1929 afs_CheckVolumeNames(AFS_VOLCHECK_FORCE | AFS_VOLCHECK_EXPIRED |
1930 AFS_VOLCHECK_BUSY | AFS_VOLCHECK_MTPTS);
1934 DECL_PIOCTL(PCheckAuth)
1939 struct unixuser *tu;
1942 AFS_STATCNT(PCheckAuth);
1943 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1944 return EIO; /* Inappropriate ioctl for device */
1947 tu = afs_GetUser(areq->uid, 1, READ_LOCK); /* check local cell authentication */
1951 /* we have a user */
1952 ObtainReadLock(&afs_xsrvAddr);
1953 ObtainReadLock(&afs_xconn);
1955 /* any tokens set? */
1956 if ((tu->states & UHasTokens) == 0)
1958 /* all connections in cell 1 working? */
1959 for (i = 0; i < NSERVERS; i++) {
1960 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
1961 for (tc = sa->conns; tc; tc = tc->next) {
1962 if (tc->user == tu && (tu->states & UTokensBad))
1967 ReleaseReadLock(&afs_xsrvAddr);
1968 ReleaseReadLock(&afs_xconn);
1969 afs_PutUser(tu, READ_LOCK);
1971 memcpy(aout, (char *)&retValue, sizeof(afs_int32));
1972 *aoutSize = sizeof(afs_int32);
1977 Prefetch(char *apath, struct afs_ioctl *adata, int afollow,
1978 struct AFS_UCRED *acred)
1981 register afs_int32 code;
1982 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1988 AFS_STATCNT(Prefetch);
1991 tp = osi_AllocLargeSpace(1024);
1992 AFS_COPYINSTR(apath, tp, 1024, &bufferSize, code);
1994 osi_FreeLargeSpace(tp);
1997 if (afs_BBusy()) { /* do this as late as possible */
1998 osi_FreeLargeSpace(tp);
1999 return EWOULDBLOCK; /* pretty close */
2001 afs_BQueue(BOP_PATH, (struct vcache *)0, 0, 0, acred, (afs_size_t) 0,
2002 (afs_size_t) 0, tp);
2006 DECL_PIOCTL(PFindVolume)
2008 register struct volume *tvp;
2009 register struct server *ts;
2010 register afs_int32 i;
2013 AFS_STATCNT(PFindVolume);
2016 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
2019 for (i = 0; i < MAXHOSTS; i++) {
2020 ts = tvp->serverHost[i];
2023 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
2024 cp += sizeof(afs_int32);
2027 /* still room for terminating NULL, add it on */
2028 ainSize = 0; /* reuse vbl */
2029 memcpy(cp, (char *)&ainSize, sizeof(afs_int32));
2030 cp += sizeof(afs_int32);
2032 *aoutSize = cp - aout;
2033 afs_PutVolume(tvp, READ_LOCK);
2039 DECL_PIOCTL(PViceAccess)
2041 register afs_int32 code;
2044 AFS_STATCNT(PViceAccess);
2047 code = afs_VerifyVCache(avc, areq);
2050 memcpy((char *)&temp, ain, sizeof(afs_int32));
2051 code = afs_AccessOK(avc, temp, areq, CHECK_MODE_BITS);
2058 DECL_PIOCTL(PSetCacheSize)
2063 AFS_STATCNT(PSetCacheSize);
2064 if (!afs_osi_suser(*acred))
2066 /* too many things are setup initially in mem cache version */
2067 if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
2069 memcpy((char *)&newValue, ain, sizeof(afs_int32));
2071 afs_cacheBlocks = afs_stats_cmperf.cacheBlocksOrig;
2073 if (newValue < afs_min_cache)
2074 afs_cacheBlocks = afs_min_cache;
2076 afs_cacheBlocks = newValue;
2078 afs_stats_cmperf.cacheBlocksTotal = afs_cacheBlocks;
2079 afs_ComputeCacheParms(); /* recompute basic cache parameters */
2080 afs_MaybeWakeupTruncateDaemon();
2081 while (waitcnt++ < 100 && afs_cacheBlocks < afs_blocksUsed) {
2082 afs_osi_Wait(1000, 0, 0);
2083 afs_MaybeWakeupTruncateDaemon();
2088 #define MAXGCSTATS 16
2089 DECL_PIOCTL(PGetCacheSize)
2091 afs_int32 results[MAXGCSTATS];
2093 register struct dcache * tdc;
2096 AFS_STATCNT(PGetCacheSize);
2098 if (sizeof(afs_int32) == ainSize){
2099 memcpy((char *)&flags, ain, sizeof(afs_int32));
2100 } else if (0 == ainSize){
2106 memset((char *)results, 0, sizeof(results));
2107 results[0] = afs_cacheBlocks;
2108 results[1] = afs_blocksUsed;
2109 results[2] = afs_cacheFiles;
2112 for (i = 0; i < afs_cacheFiles; i++) {
2113 if (afs_indexFlags[i] & IFFree) results[3]++;
2115 } else if (2 == flags){
2116 for (i = 0; i < afs_cacheFiles; i++) {
2117 if (afs_indexFlags[i] & IFFree) results[3]++;
2118 if (afs_indexFlags[i] & IFEverUsed) results[4]++;
2119 if (afs_indexFlags[i] & IFDataMod) results[5]++;
2120 if (afs_indexFlags[i] & IFDirtyPages) results[6]++;
2121 if (afs_indexFlags[i] & IFAnyPages) results[7]++;
2122 if (afs_indexFlags[i] & IFDiscarded) results[8]++;
2124 tdc = afs_indexTable[i];
2127 size = tdc->validPos;
2128 if ( 0 < size && size < (1<<12) ) results[10]++;
2129 else if (size < (1<<14) ) results[11]++;
2130 else if (size < (1<<16) ) results[12]++;
2131 else if (size < (1<<18) ) results[13]++;
2132 else if (size < (1<<20) ) results[14]++;
2133 else if (size >= (1<<20) ) results[15]++;
2137 memcpy(aout, (char *)results, sizeof(results));
2138 *aoutSize = sizeof(results);
2142 DECL_PIOCTL(PRemoveCallBack)
2144 register struct conn *tc;
2145 register afs_int32 code = 0;
2146 struct AFSCallBack CallBacks_Array[1];
2147 struct AFSCBFids theFids;
2148 struct AFSCBs theCBs;
2151 AFS_STATCNT(PRemoveCallBack);
2154 if (avc->states & CRO)
2155 return 0; /* read-only-ness can't change */
2156 ObtainWriteLock(&avc->lock, 229);
2157 theFids.AFSCBFids_len = 1;
2158 theCBs.AFSCBs_len = 1;
2159 theFids.AFSCBFids_val = (struct AFSFid *)&avc->fid.Fid;
2160 theCBs.AFSCBs_val = CallBacks_Array;
2161 CallBacks_Array[0].CallBackType = CB_DROPPED;
2162 if (avc->callback) {
2164 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2166 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
2168 code = RXAFS_GiveUpCallBacks(tc->id, &theFids, &theCBs);
2172 /* don't set code on failure since we wouldn't use it */
2173 } while (afs_Analyze
2174 (tc, code, &avc->fid, areq,
2175 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK, NULL));
2177 ObtainWriteLock(&afs_xcbhash, 457);
2178 afs_DequeueCallback(avc);
2180 avc->states &= ~(CStatd | CUnique);
2181 ReleaseWriteLock(&afs_xcbhash);
2182 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
2183 osi_dnlc_purgedp(avc);
2185 ReleaseWriteLock(&avc->lock);
2189 DECL_PIOCTL(PNewCell)
2191 /* create a new cell */
2192 afs_int32 cellHosts[MAXCELLHOSTS], *lp, magic = 0;
2193 char *newcell = 0, *linkedcell = 0, *tp = ain;
2194 register afs_int32 code, linkedstate = 0, ls;
2195 u_short fsport = 0, vlport = 0;
2198 AFS_STATCNT(PNewCell);
2199 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2200 return EIO; /* Inappropriate ioctl for device */
2202 if (!afs_osi_suser(*acred))
2205 memcpy((char *)&magic, tp, sizeof(afs_int32));
2206 tp += sizeof(afs_int32);
2207 if (magic != 0x12345678)
2210 /* A 3.4 fs newcell command will pass an array of MAXCELLHOSTS
2211 * server addresses while the 3.5 fs newcell command passes
2212 * MAXHOSTS. To figure out which is which, check if the cellname
2215 newcell = tp + (MAXCELLHOSTS + 3) * sizeof(afs_int32);
2216 scount = ((newcell[0] != '\0') ? MAXCELLHOSTS : MAXHOSTS);
2218 /* MAXCELLHOSTS (=8) is less than MAXHOSTS (=13) */
2219 memcpy((char *)cellHosts, tp, MAXCELLHOSTS * sizeof(afs_int32));
2220 tp += (scount * sizeof(afs_int32));
2222 lp = (afs_int32 *) tp;
2226 fsport = 0; /* Privileged ports not allowed */
2228 vlport = 0; /* Privileged ports not allowed */
2229 tp += (3 * sizeof(afs_int32));
2231 if ((ls = *lp) & 1) {
2232 linkedcell = tp + strlen(newcell) + 1;
2233 linkedstate |= CLinkedCell;
2236 linkedstate |= CNoSUID; /* setuid is disabled by default for fs newcell */
2238 afs_NewCell(newcell, cellHosts, linkedstate, linkedcell, fsport,
2243 DECL_PIOCTL(PNewAlias)
2245 /* create a new cell alias */
2247 register afs_int32 code;
2248 char *realName, *aliasName;
2250 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2251 return EIO; /* Inappropriate ioctl for device */
2253 if (!afs_osi_suser(*acred))
2257 tp += strlen(aliasName) + 1;
2260 code = afs_NewCellAlias(aliasName, realName);
2265 DECL_PIOCTL(PListCells)
2267 afs_int32 whichCell;
2268 register struct cell *tcell = 0;
2269 register afs_int32 i;
2270 register char *cp, *tp = ain;
2272 AFS_STATCNT(PListCells);
2273 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2274 return EIO; /* Inappropriate ioctl for device */
2276 memcpy((char *)&whichCell, tp, sizeof(afs_int32));
2277 tp += sizeof(afs_int32);
2278 tcell = afs_GetCellByIndex(whichCell, READ_LOCK);
2281 memset(cp, 0, MAXCELLHOSTS * sizeof(afs_int32));
2282 for (i = 0; i < MAXCELLHOSTS; i++) {
2283 if (tcell->cellHosts[i] == 0)
2285 memcpy(cp, (char *)&tcell->cellHosts[i]->addr->sa_ip,
2287 cp += sizeof(afs_int32);
2289 cp = aout + MAXCELLHOSTS * sizeof(afs_int32);
2290 strcpy(cp, tcell->cellName);
2291 cp += strlen(tcell->cellName) + 1;
2292 *aoutSize = cp - aout;
2293 afs_PutCell(tcell, READ_LOCK);
2301 DECL_PIOCTL(PListAliases)
2303 afs_int32 whichAlias;
2304 register struct cell_alias *tcalias = 0;
2305 register char *cp, *tp = ain;
2307 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2308 return EIO; /* Inappropriate ioctl for device */
2309 if (ainSize < sizeof(afs_int32))
2312 memcpy((char *)&whichAlias, tp, sizeof(afs_int32));
2313 tp += sizeof(afs_int32);
2315 tcalias = afs_GetCellAlias(whichAlias);
2318 strcpy(cp, tcalias->alias);
2319 cp += strlen(tcalias->alias) + 1;
2320 strcpy(cp, tcalias->cell);
2321 cp += strlen(tcalias->cell) + 1;
2322 *aoutSize = cp - aout;
2323 afs_PutCellAlias(tcalias);
2331 DECL_PIOCTL(PRemoveMount)
2333 register afs_int32 code;
2335 struct sysname_info sysState;
2336 afs_size_t offset, len;
2337 register struct conn *tc;
2338 register struct dcache *tdc;
2339 register struct vcache *tvc;
2340 struct AFSFetchStatus OutDirStatus;
2341 struct VenusFid tfid;
2342 struct AFSVolSync tsync;
2346 /* "ain" is the name of the file in this dir to remove */
2348 AFS_STATCNT(PRemoveMount);
2351 code = afs_VerifyVCache(avc, areq);
2354 if (vType(avc) != VDIR)
2357 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1); /* test for error below */
2360 Check_AtSys(avc, ain, &sysState, areq);
2361 ObtainReadLock(&tdc->lock);
2363 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
2364 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
2365 ReleaseReadLock(&tdc->lock);
2366 bufp = sysState.name;
2371 tfid.Cell = avc->fid.Cell;
2372 tfid.Fid.Volume = avc->fid.Fid.Volume;
2373 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
2374 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
2376 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
2383 if (tvc->mvstat != 1) {
2389 ObtainWriteLock(&tvc->lock, 230);
2390 code = afs_HandleLink(tvc, areq);
2392 if (tvc->linkData) {
2393 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
2398 ReleaseWriteLock(&tvc->lock);
2399 osi_dnlc_purgedp(tvc);
2405 ObtainWriteLock(&avc->lock, 231);
2406 osi_dnlc_remove(avc, bufp, tvc);
2408 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2410 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE);
2413 RXAFS_RemoveFile(tc->id, (struct AFSFid *)&avc->fid.Fid, bufp,
2414 &OutDirStatus, &tsync);
2419 } while (afs_Analyze
2420 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_REMOVEFILE,
2421 SHARED_LOCK, NULL));
2426 ReleaseWriteLock(&avc->lock);
2430 /* we have the thing in the cache */
2431 ObtainWriteLock(&tdc->lock, 661);
2432 if (afs_LocalHero(avc, tdc, &OutDirStatus, 1)) {
2433 /* we can do it locally */
2434 code = afs_dir_Delete(tdc, bufp);
2436 ZapDCE(tdc); /* surprise error -- invalid value */
2440 ReleaseWriteLock(&tdc->lock);
2441 afs_PutDCache(tdc); /* drop ref count */
2443 avc->states &= ~CUnique; /* For the dfs xlator */
2444 ReleaseWriteLock(&avc->lock);
2447 if (sysState.allocked)
2448 osi_FreeLargeSpace(bufp);
2452 DECL_PIOCTL(PVenusLogging)
2454 return EINVAL; /* OBSOLETE */
2457 DECL_PIOCTL(PGetCellStatus)
2459 register struct cell *tcell;
2462 AFS_STATCNT(PGetCellStatus);
2463 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2464 return EIO; /* Inappropriate ioctl for device */
2466 tcell = afs_GetCellByName(ain, READ_LOCK);
2469 temp = tcell->states;
2470 afs_PutCell(tcell, READ_LOCK);
2471 memcpy(aout, (char *)&temp, sizeof(afs_int32));
2472 *aoutSize = sizeof(afs_int32);
2476 DECL_PIOCTL(PSetCellStatus)
2478 register struct cell *tcell;
2481 if (!afs_osi_suser(*acred))
2483 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2484 return EIO; /* Inappropriate ioctl for device */
2486 tcell = afs_GetCellByName(ain + 2 * sizeof(afs_int32), WRITE_LOCK);
2489 memcpy((char *)&temp, ain, sizeof(afs_int32));
2491 tcell->states |= CNoSUID;
2493 tcell->states &= ~CNoSUID;
2494 afs_PutCell(tcell, WRITE_LOCK);
2498 DECL_PIOCTL(PFlushVolumeData)
2500 register afs_int32 i;
2501 register struct dcache *tdc;
2502 register struct vcache *tvc;
2503 register struct volume *tv;
2504 afs_int32 cell, volume;
2505 struct afs_q *tq, *uq;
2506 #ifdef AFS_DARWIN80_ENV
2510 AFS_STATCNT(PFlushVolumeData);
2513 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2514 return EIO; /* Inappropriate ioctl for device */
2516 volume = avc->fid.Fid.Volume; /* who to zap */
2517 cell = avc->fid.Cell;
2520 * Clear stat'd flag from all vnodes from this volume; this will invalidate all
2521 * the vcaches associated with the volume.
2524 ObtainReadLock(&afs_xvcache);
2525 i = VCHashV(&avc->fid);
2526 for (tq = afs_vhashTV[i].prev; tq != &afs_vhashTV[i]; tq = uq) {
2529 if (tvc->fid.Fid.Volume == volume && tvc->fid.Cell == cell) {
2530 if (tvc->states & CVInit) {
2531 ReleaseReadLock(&afs_xvcache);
2532 afs_osi_Sleep(&tvc->states);
2535 #ifdef AFS_DARWIN80_ENV
2536 if (tvc->states & CDeadVnode) {
2537 ReleaseReadLock(&afs_xvcache);
2538 afs_osi_Sleep(&tvc->states);
2542 #if defined(AFS_SGI_ENV) || defined(AFS_OSF_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
2543 VN_HOLD(AFSTOV(tvc));
2545 #ifdef AFS_DARWIN80_ENV
2549 if (vnode_ref(vp)) {
2556 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2559 VREFCOUNT_INC(tvc); /* AIX, apparently */
2563 ReleaseReadLock(&afs_xvcache);
2564 #ifdef AFS_BOZONLOCK_ENV
2565 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
2567 ObtainWriteLock(&tvc->lock, 232);
2569 ObtainWriteLock(&afs_xcbhash, 458);
2570 afs_DequeueCallback(tvc);
2571 tvc->states &= ~(CStatd | CDirty);
2572 ReleaseWriteLock(&afs_xcbhash);
2573 if (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
2574 osi_dnlc_purgedp(tvc);
2575 afs_TryToSmush(tvc, *acred, 1);
2576 ReleaseWriteLock(&tvc->lock);
2577 #ifdef AFS_BOZONLOCK_ENV
2578 afs_BozonUnlock(&tvc->pvnLock, tvc);
2580 #ifdef AFS_DARWIN80_ENV
2581 vnode_put(AFSTOV(tvc));
2583 ObtainReadLock(&afs_xvcache);
2585 /* our tvc ptr is still good until now */
2589 ReleaseReadLock(&afs_xvcache);
2592 MObtainWriteLock(&afs_xdcache, 328); /* needed if you're going to flush any stuff */
2593 for (i = 0; i < afs_cacheFiles; i++) {
2594 if (!(afs_indexFlags[i] & IFEverUsed))
2595 continue; /* never had any data */
2596 tdc = afs_GetDSlot(i, NULL);
2597 if (tdc->refCount <= 1) { /* too high, in use by running sys call */
2598 ReleaseReadLock(&tdc->tlock);
2599 if (tdc->f.fid.Fid.Volume == volume && tdc->f.fid.Cell == cell) {
2600 if (!(afs_indexFlags[i] & IFDataMod)) {
2601 /* if the file is modified, but has a ref cnt of only 1, then
2602 * someone probably has the file open and is writing into it.
2603 * Better to skip flushing such a file, it will be brought back
2604 * immediately on the next write anyway.
2606 * If we *must* flush, then this code has to be rearranged to call
2607 * afs_storeAllSegments() first */
2608 afs_FlushDCache(tdc);
2612 ReleaseReadLock(&tdc->tlock);
2614 afs_PutDCache(tdc); /* bumped by getdslot */
2616 MReleaseWriteLock(&afs_xdcache);
2618 ObtainReadLock(&afs_xvolume);
2619 for (i = 0; i < NVOLS; i++) {
2620 for (tv = afs_volumes[i]; tv; tv = tv->next) {
2621 if (tv->volume == volume) {
2622 afs_ResetVolumeInfo(tv);
2627 ReleaseReadLock(&afs_xvolume);
2629 /* probably, a user is doing this, probably, because things are screwed up.
2630 * maybe it's the dnlc's fault? */
2637 DECL_PIOCTL(PGetVnodeXStatus)
2639 register afs_int32 code;
2640 struct vcxstat stat;
2643 /* AFS_STATCNT(PGetVnodeXStatus); */
2646 code = afs_VerifyVCache(avc, areq);
2649 if (vType(avc) == VDIR)
2650 mode = PRSFS_LOOKUP;
2653 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
2656 memset(&stat, 0, sizeof(struct vcxstat));
2657 stat.fid = avc->fid;
2658 hset32(stat.DataVersion, hgetlo(avc->m.DataVersion));
2659 stat.lock = avc->lock;
2660 stat.parentVnode = avc->parentVnode;
2661 stat.parentUnique = avc->parentUnique;
2662 hset(stat.flushDV, avc->flushDV);
2663 hset(stat.mapDV, avc->mapDV);
2664 stat.truncPos = avc->truncPos;
2665 { /* just grab the first two - won't break anything... */
2666 struct axscache *ac;
2668 for (i = 0, ac = avc->Access; ac && i < CPSIZE; i++, ac = ac->next) {
2669 stat.randomUid[i] = ac->uid;
2670 stat.randomAccess[i] = ac->axess;
2673 stat.callback = afs_data_pointer_to_int32(avc->callback);
2674 stat.cbExpires = avc->cbExpires;
2675 stat.anyAccess = avc->anyAccess;
2676 stat.opens = avc->opens;
2677 stat.execsOrWriters = avc->execsOrWriters;
2678 stat.flockCount = avc->flockCount;
2679 stat.mvstat = avc->mvstat;
2680 stat.states = avc->states;
2681 memcpy(aout, (char *)&stat, sizeof(struct vcxstat));
2682 *aoutSize = sizeof(struct vcxstat);
2687 DECL_PIOCTL(PGetVnodeXStatus2)
2689 register afs_int32 code;
2690 struct vcxstat2 stat;
2695 code = afs_VerifyVCache(avc, areq);
2698 if (vType(avc) == VDIR)
2699 mode = PRSFS_LOOKUP;
2702 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
2705 memset(&stat, 0, sizeof(struct vcxstat2));
2707 stat.cbExpires = avc->cbExpires;
2708 stat.anyAccess = avc->anyAccess;
2709 stat.mvstat = avc->mvstat;
2710 stat.callerAccess = afs_GetAccessBits(avc, ~0, areq);
2712 memcpy(aout, (char *)&stat, sizeof(struct vcxstat2));
2713 *aoutSize = sizeof(struct vcxstat2);
2717 /* We require root for local sysname changes, but not for remote */
2718 /* (since we don't really believe remote uids anyway) */
2719 /* outname[] shouldn't really be needed- this is left as an excercise */
2720 /* for the reader. */
2721 DECL_PIOCTL(PSetSysName)
2723 char *cp, *cp2 = NULL, inname[MAXSYSNAME], outname[MAXSYSNAME];
2724 int setsysname, foundname = 0;
2725 register struct afs_exporter *exporter;
2726 register struct unixuser *au;
2727 register afs_int32 pag, error;
2728 int t, count, num = 0, allpags = 0;
2731 AFS_STATCNT(PSetSysName);
2732 if (!afs_globalVFS) {
2733 /* Afsd is NOT running; disable it */
2734 #if defined(KERNEL_HAVE_UERROR)
2735 return (setuerror(EINVAL), EINVAL);
2740 memset(inname, 0, MAXSYSNAME);
2741 memcpy((char *)&setsysname, ain, sizeof(afs_int32));
2742 ain += sizeof(afs_int32);
2743 if (setsysname & 0x8000) {
2745 setsysname &= ~0x8000;
2750 if (setsysname < 0 || setsysname > MAXNUMSYSNAMES)
2753 for (cp = ain, count = 0; count < setsysname; count++) {
2754 /* won't go past end of ain since maxsysname*num < ain length */
2756 if (t >= MAXSYSNAME || t <= 0)
2758 /* check for names that can shoot us in the foot */
2759 if (*cp == '.' && (cp[1] == 0 || (cp[1] == '.' && cp[2] == 0)))
2765 /* inname gets first entry in case we're being a translator */
2767 memcpy(inname, ain, t + 1); /* include terminating null */
2771 if ((*acred)->cr_gid == RMTUSER_REQ ||
2772 (*acred)->cr_gid == RMTUSER_REQ_PRIV) { /* Handles all exporters */
2773 if (allpags && (*acred)->cr_gid != RMTUSER_REQ_PRIV) {
2776 pag = PagInCred(*acred);
2778 return EINVAL; /* Better than panicing */
2780 if (!(au = afs_FindUser(pag, -1, READ_LOCK))) {
2781 return EINVAL; /* Better than panicing */
2783 if (!(exporter = au->exporter)) {
2784 afs_PutUser(au, READ_LOCK);
2785 return EINVAL; /* Better than panicing */
2787 error = EXP_SYSNAME(exporter, (setsysname ? cp2 : NULL), &sysnamelist,
2790 if (error == ENODEV)
2791 foundname = 0; /* sysname not set yet! */
2793 afs_PutUser(au, READ_LOCK);
2798 strcpy(outname, sysnamelist[0]);
2800 afs_PutUser(au, READ_LOCK);
2804 /* Not xlating, so local case */
2806 osi_Panic("PSetSysName: !afs_sysname\n");
2807 if (!setsysname) { /* user just wants the info */
2808 strcpy(outname, afs_sysname);
2809 foundname = afs_sysnamecount;
2810 sysnamelist = afs_sysnamelist;
2811 } else { /* Local guy; only root can change sysname */
2812 if (!afs_osi_suser(*acred))
2815 /* allpags makes no sense for local use */
2819 /* clear @sys entries from the dnlc, once afs_lookup can
2820 * do lookups of @sys entries and thinks it can trust them */
2821 /* privs ok, store the entry, ... */
2822 strcpy(afs_sysname, inname);
2823 if (setsysname > 1) { /* ... or list */
2825 for (count = 1; count < setsysname; ++count) {
2826 if (!afs_sysnamelist[count])
2828 ("PSetSysName: no afs_sysnamelist entry to write\n");
2830 memcpy(afs_sysnamelist[count], cp, t + 1); /* include null */
2834 afs_sysnamecount = setsysname;
2839 cp = aout; /* not changing so report back the count and ... */
2840 memcpy(cp, (char *)&foundname, sizeof(afs_int32));
2841 cp += sizeof(afs_int32);
2843 strcpy(cp, outname); /* ... the entry, ... */
2844 cp += strlen(outname) + 1;
2845 for (count = 1; count < foundname; ++count) { /* ... or list. */
2846 if (!sysnamelist[count])
2848 ("PSetSysName: no afs_sysnamelist entry to read\n");
2849 t = strlen(sysnamelist[count]);
2850 if (t >= MAXSYSNAME)
2851 osi_Panic("PSetSysName: sysname entry garbled\n");
2852 strcpy(cp, sysnamelist[count]);
2856 *aoutSize = cp - aout;
2861 /* sequential search through the list of touched cells is not a good
2862 * long-term solution here. For small n, though, it should be just
2863 * fine. Should consider special-casing the local cell for large n.
2864 * Likewise for PSetSPrefs.
2866 * s - number of ids in array l[] -- NOT index of last id
2867 * l - array of cell ids which have volumes that need to be sorted
2868 * vlonly - sort vl servers or file servers?
2871 ReSortCells_cb(struct cell *cell, void *arg)
2873 afs_int32 *p = (afs_int32 *) arg;
2874 afs_int32 *l = p + 1;
2877 for (i = 0; i < s; i++) {
2878 if (l[i] == cell->cellNum) {
2879 ObtainWriteLock(&cell->lock, 690);
2880 afs_SortServers(cell->cellHosts, MAXCELLHOSTS);
2881 ReleaseWriteLock(&cell->lock);
2889 ReSortCells(int s, afs_int32 * l, int vlonly)
2897 p = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * (s + 1));
2899 memcpy(p + 1, l, s * sizeof(afs_int32));
2900 afs_TraverseCells(&ReSortCells_cb, p);
2901 afs_osi_Free(p, sizeof(afs_int32) * (s + 1));
2905 ObtainReadLock(&afs_xvolume);
2906 for (i = 0; i < NVOLS; i++) {
2907 for (j = afs_volumes[i]; j; j = j->next) {
2908 for (k = 0; k < s; k++)
2909 if (j->cell == l[k]) {
2910 ObtainWriteLock(&j->lock, 233);
2911 afs_SortServers(j->serverHost, MAXHOSTS);
2912 ReleaseWriteLock(&j->lock);
2917 ReleaseReadLock(&afs_xvolume);
2921 static int debugsetsp = 0;
2923 afs_setsprefs(sp, num, vlonly)
2926 unsigned int vlonly;
2929 int i, j, k, matches, touchedSize;
2930 struct server *srvr = NULL;
2931 afs_int32 touched[34];
2935 for (k = 0; k < num; sp++, k++) {
2937 printf("sp host=%x, rank=%d\n", sp->host.s_addr, sp->rank);
2940 ObtainReadLock(&afs_xserver);
2942 i = SHash(sp->host.s_addr);
2943 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2944 if (sa->sa_ip == sp->host.s_addr) {
2946 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
2947 || (sa->sa_portal == AFS_FSPORT);
2948 if ((!vlonly && isfs) || (vlonly && !isfs)) {
2955 if (sa && matches) { /* found one! */
2957 printf("sa ip=%x, ip_rank=%d\n", sa->sa_ip, sa->sa_iprank);
2959 sa->sa_iprank = sp->rank + afs_randomMod15();
2960 afs_SortOneServer(sa->server);
2963 /* if we don't know yet what cell it's in, this is moot */
2964 for (j = touchedSize - 1;
2965 j >= 0 && touched[j] != srvr->cell->cellNum; j--)
2966 /* is it in our list of touched cells ? */ ;
2967 if (j < 0) { /* no, it's not */
2968 touched[touchedSize++] = srvr->cell->cellNum;
2969 if (touchedSize >= 32) { /* watch for ovrflow */
2970 ReleaseReadLock(&afs_xserver);
2971 ReSortCells(touchedSize, touched, vlonly);
2973 ObtainReadLock(&afs_xserver);
2979 ReleaseReadLock(&afs_xserver);
2980 /* if we didn't find one, start to create one. */
2981 /* Note that it doesn't have a cell yet... */
2983 afs_uint32 temp = sp->host.s_addr;
2985 afs_GetServer(&temp, 1, 0, (vlonly ? AFS_VLPORT : AFS_FSPORT),
2986 WRITE_LOCK, (afsUUID *) 0, 0);
2987 srvr->addr->sa_iprank = sp->rank + afs_randomMod15();
2988 afs_PutServer(srvr, WRITE_LOCK);
2990 } /* for all cited preferences */
2992 ReSortCells(touchedSize, touched, vlonly);
2996 /* Note that this may only be performed by the local root user.
2998 DECL_PIOCTL(PSetSPrefs)
3000 struct setspref *ssp;
3001 AFS_STATCNT(PSetSPrefs);
3003 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3004 return EIO; /* Inappropriate ioctl for device */
3006 if (!afs_osi_suser(*acred))
3009 if (ainSize < sizeof(struct setspref))
3012 ssp = (struct setspref *)ain;
3013 if (ainSize < sizeof(struct spref) * ssp->num_servers)
3016 afs_setsprefs(&(ssp->servers[0]), ssp->num_servers,
3017 (ssp->flags & DBservers));
3021 DECL_PIOCTL(PSetSPrefs33)
3024 AFS_STATCNT(PSetSPrefs);
3025 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3026 return EIO; /* Inappropriate ioctl for device */
3029 if (!afs_osi_suser(*acred))
3032 sp = (struct spref *)ain;
3033 afs_setsprefs(sp, ainSize / (sizeof(struct spref)), 0 /*!vlonly */ );
3037 /* some notes on the following code...
3038 * in the hash table of server structs, all servers with the same IP address
3039 * will be on the same overflow chain.
3040 * This could be sped slightly in some circumstances by having it cache the
3041 * immediately previous slot in the hash table and some supporting information
3042 * Only reports file servers now.
3044 DECL_PIOCTL(PGetSPrefs)
3046 struct sprefrequest *spin; /* input */
3047 struct sprefinfo *spout; /* output */
3048 struct spref *srvout; /* one output component */
3049 int i, j; /* counters for hash table traversal */
3050 struct server *srvr; /* one of CM's server structs */
3052 int vlonly; /* just return vlservers ? */
3055 AFS_STATCNT(PGetSPrefs);
3056 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3057 return EIO; /* Inappropriate ioctl for device */
3060 if (ainSize < sizeof(struct sprefrequest_33)) {
3063 spin = ((struct sprefrequest *)ain);
3066 if (ainSize > sizeof(struct sprefrequest_33)) {
3067 vlonly = (spin->flags & DBservers);
3071 /* struct sprefinfo includes 1 server struct... that size gets added
3072 * in during the loop that follows.
3074 *aoutSize = sizeof(struct sprefinfo) - sizeof(struct spref);
3075 spout = (struct sprefinfo *)aout;
3076 spout->next_offset = spin->offset;
3077 spout->num_servers = 0;
3078 srvout = spout->servers;
3080 ObtainReadLock(&afs_xserver);
3081 for (i = 0, j = 0; j < NSERVERS; j++) { /* sift through hash table */
3082 for (sa = afs_srvAddrs[j]; sa; sa = sa->next_bkt, i++) {
3083 if (spin->offset > (unsigned short)i) {
3084 continue; /* catch up to where we left off */
3086 spout->next_offset++;
3089 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
3090 || (sa->sa_portal == AFS_FSPORT);
3092 if ((vlonly && isfs) || (!vlonly && !isfs)) {
3093 /* only report ranks for vl servers */
3097 srvout->host.s_addr = sa->sa_ip;
3098 srvout->rank = sa->sa_iprank;
3099 *aoutSize += sizeof(struct spref);
3100 spout->num_servers++;
3103 if (*aoutSize > (PIGGYSIZE - sizeof(struct spref))) {
3104 ReleaseReadLock(&afs_xserver); /* no more room! */
3109 ReleaseReadLock(&afs_xserver);
3111 spout->next_offset = 0; /* start over from the beginning next time */
3115 /* Enable/Disable the specified exporter. Must be root to disable an exporter */
3116 int afs_NFSRootOnly = 1;
3117 DECL_PIOCTL(PExportAfs)
3119 afs_int32 export, newint =
3120 0, type, changestate, handleValue, convmode, pwsync, smounts;
3121 afs_int32 rempags = 0, pagcb = 0;
3122 register struct afs_exporter *exporter;
3124 AFS_STATCNT(PExportAfs);
3125 memcpy((char *)&handleValue, ain, sizeof(afs_int32));
3126 type = handleValue >> 24;
3131 exporter = exporter_find(type);
3133 export = handleValue & 3;
3134 changestate = handleValue & 0xfff;
3135 smounts = (handleValue >> 2) & 3;
3136 pwsync = (handleValue >> 4) & 3;
3137 convmode = (handleValue >> 6) & 3;
3138 rempags = (handleValue >> 8) & 3;
3139 pagcb = (handleValue >> 10) & 3;
3141 changestate = (handleValue >> 16) & 0x1;
3142 convmode = (handleValue >> 16) & 0x2;
3143 pwsync = (handleValue >> 16) & 0x4;
3144 smounts = (handleValue >> 16) & 0x8;
3145 export = handleValue & 0xff;
3148 /* Failed finding desired exporter; */
3152 handleValue = exporter->exp_states;
3153 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3154 *aoutSize = sizeof(afs_int32);
3156 if (!afs_osi_suser(*acred))
3157 return EACCES; /* Only superuser can do this */
3161 exporter->exp_states |= EXP_EXPORTED;
3163 exporter->exp_states &= ~EXP_EXPORTED;
3167 exporter->exp_states |= EXP_UNIXMODE;
3169 exporter->exp_states &= ~EXP_UNIXMODE;
3173 exporter->exp_states |= EXP_PWSYNC;
3175 exporter->exp_states &= ~EXP_PWSYNC;
3179 afs_NFSRootOnly = 0;
3180 exporter->exp_states |= EXP_SUBMOUNTS;
3182 afs_NFSRootOnly = 1;
3183 exporter->exp_states &= ~EXP_SUBMOUNTS;
3188 exporter->exp_states |= EXP_CLIPAGS;
3190 exporter->exp_states &= ~EXP_CLIPAGS;
3194 exporter->exp_states |= EXP_CALLBACK;
3196 exporter->exp_states &= ~EXP_CALLBACK;
3198 handleValue = exporter->exp_states;
3199 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3200 *aoutSize = sizeof(afs_int32);
3203 exporter->exp_states |= EXP_EXPORTED;
3205 exporter->exp_states &= ~EXP_EXPORTED;
3207 exporter->exp_states |= EXP_UNIXMODE;
3209 exporter->exp_states &= ~EXP_UNIXMODE;
3211 exporter->exp_states |= EXP_PWSYNC;
3213 exporter->exp_states &= ~EXP_PWSYNC;
3215 afs_NFSRootOnly = 0;
3216 exporter->exp_states |= EXP_SUBMOUNTS;
3218 afs_NFSRootOnly = 1;
3219 exporter->exp_states &= ~EXP_SUBMOUNTS;
3229 struct gaginfo *gagflags;
3231 if (!afs_osi_suser(*acred))
3234 gagflags = (struct gaginfo *)ain;
3235 afs_showflags = gagflags->showflags;
3241 DECL_PIOCTL(PTwiddleRx)
3243 struct rxparams *rxp;
3245 if (!afs_osi_suser(*acred))
3248 rxp = (struct rxparams *)ain;
3250 if (rxp->rx_initReceiveWindow)
3251 rx_initReceiveWindow = rxp->rx_initReceiveWindow;
3252 if (rxp->rx_maxReceiveWindow)
3253 rx_maxReceiveWindow = rxp->rx_maxReceiveWindow;
3254 if (rxp->rx_initSendWindow)
3255 rx_initSendWindow = rxp->rx_initSendWindow;
3256 if (rxp->rx_maxSendWindow)
3257 rx_maxSendWindow = rxp->rx_maxSendWindow;
3258 if (rxp->rxi_nSendFrags)
3259 rxi_nSendFrags = rxp->rxi_nSendFrags;
3260 if (rxp->rxi_nRecvFrags)
3261 rxi_nRecvFrags = rxp->rxi_nRecvFrags;
3262 if (rxp->rxi_OrphanFragSize)
3263 rxi_OrphanFragSize = rxp->rxi_OrphanFragSize;
3264 if (rxp->rx_maxReceiveSize) {
3265 rx_maxReceiveSize = rxp->rx_maxReceiveSize;
3266 rx_maxReceiveSizeUser = rxp->rx_maxReceiveSize;
3268 if (rxp->rx_MyMaxSendSize)
3269 rx_MyMaxSendSize = rxp->rx_MyMaxSendSize;
3274 DECL_PIOCTL(PGetInitParams)
3276 if (sizeof(struct cm_initparams) > PIGGYSIZE)
3279 memcpy(aout, (char *)&cm_initParams, sizeof(struct cm_initparams));
3280 *aoutSize = sizeof(struct cm_initparams);
3284 #ifdef AFS_SGI65_ENV
3285 /* They took crget() from us, so fake it. */
3290 cr = crdup(get_current_cred());
3291 memset((char *)cr, 0, sizeof(cred_t));
3292 #if CELL || CELL_PREPARE
3299 DECL_PIOCTL(PGetRxkcrypt)
3301 memcpy(aout, (char *)&cryptall, sizeof(afs_int32));
3302 *aoutSize = sizeof(afs_int32);
3306 DECL_PIOCTL(PSetRxkcrypt)
3310 if (!afs_osi_suser(*acred))
3312 if (ainSize != sizeof(afs_int32) || ain == NULL)
3314 memcpy((char *)&tmpval, ain, sizeof(afs_int32));
3315 /* if new mappings added later this will need to be changed */
3316 if (tmpval != 0 && tmpval != 1)
3322 #ifdef AFS_NEED_CLIENTCONTEXT
3324 * Create new credentials to correspond to a remote user with given
3325 * <hostaddr, uid, g0, g1>. This allows a server running as root to
3326 * provide pioctl (and other) services to foreign clients (i.e. nfs
3327 * clients) by using this call to `become' the client.
3330 #define PIOCTL_HEADER 6
3332 HandleClientContext(struct afs_ioctl *ablob, int *com,
3333 struct AFS_UCRED **acred, struct AFS_UCRED *credp)
3336 afs_uint32 hostaddr;
3337 afs_int32 uid, g0, g1, i, code, pag, exporter_type, isroot = 0;
3338 struct afs_exporter *exporter, *outexporter;
3339 struct AFS_UCRED *newcred;
3340 struct unixuser *au;
3341 afs_uint32 comp = *com & 0xff00;
3344 #if defined(AFS_SGIMP_ENV)
3345 osi_Assert(ISAFS_GLOCK());
3347 AFS_STATCNT(HandleClientContext);
3348 if (ablob->in_size < PIOCTL_HEADER * sizeof(afs_int32)) {
3349 /* Must at least include the PIOCTL_HEADER header words required by the protocol */
3350 return EINVAL; /* Too small to be good */
3352 ain = inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
3353 AFS_COPYIN(ablob->in, ain, PIOCTL_HEADER * sizeof(afs_int32), code);
3355 osi_FreeLargeSpace(inData);
3359 /* Extract information for remote user */
3360 hostaddr = *((afs_uint32 *) ain);
3361 ain += sizeof(hostaddr);
3362 uid = *((afs_uint32 *) ain);
3364 g0 = *((afs_uint32 *) ain);
3366 g1 = *((afs_uint32 *) ain);
3368 *com = *((afs_uint32 *) ain);
3369 ain += sizeof(afs_int32);
3370 exporter_type = *((afs_uint32 *) ain); /* In case we support more than NFS */
3373 * Of course, one must be root for most of these functions, but
3374 * we'll allow (for knfs) you to set things if the pag is 0 and
3375 * you're setting tokens or unlogging.
3378 if (!afs_osi_suser(credp)) {
3379 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
3380 /* Since SGI's suser() returns explicit failure after the call.. */
3383 /* check for acceptable opcodes for normal folks, which are, so far,
3384 * get/set tokens, sysname, and unlog.
3386 if (i != 9 && i != 3 && i != 38 && i != 8) {
3387 osi_FreeLargeSpace(inData);
3392 ablob->in_size -= PIOCTL_HEADER * sizeof(afs_int32);
3393 ablob->in += PIOCTL_HEADER * sizeof(afs_int32);
3394 osi_FreeLargeSpace(inData);
3397 * We map uid 0 to nobody to match the mapping that the nfs
3398 * server does and to ensure that the suser() calls in the afs
3399 * code fails for remote client roots.
3401 uid = afs_nobody; /* NFS_NOBODY == -2 */
3405 #ifdef AFS_AIX41_ENV
3408 newcred->cr_gid = isroot ? RMTUSER_REQ_PRIV : RMTUSER_REQ;
3409 #ifdef AFS_AIX51_ENV
3410 newcred->cr_groupset.gs_union.un_groups[0] = g0;
3411 newcred->cr_groupset.gs_union.un_groups[1] = g1;
3412 #elif defined(AFS_LINUX26_ENV)
3413 #ifdef AFS_LINUX26_ONEGROUP_ENV
3414 newcred->cr_group_info = groups_alloc(1); /* not that anything sets this */
3415 l = (((g0-0x3f00) & 0x3fff) << 14) | ((g1-0x3f00) & 0x3fff);
3416 h = ((g0-0x3f00) >> 14);
3417 h = ((g1-0x3f00) >> 14) + h + h + h;
3418 GROUP_AT(newcred->cr_group_info, 0) = ((h << 28) | l);
3420 newcred->cr_group_info = groups_alloc(2);
3421 GROUP_AT(newcred->cr_group_info, 0) = g0;
3422 GROUP_AT(newcred->cr_group_info, 1) = g1;
3425 newcred->cr_groups[0] = g0;
3426 newcred->cr_groups[1] = g1;
3429 newcred->cr_ngrps = 2;
3430 #elif !defined(AFS_LINUX26_ENV)
3431 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
3432 newcred->cr_ngroups = 2;
3434 for (i = 2; i < NGROUPS; i++)
3435 newcred->cr_groups[i] = NOGROUP;
3438 #if !defined(AFS_OSF_ENV)
3439 afs_nfsclient_init(); /* before looking for exporter, ensure one exists */
3441 if (!(exporter = exporter_find(exporter_type))) {
3442 /* Exporter wasn't initialized or an invalid exporter type */
3446 if (exporter->exp_states & EXP_PWSYNC) {
3447 if (uid != credp->cr_uid) {
3449 return ENOEXEC; /* XXX Find a better errno XXX */
3452 newcred->cr_uid = uid; /* Only temporary */
3453 code = EXP_REQHANDLER(exporter, &newcred, hostaddr, &pag, &outexporter);
3454 /* The client's pag is the only unique identifier for it */
3455 newcred->cr_uid = pag;
3457 if (!code && *com == PSETPAG) {
3458 /* Special case for 'setpag' */
3459 afs_uint32 pagvalue = genpag();
3461 au = afs_GetUser(pagvalue, -1, WRITE_LOCK); /* a new unixuser struct */
3463 * Note that we leave the 'outexporter' struct held so it won't
3466 au->exporter = outexporter;
3467 if (ablob->out_size >= 4) {
3468 AFS_COPYOUT((char *)&pagvalue, ablob->out, sizeof(afs_int32),
3471 afs_PutUser(au, WRITE_LOCK);
3474 return PSETPAG; /* Special return for setpag */
3476 EXP_RELE(outexporter);
3479 *com = (*com) | comp;
3482 #endif /* AFS_NEED_CLIENTCONTEXT */
3484 /* get all interface addresses of this client */
3486 DECL_PIOCTL(PGetCPrefs)
3488 struct sprefrequest *spin; /* input */
3489 struct sprefinfo *spout; /* output */
3490 struct spref *srvout; /* one output component */
3494 AFS_STATCNT(PGetCPrefs);
3495 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3496 return EIO; /* Inappropriate ioctl for device */
3498 if (ainSize < sizeof(struct sprefrequest))
3501 spin = (struct sprefrequest *)ain;
3502 spout = (struct sprefinfo *)aout;
3504 maxNumber = spin->num_servers; /* max addrs this time */
3505 srvout = spout->servers;
3507 ObtainReadLock(&afs_xinterface);
3509 /* copy out the client interface information from the
3510 ** kernel data structure "interface" to the output buffer
3512 for (i = spin->offset, j = 0; (i < afs_cb_interface.numberOfInterfaces)
3513 && (j < maxNumber); i++, j++, srvout++)
3514 srvout->host.s_addr = afs_cb_interface.addr_in[i];
3516 spout->num_servers = j;
3517 *aoutSize = sizeof(struct sprefinfo) + (j - 1) * sizeof(struct spref);
3519 if (i >= afs_cb_interface.numberOfInterfaces)
3520 spout->next_offset = 0; /* start from beginning again */
3522 spout->next_offset = spin->offset + j;
3524 ReleaseReadLock(&afs_xinterface);
3528 DECL_PIOCTL(PSetCPrefs)
3530 struct setspref *sin;
3533 AFS_STATCNT(PSetCPrefs);
3534 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3535 return EIO; /* Inappropriate ioctl for device */
3537 sin = (struct setspref *)ain;
3539 if (ainSize < sizeof(struct setspref))
3541 #if 0 /* num_servers is unsigned */
3542 if (sin->num_servers < 0)
3545 if (sin->num_servers > AFS_MAX_INTERFACE_ADDR)
3548 ObtainWriteLock(&afs_xinterface, 412);
3549 afs_cb_interface.numberOfInterfaces = sin->num_servers;
3550 for (i = 0; (unsigned short)i < sin->num_servers; i++)
3551 afs_cb_interface.addr_in[i] = sin->servers[i].host.s_addr;
3553 ReleaseWriteLock(&afs_xinterface);
3557 DECL_PIOCTL(PFlushMount)
3559 register afs_int32 code;
3560 register struct vcache *tvc;
3561 register struct dcache *tdc;
3562 struct VenusFid tfid;
3564 struct sysname_info sysState;
3565 afs_size_t offset, len;
3567 AFS_STATCNT(PFlushMount);
3570 code = afs_VerifyVCache(avc, areq);
3573 if (vType(avc) != VDIR) {
3576 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
3579 Check_AtSys(avc, ain, &sysState, areq);
3580 ObtainReadLock(&tdc->lock);
3582 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
3583 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
3584 ReleaseReadLock(&tdc->lock);
3585 afs_PutDCache(tdc); /* we're done with the data */
3586 bufp = sysState.name;
3590 tfid.Cell = avc->fid.Cell;
3591 tfid.Fid.Volume = avc->fid.Fid.Volume;
3592 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
3593 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
3595 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3601 if (tvc->mvstat != 1) {
3606 #ifdef AFS_BOZONLOCK_ENV
3607 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
3609 ObtainWriteLock(&tvc->lock, 649);
3610 ObtainWriteLock(&afs_xcbhash, 650);
3611 afs_DequeueCallback(tvc);
3612 tvc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
3613 ReleaseWriteLock(&afs_xcbhash);
3614 /* now find the disk cache entries */
3615 afs_TryToSmush(tvc, *acred, 1);
3616 osi_dnlc_purgedp(tvc);
3617 if (tvc->linkData && !(tvc->states & CCore)) {
3618 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
3619 tvc->linkData = NULL;
3621 ReleaseWriteLock(&tvc->lock);
3622 #ifdef AFS_BOZONLOCK_ENV
3623 afs_BozonUnlock(&tvc->pvnLock, tvc);
3627 if (sysState.allocked)
3628 osi_FreeLargeSpace(bufp);
3632 DECL_PIOCTL(PRxStatProc)
3637 if (!afs_osi_suser(*acred)) {
3641 if (ainSize != sizeof(afs_int32)) {
3645 memcpy((char *)&flags, ain, sizeof(afs_int32));
3646 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3650 if (flags & AFSCALL_RXSTATS_ENABLE) {
3651 rx_enableProcessRPCStats();
3653 if (flags & AFSCALL_RXSTATS_DISABLE) {
3654 rx_disableProcessRPCStats();
3656 if (flags & AFSCALL_RXSTATS_CLEAR) {
3657 rx_clearProcessRPCStats(AFS_RX_STATS_CLEAR_ALL);
3665 DECL_PIOCTL(PRxStatPeer)
3670 if (!afs_osi_suser(*acred)) {
3674 if (ainSize != sizeof(afs_int32)) {
3678 memcpy((char *)&flags, ain, sizeof(afs_int32));
3679 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3683 if (flags & AFSCALL_RXSTATS_ENABLE) {
3684 rx_enablePeerRPCStats();
3686 if (flags & AFSCALL_RXSTATS_DISABLE) {
3687 rx_disablePeerRPCStats();
3689 if (flags & AFSCALL_RXSTATS_CLEAR) {
3690 rx_clearPeerRPCStats(AFS_RX_STATS_CLEAR_ALL);
3697 DECL_PIOCTL(PPrefetchFromTape)
3699 register afs_int32 code, code1;
3702 struct rx_call *tcall;
3703 struct AFSVolSync tsync;
3704 struct AFSFetchStatus OutStatus;
3705 struct AFSCallBack CallBack;
3706 struct VenusFid tfid;
3710 AFS_STATCNT(PSetAcl);
3714 if (ain && (ainSize == 3 * sizeof(afs_int32)))
3715 Fid = (struct AFSFid *)ain;
3717 Fid = &avc->fid.Fid;
3718 tfid.Cell = avc->fid.Cell;
3719 tfid.Fid.Volume = Fid->Volume;
3720 tfid.Fid.Vnode = Fid->Vnode;
3721 tfid.Fid.Unique = Fid->Unique;
3723 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3725 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3726 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &avc->fid);
3729 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3730 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &tvc->fid);
3733 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3737 tcall = rx_NewCall(tc->id);
3739 StartRXAFS_FetchData(tcall, (struct AFSFid *)&tvc->fid.Fid, 0,
3742 bytes = rx_Read(tcall, (char *)aout, sizeof(afs_int32));
3744 EndRXAFS_FetchData(tcall, &OutStatus, &CallBack, &tsync);
3746 code1 = rx_EndCall(tcall, code);
3750 } while (afs_Analyze
3751 (tc, code, &tvc->fid, areq, AFS_STATS_FS_RPCIDX_RESIDENCYRPCS,
3752 SHARED_LOCK, NULL));
3753 /* This call is done only to have the callback things handled correctly */
3754 afs_FetchStatus(tvc, &tfid, areq, &OutStatus);
3758 *aoutSize = sizeof(afs_int32);
3763 DECL_PIOCTL(PResidencyCmd)
3765 register afs_int32 code;
3768 struct ResidencyCmdInputs *Inputs;
3769 struct ResidencyCmdOutputs *Outputs;
3770 struct VenusFid tfid;
3773 Inputs = (struct ResidencyCmdInputs *)ain;
3774 Outputs = (struct ResidencyCmdOutputs *)aout;
3777 if (!ain || ainSize != sizeof(struct ResidencyCmdInputs))
3782 Fid = &avc->fid.Fid;
3784 tfid.Cell = avc->fid.Cell;
3785 tfid.Fid.Volume = Fid->Volume;
3786 tfid.Fid.Vnode = Fid->Vnode;
3787 tfid.Fid.Unique = Fid->Unique;
3789 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3790 afs_Trace3(afs_iclSetp, CM_TRACE_RESIDCMD, ICL_TYPE_POINTER, tvc,
3791 ICL_TYPE_INT32, Inputs->command, ICL_TYPE_FID, &tfid);
3795 if (Inputs->command) {
3797 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3801 RXAFS_ResidencyCmd(tc->id, Fid, Inputs,
3802 (struct ResidencyCmdOutputs *)aout);
3806 } while (afs_Analyze
3807 (tc, code, &tvc->fid, areq,
3808 AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK, NULL));
3809 /* This call is done to have the callback things handled correctly */
3810 afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3811 } else { /* just a status request, return also link data */
3813 Outputs->code = afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3814 Outputs->chars[0] = 0;
3815 if (vType(tvc) == VLNK) {
3816 ObtainWriteLock(&tvc->lock, 555);
3817 if (afs_HandleLink(tvc, areq) == 0)
3818 strncpy((char *)&Outputs->chars, tvc->linkData, MAXCMDCHARS);
3819 ReleaseWriteLock(&tvc->lock);
3826 *aoutSize = sizeof(struct ResidencyCmdOutputs);
3831 DECL_PIOCTL(PNewUuid)
3833 /*AFS_STATCNT(PNewUuid); */
3834 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
3835 return EIO; /* Inappropriate ioctl for device */
3837 if (!afs_osi_suser(acred))
3840 ObtainWriteLock(&afs_xinterface, 555);
3841 afs_uuid_create(&afs_cb_interface.uuid);
3842 ReleaseWriteLock(&afs_xinterface);
3843 ForceAllNewConnections();
3846 DECL_PIOCTL(PCallBackAddr)
3849 afs_uint32 addr, code;
3855 struct unixuser *tu;
3856 struct srvAddr **addrs;
3858 /*AFS_STATCNT(PCallBackAddr); */
3859 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
3860 return EIO; /* Inappropriate ioctl for device */
3862 if (!afs_osi_suser(acred))
3865 if (ainSize < sizeof(afs_int32))
3868 memcpy(&addr, ain, sizeof(afs_int32));
3870 ObtainReadLock(&afs_xinterface);
3871 for (i = 0; (unsigned short)i < afs_cb_interface.numberOfInterfaces; i++) {
3872 if (afs_cb_interface.addr_in[i] == addr)
3876 ReleaseWriteLock(&afs_xinterface);
3878 if (afs_cb_interface.addr_in[i] != addr)
3881 ObtainReadLock(&afs_xserver); /* Necessary? */
3882 ObtainReadLock(&afs_xsrvAddr);
3885 for (i = 0; i < NSERVERS; i++) {
3886 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3891 addrs = afs_osi_Alloc(srvAddrCount * sizeof(*addrs));
3893 for (i = 0; i < NSERVERS; i++) {
3894 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3895 if (j >= srvAddrCount)
3901 ReleaseReadLock(&afs_xsrvAddr);
3902 ReleaseReadLock(&afs_xserver);
3904 for (i = 0; i < j; i++) {
3910 /* vlserver has no callback conn */
3911 if (sa->sa_portal == AFS_VLPORT) {
3915 if (!ts->cell) /* not really an active server, anyway, it must */
3916 continue; /* have just been added by setsprefs */
3918 /* get a connection, even if host is down; bumps conn ref count */
3919 tu = afs_GetUser(areq->uid, ts->cell->cellNum, SHARED_LOCK);
3920 tc = afs_ConnBySA(sa, ts->cell->fsport, ts->cell->cellNum, tu,
3921 1 /*force */ , 1 /*create */ , SHARED_LOCK);
3922 afs_PutUser(tu, SHARED_LOCK);
3926 if ((sa->sa_flags & SRVADDR_ISDOWN) || afs_HaveCallBacksFrom(ts)) {
3927 if (sa->sa_flags & SRVADDR_ISDOWN) {
3928 rx_SetConnDeadTime(tc->id, 3);
3930 #ifdef RX_ENABLE_LOCKS
3932 #endif /* RX_ENABLE_LOCKS */
3933 code = RXAFS_CallBackRxConnAddr(tc->id, &addr);
3934 #ifdef RX_ENABLE_LOCKS
3936 #endif /* RX_ENABLE_LOCKS */
3938 afs_PutConn(tc, SHARED_LOCK); /* done with it now */
3939 } /* Outer loop over addrs */
3940 #endif /* UKERNEL */
3944 DECL_PIOCTL(PNFSNukeCreds)
3946 afs_uint32 addr, code;
3947 register afs_int32 i;
3948 register struct unixuser *tu;
3950 AFS_STATCNT(PUnlog);
3951 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3952 return EIO; /* Inappropriate ioctl for device */
3954 if (ainSize < sizeof(afs_int32))
3956 memcpy(&addr, ain, sizeof(afs_int32));
3958 if ((*acred)->cr_gid == RMTUSER_REQ_PRIV && !addr) {
3959 tu = afs_GetUser(areq->uid, -1, SHARED_LOCK);
3960 if (!tu->exporter || !(addr = EXP_GETHOST(tu->exporter))) {
3961 afs_PutUser(tu, SHARED_LOCK);
3964 afs_PutUser(tu, SHARED_LOCK);
3965 } else if (!afs_osi_suser(acred)) {
3969 ObtainWriteLock(&afs_xuser, 227);
3970 for (i = 0; i < NUSERS; i++) {
3971 for (tu = afs_users[i]; tu; tu = tu->next) {
3972 if (tu->exporter && EXP_CHECKHOST(tu->exporter, addr)) {
3974 tu->states &= ~UHasTokens;
3975 /* security is not having to say you're sorry */
3976 memset((char *)&tu->ct, 0, sizeof(struct ClearToken));
3978 ReleaseWriteLock(&afs_xuser);
3979 afs_ResetUserConns(tu);
3981 ObtainWriteLock(&afs_xuser, 228);
3983 /* set the expire times to 0, causes
3984 * afs_GCUserData to remove this entry
3986 tu->ct.EndTimestamp = 0;
3988 #endif /* UKERNEL */
3992 ReleaseWriteLock(&afs_xuser);