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);
94 DECL_PIOCTL(PNFSNukeCreds);
95 DECL_PIOCTL(PNewUuid);
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 */
199 PDiscon, /* 5 -- get/set discon mode */
206 static int (*(OpioctlSw[])) () = {
208 PNFSNukeCreds, /* 1 -- nuke all creds for NFS client */
211 #define PSetClientContext 99 /* Special pioctl to setup caller's creds */
212 int afs_nobody = NFS_NOBODY;
215 HandleIoctl(register struct vcache *avc, register afs_int32 acom,
216 struct afs_ioctl *adata)
218 register afs_int32 code;
221 AFS_STATCNT(HandleIoctl);
223 switch (acom & 0xff) {
225 avc->states |= CSafeStore;
229 /* case 2 used to be abort store, but this is no longer provided,
230 * since it is impossible to implement under normal Unix.
234 /* return the name of the cell this file is open on */
235 register struct cell *tcell;
236 register afs_int32 i;
238 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
240 i = strlen(tcell->cellName) + 1; /* bytes to copy out */
242 if (i > adata->out_size) {
243 /* 0 means we're not interested in the output */
244 if (adata->out_size != 0)
248 AFS_COPYOUT(tcell->cellName, adata->out, i, code);
250 afs_PutCell(tcell, READ_LOCK);
256 case 49: /* VIOC_GETINITPARAMS */
257 if (adata->out_size < sizeof(struct cm_initparams)) {
260 AFS_COPYOUT(&cm_initParams, adata->out,
261 sizeof(struct cm_initparams), code);
273 return code; /* so far, none implemented */
278 /* For aix we don't temporarily bypass ioctl(2) but rather do our
279 * thing directly in the vnode layer call, VNOP_IOCTL; thus afs_ioctl
280 * is now called from afs_gn_ioctl.
283 afs_ioctl(struct vcache *tvc, int cmd, int arg)
285 struct afs_ioctl data;
288 AFS_STATCNT(afs_ioctl);
289 if (((cmd >> 8) & 0xff) == 'V') {
290 /* This is a VICEIOCTL call */
291 AFS_COPYIN(arg, (caddr_t) & data, sizeof(data), error);
294 error = HandleIoctl(tvc, cmd, &data);
297 /* No-op call; just return. */
301 #endif /* AFS_AIX_ENV */
303 #if defined(AFS_SGI_ENV)
304 afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
307 , struct vopbd * vbds
311 struct afs_ioctl data;
317 AFS_STATCNT(afs_ioctl);
318 if (((cmd >> 8) & 0xff) == 'V') {
319 /* This is a VICEIOCTL call */
320 error = copyin_afs_ioctl(arg, &data);
323 locked = ISAFS_GLOCK();
326 error = HandleIoctl(tvc, cmd, &data);
331 /* No-op call; just return. */
335 #endif /* AFS_SGI_ENV */
337 /* unlike most calls here, this one uses u.u_error to return error conditions,
338 since this is really an intercepted chapter 2 call, rather than a vnode
341 /* AFS_HPUX102 and up uses VNODE ioctl instead */
342 #if !defined(AFS_HPUX102_ENV) && !defined(AFS_DARWIN80_ENV)
343 #if !defined(AFS_SGI_ENV)
347 kioctl(fdes, com, arg, ext, arg2, arg3)
348 #else /* __64BIT__ */
349 kioctl32(fdes, com, arg, ext, arg2, arg3)
350 #endif /* __64BIT__ */
353 kioctl(fdes, com, arg, ext)
364 } u_uap, *uap = &u_uap;
366 #if defined(AFS_SUN5_ENV)
368 struct afs_ioctl_sys {
375 struct afs_ioctl_sys *uap;
378 #elif defined(AFS_OSF_ENV)
379 afs_xioctl(p, args, retval)
388 } *uap = (struct a *)args;
389 #elif defined(AFS_FBSD50_ENV)
392 afs_xioctl(td, uap, retval)
394 register struct ioctl_args *uap;
397 struct proc *p = td->td_proc;
398 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
406 afs_xioctl(p, uap, retval)
408 register struct ioctl_args *uap;
411 #elif defined(AFS_LINUX22_ENV)
412 struct afs_ioctl_sys {
417 afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
420 struct afs_ioctl_sys ua, *uap = &ua;
429 } *uap = (struct a *)u.u_ap;
430 #endif /* AFS_SUN5_ENV */
432 #if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
434 #elif !defined(AFS_LINUX22_ENV)
435 register struct file *fd;
437 #if defined(AFS_XBSD_ENV)
438 register struct filedesc *fdp;
440 register struct vcache *tvc;
441 register int ioctlDone = 0, code = 0;
443 AFS_STATCNT(afs_xioctl);
444 #if defined(AFS_DARWIN_ENV)
445 if ((code = fdgetf(p, uap->fd, &fd)))
447 #elif defined(AFS_XBSD_ENV)
449 if ((u_int) uap->fd >= fdp->fd_nfiles
450 || (fd = fdp->fd_ofiles[uap->fd]) == NULL)
452 if ((fd->f_flag & (FREAD | FWRITE)) == 0)
454 #elif defined(AFS_LINUX22_ENV)
457 #elif defined(AFS_AIX32_ENV)
465 if (setuerror(getf(uap->fd, &fd))) {
468 #elif defined(AFS_OSF_ENV)
470 if (code = getf(&fd, uap->fd, FILE_FLAGS_NULL, &u.u_file_state))
472 #elif defined(AFS_SUN5_ENV)
473 # if defined(AFS_SUN57_ENV)
477 # elif defined(AFS_SUN54_ENV)
482 if (code = getf(uap->fd, &fd)) {
485 # endif /* AFS_SUN57_ENV */
491 /* first determine whether this is any sort of vnode */
492 #if defined(AFS_LINUX22_ENV)
497 if (fd->f_vnode->v_type == VREG || fd->f_vnode->v_type == VDIR) {
499 if (fd->f_type == DTYPE_VNODE) {
501 /* good, this is a vnode; next see if it is an AFS vnode */
502 #if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV)
503 tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */
504 #elif defined(AFS_OBSD_ENV)
506 IsAfsVnode((struct vnode *)fd->
507 f_data) ? VTOAFS((struct vnode *)fd->f_data) : NULL;
509 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
511 #endif /* AFS_LINUX22_ENV */
512 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
513 /* This is an AFS vnode */
514 if (((uap->com >> 8) & 0xff) == 'V') {
515 register struct afs_ioctl *datap;
518 (struct afs_ioctl *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
519 code=copyin_afs_ioctl((char *)uap->arg, datap);
521 osi_FreeSmallSpace(datap);
523 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
526 #if defined(AFS_SUN5_ENV)
541 #else /* AFS_OSF_ENV */
545 #ifdef AFS_LINUX22_ENV
555 code = HandleIoctl(tvc, uap->com, datap);
556 osi_FreeSmallSpace(datap);
570 #if defined(AFS_LINUX22_ENV)
582 code = okioctl(fdes, com, arg, ext, arg2, arg3);
583 #else /* __64BIT__ */
584 code = okioctl32(fdes, com, arg, ext, arg2, arg3);
585 #endif /* __64BIT__ */
586 #else /* !AFS_AIX51_ENV */
587 code = okioctl(fdes, com, arg, ext);
588 #endif /* AFS_AIX51_ENV */
590 #else /* !AFS_AIX41_ENV */
592 okioctl(fdes, com, arg, ext);
593 #elif defined(AFS_SUN5_ENV)
594 #if defined(AFS_SUN57_ENV)
596 #elif defined(AFS_SUN54_ENV)
601 code = ioctl(uap, rvp);
602 #elif defined(AFS_FBSD50_ENV)
603 return ioctl(td, uap);
604 #elif defined(AFS_FBSD_ENV)
605 return ioctl(p, uap);
606 #elif defined(AFS_OBSD_ENV)
607 code = sys_ioctl(p, uap, retval);
608 #elif defined(AFS_DARWIN_ENV)
609 return ioctl(p, uap, retval);
610 #elif defined(AFS_OSF_ENV)
611 code = ioctl(p, args, retval);
618 #elif !defined(AFS_LINUX22_ENV)
632 #ifdef AFS_LINUX22_ENV
635 #if defined(KERNEL_HAVE_UERROR)
638 #if defined(AFS_AIX32_ENV) && !defined(AFS_AIX41_ENV)
639 return (getuerror()? -1 : u.u_ioctlrv);
641 return getuerror()? -1 : 0;
644 #endif /* AFS_LINUX22_ENV */
645 #endif /* AFS_SUN5_ENV */
646 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
650 #endif /* AFS_SGI_ENV */
651 #endif /* AFS_HPUX102_ENV */
653 #if defined(AFS_SGI_ENV)
654 /* "pioctl" system call entry point; just pass argument to the parameterized
663 afs_pioctl(struct pioctlargs *uap, rval_t * rvp)
667 AFS_STATCNT(afs_pioctl);
669 code = afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow);
678 #elif defined(AFS_OSF_ENV)
679 afs_pioctl(p, args, retval)
689 } *uap = (struct a *)args;
691 AFS_STATCNT(afs_pioctl);
692 return (afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow));
695 #elif defined(AFS_FBSD50_ENV)
697 afs_pioctl(td, args, retval)
707 } *uap = (struct a *)args;
709 AFS_STATCNT(afs_pioctl);
710 return (afs_syscall_pioctl
711 (uap->path, uap->cmd, uap->cmarg, uap->follow, td->td_ucred));
714 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
716 afs_pioctl(p, args, retval)
726 } *uap = (struct a *)args;
728 AFS_STATCNT(afs_pioctl);
729 #ifdef AFS_DARWIN80_ENV
730 return (afs_syscall_pioctl
731 (uap->path, uap->cmd, uap->cmarg, uap->follow,
734 return (afs_syscall_pioctl
735 (uap->path, uap->cmd, uap->cmarg, uap->follow,
736 p->p_cred->pc_ucred));
742 /* macro to avoid adding any more #ifdef's to pioctl code. */
743 #if defined(AFS_LINUX22_ENV) || defined(AFS_AIX41_ENV)
744 #define PIOCTL_FREE_CRED() crfree(credp)
746 #define PIOCTL_FREE_CRED()
751 afs_syscall_pioctl(path, com, cmarg, follow, rvp, credp)
753 struct AFS_UCRED *credp;
755 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
756 afs_syscall_pioctl(path, com, cmarg, follow, credp)
757 struct AFS_UCRED *credp;
759 afs_syscall_pioctl(path, com, cmarg, follow)
767 struct afs_ioctl data;
768 #ifdef AFS_NEED_CLIENTCONTEXT
769 struct AFS_UCRED *tmpcred = NULL;
771 struct AFS_UCRED *foreigncreds = NULL;
772 register afs_int32 code = 0;
773 struct vnode *vp = NULL;
775 struct ucred *credp = crref(); /* don't free until done! */
777 #ifdef AFS_LINUX22_ENV
778 cred_t *credp = crref(); /* don't free until done! */
782 AFS_STATCNT(afs_syscall_pioctl);
784 follow = 1; /* compat. with old venus */
785 code = copyin_afs_ioctl(cmarg, &data);
788 #if defined(KERNEL_HAVE_UERROR)
793 if ((com & 0xff) == PSetClientContext) {
794 #ifdef AFS_NEED_CLIENTCONTEXT
795 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV)
796 code = HandleClientContext(&data, &com, &foreigncreds, credp);
798 code = HandleClientContext(&data, &com, &foreigncreds, osi_curcred());
802 crfree(foreigncreds);
805 #if defined(KERNEL_HAVE_UERROR)
806 return (setuerror(code), code);
811 #else /* AFS_NEED_CLIENTCONTEXT */
813 #endif /* AFS_NEED_CLIENTCONTEXT */
815 #ifdef AFS_NEED_CLIENTCONTEXT
818 * We could have done without temporary setting the u.u_cred below
819 * (foreigncreds could be passed as param the pioctl modules)
820 * but calls such as afs_osi_suser() doesn't allow that since it
821 * references u.u_cred directly. We could, of course, do something
822 * like afs_osi_suser(cred) which, I think, is better since it
823 * generalizes and supports multi cred environments...
825 #if defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
827 credp = foreigncreds;
828 #elif defined(AFS_AIX41_ENV)
829 tmpcred = crref(); /* XXX */
831 #elif defined(AFS_HPUX101_ENV)
832 tmpcred = p_cred(u.u_procp);
833 set_p_cred(u.u_procp, foreigncreds);
834 #elif defined(AFS_SGI_ENV)
835 tmpcred = OSI_GET_CURRENT_CRED();
836 OSI_SET_CURRENT_CRED(foreigncreds);
839 u.u_cred = foreigncreds;
842 #endif /* AFS_NEED_CLIENTCONTEXT */
843 if ((com & 0xff) == 15) {
844 /* special case prefetch so entire pathname eval occurs in helper process.
845 * otherwise, the pioctl call is essentially useless */
846 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
848 Prefetch(path, &data, follow,
849 foreigncreds ? foreigncreds : credp);
851 code = Prefetch(path, &data, follow, osi_curcred());
854 #if defined(KERNEL_HAVE_UERROR)
863 lookupname(path, USR, follow, NULL, &vp,
864 foreigncreds ? foreigncreds : credp);
866 #ifdef AFS_LINUX22_ENV
867 code = gop_lookupname(path, AFS_UIOUSER, follow, &dp);
869 vp = (struct vnode *)dp->d_inode;
871 code = gop_lookupname(path, AFS_UIOUSER, follow, &vp);
872 #endif /* AFS_LINUX22_ENV */
873 #endif /* AFS_AIX41_ENV */
877 #if defined(KERNEL_HAVE_UERROR)
885 #if defined(AFS_SUN510_ENV)
886 if (vp && !IsAfsVnode(vp)) {
887 struct vnode *realvp;
889 if (VOP_REALVP(vp, &realvp) == 0) {
890 struct vnode *oldvp = vp;
898 /* now make the call if we were passed no file, or were passed an AFS file */
899 if (!vp || IsAfsVnode(vp)) {
900 #if defined(AFS_SUN5_ENV)
901 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
902 #elif defined(AFS_AIX41_ENV)
904 struct ucred *cred1, *cred2;
907 cred1 = cred2 = foreigncreds;
909 cred1 = cred2 = credp;
911 code = afs_HandlePioctl(vp, com, &data, follow, &cred1);
912 if (cred1 != cred2) {
913 /* something changed the creds */
917 #elif defined(AFS_HPUX101_ENV)
919 struct ucred *cred = p_cred(u.u_procp);
920 code = afs_HandlePioctl(vp, com, &data, follow, &cred);
922 #elif defined(AFS_SGI_ENV)
925 credp = OSI_GET_CURRENT_CRED();
926 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
928 #elif defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
929 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
931 code = afs_HandlePioctl(vp, com, &data, follow, &u.u_cred);
934 #if defined(KERNEL_HAVE_UERROR)
937 code = EINVAL; /* not in /afs */
942 #if defined(AFS_NEED_CLIENTCONTEXT)
945 crset(tmpcred); /* restore original credentials */
947 #if defined(AFS_HPUX101_ENV)
948 set_p_cred(u.u_procp, tmpcred); /* restore original credentials */
949 #elif defined(AFS_SGI_ENV)
950 OSI_SET_CURRENT_CRED(tmpcred); /* restore original credentials */
951 #elif defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
952 credp = tmpcred; /* restore original credentials */
954 osi_curcred() = tmpcred; /* restore original credentials */
955 #endif /* AFS_HPUX101_ENV */
956 crfree(foreigncreds);
959 #endif /* AFS_NEED_CLIENTCONTEXT */
961 #ifdef AFS_LINUX22_ENV
964 AFS_RELE(vp); /* put vnode back */
968 #if defined(KERNEL_HAVE_UERROR)
971 return (getuerror());
977 #define MAXPIOCTLTOKENLEN \
978 (3*sizeof(afs_int32)+MAXKTCTICKETLEN+sizeof(struct ClearToken)+MAXKTCREALMLEN)
981 afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
982 register struct afs_ioctl *ablob, int afollow,
983 struct AFS_UCRED **acred)
986 struct vrequest treq;
987 register afs_int32 code;
988 register afs_int32 function, device;
989 afs_int32 inSize, outSize, outSizeMax;
990 char *inData, *outData;
991 int (*(*pioctlSw)) ();
993 struct afs_fakestat_state fakestate;
995 avc = avp ? VTOAFS(avp) : NULL;
996 afs_Trace3(afs_iclSetp, CM_TRACE_PIOCTL, ICL_TYPE_INT32, acom & 0xff,
997 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, afollow);
998 AFS_STATCNT(HandlePioctl);
999 if ((code = afs_InitReq(&treq, *acred)))
1001 afs_InitFakeStat(&fakestate);
1003 code = afs_EvalFakeStat(&avc, &fakestate, &treq);
1005 afs_PutFakeStat(&fakestate);
1009 device = (acom & 0xff00) >> 8;
1011 case 'V': /* Original pioctls */
1012 pioctlSw = VpioctlSw;
1013 pioctlSwSize = sizeof(VpioctlSw);
1015 case 'C': /* Coordinated/common pioctls */
1016 pioctlSw = CpioctlSw;
1017 pioctlSwSize = sizeof(CpioctlSw);
1019 case 'O': /* Coordinated/common pioctls */
1020 pioctlSw = OpioctlSw;
1021 pioctlSwSize = sizeof(OpioctlSw);
1024 afs_PutFakeStat(&fakestate);
1027 function = acom & 0xff;
1028 if (function >= (pioctlSwSize / sizeof(char *))) {
1029 afs_PutFakeStat(&fakestate);
1030 return EINVAL; /* out of range */
1032 inSize = ablob->in_size;
1034 /* Do all range checking before continuing */
1035 if (inSize > MAXPIOCTLTOKENLEN || inSize < 0 || ablob->out_size < 0)
1038 /* Note that we use osi_Alloc for large allocs and osi_AllocLargeSpace for small ones */
1039 if (inSize > AFS_LRALLOCSIZ) {
1040 inData = osi_Alloc(inSize + 1);
1042 inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1047 AFS_COPYIN(ablob->in, inData, inSize, code);
1048 inData[inSize] = '\0';
1052 if (inSize > AFS_LRALLOCSIZ) {
1053 osi_Free(inData, inSize + 1);
1055 osi_FreeLargeSpace(inData);
1057 afs_PutFakeStat(&fakestate);
1060 if (function == 8 && device == 'V') { /* PGetTokens */
1061 outSizeMax = MAXPIOCTLTOKENLEN;
1062 outData = osi_Alloc(outSizeMax);
1064 outSizeMax = AFS_LRALLOCSIZ;
1065 outData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1068 if (inSize > AFS_LRALLOCSIZ) {
1069 osi_Free(inData, inSize + 1);
1071 osi_FreeLargeSpace(inData);
1073 afs_PutFakeStat(&fakestate);
1078 (*pioctlSw[function]) (avc, function, &treq, inData, outData, inSize,
1080 if (inSize > AFS_LRALLOCSIZ) {
1081 osi_Free(inData, inSize + 1);
1083 osi_FreeLargeSpace(inData);
1085 if (code == 0 && ablob->out_size > 0) {
1086 if (outSize > ablob->out_size) {
1087 code = E2BIG; /* data wont fit in user buffer */
1088 } else if (outSize) {
1089 AFS_COPYOUT(outData, ablob->out, outSize, code);
1092 if (outSizeMax > AFS_LRALLOCSIZ) {
1093 osi_Free(outData, outSizeMax);
1095 osi_FreeLargeSpace(outData);
1097 afs_PutFakeStat(&fakestate);
1098 return afs_CheckCode(code, &treq, 41);
1101 DECL_PIOCTL(PGetFID)
1103 AFS_STATCNT(PGetFID);
1106 memcpy(aout, (char *)&avc->fid, sizeof(struct VenusFid));
1107 *aoutSize = sizeof(struct VenusFid);
1111 DECL_PIOCTL(PSetAcl)
1113 register afs_int32 code;
1115 struct AFSOpaque acl;
1116 struct AFSVolSync tsync;
1117 struct AFSFetchStatus OutStatus;
1120 AFS_STATCNT(PSetAcl);
1123 if ((acl.AFSOpaque_len = strlen(ain) + 1) > 1024 /* AFSOPAQUEMAX */)
1126 acl.AFSOpaque_val = ain;
1128 tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1130 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREACL);
1133 RXAFS_StoreACL(tconn->id, (struct AFSFid *)&avc->fid.Fid,
1134 &acl, &OutStatus, &tsync);
1139 } while (afs_Analyze
1140 (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_STOREACL,
1141 SHARED_LOCK, NULL));
1143 /* now we've forgotten all of the access info */
1144 ObtainWriteLock(&afs_xcbhash, 455);
1146 afs_DequeueCallback(avc);
1147 avc->states &= ~(CStatd | CUnique);
1148 ReleaseWriteLock(&afs_xcbhash);
1149 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
1150 osi_dnlc_purgedp(avc);
1154 int afs_defaultAsynchrony = 0;
1156 DECL_PIOCTL(PStoreBehind)
1159 struct sbstruct *sbr;
1161 sbr = (struct sbstruct *)ain;
1162 if (sbr->sb_default != -1) {
1163 if (afs_osi_suser(*acred))
1164 afs_defaultAsynchrony = sbr->sb_default;
1169 if (avc && (sbr->sb_thisfile != -1)) {
1171 (avc, PRSFS_WRITE | PRSFS_ADMINISTER, areq, DONT_CHECK_MODE_BITS))
1172 avc->asynchrony = sbr->sb_thisfile;
1177 *aoutSize = sizeof(struct sbstruct);
1178 sbr = (struct sbstruct *)aout;
1179 sbr->sb_default = afs_defaultAsynchrony;
1181 sbr->sb_thisfile = avc->asynchrony;
1187 DECL_PIOCTL(PGCPAGs)
1189 if (!afs_osi_suser(*acred)) {
1192 afs_gcpags = AFS_GCPAGS_USERDISABLED;
1196 DECL_PIOCTL(PGetAcl)
1198 struct AFSOpaque acl;
1199 struct AFSVolSync tsync;
1200 struct AFSFetchStatus OutStatus;
1206 AFS_STATCNT(PGetAcl);
1209 Fid.Volume = avc->fid.Fid.Volume;
1210 Fid.Vnode = avc->fid.Fid.Vnode;
1211 Fid.Unique = avc->fid.Fid.Unique;
1212 if (avc->states & CForeign) {
1214 * For a dfs xlator acl we have a special hack so that the
1215 * xlator will distinguish which type of acl will return. So
1216 * we currently use the top 2-bytes (vals 0-4) to tell which
1217 * type of acl to bring back. Horrible hack but this will
1218 * cause the least number of changes to code size and interfaces.
1220 if (Fid.Vnode & 0xc0000000)
1222 Fid.Vnode |= (ainSize << 30);
1224 acl.AFSOpaque_val = aout;
1226 tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1229 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHACL);
1231 code = RXAFS_FetchACL(tconn->id, &Fid, &acl, &OutStatus, &tsync);
1236 } while (afs_Analyze
1237 (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_FETCHACL,
1238 SHARED_LOCK, NULL));
1241 *aoutSize = (acl.AFSOpaque_len == 0 ? 1 : acl.AFSOpaque_len);
1254 AFS_STATCNT(PBogus);
1258 DECL_PIOCTL(PGetFileCell)
1260 register struct cell *tcell;
1262 AFS_STATCNT(PGetFileCell);
1265 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
1268 strcpy(aout, tcell->cellName);
1269 afs_PutCell(tcell, READ_LOCK);
1270 *aoutSize = strlen(aout) + 1;
1274 DECL_PIOCTL(PGetWSCell)
1276 struct cell *tcell = NULL;
1278 AFS_STATCNT(PGetWSCell);
1279 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1280 return EIO; /* Inappropriate ioctl for device */
1282 tcell = afs_GetPrimaryCell(READ_LOCK);
1283 if (!tcell) /* no primary cell? */
1285 strcpy(aout, tcell->cellName);
1286 *aoutSize = strlen(aout) + 1;
1287 afs_PutCell(tcell, READ_LOCK);
1291 DECL_PIOCTL(PGetUserCell)
1293 register afs_int32 i;
1294 register struct unixuser *tu;
1295 register struct cell *tcell;
1297 AFS_STATCNT(PGetUserCell);
1298 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1299 return EIO; /* Inappropriate ioctl for device */
1301 /* return the cell name of the primary cell for this user */
1302 i = UHash(areq->uid);
1303 ObtainWriteLock(&afs_xuser, 224);
1304 for (tu = afs_users[i]; tu; tu = tu->next) {
1305 if (tu->uid == areq->uid && (tu->states & UPrimary)) {
1307 ReleaseWriteLock(&afs_xuser);
1312 tcell = afs_GetCell(tu->cell, READ_LOCK);
1313 afs_PutUser(tu, WRITE_LOCK);
1317 strcpy(aout, tcell->cellName);
1318 afs_PutCell(tcell, READ_LOCK);
1319 *aoutSize = strlen(aout) + 1; /* 1 for the null */
1322 ReleaseWriteLock(&afs_xuser);
1329 DECL_PIOCTL(PSetTokens)
1332 register struct unixuser *tu;
1333 struct ClearToken clear;
1334 register struct cell *tcell;
1337 struct vrequest treq;
1338 afs_int32 flag, set_parent_pag = 0;
1340 AFS_STATCNT(PSetTokens);
1341 if (!afs_resourceinit_flag) {
1344 memcpy((char *)&i, ain, sizeof(afs_int32));
1345 ain += sizeof(afs_int32);
1346 stp = ain; /* remember where the ticket is */
1347 if (i < 0 || i > MAXKTCTICKETLEN)
1348 return EINVAL; /* malloc may fail */
1350 ain += i; /* skip over ticket */
1351 memcpy((char *)&i, ain, sizeof(afs_int32));
1352 ain += sizeof(afs_int32);
1353 if (i != sizeof(struct ClearToken)) {
1356 memcpy((char *)&clear, ain, sizeof(struct ClearToken));
1357 if (clear.AuthHandle == -1)
1358 clear.AuthHandle = 999; /* more rxvab compat stuff */
1359 ain += sizeof(struct ClearToken);
1360 if (ainSize != 2 * sizeof(afs_int32) + stLen + sizeof(struct ClearToken)) {
1361 /* still stuff left? we've got primary flag and cell name. Set these */
1362 memcpy((char *)&flag, ain, sizeof(afs_int32)); /* primary id flag */
1363 ain += sizeof(afs_int32); /* skip id field */
1364 /* rest is cell name, look it up */
1365 /* some versions of gcc appear to need != 0 in order to get this right */
1366 if ((flag & 0x8000) != 0) { /* XXX Use Constant XXX */
1370 tcell = afs_GetCellByName(ain, READ_LOCK);
1374 /* default to primary cell, primary id */
1375 flag = 1; /* primary id */
1376 tcell = afs_GetPrimaryCell(READ_LOCK);
1381 afs_PutCell(tcell, READ_LOCK);
1382 if (set_parent_pag) {
1384 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1385 #if defined(AFS_DARWIN_ENV)
1386 struct proc *p = current_proc(); /* XXX */
1388 struct proc *p = curproc; /* XXX */
1390 #ifndef AFS_DARWIN80_ENV
1391 uprintf("Process %d (%s) tried to change pags in PSetTokens\n",
1392 p->p_pid, p->p_comm);
1394 if (!setpag(p, acred, -1, &pag, 1)) {
1397 if (!setpag(u.u_procp, acred, -1, &pag, 1)) { /* XXX u.u_procp is a no-op XXX */
1399 if (!setpag(acred, -1, &pag, 1)) {
1402 afs_InitReq(&treq, *acred);
1406 /* now we just set the tokens */
1407 tu = afs_GetUser(areq->uid, i, WRITE_LOCK); /* i has the cell # */
1408 tu->vid = clear.ViceId;
1409 if (tu->stp != NULL) {
1410 afs_osi_Free(tu->stp, tu->stLen);
1412 tu->stp = (char *)afs_osi_Alloc(stLen);
1414 memcpy(tu->stp, stp, stLen);
1417 afs_stats_cmfullperf.authent.TicketUpdates++;
1418 afs_ComputePAGStats();
1419 #endif /* AFS_NOSTATS */
1420 tu->states |= UHasTokens;
1421 tu->states &= ~UTokensBad;
1422 afs_SetPrimary(tu, flag);
1423 tu->tokenTime = osi_Time();
1424 afs_ResetUserConns(tu);
1425 afs_PutUser(tu, WRITE_LOCK);
1440 DECL_PIOCTL(PGetVolumeStatus)
1443 char *offLineMsg = afs_osi_Alloc(256);
1444 char *motd = afs_osi_Alloc(256);
1445 register struct conn *tc;
1446 register afs_int32 code = 0;
1447 struct AFSFetchVolumeStatus volstat;
1449 char *Name, *OfflineMsg, *MOTD;
1452 AFS_STATCNT(PGetVolumeStatus);
1458 OfflineMsg = offLineMsg;
1461 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1463 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS);
1466 RXAFS_GetVolumeStatus(tc->id, avc->fid.Fid.Volume, &volstat,
1467 &Name, &OfflineMsg, &MOTD);
1472 } while (afs_Analyze
1473 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS,
1474 SHARED_LOCK, NULL));
1478 /* Copy all this junk into msg->im_data, keeping track of the lengths. */
1480 memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
1481 cp += sizeof(VolumeStatus);
1482 strcpy(cp, volName);
1483 cp += strlen(volName) + 1;
1484 strcpy(cp, offLineMsg);
1485 cp += strlen(offLineMsg) + 1;
1487 cp += strlen(motd) + 1;
1488 *aoutSize = (cp - aout);
1490 afs_osi_Free(offLineMsg, 256);
1491 afs_osi_Free(motd, 256);
1495 DECL_PIOCTL(PSetVolumeStatus)
1498 char *offLineMsg = afs_osi_Alloc(256);
1499 char *motd = afs_osi_Alloc(256);
1500 register struct conn *tc;
1501 register afs_int32 code = 0;
1502 struct AFSFetchVolumeStatus volstat;
1503 struct AFSStoreVolumeStatus storeStat;
1504 register struct volume *tvp;
1508 AFS_STATCNT(PSetVolumeStatus);
1514 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
1516 if (tvp->states & (VRO | VBackup)) {
1517 afs_PutVolume(tvp, READ_LOCK);
1521 afs_PutVolume(tvp, READ_LOCK);
1526 /* Copy the junk out, using cp as a roving pointer. */
1528 memcpy((char *)&volstat, cp, sizeof(AFSFetchVolumeStatus));
1529 cp += sizeof(AFSFetchVolumeStatus);
1530 if (strlen(cp) >= sizeof(volName)) {
1534 strcpy(volName, cp);
1535 cp += strlen(volName) + 1;
1536 if (strlen(cp) >= sizeof(offLineMsg)) {
1540 strcpy(offLineMsg, cp);
1541 cp += strlen(offLineMsg) + 1;
1542 if (strlen(cp) >= sizeof(motd)) {
1548 if (volstat.MinQuota != -1) {
1549 storeStat.MinQuota = volstat.MinQuota;
1550 storeStat.Mask |= AFS_SETMINQUOTA;
1552 if (volstat.MaxQuota != -1) {
1553 storeStat.MaxQuota = volstat.MaxQuota;
1554 storeStat.Mask |= AFS_SETMAXQUOTA;
1557 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1559 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS);
1562 RXAFS_SetVolumeStatus(tc->id, avc->fid.Fid.Volume, &storeStat,
1563 volName, offLineMsg, motd);
1568 } while (afs_Analyze
1569 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS,
1570 SHARED_LOCK, NULL));
1574 /* we are sending parms back to make compat. with prev system. should
1575 * change interface later to not ask for current status, just set new status */
1577 memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
1578 cp += sizeof(VolumeStatus);
1579 strcpy(cp, volName);
1580 cp += strlen(volName) + 1;
1581 strcpy(cp, offLineMsg);
1582 cp += strlen(offLineMsg) + 1;
1584 cp += strlen(motd) + 1;
1585 *aoutSize = cp - aout;
1587 afs_osi_Free(offLineMsg, 256);
1588 afs_osi_Free(motd, 256);
1594 AFS_STATCNT(PFlush);
1597 #ifdef AFS_BOZONLOCK_ENV
1598 afs_BozonLock(&avc->pvnLock, avc); /* Since afs_TryToSmush will do a pvn_vptrunc */
1600 ObtainWriteLock(&avc->lock, 225);
1601 ObtainWriteLock(&afs_xcbhash, 456);
1602 afs_DequeueCallback(avc);
1603 avc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
1604 ReleaseWriteLock(&afs_xcbhash);
1605 /* now find the disk cache entries */
1606 afs_TryToSmush(avc, *acred, 1);
1607 osi_dnlc_purgedp(avc);
1608 if (avc->linkData && !(avc->states & CCore)) {
1609 afs_osi_Free(avc->linkData, strlen(avc->linkData) + 1);
1610 avc->linkData = NULL;
1612 ReleaseWriteLock(&avc->lock);
1613 #ifdef AFS_BOZONLOCK_ENV
1614 afs_BozonUnlock(&avc->pvnLock, avc);
1619 DECL_PIOCTL(PNewStatMount)
1621 register afs_int32 code;
1622 register struct vcache *tvc;
1623 register struct dcache *tdc;
1624 struct VenusFid tfid;
1626 struct sysname_info sysState;
1627 afs_size_t offset, len;
1629 AFS_STATCNT(PNewStatMount);
1632 code = afs_VerifyVCache(avc, areq);
1635 if (vType(avc) != VDIR) {
1638 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
1641 Check_AtSys(avc, ain, &sysState, areq);
1642 ObtainReadLock(&tdc->lock);
1644 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
1645 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
1646 ReleaseReadLock(&tdc->lock);
1647 afs_PutDCache(tdc); /* we're done with the data */
1648 bufp = sysState.name;
1652 tfid.Cell = avc->fid.Cell;
1653 tfid.Fid.Volume = avc->fid.Fid.Volume;
1654 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
1655 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
1657 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
1663 if (tvc->mvstat != 1) {
1668 ObtainWriteLock(&tvc->lock, 226);
1669 code = afs_HandleLink(tvc, areq);
1671 if (tvc->linkData) {
1672 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
1675 /* we have the data */
1676 strcpy(aout, tvc->linkData);
1677 *aoutSize = strlen(tvc->linkData) + 1;
1682 ReleaseWriteLock(&tvc->lock);
1685 if (sysState.allocked)
1686 osi_FreeLargeSpace(bufp);
1690 DECL_PIOCTL(PGetTokens)
1692 register struct cell *tcell;
1693 register afs_int32 i;
1694 register struct unixuser *tu;
1699 AFS_STATCNT(PGetTokens);
1700 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1701 return EIO; /* Inappropriate ioctl for device */
1703 /* weird interface. If input parameter is present, it is an integer and
1704 * we're supposed to return the parm'th tokens for this unix uid.
1705 * If not present, we just return tokens for cell 1.
1706 * If counter out of bounds, return EDOM.
1707 * If no tokens for the particular cell, return ENOTCONN.
1708 * Also, if this mysterious parm is present, we return, along with the
1709 * tokens, the primary cell indicator (an afs_int32 0) and the cell name
1710 * at the end, in that order.
1712 if ((newStyle = (ainSize > 0))) {
1713 memcpy((char *)&iterator, ain, sizeof(afs_int32));
1715 i = UHash(areq->uid);
1716 ObtainReadLock(&afs_xuser);
1717 for (tu = afs_users[i]; tu; tu = tu->next) {
1719 if (tu->uid == areq->uid && (tu->states & UHasTokens)) {
1720 if (iterator-- == 0)
1721 break; /* are we done yet? */
1724 if (tu->uid == areq->uid && afs_IsPrimaryCellNum(tu->cell))
1730 * No need to hold a read lock on each user entry
1734 ReleaseReadLock(&afs_xuser);
1739 if (((tu->states & UHasTokens) == 0)
1740 || (tu->ct.EndTimestamp < osi_Time())) {
1741 tu->states |= (UTokensBad | UNeedsReset);
1742 afs_PutUser(tu, READ_LOCK);
1745 /* use iterator for temp */
1747 iterator = tu->stLen; /* for compat, we try to return 56 byte tix if they fit */
1749 iterator = 56; /* # of bytes we're returning */
1750 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1751 cp += sizeof(afs_int32);
1752 memcpy(cp, tu->stp, tu->stLen); /* copy out st */
1754 iterator = sizeof(struct ClearToken);
1755 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1756 cp += sizeof(afs_int32);
1757 memcpy(cp, (char *)&tu->ct, sizeof(struct ClearToken));
1758 cp += sizeof(struct ClearToken);
1760 /* put out primary id and cell name, too */
1761 iterator = (tu->states & UPrimary ? 1 : 0);
1762 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1763 cp += sizeof(afs_int32);
1764 tcell = afs_GetCell(tu->cell, READ_LOCK);
1766 strcpy(cp, tcell->cellName);
1767 cp += strlen(tcell->cellName) + 1;
1768 afs_PutCell(tcell, READ_LOCK);
1772 *aoutSize = cp - aout;
1773 afs_PutUser(tu, READ_LOCK);
1779 register afs_int32 i;
1780 register struct unixuser *tu;
1782 AFS_STATCNT(PUnlog);
1783 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1784 return EIO; /* Inappropriate ioctl for device */
1786 i = UHash(areq->uid);
1787 ObtainWriteLock(&afs_xuser, 227);
1788 for (tu = afs_users[i]; tu; tu = tu->next) {
1789 if (tu->uid == areq->uid) {
1791 tu->states &= ~UHasTokens;
1792 /* security is not having to say you're sorry */
1793 memset((char *)&tu->ct, 0, sizeof(struct ClearToken));
1795 ReleaseWriteLock(&afs_xuser);
1796 /* We have to drop the lock over the call to afs_ResetUserConns, since
1797 * it obtains the afs_xvcache lock. We could also keep the lock, and
1798 * modify ResetUserConns to take parm saying we obtained the lock
1799 * already, but that is overkill. By keeping the "tu" pointer
1800 * held over the released lock, we guarantee that we won't lose our
1801 * place, and that we'll pass over every user conn that existed when
1802 * we began this call.
1804 afs_ResetUserConns(tu);
1806 ObtainWriteLock(&afs_xuser, 228);
1808 /* set the expire times to 0, causes
1809 * afs_GCUserData to remove this entry
1811 tu->ct.EndTimestamp = 0;
1813 #endif /* UKERNEL */
1816 ReleaseWriteLock(&afs_xuser);
1820 DECL_PIOCTL(PMariner)
1822 afs_int32 newHostAddr;
1823 afs_int32 oldHostAddr;
1825 AFS_STATCNT(PMariner);
1827 memcpy((char *)&oldHostAddr, (char *)&afs_marinerHost,
1830 oldHostAddr = 0xffffffff; /* disabled */
1832 memcpy((char *)&newHostAddr, ain, sizeof(afs_int32));
1833 if (newHostAddr == 0xffffffff) {
1834 /* disable mariner operations */
1836 } else if (newHostAddr) {
1838 afs_marinerHost = newHostAddr;
1840 memcpy(aout, (char *)&oldHostAddr, sizeof(afs_int32));
1841 *aoutSize = sizeof(afs_int32);
1845 DECL_PIOCTL(PCheckServers)
1847 register char *cp = 0;
1849 register struct server *ts;
1850 afs_int32 temp, *lp = (afs_int32 *) ain, havecell = 0;
1852 struct chservinfo *pcheck;
1854 AFS_STATCNT(PCheckServers);
1856 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1857 return EIO; /* Inappropriate ioctl for device */
1859 if (*lp == 0x12345678) { /* For afs3.3 version */
1860 pcheck = (struct chservinfo *)ain;
1861 if (pcheck->tinterval >= 0) {
1863 memcpy(cp, (char *)&afs_probe_interval, sizeof(afs_int32));
1864 *aoutSize = sizeof(afs_int32);
1865 if (pcheck->tinterval > 0) {
1866 if (!afs_osi_suser(*acred))
1868 afs_probe_interval = pcheck->tinterval;
1874 temp = pcheck->tflags;
1875 cp = pcheck->tbuffer;
1876 } else { /* For pre afs3.3 versions */
1877 memcpy((char *)&temp, ain, sizeof(afs_int32));
1878 cp = ain + sizeof(afs_int32);
1879 if (ainSize > sizeof(afs_int32))
1884 * 1: fast check, don't contact servers.
1885 * 2: local cell only.
1888 /* have cell name, too */
1889 cellp = afs_GetCellByName(cp, READ_LOCK);
1894 if (!cellp && (temp & 2)) {
1895 /* use local cell */
1896 cellp = afs_GetPrimaryCell(READ_LOCK);
1898 if (!(temp & 1)) { /* if not fast, call server checker routine */
1899 afs_CheckServers(1, cellp); /* check down servers */
1900 afs_CheckServers(0, cellp); /* check up servers */
1902 /* now return the current down server list */
1904 ObtainReadLock(&afs_xserver);
1905 for (i = 0; i < NSERVERS; i++) {
1906 for (ts = afs_servers[i]; ts; ts = ts->next) {
1907 if (cellp && ts->cell != cellp)
1908 continue; /* cell spec'd and wrong */
1909 if ((ts->flags & SRVR_ISDOWN)
1910 && ts->addr->sa_portal != ts->cell->vlport) {
1911 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
1912 cp += sizeof(afs_int32);
1916 ReleaseReadLock(&afs_xserver);
1918 afs_PutCell(cellp, READ_LOCK);
1919 *aoutSize = cp - aout;
1923 DECL_PIOCTL(PCheckVolNames)
1925 AFS_STATCNT(PCheckVolNames);
1926 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1927 return EIO; /* Inappropriate ioctl for device */
1929 afs_CheckRootVolume();
1930 afs_CheckVolumeNames(AFS_VOLCHECK_FORCE | AFS_VOLCHECK_EXPIRED |
1931 AFS_VOLCHECK_BUSY | AFS_VOLCHECK_MTPTS);
1935 DECL_PIOCTL(PCheckAuth)
1940 struct unixuser *tu;
1943 AFS_STATCNT(PCheckAuth);
1944 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1945 return EIO; /* Inappropriate ioctl for device */
1948 tu = afs_GetUser(areq->uid, 1, READ_LOCK); /* check local cell authentication */
1952 /* we have a user */
1953 ObtainReadLock(&afs_xsrvAddr);
1954 ObtainReadLock(&afs_xconn);
1956 /* any tokens set? */
1957 if ((tu->states & UHasTokens) == 0)
1959 /* all connections in cell 1 working? */
1960 for (i = 0; i < NSERVERS; i++) {
1961 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
1962 for (tc = sa->conns; tc; tc = tc->next) {
1963 if (tc->user == tu && (tu->states & UTokensBad))
1968 ReleaseReadLock(&afs_xsrvAddr);
1969 ReleaseReadLock(&afs_xconn);
1970 afs_PutUser(tu, READ_LOCK);
1972 memcpy(aout, (char *)&retValue, sizeof(afs_int32));
1973 *aoutSize = sizeof(afs_int32);
1978 Prefetch(char *apath, struct afs_ioctl *adata, int afollow,
1979 struct AFS_UCRED *acred)
1982 register afs_int32 code;
1983 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1989 AFS_STATCNT(Prefetch);
1992 tp = osi_AllocLargeSpace(1024);
1993 AFS_COPYINSTR(apath, tp, 1024, &bufferSize, code);
1995 osi_FreeLargeSpace(tp);
1998 if (afs_BBusy()) { /* do this as late as possible */
1999 osi_FreeLargeSpace(tp);
2000 return EWOULDBLOCK; /* pretty close */
2002 afs_BQueue(BOP_PATH, (struct vcache *)0, 0, 0, acred, (afs_size_t) 0,
2003 (afs_size_t) 0, tp);
2007 DECL_PIOCTL(PFindVolume)
2009 register struct volume *tvp;
2010 register struct server *ts;
2011 register afs_int32 i;
2014 AFS_STATCNT(PFindVolume);
2017 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
2020 for (i = 0; i < MAXHOSTS; i++) {
2021 ts = tvp->serverHost[i];
2024 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
2025 cp += sizeof(afs_int32);
2028 /* still room for terminating NULL, add it on */
2029 ainSize = 0; /* reuse vbl */
2030 memcpy(cp, (char *)&ainSize, sizeof(afs_int32));
2031 cp += sizeof(afs_int32);
2033 *aoutSize = cp - aout;
2034 afs_PutVolume(tvp, READ_LOCK);
2040 DECL_PIOCTL(PViceAccess)
2042 register afs_int32 code;
2045 AFS_STATCNT(PViceAccess);
2048 code = afs_VerifyVCache(avc, areq);
2051 memcpy((char *)&temp, ain, sizeof(afs_int32));
2052 code = afs_AccessOK(avc, temp, areq, CHECK_MODE_BITS);
2059 DECL_PIOCTL(PSetCacheSize)
2064 AFS_STATCNT(PSetCacheSize);
2065 if (!afs_osi_suser(*acred))
2067 /* too many things are setup initially in mem cache version */
2068 if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
2070 memcpy((char *)&newValue, ain, sizeof(afs_int32));
2072 afs_cacheBlocks = afs_stats_cmperf.cacheBlocksOrig;
2074 if (newValue < afs_min_cache)
2075 afs_cacheBlocks = afs_min_cache;
2077 afs_cacheBlocks = newValue;
2079 afs_stats_cmperf.cacheBlocksTotal = afs_cacheBlocks;
2080 afs_ComputeCacheParms(); /* recompute basic cache parameters */
2081 afs_MaybeWakeupTruncateDaemon();
2082 while (waitcnt++ < 100 && afs_cacheBlocks < afs_blocksUsed) {
2083 afs_osi_Wait(1000, 0, 0);
2084 afs_MaybeWakeupTruncateDaemon();
2089 #define MAXGCSTATS 16
2090 DECL_PIOCTL(PGetCacheSize)
2092 afs_int32 results[MAXGCSTATS];
2094 register struct dcache * tdc;
2097 AFS_STATCNT(PGetCacheSize);
2099 if (sizeof(afs_int32) == ainSize){
2100 memcpy((char *)&flags, ain, sizeof(afs_int32));
2101 } else if (0 == ainSize){
2107 memset((char *)results, 0, sizeof(results));
2108 results[0] = afs_cacheBlocks;
2109 results[1] = afs_blocksUsed;
2110 results[2] = afs_cacheFiles;
2113 for (i = 0; i < afs_cacheFiles; i++) {
2114 if (afs_indexFlags[i] & IFFree) results[3]++;
2116 } else if (2 == flags){
2117 for (i = 0; i < afs_cacheFiles; i++) {
2118 if (afs_indexFlags[i] & IFFree) results[3]++;
2119 if (afs_indexFlags[i] & IFEverUsed) results[4]++;
2120 if (afs_indexFlags[i] & IFDataMod) results[5]++;
2121 if (afs_indexFlags[i] & IFDirtyPages) results[6]++;
2122 if (afs_indexFlags[i] & IFAnyPages) results[7]++;
2123 if (afs_indexFlags[i] & IFDiscarded) results[8]++;
2125 tdc = afs_indexTable[i];
2128 size = tdc->validPos;
2129 if ( 0 < size && size < (1<<12) ) results[10]++;
2130 else if (size < (1<<14) ) results[11]++;
2131 else if (size < (1<<16) ) results[12]++;
2132 else if (size < (1<<18) ) results[13]++;
2133 else if (size < (1<<20) ) results[14]++;
2134 else if (size >= (1<<20) ) results[15]++;
2138 memcpy(aout, (char *)results, sizeof(results));
2139 *aoutSize = sizeof(results);
2143 DECL_PIOCTL(PRemoveCallBack)
2145 register struct conn *tc;
2146 register afs_int32 code = 0;
2147 struct AFSCallBack CallBacks_Array[1];
2148 struct AFSCBFids theFids;
2149 struct AFSCBs theCBs;
2152 AFS_STATCNT(PRemoveCallBack);
2155 if (avc->states & CRO)
2156 return 0; /* read-only-ness can't change */
2157 ObtainWriteLock(&avc->lock, 229);
2158 theFids.AFSCBFids_len = 1;
2159 theCBs.AFSCBs_len = 1;
2160 theFids.AFSCBFids_val = (struct AFSFid *)&avc->fid.Fid;
2161 theCBs.AFSCBs_val = CallBacks_Array;
2162 CallBacks_Array[0].CallBackType = CB_DROPPED;
2163 if (avc->callback) {
2165 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2167 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
2169 code = RXAFS_GiveUpCallBacks(tc->id, &theFids, &theCBs);
2173 /* don't set code on failure since we wouldn't use it */
2174 } while (afs_Analyze
2175 (tc, code, &avc->fid, areq,
2176 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK, NULL));
2178 ObtainWriteLock(&afs_xcbhash, 457);
2179 afs_DequeueCallback(avc);
2181 avc->states &= ~(CStatd | CUnique);
2182 ReleaseWriteLock(&afs_xcbhash);
2183 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
2184 osi_dnlc_purgedp(avc);
2186 ReleaseWriteLock(&avc->lock);
2190 DECL_PIOCTL(PNewCell)
2192 /* create a new cell */
2193 afs_int32 cellHosts[MAXCELLHOSTS], *lp, magic = 0;
2194 char *newcell = 0, *linkedcell = 0, *tp = ain;
2195 register afs_int32 code, linkedstate = 0, ls;
2196 u_short fsport = 0, vlport = 0;
2199 AFS_STATCNT(PNewCell);
2200 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2201 return EIO; /* Inappropriate ioctl for device */
2203 if (!afs_osi_suser(*acred))
2206 memcpy((char *)&magic, tp, sizeof(afs_int32));
2207 tp += sizeof(afs_int32);
2208 if (magic != 0x12345678)
2211 /* A 3.4 fs newcell command will pass an array of MAXCELLHOSTS
2212 * server addresses while the 3.5 fs newcell command passes
2213 * MAXHOSTS. To figure out which is which, check if the cellname
2216 newcell = tp + (MAXCELLHOSTS + 3) * sizeof(afs_int32);
2217 scount = ((newcell[0] != '\0') ? MAXCELLHOSTS : MAXHOSTS);
2219 /* MAXCELLHOSTS (=8) is less than MAXHOSTS (=13) */
2220 memcpy((char *)cellHosts, tp, MAXCELLHOSTS * sizeof(afs_int32));
2221 tp += (scount * sizeof(afs_int32));
2223 lp = (afs_int32 *) tp;
2227 fsport = 0; /* Privileged ports not allowed */
2229 vlport = 0; /* Privileged ports not allowed */
2230 tp += (3 * sizeof(afs_int32));
2232 if ((ls = *lp) & 1) {
2233 linkedcell = tp + strlen(newcell) + 1;
2234 linkedstate |= CLinkedCell;
2237 linkedstate |= CNoSUID; /* setuid is disabled by default for fs newcell */
2239 afs_NewCell(newcell, cellHosts, linkedstate, linkedcell, fsport,
2244 DECL_PIOCTL(PNewAlias)
2246 /* create a new cell alias */
2248 register afs_int32 code;
2249 char *realName, *aliasName;
2251 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2252 return EIO; /* Inappropriate ioctl for device */
2254 if (!afs_osi_suser(*acred))
2258 tp += strlen(aliasName) + 1;
2261 code = afs_NewCellAlias(aliasName, realName);
2266 DECL_PIOCTL(PListCells)
2268 afs_int32 whichCell;
2269 register struct cell *tcell = 0;
2270 register afs_int32 i;
2271 register char *cp, *tp = ain;
2273 AFS_STATCNT(PListCells);
2274 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2275 return EIO; /* Inappropriate ioctl for device */
2277 memcpy((char *)&whichCell, tp, sizeof(afs_int32));
2278 tp += sizeof(afs_int32);
2279 tcell = afs_GetCellByIndex(whichCell, READ_LOCK);
2282 memset(cp, 0, MAXCELLHOSTS * sizeof(afs_int32));
2283 for (i = 0; i < MAXCELLHOSTS; i++) {
2284 if (tcell->cellHosts[i] == 0)
2286 memcpy(cp, (char *)&tcell->cellHosts[i]->addr->sa_ip,
2288 cp += sizeof(afs_int32);
2290 cp = aout + MAXCELLHOSTS * sizeof(afs_int32);
2291 strcpy(cp, tcell->cellName);
2292 cp += strlen(tcell->cellName) + 1;
2293 *aoutSize = cp - aout;
2294 afs_PutCell(tcell, READ_LOCK);
2302 DECL_PIOCTL(PListAliases)
2304 afs_int32 whichAlias;
2305 register struct cell_alias *tcalias = 0;
2306 register char *cp, *tp = ain;
2308 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2309 return EIO; /* Inappropriate ioctl for device */
2310 if (ainSize < sizeof(afs_int32))
2313 memcpy((char *)&whichAlias, tp, sizeof(afs_int32));
2314 tp += sizeof(afs_int32);
2316 tcalias = afs_GetCellAlias(whichAlias);
2319 strcpy(cp, tcalias->alias);
2320 cp += strlen(tcalias->alias) + 1;
2321 strcpy(cp, tcalias->cell);
2322 cp += strlen(tcalias->cell) + 1;
2323 *aoutSize = cp - aout;
2324 afs_PutCellAlias(tcalias);
2332 DECL_PIOCTL(PRemoveMount)
2334 register afs_int32 code;
2336 struct sysname_info sysState;
2337 afs_size_t offset, len;
2338 register struct conn *tc;
2339 register struct dcache *tdc;
2340 register struct vcache *tvc;
2341 struct AFSFetchStatus OutDirStatus;
2342 struct VenusFid tfid;
2343 struct AFSVolSync tsync;
2347 /* "ain" is the name of the file in this dir to remove */
2349 AFS_STATCNT(PRemoveMount);
2352 code = afs_VerifyVCache(avc, areq);
2355 if (vType(avc) != VDIR)
2358 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1); /* test for error below */
2361 Check_AtSys(avc, ain, &sysState, areq);
2362 ObtainReadLock(&tdc->lock);
2364 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
2365 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
2366 ReleaseReadLock(&tdc->lock);
2367 bufp = sysState.name;
2372 tfid.Cell = avc->fid.Cell;
2373 tfid.Fid.Volume = avc->fid.Fid.Volume;
2374 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
2375 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
2377 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
2384 if (tvc->mvstat != 1) {
2390 ObtainWriteLock(&tvc->lock, 230);
2391 code = afs_HandleLink(tvc, areq);
2393 if (tvc->linkData) {
2394 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
2399 ReleaseWriteLock(&tvc->lock);
2400 osi_dnlc_purgedp(tvc);
2406 ObtainWriteLock(&avc->lock, 231);
2407 osi_dnlc_remove(avc, bufp, tvc);
2409 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2411 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE);
2414 RXAFS_RemoveFile(tc->id, (struct AFSFid *)&avc->fid.Fid, bufp,
2415 &OutDirStatus, &tsync);
2420 } while (afs_Analyze
2421 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_REMOVEFILE,
2422 SHARED_LOCK, NULL));
2427 ReleaseWriteLock(&avc->lock);
2431 /* we have the thing in the cache */
2432 ObtainWriteLock(&tdc->lock, 661);
2433 if (afs_LocalHero(avc, tdc, &OutDirStatus, 1)) {
2434 /* we can do it locally */
2435 code = afs_dir_Delete(tdc, bufp);
2437 ZapDCE(tdc); /* surprise error -- invalid value */
2441 ReleaseWriteLock(&tdc->lock);
2442 afs_PutDCache(tdc); /* drop ref count */
2444 avc->states &= ~CUnique; /* For the dfs xlator */
2445 ReleaseWriteLock(&avc->lock);
2448 if (sysState.allocked)
2449 osi_FreeLargeSpace(bufp);
2453 DECL_PIOCTL(PVenusLogging)
2455 return EINVAL; /* OBSOLETE */
2458 DECL_PIOCTL(PGetCellStatus)
2460 register struct cell *tcell;
2463 AFS_STATCNT(PGetCellStatus);
2464 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2465 return EIO; /* Inappropriate ioctl for device */
2467 tcell = afs_GetCellByName(ain, READ_LOCK);
2470 temp = tcell->states;
2471 afs_PutCell(tcell, READ_LOCK);
2472 memcpy(aout, (char *)&temp, sizeof(afs_int32));
2473 *aoutSize = sizeof(afs_int32);
2477 DECL_PIOCTL(PSetCellStatus)
2479 register struct cell *tcell;
2482 if (!afs_osi_suser(*acred))
2484 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2485 return EIO; /* Inappropriate ioctl for device */
2487 tcell = afs_GetCellByName(ain + 2 * sizeof(afs_int32), WRITE_LOCK);
2490 memcpy((char *)&temp, ain, sizeof(afs_int32));
2492 tcell->states |= CNoSUID;
2494 tcell->states &= ~CNoSUID;
2495 afs_PutCell(tcell, WRITE_LOCK);
2499 DECL_PIOCTL(PFlushVolumeData)
2501 register afs_int32 i;
2502 register struct dcache *tdc;
2503 register struct vcache *tvc;
2504 register struct volume *tv;
2505 afs_int32 cell, volume;
2506 struct afs_q *tq, *uq;
2507 #ifdef AFS_DARWIN80_ENV
2511 AFS_STATCNT(PFlushVolumeData);
2514 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2515 return EIO; /* Inappropriate ioctl for device */
2517 volume = avc->fid.Fid.Volume; /* who to zap */
2518 cell = avc->fid.Cell;
2521 * Clear stat'd flag from all vnodes from this volume; this will invalidate all
2522 * the vcaches associated with the volume.
2525 ObtainReadLock(&afs_xvcache);
2526 i = VCHashV(&avc->fid);
2527 for (tq = afs_vhashTV[i].prev; tq != &afs_vhashTV[i]; tq = uq) {
2530 if (tvc->fid.Fid.Volume == volume && tvc->fid.Cell == cell) {
2531 if (tvc->states & CVInit) {
2532 ReleaseReadLock(&afs_xvcache);
2533 afs_osi_Sleep(&tvc->states);
2536 #ifdef AFS_DARWIN80_ENV
2537 if (tvc->states & CDeadVnode) {
2538 ReleaseReadLock(&afs_xvcache);
2539 afs_osi_Sleep(&tvc->states);
2543 #if defined(AFS_SGI_ENV) || defined(AFS_OSF_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
2544 VN_HOLD(AFSTOV(tvc));
2546 #ifdef AFS_DARWIN80_ENV
2550 if (vnode_ref(vp)) {
2557 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2560 VREFCOUNT_INC(tvc); /* AIX, apparently */
2564 ReleaseReadLock(&afs_xvcache);
2565 #ifdef AFS_BOZONLOCK_ENV
2566 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
2568 ObtainWriteLock(&tvc->lock, 232);
2570 ObtainWriteLock(&afs_xcbhash, 458);
2571 afs_DequeueCallback(tvc);
2572 tvc->states &= ~(CStatd | CDirty);
2573 ReleaseWriteLock(&afs_xcbhash);
2574 if (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
2575 osi_dnlc_purgedp(tvc);
2576 afs_TryToSmush(tvc, *acred, 1);
2577 ReleaseWriteLock(&tvc->lock);
2578 #ifdef AFS_BOZONLOCK_ENV
2579 afs_BozonUnlock(&tvc->pvnLock, tvc);
2581 #ifdef AFS_DARWIN80_ENV
2582 vnode_put(AFSTOV(tvc));
2584 ObtainReadLock(&afs_xvcache);
2586 /* our tvc ptr is still good until now */
2590 ReleaseReadLock(&afs_xvcache);
2593 MObtainWriteLock(&afs_xdcache, 328); /* needed if you're going to flush any stuff */
2594 for (i = 0; i < afs_cacheFiles; i++) {
2595 if (!(afs_indexFlags[i] & IFEverUsed))
2596 continue; /* never had any data */
2597 tdc = afs_GetDSlot(i, NULL);
2598 if (tdc->refCount <= 1) { /* too high, in use by running sys call */
2599 ReleaseReadLock(&tdc->tlock);
2600 if (tdc->f.fid.Fid.Volume == volume && tdc->f.fid.Cell == cell) {
2601 if (!(afs_indexFlags[i] & IFDataMod)) {
2602 /* if the file is modified, but has a ref cnt of only 1, then
2603 * someone probably has the file open and is writing into it.
2604 * Better to skip flushing such a file, it will be brought back
2605 * immediately on the next write anyway.
2607 * If we *must* flush, then this code has to be rearranged to call
2608 * afs_storeAllSegments() first */
2609 afs_FlushDCache(tdc);
2613 ReleaseReadLock(&tdc->tlock);
2615 afs_PutDCache(tdc); /* bumped by getdslot */
2617 MReleaseWriteLock(&afs_xdcache);
2619 ObtainReadLock(&afs_xvolume);
2620 for (i = 0; i < NVOLS; i++) {
2621 for (tv = afs_volumes[i]; tv; tv = tv->next) {
2622 if (tv->volume == volume) {
2623 afs_ResetVolumeInfo(tv);
2628 ReleaseReadLock(&afs_xvolume);
2630 /* probably, a user is doing this, probably, because things are screwed up.
2631 * maybe it's the dnlc's fault? */
2638 DECL_PIOCTL(PGetVnodeXStatus)
2640 register afs_int32 code;
2641 struct vcxstat stat;
2644 /* AFS_STATCNT(PGetVnodeXStatus); */
2647 code = afs_VerifyVCache(avc, areq);
2650 if (vType(avc) == VDIR)
2651 mode = PRSFS_LOOKUP;
2654 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
2657 memset(&stat, 0, sizeof(struct vcxstat));
2658 stat.fid = avc->fid;
2659 hset32(stat.DataVersion, hgetlo(avc->m.DataVersion));
2660 stat.lock = avc->lock;
2661 stat.parentVnode = avc->parentVnode;
2662 stat.parentUnique = avc->parentUnique;
2663 hset(stat.flushDV, avc->flushDV);
2664 hset(stat.mapDV, avc->mapDV);
2665 stat.truncPos = avc->truncPos;
2666 { /* just grab the first two - won't break anything... */
2667 struct axscache *ac;
2669 for (i = 0, ac = avc->Access; ac && i < CPSIZE; i++, ac = ac->next) {
2670 stat.randomUid[i] = ac->uid;
2671 stat.randomAccess[i] = ac->axess;
2674 stat.callback = afs_data_pointer_to_int32(avc->callback);
2675 stat.cbExpires = avc->cbExpires;
2676 stat.anyAccess = avc->anyAccess;
2677 stat.opens = avc->opens;
2678 stat.execsOrWriters = avc->execsOrWriters;
2679 stat.flockCount = avc->flockCount;
2680 stat.mvstat = avc->mvstat;
2681 stat.states = avc->states;
2682 memcpy(aout, (char *)&stat, sizeof(struct vcxstat));
2683 *aoutSize = sizeof(struct vcxstat);
2688 DECL_PIOCTL(PGetVnodeXStatus2)
2690 register afs_int32 code;
2691 struct vcxstat2 stat;
2696 code = afs_VerifyVCache(avc, areq);
2699 if (vType(avc) == VDIR)
2700 mode = PRSFS_LOOKUP;
2703 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
2706 memset(&stat, 0, sizeof(struct vcxstat2));
2708 stat.cbExpires = avc->cbExpires;
2709 stat.anyAccess = avc->anyAccess;
2710 stat.mvstat = avc->mvstat;
2711 stat.callerAccess = afs_GetAccessBits(avc, ~0, areq);
2713 memcpy(aout, (char *)&stat, sizeof(struct vcxstat2));
2714 *aoutSize = sizeof(struct vcxstat2);
2718 /* We require root for local sysname changes, but not for remote */
2719 /* (since we don't really believe remote uids anyway) */
2720 /* outname[] shouldn't really be needed- this is left as an excercise */
2721 /* for the reader. */
2722 DECL_PIOCTL(PSetSysName)
2724 char *cp, *cp2 = NULL, inname[MAXSYSNAME], outname[MAXSYSNAME];
2725 afs_int32 setsysname;
2727 register struct afs_exporter *exporter;
2728 register struct unixuser *au;
2729 register afs_int32 pag, error;
2730 int t, count, num = 0, allpags = 0;
2733 AFS_STATCNT(PSetSysName);
2734 if (!afs_globalVFS) {
2735 /* Afsd is NOT running; disable it */
2736 #if defined(KERNEL_HAVE_UERROR)
2737 return (setuerror(EINVAL), EINVAL);
2742 memset(inname, 0, MAXSYSNAME);
2743 memcpy(&setsysname, ain, sizeof(afs_int32));
2744 ain += sizeof(afs_int32);
2745 if (setsysname & 0x8000) {
2747 setsysname &= ~0x8000;
2752 if (setsysname < 0 || setsysname > MAXNUMSYSNAMES)
2755 for (cp = ain, count = 0; count < setsysname; count++) {
2756 /* won't go past end of ain since maxsysname*num < ain length */
2758 if (t >= MAXSYSNAME || t <= 0)
2760 /* check for names that can shoot us in the foot */
2761 if (*cp == '.' && (cp[1] == 0 || (cp[1] == '.' && cp[2] == 0)))
2767 /* inname gets first entry in case we're being a translator */
2769 memcpy(inname, ain, t + 1); /* include terminating null */
2773 if ((*acred)->cr_gid == RMTUSER_REQ ||
2774 (*acred)->cr_gid == RMTUSER_REQ_PRIV) { /* Handles all exporters */
2775 if (allpags && (*acred)->cr_gid != RMTUSER_REQ_PRIV) {
2778 pag = PagInCred(*acred);
2780 return EINVAL; /* Better than panicing */
2782 if (!(au = afs_FindUser(pag, -1, READ_LOCK))) {
2783 return EINVAL; /* Better than panicing */
2785 if (!(exporter = au->exporter)) {
2786 afs_PutUser(au, READ_LOCK);
2787 return EINVAL; /* Better than panicing */
2789 error = EXP_SYSNAME(exporter, (setsysname ? cp2 : NULL), &sysnamelist,
2792 if (error == ENODEV)
2793 foundname = 0; /* sysname not set yet! */
2795 afs_PutUser(au, READ_LOCK);
2800 strcpy(outname, sysnamelist[0]);
2802 afs_PutUser(au, READ_LOCK);
2806 /* Not xlating, so local case */
2808 osi_Panic("PSetSysName: !afs_sysname\n");
2809 if (!setsysname) { /* user just wants the info */
2810 strcpy(outname, afs_sysname);
2811 foundname = afs_sysnamecount;
2812 sysnamelist = afs_sysnamelist;
2813 } else { /* Local guy; only root can change sysname */
2814 if (!afs_osi_suser(*acred))
2817 /* allpags makes no sense for local use */
2821 /* clear @sys entries from the dnlc, once afs_lookup can
2822 * do lookups of @sys entries and thinks it can trust them */
2823 /* privs ok, store the entry, ... */
2824 strcpy(afs_sysname, inname);
2825 if (setsysname > 1) { /* ... or list */
2827 for (count = 1; count < setsysname; ++count) {
2828 if (!afs_sysnamelist[count])
2830 ("PSetSysName: no afs_sysnamelist entry to write\n");
2832 memcpy(afs_sysnamelist[count], cp, t + 1); /* include null */
2836 afs_sysnamecount = setsysname;
2841 cp = aout; /* not changing so report back the count and ... */
2842 memcpy(cp, (char *)&foundname, sizeof(afs_int32));
2843 cp += sizeof(afs_int32);
2845 strcpy(cp, outname); /* ... the entry, ... */
2846 cp += strlen(outname) + 1;
2847 for (count = 1; count < foundname; ++count) { /* ... or list. */
2848 if (!sysnamelist[count])
2850 ("PSetSysName: no afs_sysnamelist entry to read\n");
2851 t = strlen(sysnamelist[count]);
2852 if (t >= MAXSYSNAME)
2853 osi_Panic("PSetSysName: sysname entry garbled\n");
2854 strcpy(cp, sysnamelist[count]);
2858 *aoutSize = cp - aout;
2863 /* sequential search through the list of touched cells is not a good
2864 * long-term solution here. For small n, though, it should be just
2865 * fine. Should consider special-casing the local cell for large n.
2866 * Likewise for PSetSPrefs.
2868 * s - number of ids in array l[] -- NOT index of last id
2869 * l - array of cell ids which have volumes that need to be sorted
2870 * vlonly - sort vl servers or file servers?
2873 ReSortCells_cb(struct cell *cell, void *arg)
2875 afs_int32 *p = (afs_int32 *) arg;
2876 afs_int32 *l = p + 1;
2879 for (i = 0; i < s; i++) {
2880 if (l[i] == cell->cellNum) {
2881 ObtainWriteLock(&cell->lock, 690);
2882 afs_SortServers(cell->cellHosts, MAXCELLHOSTS);
2883 ReleaseWriteLock(&cell->lock);
2891 ReSortCells(int s, afs_int32 * l, int vlonly)
2899 p = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * (s + 1));
2901 memcpy(p + 1, l, s * sizeof(afs_int32));
2902 afs_TraverseCells(&ReSortCells_cb, p);
2903 afs_osi_Free(p, sizeof(afs_int32) * (s + 1));
2907 ObtainReadLock(&afs_xvolume);
2908 for (i = 0; i < NVOLS; i++) {
2909 for (j = afs_volumes[i]; j; j = j->next) {
2910 for (k = 0; k < s; k++)
2911 if (j->cell == l[k]) {
2912 ObtainWriteLock(&j->lock, 233);
2913 afs_SortServers(j->serverHost, MAXHOSTS);
2914 ReleaseWriteLock(&j->lock);
2919 ReleaseReadLock(&afs_xvolume);
2923 static int debugsetsp = 0;
2925 afs_setsprefs(sp, num, vlonly)
2928 unsigned int vlonly;
2931 int i, j, k, matches, touchedSize;
2932 struct server *srvr = NULL;
2933 afs_int32 touched[34];
2937 for (k = 0; k < num; sp++, k++) {
2939 printf("sp host=%x, rank=%d\n", sp->host.s_addr, sp->rank);
2942 ObtainReadLock(&afs_xserver);
2944 i = SHash(sp->host.s_addr);
2945 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2946 if (sa->sa_ip == sp->host.s_addr) {
2948 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
2949 || (sa->sa_portal == AFS_FSPORT);
2950 if ((!vlonly && isfs) || (vlonly && !isfs)) {
2957 if (sa && matches) { /* found one! */
2959 printf("sa ip=%x, ip_rank=%d\n", sa->sa_ip, sa->sa_iprank);
2961 sa->sa_iprank = sp->rank + afs_randomMod15();
2962 afs_SortOneServer(sa->server);
2965 /* if we don't know yet what cell it's in, this is moot */
2966 for (j = touchedSize - 1;
2967 j >= 0 && touched[j] != srvr->cell->cellNum; j--)
2968 /* is it in our list of touched cells ? */ ;
2969 if (j < 0) { /* no, it's not */
2970 touched[touchedSize++] = srvr->cell->cellNum;
2971 if (touchedSize >= 32) { /* watch for ovrflow */
2972 ReleaseReadLock(&afs_xserver);
2973 ReSortCells(touchedSize, touched, vlonly);
2975 ObtainReadLock(&afs_xserver);
2981 ReleaseReadLock(&afs_xserver);
2982 /* if we didn't find one, start to create one. */
2983 /* Note that it doesn't have a cell yet... */
2985 afs_uint32 temp = sp->host.s_addr;
2987 afs_GetServer(&temp, 1, 0, (vlonly ? AFS_VLPORT : AFS_FSPORT),
2988 WRITE_LOCK, (afsUUID *) 0, 0);
2989 srvr->addr->sa_iprank = sp->rank + afs_randomMod15();
2990 afs_PutServer(srvr, WRITE_LOCK);
2992 } /* for all cited preferences */
2994 ReSortCells(touchedSize, touched, vlonly);
2998 /* Note that this may only be performed by the local root user.
3000 DECL_PIOCTL(PSetSPrefs)
3002 struct setspref *ssp;
3003 AFS_STATCNT(PSetSPrefs);
3005 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3006 return EIO; /* Inappropriate ioctl for device */
3008 if (!afs_osi_suser(*acred))
3011 if (ainSize < sizeof(struct setspref))
3014 ssp = (struct setspref *)ain;
3015 if (ainSize < sizeof(struct spref) * ssp->num_servers)
3018 afs_setsprefs(&(ssp->servers[0]), ssp->num_servers,
3019 (ssp->flags & DBservers));
3023 DECL_PIOCTL(PSetSPrefs33)
3026 AFS_STATCNT(PSetSPrefs);
3027 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3028 return EIO; /* Inappropriate ioctl for device */
3031 if (!afs_osi_suser(*acred))
3034 sp = (struct spref *)ain;
3035 afs_setsprefs(sp, ainSize / (sizeof(struct spref)), 0 /*!vlonly */ );
3039 /* some notes on the following code...
3040 * in the hash table of server structs, all servers with the same IP address
3041 * will be on the same overflow chain.
3042 * This could be sped slightly in some circumstances by having it cache the
3043 * immediately previous slot in the hash table and some supporting information
3044 * Only reports file servers now.
3046 DECL_PIOCTL(PGetSPrefs)
3048 struct sprefrequest *spin; /* input */
3049 struct sprefinfo *spout; /* output */
3050 struct spref *srvout; /* one output component */
3051 int i, j; /* counters for hash table traversal */
3052 struct server *srvr; /* one of CM's server structs */
3054 int vlonly; /* just return vlservers ? */
3057 AFS_STATCNT(PGetSPrefs);
3058 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3059 return EIO; /* Inappropriate ioctl for device */
3062 if (ainSize < sizeof(struct sprefrequest_33)) {
3065 spin = ((struct sprefrequest *)ain);
3068 if (ainSize > sizeof(struct sprefrequest_33)) {
3069 vlonly = (spin->flags & DBservers);
3073 /* struct sprefinfo includes 1 server struct... that size gets added
3074 * in during the loop that follows.
3076 *aoutSize = sizeof(struct sprefinfo) - sizeof(struct spref);
3077 spout = (struct sprefinfo *)aout;
3078 spout->next_offset = spin->offset;
3079 spout->num_servers = 0;
3080 srvout = spout->servers;
3082 ObtainReadLock(&afs_xserver);
3083 for (i = 0, j = 0; j < NSERVERS; j++) { /* sift through hash table */
3084 for (sa = afs_srvAddrs[j]; sa; sa = sa->next_bkt, i++) {
3085 if (spin->offset > (unsigned short)i) {
3086 continue; /* catch up to where we left off */
3088 spout->next_offset++;
3091 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
3092 || (sa->sa_portal == AFS_FSPORT);
3094 if ((vlonly && isfs) || (!vlonly && !isfs)) {
3095 /* only report ranks for vl servers */
3099 srvout->host.s_addr = sa->sa_ip;
3100 srvout->rank = sa->sa_iprank;
3101 *aoutSize += sizeof(struct spref);
3102 spout->num_servers++;
3105 if (*aoutSize > (PIGGYSIZE - sizeof(struct spref))) {
3106 ReleaseReadLock(&afs_xserver); /* no more room! */
3111 ReleaseReadLock(&afs_xserver);
3113 spout->next_offset = 0; /* start over from the beginning next time */
3117 /* Enable/Disable the specified exporter. Must be root to disable an exporter */
3118 int afs_NFSRootOnly = 1;
3119 DECL_PIOCTL(PExportAfs)
3121 afs_int32 export, newint =
3122 0, type, changestate, handleValue, convmode, pwsync, smounts;
3123 afs_int32 rempags = 0, pagcb = 0;
3124 register struct afs_exporter *exporter;
3126 AFS_STATCNT(PExportAfs);
3127 memcpy((char *)&handleValue, ain, sizeof(afs_int32));
3128 type = handleValue >> 24;
3133 exporter = exporter_find(type);
3135 export = handleValue & 3;
3136 changestate = handleValue & 0xfff;
3137 smounts = (handleValue >> 2) & 3;
3138 pwsync = (handleValue >> 4) & 3;
3139 convmode = (handleValue >> 6) & 3;
3140 rempags = (handleValue >> 8) & 3;
3141 pagcb = (handleValue >> 10) & 3;
3143 changestate = (handleValue >> 16) & 0x1;
3144 convmode = (handleValue >> 16) & 0x2;
3145 pwsync = (handleValue >> 16) & 0x4;
3146 smounts = (handleValue >> 16) & 0x8;
3147 export = handleValue & 0xff;
3150 /* Failed finding desired exporter; */
3154 handleValue = exporter->exp_states;
3155 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3156 *aoutSize = sizeof(afs_int32);
3158 if (!afs_osi_suser(*acred))
3159 return EACCES; /* Only superuser can do this */
3163 exporter->exp_states |= EXP_EXPORTED;
3165 exporter->exp_states &= ~EXP_EXPORTED;
3169 exporter->exp_states |= EXP_UNIXMODE;
3171 exporter->exp_states &= ~EXP_UNIXMODE;
3175 exporter->exp_states |= EXP_PWSYNC;
3177 exporter->exp_states &= ~EXP_PWSYNC;
3181 afs_NFSRootOnly = 0;
3182 exporter->exp_states |= EXP_SUBMOUNTS;
3184 afs_NFSRootOnly = 1;
3185 exporter->exp_states &= ~EXP_SUBMOUNTS;
3190 exporter->exp_states |= EXP_CLIPAGS;
3192 exporter->exp_states &= ~EXP_CLIPAGS;
3196 exporter->exp_states |= EXP_CALLBACK;
3198 exporter->exp_states &= ~EXP_CALLBACK;
3200 handleValue = exporter->exp_states;
3201 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3202 *aoutSize = sizeof(afs_int32);
3205 exporter->exp_states |= EXP_EXPORTED;
3207 exporter->exp_states &= ~EXP_EXPORTED;
3209 exporter->exp_states |= EXP_UNIXMODE;
3211 exporter->exp_states &= ~EXP_UNIXMODE;
3213 exporter->exp_states |= EXP_PWSYNC;
3215 exporter->exp_states &= ~EXP_PWSYNC;
3217 afs_NFSRootOnly = 0;
3218 exporter->exp_states |= EXP_SUBMOUNTS;
3220 afs_NFSRootOnly = 1;
3221 exporter->exp_states &= ~EXP_SUBMOUNTS;
3231 struct gaginfo *gagflags;
3233 if (!afs_osi_suser(*acred))
3236 gagflags = (struct gaginfo *)ain;
3237 afs_showflags = gagflags->showflags;
3243 DECL_PIOCTL(PTwiddleRx)
3245 struct rxparams *rxp;
3247 if (!afs_osi_suser(*acred))
3250 rxp = (struct rxparams *)ain;
3252 if (rxp->rx_initReceiveWindow)
3253 rx_initReceiveWindow = rxp->rx_initReceiveWindow;
3254 if (rxp->rx_maxReceiveWindow)
3255 rx_maxReceiveWindow = rxp->rx_maxReceiveWindow;
3256 if (rxp->rx_initSendWindow)
3257 rx_initSendWindow = rxp->rx_initSendWindow;
3258 if (rxp->rx_maxSendWindow)
3259 rx_maxSendWindow = rxp->rx_maxSendWindow;
3260 if (rxp->rxi_nSendFrags)
3261 rxi_nSendFrags = rxp->rxi_nSendFrags;
3262 if (rxp->rxi_nRecvFrags)
3263 rxi_nRecvFrags = rxp->rxi_nRecvFrags;
3264 if (rxp->rxi_OrphanFragSize)
3265 rxi_OrphanFragSize = rxp->rxi_OrphanFragSize;
3266 if (rxp->rx_maxReceiveSize) {
3267 rx_maxReceiveSize = rxp->rx_maxReceiveSize;
3268 rx_maxReceiveSizeUser = rxp->rx_maxReceiveSize;
3270 if (rxp->rx_MyMaxSendSize)
3271 rx_MyMaxSendSize = rxp->rx_MyMaxSendSize;
3276 DECL_PIOCTL(PGetInitParams)
3278 if (sizeof(struct cm_initparams) > PIGGYSIZE)
3281 memcpy(aout, (char *)&cm_initParams, sizeof(struct cm_initparams));
3282 *aoutSize = sizeof(struct cm_initparams);
3286 #ifdef AFS_SGI65_ENV
3287 /* They took crget() from us, so fake it. */
3292 cr = crdup(get_current_cred());
3293 memset((char *)cr, 0, sizeof(cred_t));
3294 #if CELL || CELL_PREPARE
3301 DECL_PIOCTL(PGetRxkcrypt)
3303 memcpy(aout, (char *)&cryptall, sizeof(afs_int32));
3304 *aoutSize = sizeof(afs_int32);
3308 DECL_PIOCTL(PSetRxkcrypt)
3312 if (!afs_osi_suser(*acred))
3314 if (ainSize != sizeof(afs_int32) || ain == NULL)
3316 memcpy((char *)&tmpval, ain, sizeof(afs_int32));
3317 /* if new mappings added later this will need to be changed */
3318 if (tmpval != 0 && tmpval != 1)
3324 #ifdef AFS_NEED_CLIENTCONTEXT
3326 * Create new credentials to correspond to a remote user with given
3327 * <hostaddr, uid, g0, g1>. This allows a server running as root to
3328 * provide pioctl (and other) services to foreign clients (i.e. nfs
3329 * clients) by using this call to `become' the client.
3332 #define PIOCTL_HEADER 6
3334 HandleClientContext(struct afs_ioctl *ablob, int *com,
3335 struct AFS_UCRED **acred, struct AFS_UCRED *credp)
3338 afs_uint32 hostaddr;
3339 afs_int32 uid, g0, g1, i, code, pag, exporter_type, isroot = 0;
3340 struct afs_exporter *exporter, *outexporter;
3341 struct AFS_UCRED *newcred;
3342 struct unixuser *au;
3343 afs_uint32 comp = *com & 0xff00;
3346 #if defined(AFS_SGIMP_ENV)
3347 osi_Assert(ISAFS_GLOCK());
3349 AFS_STATCNT(HandleClientContext);
3350 if (ablob->in_size < PIOCTL_HEADER * sizeof(afs_int32)) {
3351 /* Must at least include the PIOCTL_HEADER header words required by the protocol */
3352 return EINVAL; /* Too small to be good */
3354 ain = inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
3355 AFS_COPYIN(ablob->in, ain, PIOCTL_HEADER * sizeof(afs_int32), code);
3357 osi_FreeLargeSpace(inData);
3361 /* Extract information for remote user */
3362 hostaddr = *((afs_uint32 *) ain);
3363 ain += sizeof(hostaddr);
3364 uid = *((afs_uint32 *) ain);
3366 g0 = *((afs_uint32 *) ain);
3368 g1 = *((afs_uint32 *) ain);
3370 *com = *((afs_uint32 *) ain);
3371 ain += sizeof(afs_int32);
3372 exporter_type = *((afs_uint32 *) ain); /* In case we support more than NFS */
3375 * Of course, one must be root for most of these functions, but
3376 * we'll allow (for knfs) you to set things if the pag is 0 and
3377 * you're setting tokens or unlogging.
3380 if (!afs_osi_suser(credp)) {
3381 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
3382 /* Since SGI's suser() returns explicit failure after the call.. */
3385 /* check for acceptable opcodes for normal folks, which are, so far,
3386 * get/set tokens, sysname, and unlog.
3388 if (i != 9 && i != 3 && i != 38 && i != 8) {
3389 osi_FreeLargeSpace(inData);
3394 ablob->in_size -= PIOCTL_HEADER * sizeof(afs_int32);
3395 ablob->in += PIOCTL_HEADER * sizeof(afs_int32);
3396 osi_FreeLargeSpace(inData);
3399 * We map uid 0 to nobody to match the mapping that the nfs
3400 * server does and to ensure that the suser() calls in the afs
3401 * code fails for remote client roots.
3403 uid = afs_nobody; /* NFS_NOBODY == -2 */
3407 #ifdef AFS_AIX41_ENV
3410 newcred->cr_gid = isroot ? RMTUSER_REQ_PRIV : RMTUSER_REQ;
3411 #ifdef AFS_AIX51_ENV
3412 newcred->cr_groupset.gs_union.un_groups[0] = g0;
3413 newcred->cr_groupset.gs_union.un_groups[1] = g1;
3414 #elif defined(AFS_LINUX26_ENV)
3415 #ifdef AFS_LINUX26_ONEGROUP_ENV
3416 newcred->cr_group_info = groups_alloc(1); /* not that anything sets this */
3417 l = (((g0-0x3f00) & 0x3fff) << 14) | ((g1-0x3f00) & 0x3fff);
3418 h = ((g0-0x3f00) >> 14);
3419 h = ((g1-0x3f00) >> 14) + h + h + h;
3420 GROUP_AT(newcred->cr_group_info, 0) = ((h << 28) | l);
3422 newcred->cr_group_info = groups_alloc(2);
3423 GROUP_AT(newcred->cr_group_info, 0) = g0;
3424 GROUP_AT(newcred->cr_group_info, 1) = g1;
3427 newcred->cr_groups[0] = g0;
3428 newcred->cr_groups[1] = g1;
3431 newcred->cr_ngrps = 2;
3432 #elif !defined(AFS_LINUX26_ENV)
3433 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
3434 newcred->cr_ngroups = 2;
3436 for (i = 2; i < NGROUPS; i++)
3437 newcred->cr_groups[i] = NOGROUP;
3440 #if !defined(AFS_OSF_ENV)
3441 afs_nfsclient_init(); /* before looking for exporter, ensure one exists */
3443 if (!(exporter = exporter_find(exporter_type))) {
3444 /* Exporter wasn't initialized or an invalid exporter type */
3448 if (exporter->exp_states & EXP_PWSYNC) {
3449 if (uid != credp->cr_uid) {
3451 return ENOEXEC; /* XXX Find a better errno XXX */
3454 newcred->cr_uid = uid; /* Only temporary */
3455 code = EXP_REQHANDLER(exporter, &newcred, hostaddr, &pag, &outexporter);
3456 /* The client's pag is the only unique identifier for it */
3457 newcred->cr_uid = pag;
3459 if (!code && *com == PSETPAG) {
3460 /* Special case for 'setpag' */
3461 afs_uint32 pagvalue = genpag();
3463 au = afs_GetUser(pagvalue, -1, WRITE_LOCK); /* a new unixuser struct */
3465 * Note that we leave the 'outexporter' struct held so it won't
3468 au->exporter = outexporter;
3469 if (ablob->out_size >= 4) {
3470 AFS_COPYOUT((char *)&pagvalue, ablob->out, sizeof(afs_int32),
3473 afs_PutUser(au, WRITE_LOCK);
3476 return PSETPAG; /* Special return for setpag */
3478 EXP_RELE(outexporter);
3481 *com = (*com) | comp;
3484 #endif /* AFS_NEED_CLIENTCONTEXT */
3486 /* get all interface addresses of this client */
3488 DECL_PIOCTL(PGetCPrefs)
3490 struct sprefrequest *spin; /* input */
3491 struct sprefinfo *spout; /* output */
3492 struct spref *srvout; /* one output component */
3496 AFS_STATCNT(PGetCPrefs);
3497 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3498 return EIO; /* Inappropriate ioctl for device */
3500 if (ainSize < sizeof(struct sprefrequest))
3503 spin = (struct sprefrequest *)ain;
3504 spout = (struct sprefinfo *)aout;
3506 maxNumber = spin->num_servers; /* max addrs this time */
3507 srvout = spout->servers;
3509 ObtainReadLock(&afs_xinterface);
3511 /* copy out the client interface information from the
3512 ** kernel data structure "interface" to the output buffer
3514 for (i = spin->offset, j = 0; (i < afs_cb_interface.numberOfInterfaces)
3515 && (j < maxNumber); i++, j++, srvout++)
3516 srvout->host.s_addr = afs_cb_interface.addr_in[i];
3518 spout->num_servers = j;
3519 *aoutSize = sizeof(struct sprefinfo) + (j - 1) * sizeof(struct spref);
3521 if (i >= afs_cb_interface.numberOfInterfaces)
3522 spout->next_offset = 0; /* start from beginning again */
3524 spout->next_offset = spin->offset + j;
3526 ReleaseReadLock(&afs_xinterface);
3530 DECL_PIOCTL(PSetCPrefs)
3532 struct setspref *sin;
3535 AFS_STATCNT(PSetCPrefs);
3536 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3537 return EIO; /* Inappropriate ioctl for device */
3539 sin = (struct setspref *)ain;
3541 if (ainSize < sizeof(struct setspref))
3543 #if 0 /* num_servers is unsigned */
3544 if (sin->num_servers < 0)
3547 if (sin->num_servers > AFS_MAX_INTERFACE_ADDR)
3550 ObtainWriteLock(&afs_xinterface, 412);
3551 afs_cb_interface.numberOfInterfaces = sin->num_servers;
3552 for (i = 0; (unsigned short)i < sin->num_servers; i++)
3553 afs_cb_interface.addr_in[i] = sin->servers[i].host.s_addr;
3555 ReleaseWriteLock(&afs_xinterface);
3559 DECL_PIOCTL(PFlushMount)
3561 register afs_int32 code;
3562 register struct vcache *tvc;
3563 register struct dcache *tdc;
3564 struct VenusFid tfid;
3566 struct sysname_info sysState;
3567 afs_size_t offset, len;
3569 AFS_STATCNT(PFlushMount);
3572 code = afs_VerifyVCache(avc, areq);
3575 if (vType(avc) != VDIR) {
3578 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
3581 Check_AtSys(avc, ain, &sysState, areq);
3582 ObtainReadLock(&tdc->lock);
3584 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
3585 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
3586 ReleaseReadLock(&tdc->lock);
3587 afs_PutDCache(tdc); /* we're done with the data */
3588 bufp = sysState.name;
3592 tfid.Cell = avc->fid.Cell;
3593 tfid.Fid.Volume = avc->fid.Fid.Volume;
3594 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
3595 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
3597 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3603 if (tvc->mvstat != 1) {
3608 #ifdef AFS_BOZONLOCK_ENV
3609 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
3611 ObtainWriteLock(&tvc->lock, 649);
3612 ObtainWriteLock(&afs_xcbhash, 650);
3613 afs_DequeueCallback(tvc);
3614 tvc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
3615 ReleaseWriteLock(&afs_xcbhash);
3616 /* now find the disk cache entries */
3617 afs_TryToSmush(tvc, *acred, 1);
3618 osi_dnlc_purgedp(tvc);
3619 if (tvc->linkData && !(tvc->states & CCore)) {
3620 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
3621 tvc->linkData = NULL;
3623 ReleaseWriteLock(&tvc->lock);
3624 #ifdef AFS_BOZONLOCK_ENV
3625 afs_BozonUnlock(&tvc->pvnLock, tvc);
3629 if (sysState.allocked)
3630 osi_FreeLargeSpace(bufp);
3634 DECL_PIOCTL(PRxStatProc)
3639 if (!afs_osi_suser(*acred)) {
3643 if (ainSize != sizeof(afs_int32)) {
3647 memcpy((char *)&flags, ain, sizeof(afs_int32));
3648 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3652 if (flags & AFSCALL_RXSTATS_ENABLE) {
3653 rx_enableProcessRPCStats();
3655 if (flags & AFSCALL_RXSTATS_DISABLE) {
3656 rx_disableProcessRPCStats();
3658 if (flags & AFSCALL_RXSTATS_CLEAR) {
3659 rx_clearProcessRPCStats(AFS_RX_STATS_CLEAR_ALL);
3667 DECL_PIOCTL(PRxStatPeer)
3672 if (!afs_osi_suser(*acred)) {
3676 if (ainSize != sizeof(afs_int32)) {
3680 memcpy((char *)&flags, ain, sizeof(afs_int32));
3681 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3685 if (flags & AFSCALL_RXSTATS_ENABLE) {
3686 rx_enablePeerRPCStats();
3688 if (flags & AFSCALL_RXSTATS_DISABLE) {
3689 rx_disablePeerRPCStats();
3691 if (flags & AFSCALL_RXSTATS_CLEAR) {
3692 rx_clearPeerRPCStats(AFS_RX_STATS_CLEAR_ALL);
3699 DECL_PIOCTL(PPrefetchFromTape)
3701 register afs_int32 code, code1;
3704 struct rx_call *tcall;
3705 struct AFSVolSync tsync;
3706 struct AFSFetchStatus OutStatus;
3707 struct AFSCallBack CallBack;
3708 struct VenusFid tfid;
3712 AFS_STATCNT(PSetAcl);
3716 if (ain && (ainSize == 3 * sizeof(afs_int32)))
3717 Fid = (struct AFSFid *)ain;
3719 Fid = &avc->fid.Fid;
3720 tfid.Cell = avc->fid.Cell;
3721 tfid.Fid.Volume = Fid->Volume;
3722 tfid.Fid.Vnode = Fid->Vnode;
3723 tfid.Fid.Unique = Fid->Unique;
3725 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3727 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3728 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &avc->fid);
3731 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3732 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &tvc->fid);
3735 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3739 tcall = rx_NewCall(tc->id);
3741 StartRXAFS_FetchData(tcall, (struct AFSFid *)&tvc->fid.Fid, 0,
3744 bytes = rx_Read(tcall, (char *)aout, sizeof(afs_int32));
3746 EndRXAFS_FetchData(tcall, &OutStatus, &CallBack, &tsync);
3748 code1 = rx_EndCall(tcall, code);
3752 } while (afs_Analyze
3753 (tc, code, &tvc->fid, areq, AFS_STATS_FS_RPCIDX_RESIDENCYRPCS,
3754 SHARED_LOCK, NULL));
3755 /* This call is done only to have the callback things handled correctly */
3756 afs_FetchStatus(tvc, &tfid, areq, &OutStatus);
3760 *aoutSize = sizeof(afs_int32);
3765 DECL_PIOCTL(PResidencyCmd)
3767 register afs_int32 code;
3770 struct ResidencyCmdInputs *Inputs;
3771 struct ResidencyCmdOutputs *Outputs;
3772 struct VenusFid tfid;
3775 Inputs = (struct ResidencyCmdInputs *)ain;
3776 Outputs = (struct ResidencyCmdOutputs *)aout;
3779 if (!ain || ainSize != sizeof(struct ResidencyCmdInputs))
3784 Fid = &avc->fid.Fid;
3786 tfid.Cell = avc->fid.Cell;
3787 tfid.Fid.Volume = Fid->Volume;
3788 tfid.Fid.Vnode = Fid->Vnode;
3789 tfid.Fid.Unique = Fid->Unique;
3791 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3792 afs_Trace3(afs_iclSetp, CM_TRACE_RESIDCMD, ICL_TYPE_POINTER, tvc,
3793 ICL_TYPE_INT32, Inputs->command, ICL_TYPE_FID, &tfid);
3797 if (Inputs->command) {
3799 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3803 RXAFS_ResidencyCmd(tc->id, Fid, Inputs,
3804 (struct ResidencyCmdOutputs *)aout);
3808 } while (afs_Analyze
3809 (tc, code, &tvc->fid, areq,
3810 AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK, NULL));
3811 /* This call is done to have the callback things handled correctly */
3812 afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3813 } else { /* just a status request, return also link data */
3815 Outputs->code = afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3816 Outputs->chars[0] = 0;
3817 if (vType(tvc) == VLNK) {
3818 ObtainWriteLock(&tvc->lock, 555);
3819 if (afs_HandleLink(tvc, areq) == 0)
3820 strncpy((char *)&Outputs->chars, tvc->linkData, MAXCMDCHARS);
3821 ReleaseWriteLock(&tvc->lock);
3828 *aoutSize = sizeof(struct ResidencyCmdOutputs);
3833 DECL_PIOCTL(PNewUuid)
3835 /*AFS_STATCNT(PNewUuid); */
3836 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
3837 return EIO; /* Inappropriate ioctl for device */
3839 if (!afs_osi_suser(acred))
3842 ObtainWriteLock(&afs_xinterface, 555);
3843 afs_uuid_create(&afs_cb_interface.uuid);
3844 ReleaseWriteLock(&afs_xinterface);
3845 ForceAllNewConnections();
3849 DECL_PIOCTL(PCallBackAddr)
3852 afs_uint32 addr, code;
3858 struct unixuser *tu;
3859 struct srvAddr **addrs;
3861 /*AFS_STATCNT(PCallBackAddr); */
3862 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
3863 return EIO; /* Inappropriate ioctl for device */
3865 if (!afs_osi_suser(acred))
3868 if (ainSize < sizeof(afs_int32))
3871 memcpy(&addr, ain, sizeof(afs_int32));
3873 ObtainReadLock(&afs_xinterface);
3874 for (i = 0; (unsigned short)i < afs_cb_interface.numberOfInterfaces; i++) {
3875 if (afs_cb_interface.addr_in[i] == addr)
3879 ReleaseWriteLock(&afs_xinterface);
3881 if (afs_cb_interface.addr_in[i] != addr)
3884 ObtainReadLock(&afs_xserver); /* Necessary? */
3885 ObtainReadLock(&afs_xsrvAddr);
3888 for (i = 0; i < NSERVERS; i++) {
3889 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3894 addrs = afs_osi_Alloc(srvAddrCount * sizeof(*addrs));
3896 for (i = 0; i < NSERVERS; i++) {
3897 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3898 if (j >= srvAddrCount)
3904 ReleaseReadLock(&afs_xsrvAddr);
3905 ReleaseReadLock(&afs_xserver);
3907 for (i = 0; i < j; i++) {
3913 /* vlserver has no callback conn */
3914 if (sa->sa_portal == AFS_VLPORT) {
3918 if (!ts->cell) /* not really an active server, anyway, it must */
3919 continue; /* have just been added by setsprefs */
3921 /* get a connection, even if host is down; bumps conn ref count */
3922 tu = afs_GetUser(areq->uid, ts->cell->cellNum, SHARED_LOCK);
3923 tc = afs_ConnBySA(sa, ts->cell->fsport, ts->cell->cellNum, tu,
3924 1 /*force */ , 1 /*create */ , SHARED_LOCK);
3925 afs_PutUser(tu, SHARED_LOCK);
3929 if ((sa->sa_flags & SRVADDR_ISDOWN) || afs_HaveCallBacksFrom(ts)) {
3930 if (sa->sa_flags & SRVADDR_ISDOWN) {
3931 rx_SetConnDeadTime(tc->id, 3);
3933 #ifdef RX_ENABLE_LOCKS
3935 #endif /* RX_ENABLE_LOCKS */
3936 code = RXAFS_CallBackRxConnAddr(tc->id, &addr);
3937 #ifdef RX_ENABLE_LOCKS
3939 #endif /* RX_ENABLE_LOCKS */
3941 afs_PutConn(tc, SHARED_LOCK); /* done with it now */
3942 } /* Outer loop over addrs */
3943 #endif /* UKERNEL */
3947 DECL_PIOCTL(PDiscon)
3949 #ifdef AFS_DISCON_ENV
3950 static afs_int32 mode;
3952 if (ainSize == sizeof(afs_int32)) {
3953 memcpy(&mode, ain, sizeof(afs_int32));
3955 /* 3 is magic, should be a #define. */
3956 afs_SetCheckServerNATmode(mode == 3);
3957 } else if (ainSize != 0) {
3961 /* Return new mode */
3962 memcpy(aout, &mode, sizeof(afs_int32));
3963 *aoutSize = sizeof(struct VenusFid);
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);