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 AFS_STATCNT(PGetCacheSize);
2180 memset((char *)results, 0, sizeof(results));
2181 results[0] = afs_cacheBlocks;
2182 results[1] = afs_blocksUsed;
2183 memcpy(aout, (char *)results, sizeof(results));
2184 *aoutSize = sizeof(results);
2188 DECL_PIOCTL(PRemoveCallBack)
2190 register struct conn *tc;
2191 register afs_int32 code = 0;
2192 struct AFSCallBack CallBacks_Array[1];
2193 struct AFSCBFids theFids;
2194 struct AFSCBs theCBs;
2197 AFS_STATCNT(PRemoveCallBack);
2200 if (avc->states & CRO)
2201 return 0; /* read-only-ness can't change */
2202 ObtainWriteLock(&avc->lock, 229);
2203 theFids.AFSCBFids_len = 1;
2204 theCBs.AFSCBs_len = 1;
2205 theFids.AFSCBFids_val = (struct AFSFid *)&avc->fid.Fid;
2206 theCBs.AFSCBs_val = CallBacks_Array;
2207 CallBacks_Array[0].CallBackType = CB_DROPPED;
2208 if (avc->callback) {
2210 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2212 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
2214 code = RXAFS_GiveUpCallBacks(tc->id, &theFids, &theCBs);
2218 /* don't set code on failure since we wouldn't use it */
2219 } while (afs_Analyze
2220 (tc, code, &avc->fid, areq,
2221 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK, NULL));
2223 ObtainWriteLock(&afs_xcbhash, 457);
2224 afs_DequeueCallback(avc);
2226 avc->states &= ~(CStatd | CUnique);
2227 ReleaseWriteLock(&afs_xcbhash);
2228 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
2229 osi_dnlc_purgedp(avc);
2231 ReleaseWriteLock(&avc->lock);
2235 DECL_PIOCTL(PNewCell)
2237 /* create a new cell */
2238 afs_int32 cellHosts[MAXCELLHOSTS], *lp, magic = 0;
2239 char *newcell = 0, *linkedcell = 0, *tp = ain;
2240 register afs_int32 code, linkedstate = 0, ls;
2241 u_short fsport = 0, vlport = 0;
2244 AFS_STATCNT(PNewCell);
2245 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2246 return EIO; /* Inappropriate ioctl for device */
2248 if (!afs_osi_suser(*acred))
2251 memcpy((char *)&magic, tp, sizeof(afs_int32));
2252 tp += sizeof(afs_int32);
2253 if (magic != 0x12345678)
2256 /* A 3.4 fs newcell command will pass an array of MAXCELLHOSTS
2257 * server addresses while the 3.5 fs newcell command passes
2258 * MAXHOSTS. To figure out which is which, check if the cellname
2261 newcell = tp + (MAXCELLHOSTS + 3) * sizeof(afs_int32);
2262 scount = ((newcell[0] != '\0') ? MAXCELLHOSTS : MAXHOSTS);
2264 /* MAXCELLHOSTS (=8) is less than MAXHOSTS (=13) */
2265 memcpy((char *)cellHosts, tp, MAXCELLHOSTS * sizeof(afs_int32));
2266 tp += (scount * sizeof(afs_int32));
2268 lp = (afs_int32 *) tp;
2272 fsport = 0; /* Privileged ports not allowed */
2274 vlport = 0; /* Privileged ports not allowed */
2275 tp += (3 * sizeof(afs_int32));
2277 if ((ls = *lp) & 1) {
2278 linkedcell = tp + strlen(newcell) + 1;
2279 linkedstate |= CLinkedCell;
2282 linkedstate |= CNoSUID; /* setuid is disabled by default for fs newcell */
2284 afs_NewCell(newcell, cellHosts, linkedstate, linkedcell, fsport,
2289 DECL_PIOCTL(PNewAlias)
2291 /* create a new cell alias */
2293 register afs_int32 code;
2294 char *realName, *aliasName;
2296 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2297 return EIO; /* Inappropriate ioctl for device */
2299 if (!afs_osi_suser(*acred))
2303 tp += strlen(aliasName) + 1;
2306 code = afs_NewCellAlias(aliasName, realName);
2311 DECL_PIOCTL(PListCells)
2313 afs_int32 whichCell;
2314 register struct cell *tcell = 0;
2315 register afs_int32 i;
2316 register char *cp, *tp = ain;
2318 AFS_STATCNT(PListCells);
2319 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2320 return EIO; /* Inappropriate ioctl for device */
2322 memcpy((char *)&whichCell, tp, sizeof(afs_int32));
2323 tp += sizeof(afs_int32);
2324 tcell = afs_GetCellByIndex(whichCell, READ_LOCK);
2327 memset(cp, 0, MAXCELLHOSTS * sizeof(afs_int32));
2328 for (i = 0; i < MAXCELLHOSTS; i++) {
2329 if (tcell->cellHosts[i] == 0)
2331 memcpy(cp, (char *)&tcell->cellHosts[i]->addr->sa_ip,
2333 cp += sizeof(afs_int32);
2335 cp = aout + MAXCELLHOSTS * sizeof(afs_int32);
2336 strcpy(cp, tcell->cellName);
2337 cp += strlen(tcell->cellName) + 1;
2338 *aoutSize = cp - aout;
2339 afs_PutCell(tcell, READ_LOCK);
2347 DECL_PIOCTL(PListAliases)
2349 afs_int32 whichAlias;
2350 register struct cell_alias *tcalias = 0;
2351 register char *cp, *tp = ain;
2353 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2354 return EIO; /* Inappropriate ioctl for device */
2355 if (ainSize < sizeof(afs_int32))
2358 memcpy((char *)&whichAlias, tp, sizeof(afs_int32));
2359 tp += sizeof(afs_int32);
2361 tcalias = afs_GetCellAlias(whichAlias);
2364 strcpy(cp, tcalias->alias);
2365 cp += strlen(tcalias->alias) + 1;
2366 strcpy(cp, tcalias->cell);
2367 cp += strlen(tcalias->cell) + 1;
2368 *aoutSize = cp - aout;
2369 afs_PutCellAlias(tcalias);
2377 DECL_PIOCTL(PRemoveMount)
2379 register afs_int32 code;
2381 struct sysname_info sysState;
2382 afs_size_t offset, len;
2383 register struct conn *tc;
2384 register struct dcache *tdc;
2385 register struct vcache *tvc;
2386 struct AFSFetchStatus OutDirStatus;
2387 struct VenusFid tfid;
2388 struct AFSVolSync tsync;
2392 /* "ain" is the name of the file in this dir to remove */
2394 AFS_STATCNT(PRemoveMount);
2397 code = afs_VerifyVCache(avc, areq);
2400 if (vType(avc) != VDIR)
2403 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1); /* test for error below */
2406 Check_AtSys(avc, ain, &sysState, areq);
2407 ObtainReadLock(&tdc->lock);
2409 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
2410 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
2411 ReleaseReadLock(&tdc->lock);
2412 bufp = sysState.name;
2417 tfid.Cell = avc->fid.Cell;
2418 tfid.Fid.Volume = avc->fid.Fid.Volume;
2419 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
2420 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
2422 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
2429 if (tvc->mvstat != 1) {
2435 ObtainWriteLock(&tvc->lock, 230);
2436 code = afs_HandleLink(tvc, areq);
2438 if (tvc->linkData) {
2439 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
2444 ReleaseWriteLock(&tvc->lock);
2445 osi_dnlc_purgedp(tvc);
2451 ObtainWriteLock(&avc->lock, 231);
2452 osi_dnlc_remove(avc, bufp, tvc);
2454 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2456 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE);
2459 RXAFS_RemoveFile(tc->id, (struct AFSFid *)&avc->fid.Fid, bufp,
2460 &OutDirStatus, &tsync);
2465 } while (afs_Analyze
2466 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_REMOVEFILE,
2467 SHARED_LOCK, NULL));
2472 ReleaseWriteLock(&avc->lock);
2476 /* we have the thing in the cache */
2477 ObtainWriteLock(&tdc->lock, 661);
2478 if (afs_LocalHero(avc, tdc, &OutDirStatus, 1)) {
2479 /* we can do it locally */
2480 code = afs_dir_Delete(tdc, bufp);
2482 ZapDCE(tdc); /* surprise error -- invalid value */
2486 ReleaseWriteLock(&tdc->lock);
2487 afs_PutDCache(tdc); /* drop ref count */
2489 avc->states &= ~CUnique; /* For the dfs xlator */
2490 ReleaseWriteLock(&avc->lock);
2493 if (sysState.allocked)
2494 osi_FreeLargeSpace(bufp);
2498 DECL_PIOCTL(PVenusLogging)
2500 return EINVAL; /* OBSOLETE */
2503 DECL_PIOCTL(PGetCellStatus)
2505 register struct cell *tcell;
2508 AFS_STATCNT(PGetCellStatus);
2509 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2510 return EIO; /* Inappropriate ioctl for device */
2512 tcell = afs_GetCellByName(ain, READ_LOCK);
2515 temp = tcell->states;
2516 afs_PutCell(tcell, READ_LOCK);
2517 memcpy(aout, (char *)&temp, sizeof(afs_int32));
2518 *aoutSize = sizeof(afs_int32);
2522 DECL_PIOCTL(PSetCellStatus)
2524 register struct cell *tcell;
2527 if (!afs_osi_suser(*acred))
2529 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2530 return EIO; /* Inappropriate ioctl for device */
2532 tcell = afs_GetCellByName(ain + 2 * sizeof(afs_int32), WRITE_LOCK);
2535 memcpy((char *)&temp, ain, sizeof(afs_int32));
2537 tcell->states |= CNoSUID;
2539 tcell->states &= ~CNoSUID;
2540 afs_PutCell(tcell, WRITE_LOCK);
2544 DECL_PIOCTL(PFlushVolumeData)
2546 register afs_int32 i;
2547 register struct dcache *tdc;
2548 register struct vcache *tvc;
2549 register struct volume *tv;
2550 afs_int32 cell, volume;
2551 struct afs_q *tq, *uq;
2552 #ifdef AFS_DARWIN80_ENV
2556 AFS_STATCNT(PFlushVolumeData);
2559 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2560 return EIO; /* Inappropriate ioctl for device */
2562 volume = avc->fid.Fid.Volume; /* who to zap */
2563 cell = avc->fid.Cell;
2566 * Clear stat'd flag from all vnodes from this volume; this will invalidate all
2567 * the vcaches associated with the volume.
2570 ObtainReadLock(&afs_xvcache);
2571 i = VCHashV(&avc->fid);
2572 for (tq = afs_vhashTV[i].prev; tq != &afs_vhashTV[i]; tq = uq) {
2575 if (tvc->fid.Fid.Volume == volume && tvc->fid.Cell == cell) {
2576 if (tvc->states & CVInit) {
2577 ReleaseReadLock(&afs_xvcache);
2578 afs_osi_Sleep(&tvc->states);
2581 #ifdef AFS_DARWIN80_ENV
2582 if (tvc->states & CDeadVnode) {
2583 ReleaseReadLock(&afs_xvcache);
2584 afs_osi_Sleep(&tvc->states);
2588 #if defined(AFS_SGI_ENV) || defined(AFS_OSF_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
2589 VN_HOLD(AFSTOV(tvc));
2591 #ifdef AFS_DARWIN80_ENV
2595 if (vnode_ref(vp)) {
2602 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2605 VREFCOUNT_INC(tvc); /* AIX, apparently */
2609 ReleaseReadLock(&afs_xvcache);
2610 #ifdef AFS_BOZONLOCK_ENV
2611 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
2613 ObtainWriteLock(&tvc->lock, 232);
2615 ObtainWriteLock(&afs_xcbhash, 458);
2616 afs_DequeueCallback(tvc);
2617 tvc->states &= ~(CStatd | CDirty);
2618 ReleaseWriteLock(&afs_xcbhash);
2619 if (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
2620 osi_dnlc_purgedp(tvc);
2621 afs_TryToSmush(tvc, *acred, 1);
2622 ReleaseWriteLock(&tvc->lock);
2623 #ifdef AFS_BOZONLOCK_ENV
2624 afs_BozonUnlock(&tvc->pvnLock, tvc);
2626 #ifdef AFS_DARWIN80_ENV
2627 vnode_put(AFSTOV(tvc));
2629 ObtainReadLock(&afs_xvcache);
2631 /* our tvc ptr is still good until now */
2635 ReleaseReadLock(&afs_xvcache);
2638 MObtainWriteLock(&afs_xdcache, 328); /* needed if you're going to flush any stuff */
2639 for (i = 0; i < afs_cacheFiles; i++) {
2640 if (!(afs_indexFlags[i] & IFEverUsed))
2641 continue; /* never had any data */
2642 tdc = afs_GetDSlot(i, NULL);
2643 if (tdc->refCount <= 1) { /* too high, in use by running sys call */
2644 ReleaseReadLock(&tdc->tlock);
2645 if (tdc->f.fid.Fid.Volume == volume && tdc->f.fid.Cell == cell) {
2646 if (!(afs_indexFlags[i] & IFDataMod)) {
2647 /* if the file is modified, but has a ref cnt of only 1, then
2648 * someone probably has the file open and is writing into it.
2649 * Better to skip flushing such a file, it will be brought back
2650 * immediately on the next write anyway.
2652 * If we *must* flush, then this code has to be rearranged to call
2653 * afs_storeAllSegments() first */
2654 afs_FlushDCache(tdc);
2658 ReleaseReadLock(&tdc->tlock);
2660 afs_PutDCache(tdc); /* bumped by getdslot */
2662 MReleaseWriteLock(&afs_xdcache);
2664 ObtainReadLock(&afs_xvolume);
2665 for (i = 0; i < NVOLS; i++) {
2666 for (tv = afs_volumes[i]; tv; tv = tv->next) {
2667 if (tv->volume == volume) {
2668 afs_ResetVolumeInfo(tv);
2673 ReleaseReadLock(&afs_xvolume);
2675 /* probably, a user is doing this, probably, because things are screwed up.
2676 * maybe it's the dnlc's fault? */
2683 DECL_PIOCTL(PGetVnodeXStatus)
2685 register afs_int32 code;
2686 struct vcxstat stat;
2689 /* AFS_STATCNT(PGetVnodeXStatus); */
2692 code = afs_VerifyVCache(avc, areq);
2695 if (vType(avc) == VDIR)
2696 mode = PRSFS_LOOKUP;
2699 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
2702 memset(&stat, 0, sizeof(struct vcxstat));
2703 stat.fid = avc->fid;
2704 hset32(stat.DataVersion, hgetlo(avc->m.DataVersion));
2705 stat.lock = avc->lock;
2706 stat.parentVnode = avc->parentVnode;
2707 stat.parentUnique = avc->parentUnique;
2708 hset(stat.flushDV, avc->flushDV);
2709 hset(stat.mapDV, avc->mapDV);
2710 stat.truncPos = avc->truncPos;
2711 { /* just grab the first two - won't break anything... */
2712 struct axscache *ac;
2714 for (i = 0, ac = avc->Access; ac && i < CPSIZE; i++, ac = ac->next) {
2715 stat.randomUid[i] = ac->uid;
2716 stat.randomAccess[i] = ac->axess;
2719 stat.callback = afs_data_pointer_to_int32(avc->callback);
2720 stat.cbExpires = avc->cbExpires;
2721 stat.anyAccess = avc->anyAccess;
2722 stat.opens = avc->opens;
2723 stat.execsOrWriters = avc->execsOrWriters;
2724 stat.flockCount = avc->flockCount;
2725 stat.mvstat = avc->mvstat;
2726 stat.states = avc->states;
2727 memcpy(aout, (char *)&stat, sizeof(struct vcxstat));
2728 *aoutSize = sizeof(struct vcxstat);
2733 DECL_PIOCTL(PGetVnodeXStatus2)
2735 register afs_int32 code;
2736 struct vcxstat2 stat;
2741 code = afs_VerifyVCache(avc, areq);
2744 if (vType(avc) == VDIR)
2745 mode = PRSFS_LOOKUP;
2748 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
2751 memset(&stat, 0, sizeof(struct vcxstat2));
2753 stat.cbExpires = avc->cbExpires;
2754 stat.anyAccess = avc->anyAccess;
2755 stat.mvstat = avc->mvstat;
2756 stat.callerAccess = afs_GetAccessBits(avc, ~0, areq);
2758 memcpy(aout, (char *)&stat, sizeof(struct vcxstat2));
2759 *aoutSize = sizeof(struct vcxstat2);
2763 /* We require root for local sysname changes, but not for remote */
2764 /* (since we don't really believe remote uids anyway) */
2765 /* outname[] shouldn't really be needed- this is left as an excercise */
2766 /* for the reader. */
2767 DECL_PIOCTL(PSetSysName)
2769 char *cp, *cp2 = NULL, inname[MAXSYSNAME], outname[MAXSYSNAME];
2770 int setsysname, foundname = 0;
2771 register struct afs_exporter *exporter;
2772 register struct unixuser *au;
2773 register afs_int32 pag, error;
2774 int t, count, num = 0;
2775 char **sysnamelist[MAXNUMSYSNAMES];
2777 AFS_STATCNT(PSetSysName);
2778 if (!afs_globalVFS) {
2779 /* Afsd is NOT running; disable it */
2780 #if defined(KERNEL_HAVE_UERROR)
2781 return (setuerror(EINVAL), EINVAL);
2786 memset(inname, 0, MAXSYSNAME);
2787 memcpy((char *)&setsysname, ain, sizeof(afs_int32));
2788 ain += sizeof(afs_int32);
2792 if (setsysname < 0 || setsysname > MAXNUMSYSNAMES)
2795 for (cp = ain, count = 0; count < setsysname; count++) {
2796 /* won't go past end of ain since maxsysname*num < ain length */
2798 if (t >= MAXSYSNAME || t <= 0)
2800 /* check for names that can shoot us in the foot */
2801 if (*cp == '.' && (cp[1] == 0 || (cp[1] == '.' && cp[2] == 0)))
2807 /* inname gets first entry in case we're being a translator */
2809 memcpy(inname, ain, t + 1); /* include terminating null */
2813 if ((*acred)->cr_gid == RMTUSER_REQ) { /* Handles all exporters */
2814 pag = PagInCred(*acred);
2816 return EINVAL; /* Better than panicing */
2818 if (!(au = afs_FindUser(pag, -1, READ_LOCK))) {
2819 return EINVAL; /* Better than panicing */
2821 if (!(exporter = au->exporter)) {
2822 afs_PutUser(au, READ_LOCK);
2823 return EINVAL; /* Better than panicing */
2825 error = EXP_SYSNAME(exporter, (setsysname ? cp2 : NULL), sysnamelist,
2828 if (error == ENODEV)
2829 foundname = 0; /* sysname not set yet! */
2831 afs_PutUser(au, READ_LOCK);
2836 strcpy(outname, (*sysnamelist)[0]);
2838 afs_PutUser(au, READ_LOCK);
2840 /* Not xlating, so local case */
2842 osi_Panic("PSetSysName: !afs_sysname\n");
2843 if (!setsysname) { /* user just wants the info */
2844 strcpy(outname, afs_sysname);
2845 foundname = afs_sysnamecount;
2846 *sysnamelist = afs_sysnamelist;
2847 } else { /* Local guy; only root can change sysname */
2848 if (!afs_osi_suser(*acred))
2851 /* clear @sys entries from the dnlc, once afs_lookup can
2852 * do lookups of @sys entries and thinks it can trust them */
2853 /* privs ok, store the entry, ... */
2854 strcpy(afs_sysname, inname);
2855 if (setsysname > 1) { /* ... or list */
2857 for (count = 1; count < setsysname; ++count) {
2858 if (!afs_sysnamelist[count])
2860 ("PSetSysName: no afs_sysnamelist entry to write\n");
2862 memcpy(afs_sysnamelist[count], cp, t + 1); /* include null */
2866 afs_sysnamecount = setsysname;
2870 cp = aout; /* not changing so report back the count and ... */
2871 memcpy(cp, (char *)&foundname, sizeof(afs_int32));
2872 cp += sizeof(afs_int32);
2874 strcpy(cp, outname); /* ... the entry, ... */
2875 cp += strlen(outname) + 1;
2876 for (count = 1; count < foundname; ++count) { /* ... or list. */
2877 if (!(*sysnamelist)[count])
2879 ("PSetSysName: no afs_sysnamelist entry to read\n");
2880 t = strlen((*sysnamelist)[count]);
2881 if (t >= MAXSYSNAME)
2882 osi_Panic("PSetSysName: sysname entry garbled\n");
2883 strcpy(cp, (*sysnamelist)[count]);
2887 *aoutSize = cp - aout;
2892 /* sequential search through the list of touched cells is not a good
2893 * long-term solution here. For small n, though, it should be just
2894 * fine. Should consider special-casing the local cell for large n.
2895 * Likewise for PSetSPrefs.
2897 * s - number of ids in array l[] -- NOT index of last id
2898 * l - array of cell ids which have volumes that need to be sorted
2899 * vlonly - sort vl servers or file servers?
2902 ReSortCells_cb(struct cell *cell, void *arg)
2904 afs_int32 *p = (afs_int32 *) arg;
2905 afs_int32 *l = p + 1;
2908 for (i = 0; i < s; i++) {
2909 if (l[i] == cell->cellNum) {
2910 ObtainWriteLock(&cell->lock, 690);
2911 afs_SortServers(cell->cellHosts, MAXCELLHOSTS);
2912 ReleaseWriteLock(&cell->lock);
2920 ReSortCells(int s, afs_int32 * l, int vlonly)
2928 p = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * (s + 1));
2930 memcpy(p + 1, l, s * sizeof(afs_int32));
2931 afs_TraverseCells(&ReSortCells_cb, p);
2932 afs_osi_Free(p, sizeof(afs_int32) * (s + 1));
2936 ObtainReadLock(&afs_xvolume);
2937 for (i = 0; i < NVOLS; i++) {
2938 for (j = afs_volumes[i]; j; j = j->next) {
2939 for (k = 0; k < s; k++)
2940 if (j->cell == l[k]) {
2941 ObtainWriteLock(&j->lock, 233);
2942 afs_SortServers(j->serverHost, MAXHOSTS);
2943 ReleaseWriteLock(&j->lock);
2948 ReleaseReadLock(&afs_xvolume);
2952 static int debugsetsp = 0;
2954 afs_setsprefs(sp, num, vlonly)
2957 unsigned int vlonly;
2960 int i, j, k, matches, touchedSize;
2961 struct server *srvr = NULL;
2962 afs_int32 touched[34];
2966 for (k = 0; k < num; sp++, k++) {
2968 printf("sp host=%x, rank=%d\n", sp->host.s_addr, sp->rank);
2971 ObtainReadLock(&afs_xserver);
2973 i = SHash(sp->host.s_addr);
2974 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2975 if (sa->sa_ip == sp->host.s_addr) {
2977 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
2978 || (sa->sa_portal == AFS_FSPORT);
2979 if ((!vlonly && isfs) || (vlonly && !isfs)) {
2986 if (sa && matches) { /* found one! */
2988 printf("sa ip=%x, ip_rank=%d\n", sa->sa_ip, sa->sa_iprank);
2990 sa->sa_iprank = sp->rank + afs_randomMod15();
2991 afs_SortOneServer(sa->server);
2994 /* if we don't know yet what cell it's in, this is moot */
2995 for (j = touchedSize - 1;
2996 j >= 0 && touched[j] != srvr->cell->cellNum; j--)
2997 /* is it in our list of touched cells ? */ ;
2998 if (j < 0) { /* no, it's not */
2999 touched[touchedSize++] = srvr->cell->cellNum;
3000 if (touchedSize >= 32) { /* watch for ovrflow */
3001 ReleaseReadLock(&afs_xserver);
3002 ReSortCells(touchedSize, touched, vlonly);
3004 ObtainReadLock(&afs_xserver);
3010 ReleaseReadLock(&afs_xserver);
3011 /* if we didn't find one, start to create one. */
3012 /* Note that it doesn't have a cell yet... */
3014 afs_uint32 temp = sp->host.s_addr;
3016 afs_GetServer(&temp, 1, 0, (vlonly ? AFS_VLPORT : AFS_FSPORT),
3017 WRITE_LOCK, (afsUUID *) 0, 0);
3018 srvr->addr->sa_iprank = sp->rank + afs_randomMod15();
3019 afs_PutServer(srvr, WRITE_LOCK);
3021 } /* for all cited preferences */
3023 ReSortCells(touchedSize, touched, vlonly);
3027 /* Note that this may only be performed by the local root user.
3029 DECL_PIOCTL(PSetSPrefs)
3031 struct setspref *ssp;
3032 AFS_STATCNT(PSetSPrefs);
3034 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3035 return EIO; /* Inappropriate ioctl for device */
3037 if (!afs_osi_suser(*acred))
3040 if (ainSize < sizeof(struct setspref))
3043 ssp = (struct setspref *)ain;
3044 if (ainSize < sizeof(struct spref) * ssp->num_servers)
3047 afs_setsprefs(&(ssp->servers[0]), ssp->num_servers,
3048 (ssp->flags & DBservers));
3052 DECL_PIOCTL(PSetSPrefs33)
3055 AFS_STATCNT(PSetSPrefs);
3056 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3057 return EIO; /* Inappropriate ioctl for device */
3060 if (!afs_osi_suser(*acred))
3063 sp = (struct spref *)ain;
3064 afs_setsprefs(sp, ainSize / (sizeof(struct spref)), 0 /*!vlonly */ );
3068 /* some notes on the following code...
3069 * in the hash table of server structs, all servers with the same IP address
3070 * will be on the same overflow chain.
3071 * This could be sped slightly in some circumstances by having it cache the
3072 * immediately previous slot in the hash table and some supporting information
3073 * Only reports file servers now.
3075 DECL_PIOCTL(PGetSPrefs)
3077 struct sprefrequest *spin; /* input */
3078 struct sprefinfo *spout; /* output */
3079 struct spref *srvout; /* one output component */
3080 int i, j; /* counters for hash table traversal */
3081 struct server *srvr; /* one of CM's server structs */
3083 int vlonly; /* just return vlservers ? */
3086 AFS_STATCNT(PGetSPrefs);
3087 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3088 return EIO; /* Inappropriate ioctl for device */
3091 if (ainSize < sizeof(struct sprefrequest_33)) {
3094 spin = ((struct sprefrequest *)ain);
3097 if (ainSize > sizeof(struct sprefrequest_33)) {
3098 vlonly = (spin->flags & DBservers);
3102 /* struct sprefinfo includes 1 server struct... that size gets added
3103 * in during the loop that follows.
3105 *aoutSize = sizeof(struct sprefinfo) - sizeof(struct spref);
3106 spout = (struct sprefinfo *)aout;
3107 spout->next_offset = spin->offset;
3108 spout->num_servers = 0;
3109 srvout = spout->servers;
3111 ObtainReadLock(&afs_xserver);
3112 for (i = 0, j = 0; j < NSERVERS; j++) { /* sift through hash table */
3113 for (sa = afs_srvAddrs[j]; sa; sa = sa->next_bkt, i++) {
3114 if (spin->offset > (unsigned short)i) {
3115 continue; /* catch up to where we left off */
3117 spout->next_offset++;
3120 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
3121 || (sa->sa_portal == AFS_FSPORT);
3123 if ((vlonly && isfs) || (!vlonly && !isfs)) {
3124 /* only report ranks for vl servers */
3128 srvout->host.s_addr = sa->sa_ip;
3129 srvout->rank = sa->sa_iprank;
3130 *aoutSize += sizeof(struct spref);
3131 spout->num_servers++;
3134 if (*aoutSize > (PIGGYSIZE - sizeof(struct spref))) {
3135 ReleaseReadLock(&afs_xserver); /* no more room! */
3140 ReleaseReadLock(&afs_xserver);
3142 spout->next_offset = 0; /* start over from the beginning next time */
3146 /* Enable/Disable the specified exporter. Must be root to disable an exporter */
3147 int afs_NFSRootOnly = 1;
3148 DECL_PIOCTL(PExportAfs)
3150 afs_int32 export, newint =
3151 0, type, changestate, handleValue, convmode, pwsync, smounts;
3152 register struct afs_exporter *exporter;
3154 AFS_STATCNT(PExportAfs);
3155 memcpy((char *)&handleValue, ain, sizeof(afs_int32));
3156 type = handleValue >> 24;
3161 exporter = exporter_find(type);
3163 export = handleValue & 3;
3164 changestate = handleValue & 0xff;
3165 smounts = (handleValue >> 2) & 3;
3166 pwsync = (handleValue >> 4) & 3;
3167 convmode = (handleValue >> 6) & 3;
3169 changestate = (handleValue >> 16) & 0x1;
3170 convmode = (handleValue >> 16) & 0x2;
3171 pwsync = (handleValue >> 16) & 0x4;
3172 smounts = (handleValue >> 16) & 0x8;
3173 export = handleValue & 0xff;
3176 /* Failed finding desired exporter; */
3180 handleValue = exporter->exp_states;
3181 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3182 *aoutSize = sizeof(afs_int32);
3184 if (!afs_osi_suser(*acred))
3185 return EACCES; /* Only superuser can do this */
3189 exporter->exp_states |= EXP_EXPORTED;
3191 exporter->exp_states &= ~EXP_EXPORTED;
3195 exporter->exp_states |= EXP_UNIXMODE;
3197 exporter->exp_states &= ~EXP_UNIXMODE;
3201 exporter->exp_states |= EXP_PWSYNC;
3203 exporter->exp_states &= ~EXP_PWSYNC;
3207 afs_NFSRootOnly = 0;
3208 exporter->exp_states |= EXP_SUBMOUNTS;
3210 afs_NFSRootOnly = 1;
3211 exporter->exp_states &= ~EXP_SUBMOUNTS;
3214 handleValue = exporter->exp_states;
3215 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3216 *aoutSize = sizeof(afs_int32);
3219 exporter->exp_states |= EXP_EXPORTED;
3221 exporter->exp_states &= ~EXP_EXPORTED;
3223 exporter->exp_states |= EXP_UNIXMODE;
3225 exporter->exp_states &= ~EXP_UNIXMODE;
3227 exporter->exp_states |= EXP_PWSYNC;
3229 exporter->exp_states &= ~EXP_PWSYNC;
3231 afs_NFSRootOnly = 0;
3232 exporter->exp_states |= EXP_SUBMOUNTS;
3234 afs_NFSRootOnly = 1;
3235 exporter->exp_states &= ~EXP_SUBMOUNTS;
3245 struct gaginfo *gagflags;
3247 if (!afs_osi_suser(*acred))
3250 gagflags = (struct gaginfo *)ain;
3251 afs_showflags = gagflags->showflags;
3257 DECL_PIOCTL(PTwiddleRx)
3259 struct rxparams *rxp;
3261 if (!afs_osi_suser(*acred))
3264 rxp = (struct rxparams *)ain;
3266 if (rxp->rx_initReceiveWindow)
3267 rx_initReceiveWindow = rxp->rx_initReceiveWindow;
3268 if (rxp->rx_maxReceiveWindow)
3269 rx_maxReceiveWindow = rxp->rx_maxReceiveWindow;
3270 if (rxp->rx_initSendWindow)
3271 rx_initSendWindow = rxp->rx_initSendWindow;
3272 if (rxp->rx_maxSendWindow)
3273 rx_maxSendWindow = rxp->rx_maxSendWindow;
3274 if (rxp->rxi_nSendFrags)
3275 rxi_nSendFrags = rxp->rxi_nSendFrags;
3276 if (rxp->rxi_nRecvFrags)
3277 rxi_nRecvFrags = rxp->rxi_nRecvFrags;
3278 if (rxp->rxi_OrphanFragSize)
3279 rxi_OrphanFragSize = rxp->rxi_OrphanFragSize;
3280 if (rxp->rx_maxReceiveSize) {
3281 rx_maxReceiveSize = rxp->rx_maxReceiveSize;
3282 rx_maxReceiveSizeUser = rxp->rx_maxReceiveSize;
3284 if (rxp->rx_MyMaxSendSize)
3285 rx_MyMaxSendSize = rxp->rx_MyMaxSendSize;
3290 DECL_PIOCTL(PGetInitParams)
3292 if (sizeof(struct cm_initparams) > PIGGYSIZE)
3295 memcpy(aout, (char *)&cm_initParams, sizeof(struct cm_initparams));
3296 *aoutSize = sizeof(struct cm_initparams);
3300 #ifdef AFS_SGI65_ENV
3301 /* They took crget() from us, so fake it. */
3306 cr = crdup(get_current_cred());
3307 memset((char *)cr, 0, sizeof(cred_t));
3308 #if CELL || CELL_PREPARE
3315 DECL_PIOCTL(PGetRxkcrypt)
3317 memcpy(aout, (char *)&cryptall, sizeof(afs_int32));
3318 *aoutSize = sizeof(afs_int32);
3322 DECL_PIOCTL(PSetRxkcrypt)
3326 if (!afs_osi_suser(*acred))
3328 if (ainSize != sizeof(afs_int32) || ain == NULL)
3330 memcpy((char *)&tmpval, ain, sizeof(afs_int32));
3331 /* if new mappings added later this will need to be changed */
3332 if (tmpval != 0 && tmpval != 1)
3338 #ifdef AFS_NEED_CLIENTCONTEXT
3340 * Create new credentials to correspond to a remote user with given
3341 * <hostaddr, uid, g0, g1>. This allows a server running as root to
3342 * provide pioctl (and other) services to foreign clients (i.e. nfs
3343 * clients) by using this call to `become' the client.
3346 #define PIOCTL_HEADER 6
3348 HandleClientContext(struct afs_ioctl *ablob, int *com,
3349 struct AFS_UCRED **acred, struct AFS_UCRED *credp)
3352 afs_uint32 hostaddr;
3353 afs_int32 uid, g0, g1, i, code, pag, exporter_type;
3354 struct afs_exporter *exporter, *outexporter;
3355 struct AFS_UCRED *newcred;
3356 struct unixuser *au;
3358 #if defined(AFS_SGIMP_ENV)
3359 osi_Assert(ISAFS_GLOCK());
3361 AFS_STATCNT(HandleClientContext);
3362 if (ablob->in_size < PIOCTL_HEADER * sizeof(afs_int32)) {
3363 /* Must at least include the PIOCTL_HEADER header words required by the protocol */
3364 return EINVAL; /* Too small to be good */
3366 ain = inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
3367 AFS_COPYIN(ablob->in, ain, PIOCTL_HEADER * sizeof(afs_int32), code);
3369 osi_FreeLargeSpace(inData);
3373 /* Extract information for remote user */
3374 hostaddr = *((afs_uint32 *) ain);
3375 ain += sizeof(hostaddr);
3376 uid = *((afs_uint32 *) ain);
3378 g0 = *((afs_uint32 *) ain);
3380 g1 = *((afs_uint32 *) ain);
3382 *com = *((afs_uint32 *) ain);
3383 ain += sizeof(afs_int32);
3384 exporter_type = *((afs_uint32 *) ain); /* In case we support more than NFS */
3387 * Of course, one must be root for most of these functions, but
3388 * we'll allow (for knfs) you to set things if the pag is 0 and
3389 * you're setting tokens or unlogging.
3392 if (!afs_osi_suser(credp)) {
3393 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
3394 /* Since SGI's suser() returns explicit failure after the call.. */
3397 /* check for acceptable opcodes for normal folks, which are, so far,
3398 * set tokens and unlog.
3400 if (i != 9 && i != 3 && i != 38 && i != 8) {
3401 osi_FreeLargeSpace(inData);
3406 ablob->in_size -= PIOCTL_HEADER * sizeof(afs_int32);
3407 ablob->in += PIOCTL_HEADER * sizeof(afs_int32);
3408 osi_FreeLargeSpace(inData);
3411 * We map uid 0 to nobody to match the mapping that the nfs
3412 * server does and to ensure that the suser() calls in the afs
3413 * code fails for remote client roots.
3415 uid = afs_nobody; /* NFS_NOBODY == -2 */
3418 #if defined(AFS_LINUX26_ENV)
3419 newcred->cr_group_info = groups_alloc(0);
3421 #ifdef AFS_AIX41_ENV
3424 newcred->cr_gid = RMTUSER_REQ;
3425 #ifdef AFS_AIX51_ENV
3426 newcred->cr_groupset.gs_union.un_groups[0] = g0;
3427 newcred->cr_groupset.gs_union.un_groups[1] = g1;
3429 newcred->cr_groups[0] = g0;
3430 newcred->cr_groups[1] = g1;
3433 newcred->cr_ngrps = 2;
3435 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV)
3436 newcred->cr_ngroups = 2;
3438 for (i = 2; i < NGROUPS; i++)
3439 newcred->cr_groups[i] = NOGROUP;
3442 #if !defined(AFS_OSF_ENV)
3443 afs_nfsclient_init(); /* before looking for exporter, ensure one exists */
3445 if (!(exporter = exporter_find(exporter_type))) {
3446 /* Exporter wasn't initialized or an invalid exporter type */
3450 if (exporter->exp_states & EXP_PWSYNC) {
3451 if (uid != credp->cr_uid) {
3453 return ENOEXEC; /* XXX Find a better errno XXX */
3456 newcred->cr_uid = uid; /* Only temporary */
3457 code = EXP_REQHANDLER(exporter, &newcred, hostaddr, &pag, &outexporter);
3458 /* The client's pag is the only unique identifier for it */
3459 newcred->cr_uid = pag;
3461 if (!code && *com == PSETPAG) {
3462 /* Special case for 'setpag' */
3463 afs_uint32 pagvalue = genpag();
3465 au = afs_GetUser(pagvalue, -1, WRITE_LOCK); /* a new unixuser struct */
3467 * Note that we leave the 'outexporter' struct held so it won't
3470 au->exporter = outexporter;
3471 if (ablob->out_size >= 4) {
3472 AFS_COPYOUT((char *)&pagvalue, ablob->out, sizeof(afs_int32),
3475 afs_PutUser(au, WRITE_LOCK);
3478 return PSETPAG; /* Special return for setpag */
3480 EXP_RELE(outexporter);
3484 #endif /* AFS_NEED_CLIENTCONTEXT */
3486 /* get all interface addresses of this client */
3488 DECL_PIOCTL(PGetCPrefs)
3490 struct sprefrequest *spin; /* input */
3491 struct sprefinfo *spout; /* output */
3492 struct spref *srvout; /* one output component */
3496 AFS_STATCNT(PGetCPrefs);
3497 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3498 return EIO; /* Inappropriate ioctl for device */
3500 if (ainSize < sizeof(struct sprefrequest))
3503 spin = (struct sprefrequest *)ain;
3504 spout = (struct sprefinfo *)aout;
3506 maxNumber = spin->num_servers; /* max addrs this time */
3507 srvout = spout->servers;
3509 ObtainReadLock(&afs_xinterface);
3511 /* copy out the client interface information from the
3512 ** kernel data structure "interface" to the output buffer
3514 for (i = spin->offset, j = 0; (i < afs_cb_interface.numberOfInterfaces)
3515 && (j < maxNumber); i++, j++, srvout++)
3516 srvout->host.s_addr = afs_cb_interface.addr_in[i];
3518 spout->num_servers = j;
3519 *aoutSize = sizeof(struct sprefinfo) + (j - 1) * sizeof(struct spref);
3521 if (i >= afs_cb_interface.numberOfInterfaces)
3522 spout->next_offset = 0; /* start from beginning again */
3524 spout->next_offset = spin->offset + j;
3526 ReleaseReadLock(&afs_xinterface);
3530 DECL_PIOCTL(PSetCPrefs)
3532 struct setspref *sin;
3535 AFS_STATCNT(PSetCPrefs);
3536 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3537 return EIO; /* Inappropriate ioctl for device */
3539 sin = (struct setspref *)ain;
3541 if (ainSize < sizeof(struct setspref))
3543 #if 0 /* num_servers is unsigned */
3544 if (sin->num_servers < 0)
3547 if (sin->num_servers > AFS_MAX_INTERFACE_ADDR)
3550 ObtainWriteLock(&afs_xinterface, 412);
3551 afs_cb_interface.numberOfInterfaces = sin->num_servers;
3552 for (i = 0; (unsigned short)i < sin->num_servers; i++)
3553 afs_cb_interface.addr_in[i] = sin->servers[i].host.s_addr;
3555 ReleaseWriteLock(&afs_xinterface);
3559 DECL_PIOCTL(PFlushMount)
3561 register afs_int32 code;
3562 register struct vcache *tvc;
3563 register struct dcache *tdc;
3564 struct VenusFid tfid;
3566 struct sysname_info sysState;
3567 afs_size_t offset, len;
3569 AFS_STATCNT(PFlushMount);
3572 code = afs_VerifyVCache(avc, areq);
3575 if (vType(avc) != VDIR) {
3578 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
3581 Check_AtSys(avc, ain, &sysState, areq);
3582 ObtainReadLock(&tdc->lock);
3584 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
3585 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
3586 ReleaseReadLock(&tdc->lock);
3587 afs_PutDCache(tdc); /* we're done with the data */
3588 bufp = sysState.name;
3592 tfid.Cell = avc->fid.Cell;
3593 tfid.Fid.Volume = avc->fid.Fid.Volume;
3594 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
3595 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
3597 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3603 if (tvc->mvstat != 1) {
3608 #ifdef AFS_BOZONLOCK_ENV
3609 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
3611 ObtainWriteLock(&tvc->lock, 649);
3612 ObtainWriteLock(&afs_xcbhash, 650);
3613 afs_DequeueCallback(tvc);
3614 tvc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
3615 ReleaseWriteLock(&afs_xcbhash);
3616 /* now find the disk cache entries */
3617 afs_TryToSmush(tvc, *acred, 1);
3618 osi_dnlc_purgedp(tvc);
3619 if (tvc->linkData && !(tvc->states & CCore)) {
3620 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
3621 tvc->linkData = NULL;
3623 ReleaseWriteLock(&tvc->lock);
3624 #ifdef AFS_BOZONLOCK_ENV
3625 afs_BozonUnlock(&tvc->pvnLock, tvc);
3629 if (sysState.allocked)
3630 osi_FreeLargeSpace(bufp);
3634 DECL_PIOCTL(PRxStatProc)
3639 if (!afs_osi_suser(*acred)) {
3643 if (ainSize != sizeof(afs_int32)) {
3647 memcpy((char *)&flags, ain, sizeof(afs_int32));
3648 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3652 if (flags & AFSCALL_RXSTATS_ENABLE) {
3653 rx_enableProcessRPCStats();
3655 if (flags & AFSCALL_RXSTATS_DISABLE) {
3656 rx_disableProcessRPCStats();
3658 if (flags & AFSCALL_RXSTATS_CLEAR) {
3659 rx_clearProcessRPCStats(AFS_RX_STATS_CLEAR_ALL);
3667 DECL_PIOCTL(PRxStatPeer)
3672 if (!afs_osi_suser(*acred)) {
3676 if (ainSize != sizeof(afs_int32)) {
3680 memcpy((char *)&flags, ain, sizeof(afs_int32));
3681 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3685 if (flags & AFSCALL_RXSTATS_ENABLE) {
3686 rx_enablePeerRPCStats();
3688 if (flags & AFSCALL_RXSTATS_DISABLE) {
3689 rx_disablePeerRPCStats();
3691 if (flags & AFSCALL_RXSTATS_CLEAR) {
3692 rx_clearPeerRPCStats(AFS_RX_STATS_CLEAR_ALL);
3699 DECL_PIOCTL(PPrefetchFromTape)
3701 register afs_int32 code, code1;
3704 struct rx_call *tcall;
3705 struct AFSVolSync tsync;
3706 struct AFSFetchStatus OutStatus;
3707 struct AFSCallBack CallBack;
3708 struct VenusFid tfid;
3712 AFS_STATCNT(PSetAcl);
3716 if (ain && (ainSize == 3 * sizeof(afs_int32)))
3717 Fid = (struct AFSFid *)ain;
3719 Fid = &avc->fid.Fid;
3720 tfid.Cell = avc->fid.Cell;
3721 tfid.Fid.Volume = Fid->Volume;
3722 tfid.Fid.Vnode = Fid->Vnode;
3723 tfid.Fid.Unique = Fid->Unique;
3725 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3727 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3728 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &avc->fid);
3731 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3732 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &tvc->fid);
3735 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3739 tcall = rx_NewCall(tc->id);
3741 StartRXAFS_FetchData(tcall, (struct AFSFid *)&tvc->fid.Fid, 0,
3744 bytes = rx_Read(tcall, (char *)aout, sizeof(afs_int32));
3746 EndRXAFS_FetchData(tcall, &OutStatus, &CallBack, &tsync);
3748 code1 = rx_EndCall(tcall, code);
3752 } while (afs_Analyze
3753 (tc, code, &tvc->fid, areq, AFS_STATS_FS_RPCIDX_RESIDENCYRPCS,
3754 SHARED_LOCK, NULL));
3755 /* This call is done only to have the callback things handled correctly */
3756 afs_FetchStatus(tvc, &tfid, areq, &OutStatus);
3760 *aoutSize = sizeof(afs_int32);
3765 DECL_PIOCTL(PResidencyCmd)
3767 register afs_int32 code;
3770 struct ResidencyCmdInputs *Inputs;
3771 struct ResidencyCmdOutputs *Outputs;
3772 struct VenusFid tfid;
3775 Inputs = (struct ResidencyCmdInputs *)ain;
3776 Outputs = (struct ResidencyCmdOutputs *)aout;
3779 if (!ain || ainSize != sizeof(struct ResidencyCmdInputs))
3784 Fid = &avc->fid.Fid;
3786 tfid.Cell = avc->fid.Cell;
3787 tfid.Fid.Volume = Fid->Volume;
3788 tfid.Fid.Vnode = Fid->Vnode;
3789 tfid.Fid.Unique = Fid->Unique;
3791 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3792 afs_Trace3(afs_iclSetp, CM_TRACE_RESIDCMD, ICL_TYPE_POINTER, tvc,
3793 ICL_TYPE_INT32, Inputs->command, ICL_TYPE_FID, &tfid);
3797 if (Inputs->command) {
3799 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3803 RXAFS_ResidencyCmd(tc->id, Fid, Inputs,
3804 (struct ResidencyCmdOutputs *)aout);
3808 } while (afs_Analyze
3809 (tc, code, &tvc->fid, areq,
3810 AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK, NULL));
3811 /* This call is done to have the callback things handled correctly */
3812 afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3813 } else { /* just a status request, return also link data */
3815 Outputs->code = afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3816 Outputs->chars[0] = 0;
3817 if (vType(tvc) == VLNK) {
3818 ObtainWriteLock(&tvc->lock, 555);
3819 if (afs_HandleLink(tvc, areq) == 0)
3820 strncpy((char *)&Outputs->chars, tvc->linkData, MAXCMDCHARS);
3821 ReleaseWriteLock(&tvc->lock);
3828 *aoutSize = sizeof(struct ResidencyCmdOutputs);
3833 DECL_PIOCTL(PCallBackAddr)
3836 afs_uint32 addr, code;
3842 struct unixuser *tu;
3843 struct srvAddr **addrs;
3845 /*AFS_STATCNT(PCallBackAddr); */
3846 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
3847 return EIO; /* Inappropriate ioctl for device */
3849 if (!afs_osi_suser(acred))
3852 if (ainSize < sizeof(afs_int32))
3855 memcpy(&addr, ain, sizeof(afs_int32));
3857 ObtainReadLock(&afs_xinterface);
3858 for (i = 0; (unsigned short)i < afs_cb_interface.numberOfInterfaces; i++) {
3859 if (afs_cb_interface.addr_in[i] == addr)
3863 ReleaseWriteLock(&afs_xinterface);
3865 if (afs_cb_interface.addr_in[i] != addr)
3868 ObtainReadLock(&afs_xserver); /* Necessary? */
3869 ObtainReadLock(&afs_xsrvAddr);
3872 for (i = 0; i < NSERVERS; i++) {
3873 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3878 addrs = afs_osi_Alloc(srvAddrCount * sizeof(*addrs));
3880 for (i = 0; i < NSERVERS; i++) {
3881 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3882 if (j >= srvAddrCount)
3888 ReleaseReadLock(&afs_xsrvAddr);
3889 ReleaseReadLock(&afs_xserver);
3891 for (i = 0; i < j; i++) {
3897 /* vlserver has no callback conn */
3898 if (sa->sa_portal == AFS_VLPORT) {
3902 if (!ts->cell) /* not really an active server, anyway, it must */
3903 continue; /* have just been added by setsprefs */
3905 /* get a connection, even if host is down; bumps conn ref count */
3906 tu = afs_GetUser(areq->uid, ts->cell->cellNum, SHARED_LOCK);
3907 tc = afs_ConnBySA(sa, ts->cell->fsport, ts->cell->cellNum, tu,
3908 1 /*force */ , 1 /*create */ , SHARED_LOCK);
3909 afs_PutUser(tu, SHARED_LOCK);
3913 if ((sa->sa_flags & SRVADDR_ISDOWN) || afs_HaveCallBacksFrom(ts)) {
3914 if (sa->sa_flags & SRVADDR_ISDOWN) {
3915 rx_SetConnDeadTime(tc->id, 3);
3917 #ifdef RX_ENABLE_LOCKS
3919 #endif /* RX_ENABLE_LOCKS */
3920 code = RXAFS_CallBackRxConnAddr(tc->id, &addr);
3921 #ifdef RX_ENABLE_LOCKS
3923 #endif /* RX_ENABLE_LOCKS */
3925 afs_PutConn(tc, SHARED_LOCK); /* done with it now */
3926 } /* Outer loop over addrs */
3927 #endif /* UKERNEL */