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 */
34 afs_int32 afs_is_disconnected;
35 afs_int32 afs_is_logging;
36 afs_int32 afs_is_discon_rw;
37 /* On reconnection, turn this knob on until it finishes,
40 afs_int32 afs_in_sync = 0;
43 #define DECL_PIOCTL(x) static int x(struct vcache *avc, int afun, struct vrequest *areq, \
44 char *ain, char *aout, afs_int32 ainSize, afs_int32 *aoutSize, \
45 struct AFS_UCRED **acred)
47 /* Prototypes for pioctl routines */
50 DECL_PIOCTL(PStoreBehind);
55 DECL_PIOCTL(PGetFileCell);
56 DECL_PIOCTL(PGetWSCell);
57 DECL_PIOCTL(PGetUserCell);
58 DECL_PIOCTL(PSetTokens);
59 DECL_PIOCTL(PGetVolumeStatus);
60 DECL_PIOCTL(PSetVolumeStatus);
62 DECL_PIOCTL(PNewStatMount);
63 DECL_PIOCTL(PGetTokens);
65 DECL_PIOCTL(PMariner);
66 DECL_PIOCTL(PCheckServers);
67 DECL_PIOCTL(PCheckVolNames);
68 DECL_PIOCTL(PCheckAuth);
69 DECL_PIOCTL(PFindVolume);
70 DECL_PIOCTL(PViceAccess);
71 DECL_PIOCTL(PSetCacheSize);
72 DECL_PIOCTL(PGetCacheSize);
73 DECL_PIOCTL(PRemoveCallBack);
74 DECL_PIOCTL(PNewCell);
75 DECL_PIOCTL(PNewAlias);
76 DECL_PIOCTL(PListCells);
77 DECL_PIOCTL(PListAliases);
78 DECL_PIOCTL(PRemoveMount);
79 DECL_PIOCTL(PVenusLogging);
80 DECL_PIOCTL(PGetCellStatus);
81 DECL_PIOCTL(PSetCellStatus);
82 DECL_PIOCTL(PFlushVolumeData);
83 DECL_PIOCTL(PGetVnodeXStatus);
84 DECL_PIOCTL(PGetVnodeXStatus2);
85 DECL_PIOCTL(PSetSysName);
86 DECL_PIOCTL(PSetSPrefs);
87 DECL_PIOCTL(PSetSPrefs33);
88 DECL_PIOCTL(PGetSPrefs);
89 DECL_PIOCTL(PExportAfs);
91 DECL_PIOCTL(PTwiddleRx);
92 DECL_PIOCTL(PGetInitParams);
93 DECL_PIOCTL(PGetRxkcrypt);
94 DECL_PIOCTL(PSetRxkcrypt);
95 DECL_PIOCTL(PGetCPrefs);
96 DECL_PIOCTL(PSetCPrefs);
97 DECL_PIOCTL(PFlushMount);
98 DECL_PIOCTL(PRxStatProc);
99 DECL_PIOCTL(PRxStatPeer);
100 DECL_PIOCTL(PPrefetchFromTape);
101 DECL_PIOCTL(PResidencyCmd);
102 DECL_PIOCTL(PCallBackAddr);
103 DECL_PIOCTL(PDiscon);
104 DECL_PIOCTL(PNFSNukeCreds);
105 DECL_PIOCTL(PNewUuid);
106 DECL_PIOCTL(PPrecache);
109 * A macro that says whether we're going to need HandleClientContext().
110 * This is currently used only by the nfs translator.
112 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
113 #define AFS_NEED_CLIENTCONTEXT
116 /* Prototypes for private routines */
117 #ifdef AFS_NEED_CLIENTCONTEXT
118 static int HandleClientContext(struct afs_ioctl *ablob, int *com,
119 struct AFS_UCRED **acred,
120 struct AFS_UCRED *credp);
122 int HandleIoctl(register struct vcache *avc, register afs_int32 acom,
123 struct afs_ioctl *adata);
124 int afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
125 register struct afs_ioctl *ablob, int afollow,
126 struct AFS_UCRED **acred);
127 static int Prefetch(char *apath, struct afs_ioctl *adata, int afollow,
128 struct AFS_UCRED *acred);
131 static int (*(VpioctlSw[])) () = {
136 PGetVolumeStatus, /* 4 */
137 PSetVolumeStatus, /* 5 */
142 PCheckServers, /* 10 */
143 PCheckVolNames, /* 11 */
145 PBogus, /* 13 -- used to be quick check time */
146 PFindVolume, /* 14 */
147 PBogus, /* 15 -- prefetch is now special-cased; see pioctl code! */
148 PBogus, /* 16 -- used to be testing code */
149 PNoop, /* 17 -- used to be enable group */
150 PNoop, /* 18 -- used to be disable group */
151 PBogus, /* 19 -- used to be list group */
152 PViceAccess, /* 20 */
153 PUnlog, /* 21 -- unlog *is* unpag in this system */
154 PGetFID, /* 22 -- get file ID */
155 PBogus, /* 23 -- used to be waitforever */
156 PSetCacheSize, /* 24 */
157 PRemoveCallBack, /* 25 -- flush only the callback */
160 PRemoveMount, /* 28 -- delete mount point */
161 PNewStatMount, /* 29 -- new style mount point stat */
162 PGetFileCell, /* 30 -- get cell name for input file */
163 PGetWSCell, /* 31 -- get cell name for workstation */
164 PMariner, /* 32 - set/get mariner host */
165 PGetUserCell, /* 33 -- get cell name for user */
166 PVenusLogging, /* 34 -- Enable/Disable logging */
167 PGetCellStatus, /* 35 */
168 PSetCellStatus, /* 36 */
169 PFlushVolumeData, /* 37 -- flush all data from a volume */
170 PSetSysName, /* 38 - Set system name */
171 PExportAfs, /* 39 - Export Afs to remote nfs clients */
172 PGetCacheSize, /* 40 - get cache size and usage */
173 PGetVnodeXStatus, /* 41 - get vcache's special status */
174 PSetSPrefs33, /* 42 - Set CM Server preferences... */
175 PGetSPrefs, /* 43 - Get CM Server preferences... */
176 PGag, /* 44 - turn off/on all CM messages */
177 PTwiddleRx, /* 45 - adjust some RX params */
178 PSetSPrefs, /* 46 - Set CM Server preferences... */
179 PStoreBehind, /* 47 - set degree of store behind to be done */
180 PGCPAGs, /* 48 - disable automatic pag gc-ing */
181 PGetInitParams, /* 49 - get initial cm params */
182 PGetCPrefs, /* 50 - get client interface addresses */
183 PSetCPrefs, /* 51 - set client interface addresses */
184 PFlushMount, /* 52 - flush mount symlink data */
185 PRxStatProc, /* 53 - control process RX statistics */
186 PRxStatPeer, /* 54 - control peer RX statistics */
187 PGetRxkcrypt, /* 55 -- Get rxkad encryption flag */
188 PSetRxkcrypt, /* 56 -- Set rxkad encryption flag */
189 PBogus, /* 57 -- arla: set file prio */
190 PBogus, /* 58 -- arla: fallback getfh */
191 PBogus, /* 59 -- arla: fallback fhopen */
192 PBogus, /* 60 -- arla: controls xfsdebug */
193 PBogus, /* 61 -- arla: controls arla debug */
194 PBogus, /* 62 -- arla: debug interface */
195 PBogus, /* 63 -- arla: print xfs status */
196 PBogus, /* 64 -- arla: force cache check */
197 PBogus, /* 65 -- arla: break callback */
198 PPrefetchFromTape, /* 66 -- MR-AFS: prefetch file from tape */
199 PResidencyCmd, /* 67 -- MR-AFS: generic commnd interface */
200 PBogus, /* 68 -- arla: fetch stats */
201 PGetVnodeXStatus2, /* 69 - get caller access and some vcache status */
204 static int (*(CpioctlSw[])) () = {
206 PNewAlias, /* 1 -- create new cell alias */
207 PListAliases, /* 2 -- list cell aliases */
208 PCallBackAddr, /* 3 -- request addr for callback rxcon */
210 PDiscon, /* 5 -- get/set discon mode */
220 static int (*(OpioctlSw[])) () = {
222 PNFSNukeCreds, /* 1 -- nuke all creds for NFS client */
225 #define PSetClientContext 99 /* Special pioctl to setup caller's creds */
226 int afs_nobody = NFS_NOBODY;
229 HandleIoctl(register struct vcache *avc, register afs_int32 acom,
230 struct afs_ioctl *adata)
232 register afs_int32 code;
235 AFS_STATCNT(HandleIoctl);
237 switch (acom & 0xff) {
239 avc->states |= CSafeStore;
243 /* case 2 used to be abort store, but this is no longer provided,
244 * since it is impossible to implement under normal Unix.
248 /* return the name of the cell this file is open on */
249 register struct cell *tcell;
250 register afs_int32 i;
252 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
254 i = strlen(tcell->cellName) + 1; /* bytes to copy out */
256 if (i > adata->out_size) {
257 /* 0 means we're not interested in the output */
258 if (adata->out_size != 0)
262 AFS_COPYOUT(tcell->cellName, adata->out, i, code);
264 afs_PutCell(tcell, READ_LOCK);
270 case 49: /* VIOC_GETINITPARAMS */
271 if (adata->out_size < sizeof(struct cm_initparams)) {
274 AFS_COPYOUT(&cm_initParams, adata->out,
275 sizeof(struct cm_initparams), code);
287 return code; /* so far, none implemented */
292 /* For aix we don't temporarily bypass ioctl(2) but rather do our
293 * thing directly in the vnode layer call, VNOP_IOCTL; thus afs_ioctl
294 * is now called from afs_gn_ioctl.
297 afs_ioctl(struct vcache *tvc, int cmd, int arg)
299 struct afs_ioctl data;
302 AFS_STATCNT(afs_ioctl);
303 if (((cmd >> 8) & 0xff) == 'V') {
304 /* This is a VICEIOCTL call */
305 AFS_COPYIN(arg, (caddr_t) & data, sizeof(data), error);
308 error = HandleIoctl(tvc, cmd, &data);
311 /* No-op call; just return. */
315 #endif /* AFS_AIX_ENV */
317 #if defined(AFS_SGI_ENV)
318 afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
321 , struct vopbd * vbds
325 struct afs_ioctl data;
331 AFS_STATCNT(afs_ioctl);
332 if (((cmd >> 8) & 0xff) == 'V') {
333 /* This is a VICEIOCTL call */
334 error = copyin_afs_ioctl(arg, &data);
337 locked = ISAFS_GLOCK();
340 error = HandleIoctl(tvc, cmd, &data);
345 /* No-op call; just return. */
349 #endif /* AFS_SGI_ENV */
351 /* unlike most calls here, this one uses u.u_error to return error conditions,
352 since this is really an intercepted chapter 2 call, rather than a vnode
355 /* AFS_HPUX102 and up uses VNODE ioctl instead */
356 #if !defined(AFS_HPUX102_ENV) && !defined(AFS_DARWIN80_ENV)
357 #if !defined(AFS_SGI_ENV)
361 kioctl(fdes, com, arg, ext, arg2, arg3)
362 #else /* __64BIT__ */
363 kioctl32(fdes, com, arg, ext, arg2, arg3)
364 #endif /* __64BIT__ */
367 kioctl(fdes, com, arg, ext)
378 } u_uap, *uap = &u_uap;
380 #if defined(AFS_SUN5_ENV)
382 struct afs_ioctl_sys {
389 struct afs_ioctl_sys *uap;
392 #elif defined(AFS_OSF_ENV)
393 afs_xioctl(p, args, retval)
402 } *uap = (struct a *)args;
403 #elif defined(AFS_FBSD50_ENV)
406 afs_xioctl(td, uap, retval)
408 register struct ioctl_args *uap;
411 struct proc *p = td->td_proc;
412 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
420 afs_xioctl(p, uap, retval)
422 register struct ioctl_args *uap;
425 #elif defined(AFS_LINUX22_ENV)
426 struct afs_ioctl_sys {
431 afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
434 struct afs_ioctl_sys ua, *uap = &ua;
443 } *uap = (struct a *)u.u_ap;
444 #endif /* AFS_SUN5_ENV */
446 #if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
448 #elif !defined(AFS_LINUX22_ENV)
449 register struct file *fd;
451 #if defined(AFS_XBSD_ENV)
452 register struct filedesc *fdp;
454 register struct vcache *tvc;
455 register int ioctlDone = 0, code = 0;
457 AFS_STATCNT(afs_xioctl);
458 #if defined(AFS_DARWIN_ENV)
459 if ((code = fdgetf(p, uap->fd, &fd)))
461 #elif defined(AFS_XBSD_ENV)
463 if ((u_int) uap->fd >= fdp->fd_nfiles
464 || (fd = fdp->fd_ofiles[uap->fd]) == NULL)
466 if ((fd->f_flag & (FREAD | FWRITE)) == 0)
468 #elif defined(AFS_LINUX22_ENV)
471 #elif defined(AFS_AIX32_ENV)
479 if (setuerror(getf(uap->fd, &fd))) {
482 #elif defined(AFS_OSF_ENV)
484 if (code = getf(&fd, uap->fd, FILE_FLAGS_NULL, &u.u_file_state))
486 #elif defined(AFS_SUN5_ENV)
487 # if defined(AFS_SUN57_ENV)
491 # elif defined(AFS_SUN54_ENV)
496 if (code = getf(uap->fd, &fd)) {
499 # endif /* AFS_SUN57_ENV */
505 /* first determine whether this is any sort of vnode */
506 #if defined(AFS_LINUX22_ENV)
511 if (fd->f_vnode->v_type == VREG || fd->f_vnode->v_type == VDIR) {
513 if (fd->f_type == DTYPE_VNODE) {
515 /* good, this is a vnode; next see if it is an AFS vnode */
516 #if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV)
517 tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */
518 #elif defined(AFS_OBSD_ENV)
520 IsAfsVnode((struct vnode *)fd->
521 f_data) ? VTOAFS((struct vnode *)fd->f_data) : NULL;
523 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
525 #endif /* AFS_LINUX22_ENV */
526 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
527 /* This is an AFS vnode */
528 if (((uap->com >> 8) & 0xff) == 'V') {
529 register struct afs_ioctl *datap;
532 (struct afs_ioctl *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
533 code=copyin_afs_ioctl((char *)uap->arg, datap);
535 osi_FreeSmallSpace(datap);
537 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
540 #if defined(AFS_SUN5_ENV)
555 #else /* AFS_OSF_ENV */
559 #ifdef AFS_LINUX22_ENV
569 code = HandleIoctl(tvc, uap->com, datap);
570 osi_FreeSmallSpace(datap);
584 #if defined(AFS_LINUX22_ENV)
596 code = okioctl(fdes, com, arg, ext, arg2, arg3);
597 #else /* __64BIT__ */
598 code = okioctl32(fdes, com, arg, ext, arg2, arg3);
599 #endif /* __64BIT__ */
600 #else /* !AFS_AIX51_ENV */
601 code = okioctl(fdes, com, arg, ext);
602 #endif /* AFS_AIX51_ENV */
604 #else /* !AFS_AIX41_ENV */
606 okioctl(fdes, com, arg, ext);
607 #elif defined(AFS_SUN5_ENV)
608 #if defined(AFS_SUN57_ENV)
610 #elif defined(AFS_SUN54_ENV)
615 code = ioctl(uap, rvp);
616 #elif defined(AFS_FBSD50_ENV)
617 return ioctl(td, uap);
618 #elif defined(AFS_FBSD_ENV)
619 return ioctl(p, uap);
620 #elif defined(AFS_OBSD_ENV)
621 code = sys_ioctl(p, uap, retval);
622 #elif defined(AFS_DARWIN_ENV)
623 return ioctl(p, uap, retval);
624 #elif defined(AFS_OSF_ENV)
625 code = ioctl(p, args, retval);
632 #elif !defined(AFS_LINUX22_ENV)
646 #ifdef AFS_LINUX22_ENV
649 #if defined(KERNEL_HAVE_UERROR)
652 #if defined(AFS_AIX32_ENV) && !defined(AFS_AIX41_ENV)
653 return (getuerror()? -1 : u.u_ioctlrv);
655 return getuerror()? -1 : 0;
658 #endif /* AFS_LINUX22_ENV */
659 #endif /* AFS_SUN5_ENV */
660 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
664 #endif /* AFS_SGI_ENV */
665 #endif /* AFS_HPUX102_ENV */
667 #if defined(AFS_SGI_ENV)
668 /* "pioctl" system call entry point; just pass argument to the parameterized
677 afs_pioctl(struct pioctlargs *uap, rval_t * rvp)
681 AFS_STATCNT(afs_pioctl);
683 code = afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow);
692 #elif defined(AFS_OSF_ENV)
693 afs_pioctl(p, args, retval)
703 } *uap = (struct a *)args;
705 AFS_STATCNT(afs_pioctl);
706 return (afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow));
709 #elif defined(AFS_FBSD50_ENV)
711 afs_pioctl(td, args, retval)
721 } *uap = (struct a *)args;
723 AFS_STATCNT(afs_pioctl);
724 return (afs_syscall_pioctl
725 (uap->path, uap->cmd, uap->cmarg, uap->follow, td->td_ucred));
728 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
730 afs_pioctl(p, args, retval)
740 } *uap = (struct a *)args;
742 AFS_STATCNT(afs_pioctl);
743 #ifdef AFS_DARWIN80_ENV
744 return (afs_syscall_pioctl
745 (uap->path, uap->cmd, uap->cmarg, uap->follow,
748 return (afs_syscall_pioctl
749 (uap->path, uap->cmd, uap->cmarg, uap->follow,
750 p->p_cred->pc_ucred));
756 /* macro to avoid adding any more #ifdef's to pioctl code. */
757 #if defined(AFS_LINUX22_ENV) || defined(AFS_AIX41_ENV)
758 #define PIOCTL_FREE_CRED() crfree(credp)
760 #define PIOCTL_FREE_CRED()
765 afs_syscall_pioctl(path, com, cmarg, follow, rvp, credp)
767 struct AFS_UCRED *credp;
769 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
770 afs_syscall_pioctl(path, com, cmarg, follow, credp)
771 struct AFS_UCRED *credp;
773 afs_syscall_pioctl(path, com, cmarg, follow)
781 struct afs_ioctl data;
782 #ifdef AFS_NEED_CLIENTCONTEXT
783 struct AFS_UCRED *tmpcred = NULL;
785 struct AFS_UCRED *foreigncreds = NULL;
786 register afs_int32 code = 0;
787 struct vnode *vp = NULL;
789 struct ucred *credp = crref(); /* don't free until done! */
791 #ifdef AFS_LINUX22_ENV
792 cred_t *credp = crref(); /* don't free until done! */
796 AFS_STATCNT(afs_syscall_pioctl);
798 follow = 1; /* compat. with old venus */
799 code = copyin_afs_ioctl(cmarg, &data);
802 #if defined(KERNEL_HAVE_UERROR)
807 if ((com & 0xff) == PSetClientContext) {
808 #ifdef AFS_NEED_CLIENTCONTEXT
809 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV)
810 code = HandleClientContext(&data, &com, &foreigncreds, credp);
812 code = HandleClientContext(&data, &com, &foreigncreds, osi_curcred());
816 crfree(foreigncreds);
819 #if defined(KERNEL_HAVE_UERROR)
820 return (setuerror(code), code);
825 #else /* AFS_NEED_CLIENTCONTEXT */
827 #endif /* AFS_NEED_CLIENTCONTEXT */
829 #ifdef AFS_NEED_CLIENTCONTEXT
832 * We could have done without temporary setting the u.u_cred below
833 * (foreigncreds could be passed as param the pioctl modules)
834 * but calls such as afs_osi_suser() doesn't allow that since it
835 * references u.u_cred directly. We could, of course, do something
836 * like afs_osi_suser(cred) which, I think, is better since it
837 * generalizes and supports multi cred environments...
839 #if defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
841 credp = foreigncreds;
842 #elif defined(AFS_AIX41_ENV)
843 tmpcred = crref(); /* XXX */
845 #elif defined(AFS_HPUX101_ENV)
846 tmpcred = p_cred(u.u_procp);
847 set_p_cred(u.u_procp, foreigncreds);
848 #elif defined(AFS_SGI_ENV)
849 tmpcred = OSI_GET_CURRENT_CRED();
850 OSI_SET_CURRENT_CRED(foreigncreds);
853 u.u_cred = foreigncreds;
856 #endif /* AFS_NEED_CLIENTCONTEXT */
857 if ((com & 0xff) == 15) {
858 /* special case prefetch so entire pathname eval occurs in helper process.
859 * otherwise, the pioctl call is essentially useless */
860 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
862 Prefetch(path, &data, follow,
863 foreigncreds ? foreigncreds : credp);
865 code = Prefetch(path, &data, follow, osi_curcred());
868 #if defined(KERNEL_HAVE_UERROR)
877 lookupname(path, USR, follow, NULL, &vp,
878 foreigncreds ? foreigncreds : credp);
880 #ifdef AFS_LINUX22_ENV
881 code = gop_lookupname(path, AFS_UIOUSER, follow, &dp);
883 vp = (struct vnode *)dp->d_inode;
885 code = gop_lookupname(path, AFS_UIOUSER, follow, &vp);
886 #endif /* AFS_LINUX22_ENV */
887 #endif /* AFS_AIX41_ENV */
891 #if defined(KERNEL_HAVE_UERROR)
899 #if defined(AFS_SUN510_ENV)
900 if (vp && !IsAfsVnode(vp)) {
901 struct vnode *realvp;
903 #ifdef AFS_SUN511_ENV
904 (VOP_REALVP(vp, &realvp, NULL) == 0)
906 (VOP_REALVP(vp, &realvp) == 0)
909 struct vnode *oldvp = vp;
917 /* now make the call if we were passed no file, or were passed an AFS file */
918 if (!vp || IsAfsVnode(vp)) {
919 #if defined(AFS_SUN5_ENV)
920 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
921 #elif defined(AFS_AIX41_ENV)
923 struct ucred *cred1, *cred2;
926 cred1 = cred2 = foreigncreds;
928 cred1 = cred2 = credp;
930 code = afs_HandlePioctl(vp, com, &data, follow, &cred1);
931 if (cred1 != cred2) {
932 /* something changed the creds */
936 #elif defined(AFS_HPUX101_ENV)
938 struct ucred *cred = p_cred(u.u_procp);
939 code = afs_HandlePioctl(vp, com, &data, follow, &cred);
941 #elif defined(AFS_SGI_ENV)
944 credp = OSI_GET_CURRENT_CRED();
945 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
947 #elif defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
948 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
950 code = afs_HandlePioctl(vp, com, &data, follow, &u.u_cred);
953 #if defined(KERNEL_HAVE_UERROR)
956 code = EINVAL; /* not in /afs */
961 #if defined(AFS_NEED_CLIENTCONTEXT)
964 crset(tmpcred); /* restore original credentials */
966 #if defined(AFS_HPUX101_ENV)
967 set_p_cred(u.u_procp, tmpcred); /* restore original credentials */
968 #elif defined(AFS_SGI_ENV)
969 OSI_SET_CURRENT_CRED(tmpcred); /* restore original credentials */
970 #elif defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
971 credp = tmpcred; /* restore original credentials */
973 osi_curcred() = tmpcred; /* restore original credentials */
974 #endif /* AFS_HPUX101_ENV */
975 crfree(foreigncreds);
978 #endif /* AFS_NEED_CLIENTCONTEXT */
980 #ifdef AFS_LINUX22_ENV
983 AFS_RELE(vp); /* put vnode back */
987 #if defined(KERNEL_HAVE_UERROR)
990 return (getuerror());
996 #define MAXPIOCTLTOKENLEN \
997 (3*sizeof(afs_int32)+MAXKTCTICKETLEN+sizeof(struct ClearToken)+MAXKTCREALMLEN)
1000 afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
1001 register struct afs_ioctl *ablob, int afollow,
1002 struct AFS_UCRED **acred)
1005 struct vrequest treq;
1006 register afs_int32 code;
1007 register afs_int32 function, device;
1008 afs_int32 inSize, outSize, outSizeMax;
1009 char *inData, *outData;
1010 int (*(*pioctlSw)) ();
1012 struct afs_fakestat_state fakestate;
1014 avc = avp ? VTOAFS(avp) : NULL;
1015 afs_Trace3(afs_iclSetp, CM_TRACE_PIOCTL, ICL_TYPE_INT32, acom & 0xff,
1016 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, afollow);
1017 AFS_STATCNT(HandlePioctl);
1018 if ((code = afs_InitReq(&treq, *acred)))
1020 afs_InitFakeStat(&fakestate);
1022 code = afs_EvalFakeStat(&avc, &fakestate, &treq);
1024 afs_PutFakeStat(&fakestate);
1028 device = (acom & 0xff00) >> 8;
1030 case 'V': /* Original pioctls */
1031 pioctlSw = VpioctlSw;
1032 pioctlSwSize = sizeof(VpioctlSw);
1034 case 'C': /* Coordinated/common pioctls */
1035 pioctlSw = CpioctlSw;
1036 pioctlSwSize = sizeof(CpioctlSw);
1038 case 'O': /* Coordinated/common pioctls */
1039 pioctlSw = OpioctlSw;
1040 pioctlSwSize = sizeof(OpioctlSw);
1043 afs_PutFakeStat(&fakestate);
1046 function = acom & 0xff;
1047 if (function >= (pioctlSwSize / sizeof(char *))) {
1048 afs_PutFakeStat(&fakestate);
1049 return EINVAL; /* out of range */
1051 inSize = ablob->in_size;
1053 /* Do all range checking before continuing */
1054 if (inSize > MAXPIOCTLTOKENLEN || inSize < 0 || ablob->out_size < 0)
1057 /* Note that we use osi_Alloc for large allocs and osi_AllocLargeSpace for small ones */
1058 if (inSize > AFS_LRALLOCSIZ) {
1059 inData = osi_Alloc(inSize + 1);
1061 inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1066 AFS_COPYIN(ablob->in, inData, inSize, code);
1067 inData[inSize] = '\0';
1071 if (inSize > AFS_LRALLOCSIZ) {
1072 osi_Free(inData, inSize + 1);
1074 osi_FreeLargeSpace(inData);
1076 afs_PutFakeStat(&fakestate);
1079 if (function == 8 && device == 'V') { /* PGetTokens */
1080 outSizeMax = MAXPIOCTLTOKENLEN;
1081 outData = osi_Alloc(outSizeMax);
1083 outSizeMax = AFS_LRALLOCSIZ;
1084 outData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1087 if (inSize > AFS_LRALLOCSIZ) {
1088 osi_Free(inData, inSize + 1);
1090 osi_FreeLargeSpace(inData);
1092 afs_PutFakeStat(&fakestate);
1097 (*pioctlSw[function]) (avc, function, &treq, inData, outData, inSize,
1099 if (inSize > AFS_LRALLOCSIZ) {
1100 osi_Free(inData, inSize + 1);
1102 osi_FreeLargeSpace(inData);
1104 if (code == 0 && ablob->out_size > 0) {
1105 if (outSize > ablob->out_size) {
1106 code = E2BIG; /* data wont fit in user buffer */
1107 } else if (outSize) {
1108 AFS_COPYOUT(outData, ablob->out, outSize, code);
1111 if (outSizeMax > AFS_LRALLOCSIZ) {
1112 osi_Free(outData, outSizeMax);
1114 osi_FreeLargeSpace(outData);
1116 afs_PutFakeStat(&fakestate);
1117 return afs_CheckCode(code, &treq, 41);
1120 DECL_PIOCTL(PGetFID)
1122 AFS_STATCNT(PGetFID);
1125 memcpy(aout, (char *)&avc->fid, sizeof(struct VenusFid));
1126 *aoutSize = sizeof(struct VenusFid);
1130 DECL_PIOCTL(PSetAcl)
1132 register afs_int32 code;
1134 struct AFSOpaque acl;
1135 struct AFSVolSync tsync;
1136 struct AFSFetchStatus OutStatus;
1139 AFS_STATCNT(PSetAcl);
1142 if ((acl.AFSOpaque_len = strlen(ain) + 1) > 1024 /* AFSOPAQUEMAX */)
1145 acl.AFSOpaque_val = ain;
1147 tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1149 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREACL);
1152 RXAFS_StoreACL(tconn->id, (struct AFSFid *)&avc->fid.Fid,
1153 &acl, &OutStatus, &tsync);
1158 } while (afs_Analyze
1159 (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_STOREACL,
1160 SHARED_LOCK, NULL));
1162 /* now we've forgotten all of the access info */
1163 ObtainWriteLock(&afs_xcbhash, 455);
1165 afs_DequeueCallback(avc);
1166 avc->states &= ~(CStatd | CUnique);
1167 ReleaseWriteLock(&afs_xcbhash);
1168 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
1169 osi_dnlc_purgedp(avc);
1173 int afs_defaultAsynchrony = 0;
1175 DECL_PIOCTL(PStoreBehind)
1178 struct sbstruct *sbr;
1180 sbr = (struct sbstruct *)ain;
1181 if (sbr->sb_default != -1) {
1182 if (afs_osi_suser(*acred))
1183 afs_defaultAsynchrony = sbr->sb_default;
1188 if (avc && (sbr->sb_thisfile != -1)) {
1190 (avc, PRSFS_WRITE | PRSFS_ADMINISTER, areq, DONT_CHECK_MODE_BITS))
1191 avc->asynchrony = sbr->sb_thisfile;
1196 *aoutSize = sizeof(struct sbstruct);
1197 sbr = (struct sbstruct *)aout;
1198 sbr->sb_default = afs_defaultAsynchrony;
1200 sbr->sb_thisfile = avc->asynchrony;
1206 DECL_PIOCTL(PGCPAGs)
1208 if (!afs_osi_suser(*acred)) {
1211 afs_gcpags = AFS_GCPAGS_USERDISABLED;
1215 DECL_PIOCTL(PGetAcl)
1217 struct AFSOpaque acl;
1218 struct AFSVolSync tsync;
1219 struct AFSFetchStatus OutStatus;
1225 AFS_STATCNT(PGetAcl);
1228 Fid.Volume = avc->fid.Fid.Volume;
1229 Fid.Vnode = avc->fid.Fid.Vnode;
1230 Fid.Unique = avc->fid.Fid.Unique;
1231 if (avc->states & CForeign) {
1233 * For a dfs xlator acl we have a special hack so that the
1234 * xlator will distinguish which type of acl will return. So
1235 * we currently use the top 2-bytes (vals 0-4) to tell which
1236 * type of acl to bring back. Horrible hack but this will
1237 * cause the least number of changes to code size and interfaces.
1239 if (Fid.Vnode & 0xc0000000)
1241 Fid.Vnode |= (ainSize << 30);
1243 acl.AFSOpaque_val = aout;
1245 tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1248 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHACL);
1250 code = RXAFS_FetchACL(tconn->id, &Fid, &acl, &OutStatus, &tsync);
1255 } while (afs_Analyze
1256 (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_FETCHACL,
1257 SHARED_LOCK, NULL));
1260 *aoutSize = (acl.AFSOpaque_len == 0 ? 1 : acl.AFSOpaque_len);
1273 AFS_STATCNT(PBogus);
1277 DECL_PIOCTL(PGetFileCell)
1279 register struct cell *tcell;
1281 AFS_STATCNT(PGetFileCell);
1284 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
1287 strcpy(aout, tcell->cellName);
1288 afs_PutCell(tcell, READ_LOCK);
1289 *aoutSize = strlen(aout) + 1;
1293 DECL_PIOCTL(PGetWSCell)
1295 struct cell *tcell = NULL;
1297 AFS_STATCNT(PGetWSCell);
1298 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1299 return EIO; /* Inappropriate ioctl for device */
1301 tcell = afs_GetPrimaryCell(READ_LOCK);
1302 if (!tcell) /* no primary cell? */
1304 strcpy(aout, tcell->cellName);
1305 *aoutSize = strlen(aout) + 1;
1306 afs_PutCell(tcell, READ_LOCK);
1310 DECL_PIOCTL(PGetUserCell)
1312 register afs_int32 i;
1313 register struct unixuser *tu;
1314 register struct cell *tcell;
1316 AFS_STATCNT(PGetUserCell);
1317 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1318 return EIO; /* Inappropriate ioctl for device */
1320 /* return the cell name of the primary cell for this user */
1321 i = UHash(areq->uid);
1322 ObtainWriteLock(&afs_xuser, 224);
1323 for (tu = afs_users[i]; tu; tu = tu->next) {
1324 if (tu->uid == areq->uid && (tu->states & UPrimary)) {
1326 ReleaseWriteLock(&afs_xuser);
1331 tcell = afs_GetCell(tu->cell, READ_LOCK);
1332 afs_PutUser(tu, WRITE_LOCK);
1336 strcpy(aout, tcell->cellName);
1337 afs_PutCell(tcell, READ_LOCK);
1338 *aoutSize = strlen(aout) + 1; /* 1 for the null */
1341 ReleaseWriteLock(&afs_xuser);
1348 DECL_PIOCTL(PSetTokens)
1351 register struct unixuser *tu;
1352 struct ClearToken clear;
1353 register struct cell *tcell;
1356 struct vrequest treq;
1357 afs_int32 flag, set_parent_pag = 0;
1359 AFS_STATCNT(PSetTokens);
1360 if (!afs_resourceinit_flag) {
1363 memcpy((char *)&i, ain, sizeof(afs_int32));
1364 ain += sizeof(afs_int32);
1365 stp = ain; /* remember where the ticket is */
1366 if (i < 0 || i > MAXKTCTICKETLEN)
1367 return EINVAL; /* malloc may fail */
1369 ain += i; /* skip over ticket */
1370 memcpy((char *)&i, ain, sizeof(afs_int32));
1371 ain += sizeof(afs_int32);
1372 if (i != sizeof(struct ClearToken)) {
1375 memcpy((char *)&clear, ain, sizeof(struct ClearToken));
1376 if (clear.AuthHandle == -1)
1377 clear.AuthHandle = 999; /* more rxvab compat stuff */
1378 ain += sizeof(struct ClearToken);
1379 if (ainSize != 2 * sizeof(afs_int32) + stLen + sizeof(struct ClearToken)) {
1380 /* still stuff left? we've got primary flag and cell name. Set these */
1381 memcpy((char *)&flag, ain, sizeof(afs_int32)); /* primary id flag */
1382 ain += sizeof(afs_int32); /* skip id field */
1383 /* rest is cell name, look it up */
1384 /* some versions of gcc appear to need != 0 in order to get this right */
1385 if ((flag & 0x8000) != 0) { /* XXX Use Constant XXX */
1389 tcell = afs_GetCellByName(ain, READ_LOCK);
1393 /* default to primary cell, primary id */
1394 flag = 1; /* primary id */
1395 tcell = afs_GetPrimaryCell(READ_LOCK);
1400 afs_PutCell(tcell, READ_LOCK);
1401 if (set_parent_pag) {
1403 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1404 #if defined(AFS_DARWIN_ENV)
1405 struct proc *p = current_proc(); /* XXX */
1407 struct proc *p = curproc; /* XXX */
1409 #ifndef AFS_DARWIN80_ENV
1410 uprintf("Process %d (%s) tried to change pags in PSetTokens\n",
1411 p->p_pid, p->p_comm);
1413 if (!setpag(p, acred, -1, &pag, 1)) {
1416 if (!setpag(u.u_procp, acred, -1, &pag, 1)) { /* XXX u.u_procp is a no-op XXX */
1418 if (!setpag(acred, -1, &pag, 1)) {
1421 afs_InitReq(&treq, *acred);
1425 /* now we just set the tokens */
1426 tu = afs_GetUser(areq->uid, i, WRITE_LOCK); /* i has the cell # */
1427 tu->vid = clear.ViceId;
1428 if (tu->stp != NULL) {
1429 afs_osi_Free(tu->stp, tu->stLen);
1431 tu->stp = (char *)afs_osi_Alloc(stLen);
1432 if (tu->stp == NULL) {
1436 memcpy(tu->stp, stp, stLen);
1439 afs_stats_cmfullperf.authent.TicketUpdates++;
1440 afs_ComputePAGStats();
1441 #endif /* AFS_NOSTATS */
1442 tu->states |= UHasTokens;
1443 tu->states &= ~UTokensBad;
1444 afs_SetPrimary(tu, flag);
1445 tu->tokenTime = osi_Time();
1446 afs_ResetUserConns(tu);
1447 afs_PutUser(tu, WRITE_LOCK);
1462 DECL_PIOCTL(PGetVolumeStatus)
1465 char *offLineMsg = afs_osi_Alloc(256);
1466 char *motd = afs_osi_Alloc(256);
1467 register struct conn *tc;
1468 register afs_int32 code = 0;
1469 struct AFSFetchVolumeStatus volstat;
1471 char *Name, *OfflineMsg, *MOTD;
1474 AFS_STATCNT(PGetVolumeStatus);
1480 OfflineMsg = offLineMsg;
1483 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1485 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS);
1488 RXAFS_GetVolumeStatus(tc->id, avc->fid.Fid.Volume, &volstat,
1489 &Name, &OfflineMsg, &MOTD);
1494 } while (afs_Analyze
1495 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS,
1496 SHARED_LOCK, NULL));
1500 /* Copy all this junk into msg->im_data, keeping track of the lengths. */
1502 memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
1503 cp += sizeof(VolumeStatus);
1504 strcpy(cp, volName);
1505 cp += strlen(volName) + 1;
1506 strcpy(cp, offLineMsg);
1507 cp += strlen(offLineMsg) + 1;
1509 cp += strlen(motd) + 1;
1510 *aoutSize = (cp - aout);
1512 afs_osi_Free(offLineMsg, 256);
1513 afs_osi_Free(motd, 256);
1517 DECL_PIOCTL(PSetVolumeStatus)
1520 char *offLineMsg = afs_osi_Alloc(256);
1521 char *motd = afs_osi_Alloc(256);
1522 register struct conn *tc;
1523 register afs_int32 code = 0;
1524 struct AFSFetchVolumeStatus volstat;
1525 struct AFSStoreVolumeStatus storeStat;
1526 register struct volume *tvp;
1530 AFS_STATCNT(PSetVolumeStatus);
1536 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
1538 if (tvp->states & (VRO | VBackup)) {
1539 afs_PutVolume(tvp, READ_LOCK);
1543 afs_PutVolume(tvp, READ_LOCK);
1548 /* Copy the junk out, using cp as a roving pointer. */
1550 memcpy((char *)&volstat, cp, sizeof(AFSFetchVolumeStatus));
1551 cp += sizeof(AFSFetchVolumeStatus);
1552 if (strlen(cp) >= sizeof(volName)) {
1556 strcpy(volName, cp);
1557 cp += strlen(volName) + 1;
1558 if (strlen(cp) >= sizeof(offLineMsg)) {
1562 strcpy(offLineMsg, cp);
1563 cp += strlen(offLineMsg) + 1;
1564 if (strlen(cp) >= sizeof(motd)) {
1570 if (volstat.MinQuota != -1) {
1571 storeStat.MinQuota = volstat.MinQuota;
1572 storeStat.Mask |= AFS_SETMINQUOTA;
1574 if (volstat.MaxQuota != -1) {
1575 storeStat.MaxQuota = volstat.MaxQuota;
1576 storeStat.Mask |= AFS_SETMAXQUOTA;
1579 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1581 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS);
1584 RXAFS_SetVolumeStatus(tc->id, avc->fid.Fid.Volume, &storeStat,
1585 volName, offLineMsg, motd);
1590 } while (afs_Analyze
1591 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS,
1592 SHARED_LOCK, NULL));
1596 /* we are sending parms back to make compat. with prev system. should
1597 * change interface later to not ask for current status, just set new status */
1599 memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
1600 cp += sizeof(VolumeStatus);
1601 strcpy(cp, volName);
1602 cp += strlen(volName) + 1;
1603 strcpy(cp, offLineMsg);
1604 cp += strlen(offLineMsg) + 1;
1606 cp += strlen(motd) + 1;
1607 *aoutSize = cp - aout;
1609 afs_osi_Free(offLineMsg, 256);
1610 afs_osi_Free(motd, 256);
1616 AFS_STATCNT(PFlush);
1619 #ifdef AFS_BOZONLOCK_ENV
1620 afs_BozonLock(&avc->pvnLock, avc); /* Since afs_TryToSmush will do a pvn_vptrunc */
1622 ObtainWriteLock(&avc->lock, 225);
1623 ObtainWriteLock(&afs_xcbhash, 456);
1624 afs_DequeueCallback(avc);
1625 avc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
1626 ReleaseWriteLock(&afs_xcbhash);
1627 /* now find the disk cache entries */
1628 afs_TryToSmush(avc, *acred, 1);
1629 osi_dnlc_purgedp(avc);
1630 if (avc->linkData && !(avc->states & CCore)) {
1631 afs_osi_Free(avc->linkData, strlen(avc->linkData) + 1);
1632 avc->linkData = NULL;
1634 ReleaseWriteLock(&avc->lock);
1635 #ifdef AFS_BOZONLOCK_ENV
1636 afs_BozonUnlock(&avc->pvnLock, avc);
1641 DECL_PIOCTL(PNewStatMount)
1643 register afs_int32 code;
1644 register struct vcache *tvc;
1645 register struct dcache *tdc;
1646 struct VenusFid tfid;
1648 struct sysname_info sysState;
1649 afs_size_t offset, len;
1651 AFS_STATCNT(PNewStatMount);
1654 code = afs_VerifyVCache(avc, areq);
1657 if (vType(avc) != VDIR) {
1660 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
1663 Check_AtSys(avc, ain, &sysState, areq);
1664 ObtainReadLock(&tdc->lock);
1666 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
1667 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
1668 ReleaseReadLock(&tdc->lock);
1669 afs_PutDCache(tdc); /* we're done with the data */
1670 bufp = sysState.name;
1674 tfid.Cell = avc->fid.Cell;
1675 tfid.Fid.Volume = avc->fid.Fid.Volume;
1676 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
1677 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
1679 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
1685 if (tvc->mvstat != 1) {
1690 ObtainWriteLock(&tvc->lock, 226);
1691 code = afs_HandleLink(tvc, areq);
1693 if (tvc->linkData) {
1694 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
1697 /* we have the data */
1698 strcpy(aout, tvc->linkData);
1699 *aoutSize = strlen(tvc->linkData) + 1;
1704 ReleaseWriteLock(&tvc->lock);
1707 if (sysState.allocked)
1708 osi_FreeLargeSpace(bufp);
1712 DECL_PIOCTL(PGetTokens)
1714 register struct cell *tcell;
1715 register afs_int32 i;
1716 register struct unixuser *tu;
1721 AFS_STATCNT(PGetTokens);
1722 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1723 return EIO; /* Inappropriate ioctl for device */
1725 /* weird interface. If input parameter is present, it is an integer and
1726 * we're supposed to return the parm'th tokens for this unix uid.
1727 * If not present, we just return tokens for cell 1.
1728 * If counter out of bounds, return EDOM.
1729 * If no tokens for the particular cell, return ENOTCONN.
1730 * Also, if this mysterious parm is present, we return, along with the
1731 * tokens, the primary cell indicator (an afs_int32 0) and the cell name
1732 * at the end, in that order.
1734 if ((newStyle = (ainSize > 0))) {
1735 memcpy((char *)&iterator, ain, sizeof(afs_int32));
1737 i = UHash(areq->uid);
1738 ObtainReadLock(&afs_xuser);
1739 for (tu = afs_users[i]; tu; tu = tu->next) {
1741 if (tu->uid == areq->uid && (tu->states & UHasTokens)) {
1742 if (iterator-- == 0)
1743 break; /* are we done yet? */
1746 if (tu->uid == areq->uid && afs_IsPrimaryCellNum(tu->cell))
1752 * No need to hold a read lock on each user entry
1756 ReleaseReadLock(&afs_xuser);
1761 if (((tu->states & UHasTokens) == 0)
1762 || (tu->ct.EndTimestamp < osi_Time())) {
1763 tu->states |= (UTokensBad | UNeedsReset);
1764 afs_PutUser(tu, READ_LOCK);
1767 /* use iterator for temp */
1769 iterator = tu->stLen; /* for compat, we try to return 56 byte tix if they fit */
1771 iterator = 56; /* # of bytes we're returning */
1772 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1773 cp += sizeof(afs_int32);
1774 memcpy(cp, tu->stp, tu->stLen); /* copy out st */
1776 iterator = sizeof(struct ClearToken);
1777 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1778 cp += sizeof(afs_int32);
1779 memcpy(cp, (char *)&tu->ct, sizeof(struct ClearToken));
1780 cp += sizeof(struct ClearToken);
1782 /* put out primary id and cell name, too */
1783 iterator = (tu->states & UPrimary ? 1 : 0);
1784 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1785 cp += sizeof(afs_int32);
1786 tcell = afs_GetCell(tu->cell, READ_LOCK);
1788 strcpy(cp, tcell->cellName);
1789 cp += strlen(tcell->cellName) + 1;
1790 afs_PutCell(tcell, READ_LOCK);
1794 *aoutSize = cp - aout;
1795 afs_PutUser(tu, READ_LOCK);
1801 register afs_int32 i;
1802 register struct unixuser *tu;
1804 AFS_STATCNT(PUnlog);
1805 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1806 return EIO; /* Inappropriate ioctl for device */
1808 i = UHash(areq->uid);
1809 ObtainWriteLock(&afs_xuser, 227);
1810 for (tu = afs_users[i]; tu; tu = tu->next) {
1811 if (tu->uid == areq->uid) {
1813 tu->states &= ~UHasTokens;
1814 /* security is not having to say you're sorry */
1815 memset((char *)&tu->ct, 0, sizeof(struct ClearToken));
1817 ReleaseWriteLock(&afs_xuser);
1818 /* We have to drop the lock over the call to afs_ResetUserConns, since
1819 * it obtains the afs_xvcache lock. We could also keep the lock, and
1820 * modify ResetUserConns to take parm saying we obtained the lock
1821 * already, but that is overkill. By keeping the "tu" pointer
1822 * held over the released lock, we guarantee that we won't lose our
1823 * place, and that we'll pass over every user conn that existed when
1824 * we began this call.
1826 afs_ResetUserConns(tu);
1828 ObtainWriteLock(&afs_xuser, 228);
1830 /* set the expire times to 0, causes
1831 * afs_GCUserData to remove this entry
1833 tu->ct.EndTimestamp = 0;
1835 #endif /* UKERNEL */
1838 ReleaseWriteLock(&afs_xuser);
1842 DECL_PIOCTL(PMariner)
1844 afs_int32 newHostAddr;
1845 afs_int32 oldHostAddr;
1847 AFS_STATCNT(PMariner);
1849 memcpy((char *)&oldHostAddr, (char *)&afs_marinerHost,
1852 oldHostAddr = 0xffffffff; /* disabled */
1854 memcpy((char *)&newHostAddr, ain, sizeof(afs_int32));
1855 if (newHostAddr == 0xffffffff) {
1856 /* disable mariner operations */
1858 } else if (newHostAddr) {
1860 afs_marinerHost = newHostAddr;
1862 memcpy(aout, (char *)&oldHostAddr, sizeof(afs_int32));
1863 *aoutSize = sizeof(afs_int32);
1867 DECL_PIOCTL(PCheckServers)
1869 register char *cp = 0;
1871 register struct server *ts;
1872 afs_int32 temp, *lp = (afs_int32 *) ain, havecell = 0;
1874 struct chservinfo *pcheck;
1876 AFS_STATCNT(PCheckServers);
1878 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1879 return EIO; /* Inappropriate ioctl for device */
1881 if (*lp == 0x12345678) { /* For afs3.3 version */
1882 pcheck = (struct chservinfo *)ain;
1883 if (pcheck->tinterval >= 0) {
1885 memcpy(cp, (char *)&afs_probe_interval, sizeof(afs_int32));
1886 *aoutSize = sizeof(afs_int32);
1887 if (pcheck->tinterval > 0) {
1888 if (!afs_osi_suser(*acred))
1890 afs_probe_interval = pcheck->tinterval;
1896 temp = pcheck->tflags;
1897 cp = pcheck->tbuffer;
1898 } else { /* For pre afs3.3 versions */
1899 memcpy((char *)&temp, ain, sizeof(afs_int32));
1900 cp = ain + sizeof(afs_int32);
1901 if (ainSize > sizeof(afs_int32))
1906 * 1: fast check, don't contact servers.
1907 * 2: local cell only.
1910 /* have cell name, too */
1911 cellp = afs_GetCellByName(cp, READ_LOCK);
1916 if (!cellp && (temp & 2)) {
1917 /* use local cell */
1918 cellp = afs_GetPrimaryCell(READ_LOCK);
1920 if (!(temp & 1)) { /* if not fast, call server checker routine */
1921 afs_CheckServers(1, cellp); /* check down servers */
1922 afs_CheckServers(0, cellp); /* check up servers */
1924 /* now return the current down server list */
1926 ObtainReadLock(&afs_xserver);
1927 for (i = 0; i < NSERVERS; i++) {
1928 for (ts = afs_servers[i]; ts; ts = ts->next) {
1929 if (cellp && ts->cell != cellp)
1930 continue; /* cell spec'd and wrong */
1931 if ((ts->flags & SRVR_ISDOWN)
1932 && ts->addr->sa_portal != ts->cell->vlport) {
1933 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
1934 cp += sizeof(afs_int32);
1938 ReleaseReadLock(&afs_xserver);
1940 afs_PutCell(cellp, READ_LOCK);
1941 *aoutSize = cp - aout;
1945 DECL_PIOCTL(PCheckVolNames)
1947 AFS_STATCNT(PCheckVolNames);
1948 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1949 return EIO; /* Inappropriate ioctl for device */
1951 afs_CheckRootVolume();
1952 afs_CheckVolumeNames(AFS_VOLCHECK_FORCE | AFS_VOLCHECK_EXPIRED |
1953 AFS_VOLCHECK_BUSY | AFS_VOLCHECK_MTPTS);
1957 DECL_PIOCTL(PCheckAuth)
1962 struct unixuser *tu;
1965 AFS_STATCNT(PCheckAuth);
1966 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1967 return EIO; /* Inappropriate ioctl for device */
1970 tu = afs_GetUser(areq->uid, 1, READ_LOCK); /* check local cell authentication */
1974 /* we have a user */
1975 ObtainReadLock(&afs_xsrvAddr);
1976 ObtainReadLock(&afs_xconn);
1978 /* any tokens set? */
1979 if ((tu->states & UHasTokens) == 0)
1981 /* all connections in cell 1 working? */
1982 for (i = 0; i < NSERVERS; i++) {
1983 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
1984 for (tc = sa->conns; tc; tc = tc->next) {
1985 if (tc->user == tu && (tu->states & UTokensBad))
1990 ReleaseReadLock(&afs_xsrvAddr);
1991 ReleaseReadLock(&afs_xconn);
1992 afs_PutUser(tu, READ_LOCK);
1994 memcpy(aout, (char *)&retValue, sizeof(afs_int32));
1995 *aoutSize = sizeof(afs_int32);
2000 Prefetch(char *apath, struct afs_ioctl *adata, int afollow,
2001 struct AFS_UCRED *acred)
2004 register afs_int32 code;
2005 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2011 AFS_STATCNT(Prefetch);
2014 tp = osi_AllocLargeSpace(1024);
2015 AFS_COPYINSTR(apath, tp, 1024, &bufferSize, code);
2017 osi_FreeLargeSpace(tp);
2020 if (afs_BBusy()) { /* do this as late as possible */
2021 osi_FreeLargeSpace(tp);
2022 return EWOULDBLOCK; /* pretty close */
2024 afs_BQueue(BOP_PATH, (struct vcache *)0, 0, 0, acred, (afs_size_t) 0,
2025 (afs_size_t) 0, tp);
2029 DECL_PIOCTL(PFindVolume)
2031 register struct volume *tvp;
2032 register struct server *ts;
2033 register afs_int32 i;
2036 AFS_STATCNT(PFindVolume);
2039 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
2042 for (i = 0; i < MAXHOSTS; i++) {
2043 ts = tvp->serverHost[i];
2046 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
2047 cp += sizeof(afs_int32);
2050 /* still room for terminating NULL, add it on */
2051 ainSize = 0; /* reuse vbl */
2052 memcpy(cp, (char *)&ainSize, sizeof(afs_int32));
2053 cp += sizeof(afs_int32);
2055 *aoutSize = cp - aout;
2056 afs_PutVolume(tvp, READ_LOCK);
2062 DECL_PIOCTL(PViceAccess)
2064 register afs_int32 code;
2067 AFS_STATCNT(PViceAccess);
2070 code = afs_VerifyVCache(avc, areq);
2073 memcpy((char *)&temp, ain, sizeof(afs_int32));
2074 code = afs_AccessOK(avc, temp, areq, CHECK_MODE_BITS);
2081 DECL_PIOCTL(PPrecache)
2085 /*AFS_STATCNT(PPrecache);*/
2086 if (!afs_osi_suser(*acred))
2088 memcpy((char *)&newValue, ain, sizeof(afs_int32));
2089 afs_preCache = newValue*1024;
2093 DECL_PIOCTL(PSetCacheSize)
2098 AFS_STATCNT(PSetCacheSize);
2099 if (!afs_osi_suser(*acred))
2101 /* too many things are setup initially in mem cache version */
2102 if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
2104 memcpy((char *)&newValue, ain, sizeof(afs_int32));
2106 afs_cacheBlocks = afs_stats_cmperf.cacheBlocksOrig;
2108 if (newValue < afs_min_cache)
2109 afs_cacheBlocks = afs_min_cache;
2111 afs_cacheBlocks = newValue;
2113 afs_stats_cmperf.cacheBlocksTotal = afs_cacheBlocks;
2114 afs_ComputeCacheParms(); /* recompute basic cache parameters */
2115 afs_MaybeWakeupTruncateDaemon();
2116 while (waitcnt++ < 100 && afs_cacheBlocks < afs_blocksUsed) {
2117 afs_osi_Wait(1000, 0, 0);
2118 afs_MaybeWakeupTruncateDaemon();
2123 #define MAXGCSTATS 16
2124 DECL_PIOCTL(PGetCacheSize)
2126 afs_int32 results[MAXGCSTATS];
2128 register struct dcache * tdc;
2131 AFS_STATCNT(PGetCacheSize);
2133 if (sizeof(afs_int32) == ainSize){
2134 memcpy((char *)&flags, ain, sizeof(afs_int32));
2135 } else if (0 == ainSize){
2141 memset((char *)results, 0, sizeof(results));
2142 results[0] = afs_cacheBlocks;
2143 results[1] = afs_blocksUsed;
2144 results[2] = afs_cacheFiles;
2147 for (i = 0; i < afs_cacheFiles; i++) {
2148 if (afs_indexFlags[i] & IFFree) results[3]++;
2150 } else if (2 == flags){
2151 for (i = 0; i < afs_cacheFiles; i++) {
2152 if (afs_indexFlags[i] & IFFree) results[3]++;
2153 if (afs_indexFlags[i] & IFEverUsed) results[4]++;
2154 if (afs_indexFlags[i] & IFDataMod) results[5]++;
2155 if (afs_indexFlags[i] & IFDirtyPages) results[6]++;
2156 if (afs_indexFlags[i] & IFAnyPages) results[7]++;
2157 if (afs_indexFlags[i] & IFDiscarded) results[8]++;
2159 tdc = afs_indexTable[i];
2162 size = tdc->validPos;
2163 if ( 0 < size && size < (1<<12) ) results[10]++;
2164 else if (size < (1<<14) ) results[11]++;
2165 else if (size < (1<<16) ) results[12]++;
2166 else if (size < (1<<18) ) results[13]++;
2167 else if (size < (1<<20) ) results[14]++;
2168 else if (size >= (1<<20) ) results[15]++;
2172 memcpy(aout, (char *)results, sizeof(results));
2173 *aoutSize = sizeof(results);
2177 DECL_PIOCTL(PRemoveCallBack)
2179 register struct conn *tc;
2180 register afs_int32 code = 0;
2181 struct AFSCallBack CallBacks_Array[1];
2182 struct AFSCBFids theFids;
2183 struct AFSCBs theCBs;
2186 AFS_STATCNT(PRemoveCallBack);
2189 if (avc->states & CRO)
2190 return 0; /* read-only-ness can't change */
2191 ObtainWriteLock(&avc->lock, 229);
2192 theFids.AFSCBFids_len = 1;
2193 theCBs.AFSCBs_len = 1;
2194 theFids.AFSCBFids_val = (struct AFSFid *)&avc->fid.Fid;
2195 theCBs.AFSCBs_val = CallBacks_Array;
2196 CallBacks_Array[0].CallBackType = CB_DROPPED;
2197 if (avc->callback) {
2199 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2201 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
2203 code = RXAFS_GiveUpCallBacks(tc->id, &theFids, &theCBs);
2207 /* don't set code on failure since we wouldn't use it */
2208 } while (afs_Analyze
2209 (tc, code, &avc->fid, areq,
2210 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK, NULL));
2212 ObtainWriteLock(&afs_xcbhash, 457);
2213 afs_DequeueCallback(avc);
2215 avc->states &= ~(CStatd | CUnique);
2216 ReleaseWriteLock(&afs_xcbhash);
2217 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
2218 osi_dnlc_purgedp(avc);
2220 ReleaseWriteLock(&avc->lock);
2224 DECL_PIOCTL(PNewCell)
2226 /* create a new cell */
2227 afs_int32 cellHosts[MAXCELLHOSTS], *lp, magic = 0;
2228 char *newcell = 0, *linkedcell = 0, *tp = ain;
2229 register afs_int32 code, linkedstate = 0, ls;
2230 u_short fsport = 0, vlport = 0;
2233 AFS_STATCNT(PNewCell);
2234 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2235 return EIO; /* Inappropriate ioctl for device */
2237 if (!afs_osi_suser(*acred))
2240 memcpy((char *)&magic, tp, sizeof(afs_int32));
2241 tp += sizeof(afs_int32);
2242 if (magic != 0x12345678)
2245 /* A 3.4 fs newcell command will pass an array of MAXCELLHOSTS
2246 * server addresses while the 3.5 fs newcell command passes
2247 * MAXHOSTS. To figure out which is which, check if the cellname
2250 newcell = tp + (MAXCELLHOSTS + 3) * sizeof(afs_int32);
2251 scount = ((newcell[0] != '\0') ? MAXCELLHOSTS : MAXHOSTS);
2253 /* MAXCELLHOSTS (=8) is less than MAXHOSTS (=13) */
2254 memcpy((char *)cellHosts, tp, MAXCELLHOSTS * sizeof(afs_int32));
2255 tp += (scount * sizeof(afs_int32));
2257 lp = (afs_int32 *) tp;
2261 fsport = 0; /* Privileged ports not allowed */
2263 vlport = 0; /* Privileged ports not allowed */
2264 tp += (3 * sizeof(afs_int32));
2266 if ((ls = *lp) & 1) {
2267 linkedcell = tp + strlen(newcell) + 1;
2268 linkedstate |= CLinkedCell;
2271 linkedstate |= CNoSUID; /* setuid is disabled by default for fs newcell */
2273 afs_NewCell(newcell, cellHosts, linkedstate, linkedcell, fsport,
2278 DECL_PIOCTL(PNewAlias)
2280 /* create a new cell alias */
2282 register afs_int32 code;
2283 char *realName, *aliasName;
2285 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2286 return EIO; /* Inappropriate ioctl for device */
2288 if (!afs_osi_suser(*acred))
2292 tp += strlen(aliasName) + 1;
2295 code = afs_NewCellAlias(aliasName, realName);
2300 DECL_PIOCTL(PListCells)
2302 afs_int32 whichCell;
2303 register struct cell *tcell = 0;
2304 register afs_int32 i;
2305 register char *cp, *tp = ain;
2307 AFS_STATCNT(PListCells);
2308 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2309 return EIO; /* Inappropriate ioctl for device */
2311 memcpy((char *)&whichCell, tp, sizeof(afs_int32));
2312 tp += sizeof(afs_int32);
2313 tcell = afs_GetCellByIndex(whichCell, READ_LOCK);
2316 memset(cp, 0, MAXCELLHOSTS * sizeof(afs_int32));
2317 for (i = 0; i < MAXCELLHOSTS; i++) {
2318 if (tcell->cellHosts[i] == 0)
2320 memcpy(cp, (char *)&tcell->cellHosts[i]->addr->sa_ip,
2322 cp += sizeof(afs_int32);
2324 cp = aout + MAXCELLHOSTS * sizeof(afs_int32);
2325 strcpy(cp, tcell->cellName);
2326 cp += strlen(tcell->cellName) + 1;
2327 *aoutSize = cp - aout;
2328 afs_PutCell(tcell, READ_LOCK);
2336 DECL_PIOCTL(PListAliases)
2338 afs_int32 whichAlias;
2339 register struct cell_alias *tcalias = 0;
2340 register char *cp, *tp = ain;
2342 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2343 return EIO; /* Inappropriate ioctl for device */
2344 if (ainSize < sizeof(afs_int32))
2347 memcpy((char *)&whichAlias, tp, sizeof(afs_int32));
2348 tp += sizeof(afs_int32);
2350 tcalias = afs_GetCellAlias(whichAlias);
2353 strcpy(cp, tcalias->alias);
2354 cp += strlen(tcalias->alias) + 1;
2355 strcpy(cp, tcalias->cell);
2356 cp += strlen(tcalias->cell) + 1;
2357 *aoutSize = cp - aout;
2358 afs_PutCellAlias(tcalias);
2366 DECL_PIOCTL(PRemoveMount)
2368 register afs_int32 code;
2370 struct sysname_info sysState;
2371 afs_size_t offset, len;
2372 register struct conn *tc;
2373 register struct dcache *tdc;
2374 register struct vcache *tvc;
2375 struct AFSFetchStatus OutDirStatus;
2376 struct VenusFid tfid;
2377 struct AFSVolSync tsync;
2381 /* "ain" is the name of the file in this dir to remove */
2383 AFS_STATCNT(PRemoveMount);
2386 code = afs_VerifyVCache(avc, areq);
2389 if (vType(avc) != VDIR)
2392 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1); /* test for error below */
2395 Check_AtSys(avc, ain, &sysState, areq);
2396 ObtainReadLock(&tdc->lock);
2398 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
2399 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
2400 ReleaseReadLock(&tdc->lock);
2401 bufp = sysState.name;
2406 tfid.Cell = avc->fid.Cell;
2407 tfid.Fid.Volume = avc->fid.Fid.Volume;
2408 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
2409 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
2411 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
2418 if (tvc->mvstat != 1) {
2424 ObtainWriteLock(&tvc->lock, 230);
2425 code = afs_HandleLink(tvc, areq);
2427 if (tvc->linkData) {
2428 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
2433 ReleaseWriteLock(&tvc->lock);
2434 osi_dnlc_purgedp(tvc);
2440 ObtainWriteLock(&avc->lock, 231);
2441 osi_dnlc_remove(avc, bufp, tvc);
2443 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2445 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE);
2448 RXAFS_RemoveFile(tc->id, (struct AFSFid *)&avc->fid.Fid, bufp,
2449 &OutDirStatus, &tsync);
2454 } while (afs_Analyze
2455 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_REMOVEFILE,
2456 SHARED_LOCK, NULL));
2461 ReleaseWriteLock(&avc->lock);
2465 /* we have the thing in the cache */
2466 ObtainWriteLock(&tdc->lock, 661);
2467 if (afs_LocalHero(avc, tdc, &OutDirStatus, 1)) {
2468 /* we can do it locally */
2469 code = afs_dir_Delete(tdc, bufp);
2471 ZapDCE(tdc); /* surprise error -- invalid value */
2475 ReleaseWriteLock(&tdc->lock);
2476 afs_PutDCache(tdc); /* drop ref count */
2478 avc->states &= ~CUnique; /* For the dfs xlator */
2479 ReleaseWriteLock(&avc->lock);
2482 if (sysState.allocked)
2483 osi_FreeLargeSpace(bufp);
2487 DECL_PIOCTL(PVenusLogging)
2489 return EINVAL; /* OBSOLETE */
2492 DECL_PIOCTL(PGetCellStatus)
2494 register struct cell *tcell;
2497 AFS_STATCNT(PGetCellStatus);
2498 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2499 return EIO; /* Inappropriate ioctl for device */
2501 tcell = afs_GetCellByName(ain, READ_LOCK);
2504 temp = tcell->states;
2505 afs_PutCell(tcell, READ_LOCK);
2506 memcpy(aout, (char *)&temp, sizeof(afs_int32));
2507 *aoutSize = sizeof(afs_int32);
2511 DECL_PIOCTL(PSetCellStatus)
2513 register struct cell *tcell;
2516 if (!afs_osi_suser(*acred))
2518 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2519 return EIO; /* Inappropriate ioctl for device */
2521 tcell = afs_GetCellByName(ain + 2 * sizeof(afs_int32), WRITE_LOCK);
2524 memcpy((char *)&temp, ain, sizeof(afs_int32));
2526 tcell->states |= CNoSUID;
2528 tcell->states &= ~CNoSUID;
2529 afs_PutCell(tcell, WRITE_LOCK);
2533 DECL_PIOCTL(PFlushVolumeData)
2535 register afs_int32 i;
2536 register struct dcache *tdc;
2537 register struct vcache *tvc;
2538 register struct volume *tv;
2539 afs_int32 cell, volume;
2540 struct afs_q *tq, *uq;
2541 #ifdef AFS_DARWIN80_ENV
2545 AFS_STATCNT(PFlushVolumeData);
2548 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2549 return EIO; /* Inappropriate ioctl for device */
2551 volume = avc->fid.Fid.Volume; /* who to zap */
2552 cell = avc->fid.Cell;
2555 * Clear stat'd flag from all vnodes from this volume; this will invalidate all
2556 * the vcaches associated with the volume.
2559 ObtainReadLock(&afs_xvcache);
2560 i = VCHashV(&avc->fid);
2561 for (tq = afs_vhashTV[i].prev; tq != &afs_vhashTV[i]; tq = uq) {
2564 if (tvc->fid.Fid.Volume == volume && tvc->fid.Cell == cell) {
2565 if (tvc->states & CVInit) {
2566 ReleaseReadLock(&afs_xvcache);
2567 afs_osi_Sleep(&tvc->states);
2570 #ifdef AFS_DARWIN80_ENV
2571 if (tvc->states & CDeadVnode) {
2572 ReleaseReadLock(&afs_xvcache);
2573 afs_osi_Sleep(&tvc->states);
2577 #if defined(AFS_SGI_ENV) || defined(AFS_OSF_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
2578 VN_HOLD(AFSTOV(tvc));
2580 #ifdef AFS_DARWIN80_ENV
2584 if (vnode_ref(vp)) {
2591 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2594 VREFCOUNT_INC(tvc); /* AIX, apparently */
2598 ReleaseReadLock(&afs_xvcache);
2599 #ifdef AFS_BOZONLOCK_ENV
2600 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
2602 ObtainWriteLock(&tvc->lock, 232);
2604 ObtainWriteLock(&afs_xcbhash, 458);
2605 afs_DequeueCallback(tvc);
2606 tvc->states &= ~(CStatd | CDirty);
2607 ReleaseWriteLock(&afs_xcbhash);
2608 if (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
2609 osi_dnlc_purgedp(tvc);
2610 afs_TryToSmush(tvc, *acred, 1);
2611 ReleaseWriteLock(&tvc->lock);
2612 #ifdef AFS_BOZONLOCK_ENV
2613 afs_BozonUnlock(&tvc->pvnLock, tvc);
2615 #ifdef AFS_DARWIN80_ENV
2616 vnode_put(AFSTOV(tvc));
2618 ObtainReadLock(&afs_xvcache);
2620 /* our tvc ptr is still good until now */
2624 ReleaseReadLock(&afs_xvcache);
2627 MObtainWriteLock(&afs_xdcache, 328); /* needed if you're going to flush any stuff */
2628 for (i = 0; i < afs_cacheFiles; i++) {
2629 if (!(afs_indexFlags[i] & IFEverUsed))
2630 continue; /* never had any data */
2631 tdc = afs_GetDSlot(i, NULL);
2632 if (tdc->refCount <= 1) { /* too high, in use by running sys call */
2633 ReleaseReadLock(&tdc->tlock);
2634 if (tdc->f.fid.Fid.Volume == volume && tdc->f.fid.Cell == cell) {
2635 if (!(afs_indexFlags[i] & IFDataMod)) {
2636 /* if the file is modified, but has a ref cnt of only 1, then
2637 * someone probably has the file open and is writing into it.
2638 * Better to skip flushing such a file, it will be brought back
2639 * immediately on the next write anyway.
2641 * If we *must* flush, then this code has to be rearranged to call
2642 * afs_storeAllSegments() first */
2643 afs_FlushDCache(tdc);
2647 ReleaseReadLock(&tdc->tlock);
2649 afs_PutDCache(tdc); /* bumped by getdslot */
2651 MReleaseWriteLock(&afs_xdcache);
2653 ObtainReadLock(&afs_xvolume);
2654 for (i = 0; i < NVOLS; i++) {
2655 for (tv = afs_volumes[i]; tv; tv = tv->next) {
2656 if (tv->volume == volume) {
2657 afs_ResetVolumeInfo(tv);
2662 ReleaseReadLock(&afs_xvolume);
2664 /* probably, a user is doing this, probably, because things are screwed up.
2665 * maybe it's the dnlc's fault? */
2672 DECL_PIOCTL(PGetVnodeXStatus)
2674 register afs_int32 code;
2675 struct vcxstat stat;
2678 /* AFS_STATCNT(PGetVnodeXStatus); */
2681 code = afs_VerifyVCache(avc, areq);
2684 if (vType(avc) == VDIR)
2685 mode = PRSFS_LOOKUP;
2688 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
2691 memset(&stat, 0, sizeof(struct vcxstat));
2692 stat.fid = avc->fid;
2693 hset32(stat.DataVersion, hgetlo(avc->m.DataVersion));
2694 stat.lock = avc->lock;
2695 stat.parentVnode = avc->parentVnode;
2696 stat.parentUnique = avc->parentUnique;
2697 hset(stat.flushDV, avc->flushDV);
2698 hset(stat.mapDV, avc->mapDV);
2699 stat.truncPos = avc->truncPos;
2700 { /* just grab the first two - won't break anything... */
2701 struct axscache *ac;
2703 for (i = 0, ac = avc->Access; ac && i < CPSIZE; i++, ac = ac->next) {
2704 stat.randomUid[i] = ac->uid;
2705 stat.randomAccess[i] = ac->axess;
2708 stat.callback = afs_data_pointer_to_int32(avc->callback);
2709 stat.cbExpires = avc->cbExpires;
2710 stat.anyAccess = avc->anyAccess;
2711 stat.opens = avc->opens;
2712 stat.execsOrWriters = avc->execsOrWriters;
2713 stat.flockCount = avc->flockCount;
2714 stat.mvstat = avc->mvstat;
2715 stat.states = avc->states;
2716 memcpy(aout, (char *)&stat, sizeof(struct vcxstat));
2717 *aoutSize = sizeof(struct vcxstat);
2722 DECL_PIOCTL(PGetVnodeXStatus2)
2724 register afs_int32 code;
2725 struct vcxstat2 stat;
2730 code = afs_VerifyVCache(avc, areq);
2733 if (vType(avc) == VDIR)
2734 mode = PRSFS_LOOKUP;
2737 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
2740 memset(&stat, 0, sizeof(struct vcxstat2));
2742 stat.cbExpires = avc->cbExpires;
2743 stat.anyAccess = avc->anyAccess;
2744 stat.mvstat = avc->mvstat;
2745 stat.callerAccess = afs_GetAccessBits(avc, ~0, areq);
2747 memcpy(aout, (char *)&stat, sizeof(struct vcxstat2));
2748 *aoutSize = sizeof(struct vcxstat2);
2752 /* We require root for local sysname changes, but not for remote */
2753 /* (since we don't really believe remote uids anyway) */
2754 /* outname[] shouldn't really be needed- this is left as an excercise */
2755 /* for the reader. */
2756 DECL_PIOCTL(PSetSysName)
2758 char *cp, *cp2 = NULL, inname[MAXSYSNAME], outname[MAXSYSNAME];
2759 afs_int32 setsysname;
2761 register struct afs_exporter *exporter;
2762 register struct unixuser *au;
2763 register afs_int32 pag, error;
2764 int t, count, num = 0, allpags = 0;
2767 AFS_STATCNT(PSetSysName);
2768 if (!afs_globalVFS) {
2769 /* Afsd is NOT running; disable it */
2770 #if defined(KERNEL_HAVE_UERROR)
2771 return (setuerror(EINVAL), EINVAL);
2776 memset(inname, 0, MAXSYSNAME);
2777 memcpy(&setsysname, ain, sizeof(afs_int32));
2778 ain += sizeof(afs_int32);
2779 if (setsysname & 0x8000) {
2781 setsysname &= ~0x8000;
2786 if (setsysname < 0 || setsysname > MAXNUMSYSNAMES)
2789 for (cp = ain, count = 0; count < setsysname; count++) {
2790 /* won't go past end of ain since maxsysname*num < ain length */
2792 if (t >= MAXSYSNAME || t <= 0)
2794 /* check for names that can shoot us in the foot */
2795 if (*cp == '.' && (cp[1] == 0 || (cp[1] == '.' && cp[2] == 0)))
2801 /* inname gets first entry in case we're being a translator */
2803 memcpy(inname, ain, t + 1); /* include terminating null */
2807 if ((*acred)->cr_gid == RMTUSER_REQ ||
2808 (*acred)->cr_gid == RMTUSER_REQ_PRIV) { /* Handles all exporters */
2809 if (allpags && (*acred)->cr_gid != RMTUSER_REQ_PRIV) {
2812 pag = PagInCred(*acred);
2814 return EINVAL; /* Better than panicing */
2816 if (!(au = afs_FindUser(pag, -1, READ_LOCK))) {
2817 return EINVAL; /* Better than panicing */
2819 if (!(exporter = au->exporter)) {
2820 afs_PutUser(au, READ_LOCK);
2821 return EINVAL; /* Better than panicing */
2823 error = EXP_SYSNAME(exporter, (setsysname ? cp2 : NULL), &sysnamelist,
2826 if (error == ENODEV)
2827 foundname = 0; /* sysname not set yet! */
2829 afs_PutUser(au, READ_LOCK);
2834 strcpy(outname, sysnamelist[0]);
2836 afs_PutUser(au, READ_LOCK);
2840 /* Not xlating, so local case */
2842 osi_Panic("PSetSysName: !afs_sysname\n");
2843 if (!setsysname) { /* user just wants the info */
2844 strcpy(outname, afs_sysname);
2845 foundname = afs_sysnamecount;
2846 sysnamelist = afs_sysnamelist;
2847 } else { /* Local guy; only root can change sysname */
2848 if (!afs_osi_suser(*acred))
2851 /* allpags makes no sense for local use */
2855 /* clear @sys entries from the dnlc, once afs_lookup can
2856 * do lookups of @sys entries and thinks it can trust them */
2857 /* privs ok, store the entry, ... */
2858 strcpy(afs_sysname, inname);
2859 if (setsysname > 1) { /* ... or list */
2861 for (count = 1; count < setsysname; ++count) {
2862 if (!afs_sysnamelist[count])
2864 ("PSetSysName: no afs_sysnamelist entry to write\n");
2866 memcpy(afs_sysnamelist[count], cp, t + 1); /* include null */
2870 afs_sysnamecount = setsysname;
2875 cp = aout; /* not changing so report back the count and ... */
2876 memcpy(cp, (char *)&foundname, sizeof(afs_int32));
2877 cp += sizeof(afs_int32);
2879 strcpy(cp, outname); /* ... the entry, ... */
2880 cp += strlen(outname) + 1;
2881 for (count = 1; count < foundname; ++count) { /* ... or list. */
2882 if (!sysnamelist[count])
2884 ("PSetSysName: no afs_sysnamelist entry to read\n");
2885 t = strlen(sysnamelist[count]);
2886 if (t >= MAXSYSNAME)
2887 osi_Panic("PSetSysName: sysname entry garbled\n");
2888 strcpy(cp, sysnamelist[count]);
2892 *aoutSize = cp - aout;
2897 /* sequential search through the list of touched cells is not a good
2898 * long-term solution here. For small n, though, it should be just
2899 * fine. Should consider special-casing the local cell for large n.
2900 * Likewise for PSetSPrefs.
2902 * s - number of ids in array l[] -- NOT index of last id
2903 * l - array of cell ids which have volumes that need to be sorted
2904 * vlonly - sort vl servers or file servers?
2907 ReSortCells_cb(struct cell *cell, void *arg)
2909 afs_int32 *p = (afs_int32 *) arg;
2910 afs_int32 *l = p + 1;
2913 for (i = 0; i < s; i++) {
2914 if (l[i] == cell->cellNum) {
2915 ObtainWriteLock(&cell->lock, 690);
2916 afs_SortServers(cell->cellHosts, MAXCELLHOSTS);
2917 ReleaseWriteLock(&cell->lock);
2925 ReSortCells(int s, afs_int32 * l, int vlonly)
2933 p = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * (s + 1));
2935 memcpy(p + 1, l, s * sizeof(afs_int32));
2936 afs_TraverseCells(&ReSortCells_cb, p);
2937 afs_osi_Free(p, sizeof(afs_int32) * (s + 1));
2941 ObtainReadLock(&afs_xvolume);
2942 for (i = 0; i < NVOLS; i++) {
2943 for (j = afs_volumes[i]; j; j = j->next) {
2944 for (k = 0; k < s; k++)
2945 if (j->cell == l[k]) {
2946 ObtainWriteLock(&j->lock, 233);
2947 afs_SortServers(j->serverHost, MAXHOSTS);
2948 ReleaseWriteLock(&j->lock);
2953 ReleaseReadLock(&afs_xvolume);
2957 static int debugsetsp = 0;
2959 afs_setsprefs(sp, num, vlonly)
2962 unsigned int vlonly;
2965 int i, j, k, matches, touchedSize;
2966 struct server *srvr = NULL;
2967 afs_int32 touched[34];
2971 for (k = 0; k < num; sp++, k++) {
2973 printf("sp host=%x, rank=%d\n", sp->host.s_addr, sp->rank);
2976 ObtainReadLock(&afs_xserver);
2978 i = SHash(sp->host.s_addr);
2979 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2980 if (sa->sa_ip == sp->host.s_addr) {
2982 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
2983 || (sa->sa_portal == AFS_FSPORT);
2984 if ((!vlonly && isfs) || (vlonly && !isfs)) {
2991 if (sa && matches) { /* found one! */
2993 printf("sa ip=%x, ip_rank=%d\n", sa->sa_ip, sa->sa_iprank);
2995 sa->sa_iprank = sp->rank + afs_randomMod15();
2996 afs_SortOneServer(sa->server);
2999 /* if we don't know yet what cell it's in, this is moot */
3000 for (j = touchedSize - 1;
3001 j >= 0 && touched[j] != srvr->cell->cellNum; j--)
3002 /* is it in our list of touched cells ? */ ;
3003 if (j < 0) { /* no, it's not */
3004 touched[touchedSize++] = srvr->cell->cellNum;
3005 if (touchedSize >= 32) { /* watch for ovrflow */
3006 ReleaseReadLock(&afs_xserver);
3007 ReSortCells(touchedSize, touched, vlonly);
3009 ObtainReadLock(&afs_xserver);
3015 ReleaseReadLock(&afs_xserver);
3016 /* if we didn't find one, start to create one. */
3017 /* Note that it doesn't have a cell yet... */
3019 afs_uint32 temp = sp->host.s_addr;
3021 afs_GetServer(&temp, 1, 0, (vlonly ? AFS_VLPORT : AFS_FSPORT),
3022 WRITE_LOCK, (afsUUID *) 0, 0);
3023 srvr->addr->sa_iprank = sp->rank + afs_randomMod15();
3024 afs_PutServer(srvr, WRITE_LOCK);
3026 } /* for all cited preferences */
3028 ReSortCells(touchedSize, touched, vlonly);
3032 /* Note that this may only be performed by the local root user.
3034 DECL_PIOCTL(PSetSPrefs)
3036 struct setspref *ssp;
3037 AFS_STATCNT(PSetSPrefs);
3039 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3040 return EIO; /* Inappropriate ioctl for device */
3042 if (!afs_osi_suser(*acred))
3045 if (ainSize < sizeof(struct setspref))
3048 ssp = (struct setspref *)ain;
3049 if (ainSize < sizeof(struct spref) * ssp->num_servers)
3052 afs_setsprefs(&(ssp->servers[0]), ssp->num_servers,
3053 (ssp->flags & DBservers));
3057 DECL_PIOCTL(PSetSPrefs33)
3060 AFS_STATCNT(PSetSPrefs);
3061 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3062 return EIO; /* Inappropriate ioctl for device */
3065 if (!afs_osi_suser(*acred))
3068 sp = (struct spref *)ain;
3069 afs_setsprefs(sp, ainSize / (sizeof(struct spref)), 0 /*!vlonly */ );
3073 /* some notes on the following code...
3074 * in the hash table of server structs, all servers with the same IP address
3075 * will be on the same overflow chain.
3076 * This could be sped slightly in some circumstances by having it cache the
3077 * immediately previous slot in the hash table and some supporting information
3078 * Only reports file servers now.
3080 DECL_PIOCTL(PGetSPrefs)
3082 struct sprefrequest *spin; /* input */
3083 struct sprefinfo *spout; /* output */
3084 struct spref *srvout; /* one output component */
3085 int i, j; /* counters for hash table traversal */
3086 struct server *srvr; /* one of CM's server structs */
3088 int vlonly; /* just return vlservers ? */
3091 AFS_STATCNT(PGetSPrefs);
3092 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3093 return EIO; /* Inappropriate ioctl for device */
3096 if (ainSize < sizeof(struct sprefrequest_33)) {
3099 spin = ((struct sprefrequest *)ain);
3102 if (ainSize > sizeof(struct sprefrequest_33)) {
3103 vlonly = (spin->flags & DBservers);
3107 /* struct sprefinfo includes 1 server struct... that size gets added
3108 * in during the loop that follows.
3110 *aoutSize = sizeof(struct sprefinfo) - sizeof(struct spref);
3111 spout = (struct sprefinfo *)aout;
3112 spout->next_offset = spin->offset;
3113 spout->num_servers = 0;
3114 srvout = spout->servers;
3116 ObtainReadLock(&afs_xserver);
3117 for (i = 0, j = 0; j < NSERVERS; j++) { /* sift through hash table */
3118 for (sa = afs_srvAddrs[j]; sa; sa = sa->next_bkt, i++) {
3119 if (spin->offset > (unsigned short)i) {
3120 continue; /* catch up to where we left off */
3122 spout->next_offset++;
3125 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
3126 || (sa->sa_portal == AFS_FSPORT);
3128 if ((vlonly && isfs) || (!vlonly && !isfs)) {
3129 /* only report ranks for vl servers */
3133 srvout->host.s_addr = sa->sa_ip;
3134 srvout->rank = sa->sa_iprank;
3135 *aoutSize += sizeof(struct spref);
3136 spout->num_servers++;
3139 if (*aoutSize > (PIGGYSIZE - sizeof(struct spref))) {
3140 ReleaseReadLock(&afs_xserver); /* no more room! */
3145 ReleaseReadLock(&afs_xserver);
3147 spout->next_offset = 0; /* start over from the beginning next time */
3151 /* Enable/Disable the specified exporter. Must be root to disable an exporter */
3152 int afs_NFSRootOnly = 1;
3153 DECL_PIOCTL(PExportAfs)
3155 afs_int32 export, newint =
3156 0, type, changestate, handleValue, convmode, pwsync, smounts;
3157 afs_int32 rempags = 0, pagcb = 0;
3158 register struct afs_exporter *exporter;
3160 AFS_STATCNT(PExportAfs);
3161 memcpy((char *)&handleValue, ain, sizeof(afs_int32));
3162 type = handleValue >> 24;
3167 exporter = exporter_find(type);
3169 export = handleValue & 3;
3170 changestate = handleValue & 0xfff;
3171 smounts = (handleValue >> 2) & 3;
3172 pwsync = (handleValue >> 4) & 3;
3173 convmode = (handleValue >> 6) & 3;
3174 rempags = (handleValue >> 8) & 3;
3175 pagcb = (handleValue >> 10) & 3;
3177 changestate = (handleValue >> 16) & 0x1;
3178 convmode = (handleValue >> 16) & 0x2;
3179 pwsync = (handleValue >> 16) & 0x4;
3180 smounts = (handleValue >> 16) & 0x8;
3181 export = handleValue & 0xff;
3184 /* Failed finding desired exporter; */
3188 handleValue = exporter->exp_states;
3189 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3190 *aoutSize = sizeof(afs_int32);
3192 if (!afs_osi_suser(*acred))
3193 return EACCES; /* Only superuser can do this */
3197 exporter->exp_states |= EXP_EXPORTED;
3199 exporter->exp_states &= ~EXP_EXPORTED;
3203 exporter->exp_states |= EXP_UNIXMODE;
3205 exporter->exp_states &= ~EXP_UNIXMODE;
3209 exporter->exp_states |= EXP_PWSYNC;
3211 exporter->exp_states &= ~EXP_PWSYNC;
3215 afs_NFSRootOnly = 0;
3216 exporter->exp_states |= EXP_SUBMOUNTS;
3218 afs_NFSRootOnly = 1;
3219 exporter->exp_states &= ~EXP_SUBMOUNTS;
3224 exporter->exp_states |= EXP_CLIPAGS;
3226 exporter->exp_states &= ~EXP_CLIPAGS;
3230 exporter->exp_states |= EXP_CALLBACK;
3232 exporter->exp_states &= ~EXP_CALLBACK;
3234 handleValue = exporter->exp_states;
3235 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3236 *aoutSize = sizeof(afs_int32);
3239 exporter->exp_states |= EXP_EXPORTED;
3241 exporter->exp_states &= ~EXP_EXPORTED;
3243 exporter->exp_states |= EXP_UNIXMODE;
3245 exporter->exp_states &= ~EXP_UNIXMODE;
3247 exporter->exp_states |= EXP_PWSYNC;
3249 exporter->exp_states &= ~EXP_PWSYNC;
3251 afs_NFSRootOnly = 0;
3252 exporter->exp_states |= EXP_SUBMOUNTS;
3254 afs_NFSRootOnly = 1;
3255 exporter->exp_states &= ~EXP_SUBMOUNTS;
3265 struct gaginfo *gagflags;
3267 if (!afs_osi_suser(*acred))
3270 gagflags = (struct gaginfo *)ain;
3271 afs_showflags = gagflags->showflags;
3277 DECL_PIOCTL(PTwiddleRx)
3279 struct rxparams *rxp;
3281 if (!afs_osi_suser(*acred))
3284 rxp = (struct rxparams *)ain;
3286 if (rxp->rx_initReceiveWindow)
3287 rx_initReceiveWindow = rxp->rx_initReceiveWindow;
3288 if (rxp->rx_maxReceiveWindow)
3289 rx_maxReceiveWindow = rxp->rx_maxReceiveWindow;
3290 if (rxp->rx_initSendWindow)
3291 rx_initSendWindow = rxp->rx_initSendWindow;
3292 if (rxp->rx_maxSendWindow)
3293 rx_maxSendWindow = rxp->rx_maxSendWindow;
3294 if (rxp->rxi_nSendFrags)
3295 rxi_nSendFrags = rxp->rxi_nSendFrags;
3296 if (rxp->rxi_nRecvFrags)
3297 rxi_nRecvFrags = rxp->rxi_nRecvFrags;
3298 if (rxp->rxi_OrphanFragSize)
3299 rxi_OrphanFragSize = rxp->rxi_OrphanFragSize;
3300 if (rxp->rx_maxReceiveSize) {
3301 rx_maxReceiveSize = rxp->rx_maxReceiveSize;
3302 rx_maxReceiveSizeUser = rxp->rx_maxReceiveSize;
3304 if (rxp->rx_MyMaxSendSize)
3305 rx_MyMaxSendSize = rxp->rx_MyMaxSendSize;
3310 DECL_PIOCTL(PGetInitParams)
3312 if (sizeof(struct cm_initparams) > PIGGYSIZE)
3315 memcpy(aout, (char *)&cm_initParams, sizeof(struct cm_initparams));
3316 *aoutSize = sizeof(struct cm_initparams);
3320 #ifdef AFS_SGI65_ENV
3321 /* They took crget() from us, so fake it. */
3326 cr = crdup(get_current_cred());
3327 memset((char *)cr, 0, sizeof(cred_t));
3328 #if CELL || CELL_PREPARE
3335 DECL_PIOCTL(PGetRxkcrypt)
3337 memcpy(aout, (char *)&cryptall, sizeof(afs_int32));
3338 *aoutSize = sizeof(afs_int32);
3342 DECL_PIOCTL(PSetRxkcrypt)
3346 if (!afs_osi_suser(*acred))
3348 if (ainSize != sizeof(afs_int32) || ain == NULL)
3350 memcpy((char *)&tmpval, ain, sizeof(afs_int32));
3351 /* if new mappings added later this will need to be changed */
3352 if (tmpval != 0 && tmpval != 1)
3358 #ifdef AFS_NEED_CLIENTCONTEXT
3360 * Create new credentials to correspond to a remote user with given
3361 * <hostaddr, uid, g0, g1>. This allows a server running as root to
3362 * provide pioctl (and other) services to foreign clients (i.e. nfs
3363 * clients) by using this call to `become' the client.
3366 #define PIOCTL_HEADER 6
3368 HandleClientContext(struct afs_ioctl *ablob, int *com,
3369 struct AFS_UCRED **acred, struct AFS_UCRED *credp)
3372 afs_uint32 hostaddr;
3373 afs_int32 uid, g0, g1, i, code, pag, exporter_type, isroot = 0;
3374 struct afs_exporter *exporter, *outexporter;
3375 struct AFS_UCRED *newcred;
3376 struct unixuser *au;
3377 afs_uint32 comp = *com & 0xff00;
3380 #if defined(AFS_SGIMP_ENV)
3381 osi_Assert(ISAFS_GLOCK());
3383 AFS_STATCNT(HandleClientContext);
3384 if (ablob->in_size < PIOCTL_HEADER * sizeof(afs_int32)) {
3385 /* Must at least include the PIOCTL_HEADER header words required by the protocol */
3386 return EINVAL; /* Too small to be good */
3388 ain = inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
3389 AFS_COPYIN(ablob->in, ain, PIOCTL_HEADER * sizeof(afs_int32), code);
3391 osi_FreeLargeSpace(inData);
3395 /* Extract information for remote user */
3396 hostaddr = *((afs_uint32 *) ain);
3397 ain += sizeof(hostaddr);
3398 uid = *((afs_uint32 *) ain);
3400 g0 = *((afs_uint32 *) ain);
3402 g1 = *((afs_uint32 *) ain);
3404 *com = *((afs_uint32 *) ain);
3405 ain += sizeof(afs_int32);
3406 exporter_type = *((afs_uint32 *) ain); /* In case we support more than NFS */
3409 * Of course, one must be root for most of these functions, but
3410 * we'll allow (for knfs) you to set things if the pag is 0 and
3411 * you're setting tokens or unlogging.
3414 if (!afs_osi_suser(credp)) {
3415 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
3416 /* Since SGI's suser() returns explicit failure after the call.. */
3419 /* check for acceptable opcodes for normal folks, which are, so far,
3420 * get/set tokens, sysname, and unlog.
3422 if (i != 9 && i != 3 && i != 38 && i != 8) {
3423 osi_FreeLargeSpace(inData);
3428 ablob->in_size -= PIOCTL_HEADER * sizeof(afs_int32);
3429 ablob->in += PIOCTL_HEADER * sizeof(afs_int32);
3430 osi_FreeLargeSpace(inData);
3433 * We map uid 0 to nobody to match the mapping that the nfs
3434 * server does and to ensure that the suser() calls in the afs
3435 * code fails for remote client roots.
3437 uid = afs_nobody; /* NFS_NOBODY == -2 */
3441 #ifdef AFS_AIX41_ENV
3444 newcred->cr_gid = isroot ? RMTUSER_REQ_PRIV : RMTUSER_REQ;
3445 #ifdef AFS_AIX51_ENV
3446 newcred->cr_groupset.gs_union.un_groups[0] = g0;
3447 newcred->cr_groupset.gs_union.un_groups[1] = g1;
3448 #elif defined(AFS_LINUX26_ENV)
3449 #ifdef AFS_LINUX26_ONEGROUP_ENV
3450 newcred->cr_group_info = groups_alloc(1); /* not that anything sets this */
3451 l = (((g0-0x3f00) & 0x3fff) << 14) | ((g1-0x3f00) & 0x3fff);
3452 h = ((g0-0x3f00) >> 14);
3453 h = ((g1-0x3f00) >> 14) + h + h + h;
3454 GROUP_AT(newcred->cr_group_info, 0) = ((h << 28) | l);
3456 newcred->cr_group_info = groups_alloc(2);
3457 GROUP_AT(newcred->cr_group_info, 0) = g0;
3458 GROUP_AT(newcred->cr_group_info, 1) = g1;
3461 newcred->cr_groups[0] = g0;
3462 newcred->cr_groups[1] = g1;
3465 newcred->cr_ngrps = 2;
3466 #elif !defined(AFS_LINUX26_ENV)
3467 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
3468 newcred->cr_ngroups = 2;
3470 for (i = 2; i < NGROUPS; i++)
3471 newcred->cr_groups[i] = NOGROUP;
3474 #if !defined(AFS_OSF_ENV)
3475 afs_nfsclient_init(); /* before looking for exporter, ensure one exists */
3477 if (!(exporter = exporter_find(exporter_type))) {
3478 /* Exporter wasn't initialized or an invalid exporter type */
3482 if (exporter->exp_states & EXP_PWSYNC) {
3483 if (uid != credp->cr_uid) {
3485 return ENOEXEC; /* XXX Find a better errno XXX */
3488 newcred->cr_uid = uid; /* Only temporary */
3489 code = EXP_REQHANDLER(exporter, &newcred, hostaddr, &pag, &outexporter);
3490 /* The client's pag is the only unique identifier for it */
3491 newcred->cr_uid = pag;
3493 if (!code && *com == PSETPAG) {
3494 /* Special case for 'setpag' */
3495 afs_uint32 pagvalue = genpag();
3497 au = afs_GetUser(pagvalue, -1, WRITE_LOCK); /* a new unixuser struct */
3499 * Note that we leave the 'outexporter' struct held so it won't
3502 au->exporter = outexporter;
3503 if (ablob->out_size >= 4) {
3504 AFS_COPYOUT((char *)&pagvalue, ablob->out, sizeof(afs_int32),
3507 afs_PutUser(au, WRITE_LOCK);
3510 return PSETPAG; /* Special return for setpag */
3512 EXP_RELE(outexporter);
3515 *com = (*com) | comp;
3518 #endif /* AFS_NEED_CLIENTCONTEXT */
3520 /* get all interface addresses of this client */
3522 DECL_PIOCTL(PGetCPrefs)
3524 struct sprefrequest *spin; /* input */
3525 struct sprefinfo *spout; /* output */
3526 struct spref *srvout; /* one output component */
3530 AFS_STATCNT(PGetCPrefs);
3531 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3532 return EIO; /* Inappropriate ioctl for device */
3534 if (ainSize < sizeof(struct sprefrequest))
3537 spin = (struct sprefrequest *)ain;
3538 spout = (struct sprefinfo *)aout;
3540 maxNumber = spin->num_servers; /* max addrs this time */
3541 srvout = spout->servers;
3543 ObtainReadLock(&afs_xinterface);
3545 /* copy out the client interface information from the
3546 ** kernel data structure "interface" to the output buffer
3548 for (i = spin->offset, j = 0; (i < afs_cb_interface.numberOfInterfaces)
3549 && (j < maxNumber); i++, j++, srvout++)
3550 srvout->host.s_addr = afs_cb_interface.addr_in[i];
3552 spout->num_servers = j;
3553 *aoutSize = sizeof(struct sprefinfo) + (j - 1) * sizeof(struct spref);
3555 if (i >= afs_cb_interface.numberOfInterfaces)
3556 spout->next_offset = 0; /* start from beginning again */
3558 spout->next_offset = spin->offset + j;
3560 ReleaseReadLock(&afs_xinterface);
3564 DECL_PIOCTL(PSetCPrefs)
3566 struct setspref *sin;
3569 AFS_STATCNT(PSetCPrefs);
3570 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3571 return EIO; /* Inappropriate ioctl for device */
3573 sin = (struct setspref *)ain;
3575 if (ainSize < sizeof(struct setspref))
3577 #if 0 /* num_servers is unsigned */
3578 if (sin->num_servers < 0)
3581 if (sin->num_servers > AFS_MAX_INTERFACE_ADDR)
3584 ObtainWriteLock(&afs_xinterface, 412);
3585 afs_cb_interface.numberOfInterfaces = sin->num_servers;
3586 for (i = 0; (unsigned short)i < sin->num_servers; i++)
3587 afs_cb_interface.addr_in[i] = sin->servers[i].host.s_addr;
3589 ReleaseWriteLock(&afs_xinterface);
3593 DECL_PIOCTL(PFlushMount)
3595 register afs_int32 code;
3596 register struct vcache *tvc;
3597 register struct dcache *tdc;
3598 struct VenusFid tfid;
3600 struct sysname_info sysState;
3601 afs_size_t offset, len;
3603 AFS_STATCNT(PFlushMount);
3606 code = afs_VerifyVCache(avc, areq);
3609 if (vType(avc) != VDIR) {
3612 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
3615 Check_AtSys(avc, ain, &sysState, areq);
3616 ObtainReadLock(&tdc->lock);
3618 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
3619 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
3620 ReleaseReadLock(&tdc->lock);
3621 afs_PutDCache(tdc); /* we're done with the data */
3622 bufp = sysState.name;
3626 tfid.Cell = avc->fid.Cell;
3627 tfid.Fid.Volume = avc->fid.Fid.Volume;
3628 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
3629 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
3631 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3637 if (tvc->mvstat != 1) {
3642 #ifdef AFS_BOZONLOCK_ENV
3643 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
3645 ObtainWriteLock(&tvc->lock, 649);
3646 ObtainWriteLock(&afs_xcbhash, 650);
3647 afs_DequeueCallback(tvc);
3648 tvc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
3649 ReleaseWriteLock(&afs_xcbhash);
3650 /* now find the disk cache entries */
3651 afs_TryToSmush(tvc, *acred, 1);
3652 osi_dnlc_purgedp(tvc);
3653 if (tvc->linkData && !(tvc->states & CCore)) {
3654 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
3655 tvc->linkData = NULL;
3657 ReleaseWriteLock(&tvc->lock);
3658 #ifdef AFS_BOZONLOCK_ENV
3659 afs_BozonUnlock(&tvc->pvnLock, tvc);
3663 if (sysState.allocked)
3664 osi_FreeLargeSpace(bufp);
3668 DECL_PIOCTL(PRxStatProc)
3673 if (!afs_osi_suser(*acred)) {
3677 if (ainSize != sizeof(afs_int32)) {
3681 memcpy((char *)&flags, ain, sizeof(afs_int32));
3682 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3686 if (flags & AFSCALL_RXSTATS_ENABLE) {
3687 rx_enableProcessRPCStats();
3689 if (flags & AFSCALL_RXSTATS_DISABLE) {
3690 rx_disableProcessRPCStats();
3692 if (flags & AFSCALL_RXSTATS_CLEAR) {
3693 rx_clearProcessRPCStats(AFS_RX_STATS_CLEAR_ALL);
3701 DECL_PIOCTL(PRxStatPeer)
3706 if (!afs_osi_suser(*acred)) {
3710 if (ainSize != sizeof(afs_int32)) {
3714 memcpy((char *)&flags, ain, sizeof(afs_int32));
3715 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3719 if (flags & AFSCALL_RXSTATS_ENABLE) {
3720 rx_enablePeerRPCStats();
3722 if (flags & AFSCALL_RXSTATS_DISABLE) {
3723 rx_disablePeerRPCStats();
3725 if (flags & AFSCALL_RXSTATS_CLEAR) {
3726 rx_clearPeerRPCStats(AFS_RX_STATS_CLEAR_ALL);
3733 DECL_PIOCTL(PPrefetchFromTape)
3735 register afs_int32 code, code1;
3738 struct rx_call *tcall;
3739 struct AFSVolSync tsync;
3740 struct AFSFetchStatus OutStatus;
3741 struct AFSCallBack CallBack;
3742 struct VenusFid tfid;
3746 AFS_STATCNT(PSetAcl);
3750 if (ain && (ainSize == 3 * sizeof(afs_int32)))
3751 Fid = (struct AFSFid *)ain;
3753 Fid = &avc->fid.Fid;
3754 tfid.Cell = avc->fid.Cell;
3755 tfid.Fid.Volume = Fid->Volume;
3756 tfid.Fid.Vnode = Fid->Vnode;
3757 tfid.Fid.Unique = Fid->Unique;
3759 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3761 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3762 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &avc->fid);
3765 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3766 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &tvc->fid);
3769 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3773 tcall = rx_NewCall(tc->id);
3775 StartRXAFS_FetchData(tcall, (struct AFSFid *)&tvc->fid.Fid, 0,
3778 bytes = rx_Read(tcall, (char *)aout, sizeof(afs_int32));
3780 EndRXAFS_FetchData(tcall, &OutStatus, &CallBack, &tsync);
3782 code1 = rx_EndCall(tcall, code);
3786 } while (afs_Analyze
3787 (tc, code, &tvc->fid, areq, AFS_STATS_FS_RPCIDX_RESIDENCYRPCS,
3788 SHARED_LOCK, NULL));
3789 /* This call is done only to have the callback things handled correctly */
3790 afs_FetchStatus(tvc, &tfid, areq, &OutStatus);
3794 *aoutSize = sizeof(afs_int32);
3799 DECL_PIOCTL(PResidencyCmd)
3801 register afs_int32 code;
3804 struct ResidencyCmdInputs *Inputs;
3805 struct ResidencyCmdOutputs *Outputs;
3806 struct VenusFid tfid;
3809 Inputs = (struct ResidencyCmdInputs *)ain;
3810 Outputs = (struct ResidencyCmdOutputs *)aout;
3813 if (!ain || ainSize != sizeof(struct ResidencyCmdInputs))
3818 Fid = &avc->fid.Fid;
3820 tfid.Cell = avc->fid.Cell;
3821 tfid.Fid.Volume = Fid->Volume;
3822 tfid.Fid.Vnode = Fid->Vnode;
3823 tfid.Fid.Unique = Fid->Unique;
3825 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3826 afs_Trace3(afs_iclSetp, CM_TRACE_RESIDCMD, ICL_TYPE_POINTER, tvc,
3827 ICL_TYPE_INT32, Inputs->command, ICL_TYPE_FID, &tfid);
3831 if (Inputs->command) {
3833 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3837 RXAFS_ResidencyCmd(tc->id, Fid, Inputs,
3838 (struct ResidencyCmdOutputs *)aout);
3842 } while (afs_Analyze
3843 (tc, code, &tvc->fid, areq,
3844 AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK, NULL));
3845 /* This call is done to have the callback things handled correctly */
3846 afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3847 } else { /* just a status request, return also link data */
3849 Outputs->code = afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3850 Outputs->chars[0] = 0;
3851 if (vType(tvc) == VLNK) {
3852 ObtainWriteLock(&tvc->lock, 555);
3853 if (afs_HandleLink(tvc, areq) == 0)
3854 strncpy((char *)&Outputs->chars, tvc->linkData, MAXCMDCHARS);
3855 ReleaseWriteLock(&tvc->lock);
3862 *aoutSize = sizeof(struct ResidencyCmdOutputs);
3867 DECL_PIOCTL(PNewUuid)
3869 /*AFS_STATCNT(PNewUuid); */
3870 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
3871 return EIO; /* Inappropriate ioctl for device */
3873 if (!afs_osi_suser(acred))
3876 ObtainWriteLock(&afs_xinterface, 555);
3877 afs_uuid_create(&afs_cb_interface.uuid);
3878 ReleaseWriteLock(&afs_xinterface);
3879 ForceAllNewConnections();
3883 DECL_PIOCTL(PCallBackAddr)
3886 afs_uint32 addr, code;
3892 struct unixuser *tu;
3893 struct srvAddr **addrs;
3895 /*AFS_STATCNT(PCallBackAddr); */
3896 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
3897 return EIO; /* Inappropriate ioctl for device */
3899 if (!afs_osi_suser(acred))
3902 if (ainSize < sizeof(afs_int32))
3905 memcpy(&addr, ain, sizeof(afs_int32));
3907 ObtainReadLock(&afs_xinterface);
3908 for (i = 0; (unsigned short)i < afs_cb_interface.numberOfInterfaces; i++) {
3909 if (afs_cb_interface.addr_in[i] == addr)
3913 ReleaseWriteLock(&afs_xinterface);
3915 if (afs_cb_interface.addr_in[i] != addr)
3918 ObtainReadLock(&afs_xserver); /* Necessary? */
3919 ObtainReadLock(&afs_xsrvAddr);
3922 for (i = 0; i < NSERVERS; i++) {
3923 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3928 addrs = afs_osi_Alloc(srvAddrCount * sizeof(*addrs));
3930 for (i = 0; i < NSERVERS; i++) {
3931 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3932 if (j >= srvAddrCount)
3938 ReleaseReadLock(&afs_xsrvAddr);
3939 ReleaseReadLock(&afs_xserver);
3941 for (i = 0; i < j; i++) {
3947 /* vlserver has no callback conn */
3948 if (sa->sa_portal == AFS_VLPORT) {
3952 if (!ts->cell) /* not really an active server, anyway, it must */
3953 continue; /* have just been added by setsprefs */
3955 /* get a connection, even if host is down; bumps conn ref count */
3956 tu = afs_GetUser(areq->uid, ts->cell->cellNum, SHARED_LOCK);
3957 tc = afs_ConnBySA(sa, ts->cell->fsport, ts->cell->cellNum, tu,
3958 1 /*force */ , 1 /*create */ , SHARED_LOCK);
3959 afs_PutUser(tu, SHARED_LOCK);
3963 if ((sa->sa_flags & SRVADDR_ISDOWN) || afs_HaveCallBacksFrom(ts)) {
3964 if (sa->sa_flags & SRVADDR_ISDOWN) {
3965 rx_SetConnDeadTime(tc->id, 3);
3967 #ifdef RX_ENABLE_LOCKS
3969 #endif /* RX_ENABLE_LOCKS */
3970 code = RXAFS_CallBackRxConnAddr(tc->id, &addr);
3971 #ifdef RX_ENABLE_LOCKS
3973 #endif /* RX_ENABLE_LOCKS */
3975 afs_PutConn(tc, SHARED_LOCK); /* done with it now */
3976 } /* Outer loop over addrs */
3977 #endif /* UKERNEL */
3981 DECL_PIOCTL(PDiscon)
3983 #ifdef AFS_DISCON_ENV
3984 static afs_int32 mode = 1; /* Start up in 'off' */
3985 afs_int32 force = 0;
3990 if (!afs_osi_suser(*acred))
3996 afs_ConflictPolicy = ain[1] - 1;
4001 * All of these numbers are hard coded in fs.c. If they
4002 * change here, they should change there and vice versa
4005 case 0: /* Disconnect ("offline" mode), breaking all callbacks */
4006 if (!AFS_IS_DISCONNECTED) {
4007 ObtainWriteLock(&afs_discon_lock, 999);
4008 afs_DisconGiveUpCallbacks();
4009 afs_RemoveAllConns();
4010 afs_is_disconnected = 1;
4011 afs_is_discon_rw = 1;
4012 ReleaseWriteLock(&afs_discon_lock);
4015 case 1: /* Fully connected, ("online" mode). */
4016 ObtainWriteLock(&afs_discon_lock, 998);
4019 code = afs_ResyncDisconFiles(areq, *acred);
4022 if (code && !force) {
4023 printf("Files not synchronized properly, still in discon state. \
4024 Please retry or use \"force\".\n");
4026 afs_is_disconnected = 0;
4027 afs_is_discon_rw = 0;
4028 printf("\nSync succeeded. You are back online.\n");
4031 ReleaseWriteLock(&afs_discon_lock);
4040 memcpy(aout, &mode, sizeof(afs_int32));
4041 *aoutSize = sizeof(afs_int32);
4048 DECL_PIOCTL(PNFSNukeCreds)
4050 afs_uint32 addr, code;
4051 register afs_int32 i;
4052 register struct unixuser *tu;
4054 AFS_STATCNT(PUnlog);
4055 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4056 return EIO; /* Inappropriate ioctl for device */
4058 if (ainSize < sizeof(afs_int32))
4060 memcpy(&addr, ain, sizeof(afs_int32));
4062 if ((*acred)->cr_gid == RMTUSER_REQ_PRIV && !addr) {
4063 tu = afs_GetUser(areq->uid, -1, SHARED_LOCK);
4064 if (!tu->exporter || !(addr = EXP_GETHOST(tu->exporter))) {
4065 afs_PutUser(tu, SHARED_LOCK);
4068 afs_PutUser(tu, SHARED_LOCK);
4069 } else if (!afs_osi_suser(acred)) {
4073 ObtainWriteLock(&afs_xuser, 227);
4074 for (i = 0; i < NUSERS; i++) {
4075 for (tu = afs_users[i]; tu; tu = tu->next) {
4076 if (tu->exporter && EXP_CHECKHOST(tu->exporter, addr)) {
4078 tu->states &= ~UHasTokens;
4079 /* security is not having to say you're sorry */
4080 memset((char *)&tu->ct, 0, sizeof(struct ClearToken));
4082 ReleaseWriteLock(&afs_xuser);
4083 afs_ResetUserConns(tu);
4085 ObtainWriteLock(&afs_xuser, 228);
4087 /* set the expire times to 0, causes
4088 * afs_GCUserData to remove this entry
4090 tu->ct.EndTimestamp = 0;
4092 #endif /* UKERNEL */
4096 ReleaseWriteLock(&afs_xuser);