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;
199 afs_ioctl32_to_afs_ioctl(const struct afs_ioctl32 *src, struct afs_ioctl *dst)
201 dst->in = (char *)(unsigned long)src->in;
202 dst->out = (char *)(unsigned long)src->out;
203 dst->in_size = src->in_size;
204 dst->out_size = src->out_size;
208 * If you need to change copyin_afs_ioctl(), you may also need to change
213 copyin_afs_ioctl(caddr_t cmarg, struct afs_ioctl *dst)
216 #if defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)
217 struct afs_ioctl32 dst32;
220 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
222 afs_ioctl32_to_afs_ioctl(&dst32, dst);
225 #endif /* defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL) */
228 #if defined(AFS_HPUX_64BIT_ENV)
229 struct afs_ioctl32 dst32;
231 if (is_32bit(u.u_procp)) { /* is_32bit() in proc_iface.h */
232 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
234 afs_ioctl32_to_afs_ioctl(&dst32, dst);
237 #endif /* defined(AFS_HPUX_64BIT_ENV) */
239 #if defined(AFS_SUN57_64BIT_ENV)
240 struct afs_ioctl32 dst32;
242 if (get_udatamodel() == DATAMODEL_ILP32) {
243 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
245 afs_ioctl32_to_afs_ioctl(&dst32, dst);
248 #endif /* defined(AFS_SUN57_64BIT_ENV) */
250 #if defined(AFS_SGI_ENV) && (_MIPS_SZLONG==64)
251 struct afs_ioctl32 dst32;
253 if (!ABI_IS_64BIT(get_current_abi())) {
254 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
256 afs_ioctl32_to_afs_ioctl(&dst32, dst);
259 #endif /* defined(AFS_SGI_ENV) && (_MIPS_SZLONG==64) */
261 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV) && !defined(AFS_AMD64_LINUX20_ENV)
262 struct afs_ioctl32 dst32;
264 #ifdef AFS_SPARC64_LINUX24_ENV
265 if (current->thread.flags & SPARC_FLAG_32BIT)
266 #elif defined(AFS_SPARC64_LINUX20_ENV)
267 if (current->tss.flags & SPARC_FLAG_32BIT)
268 #elif defined(AFS_AMD64_LINUX20_ENV)
269 if (current->thread.flags & THREAD_IA32)
270 #elif defined(AFS_PPC64_LINUX20_ENV)
271 if (current->thread.flags & PPC_FLAG_32BIT)
272 #elif defined(AFS_S390X_LINUX20_ENV)
273 if (current->thread.flags & S390_FLAG_31BIT)
275 #error Not done for this linux type
278 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
280 afs_ioctl32_to_afs_ioctl(&dst32, dst);
283 #endif /* defined(AFS_LINUX_64BIT_KERNEL) */
285 AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code);
290 HandleIoctl(register struct vcache *avc, register afs_int32 acom,
291 struct afs_ioctl *adata)
293 register afs_int32 code;
296 AFS_STATCNT(HandleIoctl);
298 switch (acom & 0xff) {
300 avc->states |= CSafeStore;
304 /* case 2 used to be abort store, but this is no longer provided,
305 * since it is impossible to implement under normal Unix.
309 /* return the name of the cell this file is open on */
310 register struct cell *tcell;
311 register afs_int32 i;
313 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
315 i = strlen(tcell->cellName) + 1; /* bytes to copy out */
317 if (i > adata->out_size) {
318 /* 0 means we're not interested in the output */
319 if (adata->out_size != 0)
323 AFS_COPYOUT(tcell->cellName, adata->out, i, code);
325 afs_PutCell(tcell, READ_LOCK);
331 case 49: /* VIOC_GETINITPARAMS */
332 if (adata->out_size < sizeof(struct cm_initparams)) {
335 AFS_COPYOUT(&cm_initParams, adata->out,
336 sizeof(struct cm_initparams), code);
348 return code; /* so far, none implemented */
353 /* For aix we don't temporarily bypass ioctl(2) but rather do our
354 * thing directly in the vnode layer call, VNOP_IOCTL; thus afs_ioctl
355 * is now called from afs_gn_ioctl.
358 afs_ioctl(struct vcache *tvc, int cmd, int arg)
360 struct afs_ioctl data;
363 AFS_STATCNT(afs_ioctl);
364 if (((cmd >> 8) & 0xff) == 'V') {
365 /* This is a VICEIOCTL call */
366 AFS_COPYIN(arg, (caddr_t) & data, sizeof(data), error);
369 error = HandleIoctl(tvc, cmd, &data);
372 /* No-op call; just return. */
376 #endif /* AFS_AIX_ENV */
378 #if defined(AFS_SGI_ENV)
379 afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
382 , struct vopbd * vbds
386 struct afs_ioctl data;
392 AFS_STATCNT(afs_ioctl);
393 if (((cmd >> 8) & 0xff) == 'V') {
394 /* This is a VICEIOCTL call */
395 error = copyin_afs_ioctl(arg, &data);
398 locked = ISAFS_GLOCK();
401 error = HandleIoctl(tvc, cmd, &data);
406 /* No-op call; just return. */
410 #endif /* AFS_SGI_ENV */
412 /* unlike most calls here, this one uses u.u_error to return error conditions,
413 since this is really an intercepted chapter 2 call, rather than a vnode
416 /* AFS_HPUX102 and up uses VNODE ioctl instead */
417 #ifndef AFS_HPUX102_ENV
418 #if !defined(AFS_SGI_ENV)
422 kioctl(fdes, com, arg, ext, arg2, arg3)
423 #else /* __64BIT__ */
424 kioctl32(fdes, com, arg, ext, arg2, arg3)
425 #endif /* __64BIT__ */
428 kioctl(fdes, com, arg, ext)
439 } u_uap, *uap = &u_uap;
441 #if defined(AFS_SUN5_ENV)
443 struct afs_ioctl_sys {
450 struct afs_ioctl_sys *uap;
453 #elif defined(AFS_OSF_ENV)
454 afs_xioctl(p, args, retval)
463 } *uap = (struct a *)args;
464 #elif defined(AFS_FBSD50_ENV)
467 afs_xioctl(td, uap, retval)
469 register struct ioctl_args *uap;
472 struct proc *p = td->td_proc;
473 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
481 afs_xioctl(p, uap, retval)
483 register struct ioctl_args *uap;
486 #elif defined(AFS_LINUX22_ENV)
487 struct afs_ioctl_sys {
492 afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
495 struct afs_ioctl_sys ua, *uap = &ua;
504 } *uap = (struct a *)u.u_ap;
505 #endif /* AFS_SUN5_ENV */
507 #if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
509 #elif !defined(AFS_LINUX22_ENV)
510 register struct file *fd;
512 #if defined(AFS_XBSD_ENV)
513 register struct filedesc *fdp;
515 register struct vcache *tvc;
516 register int ioctlDone = 0, code = 0;
518 AFS_STATCNT(afs_xioctl);
519 #if defined(AFS_XBSD_ENV)
521 if ((u_int) uap->fd >= fdp->fd_nfiles
522 || (fd = fdp->fd_ofiles[uap->fd]) == NULL)
524 if ((fd->f_flag & (FREAD | FWRITE)) == 0)
526 #elif defined(AFS_DARWIN_ENV)
527 if ((code = fdgetf(p, uap->fd, &fd)))
529 #elif defined(AFS_LINUX22_ENV)
532 #elif defined(AFS_AIX32_ENV)
540 if (setuerror(getf(uap->fd, &fd))) {
543 #elif defined(AFS_OSF_ENV)
545 if (code = getf(&fd, uap->fd, FILE_FLAGS_NULL, &u.u_file_state))
547 #elif defined(AFS_SUN5_ENV)
548 # if defined(AFS_SUN57_ENV)
552 # elif defined(AFS_SUN54_ENV)
557 if (code = getf(uap->fd, &fd)) {
560 # endif /* AFS_SUN57_ENV */
566 /* first determine whether this is any sort of vnode */
567 #if defined(AFS_LINUX22_ENV)
572 if (fd->f_vnode->v_type == VREG || fd->f_vnode->v_type == VDIR) {
574 if (fd->f_type == DTYPE_VNODE) {
576 /* good, this is a vnode; next see if it is an AFS vnode */
577 #if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV)
578 tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */
579 #elif defined(AFS_OBSD_ENV)
581 IsAfsVnode((struct vnode *)fd->
582 f_data) ? VTOAFS((struct vnode *)fd->f_data) : NULL;
584 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
586 #endif /* AFS_LINUX22_ENV */
587 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
589 tvc = VTOAFS(afs_gntovn((struct gnode *)tvc));
590 if (!tvc) { /* shouldn't happen with held gnodes */
595 /* This is an AFS vnode */
596 if (((uap->com >> 8) & 0xff) == 'V') {
597 register struct afs_ioctl *datap;
600 (struct afs_ioctl *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
601 AFS_COPYIN((char *)uap->arg, (caddr_t) datap,
602 sizeof(struct afs_ioctl), code);
604 osi_FreeSmallSpace(datap);
606 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
609 #if defined(AFS_SUN5_ENV)
624 #else /* AFS_OSF_ENV */
628 #ifdef AFS_LINUX22_ENV
638 code = HandleIoctl(tvc, uap->com, datap);
639 osi_FreeSmallSpace(datap);
653 #if defined(AFS_LINUX22_ENV)
665 code = okioctl(fdes, com, arg, ext, arg2, arg3);
666 #else /* __64BIT__ */
667 code = okioctl32(fdes, com, arg, ext, arg2, arg3);
668 #endif /* __64BIT__ */
669 #else /* !AFS_AIX51_ENV */
670 code = okioctl(fdes, com, arg, ext);
671 #endif /* AFS_AIX51_ENV */
673 #else /* !AFS_AIX41_ENV */
675 okioctl(fdes, com, arg, ext);
676 #elif defined(AFS_SUN5_ENV)
677 #if defined(AFS_SUN57_ENV)
679 #elif defined(AFS_SUN54_ENV)
684 code = ioctl(uap, rvp);
685 #elif defined(AFS_FBSD50_ENV)
686 return ioctl(td, uap);
687 #elif defined(AFS_FBSD_ENV)
688 return ioctl(p, uap);
689 #elif defined(AFS_OBSD_ENV)
690 code = sys_ioctl(p, uap, retval);
691 #elif defined(AFS_DARWIN_ENV)
692 return ioctl(p, uap, retval);
693 #elif defined(AFS_OSF_ENV)
694 code = ioctl(p, args, retval);
701 #elif !defined(AFS_LINUX22_ENV)
715 #ifdef AFS_LINUX22_ENV
718 #if defined(KERNEL_HAVE_UERROR)
721 #if defined(AFS_AIX32_ENV) && !defined(AFS_AIX41_ENV)
722 return (getuerror()? -1 : u.u_ioctlrv);
724 return getuerror()? -1 : 0;
727 #endif /* AFS_LINUX22_ENV */
728 #endif /* AFS_SUN5_ENV */
729 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
733 #endif /* AFS_SGI_ENV */
734 #endif /* AFS_HPUX102_ENV */
736 #if defined(AFS_SGI_ENV)
737 /* "pioctl" system call entry point; just pass argument to the parameterized
746 afs_pioctl(struct pioctlargs *uap, rval_t * rvp)
750 AFS_STATCNT(afs_pioctl);
752 code = afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow);
761 #elif defined(AFS_OSF_ENV)
762 afs_pioctl(p, args, retval)
772 } *uap = (struct a *)args;
774 AFS_STATCNT(afs_pioctl);
775 return (afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow));
778 #elif defined(AFS_FBSD50_ENV)
780 afs_pioctl(td, args, retval)
790 } *uap = (struct a *)args;
792 AFS_STATCNT(afs_pioctl);
793 return (afs_syscall_pioctl
794 (uap->path, uap->cmd, uap->cmarg, uap->follow, td->td_ucred));
797 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
799 afs_pioctl(p, args, retval)
809 } *uap = (struct a *)args;
811 AFS_STATCNT(afs_pioctl);
812 return (afs_syscall_pioctl
813 (uap->path, uap->cmd, uap->cmarg, uap->follow,
814 p->p_cred->pc_ucred));
819 /* macro to avoid adding any more #ifdef's to pioctl code. */
820 #if defined(AFS_LINUX22_ENV) || defined(AFS_AIX41_ENV)
821 #define PIOCTL_FREE_CRED() crfree(credp)
823 #define PIOCTL_FREE_CRED()
828 afs_syscall_pioctl(path, com, cmarg, follow, rvp, credp)
830 struct AFS_UCRED *credp;
832 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
833 afs_syscall_pioctl(path, com, cmarg, follow, credp)
834 struct AFS_UCRED *credp;
836 afs_syscall_pioctl(path, com, cmarg, follow)
844 struct afs_ioctl data;
845 struct AFS_UCRED *tmpcred, *foreigncreds = NULL;
846 register afs_int32 code = 0;
852 struct ucred *credp = crref(); /* don't free until done! */
854 #ifdef AFS_LINUX22_ENV
855 cred_t *credp = crref(); /* don't free until done! */
859 AFS_STATCNT(afs_syscall_pioctl);
861 follow = 1; /* compat. with old venus */
862 code = copyin_afs_ioctl(cmarg, &data);
865 #if defined(KERNEL_HAVE_UERROR)
870 if ((com & 0xff) == PSetClientContext) {
871 #ifdef AFS_NEED_CLIENTCONTEXT
872 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV)
873 code = HandleClientContext(&data, &com, &foreigncreds, credp);
875 code = HandleClientContext(&data, &com, &foreigncreds, osi_curcred());
879 crfree(foreigncreds);
882 #if defined(KERNEL_HAVE_UERROR)
883 return (setuerror(code), code);
888 #else /* AFS_NEED_CLIENTCONTEXT */
890 #endif /* AFS_NEED_CLIENTCONTEXT */
892 #ifdef AFS_NEED_CLIENTCONTEXT
895 * We could have done without temporary setting the u.u_cred below
896 * (foreigncreds could be passed as param the pioctl modules)
897 * but calls such as afs_osi_suser() doesn't allow that since it
898 * references u.u_cred directly. We could, of course, do something
899 * like afs_osi_suser(cred) which, I think, is better since it
900 * generalizes and supports multi cred environments...
904 credp = foreigncreds;
905 #elif defined(AFS_AIX41_ENV)
906 tmpcred = crref(); /* XXX */
908 #elif defined(AFS_HPUX101_ENV)
909 tmpcred = p_cred(u.u_procp);
910 set_p_cred(u.u_procp, foreigncreds);
911 #elif defined(AFS_SGI_ENV)
912 tmpcred = OSI_GET_CURRENT_CRED();
913 OSI_SET_CURRENT_CRED(foreigncreds);
916 u.u_cred = foreigncreds;
919 #endif /* AFS_NEED_CLIENTCONTEXT */
920 if ((com & 0xff) == 15) {
921 /* special case prefetch so entire pathname eval occurs in helper process.
922 * otherwise, the pioctl call is essentially useless */
923 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
925 Prefetch(path, &data, follow,
926 foreigncreds ? foreigncreds : credp);
928 code = Prefetch(path, &data, follow, osi_curcred());
931 #if defined(KERNEL_HAVE_UERROR)
940 lookupname(path, USR, follow, NULL, &vp,
941 foreigncreds ? foreigncreds : credp);
943 #ifdef AFS_LINUX22_ENV
944 code = gop_lookupname(path, AFS_UIOUSER, follow, NULL, &dp);
946 vp = (struct vnode *)dp->d_inode;
948 code = gop_lookupname(path, AFS_UIOUSER, follow, NULL, &vp);
949 #endif /* AFS_LINUX22_ENV */
950 #endif /* AFS_AIX41_ENV */
954 #if defined(KERNEL_HAVE_UERROR)
962 /* now make the call if we were passed no file, or were passed an AFS file */
963 if (!vp || IsAfsVnode(vp)) {
964 #if defined(AFS_DEC_ENV)
965 /* Ultrix 4.0: can't get vcache entry unless we've got an AFS gnode.
966 * So, we must test in this part of the code. Also, must arrange to
967 * GRELE the original gnode pointer when we're done, since in Ultrix 4.0,
968 * we hold gnodes, whose references hold our vcache entries.
971 gp = vp; /* remember for "put" */
972 vp = (struct vnode *)afs_gntovn(vp); /* get vcache from gp */
975 #elif defined(AFS_SUN5_ENV)
976 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
977 #elif defined(AFS_AIX41_ENV)
979 struct ucred *cred1, *cred2;
982 cred1 = cred2 = foreigncreds;
984 cred1 = cred2 = credp;
986 code = afs_HandlePioctl(vp, com, &data, follow, &cred1);
987 if (cred1 != cred2) {
988 /* something changed the creds */
992 #elif defined(AFS_HPUX101_ENV)
994 struct ucred *cred = p_cred(u.u_procp);
995 code = afs_HandlePioctl(vp, com, &data, follow, &cred);
997 #elif defined(AFS_SGI_ENV)
1000 credp = OSI_GET_CURRENT_CRED();
1001 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1003 #elif defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1004 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1006 code = afs_HandlePioctl(vp, com, &data, follow, &u.u_cred);
1009 #if defined(KERNEL_HAVE_UERROR)
1012 code = EINVAL; /* not in /afs */
1023 #if defined(AFS_NEED_CLIENTCONTEXT)
1025 #ifdef AFS_AIX41_ENV
1026 crset(tmpcred); /* restore original credentials */
1028 #if defined(AFS_HPUX101_ENV)
1029 set_p_cred(u.u_procp, tmpcred); /* restore original credentials */
1030 #elif defined(AFS_SGI_ENV)
1031 OSI_SET_CURRENT_CRED(tmpcred); /* restore original credentials */
1032 #elif !defined(AFS_SUN5_ENV)
1033 osi_curcred() = tmpcred; /* restore original credentials */
1034 #endif /* AFS_HPUX101_ENV */
1035 crfree(foreigncreds);
1038 #endif /* AFS_NEED_CLIENTCONTEXT */
1040 #ifdef AFS_LINUX22_ENV
1043 AFS_RELE(vp); /* put vnode back */
1047 #if defined(KERNEL_HAVE_UERROR)
1050 return (getuerror());
1056 #define MAXPIOCTLTOKENLEN \
1057 (3*sizeof(afs_int32)+MAXKTCTICKETLEN+sizeof(struct ClearToken)+MAXKTCREALMLEN)
1060 afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
1061 register struct afs_ioctl *ablob, int afollow,
1062 struct AFS_UCRED **acred)
1065 struct vrequest treq;
1066 register afs_int32 code;
1067 register afs_int32 function, device;
1068 afs_int32 inSize, outSize, outSizeMax;
1069 char *inData, *outData;
1070 int (*(*pioctlSw)) ();
1072 struct afs_fakestat_state fakestate;
1074 avc = avp ? VTOAFS(avp) : NULL;
1075 afs_Trace3(afs_iclSetp, CM_TRACE_PIOCTL, ICL_TYPE_INT32, acom & 0xff,
1076 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, afollow);
1077 AFS_STATCNT(HandlePioctl);
1078 if ((code = afs_InitReq(&treq, *acred)))
1080 afs_InitFakeStat(&fakestate);
1082 code = afs_EvalFakeStat(&avc, &fakestate, &treq);
1084 afs_PutFakeStat(&fakestate);
1088 device = (acom & 0xff00) >> 8;
1090 case 'V': /* Original pioctls */
1091 pioctlSw = VpioctlSw;
1092 pioctlSwSize = sizeof(VpioctlSw);
1094 case 'C': /* Coordinated/common pioctls */
1095 pioctlSw = CpioctlSw;
1096 pioctlSwSize = sizeof(CpioctlSw);
1099 afs_PutFakeStat(&fakestate);
1102 function = acom & 0xff;
1103 if (function >= (pioctlSwSize / sizeof(char *))) {
1104 afs_PutFakeStat(&fakestate);
1105 return EINVAL; /* out of range */
1107 inSize = ablob->in_size;
1109 /* Do all range checking before continuing */
1110 if (inSize > MAXPIOCTLTOKENLEN || inSize < 0 || ablob->out_size < 0)
1113 if (inSize > AFS_LRALLOCSIZ) {
1114 inData = osi_AllocLargeSpace(inSize+1);
1116 inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1121 AFS_COPYIN(ablob->in, inData, inSize, code);
1122 inData[inSize] = '\0';
1126 if (inSize > AFS_LRALLOCSIZ) {
1127 osi_Free(inData, inSize+1);
1129 osi_FreeLargeSpace(inData);
1131 afs_PutFakeStat(&fakestate);
1134 if (function == 8 && device == 'V') { /* PGetTokens */
1135 outSizeMax = MAXPIOCTLTOKENLEN;
1136 outData = osi_Alloc(outSizeMax);
1138 outSizeMax = AFS_LRALLOCSIZ;
1139 outData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1142 if (inSize > AFS_LRALLOCSIZ) {
1143 osi_Free(inData, inSize+1);
1145 osi_FreeLargeSpace(inData);
1151 (*pioctlSw[function]) (avc, function, &treq, inData, outData, inSize,
1153 if (inSize > AFS_LRALLOCSIZ) {
1154 osi_Free(inData, inSize+1);
1156 osi_FreeLargeSpace(inData);
1158 if (code == 0 && ablob->out_size > 0) {
1159 if (outSize > ablob->out_size) {
1160 code = E2BIG; /* data wont fit in user buffer */
1161 } else if (outSize) {
1162 AFS_COPYOUT(outData, ablob->out, outSize, code);
1165 if (outSizeMax > AFS_LRALLOCSIZ) {
1166 osi_Free(outData, outSizeMax);
1168 osi_FreeLargeSpace(outData);
1170 afs_PutFakeStat(&fakestate);
1171 return afs_CheckCode(code, &treq, 41);
1174 DECL_PIOCTL(PGetFID)
1176 AFS_STATCNT(PGetFID);
1179 memcpy(aout, (char *)&avc->fid, sizeof(struct VenusFid));
1180 *aoutSize = sizeof(struct VenusFid);
1184 DECL_PIOCTL(PSetAcl)
1186 register afs_int32 code;
1188 struct AFSOpaque acl;
1189 struct AFSVolSync tsync;
1190 struct AFSFetchStatus OutStatus;
1193 AFS_STATCNT(PSetAcl);
1196 if ((acl.AFSOpaque_len = strlen(ain) + 1) > 1000)
1199 acl.AFSOpaque_val = ain;
1201 tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1203 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREACL);
1206 RXAFS_StoreACL(tconn->id, (struct AFSFid *)&avc->fid.Fid,
1207 &acl, &OutStatus, &tsync);
1212 } while (afs_Analyze
1213 (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_STOREACL,
1214 SHARED_LOCK, NULL));
1216 /* now we've forgotten all of the access info */
1217 ObtainWriteLock(&afs_xcbhash, 455);
1219 afs_DequeueCallback(avc);
1220 avc->states &= ~(CStatd | CUnique);
1221 ReleaseWriteLock(&afs_xcbhash);
1222 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
1223 osi_dnlc_purgedp(avc);
1227 int afs_defaultAsynchrony = 0;
1229 DECL_PIOCTL(PStoreBehind)
1232 struct sbstruct *sbr;
1234 sbr = (struct sbstruct *)ain;
1235 if (sbr->sb_default != -1) {
1236 if (afs_osi_suser(*acred))
1237 afs_defaultAsynchrony = sbr->sb_default;
1242 if (avc && (sbr->sb_thisfile != -1)) {
1244 (avc, PRSFS_WRITE | PRSFS_ADMINISTER, areq, DONT_CHECK_MODE_BITS))
1245 avc->asynchrony = sbr->sb_thisfile;
1250 *aoutSize = sizeof(struct sbstruct);
1251 sbr = (struct sbstruct *)aout;
1252 sbr->sb_default = afs_defaultAsynchrony;
1254 sbr->sb_thisfile = avc->asynchrony;
1260 DECL_PIOCTL(PGCPAGs)
1262 if (!afs_osi_suser(*acred)) {
1265 afs_gcpags = AFS_GCPAGS_USERDISABLED;
1269 DECL_PIOCTL(PGetAcl)
1271 struct AFSOpaque acl;
1272 struct AFSVolSync tsync;
1273 struct AFSFetchStatus OutStatus;
1279 AFS_STATCNT(PGetAcl);
1282 Fid.Volume = avc->fid.Fid.Volume;
1283 Fid.Vnode = avc->fid.Fid.Vnode;
1284 Fid.Unique = avc->fid.Fid.Unique;
1285 if (avc->states & CForeign) {
1287 * For a dfs xlator acl we have a special hack so that the
1288 * xlator will distinguish which type of acl will return. So
1289 * we currently use the top 2-bytes (vals 0-4) to tell which
1290 * type of acl to bring back. Horrible hack but this will
1291 * cause the least number of changes to code size and interfaces.
1293 if (Fid.Vnode & 0xc0000000)
1295 Fid.Vnode |= (ainSize << 30);
1297 acl.AFSOpaque_val = aout;
1299 tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1302 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHACL);
1304 code = RXAFS_FetchACL(tconn->id, &Fid, &acl, &OutStatus, &tsync);
1309 } while (afs_Analyze
1310 (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_FETCHACL,
1311 SHARED_LOCK, NULL));
1314 *aoutSize = (acl.AFSOpaque_len == 0 ? 1 : acl.AFSOpaque_len);
1327 AFS_STATCNT(PBogus);
1331 DECL_PIOCTL(PGetFileCell)
1333 register struct cell *tcell;
1335 AFS_STATCNT(PGetFileCell);
1338 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
1341 strcpy(aout, tcell->cellName);
1342 afs_PutCell(tcell, READ_LOCK);
1343 *aoutSize = strlen(aout) + 1;
1347 DECL_PIOCTL(PGetWSCell)
1349 struct cell *tcell = NULL;
1351 AFS_STATCNT(PGetWSCell);
1352 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1353 return EIO; /* Inappropriate ioctl for device */
1355 tcell = afs_GetPrimaryCell(READ_LOCK);
1356 if (!tcell) /* no primary cell? */
1358 strcpy(aout, tcell->cellName);
1359 *aoutSize = strlen(aout) + 1;
1360 afs_PutCell(tcell, READ_LOCK);
1364 DECL_PIOCTL(PGetUserCell)
1366 register afs_int32 i;
1367 register struct unixuser *tu;
1368 register struct cell *tcell;
1370 AFS_STATCNT(PGetUserCell);
1371 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1372 return EIO; /* Inappropriate ioctl for device */
1374 /* return the cell name of the primary cell for this user */
1375 i = UHash(areq->uid);
1376 ObtainWriteLock(&afs_xuser, 224);
1377 for (tu = afs_users[i]; tu; tu = tu->next) {
1378 if (tu->uid == areq->uid && (tu->states & UPrimary)) {
1380 ReleaseWriteLock(&afs_xuser);
1385 tcell = afs_GetCell(tu->cell, READ_LOCK);
1386 afs_PutUser(tu, WRITE_LOCK);
1390 strcpy(aout, tcell->cellName);
1391 afs_PutCell(tcell, READ_LOCK);
1392 *aoutSize = strlen(aout) + 1; /* 1 for the null */
1395 ReleaseWriteLock(&afs_xuser);
1402 DECL_PIOCTL(PSetTokens)
1405 register struct unixuser *tu;
1406 struct ClearToken clear;
1407 register struct cell *tcell;
1410 struct vrequest treq;
1411 afs_int32 flag, set_parent_pag = 0;
1413 AFS_STATCNT(PSetTokens);
1414 if (!afs_resourceinit_flag) {
1417 memcpy((char *)&i, ain, sizeof(afs_int32));
1418 ain += sizeof(afs_int32);
1419 stp = ain; /* remember where the ticket is */
1420 if (i < 0 || i > MAXKTCTICKETLEN)
1421 return EINVAL; /* malloc may fail */
1423 ain += i; /* skip over ticket */
1424 memcpy((char *)&i, ain, sizeof(afs_int32));
1425 ain += sizeof(afs_int32);
1426 if (i != sizeof(struct ClearToken)) {
1429 memcpy((char *)&clear, ain, sizeof(struct ClearToken));
1430 if (clear.AuthHandle == -1)
1431 clear.AuthHandle = 999; /* more rxvab compat stuff */
1432 ain += sizeof(struct ClearToken);
1433 if (ainSize != 2 * sizeof(afs_int32) + stLen + sizeof(struct ClearToken)) {
1434 /* still stuff left? we've got primary flag and cell name. Set these */
1435 memcpy((char *)&flag, ain, sizeof(afs_int32)); /* primary id flag */
1436 ain += sizeof(afs_int32); /* skip id field */
1437 /* rest is cell name, look it up */
1438 /* some versions of gcc appear to need != 0 in order to get this right */
1439 if ((flag & 0x8000) != 0) { /* XXX Use Constant XXX */
1443 tcell = afs_GetCellByName(ain, READ_LOCK);
1447 /* default to primary cell, primary id */
1448 flag = 1; /* primary id */
1449 tcell = afs_GetPrimaryCell(READ_LOCK);
1454 afs_PutCell(tcell, READ_LOCK);
1455 if (set_parent_pag) {
1457 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1458 #if defined(AFS_DARWIN_ENV)
1459 struct proc *p = current_proc(); /* XXX */
1461 struct proc *p = curproc; /* XXX */
1463 uprintf("Process %d (%s) tried to change pags in PSetTokens\n",
1464 p->p_pid, p->p_comm);
1465 if (!setpag(p, acred, -1, &pag, 1)) {
1468 if (!setpag(u.u_procp, acred, -1, &pag, 1)) { /* XXX u.u_procp is a no-op XXX */
1470 if (!setpag(acred, -1, &pag, 1)) {
1473 afs_InitReq(&treq, *acred);
1477 /* now we just set the tokens */
1478 tu = afs_GetUser(areq->uid, i, WRITE_LOCK); /* i has the cell # */
1479 tu->vid = clear.ViceId;
1480 if (tu->stp != NULL) {
1481 afs_osi_Free(tu->stp, tu->stLen);
1483 tu->stp = (char *)afs_osi_Alloc(stLen);
1485 memcpy(tu->stp, stp, stLen);
1488 afs_stats_cmfullperf.authent.TicketUpdates++;
1489 afs_ComputePAGStats();
1490 #endif /* AFS_NOSTATS */
1491 tu->states |= UHasTokens;
1492 tu->states &= ~UTokensBad;
1493 afs_SetPrimary(tu, flag);
1494 tu->tokenTime = osi_Time();
1495 afs_ResetUserConns(tu);
1496 afs_PutUser(tu, WRITE_LOCK);
1511 DECL_PIOCTL(PGetVolumeStatus)
1514 char *offLineMsg = afs_osi_Alloc(256);
1515 char *motd = afs_osi_Alloc(256);
1516 register struct conn *tc;
1517 register afs_int32 code = 0;
1518 struct VolumeStatus volstat;
1520 char *Name, *OfflineMsg, *MOTD;
1523 AFS_STATCNT(PGetVolumeStatus);
1529 OfflineMsg = offLineMsg;
1532 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1534 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS);
1537 RXAFS_GetVolumeStatus(tc->id, avc->fid.Fid.Volume, &volstat,
1538 &Name, &OfflineMsg, &MOTD);
1543 } while (afs_Analyze
1544 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS,
1545 SHARED_LOCK, NULL));
1549 /* Copy all this junk into msg->im_data, keeping track of the lengths. */
1551 memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
1552 cp += sizeof(VolumeStatus);
1553 strcpy(cp, volName);
1554 cp += strlen(volName) + 1;
1555 strcpy(cp, offLineMsg);
1556 cp += strlen(offLineMsg) + 1;
1558 cp += strlen(motd) + 1;
1559 *aoutSize = (cp - aout);
1561 afs_osi_Free(offLineMsg, 256);
1562 afs_osi_Free(motd, 256);
1566 DECL_PIOCTL(PSetVolumeStatus)
1569 char *offLineMsg = afs_osi_Alloc(256);
1570 char *motd = afs_osi_Alloc(256);
1571 register struct conn *tc;
1572 register afs_int32 code = 0;
1573 struct AFSFetchVolumeStatus volstat;
1574 struct AFSStoreVolumeStatus storeStat;
1575 register struct volume *tvp;
1579 AFS_STATCNT(PSetVolumeStatus);
1585 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
1587 if (tvp->states & (VRO | VBackup)) {
1588 afs_PutVolume(tvp, READ_LOCK);
1592 afs_PutVolume(tvp, READ_LOCK);
1597 /* Copy the junk out, using cp as a roving pointer. */
1599 memcpy((char *)&volstat, cp, sizeof(AFSFetchVolumeStatus));
1600 cp += sizeof(AFSFetchVolumeStatus);
1601 if (strlen(cp) >= sizeof(volName)) {
1605 strcpy(volName, cp);
1606 cp += strlen(volName) + 1;
1607 if (strlen(cp) >= sizeof(offLineMsg)) {
1611 strcpy(offLineMsg, cp);
1612 cp += strlen(offLineMsg) + 1;
1613 if (strlen(cp) >= sizeof(motd)) {
1619 if (volstat.MinQuota != -1) {
1620 storeStat.MinQuota = volstat.MinQuota;
1621 storeStat.Mask |= AFS_SETMINQUOTA;
1623 if (volstat.MaxQuota != -1) {
1624 storeStat.MaxQuota = volstat.MaxQuota;
1625 storeStat.Mask |= AFS_SETMAXQUOTA;
1628 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1630 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS);
1633 RXAFS_SetVolumeStatus(tc->id, avc->fid.Fid.Volume, &storeStat,
1634 volName, offLineMsg, motd);
1639 } while (afs_Analyze
1640 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS,
1641 SHARED_LOCK, NULL));
1645 /* we are sending parms back to make compat. with prev system. should
1646 * change interface later to not ask for current status, just set new status */
1648 memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
1649 cp += sizeof(VolumeStatus);
1650 strcpy(cp, volName);
1651 cp += strlen(volName) + 1;
1652 strcpy(cp, offLineMsg);
1653 cp += strlen(offLineMsg) + 1;
1655 cp += strlen(motd) + 1;
1656 *aoutSize = cp - aout;
1658 afs_osi_Free(offLineMsg, 256);
1659 afs_osi_Free(motd, 256);
1665 AFS_STATCNT(PFlush);
1668 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
1669 afs_BozonLock(&avc->pvnLock, avc); /* Since afs_TryToSmush will do a pvn_vptrunc */
1671 ObtainWriteLock(&avc->lock, 225);
1672 ObtainWriteLock(&afs_xcbhash, 456);
1673 afs_DequeueCallback(avc);
1674 avc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
1675 ReleaseWriteLock(&afs_xcbhash);
1676 /* now find the disk cache entries */
1677 afs_TryToSmush(avc, *acred, 1);
1678 osi_dnlc_purgedp(avc);
1679 afs_symhint_inval(avc);
1680 if (avc->linkData && !(avc->states & CCore)) {
1681 afs_osi_Free(avc->linkData, strlen(avc->linkData) + 1);
1682 avc->linkData = NULL;
1684 ReleaseWriteLock(&avc->lock);
1685 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
1686 afs_BozonUnlock(&avc->pvnLock, avc);
1691 DECL_PIOCTL(PNewStatMount)
1693 register afs_int32 code;
1694 register struct vcache *tvc;
1695 register struct dcache *tdc;
1696 struct VenusFid tfid;
1698 struct sysname_info sysState;
1699 afs_size_t offset, len;
1701 AFS_STATCNT(PNewStatMount);
1704 code = afs_VerifyVCache(avc, areq);
1707 if (vType(avc) != VDIR) {
1710 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
1713 Check_AtSys(avc, ain, &sysState, areq);
1714 ObtainReadLock(&tdc->lock);
1716 code = afs_dir_Lookup(&tdc->f.inode, sysState.name, &tfid.Fid);
1717 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
1718 ReleaseReadLock(&tdc->lock);
1719 afs_PutDCache(tdc); /* we're done with the data */
1720 bufp = sysState.name;
1724 tfid.Cell = avc->fid.Cell;
1725 tfid.Fid.Volume = avc->fid.Fid.Volume;
1726 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
1727 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
1729 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
1735 if (tvc->mvstat != 1) {
1740 ObtainWriteLock(&tvc->lock, 226);
1741 code = afs_HandleLink(tvc, areq);
1743 if (tvc->linkData) {
1744 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
1747 /* we have the data */
1748 strcpy(aout, tvc->linkData);
1749 *aoutSize = strlen(tvc->linkData) + 1;
1754 ReleaseWriteLock(&tvc->lock);
1757 if (sysState.allocked)
1758 osi_FreeLargeSpace(bufp);
1762 DECL_PIOCTL(PGetTokens)
1764 register struct cell *tcell;
1765 register afs_int32 i;
1766 register struct unixuser *tu;
1771 AFS_STATCNT(PGetTokens);
1772 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1773 return EIO; /* Inappropriate ioctl for device */
1775 /* weird interface. If input parameter is present, it is an integer and
1776 * we're supposed to return the parm'th tokens for this unix uid.
1777 * If not present, we just return tokens for cell 1.
1778 * If counter out of bounds, return EDOM.
1779 * If no tokens for the particular cell, return ENOTCONN.
1780 * Also, if this mysterious parm is present, we return, along with the
1781 * tokens, the primary cell indicator (an afs_int32 0) and the cell name
1782 * at the end, in that order.
1784 if ((newStyle = (ainSize > 0))) {
1785 memcpy((char *)&iterator, ain, sizeof(afs_int32));
1787 i = UHash(areq->uid);
1788 ObtainReadLock(&afs_xuser);
1789 for (tu = afs_users[i]; tu; tu = tu->next) {
1791 if (tu->uid == areq->uid && (tu->states & UHasTokens)) {
1792 if (iterator-- == 0)
1793 break; /* are we done yet? */
1796 if (tu->uid == areq->uid && afs_IsPrimaryCellNum(tu->cell))
1802 * No need to hold a read lock on each user entry
1806 ReleaseReadLock(&afs_xuser);
1811 if (((tu->states & UHasTokens) == 0)
1812 || (tu->ct.EndTimestamp < osi_Time())) {
1813 tu->states |= (UTokensBad | UNeedsReset);
1814 afs_PutUser(tu, READ_LOCK);
1817 /* use iterator for temp */
1819 iterator = tu->stLen; /* for compat, we try to return 56 byte tix if they fit */
1821 iterator = 56; /* # of bytes we're returning */
1822 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1823 cp += sizeof(afs_int32);
1824 memcpy(cp, tu->stp, tu->stLen); /* copy out st */
1826 iterator = sizeof(struct ClearToken);
1827 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1828 cp += sizeof(afs_int32);
1829 memcpy(cp, (char *)&tu->ct, sizeof(struct ClearToken));
1830 cp += sizeof(struct ClearToken);
1832 /* put out primary id and cell name, too */
1833 iterator = (tu->states & UPrimary ? 1 : 0);
1834 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1835 cp += sizeof(afs_int32);
1836 tcell = afs_GetCell(tu->cell, READ_LOCK);
1838 strcpy(cp, tcell->cellName);
1839 cp += strlen(tcell->cellName) + 1;
1840 afs_PutCell(tcell, READ_LOCK);
1844 *aoutSize = cp - aout;
1845 afs_PutUser(tu, READ_LOCK);
1851 register afs_int32 i;
1852 register struct unixuser *tu;
1854 AFS_STATCNT(PUnlog);
1855 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1856 return EIO; /* Inappropriate ioctl for device */
1858 i = UHash(areq->uid);
1859 ObtainWriteLock(&afs_xuser, 227);
1860 for (tu = afs_users[i]; tu; tu = tu->next) {
1861 if (tu->uid == areq->uid) {
1863 tu->states &= ~UHasTokens;
1864 /* security is not having to say you're sorry */
1865 memset((char *)&tu->ct, 0, sizeof(struct ClearToken));
1867 ReleaseWriteLock(&afs_xuser);
1868 /* We have to drop the lock over the call to afs_ResetUserConns, since
1869 * it obtains the afs_xvcache lock. We could also keep the lock, and
1870 * modify ResetUserConns to take parm saying we obtained the lock
1871 * already, but that is overkill. By keeping the "tu" pointer
1872 * held over the released lock, we guarantee that we won't lose our
1873 * place, and that we'll pass over every user conn that existed when
1874 * we began this call.
1876 afs_ResetUserConns(tu);
1878 ObtainWriteLock(&afs_xuser, 228);
1880 /* set the expire times to 0, causes
1881 * afs_GCUserData to remove this entry
1883 tu->ct.EndTimestamp = 0;
1885 #endif /* UKERNEL */
1888 ReleaseWriteLock(&afs_xuser);
1892 DECL_PIOCTL(PMariner)
1894 afs_int32 newHostAddr;
1895 afs_int32 oldHostAddr;
1897 AFS_STATCNT(PMariner);
1899 memcpy((char *)&oldHostAddr, (char *)&afs_marinerHost,
1902 oldHostAddr = 0xffffffff; /* disabled */
1904 memcpy((char *)&newHostAddr, ain, sizeof(afs_int32));
1905 if (newHostAddr == 0xffffffff) {
1906 /* disable mariner operations */
1908 } else if (newHostAddr) {
1910 afs_marinerHost = newHostAddr;
1912 memcpy(aout, (char *)&oldHostAddr, sizeof(afs_int32));
1913 *aoutSize = sizeof(afs_int32);
1917 DECL_PIOCTL(PCheckServers)
1919 register char *cp = 0;
1921 register struct server *ts;
1922 afs_int32 temp, *lp = (afs_int32 *) ain, havecell = 0;
1924 struct chservinfo *pcheck;
1926 AFS_STATCNT(PCheckServers);
1928 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1929 return EIO; /* Inappropriate ioctl for device */
1931 if (*lp == 0x12345678) { /* For afs3.3 version */
1932 pcheck = (struct chservinfo *)ain;
1933 if (pcheck->tinterval >= 0) {
1935 memcpy(cp, (char *)&PROBE_INTERVAL, sizeof(afs_int32));
1936 *aoutSize = sizeof(afs_int32);
1937 if (pcheck->tinterval > 0) {
1938 if (!afs_osi_suser(*acred))
1940 PROBE_INTERVAL = pcheck->tinterval;
1946 temp = pcheck->tflags;
1947 cp = pcheck->tbuffer;
1948 } else { /* For pre afs3.3 versions */
1949 memcpy((char *)&temp, ain, sizeof(afs_int32));
1950 cp = ain + sizeof(afs_int32);
1951 if (ainSize > sizeof(afs_int32))
1956 * 1: fast check, don't contact servers.
1957 * 2: local cell only.
1960 /* have cell name, too */
1961 cellp = afs_GetCellByName(cp, READ_LOCK);
1966 if (!cellp && (temp & 2)) {
1967 /* use local cell */
1968 cellp = afs_GetPrimaryCell(READ_LOCK);
1970 if (!(temp & 1)) { /* if not fast, call server checker routine */
1971 afs_CheckServers(1, cellp); /* check down servers */
1972 afs_CheckServers(0, cellp); /* check up servers */
1974 /* now return the current down server list */
1976 ObtainReadLock(&afs_xserver);
1977 for (i = 0; i < NSERVERS; i++) {
1978 for (ts = afs_servers[i]; ts; ts = ts->next) {
1979 if (cellp && ts->cell != cellp)
1980 continue; /* cell spec'd and wrong */
1981 if ((ts->flags & SRVR_ISDOWN)
1982 && ts->addr->sa_portal != ts->cell->vlport) {
1983 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
1984 cp += sizeof(afs_int32);
1988 ReleaseReadLock(&afs_xserver);
1990 afs_PutCell(cellp, READ_LOCK);
1991 *aoutSize = cp - aout;
1995 DECL_PIOCTL(PCheckVolNames)
1997 AFS_STATCNT(PCheckVolNames);
1998 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1999 return EIO; /* Inappropriate ioctl for device */
2001 afs_CheckRootVolume();
2002 afs_CheckVolumeNames(AFS_VOLCHECK_FORCE | AFS_VOLCHECK_EXPIRED |
2003 AFS_VOLCHECK_BUSY | AFS_VOLCHECK_MTPTS);
2007 DECL_PIOCTL(PCheckAuth)
2012 struct unixuser *tu;
2015 AFS_STATCNT(PCheckAuth);
2016 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2017 return EIO; /* Inappropriate ioctl for device */
2020 tu = afs_GetUser(areq->uid, 1, READ_LOCK); /* check local cell authentication */
2024 /* we have a user */
2025 ObtainReadLock(&afs_xsrvAddr);
2026 ObtainReadLock(&afs_xconn);
2028 /* any tokens set? */
2029 if ((tu->states & UHasTokens) == 0)
2031 /* all connections in cell 1 working? */
2032 for (i = 0; i < NSERVERS; i++) {
2033 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2034 for (tc = sa->conns; tc; tc = tc->next) {
2035 if (tc->user == tu && (tu->states & UTokensBad))
2040 ReleaseReadLock(&afs_xsrvAddr);
2041 ReleaseReadLock(&afs_xconn);
2042 afs_PutUser(tu, READ_LOCK);
2044 memcpy(aout, (char *)&retValue, sizeof(afs_int32));
2045 *aoutSize = sizeof(afs_int32);
2050 Prefetch(char *apath, struct afs_ioctl *adata, int afollow,
2051 struct AFS_UCRED *acred)
2054 register afs_int32 code;
2055 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2061 AFS_STATCNT(Prefetch);
2064 tp = osi_AllocLargeSpace(1024);
2065 AFS_COPYINSTR(apath, tp, 1024, &bufferSize, code);
2067 osi_FreeLargeSpace(tp);
2070 if (afs_BBusy()) { /* do this as late as possible */
2071 osi_FreeLargeSpace(tp);
2072 return EWOULDBLOCK; /* pretty close */
2074 afs_BQueue(BOP_PATH, (struct vcache *)0, 0, 0, acred, (afs_size_t) 0,
2075 (afs_size_t) 0, tp);
2079 DECL_PIOCTL(PFindVolume)
2081 register struct volume *tvp;
2082 register struct server *ts;
2083 register afs_int32 i;
2086 AFS_STATCNT(PFindVolume);
2089 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
2092 for (i = 0; i < MAXHOSTS; i++) {
2093 ts = tvp->serverHost[i];
2096 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
2097 cp += sizeof(afs_int32);
2100 /* still room for terminating NULL, add it on */
2101 ainSize = 0; /* reuse vbl */
2102 memcpy(cp, (char *)&ainSize, sizeof(afs_int32));
2103 cp += sizeof(afs_int32);
2105 *aoutSize = cp - aout;
2106 afs_PutVolume(tvp, READ_LOCK);
2112 DECL_PIOCTL(PViceAccess)
2114 register afs_int32 code;
2117 AFS_STATCNT(PViceAccess);
2120 code = afs_VerifyVCache(avc, areq);
2123 memcpy((char *)&temp, ain, sizeof(afs_int32));
2124 code = afs_AccessOK(avc, temp, areq, CHECK_MODE_BITS);
2131 DECL_PIOCTL(PSetCacheSize)
2136 AFS_STATCNT(PSetCacheSize);
2137 if (!afs_osi_suser(*acred))
2139 /* too many things are setup initially in mem cache version */
2140 if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
2142 memcpy((char *)&newValue, ain, sizeof(afs_int32));
2144 afs_cacheBlocks = afs_stats_cmperf.cacheBlocksOrig;
2146 if (newValue < afs_min_cache)
2147 afs_cacheBlocks = afs_min_cache;
2149 afs_cacheBlocks = newValue;
2151 afs_stats_cmperf.cacheBlocksTotal = afs_cacheBlocks;
2152 afs_ComputeCacheParms(); /* recompute basic cache parameters */
2153 afs_MaybeWakeupTruncateDaemon();
2154 while (waitcnt++ < 100 && afs_cacheBlocks < afs_blocksUsed) {
2155 afs_osi_Wait(1000, 0, 0);
2156 afs_MaybeWakeupTruncateDaemon();
2161 #define MAXGCSTATS 16
2162 DECL_PIOCTL(PGetCacheSize)
2164 afs_int32 results[MAXGCSTATS];
2166 AFS_STATCNT(PGetCacheSize);
2167 memset((char *)results, 0, sizeof(results));
2168 results[0] = afs_cacheBlocks;
2169 results[1] = afs_blocksUsed;
2170 memcpy(aout, (char *)results, sizeof(results));
2171 *aoutSize = sizeof(results);
2175 DECL_PIOCTL(PRemoveCallBack)
2177 register struct conn *tc;
2178 register afs_int32 code = 0;
2179 struct AFSCallBack CallBacks_Array[1];
2180 struct AFSCBFids theFids;
2181 struct AFSCBs theCBs;
2184 AFS_STATCNT(PRemoveCallBack);
2187 if (avc->states & CRO)
2188 return 0; /* read-only-ness can't change */
2189 ObtainWriteLock(&avc->lock, 229);
2190 theFids.AFSCBFids_len = 1;
2191 theCBs.AFSCBs_len = 1;
2192 theFids.AFSCBFids_val = (struct AFSFid *)&avc->fid.Fid;
2193 theCBs.AFSCBs_val = CallBacks_Array;
2194 CallBacks_Array[0].CallBackType = CB_DROPPED;
2195 if (avc->callback) {
2197 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2199 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
2201 code = RXAFS_GiveUpCallBacks(tc->id, &theFids, &theCBs);
2205 /* don't set code on failure since we wouldn't use it */
2206 } while (afs_Analyze
2207 (tc, code, &avc->fid, areq,
2208 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK, NULL));
2210 ObtainWriteLock(&afs_xcbhash, 457);
2211 afs_DequeueCallback(avc);
2213 avc->states &= ~(CStatd | CUnique);
2214 ReleaseWriteLock(&afs_xcbhash);
2215 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
2216 osi_dnlc_purgedp(avc);
2218 ReleaseWriteLock(&avc->lock);
2222 DECL_PIOCTL(PNewCell)
2224 /* create a new cell */
2225 afs_int32 cellHosts[MAXCELLHOSTS], *lp, magic = 0;
2226 char *newcell = 0, *linkedcell = 0, *tp = ain;
2227 register afs_int32 code, linkedstate = 0, ls;
2228 u_short fsport = 0, vlport = 0;
2231 AFS_STATCNT(PNewCell);
2232 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2233 return EIO; /* Inappropriate ioctl for device */
2235 if (!afs_osi_suser(*acred))
2238 memcpy((char *)&magic, tp, sizeof(afs_int32));
2239 tp += sizeof(afs_int32);
2240 if (magic != 0x12345678)
2243 /* A 3.4 fs newcell command will pass an array of MAXCELLHOSTS
2244 * server addresses while the 3.5 fs newcell command passes
2245 * MAXHOSTS. To figure out which is which, check if the cellname
2248 newcell = tp + (MAXCELLHOSTS + 3) * sizeof(afs_int32);
2249 scount = ((newcell[0] != '\0') ? MAXCELLHOSTS : MAXHOSTS);
2251 /* MAXCELLHOSTS (=8) is less than MAXHOSTS (=13) */
2252 memcpy((char *)cellHosts, tp, MAXCELLHOSTS * sizeof(afs_int32));
2253 tp += (scount * sizeof(afs_int32));
2255 lp = (afs_int32 *) tp;
2259 fsport = 0; /* Privileged ports not allowed */
2261 vlport = 0; /* Privileged ports not allowed */
2262 tp += (3 * sizeof(afs_int32));
2264 if ((ls = *lp) & 1) {
2265 linkedcell = tp + strlen(newcell) + 1;
2266 linkedstate |= CLinkedCell;
2269 linkedstate |= CNoSUID; /* setuid is disabled by default for fs newcell */
2271 afs_NewCell(newcell, cellHosts, linkedstate, linkedcell, fsport,
2276 DECL_PIOCTL(PNewAlias)
2278 /* create a new cell alias */
2280 register afs_int32 code;
2281 char *realName, *aliasName;
2283 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2284 return EIO; /* Inappropriate ioctl for device */
2286 if (!afs_osi_suser(*acred))
2290 tp += strlen(aliasName) + 1;
2293 code = afs_NewCellAlias(aliasName, realName);
2298 DECL_PIOCTL(PListCells)
2300 afs_int32 whichCell;
2301 register struct cell *tcell = 0;
2302 register afs_int32 i;
2303 register char *cp, *tp = ain;
2305 AFS_STATCNT(PListCells);
2306 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2307 return EIO; /* Inappropriate ioctl for device */
2309 memcpy((char *)&whichCell, tp, sizeof(afs_int32));
2310 tp += sizeof(afs_int32);
2311 tcell = afs_GetCellByIndex(whichCell, READ_LOCK);
2314 memset(cp, 0, MAXCELLHOSTS * sizeof(afs_int32));
2315 for (i = 0; i < MAXCELLHOSTS; i++) {
2316 if (tcell->cellHosts[i] == 0)
2318 memcpy(cp, (char *)&tcell->cellHosts[i]->addr->sa_ip,
2320 cp += sizeof(afs_int32);
2322 cp = aout + MAXCELLHOSTS * sizeof(afs_int32);
2323 strcpy(cp, tcell->cellName);
2324 cp += strlen(tcell->cellName) + 1;
2325 *aoutSize = cp - aout;
2326 afs_PutCell(tcell, READ_LOCK);
2334 DECL_PIOCTL(PListAliases)
2336 afs_int32 whichAlias;
2337 register struct cell_alias *tcalias = 0;
2338 register char *cp, *tp = ain;
2340 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2341 return EIO; /* Inappropriate ioctl for device */
2342 if (ainSize < sizeof(afs_int32))
2345 memcpy((char *)&whichAlias, tp, sizeof(afs_int32));
2346 tp += sizeof(afs_int32);
2348 tcalias = afs_GetCellAlias(whichAlias);
2351 strcpy(cp, tcalias->alias);
2352 cp += strlen(tcalias->alias) + 1;
2353 strcpy(cp, tcalias->cell);
2354 cp += strlen(tcalias->cell) + 1;
2355 *aoutSize = cp - aout;
2356 afs_PutCellAlias(tcalias);
2364 DECL_PIOCTL(PRemoveMount)
2366 register afs_int32 code;
2368 struct sysname_info sysState;
2369 afs_size_t offset, len;
2370 register struct conn *tc;
2371 register struct dcache *tdc;
2372 register struct vcache *tvc;
2373 struct AFSFetchStatus OutDirStatus;
2374 struct VenusFid tfid;
2375 struct AFSVolSync tsync;
2379 /* "ain" is the name of the file in this dir to remove */
2381 AFS_STATCNT(PRemoveMount);
2384 code = afs_VerifyVCache(avc, areq);
2387 if (vType(avc) != VDIR)
2390 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1); /* test for error below */
2393 Check_AtSys(avc, ain, &sysState, areq);
2394 ObtainReadLock(&tdc->lock);
2396 code = afs_dir_Lookup(&tdc->f.inode, sysState.name, &tfid.Fid);
2397 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
2398 ReleaseReadLock(&tdc->lock);
2399 bufp = sysState.name;
2404 tfid.Cell = avc->fid.Cell;
2405 tfid.Fid.Volume = avc->fid.Fid.Volume;
2406 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
2407 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
2409 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
2416 if (tvc->mvstat != 1) {
2422 ObtainWriteLock(&tvc->lock, 230);
2423 code = afs_HandleLink(tvc, areq);
2425 if (tvc->linkData) {
2426 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
2431 ReleaseWriteLock(&tvc->lock);
2432 osi_dnlc_purgedp(tvc);
2438 ObtainWriteLock(&avc->lock, 231);
2439 osi_dnlc_remove(avc, bufp, tvc);
2441 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2443 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE);
2446 RXAFS_RemoveFile(tc->id, (struct AFSFid *)&avc->fid.Fid, bufp,
2447 &OutDirStatus, &tsync);
2452 } while (afs_Analyze
2453 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_REMOVEFILE,
2454 SHARED_LOCK, NULL));
2459 ReleaseWriteLock(&avc->lock);
2463 /* we have the thing in the cache */
2464 ObtainWriteLock(&tdc->lock, 661);
2465 if (afs_LocalHero(avc, tdc, &OutDirStatus, 1)) {
2466 /* we can do it locally */
2467 code = afs_dir_Delete(&tdc->f.inode, bufp);
2469 ZapDCE(tdc); /* surprise error -- invalid value */
2470 DZap(&tdc->f.inode);
2473 ReleaseWriteLock(&tdc->lock);
2474 afs_PutDCache(tdc); /* drop ref count */
2476 avc->states &= ~CUnique; /* For the dfs xlator */
2477 ReleaseWriteLock(&avc->lock);
2480 if (sysState.allocked)
2481 osi_FreeLargeSpace(bufp);
2485 DECL_PIOCTL(PVenusLogging)
2487 return EINVAL; /* OBSOLETE */
2490 DECL_PIOCTL(PGetCellStatus)
2492 register struct cell *tcell;
2495 AFS_STATCNT(PGetCellStatus);
2496 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2497 return EIO; /* Inappropriate ioctl for device */
2499 tcell = afs_GetCellByName(ain, READ_LOCK);
2502 temp = tcell->states;
2503 afs_PutCell(tcell, READ_LOCK);
2504 memcpy(aout, (char *)&temp, sizeof(afs_int32));
2505 *aoutSize = sizeof(afs_int32);
2509 DECL_PIOCTL(PSetCellStatus)
2511 register struct cell *tcell;
2514 if (!afs_osi_suser(*acred))
2516 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2517 return EIO; /* Inappropriate ioctl for device */
2519 tcell = afs_GetCellByName(ain + 2 * sizeof(afs_int32), WRITE_LOCK);
2522 memcpy((char *)&temp, ain, sizeof(afs_int32));
2524 tcell->states |= CNoSUID;
2526 tcell->states &= ~CNoSUID;
2527 afs_PutCell(tcell, WRITE_LOCK);
2531 DECL_PIOCTL(PFlushVolumeData)
2533 register afs_int32 i;
2534 register struct dcache *tdc;
2535 register struct vcache *tvc;
2536 register struct volume *tv;
2537 afs_int32 cell, volume;
2539 AFS_STATCNT(PFlushVolumeData);
2542 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2543 return EIO; /* Inappropriate ioctl for device */
2545 volume = avc->fid.Fid.Volume; /* who to zap */
2546 cell = avc->fid.Cell;
2549 * Clear stat'd flag from all vnodes from this volume; this will invalidate all
2550 * the vcaches associated with the volume.
2552 ObtainReadLock(&afs_xvcache);
2553 for (i = 0; i < VCSIZE; i++) {
2554 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2555 if (tvc->fid.Fid.Volume == volume && tvc->fid.Cell == cell) {
2556 #if defined(AFS_SGI_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
2557 VN_HOLD(AFSTOV(tvc));
2559 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2565 ReleaseReadLock(&afs_xvcache);
2566 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
2567 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
2569 ObtainWriteLock(&tvc->lock, 232);
2571 ObtainWriteLock(&afs_xcbhash, 458);
2572 afs_DequeueCallback(tvc);
2573 tvc->states &= ~(CStatd | CDirty);
2574 ReleaseWriteLock(&afs_xcbhash);
2575 if (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
2576 osi_dnlc_purgedp(tvc);
2577 afs_TryToSmush(tvc, *acred, 1);
2578 ReleaseWriteLock(&tvc->lock);
2579 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
2580 afs_BozonUnlock(&tvc->pvnLock, tvc);
2582 ObtainReadLock(&afs_xvcache);
2583 /* our tvc ptr is still good until now */
2588 ReleaseReadLock(&afs_xvcache);
2591 MObtainWriteLock(&afs_xdcache, 328); /* needed if you're going to flush any stuff */
2592 for (i = 0; i < afs_cacheFiles; i++) {
2593 if (!(afs_indexFlags[i] & IFEverUsed))
2594 continue; /* never had any data */
2595 tdc = afs_GetDSlot(i, NULL);
2596 if (tdc->refCount <= 1) { /* too high, in use by running sys call */
2597 ReleaseReadLock(&tdc->tlock);
2598 if (tdc->f.fid.Fid.Volume == volume && tdc->f.fid.Cell == cell) {
2599 if (!(afs_indexFlags[i] & IFDataMod)) {
2600 /* if the file is modified, but has a ref cnt of only 1, then
2601 * someone probably has the file open and is writing into it.
2602 * Better to skip flushing such a file, it will be brought back
2603 * immediately on the next write anyway.
2605 * If we *must* flush, then this code has to be rearranged to call
2606 * afs_storeAllSegments() first */
2607 afs_FlushDCache(tdc);
2611 ReleaseReadLock(&tdc->tlock);
2613 afs_PutDCache(tdc); /* bumped by getdslot */
2615 MReleaseWriteLock(&afs_xdcache);
2617 ObtainReadLock(&afs_xvolume);
2618 for (i = 0; i < NVOLS; i++) {
2619 for (tv = afs_volumes[i]; tv; tv = tv->next) {
2620 if (tv->volume == volume) {
2621 afs_ResetVolumeInfo(tv);
2626 ReleaseReadLock(&afs_xvolume);
2628 /* probably, a user is doing this, probably, because things are screwed up.
2629 * maybe it's the dnlc's fault? */
2636 DECL_PIOCTL(PGetVnodeXStatus)
2638 register afs_int32 code;
2639 struct vcxstat stat;
2642 /* AFS_STATCNT(PGetVnodeXStatus); */
2645 code = afs_VerifyVCache(avc, areq);
2648 if (vType(avc) == VDIR)
2649 mode = PRSFS_LOOKUP;
2652 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
2654 stat.fid = avc->fid;
2655 hset32(stat.DataVersion, hgetlo(avc->m.DataVersion));
2656 stat.lock = avc->lock;
2657 stat.parentVnode = avc->parentVnode;
2658 stat.parentUnique = avc->parentUnique;
2659 hset(stat.flushDV, avc->flushDV);
2660 hset(stat.mapDV, avc->mapDV);
2661 stat.truncPos = avc->truncPos;
2662 { /* just grab the first two - won't break anything... */
2663 struct axscache *ac;
2665 for (i = 0, ac = avc->Access; ac && i < CPSIZE; i++, ac = ac->next) {
2666 stat.randomUid[i] = ac->uid;
2667 stat.randomAccess[i] = ac->axess;
2670 stat.callback = afs_data_pointer_to_int32(avc->callback);
2671 stat.cbExpires = avc->cbExpires;
2672 stat.anyAccess = avc->anyAccess;
2673 stat.opens = avc->opens;
2674 stat.execsOrWriters = avc->execsOrWriters;
2675 stat.flockCount = avc->flockCount;
2676 stat.mvstat = avc->mvstat;
2677 stat.states = avc->states;
2678 memcpy(aout, (char *)&stat, sizeof(struct vcxstat));
2679 *aoutSize = sizeof(struct vcxstat);
2684 /* We require root for local sysname changes, but not for remote */
2685 /* (since we don't really believe remote uids anyway) */
2686 /* outname[] shouldn't really be needed- this is left as an excercise */
2687 /* for the reader. */
2688 DECL_PIOCTL(PSetSysName)
2690 char *cp, *cp2, inname[MAXSYSNAME], outname[MAXSYSNAME];
2691 int setsysname, foundname = 0;
2692 register struct afs_exporter *exporter;
2693 register struct unixuser *au;
2694 register afs_int32 pag, error;
2695 int t, count, num = 0;
2696 char **sysnamelist[MAXSYSNAME];
2698 AFS_STATCNT(PSetSysName);
2699 if (!afs_globalVFS) {
2700 /* Afsd is NOT running; disable it */
2701 #if defined(KERNEL_HAVE_UERROR)
2702 return (setuerror(EINVAL), EINVAL);
2707 memset(inname, 0, MAXSYSNAME);
2708 memcpy((char *)&setsysname, ain, sizeof(afs_int32));
2709 ain += sizeof(afs_int32);
2713 if (setsysname < 0 || setsysname > MAXNUMSYSNAMES)
2716 for (cp = ain, count = 0; count < setsysname; count++) {
2717 /* won't go past end of ain since maxsysname*num < ain length */
2719 if (t >= MAXSYSNAME || t <= 0)
2721 /* check for names that can shoot us in the foot */
2722 if (*cp == '.' && (cp[1] == 0 || (cp[1] == '.' && cp[2] == 0)))
2728 /* inname gets first entry in case we're being a translator */
2730 memcpy(inname, ain, t + 1); /* include terminating null */
2734 if ((*acred)->cr_gid == RMTUSER_REQ) { /* Handles all exporters */
2735 pag = PagInCred(*acred);
2737 return EINVAL; /* Better than panicing */
2739 if (!(au = afs_FindUser(pag, -1, READ_LOCK))) {
2740 return EINVAL; /* Better than panicing */
2742 if (!(exporter = au->exporter)) {
2743 afs_PutUser(au, READ_LOCK);
2744 return EINVAL; /* Better than panicing */
2746 error = EXP_SYSNAME(exporter, (setsysname ? cp2 : NULL), sysnamelist,
2749 if (error == ENODEV)
2750 foundname = 0; /* sysname not set yet! */
2752 afs_PutUser(au, READ_LOCK);
2757 strcpy(outname, (*sysnamelist)[0]);
2759 afs_PutUser(au, READ_LOCK);
2761 /* Not xlating, so local case */
2763 osi_Panic("PSetSysName: !afs_sysname\n");
2764 if (!setsysname) { /* user just wants the info */
2765 strcpy(outname, afs_sysname);
2766 foundname = afs_sysnamecount;
2767 *sysnamelist = afs_sysnamelist;
2768 } else { /* Local guy; only root can change sysname */
2769 if (!afs_osi_suser(*acred))
2772 /* clear @sys entries from the dnlc, once afs_lookup can
2773 * do lookups of @sys entries and thinks it can trust them */
2774 /* privs ok, store the entry, ... */
2775 strcpy(afs_sysname, inname);
2776 if (setsysname > 1) { /* ... or list */
2778 for (count = 1; count < setsysname; ++count) {
2779 if (!afs_sysnamelist[count])
2781 ("PSetSysName: no afs_sysnamelist entry to write\n");
2783 memcpy(afs_sysnamelist[count], cp, t + 1); /* include null */
2787 afs_sysnamecount = setsysname;
2791 cp = aout; /* not changing so report back the count and ... */
2792 memcpy(cp, (char *)&foundname, sizeof(afs_int32));
2793 cp += sizeof(afs_int32);
2795 strcpy(cp, outname); /* ... the entry, ... */
2796 cp += strlen(outname) + 1;
2797 for (count = 1; count < foundname; ++count) { /* ... or list. */
2798 if (!(*sysnamelist)[count])
2800 ("PSetSysName: no afs_sysnamelist entry to read\n");
2801 t = strlen((*sysnamelist)[count]);
2802 if (t >= MAXSYSNAME)
2803 osi_Panic("PSetSysName: sysname entry garbled\n");
2804 strcpy(cp, (*sysnamelist)[count]);
2808 *aoutSize = cp - aout;
2813 /* sequential search through the list of touched cells is not a good
2814 * long-term solution here. For small n, though, it should be just
2815 * fine. Should consider special-casing the local cell for large n.
2816 * Likewise for PSetSPrefs.
2818 * s - number of ids in array l[] -- NOT index of last id
2819 * l - array of cell ids which have volumes that need to be sorted
2820 * vlonly - sort vl servers or file servers?
2823 ReSortCells_cb(struct cell *cell, void *arg)
2825 afs_int32 *p = (afs_int32 *) arg;
2826 afs_int32 *l = p + 1;
2829 for (i = 0; i < s; i++) {
2830 if (l[i] == cell->cellNum) {
2831 ObtainWriteLock(&cell->lock, 690);
2832 afs_SortServers(cell->cellHosts, MAXCELLHOSTS);
2833 ReleaseWriteLock(&cell->lock);
2841 ReSortCells(int s, afs_int32 * l, int vlonly)
2849 p = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * (s + 1));
2851 memcpy(p + 1, l, s * sizeof(afs_int32));
2852 afs_TraverseCells(&ReSortCells_cb, p);
2853 afs_osi_Free(p, sizeof(afs_int32) * (s + 1));
2857 ObtainReadLock(&afs_xvolume);
2858 for (i = 0; i < NVOLS; i++) {
2859 for (j = afs_volumes[i]; j; j = j->next) {
2860 for (k = 0; k < s; k++)
2861 if (j->cell == l[k]) {
2862 ObtainWriteLock(&j->lock, 233);
2863 afs_SortServers(j->serverHost, MAXHOSTS);
2864 ReleaseWriteLock(&j->lock);
2869 ReleaseReadLock(&afs_xvolume);
2873 static int debugsetsp = 0;
2875 afs_setsprefs(sp, num, vlonly)
2878 unsigned int vlonly;
2881 int i, j, k, matches, touchedSize;
2882 struct server *srvr = NULL;
2883 afs_int32 touched[34];
2887 for (k = 0; k < num; sp++, k++) {
2889 printf("sp host=%x, rank=%d\n", sp->host.s_addr, sp->rank);
2892 ObtainReadLock(&afs_xserver);
2894 i = SHash(sp->host.s_addr);
2895 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2896 if (sa->sa_ip == sp->host.s_addr) {
2898 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
2899 || (sa->sa_portal == AFS_FSPORT);
2900 if ((!vlonly && isfs) || (vlonly && !isfs)) {
2907 if (sa && matches) { /* found one! */
2909 printf("sa ip=%x, ip_rank=%d\n", sa->sa_ip, sa->sa_iprank);
2911 sa->sa_iprank = sp->rank + afs_randomMod15();
2912 afs_SortOneServer(sa->server);
2915 /* if we don't know yet what cell it's in, this is moot */
2916 for (j = touchedSize - 1;
2917 j >= 0 && touched[j] != srvr->cell->cellNum; j--)
2918 /* is it in our list of touched cells ? */ ;
2919 if (j < 0) { /* no, it's not */
2920 touched[touchedSize++] = srvr->cell->cellNum;
2921 if (touchedSize >= 32) { /* watch for ovrflow */
2922 ReleaseReadLock(&afs_xserver);
2923 ReSortCells(touchedSize, touched, vlonly);
2925 ObtainReadLock(&afs_xserver);
2931 ReleaseReadLock(&afs_xserver);
2932 /* if we didn't find one, start to create one. */
2933 /* Note that it doesn't have a cell yet... */
2935 afs_uint32 temp = sp->host.s_addr;
2937 afs_GetServer(&temp, 1, 0, (vlonly ? AFS_VLPORT : AFS_FSPORT),
2938 WRITE_LOCK, (afsUUID *) 0, 0);
2939 srvr->addr->sa_iprank = sp->rank + afs_randomMod15();
2940 afs_PutServer(srvr, WRITE_LOCK);
2942 } /* for all cited preferences */
2944 ReSortCells(touchedSize, touched, vlonly);
2948 /* Note that this may only be performed by the local root user.
2950 DECL_PIOCTL(PSetSPrefs)
2952 struct setspref *ssp;
2953 AFS_STATCNT(PSetSPrefs);
2955 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2956 return EIO; /* Inappropriate ioctl for device */
2958 if (!afs_osi_suser(*acred))
2961 if (ainSize < sizeof(struct setspref))
2964 ssp = (struct setspref *)ain;
2965 if (ainSize < sizeof(struct spref) * ssp->num_servers)
2968 afs_setsprefs(&(ssp->servers[0]), ssp->num_servers,
2969 (ssp->flags & DBservers));
2973 DECL_PIOCTL(PSetSPrefs33)
2976 AFS_STATCNT(PSetSPrefs);
2977 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2978 return EIO; /* Inappropriate ioctl for device */
2981 if (!afs_osi_suser(*acred))
2984 sp = (struct spref *)ain;
2985 afs_setsprefs(sp, ainSize / (sizeof(struct spref)), 0 /*!vlonly */ );
2989 /* some notes on the following code...
2990 * in the hash table of server structs, all servers with the same IP address
2991 * will be on the same overflow chain.
2992 * This could be sped slightly in some circumstances by having it cache the
2993 * immediately previous slot in the hash table and some supporting information
2994 * Only reports file servers now.
2996 DECL_PIOCTL(PGetSPrefs)
2998 struct sprefrequest *spin; /* input */
2999 struct sprefinfo *spout; /* output */
3000 struct spref *srvout; /* one output component */
3001 int i, j; /* counters for hash table traversal */
3002 struct server *srvr; /* one of CM's server structs */
3004 int vlonly; /* just return vlservers ? */
3007 AFS_STATCNT(PGetSPrefs);
3008 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3009 return EIO; /* Inappropriate ioctl for device */
3012 if (ainSize < sizeof(struct sprefrequest_33)) {
3015 spin = ((struct sprefrequest *)ain);
3018 if (ainSize > sizeof(struct sprefrequest_33)) {
3019 vlonly = (spin->flags & DBservers);
3023 /* struct sprefinfo includes 1 server struct... that size gets added
3024 * in during the loop that follows.
3026 *aoutSize = sizeof(struct sprefinfo) - sizeof(struct spref);
3027 spout = (struct sprefinfo *)aout;
3028 spout->next_offset = spin->offset;
3029 spout->num_servers = 0;
3030 srvout = spout->servers;
3032 ObtainReadLock(&afs_xserver);
3033 for (i = 0, j = 0; j < NSERVERS; j++) { /* sift through hash table */
3034 for (sa = afs_srvAddrs[j]; sa; sa = sa->next_bkt, i++) {
3035 if (spin->offset > (unsigned short)i) {
3036 continue; /* catch up to where we left off */
3038 spout->next_offset++;
3041 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
3042 || (sa->sa_portal == AFS_FSPORT);
3044 if ((vlonly && isfs) || (!vlonly && !isfs)) {
3045 /* only report ranks for vl servers */
3049 srvout->host.s_addr = sa->sa_ip;
3050 srvout->rank = sa->sa_iprank;
3051 *aoutSize += sizeof(struct spref);
3052 spout->num_servers++;
3055 if (*aoutSize > (PIGGYSIZE - sizeof(struct spref))) {
3056 ReleaseReadLock(&afs_xserver); /* no more room! */
3061 ReleaseReadLock(&afs_xserver);
3063 spout->next_offset = 0; /* start over from the beginning next time */
3067 /* Enable/Disable the specified exporter. Must be root to disable an exporter */
3068 int afs_NFSRootOnly = 1;
3069 DECL_PIOCTL(PExportAfs)
3071 afs_int32 export, newint =
3072 0, type, changestate, handleValue, convmode, pwsync, smounts;
3073 register struct afs_exporter *exporter;
3075 AFS_STATCNT(PExportAfs);
3076 memcpy((char *)&handleValue, ain, sizeof(afs_int32));
3077 type = handleValue >> 24;
3082 exporter = exporter_find(type);
3084 export = handleValue & 3;
3085 changestate = handleValue & 0xff;
3086 smounts = (handleValue >> 2) & 3;
3087 pwsync = (handleValue >> 4) & 3;
3088 convmode = (handleValue >> 6) & 3;
3090 changestate = (handleValue >> 16) & 0x1;
3091 convmode = (handleValue >> 16) & 0x2;
3092 pwsync = (handleValue >> 16) & 0x4;
3093 smounts = (handleValue >> 16) & 0x8;
3094 export = handleValue & 0xff;
3097 /* Failed finding desired exporter; */
3101 handleValue = exporter->exp_states;
3102 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3103 *aoutSize = sizeof(afs_int32);
3105 if (!afs_osi_suser(*acred))
3106 return EACCES; /* Only superuser can do this */
3110 exporter->exp_states |= EXP_EXPORTED;
3112 exporter->exp_states &= ~EXP_EXPORTED;
3116 exporter->exp_states |= EXP_UNIXMODE;
3118 exporter->exp_states &= ~EXP_UNIXMODE;
3122 exporter->exp_states |= EXP_PWSYNC;
3124 exporter->exp_states &= ~EXP_PWSYNC;
3128 afs_NFSRootOnly = 0;
3129 exporter->exp_states |= EXP_SUBMOUNTS;
3131 afs_NFSRootOnly = 1;
3132 exporter->exp_states &= ~EXP_SUBMOUNTS;
3135 handleValue = exporter->exp_states;
3136 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3137 *aoutSize = sizeof(afs_int32);
3140 exporter->exp_states |= EXP_EXPORTED;
3142 exporter->exp_states &= ~EXP_EXPORTED;
3144 exporter->exp_states |= EXP_UNIXMODE;
3146 exporter->exp_states &= ~EXP_UNIXMODE;
3148 exporter->exp_states |= EXP_PWSYNC;
3150 exporter->exp_states &= ~EXP_PWSYNC;
3152 afs_NFSRootOnly = 0;
3153 exporter->exp_states |= EXP_SUBMOUNTS;
3155 afs_NFSRootOnly = 1;
3156 exporter->exp_states &= ~EXP_SUBMOUNTS;
3166 struct gaginfo *gagflags;
3168 if (!afs_osi_suser(*acred))
3171 gagflags = (struct gaginfo *)ain;
3172 afs_showflags = gagflags->showflags;
3178 DECL_PIOCTL(PTwiddleRx)
3180 struct rxparams *rxp;
3182 if (!afs_osi_suser(*acred))
3185 rxp = (struct rxparams *)ain;
3187 if (rxp->rx_initReceiveWindow)
3188 rx_initReceiveWindow = rxp->rx_initReceiveWindow;
3189 if (rxp->rx_maxReceiveWindow)
3190 rx_maxReceiveWindow = rxp->rx_maxReceiveWindow;
3191 if (rxp->rx_initSendWindow)
3192 rx_initSendWindow = rxp->rx_initSendWindow;
3193 if (rxp->rx_maxSendWindow)
3194 rx_maxSendWindow = rxp->rx_maxSendWindow;
3195 if (rxp->rxi_nSendFrags)
3196 rxi_nSendFrags = rxp->rxi_nSendFrags;
3197 if (rxp->rxi_nRecvFrags)
3198 rxi_nRecvFrags = rxp->rxi_nRecvFrags;
3199 if (rxp->rxi_OrphanFragSize)
3200 rxi_OrphanFragSize = rxp->rxi_OrphanFragSize;
3201 if (rxp->rx_maxReceiveSize) {
3202 rx_maxReceiveSize = rxp->rx_maxReceiveSize;
3203 rx_maxReceiveSizeUser = rxp->rx_maxReceiveSize;
3205 if (rxp->rx_MyMaxSendSize)
3206 rx_MyMaxSendSize = rxp->rx_MyMaxSendSize;
3211 DECL_PIOCTL(PGetInitParams)
3213 if (sizeof(struct cm_initparams) > PIGGYSIZE)
3216 memcpy(aout, (char *)&cm_initParams, sizeof(struct cm_initparams));
3217 *aoutSize = sizeof(struct cm_initparams);
3221 #ifdef AFS_SGI65_ENV
3222 /* They took crget() from us, so fake it. */
3227 cr = crdup(get_current_cred());
3228 memset((char *)cr, 0, sizeof(cred_t));
3229 #if CELL || CELL_PREPARE
3236 DECL_PIOCTL(PGetRxkcrypt)
3238 memcpy(aout, (char *)&cryptall, sizeof(afs_int32));
3239 *aoutSize = sizeof(afs_int32);
3243 DECL_PIOCTL(PSetRxkcrypt)
3247 if (!afs_osi_suser(*acred))
3249 if (ainSize != sizeof(afs_int32) || ain == NULL)
3251 memcpy((char *)&tmpval, ain, sizeof(afs_int32));
3252 /* if new mappings added later this will need to be changed */
3253 if (tmpval != 0 && tmpval != 1)
3259 #ifdef AFS_NEED_CLIENTCONTEXT
3261 * Create new credentials to correspond to a remote user with given
3262 * <hostaddr, uid, g0, g1>. This allows a server running as root to
3263 * provide pioctl (and other) services to foreign clients (i.e. nfs
3264 * clients) by using this call to `become' the client.
3267 #define PIOCTL_HEADER 6
3269 HandleClientContext(struct afs_ioctl *ablob, int *com,
3270 struct AFS_UCRED **acred, struct AFS_UCRED *credp)
3273 afs_uint32 hostaddr;
3274 afs_int32 uid, g0, g1, i, code, pag, exporter_type;
3275 struct afs_exporter *exporter, *outexporter;
3276 struct AFS_UCRED *newcred;
3277 struct unixuser *au;
3279 #if defined(AFS_SGIMP_ENV)
3280 osi_Assert(ISAFS_GLOCK());
3282 AFS_STATCNT(HandleClientContext);
3283 if (ablob->in_size < PIOCTL_HEADER * sizeof(afs_int32)) {
3284 /* Must at least include the PIOCTL_HEADER header words required by the protocol */
3285 return EINVAL; /* Too small to be good */
3287 ain = inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
3288 AFS_COPYIN(ablob->in, ain, PIOCTL_HEADER * sizeof(afs_int32), code);
3290 osi_FreeLargeSpace(inData);
3294 /* Extract information for remote user */
3295 hostaddr = *((afs_uint32 *) ain);
3296 ain += sizeof(hostaddr);
3297 uid = *((afs_uint32 *) ain);
3299 g0 = *((afs_uint32 *) ain);
3301 g1 = *((afs_uint32 *) ain);
3303 *com = *((afs_uint32 *) ain);
3304 ain += sizeof(afs_int32);
3305 exporter_type = *((afs_uint32 *) ain); /* In case we support more than NFS */
3308 * Of course, one must be root for most of these functions, but
3309 * we'll allow (for knfs) you to set things if the pag is 0 and
3310 * you're setting tokens or unlogging.
3313 if (!afs_osi_suser(credp)) {
3314 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
3315 /* Since SGI's suser() returns explicit failure after the call.. */
3318 /* check for acceptable opcodes for normal folks, which are, so far,
3319 * set tokens and unlog.
3321 if (i != 9 && i != 3 && i != 38 && i != 8) {
3322 osi_FreeLargeSpace(inData);
3327 ablob->in_size -= PIOCTL_HEADER * sizeof(afs_int32);
3328 ablob->in += PIOCTL_HEADER * sizeof(afs_int32);
3329 osi_FreeLargeSpace(inData);
3332 * We map uid 0 to nobody to match the mapping that the nfs
3333 * server does and to ensure that the suser() calls in the afs
3334 * code fails for remote client roots.
3336 uid = afs_nobody; /* NFS_NOBODY == -2 */
3339 #ifdef AFS_AIX41_ENV
3342 newcred->cr_gid = RMTUSER_REQ;
3343 #ifdef AFS_AIX51_ENV
3344 newcred->cr_groupset.gs_union.un_groups[0] = g0;
3345 newcred->cr_groupset.gs_union.un_groups[1] = g1;
3347 newcred->cr_groups[0] = g0;
3348 newcred->cr_groups[1] = g1;
3351 newcred->cr_ngrps = 2;
3353 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV)
3354 newcred->cr_ngroups = 2;
3356 for (i = 2; i < NGROUPS; i++)
3357 newcred->cr_groups[i] = NOGROUP;
3360 #if !defined(AFS_OSF_ENV) && !defined(AFS_DEC_ENV)
3361 afs_nfsclient_init(); /* before looking for exporter, ensure one exists */
3363 if (!(exporter = exporter_find(exporter_type))) {
3364 /* Exporter wasn't initialized or an invalid exporter type */
3368 if (exporter->exp_states & EXP_PWSYNC) {
3369 if (uid != credp->cr_uid) {
3371 return ENOEXEC; /* XXX Find a better errno XXX */
3374 newcred->cr_uid = uid; /* Only temporary */
3375 code = EXP_REQHANDLER(exporter, &newcred, hostaddr, &pag, &outexporter);
3376 /* The client's pag is the only unique identifier for it */
3377 newcred->cr_uid = pag;
3379 if (!code && *com == PSETPAG) {
3380 /* Special case for 'setpag' */
3381 afs_uint32 pagvalue = genpag();
3383 au = afs_GetUser(pagvalue, -1, WRITE_LOCK); /* a new unixuser struct */
3385 * Note that we leave the 'outexporter' struct held so it won't
3388 au->exporter = outexporter;
3389 if (ablob->out_size >= 4) {
3390 AFS_COPYOUT((char *)&pagvalue, ablob->out, sizeof(afs_int32),
3393 afs_PutUser(au, WRITE_LOCK);
3396 return PSETPAG; /* Special return for setpag */
3398 EXP_RELE(outexporter);
3402 #endif /* AFS_NEED_CLIENTCONTEXT */
3404 /* get all interface addresses of this client */
3406 DECL_PIOCTL(PGetCPrefs)
3408 struct sprefrequest *spin; /* input */
3409 struct sprefinfo *spout; /* output */
3410 struct spref *srvout; /* one output component */
3414 AFS_STATCNT(PGetCPrefs);
3415 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3416 return EIO; /* Inappropriate ioctl for device */
3418 if (ainSize < sizeof(struct sprefrequest))
3421 spin = (struct sprefrequest *)ain;
3422 spout = (struct sprefinfo *)aout;
3424 maxNumber = spin->num_servers; /* max addrs this time */
3425 srvout = spout->servers;
3427 ObtainReadLock(&afs_xinterface);
3429 /* copy out the client interface information from the
3430 ** kernel data structure "interface" to the output buffer
3432 for (i = spin->offset, j = 0; (i < afs_cb_interface.numberOfInterfaces)
3433 && (j < maxNumber); i++, j++, srvout++)
3434 srvout->host.s_addr = afs_cb_interface.addr_in[i];
3436 spout->num_servers = j;
3437 *aoutSize = sizeof(struct sprefinfo) + (j - 1) * sizeof(struct spref);
3439 if (i >= afs_cb_interface.numberOfInterfaces)
3440 spout->next_offset = 0; /* start from beginning again */
3442 spout->next_offset = spin->offset + j;
3444 ReleaseReadLock(&afs_xinterface);
3448 DECL_PIOCTL(PSetCPrefs)
3450 struct setspref *sin;
3453 AFS_STATCNT(PSetCPrefs);
3454 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3455 return EIO; /* Inappropriate ioctl for device */
3457 sin = (struct setspref *)ain;
3459 if (ainSize < sizeof(struct setspref))
3461 #if 0 /* num_servers is unsigned */
3462 if (sin->num_servers < 0)
3465 if (sin->num_servers > AFS_MAX_INTERFACE_ADDR)
3468 ObtainWriteLock(&afs_xinterface, 412);
3469 afs_cb_interface.numberOfInterfaces = sin->num_servers;
3470 for (i = 0; (unsigned short)i < sin->num_servers; i++)
3471 afs_cb_interface.addr_in[i] = sin->servers[i].host.s_addr;
3473 ReleaseWriteLock(&afs_xinterface);
3477 DECL_PIOCTL(PFlushMount)
3479 register afs_int32 code;
3480 register struct vcache *tvc;
3481 register struct dcache *tdc;
3482 struct VenusFid tfid;
3484 struct sysname_info sysState;
3485 afs_size_t offset, len;
3487 AFS_STATCNT(PFlushMount);
3490 code = afs_VerifyVCache(avc, areq);
3493 if (vType(avc) != VDIR) {
3496 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
3499 Check_AtSys(avc, ain, &sysState, areq);
3500 ObtainReadLock(&tdc->lock);
3502 code = afs_dir_Lookup(&tdc->f.inode, sysState.name, &tfid.Fid);
3503 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
3504 ReleaseReadLock(&tdc->lock);
3505 afs_PutDCache(tdc); /* we're done with the data */
3506 bufp = sysState.name;
3510 tfid.Cell = avc->fid.Cell;
3511 tfid.Fid.Volume = avc->fid.Fid.Volume;
3512 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
3513 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
3515 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3521 if (tvc->mvstat != 1) {
3526 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
3527 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
3529 ObtainWriteLock(&tvc->lock, 649);
3530 ObtainWriteLock(&afs_xcbhash, 650);
3531 afs_DequeueCallback(tvc);
3532 tvc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
3533 ReleaseWriteLock(&afs_xcbhash);
3534 /* now find the disk cache entries */
3535 afs_TryToSmush(tvc, *acred, 1);
3536 osi_dnlc_purgedp(tvc);
3537 afs_symhint_inval(tvc);
3538 if (tvc->linkData && !(tvc->states & CCore)) {
3539 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
3540 tvc->linkData = NULL;
3542 ReleaseWriteLock(&tvc->lock);
3543 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
3544 afs_BozonUnlock(&tvc->pvnLock, tvc);
3548 if (sysState.allocked)
3549 osi_FreeLargeSpace(bufp);
3553 DECL_PIOCTL(PRxStatProc)
3558 if (!afs_osi_suser(*acred)) {
3562 if (ainSize != sizeof(afs_int32)) {
3566 memcpy((char *)&flags, ain, sizeof(afs_int32));
3567 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3571 if (flags & AFSCALL_RXSTATS_ENABLE) {
3572 rx_enableProcessRPCStats();
3574 if (flags & AFSCALL_RXSTATS_DISABLE) {
3575 rx_disableProcessRPCStats();
3577 if (flags & AFSCALL_RXSTATS_CLEAR) {
3578 rx_clearProcessRPCStats(AFS_RX_STATS_CLEAR_ALL);
3586 DECL_PIOCTL(PRxStatPeer)
3591 if (!afs_osi_suser(*acred)) {
3595 if (ainSize != sizeof(afs_int32)) {
3599 memcpy((char *)&flags, ain, sizeof(afs_int32));
3600 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3604 if (flags & AFSCALL_RXSTATS_ENABLE) {
3605 rx_enablePeerRPCStats();
3607 if (flags & AFSCALL_RXSTATS_DISABLE) {
3608 rx_disablePeerRPCStats();
3610 if (flags & AFSCALL_RXSTATS_CLEAR) {
3611 rx_clearPeerRPCStats(AFS_RX_STATS_CLEAR_ALL);
3618 DECL_PIOCTL(PPrefetchFromTape)
3620 register afs_int32 code, code1;
3623 struct rx_call *tcall;
3624 struct AFSVolSync tsync;
3625 struct AFSFetchStatus OutStatus;
3626 struct AFSCallBack CallBack;
3627 struct VenusFid tfid;
3631 AFS_STATCNT(PSetAcl);
3635 if (ain && (ainSize == 3 * sizeof(afs_int32)))
3636 Fid = (struct AFSFid *)ain;
3638 Fid = &avc->fid.Fid;
3639 tfid.Cell = avc->fid.Cell;
3640 tfid.Fid.Volume = Fid->Volume;
3641 tfid.Fid.Vnode = Fid->Vnode;
3642 tfid.Fid.Unique = Fid->Unique;
3644 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3646 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3647 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &avc->fid);
3650 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3651 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &tvc->fid);
3654 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3658 tcall = rx_NewCall(tc->id);
3660 StartRXAFS_FetchData(tcall, (struct AFSFid *)&tvc->fid.Fid, 0,
3663 bytes = rx_Read(tcall, (char *)aout, sizeof(afs_int32));
3665 EndRXAFS_FetchData(tcall, &OutStatus, &CallBack, &tsync);
3667 code1 = rx_EndCall(tcall, code);
3671 } while (afs_Analyze
3672 (tc, code, &tvc->fid, areq, AFS_STATS_FS_RPCIDX_RESIDENCYRPCS,
3673 SHARED_LOCK, NULL));
3674 /* This call is done only to have the callback things handled correctly */
3675 afs_FetchStatus(tvc, &tfid, areq, &OutStatus);
3679 *aoutSize = sizeof(afs_int32);
3684 DECL_PIOCTL(PResidencyCmd)
3686 register afs_int32 code;
3689 struct ResidencyCmdInputs *Inputs;
3690 struct ResidencyCmdOutputs *Outputs;
3691 struct VenusFid tfid;
3694 Inputs = (struct ResidencyCmdInputs *)ain;
3695 Outputs = (struct ResidencyCmdOutputs *)aout;
3698 if (!ain || ainSize != sizeof(struct ResidencyCmdInputs))
3703 Fid = &avc->fid.Fid;
3705 tfid.Cell = avc->fid.Cell;
3706 tfid.Fid.Volume = Fid->Volume;
3707 tfid.Fid.Vnode = Fid->Vnode;
3708 tfid.Fid.Unique = Fid->Unique;
3710 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3711 afs_Trace3(afs_iclSetp, CM_TRACE_RESIDCMD, ICL_TYPE_POINTER, tvc,
3712 ICL_TYPE_INT32, Inputs->command, ICL_TYPE_FID, &tfid);
3716 if (Inputs->command) {
3718 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3722 RXAFS_ResidencyCmd(tc->id, Fid, Inputs,
3723 (struct ResidencyCmdOutputs *)aout);
3727 } while (afs_Analyze
3728 (tc, code, &tvc->fid, areq,
3729 AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK, NULL));
3730 /* This call is done to have the callback things handled correctly */
3731 afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3732 } else { /* just a status request, return also link data */
3734 Outputs->code = afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3735 Outputs->chars[0] = 0;
3736 if (vType(tvc) == VLNK) {
3737 ObtainWriteLock(&tvc->lock, 555);
3738 if (afs_HandleLink(tvc, areq) == 0)
3739 strncpy((char *)&Outputs->chars, tvc->linkData, MAXCMDCHARS);
3740 ReleaseWriteLock(&tvc->lock);
3747 *aoutSize = sizeof(struct ResidencyCmdOutputs);
3752 DECL_PIOCTL(PCallBackAddr)
3755 afs_uint32 addr, code;
3761 struct unixuser *tu;
3762 struct srvAddr **addrs;
3764 /*AFS_STATCNT(PCallBackAddr);*/
3765 if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */
3766 return EIO; /* Inappropriate ioctl for device */
3768 if (!afs_osi_suser(acred))
3771 if ( ainSize < sizeof(afs_int32) )
3774 memcpy(&addr, ain, sizeof(afs_int32));
3776 ObtainReadLock(&afs_xinterface);
3777 for ( i=0; (unsigned short)i < afs_cb_interface.numberOfInterfaces; i++) {
3778 if (afs_cb_interface.addr_in[i] == addr) break;
3781 ReleaseWriteLock(&afs_xinterface);
3783 if (afs_cb_interface.addr_in[i] != addr)
3786 ObtainReadLock(&afs_xserver); /* Necessary? */
3787 ObtainReadLock(&afs_xsrvAddr);
3790 for (i=0;i<NSERVERS;i++) {
3791 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3796 addrs = afs_osi_Alloc(srvAddrCount * sizeof(*addrs));
3798 for (i=0;i<NSERVERS;i++) {
3799 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3800 if (j >= srvAddrCount) break;
3805 ReleaseReadLock(&afs_xsrvAddr);
3806 ReleaseReadLock(&afs_xserver);
3808 for (i=0; i<j; i++) {
3814 /* vlserver has no callback conn */
3815 if (sa->sa_portal == AFS_VLPORT) {
3819 if (!ts->cell) /* not really an active server, anyway, it must */
3820 continue; /* have just been added by setsprefs */
3822 /* get a connection, even if host is down; bumps conn ref count */
3823 tu = afs_GetUser(areq->uid, ts->cell->cellNum, SHARED_LOCK);
3824 tc = afs_ConnBySA(sa, ts->cell->fsport, ts->cell->cellNum, tu,
3825 1/*force*/, 1/*create*/, SHARED_LOCK);
3826 afs_PutUser(tu, SHARED_LOCK);
3830 if ((sa->sa_flags & SRVADDR_ISDOWN) || afs_HaveCallBacksFrom(ts)) {
3831 if (sa->sa_flags & SRVADDR_ISDOWN) {
3832 rx_SetConnDeadTime(tc->id, 3);
3835 #ifdef RX_ENABLE_LOCKS
3837 #endif /* RX_ENABLE_LOCKS */
3838 code = RXAFS_CallBackRxConnAddr(tc->id, &addr);
3839 #ifdef RX_ENABLE_LOCKS
3841 #endif /* RX_ENABLE_LOCKS */
3843 afs_PutConn(tc, SHARED_LOCK); /* done with it now */
3844 } /* Outer loop over addrs */
3845 #endif /* UKERNEL */