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 #ifdef AFS_PPC64_LINUX26_ENV
272 if (current->thread_info->flags & _TIF_32BIT)
274 if (current->thread.flags & PPC_FLAG_32BIT)
276 #elif defined(AFS_S390X_LINUX20_ENV)
277 if (current->thread.flags & S390_FLAG_31BIT)
279 #error Not done for this linux type
282 AFS_COPYIN(cmarg, (caddr_t) & dst32, sizeof dst32, code);
284 afs_ioctl32_to_afs_ioctl(&dst32, dst);
287 #endif /* defined(AFS_LINUX_64BIT_KERNEL) */
289 AFS_COPYIN(cmarg, (caddr_t) dst, sizeof *dst, code);
294 HandleIoctl(register struct vcache *avc, register afs_int32 acom,
295 struct afs_ioctl *adata)
297 register afs_int32 code;
300 AFS_STATCNT(HandleIoctl);
302 switch (acom & 0xff) {
304 avc->states |= CSafeStore;
308 /* case 2 used to be abort store, but this is no longer provided,
309 * since it is impossible to implement under normal Unix.
313 /* return the name of the cell this file is open on */
314 register struct cell *tcell;
315 register afs_int32 i;
317 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
319 i = strlen(tcell->cellName) + 1; /* bytes to copy out */
321 if (i > adata->out_size) {
322 /* 0 means we're not interested in the output */
323 if (adata->out_size != 0)
327 AFS_COPYOUT(tcell->cellName, adata->out, i, code);
329 afs_PutCell(tcell, READ_LOCK);
335 case 49: /* VIOC_GETINITPARAMS */
336 if (adata->out_size < sizeof(struct cm_initparams)) {
339 AFS_COPYOUT(&cm_initParams, adata->out,
340 sizeof(struct cm_initparams), code);
352 return code; /* so far, none implemented */
357 /* For aix we don't temporarily bypass ioctl(2) but rather do our
358 * thing directly in the vnode layer call, VNOP_IOCTL; thus afs_ioctl
359 * is now called from afs_gn_ioctl.
362 afs_ioctl(struct vcache *tvc, int cmd, int arg)
364 struct afs_ioctl data;
367 AFS_STATCNT(afs_ioctl);
368 if (((cmd >> 8) & 0xff) == 'V') {
369 /* This is a VICEIOCTL call */
370 AFS_COPYIN(arg, (caddr_t) & data, sizeof(data), error);
373 error = HandleIoctl(tvc, cmd, &data);
376 /* No-op call; just return. */
380 #endif /* AFS_AIX_ENV */
382 #if defined(AFS_SGI_ENV)
383 afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
386 , struct vopbd * vbds
390 struct afs_ioctl data;
396 AFS_STATCNT(afs_ioctl);
397 if (((cmd >> 8) & 0xff) == 'V') {
398 /* This is a VICEIOCTL call */
399 error = copyin_afs_ioctl(arg, &data);
402 locked = ISAFS_GLOCK();
405 error = HandleIoctl(tvc, cmd, &data);
410 /* No-op call; just return. */
414 #endif /* AFS_SGI_ENV */
416 /* unlike most calls here, this one uses u.u_error to return error conditions,
417 since this is really an intercepted chapter 2 call, rather than a vnode
420 /* AFS_HPUX102 and up uses VNODE ioctl instead */
421 #ifndef AFS_HPUX102_ENV
422 #if !defined(AFS_SGI_ENV)
426 kioctl(fdes, com, arg, ext, arg2, arg3)
427 #else /* __64BIT__ */
428 kioctl32(fdes, com, arg, ext, arg2, arg3)
429 #endif /* __64BIT__ */
432 kioctl(fdes, com, arg, ext)
443 } u_uap, *uap = &u_uap;
445 #if defined(AFS_SUN5_ENV)
447 struct afs_ioctl_sys {
454 struct afs_ioctl_sys *uap;
457 #elif defined(AFS_OSF_ENV)
458 afs_xioctl(p, args, retval)
467 } *uap = (struct a *)args;
468 #elif defined(AFS_FBSD50_ENV)
471 afs_xioctl(td, uap, retval)
473 register struct ioctl_args *uap;
476 struct proc *p = td->td_proc;
477 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
485 afs_xioctl(p, uap, retval)
487 register struct ioctl_args *uap;
490 #elif defined(AFS_LINUX22_ENV)
491 struct afs_ioctl_sys {
496 afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
499 struct afs_ioctl_sys ua, *uap = &ua;
508 } *uap = (struct a *)u.u_ap;
509 #endif /* AFS_SUN5_ENV */
511 #if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
513 #elif !defined(AFS_LINUX22_ENV)
514 register struct file *fd;
516 #if defined(AFS_XBSD_ENV)
517 register struct filedesc *fdp;
519 register struct vcache *tvc;
520 register int ioctlDone = 0, code = 0;
522 AFS_STATCNT(afs_xioctl);
523 #if defined(AFS_XBSD_ENV)
525 if ((u_int) uap->fd >= fdp->fd_nfiles
526 || (fd = fdp->fd_ofiles[uap->fd]) == NULL)
528 if ((fd->f_flag & (FREAD | FWRITE)) == 0)
530 #elif defined(AFS_DARWIN_ENV)
531 if ((code = fdgetf(p, uap->fd, &fd)))
533 #elif defined(AFS_LINUX22_ENV)
536 #elif defined(AFS_AIX32_ENV)
544 if (setuerror(getf(uap->fd, &fd))) {
547 #elif defined(AFS_OSF_ENV)
549 if (code = getf(&fd, uap->fd, FILE_FLAGS_NULL, &u.u_file_state))
551 #elif defined(AFS_SUN5_ENV)
552 # if defined(AFS_SUN57_ENV)
556 # elif defined(AFS_SUN54_ENV)
561 if (code = getf(uap->fd, &fd)) {
564 # endif /* AFS_SUN57_ENV */
570 /* first determine whether this is any sort of vnode */
571 #if defined(AFS_LINUX22_ENV)
576 if (fd->f_vnode->v_type == VREG || fd->f_vnode->v_type == VDIR) {
578 if (fd->f_type == DTYPE_VNODE) {
580 /* good, this is a vnode; next see if it is an AFS vnode */
581 #if defined(AFS_AIX32_ENV) || defined(AFS_SUN5_ENV)
582 tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */
583 #elif defined(AFS_OBSD_ENV)
585 IsAfsVnode((struct vnode *)fd->
586 f_data) ? VTOAFS((struct vnode *)fd->f_data) : NULL;
588 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
590 #endif /* AFS_LINUX22_ENV */
591 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
593 tvc = VTOAFS(afs_gntovn((struct gnode *)tvc));
594 if (!tvc) { /* shouldn't happen with held gnodes */
599 /* This is an AFS vnode */
600 if (((uap->com >> 8) & 0xff) == 'V') {
601 register struct afs_ioctl *datap;
604 (struct afs_ioctl *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
605 AFS_COPYIN((char *)uap->arg, (caddr_t) datap,
606 sizeof(struct afs_ioctl), code);
608 osi_FreeSmallSpace(datap);
610 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
613 #if defined(AFS_SUN5_ENV)
628 #else /* AFS_OSF_ENV */
632 #ifdef AFS_LINUX22_ENV
642 code = HandleIoctl(tvc, uap->com, datap);
643 osi_FreeSmallSpace(datap);
657 #if defined(AFS_LINUX22_ENV)
669 code = okioctl(fdes, com, arg, ext, arg2, arg3);
670 #else /* __64BIT__ */
671 code = okioctl32(fdes, com, arg, ext, arg2, arg3);
672 #endif /* __64BIT__ */
673 #else /* !AFS_AIX51_ENV */
674 code = okioctl(fdes, com, arg, ext);
675 #endif /* AFS_AIX51_ENV */
677 #else /* !AFS_AIX41_ENV */
679 okioctl(fdes, com, arg, ext);
680 #elif defined(AFS_SUN5_ENV)
681 #if defined(AFS_SUN57_ENV)
683 #elif defined(AFS_SUN54_ENV)
688 code = ioctl(uap, rvp);
689 #elif defined(AFS_FBSD50_ENV)
690 return ioctl(td, uap);
691 #elif defined(AFS_FBSD_ENV)
692 return ioctl(p, uap);
693 #elif defined(AFS_OBSD_ENV)
694 code = sys_ioctl(p, uap, retval);
695 #elif defined(AFS_DARWIN_ENV)
696 return ioctl(p, uap, retval);
697 #elif defined(AFS_OSF_ENV)
698 code = ioctl(p, args, retval);
705 #elif !defined(AFS_LINUX22_ENV)
719 #ifdef AFS_LINUX22_ENV
722 #if defined(KERNEL_HAVE_UERROR)
725 #if defined(AFS_AIX32_ENV) && !defined(AFS_AIX41_ENV)
726 return (getuerror()? -1 : u.u_ioctlrv);
728 return getuerror()? -1 : 0;
731 #endif /* AFS_LINUX22_ENV */
732 #endif /* AFS_SUN5_ENV */
733 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
737 #endif /* AFS_SGI_ENV */
738 #endif /* AFS_HPUX102_ENV */
740 #if defined(AFS_SGI_ENV)
741 /* "pioctl" system call entry point; just pass argument to the parameterized
750 afs_pioctl(struct pioctlargs *uap, rval_t * rvp)
754 AFS_STATCNT(afs_pioctl);
756 code = afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow);
765 #elif defined(AFS_OSF_ENV)
766 afs_pioctl(p, args, retval)
776 } *uap = (struct a *)args;
778 AFS_STATCNT(afs_pioctl);
779 return (afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow));
782 #elif defined(AFS_FBSD50_ENV)
784 afs_pioctl(td, args, retval)
794 } *uap = (struct a *)args;
796 AFS_STATCNT(afs_pioctl);
797 return (afs_syscall_pioctl
798 (uap->path, uap->cmd, uap->cmarg, uap->follow, td->td_ucred));
801 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
803 afs_pioctl(p, args, retval)
813 } *uap = (struct a *)args;
815 AFS_STATCNT(afs_pioctl);
816 return (afs_syscall_pioctl
817 (uap->path, uap->cmd, uap->cmarg, uap->follow,
818 p->p_cred->pc_ucred));
823 /* macro to avoid adding any more #ifdef's to pioctl code. */
824 #if defined(AFS_LINUX22_ENV) || defined(AFS_AIX41_ENV)
825 #define PIOCTL_FREE_CRED() crfree(credp)
827 #define PIOCTL_FREE_CRED()
832 afs_syscall_pioctl(path, com, cmarg, follow, rvp, credp)
834 struct AFS_UCRED *credp;
836 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
837 afs_syscall_pioctl(path, com, cmarg, follow, credp)
838 struct AFS_UCRED *credp;
840 afs_syscall_pioctl(path, com, cmarg, follow)
848 struct afs_ioctl data;
849 struct AFS_UCRED *tmpcred, *foreigncreds = NULL;
850 register afs_int32 code = 0;
856 struct ucred *credp = crref(); /* don't free until done! */
858 #ifdef AFS_LINUX22_ENV
859 cred_t *credp = crref(); /* don't free until done! */
863 AFS_STATCNT(afs_syscall_pioctl);
865 follow = 1; /* compat. with old venus */
866 code = copyin_afs_ioctl(cmarg, &data);
869 #if defined(KERNEL_HAVE_UERROR)
874 if ((com & 0xff) == PSetClientContext) {
875 #ifdef AFS_NEED_CLIENTCONTEXT
876 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV)
877 code = HandleClientContext(&data, &com, &foreigncreds, credp);
879 code = HandleClientContext(&data, &com, &foreigncreds, osi_curcred());
883 crfree(foreigncreds);
886 #if defined(KERNEL_HAVE_UERROR)
887 return (setuerror(code), code);
892 #else /* AFS_NEED_CLIENTCONTEXT */
894 #endif /* AFS_NEED_CLIENTCONTEXT */
896 #ifdef AFS_NEED_CLIENTCONTEXT
899 * We could have done without temporary setting the u.u_cred below
900 * (foreigncreds could be passed as param the pioctl modules)
901 * but calls such as afs_osi_suser() doesn't allow that since it
902 * references u.u_cred directly. We could, of course, do something
903 * like afs_osi_suser(cred) which, I think, is better since it
904 * generalizes and supports multi cred environments...
908 credp = foreigncreds;
909 #elif defined(AFS_AIX41_ENV)
910 tmpcred = crref(); /* XXX */
912 #elif defined(AFS_HPUX101_ENV)
913 tmpcred = p_cred(u.u_procp);
914 set_p_cred(u.u_procp, foreigncreds);
915 #elif defined(AFS_SGI_ENV)
916 tmpcred = OSI_GET_CURRENT_CRED();
917 OSI_SET_CURRENT_CRED(foreigncreds);
920 u.u_cred = foreigncreds;
923 #endif /* AFS_NEED_CLIENTCONTEXT */
924 if ((com & 0xff) == 15) {
925 /* special case prefetch so entire pathname eval occurs in helper process.
926 * otherwise, the pioctl call is essentially useless */
927 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
929 Prefetch(path, &data, follow,
930 foreigncreds ? foreigncreds : credp);
932 code = Prefetch(path, &data, follow, osi_curcred());
935 #if defined(KERNEL_HAVE_UERROR)
944 lookupname(path, USR, follow, NULL, &vp,
945 foreigncreds ? foreigncreds : credp);
947 #ifdef AFS_LINUX22_ENV
948 code = gop_lookupname(path, AFS_UIOUSER, follow, NULL, &dp);
950 vp = (struct vnode *)dp->d_inode;
952 code = gop_lookupname(path, AFS_UIOUSER, follow, NULL, &vp);
953 #endif /* AFS_LINUX22_ENV */
954 #endif /* AFS_AIX41_ENV */
958 #if defined(KERNEL_HAVE_UERROR)
966 /* now make the call if we were passed no file, or were passed an AFS file */
967 if (!vp || IsAfsVnode(vp)) {
968 #if defined(AFS_DEC_ENV)
969 /* Ultrix 4.0: can't get vcache entry unless we've got an AFS gnode.
970 * So, we must test in this part of the code. Also, must arrange to
971 * GRELE the original gnode pointer when we're done, since in Ultrix 4.0,
972 * we hold gnodes, whose references hold our vcache entries.
975 gp = vp; /* remember for "put" */
976 vp = (struct vnode *)afs_gntovn(vp); /* get vcache from gp */
979 #elif defined(AFS_SUN5_ENV)
980 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
981 #elif defined(AFS_AIX41_ENV)
983 struct ucred *cred1, *cred2;
986 cred1 = cred2 = foreigncreds;
988 cred1 = cred2 = credp;
990 code = afs_HandlePioctl(vp, com, &data, follow, &cred1);
991 if (cred1 != cred2) {
992 /* something changed the creds */
996 #elif defined(AFS_HPUX101_ENV)
998 struct ucred *cred = p_cred(u.u_procp);
999 code = afs_HandlePioctl(vp, com, &data, follow, &cred);
1001 #elif defined(AFS_SGI_ENV)
1004 credp = OSI_GET_CURRENT_CRED();
1005 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1007 #elif defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1008 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1010 code = afs_HandlePioctl(vp, com, &data, follow, &u.u_cred);
1013 #if defined(KERNEL_HAVE_UERROR)
1016 code = EINVAL; /* not in /afs */
1027 #if defined(AFS_NEED_CLIENTCONTEXT)
1029 #ifdef AFS_AIX41_ENV
1030 crset(tmpcred); /* restore original credentials */
1032 #if defined(AFS_HPUX101_ENV)
1033 set_p_cred(u.u_procp, tmpcred); /* restore original credentials */
1034 #elif defined(AFS_SGI_ENV)
1035 OSI_SET_CURRENT_CRED(tmpcred); /* restore original credentials */
1036 #elif !defined(AFS_SUN5_ENV)
1037 osi_curcred() = tmpcred; /* restore original credentials */
1038 #endif /* AFS_HPUX101_ENV */
1039 crfree(foreigncreds);
1042 #endif /* AFS_NEED_CLIENTCONTEXT */
1044 #ifdef AFS_LINUX22_ENV
1047 AFS_RELE(vp); /* put vnode back */
1051 #if defined(KERNEL_HAVE_UERROR)
1054 return (getuerror());
1060 #define MAXPIOCTLTOKENLEN \
1061 (3*sizeof(afs_int32)+MAXKTCTICKETLEN+sizeof(struct ClearToken)+MAXKTCREALMLEN)
1064 afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
1065 register struct afs_ioctl *ablob, int afollow,
1066 struct AFS_UCRED **acred)
1069 struct vrequest treq;
1070 register afs_int32 code;
1071 register afs_int32 function, device;
1072 afs_int32 inSize, outSize, outSizeMax;
1073 char *inData, *outData;
1074 int (*(*pioctlSw)) ();
1076 struct afs_fakestat_state fakestate;
1078 avc = avp ? VTOAFS(avp) : NULL;
1079 afs_Trace3(afs_iclSetp, CM_TRACE_PIOCTL, ICL_TYPE_INT32, acom & 0xff,
1080 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, afollow);
1081 AFS_STATCNT(HandlePioctl);
1082 if ((code = afs_InitReq(&treq, *acred)))
1084 afs_InitFakeStat(&fakestate);
1086 code = afs_EvalFakeStat(&avc, &fakestate, &treq);
1088 afs_PutFakeStat(&fakestate);
1092 device = (acom & 0xff00) >> 8;
1094 case 'V': /* Original pioctls */
1095 pioctlSw = VpioctlSw;
1096 pioctlSwSize = sizeof(VpioctlSw);
1098 case 'C': /* Coordinated/common pioctls */
1099 pioctlSw = CpioctlSw;
1100 pioctlSwSize = sizeof(CpioctlSw);
1103 afs_PutFakeStat(&fakestate);
1106 function = acom & 0xff;
1107 if (function >= (pioctlSwSize / sizeof(char *))) {
1108 afs_PutFakeStat(&fakestate);
1109 return EINVAL; /* out of range */
1111 inSize = ablob->in_size;
1113 /* Do all range checking before continuing */
1114 if (inSize > MAXPIOCTLTOKENLEN || inSize < 0 || ablob->out_size < 0)
1117 if (inSize > AFS_LRALLOCSIZ) {
1118 inData = osi_AllocLargeSpace(inSize+1);
1120 inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1125 AFS_COPYIN(ablob->in, inData, inSize, code);
1126 inData[inSize] = '\0';
1130 if (inSize > AFS_LRALLOCSIZ) {
1131 osi_Free(inData, inSize+1);
1133 osi_FreeLargeSpace(inData);
1135 afs_PutFakeStat(&fakestate);
1138 if (function == 8 && device == 'V') { /* PGetTokens */
1139 outSizeMax = MAXPIOCTLTOKENLEN;
1140 outData = osi_Alloc(outSizeMax);
1142 outSizeMax = AFS_LRALLOCSIZ;
1143 outData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1146 if (inSize > AFS_LRALLOCSIZ) {
1147 osi_Free(inData, inSize+1);
1149 osi_FreeLargeSpace(inData);
1155 (*pioctlSw[function]) (avc, function, &treq, inData, outData, inSize,
1157 if (inSize > AFS_LRALLOCSIZ) {
1158 osi_Free(inData, inSize+1);
1160 osi_FreeLargeSpace(inData);
1162 if (code == 0 && ablob->out_size > 0) {
1163 if (outSize > ablob->out_size) {
1164 code = E2BIG; /* data wont fit in user buffer */
1165 } else if (outSize) {
1166 AFS_COPYOUT(outData, ablob->out, outSize, code);
1169 if (outSizeMax > AFS_LRALLOCSIZ) {
1170 osi_Free(outData, outSizeMax);
1172 osi_FreeLargeSpace(outData);
1174 afs_PutFakeStat(&fakestate);
1175 return afs_CheckCode(code, &treq, 41);
1178 DECL_PIOCTL(PGetFID)
1180 AFS_STATCNT(PGetFID);
1183 memcpy(aout, (char *)&avc->fid, sizeof(struct VenusFid));
1184 *aoutSize = sizeof(struct VenusFid);
1188 DECL_PIOCTL(PSetAcl)
1190 register afs_int32 code;
1192 struct AFSOpaque acl;
1193 struct AFSVolSync tsync;
1194 struct AFSFetchStatus OutStatus;
1197 AFS_STATCNT(PSetAcl);
1200 if ((acl.AFSOpaque_len = strlen(ain) + 1) > 1000)
1203 acl.AFSOpaque_val = ain;
1205 tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1207 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREACL);
1210 RXAFS_StoreACL(tconn->id, (struct AFSFid *)&avc->fid.Fid,
1211 &acl, &OutStatus, &tsync);
1216 } while (afs_Analyze
1217 (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_STOREACL,
1218 SHARED_LOCK, NULL));
1220 /* now we've forgotten all of the access info */
1221 ObtainWriteLock(&afs_xcbhash, 455);
1223 afs_DequeueCallback(avc);
1224 avc->states &= ~(CStatd | CUnique);
1225 ReleaseWriteLock(&afs_xcbhash);
1226 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
1227 osi_dnlc_purgedp(avc);
1231 int afs_defaultAsynchrony = 0;
1233 DECL_PIOCTL(PStoreBehind)
1236 struct sbstruct *sbr;
1238 sbr = (struct sbstruct *)ain;
1239 if (sbr->sb_default != -1) {
1240 if (afs_osi_suser(*acred))
1241 afs_defaultAsynchrony = sbr->sb_default;
1246 if (avc && (sbr->sb_thisfile != -1)) {
1248 (avc, PRSFS_WRITE | PRSFS_ADMINISTER, areq, DONT_CHECK_MODE_BITS))
1249 avc->asynchrony = sbr->sb_thisfile;
1254 *aoutSize = sizeof(struct sbstruct);
1255 sbr = (struct sbstruct *)aout;
1256 sbr->sb_default = afs_defaultAsynchrony;
1258 sbr->sb_thisfile = avc->asynchrony;
1264 DECL_PIOCTL(PGCPAGs)
1266 if (!afs_osi_suser(*acred)) {
1269 afs_gcpags = AFS_GCPAGS_USERDISABLED;
1273 DECL_PIOCTL(PGetAcl)
1275 struct AFSOpaque acl;
1276 struct AFSVolSync tsync;
1277 struct AFSFetchStatus OutStatus;
1283 AFS_STATCNT(PGetAcl);
1286 Fid.Volume = avc->fid.Fid.Volume;
1287 Fid.Vnode = avc->fid.Fid.Vnode;
1288 Fid.Unique = avc->fid.Fid.Unique;
1289 if (avc->states & CForeign) {
1291 * For a dfs xlator acl we have a special hack so that the
1292 * xlator will distinguish which type of acl will return. So
1293 * we currently use the top 2-bytes (vals 0-4) to tell which
1294 * type of acl to bring back. Horrible hack but this will
1295 * cause the least number of changes to code size and interfaces.
1297 if (Fid.Vnode & 0xc0000000)
1299 Fid.Vnode |= (ainSize << 30);
1301 acl.AFSOpaque_val = aout;
1303 tconn = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1306 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHACL);
1308 code = RXAFS_FetchACL(tconn->id, &Fid, &acl, &OutStatus, &tsync);
1313 } while (afs_Analyze
1314 (tconn, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_FETCHACL,
1315 SHARED_LOCK, NULL));
1318 *aoutSize = (acl.AFSOpaque_len == 0 ? 1 : acl.AFSOpaque_len);
1331 AFS_STATCNT(PBogus);
1335 DECL_PIOCTL(PGetFileCell)
1337 register struct cell *tcell;
1339 AFS_STATCNT(PGetFileCell);
1342 tcell = afs_GetCell(avc->fid.Cell, READ_LOCK);
1345 strcpy(aout, tcell->cellName);
1346 afs_PutCell(tcell, READ_LOCK);
1347 *aoutSize = strlen(aout) + 1;
1351 DECL_PIOCTL(PGetWSCell)
1353 struct cell *tcell = NULL;
1355 AFS_STATCNT(PGetWSCell);
1356 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1357 return EIO; /* Inappropriate ioctl for device */
1359 tcell = afs_GetPrimaryCell(READ_LOCK);
1360 if (!tcell) /* no primary cell? */
1362 strcpy(aout, tcell->cellName);
1363 *aoutSize = strlen(aout) + 1;
1364 afs_PutCell(tcell, READ_LOCK);
1368 DECL_PIOCTL(PGetUserCell)
1370 register afs_int32 i;
1371 register struct unixuser *tu;
1372 register struct cell *tcell;
1374 AFS_STATCNT(PGetUserCell);
1375 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1376 return EIO; /* Inappropriate ioctl for device */
1378 /* return the cell name of the primary cell for this user */
1379 i = UHash(areq->uid);
1380 ObtainWriteLock(&afs_xuser, 224);
1381 for (tu = afs_users[i]; tu; tu = tu->next) {
1382 if (tu->uid == areq->uid && (tu->states & UPrimary)) {
1384 ReleaseWriteLock(&afs_xuser);
1389 tcell = afs_GetCell(tu->cell, READ_LOCK);
1390 afs_PutUser(tu, WRITE_LOCK);
1394 strcpy(aout, tcell->cellName);
1395 afs_PutCell(tcell, READ_LOCK);
1396 *aoutSize = strlen(aout) + 1; /* 1 for the null */
1399 ReleaseWriteLock(&afs_xuser);
1406 DECL_PIOCTL(PSetTokens)
1409 register struct unixuser *tu;
1410 struct ClearToken clear;
1411 register struct cell *tcell;
1414 struct vrequest treq;
1415 afs_int32 flag, set_parent_pag = 0;
1417 AFS_STATCNT(PSetTokens);
1418 if (!afs_resourceinit_flag) {
1421 memcpy((char *)&i, ain, sizeof(afs_int32));
1422 ain += sizeof(afs_int32);
1423 stp = ain; /* remember where the ticket is */
1424 if (i < 0 || i > MAXKTCTICKETLEN)
1425 return EINVAL; /* malloc may fail */
1427 ain += i; /* skip over ticket */
1428 memcpy((char *)&i, ain, sizeof(afs_int32));
1429 ain += sizeof(afs_int32);
1430 if (i != sizeof(struct ClearToken)) {
1433 memcpy((char *)&clear, ain, sizeof(struct ClearToken));
1434 if (clear.AuthHandle == -1)
1435 clear.AuthHandle = 999; /* more rxvab compat stuff */
1436 ain += sizeof(struct ClearToken);
1437 if (ainSize != 2 * sizeof(afs_int32) + stLen + sizeof(struct ClearToken)) {
1438 /* still stuff left? we've got primary flag and cell name. Set these */
1439 memcpy((char *)&flag, ain, sizeof(afs_int32)); /* primary id flag */
1440 ain += sizeof(afs_int32); /* skip id field */
1441 /* rest is cell name, look it up */
1442 /* some versions of gcc appear to need != 0 in order to get this right */
1443 if ((flag & 0x8000) != 0) { /* XXX Use Constant XXX */
1447 tcell = afs_GetCellByName(ain, READ_LOCK);
1451 /* default to primary cell, primary id */
1452 flag = 1; /* primary id */
1453 tcell = afs_GetPrimaryCell(READ_LOCK);
1458 afs_PutCell(tcell, READ_LOCK);
1459 if (set_parent_pag) {
1461 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1462 #if defined(AFS_DARWIN_ENV)
1463 struct proc *p = current_proc(); /* XXX */
1465 struct proc *p = curproc; /* XXX */
1467 uprintf("Process %d (%s) tried to change pags in PSetTokens\n",
1468 p->p_pid, p->p_comm);
1469 if (!setpag(p, acred, -1, &pag, 1)) {
1472 if (!setpag(u.u_procp, acred, -1, &pag, 1)) { /* XXX u.u_procp is a no-op XXX */
1474 if (!setpag(acred, -1, &pag, 1)) {
1477 afs_InitReq(&treq, *acred);
1481 /* now we just set the tokens */
1482 tu = afs_GetUser(areq->uid, i, WRITE_LOCK); /* i has the cell # */
1483 tu->vid = clear.ViceId;
1484 if (tu->stp != NULL) {
1485 afs_osi_Free(tu->stp, tu->stLen);
1487 tu->stp = (char *)afs_osi_Alloc(stLen);
1489 memcpy(tu->stp, stp, stLen);
1492 afs_stats_cmfullperf.authent.TicketUpdates++;
1493 afs_ComputePAGStats();
1494 #endif /* AFS_NOSTATS */
1495 tu->states |= UHasTokens;
1496 tu->states &= ~UTokensBad;
1497 afs_SetPrimary(tu, flag);
1498 tu->tokenTime = osi_Time();
1499 afs_ResetUserConns(tu);
1500 afs_PutUser(tu, WRITE_LOCK);
1515 DECL_PIOCTL(PGetVolumeStatus)
1518 char *offLineMsg = afs_osi_Alloc(256);
1519 char *motd = afs_osi_Alloc(256);
1520 register struct conn *tc;
1521 register afs_int32 code = 0;
1522 struct VolumeStatus volstat;
1524 char *Name, *OfflineMsg, *MOTD;
1527 AFS_STATCNT(PGetVolumeStatus);
1533 OfflineMsg = offLineMsg;
1536 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1538 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS);
1541 RXAFS_GetVolumeStatus(tc->id, avc->fid.Fid.Volume, &volstat,
1542 &Name, &OfflineMsg, &MOTD);
1547 } while (afs_Analyze
1548 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS,
1549 SHARED_LOCK, NULL));
1553 /* Copy all this junk into msg->im_data, keeping track of the lengths. */
1555 memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
1556 cp += sizeof(VolumeStatus);
1557 strcpy(cp, volName);
1558 cp += strlen(volName) + 1;
1559 strcpy(cp, offLineMsg);
1560 cp += strlen(offLineMsg) + 1;
1562 cp += strlen(motd) + 1;
1563 *aoutSize = (cp - aout);
1565 afs_osi_Free(offLineMsg, 256);
1566 afs_osi_Free(motd, 256);
1570 DECL_PIOCTL(PSetVolumeStatus)
1573 char *offLineMsg = afs_osi_Alloc(256);
1574 char *motd = afs_osi_Alloc(256);
1575 register struct conn *tc;
1576 register afs_int32 code = 0;
1577 struct AFSFetchVolumeStatus volstat;
1578 struct AFSStoreVolumeStatus storeStat;
1579 register struct volume *tvp;
1583 AFS_STATCNT(PSetVolumeStatus);
1589 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
1591 if (tvp->states & (VRO | VBackup)) {
1592 afs_PutVolume(tvp, READ_LOCK);
1596 afs_PutVolume(tvp, READ_LOCK);
1601 /* Copy the junk out, using cp as a roving pointer. */
1603 memcpy((char *)&volstat, cp, sizeof(AFSFetchVolumeStatus));
1604 cp += sizeof(AFSFetchVolumeStatus);
1605 if (strlen(cp) >= sizeof(volName)) {
1609 strcpy(volName, cp);
1610 cp += strlen(volName) + 1;
1611 if (strlen(cp) >= sizeof(offLineMsg)) {
1615 strcpy(offLineMsg, cp);
1616 cp += strlen(offLineMsg) + 1;
1617 if (strlen(cp) >= sizeof(motd)) {
1623 if (volstat.MinQuota != -1) {
1624 storeStat.MinQuota = volstat.MinQuota;
1625 storeStat.Mask |= AFS_SETMINQUOTA;
1627 if (volstat.MaxQuota != -1) {
1628 storeStat.MaxQuota = volstat.MaxQuota;
1629 storeStat.Mask |= AFS_SETMAXQUOTA;
1632 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1634 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS);
1637 RXAFS_SetVolumeStatus(tc->id, avc->fid.Fid.Volume, &storeStat,
1638 volName, offLineMsg, motd);
1643 } while (afs_Analyze
1644 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS,
1645 SHARED_LOCK, NULL));
1649 /* we are sending parms back to make compat. with prev system. should
1650 * change interface later to not ask for current status, just set new status */
1652 memcpy(cp, (char *)&volstat, sizeof(VolumeStatus));
1653 cp += sizeof(VolumeStatus);
1654 strcpy(cp, volName);
1655 cp += strlen(volName) + 1;
1656 strcpy(cp, offLineMsg);
1657 cp += strlen(offLineMsg) + 1;
1659 cp += strlen(motd) + 1;
1660 *aoutSize = cp - aout;
1662 afs_osi_Free(offLineMsg, 256);
1663 afs_osi_Free(motd, 256);
1669 AFS_STATCNT(PFlush);
1672 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
1673 afs_BozonLock(&avc->pvnLock, avc); /* Since afs_TryToSmush will do a pvn_vptrunc */
1675 ObtainWriteLock(&avc->lock, 225);
1676 ObtainWriteLock(&afs_xcbhash, 456);
1677 afs_DequeueCallback(avc);
1678 avc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
1679 ReleaseWriteLock(&afs_xcbhash);
1680 /* now find the disk cache entries */
1681 afs_TryToSmush(avc, *acred, 1);
1682 osi_dnlc_purgedp(avc);
1683 afs_symhint_inval(avc);
1684 if (avc->linkData && !(avc->states & CCore)) {
1685 afs_osi_Free(avc->linkData, strlen(avc->linkData) + 1);
1686 avc->linkData = NULL;
1688 ReleaseWriteLock(&avc->lock);
1689 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
1690 afs_BozonUnlock(&avc->pvnLock, avc);
1695 DECL_PIOCTL(PNewStatMount)
1697 register afs_int32 code;
1698 register struct vcache *tvc;
1699 register struct dcache *tdc;
1700 struct VenusFid tfid;
1702 struct sysname_info sysState;
1703 afs_size_t offset, len;
1705 AFS_STATCNT(PNewStatMount);
1708 code = afs_VerifyVCache(avc, areq);
1711 if (vType(avc) != VDIR) {
1714 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
1717 Check_AtSys(avc, ain, &sysState, areq);
1718 ObtainReadLock(&tdc->lock);
1720 code = afs_dir_Lookup(&tdc->f, sysState.name, &tfid.Fid);
1721 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
1722 ReleaseReadLock(&tdc->lock);
1723 afs_PutDCache(tdc); /* we're done with the data */
1724 bufp = sysState.name;
1728 tfid.Cell = avc->fid.Cell;
1729 tfid.Fid.Volume = avc->fid.Fid.Volume;
1730 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
1731 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
1733 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
1739 if (tvc->mvstat != 1) {
1744 ObtainWriteLock(&tvc->lock, 226);
1745 code = afs_HandleLink(tvc, areq);
1747 if (tvc->linkData) {
1748 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
1751 /* we have the data */
1752 strcpy(aout, tvc->linkData);
1753 *aoutSize = strlen(tvc->linkData) + 1;
1758 ReleaseWriteLock(&tvc->lock);
1761 if (sysState.allocked)
1762 osi_FreeLargeSpace(bufp);
1766 DECL_PIOCTL(PGetTokens)
1768 register struct cell *tcell;
1769 register afs_int32 i;
1770 register struct unixuser *tu;
1775 AFS_STATCNT(PGetTokens);
1776 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1777 return EIO; /* Inappropriate ioctl for device */
1779 /* weird interface. If input parameter is present, it is an integer and
1780 * we're supposed to return the parm'th tokens for this unix uid.
1781 * If not present, we just return tokens for cell 1.
1782 * If counter out of bounds, return EDOM.
1783 * If no tokens for the particular cell, return ENOTCONN.
1784 * Also, if this mysterious parm is present, we return, along with the
1785 * tokens, the primary cell indicator (an afs_int32 0) and the cell name
1786 * at the end, in that order.
1788 if ((newStyle = (ainSize > 0))) {
1789 memcpy((char *)&iterator, ain, sizeof(afs_int32));
1791 i = UHash(areq->uid);
1792 ObtainReadLock(&afs_xuser);
1793 for (tu = afs_users[i]; tu; tu = tu->next) {
1795 if (tu->uid == areq->uid && (tu->states & UHasTokens)) {
1796 if (iterator-- == 0)
1797 break; /* are we done yet? */
1800 if (tu->uid == areq->uid && afs_IsPrimaryCellNum(tu->cell))
1806 * No need to hold a read lock on each user entry
1810 ReleaseReadLock(&afs_xuser);
1815 if (((tu->states & UHasTokens) == 0)
1816 || (tu->ct.EndTimestamp < osi_Time())) {
1817 tu->states |= (UTokensBad | UNeedsReset);
1818 afs_PutUser(tu, READ_LOCK);
1821 /* use iterator for temp */
1823 iterator = tu->stLen; /* for compat, we try to return 56 byte tix if they fit */
1825 iterator = 56; /* # of bytes we're returning */
1826 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1827 cp += sizeof(afs_int32);
1828 memcpy(cp, tu->stp, tu->stLen); /* copy out st */
1830 iterator = sizeof(struct ClearToken);
1831 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1832 cp += sizeof(afs_int32);
1833 memcpy(cp, (char *)&tu->ct, sizeof(struct ClearToken));
1834 cp += sizeof(struct ClearToken);
1836 /* put out primary id and cell name, too */
1837 iterator = (tu->states & UPrimary ? 1 : 0);
1838 memcpy(cp, (char *)&iterator, sizeof(afs_int32));
1839 cp += sizeof(afs_int32);
1840 tcell = afs_GetCell(tu->cell, READ_LOCK);
1842 strcpy(cp, tcell->cellName);
1843 cp += strlen(tcell->cellName) + 1;
1844 afs_PutCell(tcell, READ_LOCK);
1848 *aoutSize = cp - aout;
1849 afs_PutUser(tu, READ_LOCK);
1855 register afs_int32 i;
1856 register struct unixuser *tu;
1858 AFS_STATCNT(PUnlog);
1859 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1860 return EIO; /* Inappropriate ioctl for device */
1862 i = UHash(areq->uid);
1863 ObtainWriteLock(&afs_xuser, 227);
1864 for (tu = afs_users[i]; tu; tu = tu->next) {
1865 if (tu->uid == areq->uid) {
1867 tu->states &= ~UHasTokens;
1868 /* security is not having to say you're sorry */
1869 memset((char *)&tu->ct, 0, sizeof(struct ClearToken));
1871 ReleaseWriteLock(&afs_xuser);
1872 /* We have to drop the lock over the call to afs_ResetUserConns, since
1873 * it obtains the afs_xvcache lock. We could also keep the lock, and
1874 * modify ResetUserConns to take parm saying we obtained the lock
1875 * already, but that is overkill. By keeping the "tu" pointer
1876 * held over the released lock, we guarantee that we won't lose our
1877 * place, and that we'll pass over every user conn that existed when
1878 * we began this call.
1880 afs_ResetUserConns(tu);
1882 ObtainWriteLock(&afs_xuser, 228);
1884 /* set the expire times to 0, causes
1885 * afs_GCUserData to remove this entry
1887 tu->ct.EndTimestamp = 0;
1889 #endif /* UKERNEL */
1892 ReleaseWriteLock(&afs_xuser);
1896 DECL_PIOCTL(PMariner)
1898 afs_int32 newHostAddr;
1899 afs_int32 oldHostAddr;
1901 AFS_STATCNT(PMariner);
1903 memcpy((char *)&oldHostAddr, (char *)&afs_marinerHost,
1906 oldHostAddr = 0xffffffff; /* disabled */
1908 memcpy((char *)&newHostAddr, ain, sizeof(afs_int32));
1909 if (newHostAddr == 0xffffffff) {
1910 /* disable mariner operations */
1912 } else if (newHostAddr) {
1914 afs_marinerHost = newHostAddr;
1916 memcpy(aout, (char *)&oldHostAddr, sizeof(afs_int32));
1917 *aoutSize = sizeof(afs_int32);
1921 DECL_PIOCTL(PCheckServers)
1923 register char *cp = 0;
1925 register struct server *ts;
1926 afs_int32 temp, *lp = (afs_int32 *) ain, havecell = 0;
1928 struct chservinfo *pcheck;
1930 AFS_STATCNT(PCheckServers);
1932 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1933 return EIO; /* Inappropriate ioctl for device */
1935 if (*lp == 0x12345678) { /* For afs3.3 version */
1936 pcheck = (struct chservinfo *)ain;
1937 if (pcheck->tinterval >= 0) {
1939 memcpy(cp, (char *)&PROBE_INTERVAL, sizeof(afs_int32));
1940 *aoutSize = sizeof(afs_int32);
1941 if (pcheck->tinterval > 0) {
1942 if (!afs_osi_suser(*acred))
1944 PROBE_INTERVAL = pcheck->tinterval;
1950 temp = pcheck->tflags;
1951 cp = pcheck->tbuffer;
1952 } else { /* For pre afs3.3 versions */
1953 memcpy((char *)&temp, ain, sizeof(afs_int32));
1954 cp = ain + sizeof(afs_int32);
1955 if (ainSize > sizeof(afs_int32))
1960 * 1: fast check, don't contact servers.
1961 * 2: local cell only.
1964 /* have cell name, too */
1965 cellp = afs_GetCellByName(cp, READ_LOCK);
1970 if (!cellp && (temp & 2)) {
1971 /* use local cell */
1972 cellp = afs_GetPrimaryCell(READ_LOCK);
1974 if (!(temp & 1)) { /* if not fast, call server checker routine */
1975 afs_CheckServers(1, cellp); /* check down servers */
1976 afs_CheckServers(0, cellp); /* check up servers */
1978 /* now return the current down server list */
1980 ObtainReadLock(&afs_xserver);
1981 for (i = 0; i < NSERVERS; i++) {
1982 for (ts = afs_servers[i]; ts; ts = ts->next) {
1983 if (cellp && ts->cell != cellp)
1984 continue; /* cell spec'd and wrong */
1985 if ((ts->flags & SRVR_ISDOWN)
1986 && ts->addr->sa_portal != ts->cell->vlport) {
1987 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
1988 cp += sizeof(afs_int32);
1992 ReleaseReadLock(&afs_xserver);
1994 afs_PutCell(cellp, READ_LOCK);
1995 *aoutSize = cp - aout;
1999 DECL_PIOCTL(PCheckVolNames)
2001 AFS_STATCNT(PCheckVolNames);
2002 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2003 return EIO; /* Inappropriate ioctl for device */
2005 afs_CheckRootVolume();
2006 afs_CheckVolumeNames(AFS_VOLCHECK_FORCE | AFS_VOLCHECK_EXPIRED |
2007 AFS_VOLCHECK_BUSY | AFS_VOLCHECK_MTPTS);
2011 DECL_PIOCTL(PCheckAuth)
2016 struct unixuser *tu;
2019 AFS_STATCNT(PCheckAuth);
2020 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2021 return EIO; /* Inappropriate ioctl for device */
2024 tu = afs_GetUser(areq->uid, 1, READ_LOCK); /* check local cell authentication */
2028 /* we have a user */
2029 ObtainReadLock(&afs_xsrvAddr);
2030 ObtainReadLock(&afs_xconn);
2032 /* any tokens set? */
2033 if ((tu->states & UHasTokens) == 0)
2035 /* all connections in cell 1 working? */
2036 for (i = 0; i < NSERVERS; i++) {
2037 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2038 for (tc = sa->conns; tc; tc = tc->next) {
2039 if (tc->user == tu && (tu->states & UTokensBad))
2044 ReleaseReadLock(&afs_xsrvAddr);
2045 ReleaseReadLock(&afs_xconn);
2046 afs_PutUser(tu, READ_LOCK);
2048 memcpy(aout, (char *)&retValue, sizeof(afs_int32));
2049 *aoutSize = sizeof(afs_int32);
2054 Prefetch(char *apath, struct afs_ioctl *adata, int afollow,
2055 struct AFS_UCRED *acred)
2058 register afs_int32 code;
2059 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2065 AFS_STATCNT(Prefetch);
2068 tp = osi_AllocLargeSpace(1024);
2069 AFS_COPYINSTR(apath, tp, 1024, &bufferSize, code);
2071 osi_FreeLargeSpace(tp);
2074 if (afs_BBusy()) { /* do this as late as possible */
2075 osi_FreeLargeSpace(tp);
2076 return EWOULDBLOCK; /* pretty close */
2078 afs_BQueue(BOP_PATH, (struct vcache *)0, 0, 0, acred, (afs_size_t) 0,
2079 (afs_size_t) 0, tp);
2083 DECL_PIOCTL(PFindVolume)
2085 register struct volume *tvp;
2086 register struct server *ts;
2087 register afs_int32 i;
2090 AFS_STATCNT(PFindVolume);
2093 tvp = afs_GetVolume(&avc->fid, areq, READ_LOCK);
2096 for (i = 0; i < MAXHOSTS; i++) {
2097 ts = tvp->serverHost[i];
2100 memcpy(cp, (char *)&ts->addr->sa_ip, sizeof(afs_int32));
2101 cp += sizeof(afs_int32);
2104 /* still room for terminating NULL, add it on */
2105 ainSize = 0; /* reuse vbl */
2106 memcpy(cp, (char *)&ainSize, sizeof(afs_int32));
2107 cp += sizeof(afs_int32);
2109 *aoutSize = cp - aout;
2110 afs_PutVolume(tvp, READ_LOCK);
2116 DECL_PIOCTL(PViceAccess)
2118 register afs_int32 code;
2121 AFS_STATCNT(PViceAccess);
2124 code = afs_VerifyVCache(avc, areq);
2127 memcpy((char *)&temp, ain, sizeof(afs_int32));
2128 code = afs_AccessOK(avc, temp, areq, CHECK_MODE_BITS);
2135 DECL_PIOCTL(PSetCacheSize)
2140 AFS_STATCNT(PSetCacheSize);
2141 if (!afs_osi_suser(*acred))
2143 /* too many things are setup initially in mem cache version */
2144 if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
2146 memcpy((char *)&newValue, ain, sizeof(afs_int32));
2148 afs_cacheBlocks = afs_stats_cmperf.cacheBlocksOrig;
2150 if (newValue < afs_min_cache)
2151 afs_cacheBlocks = afs_min_cache;
2153 afs_cacheBlocks = newValue;
2155 afs_stats_cmperf.cacheBlocksTotal = afs_cacheBlocks;
2156 afs_ComputeCacheParms(); /* recompute basic cache parameters */
2157 afs_MaybeWakeupTruncateDaemon();
2158 while (waitcnt++ < 100 && afs_cacheBlocks < afs_blocksUsed) {
2159 afs_osi_Wait(1000, 0, 0);
2160 afs_MaybeWakeupTruncateDaemon();
2165 #define MAXGCSTATS 16
2166 DECL_PIOCTL(PGetCacheSize)
2168 afs_int32 results[MAXGCSTATS];
2170 AFS_STATCNT(PGetCacheSize);
2171 memset((char *)results, 0, sizeof(results));
2172 results[0] = afs_cacheBlocks;
2173 results[1] = afs_blocksUsed;
2174 memcpy(aout, (char *)results, sizeof(results));
2175 *aoutSize = sizeof(results);
2179 DECL_PIOCTL(PRemoveCallBack)
2181 register struct conn *tc;
2182 register afs_int32 code = 0;
2183 struct AFSCallBack CallBacks_Array[1];
2184 struct AFSCBFids theFids;
2185 struct AFSCBs theCBs;
2188 AFS_STATCNT(PRemoveCallBack);
2191 if (avc->states & CRO)
2192 return 0; /* read-only-ness can't change */
2193 ObtainWriteLock(&avc->lock, 229);
2194 theFids.AFSCBFids_len = 1;
2195 theCBs.AFSCBs_len = 1;
2196 theFids.AFSCBFids_val = (struct AFSFid *)&avc->fid.Fid;
2197 theCBs.AFSCBs_val = CallBacks_Array;
2198 CallBacks_Array[0].CallBackType = CB_DROPPED;
2199 if (avc->callback) {
2201 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2203 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
2205 code = RXAFS_GiveUpCallBacks(tc->id, &theFids, &theCBs);
2209 /* don't set code on failure since we wouldn't use it */
2210 } while (afs_Analyze
2211 (tc, code, &avc->fid, areq,
2212 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK, NULL));
2214 ObtainWriteLock(&afs_xcbhash, 457);
2215 afs_DequeueCallback(avc);
2217 avc->states &= ~(CStatd | CUnique);
2218 ReleaseWriteLock(&afs_xcbhash);
2219 if (avc->fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
2220 osi_dnlc_purgedp(avc);
2222 ReleaseWriteLock(&avc->lock);
2226 DECL_PIOCTL(PNewCell)
2228 /* create a new cell */
2229 afs_int32 cellHosts[MAXCELLHOSTS], *lp, magic = 0;
2230 char *newcell = 0, *linkedcell = 0, *tp = ain;
2231 register afs_int32 code, linkedstate = 0, ls;
2232 u_short fsport = 0, vlport = 0;
2235 AFS_STATCNT(PNewCell);
2236 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2237 return EIO; /* Inappropriate ioctl for device */
2239 if (!afs_osi_suser(*acred))
2242 memcpy((char *)&magic, tp, sizeof(afs_int32));
2243 tp += sizeof(afs_int32);
2244 if (magic != 0x12345678)
2247 /* A 3.4 fs newcell command will pass an array of MAXCELLHOSTS
2248 * server addresses while the 3.5 fs newcell command passes
2249 * MAXHOSTS. To figure out which is which, check if the cellname
2252 newcell = tp + (MAXCELLHOSTS + 3) * sizeof(afs_int32);
2253 scount = ((newcell[0] != '\0') ? MAXCELLHOSTS : MAXHOSTS);
2255 /* MAXCELLHOSTS (=8) is less than MAXHOSTS (=13) */
2256 memcpy((char *)cellHosts, tp, MAXCELLHOSTS * sizeof(afs_int32));
2257 tp += (scount * sizeof(afs_int32));
2259 lp = (afs_int32 *) tp;
2263 fsport = 0; /* Privileged ports not allowed */
2265 vlport = 0; /* Privileged ports not allowed */
2266 tp += (3 * sizeof(afs_int32));
2268 if ((ls = *lp) & 1) {
2269 linkedcell = tp + strlen(newcell) + 1;
2270 linkedstate |= CLinkedCell;
2273 linkedstate |= CNoSUID; /* setuid is disabled by default for fs newcell */
2275 afs_NewCell(newcell, cellHosts, linkedstate, linkedcell, fsport,
2280 DECL_PIOCTL(PNewAlias)
2282 /* create a new cell alias */
2284 register afs_int32 code;
2285 char *realName, *aliasName;
2287 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2288 return EIO; /* Inappropriate ioctl for device */
2290 if (!afs_osi_suser(*acred))
2294 tp += strlen(aliasName) + 1;
2297 code = afs_NewCellAlias(aliasName, realName);
2302 DECL_PIOCTL(PListCells)
2304 afs_int32 whichCell;
2305 register struct cell *tcell = 0;
2306 register afs_int32 i;
2307 register char *cp, *tp = ain;
2309 AFS_STATCNT(PListCells);
2310 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2311 return EIO; /* Inappropriate ioctl for device */
2313 memcpy((char *)&whichCell, tp, sizeof(afs_int32));
2314 tp += sizeof(afs_int32);
2315 tcell = afs_GetCellByIndex(whichCell, READ_LOCK);
2318 memset(cp, 0, MAXCELLHOSTS * sizeof(afs_int32));
2319 for (i = 0; i < MAXCELLHOSTS; i++) {
2320 if (tcell->cellHosts[i] == 0)
2322 memcpy(cp, (char *)&tcell->cellHosts[i]->addr->sa_ip,
2324 cp += sizeof(afs_int32);
2326 cp = aout + MAXCELLHOSTS * sizeof(afs_int32);
2327 strcpy(cp, tcell->cellName);
2328 cp += strlen(tcell->cellName) + 1;
2329 *aoutSize = cp - aout;
2330 afs_PutCell(tcell, READ_LOCK);
2338 DECL_PIOCTL(PListAliases)
2340 afs_int32 whichAlias;
2341 register struct cell_alias *tcalias = 0;
2342 register char *cp, *tp = ain;
2344 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2345 return EIO; /* Inappropriate ioctl for device */
2346 if (ainSize < sizeof(afs_int32))
2349 memcpy((char *)&whichAlias, tp, sizeof(afs_int32));
2350 tp += sizeof(afs_int32);
2352 tcalias = afs_GetCellAlias(whichAlias);
2355 strcpy(cp, tcalias->alias);
2356 cp += strlen(tcalias->alias) + 1;
2357 strcpy(cp, tcalias->cell);
2358 cp += strlen(tcalias->cell) + 1;
2359 *aoutSize = cp - aout;
2360 afs_PutCellAlias(tcalias);
2368 DECL_PIOCTL(PRemoveMount)
2370 register afs_int32 code;
2372 struct sysname_info sysState;
2373 afs_size_t offset, len;
2374 register struct conn *tc;
2375 register struct dcache *tdc;
2376 register struct vcache *tvc;
2377 struct AFSFetchStatus OutDirStatus;
2378 struct VenusFid tfid;
2379 struct AFSVolSync tsync;
2383 /* "ain" is the name of the file in this dir to remove */
2385 AFS_STATCNT(PRemoveMount);
2388 code = afs_VerifyVCache(avc, areq);
2391 if (vType(avc) != VDIR)
2394 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1); /* test for error below */
2397 Check_AtSys(avc, ain, &sysState, areq);
2398 ObtainReadLock(&tdc->lock);
2400 code = afs_dir_Lookup(&tdc->f, sysState.name, &tfid.Fid);
2401 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
2402 ReleaseReadLock(&tdc->lock);
2403 bufp = sysState.name;
2408 tfid.Cell = avc->fid.Cell;
2409 tfid.Fid.Volume = avc->fid.Fid.Volume;
2410 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
2411 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
2413 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
2420 if (tvc->mvstat != 1) {
2426 ObtainWriteLock(&tvc->lock, 230);
2427 code = afs_HandleLink(tvc, areq);
2429 if (tvc->linkData) {
2430 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
2435 ReleaseWriteLock(&tvc->lock);
2436 osi_dnlc_purgedp(tvc);
2442 ObtainWriteLock(&avc->lock, 231);
2443 osi_dnlc_remove(avc, bufp, tvc);
2445 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
2447 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE);
2450 RXAFS_RemoveFile(tc->id, (struct AFSFid *)&avc->fid.Fid, bufp,
2451 &OutDirStatus, &tsync);
2456 } while (afs_Analyze
2457 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_REMOVEFILE,
2458 SHARED_LOCK, NULL));
2463 ReleaseWriteLock(&avc->lock);
2467 /* we have the thing in the cache */
2468 ObtainWriteLock(&tdc->lock, 661);
2469 if (afs_LocalHero(avc, tdc, &OutDirStatus, 1)) {
2470 /* we can do it locally */
2471 code = afs_dir_Delete(&tdc->f, bufp);
2473 ZapDCE(tdc); /* surprise error -- invalid value */
2477 ReleaseWriteLock(&tdc->lock);
2478 afs_PutDCache(tdc); /* drop ref count */
2480 avc->states &= ~CUnique; /* For the dfs xlator */
2481 ReleaseWriteLock(&avc->lock);
2484 if (sysState.allocked)
2485 osi_FreeLargeSpace(bufp);
2489 DECL_PIOCTL(PVenusLogging)
2491 return EINVAL; /* OBSOLETE */
2494 DECL_PIOCTL(PGetCellStatus)
2496 register struct cell *tcell;
2499 AFS_STATCNT(PGetCellStatus);
2500 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2501 return EIO; /* Inappropriate ioctl for device */
2503 tcell = afs_GetCellByName(ain, READ_LOCK);
2506 temp = tcell->states;
2507 afs_PutCell(tcell, READ_LOCK);
2508 memcpy(aout, (char *)&temp, sizeof(afs_int32));
2509 *aoutSize = sizeof(afs_int32);
2513 DECL_PIOCTL(PSetCellStatus)
2515 register struct cell *tcell;
2518 if (!afs_osi_suser(*acred))
2520 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2521 return EIO; /* Inappropriate ioctl for device */
2523 tcell = afs_GetCellByName(ain + 2 * sizeof(afs_int32), WRITE_LOCK);
2526 memcpy((char *)&temp, ain, sizeof(afs_int32));
2528 tcell->states |= CNoSUID;
2530 tcell->states &= ~CNoSUID;
2531 afs_PutCell(tcell, WRITE_LOCK);
2535 DECL_PIOCTL(PFlushVolumeData)
2537 register afs_int32 i;
2538 register struct dcache *tdc;
2539 register struct vcache *tvc;
2540 register struct volume *tv;
2541 afs_int32 cell, volume;
2543 AFS_STATCNT(PFlushVolumeData);
2546 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2547 return EIO; /* Inappropriate ioctl for device */
2549 volume = avc->fid.Fid.Volume; /* who to zap */
2550 cell = avc->fid.Cell;
2553 * Clear stat'd flag from all vnodes from this volume; this will invalidate all
2554 * the vcaches associated with the volume.
2556 ObtainReadLock(&afs_xvcache);
2557 for (i = 0; i < VCSIZE; i++) {
2558 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2559 if (tvc->fid.Fid.Volume == volume && tvc->fid.Cell == cell) {
2560 #if defined(AFS_SGI_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
2561 VN_HOLD(AFSTOV(tvc));
2563 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2569 ReleaseReadLock(&afs_xvcache);
2570 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
2571 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
2573 ObtainWriteLock(&tvc->lock, 232);
2575 ObtainWriteLock(&afs_xcbhash, 458);
2576 afs_DequeueCallback(tvc);
2577 tvc->states &= ~(CStatd | CDirty);
2578 ReleaseWriteLock(&afs_xcbhash);
2579 if (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
2580 osi_dnlc_purgedp(tvc);
2581 afs_TryToSmush(tvc, *acred, 1);
2582 ReleaseWriteLock(&tvc->lock);
2583 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
2584 afs_BozonUnlock(&tvc->pvnLock, tvc);
2586 ObtainReadLock(&afs_xvcache);
2587 /* our tvc ptr is still good until now */
2592 ReleaseReadLock(&afs_xvcache);
2595 MObtainWriteLock(&afs_xdcache, 328); /* needed if you're going to flush any stuff */
2596 for (i = 0; i < afs_cacheFiles; i++) {
2597 if (!(afs_indexFlags[i] & IFEverUsed))
2598 continue; /* never had any data */
2599 tdc = afs_GetDSlot(i, NULL);
2600 if (tdc->refCount <= 1) { /* too high, in use by running sys call */
2601 ReleaseReadLock(&tdc->tlock);
2602 if (tdc->f.fid.Fid.Volume == volume && tdc->f.fid.Cell == cell) {
2603 if (!(afs_indexFlags[i] & IFDataMod)) {
2604 /* if the file is modified, but has a ref cnt of only 1, then
2605 * someone probably has the file open and is writing into it.
2606 * Better to skip flushing such a file, it will be brought back
2607 * immediately on the next write anyway.
2609 * If we *must* flush, then this code has to be rearranged to call
2610 * afs_storeAllSegments() first */
2611 afs_FlushDCache(tdc);
2615 ReleaseReadLock(&tdc->tlock);
2617 afs_PutDCache(tdc); /* bumped by getdslot */
2619 MReleaseWriteLock(&afs_xdcache);
2621 ObtainReadLock(&afs_xvolume);
2622 for (i = 0; i < NVOLS; i++) {
2623 for (tv = afs_volumes[i]; tv; tv = tv->next) {
2624 if (tv->volume == volume) {
2625 afs_ResetVolumeInfo(tv);
2630 ReleaseReadLock(&afs_xvolume);
2632 /* probably, a user is doing this, probably, because things are screwed up.
2633 * maybe it's the dnlc's fault? */
2640 DECL_PIOCTL(PGetVnodeXStatus)
2642 register afs_int32 code;
2643 struct vcxstat stat;
2646 /* AFS_STATCNT(PGetVnodeXStatus); */
2649 code = afs_VerifyVCache(avc, areq);
2652 if (vType(avc) == VDIR)
2653 mode = PRSFS_LOOKUP;
2656 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
2658 stat.fid = avc->fid;
2659 hset32(stat.DataVersion, hgetlo(avc->m.DataVersion));
2660 stat.lock = avc->lock;
2661 stat.parentVnode = avc->parentVnode;
2662 stat.parentUnique = avc->parentUnique;
2663 hset(stat.flushDV, avc->flushDV);
2664 hset(stat.mapDV, avc->mapDV);
2665 stat.truncPos = avc->truncPos;
2666 { /* just grab the first two - won't break anything... */
2667 struct axscache *ac;
2669 for (i = 0, ac = avc->Access; ac && i < CPSIZE; i++, ac = ac->next) {
2670 stat.randomUid[i] = ac->uid;
2671 stat.randomAccess[i] = ac->axess;
2674 stat.callback = afs_data_pointer_to_int32(avc->callback);
2675 stat.cbExpires = avc->cbExpires;
2676 stat.anyAccess = avc->anyAccess;
2677 stat.opens = avc->opens;
2678 stat.execsOrWriters = avc->execsOrWriters;
2679 stat.flockCount = avc->flockCount;
2680 stat.mvstat = avc->mvstat;
2681 stat.states = avc->states;
2682 memcpy(aout, (char *)&stat, sizeof(struct vcxstat));
2683 *aoutSize = sizeof(struct vcxstat);
2688 /* We require root for local sysname changes, but not for remote */
2689 /* (since we don't really believe remote uids anyway) */
2690 /* outname[] shouldn't really be needed- this is left as an excercise */
2691 /* for the reader. */
2692 DECL_PIOCTL(PSetSysName)
2694 char *cp, *cp2, inname[MAXSYSNAME], outname[MAXSYSNAME];
2695 int setsysname, foundname = 0;
2696 register struct afs_exporter *exporter;
2697 register struct unixuser *au;
2698 register afs_int32 pag, error;
2699 int t, count, num = 0;
2700 char **sysnamelist[MAXSYSNAME];
2702 AFS_STATCNT(PSetSysName);
2703 if (!afs_globalVFS) {
2704 /* Afsd is NOT running; disable it */
2705 #if defined(KERNEL_HAVE_UERROR)
2706 return (setuerror(EINVAL), EINVAL);
2711 memset(inname, 0, MAXSYSNAME);
2712 memcpy((char *)&setsysname, ain, sizeof(afs_int32));
2713 ain += sizeof(afs_int32);
2717 if (setsysname < 0 || setsysname > MAXNUMSYSNAMES)
2720 for (cp = ain, count = 0; count < setsysname; count++) {
2721 /* won't go past end of ain since maxsysname*num < ain length */
2723 if (t >= MAXSYSNAME || t <= 0)
2725 /* check for names that can shoot us in the foot */
2726 if (*cp == '.' && (cp[1] == 0 || (cp[1] == '.' && cp[2] == 0)))
2732 /* inname gets first entry in case we're being a translator */
2734 memcpy(inname, ain, t + 1); /* include terminating null */
2738 if ((*acred)->cr_gid == RMTUSER_REQ) { /* Handles all exporters */
2739 pag = PagInCred(*acred);
2741 return EINVAL; /* Better than panicing */
2743 if (!(au = afs_FindUser(pag, -1, READ_LOCK))) {
2744 return EINVAL; /* Better than panicing */
2746 if (!(exporter = au->exporter)) {
2747 afs_PutUser(au, READ_LOCK);
2748 return EINVAL; /* Better than panicing */
2750 error = EXP_SYSNAME(exporter, (setsysname ? cp2 : NULL), sysnamelist,
2753 if (error == ENODEV)
2754 foundname = 0; /* sysname not set yet! */
2756 afs_PutUser(au, READ_LOCK);
2761 strcpy(outname, (*sysnamelist)[0]);
2763 afs_PutUser(au, READ_LOCK);
2765 /* Not xlating, so local case */
2767 osi_Panic("PSetSysName: !afs_sysname\n");
2768 if (!setsysname) { /* user just wants the info */
2769 strcpy(outname, afs_sysname);
2770 foundname = afs_sysnamecount;
2771 *sysnamelist = afs_sysnamelist;
2772 } else { /* Local guy; only root can change sysname */
2773 if (!afs_osi_suser(*acred))
2776 /* clear @sys entries from the dnlc, once afs_lookup can
2777 * do lookups of @sys entries and thinks it can trust them */
2778 /* privs ok, store the entry, ... */
2779 strcpy(afs_sysname, inname);
2780 if (setsysname > 1) { /* ... or list */
2782 for (count = 1; count < setsysname; ++count) {
2783 if (!afs_sysnamelist[count])
2785 ("PSetSysName: no afs_sysnamelist entry to write\n");
2787 memcpy(afs_sysnamelist[count], cp, t + 1); /* include null */
2791 afs_sysnamecount = setsysname;
2795 cp = aout; /* not changing so report back the count and ... */
2796 memcpy(cp, (char *)&foundname, sizeof(afs_int32));
2797 cp += sizeof(afs_int32);
2799 strcpy(cp, outname); /* ... the entry, ... */
2800 cp += strlen(outname) + 1;
2801 for (count = 1; count < foundname; ++count) { /* ... or list. */
2802 if (!(*sysnamelist)[count])
2804 ("PSetSysName: no afs_sysnamelist entry to read\n");
2805 t = strlen((*sysnamelist)[count]);
2806 if (t >= MAXSYSNAME)
2807 osi_Panic("PSetSysName: sysname entry garbled\n");
2808 strcpy(cp, (*sysnamelist)[count]);
2812 *aoutSize = cp - aout;
2817 /* sequential search through the list of touched cells is not a good
2818 * long-term solution here. For small n, though, it should be just
2819 * fine. Should consider special-casing the local cell for large n.
2820 * Likewise for PSetSPrefs.
2822 * s - number of ids in array l[] -- NOT index of last id
2823 * l - array of cell ids which have volumes that need to be sorted
2824 * vlonly - sort vl servers or file servers?
2827 ReSortCells_cb(struct cell *cell, void *arg)
2829 afs_int32 *p = (afs_int32 *) arg;
2830 afs_int32 *l = p + 1;
2833 for (i = 0; i < s; i++) {
2834 if (l[i] == cell->cellNum) {
2835 ObtainWriteLock(&cell->lock, 690);
2836 afs_SortServers(cell->cellHosts, MAXCELLHOSTS);
2837 ReleaseWriteLock(&cell->lock);
2845 ReSortCells(int s, afs_int32 * l, int vlonly)
2853 p = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * (s + 1));
2855 memcpy(p + 1, l, s * sizeof(afs_int32));
2856 afs_TraverseCells(&ReSortCells_cb, p);
2857 afs_osi_Free(p, sizeof(afs_int32) * (s + 1));
2861 ObtainReadLock(&afs_xvolume);
2862 for (i = 0; i < NVOLS; i++) {
2863 for (j = afs_volumes[i]; j; j = j->next) {
2864 for (k = 0; k < s; k++)
2865 if (j->cell == l[k]) {
2866 ObtainWriteLock(&j->lock, 233);
2867 afs_SortServers(j->serverHost, MAXHOSTS);
2868 ReleaseWriteLock(&j->lock);
2873 ReleaseReadLock(&afs_xvolume);
2877 static int debugsetsp = 0;
2879 afs_setsprefs(sp, num, vlonly)
2882 unsigned int vlonly;
2885 int i, j, k, matches, touchedSize;
2886 struct server *srvr = NULL;
2887 afs_int32 touched[34];
2891 for (k = 0; k < num; sp++, k++) {
2893 printf("sp host=%x, rank=%d\n", sp->host.s_addr, sp->rank);
2896 ObtainReadLock(&afs_xserver);
2898 i = SHash(sp->host.s_addr);
2899 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2900 if (sa->sa_ip == sp->host.s_addr) {
2902 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
2903 || (sa->sa_portal == AFS_FSPORT);
2904 if ((!vlonly && isfs) || (vlonly && !isfs)) {
2911 if (sa && matches) { /* found one! */
2913 printf("sa ip=%x, ip_rank=%d\n", sa->sa_ip, sa->sa_iprank);
2915 sa->sa_iprank = sp->rank + afs_randomMod15();
2916 afs_SortOneServer(sa->server);
2919 /* if we don't know yet what cell it's in, this is moot */
2920 for (j = touchedSize - 1;
2921 j >= 0 && touched[j] != srvr->cell->cellNum; j--)
2922 /* is it in our list of touched cells ? */ ;
2923 if (j < 0) { /* no, it's not */
2924 touched[touchedSize++] = srvr->cell->cellNum;
2925 if (touchedSize >= 32) { /* watch for ovrflow */
2926 ReleaseReadLock(&afs_xserver);
2927 ReSortCells(touchedSize, touched, vlonly);
2929 ObtainReadLock(&afs_xserver);
2935 ReleaseReadLock(&afs_xserver);
2936 /* if we didn't find one, start to create one. */
2937 /* Note that it doesn't have a cell yet... */
2939 afs_uint32 temp = sp->host.s_addr;
2941 afs_GetServer(&temp, 1, 0, (vlonly ? AFS_VLPORT : AFS_FSPORT),
2942 WRITE_LOCK, (afsUUID *) 0, 0);
2943 srvr->addr->sa_iprank = sp->rank + afs_randomMod15();
2944 afs_PutServer(srvr, WRITE_LOCK);
2946 } /* for all cited preferences */
2948 ReSortCells(touchedSize, touched, vlonly);
2952 /* Note that this may only be performed by the local root user.
2954 DECL_PIOCTL(PSetSPrefs)
2956 struct setspref *ssp;
2957 AFS_STATCNT(PSetSPrefs);
2959 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2960 return EIO; /* Inappropriate ioctl for device */
2962 if (!afs_osi_suser(*acred))
2965 if (ainSize < sizeof(struct setspref))
2968 ssp = (struct setspref *)ain;
2969 if (ainSize < sizeof(struct spref) * ssp->num_servers)
2972 afs_setsprefs(&(ssp->servers[0]), ssp->num_servers,
2973 (ssp->flags & DBservers));
2977 DECL_PIOCTL(PSetSPrefs33)
2980 AFS_STATCNT(PSetSPrefs);
2981 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2982 return EIO; /* Inappropriate ioctl for device */
2985 if (!afs_osi_suser(*acred))
2988 sp = (struct spref *)ain;
2989 afs_setsprefs(sp, ainSize / (sizeof(struct spref)), 0 /*!vlonly */ );
2993 /* some notes on the following code...
2994 * in the hash table of server structs, all servers with the same IP address
2995 * will be on the same overflow chain.
2996 * This could be sped slightly in some circumstances by having it cache the
2997 * immediately previous slot in the hash table and some supporting information
2998 * Only reports file servers now.
3000 DECL_PIOCTL(PGetSPrefs)
3002 struct sprefrequest *spin; /* input */
3003 struct sprefinfo *spout; /* output */
3004 struct spref *srvout; /* one output component */
3005 int i, j; /* counters for hash table traversal */
3006 struct server *srvr; /* one of CM's server structs */
3008 int vlonly; /* just return vlservers ? */
3011 AFS_STATCNT(PGetSPrefs);
3012 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3013 return EIO; /* Inappropriate ioctl for device */
3016 if (ainSize < sizeof(struct sprefrequest_33)) {
3019 spin = ((struct sprefrequest *)ain);
3022 if (ainSize > sizeof(struct sprefrequest_33)) {
3023 vlonly = (spin->flags & DBservers);
3027 /* struct sprefinfo includes 1 server struct... that size gets added
3028 * in during the loop that follows.
3030 *aoutSize = sizeof(struct sprefinfo) - sizeof(struct spref);
3031 spout = (struct sprefinfo *)aout;
3032 spout->next_offset = spin->offset;
3033 spout->num_servers = 0;
3034 srvout = spout->servers;
3036 ObtainReadLock(&afs_xserver);
3037 for (i = 0, j = 0; j < NSERVERS; j++) { /* sift through hash table */
3038 for (sa = afs_srvAddrs[j]; sa; sa = sa->next_bkt, i++) {
3039 if (spin->offset > (unsigned short)i) {
3040 continue; /* catch up to where we left off */
3042 spout->next_offset++;
3045 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
3046 || (sa->sa_portal == AFS_FSPORT);
3048 if ((vlonly && isfs) || (!vlonly && !isfs)) {
3049 /* only report ranks for vl servers */
3053 srvout->host.s_addr = sa->sa_ip;
3054 srvout->rank = sa->sa_iprank;
3055 *aoutSize += sizeof(struct spref);
3056 spout->num_servers++;
3059 if (*aoutSize > (PIGGYSIZE - sizeof(struct spref))) {
3060 ReleaseReadLock(&afs_xserver); /* no more room! */
3065 ReleaseReadLock(&afs_xserver);
3067 spout->next_offset = 0; /* start over from the beginning next time */
3071 /* Enable/Disable the specified exporter. Must be root to disable an exporter */
3072 int afs_NFSRootOnly = 1;
3073 DECL_PIOCTL(PExportAfs)
3075 afs_int32 export, newint =
3076 0, type, changestate, handleValue, convmode, pwsync, smounts;
3077 register struct afs_exporter *exporter;
3079 AFS_STATCNT(PExportAfs);
3080 memcpy((char *)&handleValue, ain, sizeof(afs_int32));
3081 type = handleValue >> 24;
3086 exporter = exporter_find(type);
3088 export = handleValue & 3;
3089 changestate = handleValue & 0xff;
3090 smounts = (handleValue >> 2) & 3;
3091 pwsync = (handleValue >> 4) & 3;
3092 convmode = (handleValue >> 6) & 3;
3094 changestate = (handleValue >> 16) & 0x1;
3095 convmode = (handleValue >> 16) & 0x2;
3096 pwsync = (handleValue >> 16) & 0x4;
3097 smounts = (handleValue >> 16) & 0x8;
3098 export = handleValue & 0xff;
3101 /* Failed finding desired exporter; */
3105 handleValue = exporter->exp_states;
3106 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3107 *aoutSize = sizeof(afs_int32);
3109 if (!afs_osi_suser(*acred))
3110 return EACCES; /* Only superuser can do this */
3114 exporter->exp_states |= EXP_EXPORTED;
3116 exporter->exp_states &= ~EXP_EXPORTED;
3120 exporter->exp_states |= EXP_UNIXMODE;
3122 exporter->exp_states &= ~EXP_UNIXMODE;
3126 exporter->exp_states |= EXP_PWSYNC;
3128 exporter->exp_states &= ~EXP_PWSYNC;
3132 afs_NFSRootOnly = 0;
3133 exporter->exp_states |= EXP_SUBMOUNTS;
3135 afs_NFSRootOnly = 1;
3136 exporter->exp_states &= ~EXP_SUBMOUNTS;
3139 handleValue = exporter->exp_states;
3140 memcpy(aout, (char *)&handleValue, sizeof(afs_int32));
3141 *aoutSize = sizeof(afs_int32);
3144 exporter->exp_states |= EXP_EXPORTED;
3146 exporter->exp_states &= ~EXP_EXPORTED;
3148 exporter->exp_states |= EXP_UNIXMODE;
3150 exporter->exp_states &= ~EXP_UNIXMODE;
3152 exporter->exp_states |= EXP_PWSYNC;
3154 exporter->exp_states &= ~EXP_PWSYNC;
3156 afs_NFSRootOnly = 0;
3157 exporter->exp_states |= EXP_SUBMOUNTS;
3159 afs_NFSRootOnly = 1;
3160 exporter->exp_states &= ~EXP_SUBMOUNTS;
3170 struct gaginfo *gagflags;
3172 if (!afs_osi_suser(*acred))
3175 gagflags = (struct gaginfo *)ain;
3176 afs_showflags = gagflags->showflags;
3182 DECL_PIOCTL(PTwiddleRx)
3184 struct rxparams *rxp;
3186 if (!afs_osi_suser(*acred))
3189 rxp = (struct rxparams *)ain;
3191 if (rxp->rx_initReceiveWindow)
3192 rx_initReceiveWindow = rxp->rx_initReceiveWindow;
3193 if (rxp->rx_maxReceiveWindow)
3194 rx_maxReceiveWindow = rxp->rx_maxReceiveWindow;
3195 if (rxp->rx_initSendWindow)
3196 rx_initSendWindow = rxp->rx_initSendWindow;
3197 if (rxp->rx_maxSendWindow)
3198 rx_maxSendWindow = rxp->rx_maxSendWindow;
3199 if (rxp->rxi_nSendFrags)
3200 rxi_nSendFrags = rxp->rxi_nSendFrags;
3201 if (rxp->rxi_nRecvFrags)
3202 rxi_nRecvFrags = rxp->rxi_nRecvFrags;
3203 if (rxp->rxi_OrphanFragSize)
3204 rxi_OrphanFragSize = rxp->rxi_OrphanFragSize;
3205 if (rxp->rx_maxReceiveSize) {
3206 rx_maxReceiveSize = rxp->rx_maxReceiveSize;
3207 rx_maxReceiveSizeUser = rxp->rx_maxReceiveSize;
3209 if (rxp->rx_MyMaxSendSize)
3210 rx_MyMaxSendSize = rxp->rx_MyMaxSendSize;
3215 DECL_PIOCTL(PGetInitParams)
3217 if (sizeof(struct cm_initparams) > PIGGYSIZE)
3220 memcpy(aout, (char *)&cm_initParams, sizeof(struct cm_initparams));
3221 *aoutSize = sizeof(struct cm_initparams);
3225 #ifdef AFS_SGI65_ENV
3226 /* They took crget() from us, so fake it. */
3231 cr = crdup(get_current_cred());
3232 memset((char *)cr, 0, sizeof(cred_t));
3233 #if CELL || CELL_PREPARE
3240 DECL_PIOCTL(PGetRxkcrypt)
3242 memcpy(aout, (char *)&cryptall, sizeof(afs_int32));
3243 *aoutSize = sizeof(afs_int32);
3247 DECL_PIOCTL(PSetRxkcrypt)
3251 if (!afs_osi_suser(*acred))
3253 if (ainSize != sizeof(afs_int32) || ain == NULL)
3255 memcpy((char *)&tmpval, ain, sizeof(afs_int32));
3256 /* if new mappings added later this will need to be changed */
3257 if (tmpval != 0 && tmpval != 1)
3263 #ifdef AFS_NEED_CLIENTCONTEXT
3265 * Create new credentials to correspond to a remote user with given
3266 * <hostaddr, uid, g0, g1>. This allows a server running as root to
3267 * provide pioctl (and other) services to foreign clients (i.e. nfs
3268 * clients) by using this call to `become' the client.
3271 #define PIOCTL_HEADER 6
3273 HandleClientContext(struct afs_ioctl *ablob, int *com,
3274 struct AFS_UCRED **acred, struct AFS_UCRED *credp)
3277 afs_uint32 hostaddr;
3278 afs_int32 uid, g0, g1, i, code, pag, exporter_type;
3279 struct afs_exporter *exporter, *outexporter;
3280 struct AFS_UCRED *newcred;
3281 struct unixuser *au;
3283 #if defined(AFS_SGIMP_ENV)
3284 osi_Assert(ISAFS_GLOCK());
3286 AFS_STATCNT(HandleClientContext);
3287 if (ablob->in_size < PIOCTL_HEADER * sizeof(afs_int32)) {
3288 /* Must at least include the PIOCTL_HEADER header words required by the protocol */
3289 return EINVAL; /* Too small to be good */
3291 ain = inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
3292 AFS_COPYIN(ablob->in, ain, PIOCTL_HEADER * sizeof(afs_int32), code);
3294 osi_FreeLargeSpace(inData);
3298 /* Extract information for remote user */
3299 hostaddr = *((afs_uint32 *) ain);
3300 ain += sizeof(hostaddr);
3301 uid = *((afs_uint32 *) ain);
3303 g0 = *((afs_uint32 *) ain);
3305 g1 = *((afs_uint32 *) ain);
3307 *com = *((afs_uint32 *) ain);
3308 ain += sizeof(afs_int32);
3309 exporter_type = *((afs_uint32 *) ain); /* In case we support more than NFS */
3312 * Of course, one must be root for most of these functions, but
3313 * we'll allow (for knfs) you to set things if the pag is 0 and
3314 * you're setting tokens or unlogging.
3317 if (!afs_osi_suser(credp)) {
3318 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
3319 /* Since SGI's suser() returns explicit failure after the call.. */
3322 /* check for acceptable opcodes for normal folks, which are, so far,
3323 * set tokens and unlog.
3325 if (i != 9 && i != 3 && i != 38 && i != 8) {
3326 osi_FreeLargeSpace(inData);
3331 ablob->in_size -= PIOCTL_HEADER * sizeof(afs_int32);
3332 ablob->in += PIOCTL_HEADER * sizeof(afs_int32);
3333 osi_FreeLargeSpace(inData);
3336 * We map uid 0 to nobody to match the mapping that the nfs
3337 * server does and to ensure that the suser() calls in the afs
3338 * code fails for remote client roots.
3340 uid = afs_nobody; /* NFS_NOBODY == -2 */
3343 #ifdef AFS_AIX41_ENV
3346 newcred->cr_gid = RMTUSER_REQ;
3347 #ifdef AFS_AIX51_ENV
3348 newcred->cr_groupset.gs_union.un_groups[0] = g0;
3349 newcred->cr_groupset.gs_union.un_groups[1] = g1;
3351 newcred->cr_groups[0] = g0;
3352 newcred->cr_groups[1] = g1;
3355 newcred->cr_ngrps = 2;
3357 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV)
3358 newcred->cr_ngroups = 2;
3360 for (i = 2; i < NGROUPS; i++)
3361 newcred->cr_groups[i] = NOGROUP;
3364 #if !defined(AFS_OSF_ENV) && !defined(AFS_DEC_ENV)
3365 afs_nfsclient_init(); /* before looking for exporter, ensure one exists */
3367 if (!(exporter = exporter_find(exporter_type))) {
3368 /* Exporter wasn't initialized or an invalid exporter type */
3372 if (exporter->exp_states & EXP_PWSYNC) {
3373 if (uid != credp->cr_uid) {
3375 return ENOEXEC; /* XXX Find a better errno XXX */
3378 newcred->cr_uid = uid; /* Only temporary */
3379 code = EXP_REQHANDLER(exporter, &newcred, hostaddr, &pag, &outexporter);
3380 /* The client's pag is the only unique identifier for it */
3381 newcred->cr_uid = pag;
3383 if (!code && *com == PSETPAG) {
3384 /* Special case for 'setpag' */
3385 afs_uint32 pagvalue = genpag();
3387 au = afs_GetUser(pagvalue, -1, WRITE_LOCK); /* a new unixuser struct */
3389 * Note that we leave the 'outexporter' struct held so it won't
3392 au->exporter = outexporter;
3393 if (ablob->out_size >= 4) {
3394 AFS_COPYOUT((char *)&pagvalue, ablob->out, sizeof(afs_int32),
3397 afs_PutUser(au, WRITE_LOCK);
3400 return PSETPAG; /* Special return for setpag */
3402 EXP_RELE(outexporter);
3406 #endif /* AFS_NEED_CLIENTCONTEXT */
3408 /* get all interface addresses of this client */
3410 DECL_PIOCTL(PGetCPrefs)
3412 struct sprefrequest *spin; /* input */
3413 struct sprefinfo *spout; /* output */
3414 struct spref *srvout; /* one output component */
3418 AFS_STATCNT(PGetCPrefs);
3419 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3420 return EIO; /* Inappropriate ioctl for device */
3422 if (ainSize < sizeof(struct sprefrequest))
3425 spin = (struct sprefrequest *)ain;
3426 spout = (struct sprefinfo *)aout;
3428 maxNumber = spin->num_servers; /* max addrs this time */
3429 srvout = spout->servers;
3431 ObtainReadLock(&afs_xinterface);
3433 /* copy out the client interface information from the
3434 ** kernel data structure "interface" to the output buffer
3436 for (i = spin->offset, j = 0; (i < afs_cb_interface.numberOfInterfaces)
3437 && (j < maxNumber); i++, j++, srvout++)
3438 srvout->host.s_addr = afs_cb_interface.addr_in[i];
3440 spout->num_servers = j;
3441 *aoutSize = sizeof(struct sprefinfo) + (j - 1) * sizeof(struct spref);
3443 if (i >= afs_cb_interface.numberOfInterfaces)
3444 spout->next_offset = 0; /* start from beginning again */
3446 spout->next_offset = spin->offset + j;
3448 ReleaseReadLock(&afs_xinterface);
3452 DECL_PIOCTL(PSetCPrefs)
3454 struct setspref *sin;
3457 AFS_STATCNT(PSetCPrefs);
3458 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3459 return EIO; /* Inappropriate ioctl for device */
3461 sin = (struct setspref *)ain;
3463 if (ainSize < sizeof(struct setspref))
3465 #if 0 /* num_servers is unsigned */
3466 if (sin->num_servers < 0)
3469 if (sin->num_servers > AFS_MAX_INTERFACE_ADDR)
3472 ObtainWriteLock(&afs_xinterface, 412);
3473 afs_cb_interface.numberOfInterfaces = sin->num_servers;
3474 for (i = 0; (unsigned short)i < sin->num_servers; i++)
3475 afs_cb_interface.addr_in[i] = sin->servers[i].host.s_addr;
3477 ReleaseWriteLock(&afs_xinterface);
3481 DECL_PIOCTL(PFlushMount)
3483 register afs_int32 code;
3484 register struct vcache *tvc;
3485 register struct dcache *tdc;
3486 struct VenusFid tfid;
3488 struct sysname_info sysState;
3489 afs_size_t offset, len;
3491 AFS_STATCNT(PFlushMount);
3494 code = afs_VerifyVCache(avc, areq);
3497 if (vType(avc) != VDIR) {
3500 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
3503 Check_AtSys(avc, ain, &sysState, areq);
3504 ObtainReadLock(&tdc->lock);
3506 code = afs_dir_Lookup(&tdc->f, sysState.name, &tfid.Fid);
3507 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
3508 ReleaseReadLock(&tdc->lock);
3509 afs_PutDCache(tdc); /* we're done with the data */
3510 bufp = sysState.name;
3514 tfid.Cell = avc->fid.Cell;
3515 tfid.Fid.Volume = avc->fid.Fid.Volume;
3516 if (!tfid.Fid.Unique && (avc->states & CForeign)) {
3517 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
3519 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3525 if (tvc->mvstat != 1) {
3530 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
3531 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
3533 ObtainWriteLock(&tvc->lock, 649);
3534 ObtainWriteLock(&afs_xcbhash, 650);
3535 afs_DequeueCallback(tvc);
3536 tvc->states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
3537 ReleaseWriteLock(&afs_xcbhash);
3538 /* now find the disk cache entries */
3539 afs_TryToSmush(tvc, *acred, 1);
3540 osi_dnlc_purgedp(tvc);
3541 afs_symhint_inval(tvc);
3542 if (tvc->linkData && !(tvc->states & CCore)) {
3543 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
3544 tvc->linkData = NULL;
3546 ReleaseWriteLock(&tvc->lock);
3547 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
3548 afs_BozonUnlock(&tvc->pvnLock, tvc);
3552 if (sysState.allocked)
3553 osi_FreeLargeSpace(bufp);
3557 DECL_PIOCTL(PRxStatProc)
3562 if (!afs_osi_suser(*acred)) {
3566 if (ainSize != sizeof(afs_int32)) {
3570 memcpy((char *)&flags, ain, sizeof(afs_int32));
3571 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3575 if (flags & AFSCALL_RXSTATS_ENABLE) {
3576 rx_enableProcessRPCStats();
3578 if (flags & AFSCALL_RXSTATS_DISABLE) {
3579 rx_disableProcessRPCStats();
3581 if (flags & AFSCALL_RXSTATS_CLEAR) {
3582 rx_clearProcessRPCStats(AFS_RX_STATS_CLEAR_ALL);
3590 DECL_PIOCTL(PRxStatPeer)
3595 if (!afs_osi_suser(*acred)) {
3599 if (ainSize != sizeof(afs_int32)) {
3603 memcpy((char *)&flags, ain, sizeof(afs_int32));
3604 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK)) {
3608 if (flags & AFSCALL_RXSTATS_ENABLE) {
3609 rx_enablePeerRPCStats();
3611 if (flags & AFSCALL_RXSTATS_DISABLE) {
3612 rx_disablePeerRPCStats();
3614 if (flags & AFSCALL_RXSTATS_CLEAR) {
3615 rx_clearPeerRPCStats(AFS_RX_STATS_CLEAR_ALL);
3622 DECL_PIOCTL(PPrefetchFromTape)
3624 register afs_int32 code, code1;
3627 struct rx_call *tcall;
3628 struct AFSVolSync tsync;
3629 struct AFSFetchStatus OutStatus;
3630 struct AFSCallBack CallBack;
3631 struct VenusFid tfid;
3635 AFS_STATCNT(PSetAcl);
3639 if (ain && (ainSize == 3 * sizeof(afs_int32)))
3640 Fid = (struct AFSFid *)ain;
3642 Fid = &avc->fid.Fid;
3643 tfid.Cell = avc->fid.Cell;
3644 tfid.Fid.Volume = Fid->Volume;
3645 tfid.Fid.Vnode = Fid->Vnode;
3646 tfid.Fid.Unique = Fid->Unique;
3648 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3650 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3651 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &avc->fid);
3654 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
3655 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &tvc->fid);
3658 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3662 tcall = rx_NewCall(tc->id);
3664 StartRXAFS_FetchData(tcall, (struct AFSFid *)&tvc->fid.Fid, 0,
3667 bytes = rx_Read(tcall, (char *)aout, sizeof(afs_int32));
3669 EndRXAFS_FetchData(tcall, &OutStatus, &CallBack, &tsync);
3671 code1 = rx_EndCall(tcall, code);
3675 } while (afs_Analyze
3676 (tc, code, &tvc->fid, areq, AFS_STATS_FS_RPCIDX_RESIDENCYRPCS,
3677 SHARED_LOCK, NULL));
3678 /* This call is done only to have the callback things handled correctly */
3679 afs_FetchStatus(tvc, &tfid, areq, &OutStatus);
3683 *aoutSize = sizeof(afs_int32);
3688 DECL_PIOCTL(PResidencyCmd)
3690 register afs_int32 code;
3693 struct ResidencyCmdInputs *Inputs;
3694 struct ResidencyCmdOutputs *Outputs;
3695 struct VenusFid tfid;
3698 Inputs = (struct ResidencyCmdInputs *)ain;
3699 Outputs = (struct ResidencyCmdOutputs *)aout;
3702 if (!ain || ainSize != sizeof(struct ResidencyCmdInputs))
3707 Fid = &avc->fid.Fid;
3709 tfid.Cell = avc->fid.Cell;
3710 tfid.Fid.Volume = Fid->Volume;
3711 tfid.Fid.Vnode = Fid->Vnode;
3712 tfid.Fid.Unique = Fid->Unique;
3714 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3715 afs_Trace3(afs_iclSetp, CM_TRACE_RESIDCMD, ICL_TYPE_POINTER, tvc,
3716 ICL_TYPE_INT32, Inputs->command, ICL_TYPE_FID, &tfid);
3720 if (Inputs->command) {
3722 tc = afs_Conn(&tvc->fid, areq, SHARED_LOCK);
3726 RXAFS_ResidencyCmd(tc->id, Fid, Inputs,
3727 (struct ResidencyCmdOutputs *)aout);
3731 } while (afs_Analyze
3732 (tc, code, &tvc->fid, areq,
3733 AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK, NULL));
3734 /* This call is done to have the callback things handled correctly */
3735 afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3736 } else { /* just a status request, return also link data */
3738 Outputs->code = afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
3739 Outputs->chars[0] = 0;
3740 if (vType(tvc) == VLNK) {
3741 ObtainWriteLock(&tvc->lock, 555);
3742 if (afs_HandleLink(tvc, areq) == 0)
3743 strncpy((char *)&Outputs->chars, tvc->linkData, MAXCMDCHARS);