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(PSetSysName);
75 DECL_PIOCTL(PSetSPrefs);
76 DECL_PIOCTL(PSetSPrefs33);
77 DECL_PIOCTL(PGetSPrefs);
78 DECL_PIOCTL(PExportAfs);
80 DECL_PIOCTL(PTwiddleRx);
81 DECL_PIOCTL(PGetInitParams);
82 DECL_PIOCTL(PGetRxkcrypt);
83 DECL_PIOCTL(PSetRxkcrypt);
84 DECL_PIOCTL(PGetCPrefs);
85 DECL_PIOCTL(PSetCPrefs);
86 DECL_PIOCTL(PFlushMount);
87 DECL_PIOCTL(PRxStatProc);
88 DECL_PIOCTL(PRxStatPeer);
89 DECL_PIOCTL(PPrefetchFromTape);
90 DECL_PIOCTL(PResidencyCmd);
93 * A macro that says whether we're going to need HandleClientContext().
94 * This is currently used only by the nfs translator.
96 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
97 #define AFS_NEED_CLIENTCONTEXT
100 /* Prototypes for private routines */
101 #ifdef AFS_NEED_CLIENTCONTEXT
102 static int HandleClientContext(struct afs_ioctl *ablob, int *com,
103 struct AFS_UCRED **acred,
104 struct AFS_UCRED *credp);
106 int HandleIoctl(register struct vcache *avc, register afs_int32 acom,
107 struct afs_ioctl *adata);
108 int afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
109 register struct afs_ioctl *ablob, int afollow,
110 struct AFS_UCRED **acred);
111 static int Prefetch(char *apath, struct afs_ioctl *adata, int afollow,
112 struct AFS_UCRED *acred);
115 static int (*(VpioctlSw[])) () = {
120 PGetVolumeStatus, /* 4 */
121 PSetVolumeStatus, /* 5 */
126 PCheckServers, /* 10 */
127 PCheckVolNames, /* 11 */
129 PBogus, /* 13 -- used to be quick check time */
130 PFindVolume, /* 14 */
131 PBogus, /* 15 -- prefetch is now special-cased; see pioctl code! */
132 PBogus, /* 16 -- used to be testing code */
133 PNoop, /* 17 -- used to be enable group */
134 PNoop, /* 18 -- used to be disable group */
135 PBogus, /* 19 -- used to be list group */
136 PViceAccess, /* 20 */
137 PUnlog, /* 21 -- unlog *is* unpag in this system */
138 PGetFID, /* 22 -- get file ID */
139 PBogus, /* 23 -- used to be waitforever */
140 PSetCacheSize, /* 24 */
141 PRemoveCallBack, /* 25 -- flush only the callback */
144 PRemoveMount, /* 28 -- delete mount point */
145 PNewStatMount, /* 29 -- new style mount point stat */
146 PGetFileCell, /* 30 -- get cell name for input file */
147 PGetWSCell, /* 31 -- get cell name for workstation */
148 PMariner, /* 32 - set/get mariner host */
149 PGetUserCell, /* 33 -- get cell name for user */
150 PVenusLogging, /* 34 -- Enable/Disable logging */
151 PGetCellStatus, /* 35 */
152 PSetCellStatus, /* 36 */
153 PFlushVolumeData, /* 37 -- flush all data from a volume */
154 PSetSysName, /* 38 - Set system name */
155 PExportAfs, /* 39 - Export Afs to remote nfs clients */
156 PGetCacheSize, /* 40 - get cache size and usage */
157 PGetVnodeXStatus, /* 41 - get vcache's special status */
158 PSetSPrefs33, /* 42 - Set CM Server preferences... */
159 PGetSPrefs, /* 43 - Get CM Server preferences... */
160 PGag, /* 44 - turn off/on all CM messages */
161 PTwiddleRx, /* 45 - adjust some RX params */
162 PSetSPrefs, /* 46 - Set CM Server preferences... */
163 PStoreBehind, /* 47 - set degree of store behind to be done */
164 PGCPAGs, /* 48 - disable automatic pag gc-ing */
165 PGetInitParams, /* 49 - get initial cm params */
166 PGetCPrefs, /* 50 - get client interface addresses */
167 PSetCPrefs, /* 51 - set client interface addresses */
168 PFlushMount, /* 52 - flush mount symlink data */
169 PRxStatProc, /* 53 - control process RX statistics */
170 PRxStatPeer, /* 54 - control peer RX statistics */
171 PGetRxkcrypt, /* 55 -- Get rxkad encryption flag */
172 PSetRxkcrypt, /* 56 -- Set rxkad encryption flag */
173 PBogus, /* 57 -- arla: set file prio */
174 PBogus, /* 58 -- arla: fallback getfh */
175 PBogus, /* 59 -- arla: fallback fhopen */
176 PBogus, /* 60 -- arla: controls xfsdebug */
177 PBogus, /* 61 -- arla: controls arla debug */
178 PBogus, /* 62 -- arla: debug interface */
179 PBogus, /* 63 -- arla: print xfs status */
180 PBogus, /* 64 -- arla: force cache check */
181 PBogus, /* 65 -- arla: break callback */
182 PPrefetchFromTape, /* 66 -- MR-AFS: prefetch file from tape */
183 PResidencyCmd, /* 67 -- MR-AFS: generic commnd interface */
184 PBogus, /* 68 -- arla: fetch stats */
187 static int (*(CpioctlSw[])) () = {
189 PNewAlias, /* 1 -- create new cell alias */
190 PListAliases, /* 2 -- list cell aliases */
193 #define PSetClientContext 99 /* Special pioctl to setup caller's creds */
194 int afs_nobody = NFS_NOBODY;
197 afs_ioctl32_to_afs_ioctl(const struct afs_ioctl32 *src, struct afs_ioctl *dst)
199 dst->in = (char *)(unsigned long)src->in;
200 dst->out = (char *)(unsigned long)src->out;
201 dst->in_size = src->in_size;
202 dst->out_size = src->out_size;
206 * If you need to change copyin_afs_ioctl(), you may also need to change
211 copyin_afs_ioctl(caddr_t cmarg, struct afs_ioctl *dst)
214 #if defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)
215 struct afs_ioctl32 dst32;
218 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
220 afs_ioctl32_to_afs_ioctl(&dst32, dst);
223 #endif /* defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL) */
226 #if defined(AFS_HPUX_64BIT_ENV)
227 struct afs_ioctl32 dst32;
229 if (is_32bit(u.u_procp)) { /* is_32bit() in proc_iface.h */
230 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
232 afs_ioctl32_to_afs_ioctl(&dst32, dst);
235 #endif /* defined(AFS_HPUX_64BIT_ENV) */
237 #if defined(AFS_SUN57_64BIT_ENV)
238 struct afs_ioctl32 dst32;
240 if (get_udatamodel() == DATAMODEL_ILP32) {
241 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
243 afs_ioctl32_to_afs_ioctl(&dst32, dst);
246 #endif /* defined(AFS_SUN57_64BIT_ENV) */
248 #if defined(AFS_SGI_ENV) && (_MIPS_SZLONG==64)
249 struct afs_ioctl32 dst32;
251 if (!ABI_IS_64BIT(get_current_abi())) {
252 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
254 afs_ioctl32_to_afs_ioctl(&dst32, dst);
257 #endif /* defined(AFS_SGI_ENV) && (_MIPS_SZLONG==64) */
259 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV) && !defined(AFS_AMD64_LINUX20_ENV)
260 struct afs_ioctl32 dst32;
262 #ifdef AFS_SPARC64_LINUX24_ENV
263 if (current->thread.flags & SPARC_FLAG_32BIT)
264 #elif defined(AFS_SPARC64_LINUX20_ENV)
265 if (current->tss.flags & SPARC_FLAG_32BIT)
266 #elif defined(AFS_AMD64_LINUX20_ENV)
267 if (current->thread.flags & THREAD_IA32)
268 #elif defined(AFS_PPC64_LINUX20_ENV)
269 if (current->thread.flags & PPC_FLAG_32BIT)
271 #error Not done for this linux type
274 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
276 afs_ioctl32_to_afs_ioctl(&dst32, dst);
279 #endif /* defined(AFS_LINUX_64BIT_KERNEL) */
281 AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code);
286 HandleIoctl(register struct vcache *avc, register afs_int32 acom,
287 struct afs_ioctl *adata)
289 register afs_int32 code;
292 AFS_STATCNT(HandleIoctl);
294 switch (acom & 0xff) {
296 avc->states |= CSafeStore;
300 /* case 2 used to be abort store, but this is no longer provided,
301 * since it is impossible to implement under normal Unix.
305 /* return the name of the cell this file is open on */
306 register struct cell *tcell;
307 register afs_int32 i;
309 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
311 i = strlen(tcell->cellName) + 1; /* bytes to copy out */
313 if (i > adata->out_size) {
314 /* 0 means we're not interested in the output */
315 if (adata->out_size != 0)
319 AFS_COPYOUT(tcell->cellName, adata->out, i, code);
321 afs_PutCell(tcell, READ_LOCK);
327 case 49: /* VIOC_GETINITPARAMS */
328 if (adata->out_size < sizeof(struct cm_initparams)) {
331 AFS_COPYOUT(&cm_initParams, adata->out,
332 sizeof(struct cm_initparams), code);
344 return code; /* so far, none implemented */
349 /* For aix we don't temporarily bypass ioctl(2) but rather do our
350 * thing directly in the vnode layer call, VNOP_IOCTL; thus afs_ioctl
351 * is now called from afs_gn_ioctl.
354 afs_ioctl(struct vcache *tvc, int cmd, int arg)
356 struct afs_ioctl data;
359 AFS_STATCNT(afs_ioctl);
360 if (((cmd >> 8) & 0xff) == 'V') {
361 /* This is a VICEIOCTL call */
362 AFS_COPYIN(arg, (caddr_t) & data, sizeof(data), error);
365 error = HandleIoctl(tvc, cmd, &data);
368 /* No-op call; just return. */
372 #endif /* AFS_AIX_ENV */
374 #if defined(AFS_SGI_ENV)
375 afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
378 , struct vopbd * vbds
382 struct afs_ioctl data;
388 AFS_STATCNT(afs_ioctl);
389 if (((cmd >> 8) & 0xff) == 'V') {
390 /* This is a VICEIOCTL call */
391 error = copyin_afs_ioctl(arg, &data);
394 locked = ISAFS_GLOCK();
397 error = HandleIoctl(tvc, cmd, &data);
402 /* No-op call; just return. */
406 #endif /* AFS_SGI_ENV */
408 /* unlike most calls here, this one uses u.u_error to return error conditions,
409 since this is really an intercepted chapter 2 call, rather than a vnode
412 /* AFS_HPUX102 and up uses VNODE ioctl instead */
413 #ifndef AFS_HPUX102_ENV
414 #if !defined(AFS_SGI_ENV)
418 kioctl(fdes, com, arg, ext, arg2, arg3)
419 #else /* __64BIT__ */
420 kioctl32(fdes, com, arg, ext, arg2, arg3)
421 #endif /* __64BIT__ */
424 kioctl(fdes, com, arg, ext)
435 } u_uap, *uap = &u_uap;
437 #if defined(AFS_SUN5_ENV)
439 struct afs_ioctl_sys {
446 struct afs_ioctl_sys *uap;
449 #elif defined(AFS_OSF_ENV)
450 afs_xioctl(p, args, retval)
459 } *uap = (struct a *)args;
460 #elif defined(AFS_FBSD50_ENV)
463 afs_xioctl(td, uap, retval)
465 register struct ioctl_args *uap;
468 struct proc *p = td->td_proc;
469 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
477 afs_xioctl(p, uap, retval)
479 register struct ioctl_args *uap;
482 #elif defined(AFS_LINUX22_ENV)
483 struct afs_ioctl_sys {
488 afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
491 struct afs_ioctl_sys ua, *uap = &ua;
500 } *uap = (struct a *)u.u_ap;
501 #endif /* AFS_SUN5_ENV */
503 #if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
505 #elif !defined(AFS_LINUX22_ENV)
506 register struct file *fd;
508 #if defined(AFS_XBSD_ENV)
509 register struct filedesc *fdp;
511 register struct vcache *tvc;
512 register int ioctlDone = 0, code = 0;
514 AFS_STATCNT(afs_xioctl);
515 #if defined(AFS_XBSD_ENV)
517 if ((u_int) uap->fd >= fdp->fd_nfiles
518 || (fd = fdp->fd_ofiles[uap->fd]) == NULL)
520 if ((fd->f_flag & (FREAD | FWRITE)) == 0)
522 #elif defined(AFS_DARWIN_ENV)
523 if ((code = fdgetf(p, uap->fd, &fd)))
525 #elif defined(AFS_LINUX22_ENV)
528 #elif defined(AFS_AIX32_ENV)
536 if (setuerror(getf(uap->fd, &fd))) {
539 #elif defined(AFS_OSF_ENV)
541 if (code = getf(&fd, uap->fd, FILE_FLAGS_NULL, &u.u_file_state))
543 #elif defined(AFS_SUN5_ENV)
544 # if defined(AFS_SUN57_ENV)
548 # elif defined(AFS_SUN54_ENV)
553 if (code = getf(uap->fd, &fd)) {
556 # endif /* AFS_SUN57_ENV */
562 /* first determine whether this is any sort of vnode */
563 #if defined(AFS_LINUX22_ENV)
568 if (fd->f_vnode->v_type == VREG || fd->f_vnode->v_type == VDIR) {
570 if (fd->f_type == DTYPE_VNODE) {
572 /* good, this is a vnode; next see if it is an AFS vnode */
573 #if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV)
574 tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */
575 #elif defined(AFS_OBSD_ENV)
577 IsAfsVnode((struct vnode *)fd->
578 f_data) ? VTOAFS((struct vnode *)fd->f_data) : NULL;
580 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
582 #endif /* AFS_LINUX22_ENV */
583 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
585 tvc = VTOAFS(afs_gntovn((struct gnode *)tvc));
586 if (!tvc) { /* shouldn't happen with held gnodes */
591 /* This is an AFS vnode */
592 if (((uap->com >> 8) & 0xff) == 'V') {
593 register struct afs_ioctl *datap;
596 (struct afs_ioctl *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
597 AFS_COPYIN((char *)uap->arg, (caddr_t) datap,
598 sizeof(struct afs_ioctl), code);
600 osi_FreeSmallSpace(datap);
602 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
605 #if defined(AFS_SUN5_ENV)
620 #else /* AFS_OSF_ENV */
624 #ifdef AFS_LINUX22_ENV
634 code = HandleIoctl(tvc, uap->com, datap);
635 osi_FreeSmallSpace(datap);
649 #if defined(AFS_LINUX22_ENV)
661 code = okioctl(fdes, com, arg, ext, arg2, arg3);
662 #else /* __64BIT__ */
663 code = okioctl32(fdes, com, arg, ext, arg2, arg3);
664 #endif /* __64BIT__ */
665 #else /* !AFS_AIX51_ENV */
666 code = okioctl(fdes, com, arg, ext);
667 #endif /* AFS_AIX51_ENV */
669 #else /* !AFS_AIX41_ENV */
671 okioctl(fdes, com, arg, ext);
672 #elif defined(AFS_SUN5_ENV)
673 #if defined(AFS_SUN57_ENV)
675 #elif defined(AFS_SUN54_ENV)
680 code = ioctl(uap, rvp);
681 #elif defined(AFS_FBSD50_ENV)
682 return ioctl(td, uap);
683 #elif defined(AFS_FBSD_ENV)
684 return ioctl(p, uap);
685 #elif defined(AFS_OBSD_ENV)
686 code = sys_ioctl(p, uap, retval);
687 #elif defined(AFS_DARWIN_ENV)
688 return ioctl(p, uap, retval);
689 #elif defined(AFS_OSF_ENV)
690 code = ioctl(p, args, retval);
697 #elif !defined(AFS_LINUX22_ENV)
711 #ifdef AFS_LINUX22_ENV
714 #if defined(KERNEL_HAVE_UERROR)
717 #if defined(AFS_AIX32_ENV) && !defined(AFS_AIX41_ENV)
718 return (getuerror()? -1 : u.u_ioctlrv);
720 return getuerror()? -1 : 0;
723 #endif /* AFS_LINUX22_ENV */
724 #endif /* AFS_SUN5_ENV */
725 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
729 #endif /* AFS_SGI_ENV */
730 #endif /* AFS_HPUX102_ENV */
732 #if defined(AFS_SGI_ENV)
733 /* "pioctl" system call entry point; just pass argument to the parameterized
742 afs_pioctl(struct pioctlargs *uap, rval_t * rvp)
746 AFS_STATCNT(afs_pioctl);
748 code = afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow);
757 #elif defined(AFS_OSF_ENV)
758 afs_pioctl(p, args, retval)
768 } *uap = (struct a *)args;
770 AFS_STATCNT(afs_pioctl);
771 return (afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow));
774 #elif defined(AFS_FBSD50_ENV)
776 afs_pioctl(td, args, retval)
786 } *uap = (struct a *)args;
788 AFS_STATCNT(afs_pioctl);
789 return (afs_syscall_pioctl
790 (uap->path, uap->cmd, uap->cmarg, uap->follow, td->td_ucred));
793 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
795 afs_pioctl(p, args, retval)
805 } *uap = (struct a *)args;
807 AFS_STATCNT(afs_pioctl);
808 return (afs_syscall_pioctl
809 (uap->path, uap->cmd, uap->cmarg, uap->follow,
810 p->p_cred->pc_ucred));
815 /* macro to avoid adding any more #ifdef's to pioctl code. */
816 #if defined(AFS_LINUX22_ENV) || defined(AFS_AIX41_ENV)
817 #define PIOCTL_FREE_CRED() crfree(credp)
819 #define PIOCTL_FREE_CRED()
824 afs_syscall_pioctl(path, com, cmarg, follow, rvp, credp)
826 struct AFS_UCRED *credp;
828 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
829 afs_syscall_pioctl(path, com, cmarg, follow, credp)
830 struct AFS_UCRED *credp;
832 afs_syscall_pioctl(path, com, cmarg, follow)
840 struct afs_ioctl data;
841 struct AFS_UCRED *tmpcred, *foreigncreds = NULL;
842 register afs_int32 code = 0;
848 struct ucred *credp = crref(); /* don't free until done! */
850 #ifdef AFS_LINUX22_ENV
851 cred_t *credp = crref(); /* don't free until done! */
855 AFS_STATCNT(afs_syscall_pioctl);
857 follow = 1; /* compat. with old venus */
858 code = copyin_afs_ioctl(cmarg, &data);
861 #if defined(KERNEL_HAVE_UERROR)
866 if ((com & 0xff) == PSetClientContext) {
867 #ifdef AFS_NEED_CLIENTCONTEXT
868 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV)
869 code = HandleClientContext(&data, &com, &foreigncreds, credp);
871 code = HandleClientContext(&data, &com, &foreigncreds, osi_curcred());
875 crfree(foreigncreds);
878 #if defined(KERNEL_HAVE_UERROR)
879 return (setuerror(code), code);
884 #else /* AFS_NEED_CLIENTCONTEXT */
886 #endif /* AFS_NEED_CLIENTCONTEXT */
888 #ifdef AFS_NEED_CLIENTCONTEXT
891 * We could have done without temporary setting the u.u_cred below
892 * (foreigncreds could be passed as param the pioctl modules)
893 * but calls such as afs_osi_suser() doesn't allow that since it
894 * references u.u_cred directly. We could, of course, do something
895 * like afs_osi_suser(cred) which, I think, is better since it
896 * generalizes and supports multi cred environments...
900 credp = foreigncreds;
901 #elif defined(AFS_AIX41_ENV)
902 tmpcred = crref(); /* XXX */
904 #elif defined(AFS_HPUX101_ENV)
905 tmpcred = p_cred(u.u_procp);
906 set_p_cred(u.u_procp, foreigncreds);
907 #elif defined(AFS_SGI_ENV)
908 tmpcred = OSI_GET_CURRENT_CRED();
909 OSI_SET_CURRENT_CRED(foreigncreds);
912 u.u_cred = foreigncreds;
915 #endif /* AFS_NEED_CLIENTCONTEXT */
916 if ((com & 0xff) == 15) {
917 /* special case prefetch so entire pathname eval occurs in helper process.
918 * otherwise, the pioctl call is essentially useless */
919 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
921 Prefetch(path, &data, follow,
922 foreigncreds ? foreigncreds : credp);
924 code = Prefetch(path, &data, follow, osi_curcred());
927 #if defined(KERNEL_HAVE_UERROR)
936 lookupname(path, USR, follow, NULL, &vp,
937 foreigncreds ? foreigncreds : credp);
939 #ifdef AFS_LINUX22_ENV
940 code = gop_lookupname(path, AFS_UIOUSER, follow, NULL, &dp);
942 vp = (struct vnode *)dp->d_inode;
944 code = gop_lookupname(path, AFS_UIOUSER, follow, NULL, &vp);
945 #endif /* AFS_LINUX22_ENV */
946 #endif /* AFS_AIX41_ENV */
950 #if defined(KERNEL_HAVE_UERROR)
958 /* now make the call if we were passed no file, or were passed an AFS file */
959 if (!vp || IsAfsVnode(vp)) {
960 #if defined(AFS_DEC_ENV)
961 /* Ultrix 4.0: can't get vcache entry unless we've got an AFS gnode.
962 * So, we must test in this part of the code. Also, must arrange to
963 * GRELE the original gnode pointer when we're done, since in Ultrix 4.0,
964 * we hold gnodes, whose references hold our vcache entries.
967 gp = vp; /* remember for "put" */
968 vp = (struct vnode *)afs_gntovn(vp); /* get vcache from gp */
971 #elif defined(AFS_SUN5_ENV)
972 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
973 #elif defined(AFS_AIX41_ENV)
975 struct ucred *cred1, *cred2;
978 cred1 = cred2 = foreigncreds;
980 cred1 = cred2 = credp;
982 code = afs_HandlePioctl(vp, com, &data, follow, &cred1);
983 if (cred1 != cred2) {
984 /* something changed the creds */
988 #elif defined(AFS_HPUX101_ENV)
990 struct ucred *cred = p_cred(u.u_procp);
991 code = afs_HandlePioctl(vp, com, &data, follow, &cred);
993 #elif defined(AFS_SGI_ENV)
996 credp = OSI_GET_CURRENT_CRED();
997 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
999 #elif defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1000 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1002 code = afs_HandlePioctl(vp, com, &data, follow, &u.u_cred);
1005 #if defined(KERNEL_HAVE_UERROR)
1008 code = EINVAL; /* not in /afs */
1019 #if defined(AFS_NEED_CLIENTCONTEXT)
1021 #ifdef AFS_AIX41_ENV
1022 crset(tmpcred); /* restore original credentials */
1024 #if defined(AFS_HPUX101_ENV)
1025 set_p_cred(u.u_procp, tmpcred); /* restore original credentials */
1026 #elif defined(AFS_SGI_ENV)
1027 OSI_SET_CURRENT_CRED(tmpcred); /* restore original credentials */
1028 #elif !defined(AFS_SUN5_ENV)
1029 osi_curcred() = tmpcred; /* restore original credentials */
1030 #endif /* AFS_HPUX101_ENV */
1031 crfree(foreigncreds);
1034 #endif /* AFS_NEED_CLIENTCONTEXT */
1036 #ifdef AFS_LINUX22_ENV
1039 AFS_RELE(vp); /* put vnode back */
1043 #if defined(KERNEL_HAVE_UERROR)
1046 return (getuerror());
1054 afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
1055 register struct afs_ioctl *ablob, int afollow,
1056 struct AFS_UCRED **acred)
1059 struct vrequest treq;
1060 register afs_int32 code;
1061 register afs_int32 function, device;
1062 afs_int32 inSize, outSize;
1063 char *inData, *outData;
1064 int (*(*pioctlSw)) ();
1066 struct afs_fakestat_state fakestate;
1068 avc = avp ? VTOAFS(avp) : NULL;
1069 afs_Trace3(afs_iclSetp, CM_TRACE_PIOCTL, ICL_TYPE_INT32, acom & 0xff,
1070 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, afollow);
1071 AFS_STATCNT(HandlePioctl);
1072 if ((code = afs_InitReq(&treq, *acred)))
1074 afs_InitFakeStat(&fakestate);
1076 code = afs_EvalFakeStat(&avc, &fakestate, &treq);
1078 afs_PutFakeStat(&fakestate);
1082 device = (acom & 0xff00) >> 8;
1084 case 'V': /* Original pioctls */
1085 pioctlSw = VpioctlSw;
1086 pioctlSwSize = sizeof(VpioctlSw);
1088 case 'C': /* Coordinated/common pioctls */
1089 pioctlSw = CpioctlSw;
1090 pioctlSwSize = sizeof(CpioctlSw);
1093 afs_PutFakeStat(&fakestate);
1096 function = acom & 0xff;
1097 if (function >= (pioctlSwSize / sizeof(char *))) {
1098 afs_PutFakeStat(&fakestate);
1099 return EINVAL; /* out of range */
1101 inSize = ablob->in_size;
1103 /* Do all range checking before continuing */
1104 if (inSize >= PIGGYSIZE || inSize < 0 || ablob->out_size < 0)
1107 inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1109 AFS_COPYIN(ablob->in, inData, inSize, code);
1110 inData[inSize] = '\0';
1114 osi_FreeLargeSpace(inData);
1115 afs_PutFakeStat(&fakestate);
1118 outData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1121 (*pioctlSw[function]) (avc, function, &treq, inData, outData, inSize,
1123 osi_FreeLargeSpace(inData);
1124 if (code == 0 && ablob->out_size > 0) {
1125 if (outSize > ablob->out_size)
1126 outSize = ablob->out_size;
1127 if (outSize >= PIGGYSIZE)
1130 outData[outSize] = '\0';
1131 AFS_COPYOUT(outData, ablob->out, outSize, code);
1134 osi_FreeLargeSpace(outData);
1135 afs_PutFakeStat(&fakestate);
1136 return afs_CheckCode(code, &treq, 41);
1139 DECL_PIOCTL(PGetFID)
1141 AFS_STATCNT(PGetFID);
1144 memcpy(aout, (char *)&avc->fid, sizeof(struct VenusFid));
1145 *aoutSize = sizeof(struct VenusFid);
1149 DECL_PIOCTL(PSetAcl)
1151 register afs_int32 code;
1153 struct AFSOpaque acl;
1154 struct AFSVolSync tsync;
1155 struct AFSFetchStatus OutStatus;
1158 AFS_STATCNT(PSetAcl);
1161 if ((acl.AFSOpaque_len = strlen(ain) + 1) > 1000)
1164 acl.AFSOpaque_val = ain;
1166 tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1168 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREACL);
1171 RXAFS_StoreACL(tconn->id, (struct AFSFid *)&avc->fid.Fid,
1172 &acl, &OutStatus, &tsync);
1177 } while (afs_Analyze
1178 (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_STOREACL,
1179 SHARED_LOCK, NULL));
1181 /* now we've forgotten all of the access info */
1182 ObtainWriteLock(&afs_xcbhash, 455);
1184 afs_DequeueCallback(avc);
1185 avc->states &= ~(CStatd | CUnique);
1186 ReleaseWriteLock(&afs_xcbhash);
1187 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
1188 osi_dnlc_purgedp(avc);
1192 int afs_defaultAsynchrony = 0;
1194 DECL_PIOCTL(PStoreBehind)
1197 struct sbstruct *sbr;
1199 sbr = (struct sbstruct *)ain;
1200 if (sbr->sb_default != -1) {
1201 if (afs_osi_suser(*acred))
1202 afs_defaultAsynchrony = sbr->sb_default;
1207 if (avc && (sbr->sb_thisfile != -1)) {
1209 (avc, PRSFS_WRITE | PRSFS_ADMINISTER, areq, DONT_CHECK_MODE_BITS))
1210 avc->asynchrony = sbr->sb_thisfile;
1215 *aoutSize = sizeof(struct sbstruct);
1216 sbr = (struct sbstruct *)aout;
1217 sbr->sb_default = afs_defaultAsynchrony;
1219 sbr->sb_thisfile = avc->asynchrony;
1225 DECL_PIOCTL(PGCPAGs)
1227 if (!afs_osi_suser(*acred)) {
1230 afs_gcpags = AFS_GCPAGS_USERDISABLED;
1234 DECL_PIOCTL(PGetAcl)
1236 struct AFSOpaque acl;
1237 struct AFSVolSync tsync;
1238 struct AFSFetchStatus OutStatus;
1244 AFS_STATCNT(PGetAcl);
1247 Fid.Volume = avc->fid.Fid.Volume;
1248 Fid.Vnode = avc->fid.Fid.Vnode;
1249 Fid.Unique = avc->fid.Fid.Unique;
1250 if (avc->states & CForeign) {
1252 * For a dfs xlator acl we have a special hack so that the
1253 * xlator will distinguish which type of acl will return. So
1254 * we currently use the top 2-bytes (vals 0-4) to tell which
1255 * type of acl to bring back. Horrible hack but this will
1256 * cause the least number of changes to code size and interfaces.
1258 if (Fid.Vnode & 0xc0000000)
1260 Fid.Vnode |= (ainSize << 30);
1262 acl.AFSOpaque_val = aout;
1264 tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1267 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHACL);
1269 code = RXAFS_FetchACL(tconn->id, &Fid, &acl, &OutStatus, &tsync);
1274 } while (afs_Analyze
1275 (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_FETCHACL,
1276 SHARED_LOCK, NULL));
1279 *aoutSize = (acl.AFSOpaque_len == 0 ? 1 : acl.AFSOpaque_len);
1292 AFS_STATCNT(PBogus);
1296 DECL_PIOCTL(PGetFileCell)
1298 register struct cell *tcell;
1300 AFS_STATCNT(PGetFileCell);
1303 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
1306 strcpy(aout, tcell->cellName);
1307 afs_PutCell(tcell, READ_LOCK);
1308 *aoutSize = strlen(aout) + 1;
1312 DECL_PIOCTL(PGetWSCell)
1314 struct cell *tcell = NULL;
1316 AFS_STATCNT(PGetWSCell);
1317 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1318 return EIO; /* Inappropriate ioctl for device */
1320 tcell = afs_GetPrimaryCell(READ_LOCK);
1321 if (!tcell) /* no primary cell? */
1323 strcpy(aout, tcell->cellName);
1324 *aoutSize = strlen(aout) + 1;
1325 afs_PutCell(tcell, READ_LOCK);
1329 DECL_PIOCTL(PGetUserCell)
1331 register afs_int32 i;
1332 register struct unixuser *tu;
1333 register struct cell *tcell;
1335 AFS_STATCNT(PGetUserCell);
1336 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1337 return EIO; /* Inappropriate ioctl for device */
1339 /* return the cell name of the primary cell for this user */
1340 i = UHash(areq->uid);
1341 ObtainWriteLock(&afs_xuser, 224);
1342 for (tu = afs_users[i]; tu; tu = tu->next) {
1343 if (tu->uid == areq->uid && (tu->states & UPrimary)) {
1345 ReleaseWriteLock(&afs_xuser);
1350 tcell = afs_GetCell(tu->cell, READ_LOCK);
1351 afs_PutUser(tu, WRITE_LOCK);
1355 strcpy(aout, tcell->cellName);
1356 afs_PutCell(tcell, READ_LOCK);
1357 *aoutSize = strlen(aout) + 1; /* 1 for the null */
1360 ReleaseWriteLock(&afs_xuser);
1367 DECL_PIOCTL(PSetTokens)
1370 register struct unixuser *tu;
1371 struct ClearToken clear;
1372 register struct cell *tcell;
1375 struct vrequest treq;
1376 afs_int32 flag, set_parent_pag = 0;
1378 AFS_STATCNT(PSetTokens);
1379 if (!afs_resourceinit_flag) {
1382 memcpy((char *)&i, ain, sizeof(afs_int32));
1383 ain += sizeof(afs_int32);
1384 stp = ain; /* remember where the ticket is */
1385 if (i < 0 || i > MAXKTCTICKETLEN)
1386 return EINVAL; /* malloc may fail */
1388 ain += i; /* skip over ticket */
1389 memcpy((char *)&i, ain, sizeof(afs_int32));
1390 ain += sizeof(afs_int32);
1391 if (i != sizeof(struct ClearToken)) {
1394 memcpy((char *)&clear, ain, sizeof(struct ClearToken));
1395 if (clear.AuthHandle == -1)
1396 clear.AuthHandle = 999; /* more rxvab compat stuff */
1397 ain += sizeof(struct ClearToken);
1398 if (ainSize != 2 * sizeof(afs_int32) + stLen + sizeof(struct ClearToken)) {
1399 /* still stuff left? we've got primary flag and cell name. Set these */
1400 memcpy((char *)&flag, ain, sizeof(afs_int32)); /* primary id flag */
1401 ain += sizeof(afs_int32); /* skip id field */
1402 /* rest is cell name, look it up */
1403 /* some versions of gcc appear to need != 0 in order to get this right */
1404 if ((flag & 0x8000) != 0) { /* XXX Use Constant XXX */
1408 tcell = afs_GetCellByName(ain, READ_LOCK);
1412 /* default to primary cell, primary id */
1413 flag = 1; /* primary id */
1414 tcell = afs_GetPrimaryCell(READ_LOCK);
1419 afs_PutCell(tcell, READ_LOCK);
1420 if (set_parent_pag) {
1422 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1423 #if defined(AFS_DARWIN_ENV)
1424 struct proc *p = current_proc(); /* XXX */
1426 struct proc *p = curproc; /* XXX */
1428 uprintf("Process %d (%s) tried to change pags in PSetTokens\n",
1429 p->p_pid, p->p_comm);
1430 if (!setpag(p, acred, -1, &pag, 1)) {
1433 if (!setpag(u.u_procp, acred, -1, &pag, 1)) { /* XXX u.u_procp is a no-op XXX */
1435 if (!setpag(acred, -1, &pag, 1)) {
1438 afs_InitReq(&treq, *acred);
1442 /* now we just set the tokens */
1443 tu = afs_GetUser(areq->uid, i, WRITE_LOCK); /* i has the cell # */
1444 tu->vid = clear.ViceId;
1445 if (tu->stp != NULL) {
1446 afs_osi_Free(tu->stp, tu->stLen);
1448 tu->stp = (char *)afs_osi_Alloc(stLen);
1450 memcpy(tu->stp, stp, stLen);
1453 afs_stats_cmfullperf.authent.TicketUpdates++;
1454 afs_ComputePAGStats();
1455 #endif /* AFS_NOSTATS */
1456 tu->states |= UHasTokens;
1457 tu->states &= ~UTokensBad;
1458 afs_SetPrimary(tu, flag);
1459 tu->tokenTime = osi_Time();
1460 afs_ResetUserConns(tu);
1461 afs_PutUser(tu, WRITE_LOCK);
1476 DECL_PIOCTL(PGetVolumeStatus)
1479 char *offLineMsg = afs_osi_Alloc(256);
1480 char *motd = afs_osi_Alloc(256);
1481 register struct conn *tc;
1482 register afs_int32 code = 0;
1483 struct VolumeStatus volstat;
1485 char *Name, *OfflineMsg, *MOTD;
1488 AFS_STATCNT(PGetVolumeStatus);
1494 OfflineMsg = offLineMsg;
1497 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1499 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS);
1502 RXAFS_GetVolumeStatus(tc->id, avc->fid.Fid.Volume, &volstat,
1503 &Name, &OfflineMsg, &MOTD);
1508 } while (afs_Analyze
1509 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS,
1510 SHARED_LOCK, NULL));
1514 /* Copy all this junk into msg->im_data, keeping track of the lengths. */
1516 memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
1517 cp += sizeof(VolumeStatus);
1518 strcpy(cp, volName);
1519 cp += strlen(volName) + 1;
1520 strcpy(cp, offLineMsg);
1521 cp += strlen(offLineMsg) + 1;
1523 cp += strlen(motd) + 1;
1524 *aoutSize = (cp - aout);
1526 afs_osi_Free(offLineMsg, 256);
1527 afs_osi_Free(motd, 256);
1531 DECL_PIOCTL(PSetVolumeStatus)
1534 char *offLineMsg = afs_osi_Alloc(256);
1535 char *motd = afs_osi_Alloc(256);
1536 register struct conn *tc;
1537 register afs_int32 code = 0;
1538 struct AFSFetchVolumeStatus volstat;
1539 struct AFSStoreVolumeStatus storeStat;
1540 register struct volume *tvp;
1544 AFS_STATCNT(PSetVolumeStatus);
1548 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
1550 if (tvp->states & (VRO | VBackup)) {
1551 afs_PutVolume(tvp, READ_LOCK);
1554 afs_PutVolume(tvp, READ_LOCK);
1557 /* Copy the junk out, using cp as a roving pointer. */
1559 memcpy((char *)&volstat, cp, sizeof(AFSFetchVolumeStatus));
1560 cp += sizeof(AFSFetchVolumeStatus);
1561 if (strlen(cp) >= sizeof(volName))
1563 strcpy(volName, cp);
1564 cp += strlen(volName) + 1;
1565 if (strlen(cp) >= sizeof(offLineMsg))
1567 strcpy(offLineMsg, cp);
1568 cp += strlen(offLineMsg) + 1;
1569 if (strlen(cp) >= sizeof(motd))
1573 if (volstat.MinQuota != -1) {
1574 storeStat.MinQuota = volstat.MinQuota;
1575 storeStat.Mask |= AFS_SETMINQUOTA;
1577 if (volstat.MaxQuota != -1) {
1578 storeStat.MaxQuota = volstat.MaxQuota;
1579 storeStat.Mask |= AFS_SETMAXQUOTA;
1582 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1584 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS);
1587 RXAFS_SetVolumeStatus(tc->id, avc->fid.Fid.Volume, &storeStat,
1588 volName, offLineMsg, motd);
1593 } while (afs_Analyze
1594 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS,
1595 SHARED_LOCK, NULL));
1599 /* we are sending parms back to make compat. with prev system. should
1600 * change interface later to not ask for current status, just set new status */
1602 memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
1603 cp += sizeof(VolumeStatus);
1604 strcpy(cp, volName);
1605 cp += strlen(volName) + 1;
1606 strcpy(cp, offLineMsg);
1607 cp += strlen(offLineMsg) + 1;
1609 cp += strlen(motd) + 1;
1610 *aoutSize = cp - aout;
1612 afs_osi_Free(offLineMsg, 256);
1613 afs_osi_Free(motd, 256);
1619 AFS_STATCNT(PFlush);
1622 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
1623 afs_BozonLock(&avc->pvnLock, avc); /* Since afs_TryToSmush will do a pvn_vptrunc */
1625 ObtainWriteLock(&avc->lock, 225);
1626 ObtainWriteLock(&afs_xcbhash, 456);
1627 afs_DequeueCallback(avc);
1628 avc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
1629 ReleaseWriteLock(&afs_xcbhash);
1630 /* now find the disk cache entries */
1631 afs_TryToSmush(avc, *acred, 1);
1632 osi_dnlc_purgedp(avc);
1633 afs_symhint_inval(avc);
1634 if (avc->linkData && !(avc->states & CCore)) {
1635 afs_osi_Free(avc->linkData, strlen(avc->linkData) + 1);
1636 avc->linkData = NULL;
1638 ReleaseWriteLock(&avc->lock);
1639 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
1640 afs_BozonUnlock(&avc->pvnLock, avc);
1645 DECL_PIOCTL(PNewStatMount)
1647 register afs_int32 code;
1648 register struct vcache *tvc;
1649 register struct dcache *tdc;
1650 struct VenusFid tfid;
1652 struct sysname_info sysState;
1653 afs_size_t offset, len;
1655 AFS_STATCNT(PNewStatMount);
1658 code = afs_VerifyVCache(avc, areq);
1661 if (vType(avc) != VDIR) {
1664 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
1667 Check_AtSys(avc, ain, &sysState, areq);
1668 ObtainReadLock(&tdc->lock);
1670 code = afs_dir_Lookup(&tdc->f.inode, sysState.name, &tfid.Fid);
1671 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
1672 ReleaseReadLock(&tdc->lock);
1673 afs_PutDCache(tdc); /* we're done with the data */
1674 bufp = sysState.name;
1678 tfid.Cell = avc->fid.Cell;
1679 tfid.Fid.Volume = avc->fid.Fid.Volume;
1680 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
1681 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
1683 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
1689 if (tvc->mvstat != 1) {
1694 ObtainWriteLock(&tvc->lock, 226);
1695 code = afs_HandleLink(tvc, areq);
1697 if (tvc->linkData) {
1698 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
1701 /* we have the data */
1702 strcpy(aout, tvc->linkData);
1703 *aoutSize = strlen(tvc->linkData) + 1;
1708 ReleaseWriteLock(&tvc->lock);
1711 if (sysState.allocked)
1712 osi_FreeLargeSpace(bufp);
1716 DECL_PIOCTL(PGetTokens)
1718 register struct cell *tcell;
1719 register afs_int32 i;
1720 register struct unixuser *tu;
1725 AFS_STATCNT(PGetTokens);
1726 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1727 return EIO; /* Inappropriate ioctl for device */
1729 /* weird interface. If input parameter is present, it is an integer and
1730 * we're supposed to return the parm'th tokens for this unix uid.
1731 * If not present, we just return tokens for cell 1.
1732 * If counter out of bounds, return EDOM.
1733 * If no tokens for the particular cell, return ENOTCONN.
1734 * Also, if this mysterious parm is present, we return, along with the
1735 * tokens, the primary cell indicator (an afs_int32 0) and the cell name
1736 * at the end, in that order.
1738 if ((newStyle = (ainSize > 0))) {
1739 memcpy((char *)&iterator, ain, sizeof(afs_int32));
1741 i = UHash(areq->uid);
1742 ObtainReadLock(&afs_xuser);
1743 for (tu = afs_users[i]; tu; tu = tu->next) {
1745 if (tu->uid == areq->uid && (tu->states & UHasTokens)) {
1746 if (iterator-- == 0)
1747 break; /* are we done yet? */
1750 if (tu->uid == areq->uid && afs_IsPrimaryCellNum(tu->cell))
1756 * No need to hold a read lock on each user entry
1760 ReleaseReadLock(&afs_xuser);
1765 if (((tu->states & UHasTokens) == 0)
1766 || (tu->ct.EndTimestamp < osi_Time())) {
1767 tu->states |= (UTokensBad | UNeedsReset);
1768 afs_PutUser(tu, READ_LOCK);
1771 /* use iterator for temp */
1773 iterator = tu->stLen; /* for compat, we try to return 56 byte tix if they fit */
1775 iterator = 56; /* # of bytes we're returning */
1776 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1777 cp += sizeof(afs_int32);
1778 memcpy(cp, tu->stp, tu->stLen); /* copy out st */
1780 iterator = sizeof(struct ClearToken);
1781 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1782 cp += sizeof(afs_int32);
1783 memcpy(cp, (char *)&tu->ct, sizeof(struct ClearToken));
1784 cp += sizeof(struct ClearToken);
1786 /* put out primary id and cell name, too */
1787 iterator = (tu->states & UPrimary ? 1 : 0);
1788 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1789 cp += sizeof(afs_int32);
1790 tcell = afs_GetCell(tu->cell, READ_LOCK);
1792 strcpy(cp, tcell->cellName);
1793 cp += strlen(tcell->cellName) + 1;
1794 afs_PutCell(tcell, READ_LOCK);
1798 *aoutSize = cp - aout;
1799 afs_PutUser(tu, READ_LOCK);
1805 register afs_int32 i;
1806 register struct unixuser *tu;
1808 AFS_STATCNT(PUnlog);
1809 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1810 return EIO; /* Inappropriate ioctl for device */
1812 i = UHash(areq->uid);
1813 ObtainWriteLock(&afs_xuser, 227);
1814 for (tu = afs_users[i]; tu; tu = tu->next) {
1815 if (tu->uid == areq->uid) {
1817 tu->states &= ~UHasTokens;
1818 /* security is not having to say you're sorry */
1819 memset((char *)&tu->ct, 0, sizeof(struct ClearToken));
1821 ReleaseWriteLock(&afs_xuser);
1822 /* We have to drop the lock over the call to afs_ResetUserConns, since
1823 * it obtains the afs_xvcache lock. We could also keep the lock, and
1824 * modify ResetUserConns to take parm saying we obtained the lock
1825 * already, but that is overkill. By keeping the "tu" pointer
1826 * held over the released lock, we guarantee that we won't lose our
1827 * place, and that we'll pass over every user conn that existed when
1828 * we began this call.
1830 afs_ResetUserConns(tu);
1832 ObtainWriteLock(&afs_xuser, 228);
1834 /* set the expire times to 0, causes
1835 * afs_GCUserData to remove this entry
1837 tu->ct.EndTimestamp = 0;
1839 #endif /* UKERNEL */
1842 ReleaseWriteLock(&afs_xuser);
1846 DECL_PIOCTL(PMariner)
1848 afs_int32 newHostAddr;
1849 afs_int32 oldHostAddr;
1851 AFS_STATCNT(PMariner);
1853 memcpy((char *)&oldHostAddr, (char *)&afs_marinerHost,
1856 oldHostAddr = 0xffffffff; /* disabled */
1858 memcpy((char *)&newHostAddr, ain, sizeof(afs_int32));
1859 if (newHostAddr == 0xffffffff) {
1860 /* disable mariner operations */
1862 } else if (newHostAddr) {
1864 afs_marinerHost = newHostAddr;
1866 memcpy(aout, (char *)&oldHostAddr, sizeof(afs_int32));
1867 *aoutSize = sizeof(afs_int32);
1871 DECL_PIOCTL(PCheckServers)
1873 register char *cp = 0;
1875 register struct server *ts;
1876 afs_int32 temp, *lp = (afs_int32 *) ain, havecell = 0;
1878 struct chservinfo *pcheck;
1880 AFS_STATCNT(PCheckServers);
1882 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1883 return EIO; /* Inappropriate ioctl for device */
1885 if (*lp == 0x12345678) { /* For afs3.3 version */
1886 pcheck = (struct chservinfo *)ain;
1887 if (pcheck->tinterval >= 0) {
1889 memcpy(cp, (char *)&PROBE_INTERVAL, sizeof(afs_int32));
1890 *aoutSize = sizeof(afs_int32);
1891 if (pcheck->tinterval > 0) {
1892 if (!afs_osi_suser(*acred))
1894 PROBE_INTERVAL = pcheck->tinterval;
1900 temp = pcheck->tflags;
1901 cp = pcheck->tbuffer;
1902 } else { /* For pre afs3.3 versions */
1903 memcpy((char *)&temp, ain, sizeof(afs_int32));
1904 cp = ain + sizeof(afs_int32);
1905 if (ainSize > sizeof(afs_int32))
1910 * 1: fast check, don't contact servers.
1911 * 2: local cell only.
1914 /* have cell name, too */
1915 cellp = afs_GetCellByName(cp, READ_LOCK);
1920 if (!cellp && (temp & 2)) {
1921 /* use local cell */
1922 cellp = afs_GetPrimaryCell(READ_LOCK);
1924 if (!(temp & 1)) { /* if not fast, call server checker routine */
1925 afs_CheckServers(1, cellp); /* check down servers */
1926 afs_CheckServers(0, cellp); /* check up servers */
1928 /* now return the current down server list */
1930 ObtainReadLock(&afs_xserver);
1931 for (i = 0; i < NSERVERS; i++) {
1932 for (ts = afs_servers[i]; ts; ts = ts->next) {
1933 if (cellp && ts->cell != cellp)
1934 continue; /* cell spec'd and wrong */
1935 if ((ts->flags & SRVR_ISDOWN)
1936 && ts->addr->sa_portal != ts->cell->vlport) {
1937 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
1938 cp += sizeof(afs_int32);
1942 ReleaseReadLock(&afs_xserver);
1944 afs_PutCell(cellp, READ_LOCK);
1945 *aoutSize = cp - aout;
1949 DECL_PIOCTL(PCheckVolNames)
1951 AFS_STATCNT(PCheckVolNames);
1952 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1953 return EIO; /* Inappropriate ioctl for device */
1955 afs_CheckRootVolume();
1956 afs_CheckVolumeNames(AFS_VOLCHECK_FORCE | AFS_VOLCHECK_EXPIRED |
1957 AFS_VOLCHECK_BUSY | AFS_VOLCHECK_MTPTS);
1961 DECL_PIOCTL(PCheckAuth)
1966 struct unixuser *tu;
1969 AFS_STATCNT(PCheckAuth);
1970 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1971 return EIO; /* Inappropriate ioctl for device */
1974 tu = afs_GetUser(areq->uid, 1, READ_LOCK); /* check local cell authentication */
1978 /* we have a user */
1979 ObtainReadLock(&afs_xsrvAddr);
1980 ObtainReadLock(&afs_xconn);
1982 /* any tokens set? */
1983 if ((tu->states & UHasTokens) == 0)
1985 /* all connections in cell 1 working? */
1986 for (i = 0; i < NSERVERS; i++) {
1987 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
1988 for (tc = sa->conns; tc; tc = tc->next) {
1989 if (tc->user == tu && (tu->states & UTokensBad))
1994 ReleaseReadLock(&afs_xsrvAddr);
1995 ReleaseReadLock(&afs_xconn);
1996 afs_PutUser(tu, READ_LOCK);
1998 memcpy(aout, (char *)&retValue, sizeof(afs_int32));
1999 *aoutSize = sizeof(afs_int32);
2004 Prefetch(char *apath, struct afs_ioctl *adata, int afollow,
2005 struct AFS_UCRED *acred)
2008 register afs_int32 code;
2009 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2015 AFS_STATCNT(Prefetch);
2018 tp = osi_AllocLargeSpace(1024);
2019 AFS_COPYINSTR(apath, tp, 1024, &bufferSize, code);
2021 osi_FreeLargeSpace(tp);
2024 if (afs_BBusy()) { /* do this as late as possible */
2025 osi_FreeLargeSpace(tp);
2026 return EWOULDBLOCK; /* pretty close */
2028 afs_BQueue(BOP_PATH, (struct vcache *)0, 0, 0, acred, (afs_size_t) 0,
2029 (afs_size_t) 0, tp);
2033 DECL_PIOCTL(PFindVolume)
2035 register struct volume *tvp;
2036 register struct server *ts;
2037 register afs_int32 i;
2040 AFS_STATCNT(PFindVolume);
2043 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
2046 for (i = 0; i < MAXHOSTS; i++) {
2047 ts = tvp->serverHost[i];
2050 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
2051 cp += sizeof(afs_int32);
2054 /* still room for terminating NULL, add it on */
2055 ainSize = 0; /* reuse vbl */
2056 memcpy(cp, (char *)&ainSize, sizeof(afs_int32));
2057 cp += sizeof(afs_int32);
2059 *aoutSize = cp - aout;
2060 afs_PutVolume(tvp, READ_LOCK);
2066 DECL_PIOCTL(PViceAccess)
2068 register afs_int32 code;
2071 AFS_STATCNT(PViceAccess);
2074 code = afs_VerifyVCache(avc, areq);
2077 memcpy((char *)&temp, ain, sizeof(afs_int32));
2078 code = afs_AccessOK(avc, temp, areq, CHECK_MODE_BITS);
2085 DECL_PIOCTL(PSetCacheSize)
2090 AFS_STATCNT(PSetCacheSize);
2091 if (!afs_osi_suser(*acred))
2093 /* too many things are setup initially in mem cache version */
2094 if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
2096 memcpy((char *)&newValue, ain, sizeof(afs_int32));
2098 afs_cacheBlocks = afs_stats_cmperf.cacheBlocksOrig;
2100 if (newValue < afs_min_cache)
2101 afs_cacheBlocks = afs_min_cache;
2103 afs_cacheBlocks = newValue;
2105 afs_stats_cmperf.cacheBlocksTotal = afs_cacheBlocks;
2106 afs_ComputeCacheParms(); /* recompute basic cache parameters */
2107 afs_MaybeWakeupTruncateDaemon();
2108 while (waitcnt++ < 100 && afs_cacheBlocks < afs_blocksUsed) {
2109 afs_osi_Wait(1000, 0, 0);
2110 afs_MaybeWakeupTruncateDaemon();
2115 #define MAXGCSTATS 16
2116 DECL_PIOCTL(PGetCacheSize)
2118 afs_int32 results[MAXGCSTATS];
2120 AFS_STATCNT(PGetCacheSize);
2121 memset((char *)results, 0, sizeof(results));
2122 results[0] = afs_cacheBlocks;
2123 results[1] = afs_blocksUsed;
2124 memcpy(aout, (char *)results, sizeof(results));
2125 *aoutSize = sizeof(results);
2129 DECL_PIOCTL(PRemoveCallBack)
2131 register struct conn *tc;
2132 register afs_int32 code = 0;
2133 struct AFSCallBack CallBacks_Array[1];
2134 struct AFSCBFids theFids;
2135 struct AFSCBs theCBs;
2138 AFS_STATCNT(PRemoveCallBack);
2141 if (avc->states & CRO)
2142 return 0; /* read-only-ness can't change */
2143 ObtainWriteLock(&avc->lock, 229);
2144 theFids.AFSCBFids_len = 1;
2145 theCBs.AFSCBs_len = 1;
2146 theFids.AFSCBFids_val = (struct AFSFid *)&avc->fid.Fid;
2147 theCBs.AFSCBs_val = CallBacks_Array;
2148 CallBacks_Array[0].CallBackType = CB_DROPPED;
2149 if (avc->callback) {
2151 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2153 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
2155 code = RXAFS_GiveUpCallBacks(tc->id, &theFids, &theCBs);
2159 /* don't set code on failure since we wouldn't use it */
2160 } while (afs_Analyze
2161 (tc, code, &avc->fid, areq,
2162 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK, NULL));
2164 ObtainWriteLock(&afs_xcbhash, 457);
2165 afs_DequeueCallback(avc);
2167 avc->states &= ~(CStatd | CUnique);
2168 ReleaseWriteLock(&afs_xcbhash);
2169 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
2170 osi_dnlc_purgedp(avc);
2172 ReleaseWriteLock(&avc->lock);
2176 DECL_PIOCTL(PNewCell)
2178 /* create a new cell */
2179 afs_int32 cellHosts[MAXCELLHOSTS], *lp, magic = 0;
2180 char *newcell = 0, *linkedcell = 0, *tp = ain;
2181 register afs_int32 code, linkedstate = 0, ls;
2182 u_short fsport = 0, vlport = 0;
2185 AFS_STATCNT(PNewCell);
2186 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2187 return EIO; /* Inappropriate ioctl for device */
2189 if (!afs_osi_suser(*acred))
2192 memcpy((char *)&magic, tp, sizeof(afs_int32));
2193 tp += sizeof(afs_int32);
2194 if (magic != 0x12345678)
2197 /* A 3.4 fs newcell command will pass an array of MAXCELLHOSTS
2198 * server addresses while the 3.5 fs newcell command passes
2199 * MAXHOSTS. To figure out which is which, check if the cellname
2202 newcell = tp + (MAXCELLHOSTS + 3) * sizeof(afs_int32);
2203 scount = ((newcell[0] != '\0') ? MAXCELLHOSTS : MAXHOSTS);
2205 /* MAXCELLHOSTS (=8) is less than MAXHOSTS (=13) */
2206 memcpy((char *)cellHosts, tp, MAXCELLHOSTS * sizeof(afs_int32));
2207 tp += (scount * sizeof(afs_int32));
2209 lp = (afs_int32 *) tp;
2213 fsport = 0; /* Privileged ports not allowed */
2215 vlport = 0; /* Privileged ports not allowed */
2216 tp += (3 * sizeof(afs_int32));
2218 if ((ls = *lp) & 1) {
2219 linkedcell = tp + strlen(newcell) + 1;
2220 linkedstate |= CLinkedCell;
2223 linkedstate |= CNoSUID; /* setuid is disabled by default for fs newcell */
2225 afs_NewCell(newcell, cellHosts, linkedstate, linkedcell, fsport,
2230 DECL_PIOCTL(PNewAlias)
2232 /* create a new cell alias */
2234 register afs_int32 code;
2235 char *realName, *aliasName;
2237 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2238 return EIO; /* Inappropriate ioctl for device */
2240 if (!afs_osi_suser(*acred))
2244 tp += strlen(aliasName) + 1;
2247 code = afs_NewCellAlias(aliasName, realName);
2252 DECL_PIOCTL(PListCells)
2254 afs_int32 whichCell;
2255 register struct cell *tcell = 0;
2256 register afs_int32 i;
2257 register char *cp, *tp = ain;
2259 AFS_STATCNT(PListCells);
2260 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2261 return EIO; /* Inappropriate ioctl for device */
2263 memcpy((char *)&whichCell, tp, sizeof(afs_int32));
2264 tp += sizeof(afs_int32);
2265 tcell = afs_GetCellByIndex(whichCell, READ_LOCK);
2268 memset(cp, 0, MAXCELLHOSTS * sizeof(afs_int32));
2269 for (i = 0; i < MAXCELLHOSTS; i++) {
2270 if (tcell->cellHosts[i] == 0)
2272 memcpy(cp, (char *)&tcell->cellHosts[i]->addr->sa_ip,
2274 cp += sizeof(afs_int32);
2276 cp = aout + MAXCELLHOSTS * sizeof(afs_int32);
2277 strcpy(cp, tcell->cellName);
2278 cp += strlen(tcell->cellName) + 1;
2279 *aoutSize = cp - aout;
2280 afs_PutCell(tcell, READ_LOCK);
2288 DECL_PIOCTL(PListAliases)
2290 afs_int32 whichAlias;
2291 register struct cell_alias *tcalias = 0;
2292 register char *cp, *tp = ain;
2294 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2295 return EIO; /* Inappropriate ioctl for device */
2296 if (ainSize < sizeof(afs_int32))
2299 memcpy((char *)&whichAlias, tp, sizeof(afs_int32));
2300 tp += sizeof(afs_int32);
2302 tcalias = afs_GetCellAlias(whichAlias);
2305 strcpy(cp, tcalias->alias);
2306 cp += strlen(tcalias->alias) + 1;
2307 strcpy(cp, tcalias->cell);
2308 cp += strlen(tcalias->cell) + 1;
2309 *aoutSize = cp - aout;
2310 afs_PutCellAlias(tcalias);
2318 DECL_PIOCTL(PRemoveMount)
2320 register afs_int32 code;
2322 struct sysname_info sysState;
2323 afs_size_t offset, len;
2324 register struct conn *tc;
2325 register struct dcache *tdc;
2326 register struct vcache *tvc;
2327 struct AFSFetchStatus OutDirStatus;
2328 struct VenusFid tfid;
2329 struct AFSVolSync tsync;
2333 /* "ain" is the name of the file in this dir to remove */
2335 AFS_STATCNT(PRemoveMount);
2338 code = afs_VerifyVCache(avc, areq);
2341 if (vType(avc) != VDIR)
2344 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1); /* test for error below */
2347 Check_AtSys(avc, ain, &sysState, areq);
2348 ObtainReadLock(&tdc->lock);
2350 code = afs_dir_Lookup(&tdc->f.inode, sysState.name, &tfid.Fid);
2351 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
2352 ReleaseReadLock(&tdc->lock);
2353 bufp = sysState.name;
2358 tfid.Cell = avc->fid.Cell;
2359 tfid.Fid.Volume = avc->fid.Fid.Volume;
2360 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
2361 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
2363 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
2370 if (tvc->mvstat != 1) {
2376 ObtainWriteLock(&tvc->lock, 230);
2377 code = afs_HandleLink(tvc, areq);
2379 if (tvc->linkData) {
2380 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
2385 ReleaseWriteLock(&tvc->lock);
2386 osi_dnlc_purgedp(tvc);
2392 ObtainWriteLock(&avc->lock, 231);
2393 osi_dnlc_remove(avc, bufp, tvc);
2395 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2397 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE);
2400 RXAFS_RemoveFile(tc->id, (struct AFSFid *)&avc->fid.Fid, bufp,
2401 &OutDirStatus, &tsync);
2406 } while (afs_Analyze
2407 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_REMOVEFILE,
2408 SHARED_LOCK, NULL));
2413 ReleaseWriteLock(&avc->lock);
2417 /* we have the thing in the cache */
2418 ObtainWriteLock(&tdc->lock, 661);
2419 if (afs_LocalHero(avc, tdc, &OutDirStatus, 1)) {
2420 /* we can do it locally */
2421 code = afs_dir_Delete(&tdc->f.inode, bufp);
2423 ZapDCE(tdc); /* surprise error -- invalid value */
2424 DZap(&tdc->f.inode);
2427 ReleaseWriteLock(&tdc->lock);
2428 afs_PutDCache(tdc); /* drop ref count */
2430 avc->states &= ~CUnique; /* For the dfs xlator */
2431 ReleaseWriteLock(&avc->lock);
2434 if (sysState.allocked)
2435 osi_FreeLargeSpace(bufp);
2439 DECL_PIOCTL(PVenusLogging)
2441 return EINVAL; /* OBSOLETE */
2444 DECL_PIOCTL(PGetCellStatus)
2446 register struct cell *tcell;
2449 AFS_STATCNT(PGetCellStatus);
2450 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2451 return EIO; /* Inappropriate ioctl for device */
2453 tcell = afs_GetCellByName(ain, READ_LOCK);
2456 temp = tcell->states;
2457 afs_PutCell(tcell, READ_LOCK);
2458 memcpy(aout, (char *)&temp, sizeof(afs_int32));
2459 *aoutSize = sizeof(afs_int32);
2463 DECL_PIOCTL(PSetCellStatus)
2465 register struct cell *tcell;
2468 if (!afs_osi_suser(*acred))
2470 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2471 return EIO; /* Inappropriate ioctl for device */
2473 tcell = afs_GetCellByName(ain + 2 * sizeof(afs_int32), WRITE_LOCK);
2476 memcpy((char *)&temp, ain, sizeof(afs_int32));
2478 tcell->states |= CNoSUID;
2480 tcell->states &= ~CNoSUID;
2481 afs_PutCell(tcell, WRITE_LOCK);
2485 DECL_PIOCTL(PFlushVolumeData)
2487 register afs_int32 i;
2488 register struct dcache *tdc;
2489 register struct vcache *tvc;
2490 register struct volume *tv;
2491 afs_int32 cell, volume;
2493 AFS_STATCNT(PFlushVolumeData);
2496 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2497 return EIO; /* Inappropriate ioctl for device */
2499 volume = avc->fid.Fid.Volume; /* who to zap */
2500 cell = avc->fid.Cell;
2503 * Clear stat'd flag from all vnodes from this volume; this will invalidate all
2504 * the vcaches associated with the volume.
2506 ObtainReadLock(&afs_xvcache);
2507 for (i = 0; i < VCSIZE; i++) {
2508 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2509 if (tvc->fid.Fid.Volume == volume && tvc->fid.Cell == cell) {
2510 #if defined(AFS_SGI_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
2511 VN_HOLD(AFSTOV(tvc));
2513 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2519 ReleaseReadLock(&afs_xvcache);
2520 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
2521 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
2523 ObtainWriteLock(&tvc->lock, 232);
2525 ObtainWriteLock(&afs_xcbhash, 458);
2526 afs_DequeueCallback(tvc);
2527 tvc->states &= ~(CStatd | CDirty);
2528 ReleaseWriteLock(&afs_xcbhash);
2529 if (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
2530 osi_dnlc_purgedp(tvc);
2531 afs_TryToSmush(tvc, *acred, 1);
2532 ReleaseWriteLock(&tvc->lock);
2533 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
2534 afs_BozonUnlock(&tvc->pvnLock, tvc);
2536 ObtainReadLock(&afs_xvcache);
2537 /* our tvc ptr is still good until now */
2542 ReleaseReadLock(&afs_xvcache);
2545 MObtainWriteLock(&afs_xdcache, 328); /* needed if you're going to flush any stuff */
2546 for (i = 0; i < afs_cacheFiles; i++) {
2547 if (!(afs_indexFlags[i] & IFEverUsed))
2548 continue; /* never had any data */
2549 tdc = afs_GetDSlot(i, NULL);
2550 if (tdc->refCount <= 1) { /* too high, in use by running sys call */
2551 ReleaseReadLock(&tdc->tlock);
2552 if (tdc->f.fid.Fid.Volume == volume && tdc->f.fid.Cell == cell) {
2553 if (!(afs_indexFlags[i] & IFDataMod)) {
2554 /* if the file is modified, but has a ref cnt of only 1, then
2555 * someone probably has the file open and is writing into it.
2556 * Better to skip flushing such a file, it will be brought back
2557 * immediately on the next write anyway.
2559 * If we *must* flush, then this code has to be rearranged to call
2560 * afs_storeAllSegments() first */
2561 afs_FlushDCache(tdc);
2565 ReleaseReadLock(&tdc->tlock);
2567 afs_PutDCache(tdc); /* bumped by getdslot */
2569 MReleaseWriteLock(&afs_xdcache);
2571 ObtainReadLock(&afs_xvolume);
2572 for (i = 0; i < NVOLS; i++) {
2573 for (tv = afs_volumes[i]; tv; tv = tv->next) {
2574 if (tv->volume == volume) {
2575 afs_ResetVolumeInfo(tv);
2580 ReleaseReadLock(&afs_xvolume);
2582 /* probably, a user is doing this, probably, because things are screwed up.
2583 * maybe it's the dnlc's fault? */
2590 DECL_PIOCTL(PGetVnodeXStatus)
2592 register afs_int32 code;
2593 struct vcxstat stat;
2596 /* AFS_STATCNT(PGetVnodeXStatus); */
2599 code = afs_VerifyVCache(avc, areq);
2602 if (vType(avc) == VDIR)
2603 mode = PRSFS_LOOKUP;
2606 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
2608 stat.fid = avc->fid;
2609 hset32(stat.DataVersion, hgetlo(avc->m.DataVersion));
2610 stat.lock = avc->lock;
2611 stat.parentVnode = avc->parentVnode;
2612 stat.parentUnique = avc->parentUnique;
2613 hset(stat.flushDV, avc->flushDV);
2614 hset(stat.mapDV, avc->mapDV);
2615 stat.truncPos = avc->truncPos;
2616 { /* just grab the first two - won't break anything... */
2617 struct axscache *ac;
2619 for (i = 0, ac = avc->Access; ac && i < CPSIZE; i++, ac = ac->next) {
2620 stat.randomUid[i] = ac->uid;
2621 stat.randomAccess[i] = ac->axess;
2624 stat.callback = afs_data_pointer_to_int32(avc->callback);
2625 stat.cbExpires = avc->cbExpires;
2626 stat.anyAccess = avc->anyAccess;
2627 stat.opens = avc->opens;
2628 stat.execsOrWriters = avc->execsOrWriters;
2629 stat.flockCount = avc->flockCount;
2630 stat.mvstat = avc->mvstat;
2631 stat.states = avc->states;
2632 memcpy(aout, (char *)&stat, sizeof(struct vcxstat));
2633 *aoutSize = sizeof(struct vcxstat);
2638 /* We require root for local sysname changes, but not for remote */
2639 /* (since we don't really believe remote uids anyway) */
2640 /* outname[] shouldn't really be needed- this is left as an excercise */
2641 /* for the reader. */
2642 DECL_PIOCTL(PSetSysName)
2644 char *cp, *cp2, inname[MAXSYSNAME], outname[MAXSYSNAME];
2645 int setsysname, foundname = 0;
2646 register struct afs_exporter *exporter;
2647 register struct unixuser *au;
2648 register afs_int32 pag, error;
2649 int t, count, num = 0;
2650 char **sysnamelist[MAXSYSNAME];
2652 AFS_STATCNT(PSetSysName);
2653 if (!afs_globalVFS) {
2654 /* Afsd is NOT running; disable it */
2655 #if defined(KERNEL_HAVE_UERROR)
2656 return (setuerror(EINVAL), EINVAL);
2661 memset(inname, 0, MAXSYSNAME);
2662 memcpy((char *)&setsysname, ain, sizeof(afs_int32));
2663 ain += sizeof(afs_int32);
2667 if (setsysname < 0 || setsysname > MAXNUMSYSNAMES)
2670 for (cp = ain, count = 0; count < setsysname; count++) {
2671 /* won't go past end of ain since maxsysname*num < ain length */
2673 if (t >= MAXSYSNAME || t <= 0)
2675 /* check for names that can shoot us in the foot */
2676 if (*cp == '.' && (cp[1] == 0 || (cp[1] == '.' && cp[2] == 0)))
2682 /* inname gets first entry in case we're being a translator */
2684 memcpy(inname, ain, t + 1); /* include terminating null */
2688 if ((*acred)->cr_gid == RMTUSER_REQ) { /* Handles all exporters */
2689 pag = PagInCred(*acred);
2691 return EINVAL; /* Better than panicing */
2693 if (!(au = afs_FindUser(pag, -1, READ_LOCK))) {
2694 return EINVAL; /* Better than panicing */
2696 if (!(exporter = au->exporter)) {
2697 afs_PutUser(au, READ_LOCK);
2698 return EINVAL; /* Better than panicing */
2700 error = EXP_SYSNAME(exporter, (setsysname ? cp2 : NULL), sysnamelist,
2703 if (error == ENODEV)
2704 foundname = 0; /* sysname not set yet! */
2706 afs_PutUser(au, READ_LOCK);
2711 strcpy(outname, (*sysnamelist)[0]);
2713 afs_PutUser(au, READ_LOCK);
2715 /* Not xlating, so local case */
2717 osi_Panic("PSetSysName: !afs_sysname\n");
2718 if (!setsysname) { /* user just wants the info */
2719 strcpy(outname, afs_sysname);
2720 foundname = afs_sysnamecount;
2721 *sysnamelist = afs_sysnamelist;
2722 } else { /* Local guy; only root can change sysname */
2723 if (!afs_osi_suser(*acred))
2726 /* clear @sys entries from the dnlc, once afs_lookup can
2727 * do lookups of @sys entries and thinks it can trust them */
2728 /* privs ok, store the entry, ... */
2729 strcpy(afs_sysname, inname);
2730 if (setsysname > 1) { /* ... or list */
2732 for (count = 1; count < setsysname; ++count) {
2733 if (!afs_sysnamelist[count])
2735 ("PSetSysName: no afs_sysnamelist entry to write\n");
2737 memcpy(afs_sysnamelist[count], cp, t + 1); /* include null */
2741 afs_sysnamecount = setsysname;
2745 cp = aout; /* not changing so report back the count and ... */
2746 memcpy(cp, (char *)&foundname, sizeof(afs_int32));
2747 cp += sizeof(afs_int32);
2749 strcpy(cp, outname); /* ... the entry, ... */
2750 cp += strlen(outname) + 1;
2751 for (count = 1; count < foundname; ++count) { /* ... or list. */
2752 if (!(*sysnamelist)[count])
2754 ("PSetSysName: no afs_sysnamelist entry to read\n");
2755 t = strlen((*sysnamelist)[count]);
2756 if (t >= MAXSYSNAME)
2757 osi_Panic("PSetSysName: sysname entry garbled\n");
2758 strcpy(cp, (*sysnamelist)[count]);
2762 *aoutSize = cp - aout;
2767 /* sequential search through the list of touched cells is not a good
2768 * long-term solution here. For small n, though, it should be just
2769 * fine. Should consider special-casing the local cell for large n.
2770 * Likewise for PSetSPrefs.
2772 * s - number of ids in array l[] -- NOT index of last id
2773 * l - array of cell ids which have volumes that need to be sorted
2774 * vlonly - sort vl servers or file servers?
2777 ReSortCells_cb(struct cell *cell, void *arg)
2779 afs_int32 *p = (afs_int32 *) arg;
2780 afs_int32 *l = p + 1;
2783 for (i = 0; i < s; i++) {
2784 if (l[i] == cell->cellNum) {
2785 ObtainWriteLock(&cell->lock, 690);
2786 afs_SortServers(cell->cellHosts, MAXCELLHOSTS);
2787 ReleaseWriteLock(&cell->lock);
2795 ReSortCells(int s, afs_int32 * l, int vlonly)
2803 p = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * (s + 1));
2805 memcpy(p + 1, l, s * sizeof(afs_int32));
2806 afs_TraverseCells(&ReSortCells_cb, p);
2807 afs_osi_Free(p, sizeof(afs_int32) * (s + 1));
2811 ObtainReadLock(&afs_xvolume);
2812 for (i = 0; i < NVOLS; i++) {
2813 for (j = afs_volumes[i]; j; j = j->next) {
2814 for (k = 0; k < s; k++)
2815 if (j->cell == l[k]) {
2816 ObtainWriteLock(&j->lock, 233);
2817 afs_SortServers(j->serverHost, MAXHOSTS);
2818 ReleaseWriteLock(&j->lock);
2823 ReleaseReadLock(&afs_xvolume);
2827 static int debugsetsp = 0;
2829 afs_setsprefs(sp, num, vlonly)
2832 unsigned int vlonly;
2835 int i, j, k, matches, touchedSize;
2836 struct server *srvr = NULL;
2837 afs_int32 touched[34];
2841 for (k = 0; k < num; sp++, k++) {
2843 printf("sp host=%x, rank=%d\n", sp->host.s_addr, sp->rank);
2846 ObtainReadLock(&afs_xserver);
2848 i = SHash(sp->host.s_addr);
2849 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2850 if (sa->sa_ip == sp->host.s_addr) {
2852 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
2853 || (sa->sa_portal == AFS_FSPORT);
2854 if ((!vlonly && isfs) || (vlonly && !isfs)) {
2861 if (sa && matches) { /* found one! */
2863 printf("sa ip=%x, ip_rank=%d\n", sa->sa_ip, sa->sa_iprank);
2865 sa->sa_iprank = sp->rank + afs_randomMod15();
2866 afs_SortOneServer(sa->server);
2869 /* if we don't know yet what cell it's in, this is moot */
2870 for (j = touchedSize - 1;
2871 j >= 0 && touched[j] != srvr->cell->cellNum; j--)
2872 /* is it in our list of touched cells ? */ ;
2873 if (j < 0) { /* no, it's not */
2874 touched[touchedSize++] = srvr->cell->cellNum;
2875 if (touchedSize >= 32) { /* watch for ovrflow */
2876 ReleaseReadLock(&afs_xserver);
2877 ReSortCells(touchedSize, touched, vlonly);
2879 ObtainReadLock(&afs_xserver);
2885 ReleaseReadLock(&afs_xserver);
2886 /* if we didn't find one, start to create one. */
2887 /* Note that it doesn't have a cell yet... */
2889 afs_uint32 temp = sp->host.s_addr;
2891 afs_GetServer(&temp, 1, 0, (vlonly ? AFS_VLPORT : AFS_FSPORT),
2892 WRITE_LOCK, (afsUUID *) 0, 0);
2893 srvr->addr->sa_iprank = sp->rank + afs_randomMod15();
2894 afs_PutServer(srvr, WRITE_LOCK);
2896 } /* for all cited preferences */
2898 ReSortCells(touchedSize, touched, vlonly);
2902 /* Note that this may only be performed by the local root user.
2904 DECL_PIOCTL(PSetSPrefs)
2906 struct setspref *ssp;
2907 AFS_STATCNT(PSetSPrefs);
2909 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2910 return EIO; /* Inappropriate ioctl for device */
2912 if (!afs_osi_suser(*acred))
2915 if (ainSize < sizeof(struct setspref))
2918 ssp = (struct setspref *)ain;
2919 if (ainSize < sizeof(struct spref) * ssp->num_servers)
2922 afs_setsprefs(&(ssp->servers[0]), ssp->num_servers,
2923 (ssp->flags & DBservers));
2927 DECL_PIOCTL(PSetSPrefs33)
2930 AFS_STATCNT(PSetSPrefs);
2931 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2932 return EIO; /* Inappropriate ioctl for device */
2935 if (!afs_osi_suser(*acred))
2938 sp = (struct spref *)ain;
2939 afs_setsprefs(sp, ainSize / (sizeof(struct spref)), 0 /*!vlonly */ );
2943 /* some notes on the following code...
2944 * in the hash table of server structs, all servers with the same IP address
2945 * will be on the same overflow chain.
2946 * This could be sped slightly in some circumstances by having it cache the
2947 * immediately previous slot in the hash table and some supporting information
2948 * Only reports file servers now.
2950 DECL_PIOCTL(PGetSPrefs)
2952 struct sprefrequest *spin; /* input */
2953 struct sprefinfo *spout; /* output */
2954 struct spref *srvout; /* one output component */
2955 int i, j; /* counters for hash table traversal */
2956 struct server *srvr; /* one of CM's server structs */
2958 int vlonly; /* just return vlservers ? */
2961 AFS_STATCNT(PGetSPrefs);
2962 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2963 return EIO; /* Inappropriate ioctl for device */
2966 if (ainSize < sizeof(struct sprefrequest_33)) {
2969 spin = ((struct sprefrequest *)ain);
2972 if (ainSize > sizeof(struct sprefrequest_33)) {
2973 vlonly = (spin->flags & DBservers);
2977 /* struct sprefinfo includes 1 server struct... that size gets added
2978 * in during the loop that follows.
2980 *aoutSize = sizeof(struct sprefinfo) - sizeof(struct spref);
2981 spout = (struct sprefinfo *)aout;
2982 spout->next_offset = spin->offset;
2983 spout->num_servers = 0;
2984 srvout = spout->servers;
2986 ObtainReadLock(&afs_xserver);
2987 for (i = 0, j = 0; j < NSERVERS; j++) { /* sift through hash table */
2988 for (sa = afs_srvAddrs[j]; sa; sa = sa->next_bkt, i++) {
2989 if (spin->offset > (unsigned short)i) {
2990 continue; /* catch up to where we left off */
2992 spout->next_offset++;
2995 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
2996 || (sa->sa_portal == AFS_FSPORT);
2998 if ((vlonly && isfs) || (!vlonly && !isfs)) {
2999 /* only report ranks for vl servers */
3003 srvout->host.s_addr = sa->sa_ip;
3004 srvout->rank = sa->sa_iprank;
3005 *aoutSize += sizeof(struct spref);
3006 spout->num_servers++;
3009 if (*aoutSize > (PIGGYSIZE - sizeof(struct spref))) {
3010 ReleaseReadLock(&afs_xserver); /* no more room! */
3015 ReleaseReadLock(&afs_xserver);
3017 spout->next_offset = 0; /* start over from the beginning next time */
3021 /* Enable/Disable the specified exporter. Must be root to disable an exporter */
3022 int afs_NFSRootOnly = 1;
3023 DECL_PIOCTL(PExportAfs)
3025 afs_int32 export, newint =
3026 0, type, changestate, handleValue, convmode, pwsync, smounts;
3027 register struct afs_exporter *exporter;
3029 AFS_STATCNT(PExportAfs);
3030 memcpy((char *)&handleValue, ain, sizeof(afs_int32));
3031 type = handleValue >> 24;
3036 exporter = exporter_find(type);
3038 export = handleValue & 3;
3039 changestate = handleValue & 0xff;
3040 smounts = (handleValue >> 2) & 3;
3041 pwsync = (handleValue >> 4) & 3;
3042 convmode = (handleValue >> 6) & 3;
3044 changestate = (handleValue >> 16) & 0x1;
3045 convmode = (handleValue >> 16) & 0x2;
3046 pwsync = (handleValue >> 16) & 0x4;
3047 smounts = (handleValue >> 16) & 0x8;
3048 export = handleValue & 0xff;
3051 /* Failed finding desired exporter; */
3055 handleValue = exporter->exp_states;
3056 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3057 *aoutSize = sizeof(afs_int32);
3059 if (!afs_osi_suser(*acred))
3060 return EACCES; /* Only superuser can do this */
3064 exporter->exp_states |= EXP_EXPORTED;
3066 exporter->exp_states &= ~EXP_EXPORTED;
3070 exporter->exp_states |= EXP_UNIXMODE;
3072 exporter->exp_states &= ~EXP_UNIXMODE;
3076 exporter->exp_states |= EXP_PWSYNC;
3078 exporter->exp_states &= ~EXP_PWSYNC;
3082 afs_NFSRootOnly = 0;
3083 exporter->exp_states |= EXP_SUBMOUNTS;
3085 afs_NFSRootOnly = 1;
3086 exporter->exp_states &= ~EXP_SUBMOUNTS;
3089 handleValue = exporter->exp_states;
3090 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3091 *aoutSize = sizeof(afs_int32);
3094 exporter->exp_states |= EXP_EXPORTED;
3096 exporter->exp_states &= ~EXP_EXPORTED;
3098 exporter->exp_states |= EXP_UNIXMODE;
3100 exporter->exp_states &= ~EXP_UNIXMODE;
3102 exporter->exp_states |= EXP_PWSYNC;
3104 exporter->exp_states &= ~EXP_PWSYNC;
3106 afs_NFSRootOnly = 0;
3107 exporter->exp_states |= EXP_SUBMOUNTS;
3109 afs_NFSRootOnly = 1;
3110 exporter->exp_states &= ~EXP_SUBMOUNTS;
3120 struct gaginfo *gagflags;
3122 if (!afs_osi_suser(*acred))
3125 gagflags = (struct gaginfo *)ain;
3126 afs_showflags = gagflags->showflags;
3132 DECL_PIOCTL(PTwiddleRx)
3134 struct rxparams *rxp;
3136 if (!afs_osi_suser(*acred))
3139 rxp = (struct rxparams *)ain;
3141 if (rxp->rx_initReceiveWindow)
3142 rx_initReceiveWindow = rxp->rx_initReceiveWindow;
3143 if (rxp->rx_maxReceiveWindow)
3144 rx_maxReceiveWindow = rxp->rx_maxReceiveWindow;
3145 if (rxp->rx_initSendWindow)
3146 rx_initSendWindow = rxp->rx_initSendWindow;
3147 if (rxp->rx_maxSendWindow)
3148 rx_maxSendWindow = rxp->rx_maxSendWindow;
3149 if (rxp->rxi_nSendFrags)
3150 rxi_nSendFrags = rxp->rxi_nSendFrags;
3151 if (rxp->rxi_nRecvFrags)
3152 rxi_nRecvFrags = rxp->rxi_nRecvFrags;
3153 if (rxp->rxi_OrphanFragSize)
3154 rxi_OrphanFragSize = rxp->rxi_OrphanFragSize;
3155 if (rxp->rx_maxReceiveSize) {
3156 rx_maxReceiveSize = rxp->rx_maxReceiveSize;
3157 rx_maxReceiveSizeUser = rxp->rx_maxReceiveSize;
3159 if (rxp->rx_MyMaxSendSize)
3160 rx_MyMaxSendSize = rxp->rx_MyMaxSendSize;
3165 DECL_PIOCTL(PGetInitParams)
3167 if (sizeof(struct cm_initparams) > PIGGYSIZE)
3170 memcpy(aout, (char *)&cm_initParams, sizeof(struct cm_initparams));
3171 *aoutSize = sizeof(struct cm_initparams);
3175 #ifdef AFS_SGI65_ENV
3176 /* They took crget() from us, so fake it. */
3181 cr = crdup(get_current_cred());
3182 memset((char *)cr, 0, sizeof(cred_t));
3183 #if CELL || CELL_PREPARE
3190 DECL_PIOCTL(PGetRxkcrypt)
3192 memcpy(aout, (char *)&cryptall, sizeof(afs_int32));
3193 *aoutSize = sizeof(afs_int32);
3197 DECL_PIOCTL(PSetRxkcrypt)
3201 if (!afs_osi_suser(*acred))
3203 if (ainSize != sizeof(afs_int32) || ain == NULL)
3205 memcpy((char *)&tmpval, ain, sizeof(afs_int32));
3206 /* if new mappings added later this will need to be changed */
3207 if (tmpval != 0 && tmpval != 1)
3213 #ifdef AFS_NEED_CLIENTCONTEXT
3215 * Create new credentials to correspond to a remote user with given
3216 * <hostaddr, uid, g0, g1>. This allows a server running as root to
3217 * provide pioctl (and other) services to foreign clients (i.e. nfs
3218 * clients) by using this call to `become' the client.
3221 #define PIOCTL_HEADER 6
3223 HandleClientContext(struct afs_ioctl *ablob, int *com,
3224 struct AFS_UCRED **acred, struct AFS_UCRED *credp)
3227 afs_uint32 hostaddr;
3228 afs_int32 uid, g0, g1, i, code, pag, exporter_type;
3229 struct afs_exporter *exporter, *outexporter;
3230 struct AFS_UCRED *newcred;
3231 struct unixuser *au;
3233 #if defined(AFS_SGIMP_ENV)
3234 osi_Assert(ISAFS_GLOCK());
3236 AFS_STATCNT(HandleClientContext);
3237 if (ablob->in_size < PIOCTL_HEADER * sizeof(afs_int32)) {
3238 /* Must at least include the PIOCTL_HEADER header words required by the protocol */
3239 return EINVAL; /* Too small to be good */
3241 ain = inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
3242 AFS_COPYIN(ablob->in, ain, PIOCTL_HEADER * sizeof(afs_int32), code);
3244 osi_FreeLargeSpace(inData);
3248 /* Extract information for remote user */
3249 hostaddr = *((afs_uint32 *) ain);
3250 ain += sizeof(hostaddr);
3251 uid = *((afs_uint32 *) ain);
3253 g0 = *((afs_uint32 *) ain);
3255 g1 = *((afs_uint32 *) ain);
3257 *com = *((afs_uint32 *) ain);
3258 ain += sizeof(afs_int32);
3259 exporter_type = *((afs_uint32 *) ain); /* In case we support more than NFS */
3262 * Of course, one must be root for most of these functions, but
3263 * we'll allow (for knfs) you to set things if the pag is 0 and
3264 * you're setting tokens or unlogging.
3267 if (!afs_osi_suser(credp)) {
3268 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
3269 /* Since SGI's suser() returns explicit failure after the call.. */
3272 /* check for acceptable opcodes for normal folks, which are, so far,
3273 * set tokens and unlog.
3275 if (i != 9 && i != 3 && i != 38 && i != 8) {
3276 osi_FreeLargeSpace(inData);
3281 ablob->in_size -= PIOCTL_HEADER * sizeof(afs_int32);
3282 ablob->in += PIOCTL_HEADER * sizeof(afs_int32);
3283 osi_FreeLargeSpace(inData);
3286 * We map uid 0 to nobody to match the mapping that the nfs
3287 * server does and to ensure that the suser() calls in the afs
3288 * code fails for remote client roots.
3290 uid = afs_nobody; /* NFS_NOBODY == -2 */
3293 #ifdef AFS_AIX41_ENV
3296 newcred->cr_gid = RMTUSER_REQ;
3297 #ifdef AFS_AIX51_ENV
3298 newcred->cr_groupset.gs_union.un_groups[0] = g0;
3299 newcred->cr_groupset.gs_union.un_groups[1] = g1;
3301 newcred->cr_groups[0] = g0;
3302 newcred->cr_groups[1] = g1;
3305 newcred->cr_ngrps = 2;
3307 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV)
3308 newcred->cr_ngroups = 2;
3310 for (i = 2; i < NGROUPS; i++)
3311 newcred->cr_groups[i] = NOGROUP;
3314 #if !defined(AFS_OSF_ENV) && !defined(AFS_DEC_ENV)
3315 afs_nfsclient_init(); /* before looking for exporter, ensure one exists */
3317 if (!(exporter = exporter_find(exporter_type))) {
3318 /* Exporter wasn't initialized or an invalid exporter type */
3322 if (exporter->exp_states & EXP_PWSYNC) {
3323 if (uid != credp->cr_uid) {
3325 return ENOEXEC; /* XXX Find a better errno XXX */
3328 newcred->cr_uid = uid; /* Only temporary */
3329 code = EXP_REQHANDLER(exporter, &newcred, hostaddr, &pag, &outexporter);
3330 /* The client's pag is the only unique identifier for it */
3331 newcred->cr_uid = pag;
3333 if (!code && *com == PSETPAG) {
3334 /* Special case for 'setpag' */
3335 afs_uint32 pagvalue = genpag();
3337 au = afs_GetUser(pagvalue, -1, WRITE_LOCK); /* a new unixuser struct */
3339 * Note that we leave the 'outexporter' struct held so it won't
3342 au->exporter = outexporter;
3343 if (ablob->out_size >= 4) {
3344 AFS_COPYOUT((char *)&pagvalue, ablob->out, sizeof(afs_int32),
3347 afs_PutUser(au, WRITE_LOCK);
3350 return PSETPAG; /* Special return for setpag */
3352 EXP_RELE(outexporter);
3356 #endif /* AFS_NEED_CLIENTCONTEXT */
3358 /* get all interface addresses of this client */
3360 DECL_PIOCTL(PGetCPrefs)
3362 struct sprefrequest *spin; /* input */
3363 struct sprefinfo *spout; /* output */
3364 struct spref *srvout; /* one output component */
3368 AFS_STATCNT(PGetCPrefs);
3369 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3370 return EIO; /* Inappropriate ioctl for device */
3372 if (ainSize < sizeof(struct sprefrequest))
3375 spin = (struct sprefrequest *)ain;
3376 spout = (struct sprefinfo *)aout;
3378 maxNumber = spin->num_servers; /* max addrs this time */
3379 srvout = spout->servers;
3381 ObtainReadLock(&afs_xinterface);
3383 /* copy out the client interface information from the
3384 ** kernel data structure "interface" to the output buffer
3386 for (i = spin->offset, j = 0; (i < afs_cb_interface.numberOfInterfaces)
3387 && (j < maxNumber); i++, j++, srvout++)
3388 srvout->host.s_addr = afs_cb_interface.addr_in[i];
3390 spout->num_servers = j;
3391 *aoutSize = sizeof(struct sprefinfo) + (j - 1) * sizeof(struct spref);
3393 if (i >= afs_cb_interface.numberOfInterfaces)
3394 spout->next_offset = 0; /* start from beginning again */
3396 spout->next_offset = spin->offset + j;
3398 ReleaseReadLock(&afs_xinterface);
3402 DECL_PIOCTL(PSetCPrefs)
3404 struct setspref *sin;
3407 AFS_STATCNT(PSetCPrefs);
3408 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3409 return EIO; /* Inappropriate ioctl for device */
3411 sin = (struct setspref *)ain;
3413 if (ainSize < sizeof(struct setspref))
3415 #if 0 /* num_servers is unsigned */
3416 if (sin->num_servers < 0)
3419 if (sin->num_servers > AFS_MAX_INTERFACE_ADDR)
3422 ObtainWriteLock(&afs_xinterface, 412);
3423 afs_cb_interface.numberOfInterfaces = sin->num_servers;
3424 for (i = 0; (unsigned short)i < sin->num_servers; i++)
3425 afs_cb_interface.addr_in[i] = sin->servers[i].host.s_addr;
3427 ReleaseWriteLock(&afs_xinterface);
3431 DECL_PIOCTL(PFlushMount)
3433 register afs_int32 code;
3434 register struct vcache *tvc;
3435 register struct dcache *tdc;
3436 struct VenusFid tfid;
3438 struct sysname_info sysState;
3439 afs_size_t offset, len;
3441 AFS_STATCNT(PFlushMount);
3444 code = afs_VerifyVCache(avc, areq);
3447 if (vType(avc) != VDIR) {
3450 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
3453 Check_AtSys(avc, ain, &sysState, areq);
3454 ObtainReadLock(&tdc->lock);
3456 code = afs_dir_Lookup(&tdc->f.inode, sysState.name, &tfid.Fid);
3457 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
3458 ReleaseReadLock(&tdc->lock);
3459 afs_PutDCache(tdc); /* we're done with the data */
3460 bufp = sysState.name;
3464 tfid.Cell = avc->fid.Cell;
3465 tfid.Fid.Volume = avc->fid.Fid.Volume;
3466 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
3467 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
3469 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3475 if (tvc->mvstat != 1) {
3480 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
3481 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
3483 ObtainWriteLock(&tvc->lock, 649);
3484 ObtainWriteLock(&afs_xcbhash, 650);
3485 afs_DequeueCallback(tvc);
3486 tvc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
3487 ReleaseWriteLock(&afs_xcbhash);
3488 /* now find the disk cache entries */
3489 afs_TryToSmush(tvc, *acred, 1);
3490 osi_dnlc_purgedp(tvc);
3491 afs_symhint_inval(tvc);
3492 if (tvc->linkData && !(tvc->states & CCore)) {
3493 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
3494 tvc->linkData = NULL;
3496 ReleaseWriteLock(&tvc->lock);
3497 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
3498 afs_BozonUnlock(&tvc->pvnLock, tvc);
3502 if (sysState.allocked)
3503 osi_FreeLargeSpace(bufp);
3507 DECL_PIOCTL(PRxStatProc)
3512 if (!afs_osi_suser(*acred)) {
3516 if (ainSize != sizeof(afs_int32)) {
3520 memcpy((char *)&flags, ain, sizeof(afs_int32));
3521 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3525 if (flags & AFSCALL_RXSTATS_ENABLE) {
3526 rx_enableProcessRPCStats();
3528 if (flags & AFSCALL_RXSTATS_DISABLE) {
3529 rx_disableProcessRPCStats();
3531 if (flags & AFSCALL_RXSTATS_CLEAR) {
3532 rx_clearProcessRPCStats(AFS_RX_STATS_CLEAR_ALL);
3540 DECL_PIOCTL(PRxStatPeer)
3545 if (!afs_osi_suser(*acred)) {
3549 if (ainSize != sizeof(afs_int32)) {
3553 memcpy((char *)&flags, ain, sizeof(afs_int32));
3554 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3558 if (flags & AFSCALL_RXSTATS_ENABLE) {
3559 rx_enablePeerRPCStats();
3561 if (flags & AFSCALL_RXSTATS_DISABLE) {
3562 rx_disablePeerRPCStats();
3564 if (flags & AFSCALL_RXSTATS_CLEAR) {
3565 rx_clearPeerRPCStats(AFS_RX_STATS_CLEAR_ALL);
3572 DECL_PIOCTL(PPrefetchFromTape)
3574 register afs_int32 code, code1;
3577 struct rx_call *tcall;
3578 struct AFSVolSync tsync;
3579 struct AFSFetchStatus OutStatus;
3580 struct AFSCallBack CallBack;
3581 struct VenusFid tfid;
3585 AFS_STATCNT(PSetAcl);
3589 if (ain && (ainSize == 3 * sizeof(afs_int32)))
3590 Fid = (struct AFSFid *)ain;
3592 Fid = &avc->fid.Fid;
3593 tfid.Cell = avc->fid.Cell;
3594 tfid.Fid.Volume = Fid->Volume;
3595 tfid.Fid.Vnode = Fid->Vnode;
3596 tfid.Fid.Unique = Fid->Unique;
3598 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3600 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3601 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &avc->fid);
3604 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3605 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &tvc->fid);
3608 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3612 tcall = rx_NewCall(tc->id);
3614 StartRXAFS_FetchData(tcall, (struct AFSFid *)&tvc->fid.Fid, 0,
3617 bytes = rx_Read(tcall, (char *)aout, sizeof(afs_int32));
3619 EndRXAFS_FetchData(tcall, &OutStatus, &CallBack, &tsync);
3621 code1 = rx_EndCall(tcall, code);
3625 } while (afs_Analyze
3626 (tc, code, &tvc->fid, areq, AFS_STATS_FS_RPCIDX_RESIDENCYRPCS,
3627 SHARED_LOCK, NULL));
3628 /* This call is done only to have the callback things handled correctly */
3629 afs_FetchStatus(tvc, &tfid, areq, &OutStatus);
3633 *aoutSize = sizeof(afs_int32);
3638 DECL_PIOCTL(PResidencyCmd)
3640 register afs_int32 code;
3643 struct ResidencyCmdInputs *Inputs;
3644 struct ResidencyCmdOutputs *Outputs;
3645 struct VenusFid tfid;
3648 Inputs = (struct ResidencyCmdInputs *)ain;
3649 Outputs = (struct ResidencyCmdOutputs *)aout;
3652 if (!ain || ainSize != sizeof(struct ResidencyCmdInputs))
3657 Fid = &avc->fid.Fid;
3659 tfid.Cell = avc->fid.Cell;
3660 tfid.Fid.Volume = Fid->Volume;
3661 tfid.Fid.Vnode = Fid->Vnode;
3662 tfid.Fid.Unique = Fid->Unique;
3664 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3665 afs_Trace3(afs_iclSetp, CM_TRACE_RESIDCMD, ICL_TYPE_POINTER, tvc,
3666 ICL_TYPE_INT32, Inputs->command, ICL_TYPE_FID, &tfid);
3670 if (Inputs->command) {
3672 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3676 RXAFS_ResidencyCmd(tc->id, Fid, Inputs,
3677 (struct ResidencyCmdOutputs *)aout);
3681 } while (afs_Analyze
3682 (tc, code, &tvc->fid, areq,
3683 AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK, NULL));
3684 /* This call is done to have the callback things handled correctly */
3685 afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3686 } else { /* just a status request, return also link data */
3688 Outputs->code = afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3689 Outputs->chars[0] = 0;
3690 if (vType(tvc) == VLNK) {
3691 ObtainWriteLock(&tvc->lock, 555);
3692 if (afs_HandleLink(tvc, areq) == 0)
3693 strncpy((char *)&Outputs->chars, tvc->linkData, MAXCMDCHARS);
3694 ReleaseWriteLock(&tvc->lock);
3701 *aoutSize = sizeof(struct ResidencyCmdOutputs);