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);
95 DECL_PIOCTL(PPrecache);
98 * A macro that says whether we're going to need HandleClientContext().
99 * This is currently used only by the nfs translator.
101 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
102 #define AFS_NEED_CLIENTCONTEXT
105 /* Prototypes for private routines */
106 #ifdef AFS_NEED_CLIENTCONTEXT
107 static int HandleClientContext(struct afs_ioctl *ablob, int *com,
108 struct AFS_UCRED **acred,
109 struct AFS_UCRED *credp);
111 int HandleIoctl(register struct vcache *avc, register afs_int32 acom,
112 struct afs_ioctl *adata);
113 int afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
114 register struct afs_ioctl *ablob, int afollow,
115 struct AFS_UCRED **acred);
116 static int Prefetch(char *apath, struct afs_ioctl *adata, int afollow,
117 struct AFS_UCRED *acred);
120 static int (*(VpioctlSw[])) () = {
125 PGetVolumeStatus, /* 4 */
126 PSetVolumeStatus, /* 5 */
131 PCheckServers, /* 10 */
132 PCheckVolNames, /* 11 */
134 PBogus, /* 13 -- used to be quick check time */
135 PFindVolume, /* 14 */
136 PBogus, /* 15 -- prefetch is now special-cased; see pioctl code! */
137 PBogus, /* 16 -- used to be testing code */
138 PNoop, /* 17 -- used to be enable group */
139 PNoop, /* 18 -- used to be disable group */
140 PBogus, /* 19 -- used to be list group */
141 PViceAccess, /* 20 */
142 PUnlog, /* 21 -- unlog *is* unpag in this system */
143 PGetFID, /* 22 -- get file ID */
144 PBogus, /* 23 -- used to be waitforever */
145 PSetCacheSize, /* 24 */
146 PRemoveCallBack, /* 25 -- flush only the callback */
149 PRemoveMount, /* 28 -- delete mount point */
150 PNewStatMount, /* 29 -- new style mount point stat */
151 PGetFileCell, /* 30 -- get cell name for input file */
152 PGetWSCell, /* 31 -- get cell name for workstation */
153 PMariner, /* 32 - set/get mariner host */
154 PGetUserCell, /* 33 -- get cell name for user */
155 PVenusLogging, /* 34 -- Enable/Disable logging */
156 PGetCellStatus, /* 35 */
157 PSetCellStatus, /* 36 */
158 PFlushVolumeData, /* 37 -- flush all data from a volume */
159 PSetSysName, /* 38 - Set system name */
160 PExportAfs, /* 39 - Export Afs to remote nfs clients */
161 PGetCacheSize, /* 40 - get cache size and usage */
162 PGetVnodeXStatus, /* 41 - get vcache's special status */
163 PSetSPrefs33, /* 42 - Set CM Server preferences... */
164 PGetSPrefs, /* 43 - Get CM Server preferences... */
165 PGag, /* 44 - turn off/on all CM messages */
166 PTwiddleRx, /* 45 - adjust some RX params */
167 PSetSPrefs, /* 46 - Set CM Server preferences... */
168 PStoreBehind, /* 47 - set degree of store behind to be done */
169 PGCPAGs, /* 48 - disable automatic pag gc-ing */
170 PGetInitParams, /* 49 - get initial cm params */
171 PGetCPrefs, /* 50 - get client interface addresses */
172 PSetCPrefs, /* 51 - set client interface addresses */
173 PFlushMount, /* 52 - flush mount symlink data */
174 PRxStatProc, /* 53 - control process RX statistics */
175 PRxStatPeer, /* 54 - control peer RX statistics */
176 PGetRxkcrypt, /* 55 -- Get rxkad encryption flag */
177 PSetRxkcrypt, /* 56 -- Set rxkad encryption flag */
178 PBogus, /* 57 -- arla: set file prio */
179 PBogus, /* 58 -- arla: fallback getfh */
180 PBogus, /* 59 -- arla: fallback fhopen */
181 PBogus, /* 60 -- arla: controls xfsdebug */
182 PBogus, /* 61 -- arla: controls arla debug */
183 PBogus, /* 62 -- arla: debug interface */
184 PBogus, /* 63 -- arla: print xfs status */
185 PBogus, /* 64 -- arla: force cache check */
186 PBogus, /* 65 -- arla: break callback */
187 PPrefetchFromTape, /* 66 -- MR-AFS: prefetch file from tape */
188 PResidencyCmd, /* 67 -- MR-AFS: generic commnd interface */
189 PBogus, /* 68 -- arla: fetch stats */
190 PGetVnodeXStatus2, /* 69 - get caller access and some vcache status */
193 static int (*(CpioctlSw[])) () = {
195 PNewAlias, /* 1 -- create new cell alias */
196 PListAliases, /* 2 -- list cell aliases */
197 PCallBackAddr, /* 3 -- request addr for callback rxcon */
209 static int (*(OpioctlSw[])) () = {
211 PNFSNukeCreds, /* 1 -- nuke all creds for NFS client */
214 #define PSetClientContext 99 /* Special pioctl to setup caller's creds */
215 int afs_nobody = NFS_NOBODY;
218 HandleIoctl(register struct vcache *avc, register afs_int32 acom,
219 struct afs_ioctl *adata)
221 register afs_int32 code;
224 AFS_STATCNT(HandleIoctl);
226 switch (acom & 0xff) {
228 avc->states |= CSafeStore;
232 /* case 2 used to be abort store, but this is no longer provided,
233 * since it is impossible to implement under normal Unix.
237 /* return the name of the cell this file is open on */
238 register struct cell *tcell;
239 register afs_int32 i;
241 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
243 i = strlen(tcell->cellName) + 1; /* bytes to copy out */
245 if (i > adata->out_size) {
246 /* 0 means we're not interested in the output */
247 if (adata->out_size != 0)
251 AFS_COPYOUT(tcell->cellName, adata->out, i, code);
253 afs_PutCell(tcell, READ_LOCK);
259 case 49: /* VIOC_GETINITPARAMS */
260 if (adata->out_size < sizeof(struct cm_initparams)) {
263 AFS_COPYOUT(&cm_initParams, adata->out,
264 sizeof(struct cm_initparams), code);
276 return code; /* so far, none implemented */
281 /* For aix we don't temporarily bypass ioctl(2) but rather do our
282 * thing directly in the vnode layer call, VNOP_IOCTL; thus afs_ioctl
283 * is now called from afs_gn_ioctl.
286 afs_ioctl(struct vcache *tvc, int cmd, int arg)
288 struct afs_ioctl data;
291 AFS_STATCNT(afs_ioctl);
292 if (((cmd >> 8) & 0xff) == 'V') {
293 /* This is a VICEIOCTL call */
294 AFS_COPYIN(arg, (caddr_t) & data, sizeof(data), error);
297 error = HandleIoctl(tvc, cmd, &data);
300 /* No-op call; just return. */
304 #endif /* AFS_AIX_ENV */
306 #if defined(AFS_SGI_ENV)
307 afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
310 , struct vopbd * vbds
314 struct afs_ioctl data;
320 AFS_STATCNT(afs_ioctl);
321 if (((cmd >> 8) & 0xff) == 'V') {
322 /* This is a VICEIOCTL call */
323 error = copyin_afs_ioctl(arg, &data);
326 locked = ISAFS_GLOCK();
329 error = HandleIoctl(tvc, cmd, &data);
334 /* No-op call; just return. */
338 #endif /* AFS_SGI_ENV */
340 /* unlike most calls here, this one uses u.u_error to return error conditions,
341 since this is really an intercepted chapter 2 call, rather than a vnode
344 /* AFS_HPUX102 and up uses VNODE ioctl instead */
345 #if !defined(AFS_HPUX102_ENV) && !defined(AFS_DARWIN80_ENV)
346 #if !defined(AFS_SGI_ENV)
350 kioctl(fdes, com, arg, ext, arg2, arg3)
351 #else /* __64BIT__ */
352 kioctl32(fdes, com, arg, ext, arg2, arg3)
353 #endif /* __64BIT__ */
356 kioctl(fdes, com, arg, ext)
367 } u_uap, *uap = &u_uap;
369 #if defined(AFS_SUN5_ENV)
371 struct afs_ioctl_sys {
378 struct afs_ioctl_sys *uap;
381 #elif defined(AFS_OSF_ENV)
382 afs_xioctl(p, args, retval)
391 } *uap = (struct a *)args;
392 #elif defined(AFS_FBSD50_ENV)
395 afs_xioctl(td, uap, retval)
397 register struct ioctl_args *uap;
400 struct proc *p = td->td_proc;
401 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
409 afs_xioctl(p, uap, retval)
411 register struct ioctl_args *uap;
414 #elif defined(AFS_LINUX22_ENV)
415 struct afs_ioctl_sys {
420 afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
423 struct afs_ioctl_sys ua, *uap = &ua;
432 } *uap = (struct a *)u.u_ap;
433 #endif /* AFS_SUN5_ENV */
435 #if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
437 #elif !defined(AFS_LINUX22_ENV)
438 register struct file *fd;
440 #if defined(AFS_XBSD_ENV)
441 register struct filedesc *fdp;
443 register struct vcache *tvc;
444 register int ioctlDone = 0, code = 0;
446 AFS_STATCNT(afs_xioctl);
447 #if defined(AFS_DARWIN_ENV)
448 if ((code = fdgetf(p, uap->fd, &fd)))
450 #elif defined(AFS_XBSD_ENV)
452 if ((u_int) uap->fd >= fdp->fd_nfiles
453 || (fd = fdp->fd_ofiles[uap->fd]) == NULL)
455 if ((fd->f_flag & (FREAD | FWRITE)) == 0)
457 #elif defined(AFS_LINUX22_ENV)
460 #elif defined(AFS_AIX32_ENV)
468 if (setuerror(getf(uap->fd, &fd))) {
471 #elif defined(AFS_OSF_ENV)
473 if (code = getf(&fd, uap->fd, FILE_FLAGS_NULL, &u.u_file_state))
475 #elif defined(AFS_SUN5_ENV)
476 # if defined(AFS_SUN57_ENV)
480 # elif defined(AFS_SUN54_ENV)
485 if (code = getf(uap->fd, &fd)) {
488 # endif /* AFS_SUN57_ENV */
494 /* first determine whether this is any sort of vnode */
495 #if defined(AFS_LINUX22_ENV)
500 if (fd->f_vnode->v_type == VREG || fd->f_vnode->v_type == VDIR) {
502 if (fd->f_type == DTYPE_VNODE) {
504 /* good, this is a vnode; next see if it is an AFS vnode */
505 #if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV)
506 tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */
507 #elif defined(AFS_OBSD_ENV)
509 IsAfsVnode((struct vnode *)fd->
510 f_data) ? VTOAFS((struct vnode *)fd->f_data) : NULL;
512 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
514 #endif /* AFS_LINUX22_ENV */
515 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
516 /* This is an AFS vnode */
517 if (((uap->com >> 8) & 0xff) == 'V') {
518 register struct afs_ioctl *datap;
521 (struct afs_ioctl *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
522 code=copyin_afs_ioctl((char *)uap->arg, datap);
524 osi_FreeSmallSpace(datap);
526 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
529 #if defined(AFS_SUN5_ENV)
544 #else /* AFS_OSF_ENV */
548 #ifdef AFS_LINUX22_ENV
558 code = HandleIoctl(tvc, uap->com, datap);
559 osi_FreeSmallSpace(datap);
573 #if defined(AFS_LINUX22_ENV)
585 code = okioctl(fdes, com, arg, ext, arg2, arg3);
586 #else /* __64BIT__ */
587 code = okioctl32(fdes, com, arg, ext, arg2, arg3);
588 #endif /* __64BIT__ */
589 #else /* !AFS_AIX51_ENV */
590 code = okioctl(fdes, com, arg, ext);
591 #endif /* AFS_AIX51_ENV */
593 #else /* !AFS_AIX41_ENV */
595 okioctl(fdes, com, arg, ext);
596 #elif defined(AFS_SUN5_ENV)
597 #if defined(AFS_SUN57_ENV)
599 #elif defined(AFS_SUN54_ENV)
604 code = ioctl(uap, rvp);
605 #elif defined(AFS_FBSD50_ENV)
606 return ioctl(td, uap);
607 #elif defined(AFS_FBSD_ENV)
608 return ioctl(p, uap);
609 #elif defined(AFS_OBSD_ENV)
610 code = sys_ioctl(p, uap, retval);
611 #elif defined(AFS_DARWIN_ENV)
612 return ioctl(p, uap, retval);
613 #elif defined(AFS_OSF_ENV)
614 code = ioctl(p, args, retval);
621 #elif !defined(AFS_LINUX22_ENV)
635 #ifdef AFS_LINUX22_ENV
638 #if defined(KERNEL_HAVE_UERROR)
641 #if defined(AFS_AIX32_ENV) && !defined(AFS_AIX41_ENV)
642 return (getuerror()? -1 : u.u_ioctlrv);
644 return getuerror()? -1 : 0;
647 #endif /* AFS_LINUX22_ENV */
648 #endif /* AFS_SUN5_ENV */
649 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
653 #endif /* AFS_SGI_ENV */
654 #endif /* AFS_HPUX102_ENV */
656 #if defined(AFS_SGI_ENV)
657 /* "pioctl" system call entry point; just pass argument to the parameterized
666 afs_pioctl(struct pioctlargs *uap, rval_t * rvp)
670 AFS_STATCNT(afs_pioctl);
672 code = afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow);
681 #elif defined(AFS_OSF_ENV)
682 afs_pioctl(p, args, retval)
692 } *uap = (struct a *)args;
694 AFS_STATCNT(afs_pioctl);
695 return (afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow));
698 #elif defined(AFS_FBSD50_ENV)
700 afs_pioctl(td, args, retval)
710 } *uap = (struct a *)args;
712 AFS_STATCNT(afs_pioctl);
713 return (afs_syscall_pioctl
714 (uap->path, uap->cmd, uap->cmarg, uap->follow, td->td_ucred));
717 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
719 afs_pioctl(p, args, retval)
729 } *uap = (struct a *)args;
731 AFS_STATCNT(afs_pioctl);
732 #ifdef AFS_DARWIN80_ENV
733 return (afs_syscall_pioctl
734 (uap->path, uap->cmd, uap->cmarg, uap->follow,
737 return (afs_syscall_pioctl
738 (uap->path, uap->cmd, uap->cmarg, uap->follow,
739 p->p_cred->pc_ucred));
745 /* macro to avoid adding any more #ifdef's to pioctl code. */
746 #if defined(AFS_LINUX22_ENV) || defined(AFS_AIX41_ENV)
747 #define PIOCTL_FREE_CRED() crfree(credp)
749 #define PIOCTL_FREE_CRED()
754 afs_syscall_pioctl(path, com, cmarg, follow, rvp, credp)
756 struct AFS_UCRED *credp;
758 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
759 afs_syscall_pioctl(path, com, cmarg, follow, credp)
760 struct AFS_UCRED *credp;
762 afs_syscall_pioctl(path, com, cmarg, follow)
770 struct afs_ioctl data;
771 #ifdef AFS_NEED_CLIENTCONTEXT
772 struct AFS_UCRED *tmpcred = NULL;
774 struct AFS_UCRED *foreigncreds = NULL;
775 register afs_int32 code = 0;
776 struct vnode *vp = NULL;
778 struct ucred *credp = crref(); /* don't free until done! */
780 #ifdef AFS_LINUX22_ENV
781 cred_t *credp = crref(); /* don't free until done! */
785 AFS_STATCNT(afs_syscall_pioctl);
787 follow = 1; /* compat. with old venus */
788 code = copyin_afs_ioctl(cmarg, &data);
791 #if defined(KERNEL_HAVE_UERROR)
796 if ((com & 0xff) == PSetClientContext) {
797 #ifdef AFS_NEED_CLIENTCONTEXT
798 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV)
799 code = HandleClientContext(&data, &com, &foreigncreds, credp);
801 code = HandleClientContext(&data, &com, &foreigncreds, osi_curcred());
805 crfree(foreigncreds);
808 #if defined(KERNEL_HAVE_UERROR)
809 return (setuerror(code), code);
814 #else /* AFS_NEED_CLIENTCONTEXT */
816 #endif /* AFS_NEED_CLIENTCONTEXT */
818 #ifdef AFS_NEED_CLIENTCONTEXT
821 * We could have done without temporary setting the u.u_cred below
822 * (foreigncreds could be passed as param the pioctl modules)
823 * but calls such as afs_osi_suser() doesn't allow that since it
824 * references u.u_cred directly. We could, of course, do something
825 * like afs_osi_suser(cred) which, I think, is better since it
826 * generalizes and supports multi cred environments...
828 #if defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
830 credp = foreigncreds;
831 #elif defined(AFS_AIX41_ENV)
832 tmpcred = crref(); /* XXX */
834 #elif defined(AFS_HPUX101_ENV)
835 tmpcred = p_cred(u.u_procp);
836 set_p_cred(u.u_procp, foreigncreds);
837 #elif defined(AFS_SGI_ENV)
838 tmpcred = OSI_GET_CURRENT_CRED();
839 OSI_SET_CURRENT_CRED(foreigncreds);
842 u.u_cred = foreigncreds;
845 #endif /* AFS_NEED_CLIENTCONTEXT */
846 if ((com & 0xff) == 15) {
847 /* special case prefetch so entire pathname eval occurs in helper process.
848 * otherwise, the pioctl call is essentially useless */
849 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
851 Prefetch(path, &data, follow,
852 foreigncreds ? foreigncreds : credp);
854 code = Prefetch(path, &data, follow, osi_curcred());
857 #if defined(KERNEL_HAVE_UERROR)
866 lookupname(path, USR, follow, NULL, &vp,
867 foreigncreds ? foreigncreds : credp);
869 #ifdef AFS_LINUX22_ENV
870 code = gop_lookupname(path, AFS_UIOUSER, follow, &dp);
872 vp = (struct vnode *)dp->d_inode;
874 code = gop_lookupname(path, AFS_UIOUSER, follow, &vp);
875 #endif /* AFS_LINUX22_ENV */
876 #endif /* AFS_AIX41_ENV */
880 #if defined(KERNEL_HAVE_UERROR)
888 #if defined(AFS_SUN510_ENV)
889 if (vp && !IsAfsVnode(vp)) {
890 struct vnode *realvp;
892 #ifdef AFS_SUN511_ENV
893 (VOP_REALVP(vp, &realvp, NULL) == 0)
895 (VOP_REALVP(vp, &realvp) == 0)
898 struct vnode *oldvp = vp;
906 /* now make the call if we were passed no file, or were passed an AFS file */
907 if (!vp || IsAfsVnode(vp)) {
908 #if defined(AFS_SUN5_ENV)
909 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
910 #elif defined(AFS_AIX41_ENV)
912 struct ucred *cred1, *cred2;
915 cred1 = cred2 = foreigncreds;
917 cred1 = cred2 = credp;
919 code = afs_HandlePioctl(vp, com, &data, follow, &cred1);
920 if (cred1 != cred2) {
921 /* something changed the creds */
925 #elif defined(AFS_HPUX101_ENV)
927 struct ucred *cred = p_cred(u.u_procp);
928 code = afs_HandlePioctl(vp, com, &data, follow, &cred);
930 #elif defined(AFS_SGI_ENV)
933 credp = OSI_GET_CURRENT_CRED();
934 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
936 #elif defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
937 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
939 code = afs_HandlePioctl(vp, com, &data, follow, &u.u_cred);
942 #if defined(KERNEL_HAVE_UERROR)
945 code = EINVAL; /* not in /afs */
950 #if defined(AFS_NEED_CLIENTCONTEXT)
953 crset(tmpcred); /* restore original credentials */
955 #if defined(AFS_HPUX101_ENV)
956 set_p_cred(u.u_procp, tmpcred); /* restore original credentials */
957 #elif defined(AFS_SGI_ENV)
958 OSI_SET_CURRENT_CRED(tmpcred); /* restore original credentials */
959 #elif defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
960 credp = tmpcred; /* restore original credentials */
962 osi_curcred() = tmpcred; /* restore original credentials */
963 #endif /* AFS_HPUX101_ENV */
964 crfree(foreigncreds);
967 #endif /* AFS_NEED_CLIENTCONTEXT */
969 #ifdef AFS_LINUX22_ENV
972 AFS_RELE(vp); /* put vnode back */
976 #if defined(KERNEL_HAVE_UERROR)
979 return (getuerror());
985 #define MAXPIOCTLTOKENLEN \
986 (3*sizeof(afs_int32)+MAXKTCTICKETLEN+sizeof(struct ClearToken)+MAXKTCREALMLEN)
989 afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
990 register struct afs_ioctl *ablob, int afollow,
991 struct AFS_UCRED **acred)
994 struct vrequest treq;
995 register afs_int32 code;
996 register afs_int32 function, device;
997 afs_int32 inSize, outSize, outSizeMax;
998 char *inData, *outData;
999 int (*(*pioctlSw)) ();
1001 struct afs_fakestat_state fakestate;
1003 avc = avp ? VTOAFS(avp) : NULL;
1004 afs_Trace3(afs_iclSetp, CM_TRACE_PIOCTL, ICL_TYPE_INT32, acom & 0xff,
1005 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, afollow);
1006 AFS_STATCNT(HandlePioctl);
1007 if ((code = afs_InitReq(&treq, *acred)))
1009 afs_InitFakeStat(&fakestate);
1011 code = afs_EvalFakeStat(&avc, &fakestate, &treq);
1013 afs_PutFakeStat(&fakestate);
1017 device = (acom & 0xff00) >> 8;
1019 case 'V': /* Original pioctls */
1020 pioctlSw = VpioctlSw;
1021 pioctlSwSize = sizeof(VpioctlSw);
1023 case 'C': /* Coordinated/common pioctls */
1024 pioctlSw = CpioctlSw;
1025 pioctlSwSize = sizeof(CpioctlSw);
1027 case 'O': /* Coordinated/common pioctls */
1028 pioctlSw = OpioctlSw;
1029 pioctlSwSize = sizeof(OpioctlSw);
1032 afs_PutFakeStat(&fakestate);
1035 function = acom & 0xff;
1036 if (function >= (pioctlSwSize / sizeof(char *))) {
1037 afs_PutFakeStat(&fakestate);
1038 return EINVAL; /* out of range */
1040 inSize = ablob->in_size;
1042 /* Do all range checking before continuing */
1043 if (inSize > MAXPIOCTLTOKENLEN || inSize < 0 || ablob->out_size < 0)
1046 /* Note that we use osi_Alloc for large allocs and osi_AllocLargeSpace for small ones */
1047 if (inSize > AFS_LRALLOCSIZ) {
1048 inData = osi_Alloc(inSize + 1);
1050 inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1055 AFS_COPYIN(ablob->in, inData, inSize, code);
1056 inData[inSize] = '\0';
1060 if (inSize > AFS_LRALLOCSIZ) {
1061 osi_Free(inData, inSize + 1);
1063 osi_FreeLargeSpace(inData);
1065 afs_PutFakeStat(&fakestate);
1068 if (function == 8 && device == 'V') { /* PGetTokens */
1069 outSizeMax = MAXPIOCTLTOKENLEN;
1070 outData = osi_Alloc(outSizeMax);
1072 outSizeMax = AFS_LRALLOCSIZ;
1073 outData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1076 if (inSize > AFS_LRALLOCSIZ) {
1077 osi_Free(inData, inSize + 1);
1079 osi_FreeLargeSpace(inData);
1081 afs_PutFakeStat(&fakestate);
1086 (*pioctlSw[function]) (avc, function, &treq, inData, outData, inSize,
1088 if (inSize > AFS_LRALLOCSIZ) {
1089 osi_Free(inData, inSize + 1);
1091 osi_FreeLargeSpace(inData);
1093 if (code == 0 && ablob->out_size > 0) {
1094 if (outSize > ablob->out_size) {
1095 code = E2BIG; /* data wont fit in user buffer */
1096 } else if (outSize) {
1097 AFS_COPYOUT(outData, ablob->out, outSize, code);
1100 if (outSizeMax > AFS_LRALLOCSIZ) {
1101 osi_Free(outData, outSizeMax);
1103 osi_FreeLargeSpace(outData);
1105 afs_PutFakeStat(&fakestate);
1106 return afs_CheckCode(code, &treq, 41);
1109 DECL_PIOCTL(PGetFID)
1111 AFS_STATCNT(PGetFID);
1114 memcpy(aout, (char *)&avc->fid, sizeof(struct VenusFid));
1115 *aoutSize = sizeof(struct VenusFid);
1119 DECL_PIOCTL(PSetAcl)
1121 register afs_int32 code;
1123 struct AFSOpaque acl;
1124 struct AFSVolSync tsync;
1125 struct AFSFetchStatus OutStatus;
1128 AFS_STATCNT(PSetAcl);
1131 if ((acl.AFSOpaque_len = strlen(ain) + 1) > 1024 /* AFSOPAQUEMAX */)
1134 acl.AFSOpaque_val = ain;
1136 tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1138 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREACL);
1141 RXAFS_StoreACL(tconn->id, (struct AFSFid *)&avc->fid.Fid,
1142 &acl, &OutStatus, &tsync);
1147 } while (afs_Analyze
1148 (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_STOREACL,
1149 SHARED_LOCK, NULL));
1151 /* now we've forgotten all of the access info */
1152 ObtainWriteLock(&afs_xcbhash, 455);
1154 afs_DequeueCallback(avc);
1155 avc->states &= ~(CStatd | CUnique);
1156 ReleaseWriteLock(&afs_xcbhash);
1157 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
1158 osi_dnlc_purgedp(avc);
1162 int afs_defaultAsynchrony = 0;
1164 DECL_PIOCTL(PStoreBehind)
1167 struct sbstruct *sbr;
1169 sbr = (struct sbstruct *)ain;
1170 if (sbr->sb_default != -1) {
1171 if (afs_osi_suser(*acred))
1172 afs_defaultAsynchrony = sbr->sb_default;
1177 if (avc && (sbr->sb_thisfile != -1)) {
1179 (avc, PRSFS_WRITE | PRSFS_ADMINISTER, areq, DONT_CHECK_MODE_BITS))
1180 avc->asynchrony = sbr->sb_thisfile;
1185 *aoutSize = sizeof(struct sbstruct);
1186 sbr = (struct sbstruct *)aout;
1187 sbr->sb_default = afs_defaultAsynchrony;
1189 sbr->sb_thisfile = avc->asynchrony;
1195 DECL_PIOCTL(PGCPAGs)
1197 if (!afs_osi_suser(*acred)) {
1200 afs_gcpags = AFS_GCPAGS_USERDISABLED;
1204 DECL_PIOCTL(PGetAcl)
1206 struct AFSOpaque acl;
1207 struct AFSVolSync tsync;
1208 struct AFSFetchStatus OutStatus;
1214 AFS_STATCNT(PGetAcl);
1217 Fid.Volume = avc->fid.Fid.Volume;
1218 Fid.Vnode = avc->fid.Fid.Vnode;
1219 Fid.Unique = avc->fid.Fid.Unique;
1220 if (avc->states & CForeign) {
1222 * For a dfs xlator acl we have a special hack so that the
1223 * xlator will distinguish which type of acl will return. So
1224 * we currently use the top 2-bytes (vals 0-4) to tell which
1225 * type of acl to bring back. Horrible hack but this will
1226 * cause the least number of changes to code size and interfaces.
1228 if (Fid.Vnode & 0xc0000000)
1230 Fid.Vnode |= (ainSize << 30);
1232 acl.AFSOpaque_val = aout;
1234 tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1237 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHACL);
1239 code = RXAFS_FetchACL(tconn->id, &Fid, &acl, &OutStatus, &tsync);
1244 } while (afs_Analyze
1245 (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_FETCHACL,
1246 SHARED_LOCK, NULL));
1249 *aoutSize = (acl.AFSOpaque_len == 0 ? 1 : acl.AFSOpaque_len);
1262 AFS_STATCNT(PBogus);
1266 DECL_PIOCTL(PGetFileCell)
1268 register struct cell *tcell;
1270 AFS_STATCNT(PGetFileCell);
1273 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
1276 strcpy(aout, tcell->cellName);
1277 afs_PutCell(tcell, READ_LOCK);
1278 *aoutSize = strlen(aout) + 1;
1282 DECL_PIOCTL(PGetWSCell)
1284 struct cell *tcell = NULL;
1286 AFS_STATCNT(PGetWSCell);
1287 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1288 return EIO; /* Inappropriate ioctl for device */
1290 tcell = afs_GetPrimaryCell(READ_LOCK);
1291 if (!tcell) /* no primary cell? */
1293 strcpy(aout, tcell->cellName);
1294 *aoutSize = strlen(aout) + 1;
1295 afs_PutCell(tcell, READ_LOCK);
1299 DECL_PIOCTL(PGetUserCell)
1301 register afs_int32 i;
1302 register struct unixuser *tu;
1303 register struct cell *tcell;
1305 AFS_STATCNT(PGetUserCell);
1306 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1307 return EIO; /* Inappropriate ioctl for device */
1309 /* return the cell name of the primary cell for this user */
1310 i = UHash(areq->uid);
1311 ObtainWriteLock(&afs_xuser, 224);
1312 for (tu = afs_users[i]; tu; tu = tu->next) {
1313 if (tu->uid == areq->uid && (tu->states & UPrimary)) {
1315 ReleaseWriteLock(&afs_xuser);
1320 tcell = afs_GetCell(tu->cell, READ_LOCK);
1321 afs_PutUser(tu, WRITE_LOCK);
1325 strcpy(aout, tcell->cellName);
1326 afs_PutCell(tcell, READ_LOCK);
1327 *aoutSize = strlen(aout) + 1; /* 1 for the null */
1330 ReleaseWriteLock(&afs_xuser);
1337 DECL_PIOCTL(PSetTokens)
1340 register struct unixuser *tu;
1341 struct ClearToken clear;
1342 register struct cell *tcell;
1345 struct vrequest treq;
1346 afs_int32 flag, set_parent_pag = 0;
1348 AFS_STATCNT(PSetTokens);
1349 if (!afs_resourceinit_flag) {
1352 memcpy((char *)&i, ain, sizeof(afs_int32));
1353 ain += sizeof(afs_int32);
1354 stp = ain; /* remember where the ticket is */
1355 if (i < 0 || i > MAXKTCTICKETLEN)
1356 return EINVAL; /* malloc may fail */
1358 ain += i; /* skip over ticket */
1359 memcpy((char *)&i, ain, sizeof(afs_int32));
1360 ain += sizeof(afs_int32);
1361 if (i != sizeof(struct ClearToken)) {
1364 memcpy((char *)&clear, ain, sizeof(struct ClearToken));
1365 if (clear.AuthHandle == -1)
1366 clear.AuthHandle = 999; /* more rxvab compat stuff */
1367 ain += sizeof(struct ClearToken);
1368 if (ainSize != 2 * sizeof(afs_int32) + stLen + sizeof(struct ClearToken)) {
1369 /* still stuff left? we've got primary flag and cell name. Set these */
1370 memcpy((char *)&flag, ain, sizeof(afs_int32)); /* primary id flag */
1371 ain += sizeof(afs_int32); /* skip id field */
1372 /* rest is cell name, look it up */
1373 /* some versions of gcc appear to need != 0 in order to get this right */
1374 if ((flag & 0x8000) != 0) { /* XXX Use Constant XXX */
1378 tcell = afs_GetCellByName(ain, READ_LOCK);
1382 /* default to primary cell, primary id */
1383 flag = 1; /* primary id */
1384 tcell = afs_GetPrimaryCell(READ_LOCK);
1389 afs_PutCell(tcell, READ_LOCK);
1390 if (set_parent_pag) {
1392 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1393 #if defined(AFS_DARWIN_ENV)
1394 struct proc *p = current_proc(); /* XXX */
1396 struct proc *p = curproc; /* XXX */
1398 #ifndef AFS_DARWIN80_ENV
1399 uprintf("Process %d (%s) tried to change pags in PSetTokens\n",
1400 p->p_pid, p->p_comm);
1402 if (!setpag(p, acred, -1, &pag, 1)) {
1405 if (!setpag(u.u_procp, acred, -1, &pag, 1)) { /* XXX u.u_procp is a no-op XXX */
1407 if (!setpag(acred, -1, &pag, 1)) {
1410 afs_InitReq(&treq, *acred);
1414 /* now we just set the tokens */
1415 tu = afs_GetUser(areq->uid, i, WRITE_LOCK); /* i has the cell # */
1416 tu->vid = clear.ViceId;
1417 if (tu->stp != NULL) {
1418 afs_osi_Free(tu->stp, tu->stLen);
1420 tu->stp = (char *)afs_osi_Alloc(stLen);
1421 if (tu->stp == NULL) {
1425 memcpy(tu->stp, stp, stLen);
1428 afs_stats_cmfullperf.authent.TicketUpdates++;
1429 afs_ComputePAGStats();
1430 #endif /* AFS_NOSTATS */
1431 tu->states |= UHasTokens;
1432 tu->states &= ~UTokensBad;
1433 afs_SetPrimary(tu, flag);
1434 tu->tokenTime = osi_Time();
1435 afs_ResetUserConns(tu);
1436 afs_PutUser(tu, WRITE_LOCK);
1451 DECL_PIOCTL(PGetVolumeStatus)
1454 char *offLineMsg = afs_osi_Alloc(256);
1455 char *motd = afs_osi_Alloc(256);
1456 register struct conn *tc;
1457 register afs_int32 code = 0;
1458 struct AFSFetchVolumeStatus volstat;
1460 char *Name, *OfflineMsg, *MOTD;
1463 AFS_STATCNT(PGetVolumeStatus);
1469 OfflineMsg = offLineMsg;
1472 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1474 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS);
1477 RXAFS_GetVolumeStatus(tc->id, avc->fid.Fid.Volume, &volstat,
1478 &Name, &OfflineMsg, &MOTD);
1483 } while (afs_Analyze
1484 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS,
1485 SHARED_LOCK, NULL));
1489 /* Copy all this junk into msg->im_data, keeping track of the lengths. */
1491 memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
1492 cp += sizeof(VolumeStatus);
1493 strcpy(cp, volName);
1494 cp += strlen(volName) + 1;
1495 strcpy(cp, offLineMsg);
1496 cp += strlen(offLineMsg) + 1;
1498 cp += strlen(motd) + 1;
1499 *aoutSize = (cp - aout);
1501 afs_osi_Free(offLineMsg, 256);
1502 afs_osi_Free(motd, 256);
1506 DECL_PIOCTL(PSetVolumeStatus)
1509 char *offLineMsg = afs_osi_Alloc(256);
1510 char *motd = afs_osi_Alloc(256);
1511 register struct conn *tc;
1512 register afs_int32 code = 0;
1513 struct AFSFetchVolumeStatus volstat;
1514 struct AFSStoreVolumeStatus storeStat;
1515 register struct volume *tvp;
1519 AFS_STATCNT(PSetVolumeStatus);
1525 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
1527 if (tvp->states & (VRO | VBackup)) {
1528 afs_PutVolume(tvp, READ_LOCK);
1532 afs_PutVolume(tvp, READ_LOCK);
1537 /* Copy the junk out, using cp as a roving pointer. */
1539 memcpy((char *)&volstat, cp, sizeof(AFSFetchVolumeStatus));
1540 cp += sizeof(AFSFetchVolumeStatus);
1541 if (strlen(cp) >= sizeof(volName)) {
1545 strcpy(volName, cp);
1546 cp += strlen(volName) + 1;
1547 if (strlen(cp) >= sizeof(offLineMsg)) {
1551 strcpy(offLineMsg, cp);
1552 cp += strlen(offLineMsg) + 1;
1553 if (strlen(cp) >= sizeof(motd)) {
1559 if (volstat.MinQuota != -1) {
1560 storeStat.MinQuota = volstat.MinQuota;
1561 storeStat.Mask |= AFS_SETMINQUOTA;
1563 if (volstat.MaxQuota != -1) {
1564 storeStat.MaxQuota = volstat.MaxQuota;
1565 storeStat.Mask |= AFS_SETMAXQUOTA;
1568 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1570 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS);
1573 RXAFS_SetVolumeStatus(tc->id, avc->fid.Fid.Volume, &storeStat,
1574 volName, offLineMsg, motd);
1579 } while (afs_Analyze
1580 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS,
1581 SHARED_LOCK, NULL));
1585 /* we are sending parms back to make compat. with prev system. should
1586 * change interface later to not ask for current status, just set new status */
1588 memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
1589 cp += sizeof(VolumeStatus);
1590 strcpy(cp, volName);
1591 cp += strlen(volName) + 1;
1592 strcpy(cp, offLineMsg);
1593 cp += strlen(offLineMsg) + 1;
1595 cp += strlen(motd) + 1;
1596 *aoutSize = cp - aout;
1598 afs_osi_Free(offLineMsg, 256);
1599 afs_osi_Free(motd, 256);
1605 AFS_STATCNT(PFlush);
1608 #ifdef AFS_BOZONLOCK_ENV
1609 afs_BozonLock(&avc->pvnLock, avc); /* Since afs_TryToSmush will do a pvn_vptrunc */
1611 ObtainWriteLock(&avc->lock, 225);
1612 ObtainWriteLock(&afs_xcbhash, 456);
1613 afs_DequeueCallback(avc);
1614 avc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
1615 ReleaseWriteLock(&afs_xcbhash);
1616 /* now find the disk cache entries */
1617 afs_TryToSmush(avc, *acred, 1);
1618 osi_dnlc_purgedp(avc);
1619 if (avc->linkData && !(avc->states & CCore)) {
1620 afs_osi_Free(avc->linkData, strlen(avc->linkData) + 1);
1621 avc->linkData = NULL;
1623 ReleaseWriteLock(&avc->lock);
1624 #ifdef AFS_BOZONLOCK_ENV
1625 afs_BozonUnlock(&avc->pvnLock, avc);
1630 DECL_PIOCTL(PNewStatMount)
1632 register afs_int32 code;
1633 register struct vcache *tvc;
1634 register struct dcache *tdc;
1635 struct VenusFid tfid;
1637 struct sysname_info sysState;
1638 afs_size_t offset, len;
1640 AFS_STATCNT(PNewStatMount);
1643 code = afs_VerifyVCache(avc, areq);
1646 if (vType(avc) != VDIR) {
1649 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
1652 Check_AtSys(avc, ain, &sysState, areq);
1653 ObtainReadLock(&tdc->lock);
1655 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
1656 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
1657 ReleaseReadLock(&tdc->lock);
1658 afs_PutDCache(tdc); /* we're done with the data */
1659 bufp = sysState.name;
1663 tfid.Cell = avc->fid.Cell;
1664 tfid.Fid.Volume = avc->fid.Fid.Volume;
1665 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
1666 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
1668 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
1674 if (tvc->mvstat != 1) {
1679 ObtainWriteLock(&tvc->lock, 226);
1680 code = afs_HandleLink(tvc, areq);
1682 if (tvc->linkData) {
1683 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
1686 /* we have the data */
1687 strcpy(aout, tvc->linkData);
1688 *aoutSize = strlen(tvc->linkData) + 1;
1693 ReleaseWriteLock(&tvc->lock);
1696 if (sysState.allocked)
1697 osi_FreeLargeSpace(bufp);
1701 DECL_PIOCTL(PGetTokens)
1703 register struct cell *tcell;
1704 register afs_int32 i;
1705 register struct unixuser *tu;
1710 AFS_STATCNT(PGetTokens);
1711 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1712 return EIO; /* Inappropriate ioctl for device */
1714 /* weird interface. If input parameter is present, it is an integer and
1715 * we're supposed to return the parm'th tokens for this unix uid.
1716 * If not present, we just return tokens for cell 1.
1717 * If counter out of bounds, return EDOM.
1718 * If no tokens for the particular cell, return ENOTCONN.
1719 * Also, if this mysterious parm is present, we return, along with the
1720 * tokens, the primary cell indicator (an afs_int32 0) and the cell name
1721 * at the end, in that order.
1723 if ((newStyle = (ainSize > 0))) {
1724 memcpy((char *)&iterator, ain, sizeof(afs_int32));
1726 i = UHash(areq->uid);
1727 ObtainReadLock(&afs_xuser);
1728 for (tu = afs_users[i]; tu; tu = tu->next) {
1730 if (tu->uid == areq->uid && (tu->states & UHasTokens)) {
1731 if (iterator-- == 0)
1732 break; /* are we done yet? */
1735 if (tu->uid == areq->uid && afs_IsPrimaryCellNum(tu->cell))
1741 * No need to hold a read lock on each user entry
1745 ReleaseReadLock(&afs_xuser);
1750 if (((tu->states & UHasTokens) == 0)
1751 || (tu->ct.EndTimestamp < osi_Time())) {
1752 tu->states |= (UTokensBad | UNeedsReset);
1753 afs_PutUser(tu, READ_LOCK);
1756 /* use iterator for temp */
1758 iterator = tu->stLen; /* for compat, we try to return 56 byte tix if they fit */
1760 iterator = 56; /* # of bytes we're returning */
1761 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1762 cp += sizeof(afs_int32);
1763 memcpy(cp, tu->stp, tu->stLen); /* copy out st */
1765 iterator = sizeof(struct ClearToken);
1766 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1767 cp += sizeof(afs_int32);
1768 memcpy(cp, (char *)&tu->ct, sizeof(struct ClearToken));
1769 cp += sizeof(struct ClearToken);
1771 /* put out primary id and cell name, too */
1772 iterator = (tu->states & UPrimary ? 1 : 0);
1773 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1774 cp += sizeof(afs_int32);
1775 tcell = afs_GetCell(tu->cell, READ_LOCK);
1777 strcpy(cp, tcell->cellName);
1778 cp += strlen(tcell->cellName) + 1;
1779 afs_PutCell(tcell, READ_LOCK);
1783 *aoutSize = cp - aout;
1784 afs_PutUser(tu, READ_LOCK);
1790 register afs_int32 i;
1791 register struct unixuser *tu;
1793 AFS_STATCNT(PUnlog);
1794 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1795 return EIO; /* Inappropriate ioctl for device */
1797 i = UHash(areq->uid);
1798 ObtainWriteLock(&afs_xuser, 227);
1799 for (tu = afs_users[i]; tu; tu = tu->next) {
1800 if (tu->uid == areq->uid) {
1802 tu->states &= ~UHasTokens;
1803 /* security is not having to say you're sorry */
1804 memset((char *)&tu->ct, 0, sizeof(struct ClearToken));
1806 ReleaseWriteLock(&afs_xuser);
1807 /* We have to drop the lock over the call to afs_ResetUserConns, since
1808 * it obtains the afs_xvcache lock. We could also keep the lock, and
1809 * modify ResetUserConns to take parm saying we obtained the lock
1810 * already, but that is overkill. By keeping the "tu" pointer
1811 * held over the released lock, we guarantee that we won't lose our
1812 * place, and that we'll pass over every user conn that existed when
1813 * we began this call.
1815 afs_ResetUserConns(tu);
1817 ObtainWriteLock(&afs_xuser, 228);
1819 /* set the expire times to 0, causes
1820 * afs_GCUserData to remove this entry
1822 tu->ct.EndTimestamp = 0;
1824 #endif /* UKERNEL */
1827 ReleaseWriteLock(&afs_xuser);
1831 DECL_PIOCTL(PMariner)
1833 afs_int32 newHostAddr;
1834 afs_int32 oldHostAddr;
1836 AFS_STATCNT(PMariner);
1838 memcpy((char *)&oldHostAddr, (char *)&afs_marinerHost,
1841 oldHostAddr = 0xffffffff; /* disabled */
1843 memcpy((char *)&newHostAddr, ain, sizeof(afs_int32));
1844 if (newHostAddr == 0xffffffff) {
1845 /* disable mariner operations */
1847 } else if (newHostAddr) {
1849 afs_marinerHost = newHostAddr;
1851 memcpy(aout, (char *)&oldHostAddr, sizeof(afs_int32));
1852 *aoutSize = sizeof(afs_int32);
1856 DECL_PIOCTL(PCheckServers)
1858 register char *cp = 0;
1860 register struct server *ts;
1861 afs_int32 temp, *lp = (afs_int32 *) ain, havecell = 0;
1863 struct chservinfo *pcheck;
1865 AFS_STATCNT(PCheckServers);
1867 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1868 return EIO; /* Inappropriate ioctl for device */
1870 if (*lp == 0x12345678) { /* For afs3.3 version */
1871 pcheck = (struct chservinfo *)ain;
1872 if (pcheck->tinterval >= 0) {
1874 memcpy(cp, (char *)&afs_probe_interval, sizeof(afs_int32));
1875 *aoutSize = sizeof(afs_int32);
1876 if (pcheck->tinterval > 0) {
1877 if (!afs_osi_suser(*acred))
1879 afs_probe_interval = pcheck->tinterval;
1885 temp = pcheck->tflags;
1886 cp = pcheck->tbuffer;
1887 } else { /* For pre afs3.3 versions */
1888 memcpy((char *)&temp, ain, sizeof(afs_int32));
1889 cp = ain + sizeof(afs_int32);
1890 if (ainSize > sizeof(afs_int32))
1895 * 1: fast check, don't contact servers.
1896 * 2: local cell only.
1899 /* have cell name, too */
1900 cellp = afs_GetCellByName(cp, READ_LOCK);
1905 if (!cellp && (temp & 2)) {
1906 /* use local cell */
1907 cellp = afs_GetPrimaryCell(READ_LOCK);
1909 if (!(temp & 1)) { /* if not fast, call server checker routine */
1910 afs_CheckServers(1, cellp); /* check down servers */
1911 afs_CheckServers(0, cellp); /* check up servers */
1913 /* now return the current down server list */
1915 ObtainReadLock(&afs_xserver);
1916 for (i = 0; i < NSERVERS; i++) {
1917 for (ts = afs_servers[i]; ts; ts = ts->next) {
1918 if (cellp && ts->cell != cellp)
1919 continue; /* cell spec'd and wrong */
1920 if ((ts->flags & SRVR_ISDOWN)
1921 && ts->addr->sa_portal != ts->cell->vlport) {
1922 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
1923 cp += sizeof(afs_int32);
1927 ReleaseReadLock(&afs_xserver);
1929 afs_PutCell(cellp, READ_LOCK);
1930 *aoutSize = cp - aout;
1934 DECL_PIOCTL(PCheckVolNames)
1936 AFS_STATCNT(PCheckVolNames);
1937 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1938 return EIO; /* Inappropriate ioctl for device */
1940 afs_CheckRootVolume();
1941 afs_CheckVolumeNames(AFS_VOLCHECK_FORCE | AFS_VOLCHECK_EXPIRED |
1942 AFS_VOLCHECK_BUSY | AFS_VOLCHECK_MTPTS);
1946 DECL_PIOCTL(PCheckAuth)
1951 struct unixuser *tu;
1954 AFS_STATCNT(PCheckAuth);
1955 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1956 return EIO; /* Inappropriate ioctl for device */
1959 tu = afs_GetUser(areq->uid, 1, READ_LOCK); /* check local cell authentication */
1963 /* we have a user */
1964 ObtainReadLock(&afs_xsrvAddr);
1965 ObtainReadLock(&afs_xconn);
1967 /* any tokens set? */
1968 if ((tu->states & UHasTokens) == 0)
1970 /* all connections in cell 1 working? */
1971 for (i = 0; i < NSERVERS; i++) {
1972 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
1973 for (tc = sa->conns; tc; tc = tc->next) {
1974 if (tc->user == tu && (tu->states & UTokensBad))
1979 ReleaseReadLock(&afs_xsrvAddr);
1980 ReleaseReadLock(&afs_xconn);
1981 afs_PutUser(tu, READ_LOCK);
1983 memcpy(aout, (char *)&retValue, sizeof(afs_int32));
1984 *aoutSize = sizeof(afs_int32);
1989 Prefetch(char *apath, struct afs_ioctl *adata, int afollow,
1990 struct AFS_UCRED *acred)
1993 register afs_int32 code;
1994 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2000 AFS_STATCNT(Prefetch);
2003 tp = osi_AllocLargeSpace(1024);
2004 AFS_COPYINSTR(apath, tp, 1024, &bufferSize, code);
2006 osi_FreeLargeSpace(tp);
2009 if (afs_BBusy()) { /* do this as late as possible */
2010 osi_FreeLargeSpace(tp);
2011 return EWOULDBLOCK; /* pretty close */
2013 afs_BQueue(BOP_PATH, (struct vcache *)0, 0, 0, acred, (afs_size_t) 0,
2014 (afs_size_t) 0, tp);
2018 DECL_PIOCTL(PFindVolume)
2020 register struct volume *tvp;
2021 register struct server *ts;
2022 register afs_int32 i;
2025 AFS_STATCNT(PFindVolume);
2028 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
2031 for (i = 0; i < MAXHOSTS; i++) {
2032 ts = tvp->serverHost[i];
2035 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
2036 cp += sizeof(afs_int32);
2039 /* still room for terminating NULL, add it on */
2040 ainSize = 0; /* reuse vbl */
2041 memcpy(cp, (char *)&ainSize, sizeof(afs_int32));
2042 cp += sizeof(afs_int32);
2044 *aoutSize = cp - aout;
2045 afs_PutVolume(tvp, READ_LOCK);
2051 DECL_PIOCTL(PViceAccess)
2053 register afs_int32 code;
2056 AFS_STATCNT(PViceAccess);
2059 code = afs_VerifyVCache(avc, areq);
2062 memcpy((char *)&temp, ain, sizeof(afs_int32));
2063 code = afs_AccessOK(avc, temp, areq, CHECK_MODE_BITS);
2070 DECL_PIOCTL(PPrecache)
2074 /*AFS_STATCNT(PPrecache);*/
2075 if (!afs_osi_suser(*acred))
2077 memcpy((char *)&newValue, ain, sizeof(afs_int32));
2078 afs_preCache = newValue*1024;
2082 DECL_PIOCTL(PSetCacheSize)
2087 AFS_STATCNT(PSetCacheSize);
2088 if (!afs_osi_suser(*acred))
2090 /* too many things are setup initially in mem cache version */
2091 if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
2093 memcpy((char *)&newValue, ain, sizeof(afs_int32));
2095 afs_cacheBlocks = afs_stats_cmperf.cacheBlocksOrig;
2097 if (newValue < afs_min_cache)
2098 afs_cacheBlocks = afs_min_cache;
2100 afs_cacheBlocks = newValue;
2102 afs_stats_cmperf.cacheBlocksTotal = afs_cacheBlocks;
2103 afs_ComputeCacheParms(); /* recompute basic cache parameters */
2104 afs_MaybeWakeupTruncateDaemon();
2105 while (waitcnt++ < 100 && afs_cacheBlocks < afs_blocksUsed) {
2106 afs_osi_Wait(1000, 0, 0);
2107 afs_MaybeWakeupTruncateDaemon();
2112 #define MAXGCSTATS 16
2113 DECL_PIOCTL(PGetCacheSize)
2115 afs_int32 results[MAXGCSTATS];
2117 register struct dcache * tdc;
2120 AFS_STATCNT(PGetCacheSize);
2122 if (sizeof(afs_int32) == ainSize){
2123 memcpy((char *)&flags, ain, sizeof(afs_int32));
2124 } else if (0 == ainSize){
2130 memset((char *)results, 0, sizeof(results));
2131 results[0] = afs_cacheBlocks;
2132 results[1] = afs_blocksUsed;
2133 results[2] = afs_cacheFiles;
2136 for (i = 0; i < afs_cacheFiles; i++) {
2137 if (afs_indexFlags[i] & IFFree) results[3]++;
2139 } else if (2 == flags){
2140 for (i = 0; i < afs_cacheFiles; i++) {
2141 if (afs_indexFlags[i] & IFFree) results[3]++;
2142 if (afs_indexFlags[i] & IFEverUsed) results[4]++;
2143 if (afs_indexFlags[i] & IFDataMod) results[5]++;
2144 if (afs_indexFlags[i] & IFDirtyPages) results[6]++;
2145 if (afs_indexFlags[i] & IFAnyPages) results[7]++;
2146 if (afs_indexFlags[i] & IFDiscarded) results[8]++;
2148 tdc = afs_indexTable[i];
2151 size = tdc->validPos;
2152 if ( 0 < size && size < (1<<12) ) results[10]++;
2153 else if (size < (1<<14) ) results[11]++;
2154 else if (size < (1<<16) ) results[12]++;
2155 else if (size < (1<<18) ) results[13]++;
2156 else if (size < (1<<20) ) results[14]++;
2157 else if (size >= (1<<20) ) results[15]++;
2161 memcpy(aout, (char *)results, sizeof(results));
2162 *aoutSize = sizeof(results);
2166 DECL_PIOCTL(PRemoveCallBack)
2168 register struct conn *tc;
2169 register afs_int32 code = 0;
2170 struct AFSCallBack CallBacks_Array[1];
2171 struct AFSCBFids theFids;
2172 struct AFSCBs theCBs;
2175 AFS_STATCNT(PRemoveCallBack);
2178 if (avc->states & CRO)
2179 return 0; /* read-only-ness can't change */
2180 ObtainWriteLock(&avc->lock, 229);
2181 theFids.AFSCBFids_len = 1;
2182 theCBs.AFSCBs_len = 1;
2183 theFids.AFSCBFids_val = (struct AFSFid *)&avc->fid.Fid;
2184 theCBs.AFSCBs_val = CallBacks_Array;
2185 CallBacks_Array[0].CallBackType = CB_DROPPED;
2186 if (avc->callback) {
2188 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2190 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
2192 code = RXAFS_GiveUpCallBacks(tc->id, &theFids, &theCBs);
2196 /* don't set code on failure since we wouldn't use it */
2197 } while (afs_Analyze
2198 (tc, code, &avc->fid, areq,
2199 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK, NULL));
2201 ObtainWriteLock(&afs_xcbhash, 457);
2202 afs_DequeueCallback(avc);
2204 avc->states &= ~(CStatd | CUnique);
2205 ReleaseWriteLock(&afs_xcbhash);
2206 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
2207 osi_dnlc_purgedp(avc);
2209 ReleaseWriteLock(&avc->lock);
2213 DECL_PIOCTL(PNewCell)
2215 /* create a new cell */
2216 afs_int32 cellHosts[MAXCELLHOSTS], *lp, magic = 0;
2217 char *newcell = 0, *linkedcell = 0, *tp = ain;
2218 register afs_int32 code, linkedstate = 0, ls;
2219 u_short fsport = 0, vlport = 0;
2222 AFS_STATCNT(PNewCell);
2223 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2224 return EIO; /* Inappropriate ioctl for device */
2226 if (!afs_osi_suser(*acred))
2229 memcpy((char *)&magic, tp, sizeof(afs_int32));
2230 tp += sizeof(afs_int32);
2231 if (magic != 0x12345678)
2234 /* A 3.4 fs newcell command will pass an array of MAXCELLHOSTS
2235 * server addresses while the 3.5 fs newcell command passes
2236 * MAXHOSTS. To figure out which is which, check if the cellname
2239 newcell = tp + (MAXCELLHOSTS + 3) * sizeof(afs_int32);
2240 scount = ((newcell[0] != '\0') ? MAXCELLHOSTS : MAXHOSTS);
2242 /* MAXCELLHOSTS (=8) is less than MAXHOSTS (=13) */
2243 memcpy((char *)cellHosts, tp, MAXCELLHOSTS * sizeof(afs_int32));
2244 tp += (scount * sizeof(afs_int32));
2246 lp = (afs_int32 *) tp;
2250 fsport = 0; /* Privileged ports not allowed */
2252 vlport = 0; /* Privileged ports not allowed */
2253 tp += (3 * sizeof(afs_int32));
2255 if ((ls = *lp) & 1) {
2256 linkedcell = tp + strlen(newcell) + 1;
2257 linkedstate |= CLinkedCell;
2260 linkedstate |= CNoSUID; /* setuid is disabled by default for fs newcell */
2262 afs_NewCell(newcell, cellHosts, linkedstate, linkedcell, fsport,
2267 DECL_PIOCTL(PNewAlias)
2269 /* create a new cell alias */
2271 register afs_int32 code;
2272 char *realName, *aliasName;
2274 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2275 return EIO; /* Inappropriate ioctl for device */
2277 if (!afs_osi_suser(*acred))
2281 tp += strlen(aliasName) + 1;
2284 code = afs_NewCellAlias(aliasName, realName);
2289 DECL_PIOCTL(PListCells)
2291 afs_int32 whichCell;
2292 register struct cell *tcell = 0;
2293 register afs_int32 i;
2294 register char *cp, *tp = ain;
2296 AFS_STATCNT(PListCells);
2297 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2298 return EIO; /* Inappropriate ioctl for device */
2300 memcpy((char *)&whichCell, tp, sizeof(afs_int32));
2301 tp += sizeof(afs_int32);
2302 tcell = afs_GetCellByIndex(whichCell, READ_LOCK);
2305 memset(cp, 0, MAXCELLHOSTS * sizeof(afs_int32));
2306 for (i = 0; i < MAXCELLHOSTS; i++) {
2307 if (tcell->cellHosts[i] == 0)
2309 memcpy(cp, (char *)&tcell->cellHosts[i]->addr->sa_ip,
2311 cp += sizeof(afs_int32);
2313 cp = aout + MAXCELLHOSTS * sizeof(afs_int32);
2314 strcpy(cp, tcell->cellName);
2315 cp += strlen(tcell->cellName) + 1;
2316 *aoutSize = cp - aout;
2317 afs_PutCell(tcell, READ_LOCK);
2325 DECL_PIOCTL(PListAliases)
2327 afs_int32 whichAlias;
2328 register struct cell_alias *tcalias = 0;
2329 register char *cp, *tp = ain;
2331 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2332 return EIO; /* Inappropriate ioctl for device */
2333 if (ainSize < sizeof(afs_int32))
2336 memcpy((char *)&whichAlias, tp, sizeof(afs_int32));
2337 tp += sizeof(afs_int32);
2339 tcalias = afs_GetCellAlias(whichAlias);
2342 strcpy(cp, tcalias->alias);
2343 cp += strlen(tcalias->alias) + 1;
2344 strcpy(cp, tcalias->cell);
2345 cp += strlen(tcalias->cell) + 1;
2346 *aoutSize = cp - aout;
2347 afs_PutCellAlias(tcalias);
2355 DECL_PIOCTL(PRemoveMount)
2357 register afs_int32 code;
2359 struct sysname_info sysState;
2360 afs_size_t offset, len;
2361 register struct conn *tc;
2362 register struct dcache *tdc;
2363 register struct vcache *tvc;
2364 struct AFSFetchStatus OutDirStatus;
2365 struct VenusFid tfid;
2366 struct AFSVolSync tsync;
2370 /* "ain" is the name of the file in this dir to remove */
2372 AFS_STATCNT(PRemoveMount);
2375 code = afs_VerifyVCache(avc, areq);
2378 if (vType(avc) != VDIR)
2381 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1); /* test for error below */
2384 Check_AtSys(avc, ain, &sysState, areq);
2385 ObtainReadLock(&tdc->lock);
2387 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
2388 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
2389 ReleaseReadLock(&tdc->lock);
2390 bufp = sysState.name;
2395 tfid.Cell = avc->fid.Cell;
2396 tfid.Fid.Volume = avc->fid.Fid.Volume;
2397 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
2398 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
2400 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
2407 if (tvc->mvstat != 1) {
2413 ObtainWriteLock(&tvc->lock, 230);
2414 code = afs_HandleLink(tvc, areq);
2416 if (tvc->linkData) {
2417 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
2422 ReleaseWriteLock(&tvc->lock);
2423 osi_dnlc_purgedp(tvc);
2429 ObtainWriteLock(&avc->lock, 231);
2430 osi_dnlc_remove(avc, bufp, tvc);
2432 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2434 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE);
2437 RXAFS_RemoveFile(tc->id, (struct AFSFid *)&avc->fid.Fid, bufp,
2438 &OutDirStatus, &tsync);
2443 } while (afs_Analyze
2444 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_REMOVEFILE,
2445 SHARED_LOCK, NULL));
2450 ReleaseWriteLock(&avc->lock);
2454 /* we have the thing in the cache */
2455 ObtainWriteLock(&tdc->lock, 661);
2456 if (afs_LocalHero(avc, tdc, &OutDirStatus, 1)) {
2457 /* we can do it locally */
2458 code = afs_dir_Delete(tdc, bufp);
2460 ZapDCE(tdc); /* surprise error -- invalid value */
2464 ReleaseWriteLock(&tdc->lock);
2465 afs_PutDCache(tdc); /* drop ref count */
2467 avc->states &= ~CUnique; /* For the dfs xlator */
2468 ReleaseWriteLock(&avc->lock);
2471 if (sysState.allocked)
2472 osi_FreeLargeSpace(bufp);
2476 DECL_PIOCTL(PVenusLogging)
2478 return EINVAL; /* OBSOLETE */
2481 DECL_PIOCTL(PGetCellStatus)
2483 register struct cell *tcell;
2486 AFS_STATCNT(PGetCellStatus);
2487 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2488 return EIO; /* Inappropriate ioctl for device */
2490 tcell = afs_GetCellByName(ain, READ_LOCK);
2493 temp = tcell->states;
2494 afs_PutCell(tcell, READ_LOCK);
2495 memcpy(aout, (char *)&temp, sizeof(afs_int32));
2496 *aoutSize = sizeof(afs_int32);
2500 DECL_PIOCTL(PSetCellStatus)
2502 register struct cell *tcell;
2505 if (!afs_osi_suser(*acred))
2507 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2508 return EIO; /* Inappropriate ioctl for device */
2510 tcell = afs_GetCellByName(ain + 2 * sizeof(afs_int32), WRITE_LOCK);
2513 memcpy((char *)&temp, ain, sizeof(afs_int32));
2515 tcell->states |= CNoSUID;
2517 tcell->states &= ~CNoSUID;
2518 afs_PutCell(tcell, WRITE_LOCK);
2522 DECL_PIOCTL(PFlushVolumeData)
2524 register afs_int32 i;
2525 register struct dcache *tdc;
2526 register struct vcache *tvc;
2527 register struct volume *tv;
2528 afs_int32 cell, volume;
2529 struct afs_q *tq, *uq;
2530 #ifdef AFS_DARWIN80_ENV
2534 AFS_STATCNT(PFlushVolumeData);
2537 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2538 return EIO; /* Inappropriate ioctl for device */
2540 volume = avc->fid.Fid.Volume; /* who to zap */
2541 cell = avc->fid.Cell;
2544 * Clear stat'd flag from all vnodes from this volume; this will invalidate all
2545 * the vcaches associated with the volume.
2548 ObtainReadLock(&afs_xvcache);
2549 i = VCHashV(&avc->fid);
2550 for (tq = afs_vhashTV[i].prev; tq != &afs_vhashTV[i]; tq = uq) {
2553 if (tvc->fid.Fid.Volume == volume && tvc->fid.Cell == cell) {
2554 if (tvc->states & CVInit) {
2555 ReleaseReadLock(&afs_xvcache);
2556 afs_osi_Sleep(&tvc->states);
2559 #ifdef AFS_DARWIN80_ENV
2560 if (tvc->states & CDeadVnode) {
2561 ReleaseReadLock(&afs_xvcache);
2562 afs_osi_Sleep(&tvc->states);
2566 #if defined(AFS_SGI_ENV) || defined(AFS_OSF_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
2567 VN_HOLD(AFSTOV(tvc));
2569 #ifdef AFS_DARWIN80_ENV
2573 if (vnode_ref(vp)) {
2580 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2583 VREFCOUNT_INC(tvc); /* AIX, apparently */
2587 ReleaseReadLock(&afs_xvcache);
2588 #ifdef AFS_BOZONLOCK_ENV
2589 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
2591 ObtainWriteLock(&tvc->lock, 232);
2593 ObtainWriteLock(&afs_xcbhash, 458);
2594 afs_DequeueCallback(tvc);
2595 tvc->states &= ~(CStatd | CDirty);
2596 ReleaseWriteLock(&afs_xcbhash);
2597 if (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
2598 osi_dnlc_purgedp(tvc);
2599 afs_TryToSmush(tvc, *acred, 1);
2600 ReleaseWriteLock(&tvc->lock);
2601 #ifdef AFS_BOZONLOCK_ENV
2602 afs_BozonUnlock(&tvc->pvnLock, tvc);
2604 #ifdef AFS_DARWIN80_ENV
2605 vnode_put(AFSTOV(tvc));
2607 ObtainReadLock(&afs_xvcache);
2609 /* our tvc ptr is still good until now */
2613 ReleaseReadLock(&afs_xvcache);
2616 MObtainWriteLock(&afs_xdcache, 328); /* needed if you're going to flush any stuff */
2617 for (i = 0; i < afs_cacheFiles; i++) {
2618 if (!(afs_indexFlags[i] & IFEverUsed))
2619 continue; /* never had any data */
2620 tdc = afs_GetDSlot(i, NULL);
2621 if (tdc->refCount <= 1) { /* too high, in use by running sys call */
2622 ReleaseReadLock(&tdc->tlock);
2623 if (tdc->f.fid.Fid.Volume == volume && tdc->f.fid.Cell == cell) {
2624 if (!(afs_indexFlags[i] & IFDataMod)) {
2625 /* if the file is modified, but has a ref cnt of only 1, then
2626 * someone probably has the file open and is writing into it.
2627 * Better to skip flushing such a file, it will be brought back
2628 * immediately on the next write anyway.
2630 * If we *must* flush, then this code has to be rearranged to call
2631 * afs_storeAllSegments() first */
2632 afs_FlushDCache(tdc);
2636 ReleaseReadLock(&tdc->tlock);
2638 afs_PutDCache(tdc); /* bumped by getdslot */
2640 MReleaseWriteLock(&afs_xdcache);
2642 ObtainReadLock(&afs_xvolume);
2643 for (i = 0; i < NVOLS; i++) {
2644 for (tv = afs_volumes[i]; tv; tv = tv->next) {
2645 if (tv->volume == volume) {
2646 afs_ResetVolumeInfo(tv);
2651 ReleaseReadLock(&afs_xvolume);
2653 /* probably, a user is doing this, probably, because things are screwed up.
2654 * maybe it's the dnlc's fault? */
2661 DECL_PIOCTL(PGetVnodeXStatus)
2663 register afs_int32 code;
2664 struct vcxstat stat;
2667 /* AFS_STATCNT(PGetVnodeXStatus); */
2670 code = afs_VerifyVCache(avc, areq);
2673 if (vType(avc) == VDIR)
2674 mode = PRSFS_LOOKUP;
2677 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
2680 memset(&stat, 0, sizeof(struct vcxstat));
2681 stat.fid = avc->fid;
2682 hset32(stat.DataVersion, hgetlo(avc->m.DataVersion));
2683 stat.lock = avc->lock;
2684 stat.parentVnode = avc->parentVnode;
2685 stat.parentUnique = avc->parentUnique;
2686 hset(stat.flushDV, avc->flushDV);
2687 hset(stat.mapDV, avc->mapDV);
2688 stat.truncPos = avc->truncPos;
2689 { /* just grab the first two - won't break anything... */
2690 struct axscache *ac;
2692 for (i = 0, ac = avc->Access; ac && i < CPSIZE; i++, ac = ac->next) {
2693 stat.randomUid[i] = ac->uid;
2694 stat.randomAccess[i] = ac->axess;
2697 stat.callback = afs_data_pointer_to_int32(avc->callback);
2698 stat.cbExpires = avc->cbExpires;
2699 stat.anyAccess = avc->anyAccess;
2700 stat.opens = avc->opens;
2701 stat.execsOrWriters = avc->execsOrWriters;
2702 stat.flockCount = avc->flockCount;
2703 stat.mvstat = avc->mvstat;
2704 stat.states = avc->states;
2705 memcpy(aout, (char *)&stat, sizeof(struct vcxstat));
2706 *aoutSize = sizeof(struct vcxstat);
2711 DECL_PIOCTL(PGetVnodeXStatus2)
2713 register afs_int32 code;
2714 struct vcxstat2 stat;
2719 code = afs_VerifyVCache(avc, areq);
2722 if (vType(avc) == VDIR)
2723 mode = PRSFS_LOOKUP;
2726 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
2729 memset(&stat, 0, sizeof(struct vcxstat2));
2731 stat.cbExpires = avc->cbExpires;
2732 stat.anyAccess = avc->anyAccess;
2733 stat.mvstat = avc->mvstat;
2734 stat.callerAccess = afs_GetAccessBits(avc, ~0, areq);
2736 memcpy(aout, (char *)&stat, sizeof(struct vcxstat2));
2737 *aoutSize = sizeof(struct vcxstat2);
2741 /* We require root for local sysname changes, but not for remote */
2742 /* (since we don't really believe remote uids anyway) */
2743 /* outname[] shouldn't really be needed- this is left as an excercise */
2744 /* for the reader. */
2745 DECL_PIOCTL(PSetSysName)
2747 char *cp, *cp2 = NULL, inname[MAXSYSNAME], outname[MAXSYSNAME];
2748 afs_int32 setsysname;
2750 register struct afs_exporter *exporter;
2751 register struct unixuser *au;
2752 register afs_int32 pag, error;
2753 int t, count, num = 0, allpags = 0;
2756 AFS_STATCNT(PSetSysName);
2757 if (!afs_globalVFS) {
2758 /* Afsd is NOT running; disable it */
2759 #if defined(KERNEL_HAVE_UERROR)
2760 return (setuerror(EINVAL), EINVAL);
2765 memset(inname, 0, MAXSYSNAME);
2766 memcpy(&setsysname, ain, sizeof(afs_int32));
2767 ain += sizeof(afs_int32);
2768 if (setsysname & 0x8000) {
2770 setsysname &= ~0x8000;
2775 if (setsysname < 0 || setsysname > MAXNUMSYSNAMES)
2778 for (cp = ain, count = 0; count < setsysname; count++) {
2779 /* won't go past end of ain since maxsysname*num < ain length */
2781 if (t >= MAXSYSNAME || t <= 0)
2783 /* check for names that can shoot us in the foot */
2784 if (*cp == '.' && (cp[1] == 0 || (cp[1] == '.' && cp[2] == 0)))
2790 /* inname gets first entry in case we're being a translator */
2792 memcpy(inname, ain, t + 1); /* include terminating null */
2796 if ((*acred)->cr_gid == RMTUSER_REQ ||
2797 (*acred)->cr_gid == RMTUSER_REQ_PRIV) { /* Handles all exporters */
2798 if (allpags && (*acred)->cr_gid != RMTUSER_REQ_PRIV) {
2801 pag = PagInCred(*acred);
2803 return EINVAL; /* Better than panicing */
2805 if (!(au = afs_FindUser(pag, -1, READ_LOCK))) {
2806 return EINVAL; /* Better than panicing */
2808 if (!(exporter = au->exporter)) {
2809 afs_PutUser(au, READ_LOCK);
2810 return EINVAL; /* Better than panicing */
2812 error = EXP_SYSNAME(exporter, (setsysname ? cp2 : NULL), &sysnamelist,
2815 if (error == ENODEV)
2816 foundname = 0; /* sysname not set yet! */
2818 afs_PutUser(au, READ_LOCK);
2823 strcpy(outname, sysnamelist[0]);
2825 afs_PutUser(au, READ_LOCK);
2829 /* Not xlating, so local case */
2831 osi_Panic("PSetSysName: !afs_sysname\n");
2832 if (!setsysname) { /* user just wants the info */
2833 strcpy(outname, afs_sysname);
2834 foundname = afs_sysnamecount;
2835 sysnamelist = afs_sysnamelist;
2836 } else { /* Local guy; only root can change sysname */
2837 if (!afs_osi_suser(*acred))
2840 /* allpags makes no sense for local use */
2844 /* clear @sys entries from the dnlc, once afs_lookup can
2845 * do lookups of @sys entries and thinks it can trust them */
2846 /* privs ok, store the entry, ... */
2847 strcpy(afs_sysname, inname);
2848 if (setsysname > 1) { /* ... or list */
2850 for (count = 1; count < setsysname; ++count) {
2851 if (!afs_sysnamelist[count])
2853 ("PSetSysName: no afs_sysnamelist entry to write\n");
2855 memcpy(afs_sysnamelist[count], cp, t + 1); /* include null */
2859 afs_sysnamecount = setsysname;
2864 cp = aout; /* not changing so report back the count and ... */
2865 memcpy(cp, (char *)&foundname, sizeof(afs_int32));
2866 cp += sizeof(afs_int32);
2868 strcpy(cp, outname); /* ... the entry, ... */
2869 cp += strlen(outname) + 1;
2870 for (count = 1; count < foundname; ++count) { /* ... or list. */
2871 if (!sysnamelist[count])
2873 ("PSetSysName: no afs_sysnamelist entry to read\n");
2874 t = strlen(sysnamelist[count]);
2875 if (t >= MAXSYSNAME)
2876 osi_Panic("PSetSysName: sysname entry garbled\n");
2877 strcpy(cp, sysnamelist[count]);
2881 *aoutSize = cp - aout;
2886 /* sequential search through the list of touched cells is not a good
2887 * long-term solution here. For small n, though, it should be just
2888 * fine. Should consider special-casing the local cell for large n.
2889 * Likewise for PSetSPrefs.
2891 * s - number of ids in array l[] -- NOT index of last id
2892 * l - array of cell ids which have volumes that need to be sorted
2893 * vlonly - sort vl servers or file servers?
2896 ReSortCells_cb(struct cell *cell, void *arg)
2898 afs_int32 *p = (afs_int32 *) arg;
2899 afs_int32 *l = p + 1;
2902 for (i = 0; i < s; i++) {
2903 if (l[i] == cell->cellNum) {
2904 ObtainWriteLock(&cell->lock, 690);
2905 afs_SortServers(cell->cellHosts, MAXCELLHOSTS);
2906 ReleaseWriteLock(&cell->lock);
2914 ReSortCells(int s, afs_int32 * l, int vlonly)
2922 p = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * (s + 1));
2924 memcpy(p + 1, l, s * sizeof(afs_int32));
2925 afs_TraverseCells(&ReSortCells_cb, p);
2926 afs_osi_Free(p, sizeof(afs_int32) * (s + 1));
2930 ObtainReadLock(&afs_xvolume);
2931 for (i = 0; i < NVOLS; i++) {
2932 for (j = afs_volumes[i]; j; j = j->next) {
2933 for (k = 0; k < s; k++)
2934 if (j->cell == l[k]) {
2935 ObtainWriteLock(&j->lock, 233);
2936 afs_SortServers(j->serverHost, MAXHOSTS);
2937 ReleaseWriteLock(&j->lock);
2942 ReleaseReadLock(&afs_xvolume);
2946 static int debugsetsp = 0;
2948 afs_setsprefs(sp, num, vlonly)
2951 unsigned int vlonly;
2954 int i, j, k, matches, touchedSize;
2955 struct server *srvr = NULL;
2956 afs_int32 touched[34];
2960 for (k = 0; k < num; sp++, k++) {
2962 printf("sp host=%x, rank=%d\n", sp->host.s_addr, sp->rank);
2965 ObtainReadLock(&afs_xserver);
2967 i = SHash(sp->host.s_addr);
2968 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2969 if (sa->sa_ip == sp->host.s_addr) {
2971 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
2972 || (sa->sa_portal == AFS_FSPORT);
2973 if ((!vlonly && isfs) || (vlonly && !isfs)) {
2980 if (sa && matches) { /* found one! */
2982 printf("sa ip=%x, ip_rank=%d\n", sa->sa_ip, sa->sa_iprank);
2984 sa->sa_iprank = sp->rank + afs_randomMod15();
2985 afs_SortOneServer(sa->server);
2988 /* if we don't know yet what cell it's in, this is moot */
2989 for (j = touchedSize - 1;
2990 j >= 0 && touched[j] != srvr->cell->cellNum; j--)
2991 /* is it in our list of touched cells ? */ ;
2992 if (j < 0) { /* no, it's not */
2993 touched[touchedSize++] = srvr->cell->cellNum;
2994 if (touchedSize >= 32) { /* watch for ovrflow */
2995 ReleaseReadLock(&afs_xserver);
2996 ReSortCells(touchedSize, touched, vlonly);
2998 ObtainReadLock(&afs_xserver);
3004 ReleaseReadLock(&afs_xserver);
3005 /* if we didn't find one, start to create one. */
3006 /* Note that it doesn't have a cell yet... */
3008 afs_uint32 temp = sp->host.s_addr;
3010 afs_GetServer(&temp, 1, 0, (vlonly ? AFS_VLPORT : AFS_FSPORT),
3011 WRITE_LOCK, (afsUUID *) 0, 0);
3012 srvr->addr->sa_iprank = sp->rank + afs_randomMod15();
3013 afs_PutServer(srvr, WRITE_LOCK);
3015 } /* for all cited preferences */
3017 ReSortCells(touchedSize, touched, vlonly);
3021 /* Note that this may only be performed by the local root user.
3023 DECL_PIOCTL(PSetSPrefs)
3025 struct setspref *ssp;
3026 AFS_STATCNT(PSetSPrefs);
3028 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3029 return EIO; /* Inappropriate ioctl for device */
3031 if (!afs_osi_suser(*acred))
3034 if (ainSize < sizeof(struct setspref))
3037 ssp = (struct setspref *)ain;
3038 if (ainSize < sizeof(struct spref) * ssp->num_servers)
3041 afs_setsprefs(&(ssp->servers[0]), ssp->num_servers,
3042 (ssp->flags & DBservers));
3046 DECL_PIOCTL(PSetSPrefs33)
3049 AFS_STATCNT(PSetSPrefs);
3050 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3051 return EIO; /* Inappropriate ioctl for device */
3054 if (!afs_osi_suser(*acred))
3057 sp = (struct spref *)ain;
3058 afs_setsprefs(sp, ainSize / (sizeof(struct spref)), 0 /*!vlonly */ );
3062 /* some notes on the following code...
3063 * in the hash table of server structs, all servers with the same IP address
3064 * will be on the same overflow chain.
3065 * This could be sped slightly in some circumstances by having it cache the
3066 * immediately previous slot in the hash table and some supporting information
3067 * Only reports file servers now.
3069 DECL_PIOCTL(PGetSPrefs)
3071 struct sprefrequest *spin; /* input */
3072 struct sprefinfo *spout; /* output */
3073 struct spref *srvout; /* one output component */
3074 int i, j; /* counters for hash table traversal */
3075 struct server *srvr; /* one of CM's server structs */
3077 int vlonly; /* just return vlservers ? */
3080 AFS_STATCNT(PGetSPrefs);
3081 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3082 return EIO; /* Inappropriate ioctl for device */
3085 if (ainSize < sizeof(struct sprefrequest_33)) {
3088 spin = ((struct sprefrequest *)ain);
3091 if (ainSize > sizeof(struct sprefrequest_33)) {
3092 vlonly = (spin->flags & DBservers);
3096 /* struct sprefinfo includes 1 server struct... that size gets added
3097 * in during the loop that follows.
3099 *aoutSize = sizeof(struct sprefinfo) - sizeof(struct spref);
3100 spout = (struct sprefinfo *)aout;
3101 spout->next_offset = spin->offset;
3102 spout->num_servers = 0;
3103 srvout = spout->servers;
3105 ObtainReadLock(&afs_xserver);
3106 for (i = 0, j = 0; j < NSERVERS; j++) { /* sift through hash table */
3107 for (sa = afs_srvAddrs[j]; sa; sa = sa->next_bkt, i++) {
3108 if (spin->offset > (unsigned short)i) {
3109 continue; /* catch up to where we left off */
3111 spout->next_offset++;
3114 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
3115 || (sa->sa_portal == AFS_FSPORT);
3117 if ((vlonly && isfs) || (!vlonly && !isfs)) {
3118 /* only report ranks for vl servers */
3122 srvout->host.s_addr = sa->sa_ip;
3123 srvout->rank = sa->sa_iprank;
3124 *aoutSize += sizeof(struct spref);
3125 spout->num_servers++;
3128 if (*aoutSize > (PIGGYSIZE - sizeof(struct spref))) {
3129 ReleaseReadLock(&afs_xserver); /* no more room! */
3134 ReleaseReadLock(&afs_xserver);
3136 spout->next_offset = 0; /* start over from the beginning next time */
3140 /* Enable/Disable the specified exporter. Must be root to disable an exporter */
3141 int afs_NFSRootOnly = 1;
3142 DECL_PIOCTL(PExportAfs)
3144 afs_int32 export, newint =
3145 0, type, changestate, handleValue, convmode, pwsync, smounts;
3146 afs_int32 rempags = 0, pagcb = 0;
3147 register struct afs_exporter *exporter;
3149 AFS_STATCNT(PExportAfs);
3150 memcpy((char *)&handleValue, ain, sizeof(afs_int32));
3151 type = handleValue >> 24;
3156 exporter = exporter_find(type);
3158 export = handleValue & 3;
3159 changestate = handleValue & 0xfff;
3160 smounts = (handleValue >> 2) & 3;
3161 pwsync = (handleValue >> 4) & 3;
3162 convmode = (handleValue >> 6) & 3;
3163 rempags = (handleValue >> 8) & 3;
3164 pagcb = (handleValue >> 10) & 3;
3166 changestate = (handleValue >> 16) & 0x1;
3167 convmode = (handleValue >> 16) & 0x2;
3168 pwsync = (handleValue >> 16) & 0x4;
3169 smounts = (handleValue >> 16) & 0x8;
3170 export = handleValue & 0xff;
3173 /* Failed finding desired exporter; */
3177 handleValue = exporter->exp_states;
3178 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3179 *aoutSize = sizeof(afs_int32);
3181 if (!afs_osi_suser(*acred))
3182 return EACCES; /* Only superuser can do this */
3186 exporter->exp_states |= EXP_EXPORTED;
3188 exporter->exp_states &= ~EXP_EXPORTED;
3192 exporter->exp_states |= EXP_UNIXMODE;
3194 exporter->exp_states &= ~EXP_UNIXMODE;
3198 exporter->exp_states |= EXP_PWSYNC;
3200 exporter->exp_states &= ~EXP_PWSYNC;
3204 afs_NFSRootOnly = 0;
3205 exporter->exp_states |= EXP_SUBMOUNTS;
3207 afs_NFSRootOnly = 1;
3208 exporter->exp_states &= ~EXP_SUBMOUNTS;
3213 exporter->exp_states |= EXP_CLIPAGS;
3215 exporter->exp_states &= ~EXP_CLIPAGS;
3219 exporter->exp_states |= EXP_CALLBACK;
3221 exporter->exp_states &= ~EXP_CALLBACK;
3223 handleValue = exporter->exp_states;
3224 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3225 *aoutSize = sizeof(afs_int32);
3228 exporter->exp_states |= EXP_EXPORTED;
3230 exporter->exp_states &= ~EXP_EXPORTED;
3232 exporter->exp_states |= EXP_UNIXMODE;
3234 exporter->exp_states &= ~EXP_UNIXMODE;
3236 exporter->exp_states |= EXP_PWSYNC;
3238 exporter->exp_states &= ~EXP_PWSYNC;
3240 afs_NFSRootOnly = 0;
3241 exporter->exp_states |= EXP_SUBMOUNTS;
3243 afs_NFSRootOnly = 1;
3244 exporter->exp_states &= ~EXP_SUBMOUNTS;
3254 struct gaginfo *gagflags;
3256 if (!afs_osi_suser(*acred))
3259 gagflags = (struct gaginfo *)ain;
3260 afs_showflags = gagflags->showflags;
3266 DECL_PIOCTL(PTwiddleRx)
3268 struct rxparams *rxp;
3270 if (!afs_osi_suser(*acred))
3273 rxp = (struct rxparams *)ain;
3275 if (rxp->rx_initReceiveWindow)
3276 rx_initReceiveWindow = rxp->rx_initReceiveWindow;
3277 if (rxp->rx_maxReceiveWindow)
3278 rx_maxReceiveWindow = rxp->rx_maxReceiveWindow;
3279 if (rxp->rx_initSendWindow)
3280 rx_initSendWindow = rxp->rx_initSendWindow;
3281 if (rxp->rx_maxSendWindow)
3282 rx_maxSendWindow = rxp->rx_maxSendWindow;
3283 if (rxp->rxi_nSendFrags)
3284 rxi_nSendFrags = rxp->rxi_nSendFrags;
3285 if (rxp->rxi_nRecvFrags)
3286 rxi_nRecvFrags = rxp->rxi_nRecvFrags;
3287 if (rxp->rxi_OrphanFragSize)
3288 rxi_OrphanFragSize = rxp->rxi_OrphanFragSize;
3289 if (rxp->rx_maxReceiveSize) {
3290 rx_maxReceiveSize = rxp->rx_maxReceiveSize;
3291 rx_maxReceiveSizeUser = rxp->rx_maxReceiveSize;
3293 if (rxp->rx_MyMaxSendSize)
3294 rx_MyMaxSendSize = rxp->rx_MyMaxSendSize;
3299 DECL_PIOCTL(PGetInitParams)
3301 if (sizeof(struct cm_initparams) > PIGGYSIZE)
3304 memcpy(aout, (char *)&cm_initParams, sizeof(struct cm_initparams));
3305 *aoutSize = sizeof(struct cm_initparams);
3309 #ifdef AFS_SGI65_ENV
3310 /* They took crget() from us, so fake it. */
3315 cr = crdup(get_current_cred());
3316 memset((char *)cr, 0, sizeof(cred_t));
3317 #if CELL || CELL_PREPARE
3324 DECL_PIOCTL(PGetRxkcrypt)
3326 memcpy(aout, (char *)&cryptall, sizeof(afs_int32));
3327 *aoutSize = sizeof(afs_int32);
3331 DECL_PIOCTL(PSetRxkcrypt)
3335 if (!afs_osi_suser(*acred))
3337 if (ainSize != sizeof(afs_int32) || ain == NULL)
3339 memcpy((char *)&tmpval, ain, sizeof(afs_int32));
3340 /* if new mappings added later this will need to be changed */
3341 if (tmpval != 0 && tmpval != 1)
3347 #ifdef AFS_NEED_CLIENTCONTEXT
3349 * Create new credentials to correspond to a remote user with given
3350 * <hostaddr, uid, g0, g1>. This allows a server running as root to
3351 * provide pioctl (and other) services to foreign clients (i.e. nfs
3352 * clients) by using this call to `become' the client.
3355 #define PIOCTL_HEADER 6
3357 HandleClientContext(struct afs_ioctl *ablob, int *com,
3358 struct AFS_UCRED **acred, struct AFS_UCRED *credp)
3361 afs_uint32 hostaddr;
3362 afs_int32 uid, g0, g1, i, code, pag, exporter_type, isroot = 0;
3363 struct afs_exporter *exporter, *outexporter;
3364 struct AFS_UCRED *newcred;
3365 struct unixuser *au;
3366 afs_uint32 comp = *com & 0xff00;
3369 #if defined(AFS_SGIMP_ENV)
3370 osi_Assert(ISAFS_GLOCK());
3372 AFS_STATCNT(HandleClientContext);
3373 if (ablob->in_size < PIOCTL_HEADER * sizeof(afs_int32)) {
3374 /* Must at least include the PIOCTL_HEADER header words required by the protocol */
3375 return EINVAL; /* Too small to be good */
3377 ain = inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
3378 AFS_COPYIN(ablob->in, ain, PIOCTL_HEADER * sizeof(afs_int32), code);
3380 osi_FreeLargeSpace(inData);
3384 /* Extract information for remote user */
3385 hostaddr = *((afs_uint32 *) ain);
3386 ain += sizeof(hostaddr);
3387 uid = *((afs_uint32 *) ain);
3389 g0 = *((afs_uint32 *) ain);
3391 g1 = *((afs_uint32 *) ain);
3393 *com = *((afs_uint32 *) ain);
3394 ain += sizeof(afs_int32);
3395 exporter_type = *((afs_uint32 *) ain); /* In case we support more than NFS */
3398 * Of course, one must be root for most of these functions, but
3399 * we'll allow (for knfs) you to set things if the pag is 0 and
3400 * you're setting tokens or unlogging.
3403 if (!afs_osi_suser(credp)) {
3404 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
3405 /* Since SGI's suser() returns explicit failure after the call.. */
3408 /* check for acceptable opcodes for normal folks, which are, so far,
3409 * get/set tokens, sysname, and unlog.
3411 if (i != 9 && i != 3 && i != 38 && i != 8) {
3412 osi_FreeLargeSpace(inData);
3417 ablob->in_size -= PIOCTL_HEADER * sizeof(afs_int32);
3418 ablob->in += PIOCTL_HEADER * sizeof(afs_int32);
3419 osi_FreeLargeSpace(inData);
3422 * We map uid 0 to nobody to match the mapping that the nfs
3423 * server does and to ensure that the suser() calls in the afs
3424 * code fails for remote client roots.
3426 uid = afs_nobody; /* NFS_NOBODY == -2 */
3430 #ifdef AFS_AIX41_ENV
3433 newcred->cr_gid = isroot ? RMTUSER_REQ_PRIV : RMTUSER_REQ;
3434 #ifdef AFS_AIX51_ENV
3435 newcred->cr_groupset.gs_union.un_groups[0] = g0;
3436 newcred->cr_groupset.gs_union.un_groups[1] = g1;
3437 #elif defined(AFS_LINUX26_ENV)
3438 #ifdef AFS_LINUX26_ONEGROUP_ENV
3439 newcred->cr_group_info = groups_alloc(1); /* not that anything sets this */
3440 l = (((g0-0x3f00) & 0x3fff) << 14) | ((g1-0x3f00) & 0x3fff);
3441 h = ((g0-0x3f00) >> 14);
3442 h = ((g1-0x3f00) >> 14) + h + h + h;
3443 GROUP_AT(newcred->cr_group_info, 0) = ((h << 28) | l);
3445 newcred->cr_group_info = groups_alloc(2);
3446 GROUP_AT(newcred->cr_group_info, 0) = g0;
3447 GROUP_AT(newcred->cr_group_info, 1) = g1;
3450 newcred->cr_groups[0] = g0;
3451 newcred->cr_groups[1] = g1;
3454 newcred->cr_ngrps = 2;
3455 #elif !defined(AFS_LINUX26_ENV)
3456 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
3457 newcred->cr_ngroups = 2;
3459 for (i = 2; i < NGROUPS; i++)
3460 newcred->cr_groups[i] = NOGROUP;
3463 #if !defined(AFS_OSF_ENV)
3464 afs_nfsclient_init(); /* before looking for exporter, ensure one exists */
3466 if (!(exporter = exporter_find(exporter_type))) {
3467 /* Exporter wasn't initialized or an invalid exporter type */
3471 if (exporter->exp_states & EXP_PWSYNC) {
3472 if (uid != credp->cr_uid) {
3474 return ENOEXEC; /* XXX Find a better errno XXX */
3477 newcred->cr_uid = uid; /* Only temporary */
3478 code = EXP_REQHANDLER(exporter, &newcred, hostaddr, &pag, &outexporter);
3479 /* The client's pag is the only unique identifier for it */
3480 newcred->cr_uid = pag;
3482 if (!code && *com == PSETPAG) {
3483 /* Special case for 'setpag' */
3484 afs_uint32 pagvalue = genpag();
3486 au = afs_GetUser(pagvalue, -1, WRITE_LOCK); /* a new unixuser struct */
3488 * Note that we leave the 'outexporter' struct held so it won't
3491 au->exporter = outexporter;
3492 if (ablob->out_size >= 4) {
3493 AFS_COPYOUT((char *)&pagvalue, ablob->out, sizeof(afs_int32),
3496 afs_PutUser(au, WRITE_LOCK);
3499 return PSETPAG; /* Special return for setpag */
3501 EXP_RELE(outexporter);
3504 *com = (*com) | comp;
3507 #endif /* AFS_NEED_CLIENTCONTEXT */
3509 /* get all interface addresses of this client */
3511 DECL_PIOCTL(PGetCPrefs)
3513 struct sprefrequest *spin; /* input */
3514 struct sprefinfo *spout; /* output */
3515 struct spref *srvout; /* one output component */
3519 AFS_STATCNT(PGetCPrefs);
3520 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3521 return EIO; /* Inappropriate ioctl for device */
3523 if (ainSize < sizeof(struct sprefrequest))
3526 spin = (struct sprefrequest *)ain;
3527 spout = (struct sprefinfo *)aout;
3529 maxNumber = spin->num_servers; /* max addrs this time */
3530 srvout = spout->servers;
3532 ObtainReadLock(&afs_xinterface);
3534 /* copy out the client interface information from the
3535 ** kernel data structure "interface" to the output buffer
3537 for (i = spin->offset, j = 0; (i < afs_cb_interface.numberOfInterfaces)
3538 && (j < maxNumber); i++, j++, srvout++)
3539 srvout->host.s_addr = afs_cb_interface.addr_in[i];
3541 spout->num_servers = j;
3542 *aoutSize = sizeof(struct sprefinfo) + (j - 1) * sizeof(struct spref);
3544 if (i >= afs_cb_interface.numberOfInterfaces)
3545 spout->next_offset = 0; /* start from beginning again */
3547 spout->next_offset = spin->offset + j;
3549 ReleaseReadLock(&afs_xinterface);
3553 DECL_PIOCTL(PSetCPrefs)
3555 struct setspref *sin;
3558 AFS_STATCNT(PSetCPrefs);
3559 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3560 return EIO; /* Inappropriate ioctl for device */
3562 sin = (struct setspref *)ain;
3564 if (ainSize < sizeof(struct setspref))
3566 #if 0 /* num_servers is unsigned */
3567 if (sin->num_servers < 0)
3570 if (sin->num_servers > AFS_MAX_INTERFACE_ADDR)
3573 ObtainWriteLock(&afs_xinterface, 412);
3574 afs_cb_interface.numberOfInterfaces = sin->num_servers;
3575 for (i = 0; (unsigned short)i < sin->num_servers; i++)
3576 afs_cb_interface.addr_in[i] = sin->servers[i].host.s_addr;
3578 ReleaseWriteLock(&afs_xinterface);
3582 DECL_PIOCTL(PFlushMount)
3584 register afs_int32 code;
3585 register struct vcache *tvc;
3586 register struct dcache *tdc;
3587 struct VenusFid tfid;
3589 struct sysname_info sysState;
3590 afs_size_t offset, len;
3592 AFS_STATCNT(PFlushMount);
3595 code = afs_VerifyVCache(avc, areq);
3598 if (vType(avc) != VDIR) {
3601 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
3604 Check_AtSys(avc, ain, &sysState, areq);
3605 ObtainReadLock(&tdc->lock);
3607 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
3608 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
3609 ReleaseReadLock(&tdc->lock);
3610 afs_PutDCache(tdc); /* we're done with the data */
3611 bufp = sysState.name;
3615 tfid.Cell = avc->fid.Cell;
3616 tfid.Fid.Volume = avc->fid.Fid.Volume;
3617 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
3618 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
3620 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3626 if (tvc->mvstat != 1) {
3631 #ifdef AFS_BOZONLOCK_ENV
3632 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
3634 ObtainWriteLock(&tvc->lock, 649);
3635 ObtainWriteLock(&afs_xcbhash, 650);
3636 afs_DequeueCallback(tvc);
3637 tvc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
3638 ReleaseWriteLock(&afs_xcbhash);
3639 /* now find the disk cache entries */
3640 afs_TryToSmush(tvc, *acred, 1);
3641 osi_dnlc_purgedp(tvc);
3642 if (tvc->linkData && !(tvc->states & CCore)) {
3643 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
3644 tvc->linkData = NULL;
3646 ReleaseWriteLock(&tvc->lock);
3647 #ifdef AFS_BOZONLOCK_ENV
3648 afs_BozonUnlock(&tvc->pvnLock, tvc);
3652 if (sysState.allocked)
3653 osi_FreeLargeSpace(bufp);
3657 DECL_PIOCTL(PRxStatProc)
3662 if (!afs_osi_suser(*acred)) {
3666 if (ainSize != sizeof(afs_int32)) {
3670 memcpy((char *)&flags, ain, sizeof(afs_int32));
3671 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3675 if (flags & AFSCALL_RXSTATS_ENABLE) {
3676 rx_enableProcessRPCStats();
3678 if (flags & AFSCALL_RXSTATS_DISABLE) {
3679 rx_disableProcessRPCStats();
3681 if (flags & AFSCALL_RXSTATS_CLEAR) {
3682 rx_clearProcessRPCStats(AFS_RX_STATS_CLEAR_ALL);
3690 DECL_PIOCTL(PRxStatPeer)
3695 if (!afs_osi_suser(*acred)) {
3699 if (ainSize != sizeof(afs_int32)) {
3703 memcpy((char *)&flags, ain, sizeof(afs_int32));
3704 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3708 if (flags & AFSCALL_RXSTATS_ENABLE) {
3709 rx_enablePeerRPCStats();
3711 if (flags & AFSCALL_RXSTATS_DISABLE) {
3712 rx_disablePeerRPCStats();
3714 if (flags & AFSCALL_RXSTATS_CLEAR) {
3715 rx_clearPeerRPCStats(AFS_RX_STATS_CLEAR_ALL);
3722 DECL_PIOCTL(PPrefetchFromTape)
3724 register afs_int32 code, code1;
3727 struct rx_call *tcall;
3728 struct AFSVolSync tsync;
3729 struct AFSFetchStatus OutStatus;
3730 struct AFSCallBack CallBack;
3731 struct VenusFid tfid;
3735 AFS_STATCNT(PSetAcl);
3739 if (ain && (ainSize == 3 * sizeof(afs_int32)))
3740 Fid = (struct AFSFid *)ain;
3742 Fid = &avc->fid.Fid;
3743 tfid.Cell = avc->fid.Cell;
3744 tfid.Fid.Volume = Fid->Volume;
3745 tfid.Fid.Vnode = Fid->Vnode;
3746 tfid.Fid.Unique = Fid->Unique;
3748 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3750 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3751 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &avc->fid);
3754 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3755 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &tvc->fid);
3758 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3762 tcall = rx_NewCall(tc->id);
3764 StartRXAFS_FetchData(tcall, (struct AFSFid *)&tvc->fid.Fid, 0,
3767 bytes = rx_Read(tcall, (char *)aout, sizeof(afs_int32));
3769 EndRXAFS_FetchData(tcall, &OutStatus, &CallBack, &tsync);
3771 code1 = rx_EndCall(tcall, code);
3775 } while (afs_Analyze
3776 (tc, code, &tvc->fid, areq, AFS_STATS_FS_RPCIDX_RESIDENCYRPCS,
3777 SHARED_LOCK, NULL));
3778 /* This call is done only to have the callback things handled correctly */
3779 afs_FetchStatus(tvc, &tfid, areq, &OutStatus);
3783 *aoutSize = sizeof(afs_int32);
3788 DECL_PIOCTL(PResidencyCmd)
3790 register afs_int32 code;
3793 struct ResidencyCmdInputs *Inputs;
3794 struct ResidencyCmdOutputs *Outputs;
3795 struct VenusFid tfid;
3798 Inputs = (struct ResidencyCmdInputs *)ain;
3799 Outputs = (struct ResidencyCmdOutputs *)aout;
3802 if (!ain || ainSize != sizeof(struct ResidencyCmdInputs))
3807 Fid = &avc->fid.Fid;
3809 tfid.Cell = avc->fid.Cell;
3810 tfid.Fid.Volume = Fid->Volume;
3811 tfid.Fid.Vnode = Fid->Vnode;
3812 tfid.Fid.Unique = Fid->Unique;
3814 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3815 afs_Trace3(afs_iclSetp, CM_TRACE_RESIDCMD, ICL_TYPE_POINTER, tvc,
3816 ICL_TYPE_INT32, Inputs->command, ICL_TYPE_FID, &tfid);
3820 if (Inputs->command) {
3822 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3826 RXAFS_ResidencyCmd(tc->id, Fid, Inputs,
3827 (struct ResidencyCmdOutputs *)aout);
3831 } while (afs_Analyze
3832 (tc, code, &tvc->fid, areq,
3833 AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK, NULL));
3834 /* This call is done to have the callback things handled correctly */
3835 afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3836 } else { /* just a status request, return also link data */
3838 Outputs->code = afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3839 Outputs->chars[0] = 0;
3840 if (vType(tvc) == VLNK) {
3841 ObtainWriteLock(&tvc->lock, 555);
3842 if (afs_HandleLink(tvc, areq) == 0)
3843 strncpy((char *)&Outputs->chars, tvc->linkData, MAXCMDCHARS);
3844 ReleaseWriteLock(&tvc->lock);
3851 *aoutSize = sizeof(struct ResidencyCmdOutputs);
3856 DECL_PIOCTL(PNewUuid)
3858 /*AFS_STATCNT(PNewUuid); */
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 ObtainWriteLock(&afs_xinterface, 555);
3866 afs_uuid_create(&afs_cb_interface.uuid);
3867 ReleaseWriteLock(&afs_xinterface);
3868 ForceAllNewConnections();
3872 DECL_PIOCTL(PCallBackAddr)
3875 afs_uint32 addr, code;
3881 struct unixuser *tu;
3882 struct srvAddr **addrs;
3884 /*AFS_STATCNT(PCallBackAddr); */
3885 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
3886 return EIO; /* Inappropriate ioctl for device */
3888 if (!afs_osi_suser(acred))
3891 if (ainSize < sizeof(afs_int32))
3894 memcpy(&addr, ain, sizeof(afs_int32));
3896 ObtainReadLock(&afs_xinterface);
3897 for (i = 0; (unsigned short)i < afs_cb_interface.numberOfInterfaces; i++) {
3898 if (afs_cb_interface.addr_in[i] == addr)
3902 ReleaseWriteLock(&afs_xinterface);
3904 if (afs_cb_interface.addr_in[i] != addr)
3907 ObtainReadLock(&afs_xserver); /* Necessary? */
3908 ObtainReadLock(&afs_xsrvAddr);
3911 for (i = 0; i < NSERVERS; i++) {
3912 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3917 addrs = afs_osi_Alloc(srvAddrCount * sizeof(*addrs));
3919 for (i = 0; i < NSERVERS; i++) {
3920 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3921 if (j >= srvAddrCount)
3927 ReleaseReadLock(&afs_xsrvAddr);
3928 ReleaseReadLock(&afs_xserver);
3930 for (i = 0; i < j; i++) {
3936 /* vlserver has no callback conn */
3937 if (sa->sa_portal == AFS_VLPORT) {
3941 if (!ts->cell) /* not really an active server, anyway, it must */
3942 continue; /* have just been added by setsprefs */
3944 /* get a connection, even if host is down; bumps conn ref count */
3945 tu = afs_GetUser(areq->uid, ts->cell->cellNum, SHARED_LOCK);
3946 tc = afs_ConnBySA(sa, ts->cell->fsport, ts->cell->cellNum, tu,
3947 1 /*force */ , 1 /*create */ , SHARED_LOCK);
3948 afs_PutUser(tu, SHARED_LOCK);
3952 if ((sa->sa_flags & SRVADDR_ISDOWN) || afs_HaveCallBacksFrom(ts)) {
3953 if (sa->sa_flags & SRVADDR_ISDOWN) {
3954 rx_SetConnDeadTime(tc->id, 3);
3956 #ifdef RX_ENABLE_LOCKS
3958 #endif /* RX_ENABLE_LOCKS */
3959 code = RXAFS_CallBackRxConnAddr(tc->id, &addr);
3960 #ifdef RX_ENABLE_LOCKS
3962 #endif /* RX_ENABLE_LOCKS */
3964 afs_PutConn(tc, SHARED_LOCK); /* done with it now */
3965 } /* Outer loop over addrs */
3966 #endif /* UKERNEL */
3970 DECL_PIOCTL(PNFSNukeCreds)
3972 afs_uint32 addr, code;
3973 register afs_int32 i;
3974 register struct unixuser *tu;
3976 AFS_STATCNT(PUnlog);
3977 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3978 return EIO; /* Inappropriate ioctl for device */
3980 if (ainSize < sizeof(afs_int32))
3982 memcpy(&addr, ain, sizeof(afs_int32));
3984 if ((*acred)->cr_gid == RMTUSER_REQ_PRIV && !addr) {
3985 tu = afs_GetUser(areq->uid, -1, SHARED_LOCK);
3986 if (!tu->exporter || !(addr = EXP_GETHOST(tu->exporter))) {
3987 afs_PutUser(tu, SHARED_LOCK);
3990 afs_PutUser(tu, SHARED_LOCK);
3991 } else if (!afs_osi_suser(acred)) {
3995 ObtainWriteLock(&afs_xuser, 227);
3996 for (i = 0; i < NUSERS; i++) {
3997 for (tu = afs_users[i]; tu; tu = tu->next) {
3998 if (tu->exporter && EXP_CHECKHOST(tu->exporter, addr)) {
4000 tu->states &= ~UHasTokens;
4001 /* security is not having to say you're sorry */
4002 memset((char *)&tu->ct, 0, sizeof(struct ClearToken));
4004 ReleaseWriteLock(&afs_xuser);
4005 afs_ResetUserConns(tu);
4007 ObtainWriteLock(&afs_xuser, 228);
4009 /* set the expire times to 0, causes
4010 * afs_GCUserData to remove this entry
4012 tu->ct.EndTimestamp = 0;
4014 #endif /* UKERNEL */
4018 ReleaseWriteLock(&afs_xuser);