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_LRALLOCSIZE) {
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);
1579 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
1581 if (tvp->states & (VRO | VBackup)) {
1582 afs_PutVolume(tvp, READ_LOCK);
1585 afs_PutVolume(tvp, READ_LOCK);
1588 /* Copy the junk out, using cp as a roving pointer. */
1590 memcpy((char *)&volstat, cp, sizeof(AFSFetchVolumeStatus));
1591 cp += sizeof(AFSFetchVolumeStatus);
1592 if (strlen(cp) >= sizeof(volName))
1594 strcpy(volName, cp);
1595 cp += strlen(volName) + 1;
1596 if (strlen(cp) >= sizeof(offLineMsg))
1598 strcpy(offLineMsg, cp);
1599 cp += strlen(offLineMsg) + 1;
1600 if (strlen(cp) >= sizeof(motd))
1604 if (volstat.MinQuota != -1) {
1605 storeStat.MinQuota = volstat.MinQuota;
1606 storeStat.Mask |= AFS_SETMINQUOTA;
1608 if (volstat.MaxQuota != -1) {
1609 storeStat.MaxQuota = volstat.MaxQuota;
1610 storeStat.Mask |= AFS_SETMAXQUOTA;
1613 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1615 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS);
1618 RXAFS_SetVolumeStatus(tc->id, avc->fid.Fid.Volume, &storeStat,
1619 volName, offLineMsg, motd);
1624 } while (afs_Analyze
1625 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS,
1626 SHARED_LOCK, NULL));
1630 /* we are sending parms back to make compat. with prev system. should
1631 * change interface later to not ask for current status, just set new status */
1633 memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
1634 cp += sizeof(VolumeStatus);
1635 strcpy(cp, volName);
1636 cp += strlen(volName) + 1;
1637 strcpy(cp, offLineMsg);
1638 cp += strlen(offLineMsg) + 1;
1640 cp += strlen(motd) + 1;
1641 *aoutSize = cp - aout;
1643 afs_osi_Free(offLineMsg, 256);
1644 afs_osi_Free(motd, 256);
1650 AFS_STATCNT(PFlush);
1653 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
1654 afs_BozonLock(&avc->pvnLock, avc); /* Since afs_TryToSmush will do a pvn_vptrunc */
1656 ObtainWriteLock(&avc->lock, 225);
1657 ObtainWriteLock(&afs_xcbhash, 456);
1658 afs_DequeueCallback(avc);
1659 avc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
1660 ReleaseWriteLock(&afs_xcbhash);
1661 /* now find the disk cache entries */
1662 afs_TryToSmush(avc, *acred, 1);
1663 osi_dnlc_purgedp(avc);
1664 afs_symhint_inval(avc);
1665 if (avc->linkData && !(avc->states & CCore)) {
1666 afs_osi_Free(avc->linkData, strlen(avc->linkData) + 1);
1667 avc->linkData = NULL;
1669 ReleaseWriteLock(&avc->lock);
1670 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
1671 afs_BozonUnlock(&avc->pvnLock, avc);
1676 DECL_PIOCTL(PNewStatMount)
1678 register afs_int32 code;
1679 register struct vcache *tvc;
1680 register struct dcache *tdc;
1681 struct VenusFid tfid;
1683 struct sysname_info sysState;
1684 afs_size_t offset, len;
1686 AFS_STATCNT(PNewStatMount);
1689 code = afs_VerifyVCache(avc, areq);
1692 if (vType(avc) != VDIR) {
1695 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
1698 Check_AtSys(avc, ain, &sysState, areq);
1699 ObtainReadLock(&tdc->lock);
1701 code = afs_dir_Lookup(&tdc->f.inode, sysState.name, &tfid.Fid);
1702 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
1703 ReleaseReadLock(&tdc->lock);
1704 afs_PutDCache(tdc); /* we're done with the data */
1705 bufp = sysState.name;
1709 tfid.Cell = avc->fid.Cell;
1710 tfid.Fid.Volume = avc->fid.Fid.Volume;
1711 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
1712 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
1714 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
1720 if (tvc->mvstat != 1) {
1725 ObtainWriteLock(&tvc->lock, 226);
1726 code = afs_HandleLink(tvc, areq);
1728 if (tvc->linkData) {
1729 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
1732 /* we have the data */
1733 strcpy(aout, tvc->linkData);
1734 *aoutSize = strlen(tvc->linkData) + 1;
1739 ReleaseWriteLock(&tvc->lock);
1742 if (sysState.allocked)
1743 osi_FreeLargeSpace(bufp);
1747 DECL_PIOCTL(PGetTokens)
1749 register struct cell *tcell;
1750 register afs_int32 i;
1751 register struct unixuser *tu;
1756 AFS_STATCNT(PGetTokens);
1757 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1758 return EIO; /* Inappropriate ioctl for device */
1760 /* weird interface. If input parameter is present, it is an integer and
1761 * we're supposed to return the parm'th tokens for this unix uid.
1762 * If not present, we just return tokens for cell 1.
1763 * If counter out of bounds, return EDOM.
1764 * If no tokens for the particular cell, return ENOTCONN.
1765 * Also, if this mysterious parm is present, we return, along with the
1766 * tokens, the primary cell indicator (an afs_int32 0) and the cell name
1767 * at the end, in that order.
1769 if ((newStyle = (ainSize > 0))) {
1770 memcpy((char *)&iterator, ain, sizeof(afs_int32));
1772 i = UHash(areq->uid);
1773 ObtainReadLock(&afs_xuser);
1774 for (tu = afs_users[i]; tu; tu = tu->next) {
1776 if (tu->uid == areq->uid && (tu->states & UHasTokens)) {
1777 if (iterator-- == 0)
1778 break; /* are we done yet? */
1781 if (tu->uid == areq->uid && afs_IsPrimaryCellNum(tu->cell))
1787 * No need to hold a read lock on each user entry
1791 ReleaseReadLock(&afs_xuser);
1796 if (((tu->states & UHasTokens) == 0)
1797 || (tu->ct.EndTimestamp < osi_Time())) {
1798 tu->states |= (UTokensBad | UNeedsReset);
1799 afs_PutUser(tu, READ_LOCK);
1802 /* use iterator for temp */
1804 iterator = tu->stLen; /* for compat, we try to return 56 byte tix if they fit */
1806 iterator = 56; /* # of bytes we're returning */
1807 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1808 cp += sizeof(afs_int32);
1809 memcpy(cp, tu->stp, tu->stLen); /* copy out st */
1811 iterator = sizeof(struct ClearToken);
1812 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1813 cp += sizeof(afs_int32);
1814 memcpy(cp, (char *)&tu->ct, sizeof(struct ClearToken));
1815 cp += sizeof(struct ClearToken);
1817 /* put out primary id and cell name, too */
1818 iterator = (tu->states & UPrimary ? 1 : 0);
1819 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1820 cp += sizeof(afs_int32);
1821 tcell = afs_GetCell(tu->cell, READ_LOCK);
1823 strcpy(cp, tcell->cellName);
1824 cp += strlen(tcell->cellName) + 1;
1825 afs_PutCell(tcell, READ_LOCK);
1829 *aoutSize = cp - aout;
1830 afs_PutUser(tu, READ_LOCK);
1836 register afs_int32 i;
1837 register struct unixuser *tu;
1839 AFS_STATCNT(PUnlog);
1840 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1841 return EIO; /* Inappropriate ioctl for device */
1843 i = UHash(areq->uid);
1844 ObtainWriteLock(&afs_xuser, 227);
1845 for (tu = afs_users[i]; tu; tu = tu->next) {
1846 if (tu->uid == areq->uid) {
1848 tu->states &= ~UHasTokens;
1849 /* security is not having to say you're sorry */
1850 memset((char *)&tu->ct, 0, sizeof(struct ClearToken));
1852 ReleaseWriteLock(&afs_xuser);
1853 /* We have to drop the lock over the call to afs_ResetUserConns, since
1854 * it obtains the afs_xvcache lock. We could also keep the lock, and
1855 * modify ResetUserConns to take parm saying we obtained the lock
1856 * already, but that is overkill. By keeping the "tu" pointer
1857 * held over the released lock, we guarantee that we won't lose our
1858 * place, and that we'll pass over every user conn that existed when
1859 * we began this call.
1861 afs_ResetUserConns(tu);
1863 ObtainWriteLock(&afs_xuser, 228);
1865 /* set the expire times to 0, causes
1866 * afs_GCUserData to remove this entry
1868 tu->ct.EndTimestamp = 0;
1870 #endif /* UKERNEL */
1873 ReleaseWriteLock(&afs_xuser);
1877 DECL_PIOCTL(PMariner)
1879 afs_int32 newHostAddr;
1880 afs_int32 oldHostAddr;
1882 AFS_STATCNT(PMariner);
1884 memcpy((char *)&oldHostAddr, (char *)&afs_marinerHost,
1887 oldHostAddr = 0xffffffff; /* disabled */
1889 memcpy((char *)&newHostAddr, ain, sizeof(afs_int32));
1890 if (newHostAddr == 0xffffffff) {
1891 /* disable mariner operations */
1893 } else if (newHostAddr) {
1895 afs_marinerHost = newHostAddr;
1897 memcpy(aout, (char *)&oldHostAddr, sizeof(afs_int32));
1898 *aoutSize = sizeof(afs_int32);
1902 DECL_PIOCTL(PCheckServers)
1904 register char *cp = 0;
1906 register struct server *ts;
1907 afs_int32 temp, *lp = (afs_int32 *) ain, havecell = 0;
1909 struct chservinfo *pcheck;
1911 AFS_STATCNT(PCheckServers);
1913 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1914 return EIO; /* Inappropriate ioctl for device */
1916 if (*lp == 0x12345678) { /* For afs3.3 version */
1917 pcheck = (struct chservinfo *)ain;
1918 if (pcheck->tinterval >= 0) {
1920 memcpy(cp, (char *)&PROBE_INTERVAL, sizeof(afs_int32));
1921 *aoutSize = sizeof(afs_int32);
1922 if (pcheck->tinterval > 0) {
1923 if (!afs_osi_suser(*acred))
1925 PROBE_INTERVAL = pcheck->tinterval;
1931 temp = pcheck->tflags;
1932 cp = pcheck->tbuffer;
1933 } else { /* For pre afs3.3 versions */
1934 memcpy((char *)&temp, ain, sizeof(afs_int32));
1935 cp = ain + sizeof(afs_int32);
1936 if (ainSize > sizeof(afs_int32))
1941 * 1: fast check, don't contact servers.
1942 * 2: local cell only.
1945 /* have cell name, too */
1946 cellp = afs_GetCellByName(cp, READ_LOCK);
1951 if (!cellp && (temp & 2)) {
1952 /* use local cell */
1953 cellp = afs_GetPrimaryCell(READ_LOCK);
1955 if (!(temp & 1)) { /* if not fast, call server checker routine */
1956 afs_CheckServers(1, cellp); /* check down servers */
1957 afs_CheckServers(0, cellp); /* check up servers */
1959 /* now return the current down server list */
1961 ObtainReadLock(&afs_xserver);
1962 for (i = 0; i < NSERVERS; i++) {
1963 for (ts = afs_servers[i]; ts; ts = ts->next) {
1964 if (cellp && ts->cell != cellp)
1965 continue; /* cell spec'd and wrong */
1966 if ((ts->flags & SRVR_ISDOWN)
1967 && ts->addr->sa_portal != ts->cell->vlport) {
1968 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
1969 cp += sizeof(afs_int32);
1973 ReleaseReadLock(&afs_xserver);
1975 afs_PutCell(cellp, READ_LOCK);
1976 *aoutSize = cp - aout;
1980 DECL_PIOCTL(PCheckVolNames)
1982 AFS_STATCNT(PCheckVolNames);
1983 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1984 return EIO; /* Inappropriate ioctl for device */
1986 afs_CheckRootVolume();
1987 afs_CheckVolumeNames(AFS_VOLCHECK_FORCE | AFS_VOLCHECK_EXPIRED |
1988 AFS_VOLCHECK_BUSY | AFS_VOLCHECK_MTPTS);
1992 DECL_PIOCTL(PCheckAuth)
1997 struct unixuser *tu;
2000 AFS_STATCNT(PCheckAuth);
2001 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2002 return EIO; /* Inappropriate ioctl for device */
2005 tu = afs_GetUser(areq->uid, 1, READ_LOCK); /* check local cell authentication */
2009 /* we have a user */
2010 ObtainReadLock(&afs_xsrvAddr);
2011 ObtainReadLock(&afs_xconn);
2013 /* any tokens set? */
2014 if ((tu->states & UHasTokens) == 0)
2016 /* all connections in cell 1 working? */
2017 for (i = 0; i < NSERVERS; i++) {
2018 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2019 for (tc = sa->conns; tc; tc = tc->next) {
2020 if (tc->user == tu && (tu->states & UTokensBad))
2025 ReleaseReadLock(&afs_xsrvAddr);
2026 ReleaseReadLock(&afs_xconn);
2027 afs_PutUser(tu, READ_LOCK);
2029 memcpy(aout, (char *)&retValue, sizeof(afs_int32));
2030 *aoutSize = sizeof(afs_int32);
2035 Prefetch(char *apath, struct afs_ioctl *adata, int afollow,
2036 struct AFS_UCRED *acred)
2039 register afs_int32 code;
2040 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2046 AFS_STATCNT(Prefetch);
2049 tp = osi_AllocLargeSpace(1024);
2050 AFS_COPYINSTR(apath, tp, 1024, &bufferSize, code);
2052 osi_FreeLargeSpace(tp);
2055 if (afs_BBusy()) { /* do this as late as possible */
2056 osi_FreeLargeSpace(tp);
2057 return EWOULDBLOCK; /* pretty close */
2059 afs_BQueue(BOP_PATH, (struct vcache *)0, 0, 0, acred, (afs_size_t) 0,
2060 (afs_size_t) 0, tp);
2064 DECL_PIOCTL(PFindVolume)
2066 register struct volume *tvp;
2067 register struct server *ts;
2068 register afs_int32 i;
2071 AFS_STATCNT(PFindVolume);
2074 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
2077 for (i = 0; i < MAXHOSTS; i++) {
2078 ts = tvp->serverHost[i];
2081 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
2082 cp += sizeof(afs_int32);
2085 /* still room for terminating NULL, add it on */
2086 ainSize = 0; /* reuse vbl */
2087 memcpy(cp, (char *)&ainSize, sizeof(afs_int32));
2088 cp += sizeof(afs_int32);
2090 *aoutSize = cp - aout;
2091 afs_PutVolume(tvp, READ_LOCK);
2097 DECL_PIOCTL(PViceAccess)
2099 register afs_int32 code;
2102 AFS_STATCNT(PViceAccess);
2105 code = afs_VerifyVCache(avc, areq);
2108 memcpy((char *)&temp, ain, sizeof(afs_int32));
2109 code = afs_AccessOK(avc, temp, areq, CHECK_MODE_BITS);
2116 DECL_PIOCTL(PSetCacheSize)
2121 AFS_STATCNT(PSetCacheSize);
2122 if (!afs_osi_suser(*acred))
2124 /* too many things are setup initially in mem cache version */
2125 if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
2127 memcpy((char *)&newValue, ain, sizeof(afs_int32));
2129 afs_cacheBlocks = afs_stats_cmperf.cacheBlocksOrig;
2131 if (newValue < afs_min_cache)
2132 afs_cacheBlocks = afs_min_cache;
2134 afs_cacheBlocks = newValue;
2136 afs_stats_cmperf.cacheBlocksTotal = afs_cacheBlocks;
2137 afs_ComputeCacheParms(); /* recompute basic cache parameters */
2138 afs_MaybeWakeupTruncateDaemon();
2139 while (waitcnt++ < 100 && afs_cacheBlocks < afs_blocksUsed) {
2140 afs_osi_Wait(1000, 0, 0);
2141 afs_MaybeWakeupTruncateDaemon();
2146 #define MAXGCSTATS 16
2147 DECL_PIOCTL(PGetCacheSize)
2149 afs_int32 results[MAXGCSTATS];
2151 AFS_STATCNT(PGetCacheSize);
2152 memset((char *)results, 0, sizeof(results));
2153 results[0] = afs_cacheBlocks;
2154 results[1] = afs_blocksUsed;
2155 memcpy(aout, (char *)results, sizeof(results));
2156 *aoutSize = sizeof(results);
2160 DECL_PIOCTL(PRemoveCallBack)
2162 register struct conn *tc;
2163 register afs_int32 code = 0;
2164 struct AFSCallBack CallBacks_Array[1];
2165 struct AFSCBFids theFids;
2166 struct AFSCBs theCBs;
2169 AFS_STATCNT(PRemoveCallBack);
2172 if (avc->states & CRO)
2173 return 0; /* read-only-ness can't change */
2174 ObtainWriteLock(&avc->lock, 229);
2175 theFids.AFSCBFids_len = 1;
2176 theCBs.AFSCBs_len = 1;
2177 theFids.AFSCBFids_val = (struct AFSFid *)&avc->fid.Fid;
2178 theCBs.AFSCBs_val = CallBacks_Array;
2179 CallBacks_Array[0].CallBackType = CB_DROPPED;
2180 if (avc->callback) {
2182 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2184 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
2186 code = RXAFS_GiveUpCallBacks(tc->id, &theFids, &theCBs);
2190 /* don't set code on failure since we wouldn't use it */
2191 } while (afs_Analyze
2192 (tc, code, &avc->fid, areq,
2193 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK, NULL));
2195 ObtainWriteLock(&afs_xcbhash, 457);
2196 afs_DequeueCallback(avc);
2198 avc->states &= ~(CStatd | CUnique);
2199 ReleaseWriteLock(&afs_xcbhash);
2200 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
2201 osi_dnlc_purgedp(avc);
2203 ReleaseWriteLock(&avc->lock);
2207 DECL_PIOCTL(PNewCell)
2209 /* create a new cell */
2210 afs_int32 cellHosts[MAXCELLHOSTS], *lp, magic = 0;
2211 char *newcell = 0, *linkedcell = 0, *tp = ain;
2212 register afs_int32 code, linkedstate = 0, ls;
2213 u_short fsport = 0, vlport = 0;
2216 AFS_STATCNT(PNewCell);
2217 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2218 return EIO; /* Inappropriate ioctl for device */
2220 if (!afs_osi_suser(*acred))
2223 memcpy((char *)&magic, tp, sizeof(afs_int32));
2224 tp += sizeof(afs_int32);
2225 if (magic != 0x12345678)
2228 /* A 3.4 fs newcell command will pass an array of MAXCELLHOSTS
2229 * server addresses while the 3.5 fs newcell command passes
2230 * MAXHOSTS. To figure out which is which, check if the cellname
2233 newcell = tp + (MAXCELLHOSTS + 3) * sizeof(afs_int32);
2234 scount = ((newcell[0] != '\0') ? MAXCELLHOSTS : MAXHOSTS);
2236 /* MAXCELLHOSTS (=8) is less than MAXHOSTS (=13) */
2237 memcpy((char *)cellHosts, tp, MAXCELLHOSTS * sizeof(afs_int32));
2238 tp += (scount * sizeof(afs_int32));
2240 lp = (afs_int32 *) tp;
2244 fsport = 0; /* Privileged ports not allowed */
2246 vlport = 0; /* Privileged ports not allowed */
2247 tp += (3 * sizeof(afs_int32));
2249 if ((ls = *lp) & 1) {
2250 linkedcell = tp + strlen(newcell) + 1;
2251 linkedstate |= CLinkedCell;
2254 linkedstate |= CNoSUID; /* setuid is disabled by default for fs newcell */
2256 afs_NewCell(newcell, cellHosts, linkedstate, linkedcell, fsport,
2261 DECL_PIOCTL(PNewAlias)
2263 /* create a new cell alias */
2265 register afs_int32 code;
2266 char *realName, *aliasName;
2268 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2269 return EIO; /* Inappropriate ioctl for device */
2271 if (!afs_osi_suser(*acred))
2275 tp += strlen(aliasName) + 1;
2278 code = afs_NewCellAlias(aliasName, realName);
2283 DECL_PIOCTL(PListCells)
2285 afs_int32 whichCell;
2286 register struct cell *tcell = 0;
2287 register afs_int32 i;
2288 register char *cp, *tp = ain;
2290 AFS_STATCNT(PListCells);
2291 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2292 return EIO; /* Inappropriate ioctl for device */
2294 memcpy((char *)&whichCell, tp, sizeof(afs_int32));
2295 tp += sizeof(afs_int32);
2296 tcell = afs_GetCellByIndex(whichCell, READ_LOCK);
2299 memset(cp, 0, MAXCELLHOSTS * sizeof(afs_int32));
2300 for (i = 0; i < MAXCELLHOSTS; i++) {
2301 if (tcell->cellHosts[i] == 0)
2303 memcpy(cp, (char *)&tcell->cellHosts[i]->addr->sa_ip,
2305 cp += sizeof(afs_int32);
2307 cp = aout + MAXCELLHOSTS * sizeof(afs_int32);
2308 strcpy(cp, tcell->cellName);
2309 cp += strlen(tcell->cellName) + 1;
2310 *aoutSize = cp - aout;
2311 afs_PutCell(tcell, READ_LOCK);
2319 DECL_PIOCTL(PListAliases)
2321 afs_int32 whichAlias;
2322 register struct cell_alias *tcalias = 0;
2323 register char *cp, *tp = ain;
2325 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2326 return EIO; /* Inappropriate ioctl for device */
2327 if (ainSize < sizeof(afs_int32))
2330 memcpy((char *)&whichAlias, tp, sizeof(afs_int32));
2331 tp += sizeof(afs_int32);
2333 tcalias = afs_GetCellAlias(whichAlias);
2336 strcpy(cp, tcalias->alias);
2337 cp += strlen(tcalias->alias) + 1;
2338 strcpy(cp, tcalias->cell);
2339 cp += strlen(tcalias->cell) + 1;
2340 *aoutSize = cp - aout;
2341 afs_PutCellAlias(tcalias);
2349 DECL_PIOCTL(PRemoveMount)
2351 register afs_int32 code;
2353 struct sysname_info sysState;
2354 afs_size_t offset, len;
2355 register struct conn *tc;
2356 register struct dcache *tdc;
2357 register struct vcache *tvc;
2358 struct AFSFetchStatus OutDirStatus;
2359 struct VenusFid tfid;
2360 struct AFSVolSync tsync;
2364 /* "ain" is the name of the file in this dir to remove */
2366 AFS_STATCNT(PRemoveMount);
2369 code = afs_VerifyVCache(avc, areq);
2372 if (vType(avc) != VDIR)
2375 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1); /* test for error below */
2378 Check_AtSys(avc, ain, &sysState, areq);
2379 ObtainReadLock(&tdc->lock);
2381 code = afs_dir_Lookup(&tdc->f.inode, sysState.name, &tfid.Fid);
2382 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
2383 ReleaseReadLock(&tdc->lock);
2384 bufp = sysState.name;
2389 tfid.Cell = avc->fid.Cell;
2390 tfid.Fid.Volume = avc->fid.Fid.Volume;
2391 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
2392 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
2394 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
2401 if (tvc->mvstat != 1) {
2407 ObtainWriteLock(&tvc->lock, 230);
2408 code = afs_HandleLink(tvc, areq);
2410 if (tvc->linkData) {
2411 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
2416 ReleaseWriteLock(&tvc->lock);
2417 osi_dnlc_purgedp(tvc);
2423 ObtainWriteLock(&avc->lock, 231);
2424 osi_dnlc_remove(avc, bufp, tvc);
2426 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2428 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE);
2431 RXAFS_RemoveFile(tc->id, (struct AFSFid *)&avc->fid.Fid, bufp,
2432 &OutDirStatus, &tsync);
2437 } while (afs_Analyze
2438 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_REMOVEFILE,
2439 SHARED_LOCK, NULL));
2444 ReleaseWriteLock(&avc->lock);
2448 /* we have the thing in the cache */
2449 ObtainWriteLock(&tdc->lock, 661);
2450 if (afs_LocalHero(avc, tdc, &OutDirStatus, 1)) {
2451 /* we can do it locally */
2452 code = afs_dir_Delete(&tdc->f.inode, bufp);
2454 ZapDCE(tdc); /* surprise error -- invalid value */
2455 DZap(&tdc->f.inode);
2458 ReleaseWriteLock(&tdc->lock);
2459 afs_PutDCache(tdc); /* drop ref count */
2461 avc->states &= ~CUnique; /* For the dfs xlator */
2462 ReleaseWriteLock(&avc->lock);
2465 if (sysState.allocked)
2466 osi_FreeLargeSpace(bufp);
2470 DECL_PIOCTL(PVenusLogging)
2472 return EINVAL; /* OBSOLETE */
2475 DECL_PIOCTL(PGetCellStatus)
2477 register struct cell *tcell;
2480 AFS_STATCNT(PGetCellStatus);
2481 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2482 return EIO; /* Inappropriate ioctl for device */
2484 tcell = afs_GetCellByName(ain, READ_LOCK);
2487 temp = tcell->states;
2488 afs_PutCell(tcell, READ_LOCK);
2489 memcpy(aout, (char *)&temp, sizeof(afs_int32));
2490 *aoutSize = sizeof(afs_int32);
2494 DECL_PIOCTL(PSetCellStatus)
2496 register struct cell *tcell;
2499 if (!afs_osi_suser(*acred))
2501 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2502 return EIO; /* Inappropriate ioctl for device */
2504 tcell = afs_GetCellByName(ain + 2 * sizeof(afs_int32), WRITE_LOCK);
2507 memcpy((char *)&temp, ain, sizeof(afs_int32));
2509 tcell->states |= CNoSUID;
2511 tcell->states &= ~CNoSUID;
2512 afs_PutCell(tcell, WRITE_LOCK);
2516 DECL_PIOCTL(PFlushVolumeData)
2518 register afs_int32 i;
2519 register struct dcache *tdc;
2520 register struct vcache *tvc;
2521 register struct volume *tv;
2522 afs_int32 cell, volume;
2524 AFS_STATCNT(PFlushVolumeData);
2527 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2528 return EIO; /* Inappropriate ioctl for device */
2530 volume = avc->fid.Fid.Volume; /* who to zap */
2531 cell = avc->fid.Cell;
2534 * Clear stat'd flag from all vnodes from this volume; this will invalidate all
2535 * the vcaches associated with the volume.
2537 ObtainReadLock(&afs_xvcache);
2538 for (i = 0; i < VCSIZE; i++) {
2539 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2540 if (tvc->fid.Fid.Volume == volume && tvc->fid.Cell == cell) {
2541 #if defined(AFS_SGI_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
2542 VN_HOLD(AFSTOV(tvc));
2544 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2550 ReleaseReadLock(&afs_xvcache);
2551 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
2552 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
2554 ObtainWriteLock(&tvc->lock, 232);
2556 ObtainWriteLock(&afs_xcbhash, 458);
2557 afs_DequeueCallback(tvc);
2558 tvc->states &= ~(CStatd | CDirty);
2559 ReleaseWriteLock(&afs_xcbhash);
2560 if (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
2561 osi_dnlc_purgedp(tvc);
2562 afs_TryToSmush(tvc, *acred, 1);
2563 ReleaseWriteLock(&tvc->lock);
2564 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
2565 afs_BozonUnlock(&tvc->pvnLock, tvc);
2567 ObtainReadLock(&afs_xvcache);
2568 /* our tvc ptr is still good until now */
2573 ReleaseReadLock(&afs_xvcache);
2576 MObtainWriteLock(&afs_xdcache, 328); /* needed if you're going to flush any stuff */
2577 for (i = 0; i < afs_cacheFiles; i++) {
2578 if (!(afs_indexFlags[i] & IFEverUsed))
2579 continue; /* never had any data */
2580 tdc = afs_GetDSlot(i, NULL);
2581 if (tdc->refCount <= 1) { /* too high, in use by running sys call */
2582 ReleaseReadLock(&tdc->tlock);
2583 if (tdc->f.fid.Fid.Volume == volume && tdc->f.fid.Cell == cell) {
2584 if (!(afs_indexFlags[i] & IFDataMod)) {
2585 /* if the file is modified, but has a ref cnt of only 1, then
2586 * someone probably has the file open and is writing into it.
2587 * Better to skip flushing such a file, it will be brought back
2588 * immediately on the next write anyway.
2590 * If we *must* flush, then this code has to be rearranged to call
2591 * afs_storeAllSegments() first */
2592 afs_FlushDCache(tdc);
2596 ReleaseReadLock(&tdc->tlock);
2598 afs_PutDCache(tdc); /* bumped by getdslot */
2600 MReleaseWriteLock(&afs_xdcache);
2602 ObtainReadLock(&afs_xvolume);
2603 for (i = 0; i < NVOLS; i++) {
2604 for (tv = afs_volumes[i]; tv; tv = tv->next) {
2605 if (tv->volume == volume) {
2606 afs_ResetVolumeInfo(tv);
2611 ReleaseReadLock(&afs_xvolume);
2613 /* probably, a user is doing this, probably, because things are screwed up.
2614 * maybe it's the dnlc's fault? */
2621 DECL_PIOCTL(PGetVnodeXStatus)
2623 register afs_int32 code;
2624 struct vcxstat stat;
2627 /* AFS_STATCNT(PGetVnodeXStatus); */
2630 code = afs_VerifyVCache(avc, areq);
2633 if (vType(avc) == VDIR)
2634 mode = PRSFS_LOOKUP;
2637 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
2639 stat.fid = avc->fid;
2640 hset32(stat.DataVersion, hgetlo(avc->m.DataVersion));
2641 stat.lock = avc->lock;
2642 stat.parentVnode = avc->parentVnode;
2643 stat.parentUnique = avc->parentUnique;
2644 hset(stat.flushDV, avc->flushDV);
2645 hset(stat.mapDV, avc->mapDV);
2646 stat.truncPos = avc->truncPos;
2647 { /* just grab the first two - won't break anything... */
2648 struct axscache *ac;
2650 for (i = 0, ac = avc->Access; ac && i < CPSIZE; i++, ac = ac->next) {
2651 stat.randomUid[i] = ac->uid;
2652 stat.randomAccess[i] = ac->axess;
2655 stat.callback = afs_data_pointer_to_int32(avc->callback);
2656 stat.cbExpires = avc->cbExpires;
2657 stat.anyAccess = avc->anyAccess;
2658 stat.opens = avc->opens;
2659 stat.execsOrWriters = avc->execsOrWriters;
2660 stat.flockCount = avc->flockCount;
2661 stat.mvstat = avc->mvstat;
2662 stat.states = avc->states;
2663 memcpy(aout, (char *)&stat, sizeof(struct vcxstat));
2664 *aoutSize = sizeof(struct vcxstat);
2669 /* We require root for local sysname changes, but not for remote */
2670 /* (since we don't really believe remote uids anyway) */
2671 /* outname[] shouldn't really be needed- this is left as an excercise */
2672 /* for the reader. */
2673 DECL_PIOCTL(PSetSysName)
2675 char *cp, *cp2, inname[MAXSYSNAME], outname[MAXSYSNAME];
2676 int setsysname, foundname = 0;
2677 register struct afs_exporter *exporter;
2678 register struct unixuser *au;
2679 register afs_int32 pag, error;
2680 int t, count, num = 0;
2681 char **sysnamelist[MAXSYSNAME];
2683 AFS_STATCNT(PSetSysName);
2684 if (!afs_globalVFS) {
2685 /* Afsd is NOT running; disable it */
2686 #if defined(KERNEL_HAVE_UERROR)
2687 return (setuerror(EINVAL), EINVAL);
2692 memset(inname, 0, MAXSYSNAME);
2693 memcpy((char *)&setsysname, ain, sizeof(afs_int32));
2694 ain += sizeof(afs_int32);
2698 if (setsysname < 0 || setsysname > MAXNUMSYSNAMES)
2701 for (cp = ain, count = 0; count < setsysname; count++) {
2702 /* won't go past end of ain since maxsysname*num < ain length */
2704 if (t >= MAXSYSNAME || t <= 0)
2706 /* check for names that can shoot us in the foot */
2707 if (*cp == '.' && (cp[1] == 0 || (cp[1] == '.' && cp[2] == 0)))
2713 /* inname gets first entry in case we're being a translator */
2715 memcpy(inname, ain, t + 1); /* include terminating null */
2719 if ((*acred)->cr_gid == RMTUSER_REQ) { /* Handles all exporters */
2720 pag = PagInCred(*acred);
2722 return EINVAL; /* Better than panicing */
2724 if (!(au = afs_FindUser(pag, -1, READ_LOCK))) {
2725 return EINVAL; /* Better than panicing */
2727 if (!(exporter = au->exporter)) {
2728 afs_PutUser(au, READ_LOCK);
2729 return EINVAL; /* Better than panicing */
2731 error = EXP_SYSNAME(exporter, (setsysname ? cp2 : NULL), sysnamelist,
2734 if (error == ENODEV)
2735 foundname = 0; /* sysname not set yet! */
2737 afs_PutUser(au, READ_LOCK);
2742 strcpy(outname, (*sysnamelist)[0]);
2744 afs_PutUser(au, READ_LOCK);
2746 /* Not xlating, so local case */
2748 osi_Panic("PSetSysName: !afs_sysname\n");
2749 if (!setsysname) { /* user just wants the info */
2750 strcpy(outname, afs_sysname);
2751 foundname = afs_sysnamecount;
2752 *sysnamelist = afs_sysnamelist;
2753 } else { /* Local guy; only root can change sysname */
2754 if (!afs_osi_suser(*acred))
2757 /* clear @sys entries from the dnlc, once afs_lookup can
2758 * do lookups of @sys entries and thinks it can trust them */
2759 /* privs ok, store the entry, ... */
2760 strcpy(afs_sysname, inname);
2761 if (setsysname > 1) { /* ... or list */
2763 for (count = 1; count < setsysname; ++count) {
2764 if (!afs_sysnamelist[count])
2766 ("PSetSysName: no afs_sysnamelist entry to write\n");
2768 memcpy(afs_sysnamelist[count], cp, t + 1); /* include null */
2772 afs_sysnamecount = setsysname;
2776 cp = aout; /* not changing so report back the count and ... */
2777 memcpy(cp, (char *)&foundname, sizeof(afs_int32));
2778 cp += sizeof(afs_int32);
2780 strcpy(cp, outname); /* ... the entry, ... */
2781 cp += strlen(outname) + 1;
2782 for (count = 1; count < foundname; ++count) { /* ... or list. */
2783 if (!(*sysnamelist)[count])
2785 ("PSetSysName: no afs_sysnamelist entry to read\n");
2786 t = strlen((*sysnamelist)[count]);
2787 if (t >= MAXSYSNAME)
2788 osi_Panic("PSetSysName: sysname entry garbled\n");
2789 strcpy(cp, (*sysnamelist)[count]);
2793 *aoutSize = cp - aout;
2798 /* sequential search through the list of touched cells is not a good
2799 * long-term solution here. For small n, though, it should be just
2800 * fine. Should consider special-casing the local cell for large n.
2801 * Likewise for PSetSPrefs.
2803 * s - number of ids in array l[] -- NOT index of last id
2804 * l - array of cell ids which have volumes that need to be sorted
2805 * vlonly - sort vl servers or file servers?
2808 ReSortCells_cb(struct cell *cell, void *arg)
2810 afs_int32 *p = (afs_int32 *) arg;
2811 afs_int32 *l = p + 1;
2814 for (i = 0; i < s; i++) {
2815 if (l[i] == cell->cellNum) {
2816 ObtainWriteLock(&cell->lock, 690);
2817 afs_SortServers(cell->cellHosts, MAXCELLHOSTS);
2818 ReleaseWriteLock(&cell->lock);
2826 ReSortCells(int s, afs_int32 * l, int vlonly)
2834 p = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * (s + 1));
2836 memcpy(p + 1, l, s * sizeof(afs_int32));
2837 afs_TraverseCells(&ReSortCells_cb, p);
2838 afs_osi_Free(p, sizeof(afs_int32) * (s + 1));
2842 ObtainReadLock(&afs_xvolume);
2843 for (i = 0; i < NVOLS; i++) {
2844 for (j = afs_volumes[i]; j; j = j->next) {
2845 for (k = 0; k < s; k++)
2846 if (j->cell == l[k]) {
2847 ObtainWriteLock(&j->lock, 233);
2848 afs_SortServers(j->serverHost, MAXHOSTS);
2849 ReleaseWriteLock(&j->lock);
2854 ReleaseReadLock(&afs_xvolume);
2858 static int debugsetsp = 0;
2860 afs_setsprefs(sp, num, vlonly)
2863 unsigned int vlonly;
2866 int i, j, k, matches, touchedSize;
2867 struct server *srvr = NULL;
2868 afs_int32 touched[34];
2872 for (k = 0; k < num; sp++, k++) {
2874 printf("sp host=%x, rank=%d\n", sp->host.s_addr, sp->rank);
2877 ObtainReadLock(&afs_xserver);
2879 i = SHash(sp->host.s_addr);
2880 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2881 if (sa->sa_ip == sp->host.s_addr) {
2883 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
2884 || (sa->sa_portal == AFS_FSPORT);
2885 if ((!vlonly && isfs) || (vlonly && !isfs)) {
2892 if (sa && matches) { /* found one! */
2894 printf("sa ip=%x, ip_rank=%d\n", sa->sa_ip, sa->sa_iprank);
2896 sa->sa_iprank = sp->rank + afs_randomMod15();
2897 afs_SortOneServer(sa->server);
2900 /* if we don't know yet what cell it's in, this is moot */
2901 for (j = touchedSize - 1;
2902 j >= 0 && touched[j] != srvr->cell->cellNum; j--)
2903 /* is it in our list of touched cells ? */ ;
2904 if (j < 0) { /* no, it's not */
2905 touched[touchedSize++] = srvr->cell->cellNum;
2906 if (touchedSize >= 32) { /* watch for ovrflow */
2907 ReleaseReadLock(&afs_xserver);
2908 ReSortCells(touchedSize, touched, vlonly);
2910 ObtainReadLock(&afs_xserver);
2916 ReleaseReadLock(&afs_xserver);
2917 /* if we didn't find one, start to create one. */
2918 /* Note that it doesn't have a cell yet... */
2920 afs_uint32 temp = sp->host.s_addr;
2922 afs_GetServer(&temp, 1, 0, (vlonly ? AFS_VLPORT : AFS_FSPORT),
2923 WRITE_LOCK, (afsUUID *) 0, 0);
2924 srvr->addr->sa_iprank = sp->rank + afs_randomMod15();
2925 afs_PutServer(srvr, WRITE_LOCK);
2927 } /* for all cited preferences */
2929 ReSortCells(touchedSize, touched, vlonly);
2933 /* Note that this may only be performed by the local root user.
2935 DECL_PIOCTL(PSetSPrefs)
2937 struct setspref *ssp;
2938 AFS_STATCNT(PSetSPrefs);
2940 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2941 return EIO; /* Inappropriate ioctl for device */
2943 if (!afs_osi_suser(*acred))
2946 if (ainSize < sizeof(struct setspref))
2949 ssp = (struct setspref *)ain;
2950 if (ainSize < sizeof(struct spref) * ssp->num_servers)
2953 afs_setsprefs(&(ssp->servers[0]), ssp->num_servers,
2954 (ssp->flags & DBservers));
2958 DECL_PIOCTL(PSetSPrefs33)
2961 AFS_STATCNT(PSetSPrefs);
2962 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2963 return EIO; /* Inappropriate ioctl for device */
2966 if (!afs_osi_suser(*acred))
2969 sp = (struct spref *)ain;
2970 afs_setsprefs(sp, ainSize / (sizeof(struct spref)), 0 /*!vlonly */ );
2974 /* some notes on the following code...
2975 * in the hash table of server structs, all servers with the same IP address
2976 * will be on the same overflow chain.
2977 * This could be sped slightly in some circumstances by having it cache the
2978 * immediately previous slot in the hash table and some supporting information
2979 * Only reports file servers now.
2981 DECL_PIOCTL(PGetSPrefs)
2983 struct sprefrequest *spin; /* input */
2984 struct sprefinfo *spout; /* output */
2985 struct spref *srvout; /* one output component */
2986 int i, j; /* counters for hash table traversal */
2987 struct server *srvr; /* one of CM's server structs */
2989 int vlonly; /* just return vlservers ? */
2992 AFS_STATCNT(PGetSPrefs);
2993 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2994 return EIO; /* Inappropriate ioctl for device */
2997 if (ainSize < sizeof(struct sprefrequest_33)) {
3000 spin = ((struct sprefrequest *)ain);
3003 if (ainSize > sizeof(struct sprefrequest_33)) {
3004 vlonly = (spin->flags & DBservers);
3008 /* struct sprefinfo includes 1 server struct... that size gets added
3009 * in during the loop that follows.
3011 *aoutSize = sizeof(struct sprefinfo) - sizeof(struct spref);
3012 spout = (struct sprefinfo *)aout;
3013 spout->next_offset = spin->offset;
3014 spout->num_servers = 0;
3015 srvout = spout->servers;
3017 ObtainReadLock(&afs_xserver);
3018 for (i = 0, j = 0; j < NSERVERS; j++) { /* sift through hash table */
3019 for (sa = afs_srvAddrs[j]; sa; sa = sa->next_bkt, i++) {
3020 if (spin->offset > (unsigned short)i) {
3021 continue; /* catch up to where we left off */
3023 spout->next_offset++;
3026 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
3027 || (sa->sa_portal == AFS_FSPORT);
3029 if ((vlonly && isfs) || (!vlonly && !isfs)) {
3030 /* only report ranks for vl servers */
3034 srvout->host.s_addr = sa->sa_ip;
3035 srvout->rank = sa->sa_iprank;
3036 *aoutSize += sizeof(struct spref);
3037 spout->num_servers++;
3040 if (*aoutSize > (PIGGYSIZE - sizeof(struct spref))) {
3041 ReleaseReadLock(&afs_xserver); /* no more room! */
3046 ReleaseReadLock(&afs_xserver);
3048 spout->next_offset = 0; /* start over from the beginning next time */
3052 /* Enable/Disable the specified exporter. Must be root to disable an exporter */
3053 int afs_NFSRootOnly = 1;
3054 DECL_PIOCTL(PExportAfs)
3056 afs_int32 export, newint =
3057 0, type, changestate, handleValue, convmode, pwsync, smounts;
3058 register struct afs_exporter *exporter;
3060 AFS_STATCNT(PExportAfs);
3061 memcpy((char *)&handleValue, ain, sizeof(afs_int32));
3062 type = handleValue >> 24;
3067 exporter = exporter_find(type);
3069 export = handleValue & 3;
3070 changestate = handleValue & 0xff;
3071 smounts = (handleValue >> 2) & 3;
3072 pwsync = (handleValue >> 4) & 3;
3073 convmode = (handleValue >> 6) & 3;
3075 changestate = (handleValue >> 16) & 0x1;
3076 convmode = (handleValue >> 16) & 0x2;
3077 pwsync = (handleValue >> 16) & 0x4;
3078 smounts = (handleValue >> 16) & 0x8;
3079 export = handleValue & 0xff;
3082 /* Failed finding desired exporter; */
3086 handleValue = exporter->exp_states;
3087 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3088 *aoutSize = sizeof(afs_int32);
3090 if (!afs_osi_suser(*acred))
3091 return EACCES; /* Only superuser can do this */
3095 exporter->exp_states |= EXP_EXPORTED;
3097 exporter->exp_states &= ~EXP_EXPORTED;
3101 exporter->exp_states |= EXP_UNIXMODE;
3103 exporter->exp_states &= ~EXP_UNIXMODE;
3107 exporter->exp_states |= EXP_PWSYNC;
3109 exporter->exp_states &= ~EXP_PWSYNC;
3113 afs_NFSRootOnly = 0;
3114 exporter->exp_states |= EXP_SUBMOUNTS;
3116 afs_NFSRootOnly = 1;
3117 exporter->exp_states &= ~EXP_SUBMOUNTS;
3120 handleValue = exporter->exp_states;
3121 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3122 *aoutSize = sizeof(afs_int32);
3125 exporter->exp_states |= EXP_EXPORTED;
3127 exporter->exp_states &= ~EXP_EXPORTED;
3129 exporter->exp_states |= EXP_UNIXMODE;
3131 exporter->exp_states &= ~EXP_UNIXMODE;
3133 exporter->exp_states |= EXP_PWSYNC;
3135 exporter->exp_states &= ~EXP_PWSYNC;
3137 afs_NFSRootOnly = 0;
3138 exporter->exp_states |= EXP_SUBMOUNTS;
3140 afs_NFSRootOnly = 1;
3141 exporter->exp_states &= ~EXP_SUBMOUNTS;
3151 struct gaginfo *gagflags;
3153 if (!afs_osi_suser(*acred))
3156 gagflags = (struct gaginfo *)ain;
3157 afs_showflags = gagflags->showflags;
3163 DECL_PIOCTL(PTwiddleRx)
3165 struct rxparams *rxp;
3167 if (!afs_osi_suser(*acred))
3170 rxp = (struct rxparams *)ain;
3172 if (rxp->rx_initReceiveWindow)
3173 rx_initReceiveWindow = rxp->rx_initReceiveWindow;
3174 if (rxp->rx_maxReceiveWindow)
3175 rx_maxReceiveWindow = rxp->rx_maxReceiveWindow;
3176 if (rxp->rx_initSendWindow)
3177 rx_initSendWindow = rxp->rx_initSendWindow;
3178 if (rxp->rx_maxSendWindow)
3179 rx_maxSendWindow = rxp->rx_maxSendWindow;
3180 if (rxp->rxi_nSendFrags)
3181 rxi_nSendFrags = rxp->rxi_nSendFrags;
3182 if (rxp->rxi_nRecvFrags)
3183 rxi_nRecvFrags = rxp->rxi_nRecvFrags;
3184 if (rxp->rxi_OrphanFragSize)
3185 rxi_OrphanFragSize = rxp->rxi_OrphanFragSize;
3186 if (rxp->rx_maxReceiveSize) {
3187 rx_maxReceiveSize = rxp->rx_maxReceiveSize;
3188 rx_maxReceiveSizeUser = rxp->rx_maxReceiveSize;
3190 if (rxp->rx_MyMaxSendSize)
3191 rx_MyMaxSendSize = rxp->rx_MyMaxSendSize;
3196 DECL_PIOCTL(PGetInitParams)
3198 if (sizeof(struct cm_initparams) > PIGGYSIZE)
3201 memcpy(aout, (char *)&cm_initParams, sizeof(struct cm_initparams));
3202 *aoutSize = sizeof(struct cm_initparams);
3206 #ifdef AFS_SGI65_ENV
3207 /* They took crget() from us, so fake it. */
3212 cr = crdup(get_current_cred());
3213 memset((char *)cr, 0, sizeof(cred_t));
3214 #if CELL || CELL_PREPARE
3221 DECL_PIOCTL(PGetRxkcrypt)
3223 memcpy(aout, (char *)&cryptall, sizeof(afs_int32));
3224 *aoutSize = sizeof(afs_int32);
3228 DECL_PIOCTL(PSetRxkcrypt)
3232 if (!afs_osi_suser(*acred))
3234 if (ainSize != sizeof(afs_int32) || ain == NULL)
3236 memcpy((char *)&tmpval, ain, sizeof(afs_int32));
3237 /* if new mappings added later this will need to be changed */
3238 if (tmpval != 0 && tmpval != 1)
3244 #ifdef AFS_NEED_CLIENTCONTEXT
3246 * Create new credentials to correspond to a remote user with given
3247 * <hostaddr, uid, g0, g1>. This allows a server running as root to
3248 * provide pioctl (and other) services to foreign clients (i.e. nfs
3249 * clients) by using this call to `become' the client.
3252 #define PIOCTL_HEADER 6
3254 HandleClientContext(struct afs_ioctl *ablob, int *com,
3255 struct AFS_UCRED **acred, struct AFS_UCRED *credp)
3258 afs_uint32 hostaddr;
3259 afs_int32 uid, g0, g1, i, code, pag, exporter_type;
3260 struct afs_exporter *exporter, *outexporter;
3261 struct AFS_UCRED *newcred;
3262 struct unixuser *au;
3264 #if defined(AFS_SGIMP_ENV)
3265 osi_Assert(ISAFS_GLOCK());
3267 AFS_STATCNT(HandleClientContext);
3268 if (ablob->in_size < PIOCTL_HEADER * sizeof(afs_int32)) {
3269 /* Must at least include the PIOCTL_HEADER header words required by the protocol */
3270 return EINVAL; /* Too small to be good */
3272 ain = inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
3273 AFS_COPYIN(ablob->in, ain, PIOCTL_HEADER * sizeof(afs_int32), code);
3275 osi_FreeLargeSpace(inData);
3279 /* Extract information for remote user */
3280 hostaddr = *((afs_uint32 *) ain);
3281 ain += sizeof(hostaddr);
3282 uid = *((afs_uint32 *) ain);
3284 g0 = *((afs_uint32 *) ain);
3286 g1 = *((afs_uint32 *) ain);
3288 *com = *((afs_uint32 *) ain);
3289 ain += sizeof(afs_int32);
3290 exporter_type = *((afs_uint32 *) ain); /* In case we support more than NFS */
3293 * Of course, one must be root for most of these functions, but
3294 * we'll allow (for knfs) you to set things if the pag is 0 and
3295 * you're setting tokens or unlogging.
3298 if (!afs_osi_suser(credp)) {
3299 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
3300 /* Since SGI's suser() returns explicit failure after the call.. */
3303 /* check for acceptable opcodes for normal folks, which are, so far,
3304 * set tokens and unlog.
3306 if (i != 9 && i != 3 && i != 38 && i != 8) {
3307 osi_FreeLargeSpace(inData);
3312 ablob->in_size -= PIOCTL_HEADER * sizeof(afs_int32);
3313 ablob->in += PIOCTL_HEADER * sizeof(afs_int32);
3314 osi_FreeLargeSpace(inData);
3317 * We map uid 0 to nobody to match the mapping that the nfs
3318 * server does and to ensure that the suser() calls in the afs
3319 * code fails for remote client roots.
3321 uid = afs_nobody; /* NFS_NOBODY == -2 */
3324 #ifdef AFS_AIX41_ENV
3327 newcred->cr_gid = RMTUSER_REQ;
3328 #ifdef AFS_AIX51_ENV
3329 newcred->cr_groupset.gs_union.un_groups[0] = g0;
3330 newcred->cr_groupset.gs_union.un_groups[1] = g1;
3332 newcred->cr_groups[0] = g0;
3333 newcred->cr_groups[1] = g1;
3336 newcred->cr_ngrps = 2;
3338 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV)
3339 newcred->cr_ngroups = 2;
3341 for (i = 2; i < NGROUPS; i++)
3342 newcred->cr_groups[i] = NOGROUP;
3345 #if !defined(AFS_OSF_ENV) && !defined(AFS_DEC_ENV)
3346 afs_nfsclient_init(); /* before looking for exporter, ensure one exists */
3348 if (!(exporter = exporter_find(exporter_type))) {
3349 /* Exporter wasn't initialized or an invalid exporter type */
3353 if (exporter->exp_states & EXP_PWSYNC) {
3354 if (uid != credp->cr_uid) {
3356 return ENOEXEC; /* XXX Find a better errno XXX */
3359 newcred->cr_uid = uid; /* Only temporary */
3360 code = EXP_REQHANDLER(exporter, &newcred, hostaddr, &pag, &outexporter);
3361 /* The client's pag is the only unique identifier for it */
3362 newcred->cr_uid = pag;
3364 if (!code && *com == PSETPAG) {
3365 /* Special case for 'setpag' */
3366 afs_uint32 pagvalue = genpag();
3368 au = afs_GetUser(pagvalue, -1, WRITE_LOCK); /* a new unixuser struct */
3370 * Note that we leave the 'outexporter' struct held so it won't
3373 au->exporter = outexporter;
3374 if (ablob->out_size >= 4) {
3375 AFS_COPYOUT((char *)&pagvalue, ablob->out, sizeof(afs_int32),
3378 afs_PutUser(au, WRITE_LOCK);
3381 return PSETPAG; /* Special return for setpag */
3383 EXP_RELE(outexporter);
3387 #endif /* AFS_NEED_CLIENTCONTEXT */
3389 /* get all interface addresses of this client */
3391 DECL_PIOCTL(PGetCPrefs)
3393 struct sprefrequest *spin; /* input */
3394 struct sprefinfo *spout; /* output */
3395 struct spref *srvout; /* one output component */
3399 AFS_STATCNT(PGetCPrefs);
3400 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3401 return EIO; /* Inappropriate ioctl for device */
3403 if (ainSize < sizeof(struct sprefrequest))
3406 spin = (struct sprefrequest *)ain;
3407 spout = (struct sprefinfo *)aout;
3409 maxNumber = spin->num_servers; /* max addrs this time */
3410 srvout = spout->servers;
3412 ObtainReadLock(&afs_xinterface);
3414 /* copy out the client interface information from the
3415 ** kernel data structure "interface" to the output buffer
3417 for (i = spin->offset, j = 0; (i < afs_cb_interface.numberOfInterfaces)
3418 && (j < maxNumber); i++, j++, srvout++)
3419 srvout->host.s_addr = afs_cb_interface.addr_in[i];
3421 spout->num_servers = j;
3422 *aoutSize = sizeof(struct sprefinfo) + (j - 1) * sizeof(struct spref);
3424 if (i >= afs_cb_interface.numberOfInterfaces)
3425 spout->next_offset = 0; /* start from beginning again */
3427 spout->next_offset = spin->offset + j;
3429 ReleaseReadLock(&afs_xinterface);
3433 DECL_PIOCTL(PSetCPrefs)
3435 struct setspref *sin;
3438 AFS_STATCNT(PSetCPrefs);
3439 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3440 return EIO; /* Inappropriate ioctl for device */
3442 sin = (struct setspref *)ain;
3444 if (ainSize < sizeof(struct setspref))
3446 #if 0 /* num_servers is unsigned */
3447 if (sin->num_servers < 0)
3450 if (sin->num_servers > AFS_MAX_INTERFACE_ADDR)
3453 ObtainWriteLock(&afs_xinterface, 412);
3454 afs_cb_interface.numberOfInterfaces = sin->num_servers;
3455 for (i = 0; (unsigned short)i < sin->num_servers; i++)
3456 afs_cb_interface.addr_in[i] = sin->servers[i].host.s_addr;
3458 ReleaseWriteLock(&afs_xinterface);
3462 DECL_PIOCTL(PFlushMount)
3464 register afs_int32 code;
3465 register struct vcache *tvc;
3466 register struct dcache *tdc;
3467 struct VenusFid tfid;
3469 struct sysname_info sysState;
3470 afs_size_t offset, len;
3472 AFS_STATCNT(PFlushMount);
3475 code = afs_VerifyVCache(avc, areq);
3478 if (vType(avc) != VDIR) {
3481 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
3484 Check_AtSys(avc, ain, &sysState, areq);
3485 ObtainReadLock(&tdc->lock);
3487 code = afs_dir_Lookup(&tdc->f.inode, sysState.name, &tfid.Fid);
3488 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
3489 ReleaseReadLock(&tdc->lock);
3490 afs_PutDCache(tdc); /* we're done with the data */
3491 bufp = sysState.name;
3495 tfid.Cell = avc->fid.Cell;
3496 tfid.Fid.Volume = avc->fid.Fid.Volume;
3497 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
3498 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
3500 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3506 if (tvc->mvstat != 1) {
3511 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
3512 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
3514 ObtainWriteLock(&tvc->lock, 649);
3515 ObtainWriteLock(&afs_xcbhash, 650);
3516 afs_DequeueCallback(tvc);
3517 tvc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
3518 ReleaseWriteLock(&afs_xcbhash);
3519 /* now find the disk cache entries */
3520 afs_TryToSmush(tvc, *acred, 1);
3521 osi_dnlc_purgedp(tvc);
3522 afs_symhint_inval(tvc);
3523 if (tvc->linkData && !(tvc->states & CCore)) {
3524 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
3525 tvc->linkData = NULL;
3527 ReleaseWriteLock(&tvc->lock);
3528 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
3529 afs_BozonUnlock(&tvc->pvnLock, tvc);
3533 if (sysState.allocked)
3534 osi_FreeLargeSpace(bufp);
3538 DECL_PIOCTL(PRxStatProc)
3543 if (!afs_osi_suser(*acred)) {
3547 if (ainSize != sizeof(afs_int32)) {
3551 memcpy((char *)&flags, ain, sizeof(afs_int32));
3552 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3556 if (flags & AFSCALL_RXSTATS_ENABLE) {
3557 rx_enableProcessRPCStats();
3559 if (flags & AFSCALL_RXSTATS_DISABLE) {
3560 rx_disableProcessRPCStats();
3562 if (flags & AFSCALL_RXSTATS_CLEAR) {
3563 rx_clearProcessRPCStats(AFS_RX_STATS_CLEAR_ALL);
3571 DECL_PIOCTL(PRxStatPeer)
3576 if (!afs_osi_suser(*acred)) {
3580 if (ainSize != sizeof(afs_int32)) {
3584 memcpy((char *)&flags, ain, sizeof(afs_int32));
3585 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3589 if (flags & AFSCALL_RXSTATS_ENABLE) {
3590 rx_enablePeerRPCStats();
3592 if (flags & AFSCALL_RXSTATS_DISABLE) {
3593 rx_disablePeerRPCStats();
3595 if (flags & AFSCALL_RXSTATS_CLEAR) {
3596 rx_clearPeerRPCStats(AFS_RX_STATS_CLEAR_ALL);
3603 DECL_PIOCTL(PPrefetchFromTape)
3605 register afs_int32 code, code1;
3608 struct rx_call *tcall;
3609 struct AFSVolSync tsync;
3610 struct AFSFetchStatus OutStatus;
3611 struct AFSCallBack CallBack;
3612 struct VenusFid tfid;
3616 AFS_STATCNT(PSetAcl);
3620 if (ain && (ainSize == 3 * sizeof(afs_int32)))
3621 Fid = (struct AFSFid *)ain;
3623 Fid = &avc->fid.Fid;
3624 tfid.Cell = avc->fid.Cell;
3625 tfid.Fid.Volume = Fid->Volume;
3626 tfid.Fid.Vnode = Fid->Vnode;
3627 tfid.Fid.Unique = Fid->Unique;
3629 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3631 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3632 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &avc->fid);
3635 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3636 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &tvc->fid);
3639 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3643 tcall = rx_NewCall(tc->id);
3645 StartRXAFS_FetchData(tcall, (struct AFSFid *)&tvc->fid.Fid, 0,
3648 bytes = rx_Read(tcall, (char *)aout, sizeof(afs_int32));
3650 EndRXAFS_FetchData(tcall, &OutStatus, &CallBack, &tsync);
3652 code1 = rx_EndCall(tcall, code);
3656 } while (afs_Analyze
3657 (tc, code, &tvc->fid, areq, AFS_STATS_FS_RPCIDX_RESIDENCYRPCS,
3658 SHARED_LOCK, NULL));
3659 /* This call is done only to have the callback things handled correctly */
3660 afs_FetchStatus(tvc, &tfid, areq, &OutStatus);
3664 *aoutSize = sizeof(afs_int32);
3669 DECL_PIOCTL(PResidencyCmd)
3671 register afs_int32 code;
3674 struct ResidencyCmdInputs *Inputs;
3675 struct ResidencyCmdOutputs *Outputs;
3676 struct VenusFid tfid;
3679 Inputs = (struct ResidencyCmdInputs *)ain;
3680 Outputs = (struct ResidencyCmdOutputs *)aout;
3683 if (!ain || ainSize != sizeof(struct ResidencyCmdInputs))
3688 Fid = &avc->fid.Fid;
3690 tfid.Cell = avc->fid.Cell;
3691 tfid.Fid.Volume = Fid->Volume;
3692 tfid.Fid.Vnode = Fid->Vnode;
3693 tfid.Fid.Unique = Fid->Unique;
3695 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3696 afs_Trace3(afs_iclSetp, CM_TRACE_RESIDCMD, ICL_TYPE_POINTER, tvc,
3697 ICL_TYPE_INT32, Inputs->command, ICL_TYPE_FID, &tfid);
3701 if (Inputs->command) {
3703 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3707 RXAFS_ResidencyCmd(tc->id, Fid, Inputs,
3708 (struct ResidencyCmdOutputs *)aout);
3712 } while (afs_Analyze
3713 (tc, code, &tvc->fid, areq,
3714 AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK, NULL));
3715 /* This call is done to have the callback things handled correctly */
3716 afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3717 } else { /* just a status request, return also link data */
3719 Outputs->code = afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3720 Outputs->chars[0] = 0;
3721 if (vType(tvc) == VLNK) {
3722 ObtainWriteLock(&tvc->lock, 555);
3723 if (afs_HandleLink(tvc, areq) == 0)
3724 strncpy((char *)&Outputs->chars, tvc->linkData, MAXCMDCHARS);
3725 ReleaseWriteLock(&tvc->lock);
3732 *aoutSize = sizeof(struct ResidencyCmdOutputs);