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"
14 #include "afs/sysincludes.h" /* Standard vendor system headers */
16 #include "h/syscallargs.h"
19 #include "h/sysproto.h"
22 #include <sys/ioctl.h>
23 #include <sys/ioccom.h>
25 #include "afsincludes.h" /* Afs-based standard headers */
26 #include "afs/afs_stats.h" /* afs statistics */
28 #include "afs/afs_bypasscache.h"
29 #include "rx/rx_globals.h"
31 struct VenusFid afs_rootFid;
32 afs_int32 afs_waitForever = 0;
33 short afs_waitForeverCount = 0;
34 afs_int32 afs_showflags = GAGUSER | GAGCONSOLE; /* show all messages */
36 afs_int32 afs_is_disconnected;
37 afs_int32 afs_is_discon_rw;
38 /* On reconnection, turn this knob on until it finishes,
41 afs_int32 afs_in_sync = 0;
49 * A set of handy little functions for encoding and decoding
50 * pioctls without losing your marbles, or memory integrity
54 afs_pd_alloc(struct afs_pdata *apd, size_t size)
57 if (size > AFS_LRALLOCSIZ)
58 apd->ptr = osi_Alloc(size + 1);
60 apd->ptr = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
65 apd->remaining = size;
71 afs_pd_free(struct afs_pdata *apd)
76 if (apd->remaining > AFS_LRALLOCSIZ)
77 osi_Free(apd->ptr, apd->remaining + 1);
79 osi_FreeLargeSpace(apd->ptr);
86 afs_pd_where(struct afs_pdata *apd)
88 return apd ? apd->ptr : NULL;
92 afs_pd_remaining(struct afs_pdata *apd)
94 return apd ? apd->remaining : 0;
98 afs_pd_skip(struct afs_pdata *apd, size_t skip)
100 if (apd == NULL || apd->remaining < skip)
102 apd->remaining -= skip;
109 afs_pd_getInt(struct afs_pdata *apd, afs_int32 *val)
111 if (apd == NULL || apd->remaining < sizeof(afs_int32))
113 apd->remaining -= sizeof(afs_int32);
114 *val = *(afs_int32 *)apd->ptr;
115 apd->ptr += sizeof(afs_int32);
120 afs_pd_getUint(struct afs_pdata *apd, afs_uint32 *val)
122 return afs_pd_getInt(apd, (afs_int32 *)val);
126 afs_pd_getBytes(struct afs_pdata *apd, void *dest, size_t bytes)
128 if (apd == NULL || apd->remaining < bytes)
130 apd->remaining -= bytes;
131 memcpy(dest, apd->ptr, bytes);
137 afs_pd_inline(struct afs_pdata *apd, size_t bytes)
141 if (apd == NULL || apd->remaining < bytes)
146 apd->remaining -= bytes;
153 afs_pd_getString(struct afs_pdata *apd, char *str, size_t maxLen)
157 if (apd == NULL || apd->remaining <= 0)
159 len = strlen(apd->ptr) + 1;
162 memcpy(str, apd->ptr, len);
164 apd->remaining -= len;
169 afs_pd_getStringPtr(struct afs_pdata *apd, char **str)
173 if (apd == NULL || apd->remaining <= 0)
175 len = strlen(apd->ptr) + 1;
178 apd->remaining -= len;
183 afs_pd_putInt(struct afs_pdata *apd, afs_int32 val)
185 if (apd == NULL || apd->remaining < sizeof(afs_int32))
187 *(afs_int32 *)apd->ptr = val;
188 apd->ptr += sizeof(afs_int32);
189 apd->remaining -= sizeof(afs_int32);
195 afs_pd_putBytes(struct afs_pdata *apd, const void *bytes, size_t len)
197 if (apd == NULL || apd->remaining < len)
199 memcpy(apd->ptr, bytes, len);
201 apd->remaining -= len;
206 afs_pd_putString(struct afs_pdata *apd, char *str) {
208 /* Add 1 so we copy the NULL too */
209 return afs_pd_putBytes(apd, str, strlen(str) +1);
213 * \defgroup pioctl Path IOCTL functions
215 * DECL_PIOCTL is a macro defined to contain the following parameters for functions:
218 * the AFS vcache structure in use by pioctl
222 * the AFS vrequest structure
224 * an afs_pdata block describing the data received from the caller
226 * an afs_pdata block describing a pre-allocated block for output
228 * UNIX credentials structure underlying the operation
231 #define DECL_PIOCTL(x) \
232 static int x(struct vcache *avc, int afun, struct vrequest *areq, \
233 struct afs_pdata *ain, struct afs_pdata *aout, \
236 /* Prototypes for pioctl routines */
237 DECL_PIOCTL(PGetFID);
238 DECL_PIOCTL(PSetAcl);
239 DECL_PIOCTL(PStoreBehind);
240 DECL_PIOCTL(PGCPAGs);
241 DECL_PIOCTL(PGetAcl);
244 DECL_PIOCTL(PGetFileCell);
245 DECL_PIOCTL(PGetWSCell);
246 DECL_PIOCTL(PGetUserCell);
247 DECL_PIOCTL(PSetTokens);
248 DECL_PIOCTL(PGetVolumeStatus);
249 DECL_PIOCTL(PSetVolumeStatus);
251 DECL_PIOCTL(PNewStatMount);
252 DECL_PIOCTL(PGetTokens);
254 DECL_PIOCTL(PMariner);
255 DECL_PIOCTL(PCheckServers);
256 DECL_PIOCTL(PCheckVolNames);
257 DECL_PIOCTL(PCheckAuth);
258 DECL_PIOCTL(PFindVolume);
259 DECL_PIOCTL(PViceAccess);
260 DECL_PIOCTL(PSetCacheSize);
261 DECL_PIOCTL(PGetCacheSize);
262 DECL_PIOCTL(PRemoveCallBack);
263 DECL_PIOCTL(PNewCell);
264 DECL_PIOCTL(PNewAlias);
265 DECL_PIOCTL(PListCells);
266 DECL_PIOCTL(PListAliases);
267 DECL_PIOCTL(PRemoveMount);
268 DECL_PIOCTL(PGetCellStatus);
269 DECL_PIOCTL(PSetCellStatus);
270 DECL_PIOCTL(PFlushVolumeData);
271 DECL_PIOCTL(PGetVnodeXStatus);
272 DECL_PIOCTL(PGetVnodeXStatus2);
273 DECL_PIOCTL(PSetSysName);
274 DECL_PIOCTL(PSetSPrefs);
275 DECL_PIOCTL(PSetSPrefs33);
276 DECL_PIOCTL(PGetSPrefs);
277 DECL_PIOCTL(PExportAfs);
279 DECL_PIOCTL(PTwiddleRx);
280 DECL_PIOCTL(PGetInitParams);
281 DECL_PIOCTL(PGetRxkcrypt);
282 DECL_PIOCTL(PSetRxkcrypt);
283 DECL_PIOCTL(PGetCPrefs);
284 DECL_PIOCTL(PSetCPrefs);
285 DECL_PIOCTL(PFlushMount);
286 DECL_PIOCTL(PRxStatProc);
287 DECL_PIOCTL(PRxStatPeer);
288 DECL_PIOCTL(PPrefetchFromTape);
290 DECL_PIOCTL(PCallBackAddr);
291 DECL_PIOCTL(PDiscon);
292 DECL_PIOCTL(PNFSNukeCreds);
293 DECL_PIOCTL(PNewUuid);
294 DECL_PIOCTL(PPrecache);
295 DECL_PIOCTL(PGetPAG);
296 #if defined(AFS_CACHE_BYPASS)
297 DECL_PIOCTL(PSetCachingThreshold);
301 * A macro that says whether we're going to need HandleClientContext().
302 * This is currently used only by the nfs translator.
304 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
305 #define AFS_NEED_CLIENTCONTEXT
308 /* Prototypes for private routines */
309 #ifdef AFS_NEED_CLIENTCONTEXT
310 static int HandleClientContext(struct afs_ioctl *ablob, int *com,
314 int HandleIoctl(register struct vcache *avc, register afs_int32 acom,
315 struct afs_ioctl *adata);
316 int afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
317 register struct afs_ioctl *ablob, int afollow,
318 afs_ucred_t **acred);
319 static int Prefetch(uparmtype apath, struct afs_ioctl *adata, int afollow,
322 typedef int (*pioctlFunction) (struct vcache *, int, struct vrequest *,
323 struct afs_pdata *, struct afs_pdata *,
326 static pioctlFunction VpioctlSw[] = {
331 PGetVolumeStatus, /* 4 */
332 PSetVolumeStatus, /* 5 */
337 PCheckServers, /* 10 */
338 PCheckVolNames, /* 11 */
340 PBogus, /* 13 -- used to be quick check time */
341 PFindVolume, /* 14 */
342 PBogus, /* 15 -- prefetch is now special-cased; see pioctl code! */
343 PBogus, /* 16 -- used to be testing code */
344 PNoop, /* 17 -- used to be enable group */
345 PNoop, /* 18 -- used to be disable group */
346 PBogus, /* 19 -- used to be list group */
347 PViceAccess, /* 20 */
348 PUnlog, /* 21 -- unlog *is* unpag in this system */
349 PGetFID, /* 22 -- get file ID */
350 PBogus, /* 23 -- used to be waitforever */
351 PSetCacheSize, /* 24 */
352 PRemoveCallBack, /* 25 -- flush only the callback */
355 PRemoveMount, /* 28 -- delete mount point */
356 PNewStatMount, /* 29 -- new style mount point stat */
357 PGetFileCell, /* 30 -- get cell name for input file */
358 PGetWSCell, /* 31 -- get cell name for workstation */
359 PMariner, /* 32 - set/get mariner host */
360 PGetUserCell, /* 33 -- get cell name for user */
361 PBogus, /* 34 -- Enable/Disable logging */
362 PGetCellStatus, /* 35 */
363 PSetCellStatus, /* 36 */
364 PFlushVolumeData, /* 37 -- flush all data from a volume */
365 PSetSysName, /* 38 - Set system name */
366 PExportAfs, /* 39 - Export Afs to remote nfs clients */
367 PGetCacheSize, /* 40 - get cache size and usage */
368 PGetVnodeXStatus, /* 41 - get vcache's special status */
369 PSetSPrefs33, /* 42 - Set CM Server preferences... */
370 PGetSPrefs, /* 43 - Get CM Server preferences... */
371 PGag, /* 44 - turn off/on all CM messages */
372 PTwiddleRx, /* 45 - adjust some RX params */
373 PSetSPrefs, /* 46 - Set CM Server preferences... */
374 PStoreBehind, /* 47 - set degree of store behind to be done */
375 PGCPAGs, /* 48 - disable automatic pag gc-ing */
376 PGetInitParams, /* 49 - get initial cm params */
377 PGetCPrefs, /* 50 - get client interface addresses */
378 PSetCPrefs, /* 51 - set client interface addresses */
379 PFlushMount, /* 52 - flush mount symlink data */
380 PRxStatProc, /* 53 - control process RX statistics */
381 PRxStatPeer, /* 54 - control peer RX statistics */
382 PGetRxkcrypt, /* 55 -- Get rxkad encryption flag */
383 PSetRxkcrypt, /* 56 -- Set rxkad encryption flag */
384 PBogus, /* 57 -- arla: set file prio */
385 PBogus, /* 58 -- arla: fallback getfh */
386 PBogus, /* 59 -- arla: fallback fhopen */
387 PBogus, /* 60 -- arla: controls xfsdebug */
388 PBogus, /* 61 -- arla: controls arla debug */
389 PBogus, /* 62 -- arla: debug interface */
390 PBogus, /* 63 -- arla: print xfs status */
391 PBogus, /* 64 -- arla: force cache check */
392 PBogus, /* 65 -- arla: break callback */
393 PPrefetchFromTape, /* 66 -- MR-AFS: prefetch file from tape */
394 PFsCmd, /* 67 -- RXOSD: generic commnd interface */
395 PBogus, /* 68 -- arla: fetch stats */
396 PGetVnodeXStatus2, /* 69 - get caller access and some vcache status */
399 static pioctlFunction CpioctlSw[] = {
401 PNewAlias, /* 1 -- create new cell alias */
402 PListAliases, /* 2 -- list cell aliases */
403 PCallBackAddr, /* 3 -- request addr for callback rxcon */
405 PDiscon, /* 5 -- get/set discon mode */
416 static pioctlFunction OpioctlSw[] = {
418 PNFSNukeCreds, /* 1 -- nuke all creds for NFS client */
419 #if defined(AFS_CACHE_BYPASS)
420 PSetCachingThreshold /* 2 -- get/set cache-bypass size threshold */
422 PNoop /* 2 -- get/set cache-bypass size threshold */
426 #define PSetClientContext 99 /* Special pioctl to setup caller's creds */
427 int afs_nobody = NFS_NOBODY;
430 HandleIoctl(register struct vcache *avc, register afs_int32 acom,
431 struct afs_ioctl *adata)
433 register afs_int32 code;
436 AFS_STATCNT(HandleIoctl);
438 switch (acom & 0xff) {
440 avc->f.states |= CSafeStore;
442 /* SXW - Should we force a MetaData flush for this flag setting */
445 /* case 2 used to be abort store, but this is no longer provided,
446 * since it is impossible to implement under normal Unix.
450 /* return the name of the cell this file is open on */
451 register struct cell *tcell;
452 register afs_int32 i;
454 tcell = afs_GetCell(avc->f.fid.Cell, READ_LOCK);
456 i = strlen(tcell->cellName) + 1; /* bytes to copy out */
458 if (i > adata->out_size) {
459 /* 0 means we're not interested in the output */
460 if (adata->out_size != 0)
464 AFS_COPYOUT(tcell->cellName, adata->out, i, code);
466 afs_PutCell(tcell, READ_LOCK);
472 case 49: /* VIOC_GETINITPARAMS */
473 if (adata->out_size < sizeof(struct cm_initparams)) {
476 AFS_COPYOUT(&cm_initParams, adata->out,
477 sizeof(struct cm_initparams), code);
489 return code; /* so far, none implemented */
493 /* For aix we don't temporarily bypass ioctl(2) but rather do our
494 * thing directly in the vnode layer call, VNOP_IOCTL; thus afs_ioctl
495 * is now called from afs_gn_ioctl.
498 afs_ioctl(struct vcache *tvc, int cmd, int arg)
500 struct afs_ioctl data;
503 AFS_STATCNT(afs_ioctl);
504 if (((cmd >> 8) & 0xff) == 'V') {
505 /* This is a VICEIOCTL call */
506 AFS_COPYIN(arg, (caddr_t) & data, sizeof(data), error);
509 error = HandleIoctl(tvc, cmd, &data);
512 /* No-op call; just return. */
516 # if defined(AFS_AIX32_ENV)
517 # if defined(AFS_AIX51_ENV)
520 kioctl(int fdes, int com, caddr_t arg, caddr_t ext, caddr_t arg2,
522 # else /* __64BIT__ */
524 kioctl32(int fdes, int com, caddr_t arg, caddr_t ext, caddr_t arg2,
526 # endif /* __64BIT__ */
529 kioctl(int fdes, int com, caddr_t arg, caddr_t ext)
530 # endif /* AFS_AIX51_ENV */
535 # ifdef AFS_AIX51_ENV
538 } u_uap, *uap = &u_uap;
540 register struct vcache *tvc;
541 register int ioctlDone = 0, code = 0;
543 AFS_STATCNT(afs_xioctl);
547 # ifdef AFS_AIX51_ENV
551 if (setuerror(getf(uap->fd, &fd))) {
554 if (fd->f_type == DTYPE_VNODE) {
555 /* good, this is a vnode; next see if it is an AFS vnode */
556 tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */
557 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
558 /* This is an AFS vnode */
559 if (((uap->com >> 8) & 0xff) == 'V') {
560 register struct afs_ioctl *datap;
563 (struct afs_ioctl *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
564 code=copyin_afs_ioctl((char *)uap->arg, datap);
566 osi_FreeSmallSpace(datap);
568 # if defined(AFS_AIX41_ENV)
571 return (setuerror(code), code);
573 code = HandleIoctl(tvc, uap->com, datap);
574 osi_FreeSmallSpace(datap);
577 # if defined(AFS_AIX41_ENV)
584 # if defined(AFS_AIX41_ENV)
586 # if defined(AFS_AIX51_ENV)
588 code = okioctl(fdes, com, arg, ext, arg2, arg3);
589 # else /* __64BIT__ */
590 code = okioctl32(fdes, com, arg, ext, arg2, arg3);
591 # endif /* __64BIT__ */
592 # else /* !AFS_AIX51_ENV */
593 code = okioctl(fdes, com, arg, ext);
594 # endif /* AFS_AIX51_ENV */
596 # elif defined(AFS_AIX32_ENV)
597 okioctl(fdes, com, arg, ext);
600 # if defined(KERNEL_HAVE_UERROR)
603 # if !defined(AFS_AIX41_ENV)
604 return (getuerror()? -1 : u.u_ioctlrv);
606 return getuerror()? -1 : 0;
613 #elif defined(AFS_SGI_ENV)
614 # if defined(AFS_SGI65_ENV)
615 afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
616 rval_t * rvalp, struct vopbd * vbds)
618 afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
619 rval_t * rvalp, struct vopbd * vbds)
622 struct afs_ioctl data;
628 AFS_STATCNT(afs_ioctl);
629 if (((cmd >> 8) & 0xff) == 'V') {
630 /* This is a VICEIOCTL call */
631 error = copyin_afs_ioctl(arg, &data);
634 locked = ISAFS_GLOCK();
637 error = HandleIoctl(tvc, cmd, &data);
642 /* No-op call; just return. */
646 #elif defined(AFS_SUN5_ENV)
647 struct afs_ioctl_sys {
654 afs_xioctl(struct afs_ioctl_sys *uap, rval_t *rvp)
657 register struct vcache *tvc;
658 register int ioctlDone = 0, code = 0;
660 AFS_STATCNT(afs_xioctl);
661 # if defined(AFS_SUN57_ENV)
665 # elif defined(AFS_SUN54_ENV)
670 if (code = getf(uap->fd, &fd)) {
674 if (fd->f_vnode->v_type == VREG || fd->f_vnode->v_type == VDIR) {
675 tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */
676 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
677 /* This is an AFS vnode */
678 if (((uap->com >> 8) & 0xff) == 'V') {
679 register struct afs_ioctl *datap;
682 (struct afs_ioctl *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
683 code=copyin_afs_ioctl((char *)uap->arg, datap);
685 osi_FreeSmallSpace(datap);
687 # if defined(AFS_SUN54_ENV)
694 code = HandleIoctl(tvc, uap->com, datap);
695 osi_FreeSmallSpace(datap);
701 # if defined(AFS_SUN57_ENV)
703 # elif defined(AFS_SUN54_ENV)
709 code = ioctl(uap, rvp);
713 #elif defined(AFS_LINUX22_ENV)
714 struct afs_ioctl_sys {
719 afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
722 struct afs_ioctl_sys ua, *uap = &ua;
723 register struct vcache *tvc;
724 register int ioctlDone = 0, code = 0;
726 AFS_STATCNT(afs_xioctl);
731 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
732 /* This is an AFS vnode */
733 if (((uap->com >> 8) & 0xff) == 'V') {
734 register struct afs_ioctl *datap;
736 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
737 code = copyin_afs_ioctl((char *)uap->arg, datap);
739 osi_FreeSmallSpace(datap);
743 code = HandleIoctl(tvc, uap->com, datap);
744 osi_FreeSmallSpace(datap);
753 #elif defined(AFS_DARWIN_ENV) && !defined(AFS_DARWIN80_ENV)
761 afs_xioctl(afs_proc_t *p, register struct ioctl_args *uap, register_t *retval)
764 register struct vcache *tvc;
765 register int ioctlDone = 0, code = 0;
767 AFS_STATCNT(afs_xioctl);
768 if ((code = fdgetf(p, uap->fd, &fd)))
770 if (fd->f_type == DTYPE_VNODE) {
771 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
772 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
773 /* This is an AFS vnode */
774 if (((uap->com >> 8) & 0xff) == 'V') {
775 register struct afs_ioctl *datap;
777 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
778 code = copyin_afs_ioctl((char *)uap->arg, datap);
780 osi_FreeSmallSpace(datap);
784 code = HandleIoctl(tvc, uap->com, datap);
785 osi_FreeSmallSpace(datap);
793 return ioctl(p, uap, retval);
797 #elif defined(AFS_XBSD_ENV)
798 # if defined(AFS_FBSD_ENV)
801 afs_xioctl(struct thread *td, register struct ioctl_args *uap,
804 afs_proc_t *p = td->td_proc;
813 afs_xioctl(afs_proc_t *p, register struct ioctl_args *uap, register_t *retval)
816 register struct filedesc *fdp;
817 register struct vcache *tvc;
818 register int ioctlDone = 0, code = 0;
821 AFS_STATCNT(afs_xioctl);
822 # if defined(AFS_NBSD40_ENV)
823 fdp = p->l_proc->p_fd;
827 if ((u_int) uap->fd >= fdp->fd_nfiles
828 || (fd = fdp->fd_ofiles[uap->fd]) == NULL)
830 if ((fd->f_flag & (FREAD | FWRITE)) == 0)
832 /* first determine whether this is any sort of vnode */
833 if (fd->f_type == DTYPE_VNODE) {
834 /* good, this is a vnode; next see if it is an AFS vnode */
835 # if defined(AFS_OBSD_ENV)
837 IsAfsVnode((struct vnode *)fd->
838 f_data) ? VTOAFS((struct vnode *)fd->f_data) : NULL;
840 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
842 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
843 /* This is an AFS vnode */
844 if (((uap->com >> 8) & 0xff) == 'V') {
845 register struct afs_ioctl *datap;
847 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
848 code = copyin_afs_ioctl((char *)uap->arg, datap);
850 osi_FreeSmallSpace(datap);
854 code = HandleIoctl(tvc, uap->com, datap);
855 osi_FreeSmallSpace(datap);
863 # if defined(AFS_FBSD_ENV)
864 return ioctl(td, uap);
865 # elif defined(AFS_OBSD_ENV)
866 code = sys_ioctl(p, uap, retval);
867 # elif defined(AFS_NBSD_ENV)
868 struct lwp *l = osi_curproc();
869 code = sys_ioctl(l, uap, retval);
875 #elif defined(UKERNEL)
883 } *uap = (struct a *)get_user_struct()->u_ap;
884 register struct file *fd;
885 register struct vcache *tvc;
886 register int ioctlDone = 0, code = 0;
888 AFS_STATCNT(afs_xioctl);
893 /* first determine whether this is any sort of vnode */
894 if (fd->f_type == DTYPE_VNODE) {
895 /* good, this is a vnode; next see if it is an AFS vnode */
896 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
897 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
898 /* This is an AFS vnode */
899 if (((uap->com >> 8) & 0xff) == 'V') {
900 register struct afs_ioctl *datap;
902 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
903 code=copyin_afs_ioctl((char *)uap->arg, datap);
905 osi_FreeSmallSpace(datap);
908 return (setuerror(code), code);
910 code = HandleIoctl(tvc, uap->com, datap);
911 osi_FreeSmallSpace(datap);
924 #endif /* AFS_HPUX102_ENV */
926 #if defined(AFS_SGI_ENV)
927 /* "pioctl" system call entry point; just pass argument to the parameterized
936 afs_pioctl(struct pioctlargs *uap, rval_t * rvp)
940 AFS_STATCNT(afs_pioctl);
942 code = afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow);
944 # ifdef AFS_SGI64_ENV
951 #elif defined(AFS_FBSD_ENV)
953 afs_pioctl(struct thread *td, void *args, int *retval)
960 } *uap = (struct a *)args;
962 AFS_STATCNT(afs_pioctl);
963 return (afs_syscall_pioctl
964 (uap->path, uap->cmd, uap->cmarg, uap->follow, td->td_ucred));
967 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
969 afs_pioctl(afs_proc_t *p, void *args, int *retval)
976 } *uap = (struct a *)args;
978 AFS_STATCNT(afs_pioctl);
979 # if defined(AFS_DARWIN80_ENV) || defined(AFS_NBSD40_ENV)
980 return (afs_syscall_pioctl
981 (uap->path, uap->cmd, uap->cmarg, uap->follow,
984 return (afs_syscall_pioctl
985 (uap->path, uap->cmd, uap->cmarg, uap->follow,
986 # if defined(AFS_FBSD_ENV)
989 p->p_cred->pc_ucred));
996 /* macro to avoid adding any more #ifdef's to pioctl code. */
997 #if defined(AFS_LINUX22_ENV) || defined(AFS_AIX41_ENV)
998 #define PIOCTL_FREE_CRED() crfree(credp)
1000 #define PIOCTL_FREE_CRED()
1005 afs_syscall_pioctl(char *path, unsigned int com, caddr_t cmarg, int follow,
1006 rval_t *vvp, afs_ucred_t *credp)
1008 #ifdef AFS_DARWIN100_ENV
1009 afs_syscall64_pioctl(user_addr_t path, unsigned int com, user_addr_t cmarg,
1010 int follow, afs_ucred_t *credp)
1011 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1012 afs_syscall_pioctl(char *path, unsigned int com, caddr_t cmarg, int follow,
1015 afs_syscall_pioctl(char *path, unsigned int com, caddr_t cmarg, int follow)
1019 struct afs_ioctl data;
1020 #ifdef AFS_NEED_CLIENTCONTEXT
1021 afs_ucred_t *tmpcred = NULL;
1023 #if defined(AFS_NEED_CLIENTCONTEXT) || defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1024 afs_ucred_t *foreigncreds = NULL;
1026 register afs_int32 code = 0;
1027 struct vnode *vp = NULL;
1028 #ifdef AFS_AIX41_ENV
1029 struct ucred *credp = crref(); /* don't free until done! */
1031 #ifdef AFS_LINUX22_ENV
1032 cred_t *credp = crref(); /* don't free until done! */
1036 AFS_STATCNT(afs_syscall_pioctl);
1038 follow = 1; /* compat. with old venus */
1039 code = copyin_afs_ioctl(cmarg, &data);
1042 #if defined(KERNEL_HAVE_UERROR)
1047 if ((com & 0xff) == PSetClientContext) {
1048 #ifdef AFS_NEED_CLIENTCONTEXT
1049 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV)
1050 code = HandleClientContext(&data, &com, &foreigncreds, credp);
1052 code = HandleClientContext(&data, &com, &foreigncreds, osi_curcred());
1056 crfree(foreigncreds);
1059 #if defined(KERNEL_HAVE_UERROR)
1060 return (setuerror(code), code);
1065 #else /* AFS_NEED_CLIENTCONTEXT */
1067 #endif /* AFS_NEED_CLIENTCONTEXT */
1069 #ifdef AFS_NEED_CLIENTCONTEXT
1072 * We could have done without temporary setting the u.u_cred below
1073 * (foreigncreds could be passed as param the pioctl modules)
1074 * but calls such as afs_osi_suser() doesn't allow that since it
1075 * references u.u_cred directly. We could, of course, do something
1076 * like afs_osi_suser(cred) which, I think, is better since it
1077 * generalizes and supports multi cred environments...
1079 #if defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
1081 credp = foreigncreds;
1082 #elif defined(AFS_AIX41_ENV)
1083 tmpcred = crref(); /* XXX */
1084 crset(foreigncreds);
1085 #elif defined(AFS_HPUX101_ENV)
1086 tmpcred = p_cred(u.u_procp);
1087 set_p_cred(u.u_procp, foreigncreds);
1088 #elif defined(AFS_SGI_ENV)
1089 tmpcred = OSI_GET_CURRENT_CRED();
1090 OSI_SET_CURRENT_CRED(foreigncreds);
1093 u.u_cred = foreigncreds;
1096 #endif /* AFS_NEED_CLIENTCONTEXT */
1097 if ((com & 0xff) == 15) {
1098 /* special case prefetch so entire pathname eval occurs in helper process.
1099 * otherwise, the pioctl call is essentially useless */
1100 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1102 Prefetch(path, &data, follow,
1103 foreigncreds ? foreigncreds : credp);
1105 code = Prefetch(path, &data, follow, osi_curcred());
1108 #if defined(KERNEL_HAVE_UERROR)
1115 #ifdef AFS_AIX41_ENV
1117 lookupname(path, USR, follow, NULL, &vp,
1118 foreigncreds ? foreigncreds : credp);
1120 #ifdef AFS_LINUX22_ENV
1121 code = gop_lookupname_user(path, AFS_UIOUSER, follow, &dp);
1123 vp = (struct vnode *)dp->d_inode;
1125 code = gop_lookupname_user(path, AFS_UIOUSER, follow, &vp);
1126 #if defined(AFS_FBSD80_ENV) /* XXX check on 7x */
1129 #endif /* AFS_FBSD80_ENV */
1130 #endif /* AFS_LINUX22_ENV */
1131 #endif /* AFS_AIX41_ENV */
1135 #if defined(KERNEL_HAVE_UERROR)
1143 #if defined(AFS_SUN510_ENV)
1144 if (vp && !IsAfsVnode(vp)) {
1145 struct vnode *realvp;
1147 #ifdef AFS_SUN511_ENV
1148 (VOP_REALVP(vp, &realvp, NULL) == 0)
1150 (VOP_REALVP(vp, &realvp) == 0)
1153 struct vnode *oldvp = vp;
1161 /* now make the call if we were passed no file, or were passed an AFS file */
1162 if (!vp || IsAfsVnode(vp)) {
1163 #if defined(AFS_SUN5_ENV)
1164 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1165 #elif defined(AFS_AIX41_ENV)
1167 struct ucred *cred1, *cred2;
1170 cred1 = cred2 = foreigncreds;
1172 cred1 = cred2 = credp;
1174 code = afs_HandlePioctl(vp, com, &data, follow, &cred1);
1175 if (cred1 != cred2) {
1176 /* something changed the creds */
1180 #elif defined(AFS_HPUX101_ENV)
1182 struct ucred *cred = p_cred(u.u_procp);
1183 code = afs_HandlePioctl(vp, com, &data, follow, &cred);
1185 #elif defined(AFS_SGI_ENV)
1188 credp = OSI_GET_CURRENT_CRED();
1189 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1191 #elif defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1192 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1193 #elif defined(UKERNEL)
1194 code = afs_HandlePioctl(vp, com, &data, follow,
1195 &(get_user_struct()->u_cred));
1197 code = afs_HandlePioctl(vp, com, &data, follow, &u.u_cred);
1200 #if defined(KERNEL_HAVE_UERROR)
1203 code = EINVAL; /* not in /afs */
1208 #if defined(AFS_NEED_CLIENTCONTEXT)
1210 #ifdef AFS_AIX41_ENV
1211 crset(tmpcred); /* restore original credentials */
1213 #if defined(AFS_HPUX101_ENV)
1214 set_p_cred(u.u_procp, tmpcred); /* restore original credentials */
1215 #elif defined(AFS_SGI_ENV)
1216 OSI_SET_CURRENT_CRED(tmpcred); /* restore original credentials */
1217 #elif defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
1218 credp = tmpcred; /* restore original credentials */
1220 osi_curcred() = tmpcred; /* restore original credentials */
1221 #endif /* AFS_HPUX101_ENV */
1222 crfree(foreigncreds);
1225 #endif /* AFS_NEED_CLIENTCONTEXT */
1227 #ifdef AFS_LINUX22_ENV
1230 #if defined(AFS_FBSD80_ENV)
1231 if (VOP_ISLOCKED(vp))
1233 #endif /* AFS_FBSD80_ENV */
1234 AFS_RELE(vp); /* put vnode back */
1238 #if defined(KERNEL_HAVE_UERROR)
1241 return (getuerror());
1247 #ifdef AFS_DARWIN100_ENV
1249 afs_syscall_pioctl(char * path, unsigned int com, caddr_t cmarg,
1250 int follow, afs_ucred_t *credp)
1252 return afs_syscall64_pioctl(CAST_USER_ADDR_T(path), com,
1253 CAST_USER_ADDR_T((unsigned int)cmarg), follow,
1258 #define MAXPIOCTLTOKENLEN \
1259 (3*sizeof(afs_int32)+MAXKTCTICKETLEN+sizeof(struct ClearToken)+MAXKTCREALMLEN)
1262 afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
1263 register struct afs_ioctl *ablob, int afollow,
1264 afs_ucred_t **acred)
1267 struct vrequest treq;
1268 register afs_int32 code;
1269 register afs_int32 function, device;
1270 struct afs_pdata input, output;
1271 struct afs_pdata copyInput, copyOutput;
1273 pioctlFunction *pioctlSw;
1275 struct afs_fakestat_state fakestate;
1277 memset(&input, 0, sizeof(input));
1278 memset(&output, 0, sizeof(output));
1280 avc = avp ? VTOAFS(avp) : NULL;
1281 afs_Trace3(afs_iclSetp, CM_TRACE_PIOCTL, ICL_TYPE_INT32, acom & 0xff,
1282 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, afollow);
1283 AFS_STATCNT(HandlePioctl);
1285 code = afs_InitReq(&treq, *acred);
1289 afs_InitFakeStat(&fakestate);
1291 code = afs_EvalFakeStat(&avc, &fakestate, &treq);
1295 device = (acom & 0xff00) >> 8;
1297 case 'V': /* Original pioctls */
1298 pioctlSw = VpioctlSw;
1299 pioctlSwSize = sizeof(VpioctlSw);
1301 case 'C': /* Coordinated/common pioctls */
1302 pioctlSw = CpioctlSw;
1303 pioctlSwSize = sizeof(CpioctlSw);
1305 case 'O': /* Coordinated/common pioctls */
1306 pioctlSw = OpioctlSw;
1307 pioctlSwSize = sizeof(OpioctlSw);
1313 function = acom & 0xff;
1314 if (function >= (pioctlSwSize / sizeof(char *))) {
1319 /* Do all range checking before continuing */
1320 if (ablob->in_size > MAXPIOCTLTOKENLEN ||
1321 ablob->in_size < 0 || ablob->out_size < 0) {
1326 code = afs_pd_alloc(&input, ablob->in_size);
1330 if (ablob->in_size > 0) {
1331 AFS_COPYIN(ablob->in, input.ptr, ablob->in_size, code);
1332 input.ptr[input.remaining] = '\0';
1337 if (function == 8 && device == 'V') { /* PGetTokens */
1338 code = afs_pd_alloc(&output, MAXPIOCTLTOKENLEN);
1340 code = afs_pd_alloc(&output, AFS_LRALLOCSIZ);
1346 copyOutput = output;
1349 (*pioctlSw[function]) (avc, function, &treq, ©Input,
1350 ©Output, acred);
1352 outSize = copyOutput.ptr - output.ptr;
1354 if (code == 0 && ablob->out_size > 0) {
1355 if (outSize > ablob->out_size) {
1356 code = E2BIG; /* data wont fit in user buffer */
1357 } else if (outSize) {
1358 AFS_COPYOUT(output.ptr, ablob->out, outSize, code);
1363 afs_pd_free(&input);
1364 afs_pd_free(&output);
1366 afs_PutFakeStat(&fakestate);
1367 return afs_CheckCode(code, &treq, 41);
1371 * VIOCGETFID (22) - Get file ID quickly
1375 * \param[in] ain not in use
1376 * \param[out] aout fid of requested file
1378 * \retval EINVAL Error if some of the initial arguments aren't set
1380 * \post get the file id of some file
1382 DECL_PIOCTL(PGetFID)
1384 AFS_STATCNT(PGetFID);
1387 if (afs_pd_putBytes(aout, &avc->f.fid, sizeof(struct VenusFid)) != 0)
1393 * VIOCSETAL (1) - Set access control list
1397 * \param[in] ain the ACL being set
1398 * \param[out] aout the ACL being set returned
1400 * \retval EINVAL Error if some of the standard args aren't set
1402 * \post Changed ACL, via direct writing to the wire
1405 dummy_PSetAcl(char *ain, char *aout)
1410 DECL_PIOCTL(PSetAcl)
1412 register afs_int32 code;
1413 struct afs_conn *tconn;
1414 struct AFSOpaque acl;
1415 struct AFSVolSync tsync;
1416 struct AFSFetchStatus OutStatus;
1419 AFS_STATCNT(PSetAcl);
1423 if (afs_pd_getStringPtr(ain, &acl.AFSOpaque_val) != 0)
1425 acl.AFSOpaque_len = strlen(acl.AFSOpaque_val) + 1;
1426 if (acl.AFSOpaque_len > 1024)
1430 tconn = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
1432 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREACL);
1435 RXAFS_StoreACL(tconn->id, (struct AFSFid *)&avc->f.fid.Fid,
1436 &acl, &OutStatus, &tsync);
1441 } while (afs_Analyze
1442 (tconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_STOREACL,
1443 SHARED_LOCK, NULL));
1445 /* now we've forgotten all of the access info */
1446 ObtainWriteLock(&afs_xcbhash, 455);
1448 afs_DequeueCallback(avc);
1449 avc->f.states &= ~(CStatd | CUnique);
1450 ReleaseWriteLock(&afs_xcbhash);
1451 if (avc->f.fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
1452 osi_dnlc_purgedp(avc);
1454 /* SXW - Should we flush metadata here? */
1458 int afs_defaultAsynchrony = 0;
1461 * VIOC_STOREBEHIND (47) Adjust store asynchrony
1465 * \param[in] ain sbstruct (store behind structure) input
1466 * \param[out] aout resulting sbstruct
1469 * Error if the user doesn't have super-user credentials
1471 * Error if there isn't enough access to not check the mode bits
1474 * Changes either the default asynchrony (the amount of data that
1475 * can remain to be written when the cache manager returns control
1476 * to the user), or the asyncrony for the specified file.
1478 DECL_PIOCTL(PStoreBehind)
1480 struct sbstruct sbr;
1482 if (afs_pd_getBytes(ain, &sbr, sizeof(struct sbstruct)) != 0)
1485 if (sbr.sb_default != -1) {
1486 if (afs_osi_suser(*acred))
1487 afs_defaultAsynchrony = sbr.sb_default;
1492 if (avc && (sbr.sb_thisfile != -1)) {
1494 (avc, PRSFS_WRITE | PRSFS_ADMINISTER, areq, DONT_CHECK_MODE_BITS))
1495 avc->asynchrony = sbr.sb_thisfile;
1500 memset(&sbr, 0, sizeof(sbr));
1501 sbr.sb_default = afs_defaultAsynchrony;
1503 sbr.sb_thisfile = avc->asynchrony;
1506 return afs_pd_putBytes(aout, &sbr, sizeof(sbr));
1510 * VIOC_GCPAGS (48) - Disable automatic PAG gc'ing
1514 * \param[in] ain not in use
1515 * \param[out] aout not in use
1517 * \retval EACCES Error if the user doesn't have super-user credentials
1519 * \post set the gcpags to GCPAGS_USERDISABLED
1521 DECL_PIOCTL(PGCPAGs)
1523 if (!afs_osi_suser(*acred)) {
1526 afs_gcpags = AFS_GCPAGS_USERDISABLED;
1531 * VIOCGETAL (2) - Get access control list
1535 * \param[in] ain not in use
1536 * \param[out] aout the ACL
1538 * \retval EINVAL Error if some of the standard args aren't set
1539 * \retval ERANGE Error if the vnode of the file id is too large
1540 * \retval -1 Error if getting the ACL failed
1542 * \post Obtain the ACL, based on file ID
1545 * There is a hack to tell which type of ACL is being returned, checks
1546 * the top 2-bytes of the input size to judge what type of ACL it is,
1547 * only for dfs xlator ACLs
1549 DECL_PIOCTL(PGetAcl)
1551 struct AFSOpaque acl;
1552 struct AFSVolSync tsync;
1553 struct AFSFetchStatus OutStatus;
1555 struct afs_conn *tconn;
1559 AFS_STATCNT(PGetAcl);
1562 Fid.Volume = avc->f.fid.Fid.Volume;
1563 Fid.Vnode = avc->f.fid.Fid.Vnode;
1564 Fid.Unique = avc->f.fid.Fid.Unique;
1565 if (avc->f.states & CForeign) {
1567 * For a dfs xlator acl we have a special hack so that the
1568 * xlator will distinguish which type of acl will return. So
1569 * we currently use the top 2-bytes (vals 0-4) to tell which
1570 * type of acl to bring back. Horrible hack but this will
1571 * cause the least number of changes to code size and interfaces.
1573 if (Fid.Vnode & 0xc0000000)
1575 Fid.Vnode |= (ain->remaining << 30);
1577 acl.AFSOpaque_val = aout->ptr;
1579 tconn = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
1581 acl.AFSOpaque_val[0] = '\0';
1582 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHACL);
1584 code = RXAFS_FetchACL(tconn->id, &Fid, &acl, &OutStatus, &tsync);
1589 } while (afs_Analyze
1590 (tconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_FETCHACL,
1591 SHARED_LOCK, NULL));
1594 if (acl.AFSOpaque_len == 0)
1595 afs_pd_skip(aout, 1); /* leave the NULL */
1597 afs_pd_skip(aout, acl.AFSOpaque_len); /* Length of the ACL */
1603 * PNoop returns success. Used for functions which are not implemented
1604 * or are no longer in use.
1608 * \retval Always returns success
1611 * Functions involved in this:
1612 * 17 (VIOCENGROUP) -- used to be enable group;
1613 * 18 (VIOCDISGROUP) -- used to be disable group;
1614 * 2 (?) -- get/set cache-bypass size threshold
1623 * PBogus returns fail. Used for functions which are not implemented or
1624 * are no longer in use.
1628 * \retval EINVAL Always returns this value
1631 * Functions involved in this:
1637 * 13 (VIOCGETTIME) -- used to be quick check time;
1638 * 15 (VIOCPREFETCH) -- prefetch is now special-cased; see pioctl code!;
1639 * 16 (VIOCNOP) -- used to be testing code;
1640 * 19 (VIOCLISTGROUPS) -- used to be list group;
1641 * 23 (VIOCWAITFOREVER) -- used to be waitforever;
1642 * 57 (VIOC_FPRIOSTATUS) -- arla: set file prio;
1643 * 58 (VIOC_FHGET) -- arla: fallback getfh;
1644 * 59 (VIOC_FHOPEN) -- arla: fallback fhopen;
1645 * 60 (VIOC_XFSDEBUG) -- arla: controls xfsdebug;
1646 * 61 (VIOC_ARLADEBUG) -- arla: controls arla debug;
1647 * 62 (VIOC_AVIATOR) -- arla: debug interface;
1648 * 63 (VIOC_XFSDEBUG_PRINT) -- arla: print xfs status;
1649 * 64 (VIOC_CALCULATE_CACHE) -- arla: force cache check;
1650 * 65 (VIOC_BREAKCELLBACK) -- arla: break callback;
1651 * 68 (?) -- arla: fetch stats;
1655 AFS_STATCNT(PBogus);
1660 * VIOC_FILE_CELL_NAME (30) - Get cell in which file lives
1664 * \param[in] ain not in use (avc used to pass in file id)
1665 * \param[out] aout cell name
1667 * \retval EINVAL Error if some of the standard args aren't set
1668 * \retval ESRCH Error if the file isn't part of a cell
1670 * \post Get a cell based on a passed in file id
1672 DECL_PIOCTL(PGetFileCell)
1674 register struct cell *tcell;
1676 AFS_STATCNT(PGetFileCell);
1679 tcell = afs_GetCell(avc->f.fid.Cell, READ_LOCK);
1683 if (afs_pd_putString(aout, tcell->cellName) != 0)
1686 afs_PutCell(tcell, READ_LOCK);
1691 * VIOC_GET_WS_CELL (31) - Get cell in which workstation lives
1695 * \param[in] ain not in use
1696 * \param[out] aout cell name
1699 * Error if the afs daemon hasn't started yet
1701 * Error if the machine isn't part of a cell, for whatever reason
1703 * \post Get the primary cell that the machine is a part of.
1705 DECL_PIOCTL(PGetWSCell)
1707 struct cell *tcell = NULL;
1709 AFS_STATCNT(PGetWSCell);
1710 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1711 return EIO; /* Inappropriate ioctl for device */
1713 tcell = afs_GetPrimaryCell(READ_LOCK);
1714 if (!tcell) /* no primary cell? */
1717 if (afs_pd_putString(aout, tcell->cellName) != 0)
1719 afs_PutCell(tcell, READ_LOCK);
1724 * VIOC_GET_PRIMARY_CELL (33) - Get primary cell for caller
1728 * \param[in] ain not in use (user id found via areq)
1729 * \param[out] aout cell name
1732 * Error if the user id doesn't have a primary cell specified
1734 * \post Get the primary cell for a certain user, based on the user's uid
1736 DECL_PIOCTL(PGetUserCell)
1738 register afs_int32 i;
1739 register struct unixuser *tu;
1740 register struct cell *tcell;
1742 AFS_STATCNT(PGetUserCell);
1743 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1744 return EIO; /* Inappropriate ioctl for device */
1746 /* return the cell name of the primary cell for this user */
1747 i = UHash(areq->uid);
1748 ObtainWriteLock(&afs_xuser, 224);
1749 for (tu = afs_users[i]; tu; tu = tu->next) {
1750 if (tu->uid == areq->uid && (tu->states & UPrimary)) {
1752 ReleaseWriteLock(&afs_xuser);
1757 tcell = afs_GetCell(tu->cell, READ_LOCK);
1758 afs_PutUser(tu, WRITE_LOCK);
1762 if (afs_pd_putString(aout, tcell->cellName) != 0)
1764 afs_PutCell(tcell, READ_LOCK);
1767 ReleaseWriteLock(&afs_xuser);
1773 * VIOCSETTOK (3) - Set authentication tokens
1777 * \param[in] ain the krb tickets from which to set the afs tokens
1778 * \param[out] aout not in use
1781 * Error if the ticket is either too long or too short
1783 * Error if the AFS initState is below 101
1785 * Error if the cell for which the Token is being set can't be found
1788 * Set the Tokens for a specific cell name, unless there is none set,
1789 * then default to primary
1792 DECL_PIOCTL(PSetTokens)
1795 register struct unixuser *tu;
1796 struct ClearToken clear;
1797 register struct cell *tcell;
1801 struct vrequest treq;
1802 afs_int32 flag, set_parent_pag = 0;
1804 AFS_STATCNT(PSetTokens);
1805 if (!afs_resourceinit_flag) {
1809 if (afs_pd_getInt(ain, &stLen) != 0)
1812 stp = afs_pd_where(ain); /* remember where the ticket is */
1813 if (stLen < 0 || stLen > MAXKTCTICKETLEN)
1814 return EINVAL; /* malloc may fail */
1815 if (afs_pd_skip(ain, stLen) != 0)
1818 if (afs_pd_getInt(ain, &i) != 0)
1820 if (i != sizeof(struct ClearToken))
1823 if (afs_pd_getBytes(ain, &clear, sizeof(struct ClearToken)) !=0)
1826 if (clear.AuthHandle == -1)
1827 clear.AuthHandle = 999; /* more rxvab compat stuff */
1829 if (afs_pd_remaining(ain) != 0) {
1830 /* still stuff left? we've got primary flag and cell name.
1833 if (afs_pd_getInt(ain, &flag) != 0)
1836 /* some versions of gcc appear to need != 0 in order to get this
1838 if ((flag & 0x8000) != 0) { /* XXX Use Constant XXX */
1843 if (afs_pd_getStringPtr(ain, &cellName) != 0)
1846 /* rest is cell name, look it up */
1847 tcell = afs_GetCellByName(cellName, READ_LOCK);
1851 /* default to primary cell, primary id */
1852 flag = 1; /* primary id */
1853 tcell = afs_GetPrimaryCell(READ_LOCK);
1858 afs_PutCell(tcell, READ_LOCK);
1859 if (set_parent_pag) {
1861 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1863 osi_procname(procname, 256);
1864 afs_warnuser("Process %d (%s) tried to change pags in PSetTokens\n",
1865 MyPidxx2Pid(MyPidxx), procname);
1866 if (!setpag(osi_curproc(), acred, -1, &pag, 1)) {
1868 if (!setpag(acred, -1, &pag, 1)) {
1870 afs_InitReq(&treq, *acred);
1874 /* now we just set the tokens */
1875 tu = afs_GetUser(areq->uid, i, WRITE_LOCK); /* i has the cell # */
1876 tu->vid = clear.ViceId;
1877 if (tu->stp != NULL) {
1878 afs_osi_Free(tu->stp, tu->stLen);
1880 tu->stp = (char *)afs_osi_Alloc(stLen);
1881 if (tu->stp == NULL) {
1885 memcpy(tu->stp, stp, stLen);
1888 afs_stats_cmfullperf.authent.TicketUpdates++;
1889 afs_ComputePAGStats();
1890 #endif /* AFS_NOSTATS */
1891 tu->states |= UHasTokens;
1892 tu->states &= ~UTokensBad;
1893 afs_SetPrimary(tu, flag);
1894 tu->tokenTime = osi_Time();
1895 afs_ResetUserConns(tu);
1896 afs_NotifyUser(tu, UTokensObtained);
1897 afs_PutUser(tu, WRITE_LOCK);
1913 * VIOCGETVOLSTAT (4) - Get volume status
1917 * \param[in] ain not in use
1918 * \param[out] aout status of the volume
1920 * \retval EINVAL Error if some of the standard args aren't set
1923 * The status of a volume (based on the FID of the volume), or an
1924 * offline message /motd
1926 DECL_PIOCTL(PGetVolumeStatus)
1929 char *offLineMsg = afs_osi_Alloc(256);
1930 char *motd = afs_osi_Alloc(256);
1931 register struct afs_conn *tc;
1932 register afs_int32 code = 0;
1933 struct AFSFetchVolumeStatus volstat;
1937 AFS_STATCNT(PGetVolumeStatus);
1944 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
1946 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS);
1949 RXAFS_GetVolumeStatus(tc->id, avc->f.fid.Fid.Volume, &volstat,
1950 &Name, &offLineMsg, &motd);
1955 } while (afs_Analyze
1956 (tc, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS,
1957 SHARED_LOCK, NULL));
1961 /* Copy all this junk into msg->im_data, keeping track of the lengths. */
1962 if (afs_pd_putBytes(aout, &volstat, sizeof(VolumeStatus)) != 0)
1964 if (afs_pd_putString(aout, volName) != 0)
1966 if (afs_pd_putString(aout, offLineMsg) != 0)
1968 if (afs_pd_putString(aout, motd) != 0)
1971 afs_osi_Free(offLineMsg, 256);
1972 afs_osi_Free(motd, 256);
1977 * VIOCSETVOLSTAT (5) - Set volume status
1982 * values to set the status at, offline message, message of the day,
1983 * volume name, minimum quota, maximum quota
1985 * status of a volume, offlines messages, minimum quota, maximumm quota
1988 * Error if some of the standard args aren't set
1990 * Error if the volume is read only, or a backup volume
1992 * Error if the volume can't be accessed
1994 * Error if the volume name, offline message, and motd are too big
1997 * Set the status of a volume, including any offline messages,
1998 * a minimum quota, and a maximum quota
2000 DECL_PIOCTL(PSetVolumeStatus)
2005 register struct afs_conn *tc;
2006 register afs_int32 code = 0;
2007 struct AFSFetchVolumeStatus volstat;
2008 struct AFSStoreVolumeStatus storeStat;
2009 register struct volume *tvp;
2012 AFS_STATCNT(PSetVolumeStatus);
2016 tvp = afs_GetVolume(&avc->f.fid, areq, READ_LOCK);
2018 if (tvp->states & (VRO | VBackup)) {
2019 afs_PutVolume(tvp, READ_LOCK);
2022 afs_PutVolume(tvp, READ_LOCK);
2027 if (afs_pd_getBytes(ain, &volstat, sizeof(AFSFetchVolumeStatus)) != 0)
2030 if (afs_pd_getStringPtr(ain, &volName) != 0)
2032 if (strlen(volName) > 32)
2035 if (afs_pd_getStringPtr(ain, &offLineMsg) != 0)
2037 if (strlen(offLineMsg) > 256)
2040 if (afs_pd_getStringPtr(ain, &motd) != 0)
2042 if (strlen(motd) > 256)
2045 /* Done reading ... */
2048 if (volstat.MinQuota != -1) {
2049 storeStat.MinQuota = volstat.MinQuota;
2050 storeStat.Mask |= AFS_SETMINQUOTA;
2052 if (volstat.MaxQuota != -1) {
2053 storeStat.MaxQuota = volstat.MaxQuota;
2054 storeStat.Mask |= AFS_SETMAXQUOTA;
2057 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
2059 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS);
2062 RXAFS_SetVolumeStatus(tc->id, avc->f.fid.Fid.Volume, &storeStat,
2063 volName, offLineMsg, motd);
2068 } while (afs_Analyze
2069 (tc, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS,
2070 SHARED_LOCK, NULL));
2074 /* we are sending parms back to make compat. with prev system. should
2075 * change interface later to not ask for current status, just set new
2078 if (afs_pd_putBytes(aout, &volstat, sizeof(VolumeStatus)) != 0)
2080 if (afs_pd_putString(aout, volName) != 0)
2082 if (afs_pd_putString(aout, offLineMsg) != 0)
2084 if (afs_pd_putString(aout, motd) != 0)
2091 * VIOCFLUSH (6) - Invalidate cache entry
2095 * \param[in] ain not in use
2096 * \param[out] aout not in use
2098 * \retval EINVAL Error if some of the standard args aren't set
2100 * \post Flush any information the cache manager has on an entry
2104 AFS_STATCNT(PFlush);
2107 #ifdef AFS_BOZONLOCK_ENV
2108 afs_BozonLock(&avc->pvnLock, avc); /* Since afs_TryToSmush will do a pvn_vptrunc */
2110 ObtainWriteLock(&avc->lock, 225);
2111 afs_ResetVCache(avc, *acred);
2112 ReleaseWriteLock(&avc->lock);
2113 #ifdef AFS_BOZONLOCK_ENV
2114 afs_BozonUnlock(&avc->pvnLock, avc);
2120 * VIOC_AFS_STAT_MT_PT (29) - Stat mount point
2125 * the last component in a path, related to mountpoint that we're
2126 * looking for information about
2128 * volume, cell, link data
2130 * \retval EINVAL Error if some of the standard args aren't set
2131 * \retval ENOTDIR Error if the 'mount point' argument isn't a directory
2132 * \retval EIO Error if the link data can't be accessed
2134 * \post Get the volume, and cell, as well as the link data for a mount point
2136 DECL_PIOCTL(PNewStatMount)
2138 register afs_int32 code;
2139 register struct vcache *tvc;
2140 register struct dcache *tdc;
2141 struct VenusFid tfid;
2144 struct sysname_info sysState;
2145 afs_size_t offset, len;
2147 AFS_STATCNT(PNewStatMount);
2151 if (afs_pd_getStringPtr(ain, &name) != 0)
2154 code = afs_VerifyVCache(avc, areq);
2157 if (vType(avc) != VDIR) {
2160 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
2163 Check_AtSys(avc, name, &sysState, areq);
2164 ObtainReadLock(&tdc->lock);
2166 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
2167 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
2168 ReleaseReadLock(&tdc->lock);
2169 afs_PutDCache(tdc); /* we're done with the data */
2170 bufp = sysState.name;
2174 tfid.Cell = avc->f.fid.Cell;
2175 tfid.Fid.Volume = avc->f.fid.Fid.Volume;
2176 if (!tfid.Fid.Unique && (avc->f.states & CForeign)) {
2177 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
2179 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
2185 if (tvc->mvstat != 1) {
2190 ObtainWriteLock(&tvc->lock, 226);
2191 code = afs_HandleLink(tvc, areq);
2193 if (tvc->linkData) {
2194 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
2197 /* we have the data */
2198 if (afs_pd_putString(aout, tvc->linkData) != 0)
2204 ReleaseWriteLock(&tvc->lock);
2207 if (sysState.allocked)
2208 osi_FreeLargeSpace(bufp);
2213 * VIOCGETTOK (8) - Get authentication tokens
2217 * \param[in] ain cellid to return tokens for
2218 * \param[out] aout token
2221 * Error if the afs daemon hasn't started yet
2223 * Error if the input parameter is out of the bounds of the available
2226 * Error if there aren't tokens for this cell
2229 * If the input paramater exists, get the token that corresponds to
2230 * the parameter value, if there is no token at this value, get the
2231 * token for the first cell
2233 * \notes "it's a weird interface (from comments in the code)"
2236 DECL_PIOCTL(PGetTokens)
2238 register struct cell *tcell;
2239 register afs_int32 i;
2240 register struct unixuser *tu;
2241 afs_int32 iterator = 0;
2245 AFS_STATCNT(PGetTokens);
2246 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2247 return EIO; /* Inappropriate ioctl for device */
2249 /* weird interface. If input parameter is present, it is an integer and
2250 * we're supposed to return the parm'th tokens for this unix uid.
2251 * If not present, we just return tokens for cell 1.
2252 * If counter out of bounds, return EDOM.
2253 * If no tokens for the particular cell, return ENOTCONN.
2254 * Also, if this mysterious parm is present, we return, along with the
2255 * tokens, the primary cell indicator (an afs_int32 0) and the cell name
2256 * at the end, in that order.
2258 newStyle = (afs_pd_remaining(ain) > 0);
2260 if (afs_pd_getInt(ain, &iterator) != 0)
2263 i = UHash(areq->uid);
2264 ObtainReadLock(&afs_xuser);
2265 for (tu = afs_users[i]; tu; tu = tu->next) {
2267 if (tu->uid == areq->uid && (tu->states & UHasTokens)) {
2268 if (iterator-- == 0)
2269 break; /* are we done yet? */
2272 if (tu->uid == areq->uid && afs_IsPrimaryCellNum(tu->cell))
2278 * No need to hold a read lock on each user entry
2282 ReleaseReadLock(&afs_xuser);
2287 if (((tu->states & UHasTokens) == 0)
2288 || (tu->ct.EndTimestamp < osi_Time())) {
2289 tu->states |= (UTokensBad | UNeedsReset);
2290 afs_NotifyUser(tu, UTokensDropped);
2291 afs_PutUser(tu, READ_LOCK);
2294 iterator = tu->stLen; /* for compat, we try to return 56 byte tix if they fit */
2296 iterator = 56; /* # of bytes we're returning */
2298 if (afs_pd_putInt(aout, iterator) != 0)
2300 if (afs_pd_putBytes(aout, tu->stp, tu->stLen) != 0)
2302 if (tu->stLen < 56) {
2303 /* Tokens are always 56 bytes or larger */
2304 if (afs_pd_skip(aout, iterator - tu->stLen) != 0) {
2309 if (afs_pd_putInt(aout, sizeof(struct ClearToken)) != 0)
2311 if (afs_pd_putBytes(aout, &tu->ct, sizeof(struct ClearToken)) != 0)
2315 /* put out primary id and cell name, too */
2316 iterator = (tu->states & UPrimary ? 1 : 0);
2317 if (afs_pd_putInt(aout, iterator) != 0)
2319 tcell = afs_GetCell(tu->cell, READ_LOCK);
2321 if (afs_pd_putString(aout, tcell->cellName) != 0)
2323 afs_PutCell(tcell, READ_LOCK);
2325 if (afs_pd_putString(aout, "") != 0)
2328 /* Got here, all is good */
2331 afs_PutUser(tu, READ_LOCK);
2336 * VIOCUNLOG (9) - Invalidate tokens
2340 * \param[in] ain not in use
2341 * \param[out] aout not in use
2343 * \retval EIO Error if the afs daemon hasn't been started yet
2345 * \post remove tokens from a user, specified by the user id
2347 * \notes sets the token's time to 0, which then causes it to be removed
2348 * \notes Unlog is the same as un-pag in OpenAFS
2352 register afs_int32 i;
2353 register struct unixuser *tu;
2355 AFS_STATCNT(PUnlog);
2356 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2357 return EIO; /* Inappropriate ioctl for device */
2359 i = UHash(areq->uid);
2360 ObtainWriteLock(&afs_xuser, 227);
2361 for (tu = afs_users[i]; tu; tu = tu->next) {
2362 if (tu->uid == areq->uid) {
2364 tu->states &= ~UHasTokens;
2365 /* security is not having to say you're sorry */
2366 memset(&tu->ct, 0, sizeof(struct ClearToken));
2368 ReleaseWriteLock(&afs_xuser);
2369 afs_NotifyUser(tu, UTokensDropped);
2370 /* We have to drop the lock over the call to afs_ResetUserConns,
2371 * since it obtains the afs_xvcache lock. We could also keep
2372 * the lock, and modify ResetUserConns to take parm saying we
2373 * obtained the lock already, but that is overkill. By keeping
2374 * the "tu" pointer held over the released lock, we guarantee
2375 * that we won't lose our place, and that we'll pass over
2376 * every user conn that existed when we began this call.
2378 afs_ResetUserConns(tu);
2380 ObtainWriteLock(&afs_xuser, 228);
2382 /* set the expire times to 0, causes
2383 * afs_GCUserData to remove this entry
2385 tu->ct.EndTimestamp = 0;
2387 #endif /* UKERNEL */
2390 ReleaseWriteLock(&afs_xuser);
2395 * VIOC_AFS_MARINER_HOST (32) - Get/set mariner (cache manager monitor) host
2399 * \param[in] ain host address to be set
2400 * \param[out] aout old host address
2403 * depending on whether or not a variable is set, either get the host
2404 * for the cache manager monitor, or set the old address and give it
2407 * \notes Errors turn off mariner
2409 DECL_PIOCTL(PMariner)
2411 afs_int32 newHostAddr;
2412 afs_int32 oldHostAddr;
2414 AFS_STATCNT(PMariner);
2416 memcpy((char *)&oldHostAddr, (char *)&afs_marinerHost,
2419 oldHostAddr = 0xffffffff; /* disabled */
2421 if (afs_pd_getInt(ain, &newHostAddr) != 0)
2424 if (newHostAddr == 0xffffffff) {
2425 /* disable mariner operations */
2427 } else if (newHostAddr) {
2429 afs_marinerHost = newHostAddr;
2432 if (afs_pd_putInt(aout, oldHostAddr) != 0)
2439 * VIOCCKSERV (10) - Check that servers are up
2443 * \param[in] ain name of the cell
2444 * \param[out] aout current down server list
2446 * \retval EIO Error if the afs daemon hasn't started yet
2447 * \retval EACCES Error if the user doesn't have super-user credentials
2448 * \retval ENOENT Error if we are unable to obtain the cell
2451 * Either a fast check (where it doesn't contact servers) or a
2452 * local check (checks local cell only)
2454 DECL_PIOCTL(PCheckServers)
2457 register struct server *ts;
2459 char *cellName = NULL;
2461 struct chservinfo *pcheck;
2463 AFS_STATCNT(PCheckServers);
2465 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2466 return EIO; /* Inappropriate ioctl for device */
2468 /* This is tricky, because we need to peak at the datastream to see
2469 * what we're getting. For now, let's cheat. */
2471 /* ain contains either an int32 or a string */
2472 if (ain->remaining == 0)
2475 if (*(afs_int32 *)ain->ptr == 0x12345678) { /* For afs3.3 version */
2476 pcheck = afs_pd_inline(ain, sizeof(*pcheck));
2480 if (pcheck->tinterval >= 0) {
2481 if (afs_pd_putInt(aout, afs_probe_interval) != 0)
2483 if (pcheck->tinterval > 0) {
2484 if (!afs_osi_suser(*acred))
2486 afs_probe_interval = pcheck->tinterval;
2490 temp = pcheck->tflags;
2492 cellName = pcheck->tbuffer;
2493 } else { /* For pre afs3.3 versions */
2494 if (afs_pd_getInt(ain, &temp) != 0)
2496 if (afs_pd_remaining(ain) > 0) {
2497 if (afs_pd_getStringPtr(ain, &cellName) != 0)
2503 * 1: fast check, don't contact servers.
2504 * 2: local cell only.
2507 /* have cell name, too */
2508 cellp = afs_GetCellByName(cellName, READ_LOCK);
2513 if (!cellp && (temp & 2)) {
2514 /* use local cell */
2515 cellp = afs_GetPrimaryCell(READ_LOCK);
2517 if (!(temp & 1)) { /* if not fast, call server checker routine */
2518 afs_CheckServers(1, cellp); /* check down servers */
2519 afs_CheckServers(0, cellp); /* check up servers */
2521 /* now return the current down server list */
2522 ObtainReadLock(&afs_xserver);
2523 for (i = 0; i < NSERVERS; i++) {
2524 for (ts = afs_servers[i]; ts; ts = ts->next) {
2525 if (cellp && ts->cell != cellp)
2526 continue; /* cell spec'd and wrong */
2527 if ((ts->flags & SRVR_ISDOWN)
2528 && ts->addr->sa_portal != ts->cell->vlport) {
2529 afs_pd_putInt(aout, ts->addr->sa_ip);
2533 ReleaseReadLock(&afs_xserver);
2535 afs_PutCell(cellp, READ_LOCK);
2540 * VIOCCKBACK (11) - Check backup volume mappings
2544 * \param[in] ain not in use
2545 * \param[out] aout not in use
2547 * \retval EIO Error if the afs daemon hasn't started yet
2550 * Check the root volume, and then check the names if the volume
2551 * check variable is set to force, has expired, is busy, or if
2552 * the mount points variable is set
2554 DECL_PIOCTL(PCheckVolNames)
2556 AFS_STATCNT(PCheckVolNames);
2557 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2558 return EIO; /* Inappropriate ioctl for device */
2560 afs_CheckRootVolume();
2561 afs_CheckVolumeNames(AFS_VOLCHECK_FORCE | AFS_VOLCHECK_EXPIRED |
2562 AFS_VOLCHECK_BUSY | AFS_VOLCHECK_MTPTS);
2567 * VIOCCKCONN (12) - Check connections for a user
2571 * \param[in] ain not in use
2572 * \param[out] aout not in use
2575 * Error if no user is specififed, the user has no tokens set,
2576 * or if the user's tokens are bad
2579 * check to see if a user has the correct authentication.
2580 * If so, allow access.
2582 * \notes Check the connections to all the servers specified
2584 DECL_PIOCTL(PCheckAuth)
2588 struct afs_conn *tc;
2589 struct unixuser *tu;
2592 AFS_STATCNT(PCheckAuth);
2593 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2594 return EIO; /* Inappropriate ioctl for device */
2597 tu = afs_GetUser(areq->uid, 1, READ_LOCK); /* check local cell authentication */
2601 /* we have a user */
2602 ObtainReadLock(&afs_xsrvAddr);
2603 ObtainReadLock(&afs_xconn);
2605 /* any tokens set? */
2606 if ((tu->states & UHasTokens) == 0)
2608 /* all connections in cell 1 working? */
2609 for (i = 0; i < NSERVERS; i++) {
2610 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2611 for (tc = sa->conns; tc; tc = tc->next) {
2612 if (tc->user == tu && (tu->states & UTokensBad))
2617 ReleaseReadLock(&afs_xsrvAddr);
2618 ReleaseReadLock(&afs_xconn);
2619 afs_PutUser(tu, READ_LOCK);
2621 if (afs_pd_putInt(aout, retValue) != 0)
2627 Prefetch(uparmtype apath, struct afs_ioctl *adata, int afollow,
2631 register afs_int32 code;
2632 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2638 AFS_STATCNT(Prefetch);
2641 tp = osi_AllocLargeSpace(1024);
2642 AFS_COPYINSTR(apath, tp, 1024, &bufferSize, code);
2644 osi_FreeLargeSpace(tp);
2647 if (afs_BBusy()) { /* do this as late as possible */
2648 osi_FreeLargeSpace(tp);
2649 return EWOULDBLOCK; /* pretty close */
2651 afs_BQueue(BOP_PATH, (struct vcache *)0, 0, 0, acred, (afs_size_t) 0,
2652 (afs_size_t) 0, tp, (void *)0, (void *)0);
2657 * VIOCWHEREIS (14) - Find out where a volume is located
2661 * \param[in] ain not in use
2662 * \param[out] aout volume location
2664 * \retval EINVAL Error if some of the default arguments don't exist
2665 * \retval ENODEV Error if there is no such volume
2667 * \post fine a volume, based on a volume file id
2669 * \notes check each of the servers specified
2671 DECL_PIOCTL(PFindVolume)
2673 register struct volume *tvp;
2674 register struct server *ts;
2675 register afs_int32 i;
2678 AFS_STATCNT(PFindVolume);
2681 tvp = afs_GetVolume(&avc->f.fid, areq, READ_LOCK);
2685 for (i = 0; i < AFS_MAXHOSTS; i++) {
2686 ts = tvp->serverHost[i];
2689 if (afs_pd_putInt(aout, ts->addr->sa_ip) != 0) {
2694 if (i < AFS_MAXHOSTS) {
2695 /* still room for terminating NULL, add it on */
2696 if (afs_pd_putInt(aout, 0) != 0) {
2702 afs_PutVolume(tvp, READ_LOCK);
2707 * VIOCACCESS (20) - Access using PRS_FS bits
2711 * \param[in] ain PRS_FS bits
2712 * \param[out] aout not in use
2714 * \retval EINVAL Error if some of the initial arguments aren't set
2715 * \retval EACCES Error if access is denied
2717 * \post check to make sure access is allowed
2719 DECL_PIOCTL(PViceAccess)
2721 register afs_int32 code;
2724 AFS_STATCNT(PViceAccess);
2728 code = afs_VerifyVCache(avc, areq);
2732 if (afs_pd_getInt(ain, &temp) != 0)
2735 code = afs_AccessOK(avc, temp, areq, CHECK_MODE_BITS);
2743 * VIOC_GETPAG (13) - Get PAG value
2747 * \param[in] ain not in use
2748 * \param[out] aout PAG value or NOPAG
2750 * \post get PAG value for the caller's cred
2752 DECL_PIOCTL(PGetPAG)
2756 pag = PagInCred(*acred);
2758 return afs_pd_putInt(aout, pag);
2761 DECL_PIOCTL(PPrecache)
2765 /*AFS_STATCNT(PPrecache);*/
2766 if (!afs_osi_suser(*acred))
2769 if (afs_pd_getInt(ain, &newValue) != 0)
2772 afs_preCache = newValue*1024;
2777 * VIOCSETCACHESIZE (24) - Set venus cache size in 1000 units
2781 * \param[in] ain the size the venus cache should be set to
2782 * \param[out] aout not in use
2784 * \retval EACCES Error if the user doesn't have super-user credentials
2785 * \retval EROFS Error if the cache is set to be in memory
2788 * Set the cache size based on user input. If no size is given,
2789 * set it to the default OpenAFS cache size.
2792 * recompute the general cache parameters for every single block allocated
2794 DECL_PIOCTL(PSetCacheSize)
2799 AFS_STATCNT(PSetCacheSize);
2801 if (!afs_osi_suser(*acred))
2803 /* too many things are setup initially in mem cache version */
2804 if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
2806 if (afs_pd_getInt(ain, &newValue) != 0)
2809 afs_cacheBlocks = afs_stats_cmperf.cacheBlocksOrig;
2811 if (newValue < afs_min_cache)
2812 afs_cacheBlocks = afs_min_cache;
2814 afs_cacheBlocks = newValue;
2816 afs_stats_cmperf.cacheBlocksTotal = afs_cacheBlocks;
2817 afs_ComputeCacheParms(); /* recompute basic cache parameters */
2818 afs_MaybeWakeupTruncateDaemon();
2819 while (waitcnt++ < 100 && afs_cacheBlocks < afs_blocksUsed) {
2820 afs_osi_Wait(1000, 0, 0);
2821 afs_MaybeWakeupTruncateDaemon();
2826 #define MAXGCSTATS 16
2828 * VIOCGETCACHEPARMS (40) - Get cache stats
2832 * \param[in] ain afs index flags
2833 * \param[out] aout cache blocks, blocks used, blocks files (in an array)
2835 * \post Get the cache blocks, and how many of the cache blocks there are
2837 DECL_PIOCTL(PGetCacheSize)
2839 afs_int32 results[MAXGCSTATS];
2841 register struct dcache * tdc;
2844 AFS_STATCNT(PGetCacheSize);
2846 if (afs_pd_remaining(ain) == sizeof(afs_int32)) {
2847 afs_pd_getInt(ain, &flags); /* can't error, we just checked size */
2848 } else if (afs_pd_remaining(ain) == 0) {
2854 memset(results, 0, sizeof(results));
2855 results[0] = afs_cacheBlocks;
2856 results[1] = afs_blocksUsed;
2857 results[2] = afs_cacheFiles;
2860 for (i = 0; i < afs_cacheFiles; i++) {
2861 if (afs_indexFlags[i] & IFFree) results[3]++;
2863 } else if (2 == flags){
2864 for (i = 0; i < afs_cacheFiles; i++) {
2865 if (afs_indexFlags[i] & IFFree) results[3]++;
2866 if (afs_indexFlags[i] & IFEverUsed) results[4]++;
2867 if (afs_indexFlags[i] & IFDataMod) results[5]++;
2868 if (afs_indexFlags[i] & IFDirtyPages) results[6]++;
2869 if (afs_indexFlags[i] & IFAnyPages) results[7]++;
2870 if (afs_indexFlags[i] & IFDiscarded) results[8]++;
2872 tdc = afs_indexTable[i];
2875 size = tdc->validPos;
2876 if ( 0 < size && size < (1<<12) ) results[10]++;
2877 else if (size < (1<<14) ) results[11]++;
2878 else if (size < (1<<16) ) results[12]++;
2879 else if (size < (1<<18) ) results[13]++;
2880 else if (size < (1<<20) ) results[14]++;
2881 else if (size >= (1<<20) ) results[15]++;
2885 return afs_pd_putBytes(aout, results, sizeof(results));
2889 * VIOCFLUSHCB (25) - Flush callback only
2893 * \param[in] ain not in use
2894 * \param[out] aout not in use
2896 * \retval EINVAL Error if some of the standard args aren't set
2897 * \retval 0 0 returned if the volume is set to read-only
2900 * Flushes callbacks, by setting the length of callbacks to one,
2901 * setting the next callback to be sent to the CB_DROPPED value,
2902 * and then dequeues everything else.
2904 DECL_PIOCTL(PRemoveCallBack)
2906 register struct afs_conn *tc;
2907 register afs_int32 code = 0;
2908 struct AFSCallBack CallBacks_Array[1];
2909 struct AFSCBFids theFids;
2910 struct AFSCBs theCBs;
2913 AFS_STATCNT(PRemoveCallBack);
2916 if (avc->f.states & CRO)
2917 return 0; /* read-only-ness can't change */
2918 ObtainWriteLock(&avc->lock, 229);
2919 theFids.AFSCBFids_len = 1;
2920 theCBs.AFSCBs_len = 1;
2921 theFids.AFSCBFids_val = (struct AFSFid *)&avc->f.fid.Fid;
2922 theCBs.AFSCBs_val = CallBacks_Array;
2923 CallBacks_Array[0].CallBackType = CB_DROPPED;
2924 if (avc->callback) {
2926 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
2928 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
2930 code = RXAFS_GiveUpCallBacks(tc->id, &theFids, &theCBs);
2934 /* don't set code on failure since we wouldn't use it */
2935 } while (afs_Analyze
2936 (tc, code, &avc->f.fid, areq,
2937 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK, NULL));
2939 ObtainWriteLock(&afs_xcbhash, 457);
2940 afs_DequeueCallback(avc);
2942 avc->f.states &= ~(CStatd | CUnique);
2943 ReleaseWriteLock(&afs_xcbhash);
2944 if (avc->f.fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
2945 osi_dnlc_purgedp(avc);
2947 ReleaseWriteLock(&avc->lock);
2952 * VIOCNEWCELL (26) - Configure new cell
2957 * the name of the cell, the hosts that will be a part of the cell,
2958 * whether or not it's linked with another cell, the other cell it's
2959 * linked with, the file server port, and the volume server port
2963 * \retval EIO Error if the afs daemon hasn't started yet
2964 * \retval EACCES Error if the user doesn't have super-user cedentials
2965 * \retval EINVAL Error if some 'magic' var doesn't have a certain bit set
2967 * \post creates a new cell
2969 DECL_PIOCTL(PNewCell)
2971 afs_int32 cellHosts[AFS_MAXCELLHOSTS], magic = 0;
2972 char *newcell = NULL;
2973 char *linkedcell = NULL;
2975 afs_int32 linkedstate = 0;
2976 afs_int32 fsport = 0, vlport = 0;
2979 AFS_STATCNT(PNewCell);
2980 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2981 return EIO; /* Inappropriate ioctl for device */
2983 if (!afs_osi_suser(*acred))
2986 if (afs_pd_getInt(ain, &magic) != 0)
2988 if (magic != 0x12345678)
2991 /* A 3.4 fs newcell command will pass an array of AFS_MAXCELLHOSTS
2992 * server addresses while the 3.5 fs newcell command passes
2993 * AFS_MAXHOSTS. To figure out which is which, check if the cellname
2996 * This whole logic is bogus, because it relies on the newer command
2997 * sending its 12th address as 0.
2999 if ((afs_pd_remaining(ain) < AFS_MAXCELLHOSTS +3) * sizeof(afs_int32))
3002 newcell = afs_pd_where(ain) + (AFS_MAXCELLHOSTS + 3) * sizeof(afs_int32);
3003 if (newcell[0] != '\0') {
3006 skip = AFS_MAXHOSTS - AFS_MAXCELLHOSTS;
3009 /* AFS_MAXCELLHOSTS (=8) is less than AFS_MAXHOSTS (=13) */
3010 if (afs_pd_getBytes(ain, &cellHosts,
3011 AFS_MAXCELLHOSTS * sizeof(afs_int32)) != 0)
3013 if (afs_pd_skip(ain, skip * sizeof(afs_int32)) !=0)
3016 if (afs_pd_getInt(ain, &fsport) != 0)
3019 fsport = 0; /* Privileged ports not allowed */
3021 if (afs_pd_getInt(ain, &vlport) != 0)
3024 vlport = 0; /* Privileged ports not allowed */
3026 if (afs_pd_getInt(ain, &ls) != 0)
3029 if (afs_pd_getStringPtr(ain, &newcell) != 0)
3033 if (afs_pd_getStringPtr(ain, &linkedcell) != 0)
3035 linkedstate |= CLinkedCell;
3038 linkedstate |= CNoSUID; /* setuid is disabled by default for fs newcell */
3040 afs_NewCell(newcell, cellHosts, linkedstate, linkedcell, fsport,
3045 DECL_PIOCTL(PNewAlias)
3047 /* create a new cell alias */
3048 char *realName, *aliasName;
3050 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3051 return EIO; /* Inappropriate ioctl for device */
3053 if (!afs_osi_suser(*acred))
3056 if (afs_pd_getStringPtr(ain, &aliasName) != 0)
3058 if (afs_pd_getStringPtr(ain, &realName) != 0)
3061 return afs_NewCellAlias(aliasName, realName);
3065 * VIOCGETCELL (27) - Get cell info
3069 * \param[in] ain The cell index of a specific cell
3070 * \param[out] aout list of servers in the cell
3072 * \retval EIO Error if the afs daemon hasn't started yet
3073 * \retval EDOM Error if there is no cell asked about
3075 * \post Lists the cell's server names and and addresses
3077 DECL_PIOCTL(PListCells)
3079 afs_int32 whichCell;
3080 register struct cell *tcell = 0;
3081 register afs_int32 i;
3084 AFS_STATCNT(PListCells);
3085 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3086 return EIO; /* Inappropriate ioctl for device */
3088 if (afs_pd_getInt(ain, &whichCell) != 0)
3091 tcell = afs_GetCellByIndex(whichCell, READ_LOCK);
3097 for (i = 0; i < AFS_MAXCELLHOSTS; i++) {
3098 if (tcell->cellHosts[i] == 0)
3100 if (afs_pd_putInt(aout, tcell->cellHosts[i]->addr->sa_ip) != 0)
3103 for (;i < AFS_MAXCELLHOSTS; i++) {
3104 if (afs_pd_putInt(aout, 0) != 0)
3107 if (afs_pd_putString(aout, tcell->cellName) != 0)
3112 afs_PutCell(tcell, READ_LOCK);
3116 DECL_PIOCTL(PListAliases)
3118 afs_int32 whichAlias;
3119 register struct cell_alias *tcalias = 0;
3122 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3123 return EIO; /* Inappropriate ioctl for device */
3125 if (afs_pd_getInt(ain, &whichAlias) != 0)
3128 tcalias = afs_GetCellAlias(whichAlias);
3129 if (tcalias == NULL)
3133 if (afs_pd_putString(aout, tcalias->alias) != 0)
3135 if (afs_pd_putString(aout, tcalias->cell) != 0)
3140 afs_PutCellAlias(tcalias);
3145 * VIOC_AFS_DELETE_MT_PT (28) - Delete mount point
3149 * \param[in] ain the name of the file in this dir to remove
3150 * \param[out] aout not in use
3153 * Error if some of the standard args aren't set
3155 * Error if the argument to remove is not a directory
3157 * Error if there is no cache to remove the mount point from or
3158 * if a vcache doesn't exist
3161 * Ensure that everything is OK before deleting the mountpoint.
3162 * If not, don't delete. Delete a mount point based on a file id.
3164 DECL_PIOCTL(PRemoveMount)
3166 register afs_int32 code;
3169 struct sysname_info sysState;
3170 afs_size_t offset, len;
3171 register struct afs_conn *tc;
3172 register struct dcache *tdc;
3173 register struct vcache *tvc;
3174 struct AFSFetchStatus OutDirStatus;
3175 struct VenusFid tfid;
3176 struct AFSVolSync tsync;
3179 /* "ain" is the name of the file in this dir to remove */
3181 AFS_STATCNT(PRemoveMount);
3184 if (afs_pd_getStringPtr(ain, &name) != 0)
3187 code = afs_VerifyVCache(avc, areq);
3190 if (vType(avc) != VDIR)
3193 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1); /* test for error below */
3196 Check_AtSys(avc, name, &sysState, areq);
3197 ObtainReadLock(&tdc->lock);
3199 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
3200 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
3201 ReleaseReadLock(&tdc->lock);
3202 bufp = sysState.name;
3207 tfid.Cell = avc->f.fid.Cell;
3208 tfid.Fid.Volume = avc->f.fid.Fid.Volume;
3209 if (!tfid.Fid.Unique && (avc->f.states & CForeign)) {
3210 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
3212 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3219 if (tvc->mvstat != 1) {
3225 ObtainWriteLock(&tvc->lock, 230);
3226 code = afs_HandleLink(tvc, areq);
3228 if (tvc->linkData) {
3229 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
3234 ReleaseWriteLock(&tvc->lock);
3235 osi_dnlc_purgedp(tvc);
3241 ObtainWriteLock(&avc->lock, 231);
3242 osi_dnlc_remove(avc, bufp, tvc);
3244 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
3246 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE);
3249 RXAFS_RemoveFile(tc->id, (struct AFSFid *)&avc->f.fid.Fid, bufp,
3250 &OutDirStatus, &tsync);
3255 } while (afs_Analyze
3256 (tc, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_REMOVEFILE,
3257 SHARED_LOCK, NULL));
3262 ReleaseWriteLock(&avc->lock);
3266 /* we have the thing in the cache */
3267 ObtainWriteLock(&tdc->lock, 661);
3268 if (afs_LocalHero(avc, tdc, &OutDirStatus, 1)) {
3269 /* we can do it locally */
3270 code = afs_dir_Delete(tdc, bufp);
3272 ZapDCE(tdc); /* surprise error -- invalid value */
3276 ReleaseWriteLock(&tdc->lock);
3277 afs_PutDCache(tdc); /* drop ref count */
3279 avc->f.states &= ~CUnique; /* For the dfs xlator */
3280 ReleaseWriteLock(&avc->lock);
3283 if (sysState.allocked)
3284 osi_FreeLargeSpace(bufp);
3289 * VIOC_GETCELLSTATUS (35) - Get cell status info
3293 * \param[in] ain The cell you want status information on
3294 * \param[out] aout cell state (as a struct)
3296 * \retval EIO Error if the afs daemon hasn't started yet
3297 * \retval ENOENT Error if the cell doesn't exist
3299 * \post Returns the state of the cell as defined in a struct cell
3301 DECL_PIOCTL(PGetCellStatus)
3303 register struct cell *tcell;
3307 AFS_STATCNT(PGetCellStatus);
3308 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3309 return EIO; /* Inappropriate ioctl for device */
3311 if (afs_pd_getStringPtr(ain, &cellName) != 0)
3314 tcell = afs_GetCellByName(cellName, READ_LOCK);
3317 temp = tcell->states;
3318 afs_PutCell(tcell, READ_LOCK);
3320 return afs_pd_putInt(aout, temp);
3324 * VIOC_SETCELLSTATUS (36) - Set corresponding info
3329 * The cell you want to set information about, and the values you
3334 * \retval EIO Error if the afs daemon hasn't started yet
3335 * \retval EACCES Error if the user doesn't have super-user credentials
3338 * Set the state of the cell in a defined struct cell, based on
3339 * whether or not SetUID is allowed
3341 DECL_PIOCTL(PSetCellStatus)
3343 register struct cell *tcell;
3345 afs_int32 flags0, flags1;
3347 if (!afs_osi_suser(*acred))
3349 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3350 return EIO; /* Inappropriate ioctl for device */
3352 if (afs_pd_getInt(ain, &flags0) != 0)
3354 if (afs_pd_getInt(ain, &flags1) != 0)
3356 if (afs_pd_getStringPtr(ain, &cellName) != 0)
3359 tcell = afs_GetCellByName(cellName, WRITE_LOCK);
3362 if (flags0 & CNoSUID)
3363 tcell->states |= CNoSUID;
3365 tcell->states &= ~CNoSUID;
3366 afs_PutCell(tcell, WRITE_LOCK);
3371 * VIOC_FLUSHVOLUME (37) - Flush whole volume's data
3375 * \param[in] ain not in use (args in avc)
3376 * \param[out] aout not in use
3378 * \retval EINVAL Error if some of the standard args aren't set
3379 * \retval EIO Error if the afs daemon hasn't started yet
3382 * Flush all cached contents of a volume. Exactly what stays and what
3383 * goes depends on the platform.
3386 * Does not flush a file that a user has open and is using, because
3387 * it will be re-created on next write. Also purges the dnlc,
3388 * because things are screwed up.
3390 DECL_PIOCTL(PFlushVolumeData)
3392 register afs_int32 i;
3393 register struct dcache *tdc;
3394 register struct vcache *tvc;
3395 register struct volume *tv;
3396 afs_int32 cell, volume;
3397 struct afs_q *tq, *uq;
3398 #ifdef AFS_DARWIN80_ENV
3402 AFS_STATCNT(PFlushVolumeData);
3405 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3406 return EIO; /* Inappropriate ioctl for device */
3408 volume = avc->f.fid.Fid.Volume; /* who to zap */
3409 cell = avc->f.fid.Cell;
3412 * Clear stat'd flag from all vnodes from this volume; this will
3413 * invalidate all the vcaches associated with the volume.
3416 ObtainReadLock(&afs_xvcache);
3417 i = VCHashV(&avc->f.fid);
3418 for (tq = afs_vhashTV[i].prev; tq != &afs_vhashTV[i]; tq = uq) {
3421 if (tvc->f.fid.Fid.Volume == volume && tvc->f.fid.Cell == cell) {
3422 if (tvc->f.states & CVInit) {
3423 ReleaseReadLock(&afs_xvcache);
3424 afs_osi_Sleep(&tvc->f.states);
3427 #ifdef AFS_DARWIN80_ENV
3428 if (tvc->f.states & CDeadVnode) {
3429 if (!(tvc->f.states & CBulkFetching)) {
3430 ReleaseReadLock(&afs_xvcache);
3431 afs_osi_Sleep(&tvc->f.states);
3438 if (vnode_ref(vp)) {
3444 if (tvc->f.states & (CBulkFetching|CDeadVnode)) {
3446 vnode_recycle(AFSTOV(tvc));
3452 ReleaseReadLock(&afs_xvcache);
3453 #ifdef AFS_BOZONLOCK_ENV
3454 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
3456 ObtainWriteLock(&tvc->lock, 232);
3458 ObtainWriteLock(&afs_xcbhash, 458);
3459 afs_DequeueCallback(tvc);
3460 tvc->f.states &= ~(CStatd | CDirty);
3461 ReleaseWriteLock(&afs_xcbhash);
3462 if (tvc->f.fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
3463 osi_dnlc_purgedp(tvc);
3464 afs_TryToSmush(tvc, *acred, 1);
3465 ReleaseWriteLock(&tvc->lock);
3466 #ifdef AFS_BOZONLOCK_ENV
3467 afs_BozonUnlock(&tvc->pvnLock, tvc);
3469 #ifdef AFS_DARWIN80_ENV
3470 vnode_put(AFSTOV(tvc));
3472 ObtainReadLock(&afs_xvcache);
3474 /* our tvc ptr is still good until now */
3478 ReleaseReadLock(&afs_xvcache);
3481 ObtainWriteLock(&afs_xdcache, 328); /* needed to flush any stuff */
3482 for (i = 0; i < afs_cacheFiles; i++) {
3483 if (!(afs_indexFlags[i] & IFEverUsed))
3484 continue; /* never had any data */
3485 tdc = afs_GetDSlot(i, NULL);
3486 if (tdc->refCount <= 1) { /* too high, in use by running sys call */
3487 ReleaseReadLock(&tdc->tlock);
3488 if (tdc->f.fid.Fid.Volume == volume && tdc->f.fid.Cell == cell) {
3489 if (!(afs_indexFlags[i] & IFDataMod)) {
3490 /* if the file is modified, but has a ref cnt of only 1,
3491 * then someone probably has the file open and is writing
3492 * into it. Better to skip flushing such a file, it will be
3493 * brought back immediately on the next write anyway.
3495 * If we *must* flush, then this code has to be rearranged
3496 * to call afs_storeAllSegments() first */
3497 afs_FlushDCache(tdc);
3501 ReleaseReadLock(&tdc->tlock);
3503 afs_PutDCache(tdc); /* bumped by getdslot */
3505 ReleaseWriteLock(&afs_xdcache);
3507 ObtainReadLock(&afs_xvolume);
3508 for (i = 0; i < NVOLS; i++) {
3509 for (tv = afs_volumes[i]; tv; tv = tv->next) {
3510 if (tv->volume == volume) {
3511 afs_ResetVolumeInfo(tv);
3516 ReleaseReadLock(&afs_xvolume);
3518 /* probably, a user is doing this, probably, because things are screwed up.
3519 * maybe it's the dnlc's fault? */
3526 * VIOCGETVCXSTATUS (41) - gets vnode x status
3531 * not in use (avc used)
3533 * vcxstat: the file id, the data version, any lock, the parent vnode,
3534 * the parent unique id, the trunc position, the callback, cbExpires,
3535 * what access is being made, what files are open,
3536 * any users executing/writing, the flock count, the states,
3540 * Error if some of the initial default arguments aren't set
3542 * Error if access to check the mode bits is denied
3545 * gets stats for the vnode, a struct listed in vcxstat
3547 DECL_PIOCTL(PGetVnodeXStatus)
3549 register afs_int32 code;
3550 struct vcxstat stat;
3553 /* AFS_STATCNT(PGetVnodeXStatus); */
3556 code = afs_VerifyVCache(avc, areq);
3559 if (vType(avc) == VDIR)
3560 mode = PRSFS_LOOKUP;
3563 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
3566 memset(&stat, 0, sizeof(struct vcxstat));
3567 stat.fid = avc->f.fid;
3568 hset32(stat.DataVersion, hgetlo(avc->f.m.DataVersion));
3569 stat.lock = avc->lock;
3570 stat.parentVnode = avc->f.parent.vnode;
3571 stat.parentUnique = avc->f.parent.unique;
3572 hset(stat.flushDV, avc->flushDV);
3573 hset(stat.mapDV, avc->mapDV);
3574 stat.truncPos = avc->f.truncPos;
3575 { /* just grab the first two - won't break anything... */
3576 struct axscache *ac;
3578 for (i = 0, ac = avc->Access; ac && i < CPSIZE; i++, ac = ac->next) {
3579 stat.randomUid[i] = ac->uid;
3580 stat.randomAccess[i] = ac->axess;
3583 stat.callback = afs_data_pointer_to_int32(avc->callback);
3584 stat.cbExpires = avc->cbExpires;
3585 stat.anyAccess = avc->f.anyAccess;
3586 stat.opens = avc->opens;
3587 stat.execsOrWriters = avc->execsOrWriters;
3588 stat.flockCount = avc->flockCount;
3589 stat.mvstat = avc->mvstat;
3590 stat.states = avc->f.states;
3591 return afs_pd_putBytes(aout, &stat, sizeof(struct vcxstat));
3595 DECL_PIOCTL(PGetVnodeXStatus2)
3597 register afs_int32 code;
3598 struct vcxstat2 stat;
3603 code = afs_VerifyVCache(avc, areq);
3606 if (vType(avc) == VDIR)
3607 mode = PRSFS_LOOKUP;
3610 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
3613 memset(&stat, 0, sizeof(struct vcxstat2));
3615 stat.cbExpires = avc->cbExpires;
3616 stat.anyAccess = avc->f.anyAccess;
3617 stat.mvstat = avc->mvstat;
3618 stat.callerAccess = afs_GetAccessBits(avc, ~0, areq);
3620 return afs_pd_putBytes(aout, &stat, sizeof(struct vcxstat2));
3625 * VIOC_AFS_SYSNAME (38) - Change @sys value
3629 * \param[in] ain new value for @sys
3630 * \param[out] aout count, entry, list (debug values?)
3633 * Error if afsd isn't running, the new sysname is too large,
3634 * the new sysname causes issues (starts with a . or ..),
3635 * there is no PAG set in the credentials, or the user of a PAG
3638 * Error if the user doesn't have super-user credentials
3641 * Set the value of @sys if these things work: if the input isn't
3642 * too long or if input doesn't start with . or ..
3645 * We require root for local sysname changes, but not for remote
3646 * (since we don't really believe remote uids anyway)
3647 * outname[] shouldn't really be needed- this is left as an
3648 * exercise for the reader.
3650 DECL_PIOCTL(PSetSysName)
3652 char *inname = NULL;
3653 char outname[MAXSYSNAME];
3654 afs_int32 setsysname;
3656 register struct afs_exporter *exporter;
3657 register struct unixuser *au;
3658 register afs_int32 pag, error;
3659 int t, count, num = 0, allpags = 0;
3661 struct afs_pdata validate;
3663 AFS_STATCNT(PSetSysName);
3664 if (!afs_globalVFS) {
3665 /* Afsd is NOT running; disable it */
3666 #if defined(KERNEL_HAVE_UERROR)
3667 return (setuerror(EINVAL), EINVAL);
3672 if (afs_pd_getInt(ain, &setsysname) != 0)
3674 if (setsysname & 0x8000) {
3676 setsysname &= ~0x8000;
3681 if (setsysname < 0 || setsysname > MAXNUMSYSNAMES)
3684 for (count = 0; count < setsysname; count++) {
3685 if (afs_pd_getStringPtr(&validate, &inname) != 0)
3688 if (t >= MAXSYSNAME || t <= 0)
3690 /* check for names that can shoot us in the foot */
3691 if (inname[0] == '.' && (inname[1] == 0
3692 || (inname[1] == '.' && inname[2] == 0)))
3695 /* args ok, so go back to the beginning of that section */
3697 if (afs_pd_getStringPtr(ain, &inname) != 0)
3701 if (afs_cr_gid(*acred) == RMTUSER_REQ ||
3702 afs_cr_gid(*acred) == RMTUSER_REQ_PRIV) { /* Handles all exporters */
3703 if (allpags && afs_cr_gid(*acred) != RMTUSER_REQ_PRIV) {
3706 pag = PagInCred(*acred);
3708 return EINVAL; /* Better than panicing */
3710 if (!(au = afs_FindUser(pag, -1, READ_LOCK))) {
3711 return EINVAL; /* Better than panicing */
3713 if (!(exporter = au->exporter)) {
3714 afs_PutUser(au, READ_LOCK);
3715 return EINVAL; /* Better than panicing */
3717 error = EXP_SYSNAME(exporter, inname, &sysnamelist,
3720 if (error == ENODEV)
3721 foundname = 0; /* sysname not set yet! */
3723 afs_PutUser(au, READ_LOCK);
3728 strcpy(outname, sysnamelist[0]);
3730 afs_PutUser(au, READ_LOCK);
3734 /* Not xlating, so local case */
3736 osi_Panic("PSetSysName: !afs_sysname\n");
3737 if (!setsysname) { /* user just wants the info */
3738 strcpy(outname, afs_sysname);
3739 foundname = afs_sysnamecount;
3740 sysnamelist = afs_sysnamelist;
3741 } else { /* Local guy; only root can change sysname */
3742 if (!afs_osi_suser(*acred))
3745 /* allpags makes no sense for local use */
3749 /* clear @sys entries from the dnlc, once afs_lookup can
3750 * do lookups of @sys entries and thinks it can trust them */
3751 /* privs ok, store the entry, ... */
3753 if (strlen(inname) >= MAXSYSNAME-1)
3755 strcpy(afs_sysname, inname);
3757 if (setsysname > 1) { /* ... or list */
3758 for (count = 1; count < setsysname; ++count) {
3759 if (!afs_sysnamelist[count])
3761 ("PSetSysName: no afs_sysnamelist entry to write\n");
3762 if (afs_pd_getString(ain, afs_sysnamelist[count],
3767 afs_sysnamecount = setsysname;
3772 if (afs_pd_putInt(aout, foundname) != 0)
3775 if (afs_pd_putString(aout, outname) != 0)
3777 for (count = 1; count < foundname; ++count) { /* ... or list. */
3778 if (!sysnamelist[count])
3780 ("PSetSysName: no afs_sysnamelist entry to read\n");
3781 t = strlen(sysnamelist[count]);
3782 if (t >= MAXSYSNAME)
3783 osi_Panic("PSetSysName: sysname entry garbled\n");
3784 if (afs_pd_putString(aout, sysnamelist[count]) != 0)
3792 /* sequential search through the list of touched cells is not a good
3793 * long-term solution here. For small n, though, it should be just
3794 * fine. Should consider special-casing the local cell for large n.
3795 * Likewise for PSetSPrefs.
3797 * s - number of ids in array l[] -- NOT index of last id
3798 * l - array of cell ids which have volumes that need to be sorted
3799 * vlonly - sort vl servers or file servers?
3802 ReSortCells_cb(struct cell *cell, void *arg)
3804 afs_int32 *p = (afs_int32 *) arg;
3805 afs_int32 *l = p + 1;
3808 for (i = 0; i < s; i++) {
3809 if (l[i] == cell->cellNum) {
3810 ObtainWriteLock(&cell->lock, 690);
3811 afs_SortServers(cell->cellHosts, AFS_MAXCELLHOSTS);
3812 ReleaseWriteLock(&cell->lock);
3820 ReSortCells(int s, afs_int32 * l, int vlonly)
3828 p = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * (s + 1));
3830 memcpy(p + 1, l, s * sizeof(afs_int32));
3831 afs_TraverseCells(&ReSortCells_cb, p);
3832 afs_osi_Free(p, sizeof(afs_int32) * (s + 1));
3836 ObtainReadLock(&afs_xvolume);
3837 for (i = 0; i < NVOLS; i++) {
3838 for (j = afs_volumes[i]; j; j = j->next) {
3839 for (k = 0; k < s; k++)
3840 if (j->cell == l[k]) {
3841 ObtainWriteLock(&j->lock, 233);
3842 afs_SortServers(j->serverHost, AFS_MAXHOSTS);
3843 ReleaseWriteLock(&j->lock);
3848 ReleaseReadLock(&afs_xvolume);
3852 static int debugsetsp = 0;
3854 afs_setsprefs(struct spref *sp, unsigned int num, unsigned int vlonly)
3857 int i, j, k, matches, touchedSize;
3858 struct server *srvr = NULL;
3859 afs_int32 touched[34];
3863 for (k = 0; k < num; sp++, k++) {
3865 afs_warn("sp host=%x, rank=%d\n", sp->host.s_addr, sp->rank);
3868 ObtainReadLock(&afs_xserver);
3870 i = SHash(sp->host.s_addr);
3871 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3872 if (sa->sa_ip == sp->host.s_addr) {
3874 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
3875 || (sa->sa_portal == AFS_FSPORT);
3876 if ((!vlonly && isfs) || (vlonly && !isfs)) {
3883 if (sa && matches) { /* found one! */
3885 afs_warn("sa ip=%x, ip_rank=%d\n", sa->sa_ip, sa->sa_iprank);
3887 sa->sa_iprank = sp->rank + afs_randomMod15();
3888 afs_SortOneServer(sa->server);
3891 /* if we don't know yet what cell it's in, this is moot */
3892 for (j = touchedSize - 1;
3893 j >= 0 && touched[j] != srvr->cell->cellNum; j--)
3894 /* is it in our list of touched cells ? */ ;
3895 if (j < 0) { /* no, it's not */
3896 touched[touchedSize++] = srvr->cell->cellNum;
3897 if (touchedSize >= 32) { /* watch for ovrflow */
3898 ReleaseReadLock(&afs_xserver);
3899 ReSortCells(touchedSize, touched, vlonly);
3901 ObtainReadLock(&afs_xserver);
3907 ReleaseReadLock(&afs_xserver);
3908 /* if we didn't find one, start to create one. */
3909 /* Note that it doesn't have a cell yet... */
3911 afs_uint32 temp = sp->host.s_addr;
3913 afs_GetServer(&temp, 1, 0, (vlonly ? AFS_VLPORT : AFS_FSPORT),
3914 WRITE_LOCK, (afsUUID *) 0, 0);
3915 srvr->addr->sa_iprank = sp->rank + afs_randomMod15();
3916 afs_PutServer(srvr, WRITE_LOCK);
3918 } /* for all cited preferences */
3920 ReSortCells(touchedSize, touched, vlonly);
3925 * VIOC_SETPREFS (46) - Set server ranks
3927 * \param[in] ain the sprefs value you want the sprefs to be set to
3928 * \param[out] aout not in use
3931 * Error if the afs daemon hasn't started yet
3933 * Error if the user doesn't have super-user credentials
3935 * Error if the struct setsprefs is too large or if it multiplied
3936 * by the number of servers is too large
3938 * \post set the sprefs using the afs_setsprefs() function
3940 DECL_PIOCTL(PSetSPrefs)
3942 struct setspref *ssp;
3946 AFS_STATCNT(PSetSPrefs);
3948 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3949 return EIO; /* Inappropriate ioctl for device */
3951 if (!afs_osi_suser(*acred))
3954 /* The I/O handling here is ghastly, as it relies on overrunning the ends
3955 * of arrays. But, i'm not quite brave enough to change it yet. */
3957 ainSize = ain->remaining;
3959 if (ainSize < sizeof(struct setspref))
3962 ssp = (struct setspref *)ainPtr;
3963 if (ainSize < (sizeof(struct setspref)
3964 + sizeof(struct spref) * ssp->num_servers-1))
3967 afs_setsprefs(&(ssp->servers[0]), ssp->num_servers,
3968 (ssp->flags & DBservers));
3973 * VIOC_SETPREFS33 (42) - Set server ranks (deprecated)
3975 * \param[in] ain the server preferences to be set
3976 * \param[out] aout not in use
3978 * \retval EIO Error if the afs daemon hasn't started yet
3979 * \retval EACCES Error if the user doesn't have super-user credentials
3981 * \post set the server preferences, calling a function
3983 * \notes this may only be performed by the local root user.
3985 DECL_PIOCTL(PSetSPrefs33)
3987 AFS_STATCNT(PSetSPrefs);
3988 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3989 return EIO; /* Inappropriate ioctl for device */
3992 if (!afs_osi_suser(*acred))
3995 afs_setsprefs((struct spref *)afs_pd_where(ain),
3996 afs_pd_remaining(ain) / sizeof(struct spref),
4002 * VIOC_GETSPREFS (43) - Get server ranks
4006 * \param[in] ain the server preferences to get
4007 * \param[out] aout the server preferences information
4009 * \retval EIO Error if the afs daemon hasn't started yet
4010 * \retval ENOENT Error if the sprefrequest is too large
4012 * \post Get the sprefs
4015 * in the hash table of server structs, all servers with the same
4016 * IP address; will be on the same overflow chain; This could be
4017 * sped slightly in some circumstances by having it cache the
4018 * immediately previous slot in the hash table and some
4019 * supporting information; Only reports file servers now.
4021 DECL_PIOCTL(PGetSPrefs)
4023 struct sprefrequest spin; /* input */
4024 struct sprefinfo *spout; /* output */
4025 struct spref *srvout; /* one output component */
4026 int i, j; /* counters for hash table traversal */
4027 struct server *srvr; /* one of CM's server structs */
4029 int vlonly; /* just return vlservers ? */
4032 AFS_STATCNT(PGetSPrefs);
4033 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4034 return EIO; /* Inappropriate ioctl for device */
4036 /* Work out from the size whether we've got a new, or old, style pioctl */
4037 if (afs_pd_remaining(ain) < sizeof(struct sprefrequest)) {
4038 if (afs_pd_getBytes(ain, &spin, sizeof(struct sprefrequest_33)) != 0)
4043 if (afs_pd_getBytes(ain, &spin, sizeof(struct sprefrequest)) != 0)
4045 vlonly = (spin.flags & DBservers);
4048 /* This code relies on overflowing arrays. It's ghastly, but I'm not
4049 * quite brave enough to tackle it yet ...
4052 /* struct sprefinfo includes 1 server struct... that size gets added
4053 * in during the loop that follows.
4055 spout = afs_pd_inline(aout,
4056 sizeof(struct sprefinfo) - sizeof(struct spref));
4057 spout->next_offset = spin.offset;
4058 spout->num_servers = 0;
4059 srvout = spout->servers;
4061 ObtainReadLock(&afs_xserver);
4062 for (i = 0, j = 0; j < NSERVERS; j++) { /* sift through hash table */
4063 for (sa = afs_srvAddrs[j]; sa; sa = sa->next_bkt, i++) {
4064 if (spin.offset > (unsigned short)i) {
4065 continue; /* catch up to where we left off */
4067 spout->next_offset++;
4070 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
4071 || (sa->sa_portal == AFS_FSPORT);
4073 if ((vlonly && isfs) || (!vlonly && !isfs)) {
4074 /* only report ranks for vl servers */
4078 /* Check we've actually got the space we're about to use */
4079 if (afs_pd_inline(aout, sizeof(struct spref)) == NULL) {
4080 ReleaseReadLock(&afs_xserver); /* no more room! */
4084 srvout->host.s_addr = sa->sa_ip;
4085 srvout->rank = sa->sa_iprank;
4086 spout->num_servers++;
4090 ReleaseReadLock(&afs_xserver);
4092 spout->next_offset = 0; /* start over from the beginning next time */
4097 /* Enable/Disable the specified exporter. Must be root to disable an exporter */
4098 int afs_NFSRootOnly = 1;
4100 * VIOC_EXPORTAFS (39) - Export afs to nfs clients
4105 * an integer containing the desired exportee flags
4107 * an integer containing the current exporter flags
4109 * \retval ENODEV Error if the exporter doesn't exist
4110 * \retval EACCES Error if the user doesn't have super-user credentials
4113 * Changes the state of various values to reflect the change
4114 * of the export values between nfs and afs.
4116 * \notes Legacy code obtained from IBM.
4118 DECL_PIOCTL(PExportAfs)
4120 afs_int32 export, newint = 0;
4121 afs_int32 type, changestate, handleValue, convmode, pwsync, smounts;
4122 afs_int32 rempags = 0, pagcb = 0;
4123 register struct afs_exporter *exporter;
4125 AFS_STATCNT(PExportAfs);
4126 if (afs_pd_getInt(ain, &handleValue) != 0)
4128 type = handleValue >> 24;
4133 exporter = exporter_find(type);
4135 export = handleValue & 3;
4136 changestate = handleValue & 0xfff;
4137 smounts = (handleValue >> 2) & 3;
4138 pwsync = (handleValue >> 4) & 3;
4139 convmode = (handleValue >> 6) & 3;
4140 rempags = (handleValue >> 8) & 3;
4141 pagcb = (handleValue >> 10) & 3;
4143 changestate = (handleValue >> 16) & 0x1;
4144 convmode = (handleValue >> 16) & 0x2;
4145 pwsync = (handleValue >> 16) & 0x4;
4146 smounts = (handleValue >> 16) & 0x8;
4147 export = handleValue & 0xff;
4150 /* Failed finding desired exporter; */
4154 handleValue = exporter->exp_states;
4155 if (afs_pd_putInt(aout, handleValue) != 0)
4158 if (!afs_osi_suser(*acred))
4159 return EACCES; /* Only superuser can do this */
4163 exporter->exp_states |= EXP_EXPORTED;
4165 exporter->exp_states &= ~EXP_EXPORTED;
4169 exporter->exp_states |= EXP_UNIXMODE;
4171 exporter->exp_states &= ~EXP_UNIXMODE;
4175 exporter->exp_states |= EXP_PWSYNC;
4177 exporter->exp_states &= ~EXP_PWSYNC;
4181 afs_NFSRootOnly = 0;
4182 exporter->exp_states |= EXP_SUBMOUNTS;
4184 afs_NFSRootOnly = 1;
4185 exporter->exp_states &= ~EXP_SUBMOUNTS;
4190 exporter->exp_states |= EXP_CLIPAGS;
4192 exporter->exp_states &= ~EXP_CLIPAGS;
4196 exporter->exp_states |= EXP_CALLBACK;
4198 exporter->exp_states &= ~EXP_CALLBACK;
4200 handleValue = exporter->exp_states;
4201 if (afs_pd_putInt(aout, handleValue) != 0)
4205 exporter->exp_states |= EXP_EXPORTED;
4207 exporter->exp_states &= ~EXP_EXPORTED;
4209 exporter->exp_states |= EXP_UNIXMODE;
4211 exporter->exp_states &= ~EXP_UNIXMODE;
4213 exporter->exp_states |= EXP_PWSYNC;
4215 exporter->exp_states &= ~EXP_PWSYNC;
4217 afs_NFSRootOnly = 0;
4218 exporter->exp_states |= EXP_SUBMOUNTS;
4220 afs_NFSRootOnly = 1;
4221 exporter->exp_states &= ~EXP_SUBMOUNTS;
4230 * VIOC_GAG (44) - Silence Cache Manager
4234 * \param[in] ain the flags to either gag or de-gag the cache manager
4235 * \param[out] aout not in use
4237 * \retval EACCES Error if the user doesn't have super-user credentials
4239 * \post set the gag flags, then show these flags
4243 struct gaginfo *gagflags;
4245 if (!afs_osi_suser(*acred))
4248 gagflags = afs_pd_inline(ain, sizeof(*gagflags));
4249 if (gagflags == NULL)
4251 afs_showflags = gagflags->showflags;
4257 * VIOC_TWIDDLE (45) - Adjust RX knobs
4261 * \param[in] ain the previous settings of the 'knobs'
4262 * \param[out] aout not in use
4264 * \retval EACCES Error if the user doesn't have super-user credentials
4266 * \post build out the struct rxp, from a struct rx
4268 DECL_PIOCTL(PTwiddleRx)
4270 struct rxparams *rxp;
4272 if (!afs_osi_suser(*acred))
4275 rxp = afs_pd_inline(ain, sizeof(*rxp));
4279 if (rxp->rx_initReceiveWindow)
4280 rx_initReceiveWindow = rxp->rx_initReceiveWindow;
4281 if (rxp->rx_maxReceiveWindow)
4282 rx_maxReceiveWindow = rxp->rx_maxReceiveWindow;
4283 if (rxp->rx_initSendWindow)
4284 rx_initSendWindow = rxp->rx_initSendWindow;
4285 if (rxp->rx_maxSendWindow)
4286 rx_maxSendWindow = rxp->rx_maxSendWindow;
4287 if (rxp->rxi_nSendFrags)
4288 rxi_nSendFrags = rxp->rxi_nSendFrags;
4289 if (rxp->rxi_nRecvFrags)
4290 rxi_nRecvFrags = rxp->rxi_nRecvFrags;
4291 if (rxp->rxi_OrphanFragSize)
4292 rxi_OrphanFragSize = rxp->rxi_OrphanFragSize;
4293 if (rxp->rx_maxReceiveSize) {
4294 rx_maxReceiveSize = rxp->rx_maxReceiveSize;
4295 rx_maxReceiveSizeUser = rxp->rx_maxReceiveSize;
4297 if (rxp->rx_MyMaxSendSize)
4298 rx_MyMaxSendSize = rxp->rx_MyMaxSendSize;
4304 * VIOC_GETINITPARAMS (49) - Get initial cache manager parameters
4308 * \param[in] ain not in use
4309 * \param[out] aout initial cache manager params
4312 * Error if the initial parameters are bigger than some PIGGYSIZE
4314 * \post return the initial cache manager parameters
4316 DECL_PIOCTL(PGetInitParams)
4318 if (sizeof(struct cm_initparams) > PIGGYSIZE)
4321 return afs_pd_putBytes(aout, &cm_initParams,
4322 sizeof(struct cm_initparams));
4326 #ifdef AFS_SGI65_ENV
4327 /* They took crget() from us, so fake it. */
4332 cr = crdup(get_current_cred());
4333 memset(cr, 0, sizeof(cred_t));
4334 #if CELL || CELL_PREPARE
4342 * VIOC_GETRXKCRYPT (55) - Get rxkad encryption flag
4346 * \param[in] ain not in use
4347 * \param[out] aout value of cryptall
4349 * \post Turns on, or disables, rxkad encryption by setting the cryptall global
4351 DECL_PIOCTL(PGetRxkcrypt)
4353 return afs_pd_putInt(aout, cryptall);
4357 * VIOC_SETRXKCRYPT (56) - Set rxkad encryption flag
4361 * \param[in] ain the argument whether or not things should be encrypted
4362 * \param[out] aout not in use
4365 * Error if the user doesn't have super-user credentials
4367 * Error if the input is too big, or if the input is outside the
4368 * bounds of what it can be set to
4370 * \post set whether or not things should be encrypted
4373 * may need to be modified at a later date to take into account
4374 * other values for cryptall (beyond true or false)
4376 DECL_PIOCTL(PSetRxkcrypt)
4380 if (!afs_osi_suser(*acred))
4382 if (afs_pd_getInt(ain, &tmpval) != 0)
4384 /* if new mappings added later this will need to be changed */
4385 if (tmpval != 0 && tmpval != 1)
4391 #ifdef AFS_NEED_CLIENTCONTEXT
4393 * Create new credentials to correspond to a remote user with given
4394 * <hostaddr, uid, g0, g1>. This allows a server running as root to
4395 * provide pioctl (and other) services to foreign clients (i.e. nfs
4396 * clients) by using this call to `become' the client.
4399 #define PIOCTL_HEADER 6
4401 HandleClientContext(struct afs_ioctl *ablob, int *com,
4402 afs_ucred_t **acred, afs_ucred_t *credp)
4405 afs_uint32 hostaddr;
4406 afs_int32 uid, g0, g1, i, code, pag, exporter_type, isroot = 0;
4407 struct afs_exporter *exporter, *outexporter;
4408 afs_ucred_t *newcred;
4409 struct unixuser *au;
4410 afs_uint32 comp = *com & 0xff00;
4412 #if defined(AFS_SUN510_ENV)
4416 #if defined(AFS_SGIMP_ENV)
4417 osi_Assert(ISAFS_GLOCK());
4419 AFS_STATCNT(HandleClientContext);
4420 if (ablob->in_size < PIOCTL_HEADER * sizeof(afs_int32)) {
4421 /* Must at least include the PIOCTL_HEADER header words
4422 * required by the protocol */
4423 return EINVAL; /* Too small to be good */
4425 ain = inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
4426 AFS_COPYIN(ablob->in, ain, PIOCTL_HEADER * sizeof(afs_int32), code);
4428 osi_FreeLargeSpace(inData);
4432 /* Extract information for remote user */
4433 hostaddr = *((afs_uint32 *) ain);
4434 ain += sizeof(hostaddr);
4435 uid = *((afs_uint32 *) ain);
4437 g0 = *((afs_uint32 *) ain);
4439 g1 = *((afs_uint32 *) ain);
4441 *com = *((afs_uint32 *) ain);
4442 ain += sizeof(afs_int32);
4443 exporter_type = *((afs_uint32 *) ain);/* In case we support more than NFS */
4446 * Of course, one must be root for most of these functions, but
4447 * we'll allow (for knfs) you to set things if the pag is 0 and
4448 * you're setting tokens or unlogging.
4451 if (!afs_osi_suser(credp)) {
4452 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
4453 /* Since SGI's suser() returns explicit failure after the call.. */
4456 /* check for acceptable opcodes for normal folks, which are, so far,
4457 * get/set tokens, sysname, and unlog.
4459 if (i != 9 && i != 3 && i != 38 && i != 8) {
4460 osi_FreeLargeSpace(inData);
4465 ablob->in_size -= PIOCTL_HEADER * sizeof(afs_int32);
4466 ablob->in += PIOCTL_HEADER * sizeof(afs_int32);
4467 osi_FreeLargeSpace(inData);
4470 * We map uid 0 to nobody to match the mapping that the nfs
4471 * server does and to ensure that the suser() calls in the afs
4472 * code fails for remote client roots.
4474 uid = afs_nobody; /* NFS_NOBODY == -2 */
4478 #ifdef AFS_AIX41_ENV
4481 afs_set_cr_gid(newcred, isroot ? RMTUSER_REQ_PRIV : RMTUSER_REQ);
4482 #ifdef AFS_AIX51_ENV
4483 newcred->cr_groupset.gs_union.un_groups[0] = g0;
4484 newcred->cr_groupset.gs_union.un_groups[1] = g1;
4485 #elif defined(AFS_LINUX26_ENV)
4486 # ifdef AFS_LINUX26_ONEGROUP_ENV
4487 afs_set_cr_group_info(newcred, groups_alloc(1)); /* nothing sets this */
4488 l = (((g0-0x3f00) & 0x3fff) << 14) | ((g1-0x3f00) & 0x3fff);
4489 h = ((g0-0x3f00) >> 14);
4490 h = ((g1-0x3f00) >> 14) + h + h + h;
4491 GROUP_AT(afs_cr_group_info(newcred), 0) = ((h << 28) | l);
4493 afs_set_cr_group_info(newcred, groups_alloc(2));
4494 GROUP_AT(afs_cr_group_info(newcred), 0) = g0;
4495 GROUP_AT(afs_cr_group_info(newcred), 1) = g1;
4497 #elif defined(AFS_SUN510_ENV)
4500 crsetgroups(newcred, 2, gids);
4502 newcred->cr_groups[0] = g0;
4503 newcred->cr_groups[1] = g1;
4506 newcred->cr_ngrps = 2;
4507 #elif !defined(AFS_LINUX26_ENV) && !defined(AFS_SUN510_ENV)
4508 # if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_FBSD80_ENV)
4509 newcred->cr_ngroups = 2;
4511 for (i = 2; i < NGROUPS; i++)
4512 newcred->cr_groups[i] = NOGROUP;
4515 if (!(exporter = exporter_find(exporter_type))) {
4516 /* Exporter wasn't initialized or an invalid exporter type */
4520 if (exporter->exp_states & EXP_PWSYNC) {
4521 if (uid != afs_cr_uid(credp)) {
4523 return ENOEXEC; /* XXX Find a better errno XXX */
4526 afs_set_cr_uid(newcred, uid); /* Only temporary */
4527 code = EXP_REQHANDLER(exporter, &newcred, hostaddr, &pag, &outexporter);
4528 /* The client's pag is the only unique identifier for it */
4529 afs_set_cr_uid(newcred, pag);
4531 if (!code && *com == PSETPAG) {
4532 /* Special case for 'setpag' */
4533 afs_uint32 pagvalue = genpag();
4535 au = afs_GetUser(pagvalue, -1, WRITE_LOCK); /* a new unixuser struct */
4537 * Note that we leave the 'outexporter' struct held so it won't
4540 au->exporter = outexporter;
4541 if (ablob->out_size >= 4) {
4542 AFS_COPYOUT((char *)&pagvalue, ablob->out, sizeof(afs_int32),
4545 afs_PutUser(au, WRITE_LOCK);
4548 return PSETPAG; /* Special return for setpag */
4550 EXP_RELE(outexporter);
4553 *com = (*com) | comp;
4556 #endif /* AFS_NEED_CLIENTCONTEXT */
4560 * VIOC_GETCPREFS (50) - Get client interface
4564 * \param[in] ain sprefrequest input
4565 * \param[out] aout spref information
4567 * \retval EIO Error if the afs daemon hasn't started yet
4568 * \retval EINVAL Error if some of the standard args aren't set
4571 * get all interface addresses and other information of the client
4574 DECL_PIOCTL(PGetCPrefs)
4576 struct sprefrequest *spin; /* input */
4577 struct sprefinfo *spout; /* output */
4578 struct spref *srvout; /* one output component */
4582 AFS_STATCNT(PGetCPrefs);
4583 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4584 return EIO; /* Inappropriate ioctl for device */
4586 spin = afs_pd_inline(ain, sizeof(*spin));
4590 /* Output spout relies on writing past the end of arrays. It's horrible,
4591 * but I'm not quite brave enough to tackle it yet */
4592 spout = (struct sprefinfo *)aout->ptr;
4594 maxNumber = spin->num_servers; /* max addrs this time */
4595 srvout = spout->servers;
4597 ObtainReadLock(&afs_xinterface);
4599 /* copy out the client interface information from the
4600 * kernel data structure "interface" to the output buffer
4602 for (i = spin->offset, j = 0; (i < afs_cb_interface.numberOfInterfaces)
4603 && (j < maxNumber); i++, j++, srvout++)
4604 srvout->host.s_addr = afs_cb_interface.addr_in[i];
4606 spout->num_servers = j;
4607 aout->ptr += sizeof(struct sprefinfo) + (j - 1) * sizeof(struct spref);
4609 if (i >= afs_cb_interface.numberOfInterfaces)
4610 spout->next_offset = 0; /* start from beginning again */
4612 spout->next_offset = spin->offset + j;
4614 ReleaseReadLock(&afs_xinterface);
4619 * VIOC_SETCPREFS (51) - Set client interface
4623 * \param[in] ain the interfaces you want set
4624 * \param[out] aout not in use
4626 * \retval EIO Error if the afs daemon hasn't started yet
4627 * \retval EINVAL Error if the input is too large for the struct
4628 * \retval ENOMEM Error if there are too many servers
4630 * \post set the callbak interfaces addresses to those of the hosts
4632 DECL_PIOCTL(PSetCPrefs)
4636 struct setspref *sin;
4639 AFS_STATCNT(PSetCPrefs);
4640 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4641 return EIO; /* Inappropriate ioctl for device */
4643 /* Yuck. Input to this function relies on reading past the end of
4644 * structures. Bodge it for now.
4647 ainSize = ain->remaining;
4649 sin = (struct setspref *)ainPtr;
4651 if (ainSize < sizeof(struct setspref))
4653 #if 0 /* num_servers is unsigned */
4654 if (sin->num_servers < 0)
4657 if (sin->num_servers > AFS_MAX_INTERFACE_ADDR)
4660 ObtainWriteLock(&afs_xinterface, 412);
4661 afs_cb_interface.numberOfInterfaces = sin->num_servers;
4662 for (i = 0; (unsigned short)i < sin->num_servers; i++)
4663 afs_cb_interface.addr_in[i] = sin->servers[i].host.s_addr;
4665 ReleaseWriteLock(&afs_xinterface);
4670 * VIOC_AFS_FLUSHMOUNT (52) - Flush mount symlink data
4675 * the last part of a path to a mount point, which tells us what to flush
4680 * Error if some of the initial arguments aren't set
4682 * Error if the initial argument for the mount point isn't a directory
4684 * Error if the dcache entry isn't set
4687 * remove all of the mount data from the dcache regarding a
4688 * certain mount point
4690 DECL_PIOCTL(PFlushMount)
4692 register afs_int32 code;
4693 register struct vcache *tvc;
4694 register struct dcache *tdc;
4695 struct VenusFid tfid;
4698 struct sysname_info sysState;
4699 afs_size_t offset, len;
4701 AFS_STATCNT(PFlushMount);
4705 if (afs_pd_getStringPtr(ain, &mount) != 0)
4708 code = afs_VerifyVCache(avc, areq);
4711 if (vType(avc) != VDIR) {
4714 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
4717 Check_AtSys(avc, mount, &sysState, areq);
4718 ObtainReadLock(&tdc->lock);
4720 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
4721 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
4722 ReleaseReadLock(&tdc->lock);
4723 afs_PutDCache(tdc); /* we're done with the data */
4724 bufp = sysState.name;
4728 tfid.Cell = avc->f.fid.Cell;
4729 tfid.Fid.Volume = avc->f.fid.Fid.Volume;
4730 if (!tfid.Fid.Unique && (avc->f.states & CForeign)) {
4731 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
4733 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
4739 if (tvc->mvstat != 1) {
4744 #ifdef AFS_BOZONLOCK_ENV
4745 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
4747 ObtainWriteLock(&tvc->lock, 649);
4748 ObtainWriteLock(&afs_xcbhash, 650);
4749 afs_DequeueCallback(tvc);
4750 tvc->f.states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
4751 ReleaseWriteLock(&afs_xcbhash);
4752 /* now find the disk cache entries */
4753 afs_TryToSmush(tvc, *acred, 1);
4754 osi_dnlc_purgedp(tvc);
4755 if (tvc->linkData && !(tvc->f.states & CCore)) {
4756 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
4757 tvc->linkData = NULL;
4759 ReleaseWriteLock(&tvc->lock);
4760 #ifdef AFS_BOZONLOCK_ENV
4761 afs_BozonUnlock(&tvc->pvnLock, tvc);
4765 if (sysState.allocked)
4766 osi_FreeLargeSpace(bufp);
4771 * VIOC_RXSTAT_PROC (53) - Control process RX statistics
4775 * \param[in] ain the flags that control which stats to use
4776 * \param[out] aout not in use
4778 * \retval EACCES Error if the user doesn't have super-user credentials
4779 * \retval EINVAL Error if the flag input is too long
4782 * either enable process RPCStats, disable process RPCStats,
4783 * or clear the process RPCStats
4785 DECL_PIOCTL(PRxStatProc)
4789 if (!afs_osi_suser(*acred))
4792 if (afs_pd_getInt(ain, &flags) != 0)
4795 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK))
4798 if (flags & AFSCALL_RXSTATS_ENABLE) {
4799 rx_enableProcessRPCStats();
4801 if (flags & AFSCALL_RXSTATS_DISABLE) {
4802 rx_disableProcessRPCStats();
4804 if (flags & AFSCALL_RXSTATS_CLEAR) {
4805 rx_clearProcessRPCStats(AFS_RX_STATS_CLEAR_ALL);
4812 * VIOC_RXSTAT_PEER (54) - Control peer RX statistics
4816 * \param[in] ain the flags that control which statistics to use
4817 * \param[out] aout not in use
4819 * \retval EACCES Error if the user doesn't have super-user credentials
4820 * \retval EINVAL Error if the flag input is too long
4823 * either enable peer RPCStatws, disable peer RPCStats,
4824 * or clear the peer RPCStats
4826 DECL_PIOCTL(PRxStatPeer)
4830 if (!afs_osi_suser(*acred))
4833 if (afs_pd_getInt(ain, &flags) != 0)
4836 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK))
4839 if (flags & AFSCALL_RXSTATS_ENABLE) {
4840 rx_enablePeerRPCStats();
4842 if (flags & AFSCALL_RXSTATS_DISABLE) {
4843 rx_disablePeerRPCStats();
4845 if (flags & AFSCALL_RXSTATS_CLEAR) {
4846 rx_clearPeerRPCStats(AFS_RX_STATS_CLEAR_ALL);
4851 DECL_PIOCTL(PPrefetchFromTape)
4853 register afs_int32 code, code1;
4854 afs_int32 bytes, outval;
4855 struct afs_conn *tc;
4856 struct rx_call *tcall;
4857 struct AFSVolSync tsync;
4858 struct AFSFetchStatus OutStatus;
4859 struct AFSCallBack CallBack;
4860 struct VenusFid tfid;
4864 AFS_STATCNT(PSetAcl);
4868 Fid = afs_pd_inline(ain, sizeof(struct AFSFid));
4870 Fid = &avc->f.fid.Fid;
4872 tfid.Cell = avc->f.fid.Cell;
4873 tfid.Fid.Volume = Fid->Volume;
4874 tfid.Fid.Vnode = Fid->Vnode;
4875 tfid.Fid.Unique = Fid->Unique;
4877 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
4879 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
4880 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &avc->f.fid);
4883 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
4884 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &tvc->f.fid);
4887 tc = afs_Conn(&tvc->f.fid, areq, SHARED_LOCK);
4891 tcall = rx_NewCall(tc->id);
4893 StartRXAFS_FetchData(tcall, (struct AFSFid *)&tvc->f.fid.Fid, 0,
4896 bytes = rx_Read(tcall, (char *)&outval, sizeof(afs_int32));
4898 EndRXAFS_FetchData(tcall, &OutStatus, &CallBack, &tsync);
4900 code1 = rx_EndCall(tcall, code);
4904 } while (afs_Analyze
4905 (tc, code, &tvc->f.fid, areq, AFS_STATS_FS_RPCIDX_RESIDENCYRPCS,
4906 SHARED_LOCK, NULL));
4907 /* This call is done only to have the callback things handled correctly */
4908 afs_FetchStatus(tvc, &tfid, areq, &OutStatus);
4914 return afs_pd_putInt(aout, outval);
4919 register afs_int32 code;
4920 struct afs_conn *tc;
4922 struct FsCmdInputs *Inputs;
4923 struct FsCmdOutputs *Outputs;
4924 struct VenusFid tfid;
4930 Inputs = afs_pd_inline(ain, sizeof(*Inputs));
4934 Outputs = afs_pd_inline(aout, sizeof(*Outputs));
4935 if (Outputs == NULL)
4940 Fid = &avc->f.fid.Fid;
4942 tfid.Cell = avc->f.fid.Cell;
4943 tfid.Fid.Volume = Fid->Volume;
4944 tfid.Fid.Vnode = Fid->Vnode;
4945 tfid.Fid.Unique = Fid->Unique;
4947 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
4948 afs_Trace3(afs_iclSetp, CM_TRACE_RESIDCMD, ICL_TYPE_POINTER, tvc,
4949 ICL_TYPE_INT32, Inputs->command, ICL_TYPE_FID, &tfid);
4953 if (Inputs->command) {
4955 tc = afs_Conn(&tvc->f.fid, areq, SHARED_LOCK);
4959 RXAFS_FsCmd(tc->id, Fid, Inputs,
4960 (struct FsCmdOutputs *)aout);
4964 } while (afs_Analyze
4965 (tc, code, &tvc->f.fid, areq,
4966 AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK, NULL));
4967 /* This call is done to have the callback things handled correctly */
4968 afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
4969 } else { /* just a status request, return also link data */
4971 Outputs->code = afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
4972 Outputs->chars[0] = 0;
4973 if (vType(tvc) == VLNK) {
4974 ObtainWriteLock(&tvc->lock, 555);
4975 if (afs_HandleLink(tvc, areq) == 0)
4976 strncpy((char *)&Outputs->chars, tvc->linkData, MAXCMDCHARS);
4977 ReleaseWriteLock(&tvc->lock);
4986 DECL_PIOCTL(PNewUuid)
4988 /*AFS_STATCNT(PNewUuid); */
4989 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
4990 return EIO; /* Inappropriate ioctl for device */
4992 if (!afs_osi_suser(*acred))
4995 ObtainWriteLock(&afs_xinterface, 555);
4996 afs_uuid_create(&afs_cb_interface.uuid);
4997 ReleaseWriteLock(&afs_xinterface);
4998 ForceAllNewConnections();
5002 #if defined(AFS_CACHE_BYPASS)
5004 DECL_PIOCTL(PSetCachingThreshold)
5006 afs_int32 getting = 1;
5007 afs_int32 setting = 1;
5008 afs_int32 threshold = AFS_CACHE_BYPASS_DISABLED;
5010 if (afs_pd_getInt(ain, &threshold) != 0)
5016 if (setting == 0 && getting == 0)
5020 * If setting, set first, and return the value now in effect
5023 if (!afs_osi_suser(*acred))
5025 cache_bypass_threshold = threshold;
5026 afs_warn("Cache Bypass Threshold set to: %d\n", threshold);
5027 /* TODO: move to separate pioctl, or enhance pioctl */
5028 cache_bypass_strategy = LARGE_FILES_BYPASS_CACHE;
5031 /* Return the current size threshold */
5033 return afs_pd_putInt(aout, cache_bypass_threshold);
5038 #endif /* defined(AFS_CACHE_BYPASS) */
5040 DECL_PIOCTL(PCallBackAddr)
5043 afs_uint32 addr, code;
5047 struct afs_conn *tc;
5049 struct unixuser *tu;
5050 struct srvAddr **addrs;
5052 /*AFS_STATCNT(PCallBackAddr); */
5053 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
5054 return EIO; /* Inappropriate ioctl for device */
5056 if (!afs_osi_suser(acred))
5059 if (afs_pd_getInt(ain, &addr) != 0)
5062 ObtainReadLock(&afs_xinterface);
5063 for (i = 0; (unsigned short)i < afs_cb_interface.numberOfInterfaces; i++) {
5064 if (afs_cb_interface.addr_in[i] == addr)
5068 ReleaseWriteLock(&afs_xinterface);
5070 if (afs_cb_interface.addr_in[i] != addr)
5073 ObtainReadLock(&afs_xserver); /* Necessary? */
5074 ObtainReadLock(&afs_xsrvAddr);
5077 for (i = 0; i < NSERVERS; i++) {
5078 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
5083 addrs = afs_osi_Alloc(srvAddrCount * sizeof(*addrs));
5085 for (i = 0; i < NSERVERS; i++) {
5086 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
5087 if (j >= srvAddrCount)
5093 ReleaseReadLock(&afs_xsrvAddr);
5094 ReleaseReadLock(&afs_xserver);
5096 for (i = 0; i < j; i++) {
5102 /* vlserver has no callback conn */
5103 if (sa->sa_portal == AFS_VLPORT) {
5107 if (!ts->cell) /* not really an active server, anyway, it must */
5108 continue; /* have just been added by setsprefs */
5110 /* get a connection, even if host is down; bumps conn ref count */
5111 tu = afs_GetUser(areq->uid, ts->cell->cellNum, SHARED_LOCK);
5112 tc = afs_ConnBySA(sa, ts->cell->fsport, ts->cell->cellNum, tu,
5113 1 /*force */ , 1 /*create */ , SHARED_LOCK);
5114 afs_PutUser(tu, SHARED_LOCK);
5118 if ((sa->sa_flags & SRVADDR_ISDOWN) || afs_HaveCallBacksFrom(ts)) {
5119 if (sa->sa_flags & SRVADDR_ISDOWN) {
5120 rx_SetConnDeadTime(tc->id, 3);
5122 #ifdef RX_ENABLE_LOCKS
5124 #endif /* RX_ENABLE_LOCKS */
5125 code = RXAFS_CallBackRxConnAddr(tc->id, &addr);
5126 #ifdef RX_ENABLE_LOCKS
5128 #endif /* RX_ENABLE_LOCKS */
5130 afs_PutConn(tc, SHARED_LOCK); /* done with it now */
5131 } /* Outer loop over addrs */
5132 #endif /* UKERNEL */
5136 DECL_PIOCTL(PDiscon)
5138 static afs_int32 mode = 1; /* Start up in 'off' */
5139 afs_int32 force = 0;
5142 struct vrequest lreq;
5144 if (afs_pd_getBytes(ain, &flags, 4) == 0) {
5145 if (!afs_osi_suser(*acred))
5149 mode = flags[0] - 1;
5151 afs_ConflictPolicy = flags[1] - 1;
5155 /* Fake InitReq support for UID override */
5156 memset(&lreq, 0, sizeof(lreq));
5157 lreq.uid = flags[3];
5158 areq = &lreq; /* override areq we got */
5162 * All of these numbers are hard coded in fs.c. If they
5163 * change here, they should change there and vice versa
5166 case 0: /* Disconnect ("offline" mode), breaking all callbacks */
5167 if (!AFS_IS_DISCONNECTED) {
5168 ObtainWriteLock(&afs_discon_lock, 999);
5169 afs_DisconGiveUpCallbacks();
5170 afs_RemoveAllConns();
5171 afs_is_disconnected = 1;
5172 afs_is_discon_rw = 1;
5173 ReleaseWriteLock(&afs_discon_lock);
5176 case 1: /* Fully connected, ("online" mode). */
5177 ObtainWriteLock(&afs_discon_lock, 998);
5180 afs_MarkAllServersUp();
5181 code = afs_ResyncDisconFiles(areq, *acred);
5184 if (code && !force) {
5185 afs_warnuser("Files not synchronized properly, still in discon state. \n"
5186 "Please retry or use \"force\".\n");
5190 afs_DisconDiscardAll(*acred);
5192 afs_ClearAllStatdFlag();
5193 afs_is_disconnected = 0;
5194 afs_is_discon_rw = 0;
5195 afs_warnuser("\nSync succeeded. You are back online.\n");
5198 ReleaseWriteLock(&afs_discon_lock);
5210 return afs_pd_putInt(aout, mode);
5213 DECL_PIOCTL(PNFSNukeCreds)
5216 register afs_int32 i;
5217 register struct unixuser *tu;
5219 AFS_STATCNT(PUnlog);
5220 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
5221 return EIO; /* Inappropriate ioctl for device */
5223 if (afs_pd_getUint(ain, &addr) != 0)
5226 if (afs_cr_gid(*acred) == RMTUSER_REQ_PRIV && !addr) {
5227 tu = afs_GetUser(areq->uid, -1, SHARED_LOCK);
5228 if (!tu->exporter || !(addr = EXP_GETHOST(tu->exporter))) {
5229 afs_PutUser(tu, SHARED_LOCK);
5232 afs_PutUser(tu, SHARED_LOCK);
5233 } else if (!afs_osi_suser(acred)) {
5237 ObtainWriteLock(&afs_xuser, 227);
5238 for (i = 0; i < NUSERS; i++) {
5239 for (tu = afs_users[i]; tu; tu = tu->next) {
5240 if (tu->exporter && EXP_CHECKHOST(tu->exporter, addr)) {
5242 tu->states &= ~UHasTokens;
5243 /* security is not having to say you're sorry */
5244 memset(&tu->ct, 0, sizeof(struct ClearToken));
5246 ReleaseWriteLock(&afs_xuser);
5247 afs_ResetUserConns(tu);
5249 ObtainWriteLock(&afs_xuser, 228);
5251 /* set the expire times to 0, causes
5252 * afs_GCUserData to remove this entry
5254 tu->ct.EndTimestamp = 0;
5256 #endif /* UKERNEL */
5260 ReleaseWriteLock(&afs_xuser);