2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include "afs/param.h"
16 #include "afs/sysincludes.h" /* Standard vendor system headers */
18 #include "h/syscallargs.h"
21 #include "h/sysproto.h"
23 #include "afsincludes.h" /* Afs-based standard headers */
24 #include "afs/afs_stats.h" /* afs statistics */
26 #include "rx/rx_globals.h"
28 struct VenusFid afs_rootFid;
29 afs_int32 afs_waitForever = 0;
30 short afs_waitForeverCount = 0;
31 afs_int32 afs_showflags = GAGUSER | GAGCONSOLE; /* show all messages */
33 #define DECL_PIOCTL(x) static int x(struct vcache *avc, int afun, struct vrequest *areq, \
34 char *ain, char *aout, afs_int32 ainSize, afs_int32 *aoutSize, \
35 struct AFS_UCRED **acred)
37 /* Prototypes for pioctl routines */
40 DECL_PIOCTL(PStoreBehind);
45 DECL_PIOCTL(PGetFileCell);
46 DECL_PIOCTL(PGetWSCell);
47 DECL_PIOCTL(PGetUserCell);
48 DECL_PIOCTL(PSetTokens);
49 DECL_PIOCTL(PGetVolumeStatus);
50 DECL_PIOCTL(PSetVolumeStatus);
52 DECL_PIOCTL(PNewStatMount);
53 DECL_PIOCTL(PGetTokens);
55 DECL_PIOCTL(PMariner);
56 DECL_PIOCTL(PCheckServers);
57 DECL_PIOCTL(PCheckVolNames);
58 DECL_PIOCTL(PCheckAuth);
59 DECL_PIOCTL(PFindVolume);
60 DECL_PIOCTL(PViceAccess);
61 DECL_PIOCTL(PSetCacheSize);
62 DECL_PIOCTL(PGetCacheSize);
63 DECL_PIOCTL(PRemoveCallBack);
64 DECL_PIOCTL(PNewCell);
65 DECL_PIOCTL(PNewAlias);
66 DECL_PIOCTL(PListCells);
67 DECL_PIOCTL(PListAliases);
68 DECL_PIOCTL(PRemoveMount);
69 DECL_PIOCTL(PVenusLogging);
70 DECL_PIOCTL(PGetCellStatus);
71 DECL_PIOCTL(PSetCellStatus);
72 DECL_PIOCTL(PFlushVolumeData);
73 DECL_PIOCTL(PGetVnodeXStatus);
74 DECL_PIOCTL(PGetVnodeXStatus2);
75 DECL_PIOCTL(PSetSysName);
76 DECL_PIOCTL(PSetSPrefs);
77 DECL_PIOCTL(PSetSPrefs33);
78 DECL_PIOCTL(PGetSPrefs);
79 DECL_PIOCTL(PExportAfs);
81 DECL_PIOCTL(PTwiddleRx);
82 DECL_PIOCTL(PGetInitParams);
83 DECL_PIOCTL(PGetRxkcrypt);
84 DECL_PIOCTL(PSetRxkcrypt);
85 DECL_PIOCTL(PGetCPrefs);
86 DECL_PIOCTL(PSetCPrefs);
87 DECL_PIOCTL(PFlushMount);
88 DECL_PIOCTL(PRxStatProc);
89 DECL_PIOCTL(PRxStatPeer);
90 DECL_PIOCTL(PPrefetchFromTape);
91 DECL_PIOCTL(PResidencyCmd);
92 DECL_PIOCTL(PCallBackAddr);
95 * A macro that says whether we're going to need HandleClientContext().
96 * This is currently used only by the nfs translator.
98 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
99 #define AFS_NEED_CLIENTCONTEXT
102 /* Prototypes for private routines */
103 #ifdef AFS_NEED_CLIENTCONTEXT
104 static int HandleClientContext(struct afs_ioctl *ablob, int *com,
105 struct AFS_UCRED **acred,
106 struct AFS_UCRED *credp);
108 int HandleIoctl(register struct vcache *avc, register afs_int32 acom,
109 struct afs_ioctl *adata);
110 int afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
111 register struct afs_ioctl *ablob, int afollow,
112 struct AFS_UCRED **acred);
113 static int Prefetch(char *apath, struct afs_ioctl *adata, int afollow,
114 struct AFS_UCRED *acred);
117 static int (*(VpioctlSw[])) () = {
122 PGetVolumeStatus, /* 4 */
123 PSetVolumeStatus, /* 5 */
128 PCheckServers, /* 10 */
129 PCheckVolNames, /* 11 */
131 PBogus, /* 13 -- used to be quick check time */
132 PFindVolume, /* 14 */
133 PBogus, /* 15 -- prefetch is now special-cased; see pioctl code! */
134 PBogus, /* 16 -- used to be testing code */
135 PNoop, /* 17 -- used to be enable group */
136 PNoop, /* 18 -- used to be disable group */
137 PBogus, /* 19 -- used to be list group */
138 PViceAccess, /* 20 */
139 PUnlog, /* 21 -- unlog *is* unpag in this system */
140 PGetFID, /* 22 -- get file ID */
141 PBogus, /* 23 -- used to be waitforever */
142 PSetCacheSize, /* 24 */
143 PRemoveCallBack, /* 25 -- flush only the callback */
146 PRemoveMount, /* 28 -- delete mount point */
147 PNewStatMount, /* 29 -- new style mount point stat */
148 PGetFileCell, /* 30 -- get cell name for input file */
149 PGetWSCell, /* 31 -- get cell name for workstation */
150 PMariner, /* 32 - set/get mariner host */
151 PGetUserCell, /* 33 -- get cell name for user */
152 PVenusLogging, /* 34 -- Enable/Disable logging */
153 PGetCellStatus, /* 35 */
154 PSetCellStatus, /* 36 */
155 PFlushVolumeData, /* 37 -- flush all data from a volume */
156 PSetSysName, /* 38 - Set system name */
157 PExportAfs, /* 39 - Export Afs to remote nfs clients */
158 PGetCacheSize, /* 40 - get cache size and usage */
159 PGetVnodeXStatus, /* 41 - get vcache's special status */
160 PSetSPrefs33, /* 42 - Set CM Server preferences... */
161 PGetSPrefs, /* 43 - Get CM Server preferences... */
162 PGag, /* 44 - turn off/on all CM messages */
163 PTwiddleRx, /* 45 - adjust some RX params */
164 PSetSPrefs, /* 46 - Set CM Server preferences... */
165 PStoreBehind, /* 47 - set degree of store behind to be done */
166 PGCPAGs, /* 48 - disable automatic pag gc-ing */
167 PGetInitParams, /* 49 - get initial cm params */
168 PGetCPrefs, /* 50 - get client interface addresses */
169 PSetCPrefs, /* 51 - set client interface addresses */
170 PFlushMount, /* 52 - flush mount symlink data */
171 PRxStatProc, /* 53 - control process RX statistics */
172 PRxStatPeer, /* 54 - control peer RX statistics */
173 PGetRxkcrypt, /* 55 -- Get rxkad encryption flag */
174 PSetRxkcrypt, /* 56 -- Set rxkad encryption flag */
175 PBogus, /* 57 -- arla: set file prio */
176 PBogus, /* 58 -- arla: fallback getfh */
177 PBogus, /* 59 -- arla: fallback fhopen */
178 PBogus, /* 60 -- arla: controls xfsdebug */
179 PBogus, /* 61 -- arla: controls arla debug */
180 PBogus, /* 62 -- arla: debug interface */
181 PBogus, /* 63 -- arla: print xfs status */
182 PBogus, /* 64 -- arla: force cache check */
183 PBogus, /* 65 -- arla: break callback */
184 PPrefetchFromTape, /* 66 -- MR-AFS: prefetch file from tape */
185 PResidencyCmd, /* 67 -- MR-AFS: generic commnd interface */
186 PBogus, /* 68 -- arla: fetch stats */
187 PGetVnodeXStatus2, /* 69 - get caller access and some vcache status */
190 static int (*(CpioctlSw[])) () = {
192 PNewAlias, /* 1 -- create new cell alias */
193 PListAliases, /* 2 -- list cell aliases */
194 PCallBackAddr, /* 3 -- request addr for callback rxcon */
197 #define PSetClientContext 99 /* Special pioctl to setup caller's creds */
198 int afs_nobody = NFS_NOBODY;
200 #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(NEED_IOCTL32)
202 afs_ioctl32_to_afs_ioctl(const struct afs_ioctl32 *src, struct afs_ioctl *dst)
204 dst->in = (char *)(unsigned long)src->in;
205 dst->out = (char *)(unsigned long)src->out;
206 dst->in_size = src->in_size;
207 dst->out_size = src->out_size;
212 * If you need to change copyin_afs_ioctl(), you may also need to change
217 copyin_afs_ioctl(caddr_t cmarg, struct afs_ioctl *dst)
220 #if defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)
221 struct afs_ioctl32 dst32;
224 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
226 afs_ioctl32_to_afs_ioctl(&dst32, dst);
229 #endif /* defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL) */
232 #if defined(AFS_HPUX_64BIT_ENV)
233 struct afs_ioctl32 dst32;
235 if (is_32bit(u.u_procp)) { /* is_32bit() in proc_iface.h */
236 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
238 afs_ioctl32_to_afs_ioctl(&dst32, dst);
241 #endif /* defined(AFS_HPUX_64BIT_ENV) */
243 #if defined(AFS_SUN57_64BIT_ENV)
244 struct afs_ioctl32 dst32;
246 if (get_udatamodel() == DATAMODEL_ILP32) {
247 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
249 afs_ioctl32_to_afs_ioctl(&dst32, dst);
252 #endif /* defined(AFS_SUN57_64BIT_ENV) */
254 #if defined(AFS_SGI_ENV) && (_MIPS_SZLONG==64)
255 struct afs_ioctl32 dst32;
257 if (!ABI_IS_64BIT(get_current_abi())) {
258 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
260 afs_ioctl32_to_afs_ioctl(&dst32, dst);
263 #endif /* defined(AFS_SGI_ENV) && (_MIPS_SZLONG==64) */
265 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)
266 struct afs_ioctl32 dst32;
268 #ifdef AFS_SPARC64_LINUX26_ENV
269 if (test_thread_flag(TIF_32BIT))
270 #elif AFS_SPARC64_LINUX24_ENV
271 if (current->thread.flags & SPARC_FLAG_32BIT)
272 #elif defined(AFS_SPARC64_LINUX20_ENV)
273 if (current->tss.flags & SPARC_FLAG_32BIT)
275 #elif defined(AFS_AMD64_LINUX26_ENV)
276 if (test_thread_flag(TIF_IA32))
277 #elif defined(AFS_AMD64_LINUX20_ENV)
278 if (current->thread.flags & THREAD_IA32)
280 #elif defined(AFS_PPC64_LINUX26_ENV)
281 if (current->thread_info->flags & _TIF_32BIT)
282 #elif defined(AFS_PPC64_LINUX20_ENV)
283 if (current->thread.flags & PPC_FLAG_32BIT)
285 #elif defined(AFS_S390X_LINUX26_ENV)
286 if (test_thread_flag(TIF_31BIT))
287 #elif defined(AFS_S390X_LINUX20_ENV)
288 if (current->thread.flags & S390_FLAG_31BIT)
291 #error pioctl32 not done for this linux
294 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
296 afs_ioctl32_to_afs_ioctl(&dst32, dst);
299 #endif /* defined(AFS_LINUX_64BIT_KERNEL) */
301 AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code);
306 HandleIoctl(register struct vcache *avc, register afs_int32 acom,
307 struct afs_ioctl *adata)
309 register afs_int32 code;
312 AFS_STATCNT(HandleIoctl);
314 switch (acom & 0xff) {
316 avc->states |= CSafeStore;
320 /* case 2 used to be abort store, but this is no longer provided,
321 * since it is impossible to implement under normal Unix.
325 /* return the name of the cell this file is open on */
326 register struct cell *tcell;
327 register afs_int32 i;
329 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
331 i = strlen(tcell->cellName) + 1; /* bytes to copy out */
333 if (i > adata->out_size) {
334 /* 0 means we're not interested in the output */
335 if (adata->out_size != 0)
339 AFS_COPYOUT(tcell->cellName, adata->out, i, code);
341 afs_PutCell(tcell, READ_LOCK);
347 case 49: /* VIOC_GETINITPARAMS */
348 if (adata->out_size < sizeof(struct cm_initparams)) {
351 AFS_COPYOUT(&cm_initParams, adata->out,
352 sizeof(struct cm_initparams), code);
364 return code; /* so far, none implemented */
369 /* For aix we don't temporarily bypass ioctl(2) but rather do our
370 * thing directly in the vnode layer call, VNOP_IOCTL; thus afs_ioctl
371 * is now called from afs_gn_ioctl.
374 afs_ioctl(struct vcache *tvc, int cmd, int arg)
376 struct afs_ioctl data;
379 AFS_STATCNT(afs_ioctl);
380 if (((cmd >> 8) & 0xff) == 'V') {
381 /* This is a VICEIOCTL call */
382 AFS_COPYIN(arg, (caddr_t) & data, sizeof(data), error);
385 error = HandleIoctl(tvc, cmd, &data);
388 /* No-op call; just return. */
392 #endif /* AFS_AIX_ENV */
394 #if defined(AFS_SGI_ENV)
395 afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
398 , struct vopbd * vbds
402 struct afs_ioctl data;
408 AFS_STATCNT(afs_ioctl);
409 if (((cmd >> 8) & 0xff) == 'V') {
410 /* This is a VICEIOCTL call */
411 error = copyin_afs_ioctl(arg, &data);
414 locked = ISAFS_GLOCK();
417 error = HandleIoctl(tvc, cmd, &data);
422 /* No-op call; just return. */
426 #endif /* AFS_SGI_ENV */
428 /* unlike most calls here, this one uses u.u_error to return error conditions,
429 since this is really an intercepted chapter 2 call, rather than a vnode
432 /* AFS_HPUX102 and up uses VNODE ioctl instead */
433 #ifndef AFS_HPUX102_ENV
434 #if !defined(AFS_SGI_ENV)
438 kioctl(fdes, com, arg, ext, arg2, arg3)
439 #else /* __64BIT__ */
440 kioctl32(fdes, com, arg, ext, arg2, arg3)
441 #endif /* __64BIT__ */
444 kioctl(fdes, com, arg, ext)
455 } u_uap, *uap = &u_uap;
457 #if defined(AFS_SUN5_ENV)
459 struct afs_ioctl_sys {
466 struct afs_ioctl_sys *uap;
469 #elif defined(AFS_OSF_ENV)
470 afs_xioctl(p, args, retval)
479 } *uap = (struct a *)args;
480 #elif defined(AFS_FBSD50_ENV)
483 afs_xioctl(td, uap, retval)
485 register struct ioctl_args *uap;
488 struct proc *p = td->td_proc;
489 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
497 afs_xioctl(p, uap, retval)
499 register struct ioctl_args *uap;
502 #elif defined(AFS_LINUX22_ENV)
503 struct afs_ioctl_sys {
508 afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
511 struct afs_ioctl_sys ua, *uap = &ua;
520 } *uap = (struct a *)u.u_ap;
521 #endif /* AFS_SUN5_ENV */
523 #if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
525 #elif !defined(AFS_LINUX22_ENV)
526 register struct file *fd;
528 #if defined(AFS_XBSD_ENV)
529 register struct filedesc *fdp;
531 register struct vcache *tvc;
532 register int ioctlDone = 0, code = 0;
534 AFS_STATCNT(afs_xioctl);
535 #if defined(AFS_DARWIN_ENV)
536 if ((code = fdgetf(p, uap->fd, &fd)))
538 #elif defined(AFS_XBSD_ENV)
540 if ((u_int) uap->fd >= fdp->fd_nfiles
541 || (fd = fdp->fd_ofiles[uap->fd]) == NULL)
543 if ((fd->f_flag & (FREAD | FWRITE)) == 0)
545 #elif defined(AFS_LINUX22_ENV)
548 #elif defined(AFS_AIX32_ENV)
556 if (setuerror(getf(uap->fd, &fd))) {
559 #elif defined(AFS_OSF_ENV)
561 if (code = getf(&fd, uap->fd, FILE_FLAGS_NULL, &u.u_file_state))
563 #elif defined(AFS_SUN5_ENV)
564 # if defined(AFS_SUN57_ENV)
568 # elif defined(AFS_SUN54_ENV)
573 if (code = getf(uap->fd, &fd)) {
576 # endif /* AFS_SUN57_ENV */
582 /* first determine whether this is any sort of vnode */
583 #if defined(AFS_LINUX22_ENV)
588 if (fd->f_vnode->v_type == VREG || fd->f_vnode->v_type == VDIR) {
590 if (fd->f_type == DTYPE_VNODE) {
592 /* good, this is a vnode; next see if it is an AFS vnode */
593 #if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV)
594 tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */
595 #elif defined(AFS_OBSD_ENV)
597 IsAfsVnode((struct vnode *)fd->
598 f_data) ? VTOAFS((struct vnode *)fd->f_data) : NULL;
600 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
602 #endif /* AFS_LINUX22_ENV */
603 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
604 /* This is an AFS vnode */
605 if (((uap->com >> 8) & 0xff) == 'V') {
606 register struct afs_ioctl *datap;
609 (struct afs_ioctl *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
610 code=copyin_afs_ioctl((char *)uap->arg, datap);
612 osi_FreeSmallSpace(datap);
614 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
617 #if defined(AFS_SUN5_ENV)
632 #else /* AFS_OSF_ENV */
636 #ifdef AFS_LINUX22_ENV
646 code = HandleIoctl(tvc, uap->com, datap);
647 osi_FreeSmallSpace(datap);
661 #if defined(AFS_LINUX22_ENV)
673 code = okioctl(fdes, com, arg, ext, arg2, arg3);
674 #else /* __64BIT__ */
675 code = okioctl32(fdes, com, arg, ext, arg2, arg3);
676 #endif /* __64BIT__ */
677 #else /* !AFS_AIX51_ENV */
678 code = okioctl(fdes, com, arg, ext);
679 #endif /* AFS_AIX51_ENV */
681 #else /* !AFS_AIX41_ENV */
683 okioctl(fdes, com, arg, ext);
684 #elif defined(AFS_SUN5_ENV)
685 #if defined(AFS_SUN57_ENV)
687 #elif defined(AFS_SUN54_ENV)
692 code = ioctl(uap, rvp);
693 #elif defined(AFS_FBSD50_ENV)
694 return ioctl(td, uap);
695 #elif defined(AFS_FBSD_ENV)
696 return ioctl(p, uap);
697 #elif defined(AFS_OBSD_ENV)
698 code = sys_ioctl(p, uap, retval);
699 #elif defined(AFS_DARWIN_ENV)
700 return ioctl(p, uap, retval);
701 #elif defined(AFS_OSF_ENV)
702 code = ioctl(p, args, retval);
709 #elif !defined(AFS_LINUX22_ENV)
723 #ifdef AFS_LINUX22_ENV
726 #if defined(KERNEL_HAVE_UERROR)
729 #if defined(AFS_AIX32_ENV) && !defined(AFS_AIX41_ENV)
730 return (getuerror()? -1 : u.u_ioctlrv);
732 return getuerror()? -1 : 0;
735 #endif /* AFS_LINUX22_ENV */
736 #endif /* AFS_SUN5_ENV */
737 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
741 #endif /* AFS_SGI_ENV */
742 #endif /* AFS_HPUX102_ENV */
744 #if defined(AFS_SGI_ENV)
745 /* "pioctl" system call entry point; just pass argument to the parameterized
754 afs_pioctl(struct pioctlargs *uap, rval_t * rvp)
758 AFS_STATCNT(afs_pioctl);
760 code = afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow);
769 #elif defined(AFS_OSF_ENV)
770 afs_pioctl(p, args, retval)
780 } *uap = (struct a *)args;
782 AFS_STATCNT(afs_pioctl);
783 return (afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow));
786 #elif defined(AFS_FBSD50_ENV)
788 afs_pioctl(td, args, retval)
798 } *uap = (struct a *)args;
800 AFS_STATCNT(afs_pioctl);
801 return (afs_syscall_pioctl
802 (uap->path, uap->cmd, uap->cmarg, uap->follow, td->td_ucred));
805 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
807 afs_pioctl(p, args, retval)
817 } *uap = (struct a *)args;
819 AFS_STATCNT(afs_pioctl);
820 return (afs_syscall_pioctl
821 (uap->path, uap->cmd, uap->cmarg, uap->follow,
822 p->p_cred->pc_ucred));
827 /* macro to avoid adding any more #ifdef's to pioctl code. */
828 #if defined(AFS_LINUX22_ENV) || defined(AFS_AIX41_ENV)
829 #define PIOCTL_FREE_CRED() crfree(credp)
831 #define PIOCTL_FREE_CRED()
836 afs_syscall_pioctl(path, com, cmarg, follow, rvp, credp)
838 struct AFS_UCRED *credp;
840 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
841 afs_syscall_pioctl(path, com, cmarg, follow, credp)
842 struct AFS_UCRED *credp;
844 afs_syscall_pioctl(path, com, cmarg, follow)
852 struct afs_ioctl data;
853 #ifdef AFS_NEED_CLIENTCONTEXT
854 struct AFS_UCRED *tmpcred;
856 struct AFS_UCRED *foreigncreds = NULL;
857 register afs_int32 code = 0;
858 struct vnode *vp = NULL;
860 struct ucred *credp = crref(); /* don't free until done! */
862 #ifdef AFS_LINUX22_ENV
863 cred_t *credp = crref(); /* don't free until done! */
867 AFS_STATCNT(afs_syscall_pioctl);
869 follow = 1; /* compat. with old venus */
870 code = copyin_afs_ioctl(cmarg, &data);
873 #if defined(KERNEL_HAVE_UERROR)
878 if ((com & 0xff) == PSetClientContext) {
879 #ifdef AFS_NEED_CLIENTCONTEXT
880 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV)
881 code = HandleClientContext(&data, &com, &foreigncreds, credp);
883 code = HandleClientContext(&data, &com, &foreigncreds, osi_curcred());
887 crfree(foreigncreds);
890 #if defined(KERNEL_HAVE_UERROR)
891 return (setuerror(code), code);
896 #else /* AFS_NEED_CLIENTCONTEXT */
898 #endif /* AFS_NEED_CLIENTCONTEXT */
900 #ifdef AFS_NEED_CLIENTCONTEXT
903 * We could have done without temporary setting the u.u_cred below
904 * (foreigncreds could be passed as param the pioctl modules)
905 * but calls such as afs_osi_suser() doesn't allow that since it
906 * references u.u_cred directly. We could, of course, do something
907 * like afs_osi_suser(cred) which, I think, is better since it
908 * generalizes and supports multi cred environments...
912 credp = foreigncreds;
913 #elif defined(AFS_AIX41_ENV)
914 tmpcred = crref(); /* XXX */
916 #elif defined(AFS_HPUX101_ENV)
917 tmpcred = p_cred(u.u_procp);
918 set_p_cred(u.u_procp, foreigncreds);
919 #elif defined(AFS_SGI_ENV)
920 tmpcred = OSI_GET_CURRENT_CRED();
921 OSI_SET_CURRENT_CRED(foreigncreds);
924 u.u_cred = foreigncreds;
927 #endif /* AFS_NEED_CLIENTCONTEXT */
928 if ((com & 0xff) == 15) {
929 /* special case prefetch so entire pathname eval occurs in helper process.
930 * otherwise, the pioctl call is essentially useless */
931 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
933 Prefetch(path, &data, follow,
934 foreigncreds ? foreigncreds : credp);
936 code = Prefetch(path, &data, follow, osi_curcred());
939 #if defined(KERNEL_HAVE_UERROR)
948 lookupname(path, USR, follow, NULL, &vp,
949 foreigncreds ? foreigncreds : credp);
951 #ifdef AFS_LINUX22_ENV
952 code = gop_lookupname(path, AFS_UIOUSER, follow, &dp);
954 vp = (struct vnode *)dp->d_inode;
956 code = gop_lookupname(path, AFS_UIOUSER, follow, &vp);
957 #endif /* AFS_LINUX22_ENV */
958 #endif /* AFS_AIX41_ENV */
962 #if defined(KERNEL_HAVE_UERROR)
970 /* now make the call if we were passed no file, or were passed an AFS file */
971 if (!vp || IsAfsVnode(vp)) {
972 #if defined(AFS_SUN5_ENV)
973 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
974 #elif defined(AFS_AIX41_ENV)
976 struct ucred *cred1, *cred2;
979 cred1 = cred2 = foreigncreds;
981 cred1 = cred2 = credp;
983 code = afs_HandlePioctl(vp, com, &data, follow, &cred1);
984 if (cred1 != cred2) {
985 /* something changed the creds */
989 #elif defined(AFS_HPUX101_ENV)
991 struct ucred *cred = p_cred(u.u_procp);
992 code = afs_HandlePioctl(vp, com, &data, follow, &cred);
994 #elif defined(AFS_SGI_ENV)
997 credp = OSI_GET_CURRENT_CRED();
998 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1000 #elif defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1001 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1003 code = afs_HandlePioctl(vp, com, &data, follow, &u.u_cred);
1006 #if defined(KERNEL_HAVE_UERROR)
1009 code = EINVAL; /* not in /afs */
1014 #if defined(AFS_NEED_CLIENTCONTEXT)
1016 #ifdef AFS_AIX41_ENV
1017 crset(tmpcred); /* restore original credentials */
1019 #if defined(AFS_HPUX101_ENV)
1020 set_p_cred(u.u_procp, tmpcred); /* restore original credentials */
1021 #elif defined(AFS_SGI_ENV)
1022 OSI_SET_CURRENT_CRED(tmpcred); /* restore original credentials */
1023 #elif !defined(AFS_SUN5_ENV)
1024 osi_curcred() = tmpcred; /* restore original credentials */
1025 #endif /* AFS_HPUX101_ENV */
1026 crfree(foreigncreds);
1029 #endif /* AFS_NEED_CLIENTCONTEXT */
1031 #ifdef AFS_LINUX22_ENV
1034 AFS_RELE(vp); /* put vnode back */
1038 #if defined(KERNEL_HAVE_UERROR)
1041 return (getuerror());
1047 #define MAXPIOCTLTOKENLEN \
1048 (3*sizeof(afs_int32)+MAXKTCTICKETLEN+sizeof(struct ClearToken)+MAXKTCREALMLEN)
1051 afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
1052 register struct afs_ioctl *ablob, int afollow,
1053 struct AFS_UCRED **acred)
1056 struct vrequest treq;
1057 register afs_int32 code;
1058 register afs_int32 function, device;
1059 afs_int32 inSize, outSize, outSizeMax;
1060 char *inData, *outData;
1061 int (*(*pioctlSw)) ();
1063 struct afs_fakestat_state fakestate;
1065 avc = avp ? VTOAFS(avp) : NULL;
1066 afs_Trace3(afs_iclSetp, CM_TRACE_PIOCTL, ICL_TYPE_INT32, acom & 0xff,
1067 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, afollow);
1068 AFS_STATCNT(HandlePioctl);
1069 if ((code = afs_InitReq(&treq, *acred)))
1071 afs_InitFakeStat(&fakestate);
1073 code = afs_EvalFakeStat(&avc, &fakestate, &treq);
1075 afs_PutFakeStat(&fakestate);
1079 device = (acom & 0xff00) >> 8;
1081 case 'V': /* Original pioctls */
1082 pioctlSw = VpioctlSw;
1083 pioctlSwSize = sizeof(VpioctlSw);
1085 case 'C': /* Coordinated/common pioctls */
1086 pioctlSw = CpioctlSw;
1087 pioctlSwSize = sizeof(CpioctlSw);
1090 afs_PutFakeStat(&fakestate);
1093 function = acom & 0xff;
1094 if (function >= (pioctlSwSize / sizeof(char *))) {
1095 afs_PutFakeStat(&fakestate);
1096 return EINVAL; /* out of range */
1098 inSize = ablob->in_size;
1100 /* Do all range checking before continuing */
1101 if (inSize > MAXPIOCTLTOKENLEN || inSize < 0 || ablob->out_size < 0)
1104 /* Note that we use osi_Alloc for large allocs and osi_AllocLargeSpace for small ones */
1105 if (inSize > AFS_LRALLOCSIZ) {
1106 inData = osi_Alloc(inSize + 1);
1108 inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1113 AFS_COPYIN(ablob->in, inData, inSize, code);
1114 inData[inSize] = '\0';
1118 if (inSize > AFS_LRALLOCSIZ) {
1119 osi_Free(inData, inSize + 1);
1121 osi_FreeLargeSpace(inData);
1123 afs_PutFakeStat(&fakestate);
1126 if (function == 8 && device == 'V') { /* PGetTokens */
1127 outSizeMax = MAXPIOCTLTOKENLEN;
1128 outData = osi_Alloc(outSizeMax);
1130 outSizeMax = AFS_LRALLOCSIZ;
1131 outData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1134 if (inSize > AFS_LRALLOCSIZ) {
1135 osi_Free(inData, inSize + 1);
1137 osi_FreeLargeSpace(inData);
1139 afs_PutFakeStat(&fakestate);
1144 (*pioctlSw[function]) (avc, function, &treq, inData, outData, inSize,
1146 if (inSize > AFS_LRALLOCSIZ) {
1147 osi_Free(inData, inSize + 1);
1149 osi_FreeLargeSpace(inData);
1151 if (code == 0 && ablob->out_size > 0) {
1152 if (outSize > ablob->out_size) {
1153 code = E2BIG; /* data wont fit in user buffer */
1154 } else if (outSize) {
1155 AFS_COPYOUT(outData, ablob->out, outSize, code);
1158 if (outSizeMax > AFS_LRALLOCSIZ) {
1159 osi_Free(outData, outSizeMax);
1161 osi_FreeLargeSpace(outData);
1163 afs_PutFakeStat(&fakestate);
1164 return afs_CheckCode(code, &treq, 41);
1167 DECL_PIOCTL(PGetFID)
1169 AFS_STATCNT(PGetFID);
1172 memcpy(aout, (char *)&avc->fid, sizeof(struct VenusFid));
1173 *aoutSize = sizeof(struct VenusFid);
1177 DECL_PIOCTL(PSetAcl)
1179 register afs_int32 code;
1181 struct AFSOpaque acl;
1182 struct AFSVolSync tsync;
1183 struct AFSFetchStatus OutStatus;
1186 AFS_STATCNT(PSetAcl);
1189 if ((acl.AFSOpaque_len = strlen(ain) + 1) > 1000)
1192 acl.AFSOpaque_val = ain;
1194 tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1196 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREACL);
1199 RXAFS_StoreACL(tconn->id, (struct AFSFid *)&avc->fid.Fid,
1200 &acl, &OutStatus, &tsync);
1205 } while (afs_Analyze
1206 (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_STOREACL,
1207 SHARED_LOCK, NULL));
1209 /* now we've forgotten all of the access info */
1210 ObtainWriteLock(&afs_xcbhash, 455);
1212 afs_DequeueCallback(avc);
1213 avc->states &= ~(CStatd | CUnique);
1214 ReleaseWriteLock(&afs_xcbhash);
1215 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
1216 osi_dnlc_purgedp(avc);
1220 int afs_defaultAsynchrony = 0;
1222 DECL_PIOCTL(PStoreBehind)
1225 struct sbstruct *sbr;
1227 sbr = (struct sbstruct *)ain;
1228 if (sbr->sb_default != -1) {
1229 if (afs_osi_suser(*acred))
1230 afs_defaultAsynchrony = sbr->sb_default;
1235 if (avc && (sbr->sb_thisfile != -1)) {
1237 (avc, PRSFS_WRITE | PRSFS_ADMINISTER, areq, DONT_CHECK_MODE_BITS))
1238 avc->asynchrony = sbr->sb_thisfile;
1243 *aoutSize = sizeof(struct sbstruct);
1244 sbr = (struct sbstruct *)aout;
1245 sbr->sb_default = afs_defaultAsynchrony;
1247 sbr->sb_thisfile = avc->asynchrony;
1253 DECL_PIOCTL(PGCPAGs)
1255 if (!afs_osi_suser(*acred)) {
1258 afs_gcpags = AFS_GCPAGS_USERDISABLED;
1262 DECL_PIOCTL(PGetAcl)
1264 struct AFSOpaque acl;
1265 struct AFSVolSync tsync;
1266 struct AFSFetchStatus OutStatus;
1272 AFS_STATCNT(PGetAcl);
1275 Fid.Volume = avc->fid.Fid.Volume;
1276 Fid.Vnode = avc->fid.Fid.Vnode;
1277 Fid.Unique = avc->fid.Fid.Unique;
1278 if (avc->states & CForeign) {
1280 * For a dfs xlator acl we have a special hack so that the
1281 * xlator will distinguish which type of acl will return. So
1282 * we currently use the top 2-bytes (vals 0-4) to tell which
1283 * type of acl to bring back. Horrible hack but this will
1284 * cause the least number of changes to code size and interfaces.
1286 if (Fid.Vnode & 0xc0000000)
1288 Fid.Vnode |= (ainSize << 30);
1290 acl.AFSOpaque_val = aout;
1292 tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1295 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHACL);
1297 code = RXAFS_FetchACL(tconn->id, &Fid, &acl, &OutStatus, &tsync);
1302 } while (afs_Analyze
1303 (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_FETCHACL,
1304 SHARED_LOCK, NULL));
1307 *aoutSize = (acl.AFSOpaque_len == 0 ? 1 : acl.AFSOpaque_len);
1320 AFS_STATCNT(PBogus);
1324 DECL_PIOCTL(PGetFileCell)
1326 register struct cell *tcell;
1328 AFS_STATCNT(PGetFileCell);
1331 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
1334 strcpy(aout, tcell->cellName);
1335 afs_PutCell(tcell, READ_LOCK);
1336 *aoutSize = strlen(aout) + 1;
1340 DECL_PIOCTL(PGetWSCell)
1342 struct cell *tcell = NULL;
1344 AFS_STATCNT(PGetWSCell);
1345 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1346 return EIO; /* Inappropriate ioctl for device */
1348 tcell = afs_GetPrimaryCell(READ_LOCK);
1349 if (!tcell) /* no primary cell? */
1351 strcpy(aout, tcell->cellName);
1352 *aoutSize = strlen(aout) + 1;
1353 afs_PutCell(tcell, READ_LOCK);
1357 DECL_PIOCTL(PGetUserCell)
1359 register afs_int32 i;
1360 register struct unixuser *tu;
1361 register struct cell *tcell;
1363 AFS_STATCNT(PGetUserCell);
1364 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1365 return EIO; /* Inappropriate ioctl for device */
1367 /* return the cell name of the primary cell for this user */
1368 i = UHash(areq->uid);
1369 ObtainWriteLock(&afs_xuser, 224);
1370 for (tu = afs_users[i]; tu; tu = tu->next) {
1371 if (tu->uid == areq->uid && (tu->states & UPrimary)) {
1373 ReleaseWriteLock(&afs_xuser);
1378 tcell = afs_GetCell(tu->cell, READ_LOCK);
1379 afs_PutUser(tu, WRITE_LOCK);
1383 strcpy(aout, tcell->cellName);
1384 afs_PutCell(tcell, READ_LOCK);
1385 *aoutSize = strlen(aout) + 1; /* 1 for the null */
1388 ReleaseWriteLock(&afs_xuser);
1395 DECL_PIOCTL(PSetTokens)
1398 register struct unixuser *tu;
1399 struct ClearToken clear;
1400 register struct cell *tcell;
1403 struct vrequest treq;
1404 afs_int32 flag, set_parent_pag = 0;
1406 AFS_STATCNT(PSetTokens);
1407 if (!afs_resourceinit_flag) {
1410 memcpy((char *)&i, ain, sizeof(afs_int32));
1411 ain += sizeof(afs_int32);
1412 stp = ain; /* remember where the ticket is */
1413 if (i < 0 || i > MAXKTCTICKETLEN)
1414 return EINVAL; /* malloc may fail */
1416 ain += i; /* skip over ticket */
1417 memcpy((char *)&i, ain, sizeof(afs_int32));
1418 ain += sizeof(afs_int32);
1419 if (i != sizeof(struct ClearToken)) {
1422 memcpy((char *)&clear, ain, sizeof(struct ClearToken));
1423 if (clear.AuthHandle == -1)
1424 clear.AuthHandle = 999; /* more rxvab compat stuff */
1425 ain += sizeof(struct ClearToken);
1426 if (ainSize != 2 * sizeof(afs_int32) + stLen + sizeof(struct ClearToken)) {
1427 /* still stuff left? we've got primary flag and cell name. Set these */
1428 memcpy((char *)&flag, ain, sizeof(afs_int32)); /* primary id flag */
1429 ain += sizeof(afs_int32); /* skip id field */
1430 /* rest is cell name, look it up */
1431 /* some versions of gcc appear to need != 0 in order to get this right */
1432 if ((flag & 0x8000) != 0) { /* XXX Use Constant XXX */
1436 tcell = afs_GetCellByName(ain, READ_LOCK);
1440 /* default to primary cell, primary id */
1441 flag = 1; /* primary id */
1442 tcell = afs_GetPrimaryCell(READ_LOCK);
1447 afs_PutCell(tcell, READ_LOCK);
1448 if (set_parent_pag) {
1450 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1451 #if defined(AFS_DARWIN_ENV)
1452 struct proc *p = current_proc(); /* XXX */
1454 struct proc *p = curproc; /* XXX */
1456 uprintf("Process %d (%s) tried to change pags in PSetTokens\n",
1457 p->p_pid, p->p_comm);
1458 if (!setpag(p, acred, -1, &pag, 1)) {
1461 if (!setpag(u.u_procp, acred, -1, &pag, 1)) { /* XXX u.u_procp is a no-op XXX */
1463 if (!setpag(acred, -1, &pag, 1)) {
1466 afs_InitReq(&treq, *acred);
1470 /* now we just set the tokens */
1471 tu = afs_GetUser(areq->uid, i, WRITE_LOCK); /* i has the cell # */
1472 tu->vid = clear.ViceId;
1473 if (tu->stp != NULL) {
1474 afs_osi_Free(tu->stp, tu->stLen);
1476 tu->stp = (char *)afs_osi_Alloc(stLen);
1478 memcpy(tu->stp, stp, stLen);
1481 afs_stats_cmfullperf.authent.TicketUpdates++;
1482 afs_ComputePAGStats();
1483 #endif /* AFS_NOSTATS */
1484 tu->states |= UHasTokens;
1485 tu->states &= ~UTokensBad;
1486 afs_SetPrimary(tu, flag);
1487 tu->tokenTime = osi_Time();
1488 afs_ResetUserConns(tu);
1489 afs_PutUser(tu, WRITE_LOCK);
1504 DECL_PIOCTL(PGetVolumeStatus)
1507 char *offLineMsg = afs_osi_Alloc(256);
1508 char *motd = afs_osi_Alloc(256);
1509 register struct conn *tc;
1510 register afs_int32 code = 0;
1511 struct AFSFetchVolumeStatus volstat;
1513 char *Name, *OfflineMsg, *MOTD;
1516 AFS_STATCNT(PGetVolumeStatus);
1522 OfflineMsg = offLineMsg;
1525 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1527 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS);
1530 RXAFS_GetVolumeStatus(tc->id, avc->fid.Fid.Volume, &volstat,
1531 &Name, &OfflineMsg, &MOTD);
1536 } while (afs_Analyze
1537 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS,
1538 SHARED_LOCK, NULL));
1542 /* Copy all this junk into msg->im_data, keeping track of the lengths. */
1544 memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
1545 cp += sizeof(VolumeStatus);
1546 strcpy(cp, volName);
1547 cp += strlen(volName) + 1;
1548 strcpy(cp, offLineMsg);
1549 cp += strlen(offLineMsg) + 1;
1551 cp += strlen(motd) + 1;
1552 *aoutSize = (cp - aout);
1554 afs_osi_Free(offLineMsg, 256);
1555 afs_osi_Free(motd, 256);
1559 DECL_PIOCTL(PSetVolumeStatus)
1562 char *offLineMsg = afs_osi_Alloc(256);
1563 char *motd = afs_osi_Alloc(256);
1564 register struct conn *tc;
1565 register afs_int32 code = 0;
1566 struct AFSFetchVolumeStatus volstat;
1567 struct AFSStoreVolumeStatus storeStat;
1568 register struct volume *tvp;
1572 AFS_STATCNT(PSetVolumeStatus);
1578 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
1580 if (tvp->states & (VRO | VBackup)) {
1581 afs_PutVolume(tvp, READ_LOCK);
1585 afs_PutVolume(tvp, READ_LOCK);
1590 /* Copy the junk out, using cp as a roving pointer. */
1592 memcpy((char *)&volstat, cp, sizeof(AFSFetchVolumeStatus));
1593 cp += sizeof(AFSFetchVolumeStatus);
1594 if (strlen(cp) >= sizeof(volName)) {
1598 strcpy(volName, cp);
1599 cp += strlen(volName) + 1;
1600 if (strlen(cp) >= sizeof(offLineMsg)) {
1604 strcpy(offLineMsg, cp);
1605 cp += strlen(offLineMsg) + 1;
1606 if (strlen(cp) >= sizeof(motd)) {
1612 if (volstat.MinQuota != -1) {
1613 storeStat.MinQuota = volstat.MinQuota;
1614 storeStat.Mask |= AFS_SETMINQUOTA;
1616 if (volstat.MaxQuota != -1) {
1617 storeStat.MaxQuota = volstat.MaxQuota;
1618 storeStat.Mask |= AFS_SETMAXQUOTA;
1621 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1623 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS);
1626 RXAFS_SetVolumeStatus(tc->id, avc->fid.Fid.Volume, &storeStat,
1627 volName, offLineMsg, motd);
1632 } while (afs_Analyze
1633 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS,
1634 SHARED_LOCK, NULL));
1638 /* we are sending parms back to make compat. with prev system. should
1639 * change interface later to not ask for current status, just set new status */
1641 memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
1642 cp += sizeof(VolumeStatus);
1643 strcpy(cp, volName);
1644 cp += strlen(volName) + 1;
1645 strcpy(cp, offLineMsg);
1646 cp += strlen(offLineMsg) + 1;
1648 cp += strlen(motd) + 1;
1649 *aoutSize = cp - aout;
1651 afs_osi_Free(offLineMsg, 256);
1652 afs_osi_Free(motd, 256);
1658 AFS_STATCNT(PFlush);
1661 #ifdef AFS_BOZONLOCK_ENV
1662 afs_BozonLock(&avc->pvnLock, avc); /* Since afs_TryToSmush will do a pvn_vptrunc */
1664 ObtainWriteLock(&avc->lock, 225);
1665 ObtainWriteLock(&afs_xcbhash, 456);
1666 afs_DequeueCallback(avc);
1667 avc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
1668 ReleaseWriteLock(&afs_xcbhash);
1669 /* now find the disk cache entries */
1670 afs_TryToSmush(avc, *acred, 1);
1671 osi_dnlc_purgedp(avc);
1672 if (avc->linkData && !(avc->states & CCore)) {
1673 afs_osi_Free(avc->linkData, strlen(avc->linkData) + 1);
1674 avc->linkData = NULL;
1676 ReleaseWriteLock(&avc->lock);
1677 #ifdef AFS_BOZONLOCK_ENV
1678 afs_BozonUnlock(&avc->pvnLock, avc);
1683 DECL_PIOCTL(PNewStatMount)
1685 register afs_int32 code;
1686 register struct vcache *tvc;
1687 register struct dcache *tdc;
1688 struct VenusFid tfid;
1690 struct sysname_info sysState;
1691 afs_size_t offset, len;
1693 AFS_STATCNT(PNewStatMount);
1696 code = afs_VerifyVCache(avc, areq);
1699 if (vType(avc) != VDIR) {
1702 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
1705 Check_AtSys(avc, ain, &sysState, areq);
1706 ObtainReadLock(&tdc->lock);
1708 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
1709 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
1710 ReleaseReadLock(&tdc->lock);
1711 afs_PutDCache(tdc); /* we're done with the data */
1712 bufp = sysState.name;
1716 tfid.Cell = avc->fid.Cell;
1717 tfid.Fid.Volume = avc->fid.Fid.Volume;
1718 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
1719 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
1721 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
1727 if (tvc->mvstat != 1) {
1732 ObtainWriteLock(&tvc->lock, 226);
1733 code = afs_HandleLink(tvc, areq);
1735 if (tvc->linkData) {
1736 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
1739 /* we have the data */
1740 strcpy(aout, tvc->linkData);
1741 *aoutSize = strlen(tvc->linkData) + 1;
1746 ReleaseWriteLock(&tvc->lock);
1749 if (sysState.allocked)
1750 osi_FreeLargeSpace(bufp);
1754 DECL_PIOCTL(PGetTokens)
1756 register struct cell *tcell;
1757 register afs_int32 i;
1758 register struct unixuser *tu;
1763 AFS_STATCNT(PGetTokens);
1764 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1765 return EIO; /* Inappropriate ioctl for device */
1767 /* weird interface. If input parameter is present, it is an integer and
1768 * we're supposed to return the parm'th tokens for this unix uid.
1769 * If not present, we just return tokens for cell 1.
1770 * If counter out of bounds, return EDOM.
1771 * If no tokens for the particular cell, return ENOTCONN.
1772 * Also, if this mysterious parm is present, we return, along with the
1773 * tokens, the primary cell indicator (an afs_int32 0) and the cell name
1774 * at the end, in that order.
1776 if ((newStyle = (ainSize > 0))) {
1777 memcpy((char *)&iterator, ain, sizeof(afs_int32));
1779 i = UHash(areq->uid);
1780 ObtainReadLock(&afs_xuser);
1781 for (tu = afs_users[i]; tu; tu = tu->next) {
1783 if (tu->uid == areq->uid && (tu->states & UHasTokens)) {
1784 if (iterator-- == 0)
1785 break; /* are we done yet? */
1788 if (tu->uid == areq->uid && afs_IsPrimaryCellNum(tu->cell))
1794 * No need to hold a read lock on each user entry
1798 ReleaseReadLock(&afs_xuser);
1803 if (((tu->states & UHasTokens) == 0)
1804 || (tu->ct.EndTimestamp < osi_Time())) {
1805 tu->states |= (UTokensBad | UNeedsReset);
1806 afs_PutUser(tu, READ_LOCK);
1809 /* use iterator for temp */
1811 iterator = tu->stLen; /* for compat, we try to return 56 byte tix if they fit */
1813 iterator = 56; /* # of bytes we're returning */
1814 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1815 cp += sizeof(afs_int32);
1816 memcpy(cp, tu->stp, tu->stLen); /* copy out st */
1818 iterator = sizeof(struct ClearToken);
1819 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1820 cp += sizeof(afs_int32);
1821 memcpy(cp, (char *)&tu->ct, sizeof(struct ClearToken));
1822 cp += sizeof(struct ClearToken);
1824 /* put out primary id and cell name, too */
1825 iterator = (tu->states & UPrimary ? 1 : 0);
1826 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1827 cp += sizeof(afs_int32);
1828 tcell = afs_GetCell(tu->cell, READ_LOCK);
1830 strcpy(cp, tcell->cellName);
1831 cp += strlen(tcell->cellName) + 1;
1832 afs_PutCell(tcell, READ_LOCK);
1836 *aoutSize = cp - aout;
1837 afs_PutUser(tu, READ_LOCK);
1843 register afs_int32 i;
1844 register struct unixuser *tu;
1846 AFS_STATCNT(PUnlog);
1847 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1848 return EIO; /* Inappropriate ioctl for device */
1850 i = UHash(areq->uid);
1851 ObtainWriteLock(&afs_xuser, 227);
1852 for (tu = afs_users[i]; tu; tu = tu->next) {
1853 if (tu->uid == areq->uid) {
1855 tu->states &= ~UHasTokens;
1856 /* security is not having to say you're sorry */
1857 memset((char *)&tu->ct, 0, sizeof(struct ClearToken));
1859 ReleaseWriteLock(&afs_xuser);
1860 /* We have to drop the lock over the call to afs_ResetUserConns, since
1861 * it obtains the afs_xvcache lock. We could also keep the lock, and
1862 * modify ResetUserConns to take parm saying we obtained the lock
1863 * already, but that is overkill. By keeping the "tu" pointer
1864 * held over the released lock, we guarantee that we won't lose our
1865 * place, and that we'll pass over every user conn that existed when
1866 * we began this call.
1868 afs_ResetUserConns(tu);
1870 ObtainWriteLock(&afs_xuser, 228);
1872 /* set the expire times to 0, causes
1873 * afs_GCUserData to remove this entry
1875 tu->ct.EndTimestamp = 0;
1877 #endif /* UKERNEL */
1880 ReleaseWriteLock(&afs_xuser);
1884 DECL_PIOCTL(PMariner)
1886 afs_int32 newHostAddr;
1887 afs_int32 oldHostAddr;
1889 AFS_STATCNT(PMariner);
1891 memcpy((char *)&oldHostAddr, (char *)&afs_marinerHost,
1894 oldHostAddr = 0xffffffff; /* disabled */
1896 memcpy((char *)&newHostAddr, ain, sizeof(afs_int32));
1897 if (newHostAddr == 0xffffffff) {
1898 /* disable mariner operations */
1900 } else if (newHostAddr) {
1902 afs_marinerHost = newHostAddr;
1904 memcpy(aout, (char *)&oldHostAddr, sizeof(afs_int32));
1905 *aoutSize = sizeof(afs_int32);
1909 DECL_PIOCTL(PCheckServers)
1911 register char *cp = 0;
1913 register struct server *ts;
1914 afs_int32 temp, *lp = (afs_int32 *) ain, havecell = 0;
1916 struct chservinfo *pcheck;
1918 AFS_STATCNT(PCheckServers);
1920 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1921 return EIO; /* Inappropriate ioctl for device */
1923 if (*lp == 0x12345678) { /* For afs3.3 version */
1924 pcheck = (struct chservinfo *)ain;
1925 if (pcheck->tinterval >= 0) {
1927 memcpy(cp, (char *)&PROBE_INTERVAL, sizeof(afs_int32));
1928 *aoutSize = sizeof(afs_int32);
1929 if (pcheck->tinterval > 0) {
1930 if (!afs_osi_suser(*acred))
1932 PROBE_INTERVAL = pcheck->tinterval;
1938 temp = pcheck->tflags;
1939 cp = pcheck->tbuffer;
1940 } else { /* For pre afs3.3 versions */
1941 memcpy((char *)&temp, ain, sizeof(afs_int32));
1942 cp = ain + sizeof(afs_int32);
1943 if (ainSize > sizeof(afs_int32))
1948 * 1: fast check, don't contact servers.
1949 * 2: local cell only.
1952 /* have cell name, too */
1953 cellp = afs_GetCellByName(cp, READ_LOCK);
1958 if (!cellp && (temp & 2)) {
1959 /* use local cell */
1960 cellp = afs_GetPrimaryCell(READ_LOCK);
1962 if (!(temp & 1)) { /* if not fast, call server checker routine */
1963 afs_CheckServers(1, cellp); /* check down servers */
1964 afs_CheckServers(0, cellp); /* check up servers */
1966 /* now return the current down server list */
1968 ObtainReadLock(&afs_xserver);
1969 for (i = 0; i < NSERVERS; i++) {
1970 for (ts = afs_servers[i]; ts; ts = ts->next) {
1971 if (cellp && ts->cell != cellp)
1972 continue; /* cell spec'd and wrong */
1973 if ((ts->flags & SRVR_ISDOWN)
1974 && ts->addr->sa_portal != ts->cell->vlport) {
1975 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
1976 cp += sizeof(afs_int32);
1980 ReleaseReadLock(&afs_xserver);
1982 afs_PutCell(cellp, READ_LOCK);
1983 *aoutSize = cp - aout;
1987 DECL_PIOCTL(PCheckVolNames)
1989 AFS_STATCNT(PCheckVolNames);
1990 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1991 return EIO; /* Inappropriate ioctl for device */
1993 afs_CheckRootVolume();
1994 afs_CheckVolumeNames(AFS_VOLCHECK_FORCE | AFS_VOLCHECK_EXPIRED |
1995 AFS_VOLCHECK_BUSY | AFS_VOLCHECK_MTPTS);
1999 DECL_PIOCTL(PCheckAuth)
2004 struct unixuser *tu;
2007 AFS_STATCNT(PCheckAuth);
2008 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2009 return EIO; /* Inappropriate ioctl for device */
2012 tu = afs_GetUser(areq->uid, 1, READ_LOCK); /* check local cell authentication */
2016 /* we have a user */
2017 ObtainReadLock(&afs_xsrvAddr);
2018 ObtainReadLock(&afs_xconn);
2020 /* any tokens set? */
2021 if ((tu->states & UHasTokens) == 0)
2023 /* all connections in cell 1 working? */
2024 for (i = 0; i < NSERVERS; i++) {
2025 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2026 for (tc = sa->conns; tc; tc = tc->next) {
2027 if (tc->user == tu && (tu->states & UTokensBad))
2032 ReleaseReadLock(&afs_xsrvAddr);
2033 ReleaseReadLock(&afs_xconn);
2034 afs_PutUser(tu, READ_LOCK);
2036 memcpy(aout, (char *)&retValue, sizeof(afs_int32));
2037 *aoutSize = sizeof(afs_int32);
2042 Prefetch(char *apath, struct afs_ioctl *adata, int afollow,
2043 struct AFS_UCRED *acred)
2046 register afs_int32 code;
2047 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2053 AFS_STATCNT(Prefetch);
2056 tp = osi_AllocLargeSpace(1024);
2057 AFS_COPYINSTR(apath, tp, 1024, &bufferSize, code);
2059 osi_FreeLargeSpace(tp);
2062 if (afs_BBusy()) { /* do this as late as possible */
2063 osi_FreeLargeSpace(tp);
2064 return EWOULDBLOCK; /* pretty close */
2066 afs_BQueue(BOP_PATH, (struct vcache *)0, 0, 0, acred, (afs_size_t) 0,
2067 (afs_size_t) 0, tp);
2071 DECL_PIOCTL(PFindVolume)
2073 register struct volume *tvp;
2074 register struct server *ts;
2075 register afs_int32 i;
2078 AFS_STATCNT(PFindVolume);
2081 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
2084 for (i = 0; i < MAXHOSTS; i++) {
2085 ts = tvp->serverHost[i];
2088 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
2089 cp += sizeof(afs_int32);
2092 /* still room for terminating NULL, add it on */
2093 ainSize = 0; /* reuse vbl */
2094 memcpy(cp, (char *)&ainSize, sizeof(afs_int32));
2095 cp += sizeof(afs_int32);
2097 *aoutSize = cp - aout;
2098 afs_PutVolume(tvp, READ_LOCK);
2104 DECL_PIOCTL(PViceAccess)
2106 register afs_int32 code;
2109 AFS_STATCNT(PViceAccess);
2112 code = afs_VerifyVCache(avc, areq);
2115 memcpy((char *)&temp, ain, sizeof(afs_int32));
2116 code = afs_AccessOK(avc, temp, areq, CHECK_MODE_BITS);
2123 DECL_PIOCTL(PSetCacheSize)
2128 AFS_STATCNT(PSetCacheSize);
2129 if (!afs_osi_suser(*acred))
2131 /* too many things are setup initially in mem cache version */
2132 if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
2134 memcpy((char *)&newValue, ain, sizeof(afs_int32));
2136 afs_cacheBlocks = afs_stats_cmperf.cacheBlocksOrig;
2138 if (newValue < afs_min_cache)
2139 afs_cacheBlocks = afs_min_cache;
2141 afs_cacheBlocks = newValue;
2143 afs_stats_cmperf.cacheBlocksTotal = afs_cacheBlocks;
2144 afs_ComputeCacheParms(); /* recompute basic cache parameters */
2145 afs_MaybeWakeupTruncateDaemon();
2146 while (waitcnt++ < 100 && afs_cacheBlocks < afs_blocksUsed) {
2147 afs_osi_Wait(1000, 0, 0);
2148 afs_MaybeWakeupTruncateDaemon();
2153 #define MAXGCSTATS 16
2154 DECL_PIOCTL(PGetCacheSize)
2156 afs_int32 results[MAXGCSTATS];
2158 AFS_STATCNT(PGetCacheSize);
2159 memset((char *)results, 0, sizeof(results));
2160 results[0] = afs_cacheBlocks;
2161 results[1] = afs_blocksUsed;
2162 memcpy(aout, (char *)results, sizeof(results));
2163 *aoutSize = sizeof(results);
2167 DECL_PIOCTL(PRemoveCallBack)
2169 register struct conn *tc;
2170 register afs_int32 code = 0;
2171 struct AFSCallBack CallBacks_Array[1];
2172 struct AFSCBFids theFids;
2173 struct AFSCBs theCBs;
2176 AFS_STATCNT(PRemoveCallBack);
2179 if (avc->states & CRO)
2180 return 0; /* read-only-ness can't change */
2181 ObtainWriteLock(&avc->lock, 229);
2182 theFids.AFSCBFids_len = 1;
2183 theCBs.AFSCBs_len = 1;
2184 theFids.AFSCBFids_val = (struct AFSFid *)&avc->fid.Fid;
2185 theCBs.AFSCBs_val = CallBacks_Array;
2186 CallBacks_Array[0].CallBackType = CB_DROPPED;
2187 if (avc->callback) {
2189 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2191 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
2193 code = RXAFS_GiveUpCallBacks(tc->id, &theFids, &theCBs);
2197 /* don't set code on failure since we wouldn't use it */
2198 } while (afs_Analyze
2199 (tc, code, &avc->fid, areq,
2200 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK, NULL));
2202 ObtainWriteLock(&afs_xcbhash, 457);
2203 afs_DequeueCallback(avc);
2205 avc->states &= ~(CStatd | CUnique);
2206 ReleaseWriteLock(&afs_xcbhash);
2207 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
2208 osi_dnlc_purgedp(avc);
2210 ReleaseWriteLock(&avc->lock);
2214 DECL_PIOCTL(PNewCell)
2216 /* create a new cell */
2217 afs_int32 cellHosts[MAXCELLHOSTS], *lp, magic = 0;
2218 char *newcell = 0, *linkedcell = 0, *tp = ain;
2219 register afs_int32 code, linkedstate = 0, ls;
2220 u_short fsport = 0, vlport = 0;
2223 AFS_STATCNT(PNewCell);
2224 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2225 return EIO; /* Inappropriate ioctl for device */
2227 if (!afs_osi_suser(*acred))
2230 memcpy((char *)&magic, tp, sizeof(afs_int32));
2231 tp += sizeof(afs_int32);
2232 if (magic != 0x12345678)
2235 /* A 3.4 fs newcell command will pass an array of MAXCELLHOSTS
2236 * server addresses while the 3.5 fs newcell command passes
2237 * MAXHOSTS. To figure out which is which, check if the cellname
2240 newcell = tp + (MAXCELLHOSTS + 3) * sizeof(afs_int32);
2241 scount = ((newcell[0] != '\0') ? MAXCELLHOSTS : MAXHOSTS);
2243 /* MAXCELLHOSTS (=8) is less than MAXHOSTS (=13) */
2244 memcpy((char *)cellHosts, tp, MAXCELLHOSTS * sizeof(afs_int32));
2245 tp += (scount * sizeof(afs_int32));
2247 lp = (afs_int32 *) tp;
2251 fsport = 0; /* Privileged ports not allowed */
2253 vlport = 0; /* Privileged ports not allowed */
2254 tp += (3 * sizeof(afs_int32));
2256 if ((ls = *lp) & 1) {
2257 linkedcell = tp + strlen(newcell) + 1;
2258 linkedstate |= CLinkedCell;
2261 linkedstate |= CNoSUID; /* setuid is disabled by default for fs newcell */
2263 afs_NewCell(newcell, cellHosts, linkedstate, linkedcell, fsport,
2268 DECL_PIOCTL(PNewAlias)
2270 /* create a new cell alias */
2272 register afs_int32 code;
2273 char *realName, *aliasName;
2275 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2276 return EIO; /* Inappropriate ioctl for device */
2278 if (!afs_osi_suser(*acred))
2282 tp += strlen(aliasName) + 1;
2285 code = afs_NewCellAlias(aliasName, realName);
2290 DECL_PIOCTL(PListCells)
2292 afs_int32 whichCell;
2293 register struct cell *tcell = 0;
2294 register afs_int32 i;
2295 register char *cp, *tp = ain;
2297 AFS_STATCNT(PListCells);
2298 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2299 return EIO; /* Inappropriate ioctl for device */
2301 memcpy((char *)&whichCell, tp, sizeof(afs_int32));
2302 tp += sizeof(afs_int32);
2303 tcell = afs_GetCellByIndex(whichCell, READ_LOCK);
2306 memset(cp, 0, MAXCELLHOSTS * sizeof(afs_int32));
2307 for (i = 0; i < MAXCELLHOSTS; i++) {
2308 if (tcell->cellHosts[i] == 0)
2310 memcpy(cp, (char *)&tcell->cellHosts[i]->addr->sa_ip,
2312 cp += sizeof(afs_int32);
2314 cp = aout + MAXCELLHOSTS * sizeof(afs_int32);
2315 strcpy(cp, tcell->cellName);
2316 cp += strlen(tcell->cellName) + 1;
2317 *aoutSize = cp - aout;
2318 afs_PutCell(tcell, READ_LOCK);
2326 DECL_PIOCTL(PListAliases)
2328 afs_int32 whichAlias;
2329 register struct cell_alias *tcalias = 0;
2330 register char *cp, *tp = ain;
2332 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2333 return EIO; /* Inappropriate ioctl for device */
2334 if (ainSize < sizeof(afs_int32))
2337 memcpy((char *)&whichAlias, tp, sizeof(afs_int32));
2338 tp += sizeof(afs_int32);
2340 tcalias = afs_GetCellAlias(whichAlias);
2343 strcpy(cp, tcalias->alias);
2344 cp += strlen(tcalias->alias) + 1;
2345 strcpy(cp, tcalias->cell);
2346 cp += strlen(tcalias->cell) + 1;
2347 *aoutSize = cp - aout;
2348 afs_PutCellAlias(tcalias);
2356 DECL_PIOCTL(PRemoveMount)
2358 register afs_int32 code;
2360 struct sysname_info sysState;
2361 afs_size_t offset, len;
2362 register struct conn *tc;
2363 register struct dcache *tdc;
2364 register struct vcache *tvc;
2365 struct AFSFetchStatus OutDirStatus;
2366 struct VenusFid tfid;
2367 struct AFSVolSync tsync;
2371 /* "ain" is the name of the file in this dir to remove */
2373 AFS_STATCNT(PRemoveMount);
2376 code = afs_VerifyVCache(avc, areq);
2379 if (vType(avc) != VDIR)
2382 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1); /* test for error below */
2385 Check_AtSys(avc, ain, &sysState, areq);
2386 ObtainReadLock(&tdc->lock);
2388 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
2389 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
2390 ReleaseReadLock(&tdc->lock);
2391 bufp = sysState.name;
2396 tfid.Cell = avc->fid.Cell;
2397 tfid.Fid.Volume = avc->fid.Fid.Volume;
2398 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
2399 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
2401 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
2408 if (tvc->mvstat != 1) {
2414 ObtainWriteLock(&tvc->lock, 230);
2415 code = afs_HandleLink(tvc, areq);
2417 if (tvc->linkData) {
2418 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
2423 ReleaseWriteLock(&tvc->lock);
2424 osi_dnlc_purgedp(tvc);
2430 ObtainWriteLock(&avc->lock, 231);
2431 osi_dnlc_remove(avc, bufp, tvc);
2433 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2435 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE);
2438 RXAFS_RemoveFile(tc->id, (struct AFSFid *)&avc->fid.Fid, bufp,
2439 &OutDirStatus, &tsync);
2444 } while (afs_Analyze
2445 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_REMOVEFILE,
2446 SHARED_LOCK, NULL));
2451 ReleaseWriteLock(&avc->lock);
2455 /* we have the thing in the cache */
2456 ObtainWriteLock(&tdc->lock, 661);
2457 if (afs_LocalHero(avc, tdc, &OutDirStatus, 1)) {
2458 /* we can do it locally */
2459 code = afs_dir_Delete(tdc, bufp);
2461 ZapDCE(tdc); /* surprise error -- invalid value */
2465 ReleaseWriteLock(&tdc->lock);
2466 afs_PutDCache(tdc); /* drop ref count */
2468 avc->states &= ~CUnique; /* For the dfs xlator */
2469 ReleaseWriteLock(&avc->lock);
2472 if (sysState.allocked)
2473 osi_FreeLargeSpace(bufp);
2477 DECL_PIOCTL(PVenusLogging)
2479 return EINVAL; /* OBSOLETE */
2482 DECL_PIOCTL(PGetCellStatus)
2484 register struct cell *tcell;
2487 AFS_STATCNT(PGetCellStatus);
2488 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2489 return EIO; /* Inappropriate ioctl for device */
2491 tcell = afs_GetCellByName(ain, READ_LOCK);
2494 temp = tcell->states;
2495 afs_PutCell(tcell, READ_LOCK);
2496 memcpy(aout, (char *)&temp, sizeof(afs_int32));
2497 *aoutSize = sizeof(afs_int32);
2501 DECL_PIOCTL(PSetCellStatus)
2503 register struct cell *tcell;
2506 if (!afs_osi_suser(*acred))
2508 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2509 return EIO; /* Inappropriate ioctl for device */
2511 tcell = afs_GetCellByName(ain + 2 * sizeof(afs_int32), WRITE_LOCK);
2514 memcpy((char *)&temp, ain, sizeof(afs_int32));
2516 tcell->states |= CNoSUID;
2518 tcell->states &= ~CNoSUID;
2519 afs_PutCell(tcell, WRITE_LOCK);
2523 DECL_PIOCTL(PFlushVolumeData)
2525 register afs_int32 i;
2526 register struct dcache *tdc;
2527 register struct vcache *tvc;
2528 register struct volume *tv;
2529 afs_int32 cell, volume;
2530 struct afs_q *tq, *uq;
2532 AFS_STATCNT(PFlushVolumeData);
2535 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2536 return EIO; /* Inappropriate ioctl for device */
2538 volume = avc->fid.Fid.Volume; /* who to zap */
2539 cell = avc->fid.Cell;
2542 * Clear stat'd flag from all vnodes from this volume; this will invalidate all
2543 * the vcaches associated with the volume.
2545 ObtainReadLock(&afs_xvcache);
2546 i = VCHashV(&avc->fid);
2547 for (tq = afs_vhashTV[i].prev; tq != &afs_vhashTV[i]; tq = uq) {
2550 if (tvc->fid.Fid.Volume == volume && tvc->fid.Cell == cell) {
2551 #if defined(AFS_SGI_ENV) || defined(AFS_OSF_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
2552 VN_HOLD(AFSTOV(tvc));
2554 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2557 VREFCOUNT_INC(tvc); /* AIX, apparently */
2560 ReleaseReadLock(&afs_xvcache);
2561 #ifdef AFS_BOZONLOCK_ENV
2562 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
2564 ObtainWriteLock(&tvc->lock, 232);
2566 ObtainWriteLock(&afs_xcbhash, 458);
2567 afs_DequeueCallback(tvc);
2568 tvc->states &= ~(CStatd | CDirty);
2569 ReleaseWriteLock(&afs_xcbhash);
2570 if (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
2571 osi_dnlc_purgedp(tvc);
2572 afs_TryToSmush(tvc, *acred, 1);
2573 ReleaseWriteLock(&tvc->lock);
2574 #ifdef AFS_BOZONLOCK_ENV
2575 afs_BozonUnlock(&tvc->pvnLock, tvc);
2577 ObtainReadLock(&afs_xvcache);
2578 /* our tvc ptr is still good until now */
2582 ReleaseReadLock(&afs_xvcache);
2585 MObtainWriteLock(&afs_xdcache, 328); /* needed if you're going to flush any stuff */
2586 for (i = 0; i < afs_cacheFiles; i++) {
2587 if (!(afs_indexFlags[i] & IFEverUsed))
2588 continue; /* never had any data */
2589 tdc = afs_GetDSlot(i, NULL);
2590 if (tdc->refCount <= 1) { /* too high, in use by running sys call */
2591 ReleaseReadLock(&tdc->tlock);
2592 if (tdc->f.fid.Fid.Volume == volume && tdc->f.fid.Cell == cell) {
2593 if (!(afs_indexFlags[i] & IFDataMod)) {
2594 /* if the file is modified, but has a ref cnt of only 1, then
2595 * someone probably has the file open and is writing into it.
2596 * Better to skip flushing such a file, it will be brought back
2597 * immediately on the next write anyway.
2599 * If we *must* flush, then this code has to be rearranged to call
2600 * afs_storeAllSegments() first */
2601 afs_FlushDCache(tdc);
2605 ReleaseReadLock(&tdc->tlock);
2607 afs_PutDCache(tdc); /* bumped by getdslot */
2609 MReleaseWriteLock(&afs_xdcache);
2611 ObtainReadLock(&afs_xvolume);
2612 for (i = 0; i < NVOLS; i++) {
2613 for (tv = afs_volumes[i]; tv; tv = tv->next) {
2614 if (tv->volume == volume) {
2615 afs_ResetVolumeInfo(tv);
2620 ReleaseReadLock(&afs_xvolume);
2622 /* probably, a user is doing this, probably, because things are screwed up.
2623 * maybe it's the dnlc's fault? */
2630 DECL_PIOCTL(PGetVnodeXStatus)
2632 register afs_int32 code;
2633 struct vcxstat stat;
2636 /* AFS_STATCNT(PGetVnodeXStatus); */
2639 code = afs_VerifyVCache(avc, areq);
2642 if (vType(avc) == VDIR)
2643 mode = PRSFS_LOOKUP;
2646 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
2649 memset(&stat, 0, sizeof(struct vcxstat));
2650 stat.fid = avc->fid;
2651 hset32(stat.DataVersion, hgetlo(avc->m.DataVersion));
2652 stat.lock = avc->lock;
2653 stat.parentVnode = avc->parentVnode;
2654 stat.parentUnique = avc->parentUnique;
2655 hset(stat.flushDV, avc->flushDV);
2656 hset(stat.mapDV, avc->mapDV);
2657 stat.truncPos = avc->truncPos;
2658 { /* just grab the first two - won't break anything... */
2659 struct axscache *ac;
2661 for (i = 0, ac = avc->Access; ac && i < CPSIZE; i++, ac = ac->next) {
2662 stat.randomUid[i] = ac->uid;
2663 stat.randomAccess[i] = ac->axess;
2666 stat.callback = afs_data_pointer_to_int32(avc->callback);
2667 stat.cbExpires = avc->cbExpires;
2668 stat.anyAccess = avc->anyAccess;
2669 stat.opens = avc->opens;
2670 stat.execsOrWriters = avc->execsOrWriters;
2671 stat.flockCount = avc->flockCount;
2672 stat.mvstat = avc->mvstat;
2673 stat.states = avc->states;
2674 memcpy(aout, (char *)&stat, sizeof(struct vcxstat));
2675 *aoutSize = sizeof(struct vcxstat);
2680 DECL_PIOCTL(PGetVnodeXStatus2)
2682 register afs_int32 code;
2683 struct vcxstat2 stat;
2688 code = afs_VerifyVCache(avc, areq);
2691 if (vType(avc) == VDIR)
2692 mode = PRSFS_LOOKUP;
2695 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
2698 memset(&stat, 0, sizeof(struct vcxstat2));
2700 stat.cbExpires = avc->cbExpires;
2701 stat.anyAccess = avc->anyAccess;
2702 stat.mvstat = avc->mvstat;
2703 stat.callerAccess = afs_GetAccessBits(avc, ~0, areq);
2705 memcpy(aout, (char *)&stat, sizeof(struct vcxstat2));
2706 *aoutSize = sizeof(struct vcxstat2);
2710 /* We require root for local sysname changes, but not for remote */
2711 /* (since we don't really believe remote uids anyway) */
2712 /* outname[] shouldn't really be needed- this is left as an excercise */
2713 /* for the reader. */
2714 DECL_PIOCTL(PSetSysName)
2716 char *cp, *cp2 = NULL, inname[MAXSYSNAME], outname[MAXSYSNAME];
2717 int setsysname, foundname = 0;
2718 register struct afs_exporter *exporter;
2719 register struct unixuser *au;
2720 register afs_int32 pag, error;
2721 int t, count, num = 0;
2722 char **sysnamelist[MAXNUMSYSNAMES];
2724 AFS_STATCNT(PSetSysName);
2725 if (!afs_globalVFS) {
2726 /* Afsd is NOT running; disable it */
2727 #if defined(KERNEL_HAVE_UERROR)
2728 return (setuerror(EINVAL), EINVAL);
2733 memset(inname, 0, MAXSYSNAME);
2734 memcpy((char *)&setsysname, ain, sizeof(afs_int32));
2735 ain += sizeof(afs_int32);
2739 if (setsysname < 0 || setsysname > MAXNUMSYSNAMES)
2742 for (cp = ain, count = 0; count < setsysname; count++) {
2743 /* won't go past end of ain since maxsysname*num < ain length */
2745 if (t >= MAXSYSNAME || t <= 0)
2747 /* check for names that can shoot us in the foot */
2748 if (*cp == '.' && (cp[1] == 0 || (cp[1] == '.' && cp[2] == 0)))
2754 /* inname gets first entry in case we're being a translator */
2756 memcpy(inname, ain, t + 1); /* include terminating null */
2760 if ((*acred)->cr_gid == RMTUSER_REQ) { /* Handles all exporters */
2761 pag = PagInCred(*acred);
2763 return EINVAL; /* Better than panicing */
2765 if (!(au = afs_FindUser(pag, -1, READ_LOCK))) {
2766 return EINVAL; /* Better than panicing */
2768 if (!(exporter = au->exporter)) {
2769 afs_PutUser(au, READ_LOCK);
2770 return EINVAL; /* Better than panicing */
2772 error = EXP_SYSNAME(exporter, (setsysname ? cp2 : NULL), sysnamelist,
2775 if (error == ENODEV)
2776 foundname = 0; /* sysname not set yet! */
2778 afs_PutUser(au, READ_LOCK);
2783 strcpy(outname, (*sysnamelist)[0]);
2785 afs_PutUser(au, READ_LOCK);
2787 /* Not xlating, so local case */
2789 osi_Panic("PSetSysName: !afs_sysname\n");
2790 if (!setsysname) { /* user just wants the info */
2791 strcpy(outname, afs_sysname);
2792 foundname = afs_sysnamecount;
2793 *sysnamelist = afs_sysnamelist;
2794 } else { /* Local guy; only root can change sysname */
2795 if (!afs_osi_suser(*acred))
2798 /* clear @sys entries from the dnlc, once afs_lookup can
2799 * do lookups of @sys entries and thinks it can trust them */
2800 /* privs ok, store the entry, ... */
2801 strcpy(afs_sysname, inname);
2802 if (setsysname > 1) { /* ... or list */
2804 for (count = 1; count < setsysname; ++count) {
2805 if (!afs_sysnamelist[count])
2807 ("PSetSysName: no afs_sysnamelist entry to write\n");
2809 memcpy(afs_sysnamelist[count], cp, t + 1); /* include null */
2813 afs_sysnamecount = setsysname;
2817 cp = aout; /* not changing so report back the count and ... */
2818 memcpy(cp, (char *)&foundname, sizeof(afs_int32));
2819 cp += sizeof(afs_int32);
2821 strcpy(cp, outname); /* ... the entry, ... */
2822 cp += strlen(outname) + 1;
2823 for (count = 1; count < foundname; ++count) { /* ... or list. */
2824 if (!(*sysnamelist)[count])
2826 ("PSetSysName: no afs_sysnamelist entry to read\n");
2827 t = strlen((*sysnamelist)[count]);
2828 if (t >= MAXSYSNAME)
2829 osi_Panic("PSetSysName: sysname entry garbled\n");
2830 strcpy(cp, (*sysnamelist)[count]);
2834 *aoutSize = cp - aout;
2839 /* sequential search through the list of touched cells is not a good
2840 * long-term solution here. For small n, though, it should be just
2841 * fine. Should consider special-casing the local cell for large n.
2842 * Likewise for PSetSPrefs.
2844 * s - number of ids in array l[] -- NOT index of last id
2845 * l - array of cell ids which have volumes that need to be sorted
2846 * vlonly - sort vl servers or file servers?
2849 ReSortCells_cb(struct cell *cell, void *arg)
2851 afs_int32 *p = (afs_int32 *) arg;
2852 afs_int32 *l = p + 1;
2855 for (i = 0; i < s; i++) {
2856 if (l[i] == cell->cellNum) {
2857 ObtainWriteLock(&cell->lock, 690);
2858 afs_SortServers(cell->cellHosts, MAXCELLHOSTS);
2859 ReleaseWriteLock(&cell->lock);
2867 ReSortCells(int s, afs_int32 * l, int vlonly)
2875 p = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * (s + 1));
2877 memcpy(p + 1, l, s * sizeof(afs_int32));
2878 afs_TraverseCells(&ReSortCells_cb, p);
2879 afs_osi_Free(p, sizeof(afs_int32) * (s + 1));
2883 ObtainReadLock(&afs_xvolume);
2884 for (i = 0; i < NVOLS; i++) {
2885 for (j = afs_volumes[i]; j; j = j->next) {
2886 for (k = 0; k < s; k++)
2887 if (j->cell == l[k]) {
2888 ObtainWriteLock(&j->lock, 233);
2889 afs_SortServers(j->serverHost, MAXHOSTS);
2890 ReleaseWriteLock(&j->lock);
2895 ReleaseReadLock(&afs_xvolume);
2899 static int debugsetsp = 0;
2901 afs_setsprefs(sp, num, vlonly)
2904 unsigned int vlonly;
2907 int i, j, k, matches, touchedSize;
2908 struct server *srvr = NULL;
2909 afs_int32 touched[34];
2913 for (k = 0; k < num; sp++, k++) {
2915 printf("sp host=%x, rank=%d\n", sp->host.s_addr, sp->rank);
2918 ObtainReadLock(&afs_xserver);
2920 i = SHash(sp->host.s_addr);
2921 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2922 if (sa->sa_ip == sp->host.s_addr) {
2924 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
2925 || (sa->sa_portal == AFS_FSPORT);
2926 if ((!vlonly && isfs) || (vlonly && !isfs)) {
2933 if (sa && matches) { /* found one! */
2935 printf("sa ip=%x, ip_rank=%d\n", sa->sa_ip, sa->sa_iprank);
2937 sa->sa_iprank = sp->rank + afs_randomMod15();
2938 afs_SortOneServer(sa->server);
2941 /* if we don't know yet what cell it's in, this is moot */
2942 for (j = touchedSize - 1;
2943 j >= 0 && touched[j] != srvr->cell->cellNum; j--)
2944 /* is it in our list of touched cells ? */ ;
2945 if (j < 0) { /* no, it's not */
2946 touched[touchedSize++] = srvr->cell->cellNum;
2947 if (touchedSize >= 32) { /* watch for ovrflow */
2948 ReleaseReadLock(&afs_xserver);
2949 ReSortCells(touchedSize, touched, vlonly);
2951 ObtainReadLock(&afs_xserver);
2957 ReleaseReadLock(&afs_xserver);
2958 /* if we didn't find one, start to create one. */
2959 /* Note that it doesn't have a cell yet... */
2961 afs_uint32 temp = sp->host.s_addr;
2963 afs_GetServer(&temp, 1, 0, (vlonly ? AFS_VLPORT : AFS_FSPORT),
2964 WRITE_LOCK, (afsUUID *) 0, 0);
2965 srvr->addr->sa_iprank = sp->rank + afs_randomMod15();
2966 afs_PutServer(srvr, WRITE_LOCK);
2968 } /* for all cited preferences */
2970 ReSortCells(touchedSize, touched, vlonly);
2974 /* Note that this may only be performed by the local root user.
2976 DECL_PIOCTL(PSetSPrefs)
2978 struct setspref *ssp;
2979 AFS_STATCNT(PSetSPrefs);
2981 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2982 return EIO; /* Inappropriate ioctl for device */
2984 if (!afs_osi_suser(*acred))
2987 if (ainSize < sizeof(struct setspref))
2990 ssp = (struct setspref *)ain;
2991 if (ainSize < sizeof(struct spref) * ssp->num_servers)
2994 afs_setsprefs(&(ssp->servers[0]), ssp->num_servers,
2995 (ssp->flags & DBservers));
2999 DECL_PIOCTL(PSetSPrefs33)
3002 AFS_STATCNT(PSetSPrefs);
3003 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3004 return EIO; /* Inappropriate ioctl for device */
3007 if (!afs_osi_suser(*acred))
3010 sp = (struct spref *)ain;
3011 afs_setsprefs(sp, ainSize / (sizeof(struct spref)), 0 /*!vlonly */ );
3015 /* some notes on the following code...
3016 * in the hash table of server structs, all servers with the same IP address
3017 * will be on the same overflow chain.
3018 * This could be sped slightly in some circumstances by having it cache the
3019 * immediately previous slot in the hash table and some supporting information
3020 * Only reports file servers now.
3022 DECL_PIOCTL(PGetSPrefs)
3024 struct sprefrequest *spin; /* input */
3025 struct sprefinfo *spout; /* output */
3026 struct spref *srvout; /* one output component */
3027 int i, j; /* counters for hash table traversal */
3028 struct server *srvr; /* one of CM's server structs */
3030 int vlonly; /* just return vlservers ? */
3033 AFS_STATCNT(PGetSPrefs);
3034 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3035 return EIO; /* Inappropriate ioctl for device */
3038 if (ainSize < sizeof(struct sprefrequest_33)) {
3041 spin = ((struct sprefrequest *)ain);
3044 if (ainSize > sizeof(struct sprefrequest_33)) {
3045 vlonly = (spin->flags & DBservers);
3049 /* struct sprefinfo includes 1 server struct... that size gets added
3050 * in during the loop that follows.
3052 *aoutSize = sizeof(struct sprefinfo) - sizeof(struct spref);
3053 spout = (struct sprefinfo *)aout;
3054 spout->next_offset = spin->offset;
3055 spout->num_servers = 0;
3056 srvout = spout->servers;
3058 ObtainReadLock(&afs_xserver);
3059 for (i = 0, j = 0; j < NSERVERS; j++) { /* sift through hash table */
3060 for (sa = afs_srvAddrs[j]; sa; sa = sa->next_bkt, i++) {
3061 if (spin->offset > (unsigned short)i) {
3062 continue; /* catch up to where we left off */
3064 spout->next_offset++;
3067 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
3068 || (sa->sa_portal == AFS_FSPORT);
3070 if ((vlonly && isfs) || (!vlonly && !isfs)) {
3071 /* only report ranks for vl servers */
3075 srvout->host.s_addr = sa->sa_ip;
3076 srvout->rank = sa->sa_iprank;
3077 *aoutSize += sizeof(struct spref);
3078 spout->num_servers++;
3081 if (*aoutSize > (PIGGYSIZE - sizeof(struct spref))) {
3082 ReleaseReadLock(&afs_xserver); /* no more room! */
3087 ReleaseReadLock(&afs_xserver);
3089 spout->next_offset = 0; /* start over from the beginning next time */
3093 /* Enable/Disable the specified exporter. Must be root to disable an exporter */
3094 int afs_NFSRootOnly = 1;
3095 DECL_PIOCTL(PExportAfs)
3097 afs_int32 export, newint =
3098 0, type, changestate, handleValue, convmode, pwsync, smounts;
3099 register struct afs_exporter *exporter;
3101 AFS_STATCNT(PExportAfs);
3102 memcpy((char *)&handleValue, ain, sizeof(afs_int32));
3103 type = handleValue >> 24;
3108 exporter = exporter_find(type);
3110 export = handleValue & 3;
3111 changestate = handleValue & 0xff;
3112 smounts = (handleValue >> 2) & 3;
3113 pwsync = (handleValue >> 4) & 3;
3114 convmode = (handleValue >> 6) & 3;
3116 changestate = (handleValue >> 16) & 0x1;
3117 convmode = (handleValue >> 16) & 0x2;
3118 pwsync = (handleValue >> 16) & 0x4;
3119 smounts = (handleValue >> 16) & 0x8;
3120 export = handleValue & 0xff;
3123 /* Failed finding desired exporter; */
3127 handleValue = exporter->exp_states;
3128 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3129 *aoutSize = sizeof(afs_int32);
3131 if (!afs_osi_suser(*acred))
3132 return EACCES; /* Only superuser can do this */
3136 exporter->exp_states |= EXP_EXPORTED;
3138 exporter->exp_states &= ~EXP_EXPORTED;
3142 exporter->exp_states |= EXP_UNIXMODE;
3144 exporter->exp_states &= ~EXP_UNIXMODE;
3148 exporter->exp_states |= EXP_PWSYNC;
3150 exporter->exp_states &= ~EXP_PWSYNC;
3154 afs_NFSRootOnly = 0;
3155 exporter->exp_states |= EXP_SUBMOUNTS;
3157 afs_NFSRootOnly = 1;
3158 exporter->exp_states &= ~EXP_SUBMOUNTS;
3161 handleValue = exporter->exp_states;
3162 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3163 *aoutSize = sizeof(afs_int32);
3166 exporter->exp_states |= EXP_EXPORTED;
3168 exporter->exp_states &= ~EXP_EXPORTED;
3170 exporter->exp_states |= EXP_UNIXMODE;
3172 exporter->exp_states &= ~EXP_UNIXMODE;
3174 exporter->exp_states |= EXP_PWSYNC;
3176 exporter->exp_states &= ~EXP_PWSYNC;
3178 afs_NFSRootOnly = 0;
3179 exporter->exp_states |= EXP_SUBMOUNTS;
3181 afs_NFSRootOnly = 1;
3182 exporter->exp_states &= ~EXP_SUBMOUNTS;
3192 struct gaginfo *gagflags;
3194 if (!afs_osi_suser(*acred))
3197 gagflags = (struct gaginfo *)ain;
3198 afs_showflags = gagflags->showflags;
3204 DECL_PIOCTL(PTwiddleRx)
3206 struct rxparams *rxp;
3208 if (!afs_osi_suser(*acred))
3211 rxp = (struct rxparams *)ain;
3213 if (rxp->rx_initReceiveWindow)
3214 rx_initReceiveWindow = rxp->rx_initReceiveWindow;
3215 if (rxp->rx_maxReceiveWindow)
3216 rx_maxReceiveWindow = rxp->rx_maxReceiveWindow;
3217 if (rxp->rx_initSendWindow)
3218 rx_initSendWindow = rxp->rx_initSendWindow;
3219 if (rxp->rx_maxSendWindow)
3220 rx_maxSendWindow = rxp->rx_maxSendWindow;
3221 if (rxp->rxi_nSendFrags)
3222 rxi_nSendFrags = rxp->rxi_nSendFrags;
3223 if (rxp->rxi_nRecvFrags)
3224 rxi_nRecvFrags = rxp->rxi_nRecvFrags;
3225 if (rxp->rxi_OrphanFragSize)
3226 rxi_OrphanFragSize = rxp->rxi_OrphanFragSize;
3227 if (rxp->rx_maxReceiveSize) {
3228 rx_maxReceiveSize = rxp->rx_maxReceiveSize;
3229 rx_maxReceiveSizeUser = rxp->rx_maxReceiveSize;
3231 if (rxp->rx_MyMaxSendSize)
3232 rx_MyMaxSendSize = rxp->rx_MyMaxSendSize;
3237 DECL_PIOCTL(PGetInitParams)
3239 if (sizeof(struct cm_initparams) > PIGGYSIZE)
3242 memcpy(aout, (char *)&cm_initParams, sizeof(struct cm_initparams));
3243 *aoutSize = sizeof(struct cm_initparams);
3247 #ifdef AFS_SGI65_ENV
3248 /* They took crget() from us, so fake it. */
3253 cr = crdup(get_current_cred());
3254 memset((char *)cr, 0, sizeof(cred_t));
3255 #if CELL || CELL_PREPARE
3262 DECL_PIOCTL(PGetRxkcrypt)
3264 memcpy(aout, (char *)&cryptall, sizeof(afs_int32));
3265 *aoutSize = sizeof(afs_int32);
3269 DECL_PIOCTL(PSetRxkcrypt)
3273 if (!afs_osi_suser(*acred))
3275 if (ainSize != sizeof(afs_int32) || ain == NULL)
3277 memcpy((char *)&tmpval, ain, sizeof(afs_int32));
3278 /* if new mappings added later this will need to be changed */
3279 if (tmpval != 0 && tmpval != 1)
3285 #ifdef AFS_NEED_CLIENTCONTEXT
3287 * Create new credentials to correspond to a remote user with given
3288 * <hostaddr, uid, g0, g1>. This allows a server running as root to
3289 * provide pioctl (and other) services to foreign clients (i.e. nfs
3290 * clients) by using this call to `become' the client.
3293 #define PIOCTL_HEADER 6
3295 HandleClientContext(struct afs_ioctl *ablob, int *com,
3296 struct AFS_UCRED **acred, struct AFS_UCRED *credp)
3299 afs_uint32 hostaddr;
3300 afs_int32 uid, g0, g1, i, code, pag, exporter_type;
3301 struct afs_exporter *exporter, *outexporter;
3302 struct AFS_UCRED *newcred;
3303 struct unixuser *au;
3305 #if defined(AFS_SGIMP_ENV)
3306 osi_Assert(ISAFS_GLOCK());
3308 AFS_STATCNT(HandleClientContext);
3309 if (ablob->in_size < PIOCTL_HEADER * sizeof(afs_int32)) {
3310 /* Must at least include the PIOCTL_HEADER header words required by the protocol */
3311 return EINVAL; /* Too small to be good */
3313 ain = inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
3314 AFS_COPYIN(ablob->in, ain, PIOCTL_HEADER * sizeof(afs_int32), code);
3316 osi_FreeLargeSpace(inData);
3320 /* Extract information for remote user */
3321 hostaddr = *((afs_uint32 *) ain);
3322 ain += sizeof(hostaddr);
3323 uid = *((afs_uint32 *) ain);
3325 g0 = *((afs_uint32 *) ain);
3327 g1 = *((afs_uint32 *) ain);
3329 *com = *((afs_uint32 *) ain);
3330 ain += sizeof(afs_int32);
3331 exporter_type = *((afs_uint32 *) ain); /* In case we support more than NFS */
3334 * Of course, one must be root for most of these functions, but
3335 * we'll allow (for knfs) you to set things if the pag is 0 and
3336 * you're setting tokens or unlogging.
3339 if (!afs_osi_suser(credp)) {
3340 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
3341 /* Since SGI's suser() returns explicit failure after the call.. */
3344 /* check for acceptable opcodes for normal folks, which are, so far,
3345 * set tokens and unlog.
3347 if (i != 9 && i != 3 && i != 38 && i != 8) {
3348 osi_FreeLargeSpace(inData);
3353 ablob->in_size -= PIOCTL_HEADER * sizeof(afs_int32);
3354 ablob->in += PIOCTL_HEADER * sizeof(afs_int32);
3355 osi_FreeLargeSpace(inData);
3358 * We map uid 0 to nobody to match the mapping that the nfs
3359 * server does and to ensure that the suser() calls in the afs
3360 * code fails for remote client roots.
3362 uid = afs_nobody; /* NFS_NOBODY == -2 */
3365 #if defined(AFS_LINUX26_ENV)
3366 newcred->cr_group_info = groups_alloc(0);
3368 #ifdef AFS_AIX41_ENV
3371 newcred->cr_gid = RMTUSER_REQ;
3372 #ifdef AFS_AIX51_ENV
3373 newcred->cr_groupset.gs_union.un_groups[0] = g0;
3374 newcred->cr_groupset.gs_union.un_groups[1] = g1;
3376 newcred->cr_groups[0] = g0;
3377 newcred->cr_groups[1] = g1;
3380 newcred->cr_ngrps = 2;
3382 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV)
3383 newcred->cr_ngroups = 2;
3385 for (i = 2; i < NGROUPS; i++)
3386 newcred->cr_groups[i] = NOGROUP;
3389 #if !defined(AFS_OSF_ENV)
3390 afs_nfsclient_init(); /* before looking for exporter, ensure one exists */
3392 if (!(exporter = exporter_find(exporter_type))) {
3393 /* Exporter wasn't initialized or an invalid exporter type */
3397 if (exporter->exp_states & EXP_PWSYNC) {
3398 if (uid != credp->cr_uid) {
3400 return ENOEXEC; /* XXX Find a better errno XXX */
3403 newcred->cr_uid = uid; /* Only temporary */
3404 code = EXP_REQHANDLER(exporter, &newcred, hostaddr, &pag, &outexporter);
3405 /* The client's pag is the only unique identifier for it */
3406 newcred->cr_uid = pag;
3408 if (!code && *com == PSETPAG) {
3409 /* Special case for 'setpag' */
3410 afs_uint32 pagvalue = genpag();
3412 au = afs_GetUser(pagvalue, -1, WRITE_LOCK); /* a new unixuser struct */
3414 * Note that we leave the 'outexporter' struct held so it won't
3417 au->exporter = outexporter;
3418 if (ablob->out_size >= 4) {
3419 AFS_COPYOUT((char *)&pagvalue, ablob->out, sizeof(afs_int32),
3422 afs_PutUser(au, WRITE_LOCK);
3425 return PSETPAG; /* Special return for setpag */
3427 EXP_RELE(outexporter);
3431 #endif /* AFS_NEED_CLIENTCONTEXT */
3433 /* get all interface addresses of this client */
3435 DECL_PIOCTL(PGetCPrefs)
3437 struct sprefrequest *spin; /* input */
3438 struct sprefinfo *spout; /* output */
3439 struct spref *srvout; /* one output component */
3443 AFS_STATCNT(PGetCPrefs);
3444 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3445 return EIO; /* Inappropriate ioctl for device */
3447 if (ainSize < sizeof(struct sprefrequest))
3450 spin = (struct sprefrequest *)ain;
3451 spout = (struct sprefinfo *)aout;
3453 maxNumber = spin->num_servers; /* max addrs this time */
3454 srvout = spout->servers;
3456 ObtainReadLock(&afs_xinterface);
3458 /* copy out the client interface information from the
3459 ** kernel data structure "interface" to the output buffer
3461 for (i = spin->offset, j = 0; (i < afs_cb_interface.numberOfInterfaces)
3462 && (j < maxNumber); i++, j++, srvout++)
3463 srvout->host.s_addr = afs_cb_interface.addr_in[i];
3465 spout->num_servers = j;
3466 *aoutSize = sizeof(struct sprefinfo) + (j - 1) * sizeof(struct spref);
3468 if (i >= afs_cb_interface.numberOfInterfaces)
3469 spout->next_offset = 0; /* start from beginning again */
3471 spout->next_offset = spin->offset + j;
3473 ReleaseReadLock(&afs_xinterface);
3477 DECL_PIOCTL(PSetCPrefs)
3479 struct setspref *sin;
3482 AFS_STATCNT(PSetCPrefs);
3483 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3484 return EIO; /* Inappropriate ioctl for device */
3486 sin = (struct setspref *)ain;
3488 if (ainSize < sizeof(struct setspref))
3490 #if 0 /* num_servers is unsigned */
3491 if (sin->num_servers < 0)
3494 if (sin->num_servers > AFS_MAX_INTERFACE_ADDR)
3497 ObtainWriteLock(&afs_xinterface, 412);
3498 afs_cb_interface.numberOfInterfaces = sin->num_servers;
3499 for (i = 0; (unsigned short)i < sin->num_servers; i++)
3500 afs_cb_interface.addr_in[i] = sin->servers[i].host.s_addr;
3502 ReleaseWriteLock(&afs_xinterface);
3506 DECL_PIOCTL(PFlushMount)
3508 register afs_int32 code;
3509 register struct vcache *tvc;
3510 register struct dcache *tdc;
3511 struct VenusFid tfid;
3513 struct sysname_info sysState;
3514 afs_size_t offset, len;
3516 AFS_STATCNT(PFlushMount);
3519 code = afs_VerifyVCache(avc, areq);
3522 if (vType(avc) != VDIR) {
3525 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
3528 Check_AtSys(avc, ain, &sysState, areq);
3529 ObtainReadLock(&tdc->lock);
3531 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
3532 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
3533 ReleaseReadLock(&tdc->lock);
3534 afs_PutDCache(tdc); /* we're done with the data */
3535 bufp = sysState.name;
3539 tfid.Cell = avc->fid.Cell;
3540 tfid.Fid.Volume = avc->fid.Fid.Volume;
3541 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
3542 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
3544 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3550 if (tvc->mvstat != 1) {
3555 #ifdef AFS_BOZONLOCK_ENV
3556 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
3558 ObtainWriteLock(&tvc->lock, 649);
3559 ObtainWriteLock(&afs_xcbhash, 650);
3560 afs_DequeueCallback(tvc);
3561 tvc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
3562 ReleaseWriteLock(&afs_xcbhash);
3563 /* now find the disk cache entries */
3564 afs_TryToSmush(tvc, *acred, 1);
3565 osi_dnlc_purgedp(tvc);
3566 if (tvc->linkData && !(tvc->states & CCore)) {
3567 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
3568 tvc->linkData = NULL;
3570 ReleaseWriteLock(&tvc->lock);
3571 #ifdef AFS_BOZONLOCK_ENV
3572 afs_BozonUnlock(&tvc->pvnLock, tvc);
3576 if (sysState.allocked)
3577 osi_FreeLargeSpace(bufp);
3581 DECL_PIOCTL(PRxStatProc)
3586 if (!afs_osi_suser(*acred)) {
3590 if (ainSize != sizeof(afs_int32)) {
3594 memcpy((char *)&flags, ain, sizeof(afs_int32));
3595 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3599 if (flags & AFSCALL_RXSTATS_ENABLE) {
3600 rx_enableProcessRPCStats();
3602 if (flags & AFSCALL_RXSTATS_DISABLE) {
3603 rx_disableProcessRPCStats();
3605 if (flags & AFSCALL_RXSTATS_CLEAR) {
3606 rx_clearProcessRPCStats(AFS_RX_STATS_CLEAR_ALL);
3614 DECL_PIOCTL(PRxStatPeer)
3619 if (!afs_osi_suser(*acred)) {
3623 if (ainSize != sizeof(afs_int32)) {
3627 memcpy((char *)&flags, ain, sizeof(afs_int32));
3628 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3632 if (flags & AFSCALL_RXSTATS_ENABLE) {
3633 rx_enablePeerRPCStats();
3635 if (flags & AFSCALL_RXSTATS_DISABLE) {
3636 rx_disablePeerRPCStats();
3638 if (flags & AFSCALL_RXSTATS_CLEAR) {
3639 rx_clearPeerRPCStats(AFS_RX_STATS_CLEAR_ALL);
3646 DECL_PIOCTL(PPrefetchFromTape)
3648 register afs_int32 code, code1;
3651 struct rx_call *tcall;
3652 struct AFSVolSync tsync;
3653 struct AFSFetchStatus OutStatus;
3654 struct AFSCallBack CallBack;
3655 struct VenusFid tfid;
3659 AFS_STATCNT(PSetAcl);
3663 if (ain && (ainSize == 3 * sizeof(afs_int32)))
3664 Fid = (struct AFSFid *)ain;
3666 Fid = &avc->fid.Fid;
3667 tfid.Cell = avc->fid.Cell;
3668 tfid.Fid.Volume = Fid->Volume;
3669 tfid.Fid.Vnode = Fid->Vnode;
3670 tfid.Fid.Unique = Fid->Unique;
3672 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3674 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3675 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &avc->fid);
3678 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3679 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &tvc->fid);
3682 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3686 tcall = rx_NewCall(tc->id);
3688 StartRXAFS_FetchData(tcall, (struct AFSFid *)&tvc->fid.Fid, 0,
3691 bytes = rx_Read(tcall, (char *)aout, sizeof(afs_int32));
3693 EndRXAFS_FetchData(tcall, &OutStatus, &CallBack, &tsync);
3695 code1 = rx_EndCall(tcall, code);
3699 } while (afs_Analyze
3700 (tc, code, &tvc->fid, areq, AFS_STATS_FS_RPCIDX_RESIDENCYRPCS,
3701 SHARED_LOCK, NULL));
3702 /* This call is done only to have the callback things handled correctly */
3703 afs_FetchStatus(tvc, &tfid, areq, &OutStatus);
3707 *aoutSize = sizeof(afs_int32);
3712 DECL_PIOCTL(PResidencyCmd)
3714 register afs_int32 code;
3717 struct ResidencyCmdInputs *Inputs;
3718 struct ResidencyCmdOutputs *Outputs;
3719 struct VenusFid tfid;
3722 Inputs = (struct ResidencyCmdInputs *)ain;
3723 Outputs = (struct ResidencyCmdOutputs *)aout;
3726 if (!ain || ainSize != sizeof(struct ResidencyCmdInputs))
3731 Fid = &avc->fid.Fid;
3733 tfid.Cell = avc->fid.Cell;
3734 tfid.Fid.Volume = Fid->Volume;
3735 tfid.Fid.Vnode = Fid->Vnode;
3736 tfid.Fid.Unique = Fid->Unique;
3738 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3739 afs_Trace3(afs_iclSetp, CM_TRACE_RESIDCMD, ICL_TYPE_POINTER, tvc,
3740 ICL_TYPE_INT32, Inputs->command, ICL_TYPE_FID, &tfid);
3744 if (Inputs->command) {
3746 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3750 RXAFS_ResidencyCmd(tc->id, Fid, Inputs,
3751 (struct ResidencyCmdOutputs *)aout);
3755 } while (afs_Analyze
3756 (tc, code, &tvc->fid, areq,
3757 AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK, NULL));
3758 /* This call is done to have the callback things handled correctly */
3759 afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3760 } else { /* just a status request, return also link data */
3762 Outputs->code = afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3763 Outputs->chars[0] = 0;
3764 if (vType(tvc) == VLNK) {
3765 ObtainWriteLock(&tvc->lock, 555);
3766 if (afs_HandleLink(tvc, areq) == 0)
3767 strncpy((char *)&Outputs->chars, tvc->linkData, MAXCMDCHARS);
3768 ReleaseWriteLock(&tvc->lock);
3775 *aoutSize = sizeof(struct ResidencyCmdOutputs);
3780 DECL_PIOCTL(PCallBackAddr)
3783 afs_uint32 addr, code;
3789 struct unixuser *tu;
3790 struct srvAddr **addrs;
3792 /*AFS_STATCNT(PCallBackAddr); */
3793 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
3794 return EIO; /* Inappropriate ioctl for device */
3796 if (!afs_osi_suser(acred))
3799 if (ainSize < sizeof(afs_int32))
3802 memcpy(&addr, ain, sizeof(afs_int32));
3804 ObtainReadLock(&afs_xinterface);
3805 for (i = 0; (unsigned short)i < afs_cb_interface.numberOfInterfaces; i++) {
3806 if (afs_cb_interface.addr_in[i] == addr)
3810 ReleaseWriteLock(&afs_xinterface);
3812 if (afs_cb_interface.addr_in[i] != addr)
3815 ObtainReadLock(&afs_xserver); /* Necessary? */
3816 ObtainReadLock(&afs_xsrvAddr);
3819 for (i = 0; i < NSERVERS; i++) {
3820 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3825 addrs = afs_osi_Alloc(srvAddrCount * sizeof(*addrs));
3827 for (i = 0; i < NSERVERS; i++) {
3828 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3829 if (j >= srvAddrCount)
3835 ReleaseReadLock(&afs_xsrvAddr);
3836 ReleaseReadLock(&afs_xserver);
3838 for (i = 0; i < j; i++) {
3844 /* vlserver has no callback conn */
3845 if (sa->sa_portal == AFS_VLPORT) {
3849 if (!ts->cell) /* not really an active server, anyway, it must */
3850 continue; /* have just been added by setsprefs */
3852 /* get a connection, even if host is down; bumps conn ref count */
3853 tu = afs_GetUser(areq->uid, ts->cell->cellNum, SHARED_LOCK);
3854 tc = afs_ConnBySA(sa, ts->cell->fsport, ts->cell->cellNum, tu,
3855 1 /*force */ , 1 /*create */ , SHARED_LOCK);
3856 afs_PutUser(tu, SHARED_LOCK);
3860 if ((sa->sa_flags & SRVADDR_ISDOWN) || afs_HaveCallBacksFrom(ts)) {
3861 if (sa->sa_flags & SRVADDR_ISDOWN) {
3862 rx_SetConnDeadTime(tc->id, 3);
3864 #ifdef RX_ENABLE_LOCKS
3866 #endif /* RX_ENABLE_LOCKS */
3867 code = RXAFS_CallBackRxConnAddr(tc->id, &addr);
3868 #ifdef RX_ENABLE_LOCKS
3870 #endif /* RX_ENABLE_LOCKS */
3872 afs_PutConn(tc, SHARED_LOCK); /* done with it now */
3873 } /* Outer loop over addrs */
3874 #endif /* UKERNEL */