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;
38 #define DECL_PIOCTL(x) static int x(struct vcache *avc, int afun, struct vrequest *areq, \
39 char *ain, char *aout, afs_int32 ainSize, afs_int32 *aoutSize, \
40 struct AFS_UCRED **acred)
42 /* Prototypes for pioctl routines */
45 DECL_PIOCTL(PStoreBehind);
50 DECL_PIOCTL(PGetFileCell);
51 DECL_PIOCTL(PGetWSCell);
52 DECL_PIOCTL(PGetUserCell);
53 DECL_PIOCTL(PSetTokens);
54 DECL_PIOCTL(PGetVolumeStatus);
55 DECL_PIOCTL(PSetVolumeStatus);
57 DECL_PIOCTL(PNewStatMount);
58 DECL_PIOCTL(PGetTokens);
60 DECL_PIOCTL(PMariner);
61 DECL_PIOCTL(PCheckServers);
62 DECL_PIOCTL(PCheckVolNames);
63 DECL_PIOCTL(PCheckAuth);
64 DECL_PIOCTL(PFindVolume);
65 DECL_PIOCTL(PViceAccess);
66 DECL_PIOCTL(PSetCacheSize);
67 DECL_PIOCTL(PGetCacheSize);
68 DECL_PIOCTL(PRemoveCallBack);
69 DECL_PIOCTL(PNewCell);
70 DECL_PIOCTL(PNewAlias);
71 DECL_PIOCTL(PListCells);
72 DECL_PIOCTL(PListAliases);
73 DECL_PIOCTL(PRemoveMount);
74 DECL_PIOCTL(PVenusLogging);
75 DECL_PIOCTL(PGetCellStatus);
76 DECL_PIOCTL(PSetCellStatus);
77 DECL_PIOCTL(PFlushVolumeData);
78 DECL_PIOCTL(PGetVnodeXStatus);
79 DECL_PIOCTL(PGetVnodeXStatus2);
80 DECL_PIOCTL(PSetSysName);
81 DECL_PIOCTL(PSetSPrefs);
82 DECL_PIOCTL(PSetSPrefs33);
83 DECL_PIOCTL(PGetSPrefs);
84 DECL_PIOCTL(PExportAfs);
86 DECL_PIOCTL(PTwiddleRx);
87 DECL_PIOCTL(PGetInitParams);
88 DECL_PIOCTL(PGetRxkcrypt);
89 DECL_PIOCTL(PSetRxkcrypt);
90 DECL_PIOCTL(PGetCPrefs);
91 DECL_PIOCTL(PSetCPrefs);
92 DECL_PIOCTL(PFlushMount);
93 DECL_PIOCTL(PRxStatProc);
94 DECL_PIOCTL(PRxStatPeer);
95 DECL_PIOCTL(PPrefetchFromTape);
96 DECL_PIOCTL(PResidencyCmd);
97 DECL_PIOCTL(PCallBackAddr);
99 DECL_PIOCTL(PNFSNukeCreds);
100 DECL_PIOCTL(PNewUuid);
101 DECL_PIOCTL(PPrecache);
104 * A macro that says whether we're going to need HandleClientContext().
105 * This is currently used only by the nfs translator.
107 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
108 #define AFS_NEED_CLIENTCONTEXT
111 /* Prototypes for private routines */
112 #ifdef AFS_NEED_CLIENTCONTEXT
113 static int HandleClientContext(struct afs_ioctl *ablob, int *com,
114 struct AFS_UCRED **acred,
115 struct AFS_UCRED *credp);
117 int HandleIoctl(register struct vcache *avc, register afs_int32 acom,
118 struct afs_ioctl *adata);
119 int afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
120 register struct afs_ioctl *ablob, int afollow,
121 struct AFS_UCRED **acred);
122 static int Prefetch(char *apath, struct afs_ioctl *adata, int afollow,
123 struct AFS_UCRED *acred);
126 static int (*(VpioctlSw[])) () = {
131 PGetVolumeStatus, /* 4 */
132 PSetVolumeStatus, /* 5 */
137 PCheckServers, /* 10 */
138 PCheckVolNames, /* 11 */
140 PBogus, /* 13 -- used to be quick check time */
141 PFindVolume, /* 14 */
142 PBogus, /* 15 -- prefetch is now special-cased; see pioctl code! */
143 PBogus, /* 16 -- used to be testing code */
144 PNoop, /* 17 -- used to be enable group */
145 PNoop, /* 18 -- used to be disable group */
146 PBogus, /* 19 -- used to be list group */
147 PViceAccess, /* 20 */
148 PUnlog, /* 21 -- unlog *is* unpag in this system */
149 PGetFID, /* 22 -- get file ID */
150 PBogus, /* 23 -- used to be waitforever */
151 PSetCacheSize, /* 24 */
152 PRemoveCallBack, /* 25 -- flush only the callback */
155 PRemoveMount, /* 28 -- delete mount point */
156 PNewStatMount, /* 29 -- new style mount point stat */
157 PGetFileCell, /* 30 -- get cell name for input file */
158 PGetWSCell, /* 31 -- get cell name for workstation */
159 PMariner, /* 32 - set/get mariner host */
160 PGetUserCell, /* 33 -- get cell name for user */
161 PVenusLogging, /* 34 -- Enable/Disable logging */
162 PGetCellStatus, /* 35 */
163 PSetCellStatus, /* 36 */
164 PFlushVolumeData, /* 37 -- flush all data from a volume */
165 PSetSysName, /* 38 - Set system name */
166 PExportAfs, /* 39 - Export Afs to remote nfs clients */
167 PGetCacheSize, /* 40 - get cache size and usage */
168 PGetVnodeXStatus, /* 41 - get vcache's special status */
169 PSetSPrefs33, /* 42 - Set CM Server preferences... */
170 PGetSPrefs, /* 43 - Get CM Server preferences... */
171 PGag, /* 44 - turn off/on all CM messages */
172 PTwiddleRx, /* 45 - adjust some RX params */
173 PSetSPrefs, /* 46 - Set CM Server preferences... */
174 PStoreBehind, /* 47 - set degree of store behind to be done */
175 PGCPAGs, /* 48 - disable automatic pag gc-ing */
176 PGetInitParams, /* 49 - get initial cm params */
177 PGetCPrefs, /* 50 - get client interface addresses */
178 PSetCPrefs, /* 51 - set client interface addresses */
179 PFlushMount, /* 52 - flush mount symlink data */
180 PRxStatProc, /* 53 - control process RX statistics */
181 PRxStatPeer, /* 54 - control peer RX statistics */
182 PGetRxkcrypt, /* 55 -- Get rxkad encryption flag */
183 PSetRxkcrypt, /* 56 -- Set rxkad encryption flag */
184 PBogus, /* 57 -- arla: set file prio */
185 PBogus, /* 58 -- arla: fallback getfh */
186 PBogus, /* 59 -- arla: fallback fhopen */
187 PBogus, /* 60 -- arla: controls xfsdebug */
188 PBogus, /* 61 -- arla: controls arla debug */
189 PBogus, /* 62 -- arla: debug interface */
190 PBogus, /* 63 -- arla: print xfs status */
191 PBogus, /* 64 -- arla: force cache check */
192 PBogus, /* 65 -- arla: break callback */
193 PPrefetchFromTape, /* 66 -- MR-AFS: prefetch file from tape */
194 PResidencyCmd, /* 67 -- MR-AFS: generic commnd interface */
195 PBogus, /* 68 -- arla: fetch stats */
196 PGetVnodeXStatus2, /* 69 - get caller access and some vcache status */
199 static int (*(CpioctlSw[])) () = {
201 PNewAlias, /* 1 -- create new cell alias */
202 PListAliases, /* 2 -- list cell aliases */
203 PCallBackAddr, /* 3 -- request addr for callback rxcon */
215 static int (*(OpioctlSw[])) () = {
217 PNFSNukeCreds, /* 1 -- nuke all creds for NFS client */
220 #define PSetClientContext 99 /* Special pioctl to setup caller's creds */
221 int afs_nobody = NFS_NOBODY;
224 HandleIoctl(register struct vcache *avc, register afs_int32 acom,
225 struct afs_ioctl *adata)
227 register afs_int32 code;
230 AFS_STATCNT(HandleIoctl);
232 switch (acom & 0xff) {
234 avc->states |= CSafeStore;
238 /* case 2 used to be abort store, but this is no longer provided,
239 * since it is impossible to implement under normal Unix.
243 /* return the name of the cell this file is open on */
244 register struct cell *tcell;
245 register afs_int32 i;
247 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
249 i = strlen(tcell->cellName) + 1; /* bytes to copy out */
251 if (i > adata->out_size) {
252 /* 0 means we're not interested in the output */
253 if (adata->out_size != 0)
257 AFS_COPYOUT(tcell->cellName, adata->out, i, code);
259 afs_PutCell(tcell, READ_LOCK);
265 case 49: /* VIOC_GETINITPARAMS */
266 if (adata->out_size < sizeof(struct cm_initparams)) {
269 AFS_COPYOUT(&cm_initParams, adata->out,
270 sizeof(struct cm_initparams), code);
282 return code; /* so far, none implemented */
287 /* For aix we don't temporarily bypass ioctl(2) but rather do our
288 * thing directly in the vnode layer call, VNOP_IOCTL; thus afs_ioctl
289 * is now called from afs_gn_ioctl.
292 afs_ioctl(struct vcache *tvc, int cmd, int arg)
294 struct afs_ioctl data;
297 AFS_STATCNT(afs_ioctl);
298 if (((cmd >> 8) & 0xff) == 'V') {
299 /* This is a VICEIOCTL call */
300 AFS_COPYIN(arg, (caddr_t) & data, sizeof(data), error);
303 error = HandleIoctl(tvc, cmd, &data);
306 /* No-op call; just return. */
310 #endif /* AFS_AIX_ENV */
312 #if defined(AFS_SGI_ENV)
313 afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
316 , struct vopbd * vbds
320 struct afs_ioctl data;
326 AFS_STATCNT(afs_ioctl);
327 if (((cmd >> 8) & 0xff) == 'V') {
328 /* This is a VICEIOCTL call */
329 error = copyin_afs_ioctl(arg, &data);
332 locked = ISAFS_GLOCK();
335 error = HandleIoctl(tvc, cmd, &data);
340 /* No-op call; just return. */
344 #endif /* AFS_SGI_ENV */
346 /* unlike most calls here, this one uses u.u_error to return error conditions,
347 since this is really an intercepted chapter 2 call, rather than a vnode
350 /* AFS_HPUX102 and up uses VNODE ioctl instead */
351 #if !defined(AFS_HPUX102_ENV) && !defined(AFS_DARWIN80_ENV)
352 #if !defined(AFS_SGI_ENV)
356 kioctl(fdes, com, arg, ext, arg2, arg3)
357 #else /* __64BIT__ */
358 kioctl32(fdes, com, arg, ext, arg2, arg3)
359 #endif /* __64BIT__ */
362 kioctl(fdes, com, arg, ext)
373 } u_uap, *uap = &u_uap;
375 #if defined(AFS_SUN5_ENV)
377 struct afs_ioctl_sys {
384 struct afs_ioctl_sys *uap;
387 #elif defined(AFS_OSF_ENV)
388 afs_xioctl(p, args, retval)
397 } *uap = (struct a *)args;
398 #elif defined(AFS_FBSD50_ENV)
401 afs_xioctl(td, uap, retval)
403 register struct ioctl_args *uap;
406 struct proc *p = td->td_proc;
407 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
415 afs_xioctl(p, uap, retval)
417 register struct ioctl_args *uap;
420 #elif defined(AFS_LINUX22_ENV)
421 struct afs_ioctl_sys {
426 afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
429 struct afs_ioctl_sys ua, *uap = &ua;
438 } *uap = (struct a *)u.u_ap;
439 #endif /* AFS_SUN5_ENV */
441 #if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
443 #elif !defined(AFS_LINUX22_ENV)
444 register struct file *fd;
446 #if defined(AFS_XBSD_ENV)
447 register struct filedesc *fdp;
449 register struct vcache *tvc;
450 register int ioctlDone = 0, code = 0;
452 AFS_STATCNT(afs_xioctl);
453 #if defined(AFS_DARWIN_ENV)
454 if ((code = fdgetf(p, uap->fd, &fd)))
456 #elif defined(AFS_XBSD_ENV)
458 if ((u_int) uap->fd >= fdp->fd_nfiles
459 || (fd = fdp->fd_ofiles[uap->fd]) == NULL)
461 if ((fd->f_flag & (FREAD | FWRITE)) == 0)
463 #elif defined(AFS_LINUX22_ENV)
466 #elif defined(AFS_AIX32_ENV)
474 if (setuerror(getf(uap->fd, &fd))) {
477 #elif defined(AFS_OSF_ENV)
479 if (code = getf(&fd, uap->fd, FILE_FLAGS_NULL, &u.u_file_state))
481 #elif defined(AFS_SUN5_ENV)
482 # if defined(AFS_SUN57_ENV)
486 # elif defined(AFS_SUN54_ENV)
491 if (code = getf(uap->fd, &fd)) {
494 # endif /* AFS_SUN57_ENV */
500 /* first determine whether this is any sort of vnode */
501 #if defined(AFS_LINUX22_ENV)
506 if (fd->f_vnode->v_type == VREG || fd->f_vnode->v_type == VDIR) {
508 if (fd->f_type == DTYPE_VNODE) {
510 /* good, this is a vnode; next see if it is an AFS vnode */
511 #if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV)
512 tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */
513 #elif defined(AFS_OBSD_ENV)
515 IsAfsVnode((struct vnode *)fd->
516 f_data) ? VTOAFS((struct vnode *)fd->f_data) : NULL;
518 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
520 #endif /* AFS_LINUX22_ENV */
521 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
522 /* This is an AFS vnode */
523 if (((uap->com >> 8) & 0xff) == 'V') {
524 register struct afs_ioctl *datap;
527 (struct afs_ioctl *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
528 code=copyin_afs_ioctl((char *)uap->arg, datap);
530 osi_FreeSmallSpace(datap);
532 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
535 #if defined(AFS_SUN5_ENV)
550 #else /* AFS_OSF_ENV */
554 #ifdef AFS_LINUX22_ENV
564 code = HandleIoctl(tvc, uap->com, datap);
565 osi_FreeSmallSpace(datap);
579 #if defined(AFS_LINUX22_ENV)
591 code = okioctl(fdes, com, arg, ext, arg2, arg3);
592 #else /* __64BIT__ */
593 code = okioctl32(fdes, com, arg, ext, arg2, arg3);
594 #endif /* __64BIT__ */
595 #else /* !AFS_AIX51_ENV */
596 code = okioctl(fdes, com, arg, ext);
597 #endif /* AFS_AIX51_ENV */
599 #else /* !AFS_AIX41_ENV */
601 okioctl(fdes, com, arg, ext);
602 #elif defined(AFS_SUN5_ENV)
603 #if defined(AFS_SUN57_ENV)
605 #elif defined(AFS_SUN54_ENV)
610 code = ioctl(uap, rvp);
611 #elif defined(AFS_FBSD50_ENV)
612 return ioctl(td, uap);
613 #elif defined(AFS_FBSD_ENV)
614 return ioctl(p, uap);
615 #elif defined(AFS_OBSD_ENV)
616 code = sys_ioctl(p, uap, retval);
617 #elif defined(AFS_DARWIN_ENV)
618 return ioctl(p, uap, retval);
619 #elif defined(AFS_OSF_ENV)
620 code = ioctl(p, args, retval);
627 #elif !defined(AFS_LINUX22_ENV)
641 #ifdef AFS_LINUX22_ENV
644 #if defined(KERNEL_HAVE_UERROR)
647 #if defined(AFS_AIX32_ENV) && !defined(AFS_AIX41_ENV)
648 return (getuerror()? -1 : u.u_ioctlrv);
650 return getuerror()? -1 : 0;
653 #endif /* AFS_LINUX22_ENV */
654 #endif /* AFS_SUN5_ENV */
655 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
659 #endif /* AFS_SGI_ENV */
660 #endif /* AFS_HPUX102_ENV */
662 #if defined(AFS_SGI_ENV)
663 /* "pioctl" system call entry point; just pass argument to the parameterized
672 afs_pioctl(struct pioctlargs *uap, rval_t * rvp)
676 AFS_STATCNT(afs_pioctl);
678 code = afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow);
687 #elif defined(AFS_OSF_ENV)
688 afs_pioctl(p, args, retval)
698 } *uap = (struct a *)args;
700 AFS_STATCNT(afs_pioctl);
701 return (afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow));
704 #elif defined(AFS_FBSD50_ENV)
706 afs_pioctl(td, args, retval)
716 } *uap = (struct a *)args;
718 AFS_STATCNT(afs_pioctl);
719 return (afs_syscall_pioctl
720 (uap->path, uap->cmd, uap->cmarg, uap->follow, td->td_ucred));
723 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
725 afs_pioctl(p, args, retval)
735 } *uap = (struct a *)args;
737 AFS_STATCNT(afs_pioctl);
738 #ifdef AFS_DARWIN80_ENV
739 return (afs_syscall_pioctl
740 (uap->path, uap->cmd, uap->cmarg, uap->follow,
743 return (afs_syscall_pioctl
744 (uap->path, uap->cmd, uap->cmarg, uap->follow,
745 p->p_cred->pc_ucred));
751 /* macro to avoid adding any more #ifdef's to pioctl code. */
752 #if defined(AFS_LINUX22_ENV) || defined(AFS_AIX41_ENV)
753 #define PIOCTL_FREE_CRED() crfree(credp)
755 #define PIOCTL_FREE_CRED()
760 afs_syscall_pioctl(path, com, cmarg, follow, rvp, credp)
762 struct AFS_UCRED *credp;
764 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
765 afs_syscall_pioctl(path, com, cmarg, follow, credp)
766 struct AFS_UCRED *credp;
768 afs_syscall_pioctl(path, com, cmarg, follow)
776 struct afs_ioctl data;
777 #ifdef AFS_NEED_CLIENTCONTEXT
778 struct AFS_UCRED *tmpcred = NULL;
780 struct AFS_UCRED *foreigncreds = NULL;
781 register afs_int32 code = 0;
782 struct vnode *vp = NULL;
784 struct ucred *credp = crref(); /* don't free until done! */
786 #ifdef AFS_LINUX22_ENV
787 cred_t *credp = crref(); /* don't free until done! */
791 AFS_STATCNT(afs_syscall_pioctl);
793 follow = 1; /* compat. with old venus */
794 code = copyin_afs_ioctl(cmarg, &data);
797 #if defined(KERNEL_HAVE_UERROR)
802 if ((com & 0xff) == PSetClientContext) {
803 #ifdef AFS_NEED_CLIENTCONTEXT
804 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV)
805 code = HandleClientContext(&data, &com, &foreigncreds, credp);
807 code = HandleClientContext(&data, &com, &foreigncreds, osi_curcred());
811 crfree(foreigncreds);
814 #if defined(KERNEL_HAVE_UERROR)
815 return (setuerror(code), code);
820 #else /* AFS_NEED_CLIENTCONTEXT */
822 #endif /* AFS_NEED_CLIENTCONTEXT */
824 #ifdef AFS_NEED_CLIENTCONTEXT
827 * We could have done without temporary setting the u.u_cred below
828 * (foreigncreds could be passed as param the pioctl modules)
829 * but calls such as afs_osi_suser() doesn't allow that since it
830 * references u.u_cred directly. We could, of course, do something
831 * like afs_osi_suser(cred) which, I think, is better since it
832 * generalizes and supports multi cred environments...
834 #if defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
836 credp = foreigncreds;
837 #elif defined(AFS_AIX41_ENV)
838 tmpcred = crref(); /* XXX */
840 #elif defined(AFS_HPUX101_ENV)
841 tmpcred = p_cred(u.u_procp);
842 set_p_cred(u.u_procp, foreigncreds);
843 #elif defined(AFS_SGI_ENV)
844 tmpcred = OSI_GET_CURRENT_CRED();
845 OSI_SET_CURRENT_CRED(foreigncreds);
848 u.u_cred = foreigncreds;
851 #endif /* AFS_NEED_CLIENTCONTEXT */
852 if ((com & 0xff) == 15) {
853 /* special case prefetch so entire pathname eval occurs in helper process.
854 * otherwise, the pioctl call is essentially useless */
855 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
857 Prefetch(path, &data, follow,
858 foreigncreds ? foreigncreds : credp);
860 code = Prefetch(path, &data, follow, osi_curcred());
863 #if defined(KERNEL_HAVE_UERROR)
872 lookupname(path, USR, follow, NULL, &vp,
873 foreigncreds ? foreigncreds : credp);
875 #ifdef AFS_LINUX22_ENV
876 code = gop_lookupname(path, AFS_UIOUSER, follow, &dp);
878 vp = (struct vnode *)dp->d_inode;
880 code = gop_lookupname(path, AFS_UIOUSER, follow, &vp);
881 #endif /* AFS_LINUX22_ENV */
882 #endif /* AFS_AIX41_ENV */
886 #if defined(KERNEL_HAVE_UERROR)
894 #if defined(AFS_SUN510_ENV)
895 if (vp && !IsAfsVnode(vp)) {
896 struct vnode *realvp;
898 #ifdef AFS_SUN511_ENV
899 (VOP_REALVP(vp, &realvp, NULL) == 0)
901 (VOP_REALVP(vp, &realvp) == 0)
904 struct vnode *oldvp = vp;
912 /* now make the call if we were passed no file, or were passed an AFS file */
913 if (!vp || IsAfsVnode(vp)) {
914 #if defined(AFS_SUN5_ENV)
915 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
916 #elif defined(AFS_AIX41_ENV)
918 struct ucred *cred1, *cred2;
921 cred1 = cred2 = foreigncreds;
923 cred1 = cred2 = credp;
925 code = afs_HandlePioctl(vp, com, &data, follow, &cred1);
926 if (cred1 != cred2) {
927 /* something changed the creds */
931 #elif defined(AFS_HPUX101_ENV)
933 struct ucred *cred = p_cred(u.u_procp);
934 code = afs_HandlePioctl(vp, com, &data, follow, &cred);
936 #elif defined(AFS_SGI_ENV)
939 credp = OSI_GET_CURRENT_CRED();
940 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
942 #elif defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
943 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
945 code = afs_HandlePioctl(vp, com, &data, follow, &u.u_cred);
948 #if defined(KERNEL_HAVE_UERROR)
951 code = EINVAL; /* not in /afs */
956 #if defined(AFS_NEED_CLIENTCONTEXT)
959 crset(tmpcred); /* restore original credentials */
961 #if defined(AFS_HPUX101_ENV)
962 set_p_cred(u.u_procp, tmpcred); /* restore original credentials */
963 #elif defined(AFS_SGI_ENV)
964 OSI_SET_CURRENT_CRED(tmpcred); /* restore original credentials */
965 #elif defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
966 credp = tmpcred; /* restore original credentials */
968 osi_curcred() = tmpcred; /* restore original credentials */
969 #endif /* AFS_HPUX101_ENV */
970 crfree(foreigncreds);
973 #endif /* AFS_NEED_CLIENTCONTEXT */
975 #ifdef AFS_LINUX22_ENV
978 AFS_RELE(vp); /* put vnode back */
982 #if defined(KERNEL_HAVE_UERROR)
985 return (getuerror());
991 #define MAXPIOCTLTOKENLEN \
992 (3*sizeof(afs_int32)+MAXKTCTICKETLEN+sizeof(struct ClearToken)+MAXKTCREALMLEN)
995 afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
996 register struct afs_ioctl *ablob, int afollow,
997 struct AFS_UCRED **acred)
1000 struct vrequest treq;
1001 register afs_int32 code;
1002 register afs_int32 function, device;
1003 afs_int32 inSize, outSize, outSizeMax;
1004 char *inData, *outData;
1005 int (*(*pioctlSw)) ();
1007 struct afs_fakestat_state fakestate;
1009 avc = avp ? VTOAFS(avp) : NULL;
1010 afs_Trace3(afs_iclSetp, CM_TRACE_PIOCTL, ICL_TYPE_INT32, acom & 0xff,
1011 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, afollow);
1012 AFS_STATCNT(HandlePioctl);
1013 if ((code = afs_InitReq(&treq, *acred)))
1015 afs_InitFakeStat(&fakestate);
1017 code = afs_EvalFakeStat(&avc, &fakestate, &treq);
1019 afs_PutFakeStat(&fakestate);
1023 device = (acom & 0xff00) >> 8;
1025 case 'V': /* Original pioctls */
1026 pioctlSw = VpioctlSw;
1027 pioctlSwSize = sizeof(VpioctlSw);
1029 case 'C': /* Coordinated/common pioctls */
1030 pioctlSw = CpioctlSw;
1031 pioctlSwSize = sizeof(CpioctlSw);
1033 case 'O': /* Coordinated/common pioctls */
1034 pioctlSw = OpioctlSw;
1035 pioctlSwSize = sizeof(OpioctlSw);
1038 afs_PutFakeStat(&fakestate);
1041 function = acom & 0xff;
1042 if (function >= (pioctlSwSize / sizeof(char *))) {
1043 afs_PutFakeStat(&fakestate);
1044 return EINVAL; /* out of range */
1046 inSize = ablob->in_size;
1048 /* Do all range checking before continuing */
1049 if (inSize > MAXPIOCTLTOKENLEN || inSize < 0 || ablob->out_size < 0)
1052 /* Note that we use osi_Alloc for large allocs and osi_AllocLargeSpace for small ones */
1053 if (inSize > AFS_LRALLOCSIZ) {
1054 inData = osi_Alloc(inSize + 1);
1056 inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1061 AFS_COPYIN(ablob->in, inData, inSize, code);
1062 inData[inSize] = '\0';
1066 if (inSize > AFS_LRALLOCSIZ) {
1067 osi_Free(inData, inSize + 1);
1069 osi_FreeLargeSpace(inData);
1071 afs_PutFakeStat(&fakestate);
1074 if (function == 8 && device == 'V') { /* PGetTokens */
1075 outSizeMax = MAXPIOCTLTOKENLEN;
1076 outData = osi_Alloc(outSizeMax);
1078 outSizeMax = AFS_LRALLOCSIZ;
1079 outData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1082 if (inSize > AFS_LRALLOCSIZ) {
1083 osi_Free(inData, inSize + 1);
1085 osi_FreeLargeSpace(inData);
1087 afs_PutFakeStat(&fakestate);
1092 (*pioctlSw[function]) (avc, function, &treq, inData, outData, inSize,
1094 if (inSize > AFS_LRALLOCSIZ) {
1095 osi_Free(inData, inSize + 1);
1097 osi_FreeLargeSpace(inData);
1099 if (code == 0 && ablob->out_size > 0) {
1100 if (outSize > ablob->out_size) {
1101 code = E2BIG; /* data wont fit in user buffer */
1102 } else if (outSize) {
1103 AFS_COPYOUT(outData, ablob->out, outSize, code);
1106 if (outSizeMax > AFS_LRALLOCSIZ) {
1107 osi_Free(outData, outSizeMax);
1109 osi_FreeLargeSpace(outData);
1111 afs_PutFakeStat(&fakestate);
1112 return afs_CheckCode(code, &treq, 41);
1115 DECL_PIOCTL(PGetFID)
1117 AFS_STATCNT(PGetFID);
1120 memcpy(aout, (char *)&avc->fid, sizeof(struct VenusFid));
1121 *aoutSize = sizeof(struct VenusFid);
1125 DECL_PIOCTL(PSetAcl)
1127 register afs_int32 code;
1129 struct AFSOpaque acl;
1130 struct AFSVolSync tsync;
1131 struct AFSFetchStatus OutStatus;
1134 AFS_STATCNT(PSetAcl);
1137 if ((acl.AFSOpaque_len = strlen(ain) + 1) > 1024 /* AFSOPAQUEMAX */)
1140 acl.AFSOpaque_val = ain;
1142 tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1144 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREACL);
1147 RXAFS_StoreACL(tconn->id, (struct AFSFid *)&avc->fid.Fid,
1148 &acl, &OutStatus, &tsync);
1153 } while (afs_Analyze
1154 (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_STOREACL,
1155 SHARED_LOCK, NULL));
1157 /* now we've forgotten all of the access info */
1158 ObtainWriteLock(&afs_xcbhash, 455);
1160 afs_DequeueCallback(avc);
1161 avc->states &= ~(CStatd | CUnique);
1162 ReleaseWriteLock(&afs_xcbhash);
1163 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
1164 osi_dnlc_purgedp(avc);
1168 int afs_defaultAsynchrony = 0;
1170 DECL_PIOCTL(PStoreBehind)
1173 struct sbstruct *sbr;
1175 sbr = (struct sbstruct *)ain;
1176 if (sbr->sb_default != -1) {
1177 if (afs_osi_suser(*acred))
1178 afs_defaultAsynchrony = sbr->sb_default;
1183 if (avc && (sbr->sb_thisfile != -1)) {
1185 (avc, PRSFS_WRITE | PRSFS_ADMINISTER, areq, DONT_CHECK_MODE_BITS))
1186 avc->asynchrony = sbr->sb_thisfile;
1191 *aoutSize = sizeof(struct sbstruct);
1192 sbr = (struct sbstruct *)aout;
1193 sbr->sb_default = afs_defaultAsynchrony;
1195 sbr->sb_thisfile = avc->asynchrony;
1201 DECL_PIOCTL(PGCPAGs)
1203 if (!afs_osi_suser(*acred)) {
1206 afs_gcpags = AFS_GCPAGS_USERDISABLED;
1210 DECL_PIOCTL(PGetAcl)
1212 struct AFSOpaque acl;
1213 struct AFSVolSync tsync;
1214 struct AFSFetchStatus OutStatus;
1220 AFS_STATCNT(PGetAcl);
1223 Fid.Volume = avc->fid.Fid.Volume;
1224 Fid.Vnode = avc->fid.Fid.Vnode;
1225 Fid.Unique = avc->fid.Fid.Unique;
1226 if (avc->states & CForeign) {
1228 * For a dfs xlator acl we have a special hack so that the
1229 * xlator will distinguish which type of acl will return. So
1230 * we currently use the top 2-bytes (vals 0-4) to tell which
1231 * type of acl to bring back. Horrible hack but this will
1232 * cause the least number of changes to code size and interfaces.
1234 if (Fid.Vnode & 0xc0000000)
1236 Fid.Vnode |= (ainSize << 30);
1238 acl.AFSOpaque_val = aout;
1240 tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1243 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHACL);
1245 code = RXAFS_FetchACL(tconn->id, &Fid, &acl, &OutStatus, &tsync);
1250 } while (afs_Analyze
1251 (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_FETCHACL,
1252 SHARED_LOCK, NULL));
1255 *aoutSize = (acl.AFSOpaque_len == 0 ? 1 : acl.AFSOpaque_len);
1268 AFS_STATCNT(PBogus);
1272 DECL_PIOCTL(PGetFileCell)
1274 register struct cell *tcell;
1276 AFS_STATCNT(PGetFileCell);
1279 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
1282 strcpy(aout, tcell->cellName);
1283 afs_PutCell(tcell, READ_LOCK);
1284 *aoutSize = strlen(aout) + 1;
1288 DECL_PIOCTL(PGetWSCell)
1290 struct cell *tcell = NULL;
1292 AFS_STATCNT(PGetWSCell);
1293 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1294 return EIO; /* Inappropriate ioctl for device */
1296 tcell = afs_GetPrimaryCell(READ_LOCK);
1297 if (!tcell) /* no primary cell? */
1299 strcpy(aout, tcell->cellName);
1300 *aoutSize = strlen(aout) + 1;
1301 afs_PutCell(tcell, READ_LOCK);
1305 DECL_PIOCTL(PGetUserCell)
1307 register afs_int32 i;
1308 register struct unixuser *tu;
1309 register struct cell *tcell;
1311 AFS_STATCNT(PGetUserCell);
1312 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1313 return EIO; /* Inappropriate ioctl for device */
1315 /* return the cell name of the primary cell for this user */
1316 i = UHash(areq->uid);
1317 ObtainWriteLock(&afs_xuser, 224);
1318 for (tu = afs_users[i]; tu; tu = tu->next) {
1319 if (tu->uid == areq->uid && (tu->states & UPrimary)) {
1321 ReleaseWriteLock(&afs_xuser);
1326 tcell = afs_GetCell(tu->cell, READ_LOCK);
1327 afs_PutUser(tu, WRITE_LOCK);
1331 strcpy(aout, tcell->cellName);
1332 afs_PutCell(tcell, READ_LOCK);
1333 *aoutSize = strlen(aout) + 1; /* 1 for the null */
1336 ReleaseWriteLock(&afs_xuser);
1343 DECL_PIOCTL(PSetTokens)
1346 register struct unixuser *tu;
1347 struct ClearToken clear;
1348 register struct cell *tcell;
1351 struct vrequest treq;
1352 afs_int32 flag, set_parent_pag = 0;
1354 AFS_STATCNT(PSetTokens);
1355 if (!afs_resourceinit_flag) {
1358 memcpy((char *)&i, ain, sizeof(afs_int32));
1359 ain += sizeof(afs_int32);
1360 stp = ain; /* remember where the ticket is */
1361 if (i < 0 || i > MAXKTCTICKETLEN)
1362 return EINVAL; /* malloc may fail */
1364 ain += i; /* skip over ticket */
1365 memcpy((char *)&i, ain, sizeof(afs_int32));
1366 ain += sizeof(afs_int32);
1367 if (i != sizeof(struct ClearToken)) {
1370 memcpy((char *)&clear, ain, sizeof(struct ClearToken));
1371 if (clear.AuthHandle == -1)
1372 clear.AuthHandle = 999; /* more rxvab compat stuff */
1373 ain += sizeof(struct ClearToken);
1374 if (ainSize != 2 * sizeof(afs_int32) + stLen + sizeof(struct ClearToken)) {
1375 /* still stuff left? we've got primary flag and cell name. Set these */
1376 memcpy((char *)&flag, ain, sizeof(afs_int32)); /* primary id flag */
1377 ain += sizeof(afs_int32); /* skip id field */
1378 /* rest is cell name, look it up */
1379 /* some versions of gcc appear to need != 0 in order to get this right */
1380 if ((flag & 0x8000) != 0) { /* XXX Use Constant XXX */
1384 tcell = afs_GetCellByName(ain, READ_LOCK);
1388 /* default to primary cell, primary id */
1389 flag = 1; /* primary id */
1390 tcell = afs_GetPrimaryCell(READ_LOCK);
1395 afs_PutCell(tcell, READ_LOCK);
1396 if (set_parent_pag) {
1398 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1399 #if defined(AFS_DARWIN_ENV)
1400 struct proc *p = current_proc(); /* XXX */
1402 struct proc *p = curproc; /* XXX */
1404 #ifndef AFS_DARWIN80_ENV
1405 uprintf("Process %d (%s) tried to change pags in PSetTokens\n",
1406 p->p_pid, p->p_comm);
1408 if (!setpag(p, acred, -1, &pag, 1)) {
1411 if (!setpag(u.u_procp, acred, -1, &pag, 1)) { /* XXX u.u_procp is a no-op XXX */
1413 if (!setpag(acred, -1, &pag, 1)) {
1416 afs_InitReq(&treq, *acred);
1420 /* now we just set the tokens */
1421 tu = afs_GetUser(areq->uid, i, WRITE_LOCK); /* i has the cell # */
1422 tu->vid = clear.ViceId;
1423 if (tu->stp != NULL) {
1424 afs_osi_Free(tu->stp, tu->stLen);
1426 tu->stp = (char *)afs_osi_Alloc(stLen);
1427 if (tu->stp == NULL) {
1431 memcpy(tu->stp, stp, stLen);
1434 afs_stats_cmfullperf.authent.TicketUpdates++;
1435 afs_ComputePAGStats();
1436 #endif /* AFS_NOSTATS */
1437 tu->states |= UHasTokens;
1438 tu->states &= ~UTokensBad;
1439 afs_SetPrimary(tu, flag);
1440 tu->tokenTime = osi_Time();
1441 afs_ResetUserConns(tu);
1442 afs_PutUser(tu, WRITE_LOCK);
1457 DECL_PIOCTL(PGetVolumeStatus)
1460 char *offLineMsg = afs_osi_Alloc(256);
1461 char *motd = afs_osi_Alloc(256);
1462 register struct conn *tc;
1463 register afs_int32 code = 0;
1464 struct AFSFetchVolumeStatus volstat;
1466 char *Name, *OfflineMsg, *MOTD;
1469 AFS_STATCNT(PGetVolumeStatus);
1475 OfflineMsg = offLineMsg;
1478 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1480 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS);
1483 RXAFS_GetVolumeStatus(tc->id, avc->fid.Fid.Volume, &volstat,
1484 &Name, &OfflineMsg, &MOTD);
1489 } while (afs_Analyze
1490 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS,
1491 SHARED_LOCK, NULL));
1495 /* Copy all this junk into msg->im_data, keeping track of the lengths. */
1497 memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
1498 cp += sizeof(VolumeStatus);
1499 strcpy(cp, volName);
1500 cp += strlen(volName) + 1;
1501 strcpy(cp, offLineMsg);
1502 cp += strlen(offLineMsg) + 1;
1504 cp += strlen(motd) + 1;
1505 *aoutSize = (cp - aout);
1507 afs_osi_Free(offLineMsg, 256);
1508 afs_osi_Free(motd, 256);
1512 DECL_PIOCTL(PSetVolumeStatus)
1515 char *offLineMsg = afs_osi_Alloc(256);
1516 char *motd = afs_osi_Alloc(256);
1517 register struct conn *tc;
1518 register afs_int32 code = 0;
1519 struct AFSFetchVolumeStatus volstat;
1520 struct AFSStoreVolumeStatus storeStat;
1521 register struct volume *tvp;
1525 AFS_STATCNT(PSetVolumeStatus);
1531 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
1533 if (tvp->states & (VRO | VBackup)) {
1534 afs_PutVolume(tvp, READ_LOCK);
1538 afs_PutVolume(tvp, READ_LOCK);
1543 /* Copy the junk out, using cp as a roving pointer. */
1545 memcpy((char *)&volstat, cp, sizeof(AFSFetchVolumeStatus));
1546 cp += sizeof(AFSFetchVolumeStatus);
1547 if (strlen(cp) >= sizeof(volName)) {
1551 strcpy(volName, cp);
1552 cp += strlen(volName) + 1;
1553 if (strlen(cp) >= sizeof(offLineMsg)) {
1557 strcpy(offLineMsg, cp);
1558 cp += strlen(offLineMsg) + 1;
1559 if (strlen(cp) >= sizeof(motd)) {
1565 if (volstat.MinQuota != -1) {
1566 storeStat.MinQuota = volstat.MinQuota;
1567 storeStat.Mask |= AFS_SETMINQUOTA;
1569 if (volstat.MaxQuota != -1) {
1570 storeStat.MaxQuota = volstat.MaxQuota;
1571 storeStat.Mask |= AFS_SETMAXQUOTA;
1574 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1576 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS);
1579 RXAFS_SetVolumeStatus(tc->id, avc->fid.Fid.Volume, &storeStat,
1580 volName, offLineMsg, motd);
1585 } while (afs_Analyze
1586 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS,
1587 SHARED_LOCK, NULL));
1591 /* we are sending parms back to make compat. with prev system. should
1592 * change interface later to not ask for current status, just set new status */
1594 memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
1595 cp += sizeof(VolumeStatus);
1596 strcpy(cp, volName);
1597 cp += strlen(volName) + 1;
1598 strcpy(cp, offLineMsg);
1599 cp += strlen(offLineMsg) + 1;
1601 cp += strlen(motd) + 1;
1602 *aoutSize = cp - aout;
1604 afs_osi_Free(offLineMsg, 256);
1605 afs_osi_Free(motd, 256);
1611 AFS_STATCNT(PFlush);
1614 #ifdef AFS_BOZONLOCK_ENV
1615 afs_BozonLock(&avc->pvnLock, avc); /* Since afs_TryToSmush will do a pvn_vptrunc */
1617 ObtainWriteLock(&avc->lock, 225);
1618 ObtainWriteLock(&afs_xcbhash, 456);
1619 afs_DequeueCallback(avc);
1620 avc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
1621 ReleaseWriteLock(&afs_xcbhash);
1622 /* now find the disk cache entries */
1623 afs_TryToSmush(avc, *acred, 1);
1624 osi_dnlc_purgedp(avc);
1625 if (avc->linkData && !(avc->states & CCore)) {
1626 afs_osi_Free(avc->linkData, strlen(avc->linkData) + 1);
1627 avc->linkData = NULL;
1629 ReleaseWriteLock(&avc->lock);
1630 #ifdef AFS_BOZONLOCK_ENV
1631 afs_BozonUnlock(&avc->pvnLock, avc);
1636 DECL_PIOCTL(PNewStatMount)
1638 register afs_int32 code;
1639 register struct vcache *tvc;
1640 register struct dcache *tdc;
1641 struct VenusFid tfid;
1643 struct sysname_info sysState;
1644 afs_size_t offset, len;
1646 AFS_STATCNT(PNewStatMount);
1649 code = afs_VerifyVCache(avc, areq);
1652 if (vType(avc) != VDIR) {
1655 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
1658 Check_AtSys(avc, ain, &sysState, areq);
1659 ObtainReadLock(&tdc->lock);
1661 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
1662 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
1663 ReleaseReadLock(&tdc->lock);
1664 afs_PutDCache(tdc); /* we're done with the data */
1665 bufp = sysState.name;
1669 tfid.Cell = avc->fid.Cell;
1670 tfid.Fid.Volume = avc->fid.Fid.Volume;
1671 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
1672 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
1674 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
1680 if (tvc->mvstat != 1) {
1685 ObtainWriteLock(&tvc->lock, 226);
1686 code = afs_HandleLink(tvc, areq);
1688 if (tvc->linkData) {
1689 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
1692 /* we have the data */
1693 strcpy(aout, tvc->linkData);
1694 *aoutSize = strlen(tvc->linkData) + 1;
1699 ReleaseWriteLock(&tvc->lock);
1702 if (sysState.allocked)
1703 osi_FreeLargeSpace(bufp);
1707 DECL_PIOCTL(PGetTokens)
1709 register struct cell *tcell;
1710 register afs_int32 i;
1711 register struct unixuser *tu;
1716 AFS_STATCNT(PGetTokens);
1717 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1718 return EIO; /* Inappropriate ioctl for device */
1720 /* weird interface. If input parameter is present, it is an integer and
1721 * we're supposed to return the parm'th tokens for this unix uid.
1722 * If not present, we just return tokens for cell 1.
1723 * If counter out of bounds, return EDOM.
1724 * If no tokens for the particular cell, return ENOTCONN.
1725 * Also, if this mysterious parm is present, we return, along with the
1726 * tokens, the primary cell indicator (an afs_int32 0) and the cell name
1727 * at the end, in that order.
1729 if ((newStyle = (ainSize > 0))) {
1730 memcpy((char *)&iterator, ain, sizeof(afs_int32));
1732 i = UHash(areq->uid);
1733 ObtainReadLock(&afs_xuser);
1734 for (tu = afs_users[i]; tu; tu = tu->next) {
1736 if (tu->uid == areq->uid && (tu->states & UHasTokens)) {
1737 if (iterator-- == 0)
1738 break; /* are we done yet? */
1741 if (tu->uid == areq->uid && afs_IsPrimaryCellNum(tu->cell))
1747 * No need to hold a read lock on each user entry
1751 ReleaseReadLock(&afs_xuser);
1756 if (((tu->states & UHasTokens) == 0)
1757 || (tu->ct.EndTimestamp < osi_Time())) {
1758 tu->states |= (UTokensBad | UNeedsReset);
1759 afs_PutUser(tu, READ_LOCK);
1762 /* use iterator for temp */
1764 iterator = tu->stLen; /* for compat, we try to return 56 byte tix if they fit */
1766 iterator = 56; /* # of bytes we're returning */
1767 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1768 cp += sizeof(afs_int32);
1769 memcpy(cp, tu->stp, tu->stLen); /* copy out st */
1771 iterator = sizeof(struct ClearToken);
1772 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1773 cp += sizeof(afs_int32);
1774 memcpy(cp, (char *)&tu->ct, sizeof(struct ClearToken));
1775 cp += sizeof(struct ClearToken);
1777 /* put out primary id and cell name, too */
1778 iterator = (tu->states & UPrimary ? 1 : 0);
1779 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1780 cp += sizeof(afs_int32);
1781 tcell = afs_GetCell(tu->cell, READ_LOCK);
1783 strcpy(cp, tcell->cellName);
1784 cp += strlen(tcell->cellName) + 1;
1785 afs_PutCell(tcell, READ_LOCK);
1789 *aoutSize = cp - aout;
1790 afs_PutUser(tu, READ_LOCK);
1796 register afs_int32 i;
1797 register struct unixuser *tu;
1799 AFS_STATCNT(PUnlog);
1800 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1801 return EIO; /* Inappropriate ioctl for device */
1803 i = UHash(areq->uid);
1804 ObtainWriteLock(&afs_xuser, 227);
1805 for (tu = afs_users[i]; tu; tu = tu->next) {
1806 if (tu->uid == areq->uid) {
1808 tu->states &= ~UHasTokens;
1809 /* security is not having to say you're sorry */
1810 memset((char *)&tu->ct, 0, sizeof(struct ClearToken));
1812 ReleaseWriteLock(&afs_xuser);
1813 /* We have to drop the lock over the call to afs_ResetUserConns, since
1814 * it obtains the afs_xvcache lock. We could also keep the lock, and
1815 * modify ResetUserConns to take parm saying we obtained the lock
1816 * already, but that is overkill. By keeping the "tu" pointer
1817 * held over the released lock, we guarantee that we won't lose our
1818 * place, and that we'll pass over every user conn that existed when
1819 * we began this call.
1821 afs_ResetUserConns(tu);
1823 ObtainWriteLock(&afs_xuser, 228);
1825 /* set the expire times to 0, causes
1826 * afs_GCUserData to remove this entry
1828 tu->ct.EndTimestamp = 0;
1830 #endif /* UKERNEL */
1833 ReleaseWriteLock(&afs_xuser);
1837 DECL_PIOCTL(PMariner)
1839 afs_int32 newHostAddr;
1840 afs_int32 oldHostAddr;
1842 AFS_STATCNT(PMariner);
1844 memcpy((char *)&oldHostAddr, (char *)&afs_marinerHost,
1847 oldHostAddr = 0xffffffff; /* disabled */
1849 memcpy((char *)&newHostAddr, ain, sizeof(afs_int32));
1850 if (newHostAddr == 0xffffffff) {
1851 /* disable mariner operations */
1853 } else if (newHostAddr) {
1855 afs_marinerHost = newHostAddr;
1857 memcpy(aout, (char *)&oldHostAddr, sizeof(afs_int32));
1858 *aoutSize = sizeof(afs_int32);
1862 DECL_PIOCTL(PCheckServers)
1864 register char *cp = 0;
1866 register struct server *ts;
1867 afs_int32 temp, *lp = (afs_int32 *) ain, havecell = 0;
1869 struct chservinfo *pcheck;
1871 AFS_STATCNT(PCheckServers);
1873 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1874 return EIO; /* Inappropriate ioctl for device */
1876 if (*lp == 0x12345678) { /* For afs3.3 version */
1877 pcheck = (struct chservinfo *)ain;
1878 if (pcheck->tinterval >= 0) {
1880 memcpy(cp, (char *)&afs_probe_interval, sizeof(afs_int32));
1881 *aoutSize = sizeof(afs_int32);
1882 if (pcheck->tinterval > 0) {
1883 if (!afs_osi_suser(*acred))
1885 afs_probe_interval = pcheck->tinterval;
1891 temp = pcheck->tflags;
1892 cp = pcheck->tbuffer;
1893 } else { /* For pre afs3.3 versions */
1894 memcpy((char *)&temp, ain, sizeof(afs_int32));
1895 cp = ain + sizeof(afs_int32);
1896 if (ainSize > sizeof(afs_int32))
1901 * 1: fast check, don't contact servers.
1902 * 2: local cell only.
1905 /* have cell name, too */
1906 cellp = afs_GetCellByName(cp, READ_LOCK);
1911 if (!cellp && (temp & 2)) {
1912 /* use local cell */
1913 cellp = afs_GetPrimaryCell(READ_LOCK);
1915 if (!(temp & 1)) { /* if not fast, call server checker routine */
1916 afs_CheckServers(1, cellp); /* check down servers */
1917 afs_CheckServers(0, cellp); /* check up servers */
1919 /* now return the current down server list */
1921 ObtainReadLock(&afs_xserver);
1922 for (i = 0; i < NSERVERS; i++) {
1923 for (ts = afs_servers[i]; ts; ts = ts->next) {
1924 if (cellp && ts->cell != cellp)
1925 continue; /* cell spec'd and wrong */
1926 if ((ts->flags & SRVR_ISDOWN)
1927 && ts->addr->sa_portal != ts->cell->vlport) {
1928 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
1929 cp += sizeof(afs_int32);
1933 ReleaseReadLock(&afs_xserver);
1935 afs_PutCell(cellp, READ_LOCK);
1936 *aoutSize = cp - aout;
1940 DECL_PIOCTL(PCheckVolNames)
1942 AFS_STATCNT(PCheckVolNames);
1943 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1944 return EIO; /* Inappropriate ioctl for device */
1946 afs_CheckRootVolume();
1947 afs_CheckVolumeNames(AFS_VOLCHECK_FORCE | AFS_VOLCHECK_EXPIRED |
1948 AFS_VOLCHECK_BUSY | AFS_VOLCHECK_MTPTS);
1952 DECL_PIOCTL(PCheckAuth)
1957 struct unixuser *tu;
1960 AFS_STATCNT(PCheckAuth);
1961 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1962 return EIO; /* Inappropriate ioctl for device */
1965 tu = afs_GetUser(areq->uid, 1, READ_LOCK); /* check local cell authentication */
1969 /* we have a user */
1970 ObtainReadLock(&afs_xsrvAddr);
1971 ObtainReadLock(&afs_xconn);
1973 /* any tokens set? */
1974 if ((tu->states & UHasTokens) == 0)
1976 /* all connections in cell 1 working? */
1977 for (i = 0; i < NSERVERS; i++) {
1978 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
1979 for (tc = sa->conns; tc; tc = tc->next) {
1980 if (tc->user == tu && (tu->states & UTokensBad))
1985 ReleaseReadLock(&afs_xsrvAddr);
1986 ReleaseReadLock(&afs_xconn);
1987 afs_PutUser(tu, READ_LOCK);
1989 memcpy(aout, (char *)&retValue, sizeof(afs_int32));
1990 *aoutSize = sizeof(afs_int32);
1995 Prefetch(char *apath, struct afs_ioctl *adata, int afollow,
1996 struct AFS_UCRED *acred)
1999 register afs_int32 code;
2000 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2006 AFS_STATCNT(Prefetch);
2009 tp = osi_AllocLargeSpace(1024);
2010 AFS_COPYINSTR(apath, tp, 1024, &bufferSize, code);
2012 osi_FreeLargeSpace(tp);
2015 if (afs_BBusy()) { /* do this as late as possible */
2016 osi_FreeLargeSpace(tp);
2017 return EWOULDBLOCK; /* pretty close */
2019 afs_BQueue(BOP_PATH, (struct vcache *)0, 0, 0, acred, (afs_size_t) 0,
2020 (afs_size_t) 0, tp);
2024 DECL_PIOCTL(PFindVolume)
2026 register struct volume *tvp;
2027 register struct server *ts;
2028 register afs_int32 i;
2031 AFS_STATCNT(PFindVolume);
2034 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
2037 for (i = 0; i < MAXHOSTS; i++) {
2038 ts = tvp->serverHost[i];
2041 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
2042 cp += sizeof(afs_int32);
2045 /* still room for terminating NULL, add it on */
2046 ainSize = 0; /* reuse vbl */
2047 memcpy(cp, (char *)&ainSize, sizeof(afs_int32));
2048 cp += sizeof(afs_int32);
2050 *aoutSize = cp - aout;
2051 afs_PutVolume(tvp, READ_LOCK);
2057 DECL_PIOCTL(PViceAccess)
2059 register afs_int32 code;
2062 AFS_STATCNT(PViceAccess);
2065 code = afs_VerifyVCache(avc, areq);
2068 memcpy((char *)&temp, ain, sizeof(afs_int32));
2069 code = afs_AccessOK(avc, temp, areq, CHECK_MODE_BITS);
2076 DECL_PIOCTL(PPrecache)
2080 /*AFS_STATCNT(PPrecache);*/
2081 if (!afs_osi_suser(*acred))
2083 memcpy((char *)&newValue, ain, sizeof(afs_int32));
2084 afs_preCache = newValue*1024;
2088 DECL_PIOCTL(PSetCacheSize)
2093 AFS_STATCNT(PSetCacheSize);
2094 if (!afs_osi_suser(*acred))
2096 /* too many things are setup initially in mem cache version */
2097 if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
2099 memcpy((char *)&newValue, ain, sizeof(afs_int32));
2101 afs_cacheBlocks = afs_stats_cmperf.cacheBlocksOrig;
2103 if (newValue < afs_min_cache)
2104 afs_cacheBlocks = afs_min_cache;
2106 afs_cacheBlocks = newValue;
2108 afs_stats_cmperf.cacheBlocksTotal = afs_cacheBlocks;
2109 afs_ComputeCacheParms(); /* recompute basic cache parameters */
2110 afs_MaybeWakeupTruncateDaemon();
2111 while (waitcnt++ < 100 && afs_cacheBlocks < afs_blocksUsed) {
2112 afs_osi_Wait(1000, 0, 0);
2113 afs_MaybeWakeupTruncateDaemon();
2118 #define MAXGCSTATS 16
2119 DECL_PIOCTL(PGetCacheSize)
2121 afs_int32 results[MAXGCSTATS];
2123 register struct dcache * tdc;
2126 AFS_STATCNT(PGetCacheSize);
2128 if (sizeof(afs_int32) == ainSize){
2129 memcpy((char *)&flags, ain, sizeof(afs_int32));
2130 } else if (0 == ainSize){
2136 memset((char *)results, 0, sizeof(results));
2137 results[0] = afs_cacheBlocks;
2138 results[1] = afs_blocksUsed;
2139 results[2] = afs_cacheFiles;
2142 for (i = 0; i < afs_cacheFiles; i++) {
2143 if (afs_indexFlags[i] & IFFree) results[3]++;
2145 } else if (2 == flags){
2146 for (i = 0; i < afs_cacheFiles; i++) {
2147 if (afs_indexFlags[i] & IFFree) results[3]++;
2148 if (afs_indexFlags[i] & IFEverUsed) results[4]++;
2149 if (afs_indexFlags[i] & IFDataMod) results[5]++;
2150 if (afs_indexFlags[i] & IFDirtyPages) results[6]++;
2151 if (afs_indexFlags[i] & IFAnyPages) results[7]++;
2152 if (afs_indexFlags[i] & IFDiscarded) results[8]++;
2154 tdc = afs_indexTable[i];
2157 size = tdc->validPos;
2158 if ( 0 < size && size < (1<<12) ) results[10]++;
2159 else if (size < (1<<14) ) results[11]++;
2160 else if (size < (1<<16) ) results[12]++;
2161 else if (size < (1<<18) ) results[13]++;
2162 else if (size < (1<<20) ) results[14]++;
2163 else if (size >= (1<<20) ) results[15]++;
2167 memcpy(aout, (char *)results, sizeof(results));
2168 *aoutSize = sizeof(results);
2172 DECL_PIOCTL(PRemoveCallBack)
2174 register struct conn *tc;
2175 register afs_int32 code = 0;
2176 struct AFSCallBack CallBacks_Array[1];
2177 struct AFSCBFids theFids;
2178 struct AFSCBs theCBs;
2181 AFS_STATCNT(PRemoveCallBack);
2184 if (avc->states & CRO)
2185 return 0; /* read-only-ness can't change */
2186 ObtainWriteLock(&avc->lock, 229);
2187 theFids.AFSCBFids_len = 1;
2188 theCBs.AFSCBs_len = 1;
2189 theFids.AFSCBFids_val = (struct AFSFid *)&avc->fid.Fid;
2190 theCBs.AFSCBs_val = CallBacks_Array;
2191 CallBacks_Array[0].CallBackType = CB_DROPPED;
2192 if (avc->callback) {
2194 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2196 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
2198 code = RXAFS_GiveUpCallBacks(tc->id, &theFids, &theCBs);
2202 /* don't set code on failure since we wouldn't use it */
2203 } while (afs_Analyze
2204 (tc, code, &avc->fid, areq,
2205 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK, NULL));
2207 ObtainWriteLock(&afs_xcbhash, 457);
2208 afs_DequeueCallback(avc);
2210 avc->states &= ~(CStatd | CUnique);
2211 ReleaseWriteLock(&afs_xcbhash);
2212 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
2213 osi_dnlc_purgedp(avc);
2215 ReleaseWriteLock(&avc->lock);
2219 DECL_PIOCTL(PNewCell)
2221 /* create a new cell */
2222 afs_int32 cellHosts[MAXCELLHOSTS], *lp, magic = 0;
2223 char *newcell = 0, *linkedcell = 0, *tp = ain;
2224 register afs_int32 code, linkedstate = 0, ls;
2225 u_short fsport = 0, vlport = 0;
2228 AFS_STATCNT(PNewCell);
2229 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2230 return EIO; /* Inappropriate ioctl for device */
2232 if (!afs_osi_suser(*acred))
2235 memcpy((char *)&magic, tp, sizeof(afs_int32));
2236 tp += sizeof(afs_int32);
2237 if (magic != 0x12345678)
2240 /* A 3.4 fs newcell command will pass an array of MAXCELLHOSTS
2241 * server addresses while the 3.5 fs newcell command passes
2242 * MAXHOSTS. To figure out which is which, check if the cellname
2245 newcell = tp + (MAXCELLHOSTS + 3) * sizeof(afs_int32);
2246 scount = ((newcell[0] != '\0') ? MAXCELLHOSTS : MAXHOSTS);
2248 /* MAXCELLHOSTS (=8) is less than MAXHOSTS (=13) */
2249 memcpy((char *)cellHosts, tp, MAXCELLHOSTS * sizeof(afs_int32));
2250 tp += (scount * sizeof(afs_int32));
2252 lp = (afs_int32 *) tp;
2256 fsport = 0; /* Privileged ports not allowed */
2258 vlport = 0; /* Privileged ports not allowed */
2259 tp += (3 * sizeof(afs_int32));
2261 if ((ls = *lp) & 1) {
2262 linkedcell = tp + strlen(newcell) + 1;
2263 linkedstate |= CLinkedCell;
2266 linkedstate |= CNoSUID; /* setuid is disabled by default for fs newcell */
2268 afs_NewCell(newcell, cellHosts, linkedstate, linkedcell, fsport,
2273 DECL_PIOCTL(PNewAlias)
2275 /* create a new cell alias */
2277 register afs_int32 code;
2278 char *realName, *aliasName;
2280 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2281 return EIO; /* Inappropriate ioctl for device */
2283 if (!afs_osi_suser(*acred))
2287 tp += strlen(aliasName) + 1;
2290 code = afs_NewCellAlias(aliasName, realName);
2295 DECL_PIOCTL(PListCells)
2297 afs_int32 whichCell;
2298 register struct cell *tcell = 0;
2299 register afs_int32 i;
2300 register char *cp, *tp = ain;
2302 AFS_STATCNT(PListCells);
2303 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2304 return EIO; /* Inappropriate ioctl for device */
2306 memcpy((char *)&whichCell, tp, sizeof(afs_int32));
2307 tp += sizeof(afs_int32);
2308 tcell = afs_GetCellByIndex(whichCell, READ_LOCK);
2311 memset(cp, 0, MAXCELLHOSTS * sizeof(afs_int32));
2312 for (i = 0; i < MAXCELLHOSTS; i++) {
2313 if (tcell->cellHosts[i] == 0)
2315 memcpy(cp, (char *)&tcell->cellHosts[i]->addr->sa_ip,
2317 cp += sizeof(afs_int32);
2319 cp = aout + MAXCELLHOSTS * sizeof(afs_int32);
2320 strcpy(cp, tcell->cellName);
2321 cp += strlen(tcell->cellName) + 1;
2322 *aoutSize = cp - aout;
2323 afs_PutCell(tcell, READ_LOCK);
2331 DECL_PIOCTL(PListAliases)
2333 afs_int32 whichAlias;
2334 register struct cell_alias *tcalias = 0;
2335 register char *cp, *tp = ain;
2337 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2338 return EIO; /* Inappropriate ioctl for device */
2339 if (ainSize < sizeof(afs_int32))
2342 memcpy((char *)&whichAlias, tp, sizeof(afs_int32));
2343 tp += sizeof(afs_int32);
2345 tcalias = afs_GetCellAlias(whichAlias);
2348 strcpy(cp, tcalias->alias);
2349 cp += strlen(tcalias->alias) + 1;
2350 strcpy(cp, tcalias->cell);
2351 cp += strlen(tcalias->cell) + 1;
2352 *aoutSize = cp - aout;
2353 afs_PutCellAlias(tcalias);
2361 DECL_PIOCTL(PRemoveMount)
2363 register afs_int32 code;
2365 struct sysname_info sysState;
2366 afs_size_t offset, len;
2367 register struct conn *tc;
2368 register struct dcache *tdc;
2369 register struct vcache *tvc;
2370 struct AFSFetchStatus OutDirStatus;
2371 struct VenusFid tfid;
2372 struct AFSVolSync tsync;
2376 /* "ain" is the name of the file in this dir to remove */
2378 AFS_STATCNT(PRemoveMount);
2381 code = afs_VerifyVCache(avc, areq);
2384 if (vType(avc) != VDIR)
2387 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1); /* test for error below */
2390 Check_AtSys(avc, ain, &sysState, areq);
2391 ObtainReadLock(&tdc->lock);
2393 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
2394 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
2395 ReleaseReadLock(&tdc->lock);
2396 bufp = sysState.name;
2401 tfid.Cell = avc->fid.Cell;
2402 tfid.Fid.Volume = avc->fid.Fid.Volume;
2403 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
2404 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
2406 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
2413 if (tvc->mvstat != 1) {
2419 ObtainWriteLock(&tvc->lock, 230);
2420 code = afs_HandleLink(tvc, areq);
2422 if (tvc->linkData) {
2423 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
2428 ReleaseWriteLock(&tvc->lock);
2429 osi_dnlc_purgedp(tvc);
2435 ObtainWriteLock(&avc->lock, 231);
2436 osi_dnlc_remove(avc, bufp, tvc);
2438 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2440 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE);
2443 RXAFS_RemoveFile(tc->id, (struct AFSFid *)&avc->fid.Fid, bufp,
2444 &OutDirStatus, &tsync);
2449 } while (afs_Analyze
2450 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_REMOVEFILE,
2451 SHARED_LOCK, NULL));
2456 ReleaseWriteLock(&avc->lock);
2460 /* we have the thing in the cache */
2461 ObtainWriteLock(&tdc->lock, 661);
2462 if (afs_LocalHero(avc, tdc, &OutDirStatus, 1)) {
2463 /* we can do it locally */
2464 code = afs_dir_Delete(tdc, bufp);
2466 ZapDCE(tdc); /* surprise error -- invalid value */
2470 ReleaseWriteLock(&tdc->lock);
2471 afs_PutDCache(tdc); /* drop ref count */
2473 avc->states &= ~CUnique; /* For the dfs xlator */
2474 ReleaseWriteLock(&avc->lock);
2477 if (sysState.allocked)
2478 osi_FreeLargeSpace(bufp);
2482 DECL_PIOCTL(PVenusLogging)
2484 return EINVAL; /* OBSOLETE */
2487 DECL_PIOCTL(PGetCellStatus)
2489 register struct cell *tcell;
2492 AFS_STATCNT(PGetCellStatus);
2493 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2494 return EIO; /* Inappropriate ioctl for device */
2496 tcell = afs_GetCellByName(ain, READ_LOCK);
2499 temp = tcell->states;
2500 afs_PutCell(tcell, READ_LOCK);
2501 memcpy(aout, (char *)&temp, sizeof(afs_int32));
2502 *aoutSize = sizeof(afs_int32);
2506 DECL_PIOCTL(PSetCellStatus)
2508 register struct cell *tcell;
2511 if (!afs_osi_suser(*acred))
2513 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2514 return EIO; /* Inappropriate ioctl for device */
2516 tcell = afs_GetCellByName(ain + 2 * sizeof(afs_int32), WRITE_LOCK);
2519 memcpy((char *)&temp, ain, sizeof(afs_int32));
2521 tcell->states |= CNoSUID;
2523 tcell->states &= ~CNoSUID;
2524 afs_PutCell(tcell, WRITE_LOCK);
2528 DECL_PIOCTL(PFlushVolumeData)
2530 register afs_int32 i;
2531 register struct dcache *tdc;
2532 register struct vcache *tvc;
2533 register struct volume *tv;
2534 afs_int32 cell, volume;
2535 struct afs_q *tq, *uq;
2536 #ifdef AFS_DARWIN80_ENV
2540 AFS_STATCNT(PFlushVolumeData);
2543 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2544 return EIO; /* Inappropriate ioctl for device */
2546 volume = avc->fid.Fid.Volume; /* who to zap */
2547 cell = avc->fid.Cell;
2550 * Clear stat'd flag from all vnodes from this volume; this will invalidate all
2551 * the vcaches associated with the volume.
2554 ObtainReadLock(&afs_xvcache);
2555 i = VCHashV(&avc->fid);
2556 for (tq = afs_vhashTV[i].prev; tq != &afs_vhashTV[i]; tq = uq) {
2559 if (tvc->fid.Fid.Volume == volume && tvc->fid.Cell == cell) {
2560 if (tvc->states & CVInit) {
2561 ReleaseReadLock(&afs_xvcache);
2562 afs_osi_Sleep(&tvc->states);
2565 #ifdef AFS_DARWIN80_ENV
2566 if (tvc->states & CDeadVnode) {
2567 ReleaseReadLock(&afs_xvcache);
2568 afs_osi_Sleep(&tvc->states);
2572 #if defined(AFS_SGI_ENV) || defined(AFS_OSF_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
2573 VN_HOLD(AFSTOV(tvc));
2575 #ifdef AFS_DARWIN80_ENV
2579 if (vnode_ref(vp)) {
2586 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2589 VREFCOUNT_INC(tvc); /* AIX, apparently */
2593 ReleaseReadLock(&afs_xvcache);
2594 #ifdef AFS_BOZONLOCK_ENV
2595 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
2597 ObtainWriteLock(&tvc->lock, 232);
2599 ObtainWriteLock(&afs_xcbhash, 458);
2600 afs_DequeueCallback(tvc);
2601 tvc->states &= ~(CStatd | CDirty);
2602 ReleaseWriteLock(&afs_xcbhash);
2603 if (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
2604 osi_dnlc_purgedp(tvc);
2605 afs_TryToSmush(tvc, *acred, 1);
2606 ReleaseWriteLock(&tvc->lock);
2607 #ifdef AFS_BOZONLOCK_ENV
2608 afs_BozonUnlock(&tvc->pvnLock, tvc);
2610 #ifdef AFS_DARWIN80_ENV
2611 vnode_put(AFSTOV(tvc));
2613 ObtainReadLock(&afs_xvcache);
2615 /* our tvc ptr is still good until now */
2619 ReleaseReadLock(&afs_xvcache);
2622 MObtainWriteLock(&afs_xdcache, 328); /* needed if you're going to flush any stuff */
2623 for (i = 0; i < afs_cacheFiles; i++) {
2624 if (!(afs_indexFlags[i] & IFEverUsed))
2625 continue; /* never had any data */
2626 tdc = afs_GetDSlot(i, NULL);
2627 if (tdc->refCount <= 1) { /* too high, in use by running sys call */
2628 ReleaseReadLock(&tdc->tlock);
2629 if (tdc->f.fid.Fid.Volume == volume && tdc->f.fid.Cell == cell) {
2630 if (!(afs_indexFlags[i] & IFDataMod)) {
2631 /* if the file is modified, but has a ref cnt of only 1, then
2632 * someone probably has the file open and is writing into it.
2633 * Better to skip flushing such a file, it will be brought back
2634 * immediately on the next write anyway.
2636 * If we *must* flush, then this code has to be rearranged to call
2637 * afs_storeAllSegments() first */
2638 afs_FlushDCache(tdc);
2642 ReleaseReadLock(&tdc->tlock);
2644 afs_PutDCache(tdc); /* bumped by getdslot */
2646 MReleaseWriteLock(&afs_xdcache);
2648 ObtainReadLock(&afs_xvolume);
2649 for (i = 0; i < NVOLS; i++) {
2650 for (tv = afs_volumes[i]; tv; tv = tv->next) {
2651 if (tv->volume == volume) {
2652 afs_ResetVolumeInfo(tv);
2657 ReleaseReadLock(&afs_xvolume);
2659 /* probably, a user is doing this, probably, because things are screwed up.
2660 * maybe it's the dnlc's fault? */
2667 DECL_PIOCTL(PGetVnodeXStatus)
2669 register afs_int32 code;
2670 struct vcxstat stat;
2673 /* AFS_STATCNT(PGetVnodeXStatus); */
2676 code = afs_VerifyVCache(avc, areq);
2679 if (vType(avc) == VDIR)
2680 mode = PRSFS_LOOKUP;
2683 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
2686 memset(&stat, 0, sizeof(struct vcxstat));
2687 stat.fid = avc->fid;
2688 hset32(stat.DataVersion, hgetlo(avc->m.DataVersion));
2689 stat.lock = avc->lock;
2690 stat.parentVnode = avc->parentVnode;
2691 stat.parentUnique = avc->parentUnique;
2692 hset(stat.flushDV, avc->flushDV);
2693 hset(stat.mapDV, avc->mapDV);
2694 stat.truncPos = avc->truncPos;
2695 { /* just grab the first two - won't break anything... */
2696 struct axscache *ac;
2698 for (i = 0, ac = avc->Access; ac && i < CPSIZE; i++, ac = ac->next) {
2699 stat.randomUid[i] = ac->uid;
2700 stat.randomAccess[i] = ac->axess;
2703 stat.callback = afs_data_pointer_to_int32(avc->callback);
2704 stat.cbExpires = avc->cbExpires;
2705 stat.anyAccess = avc->anyAccess;
2706 stat.opens = avc->opens;
2707 stat.execsOrWriters = avc->execsOrWriters;
2708 stat.flockCount = avc->flockCount;
2709 stat.mvstat = avc->mvstat;
2710 stat.states = avc->states;
2711 memcpy(aout, (char *)&stat, sizeof(struct vcxstat));
2712 *aoutSize = sizeof(struct vcxstat);
2717 DECL_PIOCTL(PGetVnodeXStatus2)
2719 register afs_int32 code;
2720 struct vcxstat2 stat;
2725 code = afs_VerifyVCache(avc, areq);
2728 if (vType(avc) == VDIR)
2729 mode = PRSFS_LOOKUP;
2732 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
2735 memset(&stat, 0, sizeof(struct vcxstat2));
2737 stat.cbExpires = avc->cbExpires;
2738 stat.anyAccess = avc->anyAccess;
2739 stat.mvstat = avc->mvstat;
2740 stat.callerAccess = afs_GetAccessBits(avc, ~0, areq);
2742 memcpy(aout, (char *)&stat, sizeof(struct vcxstat2));
2743 *aoutSize = sizeof(struct vcxstat2);
2747 /* We require root for local sysname changes, but not for remote */
2748 /* (since we don't really believe remote uids anyway) */
2749 /* outname[] shouldn't really be needed- this is left as an excercise */
2750 /* for the reader. */
2751 DECL_PIOCTL(PSetSysName)
2753 char *cp, *cp2 = NULL, inname[MAXSYSNAME], outname[MAXSYSNAME];
2754 afs_int32 setsysname;
2756 register struct afs_exporter *exporter;
2757 register struct unixuser *au;
2758 register afs_int32 pag, error;
2759 int t, count, num = 0, allpags = 0;
2762 AFS_STATCNT(PSetSysName);
2763 if (!afs_globalVFS) {
2764 /* Afsd is NOT running; disable it */
2765 #if defined(KERNEL_HAVE_UERROR)
2766 return (setuerror(EINVAL), EINVAL);
2771 memset(inname, 0, MAXSYSNAME);
2772 memcpy(&setsysname, ain, sizeof(afs_int32));
2773 ain += sizeof(afs_int32);
2774 if (setsysname & 0x8000) {
2776 setsysname &= ~0x8000;
2781 if (setsysname < 0 || setsysname > MAXNUMSYSNAMES)
2784 for (cp = ain, count = 0; count < setsysname; count++) {
2785 /* won't go past end of ain since maxsysname*num < ain length */
2787 if (t >= MAXSYSNAME || t <= 0)
2789 /* check for names that can shoot us in the foot */
2790 if (*cp == '.' && (cp[1] == 0 || (cp[1] == '.' && cp[2] == 0)))
2796 /* inname gets first entry in case we're being a translator */
2798 memcpy(inname, ain, t + 1); /* include terminating null */
2802 if ((*acred)->cr_gid == RMTUSER_REQ ||
2803 (*acred)->cr_gid == RMTUSER_REQ_PRIV) { /* Handles all exporters */
2804 if (allpags && (*acred)->cr_gid != RMTUSER_REQ_PRIV) {
2807 pag = PagInCred(*acred);
2809 return EINVAL; /* Better than panicing */
2811 if (!(au = afs_FindUser(pag, -1, READ_LOCK))) {
2812 return EINVAL; /* Better than panicing */
2814 if (!(exporter = au->exporter)) {
2815 afs_PutUser(au, READ_LOCK);
2816 return EINVAL; /* Better than panicing */
2818 error = EXP_SYSNAME(exporter, (setsysname ? cp2 : NULL), &sysnamelist,
2821 if (error == ENODEV)
2822 foundname = 0; /* sysname not set yet! */
2824 afs_PutUser(au, READ_LOCK);
2829 strcpy(outname, sysnamelist[0]);
2831 afs_PutUser(au, READ_LOCK);
2835 /* Not xlating, so local case */
2837 osi_Panic("PSetSysName: !afs_sysname\n");
2838 if (!setsysname) { /* user just wants the info */
2839 strcpy(outname, afs_sysname);
2840 foundname = afs_sysnamecount;
2841 sysnamelist = afs_sysnamelist;
2842 } else { /* Local guy; only root can change sysname */
2843 if (!afs_osi_suser(*acred))
2846 /* allpags makes no sense for local use */
2850 /* clear @sys entries from the dnlc, once afs_lookup can
2851 * do lookups of @sys entries and thinks it can trust them */
2852 /* privs ok, store the entry, ... */
2853 strcpy(afs_sysname, inname);
2854 if (setsysname > 1) { /* ... or list */
2856 for (count = 1; count < setsysname; ++count) {
2857 if (!afs_sysnamelist[count])
2859 ("PSetSysName: no afs_sysnamelist entry to write\n");
2861 memcpy(afs_sysnamelist[count], cp, t + 1); /* include null */
2865 afs_sysnamecount = setsysname;
2870 cp = aout; /* not changing so report back the count and ... */
2871 memcpy(cp, (char *)&foundname, sizeof(afs_int32));
2872 cp += sizeof(afs_int32);
2874 strcpy(cp, outname); /* ... the entry, ... */
2875 cp += strlen(outname) + 1;
2876 for (count = 1; count < foundname; ++count) { /* ... or list. */
2877 if (!sysnamelist[count])
2879 ("PSetSysName: no afs_sysnamelist entry to read\n");
2880 t = strlen(sysnamelist[count]);
2881 if (t >= MAXSYSNAME)
2882 osi_Panic("PSetSysName: sysname entry garbled\n");
2883 strcpy(cp, sysnamelist[count]);
2887 *aoutSize = cp - aout;
2892 /* sequential search through the list of touched cells is not a good
2893 * long-term solution here. For small n, though, it should be just
2894 * fine. Should consider special-casing the local cell for large n.
2895 * Likewise for PSetSPrefs.
2897 * s - number of ids in array l[] -- NOT index of last id
2898 * l - array of cell ids which have volumes that need to be sorted
2899 * vlonly - sort vl servers or file servers?
2902 ReSortCells_cb(struct cell *cell, void *arg)
2904 afs_int32 *p = (afs_int32 *) arg;
2905 afs_int32 *l = p + 1;
2908 for (i = 0; i < s; i++) {
2909 if (l[i] == cell->cellNum) {
2910 ObtainWriteLock(&cell->lock, 690);
2911 afs_SortServers(cell->cellHosts, MAXCELLHOSTS);
2912 ReleaseWriteLock(&cell->lock);
2920 ReSortCells(int s, afs_int32 * l, int vlonly)
2928 p = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * (s + 1));
2930 memcpy(p + 1, l, s * sizeof(afs_int32));
2931 afs_TraverseCells(&ReSortCells_cb, p);
2932 afs_osi_Free(p, sizeof(afs_int32) * (s + 1));
2936 ObtainReadLock(&afs_xvolume);
2937 for (i = 0; i < NVOLS; i++) {
2938 for (j = afs_volumes[i]; j; j = j->next) {
2939 for (k = 0; k < s; k++)
2940 if (j->cell == l[k]) {
2941 ObtainWriteLock(&j->lock, 233);
2942 afs_SortServers(j->serverHost, MAXHOSTS);
2943 ReleaseWriteLock(&j->lock);
2948 ReleaseReadLock(&afs_xvolume);
2952 static int debugsetsp = 0;
2954 afs_setsprefs(sp, num, vlonly)
2957 unsigned int vlonly;
2960 int i, j, k, matches, touchedSize;
2961 struct server *srvr = NULL;
2962 afs_int32 touched[34];
2966 for (k = 0; k < num; sp++, k++) {
2968 printf("sp host=%x, rank=%d\n", sp->host.s_addr, sp->rank);
2971 ObtainReadLock(&afs_xserver);
2973 i = SHash(sp->host.s_addr);
2974 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2975 if (sa->sa_ip == sp->host.s_addr) {
2977 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
2978 || (sa->sa_portal == AFS_FSPORT);
2979 if ((!vlonly && isfs) || (vlonly && !isfs)) {
2986 if (sa && matches) { /* found one! */
2988 printf("sa ip=%x, ip_rank=%d\n", sa->sa_ip, sa->sa_iprank);
2990 sa->sa_iprank = sp->rank + afs_randomMod15();
2991 afs_SortOneServer(sa->server);
2994 /* if we don't know yet what cell it's in, this is moot */
2995 for (j = touchedSize - 1;
2996 j >= 0 && touched[j] != srvr->cell->cellNum; j--)
2997 /* is it in our list of touched cells ? */ ;
2998 if (j < 0) { /* no, it's not */
2999 touched[touchedSize++] = srvr->cell->cellNum;
3000 if (touchedSize >= 32) { /* watch for ovrflow */
3001 ReleaseReadLock(&afs_xserver);
3002 ReSortCells(touchedSize, touched, vlonly);
3004 ObtainReadLock(&afs_xserver);
3010 ReleaseReadLock(&afs_xserver);
3011 /* if we didn't find one, start to create one. */
3012 /* Note that it doesn't have a cell yet... */
3014 afs_uint32 temp = sp->host.s_addr;
3016 afs_GetServer(&temp, 1, 0, (vlonly ? AFS_VLPORT : AFS_FSPORT),
3017 WRITE_LOCK, (afsUUID *) 0, 0);
3018 srvr->addr->sa_iprank = sp->rank + afs_randomMod15();
3019 afs_PutServer(srvr, WRITE_LOCK);
3021 } /* for all cited preferences */
3023 ReSortCells(touchedSize, touched, vlonly);
3027 /* Note that this may only be performed by the local root user.
3029 DECL_PIOCTL(PSetSPrefs)
3031 struct setspref *ssp;
3032 AFS_STATCNT(PSetSPrefs);
3034 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3035 return EIO; /* Inappropriate ioctl for device */
3037 if (!afs_osi_suser(*acred))
3040 if (ainSize < sizeof(struct setspref))
3043 ssp = (struct setspref *)ain;
3044 if (ainSize < sizeof(struct spref) * ssp->num_servers)
3047 afs_setsprefs(&(ssp->servers[0]), ssp->num_servers,
3048 (ssp->flags & DBservers));
3052 DECL_PIOCTL(PSetSPrefs33)
3055 AFS_STATCNT(PSetSPrefs);
3056 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3057 return EIO; /* Inappropriate ioctl for device */
3060 if (!afs_osi_suser(*acred))
3063 sp = (struct spref *)ain;
3064 afs_setsprefs(sp, ainSize / (sizeof(struct spref)), 0 /*!vlonly */ );
3068 /* some notes on the following code...
3069 * in the hash table of server structs, all servers with the same IP address
3070 * will be on the same overflow chain.
3071 * This could be sped slightly in some circumstances by having it cache the
3072 * immediately previous slot in the hash table and some supporting information
3073 * Only reports file servers now.
3075 DECL_PIOCTL(PGetSPrefs)
3077 struct sprefrequest *spin; /* input */
3078 struct sprefinfo *spout; /* output */
3079 struct spref *srvout; /* one output component */
3080 int i, j; /* counters for hash table traversal */
3081 struct server *srvr; /* one of CM's server structs */
3083 int vlonly; /* just return vlservers ? */
3086 AFS_STATCNT(PGetSPrefs);
3087 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3088 return EIO; /* Inappropriate ioctl for device */
3091 if (ainSize < sizeof(struct sprefrequest_33)) {
3094 spin = ((struct sprefrequest *)ain);
3097 if (ainSize > sizeof(struct sprefrequest_33)) {
3098 vlonly = (spin->flags & DBservers);
3102 /* struct sprefinfo includes 1 server struct... that size gets added
3103 * in during the loop that follows.
3105 *aoutSize = sizeof(struct sprefinfo) - sizeof(struct spref);
3106 spout = (struct sprefinfo *)aout;
3107 spout->next_offset = spin->offset;
3108 spout->num_servers = 0;
3109 srvout = spout->servers;
3111 ObtainReadLock(&afs_xserver);
3112 for (i = 0, j = 0; j < NSERVERS; j++) { /* sift through hash table */
3113 for (sa = afs_srvAddrs[j]; sa; sa = sa->next_bkt, i++) {
3114 if (spin->offset > (unsigned short)i) {
3115 continue; /* catch up to where we left off */
3117 spout->next_offset++;
3120 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
3121 || (sa->sa_portal == AFS_FSPORT);
3123 if ((vlonly && isfs) || (!vlonly && !isfs)) {
3124 /* only report ranks for vl servers */
3128 srvout->host.s_addr = sa->sa_ip;
3129 srvout->rank = sa->sa_iprank;
3130 *aoutSize += sizeof(struct spref);
3131 spout->num_servers++;
3134 if (*aoutSize > (PIGGYSIZE - sizeof(struct spref))) {
3135 ReleaseReadLock(&afs_xserver); /* no more room! */
3140 ReleaseReadLock(&afs_xserver);
3142 spout->next_offset = 0; /* start over from the beginning next time */
3146 /* Enable/Disable the specified exporter. Must be root to disable an exporter */
3147 int afs_NFSRootOnly = 1;
3148 DECL_PIOCTL(PExportAfs)
3150 afs_int32 export, newint =
3151 0, type, changestate, handleValue, convmode, pwsync, smounts;
3152 afs_int32 rempags = 0, pagcb = 0;
3153 register struct afs_exporter *exporter;
3155 AFS_STATCNT(PExportAfs);
3156 memcpy((char *)&handleValue, ain, sizeof(afs_int32));
3157 type = handleValue >> 24;
3162 exporter = exporter_find(type);
3164 export = handleValue & 3;
3165 changestate = handleValue & 0xfff;
3166 smounts = (handleValue >> 2) & 3;
3167 pwsync = (handleValue >> 4) & 3;
3168 convmode = (handleValue >> 6) & 3;
3169 rempags = (handleValue >> 8) & 3;
3170 pagcb = (handleValue >> 10) & 3;
3172 changestate = (handleValue >> 16) & 0x1;
3173 convmode = (handleValue >> 16) & 0x2;
3174 pwsync = (handleValue >> 16) & 0x4;
3175 smounts = (handleValue >> 16) & 0x8;
3176 export = handleValue & 0xff;
3179 /* Failed finding desired exporter; */
3183 handleValue = exporter->exp_states;
3184 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3185 *aoutSize = sizeof(afs_int32);
3187 if (!afs_osi_suser(*acred))
3188 return EACCES; /* Only superuser can do this */
3192 exporter->exp_states |= EXP_EXPORTED;
3194 exporter->exp_states &= ~EXP_EXPORTED;
3198 exporter->exp_states |= EXP_UNIXMODE;
3200 exporter->exp_states &= ~EXP_UNIXMODE;
3204 exporter->exp_states |= EXP_PWSYNC;
3206 exporter->exp_states &= ~EXP_PWSYNC;
3210 afs_NFSRootOnly = 0;
3211 exporter->exp_states |= EXP_SUBMOUNTS;
3213 afs_NFSRootOnly = 1;
3214 exporter->exp_states &= ~EXP_SUBMOUNTS;
3219 exporter->exp_states |= EXP_CLIPAGS;
3221 exporter->exp_states &= ~EXP_CLIPAGS;
3225 exporter->exp_states |= EXP_CALLBACK;
3227 exporter->exp_states &= ~EXP_CALLBACK;
3229 handleValue = exporter->exp_states;
3230 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3231 *aoutSize = sizeof(afs_int32);
3234 exporter->exp_states |= EXP_EXPORTED;
3236 exporter->exp_states &= ~EXP_EXPORTED;
3238 exporter->exp_states |= EXP_UNIXMODE;
3240 exporter->exp_states &= ~EXP_UNIXMODE;
3242 exporter->exp_states |= EXP_PWSYNC;
3244 exporter->exp_states &= ~EXP_PWSYNC;
3246 afs_NFSRootOnly = 0;
3247 exporter->exp_states |= EXP_SUBMOUNTS;
3249 afs_NFSRootOnly = 1;
3250 exporter->exp_states &= ~EXP_SUBMOUNTS;
3260 struct gaginfo *gagflags;
3262 if (!afs_osi_suser(*acred))
3265 gagflags = (struct gaginfo *)ain;
3266 afs_showflags = gagflags->showflags;
3272 DECL_PIOCTL(PTwiddleRx)
3274 struct rxparams *rxp;
3276 if (!afs_osi_suser(*acred))
3279 rxp = (struct rxparams *)ain;
3281 if (rxp->rx_initReceiveWindow)
3282 rx_initReceiveWindow = rxp->rx_initReceiveWindow;
3283 if (rxp->rx_maxReceiveWindow)
3284 rx_maxReceiveWindow = rxp->rx_maxReceiveWindow;
3285 if (rxp->rx_initSendWindow)
3286 rx_initSendWindow = rxp->rx_initSendWindow;
3287 if (rxp->rx_maxSendWindow)
3288 rx_maxSendWindow = rxp->rx_maxSendWindow;
3289 if (rxp->rxi_nSendFrags)
3290 rxi_nSendFrags = rxp->rxi_nSendFrags;
3291 if (rxp->rxi_nRecvFrags)
3292 rxi_nRecvFrags = rxp->rxi_nRecvFrags;
3293 if (rxp->rxi_OrphanFragSize)
3294 rxi_OrphanFragSize = rxp->rxi_OrphanFragSize;
3295 if (rxp->rx_maxReceiveSize) {
3296 rx_maxReceiveSize = rxp->rx_maxReceiveSize;
3297 rx_maxReceiveSizeUser = rxp->rx_maxReceiveSize;
3299 if (rxp->rx_MyMaxSendSize)
3300 rx_MyMaxSendSize = rxp->rx_MyMaxSendSize;
3305 DECL_PIOCTL(PGetInitParams)
3307 if (sizeof(struct cm_initparams) > PIGGYSIZE)
3310 memcpy(aout, (char *)&cm_initParams, sizeof(struct cm_initparams));
3311 *aoutSize = sizeof(struct cm_initparams);
3315 #ifdef AFS_SGI65_ENV
3316 /* They took crget() from us, so fake it. */
3321 cr = crdup(get_current_cred());
3322 memset((char *)cr, 0, sizeof(cred_t));
3323 #if CELL || CELL_PREPARE
3330 DECL_PIOCTL(PGetRxkcrypt)
3332 memcpy(aout, (char *)&cryptall, sizeof(afs_int32));
3333 *aoutSize = sizeof(afs_int32);
3337 DECL_PIOCTL(PSetRxkcrypt)
3341 if (!afs_osi_suser(*acred))
3343 if (ainSize != sizeof(afs_int32) || ain == NULL)
3345 memcpy((char *)&tmpval, ain, sizeof(afs_int32));
3346 /* if new mappings added later this will need to be changed */
3347 if (tmpval != 0 && tmpval != 1)
3353 #ifdef AFS_NEED_CLIENTCONTEXT
3355 * Create new credentials to correspond to a remote user with given
3356 * <hostaddr, uid, g0, g1>. This allows a server running as root to
3357 * provide pioctl (and other) services to foreign clients (i.e. nfs
3358 * clients) by using this call to `become' the client.
3361 #define PIOCTL_HEADER 6
3363 HandleClientContext(struct afs_ioctl *ablob, int *com,
3364 struct AFS_UCRED **acred, struct AFS_UCRED *credp)
3367 afs_uint32 hostaddr;
3368 afs_int32 uid, g0, g1, i, code, pag, exporter_type, isroot = 0;
3369 struct afs_exporter *exporter, *outexporter;
3370 struct AFS_UCRED *newcred;
3371 struct unixuser *au;
3372 afs_uint32 comp = *com & 0xff00;
3375 #if defined(AFS_SGIMP_ENV)
3376 osi_Assert(ISAFS_GLOCK());
3378 AFS_STATCNT(HandleClientContext);
3379 if (ablob->in_size < PIOCTL_HEADER * sizeof(afs_int32)) {
3380 /* Must at least include the PIOCTL_HEADER header words required by the protocol */
3381 return EINVAL; /* Too small to be good */
3383 ain = inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
3384 AFS_COPYIN(ablob->in, ain, PIOCTL_HEADER * sizeof(afs_int32), code);
3386 osi_FreeLargeSpace(inData);
3390 /* Extract information for remote user */
3391 hostaddr = *((afs_uint32 *) ain);
3392 ain += sizeof(hostaddr);
3393 uid = *((afs_uint32 *) ain);
3395 g0 = *((afs_uint32 *) ain);
3397 g1 = *((afs_uint32 *) ain);
3399 *com = *((afs_uint32 *) ain);
3400 ain += sizeof(afs_int32);
3401 exporter_type = *((afs_uint32 *) ain); /* In case we support more than NFS */
3404 * Of course, one must be root for most of these functions, but
3405 * we'll allow (for knfs) you to set things if the pag is 0 and
3406 * you're setting tokens or unlogging.
3409 if (!afs_osi_suser(credp)) {
3410 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
3411 /* Since SGI's suser() returns explicit failure after the call.. */
3414 /* check for acceptable opcodes for normal folks, which are, so far,
3415 * get/set tokens, sysname, and unlog.
3417 if (i != 9 && i != 3 && i != 38 && i != 8) {
3418 osi_FreeLargeSpace(inData);
3423 ablob->in_size -= PIOCTL_HEADER * sizeof(afs_int32);
3424 ablob->in += PIOCTL_HEADER * sizeof(afs_int32);
3425 osi_FreeLargeSpace(inData);
3428 * We map uid 0 to nobody to match the mapping that the nfs
3429 * server does and to ensure that the suser() calls in the afs
3430 * code fails for remote client roots.
3432 uid = afs_nobody; /* NFS_NOBODY == -2 */
3436 #ifdef AFS_AIX41_ENV
3439 newcred->cr_gid = isroot ? RMTUSER_REQ_PRIV : RMTUSER_REQ;
3440 #ifdef AFS_AIX51_ENV
3441 newcred->cr_groupset.gs_union.un_groups[0] = g0;
3442 newcred->cr_groupset.gs_union.un_groups[1] = g1;
3443 #elif defined(AFS_LINUX26_ENV)
3444 #ifdef AFS_LINUX26_ONEGROUP_ENV
3445 newcred->cr_group_info = groups_alloc(1); /* not that anything sets this */
3446 l = (((g0-0x3f00) & 0x3fff) << 14) | ((g1-0x3f00) & 0x3fff);
3447 h = ((g0-0x3f00) >> 14);
3448 h = ((g1-0x3f00) >> 14) + h + h + h;
3449 GROUP_AT(newcred->cr_group_info, 0) = ((h << 28) | l);
3451 newcred->cr_group_info = groups_alloc(2);
3452 GROUP_AT(newcred->cr_group_info, 0) = g0;
3453 GROUP_AT(newcred->cr_group_info, 1) = g1;
3456 newcred->cr_groups[0] = g0;
3457 newcred->cr_groups[1] = g1;
3460 newcred->cr_ngrps = 2;
3461 #elif !defined(AFS_LINUX26_ENV)
3462 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
3463 newcred->cr_ngroups = 2;
3465 for (i = 2; i < NGROUPS; i++)
3466 newcred->cr_groups[i] = NOGROUP;
3469 #if !defined(AFS_OSF_ENV)
3470 afs_nfsclient_init(); /* before looking for exporter, ensure one exists */
3472 if (!(exporter = exporter_find(exporter_type))) {
3473 /* Exporter wasn't initialized or an invalid exporter type */
3477 if (exporter->exp_states & EXP_PWSYNC) {
3478 if (uid != credp->cr_uid) {
3480 return ENOEXEC; /* XXX Find a better errno XXX */
3483 newcred->cr_uid = uid; /* Only temporary */
3484 code = EXP_REQHANDLER(exporter, &newcred, hostaddr, &pag, &outexporter);
3485 /* The client's pag is the only unique identifier for it */
3486 newcred->cr_uid = pag;
3488 if (!code && *com == PSETPAG) {
3489 /* Special case for 'setpag' */
3490 afs_uint32 pagvalue = genpag();
3492 au = afs_GetUser(pagvalue, -1, WRITE_LOCK); /* a new unixuser struct */
3494 * Note that we leave the 'outexporter' struct held so it won't
3497 au->exporter = outexporter;
3498 if (ablob->out_size >= 4) {
3499 AFS_COPYOUT((char *)&pagvalue, ablob->out, sizeof(afs_int32),
3502 afs_PutUser(au, WRITE_LOCK);
3505 return PSETPAG; /* Special return for setpag */
3507 EXP_RELE(outexporter);
3510 *com = (*com) | comp;
3513 #endif /* AFS_NEED_CLIENTCONTEXT */
3515 /* get all interface addresses of this client */
3517 DECL_PIOCTL(PGetCPrefs)
3519 struct sprefrequest *spin; /* input */
3520 struct sprefinfo *spout; /* output */
3521 struct spref *srvout; /* one output component */
3525 AFS_STATCNT(PGetCPrefs);
3526 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3527 return EIO; /* Inappropriate ioctl for device */
3529 if (ainSize < sizeof(struct sprefrequest))
3532 spin = (struct sprefrequest *)ain;
3533 spout = (struct sprefinfo *)aout;
3535 maxNumber = spin->num_servers; /* max addrs this time */
3536 srvout = spout->servers;
3538 ObtainReadLock(&afs_xinterface);
3540 /* copy out the client interface information from the
3541 ** kernel data structure "interface" to the output buffer
3543 for (i = spin->offset, j = 0; (i < afs_cb_interface.numberOfInterfaces)
3544 && (j < maxNumber); i++, j++, srvout++)
3545 srvout->host.s_addr = afs_cb_interface.addr_in[i];
3547 spout->num_servers = j;
3548 *aoutSize = sizeof(struct sprefinfo) + (j - 1) * sizeof(struct spref);
3550 if (i >= afs_cb_interface.numberOfInterfaces)
3551 spout->next_offset = 0; /* start from beginning again */
3553 spout->next_offset = spin->offset + j;
3555 ReleaseReadLock(&afs_xinterface);
3559 DECL_PIOCTL(PSetCPrefs)
3561 struct setspref *sin;
3564 AFS_STATCNT(PSetCPrefs);
3565 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3566 return EIO; /* Inappropriate ioctl for device */
3568 sin = (struct setspref *)ain;
3570 if (ainSize < sizeof(struct setspref))
3572 #if 0 /* num_servers is unsigned */
3573 if (sin->num_servers < 0)
3576 if (sin->num_servers > AFS_MAX_INTERFACE_ADDR)
3579 ObtainWriteLock(&afs_xinterface, 412);
3580 afs_cb_interface.numberOfInterfaces = sin->num_servers;
3581 for (i = 0; (unsigned short)i < sin->num_servers; i++)
3582 afs_cb_interface.addr_in[i] = sin->servers[i].host.s_addr;
3584 ReleaseWriteLock(&afs_xinterface);
3588 DECL_PIOCTL(PFlushMount)
3590 register afs_int32 code;
3591 register struct vcache *tvc;
3592 register struct dcache *tdc;
3593 struct VenusFid tfid;
3595 struct sysname_info sysState;
3596 afs_size_t offset, len;
3598 AFS_STATCNT(PFlushMount);
3601 code = afs_VerifyVCache(avc, areq);
3604 if (vType(avc) != VDIR) {
3607 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
3610 Check_AtSys(avc, ain, &sysState, areq);
3611 ObtainReadLock(&tdc->lock);
3613 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
3614 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
3615 ReleaseReadLock(&tdc->lock);
3616 afs_PutDCache(tdc); /* we're done with the data */
3617 bufp = sysState.name;
3621 tfid.Cell = avc->fid.Cell;
3622 tfid.Fid.Volume = avc->fid.Fid.Volume;
3623 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
3624 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
3626 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3632 if (tvc->mvstat != 1) {
3637 #ifdef AFS_BOZONLOCK_ENV
3638 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
3640 ObtainWriteLock(&tvc->lock, 649);
3641 ObtainWriteLock(&afs_xcbhash, 650);
3642 afs_DequeueCallback(tvc);
3643 tvc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
3644 ReleaseWriteLock(&afs_xcbhash);
3645 /* now find the disk cache entries */
3646 afs_TryToSmush(tvc, *acred, 1);
3647 osi_dnlc_purgedp(tvc);
3648 if (tvc->linkData && !(tvc->states & CCore)) {
3649 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
3650 tvc->linkData = NULL;
3652 ReleaseWriteLock(&tvc->lock);
3653 #ifdef AFS_BOZONLOCK_ENV
3654 afs_BozonUnlock(&tvc->pvnLock, tvc);
3658 if (sysState.allocked)
3659 osi_FreeLargeSpace(bufp);
3663 DECL_PIOCTL(PRxStatProc)
3668 if (!afs_osi_suser(*acred)) {
3672 if (ainSize != sizeof(afs_int32)) {
3676 memcpy((char *)&flags, ain, sizeof(afs_int32));
3677 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3681 if (flags & AFSCALL_RXSTATS_ENABLE) {
3682 rx_enableProcessRPCStats();
3684 if (flags & AFSCALL_RXSTATS_DISABLE) {
3685 rx_disableProcessRPCStats();
3687 if (flags & AFSCALL_RXSTATS_CLEAR) {
3688 rx_clearProcessRPCStats(AFS_RX_STATS_CLEAR_ALL);
3696 DECL_PIOCTL(PRxStatPeer)
3701 if (!afs_osi_suser(*acred)) {
3705 if (ainSize != sizeof(afs_int32)) {
3709 memcpy((char *)&flags, ain, sizeof(afs_int32));
3710 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3714 if (flags & AFSCALL_RXSTATS_ENABLE) {
3715 rx_enablePeerRPCStats();
3717 if (flags & AFSCALL_RXSTATS_DISABLE) {
3718 rx_disablePeerRPCStats();
3720 if (flags & AFSCALL_RXSTATS_CLEAR) {
3721 rx_clearPeerRPCStats(AFS_RX_STATS_CLEAR_ALL);
3728 DECL_PIOCTL(PPrefetchFromTape)
3730 register afs_int32 code, code1;
3733 struct rx_call *tcall;
3734 struct AFSVolSync tsync;
3735 struct AFSFetchStatus OutStatus;
3736 struct AFSCallBack CallBack;
3737 struct VenusFid tfid;
3741 AFS_STATCNT(PSetAcl);
3745 if (ain && (ainSize == 3 * sizeof(afs_int32)))
3746 Fid = (struct AFSFid *)ain;
3748 Fid = &avc->fid.Fid;
3749 tfid.Cell = avc->fid.Cell;
3750 tfid.Fid.Volume = Fid->Volume;
3751 tfid.Fid.Vnode = Fid->Vnode;
3752 tfid.Fid.Unique = Fid->Unique;
3754 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3756 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3757 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &avc->fid);
3760 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3761 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &tvc->fid);
3764 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3768 tcall = rx_NewCall(tc->id);
3770 StartRXAFS_FetchData(tcall, (struct AFSFid *)&tvc->fid.Fid, 0,
3773 bytes = rx_Read(tcall, (char *)aout, sizeof(afs_int32));
3775 EndRXAFS_FetchData(tcall, &OutStatus, &CallBack, &tsync);
3777 code1 = rx_EndCall(tcall, code);
3781 } while (afs_Analyze
3782 (tc, code, &tvc->fid, areq, AFS_STATS_FS_RPCIDX_RESIDENCYRPCS,
3783 SHARED_LOCK, NULL));
3784 /* This call is done only to have the callback things handled correctly */
3785 afs_FetchStatus(tvc, &tfid, areq, &OutStatus);
3789 *aoutSize = sizeof(afs_int32);
3794 DECL_PIOCTL(PResidencyCmd)
3796 register afs_int32 code;
3799 struct ResidencyCmdInputs *Inputs;
3800 struct ResidencyCmdOutputs *Outputs;
3801 struct VenusFid tfid;
3804 Inputs = (struct ResidencyCmdInputs *)ain;
3805 Outputs = (struct ResidencyCmdOutputs *)aout;
3808 if (!ain || ainSize != sizeof(struct ResidencyCmdInputs))
3813 Fid = &avc->fid.Fid;
3815 tfid.Cell = avc->fid.Cell;
3816 tfid.Fid.Volume = Fid->Volume;
3817 tfid.Fid.Vnode = Fid->Vnode;
3818 tfid.Fid.Unique = Fid->Unique;
3820 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3821 afs_Trace3(afs_iclSetp, CM_TRACE_RESIDCMD, ICL_TYPE_POINTER, tvc,
3822 ICL_TYPE_INT32, Inputs->command, ICL_TYPE_FID, &tfid);
3826 if (Inputs->command) {
3828 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3832 RXAFS_ResidencyCmd(tc->id, Fid, Inputs,
3833 (struct ResidencyCmdOutputs *)aout);
3837 } while (afs_Analyze
3838 (tc, code, &tvc->fid, areq,
3839 AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK, NULL));
3840 /* This call is done to have the callback things handled correctly */
3841 afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3842 } else { /* just a status request, return also link data */
3844 Outputs->code = afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3845 Outputs->chars[0] = 0;
3846 if (vType(tvc) == VLNK) {
3847 ObtainWriteLock(&tvc->lock, 555);
3848 if (afs_HandleLink(tvc, areq) == 0)
3849 strncpy((char *)&Outputs->chars, tvc->linkData, MAXCMDCHARS);
3850 ReleaseWriteLock(&tvc->lock);
3857 *aoutSize = sizeof(struct ResidencyCmdOutputs);
3862 DECL_PIOCTL(PNewUuid)
3864 /*AFS_STATCNT(PNewUuid); */
3865 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
3866 return EIO; /* Inappropriate ioctl for device */
3868 if (!afs_osi_suser(acred))
3871 ObtainWriteLock(&afs_xinterface, 555);
3872 afs_uuid_create(&afs_cb_interface.uuid);
3873 ReleaseWriteLock(&afs_xinterface);
3874 ForceAllNewConnections();
3878 DECL_PIOCTL(PCallBackAddr)
3881 afs_uint32 addr, code;
3887 struct unixuser *tu;
3888 struct srvAddr **addrs;
3890 /*AFS_STATCNT(PCallBackAddr); */
3891 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
3892 return EIO; /* Inappropriate ioctl for device */
3894 if (!afs_osi_suser(acred))
3897 if (ainSize < sizeof(afs_int32))
3900 memcpy(&addr, ain, sizeof(afs_int32));
3902 ObtainReadLock(&afs_xinterface);
3903 for (i = 0; (unsigned short)i < afs_cb_interface.numberOfInterfaces; i++) {
3904 if (afs_cb_interface.addr_in[i] == addr)
3908 ReleaseWriteLock(&afs_xinterface);
3910 if (afs_cb_interface.addr_in[i] != addr)
3913 ObtainReadLock(&afs_xserver); /* Necessary? */
3914 ObtainReadLock(&afs_xsrvAddr);
3917 for (i = 0; i < NSERVERS; i++) {
3918 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3923 addrs = afs_osi_Alloc(srvAddrCount * sizeof(*addrs));
3925 for (i = 0; i < NSERVERS; i++) {
3926 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3927 if (j >= srvAddrCount)
3933 ReleaseReadLock(&afs_xsrvAddr);
3934 ReleaseReadLock(&afs_xserver);
3936 for (i = 0; i < j; i++) {
3942 /* vlserver has no callback conn */
3943 if (sa->sa_portal == AFS_VLPORT) {
3947 if (!ts->cell) /* not really an active server, anyway, it must */
3948 continue; /* have just been added by setsprefs */
3950 /* get a connection, even if host is down; bumps conn ref count */
3951 tu = afs_GetUser(areq->uid, ts->cell->cellNum, SHARED_LOCK);
3952 tc = afs_ConnBySA(sa, ts->cell->fsport, ts->cell->cellNum, tu,
3953 1 /*force */ , 1 /*create */ , SHARED_LOCK);
3954 afs_PutUser(tu, SHARED_LOCK);
3958 if ((sa->sa_flags & SRVADDR_ISDOWN) || afs_HaveCallBacksFrom(ts)) {
3959 if (sa->sa_flags & SRVADDR_ISDOWN) {
3960 rx_SetConnDeadTime(tc->id, 3);
3962 #ifdef RX_ENABLE_LOCKS
3964 #endif /* RX_ENABLE_LOCKS */
3965 code = RXAFS_CallBackRxConnAddr(tc->id, &addr);
3966 #ifdef RX_ENABLE_LOCKS
3968 #endif /* RX_ENABLE_LOCKS */
3970 afs_PutConn(tc, SHARED_LOCK); /* done with it now */
3971 } /* Outer loop over addrs */
3972 #endif /* UKERNEL */
3976 DECL_PIOCTL(PDiscon)
3978 #ifdef AFS_DISCON_ENV
3979 static afs_int32 mode = 4; /* Start up in 'full' */
3981 if (ainSize == sizeof(afs_int32)) {
3983 if (!afs_osi_suser(*acred))
3986 memcpy(&mode, ain, sizeof(afs_int32));
3989 * All of these numbers are hard coded in fs.c. If they
3990 * change here, they should change there and vice versa
3993 case 0: /* Disconnect, breaking all callbacks */
3994 if (!AFS_IS_DISCONNECTED) {
3995 ObtainWriteLock(&afs_discon_lock, 999);
3996 afs_DisconGiveUpCallbacks();
3997 afs_RemoveAllConns();
3998 afs_is_disconnected = 1;
3999 ReleaseWriteLock(&afs_discon_lock);
4002 case 4: /* Fully connected */
4003 ObtainWriteLock(&afs_discon_lock, 998);
4004 afs_is_disconnected = 0;
4005 ReleaseWriteLock(&afs_discon_lock);
4014 memcpy(aout, &mode, sizeof(afs_int32));
4015 *aoutSize = sizeof(afs_int32);
4022 DECL_PIOCTL(PNFSNukeCreds)
4024 afs_uint32 addr, code;
4025 register afs_int32 i;
4026 register struct unixuser *tu;
4028 AFS_STATCNT(PUnlog);
4029 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4030 return EIO; /* Inappropriate ioctl for device */
4032 if (ainSize < sizeof(afs_int32))
4034 memcpy(&addr, ain, sizeof(afs_int32));
4036 if ((*acred)->cr_gid == RMTUSER_REQ_PRIV && !addr) {
4037 tu = afs_GetUser(areq->uid, -1, SHARED_LOCK);
4038 if (!tu->exporter || !(addr = EXP_GETHOST(tu->exporter))) {
4039 afs_PutUser(tu, SHARED_LOCK);
4042 afs_PutUser(tu, SHARED_LOCK);
4043 } else if (!afs_osi_suser(acred)) {
4047 ObtainWriteLock(&afs_xuser, 227);
4048 for (i = 0; i < NUSERS; i++) {
4049 for (tu = afs_users[i]; tu; tu = tu->next) {
4050 if (tu->exporter && EXP_CHECKHOST(tu->exporter, addr)) {
4052 tu->states &= ~UHasTokens;
4053 /* security is not having to say you're sorry */
4054 memset((char *)&tu->ct, 0, sizeof(struct ClearToken));
4056 ReleaseWriteLock(&afs_xuser);
4057 afs_ResetUserConns(tu);
4059 ObtainWriteLock(&afs_xuser, 228);
4061 /* set the expire times to 0, causes
4062 * afs_GCUserData to remove this entry
4064 tu->ct.EndTimestamp = 0;
4066 #endif /* UKERNEL */
4070 ReleaseWriteLock(&afs_xuser);