2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include "afs/param.h"
16 #include "afs/sysincludes.h" /* Standard vendor system headers */
18 #include "h/syscallargs.h"
21 #include "h/sysproto.h"
23 #include "afsincludes.h" /* Afs-based standard headers */
24 #include "afs/afs_stats.h" /* afs statistics */
26 #include "rx/rx_globals.h"
28 struct VenusFid afs_rootFid;
29 afs_int32 afs_waitForever = 0;
30 short afs_waitForeverCount = 0;
31 afs_int32 afs_showflags = GAGUSER | GAGCONSOLE; /* show all messages */
33 #define DECL_PIOCTL(x) static int x(struct vcache *avc, int afun, struct vrequest *areq, \
34 char *ain, char *aout, afs_int32 ainSize, afs_int32 *aoutSize, \
35 struct AFS_UCRED **acred)
37 /* Prototypes for pioctl routines */
40 DECL_PIOCTL(PStoreBehind);
45 DECL_PIOCTL(PGetFileCell);
46 DECL_PIOCTL(PGetWSCell);
47 DECL_PIOCTL(PGetUserCell);
48 DECL_PIOCTL(PSetTokens);
49 DECL_PIOCTL(PGetVolumeStatus);
50 DECL_PIOCTL(PSetVolumeStatus);
52 DECL_PIOCTL(PNewStatMount);
53 DECL_PIOCTL(PGetTokens);
55 DECL_PIOCTL(PMariner);
56 DECL_PIOCTL(PCheckServers);
57 DECL_PIOCTL(PCheckVolNames);
58 DECL_PIOCTL(PCheckAuth);
59 DECL_PIOCTL(PFindVolume);
60 DECL_PIOCTL(PViceAccess);
61 DECL_PIOCTL(PSetCacheSize);
62 DECL_PIOCTL(PGetCacheSize);
63 DECL_PIOCTL(PRemoveCallBack);
64 DECL_PIOCTL(PNewCell);
65 DECL_PIOCTL(PNewAlias);
66 DECL_PIOCTL(PListCells);
67 DECL_PIOCTL(PListAliases);
68 DECL_PIOCTL(PRemoveMount);
69 DECL_PIOCTL(PVenusLogging);
70 DECL_PIOCTL(PGetCellStatus);
71 DECL_PIOCTL(PSetCellStatus);
72 DECL_PIOCTL(PFlushVolumeData);
73 DECL_PIOCTL(PGetVnodeXStatus);
74 DECL_PIOCTL(PSetSysName);
75 DECL_PIOCTL(PSetSPrefs);
76 DECL_PIOCTL(PSetSPrefs33);
77 DECL_PIOCTL(PGetSPrefs);
78 DECL_PIOCTL(PExportAfs);
80 DECL_PIOCTL(PTwiddleRx);
81 DECL_PIOCTL(PGetInitParams);
82 DECL_PIOCTL(PGetRxkcrypt);
83 DECL_PIOCTL(PSetRxkcrypt);
84 DECL_PIOCTL(PGetCPrefs);
85 DECL_PIOCTL(PSetCPrefs);
86 DECL_PIOCTL(PFlushMount);
87 DECL_PIOCTL(PRxStatProc);
88 DECL_PIOCTL(PRxStatPeer);
89 DECL_PIOCTL(PPrefetchFromTape);
90 DECL_PIOCTL(PResidencyCmd);
91 DECL_PIOCTL(PCallBackAddr);
94 * A macro that says whether we're going to need HandleClientContext().
95 * This is currently used only by the nfs translator.
97 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
98 #define AFS_NEED_CLIENTCONTEXT
101 /* Prototypes for private routines */
102 #ifdef AFS_NEED_CLIENTCONTEXT
103 static int HandleClientContext(struct afs_ioctl *ablob, int *com,
104 struct AFS_UCRED **acred,
105 struct AFS_UCRED *credp);
107 int HandleIoctl(register struct vcache *avc, register afs_int32 acom,
108 struct afs_ioctl *adata);
109 int afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
110 register struct afs_ioctl *ablob, int afollow,
111 struct AFS_UCRED **acred);
112 static int Prefetch(char *apath, struct afs_ioctl *adata, int afollow,
113 struct AFS_UCRED *acred);
116 static int (*(VpioctlSw[])) () = {
121 PGetVolumeStatus, /* 4 */
122 PSetVolumeStatus, /* 5 */
127 PCheckServers, /* 10 */
128 PCheckVolNames, /* 11 */
130 PBogus, /* 13 -- used to be quick check time */
131 PFindVolume, /* 14 */
132 PBogus, /* 15 -- prefetch is now special-cased; see pioctl code! */
133 PBogus, /* 16 -- used to be testing code */
134 PNoop, /* 17 -- used to be enable group */
135 PNoop, /* 18 -- used to be disable group */
136 PBogus, /* 19 -- used to be list group */
137 PViceAccess, /* 20 */
138 PUnlog, /* 21 -- unlog *is* unpag in this system */
139 PGetFID, /* 22 -- get file ID */
140 PBogus, /* 23 -- used to be waitforever */
141 PSetCacheSize, /* 24 */
142 PRemoveCallBack, /* 25 -- flush only the callback */
145 PRemoveMount, /* 28 -- delete mount point */
146 PNewStatMount, /* 29 -- new style mount point stat */
147 PGetFileCell, /* 30 -- get cell name for input file */
148 PGetWSCell, /* 31 -- get cell name for workstation */
149 PMariner, /* 32 - set/get mariner host */
150 PGetUserCell, /* 33 -- get cell name for user */
151 PVenusLogging, /* 34 -- Enable/Disable logging */
152 PGetCellStatus, /* 35 */
153 PSetCellStatus, /* 36 */
154 PFlushVolumeData, /* 37 -- flush all data from a volume */
155 PSetSysName, /* 38 - Set system name */
156 PExportAfs, /* 39 - Export Afs to remote nfs clients */
157 PGetCacheSize, /* 40 - get cache size and usage */
158 PGetVnodeXStatus, /* 41 - get vcache's special status */
159 PSetSPrefs33, /* 42 - Set CM Server preferences... */
160 PGetSPrefs, /* 43 - Get CM Server preferences... */
161 PGag, /* 44 - turn off/on all CM messages */
162 PTwiddleRx, /* 45 - adjust some RX params */
163 PSetSPrefs, /* 46 - Set CM Server preferences... */
164 PStoreBehind, /* 47 - set degree of store behind to be done */
165 PGCPAGs, /* 48 - disable automatic pag gc-ing */
166 PGetInitParams, /* 49 - get initial cm params */
167 PGetCPrefs, /* 50 - get client interface addresses */
168 PSetCPrefs, /* 51 - set client interface addresses */
169 PFlushMount, /* 52 - flush mount symlink data */
170 PRxStatProc, /* 53 - control process RX statistics */
171 PRxStatPeer, /* 54 - control peer RX statistics */
172 PGetRxkcrypt, /* 55 -- Get rxkad encryption flag */
173 PSetRxkcrypt, /* 56 -- Set rxkad encryption flag */
174 PBogus, /* 57 -- arla: set file prio */
175 PBogus, /* 58 -- arla: fallback getfh */
176 PBogus, /* 59 -- arla: fallback fhopen */
177 PBogus, /* 60 -- arla: controls xfsdebug */
178 PBogus, /* 61 -- arla: controls arla debug */
179 PBogus, /* 62 -- arla: debug interface */
180 PBogus, /* 63 -- arla: print xfs status */
181 PBogus, /* 64 -- arla: force cache check */
182 PBogus, /* 65 -- arla: break callback */
183 PPrefetchFromTape, /* 66 -- MR-AFS: prefetch file from tape */
184 PResidencyCmd, /* 67 -- MR-AFS: generic commnd interface */
185 PBogus, /* 68 -- arla: fetch stats */
188 static int (*(CpioctlSw[])) () = {
190 PNewAlias, /* 1 -- create new cell alias */
191 PListAliases, /* 2 -- list cell aliases */
192 PCallBackAddr, /* 3 -- request addr for callback rxcon */
195 #define PSetClientContext 99 /* Special pioctl to setup caller's creds */
196 int afs_nobody = NFS_NOBODY;
199 afs_ioctl32_to_afs_ioctl(const struct afs_ioctl32 *src, struct afs_ioctl *dst)
201 dst->in = (char *)(unsigned long)src->in;
202 dst->out = (char *)(unsigned long)src->out;
203 dst->in_size = src->in_size;
204 dst->out_size = src->out_size;
208 * If you need to change copyin_afs_ioctl(), you may also need to change
213 copyin_afs_ioctl(caddr_t cmarg, struct afs_ioctl *dst)
216 #if defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)
217 struct afs_ioctl32 dst32;
220 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
222 afs_ioctl32_to_afs_ioctl(&dst32, dst);
225 #endif /* defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL) */
228 #if defined(AFS_HPUX_64BIT_ENV)
229 struct afs_ioctl32 dst32;
231 if (is_32bit(u.u_procp)) { /* is_32bit() in proc_iface.h */
232 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
234 afs_ioctl32_to_afs_ioctl(&dst32, dst);
237 #endif /* defined(AFS_HPUX_64BIT_ENV) */
239 #if defined(AFS_SUN57_64BIT_ENV)
240 struct afs_ioctl32 dst32;
242 if (get_udatamodel() == DATAMODEL_ILP32) {
243 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
245 afs_ioctl32_to_afs_ioctl(&dst32, dst);
248 #endif /* defined(AFS_SUN57_64BIT_ENV) */
250 #if defined(AFS_SGI_ENV) && (_MIPS_SZLONG==64)
251 struct afs_ioctl32 dst32;
253 if (!ABI_IS_64BIT(get_current_abi())) {
254 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
256 afs_ioctl32_to_afs_ioctl(&dst32, dst);
259 #endif /* defined(AFS_SGI_ENV) && (_MIPS_SZLONG==64) */
261 #if defined(AFS_LINUX_64BIT_KERNEL) && !defined(AFS_ALPHA_LINUX20_ENV) && !defined(AFS_IA64_LINUX20_ENV) && !defined(AFS_AMD64_LINUX20_ENV)
262 struct afs_ioctl32 dst32;
264 #ifdef AFS_SPARC64_LINUX24_ENV
265 if (current->thread.flags & SPARC_FLAG_32BIT)
266 #elif defined(AFS_SPARC64_LINUX20_ENV)
267 if (current->tss.flags & SPARC_FLAG_32BIT)
268 #elif defined(AFS_AMD64_LINUX20_ENV)
269 if (current->thread.flags & THREAD_IA32)
270 #elif defined(AFS_PPC64_LINUX20_ENV)
271 if (current->thread.flags & PPC_FLAG_32BIT)
273 #error Not done for this linux type
276 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
278 afs_ioctl32_to_afs_ioctl(&dst32, dst);
281 #endif /* defined(AFS_LINUX_64BIT_KERNEL) */
283 AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code);
288 HandleIoctl(register struct vcache *avc, register afs_int32 acom,
289 struct afs_ioctl *adata)
291 register afs_int32 code;
294 AFS_STATCNT(HandleIoctl);
296 switch (acom & 0xff) {
298 avc->states |= CSafeStore;
302 /* case 2 used to be abort store, but this is no longer provided,
303 * since it is impossible to implement under normal Unix.
307 /* return the name of the cell this file is open on */
308 register struct cell *tcell;
309 register afs_int32 i;
311 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
313 i = strlen(tcell->cellName) + 1; /* bytes to copy out */
315 if (i > adata->out_size) {
316 /* 0 means we're not interested in the output */
317 if (adata->out_size != 0)
321 AFS_COPYOUT(tcell->cellName, adata->out, i, code);
323 afs_PutCell(tcell, READ_LOCK);
329 case 49: /* VIOC_GETINITPARAMS */
330 if (adata->out_size < sizeof(struct cm_initparams)) {
333 AFS_COPYOUT(&cm_initParams, adata->out,
334 sizeof(struct cm_initparams), code);
346 return code; /* so far, none implemented */
351 /* For aix we don't temporarily bypass ioctl(2) but rather do our
352 * thing directly in the vnode layer call, VNOP_IOCTL; thus afs_ioctl
353 * is now called from afs_gn_ioctl.
356 afs_ioctl(struct vcache *tvc, int cmd, int arg)
358 struct afs_ioctl data;
361 AFS_STATCNT(afs_ioctl);
362 if (((cmd >> 8) & 0xff) == 'V') {
363 /* This is a VICEIOCTL call */
364 AFS_COPYIN(arg, (caddr_t) & data, sizeof(data), error);
367 error = HandleIoctl(tvc, cmd, &data);
370 /* No-op call; just return. */
374 #endif /* AFS_AIX_ENV */
376 #if defined(AFS_SGI_ENV)
377 afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
380 , struct vopbd * vbds
384 struct afs_ioctl data;
390 AFS_STATCNT(afs_ioctl);
391 if (((cmd >> 8) & 0xff) == 'V') {
392 /* This is a VICEIOCTL call */
393 error = copyin_afs_ioctl(arg, &data);
396 locked = ISAFS_GLOCK();
399 error = HandleIoctl(tvc, cmd, &data);
404 /* No-op call; just return. */
408 #endif /* AFS_SGI_ENV */
410 /* unlike most calls here, this one uses u.u_error to return error conditions,
411 since this is really an intercepted chapter 2 call, rather than a vnode
414 /* AFS_HPUX102 and up uses VNODE ioctl instead */
415 #ifndef AFS_HPUX102_ENV
416 #if !defined(AFS_SGI_ENV)
420 kioctl(fdes, com, arg, ext, arg2, arg3)
421 #else /* __64BIT__ */
422 kioctl32(fdes, com, arg, ext, arg2, arg3)
423 #endif /* __64BIT__ */
426 kioctl(fdes, com, arg, ext)
437 } u_uap, *uap = &u_uap;
439 #if defined(AFS_SUN5_ENV)
441 struct afs_ioctl_sys {
448 struct afs_ioctl_sys *uap;
451 #elif defined(AFS_OSF_ENV)
452 afs_xioctl(p, args, retval)
461 } *uap = (struct a *)args;
462 #elif defined(AFS_FBSD50_ENV)
465 afs_xioctl(td, uap, retval)
467 register struct ioctl_args *uap;
470 struct proc *p = td->td_proc;
471 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
479 afs_xioctl(p, uap, retval)
481 register struct ioctl_args *uap;
484 #elif defined(AFS_LINUX22_ENV)
485 struct afs_ioctl_sys {
490 afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
493 struct afs_ioctl_sys ua, *uap = &ua;
502 } *uap = (struct a *)u.u_ap;
503 #endif /* AFS_SUN5_ENV */
505 #if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
507 #elif !defined(AFS_LINUX22_ENV)
508 register struct file *fd;
510 #if defined(AFS_XBSD_ENV)
511 register struct filedesc *fdp;
513 register struct vcache *tvc;
514 register int ioctlDone = 0, code = 0;
516 AFS_STATCNT(afs_xioctl);
517 #if defined(AFS_XBSD_ENV)
519 if ((u_int) uap->fd >= fdp->fd_nfiles
520 || (fd = fdp->fd_ofiles[uap->fd]) == NULL)
522 if ((fd->f_flag & (FREAD | FWRITE)) == 0)
524 #elif defined(AFS_DARWIN_ENV)
525 if ((code = fdgetf(p, uap->fd, &fd)))
527 #elif defined(AFS_LINUX22_ENV)
530 #elif defined(AFS_AIX32_ENV)
538 if (setuerror(getf(uap->fd, &fd))) {
541 #elif defined(AFS_OSF_ENV)
543 if (code = getf(&fd, uap->fd, FILE_FLAGS_NULL, &u.u_file_state))
545 #elif defined(AFS_SUN5_ENV)
546 # if defined(AFS_SUN57_ENV)
550 # elif defined(AFS_SUN54_ENV)
555 if (code = getf(uap->fd, &fd)) {
558 # endif /* AFS_SUN57_ENV */
564 /* first determine whether this is any sort of vnode */
565 #if defined(AFS_LINUX22_ENV)
570 if (fd->f_vnode->v_type == VREG || fd->f_vnode->v_type == VDIR) {
572 if (fd->f_type == DTYPE_VNODE) {
574 /* good, this is a vnode; next see if it is an AFS vnode */
575 #if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV)
576 tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */
577 #elif defined(AFS_OBSD_ENV)
579 IsAfsVnode((struct vnode *)fd->
580 f_data) ? VTOAFS((struct vnode *)fd->f_data) : NULL;
582 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
584 #endif /* AFS_LINUX22_ENV */
585 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
587 tvc = VTOAFS(afs_gntovn((struct gnode *)tvc));
588 if (!tvc) { /* shouldn't happen with held gnodes */
593 /* This is an AFS vnode */
594 if (((uap->com >> 8) & 0xff) == 'V') {
595 register struct afs_ioctl *datap;
598 (struct afs_ioctl *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
599 AFS_COPYIN((char *)uap->arg, (caddr_t) datap,
600 sizeof(struct afs_ioctl), code);
602 osi_FreeSmallSpace(datap);
604 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
607 #if defined(AFS_SUN5_ENV)
622 #else /* AFS_OSF_ENV */
626 #ifdef AFS_LINUX22_ENV
636 code = HandleIoctl(tvc, uap->com, datap);
637 osi_FreeSmallSpace(datap);
651 #if defined(AFS_LINUX22_ENV)
663 code = okioctl(fdes, com, arg, ext, arg2, arg3);
664 #else /* __64BIT__ */
665 code = okioctl32(fdes, com, arg, ext, arg2, arg3);
666 #endif /* __64BIT__ */
667 #else /* !AFS_AIX51_ENV */
668 code = okioctl(fdes, com, arg, ext);
669 #endif /* AFS_AIX51_ENV */
671 #else /* !AFS_AIX41_ENV */
673 okioctl(fdes, com, arg, ext);
674 #elif defined(AFS_SUN5_ENV)
675 #if defined(AFS_SUN57_ENV)
677 #elif defined(AFS_SUN54_ENV)
682 code = ioctl(uap, rvp);
683 #elif defined(AFS_FBSD50_ENV)
684 return ioctl(td, uap);
685 #elif defined(AFS_FBSD_ENV)
686 return ioctl(p, uap);
687 #elif defined(AFS_OBSD_ENV)
688 code = sys_ioctl(p, uap, retval);
689 #elif defined(AFS_DARWIN_ENV)
690 return ioctl(p, uap, retval);
691 #elif defined(AFS_OSF_ENV)
692 code = ioctl(p, args, retval);
699 #elif !defined(AFS_LINUX22_ENV)
713 #ifdef AFS_LINUX22_ENV
716 #if defined(KERNEL_HAVE_UERROR)
719 #if defined(AFS_AIX32_ENV) && !defined(AFS_AIX41_ENV)
720 return (getuerror()? -1 : u.u_ioctlrv);
722 return getuerror()? -1 : 0;
725 #endif /* AFS_LINUX22_ENV */
726 #endif /* AFS_SUN5_ENV */
727 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
731 #endif /* AFS_SGI_ENV */
732 #endif /* AFS_HPUX102_ENV */
734 #if defined(AFS_SGI_ENV)
735 /* "pioctl" system call entry point; just pass argument to the parameterized
744 afs_pioctl(struct pioctlargs *uap, rval_t * rvp)
748 AFS_STATCNT(afs_pioctl);
750 code = afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow);
759 #elif defined(AFS_OSF_ENV)
760 afs_pioctl(p, args, retval)
770 } *uap = (struct a *)args;
772 AFS_STATCNT(afs_pioctl);
773 return (afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow));
776 #elif defined(AFS_FBSD50_ENV)
778 afs_pioctl(td, args, retval)
788 } *uap = (struct a *)args;
790 AFS_STATCNT(afs_pioctl);
791 return (afs_syscall_pioctl
792 (uap->path, uap->cmd, uap->cmarg, uap->follow, td->td_ucred));
795 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
797 afs_pioctl(p, args, retval)
807 } *uap = (struct a *)args;
809 AFS_STATCNT(afs_pioctl);
810 return (afs_syscall_pioctl
811 (uap->path, uap->cmd, uap->cmarg, uap->follow,
812 p->p_cred->pc_ucred));
817 /* macro to avoid adding any more #ifdef's to pioctl code. */
818 #if defined(AFS_LINUX22_ENV) || defined(AFS_AIX41_ENV)
819 #define PIOCTL_FREE_CRED() crfree(credp)
821 #define PIOCTL_FREE_CRED()
826 afs_syscall_pioctl(path, com, cmarg, follow, rvp, credp)
828 struct AFS_UCRED *credp;
830 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
831 afs_syscall_pioctl(path, com, cmarg, follow, credp)
832 struct AFS_UCRED *credp;
834 afs_syscall_pioctl(path, com, cmarg, follow)
842 struct afs_ioctl data;
843 struct AFS_UCRED *tmpcred, *foreigncreds = NULL;
844 register afs_int32 code = 0;
850 struct ucred *credp = crref(); /* don't free until done! */
852 #ifdef AFS_LINUX22_ENV
853 cred_t *credp = crref(); /* don't free until done! */
857 AFS_STATCNT(afs_syscall_pioctl);
859 follow = 1; /* compat. with old venus */
860 code = copyin_afs_ioctl(cmarg, &data);
863 #if defined(KERNEL_HAVE_UERROR)
868 if ((com & 0xff) == PSetClientContext) {
869 #ifdef AFS_NEED_CLIENTCONTEXT
870 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV)
871 code = HandleClientContext(&data, &com, &foreigncreds, credp);
873 code = HandleClientContext(&data, &com, &foreigncreds, osi_curcred());
877 crfree(foreigncreds);
880 #if defined(KERNEL_HAVE_UERROR)
881 return (setuerror(code), code);
886 #else /* AFS_NEED_CLIENTCONTEXT */
888 #endif /* AFS_NEED_CLIENTCONTEXT */
890 #ifdef AFS_NEED_CLIENTCONTEXT
893 * We could have done without temporary setting the u.u_cred below
894 * (foreigncreds could be passed as param the pioctl modules)
895 * but calls such as afs_osi_suser() doesn't allow that since it
896 * references u.u_cred directly. We could, of course, do something
897 * like afs_osi_suser(cred) which, I think, is better since it
898 * generalizes and supports multi cred environments...
902 credp = foreigncreds;
903 #elif defined(AFS_AIX41_ENV)
904 tmpcred = crref(); /* XXX */
906 #elif defined(AFS_HPUX101_ENV)
907 tmpcred = p_cred(u.u_procp);
908 set_p_cred(u.u_procp, foreigncreds);
909 #elif defined(AFS_SGI_ENV)
910 tmpcred = OSI_GET_CURRENT_CRED();
911 OSI_SET_CURRENT_CRED(foreigncreds);
914 u.u_cred = foreigncreds;
917 #endif /* AFS_NEED_CLIENTCONTEXT */
918 if ((com & 0xff) == 15) {
919 /* special case prefetch so entire pathname eval occurs in helper process.
920 * otherwise, the pioctl call is essentially useless */
921 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
923 Prefetch(path, &data, follow,
924 foreigncreds ? foreigncreds : credp);
926 code = Prefetch(path, &data, follow, osi_curcred());
929 #if defined(KERNEL_HAVE_UERROR)
938 lookupname(path, USR, follow, NULL, &vp,
939 foreigncreds ? foreigncreds : credp);
941 #ifdef AFS_LINUX22_ENV
942 code = gop_lookupname(path, AFS_UIOUSER, follow, NULL, &dp);
944 vp = (struct vnode *)dp->d_inode;
946 code = gop_lookupname(path, AFS_UIOUSER, follow, NULL, &vp);
947 #endif /* AFS_LINUX22_ENV */
948 #endif /* AFS_AIX41_ENV */
952 #if defined(KERNEL_HAVE_UERROR)
960 /* now make the call if we were passed no file, or were passed an AFS file */
961 if (!vp || IsAfsVnode(vp)) {
962 #if defined(AFS_DEC_ENV)
963 /* Ultrix 4.0: can't get vcache entry unless we've got an AFS gnode.
964 * So, we must test in this part of the code. Also, must arrange to
965 * GRELE the original gnode pointer when we're done, since in Ultrix 4.0,
966 * we hold gnodes, whose references hold our vcache entries.
969 gp = vp; /* remember for "put" */
970 vp = (struct vnode *)afs_gntovn(vp); /* get vcache from gp */
973 #elif defined(AFS_SUN5_ENV)
974 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
975 #elif defined(AFS_AIX41_ENV)
977 struct ucred *cred1, *cred2;
980 cred1 = cred2 = foreigncreds;
982 cred1 = cred2 = credp;
984 code = afs_HandlePioctl(vp, com, &data, follow, &cred1);
985 if (cred1 != cred2) {
986 /* something changed the creds */
990 #elif defined(AFS_HPUX101_ENV)
992 struct ucred *cred = p_cred(u.u_procp);
993 code = afs_HandlePioctl(vp, com, &data, follow, &cred);
995 #elif defined(AFS_SGI_ENV)
998 credp = OSI_GET_CURRENT_CRED();
999 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1001 #elif defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1002 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1004 code = afs_HandlePioctl(vp, com, &data, follow, &u.u_cred);
1007 #if defined(KERNEL_HAVE_UERROR)
1010 code = EINVAL; /* not in /afs */
1021 #if defined(AFS_NEED_CLIENTCONTEXT)
1023 #ifdef AFS_AIX41_ENV
1024 crset(tmpcred); /* restore original credentials */
1026 #if defined(AFS_HPUX101_ENV)
1027 set_p_cred(u.u_procp, tmpcred); /* restore original credentials */
1028 #elif defined(AFS_SGI_ENV)
1029 OSI_SET_CURRENT_CRED(tmpcred); /* restore original credentials */
1030 #elif !defined(AFS_SUN5_ENV)
1031 osi_curcred() = tmpcred; /* restore original credentials */
1032 #endif /* AFS_HPUX101_ENV */
1033 crfree(foreigncreds);
1036 #endif /* AFS_NEED_CLIENTCONTEXT */
1038 #ifdef AFS_LINUX22_ENV
1041 AFS_RELE(vp); /* put vnode back */
1045 #if defined(KERNEL_HAVE_UERROR)
1048 return (getuerror());
1054 #define MAXPIOCTLTOKENLEN \
1055 (3*sizeof(afs_int32)+MAXKTCTICKETLEN+sizeof(struct ClearToken)+MAXKTCREALMLEN)
1058 afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
1059 register struct afs_ioctl *ablob, int afollow,
1060 struct AFS_UCRED **acred)
1063 struct vrequest treq;
1064 register afs_int32 code;
1065 register afs_int32 function, device;
1066 afs_int32 inSize, outSize, outSizeMax;
1067 char *inData, *outData;
1068 int (*(*pioctlSw)) ();
1070 struct afs_fakestat_state fakestate;
1072 avc = avp ? VTOAFS(avp) : NULL;
1073 afs_Trace3(afs_iclSetp, CM_TRACE_PIOCTL, ICL_TYPE_INT32, acom & 0xff,
1074 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, afollow);
1075 AFS_STATCNT(HandlePioctl);
1076 if ((code = afs_InitReq(&treq, *acred)))
1078 afs_InitFakeStat(&fakestate);
1080 code = afs_EvalFakeStat(&avc, &fakestate, &treq);
1082 afs_PutFakeStat(&fakestate);
1086 device = (acom & 0xff00) >> 8;
1088 case 'V': /* Original pioctls */
1089 pioctlSw = VpioctlSw;
1090 pioctlSwSize = sizeof(VpioctlSw);
1092 case 'C': /* Coordinated/common pioctls */
1093 pioctlSw = CpioctlSw;
1094 pioctlSwSize = sizeof(CpioctlSw);
1097 afs_PutFakeStat(&fakestate);
1100 function = acom & 0xff;
1101 if (function >= (pioctlSwSize / sizeof(char *))) {
1102 afs_PutFakeStat(&fakestate);
1103 return EINVAL; /* out of range */
1105 inSize = ablob->in_size;
1107 /* Do all range checking before continuing */
1108 if (inSize > MAXPIOCTLTOKENLEN || inSize < 0 || ablob->out_size < 0)
1111 if (inSize > AFS_LRALLOCSIZ) {
1112 inData = osi_AllocLargeSpace(inSize+1);
1114 inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1119 AFS_COPYIN(ablob->in, inData, inSize, code);
1120 inData[inSize] = '\0';
1124 if (inSize > AFS_LRALLOCSIZ) {
1125 osi_Free(inData, inSize+1);
1127 osi_FreeLargeSpace(inData);
1129 afs_PutFakeStat(&fakestate);
1132 if (function == 8 && device == 'V') { /* PGetTokens */
1133 outSizeMax = MAXPIOCTLTOKENLEN;
1134 outData = osi_Alloc(outSizeMax);
1136 outSizeMax = AFS_LRALLOCSIZ;
1137 outData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1140 if (inSize > AFS_LRALLOCSIZ) {
1141 osi_Free(inData, inSize+1);
1143 osi_FreeLargeSpace(inData);
1149 (*pioctlSw[function]) (avc, function, &treq, inData, outData, inSize,
1151 if (inSize > AFS_LRALLOCSIZ) {
1152 osi_Free(inData, inSize+1);
1154 osi_FreeLargeSpace(inData);
1156 if (code == 0 && ablob->out_size > 0) {
1157 if (outSize > ablob->out_size) {
1158 code = E2BIG; /* data wont fit in user buffer */
1159 } else if (outSize) {
1160 AFS_COPYOUT(outData, ablob->out, outSize, code);
1163 if (outSizeMax > AFS_LRALLOCSIZ) {
1164 osi_Free(outData, outSizeMax);
1166 osi_FreeLargeSpace(outData);
1168 afs_PutFakeStat(&fakestate);
1169 return afs_CheckCode(code, &treq, 41);
1172 DECL_PIOCTL(PGetFID)
1174 AFS_STATCNT(PGetFID);
1177 memcpy(aout, (char *)&avc->fid, sizeof(struct VenusFid));
1178 *aoutSize = sizeof(struct VenusFid);
1182 DECL_PIOCTL(PSetAcl)
1184 register afs_int32 code;
1186 struct AFSOpaque acl;
1187 struct AFSVolSync tsync;
1188 struct AFSFetchStatus OutStatus;
1191 AFS_STATCNT(PSetAcl);
1194 if ((acl.AFSOpaque_len = strlen(ain) + 1) > 1000)
1197 acl.AFSOpaque_val = ain;
1199 tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1201 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREACL);
1204 RXAFS_StoreACL(tconn->id, (struct AFSFid *)&avc->fid.Fid,
1205 &acl, &OutStatus, &tsync);
1210 } while (afs_Analyze
1211 (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_STOREACL,
1212 SHARED_LOCK, NULL));
1214 /* now we've forgotten all of the access info */
1215 ObtainWriteLock(&afs_xcbhash, 455);
1217 afs_DequeueCallback(avc);
1218 avc->states &= ~(CStatd | CUnique);
1219 ReleaseWriteLock(&afs_xcbhash);
1220 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
1221 osi_dnlc_purgedp(avc);
1225 int afs_defaultAsynchrony = 0;
1227 DECL_PIOCTL(PStoreBehind)
1230 struct sbstruct *sbr;
1232 sbr = (struct sbstruct *)ain;
1233 if (sbr->sb_default != -1) {
1234 if (afs_osi_suser(*acred))
1235 afs_defaultAsynchrony = sbr->sb_default;
1240 if (avc && (sbr->sb_thisfile != -1)) {
1242 (avc, PRSFS_WRITE | PRSFS_ADMINISTER, areq, DONT_CHECK_MODE_BITS))
1243 avc->asynchrony = sbr->sb_thisfile;
1248 *aoutSize = sizeof(struct sbstruct);
1249 sbr = (struct sbstruct *)aout;
1250 sbr->sb_default = afs_defaultAsynchrony;
1252 sbr->sb_thisfile = avc->asynchrony;
1258 DECL_PIOCTL(PGCPAGs)
1260 if (!afs_osi_suser(*acred)) {
1263 afs_gcpags = AFS_GCPAGS_USERDISABLED;
1267 DECL_PIOCTL(PGetAcl)
1269 struct AFSOpaque acl;
1270 struct AFSVolSync tsync;
1271 struct AFSFetchStatus OutStatus;
1277 AFS_STATCNT(PGetAcl);
1280 Fid.Volume = avc->fid.Fid.Volume;
1281 Fid.Vnode = avc->fid.Fid.Vnode;
1282 Fid.Unique = avc->fid.Fid.Unique;
1283 if (avc->states & CForeign) {
1285 * For a dfs xlator acl we have a special hack so that the
1286 * xlator will distinguish which type of acl will return. So
1287 * we currently use the top 2-bytes (vals 0-4) to tell which
1288 * type of acl to bring back. Horrible hack but this will
1289 * cause the least number of changes to code size and interfaces.
1291 if (Fid.Vnode & 0xc0000000)
1293 Fid.Vnode |= (ainSize << 30);
1295 acl.AFSOpaque_val = aout;
1297 tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1300 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHACL);
1302 code = RXAFS_FetchACL(tconn->id, &Fid, &acl, &OutStatus, &tsync);
1307 } while (afs_Analyze
1308 (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_FETCHACL,
1309 SHARED_LOCK, NULL));
1312 *aoutSize = (acl.AFSOpaque_len == 0 ? 1 : acl.AFSOpaque_len);
1325 AFS_STATCNT(PBogus);
1329 DECL_PIOCTL(PGetFileCell)
1331 register struct cell *tcell;
1333 AFS_STATCNT(PGetFileCell);
1336 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
1339 strcpy(aout, tcell->cellName);
1340 afs_PutCell(tcell, READ_LOCK);
1341 *aoutSize = strlen(aout) + 1;
1345 DECL_PIOCTL(PGetWSCell)
1347 struct cell *tcell = NULL;
1349 AFS_STATCNT(PGetWSCell);
1350 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1351 return EIO; /* Inappropriate ioctl for device */
1353 tcell = afs_GetPrimaryCell(READ_LOCK);
1354 if (!tcell) /* no primary cell? */
1356 strcpy(aout, tcell->cellName);
1357 *aoutSize = strlen(aout) + 1;
1358 afs_PutCell(tcell, READ_LOCK);
1362 DECL_PIOCTL(PGetUserCell)
1364 register afs_int32 i;
1365 register struct unixuser *tu;
1366 register struct cell *tcell;
1368 AFS_STATCNT(PGetUserCell);
1369 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1370 return EIO; /* Inappropriate ioctl for device */
1372 /* return the cell name of the primary cell for this user */
1373 i = UHash(areq->uid);
1374 ObtainWriteLock(&afs_xuser, 224);
1375 for (tu = afs_users[i]; tu; tu = tu->next) {
1376 if (tu->uid == areq->uid && (tu->states & UPrimary)) {
1378 ReleaseWriteLock(&afs_xuser);
1383 tcell = afs_GetCell(tu->cell, READ_LOCK);
1384 afs_PutUser(tu, WRITE_LOCK);
1388 strcpy(aout, tcell->cellName);
1389 afs_PutCell(tcell, READ_LOCK);
1390 *aoutSize = strlen(aout) + 1; /* 1 for the null */
1393 ReleaseWriteLock(&afs_xuser);
1400 DECL_PIOCTL(PSetTokens)
1403 register struct unixuser *tu;
1404 struct ClearToken clear;
1405 register struct cell *tcell;
1408 struct vrequest treq;
1409 afs_int32 flag, set_parent_pag = 0;
1411 AFS_STATCNT(PSetTokens);
1412 if (!afs_resourceinit_flag) {
1415 memcpy((char *)&i, ain, sizeof(afs_int32));
1416 ain += sizeof(afs_int32);
1417 stp = ain; /* remember where the ticket is */
1418 if (i < 0 || i > MAXKTCTICKETLEN)
1419 return EINVAL; /* malloc may fail */
1421 ain += i; /* skip over ticket */
1422 memcpy((char *)&i, ain, sizeof(afs_int32));
1423 ain += sizeof(afs_int32);
1424 if (i != sizeof(struct ClearToken)) {
1427 memcpy((char *)&clear, ain, sizeof(struct ClearToken));
1428 if (clear.AuthHandle == -1)
1429 clear.AuthHandle = 999; /* more rxvab compat stuff */
1430 ain += sizeof(struct ClearToken);
1431 if (ainSize != 2 * sizeof(afs_int32) + stLen + sizeof(struct ClearToken)) {
1432 /* still stuff left? we've got primary flag and cell name. Set these */
1433 memcpy((char *)&flag, ain, sizeof(afs_int32)); /* primary id flag */
1434 ain += sizeof(afs_int32); /* skip id field */
1435 /* rest is cell name, look it up */
1436 /* some versions of gcc appear to need != 0 in order to get this right */
1437 if ((flag & 0x8000) != 0) { /* XXX Use Constant XXX */
1441 tcell = afs_GetCellByName(ain, READ_LOCK);
1445 /* default to primary cell, primary id */
1446 flag = 1; /* primary id */
1447 tcell = afs_GetPrimaryCell(READ_LOCK);
1452 afs_PutCell(tcell, READ_LOCK);
1453 if (set_parent_pag) {
1455 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1456 #if defined(AFS_DARWIN_ENV)
1457 struct proc *p = current_proc(); /* XXX */
1459 struct proc *p = curproc; /* XXX */
1461 uprintf("Process %d (%s) tried to change pags in PSetTokens\n",
1462 p->p_pid, p->p_comm);
1463 if (!setpag(p, acred, -1, &pag, 1)) {
1466 if (!setpag(u.u_procp, acred, -1, &pag, 1)) { /* XXX u.u_procp is a no-op XXX */
1468 if (!setpag(acred, -1, &pag, 1)) {
1471 afs_InitReq(&treq, *acred);
1475 /* now we just set the tokens */
1476 tu = afs_GetUser(areq->uid, i, WRITE_LOCK); /* i has the cell # */
1477 tu->vid = clear.ViceId;
1478 if (tu->stp != NULL) {
1479 afs_osi_Free(tu->stp, tu->stLen);
1481 tu->stp = (char *)afs_osi_Alloc(stLen);
1483 memcpy(tu->stp, stp, stLen);
1486 afs_stats_cmfullperf.authent.TicketUpdates++;
1487 afs_ComputePAGStats();
1488 #endif /* AFS_NOSTATS */
1489 tu->states |= UHasTokens;
1490 tu->states &= ~UTokensBad;
1491 afs_SetPrimary(tu, flag);
1492 tu->tokenTime = osi_Time();
1493 afs_ResetUserConns(tu);
1494 afs_PutUser(tu, WRITE_LOCK);
1509 DECL_PIOCTL(PGetVolumeStatus)
1512 char *offLineMsg = afs_osi_Alloc(256);
1513 char *motd = afs_osi_Alloc(256);
1514 register struct conn *tc;
1515 register afs_int32 code = 0;
1516 struct VolumeStatus volstat;
1518 char *Name, *OfflineMsg, *MOTD;
1521 AFS_STATCNT(PGetVolumeStatus);
1527 OfflineMsg = offLineMsg;
1530 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1532 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS);
1535 RXAFS_GetVolumeStatus(tc->id, avc->fid.Fid.Volume, &volstat,
1536 &Name, &OfflineMsg, &MOTD);
1541 } while (afs_Analyze
1542 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS,
1543 SHARED_LOCK, NULL));
1547 /* Copy all this junk into msg->im_data, keeping track of the lengths. */
1549 memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
1550 cp += sizeof(VolumeStatus);
1551 strcpy(cp, volName);
1552 cp += strlen(volName) + 1;
1553 strcpy(cp, offLineMsg);
1554 cp += strlen(offLineMsg) + 1;
1556 cp += strlen(motd) + 1;
1557 *aoutSize = (cp - aout);
1559 afs_osi_Free(offLineMsg, 256);
1560 afs_osi_Free(motd, 256);
1564 DECL_PIOCTL(PSetVolumeStatus)
1567 char *offLineMsg = afs_osi_Alloc(256);
1568 char *motd = afs_osi_Alloc(256);
1569 register struct conn *tc;
1570 register afs_int32 code = 0;
1571 struct AFSFetchVolumeStatus volstat;
1572 struct AFSStoreVolumeStatus storeStat;
1573 register struct volume *tvp;
1577 AFS_STATCNT(PSetVolumeStatus);
1583 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
1585 if (tvp->states & (VRO | VBackup)) {
1586 afs_PutVolume(tvp, READ_LOCK);
1590 afs_PutVolume(tvp, READ_LOCK);
1595 /* Copy the junk out, using cp as a roving pointer. */
1597 memcpy((char *)&volstat, cp, sizeof(AFSFetchVolumeStatus));
1598 cp += sizeof(AFSFetchVolumeStatus);
1599 if (strlen(cp) >= sizeof(volName)) {
1603 strcpy(volName, cp);
1604 cp += strlen(volName) + 1;
1605 if (strlen(cp) >= sizeof(offLineMsg)) {
1609 strcpy(offLineMsg, cp);
1610 cp += strlen(offLineMsg) + 1;
1611 if (strlen(cp) >= sizeof(motd)) {
1617 if (volstat.MinQuota != -1) {
1618 storeStat.MinQuota = volstat.MinQuota;
1619 storeStat.Mask |= AFS_SETMINQUOTA;
1621 if (volstat.MaxQuota != -1) {
1622 storeStat.MaxQuota = volstat.MaxQuota;
1623 storeStat.Mask |= AFS_SETMAXQUOTA;
1626 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1628 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS);
1631 RXAFS_SetVolumeStatus(tc->id, avc->fid.Fid.Volume, &storeStat,
1632 volName, offLineMsg, motd);
1637 } while (afs_Analyze
1638 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS,
1639 SHARED_LOCK, NULL));
1643 /* we are sending parms back to make compat. with prev system. should
1644 * change interface later to not ask for current status, just set new status */
1646 memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
1647 cp += sizeof(VolumeStatus);
1648 strcpy(cp, volName);
1649 cp += strlen(volName) + 1;
1650 strcpy(cp, offLineMsg);
1651 cp += strlen(offLineMsg) + 1;
1653 cp += strlen(motd) + 1;
1654 *aoutSize = cp - aout;
1656 afs_osi_Free(offLineMsg, 256);
1657 afs_osi_Free(motd, 256);
1663 AFS_STATCNT(PFlush);
1666 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
1667 afs_BozonLock(&avc->pvnLock, avc); /* Since afs_TryToSmush will do a pvn_vptrunc */
1669 ObtainWriteLock(&avc->lock, 225);
1670 ObtainWriteLock(&afs_xcbhash, 456);
1671 afs_DequeueCallback(avc);
1672 avc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
1673 ReleaseWriteLock(&afs_xcbhash);
1674 /* now find the disk cache entries */
1675 afs_TryToSmush(avc, *acred, 1);
1676 osi_dnlc_purgedp(avc);
1677 afs_symhint_inval(avc);
1678 if (avc->linkData && !(avc->states & CCore)) {
1679 afs_osi_Free(avc->linkData, strlen(avc->linkData) + 1);
1680 avc->linkData = NULL;
1682 ReleaseWriteLock(&avc->lock);
1683 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
1684 afs_BozonUnlock(&avc->pvnLock, avc);
1689 DECL_PIOCTL(PNewStatMount)
1691 register afs_int32 code;
1692 register struct vcache *tvc;
1693 register struct dcache *tdc;
1694 struct VenusFid tfid;
1696 struct sysname_info sysState;
1697 afs_size_t offset, len;
1699 AFS_STATCNT(PNewStatMount);
1702 code = afs_VerifyVCache(avc, areq);
1705 if (vType(avc) != VDIR) {
1708 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
1711 Check_AtSys(avc, ain, &sysState, areq);
1712 ObtainReadLock(&tdc->lock);
1714 code = afs_dir_Lookup(&tdc->f.inode, sysState.name, &tfid.Fid);
1715 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
1716 ReleaseReadLock(&tdc->lock);
1717 afs_PutDCache(tdc); /* we're done with the data */
1718 bufp = sysState.name;
1722 tfid.Cell = avc->fid.Cell;
1723 tfid.Fid.Volume = avc->fid.Fid.Volume;
1724 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
1725 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
1727 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
1733 if (tvc->mvstat != 1) {
1738 ObtainWriteLock(&tvc->lock, 226);
1739 code = afs_HandleLink(tvc, areq);
1741 if (tvc->linkData) {
1742 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
1745 /* we have the data */
1746 strcpy(aout, tvc->linkData);
1747 *aoutSize = strlen(tvc->linkData) + 1;
1752 ReleaseWriteLock(&tvc->lock);
1755 if (sysState.allocked)
1756 osi_FreeLargeSpace(bufp);
1760 DECL_PIOCTL(PGetTokens)
1762 register struct cell *tcell;
1763 register afs_int32 i;
1764 register struct unixuser *tu;
1769 AFS_STATCNT(PGetTokens);
1770 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1771 return EIO; /* Inappropriate ioctl for device */
1773 /* weird interface. If input parameter is present, it is an integer and
1774 * we're supposed to return the parm'th tokens for this unix uid.
1775 * If not present, we just return tokens for cell 1.
1776 * If counter out of bounds, return EDOM.
1777 * If no tokens for the particular cell, return ENOTCONN.
1778 * Also, if this mysterious parm is present, we return, along with the
1779 * tokens, the primary cell indicator (an afs_int32 0) and the cell name
1780 * at the end, in that order.
1782 if ((newStyle = (ainSize > 0))) {
1783 memcpy((char *)&iterator, ain, sizeof(afs_int32));
1785 i = UHash(areq->uid);
1786 ObtainReadLock(&afs_xuser);
1787 for (tu = afs_users[i]; tu; tu = tu->next) {
1789 if (tu->uid == areq->uid && (tu->states & UHasTokens)) {
1790 if (iterator-- == 0)
1791 break; /* are we done yet? */
1794 if (tu->uid == areq->uid && afs_IsPrimaryCellNum(tu->cell))
1800 * No need to hold a read lock on each user entry
1804 ReleaseReadLock(&afs_xuser);
1809 if (((tu->states & UHasTokens) == 0)
1810 || (tu->ct.EndTimestamp < osi_Time())) {
1811 tu->states |= (UTokensBad | UNeedsReset);
1812 afs_PutUser(tu, READ_LOCK);
1815 /* use iterator for temp */
1817 iterator = tu->stLen; /* for compat, we try to return 56 byte tix if they fit */
1819 iterator = 56; /* # of bytes we're returning */
1820 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1821 cp += sizeof(afs_int32);
1822 memcpy(cp, tu->stp, tu->stLen); /* copy out st */
1824 iterator = sizeof(struct ClearToken);
1825 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1826 cp += sizeof(afs_int32);
1827 memcpy(cp, (char *)&tu->ct, sizeof(struct ClearToken));
1828 cp += sizeof(struct ClearToken);
1830 /* put out primary id and cell name, too */
1831 iterator = (tu->states & UPrimary ? 1 : 0);
1832 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1833 cp += sizeof(afs_int32);
1834 tcell = afs_GetCell(tu->cell, READ_LOCK);
1836 strcpy(cp, tcell->cellName);
1837 cp += strlen(tcell->cellName) + 1;
1838 afs_PutCell(tcell, READ_LOCK);
1842 *aoutSize = cp - aout;
1843 afs_PutUser(tu, READ_LOCK);
1849 register afs_int32 i;
1850 register struct unixuser *tu;
1852 AFS_STATCNT(PUnlog);
1853 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1854 return EIO; /* Inappropriate ioctl for device */
1856 i = UHash(areq->uid);
1857 ObtainWriteLock(&afs_xuser, 227);
1858 for (tu = afs_users[i]; tu; tu = tu->next) {
1859 if (tu->uid == areq->uid) {
1861 tu->states &= ~UHasTokens;
1862 /* security is not having to say you're sorry */
1863 memset((char *)&tu->ct, 0, sizeof(struct ClearToken));
1865 ReleaseWriteLock(&afs_xuser);
1866 /* We have to drop the lock over the call to afs_ResetUserConns, since
1867 * it obtains the afs_xvcache lock. We could also keep the lock, and
1868 * modify ResetUserConns to take parm saying we obtained the lock
1869 * already, but that is overkill. By keeping the "tu" pointer
1870 * held over the released lock, we guarantee that we won't lose our
1871 * place, and that we'll pass over every user conn that existed when
1872 * we began this call.
1874 afs_ResetUserConns(tu);
1876 ObtainWriteLock(&afs_xuser, 228);
1878 /* set the expire times to 0, causes
1879 * afs_GCUserData to remove this entry
1881 tu->ct.EndTimestamp = 0;
1883 #endif /* UKERNEL */
1886 ReleaseWriteLock(&afs_xuser);
1890 DECL_PIOCTL(PMariner)
1892 afs_int32 newHostAddr;
1893 afs_int32 oldHostAddr;
1895 AFS_STATCNT(PMariner);
1897 memcpy((char *)&oldHostAddr, (char *)&afs_marinerHost,
1900 oldHostAddr = 0xffffffff; /* disabled */
1902 memcpy((char *)&newHostAddr, ain, sizeof(afs_int32));
1903 if (newHostAddr == 0xffffffff) {
1904 /* disable mariner operations */
1906 } else if (newHostAddr) {
1908 afs_marinerHost = newHostAddr;
1910 memcpy(aout, (char *)&oldHostAddr, sizeof(afs_int32));
1911 *aoutSize = sizeof(afs_int32);
1915 DECL_PIOCTL(PCheckServers)
1917 register char *cp = 0;
1919 register struct server *ts;
1920 afs_int32 temp, *lp = (afs_int32 *) ain, havecell = 0;
1922 struct chservinfo *pcheck;
1924 AFS_STATCNT(PCheckServers);
1926 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1927 return EIO; /* Inappropriate ioctl for device */
1929 if (*lp == 0x12345678) { /* For afs3.3 version */
1930 pcheck = (struct chservinfo *)ain;
1931 if (pcheck->tinterval >= 0) {
1933 memcpy(cp, (char *)&PROBE_INTERVAL, sizeof(afs_int32));
1934 *aoutSize = sizeof(afs_int32);
1935 if (pcheck->tinterval > 0) {
1936 if (!afs_osi_suser(*acred))
1938 PROBE_INTERVAL = pcheck->tinterval;
1944 temp = pcheck->tflags;
1945 cp = pcheck->tbuffer;
1946 } else { /* For pre afs3.3 versions */
1947 memcpy((char *)&temp, ain, sizeof(afs_int32));
1948 cp = ain + sizeof(afs_int32);
1949 if (ainSize > sizeof(afs_int32))
1954 * 1: fast check, don't contact servers.
1955 * 2: local cell only.
1958 /* have cell name, too */
1959 cellp = afs_GetCellByName(cp, READ_LOCK);
1964 if (!cellp && (temp & 2)) {
1965 /* use local cell */
1966 cellp = afs_GetPrimaryCell(READ_LOCK);
1968 if (!(temp & 1)) { /* if not fast, call server checker routine */
1969 afs_CheckServers(1, cellp); /* check down servers */
1970 afs_CheckServers(0, cellp); /* check up servers */
1972 /* now return the current down server list */
1974 ObtainReadLock(&afs_xserver);
1975 for (i = 0; i < NSERVERS; i++) {
1976 for (ts = afs_servers[i]; ts; ts = ts->next) {
1977 if (cellp && ts->cell != cellp)
1978 continue; /* cell spec'd and wrong */
1979 if ((ts->flags & SRVR_ISDOWN)
1980 && ts->addr->sa_portal != ts->cell->vlport) {
1981 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
1982 cp += sizeof(afs_int32);
1986 ReleaseReadLock(&afs_xserver);
1988 afs_PutCell(cellp, READ_LOCK);
1989 *aoutSize = cp - aout;
1993 DECL_PIOCTL(PCheckVolNames)
1995 AFS_STATCNT(PCheckVolNames);
1996 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1997 return EIO; /* Inappropriate ioctl for device */
1999 afs_CheckRootVolume();
2000 afs_CheckVolumeNames(AFS_VOLCHECK_FORCE | AFS_VOLCHECK_EXPIRED |
2001 AFS_VOLCHECK_BUSY | AFS_VOLCHECK_MTPTS);
2005 DECL_PIOCTL(PCheckAuth)
2010 struct unixuser *tu;
2013 AFS_STATCNT(PCheckAuth);
2014 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2015 return EIO; /* Inappropriate ioctl for device */
2018 tu = afs_GetUser(areq->uid, 1, READ_LOCK); /* check local cell authentication */
2022 /* we have a user */
2023 ObtainReadLock(&afs_xsrvAddr);
2024 ObtainReadLock(&afs_xconn);
2026 /* any tokens set? */
2027 if ((tu->states & UHasTokens) == 0)
2029 /* all connections in cell 1 working? */
2030 for (i = 0; i < NSERVERS; i++) {
2031 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2032 for (tc = sa->conns; tc; tc = tc->next) {
2033 if (tc->user == tu && (tu->states & UTokensBad))
2038 ReleaseReadLock(&afs_xsrvAddr);
2039 ReleaseReadLock(&afs_xconn);
2040 afs_PutUser(tu, READ_LOCK);
2042 memcpy(aout, (char *)&retValue, sizeof(afs_int32));
2043 *aoutSize = sizeof(afs_int32);
2048 Prefetch(char *apath, struct afs_ioctl *adata, int afollow,
2049 struct AFS_UCRED *acred)
2052 register afs_int32 code;
2053 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2059 AFS_STATCNT(Prefetch);
2062 tp = osi_AllocLargeSpace(1024);
2063 AFS_COPYINSTR(apath, tp, 1024, &bufferSize, code);
2065 osi_FreeLargeSpace(tp);
2068 if (afs_BBusy()) { /* do this as late as possible */
2069 osi_FreeLargeSpace(tp);
2070 return EWOULDBLOCK; /* pretty close */
2072 afs_BQueue(BOP_PATH, (struct vcache *)0, 0, 0, acred, (afs_size_t) 0,
2073 (afs_size_t) 0, tp);
2077 DECL_PIOCTL(PFindVolume)
2079 register struct volume *tvp;
2080 register struct server *ts;
2081 register afs_int32 i;
2084 AFS_STATCNT(PFindVolume);
2087 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
2090 for (i = 0; i < MAXHOSTS; i++) {
2091 ts = tvp->serverHost[i];
2094 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
2095 cp += sizeof(afs_int32);
2098 /* still room for terminating NULL, add it on */
2099 ainSize = 0; /* reuse vbl */
2100 memcpy(cp, (char *)&ainSize, sizeof(afs_int32));
2101 cp += sizeof(afs_int32);
2103 *aoutSize = cp - aout;
2104 afs_PutVolume(tvp, READ_LOCK);
2110 DECL_PIOCTL(PViceAccess)
2112 register afs_int32 code;
2115 AFS_STATCNT(PViceAccess);
2118 code = afs_VerifyVCache(avc, areq);
2121 memcpy((char *)&temp, ain, sizeof(afs_int32));
2122 code = afs_AccessOK(avc, temp, areq, CHECK_MODE_BITS);
2129 DECL_PIOCTL(PSetCacheSize)
2134 AFS_STATCNT(PSetCacheSize);
2135 if (!afs_osi_suser(*acred))
2137 /* too many things are setup initially in mem cache version */
2138 if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
2140 memcpy((char *)&newValue, ain, sizeof(afs_int32));
2142 afs_cacheBlocks = afs_stats_cmperf.cacheBlocksOrig;
2144 if (newValue < afs_min_cache)
2145 afs_cacheBlocks = afs_min_cache;
2147 afs_cacheBlocks = newValue;
2149 afs_stats_cmperf.cacheBlocksTotal = afs_cacheBlocks;
2150 afs_ComputeCacheParms(); /* recompute basic cache parameters */
2151 afs_MaybeWakeupTruncateDaemon();
2152 while (waitcnt++ < 100 && afs_cacheBlocks < afs_blocksUsed) {
2153 afs_osi_Wait(1000, 0, 0);
2154 afs_MaybeWakeupTruncateDaemon();
2159 #define MAXGCSTATS 16
2160 DECL_PIOCTL(PGetCacheSize)
2162 afs_int32 results[MAXGCSTATS];
2164 AFS_STATCNT(PGetCacheSize);
2165 memset((char *)results, 0, sizeof(results));
2166 results[0] = afs_cacheBlocks;
2167 results[1] = afs_blocksUsed;
2168 memcpy(aout, (char *)results, sizeof(results));
2169 *aoutSize = sizeof(results);
2173 DECL_PIOCTL(PRemoveCallBack)
2175 register struct conn *tc;
2176 register afs_int32 code = 0;
2177 struct AFSCallBack CallBacks_Array[1];
2178 struct AFSCBFids theFids;
2179 struct AFSCBs theCBs;
2182 AFS_STATCNT(PRemoveCallBack);
2185 if (avc->states & CRO)
2186 return 0; /* read-only-ness can't change */
2187 ObtainWriteLock(&avc->lock, 229);
2188 theFids.AFSCBFids_len = 1;
2189 theCBs.AFSCBs_len = 1;
2190 theFids.AFSCBFids_val = (struct AFSFid *)&avc->fid.Fid;
2191 theCBs.AFSCBs_val = CallBacks_Array;
2192 CallBacks_Array[0].CallBackType = CB_DROPPED;
2193 if (avc->callback) {
2195 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2197 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
2199 code = RXAFS_GiveUpCallBacks(tc->id, &theFids, &theCBs);
2203 /* don't set code on failure since we wouldn't use it */
2204 } while (afs_Analyze
2205 (tc, code, &avc->fid, areq,
2206 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK, NULL));
2208 ObtainWriteLock(&afs_xcbhash, 457);
2209 afs_DequeueCallback(avc);
2211 avc->states &= ~(CStatd | CUnique);
2212 ReleaseWriteLock(&afs_xcbhash);
2213 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
2214 osi_dnlc_purgedp(avc);
2216 ReleaseWriteLock(&avc->lock);
2220 DECL_PIOCTL(PNewCell)
2222 /* create a new cell */
2223 afs_int32 cellHosts[MAXCELLHOSTS], *lp, magic = 0;
2224 char *newcell = 0, *linkedcell = 0, *tp = ain;
2225 register afs_int32 code, linkedstate = 0, ls;
2226 u_short fsport = 0, vlport = 0;
2229 AFS_STATCNT(PNewCell);
2230 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2231 return EIO; /* Inappropriate ioctl for device */
2233 if (!afs_osi_suser(*acred))
2236 memcpy((char *)&magic, tp, sizeof(afs_int32));
2237 tp += sizeof(afs_int32);
2238 if (magic != 0x12345678)
2241 /* A 3.4 fs newcell command will pass an array of MAXCELLHOSTS
2242 * server addresses while the 3.5 fs newcell command passes
2243 * MAXHOSTS. To figure out which is which, check if the cellname
2246 newcell = tp + (MAXCELLHOSTS + 3) * sizeof(afs_int32);
2247 scount = ((newcell[0] != '\0') ? MAXCELLHOSTS : MAXHOSTS);
2249 /* MAXCELLHOSTS (=8) is less than MAXHOSTS (=13) */
2250 memcpy((char *)cellHosts, tp, MAXCELLHOSTS * sizeof(afs_int32));
2251 tp += (scount * sizeof(afs_int32));
2253 lp = (afs_int32 *) tp;
2257 fsport = 0; /* Privileged ports not allowed */
2259 vlport = 0; /* Privileged ports not allowed */
2260 tp += (3 * sizeof(afs_int32));
2262 if ((ls = *lp) & 1) {
2263 linkedcell = tp + strlen(newcell) + 1;
2264 linkedstate |= CLinkedCell;
2267 linkedstate |= CNoSUID; /* setuid is disabled by default for fs newcell */
2269 afs_NewCell(newcell, cellHosts, linkedstate, linkedcell, fsport,
2274 DECL_PIOCTL(PNewAlias)
2276 /* create a new cell alias */
2278 register afs_int32 code;
2279 char *realName, *aliasName;
2281 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2282 return EIO; /* Inappropriate ioctl for device */
2284 if (!afs_osi_suser(*acred))
2288 tp += strlen(aliasName) + 1;
2291 code = afs_NewCellAlias(aliasName, realName);
2296 DECL_PIOCTL(PListCells)
2298 afs_int32 whichCell;
2299 register struct cell *tcell = 0;
2300 register afs_int32 i;
2301 register char *cp, *tp = ain;
2303 AFS_STATCNT(PListCells);
2304 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2305 return EIO; /* Inappropriate ioctl for device */
2307 memcpy((char *)&whichCell, tp, sizeof(afs_int32));
2308 tp += sizeof(afs_int32);
2309 tcell = afs_GetCellByIndex(whichCell, READ_LOCK);
2312 memset(cp, 0, MAXCELLHOSTS * sizeof(afs_int32));
2313 for (i = 0; i < MAXCELLHOSTS; i++) {
2314 if (tcell->cellHosts[i] == 0)
2316 memcpy(cp, (char *)&tcell->cellHosts[i]->addr->sa_ip,
2318 cp += sizeof(afs_int32);
2320 cp = aout + MAXCELLHOSTS * sizeof(afs_int32);
2321 strcpy(cp, tcell->cellName);
2322 cp += strlen(tcell->cellName) + 1;
2323 *aoutSize = cp - aout;
2324 afs_PutCell(tcell, READ_LOCK);
2332 DECL_PIOCTL(PListAliases)
2334 afs_int32 whichAlias;
2335 register struct cell_alias *tcalias = 0;
2336 register char *cp, *tp = ain;
2338 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2339 return EIO; /* Inappropriate ioctl for device */
2340 if (ainSize < sizeof(afs_int32))
2343 memcpy((char *)&whichAlias, tp, sizeof(afs_int32));
2344 tp += sizeof(afs_int32);
2346 tcalias = afs_GetCellAlias(whichAlias);
2349 strcpy(cp, tcalias->alias);
2350 cp += strlen(tcalias->alias) + 1;
2351 strcpy(cp, tcalias->cell);
2352 cp += strlen(tcalias->cell) + 1;
2353 *aoutSize = cp - aout;
2354 afs_PutCellAlias(tcalias);
2362 DECL_PIOCTL(PRemoveMount)
2364 register afs_int32 code;
2366 struct sysname_info sysState;
2367 afs_size_t offset, len;
2368 register struct conn *tc;
2369 register struct dcache *tdc;
2370 register struct vcache *tvc;
2371 struct AFSFetchStatus OutDirStatus;
2372 struct VenusFid tfid;
2373 struct AFSVolSync tsync;
2377 /* "ain" is the name of the file in this dir to remove */
2379 AFS_STATCNT(PRemoveMount);
2382 code = afs_VerifyVCache(avc, areq);
2385 if (vType(avc) != VDIR)
2388 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1); /* test for error below */
2391 Check_AtSys(avc, ain, &sysState, areq);
2392 ObtainReadLock(&tdc->lock);
2394 code = afs_dir_Lookup(&tdc->f.inode, sysState.name, &tfid.Fid);
2395 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
2396 ReleaseReadLock(&tdc->lock);
2397 bufp = sysState.name;
2402 tfid.Cell = avc->fid.Cell;
2403 tfid.Fid.Volume = avc->fid.Fid.Volume;
2404 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
2405 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
2407 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
2414 if (tvc->mvstat != 1) {
2420 ObtainWriteLock(&tvc->lock, 230);
2421 code = afs_HandleLink(tvc, areq);
2423 if (tvc->linkData) {
2424 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
2429 ReleaseWriteLock(&tvc->lock);
2430 osi_dnlc_purgedp(tvc);
2436 ObtainWriteLock(&avc->lock, 231);
2437 osi_dnlc_remove(avc, bufp, tvc);
2439 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2441 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE);
2444 RXAFS_RemoveFile(tc->id, (struct AFSFid *)&avc->fid.Fid, bufp,
2445 &OutDirStatus, &tsync);
2450 } while (afs_Analyze
2451 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_REMOVEFILE,
2452 SHARED_LOCK, NULL));
2457 ReleaseWriteLock(&avc->lock);
2461 /* we have the thing in the cache */
2462 ObtainWriteLock(&tdc->lock, 661);
2463 if (afs_LocalHero(avc, tdc, &OutDirStatus, 1)) {
2464 /* we can do it locally */
2465 code = afs_dir_Delete(&tdc->f.inode, bufp);
2467 ZapDCE(tdc); /* surprise error -- invalid value */
2468 DZap(&tdc->f.inode);
2471 ReleaseWriteLock(&tdc->lock);
2472 afs_PutDCache(tdc); /* drop ref count */
2474 avc->states &= ~CUnique; /* For the dfs xlator */
2475 ReleaseWriteLock(&avc->lock);
2478 if (sysState.allocked)
2479 osi_FreeLargeSpace(bufp);
2483 DECL_PIOCTL(PVenusLogging)
2485 return EINVAL; /* OBSOLETE */
2488 DECL_PIOCTL(PGetCellStatus)
2490 register struct cell *tcell;
2493 AFS_STATCNT(PGetCellStatus);
2494 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2495 return EIO; /* Inappropriate ioctl for device */
2497 tcell = afs_GetCellByName(ain, READ_LOCK);
2500 temp = tcell->states;
2501 afs_PutCell(tcell, READ_LOCK);
2502 memcpy(aout, (char *)&temp, sizeof(afs_int32));
2503 *aoutSize = sizeof(afs_int32);
2507 DECL_PIOCTL(PSetCellStatus)
2509 register struct cell *tcell;
2512 if (!afs_osi_suser(*acred))
2514 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2515 return EIO; /* Inappropriate ioctl for device */
2517 tcell = afs_GetCellByName(ain + 2 * sizeof(afs_int32), WRITE_LOCK);
2520 memcpy((char *)&temp, ain, sizeof(afs_int32));
2522 tcell->states |= CNoSUID;
2524 tcell->states &= ~CNoSUID;
2525 afs_PutCell(tcell, WRITE_LOCK);
2529 DECL_PIOCTL(PFlushVolumeData)
2531 register afs_int32 i;
2532 register struct dcache *tdc;
2533 register struct vcache *tvc;
2534 register struct volume *tv;
2535 afs_int32 cell, volume;
2537 AFS_STATCNT(PFlushVolumeData);
2540 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2541 return EIO; /* Inappropriate ioctl for device */
2543 volume = avc->fid.Fid.Volume; /* who to zap */
2544 cell = avc->fid.Cell;
2547 * Clear stat'd flag from all vnodes from this volume; this will invalidate all
2548 * the vcaches associated with the volume.
2550 ObtainReadLock(&afs_xvcache);
2551 for (i = 0; i < VCSIZE; i++) {
2552 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2553 if (tvc->fid.Fid.Volume == volume && tvc->fid.Cell == cell) {
2554 #if defined(AFS_SGI_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
2555 VN_HOLD(AFSTOV(tvc));
2557 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2563 ReleaseReadLock(&afs_xvcache);
2564 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
2565 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
2567 ObtainWriteLock(&tvc->lock, 232);
2569 ObtainWriteLock(&afs_xcbhash, 458);
2570 afs_DequeueCallback(tvc);
2571 tvc->states &= ~(CStatd | CDirty);
2572 ReleaseWriteLock(&afs_xcbhash);
2573 if (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
2574 osi_dnlc_purgedp(tvc);
2575 afs_TryToSmush(tvc, *acred, 1);
2576 ReleaseWriteLock(&tvc->lock);
2577 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
2578 afs_BozonUnlock(&tvc->pvnLock, tvc);
2580 ObtainReadLock(&afs_xvcache);
2581 /* our tvc ptr is still good until now */
2586 ReleaseReadLock(&afs_xvcache);
2589 MObtainWriteLock(&afs_xdcache, 328); /* needed if you're going to flush any stuff */
2590 for (i = 0; i < afs_cacheFiles; i++) {
2591 if (!(afs_indexFlags[i] & IFEverUsed))
2592 continue; /* never had any data */
2593 tdc = afs_GetDSlot(i, NULL);
2594 if (tdc->refCount <= 1) { /* too high, in use by running sys call */
2595 ReleaseReadLock(&tdc->tlock);
2596 if (tdc->f.fid.Fid.Volume == volume && tdc->f.fid.Cell == cell) {
2597 if (!(afs_indexFlags[i] & IFDataMod)) {
2598 /* if the file is modified, but has a ref cnt of only 1, then
2599 * someone probably has the file open and is writing into it.
2600 * Better to skip flushing such a file, it will be brought back
2601 * immediately on the next write anyway.
2603 * If we *must* flush, then this code has to be rearranged to call
2604 * afs_storeAllSegments() first */
2605 afs_FlushDCache(tdc);
2609 ReleaseReadLock(&tdc->tlock);
2611 afs_PutDCache(tdc); /* bumped by getdslot */
2613 MReleaseWriteLock(&afs_xdcache);
2615 ObtainReadLock(&afs_xvolume);
2616 for (i = 0; i < NVOLS; i++) {
2617 for (tv = afs_volumes[i]; tv; tv = tv->next) {
2618 if (tv->volume == volume) {
2619 afs_ResetVolumeInfo(tv);
2624 ReleaseReadLock(&afs_xvolume);
2626 /* probably, a user is doing this, probably, because things are screwed up.
2627 * maybe it's the dnlc's fault? */
2634 DECL_PIOCTL(PGetVnodeXStatus)
2636 register afs_int32 code;
2637 struct vcxstat stat;
2640 /* AFS_STATCNT(PGetVnodeXStatus); */
2643 code = afs_VerifyVCache(avc, areq);
2646 if (vType(avc) == VDIR)
2647 mode = PRSFS_LOOKUP;
2650 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
2652 stat.fid = avc->fid;
2653 hset32(stat.DataVersion, hgetlo(avc->m.DataVersion));
2654 stat.lock = avc->lock;
2655 stat.parentVnode = avc->parentVnode;
2656 stat.parentUnique = avc->parentUnique;
2657 hset(stat.flushDV, avc->flushDV);
2658 hset(stat.mapDV, avc->mapDV);
2659 stat.truncPos = avc->truncPos;
2660 { /* just grab the first two - won't break anything... */
2661 struct axscache *ac;
2663 for (i = 0, ac = avc->Access; ac && i < CPSIZE; i++, ac = ac->next) {
2664 stat.randomUid[i] = ac->uid;
2665 stat.randomAccess[i] = ac->axess;
2668 stat.callback = afs_data_pointer_to_int32(avc->callback);
2669 stat.cbExpires = avc->cbExpires;
2670 stat.anyAccess = avc->anyAccess;
2671 stat.opens = avc->opens;
2672 stat.execsOrWriters = avc->execsOrWriters;
2673 stat.flockCount = avc->flockCount;
2674 stat.mvstat = avc->mvstat;
2675 stat.states = avc->states;
2676 memcpy(aout, (char *)&stat, sizeof(struct vcxstat));
2677 *aoutSize = sizeof(struct vcxstat);
2682 /* We require root for local sysname changes, but not for remote */
2683 /* (since we don't really believe remote uids anyway) */
2684 /* outname[] shouldn't really be needed- this is left as an excercise */
2685 /* for the reader. */
2686 DECL_PIOCTL(PSetSysName)
2688 char *cp, *cp2, inname[MAXSYSNAME], outname[MAXSYSNAME];
2689 int setsysname, foundname = 0;
2690 register struct afs_exporter *exporter;
2691 register struct unixuser *au;
2692 register afs_int32 pag, error;
2693 int t, count, num = 0;
2694 char **sysnamelist[MAXSYSNAME];
2696 AFS_STATCNT(PSetSysName);
2697 if (!afs_globalVFS) {
2698 /* Afsd is NOT running; disable it */
2699 #if defined(KERNEL_HAVE_UERROR)
2700 return (setuerror(EINVAL), EINVAL);
2705 memset(inname, 0, MAXSYSNAME);
2706 memcpy((char *)&setsysname, ain, sizeof(afs_int32));
2707 ain += sizeof(afs_int32);
2711 if (setsysname < 0 || setsysname > MAXNUMSYSNAMES)
2714 for (cp = ain, count = 0; count < setsysname; count++) {
2715 /* won't go past end of ain since maxsysname*num < ain length */
2717 if (t >= MAXSYSNAME || t <= 0)
2719 /* check for names that can shoot us in the foot */
2720 if (*cp == '.' && (cp[1] == 0 || (cp[1] == '.' && cp[2] == 0)))
2726 /* inname gets first entry in case we're being a translator */
2728 memcpy(inname, ain, t + 1); /* include terminating null */
2732 if ((*acred)->cr_gid == RMTUSER_REQ) { /* Handles all exporters */
2733 pag = PagInCred(*acred);
2735 return EINVAL; /* Better than panicing */
2737 if (!(au = afs_FindUser(pag, -1, READ_LOCK))) {
2738 return EINVAL; /* Better than panicing */
2740 if (!(exporter = au->exporter)) {
2741 afs_PutUser(au, READ_LOCK);
2742 return EINVAL; /* Better than panicing */
2744 error = EXP_SYSNAME(exporter, (setsysname ? cp2 : NULL), sysnamelist,
2747 if (error == ENODEV)
2748 foundname = 0; /* sysname not set yet! */
2750 afs_PutUser(au, READ_LOCK);
2755 strcpy(outname, (*sysnamelist)[0]);
2757 afs_PutUser(au, READ_LOCK);
2759 /* Not xlating, so local case */
2761 osi_Panic("PSetSysName: !afs_sysname\n");
2762 if (!setsysname) { /* user just wants the info */
2763 strcpy(outname, afs_sysname);
2764 foundname = afs_sysnamecount;
2765 *sysnamelist = afs_sysnamelist;
2766 } else { /* Local guy; only root can change sysname */
2767 if (!afs_osi_suser(*acred))
2770 /* clear @sys entries from the dnlc, once afs_lookup can
2771 * do lookups of @sys entries and thinks it can trust them */
2772 /* privs ok, store the entry, ... */
2773 strcpy(afs_sysname, inname);
2774 if (setsysname > 1) { /* ... or list */
2776 for (count = 1; count < setsysname; ++count) {
2777 if (!afs_sysnamelist[count])
2779 ("PSetSysName: no afs_sysnamelist entry to write\n");
2781 memcpy(afs_sysnamelist[count], cp, t + 1); /* include null */
2785 afs_sysnamecount = setsysname;
2789 cp = aout; /* not changing so report back the count and ... */
2790 memcpy(cp, (char *)&foundname, sizeof(afs_int32));
2791 cp += sizeof(afs_int32);
2793 strcpy(cp, outname); /* ... the entry, ... */
2794 cp += strlen(outname) + 1;
2795 for (count = 1; count < foundname; ++count) { /* ... or list. */
2796 if (!(*sysnamelist)[count])
2798 ("PSetSysName: no afs_sysnamelist entry to read\n");
2799 t = strlen((*sysnamelist)[count]);
2800 if (t >= MAXSYSNAME)
2801 osi_Panic("PSetSysName: sysname entry garbled\n");
2802 strcpy(cp, (*sysnamelist)[count]);
2806 *aoutSize = cp - aout;
2811 /* sequential search through the list of touched cells is not a good
2812 * long-term solution here. For small n, though, it should be just
2813 * fine. Should consider special-casing the local cell for large n.
2814 * Likewise for PSetSPrefs.
2816 * s - number of ids in array l[] -- NOT index of last id
2817 * l - array of cell ids which have volumes that need to be sorted
2818 * vlonly - sort vl servers or file servers?
2821 ReSortCells_cb(struct cell *cell, void *arg)
2823 afs_int32 *p = (afs_int32 *) arg;
2824 afs_int32 *l = p + 1;
2827 for (i = 0; i < s; i++) {
2828 if (l[i] == cell->cellNum) {
2829 ObtainWriteLock(&cell->lock, 690);
2830 afs_SortServers(cell->cellHosts, MAXCELLHOSTS);
2831 ReleaseWriteLock(&cell->lock);
2839 ReSortCells(int s, afs_int32 * l, int vlonly)
2847 p = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * (s + 1));
2849 memcpy(p + 1, l, s * sizeof(afs_int32));
2850 afs_TraverseCells(&ReSortCells_cb, p);
2851 afs_osi_Free(p, sizeof(afs_int32) * (s + 1));
2855 ObtainReadLock(&afs_xvolume);
2856 for (i = 0; i < NVOLS; i++) {
2857 for (j = afs_volumes[i]; j; j = j->next) {
2858 for (k = 0; k < s; k++)
2859 if (j->cell == l[k]) {
2860 ObtainWriteLock(&j->lock, 233);
2861 afs_SortServers(j->serverHost, MAXHOSTS);
2862 ReleaseWriteLock(&j->lock);
2867 ReleaseReadLock(&afs_xvolume);
2871 static int debugsetsp = 0;
2873 afs_setsprefs(sp, num, vlonly)
2876 unsigned int vlonly;
2879 int i, j, k, matches, touchedSize;
2880 struct server *srvr = NULL;
2881 afs_int32 touched[34];
2885 for (k = 0; k < num; sp++, k++) {
2887 printf("sp host=%x, rank=%d\n", sp->host.s_addr, sp->rank);
2890 ObtainReadLock(&afs_xserver);
2892 i = SHash(sp->host.s_addr);
2893 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2894 if (sa->sa_ip == sp->host.s_addr) {
2896 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
2897 || (sa->sa_portal == AFS_FSPORT);
2898 if ((!vlonly && isfs) || (vlonly && !isfs)) {
2905 if (sa && matches) { /* found one! */
2907 printf("sa ip=%x, ip_rank=%d\n", sa->sa_ip, sa->sa_iprank);
2909 sa->sa_iprank = sp->rank + afs_randomMod15();
2910 afs_SortOneServer(sa->server);
2913 /* if we don't know yet what cell it's in, this is moot */
2914 for (j = touchedSize - 1;
2915 j >= 0 && touched[j] != srvr->cell->cellNum; j--)
2916 /* is it in our list of touched cells ? */ ;
2917 if (j < 0) { /* no, it's not */
2918 touched[touchedSize++] = srvr->cell->cellNum;
2919 if (touchedSize >= 32) { /* watch for ovrflow */
2920 ReleaseReadLock(&afs_xserver);
2921 ReSortCells(touchedSize, touched, vlonly);
2923 ObtainReadLock(&afs_xserver);
2929 ReleaseReadLock(&afs_xserver);
2930 /* if we didn't find one, start to create one. */
2931 /* Note that it doesn't have a cell yet... */
2933 afs_uint32 temp = sp->host.s_addr;
2935 afs_GetServer(&temp, 1, 0, (vlonly ? AFS_VLPORT : AFS_FSPORT),
2936 WRITE_LOCK, (afsUUID *) 0, 0);
2937 srvr->addr->sa_iprank = sp->rank + afs_randomMod15();
2938 afs_PutServer(srvr, WRITE_LOCK);
2940 } /* for all cited preferences */
2942 ReSortCells(touchedSize, touched, vlonly);
2946 /* Note that this may only be performed by the local root user.
2948 DECL_PIOCTL(PSetSPrefs)
2950 struct setspref *ssp;
2951 AFS_STATCNT(PSetSPrefs);
2953 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2954 return EIO; /* Inappropriate ioctl for device */
2956 if (!afs_osi_suser(*acred))
2959 if (ainSize < sizeof(struct setspref))
2962 ssp = (struct setspref *)ain;
2963 if (ainSize < sizeof(struct spref) * ssp->num_servers)
2966 afs_setsprefs(&(ssp->servers[0]), ssp->num_servers,
2967 (ssp->flags & DBservers));
2971 DECL_PIOCTL(PSetSPrefs33)
2974 AFS_STATCNT(PSetSPrefs);
2975 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2976 return EIO; /* Inappropriate ioctl for device */
2979 if (!afs_osi_suser(*acred))
2982 sp = (struct spref *)ain;
2983 afs_setsprefs(sp, ainSize / (sizeof(struct spref)), 0 /*!vlonly */ );
2987 /* some notes on the following code...
2988 * in the hash table of server structs, all servers with the same IP address
2989 * will be on the same overflow chain.
2990 * This could be sped slightly in some circumstances by having it cache the
2991 * immediately previous slot in the hash table and some supporting information
2992 * Only reports file servers now.
2994 DECL_PIOCTL(PGetSPrefs)
2996 struct sprefrequest *spin; /* input */
2997 struct sprefinfo *spout; /* output */
2998 struct spref *srvout; /* one output component */
2999 int i, j; /* counters for hash table traversal */
3000 struct server *srvr; /* one of CM's server structs */
3002 int vlonly; /* just return vlservers ? */
3005 AFS_STATCNT(PGetSPrefs);
3006 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3007 return EIO; /* Inappropriate ioctl for device */
3010 if (ainSize < sizeof(struct sprefrequest_33)) {
3013 spin = ((struct sprefrequest *)ain);
3016 if (ainSize > sizeof(struct sprefrequest_33)) {
3017 vlonly = (spin->flags & DBservers);
3021 /* struct sprefinfo includes 1 server struct... that size gets added
3022 * in during the loop that follows.
3024 *aoutSize = sizeof(struct sprefinfo) - sizeof(struct spref);
3025 spout = (struct sprefinfo *)aout;
3026 spout->next_offset = spin->offset;
3027 spout->num_servers = 0;
3028 srvout = spout->servers;
3030 ObtainReadLock(&afs_xserver);
3031 for (i = 0, j = 0; j < NSERVERS; j++) { /* sift through hash table */
3032 for (sa = afs_srvAddrs[j]; sa; sa = sa->next_bkt, i++) {
3033 if (spin->offset > (unsigned short)i) {
3034 continue; /* catch up to where we left off */
3036 spout->next_offset++;
3039 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
3040 || (sa->sa_portal == AFS_FSPORT);
3042 if ((vlonly && isfs) || (!vlonly && !isfs)) {
3043 /* only report ranks for vl servers */
3047 srvout->host.s_addr = sa->sa_ip;
3048 srvout->rank = sa->sa_iprank;
3049 *aoutSize += sizeof(struct spref);
3050 spout->num_servers++;
3053 if (*aoutSize > (PIGGYSIZE - sizeof(struct spref))) {
3054 ReleaseReadLock(&afs_xserver); /* no more room! */
3059 ReleaseReadLock(&afs_xserver);
3061 spout->next_offset = 0; /* start over from the beginning next time */
3065 /* Enable/Disable the specified exporter. Must be root to disable an exporter */
3066 int afs_NFSRootOnly = 1;
3067 DECL_PIOCTL(PExportAfs)
3069 afs_int32 export, newint =
3070 0, type, changestate, handleValue, convmode, pwsync, smounts;
3071 register struct afs_exporter *exporter;
3073 AFS_STATCNT(PExportAfs);
3074 memcpy((char *)&handleValue, ain, sizeof(afs_int32));
3075 type = handleValue >> 24;
3080 exporter = exporter_find(type);
3082 export = handleValue & 3;
3083 changestate = handleValue & 0xff;
3084 smounts = (handleValue >> 2) & 3;
3085 pwsync = (handleValue >> 4) & 3;
3086 convmode = (handleValue >> 6) & 3;
3088 changestate = (handleValue >> 16) & 0x1;
3089 convmode = (handleValue >> 16) & 0x2;
3090 pwsync = (handleValue >> 16) & 0x4;
3091 smounts = (handleValue >> 16) & 0x8;
3092 export = handleValue & 0xff;
3095 /* Failed finding desired exporter; */
3099 handleValue = exporter->exp_states;
3100 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3101 *aoutSize = sizeof(afs_int32);
3103 if (!afs_osi_suser(*acred))
3104 return EACCES; /* Only superuser can do this */
3108 exporter->exp_states |= EXP_EXPORTED;
3110 exporter->exp_states &= ~EXP_EXPORTED;
3114 exporter->exp_states |= EXP_UNIXMODE;
3116 exporter->exp_states &= ~EXP_UNIXMODE;
3120 exporter->exp_states |= EXP_PWSYNC;
3122 exporter->exp_states &= ~EXP_PWSYNC;
3126 afs_NFSRootOnly = 0;
3127 exporter->exp_states |= EXP_SUBMOUNTS;
3129 afs_NFSRootOnly = 1;
3130 exporter->exp_states &= ~EXP_SUBMOUNTS;
3133 handleValue = exporter->exp_states;
3134 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3135 *aoutSize = sizeof(afs_int32);
3138 exporter->exp_states |= EXP_EXPORTED;
3140 exporter->exp_states &= ~EXP_EXPORTED;
3142 exporter->exp_states |= EXP_UNIXMODE;
3144 exporter->exp_states &= ~EXP_UNIXMODE;
3146 exporter->exp_states |= EXP_PWSYNC;
3148 exporter->exp_states &= ~EXP_PWSYNC;
3150 afs_NFSRootOnly = 0;
3151 exporter->exp_states |= EXP_SUBMOUNTS;
3153 afs_NFSRootOnly = 1;
3154 exporter->exp_states &= ~EXP_SUBMOUNTS;
3164 struct gaginfo *gagflags;
3166 if (!afs_osi_suser(*acred))
3169 gagflags = (struct gaginfo *)ain;
3170 afs_showflags = gagflags->showflags;
3176 DECL_PIOCTL(PTwiddleRx)
3178 struct rxparams *rxp;
3180 if (!afs_osi_suser(*acred))
3183 rxp = (struct rxparams *)ain;
3185 if (rxp->rx_initReceiveWindow)
3186 rx_initReceiveWindow = rxp->rx_initReceiveWindow;
3187 if (rxp->rx_maxReceiveWindow)
3188 rx_maxReceiveWindow = rxp->rx_maxReceiveWindow;
3189 if (rxp->rx_initSendWindow)
3190 rx_initSendWindow = rxp->rx_initSendWindow;
3191 if (rxp->rx_maxSendWindow)
3192 rx_maxSendWindow = rxp->rx_maxSendWindow;
3193 if (rxp->rxi_nSendFrags)
3194 rxi_nSendFrags = rxp->rxi_nSendFrags;
3195 if (rxp->rxi_nRecvFrags)
3196 rxi_nRecvFrags = rxp->rxi_nRecvFrags;
3197 if (rxp->rxi_OrphanFragSize)
3198 rxi_OrphanFragSize = rxp->rxi_OrphanFragSize;
3199 if (rxp->rx_maxReceiveSize) {
3200 rx_maxReceiveSize = rxp->rx_maxReceiveSize;
3201 rx_maxReceiveSizeUser = rxp->rx_maxReceiveSize;
3203 if (rxp->rx_MyMaxSendSize)
3204 rx_MyMaxSendSize = rxp->rx_MyMaxSendSize;
3209 DECL_PIOCTL(PGetInitParams)
3211 if (sizeof(struct cm_initparams) > PIGGYSIZE)
3214 memcpy(aout, (char *)&cm_initParams, sizeof(struct cm_initparams));
3215 *aoutSize = sizeof(struct cm_initparams);
3219 #ifdef AFS_SGI65_ENV
3220 /* They took crget() from us, so fake it. */
3225 cr = crdup(get_current_cred());
3226 memset((char *)cr, 0, sizeof(cred_t));
3227 #if CELL || CELL_PREPARE
3234 DECL_PIOCTL(PGetRxkcrypt)
3236 memcpy(aout, (char *)&cryptall, sizeof(afs_int32));
3237 *aoutSize = sizeof(afs_int32);
3241 DECL_PIOCTL(PSetRxkcrypt)
3245 if (!afs_osi_suser(*acred))
3247 if (ainSize != sizeof(afs_int32) || ain == NULL)
3249 memcpy((char *)&tmpval, ain, sizeof(afs_int32));
3250 /* if new mappings added later this will need to be changed */
3251 if (tmpval != 0 && tmpval != 1)
3257 #ifdef AFS_NEED_CLIENTCONTEXT
3259 * Create new credentials to correspond to a remote user with given
3260 * <hostaddr, uid, g0, g1>. This allows a server running as root to
3261 * provide pioctl (and other) services to foreign clients (i.e. nfs
3262 * clients) by using this call to `become' the client.
3265 #define PIOCTL_HEADER 6
3267 HandleClientContext(struct afs_ioctl *ablob, int *com,
3268 struct AFS_UCRED **acred, struct AFS_UCRED *credp)
3271 afs_uint32 hostaddr;
3272 afs_int32 uid, g0, g1, i, code, pag, exporter_type;
3273 struct afs_exporter *exporter, *outexporter;
3274 struct AFS_UCRED *newcred;
3275 struct unixuser *au;
3277 #if defined(AFS_SGIMP_ENV)
3278 osi_Assert(ISAFS_GLOCK());
3280 AFS_STATCNT(HandleClientContext);
3281 if (ablob->in_size < PIOCTL_HEADER * sizeof(afs_int32)) {
3282 /* Must at least include the PIOCTL_HEADER header words required by the protocol */
3283 return EINVAL; /* Too small to be good */
3285 ain = inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
3286 AFS_COPYIN(ablob->in, ain, PIOCTL_HEADER * sizeof(afs_int32), code);
3288 osi_FreeLargeSpace(inData);
3292 /* Extract information for remote user */
3293 hostaddr = *((afs_uint32 *) ain);
3294 ain += sizeof(hostaddr);
3295 uid = *((afs_uint32 *) ain);
3297 g0 = *((afs_uint32 *) ain);
3299 g1 = *((afs_uint32 *) ain);
3301 *com = *((afs_uint32 *) ain);
3302 ain += sizeof(afs_int32);
3303 exporter_type = *((afs_uint32 *) ain); /* In case we support more than NFS */
3306 * Of course, one must be root for most of these functions, but
3307 * we'll allow (for knfs) you to set things if the pag is 0 and
3308 * you're setting tokens or unlogging.
3311 if (!afs_osi_suser(credp)) {
3312 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
3313 /* Since SGI's suser() returns explicit failure after the call.. */
3316 /* check for acceptable opcodes for normal folks, which are, so far,
3317 * set tokens and unlog.
3319 if (i != 9 && i != 3 && i != 38 && i != 8) {
3320 osi_FreeLargeSpace(inData);
3325 ablob->in_size -= PIOCTL_HEADER * sizeof(afs_int32);
3326 ablob->in += PIOCTL_HEADER * sizeof(afs_int32);
3327 osi_FreeLargeSpace(inData);
3330 * We map uid 0 to nobody to match the mapping that the nfs
3331 * server does and to ensure that the suser() calls in the afs
3332 * code fails for remote client roots.
3334 uid = afs_nobody; /* NFS_NOBODY == -2 */
3337 #ifdef AFS_AIX41_ENV
3340 newcred->cr_gid = RMTUSER_REQ;
3341 #ifdef AFS_AIX51_ENV
3342 newcred->cr_groupset.gs_union.un_groups[0] = g0;
3343 newcred->cr_groupset.gs_union.un_groups[1] = g1;
3345 newcred->cr_groups[0] = g0;
3346 newcred->cr_groups[1] = g1;
3349 newcred->cr_ngrps = 2;
3351 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV)
3352 newcred->cr_ngroups = 2;
3354 for (i = 2; i < NGROUPS; i++)
3355 newcred->cr_groups[i] = NOGROUP;
3358 #if !defined(AFS_OSF_ENV) && !defined(AFS_DEC_ENV)
3359 afs_nfsclient_init(); /* before looking for exporter, ensure one exists */
3361 if (!(exporter = exporter_find(exporter_type))) {
3362 /* Exporter wasn't initialized or an invalid exporter type */
3366 if (exporter->exp_states & EXP_PWSYNC) {
3367 if (uid != credp->cr_uid) {
3369 return ENOEXEC; /* XXX Find a better errno XXX */
3372 newcred->cr_uid = uid; /* Only temporary */
3373 code = EXP_REQHANDLER(exporter, &newcred, hostaddr, &pag, &outexporter);
3374 /* The client's pag is the only unique identifier for it */
3375 newcred->cr_uid = pag;
3377 if (!code && *com == PSETPAG) {
3378 /* Special case for 'setpag' */
3379 afs_uint32 pagvalue = genpag();
3381 au = afs_GetUser(pagvalue, -1, WRITE_LOCK); /* a new unixuser struct */
3383 * Note that we leave the 'outexporter' struct held so it won't
3386 au->exporter = outexporter;
3387 if (ablob->out_size >= 4) {
3388 AFS_COPYOUT((char *)&pagvalue, ablob->out, sizeof(afs_int32),
3391 afs_PutUser(au, WRITE_LOCK);
3394 return PSETPAG; /* Special return for setpag */
3396 EXP_RELE(outexporter);
3400 #endif /* AFS_NEED_CLIENTCONTEXT */
3402 /* get all interface addresses of this client */
3404 DECL_PIOCTL(PGetCPrefs)
3406 struct sprefrequest *spin; /* input */
3407 struct sprefinfo *spout; /* output */
3408 struct spref *srvout; /* one output component */
3412 AFS_STATCNT(PGetCPrefs);
3413 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3414 return EIO; /* Inappropriate ioctl for device */
3416 if (ainSize < sizeof(struct sprefrequest))
3419 spin = (struct sprefrequest *)ain;
3420 spout = (struct sprefinfo *)aout;
3422 maxNumber = spin->num_servers; /* max addrs this time */
3423 srvout = spout->servers;
3425 ObtainReadLock(&afs_xinterface);
3427 /* copy out the client interface information from the
3428 ** kernel data structure "interface" to the output buffer
3430 for (i = spin->offset, j = 0; (i < afs_cb_interface.numberOfInterfaces)
3431 && (j < maxNumber); i++, j++, srvout++)
3432 srvout->host.s_addr = afs_cb_interface.addr_in[i];
3434 spout->num_servers = j;
3435 *aoutSize = sizeof(struct sprefinfo) + (j - 1) * sizeof(struct spref);
3437 if (i >= afs_cb_interface.numberOfInterfaces)
3438 spout->next_offset = 0; /* start from beginning again */
3440 spout->next_offset = spin->offset + j;
3442 ReleaseReadLock(&afs_xinterface);
3446 DECL_PIOCTL(PSetCPrefs)
3448 struct setspref *sin;
3451 AFS_STATCNT(PSetCPrefs);
3452 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3453 return EIO; /* Inappropriate ioctl for device */
3455 sin = (struct setspref *)ain;
3457 if (ainSize < sizeof(struct setspref))
3459 #if 0 /* num_servers is unsigned */
3460 if (sin->num_servers < 0)
3463 if (sin->num_servers > AFS_MAX_INTERFACE_ADDR)
3466 ObtainWriteLock(&afs_xinterface, 412);
3467 afs_cb_interface.numberOfInterfaces = sin->num_servers;
3468 for (i = 0; (unsigned short)i < sin->num_servers; i++)
3469 afs_cb_interface.addr_in[i] = sin->servers[i].host.s_addr;
3471 ReleaseWriteLock(&afs_xinterface);
3475 DECL_PIOCTL(PFlushMount)
3477 register afs_int32 code;
3478 register struct vcache *tvc;
3479 register struct dcache *tdc;
3480 struct VenusFid tfid;
3482 struct sysname_info sysState;
3483 afs_size_t offset, len;
3485 AFS_STATCNT(PFlushMount);
3488 code = afs_VerifyVCache(avc, areq);
3491 if (vType(avc) != VDIR) {
3494 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
3497 Check_AtSys(avc, ain, &sysState, areq);
3498 ObtainReadLock(&tdc->lock);
3500 code = afs_dir_Lookup(&tdc->f.inode, sysState.name, &tfid.Fid);
3501 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
3502 ReleaseReadLock(&tdc->lock);
3503 afs_PutDCache(tdc); /* we're done with the data */
3504 bufp = sysState.name;
3508 tfid.Cell = avc->fid.Cell;
3509 tfid.Fid.Volume = avc->fid.Fid.Volume;
3510 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
3511 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
3513 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3519 if (tvc->mvstat != 1) {
3524 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
3525 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
3527 ObtainWriteLock(&tvc->lock, 649);
3528 ObtainWriteLock(&afs_xcbhash, 650);
3529 afs_DequeueCallback(tvc);
3530 tvc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
3531 ReleaseWriteLock(&afs_xcbhash);
3532 /* now find the disk cache entries */
3533 afs_TryToSmush(tvc, *acred, 1);
3534 osi_dnlc_purgedp(tvc);
3535 afs_symhint_inval(tvc);
3536 if (tvc->linkData && !(tvc->states & CCore)) {
3537 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
3538 tvc->linkData = NULL;
3540 ReleaseWriteLock(&tvc->lock);
3541 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
3542 afs_BozonUnlock(&tvc->pvnLock, tvc);
3546 if (sysState.allocked)
3547 osi_FreeLargeSpace(bufp);
3551 DECL_PIOCTL(PRxStatProc)
3556 if (!afs_osi_suser(*acred)) {
3560 if (ainSize != sizeof(afs_int32)) {
3564 memcpy((char *)&flags, ain, sizeof(afs_int32));
3565 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3569 if (flags & AFSCALL_RXSTATS_ENABLE) {
3570 rx_enableProcessRPCStats();
3572 if (flags & AFSCALL_RXSTATS_DISABLE) {
3573 rx_disableProcessRPCStats();
3575 if (flags & AFSCALL_RXSTATS_CLEAR) {
3576 rx_clearProcessRPCStats(AFS_RX_STATS_CLEAR_ALL);
3584 DECL_PIOCTL(PRxStatPeer)
3589 if (!afs_osi_suser(*acred)) {
3593 if (ainSize != sizeof(afs_int32)) {
3597 memcpy((char *)&flags, ain, sizeof(afs_int32));
3598 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3602 if (flags & AFSCALL_RXSTATS_ENABLE) {
3603 rx_enablePeerRPCStats();
3605 if (flags & AFSCALL_RXSTATS_DISABLE) {
3606 rx_disablePeerRPCStats();
3608 if (flags & AFSCALL_RXSTATS_CLEAR) {
3609 rx_clearPeerRPCStats(AFS_RX_STATS_CLEAR_ALL);
3616 DECL_PIOCTL(PPrefetchFromTape)
3618 register afs_int32 code, code1;
3621 struct rx_call *tcall;
3622 struct AFSVolSync tsync;
3623 struct AFSFetchStatus OutStatus;
3624 struct AFSCallBack CallBack;
3625 struct VenusFid tfid;
3629 AFS_STATCNT(PSetAcl);
3633 if (ain && (ainSize == 3 * sizeof(afs_int32)))
3634 Fid = (struct AFSFid *)ain;
3636 Fid = &avc->fid.Fid;
3637 tfid.Cell = avc->fid.Cell;
3638 tfid.Fid.Volume = Fid->Volume;
3639 tfid.Fid.Vnode = Fid->Vnode;
3640 tfid.Fid.Unique = Fid->Unique;
3642 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3644 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3645 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &avc->fid);
3648 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3649 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &tvc->fid);
3652 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3656 tcall = rx_NewCall(tc->id);
3658 StartRXAFS_FetchData(tcall, (struct AFSFid *)&tvc->fid.Fid, 0,
3661 bytes = rx_Read(tcall, (char *)aout, sizeof(afs_int32));
3663 EndRXAFS_FetchData(tcall, &OutStatus, &CallBack, &tsync);
3665 code1 = rx_EndCall(tcall, code);
3669 } while (afs_Analyze
3670 (tc, code, &tvc->fid, areq, AFS_STATS_FS_RPCIDX_RESIDENCYRPCS,
3671 SHARED_LOCK, NULL));
3672 /* This call is done only to have the callback things handled correctly */
3673 afs_FetchStatus(tvc, &tfid, areq, &OutStatus);
3677 *aoutSize = sizeof(afs_int32);
3682 DECL_PIOCTL(PResidencyCmd)
3684 register afs_int32 code;
3687 struct ResidencyCmdInputs *Inputs;
3688 struct ResidencyCmdOutputs *Outputs;
3689 struct VenusFid tfid;
3692 Inputs = (struct ResidencyCmdInputs *)ain;
3693 Outputs = (struct ResidencyCmdOutputs *)aout;
3696 if (!ain || ainSize != sizeof(struct ResidencyCmdInputs))
3701 Fid = &avc->fid.Fid;
3703 tfid.Cell = avc->fid.Cell;
3704 tfid.Fid.Volume = Fid->Volume;
3705 tfid.Fid.Vnode = Fid->Vnode;
3706 tfid.Fid.Unique = Fid->Unique;
3708 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3709 afs_Trace3(afs_iclSetp, CM_TRACE_RESIDCMD, ICL_TYPE_POINTER, tvc,
3710 ICL_TYPE_INT32, Inputs->command, ICL_TYPE_FID, &tfid);
3714 if (Inputs->command) {
3716 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3720 RXAFS_ResidencyCmd(tc->id, Fid, Inputs,
3721 (struct ResidencyCmdOutputs *)aout);
3725 } while (afs_Analyze
3726 (tc, code, &tvc->fid, areq,
3727 AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK, NULL));
3728 /* This call is done to have the callback things handled correctly */
3729 afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3730 } else { /* just a status request, return also link data */
3732 Outputs->code = afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3733 Outputs->chars[0] = 0;
3734 if (vType(tvc) == VLNK) {
3735 ObtainWriteLock(&tvc->lock, 555);
3736 if (afs_HandleLink(tvc, areq) == 0)
3737 strncpy((char *)&Outputs->chars, tvc->linkData, MAXCMDCHARS);
3738 ReleaseWriteLock(&tvc->lock);
3745 *aoutSize = sizeof(struct ResidencyCmdOutputs);
3750 DECL_PIOCTL(PCallBackAddr)
3753 afs_uint32 addr, code;
3759 struct unixuser *tu;
3760 struct srvAddr **addrs;
3761 extern int afs_HaveCallBacksFrom(struct server *aserver);
3763 /*AFS_STATCNT(PCallBackAddr);*/
3764 if ( !afs_resourceinit_flag ) /* afs deamons havn't started yet */
3765 return EIO; /* Inappropriate ioctl for device */
3767 if (!afs_osi_suser(acred))
3770 if ( ainSize < sizeof(afs_int32) )
3773 memcpy(&addr, ain, sizeof(afs_int32));
3775 ObtainReadLock(&afs_xinterface);
3776 for ( i=0; (unsigned short)i < afs_cb_interface.numberOfInterfaces; i++) {
3777 if (afs_cb_interface.addr_in[i] == addr) break;
3780 ReleaseWriteLock(&afs_xinterface);
3782 if (afs_cb_interface.addr_in[i] != addr)
3785 ObtainReadLock(&afs_xserver); /* Necessary? */
3786 ObtainReadLock(&afs_xsrvAddr);
3789 for (i=0;i<NSERVERS;i++) {
3790 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3795 addrs = afs_osi_Alloc(srvAddrCount * sizeof(*addrs));
3797 for (i=0;i<NSERVERS;i++) {
3798 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3799 if (j >= srvAddrCount) break;
3804 ReleaseReadLock(&afs_xsrvAddr);
3805 ReleaseReadLock(&afs_xserver);
3807 for (i=0; i<j; i++) {
3813 /* vlserver has no callback conn */
3814 if (sa->sa_portal == AFS_VLPORT) {
3818 if (!ts->cell) /* not really an active server, anyway, it must */
3819 continue; /* have just been added by setsprefs */
3821 /* get a connection, even if host is down; bumps conn ref count */
3822 tu = afs_GetUser(areq->uid, ts->cell->cellNum, SHARED_LOCK);
3823 tc = afs_ConnBySA(sa, ts->cell->fsport, ts->cell->cellNum, tu,
3824 1/*force*/, 1/*create*/, SHARED_LOCK);
3825 afs_PutUser(tu, SHARED_LOCK);
3829 if ((sa->sa_flags & SRVADDR_ISDOWN) || afs_HaveCallBacksFrom(ts)) {
3830 if (sa->sa_flags & SRVADDR_ISDOWN) {
3831 rx_SetConnDeadTime(tc->id, 3);
3834 #ifdef RX_ENABLE_LOCKS
3836 #endif /* RX_ENABLE_LOCKS */
3837 code = RXAFS_CallBackRxConnAddr(tc->id, &addr);
3838 #ifdef RX_ENABLE_LOCKS
3840 #endif /* RX_ENABLE_LOCKS */
3842 afs_PutConn(tc, SHARED_LOCK); /* done with it now */
3843 } /* Outer loop over addrs */
3844 #endif /* UKERNEL */