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 #if !defined(AFS_HPUX102_ENV) && !defined(AFS_DARWIN80_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 #ifdef AFS_DARWIN80_ENV
821 return (afs_syscall_pioctl
822 (uap->path, uap->cmd, uap->cmarg, uap->follow,
825 return (afs_syscall_pioctl
826 (uap->path, uap->cmd, uap->cmarg, uap->follow,
827 p->p_cred->pc_ucred));
833 /* macro to avoid adding any more #ifdef's to pioctl code. */
834 #if defined(AFS_LINUX22_ENV) || defined(AFS_AIX41_ENV)
835 #define PIOCTL_FREE_CRED() crfree(credp)
837 #define PIOCTL_FREE_CRED()
842 afs_syscall_pioctl(path, com, cmarg, follow, rvp, credp)
844 struct AFS_UCRED *credp;
846 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
847 afs_syscall_pioctl(path, com, cmarg, follow, credp)
848 struct AFS_UCRED *credp;
850 afs_syscall_pioctl(path, com, cmarg, follow)
858 struct afs_ioctl data;
859 #ifdef AFS_NEED_CLIENTCONTEXT
860 struct AFS_UCRED *tmpcred;
862 struct AFS_UCRED *foreigncreds = NULL;
863 register afs_int32 code = 0;
864 struct vnode *vp = NULL;
866 struct ucred *credp = crref(); /* don't free until done! */
868 #ifdef AFS_LINUX22_ENV
869 cred_t *credp = crref(); /* don't free until done! */
873 AFS_STATCNT(afs_syscall_pioctl);
875 follow = 1; /* compat. with old venus */
876 code = copyin_afs_ioctl(cmarg, &data);
879 #if defined(KERNEL_HAVE_UERROR)
884 if ((com & 0xff) == PSetClientContext) {
885 #ifdef AFS_NEED_CLIENTCONTEXT
886 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV)
887 code = HandleClientContext(&data, &com, &foreigncreds, credp);
889 code = HandleClientContext(&data, &com, &foreigncreds, osi_curcred());
893 crfree(foreigncreds);
896 #if defined(KERNEL_HAVE_UERROR)
897 return (setuerror(code), code);
902 #else /* AFS_NEED_CLIENTCONTEXT */
904 #endif /* AFS_NEED_CLIENTCONTEXT */
906 #ifdef AFS_NEED_CLIENTCONTEXT
909 * We could have done without temporary setting the u.u_cred below
910 * (foreigncreds could be passed as param the pioctl modules)
911 * but calls such as afs_osi_suser() doesn't allow that since it
912 * references u.u_cred directly. We could, of course, do something
913 * like afs_osi_suser(cred) which, I think, is better since it
914 * generalizes and supports multi cred environments...
918 credp = foreigncreds;
919 #elif defined(AFS_AIX41_ENV)
920 tmpcred = crref(); /* XXX */
922 #elif defined(AFS_HPUX101_ENV)
923 tmpcred = p_cred(u.u_procp);
924 set_p_cred(u.u_procp, foreigncreds);
925 #elif defined(AFS_SGI_ENV)
926 tmpcred = OSI_GET_CURRENT_CRED();
927 OSI_SET_CURRENT_CRED(foreigncreds);
930 u.u_cred = foreigncreds;
933 #endif /* AFS_NEED_CLIENTCONTEXT */
934 if ((com & 0xff) == 15) {
935 /* special case prefetch so entire pathname eval occurs in helper process.
936 * otherwise, the pioctl call is essentially useless */
937 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
939 Prefetch(path, &data, follow,
940 foreigncreds ? foreigncreds : credp);
942 code = Prefetch(path, &data, follow, osi_curcred());
945 #if defined(KERNEL_HAVE_UERROR)
954 lookupname(path, USR, follow, NULL, &vp,
955 foreigncreds ? foreigncreds : credp);
957 #ifdef AFS_LINUX22_ENV
958 code = gop_lookupname(path, AFS_UIOUSER, follow, &dp);
960 vp = (struct vnode *)dp->d_inode;
962 code = gop_lookupname(path, AFS_UIOUSER, follow, &vp);
963 #endif /* AFS_LINUX22_ENV */
964 #endif /* AFS_AIX41_ENV */
968 #if defined(KERNEL_HAVE_UERROR)
976 #if defined(AFS_SUN510_ENV)
977 if (vp && !IsAfsVnode(vp)) {
978 struct vnode *realvp;
980 if (VOP_REALVP(vp, &realvp) == 0) {
981 struct vnode *oldvp = vp;
989 /* now make the call if we were passed no file, or were passed an AFS file */
990 if (!vp || IsAfsVnode(vp)) {
991 #if defined(AFS_SUN5_ENV)
992 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
993 #elif defined(AFS_AIX41_ENV)
995 struct ucred *cred1, *cred2;
998 cred1 = cred2 = foreigncreds;
1000 cred1 = cred2 = credp;
1002 code = afs_HandlePioctl(vp, com, &data, follow, &cred1);
1003 if (cred1 != cred2) {
1004 /* something changed the creds */
1008 #elif defined(AFS_HPUX101_ENV)
1010 struct ucred *cred = p_cred(u.u_procp);
1011 code = afs_HandlePioctl(vp, com, &data, follow, &cred);
1013 #elif defined(AFS_SGI_ENV)
1016 credp = OSI_GET_CURRENT_CRED();
1017 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1019 #elif defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1020 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1022 code = afs_HandlePioctl(vp, com, &data, follow, &u.u_cred);
1025 #if defined(KERNEL_HAVE_UERROR)
1028 code = EINVAL; /* not in /afs */
1033 #if defined(AFS_NEED_CLIENTCONTEXT)
1035 #ifdef AFS_AIX41_ENV
1036 crset(tmpcred); /* restore original credentials */
1038 #if defined(AFS_HPUX101_ENV)
1039 set_p_cred(u.u_procp, tmpcred); /* restore original credentials */
1040 #elif defined(AFS_SGI_ENV)
1041 OSI_SET_CURRENT_CRED(tmpcred); /* restore original credentials */
1042 #elif !defined(AFS_SUN5_ENV)
1043 osi_curcred() = tmpcred; /* restore original credentials */
1044 #endif /* AFS_HPUX101_ENV */
1045 crfree(foreigncreds);
1048 #endif /* AFS_NEED_CLIENTCONTEXT */
1050 #ifdef AFS_LINUX22_ENV
1053 AFS_RELE(vp); /* put vnode back */
1057 #if defined(KERNEL_HAVE_UERROR)
1060 return (getuerror());
1066 #define MAXPIOCTLTOKENLEN \
1067 (3*sizeof(afs_int32)+MAXKTCTICKETLEN+sizeof(struct ClearToken)+MAXKTCREALMLEN)
1070 afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
1071 register struct afs_ioctl *ablob, int afollow,
1072 struct AFS_UCRED **acred)
1075 struct vrequest treq;
1076 register afs_int32 code;
1077 register afs_int32 function, device;
1078 afs_int32 inSize, outSize, outSizeMax;
1079 char *inData, *outData;
1080 int (*(*pioctlSw)) ();
1082 struct afs_fakestat_state fakestate;
1084 avc = avp ? VTOAFS(avp) : NULL;
1085 afs_Trace3(afs_iclSetp, CM_TRACE_PIOCTL, ICL_TYPE_INT32, acom & 0xff,
1086 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, afollow);
1087 AFS_STATCNT(HandlePioctl);
1088 if ((code = afs_InitReq(&treq, *acred)))
1090 afs_InitFakeStat(&fakestate);
1092 code = afs_EvalFakeStat(&avc, &fakestate, &treq);
1094 afs_PutFakeStat(&fakestate);
1098 device = (acom & 0xff00) >> 8;
1100 case 'V': /* Original pioctls */
1101 pioctlSw = VpioctlSw;
1102 pioctlSwSize = sizeof(VpioctlSw);
1104 case 'C': /* Coordinated/common pioctls */
1105 pioctlSw = CpioctlSw;
1106 pioctlSwSize = sizeof(CpioctlSw);
1109 afs_PutFakeStat(&fakestate);
1112 function = acom & 0xff;
1113 if (function >= (pioctlSwSize / sizeof(char *))) {
1114 afs_PutFakeStat(&fakestate);
1115 return EINVAL; /* out of range */
1117 inSize = ablob->in_size;
1119 /* Do all range checking before continuing */
1120 if (inSize > MAXPIOCTLTOKENLEN || inSize < 0 || ablob->out_size < 0)
1123 /* Note that we use osi_Alloc for large allocs and osi_AllocLargeSpace for small ones */
1124 if (inSize > AFS_LRALLOCSIZ) {
1125 inData = osi_Alloc(inSize + 1);
1127 inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1132 AFS_COPYIN(ablob->in, inData, inSize, code);
1133 inData[inSize] = '\0';
1137 if (inSize > AFS_LRALLOCSIZ) {
1138 osi_Free(inData, inSize + 1);
1140 osi_FreeLargeSpace(inData);
1142 afs_PutFakeStat(&fakestate);
1145 if (function == 8 && device == 'V') { /* PGetTokens */
1146 outSizeMax = MAXPIOCTLTOKENLEN;
1147 outData = osi_Alloc(outSizeMax);
1149 outSizeMax = AFS_LRALLOCSIZ;
1150 outData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1153 if (inSize > AFS_LRALLOCSIZ) {
1154 osi_Free(inData, inSize + 1);
1156 osi_FreeLargeSpace(inData);
1158 afs_PutFakeStat(&fakestate);
1163 (*pioctlSw[function]) (avc, function, &treq, inData, outData, inSize,
1165 if (inSize > AFS_LRALLOCSIZ) {
1166 osi_Free(inData, inSize + 1);
1168 osi_FreeLargeSpace(inData);
1170 if (code == 0 && ablob->out_size > 0) {
1171 if (outSize > ablob->out_size) {
1172 code = E2BIG; /* data wont fit in user buffer */
1173 } else if (outSize) {
1174 AFS_COPYOUT(outData, ablob->out, outSize, code);
1177 if (outSizeMax > AFS_LRALLOCSIZ) {
1178 osi_Free(outData, outSizeMax);
1180 osi_FreeLargeSpace(outData);
1182 afs_PutFakeStat(&fakestate);
1183 return afs_CheckCode(code, &treq, 41);
1186 DECL_PIOCTL(PGetFID)
1188 AFS_STATCNT(PGetFID);
1191 memcpy(aout, (char *)&avc->fid, sizeof(struct VenusFid));
1192 *aoutSize = sizeof(struct VenusFid);
1196 DECL_PIOCTL(PSetAcl)
1198 register afs_int32 code;
1200 struct AFSOpaque acl;
1201 struct AFSVolSync tsync;
1202 struct AFSFetchStatus OutStatus;
1205 AFS_STATCNT(PSetAcl);
1208 if ((acl.AFSOpaque_len = strlen(ain) + 1) > 1024 /* AFSOPAQUEMAX */)
1211 acl.AFSOpaque_val = ain;
1213 tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1215 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREACL);
1218 RXAFS_StoreACL(tconn->id, (struct AFSFid *)&avc->fid.Fid,
1219 &acl, &OutStatus, &tsync);
1224 } while (afs_Analyze
1225 (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_STOREACL,
1226 SHARED_LOCK, NULL));
1228 /* now we've forgotten all of the access info */
1229 ObtainWriteLock(&afs_xcbhash, 455);
1231 afs_DequeueCallback(avc);
1232 avc->states &= ~(CStatd | CUnique);
1233 ReleaseWriteLock(&afs_xcbhash);
1234 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
1235 osi_dnlc_purgedp(avc);
1239 int afs_defaultAsynchrony = 0;
1241 DECL_PIOCTL(PStoreBehind)
1244 struct sbstruct *sbr;
1246 sbr = (struct sbstruct *)ain;
1247 if (sbr->sb_default != -1) {
1248 if (afs_osi_suser(*acred))
1249 afs_defaultAsynchrony = sbr->sb_default;
1254 if (avc && (sbr->sb_thisfile != -1)) {
1256 (avc, PRSFS_WRITE | PRSFS_ADMINISTER, areq, DONT_CHECK_MODE_BITS))
1257 avc->asynchrony = sbr->sb_thisfile;
1262 *aoutSize = sizeof(struct sbstruct);
1263 sbr = (struct sbstruct *)aout;
1264 sbr->sb_default = afs_defaultAsynchrony;
1266 sbr->sb_thisfile = avc->asynchrony;
1272 DECL_PIOCTL(PGCPAGs)
1274 if (!afs_osi_suser(*acred)) {
1277 afs_gcpags = AFS_GCPAGS_USERDISABLED;
1281 DECL_PIOCTL(PGetAcl)
1283 struct AFSOpaque acl;
1284 struct AFSVolSync tsync;
1285 struct AFSFetchStatus OutStatus;
1291 AFS_STATCNT(PGetAcl);
1294 Fid.Volume = avc->fid.Fid.Volume;
1295 Fid.Vnode = avc->fid.Fid.Vnode;
1296 Fid.Unique = avc->fid.Fid.Unique;
1297 if (avc->states & CForeign) {
1299 * For a dfs xlator acl we have a special hack so that the
1300 * xlator will distinguish which type of acl will return. So
1301 * we currently use the top 2-bytes (vals 0-4) to tell which
1302 * type of acl to bring back. Horrible hack but this will
1303 * cause the least number of changes to code size and interfaces.
1305 if (Fid.Vnode & 0xc0000000)
1307 Fid.Vnode |= (ainSize << 30);
1309 acl.AFSOpaque_val = aout;
1311 tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1314 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHACL);
1316 code = RXAFS_FetchACL(tconn->id, &Fid, &acl, &OutStatus, &tsync);
1321 } while (afs_Analyze
1322 (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_FETCHACL,
1323 SHARED_LOCK, NULL));
1326 *aoutSize = (acl.AFSOpaque_len == 0 ? 1 : acl.AFSOpaque_len);
1339 AFS_STATCNT(PBogus);
1343 DECL_PIOCTL(PGetFileCell)
1345 register struct cell *tcell;
1347 AFS_STATCNT(PGetFileCell);
1350 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
1353 strcpy(aout, tcell->cellName);
1354 afs_PutCell(tcell, READ_LOCK);
1355 *aoutSize = strlen(aout) + 1;
1359 DECL_PIOCTL(PGetWSCell)
1361 struct cell *tcell = NULL;
1363 AFS_STATCNT(PGetWSCell);
1364 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1365 return EIO; /* Inappropriate ioctl for device */
1367 tcell = afs_GetPrimaryCell(READ_LOCK);
1368 if (!tcell) /* no primary cell? */
1370 strcpy(aout, tcell->cellName);
1371 *aoutSize = strlen(aout) + 1;
1372 afs_PutCell(tcell, READ_LOCK);
1376 DECL_PIOCTL(PGetUserCell)
1378 register afs_int32 i;
1379 register struct unixuser *tu;
1380 register struct cell *tcell;
1382 AFS_STATCNT(PGetUserCell);
1383 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1384 return EIO; /* Inappropriate ioctl for device */
1386 /* return the cell name of the primary cell for this user */
1387 i = UHash(areq->uid);
1388 ObtainWriteLock(&afs_xuser, 224);
1389 for (tu = afs_users[i]; tu; tu = tu->next) {
1390 if (tu->uid == areq->uid && (tu->states & UPrimary)) {
1392 ReleaseWriteLock(&afs_xuser);
1397 tcell = afs_GetCell(tu->cell, READ_LOCK);
1398 afs_PutUser(tu, WRITE_LOCK);
1402 strcpy(aout, tcell->cellName);
1403 afs_PutCell(tcell, READ_LOCK);
1404 *aoutSize = strlen(aout) + 1; /* 1 for the null */
1407 ReleaseWriteLock(&afs_xuser);
1414 DECL_PIOCTL(PSetTokens)
1417 register struct unixuser *tu;
1418 struct ClearToken clear;
1419 register struct cell *tcell;
1422 struct vrequest treq;
1423 afs_int32 flag, set_parent_pag = 0;
1425 AFS_STATCNT(PSetTokens);
1426 if (!afs_resourceinit_flag) {
1429 memcpy((char *)&i, ain, sizeof(afs_int32));
1430 ain += sizeof(afs_int32);
1431 stp = ain; /* remember where the ticket is */
1432 if (i < 0 || i > MAXKTCTICKETLEN)
1433 return EINVAL; /* malloc may fail */
1435 ain += i; /* skip over ticket */
1436 memcpy((char *)&i, ain, sizeof(afs_int32));
1437 ain += sizeof(afs_int32);
1438 if (i != sizeof(struct ClearToken)) {
1441 memcpy((char *)&clear, ain, sizeof(struct ClearToken));
1442 if (clear.AuthHandle == -1)
1443 clear.AuthHandle = 999; /* more rxvab compat stuff */
1444 ain += sizeof(struct ClearToken);
1445 if (ainSize != 2 * sizeof(afs_int32) + stLen + sizeof(struct ClearToken)) {
1446 /* still stuff left? we've got primary flag and cell name. Set these */
1447 memcpy((char *)&flag, ain, sizeof(afs_int32)); /* primary id flag */
1448 ain += sizeof(afs_int32); /* skip id field */
1449 /* rest is cell name, look it up */
1450 /* some versions of gcc appear to need != 0 in order to get this right */
1451 if ((flag & 0x8000) != 0) { /* XXX Use Constant XXX */
1455 tcell = afs_GetCellByName(ain, READ_LOCK);
1459 /* default to primary cell, primary id */
1460 flag = 1; /* primary id */
1461 tcell = afs_GetPrimaryCell(READ_LOCK);
1466 afs_PutCell(tcell, READ_LOCK);
1467 if (set_parent_pag) {
1469 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1470 #if defined(AFS_DARWIN_ENV)
1471 struct proc *p = current_proc(); /* XXX */
1473 struct proc *p = curproc; /* XXX */
1475 #ifndef AFS_DARWIN80_ENV
1476 uprintf("Process %d (%s) tried to change pags in PSetTokens\n",
1477 p->p_pid, p->p_comm);
1479 if (!setpag(p, acred, -1, &pag, 1)) {
1482 if (!setpag(u.u_procp, acred, -1, &pag, 1)) { /* XXX u.u_procp is a no-op XXX */
1484 if (!setpag(acred, -1, &pag, 1)) {
1487 afs_InitReq(&treq, *acred);
1491 /* now we just set the tokens */
1492 tu = afs_GetUser(areq->uid, i, WRITE_LOCK); /* i has the cell # */
1493 tu->vid = clear.ViceId;
1494 if (tu->stp != NULL) {
1495 afs_osi_Free(tu->stp, tu->stLen);
1497 tu->stp = (char *)afs_osi_Alloc(stLen);
1499 memcpy(tu->stp, stp, stLen);
1502 afs_stats_cmfullperf.authent.TicketUpdates++;
1503 afs_ComputePAGStats();
1504 #endif /* AFS_NOSTATS */
1505 tu->states |= UHasTokens;
1506 tu->states &= ~UTokensBad;
1507 afs_SetPrimary(tu, flag);
1508 tu->tokenTime = osi_Time();
1509 afs_ResetUserConns(tu);
1510 afs_PutUser(tu, WRITE_LOCK);
1525 DECL_PIOCTL(PGetVolumeStatus)
1528 char *offLineMsg = afs_osi_Alloc(256);
1529 char *motd = afs_osi_Alloc(256);
1530 register struct conn *tc;
1531 register afs_int32 code = 0;
1532 struct AFSFetchVolumeStatus volstat;
1534 char *Name, *OfflineMsg, *MOTD;
1537 AFS_STATCNT(PGetVolumeStatus);
1543 OfflineMsg = offLineMsg;
1546 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1548 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS);
1551 RXAFS_GetVolumeStatus(tc->id, avc->fid.Fid.Volume, &volstat,
1552 &Name, &OfflineMsg, &MOTD);
1557 } while (afs_Analyze
1558 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS,
1559 SHARED_LOCK, NULL));
1563 /* Copy all this junk into msg->im_data, keeping track of the lengths. */
1565 memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
1566 cp += sizeof(VolumeStatus);
1567 strcpy(cp, volName);
1568 cp += strlen(volName) + 1;
1569 strcpy(cp, offLineMsg);
1570 cp += strlen(offLineMsg) + 1;
1572 cp += strlen(motd) + 1;
1573 *aoutSize = (cp - aout);
1575 afs_osi_Free(offLineMsg, 256);
1576 afs_osi_Free(motd, 256);
1580 DECL_PIOCTL(PSetVolumeStatus)
1583 char *offLineMsg = afs_osi_Alloc(256);
1584 char *motd = afs_osi_Alloc(256);
1585 register struct conn *tc;
1586 register afs_int32 code = 0;
1587 struct AFSFetchVolumeStatus volstat;
1588 struct AFSStoreVolumeStatus storeStat;
1589 register struct volume *tvp;
1593 AFS_STATCNT(PSetVolumeStatus);
1599 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
1601 if (tvp->states & (VRO | VBackup)) {
1602 afs_PutVolume(tvp, READ_LOCK);
1606 afs_PutVolume(tvp, READ_LOCK);
1611 /* Copy the junk out, using cp as a roving pointer. */
1613 memcpy((char *)&volstat, cp, sizeof(AFSFetchVolumeStatus));
1614 cp += sizeof(AFSFetchVolumeStatus);
1615 if (strlen(cp) >= sizeof(volName)) {
1619 strcpy(volName, cp);
1620 cp += strlen(volName) + 1;
1621 if (strlen(cp) >= sizeof(offLineMsg)) {
1625 strcpy(offLineMsg, cp);
1626 cp += strlen(offLineMsg) + 1;
1627 if (strlen(cp) >= sizeof(motd)) {
1633 if (volstat.MinQuota != -1) {
1634 storeStat.MinQuota = volstat.MinQuota;
1635 storeStat.Mask |= AFS_SETMINQUOTA;
1637 if (volstat.MaxQuota != -1) {
1638 storeStat.MaxQuota = volstat.MaxQuota;
1639 storeStat.Mask |= AFS_SETMAXQUOTA;
1642 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1644 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS);
1647 RXAFS_SetVolumeStatus(tc->id, avc->fid.Fid.Volume, &storeStat,
1648 volName, offLineMsg, motd);
1653 } while (afs_Analyze
1654 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS,
1655 SHARED_LOCK, NULL));
1659 /* we are sending parms back to make compat. with prev system. should
1660 * change interface later to not ask for current status, just set new status */
1662 memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
1663 cp += sizeof(VolumeStatus);
1664 strcpy(cp, volName);
1665 cp += strlen(volName) + 1;
1666 strcpy(cp, offLineMsg);
1667 cp += strlen(offLineMsg) + 1;
1669 cp += strlen(motd) + 1;
1670 *aoutSize = cp - aout;
1672 afs_osi_Free(offLineMsg, 256);
1673 afs_osi_Free(motd, 256);
1679 AFS_STATCNT(PFlush);
1682 #ifdef AFS_BOZONLOCK_ENV
1683 afs_BozonLock(&avc->pvnLock, avc); /* Since afs_TryToSmush will do a pvn_vptrunc */
1685 ObtainWriteLock(&avc->lock, 225);
1686 ObtainWriteLock(&afs_xcbhash, 456);
1687 afs_DequeueCallback(avc);
1688 avc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
1689 ReleaseWriteLock(&afs_xcbhash);
1690 /* now find the disk cache entries */
1691 afs_TryToSmush(avc, *acred, 1);
1692 osi_dnlc_purgedp(avc);
1693 if (avc->linkData && !(avc->states & CCore)) {
1694 afs_osi_Free(avc->linkData, strlen(avc->linkData) + 1);
1695 avc->linkData = NULL;
1697 ReleaseWriteLock(&avc->lock);
1698 #ifdef AFS_BOZONLOCK_ENV
1699 afs_BozonUnlock(&avc->pvnLock, avc);
1704 DECL_PIOCTL(PNewStatMount)
1706 register afs_int32 code;
1707 register struct vcache *tvc;
1708 register struct dcache *tdc;
1709 struct VenusFid tfid;
1711 struct sysname_info sysState;
1712 afs_size_t offset, len;
1714 AFS_STATCNT(PNewStatMount);
1717 code = afs_VerifyVCache(avc, areq);
1720 if (vType(avc) != VDIR) {
1723 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
1726 Check_AtSys(avc, ain, &sysState, areq);
1727 ObtainReadLock(&tdc->lock);
1729 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
1730 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
1731 ReleaseReadLock(&tdc->lock);
1732 afs_PutDCache(tdc); /* we're done with the data */
1733 bufp = sysState.name;
1737 tfid.Cell = avc->fid.Cell;
1738 tfid.Fid.Volume = avc->fid.Fid.Volume;
1739 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
1740 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
1742 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
1748 if (tvc->mvstat != 1) {
1753 ObtainWriteLock(&tvc->lock, 226);
1754 code = afs_HandleLink(tvc, areq);
1756 if (tvc->linkData) {
1757 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
1760 /* we have the data */
1761 strcpy(aout, tvc->linkData);
1762 *aoutSize = strlen(tvc->linkData) + 1;
1767 ReleaseWriteLock(&tvc->lock);
1770 if (sysState.allocked)
1771 osi_FreeLargeSpace(bufp);
1775 DECL_PIOCTL(PGetTokens)
1777 register struct cell *tcell;
1778 register afs_int32 i;
1779 register struct unixuser *tu;
1784 AFS_STATCNT(PGetTokens);
1785 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1786 return EIO; /* Inappropriate ioctl for device */
1788 /* weird interface. If input parameter is present, it is an integer and
1789 * we're supposed to return the parm'th tokens for this unix uid.
1790 * If not present, we just return tokens for cell 1.
1791 * If counter out of bounds, return EDOM.
1792 * If no tokens for the particular cell, return ENOTCONN.
1793 * Also, if this mysterious parm is present, we return, along with the
1794 * tokens, the primary cell indicator (an afs_int32 0) and the cell name
1795 * at the end, in that order.
1797 if ((newStyle = (ainSize > 0))) {
1798 memcpy((char *)&iterator, ain, sizeof(afs_int32));
1800 i = UHash(areq->uid);
1801 ObtainReadLock(&afs_xuser);
1802 for (tu = afs_users[i]; tu; tu = tu->next) {
1804 if (tu->uid == areq->uid && (tu->states & UHasTokens)) {
1805 if (iterator-- == 0)
1806 break; /* are we done yet? */
1809 if (tu->uid == areq->uid && afs_IsPrimaryCellNum(tu->cell))
1815 * No need to hold a read lock on each user entry
1819 ReleaseReadLock(&afs_xuser);
1824 if (((tu->states & UHasTokens) == 0)
1825 || (tu->ct.EndTimestamp < osi_Time())) {
1826 tu->states |= (UTokensBad | UNeedsReset);
1827 afs_PutUser(tu, READ_LOCK);
1830 /* use iterator for temp */
1832 iterator = tu->stLen; /* for compat, we try to return 56 byte tix if they fit */
1834 iterator = 56; /* # of bytes we're returning */
1835 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1836 cp += sizeof(afs_int32);
1837 memcpy(cp, tu->stp, tu->stLen); /* copy out st */
1839 iterator = sizeof(struct ClearToken);
1840 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1841 cp += sizeof(afs_int32);
1842 memcpy(cp, (char *)&tu->ct, sizeof(struct ClearToken));
1843 cp += sizeof(struct ClearToken);
1845 /* put out primary id and cell name, too */
1846 iterator = (tu->states & UPrimary ? 1 : 0);
1847 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1848 cp += sizeof(afs_int32);
1849 tcell = afs_GetCell(tu->cell, READ_LOCK);
1851 strcpy(cp, tcell->cellName);
1852 cp += strlen(tcell->cellName) + 1;
1853 afs_PutCell(tcell, READ_LOCK);
1857 *aoutSize = cp - aout;
1858 afs_PutUser(tu, READ_LOCK);
1864 register afs_int32 i;
1865 register struct unixuser *tu;
1867 AFS_STATCNT(PUnlog);
1868 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1869 return EIO; /* Inappropriate ioctl for device */
1871 i = UHash(areq->uid);
1872 ObtainWriteLock(&afs_xuser, 227);
1873 for (tu = afs_users[i]; tu; tu = tu->next) {
1874 if (tu->uid == areq->uid) {
1876 tu->states &= ~UHasTokens;
1877 /* security is not having to say you're sorry */
1878 memset((char *)&tu->ct, 0, sizeof(struct ClearToken));
1880 ReleaseWriteLock(&afs_xuser);
1881 /* We have to drop the lock over the call to afs_ResetUserConns, since
1882 * it obtains the afs_xvcache lock. We could also keep the lock, and
1883 * modify ResetUserConns to take parm saying we obtained the lock
1884 * already, but that is overkill. By keeping the "tu" pointer
1885 * held over the released lock, we guarantee that we won't lose our
1886 * place, and that we'll pass over every user conn that existed when
1887 * we began this call.
1889 afs_ResetUserConns(tu);
1891 ObtainWriteLock(&afs_xuser, 228);
1893 /* set the expire times to 0, causes
1894 * afs_GCUserData to remove this entry
1896 tu->ct.EndTimestamp = 0;
1898 #endif /* UKERNEL */
1901 ReleaseWriteLock(&afs_xuser);
1905 DECL_PIOCTL(PMariner)
1907 afs_int32 newHostAddr;
1908 afs_int32 oldHostAddr;
1910 AFS_STATCNT(PMariner);
1912 memcpy((char *)&oldHostAddr, (char *)&afs_marinerHost,
1915 oldHostAddr = 0xffffffff; /* disabled */
1917 memcpy((char *)&newHostAddr, ain, sizeof(afs_int32));
1918 if (newHostAddr == 0xffffffff) {
1919 /* disable mariner operations */
1921 } else if (newHostAddr) {
1923 afs_marinerHost = newHostAddr;
1925 memcpy(aout, (char *)&oldHostAddr, sizeof(afs_int32));
1926 *aoutSize = sizeof(afs_int32);
1930 DECL_PIOCTL(PCheckServers)
1932 register char *cp = 0;
1934 register struct server *ts;
1935 afs_int32 temp, *lp = (afs_int32 *) ain, havecell = 0;
1937 struct chservinfo *pcheck;
1939 AFS_STATCNT(PCheckServers);
1941 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1942 return EIO; /* Inappropriate ioctl for device */
1944 if (*lp == 0x12345678) { /* For afs3.3 version */
1945 pcheck = (struct chservinfo *)ain;
1946 if (pcheck->tinterval >= 0) {
1948 memcpy(cp, (char *)&afs_probe_interval, sizeof(afs_int32));
1949 *aoutSize = sizeof(afs_int32);
1950 if (pcheck->tinterval > 0) {
1951 if (!afs_osi_suser(*acred))
1953 afs_probe_interval = pcheck->tinterval;
1959 temp = pcheck->tflags;
1960 cp = pcheck->tbuffer;
1961 } else { /* For pre afs3.3 versions */
1962 memcpy((char *)&temp, ain, sizeof(afs_int32));
1963 cp = ain + sizeof(afs_int32);
1964 if (ainSize > sizeof(afs_int32))
1969 * 1: fast check, don't contact servers.
1970 * 2: local cell only.
1973 /* have cell name, too */
1974 cellp = afs_GetCellByName(cp, READ_LOCK);
1979 if (!cellp && (temp & 2)) {
1980 /* use local cell */
1981 cellp = afs_GetPrimaryCell(READ_LOCK);
1983 if (!(temp & 1)) { /* if not fast, call server checker routine */
1984 afs_CheckServers(1, cellp); /* check down servers */
1985 afs_CheckServers(0, cellp); /* check up servers */
1987 /* now return the current down server list */
1989 ObtainReadLock(&afs_xserver);
1990 for (i = 0; i < NSERVERS; i++) {
1991 for (ts = afs_servers[i]; ts; ts = ts->next) {
1992 if (cellp && ts->cell != cellp)
1993 continue; /* cell spec'd and wrong */
1994 if ((ts->flags & SRVR_ISDOWN)
1995 && ts->addr->sa_portal != ts->cell->vlport) {
1996 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
1997 cp += sizeof(afs_int32);
2001 ReleaseReadLock(&afs_xserver);
2003 afs_PutCell(cellp, READ_LOCK);
2004 *aoutSize = cp - aout;
2008 DECL_PIOCTL(PCheckVolNames)
2010 AFS_STATCNT(PCheckVolNames);
2011 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2012 return EIO; /* Inappropriate ioctl for device */
2014 afs_CheckRootVolume();
2015 afs_CheckVolumeNames(AFS_VOLCHECK_FORCE | AFS_VOLCHECK_EXPIRED |
2016 AFS_VOLCHECK_BUSY | AFS_VOLCHECK_MTPTS);
2020 DECL_PIOCTL(PCheckAuth)
2025 struct unixuser *tu;
2028 AFS_STATCNT(PCheckAuth);
2029 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2030 return EIO; /* Inappropriate ioctl for device */
2033 tu = afs_GetUser(areq->uid, 1, READ_LOCK); /* check local cell authentication */
2037 /* we have a user */
2038 ObtainReadLock(&afs_xsrvAddr);
2039 ObtainReadLock(&afs_xconn);
2041 /* any tokens set? */
2042 if ((tu->states & UHasTokens) == 0)
2044 /* all connections in cell 1 working? */
2045 for (i = 0; i < NSERVERS; i++) {
2046 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2047 for (tc = sa->conns; tc; tc = tc->next) {
2048 if (tc->user == tu && (tu->states & UTokensBad))
2053 ReleaseReadLock(&afs_xsrvAddr);
2054 ReleaseReadLock(&afs_xconn);
2055 afs_PutUser(tu, READ_LOCK);
2057 memcpy(aout, (char *)&retValue, sizeof(afs_int32));
2058 *aoutSize = sizeof(afs_int32);
2063 Prefetch(char *apath, struct afs_ioctl *adata, int afollow,
2064 struct AFS_UCRED *acred)
2067 register afs_int32 code;
2068 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2074 AFS_STATCNT(Prefetch);
2077 tp = osi_AllocLargeSpace(1024);
2078 AFS_COPYINSTR(apath, tp, 1024, &bufferSize, code);
2080 osi_FreeLargeSpace(tp);
2083 if (afs_BBusy()) { /* do this as late as possible */
2084 osi_FreeLargeSpace(tp);
2085 return EWOULDBLOCK; /* pretty close */
2087 afs_BQueue(BOP_PATH, (struct vcache *)0, 0, 0, acred, (afs_size_t) 0,
2088 (afs_size_t) 0, tp);
2092 DECL_PIOCTL(PFindVolume)
2094 register struct volume *tvp;
2095 register struct server *ts;
2096 register afs_int32 i;
2099 AFS_STATCNT(PFindVolume);
2102 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
2105 for (i = 0; i < MAXHOSTS; i++) {
2106 ts = tvp->serverHost[i];
2109 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
2110 cp += sizeof(afs_int32);
2113 /* still room for terminating NULL, add it on */
2114 ainSize = 0; /* reuse vbl */
2115 memcpy(cp, (char *)&ainSize, sizeof(afs_int32));
2116 cp += sizeof(afs_int32);
2118 *aoutSize = cp - aout;
2119 afs_PutVolume(tvp, READ_LOCK);
2125 DECL_PIOCTL(PViceAccess)
2127 register afs_int32 code;
2130 AFS_STATCNT(PViceAccess);
2133 code = afs_VerifyVCache(avc, areq);
2136 memcpy((char *)&temp, ain, sizeof(afs_int32));
2137 code = afs_AccessOK(avc, temp, areq, CHECK_MODE_BITS);
2144 DECL_PIOCTL(PSetCacheSize)
2149 AFS_STATCNT(PSetCacheSize);
2150 if (!afs_osi_suser(*acred))
2152 /* too many things are setup initially in mem cache version */
2153 if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
2155 memcpy((char *)&newValue, ain, sizeof(afs_int32));
2157 afs_cacheBlocks = afs_stats_cmperf.cacheBlocksOrig;
2159 if (newValue < afs_min_cache)
2160 afs_cacheBlocks = afs_min_cache;
2162 afs_cacheBlocks = newValue;
2164 afs_stats_cmperf.cacheBlocksTotal = afs_cacheBlocks;
2165 afs_ComputeCacheParms(); /* recompute basic cache parameters */
2166 afs_MaybeWakeupTruncateDaemon();
2167 while (waitcnt++ < 100 && afs_cacheBlocks < afs_blocksUsed) {
2168 afs_osi_Wait(1000, 0, 0);
2169 afs_MaybeWakeupTruncateDaemon();
2174 #define MAXGCSTATS 16
2175 DECL_PIOCTL(PGetCacheSize)
2177 afs_int32 results[MAXGCSTATS];
2179 register struct dcache * tdc;
2182 AFS_STATCNT(PGetCacheSize);
2184 if (sizeof(afs_int32) == ainSize){
2185 memcpy((char *)&flags, ain, sizeof(afs_int32));
2186 } else if (0 == ainSize){
2192 memset((char *)results, 0, sizeof(results));
2193 results[0] = afs_cacheBlocks;
2194 results[1] = afs_blocksUsed;
2195 results[2] = afs_cacheFiles;
2198 for (i = 0; i < afs_cacheFiles; i++) {
2199 if (afs_indexFlags[i] & IFFree) results[3]++;
2201 } else if (2 == flags){
2202 for (i = 0; i < afs_cacheFiles; i++) {
2203 if (afs_indexFlags[i] & IFFree) results[3]++;
2204 if (afs_indexFlags[i] & IFEverUsed) results[4]++;
2205 if (afs_indexFlags[i] & IFDataMod) results[5]++;
2206 if (afs_indexFlags[i] & IFDirtyPages) results[6]++;
2207 if (afs_indexFlags[i] & IFAnyPages) results[7]++;
2208 if (afs_indexFlags[i] & IFDiscarded) results[8]++;
2210 tdc = afs_indexTable[i];
2213 size = tdc->validPos;
2214 if ( 0 < size && size < (1<<12) ) results[10]++;
2215 else if (size < (1<<14) ) results[11]++;
2216 else if (size < (1<<16) ) results[12]++;
2217 else if (size < (1<<18) ) results[13]++;
2218 else if (size < (1<<20) ) results[14]++;
2219 else if (size >= (1<<20) ) results[15]++;
2223 memcpy(aout, (char *)results, sizeof(results));
2224 *aoutSize = sizeof(results);
2228 DECL_PIOCTL(PRemoveCallBack)
2230 register struct conn *tc;
2231 register afs_int32 code = 0;
2232 struct AFSCallBack CallBacks_Array[1];
2233 struct AFSCBFids theFids;
2234 struct AFSCBs theCBs;
2237 AFS_STATCNT(PRemoveCallBack);
2240 if (avc->states & CRO)
2241 return 0; /* read-only-ness can't change */
2242 ObtainWriteLock(&avc->lock, 229);
2243 theFids.AFSCBFids_len = 1;
2244 theCBs.AFSCBs_len = 1;
2245 theFids.AFSCBFids_val = (struct AFSFid *)&avc->fid.Fid;
2246 theCBs.AFSCBs_val = CallBacks_Array;
2247 CallBacks_Array[0].CallBackType = CB_DROPPED;
2248 if (avc->callback) {
2250 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2252 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
2254 code = RXAFS_GiveUpCallBacks(tc->id, &theFids, &theCBs);
2258 /* don't set code on failure since we wouldn't use it */
2259 } while (afs_Analyze
2260 (tc, code, &avc->fid, areq,
2261 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK, NULL));
2263 ObtainWriteLock(&afs_xcbhash, 457);
2264 afs_DequeueCallback(avc);
2266 avc->states &= ~(CStatd | CUnique);
2267 ReleaseWriteLock(&afs_xcbhash);
2268 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
2269 osi_dnlc_purgedp(avc);
2271 ReleaseWriteLock(&avc->lock);
2275 DECL_PIOCTL(PNewCell)
2277 /* create a new cell */
2278 afs_int32 cellHosts[MAXCELLHOSTS], *lp, magic = 0;
2279 char *newcell = 0, *linkedcell = 0, *tp = ain;
2280 register afs_int32 code, linkedstate = 0, ls;
2281 u_short fsport = 0, vlport = 0;
2284 AFS_STATCNT(PNewCell);
2285 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2286 return EIO; /* Inappropriate ioctl for device */
2288 if (!afs_osi_suser(*acred))
2291 memcpy((char *)&magic, tp, sizeof(afs_int32));
2292 tp += sizeof(afs_int32);
2293 if (magic != 0x12345678)
2296 /* A 3.4 fs newcell command will pass an array of MAXCELLHOSTS
2297 * server addresses while the 3.5 fs newcell command passes
2298 * MAXHOSTS. To figure out which is which, check if the cellname
2301 newcell = tp + (MAXCELLHOSTS + 3) * sizeof(afs_int32);
2302 scount = ((newcell[0] != '\0') ? MAXCELLHOSTS : MAXHOSTS);
2304 /* MAXCELLHOSTS (=8) is less than MAXHOSTS (=13) */
2305 memcpy((char *)cellHosts, tp, MAXCELLHOSTS * sizeof(afs_int32));
2306 tp += (scount * sizeof(afs_int32));
2308 lp = (afs_int32 *) tp;
2312 fsport = 0; /* Privileged ports not allowed */
2314 vlport = 0; /* Privileged ports not allowed */
2315 tp += (3 * sizeof(afs_int32));
2317 if ((ls = *lp) & 1) {
2318 linkedcell = tp + strlen(newcell) + 1;
2319 linkedstate |= CLinkedCell;
2322 linkedstate |= CNoSUID; /* setuid is disabled by default for fs newcell */
2324 afs_NewCell(newcell, cellHosts, linkedstate, linkedcell, fsport,
2329 DECL_PIOCTL(PNewAlias)
2331 /* create a new cell alias */
2333 register afs_int32 code;
2334 char *realName, *aliasName;
2336 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2337 return EIO; /* Inappropriate ioctl for device */
2339 if (!afs_osi_suser(*acred))
2343 tp += strlen(aliasName) + 1;
2346 code = afs_NewCellAlias(aliasName, realName);
2351 DECL_PIOCTL(PListCells)
2353 afs_int32 whichCell;
2354 register struct cell *tcell = 0;
2355 register afs_int32 i;
2356 register char *cp, *tp = ain;
2358 AFS_STATCNT(PListCells);
2359 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2360 return EIO; /* Inappropriate ioctl for device */
2362 memcpy((char *)&whichCell, tp, sizeof(afs_int32));
2363 tp += sizeof(afs_int32);
2364 tcell = afs_GetCellByIndex(whichCell, READ_LOCK);
2367 memset(cp, 0, MAXCELLHOSTS * sizeof(afs_int32));
2368 for (i = 0; i < MAXCELLHOSTS; i++) {
2369 if (tcell->cellHosts[i] == 0)
2371 memcpy(cp, (char *)&tcell->cellHosts[i]->addr->sa_ip,
2373 cp += sizeof(afs_int32);
2375 cp = aout + MAXCELLHOSTS * sizeof(afs_int32);
2376 strcpy(cp, tcell->cellName);
2377 cp += strlen(tcell->cellName) + 1;
2378 *aoutSize = cp - aout;
2379 afs_PutCell(tcell, READ_LOCK);
2387 DECL_PIOCTL(PListAliases)
2389 afs_int32 whichAlias;
2390 register struct cell_alias *tcalias = 0;
2391 register char *cp, *tp = ain;
2393 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2394 return EIO; /* Inappropriate ioctl for device */
2395 if (ainSize < sizeof(afs_int32))
2398 memcpy((char *)&whichAlias, tp, sizeof(afs_int32));
2399 tp += sizeof(afs_int32);
2401 tcalias = afs_GetCellAlias(whichAlias);
2404 strcpy(cp, tcalias->alias);
2405 cp += strlen(tcalias->alias) + 1;
2406 strcpy(cp, tcalias->cell);
2407 cp += strlen(tcalias->cell) + 1;
2408 *aoutSize = cp - aout;
2409 afs_PutCellAlias(tcalias);
2417 DECL_PIOCTL(PRemoveMount)
2419 register afs_int32 code;
2421 struct sysname_info sysState;
2422 afs_size_t offset, len;
2423 register struct conn *tc;
2424 register struct dcache *tdc;
2425 register struct vcache *tvc;
2426 struct AFSFetchStatus OutDirStatus;
2427 struct VenusFid tfid;
2428 struct AFSVolSync tsync;
2432 /* "ain" is the name of the file in this dir to remove */
2434 AFS_STATCNT(PRemoveMount);
2437 code = afs_VerifyVCache(avc, areq);
2440 if (vType(avc) != VDIR)
2443 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1); /* test for error below */
2446 Check_AtSys(avc, ain, &sysState, areq);
2447 ObtainReadLock(&tdc->lock);
2449 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
2450 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
2451 ReleaseReadLock(&tdc->lock);
2452 bufp = sysState.name;
2457 tfid.Cell = avc->fid.Cell;
2458 tfid.Fid.Volume = avc->fid.Fid.Volume;
2459 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
2460 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
2462 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
2469 if (tvc->mvstat != 1) {
2475 ObtainWriteLock(&tvc->lock, 230);
2476 code = afs_HandleLink(tvc, areq);
2478 if (tvc->linkData) {
2479 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
2484 ReleaseWriteLock(&tvc->lock);
2485 osi_dnlc_purgedp(tvc);
2491 ObtainWriteLock(&avc->lock, 231);
2492 osi_dnlc_remove(avc, bufp, tvc);
2494 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2496 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE);
2499 RXAFS_RemoveFile(tc->id, (struct AFSFid *)&avc->fid.Fid, bufp,
2500 &OutDirStatus, &tsync);
2505 } while (afs_Analyze
2506 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_REMOVEFILE,
2507 SHARED_LOCK, NULL));
2512 ReleaseWriteLock(&avc->lock);
2516 /* we have the thing in the cache */
2517 ObtainWriteLock(&tdc->lock, 661);
2518 if (afs_LocalHero(avc, tdc, &OutDirStatus, 1)) {
2519 /* we can do it locally */
2520 code = afs_dir_Delete(tdc, bufp);
2522 ZapDCE(tdc); /* surprise error -- invalid value */
2526 ReleaseWriteLock(&tdc->lock);
2527 afs_PutDCache(tdc); /* drop ref count */
2529 avc->states &= ~CUnique; /* For the dfs xlator */
2530 ReleaseWriteLock(&avc->lock);
2533 if (sysState.allocked)
2534 osi_FreeLargeSpace(bufp);
2538 DECL_PIOCTL(PVenusLogging)
2540 return EINVAL; /* OBSOLETE */
2543 DECL_PIOCTL(PGetCellStatus)
2545 register struct cell *tcell;
2548 AFS_STATCNT(PGetCellStatus);
2549 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2550 return EIO; /* Inappropriate ioctl for device */
2552 tcell = afs_GetCellByName(ain, READ_LOCK);
2555 temp = tcell->states;
2556 afs_PutCell(tcell, READ_LOCK);
2557 memcpy(aout, (char *)&temp, sizeof(afs_int32));
2558 *aoutSize = sizeof(afs_int32);
2562 DECL_PIOCTL(PSetCellStatus)
2564 register struct cell *tcell;
2567 if (!afs_osi_suser(*acred))
2569 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2570 return EIO; /* Inappropriate ioctl for device */
2572 tcell = afs_GetCellByName(ain + 2 * sizeof(afs_int32), WRITE_LOCK);
2575 memcpy((char *)&temp, ain, sizeof(afs_int32));
2577 tcell->states |= CNoSUID;
2579 tcell->states &= ~CNoSUID;
2580 afs_PutCell(tcell, WRITE_LOCK);
2584 DECL_PIOCTL(PFlushVolumeData)
2586 register afs_int32 i;
2587 register struct dcache *tdc;
2588 register struct vcache *tvc;
2589 register struct volume *tv;
2590 afs_int32 cell, volume;
2591 struct afs_q *tq, *uq;
2592 #ifdef AFS_DARWIN80_ENV
2596 AFS_STATCNT(PFlushVolumeData);
2599 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2600 return EIO; /* Inappropriate ioctl for device */
2602 volume = avc->fid.Fid.Volume; /* who to zap */
2603 cell = avc->fid.Cell;
2606 * Clear stat'd flag from all vnodes from this volume; this will invalidate all
2607 * the vcaches associated with the volume.
2610 ObtainReadLock(&afs_xvcache);
2611 i = VCHashV(&avc->fid);
2612 for (tq = afs_vhashTV[i].prev; tq != &afs_vhashTV[i]; tq = uq) {
2615 if (tvc->fid.Fid.Volume == volume && tvc->fid.Cell == cell) {
2616 if (tvc->states & CVInit) {
2617 ReleaseReadLock(&afs_xvcache);
2618 afs_osi_Sleep(&tvc->states);
2621 #ifdef AFS_DARWIN80_ENV
2622 if (tvc->states & CDeadVnode) {
2623 ReleaseReadLock(&afs_xvcache);
2624 afs_osi_Sleep(&tvc->states);
2628 #if defined(AFS_SGI_ENV) || defined(AFS_OSF_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
2629 VN_HOLD(AFSTOV(tvc));
2631 #ifdef AFS_DARWIN80_ENV
2635 if (vnode_ref(vp)) {
2642 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2645 VREFCOUNT_INC(tvc); /* AIX, apparently */
2649 ReleaseReadLock(&afs_xvcache);
2650 #ifdef AFS_BOZONLOCK_ENV
2651 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
2653 ObtainWriteLock(&tvc->lock, 232);
2655 ObtainWriteLock(&afs_xcbhash, 458);
2656 afs_DequeueCallback(tvc);
2657 tvc->states &= ~(CStatd | CDirty);
2658 ReleaseWriteLock(&afs_xcbhash);
2659 if (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
2660 osi_dnlc_purgedp(tvc);
2661 afs_TryToSmush(tvc, *acred, 1);
2662 ReleaseWriteLock(&tvc->lock);
2663 #ifdef AFS_BOZONLOCK_ENV
2664 afs_BozonUnlock(&tvc->pvnLock, tvc);
2666 #ifdef AFS_DARWIN80_ENV
2667 vnode_put(AFSTOV(tvc));
2669 ObtainReadLock(&afs_xvcache);
2671 /* our tvc ptr is still good until now */
2675 ReleaseReadLock(&afs_xvcache);
2678 MObtainWriteLock(&afs_xdcache, 328); /* needed if you're going to flush any stuff */
2679 for (i = 0; i < afs_cacheFiles; i++) {
2680 if (!(afs_indexFlags[i] & IFEverUsed))
2681 continue; /* never had any data */
2682 tdc = afs_GetDSlot(i, NULL);
2683 if (tdc->refCount <= 1) { /* too high, in use by running sys call */
2684 ReleaseReadLock(&tdc->tlock);
2685 if (tdc->f.fid.Fid.Volume == volume && tdc->f.fid.Cell == cell) {
2686 if (!(afs_indexFlags[i] & IFDataMod)) {
2687 /* if the file is modified, but has a ref cnt of only 1, then
2688 * someone probably has the file open and is writing into it.
2689 * Better to skip flushing such a file, it will be brought back
2690 * immediately on the next write anyway.
2692 * If we *must* flush, then this code has to be rearranged to call
2693 * afs_storeAllSegments() first */
2694 afs_FlushDCache(tdc);
2698 ReleaseReadLock(&tdc->tlock);
2700 afs_PutDCache(tdc); /* bumped by getdslot */
2702 MReleaseWriteLock(&afs_xdcache);
2704 ObtainReadLock(&afs_xvolume);
2705 for (i = 0; i < NVOLS; i++) {
2706 for (tv = afs_volumes[i]; tv; tv = tv->next) {
2707 if (tv->volume == volume) {
2708 afs_ResetVolumeInfo(tv);
2713 ReleaseReadLock(&afs_xvolume);
2715 /* probably, a user is doing this, probably, because things are screwed up.
2716 * maybe it's the dnlc's fault? */
2723 DECL_PIOCTL(PGetVnodeXStatus)
2725 register afs_int32 code;
2726 struct vcxstat stat;
2729 /* AFS_STATCNT(PGetVnodeXStatus); */
2732 code = afs_VerifyVCache(avc, areq);
2735 if (vType(avc) == VDIR)
2736 mode = PRSFS_LOOKUP;
2739 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
2742 memset(&stat, 0, sizeof(struct vcxstat));
2743 stat.fid = avc->fid;
2744 hset32(stat.DataVersion, hgetlo(avc->m.DataVersion));
2745 stat.lock = avc->lock;
2746 stat.parentVnode = avc->parentVnode;
2747 stat.parentUnique = avc->parentUnique;
2748 hset(stat.flushDV, avc->flushDV);
2749 hset(stat.mapDV, avc->mapDV);
2750 stat.truncPos = avc->truncPos;
2751 { /* just grab the first two - won't break anything... */
2752 struct axscache *ac;
2754 for (i = 0, ac = avc->Access; ac && i < CPSIZE; i++, ac = ac->next) {
2755 stat.randomUid[i] = ac->uid;
2756 stat.randomAccess[i] = ac->axess;
2759 stat.callback = afs_data_pointer_to_int32(avc->callback);
2760 stat.cbExpires = avc->cbExpires;
2761 stat.anyAccess = avc->anyAccess;
2762 stat.opens = avc->opens;
2763 stat.execsOrWriters = avc->execsOrWriters;
2764 stat.flockCount = avc->flockCount;
2765 stat.mvstat = avc->mvstat;
2766 stat.states = avc->states;
2767 memcpy(aout, (char *)&stat, sizeof(struct vcxstat));
2768 *aoutSize = sizeof(struct vcxstat);
2773 DECL_PIOCTL(PGetVnodeXStatus2)
2775 register afs_int32 code;
2776 struct vcxstat2 stat;
2781 code = afs_VerifyVCache(avc, areq);
2784 if (vType(avc) == VDIR)
2785 mode = PRSFS_LOOKUP;
2788 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
2791 memset(&stat, 0, sizeof(struct vcxstat2));
2793 stat.cbExpires = avc->cbExpires;
2794 stat.anyAccess = avc->anyAccess;
2795 stat.mvstat = avc->mvstat;
2796 stat.callerAccess = afs_GetAccessBits(avc, ~0, areq);
2798 memcpy(aout, (char *)&stat, sizeof(struct vcxstat2));
2799 *aoutSize = sizeof(struct vcxstat2);
2803 /* We require root for local sysname changes, but not for remote */
2804 /* (since we don't really believe remote uids anyway) */
2805 /* outname[] shouldn't really be needed- this is left as an excercise */
2806 /* for the reader. */
2807 DECL_PIOCTL(PSetSysName)
2809 char *cp, *cp2 = NULL, inname[MAXSYSNAME], outname[MAXSYSNAME];
2810 int setsysname, foundname = 0;
2811 register struct afs_exporter *exporter;
2812 register struct unixuser *au;
2813 register afs_int32 pag, error;
2814 int t, count, num = 0;
2815 char **sysnamelist[MAXNUMSYSNAMES];
2817 AFS_STATCNT(PSetSysName);
2818 if (!afs_globalVFS) {
2819 /* Afsd is NOT running; disable it */
2820 #if defined(KERNEL_HAVE_UERROR)
2821 return (setuerror(EINVAL), EINVAL);
2826 memset(inname, 0, MAXSYSNAME);
2827 memcpy((char *)&setsysname, ain, sizeof(afs_int32));
2828 ain += sizeof(afs_int32);
2832 if (setsysname < 0 || setsysname > MAXNUMSYSNAMES)
2835 for (cp = ain, count = 0; count < setsysname; count++) {
2836 /* won't go past end of ain since maxsysname*num < ain length */
2838 if (t >= MAXSYSNAME || t <= 0)
2840 /* check for names that can shoot us in the foot */
2841 if (*cp == '.' && (cp[1] == 0 || (cp[1] == '.' && cp[2] == 0)))
2847 /* inname gets first entry in case we're being a translator */
2849 memcpy(inname, ain, t + 1); /* include terminating null */
2853 if ((*acred)->cr_gid == RMTUSER_REQ) { /* Handles all exporters */
2854 pag = PagInCred(*acred);
2856 return EINVAL; /* Better than panicing */
2858 if (!(au = afs_FindUser(pag, -1, READ_LOCK))) {
2859 return EINVAL; /* Better than panicing */
2861 if (!(exporter = au->exporter)) {
2862 afs_PutUser(au, READ_LOCK);
2863 return EINVAL; /* Better than panicing */
2865 error = EXP_SYSNAME(exporter, (setsysname ? cp2 : NULL), sysnamelist,
2868 if (error == ENODEV)
2869 foundname = 0; /* sysname not set yet! */
2871 afs_PutUser(au, READ_LOCK);
2876 strcpy(outname, (*sysnamelist)[0]);
2878 afs_PutUser(au, READ_LOCK);
2880 /* Not xlating, so local case */
2882 osi_Panic("PSetSysName: !afs_sysname\n");
2883 if (!setsysname) { /* user just wants the info */
2884 strcpy(outname, afs_sysname);
2885 foundname = afs_sysnamecount;
2886 *sysnamelist = afs_sysnamelist;
2887 } else { /* Local guy; only root can change sysname */
2888 if (!afs_osi_suser(*acred))
2891 /* clear @sys entries from the dnlc, once afs_lookup can
2892 * do lookups of @sys entries and thinks it can trust them */
2893 /* privs ok, store the entry, ... */
2894 strcpy(afs_sysname, inname);
2895 if (setsysname > 1) { /* ... or list */
2897 for (count = 1; count < setsysname; ++count) {
2898 if (!afs_sysnamelist[count])
2900 ("PSetSysName: no afs_sysnamelist entry to write\n");
2902 memcpy(afs_sysnamelist[count], cp, t + 1); /* include null */
2906 afs_sysnamecount = setsysname;
2910 cp = aout; /* not changing so report back the count and ... */
2911 memcpy(cp, (char *)&foundname, sizeof(afs_int32));
2912 cp += sizeof(afs_int32);
2914 strcpy(cp, outname); /* ... the entry, ... */
2915 cp += strlen(outname) + 1;
2916 for (count = 1; count < foundname; ++count) { /* ... or list. */
2917 if (!(*sysnamelist)[count])
2919 ("PSetSysName: no afs_sysnamelist entry to read\n");
2920 t = strlen((*sysnamelist)[count]);
2921 if (t >= MAXSYSNAME)
2922 osi_Panic("PSetSysName: sysname entry garbled\n");
2923 strcpy(cp, (*sysnamelist)[count]);
2927 *aoutSize = cp - aout;
2932 /* sequential search through the list of touched cells is not a good
2933 * long-term solution here. For small n, though, it should be just
2934 * fine. Should consider special-casing the local cell for large n.
2935 * Likewise for PSetSPrefs.
2937 * s - number of ids in array l[] -- NOT index of last id
2938 * l - array of cell ids which have volumes that need to be sorted
2939 * vlonly - sort vl servers or file servers?
2942 ReSortCells_cb(struct cell *cell, void *arg)
2944 afs_int32 *p = (afs_int32 *) arg;
2945 afs_int32 *l = p + 1;
2948 for (i = 0; i < s; i++) {
2949 if (l[i] == cell->cellNum) {
2950 ObtainWriteLock(&cell->lock, 690);
2951 afs_SortServers(cell->cellHosts, MAXCELLHOSTS);
2952 ReleaseWriteLock(&cell->lock);
2960 ReSortCells(int s, afs_int32 * l, int vlonly)
2968 p = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * (s + 1));
2970 memcpy(p + 1, l, s * sizeof(afs_int32));
2971 afs_TraverseCells(&ReSortCells_cb, p);
2972 afs_osi_Free(p, sizeof(afs_int32) * (s + 1));
2976 ObtainReadLock(&afs_xvolume);
2977 for (i = 0; i < NVOLS; i++) {
2978 for (j = afs_volumes[i]; j; j = j->next) {
2979 for (k = 0; k < s; k++)
2980 if (j->cell == l[k]) {
2981 ObtainWriteLock(&j->lock, 233);
2982 afs_SortServers(j->serverHost, MAXHOSTS);
2983 ReleaseWriteLock(&j->lock);
2988 ReleaseReadLock(&afs_xvolume);
2992 static int debugsetsp = 0;
2994 afs_setsprefs(sp, num, vlonly)
2997 unsigned int vlonly;
3000 int i, j, k, matches, touchedSize;
3001 struct server *srvr = NULL;
3002 afs_int32 touched[34];
3006 for (k = 0; k < num; sp++, k++) {
3008 printf("sp host=%x, rank=%d\n", sp->host.s_addr, sp->rank);
3011 ObtainReadLock(&afs_xserver);
3013 i = SHash(sp->host.s_addr);
3014 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3015 if (sa->sa_ip == sp->host.s_addr) {
3017 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
3018 || (sa->sa_portal == AFS_FSPORT);
3019 if ((!vlonly && isfs) || (vlonly && !isfs)) {
3026 if (sa && matches) { /* found one! */
3028 printf("sa ip=%x, ip_rank=%d\n", sa->sa_ip, sa->sa_iprank);
3030 sa->sa_iprank = sp->rank + afs_randomMod15();
3031 afs_SortOneServer(sa->server);
3034 /* if we don't know yet what cell it's in, this is moot */
3035 for (j = touchedSize - 1;
3036 j >= 0 && touched[j] != srvr->cell->cellNum; j--)
3037 /* is it in our list of touched cells ? */ ;
3038 if (j < 0) { /* no, it's not */
3039 touched[touchedSize++] = srvr->cell->cellNum;
3040 if (touchedSize >= 32) { /* watch for ovrflow */
3041 ReleaseReadLock(&afs_xserver);
3042 ReSortCells(touchedSize, touched, vlonly);
3044 ObtainReadLock(&afs_xserver);
3050 ReleaseReadLock(&afs_xserver);
3051 /* if we didn't find one, start to create one. */
3052 /* Note that it doesn't have a cell yet... */
3054 afs_uint32 temp = sp->host.s_addr;
3056 afs_GetServer(&temp, 1, 0, (vlonly ? AFS_VLPORT : AFS_FSPORT),
3057 WRITE_LOCK, (afsUUID *) 0, 0);
3058 srvr->addr->sa_iprank = sp->rank + afs_randomMod15();
3059 afs_PutServer(srvr, WRITE_LOCK);
3061 } /* for all cited preferences */
3063 ReSortCells(touchedSize, touched, vlonly);
3067 /* Note that this may only be performed by the local root user.
3069 DECL_PIOCTL(PSetSPrefs)
3071 struct setspref *ssp;
3072 AFS_STATCNT(PSetSPrefs);
3074 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3075 return EIO; /* Inappropriate ioctl for device */
3077 if (!afs_osi_suser(*acred))
3080 if (ainSize < sizeof(struct setspref))
3083 ssp = (struct setspref *)ain;
3084 if (ainSize < sizeof(struct spref) * ssp->num_servers)
3087 afs_setsprefs(&(ssp->servers[0]), ssp->num_servers,
3088 (ssp->flags & DBservers));
3092 DECL_PIOCTL(PSetSPrefs33)
3095 AFS_STATCNT(PSetSPrefs);
3096 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3097 return EIO; /* Inappropriate ioctl for device */
3100 if (!afs_osi_suser(*acred))
3103 sp = (struct spref *)ain;
3104 afs_setsprefs(sp, ainSize / (sizeof(struct spref)), 0 /*!vlonly */ );
3108 /* some notes on the following code...
3109 * in the hash table of server structs, all servers with the same IP address
3110 * will be on the same overflow chain.
3111 * This could be sped slightly in some circumstances by having it cache the
3112 * immediately previous slot in the hash table and some supporting information
3113 * Only reports file servers now.
3115 DECL_PIOCTL(PGetSPrefs)
3117 struct sprefrequest *spin; /* input */
3118 struct sprefinfo *spout; /* output */
3119 struct spref *srvout; /* one output component */
3120 int i, j; /* counters for hash table traversal */
3121 struct server *srvr; /* one of CM's server structs */
3123 int vlonly; /* just return vlservers ? */
3126 AFS_STATCNT(PGetSPrefs);
3127 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3128 return EIO; /* Inappropriate ioctl for device */
3131 if (ainSize < sizeof(struct sprefrequest_33)) {
3134 spin = ((struct sprefrequest *)ain);
3137 if (ainSize > sizeof(struct sprefrequest_33)) {
3138 vlonly = (spin->flags & DBservers);
3142 /* struct sprefinfo includes 1 server struct... that size gets added
3143 * in during the loop that follows.
3145 *aoutSize = sizeof(struct sprefinfo) - sizeof(struct spref);
3146 spout = (struct sprefinfo *)aout;
3147 spout->next_offset = spin->offset;
3148 spout->num_servers = 0;
3149 srvout = spout->servers;
3151 ObtainReadLock(&afs_xserver);
3152 for (i = 0, j = 0; j < NSERVERS; j++) { /* sift through hash table */
3153 for (sa = afs_srvAddrs[j]; sa; sa = sa->next_bkt, i++) {
3154 if (spin->offset > (unsigned short)i) {
3155 continue; /* catch up to where we left off */
3157 spout->next_offset++;
3160 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
3161 || (sa->sa_portal == AFS_FSPORT);
3163 if ((vlonly && isfs) || (!vlonly && !isfs)) {
3164 /* only report ranks for vl servers */
3168 srvout->host.s_addr = sa->sa_ip;
3169 srvout->rank = sa->sa_iprank;
3170 *aoutSize += sizeof(struct spref);
3171 spout->num_servers++;
3174 if (*aoutSize > (PIGGYSIZE - sizeof(struct spref))) {
3175 ReleaseReadLock(&afs_xserver); /* no more room! */
3180 ReleaseReadLock(&afs_xserver);
3182 spout->next_offset = 0; /* start over from the beginning next time */
3186 /* Enable/Disable the specified exporter. Must be root to disable an exporter */
3187 int afs_NFSRootOnly = 1;
3188 DECL_PIOCTL(PExportAfs)
3190 afs_int32 export, newint =
3191 0, type, changestate, handleValue, convmode, pwsync, smounts;
3192 register struct afs_exporter *exporter;
3194 AFS_STATCNT(PExportAfs);
3195 memcpy((char *)&handleValue, ain, sizeof(afs_int32));
3196 type = handleValue >> 24;
3201 exporter = exporter_find(type);
3203 export = handleValue & 3;
3204 changestate = handleValue & 0xff;
3205 smounts = (handleValue >> 2) & 3;
3206 pwsync = (handleValue >> 4) & 3;
3207 convmode = (handleValue >> 6) & 3;
3209 changestate = (handleValue >> 16) & 0x1;
3210 convmode = (handleValue >> 16) & 0x2;
3211 pwsync = (handleValue >> 16) & 0x4;
3212 smounts = (handleValue >> 16) & 0x8;
3213 export = handleValue & 0xff;
3216 /* Failed finding desired exporter; */
3220 handleValue = exporter->exp_states;
3221 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3222 *aoutSize = sizeof(afs_int32);
3224 if (!afs_osi_suser(*acred))
3225 return EACCES; /* Only superuser can do this */
3229 exporter->exp_states |= EXP_EXPORTED;
3231 exporter->exp_states &= ~EXP_EXPORTED;
3235 exporter->exp_states |= EXP_UNIXMODE;
3237 exporter->exp_states &= ~EXP_UNIXMODE;
3241 exporter->exp_states |= EXP_PWSYNC;
3243 exporter->exp_states &= ~EXP_PWSYNC;
3247 afs_NFSRootOnly = 0;
3248 exporter->exp_states |= EXP_SUBMOUNTS;
3250 afs_NFSRootOnly = 1;
3251 exporter->exp_states &= ~EXP_SUBMOUNTS;
3254 handleValue = exporter->exp_states;
3255 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3256 *aoutSize = sizeof(afs_int32);
3259 exporter->exp_states |= EXP_EXPORTED;
3261 exporter->exp_states &= ~EXP_EXPORTED;
3263 exporter->exp_states |= EXP_UNIXMODE;
3265 exporter->exp_states &= ~EXP_UNIXMODE;
3267 exporter->exp_states |= EXP_PWSYNC;
3269 exporter->exp_states &= ~EXP_PWSYNC;
3271 afs_NFSRootOnly = 0;
3272 exporter->exp_states |= EXP_SUBMOUNTS;
3274 afs_NFSRootOnly = 1;
3275 exporter->exp_states &= ~EXP_SUBMOUNTS;
3285 struct gaginfo *gagflags;
3287 if (!afs_osi_suser(*acred))
3290 gagflags = (struct gaginfo *)ain;
3291 afs_showflags = gagflags->showflags;
3297 DECL_PIOCTL(PTwiddleRx)
3299 struct rxparams *rxp;
3301 if (!afs_osi_suser(*acred))
3304 rxp = (struct rxparams *)ain;
3306 if (rxp->rx_initReceiveWindow)
3307 rx_initReceiveWindow = rxp->rx_initReceiveWindow;
3308 if (rxp->rx_maxReceiveWindow)
3309 rx_maxReceiveWindow = rxp->rx_maxReceiveWindow;
3310 if (rxp->rx_initSendWindow)
3311 rx_initSendWindow = rxp->rx_initSendWindow;
3312 if (rxp->rx_maxSendWindow)
3313 rx_maxSendWindow = rxp->rx_maxSendWindow;
3314 if (rxp->rxi_nSendFrags)
3315 rxi_nSendFrags = rxp->rxi_nSendFrags;
3316 if (rxp->rxi_nRecvFrags)
3317 rxi_nRecvFrags = rxp->rxi_nRecvFrags;
3318 if (rxp->rxi_OrphanFragSize)
3319 rxi_OrphanFragSize = rxp->rxi_OrphanFragSize;
3320 if (rxp->rx_maxReceiveSize) {
3321 rx_maxReceiveSize = rxp->rx_maxReceiveSize;
3322 rx_maxReceiveSizeUser = rxp->rx_maxReceiveSize;
3324 if (rxp->rx_MyMaxSendSize)
3325 rx_MyMaxSendSize = rxp->rx_MyMaxSendSize;
3330 DECL_PIOCTL(PGetInitParams)
3332 if (sizeof(struct cm_initparams) > PIGGYSIZE)
3335 memcpy(aout, (char *)&cm_initParams, sizeof(struct cm_initparams));
3336 *aoutSize = sizeof(struct cm_initparams);
3340 #ifdef AFS_SGI65_ENV
3341 /* They took crget() from us, so fake it. */
3346 cr = crdup(get_current_cred());
3347 memset((char *)cr, 0, sizeof(cred_t));
3348 #if CELL || CELL_PREPARE
3355 DECL_PIOCTL(PGetRxkcrypt)
3357 memcpy(aout, (char *)&cryptall, sizeof(afs_int32));
3358 *aoutSize = sizeof(afs_int32);
3362 DECL_PIOCTL(PSetRxkcrypt)
3366 if (!afs_osi_suser(*acred))
3368 if (ainSize != sizeof(afs_int32) || ain == NULL)
3370 memcpy((char *)&tmpval, ain, sizeof(afs_int32));
3371 /* if new mappings added later this will need to be changed */
3372 if (tmpval != 0 && tmpval != 1)
3378 #ifdef AFS_NEED_CLIENTCONTEXT
3380 * Create new credentials to correspond to a remote user with given
3381 * <hostaddr, uid, g0, g1>. This allows a server running as root to
3382 * provide pioctl (and other) services to foreign clients (i.e. nfs
3383 * clients) by using this call to `become' the client.
3386 #define PIOCTL_HEADER 6
3388 HandleClientContext(struct afs_ioctl *ablob, int *com,
3389 struct AFS_UCRED **acred, struct AFS_UCRED *credp)
3392 afs_uint32 hostaddr;
3393 afs_int32 uid, g0, g1, i, code, pag, exporter_type;
3394 struct afs_exporter *exporter, *outexporter;
3395 struct AFS_UCRED *newcred;
3396 struct unixuser *au;
3398 #if defined(AFS_SGIMP_ENV)
3399 osi_Assert(ISAFS_GLOCK());
3401 AFS_STATCNT(HandleClientContext);
3402 if (ablob->in_size < PIOCTL_HEADER * sizeof(afs_int32)) {
3403 /* Must at least include the PIOCTL_HEADER header words required by the protocol */
3404 return EINVAL; /* Too small to be good */
3406 ain = inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
3407 AFS_COPYIN(ablob->in, ain, PIOCTL_HEADER * sizeof(afs_int32), code);
3409 osi_FreeLargeSpace(inData);
3413 /* Extract information for remote user */
3414 hostaddr = *((afs_uint32 *) ain);
3415 ain += sizeof(hostaddr);
3416 uid = *((afs_uint32 *) ain);
3418 g0 = *((afs_uint32 *) ain);
3420 g1 = *((afs_uint32 *) ain);
3422 *com = *((afs_uint32 *) ain);
3423 ain += sizeof(afs_int32);
3424 exporter_type = *((afs_uint32 *) ain); /* In case we support more than NFS */
3427 * Of course, one must be root for most of these functions, but
3428 * we'll allow (for knfs) you to set things if the pag is 0 and
3429 * you're setting tokens or unlogging.
3432 if (!afs_osi_suser(credp)) {
3433 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
3434 /* Since SGI's suser() returns explicit failure after the call.. */
3437 /* check for acceptable opcodes for normal folks, which are, so far,
3438 * set tokens and unlog.
3440 if (i != 9 && i != 3 && i != 38 && i != 8) {
3441 osi_FreeLargeSpace(inData);
3446 ablob->in_size -= PIOCTL_HEADER * sizeof(afs_int32);
3447 ablob->in += PIOCTL_HEADER * sizeof(afs_int32);
3448 osi_FreeLargeSpace(inData);
3451 * We map uid 0 to nobody to match the mapping that the nfs
3452 * server does and to ensure that the suser() calls in the afs
3453 * code fails for remote client roots.
3455 uid = afs_nobody; /* NFS_NOBODY == -2 */
3458 #if defined(AFS_LINUX26_ENV)
3459 newcred->cr_group_info = groups_alloc(0);
3461 #ifdef AFS_AIX41_ENV
3464 newcred->cr_gid = RMTUSER_REQ;
3465 #ifdef AFS_AIX51_ENV
3466 newcred->cr_groupset.gs_union.un_groups[0] = g0;
3467 newcred->cr_groupset.gs_union.un_groups[1] = g1;
3469 newcred->cr_groups[0] = g0;
3470 newcred->cr_groups[1] = g1;
3473 newcred->cr_ngrps = 2;
3475 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV)
3476 newcred->cr_ngroups = 2;
3478 for (i = 2; i < NGROUPS; i++)
3479 newcred->cr_groups[i] = NOGROUP;
3482 #if !defined(AFS_OSF_ENV)
3483 afs_nfsclient_init(); /* before looking for exporter, ensure one exists */
3485 if (!(exporter = exporter_find(exporter_type))) {
3486 /* Exporter wasn't initialized or an invalid exporter type */
3490 if (exporter->exp_states & EXP_PWSYNC) {
3491 if (uid != credp->cr_uid) {
3493 return ENOEXEC; /* XXX Find a better errno XXX */
3496 newcred->cr_uid = uid; /* Only temporary */
3497 code = EXP_REQHANDLER(exporter, &newcred, hostaddr, &pag, &outexporter);
3498 /* The client's pag is the only unique identifier for it */
3499 newcred->cr_uid = pag;
3501 if (!code && *com == PSETPAG) {
3502 /* Special case for 'setpag' */
3503 afs_uint32 pagvalue = genpag();
3505 au = afs_GetUser(pagvalue, -1, WRITE_LOCK); /* a new unixuser struct */
3507 * Note that we leave the 'outexporter' struct held so it won't
3510 au->exporter = outexporter;
3511 if (ablob->out_size >= 4) {
3512 AFS_COPYOUT((char *)&pagvalue, ablob->out, sizeof(afs_int32),
3515 afs_PutUser(au, WRITE_LOCK);
3518 return PSETPAG; /* Special return for setpag */
3520 EXP_RELE(outexporter);
3524 #endif /* AFS_NEED_CLIENTCONTEXT */
3526 /* get all interface addresses of this client */
3528 DECL_PIOCTL(PGetCPrefs)
3530 struct sprefrequest *spin; /* input */
3531 struct sprefinfo *spout; /* output */
3532 struct spref *srvout; /* one output component */
3536 AFS_STATCNT(PGetCPrefs);
3537 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3538 return EIO; /* Inappropriate ioctl for device */
3540 if (ainSize < sizeof(struct sprefrequest))
3543 spin = (struct sprefrequest *)ain;
3544 spout = (struct sprefinfo *)aout;
3546 maxNumber = spin->num_servers; /* max addrs this time */
3547 srvout = spout->servers;
3549 ObtainReadLock(&afs_xinterface);
3551 /* copy out the client interface information from the
3552 ** kernel data structure "interface" to the output buffer
3554 for (i = spin->offset, j = 0; (i < afs_cb_interface.numberOfInterfaces)
3555 && (j < maxNumber); i++, j++, srvout++)
3556 srvout->host.s_addr = afs_cb_interface.addr_in[i];
3558 spout->num_servers = j;
3559 *aoutSize = sizeof(struct sprefinfo) + (j - 1) * sizeof(struct spref);
3561 if (i >= afs_cb_interface.numberOfInterfaces)
3562 spout->next_offset = 0; /* start from beginning again */
3564 spout->next_offset = spin->offset + j;
3566 ReleaseReadLock(&afs_xinterface);
3570 DECL_PIOCTL(PSetCPrefs)
3572 struct setspref *sin;
3575 AFS_STATCNT(PSetCPrefs);
3576 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3577 return EIO; /* Inappropriate ioctl for device */
3579 sin = (struct setspref *)ain;
3581 if (ainSize < sizeof(struct setspref))
3583 #if 0 /* num_servers is unsigned */
3584 if (sin->num_servers < 0)
3587 if (sin->num_servers > AFS_MAX_INTERFACE_ADDR)
3590 ObtainWriteLock(&afs_xinterface, 412);
3591 afs_cb_interface.numberOfInterfaces = sin->num_servers;
3592 for (i = 0; (unsigned short)i < sin->num_servers; i++)
3593 afs_cb_interface.addr_in[i] = sin->servers[i].host.s_addr;
3595 ReleaseWriteLock(&afs_xinterface);
3599 DECL_PIOCTL(PFlushMount)
3601 register afs_int32 code;
3602 register struct vcache *tvc;
3603 register struct dcache *tdc;
3604 struct VenusFid tfid;
3606 struct sysname_info sysState;
3607 afs_size_t offset, len;
3609 AFS_STATCNT(PFlushMount);
3612 code = afs_VerifyVCache(avc, areq);
3615 if (vType(avc) != VDIR) {
3618 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
3621 Check_AtSys(avc, ain, &sysState, areq);
3622 ObtainReadLock(&tdc->lock);
3624 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
3625 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
3626 ReleaseReadLock(&tdc->lock);
3627 afs_PutDCache(tdc); /* we're done with the data */
3628 bufp = sysState.name;
3632 tfid.Cell = avc->fid.Cell;
3633 tfid.Fid.Volume = avc->fid.Fid.Volume;
3634 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
3635 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
3637 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3643 if (tvc->mvstat != 1) {
3648 #ifdef AFS_BOZONLOCK_ENV
3649 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
3651 ObtainWriteLock(&tvc->lock, 649);
3652 ObtainWriteLock(&afs_xcbhash, 650);
3653 afs_DequeueCallback(tvc);
3654 tvc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
3655 ReleaseWriteLock(&afs_xcbhash);
3656 /* now find the disk cache entries */
3657 afs_TryToSmush(tvc, *acred, 1);
3658 osi_dnlc_purgedp(tvc);
3659 if (tvc->linkData && !(tvc->states & CCore)) {
3660 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
3661 tvc->linkData = NULL;
3663 ReleaseWriteLock(&tvc->lock);
3664 #ifdef AFS_BOZONLOCK_ENV
3665 afs_BozonUnlock(&tvc->pvnLock, tvc);
3669 if (sysState.allocked)
3670 osi_FreeLargeSpace(bufp);
3674 DECL_PIOCTL(PRxStatProc)
3679 if (!afs_osi_suser(*acred)) {
3683 if (ainSize != sizeof(afs_int32)) {
3687 memcpy((char *)&flags, ain, sizeof(afs_int32));
3688 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3692 if (flags & AFSCALL_RXSTATS_ENABLE) {
3693 rx_enableProcessRPCStats();
3695 if (flags & AFSCALL_RXSTATS_DISABLE) {
3696 rx_disableProcessRPCStats();
3698 if (flags & AFSCALL_RXSTATS_CLEAR) {
3699 rx_clearProcessRPCStats(AFS_RX_STATS_CLEAR_ALL);
3707 DECL_PIOCTL(PRxStatPeer)
3712 if (!afs_osi_suser(*acred)) {
3716 if (ainSize != sizeof(afs_int32)) {
3720 memcpy((char *)&flags, ain, sizeof(afs_int32));
3721 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3725 if (flags & AFSCALL_RXSTATS_ENABLE) {
3726 rx_enablePeerRPCStats();
3728 if (flags & AFSCALL_RXSTATS_DISABLE) {
3729 rx_disablePeerRPCStats();
3731 if (flags & AFSCALL_RXSTATS_CLEAR) {
3732 rx_clearPeerRPCStats(AFS_RX_STATS_CLEAR_ALL);
3739 DECL_PIOCTL(PPrefetchFromTape)
3741 register afs_int32 code, code1;
3744 struct rx_call *tcall;
3745 struct AFSVolSync tsync;
3746 struct AFSFetchStatus OutStatus;
3747 struct AFSCallBack CallBack;
3748 struct VenusFid tfid;
3752 AFS_STATCNT(PSetAcl);
3756 if (ain && (ainSize == 3 * sizeof(afs_int32)))
3757 Fid = (struct AFSFid *)ain;
3759 Fid = &avc->fid.Fid;
3760 tfid.Cell = avc->fid.Cell;
3761 tfid.Fid.Volume = Fid->Volume;
3762 tfid.Fid.Vnode = Fid->Vnode;
3763 tfid.Fid.Unique = Fid->Unique;
3765 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3767 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3768 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &avc->fid);
3771 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3772 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &tvc->fid);
3775 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3779 tcall = rx_NewCall(tc->id);
3781 StartRXAFS_FetchData(tcall, (struct AFSFid *)&tvc->fid.Fid, 0,
3784 bytes = rx_Read(tcall, (char *)aout, sizeof(afs_int32));
3786 EndRXAFS_FetchData(tcall, &OutStatus, &CallBack, &tsync);
3788 code1 = rx_EndCall(tcall, code);
3792 } while (afs_Analyze
3793 (tc, code, &tvc->fid, areq, AFS_STATS_FS_RPCIDX_RESIDENCYRPCS,
3794 SHARED_LOCK, NULL));
3795 /* This call is done only to have the callback things handled correctly */
3796 afs_FetchStatus(tvc, &tfid, areq, &OutStatus);
3800 *aoutSize = sizeof(afs_int32);
3805 DECL_PIOCTL(PResidencyCmd)
3807 register afs_int32 code;
3810 struct ResidencyCmdInputs *Inputs;
3811 struct ResidencyCmdOutputs *Outputs;
3812 struct VenusFid tfid;
3815 Inputs = (struct ResidencyCmdInputs *)ain;
3816 Outputs = (struct ResidencyCmdOutputs *)aout;
3819 if (!ain || ainSize != sizeof(struct ResidencyCmdInputs))
3824 Fid = &avc->fid.Fid;
3826 tfid.Cell = avc->fid.Cell;
3827 tfid.Fid.Volume = Fid->Volume;
3828 tfid.Fid.Vnode = Fid->Vnode;
3829 tfid.Fid.Unique = Fid->Unique;
3831 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3832 afs_Trace3(afs_iclSetp, CM_TRACE_RESIDCMD, ICL_TYPE_POINTER, tvc,
3833 ICL_TYPE_INT32, Inputs->command, ICL_TYPE_FID, &tfid);
3837 if (Inputs->command) {
3839 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3843 RXAFS_ResidencyCmd(tc->id, Fid, Inputs,
3844 (struct ResidencyCmdOutputs *)aout);
3848 } while (afs_Analyze
3849 (tc, code, &tvc->fid, areq,
3850 AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK, NULL));
3851 /* This call is done to have the callback things handled correctly */
3852 afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3853 } else { /* just a status request, return also link data */
3855 Outputs->code = afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3856 Outputs->chars[0] = 0;
3857 if (vType(tvc) == VLNK) {
3858 ObtainWriteLock(&tvc->lock, 555);
3859 if (afs_HandleLink(tvc, areq) == 0)
3860 strncpy((char *)&Outputs->chars, tvc->linkData, MAXCMDCHARS);
3861 ReleaseWriteLock(&tvc->lock);
3868 *aoutSize = sizeof(struct ResidencyCmdOutputs);
3873 DECL_PIOCTL(PCallBackAddr)
3876 afs_uint32 addr, code;
3882 struct unixuser *tu;
3883 struct srvAddr **addrs;
3885 /*AFS_STATCNT(PCallBackAddr); */
3886 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
3887 return EIO; /* Inappropriate ioctl for device */
3889 if (!afs_osi_suser(acred))
3892 if (ainSize < sizeof(afs_int32))
3895 memcpy(&addr, ain, sizeof(afs_int32));
3897 ObtainReadLock(&afs_xinterface);
3898 for (i = 0; (unsigned short)i < afs_cb_interface.numberOfInterfaces; i++) {
3899 if (afs_cb_interface.addr_in[i] == addr)
3903 ReleaseWriteLock(&afs_xinterface);
3905 if (afs_cb_interface.addr_in[i] != addr)
3908 ObtainReadLock(&afs_xserver); /* Necessary? */
3909 ObtainReadLock(&afs_xsrvAddr);
3912 for (i = 0; i < NSERVERS; i++) {
3913 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3918 addrs = afs_osi_Alloc(srvAddrCount * sizeof(*addrs));
3920 for (i = 0; i < NSERVERS; i++) {
3921 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3922 if (j >= srvAddrCount)
3928 ReleaseReadLock(&afs_xsrvAddr);
3929 ReleaseReadLock(&afs_xserver);
3931 for (i = 0; i < j; i++) {
3937 /* vlserver has no callback conn */
3938 if (sa->sa_portal == AFS_VLPORT) {
3942 if (!ts->cell) /* not really an active server, anyway, it must */
3943 continue; /* have just been added by setsprefs */
3945 /* get a connection, even if host is down; bumps conn ref count */
3946 tu = afs_GetUser(areq->uid, ts->cell->cellNum, SHARED_LOCK);
3947 tc = afs_ConnBySA(sa, ts->cell->fsport, ts->cell->cellNum, tu,
3948 1 /*force */ , 1 /*create */ , SHARED_LOCK);
3949 afs_PutUser(tu, SHARED_LOCK);
3953 if ((sa->sa_flags & SRVADDR_ISDOWN) || afs_HaveCallBacksFrom(ts)) {
3954 if (sa->sa_flags & SRVADDR_ISDOWN) {
3955 rx_SetConnDeadTime(tc->id, 3);
3957 #ifdef RX_ENABLE_LOCKS
3959 #endif /* RX_ENABLE_LOCKS */
3960 code = RXAFS_CallBackRxConnAddr(tc->id, &addr);
3961 #ifdef RX_ENABLE_LOCKS
3963 #endif /* RX_ENABLE_LOCKS */
3965 afs_PutConn(tc, SHARED_LOCK); /* done with it now */
3966 } /* Outer loop over addrs */
3967 #endif /* UKERNEL */