2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include "afs/param.h"
16 #include "afs/sysincludes.h" /* Standard vendor system headers */
18 #include "h/syscallargs.h"
21 #include "h/sysproto.h"
23 #include "afsincludes.h" /* Afs-based standard headers */
24 #include "afs/afs_stats.h" /* afs statistics */
26 #include "rx/rx_globals.h"
28 struct VenusFid afs_rootFid;
29 afs_int32 afs_waitForever = 0;
30 short afs_waitForeverCount = 0;
31 afs_int32 afs_showflags = GAGUSER | GAGCONSOLE; /* show all messages */
33 #define DECL_PIOCTL(x) static int x(struct vcache *avc, int afun, struct vrequest *areq, \
34 char *ain, char *aout, afs_int32 ainSize, afs_int32 *aoutSize, \
35 struct AFS_UCRED **acred)
37 /* Prototypes for pioctl routines */
40 DECL_PIOCTL(PStoreBehind);
45 DECL_PIOCTL(PGetFileCell);
46 DECL_PIOCTL(PGetWSCell);
47 DECL_PIOCTL(PGetUserCell);
48 DECL_PIOCTL(PSetTokens);
49 DECL_PIOCTL(PGetVolumeStatus);
50 DECL_PIOCTL(PSetVolumeStatus);
52 DECL_PIOCTL(PNewStatMount);
53 DECL_PIOCTL(PGetTokens);
55 DECL_PIOCTL(PMariner);
56 DECL_PIOCTL(PCheckServers);
57 DECL_PIOCTL(PCheckVolNames);
58 DECL_PIOCTL(PCheckAuth);
59 DECL_PIOCTL(PFindVolume);
60 DECL_PIOCTL(PViceAccess);
61 DECL_PIOCTL(PSetCacheSize);
62 DECL_PIOCTL(PGetCacheSize);
63 DECL_PIOCTL(PRemoveCallBack);
64 DECL_PIOCTL(PNewCell);
65 DECL_PIOCTL(PNewAlias);
66 DECL_PIOCTL(PListCells);
67 DECL_PIOCTL(PListAliases);
68 DECL_PIOCTL(PRemoveMount);
69 DECL_PIOCTL(PVenusLogging);
70 DECL_PIOCTL(PGetCellStatus);
71 DECL_PIOCTL(PSetCellStatus);
72 DECL_PIOCTL(PFlushVolumeData);
73 DECL_PIOCTL(PGetVnodeXStatus);
74 DECL_PIOCTL(PGetVnodeXStatus2);
75 DECL_PIOCTL(PSetSysName);
76 DECL_PIOCTL(PSetSPrefs);
77 DECL_PIOCTL(PSetSPrefs33);
78 DECL_PIOCTL(PGetSPrefs);
79 DECL_PIOCTL(PExportAfs);
81 DECL_PIOCTL(PTwiddleRx);
82 DECL_PIOCTL(PGetInitParams);
83 DECL_PIOCTL(PGetRxkcrypt);
84 DECL_PIOCTL(PSetRxkcrypt);
85 DECL_PIOCTL(PGetCPrefs);
86 DECL_PIOCTL(PSetCPrefs);
87 DECL_PIOCTL(PFlushMount);
88 DECL_PIOCTL(PRxStatProc);
89 DECL_PIOCTL(PRxStatPeer);
90 DECL_PIOCTL(PPrefetchFromTape);
91 DECL_PIOCTL(PResidencyCmd);
92 DECL_PIOCTL(PCallBackAddr);
94 DECL_PIOCTL(PNFSNukeCreds);
95 DECL_PIOCTL(PNewUuid);
96 DECL_PIOCTL(PPrecache);
99 * A macro that says whether we're going to need HandleClientContext().
100 * This is currently used only by the nfs translator.
102 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
103 #define AFS_NEED_CLIENTCONTEXT
106 /* Prototypes for private routines */
107 #ifdef AFS_NEED_CLIENTCONTEXT
108 static int HandleClientContext(struct afs_ioctl *ablob, int *com,
109 struct AFS_UCRED **acred,
110 struct AFS_UCRED *credp);
112 int HandleIoctl(register struct vcache *avc, register afs_int32 acom,
113 struct afs_ioctl *adata);
114 int afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
115 register struct afs_ioctl *ablob, int afollow,
116 struct AFS_UCRED **acred);
117 static int Prefetch(char *apath, struct afs_ioctl *adata, int afollow,
118 struct AFS_UCRED *acred);
121 static int (*(VpioctlSw[])) () = {
126 PGetVolumeStatus, /* 4 */
127 PSetVolumeStatus, /* 5 */
132 PCheckServers, /* 10 */
133 PCheckVolNames, /* 11 */
135 PBogus, /* 13 -- used to be quick check time */
136 PFindVolume, /* 14 */
137 PBogus, /* 15 -- prefetch is now special-cased; see pioctl code! */
138 PBogus, /* 16 -- used to be testing code */
139 PNoop, /* 17 -- used to be enable group */
140 PNoop, /* 18 -- used to be disable group */
141 PBogus, /* 19 -- used to be list group */
142 PViceAccess, /* 20 */
143 PUnlog, /* 21 -- unlog *is* unpag in this system */
144 PGetFID, /* 22 -- get file ID */
145 PBogus, /* 23 -- used to be waitforever */
146 PSetCacheSize, /* 24 */
147 PRemoveCallBack, /* 25 -- flush only the callback */
150 PRemoveMount, /* 28 -- delete mount point */
151 PNewStatMount, /* 29 -- new style mount point stat */
152 PGetFileCell, /* 30 -- get cell name for input file */
153 PGetWSCell, /* 31 -- get cell name for workstation */
154 PMariner, /* 32 - set/get mariner host */
155 PGetUserCell, /* 33 -- get cell name for user */
156 PVenusLogging, /* 34 -- Enable/Disable logging */
157 PGetCellStatus, /* 35 */
158 PSetCellStatus, /* 36 */
159 PFlushVolumeData, /* 37 -- flush all data from a volume */
160 PSetSysName, /* 38 - Set system name */
161 PExportAfs, /* 39 - Export Afs to remote nfs clients */
162 PGetCacheSize, /* 40 - get cache size and usage */
163 PGetVnodeXStatus, /* 41 - get vcache's special status */
164 PSetSPrefs33, /* 42 - Set CM Server preferences... */
165 PGetSPrefs, /* 43 - Get CM Server preferences... */
166 PGag, /* 44 - turn off/on all CM messages */
167 PTwiddleRx, /* 45 - adjust some RX params */
168 PSetSPrefs, /* 46 - Set CM Server preferences... */
169 PStoreBehind, /* 47 - set degree of store behind to be done */
170 PGCPAGs, /* 48 - disable automatic pag gc-ing */
171 PGetInitParams, /* 49 - get initial cm params */
172 PGetCPrefs, /* 50 - get client interface addresses */
173 PSetCPrefs, /* 51 - set client interface addresses */
174 PFlushMount, /* 52 - flush mount symlink data */
175 PRxStatProc, /* 53 - control process RX statistics */
176 PRxStatPeer, /* 54 - control peer RX statistics */
177 PGetRxkcrypt, /* 55 -- Get rxkad encryption flag */
178 PSetRxkcrypt, /* 56 -- Set rxkad encryption flag */
179 PBogus, /* 57 -- arla: set file prio */
180 PBogus, /* 58 -- arla: fallback getfh */
181 PBogus, /* 59 -- arla: fallback fhopen */
182 PBogus, /* 60 -- arla: controls xfsdebug */
183 PBogus, /* 61 -- arla: controls arla debug */
184 PBogus, /* 62 -- arla: debug interface */
185 PBogus, /* 63 -- arla: print xfs status */
186 PBogus, /* 64 -- arla: force cache check */
187 PBogus, /* 65 -- arla: break callback */
188 PPrefetchFromTape, /* 66 -- MR-AFS: prefetch file from tape */
189 PResidencyCmd, /* 67 -- MR-AFS: generic commnd interface */
190 PBogus, /* 68 -- arla: fetch stats */
191 PGetVnodeXStatus2, /* 69 - get caller access and some vcache status */
194 static int (*(CpioctlSw[])) () = {
196 PNewAlias, /* 1 -- create new cell alias */
197 PListAliases, /* 2 -- list cell aliases */
198 PCallBackAddr, /* 3 -- request addr for callback rxcon */
200 PDiscon, /* 5 -- get/set discon mode */
210 static int (*(OpioctlSw[])) () = {
212 PNFSNukeCreds, /* 1 -- nuke all creds for NFS client */
215 #define PSetClientContext 99 /* Special pioctl to setup caller's creds */
216 int afs_nobody = NFS_NOBODY;
219 HandleIoctl(register struct vcache *avc, register afs_int32 acom,
220 struct afs_ioctl *adata)
222 register afs_int32 code;
225 AFS_STATCNT(HandleIoctl);
227 switch (acom & 0xff) {
229 avc->states |= CSafeStore;
233 /* case 2 used to be abort store, but this is no longer provided,
234 * since it is impossible to implement under normal Unix.
238 /* return the name of the cell this file is open on */
239 register struct cell *tcell;
240 register afs_int32 i;
242 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
244 i = strlen(tcell->cellName) + 1; /* bytes to copy out */
246 if (i > adata->out_size) {
247 /* 0 means we're not interested in the output */
248 if (adata->out_size != 0)
252 AFS_COPYOUT(tcell->cellName, adata->out, i, code);
254 afs_PutCell(tcell, READ_LOCK);
260 case 49: /* VIOC_GETINITPARAMS */
261 if (adata->out_size < sizeof(struct cm_initparams)) {
264 AFS_COPYOUT(&cm_initParams, adata->out,
265 sizeof(struct cm_initparams), code);
277 return code; /* so far, none implemented */
282 /* For aix we don't temporarily bypass ioctl(2) but rather do our
283 * thing directly in the vnode layer call, VNOP_IOCTL; thus afs_ioctl
284 * is now called from afs_gn_ioctl.
287 afs_ioctl(struct vcache *tvc, int cmd, int arg)
289 struct afs_ioctl data;
292 AFS_STATCNT(afs_ioctl);
293 if (((cmd >> 8) & 0xff) == 'V') {
294 /* This is a VICEIOCTL call */
295 AFS_COPYIN(arg, (caddr_t) & data, sizeof(data), error);
298 error = HandleIoctl(tvc, cmd, &data);
301 /* No-op call; just return. */
305 #endif /* AFS_AIX_ENV */
307 #if defined(AFS_SGI_ENV)
308 afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
311 , struct vopbd * vbds
315 struct afs_ioctl data;
321 AFS_STATCNT(afs_ioctl);
322 if (((cmd >> 8) & 0xff) == 'V') {
323 /* This is a VICEIOCTL call */
324 error = copyin_afs_ioctl(arg, &data);
327 locked = ISAFS_GLOCK();
330 error = HandleIoctl(tvc, cmd, &data);
335 /* No-op call; just return. */
339 #endif /* AFS_SGI_ENV */
341 /* unlike most calls here, this one uses u.u_error to return error conditions,
342 since this is really an intercepted chapter 2 call, rather than a vnode
345 /* AFS_HPUX102 and up uses VNODE ioctl instead */
346 #if !defined(AFS_HPUX102_ENV) && !defined(AFS_DARWIN80_ENV)
347 #if !defined(AFS_SGI_ENV)
351 kioctl(fdes, com, arg, ext, arg2, arg3)
352 #else /* __64BIT__ */
353 kioctl32(fdes, com, arg, ext, arg2, arg3)
354 #endif /* __64BIT__ */
357 kioctl(fdes, com, arg, ext)
368 } u_uap, *uap = &u_uap;
370 #if defined(AFS_SUN5_ENV)
372 struct afs_ioctl_sys {
379 struct afs_ioctl_sys *uap;
382 #elif defined(AFS_OSF_ENV)
383 afs_xioctl(p, args, retval)
392 } *uap = (struct a *)args;
393 #elif defined(AFS_FBSD50_ENV)
396 afs_xioctl(td, uap, retval)
398 register struct ioctl_args *uap;
401 struct proc *p = td->td_proc;
402 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
410 afs_xioctl(p, uap, retval)
412 register struct ioctl_args *uap;
415 #elif defined(AFS_LINUX22_ENV)
416 struct afs_ioctl_sys {
421 afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
424 struct afs_ioctl_sys ua, *uap = &ua;
433 } *uap = (struct a *)u.u_ap;
434 #endif /* AFS_SUN5_ENV */
436 #if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
438 #elif !defined(AFS_LINUX22_ENV)
439 register struct file *fd;
441 #if defined(AFS_XBSD_ENV)
442 register struct filedesc *fdp;
444 register struct vcache *tvc;
445 register int ioctlDone = 0, code = 0;
447 AFS_STATCNT(afs_xioctl);
448 #if defined(AFS_DARWIN_ENV)
449 if ((code = fdgetf(p, uap->fd, &fd)))
451 #elif defined(AFS_XBSD_ENV)
453 if ((u_int) uap->fd >= fdp->fd_nfiles
454 || (fd = fdp->fd_ofiles[uap->fd]) == NULL)
456 if ((fd->f_flag & (FREAD | FWRITE)) == 0)
458 #elif defined(AFS_LINUX22_ENV)
461 #elif defined(AFS_AIX32_ENV)
469 if (setuerror(getf(uap->fd, &fd))) {
472 #elif defined(AFS_OSF_ENV)
474 if (code = getf(&fd, uap->fd, FILE_FLAGS_NULL, &u.u_file_state))
476 #elif defined(AFS_SUN5_ENV)
477 # if defined(AFS_SUN57_ENV)
481 # elif defined(AFS_SUN54_ENV)
486 if (code = getf(uap->fd, &fd)) {
489 # endif /* AFS_SUN57_ENV */
495 /* first determine whether this is any sort of vnode */
496 #if defined(AFS_LINUX22_ENV)
501 if (fd->f_vnode->v_type == VREG || fd->f_vnode->v_type == VDIR) {
503 if (fd->f_type == DTYPE_VNODE) {
505 /* good, this is a vnode; next see if it is an AFS vnode */
506 #if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV)
507 tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */
508 #elif defined(AFS_OBSD_ENV)
510 IsAfsVnode((struct vnode *)fd->
511 f_data) ? VTOAFS((struct vnode *)fd->f_data) : NULL;
513 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
515 #endif /* AFS_LINUX22_ENV */
516 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
517 /* This is an AFS vnode */
518 if (((uap->com >> 8) & 0xff) == 'V') {
519 register struct afs_ioctl *datap;
522 (struct afs_ioctl *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
523 code=copyin_afs_ioctl((char *)uap->arg, datap);
525 osi_FreeSmallSpace(datap);
527 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
530 #if defined(AFS_SUN5_ENV)
545 #else /* AFS_OSF_ENV */
549 #ifdef AFS_LINUX22_ENV
559 code = HandleIoctl(tvc, uap->com, datap);
560 osi_FreeSmallSpace(datap);
574 #if defined(AFS_LINUX22_ENV)
586 code = okioctl(fdes, com, arg, ext, arg2, arg3);
587 #else /* __64BIT__ */
588 code = okioctl32(fdes, com, arg, ext, arg2, arg3);
589 #endif /* __64BIT__ */
590 #else /* !AFS_AIX51_ENV */
591 code = okioctl(fdes, com, arg, ext);
592 #endif /* AFS_AIX51_ENV */
594 #else /* !AFS_AIX41_ENV */
596 okioctl(fdes, com, arg, ext);
597 #elif defined(AFS_SUN5_ENV)
598 #if defined(AFS_SUN57_ENV)
600 #elif defined(AFS_SUN54_ENV)
605 code = ioctl(uap, rvp);
606 #elif defined(AFS_FBSD50_ENV)
607 return ioctl(td, uap);
608 #elif defined(AFS_FBSD_ENV)
609 return ioctl(p, uap);
610 #elif defined(AFS_OBSD_ENV)
611 code = sys_ioctl(p, uap, retval);
612 #elif defined(AFS_DARWIN_ENV)
613 return ioctl(p, uap, retval);
614 #elif defined(AFS_OSF_ENV)
615 code = ioctl(p, args, retval);
622 #elif !defined(AFS_LINUX22_ENV)
636 #ifdef AFS_LINUX22_ENV
639 #if defined(KERNEL_HAVE_UERROR)
642 #if defined(AFS_AIX32_ENV) && !defined(AFS_AIX41_ENV)
643 return (getuerror()? -1 : u.u_ioctlrv);
645 return getuerror()? -1 : 0;
648 #endif /* AFS_LINUX22_ENV */
649 #endif /* AFS_SUN5_ENV */
650 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
654 #endif /* AFS_SGI_ENV */
655 #endif /* AFS_HPUX102_ENV */
657 #if defined(AFS_SGI_ENV)
658 /* "pioctl" system call entry point; just pass argument to the parameterized
667 afs_pioctl(struct pioctlargs *uap, rval_t * rvp)
671 AFS_STATCNT(afs_pioctl);
673 code = afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow);
682 #elif defined(AFS_OSF_ENV)
683 afs_pioctl(p, args, retval)
693 } *uap = (struct a *)args;
695 AFS_STATCNT(afs_pioctl);
696 return (afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow));
699 #elif defined(AFS_FBSD50_ENV)
701 afs_pioctl(td, args, retval)
711 } *uap = (struct a *)args;
713 AFS_STATCNT(afs_pioctl);
714 return (afs_syscall_pioctl
715 (uap->path, uap->cmd, uap->cmarg, uap->follow, td->td_ucred));
718 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
720 afs_pioctl(p, args, retval)
730 } *uap = (struct a *)args;
732 AFS_STATCNT(afs_pioctl);
733 #ifdef AFS_DARWIN80_ENV
734 return (afs_syscall_pioctl
735 (uap->path, uap->cmd, uap->cmarg, uap->follow,
738 return (afs_syscall_pioctl
739 (uap->path, uap->cmd, uap->cmarg, uap->follow,
740 p->p_cred->pc_ucred));
746 /* macro to avoid adding any more #ifdef's to pioctl code. */
747 #if defined(AFS_LINUX22_ENV) || defined(AFS_AIX41_ENV)
748 #define PIOCTL_FREE_CRED() crfree(credp)
750 #define PIOCTL_FREE_CRED()
755 afs_syscall_pioctl(path, com, cmarg, follow, rvp, credp)
757 struct AFS_UCRED *credp;
759 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
760 afs_syscall_pioctl(path, com, cmarg, follow, credp)
761 struct AFS_UCRED *credp;
763 afs_syscall_pioctl(path, com, cmarg, follow)
771 struct afs_ioctl data;
772 #ifdef AFS_NEED_CLIENTCONTEXT
773 struct AFS_UCRED *tmpcred = NULL;
775 struct AFS_UCRED *foreigncreds = NULL;
776 register afs_int32 code = 0;
777 struct vnode *vp = NULL;
779 struct ucred *credp = crref(); /* don't free until done! */
781 #ifdef AFS_LINUX22_ENV
782 cred_t *credp = crref(); /* don't free until done! */
786 AFS_STATCNT(afs_syscall_pioctl);
788 follow = 1; /* compat. with old venus */
789 code = copyin_afs_ioctl(cmarg, &data);
792 #if defined(KERNEL_HAVE_UERROR)
797 if ((com & 0xff) == PSetClientContext) {
798 #ifdef AFS_NEED_CLIENTCONTEXT
799 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV)
800 code = HandleClientContext(&data, &com, &foreigncreds, credp);
802 code = HandleClientContext(&data, &com, &foreigncreds, osi_curcred());
806 crfree(foreigncreds);
809 #if defined(KERNEL_HAVE_UERROR)
810 return (setuerror(code), code);
815 #else /* AFS_NEED_CLIENTCONTEXT */
817 #endif /* AFS_NEED_CLIENTCONTEXT */
819 #ifdef AFS_NEED_CLIENTCONTEXT
822 * We could have done without temporary setting the u.u_cred below
823 * (foreigncreds could be passed as param the pioctl modules)
824 * but calls such as afs_osi_suser() doesn't allow that since it
825 * references u.u_cred directly. We could, of course, do something
826 * like afs_osi_suser(cred) which, I think, is better since it
827 * generalizes and supports multi cred environments...
829 #if defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
831 credp = foreigncreds;
832 #elif defined(AFS_AIX41_ENV)
833 tmpcred = crref(); /* XXX */
835 #elif defined(AFS_HPUX101_ENV)
836 tmpcred = p_cred(u.u_procp);
837 set_p_cred(u.u_procp, foreigncreds);
838 #elif defined(AFS_SGI_ENV)
839 tmpcred = OSI_GET_CURRENT_CRED();
840 OSI_SET_CURRENT_CRED(foreigncreds);
843 u.u_cred = foreigncreds;
846 #endif /* AFS_NEED_CLIENTCONTEXT */
847 if ((com & 0xff) == 15) {
848 /* special case prefetch so entire pathname eval occurs in helper process.
849 * otherwise, the pioctl call is essentially useless */
850 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
852 Prefetch(path, &data, follow,
853 foreigncreds ? foreigncreds : credp);
855 code = Prefetch(path, &data, follow, osi_curcred());
858 #if defined(KERNEL_HAVE_UERROR)
867 lookupname(path, USR, follow, NULL, &vp,
868 foreigncreds ? foreigncreds : credp);
870 #ifdef AFS_LINUX22_ENV
871 code = gop_lookupname(path, AFS_UIOUSER, follow, &dp);
873 vp = (struct vnode *)dp->d_inode;
875 code = gop_lookupname(path, AFS_UIOUSER, follow, &vp);
876 #endif /* AFS_LINUX22_ENV */
877 #endif /* AFS_AIX41_ENV */
881 #if defined(KERNEL_HAVE_UERROR)
889 #if defined(AFS_SUN510_ENV)
890 if (vp && !IsAfsVnode(vp)) {
891 struct vnode *realvp;
893 #ifdef AFS_SUN511_ENV
894 (VOP_REALVP(vp, &realvp, NULL) == 0)
896 (VOP_REALVP(vp, &realvp) == 0)
899 struct vnode *oldvp = vp;
907 /* now make the call if we were passed no file, or were passed an AFS file */
908 if (!vp || IsAfsVnode(vp)) {
909 #if defined(AFS_SUN5_ENV)
910 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
911 #elif defined(AFS_AIX41_ENV)
913 struct ucred *cred1, *cred2;
916 cred1 = cred2 = foreigncreds;
918 cred1 = cred2 = credp;
920 code = afs_HandlePioctl(vp, com, &data, follow, &cred1);
921 if (cred1 != cred2) {
922 /* something changed the creds */
926 #elif defined(AFS_HPUX101_ENV)
928 struct ucred *cred = p_cred(u.u_procp);
929 code = afs_HandlePioctl(vp, com, &data, follow, &cred);
931 #elif defined(AFS_SGI_ENV)
934 credp = OSI_GET_CURRENT_CRED();
935 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
937 #elif defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
938 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
940 code = afs_HandlePioctl(vp, com, &data, follow, &u.u_cred);
943 #if defined(KERNEL_HAVE_UERROR)
946 code = EINVAL; /* not in /afs */
951 #if defined(AFS_NEED_CLIENTCONTEXT)
954 crset(tmpcred); /* restore original credentials */
956 #if defined(AFS_HPUX101_ENV)
957 set_p_cred(u.u_procp, tmpcred); /* restore original credentials */
958 #elif defined(AFS_SGI_ENV)
959 OSI_SET_CURRENT_CRED(tmpcred); /* restore original credentials */
960 #elif defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
961 credp = tmpcred; /* restore original credentials */
963 osi_curcred() = tmpcred; /* restore original credentials */
964 #endif /* AFS_HPUX101_ENV */
965 crfree(foreigncreds);
968 #endif /* AFS_NEED_CLIENTCONTEXT */
970 #ifdef AFS_LINUX22_ENV
973 AFS_RELE(vp); /* put vnode back */
977 #if defined(KERNEL_HAVE_UERROR)
980 return (getuerror());
986 #define MAXPIOCTLTOKENLEN \
987 (3*sizeof(afs_int32)+MAXKTCTICKETLEN+sizeof(struct ClearToken)+MAXKTCREALMLEN)
990 afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
991 register struct afs_ioctl *ablob, int afollow,
992 struct AFS_UCRED **acred)
995 struct vrequest treq;
996 register afs_int32 code;
997 register afs_int32 function, device;
998 afs_int32 inSize, outSize, outSizeMax;
999 char *inData, *outData;
1000 int (*(*pioctlSw)) ();
1002 struct afs_fakestat_state fakestate;
1004 avc = avp ? VTOAFS(avp) : NULL;
1005 afs_Trace3(afs_iclSetp, CM_TRACE_PIOCTL, ICL_TYPE_INT32, acom & 0xff,
1006 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, afollow);
1007 AFS_STATCNT(HandlePioctl);
1008 if ((code = afs_InitReq(&treq, *acred)))
1010 afs_InitFakeStat(&fakestate);
1012 code = afs_EvalFakeStat(&avc, &fakestate, &treq);
1014 afs_PutFakeStat(&fakestate);
1018 device = (acom & 0xff00) >> 8;
1020 case 'V': /* Original pioctls */
1021 pioctlSw = VpioctlSw;
1022 pioctlSwSize = sizeof(VpioctlSw);
1024 case 'C': /* Coordinated/common pioctls */
1025 pioctlSw = CpioctlSw;
1026 pioctlSwSize = sizeof(CpioctlSw);
1028 case 'O': /* Coordinated/common pioctls */
1029 pioctlSw = OpioctlSw;
1030 pioctlSwSize = sizeof(OpioctlSw);
1033 afs_PutFakeStat(&fakestate);
1036 function = acom & 0xff;
1037 if (function >= (pioctlSwSize / sizeof(char *))) {
1038 afs_PutFakeStat(&fakestate);
1039 return EINVAL; /* out of range */
1041 inSize = ablob->in_size;
1043 /* Do all range checking before continuing */
1044 if (inSize > MAXPIOCTLTOKENLEN || inSize < 0 || ablob->out_size < 0)
1047 /* Note that we use osi_Alloc for large allocs and osi_AllocLargeSpace for small ones */
1048 if (inSize > AFS_LRALLOCSIZ) {
1049 inData = osi_Alloc(inSize + 1);
1051 inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1056 AFS_COPYIN(ablob->in, inData, inSize, code);
1057 inData[inSize] = '\0';
1061 if (inSize > AFS_LRALLOCSIZ) {
1062 osi_Free(inData, inSize + 1);
1064 osi_FreeLargeSpace(inData);
1066 afs_PutFakeStat(&fakestate);
1069 if (function == 8 && device == 'V') { /* PGetTokens */
1070 outSizeMax = MAXPIOCTLTOKENLEN;
1071 outData = osi_Alloc(outSizeMax);
1073 outSizeMax = AFS_LRALLOCSIZ;
1074 outData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1077 if (inSize > AFS_LRALLOCSIZ) {
1078 osi_Free(inData, inSize + 1);
1080 osi_FreeLargeSpace(inData);
1082 afs_PutFakeStat(&fakestate);
1087 (*pioctlSw[function]) (avc, function, &treq, inData, outData, inSize,
1089 if (inSize > AFS_LRALLOCSIZ) {
1090 osi_Free(inData, inSize + 1);
1092 osi_FreeLargeSpace(inData);
1094 if (code == 0 && ablob->out_size > 0) {
1095 if (outSize > ablob->out_size) {
1096 code = E2BIG; /* data wont fit in user buffer */
1097 } else if (outSize) {
1098 AFS_COPYOUT(outData, ablob->out, outSize, code);
1101 if (outSizeMax > AFS_LRALLOCSIZ) {
1102 osi_Free(outData, outSizeMax);
1104 osi_FreeLargeSpace(outData);
1106 afs_PutFakeStat(&fakestate);
1107 return afs_CheckCode(code, &treq, 41);
1110 DECL_PIOCTL(PGetFID)
1112 AFS_STATCNT(PGetFID);
1115 memcpy(aout, (char *)&avc->fid, sizeof(struct VenusFid));
1116 *aoutSize = sizeof(struct VenusFid);
1120 DECL_PIOCTL(PSetAcl)
1122 register afs_int32 code;
1124 struct AFSOpaque acl;
1125 struct AFSVolSync tsync;
1126 struct AFSFetchStatus OutStatus;
1129 AFS_STATCNT(PSetAcl);
1132 if ((acl.AFSOpaque_len = strlen(ain) + 1) > 1024 /* AFSOPAQUEMAX */)
1135 acl.AFSOpaque_val = ain;
1137 tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1139 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREACL);
1142 RXAFS_StoreACL(tconn->id, (struct AFSFid *)&avc->fid.Fid,
1143 &acl, &OutStatus, &tsync);
1148 } while (afs_Analyze
1149 (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_STOREACL,
1150 SHARED_LOCK, NULL));
1152 /* now we've forgotten all of the access info */
1153 ObtainWriteLock(&afs_xcbhash, 455);
1155 afs_DequeueCallback(avc);
1156 avc->states &= ~(CStatd | CUnique);
1157 ReleaseWriteLock(&afs_xcbhash);
1158 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
1159 osi_dnlc_purgedp(avc);
1163 int afs_defaultAsynchrony = 0;
1165 DECL_PIOCTL(PStoreBehind)
1168 struct sbstruct *sbr;
1170 sbr = (struct sbstruct *)ain;
1171 if (sbr->sb_default != -1) {
1172 if (afs_osi_suser(*acred))
1173 afs_defaultAsynchrony = sbr->sb_default;
1178 if (avc && (sbr->sb_thisfile != -1)) {
1180 (avc, PRSFS_WRITE | PRSFS_ADMINISTER, areq, DONT_CHECK_MODE_BITS))
1181 avc->asynchrony = sbr->sb_thisfile;
1186 *aoutSize = sizeof(struct sbstruct);
1187 sbr = (struct sbstruct *)aout;
1188 sbr->sb_default = afs_defaultAsynchrony;
1190 sbr->sb_thisfile = avc->asynchrony;
1196 DECL_PIOCTL(PGCPAGs)
1198 if (!afs_osi_suser(*acred)) {
1201 afs_gcpags = AFS_GCPAGS_USERDISABLED;
1205 DECL_PIOCTL(PGetAcl)
1207 struct AFSOpaque acl;
1208 struct AFSVolSync tsync;
1209 struct AFSFetchStatus OutStatus;
1215 AFS_STATCNT(PGetAcl);
1218 Fid.Volume = avc->fid.Fid.Volume;
1219 Fid.Vnode = avc->fid.Fid.Vnode;
1220 Fid.Unique = avc->fid.Fid.Unique;
1221 if (avc->states & CForeign) {
1223 * For a dfs xlator acl we have a special hack so that the
1224 * xlator will distinguish which type of acl will return. So
1225 * we currently use the top 2-bytes (vals 0-4) to tell which
1226 * type of acl to bring back. Horrible hack but this will
1227 * cause the least number of changes to code size and interfaces.
1229 if (Fid.Vnode & 0xc0000000)
1231 Fid.Vnode |= (ainSize << 30);
1233 acl.AFSOpaque_val = aout;
1235 tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1238 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHACL);
1240 code = RXAFS_FetchACL(tconn->id, &Fid, &acl, &OutStatus, &tsync);
1245 } while (afs_Analyze
1246 (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_FETCHACL,
1247 SHARED_LOCK, NULL));
1250 *aoutSize = (acl.AFSOpaque_len == 0 ? 1 : acl.AFSOpaque_len);
1263 AFS_STATCNT(PBogus);
1267 DECL_PIOCTL(PGetFileCell)
1269 register struct cell *tcell;
1271 AFS_STATCNT(PGetFileCell);
1274 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
1277 strcpy(aout, tcell->cellName);
1278 afs_PutCell(tcell, READ_LOCK);
1279 *aoutSize = strlen(aout) + 1;
1283 DECL_PIOCTL(PGetWSCell)
1285 struct cell *tcell = NULL;
1287 AFS_STATCNT(PGetWSCell);
1288 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1289 return EIO; /* Inappropriate ioctl for device */
1291 tcell = afs_GetPrimaryCell(READ_LOCK);
1292 if (!tcell) /* no primary cell? */
1294 strcpy(aout, tcell->cellName);
1295 *aoutSize = strlen(aout) + 1;
1296 afs_PutCell(tcell, READ_LOCK);
1300 DECL_PIOCTL(PGetUserCell)
1302 register afs_int32 i;
1303 register struct unixuser *tu;
1304 register struct cell *tcell;
1306 AFS_STATCNT(PGetUserCell);
1307 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1308 return EIO; /* Inappropriate ioctl for device */
1310 /* return the cell name of the primary cell for this user */
1311 i = UHash(areq->uid);
1312 ObtainWriteLock(&afs_xuser, 224);
1313 for (tu = afs_users[i]; tu; tu = tu->next) {
1314 if (tu->uid == areq->uid && (tu->states & UPrimary)) {
1316 ReleaseWriteLock(&afs_xuser);
1321 tcell = afs_GetCell(tu->cell, READ_LOCK);
1322 afs_PutUser(tu, WRITE_LOCK);
1326 strcpy(aout, tcell->cellName);
1327 afs_PutCell(tcell, READ_LOCK);
1328 *aoutSize = strlen(aout) + 1; /* 1 for the null */
1331 ReleaseWriteLock(&afs_xuser);
1338 DECL_PIOCTL(PSetTokens)
1341 register struct unixuser *tu;
1342 struct ClearToken clear;
1343 register struct cell *tcell;
1346 struct vrequest treq;
1347 afs_int32 flag, set_parent_pag = 0;
1349 AFS_STATCNT(PSetTokens);
1350 if (!afs_resourceinit_flag) {
1353 memcpy((char *)&i, ain, sizeof(afs_int32));
1354 ain += sizeof(afs_int32);
1355 stp = ain; /* remember where the ticket is */
1356 if (i < 0 || i > MAXKTCTICKETLEN)
1357 return EINVAL; /* malloc may fail */
1359 ain += i; /* skip over ticket */
1360 memcpy((char *)&i, ain, sizeof(afs_int32));
1361 ain += sizeof(afs_int32);
1362 if (i != sizeof(struct ClearToken)) {
1365 memcpy((char *)&clear, ain, sizeof(struct ClearToken));
1366 if (clear.AuthHandle == -1)
1367 clear.AuthHandle = 999; /* more rxvab compat stuff */
1368 ain += sizeof(struct ClearToken);
1369 if (ainSize != 2 * sizeof(afs_int32) + stLen + sizeof(struct ClearToken)) {
1370 /* still stuff left? we've got primary flag and cell name. Set these */
1371 memcpy((char *)&flag, ain, sizeof(afs_int32)); /* primary id flag */
1372 ain += sizeof(afs_int32); /* skip id field */
1373 /* rest is cell name, look it up */
1374 /* some versions of gcc appear to need != 0 in order to get this right */
1375 if ((flag & 0x8000) != 0) { /* XXX Use Constant XXX */
1379 tcell = afs_GetCellByName(ain, READ_LOCK);
1383 /* default to primary cell, primary id */
1384 flag = 1; /* primary id */
1385 tcell = afs_GetPrimaryCell(READ_LOCK);
1390 afs_PutCell(tcell, READ_LOCK);
1391 if (set_parent_pag) {
1393 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1394 #if defined(AFS_DARWIN_ENV)
1395 struct proc *p = current_proc(); /* XXX */
1397 struct proc *p = curproc; /* XXX */
1399 #ifndef AFS_DARWIN80_ENV
1400 uprintf("Process %d (%s) tried to change pags in PSetTokens\n",
1401 p->p_pid, p->p_comm);
1403 if (!setpag(p, acred, -1, &pag, 1)) {
1406 if (!setpag(u.u_procp, acred, -1, &pag, 1)) { /* XXX u.u_procp is a no-op XXX */
1408 if (!setpag(acred, -1, &pag, 1)) {
1411 afs_InitReq(&treq, *acred);
1415 /* now we just set the tokens */
1416 tu = afs_GetUser(areq->uid, i, WRITE_LOCK); /* i has the cell # */
1417 tu->vid = clear.ViceId;
1418 if (tu->stp != NULL) {
1419 afs_osi_Free(tu->stp, tu->stLen);
1421 tu->stp = (char *)afs_osi_Alloc(stLen);
1422 if (tu->stp == NULL) {
1426 memcpy(tu->stp, stp, stLen);
1429 afs_stats_cmfullperf.authent.TicketUpdates++;
1430 afs_ComputePAGStats();
1431 #endif /* AFS_NOSTATS */
1432 tu->states |= UHasTokens;
1433 tu->states &= ~UTokensBad;
1434 afs_SetPrimary(tu, flag);
1435 tu->tokenTime = osi_Time();
1436 afs_ResetUserConns(tu);
1437 afs_PutUser(tu, WRITE_LOCK);
1452 DECL_PIOCTL(PGetVolumeStatus)
1455 char *offLineMsg = afs_osi_Alloc(256);
1456 char *motd = afs_osi_Alloc(256);
1457 register struct conn *tc;
1458 register afs_int32 code = 0;
1459 struct AFSFetchVolumeStatus volstat;
1461 char *Name, *OfflineMsg, *MOTD;
1464 AFS_STATCNT(PGetVolumeStatus);
1470 OfflineMsg = offLineMsg;
1473 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1475 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS);
1478 RXAFS_GetVolumeStatus(tc->id, avc->fid.Fid.Volume, &volstat,
1479 &Name, &OfflineMsg, &MOTD);
1484 } while (afs_Analyze
1485 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS,
1486 SHARED_LOCK, NULL));
1490 /* Copy all this junk into msg->im_data, keeping track of the lengths. */
1492 memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
1493 cp += sizeof(VolumeStatus);
1494 strcpy(cp, volName);
1495 cp += strlen(volName) + 1;
1496 strcpy(cp, offLineMsg);
1497 cp += strlen(offLineMsg) + 1;
1499 cp += strlen(motd) + 1;
1500 *aoutSize = (cp - aout);
1502 afs_osi_Free(offLineMsg, 256);
1503 afs_osi_Free(motd, 256);
1507 DECL_PIOCTL(PSetVolumeStatus)
1510 char *offLineMsg = afs_osi_Alloc(256);
1511 char *motd = afs_osi_Alloc(256);
1512 register struct conn *tc;
1513 register afs_int32 code = 0;
1514 struct AFSFetchVolumeStatus volstat;
1515 struct AFSStoreVolumeStatus storeStat;
1516 register struct volume *tvp;
1520 AFS_STATCNT(PSetVolumeStatus);
1526 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
1528 if (tvp->states & (VRO | VBackup)) {
1529 afs_PutVolume(tvp, READ_LOCK);
1533 afs_PutVolume(tvp, READ_LOCK);
1538 /* Copy the junk out, using cp as a roving pointer. */
1540 memcpy((char *)&volstat, cp, sizeof(AFSFetchVolumeStatus));
1541 cp += sizeof(AFSFetchVolumeStatus);
1542 if (strlen(cp) >= sizeof(volName)) {
1546 strcpy(volName, cp);
1547 cp += strlen(volName) + 1;
1548 if (strlen(cp) >= sizeof(offLineMsg)) {
1552 strcpy(offLineMsg, cp);
1553 cp += strlen(offLineMsg) + 1;
1554 if (strlen(cp) >= sizeof(motd)) {
1560 if (volstat.MinQuota != -1) {
1561 storeStat.MinQuota = volstat.MinQuota;
1562 storeStat.Mask |= AFS_SETMINQUOTA;
1564 if (volstat.MaxQuota != -1) {
1565 storeStat.MaxQuota = volstat.MaxQuota;
1566 storeStat.Mask |= AFS_SETMAXQUOTA;
1569 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1571 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS);
1574 RXAFS_SetVolumeStatus(tc->id, avc->fid.Fid.Volume, &storeStat,
1575 volName, offLineMsg, motd);
1580 } while (afs_Analyze
1581 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS,
1582 SHARED_LOCK, NULL));
1586 /* we are sending parms back to make compat. with prev system. should
1587 * change interface later to not ask for current status, just set new status */
1589 memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
1590 cp += sizeof(VolumeStatus);
1591 strcpy(cp, volName);
1592 cp += strlen(volName) + 1;
1593 strcpy(cp, offLineMsg);
1594 cp += strlen(offLineMsg) + 1;
1596 cp += strlen(motd) + 1;
1597 *aoutSize = cp - aout;
1599 afs_osi_Free(offLineMsg, 256);
1600 afs_osi_Free(motd, 256);
1606 AFS_STATCNT(PFlush);
1609 #ifdef AFS_BOZONLOCK_ENV
1610 afs_BozonLock(&avc->pvnLock, avc); /* Since afs_TryToSmush will do a pvn_vptrunc */
1612 ObtainWriteLock(&avc->lock, 225);
1613 ObtainWriteLock(&afs_xcbhash, 456);
1614 afs_DequeueCallback(avc);
1615 avc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
1616 ReleaseWriteLock(&afs_xcbhash);
1617 /* now find the disk cache entries */
1618 afs_TryToSmush(avc, *acred, 1);
1619 osi_dnlc_purgedp(avc);
1620 if (avc->linkData && !(avc->states & CCore)) {
1621 afs_osi_Free(avc->linkData, strlen(avc->linkData) + 1);
1622 avc->linkData = NULL;
1624 ReleaseWriteLock(&avc->lock);
1625 #ifdef AFS_BOZONLOCK_ENV
1626 afs_BozonUnlock(&avc->pvnLock, avc);
1631 DECL_PIOCTL(PNewStatMount)
1633 register afs_int32 code;
1634 register struct vcache *tvc;
1635 register struct dcache *tdc;
1636 struct VenusFid tfid;
1638 struct sysname_info sysState;
1639 afs_size_t offset, len;
1641 AFS_STATCNT(PNewStatMount);
1644 code = afs_VerifyVCache(avc, areq);
1647 if (vType(avc) != VDIR) {
1650 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
1653 Check_AtSys(avc, ain, &sysState, areq);
1654 ObtainReadLock(&tdc->lock);
1656 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
1657 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
1658 ReleaseReadLock(&tdc->lock);
1659 afs_PutDCache(tdc); /* we're done with the data */
1660 bufp = sysState.name;
1664 tfid.Cell = avc->fid.Cell;
1665 tfid.Fid.Volume = avc->fid.Fid.Volume;
1666 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
1667 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
1669 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
1675 if (tvc->mvstat != 1) {
1680 ObtainWriteLock(&tvc->lock, 226);
1681 code = afs_HandleLink(tvc, areq);
1683 if (tvc->linkData) {
1684 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
1687 /* we have the data */
1688 strcpy(aout, tvc->linkData);
1689 *aoutSize = strlen(tvc->linkData) + 1;
1694 ReleaseWriteLock(&tvc->lock);
1697 if (sysState.allocked)
1698 osi_FreeLargeSpace(bufp);
1702 DECL_PIOCTL(PGetTokens)
1704 register struct cell *tcell;
1705 register afs_int32 i;
1706 register struct unixuser *tu;
1711 AFS_STATCNT(PGetTokens);
1712 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1713 return EIO; /* Inappropriate ioctl for device */
1715 /* weird interface. If input parameter is present, it is an integer and
1716 * we're supposed to return the parm'th tokens for this unix uid.
1717 * If not present, we just return tokens for cell 1.
1718 * If counter out of bounds, return EDOM.
1719 * If no tokens for the particular cell, return ENOTCONN.
1720 * Also, if this mysterious parm is present, we return, along with the
1721 * tokens, the primary cell indicator (an afs_int32 0) and the cell name
1722 * at the end, in that order.
1724 if ((newStyle = (ainSize > 0))) {
1725 memcpy((char *)&iterator, ain, sizeof(afs_int32));
1727 i = UHash(areq->uid);
1728 ObtainReadLock(&afs_xuser);
1729 for (tu = afs_users[i]; tu; tu = tu->next) {
1731 if (tu->uid == areq->uid && (tu->states & UHasTokens)) {
1732 if (iterator-- == 0)
1733 break; /* are we done yet? */
1736 if (tu->uid == areq->uid && afs_IsPrimaryCellNum(tu->cell))
1742 * No need to hold a read lock on each user entry
1746 ReleaseReadLock(&afs_xuser);
1751 if (((tu->states & UHasTokens) == 0)
1752 || (tu->ct.EndTimestamp < osi_Time())) {
1753 tu->states |= (UTokensBad | UNeedsReset);
1754 afs_PutUser(tu, READ_LOCK);
1757 /* use iterator for temp */
1759 iterator = tu->stLen; /* for compat, we try to return 56 byte tix if they fit */
1761 iterator = 56; /* # of bytes we're returning */
1762 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1763 cp += sizeof(afs_int32);
1764 memcpy(cp, tu->stp, tu->stLen); /* copy out st */
1766 iterator = sizeof(struct ClearToken);
1767 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1768 cp += sizeof(afs_int32);
1769 memcpy(cp, (char *)&tu->ct, sizeof(struct ClearToken));
1770 cp += sizeof(struct ClearToken);
1772 /* put out primary id and cell name, too */
1773 iterator = (tu->states & UPrimary ? 1 : 0);
1774 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1775 cp += sizeof(afs_int32);
1776 tcell = afs_GetCell(tu->cell, READ_LOCK);
1778 strcpy(cp, tcell->cellName);
1779 cp += strlen(tcell->cellName) + 1;
1780 afs_PutCell(tcell, READ_LOCK);
1784 *aoutSize = cp - aout;
1785 afs_PutUser(tu, READ_LOCK);
1791 register afs_int32 i;
1792 register struct unixuser *tu;
1794 AFS_STATCNT(PUnlog);
1795 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1796 return EIO; /* Inappropriate ioctl for device */
1798 i = UHash(areq->uid);
1799 ObtainWriteLock(&afs_xuser, 227);
1800 for (tu = afs_users[i]; tu; tu = tu->next) {
1801 if (tu->uid == areq->uid) {
1803 tu->states &= ~UHasTokens;
1804 /* security is not having to say you're sorry */
1805 memset((char *)&tu->ct, 0, sizeof(struct ClearToken));
1807 ReleaseWriteLock(&afs_xuser);
1808 /* We have to drop the lock over the call to afs_ResetUserConns, since
1809 * it obtains the afs_xvcache lock. We could also keep the lock, and
1810 * modify ResetUserConns to take parm saying we obtained the lock
1811 * already, but that is overkill. By keeping the "tu" pointer
1812 * held over the released lock, we guarantee that we won't lose our
1813 * place, and that we'll pass over every user conn that existed when
1814 * we began this call.
1816 afs_ResetUserConns(tu);
1818 ObtainWriteLock(&afs_xuser, 228);
1820 /* set the expire times to 0, causes
1821 * afs_GCUserData to remove this entry
1823 tu->ct.EndTimestamp = 0;
1825 #endif /* UKERNEL */
1828 ReleaseWriteLock(&afs_xuser);
1832 DECL_PIOCTL(PMariner)
1834 afs_int32 newHostAddr;
1835 afs_int32 oldHostAddr;
1837 AFS_STATCNT(PMariner);
1839 memcpy((char *)&oldHostAddr, (char *)&afs_marinerHost,
1842 oldHostAddr = 0xffffffff; /* disabled */
1844 memcpy((char *)&newHostAddr, ain, sizeof(afs_int32));
1845 if (newHostAddr == 0xffffffff) {
1846 /* disable mariner operations */
1848 } else if (newHostAddr) {
1850 afs_marinerHost = newHostAddr;
1852 memcpy(aout, (char *)&oldHostAddr, sizeof(afs_int32));
1853 *aoutSize = sizeof(afs_int32);
1857 DECL_PIOCTL(PCheckServers)
1859 register char *cp = 0;
1861 register struct server *ts;
1862 afs_int32 temp, *lp = (afs_int32 *) ain, havecell = 0;
1864 struct chservinfo *pcheck;
1866 AFS_STATCNT(PCheckServers);
1868 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1869 return EIO; /* Inappropriate ioctl for device */
1871 if (*lp == 0x12345678) { /* For afs3.3 version */
1872 pcheck = (struct chservinfo *)ain;
1873 if (pcheck->tinterval >= 0) {
1875 memcpy(cp, (char *)&afs_probe_interval, sizeof(afs_int32));
1876 *aoutSize = sizeof(afs_int32);
1877 if (pcheck->tinterval > 0) {
1878 if (!afs_osi_suser(*acred))
1880 afs_probe_interval = pcheck->tinterval;
1886 temp = pcheck->tflags;
1887 cp = pcheck->tbuffer;
1888 } else { /* For pre afs3.3 versions */
1889 memcpy((char *)&temp, ain, sizeof(afs_int32));
1890 cp = ain + sizeof(afs_int32);
1891 if (ainSize > sizeof(afs_int32))
1896 * 1: fast check, don't contact servers.
1897 * 2: local cell only.
1900 /* have cell name, too */
1901 cellp = afs_GetCellByName(cp, READ_LOCK);
1906 if (!cellp && (temp & 2)) {
1907 /* use local cell */
1908 cellp = afs_GetPrimaryCell(READ_LOCK);
1910 if (!(temp & 1)) { /* if not fast, call server checker routine */
1911 afs_CheckServers(1, cellp); /* check down servers */
1912 afs_CheckServers(0, cellp); /* check up servers */
1914 /* now return the current down server list */
1916 ObtainReadLock(&afs_xserver);
1917 for (i = 0; i < NSERVERS; i++) {
1918 for (ts = afs_servers[i]; ts; ts = ts->next) {
1919 if (cellp && ts->cell != cellp)
1920 continue; /* cell spec'd and wrong */
1921 if ((ts->flags & SRVR_ISDOWN)
1922 && ts->addr->sa_portal != ts->cell->vlport) {
1923 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
1924 cp += sizeof(afs_int32);
1928 ReleaseReadLock(&afs_xserver);
1930 afs_PutCell(cellp, READ_LOCK);
1931 *aoutSize = cp - aout;
1935 DECL_PIOCTL(PCheckVolNames)
1937 AFS_STATCNT(PCheckVolNames);
1938 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1939 return EIO; /* Inappropriate ioctl for device */
1941 afs_CheckRootVolume();
1942 afs_CheckVolumeNames(AFS_VOLCHECK_FORCE | AFS_VOLCHECK_EXPIRED |
1943 AFS_VOLCHECK_BUSY | AFS_VOLCHECK_MTPTS);
1947 DECL_PIOCTL(PCheckAuth)
1952 struct unixuser *tu;
1955 AFS_STATCNT(PCheckAuth);
1956 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1957 return EIO; /* Inappropriate ioctl for device */
1960 tu = afs_GetUser(areq->uid, 1, READ_LOCK); /* check local cell authentication */
1964 /* we have a user */
1965 ObtainReadLock(&afs_xsrvAddr);
1966 ObtainReadLock(&afs_xconn);
1968 /* any tokens set? */
1969 if ((tu->states & UHasTokens) == 0)
1971 /* all connections in cell 1 working? */
1972 for (i = 0; i < NSERVERS; i++) {
1973 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
1974 for (tc = sa->conns; tc; tc = tc->next) {
1975 if (tc->user == tu && (tu->states & UTokensBad))
1980 ReleaseReadLock(&afs_xsrvAddr);
1981 ReleaseReadLock(&afs_xconn);
1982 afs_PutUser(tu, READ_LOCK);
1984 memcpy(aout, (char *)&retValue, sizeof(afs_int32));
1985 *aoutSize = sizeof(afs_int32);
1990 Prefetch(char *apath, struct afs_ioctl *adata, int afollow,
1991 struct AFS_UCRED *acred)
1994 register afs_int32 code;
1995 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2001 AFS_STATCNT(Prefetch);
2004 tp = osi_AllocLargeSpace(1024);
2005 AFS_COPYINSTR(apath, tp, 1024, &bufferSize, code);
2007 osi_FreeLargeSpace(tp);
2010 if (afs_BBusy()) { /* do this as late as possible */
2011 osi_FreeLargeSpace(tp);
2012 return EWOULDBLOCK; /* pretty close */
2014 afs_BQueue(BOP_PATH, (struct vcache *)0, 0, 0, acred, (afs_size_t) 0,
2015 (afs_size_t) 0, tp);
2019 DECL_PIOCTL(PFindVolume)
2021 register struct volume *tvp;
2022 register struct server *ts;
2023 register afs_int32 i;
2026 AFS_STATCNT(PFindVolume);
2029 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
2032 for (i = 0; i < MAXHOSTS; i++) {
2033 ts = tvp->serverHost[i];
2036 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
2037 cp += sizeof(afs_int32);
2040 /* still room for terminating NULL, add it on */
2041 ainSize = 0; /* reuse vbl */
2042 memcpy(cp, (char *)&ainSize, sizeof(afs_int32));
2043 cp += sizeof(afs_int32);
2045 *aoutSize = cp - aout;
2046 afs_PutVolume(tvp, READ_LOCK);
2052 DECL_PIOCTL(PViceAccess)
2054 register afs_int32 code;
2057 AFS_STATCNT(PViceAccess);
2060 code = afs_VerifyVCache(avc, areq);
2063 memcpy((char *)&temp, ain, sizeof(afs_int32));
2064 code = afs_AccessOK(avc, temp, areq, CHECK_MODE_BITS);
2071 DECL_PIOCTL(PPrecache)
2075 /*AFS_STATCNT(PPrecache);*/
2076 if (!afs_osi_suser(*acred))
2078 memcpy((char *)&newValue, ain, sizeof(afs_int32));
2079 afs_preCache = newValue*1024;
2083 DECL_PIOCTL(PSetCacheSize)
2088 AFS_STATCNT(PSetCacheSize);
2089 if (!afs_osi_suser(*acred))
2091 /* too many things are setup initially in mem cache version */
2092 if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
2094 memcpy((char *)&newValue, ain, sizeof(afs_int32));
2096 afs_cacheBlocks = afs_stats_cmperf.cacheBlocksOrig;
2098 if (newValue < afs_min_cache)
2099 afs_cacheBlocks = afs_min_cache;
2101 afs_cacheBlocks = newValue;
2103 afs_stats_cmperf.cacheBlocksTotal = afs_cacheBlocks;
2104 afs_ComputeCacheParms(); /* recompute basic cache parameters */
2105 afs_MaybeWakeupTruncateDaemon();
2106 while (waitcnt++ < 100 && afs_cacheBlocks < afs_blocksUsed) {
2107 afs_osi_Wait(1000, 0, 0);
2108 afs_MaybeWakeupTruncateDaemon();
2113 #define MAXGCSTATS 16
2114 DECL_PIOCTL(PGetCacheSize)
2116 afs_int32 results[MAXGCSTATS];
2118 register struct dcache * tdc;
2121 AFS_STATCNT(PGetCacheSize);
2123 if (sizeof(afs_int32) == ainSize){
2124 memcpy((char *)&flags, ain, sizeof(afs_int32));
2125 } else if (0 == ainSize){
2131 memset((char *)results, 0, sizeof(results));
2132 results[0] = afs_cacheBlocks;
2133 results[1] = afs_blocksUsed;
2134 results[2] = afs_cacheFiles;
2137 for (i = 0; i < afs_cacheFiles; i++) {
2138 if (afs_indexFlags[i] & IFFree) results[3]++;
2140 } else if (2 == flags){
2141 for (i = 0; i < afs_cacheFiles; i++) {
2142 if (afs_indexFlags[i] & IFFree) results[3]++;
2143 if (afs_indexFlags[i] & IFEverUsed) results[4]++;
2144 if (afs_indexFlags[i] & IFDataMod) results[5]++;
2145 if (afs_indexFlags[i] & IFDirtyPages) results[6]++;
2146 if (afs_indexFlags[i] & IFAnyPages) results[7]++;
2147 if (afs_indexFlags[i] & IFDiscarded) results[8]++;
2149 tdc = afs_indexTable[i];
2152 size = tdc->validPos;
2153 if ( 0 < size && size < (1<<12) ) results[10]++;
2154 else if (size < (1<<14) ) results[11]++;
2155 else if (size < (1<<16) ) results[12]++;
2156 else if (size < (1<<18) ) results[13]++;
2157 else if (size < (1<<20) ) results[14]++;
2158 else if (size >= (1<<20) ) results[15]++;
2162 memcpy(aout, (char *)results, sizeof(results));
2163 *aoutSize = sizeof(results);
2167 DECL_PIOCTL(PRemoveCallBack)
2169 register struct conn *tc;
2170 register afs_int32 code = 0;
2171 struct AFSCallBack CallBacks_Array[1];
2172 struct AFSCBFids theFids;
2173 struct AFSCBs theCBs;
2176 AFS_STATCNT(PRemoveCallBack);
2179 if (avc->states & CRO)
2180 return 0; /* read-only-ness can't change */
2181 ObtainWriteLock(&avc->lock, 229);
2182 theFids.AFSCBFids_len = 1;
2183 theCBs.AFSCBs_len = 1;
2184 theFids.AFSCBFids_val = (struct AFSFid *)&avc->fid.Fid;
2185 theCBs.AFSCBs_val = CallBacks_Array;
2186 CallBacks_Array[0].CallBackType = CB_DROPPED;
2187 if (avc->callback) {
2189 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2191 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
2193 code = RXAFS_GiveUpCallBacks(tc->id, &theFids, &theCBs);
2197 /* don't set code on failure since we wouldn't use it */
2198 } while (afs_Analyze
2199 (tc, code, &avc->fid, areq,
2200 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK, NULL));
2202 ObtainWriteLock(&afs_xcbhash, 457);
2203 afs_DequeueCallback(avc);
2205 avc->states &= ~(CStatd | CUnique);
2206 ReleaseWriteLock(&afs_xcbhash);
2207 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
2208 osi_dnlc_purgedp(avc);
2210 ReleaseWriteLock(&avc->lock);
2214 DECL_PIOCTL(PNewCell)
2216 /* create a new cell */
2217 afs_int32 cellHosts[MAXCELLHOSTS], *lp, magic = 0;
2218 char *newcell = 0, *linkedcell = 0, *tp = ain;
2219 register afs_int32 code, linkedstate = 0, ls;
2220 u_short fsport = 0, vlport = 0;
2223 AFS_STATCNT(PNewCell);
2224 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2225 return EIO; /* Inappropriate ioctl for device */
2227 if (!afs_osi_suser(*acred))
2230 memcpy((char *)&magic, tp, sizeof(afs_int32));
2231 tp += sizeof(afs_int32);
2232 if (magic != 0x12345678)
2235 /* A 3.4 fs newcell command will pass an array of MAXCELLHOSTS
2236 * server addresses while the 3.5 fs newcell command passes
2237 * MAXHOSTS. To figure out which is which, check if the cellname
2240 newcell = tp + (MAXCELLHOSTS + 3) * sizeof(afs_int32);
2241 scount = ((newcell[0] != '\0') ? MAXCELLHOSTS : MAXHOSTS);
2243 /* MAXCELLHOSTS (=8) is less than MAXHOSTS (=13) */
2244 memcpy((char *)cellHosts, tp, MAXCELLHOSTS * sizeof(afs_int32));
2245 tp += (scount * sizeof(afs_int32));
2247 lp = (afs_int32 *) tp;
2251 fsport = 0; /* Privileged ports not allowed */
2253 vlport = 0; /* Privileged ports not allowed */
2254 tp += (3 * sizeof(afs_int32));
2256 if ((ls = *lp) & 1) {
2257 linkedcell = tp + strlen(newcell) + 1;
2258 linkedstate |= CLinkedCell;
2261 linkedstate |= CNoSUID; /* setuid is disabled by default for fs newcell */
2263 afs_NewCell(newcell, cellHosts, linkedstate, linkedcell, fsport,
2268 DECL_PIOCTL(PNewAlias)
2270 /* create a new cell alias */
2272 register afs_int32 code;
2273 char *realName, *aliasName;
2275 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2276 return EIO; /* Inappropriate ioctl for device */
2278 if (!afs_osi_suser(*acred))
2282 tp += strlen(aliasName) + 1;
2285 code = afs_NewCellAlias(aliasName, realName);
2290 DECL_PIOCTL(PListCells)
2292 afs_int32 whichCell;
2293 register struct cell *tcell = 0;
2294 register afs_int32 i;
2295 register char *cp, *tp = ain;
2297 AFS_STATCNT(PListCells);
2298 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2299 return EIO; /* Inappropriate ioctl for device */
2301 memcpy((char *)&whichCell, tp, sizeof(afs_int32));
2302 tp += sizeof(afs_int32);
2303 tcell = afs_GetCellByIndex(whichCell, READ_LOCK);
2306 memset(cp, 0, MAXCELLHOSTS * sizeof(afs_int32));
2307 for (i = 0; i < MAXCELLHOSTS; i++) {
2308 if (tcell->cellHosts[i] == 0)
2310 memcpy(cp, (char *)&tcell->cellHosts[i]->addr->sa_ip,
2312 cp += sizeof(afs_int32);
2314 cp = aout + MAXCELLHOSTS * sizeof(afs_int32);
2315 strcpy(cp, tcell->cellName);
2316 cp += strlen(tcell->cellName) + 1;
2317 *aoutSize = cp - aout;
2318 afs_PutCell(tcell, READ_LOCK);
2326 DECL_PIOCTL(PListAliases)
2328 afs_int32 whichAlias;
2329 register struct cell_alias *tcalias = 0;
2330 register char *cp, *tp = ain;
2332 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2333 return EIO; /* Inappropriate ioctl for device */
2334 if (ainSize < sizeof(afs_int32))
2337 memcpy((char *)&whichAlias, tp, sizeof(afs_int32));
2338 tp += sizeof(afs_int32);
2340 tcalias = afs_GetCellAlias(whichAlias);
2343 strcpy(cp, tcalias->alias);
2344 cp += strlen(tcalias->alias) + 1;
2345 strcpy(cp, tcalias->cell);
2346 cp += strlen(tcalias->cell) + 1;
2347 *aoutSize = cp - aout;
2348 afs_PutCellAlias(tcalias);
2356 DECL_PIOCTL(PRemoveMount)
2358 register afs_int32 code;
2360 struct sysname_info sysState;
2361 afs_size_t offset, len;
2362 register struct conn *tc;
2363 register struct dcache *tdc;
2364 register struct vcache *tvc;
2365 struct AFSFetchStatus OutDirStatus;
2366 struct VenusFid tfid;
2367 struct AFSVolSync tsync;
2371 /* "ain" is the name of the file in this dir to remove */
2373 AFS_STATCNT(PRemoveMount);
2376 code = afs_VerifyVCache(avc, areq);
2379 if (vType(avc) != VDIR)
2382 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1); /* test for error below */
2385 Check_AtSys(avc, ain, &sysState, areq);
2386 ObtainReadLock(&tdc->lock);
2388 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
2389 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
2390 ReleaseReadLock(&tdc->lock);
2391 bufp = sysState.name;
2396 tfid.Cell = avc->fid.Cell;
2397 tfid.Fid.Volume = avc->fid.Fid.Volume;
2398 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
2399 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
2401 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
2408 if (tvc->mvstat != 1) {
2414 ObtainWriteLock(&tvc->lock, 230);
2415 code = afs_HandleLink(tvc, areq);
2417 if (tvc->linkData) {
2418 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
2423 ReleaseWriteLock(&tvc->lock);
2424 osi_dnlc_purgedp(tvc);
2430 ObtainWriteLock(&avc->lock, 231);
2431 osi_dnlc_remove(avc, bufp, tvc);
2433 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2435 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE);
2438 RXAFS_RemoveFile(tc->id, (struct AFSFid *)&avc->fid.Fid, bufp,
2439 &OutDirStatus, &tsync);
2444 } while (afs_Analyze
2445 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_REMOVEFILE,
2446 SHARED_LOCK, NULL));
2451 ReleaseWriteLock(&avc->lock);
2455 /* we have the thing in the cache */
2456 ObtainWriteLock(&tdc->lock, 661);
2457 if (afs_LocalHero(avc, tdc, &OutDirStatus, 1)) {
2458 /* we can do it locally */
2459 code = afs_dir_Delete(tdc, bufp);
2461 ZapDCE(tdc); /* surprise error -- invalid value */
2465 ReleaseWriteLock(&tdc->lock);
2466 afs_PutDCache(tdc); /* drop ref count */
2468 avc->states &= ~CUnique; /* For the dfs xlator */
2469 ReleaseWriteLock(&avc->lock);
2472 if (sysState.allocked)
2473 osi_FreeLargeSpace(bufp);
2477 DECL_PIOCTL(PVenusLogging)
2479 return EINVAL; /* OBSOLETE */
2482 DECL_PIOCTL(PGetCellStatus)
2484 register struct cell *tcell;
2487 AFS_STATCNT(PGetCellStatus);
2488 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2489 return EIO; /* Inappropriate ioctl for device */
2491 tcell = afs_GetCellByName(ain, READ_LOCK);
2494 temp = tcell->states;
2495 afs_PutCell(tcell, READ_LOCK);
2496 memcpy(aout, (char *)&temp, sizeof(afs_int32));
2497 *aoutSize = sizeof(afs_int32);
2501 DECL_PIOCTL(PSetCellStatus)
2503 register struct cell *tcell;
2506 if (!afs_osi_suser(*acred))
2508 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2509 return EIO; /* Inappropriate ioctl for device */
2511 tcell = afs_GetCellByName(ain + 2 * sizeof(afs_int32), WRITE_LOCK);
2514 memcpy((char *)&temp, ain, sizeof(afs_int32));
2516 tcell->states |= CNoSUID;
2518 tcell->states &= ~CNoSUID;
2519 afs_PutCell(tcell, WRITE_LOCK);
2523 DECL_PIOCTL(PFlushVolumeData)
2525 register afs_int32 i;
2526 register struct dcache *tdc;
2527 register struct vcache *tvc;
2528 register struct volume *tv;
2529 afs_int32 cell, volume;
2530 struct afs_q *tq, *uq;
2531 #ifdef AFS_DARWIN80_ENV
2535 AFS_STATCNT(PFlushVolumeData);
2538 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2539 return EIO; /* Inappropriate ioctl for device */
2541 volume = avc->fid.Fid.Volume; /* who to zap */
2542 cell = avc->fid.Cell;
2545 * Clear stat'd flag from all vnodes from this volume; this will invalidate all
2546 * the vcaches associated with the volume.
2549 ObtainReadLock(&afs_xvcache);
2550 i = VCHashV(&avc->fid);
2551 for (tq = afs_vhashTV[i].prev; tq != &afs_vhashTV[i]; tq = uq) {
2554 if (tvc->fid.Fid.Volume == volume && tvc->fid.Cell == cell) {
2555 if (tvc->states & CVInit) {
2556 ReleaseReadLock(&afs_xvcache);
2557 afs_osi_Sleep(&tvc->states);
2560 #ifdef AFS_DARWIN80_ENV
2561 if (tvc->states & CDeadVnode) {
2562 ReleaseReadLock(&afs_xvcache);
2563 afs_osi_Sleep(&tvc->states);
2567 #if defined(AFS_SGI_ENV) || defined(AFS_OSF_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
2568 VN_HOLD(AFSTOV(tvc));
2570 #ifdef AFS_DARWIN80_ENV
2574 if (vnode_ref(vp)) {
2581 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2584 VREFCOUNT_INC(tvc); /* AIX, apparently */
2588 ReleaseReadLock(&afs_xvcache);
2589 #ifdef AFS_BOZONLOCK_ENV
2590 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
2592 ObtainWriteLock(&tvc->lock, 232);
2594 ObtainWriteLock(&afs_xcbhash, 458);
2595 afs_DequeueCallback(tvc);
2596 tvc->states &= ~(CStatd | CDirty);
2597 ReleaseWriteLock(&afs_xcbhash);
2598 if (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
2599 osi_dnlc_purgedp(tvc);
2600 afs_TryToSmush(tvc, *acred, 1);
2601 ReleaseWriteLock(&tvc->lock);
2602 #ifdef AFS_BOZONLOCK_ENV
2603 afs_BozonUnlock(&tvc->pvnLock, tvc);
2605 #ifdef AFS_DARWIN80_ENV
2606 vnode_put(AFSTOV(tvc));
2608 ObtainReadLock(&afs_xvcache);
2610 /* our tvc ptr is still good until now */
2614 ReleaseReadLock(&afs_xvcache);
2617 MObtainWriteLock(&afs_xdcache, 328); /* needed if you're going to flush any stuff */
2618 for (i = 0; i < afs_cacheFiles; i++) {
2619 if (!(afs_indexFlags[i] & IFEverUsed))
2620 continue; /* never had any data */
2621 tdc = afs_GetDSlot(i, NULL);
2622 if (tdc->refCount <= 1) { /* too high, in use by running sys call */
2623 ReleaseReadLock(&tdc->tlock);
2624 if (tdc->f.fid.Fid.Volume == volume && tdc->f.fid.Cell == cell) {
2625 if (!(afs_indexFlags[i] & IFDataMod)) {
2626 /* if the file is modified, but has a ref cnt of only 1, then
2627 * someone probably has the file open and is writing into it.
2628 * Better to skip flushing such a file, it will be brought back
2629 * immediately on the next write anyway.
2631 * If we *must* flush, then this code has to be rearranged to call
2632 * afs_storeAllSegments() first */
2633 afs_FlushDCache(tdc);
2637 ReleaseReadLock(&tdc->tlock);
2639 afs_PutDCache(tdc); /* bumped by getdslot */
2641 MReleaseWriteLock(&afs_xdcache);
2643 ObtainReadLock(&afs_xvolume);
2644 for (i = 0; i < NVOLS; i++) {
2645 for (tv = afs_volumes[i]; tv; tv = tv->next) {
2646 if (tv->volume == volume) {
2647 afs_ResetVolumeInfo(tv);
2652 ReleaseReadLock(&afs_xvolume);
2654 /* probably, a user is doing this, probably, because things are screwed up.
2655 * maybe it's the dnlc's fault? */
2662 DECL_PIOCTL(PGetVnodeXStatus)
2664 register afs_int32 code;
2665 struct vcxstat stat;
2668 /* AFS_STATCNT(PGetVnodeXStatus); */
2671 code = afs_VerifyVCache(avc, areq);
2674 if (vType(avc) == VDIR)
2675 mode = PRSFS_LOOKUP;
2678 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
2681 memset(&stat, 0, sizeof(struct vcxstat));
2682 stat.fid = avc->fid;
2683 hset32(stat.DataVersion, hgetlo(avc->m.DataVersion));
2684 stat.lock = avc->lock;
2685 stat.parentVnode = avc->parentVnode;
2686 stat.parentUnique = avc->parentUnique;
2687 hset(stat.flushDV, avc->flushDV);
2688 hset(stat.mapDV, avc->mapDV);
2689 stat.truncPos = avc->truncPos;
2690 { /* just grab the first two - won't break anything... */
2691 struct axscache *ac;
2693 for (i = 0, ac = avc->Access; ac && i < CPSIZE; i++, ac = ac->next) {
2694 stat.randomUid[i] = ac->uid;
2695 stat.randomAccess[i] = ac->axess;
2698 stat.callback = afs_data_pointer_to_int32(avc->callback);
2699 stat.cbExpires = avc->cbExpires;
2700 stat.anyAccess = avc->anyAccess;
2701 stat.opens = avc->opens;
2702 stat.execsOrWriters = avc->execsOrWriters;
2703 stat.flockCount = avc->flockCount;
2704 stat.mvstat = avc->mvstat;
2705 stat.states = avc->states;
2706 memcpy(aout, (char *)&stat, sizeof(struct vcxstat));
2707 *aoutSize = sizeof(struct vcxstat);
2712 DECL_PIOCTL(PGetVnodeXStatus2)
2714 register afs_int32 code;
2715 struct vcxstat2 stat;
2720 code = afs_VerifyVCache(avc, areq);
2723 if (vType(avc) == VDIR)
2724 mode = PRSFS_LOOKUP;
2727 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
2730 memset(&stat, 0, sizeof(struct vcxstat2));
2732 stat.cbExpires = avc->cbExpires;
2733 stat.anyAccess = avc->anyAccess;
2734 stat.mvstat = avc->mvstat;
2735 stat.callerAccess = afs_GetAccessBits(avc, ~0, areq);
2737 memcpy(aout, (char *)&stat, sizeof(struct vcxstat2));
2738 *aoutSize = sizeof(struct vcxstat2);
2742 /* We require root for local sysname changes, but not for remote */
2743 /* (since we don't really believe remote uids anyway) */
2744 /* outname[] shouldn't really be needed- this is left as an excercise */
2745 /* for the reader. */
2746 DECL_PIOCTL(PSetSysName)
2748 char *cp, *cp2 = NULL, inname[MAXSYSNAME], outname[MAXSYSNAME];
2749 afs_int32 setsysname;
2751 register struct afs_exporter *exporter;
2752 register struct unixuser *au;
2753 register afs_int32 pag, error;
2754 int t, count, num = 0, allpags = 0;
2757 AFS_STATCNT(PSetSysName);
2758 if (!afs_globalVFS) {
2759 /* Afsd is NOT running; disable it */
2760 #if defined(KERNEL_HAVE_UERROR)
2761 return (setuerror(EINVAL), EINVAL);
2766 memset(inname, 0, MAXSYSNAME);
2767 memcpy(&setsysname, ain, sizeof(afs_int32));
2768 ain += sizeof(afs_int32);
2769 if (setsysname & 0x8000) {
2771 setsysname &= ~0x8000;
2776 if (setsysname < 0 || setsysname > MAXNUMSYSNAMES)
2779 for (cp = ain, count = 0; count < setsysname; count++) {
2780 /* won't go past end of ain since maxsysname*num < ain length */
2782 if (t >= MAXSYSNAME || t <= 0)
2784 /* check for names that can shoot us in the foot */
2785 if (*cp == '.' && (cp[1] == 0 || (cp[1] == '.' && cp[2] == 0)))
2791 /* inname gets first entry in case we're being a translator */
2793 memcpy(inname, ain, t + 1); /* include terminating null */
2797 if ((*acred)->cr_gid == RMTUSER_REQ ||
2798 (*acred)->cr_gid == RMTUSER_REQ_PRIV) { /* Handles all exporters */
2799 if (allpags && (*acred)->cr_gid != RMTUSER_REQ_PRIV) {
2802 pag = PagInCred(*acred);
2804 return EINVAL; /* Better than panicing */
2806 if (!(au = afs_FindUser(pag, -1, READ_LOCK))) {
2807 return EINVAL; /* Better than panicing */
2809 if (!(exporter = au->exporter)) {
2810 afs_PutUser(au, READ_LOCK);
2811 return EINVAL; /* Better than panicing */
2813 error = EXP_SYSNAME(exporter, (setsysname ? cp2 : NULL), &sysnamelist,
2816 if (error == ENODEV)
2817 foundname = 0; /* sysname not set yet! */
2819 afs_PutUser(au, READ_LOCK);
2824 strcpy(outname, sysnamelist[0]);
2826 afs_PutUser(au, READ_LOCK);
2830 /* Not xlating, so local case */
2832 osi_Panic("PSetSysName: !afs_sysname\n");
2833 if (!setsysname) { /* user just wants the info */
2834 strcpy(outname, afs_sysname);
2835 foundname = afs_sysnamecount;
2836 sysnamelist = afs_sysnamelist;
2837 } else { /* Local guy; only root can change sysname */
2838 if (!afs_osi_suser(*acred))
2841 /* allpags makes no sense for local use */
2845 /* clear @sys entries from the dnlc, once afs_lookup can
2846 * do lookups of @sys entries and thinks it can trust them */
2847 /* privs ok, store the entry, ... */
2848 strcpy(afs_sysname, inname);
2849 if (setsysname > 1) { /* ... or list */
2851 for (count = 1; count < setsysname; ++count) {
2852 if (!afs_sysnamelist[count])
2854 ("PSetSysName: no afs_sysnamelist entry to write\n");
2856 memcpy(afs_sysnamelist[count], cp, t + 1); /* include null */
2860 afs_sysnamecount = setsysname;
2865 cp = aout; /* not changing so report back the count and ... */
2866 memcpy(cp, (char *)&foundname, sizeof(afs_int32));
2867 cp += sizeof(afs_int32);
2869 strcpy(cp, outname); /* ... the entry, ... */
2870 cp += strlen(outname) + 1;
2871 for (count = 1; count < foundname; ++count) { /* ... or list. */
2872 if (!sysnamelist[count])
2874 ("PSetSysName: no afs_sysnamelist entry to read\n");
2875 t = strlen(sysnamelist[count]);
2876 if (t >= MAXSYSNAME)
2877 osi_Panic("PSetSysName: sysname entry garbled\n");
2878 strcpy(cp, sysnamelist[count]);
2882 *aoutSize = cp - aout;
2887 /* sequential search through the list of touched cells is not a good
2888 * long-term solution here. For small n, though, it should be just
2889 * fine. Should consider special-casing the local cell for large n.
2890 * Likewise for PSetSPrefs.
2892 * s - number of ids in array l[] -- NOT index of last id
2893 * l - array of cell ids which have volumes that need to be sorted
2894 * vlonly - sort vl servers or file servers?
2897 ReSortCells_cb(struct cell *cell, void *arg)
2899 afs_int32 *p = (afs_int32 *) arg;
2900 afs_int32 *l = p + 1;
2903 for (i = 0; i < s; i++) {
2904 if (l[i] == cell->cellNum) {
2905 ObtainWriteLock(&cell->lock, 690);
2906 afs_SortServers(cell->cellHosts, MAXCELLHOSTS);
2907 ReleaseWriteLock(&cell->lock);
2915 ReSortCells(int s, afs_int32 * l, int vlonly)
2923 p = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * (s + 1));
2925 memcpy(p + 1, l, s * sizeof(afs_int32));
2926 afs_TraverseCells(&ReSortCells_cb, p);
2927 afs_osi_Free(p, sizeof(afs_int32) * (s + 1));
2931 ObtainReadLock(&afs_xvolume);
2932 for (i = 0; i < NVOLS; i++) {
2933 for (j = afs_volumes[i]; j; j = j->next) {
2934 for (k = 0; k < s; k++)
2935 if (j->cell == l[k]) {
2936 ObtainWriteLock(&j->lock, 233);
2937 afs_SortServers(j->serverHost, MAXHOSTS);
2938 ReleaseWriteLock(&j->lock);
2943 ReleaseReadLock(&afs_xvolume);
2947 static int debugsetsp = 0;
2949 afs_setsprefs(sp, num, vlonly)
2952 unsigned int vlonly;
2955 int i, j, k, matches, touchedSize;
2956 struct server *srvr = NULL;
2957 afs_int32 touched[34];
2961 for (k = 0; k < num; sp++, k++) {
2963 printf("sp host=%x, rank=%d\n", sp->host.s_addr, sp->rank);
2966 ObtainReadLock(&afs_xserver);
2968 i = SHash(sp->host.s_addr);
2969 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2970 if (sa->sa_ip == sp->host.s_addr) {
2972 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
2973 || (sa->sa_portal == AFS_FSPORT);
2974 if ((!vlonly && isfs) || (vlonly && !isfs)) {
2981 if (sa && matches) { /* found one! */
2983 printf("sa ip=%x, ip_rank=%d\n", sa->sa_ip, sa->sa_iprank);
2985 sa->sa_iprank = sp->rank + afs_randomMod15();
2986 afs_SortOneServer(sa->server);
2989 /* if we don't know yet what cell it's in, this is moot */
2990 for (j = touchedSize - 1;
2991 j >= 0 && touched[j] != srvr->cell->cellNum; j--)
2992 /* is it in our list of touched cells ? */ ;
2993 if (j < 0) { /* no, it's not */
2994 touched[touchedSize++] = srvr->cell->cellNum;
2995 if (touchedSize >= 32) { /* watch for ovrflow */
2996 ReleaseReadLock(&afs_xserver);
2997 ReSortCells(touchedSize, touched, vlonly);
2999 ObtainReadLock(&afs_xserver);
3005 ReleaseReadLock(&afs_xserver);
3006 /* if we didn't find one, start to create one. */
3007 /* Note that it doesn't have a cell yet... */
3009 afs_uint32 temp = sp->host.s_addr;
3011 afs_GetServer(&temp, 1, 0, (vlonly ? AFS_VLPORT : AFS_FSPORT),
3012 WRITE_LOCK, (afsUUID *) 0, 0);
3013 srvr->addr->sa_iprank = sp->rank + afs_randomMod15();
3014 afs_PutServer(srvr, WRITE_LOCK);
3016 } /* for all cited preferences */
3018 ReSortCells(touchedSize, touched, vlonly);
3022 /* Note that this may only be performed by the local root user.
3024 DECL_PIOCTL(PSetSPrefs)
3026 struct setspref *ssp;
3027 AFS_STATCNT(PSetSPrefs);
3029 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3030 return EIO; /* Inappropriate ioctl for device */
3032 if (!afs_osi_suser(*acred))
3035 if (ainSize < sizeof(struct setspref))
3038 ssp = (struct setspref *)ain;
3039 if (ainSize < sizeof(struct spref) * ssp->num_servers)
3042 afs_setsprefs(&(ssp->servers[0]), ssp->num_servers,
3043 (ssp->flags & DBservers));
3047 DECL_PIOCTL(PSetSPrefs33)
3050 AFS_STATCNT(PSetSPrefs);
3051 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3052 return EIO; /* Inappropriate ioctl for device */
3055 if (!afs_osi_suser(*acred))
3058 sp = (struct spref *)ain;
3059 afs_setsprefs(sp, ainSize / (sizeof(struct spref)), 0 /*!vlonly */ );
3063 /* some notes on the following code...
3064 * in the hash table of server structs, all servers with the same IP address
3065 * will be on the same overflow chain.
3066 * This could be sped slightly in some circumstances by having it cache the
3067 * immediately previous slot in the hash table and some supporting information
3068 * Only reports file servers now.
3070 DECL_PIOCTL(PGetSPrefs)
3072 struct sprefrequest *spin; /* input */
3073 struct sprefinfo *spout; /* output */
3074 struct spref *srvout; /* one output component */
3075 int i, j; /* counters for hash table traversal */
3076 struct server *srvr; /* one of CM's server structs */
3078 int vlonly; /* just return vlservers ? */
3081 AFS_STATCNT(PGetSPrefs);
3082 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3083 return EIO; /* Inappropriate ioctl for device */
3086 if (ainSize < sizeof(struct sprefrequest_33)) {
3089 spin = ((struct sprefrequest *)ain);
3092 if (ainSize > sizeof(struct sprefrequest_33)) {
3093 vlonly = (spin->flags & DBservers);
3097 /* struct sprefinfo includes 1 server struct... that size gets added
3098 * in during the loop that follows.
3100 *aoutSize = sizeof(struct sprefinfo) - sizeof(struct spref);
3101 spout = (struct sprefinfo *)aout;
3102 spout->next_offset = spin->offset;
3103 spout->num_servers = 0;
3104 srvout = spout->servers;
3106 ObtainReadLock(&afs_xserver);
3107 for (i = 0, j = 0; j < NSERVERS; j++) { /* sift through hash table */
3108 for (sa = afs_srvAddrs[j]; sa; sa = sa->next_bkt, i++) {
3109 if (spin->offset > (unsigned short)i) {
3110 continue; /* catch up to where we left off */
3112 spout->next_offset++;
3115 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
3116 || (sa->sa_portal == AFS_FSPORT);
3118 if ((vlonly && isfs) || (!vlonly && !isfs)) {
3119 /* only report ranks for vl servers */
3123 srvout->host.s_addr = sa->sa_ip;
3124 srvout->rank = sa->sa_iprank;
3125 *aoutSize += sizeof(struct spref);
3126 spout->num_servers++;
3129 if (*aoutSize > (PIGGYSIZE - sizeof(struct spref))) {
3130 ReleaseReadLock(&afs_xserver); /* no more room! */
3135 ReleaseReadLock(&afs_xserver);
3137 spout->next_offset = 0; /* start over from the beginning next time */
3141 /* Enable/Disable the specified exporter. Must be root to disable an exporter */
3142 int afs_NFSRootOnly = 1;
3143 DECL_PIOCTL(PExportAfs)
3145 afs_int32 export, newint =
3146 0, type, changestate, handleValue, convmode, pwsync, smounts;
3147 afs_int32 rempags = 0, pagcb = 0;
3148 register struct afs_exporter *exporter;
3150 AFS_STATCNT(PExportAfs);
3151 memcpy((char *)&handleValue, ain, sizeof(afs_int32));
3152 type = handleValue >> 24;
3157 exporter = exporter_find(type);
3159 export = handleValue & 3;
3160 changestate = handleValue & 0xfff;
3161 smounts = (handleValue >> 2) & 3;
3162 pwsync = (handleValue >> 4) & 3;
3163 convmode = (handleValue >> 6) & 3;
3164 rempags = (handleValue >> 8) & 3;
3165 pagcb = (handleValue >> 10) & 3;
3167 changestate = (handleValue >> 16) & 0x1;
3168 convmode = (handleValue >> 16) & 0x2;
3169 pwsync = (handleValue >> 16) & 0x4;
3170 smounts = (handleValue >> 16) & 0x8;
3171 export = handleValue & 0xff;
3174 /* Failed finding desired exporter; */
3178 handleValue = exporter->exp_states;
3179 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3180 *aoutSize = sizeof(afs_int32);
3182 if (!afs_osi_suser(*acred))
3183 return EACCES; /* Only superuser can do this */
3187 exporter->exp_states |= EXP_EXPORTED;
3189 exporter->exp_states &= ~EXP_EXPORTED;
3193 exporter->exp_states |= EXP_UNIXMODE;
3195 exporter->exp_states &= ~EXP_UNIXMODE;
3199 exporter->exp_states |= EXP_PWSYNC;
3201 exporter->exp_states &= ~EXP_PWSYNC;
3205 afs_NFSRootOnly = 0;
3206 exporter->exp_states |= EXP_SUBMOUNTS;
3208 afs_NFSRootOnly = 1;
3209 exporter->exp_states &= ~EXP_SUBMOUNTS;
3214 exporter->exp_states |= EXP_CLIPAGS;
3216 exporter->exp_states &= ~EXP_CLIPAGS;
3220 exporter->exp_states |= EXP_CALLBACK;
3222 exporter->exp_states &= ~EXP_CALLBACK;
3224 handleValue = exporter->exp_states;
3225 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3226 *aoutSize = sizeof(afs_int32);
3229 exporter->exp_states |= EXP_EXPORTED;
3231 exporter->exp_states &= ~EXP_EXPORTED;
3233 exporter->exp_states |= EXP_UNIXMODE;
3235 exporter->exp_states &= ~EXP_UNIXMODE;
3237 exporter->exp_states |= EXP_PWSYNC;
3239 exporter->exp_states &= ~EXP_PWSYNC;
3241 afs_NFSRootOnly = 0;
3242 exporter->exp_states |= EXP_SUBMOUNTS;
3244 afs_NFSRootOnly = 1;
3245 exporter->exp_states &= ~EXP_SUBMOUNTS;
3255 struct gaginfo *gagflags;
3257 if (!afs_osi_suser(*acred))
3260 gagflags = (struct gaginfo *)ain;
3261 afs_showflags = gagflags->showflags;
3267 DECL_PIOCTL(PTwiddleRx)
3269 struct rxparams *rxp;
3271 if (!afs_osi_suser(*acred))
3274 rxp = (struct rxparams *)ain;
3276 if (rxp->rx_initReceiveWindow)
3277 rx_initReceiveWindow = rxp->rx_initReceiveWindow;
3278 if (rxp->rx_maxReceiveWindow)
3279 rx_maxReceiveWindow = rxp->rx_maxReceiveWindow;
3280 if (rxp->rx_initSendWindow)
3281 rx_initSendWindow = rxp->rx_initSendWindow;
3282 if (rxp->rx_maxSendWindow)
3283 rx_maxSendWindow = rxp->rx_maxSendWindow;
3284 if (rxp->rxi_nSendFrags)
3285 rxi_nSendFrags = rxp->rxi_nSendFrags;
3286 if (rxp->rxi_nRecvFrags)
3287 rxi_nRecvFrags = rxp->rxi_nRecvFrags;
3288 if (rxp->rxi_OrphanFragSize)
3289 rxi_OrphanFragSize = rxp->rxi_OrphanFragSize;
3290 if (rxp->rx_maxReceiveSize) {
3291 rx_maxReceiveSize = rxp->rx_maxReceiveSize;
3292 rx_maxReceiveSizeUser = rxp->rx_maxReceiveSize;
3294 if (rxp->rx_MyMaxSendSize)
3295 rx_MyMaxSendSize = rxp->rx_MyMaxSendSize;
3300 DECL_PIOCTL(PGetInitParams)
3302 if (sizeof(struct cm_initparams) > PIGGYSIZE)
3305 memcpy(aout, (char *)&cm_initParams, sizeof(struct cm_initparams));
3306 *aoutSize = sizeof(struct cm_initparams);
3310 #ifdef AFS_SGI65_ENV
3311 /* They took crget() from us, so fake it. */
3316 cr = crdup(get_current_cred());
3317 memset((char *)cr, 0, sizeof(cred_t));
3318 #if CELL || CELL_PREPARE
3325 DECL_PIOCTL(PGetRxkcrypt)
3327 memcpy(aout, (char *)&cryptall, sizeof(afs_int32));
3328 *aoutSize = sizeof(afs_int32);
3332 DECL_PIOCTL(PSetRxkcrypt)
3336 if (!afs_osi_suser(*acred))
3338 if (ainSize != sizeof(afs_int32) || ain == NULL)
3340 memcpy((char *)&tmpval, ain, sizeof(afs_int32));
3341 /* if new mappings added later this will need to be changed */
3342 if (tmpval != 0 && tmpval != 1)
3348 #ifdef AFS_NEED_CLIENTCONTEXT
3350 * Create new credentials to correspond to a remote user with given
3351 * <hostaddr, uid, g0, g1>. This allows a server running as root to
3352 * provide pioctl (and other) services to foreign clients (i.e. nfs
3353 * clients) by using this call to `become' the client.
3356 #define PIOCTL_HEADER 6
3358 HandleClientContext(struct afs_ioctl *ablob, int *com,
3359 struct AFS_UCRED **acred, struct AFS_UCRED *credp)
3362 afs_uint32 hostaddr;
3363 afs_int32 uid, g0, g1, i, code, pag, exporter_type, isroot = 0;
3364 struct afs_exporter *exporter, *outexporter;
3365 struct AFS_UCRED *newcred;
3366 struct unixuser *au;
3367 afs_uint32 comp = *com & 0xff00;
3370 #if defined(AFS_SGIMP_ENV)
3371 osi_Assert(ISAFS_GLOCK());
3373 AFS_STATCNT(HandleClientContext);
3374 if (ablob->in_size < PIOCTL_HEADER * sizeof(afs_int32)) {
3375 /* Must at least include the PIOCTL_HEADER header words required by the protocol */
3376 return EINVAL; /* Too small to be good */
3378 ain = inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
3379 AFS_COPYIN(ablob->in, ain, PIOCTL_HEADER * sizeof(afs_int32), code);
3381 osi_FreeLargeSpace(inData);
3385 /* Extract information for remote user */
3386 hostaddr = *((afs_uint32 *) ain);
3387 ain += sizeof(hostaddr);
3388 uid = *((afs_uint32 *) ain);
3390 g0 = *((afs_uint32 *) ain);
3392 g1 = *((afs_uint32 *) ain);
3394 *com = *((afs_uint32 *) ain);
3395 ain += sizeof(afs_int32);
3396 exporter_type = *((afs_uint32 *) ain); /* In case we support more than NFS */
3399 * Of course, one must be root for most of these functions, but
3400 * we'll allow (for knfs) you to set things if the pag is 0 and
3401 * you're setting tokens or unlogging.
3404 if (!afs_osi_suser(credp)) {
3405 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
3406 /* Since SGI's suser() returns explicit failure after the call.. */
3409 /* check for acceptable opcodes for normal folks, which are, so far,
3410 * get/set tokens, sysname, and unlog.
3412 if (i != 9 && i != 3 && i != 38 && i != 8) {
3413 osi_FreeLargeSpace(inData);
3418 ablob->in_size -= PIOCTL_HEADER * sizeof(afs_int32);
3419 ablob->in += PIOCTL_HEADER * sizeof(afs_int32);
3420 osi_FreeLargeSpace(inData);
3423 * We map uid 0 to nobody to match the mapping that the nfs
3424 * server does and to ensure that the suser() calls in the afs
3425 * code fails for remote client roots.
3427 uid = afs_nobody; /* NFS_NOBODY == -2 */
3431 #ifdef AFS_AIX41_ENV
3434 newcred->cr_gid = isroot ? RMTUSER_REQ_PRIV : RMTUSER_REQ;
3435 #ifdef AFS_AIX51_ENV
3436 newcred->cr_groupset.gs_union.un_groups[0] = g0;
3437 newcred->cr_groupset.gs_union.un_groups[1] = g1;
3438 #elif defined(AFS_LINUX26_ENV)
3439 #ifdef AFS_LINUX26_ONEGROUP_ENV
3440 newcred->cr_group_info = groups_alloc(1); /* not that anything sets this */
3441 l = (((g0-0x3f00) & 0x3fff) << 14) | ((g1-0x3f00) & 0x3fff);
3442 h = ((g0-0x3f00) >> 14);
3443 h = ((g1-0x3f00) >> 14) + h + h + h;
3444 GROUP_AT(newcred->cr_group_info, 0) = ((h << 28) | l);
3446 newcred->cr_group_info = groups_alloc(2);
3447 GROUP_AT(newcred->cr_group_info, 0) = g0;
3448 GROUP_AT(newcred->cr_group_info, 1) = g1;
3451 newcred->cr_groups[0] = g0;
3452 newcred->cr_groups[1] = g1;
3455 newcred->cr_ngrps = 2;
3456 #elif !defined(AFS_LINUX26_ENV)
3457 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
3458 newcred->cr_ngroups = 2;
3460 for (i = 2; i < NGROUPS; i++)
3461 newcred->cr_groups[i] = NOGROUP;
3464 #if !defined(AFS_OSF_ENV)
3465 afs_nfsclient_init(); /* before looking for exporter, ensure one exists */
3467 if (!(exporter = exporter_find(exporter_type))) {
3468 /* Exporter wasn't initialized or an invalid exporter type */
3472 if (exporter->exp_states & EXP_PWSYNC) {
3473 if (uid != credp->cr_uid) {
3475 return ENOEXEC; /* XXX Find a better errno XXX */
3478 newcred->cr_uid = uid; /* Only temporary */
3479 code = EXP_REQHANDLER(exporter, &newcred, hostaddr, &pag, &outexporter);
3480 /* The client's pag is the only unique identifier for it */
3481 newcred->cr_uid = pag;
3483 if (!code && *com == PSETPAG) {
3484 /* Special case for 'setpag' */
3485 afs_uint32 pagvalue = genpag();
3487 au = afs_GetUser(pagvalue, -1, WRITE_LOCK); /* a new unixuser struct */
3489 * Note that we leave the 'outexporter' struct held so it won't
3492 au->exporter = outexporter;
3493 if (ablob->out_size >= 4) {
3494 AFS_COPYOUT((char *)&pagvalue, ablob->out, sizeof(afs_int32),
3497 afs_PutUser(au, WRITE_LOCK);
3500 return PSETPAG; /* Special return for setpag */
3502 EXP_RELE(outexporter);
3505 *com = (*com) | comp;
3508 #endif /* AFS_NEED_CLIENTCONTEXT */
3510 /* get all interface addresses of this client */
3512 DECL_PIOCTL(PGetCPrefs)
3514 struct sprefrequest *spin; /* input */
3515 struct sprefinfo *spout; /* output */
3516 struct spref *srvout; /* one output component */
3520 AFS_STATCNT(PGetCPrefs);
3521 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3522 return EIO; /* Inappropriate ioctl for device */
3524 if (ainSize < sizeof(struct sprefrequest))
3527 spin = (struct sprefrequest *)ain;
3528 spout = (struct sprefinfo *)aout;
3530 maxNumber = spin->num_servers; /* max addrs this time */
3531 srvout = spout->servers;
3533 ObtainReadLock(&afs_xinterface);
3535 /* copy out the client interface information from the
3536 ** kernel data structure "interface" to the output buffer
3538 for (i = spin->offset, j = 0; (i < afs_cb_interface.numberOfInterfaces)
3539 && (j < maxNumber); i++, j++, srvout++)
3540 srvout->host.s_addr = afs_cb_interface.addr_in[i];
3542 spout->num_servers = j;
3543 *aoutSize = sizeof(struct sprefinfo) + (j - 1) * sizeof(struct spref);
3545 if (i >= afs_cb_interface.numberOfInterfaces)
3546 spout->next_offset = 0; /* start from beginning again */
3548 spout->next_offset = spin->offset + j;
3550 ReleaseReadLock(&afs_xinterface);
3554 DECL_PIOCTL(PSetCPrefs)
3556 struct setspref *sin;
3559 AFS_STATCNT(PSetCPrefs);
3560 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3561 return EIO; /* Inappropriate ioctl for device */
3563 sin = (struct setspref *)ain;
3565 if (ainSize < sizeof(struct setspref))
3567 #if 0 /* num_servers is unsigned */
3568 if (sin->num_servers < 0)
3571 if (sin->num_servers > AFS_MAX_INTERFACE_ADDR)
3574 ObtainWriteLock(&afs_xinterface, 412);
3575 afs_cb_interface.numberOfInterfaces = sin->num_servers;
3576 for (i = 0; (unsigned short)i < sin->num_servers; i++)
3577 afs_cb_interface.addr_in[i] = sin->servers[i].host.s_addr;
3579 ReleaseWriteLock(&afs_xinterface);
3583 DECL_PIOCTL(PFlushMount)
3585 register afs_int32 code;
3586 register struct vcache *tvc;
3587 register struct dcache *tdc;
3588 struct VenusFid tfid;
3590 struct sysname_info sysState;
3591 afs_size_t offset, len;
3593 AFS_STATCNT(PFlushMount);
3596 code = afs_VerifyVCache(avc, areq);
3599 if (vType(avc) != VDIR) {
3602 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
3605 Check_AtSys(avc, ain, &sysState, areq);
3606 ObtainReadLock(&tdc->lock);
3608 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
3609 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
3610 ReleaseReadLock(&tdc->lock);
3611 afs_PutDCache(tdc); /* we're done with the data */
3612 bufp = sysState.name;
3616 tfid.Cell = avc->fid.Cell;
3617 tfid.Fid.Volume = avc->fid.Fid.Volume;
3618 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
3619 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
3621 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3627 if (tvc->mvstat != 1) {
3632 #ifdef AFS_BOZONLOCK_ENV
3633 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
3635 ObtainWriteLock(&tvc->lock, 649);
3636 ObtainWriteLock(&afs_xcbhash, 650);
3637 afs_DequeueCallback(tvc);
3638 tvc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
3639 ReleaseWriteLock(&afs_xcbhash);
3640 /* now find the disk cache entries */
3641 afs_TryToSmush(tvc, *acred, 1);
3642 osi_dnlc_purgedp(tvc);
3643 if (tvc->linkData && !(tvc->states & CCore)) {
3644 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
3645 tvc->linkData = NULL;
3647 ReleaseWriteLock(&tvc->lock);
3648 #ifdef AFS_BOZONLOCK_ENV
3649 afs_BozonUnlock(&tvc->pvnLock, tvc);
3653 if (sysState.allocked)
3654 osi_FreeLargeSpace(bufp);
3658 DECL_PIOCTL(PRxStatProc)
3663 if (!afs_osi_suser(*acred)) {
3667 if (ainSize != sizeof(afs_int32)) {
3671 memcpy((char *)&flags, ain, sizeof(afs_int32));
3672 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3676 if (flags & AFSCALL_RXSTATS_ENABLE) {
3677 rx_enableProcessRPCStats();
3679 if (flags & AFSCALL_RXSTATS_DISABLE) {
3680 rx_disableProcessRPCStats();
3682 if (flags & AFSCALL_RXSTATS_CLEAR) {
3683 rx_clearProcessRPCStats(AFS_RX_STATS_CLEAR_ALL);
3691 DECL_PIOCTL(PRxStatPeer)
3696 if (!afs_osi_suser(*acred)) {
3700 if (ainSize != sizeof(afs_int32)) {
3704 memcpy((char *)&flags, ain, sizeof(afs_int32));
3705 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3709 if (flags & AFSCALL_RXSTATS_ENABLE) {
3710 rx_enablePeerRPCStats();
3712 if (flags & AFSCALL_RXSTATS_DISABLE) {
3713 rx_disablePeerRPCStats();
3715 if (flags & AFSCALL_RXSTATS_CLEAR) {
3716 rx_clearPeerRPCStats(AFS_RX_STATS_CLEAR_ALL);
3723 DECL_PIOCTL(PPrefetchFromTape)
3725 register afs_int32 code, code1;
3728 struct rx_call *tcall;
3729 struct AFSVolSync tsync;
3730 struct AFSFetchStatus OutStatus;
3731 struct AFSCallBack CallBack;
3732 struct VenusFid tfid;
3736 AFS_STATCNT(PSetAcl);
3740 if (ain && (ainSize == 3 * sizeof(afs_int32)))
3741 Fid = (struct AFSFid *)ain;
3743 Fid = &avc->fid.Fid;
3744 tfid.Cell = avc->fid.Cell;
3745 tfid.Fid.Volume = Fid->Volume;
3746 tfid.Fid.Vnode = Fid->Vnode;
3747 tfid.Fid.Unique = Fid->Unique;
3749 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3751 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3752 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &avc->fid);
3755 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3756 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &tvc->fid);
3759 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3763 tcall = rx_NewCall(tc->id);
3765 StartRXAFS_FetchData(tcall, (struct AFSFid *)&tvc->fid.Fid, 0,
3768 bytes = rx_Read(tcall, (char *)aout, sizeof(afs_int32));
3770 EndRXAFS_FetchData(tcall, &OutStatus, &CallBack, &tsync);
3772 code1 = rx_EndCall(tcall, code);
3776 } while (afs_Analyze
3777 (tc, code, &tvc->fid, areq, AFS_STATS_FS_RPCIDX_RESIDENCYRPCS,
3778 SHARED_LOCK, NULL));
3779 /* This call is done only to have the callback things handled correctly */
3780 afs_FetchStatus(tvc, &tfid, areq, &OutStatus);
3784 *aoutSize = sizeof(afs_int32);
3789 DECL_PIOCTL(PResidencyCmd)
3791 register afs_int32 code;
3794 struct ResidencyCmdInputs *Inputs;
3795 struct ResidencyCmdOutputs *Outputs;
3796 struct VenusFid tfid;
3799 Inputs = (struct ResidencyCmdInputs *)ain;
3800 Outputs = (struct ResidencyCmdOutputs *)aout;
3803 if (!ain || ainSize != sizeof(struct ResidencyCmdInputs))
3808 Fid = &avc->fid.Fid;
3810 tfid.Cell = avc->fid.Cell;
3811 tfid.Fid.Volume = Fid->Volume;
3812 tfid.Fid.Vnode = Fid->Vnode;
3813 tfid.Fid.Unique = Fid->Unique;
3815 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3816 afs_Trace3(afs_iclSetp, CM_TRACE_RESIDCMD, ICL_TYPE_POINTER, tvc,
3817 ICL_TYPE_INT32, Inputs->command, ICL_TYPE_FID, &tfid);
3821 if (Inputs->command) {
3823 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3827 RXAFS_ResidencyCmd(tc->id, Fid, Inputs,
3828 (struct ResidencyCmdOutputs *)aout);
3832 } while (afs_Analyze
3833 (tc, code, &tvc->fid, areq,
3834 AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK, NULL));
3835 /* This call is done to have the callback things handled correctly */
3836 afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3837 } else { /* just a status request, return also link data */
3839 Outputs->code = afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3840 Outputs->chars[0] = 0;
3841 if (vType(tvc) == VLNK) {
3842 ObtainWriteLock(&tvc->lock, 555);
3843 if (afs_HandleLink(tvc, areq) == 0)
3844 strncpy((char *)&Outputs->chars, tvc->linkData, MAXCMDCHARS);
3845 ReleaseWriteLock(&tvc->lock);
3852 *aoutSize = sizeof(struct ResidencyCmdOutputs);
3857 DECL_PIOCTL(PNewUuid)
3859 /*AFS_STATCNT(PNewUuid); */
3860 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
3861 return EIO; /* Inappropriate ioctl for device */
3863 if (!afs_osi_suser(acred))
3866 ObtainWriteLock(&afs_xinterface, 555);
3867 afs_uuid_create(&afs_cb_interface.uuid);
3868 ReleaseWriteLock(&afs_xinterface);
3869 ForceAllNewConnections();
3873 DECL_PIOCTL(PCallBackAddr)
3876 afs_uint32 addr, code;
3882 struct unixuser *tu;
3883 struct srvAddr **addrs;
3885 /*AFS_STATCNT(PCallBackAddr); */
3886 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
3887 return EIO; /* Inappropriate ioctl for device */
3889 if (!afs_osi_suser(acred))
3892 if (ainSize < sizeof(afs_int32))
3895 memcpy(&addr, ain, sizeof(afs_int32));
3897 ObtainReadLock(&afs_xinterface);
3898 for (i = 0; (unsigned short)i < afs_cb_interface.numberOfInterfaces; i++) {
3899 if (afs_cb_interface.addr_in[i] == addr)
3903 ReleaseWriteLock(&afs_xinterface);
3905 if (afs_cb_interface.addr_in[i] != addr)
3908 ObtainReadLock(&afs_xserver); /* Necessary? */
3909 ObtainReadLock(&afs_xsrvAddr);
3912 for (i = 0; i < NSERVERS; i++) {
3913 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3918 addrs = afs_osi_Alloc(srvAddrCount * sizeof(*addrs));
3920 for (i = 0; i < NSERVERS; i++) {
3921 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3922 if (j >= srvAddrCount)
3928 ReleaseReadLock(&afs_xsrvAddr);
3929 ReleaseReadLock(&afs_xserver);
3931 for (i = 0; i < j; i++) {
3937 /* vlserver has no callback conn */
3938 if (sa->sa_portal == AFS_VLPORT) {
3942 if (!ts->cell) /* not really an active server, anyway, it must */
3943 continue; /* have just been added by setsprefs */
3945 /* get a connection, even if host is down; bumps conn ref count */
3946 tu = afs_GetUser(areq->uid, ts->cell->cellNum, SHARED_LOCK);
3947 tc = afs_ConnBySA(sa, ts->cell->fsport, ts->cell->cellNum, tu,
3948 1 /*force */ , 1 /*create */ , SHARED_LOCK);
3949 afs_PutUser(tu, SHARED_LOCK);
3953 if ((sa->sa_flags & SRVADDR_ISDOWN) || afs_HaveCallBacksFrom(ts)) {
3954 if (sa->sa_flags & SRVADDR_ISDOWN) {
3955 rx_SetConnDeadTime(tc->id, 3);
3957 #ifdef RX_ENABLE_LOCKS
3959 #endif /* RX_ENABLE_LOCKS */
3960 code = RXAFS_CallBackRxConnAddr(tc->id, &addr);
3961 #ifdef RX_ENABLE_LOCKS
3963 #endif /* RX_ENABLE_LOCKS */
3965 afs_PutConn(tc, SHARED_LOCK); /* done with it now */
3966 } /* Outer loop over addrs */
3967 #endif /* UKERNEL */
3971 DECL_PIOCTL(PDiscon)
3973 #ifdef AFS_DISCON_ENV
3974 static afs_int32 mode;
3976 if (ainSize == sizeof(afs_int32)) {
3977 memcpy(&mode, ain, sizeof(afs_int32));
3979 /* 3 is magic, should be a #define. */
3980 afs_SetCheckServerNATmode(mode == 3);
3981 } else if (ainSize != 0) {
3985 /* Return new mode */
3986 memcpy(aout, &mode, sizeof(afs_int32));
3987 *aoutSize = sizeof(struct VenusFid);
3994 DECL_PIOCTL(PNFSNukeCreds)
3996 afs_uint32 addr, code;
3997 register afs_int32 i;
3998 register struct unixuser *tu;
4000 AFS_STATCNT(PUnlog);
4001 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4002 return EIO; /* Inappropriate ioctl for device */
4004 if (ainSize < sizeof(afs_int32))
4006 memcpy(&addr, ain, sizeof(afs_int32));
4008 if ((*acred)->cr_gid == RMTUSER_REQ_PRIV && !addr) {
4009 tu = afs_GetUser(areq->uid, -1, SHARED_LOCK);
4010 if (!tu->exporter || !(addr = EXP_GETHOST(tu->exporter))) {
4011 afs_PutUser(tu, SHARED_LOCK);
4014 afs_PutUser(tu, SHARED_LOCK);
4015 } else if (!afs_osi_suser(acred)) {
4019 ObtainWriteLock(&afs_xuser, 227);
4020 for (i = 0; i < NUSERS; i++) {
4021 for (tu = afs_users[i]; tu; tu = tu->next) {
4022 if (tu->exporter && EXP_CHECKHOST(tu->exporter, addr)) {
4024 tu->states &= ~UHasTokens;
4025 /* security is not having to say you're sorry */
4026 memset((char *)&tu->ct, 0, sizeof(struct ClearToken));
4028 ReleaseWriteLock(&afs_xuser);
4029 afs_ResetUserConns(tu);
4031 ObtainWriteLock(&afs_xuser, 228);
4033 /* set the expire times to 0, causes
4034 * afs_GCUserData to remove this entry
4036 tu->ct.EndTimestamp = 0;
4038 #endif /* UKERNEL */
4042 ReleaseWriteLock(&afs_xuser);