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);
91 DECL_PIOCTL(PCallBackAddr);
94 * A macro that says whether we're going to need HandleClientContext().
95 * This is currently used only by the nfs translator.
97 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
98 #define AFS_NEED_CLIENTCONTEXT
101 /* Prototypes for private routines */
102 #ifdef AFS_NEED_CLIENTCONTEXT
103 static int HandleClientContext(struct afs_ioctl *ablob, int *com,
104 struct AFS_UCRED **acred,
105 struct AFS_UCRED *credp);
107 int HandleIoctl(register struct vcache *avc, register afs_int32 acom,
108 struct afs_ioctl *adata);
109 int afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
110 register struct afs_ioctl *ablob, int afollow,
111 struct AFS_UCRED **acred);
112 static int Prefetch(char *apath, struct afs_ioctl *adata, int afollow,
113 struct AFS_UCRED *acred);
116 static int (*(VpioctlSw[])) () = {
121 PGetVolumeStatus, /* 4 */
122 PSetVolumeStatus, /* 5 */
127 PCheckServers, /* 10 */
128 PCheckVolNames, /* 11 */
130 PBogus, /* 13 -- used to be quick check time */
131 PFindVolume, /* 14 */
132 PBogus, /* 15 -- prefetch is now special-cased; see pioctl code! */
133 PBogus, /* 16 -- used to be testing code */
134 PNoop, /* 17 -- used to be enable group */
135 PNoop, /* 18 -- used to be disable group */
136 PBogus, /* 19 -- used to be list group */
137 PViceAccess, /* 20 */
138 PUnlog, /* 21 -- unlog *is* unpag in this system */
139 PGetFID, /* 22 -- get file ID */
140 PBogus, /* 23 -- used to be waitforever */
141 PSetCacheSize, /* 24 */
142 PRemoveCallBack, /* 25 -- flush only the callback */
145 PRemoveMount, /* 28 -- delete mount point */
146 PNewStatMount, /* 29 -- new style mount point stat */
147 PGetFileCell, /* 30 -- get cell name for input file */
148 PGetWSCell, /* 31 -- get cell name for workstation */
149 PMariner, /* 32 - set/get mariner host */
150 PGetUserCell, /* 33 -- get cell name for user */
151 PVenusLogging, /* 34 -- Enable/Disable logging */
152 PGetCellStatus, /* 35 */
153 PSetCellStatus, /* 36 */
154 PFlushVolumeData, /* 37 -- flush all data from a volume */
155 PSetSysName, /* 38 - Set system name */
156 PExportAfs, /* 39 - Export Afs to remote nfs clients */
157 PGetCacheSize, /* 40 - get cache size and usage */
158 PGetVnodeXStatus, /* 41 - get vcache's special status */
159 PSetSPrefs33, /* 42 - Set CM Server preferences... */
160 PGetSPrefs, /* 43 - Get CM Server preferences... */
161 PGag, /* 44 - turn off/on all CM messages */
162 PTwiddleRx, /* 45 - adjust some RX params */
163 PSetSPrefs, /* 46 - Set CM Server preferences... */
164 PStoreBehind, /* 47 - set degree of store behind to be done */
165 PGCPAGs, /* 48 - disable automatic pag gc-ing */
166 PGetInitParams, /* 49 - get initial cm params */
167 PGetCPrefs, /* 50 - get client interface addresses */
168 PSetCPrefs, /* 51 - set client interface addresses */
169 PFlushMount, /* 52 - flush mount symlink data */
170 PRxStatProc, /* 53 - control process RX statistics */
171 PRxStatPeer, /* 54 - control peer RX statistics */
172 PGetRxkcrypt, /* 55 -- Get rxkad encryption flag */
173 PSetRxkcrypt, /* 56 -- Set rxkad encryption flag */
174 PBogus, /* 57 -- arla: set file prio */
175 PBogus, /* 58 -- arla: fallback getfh */
176 PBogus, /* 59 -- arla: fallback fhopen */
177 PBogus, /* 60 -- arla: controls xfsdebug */
178 PBogus, /* 61 -- arla: controls arla debug */
179 PBogus, /* 62 -- arla: debug interface */
180 PBogus, /* 63 -- arla: print xfs status */
181 PBogus, /* 64 -- arla: force cache check */
182 PBogus, /* 65 -- arla: break callback */
183 PPrefetchFromTape, /* 66 -- MR-AFS: prefetch file from tape */
184 PResidencyCmd, /* 67 -- MR-AFS: generic commnd interface */
185 PBogus, /* 68 -- arla: fetch stats */
188 static int (*(CpioctlSw[])) () = {
190 PNewAlias, /* 1 -- create new cell alias */
191 PListAliases, /* 2 -- list cell aliases */
192 PCallBackAddr, /* 3 -- request addr for callback rxcon */
195 #define PSetClientContext 99 /* Special pioctl to setup caller's creds */
196 int afs_nobody = NFS_NOBODY;
198 #if (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)) || defined(AFS_HPUX_64BIT_ENV) || defined(AFS_SUN57_64BIT_ENV) || (defined(AFS_SGI_ENV) && (_MIPS_SZLONG==64)) || (defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV))
200 afs_ioctl32_to_afs_ioctl(const struct afs_ioctl32 *src, struct afs_ioctl *dst)
202 dst->in = (char *)(unsigned long)src->in;
203 dst->out = (char *)(unsigned long)src->out;
204 dst->in_size = src->in_size;
205 dst->out_size = src->out_size;
210 * If you need to change copyin_afs_ioctl(), you may also need to change
215 copyin_afs_ioctl(caddr_t cmarg, struct afs_ioctl *dst)
218 #if defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)
219 struct afs_ioctl32 dst32;
222 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
224 afs_ioctl32_to_afs_ioctl(&dst32, dst);
227 #endif /* defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL) */
230 #if defined(AFS_HPUX_64BIT_ENV)
231 struct afs_ioctl32 dst32;
233 if (is_32bit(u.u_procp)) { /* is_32bit() in proc_iface.h */
234 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
236 afs_ioctl32_to_afs_ioctl(&dst32, dst);
239 #endif /* defined(AFS_HPUX_64BIT_ENV) */
241 #if defined(AFS_SUN57_64BIT_ENV)
242 struct afs_ioctl32 dst32;
244 if (get_udatamodel() == DATAMODEL_ILP32) {
245 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
247 afs_ioctl32_to_afs_ioctl(&dst32, dst);
250 #endif /* defined(AFS_SUN57_64BIT_ENV) */
252 #if defined(AFS_SGI_ENV) && (_MIPS_SZLONG==64)
253 struct afs_ioctl32 dst32;
255 if (!ABI_IS_64BIT(get_current_abi())) {
256 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
258 afs_ioctl32_to_afs_ioctl(&dst32, dst);
261 #endif /* defined(AFS_SGI_ENV) && (_MIPS_SZLONG==64) */
263 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)
264 struct afs_ioctl32 dst32;
266 #ifdef AFS_SPARC64_LINUX24_ENV
267 if (current->thread.flags & SPARC_FLAG_32BIT)
268 #elif defined(AFS_SPARC64_LINUX20_ENV)
269 if (current->tss.flags & SPARC_FLAG_32BIT)
271 #elif defined(AFS_AMD64_LINUX26_ENV)
272 if (test_thread_flag(TIF_IA32))
273 #elif defined(AFS_AMD64_LINUX20_ENV)
274 if (current->thread.flags & THREAD_IA32)
276 #elif defined(AFS_PPC64_LINUX26_ENV)
277 if (current->thread_info->flags & _TIF_32BIT)
278 #elif defined(AFS_PPC64_LINUX20_ENV)
279 if (current->thread.flags & PPC_FLAG_32BIT)
281 #elif defined(AFS_S390X_LINUX26_ENV)
282 if (test_thread_flag(TIF_31BIT))
283 #elif defined(AFS_S390X_LINUX20_ENV)
284 if (current->thread.flags & S390_FLAG_31BIT)
287 #error pioctl32 not done for this linux
290 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
292 afs_ioctl32_to_afs_ioctl(&dst32, dst);
295 #endif /* defined(AFS_LINUX_64BIT_KERNEL) */
297 AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code);
302 HandleIoctl(register struct vcache *avc, register afs_int32 acom,
303 struct afs_ioctl *adata)
305 register afs_int32 code;
308 AFS_STATCNT(HandleIoctl);
310 switch (acom & 0xff) {
312 avc->states |= CSafeStore;
316 /* case 2 used to be abort store, but this is no longer provided,
317 * since it is impossible to implement under normal Unix.
321 /* return the name of the cell this file is open on */
322 register struct cell *tcell;
323 register afs_int32 i;
325 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
327 i = strlen(tcell->cellName) + 1; /* bytes to copy out */
329 if (i > adata->out_size) {
330 /* 0 means we're not interested in the output */
331 if (adata->out_size != 0)
335 AFS_COPYOUT(tcell->cellName, adata->out, i, code);
337 afs_PutCell(tcell, READ_LOCK);
343 case 49: /* VIOC_GETINITPARAMS */
344 if (adata->out_size < sizeof(struct cm_initparams)) {
347 AFS_COPYOUT(&cm_initParams, adata->out,
348 sizeof(struct cm_initparams), code);
360 return code; /* so far, none implemented */
365 /* For aix we don't temporarily bypass ioctl(2) but rather do our
366 * thing directly in the vnode layer call, VNOP_IOCTL; thus afs_ioctl
367 * is now called from afs_gn_ioctl.
370 afs_ioctl(struct vcache *tvc, int cmd, int arg)
372 struct afs_ioctl data;
375 AFS_STATCNT(afs_ioctl);
376 if (((cmd >> 8) & 0xff) == 'V') {
377 /* This is a VICEIOCTL call */
378 AFS_COPYIN(arg, (caddr_t) & data, sizeof(data), error);
381 error = HandleIoctl(tvc, cmd, &data);
384 /* No-op call; just return. */
388 #endif /* AFS_AIX_ENV */
390 #if defined(AFS_SGI_ENV)
391 afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
394 , struct vopbd * vbds
398 struct afs_ioctl data;
404 AFS_STATCNT(afs_ioctl);
405 if (((cmd >> 8) & 0xff) == 'V') {
406 /* This is a VICEIOCTL call */
407 error = copyin_afs_ioctl(arg, &data);
410 locked = ISAFS_GLOCK();
413 error = HandleIoctl(tvc, cmd, &data);
418 /* No-op call; just return. */
422 #endif /* AFS_SGI_ENV */
424 /* unlike most calls here, this one uses u.u_error to return error conditions,
425 since this is really an intercepted chapter 2 call, rather than a vnode
428 /* AFS_HPUX102 and up uses VNODE ioctl instead */
429 #ifndef AFS_HPUX102_ENV
430 #if !defined(AFS_SGI_ENV)
434 kioctl(fdes, com, arg, ext, arg2, arg3)
435 #else /* __64BIT__ */
436 kioctl32(fdes, com, arg, ext, arg2, arg3)
437 #endif /* __64BIT__ */
440 kioctl(fdes, com, arg, ext)
451 } u_uap, *uap = &u_uap;
453 #if defined(AFS_SUN5_ENV)
455 struct afs_ioctl_sys {
462 struct afs_ioctl_sys *uap;
465 #elif defined(AFS_OSF_ENV)
466 afs_xioctl(p, args, retval)
475 } *uap = (struct a *)args;
476 #elif defined(AFS_FBSD50_ENV)
479 afs_xioctl(td, uap, retval)
481 register struct ioctl_args *uap;
484 struct proc *p = td->td_proc;
485 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
493 afs_xioctl(p, uap, retval)
495 register struct ioctl_args *uap;
498 #elif defined(AFS_LINUX22_ENV)
499 struct afs_ioctl_sys {
504 afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
507 struct afs_ioctl_sys ua, *uap = &ua;
516 } *uap = (struct a *)u.u_ap;
517 #endif /* AFS_SUN5_ENV */
519 #if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
521 #elif !defined(AFS_LINUX22_ENV)
522 register struct file *fd;
524 #if defined(AFS_XBSD_ENV)
525 register struct filedesc *fdp;
527 register struct vcache *tvc;
528 register int ioctlDone = 0, code = 0;
530 AFS_STATCNT(afs_xioctl);
531 #if defined(AFS_XBSD_ENV)
533 if ((u_int) uap->fd >= fdp->fd_nfiles
534 || (fd = fdp->fd_ofiles[uap->fd]) == NULL)
536 if ((fd->f_flag & (FREAD | FWRITE)) == 0)
538 #elif defined(AFS_DARWIN_ENV)
539 if ((code = fdgetf(p, uap->fd, &fd)))
541 #elif defined(AFS_LINUX22_ENV)
544 #elif defined(AFS_AIX32_ENV)
552 if (setuerror(getf(uap->fd, &fd))) {
555 #elif defined(AFS_OSF_ENV)
557 if (code = getf(&fd, uap->fd, FILE_FLAGS_NULL, &u.u_file_state))
559 #elif defined(AFS_SUN5_ENV)
560 # if defined(AFS_SUN57_ENV)
564 # elif defined(AFS_SUN54_ENV)
569 if (code = getf(uap->fd, &fd)) {
572 # endif /* AFS_SUN57_ENV */
578 /* first determine whether this is any sort of vnode */
579 #if defined(AFS_LINUX22_ENV)
584 if (fd->f_vnode->v_type == VREG || fd->f_vnode->v_type == VDIR) {
586 if (fd->f_type == DTYPE_VNODE) {
588 /* good, this is a vnode; next see if it is an AFS vnode */
589 #if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV)
590 tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */
591 #elif defined(AFS_OBSD_ENV)
593 IsAfsVnode((struct vnode *)fd->
594 f_data) ? VTOAFS((struct vnode *)fd->f_data) : NULL;
596 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
598 #endif /* AFS_LINUX22_ENV */
599 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
600 /* This is an AFS vnode */
601 if (((uap->com >> 8) & 0xff) == 'V') {
602 register struct afs_ioctl *datap;
605 (struct afs_ioctl *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
606 AFS_COPYIN((char *)uap->arg, (caddr_t) datap,
607 sizeof(struct afs_ioctl), code);
609 osi_FreeSmallSpace(datap);
611 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
614 #if defined(AFS_SUN5_ENV)
629 #else /* AFS_OSF_ENV */
633 #ifdef AFS_LINUX22_ENV
643 code = HandleIoctl(tvc, uap->com, datap);
644 osi_FreeSmallSpace(datap);
658 #if defined(AFS_LINUX22_ENV)
670 code = okioctl(fdes, com, arg, ext, arg2, arg3);
671 #else /* __64BIT__ */
672 code = okioctl32(fdes, com, arg, ext, arg2, arg3);
673 #endif /* __64BIT__ */
674 #else /* !AFS_AIX51_ENV */
675 code = okioctl(fdes, com, arg, ext);
676 #endif /* AFS_AIX51_ENV */
678 #else /* !AFS_AIX41_ENV */
680 okioctl(fdes, com, arg, ext);
681 #elif defined(AFS_SUN5_ENV)
682 #if defined(AFS_SUN57_ENV)
684 #elif defined(AFS_SUN54_ENV)
689 code = ioctl(uap, rvp);
690 #elif defined(AFS_FBSD50_ENV)
691 return ioctl(td, uap);
692 #elif defined(AFS_FBSD_ENV)
693 return ioctl(p, uap);
694 #elif defined(AFS_OBSD_ENV)
695 code = sys_ioctl(p, uap, retval);
696 #elif defined(AFS_DARWIN_ENV)
697 return ioctl(p, uap, retval);
698 #elif defined(AFS_OSF_ENV)
699 code = ioctl(p, args, retval);
706 #elif !defined(AFS_LINUX22_ENV)
720 #ifdef AFS_LINUX22_ENV
723 #if defined(KERNEL_HAVE_UERROR)
726 #if defined(AFS_AIX32_ENV) && !defined(AFS_AIX41_ENV)
727 return (getuerror()? -1 : u.u_ioctlrv);
729 return getuerror()? -1 : 0;
732 #endif /* AFS_LINUX22_ENV */
733 #endif /* AFS_SUN5_ENV */
734 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
738 #endif /* AFS_SGI_ENV */
739 #endif /* AFS_HPUX102_ENV */
741 #if defined(AFS_SGI_ENV)
742 /* "pioctl" system call entry point; just pass argument to the parameterized
751 afs_pioctl(struct pioctlargs *uap, rval_t * rvp)
755 AFS_STATCNT(afs_pioctl);
757 code = afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow);
766 #elif defined(AFS_OSF_ENV)
767 afs_pioctl(p, args, retval)
777 } *uap = (struct a *)args;
779 AFS_STATCNT(afs_pioctl);
780 return (afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow));
783 #elif defined(AFS_FBSD50_ENV)
785 afs_pioctl(td, args, retval)
795 } *uap = (struct a *)args;
797 AFS_STATCNT(afs_pioctl);
798 return (afs_syscall_pioctl
799 (uap->path, uap->cmd, uap->cmarg, uap->follow, td->td_ucred));
802 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
804 afs_pioctl(p, args, retval)
814 } *uap = (struct a *)args;
816 AFS_STATCNT(afs_pioctl);
817 return (afs_syscall_pioctl
818 (uap->path, uap->cmd, uap->cmarg, uap->follow,
819 p->p_cred->pc_ucred));
824 /* macro to avoid adding any more #ifdef's to pioctl code. */
825 #if defined(AFS_LINUX22_ENV) || defined(AFS_AIX41_ENV)
826 #define PIOCTL_FREE_CRED() crfree(credp)
828 #define PIOCTL_FREE_CRED()
833 afs_syscall_pioctl(path, com, cmarg, follow, rvp, credp)
835 struct AFS_UCRED *credp;
837 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
838 afs_syscall_pioctl(path, com, cmarg, follow, credp)
839 struct AFS_UCRED *credp;
841 afs_syscall_pioctl(path, com, cmarg, follow)
849 struct afs_ioctl data;
850 #ifdef AFS_NEED_CLIENTCONTEXT
851 struct AFS_UCRED *tmpcred;
853 struct AFS_UCRED *foreigncreds = NULL;
854 register afs_int32 code = 0;
855 struct vnode *vp = NULL;
857 struct ucred *credp = crref(); /* don't free until done! */
859 #ifdef AFS_LINUX22_ENV
860 cred_t *credp = crref(); /* don't free until done! */
864 AFS_STATCNT(afs_syscall_pioctl);
866 follow = 1; /* compat. with old venus */
867 code = copyin_afs_ioctl(cmarg, &data);
870 #if defined(KERNEL_HAVE_UERROR)
875 if ((com & 0xff) == PSetClientContext) {
876 #ifdef AFS_NEED_CLIENTCONTEXT
877 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV)
878 code = HandleClientContext(&data, &com, &foreigncreds, credp);
880 code = HandleClientContext(&data, &com, &foreigncreds, osi_curcred());
884 crfree(foreigncreds);
887 #if defined(KERNEL_HAVE_UERROR)
888 return (setuerror(code), code);
893 #else /* AFS_NEED_CLIENTCONTEXT */
895 #endif /* AFS_NEED_CLIENTCONTEXT */
897 #ifdef AFS_NEED_CLIENTCONTEXT
900 * We could have done without temporary setting the u.u_cred below
901 * (foreigncreds could be passed as param the pioctl modules)
902 * but calls such as afs_osi_suser() doesn't allow that since it
903 * references u.u_cred directly. We could, of course, do something
904 * like afs_osi_suser(cred) which, I think, is better since it
905 * generalizes and supports multi cred environments...
909 credp = foreigncreds;
910 #elif defined(AFS_AIX41_ENV)
911 tmpcred = crref(); /* XXX */
913 #elif defined(AFS_HPUX101_ENV)
914 tmpcred = p_cred(u.u_procp);
915 set_p_cred(u.u_procp, foreigncreds);
916 #elif defined(AFS_SGI_ENV)
917 tmpcred = OSI_GET_CURRENT_CRED();
918 OSI_SET_CURRENT_CRED(foreigncreds);
921 u.u_cred = foreigncreds;
924 #endif /* AFS_NEED_CLIENTCONTEXT */
925 if ((com & 0xff) == 15) {
926 /* special case prefetch so entire pathname eval occurs in helper process.
927 * otherwise, the pioctl call is essentially useless */
928 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
930 Prefetch(path, &data, follow,
931 foreigncreds ? foreigncreds : credp);
933 code = Prefetch(path, &data, follow, osi_curcred());
936 #if defined(KERNEL_HAVE_UERROR)
945 lookupname(path, USR, follow, NULL, &vp,
946 foreigncreds ? foreigncreds : credp);
948 #ifdef AFS_LINUX22_ENV
949 code = gop_lookupname(path, AFS_UIOUSER, follow, &dp);
951 vp = (struct vnode *)dp->d_inode;
953 code = gop_lookupname(path, AFS_UIOUSER, follow, &vp);
954 #endif /* AFS_LINUX22_ENV */
955 #endif /* AFS_AIX41_ENV */
959 #if defined(KERNEL_HAVE_UERROR)
967 /* now make the call if we were passed no file, or were passed an AFS file */
968 if (!vp || IsAfsVnode(vp)) {
969 #if 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 */
1011 #if defined(AFS_NEED_CLIENTCONTEXT)
1013 #ifdef AFS_AIX41_ENV
1014 crset(tmpcred); /* restore original credentials */
1016 #if defined(AFS_HPUX101_ENV)
1017 set_p_cred(u.u_procp, tmpcred); /* restore original credentials */
1018 #elif defined(AFS_SGI_ENV)
1019 OSI_SET_CURRENT_CRED(tmpcred); /* restore original credentials */
1020 #elif !defined(AFS_SUN5_ENV)
1021 osi_curcred() = tmpcred; /* restore original credentials */
1022 #endif /* AFS_HPUX101_ENV */
1023 crfree(foreigncreds);
1026 #endif /* AFS_NEED_CLIENTCONTEXT */
1028 #ifdef AFS_LINUX22_ENV
1031 AFS_RELE(vp); /* put vnode back */
1035 #if defined(KERNEL_HAVE_UERROR)
1038 return (getuerror());
1044 #define MAXPIOCTLTOKENLEN \
1045 (3*sizeof(afs_int32)+MAXKTCTICKETLEN+sizeof(struct ClearToken)+MAXKTCREALMLEN)
1048 afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
1049 register struct afs_ioctl *ablob, int afollow,
1050 struct AFS_UCRED **acred)
1053 struct vrequest treq;
1054 register afs_int32 code;
1055 register afs_int32 function, device;
1056 afs_int32 inSize, outSize, outSizeMax;
1057 char *inData, *outData;
1058 int (*(*pioctlSw)) ();
1060 struct afs_fakestat_state fakestate;
1062 avc = avp ? VTOAFS(avp) : NULL;
1063 afs_Trace3(afs_iclSetp, CM_TRACE_PIOCTL, ICL_TYPE_INT32, acom & 0xff,
1064 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, afollow);
1065 AFS_STATCNT(HandlePioctl);
1066 if ((code = afs_InitReq(&treq, *acred)))
1068 afs_InitFakeStat(&fakestate);
1070 code = afs_EvalFakeStat(&avc, &fakestate, &treq);
1072 afs_PutFakeStat(&fakestate);
1076 device = (acom & 0xff00) >> 8;
1078 case 'V': /* Original pioctls */
1079 pioctlSw = VpioctlSw;
1080 pioctlSwSize = sizeof(VpioctlSw);
1082 case 'C': /* Coordinated/common pioctls */
1083 pioctlSw = CpioctlSw;
1084 pioctlSwSize = sizeof(CpioctlSw);
1087 afs_PutFakeStat(&fakestate);
1090 function = acom & 0xff;
1091 if (function >= (pioctlSwSize / sizeof(char *))) {
1092 afs_PutFakeStat(&fakestate);
1093 return EINVAL; /* out of range */
1095 inSize = ablob->in_size;
1097 /* Do all range checking before continuing */
1098 if (inSize > MAXPIOCTLTOKENLEN || inSize < 0 || ablob->out_size < 0)
1101 /* Note that we use osi_Alloc for large allocs and osi_AllocLargeSpace for small ones */
1102 if (inSize > AFS_LRALLOCSIZ) {
1103 inData = osi_Alloc(inSize + 1);
1105 inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1110 AFS_COPYIN(ablob->in, inData, inSize, code);
1111 inData[inSize] = '\0';
1115 if (inSize > AFS_LRALLOCSIZ) {
1116 osi_Free(inData, inSize + 1);
1118 osi_FreeLargeSpace(inData);
1120 afs_PutFakeStat(&fakestate);
1123 if (function == 8 && device == 'V') { /* PGetTokens */
1124 outSizeMax = MAXPIOCTLTOKENLEN;
1125 outData = osi_Alloc(outSizeMax);
1127 outSizeMax = AFS_LRALLOCSIZ;
1128 outData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1131 if (inSize > AFS_LRALLOCSIZ) {
1132 osi_Free(inData, inSize + 1);
1134 osi_FreeLargeSpace(inData);
1136 afs_PutFakeStat(&fakestate);
1141 (*pioctlSw[function]) (avc, function, &treq, inData, outData, inSize,
1143 if (inSize > AFS_LRALLOCSIZ) {
1144 osi_Free(inData, inSize + 1);
1146 osi_FreeLargeSpace(inData);
1148 if (code == 0 && ablob->out_size > 0) {
1149 if (outSize > ablob->out_size) {
1150 code = E2BIG; /* data wont fit in user buffer */
1151 } else if (outSize) {
1152 AFS_COPYOUT(outData, ablob->out, outSize, code);
1155 if (outSizeMax > AFS_LRALLOCSIZ) {
1156 osi_Free(outData, outSizeMax);
1158 osi_FreeLargeSpace(outData);
1160 afs_PutFakeStat(&fakestate);
1161 return afs_CheckCode(code, &treq, 41);
1164 DECL_PIOCTL(PGetFID)
1166 AFS_STATCNT(PGetFID);
1169 memcpy(aout, (char *)&avc->fid, sizeof(struct VenusFid));
1170 *aoutSize = sizeof(struct VenusFid);
1174 DECL_PIOCTL(PSetAcl)
1176 register afs_int32 code;
1178 struct AFSOpaque acl;
1179 struct AFSVolSync tsync;
1180 struct AFSFetchStatus OutStatus;
1183 AFS_STATCNT(PSetAcl);
1186 if ((acl.AFSOpaque_len = strlen(ain) + 1) > 1000)
1189 acl.AFSOpaque_val = ain;
1191 tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1193 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREACL);
1196 RXAFS_StoreACL(tconn->id, (struct AFSFid *)&avc->fid.Fid,
1197 &acl, &OutStatus, &tsync);
1202 } while (afs_Analyze
1203 (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_STOREACL,
1204 SHARED_LOCK, NULL));
1206 /* now we've forgotten all of the access info */
1207 ObtainWriteLock(&afs_xcbhash, 455);
1209 afs_DequeueCallback(avc);
1210 avc->states &= ~(CStatd | CUnique);
1211 ReleaseWriteLock(&afs_xcbhash);
1212 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
1213 osi_dnlc_purgedp(avc);
1217 int afs_defaultAsynchrony = 0;
1219 DECL_PIOCTL(PStoreBehind)
1222 struct sbstruct *sbr;
1224 sbr = (struct sbstruct *)ain;
1225 if (sbr->sb_default != -1) {
1226 if (afs_osi_suser(*acred))
1227 afs_defaultAsynchrony = sbr->sb_default;
1232 if (avc && (sbr->sb_thisfile != -1)) {
1234 (avc, PRSFS_WRITE | PRSFS_ADMINISTER, areq, DONT_CHECK_MODE_BITS))
1235 avc->asynchrony = sbr->sb_thisfile;
1240 *aoutSize = sizeof(struct sbstruct);
1241 sbr = (struct sbstruct *)aout;
1242 sbr->sb_default = afs_defaultAsynchrony;
1244 sbr->sb_thisfile = avc->asynchrony;
1250 DECL_PIOCTL(PGCPAGs)
1252 if (!afs_osi_suser(*acred)) {
1255 afs_gcpags = AFS_GCPAGS_USERDISABLED;
1259 DECL_PIOCTL(PGetAcl)
1261 struct AFSOpaque acl;
1262 struct AFSVolSync tsync;
1263 struct AFSFetchStatus OutStatus;
1269 AFS_STATCNT(PGetAcl);
1272 Fid.Volume = avc->fid.Fid.Volume;
1273 Fid.Vnode = avc->fid.Fid.Vnode;
1274 Fid.Unique = avc->fid.Fid.Unique;
1275 if (avc->states & CForeign) {
1277 * For a dfs xlator acl we have a special hack so that the
1278 * xlator will distinguish which type of acl will return. So
1279 * we currently use the top 2-bytes (vals 0-4) to tell which
1280 * type of acl to bring back. Horrible hack but this will
1281 * cause the least number of changes to code size and interfaces.
1283 if (Fid.Vnode & 0xc0000000)
1285 Fid.Vnode |= (ainSize << 30);
1287 acl.AFSOpaque_val = aout;
1289 tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1292 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHACL);
1294 code = RXAFS_FetchACL(tconn->id, &Fid, &acl, &OutStatus, &tsync);
1299 } while (afs_Analyze
1300 (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_FETCHACL,
1301 SHARED_LOCK, NULL));
1304 *aoutSize = (acl.AFSOpaque_len == 0 ? 1 : acl.AFSOpaque_len);
1317 AFS_STATCNT(PBogus);
1321 DECL_PIOCTL(PGetFileCell)
1323 register struct cell *tcell;
1325 AFS_STATCNT(PGetFileCell);
1328 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
1331 strcpy(aout, tcell->cellName);
1332 afs_PutCell(tcell, READ_LOCK);
1333 *aoutSize = strlen(aout) + 1;
1337 DECL_PIOCTL(PGetWSCell)
1339 struct cell *tcell = NULL;
1341 AFS_STATCNT(PGetWSCell);
1342 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1343 return EIO; /* Inappropriate ioctl for device */
1345 tcell = afs_GetPrimaryCell(READ_LOCK);
1346 if (!tcell) /* no primary cell? */
1348 strcpy(aout, tcell->cellName);
1349 *aoutSize = strlen(aout) + 1;
1350 afs_PutCell(tcell, READ_LOCK);
1354 DECL_PIOCTL(PGetUserCell)
1356 register afs_int32 i;
1357 register struct unixuser *tu;
1358 register struct cell *tcell;
1360 AFS_STATCNT(PGetUserCell);
1361 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1362 return EIO; /* Inappropriate ioctl for device */
1364 /* return the cell name of the primary cell for this user */
1365 i = UHash(areq->uid);
1366 ObtainWriteLock(&afs_xuser, 224);
1367 for (tu = afs_users[i]; tu; tu = tu->next) {
1368 if (tu->uid == areq->uid && (tu->states & UPrimary)) {
1370 ReleaseWriteLock(&afs_xuser);
1375 tcell = afs_GetCell(tu->cell, READ_LOCK);
1376 afs_PutUser(tu, WRITE_LOCK);
1380 strcpy(aout, tcell->cellName);
1381 afs_PutCell(tcell, READ_LOCK);
1382 *aoutSize = strlen(aout) + 1; /* 1 for the null */
1385 ReleaseWriteLock(&afs_xuser);
1392 DECL_PIOCTL(PSetTokens)
1395 register struct unixuser *tu;
1396 struct ClearToken clear;
1397 register struct cell *tcell;
1400 struct vrequest treq;
1401 afs_int32 flag, set_parent_pag = 0;
1403 AFS_STATCNT(PSetTokens);
1404 if (!afs_resourceinit_flag) {
1407 memcpy((char *)&i, ain, sizeof(afs_int32));
1408 ain += sizeof(afs_int32);
1409 stp = ain; /* remember where the ticket is */
1410 if (i < 0 || i > MAXKTCTICKETLEN)
1411 return EINVAL; /* malloc may fail */
1413 ain += i; /* skip over ticket */
1414 memcpy((char *)&i, ain, sizeof(afs_int32));
1415 ain += sizeof(afs_int32);
1416 if (i != sizeof(struct ClearToken)) {
1419 memcpy((char *)&clear, ain, sizeof(struct ClearToken));
1420 if (clear.AuthHandle == -1)
1421 clear.AuthHandle = 999; /* more rxvab compat stuff */
1422 ain += sizeof(struct ClearToken);
1423 if (ainSize != 2 * sizeof(afs_int32) + stLen + sizeof(struct ClearToken)) {
1424 /* still stuff left? we've got primary flag and cell name. Set these */
1425 memcpy((char *)&flag, ain, sizeof(afs_int32)); /* primary id flag */
1426 ain += sizeof(afs_int32); /* skip id field */
1427 /* rest is cell name, look it up */
1428 /* some versions of gcc appear to need != 0 in order to get this right */
1429 if ((flag & 0x8000) != 0) { /* XXX Use Constant XXX */
1433 tcell = afs_GetCellByName(ain, READ_LOCK);
1437 /* default to primary cell, primary id */
1438 flag = 1; /* primary id */
1439 tcell = afs_GetPrimaryCell(READ_LOCK);
1444 afs_PutCell(tcell, READ_LOCK);
1445 if (set_parent_pag) {
1447 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1448 #if defined(AFS_DARWIN_ENV)
1449 struct proc *p = current_proc(); /* XXX */
1451 struct proc *p = curproc; /* XXX */
1453 uprintf("Process %d (%s) tried to change pags in PSetTokens\n",
1454 p->p_pid, p->p_comm);
1455 if (!setpag(p, acred, -1, &pag, 1)) {
1458 if (!setpag(u.u_procp, acred, -1, &pag, 1)) { /* XXX u.u_procp is a no-op XXX */
1460 if (!setpag(acred, -1, &pag, 1)) {
1463 afs_InitReq(&treq, *acred);
1467 /* now we just set the tokens */
1468 tu = afs_GetUser(areq->uid, i, WRITE_LOCK); /* i has the cell # */
1469 tu->vid = clear.ViceId;
1470 if (tu->stp != NULL) {
1471 afs_osi_Free(tu->stp, tu->stLen);
1473 tu->stp = (char *)afs_osi_Alloc(stLen);
1475 memcpy(tu->stp, stp, stLen);
1478 afs_stats_cmfullperf.authent.TicketUpdates++;
1479 afs_ComputePAGStats();
1480 #endif /* AFS_NOSTATS */
1481 tu->states |= UHasTokens;
1482 tu->states &= ~UTokensBad;
1483 afs_SetPrimary(tu, flag);
1484 tu->tokenTime = osi_Time();
1485 afs_ResetUserConns(tu);
1486 afs_PutUser(tu, WRITE_LOCK);
1501 DECL_PIOCTL(PGetVolumeStatus)
1504 char *offLineMsg = afs_osi_Alloc(256);
1505 char *motd = afs_osi_Alloc(256);
1506 register struct conn *tc;
1507 register afs_int32 code = 0;
1508 struct AFSFetchVolumeStatus volstat;
1510 char *Name, *OfflineMsg, *MOTD;
1513 AFS_STATCNT(PGetVolumeStatus);
1519 OfflineMsg = offLineMsg;
1522 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1524 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS);
1527 RXAFS_GetVolumeStatus(tc->id, avc->fid.Fid.Volume, &volstat,
1528 &Name, &OfflineMsg, &MOTD);
1533 } while (afs_Analyze
1534 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS,
1535 SHARED_LOCK, NULL));
1539 /* Copy all this junk into msg->im_data, keeping track of the lengths. */
1541 memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
1542 cp += sizeof(VolumeStatus);
1543 strcpy(cp, volName);
1544 cp += strlen(volName) + 1;
1545 strcpy(cp, offLineMsg);
1546 cp += strlen(offLineMsg) + 1;
1548 cp += strlen(motd) + 1;
1549 *aoutSize = (cp - aout);
1551 afs_osi_Free(offLineMsg, 256);
1552 afs_osi_Free(motd, 256);
1556 DECL_PIOCTL(PSetVolumeStatus)
1559 char *offLineMsg = afs_osi_Alloc(256);
1560 char *motd = afs_osi_Alloc(256);
1561 register struct conn *tc;
1562 register afs_int32 code = 0;
1563 struct AFSFetchVolumeStatus volstat;
1564 struct AFSStoreVolumeStatus storeStat;
1565 register struct volume *tvp;
1569 AFS_STATCNT(PSetVolumeStatus);
1575 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
1577 if (tvp->states & (VRO | VBackup)) {
1578 afs_PutVolume(tvp, READ_LOCK);
1582 afs_PutVolume(tvp, READ_LOCK);
1587 /* Copy the junk out, using cp as a roving pointer. */
1589 memcpy((char *)&volstat, cp, sizeof(AFSFetchVolumeStatus));
1590 cp += sizeof(AFSFetchVolumeStatus);
1591 if (strlen(cp) >= sizeof(volName)) {
1595 strcpy(volName, cp);
1596 cp += strlen(volName) + 1;
1597 if (strlen(cp) >= sizeof(offLineMsg)) {
1601 strcpy(offLineMsg, cp);
1602 cp += strlen(offLineMsg) + 1;
1603 if (strlen(cp) >= sizeof(motd)) {
1609 if (volstat.MinQuota != -1) {
1610 storeStat.MinQuota = volstat.MinQuota;
1611 storeStat.Mask |= AFS_SETMINQUOTA;
1613 if (volstat.MaxQuota != -1) {
1614 storeStat.MaxQuota = volstat.MaxQuota;
1615 storeStat.Mask |= AFS_SETMAXQUOTA;
1618 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1620 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS);
1623 RXAFS_SetVolumeStatus(tc->id, avc->fid.Fid.Volume, &storeStat,
1624 volName, offLineMsg, motd);
1629 } while (afs_Analyze
1630 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS,
1631 SHARED_LOCK, NULL));
1635 /* we are sending parms back to make compat. with prev system. should
1636 * change interface later to not ask for current status, just set new status */
1638 memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
1639 cp += sizeof(VolumeStatus);
1640 strcpy(cp, volName);
1641 cp += strlen(volName) + 1;
1642 strcpy(cp, offLineMsg);
1643 cp += strlen(offLineMsg) + 1;
1645 cp += strlen(motd) + 1;
1646 *aoutSize = cp - aout;
1648 afs_osi_Free(offLineMsg, 256);
1649 afs_osi_Free(motd, 256);
1655 AFS_STATCNT(PFlush);
1658 #ifdef AFS_BOZONLOCK_ENV
1659 afs_BozonLock(&avc->pvnLock, avc); /* Since afs_TryToSmush will do a pvn_vptrunc */
1661 ObtainWriteLock(&avc->lock, 225);
1662 ObtainWriteLock(&afs_xcbhash, 456);
1663 afs_DequeueCallback(avc);
1664 avc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
1665 ReleaseWriteLock(&afs_xcbhash);
1666 /* now find the disk cache entries */
1667 afs_TryToSmush(avc, *acred, 1);
1668 osi_dnlc_purgedp(avc);
1669 afs_symhint_inval(avc);
1670 if (avc->linkData && !(avc->states & CCore)) {
1671 afs_osi_Free(avc->linkData, strlen(avc->linkData) + 1);
1672 avc->linkData = NULL;
1674 ReleaseWriteLock(&avc->lock);
1675 #ifdef AFS_BOZONLOCK_ENV
1676 afs_BozonUnlock(&avc->pvnLock, avc);
1681 DECL_PIOCTL(PNewStatMount)
1683 register afs_int32 code;
1684 register struct vcache *tvc;
1685 register struct dcache *tdc;
1686 struct VenusFid tfid;
1688 struct sysname_info sysState;
1689 afs_size_t offset, len;
1691 AFS_STATCNT(PNewStatMount);
1694 code = afs_VerifyVCache(avc, areq);
1697 if (vType(avc) != VDIR) {
1700 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
1703 Check_AtSys(avc, ain, &sysState, areq);
1704 ObtainReadLock(&tdc->lock);
1706 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
1707 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
1708 ReleaseReadLock(&tdc->lock);
1709 afs_PutDCache(tdc); /* we're done with the data */
1710 bufp = sysState.name;
1714 tfid.Cell = avc->fid.Cell;
1715 tfid.Fid.Volume = avc->fid.Fid.Volume;
1716 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
1717 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
1719 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
1725 if (tvc->mvstat != 1) {
1730 ObtainWriteLock(&tvc->lock, 226);
1731 code = afs_HandleLink(tvc, areq);
1733 if (tvc->linkData) {
1734 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
1737 /* we have the data */
1738 strcpy(aout, tvc->linkData);
1739 *aoutSize = strlen(tvc->linkData) + 1;
1744 ReleaseWriteLock(&tvc->lock);
1747 if (sysState.allocked)
1748 osi_FreeLargeSpace(bufp);
1752 DECL_PIOCTL(PGetTokens)
1754 register struct cell *tcell;
1755 register afs_int32 i;
1756 register struct unixuser *tu;
1761 AFS_STATCNT(PGetTokens);
1762 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1763 return EIO; /* Inappropriate ioctl for device */
1765 /* weird interface. If input parameter is present, it is an integer and
1766 * we're supposed to return the parm'th tokens for this unix uid.
1767 * If not present, we just return tokens for cell 1.
1768 * If counter out of bounds, return EDOM.
1769 * If no tokens for the particular cell, return ENOTCONN.
1770 * Also, if this mysterious parm is present, we return, along with the
1771 * tokens, the primary cell indicator (an afs_int32 0) and the cell name
1772 * at the end, in that order.
1774 if ((newStyle = (ainSize > 0))) {
1775 memcpy((char *)&iterator, ain, sizeof(afs_int32));
1777 i = UHash(areq->uid);
1778 ObtainReadLock(&afs_xuser);
1779 for (tu = afs_users[i]; tu; tu = tu->next) {
1781 if (tu->uid == areq->uid && (tu->states & UHasTokens)) {
1782 if (iterator-- == 0)
1783 break; /* are we done yet? */
1786 if (tu->uid == areq->uid && afs_IsPrimaryCellNum(tu->cell))
1792 * No need to hold a read lock on each user entry
1796 ReleaseReadLock(&afs_xuser);
1801 if (((tu->states & UHasTokens) == 0)
1802 || (tu->ct.EndTimestamp < osi_Time())) {
1803 tu->states |= (UTokensBad | UNeedsReset);
1804 afs_PutUser(tu, READ_LOCK);
1807 /* use iterator for temp */
1809 iterator = tu->stLen; /* for compat, we try to return 56 byte tix if they fit */
1811 iterator = 56; /* # of bytes we're returning */
1812 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1813 cp += sizeof(afs_int32);
1814 memcpy(cp, tu->stp, tu->stLen); /* copy out st */
1816 iterator = sizeof(struct ClearToken);
1817 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1818 cp += sizeof(afs_int32);
1819 memcpy(cp, (char *)&tu->ct, sizeof(struct ClearToken));
1820 cp += sizeof(struct ClearToken);
1822 /* put out primary id and cell name, too */
1823 iterator = (tu->states & UPrimary ? 1 : 0);
1824 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1825 cp += sizeof(afs_int32);
1826 tcell = afs_GetCell(tu->cell, READ_LOCK);
1828 strcpy(cp, tcell->cellName);
1829 cp += strlen(tcell->cellName) + 1;
1830 afs_PutCell(tcell, READ_LOCK);
1834 *aoutSize = cp - aout;
1835 afs_PutUser(tu, READ_LOCK);
1841 register afs_int32 i;
1842 register struct unixuser *tu;
1844 AFS_STATCNT(PUnlog);
1845 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1846 return EIO; /* Inappropriate ioctl for device */
1848 i = UHash(areq->uid);
1849 ObtainWriteLock(&afs_xuser, 227);
1850 for (tu = afs_users[i]; tu; tu = tu->next) {
1851 if (tu->uid == areq->uid) {
1853 tu->states &= ~UHasTokens;
1854 /* security is not having to say you're sorry */
1855 memset((char *)&tu->ct, 0, sizeof(struct ClearToken));
1857 ReleaseWriteLock(&afs_xuser);
1858 /* We have to drop the lock over the call to afs_ResetUserConns, since
1859 * it obtains the afs_xvcache lock. We could also keep the lock, and
1860 * modify ResetUserConns to take parm saying we obtained the lock
1861 * already, but that is overkill. By keeping the "tu" pointer
1862 * held over the released lock, we guarantee that we won't lose our
1863 * place, and that we'll pass over every user conn that existed when
1864 * we began this call.
1866 afs_ResetUserConns(tu);
1868 ObtainWriteLock(&afs_xuser, 228);
1870 /* set the expire times to 0, causes
1871 * afs_GCUserData to remove this entry
1873 tu->ct.EndTimestamp = 0;
1875 #endif /* UKERNEL */
1878 ReleaseWriteLock(&afs_xuser);
1882 DECL_PIOCTL(PMariner)
1884 afs_int32 newHostAddr;
1885 afs_int32 oldHostAddr;
1887 AFS_STATCNT(PMariner);
1889 memcpy((char *)&oldHostAddr, (char *)&afs_marinerHost,
1892 oldHostAddr = 0xffffffff; /* disabled */
1894 memcpy((char *)&newHostAddr, ain, sizeof(afs_int32));
1895 if (newHostAddr == 0xffffffff) {
1896 /* disable mariner operations */
1898 } else if (newHostAddr) {
1900 afs_marinerHost = newHostAddr;
1902 memcpy(aout, (char *)&oldHostAddr, sizeof(afs_int32));
1903 *aoutSize = sizeof(afs_int32);
1907 DECL_PIOCTL(PCheckServers)
1909 register char *cp = 0;
1911 register struct server *ts;
1912 afs_int32 temp, *lp = (afs_int32 *) ain, havecell = 0;
1914 struct chservinfo *pcheck;
1916 AFS_STATCNT(PCheckServers);
1918 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1919 return EIO; /* Inappropriate ioctl for device */
1921 if (*lp == 0x12345678) { /* For afs3.3 version */
1922 pcheck = (struct chservinfo *)ain;
1923 if (pcheck->tinterval >= 0) {
1925 memcpy(cp, (char *)&PROBE_INTERVAL, sizeof(afs_int32));
1926 *aoutSize = sizeof(afs_int32);
1927 if (pcheck->tinterval > 0) {
1928 if (!afs_osi_suser(*acred))
1930 PROBE_INTERVAL = pcheck->tinterval;
1936 temp = pcheck->tflags;
1937 cp = pcheck->tbuffer;
1938 } else { /* For pre afs3.3 versions */
1939 memcpy((char *)&temp, ain, sizeof(afs_int32));
1940 cp = ain + sizeof(afs_int32);
1941 if (ainSize > sizeof(afs_int32))
1946 * 1: fast check, don't contact servers.
1947 * 2: local cell only.
1950 /* have cell name, too */
1951 cellp = afs_GetCellByName(cp, READ_LOCK);
1956 if (!cellp && (temp & 2)) {
1957 /* use local cell */
1958 cellp = afs_GetPrimaryCell(READ_LOCK);
1960 if (!(temp & 1)) { /* if not fast, call server checker routine */
1961 afs_CheckServers(1, cellp); /* check down servers */
1962 afs_CheckServers(0, cellp); /* check up servers */
1964 /* now return the current down server list */
1966 ObtainReadLock(&afs_xserver);
1967 for (i = 0; i < NSERVERS; i++) {
1968 for (ts = afs_servers[i]; ts; ts = ts->next) {
1969 if (cellp && ts->cell != cellp)
1970 continue; /* cell spec'd and wrong */
1971 if ((ts->flags & SRVR_ISDOWN)
1972 && ts->addr->sa_portal != ts->cell->vlport) {
1973 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
1974 cp += sizeof(afs_int32);
1978 ReleaseReadLock(&afs_xserver);
1980 afs_PutCell(cellp, READ_LOCK);
1981 *aoutSize = cp - aout;
1985 DECL_PIOCTL(PCheckVolNames)
1987 AFS_STATCNT(PCheckVolNames);
1988 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1989 return EIO; /* Inappropriate ioctl for device */
1991 afs_CheckRootVolume();
1992 afs_CheckVolumeNames(AFS_VOLCHECK_FORCE | AFS_VOLCHECK_EXPIRED |
1993 AFS_VOLCHECK_BUSY | AFS_VOLCHECK_MTPTS);
1997 DECL_PIOCTL(PCheckAuth)
2002 struct unixuser *tu;
2005 AFS_STATCNT(PCheckAuth);
2006 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2007 return EIO; /* Inappropriate ioctl for device */
2010 tu = afs_GetUser(areq->uid, 1, READ_LOCK); /* check local cell authentication */
2014 /* we have a user */
2015 ObtainReadLock(&afs_xsrvAddr);
2016 ObtainReadLock(&afs_xconn);
2018 /* any tokens set? */
2019 if ((tu->states & UHasTokens) == 0)
2021 /* all connections in cell 1 working? */
2022 for (i = 0; i < NSERVERS; i++) {
2023 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2024 for (tc = sa->conns; tc; tc = tc->next) {
2025 if (tc->user == tu && (tu->states & UTokensBad))
2030 ReleaseReadLock(&afs_xsrvAddr);
2031 ReleaseReadLock(&afs_xconn);
2032 afs_PutUser(tu, READ_LOCK);
2034 memcpy(aout, (char *)&retValue, sizeof(afs_int32));
2035 *aoutSize = sizeof(afs_int32);
2040 Prefetch(char *apath, struct afs_ioctl *adata, int afollow,
2041 struct AFS_UCRED *acred)
2044 register afs_int32 code;
2045 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2051 AFS_STATCNT(Prefetch);
2054 tp = osi_AllocLargeSpace(1024);
2055 AFS_COPYINSTR(apath, tp, 1024, &bufferSize, code);
2057 osi_FreeLargeSpace(tp);
2060 if (afs_BBusy()) { /* do this as late as possible */
2061 osi_FreeLargeSpace(tp);
2062 return EWOULDBLOCK; /* pretty close */
2064 afs_BQueue(BOP_PATH, (struct vcache *)0, 0, 0, acred, (afs_size_t) 0,
2065 (afs_size_t) 0, tp);
2069 DECL_PIOCTL(PFindVolume)
2071 register struct volume *tvp;
2072 register struct server *ts;
2073 register afs_int32 i;
2076 AFS_STATCNT(PFindVolume);
2079 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
2082 for (i = 0; i < MAXHOSTS; i++) {
2083 ts = tvp->serverHost[i];
2086 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
2087 cp += sizeof(afs_int32);
2090 /* still room for terminating NULL, add it on */
2091 ainSize = 0; /* reuse vbl */
2092 memcpy(cp, (char *)&ainSize, sizeof(afs_int32));
2093 cp += sizeof(afs_int32);
2095 *aoutSize = cp - aout;
2096 afs_PutVolume(tvp, READ_LOCK);
2102 DECL_PIOCTL(PViceAccess)
2104 register afs_int32 code;
2107 AFS_STATCNT(PViceAccess);
2110 code = afs_VerifyVCache(avc, areq);
2113 memcpy((char *)&temp, ain, sizeof(afs_int32));
2114 code = afs_AccessOK(avc, temp, areq, CHECK_MODE_BITS);
2121 DECL_PIOCTL(PSetCacheSize)
2126 AFS_STATCNT(PSetCacheSize);
2127 if (!afs_osi_suser(*acred))
2129 /* too many things are setup initially in mem cache version */
2130 if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
2132 memcpy((char *)&newValue, ain, sizeof(afs_int32));
2134 afs_cacheBlocks = afs_stats_cmperf.cacheBlocksOrig;
2136 if (newValue < afs_min_cache)
2137 afs_cacheBlocks = afs_min_cache;
2139 afs_cacheBlocks = newValue;
2141 afs_stats_cmperf.cacheBlocksTotal = afs_cacheBlocks;
2142 afs_ComputeCacheParms(); /* recompute basic cache parameters */
2143 afs_MaybeWakeupTruncateDaemon();
2144 while (waitcnt++ < 100 && afs_cacheBlocks < afs_blocksUsed) {
2145 afs_osi_Wait(1000, 0, 0);
2146 afs_MaybeWakeupTruncateDaemon();
2151 #define MAXGCSTATS 16
2152 DECL_PIOCTL(PGetCacheSize)
2154 afs_int32 results[MAXGCSTATS];
2156 AFS_STATCNT(PGetCacheSize);
2157 memset((char *)results, 0, sizeof(results));
2158 results[0] = afs_cacheBlocks;
2159 results[1] = afs_blocksUsed;
2160 memcpy(aout, (char *)results, sizeof(results));
2161 *aoutSize = sizeof(results);
2165 DECL_PIOCTL(PRemoveCallBack)
2167 register struct conn *tc;
2168 register afs_int32 code = 0;
2169 struct AFSCallBack CallBacks_Array[1];
2170 struct AFSCBFids theFids;
2171 struct AFSCBs theCBs;
2174 AFS_STATCNT(PRemoveCallBack);
2177 if (avc->states & CRO)
2178 return 0; /* read-only-ness can't change */
2179 ObtainWriteLock(&avc->lock, 229);
2180 theFids.AFSCBFids_len = 1;
2181 theCBs.AFSCBs_len = 1;
2182 theFids.AFSCBFids_val = (struct AFSFid *)&avc->fid.Fid;
2183 theCBs.AFSCBs_val = CallBacks_Array;
2184 CallBacks_Array[0].CallBackType = CB_DROPPED;
2185 if (avc->callback) {
2187 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2189 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
2191 code = RXAFS_GiveUpCallBacks(tc->id, &theFids, &theCBs);
2195 /* don't set code on failure since we wouldn't use it */
2196 } while (afs_Analyze
2197 (tc, code, &avc->fid, areq,
2198 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK, NULL));
2200 ObtainWriteLock(&afs_xcbhash, 457);
2201 afs_DequeueCallback(avc);
2203 avc->states &= ~(CStatd | CUnique);
2204 ReleaseWriteLock(&afs_xcbhash);
2205 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
2206 osi_dnlc_purgedp(avc);
2208 ReleaseWriteLock(&avc->lock);
2212 DECL_PIOCTL(PNewCell)
2214 /* create a new cell */
2215 afs_int32 cellHosts[MAXCELLHOSTS], *lp, magic = 0;
2216 char *newcell = 0, *linkedcell = 0, *tp = ain;
2217 register afs_int32 code, linkedstate = 0, ls;
2218 u_short fsport = 0, vlport = 0;
2221 AFS_STATCNT(PNewCell);
2222 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2223 return EIO; /* Inappropriate ioctl for device */
2225 if (!afs_osi_suser(*acred))
2228 memcpy((char *)&magic, tp, sizeof(afs_int32));
2229 tp += sizeof(afs_int32);
2230 if (magic != 0x12345678)
2233 /* A 3.4 fs newcell command will pass an array of MAXCELLHOSTS
2234 * server addresses while the 3.5 fs newcell command passes
2235 * MAXHOSTS. To figure out which is which, check if the cellname
2238 newcell = tp + (MAXCELLHOSTS + 3) * sizeof(afs_int32);
2239 scount = ((newcell[0] != '\0') ? MAXCELLHOSTS : MAXHOSTS);
2241 /* MAXCELLHOSTS (=8) is less than MAXHOSTS (=13) */
2242 memcpy((char *)cellHosts, tp, MAXCELLHOSTS * sizeof(afs_int32));
2243 tp += (scount * sizeof(afs_int32));
2245 lp = (afs_int32 *) tp;
2249 fsport = 0; /* Privileged ports not allowed */
2251 vlport = 0; /* Privileged ports not allowed */
2252 tp += (3 * sizeof(afs_int32));
2254 if ((ls = *lp) & 1) {
2255 linkedcell = tp + strlen(newcell) + 1;
2256 linkedstate |= CLinkedCell;
2259 linkedstate |= CNoSUID; /* setuid is disabled by default for fs newcell */
2261 afs_NewCell(newcell, cellHosts, linkedstate, linkedcell, fsport,
2266 DECL_PIOCTL(PNewAlias)
2268 /* create a new cell alias */
2270 register afs_int32 code;
2271 char *realName, *aliasName;
2273 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2274 return EIO; /* Inappropriate ioctl for device */
2276 if (!afs_osi_suser(*acred))
2280 tp += strlen(aliasName) + 1;
2283 code = afs_NewCellAlias(aliasName, realName);
2288 DECL_PIOCTL(PListCells)
2290 afs_int32 whichCell;
2291 register struct cell *tcell = 0;
2292 register afs_int32 i;
2293 register char *cp, *tp = ain;
2295 AFS_STATCNT(PListCells);
2296 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2297 return EIO; /* Inappropriate ioctl for device */
2299 memcpy((char *)&whichCell, tp, sizeof(afs_int32));
2300 tp += sizeof(afs_int32);
2301 tcell = afs_GetCellByIndex(whichCell, READ_LOCK);
2304 memset(cp, 0, MAXCELLHOSTS * sizeof(afs_int32));
2305 for (i = 0; i < MAXCELLHOSTS; i++) {
2306 if (tcell->cellHosts[i] == 0)
2308 memcpy(cp, (char *)&tcell->cellHosts[i]->addr->sa_ip,
2310 cp += sizeof(afs_int32);
2312 cp = aout + MAXCELLHOSTS * sizeof(afs_int32);
2313 strcpy(cp, tcell->cellName);
2314 cp += strlen(tcell->cellName) + 1;
2315 *aoutSize = cp - aout;
2316 afs_PutCell(tcell, READ_LOCK);
2324 DECL_PIOCTL(PListAliases)
2326 afs_int32 whichAlias;
2327 register struct cell_alias *tcalias = 0;
2328 register char *cp, *tp = ain;
2330 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2331 return EIO; /* Inappropriate ioctl for device */
2332 if (ainSize < sizeof(afs_int32))
2335 memcpy((char *)&whichAlias, tp, sizeof(afs_int32));
2336 tp += sizeof(afs_int32);
2338 tcalias = afs_GetCellAlias(whichAlias);
2341 strcpy(cp, tcalias->alias);
2342 cp += strlen(tcalias->alias) + 1;
2343 strcpy(cp, tcalias->cell);
2344 cp += strlen(tcalias->cell) + 1;
2345 *aoutSize = cp - aout;
2346 afs_PutCellAlias(tcalias);
2354 DECL_PIOCTL(PRemoveMount)
2356 register afs_int32 code;
2358 struct sysname_info sysState;
2359 afs_size_t offset, len;
2360 register struct conn *tc;
2361 register struct dcache *tdc;
2362 register struct vcache *tvc;
2363 struct AFSFetchStatus OutDirStatus;
2364 struct VenusFid tfid;
2365 struct AFSVolSync tsync;
2369 /* "ain" is the name of the file in this dir to remove */
2371 AFS_STATCNT(PRemoveMount);
2374 code = afs_VerifyVCache(avc, areq);
2377 if (vType(avc) != VDIR)
2380 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1); /* test for error below */
2383 Check_AtSys(avc, ain, &sysState, areq);
2384 ObtainReadLock(&tdc->lock);
2386 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
2387 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
2388 ReleaseReadLock(&tdc->lock);
2389 bufp = sysState.name;
2394 tfid.Cell = avc->fid.Cell;
2395 tfid.Fid.Volume = avc->fid.Fid.Volume;
2396 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
2397 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
2399 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
2406 if (tvc->mvstat != 1) {
2412 ObtainWriteLock(&tvc->lock, 230);
2413 code = afs_HandleLink(tvc, areq);
2415 if (tvc->linkData) {
2416 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
2421 ReleaseWriteLock(&tvc->lock);
2422 osi_dnlc_purgedp(tvc);
2428 ObtainWriteLock(&avc->lock, 231);
2429 osi_dnlc_remove(avc, bufp, tvc);
2431 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2433 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE);
2436 RXAFS_RemoveFile(tc->id, (struct AFSFid *)&avc->fid.Fid, bufp,
2437 &OutDirStatus, &tsync);
2442 } while (afs_Analyze
2443 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_REMOVEFILE,
2444 SHARED_LOCK, NULL));
2449 ReleaseWriteLock(&avc->lock);
2453 /* we have the thing in the cache */
2454 ObtainWriteLock(&tdc->lock, 661);
2455 if (afs_LocalHero(avc, tdc, &OutDirStatus, 1)) {
2456 /* we can do it locally */
2457 code = afs_dir_Delete(tdc, bufp);
2459 ZapDCE(tdc); /* surprise error -- invalid value */
2463 ReleaseWriteLock(&tdc->lock);
2464 afs_PutDCache(tdc); /* drop ref count */
2466 avc->states &= ~CUnique; /* For the dfs xlator */
2467 ReleaseWriteLock(&avc->lock);
2470 if (sysState.allocked)
2471 osi_FreeLargeSpace(bufp);
2475 DECL_PIOCTL(PVenusLogging)
2477 return EINVAL; /* OBSOLETE */
2480 DECL_PIOCTL(PGetCellStatus)
2482 register struct cell *tcell;
2485 AFS_STATCNT(PGetCellStatus);
2486 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2487 return EIO; /* Inappropriate ioctl for device */
2489 tcell = afs_GetCellByName(ain, READ_LOCK);
2492 temp = tcell->states;
2493 afs_PutCell(tcell, READ_LOCK);
2494 memcpy(aout, (char *)&temp, sizeof(afs_int32));
2495 *aoutSize = sizeof(afs_int32);
2499 DECL_PIOCTL(PSetCellStatus)
2501 register struct cell *tcell;
2504 if (!afs_osi_suser(*acred))
2506 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2507 return EIO; /* Inappropriate ioctl for device */
2509 tcell = afs_GetCellByName(ain + 2 * sizeof(afs_int32), WRITE_LOCK);
2512 memcpy((char *)&temp, ain, sizeof(afs_int32));
2514 tcell->states |= CNoSUID;
2516 tcell->states &= ~CNoSUID;
2517 afs_PutCell(tcell, WRITE_LOCK);
2521 DECL_PIOCTL(PFlushVolumeData)
2523 register afs_int32 i;
2524 register struct dcache *tdc;
2525 register struct vcache *tvc;
2526 register struct volume *tv;
2527 afs_int32 cell, volume;
2529 AFS_STATCNT(PFlushVolumeData);
2532 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2533 return EIO; /* Inappropriate ioctl for device */
2535 volume = avc->fid.Fid.Volume; /* who to zap */
2536 cell = avc->fid.Cell;
2539 * Clear stat'd flag from all vnodes from this volume; this will invalidate all
2540 * the vcaches associated with the volume.
2542 ObtainReadLock(&afs_xvcache);
2543 for (i = 0; i < VCSIZE; i++) {
2544 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2545 if (tvc->fid.Fid.Volume == volume && tvc->fid.Cell == cell) {
2546 #if defined(AFS_SGI_ENV) || defined(AFS_OSF_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
2547 VN_HOLD(AFSTOV(tvc));
2549 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2552 VREFCOUNT_INC(tvc); /* AIX, apparently */
2555 ReleaseReadLock(&afs_xvcache);
2556 #ifdef AFS_BOZONLOCK_ENV
2557 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
2559 ObtainWriteLock(&tvc->lock, 232);
2561 ObtainWriteLock(&afs_xcbhash, 458);
2562 afs_DequeueCallback(tvc);
2563 tvc->states &= ~(CStatd | CDirty);
2564 ReleaseWriteLock(&afs_xcbhash);
2565 if (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
2566 osi_dnlc_purgedp(tvc);
2567 afs_TryToSmush(tvc, *acred, 1);
2568 ReleaseWriteLock(&tvc->lock);
2569 #ifdef AFS_BOZONLOCK_ENV
2570 afs_BozonUnlock(&tvc->pvnLock, tvc);
2572 ObtainReadLock(&afs_xvcache);
2573 /* our tvc ptr is still good until now */
2578 ReleaseReadLock(&afs_xvcache);
2581 MObtainWriteLock(&afs_xdcache, 328); /* needed if you're going to flush any stuff */
2582 for (i = 0; i < afs_cacheFiles; i++) {
2583 if (!(afs_indexFlags[i] & IFEverUsed))
2584 continue; /* never had any data */
2585 tdc = afs_GetDSlot(i, NULL);
2586 if (tdc->refCount <= 1) { /* too high, in use by running sys call */
2587 ReleaseReadLock(&tdc->tlock);
2588 if (tdc->f.fid.Fid.Volume == volume && tdc->f.fid.Cell == cell) {
2589 if (!(afs_indexFlags[i] & IFDataMod)) {
2590 /* if the file is modified, but has a ref cnt of only 1, then
2591 * someone probably has the file open and is writing into it.
2592 * Better to skip flushing such a file, it will be brought back
2593 * immediately on the next write anyway.
2595 * If we *must* flush, then this code has to be rearranged to call
2596 * afs_storeAllSegments() first */
2597 afs_FlushDCache(tdc);
2601 ReleaseReadLock(&tdc->tlock);
2603 afs_PutDCache(tdc); /* bumped by getdslot */
2605 MReleaseWriteLock(&afs_xdcache);
2607 ObtainReadLock(&afs_xvolume);
2608 for (i = 0; i < NVOLS; i++) {
2609 for (tv = afs_volumes[i]; tv; tv = tv->next) {
2610 if (tv->volume == volume) {
2611 afs_ResetVolumeInfo(tv);
2616 ReleaseReadLock(&afs_xvolume);
2618 /* probably, a user is doing this, probably, because things are screwed up.
2619 * maybe it's the dnlc's fault? */
2626 DECL_PIOCTL(PGetVnodeXStatus)
2628 register afs_int32 code;
2629 struct vcxstat stat;
2632 /* AFS_STATCNT(PGetVnodeXStatus); */
2635 code = afs_VerifyVCache(avc, areq);
2638 if (vType(avc) == VDIR)
2639 mode = PRSFS_LOOKUP;
2642 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
2644 stat.fid = avc->fid;
2645 hset32(stat.DataVersion, hgetlo(avc->m.DataVersion));
2646 stat.lock = avc->lock;
2647 stat.parentVnode = avc->parentVnode;
2648 stat.parentUnique = avc->parentUnique;
2649 hset(stat.flushDV, avc->flushDV);
2650 hset(stat.mapDV, avc->mapDV);
2651 stat.truncPos = avc->truncPos;
2652 { /* just grab the first two - won't break anything... */
2653 struct axscache *ac;
2655 for (i = 0, ac = avc->Access; ac && i < CPSIZE; i++, ac = ac->next) {
2656 stat.randomUid[i] = ac->uid;
2657 stat.randomAccess[i] = ac->axess;
2660 stat.callback = afs_data_pointer_to_int32(avc->callback);
2661 stat.cbExpires = avc->cbExpires;
2662 stat.anyAccess = avc->anyAccess;
2663 stat.opens = avc->opens;
2664 stat.execsOrWriters = avc->execsOrWriters;
2665 stat.flockCount = avc->flockCount;
2666 stat.mvstat = avc->mvstat;
2667 stat.states = avc->states;
2668 memcpy(aout, (char *)&stat, sizeof(struct vcxstat));
2669 *aoutSize = sizeof(struct vcxstat);
2674 /* We require root for local sysname changes, but not for remote */
2675 /* (since we don't really believe remote uids anyway) */
2676 /* outname[] shouldn't really be needed- this is left as an excercise */
2677 /* for the reader. */
2678 DECL_PIOCTL(PSetSysName)
2680 char *cp, *cp2 = NULL, inname[MAXSYSNAME], outname[MAXSYSNAME];
2681 int setsysname, foundname = 0;
2682 register struct afs_exporter *exporter;
2683 register struct unixuser *au;
2684 register afs_int32 pag, error;
2685 int t, count, num = 0;
2686 char **sysnamelist[MAXSYSNAME];
2688 AFS_STATCNT(PSetSysName);
2689 if (!afs_globalVFS) {
2690 /* Afsd is NOT running; disable it */
2691 #if defined(KERNEL_HAVE_UERROR)
2692 return (setuerror(EINVAL), EINVAL);
2697 memset(inname, 0, MAXSYSNAME);
2698 memcpy((char *)&setsysname, ain, sizeof(afs_int32));
2699 ain += sizeof(afs_int32);
2703 if (setsysname < 0 || setsysname > MAXNUMSYSNAMES)
2706 for (cp = ain, count = 0; count < setsysname; count++) {
2707 /* won't go past end of ain since maxsysname*num < ain length */
2709 if (t >= MAXSYSNAME || t <= 0)
2711 /* check for names that can shoot us in the foot */
2712 if (*cp == '.' && (cp[1] == 0 || (cp[1] == '.' && cp[2] == 0)))
2718 /* inname gets first entry in case we're being a translator */
2720 memcpy(inname, ain, t + 1); /* include terminating null */
2724 if ((*acred)->cr_gid == RMTUSER_REQ) { /* Handles all exporters */
2725 pag = PagInCred(*acred);
2727 return EINVAL; /* Better than panicing */
2729 if (!(au = afs_FindUser(pag, -1, READ_LOCK))) {
2730 return EINVAL; /* Better than panicing */
2732 if (!(exporter = au->exporter)) {
2733 afs_PutUser(au, READ_LOCK);
2734 return EINVAL; /* Better than panicing */
2736 error = EXP_SYSNAME(exporter, (setsysname ? cp2 : NULL), sysnamelist,
2739 if (error == ENODEV)
2740 foundname = 0; /* sysname not set yet! */
2742 afs_PutUser(au, READ_LOCK);
2747 strcpy(outname, (*sysnamelist)[0]);
2749 afs_PutUser(au, READ_LOCK);
2751 /* Not xlating, so local case */
2753 osi_Panic("PSetSysName: !afs_sysname\n");
2754 if (!setsysname) { /* user just wants the info */
2755 strcpy(outname, afs_sysname);
2756 foundname = afs_sysnamecount;
2757 *sysnamelist = afs_sysnamelist;
2758 } else { /* Local guy; only root can change sysname */
2759 if (!afs_osi_suser(*acred))
2762 /* clear @sys entries from the dnlc, once afs_lookup can
2763 * do lookups of @sys entries and thinks it can trust them */
2764 /* privs ok, store the entry, ... */
2765 strcpy(afs_sysname, inname);
2766 if (setsysname > 1) { /* ... or list */
2768 for (count = 1; count < setsysname; ++count) {
2769 if (!afs_sysnamelist[count])
2771 ("PSetSysName: no afs_sysnamelist entry to write\n");
2773 memcpy(afs_sysnamelist[count], cp, t + 1); /* include null */
2777 afs_sysnamecount = setsysname;
2781 cp = aout; /* not changing so report back the count and ... */
2782 memcpy(cp, (char *)&foundname, sizeof(afs_int32));
2783 cp += sizeof(afs_int32);
2785 strcpy(cp, outname); /* ... the entry, ... */
2786 cp += strlen(outname) + 1;
2787 for (count = 1; count < foundname; ++count) { /* ... or list. */
2788 if (!(*sysnamelist)[count])
2790 ("PSetSysName: no afs_sysnamelist entry to read\n");
2791 t = strlen((*sysnamelist)[count]);
2792 if (t >= MAXSYSNAME)
2793 osi_Panic("PSetSysName: sysname entry garbled\n");
2794 strcpy(cp, (*sysnamelist)[count]);
2798 *aoutSize = cp - aout;
2803 /* sequential search through the list of touched cells is not a good
2804 * long-term solution here. For small n, though, it should be just
2805 * fine. Should consider special-casing the local cell for large n.
2806 * Likewise for PSetSPrefs.
2808 * s - number of ids in array l[] -- NOT index of last id
2809 * l - array of cell ids which have volumes that need to be sorted
2810 * vlonly - sort vl servers or file servers?
2813 ReSortCells_cb(struct cell *cell, void *arg)
2815 afs_int32 *p = (afs_int32 *) arg;
2816 afs_int32 *l = p + 1;
2819 for (i = 0; i < s; i++) {
2820 if (l[i] == cell->cellNum) {
2821 ObtainWriteLock(&cell->lock, 690);
2822 afs_SortServers(cell->cellHosts, MAXCELLHOSTS);
2823 ReleaseWriteLock(&cell->lock);
2831 ReSortCells(int s, afs_int32 * l, int vlonly)
2839 p = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * (s + 1));
2841 memcpy(p + 1, l, s * sizeof(afs_int32));
2842 afs_TraverseCells(&ReSortCells_cb, p);
2843 afs_osi_Free(p, sizeof(afs_int32) * (s + 1));
2847 ObtainReadLock(&afs_xvolume);
2848 for (i = 0; i < NVOLS; i++) {
2849 for (j = afs_volumes[i]; j; j = j->next) {
2850 for (k = 0; k < s; k++)
2851 if (j->cell == l[k]) {
2852 ObtainWriteLock(&j->lock, 233);
2853 afs_SortServers(j->serverHost, MAXHOSTS);
2854 ReleaseWriteLock(&j->lock);
2859 ReleaseReadLock(&afs_xvolume);
2863 static int debugsetsp = 0;
2865 afs_setsprefs(sp, num, vlonly)
2868 unsigned int vlonly;
2871 int i, j, k, matches, touchedSize;
2872 struct server *srvr = NULL;
2873 afs_int32 touched[34];
2877 for (k = 0; k < num; sp++, k++) {
2879 printf("sp host=%x, rank=%d\n", sp->host.s_addr, sp->rank);
2882 ObtainReadLock(&afs_xserver);
2884 i = SHash(sp->host.s_addr);
2885 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2886 if (sa->sa_ip == sp->host.s_addr) {
2888 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
2889 || (sa->sa_portal == AFS_FSPORT);
2890 if ((!vlonly && isfs) || (vlonly && !isfs)) {
2897 if (sa && matches) { /* found one! */
2899 printf("sa ip=%x, ip_rank=%d\n", sa->sa_ip, sa->sa_iprank);
2901 sa->sa_iprank = sp->rank + afs_randomMod15();
2902 afs_SortOneServer(sa->server);
2905 /* if we don't know yet what cell it's in, this is moot */
2906 for (j = touchedSize - 1;
2907 j >= 0 && touched[j] != srvr->cell->cellNum; j--)
2908 /* is it in our list of touched cells ? */ ;
2909 if (j < 0) { /* no, it's not */
2910 touched[touchedSize++] = srvr->cell->cellNum;
2911 if (touchedSize >= 32) { /* watch for ovrflow */
2912 ReleaseReadLock(&afs_xserver);
2913 ReSortCells(touchedSize, touched, vlonly);
2915 ObtainReadLock(&afs_xserver);
2921 ReleaseReadLock(&afs_xserver);
2922 /* if we didn't find one, start to create one. */
2923 /* Note that it doesn't have a cell yet... */
2925 afs_uint32 temp = sp->host.s_addr;
2927 afs_GetServer(&temp, 1, 0, (vlonly ? AFS_VLPORT : AFS_FSPORT),
2928 WRITE_LOCK, (afsUUID *) 0, 0);
2929 srvr->addr->sa_iprank = sp->rank + afs_randomMod15();
2930 afs_PutServer(srvr, WRITE_LOCK);
2932 } /* for all cited preferences */
2934 ReSortCells(touchedSize, touched, vlonly);
2938 /* Note that this may only be performed by the local root user.
2940 DECL_PIOCTL(PSetSPrefs)
2942 struct setspref *ssp;
2943 AFS_STATCNT(PSetSPrefs);
2945 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2946 return EIO; /* Inappropriate ioctl for device */
2948 if (!afs_osi_suser(*acred))
2951 if (ainSize < sizeof(struct setspref))
2954 ssp = (struct setspref *)ain;
2955 if (ainSize < sizeof(struct spref) * ssp->num_servers)
2958 afs_setsprefs(&(ssp->servers[0]), ssp->num_servers,
2959 (ssp->flags & DBservers));
2963 DECL_PIOCTL(PSetSPrefs33)
2966 AFS_STATCNT(PSetSPrefs);
2967 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2968 return EIO; /* Inappropriate ioctl for device */
2971 if (!afs_osi_suser(*acred))
2974 sp = (struct spref *)ain;
2975 afs_setsprefs(sp, ainSize / (sizeof(struct spref)), 0 /*!vlonly */ );
2979 /* some notes on the following code...
2980 * in the hash table of server structs, all servers with the same IP address
2981 * will be on the same overflow chain.
2982 * This could be sped slightly in some circumstances by having it cache the
2983 * immediately previous slot in the hash table and some supporting information
2984 * Only reports file servers now.
2986 DECL_PIOCTL(PGetSPrefs)
2988 struct sprefrequest *spin; /* input */
2989 struct sprefinfo *spout; /* output */
2990 struct spref *srvout; /* one output component */
2991 int i, j; /* counters for hash table traversal */
2992 struct server *srvr; /* one of CM's server structs */
2994 int vlonly; /* just return vlservers ? */
2997 AFS_STATCNT(PGetSPrefs);
2998 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2999 return EIO; /* Inappropriate ioctl for device */
3002 if (ainSize < sizeof(struct sprefrequest_33)) {
3005 spin = ((struct sprefrequest *)ain);
3008 if (ainSize > sizeof(struct sprefrequest_33)) {
3009 vlonly = (spin->flags & DBservers);
3013 /* struct sprefinfo includes 1 server struct... that size gets added
3014 * in during the loop that follows.
3016 *aoutSize = sizeof(struct sprefinfo) - sizeof(struct spref);
3017 spout = (struct sprefinfo *)aout;
3018 spout->next_offset = spin->offset;
3019 spout->num_servers = 0;
3020 srvout = spout->servers;
3022 ObtainReadLock(&afs_xserver);
3023 for (i = 0, j = 0; j < NSERVERS; j++) { /* sift through hash table */
3024 for (sa = afs_srvAddrs[j]; sa; sa = sa->next_bkt, i++) {
3025 if (spin->offset > (unsigned short)i) {
3026 continue; /* catch up to where we left off */
3028 spout->next_offset++;
3031 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
3032 || (sa->sa_portal == AFS_FSPORT);
3034 if ((vlonly && isfs) || (!vlonly && !isfs)) {
3035 /* only report ranks for vl servers */
3039 srvout->host.s_addr = sa->sa_ip;
3040 srvout->rank = sa->sa_iprank;
3041 *aoutSize += sizeof(struct spref);
3042 spout->num_servers++;
3045 if (*aoutSize > (PIGGYSIZE - sizeof(struct spref))) {
3046 ReleaseReadLock(&afs_xserver); /* no more room! */
3051 ReleaseReadLock(&afs_xserver);
3053 spout->next_offset = 0; /* start over from the beginning next time */
3057 /* Enable/Disable the specified exporter. Must be root to disable an exporter */
3058 int afs_NFSRootOnly = 1;
3059 DECL_PIOCTL(PExportAfs)
3061 afs_int32 export, newint =
3062 0, type, changestate, handleValue, convmode, pwsync, smounts;
3063 register struct afs_exporter *exporter;
3065 AFS_STATCNT(PExportAfs);
3066 memcpy((char *)&handleValue, ain, sizeof(afs_int32));
3067 type = handleValue >> 24;
3072 exporter = exporter_find(type);
3074 export = handleValue & 3;
3075 changestate = handleValue & 0xff;
3076 smounts = (handleValue >> 2) & 3;
3077 pwsync = (handleValue >> 4) & 3;
3078 convmode = (handleValue >> 6) & 3;
3080 changestate = (handleValue >> 16) & 0x1;
3081 convmode = (handleValue >> 16) & 0x2;
3082 pwsync = (handleValue >> 16) & 0x4;
3083 smounts = (handleValue >> 16) & 0x8;
3084 export = handleValue & 0xff;
3087 /* Failed finding desired exporter; */
3091 handleValue = exporter->exp_states;
3092 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3093 *aoutSize = sizeof(afs_int32);
3095 if (!afs_osi_suser(*acred))
3096 return EACCES; /* Only superuser can do this */
3100 exporter->exp_states |= EXP_EXPORTED;
3102 exporter->exp_states &= ~EXP_EXPORTED;
3106 exporter->exp_states |= EXP_UNIXMODE;
3108 exporter->exp_states &= ~EXP_UNIXMODE;
3112 exporter->exp_states |= EXP_PWSYNC;
3114 exporter->exp_states &= ~EXP_PWSYNC;
3118 afs_NFSRootOnly = 0;
3119 exporter->exp_states |= EXP_SUBMOUNTS;
3121 afs_NFSRootOnly = 1;
3122 exporter->exp_states &= ~EXP_SUBMOUNTS;
3125 handleValue = exporter->exp_states;
3126 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3127 *aoutSize = sizeof(afs_int32);
3130 exporter->exp_states |= EXP_EXPORTED;
3132 exporter->exp_states &= ~EXP_EXPORTED;
3134 exporter->exp_states |= EXP_UNIXMODE;
3136 exporter->exp_states &= ~EXP_UNIXMODE;
3138 exporter->exp_states |= EXP_PWSYNC;
3140 exporter->exp_states &= ~EXP_PWSYNC;
3142 afs_NFSRootOnly = 0;
3143 exporter->exp_states |= EXP_SUBMOUNTS;
3145 afs_NFSRootOnly = 1;
3146 exporter->exp_states &= ~EXP_SUBMOUNTS;
3156 struct gaginfo *gagflags;
3158 if (!afs_osi_suser(*acred))
3161 gagflags = (struct gaginfo *)ain;
3162 afs_showflags = gagflags->showflags;
3168 DECL_PIOCTL(PTwiddleRx)
3170 struct rxparams *rxp;
3172 if (!afs_osi_suser(*acred))
3175 rxp = (struct rxparams *)ain;
3177 if (rxp->rx_initReceiveWindow)
3178 rx_initReceiveWindow = rxp->rx_initReceiveWindow;
3179 if (rxp->rx_maxReceiveWindow)
3180 rx_maxReceiveWindow = rxp->rx_maxReceiveWindow;
3181 if (rxp->rx_initSendWindow)
3182 rx_initSendWindow = rxp->rx_initSendWindow;
3183 if (rxp->rx_maxSendWindow)
3184 rx_maxSendWindow = rxp->rx_maxSendWindow;
3185 if (rxp->rxi_nSendFrags)
3186 rxi_nSendFrags = rxp->rxi_nSendFrags;
3187 if (rxp->rxi_nRecvFrags)
3188 rxi_nRecvFrags = rxp->rxi_nRecvFrags;
3189 if (rxp->rxi_OrphanFragSize)
3190 rxi_OrphanFragSize = rxp->rxi_OrphanFragSize;
3191 if (rxp->rx_maxReceiveSize) {
3192 rx_maxReceiveSize = rxp->rx_maxReceiveSize;
3193 rx_maxReceiveSizeUser = rxp->rx_maxReceiveSize;
3195 if (rxp->rx_MyMaxSendSize)
3196 rx_MyMaxSendSize = rxp->rx_MyMaxSendSize;
3201 DECL_PIOCTL(PGetInitParams)
3203 if (sizeof(struct cm_initparams) > PIGGYSIZE)
3206 memcpy(aout, (char *)&cm_initParams, sizeof(struct cm_initparams));
3207 *aoutSize = sizeof(struct cm_initparams);
3211 #ifdef AFS_SGI65_ENV
3212 /* They took crget() from us, so fake it. */
3217 cr = crdup(get_current_cred());
3218 memset((char *)cr, 0, sizeof(cred_t));
3219 #if CELL || CELL_PREPARE
3226 DECL_PIOCTL(PGetRxkcrypt)
3228 memcpy(aout, (char *)&cryptall, sizeof(afs_int32));
3229 *aoutSize = sizeof(afs_int32);
3233 DECL_PIOCTL(PSetRxkcrypt)
3237 if (!afs_osi_suser(*acred))
3239 if (ainSize != sizeof(afs_int32) || ain == NULL)
3241 memcpy((char *)&tmpval, ain, sizeof(afs_int32));
3242 /* if new mappings added later this will need to be changed */
3243 if (tmpval != 0 && tmpval != 1)
3249 #ifdef AFS_NEED_CLIENTCONTEXT
3251 * Create new credentials to correspond to a remote user with given
3252 * <hostaddr, uid, g0, g1>. This allows a server running as root to
3253 * provide pioctl (and other) services to foreign clients (i.e. nfs
3254 * clients) by using this call to `become' the client.
3257 #define PIOCTL_HEADER 6
3259 HandleClientContext(struct afs_ioctl *ablob, int *com,
3260 struct AFS_UCRED **acred, struct AFS_UCRED *credp)
3263 afs_uint32 hostaddr;
3264 afs_int32 uid, g0, g1, i, code, pag, exporter_type;
3265 struct afs_exporter *exporter, *outexporter;
3266 struct AFS_UCRED *newcred;
3267 struct unixuser *au;
3269 #if defined(AFS_SGIMP_ENV)
3270 osi_Assert(ISAFS_GLOCK());
3272 AFS_STATCNT(HandleClientContext);
3273 if (ablob->in_size < PIOCTL_HEADER * sizeof(afs_int32)) {
3274 /* Must at least include the PIOCTL_HEADER header words required by the protocol */
3275 return EINVAL; /* Too small to be good */
3277 ain = inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
3278 AFS_COPYIN(ablob->in, ain, PIOCTL_HEADER * sizeof(afs_int32), code);
3280 osi_FreeLargeSpace(inData);
3284 /* Extract information for remote user */
3285 hostaddr = *((afs_uint32 *) ain);
3286 ain += sizeof(hostaddr);
3287 uid = *((afs_uint32 *) ain);
3289 g0 = *((afs_uint32 *) ain);
3291 g1 = *((afs_uint32 *) ain);
3293 *com = *((afs_uint32 *) ain);
3294 ain += sizeof(afs_int32);
3295 exporter_type = *((afs_uint32 *) ain); /* In case we support more than NFS */
3298 * Of course, one must be root for most of these functions, but
3299 * we'll allow (for knfs) you to set things if the pag is 0 and
3300 * you're setting tokens or unlogging.
3303 if (!afs_osi_suser(credp)) {
3304 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
3305 /* Since SGI's suser() returns explicit failure after the call.. */
3308 /* check for acceptable opcodes for normal folks, which are, so far,
3309 * set tokens and unlog.
3311 if (i != 9 && i != 3 && i != 38 && i != 8) {
3312 osi_FreeLargeSpace(inData);
3317 ablob->in_size -= PIOCTL_HEADER * sizeof(afs_int32);
3318 ablob->in += PIOCTL_HEADER * sizeof(afs_int32);
3319 osi_FreeLargeSpace(inData);
3322 * We map uid 0 to nobody to match the mapping that the nfs
3323 * server does and to ensure that the suser() calls in the afs
3324 * code fails for remote client roots.
3326 uid = afs_nobody; /* NFS_NOBODY == -2 */
3329 #if defined(AFS_LINUX26_ENV)
3330 newcred->cr_group_info = groups_alloc(0);
3332 #ifdef AFS_AIX41_ENV
3335 newcred->cr_gid = RMTUSER_REQ;
3336 #ifdef AFS_AIX51_ENV
3337 newcred->cr_groupset.gs_union.un_groups[0] = g0;
3338 newcred->cr_groupset.gs_union.un_groups[1] = g1;
3340 newcred->cr_groups[0] = g0;
3341 newcred->cr_groups[1] = g1;
3344 newcred->cr_ngrps = 2;
3346 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV)
3347 newcred->cr_ngroups = 2;
3349 for (i = 2; i < NGROUPS; i++)
3350 newcred->cr_groups[i] = NOGROUP;
3353 #if !defined(AFS_OSF_ENV)
3354 afs_nfsclient_init(); /* before looking for exporter, ensure one exists */
3356 if (!(exporter = exporter_find(exporter_type))) {
3357 /* Exporter wasn't initialized or an invalid exporter type */
3361 if (exporter->exp_states & EXP_PWSYNC) {
3362 if (uid != credp->cr_uid) {
3364 return ENOEXEC; /* XXX Find a better errno XXX */
3367 newcred->cr_uid = uid; /* Only temporary */
3368 code = EXP_REQHANDLER(exporter, &newcred, hostaddr, &pag, &outexporter);
3369 /* The client's pag is the only unique identifier for it */
3370 newcred->cr_uid = pag;
3372 if (!code && *com == PSETPAG) {
3373 /* Special case for 'setpag' */
3374 afs_uint32 pagvalue = genpag();
3376 au = afs_GetUser(pagvalue, -1, WRITE_LOCK); /* a new unixuser struct */
3378 * Note that we leave the 'outexporter' struct held so it won't
3381 au->exporter = outexporter;
3382 if (ablob->out_size >= 4) {
3383 AFS_COPYOUT((char *)&pagvalue, ablob->out, sizeof(afs_int32),
3386 afs_PutUser(au, WRITE_LOCK);
3389 return PSETPAG; /* Special return for setpag */
3391 EXP_RELE(outexporter);
3395 #endif /* AFS_NEED_CLIENTCONTEXT */
3397 /* get all interface addresses of this client */
3399 DECL_PIOCTL(PGetCPrefs)
3401 struct sprefrequest *spin; /* input */
3402 struct sprefinfo *spout; /* output */
3403 struct spref *srvout; /* one output component */
3407 AFS_STATCNT(PGetCPrefs);
3408 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3409 return EIO; /* Inappropriate ioctl for device */
3411 if (ainSize < sizeof(struct sprefrequest))
3414 spin = (struct sprefrequest *)ain;
3415 spout = (struct sprefinfo *)aout;
3417 maxNumber = spin->num_servers; /* max addrs this time */
3418 srvout = spout->servers;
3420 ObtainReadLock(&afs_xinterface);
3422 /* copy out the client interface information from the
3423 ** kernel data structure "interface" to the output buffer
3425 for (i = spin->offset, j = 0; (i < afs_cb_interface.numberOfInterfaces)
3426 && (j < maxNumber); i++, j++, srvout++)
3427 srvout->host.s_addr = afs_cb_interface.addr_in[i];
3429 spout->num_servers = j;
3430 *aoutSize = sizeof(struct sprefinfo) + (j - 1) * sizeof(struct spref);
3432 if (i >= afs_cb_interface.numberOfInterfaces)
3433 spout->next_offset = 0; /* start from beginning again */
3435 spout->next_offset = spin->offset + j;
3437 ReleaseReadLock(&afs_xinterface);
3441 DECL_PIOCTL(PSetCPrefs)
3443 struct setspref *sin;
3446 AFS_STATCNT(PSetCPrefs);
3447 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3448 return EIO; /* Inappropriate ioctl for device */
3450 sin = (struct setspref *)ain;
3452 if (ainSize < sizeof(struct setspref))
3454 #if 0 /* num_servers is unsigned */
3455 if (sin->num_servers < 0)
3458 if (sin->num_servers > AFS_MAX_INTERFACE_ADDR)
3461 ObtainWriteLock(&afs_xinterface, 412);
3462 afs_cb_interface.numberOfInterfaces = sin->num_servers;
3463 for (i = 0; (unsigned short)i < sin->num_servers; i++)
3464 afs_cb_interface.addr_in[i] = sin->servers[i].host.s_addr;
3466 ReleaseWriteLock(&afs_xinterface);
3470 DECL_PIOCTL(PFlushMount)
3472 register afs_int32 code;
3473 register struct vcache *tvc;
3474 register struct dcache *tdc;
3475 struct VenusFid tfid;
3477 struct sysname_info sysState;
3478 afs_size_t offset, len;
3480 AFS_STATCNT(PFlushMount);
3483 code = afs_VerifyVCache(avc, areq);
3486 if (vType(avc) != VDIR) {
3489 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
3492 Check_AtSys(avc, ain, &sysState, areq);
3493 ObtainReadLock(&tdc->lock);
3495 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
3496 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
3497 ReleaseReadLock(&tdc->lock);
3498 afs_PutDCache(tdc); /* we're done with the data */
3499 bufp = sysState.name;
3503 tfid.Cell = avc->fid.Cell;
3504 tfid.Fid.Volume = avc->fid.Fid.Volume;
3505 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
3506 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
3508 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3514 if (tvc->mvstat != 1) {
3519 #ifdef AFS_BOZONLOCK_ENV
3520 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
3522 ObtainWriteLock(&tvc->lock, 649);
3523 ObtainWriteLock(&afs_xcbhash, 650);
3524 afs_DequeueCallback(tvc);
3525 tvc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
3526 ReleaseWriteLock(&afs_xcbhash);
3527 /* now find the disk cache entries */
3528 afs_TryToSmush(tvc, *acred, 1);
3529 osi_dnlc_purgedp(tvc);
3530 afs_symhint_inval(tvc);
3531 if (tvc->linkData && !(tvc->states & CCore)) {
3532 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
3533 tvc->linkData = NULL;
3535 ReleaseWriteLock(&tvc->lock);
3536 #ifdef AFS_BOZONLOCK_ENV
3537 afs_BozonUnlock(&tvc->pvnLock, tvc);
3541 if (sysState.allocked)
3542 osi_FreeLargeSpace(bufp);
3546 DECL_PIOCTL(PRxStatProc)
3551 if (!afs_osi_suser(*acred)) {
3555 if (ainSize != sizeof(afs_int32)) {
3559 memcpy((char *)&flags, ain, sizeof(afs_int32));
3560 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3564 if (flags & AFSCALL_RXSTATS_ENABLE) {
3565 rx_enableProcessRPCStats();
3567 if (flags & AFSCALL_RXSTATS_DISABLE) {
3568 rx_disableProcessRPCStats();
3570 if (flags & AFSCALL_RXSTATS_CLEAR) {
3571 rx_clearProcessRPCStats(AFS_RX_STATS_CLEAR_ALL);
3579 DECL_PIOCTL(PRxStatPeer)
3584 if (!afs_osi_suser(*acred)) {
3588 if (ainSize != sizeof(afs_int32)) {
3592 memcpy((char *)&flags, ain, sizeof(afs_int32));
3593 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3597 if (flags & AFSCALL_RXSTATS_ENABLE) {
3598 rx_enablePeerRPCStats();
3600 if (flags & AFSCALL_RXSTATS_DISABLE) {
3601 rx_disablePeerRPCStats();
3603 if (flags & AFSCALL_RXSTATS_CLEAR) {
3604 rx_clearPeerRPCStats(AFS_RX_STATS_CLEAR_ALL);
3611 DECL_PIOCTL(PPrefetchFromTape)
3613 register afs_int32 code, code1;
3616 struct rx_call *tcall;
3617 struct AFSVolSync tsync;
3618 struct AFSFetchStatus OutStatus;
3619 struct AFSCallBack CallBack;
3620 struct VenusFid tfid;
3624 AFS_STATCNT(PSetAcl);
3628 if (ain && (ainSize == 3 * sizeof(afs_int32)))
3629 Fid = (struct AFSFid *)ain;
3631 Fid = &avc->fid.Fid;
3632 tfid.Cell = avc->fid.Cell;
3633 tfid.Fid.Volume = Fid->Volume;
3634 tfid.Fid.Vnode = Fid->Vnode;
3635 tfid.Fid.Unique = Fid->Unique;
3637 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3639 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3640 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &avc->fid);
3643 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3644 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &tvc->fid);
3647 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3651 tcall = rx_NewCall(tc->id);
3653 StartRXAFS_FetchData(tcall, (struct AFSFid *)&tvc->fid.Fid, 0,
3656 bytes = rx_Read(tcall, (char *)aout, sizeof(afs_int32));
3658 EndRXAFS_FetchData(tcall, &OutStatus, &CallBack, &tsync);
3660 code1 = rx_EndCall(tcall, code);
3664 } while (afs_Analyze
3665 (tc, code, &tvc->fid, areq, AFS_STATS_FS_RPCIDX_RESIDENCYRPCS,
3666 SHARED_LOCK, NULL));
3667 /* This call is done only to have the callback things handled correctly */
3668 afs_FetchStatus(tvc, &tfid, areq, &OutStatus);
3672 *aoutSize = sizeof(afs_int32);
3677 DECL_PIOCTL(PResidencyCmd)
3679 register afs_int32 code;
3682 struct ResidencyCmdInputs *Inputs;
3683 struct ResidencyCmdOutputs *Outputs;
3684 struct VenusFid tfid;
3687 Inputs = (struct ResidencyCmdInputs *)ain;
3688 Outputs = (struct ResidencyCmdOutputs *)aout;
3691 if (!ain || ainSize != sizeof(struct ResidencyCmdInputs))
3696 Fid = &avc->fid.Fid;
3698 tfid.Cell = avc->fid.Cell;
3699 tfid.Fid.Volume = Fid->Volume;
3700 tfid.Fid.Vnode = Fid->Vnode;
3701 tfid.Fid.Unique = Fid->Unique;
3703 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3704 afs_Trace3(afs_iclSetp, CM_TRACE_RESIDCMD, ICL_TYPE_POINTER, tvc,
3705 ICL_TYPE_INT32, Inputs->command, ICL_TYPE_FID, &tfid);
3709 if (Inputs->command) {
3711 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3715 RXAFS_ResidencyCmd(tc->id, Fid, Inputs,
3716 (struct ResidencyCmdOutputs *)aout);
3720 } while (afs_Analyze
3721 (tc, code, &tvc->fid, areq,
3722 AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK, NULL));
3723 /* This call is done to have the callback things handled correctly */
3724 afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3725 } else { /* just a status request, return also link data */
3727 Outputs->code = afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3728 Outputs->chars[0] = 0;
3729 if (vType(tvc) == VLNK) {
3730 ObtainWriteLock(&tvc->lock, 555);
3731 if (afs_HandleLink(tvc, areq) == 0)
3732 strncpy((char *)&Outputs->chars, tvc->linkData, MAXCMDCHARS);
3733 ReleaseWriteLock(&tvc->lock);
3740 *aoutSize = sizeof(struct ResidencyCmdOutputs);
3745 DECL_PIOCTL(PCallBackAddr)
3748 afs_uint32 addr, code;
3754 struct unixuser *tu;
3755 struct srvAddr **addrs;
3757 /*AFS_STATCNT(PCallBackAddr); */
3758 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
3759 return EIO; /* Inappropriate ioctl for device */
3761 if (!afs_osi_suser(acred))
3764 if (ainSize < sizeof(afs_int32))
3767 memcpy(&addr, ain, sizeof(afs_int32));
3769 ObtainReadLock(&afs_xinterface);
3770 for (i = 0; (unsigned short)i < afs_cb_interface.numberOfInterfaces; i++) {
3771 if (afs_cb_interface.addr_in[i] == addr)
3775 ReleaseWriteLock(&afs_xinterface);
3777 if (afs_cb_interface.addr_in[i] != addr)
3780 ObtainReadLock(&afs_xserver); /* Necessary? */
3781 ObtainReadLock(&afs_xsrvAddr);
3784 for (i = 0; i < NSERVERS; i++) {
3785 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3790 addrs = afs_osi_Alloc(srvAddrCount * sizeof(*addrs));
3792 for (i = 0; i < NSERVERS; i++) {
3793 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3794 if (j >= srvAddrCount)
3800 ReleaseReadLock(&afs_xsrvAddr);
3801 ReleaseReadLock(&afs_xserver);
3803 for (i = 0; i < j; i++) {
3809 /* vlserver has no callback conn */
3810 if (sa->sa_portal == AFS_VLPORT) {
3814 if (!ts->cell) /* not really an active server, anyway, it must */
3815 continue; /* have just been added by setsprefs */
3817 /* get a connection, even if host is down; bumps conn ref count */
3818 tu = afs_GetUser(areq->uid, ts->cell->cellNum, SHARED_LOCK);
3819 tc = afs_ConnBySA(sa, ts->cell->fsport, ts->cell->cellNum, tu,
3820 1 /*force */ , 1 /*create */ , SHARED_LOCK);
3821 afs_PutUser(tu, SHARED_LOCK);
3825 if ((sa->sa_flags & SRVADDR_ISDOWN) || afs_HaveCallBacksFrom(ts)) {
3826 if (sa->sa_flags & SRVADDR_ISDOWN) {
3827 rx_SetConnDeadTime(tc->id, 3);
3829 #ifdef RX_ENABLE_LOCKS
3831 #endif /* RX_ENABLE_LOCKS */
3832 code = RXAFS_CallBackRxConnAddr(tc->id, &addr);
3833 #ifdef RX_ENABLE_LOCKS
3835 #endif /* RX_ENABLE_LOCKS */
3837 afs_PutConn(tc, SHARED_LOCK); /* done with it now */
3838 } /* Outer loop over addrs */
3839 #endif /* UKERNEL */