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);
93 * A macro that says whether we're going to need HandleClientContext().
94 * This is currently used only by the nfs translator.
96 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
97 #define AFS_NEED_CLIENTCONTEXT
100 /* Prototypes for private routines */
101 #ifdef AFS_NEED_CLIENTCONTEXT
102 static int HandleClientContext(struct afs_ioctl *ablob, int *com,
103 struct AFS_UCRED **acred,
104 struct AFS_UCRED *credp);
106 int HandleIoctl(register struct vcache *avc, register afs_int32 acom,
107 struct afs_ioctl *adata);
108 int afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
109 register struct afs_ioctl *ablob, int afollow,
110 struct AFS_UCRED **acred);
111 static int Prefetch(char *apath, struct afs_ioctl *adata, int afollow,
112 struct AFS_UCRED *acred);
115 static int (*(VpioctlSw[])) () = {
120 PGetVolumeStatus, /* 4 */
121 PSetVolumeStatus, /* 5 */
126 PCheckServers, /* 10 */
127 PCheckVolNames, /* 11 */
129 PBogus, /* 13 -- used to be quick check time */
130 PFindVolume, /* 14 */
131 PBogus, /* 15 -- prefetch is now special-cased; see pioctl code! */
132 PBogus, /* 16 -- used to be testing code */
133 PNoop, /* 17 -- used to be enable group */
134 PNoop, /* 18 -- used to be disable group */
135 PBogus, /* 19 -- used to be list group */
136 PViceAccess, /* 20 */
137 PUnlog, /* 21 -- unlog *is* unpag in this system */
138 PGetFID, /* 22 -- get file ID */
139 PBogus, /* 23 -- used to be waitforever */
140 PSetCacheSize, /* 24 */
141 PRemoveCallBack, /* 25 -- flush only the callback */
144 PRemoveMount, /* 28 -- delete mount point */
145 PNewStatMount, /* 29 -- new style mount point stat */
146 PGetFileCell, /* 30 -- get cell name for input file */
147 PGetWSCell, /* 31 -- get cell name for workstation */
148 PMariner, /* 32 - set/get mariner host */
149 PGetUserCell, /* 33 -- get cell name for user */
150 PVenusLogging, /* 34 -- Enable/Disable logging */
151 PGetCellStatus, /* 35 */
152 PSetCellStatus, /* 36 */
153 PFlushVolumeData, /* 37 -- flush all data from a volume */
154 PSetSysName, /* 38 - Set system name */
155 PExportAfs, /* 39 - Export Afs to remote nfs clients */
156 PGetCacheSize, /* 40 - get cache size and usage */
157 PGetVnodeXStatus, /* 41 - get vcache's special status */
158 PSetSPrefs33, /* 42 - Set CM Server preferences... */
159 PGetSPrefs, /* 43 - Get CM Server preferences... */
160 PGag, /* 44 - turn off/on all CM messages */
161 PTwiddleRx, /* 45 - adjust some RX params */
162 PSetSPrefs, /* 46 - Set CM Server preferences... */
163 PStoreBehind, /* 47 - set degree of store behind to be done */
164 PGCPAGs, /* 48 - disable automatic pag gc-ing */
165 PGetInitParams, /* 49 - get initial cm params */
166 PGetCPrefs, /* 50 - get client interface addresses */
167 PSetCPrefs, /* 51 - set client interface addresses */
168 PFlushMount, /* 52 - flush mount symlink data */
169 PRxStatProc, /* 53 - control process RX statistics */
170 PRxStatPeer, /* 54 - control peer RX statistics */
171 PGetRxkcrypt, /* 55 -- Get rxkad encryption flag */
172 PSetRxkcrypt, /* 56 -- Set rxkad encryption flag */
173 PBogus, /* 57 -- arla: set file prio */
174 PBogus, /* 58 -- arla: fallback getfh */
175 PBogus, /* 59 -- arla: fallback fhopen */
176 PBogus, /* 60 -- arla: controls xfsdebug */
177 PBogus, /* 61 -- arla: controls arla debug */
178 PBogus, /* 62 -- arla: debug interface */
179 PBogus, /* 63 -- arla: print xfs status */
180 PBogus, /* 64 -- arla: force cache check */
181 PBogus, /* 65 -- arla: break callback */
182 PPrefetchFromTape, /* 66 -- MR-AFS: prefetch file from tape */
183 PResidencyCmd, /* 67 -- MR-AFS: generic commnd interface */
184 PBogus, /* 68 -- arla: fetch stats */
187 static int (*(CpioctlSw[])) () = {
189 PNewAlias, /* 1 -- create new cell alias */
190 PListAliases, /* 2 -- list cell aliases */
193 #define PSetClientContext 99 /* Special pioctl to setup caller's creds */
194 int afs_nobody = NFS_NOBODY;
197 afs_ioctl32_to_afs_ioctl(const struct afs_ioctl32 *src, struct afs_ioctl *dst)
199 dst->in = (char *)(unsigned long)src->in;
200 dst->out = (char *)(unsigned long)src->out;
201 dst->in_size = src->in_size;
202 dst->out_size = src->out_size;
206 * If you need to change copyin_afs_ioctl(), you may also need to change
211 copyin_afs_ioctl(caddr_t cmarg, struct afs_ioctl *dst)
214 #if defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)
215 struct afs_ioctl32 dst32;
218 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
220 afs_ioctl32_to_afs_ioctl(&dst32, dst);
223 #endif /* defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL) */
226 #if defined(AFS_HPUX_64BIT_ENV)
227 struct afs_ioctl32 dst32;
229 if (is_32bit(u.u_procp)) { /* is_32bit() in proc_iface.h */
230 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
232 afs_ioctl32_to_afs_ioctl(&dst32, dst);
235 #endif /* defined(AFS_HPUX_64BIT_ENV) */
237 #if defined(AFS_SUN57_64BIT_ENV)
238 struct afs_ioctl32 dst32;
240 if (get_udatamodel() == DATAMODEL_ILP32) {
241 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
243 afs_ioctl32_to_afs_ioctl(&dst32, dst);
246 #endif /* defined(AFS_SUN57_64BIT_ENV) */
248 #if defined(AFS_SGI_ENV) && (_MIPS_SZLONG==64)
249 struct afs_ioctl32 dst32;
251 if (!ABI_IS_64BIT(get_current_abi())) {
252 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
254 afs_ioctl32_to_afs_ioctl(&dst32, dst);
257 #endif /* defined(AFS_SGI_ENV) && (_MIPS_SZLONG==64) */
259 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV) && !defined(AFS_AMD64_LINUX20_ENV)
260 struct afs_ioctl32 dst32;
262 #ifdef AFS_SPARC64_LINUX24_ENV
263 if (current->thread.flags & SPARC_FLAG_32BIT)
264 #elif defined(AFS_SPARC64_LINUX20_ENV)
265 if (current->tss.flags & SPARC_FLAG_32BIT)
266 #elif defined(AFS_AMD64_LINUX20_ENV)
267 if (current->thread.flags & THREAD_IA32)
268 #elif defined(AFS_PPC64_LINUX20_ENV)
269 if (current->thread.flags & PPC_FLAG_32BIT)
271 #error Not done for this linux type
274 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
276 afs_ioctl32_to_afs_ioctl(&dst32, dst);
279 #endif /* defined(AFS_LINUX_64BIT_KERNEL) */
281 AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code);
286 HandleIoctl(register struct vcache *avc, register afs_int32 acom,
287 struct afs_ioctl *adata)
289 register afs_int32 code;
292 AFS_STATCNT(HandleIoctl);
294 switch (acom & 0xff) {
296 avc->states |= CSafeStore;
300 /* case 2 used to be abort store, but this is no longer provided,
301 * since it is impossible to implement under normal Unix.
305 /* return the name of the cell this file is open on */
306 register struct cell *tcell;
307 register afs_int32 i;
309 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
311 i = strlen(tcell->cellName) + 1; /* bytes to copy out */
313 if (i > adata->out_size) {
314 /* 0 means we're not interested in the output */
315 if (adata->out_size != 0)
319 AFS_COPYOUT(tcell->cellName, adata->out, i, code);
321 afs_PutCell(tcell, READ_LOCK);
327 case 49: /* VIOC_GETINITPARAMS */
328 if (adata->out_size < sizeof(struct cm_initparams)) {
331 AFS_COPYOUT(&cm_initParams, adata->out,
332 sizeof(struct cm_initparams), code);
344 return code; /* so far, none implemented */
349 /* For aix we don't temporarily bypass ioctl(2) but rather do our
350 * thing directly in the vnode layer call, VNOP_IOCTL; thus afs_ioctl
351 * is now called from afs_gn_ioctl.
354 afs_ioctl(struct vcache *tvc, int cmd, int arg)
356 struct afs_ioctl data;
359 AFS_STATCNT(afs_ioctl);
360 if (((cmd >> 8) & 0xff) == 'V') {
361 /* This is a VICEIOCTL call */
362 AFS_COPYIN(arg, (caddr_t) & data, sizeof(data), error);
365 error = HandleIoctl(tvc, cmd, &data);
368 /* No-op call; just return. */
372 #endif /* AFS_AIX_ENV */
374 #if defined(AFS_SGI_ENV)
375 afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
378 , struct vopbd * vbds
382 struct afs_ioctl data;
388 AFS_STATCNT(afs_ioctl);
389 if (((cmd >> 8) & 0xff) == 'V') {
390 /* This is a VICEIOCTL call */
391 error = copyin_afs_ioctl(arg, &data);
394 locked = ISAFS_GLOCK();
397 error = HandleIoctl(tvc, cmd, &data);
402 /* No-op call; just return. */
406 #endif /* AFS_SGI_ENV */
408 /* unlike most calls here, this one uses u.u_error to return error conditions,
409 since this is really an intercepted chapter 2 call, rather than a vnode
412 /* AFS_HPUX102 and up uses VNODE ioctl instead */
413 #ifndef AFS_HPUX102_ENV
414 #if !defined(AFS_SGI_ENV)
418 kioctl(fdes, com, arg, ext, arg2, arg3)
419 #else /* __64BIT__ */
420 kioctl32(fdes, com, arg, ext, arg2, arg3)
421 #endif /* __64BIT__ */
424 kioctl(fdes, com, arg, ext)
435 } u_uap, *uap = &u_uap;
437 #if defined(AFS_SUN5_ENV)
439 struct afs_ioctl_sys {
446 struct afs_ioctl_sys *uap;
449 #elif defined(AFS_OSF_ENV)
450 afs_xioctl(p, args, retval)
459 } *uap = (struct a *)args;
460 #elif defined(AFS_FBSD50_ENV)
463 afs_xioctl(td, uap, retval)
465 register struct ioctl_args *uap;
468 struct proc *p = td->td_proc;
469 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
477 afs_xioctl(p, uap, retval)
479 register struct ioctl_args *uap;
482 #elif defined(AFS_LINUX22_ENV)
483 struct afs_ioctl_sys {
488 afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
491 struct afs_ioctl_sys ua, *uap = &ua;
500 } *uap = (struct a *)u.u_ap;
501 #endif /* AFS_SUN5_ENV */
503 #if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
505 #elif !defined(AFS_LINUX22_ENV)
506 register struct file *fd;
508 #if defined(AFS_XBSD_ENV)
509 register struct filedesc *fdp;
511 register struct vcache *tvc;
512 register int ioctlDone = 0, code = 0;
514 AFS_STATCNT(afs_xioctl);
515 #if defined(AFS_XBSD_ENV)
517 if ((u_int) uap->fd >= fdp->fd_nfiles
518 || (fd = fdp->fd_ofiles[uap->fd]) == NULL)
520 if ((fd->f_flag & (FREAD | FWRITE)) == 0)
522 #elif defined(AFS_DARWIN_ENV)
523 if ((code = fdgetf(p, uap->fd, &fd)))
525 #elif defined(AFS_LINUX22_ENV)
528 #elif defined(AFS_AIX32_ENV)
536 if (setuerror(getf(uap->fd, &fd))) {
539 #elif defined(AFS_OSF_ENV)
541 if (code = getf(&fd, uap->fd, FILE_FLAGS_NULL, &u.u_file_state))
543 #elif defined(AFS_SUN5_ENV)
544 # if defined(AFS_SUN57_ENV)
548 # elif defined(AFS_SUN54_ENV)
553 if (code = getf(uap->fd, &fd)) {
556 # endif /* AFS_SUN57_ENV */
562 /* first determine whether this is any sort of vnode */
563 #if defined(AFS_LINUX22_ENV)
568 if (fd->f_vnode->v_type == VREG || fd->f_vnode->v_type == VDIR) {
570 if (fd->f_type == DTYPE_VNODE) {
572 /* good, this is a vnode; next see if it is an AFS vnode */
573 #if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV)
574 tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */
575 #elif defined(AFS_OBSD_ENV)
577 IsAfsVnode((struct vnode *)fd->
578 f_data) ? VTOAFS((struct vnode *)fd->f_data) : NULL;
580 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
582 #endif /* AFS_LINUX22_ENV */
583 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
585 tvc = VTOAFS(afs_gntovn((struct gnode *)tvc));
586 if (!tvc) { /* shouldn't happen with held gnodes */
591 /* This is an AFS vnode */
592 if (((uap->com >> 8) & 0xff) == 'V') {
593 register struct afs_ioctl *datap;
596 (struct afs_ioctl *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
597 AFS_COPYIN((char *)uap->arg, (caddr_t) datap,
598 sizeof(struct afs_ioctl), code);
600 osi_FreeSmallSpace(datap);
602 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
605 #if defined(AFS_SUN5_ENV)
620 #else /* AFS_OSF_ENV */
624 #ifdef AFS_LINUX22_ENV
634 code = HandleIoctl(tvc, uap->com, datap);
635 osi_FreeSmallSpace(datap);
649 #if defined(AFS_LINUX22_ENV)
661 code = okioctl(fdes, com, arg, ext, arg2, arg3);
662 #else /* __64BIT__ */
663 code = okioctl32(fdes, com, arg, ext, arg2, arg3);
664 #endif /* __64BIT__ */
665 #else /* !AFS_AIX51_ENV */
666 code = okioctl(fdes, com, arg, ext);
667 #endif /* AFS_AIX51_ENV */
669 #else /* !AFS_AIX41_ENV */
671 okioctl(fdes, com, arg, ext);
672 #elif defined(AFS_SUN5_ENV)
673 #if defined(AFS_SUN57_ENV)
675 #elif defined(AFS_SUN54_ENV)
680 code = ioctl(uap, rvp);
681 #elif defined(AFS_FBSD50_ENV)
682 return ioctl(td, uap);
683 #elif defined(AFS_FBSD_ENV)
684 return ioctl(p, uap);
685 #elif defined(AFS_OBSD_ENV)
686 code = sys_ioctl(p, uap, retval);
687 #elif defined(AFS_DARWIN_ENV)
688 return ioctl(p, uap, retval);
689 #elif defined(AFS_OSF_ENV)
690 code = ioctl(p, args, retval);
697 #elif !defined(AFS_LINUX22_ENV)
711 #ifdef AFS_LINUX22_ENV
714 #if defined(KERNEL_HAVE_UERROR)
717 #if defined(AFS_AIX32_ENV) && !defined(AFS_AIX41_ENV)
718 return (getuerror()? -1 : u.u_ioctlrv);
720 return getuerror()? -1 : 0;
723 #endif /* AFS_LINUX22_ENV */
724 #endif /* AFS_SUN5_ENV */
725 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
729 #endif /* AFS_SGI_ENV */
730 #endif /* AFS_HPUX102_ENV */
732 #if defined(AFS_SGI_ENV)
733 /* "pioctl" system call entry point; just pass argument to the parameterized
742 afs_pioctl(struct pioctlargs *uap, rval_t * rvp)
746 AFS_STATCNT(afs_pioctl);
748 code = afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow);
757 #elif defined(AFS_OSF_ENV)
758 afs_pioctl(p, args, retval)
768 } *uap = (struct a *)args;
770 AFS_STATCNT(afs_pioctl);
771 return (afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow));
774 #elif defined(AFS_FBSD50_ENV)
776 afs_pioctl(td, args, retval)
786 } *uap = (struct a *)args;
788 AFS_STATCNT(afs_pioctl);
789 return (afs_syscall_pioctl
790 (uap->path, uap->cmd, uap->cmarg, uap->follow, td->td_ucred));
793 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
795 afs_pioctl(p, args, retval)
805 } *uap = (struct a *)args;
807 AFS_STATCNT(afs_pioctl);
808 return (afs_syscall_pioctl
809 (uap->path, uap->cmd, uap->cmarg, uap->follow,
810 p->p_cred->pc_ucred));
815 /* macro to avoid adding any more #ifdef's to pioctl code. */
816 #if defined(AFS_LINUX22_ENV) || defined(AFS_AIX41_ENV)
817 #define PIOCTL_FREE_CRED() crfree(credp)
819 #define PIOCTL_FREE_CRED()
824 afs_syscall_pioctl(path, com, cmarg, follow, rvp, credp)
826 struct AFS_UCRED *credp;
828 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
829 afs_syscall_pioctl(path, com, cmarg, follow, credp)
830 struct AFS_UCRED *credp;
832 afs_syscall_pioctl(path, com, cmarg, follow)
840 struct afs_ioctl data;
841 struct AFS_UCRED *tmpcred, *foreigncreds = NULL;
842 register afs_int32 code = 0;
848 struct ucred *credp = crref(); /* don't free until done! */
850 #ifdef AFS_LINUX22_ENV
851 cred_t *credp = crref(); /* don't free until done! */
855 AFS_STATCNT(afs_syscall_pioctl);
857 follow = 1; /* compat. with old venus */
858 code = copyin_afs_ioctl(cmarg, &data);
861 #if defined(KERNEL_HAVE_UERROR)
866 if ((com & 0xff) == PSetClientContext) {
867 #ifdef AFS_NEED_CLIENTCONTEXT
868 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV)
869 code = HandleClientContext(&data, &com, &foreigncreds, credp);
871 code = HandleClientContext(&data, &com, &foreigncreds, osi_curcred());
875 crfree(foreigncreds);
878 #if defined(KERNEL_HAVE_UERROR)
879 return (setuerror(code), code);
884 #else /* AFS_NEED_CLIENTCONTEXT */
886 #endif /* AFS_NEED_CLIENTCONTEXT */
888 #ifdef AFS_NEED_CLIENTCONTEXT
891 * We could have done without temporary setting the u.u_cred below
892 * (foreigncreds could be passed as param the pioctl modules)
893 * but calls such as afs_osi_suser() doesn't allow that since it
894 * references u.u_cred directly. We could, of course, do something
895 * like afs_osi_suser(cred) which, I think, is better since it
896 * generalizes and supports multi cred environments...
900 credp = foreigncreds;
901 #elif defined(AFS_AIX41_ENV)
902 tmpcred = crref(); /* XXX */
904 #elif defined(AFS_HPUX101_ENV)
905 tmpcred = p_cred(u.u_procp);
906 set_p_cred(u.u_procp, foreigncreds);
907 #elif defined(AFS_SGI_ENV)
908 tmpcred = OSI_GET_CURRENT_CRED();
909 OSI_SET_CURRENT_CRED(foreigncreds);
912 u.u_cred = foreigncreds;
915 #endif /* AFS_NEED_CLIENTCONTEXT */
916 if ((com & 0xff) == 15) {
917 /* special case prefetch so entire pathname eval occurs in helper process.
918 * otherwise, the pioctl call is essentially useless */
919 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
921 Prefetch(path, &data, follow,
922 foreigncreds ? foreigncreds : credp);
924 code = Prefetch(path, &data, follow, osi_curcred());
927 #if defined(KERNEL_HAVE_UERROR)
936 lookupname(path, USR, follow, NULL, &vp,
937 foreigncreds ? foreigncreds : credp);
939 #ifdef AFS_LINUX22_ENV
940 code = gop_lookupname(path, AFS_UIOUSER, follow, NULL, &dp);
942 vp = (struct vnode *)dp->d_inode;
944 code = gop_lookupname(path, AFS_UIOUSER, follow, NULL, &vp);
945 #endif /* AFS_LINUX22_ENV */
946 #endif /* AFS_AIX41_ENV */
950 #if defined(KERNEL_HAVE_UERROR)
958 /* now make the call if we were passed no file, or were passed an AFS file */
959 if (!vp || IsAfsVnode(vp)) {
960 #if defined(AFS_DEC_ENV)
961 /* Ultrix 4.0: can't get vcache entry unless we've got an AFS gnode.
962 * So, we must test in this part of the code. Also, must arrange to
963 * GRELE the original gnode pointer when we're done, since in Ultrix 4.0,
964 * we hold gnodes, whose references hold our vcache entries.
967 gp = vp; /* remember for "put" */
968 vp = (struct vnode *)afs_gntovn(vp); /* get vcache from gp */
971 #elif defined(AFS_SUN5_ENV)
972 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
973 #elif defined(AFS_AIX41_ENV)
975 struct ucred *cred1, *cred2;
978 cred1 = cred2 = foreigncreds;
980 cred1 = cred2 = credp;
982 code = afs_HandlePioctl(vp, com, &data, follow, &cred1);
983 if (cred1 != cred2) {
984 /* something changed the creds */
988 #elif defined(AFS_HPUX101_ENV)
990 struct ucred *cred = p_cred(u.u_procp);
991 code = afs_HandlePioctl(vp, com, &data, follow, &cred);
993 #elif defined(AFS_SGI_ENV)
996 credp = OSI_GET_CURRENT_CRED();
997 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
999 #elif defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1000 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1002 code = afs_HandlePioctl(vp, com, &data, follow, &u.u_cred);
1005 #if defined(KERNEL_HAVE_UERROR)
1008 code = EINVAL; /* not in /afs */
1019 #if defined(AFS_NEED_CLIENTCONTEXT)
1021 #ifdef AFS_AIX41_ENV
1022 crset(tmpcred); /* restore original credentials */
1024 #if defined(AFS_HPUX101_ENV)
1025 set_p_cred(u.u_procp, tmpcred); /* restore original credentials */
1026 #elif defined(AFS_SGI_ENV)
1027 OSI_SET_CURRENT_CRED(tmpcred); /* restore original credentials */
1028 #elif !defined(AFS_SUN5_ENV)
1029 osi_curcred() = tmpcred; /* restore original credentials */
1030 #endif /* AFS_HPUX101_ENV */
1031 crfree(foreigncreds);
1034 #endif /* AFS_NEED_CLIENTCONTEXT */
1036 #ifdef AFS_LINUX22_ENV
1039 AFS_RELE(vp); /* put vnode back */
1043 #if defined(KERNEL_HAVE_UERROR)
1046 return (getuerror());
1052 #define MAXPIOCTLTOKENLEN \
1053 (3*sizeof(afs_int32)+MAXKTCTICKETLEN+sizeof(struct ClearToken)+MAXKTCREALMLEN)
1056 afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
1057 register struct afs_ioctl *ablob, int afollow,
1058 struct AFS_UCRED **acred)
1061 struct vrequest treq;
1062 register afs_int32 code;
1063 register afs_int32 function, device;
1064 afs_int32 inSize, outSize, outSizeMax;
1065 char *inData, *outData;
1066 int (*(*pioctlSw)) ();
1068 struct afs_fakestat_state fakestate;
1070 avc = avp ? VTOAFS(avp) : NULL;
1071 afs_Trace3(afs_iclSetp, CM_TRACE_PIOCTL, ICL_TYPE_INT32, acom & 0xff,
1072 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, afollow);
1073 AFS_STATCNT(HandlePioctl);
1074 if ((code = afs_InitReq(&treq, *acred)))
1076 afs_InitFakeStat(&fakestate);
1078 code = afs_EvalFakeStat(&avc, &fakestate, &treq);
1080 afs_PutFakeStat(&fakestate);
1084 device = (acom & 0xff00) >> 8;
1086 case 'V': /* Original pioctls */
1087 pioctlSw = VpioctlSw;
1088 pioctlSwSize = sizeof(VpioctlSw);
1090 case 'C': /* Coordinated/common pioctls */
1091 pioctlSw = CpioctlSw;
1092 pioctlSwSize = sizeof(CpioctlSw);
1095 afs_PutFakeStat(&fakestate);
1098 function = acom & 0xff;
1099 if (function >= (pioctlSwSize / sizeof(char *))) {
1100 afs_PutFakeStat(&fakestate);
1101 return EINVAL; /* out of range */
1103 inSize = ablob->in_size;
1105 /* Do all range checking before continuing */
1106 if (inSize > MAXPIOCTLTOKENLEN || inSize < 0 || ablob->out_size < 0)
1109 if (inSize > AFS_LRALLOCSIZ) {
1110 inData = osi_AllocLargeSpace(inSize+1);
1112 inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1117 AFS_COPYIN(ablob->in, inData, inSize, code);
1118 inData[inSize] = '\0';
1122 if (inSize > AFS_LRALLOCSIZ) {
1123 osi_Free(inData, inSize+1);
1125 osi_FreeLargeSpace(inData);
1127 afs_PutFakeStat(&fakestate);
1130 if (function == 8 && device == 'V') { /* PGetTokens */
1131 outSizeMax = MAXPIOCTLTOKENLEN;
1132 outData = osi_Alloc(outSizeMax);
1134 outSizeMax = AFS_LRALLOCSIZ;
1135 outData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1138 if (inSize > AFS_LRALLOCSIZ) {
1139 osi_Free(inData, inSize+1);
1141 osi_FreeLargeSpace(inData);
1147 (*pioctlSw[function]) (avc, function, &treq, inData, outData, inSize,
1149 if (inSize > AFS_LRALLOCSIZ) {
1150 osi_Free(inData, inSize+1);
1152 osi_FreeLargeSpace(inData);
1154 if (code == 0 && ablob->out_size > 0) {
1155 if (outSize > ablob->out_size) {
1156 code = E2BIG; /* data wont fit in user buffer */
1157 } else if (outSize) {
1158 AFS_COPYOUT(outData, ablob->out, outSize, code);
1161 if (outSizeMax > AFS_LRALLOCSIZ) {
1162 osi_Free(outData, outSizeMax);
1164 osi_FreeLargeSpace(outData);
1166 afs_PutFakeStat(&fakestate);
1167 return afs_CheckCode(code, &treq, 41);
1170 DECL_PIOCTL(PGetFID)
1172 AFS_STATCNT(PGetFID);
1175 memcpy(aout, (char *)&avc->fid, sizeof(struct VenusFid));
1176 *aoutSize = sizeof(struct VenusFid);
1180 DECL_PIOCTL(PSetAcl)
1182 register afs_int32 code;
1184 struct AFSOpaque acl;
1185 struct AFSVolSync tsync;
1186 struct AFSFetchStatus OutStatus;
1189 AFS_STATCNT(PSetAcl);
1192 if ((acl.AFSOpaque_len = strlen(ain) + 1) > 1000)
1195 acl.AFSOpaque_val = ain;
1197 tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1199 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREACL);
1202 RXAFS_StoreACL(tconn->id, (struct AFSFid *)&avc->fid.Fid,
1203 &acl, &OutStatus, &tsync);
1208 } while (afs_Analyze
1209 (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_STOREACL,
1210 SHARED_LOCK, NULL));
1212 /* now we've forgotten all of the access info */
1213 ObtainWriteLock(&afs_xcbhash, 455);
1215 afs_DequeueCallback(avc);
1216 avc->states &= ~(CStatd | CUnique);
1217 ReleaseWriteLock(&afs_xcbhash);
1218 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
1219 osi_dnlc_purgedp(avc);
1223 int afs_defaultAsynchrony = 0;
1225 DECL_PIOCTL(PStoreBehind)
1228 struct sbstruct *sbr;
1230 sbr = (struct sbstruct *)ain;
1231 if (sbr->sb_default != -1) {
1232 if (afs_osi_suser(*acred))
1233 afs_defaultAsynchrony = sbr->sb_default;
1238 if (avc && (sbr->sb_thisfile != -1)) {
1240 (avc, PRSFS_WRITE | PRSFS_ADMINISTER, areq, DONT_CHECK_MODE_BITS))
1241 avc->asynchrony = sbr->sb_thisfile;
1246 *aoutSize = sizeof(struct sbstruct);
1247 sbr = (struct sbstruct *)aout;
1248 sbr->sb_default = afs_defaultAsynchrony;
1250 sbr->sb_thisfile = avc->asynchrony;
1256 DECL_PIOCTL(PGCPAGs)
1258 if (!afs_osi_suser(*acred)) {
1261 afs_gcpags = AFS_GCPAGS_USERDISABLED;
1265 DECL_PIOCTL(PGetAcl)
1267 struct AFSOpaque acl;
1268 struct AFSVolSync tsync;
1269 struct AFSFetchStatus OutStatus;
1275 AFS_STATCNT(PGetAcl);
1278 Fid.Volume = avc->fid.Fid.Volume;
1279 Fid.Vnode = avc->fid.Fid.Vnode;
1280 Fid.Unique = avc->fid.Fid.Unique;
1281 if (avc->states & CForeign) {
1283 * For a dfs xlator acl we have a special hack so that the
1284 * xlator will distinguish which type of acl will return. So
1285 * we currently use the top 2-bytes (vals 0-4) to tell which
1286 * type of acl to bring back. Horrible hack but this will
1287 * cause the least number of changes to code size and interfaces.
1289 if (Fid.Vnode & 0xc0000000)
1291 Fid.Vnode |= (ainSize << 30);
1293 acl.AFSOpaque_val = aout;
1295 tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1298 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHACL);
1300 code = RXAFS_FetchACL(tconn->id, &Fid, &acl, &OutStatus, &tsync);
1305 } while (afs_Analyze
1306 (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_FETCHACL,
1307 SHARED_LOCK, NULL));
1310 *aoutSize = (acl.AFSOpaque_len == 0 ? 1 : acl.AFSOpaque_len);
1323 AFS_STATCNT(PBogus);
1327 DECL_PIOCTL(PGetFileCell)
1329 register struct cell *tcell;
1331 AFS_STATCNT(PGetFileCell);
1334 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
1337 strcpy(aout, tcell->cellName);
1338 afs_PutCell(tcell, READ_LOCK);
1339 *aoutSize = strlen(aout) + 1;
1343 DECL_PIOCTL(PGetWSCell)
1345 struct cell *tcell = NULL;
1347 AFS_STATCNT(PGetWSCell);
1348 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1349 return EIO; /* Inappropriate ioctl for device */
1351 tcell = afs_GetPrimaryCell(READ_LOCK);
1352 if (!tcell) /* no primary cell? */
1354 strcpy(aout, tcell->cellName);
1355 *aoutSize = strlen(aout) + 1;
1356 afs_PutCell(tcell, READ_LOCK);
1360 DECL_PIOCTL(PGetUserCell)
1362 register afs_int32 i;
1363 register struct unixuser *tu;
1364 register struct cell *tcell;
1366 AFS_STATCNT(PGetUserCell);
1367 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1368 return EIO; /* Inappropriate ioctl for device */
1370 /* return the cell name of the primary cell for this user */
1371 i = UHash(areq->uid);
1372 ObtainWriteLock(&afs_xuser, 224);
1373 for (tu = afs_users[i]; tu; tu = tu->next) {
1374 if (tu->uid == areq->uid && (tu->states & UPrimary)) {
1376 ReleaseWriteLock(&afs_xuser);
1381 tcell = afs_GetCell(tu->cell, READ_LOCK);
1382 afs_PutUser(tu, WRITE_LOCK);
1386 strcpy(aout, tcell->cellName);
1387 afs_PutCell(tcell, READ_LOCK);
1388 *aoutSize = strlen(aout) + 1; /* 1 for the null */
1391 ReleaseWriteLock(&afs_xuser);
1398 DECL_PIOCTL(PSetTokens)
1401 register struct unixuser *tu;
1402 struct ClearToken clear;
1403 register struct cell *tcell;
1406 struct vrequest treq;
1407 afs_int32 flag, set_parent_pag = 0;
1409 AFS_STATCNT(PSetTokens);
1410 if (!afs_resourceinit_flag) {
1413 memcpy((char *)&i, ain, sizeof(afs_int32));
1414 ain += sizeof(afs_int32);
1415 stp = ain; /* remember where the ticket is */
1416 if (i < 0 || i > MAXKTCTICKETLEN)
1417 return EINVAL; /* malloc may fail */
1419 ain += i; /* skip over ticket */
1420 memcpy((char *)&i, ain, sizeof(afs_int32));
1421 ain += sizeof(afs_int32);
1422 if (i != sizeof(struct ClearToken)) {
1425 memcpy((char *)&clear, ain, sizeof(struct ClearToken));
1426 if (clear.AuthHandle == -1)
1427 clear.AuthHandle = 999; /* more rxvab compat stuff */
1428 ain += sizeof(struct ClearToken);
1429 if (ainSize != 2 * sizeof(afs_int32) + stLen + sizeof(struct ClearToken)) {
1430 /* still stuff left? we've got primary flag and cell name. Set these */
1431 memcpy((char *)&flag, ain, sizeof(afs_int32)); /* primary id flag */
1432 ain += sizeof(afs_int32); /* skip id field */
1433 /* rest is cell name, look it up */
1434 /* some versions of gcc appear to need != 0 in order to get this right */
1435 if ((flag & 0x8000) != 0) { /* XXX Use Constant XXX */
1439 tcell = afs_GetCellByName(ain, READ_LOCK);
1443 /* default to primary cell, primary id */
1444 flag = 1; /* primary id */
1445 tcell = afs_GetPrimaryCell(READ_LOCK);
1450 afs_PutCell(tcell, READ_LOCK);
1451 if (set_parent_pag) {
1453 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1454 #if defined(AFS_DARWIN_ENV)
1455 struct proc *p = current_proc(); /* XXX */
1457 struct proc *p = curproc; /* XXX */
1459 uprintf("Process %d (%s) tried to change pags in PSetTokens\n",
1460 p->p_pid, p->p_comm);
1461 if (!setpag(p, acred, -1, &pag, 1)) {
1464 if (!setpag(u.u_procp, acred, -1, &pag, 1)) { /* XXX u.u_procp is a no-op XXX */
1466 if (!setpag(acred, -1, &pag, 1)) {
1469 afs_InitReq(&treq, *acred);
1473 /* now we just set the tokens */
1474 tu = afs_GetUser(areq->uid, i, WRITE_LOCK); /* i has the cell # */
1475 tu->vid = clear.ViceId;
1476 if (tu->stp != NULL) {
1477 afs_osi_Free(tu->stp, tu->stLen);
1479 tu->stp = (char *)afs_osi_Alloc(stLen);
1481 memcpy(tu->stp, stp, stLen);
1484 afs_stats_cmfullperf.authent.TicketUpdates++;
1485 afs_ComputePAGStats();
1486 #endif /* AFS_NOSTATS */
1487 tu->states |= UHasTokens;
1488 tu->states &= ~UTokensBad;
1489 afs_SetPrimary(tu, flag);
1490 tu->tokenTime = osi_Time();
1491 afs_ResetUserConns(tu);
1492 afs_PutUser(tu, WRITE_LOCK);
1507 DECL_PIOCTL(PGetVolumeStatus)
1510 char *offLineMsg = afs_osi_Alloc(256);
1511 char *motd = afs_osi_Alloc(256);
1512 register struct conn *tc;
1513 register afs_int32 code = 0;
1514 struct VolumeStatus volstat;
1516 char *Name, *OfflineMsg, *MOTD;
1519 AFS_STATCNT(PGetVolumeStatus);
1525 OfflineMsg = offLineMsg;
1528 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1530 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS);
1533 RXAFS_GetVolumeStatus(tc->id, avc->fid.Fid.Volume, &volstat,
1534 &Name, &OfflineMsg, &MOTD);
1539 } while (afs_Analyze
1540 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS,
1541 SHARED_LOCK, NULL));
1545 /* Copy all this junk into msg->im_data, keeping track of the lengths. */
1547 memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
1548 cp += sizeof(VolumeStatus);
1549 strcpy(cp, volName);
1550 cp += strlen(volName) + 1;
1551 strcpy(cp, offLineMsg);
1552 cp += strlen(offLineMsg) + 1;
1554 cp += strlen(motd) + 1;
1555 *aoutSize = (cp - aout);
1557 afs_osi_Free(offLineMsg, 256);
1558 afs_osi_Free(motd, 256);
1562 DECL_PIOCTL(PSetVolumeStatus)
1565 char *offLineMsg = afs_osi_Alloc(256);
1566 char *motd = afs_osi_Alloc(256);
1567 register struct conn *tc;
1568 register afs_int32 code = 0;
1569 struct AFSFetchVolumeStatus volstat;
1570 struct AFSStoreVolumeStatus storeStat;
1571 register struct volume *tvp;
1575 AFS_STATCNT(PSetVolumeStatus);
1581 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
1583 if (tvp->states & (VRO | VBackup)) {
1584 afs_PutVolume(tvp, READ_LOCK);
1588 afs_PutVolume(tvp, READ_LOCK);
1593 /* Copy the junk out, using cp as a roving pointer. */
1595 memcpy((char *)&volstat, cp, sizeof(AFSFetchVolumeStatus));
1596 cp += sizeof(AFSFetchVolumeStatus);
1597 if (strlen(cp) >= sizeof(volName)) {
1601 strcpy(volName, cp);
1602 cp += strlen(volName) + 1;
1603 if (strlen(cp) >= sizeof(offLineMsg)) {
1607 strcpy(offLineMsg, cp);
1608 cp += strlen(offLineMsg) + 1;
1609 if (strlen(cp) >= sizeof(motd)) {
1615 if (volstat.MinQuota != -1) {
1616 storeStat.MinQuota = volstat.MinQuota;
1617 storeStat.Mask |= AFS_SETMINQUOTA;
1619 if (volstat.MaxQuota != -1) {
1620 storeStat.MaxQuota = volstat.MaxQuota;
1621 storeStat.Mask |= AFS_SETMAXQUOTA;
1624 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1626 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS);
1629 RXAFS_SetVolumeStatus(tc->id, avc->fid.Fid.Volume, &storeStat,
1630 volName, offLineMsg, motd);
1635 } while (afs_Analyze
1636 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS,
1637 SHARED_LOCK, NULL));
1641 /* we are sending parms back to make compat. with prev system. should
1642 * change interface later to not ask for current status, just set new status */
1644 memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
1645 cp += sizeof(VolumeStatus);
1646 strcpy(cp, volName);
1647 cp += strlen(volName) + 1;
1648 strcpy(cp, offLineMsg);
1649 cp += strlen(offLineMsg) + 1;
1651 cp += strlen(motd) + 1;
1652 *aoutSize = cp - aout;
1654 afs_osi_Free(offLineMsg, 256);
1655 afs_osi_Free(motd, 256);
1661 AFS_STATCNT(PFlush);
1664 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
1665 afs_BozonLock(&avc->pvnLock, avc); /* Since afs_TryToSmush will do a pvn_vptrunc */
1667 ObtainWriteLock(&avc->lock, 225);
1668 ObtainWriteLock(&afs_xcbhash, 456);
1669 afs_DequeueCallback(avc);
1670 avc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
1671 ReleaseWriteLock(&afs_xcbhash);
1672 /* now find the disk cache entries */
1673 afs_TryToSmush(avc, *acred, 1);
1674 osi_dnlc_purgedp(avc);
1675 afs_symhint_inval(avc);
1676 if (avc->linkData && !(avc->states & CCore)) {
1677 afs_osi_Free(avc->linkData, strlen(avc->linkData) + 1);
1678 avc->linkData = NULL;
1680 ReleaseWriteLock(&avc->lock);
1681 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
1682 afs_BozonUnlock(&avc->pvnLock, avc);
1687 DECL_PIOCTL(PNewStatMount)
1689 register afs_int32 code;
1690 register struct vcache *tvc;
1691 register struct dcache *tdc;
1692 struct VenusFid tfid;
1694 struct sysname_info sysState;
1695 afs_size_t offset, len;
1697 AFS_STATCNT(PNewStatMount);
1700 code = afs_VerifyVCache(avc, areq);
1703 if (vType(avc) != VDIR) {
1706 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
1709 Check_AtSys(avc, ain, &sysState, areq);
1710 ObtainReadLock(&tdc->lock);
1712 code = afs_dir_Lookup(&tdc->f.inode, sysState.name, &tfid.Fid);
1713 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
1714 ReleaseReadLock(&tdc->lock);
1715 afs_PutDCache(tdc); /* we're done with the data */
1716 bufp = sysState.name;
1720 tfid.Cell = avc->fid.Cell;
1721 tfid.Fid.Volume = avc->fid.Fid.Volume;
1722 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
1723 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
1725 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
1731 if (tvc->mvstat != 1) {
1736 ObtainWriteLock(&tvc->lock, 226);
1737 code = afs_HandleLink(tvc, areq);
1739 if (tvc->linkData) {
1740 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
1743 /* we have the data */
1744 strcpy(aout, tvc->linkData);
1745 *aoutSize = strlen(tvc->linkData) + 1;
1750 ReleaseWriteLock(&tvc->lock);
1753 if (sysState.allocked)
1754 osi_FreeLargeSpace(bufp);
1758 DECL_PIOCTL(PGetTokens)
1760 register struct cell *tcell;
1761 register afs_int32 i;
1762 register struct unixuser *tu;
1767 AFS_STATCNT(PGetTokens);
1768 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1769 return EIO; /* Inappropriate ioctl for device */
1771 /* weird interface. If input parameter is present, it is an integer and
1772 * we're supposed to return the parm'th tokens for this unix uid.
1773 * If not present, we just return tokens for cell 1.
1774 * If counter out of bounds, return EDOM.
1775 * If no tokens for the particular cell, return ENOTCONN.
1776 * Also, if this mysterious parm is present, we return, along with the
1777 * tokens, the primary cell indicator (an afs_int32 0) and the cell name
1778 * at the end, in that order.
1780 if ((newStyle = (ainSize > 0))) {
1781 memcpy((char *)&iterator, ain, sizeof(afs_int32));
1783 i = UHash(areq->uid);
1784 ObtainReadLock(&afs_xuser);
1785 for (tu = afs_users[i]; tu; tu = tu->next) {
1787 if (tu->uid == areq->uid && (tu->states & UHasTokens)) {
1788 if (iterator-- == 0)
1789 break; /* are we done yet? */
1792 if (tu->uid == areq->uid && afs_IsPrimaryCellNum(tu->cell))
1798 * No need to hold a read lock on each user entry
1802 ReleaseReadLock(&afs_xuser);
1807 if (((tu->states & UHasTokens) == 0)
1808 || (tu->ct.EndTimestamp < osi_Time())) {
1809 tu->states |= (UTokensBad | UNeedsReset);
1810 afs_PutUser(tu, READ_LOCK);
1813 /* use iterator for temp */
1815 iterator = tu->stLen; /* for compat, we try to return 56 byte tix if they fit */
1817 iterator = 56; /* # of bytes we're returning */
1818 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1819 cp += sizeof(afs_int32);
1820 memcpy(cp, tu->stp, tu->stLen); /* copy out st */
1822 iterator = sizeof(struct ClearToken);
1823 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1824 cp += sizeof(afs_int32);
1825 memcpy(cp, (char *)&tu->ct, sizeof(struct ClearToken));
1826 cp += sizeof(struct ClearToken);
1828 /* put out primary id and cell name, too */
1829 iterator = (tu->states & UPrimary ? 1 : 0);
1830 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1831 cp += sizeof(afs_int32);
1832 tcell = afs_GetCell(tu->cell, READ_LOCK);
1834 strcpy(cp, tcell->cellName);
1835 cp += strlen(tcell->cellName) + 1;
1836 afs_PutCell(tcell, READ_LOCK);
1840 *aoutSize = cp - aout;
1841 afs_PutUser(tu, READ_LOCK);
1847 register afs_int32 i;
1848 register struct unixuser *tu;
1850 AFS_STATCNT(PUnlog);
1851 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1852 return EIO; /* Inappropriate ioctl for device */
1854 i = UHash(areq->uid);
1855 ObtainWriteLock(&afs_xuser, 227);
1856 for (tu = afs_users[i]; tu; tu = tu->next) {
1857 if (tu->uid == areq->uid) {
1859 tu->states &= ~UHasTokens;
1860 /* security is not having to say you're sorry */
1861 memset((char *)&tu->ct, 0, sizeof(struct ClearToken));
1863 ReleaseWriteLock(&afs_xuser);
1864 /* We have to drop the lock over the call to afs_ResetUserConns, since
1865 * it obtains the afs_xvcache lock. We could also keep the lock, and
1866 * modify ResetUserConns to take parm saying we obtained the lock
1867 * already, but that is overkill. By keeping the "tu" pointer
1868 * held over the released lock, we guarantee that we won't lose our
1869 * place, and that we'll pass over every user conn that existed when
1870 * we began this call.
1872 afs_ResetUserConns(tu);
1874 ObtainWriteLock(&afs_xuser, 228);
1876 /* set the expire times to 0, causes
1877 * afs_GCUserData to remove this entry
1879 tu->ct.EndTimestamp = 0;
1881 #endif /* UKERNEL */
1884 ReleaseWriteLock(&afs_xuser);
1888 DECL_PIOCTL(PMariner)
1890 afs_int32 newHostAddr;
1891 afs_int32 oldHostAddr;
1893 AFS_STATCNT(PMariner);
1895 memcpy((char *)&oldHostAddr, (char *)&afs_marinerHost,
1898 oldHostAddr = 0xffffffff; /* disabled */
1900 memcpy((char *)&newHostAddr, ain, sizeof(afs_int32));
1901 if (newHostAddr == 0xffffffff) {
1902 /* disable mariner operations */
1904 } else if (newHostAddr) {
1906 afs_marinerHost = newHostAddr;
1908 memcpy(aout, (char *)&oldHostAddr, sizeof(afs_int32));
1909 *aoutSize = sizeof(afs_int32);
1913 DECL_PIOCTL(PCheckServers)
1915 register char *cp = 0;
1917 register struct server *ts;
1918 afs_int32 temp, *lp = (afs_int32 *) ain, havecell = 0;
1920 struct chservinfo *pcheck;
1922 AFS_STATCNT(PCheckServers);
1924 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1925 return EIO; /* Inappropriate ioctl for device */
1927 if (*lp == 0x12345678) { /* For afs3.3 version */
1928 pcheck = (struct chservinfo *)ain;
1929 if (pcheck->tinterval >= 0) {
1931 memcpy(cp, (char *)&PROBE_INTERVAL, sizeof(afs_int32));
1932 *aoutSize = sizeof(afs_int32);
1933 if (pcheck->tinterval > 0) {
1934 if (!afs_osi_suser(*acred))
1936 PROBE_INTERVAL = pcheck->tinterval;
1942 temp = pcheck->tflags;
1943 cp = pcheck->tbuffer;
1944 } else { /* For pre afs3.3 versions */
1945 memcpy((char *)&temp, ain, sizeof(afs_int32));
1946 cp = ain + sizeof(afs_int32);
1947 if (ainSize > sizeof(afs_int32))
1952 * 1: fast check, don't contact servers.
1953 * 2: local cell only.
1956 /* have cell name, too */
1957 cellp = afs_GetCellByName(cp, READ_LOCK);
1962 if (!cellp && (temp & 2)) {
1963 /* use local cell */
1964 cellp = afs_GetPrimaryCell(READ_LOCK);
1966 if (!(temp & 1)) { /* if not fast, call server checker routine */
1967 afs_CheckServers(1, cellp); /* check down servers */
1968 afs_CheckServers(0, cellp); /* check up servers */
1970 /* now return the current down server list */
1972 ObtainReadLock(&afs_xserver);
1973 for (i = 0; i < NSERVERS; i++) {
1974 for (ts = afs_servers[i]; ts; ts = ts->next) {
1975 if (cellp && ts->cell != cellp)
1976 continue; /* cell spec'd and wrong */
1977 if ((ts->flags & SRVR_ISDOWN)
1978 && ts->addr->sa_portal != ts->cell->vlport) {
1979 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
1980 cp += sizeof(afs_int32);
1984 ReleaseReadLock(&afs_xserver);
1986 afs_PutCell(cellp, READ_LOCK);
1987 *aoutSize = cp - aout;
1991 DECL_PIOCTL(PCheckVolNames)
1993 AFS_STATCNT(PCheckVolNames);
1994 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1995 return EIO; /* Inappropriate ioctl for device */
1997 afs_CheckRootVolume();
1998 afs_CheckVolumeNames(AFS_VOLCHECK_FORCE | AFS_VOLCHECK_EXPIRED |
1999 AFS_VOLCHECK_BUSY | AFS_VOLCHECK_MTPTS);
2003 DECL_PIOCTL(PCheckAuth)
2008 struct unixuser *tu;
2011 AFS_STATCNT(PCheckAuth);
2012 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2013 return EIO; /* Inappropriate ioctl for device */
2016 tu = afs_GetUser(areq->uid, 1, READ_LOCK); /* check local cell authentication */
2020 /* we have a user */
2021 ObtainReadLock(&afs_xsrvAddr);
2022 ObtainReadLock(&afs_xconn);
2024 /* any tokens set? */
2025 if ((tu->states & UHasTokens) == 0)
2027 /* all connections in cell 1 working? */
2028 for (i = 0; i < NSERVERS; i++) {
2029 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2030 for (tc = sa->conns; tc; tc = tc->next) {
2031 if (tc->user == tu && (tu->states & UTokensBad))
2036 ReleaseReadLock(&afs_xsrvAddr);
2037 ReleaseReadLock(&afs_xconn);
2038 afs_PutUser(tu, READ_LOCK);
2040 memcpy(aout, (char *)&retValue, sizeof(afs_int32));
2041 *aoutSize = sizeof(afs_int32);
2046 Prefetch(char *apath, struct afs_ioctl *adata, int afollow,
2047 struct AFS_UCRED *acred)
2050 register afs_int32 code;
2051 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2057 AFS_STATCNT(Prefetch);
2060 tp = osi_AllocLargeSpace(1024);
2061 AFS_COPYINSTR(apath, tp, 1024, &bufferSize, code);
2063 osi_FreeLargeSpace(tp);
2066 if (afs_BBusy()) { /* do this as late as possible */
2067 osi_FreeLargeSpace(tp);
2068 return EWOULDBLOCK; /* pretty close */
2070 afs_BQueue(BOP_PATH, (struct vcache *)0, 0, 0, acred, (afs_size_t) 0,
2071 (afs_size_t) 0, tp);
2075 DECL_PIOCTL(PFindVolume)
2077 register struct volume *tvp;
2078 register struct server *ts;
2079 register afs_int32 i;
2082 AFS_STATCNT(PFindVolume);
2085 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
2088 for (i = 0; i < MAXHOSTS; i++) {
2089 ts = tvp->serverHost[i];
2092 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
2093 cp += sizeof(afs_int32);
2096 /* still room for terminating NULL, add it on */
2097 ainSize = 0; /* reuse vbl */
2098 memcpy(cp, (char *)&ainSize, sizeof(afs_int32));
2099 cp += sizeof(afs_int32);
2101 *aoutSize = cp - aout;
2102 afs_PutVolume(tvp, READ_LOCK);
2108 DECL_PIOCTL(PViceAccess)
2110 register afs_int32 code;
2113 AFS_STATCNT(PViceAccess);
2116 code = afs_VerifyVCache(avc, areq);
2119 memcpy((char *)&temp, ain, sizeof(afs_int32));
2120 code = afs_AccessOK(avc, temp, areq, CHECK_MODE_BITS);
2127 DECL_PIOCTL(PSetCacheSize)
2132 AFS_STATCNT(PSetCacheSize);
2133 if (!afs_osi_suser(*acred))
2135 /* too many things are setup initially in mem cache version */
2136 if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
2138 memcpy((char *)&newValue, ain, sizeof(afs_int32));
2140 afs_cacheBlocks = afs_stats_cmperf.cacheBlocksOrig;
2142 if (newValue < afs_min_cache)
2143 afs_cacheBlocks = afs_min_cache;
2145 afs_cacheBlocks = newValue;
2147 afs_stats_cmperf.cacheBlocksTotal = afs_cacheBlocks;
2148 afs_ComputeCacheParms(); /* recompute basic cache parameters */
2149 afs_MaybeWakeupTruncateDaemon();
2150 while (waitcnt++ < 100 && afs_cacheBlocks < afs_blocksUsed) {
2151 afs_osi_Wait(1000, 0, 0);
2152 afs_MaybeWakeupTruncateDaemon();
2157 #define MAXGCSTATS 16
2158 DECL_PIOCTL(PGetCacheSize)
2160 afs_int32 results[MAXGCSTATS];
2162 AFS_STATCNT(PGetCacheSize);
2163 memset((char *)results, 0, sizeof(results));
2164 results[0] = afs_cacheBlocks;
2165 results[1] = afs_blocksUsed;
2166 memcpy(aout, (char *)results, sizeof(results));
2167 *aoutSize = sizeof(results);
2171 DECL_PIOCTL(PRemoveCallBack)
2173 register struct conn *tc;
2174 register afs_int32 code = 0;
2175 struct AFSCallBack CallBacks_Array[1];
2176 struct AFSCBFids theFids;
2177 struct AFSCBs theCBs;
2180 AFS_STATCNT(PRemoveCallBack);
2183 if (avc->states & CRO)
2184 return 0; /* read-only-ness can't change */
2185 ObtainWriteLock(&avc->lock, 229);
2186 theFids.AFSCBFids_len = 1;
2187 theCBs.AFSCBs_len = 1;
2188 theFids.AFSCBFids_val = (struct AFSFid *)&avc->fid.Fid;
2189 theCBs.AFSCBs_val = CallBacks_Array;
2190 CallBacks_Array[0].CallBackType = CB_DROPPED;
2191 if (avc->callback) {
2193 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2195 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
2197 code = RXAFS_GiveUpCallBacks(tc->id, &theFids, &theCBs);
2201 /* don't set code on failure since we wouldn't use it */
2202 } while (afs_Analyze
2203 (tc, code, &avc->fid, areq,
2204 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK, NULL));
2206 ObtainWriteLock(&afs_xcbhash, 457);
2207 afs_DequeueCallback(avc);
2209 avc->states &= ~(CStatd | CUnique);
2210 ReleaseWriteLock(&afs_xcbhash);
2211 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
2212 osi_dnlc_purgedp(avc);
2214 ReleaseWriteLock(&avc->lock);
2218 DECL_PIOCTL(PNewCell)
2220 /* create a new cell */
2221 afs_int32 cellHosts[MAXCELLHOSTS], *lp, magic = 0;
2222 char *newcell = 0, *linkedcell = 0, *tp = ain;
2223 register afs_int32 code, linkedstate = 0, ls;
2224 u_short fsport = 0, vlport = 0;
2227 AFS_STATCNT(PNewCell);
2228 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2229 return EIO; /* Inappropriate ioctl for device */
2231 if (!afs_osi_suser(*acred))
2234 memcpy((char *)&magic, tp, sizeof(afs_int32));
2235 tp += sizeof(afs_int32);
2236 if (magic != 0x12345678)
2239 /* A 3.4 fs newcell command will pass an array of MAXCELLHOSTS
2240 * server addresses while the 3.5 fs newcell command passes
2241 * MAXHOSTS. To figure out which is which, check if the cellname
2244 newcell = tp + (MAXCELLHOSTS + 3) * sizeof(afs_int32);
2245 scount = ((newcell[0] != '\0') ? MAXCELLHOSTS : MAXHOSTS);
2247 /* MAXCELLHOSTS (=8) is less than MAXHOSTS (=13) */
2248 memcpy((char *)cellHosts, tp, MAXCELLHOSTS * sizeof(afs_int32));
2249 tp += (scount * sizeof(afs_int32));
2251 lp = (afs_int32 *) tp;
2255 fsport = 0; /* Privileged ports not allowed */
2257 vlport = 0; /* Privileged ports not allowed */
2258 tp += (3 * sizeof(afs_int32));
2260 if ((ls = *lp) & 1) {
2261 linkedcell = tp + strlen(newcell) + 1;
2262 linkedstate |= CLinkedCell;
2265 linkedstate |= CNoSUID; /* setuid is disabled by default for fs newcell */
2267 afs_NewCell(newcell, cellHosts, linkedstate, linkedcell, fsport,
2272 DECL_PIOCTL(PNewAlias)
2274 /* create a new cell alias */
2276 register afs_int32 code;
2277 char *realName, *aliasName;
2279 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2280 return EIO; /* Inappropriate ioctl for device */
2282 if (!afs_osi_suser(*acred))
2286 tp += strlen(aliasName) + 1;
2289 code = afs_NewCellAlias(aliasName, realName);
2294 DECL_PIOCTL(PListCells)
2296 afs_int32 whichCell;
2297 register struct cell *tcell = 0;
2298 register afs_int32 i;
2299 register char *cp, *tp = ain;
2301 AFS_STATCNT(PListCells);
2302 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2303 return EIO; /* Inappropriate ioctl for device */
2305 memcpy((char *)&whichCell, tp, sizeof(afs_int32));
2306 tp += sizeof(afs_int32);
2307 tcell = afs_GetCellByIndex(whichCell, READ_LOCK);
2310 memset(cp, 0, MAXCELLHOSTS * sizeof(afs_int32));
2311 for (i = 0; i < MAXCELLHOSTS; i++) {
2312 if (tcell->cellHosts[i] == 0)
2314 memcpy(cp, (char *)&tcell->cellHosts[i]->addr->sa_ip,
2316 cp += sizeof(afs_int32);
2318 cp = aout + MAXCELLHOSTS * sizeof(afs_int32);
2319 strcpy(cp, tcell->cellName);
2320 cp += strlen(tcell->cellName) + 1;
2321 *aoutSize = cp - aout;
2322 afs_PutCell(tcell, READ_LOCK);
2330 DECL_PIOCTL(PListAliases)
2332 afs_int32 whichAlias;
2333 register struct cell_alias *tcalias = 0;
2334 register char *cp, *tp = ain;
2336 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2337 return EIO; /* Inappropriate ioctl for device */
2338 if (ainSize < sizeof(afs_int32))
2341 memcpy((char *)&whichAlias, tp, sizeof(afs_int32));
2342 tp += sizeof(afs_int32);
2344 tcalias = afs_GetCellAlias(whichAlias);
2347 strcpy(cp, tcalias->alias);
2348 cp += strlen(tcalias->alias) + 1;
2349 strcpy(cp, tcalias->cell);
2350 cp += strlen(tcalias->cell) + 1;
2351 *aoutSize = cp - aout;
2352 afs_PutCellAlias(tcalias);
2360 DECL_PIOCTL(PRemoveMount)
2362 register afs_int32 code;
2364 struct sysname_info sysState;
2365 afs_size_t offset, len;
2366 register struct conn *tc;
2367 register struct dcache *tdc;
2368 register struct vcache *tvc;
2369 struct AFSFetchStatus OutDirStatus;
2370 struct VenusFid tfid;
2371 struct AFSVolSync tsync;
2375 /* "ain" is the name of the file in this dir to remove */
2377 AFS_STATCNT(PRemoveMount);
2380 code = afs_VerifyVCache(avc, areq);
2383 if (vType(avc) != VDIR)
2386 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1); /* test for error below */
2389 Check_AtSys(avc, ain, &sysState, areq);
2390 ObtainReadLock(&tdc->lock);
2392 code = afs_dir_Lookup(&tdc->f.inode, sysState.name, &tfid.Fid);
2393 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
2394 ReleaseReadLock(&tdc->lock);
2395 bufp = sysState.name;
2400 tfid.Cell = avc->fid.Cell;
2401 tfid.Fid.Volume = avc->fid.Fid.Volume;
2402 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
2403 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
2405 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
2412 if (tvc->mvstat != 1) {
2418 ObtainWriteLock(&tvc->lock, 230);
2419 code = afs_HandleLink(tvc, areq);
2421 if (tvc->linkData) {
2422 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
2427 ReleaseWriteLock(&tvc->lock);
2428 osi_dnlc_purgedp(tvc);
2434 ObtainWriteLock(&avc->lock, 231);
2435 osi_dnlc_remove(avc, bufp, tvc);
2437 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2439 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE);
2442 RXAFS_RemoveFile(tc->id, (struct AFSFid *)&avc->fid.Fid, bufp,
2443 &OutDirStatus, &tsync);
2448 } while (afs_Analyze
2449 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_REMOVEFILE,
2450 SHARED_LOCK, NULL));
2455 ReleaseWriteLock(&avc->lock);
2459 /* we have the thing in the cache */
2460 ObtainWriteLock(&tdc->lock, 661);
2461 if (afs_LocalHero(avc, tdc, &OutDirStatus, 1)) {
2462 /* we can do it locally */
2463 code = afs_dir_Delete(&tdc->f.inode, bufp);
2465 ZapDCE(tdc); /* surprise error -- invalid value */
2466 DZap(&tdc->f.inode);
2469 ReleaseWriteLock(&tdc->lock);
2470 afs_PutDCache(tdc); /* drop ref count */
2472 avc->states &= ~CUnique; /* For the dfs xlator */
2473 ReleaseWriteLock(&avc->lock);
2476 if (sysState.allocked)
2477 osi_FreeLargeSpace(bufp);
2481 DECL_PIOCTL(PVenusLogging)
2483 return EINVAL; /* OBSOLETE */
2486 DECL_PIOCTL(PGetCellStatus)
2488 register struct cell *tcell;
2491 AFS_STATCNT(PGetCellStatus);
2492 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2493 return EIO; /* Inappropriate ioctl for device */
2495 tcell = afs_GetCellByName(ain, READ_LOCK);
2498 temp = tcell->states;
2499 afs_PutCell(tcell, READ_LOCK);
2500 memcpy(aout, (char *)&temp, sizeof(afs_int32));
2501 *aoutSize = sizeof(afs_int32);
2505 DECL_PIOCTL(PSetCellStatus)
2507 register struct cell *tcell;
2510 if (!afs_osi_suser(*acred))
2512 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2513 return EIO; /* Inappropriate ioctl for device */
2515 tcell = afs_GetCellByName(ain + 2 * sizeof(afs_int32), WRITE_LOCK);
2518 memcpy((char *)&temp, ain, sizeof(afs_int32));
2520 tcell->states |= CNoSUID;
2522 tcell->states &= ~CNoSUID;
2523 afs_PutCell(tcell, WRITE_LOCK);
2527 DECL_PIOCTL(PFlushVolumeData)
2529 register afs_int32 i;
2530 register struct dcache *tdc;
2531 register struct vcache *tvc;
2532 register struct volume *tv;
2533 afs_int32 cell, volume;
2535 AFS_STATCNT(PFlushVolumeData);
2538 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2539 return EIO; /* Inappropriate ioctl for device */
2541 volume = avc->fid.Fid.Volume; /* who to zap */
2542 cell = avc->fid.Cell;
2545 * Clear stat'd flag from all vnodes from this volume; this will invalidate all
2546 * the vcaches associated with the volume.
2548 ObtainReadLock(&afs_xvcache);
2549 for (i = 0; i < VCSIZE; i++) {
2550 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2551 if (tvc->fid.Fid.Volume == volume && tvc->fid.Cell == cell) {
2552 #if defined(AFS_SGI_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
2553 VN_HOLD(AFSTOV(tvc));
2555 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2561 ReleaseReadLock(&afs_xvcache);
2562 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
2563 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
2565 ObtainWriteLock(&tvc->lock, 232);
2567 ObtainWriteLock(&afs_xcbhash, 458);
2568 afs_DequeueCallback(tvc);
2569 tvc->states &= ~(CStatd | CDirty);
2570 ReleaseWriteLock(&afs_xcbhash);
2571 if (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
2572 osi_dnlc_purgedp(tvc);
2573 afs_TryToSmush(tvc, *acred, 1);
2574 ReleaseWriteLock(&tvc->lock);
2575 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
2576 afs_BozonUnlock(&tvc->pvnLock, tvc);
2578 ObtainReadLock(&afs_xvcache);
2579 /* our tvc ptr is still good until now */
2584 ReleaseReadLock(&afs_xvcache);
2587 MObtainWriteLock(&afs_xdcache, 328); /* needed if you're going to flush any stuff */
2588 for (i = 0; i < afs_cacheFiles; i++) {
2589 if (!(afs_indexFlags[i] & IFEverUsed))
2590 continue; /* never had any data */
2591 tdc = afs_GetDSlot(i, NULL);
2592 if (tdc->refCount <= 1) { /* too high, in use by running sys call */
2593 ReleaseReadLock(&tdc->tlock);
2594 if (tdc->f.fid.Fid.Volume == volume && tdc->f.fid.Cell == cell) {
2595 if (!(afs_indexFlags[i] & IFDataMod)) {
2596 /* if the file is modified, but has a ref cnt of only 1, then
2597 * someone probably has the file open and is writing into it.
2598 * Better to skip flushing such a file, it will be brought back
2599 * immediately on the next write anyway.
2601 * If we *must* flush, then this code has to be rearranged to call
2602 * afs_storeAllSegments() first */
2603 afs_FlushDCache(tdc);
2607 ReleaseReadLock(&tdc->tlock);
2609 afs_PutDCache(tdc); /* bumped by getdslot */
2611 MReleaseWriteLock(&afs_xdcache);
2613 ObtainReadLock(&afs_xvolume);
2614 for (i = 0; i < NVOLS; i++) {
2615 for (tv = afs_volumes[i]; tv; tv = tv->next) {
2616 if (tv->volume == volume) {
2617 afs_ResetVolumeInfo(tv);
2622 ReleaseReadLock(&afs_xvolume);
2624 /* probably, a user is doing this, probably, because things are screwed up.
2625 * maybe it's the dnlc's fault? */
2632 DECL_PIOCTL(PGetVnodeXStatus)
2634 register afs_int32 code;
2635 struct vcxstat stat;
2638 /* AFS_STATCNT(PGetVnodeXStatus); */
2641 code = afs_VerifyVCache(avc, areq);
2644 if (vType(avc) == VDIR)
2645 mode = PRSFS_LOOKUP;
2648 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
2650 stat.fid = avc->fid;
2651 hset32(stat.DataVersion, hgetlo(avc->m.DataVersion));
2652 stat.lock = avc->lock;
2653 stat.parentVnode = avc->parentVnode;
2654 stat.parentUnique = avc->parentUnique;
2655 hset(stat.flushDV, avc->flushDV);
2656 hset(stat.mapDV, avc->mapDV);
2657 stat.truncPos = avc->truncPos;
2658 { /* just grab the first two - won't break anything... */
2659 struct axscache *ac;
2661 for (i = 0, ac = avc->Access; ac && i < CPSIZE; i++, ac = ac->next) {
2662 stat.randomUid[i] = ac->uid;
2663 stat.randomAccess[i] = ac->axess;
2666 stat.callback = afs_data_pointer_to_int32(avc->callback);
2667 stat.cbExpires = avc->cbExpires;
2668 stat.anyAccess = avc->anyAccess;
2669 stat.opens = avc->opens;
2670 stat.execsOrWriters = avc->execsOrWriters;
2671 stat.flockCount = avc->flockCount;
2672 stat.mvstat = avc->mvstat;
2673 stat.states = avc->states;
2674 memcpy(aout, (char *)&stat, sizeof(struct vcxstat));
2675 *aoutSize = sizeof(struct vcxstat);
2680 /* We require root for local sysname changes, but not for remote */
2681 /* (since we don't really believe remote uids anyway) */
2682 /* outname[] shouldn't really be needed- this is left as an excercise */
2683 /* for the reader. */
2684 DECL_PIOCTL(PSetSysName)
2686 char *cp, *cp2, inname[MAXSYSNAME], outname[MAXSYSNAME];
2687 int setsysname, foundname = 0;
2688 register struct afs_exporter *exporter;
2689 register struct unixuser *au;
2690 register afs_int32 pag, error;
2691 int t, count, num = 0;
2692 char **sysnamelist[MAXSYSNAME];
2694 AFS_STATCNT(PSetSysName);
2695 if (!afs_globalVFS) {
2696 /* Afsd is NOT running; disable it */
2697 #if defined(KERNEL_HAVE_UERROR)
2698 return (setuerror(EINVAL), EINVAL);
2703 memset(inname, 0, MAXSYSNAME);
2704 memcpy((char *)&setsysname, ain, sizeof(afs_int32));
2705 ain += sizeof(afs_int32);
2709 if (setsysname < 0 || setsysname > MAXNUMSYSNAMES)
2712 for (cp = ain, count = 0; count < setsysname; count++) {
2713 /* won't go past end of ain since maxsysname*num < ain length */
2715 if (t >= MAXSYSNAME || t <= 0)
2717 /* check for names that can shoot us in the foot */
2718 if (*cp == '.' && (cp[1] == 0 || (cp[1] == '.' && cp[2] == 0)))
2724 /* inname gets first entry in case we're being a translator */
2726 memcpy(inname, ain, t + 1); /* include terminating null */
2730 if ((*acred)->cr_gid == RMTUSER_REQ) { /* Handles all exporters */
2731 pag = PagInCred(*acred);
2733 return EINVAL; /* Better than panicing */
2735 if (!(au = afs_FindUser(pag, -1, READ_LOCK))) {
2736 return EINVAL; /* Better than panicing */
2738 if (!(exporter = au->exporter)) {
2739 afs_PutUser(au, READ_LOCK);
2740 return EINVAL; /* Better than panicing */
2742 error = EXP_SYSNAME(exporter, (setsysname ? cp2 : NULL), sysnamelist,
2745 if (error == ENODEV)
2746 foundname = 0; /* sysname not set yet! */
2748 afs_PutUser(au, READ_LOCK);
2753 strcpy(outname, (*sysnamelist)[0]);
2755 afs_PutUser(au, READ_LOCK);
2757 /* Not xlating, so local case */
2759 osi_Panic("PSetSysName: !afs_sysname\n");
2760 if (!setsysname) { /* user just wants the info */
2761 strcpy(outname, afs_sysname);
2762 foundname = afs_sysnamecount;
2763 *sysnamelist = afs_sysnamelist;
2764 } else { /* Local guy; only root can change sysname */
2765 if (!afs_osi_suser(*acred))
2768 /* clear @sys entries from the dnlc, once afs_lookup can
2769 * do lookups of @sys entries and thinks it can trust them */
2770 /* privs ok, store the entry, ... */
2771 strcpy(afs_sysname, inname);
2772 if (setsysname > 1) { /* ... or list */
2774 for (count = 1; count < setsysname; ++count) {
2775 if (!afs_sysnamelist[count])
2777 ("PSetSysName: no afs_sysnamelist entry to write\n");
2779 memcpy(afs_sysnamelist[count], cp, t + 1); /* include null */
2783 afs_sysnamecount = setsysname;
2787 cp = aout; /* not changing so report back the count and ... */
2788 memcpy(cp, (char *)&foundname, sizeof(afs_int32));
2789 cp += sizeof(afs_int32);
2791 strcpy(cp, outname); /* ... the entry, ... */
2792 cp += strlen(outname) + 1;
2793 for (count = 1; count < foundname; ++count) { /* ... or list. */
2794 if (!(*sysnamelist)[count])
2796 ("PSetSysName: no afs_sysnamelist entry to read\n");
2797 t = strlen((*sysnamelist)[count]);
2798 if (t >= MAXSYSNAME)
2799 osi_Panic("PSetSysName: sysname entry garbled\n");
2800 strcpy(cp, (*sysnamelist)[count]);
2804 *aoutSize = cp - aout;
2809 /* sequential search through the list of touched cells is not a good
2810 * long-term solution here. For small n, though, it should be just
2811 * fine. Should consider special-casing the local cell for large n.
2812 * Likewise for PSetSPrefs.
2814 * s - number of ids in array l[] -- NOT index of last id
2815 * l - array of cell ids which have volumes that need to be sorted
2816 * vlonly - sort vl servers or file servers?
2819 ReSortCells_cb(struct cell *cell, void *arg)
2821 afs_int32 *p = (afs_int32 *) arg;
2822 afs_int32 *l = p + 1;
2825 for (i = 0; i < s; i++) {
2826 if (l[i] == cell->cellNum) {
2827 ObtainWriteLock(&cell->lock, 690);
2828 afs_SortServers(cell->cellHosts, MAXCELLHOSTS);
2829 ReleaseWriteLock(&cell->lock);
2837 ReSortCells(int s, afs_int32 * l, int vlonly)
2845 p = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * (s + 1));
2847 memcpy(p + 1, l, s * sizeof(afs_int32));
2848 afs_TraverseCells(&ReSortCells_cb, p);
2849 afs_osi_Free(p, sizeof(afs_int32) * (s + 1));
2853 ObtainReadLock(&afs_xvolume);
2854 for (i = 0; i < NVOLS; i++) {
2855 for (j = afs_volumes[i]; j; j = j->next) {
2856 for (k = 0; k < s; k++)
2857 if (j->cell == l[k]) {
2858 ObtainWriteLock(&j->lock, 233);
2859 afs_SortServers(j->serverHost, MAXHOSTS);
2860 ReleaseWriteLock(&j->lock);
2865 ReleaseReadLock(&afs_xvolume);
2869 static int debugsetsp = 0;
2871 afs_setsprefs(sp, num, vlonly)
2874 unsigned int vlonly;
2877 int i, j, k, matches, touchedSize;
2878 struct server *srvr = NULL;
2879 afs_int32 touched[34];
2883 for (k = 0; k < num; sp++, k++) {
2885 printf("sp host=%x, rank=%d\n", sp->host.s_addr, sp->rank);
2888 ObtainReadLock(&afs_xserver);
2890 i = SHash(sp->host.s_addr);
2891 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2892 if (sa->sa_ip == sp->host.s_addr) {
2894 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
2895 || (sa->sa_portal == AFS_FSPORT);
2896 if ((!vlonly && isfs) || (vlonly && !isfs)) {
2903 if (sa && matches) { /* found one! */
2905 printf("sa ip=%x, ip_rank=%d\n", sa->sa_ip, sa->sa_iprank);
2907 sa->sa_iprank = sp->rank + afs_randomMod15();
2908 afs_SortOneServer(sa->server);
2911 /* if we don't know yet what cell it's in, this is moot */
2912 for (j = touchedSize - 1;
2913 j >= 0 && touched[j] != srvr->cell->cellNum; j--)
2914 /* is it in our list of touched cells ? */ ;
2915 if (j < 0) { /* no, it's not */
2916 touched[touchedSize++] = srvr->cell->cellNum;
2917 if (touchedSize >= 32) { /* watch for ovrflow */
2918 ReleaseReadLock(&afs_xserver);
2919 ReSortCells(touchedSize, touched, vlonly);
2921 ObtainReadLock(&afs_xserver);
2927 ReleaseReadLock(&afs_xserver);
2928 /* if we didn't find one, start to create one. */
2929 /* Note that it doesn't have a cell yet... */
2931 afs_uint32 temp = sp->host.s_addr;
2933 afs_GetServer(&temp, 1, 0, (vlonly ? AFS_VLPORT : AFS_FSPORT),
2934 WRITE_LOCK, (afsUUID *) 0, 0);
2935 srvr->addr->sa_iprank = sp->rank + afs_randomMod15();
2936 afs_PutServer(srvr, WRITE_LOCK);
2938 } /* for all cited preferences */
2940 ReSortCells(touchedSize, touched, vlonly);
2944 /* Note that this may only be performed by the local root user.
2946 DECL_PIOCTL(PSetSPrefs)
2948 struct setspref *ssp;
2949 AFS_STATCNT(PSetSPrefs);
2951 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2952 return EIO; /* Inappropriate ioctl for device */
2954 if (!afs_osi_suser(*acred))
2957 if (ainSize < sizeof(struct setspref))
2960 ssp = (struct setspref *)ain;
2961 if (ainSize < sizeof(struct spref) * ssp->num_servers)
2964 afs_setsprefs(&(ssp->servers[0]), ssp->num_servers,
2965 (ssp->flags & DBservers));
2969 DECL_PIOCTL(PSetSPrefs33)
2972 AFS_STATCNT(PSetSPrefs);
2973 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2974 return EIO; /* Inappropriate ioctl for device */
2977 if (!afs_osi_suser(*acred))
2980 sp = (struct spref *)ain;
2981 afs_setsprefs(sp, ainSize / (sizeof(struct spref)), 0 /*!vlonly */ );
2985 /* some notes on the following code...
2986 * in the hash table of server structs, all servers with the same IP address
2987 * will be on the same overflow chain.
2988 * This could be sped slightly in some circumstances by having it cache the
2989 * immediately previous slot in the hash table and some supporting information
2990 * Only reports file servers now.
2992 DECL_PIOCTL(PGetSPrefs)
2994 struct sprefrequest *spin; /* input */
2995 struct sprefinfo *spout; /* output */
2996 struct spref *srvout; /* one output component */
2997 int i, j; /* counters for hash table traversal */
2998 struct server *srvr; /* one of CM's server structs */
3000 int vlonly; /* just return vlservers ? */
3003 AFS_STATCNT(PGetSPrefs);
3004 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3005 return EIO; /* Inappropriate ioctl for device */
3008 if (ainSize < sizeof(struct sprefrequest_33)) {
3011 spin = ((struct sprefrequest *)ain);
3014 if (ainSize > sizeof(struct sprefrequest_33)) {
3015 vlonly = (spin->flags & DBservers);
3019 /* struct sprefinfo includes 1 server struct... that size gets added
3020 * in during the loop that follows.
3022 *aoutSize = sizeof(struct sprefinfo) - sizeof(struct spref);
3023 spout = (struct sprefinfo *)aout;
3024 spout->next_offset = spin->offset;
3025 spout->num_servers = 0;
3026 srvout = spout->servers;
3028 ObtainReadLock(&afs_xserver);
3029 for (i = 0, j = 0; j < NSERVERS; j++) { /* sift through hash table */
3030 for (sa = afs_srvAddrs[j]; sa; sa = sa->next_bkt, i++) {
3031 if (spin->offset > (unsigned short)i) {
3032 continue; /* catch up to where we left off */
3034 spout->next_offset++;
3037 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
3038 || (sa->sa_portal == AFS_FSPORT);
3040 if ((vlonly && isfs) || (!vlonly && !isfs)) {
3041 /* only report ranks for vl servers */
3045 srvout->host.s_addr = sa->sa_ip;
3046 srvout->rank = sa->sa_iprank;
3047 *aoutSize += sizeof(struct spref);
3048 spout->num_servers++;
3051 if (*aoutSize > (PIGGYSIZE - sizeof(struct spref))) {
3052 ReleaseReadLock(&afs_xserver); /* no more room! */
3057 ReleaseReadLock(&afs_xserver);
3059 spout->next_offset = 0; /* start over from the beginning next time */
3063 /* Enable/Disable the specified exporter. Must be root to disable an exporter */
3064 int afs_NFSRootOnly = 1;
3065 DECL_PIOCTL(PExportAfs)
3067 afs_int32 export, newint =
3068 0, type, changestate, handleValue, convmode, pwsync, smounts;
3069 register struct afs_exporter *exporter;
3071 AFS_STATCNT(PExportAfs);
3072 memcpy((char *)&handleValue, ain, sizeof(afs_int32));
3073 type = handleValue >> 24;
3078 exporter = exporter_find(type);
3080 export = handleValue & 3;
3081 changestate = handleValue & 0xff;
3082 smounts = (handleValue >> 2) & 3;
3083 pwsync = (handleValue >> 4) & 3;
3084 convmode = (handleValue >> 6) & 3;
3086 changestate = (handleValue >> 16) & 0x1;
3087 convmode = (handleValue >> 16) & 0x2;
3088 pwsync = (handleValue >> 16) & 0x4;
3089 smounts = (handleValue >> 16) & 0x8;
3090 export = handleValue & 0xff;
3093 /* Failed finding desired exporter; */
3097 handleValue = exporter->exp_states;
3098 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3099 *aoutSize = sizeof(afs_int32);
3101 if (!afs_osi_suser(*acred))
3102 return EACCES; /* Only superuser can do this */
3106 exporter->exp_states |= EXP_EXPORTED;
3108 exporter->exp_states &= ~EXP_EXPORTED;
3112 exporter->exp_states |= EXP_UNIXMODE;
3114 exporter->exp_states &= ~EXP_UNIXMODE;
3118 exporter->exp_states |= EXP_PWSYNC;
3120 exporter->exp_states &= ~EXP_PWSYNC;
3124 afs_NFSRootOnly = 0;
3125 exporter->exp_states |= EXP_SUBMOUNTS;
3127 afs_NFSRootOnly = 1;
3128 exporter->exp_states &= ~EXP_SUBMOUNTS;
3131 handleValue = exporter->exp_states;
3132 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3133 *aoutSize = sizeof(afs_int32);
3136 exporter->exp_states |= EXP_EXPORTED;
3138 exporter->exp_states &= ~EXP_EXPORTED;
3140 exporter->exp_states |= EXP_UNIXMODE;
3142 exporter->exp_states &= ~EXP_UNIXMODE;
3144 exporter->exp_states |= EXP_PWSYNC;
3146 exporter->exp_states &= ~EXP_PWSYNC;
3148 afs_NFSRootOnly = 0;
3149 exporter->exp_states |= EXP_SUBMOUNTS;
3151 afs_NFSRootOnly = 1;
3152 exporter->exp_states &= ~EXP_SUBMOUNTS;
3162 struct gaginfo *gagflags;
3164 if (!afs_osi_suser(*acred))
3167 gagflags = (struct gaginfo *)ain;
3168 afs_showflags = gagflags->showflags;
3174 DECL_PIOCTL(PTwiddleRx)
3176 struct rxparams *rxp;
3178 if (!afs_osi_suser(*acred))
3181 rxp = (struct rxparams *)ain;
3183 if (rxp->rx_initReceiveWindow)
3184 rx_initReceiveWindow = rxp->rx_initReceiveWindow;
3185 if (rxp->rx_maxReceiveWindow)
3186 rx_maxReceiveWindow = rxp->rx_maxReceiveWindow;
3187 if (rxp->rx_initSendWindow)
3188 rx_initSendWindow = rxp->rx_initSendWindow;
3189 if (rxp->rx_maxSendWindow)
3190 rx_maxSendWindow = rxp->rx_maxSendWindow;
3191 if (rxp->rxi_nSendFrags)
3192 rxi_nSendFrags = rxp->rxi_nSendFrags;
3193 if (rxp->rxi_nRecvFrags)
3194 rxi_nRecvFrags = rxp->rxi_nRecvFrags;
3195 if (rxp->rxi_OrphanFragSize)
3196 rxi_OrphanFragSize = rxp->rxi_OrphanFragSize;
3197 if (rxp->rx_maxReceiveSize) {
3198 rx_maxReceiveSize = rxp->rx_maxReceiveSize;
3199 rx_maxReceiveSizeUser = rxp->rx_maxReceiveSize;
3201 if (rxp->rx_MyMaxSendSize)
3202 rx_MyMaxSendSize = rxp->rx_MyMaxSendSize;
3207 DECL_PIOCTL(PGetInitParams)
3209 if (sizeof(struct cm_initparams) > PIGGYSIZE)
3212 memcpy(aout, (char *)&cm_initParams, sizeof(struct cm_initparams));
3213 *aoutSize = sizeof(struct cm_initparams);
3217 #ifdef AFS_SGI65_ENV
3218 /* They took crget() from us, so fake it. */
3223 cr = crdup(get_current_cred());
3224 memset((char *)cr, 0, sizeof(cred_t));
3225 #if CELL || CELL_PREPARE
3232 DECL_PIOCTL(PGetRxkcrypt)
3234 memcpy(aout, (char *)&cryptall, sizeof(afs_int32));
3235 *aoutSize = sizeof(afs_int32);
3239 DECL_PIOCTL(PSetRxkcrypt)
3243 if (!afs_osi_suser(*acred))
3245 if (ainSize != sizeof(afs_int32) || ain == NULL)
3247 memcpy((char *)&tmpval, ain, sizeof(afs_int32));
3248 /* if new mappings added later this will need to be changed */
3249 if (tmpval != 0 && tmpval != 1)
3255 #ifdef AFS_NEED_CLIENTCONTEXT
3257 * Create new credentials to correspond to a remote user with given
3258 * <hostaddr, uid, g0, g1>. This allows a server running as root to
3259 * provide pioctl (and other) services to foreign clients (i.e. nfs
3260 * clients) by using this call to `become' the client.
3263 #define PIOCTL_HEADER 6
3265 HandleClientContext(struct afs_ioctl *ablob, int *com,
3266 struct AFS_UCRED **acred, struct AFS_UCRED *credp)
3269 afs_uint32 hostaddr;
3270 afs_int32 uid, g0, g1, i, code, pag, exporter_type;
3271 struct afs_exporter *exporter, *outexporter;
3272 struct AFS_UCRED *newcred;
3273 struct unixuser *au;
3275 #if defined(AFS_SGIMP_ENV)
3276 osi_Assert(ISAFS_GLOCK());
3278 AFS_STATCNT(HandleClientContext);
3279 if (ablob->in_size < PIOCTL_HEADER * sizeof(afs_int32)) {
3280 /* Must at least include the PIOCTL_HEADER header words required by the protocol */
3281 return EINVAL; /* Too small to be good */
3283 ain = inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
3284 AFS_COPYIN(ablob->in, ain, PIOCTL_HEADER * sizeof(afs_int32), code);
3286 osi_FreeLargeSpace(inData);
3290 /* Extract information for remote user */
3291 hostaddr = *((afs_uint32 *) ain);
3292 ain += sizeof(hostaddr);
3293 uid = *((afs_uint32 *) ain);
3295 g0 = *((afs_uint32 *) ain);
3297 g1 = *((afs_uint32 *) ain);
3299 *com = *((afs_uint32 *) ain);
3300 ain += sizeof(afs_int32);
3301 exporter_type = *((afs_uint32 *) ain); /* In case we support more than NFS */
3304 * Of course, one must be root for most of these functions, but
3305 * we'll allow (for knfs) you to set things if the pag is 0 and
3306 * you're setting tokens or unlogging.
3309 if (!afs_osi_suser(credp)) {
3310 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
3311 /* Since SGI's suser() returns explicit failure after the call.. */
3314 /* check for acceptable opcodes for normal folks, which are, so far,
3315 * set tokens and unlog.
3317 if (i != 9 && i != 3 && i != 38 && i != 8) {
3318 osi_FreeLargeSpace(inData);
3323 ablob->in_size -= PIOCTL_HEADER * sizeof(afs_int32);
3324 ablob->in += PIOCTL_HEADER * sizeof(afs_int32);
3325 osi_FreeLargeSpace(inData);
3328 * We map uid 0 to nobody to match the mapping that the nfs
3329 * server does and to ensure that the suser() calls in the afs
3330 * code fails for remote client roots.
3332 uid = afs_nobody; /* NFS_NOBODY == -2 */
3335 #ifdef AFS_AIX41_ENV
3338 newcred->cr_gid = RMTUSER_REQ;
3339 #ifdef AFS_AIX51_ENV
3340 newcred->cr_groupset.gs_union.un_groups[0] = g0;
3341 newcred->cr_groupset.gs_union.un_groups[1] = g1;
3343 newcred->cr_groups[0] = g0;
3344 newcred->cr_groups[1] = g1;
3347 newcred->cr_ngrps = 2;
3349 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV)
3350 newcred->cr_ngroups = 2;
3352 for (i = 2; i < NGROUPS; i++)
3353 newcred->cr_groups[i] = NOGROUP;
3356 #if !defined(AFS_OSF_ENV) && !defined(AFS_DEC_ENV)
3357 afs_nfsclient_init(); /* before looking for exporter, ensure one exists */
3359 if (!(exporter = exporter_find(exporter_type))) {
3360 /* Exporter wasn't initialized or an invalid exporter type */
3364 if (exporter->exp_states & EXP_PWSYNC) {
3365 if (uid != credp->cr_uid) {
3367 return ENOEXEC; /* XXX Find a better errno XXX */
3370 newcred->cr_uid = uid; /* Only temporary */
3371 code = EXP_REQHANDLER(exporter, &newcred, hostaddr, &pag, &outexporter);
3372 /* The client's pag is the only unique identifier for it */
3373 newcred->cr_uid = pag;
3375 if (!code && *com == PSETPAG) {
3376 /* Special case for 'setpag' */
3377 afs_uint32 pagvalue = genpag();
3379 au = afs_GetUser(pagvalue, -1, WRITE_LOCK); /* a new unixuser struct */
3381 * Note that we leave the 'outexporter' struct held so it won't
3384 au->exporter = outexporter;
3385 if (ablob->out_size >= 4) {
3386 AFS_COPYOUT((char *)&pagvalue, ablob->out, sizeof(afs_int32),
3389 afs_PutUser(au, WRITE_LOCK);
3392 return PSETPAG; /* Special return for setpag */
3394 EXP_RELE(outexporter);
3398 #endif /* AFS_NEED_CLIENTCONTEXT */
3400 /* get all interface addresses of this client */
3402 DECL_PIOCTL(PGetCPrefs)
3404 struct sprefrequest *spin; /* input */
3405 struct sprefinfo *spout; /* output */
3406 struct spref *srvout; /* one output component */
3410 AFS_STATCNT(PGetCPrefs);
3411 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3412 return EIO; /* Inappropriate ioctl for device */
3414 if (ainSize < sizeof(struct sprefrequest))
3417 spin = (struct sprefrequest *)ain;
3418 spout = (struct sprefinfo *)aout;
3420 maxNumber = spin->num_servers; /* max addrs this time */
3421 srvout = spout->servers;
3423 ObtainReadLock(&afs_xinterface);
3425 /* copy out the client interface information from the
3426 ** kernel data structure "interface" to the output buffer
3428 for (i = spin->offset, j = 0; (i < afs_cb_interface.numberOfInterfaces)
3429 && (j < maxNumber); i++, j++, srvout++)
3430 srvout->host.s_addr = afs_cb_interface.addr_in[i];
3432 spout->num_servers = j;
3433 *aoutSize = sizeof(struct sprefinfo) + (j - 1) * sizeof(struct spref);
3435 if (i >= afs_cb_interface.numberOfInterfaces)
3436 spout->next_offset = 0; /* start from beginning again */
3438 spout->next_offset = spin->offset + j;
3440 ReleaseReadLock(&afs_xinterface);
3444 DECL_PIOCTL(PSetCPrefs)
3446 struct setspref *sin;
3449 AFS_STATCNT(PSetCPrefs);
3450 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3451 return EIO; /* Inappropriate ioctl for device */
3453 sin = (struct setspref *)ain;
3455 if (ainSize < sizeof(struct setspref))
3457 #if 0 /* num_servers is unsigned */
3458 if (sin->num_servers < 0)
3461 if (sin->num_servers > AFS_MAX_INTERFACE_ADDR)
3464 ObtainWriteLock(&afs_xinterface, 412);
3465 afs_cb_interface.numberOfInterfaces = sin->num_servers;
3466 for (i = 0; (unsigned short)i < sin->num_servers; i++)
3467 afs_cb_interface.addr_in[i] = sin->servers[i].host.s_addr;
3469 ReleaseWriteLock(&afs_xinterface);
3473 DECL_PIOCTL(PFlushMount)
3475 register afs_int32 code;
3476 register struct vcache *tvc;
3477 register struct dcache *tdc;
3478 struct VenusFid tfid;
3480 struct sysname_info sysState;
3481 afs_size_t offset, len;
3483 AFS_STATCNT(PFlushMount);
3486 code = afs_VerifyVCache(avc, areq);
3489 if (vType(avc) != VDIR) {
3492 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
3495 Check_AtSys(avc, ain, &sysState, areq);
3496 ObtainReadLock(&tdc->lock);
3498 code = afs_dir_Lookup(&tdc->f.inode, sysState.name, &tfid.Fid);
3499 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
3500 ReleaseReadLock(&tdc->lock);
3501 afs_PutDCache(tdc); /* we're done with the data */
3502 bufp = sysState.name;
3506 tfid.Cell = avc->fid.Cell;
3507 tfid.Fid.Volume = avc->fid.Fid.Volume;
3508 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
3509 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
3511 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3517 if (tvc->mvstat != 1) {
3522 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
3523 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
3525 ObtainWriteLock(&tvc->lock, 649);
3526 ObtainWriteLock(&afs_xcbhash, 650);
3527 afs_DequeueCallback(tvc);
3528 tvc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
3529 ReleaseWriteLock(&afs_xcbhash);
3530 /* now find the disk cache entries */
3531 afs_TryToSmush(tvc, *acred, 1);
3532 osi_dnlc_purgedp(tvc);
3533 afs_symhint_inval(tvc);
3534 if (tvc->linkData && !(tvc->states & CCore)) {
3535 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
3536 tvc->linkData = NULL;
3538 ReleaseWriteLock(&tvc->lock);
3539 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
3540 afs_BozonUnlock(&tvc->pvnLock, tvc);
3544 if (sysState.allocked)
3545 osi_FreeLargeSpace(bufp);
3549 DECL_PIOCTL(PRxStatProc)
3554 if (!afs_osi_suser(*acred)) {
3558 if (ainSize != sizeof(afs_int32)) {
3562 memcpy((char *)&flags, ain, sizeof(afs_int32));
3563 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3567 if (flags & AFSCALL_RXSTATS_ENABLE) {
3568 rx_enableProcessRPCStats();
3570 if (flags & AFSCALL_RXSTATS_DISABLE) {
3571 rx_disableProcessRPCStats();
3573 if (flags & AFSCALL_RXSTATS_CLEAR) {
3574 rx_clearProcessRPCStats(AFS_RX_STATS_CLEAR_ALL);
3582 DECL_PIOCTL(PRxStatPeer)
3587 if (!afs_osi_suser(*acred)) {
3591 if (ainSize != sizeof(afs_int32)) {
3595 memcpy((char *)&flags, ain, sizeof(afs_int32));
3596 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3600 if (flags & AFSCALL_RXSTATS_ENABLE) {
3601 rx_enablePeerRPCStats();
3603 if (flags & AFSCALL_RXSTATS_DISABLE) {
3604 rx_disablePeerRPCStats();
3606 if (flags & AFSCALL_RXSTATS_CLEAR) {
3607 rx_clearPeerRPCStats(AFS_RX_STATS_CLEAR_ALL);
3614 DECL_PIOCTL(PPrefetchFromTape)
3616 register afs_int32 code, code1;
3619 struct rx_call *tcall;
3620 struct AFSVolSync tsync;
3621 struct AFSFetchStatus OutStatus;
3622 struct AFSCallBack CallBack;
3623 struct VenusFid tfid;
3627 AFS_STATCNT(PSetAcl);
3631 if (ain && (ainSize == 3 * sizeof(afs_int32)))
3632 Fid = (struct AFSFid *)ain;
3634 Fid = &avc->fid.Fid;
3635 tfid.Cell = avc->fid.Cell;
3636 tfid.Fid.Volume = Fid->Volume;
3637 tfid.Fid.Vnode = Fid->Vnode;
3638 tfid.Fid.Unique = Fid->Unique;
3640 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3642 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3643 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &avc->fid);
3646 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3647 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &tvc->fid);
3650 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3654 tcall = rx_NewCall(tc->id);
3656 StartRXAFS_FetchData(tcall, (struct AFSFid *)&tvc->fid.Fid, 0,
3659 bytes = rx_Read(tcall, (char *)aout, sizeof(afs_int32));
3661 EndRXAFS_FetchData(tcall, &OutStatus, &CallBack, &tsync);
3663 code1 = rx_EndCall(tcall, code);
3667 } while (afs_Analyze
3668 (tc, code, &tvc->fid, areq, AFS_STATS_FS_RPCIDX_RESIDENCYRPCS,
3669 SHARED_LOCK, NULL));
3670 /* This call is done only to have the callback things handled correctly */
3671 afs_FetchStatus(tvc, &tfid, areq, &OutStatus);
3675 *aoutSize = sizeof(afs_int32);
3680 DECL_PIOCTL(PResidencyCmd)
3682 register afs_int32 code;
3685 struct ResidencyCmdInputs *Inputs;
3686 struct ResidencyCmdOutputs *Outputs;
3687 struct VenusFid tfid;
3690 Inputs = (struct ResidencyCmdInputs *)ain;
3691 Outputs = (struct ResidencyCmdOutputs *)aout;
3694 if (!ain || ainSize != sizeof(struct ResidencyCmdInputs))
3699 Fid = &avc->fid.Fid;
3701 tfid.Cell = avc->fid.Cell;
3702 tfid.Fid.Volume = Fid->Volume;
3703 tfid.Fid.Vnode = Fid->Vnode;
3704 tfid.Fid.Unique = Fid->Unique;
3706 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3707 afs_Trace3(afs_iclSetp, CM_TRACE_RESIDCMD, ICL_TYPE_POINTER, tvc,
3708 ICL_TYPE_INT32, Inputs->command, ICL_TYPE_FID, &tfid);
3712 if (Inputs->command) {
3714 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3718 RXAFS_ResidencyCmd(tc->id, Fid, Inputs,
3719 (struct ResidencyCmdOutputs *)aout);
3723 } while (afs_Analyze
3724 (tc, code, &tvc->fid, areq,
3725 AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK, NULL));
3726 /* This call is done to have the callback things handled correctly */
3727 afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3728 } else { /* just a status request, return also link data */
3730 Outputs->code = afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3731 Outputs->chars[0] = 0;
3732 if (vType(tvc) == VLNK) {
3733 ObtainWriteLock(&tvc->lock, 555);
3734 if (afs_HandleLink(tvc, areq) == 0)
3735 strncpy((char *)&Outputs->chars, tvc->linkData, MAXCMDCHARS);
3736 ReleaseWriteLock(&tvc->lock);
3743 *aoutSize = sizeof(struct ResidencyCmdOutputs);