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(PSetSysName);
75 DECL_PIOCTL(PSetSPrefs);
76 DECL_PIOCTL(PSetSPrefs33);
77 DECL_PIOCTL(PGetSPrefs);
78 DECL_PIOCTL(PExportAfs);
80 DECL_PIOCTL(PTwiddleRx);
81 DECL_PIOCTL(PGetInitParams);
82 DECL_PIOCTL(PGetRxkcrypt);
83 DECL_PIOCTL(PSetRxkcrypt);
84 DECL_PIOCTL(PGetCPrefs);
85 DECL_PIOCTL(PSetCPrefs);
86 DECL_PIOCTL(PFlushMount);
87 DECL_PIOCTL(PRxStatProc);
88 DECL_PIOCTL(PRxStatPeer);
89 DECL_PIOCTL(PPrefetchFromTape);
90 DECL_PIOCTL(PResidencyCmd);
91 DECL_PIOCTL(PCallBackAddr);
94 * A macro that says whether we're going to need HandleClientContext().
95 * This is currently used only by the nfs translator.
97 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
98 #define AFS_NEED_CLIENTCONTEXT
101 /* Prototypes for private routines */
102 #ifdef AFS_NEED_CLIENTCONTEXT
103 static int HandleClientContext(struct afs_ioctl *ablob, int *com,
104 struct AFS_UCRED **acred,
105 struct AFS_UCRED *credp);
107 int HandleIoctl(register struct vcache *avc, register afs_int32 acom,
108 struct afs_ioctl *adata);
109 int afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
110 register struct afs_ioctl *ablob, int afollow,
111 struct AFS_UCRED **acred);
112 static int Prefetch(char *apath, struct afs_ioctl *adata, int afollow,
113 struct AFS_UCRED *acred);
116 static int (*(VpioctlSw[])) () = {
121 PGetVolumeStatus, /* 4 */
122 PSetVolumeStatus, /* 5 */
127 PCheckServers, /* 10 */
128 PCheckVolNames, /* 11 */
130 PBogus, /* 13 -- used to be quick check time */
131 PFindVolume, /* 14 */
132 PBogus, /* 15 -- prefetch is now special-cased; see pioctl code! */
133 PBogus, /* 16 -- used to be testing code */
134 PNoop, /* 17 -- used to be enable group */
135 PNoop, /* 18 -- used to be disable group */
136 PBogus, /* 19 -- used to be list group */
137 PViceAccess, /* 20 */
138 PUnlog, /* 21 -- unlog *is* unpag in this system */
139 PGetFID, /* 22 -- get file ID */
140 PBogus, /* 23 -- used to be waitforever */
141 PSetCacheSize, /* 24 */
142 PRemoveCallBack, /* 25 -- flush only the callback */
145 PRemoveMount, /* 28 -- delete mount point */
146 PNewStatMount, /* 29 -- new style mount point stat */
147 PGetFileCell, /* 30 -- get cell name for input file */
148 PGetWSCell, /* 31 -- get cell name for workstation */
149 PMariner, /* 32 - set/get mariner host */
150 PGetUserCell, /* 33 -- get cell name for user */
151 PVenusLogging, /* 34 -- Enable/Disable logging */
152 PGetCellStatus, /* 35 */
153 PSetCellStatus, /* 36 */
154 PFlushVolumeData, /* 37 -- flush all data from a volume */
155 PSetSysName, /* 38 - Set system name */
156 PExportAfs, /* 39 - Export Afs to remote nfs clients */
157 PGetCacheSize, /* 40 - get cache size and usage */
158 PGetVnodeXStatus, /* 41 - get vcache's special status */
159 PSetSPrefs33, /* 42 - Set CM Server preferences... */
160 PGetSPrefs, /* 43 - Get CM Server preferences... */
161 PGag, /* 44 - turn off/on all CM messages */
162 PTwiddleRx, /* 45 - adjust some RX params */
163 PSetSPrefs, /* 46 - Set CM Server preferences... */
164 PStoreBehind, /* 47 - set degree of store behind to be done */
165 PGCPAGs, /* 48 - disable automatic pag gc-ing */
166 PGetInitParams, /* 49 - get initial cm params */
167 PGetCPrefs, /* 50 - get client interface addresses */
168 PSetCPrefs, /* 51 - set client interface addresses */
169 PFlushMount, /* 52 - flush mount symlink data */
170 PRxStatProc, /* 53 - control process RX statistics */
171 PRxStatPeer, /* 54 - control peer RX statistics */
172 PGetRxkcrypt, /* 55 -- Get rxkad encryption flag */
173 PSetRxkcrypt, /* 56 -- Set rxkad encryption flag */
174 PBogus, /* 57 -- arla: set file prio */
175 PBogus, /* 58 -- arla: fallback getfh */
176 PBogus, /* 59 -- arla: fallback fhopen */
177 PBogus, /* 60 -- arla: controls xfsdebug */
178 PBogus, /* 61 -- arla: controls arla debug */
179 PBogus, /* 62 -- arla: debug interface */
180 PBogus, /* 63 -- arla: print xfs status */
181 PBogus, /* 64 -- arla: force cache check */
182 PBogus, /* 65 -- arla: break callback */
183 PPrefetchFromTape, /* 66 -- MR-AFS: prefetch file from tape */
184 PResidencyCmd, /* 67 -- MR-AFS: generic commnd interface */
185 PBogus, /* 68 -- arla: fetch stats */
188 static int (*(CpioctlSw[])) () = {
190 PNewAlias, /* 1 -- create new cell alias */
191 PListAliases, /* 2 -- list cell aliases */
192 PCallBackAddr, /* 3 -- request addr for callback rxcon */
195 #define PSetClientContext 99 /* Special pioctl to setup caller's creds */
196 int afs_nobody = NFS_NOBODY;
198 #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(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV))
200 afs_ioctl32_to_afs_ioctl(const struct afs_ioctl32 *src, struct afs_ioctl *dst)
202 dst->in = (char *)(unsigned long)src->in;
203 dst->out = (char *)(unsigned long)src->out;
204 dst->in_size = src->in_size;
205 dst->out_size = src->out_size;
210 * If you need to change copyin_afs_ioctl(), you may also need to change
215 copyin_afs_ioctl(caddr_t cmarg, struct afs_ioctl *dst)
218 #if defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)
219 struct afs_ioctl32 dst32;
222 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
224 afs_ioctl32_to_afs_ioctl(&dst32, dst);
227 #endif /* defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL) */
230 #if defined(AFS_HPUX_64BIT_ENV)
231 struct afs_ioctl32 dst32;
233 if (is_32bit(u.u_procp)) { /* is_32bit() in proc_iface.h */
234 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
236 afs_ioctl32_to_afs_ioctl(&dst32, dst);
239 #endif /* defined(AFS_HPUX_64BIT_ENV) */
241 #if defined(AFS_SUN57_64BIT_ENV)
242 struct afs_ioctl32 dst32;
244 if (get_udatamodel() == DATAMODEL_ILP32) {
245 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
247 afs_ioctl32_to_afs_ioctl(&dst32, dst);
250 #endif /* defined(AFS_SUN57_64BIT_ENV) */
252 #if defined(AFS_SGI_ENV) && (_MIPS_SZLONG==64)
253 struct afs_ioctl32 dst32;
255 if (!ABI_IS_64BIT(get_current_abi())) {
256 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
258 afs_ioctl32_to_afs_ioctl(&dst32, dst);
261 #endif /* defined(AFS_SGI_ENV) && (_MIPS_SZLONG==64) */
263 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV)
264 struct afs_ioctl32 dst32;
266 #ifdef AFS_SPARC64_LINUX24_ENV
267 if (current->thread.flags & SPARC_FLAG_32BIT)
268 #elif defined(AFS_SPARC64_LINUX20_ENV)
269 if (current->tss.flags & SPARC_FLAG_32BIT)
271 #elif defined(AFS_AMD64_LINUX26_ENV)
272 if (test_thread_flag(TIF_IA32))
273 #elif defined(AFS_AMD64_LINUX20_ENV)
274 if (current->thread.flags & THREAD_IA32)
276 #elif defined(AFS_PPC64_LINUX26_ENV)
277 if (current->thread_info->flags & _TIF_32BIT)
278 #elif defined(AFS_PPC64_LINUX20_ENV)
279 if (current->thread.flags & PPC_FLAG_32BIT)
281 #elif defined(AFS_S390X_LINUX26_ENV)
282 if (test_thread_flag(TIF_31BIT))
283 #elif defined(AFS_S390X_LINUX20_ENV)
284 if (current->thread.flags & S390_FLAG_31BIT)
287 #error pioctl32 not done for this linux
290 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
292 afs_ioctl32_to_afs_ioctl(&dst32, dst);
295 #endif /* defined(AFS_LINUX_64BIT_KERNEL) */
297 AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code);
302 HandleIoctl(register struct vcache *avc, register afs_int32 acom,
303 struct afs_ioctl *adata)
305 register afs_int32 code;
308 AFS_STATCNT(HandleIoctl);
310 switch (acom & 0xff) {
312 avc->states |= CSafeStore;
316 /* case 2 used to be abort store, but this is no longer provided,
317 * since it is impossible to implement under normal Unix.
321 /* return the name of the cell this file is open on */
322 register struct cell *tcell;
323 register afs_int32 i;
325 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
327 i = strlen(tcell->cellName) + 1; /* bytes to copy out */
329 if (i > adata->out_size) {
330 /* 0 means we're not interested in the output */
331 if (adata->out_size != 0)
335 AFS_COPYOUT(tcell->cellName, adata->out, i, code);
337 afs_PutCell(tcell, READ_LOCK);
343 case 49: /* VIOC_GETINITPARAMS */
344 if (adata->out_size < sizeof(struct cm_initparams)) {
347 AFS_COPYOUT(&cm_initParams, adata->out,
348 sizeof(struct cm_initparams), code);
360 return code; /* so far, none implemented */
365 /* For aix we don't temporarily bypass ioctl(2) but rather do our
366 * thing directly in the vnode layer call, VNOP_IOCTL; thus afs_ioctl
367 * is now called from afs_gn_ioctl.
370 afs_ioctl(struct vcache *tvc, int cmd, int arg)
372 struct afs_ioctl data;
375 AFS_STATCNT(afs_ioctl);
376 if (((cmd >> 8) & 0xff) == 'V') {
377 /* This is a VICEIOCTL call */
378 AFS_COPYIN(arg, (caddr_t) & data, sizeof(data), error);
381 error = HandleIoctl(tvc, cmd, &data);
384 /* No-op call; just return. */
388 #endif /* AFS_AIX_ENV */
390 #if defined(AFS_SGI_ENV)
391 afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
394 , struct vopbd * vbds
398 struct afs_ioctl data;
404 AFS_STATCNT(afs_ioctl);
405 if (((cmd >> 8) & 0xff) == 'V') {
406 /* This is a VICEIOCTL call */
407 error = copyin_afs_ioctl(arg, &data);
410 locked = ISAFS_GLOCK();
413 error = HandleIoctl(tvc, cmd, &data);
418 /* No-op call; just return. */
422 #endif /* AFS_SGI_ENV */
424 /* unlike most calls here, this one uses u.u_error to return error conditions,
425 since this is really an intercepted chapter 2 call, rather than a vnode
428 /* AFS_HPUX102 and up uses VNODE ioctl instead */
429 #ifndef AFS_HPUX102_ENV
430 #if !defined(AFS_SGI_ENV)
434 kioctl(fdes, com, arg, ext, arg2, arg3)
435 #else /* __64BIT__ */
436 kioctl32(fdes, com, arg, ext, arg2, arg3)
437 #endif /* __64BIT__ */
440 kioctl(fdes, com, arg, ext)
451 } u_uap, *uap = &u_uap;
453 #if defined(AFS_SUN5_ENV)
455 struct afs_ioctl_sys {
462 struct afs_ioctl_sys *uap;
465 #elif defined(AFS_OSF_ENV)
466 afs_xioctl(p, args, retval)
475 } *uap = (struct a *)args;
476 #elif defined(AFS_FBSD50_ENV)
479 afs_xioctl(td, uap, retval)
481 register struct ioctl_args *uap;
484 struct proc *p = td->td_proc;
485 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
493 afs_xioctl(p, uap, retval)
495 register struct ioctl_args *uap;
498 #elif defined(AFS_LINUX22_ENV)
499 struct afs_ioctl_sys {
504 afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
507 struct afs_ioctl_sys ua, *uap = &ua;
516 } *uap = (struct a *)u.u_ap;
517 #endif /* AFS_SUN5_ENV */
519 #if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
521 #elif !defined(AFS_LINUX22_ENV)
522 register struct file *fd;
524 #if defined(AFS_XBSD_ENV)
525 register struct filedesc *fdp;
527 register struct vcache *tvc;
528 register int ioctlDone = 0, code = 0;
530 AFS_STATCNT(afs_xioctl);
531 #if defined(AFS_XBSD_ENV)
533 if ((u_int) uap->fd >= fdp->fd_nfiles
534 || (fd = fdp->fd_ofiles[uap->fd]) == NULL)
536 if ((fd->f_flag & (FREAD | FWRITE)) == 0)
538 #elif defined(AFS_DARWIN_ENV)
539 if ((code = fdgetf(p, uap->fd, &fd)))
541 #elif defined(AFS_LINUX22_ENV)
544 #elif defined(AFS_AIX32_ENV)
552 if (setuerror(getf(uap->fd, &fd))) {
555 #elif defined(AFS_OSF_ENV)
557 if (code = getf(&fd, uap->fd, FILE_FLAGS_NULL, &u.u_file_state))
559 #elif defined(AFS_SUN5_ENV)
560 # if defined(AFS_SUN57_ENV)
564 # elif defined(AFS_SUN54_ENV)
569 if (code = getf(uap->fd, &fd)) {
572 # endif /* AFS_SUN57_ENV */
578 /* first determine whether this is any sort of vnode */
579 #if defined(AFS_LINUX22_ENV)
584 if (fd->f_vnode->v_type == VREG || fd->f_vnode->v_type == VDIR) {
586 if (fd->f_type == DTYPE_VNODE) {
588 /* good, this is a vnode; next see if it is an AFS vnode */
589 #if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV)
590 tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */
591 #elif defined(AFS_OBSD_ENV)
593 IsAfsVnode((struct vnode *)fd->
594 f_data) ? VTOAFS((struct vnode *)fd->f_data) : NULL;
596 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
598 #endif /* AFS_LINUX22_ENV */
599 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
601 tvc = VTOAFS(afs_gntovn((struct gnode *)tvc));
602 if (!tvc) { /* shouldn't happen with held gnodes */
607 /* This is an AFS vnode */
608 if (((uap->com >> 8) & 0xff) == 'V') {
609 register struct afs_ioctl *datap;
612 (struct afs_ioctl *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
613 AFS_COPYIN((char *)uap->arg, (caddr_t) datap,
614 sizeof(struct afs_ioctl), code);
616 osi_FreeSmallSpace(datap);
618 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
621 #if defined(AFS_SUN5_ENV)
636 #else /* AFS_OSF_ENV */
640 #ifdef AFS_LINUX22_ENV
650 code = HandleIoctl(tvc, uap->com, datap);
651 osi_FreeSmallSpace(datap);
665 #if defined(AFS_LINUX22_ENV)
677 code = okioctl(fdes, com, arg, ext, arg2, arg3);
678 #else /* __64BIT__ */
679 code = okioctl32(fdes, com, arg, ext, arg2, arg3);
680 #endif /* __64BIT__ */
681 #else /* !AFS_AIX51_ENV */
682 code = okioctl(fdes, com, arg, ext);
683 #endif /* AFS_AIX51_ENV */
685 #else /* !AFS_AIX41_ENV */
687 okioctl(fdes, com, arg, ext);
688 #elif defined(AFS_SUN5_ENV)
689 #if defined(AFS_SUN57_ENV)
691 #elif defined(AFS_SUN54_ENV)
696 code = ioctl(uap, rvp);
697 #elif defined(AFS_FBSD50_ENV)
698 return ioctl(td, uap);
699 #elif defined(AFS_FBSD_ENV)
700 return ioctl(p, uap);
701 #elif defined(AFS_OBSD_ENV)
702 code = sys_ioctl(p, uap, retval);
703 #elif defined(AFS_DARWIN_ENV)
704 return ioctl(p, uap, retval);
705 #elif defined(AFS_OSF_ENV)
706 code = ioctl(p, args, retval);
713 #elif !defined(AFS_LINUX22_ENV)
727 #ifdef AFS_LINUX22_ENV
730 #if defined(KERNEL_HAVE_UERROR)
733 #if defined(AFS_AIX32_ENV) && !defined(AFS_AIX41_ENV)
734 return (getuerror()? -1 : u.u_ioctlrv);
736 return getuerror()? -1 : 0;
739 #endif /* AFS_LINUX22_ENV */
740 #endif /* AFS_SUN5_ENV */
741 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
745 #endif /* AFS_SGI_ENV */
746 #endif /* AFS_HPUX102_ENV */
748 #if defined(AFS_SGI_ENV)
749 /* "pioctl" system call entry point; just pass argument to the parameterized
758 afs_pioctl(struct pioctlargs *uap, rval_t * rvp)
762 AFS_STATCNT(afs_pioctl);
764 code = afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow);
773 #elif defined(AFS_OSF_ENV)
774 afs_pioctl(p, args, retval)
784 } *uap = (struct a *)args;
786 AFS_STATCNT(afs_pioctl);
787 return (afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow));
790 #elif defined(AFS_FBSD50_ENV)
792 afs_pioctl(td, args, retval)
802 } *uap = (struct a *)args;
804 AFS_STATCNT(afs_pioctl);
805 return (afs_syscall_pioctl
806 (uap->path, uap->cmd, uap->cmarg, uap->follow, td->td_ucred));
809 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
811 afs_pioctl(p, args, retval)
821 } *uap = (struct a *)args;
823 AFS_STATCNT(afs_pioctl);
824 return (afs_syscall_pioctl
825 (uap->path, uap->cmd, uap->cmarg, uap->follow,
826 p->p_cred->pc_ucred));
831 /* macro to avoid adding any more #ifdef's to pioctl code. */
832 #if defined(AFS_LINUX22_ENV) || defined(AFS_AIX41_ENV)
833 #define PIOCTL_FREE_CRED() crfree(credp)
835 #define PIOCTL_FREE_CRED()
840 afs_syscall_pioctl(path, com, cmarg, follow, rvp, credp)
842 struct AFS_UCRED *credp;
844 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
845 afs_syscall_pioctl(path, com, cmarg, follow, credp)
846 struct AFS_UCRED *credp;
848 afs_syscall_pioctl(path, com, cmarg, follow)
856 struct afs_ioctl data;
857 #ifdef AFS_NEED_CLIENTCONTEXT
858 struct AFS_UCRED *tmpcred;
860 struct AFS_UCRED *foreigncreds = NULL;
861 register afs_int32 code = 0;
862 struct vnode *vp = NULL;
867 struct ucred *credp = crref(); /* don't free until done! */
869 #ifdef AFS_LINUX22_ENV
870 cred_t *credp = crref(); /* don't free until done! */
874 AFS_STATCNT(afs_syscall_pioctl);
876 follow = 1; /* compat. with old venus */
877 code = copyin_afs_ioctl(cmarg, &data);
880 #if defined(KERNEL_HAVE_UERROR)
885 if ((com & 0xff) == PSetClientContext) {
886 #ifdef AFS_NEED_CLIENTCONTEXT
887 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV)
888 code = HandleClientContext(&data, &com, &foreigncreds, credp);
890 code = HandleClientContext(&data, &com, &foreigncreds, osi_curcred());
894 crfree(foreigncreds);
897 #if defined(KERNEL_HAVE_UERROR)
898 return (setuerror(code), code);
903 #else /* AFS_NEED_CLIENTCONTEXT */
905 #endif /* AFS_NEED_CLIENTCONTEXT */
907 #ifdef AFS_NEED_CLIENTCONTEXT
910 * We could have done without temporary setting the u.u_cred below
911 * (foreigncreds could be passed as param the pioctl modules)
912 * but calls such as afs_osi_suser() doesn't allow that since it
913 * references u.u_cred directly. We could, of course, do something
914 * like afs_osi_suser(cred) which, I think, is better since it
915 * generalizes and supports multi cred environments...
919 credp = foreigncreds;
920 #elif defined(AFS_AIX41_ENV)
921 tmpcred = crref(); /* XXX */
923 #elif defined(AFS_HPUX101_ENV)
924 tmpcred = p_cred(u.u_procp);
925 set_p_cred(u.u_procp, foreigncreds);
926 #elif defined(AFS_SGI_ENV)
927 tmpcred = OSI_GET_CURRENT_CRED();
928 OSI_SET_CURRENT_CRED(foreigncreds);
931 u.u_cred = foreigncreds;
934 #endif /* AFS_NEED_CLIENTCONTEXT */
935 if ((com & 0xff) == 15) {
936 /* special case prefetch so entire pathname eval occurs in helper process.
937 * otherwise, the pioctl call is essentially useless */
938 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
940 Prefetch(path, &data, follow,
941 foreigncreds ? foreigncreds : credp);
943 code = Prefetch(path, &data, follow, osi_curcred());
946 #if defined(KERNEL_HAVE_UERROR)
955 lookupname(path, USR, follow, NULL, &vp,
956 foreigncreds ? foreigncreds : credp);
958 #ifdef AFS_LINUX22_ENV
959 code = gop_lookupname(path, AFS_UIOUSER, follow, NULL, &dp);
961 vp = (struct vnode *)dp->d_inode;
963 code = gop_lookupname(path, AFS_UIOUSER, follow, NULL, &vp);
964 #endif /* AFS_LINUX22_ENV */
965 #endif /* AFS_AIX41_ENV */
969 #if defined(KERNEL_HAVE_UERROR)
977 /* now make the call if we were passed no file, or were passed an AFS file */
978 if (!vp || IsAfsVnode(vp)) {
979 #if defined(AFS_DEC_ENV)
980 /* Ultrix 4.0: can't get vcache entry unless we've got an AFS gnode.
981 * So, we must test in this part of the code. Also, must arrange to
982 * GRELE the original gnode pointer when we're done, since in Ultrix 4.0,
983 * we hold gnodes, whose references hold our vcache entries.
986 gp = vp; /* remember for "put" */
987 vp = (struct vnode *)afs_gntovn(vp); /* get vcache from gp */
990 #elif defined(AFS_SUN5_ENV)
991 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
992 #elif defined(AFS_AIX41_ENV)
994 struct ucred *cred1, *cred2;
997 cred1 = cred2 = foreigncreds;
999 cred1 = cred2 = credp;
1001 code = afs_HandlePioctl(vp, com, &data, follow, &cred1);
1002 if (cred1 != cred2) {
1003 /* something changed the creds */
1007 #elif defined(AFS_HPUX101_ENV)
1009 struct ucred *cred = p_cred(u.u_procp);
1010 code = afs_HandlePioctl(vp, com, &data, follow, &cred);
1012 #elif defined(AFS_SGI_ENV)
1015 credp = OSI_GET_CURRENT_CRED();
1016 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1018 #elif defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1019 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1021 code = afs_HandlePioctl(vp, com, &data, follow, &u.u_cred);
1024 #if defined(KERNEL_HAVE_UERROR)
1027 code = EINVAL; /* not in /afs */
1038 #if defined(AFS_NEED_CLIENTCONTEXT)
1040 #ifdef AFS_AIX41_ENV
1041 crset(tmpcred); /* restore original credentials */
1043 #if defined(AFS_HPUX101_ENV)
1044 set_p_cred(u.u_procp, tmpcred); /* restore original credentials */
1045 #elif defined(AFS_SGI_ENV)
1046 OSI_SET_CURRENT_CRED(tmpcred); /* restore original credentials */
1047 #elif !defined(AFS_SUN5_ENV)
1048 osi_curcred() = tmpcred; /* restore original credentials */
1049 #endif /* AFS_HPUX101_ENV */
1050 crfree(foreigncreds);
1053 #endif /* AFS_NEED_CLIENTCONTEXT */
1055 #ifdef AFS_LINUX22_ENV
1058 AFS_RELE(vp); /* put vnode back */
1062 #if defined(KERNEL_HAVE_UERROR)
1065 return (getuerror());
1071 #define MAXPIOCTLTOKENLEN \
1072 (3*sizeof(afs_int32)+MAXKTCTICKETLEN+sizeof(struct ClearToken)+MAXKTCREALMLEN)
1075 afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
1076 register struct afs_ioctl *ablob, int afollow,
1077 struct AFS_UCRED **acred)
1080 struct vrequest treq;
1081 register afs_int32 code;
1082 register afs_int32 function, device;
1083 afs_int32 inSize, outSize, outSizeMax;
1084 char *inData, *outData;
1085 int (*(*pioctlSw)) ();
1087 struct afs_fakestat_state fakestate;
1089 avc = avp ? VTOAFS(avp) : NULL;
1090 afs_Trace3(afs_iclSetp, CM_TRACE_PIOCTL, ICL_TYPE_INT32, acom & 0xff,
1091 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, afollow);
1092 AFS_STATCNT(HandlePioctl);
1093 if ((code = afs_InitReq(&treq, *acred)))
1095 afs_InitFakeStat(&fakestate);
1097 code = afs_EvalFakeStat(&avc, &fakestate, &treq);
1099 afs_PutFakeStat(&fakestate);
1103 device = (acom & 0xff00) >> 8;
1105 case 'V': /* Original pioctls */
1106 pioctlSw = VpioctlSw;
1107 pioctlSwSize = sizeof(VpioctlSw);
1109 case 'C': /* Coordinated/common pioctls */
1110 pioctlSw = CpioctlSw;
1111 pioctlSwSize = sizeof(CpioctlSw);
1114 afs_PutFakeStat(&fakestate);
1117 function = acom & 0xff;
1118 if (function >= (pioctlSwSize / sizeof(char *))) {
1119 afs_PutFakeStat(&fakestate);
1120 return EINVAL; /* out of range */
1122 inSize = ablob->in_size;
1124 /* Do all range checking before continuing */
1125 if (inSize > MAXPIOCTLTOKENLEN || inSize < 0 || ablob->out_size < 0)
1128 /* Note that we use osi_Alloc for large allocs and osi_AllocLargeSpace for small ones */
1129 if (inSize > AFS_LRALLOCSIZ) {
1130 inData = osi_Alloc(inSize + 1);
1132 inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1137 AFS_COPYIN(ablob->in, inData, inSize, code);
1138 inData[inSize] = '\0';
1142 if (inSize > AFS_LRALLOCSIZ) {
1143 osi_Free(inData, inSize + 1);
1145 osi_FreeLargeSpace(inData);
1147 afs_PutFakeStat(&fakestate);
1150 if (function == 8 && device == 'V') { /* PGetTokens */
1151 outSizeMax = MAXPIOCTLTOKENLEN;
1152 outData = osi_Alloc(outSizeMax);
1154 outSizeMax = AFS_LRALLOCSIZ;
1155 outData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1158 if (inSize > AFS_LRALLOCSIZ) {
1159 osi_Free(inData, inSize + 1);
1161 osi_FreeLargeSpace(inData);
1163 afs_PutFakeStat(&fakestate);
1168 (*pioctlSw[function]) (avc, function, &treq, inData, outData, inSize,
1170 if (inSize > AFS_LRALLOCSIZ) {
1171 osi_Free(inData, inSize + 1);
1173 osi_FreeLargeSpace(inData);
1175 if (code == 0 && ablob->out_size > 0) {
1176 if (outSize > ablob->out_size) {
1177 code = E2BIG; /* data wont fit in user buffer */
1178 } else if (outSize) {
1179 AFS_COPYOUT(outData, ablob->out, outSize, code);
1182 if (outSizeMax > AFS_LRALLOCSIZ) {
1183 osi_Free(outData, outSizeMax);
1185 osi_FreeLargeSpace(outData);
1187 afs_PutFakeStat(&fakestate);
1188 return afs_CheckCode(code, &treq, 41);
1191 DECL_PIOCTL(PGetFID)
1193 AFS_STATCNT(PGetFID);
1196 memcpy(aout, (char *)&avc->fid, sizeof(struct VenusFid));
1197 *aoutSize = sizeof(struct VenusFid);
1201 DECL_PIOCTL(PSetAcl)
1203 register afs_int32 code;
1205 struct AFSOpaque acl;
1206 struct AFSVolSync tsync;
1207 struct AFSFetchStatus OutStatus;
1210 AFS_STATCNT(PSetAcl);
1213 if ((acl.AFSOpaque_len = strlen(ain) + 1) > 1000)
1216 acl.AFSOpaque_val = ain;
1218 tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1220 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREACL);
1223 RXAFS_StoreACL(tconn->id, (struct AFSFid *)&avc->fid.Fid,
1224 &acl, &OutStatus, &tsync);
1229 } while (afs_Analyze
1230 (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_STOREACL,
1231 SHARED_LOCK, NULL));
1233 /* now we've forgotten all of the access info */
1234 ObtainWriteLock(&afs_xcbhash, 455);
1236 afs_DequeueCallback(avc);
1237 avc->states &= ~(CStatd | CUnique);
1238 ReleaseWriteLock(&afs_xcbhash);
1239 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
1240 osi_dnlc_purgedp(avc);
1244 int afs_defaultAsynchrony = 0;
1246 DECL_PIOCTL(PStoreBehind)
1249 struct sbstruct *sbr;
1251 sbr = (struct sbstruct *)ain;
1252 if (sbr->sb_default != -1) {
1253 if (afs_osi_suser(*acred))
1254 afs_defaultAsynchrony = sbr->sb_default;
1259 if (avc && (sbr->sb_thisfile != -1)) {
1261 (avc, PRSFS_WRITE | PRSFS_ADMINISTER, areq, DONT_CHECK_MODE_BITS))
1262 avc->asynchrony = sbr->sb_thisfile;
1267 *aoutSize = sizeof(struct sbstruct);
1268 sbr = (struct sbstruct *)aout;
1269 sbr->sb_default = afs_defaultAsynchrony;
1271 sbr->sb_thisfile = avc->asynchrony;
1277 DECL_PIOCTL(PGCPAGs)
1279 if (!afs_osi_suser(*acred)) {
1282 afs_gcpags = AFS_GCPAGS_USERDISABLED;
1286 DECL_PIOCTL(PGetAcl)
1288 struct AFSOpaque acl;
1289 struct AFSVolSync tsync;
1290 struct AFSFetchStatus OutStatus;
1296 AFS_STATCNT(PGetAcl);
1299 Fid.Volume = avc->fid.Fid.Volume;
1300 Fid.Vnode = avc->fid.Fid.Vnode;
1301 Fid.Unique = avc->fid.Fid.Unique;
1302 if (avc->states & CForeign) {
1304 * For a dfs xlator acl we have a special hack so that the
1305 * xlator will distinguish which type of acl will return. So
1306 * we currently use the top 2-bytes (vals 0-4) to tell which
1307 * type of acl to bring back. Horrible hack but this will
1308 * cause the least number of changes to code size and interfaces.
1310 if (Fid.Vnode & 0xc0000000)
1312 Fid.Vnode |= (ainSize << 30);
1314 acl.AFSOpaque_val = aout;
1316 tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1319 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHACL);
1321 code = RXAFS_FetchACL(tconn->id, &Fid, &acl, &OutStatus, &tsync);
1326 } while (afs_Analyze
1327 (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_FETCHACL,
1328 SHARED_LOCK, NULL));
1331 *aoutSize = (acl.AFSOpaque_len == 0 ? 1 : acl.AFSOpaque_len);
1344 AFS_STATCNT(PBogus);
1348 DECL_PIOCTL(PGetFileCell)
1350 register struct cell *tcell;
1352 AFS_STATCNT(PGetFileCell);
1355 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
1358 strcpy(aout, tcell->cellName);
1359 afs_PutCell(tcell, READ_LOCK);
1360 *aoutSize = strlen(aout) + 1;
1364 DECL_PIOCTL(PGetWSCell)
1366 struct cell *tcell = NULL;
1368 AFS_STATCNT(PGetWSCell);
1369 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1370 return EIO; /* Inappropriate ioctl for device */
1372 tcell = afs_GetPrimaryCell(READ_LOCK);
1373 if (!tcell) /* no primary cell? */
1375 strcpy(aout, tcell->cellName);
1376 *aoutSize = strlen(aout) + 1;
1377 afs_PutCell(tcell, READ_LOCK);
1381 DECL_PIOCTL(PGetUserCell)
1383 register afs_int32 i;
1384 register struct unixuser *tu;
1385 register struct cell *tcell;
1387 AFS_STATCNT(PGetUserCell);
1388 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1389 return EIO; /* Inappropriate ioctl for device */
1391 /* return the cell name of the primary cell for this user */
1392 i = UHash(areq->uid);
1393 ObtainWriteLock(&afs_xuser, 224);
1394 for (tu = afs_users[i]; tu; tu = tu->next) {
1395 if (tu->uid == areq->uid && (tu->states & UPrimary)) {
1397 ReleaseWriteLock(&afs_xuser);
1402 tcell = afs_GetCell(tu->cell, READ_LOCK);
1403 afs_PutUser(tu, WRITE_LOCK);
1407 strcpy(aout, tcell->cellName);
1408 afs_PutCell(tcell, READ_LOCK);
1409 *aoutSize = strlen(aout) + 1; /* 1 for the null */
1412 ReleaseWriteLock(&afs_xuser);
1419 DECL_PIOCTL(PSetTokens)
1422 register struct unixuser *tu;
1423 struct ClearToken clear;
1424 register struct cell *tcell;
1427 struct vrequest treq;
1428 afs_int32 flag, set_parent_pag = 0;
1430 AFS_STATCNT(PSetTokens);
1431 if (!afs_resourceinit_flag) {
1434 memcpy((char *)&i, ain, sizeof(afs_int32));
1435 ain += sizeof(afs_int32);
1436 stp = ain; /* remember where the ticket is */
1437 if (i < 0 || i > MAXKTCTICKETLEN)
1438 return EINVAL; /* malloc may fail */
1440 ain += i; /* skip over ticket */
1441 memcpy((char *)&i, ain, sizeof(afs_int32));
1442 ain += sizeof(afs_int32);
1443 if (i != sizeof(struct ClearToken)) {
1446 memcpy((char *)&clear, ain, sizeof(struct ClearToken));
1447 if (clear.AuthHandle == -1)
1448 clear.AuthHandle = 999; /* more rxvab compat stuff */
1449 ain += sizeof(struct ClearToken);
1450 if (ainSize != 2 * sizeof(afs_int32) + stLen + sizeof(struct ClearToken)) {
1451 /* still stuff left? we've got primary flag and cell name. Set these */
1452 memcpy((char *)&flag, ain, sizeof(afs_int32)); /* primary id flag */
1453 ain += sizeof(afs_int32); /* skip id field */
1454 /* rest is cell name, look it up */
1455 /* some versions of gcc appear to need != 0 in order to get this right */
1456 if ((flag & 0x8000) != 0) { /* XXX Use Constant XXX */
1460 tcell = afs_GetCellByName(ain, READ_LOCK);
1464 /* default to primary cell, primary id */
1465 flag = 1; /* primary id */
1466 tcell = afs_GetPrimaryCell(READ_LOCK);
1471 afs_PutCell(tcell, READ_LOCK);
1472 if (set_parent_pag) {
1474 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1475 #if defined(AFS_DARWIN_ENV)
1476 struct proc *p = current_proc(); /* XXX */
1478 struct proc *p = curproc; /* XXX */
1480 uprintf("Process %d (%s) tried to change pags in PSetTokens\n",
1481 p->p_pid, p->p_comm);
1482 if (!setpag(p, acred, -1, &pag, 1)) {
1485 if (!setpag(u.u_procp, acred, -1, &pag, 1)) { /* XXX u.u_procp is a no-op XXX */
1487 if (!setpag(acred, -1, &pag, 1)) {
1490 afs_InitReq(&treq, *acred);
1494 /* now we just set the tokens */
1495 tu = afs_GetUser(areq->uid, i, WRITE_LOCK); /* i has the cell # */
1496 tu->vid = clear.ViceId;
1497 if (tu->stp != NULL) {
1498 afs_osi_Free(tu->stp, tu->stLen);
1500 tu->stp = (char *)afs_osi_Alloc(stLen);
1502 memcpy(tu->stp, stp, stLen);
1505 afs_stats_cmfullperf.authent.TicketUpdates++;
1506 afs_ComputePAGStats();
1507 #endif /* AFS_NOSTATS */
1508 tu->states |= UHasTokens;
1509 tu->states &= ~UTokensBad;
1510 afs_SetPrimary(tu, flag);
1511 tu->tokenTime = osi_Time();
1512 afs_ResetUserConns(tu);
1513 afs_PutUser(tu, WRITE_LOCK);
1528 DECL_PIOCTL(PGetVolumeStatus)
1531 char *offLineMsg = afs_osi_Alloc(256);
1532 char *motd = afs_osi_Alloc(256);
1533 register struct conn *tc;
1534 register afs_int32 code = 0;
1535 struct AFSFetchVolumeStatus volstat;
1537 char *Name, *OfflineMsg, *MOTD;
1540 AFS_STATCNT(PGetVolumeStatus);
1546 OfflineMsg = offLineMsg;
1549 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1551 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS);
1554 RXAFS_GetVolumeStatus(tc->id, avc->fid.Fid.Volume, &volstat,
1555 &Name, &OfflineMsg, &MOTD);
1560 } while (afs_Analyze
1561 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS,
1562 SHARED_LOCK, NULL));
1566 /* Copy all this junk into msg->im_data, keeping track of the lengths. */
1568 memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
1569 cp += sizeof(VolumeStatus);
1570 strcpy(cp, volName);
1571 cp += strlen(volName) + 1;
1572 strcpy(cp, offLineMsg);
1573 cp += strlen(offLineMsg) + 1;
1575 cp += strlen(motd) + 1;
1576 *aoutSize = (cp - aout);
1578 afs_osi_Free(offLineMsg, 256);
1579 afs_osi_Free(motd, 256);
1583 DECL_PIOCTL(PSetVolumeStatus)
1586 char *offLineMsg = afs_osi_Alloc(256);
1587 char *motd = afs_osi_Alloc(256);
1588 register struct conn *tc;
1589 register afs_int32 code = 0;
1590 struct AFSFetchVolumeStatus volstat;
1591 struct AFSStoreVolumeStatus storeStat;
1592 register struct volume *tvp;
1596 AFS_STATCNT(PSetVolumeStatus);
1602 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
1604 if (tvp->states & (VRO | VBackup)) {
1605 afs_PutVolume(tvp, READ_LOCK);
1609 afs_PutVolume(tvp, READ_LOCK);
1614 /* Copy the junk out, using cp as a roving pointer. */
1616 memcpy((char *)&volstat, cp, sizeof(AFSFetchVolumeStatus));
1617 cp += sizeof(AFSFetchVolumeStatus);
1618 if (strlen(cp) >= sizeof(volName)) {
1622 strcpy(volName, cp);
1623 cp += strlen(volName) + 1;
1624 if (strlen(cp) >= sizeof(offLineMsg)) {
1628 strcpy(offLineMsg, cp);
1629 cp += strlen(offLineMsg) + 1;
1630 if (strlen(cp) >= sizeof(motd)) {
1636 if (volstat.MinQuota != -1) {
1637 storeStat.MinQuota = volstat.MinQuota;
1638 storeStat.Mask |= AFS_SETMINQUOTA;
1640 if (volstat.MaxQuota != -1) {
1641 storeStat.MaxQuota = volstat.MaxQuota;
1642 storeStat.Mask |= AFS_SETMAXQUOTA;
1645 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1647 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS);
1650 RXAFS_SetVolumeStatus(tc->id, avc->fid.Fid.Volume, &storeStat,
1651 volName, offLineMsg, motd);
1656 } while (afs_Analyze
1657 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS,
1658 SHARED_LOCK, NULL));
1662 /* we are sending parms back to make compat. with prev system. should
1663 * change interface later to not ask for current status, just set new status */
1665 memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
1666 cp += sizeof(VolumeStatus);
1667 strcpy(cp, volName);
1668 cp += strlen(volName) + 1;
1669 strcpy(cp, offLineMsg);
1670 cp += strlen(offLineMsg) + 1;
1672 cp += strlen(motd) + 1;
1673 *aoutSize = cp - aout;
1675 afs_osi_Free(offLineMsg, 256);
1676 afs_osi_Free(motd, 256);
1682 AFS_STATCNT(PFlush);
1685 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
1686 afs_BozonLock(&avc->pvnLock, avc); /* Since afs_TryToSmush will do a pvn_vptrunc */
1688 ObtainWriteLock(&avc->lock, 225);
1689 ObtainWriteLock(&afs_xcbhash, 456);
1690 afs_DequeueCallback(avc);
1691 avc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
1692 ReleaseWriteLock(&afs_xcbhash);
1693 /* now find the disk cache entries */
1694 afs_TryToSmush(avc, *acred, 1);
1695 osi_dnlc_purgedp(avc);
1696 afs_symhint_inval(avc);
1697 if (avc->linkData && !(avc->states & CCore)) {
1698 afs_osi_Free(avc->linkData, strlen(avc->linkData) + 1);
1699 avc->linkData = NULL;
1701 ReleaseWriteLock(&avc->lock);
1702 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
1703 afs_BozonUnlock(&avc->pvnLock, avc);
1708 DECL_PIOCTL(PNewStatMount)
1710 register afs_int32 code;
1711 register struct vcache *tvc;
1712 register struct dcache *tdc;
1713 struct VenusFid tfid;
1715 struct sysname_info sysState;
1716 afs_size_t offset, len;
1718 AFS_STATCNT(PNewStatMount);
1721 code = afs_VerifyVCache(avc, areq);
1724 if (vType(avc) != VDIR) {
1727 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
1730 Check_AtSys(avc, ain, &sysState, areq);
1731 ObtainReadLock(&tdc->lock);
1733 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
1734 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
1735 ReleaseReadLock(&tdc->lock);
1736 afs_PutDCache(tdc); /* we're done with the data */
1737 bufp = sysState.name;
1741 tfid.Cell = avc->fid.Cell;
1742 tfid.Fid.Volume = avc->fid.Fid.Volume;
1743 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
1744 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
1746 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
1752 if (tvc->mvstat != 1) {
1757 ObtainWriteLock(&tvc->lock, 226);
1758 code = afs_HandleLink(tvc, areq);
1760 if (tvc->linkData) {
1761 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
1764 /* we have the data */
1765 strcpy(aout, tvc->linkData);
1766 *aoutSize = strlen(tvc->linkData) + 1;
1771 ReleaseWriteLock(&tvc->lock);
1774 if (sysState.allocked)
1775 osi_FreeLargeSpace(bufp);
1779 DECL_PIOCTL(PGetTokens)
1781 register struct cell *tcell;
1782 register afs_int32 i;
1783 register struct unixuser *tu;
1788 AFS_STATCNT(PGetTokens);
1789 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1790 return EIO; /* Inappropriate ioctl for device */
1792 /* weird interface. If input parameter is present, it is an integer and
1793 * we're supposed to return the parm'th tokens for this unix uid.
1794 * If not present, we just return tokens for cell 1.
1795 * If counter out of bounds, return EDOM.
1796 * If no tokens for the particular cell, return ENOTCONN.
1797 * Also, if this mysterious parm is present, we return, along with the
1798 * tokens, the primary cell indicator (an afs_int32 0) and the cell name
1799 * at the end, in that order.
1801 if ((newStyle = (ainSize > 0))) {
1802 memcpy((char *)&iterator, ain, sizeof(afs_int32));
1804 i = UHash(areq->uid);
1805 ObtainReadLock(&afs_xuser);
1806 for (tu = afs_users[i]; tu; tu = tu->next) {
1808 if (tu->uid == areq->uid && (tu->states & UHasTokens)) {
1809 if (iterator-- == 0)
1810 break; /* are we done yet? */
1813 if (tu->uid == areq->uid && afs_IsPrimaryCellNum(tu->cell))
1819 * No need to hold a read lock on each user entry
1823 ReleaseReadLock(&afs_xuser);
1828 if (((tu->states & UHasTokens) == 0)
1829 || (tu->ct.EndTimestamp < osi_Time())) {
1830 tu->states |= (UTokensBad | UNeedsReset);
1831 afs_PutUser(tu, READ_LOCK);
1834 /* use iterator for temp */
1836 iterator = tu->stLen; /* for compat, we try to return 56 byte tix if they fit */
1838 iterator = 56; /* # of bytes we're returning */
1839 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1840 cp += sizeof(afs_int32);
1841 memcpy(cp, tu->stp, tu->stLen); /* copy out st */
1843 iterator = sizeof(struct ClearToken);
1844 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1845 cp += sizeof(afs_int32);
1846 memcpy(cp, (char *)&tu->ct, sizeof(struct ClearToken));
1847 cp += sizeof(struct ClearToken);
1849 /* put out primary id and cell name, too */
1850 iterator = (tu->states & UPrimary ? 1 : 0);
1851 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1852 cp += sizeof(afs_int32);
1853 tcell = afs_GetCell(tu->cell, READ_LOCK);
1855 strcpy(cp, tcell->cellName);
1856 cp += strlen(tcell->cellName) + 1;
1857 afs_PutCell(tcell, READ_LOCK);
1861 *aoutSize = cp - aout;
1862 afs_PutUser(tu, READ_LOCK);
1868 register afs_int32 i;
1869 register struct unixuser *tu;
1871 AFS_STATCNT(PUnlog);
1872 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1873 return EIO; /* Inappropriate ioctl for device */
1875 i = UHash(areq->uid);
1876 ObtainWriteLock(&afs_xuser, 227);
1877 for (tu = afs_users[i]; tu; tu = tu->next) {
1878 if (tu->uid == areq->uid) {
1880 tu->states &= ~UHasTokens;
1881 /* security is not having to say you're sorry */
1882 memset((char *)&tu->ct, 0, sizeof(struct ClearToken));
1884 ReleaseWriteLock(&afs_xuser);
1885 /* We have to drop the lock over the call to afs_ResetUserConns, since
1886 * it obtains the afs_xvcache lock. We could also keep the lock, and
1887 * modify ResetUserConns to take parm saying we obtained the lock
1888 * already, but that is overkill. By keeping the "tu" pointer
1889 * held over the released lock, we guarantee that we won't lose our
1890 * place, and that we'll pass over every user conn that existed when
1891 * we began this call.
1893 afs_ResetUserConns(tu);
1895 ObtainWriteLock(&afs_xuser, 228);
1897 /* set the expire times to 0, causes
1898 * afs_GCUserData to remove this entry
1900 tu->ct.EndTimestamp = 0;
1902 #endif /* UKERNEL */
1905 ReleaseWriteLock(&afs_xuser);
1909 DECL_PIOCTL(PMariner)
1911 afs_int32 newHostAddr;
1912 afs_int32 oldHostAddr;
1914 AFS_STATCNT(PMariner);
1916 memcpy((char *)&oldHostAddr, (char *)&afs_marinerHost,
1919 oldHostAddr = 0xffffffff; /* disabled */
1921 memcpy((char *)&newHostAddr, ain, sizeof(afs_int32));
1922 if (newHostAddr == 0xffffffff) {
1923 /* disable mariner operations */
1925 } else if (newHostAddr) {
1927 afs_marinerHost = newHostAddr;
1929 memcpy(aout, (char *)&oldHostAddr, sizeof(afs_int32));
1930 *aoutSize = sizeof(afs_int32);
1934 DECL_PIOCTL(PCheckServers)
1936 register char *cp = 0;
1938 register struct server *ts;
1939 afs_int32 temp, *lp = (afs_int32 *) ain, havecell = 0;
1941 struct chservinfo *pcheck;
1943 AFS_STATCNT(PCheckServers);
1945 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1946 return EIO; /* Inappropriate ioctl for device */
1948 if (*lp == 0x12345678) { /* For afs3.3 version */
1949 pcheck = (struct chservinfo *)ain;
1950 if (pcheck->tinterval >= 0) {
1952 memcpy(cp, (char *)&PROBE_INTERVAL, sizeof(afs_int32));
1953 *aoutSize = sizeof(afs_int32);
1954 if (pcheck->tinterval > 0) {
1955 if (!afs_osi_suser(*acred))
1957 PROBE_INTERVAL = pcheck->tinterval;
1963 temp = pcheck->tflags;
1964 cp = pcheck->tbuffer;
1965 } else { /* For pre afs3.3 versions */
1966 memcpy((char *)&temp, ain, sizeof(afs_int32));
1967 cp = ain + sizeof(afs_int32);
1968 if (ainSize > sizeof(afs_int32))
1973 * 1: fast check, don't contact servers.
1974 * 2: local cell only.
1977 /* have cell name, too */
1978 cellp = afs_GetCellByName(cp, READ_LOCK);
1983 if (!cellp && (temp & 2)) {
1984 /* use local cell */
1985 cellp = afs_GetPrimaryCell(READ_LOCK);
1987 if (!(temp & 1)) { /* if not fast, call server checker routine */
1988 afs_CheckServers(1, cellp); /* check down servers */
1989 afs_CheckServers(0, cellp); /* check up servers */
1991 /* now return the current down server list */
1993 ObtainReadLock(&afs_xserver);
1994 for (i = 0; i < NSERVERS; i++) {
1995 for (ts = afs_servers[i]; ts; ts = ts->next) {
1996 if (cellp && ts->cell != cellp)
1997 continue; /* cell spec'd and wrong */
1998 if ((ts->flags & SRVR_ISDOWN)
1999 && ts->addr->sa_portal != ts->cell->vlport) {
2000 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
2001 cp += sizeof(afs_int32);
2005 ReleaseReadLock(&afs_xserver);
2007 afs_PutCell(cellp, READ_LOCK);
2008 *aoutSize = cp - aout;
2012 DECL_PIOCTL(PCheckVolNames)
2014 AFS_STATCNT(PCheckVolNames);
2015 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2016 return EIO; /* Inappropriate ioctl for device */
2018 afs_CheckRootVolume();
2019 afs_CheckVolumeNames(AFS_VOLCHECK_FORCE | AFS_VOLCHECK_EXPIRED |
2020 AFS_VOLCHECK_BUSY | AFS_VOLCHECK_MTPTS);
2024 DECL_PIOCTL(PCheckAuth)
2029 struct unixuser *tu;
2032 AFS_STATCNT(PCheckAuth);
2033 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2034 return EIO; /* Inappropriate ioctl for device */
2037 tu = afs_GetUser(areq->uid, 1, READ_LOCK); /* check local cell authentication */
2041 /* we have a user */
2042 ObtainReadLock(&afs_xsrvAddr);
2043 ObtainReadLock(&afs_xconn);
2045 /* any tokens set? */
2046 if ((tu->states & UHasTokens) == 0)
2048 /* all connections in cell 1 working? */
2049 for (i = 0; i < NSERVERS; i++) {
2050 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2051 for (tc = sa->conns; tc; tc = tc->next) {
2052 if (tc->user == tu && (tu->states & UTokensBad))
2057 ReleaseReadLock(&afs_xsrvAddr);
2058 ReleaseReadLock(&afs_xconn);
2059 afs_PutUser(tu, READ_LOCK);
2061 memcpy(aout, (char *)&retValue, sizeof(afs_int32));
2062 *aoutSize = sizeof(afs_int32);
2067 Prefetch(char *apath, struct afs_ioctl *adata, int afollow,
2068 struct AFS_UCRED *acred)
2071 register afs_int32 code;
2072 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2078 AFS_STATCNT(Prefetch);
2081 tp = osi_AllocLargeSpace(1024);
2082 AFS_COPYINSTR(apath, tp, 1024, &bufferSize, code);
2084 osi_FreeLargeSpace(tp);
2087 if (afs_BBusy()) { /* do this as late as possible */
2088 osi_FreeLargeSpace(tp);
2089 return EWOULDBLOCK; /* pretty close */
2091 afs_BQueue(BOP_PATH, (struct vcache *)0, 0, 0, acred, (afs_size_t) 0,
2092 (afs_size_t) 0, tp);
2096 DECL_PIOCTL(PFindVolume)
2098 register struct volume *tvp;
2099 register struct server *ts;
2100 register afs_int32 i;
2103 AFS_STATCNT(PFindVolume);
2106 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
2109 for (i = 0; i < MAXHOSTS; i++) {
2110 ts = tvp->serverHost[i];
2113 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
2114 cp += sizeof(afs_int32);
2117 /* still room for terminating NULL, add it on */
2118 ainSize = 0; /* reuse vbl */
2119 memcpy(cp, (char *)&ainSize, sizeof(afs_int32));
2120 cp += sizeof(afs_int32);
2122 *aoutSize = cp - aout;
2123 afs_PutVolume(tvp, READ_LOCK);
2129 DECL_PIOCTL(PViceAccess)
2131 register afs_int32 code;
2134 AFS_STATCNT(PViceAccess);
2137 code = afs_VerifyVCache(avc, areq);
2140 memcpy((char *)&temp, ain, sizeof(afs_int32));
2141 code = afs_AccessOK(avc, temp, areq, CHECK_MODE_BITS);
2148 DECL_PIOCTL(PSetCacheSize)
2153 AFS_STATCNT(PSetCacheSize);
2154 if (!afs_osi_suser(*acred))
2156 /* too many things are setup initially in mem cache version */
2157 if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
2159 memcpy((char *)&newValue, ain, sizeof(afs_int32));
2161 afs_cacheBlocks = afs_stats_cmperf.cacheBlocksOrig;
2163 if (newValue < afs_min_cache)
2164 afs_cacheBlocks = afs_min_cache;
2166 afs_cacheBlocks = newValue;
2168 afs_stats_cmperf.cacheBlocksTotal = afs_cacheBlocks;
2169 afs_ComputeCacheParms(); /* recompute basic cache parameters */
2170 afs_MaybeWakeupTruncateDaemon();
2171 while (waitcnt++ < 100 && afs_cacheBlocks < afs_blocksUsed) {
2172 afs_osi_Wait(1000, 0, 0);
2173 afs_MaybeWakeupTruncateDaemon();
2178 #define MAXGCSTATS 16
2179 DECL_PIOCTL(PGetCacheSize)
2181 afs_int32 results[MAXGCSTATS];
2183 AFS_STATCNT(PGetCacheSize);
2184 memset((char *)results, 0, sizeof(results));
2185 results[0] = afs_cacheBlocks;
2186 results[1] = afs_blocksUsed;
2187 memcpy(aout, (char *)results, sizeof(results));
2188 *aoutSize = sizeof(results);
2192 DECL_PIOCTL(PRemoveCallBack)
2194 register struct conn *tc;
2195 register afs_int32 code = 0;
2196 struct AFSCallBack CallBacks_Array[1];
2197 struct AFSCBFids theFids;
2198 struct AFSCBs theCBs;
2201 AFS_STATCNT(PRemoveCallBack);
2204 if (avc->states & CRO)
2205 return 0; /* read-only-ness can't change */
2206 ObtainWriteLock(&avc->lock, 229);
2207 theFids.AFSCBFids_len = 1;
2208 theCBs.AFSCBs_len = 1;
2209 theFids.AFSCBFids_val = (struct AFSFid *)&avc->fid.Fid;
2210 theCBs.AFSCBs_val = CallBacks_Array;
2211 CallBacks_Array[0].CallBackType = CB_DROPPED;
2212 if (avc->callback) {
2214 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2216 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
2218 code = RXAFS_GiveUpCallBacks(tc->id, &theFids, &theCBs);
2222 /* don't set code on failure since we wouldn't use it */
2223 } while (afs_Analyze
2224 (tc, code, &avc->fid, areq,
2225 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK, NULL));
2227 ObtainWriteLock(&afs_xcbhash, 457);
2228 afs_DequeueCallback(avc);
2230 avc->states &= ~(CStatd | CUnique);
2231 ReleaseWriteLock(&afs_xcbhash);
2232 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
2233 osi_dnlc_purgedp(avc);
2235 ReleaseWriteLock(&avc->lock);
2239 DECL_PIOCTL(PNewCell)
2241 /* create a new cell */
2242 afs_int32 cellHosts[MAXCELLHOSTS], *lp, magic = 0;
2243 char *newcell = 0, *linkedcell = 0, *tp = ain;
2244 register afs_int32 code, linkedstate = 0, ls;
2245 u_short fsport = 0, vlport = 0;
2248 AFS_STATCNT(PNewCell);
2249 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2250 return EIO; /* Inappropriate ioctl for device */
2252 if (!afs_osi_suser(*acred))
2255 memcpy((char *)&magic, tp, sizeof(afs_int32));
2256 tp += sizeof(afs_int32);
2257 if (magic != 0x12345678)
2260 /* A 3.4 fs newcell command will pass an array of MAXCELLHOSTS
2261 * server addresses while the 3.5 fs newcell command passes
2262 * MAXHOSTS. To figure out which is which, check if the cellname
2265 newcell = tp + (MAXCELLHOSTS + 3) * sizeof(afs_int32);
2266 scount = ((newcell[0] != '\0') ? MAXCELLHOSTS : MAXHOSTS);
2268 /* MAXCELLHOSTS (=8) is less than MAXHOSTS (=13) */
2269 memcpy((char *)cellHosts, tp, MAXCELLHOSTS * sizeof(afs_int32));
2270 tp += (scount * sizeof(afs_int32));
2272 lp = (afs_int32 *) tp;
2276 fsport = 0; /* Privileged ports not allowed */
2278 vlport = 0; /* Privileged ports not allowed */
2279 tp += (3 * sizeof(afs_int32));
2281 if ((ls = *lp) & 1) {
2282 linkedcell = tp + strlen(newcell) + 1;
2283 linkedstate |= CLinkedCell;
2286 linkedstate |= CNoSUID; /* setuid is disabled by default for fs newcell */
2288 afs_NewCell(newcell, cellHosts, linkedstate, linkedcell, fsport,
2293 DECL_PIOCTL(PNewAlias)
2295 /* create a new cell alias */
2297 register afs_int32 code;
2298 char *realName, *aliasName;
2300 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2301 return EIO; /* Inappropriate ioctl for device */
2303 if (!afs_osi_suser(*acred))
2307 tp += strlen(aliasName) + 1;
2310 code = afs_NewCellAlias(aliasName, realName);
2315 DECL_PIOCTL(PListCells)
2317 afs_int32 whichCell;
2318 register struct cell *tcell = 0;
2319 register afs_int32 i;
2320 register char *cp, *tp = ain;
2322 AFS_STATCNT(PListCells);
2323 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2324 return EIO; /* Inappropriate ioctl for device */
2326 memcpy((char *)&whichCell, tp, sizeof(afs_int32));
2327 tp += sizeof(afs_int32);
2328 tcell = afs_GetCellByIndex(whichCell, READ_LOCK);
2331 memset(cp, 0, MAXCELLHOSTS * sizeof(afs_int32));
2332 for (i = 0; i < MAXCELLHOSTS; i++) {
2333 if (tcell->cellHosts[i] == 0)
2335 memcpy(cp, (char *)&tcell->cellHosts[i]->addr->sa_ip,
2337 cp += sizeof(afs_int32);
2339 cp = aout + MAXCELLHOSTS * sizeof(afs_int32);
2340 strcpy(cp, tcell->cellName);
2341 cp += strlen(tcell->cellName) + 1;
2342 *aoutSize = cp - aout;
2343 afs_PutCell(tcell, READ_LOCK);
2351 DECL_PIOCTL(PListAliases)
2353 afs_int32 whichAlias;
2354 register struct cell_alias *tcalias = 0;
2355 register char *cp, *tp = ain;
2357 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2358 return EIO; /* Inappropriate ioctl for device */
2359 if (ainSize < sizeof(afs_int32))
2362 memcpy((char *)&whichAlias, tp, sizeof(afs_int32));
2363 tp += sizeof(afs_int32);
2365 tcalias = afs_GetCellAlias(whichAlias);
2368 strcpy(cp, tcalias->alias);
2369 cp += strlen(tcalias->alias) + 1;
2370 strcpy(cp, tcalias->cell);
2371 cp += strlen(tcalias->cell) + 1;
2372 *aoutSize = cp - aout;
2373 afs_PutCellAlias(tcalias);
2381 DECL_PIOCTL(PRemoveMount)
2383 register afs_int32 code;
2385 struct sysname_info sysState;
2386 afs_size_t offset, len;
2387 register struct conn *tc;
2388 register struct dcache *tdc;
2389 register struct vcache *tvc;
2390 struct AFSFetchStatus OutDirStatus;
2391 struct VenusFid tfid;
2392 struct AFSVolSync tsync;
2396 /* "ain" is the name of the file in this dir to remove */
2398 AFS_STATCNT(PRemoveMount);
2401 code = afs_VerifyVCache(avc, areq);
2404 if (vType(avc) != VDIR)
2407 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1); /* test for error below */
2410 Check_AtSys(avc, ain, &sysState, areq);
2411 ObtainReadLock(&tdc->lock);
2413 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
2414 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
2415 ReleaseReadLock(&tdc->lock);
2416 bufp = sysState.name;
2421 tfid.Cell = avc->fid.Cell;
2422 tfid.Fid.Volume = avc->fid.Fid.Volume;
2423 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
2424 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
2426 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
2433 if (tvc->mvstat != 1) {
2439 ObtainWriteLock(&tvc->lock, 230);
2440 code = afs_HandleLink(tvc, areq);
2442 if (tvc->linkData) {
2443 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
2448 ReleaseWriteLock(&tvc->lock);
2449 osi_dnlc_purgedp(tvc);
2455 ObtainWriteLock(&avc->lock, 231);
2456 osi_dnlc_remove(avc, bufp, tvc);
2458 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2460 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE);
2463 RXAFS_RemoveFile(tc->id, (struct AFSFid *)&avc->fid.Fid, bufp,
2464 &OutDirStatus, &tsync);
2469 } while (afs_Analyze
2470 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_REMOVEFILE,
2471 SHARED_LOCK, NULL));
2476 ReleaseWriteLock(&avc->lock);
2480 /* we have the thing in the cache */
2481 ObtainWriteLock(&tdc->lock, 661);
2482 if (afs_LocalHero(avc, tdc, &OutDirStatus, 1)) {
2483 /* we can do it locally */
2484 code = afs_dir_Delete(tdc, bufp);
2486 ZapDCE(tdc); /* surprise error -- invalid value */
2490 ReleaseWriteLock(&tdc->lock);
2491 afs_PutDCache(tdc); /* drop ref count */
2493 avc->states &= ~CUnique; /* For the dfs xlator */
2494 ReleaseWriteLock(&avc->lock);
2497 if (sysState.allocked)
2498 osi_FreeLargeSpace(bufp);
2502 DECL_PIOCTL(PVenusLogging)
2504 return EINVAL; /* OBSOLETE */
2507 DECL_PIOCTL(PGetCellStatus)
2509 register struct cell *tcell;
2512 AFS_STATCNT(PGetCellStatus);
2513 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2514 return EIO; /* Inappropriate ioctl for device */
2516 tcell = afs_GetCellByName(ain, READ_LOCK);
2519 temp = tcell->states;
2520 afs_PutCell(tcell, READ_LOCK);
2521 memcpy(aout, (char *)&temp, sizeof(afs_int32));
2522 *aoutSize = sizeof(afs_int32);
2526 DECL_PIOCTL(PSetCellStatus)
2528 register struct cell *tcell;
2531 if (!afs_osi_suser(*acred))
2533 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2534 return EIO; /* Inappropriate ioctl for device */
2536 tcell = afs_GetCellByName(ain + 2 * sizeof(afs_int32), WRITE_LOCK);
2539 memcpy((char *)&temp, ain, sizeof(afs_int32));
2541 tcell->states |= CNoSUID;
2543 tcell->states &= ~CNoSUID;
2544 afs_PutCell(tcell, WRITE_LOCK);
2548 DECL_PIOCTL(PFlushVolumeData)
2550 register afs_int32 i;
2551 register struct dcache *tdc;
2552 register struct vcache *tvc;
2553 register struct volume *tv;
2554 afs_int32 cell, volume;
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.
2569 ObtainReadLock(&afs_xvcache);
2570 for (i = 0; i < VCSIZE; i++) {
2571 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2572 if (tvc->fid.Fid.Volume == volume && tvc->fid.Cell == cell) {
2573 #if defined(AFS_SGI_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
2574 VN_HOLD(AFSTOV(tvc));
2576 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2582 ReleaseReadLock(&afs_xvcache);
2583 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
2584 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
2586 ObtainWriteLock(&tvc->lock, 232);
2588 ObtainWriteLock(&afs_xcbhash, 458);
2589 afs_DequeueCallback(tvc);
2590 tvc->states &= ~(CStatd | CDirty);
2591 ReleaseWriteLock(&afs_xcbhash);
2592 if (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
2593 osi_dnlc_purgedp(tvc);
2594 afs_TryToSmush(tvc, *acred, 1);
2595 ReleaseWriteLock(&tvc->lock);
2596 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
2597 afs_BozonUnlock(&tvc->pvnLock, tvc);
2599 ObtainReadLock(&afs_xvcache);
2600 /* our tvc ptr is still good until now */
2605 ReleaseReadLock(&afs_xvcache);
2608 MObtainWriteLock(&afs_xdcache, 328); /* needed if you're going to flush any stuff */
2609 for (i = 0; i < afs_cacheFiles; i++) {
2610 if (!(afs_indexFlags[i] & IFEverUsed))
2611 continue; /* never had any data */
2612 tdc = afs_GetDSlot(i, NULL);
2613 if (tdc->refCount <= 1) { /* too high, in use by running sys call */
2614 ReleaseReadLock(&tdc->tlock);
2615 if (tdc->f.fid.Fid.Volume == volume && tdc->f.fid.Cell == cell) {
2616 if (!(afs_indexFlags[i] & IFDataMod)) {
2617 /* if the file is modified, but has a ref cnt of only 1, then
2618 * someone probably has the file open and is writing into it.
2619 * Better to skip flushing such a file, it will be brought back
2620 * immediately on the next write anyway.
2622 * If we *must* flush, then this code has to be rearranged to call
2623 * afs_storeAllSegments() first */
2624 afs_FlushDCache(tdc);
2628 ReleaseReadLock(&tdc->tlock);
2630 afs_PutDCache(tdc); /* bumped by getdslot */
2632 MReleaseWriteLock(&afs_xdcache);
2634 ObtainReadLock(&afs_xvolume);
2635 for (i = 0; i < NVOLS; i++) {
2636 for (tv = afs_volumes[i]; tv; tv = tv->next) {
2637 if (tv->volume == volume) {
2638 afs_ResetVolumeInfo(tv);
2643 ReleaseReadLock(&afs_xvolume);
2645 /* probably, a user is doing this, probably, because things are screwed up.
2646 * maybe it's the dnlc's fault? */
2653 DECL_PIOCTL(PGetVnodeXStatus)
2655 register afs_int32 code;
2656 struct vcxstat stat;
2659 /* AFS_STATCNT(PGetVnodeXStatus); */
2662 code = afs_VerifyVCache(avc, areq);
2665 if (vType(avc) == VDIR)
2666 mode = PRSFS_LOOKUP;
2669 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
2671 stat.fid = avc->fid;
2672 hset32(stat.DataVersion, hgetlo(avc->m.DataVersion));
2673 stat.lock = avc->lock;
2674 stat.parentVnode = avc->parentVnode;
2675 stat.parentUnique = avc->parentUnique;
2676 hset(stat.flushDV, avc->flushDV);
2677 hset(stat.mapDV, avc->mapDV);
2678 stat.truncPos = avc->truncPos;
2679 { /* just grab the first two - won't break anything... */
2680 struct axscache *ac;
2682 for (i = 0, ac = avc->Access; ac && i < CPSIZE; i++, ac = ac->next) {
2683 stat.randomUid[i] = ac->uid;
2684 stat.randomAccess[i] = ac->axess;
2687 stat.callback = afs_data_pointer_to_int32(avc->callback);
2688 stat.cbExpires = avc->cbExpires;
2689 stat.anyAccess = avc->anyAccess;
2690 stat.opens = avc->opens;
2691 stat.execsOrWriters = avc->execsOrWriters;
2692 stat.flockCount = avc->flockCount;
2693 stat.mvstat = avc->mvstat;
2694 stat.states = avc->states;
2695 memcpy(aout, (char *)&stat, sizeof(struct vcxstat));
2696 *aoutSize = sizeof(struct vcxstat);
2701 /* We require root for local sysname changes, but not for remote */
2702 /* (since we don't really believe remote uids anyway) */
2703 /* outname[] shouldn't really be needed- this is left as an excercise */
2704 /* for the reader. */
2705 DECL_PIOCTL(PSetSysName)
2707 char *cp, *cp2 = NULL, inname[MAXSYSNAME], outname[MAXSYSNAME];
2708 int setsysname, foundname = 0;
2709 register struct afs_exporter *exporter;
2710 register struct unixuser *au;
2711 register afs_int32 pag, error;
2712 int t, count, num = 0;
2713 char **sysnamelist[MAXSYSNAME];
2715 AFS_STATCNT(PSetSysName);
2716 if (!afs_globalVFS) {
2717 /* Afsd is NOT running; disable it */
2718 #if defined(KERNEL_HAVE_UERROR)
2719 return (setuerror(EINVAL), EINVAL);
2724 memset(inname, 0, MAXSYSNAME);
2725 memcpy((char *)&setsysname, ain, sizeof(afs_int32));
2726 ain += sizeof(afs_int32);
2730 if (setsysname < 0 || setsysname > MAXNUMSYSNAMES)
2733 for (cp = ain, count = 0; count < setsysname; count++) {
2734 /* won't go past end of ain since maxsysname*num < ain length */
2736 if (t >= MAXSYSNAME || t <= 0)
2738 /* check for names that can shoot us in the foot */
2739 if (*cp == '.' && (cp[1] == 0 || (cp[1] == '.' && cp[2] == 0)))
2745 /* inname gets first entry in case we're being a translator */
2747 memcpy(inname, ain, t + 1); /* include terminating null */
2751 if ((*acred)->cr_gid == RMTUSER_REQ) { /* Handles all exporters */
2752 pag = PagInCred(*acred);
2754 return EINVAL; /* Better than panicing */
2756 if (!(au = afs_FindUser(pag, -1, READ_LOCK))) {
2757 return EINVAL; /* Better than panicing */
2759 if (!(exporter = au->exporter)) {
2760 afs_PutUser(au, READ_LOCK);
2761 return EINVAL; /* Better than panicing */
2763 error = EXP_SYSNAME(exporter, (setsysname ? cp2 : NULL), sysnamelist,
2766 if (error == ENODEV)
2767 foundname = 0; /* sysname not set yet! */
2769 afs_PutUser(au, READ_LOCK);
2774 strcpy(outname, (*sysnamelist)[0]);
2776 afs_PutUser(au, READ_LOCK);
2778 /* Not xlating, so local case */
2780 osi_Panic("PSetSysName: !afs_sysname\n");
2781 if (!setsysname) { /* user just wants the info */
2782 strcpy(outname, afs_sysname);
2783 foundname = afs_sysnamecount;
2784 *sysnamelist = afs_sysnamelist;
2785 } else { /* Local guy; only root can change sysname */
2786 if (!afs_osi_suser(*acred))
2789 /* clear @sys entries from the dnlc, once afs_lookup can
2790 * do lookups of @sys entries and thinks it can trust them */
2791 /* privs ok, store the entry, ... */
2792 strcpy(afs_sysname, inname);
2793 if (setsysname > 1) { /* ... or list */
2795 for (count = 1; count < setsysname; ++count) {
2796 if (!afs_sysnamelist[count])
2798 ("PSetSysName: no afs_sysnamelist entry to write\n");
2800 memcpy(afs_sysnamelist[count], cp, t + 1); /* include null */
2804 afs_sysnamecount = setsysname;
2808 cp = aout; /* not changing so report back the count and ... */
2809 memcpy(cp, (char *)&foundname, sizeof(afs_int32));
2810 cp += sizeof(afs_int32);
2812 strcpy(cp, outname); /* ... the entry, ... */
2813 cp += strlen(outname) + 1;
2814 for (count = 1; count < foundname; ++count) { /* ... or list. */
2815 if (!(*sysnamelist)[count])
2817 ("PSetSysName: no afs_sysnamelist entry to read\n");
2818 t = strlen((*sysnamelist)[count]);
2819 if (t >= MAXSYSNAME)
2820 osi_Panic("PSetSysName: sysname entry garbled\n");
2821 strcpy(cp, (*sysnamelist)[count]);
2825 *aoutSize = cp - aout;
2830 /* sequential search through the list of touched cells is not a good
2831 * long-term solution here. For small n, though, it should be just
2832 * fine. Should consider special-casing the local cell for large n.
2833 * Likewise for PSetSPrefs.
2835 * s - number of ids in array l[] -- NOT index of last id
2836 * l - array of cell ids which have volumes that need to be sorted
2837 * vlonly - sort vl servers or file servers?
2840 ReSortCells_cb(struct cell *cell, void *arg)
2842 afs_int32 *p = (afs_int32 *) arg;
2843 afs_int32 *l = p + 1;
2846 for (i = 0; i < s; i++) {
2847 if (l[i] == cell->cellNum) {
2848 ObtainWriteLock(&cell->lock, 690);
2849 afs_SortServers(cell->cellHosts, MAXCELLHOSTS);
2850 ReleaseWriteLock(&cell->lock);
2858 ReSortCells(int s, afs_int32 * l, int vlonly)
2866 p = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * (s + 1));
2868 memcpy(p + 1, l, s * sizeof(afs_int32));
2869 afs_TraverseCells(&ReSortCells_cb, p);
2870 afs_osi_Free(p, sizeof(afs_int32) * (s + 1));
2874 ObtainReadLock(&afs_xvolume);
2875 for (i = 0; i < NVOLS; i++) {
2876 for (j = afs_volumes[i]; j; j = j->next) {
2877 for (k = 0; k < s; k++)
2878 if (j->cell == l[k]) {
2879 ObtainWriteLock(&j->lock, 233);
2880 afs_SortServers(j->serverHost, MAXHOSTS);
2881 ReleaseWriteLock(&j->lock);
2886 ReleaseReadLock(&afs_xvolume);
2890 static int debugsetsp = 0;
2892 afs_setsprefs(sp, num, vlonly)
2895 unsigned int vlonly;
2898 int i, j, k, matches, touchedSize;
2899 struct server *srvr = NULL;
2900 afs_int32 touched[34];
2904 for (k = 0; k < num; sp++, k++) {
2906 printf("sp host=%x, rank=%d\n", sp->host.s_addr, sp->rank);
2909 ObtainReadLock(&afs_xserver);
2911 i = SHash(sp->host.s_addr);
2912 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2913 if (sa->sa_ip == sp->host.s_addr) {
2915 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
2916 || (sa->sa_portal == AFS_FSPORT);
2917 if ((!vlonly && isfs) || (vlonly && !isfs)) {
2924 if (sa && matches) { /* found one! */
2926 printf("sa ip=%x, ip_rank=%d\n", sa->sa_ip, sa->sa_iprank);
2928 sa->sa_iprank = sp->rank + afs_randomMod15();
2929 afs_SortOneServer(sa->server);
2932 /* if we don't know yet what cell it's in, this is moot */
2933 for (j = touchedSize - 1;
2934 j >= 0 && touched[j] != srvr->cell->cellNum; j--)
2935 /* is it in our list of touched cells ? */ ;
2936 if (j < 0) { /* no, it's not */
2937 touched[touchedSize++] = srvr->cell->cellNum;
2938 if (touchedSize >= 32) { /* watch for ovrflow */
2939 ReleaseReadLock(&afs_xserver);
2940 ReSortCells(touchedSize, touched, vlonly);
2942 ObtainReadLock(&afs_xserver);
2948 ReleaseReadLock(&afs_xserver);
2949 /* if we didn't find one, start to create one. */
2950 /* Note that it doesn't have a cell yet... */
2952 afs_uint32 temp = sp->host.s_addr;
2954 afs_GetServer(&temp, 1, 0, (vlonly ? AFS_VLPORT : AFS_FSPORT),
2955 WRITE_LOCK, (afsUUID *) 0, 0);
2956 srvr->addr->sa_iprank = sp->rank + afs_randomMod15();
2957 afs_PutServer(srvr, WRITE_LOCK);
2959 } /* for all cited preferences */
2961 ReSortCells(touchedSize, touched, vlonly);
2965 /* Note that this may only be performed by the local root user.
2967 DECL_PIOCTL(PSetSPrefs)
2969 struct setspref *ssp;
2970 AFS_STATCNT(PSetSPrefs);
2972 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2973 return EIO; /* Inappropriate ioctl for device */
2975 if (!afs_osi_suser(*acred))
2978 if (ainSize < sizeof(struct setspref))
2981 ssp = (struct setspref *)ain;
2982 if (ainSize < sizeof(struct spref) * ssp->num_servers)
2985 afs_setsprefs(&(ssp->servers[0]), ssp->num_servers,
2986 (ssp->flags & DBservers));
2990 DECL_PIOCTL(PSetSPrefs33)
2993 AFS_STATCNT(PSetSPrefs);
2994 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2995 return EIO; /* Inappropriate ioctl for device */
2998 if (!afs_osi_suser(*acred))
3001 sp = (struct spref *)ain;
3002 afs_setsprefs(sp, ainSize / (sizeof(struct spref)), 0 /*!vlonly */ );
3006 /* some notes on the following code...
3007 * in the hash table of server structs, all servers with the same IP address
3008 * will be on the same overflow chain.
3009 * This could be sped slightly in some circumstances by having it cache the
3010 * immediately previous slot in the hash table and some supporting information
3011 * Only reports file servers now.
3013 DECL_PIOCTL(PGetSPrefs)
3015 struct sprefrequest *spin; /* input */
3016 struct sprefinfo *spout; /* output */
3017 struct spref *srvout; /* one output component */
3018 int i, j; /* counters for hash table traversal */
3019 struct server *srvr; /* one of CM's server structs */
3021 int vlonly; /* just return vlservers ? */
3024 AFS_STATCNT(PGetSPrefs);
3025 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3026 return EIO; /* Inappropriate ioctl for device */
3029 if (ainSize < sizeof(struct sprefrequest_33)) {
3032 spin = ((struct sprefrequest *)ain);
3035 if (ainSize > sizeof(struct sprefrequest_33)) {
3036 vlonly = (spin->flags & DBservers);
3040 /* struct sprefinfo includes 1 server struct... that size gets added
3041 * in during the loop that follows.
3043 *aoutSize = sizeof(struct sprefinfo) - sizeof(struct spref);
3044 spout = (struct sprefinfo *)aout;
3045 spout->next_offset = spin->offset;
3046 spout->num_servers = 0;
3047 srvout = spout->servers;
3049 ObtainReadLock(&afs_xserver);
3050 for (i = 0, j = 0; j < NSERVERS; j++) { /* sift through hash table */
3051 for (sa = afs_srvAddrs[j]; sa; sa = sa->next_bkt, i++) {
3052 if (spin->offset > (unsigned short)i) {
3053 continue; /* catch up to where we left off */
3055 spout->next_offset++;
3058 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
3059 || (sa->sa_portal == AFS_FSPORT);
3061 if ((vlonly && isfs) || (!vlonly && !isfs)) {
3062 /* only report ranks for vl servers */
3066 srvout->host.s_addr = sa->sa_ip;
3067 srvout->rank = sa->sa_iprank;
3068 *aoutSize += sizeof(struct spref);
3069 spout->num_servers++;
3072 if (*aoutSize > (PIGGYSIZE - sizeof(struct spref))) {
3073 ReleaseReadLock(&afs_xserver); /* no more room! */
3078 ReleaseReadLock(&afs_xserver);
3080 spout->next_offset = 0; /* start over from the beginning next time */
3084 /* Enable/Disable the specified exporter. Must be root to disable an exporter */
3085 int afs_NFSRootOnly = 1;
3086 DECL_PIOCTL(PExportAfs)
3088 afs_int32 export, newint =
3089 0, type, changestate, handleValue, convmode, pwsync, smounts;
3090 register struct afs_exporter *exporter;
3092 AFS_STATCNT(PExportAfs);
3093 memcpy((char *)&handleValue, ain, sizeof(afs_int32));
3094 type = handleValue >> 24;
3099 exporter = exporter_find(type);
3101 export = handleValue & 3;
3102 changestate = handleValue & 0xff;
3103 smounts = (handleValue >> 2) & 3;
3104 pwsync = (handleValue >> 4) & 3;
3105 convmode = (handleValue >> 6) & 3;
3107 changestate = (handleValue >> 16) & 0x1;
3108 convmode = (handleValue >> 16) & 0x2;
3109 pwsync = (handleValue >> 16) & 0x4;
3110 smounts = (handleValue >> 16) & 0x8;
3111 export = handleValue & 0xff;
3114 /* Failed finding desired exporter; */
3118 handleValue = exporter->exp_states;
3119 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3120 *aoutSize = sizeof(afs_int32);
3122 if (!afs_osi_suser(*acred))
3123 return EACCES; /* Only superuser can do this */
3127 exporter->exp_states |= EXP_EXPORTED;
3129 exporter->exp_states &= ~EXP_EXPORTED;
3133 exporter->exp_states |= EXP_UNIXMODE;
3135 exporter->exp_states &= ~EXP_UNIXMODE;
3139 exporter->exp_states |= EXP_PWSYNC;
3141 exporter->exp_states &= ~EXP_PWSYNC;
3145 afs_NFSRootOnly = 0;
3146 exporter->exp_states |= EXP_SUBMOUNTS;
3148 afs_NFSRootOnly = 1;
3149 exporter->exp_states &= ~EXP_SUBMOUNTS;
3152 handleValue = exporter->exp_states;
3153 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3154 *aoutSize = sizeof(afs_int32);
3157 exporter->exp_states |= EXP_EXPORTED;
3159 exporter->exp_states &= ~EXP_EXPORTED;
3161 exporter->exp_states |= EXP_UNIXMODE;
3163 exporter->exp_states &= ~EXP_UNIXMODE;
3165 exporter->exp_states |= EXP_PWSYNC;
3167 exporter->exp_states &= ~EXP_PWSYNC;
3169 afs_NFSRootOnly = 0;
3170 exporter->exp_states |= EXP_SUBMOUNTS;
3172 afs_NFSRootOnly = 1;
3173 exporter->exp_states &= ~EXP_SUBMOUNTS;
3183 struct gaginfo *gagflags;
3185 if (!afs_osi_suser(*acred))
3188 gagflags = (struct gaginfo *)ain;
3189 afs_showflags = gagflags->showflags;
3195 DECL_PIOCTL(PTwiddleRx)
3197 struct rxparams *rxp;
3199 if (!afs_osi_suser(*acred))
3202 rxp = (struct rxparams *)ain;
3204 if (rxp->rx_initReceiveWindow)
3205 rx_initReceiveWindow = rxp->rx_initReceiveWindow;
3206 if (rxp->rx_maxReceiveWindow)
3207 rx_maxReceiveWindow = rxp->rx_maxReceiveWindow;
3208 if (rxp->rx_initSendWindow)
3209 rx_initSendWindow = rxp->rx_initSendWindow;
3210 if (rxp->rx_maxSendWindow)
3211 rx_maxSendWindow = rxp->rx_maxSendWindow;
3212 if (rxp->rxi_nSendFrags)
3213 rxi_nSendFrags = rxp->rxi_nSendFrags;
3214 if (rxp->rxi_nRecvFrags)
3215 rxi_nRecvFrags = rxp->rxi_nRecvFrags;
3216 if (rxp->rxi_OrphanFragSize)
3217 rxi_OrphanFragSize = rxp->rxi_OrphanFragSize;
3218 if (rxp->rx_maxReceiveSize) {
3219 rx_maxReceiveSize = rxp->rx_maxReceiveSize;
3220 rx_maxReceiveSizeUser = rxp->rx_maxReceiveSize;
3222 if (rxp->rx_MyMaxSendSize)
3223 rx_MyMaxSendSize = rxp->rx_MyMaxSendSize;
3228 DECL_PIOCTL(PGetInitParams)
3230 if (sizeof(struct cm_initparams) > PIGGYSIZE)
3233 memcpy(aout, (char *)&cm_initParams, sizeof(struct cm_initparams));
3234 *aoutSize = sizeof(struct cm_initparams);
3238 #ifdef AFS_SGI65_ENV
3239 /* They took crget() from us, so fake it. */
3244 cr = crdup(get_current_cred());
3245 memset((char *)cr, 0, sizeof(cred_t));
3246 #if CELL || CELL_PREPARE
3253 DECL_PIOCTL(PGetRxkcrypt)
3255 memcpy(aout, (char *)&cryptall, sizeof(afs_int32));
3256 *aoutSize = sizeof(afs_int32);
3260 DECL_PIOCTL(PSetRxkcrypt)
3264 if (!afs_osi_suser(*acred))
3266 if (ainSize != sizeof(afs_int32) || ain == NULL)
3268 memcpy((char *)&tmpval, ain, sizeof(afs_int32));
3269 /* if new mappings added later this will need to be changed */
3270 if (tmpval != 0 && tmpval != 1)
3276 #ifdef AFS_NEED_CLIENTCONTEXT
3278 * Create new credentials to correspond to a remote user with given
3279 * <hostaddr, uid, g0, g1>. This allows a server running as root to
3280 * provide pioctl (and other) services to foreign clients (i.e. nfs
3281 * clients) by using this call to `become' the client.
3284 #define PIOCTL_HEADER 6
3286 HandleClientContext(struct afs_ioctl *ablob, int *com,
3287 struct AFS_UCRED **acred, struct AFS_UCRED *credp)
3290 afs_uint32 hostaddr;
3291 afs_int32 uid, g0, g1, i, code, pag, exporter_type;
3292 struct afs_exporter *exporter, *outexporter;
3293 struct AFS_UCRED *newcred;
3294 struct unixuser *au;
3296 #if defined(AFS_SGIMP_ENV)
3297 osi_Assert(ISAFS_GLOCK());
3299 AFS_STATCNT(HandleClientContext);
3300 if (ablob->in_size < PIOCTL_HEADER * sizeof(afs_int32)) {
3301 /* Must at least include the PIOCTL_HEADER header words required by the protocol */
3302 return EINVAL; /* Too small to be good */
3304 ain = inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
3305 AFS_COPYIN(ablob->in, ain, PIOCTL_HEADER * sizeof(afs_int32), code);
3307 osi_FreeLargeSpace(inData);
3311 /* Extract information for remote user */
3312 hostaddr = *((afs_uint32 *) ain);
3313 ain += sizeof(hostaddr);
3314 uid = *((afs_uint32 *) ain);
3316 g0 = *((afs_uint32 *) ain);
3318 g1 = *((afs_uint32 *) ain);
3320 *com = *((afs_uint32 *) ain);
3321 ain += sizeof(afs_int32);
3322 exporter_type = *((afs_uint32 *) ain); /* In case we support more than NFS */
3325 * Of course, one must be root for most of these functions, but
3326 * we'll allow (for knfs) you to set things if the pag is 0 and
3327 * you're setting tokens or unlogging.
3330 if (!afs_osi_suser(credp)) {
3331 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
3332 /* Since SGI's suser() returns explicit failure after the call.. */
3335 /* check for acceptable opcodes for normal folks, which are, so far,
3336 * set tokens and unlog.
3338 if (i != 9 && i != 3 && i != 38 && i != 8) {
3339 osi_FreeLargeSpace(inData);
3344 ablob->in_size -= PIOCTL_HEADER * sizeof(afs_int32);
3345 ablob->in += PIOCTL_HEADER * sizeof(afs_int32);
3346 osi_FreeLargeSpace(inData);
3349 * We map uid 0 to nobody to match the mapping that the nfs
3350 * server does and to ensure that the suser() calls in the afs
3351 * code fails for remote client roots.
3353 uid = afs_nobody; /* NFS_NOBODY == -2 */
3356 #ifdef AFS_AIX41_ENV
3359 newcred->cr_gid = RMTUSER_REQ;
3360 #ifdef AFS_AIX51_ENV
3361 newcred->cr_groupset.gs_union.un_groups[0] = g0;
3362 newcred->cr_groupset.gs_union.un_groups[1] = g1;
3364 newcred->cr_groups[0] = g0;
3365 newcred->cr_groups[1] = g1;
3368 newcred->cr_ngrps = 2;
3370 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV)
3371 newcred->cr_ngroups = 2;
3373 for (i = 2; i < NGROUPS; i++)
3374 newcred->cr_groups[i] = NOGROUP;
3377 #if !defined(AFS_OSF_ENV) && !defined(AFS_DEC_ENV)
3378 afs_nfsclient_init(); /* before looking for exporter, ensure one exists */
3380 if (!(exporter = exporter_find(exporter_type))) {
3381 /* Exporter wasn't initialized or an invalid exporter type */
3385 if (exporter->exp_states & EXP_PWSYNC) {
3386 if (uid != credp->cr_uid) {
3388 return ENOEXEC; /* XXX Find a better errno XXX */
3391 newcred->cr_uid = uid; /* Only temporary */
3392 code = EXP_REQHANDLER(exporter, &newcred, hostaddr, &pag, &outexporter);
3393 /* The client's pag is the only unique identifier for it */
3394 newcred->cr_uid = pag;
3396 if (!code && *com == PSETPAG) {
3397 /* Special case for 'setpag' */
3398 afs_uint32 pagvalue = genpag();
3400 au = afs_GetUser(pagvalue, -1, WRITE_LOCK); /* a new unixuser struct */
3402 * Note that we leave the 'outexporter' struct held so it won't
3405 au->exporter = outexporter;
3406 if (ablob->out_size >= 4) {
3407 AFS_COPYOUT((char *)&pagvalue, ablob->out, sizeof(afs_int32),
3410 afs_PutUser(au, WRITE_LOCK);
3413 return PSETPAG; /* Special return for setpag */
3415 EXP_RELE(outexporter);
3419 #endif /* AFS_NEED_CLIENTCONTEXT */
3421 /* get all interface addresses of this client */
3423 DECL_PIOCTL(PGetCPrefs)
3425 struct sprefrequest *spin; /* input */
3426 struct sprefinfo *spout; /* output */
3427 struct spref *srvout; /* one output component */
3431 AFS_STATCNT(PGetCPrefs);
3432 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3433 return EIO; /* Inappropriate ioctl for device */
3435 if (ainSize < sizeof(struct sprefrequest))
3438 spin = (struct sprefrequest *)ain;
3439 spout = (struct sprefinfo *)aout;
3441 maxNumber = spin->num_servers; /* max addrs this time */
3442 srvout = spout->servers;
3444 ObtainReadLock(&afs_xinterface);
3446 /* copy out the client interface information from the
3447 ** kernel data structure "interface" to the output buffer
3449 for (i = spin->offset, j = 0; (i < afs_cb_interface.numberOfInterfaces)
3450 && (j < maxNumber); i++, j++, srvout++)
3451 srvout->host.s_addr = afs_cb_interface.addr_in[i];
3453 spout->num_servers = j;
3454 *aoutSize = sizeof(struct sprefinfo) + (j - 1) * sizeof(struct spref);
3456 if (i >= afs_cb_interface.numberOfInterfaces)
3457 spout->next_offset = 0; /* start from beginning again */
3459 spout->next_offset = spin->offset + j;
3461 ReleaseReadLock(&afs_xinterface);
3465 DECL_PIOCTL(PSetCPrefs)
3467 struct setspref *sin;
3470 AFS_STATCNT(PSetCPrefs);
3471 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3472 return EIO; /* Inappropriate ioctl for device */
3474 sin = (struct setspref *)ain;
3476 if (ainSize < sizeof(struct setspref))
3478 #if 0 /* num_servers is unsigned */
3479 if (sin->num_servers < 0)
3482 if (sin->num_servers > AFS_MAX_INTERFACE_ADDR)
3485 ObtainWriteLock(&afs_xinterface, 412);
3486 afs_cb_interface.numberOfInterfaces = sin->num_servers;
3487 for (i = 0; (unsigned short)i < sin->num_servers; i++)
3488 afs_cb_interface.addr_in[i] = sin->servers[i].host.s_addr;
3490 ReleaseWriteLock(&afs_xinterface);
3494 DECL_PIOCTL(PFlushMount)
3496 register afs_int32 code;
3497 register struct vcache *tvc;
3498 register struct dcache *tdc;
3499 struct VenusFid tfid;
3501 struct sysname_info sysState;
3502 afs_size_t offset, len;
3504 AFS_STATCNT(PFlushMount);
3507 code = afs_VerifyVCache(avc, areq);
3510 if (vType(avc) != VDIR) {
3513 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
3516 Check_AtSys(avc, ain, &sysState, areq);
3517 ObtainReadLock(&tdc->lock);
3519 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
3520 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
3521 ReleaseReadLock(&tdc->lock);
3522 afs_PutDCache(tdc); /* we're done with the data */
3523 bufp = sysState.name;
3527 tfid.Cell = avc->fid.Cell;
3528 tfid.Fid.Volume = avc->fid.Fid.Volume;
3529 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
3530 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
3532 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3538 if (tvc->mvstat != 1) {
3543 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
3544 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
3546 ObtainWriteLock(&tvc->lock, 649);
3547 ObtainWriteLock(&afs_xcbhash, 650);
3548 afs_DequeueCallback(tvc);
3549 tvc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
3550 ReleaseWriteLock(&afs_xcbhash);
3551 /* now find the disk cache entries */
3552 afs_TryToSmush(tvc, *acred, 1);
3553 osi_dnlc_purgedp(tvc);
3554 afs_symhint_inval(tvc);
3555 if (tvc->linkData && !(tvc->states & CCore)) {
3556 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
3557 tvc->linkData = NULL;
3559 ReleaseWriteLock(&tvc->lock);
3560 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
3561 afs_BozonUnlock(&tvc->pvnLock, tvc);
3565 if (sysState.allocked)
3566 osi_FreeLargeSpace(bufp);
3570 DECL_PIOCTL(PRxStatProc)
3575 if (!afs_osi_suser(*acred)) {
3579 if (ainSize != sizeof(afs_int32)) {
3583 memcpy((char *)&flags, ain, sizeof(afs_int32));
3584 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3588 if (flags & AFSCALL_RXSTATS_ENABLE) {
3589 rx_enableProcessRPCStats();
3591 if (flags & AFSCALL_RXSTATS_DISABLE) {
3592 rx_disableProcessRPCStats();
3594 if (flags & AFSCALL_RXSTATS_CLEAR) {
3595 rx_clearProcessRPCStats(AFS_RX_STATS_CLEAR_ALL);
3603 DECL_PIOCTL(PRxStatPeer)
3608 if (!afs_osi_suser(*acred)) {
3612 if (ainSize != sizeof(afs_int32)) {
3616 memcpy((char *)&flags, ain, sizeof(afs_int32));
3617 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3621 if (flags & AFSCALL_RXSTATS_ENABLE) {
3622 rx_enablePeerRPCStats();
3624 if (flags & AFSCALL_RXSTATS_DISABLE) {
3625 rx_disablePeerRPCStats();
3627 if (flags & AFSCALL_RXSTATS_CLEAR) {
3628 rx_clearPeerRPCStats(AFS_RX_STATS_CLEAR_ALL);
3635 DECL_PIOCTL(PPrefetchFromTape)
3637 register afs_int32 code, code1;
3640 struct rx_call *tcall;
3641 struct AFSVolSync tsync;
3642 struct AFSFetchStatus OutStatus;
3643 struct AFSCallBack CallBack;
3644 struct VenusFid tfid;
3648 AFS_STATCNT(PSetAcl);
3652 if (ain && (ainSize == 3 * sizeof(afs_int32)))
3653 Fid = (struct AFSFid *)ain;
3655 Fid = &avc->fid.Fid;
3656 tfid.Cell = avc->fid.Cell;
3657 tfid.Fid.Volume = Fid->Volume;
3658 tfid.Fid.Vnode = Fid->Vnode;
3659 tfid.Fid.Unique = Fid->Unique;
3661 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3663 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3664 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &avc->fid);
3667 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3668 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &tvc->fid);
3671 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3675 tcall = rx_NewCall(tc->id);
3677 StartRXAFS_FetchData(tcall, (struct AFSFid *)&tvc->fid.Fid, 0,
3680 bytes = rx_Read(tcall, (char *)aout, sizeof(afs_int32));
3682 EndRXAFS_FetchData(tcall, &OutStatus, &CallBack, &tsync);
3684 code1 = rx_EndCall(tcall, code);
3688 } while (afs_Analyze
3689 (tc, code, &tvc->fid, areq, AFS_STATS_FS_RPCIDX_RESIDENCYRPCS,
3690 SHARED_LOCK, NULL));
3691 /* This call is done only to have the callback things handled correctly */
3692 afs_FetchStatus(tvc, &tfid, areq, &OutStatus);
3696 *aoutSize = sizeof(afs_int32);
3701 DECL_PIOCTL(PResidencyCmd)
3703 register afs_int32 code;
3706 struct ResidencyCmdInputs *Inputs;
3707 struct ResidencyCmdOutputs *Outputs;
3708 struct VenusFid tfid;
3711 Inputs = (struct ResidencyCmdInputs *)ain;
3712 Outputs = (struct ResidencyCmdOutputs *)aout;
3715 if (!ain || ainSize != sizeof(struct ResidencyCmdInputs))
3720 Fid = &avc->fid.Fid;
3722 tfid.Cell = avc->fid.Cell;
3723 tfid.Fid.Volume = Fid->Volume;
3724 tfid.Fid.Vnode = Fid->Vnode;
3725 tfid.Fid.Unique = Fid->Unique;
3727 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3728 afs_Trace3(afs_iclSetp, CM_TRACE_RESIDCMD, ICL_TYPE_POINTER, tvc,
3729 ICL_TYPE_INT32, Inputs->command, ICL_TYPE_FID, &tfid);
3733 if (Inputs->command) {
3735 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3739 RXAFS_ResidencyCmd(tc->id, Fid, Inputs,
3740 (struct ResidencyCmdOutputs *)aout);
3744 } while (afs_Analyze
3745 (tc, code, &tvc->fid, areq,
3746 AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK, NULL));
3747 /* This call is done to have the callback things handled correctly */
3748 afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3749 } else { /* just a status request, return also link data */
3751 Outputs->code = afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3752 Outputs->chars[0] = 0;
3753 if (vType(tvc) == VLNK) {
3754 ObtainWriteLock(&tvc->lock, 555);
3755 if (afs_HandleLink(tvc, areq) == 0)
3756 strncpy((char *)&Outputs->chars, tvc->linkData, MAXCMDCHARS);
3757 ReleaseWriteLock(&tvc->lock);
3764 *aoutSize = sizeof(struct ResidencyCmdOutputs);
3769 DECL_PIOCTL(PCallBackAddr)
3772 afs_uint32 addr, code;
3778 struct unixuser *tu;
3779 struct srvAddr **addrs;
3781 /*AFS_STATCNT(PCallBackAddr); */
3782 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
3783 return EIO; /* Inappropriate ioctl for device */
3785 if (!afs_osi_suser(acred))
3788 if (ainSize < sizeof(afs_int32))
3791 memcpy(&addr, ain, sizeof(afs_int32));
3793 ObtainReadLock(&afs_xinterface);
3794 for (i = 0; (unsigned short)i < afs_cb_interface.numberOfInterfaces; i++) {
3795 if (afs_cb_interface.addr_in[i] == addr)
3799 ReleaseWriteLock(&afs_xinterface);
3801 if (afs_cb_interface.addr_in[i] != addr)
3804 ObtainReadLock(&afs_xserver); /* Necessary? */
3805 ObtainReadLock(&afs_xsrvAddr);
3808 for (i = 0; i < NSERVERS; i++) {
3809 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3814 addrs = afs_osi_Alloc(srvAddrCount * sizeof(*addrs));
3816 for (i = 0; i < NSERVERS; i++) {
3817 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3818 if (j >= srvAddrCount)
3824 ReleaseReadLock(&afs_xsrvAddr);
3825 ReleaseReadLock(&afs_xserver);
3827 for (i = 0; i < j; i++) {
3833 /* vlserver has no callback conn */
3834 if (sa->sa_portal == AFS_VLPORT) {
3838 if (!ts->cell) /* not really an active server, anyway, it must */
3839 continue; /* have just been added by setsprefs */
3841 /* get a connection, even if host is down; bumps conn ref count */
3842 tu = afs_GetUser(areq->uid, ts->cell->cellNum, SHARED_LOCK);
3843 tc = afs_ConnBySA(sa, ts->cell->fsport, ts->cell->cellNum, tu,
3844 1 /*force */ , 1 /*create */ , SHARED_LOCK);
3845 afs_PutUser(tu, SHARED_LOCK);
3849 if ((sa->sa_flags & SRVADDR_ISDOWN) || afs_HaveCallBacksFrom(ts)) {
3850 if (sa->sa_flags & SRVADDR_ISDOWN) {
3851 rx_SetConnDeadTime(tc->id, 3);
3853 #ifdef RX_ENABLE_LOCKS
3855 #endif /* RX_ENABLE_LOCKS */
3856 code = RXAFS_CallBackRxConnAddr(tc->id, &addr);
3857 #ifdef RX_ENABLE_LOCKS
3859 #endif /* RX_ENABLE_LOCKS */
3861 afs_PutConn(tc, SHARED_LOCK); /* done with it now */
3862 } /* Outer loop over addrs */
3863 #endif /* UKERNEL */