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)
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)
269 #error Not done for this linux type
272 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
274 afs_ioctl32_to_afs_ioctl(&dst32, dst);
277 #endif /* defined(AFS_LINUX_64BIT_KERNEL) */
279 AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code);
284 HandleIoctl(register struct vcache *avc, register afs_int32 acom,
285 struct afs_ioctl *adata)
287 register afs_int32 code;
290 AFS_STATCNT(HandleIoctl);
292 switch (acom & 0xff) {
294 avc->states |= CSafeStore;
298 /* case 2 used to be abort store, but this is no longer provided,
299 * since it is impossible to implement under normal Unix.
303 /* return the name of the cell this file is open on */
304 register struct cell *tcell;
305 register afs_int32 i;
307 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
309 i = strlen(tcell->cellName) + 1; /* bytes to copy out */
311 if (i > adata->out_size) {
312 /* 0 means we're not interested in the output */
313 if (adata->out_size != 0)
317 AFS_COPYOUT(tcell->cellName, adata->out, i, code);
319 afs_PutCell(tcell, READ_LOCK);
325 case 49: /* VIOC_GETINITPARAMS */
326 if (adata->out_size < sizeof(struct cm_initparams)) {
329 AFS_COPYOUT(&cm_initParams, adata->out,
330 sizeof(struct cm_initparams), code);
342 return code; /* so far, none implemented */
347 /* For aix we don't temporarily bypass ioctl(2) but rather do our
348 * thing directly in the vnode layer call, VNOP_IOCTL; thus afs_ioctl
349 * is now called from afs_gn_ioctl.
352 afs_ioctl(struct vcache *tvc, int cmd, int arg)
354 struct afs_ioctl data;
357 AFS_STATCNT(afs_ioctl);
358 if (((cmd >> 8) & 0xff) == 'V') {
359 /* This is a VICEIOCTL call */
360 AFS_COPYIN(arg, (caddr_t) & data, sizeof(data), error);
363 error = HandleIoctl(tvc, cmd, &data);
366 /* No-op call; just return. */
370 #endif /* AFS_AIX_ENV */
372 #if defined(AFS_SGI_ENV)
373 afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
376 , struct vopbd * vbds
380 struct afs_ioctl data;
386 AFS_STATCNT(afs_ioctl);
387 if (((cmd >> 8) & 0xff) == 'V') {
388 /* This is a VICEIOCTL call */
389 error = copyin_afs_ioctl(arg, &data);
392 locked = ISAFS_GLOCK();
395 error = HandleIoctl(tvc, cmd, &data);
400 /* No-op call; just return. */
404 #endif /* AFS_SGI_ENV */
406 /* unlike most calls here, this one uses u.u_error to return error conditions,
407 since this is really an intercepted chapter 2 call, rather than a vnode
410 /* AFS_HPUX102 and up uses VNODE ioctl instead */
411 #ifndef AFS_HPUX102_ENV
412 #if !defined(AFS_SGI_ENV)
416 kioctl(fdes, com, arg, ext, arg2, arg3)
417 #else /* __64BIT__ */
418 kioctl32(fdes, com, arg, ext, arg2, arg3)
419 #endif /* __64BIT__ */
422 kioctl(fdes, com, arg, ext)
433 } u_uap, *uap = &u_uap;
435 #if defined(AFS_SUN5_ENV)
437 struct afs_ioctl_sys {
444 struct afs_ioctl_sys *uap;
447 #elif defined(AFS_OSF_ENV)
448 afs_xioctl(p, args, retval)
457 } *uap = (struct a *)args;
458 #elif defined(AFS_FBSD50_ENV)
461 afs_xioctl(td, uap, retval)
463 register struct ioctl_args *uap;
466 struct proc *p = td->td_proc;
467 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
475 afs_xioctl(p, uap, retval)
477 register struct ioctl_args *uap;
480 #elif defined(AFS_LINUX22_ENV)
481 struct afs_ioctl_sys {
486 afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
489 struct afs_ioctl_sys ua, *uap = &ua;
498 } *uap = (struct a *)u.u_ap;
499 #endif /* AFS_SUN5_ENV */
501 #if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
503 #elif !defined(AFS_LINUX22_ENV)
504 register struct file *fd;
506 #if defined(AFS_XBSD_ENV)
507 register struct filedesc *fdp;
509 register struct vcache *tvc;
510 register int ioctlDone = 0, code = 0;
512 AFS_STATCNT(afs_xioctl);
513 #if defined(AFS_XBSD_ENV)
515 if ((u_int) uap->fd >= fdp->fd_nfiles
516 || (fd = fdp->fd_ofiles[uap->fd]) == NULL)
518 if ((fd->f_flag & (FREAD | FWRITE)) == 0)
520 #elif defined(AFS_DARWIN_ENV)
521 if ((code = fdgetf(p, uap->fd, &fd)))
523 #elif defined(AFS_LINUX22_ENV)
526 #elif defined(AFS_AIX32_ENV)
534 if (setuerror(getf(uap->fd, &fd))) {
537 #elif defined(AFS_OSF_ENV)
539 if (code = getf(&fd, uap->fd, FILE_FLAGS_NULL, &u.u_file_state))
541 #elif defined(AFS_SUN5_ENV)
542 # if defined(AFS_SUN57_ENV)
546 # elif defined(AFS_SUN54_ENV)
551 if (code = getf(uap->fd, &fd)) {
554 # endif /* AFS_SUN57_ENV */
560 /* first determine whether this is any sort of vnode */
561 #if defined(AFS_LINUX22_ENV)
566 if (fd->f_vnode->v_type == VREG || fd->f_vnode->v_type == VDIR) {
568 if (fd->f_type == DTYPE_VNODE) {
570 /* good, this is a vnode; next see if it is an AFS vnode */
571 #if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV)
572 tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */
573 #elif defined(AFS_OBSD_ENV)
575 IsAfsVnode((struct vnode *)fd->
576 f_data) ? VTOAFS((struct vnode *)fd->f_data) : NULL;
578 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
580 #endif /* AFS_LINUX22_ENV */
581 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
583 tvc = VTOAFS(afs_gntovn((struct gnode *)tvc));
584 if (!tvc) { /* shouldn't happen with held gnodes */
589 /* This is an AFS vnode */
590 if (((uap->com >> 8) & 0xff) == 'V') {
591 register struct afs_ioctl *datap;
594 (struct afs_ioctl *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
595 AFS_COPYIN((char *)uap->arg, (caddr_t) datap,
596 sizeof(struct afs_ioctl), code);
598 osi_FreeSmallSpace(datap);
600 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
603 #if defined(AFS_SUN5_ENV)
618 #else /* AFS_OSF_ENV */
622 #ifdef AFS_LINUX22_ENV
632 code = HandleIoctl(tvc, uap->com, datap);
633 osi_FreeSmallSpace(datap);
647 #if defined(AFS_LINUX22_ENV)
659 code = okioctl(fdes, com, arg, ext, arg2, arg3);
660 #else /* __64BIT__ */
661 code = okioctl32(fdes, com, arg, ext, arg2, arg3);
662 #endif /* __64BIT__ */
663 #else /* !AFS_AIX51_ENV */
664 code = okioctl(fdes, com, arg, ext);
665 #endif /* AFS_AIX51_ENV */
667 #else /* !AFS_AIX41_ENV */
669 okioctl(fdes, com, arg, ext);
670 #elif defined(AFS_SUN5_ENV)
671 #if defined(AFS_SUN57_ENV)
673 #elif defined(AFS_SUN54_ENV)
678 code = ioctl(uap, rvp);
679 #elif defined(AFS_FBSD50_ENV)
680 return ioctl(td, uap);
681 #elif defined(AFS_FBSD_ENV)
682 return ioctl(p, uap);
683 #elif defined(AFS_OBSD_ENV)
684 code = sys_ioctl(p, uap, retval);
685 #elif defined(AFS_DARWIN_ENV)
686 return ioctl(p, uap, retval);
687 #elif defined(AFS_OSF_ENV)
688 code = ioctl(p, args, retval);
695 #elif !defined(AFS_LINUX22_ENV)
709 #ifdef AFS_LINUX22_ENV
712 #if defined(KERNEL_HAVE_UERROR)
715 #if defined(AFS_AIX32_ENV) && !defined(AFS_AIX41_ENV)
716 return (getuerror()? -1 : u.u_ioctlrv);
718 return getuerror()? -1 : 0;
721 #endif /* AFS_LINUX22_ENV */
722 #endif /* AFS_SUN5_ENV */
723 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
727 #endif /* AFS_SGI_ENV */
728 #endif /* AFS_HPUX102_ENV */
730 #if defined(AFS_SGI_ENV)
731 /* "pioctl" system call entry point; just pass argument to the parameterized
740 afs_pioctl(struct pioctlargs *uap, rval_t * rvp)
744 AFS_STATCNT(afs_pioctl);
746 code = afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow);
755 #elif defined(AFS_OSF_ENV)
756 afs_pioctl(p, args, retval)
766 } *uap = (struct a *)args;
768 AFS_STATCNT(afs_pioctl);
769 return (afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow));
772 #elif defined(AFS_FBSD50_ENV)
774 afs_pioctl(td, args, retval)
784 } *uap = (struct a *)args;
786 AFS_STATCNT(afs_pioctl);
787 return (afs_syscall_pioctl
788 (uap->path, uap->cmd, uap->cmarg, uap->follow, td->td_ucred));
791 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
793 afs_pioctl(p, args, retval)
803 } *uap = (struct a *)args;
805 AFS_STATCNT(afs_pioctl);
806 return (afs_syscall_pioctl
807 (uap->path, uap->cmd, uap->cmarg, uap->follow,
808 p->p_cred->pc_ucred));
813 /* macro to avoid adding any more #ifdef's to pioctl code. */
814 #if defined(AFS_LINUX22_ENV) || defined(AFS_AIX41_ENV)
815 #define PIOCTL_FREE_CRED() crfree(credp)
817 #define PIOCTL_FREE_CRED()
822 afs_syscall_pioctl(path, com, cmarg, follow, rvp, credp)
824 struct AFS_UCRED *credp;
826 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
827 afs_syscall_pioctl(path, com, cmarg, follow, credp)
828 struct AFS_UCRED *credp;
830 afs_syscall_pioctl(path, com, cmarg, follow)
838 struct afs_ioctl data;
839 struct AFS_UCRED *tmpcred, *foreigncreds = NULL;
840 register afs_int32 code = 0;
846 struct ucred *credp = crref(); /* don't free until done! */
848 #ifdef AFS_LINUX22_ENV
849 cred_t *credp = crref(); /* don't free until done! */
853 AFS_STATCNT(afs_syscall_pioctl);
855 follow = 1; /* compat. with old venus */
856 code = copyin_afs_ioctl(cmarg, &data);
859 #if defined(KERNEL_HAVE_UERROR)
864 if ((com & 0xff) == PSetClientContext) {
865 #ifdef AFS_NEED_CLIENTCONTEXT
866 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV)
867 code = HandleClientContext(&data, &com, &foreigncreds, credp);
869 code = HandleClientContext(&data, &com, &foreigncreds, osi_curcred());
873 crfree(foreigncreds);
876 #if defined(KERNEL_HAVE_UERROR)
877 return (setuerror(code), code);
882 #else /* AFS_NEED_CLIENTCONTEXT */
884 #endif /* AFS_NEED_CLIENTCONTEXT */
886 #ifdef AFS_NEED_CLIENTCONTEXT
889 * We could have done without temporary setting the u.u_cred below
890 * (foreigncreds could be passed as param the pioctl modules)
891 * but calls such as afs_osi_suser() doesn't allow that since it
892 * references u.u_cred directly. We could, of course, do something
893 * like afs_osi_suser(cred) which, I think, is better since it
894 * generalizes and supports multi cred environments...
898 credp = foreigncreds;
899 #elif defined(AFS_AIX41_ENV)
900 tmpcred = crref(); /* XXX */
902 #elif defined(AFS_HPUX101_ENV)
903 tmpcred = p_cred(u.u_procp);
904 set_p_cred(u.u_procp, foreigncreds);
905 #elif defined(AFS_SGI_ENV)
906 tmpcred = OSI_GET_CURRENT_CRED();
907 OSI_SET_CURRENT_CRED(foreigncreds);
910 u.u_cred = foreigncreds;
913 #endif /* AFS_NEED_CLIENTCONTEXT */
914 if ((com & 0xff) == 15) {
915 /* special case prefetch so entire pathname eval occurs in helper process.
916 * otherwise, the pioctl call is essentially useless */
917 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
919 Prefetch(path, &data, follow,
920 foreigncreds ? foreigncreds : credp);
922 code = Prefetch(path, &data, follow, osi_curcred());
925 #if defined(KERNEL_HAVE_UERROR)
934 lookupname(path, USR, follow, NULL, &vp,
935 foreigncreds ? foreigncreds : credp);
937 #ifdef AFS_LINUX22_ENV
938 code = gop_lookupname(path, AFS_UIOUSER, follow, NULL, &dp);
940 vp = (struct vnode *)dp->d_inode;
942 code = gop_lookupname(path, AFS_UIOUSER, follow, NULL, &vp);
943 #endif /* AFS_LINUX22_ENV */
944 #endif /* AFS_AIX41_ENV */
948 #if defined(KERNEL_HAVE_UERROR)
956 /* now make the call if we were passed no file, or were passed an AFS file */
957 if (!vp || IsAfsVnode(vp)) {
958 #if defined(AFS_DEC_ENV)
959 /* Ultrix 4.0: can't get vcache entry unless we've got an AFS gnode.
960 * So, we must test in this part of the code. Also, must arrange to
961 * GRELE the original gnode pointer when we're done, since in Ultrix 4.0,
962 * we hold gnodes, whose references hold our vcache entries.
965 gp = vp; /* remember for "put" */
966 vp = (struct vnode *)afs_gntovn(vp); /* get vcache from gp */
969 #elif defined(AFS_SUN5_ENV)
970 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
971 #elif defined(AFS_AIX41_ENV)
973 struct ucred *cred1, *cred2;
976 cred1 = cred2 = foreigncreds;
978 cred1 = cred2 = credp;
980 code = afs_HandlePioctl(vp, com, &data, follow, &cred1);
981 if (cred1 != cred2) {
982 /* something changed the creds */
986 #elif defined(AFS_HPUX101_ENV)
988 struct ucred *cred = p_cred(u.u_procp);
989 code = afs_HandlePioctl(vp, com, &data, follow, &cred);
991 #elif defined(AFS_SGI_ENV)
994 credp = OSI_GET_CURRENT_CRED();
995 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
997 #elif defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
998 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1000 code = afs_HandlePioctl(vp, com, &data, follow, &u.u_cred);
1003 #if defined(KERNEL_HAVE_UERROR)
1006 code = EINVAL; /* not in /afs */
1017 #if defined(AFS_NEED_CLIENTCONTEXT)
1019 #ifdef AFS_AIX41_ENV
1020 crset(tmpcred); /* restore original credentials */
1022 #if defined(AFS_HPUX101_ENV)
1023 set_p_cred(u.u_procp, tmpcred); /* restore original credentials */
1024 #elif defined(AFS_SGI_ENV)
1025 OSI_SET_CURRENT_CRED(tmpcred); /* restore original credentials */
1026 #elif !defined(AFS_SUN5_ENV)
1027 osi_curcred() = tmpcred; /* restore original credentials */
1028 #endif /* AFS_HPUX101_ENV */
1029 crfree(foreigncreds);
1032 #endif /* AFS_NEED_CLIENTCONTEXT */
1034 #ifdef AFS_LINUX22_ENV
1037 AFS_RELE(vp); /* put vnode back */
1041 #if defined(KERNEL_HAVE_UERROR)
1044 return (getuerror());
1052 afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
1053 register struct afs_ioctl *ablob, int afollow,
1054 struct AFS_UCRED **acred)
1057 struct vrequest treq;
1058 register afs_int32 code;
1059 register afs_int32 function, device;
1060 afs_int32 inSize, outSize;
1061 char *inData, *outData;
1062 int (*(*pioctlSw)) ();
1064 struct afs_fakestat_state fakestate;
1066 avc = avp ? VTOAFS(avp) : NULL;
1067 afs_Trace3(afs_iclSetp, CM_TRACE_PIOCTL, ICL_TYPE_INT32, acom & 0xff,
1068 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, afollow);
1069 AFS_STATCNT(HandlePioctl);
1070 if ((code = afs_InitReq(&treq, *acred)))
1072 afs_InitFakeStat(&fakestate);
1074 code = afs_EvalFakeStat(&avc, &fakestate, &treq);
1076 afs_PutFakeStat(&fakestate);
1080 device = (acom & 0xff00) >> 8;
1082 case 'V': /* Original pioctls */
1083 pioctlSw = VpioctlSw;
1084 pioctlSwSize = sizeof(VpioctlSw);
1086 case 'C': /* Coordinated/common pioctls */
1087 pioctlSw = CpioctlSw;
1088 pioctlSwSize = sizeof(CpioctlSw);
1091 afs_PutFakeStat(&fakestate);
1094 function = acom & 0xff;
1095 if (function >= (pioctlSwSize / sizeof(char *))) {
1096 afs_PutFakeStat(&fakestate);
1097 return EINVAL; /* out of range */
1099 inSize = ablob->in_size;
1101 /* Do all range checking before continuing */
1102 if (inSize >= PIGGYSIZE || inSize < 0 || ablob->out_size < 0)
1105 inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1107 AFS_COPYIN(ablob->in, inData, inSize, code);
1108 inData[inSize] = '\0';
1112 osi_FreeLargeSpace(inData);
1113 afs_PutFakeStat(&fakestate);
1116 outData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1119 (*pioctlSw[function]) (avc, function, &treq, inData, outData, inSize,
1121 osi_FreeLargeSpace(inData);
1122 if (code == 0 && ablob->out_size > 0) {
1123 if (outSize > ablob->out_size)
1124 outSize = ablob->out_size;
1125 if (outSize >= PIGGYSIZE)
1128 outData[outSize] = '\0';
1129 AFS_COPYOUT(outData, ablob->out, outSize, code);
1132 osi_FreeLargeSpace(outData);
1133 afs_PutFakeStat(&fakestate);
1134 return afs_CheckCode(code, &treq, 41);
1137 DECL_PIOCTL(PGetFID)
1139 AFS_STATCNT(PGetFID);
1142 memcpy(aout, (char *)&avc->fid, sizeof(struct VenusFid));
1143 *aoutSize = sizeof(struct VenusFid);
1147 DECL_PIOCTL(PSetAcl)
1149 register afs_int32 code;
1151 struct AFSOpaque acl;
1152 struct AFSVolSync tsync;
1153 struct AFSFetchStatus OutStatus;
1156 AFS_STATCNT(PSetAcl);
1159 if ((acl.AFSOpaque_len = strlen(ain) + 1) > 1000)
1162 acl.AFSOpaque_val = ain;
1164 tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1166 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREACL);
1169 RXAFS_StoreACL(tconn->id, (struct AFSFid *)&avc->fid.Fid,
1170 &acl, &OutStatus, &tsync);
1175 } while (afs_Analyze
1176 (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_STOREACL,
1177 SHARED_LOCK, NULL));
1179 /* now we've forgotten all of the access info */
1180 ObtainWriteLock(&afs_xcbhash, 455);
1182 afs_DequeueCallback(avc);
1183 avc->states &= ~(CStatd | CUnique);
1184 ReleaseWriteLock(&afs_xcbhash);
1185 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
1186 osi_dnlc_purgedp(avc);
1190 int afs_defaultAsynchrony = 0;
1192 DECL_PIOCTL(PStoreBehind)
1195 struct sbstruct *sbr;
1197 sbr = (struct sbstruct *)ain;
1198 if (sbr->sb_default != -1) {
1199 if (afs_osi_suser(*acred))
1200 afs_defaultAsynchrony = sbr->sb_default;
1205 if (avc && (sbr->sb_thisfile != -1)) {
1207 (avc, PRSFS_WRITE | PRSFS_ADMINISTER, areq, DONT_CHECK_MODE_BITS))
1208 avc->asynchrony = sbr->sb_thisfile;
1213 *aoutSize = sizeof(struct sbstruct);
1214 sbr = (struct sbstruct *)aout;
1215 sbr->sb_default = afs_defaultAsynchrony;
1217 sbr->sb_thisfile = avc->asynchrony;
1223 DECL_PIOCTL(PGCPAGs)
1225 if (!afs_osi_suser(*acred)) {
1228 afs_gcpags = AFS_GCPAGS_USERDISABLED;
1232 DECL_PIOCTL(PGetAcl)
1234 struct AFSOpaque acl;
1235 struct AFSVolSync tsync;
1236 struct AFSFetchStatus OutStatus;
1242 AFS_STATCNT(PGetAcl);
1245 Fid.Volume = avc->fid.Fid.Volume;
1246 Fid.Vnode = avc->fid.Fid.Vnode;
1247 Fid.Unique = avc->fid.Fid.Unique;
1248 if (avc->states & CForeign) {
1250 * For a dfs xlator acl we have a special hack so that the
1251 * xlator will distinguish which type of acl will return. So
1252 * we currently use the top 2-bytes (vals 0-4) to tell which
1253 * type of acl to bring back. Horrible hack but this will
1254 * cause the least number of changes to code size and interfaces.
1256 if (Fid.Vnode & 0xc0000000)
1258 Fid.Vnode |= (ainSize << 30);
1260 acl.AFSOpaque_val = aout;
1262 tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1265 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHACL);
1267 code = RXAFS_FetchACL(tconn->id, &Fid, &acl, &OutStatus, &tsync);
1272 } while (afs_Analyze
1273 (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_FETCHACL,
1274 SHARED_LOCK, NULL));
1277 *aoutSize = (acl.AFSOpaque_len == 0 ? 1 : acl.AFSOpaque_len);
1290 AFS_STATCNT(PBogus);
1294 DECL_PIOCTL(PGetFileCell)
1296 register struct cell *tcell;
1298 AFS_STATCNT(PGetFileCell);
1301 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
1304 strcpy(aout, tcell->cellName);
1305 afs_PutCell(tcell, READ_LOCK);
1306 *aoutSize = strlen(aout) + 1;
1310 DECL_PIOCTL(PGetWSCell)
1312 struct cell *tcell = NULL;
1314 AFS_STATCNT(PGetWSCell);
1315 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1316 return EIO; /* Inappropriate ioctl for device */
1318 tcell = afs_GetPrimaryCell(READ_LOCK);
1319 if (!tcell) /* no primary cell? */
1321 strcpy(aout, tcell->cellName);
1322 *aoutSize = strlen(aout) + 1;
1323 afs_PutCell(tcell, READ_LOCK);
1327 DECL_PIOCTL(PGetUserCell)
1329 register afs_int32 i;
1330 register struct unixuser *tu;
1331 register struct cell *tcell;
1333 AFS_STATCNT(PGetUserCell);
1334 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1335 return EIO; /* Inappropriate ioctl for device */
1337 /* return the cell name of the primary cell for this user */
1338 i = UHash(areq->uid);
1339 ObtainWriteLock(&afs_xuser, 224);
1340 for (tu = afs_users[i]; tu; tu = tu->next) {
1341 if (tu->uid == areq->uid && (tu->states & UPrimary)) {
1343 ReleaseWriteLock(&afs_xuser);
1348 tcell = afs_GetCell(tu->cell, READ_LOCK);
1349 afs_PutUser(tu, WRITE_LOCK);
1353 strcpy(aout, tcell->cellName);
1354 afs_PutCell(tcell, READ_LOCK);
1355 *aoutSize = strlen(aout) + 1; /* 1 for the null */
1358 ReleaseWriteLock(&afs_xuser);
1365 DECL_PIOCTL(PSetTokens)
1368 register struct unixuser *tu;
1369 struct ClearToken clear;
1370 register struct cell *tcell;
1373 struct vrequest treq;
1374 afs_int32 flag, set_parent_pag = 0;
1376 AFS_STATCNT(PSetTokens);
1377 if (!afs_resourceinit_flag) {
1380 memcpy((char *)&i, ain, sizeof(afs_int32));
1381 ain += sizeof(afs_int32);
1382 stp = ain; /* remember where the ticket is */
1383 if (i < 0 || i > 2000)
1384 return EINVAL; /* malloc may fail */
1385 if (i > MAXKTCTICKETLEN)
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, 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;
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)
2669 for (cp = ain, count = 0; count < setsysname; count++) {
2670 /* won't go past end of ain since maxsysname*num < ain length */
2672 if (t >= MAXSYSNAME || t <= 0)
2674 /* check for names that can shoot us in the foot */
2675 if (*cp == '.' && (cp[1] == 0 || (cp[1] == '.' && cp[2] == 0)))
2681 /* inname gets first entry in case we're being a translater */
2683 memcpy(inname, ain, t + 1); /* include terminating null */
2686 if ((*acred)->cr_gid == RMTUSER_REQ) { /* Handles all exporters */
2687 pag = PagInCred(*acred);
2689 return EINVAL; /* Better than panicing */
2691 if (!(au = afs_FindUser(pag, -1, READ_LOCK))) {
2692 return EINVAL; /* Better than panicing */
2694 if (!(exporter = au->exporter)) {
2695 afs_PutUser(au, READ_LOCK);
2696 return EINVAL; /* Better than panicing */
2698 error = EXP_SYSNAME(exporter, (setsysname ? inname : NULL), outname);
2700 if (error == ENODEV)
2701 foundname = 0; /* sysname not set yet! */
2703 afs_PutUser(au, READ_LOCK);
2708 afs_PutUser(au, READ_LOCK);
2711 /* Not xlating, so local case */
2713 osi_Panic("PSetSysName: !afs_sysname\n");
2714 if (!setsysname) { /* user just wants the info */
2715 strcpy(outname, afs_sysname);
2716 foundname = afs_sysnamecount;
2717 } else { /* Local guy; only root can change sysname */
2718 if (!afs_osi_suser(*acred))
2721 /* clear @sys entries from the dnlc, once afs_lookup can
2722 * do lookups of @sys entries and thinks it can trust them */
2723 /* privs ok, store the entry, ... */
2724 strcpy(afs_sysname, inname);
2725 if (setsysname > 1) { /* ... or list */
2727 for (count = 1; count < setsysname; ++count) {
2728 if (!afs_sysnamelist[count])
2730 ("PSetSysName: no afs_sysnamelist entry to write\n");
2732 memcpy(afs_sysnamelist[count], cp, t + 1); /* include null */
2736 afs_sysnamecount = setsysname;
2740 cp = aout; /* not changing so report back the count and ... */
2741 memcpy(cp, (char *)&foundname, sizeof(afs_int32));
2742 cp += sizeof(afs_int32);
2744 strcpy(cp, outname); /* ... the entry, ... */
2745 cp += strlen(outname) + 1;
2746 for (count = 1; count < foundname; ++count) { /* ... or list. */
2747 /* Note: we don't support @sys lists for exporters */
2748 if (!afs_sysnamelist[count])
2750 ("PSetSysName: no afs_sysnamelist entry to read\n");
2751 t = strlen(afs_sysnamelist[count]);
2752 if (t >= MAXSYSNAME)
2753 osi_Panic("PSetSysName: sysname entry garbled\n");
2754 strcpy(cp, afs_sysnamelist[count]);
2758 *aoutSize = cp - aout;
2763 /* sequential search through the list of touched cells is not a good
2764 * long-term solution here. For small n, though, it should be just
2765 * fine. Should consider special-casing the local cell for large n.
2766 * Likewise for PSetSPrefs.
2768 * s - number of ids in array l[] -- NOT index of last id
2769 * l - array of cell ids which have volumes that need to be sorted
2770 * vlonly - sort vl servers or file servers?
2773 ReSortCells_cb(struct cell *cell, void *arg)
2775 afs_int32 *p = (afs_int32 *) arg;
2776 afs_int32 *l = p + 1;
2779 for (i = 0; i < s; i++) {
2780 if (l[i] == cell->cellNum) {
2781 ObtainWriteLock(&cell->lock, 690);
2782 afs_SortServers(cell->cellHosts, MAXCELLHOSTS);
2783 ReleaseWriteLock(&cell->lock);
2791 ReSortCells(int s, afs_int32 * l, int vlonly)
2799 p = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * (s + 1));
2801 memcpy(p + 1, l, s * sizeof(afs_int32));
2802 afs_TraverseCells(&ReSortCells_cb, p);
2803 afs_osi_Free(p, sizeof(afs_int32) * (s + 1));
2807 ObtainReadLock(&afs_xvolume);
2808 for (i = 0; i < NVOLS; i++) {
2809 for (j = afs_volumes[i]; j; j = j->next) {
2810 for (k = 0; k < s; k++)
2811 if (j->cell == l[k]) {
2812 ObtainWriteLock(&j->lock, 233);
2813 afs_SortServers(j->serverHost, MAXHOSTS);
2814 ReleaseWriteLock(&j->lock);
2819 ReleaseReadLock(&afs_xvolume);
2823 static int debugsetsp = 0;
2825 afs_setsprefs(sp, num, vlonly)
2828 unsigned int vlonly;
2831 int i, j, k, matches, touchedSize;
2832 struct server *srvr = NULL;
2833 afs_int32 touched[34];
2837 for (k = 0; k < num; sp++, k++) {
2839 printf("sp host=%x, rank=%d\n", sp->host.s_addr, sp->rank);
2842 ObtainReadLock(&afs_xserver);
2844 i = SHash(sp->host.s_addr);
2845 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2846 if (sa->sa_ip == sp->host.s_addr) {
2848 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
2849 || (sa->sa_portal == AFS_FSPORT);
2850 if ((!vlonly && isfs) || (vlonly && !isfs)) {
2857 if (sa && matches) { /* found one! */
2859 printf("sa ip=%x, ip_rank=%d\n", sa->sa_ip, sa->sa_iprank);
2861 sa->sa_iprank = sp->rank + afs_randomMod15();
2862 afs_SortOneServer(sa->server);
2865 /* if we don't know yet what cell it's in, this is moot */
2866 for (j = touchedSize - 1;
2867 j >= 0 && touched[j] != srvr->cell->cellNum; j--)
2868 /* is it in our list of touched cells ? */ ;
2869 if (j < 0) { /* no, it's not */
2870 touched[touchedSize++] = srvr->cell->cellNum;
2871 if (touchedSize >= 32) { /* watch for ovrflow */
2872 ReleaseReadLock(&afs_xserver);
2873 ReSortCells(touchedSize, touched, vlonly);
2875 ObtainReadLock(&afs_xserver);
2881 ReleaseReadLock(&afs_xserver);
2882 /* if we didn't find one, start to create one. */
2883 /* Note that it doesn't have a cell yet... */
2885 afs_uint32 temp = sp->host.s_addr;
2887 afs_GetServer(&temp, 1, 0, (vlonly ? AFS_VLPORT : AFS_FSPORT),
2888 WRITE_LOCK, (afsUUID *) 0, 0);
2889 srvr->addr->sa_iprank = sp->rank + afs_randomMod15();
2890 afs_PutServer(srvr, WRITE_LOCK);
2892 } /* for all cited preferences */
2894 ReSortCells(touchedSize, touched, vlonly);
2898 /* Note that this may only be performed by the local root user.
2900 DECL_PIOCTL(PSetSPrefs)
2902 struct setspref *ssp;
2903 AFS_STATCNT(PSetSPrefs);
2905 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2906 return EIO; /* Inappropriate ioctl for device */
2908 if (!afs_osi_suser(*acred))
2911 if (ainSize < sizeof(struct setspref))
2914 ssp = (struct setspref *)ain;
2915 if (ainSize < sizeof(struct spref) * ssp->num_servers)
2918 afs_setsprefs(&(ssp->servers[0]), ssp->num_servers,
2919 (ssp->flags & DBservers));
2923 DECL_PIOCTL(PSetSPrefs33)
2926 AFS_STATCNT(PSetSPrefs);
2927 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2928 return EIO; /* Inappropriate ioctl for device */
2931 if (!afs_osi_suser(*acred))
2934 sp = (struct spref *)ain;
2935 afs_setsprefs(sp, ainSize / (sizeof(struct spref)), 0 /*!vlonly */ );
2939 /* some notes on the following code...
2940 * in the hash table of server structs, all servers with the same IP address
2941 * will be on the same overflow chain.
2942 * This could be sped slightly in some circumstances by having it cache the
2943 * immediately previous slot in the hash table and some supporting information
2944 * Only reports file servers now.
2946 DECL_PIOCTL(PGetSPrefs)
2948 struct sprefrequest *spin; /* input */
2949 struct sprefinfo *spout; /* output */
2950 struct spref *srvout; /* one output component */
2951 int i, j; /* counters for hash table traversal */
2952 struct server *srvr; /* one of CM's server structs */
2954 int vlonly; /* just return vlservers ? */
2957 AFS_STATCNT(PGetSPrefs);
2958 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2959 return EIO; /* Inappropriate ioctl for device */
2962 if (ainSize < sizeof(struct sprefrequest_33)) {
2965 spin = ((struct sprefrequest *)ain);
2968 if (ainSize > sizeof(struct sprefrequest_33)) {
2969 vlonly = (spin->flags & DBservers);
2973 /* struct sprefinfo includes 1 server struct... that size gets added
2974 * in during the loop that follows.
2976 *aoutSize = sizeof(struct sprefinfo) - sizeof(struct spref);
2977 spout = (struct sprefinfo *)aout;
2978 spout->next_offset = spin->offset;
2979 spout->num_servers = 0;
2980 srvout = spout->servers;
2982 ObtainReadLock(&afs_xserver);
2983 for (i = 0, j = 0; j < NSERVERS; j++) { /* sift through hash table */
2984 for (sa = afs_srvAddrs[j]; sa; sa = sa->next_bkt, i++) {
2985 if (spin->offset > (unsigned short)i) {
2986 continue; /* catch up to where we left off */
2988 spout->next_offset++;
2991 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
2992 || (sa->sa_portal == AFS_FSPORT);
2994 if ((vlonly && isfs) || (!vlonly && !isfs)) {
2995 /* only report ranks for vl servers */
2999 srvout->host.s_addr = sa->sa_ip;
3000 srvout->rank = sa->sa_iprank;
3001 *aoutSize += sizeof(struct spref);
3002 spout->num_servers++;
3005 if (*aoutSize > (PIGGYSIZE - sizeof(struct spref))) {
3006 ReleaseReadLock(&afs_xserver); /* no more room! */
3011 ReleaseReadLock(&afs_xserver);
3013 spout->next_offset = 0; /* start over from the beginning next time */
3017 /* Enable/Disable the specified exporter. Must be root to disable an exporter */
3018 int afs_NFSRootOnly = 1;
3019 DECL_PIOCTL(PExportAfs)
3021 afs_int32 export, newint =
3022 0, type, changestate, handleValue, convmode, pwsync, smounts;
3023 register struct afs_exporter *exporter;
3025 AFS_STATCNT(PExportAfs);
3026 memcpy((char *)&handleValue, ain, sizeof(afs_int32));
3027 type = handleValue >> 24;
3032 exporter = exporter_find(type);
3034 export = handleValue & 3;
3035 changestate = handleValue & 0xff;
3036 smounts = (handleValue >> 2) & 3;
3037 pwsync = (handleValue >> 4) & 3;
3038 convmode = (handleValue >> 6) & 3;
3040 changestate = (handleValue >> 16) & 0x1;
3041 convmode = (handleValue >> 16) & 0x2;
3042 pwsync = (handleValue >> 16) & 0x4;
3043 smounts = (handleValue >> 16) & 0x8;
3044 export = handleValue & 0xff;
3047 /* Failed finding desired exporter; */
3051 handleValue = exporter->exp_states;
3052 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3053 *aoutSize = sizeof(afs_int32);
3055 if (!afs_osi_suser(*acred))
3056 return EACCES; /* Only superuser can do this */
3060 exporter->exp_states |= EXP_EXPORTED;
3062 exporter->exp_states &= ~EXP_EXPORTED;
3066 exporter->exp_states |= EXP_UNIXMODE;
3068 exporter->exp_states &= ~EXP_UNIXMODE;
3072 exporter->exp_states |= EXP_PWSYNC;
3074 exporter->exp_states &= ~EXP_PWSYNC;
3078 afs_NFSRootOnly = 0;
3079 exporter->exp_states |= EXP_SUBMOUNTS;
3081 afs_NFSRootOnly = 1;
3082 exporter->exp_states &= ~EXP_SUBMOUNTS;
3085 handleValue = exporter->exp_states;
3086 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3087 *aoutSize = sizeof(afs_int32);
3090 exporter->exp_states |= EXP_EXPORTED;
3092 exporter->exp_states &= ~EXP_EXPORTED;
3094 exporter->exp_states |= EXP_UNIXMODE;
3096 exporter->exp_states &= ~EXP_UNIXMODE;
3098 exporter->exp_states |= EXP_PWSYNC;
3100 exporter->exp_states &= ~EXP_PWSYNC;
3102 afs_NFSRootOnly = 0;
3103 exporter->exp_states |= EXP_SUBMOUNTS;
3105 afs_NFSRootOnly = 1;
3106 exporter->exp_states &= ~EXP_SUBMOUNTS;
3116 struct gaginfo *gagflags;
3118 if (!afs_osi_suser(*acred))
3121 gagflags = (struct gaginfo *)ain;
3122 afs_showflags = gagflags->showflags;
3128 DECL_PIOCTL(PTwiddleRx)
3130 struct rxparams *rxp;
3132 if (!afs_osi_suser(*acred))
3135 rxp = (struct rxparams *)ain;
3137 if (rxp->rx_initReceiveWindow)
3138 rx_initReceiveWindow = rxp->rx_initReceiveWindow;
3139 if (rxp->rx_maxReceiveWindow)
3140 rx_maxReceiveWindow = rxp->rx_maxReceiveWindow;
3141 if (rxp->rx_initSendWindow)
3142 rx_initSendWindow = rxp->rx_initSendWindow;
3143 if (rxp->rx_maxSendWindow)
3144 rx_maxSendWindow = rxp->rx_maxSendWindow;
3145 if (rxp->rxi_nSendFrags)
3146 rxi_nSendFrags = rxp->rxi_nSendFrags;
3147 if (rxp->rxi_nRecvFrags)
3148 rxi_nRecvFrags = rxp->rxi_nRecvFrags;
3149 if (rxp->rxi_OrphanFragSize)
3150 rxi_OrphanFragSize = rxp->rxi_OrphanFragSize;
3151 if (rxp->rx_maxReceiveSize) {
3152 rx_maxReceiveSize = rxp->rx_maxReceiveSize;
3153 rx_maxReceiveSizeUser = rxp->rx_maxReceiveSize;
3155 if (rxp->rx_MyMaxSendSize)
3156 rx_MyMaxSendSize = rxp->rx_MyMaxSendSize;
3161 DECL_PIOCTL(PGetInitParams)
3163 if (sizeof(struct cm_initparams) > PIGGYSIZE)
3166 memcpy(aout, (char *)&cm_initParams, sizeof(struct cm_initparams));
3167 *aoutSize = sizeof(struct cm_initparams);
3171 #ifdef AFS_SGI65_ENV
3172 /* They took crget() from us, so fake it. */
3177 cr = crdup(get_current_cred());
3178 memset((char *)cr, 0, sizeof(cred_t));
3179 #if CELL || CELL_PREPARE
3186 DECL_PIOCTL(PGetRxkcrypt)
3188 memcpy(aout, (char *)&cryptall, sizeof(afs_int32));
3189 *aoutSize = sizeof(afs_int32);
3193 DECL_PIOCTL(PSetRxkcrypt)
3197 if (!afs_osi_suser(*acred))
3199 if (ainSize != sizeof(afs_int32) || ain == NULL)
3201 memcpy((char *)&tmpval, ain, sizeof(afs_int32));
3202 /* if new mappings added later this will need to be changed */
3203 if (tmpval != 0 && tmpval != 1)
3209 #ifdef AFS_NEED_CLIENTCONTEXT
3211 * Create new credentials to correspond to a remote user with given
3212 * <hostaddr, uid, g0, g1>. This allows a server running as root to
3213 * provide pioctl (and other) services to foreign clients (i.e. nfs
3214 * clients) by using this call to `become' the client.
3217 #define PIOCTL_HEADER 6
3219 HandleClientContext(struct afs_ioctl *ablob, int *com,
3220 struct AFS_UCRED **acred, struct AFS_UCRED *credp)
3223 afs_uint32 hostaddr;
3224 afs_int32 uid, g0, g1, i, code, pag, exporter_type;
3225 struct afs_exporter *exporter, *outexporter;
3226 struct AFS_UCRED *newcred;
3227 struct unixuser *au;
3229 #if defined(AFS_SGIMP_ENV)
3230 osi_Assert(ISAFS_GLOCK());
3232 AFS_STATCNT(HandleClientContext);
3233 if (ablob->in_size < PIOCTL_HEADER * sizeof(afs_int32)) {
3234 /* Must at least include the PIOCTL_HEADER header words required by the protocol */
3235 return EINVAL; /* Too small to be good */
3237 ain = inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
3238 AFS_COPYIN(ablob->in, ain, PIOCTL_HEADER * sizeof(afs_int32), code);
3240 osi_FreeLargeSpace(inData);
3244 /* Extract information for remote user */
3245 hostaddr = *((afs_uint32 *) ain);
3246 ain += sizeof(hostaddr);
3247 uid = *((afs_uint32 *) ain);
3249 g0 = *((afs_uint32 *) ain);
3251 g1 = *((afs_uint32 *) ain);
3253 *com = *((afs_uint32 *) ain);
3254 ain += sizeof(afs_int32);
3255 exporter_type = *((afs_uint32 *) ain); /* In case we support more than NFS */
3258 * Of course, one must be root for most of these functions, but
3259 * we'll allow (for knfs) you to set things if the pag is 0 and
3260 * you're setting tokens or unlogging.
3263 if (!afs_osi_suser(credp)) {
3264 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
3265 /* Since SGI's suser() returns explicit failure after the call.. */
3268 /* check for acceptable opcodes for normal folks, which are, so far,
3269 * set tokens and unlog.
3271 if (i != 9 && i != 3 && i != 38 && i != 8) {
3272 osi_FreeLargeSpace(inData);
3277 ablob->in_size -= PIOCTL_HEADER * sizeof(afs_int32);
3278 ablob->in += PIOCTL_HEADER * sizeof(afs_int32);
3279 osi_FreeLargeSpace(inData);
3282 * We map uid 0 to nobody to match the mapping that the nfs
3283 * server does and to ensure that the suser() calls in the afs
3284 * code fails for remote client roots.
3286 uid = afs_nobody; /* NFS_NOBODY == -2 */
3289 #ifdef AFS_AIX41_ENV
3292 newcred->cr_gid = RMTUSER_REQ;
3293 #ifdef AFS_AIX51_ENV
3294 newcred->cr_groupset.gs_union.un_groups[0] = g0;
3295 newcred->cr_groupset.gs_union.un_groups[1] = g1;
3297 newcred->cr_groups[0] = g0;
3298 newcred->cr_groups[1] = g1;
3301 newcred->cr_ngrps = 2;
3303 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV)
3304 newcred->cr_ngroups = 2;
3306 for (i = 2; i < NGROUPS; i++)
3307 newcred->cr_groups[i] = NOGROUP;
3310 #if !defined(AFS_OSF_ENV) && !defined(AFS_DEC_ENV)
3311 afs_nfsclient_init(); /* before looking for exporter, ensure one exists */
3313 if (!(exporter = exporter_find(exporter_type))) {
3314 /* Exporter wasn't initialized or an invalid exporter type */
3318 if (exporter->exp_states & EXP_PWSYNC) {
3319 if (uid != credp->cr_uid) {
3321 return ENOEXEC; /* XXX Find a better errno XXX */
3324 newcred->cr_uid = uid; /* Only temporary */
3325 code = EXP_REQHANDLER(exporter, &newcred, hostaddr, &pag, &outexporter);
3326 /* The client's pag is the only unique identifier for it */
3327 newcred->cr_uid = pag;
3329 if (!code && *com == PSETPAG) {
3330 /* Special case for 'setpag' */
3331 afs_uint32 pagvalue = genpag();
3333 au = afs_GetUser(pagvalue, -1, WRITE_LOCK); /* a new unixuser struct */
3335 * Note that we leave the 'outexporter' struct held so it won't
3338 au->exporter = outexporter;
3339 if (ablob->out_size >= 4) {
3340 AFS_COPYOUT((char *)&pagvalue, ablob->out, sizeof(afs_int32),
3343 afs_PutUser(au, WRITE_LOCK);
3346 return PSETPAG; /* Special return for setpag */
3348 EXP_RELE(outexporter);
3352 #endif /* AFS_NEED_CLIENTCONTEXT */
3354 /* get all interface addresses of this client */
3356 DECL_PIOCTL(PGetCPrefs)
3358 struct sprefrequest *spin; /* input */
3359 struct sprefinfo *spout; /* output */
3360 struct spref *srvout; /* one output component */
3364 AFS_STATCNT(PGetCPrefs);
3365 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3366 return EIO; /* Inappropriate ioctl for device */
3368 if (ainSize < sizeof(struct sprefrequest))
3371 spin = (struct sprefrequest *)ain;
3372 spout = (struct sprefinfo *)aout;
3374 maxNumber = spin->num_servers; /* max addrs this time */
3375 srvout = spout->servers;
3377 ObtainReadLock(&afs_xinterface);
3379 /* copy out the client interface information from the
3380 ** kernel data structure "interface" to the output buffer
3382 for (i = spin->offset, j = 0; (i < afs_cb_interface.numberOfInterfaces)
3383 && (j < maxNumber); i++, j++, srvout++)
3384 srvout->host.s_addr = afs_cb_interface.addr_in[i];
3386 spout->num_servers = j;
3387 *aoutSize = sizeof(struct sprefinfo) + (j - 1) * sizeof(struct spref);
3389 if (i >= afs_cb_interface.numberOfInterfaces)
3390 spout->next_offset = 0; /* start from beginning again */
3392 spout->next_offset = spin->offset + j;
3394 ReleaseReadLock(&afs_xinterface);
3398 DECL_PIOCTL(PSetCPrefs)
3400 struct setspref *sin;
3403 AFS_STATCNT(PSetCPrefs);
3404 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3405 return EIO; /* Inappropriate ioctl for device */
3407 sin = (struct setspref *)ain;
3409 if (ainSize < sizeof(struct setspref))
3411 #if 0 /* num_servers is unsigned */
3412 if (sin->num_servers < 0)
3415 if (sin->num_servers > AFS_MAX_INTERFACE_ADDR)
3418 ObtainWriteLock(&afs_xinterface, 412);
3419 afs_cb_interface.numberOfInterfaces = sin->num_servers;
3420 for (i = 0; (unsigned short)i < sin->num_servers; i++)
3421 afs_cb_interface.addr_in[i] = sin->servers[i].host.s_addr;
3423 ReleaseWriteLock(&afs_xinterface);
3427 DECL_PIOCTL(PFlushMount)
3429 register afs_int32 code;
3430 register struct vcache *tvc;
3431 register struct dcache *tdc;
3432 struct VenusFid tfid;
3434 struct sysname_info sysState;
3435 afs_size_t offset, len;
3437 AFS_STATCNT(PFlushMount);
3440 code = afs_VerifyVCache(avc, areq);
3443 if (vType(avc) != VDIR) {
3446 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
3449 Check_AtSys(avc, ain, &sysState, areq);
3450 ObtainReadLock(&tdc->lock);
3452 code = afs_dir_Lookup(&tdc->f.inode, sysState.name, &tfid.Fid);
3453 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
3454 ReleaseReadLock(&tdc->lock);
3455 afs_PutDCache(tdc); /* we're done with the data */
3456 bufp = sysState.name;
3460 tfid.Cell = avc->fid.Cell;
3461 tfid.Fid.Volume = avc->fid.Fid.Volume;
3462 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
3463 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
3465 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3471 if (tvc->mvstat != 1) {
3476 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
3477 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
3479 ObtainWriteLock(&tvc->lock, 649);
3480 ObtainWriteLock(&afs_xcbhash, 650);
3481 afs_DequeueCallback(tvc);
3482 tvc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
3483 ReleaseWriteLock(&afs_xcbhash);
3484 /* now find the disk cache entries */
3485 afs_TryToSmush(tvc, *acred, 1);
3486 osi_dnlc_purgedp(tvc);
3487 afs_symhint_inval(tvc);
3488 if (tvc->linkData && !(tvc->states & CCore)) {
3489 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
3490 tvc->linkData = NULL;
3492 ReleaseWriteLock(&tvc->lock);
3493 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
3494 afs_BozonUnlock(&tvc->pvnLock, tvc);
3498 if (sysState.allocked)
3499 osi_FreeLargeSpace(bufp);
3503 DECL_PIOCTL(PRxStatProc)
3508 if (!afs_osi_suser(*acred)) {
3512 if (ainSize != sizeof(afs_int32)) {
3516 memcpy((char *)&flags, ain, sizeof(afs_int32));
3517 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3521 if (flags & AFSCALL_RXSTATS_ENABLE) {
3522 rx_enableProcessRPCStats();
3524 if (flags & AFSCALL_RXSTATS_DISABLE) {
3525 rx_disableProcessRPCStats();
3527 if (flags & AFSCALL_RXSTATS_CLEAR) {
3528 rx_clearProcessRPCStats(AFS_RX_STATS_CLEAR_ALL);
3536 DECL_PIOCTL(PRxStatPeer)
3541 if (!afs_osi_suser(*acred)) {
3545 if (ainSize != sizeof(afs_int32)) {
3549 memcpy((char *)&flags, ain, sizeof(afs_int32));
3550 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3554 if (flags & AFSCALL_RXSTATS_ENABLE) {
3555 rx_enablePeerRPCStats();
3557 if (flags & AFSCALL_RXSTATS_DISABLE) {
3558 rx_disablePeerRPCStats();
3560 if (flags & AFSCALL_RXSTATS_CLEAR) {
3561 rx_clearPeerRPCStats(AFS_RX_STATS_CLEAR_ALL);
3568 DECL_PIOCTL(PPrefetchFromTape)
3570 register afs_int32 code, code1;
3573 struct rx_call *tcall;
3574 struct AFSVolSync tsync;
3575 struct AFSFetchStatus OutStatus;
3576 struct AFSCallBack CallBack;
3577 struct VenusFid tfid;
3581 AFS_STATCNT(PSetAcl);
3585 if (ain && (ainSize == 3 * sizeof(afs_int32)))
3586 Fid = (struct AFSFid *)ain;
3588 Fid = &avc->fid.Fid;
3589 tfid.Cell = avc->fid.Cell;
3590 tfid.Fid.Volume = Fid->Volume;
3591 tfid.Fid.Vnode = Fid->Vnode;
3592 tfid.Fid.Unique = Fid->Unique;
3594 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3596 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3597 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &avc->fid);
3600 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3601 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &tvc->fid);
3604 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3608 tcall = rx_NewCall(tc->id);
3610 StartRXAFS_FetchData(tcall, (struct AFSFid *)&tvc->fid.Fid, 0,
3613 bytes = rx_Read(tcall, (char *)aout, sizeof(afs_int32));
3615 EndRXAFS_FetchData(tcall, &OutStatus, &CallBack, &tsync);
3617 code1 = rx_EndCall(tcall, code);
3621 } while (afs_Analyze
3622 (tc, code, &tvc->fid, areq, AFS_STATS_FS_RPCIDX_RESIDENCYRPCS,
3623 SHARED_LOCK, NULL));
3624 /* This call is done only to have the callback things handled correctly */
3625 afs_FetchStatus(tvc, &tfid, areq, &OutStatus);
3629 *aoutSize = sizeof(afs_int32);
3634 DECL_PIOCTL(PResidencyCmd)
3636 register afs_int32 code;
3639 struct ResidencyCmdInputs *Inputs;
3640 struct ResidencyCmdOutputs *Outputs;
3641 struct VenusFid tfid;
3644 Inputs = (struct ResidencyCmdInputs *)ain;
3645 Outputs = (struct ResidencyCmdOutputs *)aout;
3648 if (!ain || ainSize != sizeof(struct ResidencyCmdInputs))
3653 Fid = &avc->fid.Fid;
3655 tfid.Cell = avc->fid.Cell;
3656 tfid.Fid.Volume = Fid->Volume;
3657 tfid.Fid.Vnode = Fid->Vnode;
3658 tfid.Fid.Unique = Fid->Unique;
3660 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3661 afs_Trace3(afs_iclSetp, CM_TRACE_RESIDCMD, ICL_TYPE_POINTER, tvc,
3662 ICL_TYPE_INT32, Inputs->command, ICL_TYPE_FID, &tfid);
3666 if (Inputs->command) {
3668 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3672 RXAFS_ResidencyCmd(tc->id, Fid, Inputs,
3673 (struct ResidencyCmdOutputs *)aout);
3677 } while (afs_Analyze
3678 (tc, code, &tvc->fid, areq,
3679 AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK, NULL));
3680 /* This call is done to have the callback things handled correctly */
3681 afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3682 } else { /* just a status request, return also link data */
3684 Outputs->code = afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3685 Outputs->chars[0] = 0;
3686 if (vType(tvc) == VLNK) {
3687 ObtainWriteLock(&tvc->lock, 555);
3688 if (afs_HandleLink(tvc, areq) == 0)
3689 strncpy((char *)&Outputs->chars, tvc->linkData, MAXCMDCHARS);
3690 ReleaseWriteLock(&tvc->lock);
3697 *aoutSize = sizeof(struct ResidencyCmdOutputs);