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;
2531 AFS_STATCNT(PFlushVolumeData);
2534 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2535 return EIO; /* Inappropriate ioctl for device */
2537 volume = avc->fid.Fid.Volume; /* who to zap */
2538 cell = avc->fid.Cell;
2541 * Clear stat'd flag from all vnodes from this volume; this will invalidate all
2542 * the vcaches associated with the volume.
2544 ObtainReadLock(&afs_xvcache);
2545 i = VCHashV(&avc->fid);
2546 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->vhnext) {
2547 if (tvc->fid.Fid.Volume == volume && tvc->fid.Cell == cell) {
2548 #if defined(AFS_SGI_ENV) || defined(AFS_OSF_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
2549 VN_HOLD(AFSTOV(tvc));
2551 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2554 VREFCOUNT_INC(tvc); /* AIX, apparently */
2557 ReleaseReadLock(&afs_xvcache);
2558 #ifdef AFS_BOZONLOCK_ENV
2559 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
2561 ObtainWriteLock(&tvc->lock, 232);
2563 ObtainWriteLock(&afs_xcbhash, 458);
2564 afs_DequeueCallback(tvc);
2565 tvc->states &= ~(CStatd | CDirty);
2566 ReleaseWriteLock(&afs_xcbhash);
2567 if (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
2568 osi_dnlc_purgedp(tvc);
2569 afs_TryToSmush(tvc, *acred, 1);
2570 ReleaseWriteLock(&tvc->lock);
2571 #ifdef AFS_BOZONLOCK_ENV
2572 afs_BozonUnlock(&tvc->pvnLock, tvc);
2574 ObtainReadLock(&afs_xvcache);
2575 /* our tvc ptr is still good until now */
2579 ReleaseReadLock(&afs_xvcache);
2582 MObtainWriteLock(&afs_xdcache, 328); /* needed if you're going to flush any stuff */
2583 for (i = 0; i < afs_cacheFiles; i++) {
2584 if (!(afs_indexFlags[i] & IFEverUsed))
2585 continue; /* never had any data */
2586 tdc = afs_GetDSlot(i, NULL);
2587 if (tdc->refCount <= 1) { /* too high, in use by running sys call */
2588 ReleaseReadLock(&tdc->tlock);
2589 if (tdc->f.fid.Fid.Volume == volume && tdc->f.fid.Cell == cell) {
2590 if (!(afs_indexFlags[i] & IFDataMod)) {
2591 /* if the file is modified, but has a ref cnt of only 1, then
2592 * someone probably has the file open and is writing into it.
2593 * Better to skip flushing such a file, it will be brought back
2594 * immediately on the next write anyway.
2596 * If we *must* flush, then this code has to be rearranged to call
2597 * afs_storeAllSegments() first */
2598 afs_FlushDCache(tdc);
2602 ReleaseReadLock(&tdc->tlock);
2604 afs_PutDCache(tdc); /* bumped by getdslot */
2606 MReleaseWriteLock(&afs_xdcache);
2608 ObtainReadLock(&afs_xvolume);
2609 for (i = 0; i < NVOLS; i++) {
2610 for (tv = afs_volumes[i]; tv; tv = tv->next) {
2611 if (tv->volume == volume) {
2612 afs_ResetVolumeInfo(tv);
2617 ReleaseReadLock(&afs_xvolume);
2619 /* probably, a user is doing this, probably, because things are screwed up.
2620 * maybe it's the dnlc's fault? */
2627 DECL_PIOCTL(PGetVnodeXStatus)
2629 register afs_int32 code;
2630 struct vcxstat stat;
2633 /* AFS_STATCNT(PGetVnodeXStatus); */
2636 code = afs_VerifyVCache(avc, areq);
2639 if (vType(avc) == VDIR)
2640 mode = PRSFS_LOOKUP;
2643 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
2646 memset(&stat, 0, sizeof(struct vcxstat));
2647 stat.fid = avc->fid;
2648 hset32(stat.DataVersion, hgetlo(avc->m.DataVersion));
2649 stat.lock = avc->lock;
2650 stat.parentVnode = avc->parentVnode;
2651 stat.parentUnique = avc->parentUnique;
2652 hset(stat.flushDV, avc->flushDV);
2653 hset(stat.mapDV, avc->mapDV);
2654 stat.truncPos = avc->truncPos;
2655 { /* just grab the first two - won't break anything... */
2656 struct axscache *ac;
2658 for (i = 0, ac = avc->Access; ac && i < CPSIZE; i++, ac = ac->next) {
2659 stat.randomUid[i] = ac->uid;
2660 stat.randomAccess[i] = ac->axess;
2663 stat.callback = afs_data_pointer_to_int32(avc->callback);
2664 stat.cbExpires = avc->cbExpires;
2665 stat.anyAccess = avc->anyAccess;
2666 stat.opens = avc->opens;
2667 stat.execsOrWriters = avc->execsOrWriters;
2668 stat.flockCount = avc->flockCount;
2669 stat.mvstat = avc->mvstat;
2670 stat.states = avc->states;
2671 memcpy(aout, (char *)&stat, sizeof(struct vcxstat));
2672 *aoutSize = sizeof(struct vcxstat);
2677 DECL_PIOCTL(PGetVnodeXStatus2)
2679 register afs_int32 code;
2680 struct vcxstat2 stat;
2685 code = afs_VerifyVCache(avc, areq);
2688 if (vType(avc) == VDIR)
2689 mode = PRSFS_LOOKUP;
2692 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
2695 memset(&stat, 0, sizeof(struct vcxstat2));
2697 stat.cbExpires = avc->cbExpires;
2698 stat.anyAccess = avc->anyAccess;
2699 stat.mvstat = avc->mvstat;
2700 stat.callerAccess = afs_GetAccessBits(avc, ~0, areq);
2702 memcpy(aout, (char *)&stat, sizeof(struct vcxstat2));
2703 *aoutSize = sizeof(struct vcxstat2);
2707 /* We require root for local sysname changes, but not for remote */
2708 /* (since we don't really believe remote uids anyway) */
2709 /* outname[] shouldn't really be needed- this is left as an excercise */
2710 /* for the reader. */
2711 DECL_PIOCTL(PSetSysName)
2713 char *cp, *cp2 = NULL, inname[MAXSYSNAME], outname[MAXSYSNAME];
2714 int setsysname, foundname = 0;
2715 register struct afs_exporter *exporter;
2716 register struct unixuser *au;
2717 register afs_int32 pag, error;
2718 int t, count, num = 0;
2719 char **sysnamelist[MAXNUMSYSNAMES];
2721 AFS_STATCNT(PSetSysName);
2722 if (!afs_globalVFS) {
2723 /* Afsd is NOT running; disable it */
2724 #if defined(KERNEL_HAVE_UERROR)
2725 return (setuerror(EINVAL), EINVAL);
2730 memset(inname, 0, MAXSYSNAME);
2731 memcpy((char *)&setsysname, ain, sizeof(afs_int32));
2732 ain += sizeof(afs_int32);
2736 if (setsysname < 0 || setsysname > MAXNUMSYSNAMES)
2739 for (cp = ain, count = 0; count < setsysname; count++) {
2740 /* won't go past end of ain since maxsysname*num < ain length */
2742 if (t >= MAXSYSNAME || t <= 0)
2744 /* check for names that can shoot us in the foot */
2745 if (*cp == '.' && (cp[1] == 0 || (cp[1] == '.' && cp[2] == 0)))
2751 /* inname gets first entry in case we're being a translator */
2753 memcpy(inname, ain, t + 1); /* include terminating null */
2757 if ((*acred)->cr_gid == RMTUSER_REQ) { /* Handles all exporters */
2758 pag = PagInCred(*acred);
2760 return EINVAL; /* Better than panicing */
2762 if (!(au = afs_FindUser(pag, -1, READ_LOCK))) {
2763 return EINVAL; /* Better than panicing */
2765 if (!(exporter = au->exporter)) {
2766 afs_PutUser(au, READ_LOCK);
2767 return EINVAL; /* Better than panicing */
2769 error = EXP_SYSNAME(exporter, (setsysname ? cp2 : NULL), sysnamelist,
2772 if (error == ENODEV)
2773 foundname = 0; /* sysname not set yet! */
2775 afs_PutUser(au, READ_LOCK);
2780 strcpy(outname, (*sysnamelist)[0]);
2782 afs_PutUser(au, READ_LOCK);
2784 /* Not xlating, so local case */
2786 osi_Panic("PSetSysName: !afs_sysname\n");
2787 if (!setsysname) { /* user just wants the info */
2788 strcpy(outname, afs_sysname);
2789 foundname = afs_sysnamecount;
2790 *sysnamelist = afs_sysnamelist;
2791 } else { /* Local guy; only root can change sysname */
2792 if (!afs_osi_suser(*acred))
2795 /* clear @sys entries from the dnlc, once afs_lookup can
2796 * do lookups of @sys entries and thinks it can trust them */
2797 /* privs ok, store the entry, ... */
2798 strcpy(afs_sysname, inname);
2799 if (setsysname > 1) { /* ... or list */
2801 for (count = 1; count < setsysname; ++count) {
2802 if (!afs_sysnamelist[count])
2804 ("PSetSysName: no afs_sysnamelist entry to write\n");
2806 memcpy(afs_sysnamelist[count], cp, t + 1); /* include null */
2810 afs_sysnamecount = setsysname;
2814 cp = aout; /* not changing so report back the count and ... */
2815 memcpy(cp, (char *)&foundname, sizeof(afs_int32));
2816 cp += sizeof(afs_int32);
2818 strcpy(cp, outname); /* ... the entry, ... */
2819 cp += strlen(outname) + 1;
2820 for (count = 1; count < foundname; ++count) { /* ... or list. */
2821 if (!(*sysnamelist)[count])
2823 ("PSetSysName: no afs_sysnamelist entry to read\n");
2824 t = strlen((*sysnamelist)[count]);
2825 if (t >= MAXSYSNAME)
2826 osi_Panic("PSetSysName: sysname entry garbled\n");
2827 strcpy(cp, (*sysnamelist)[count]);
2831 *aoutSize = cp - aout;
2836 /* sequential search through the list of touched cells is not a good
2837 * long-term solution here. For small n, though, it should be just
2838 * fine. Should consider special-casing the local cell for large n.
2839 * Likewise for PSetSPrefs.
2841 * s - number of ids in array l[] -- NOT index of last id
2842 * l - array of cell ids which have volumes that need to be sorted
2843 * vlonly - sort vl servers or file servers?
2846 ReSortCells_cb(struct cell *cell, void *arg)
2848 afs_int32 *p = (afs_int32 *) arg;
2849 afs_int32 *l = p + 1;
2852 for (i = 0; i < s; i++) {
2853 if (l[i] == cell->cellNum) {
2854 ObtainWriteLock(&cell->lock, 690);
2855 afs_SortServers(cell->cellHosts, MAXCELLHOSTS);
2856 ReleaseWriteLock(&cell->lock);
2864 ReSortCells(int s, afs_int32 * l, int vlonly)
2872 p = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * (s + 1));
2874 memcpy(p + 1, l, s * sizeof(afs_int32));
2875 afs_TraverseCells(&ReSortCells_cb, p);
2876 afs_osi_Free(p, sizeof(afs_int32) * (s + 1));
2880 ObtainReadLock(&afs_xvolume);
2881 for (i = 0; i < NVOLS; i++) {
2882 for (j = afs_volumes[i]; j; j = j->next) {
2883 for (k = 0; k < s; k++)
2884 if (j->cell == l[k]) {
2885 ObtainWriteLock(&j->lock, 233);
2886 afs_SortServers(j->serverHost, MAXHOSTS);
2887 ReleaseWriteLock(&j->lock);
2892 ReleaseReadLock(&afs_xvolume);
2896 static int debugsetsp = 0;
2898 afs_setsprefs(sp, num, vlonly)
2901 unsigned int vlonly;
2904 int i, j, k, matches, touchedSize;
2905 struct server *srvr = NULL;
2906 afs_int32 touched[34];
2910 for (k = 0; k < num; sp++, k++) {
2912 printf("sp host=%x, rank=%d\n", sp->host.s_addr, sp->rank);
2915 ObtainReadLock(&afs_xserver);
2917 i = SHash(sp->host.s_addr);
2918 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2919 if (sa->sa_ip == sp->host.s_addr) {
2921 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
2922 || (sa->sa_portal == AFS_FSPORT);
2923 if ((!vlonly && isfs) || (vlonly && !isfs)) {
2930 if (sa && matches) { /* found one! */
2932 printf("sa ip=%x, ip_rank=%d\n", sa->sa_ip, sa->sa_iprank);
2934 sa->sa_iprank = sp->rank + afs_randomMod15();
2935 afs_SortOneServer(sa->server);
2938 /* if we don't know yet what cell it's in, this is moot */
2939 for (j = touchedSize - 1;
2940 j >= 0 && touched[j] != srvr->cell->cellNum; j--)
2941 /* is it in our list of touched cells ? */ ;
2942 if (j < 0) { /* no, it's not */
2943 touched[touchedSize++] = srvr->cell->cellNum;
2944 if (touchedSize >= 32) { /* watch for ovrflow */
2945 ReleaseReadLock(&afs_xserver);
2946 ReSortCells(touchedSize, touched, vlonly);
2948 ObtainReadLock(&afs_xserver);
2954 ReleaseReadLock(&afs_xserver);
2955 /* if we didn't find one, start to create one. */
2956 /* Note that it doesn't have a cell yet... */
2958 afs_uint32 temp = sp->host.s_addr;
2960 afs_GetServer(&temp, 1, 0, (vlonly ? AFS_VLPORT : AFS_FSPORT),
2961 WRITE_LOCK, (afsUUID *) 0, 0);
2962 srvr->addr->sa_iprank = sp->rank + afs_randomMod15();
2963 afs_PutServer(srvr, WRITE_LOCK);
2965 } /* for all cited preferences */
2967 ReSortCells(touchedSize, touched, vlonly);
2971 /* Note that this may only be performed by the local root user.
2973 DECL_PIOCTL(PSetSPrefs)
2975 struct setspref *ssp;
2976 AFS_STATCNT(PSetSPrefs);
2978 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2979 return EIO; /* Inappropriate ioctl for device */
2981 if (!afs_osi_suser(*acred))
2984 if (ainSize < sizeof(struct setspref))
2987 ssp = (struct setspref *)ain;
2988 if (ainSize < sizeof(struct spref) * ssp->num_servers)
2991 afs_setsprefs(&(ssp->servers[0]), ssp->num_servers,
2992 (ssp->flags & DBservers));
2996 DECL_PIOCTL(PSetSPrefs33)
2999 AFS_STATCNT(PSetSPrefs);
3000 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3001 return EIO; /* Inappropriate ioctl for device */
3004 if (!afs_osi_suser(*acred))
3007 sp = (struct spref *)ain;
3008 afs_setsprefs(sp, ainSize / (sizeof(struct spref)), 0 /*!vlonly */ );
3012 /* some notes on the following code...
3013 * in the hash table of server structs, all servers with the same IP address
3014 * will be on the same overflow chain.
3015 * This could be sped slightly in some circumstances by having it cache the
3016 * immediately previous slot in the hash table and some supporting information
3017 * Only reports file servers now.
3019 DECL_PIOCTL(PGetSPrefs)
3021 struct sprefrequest *spin; /* input */
3022 struct sprefinfo *spout; /* output */
3023 struct spref *srvout; /* one output component */
3024 int i, j; /* counters for hash table traversal */
3025 struct server *srvr; /* one of CM's server structs */
3027 int vlonly; /* just return vlservers ? */
3030 AFS_STATCNT(PGetSPrefs);
3031 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3032 return EIO; /* Inappropriate ioctl for device */
3035 if (ainSize < sizeof(struct sprefrequest_33)) {
3038 spin = ((struct sprefrequest *)ain);
3041 if (ainSize > sizeof(struct sprefrequest_33)) {
3042 vlonly = (spin->flags & DBservers);
3046 /* struct sprefinfo includes 1 server struct... that size gets added
3047 * in during the loop that follows.
3049 *aoutSize = sizeof(struct sprefinfo) - sizeof(struct spref);
3050 spout = (struct sprefinfo *)aout;
3051 spout->next_offset = spin->offset;
3052 spout->num_servers = 0;
3053 srvout = spout->servers;
3055 ObtainReadLock(&afs_xserver);
3056 for (i = 0, j = 0; j < NSERVERS; j++) { /* sift through hash table */
3057 for (sa = afs_srvAddrs[j]; sa; sa = sa->next_bkt, i++) {
3058 if (spin->offset > (unsigned short)i) {
3059 continue; /* catch up to where we left off */
3061 spout->next_offset++;
3064 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
3065 || (sa->sa_portal == AFS_FSPORT);
3067 if ((vlonly && isfs) || (!vlonly && !isfs)) {
3068 /* only report ranks for vl servers */
3072 srvout->host.s_addr = sa->sa_ip;
3073 srvout->rank = sa->sa_iprank;
3074 *aoutSize += sizeof(struct spref);
3075 spout->num_servers++;
3078 if (*aoutSize > (PIGGYSIZE - sizeof(struct spref))) {
3079 ReleaseReadLock(&afs_xserver); /* no more room! */
3084 ReleaseReadLock(&afs_xserver);
3086 spout->next_offset = 0; /* start over from the beginning next time */
3090 /* Enable/Disable the specified exporter. Must be root to disable an exporter */
3091 int afs_NFSRootOnly = 1;
3092 DECL_PIOCTL(PExportAfs)
3094 afs_int32 export, newint =
3095 0, type, changestate, handleValue, convmode, pwsync, smounts;
3096 register struct afs_exporter *exporter;
3098 AFS_STATCNT(PExportAfs);
3099 memcpy((char *)&handleValue, ain, sizeof(afs_int32));
3100 type = handleValue >> 24;
3105 exporter = exporter_find(type);
3107 export = handleValue & 3;
3108 changestate = handleValue & 0xff;
3109 smounts = (handleValue >> 2) & 3;
3110 pwsync = (handleValue >> 4) & 3;
3111 convmode = (handleValue >> 6) & 3;
3113 changestate = (handleValue >> 16) & 0x1;
3114 convmode = (handleValue >> 16) & 0x2;
3115 pwsync = (handleValue >> 16) & 0x4;
3116 smounts = (handleValue >> 16) & 0x8;
3117 export = handleValue & 0xff;
3120 /* Failed finding desired exporter; */
3124 handleValue = exporter->exp_states;
3125 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3126 *aoutSize = sizeof(afs_int32);
3128 if (!afs_osi_suser(*acred))
3129 return EACCES; /* Only superuser can do this */
3133 exporter->exp_states |= EXP_EXPORTED;
3135 exporter->exp_states &= ~EXP_EXPORTED;
3139 exporter->exp_states |= EXP_UNIXMODE;
3141 exporter->exp_states &= ~EXP_UNIXMODE;
3145 exporter->exp_states |= EXP_PWSYNC;
3147 exporter->exp_states &= ~EXP_PWSYNC;
3151 afs_NFSRootOnly = 0;
3152 exporter->exp_states |= EXP_SUBMOUNTS;
3154 afs_NFSRootOnly = 1;
3155 exporter->exp_states &= ~EXP_SUBMOUNTS;
3158 handleValue = exporter->exp_states;
3159 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3160 *aoutSize = sizeof(afs_int32);
3163 exporter->exp_states |= EXP_EXPORTED;
3165 exporter->exp_states &= ~EXP_EXPORTED;
3167 exporter->exp_states |= EXP_UNIXMODE;
3169 exporter->exp_states &= ~EXP_UNIXMODE;
3171 exporter->exp_states |= EXP_PWSYNC;
3173 exporter->exp_states &= ~EXP_PWSYNC;
3175 afs_NFSRootOnly = 0;
3176 exporter->exp_states |= EXP_SUBMOUNTS;
3178 afs_NFSRootOnly = 1;
3179 exporter->exp_states &= ~EXP_SUBMOUNTS;
3189 struct gaginfo *gagflags;
3191 if (!afs_osi_suser(*acred))
3194 gagflags = (struct gaginfo *)ain;
3195 afs_showflags = gagflags->showflags;
3201 DECL_PIOCTL(PTwiddleRx)
3203 struct rxparams *rxp;
3205 if (!afs_osi_suser(*acred))
3208 rxp = (struct rxparams *)ain;
3210 if (rxp->rx_initReceiveWindow)
3211 rx_initReceiveWindow = rxp->rx_initReceiveWindow;
3212 if (rxp->rx_maxReceiveWindow)
3213 rx_maxReceiveWindow = rxp->rx_maxReceiveWindow;
3214 if (rxp->rx_initSendWindow)
3215 rx_initSendWindow = rxp->rx_initSendWindow;
3216 if (rxp->rx_maxSendWindow)
3217 rx_maxSendWindow = rxp->rx_maxSendWindow;
3218 if (rxp->rxi_nSendFrags)
3219 rxi_nSendFrags = rxp->rxi_nSendFrags;
3220 if (rxp->rxi_nRecvFrags)
3221 rxi_nRecvFrags = rxp->rxi_nRecvFrags;
3222 if (rxp->rxi_OrphanFragSize)
3223 rxi_OrphanFragSize = rxp->rxi_OrphanFragSize;
3224 if (rxp->rx_maxReceiveSize) {
3225 rx_maxReceiveSize = rxp->rx_maxReceiveSize;
3226 rx_maxReceiveSizeUser = rxp->rx_maxReceiveSize;
3228 if (rxp->rx_MyMaxSendSize)
3229 rx_MyMaxSendSize = rxp->rx_MyMaxSendSize;
3234 DECL_PIOCTL(PGetInitParams)
3236 if (sizeof(struct cm_initparams) > PIGGYSIZE)
3239 memcpy(aout, (char *)&cm_initParams, sizeof(struct cm_initparams));
3240 *aoutSize = sizeof(struct cm_initparams);
3244 #ifdef AFS_SGI65_ENV
3245 /* They took crget() from us, so fake it. */
3250 cr = crdup(get_current_cred());
3251 memset((char *)cr, 0, sizeof(cred_t));
3252 #if CELL || CELL_PREPARE
3259 DECL_PIOCTL(PGetRxkcrypt)
3261 memcpy(aout, (char *)&cryptall, sizeof(afs_int32));
3262 *aoutSize = sizeof(afs_int32);
3266 DECL_PIOCTL(PSetRxkcrypt)
3270 if (!afs_osi_suser(*acred))
3272 if (ainSize != sizeof(afs_int32) || ain == NULL)
3274 memcpy((char *)&tmpval, ain, sizeof(afs_int32));
3275 /* if new mappings added later this will need to be changed */
3276 if (tmpval != 0 && tmpval != 1)
3282 #ifdef AFS_NEED_CLIENTCONTEXT
3284 * Create new credentials to correspond to a remote user with given
3285 * <hostaddr, uid, g0, g1>. This allows a server running as root to
3286 * provide pioctl (and other) services to foreign clients (i.e. nfs
3287 * clients) by using this call to `become' the client.
3290 #define PIOCTL_HEADER 6
3292 HandleClientContext(struct afs_ioctl *ablob, int *com,
3293 struct AFS_UCRED **acred, struct AFS_UCRED *credp)
3296 afs_uint32 hostaddr;
3297 afs_int32 uid, g0, g1, i, code, pag, exporter_type;
3298 struct afs_exporter *exporter, *outexporter;
3299 struct AFS_UCRED *newcred;
3300 struct unixuser *au;
3302 #if defined(AFS_SGIMP_ENV)
3303 osi_Assert(ISAFS_GLOCK());
3305 AFS_STATCNT(HandleClientContext);
3306 if (ablob->in_size < PIOCTL_HEADER * sizeof(afs_int32)) {
3307 /* Must at least include the PIOCTL_HEADER header words required by the protocol */
3308 return EINVAL; /* Too small to be good */
3310 ain = inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
3311 AFS_COPYIN(ablob->in, ain, PIOCTL_HEADER * sizeof(afs_int32), code);
3313 osi_FreeLargeSpace(inData);
3317 /* Extract information for remote user */
3318 hostaddr = *((afs_uint32 *) ain);
3319 ain += sizeof(hostaddr);
3320 uid = *((afs_uint32 *) ain);
3322 g0 = *((afs_uint32 *) ain);
3324 g1 = *((afs_uint32 *) ain);
3326 *com = *((afs_uint32 *) ain);
3327 ain += sizeof(afs_int32);
3328 exporter_type = *((afs_uint32 *) ain); /* In case we support more than NFS */
3331 * Of course, one must be root for most of these functions, but
3332 * we'll allow (for knfs) you to set things if the pag is 0 and
3333 * you're setting tokens or unlogging.
3336 if (!afs_osi_suser(credp)) {
3337 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
3338 /* Since SGI's suser() returns explicit failure after the call.. */
3341 /* check for acceptable opcodes for normal folks, which are, so far,
3342 * set tokens and unlog.
3344 if (i != 9 && i != 3 && i != 38 && i != 8) {
3345 osi_FreeLargeSpace(inData);
3350 ablob->in_size -= PIOCTL_HEADER * sizeof(afs_int32);
3351 ablob->in += PIOCTL_HEADER * sizeof(afs_int32);
3352 osi_FreeLargeSpace(inData);
3355 * We map uid 0 to nobody to match the mapping that the nfs
3356 * server does and to ensure that the suser() calls in the afs
3357 * code fails for remote client roots.
3359 uid = afs_nobody; /* NFS_NOBODY == -2 */
3362 #if defined(AFS_LINUX26_ENV)
3363 newcred->cr_group_info = groups_alloc(0);
3365 #ifdef AFS_AIX41_ENV
3368 newcred->cr_gid = RMTUSER_REQ;
3369 #ifdef AFS_AIX51_ENV
3370 newcred->cr_groupset.gs_union.un_groups[0] = g0;
3371 newcred->cr_groupset.gs_union.un_groups[1] = g1;
3373 newcred->cr_groups[0] = g0;
3374 newcred->cr_groups[1] = g1;
3377 newcred->cr_ngrps = 2;
3379 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV)
3380 newcred->cr_ngroups = 2;
3382 for (i = 2; i < NGROUPS; i++)
3383 newcred->cr_groups[i] = NOGROUP;
3386 #if !defined(AFS_OSF_ENV)
3387 afs_nfsclient_init(); /* before looking for exporter, ensure one exists */
3389 if (!(exporter = exporter_find(exporter_type))) {
3390 /* Exporter wasn't initialized or an invalid exporter type */
3394 if (exporter->exp_states & EXP_PWSYNC) {
3395 if (uid != credp->cr_uid) {
3397 return ENOEXEC; /* XXX Find a better errno XXX */
3400 newcred->cr_uid = uid; /* Only temporary */
3401 code = EXP_REQHANDLER(exporter, &newcred, hostaddr, &pag, &outexporter);
3402 /* The client's pag is the only unique identifier for it */
3403 newcred->cr_uid = pag;
3405 if (!code && *com == PSETPAG) {
3406 /* Special case for 'setpag' */
3407 afs_uint32 pagvalue = genpag();
3409 au = afs_GetUser(pagvalue, -1, WRITE_LOCK); /* a new unixuser struct */
3411 * Note that we leave the 'outexporter' struct held so it won't
3414 au->exporter = outexporter;
3415 if (ablob->out_size >= 4) {
3416 AFS_COPYOUT((char *)&pagvalue, ablob->out, sizeof(afs_int32),
3419 afs_PutUser(au, WRITE_LOCK);
3422 return PSETPAG; /* Special return for setpag */
3424 EXP_RELE(outexporter);
3428 #endif /* AFS_NEED_CLIENTCONTEXT */
3430 /* get all interface addresses of this client */
3432 DECL_PIOCTL(PGetCPrefs)
3434 struct sprefrequest *spin; /* input */
3435 struct sprefinfo *spout; /* output */
3436 struct spref *srvout; /* one output component */
3440 AFS_STATCNT(PGetCPrefs);
3441 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3442 return EIO; /* Inappropriate ioctl for device */
3444 if (ainSize < sizeof(struct sprefrequest))
3447 spin = (struct sprefrequest *)ain;
3448 spout = (struct sprefinfo *)aout;
3450 maxNumber = spin->num_servers; /* max addrs this time */
3451 srvout = spout->servers;
3453 ObtainReadLock(&afs_xinterface);
3455 /* copy out the client interface information from the
3456 ** kernel data structure "interface" to the output buffer
3458 for (i = spin->offset, j = 0; (i < afs_cb_interface.numberOfInterfaces)
3459 && (j < maxNumber); i++, j++, srvout++)
3460 srvout->host.s_addr = afs_cb_interface.addr_in[i];
3462 spout->num_servers = j;
3463 *aoutSize = sizeof(struct sprefinfo) + (j - 1) * sizeof(struct spref);
3465 if (i >= afs_cb_interface.numberOfInterfaces)
3466 spout->next_offset = 0; /* start from beginning again */
3468 spout->next_offset = spin->offset + j;
3470 ReleaseReadLock(&afs_xinterface);
3474 DECL_PIOCTL(PSetCPrefs)
3476 struct setspref *sin;
3479 AFS_STATCNT(PSetCPrefs);
3480 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3481 return EIO; /* Inappropriate ioctl for device */
3483 sin = (struct setspref *)ain;
3485 if (ainSize < sizeof(struct setspref))
3487 #if 0 /* num_servers is unsigned */
3488 if (sin->num_servers < 0)
3491 if (sin->num_servers > AFS_MAX_INTERFACE_ADDR)
3494 ObtainWriteLock(&afs_xinterface, 412);
3495 afs_cb_interface.numberOfInterfaces = sin->num_servers;
3496 for (i = 0; (unsigned short)i < sin->num_servers; i++)
3497 afs_cb_interface.addr_in[i] = sin->servers[i].host.s_addr;
3499 ReleaseWriteLock(&afs_xinterface);
3503 DECL_PIOCTL(PFlushMount)
3505 register afs_int32 code;
3506 register struct vcache *tvc;
3507 register struct dcache *tdc;
3508 struct VenusFid tfid;
3510 struct sysname_info sysState;
3511 afs_size_t offset, len;
3513 AFS_STATCNT(PFlushMount);
3516 code = afs_VerifyVCache(avc, areq);
3519 if (vType(avc) != VDIR) {
3522 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
3525 Check_AtSys(avc, ain, &sysState, areq);
3526 ObtainReadLock(&tdc->lock);
3528 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
3529 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
3530 ReleaseReadLock(&tdc->lock);
3531 afs_PutDCache(tdc); /* we're done with the data */
3532 bufp = sysState.name;
3536 tfid.Cell = avc->fid.Cell;
3537 tfid.Fid.Volume = avc->fid.Fid.Volume;
3538 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
3539 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
3541 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3547 if (tvc->mvstat != 1) {
3552 #ifdef AFS_BOZONLOCK_ENV
3553 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
3555 ObtainWriteLock(&tvc->lock, 649);
3556 ObtainWriteLock(&afs_xcbhash, 650);
3557 afs_DequeueCallback(tvc);
3558 tvc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
3559 ReleaseWriteLock(&afs_xcbhash);
3560 /* now find the disk cache entries */
3561 afs_TryToSmush(tvc, *acred, 1);
3562 osi_dnlc_purgedp(tvc);
3563 if (tvc->linkData && !(tvc->states & CCore)) {
3564 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
3565 tvc->linkData = NULL;
3567 ReleaseWriteLock(&tvc->lock);
3568 #ifdef AFS_BOZONLOCK_ENV
3569 afs_BozonUnlock(&tvc->pvnLock, tvc);
3573 if (sysState.allocked)
3574 osi_FreeLargeSpace(bufp);
3578 DECL_PIOCTL(PRxStatProc)
3583 if (!afs_osi_suser(*acred)) {
3587 if (ainSize != sizeof(afs_int32)) {
3591 memcpy((char *)&flags, ain, sizeof(afs_int32));
3592 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3596 if (flags & AFSCALL_RXSTATS_ENABLE) {
3597 rx_enableProcessRPCStats();
3599 if (flags & AFSCALL_RXSTATS_DISABLE) {
3600 rx_disableProcessRPCStats();
3602 if (flags & AFSCALL_RXSTATS_CLEAR) {
3603 rx_clearProcessRPCStats(AFS_RX_STATS_CLEAR_ALL);
3611 DECL_PIOCTL(PRxStatPeer)
3616 if (!afs_osi_suser(*acred)) {
3620 if (ainSize != sizeof(afs_int32)) {
3624 memcpy((char *)&flags, ain, sizeof(afs_int32));
3625 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3629 if (flags & AFSCALL_RXSTATS_ENABLE) {
3630 rx_enablePeerRPCStats();
3632 if (flags & AFSCALL_RXSTATS_DISABLE) {
3633 rx_disablePeerRPCStats();
3635 if (flags & AFSCALL_RXSTATS_CLEAR) {
3636 rx_clearPeerRPCStats(AFS_RX_STATS_CLEAR_ALL);
3643 DECL_PIOCTL(PPrefetchFromTape)
3645 register afs_int32 code, code1;
3648 struct rx_call *tcall;
3649 struct AFSVolSync tsync;
3650 struct AFSFetchStatus OutStatus;
3651 struct AFSCallBack CallBack;
3652 struct VenusFid tfid;
3656 AFS_STATCNT(PSetAcl);
3660 if (ain && (ainSize == 3 * sizeof(afs_int32)))
3661 Fid = (struct AFSFid *)ain;
3663 Fid = &avc->fid.Fid;
3664 tfid.Cell = avc->fid.Cell;
3665 tfid.Fid.Volume = Fid->Volume;
3666 tfid.Fid.Vnode = Fid->Vnode;
3667 tfid.Fid.Unique = Fid->Unique;
3669 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3671 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3672 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &avc->fid);
3675 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3676 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &tvc->fid);
3679 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3683 tcall = rx_NewCall(tc->id);
3685 StartRXAFS_FetchData(tcall, (struct AFSFid *)&tvc->fid.Fid, 0,
3688 bytes = rx_Read(tcall, (char *)aout, sizeof(afs_int32));
3690 EndRXAFS_FetchData(tcall, &OutStatus, &CallBack, &tsync);
3692 code1 = rx_EndCall(tcall, code);
3696 } while (afs_Analyze
3697 (tc, code, &tvc->fid, areq, AFS_STATS_FS_RPCIDX_RESIDENCYRPCS,
3698 SHARED_LOCK, NULL));
3699 /* This call is done only to have the callback things handled correctly */
3700 afs_FetchStatus(tvc, &tfid, areq, &OutStatus);
3704 *aoutSize = sizeof(afs_int32);
3709 DECL_PIOCTL(PResidencyCmd)
3711 register afs_int32 code;
3714 struct ResidencyCmdInputs *Inputs;
3715 struct ResidencyCmdOutputs *Outputs;
3716 struct VenusFid tfid;
3719 Inputs = (struct ResidencyCmdInputs *)ain;
3720 Outputs = (struct ResidencyCmdOutputs *)aout;
3723 if (!ain || ainSize != sizeof(struct ResidencyCmdInputs))
3728 Fid = &avc->fid.Fid;
3730 tfid.Cell = avc->fid.Cell;
3731 tfid.Fid.Volume = Fid->Volume;
3732 tfid.Fid.Vnode = Fid->Vnode;
3733 tfid.Fid.Unique = Fid->Unique;
3735 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3736 afs_Trace3(afs_iclSetp, CM_TRACE_RESIDCMD, ICL_TYPE_POINTER, tvc,
3737 ICL_TYPE_INT32, Inputs->command, ICL_TYPE_FID, &tfid);
3741 if (Inputs->command) {
3743 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3747 RXAFS_ResidencyCmd(tc->id, Fid, Inputs,
3748 (struct ResidencyCmdOutputs *)aout);
3752 } while (afs_Analyze
3753 (tc, code, &tvc->fid, areq,
3754 AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK, NULL));
3755 /* This call is done to have the callback things handled correctly */
3756 afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3757 } else { /* just a status request, return also link data */
3759 Outputs->code = afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3760 Outputs->chars[0] = 0;
3761 if (vType(tvc) == VLNK) {
3762 ObtainWriteLock(&tvc->lock, 555);
3763 if (afs_HandleLink(tvc, areq) == 0)
3764 strncpy((char *)&Outputs->chars, tvc->linkData, MAXCMDCHARS);
3765 ReleaseWriteLock(&tvc->lock);
3772 *aoutSize = sizeof(struct ResidencyCmdOutputs);
3777 DECL_PIOCTL(PCallBackAddr)
3780 afs_uint32 addr, code;
3786 struct unixuser *tu;
3787 struct srvAddr **addrs;
3789 /*AFS_STATCNT(PCallBackAddr); */
3790 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
3791 return EIO; /* Inappropriate ioctl for device */
3793 if (!afs_osi_suser(acred))
3796 if (ainSize < sizeof(afs_int32))
3799 memcpy(&addr, ain, sizeof(afs_int32));
3801 ObtainReadLock(&afs_xinterface);
3802 for (i = 0; (unsigned short)i < afs_cb_interface.numberOfInterfaces; i++) {
3803 if (afs_cb_interface.addr_in[i] == addr)
3807 ReleaseWriteLock(&afs_xinterface);
3809 if (afs_cb_interface.addr_in[i] != addr)
3812 ObtainReadLock(&afs_xserver); /* Necessary? */
3813 ObtainReadLock(&afs_xsrvAddr);
3816 for (i = 0; i < NSERVERS; i++) {
3817 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3822 addrs = afs_osi_Alloc(srvAddrCount * sizeof(*addrs));
3824 for (i = 0; i < NSERVERS; i++) {
3825 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3826 if (j >= srvAddrCount)
3832 ReleaseReadLock(&afs_xsrvAddr);
3833 ReleaseReadLock(&afs_xserver);
3835 for (i = 0; i < j; i++) {
3841 /* vlserver has no callback conn */
3842 if (sa->sa_portal == AFS_VLPORT) {
3846 if (!ts->cell) /* not really an active server, anyway, it must */
3847 continue; /* have just been added by setsprefs */
3849 /* get a connection, even if host is down; bumps conn ref count */
3850 tu = afs_GetUser(areq->uid, ts->cell->cellNum, SHARED_LOCK);
3851 tc = afs_ConnBySA(sa, ts->cell->fsport, ts->cell->cellNum, tu,
3852 1 /*force */ , 1 /*create */ , SHARED_LOCK);
3853 afs_PutUser(tu, SHARED_LOCK);
3857 if ((sa->sa_flags & SRVADDR_ISDOWN) || afs_HaveCallBacksFrom(ts)) {
3858 if (sa->sa_flags & SRVADDR_ISDOWN) {
3859 rx_SetConnDeadTime(tc->id, 3);
3861 #ifdef RX_ENABLE_LOCKS
3863 #endif /* RX_ENABLE_LOCKS */
3864 code = RXAFS_CallBackRxConnAddr(tc->id, &addr);
3865 #ifdef RX_ENABLE_LOCKS
3867 #endif /* RX_ENABLE_LOCKS */
3869 afs_PutConn(tc, SHARED_LOCK); /* done with it now */
3870 } /* Outer loop over addrs */
3871 #endif /* UKERNEL */