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 afs_symhint_inval(avc);
1673 if (avc->linkData && !(avc->states & CCore)) {
1674 afs_osi_Free(avc->linkData, strlen(avc->linkData) + 1);
1675 avc->linkData = NULL;
1677 ReleaseWriteLock(&avc->lock);
1678 #ifdef AFS_BOZONLOCK_ENV
1679 afs_BozonUnlock(&avc->pvnLock, avc);
1684 DECL_PIOCTL(PNewStatMount)
1686 register afs_int32 code;
1687 register struct vcache *tvc;
1688 register struct dcache *tdc;
1689 struct VenusFid tfid;
1691 struct sysname_info sysState;
1692 afs_size_t offset, len;
1694 AFS_STATCNT(PNewStatMount);
1697 code = afs_VerifyVCache(avc, areq);
1700 if (vType(avc) != VDIR) {
1703 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
1706 Check_AtSys(avc, ain, &sysState, areq);
1707 ObtainReadLock(&tdc->lock);
1709 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
1710 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
1711 ReleaseReadLock(&tdc->lock);
1712 afs_PutDCache(tdc); /* we're done with the data */
1713 bufp = sysState.name;
1717 tfid.Cell = avc->fid.Cell;
1718 tfid.Fid.Volume = avc->fid.Fid.Volume;
1719 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
1720 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
1722 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
1728 if (tvc->mvstat != 1) {
1733 ObtainWriteLock(&tvc->lock, 226);
1734 code = afs_HandleLink(tvc, areq);
1736 if (tvc->linkData) {
1737 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
1740 /* we have the data */
1741 strcpy(aout, tvc->linkData);
1742 *aoutSize = strlen(tvc->linkData) + 1;
1747 ReleaseWriteLock(&tvc->lock);
1750 if (sysState.allocked)
1751 osi_FreeLargeSpace(bufp);
1755 DECL_PIOCTL(PGetTokens)
1757 register struct cell *tcell;
1758 register afs_int32 i;
1759 register struct unixuser *tu;
1764 AFS_STATCNT(PGetTokens);
1765 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1766 return EIO; /* Inappropriate ioctl for device */
1768 /* weird interface. If input parameter is present, it is an integer and
1769 * we're supposed to return the parm'th tokens for this unix uid.
1770 * If not present, we just return tokens for cell 1.
1771 * If counter out of bounds, return EDOM.
1772 * If no tokens for the particular cell, return ENOTCONN.
1773 * Also, if this mysterious parm is present, we return, along with the
1774 * tokens, the primary cell indicator (an afs_int32 0) and the cell name
1775 * at the end, in that order.
1777 if ((newStyle = (ainSize > 0))) {
1778 memcpy((char *)&iterator, ain, sizeof(afs_int32));
1780 i = UHash(areq->uid);
1781 ObtainReadLock(&afs_xuser);
1782 for (tu = afs_users[i]; tu; tu = tu->next) {
1784 if (tu->uid == areq->uid && (tu->states & UHasTokens)) {
1785 if (iterator-- == 0)
1786 break; /* are we done yet? */
1789 if (tu->uid == areq->uid && afs_IsPrimaryCellNum(tu->cell))
1795 * No need to hold a read lock on each user entry
1799 ReleaseReadLock(&afs_xuser);
1804 if (((tu->states & UHasTokens) == 0)
1805 || (tu->ct.EndTimestamp < osi_Time())) {
1806 tu->states |= (UTokensBad | UNeedsReset);
1807 afs_PutUser(tu, READ_LOCK);
1810 /* use iterator for temp */
1812 iterator = tu->stLen; /* for compat, we try to return 56 byte tix if they fit */
1814 iterator = 56; /* # of bytes we're returning */
1815 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1816 cp += sizeof(afs_int32);
1817 memcpy(cp, tu->stp, tu->stLen); /* copy out st */
1819 iterator = sizeof(struct ClearToken);
1820 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1821 cp += sizeof(afs_int32);
1822 memcpy(cp, (char *)&tu->ct, sizeof(struct ClearToken));
1823 cp += sizeof(struct ClearToken);
1825 /* put out primary id and cell name, too */
1826 iterator = (tu->states & UPrimary ? 1 : 0);
1827 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1828 cp += sizeof(afs_int32);
1829 tcell = afs_GetCell(tu->cell, READ_LOCK);
1831 strcpy(cp, tcell->cellName);
1832 cp += strlen(tcell->cellName) + 1;
1833 afs_PutCell(tcell, READ_LOCK);
1837 *aoutSize = cp - aout;
1838 afs_PutUser(tu, READ_LOCK);
1844 register afs_int32 i;
1845 register struct unixuser *tu;
1847 AFS_STATCNT(PUnlog);
1848 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1849 return EIO; /* Inappropriate ioctl for device */
1851 i = UHash(areq->uid);
1852 ObtainWriteLock(&afs_xuser, 227);
1853 for (tu = afs_users[i]; tu; tu = tu->next) {
1854 if (tu->uid == areq->uid) {
1856 tu->states &= ~UHasTokens;
1857 /* security is not having to say you're sorry */
1858 memset((char *)&tu->ct, 0, sizeof(struct ClearToken));
1860 ReleaseWriteLock(&afs_xuser);
1861 /* We have to drop the lock over the call to afs_ResetUserConns, since
1862 * it obtains the afs_xvcache lock. We could also keep the lock, and
1863 * modify ResetUserConns to take parm saying we obtained the lock
1864 * already, but that is overkill. By keeping the "tu" pointer
1865 * held over the released lock, we guarantee that we won't lose our
1866 * place, and that we'll pass over every user conn that existed when
1867 * we began this call.
1869 afs_ResetUserConns(tu);
1871 ObtainWriteLock(&afs_xuser, 228);
1873 /* set the expire times to 0, causes
1874 * afs_GCUserData to remove this entry
1876 tu->ct.EndTimestamp = 0;
1878 #endif /* UKERNEL */
1881 ReleaseWriteLock(&afs_xuser);
1885 DECL_PIOCTL(PMariner)
1887 afs_int32 newHostAddr;
1888 afs_int32 oldHostAddr;
1890 AFS_STATCNT(PMariner);
1892 memcpy((char *)&oldHostAddr, (char *)&afs_marinerHost,
1895 oldHostAddr = 0xffffffff; /* disabled */
1897 memcpy((char *)&newHostAddr, ain, sizeof(afs_int32));
1898 if (newHostAddr == 0xffffffff) {
1899 /* disable mariner operations */
1901 } else if (newHostAddr) {
1903 afs_marinerHost = newHostAddr;
1905 memcpy(aout, (char *)&oldHostAddr, sizeof(afs_int32));
1906 *aoutSize = sizeof(afs_int32);
1910 DECL_PIOCTL(PCheckServers)
1912 register char *cp = 0;
1914 register struct server *ts;
1915 afs_int32 temp, *lp = (afs_int32 *) ain, havecell = 0;
1917 struct chservinfo *pcheck;
1919 AFS_STATCNT(PCheckServers);
1921 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1922 return EIO; /* Inappropriate ioctl for device */
1924 if (*lp == 0x12345678) { /* For afs3.3 version */
1925 pcheck = (struct chservinfo *)ain;
1926 if (pcheck->tinterval >= 0) {
1928 memcpy(cp, (char *)&PROBE_INTERVAL, sizeof(afs_int32));
1929 *aoutSize = sizeof(afs_int32);
1930 if (pcheck->tinterval > 0) {
1931 if (!afs_osi_suser(*acred))
1933 PROBE_INTERVAL = pcheck->tinterval;
1939 temp = pcheck->tflags;
1940 cp = pcheck->tbuffer;
1941 } else { /* For pre afs3.3 versions */
1942 memcpy((char *)&temp, ain, sizeof(afs_int32));
1943 cp = ain + sizeof(afs_int32);
1944 if (ainSize > sizeof(afs_int32))
1949 * 1: fast check, don't contact servers.
1950 * 2: local cell only.
1953 /* have cell name, too */
1954 cellp = afs_GetCellByName(cp, READ_LOCK);
1959 if (!cellp && (temp & 2)) {
1960 /* use local cell */
1961 cellp = afs_GetPrimaryCell(READ_LOCK);
1963 if (!(temp & 1)) { /* if not fast, call server checker routine */
1964 afs_CheckServers(1, cellp); /* check down servers */
1965 afs_CheckServers(0, cellp); /* check up servers */
1967 /* now return the current down server list */
1969 ObtainReadLock(&afs_xserver);
1970 for (i = 0; i < NSERVERS; i++) {
1971 for (ts = afs_servers[i]; ts; ts = ts->next) {
1972 if (cellp && ts->cell != cellp)
1973 continue; /* cell spec'd and wrong */
1974 if ((ts->flags & SRVR_ISDOWN)
1975 && ts->addr->sa_portal != ts->cell->vlport) {
1976 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
1977 cp += sizeof(afs_int32);
1981 ReleaseReadLock(&afs_xserver);
1983 afs_PutCell(cellp, READ_LOCK);
1984 *aoutSize = cp - aout;
1988 DECL_PIOCTL(PCheckVolNames)
1990 AFS_STATCNT(PCheckVolNames);
1991 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1992 return EIO; /* Inappropriate ioctl for device */
1994 afs_CheckRootVolume();
1995 afs_CheckVolumeNames(AFS_VOLCHECK_FORCE | AFS_VOLCHECK_EXPIRED |
1996 AFS_VOLCHECK_BUSY | AFS_VOLCHECK_MTPTS);
2000 DECL_PIOCTL(PCheckAuth)
2005 struct unixuser *tu;
2008 AFS_STATCNT(PCheckAuth);
2009 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2010 return EIO; /* Inappropriate ioctl for device */
2013 tu = afs_GetUser(areq->uid, 1, READ_LOCK); /* check local cell authentication */
2017 /* we have a user */
2018 ObtainReadLock(&afs_xsrvAddr);
2019 ObtainReadLock(&afs_xconn);
2021 /* any tokens set? */
2022 if ((tu->states & UHasTokens) == 0)
2024 /* all connections in cell 1 working? */
2025 for (i = 0; i < NSERVERS; i++) {
2026 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2027 for (tc = sa->conns; tc; tc = tc->next) {
2028 if (tc->user == tu && (tu->states & UTokensBad))
2033 ReleaseReadLock(&afs_xsrvAddr);
2034 ReleaseReadLock(&afs_xconn);
2035 afs_PutUser(tu, READ_LOCK);
2037 memcpy(aout, (char *)&retValue, sizeof(afs_int32));
2038 *aoutSize = sizeof(afs_int32);
2043 Prefetch(char *apath, struct afs_ioctl *adata, int afollow,
2044 struct AFS_UCRED *acred)
2047 register afs_int32 code;
2048 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2054 AFS_STATCNT(Prefetch);
2057 tp = osi_AllocLargeSpace(1024);
2058 AFS_COPYINSTR(apath, tp, 1024, &bufferSize, code);
2060 osi_FreeLargeSpace(tp);
2063 if (afs_BBusy()) { /* do this as late as possible */
2064 osi_FreeLargeSpace(tp);
2065 return EWOULDBLOCK; /* pretty close */
2067 afs_BQueue(BOP_PATH, (struct vcache *)0, 0, 0, acred, (afs_size_t) 0,
2068 (afs_size_t) 0, tp);
2072 DECL_PIOCTL(PFindVolume)
2074 register struct volume *tvp;
2075 register struct server *ts;
2076 register afs_int32 i;
2079 AFS_STATCNT(PFindVolume);
2082 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
2085 for (i = 0; i < MAXHOSTS; i++) {
2086 ts = tvp->serverHost[i];
2089 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
2090 cp += sizeof(afs_int32);
2093 /* still room for terminating NULL, add it on */
2094 ainSize = 0; /* reuse vbl */
2095 memcpy(cp, (char *)&ainSize, sizeof(afs_int32));
2096 cp += sizeof(afs_int32);
2098 *aoutSize = cp - aout;
2099 afs_PutVolume(tvp, READ_LOCK);
2105 DECL_PIOCTL(PViceAccess)
2107 register afs_int32 code;
2110 AFS_STATCNT(PViceAccess);
2113 code = afs_VerifyVCache(avc, areq);
2116 memcpy((char *)&temp, ain, sizeof(afs_int32));
2117 code = afs_AccessOK(avc, temp, areq, CHECK_MODE_BITS);
2124 DECL_PIOCTL(PSetCacheSize)
2129 AFS_STATCNT(PSetCacheSize);
2130 if (!afs_osi_suser(*acred))
2132 /* too many things are setup initially in mem cache version */
2133 if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
2135 memcpy((char *)&newValue, ain, sizeof(afs_int32));
2137 afs_cacheBlocks = afs_stats_cmperf.cacheBlocksOrig;
2139 if (newValue < afs_min_cache)
2140 afs_cacheBlocks = afs_min_cache;
2142 afs_cacheBlocks = newValue;
2144 afs_stats_cmperf.cacheBlocksTotal = afs_cacheBlocks;
2145 afs_ComputeCacheParms(); /* recompute basic cache parameters */
2146 afs_MaybeWakeupTruncateDaemon();
2147 while (waitcnt++ < 100 && afs_cacheBlocks < afs_blocksUsed) {
2148 afs_osi_Wait(1000, 0, 0);
2149 afs_MaybeWakeupTruncateDaemon();
2154 #define MAXGCSTATS 16
2155 DECL_PIOCTL(PGetCacheSize)
2157 afs_int32 results[MAXGCSTATS];
2159 AFS_STATCNT(PGetCacheSize);
2160 memset((char *)results, 0, sizeof(results));
2161 results[0] = afs_cacheBlocks;
2162 results[1] = afs_blocksUsed;
2163 memcpy(aout, (char *)results, sizeof(results));
2164 *aoutSize = sizeof(results);
2168 DECL_PIOCTL(PRemoveCallBack)
2170 register struct conn *tc;
2171 register afs_int32 code = 0;
2172 struct AFSCallBack CallBacks_Array[1];
2173 struct AFSCBFids theFids;
2174 struct AFSCBs theCBs;
2177 AFS_STATCNT(PRemoveCallBack);
2180 if (avc->states & CRO)
2181 return 0; /* read-only-ness can't change */
2182 ObtainWriteLock(&avc->lock, 229);
2183 theFids.AFSCBFids_len = 1;
2184 theCBs.AFSCBs_len = 1;
2185 theFids.AFSCBFids_val = (struct AFSFid *)&avc->fid.Fid;
2186 theCBs.AFSCBs_val = CallBacks_Array;
2187 CallBacks_Array[0].CallBackType = CB_DROPPED;
2188 if (avc->callback) {
2190 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2192 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
2194 code = RXAFS_GiveUpCallBacks(tc->id, &theFids, &theCBs);
2198 /* don't set code on failure since we wouldn't use it */
2199 } while (afs_Analyze
2200 (tc, code, &avc->fid, areq,
2201 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK, NULL));
2203 ObtainWriteLock(&afs_xcbhash, 457);
2204 afs_DequeueCallback(avc);
2206 avc->states &= ~(CStatd | CUnique);
2207 ReleaseWriteLock(&afs_xcbhash);
2208 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
2209 osi_dnlc_purgedp(avc);
2211 ReleaseWriteLock(&avc->lock);
2215 DECL_PIOCTL(PNewCell)
2217 /* create a new cell */
2218 afs_int32 cellHosts[MAXCELLHOSTS], *lp, magic = 0;
2219 char *newcell = 0, *linkedcell = 0, *tp = ain;
2220 register afs_int32 code, linkedstate = 0, ls;
2221 u_short fsport = 0, vlport = 0;
2224 AFS_STATCNT(PNewCell);
2225 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2226 return EIO; /* Inappropriate ioctl for device */
2228 if (!afs_osi_suser(*acred))
2231 memcpy((char *)&magic, tp, sizeof(afs_int32));
2232 tp += sizeof(afs_int32);
2233 if (magic != 0x12345678)
2236 /* A 3.4 fs newcell command will pass an array of MAXCELLHOSTS
2237 * server addresses while the 3.5 fs newcell command passes
2238 * MAXHOSTS. To figure out which is which, check if the cellname
2241 newcell = tp + (MAXCELLHOSTS + 3) * sizeof(afs_int32);
2242 scount = ((newcell[0] != '\0') ? MAXCELLHOSTS : MAXHOSTS);
2244 /* MAXCELLHOSTS (=8) is less than MAXHOSTS (=13) */
2245 memcpy((char *)cellHosts, tp, MAXCELLHOSTS * sizeof(afs_int32));
2246 tp += (scount * sizeof(afs_int32));
2248 lp = (afs_int32 *) tp;
2252 fsport = 0; /* Privileged ports not allowed */
2254 vlport = 0; /* Privileged ports not allowed */
2255 tp += (3 * sizeof(afs_int32));
2257 if ((ls = *lp) & 1) {
2258 linkedcell = tp + strlen(newcell) + 1;
2259 linkedstate |= CLinkedCell;
2262 linkedstate |= CNoSUID; /* setuid is disabled by default for fs newcell */
2264 afs_NewCell(newcell, cellHosts, linkedstate, linkedcell, fsport,
2269 DECL_PIOCTL(PNewAlias)
2271 /* create a new cell alias */
2273 register afs_int32 code;
2274 char *realName, *aliasName;
2276 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2277 return EIO; /* Inappropriate ioctl for device */
2279 if (!afs_osi_suser(*acred))
2283 tp += strlen(aliasName) + 1;
2286 code = afs_NewCellAlias(aliasName, realName);
2291 DECL_PIOCTL(PListCells)
2293 afs_int32 whichCell;
2294 register struct cell *tcell = 0;
2295 register afs_int32 i;
2296 register char *cp, *tp = ain;
2298 AFS_STATCNT(PListCells);
2299 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2300 return EIO; /* Inappropriate ioctl for device */
2302 memcpy((char *)&whichCell, tp, sizeof(afs_int32));
2303 tp += sizeof(afs_int32);
2304 tcell = afs_GetCellByIndex(whichCell, READ_LOCK);
2307 memset(cp, 0, MAXCELLHOSTS * sizeof(afs_int32));
2308 for (i = 0; i < MAXCELLHOSTS; i++) {
2309 if (tcell->cellHosts[i] == 0)
2311 memcpy(cp, (char *)&tcell->cellHosts[i]->addr->sa_ip,
2313 cp += sizeof(afs_int32);
2315 cp = aout + MAXCELLHOSTS * sizeof(afs_int32);
2316 strcpy(cp, tcell->cellName);
2317 cp += strlen(tcell->cellName) + 1;
2318 *aoutSize = cp - aout;
2319 afs_PutCell(tcell, READ_LOCK);
2327 DECL_PIOCTL(PListAliases)
2329 afs_int32 whichAlias;
2330 register struct cell_alias *tcalias = 0;
2331 register char *cp, *tp = ain;
2333 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2334 return EIO; /* Inappropriate ioctl for device */
2335 if (ainSize < sizeof(afs_int32))
2338 memcpy((char *)&whichAlias, tp, sizeof(afs_int32));
2339 tp += sizeof(afs_int32);
2341 tcalias = afs_GetCellAlias(whichAlias);
2344 strcpy(cp, tcalias->alias);
2345 cp += strlen(tcalias->alias) + 1;
2346 strcpy(cp, tcalias->cell);
2347 cp += strlen(tcalias->cell) + 1;
2348 *aoutSize = cp - aout;
2349 afs_PutCellAlias(tcalias);
2357 DECL_PIOCTL(PRemoveMount)
2359 register afs_int32 code;
2361 struct sysname_info sysState;
2362 afs_size_t offset, len;
2363 register struct conn *tc;
2364 register struct dcache *tdc;
2365 register struct vcache *tvc;
2366 struct AFSFetchStatus OutDirStatus;
2367 struct VenusFid tfid;
2368 struct AFSVolSync tsync;
2372 /* "ain" is the name of the file in this dir to remove */
2374 AFS_STATCNT(PRemoveMount);
2377 code = afs_VerifyVCache(avc, areq);
2380 if (vType(avc) != VDIR)
2383 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1); /* test for error below */
2386 Check_AtSys(avc, ain, &sysState, areq);
2387 ObtainReadLock(&tdc->lock);
2389 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
2390 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
2391 ReleaseReadLock(&tdc->lock);
2392 bufp = sysState.name;
2397 tfid.Cell = avc->fid.Cell;
2398 tfid.Fid.Volume = avc->fid.Fid.Volume;
2399 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
2400 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
2402 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
2409 if (tvc->mvstat != 1) {
2415 ObtainWriteLock(&tvc->lock, 230);
2416 code = afs_HandleLink(tvc, areq);
2418 if (tvc->linkData) {
2419 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
2424 ReleaseWriteLock(&tvc->lock);
2425 osi_dnlc_purgedp(tvc);
2431 ObtainWriteLock(&avc->lock, 231);
2432 osi_dnlc_remove(avc, bufp, tvc);
2434 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2436 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE);
2439 RXAFS_RemoveFile(tc->id, (struct AFSFid *)&avc->fid.Fid, bufp,
2440 &OutDirStatus, &tsync);
2445 } while (afs_Analyze
2446 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_REMOVEFILE,
2447 SHARED_LOCK, NULL));
2452 ReleaseWriteLock(&avc->lock);
2456 /* we have the thing in the cache */
2457 ObtainWriteLock(&tdc->lock, 661);
2458 if (afs_LocalHero(avc, tdc, &OutDirStatus, 1)) {
2459 /* we can do it locally */
2460 code = afs_dir_Delete(tdc, bufp);
2462 ZapDCE(tdc); /* surprise error -- invalid value */
2466 ReleaseWriteLock(&tdc->lock);
2467 afs_PutDCache(tdc); /* drop ref count */
2469 avc->states &= ~CUnique; /* For the dfs xlator */
2470 ReleaseWriteLock(&avc->lock);
2473 if (sysState.allocked)
2474 osi_FreeLargeSpace(bufp);
2478 DECL_PIOCTL(PVenusLogging)
2480 return EINVAL; /* OBSOLETE */
2483 DECL_PIOCTL(PGetCellStatus)
2485 register struct cell *tcell;
2488 AFS_STATCNT(PGetCellStatus);
2489 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2490 return EIO; /* Inappropriate ioctl for device */
2492 tcell = afs_GetCellByName(ain, READ_LOCK);
2495 temp = tcell->states;
2496 afs_PutCell(tcell, READ_LOCK);
2497 memcpy(aout, (char *)&temp, sizeof(afs_int32));
2498 *aoutSize = sizeof(afs_int32);
2502 DECL_PIOCTL(PSetCellStatus)
2504 register struct cell *tcell;
2507 if (!afs_osi_suser(*acred))
2509 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2510 return EIO; /* Inappropriate ioctl for device */
2512 tcell = afs_GetCellByName(ain + 2 * sizeof(afs_int32), WRITE_LOCK);
2515 memcpy((char *)&temp, ain, sizeof(afs_int32));
2517 tcell->states |= CNoSUID;
2519 tcell->states &= ~CNoSUID;
2520 afs_PutCell(tcell, WRITE_LOCK);
2524 DECL_PIOCTL(PFlushVolumeData)
2526 register afs_int32 i;
2527 register struct dcache *tdc;
2528 register struct vcache *tvc;
2529 register struct volume *tv;
2530 afs_int32 cell, volume;
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 (tvc = afs_vhashT[i]; tvc; tvc = tvc->vhnext) {
2548 if (tvc->fid.Fid.Volume == volume && tvc->fid.Cell == cell) {
2549 #if defined(AFS_SGI_ENV) || defined(AFS_OSF_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
2550 VN_HOLD(AFSTOV(tvc));
2552 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2555 VREFCOUNT_INC(tvc); /* AIX, apparently */
2558 ReleaseReadLock(&afs_xvcache);
2559 #ifdef AFS_BOZONLOCK_ENV
2560 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
2562 ObtainWriteLock(&tvc->lock, 232);
2564 ObtainWriteLock(&afs_xcbhash, 458);
2565 afs_DequeueCallback(tvc);
2566 tvc->states &= ~(CStatd | CDirty);
2567 ReleaseWriteLock(&afs_xcbhash);
2568 if (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
2569 osi_dnlc_purgedp(tvc);
2570 afs_TryToSmush(tvc, *acred, 1);
2571 ReleaseWriteLock(&tvc->lock);
2572 #ifdef AFS_BOZONLOCK_ENV
2573 afs_BozonUnlock(&tvc->pvnLock, tvc);
2575 ObtainReadLock(&afs_xvcache);
2576 /* our tvc ptr is still good until now */
2580 ReleaseReadLock(&afs_xvcache);
2583 MObtainWriteLock(&afs_xdcache, 328); /* needed if you're going to flush any stuff */
2584 for (i = 0; i < afs_cacheFiles; i++) {
2585 if (!(afs_indexFlags[i] & IFEverUsed))
2586 continue; /* never had any data */
2587 tdc = afs_GetDSlot(i, NULL);
2588 if (tdc->refCount <= 1) { /* too high, in use by running sys call */
2589 ReleaseReadLock(&tdc->tlock);
2590 if (tdc->f.fid.Fid.Volume == volume && tdc->f.fid.Cell == cell) {
2591 if (!(afs_indexFlags[i] & IFDataMod)) {
2592 /* if the file is modified, but has a ref cnt of only 1, then
2593 * someone probably has the file open and is writing into it.
2594 * Better to skip flushing such a file, it will be brought back
2595 * immediately on the next write anyway.
2597 * If we *must* flush, then this code has to be rearranged to call
2598 * afs_storeAllSegments() first */
2599 afs_FlushDCache(tdc);
2603 ReleaseReadLock(&tdc->tlock);
2605 afs_PutDCache(tdc); /* bumped by getdslot */
2607 MReleaseWriteLock(&afs_xdcache);
2609 ObtainReadLock(&afs_xvolume);
2610 for (i = 0; i < NVOLS; i++) {
2611 for (tv = afs_volumes[i]; tv; tv = tv->next) {
2612 if (tv->volume == volume) {
2613 afs_ResetVolumeInfo(tv);
2618 ReleaseReadLock(&afs_xvolume);
2620 /* probably, a user is doing this, probably, because things are screwed up.
2621 * maybe it's the dnlc's fault? */
2628 DECL_PIOCTL(PGetVnodeXStatus)
2630 register afs_int32 code;
2631 struct vcxstat stat;
2634 /* AFS_STATCNT(PGetVnodeXStatus); */
2637 code = afs_VerifyVCache(avc, areq);
2640 if (vType(avc) == VDIR)
2641 mode = PRSFS_LOOKUP;
2644 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
2647 memset(&stat, 0, sizeof(struct vcxstat));
2648 stat.fid = avc->fid;
2649 hset32(stat.DataVersion, hgetlo(avc->m.DataVersion));
2650 stat.lock = avc->lock;
2651 stat.parentVnode = avc->parentVnode;
2652 stat.parentUnique = avc->parentUnique;
2653 hset(stat.flushDV, avc->flushDV);
2654 hset(stat.mapDV, avc->mapDV);
2655 stat.truncPos = avc->truncPos;
2656 { /* just grab the first two - won't break anything... */
2657 struct axscache *ac;
2659 for (i = 0, ac = avc->Access; ac && i < CPSIZE; i++, ac = ac->next) {
2660 stat.randomUid[i] = ac->uid;
2661 stat.randomAccess[i] = ac->axess;
2664 stat.callback = afs_data_pointer_to_int32(avc->callback);
2665 stat.cbExpires = avc->cbExpires;
2666 stat.anyAccess = avc->anyAccess;
2667 stat.opens = avc->opens;
2668 stat.execsOrWriters = avc->execsOrWriters;
2669 stat.flockCount = avc->flockCount;
2670 stat.mvstat = avc->mvstat;
2671 stat.states = avc->states;
2672 memcpy(aout, (char *)&stat, sizeof(struct vcxstat));
2673 *aoutSize = sizeof(struct vcxstat);
2678 DECL_PIOCTL(PGetVnodeXStatus2)
2680 register afs_int32 code;
2681 struct vcxstat2 stat;
2686 code = afs_VerifyVCache(avc, areq);
2689 if (vType(avc) == VDIR)
2690 mode = PRSFS_LOOKUP;
2693 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
2696 memset(&stat, 0, sizeof(struct vcxstat2));
2698 stat.cbExpires = avc->cbExpires;
2699 stat.anyAccess = avc->anyAccess;
2700 stat.mvstat = avc->mvstat;
2701 stat.callerAccess = afs_GetAccessBits(avc, ~0, areq);
2703 memcpy(aout, (char *)&stat, sizeof(struct vcxstat2));
2704 *aoutSize = sizeof(struct vcxstat2);
2708 /* We require root for local sysname changes, but not for remote */
2709 /* (since we don't really believe remote uids anyway) */
2710 /* outname[] shouldn't really be needed- this is left as an excercise */
2711 /* for the reader. */
2712 DECL_PIOCTL(PSetSysName)
2714 char *cp, *cp2 = NULL, inname[MAXSYSNAME], outname[MAXSYSNAME];
2715 int setsysname, foundname = 0;
2716 register struct afs_exporter *exporter;
2717 register struct unixuser *au;
2718 register afs_int32 pag, error;
2719 int t, count, num = 0;
2720 char **sysnamelist[MAXSYSNAME];
2722 AFS_STATCNT(PSetSysName);
2723 if (!afs_globalVFS) {
2724 /* Afsd is NOT running; disable it */
2725 #if defined(KERNEL_HAVE_UERROR)
2726 return (setuerror(EINVAL), EINVAL);
2731 memset(inname, 0, MAXSYSNAME);
2732 memcpy((char *)&setsysname, ain, sizeof(afs_int32));
2733 ain += sizeof(afs_int32);
2737 if (setsysname < 0 || setsysname > MAXNUMSYSNAMES)
2740 for (cp = ain, count = 0; count < setsysname; count++) {
2741 /* won't go past end of ain since maxsysname*num < ain length */
2743 if (t >= MAXSYSNAME || t <= 0)
2745 /* check for names that can shoot us in the foot */
2746 if (*cp == '.' && (cp[1] == 0 || (cp[1] == '.' && cp[2] == 0)))
2752 /* inname gets first entry in case we're being a translator */
2754 memcpy(inname, ain, t + 1); /* include terminating null */
2758 if ((*acred)->cr_gid == RMTUSER_REQ) { /* Handles all exporters */
2759 pag = PagInCred(*acred);
2761 return EINVAL; /* Better than panicing */
2763 if (!(au = afs_FindUser(pag, -1, READ_LOCK))) {
2764 return EINVAL; /* Better than panicing */
2766 if (!(exporter = au->exporter)) {
2767 afs_PutUser(au, READ_LOCK);
2768 return EINVAL; /* Better than panicing */
2770 error = EXP_SYSNAME(exporter, (setsysname ? cp2 : NULL), sysnamelist,
2773 if (error == ENODEV)
2774 foundname = 0; /* sysname not set yet! */
2776 afs_PutUser(au, READ_LOCK);
2781 strcpy(outname, (*sysnamelist)[0]);
2783 afs_PutUser(au, READ_LOCK);
2785 /* Not xlating, so local case */
2787 osi_Panic("PSetSysName: !afs_sysname\n");
2788 if (!setsysname) { /* user just wants the info */
2789 strcpy(outname, afs_sysname);
2790 foundname = afs_sysnamecount;
2791 *sysnamelist = afs_sysnamelist;
2792 } else { /* Local guy; only root can change sysname */
2793 if (!afs_osi_suser(*acred))
2796 /* clear @sys entries from the dnlc, once afs_lookup can
2797 * do lookups of @sys entries and thinks it can trust them */
2798 /* privs ok, store the entry, ... */
2799 strcpy(afs_sysname, inname);
2800 if (setsysname > 1) { /* ... or list */
2802 for (count = 1; count < setsysname; ++count) {
2803 if (!afs_sysnamelist[count])
2805 ("PSetSysName: no afs_sysnamelist entry to write\n");
2807 memcpy(afs_sysnamelist[count], cp, t + 1); /* include null */
2811 afs_sysnamecount = setsysname;
2815 cp = aout; /* not changing so report back the count and ... */
2816 memcpy(cp, (char *)&foundname, sizeof(afs_int32));
2817 cp += sizeof(afs_int32);
2819 strcpy(cp, outname); /* ... the entry, ... */
2820 cp += strlen(outname) + 1;
2821 for (count = 1; count < foundname; ++count) { /* ... or list. */
2822 if (!(*sysnamelist)[count])
2824 ("PSetSysName: no afs_sysnamelist entry to read\n");
2825 t = strlen((*sysnamelist)[count]);
2826 if (t >= MAXSYSNAME)
2827 osi_Panic("PSetSysName: sysname entry garbled\n");
2828 strcpy(cp, (*sysnamelist)[count]);
2832 *aoutSize = cp - aout;
2837 /* sequential search through the list of touched cells is not a good
2838 * long-term solution here. For small n, though, it should be just
2839 * fine. Should consider special-casing the local cell for large n.
2840 * Likewise for PSetSPrefs.
2842 * s - number of ids in array l[] -- NOT index of last id
2843 * l - array of cell ids which have volumes that need to be sorted
2844 * vlonly - sort vl servers or file servers?
2847 ReSortCells_cb(struct cell *cell, void *arg)
2849 afs_int32 *p = (afs_int32 *) arg;
2850 afs_int32 *l = p + 1;
2853 for (i = 0; i < s; i++) {
2854 if (l[i] == cell->cellNum) {
2855 ObtainWriteLock(&cell->lock, 690);
2856 afs_SortServers(cell->cellHosts, MAXCELLHOSTS);
2857 ReleaseWriteLock(&cell->lock);
2865 ReSortCells(int s, afs_int32 * l, int vlonly)
2873 p = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * (s + 1));
2875 memcpy(p + 1, l, s * sizeof(afs_int32));
2876 afs_TraverseCells(&ReSortCells_cb, p);
2877 afs_osi_Free(p, sizeof(afs_int32) * (s + 1));
2881 ObtainReadLock(&afs_xvolume);
2882 for (i = 0; i < NVOLS; i++) {
2883 for (j = afs_volumes[i]; j; j = j->next) {
2884 for (k = 0; k < s; k++)
2885 if (j->cell == l[k]) {
2886 ObtainWriteLock(&j->lock, 233);
2887 afs_SortServers(j->serverHost, MAXHOSTS);
2888 ReleaseWriteLock(&j->lock);
2893 ReleaseReadLock(&afs_xvolume);
2897 static int debugsetsp = 0;
2899 afs_setsprefs(sp, num, vlonly)
2902 unsigned int vlonly;
2905 int i, j, k, matches, touchedSize;
2906 struct server *srvr = NULL;
2907 afs_int32 touched[34];
2911 for (k = 0; k < num; sp++, k++) {
2913 printf("sp host=%x, rank=%d\n", sp->host.s_addr, sp->rank);
2916 ObtainReadLock(&afs_xserver);
2918 i = SHash(sp->host.s_addr);
2919 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2920 if (sa->sa_ip == sp->host.s_addr) {
2922 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
2923 || (sa->sa_portal == AFS_FSPORT);
2924 if ((!vlonly && isfs) || (vlonly && !isfs)) {
2931 if (sa && matches) { /* found one! */
2933 printf("sa ip=%x, ip_rank=%d\n", sa->sa_ip, sa->sa_iprank);
2935 sa->sa_iprank = sp->rank + afs_randomMod15();
2936 afs_SortOneServer(sa->server);
2939 /* if we don't know yet what cell it's in, this is moot */
2940 for (j = touchedSize - 1;
2941 j >= 0 && touched[j] != srvr->cell->cellNum; j--)
2942 /* is it in our list of touched cells ? */ ;
2943 if (j < 0) { /* no, it's not */
2944 touched[touchedSize++] = srvr->cell->cellNum;
2945 if (touchedSize >= 32) { /* watch for ovrflow */
2946 ReleaseReadLock(&afs_xserver);
2947 ReSortCells(touchedSize, touched, vlonly);
2949 ObtainReadLock(&afs_xserver);
2955 ReleaseReadLock(&afs_xserver);
2956 /* if we didn't find one, start to create one. */
2957 /* Note that it doesn't have a cell yet... */
2959 afs_uint32 temp = sp->host.s_addr;
2961 afs_GetServer(&temp, 1, 0, (vlonly ? AFS_VLPORT : AFS_FSPORT),
2962 WRITE_LOCK, (afsUUID *) 0, 0);
2963 srvr->addr->sa_iprank = sp->rank + afs_randomMod15();
2964 afs_PutServer(srvr, WRITE_LOCK);
2966 } /* for all cited preferences */
2968 ReSortCells(touchedSize, touched, vlonly);
2972 /* Note that this may only be performed by the local root user.
2974 DECL_PIOCTL(PSetSPrefs)
2976 struct setspref *ssp;
2977 AFS_STATCNT(PSetSPrefs);
2979 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2980 return EIO; /* Inappropriate ioctl for device */
2982 if (!afs_osi_suser(*acred))
2985 if (ainSize < sizeof(struct setspref))
2988 ssp = (struct setspref *)ain;
2989 if (ainSize < sizeof(struct spref) * ssp->num_servers)
2992 afs_setsprefs(&(ssp->servers[0]), ssp->num_servers,
2993 (ssp->flags & DBservers));
2997 DECL_PIOCTL(PSetSPrefs33)
3000 AFS_STATCNT(PSetSPrefs);
3001 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3002 return EIO; /* Inappropriate ioctl for device */
3005 if (!afs_osi_suser(*acred))
3008 sp = (struct spref *)ain;
3009 afs_setsprefs(sp, ainSize / (sizeof(struct spref)), 0 /*!vlonly */ );
3013 /* some notes on the following code...
3014 * in the hash table of server structs, all servers with the same IP address
3015 * will be on the same overflow chain.
3016 * This could be sped slightly in some circumstances by having it cache the
3017 * immediately previous slot in the hash table and some supporting information
3018 * Only reports file servers now.
3020 DECL_PIOCTL(PGetSPrefs)
3022 struct sprefrequest *spin; /* input */
3023 struct sprefinfo *spout; /* output */
3024 struct spref *srvout; /* one output component */
3025 int i, j; /* counters for hash table traversal */
3026 struct server *srvr; /* one of CM's server structs */
3028 int vlonly; /* just return vlservers ? */
3031 AFS_STATCNT(PGetSPrefs);
3032 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3033 return EIO; /* Inappropriate ioctl for device */
3036 if (ainSize < sizeof(struct sprefrequest_33)) {
3039 spin = ((struct sprefrequest *)ain);
3042 if (ainSize > sizeof(struct sprefrequest_33)) {
3043 vlonly = (spin->flags & DBservers);
3047 /* struct sprefinfo includes 1 server struct... that size gets added
3048 * in during the loop that follows.
3050 *aoutSize = sizeof(struct sprefinfo) - sizeof(struct spref);
3051 spout = (struct sprefinfo *)aout;
3052 spout->next_offset = spin->offset;
3053 spout->num_servers = 0;
3054 srvout = spout->servers;
3056 ObtainReadLock(&afs_xserver);
3057 for (i = 0, j = 0; j < NSERVERS; j++) { /* sift through hash table */
3058 for (sa = afs_srvAddrs[j]; sa; sa = sa->next_bkt, i++) {
3059 if (spin->offset > (unsigned short)i) {
3060 continue; /* catch up to where we left off */
3062 spout->next_offset++;
3065 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
3066 || (sa->sa_portal == AFS_FSPORT);
3068 if ((vlonly && isfs) || (!vlonly && !isfs)) {
3069 /* only report ranks for vl servers */
3073 srvout->host.s_addr = sa->sa_ip;
3074 srvout->rank = sa->sa_iprank;
3075 *aoutSize += sizeof(struct spref);
3076 spout->num_servers++;
3079 if (*aoutSize > (PIGGYSIZE - sizeof(struct spref))) {
3080 ReleaseReadLock(&afs_xserver); /* no more room! */
3085 ReleaseReadLock(&afs_xserver);
3087 spout->next_offset = 0; /* start over from the beginning next time */
3091 /* Enable/Disable the specified exporter. Must be root to disable an exporter */
3092 int afs_NFSRootOnly = 1;
3093 DECL_PIOCTL(PExportAfs)
3095 afs_int32 export, newint =
3096 0, type, changestate, handleValue, convmode, pwsync, smounts;
3097 register struct afs_exporter *exporter;
3099 AFS_STATCNT(PExportAfs);
3100 memcpy((char *)&handleValue, ain, sizeof(afs_int32));
3101 type = handleValue >> 24;
3106 exporter = exporter_find(type);
3108 export = handleValue & 3;
3109 changestate = handleValue & 0xff;
3110 smounts = (handleValue >> 2) & 3;
3111 pwsync = (handleValue >> 4) & 3;
3112 convmode = (handleValue >> 6) & 3;
3114 changestate = (handleValue >> 16) & 0x1;
3115 convmode = (handleValue >> 16) & 0x2;
3116 pwsync = (handleValue >> 16) & 0x4;
3117 smounts = (handleValue >> 16) & 0x8;
3118 export = handleValue & 0xff;
3121 /* Failed finding desired exporter; */
3125 handleValue = exporter->exp_states;
3126 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3127 *aoutSize = sizeof(afs_int32);
3129 if (!afs_osi_suser(*acred))
3130 return EACCES; /* Only superuser can do this */
3134 exporter->exp_states |= EXP_EXPORTED;
3136 exporter->exp_states &= ~EXP_EXPORTED;
3140 exporter->exp_states |= EXP_UNIXMODE;
3142 exporter->exp_states &= ~EXP_UNIXMODE;
3146 exporter->exp_states |= EXP_PWSYNC;
3148 exporter->exp_states &= ~EXP_PWSYNC;
3152 afs_NFSRootOnly = 0;
3153 exporter->exp_states |= EXP_SUBMOUNTS;
3155 afs_NFSRootOnly = 1;
3156 exporter->exp_states &= ~EXP_SUBMOUNTS;
3159 handleValue = exporter->exp_states;
3160 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3161 *aoutSize = sizeof(afs_int32);
3164 exporter->exp_states |= EXP_EXPORTED;
3166 exporter->exp_states &= ~EXP_EXPORTED;
3168 exporter->exp_states |= EXP_UNIXMODE;
3170 exporter->exp_states &= ~EXP_UNIXMODE;
3172 exporter->exp_states |= EXP_PWSYNC;
3174 exporter->exp_states &= ~EXP_PWSYNC;
3176 afs_NFSRootOnly = 0;
3177 exporter->exp_states |= EXP_SUBMOUNTS;
3179 afs_NFSRootOnly = 1;
3180 exporter->exp_states &= ~EXP_SUBMOUNTS;
3190 struct gaginfo *gagflags;
3192 if (!afs_osi_suser(*acred))
3195 gagflags = (struct gaginfo *)ain;
3196 afs_showflags = gagflags->showflags;
3202 DECL_PIOCTL(PTwiddleRx)
3204 struct rxparams *rxp;
3206 if (!afs_osi_suser(*acred))
3209 rxp = (struct rxparams *)ain;
3211 if (rxp->rx_initReceiveWindow)
3212 rx_initReceiveWindow = rxp->rx_initReceiveWindow;
3213 if (rxp->rx_maxReceiveWindow)
3214 rx_maxReceiveWindow = rxp->rx_maxReceiveWindow;
3215 if (rxp->rx_initSendWindow)
3216 rx_initSendWindow = rxp->rx_initSendWindow;
3217 if (rxp->rx_maxSendWindow)
3218 rx_maxSendWindow = rxp->rx_maxSendWindow;
3219 if (rxp->rxi_nSendFrags)
3220 rxi_nSendFrags = rxp->rxi_nSendFrags;
3221 if (rxp->rxi_nRecvFrags)
3222 rxi_nRecvFrags = rxp->rxi_nRecvFrags;
3223 if (rxp->rxi_OrphanFragSize)
3224 rxi_OrphanFragSize = rxp->rxi_OrphanFragSize;
3225 if (rxp->rx_maxReceiveSize) {
3226 rx_maxReceiveSize = rxp->rx_maxReceiveSize;
3227 rx_maxReceiveSizeUser = rxp->rx_maxReceiveSize;
3229 if (rxp->rx_MyMaxSendSize)
3230 rx_MyMaxSendSize = rxp->rx_MyMaxSendSize;
3235 DECL_PIOCTL(PGetInitParams)
3237 if (sizeof(struct cm_initparams) > PIGGYSIZE)
3240 memcpy(aout, (char *)&cm_initParams, sizeof(struct cm_initparams));
3241 *aoutSize = sizeof(struct cm_initparams);
3245 #ifdef AFS_SGI65_ENV
3246 /* They took crget() from us, so fake it. */
3251 cr = crdup(get_current_cred());
3252 memset((char *)cr, 0, sizeof(cred_t));
3253 #if CELL || CELL_PREPARE
3260 DECL_PIOCTL(PGetRxkcrypt)
3262 memcpy(aout, (char *)&cryptall, sizeof(afs_int32));
3263 *aoutSize = sizeof(afs_int32);
3267 DECL_PIOCTL(PSetRxkcrypt)
3271 if (!afs_osi_suser(*acred))
3273 if (ainSize != sizeof(afs_int32) || ain == NULL)
3275 memcpy((char *)&tmpval, ain, sizeof(afs_int32));
3276 /* if new mappings added later this will need to be changed */
3277 if (tmpval != 0 && tmpval != 1)
3283 #ifdef AFS_NEED_CLIENTCONTEXT
3285 * Create new credentials to correspond to a remote user with given
3286 * <hostaddr, uid, g0, g1>. This allows a server running as root to
3287 * provide pioctl (and other) services to foreign clients (i.e. nfs
3288 * clients) by using this call to `become' the client.
3291 #define PIOCTL_HEADER 6
3293 HandleClientContext(struct afs_ioctl *ablob, int *com,
3294 struct AFS_UCRED **acred, struct AFS_UCRED *credp)
3297 afs_uint32 hostaddr;
3298 afs_int32 uid, g0, g1, i, code, pag, exporter_type;
3299 struct afs_exporter *exporter, *outexporter;
3300 struct AFS_UCRED *newcred;
3301 struct unixuser *au;
3303 #if defined(AFS_SGIMP_ENV)
3304 osi_Assert(ISAFS_GLOCK());
3306 AFS_STATCNT(HandleClientContext);
3307 if (ablob->in_size < PIOCTL_HEADER * sizeof(afs_int32)) {
3308 /* Must at least include the PIOCTL_HEADER header words required by the protocol */
3309 return EINVAL; /* Too small to be good */
3311 ain = inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
3312 AFS_COPYIN(ablob->in, ain, PIOCTL_HEADER * sizeof(afs_int32), code);
3314 osi_FreeLargeSpace(inData);
3318 /* Extract information for remote user */
3319 hostaddr = *((afs_uint32 *) ain);
3320 ain += sizeof(hostaddr);
3321 uid = *((afs_uint32 *) ain);
3323 g0 = *((afs_uint32 *) ain);
3325 g1 = *((afs_uint32 *) ain);
3327 *com = *((afs_uint32 *) ain);
3328 ain += sizeof(afs_int32);
3329 exporter_type = *((afs_uint32 *) ain); /* In case we support more than NFS */
3332 * Of course, one must be root for most of these functions, but
3333 * we'll allow (for knfs) you to set things if the pag is 0 and
3334 * you're setting tokens or unlogging.
3337 if (!afs_osi_suser(credp)) {
3338 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
3339 /* Since SGI's suser() returns explicit failure after the call.. */
3342 /* check for acceptable opcodes for normal folks, which are, so far,
3343 * set tokens and unlog.
3345 if (i != 9 && i != 3 && i != 38 && i != 8) {
3346 osi_FreeLargeSpace(inData);
3351 ablob->in_size -= PIOCTL_HEADER * sizeof(afs_int32);
3352 ablob->in += PIOCTL_HEADER * sizeof(afs_int32);
3353 osi_FreeLargeSpace(inData);
3356 * We map uid 0 to nobody to match the mapping that the nfs
3357 * server does and to ensure that the suser() calls in the afs
3358 * code fails for remote client roots.
3360 uid = afs_nobody; /* NFS_NOBODY == -2 */
3363 #if defined(AFS_LINUX26_ENV)
3364 newcred->cr_group_info = groups_alloc(0);
3366 #ifdef AFS_AIX41_ENV
3369 newcred->cr_gid = RMTUSER_REQ;
3370 #ifdef AFS_AIX51_ENV
3371 newcred->cr_groupset.gs_union.un_groups[0] = g0;
3372 newcred->cr_groupset.gs_union.un_groups[1] = g1;
3374 newcred->cr_groups[0] = g0;
3375 newcred->cr_groups[1] = g1;
3378 newcred->cr_ngrps = 2;
3380 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV)
3381 newcred->cr_ngroups = 2;
3383 for (i = 2; i < NGROUPS; i++)
3384 newcred->cr_groups[i] = NOGROUP;
3387 #if !defined(AFS_OSF_ENV)
3388 afs_nfsclient_init(); /* before looking for exporter, ensure one exists */
3390 if (!(exporter = exporter_find(exporter_type))) {
3391 /* Exporter wasn't initialized or an invalid exporter type */
3395 if (exporter->exp_states & EXP_PWSYNC) {
3396 if (uid != credp->cr_uid) {
3398 return ENOEXEC; /* XXX Find a better errno XXX */
3401 newcred->cr_uid = uid; /* Only temporary */
3402 code = EXP_REQHANDLER(exporter, &newcred, hostaddr, &pag, &outexporter);
3403 /* The client's pag is the only unique identifier for it */
3404 newcred->cr_uid = pag;
3406 if (!code && *com == PSETPAG) {
3407 /* Special case for 'setpag' */
3408 afs_uint32 pagvalue = genpag();
3410 au = afs_GetUser(pagvalue, -1, WRITE_LOCK); /* a new unixuser struct */
3412 * Note that we leave the 'outexporter' struct held so it won't
3415 au->exporter = outexporter;
3416 if (ablob->out_size >= 4) {
3417 AFS_COPYOUT((char *)&pagvalue, ablob->out, sizeof(afs_int32),
3420 afs_PutUser(au, WRITE_LOCK);
3423 return PSETPAG; /* Special return for setpag */
3425 EXP_RELE(outexporter);
3429 #endif /* AFS_NEED_CLIENTCONTEXT */
3431 /* get all interface addresses of this client */
3433 DECL_PIOCTL(PGetCPrefs)
3435 struct sprefrequest *spin; /* input */
3436 struct sprefinfo *spout; /* output */
3437 struct spref *srvout; /* one output component */
3441 AFS_STATCNT(PGetCPrefs);
3442 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3443 return EIO; /* Inappropriate ioctl for device */
3445 if (ainSize < sizeof(struct sprefrequest))
3448 spin = (struct sprefrequest *)ain;
3449 spout = (struct sprefinfo *)aout;
3451 maxNumber = spin->num_servers; /* max addrs this time */
3452 srvout = spout->servers;
3454 ObtainReadLock(&afs_xinterface);
3456 /* copy out the client interface information from the
3457 ** kernel data structure "interface" to the output buffer
3459 for (i = spin->offset, j = 0; (i < afs_cb_interface.numberOfInterfaces)
3460 && (j < maxNumber); i++, j++, srvout++)
3461 srvout->host.s_addr = afs_cb_interface.addr_in[i];
3463 spout->num_servers = j;
3464 *aoutSize = sizeof(struct sprefinfo) + (j - 1) * sizeof(struct spref);
3466 if (i >= afs_cb_interface.numberOfInterfaces)
3467 spout->next_offset = 0; /* start from beginning again */
3469 spout->next_offset = spin->offset + j;
3471 ReleaseReadLock(&afs_xinterface);
3475 DECL_PIOCTL(PSetCPrefs)
3477 struct setspref *sin;
3480 AFS_STATCNT(PSetCPrefs);
3481 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3482 return EIO; /* Inappropriate ioctl for device */
3484 sin = (struct setspref *)ain;
3486 if (ainSize < sizeof(struct setspref))
3488 #if 0 /* num_servers is unsigned */
3489 if (sin->num_servers < 0)
3492 if (sin->num_servers > AFS_MAX_INTERFACE_ADDR)
3495 ObtainWriteLock(&afs_xinterface, 412);
3496 afs_cb_interface.numberOfInterfaces = sin->num_servers;
3497 for (i = 0; (unsigned short)i < sin->num_servers; i++)
3498 afs_cb_interface.addr_in[i] = sin->servers[i].host.s_addr;
3500 ReleaseWriteLock(&afs_xinterface);
3504 DECL_PIOCTL(PFlushMount)
3506 register afs_int32 code;
3507 register struct vcache *tvc;
3508 register struct dcache *tdc;
3509 struct VenusFid tfid;
3511 struct sysname_info sysState;
3512 afs_size_t offset, len;
3514 AFS_STATCNT(PFlushMount);
3517 code = afs_VerifyVCache(avc, areq);
3520 if (vType(avc) != VDIR) {
3523 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
3526 Check_AtSys(avc, ain, &sysState, areq);
3527 ObtainReadLock(&tdc->lock);
3529 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
3530 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
3531 ReleaseReadLock(&tdc->lock);
3532 afs_PutDCache(tdc); /* we're done with the data */
3533 bufp = sysState.name;
3537 tfid.Cell = avc->fid.Cell;
3538 tfid.Fid.Volume = avc->fid.Fid.Volume;
3539 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
3540 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
3542 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3548 if (tvc->mvstat != 1) {
3553 #ifdef AFS_BOZONLOCK_ENV
3554 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
3556 ObtainWriteLock(&tvc->lock, 649);
3557 ObtainWriteLock(&afs_xcbhash, 650);
3558 afs_DequeueCallback(tvc);
3559 tvc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
3560 ReleaseWriteLock(&afs_xcbhash);
3561 /* now find the disk cache entries */
3562 afs_TryToSmush(tvc, *acred, 1);
3563 osi_dnlc_purgedp(tvc);
3564 afs_symhint_inval(tvc);
3565 if (tvc->linkData && !(tvc->states & CCore)) {
3566 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
3567 tvc->linkData = NULL;
3569 ReleaseWriteLock(&tvc->lock);
3570 #ifdef AFS_BOZONLOCK_ENV
3571 afs_BozonUnlock(&tvc->pvnLock, tvc);
3575 if (sysState.allocked)
3576 osi_FreeLargeSpace(bufp);
3580 DECL_PIOCTL(PRxStatProc)
3585 if (!afs_osi_suser(*acred)) {
3589 if (ainSize != sizeof(afs_int32)) {
3593 memcpy((char *)&flags, ain, sizeof(afs_int32));
3594 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3598 if (flags & AFSCALL_RXSTATS_ENABLE) {
3599 rx_enableProcessRPCStats();
3601 if (flags & AFSCALL_RXSTATS_DISABLE) {
3602 rx_disableProcessRPCStats();
3604 if (flags & AFSCALL_RXSTATS_CLEAR) {
3605 rx_clearProcessRPCStats(AFS_RX_STATS_CLEAR_ALL);
3613 DECL_PIOCTL(PRxStatPeer)
3618 if (!afs_osi_suser(*acred)) {
3622 if (ainSize != sizeof(afs_int32)) {
3626 memcpy((char *)&flags, ain, sizeof(afs_int32));
3627 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3631 if (flags & AFSCALL_RXSTATS_ENABLE) {
3632 rx_enablePeerRPCStats();
3634 if (flags & AFSCALL_RXSTATS_DISABLE) {
3635 rx_disablePeerRPCStats();
3637 if (flags & AFSCALL_RXSTATS_CLEAR) {
3638 rx_clearPeerRPCStats(AFS_RX_STATS_CLEAR_ALL);
3645 DECL_PIOCTL(PPrefetchFromTape)
3647 register afs_int32 code, code1;
3650 struct rx_call *tcall;
3651 struct AFSVolSync tsync;
3652 struct AFSFetchStatus OutStatus;
3653 struct AFSCallBack CallBack;
3654 struct VenusFid tfid;
3658 AFS_STATCNT(PSetAcl);
3662 if (ain && (ainSize == 3 * sizeof(afs_int32)))
3663 Fid = (struct AFSFid *)ain;
3665 Fid = &avc->fid.Fid;
3666 tfid.Cell = avc->fid.Cell;
3667 tfid.Fid.Volume = Fid->Volume;
3668 tfid.Fid.Vnode = Fid->Vnode;
3669 tfid.Fid.Unique = Fid->Unique;
3671 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3673 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3674 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &avc->fid);
3677 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3678 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &tvc->fid);
3681 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3685 tcall = rx_NewCall(tc->id);
3687 StartRXAFS_FetchData(tcall, (struct AFSFid *)&tvc->fid.Fid, 0,
3690 bytes = rx_Read(tcall, (char *)aout, sizeof(afs_int32));
3692 EndRXAFS_FetchData(tcall, &OutStatus, &CallBack, &tsync);
3694 code1 = rx_EndCall(tcall, code);
3698 } while (afs_Analyze
3699 (tc, code, &tvc->fid, areq, AFS_STATS_FS_RPCIDX_RESIDENCYRPCS,
3700 SHARED_LOCK, NULL));
3701 /* This call is done only to have the callback things handled correctly */
3702 afs_FetchStatus(tvc, &tfid, areq, &OutStatus);
3706 *aoutSize = sizeof(afs_int32);
3711 DECL_PIOCTL(PResidencyCmd)
3713 register afs_int32 code;
3716 struct ResidencyCmdInputs *Inputs;
3717 struct ResidencyCmdOutputs *Outputs;
3718 struct VenusFid tfid;
3721 Inputs = (struct ResidencyCmdInputs *)ain;
3722 Outputs = (struct ResidencyCmdOutputs *)aout;
3725 if (!ain || ainSize != sizeof(struct ResidencyCmdInputs))
3730 Fid = &avc->fid.Fid;
3732 tfid.Cell = avc->fid.Cell;
3733 tfid.Fid.Volume = Fid->Volume;
3734 tfid.Fid.Vnode = Fid->Vnode;
3735 tfid.Fid.Unique = Fid->Unique;
3737 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3738 afs_Trace3(afs_iclSetp, CM_TRACE_RESIDCMD, ICL_TYPE_POINTER, tvc,
3739 ICL_TYPE_INT32, Inputs->command, ICL_TYPE_FID, &tfid);
3743 if (Inputs->command) {
3745 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3749 RXAFS_ResidencyCmd(tc->id, Fid, Inputs,
3750 (struct ResidencyCmdOutputs *)aout);
3754 } while (afs_Analyze
3755 (tc, code, &tvc->fid, areq,
3756 AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK, NULL));
3757 /* This call is done to have the callback things handled correctly */
3758 afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3759 } else { /* just a status request, return also link data */
3761 Outputs->code = afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3762 Outputs->chars[0] = 0;
3763 if (vType(tvc) == VLNK) {
3764 ObtainWriteLock(&tvc->lock, 555);
3765 if (afs_HandleLink(tvc, areq) == 0)
3766 strncpy((char *)&Outputs->chars, tvc->linkData, MAXCMDCHARS);
3767 ReleaseWriteLock(&tvc->lock);
3774 *aoutSize = sizeof(struct ResidencyCmdOutputs);
3779 DECL_PIOCTL(PCallBackAddr)
3782 afs_uint32 addr, code;
3788 struct unixuser *tu;
3789 struct srvAddr **addrs;
3791 /*AFS_STATCNT(PCallBackAddr); */
3792 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
3793 return EIO; /* Inappropriate ioctl for device */
3795 if (!afs_osi_suser(acred))
3798 if (ainSize < sizeof(afs_int32))
3801 memcpy(&addr, ain, sizeof(afs_int32));
3803 ObtainReadLock(&afs_xinterface);
3804 for (i = 0; (unsigned short)i < afs_cb_interface.numberOfInterfaces; i++) {
3805 if (afs_cb_interface.addr_in[i] == addr)
3809 ReleaseWriteLock(&afs_xinterface);
3811 if (afs_cb_interface.addr_in[i] != addr)
3814 ObtainReadLock(&afs_xserver); /* Necessary? */
3815 ObtainReadLock(&afs_xsrvAddr);
3818 for (i = 0; i < NSERVERS; i++) {
3819 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3824 addrs = afs_osi_Alloc(srvAddrCount * sizeof(*addrs));
3826 for (i = 0; i < NSERVERS; i++) {
3827 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3828 if (j >= srvAddrCount)
3834 ReleaseReadLock(&afs_xsrvAddr);
3835 ReleaseReadLock(&afs_xserver);
3837 for (i = 0; i < j; i++) {
3843 /* vlserver has no callback conn */
3844 if (sa->sa_portal == AFS_VLPORT) {
3848 if (!ts->cell) /* not really an active server, anyway, it must */
3849 continue; /* have just been added by setsprefs */
3851 /* get a connection, even if host is down; bumps conn ref count */
3852 tu = afs_GetUser(areq->uid, ts->cell->cellNum, SHARED_LOCK);
3853 tc = afs_ConnBySA(sa, ts->cell->fsport, ts->cell->cellNum, tu,
3854 1 /*force */ , 1 /*create */ , SHARED_LOCK);
3855 afs_PutUser(tu, SHARED_LOCK);
3859 if ((sa->sa_flags & SRVADDR_ISDOWN) || afs_HaveCallBacksFrom(ts)) {
3860 if (sa->sa_flags & SRVADDR_ISDOWN) {
3861 rx_SetConnDeadTime(tc->id, 3);
3863 #ifdef RX_ENABLE_LOCKS
3865 #endif /* RX_ENABLE_LOCKS */
3866 code = RXAFS_CallBackRxConnAddr(tc->id, &addr);
3867 #ifdef RX_ENABLE_LOCKS
3869 #endif /* RX_ENABLE_LOCKS */
3871 afs_PutConn(tc, SHARED_LOCK); /* done with it now */
3872 } /* Outer loop over addrs */
3873 #endif /* UKERNEL */