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"
21 #include "afsincludes.h" /* Afs-based standard headers */
22 #include "afs/afs_stats.h" /* afs statistics */
24 #include "afs/afs_bypasscache.h"
25 #include "rx/rx_globals.h"
27 struct VenusFid afs_rootFid;
28 afs_int32 afs_waitForever = 0;
29 short afs_waitForeverCount = 0;
30 afs_int32 afs_showflags = GAGUSER | GAGCONSOLE; /* show all messages */
33 afs_int32 afs_is_disconnected;
34 afs_int32 afs_is_discon_rw;
35 /* On reconnection, turn this knob on until it finishes,
38 afs_int32 afs_in_sync = 0;
47 * A set of handy little functions for encoding and decoding
48 * pioctls without losing your marbles, or memory integrity
52 afs_pd_alloc(struct afs_pdata *apd, size_t size) {
54 if (size > AFS_LRALLOCSIZ)
55 apd->ptr = osi_Alloc(size + 1);
57 apd->ptr = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
62 apd->remaining = size;
68 afs_pd_free(struct afs_pdata *apd) {
72 if (apd->remaining > AFS_LRALLOCSIZ)
73 osi_Free(apd->ptr, apd->remaining + 1);
75 osi_FreeLargeSpace(apd->ptr);
82 afs_pd_where(struct afs_pdata *apd) {
83 return apd ? apd->ptr : NULL;
87 afs_pd_remaining(struct afs_pdata *apd) {
88 return apd ? apd->remaining : 0;
92 afs_pd_skip(struct afs_pdata *apd, size_t skip) {
93 if (apd == NULL || apd->remaining < skip)
95 apd->remaining -= skip;
102 afs_pd_getInt(struct afs_pdata *apd, afs_int32 *val) {
103 if (apd == NULL || apd->remaining < sizeof(afs_int32))
105 apd->remaining -= sizeof(afs_int32);
106 *val = *(afs_int32 *)apd->ptr;
107 apd->ptr += sizeof(afs_int32);
112 afs_pd_getUint(struct afs_pdata *apd, afs_uint32 *val) {
113 return afs_pd_getInt(apd, (afs_int32 *)val);
117 afs_pd_getBytes(struct afs_pdata *apd, void *dest, size_t bytes) {
118 if (apd == NULL || apd->remaining < bytes)
120 apd->remaining -= bytes;
121 memcpy(dest, apd->ptr, bytes);
127 afs_pd_inline(struct afs_pdata *apd, size_t bytes) {
130 if (apd == NULL || apd->remaining < bytes)
135 apd->remaining -= bytes;
142 afs_pd_getString(struct afs_pdata *apd, char *str, size_t maxLen) {
145 if (apd == NULL || apd->remaining <= 0)
147 len = strlen(apd->ptr) + 1;
150 memcpy(str, apd->ptr, len);
152 apd->remaining -= len;
157 afs_pd_getStringPtr(struct afs_pdata *apd, char **str) {
160 if (apd == NULL || apd->remaining <= 0)
162 len = strlen(apd->ptr) + 1;
165 apd->remaining -= len;
170 afs_pd_putInt(struct afs_pdata *apd, afs_int32 val) {
171 if (apd == NULL || apd->remaining < sizeof(afs_int32))
173 *(afs_int32 *)apd->ptr = val;
174 apd->ptr += sizeof(afs_int32);
175 apd->remaining -= sizeof(afs_int32);
181 afs_pd_putBytes(struct afs_pdata *apd, const void *bytes, size_t len) {
182 if (apd == NULL || apd->remaining < len)
184 memcpy(apd->ptr, bytes, len);
186 apd->remaining -= len;
191 afs_pd_putString(struct afs_pdata *apd, char *str) {
193 /* Add 1 so we copy the NULL too */
194 return afs_pd_putBytes(apd, str, strlen(str) +1);
198 * \defgroup pioctl Path IOCTL functions
200 * DECL_PIOCTL is a macro defined to contain the following parameters for functions:
203 * the AFS vcache structure in use by pioctl
207 * the AFS vrequest structure
209 * an afs_pdata block describing the data received from the caller
211 * an afs_pdata block describing a pre-allocated block for output
213 * UNIX credentials structure underlying the operation
216 #define DECL_PIOCTL(x) \
217 static int x(struct vcache *avc, int afun, struct vrequest *areq, \
218 struct afs_pdata *ain, struct afs_pdata *aout, \
221 /* Prototypes for pioctl routines */
222 DECL_PIOCTL(PGetFID);
223 DECL_PIOCTL(PSetAcl);
224 DECL_PIOCTL(PStoreBehind);
225 DECL_PIOCTL(PGCPAGs);
226 DECL_PIOCTL(PGetAcl);
229 DECL_PIOCTL(PGetFileCell);
230 DECL_PIOCTL(PGetWSCell);
231 DECL_PIOCTL(PGetUserCell);
232 DECL_PIOCTL(PSetTokens);
233 DECL_PIOCTL(PGetVolumeStatus);
234 DECL_PIOCTL(PSetVolumeStatus);
236 DECL_PIOCTL(PNewStatMount);
237 DECL_PIOCTL(PGetTokens);
239 DECL_PIOCTL(PMariner);
240 DECL_PIOCTL(PCheckServers);
241 DECL_PIOCTL(PCheckVolNames);
242 DECL_PIOCTL(PCheckAuth);
243 DECL_PIOCTL(PFindVolume);
244 DECL_PIOCTL(PViceAccess);
245 DECL_PIOCTL(PSetCacheSize);
246 DECL_PIOCTL(PGetCacheSize);
247 DECL_PIOCTL(PRemoveCallBack);
248 DECL_PIOCTL(PNewCell);
249 DECL_PIOCTL(PNewAlias);
250 DECL_PIOCTL(PListCells);
251 DECL_PIOCTL(PListAliases);
252 DECL_PIOCTL(PRemoveMount);
253 DECL_PIOCTL(PGetCellStatus);
254 DECL_PIOCTL(PSetCellStatus);
255 DECL_PIOCTL(PFlushVolumeData);
256 DECL_PIOCTL(PGetVnodeXStatus);
257 DECL_PIOCTL(PGetVnodeXStatus2);
258 DECL_PIOCTL(PSetSysName);
259 DECL_PIOCTL(PSetSPrefs);
260 DECL_PIOCTL(PSetSPrefs33);
261 DECL_PIOCTL(PGetSPrefs);
262 DECL_PIOCTL(PExportAfs);
264 DECL_PIOCTL(PTwiddleRx);
265 DECL_PIOCTL(PGetInitParams);
266 DECL_PIOCTL(PGetRxkcrypt);
267 DECL_PIOCTL(PSetRxkcrypt);
268 DECL_PIOCTL(PGetCPrefs);
269 DECL_PIOCTL(PSetCPrefs);
270 DECL_PIOCTL(PFlushMount);
271 DECL_PIOCTL(PRxStatProc);
272 DECL_PIOCTL(PRxStatPeer);
273 DECL_PIOCTL(PPrefetchFromTape);
275 DECL_PIOCTL(PCallBackAddr);
276 DECL_PIOCTL(PDiscon);
277 DECL_PIOCTL(PNFSNukeCreds);
278 DECL_PIOCTL(PNewUuid);
279 DECL_PIOCTL(PPrecache);
280 DECL_PIOCTL(PGetPAG);
281 #if defined(AFS_CACHE_BYPASS)
282 DECL_PIOCTL(PSetCachingThreshold);
283 DECL_PIOCTL(PSetCachingBlkSize);
287 * A macro that says whether we're going to need HandleClientContext().
288 * This is currently used only by the nfs translator.
290 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
291 #define AFS_NEED_CLIENTCONTEXT
294 /* Prototypes for private routines */
295 #ifdef AFS_NEED_CLIENTCONTEXT
296 static int HandleClientContext(struct afs_ioctl *ablob, int *com,
300 int HandleIoctl(register struct vcache *avc, register afs_int32 acom,
301 struct afs_ioctl *adata);
302 int afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
303 register struct afs_ioctl *ablob, int afollow,
304 afs_ucred_t **acred);
305 static int Prefetch(uparmtype apath, struct afs_ioctl *adata, int afollow,
308 typedef int (*pioctlFunction) (struct vcache *, int, struct vrequest *,
309 struct afs_pdata *, struct afs_pdata *,
312 static pioctlFunction VpioctlSw[] = {
317 PGetVolumeStatus, /* 4 */
318 PSetVolumeStatus, /* 5 */
323 PCheckServers, /* 10 */
324 PCheckVolNames, /* 11 */
326 PBogus, /* 13 -- used to be quick check time */
327 PFindVolume, /* 14 */
328 PBogus, /* 15 -- prefetch is now special-cased; see pioctl code! */
329 PBogus, /* 16 -- used to be testing code */
330 PNoop, /* 17 -- used to be enable group */
331 PNoop, /* 18 -- used to be disable group */
332 PBogus, /* 19 -- used to be list group */
333 PViceAccess, /* 20 */
334 PUnlog, /* 21 -- unlog *is* unpag in this system */
335 PGetFID, /* 22 -- get file ID */
336 PBogus, /* 23 -- used to be waitforever */
337 PSetCacheSize, /* 24 */
338 PRemoveCallBack, /* 25 -- flush only the callback */
341 PRemoveMount, /* 28 -- delete mount point */
342 PNewStatMount, /* 29 -- new style mount point stat */
343 PGetFileCell, /* 30 -- get cell name for input file */
344 PGetWSCell, /* 31 -- get cell name for workstation */
345 PMariner, /* 32 - set/get mariner host */
346 PGetUserCell, /* 33 -- get cell name for user */
347 PBogus, /* 34 -- Enable/Disable logging */
348 PGetCellStatus, /* 35 */
349 PSetCellStatus, /* 36 */
350 PFlushVolumeData, /* 37 -- flush all data from a volume */
351 PSetSysName, /* 38 - Set system name */
352 PExportAfs, /* 39 - Export Afs to remote nfs clients */
353 PGetCacheSize, /* 40 - get cache size and usage */
354 PGetVnodeXStatus, /* 41 - get vcache's special status */
355 PSetSPrefs33, /* 42 - Set CM Server preferences... */
356 PGetSPrefs, /* 43 - Get CM Server preferences... */
357 PGag, /* 44 - turn off/on all CM messages */
358 PTwiddleRx, /* 45 - adjust some RX params */
359 PSetSPrefs, /* 46 - Set CM Server preferences... */
360 PStoreBehind, /* 47 - set degree of store behind to be done */
361 PGCPAGs, /* 48 - disable automatic pag gc-ing */
362 PGetInitParams, /* 49 - get initial cm params */
363 PGetCPrefs, /* 50 - get client interface addresses */
364 PSetCPrefs, /* 51 - set client interface addresses */
365 PFlushMount, /* 52 - flush mount symlink data */
366 PRxStatProc, /* 53 - control process RX statistics */
367 PRxStatPeer, /* 54 - control peer RX statistics */
368 PGetRxkcrypt, /* 55 -- Get rxkad encryption flag */
369 PSetRxkcrypt, /* 56 -- Set rxkad encryption flag */
370 PBogus, /* 57 -- arla: set file prio */
371 PBogus, /* 58 -- arla: fallback getfh */
372 PBogus, /* 59 -- arla: fallback fhopen */
373 PBogus, /* 60 -- arla: controls xfsdebug */
374 PBogus, /* 61 -- arla: controls arla debug */
375 PBogus, /* 62 -- arla: debug interface */
376 PBogus, /* 63 -- arla: print xfs status */
377 PBogus, /* 64 -- arla: force cache check */
378 PBogus, /* 65 -- arla: break callback */
379 PPrefetchFromTape, /* 66 -- MR-AFS: prefetch file from tape */
380 PFsCmd, /* 67 -- RXOSD: generic commnd interface */
381 PBogus, /* 68 -- arla: fetch stats */
382 PGetVnodeXStatus2, /* 69 - get caller access and some vcache status */
385 static pioctlFunction CpioctlSw[] = {
387 PNewAlias, /* 1 -- create new cell alias */
388 PListAliases, /* 2 -- list cell aliases */
389 PCallBackAddr, /* 3 -- request addr for callback rxcon */
391 PDiscon, /* 5 -- get/set discon mode */
402 static pioctlFunction OpioctlSw[] = {
404 PNFSNukeCreds, /* 1 -- nuke all creds for NFS client */
405 #if defined(AFS_CACHE_BYPASS)
406 PSetCachingThreshold /* 2 -- get/set cache-bypass size threshold */
408 PNoop /* 2 -- get/set cache-bypass size threshold */
412 #define PSetClientContext 99 /* Special pioctl to setup caller's creds */
413 int afs_nobody = NFS_NOBODY;
416 HandleIoctl(register struct vcache *avc, register afs_int32 acom,
417 struct afs_ioctl *adata)
419 register afs_int32 code;
422 AFS_STATCNT(HandleIoctl);
424 switch (acom & 0xff) {
426 avc->f.states |= CSafeStore;
428 /* SXW - Should we force a MetaData flush for this flag setting */
431 /* case 2 used to be abort store, but this is no longer provided,
432 * since it is impossible to implement under normal Unix.
436 /* return the name of the cell this file is open on */
437 register struct cell *tcell;
438 register afs_int32 i;
440 tcell = afs_GetCell(avc->f.fid.Cell, READ_LOCK);
442 i = strlen(tcell->cellName) + 1; /* bytes to copy out */
444 if (i > adata->out_size) {
445 /* 0 means we're not interested in the output */
446 if (adata->out_size != 0)
450 AFS_COPYOUT(tcell->cellName, adata->out, i, code);
452 afs_PutCell(tcell, READ_LOCK);
458 case 49: /* VIOC_GETINITPARAMS */
459 if (adata->out_size < sizeof(struct cm_initparams)) {
462 AFS_COPYOUT(&cm_initParams, adata->out,
463 sizeof(struct cm_initparams), code);
475 return code; /* so far, none implemented */
479 /* For aix we don't temporarily bypass ioctl(2) but rather do our
480 * thing directly in the vnode layer call, VNOP_IOCTL; thus afs_ioctl
481 * is now called from afs_gn_ioctl.
484 afs_ioctl(struct vcache *tvc, int cmd, int arg)
486 struct afs_ioctl data;
489 AFS_STATCNT(afs_ioctl);
490 if (((cmd >> 8) & 0xff) == 'V') {
491 /* This is a VICEIOCTL call */
492 AFS_COPYIN(arg, (caddr_t) & data, sizeof(data), error);
495 error = HandleIoctl(tvc, cmd, &data);
498 /* No-op call; just return. */
502 # if defined(AFS_AIX32_ENV)
503 # if defined(AFS_AIX51_ENV)
506 kioctl(int fdes, int com, caddr_t arg, caddr_t ext, caddr_t arg2,
508 # else /* __64BIT__ */
510 kioctl32(int fdes, int com, caddr_t arg, caddr_t ext, caddr_t arg2,
512 # endif /* __64BIT__ */
515 kioctl(int fdes, int com, caddr_t arg, caddr_t ext)
516 # endif /* AFS_AIX51_ENV */
521 # ifdef AFS_AIX51_ENV
524 } u_uap, *uap = &u_uap;
526 register struct vcache *tvc;
527 register int ioctlDone = 0, code = 0;
529 AFS_STATCNT(afs_xioctl);
533 # ifdef AFS_AIX51_ENV
537 if (setuerror(getf(uap->fd, &fd))) {
540 if (fd->f_type == DTYPE_VNODE) {
541 /* good, this is a vnode; next see if it is an AFS vnode */
542 tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */
543 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
544 /* This is an AFS vnode */
545 if (((uap->com >> 8) & 0xff) == 'V') {
546 register struct afs_ioctl *datap;
549 (struct afs_ioctl *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
550 code=copyin_afs_ioctl((char *)uap->arg, datap);
552 osi_FreeSmallSpace(datap);
554 # if defined(AFS_AIX41_ENV)
557 return (setuerror(code), code);
559 code = HandleIoctl(tvc, uap->com, datap);
560 osi_FreeSmallSpace(datap);
563 # if defined(AFS_AIX41_ENV)
570 # if defined(AFS_AIX41_ENV)
572 # if defined(AFS_AIX51_ENV)
574 code = okioctl(fdes, com, arg, ext, arg2, arg3);
575 # else /* __64BIT__ */
576 code = okioctl32(fdes, com, arg, ext, arg2, arg3);
577 # endif /* __64BIT__ */
578 # else /* !AFS_AIX51_ENV */
579 code = okioctl(fdes, com, arg, ext);
580 # endif /* AFS_AIX51_ENV */
582 # elif defined(AFS_AIX32_ENV)
583 okioctl(fdes, com, arg, ext);
586 # if defined(KERNEL_HAVE_UERROR)
589 # if !defined(AFS_AIX41_ENV)
590 return (getuerror()? -1 : u.u_ioctlrv);
592 return getuerror()? -1 : 0;
599 #elif defined(AFS_SGI_ENV)
600 # if defined(AFS_SGI65_ENV)
601 afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
602 rval_t * rvalp, struct vopbd * vbds)
604 afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
605 rval_t * rvalp, struct vopbd * vbds)
608 struct afs_ioctl data;
614 AFS_STATCNT(afs_ioctl);
615 if (((cmd >> 8) & 0xff) == 'V') {
616 /* This is a VICEIOCTL call */
617 error = copyin_afs_ioctl(arg, &data);
620 locked = ISAFS_GLOCK();
623 error = HandleIoctl(tvc, cmd, &data);
628 /* No-op call; just return. */
632 #elif defined(AFS_SUN5_ENV)
633 struct afs_ioctl_sys {
640 afs_xioctl(struct afs_ioctl_sys *uap, rval_t *rvp)
643 register struct vcache *tvc;
644 register int ioctlDone = 0, code = 0;
646 AFS_STATCNT(afs_xioctl);
647 # if defined(AFS_SUN57_ENV)
651 # elif defined(AFS_SUN54_ENV)
656 if (code = getf(uap->fd, &fd)) {
660 if (fd->f_vnode->v_type == VREG || fd->f_vnode->v_type == VDIR) {
661 tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */
662 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
663 /* This is an AFS vnode */
664 if (((uap->com >> 8) & 0xff) == 'V') {
665 register struct afs_ioctl *datap;
668 (struct afs_ioctl *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
669 code=copyin_afs_ioctl((char *)uap->arg, datap);
671 osi_FreeSmallSpace(datap);
673 # if defined(AFS_SUN54_ENV)
680 code = HandleIoctl(tvc, uap->com, datap);
681 osi_FreeSmallSpace(datap);
687 # if defined(AFS_SUN57_ENV)
689 # elif defined(AFS_SUN54_ENV)
695 code = ioctl(uap, rvp);
699 #elif defined(AFS_LINUX22_ENV)
700 struct afs_ioctl_sys {
705 afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
708 struct afs_ioctl_sys ua, *uap = &ua;
709 register struct vcache *tvc;
710 register int ioctlDone = 0, code = 0;
712 AFS_STATCNT(afs_xioctl);
717 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
718 /* This is an AFS vnode */
719 if (((uap->com >> 8) & 0xff) == 'V') {
720 register struct afs_ioctl *datap;
722 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
723 code = copyin_afs_ioctl((char *)uap->arg, datap);
725 osi_FreeSmallSpace(datap);
729 code = HandleIoctl(tvc, uap->com, datap);
730 osi_FreeSmallSpace(datap);
739 #elif defined(AFS_DARWIN_ENV) && !defined(AFS_DARWIN80_ENV)
747 afs_xioctl(afs_proc_t *p, register struct ioctl_args *uap, register_t *retval)
750 register struct vcache *tvc;
751 register int ioctlDone = 0, code = 0;
753 AFS_STATCNT(afs_xioctl);
754 if ((code = fdgetf(p, uap->fd, &fd)))
756 if (fd->f_type == DTYPE_VNODE) {
757 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
758 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
759 /* This is an AFS vnode */
760 if (((uap->com >> 8) & 0xff) == 'V') {
761 register struct afs_ioctl *datap;
763 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
764 code = copyin_afs_ioctl((char *)uap->arg, datap);
766 osi_FreeSmallSpace(datap);
770 code = HandleIoctl(tvc, uap->com, datap);
771 osi_FreeSmallSpace(datap);
779 return ioctl(p, uap, retval);
783 #elif defined(AFS_XBSD_ENV)
784 # if defined(AFS_FBSD50_ENV)
787 afs_xioctl(struct thread *td, register struct ioctl_args *uap,
790 afs_proc_t *p = td->td_proc;
799 afs_xioctl(afs_proc_t *p, register struct ioctl_args *uap, register_t *retval)
802 register struct filedesc *fdp;
803 register struct vcache *tvc;
804 register int ioctlDone = 0, code = 0;
807 AFS_STATCNT(afs_xioctl);
809 if ((u_int) uap->fd >= fdp->fd_nfiles
810 || (fd = fdp->fd_ofiles[uap->fd]) == NULL)
812 if ((fd->f_flag & (FREAD | FWRITE)) == 0)
814 /* first determine whether this is any sort of vnode */
815 if (fd->f_type == DTYPE_VNODE) {
816 /* good, this is a vnode; next see if it is an AFS vnode */
817 # if defined(AFS_OBSD_ENV)
819 IsAfsVnode((struct vnode *)fd->
820 f_data) ? VTOAFS((struct vnode *)fd->f_data) : NULL;
822 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
824 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
825 /* This is an AFS vnode */
826 if (((uap->com >> 8) & 0xff) == 'V') {
827 register struct afs_ioctl *datap;
829 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
830 code = copyin_afs_ioctl((char *)uap->arg, datap);
832 osi_FreeSmallSpace(datap);
836 code = HandleIoctl(tvc, uap->com, datap);
837 osi_FreeSmallSpace(datap);
845 # if defined(AFS_FBSD50_ENV)
846 return ioctl(td, uap);
847 # elif defined(AFS_FBSD_ENV)
848 return ioctl(p, uap);
849 # elif defined(AFS_OBSD_ENV)
850 code = sys_ioctl(p, uap, retval);
856 #elif defined(UKERNEL)
864 } *uap = (struct a *)get_user_struct()->u_ap;
865 register struct file *fd;
866 register struct vcache *tvc;
867 register int ioctlDone = 0, code = 0;
869 AFS_STATCNT(afs_xioctl);
874 /* first determine whether this is any sort of vnode */
875 if (fd->f_type == DTYPE_VNODE) {
876 /* good, this is a vnode; next see if it is an AFS vnode */
877 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
878 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
879 /* This is an AFS vnode */
880 if (((uap->com >> 8) & 0xff) == 'V') {
881 register struct afs_ioctl *datap;
883 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
884 code=copyin_afs_ioctl((char *)uap->arg, datap);
886 osi_FreeSmallSpace(datap);
889 return (setuerror(code), code);
891 code = HandleIoctl(tvc, uap->com, datap);
892 osi_FreeSmallSpace(datap);
905 #endif /* AFS_HPUX102_ENV */
907 #if defined(AFS_SGI_ENV)
908 /* "pioctl" system call entry point; just pass argument to the parameterized
917 afs_pioctl(struct pioctlargs *uap, rval_t * rvp)
921 AFS_STATCNT(afs_pioctl);
923 code = afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow);
925 # ifdef AFS_SGI64_ENV
932 #elif defined(AFS_FBSD50_ENV)
934 afs_pioctl(struct thread *td, void *args, int *retval)
941 } *uap = (struct a *)args;
943 AFS_STATCNT(afs_pioctl);
944 return (afs_syscall_pioctl
945 (uap->path, uap->cmd, uap->cmarg, uap->follow, td->td_ucred));
948 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
950 afs_pioctl(afs_proc_t *p, void *args, int *retval)
957 } *uap = (struct a *)args;
959 AFS_STATCNT(afs_pioctl);
960 # ifdef AFS_DARWIN80_ENV
961 return (afs_syscall_pioctl
962 (uap->path, uap->cmd, uap->cmarg, uap->follow,
965 return (afs_syscall_pioctl
966 (uap->path, uap->cmd, uap->cmarg, uap->follow,
967 p->p_cred->pc_ucred));
973 /* macro to avoid adding any more #ifdef's to pioctl code. */
974 #if defined(AFS_LINUX22_ENV) || defined(AFS_AIX41_ENV)
975 #define PIOCTL_FREE_CRED() crfree(credp)
977 #define PIOCTL_FREE_CRED()
982 afs_syscall_pioctl(char *path, unsigned int com, caddr_t cmarg, int follow,
983 rval_t *vvp, afs_ucred_t *credp)
985 #ifdef AFS_DARWIN100_ENV
986 afs_syscall64_pioctl(user_addr_t path, unsigned int com, user_addr_t cmarg,
987 int follow, afs_ucred_t *credp)
988 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
989 afs_syscall_pioctl(char *path, unsigned int com, caddr_t cmarg, int follow,
992 afs_syscall_pioctl(char *path, unsigned int com, caddr_t cmarg, int follow)
996 struct afs_ioctl data;
997 #ifdef AFS_NEED_CLIENTCONTEXT
998 afs_ucred_t *tmpcred = NULL;
1000 #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)
1001 afs_ucred_t *foreigncreds = NULL;
1003 register afs_int32 code = 0;
1004 struct vnode *vp = NULL;
1005 #ifdef AFS_AIX41_ENV
1006 struct ucred *credp = crref(); /* don't free until done! */
1008 #ifdef AFS_LINUX22_ENV
1009 cred_t *credp = crref(); /* don't free until done! */
1013 AFS_STATCNT(afs_syscall_pioctl);
1015 follow = 1; /* compat. with old venus */
1016 code = copyin_afs_ioctl(cmarg, &data);
1019 #if defined(KERNEL_HAVE_UERROR)
1024 if ((com & 0xff) == PSetClientContext) {
1025 #ifdef AFS_NEED_CLIENTCONTEXT
1026 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV)
1027 code = HandleClientContext(&data, &com, &foreigncreds, credp);
1029 code = HandleClientContext(&data, &com, &foreigncreds, osi_curcred());
1033 crfree(foreigncreds);
1036 #if defined(KERNEL_HAVE_UERROR)
1037 return (setuerror(code), code);
1042 #else /* AFS_NEED_CLIENTCONTEXT */
1044 #endif /* AFS_NEED_CLIENTCONTEXT */
1046 #ifdef AFS_NEED_CLIENTCONTEXT
1049 * We could have done without temporary setting the u.u_cred below
1050 * (foreigncreds could be passed as param the pioctl modules)
1051 * but calls such as afs_osi_suser() doesn't allow that since it
1052 * references u.u_cred directly. We could, of course, do something
1053 * like afs_osi_suser(cred) which, I think, is better since it
1054 * generalizes and supports multi cred environments...
1056 #if defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
1058 credp = foreigncreds;
1059 #elif defined(AFS_AIX41_ENV)
1060 tmpcred = crref(); /* XXX */
1061 crset(foreigncreds);
1062 #elif defined(AFS_HPUX101_ENV)
1063 tmpcred = p_cred(u.u_procp);
1064 set_p_cred(u.u_procp, foreigncreds);
1065 #elif defined(AFS_SGI_ENV)
1066 tmpcred = OSI_GET_CURRENT_CRED();
1067 OSI_SET_CURRENT_CRED(foreigncreds);
1070 u.u_cred = foreigncreds;
1073 #endif /* AFS_NEED_CLIENTCONTEXT */
1074 if ((com & 0xff) == 15) {
1075 /* special case prefetch so entire pathname eval occurs in helper process.
1076 * otherwise, the pioctl call is essentially useless */
1077 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1079 Prefetch(path, &data, follow,
1080 foreigncreds ? foreigncreds : credp);
1082 code = Prefetch(path, &data, follow, osi_curcred());
1085 #if defined(KERNEL_HAVE_UERROR)
1092 #ifdef AFS_AIX41_ENV
1094 lookupname(path, USR, follow, NULL, &vp,
1095 foreigncreds ? foreigncreds : credp);
1097 #ifdef AFS_LINUX22_ENV
1098 code = gop_lookupname_user(path, AFS_UIOUSER, follow, &dp);
1100 vp = (struct vnode *)dp->d_inode;
1102 code = gop_lookupname_user(path, AFS_UIOUSER, follow, &vp);
1103 #if defined(AFS_FBSD80_ENV) /* XXX check on 7x */
1105 #endif /* AFS_FBSD80_ENV */
1106 #endif /* AFS_LINUX22_ENV */
1107 #endif /* AFS_AIX41_ENV */
1111 #if defined(KERNEL_HAVE_UERROR)
1119 #if defined(AFS_SUN510_ENV)
1120 if (vp && !IsAfsVnode(vp)) {
1121 struct vnode *realvp;
1123 #ifdef AFS_SUN511_ENV
1124 (VOP_REALVP(vp, &realvp, NULL) == 0)
1126 (VOP_REALVP(vp, &realvp) == 0)
1129 struct vnode *oldvp = vp;
1137 /* now make the call if we were passed no file, or were passed an AFS file */
1138 if (!vp || IsAfsVnode(vp)) {
1139 #if defined(AFS_SUN5_ENV)
1140 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1141 #elif defined(AFS_AIX41_ENV)
1143 struct ucred *cred1, *cred2;
1146 cred1 = cred2 = foreigncreds;
1148 cred1 = cred2 = credp;
1150 code = afs_HandlePioctl(vp, com, &data, follow, &cred1);
1151 if (cred1 != cred2) {
1152 /* something changed the creds */
1156 #elif defined(AFS_HPUX101_ENV)
1158 struct ucred *cred = p_cred(u.u_procp);
1159 code = afs_HandlePioctl(vp, com, &data, follow, &cred);
1161 #elif defined(AFS_SGI_ENV)
1164 credp = OSI_GET_CURRENT_CRED();
1165 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1167 #elif defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1168 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1169 #elif defined(UKERNEL)
1170 code = afs_HandlePioctl(vp, com, &data, follow,
1171 &(get_user_struct()->u_cred));
1173 code = afs_HandlePioctl(vp, com, &data, follow, &u.u_cred);
1176 #if defined(KERNEL_HAVE_UERROR)
1179 code = EINVAL; /* not in /afs */
1184 #if defined(AFS_NEED_CLIENTCONTEXT)
1186 #ifdef AFS_AIX41_ENV
1187 crset(tmpcred); /* restore original credentials */
1189 #if defined(AFS_HPUX101_ENV)
1190 set_p_cred(u.u_procp, tmpcred); /* restore original credentials */
1191 #elif defined(AFS_SGI_ENV)
1192 OSI_SET_CURRENT_CRED(tmpcred); /* restore original credentials */
1193 #elif defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
1194 credp = tmpcred; /* restore original credentials */
1196 osi_curcred() = tmpcred; /* restore original credentials */
1197 #endif /* AFS_HPUX101_ENV */
1198 crfree(foreigncreds);
1201 #endif /* AFS_NEED_CLIENTCONTEXT */
1203 #ifdef AFS_LINUX22_ENV
1206 #if defined(AFS_FBSD80_ENV)
1207 if (VOP_ISLOCKED(vp))
1209 #endif /* AFS_FBSD80_ENV */
1210 AFS_RELE(vp); /* put vnode back */
1214 #if defined(KERNEL_HAVE_UERROR)
1217 return (getuerror());
1223 #ifdef AFS_DARWIN100_ENV
1225 afs_syscall_pioctl(char * path, unsigned int com, caddr_t cmarg,
1226 int follow, afs_ucred_t *credp)
1228 return afs_syscall64_pioctl(CAST_USER_ADDR_T(path), com,
1229 CAST_USER_ADDR_T((unsigned int)cmarg), follow,
1234 #define MAXPIOCTLTOKENLEN \
1235 (3*sizeof(afs_int32)+MAXKTCTICKETLEN+sizeof(struct ClearToken)+MAXKTCREALMLEN)
1238 afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
1239 register struct afs_ioctl *ablob, int afollow,
1240 afs_ucred_t **acred)
1243 struct vrequest treq;
1244 register afs_int32 code;
1245 register afs_int32 function, device;
1246 struct afs_pdata input, output;
1247 struct afs_pdata copyInput, copyOutput;
1249 pioctlFunction *pioctlSw;
1251 struct afs_fakestat_state fakestate;
1253 memset(&input, 0, sizeof(input));
1254 memset(&output, 0, sizeof(output));
1256 avc = avp ? VTOAFS(avp) : NULL;
1257 afs_Trace3(afs_iclSetp, CM_TRACE_PIOCTL, ICL_TYPE_INT32, acom & 0xff,
1258 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, afollow);
1259 AFS_STATCNT(HandlePioctl);
1261 code = afs_InitReq(&treq, *acred);
1265 afs_InitFakeStat(&fakestate);
1267 code = afs_EvalFakeStat(&avc, &fakestate, &treq);
1271 device = (acom & 0xff00) >> 8;
1273 case 'V': /* Original pioctls */
1274 pioctlSw = VpioctlSw;
1275 pioctlSwSize = sizeof(VpioctlSw);
1277 case 'C': /* Coordinated/common pioctls */
1278 pioctlSw = CpioctlSw;
1279 pioctlSwSize = sizeof(CpioctlSw);
1281 case 'O': /* Coordinated/common pioctls */
1282 pioctlSw = OpioctlSw;
1283 pioctlSwSize = sizeof(OpioctlSw);
1289 function = acom & 0xff;
1290 if (function >= (pioctlSwSize / sizeof(char *))) {
1295 /* Do all range checking before continuing */
1296 if (ablob->in_size > MAXPIOCTLTOKENLEN ||
1297 ablob->in_size < 0 || ablob->out_size < 0) {
1302 code = afs_pd_alloc(&input, ablob->in_size);
1306 if (ablob->in_size > 0) {
1307 AFS_COPYIN(ablob->in, input.ptr, ablob->in_size, code);
1308 input.ptr[input.remaining] = '\0';
1313 if (function == 8 && device == 'V') { /* PGetTokens */
1314 code = afs_pd_alloc(&output, MAXPIOCTLTOKENLEN);
1316 code = afs_pd_alloc(&output, AFS_LRALLOCSIZ);
1322 copyOutput = output;
1325 (*pioctlSw[function]) (avc, function, &treq, ©Input,
1326 ©Output, acred);
1328 outSize = copyOutput.ptr - output.ptr;
1330 if (code == 0 && ablob->out_size > 0) {
1331 if (outSize > ablob->out_size) {
1332 code = E2BIG; /* data wont fit in user buffer */
1333 } else if (outSize) {
1334 AFS_COPYOUT(output.ptr, ablob->out, outSize, code);
1339 afs_pd_free(&input);
1340 afs_pd_free(&output);
1342 afs_PutFakeStat(&fakestate);
1343 return afs_CheckCode(code, &treq, 41);
1347 * VIOCGETFID (22) - Get file ID quickly
1351 * \param[in] ain not in use
1352 * \param[out] aout fid of requested file
1354 * \retval EINVAL Error if some of the initial arguments aren't set
1356 * \post get the file id of some file
1358 DECL_PIOCTL(PGetFID)
1360 AFS_STATCNT(PGetFID);
1363 if (afs_pd_putBytes(aout, &avc->f.fid, sizeof(struct VenusFid)) != 0)
1369 * VIOCSETAL (1) - Set access control list
1373 * \param[in] ain the ACL being set
1374 * \param[out] aout the ACL being set returned
1376 * \retval EINVAL Error if some of the standard args aren't set
1378 * \post Changed ACL, via direct writing to the wire
1380 int dummy_PSetAcl(char *ain, char *aout)
1385 DECL_PIOCTL(PSetAcl)
1387 register afs_int32 code;
1388 struct afs_conn *tconn;
1389 struct AFSOpaque acl;
1390 struct AFSVolSync tsync;
1391 struct AFSFetchStatus OutStatus;
1394 AFS_STATCNT(PSetAcl);
1398 if (afs_pd_getStringPtr(ain, &acl.AFSOpaque_val) != 0)
1400 acl.AFSOpaque_len = strlen(acl.AFSOpaque_val) + 1;
1401 if (acl.AFSOpaque_len > 1024)
1405 tconn = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
1407 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREACL);
1410 RXAFS_StoreACL(tconn->id, (struct AFSFid *)&avc->f.fid.Fid,
1411 &acl, &OutStatus, &tsync);
1416 } while (afs_Analyze
1417 (tconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_STOREACL,
1418 SHARED_LOCK, NULL));
1420 /* now we've forgotten all of the access info */
1421 ObtainWriteLock(&afs_xcbhash, 455);
1423 afs_DequeueCallback(avc);
1424 avc->f.states &= ~(CStatd | CUnique);
1425 ReleaseWriteLock(&afs_xcbhash);
1426 if (avc->f.fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
1427 osi_dnlc_purgedp(avc);
1429 /* SXW - Should we flush metadata here? */
1433 int afs_defaultAsynchrony = 0;
1436 * VIOC_STOREBEHIND (47) Adjust store asynchrony
1440 * \param[in] ain sbstruct (store behind structure) input
1441 * \param[out] aout resulting sbstruct
1444 * Error if the user doesn't have super-user credentials
1446 * Error if there isn't enough access to not check the mode bits
1449 * Changes either the default asynchrony (the amount of data that
1450 * can remain to be written when the cache manager returns control
1451 * to the user), or the asyncrony for the specified file.
1453 DECL_PIOCTL(PStoreBehind)
1455 struct sbstruct sbr;
1457 if (afs_pd_getBytes(ain, &sbr, sizeof(struct sbstruct)) != 0)
1460 if (sbr.sb_default != -1) {
1461 if (afs_osi_suser(*acred))
1462 afs_defaultAsynchrony = sbr.sb_default;
1467 if (avc && (sbr.sb_thisfile != -1)) {
1469 (avc, PRSFS_WRITE | PRSFS_ADMINISTER, areq, DONT_CHECK_MODE_BITS))
1470 avc->asynchrony = sbr.sb_thisfile;
1475 memset(&sbr, 0, sizeof(sbr));
1476 sbr.sb_default = afs_defaultAsynchrony;
1478 sbr.sb_thisfile = avc->asynchrony;
1481 return afs_pd_putBytes(aout, &sbr, sizeof(sbr));
1485 * VIOC_GCPAGS (48) - Disable automatic PAG gc'ing
1489 * \param[in] ain not in use
1490 * \param[out] aout not in use
1492 * \retval EACCES Error if the user doesn't have super-user credentials
1494 * \post set the gcpags to GCPAGS_USERDISABLED
1496 DECL_PIOCTL(PGCPAGs)
1498 if (!afs_osi_suser(*acred)) {
1501 afs_gcpags = AFS_GCPAGS_USERDISABLED;
1506 * VIOCGETAL (2) - Get access control list
1510 * \param[in] ain not in use
1511 * \param[out] aout the ACL
1513 * \retval EINVAL Error if some of the standard args aren't set
1514 * \retval ERANGE Error if the vnode of the file id is too large
1515 * \retval -1 Error if getting the ACL failed
1517 * \post Obtain the ACL, based on file ID
1520 * There is a hack to tell which type of ACL is being returned, checks
1521 * the top 2-bytes of the input size to judge what type of ACL it is,
1522 * only for dfs xlator ACLs
1524 DECL_PIOCTL(PGetAcl)
1526 struct AFSOpaque acl;
1527 struct AFSVolSync tsync;
1528 struct AFSFetchStatus OutStatus;
1530 struct afs_conn *tconn;
1534 AFS_STATCNT(PGetAcl);
1537 Fid.Volume = avc->f.fid.Fid.Volume;
1538 Fid.Vnode = avc->f.fid.Fid.Vnode;
1539 Fid.Unique = avc->f.fid.Fid.Unique;
1540 if (avc->f.states & CForeign) {
1542 * For a dfs xlator acl we have a special hack so that the
1543 * xlator will distinguish which type of acl will return. So
1544 * we currently use the top 2-bytes (vals 0-4) to tell which
1545 * type of acl to bring back. Horrible hack but this will
1546 * cause the least number of changes to code size and interfaces.
1548 if (Fid.Vnode & 0xc0000000)
1550 Fid.Vnode |= (ain->remaining << 30);
1552 acl.AFSOpaque_val = aout->ptr;
1554 tconn = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
1556 acl.AFSOpaque_val[0] = '\0';
1557 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHACL);
1559 code = RXAFS_FetchACL(tconn->id, &Fid, &acl, &OutStatus, &tsync);
1564 } while (afs_Analyze
1565 (tconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_FETCHACL,
1566 SHARED_LOCK, NULL));
1569 if (acl.AFSOpaque_len == 0)
1570 afs_pd_skip(aout, 1); /* leave the NULL */
1572 afs_pd_skip(aout, acl.AFSOpaque_len); /* Length of the ACL */
1578 * PNoop returns success. Used for functions which are not implemented
1579 * or are no longer in use.
1583 * \retval Always returns success
1586 * Functions involved in this:
1587 * 17 (VIOCENGROUP) -- used to be enable group;
1588 * 18 (VIOCDISGROUP) -- used to be disable group;
1589 * 2 (?) -- get/set cache-bypass size threshold
1598 * PBogus returns fail. Used for functions which are not implemented or
1599 * are no longer in use.
1603 * \retval EINVAL Always returns this value
1606 * Functions involved in this:
1612 * 13 (VIOCGETTIME) -- used to be quick check time;
1613 * 15 (VIOCPREFETCH) -- prefetch is now special-cased; see pioctl code!;
1614 * 16 (VIOCNOP) -- used to be testing code;
1615 * 19 (VIOCLISTGROUPS) -- used to be list group;
1616 * 23 (VIOCWAITFOREVER) -- used to be waitforever;
1617 * 57 (VIOC_FPRIOSTATUS) -- arla: set file prio;
1618 * 58 (VIOC_FHGET) -- arla: fallback getfh;
1619 * 59 (VIOC_FHOPEN) -- arla: fallback fhopen;
1620 * 60 (VIOC_XFSDEBUG) -- arla: controls xfsdebug;
1621 * 61 (VIOC_ARLADEBUG) -- arla: controls arla debug;
1622 * 62 (VIOC_AVIATOR) -- arla: debug interface;
1623 * 63 (VIOC_XFSDEBUG_PRINT) -- arla: print xfs status;
1624 * 64 (VIOC_CALCULATE_CACHE) -- arla: force cache check;
1625 * 65 (VIOC_BREAKCELLBACK) -- arla: break callback;
1626 * 68 (?) -- arla: fetch stats;
1630 AFS_STATCNT(PBogus);
1635 * VIOC_FILE_CELL_NAME (30) - Get cell in which file lives
1639 * \param[in] ain not in use (avc used to pass in file id)
1640 * \param[out] aout cell name
1642 * \retval EINVAL Error if some of the standard args aren't set
1643 * \retval ESRCH Error if the file isn't part of a cell
1645 * \post Get a cell based on a passed in file id
1647 DECL_PIOCTL(PGetFileCell)
1649 register struct cell *tcell;
1651 AFS_STATCNT(PGetFileCell);
1654 tcell = afs_GetCell(avc->f.fid.Cell, READ_LOCK);
1658 if (afs_pd_putString(aout, tcell->cellName) != 0)
1661 afs_PutCell(tcell, READ_LOCK);
1666 * VIOC_GET_WS_CELL (31) - Get cell in which workstation lives
1670 * \param[in] ain not in use
1671 * \param[out] aout cell name
1674 * Error if the afs daemon hasn't started yet
1676 * Error if the machine isn't part of a cell, for whatever reason
1678 * \post Get the primary cell that the machine is a part of.
1680 DECL_PIOCTL(PGetWSCell)
1682 struct cell *tcell = NULL;
1684 AFS_STATCNT(PGetWSCell);
1685 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1686 return EIO; /* Inappropriate ioctl for device */
1688 tcell = afs_GetPrimaryCell(READ_LOCK);
1689 if (!tcell) /* no primary cell? */
1692 if (afs_pd_putString(aout, tcell->cellName) != 0)
1694 afs_PutCell(tcell, READ_LOCK);
1699 * VIOC_GET_PRIMARY_CELL (33) - Get primary cell for caller
1703 * \param[in] ain not in use (user id found via areq)
1704 * \param[out] aout cell name
1707 * Error if the user id doesn't have a primary cell specified
1709 * \post Get the primary cell for a certain user, based on the user's uid
1711 DECL_PIOCTL(PGetUserCell)
1713 register afs_int32 i;
1714 register struct unixuser *tu;
1715 register struct cell *tcell;
1717 AFS_STATCNT(PGetUserCell);
1718 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1719 return EIO; /* Inappropriate ioctl for device */
1721 /* return the cell name of the primary cell for this user */
1722 i = UHash(areq->uid);
1723 ObtainWriteLock(&afs_xuser, 224);
1724 for (tu = afs_users[i]; tu; tu = tu->next) {
1725 if (tu->uid == areq->uid && (tu->states & UPrimary)) {
1727 ReleaseWriteLock(&afs_xuser);
1732 tcell = afs_GetCell(tu->cell, READ_LOCK);
1733 afs_PutUser(tu, WRITE_LOCK);
1737 if (afs_pd_putString(aout, tcell->cellName) != 0)
1739 afs_PutCell(tcell, READ_LOCK);
1742 ReleaseWriteLock(&afs_xuser);
1748 * VIOCSETTOK (3) - Set authentication tokens
1752 * \param[in] ain the krb tickets from which to set the afs tokens
1753 * \param[out] aout not in use
1756 * Error if the ticket is either too long or too short
1758 * Error if the AFS initState is below 101
1760 * Error if the cell for which the Token is being set can't be found
1763 * Set the Tokens for a specific cell name, unless there is none set,
1764 * then default to primary
1767 DECL_PIOCTL(PSetTokens)
1770 register struct unixuser *tu;
1771 struct ClearToken clear;
1772 register struct cell *tcell;
1776 struct vrequest treq;
1777 afs_int32 flag, set_parent_pag = 0;
1779 AFS_STATCNT(PSetTokens);
1780 if (!afs_resourceinit_flag) {
1784 if (afs_pd_getInt(ain, &stLen) != 0)
1787 stp = afs_pd_where(ain); /* remember where the ticket is */
1788 if (stLen < 0 || stLen > MAXKTCTICKETLEN)
1789 return EINVAL; /* malloc may fail */
1790 if (afs_pd_skip(ain, stLen) != 0)
1793 if (afs_pd_getInt(ain, &i) != 0)
1795 if (i != sizeof(struct ClearToken))
1798 if (afs_pd_getBytes(ain, &clear, sizeof(struct ClearToken)) !=0)
1801 if (clear.AuthHandle == -1)
1802 clear.AuthHandle = 999; /* more rxvab compat stuff */
1804 if (afs_pd_remaining(ain) != 0) {
1805 /* still stuff left? we've got primary flag and cell name.
1808 if (afs_pd_getInt(ain, &flag) != 0)
1811 /* some versions of gcc appear to need != 0 in order to get this
1813 if ((flag & 0x8000) != 0) { /* XXX Use Constant XXX */
1818 if (afs_pd_getStringPtr(ain, &cellName) != 0)
1821 /* rest is cell name, look it up */
1822 tcell = afs_GetCellByName(cellName, READ_LOCK);
1826 /* default to primary cell, primary id */
1827 flag = 1; /* primary id */
1828 tcell = afs_GetPrimaryCell(READ_LOCK);
1833 afs_PutCell(tcell, READ_LOCK);
1834 if (set_parent_pag) {
1836 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1837 # if defined(AFS_DARWIN_ENV)
1838 afs_proc_t *p = current_proc(); /* XXX */
1840 proc_selfname(procname, 256);
1842 afs_proc_t *p = curproc; /* XXX */
1843 char *procname = p->p_comm;
1845 afs_warnuser("Process %d (%s) tried to change pags in PSetTokens\n",
1846 MyPidxx2Pid(MyPidxx), procname);
1847 if (!setpag(p, acred, -1, &pag, 1)) {
1849 if (!setpag(acred, -1, &pag, 1)) {
1851 afs_InitReq(&treq, *acred);
1855 /* now we just set the tokens */
1856 tu = afs_GetUser(areq->uid, i, WRITE_LOCK); /* i has the cell # */
1857 tu->vid = clear.ViceId;
1858 if (tu->stp != NULL) {
1859 afs_osi_Free(tu->stp, tu->stLen);
1861 tu->stp = (char *)afs_osi_Alloc(stLen);
1862 if (tu->stp == NULL) {
1866 memcpy(tu->stp, stp, stLen);
1869 afs_stats_cmfullperf.authent.TicketUpdates++;
1870 afs_ComputePAGStats();
1871 #endif /* AFS_NOSTATS */
1872 tu->states |= UHasTokens;
1873 tu->states &= ~UTokensBad;
1874 afs_SetPrimary(tu, flag);
1875 tu->tokenTime = osi_Time();
1876 afs_ResetUserConns(tu);
1877 afs_NotifyUser(tu, UTokensObtained);
1878 afs_PutUser(tu, WRITE_LOCK);
1894 * VIOCGETVOLSTAT (4) - Get volume status
1898 * \param[in] ain not in use
1899 * \param[out] aout status of the volume
1901 * \retval EINVAL Error if some of the standard args aren't set
1904 * The status of a volume (based on the FID of the volume), or an
1905 * offline message /motd
1907 DECL_PIOCTL(PGetVolumeStatus)
1910 char *offLineMsg = afs_osi_Alloc(256);
1911 char *motd = afs_osi_Alloc(256);
1912 register struct afs_conn *tc;
1913 register afs_int32 code = 0;
1914 struct AFSFetchVolumeStatus volstat;
1918 AFS_STATCNT(PGetVolumeStatus);
1925 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
1927 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS);
1930 RXAFS_GetVolumeStatus(tc->id, avc->f.fid.Fid.Volume, &volstat,
1931 &Name, &offLineMsg, &motd);
1936 } while (afs_Analyze
1937 (tc, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS,
1938 SHARED_LOCK, NULL));
1942 /* Copy all this junk into msg->im_data, keeping track of the lengths. */
1943 if (afs_pd_putBytes(aout, &volstat, sizeof(VolumeStatus)) != 0)
1945 if (afs_pd_putString(aout, volName) != 0)
1947 if (afs_pd_putString(aout, offLineMsg) != 0)
1949 if (afs_pd_putString(aout, motd) != 0)
1952 afs_osi_Free(offLineMsg, 256);
1953 afs_osi_Free(motd, 256);
1958 * VIOCSETVOLSTAT (5) - Set volume status
1963 * values to set the status at, offline message, message of the day,
1964 * volume name, minimum quota, maximum quota
1966 * status of a volume, offlines messages, minimum quota, maximumm quota
1969 * Error if some of the standard args aren't set
1971 * Error if the volume is read only, or a backup volume
1973 * Error if the volume can't be accessed
1975 * Error if the volume name, offline message, and motd are too big
1978 * Set the status of a volume, including any offline messages,
1979 * a minimum quota, and a maximum quota
1981 DECL_PIOCTL(PSetVolumeStatus)
1986 register struct afs_conn *tc;
1987 register afs_int32 code = 0;
1988 struct AFSFetchVolumeStatus volstat;
1989 struct AFSStoreVolumeStatus storeStat;
1990 register struct volume *tvp;
1993 AFS_STATCNT(PSetVolumeStatus);
1997 tvp = afs_GetVolume(&avc->f.fid, areq, READ_LOCK);
1999 if (tvp->states & (VRO | VBackup)) {
2000 afs_PutVolume(tvp, READ_LOCK);
2003 afs_PutVolume(tvp, READ_LOCK);
2008 if (afs_pd_getBytes(ain, &volstat, sizeof(AFSFetchVolumeStatus)) != 0)
2011 if (afs_pd_getStringPtr(ain, &volName) != 0)
2013 if (strlen(volName) > 32)
2016 if (afs_pd_getStringPtr(ain, &offLineMsg) != 0)
2018 if (strlen(offLineMsg) > 256)
2021 if (afs_pd_getStringPtr(ain, &motd) != 0)
2023 if (strlen(motd) > 256)
2026 /* Done reading ... */
2029 if (volstat.MinQuota != -1) {
2030 storeStat.MinQuota = volstat.MinQuota;
2031 storeStat.Mask |= AFS_SETMINQUOTA;
2033 if (volstat.MaxQuota != -1) {
2034 storeStat.MaxQuota = volstat.MaxQuota;
2035 storeStat.Mask |= AFS_SETMAXQUOTA;
2038 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
2040 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS);
2043 RXAFS_SetVolumeStatus(tc->id, avc->f.fid.Fid.Volume, &storeStat,
2044 volName, offLineMsg, motd);
2049 } while (afs_Analyze
2050 (tc, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS,
2051 SHARED_LOCK, NULL));
2055 /* we are sending parms back to make compat. with prev system. should
2056 * change interface later to not ask for current status, just set new
2059 if (afs_pd_putBytes(aout, &volstat, sizeof(VolumeStatus)) != 0)
2061 if (afs_pd_putString(aout, volName) != 0)
2063 if (afs_pd_putString(aout, offLineMsg) != 0)
2065 if (afs_pd_putString(aout, motd) != 0)
2072 * VIOCFLUSH (6) - Invalidate cache entry
2076 * \param[in] ain not in use
2077 * \param[out] aout not in use
2079 * \retval EINVAL Error if some of the standard args aren't set
2081 * \post Flush any information the cache manager has on an entry
2085 AFS_STATCNT(PFlush);
2088 #ifdef AFS_BOZONLOCK_ENV
2089 afs_BozonLock(&avc->pvnLock, avc); /* Since afs_TryToSmush will do a pvn_vptrunc */
2091 ObtainWriteLock(&avc->lock, 225);
2092 afs_ResetVCache(avc, *acred);
2093 ReleaseWriteLock(&avc->lock);
2094 #ifdef AFS_BOZONLOCK_ENV
2095 afs_BozonUnlock(&avc->pvnLock, avc);
2101 * VIOC_AFS_STAT_MT_PT (29) - Stat mount point
2106 * the last component in a path, related to mountpoint that we're
2107 * looking for information about
2109 * volume, cell, link data
2111 * \retval EINVAL Error if some of the standard args aren't set
2112 * \retval ENOTDIR Error if the 'mount point' argument isn't a directory
2113 * \retval EIO Error if the link data can't be accessed
2115 * \post Get the volume, and cell, as well as the link data for a mount point
2117 DECL_PIOCTL(PNewStatMount)
2119 register afs_int32 code;
2120 register struct vcache *tvc;
2121 register struct dcache *tdc;
2122 struct VenusFid tfid;
2125 struct sysname_info sysState;
2126 afs_size_t offset, len;
2128 AFS_STATCNT(PNewStatMount);
2132 if (afs_pd_getStringPtr(ain, &name) != 0)
2135 code = afs_VerifyVCache(avc, areq);
2138 if (vType(avc) != VDIR) {
2141 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
2144 Check_AtSys(avc, name, &sysState, areq);
2145 ObtainReadLock(&tdc->lock);
2147 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
2148 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
2149 ReleaseReadLock(&tdc->lock);
2150 afs_PutDCache(tdc); /* we're done with the data */
2151 bufp = sysState.name;
2155 tfid.Cell = avc->f.fid.Cell;
2156 tfid.Fid.Volume = avc->f.fid.Fid.Volume;
2157 if (!tfid.Fid.Unique && (avc->f.states & CForeign)) {
2158 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
2160 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
2166 if (tvc->mvstat != 1) {
2171 ObtainWriteLock(&tvc->lock, 226);
2172 code = afs_HandleLink(tvc, areq);
2174 if (tvc->linkData) {
2175 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
2178 /* we have the data */
2179 if (afs_pd_putString(aout, tvc->linkData) != 0)
2185 ReleaseWriteLock(&tvc->lock);
2188 if (sysState.allocked)
2189 osi_FreeLargeSpace(bufp);
2194 * VIOCGETTOK (8) - Get authentication tokens
2198 * \param[in] ain cellid to return tokens for
2199 * \param[out] aout token
2202 * Error if the afs daemon hasn't started yet
2204 * Error if the input parameter is out of the bounds of the available
2207 * Error if there aren't tokens for this cell
2210 * If the input paramater exists, get the token that corresponds to
2211 * the parameter value, if there is no token at this value, get the
2212 * token for the first cell
2214 * \notes "it's a weird interface (from comments in the code)"
2217 DECL_PIOCTL(PGetTokens)
2219 register struct cell *tcell;
2220 register afs_int32 i;
2221 register struct unixuser *tu;
2222 afs_int32 iterator = 0;
2226 AFS_STATCNT(PGetTokens);
2227 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2228 return EIO; /* Inappropriate ioctl for device */
2230 /* weird interface. If input parameter is present, it is an integer and
2231 * we're supposed to return the parm'th tokens for this unix uid.
2232 * If not present, we just return tokens for cell 1.
2233 * If counter out of bounds, return EDOM.
2234 * If no tokens for the particular cell, return ENOTCONN.
2235 * Also, if this mysterious parm is present, we return, along with the
2236 * tokens, the primary cell indicator (an afs_int32 0) and the cell name
2237 * at the end, in that order.
2239 newStyle = (afs_pd_remaining(ain) > 0);
2241 if (afs_pd_getInt(ain, &iterator) != 0)
2244 i = UHash(areq->uid);
2245 ObtainReadLock(&afs_xuser);
2246 for (tu = afs_users[i]; tu; tu = tu->next) {
2248 if (tu->uid == areq->uid && (tu->states & UHasTokens)) {
2249 if (iterator-- == 0)
2250 break; /* are we done yet? */
2253 if (tu->uid == areq->uid && afs_IsPrimaryCellNum(tu->cell))
2259 * No need to hold a read lock on each user entry
2263 ReleaseReadLock(&afs_xuser);
2268 if (((tu->states & UHasTokens) == 0)
2269 || (tu->ct.EndTimestamp < osi_Time())) {
2270 tu->states |= (UTokensBad | UNeedsReset);
2271 afs_NotifyUser(tu, UTokensDropped);
2272 afs_PutUser(tu, READ_LOCK);
2275 iterator = tu->stLen; /* for compat, we try to return 56 byte tix if they fit */
2277 iterator = 56; /* # of bytes we're returning */
2279 if (afs_pd_putInt(aout, iterator) != 0)
2281 if (afs_pd_putBytes(aout, tu->stp, tu->stLen) != 0)
2283 if (tu->stLen < 56) {
2284 /* Tokens are always 56 bytes or larger */
2285 if (afs_pd_skip(aout, iterator - tu->stLen) != 0) {
2290 if (afs_pd_putInt(aout, sizeof(struct ClearToken)) != 0)
2292 if (afs_pd_putBytes(aout, &tu->ct, sizeof(struct ClearToken)) != 0)
2296 /* put out primary id and cell name, too */
2297 iterator = (tu->states & UPrimary ? 1 : 0);
2298 if (afs_pd_putInt(aout, iterator) != 0)
2300 tcell = afs_GetCell(tu->cell, READ_LOCK);
2302 if (afs_pd_putString(aout, tcell->cellName) != 0)
2304 afs_PutCell(tcell, READ_LOCK);
2306 if (afs_pd_putString(aout, "") != 0)
2309 /* Got here, all is good */
2312 afs_PutUser(tu, READ_LOCK);
2317 * VIOCUNLOG (9) - Invalidate tokens
2321 * \param[in] ain not in use
2322 * \param[out] aout not in use
2324 * \retval EIO Error if the afs daemon hasn't been started yet
2326 * \post remove tokens from a user, specified by the user id
2328 * \notes sets the token's time to 0, which then causes it to be removed
2329 * \notes Unlog is the same as un-pag in OpenAFS
2333 register afs_int32 i;
2334 register struct unixuser *tu;
2336 AFS_STATCNT(PUnlog);
2337 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2338 return EIO; /* Inappropriate ioctl for device */
2340 i = UHash(areq->uid);
2341 ObtainWriteLock(&afs_xuser, 227);
2342 for (tu = afs_users[i]; tu; tu = tu->next) {
2343 if (tu->uid == areq->uid) {
2345 tu->states &= ~UHasTokens;
2346 /* security is not having to say you're sorry */
2347 memset(&tu->ct, 0, sizeof(struct ClearToken));
2349 ReleaseWriteLock(&afs_xuser);
2350 afs_NotifyUser(tu, UTokensDropped);
2351 /* We have to drop the lock over the call to afs_ResetUserConns,
2352 * since it obtains the afs_xvcache lock. We could also keep
2353 * the lock, and modify ResetUserConns to take parm saying we
2354 * obtained the lock already, but that is overkill. By keeping
2355 * the "tu" pointer held over the released lock, we guarantee
2356 * that we won't lose our place, and that we'll pass over
2357 * every user conn that existed when we began this call.
2359 afs_ResetUserConns(tu);
2361 ObtainWriteLock(&afs_xuser, 228);
2363 /* set the expire times to 0, causes
2364 * afs_GCUserData to remove this entry
2366 tu->ct.EndTimestamp = 0;
2368 #endif /* UKERNEL */
2371 ReleaseWriteLock(&afs_xuser);
2376 * VIOC_AFS_MARINER_HOST (32) - Get/set mariner (cache manager monitor) host
2380 * \param[in] ain host address to be set
2381 * \param[out] aout old host address
2384 * depending on whether or not a variable is set, either get the host
2385 * for the cache manager monitor, or set the old address and give it
2388 * \notes Errors turn off mariner
2390 DECL_PIOCTL(PMariner)
2392 afs_int32 newHostAddr;
2393 afs_int32 oldHostAddr;
2395 AFS_STATCNT(PMariner);
2397 memcpy((char *)&oldHostAddr, (char *)&afs_marinerHost,
2400 oldHostAddr = 0xffffffff; /* disabled */
2402 if (afs_pd_getInt(ain, &newHostAddr) != 0)
2405 if (newHostAddr == 0xffffffff) {
2406 /* disable mariner operations */
2408 } else if (newHostAddr) {
2410 afs_marinerHost = newHostAddr;
2413 if (afs_pd_putInt(aout, oldHostAddr) != 0)
2420 * VIOCCKSERV (10) - Check that servers are up
2424 * \param[in] ain name of the cell
2425 * \param[out] aout current down server list
2427 * \retval EIO Error if the afs daemon hasn't started yet
2428 * \retval EACCES Error if the user doesn't have super-user credentials
2429 * \retval ENOENT Error if we are unable to obtain the cell
2432 * Either a fast check (where it doesn't contact servers) or a
2433 * local check (checks local cell only)
2435 DECL_PIOCTL(PCheckServers)
2438 register struct server *ts;
2440 char *cellName = NULL;
2442 struct chservinfo *pcheck;
2444 AFS_STATCNT(PCheckServers);
2446 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2447 return EIO; /* Inappropriate ioctl for device */
2449 /* This is tricky, because we need to peak at the datastream to see
2450 * what we're getting. For now, let's cheat. */
2452 /* ain contains either an int32 or a string */
2453 if (ain->remaining == 0)
2456 if (*(afs_int32 *)ain->ptr == 0x12345678) { /* For afs3.3 version */
2457 pcheck = afs_pd_inline(ain, sizeof(*pcheck));
2461 if (pcheck->tinterval >= 0) {
2462 if (afs_pd_putInt(aout, afs_probe_interval) != 0)
2464 if (pcheck->tinterval > 0) {
2465 if (!afs_osi_suser(*acred))
2467 afs_probe_interval = pcheck->tinterval;
2471 temp = pcheck->tflags;
2473 cellName = pcheck->tbuffer;
2474 } else { /* For pre afs3.3 versions */
2475 if (afs_pd_getInt(ain, &temp) != 0)
2477 if (afs_pd_remaining(ain) > 0) {
2478 if (afs_pd_getStringPtr(ain, &cellName) != 0)
2484 * 1: fast check, don't contact servers.
2485 * 2: local cell only.
2488 /* have cell name, too */
2489 cellp = afs_GetCellByName(cellName, READ_LOCK);
2494 if (!cellp && (temp & 2)) {
2495 /* use local cell */
2496 cellp = afs_GetPrimaryCell(READ_LOCK);
2498 if (!(temp & 1)) { /* if not fast, call server checker routine */
2499 afs_CheckServers(1, cellp); /* check down servers */
2500 afs_CheckServers(0, cellp); /* check up servers */
2502 /* now return the current down server list */
2503 ObtainReadLock(&afs_xserver);
2504 for (i = 0; i < NSERVERS; i++) {
2505 for (ts = afs_servers[i]; ts; ts = ts->next) {
2506 if (cellp && ts->cell != cellp)
2507 continue; /* cell spec'd and wrong */
2508 if ((ts->flags & SRVR_ISDOWN)
2509 && ts->addr->sa_portal != ts->cell->vlport) {
2510 afs_pd_putInt(aout, ts->addr->sa_ip);
2514 ReleaseReadLock(&afs_xserver);
2516 afs_PutCell(cellp, READ_LOCK);
2521 * VIOCCKBACK (11) - Check backup volume mappings
2525 * \param[in] ain not in use
2526 * \param[out] aout not in use
2528 * \retval EIO Error if the afs daemon hasn't started yet
2531 * Check the root volume, and then check the names if the volume
2532 * check variable is set to force, has expired, is busy, or if
2533 * the mount points variable is set
2535 DECL_PIOCTL(PCheckVolNames)
2537 AFS_STATCNT(PCheckVolNames);
2538 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2539 return EIO; /* Inappropriate ioctl for device */
2541 afs_CheckRootVolume();
2542 afs_CheckVolumeNames(AFS_VOLCHECK_FORCE | AFS_VOLCHECK_EXPIRED |
2543 AFS_VOLCHECK_BUSY | AFS_VOLCHECK_MTPTS);
2548 * VIOCCKCONN (12) - Check connections for a user
2552 * \param[in] ain not in use
2553 * \param[out] aout not in use
2556 * Error if no user is specififed, the user has no tokens set,
2557 * or if the user's tokens are bad
2560 * check to see if a user has the correct authentication.
2561 * If so, allow access.
2563 * \notes Check the connections to all the servers specified
2565 DECL_PIOCTL(PCheckAuth)
2569 struct afs_conn *tc;
2570 struct unixuser *tu;
2573 AFS_STATCNT(PCheckAuth);
2574 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2575 return EIO; /* Inappropriate ioctl for device */
2578 tu = afs_GetUser(areq->uid, 1, READ_LOCK); /* check local cell authentication */
2582 /* we have a user */
2583 ObtainReadLock(&afs_xsrvAddr);
2584 ObtainReadLock(&afs_xconn);
2586 /* any tokens set? */
2587 if ((tu->states & UHasTokens) == 0)
2589 /* all connections in cell 1 working? */
2590 for (i = 0; i < NSERVERS; i++) {
2591 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2592 for (tc = sa->conns; tc; tc = tc->next) {
2593 if (tc->user == tu && (tu->states & UTokensBad))
2598 ReleaseReadLock(&afs_xsrvAddr);
2599 ReleaseReadLock(&afs_xconn);
2600 afs_PutUser(tu, READ_LOCK);
2602 if (afs_pd_putInt(aout, retValue) != 0)
2608 Prefetch(uparmtype apath, struct afs_ioctl *adata, int afollow,
2612 register afs_int32 code;
2613 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2619 AFS_STATCNT(Prefetch);
2622 tp = osi_AllocLargeSpace(1024);
2623 AFS_COPYINSTR(apath, tp, 1024, &bufferSize, code);
2625 osi_FreeLargeSpace(tp);
2628 if (afs_BBusy()) { /* do this as late as possible */
2629 osi_FreeLargeSpace(tp);
2630 return EWOULDBLOCK; /* pretty close */
2632 afs_BQueue(BOP_PATH, (struct vcache *)0, 0, 0, acred, (afs_size_t) 0,
2633 (afs_size_t) 0, tp, (void *)0, (void *)0);
2638 * VIOCWHEREIS (14) - Find out where a volume is located
2642 * \param[in] ain not in use
2643 * \param[out] aout volume location
2645 * \retval EINVAL Error if some of the default arguments don't exist
2646 * \retval ENODEV Error if there is no such volume
2648 * \post fine a volume, based on a volume file id
2650 * \notes check each of the servers specified
2652 DECL_PIOCTL(PFindVolume)
2654 register struct volume *tvp;
2655 register struct server *ts;
2656 register afs_int32 i;
2659 AFS_STATCNT(PFindVolume);
2662 tvp = afs_GetVolume(&avc->f.fid, areq, READ_LOCK);
2666 for (i = 0; i < AFS_MAXHOSTS; i++) {
2667 ts = tvp->serverHost[i];
2670 if (afs_pd_putInt(aout, ts->addr->sa_ip) != 0) {
2675 if (i < AFS_MAXHOSTS) {
2676 /* still room for terminating NULL, add it on */
2677 if (afs_pd_putInt(aout, 0) != 0) {
2683 afs_PutVolume(tvp, READ_LOCK);
2688 * VIOCACCESS (20) - Access using PRS_FS bits
2692 * \param[in] ain PRS_FS bits
2693 * \param[out] aout not in use
2695 * \retval EINVAL Error if some of the initial arguments aren't set
2696 * \retval EACCES Error if access is denied
2698 * \post check to make sure access is allowed
2700 DECL_PIOCTL(PViceAccess)
2702 register afs_int32 code;
2705 AFS_STATCNT(PViceAccess);
2709 code = afs_VerifyVCache(avc, areq);
2713 if (afs_pd_getInt(ain, &temp) != 0)
2716 code = afs_AccessOK(avc, temp, areq, CHECK_MODE_BITS);
2724 * VIOC_GETPAG (13) - Get PAG value
2728 * \param[in] ain not in use
2729 * \param[out] aout PAG value or NOPAG
2731 * \post get PAG value for the caller's cred
2733 DECL_PIOCTL(PGetPAG)
2737 pag = PagInCred(*acred);
2739 return afs_pd_putInt(aout, pag);
2742 DECL_PIOCTL(PPrecache)
2746 /*AFS_STATCNT(PPrecache);*/
2747 if (!afs_osi_suser(*acred))
2750 if (afs_pd_getInt(ain, &newValue) != 0)
2753 afs_preCache = newValue*1024;
2758 * VIOCSETCACHESIZE (24) - Set venus cache size in 1000 units
2762 * \param[in] ain the size the venus cache should be set to
2763 * \param[out] aout not in use
2765 * \retval EACCES Error if the user doesn't have super-user credentials
2766 * \retval EROFS Error if the cache is set to be in memory
2769 * Set the cache size based on user input. If no size is given,
2770 * set it to the default OpenAFS cache size.
2773 * recompute the general cache parameters for every single block allocated
2775 DECL_PIOCTL(PSetCacheSize)
2780 AFS_STATCNT(PSetCacheSize);
2782 if (!afs_osi_suser(*acred))
2784 /* too many things are setup initially in mem cache version */
2785 if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
2787 if (afs_pd_getInt(ain, &newValue) != 0)
2790 afs_cacheBlocks = afs_stats_cmperf.cacheBlocksOrig;
2792 if (newValue < afs_min_cache)
2793 afs_cacheBlocks = afs_min_cache;
2795 afs_cacheBlocks = newValue;
2797 afs_stats_cmperf.cacheBlocksTotal = afs_cacheBlocks;
2798 afs_ComputeCacheParms(); /* recompute basic cache parameters */
2799 afs_MaybeWakeupTruncateDaemon();
2800 while (waitcnt++ < 100 && afs_cacheBlocks < afs_blocksUsed) {
2801 afs_osi_Wait(1000, 0, 0);
2802 afs_MaybeWakeupTruncateDaemon();
2807 #define MAXGCSTATS 16
2809 * VIOCGETCACHEPARMS (40) - Get cache stats
2813 * \param[in] ain afs index flags
2814 * \param[out] aout cache blocks, blocks used, blocks files (in an array)
2816 * \post Get the cache blocks, and how many of the cache blocks there are
2818 DECL_PIOCTL(PGetCacheSize)
2820 afs_int32 results[MAXGCSTATS];
2822 register struct dcache * tdc;
2825 AFS_STATCNT(PGetCacheSize);
2827 if (afs_pd_remaining(ain) == sizeof(afs_int32)) {
2828 afs_pd_getInt(ain, &flags); /* can't error, we just checked size */
2829 } else if (afs_pd_remaining(ain) == 0) {
2835 memset(results, 0, sizeof(results));
2836 results[0] = afs_cacheBlocks;
2837 results[1] = afs_blocksUsed;
2838 results[2] = afs_cacheFiles;
2841 for (i = 0; i < afs_cacheFiles; i++) {
2842 if (afs_indexFlags[i] & IFFree) results[3]++;
2844 } else if (2 == flags){
2845 for (i = 0; i < afs_cacheFiles; i++) {
2846 if (afs_indexFlags[i] & IFFree) results[3]++;
2847 if (afs_indexFlags[i] & IFEverUsed) results[4]++;
2848 if (afs_indexFlags[i] & IFDataMod) results[5]++;
2849 if (afs_indexFlags[i] & IFDirtyPages) results[6]++;
2850 if (afs_indexFlags[i] & IFAnyPages) results[7]++;
2851 if (afs_indexFlags[i] & IFDiscarded) results[8]++;
2853 tdc = afs_indexTable[i];
2856 size = tdc->validPos;
2857 if ( 0 < size && size < (1<<12) ) results[10]++;
2858 else if (size < (1<<14) ) results[11]++;
2859 else if (size < (1<<16) ) results[12]++;
2860 else if (size < (1<<18) ) results[13]++;
2861 else if (size < (1<<20) ) results[14]++;
2862 else if (size >= (1<<20) ) results[15]++;
2866 return afs_pd_putBytes(aout, results, sizeof(results));
2870 * VIOCFLUSHCB (25) - Flush callback only
2874 * \param[in] ain not in use
2875 * \param[out] aout not in use
2877 * \retval EINVAL Error if some of the standard args aren't set
2878 * \retval 0 0 returned if the volume is set to read-only
2881 * Flushes callbacks, by setting the length of callbacks to one,
2882 * setting the next callback to be sent to the CB_DROPPED value,
2883 * and then dequeues everything else.
2885 DECL_PIOCTL(PRemoveCallBack)
2887 register struct afs_conn *tc;
2888 register afs_int32 code = 0;
2889 struct AFSCallBack CallBacks_Array[1];
2890 struct AFSCBFids theFids;
2891 struct AFSCBs theCBs;
2894 AFS_STATCNT(PRemoveCallBack);
2897 if (avc->f.states & CRO)
2898 return 0; /* read-only-ness can't change */
2899 ObtainWriteLock(&avc->lock, 229);
2900 theFids.AFSCBFids_len = 1;
2901 theCBs.AFSCBs_len = 1;
2902 theFids.AFSCBFids_val = (struct AFSFid *)&avc->f.fid.Fid;
2903 theCBs.AFSCBs_val = CallBacks_Array;
2904 CallBacks_Array[0].CallBackType = CB_DROPPED;
2905 if (avc->callback) {
2907 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
2909 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
2911 code = RXAFS_GiveUpCallBacks(tc->id, &theFids, &theCBs);
2915 /* don't set code on failure since we wouldn't use it */
2916 } while (afs_Analyze
2917 (tc, code, &avc->f.fid, areq,
2918 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK, NULL));
2920 ObtainWriteLock(&afs_xcbhash, 457);
2921 afs_DequeueCallback(avc);
2923 avc->f.states &= ~(CStatd | CUnique);
2924 ReleaseWriteLock(&afs_xcbhash);
2925 if (avc->f.fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
2926 osi_dnlc_purgedp(avc);
2928 ReleaseWriteLock(&avc->lock);
2933 * VIOCNEWCELL (26) - Configure new cell
2938 * the name of the cell, the hosts that will be a part of the cell,
2939 * whether or not it's linked with another cell, the other cell it's
2940 * linked with, the file server port, and the volume server port
2944 * \retval EIO Error if the afs daemon hasn't started yet
2945 * \retval EACCES Error if the user doesn't have super-user cedentials
2946 * \retval EINVAL Error if some 'magic' var doesn't have a certain bit set
2948 * \post creates a new cell
2950 DECL_PIOCTL(PNewCell)
2952 afs_int32 cellHosts[AFS_MAXCELLHOSTS], magic = 0;
2953 char *newcell = NULL;
2954 char *linkedcell = NULL;
2956 afs_int32 linkedstate = 0;
2957 afs_int32 fsport = 0, vlport = 0;
2960 AFS_STATCNT(PNewCell);
2961 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2962 return EIO; /* Inappropriate ioctl for device */
2964 if (!afs_osi_suser(*acred))
2967 if (afs_pd_getInt(ain, &magic) != 0)
2969 if (magic != 0x12345678)
2972 /* A 3.4 fs newcell command will pass an array of AFS_MAXCELLHOSTS
2973 * server addresses while the 3.5 fs newcell command passes
2974 * AFS_MAXHOSTS. To figure out which is which, check if the cellname
2977 * This whole logic is bogus, because it relies on the newer command
2978 * sending its 12th address as 0.
2980 if ((afs_pd_remaining(ain) < AFS_MAXCELLHOSTS +3) * sizeof(afs_int32))
2983 newcell = afs_pd_where(ain) + (AFS_MAXCELLHOSTS + 3) * sizeof(afs_int32);
2984 if (newcell[0] != '\0') {
2987 skip = AFS_MAXHOSTS - AFS_MAXCELLHOSTS;
2990 /* AFS_MAXCELLHOSTS (=8) is less than AFS_MAXHOSTS (=13) */
2991 if (afs_pd_getBytes(ain, &cellHosts,
2992 AFS_MAXCELLHOSTS * sizeof(afs_int32)) != 0)
2994 if (afs_pd_skip(ain, skip * sizeof(afs_int32)) !=0)
2997 if (afs_pd_getInt(ain, &fsport) != 0)
3000 fsport = 0; /* Privileged ports not allowed */
3002 if (afs_pd_getInt(ain, &vlport) != 0)
3005 vlport = 0; /* Privileged ports not allowed */
3007 if (afs_pd_getInt(ain, &ls) != 0)
3010 if (afs_pd_getStringPtr(ain, &newcell) != 0)
3014 if (afs_pd_getStringPtr(ain, &linkedcell) != 0)
3016 linkedstate |= CLinkedCell;
3019 linkedstate |= CNoSUID; /* setuid is disabled by default for fs newcell */
3021 afs_NewCell(newcell, cellHosts, linkedstate, linkedcell, fsport,
3026 DECL_PIOCTL(PNewAlias)
3028 /* create a new cell alias */
3029 char *realName, *aliasName;
3031 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3032 return EIO; /* Inappropriate ioctl for device */
3034 if (!afs_osi_suser(*acred))
3037 if (afs_pd_getStringPtr(ain, &aliasName) != 0)
3039 if (afs_pd_getStringPtr(ain, &realName) != 0)
3042 return afs_NewCellAlias(aliasName, realName);
3046 * VIOCGETCELL (27) - Get cell info
3050 * \param[in] ain The cell index of a specific cell
3051 * \param[out] aout list of servers in the cell
3053 * \retval EIO Error if the afs daemon hasn't started yet
3054 * \retval EDOM Error if there is no cell asked about
3056 * \post Lists the cell's server names and and addresses
3058 DECL_PIOCTL(PListCells)
3060 afs_int32 whichCell;
3061 register struct cell *tcell = 0;
3062 register afs_int32 i;
3065 AFS_STATCNT(PListCells);
3066 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3067 return EIO; /* Inappropriate ioctl for device */
3069 if (afs_pd_getInt(ain, &whichCell) != 0)
3072 tcell = afs_GetCellByIndex(whichCell, READ_LOCK);
3078 for (i = 0; i < AFS_MAXCELLHOSTS; i++) {
3079 if (tcell->cellHosts[i] == 0)
3081 if (afs_pd_putInt(aout, tcell->cellHosts[i]->addr->sa_ip) != 0)
3084 for (;i < AFS_MAXCELLHOSTS; i++) {
3085 if (afs_pd_putInt(aout, 0) != 0)
3088 if (afs_pd_putString(aout, tcell->cellName) != 0)
3093 afs_PutCell(tcell, READ_LOCK);
3097 DECL_PIOCTL(PListAliases)
3099 afs_int32 whichAlias;
3100 register struct cell_alias *tcalias = 0;
3103 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3104 return EIO; /* Inappropriate ioctl for device */
3106 if (afs_pd_getInt(ain, &whichAlias) != 0)
3109 tcalias = afs_GetCellAlias(whichAlias);
3110 if (tcalias == NULL)
3114 if (afs_pd_putString(aout, tcalias->alias) != 0)
3116 if (afs_pd_putString(aout, tcalias->cell) != 0)
3121 afs_PutCellAlias(tcalias);
3126 * VIOC_AFS_DELETE_MT_PT (28) - Delete mount point
3130 * \param[in] ain the name of the file in this dir to remove
3131 * \param[out] aout not in use
3134 * Error if some of the standard args aren't set
3136 * Error if the argument to remove is not a directory
3138 * Error if there is no cache to remove the mount point from or
3139 * if a vcache doesn't exist
3142 * Ensure that everything is OK before deleting the mountpoint.
3143 * If not, don't delete. Delete a mount point based on a file id.
3145 DECL_PIOCTL(PRemoveMount)
3147 register afs_int32 code;
3150 struct sysname_info sysState;
3151 afs_size_t offset, len;
3152 register struct afs_conn *tc;
3153 register struct dcache *tdc;
3154 register struct vcache *tvc;
3155 struct AFSFetchStatus OutDirStatus;
3156 struct VenusFid tfid;
3157 struct AFSVolSync tsync;
3160 /* "ain" is the name of the file in this dir to remove */
3162 AFS_STATCNT(PRemoveMount);
3165 if (afs_pd_getStringPtr(ain, &name) != 0)
3168 code = afs_VerifyVCache(avc, areq);
3171 if (vType(avc) != VDIR)
3174 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1); /* test for error below */
3177 Check_AtSys(avc, name, &sysState, areq);
3178 ObtainReadLock(&tdc->lock);
3180 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
3181 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
3182 ReleaseReadLock(&tdc->lock);
3183 bufp = sysState.name;
3188 tfid.Cell = avc->f.fid.Cell;
3189 tfid.Fid.Volume = avc->f.fid.Fid.Volume;
3190 if (!tfid.Fid.Unique && (avc->f.states & CForeign)) {
3191 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
3193 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3200 if (tvc->mvstat != 1) {
3206 ObtainWriteLock(&tvc->lock, 230);
3207 code = afs_HandleLink(tvc, areq);
3209 if (tvc->linkData) {
3210 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
3215 ReleaseWriteLock(&tvc->lock);
3216 osi_dnlc_purgedp(tvc);
3222 ObtainWriteLock(&avc->lock, 231);
3223 osi_dnlc_remove(avc, bufp, tvc);
3225 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
3227 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE);
3230 RXAFS_RemoveFile(tc->id, (struct AFSFid *)&avc->f.fid.Fid, bufp,
3231 &OutDirStatus, &tsync);
3236 } while (afs_Analyze
3237 (tc, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_REMOVEFILE,
3238 SHARED_LOCK, NULL));
3243 ReleaseWriteLock(&avc->lock);
3247 /* we have the thing in the cache */
3248 ObtainWriteLock(&tdc->lock, 661);
3249 if (afs_LocalHero(avc, tdc, &OutDirStatus, 1)) {
3250 /* we can do it locally */
3251 code = afs_dir_Delete(tdc, bufp);
3253 ZapDCE(tdc); /* surprise error -- invalid value */
3257 ReleaseWriteLock(&tdc->lock);
3258 afs_PutDCache(tdc); /* drop ref count */
3260 avc->f.states &= ~CUnique; /* For the dfs xlator */
3261 ReleaseWriteLock(&avc->lock);
3264 if (sysState.allocked)
3265 osi_FreeLargeSpace(bufp);
3270 * VIOC_GETCELLSTATUS (35) - Get cell status info
3274 * \param[in] ain The cell you want status information on
3275 * \param[out] aout cell state (as a struct)
3277 * \retval EIO Error if the afs daemon hasn't started yet
3278 * \retval ENOENT Error if the cell doesn't exist
3280 * \post Returns the state of the cell as defined in a struct cell
3282 DECL_PIOCTL(PGetCellStatus)
3284 register struct cell *tcell;
3288 AFS_STATCNT(PGetCellStatus);
3289 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3290 return EIO; /* Inappropriate ioctl for device */
3292 if (afs_pd_getStringPtr(ain, &cellName) != 0)
3295 tcell = afs_GetCellByName(cellName, READ_LOCK);
3298 temp = tcell->states;
3299 afs_PutCell(tcell, READ_LOCK);
3301 return afs_pd_putInt(aout, temp);
3305 * VIOC_SETCELLSTATUS (36) - Set corresponding info
3310 * The cell you want to set information about, and the values you
3315 * \retval EIO Error if the afs daemon hasn't started yet
3316 * \retval EACCES Error if the user doesn't have super-user credentials
3319 * Set the state of the cell in a defined struct cell, based on
3320 * whether or not SetUID is allowed
3322 DECL_PIOCTL(PSetCellStatus)
3324 register struct cell *tcell;
3326 afs_int32 flags0, flags1;
3328 if (!afs_osi_suser(*acred))
3330 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3331 return EIO; /* Inappropriate ioctl for device */
3333 if (afs_pd_getInt(ain, &flags0) != 0)
3335 if (afs_pd_getInt(ain, &flags1) != 0)
3337 if (afs_pd_getStringPtr(ain, &cellName) != 0)
3340 tcell = afs_GetCellByName(cellName, WRITE_LOCK);
3343 if (flags0 & CNoSUID)
3344 tcell->states |= CNoSUID;
3346 tcell->states &= ~CNoSUID;
3347 afs_PutCell(tcell, WRITE_LOCK);
3352 * VIOC_FLUSHVOLUME (37) - Flush whole volume's data
3356 * \param[in] ain not in use (args in avc)
3357 * \param[out] aout not in use
3359 * \retval EINVAL Error if some of the standard args aren't set
3360 * \retval EIO Error if the afs daemon hasn't started yet
3363 * Flush all cached contents of a volume. Exactly what stays and what
3364 * goes depends on the platform.
3367 * Does not flush a file that a user has open and is using, because
3368 * it will be re-created on next write. Also purges the dnlc,
3369 * because things are screwed up.
3371 DECL_PIOCTL(PFlushVolumeData)
3373 register afs_int32 i;
3374 register struct dcache *tdc;
3375 register struct vcache *tvc;
3376 register struct volume *tv;
3377 afs_int32 cell, volume;
3378 struct afs_q *tq, *uq;
3379 #ifdef AFS_DARWIN80_ENV
3383 AFS_STATCNT(PFlushVolumeData);
3386 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3387 return EIO; /* Inappropriate ioctl for device */
3389 volume = avc->f.fid.Fid.Volume; /* who to zap */
3390 cell = avc->f.fid.Cell;
3393 * Clear stat'd flag from all vnodes from this volume; this will
3394 * invalidate all the vcaches associated with the volume.
3397 ObtainReadLock(&afs_xvcache);
3398 i = VCHashV(&avc->f.fid);
3399 for (tq = afs_vhashTV[i].prev; tq != &afs_vhashTV[i]; tq = uq) {
3402 if (tvc->f.fid.Fid.Volume == volume && tvc->f.fid.Cell == cell) {
3403 if (tvc->f.states & CVInit) {
3404 ReleaseReadLock(&afs_xvcache);
3405 afs_osi_Sleep(&tvc->f.states);
3408 #ifdef AFS_DARWIN80_ENV
3409 if (tvc->f.states & CDeadVnode) {
3410 if (!(tvc->f.states & CBulkFetching)) {
3411 ReleaseReadLock(&afs_xvcache);
3412 afs_osi_Sleep(&tvc->f.states);
3417 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
3418 VN_HOLD(AFSTOV(tvc));
3419 #elif defined(AFS_DARWIN80_ENV)
3423 if (vnode_ref(vp)) {
3429 if (tvc->f.states & (CBulkFetching|CDeadVnode)) {
3431 vnode_recycle(AFSTOV(tvc));
3437 ReleaseReadLock(&afs_xvcache);
3438 #ifdef AFS_BOZONLOCK_ENV
3439 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
3441 ObtainWriteLock(&tvc->lock, 232);
3443 ObtainWriteLock(&afs_xcbhash, 458);
3444 afs_DequeueCallback(tvc);
3445 tvc->f.states &= ~(CStatd | CDirty);
3446 ReleaseWriteLock(&afs_xcbhash);
3447 if (tvc->f.fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
3448 osi_dnlc_purgedp(tvc);
3449 afs_TryToSmush(tvc, *acred, 1);
3450 ReleaseWriteLock(&tvc->lock);
3451 #ifdef AFS_BOZONLOCK_ENV
3452 afs_BozonUnlock(&tvc->pvnLock, tvc);
3454 #ifdef AFS_DARWIN80_ENV
3455 vnode_put(AFSTOV(tvc));
3457 ObtainReadLock(&afs_xvcache);
3459 /* our tvc ptr is still good until now */
3463 ReleaseReadLock(&afs_xvcache);
3466 ObtainWriteLock(&afs_xdcache, 328); /* needed to flush any stuff */
3467 for (i = 0; i < afs_cacheFiles; i++) {
3468 if (!(afs_indexFlags[i] & IFEverUsed))
3469 continue; /* never had any data */
3470 tdc = afs_GetDSlot(i, NULL);
3471 if (tdc->refCount <= 1) { /* too high, in use by running sys call */
3472 ReleaseReadLock(&tdc->tlock);
3473 if (tdc->f.fid.Fid.Volume == volume && tdc->f.fid.Cell == cell) {
3474 if (!(afs_indexFlags[i] & IFDataMod)) {
3475 /* if the file is modified, but has a ref cnt of only 1,
3476 * then someone probably has the file open and is writing
3477 * into it. Better to skip flushing such a file, it will be
3478 * brought back immediately on the next write anyway.
3480 * If we *must* flush, then this code has to be rearranged
3481 * to call afs_storeAllSegments() first */
3482 afs_FlushDCache(tdc);
3486 ReleaseReadLock(&tdc->tlock);
3488 afs_PutDCache(tdc); /* bumped by getdslot */
3490 ReleaseWriteLock(&afs_xdcache);
3492 ObtainReadLock(&afs_xvolume);
3493 for (i = 0; i < NVOLS; i++) {
3494 for (tv = afs_volumes[i]; tv; tv = tv->next) {
3495 if (tv->volume == volume) {
3496 afs_ResetVolumeInfo(tv);
3501 ReleaseReadLock(&afs_xvolume);
3503 /* probably, a user is doing this, probably, because things are screwed up.
3504 * maybe it's the dnlc's fault? */
3511 * VIOCGETVCXSTATUS (41) - gets vnode x status
3516 * not in use (avc used)
3518 * vcxstat: the file id, the data version, any lock, the parent vnode,
3519 * the parent unique id, the trunc position, the callback, cbExpires,
3520 * what access is being made, what files are open,
3521 * any users executing/writing, the flock count, the states,
3525 * Error if some of the initial default arguments aren't set
3527 * Error if access to check the mode bits is denied
3530 * gets stats for the vnode, a struct listed in vcxstat
3532 DECL_PIOCTL(PGetVnodeXStatus)
3534 register afs_int32 code;
3535 struct vcxstat stat;
3538 /* AFS_STATCNT(PGetVnodeXStatus); */
3541 code = afs_VerifyVCache(avc, areq);
3544 if (vType(avc) == VDIR)
3545 mode = PRSFS_LOOKUP;
3548 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
3551 memset(&stat, 0, sizeof(struct vcxstat));
3552 stat.fid = avc->f.fid;
3553 hset32(stat.DataVersion, hgetlo(avc->f.m.DataVersion));
3554 stat.lock = avc->lock;
3555 stat.parentVnode = avc->f.parent.vnode;
3556 stat.parentUnique = avc->f.parent.unique;
3557 hset(stat.flushDV, avc->flushDV);
3558 hset(stat.mapDV, avc->mapDV);
3559 stat.truncPos = avc->f.truncPos;
3560 { /* just grab the first two - won't break anything... */
3561 struct axscache *ac;
3563 for (i = 0, ac = avc->Access; ac && i < CPSIZE; i++, ac = ac->next) {
3564 stat.randomUid[i] = ac->uid;
3565 stat.randomAccess[i] = ac->axess;
3568 stat.callback = afs_data_pointer_to_int32(avc->callback);
3569 stat.cbExpires = avc->cbExpires;
3570 stat.anyAccess = avc->f.anyAccess;
3571 stat.opens = avc->opens;
3572 stat.execsOrWriters = avc->execsOrWriters;
3573 stat.flockCount = avc->flockCount;
3574 stat.mvstat = avc->mvstat;
3575 stat.states = avc->f.states;
3576 return afs_pd_putBytes(aout, &stat, sizeof(struct vcxstat));
3580 DECL_PIOCTL(PGetVnodeXStatus2)
3582 register afs_int32 code;
3583 struct vcxstat2 stat;
3588 code = afs_VerifyVCache(avc, areq);
3591 if (vType(avc) == VDIR)
3592 mode = PRSFS_LOOKUP;
3595 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
3598 memset(&stat, 0, sizeof(struct vcxstat2));
3600 stat.cbExpires = avc->cbExpires;
3601 stat.anyAccess = avc->f.anyAccess;
3602 stat.mvstat = avc->mvstat;
3603 stat.callerAccess = afs_GetAccessBits(avc, ~0, areq);
3605 return afs_pd_putBytes(aout, &stat, sizeof(struct vcxstat2));
3610 * VIOC_AFS_SYSNAME (38) - Change @sys value
3614 * \param[in] ain new value for @sys
3615 * \param[out] aout count, entry, list (debug values?)
3618 * Error if afsd isn't running, the new sysname is too large,
3619 * the new sysname causes issues (starts with a . or ..),
3620 * there is no PAG set in the credentials, or the user of a PAG
3623 * Error if the user doesn't have super-user credentials
3626 * Set the value of @sys if these things work: if the input isn't
3627 * too long or if input doesn't start with . or ..
3630 * We require root for local sysname changes, but not for remote
3631 * (since we don't really believe remote uids anyway)
3632 * outname[] shouldn't really be needed- this is left as an
3633 * exercise for the reader.
3635 DECL_PIOCTL(PSetSysName)
3637 char *inname = NULL;
3638 char outname[MAXSYSNAME];
3639 afs_int32 setsysname;
3641 register struct afs_exporter *exporter;
3642 register struct unixuser *au;
3643 register afs_int32 pag, error;
3644 int t, count, num = 0, allpags = 0;
3646 struct afs_pdata validate;
3648 AFS_STATCNT(PSetSysName);
3649 if (!afs_globalVFS) {
3650 /* Afsd is NOT running; disable it */
3651 #if defined(KERNEL_HAVE_UERROR)
3652 return (setuerror(EINVAL), EINVAL);
3657 if (afs_pd_getInt(ain, &setsysname) != 0)
3659 if (setsysname & 0x8000) {
3661 setsysname &= ~0x8000;
3666 if (setsysname < 0 || setsysname > MAXNUMSYSNAMES)
3669 for (count = 0; count < setsysname; count++) {
3670 if (afs_pd_getStringPtr(&validate, &inname) != 0)
3673 if (t >= MAXSYSNAME || t <= 0)
3675 /* check for names that can shoot us in the foot */
3676 if (inname[0] == '.' && (inname[1] == 0
3677 || (inname[1] == '.' && inname[2] == 0)))
3680 /* args ok, so go back to the beginning of that section */
3682 if (afs_pd_getStringPtr(ain, &inname) != 0)
3686 if (afs_cr_gid(*acred) == RMTUSER_REQ ||
3687 afs_cr_gid(*acred) == RMTUSER_REQ_PRIV) { /* Handles all exporters */
3688 if (allpags && afs_cr_gid(*acred) != RMTUSER_REQ_PRIV) {
3691 pag = PagInCred(*acred);
3693 return EINVAL; /* Better than panicing */
3695 if (!(au = afs_FindUser(pag, -1, READ_LOCK))) {
3696 return EINVAL; /* Better than panicing */
3698 if (!(exporter = au->exporter)) {
3699 afs_PutUser(au, READ_LOCK);
3700 return EINVAL; /* Better than panicing */
3702 error = EXP_SYSNAME(exporter, inname, &sysnamelist,
3705 if (error == ENODEV)
3706 foundname = 0; /* sysname not set yet! */
3708 afs_PutUser(au, READ_LOCK);
3713 strcpy(outname, sysnamelist[0]);
3715 afs_PutUser(au, READ_LOCK);
3719 /* Not xlating, so local case */
3721 osi_Panic("PSetSysName: !afs_sysname\n");
3722 if (!setsysname) { /* user just wants the info */
3723 strcpy(outname, afs_sysname);
3724 foundname = afs_sysnamecount;
3725 sysnamelist = afs_sysnamelist;
3726 } else { /* Local guy; only root can change sysname */
3727 if (!afs_osi_suser(*acred))
3730 /* allpags makes no sense for local use */
3734 /* clear @sys entries from the dnlc, once afs_lookup can
3735 * do lookups of @sys entries and thinks it can trust them */
3736 /* privs ok, store the entry, ... */
3738 if (strlen(inname) >= MAXSYSNAME-1)
3740 strcpy(afs_sysname, inname);
3742 if (setsysname > 1) { /* ... or list */
3743 for (count = 1; count < setsysname; ++count) {
3744 if (!afs_sysnamelist[count])
3746 ("PSetSysName: no afs_sysnamelist entry to write\n");
3747 if (afs_pd_getString(ain, afs_sysnamelist[count],
3752 afs_sysnamecount = setsysname;
3757 if (afs_pd_putInt(aout, foundname) != 0)
3760 if (afs_pd_putString(aout, outname) != 0)
3762 for (count = 1; count < foundname; ++count) { /* ... or list. */
3763 if (!sysnamelist[count])
3765 ("PSetSysName: no afs_sysnamelist entry to read\n");
3766 t = strlen(sysnamelist[count]);
3767 if (t >= MAXSYSNAME)
3768 osi_Panic("PSetSysName: sysname entry garbled\n");
3769 if (afs_pd_putString(aout, sysnamelist[count]) != 0)
3777 /* sequential search through the list of touched cells is not a good
3778 * long-term solution here. For small n, though, it should be just
3779 * fine. Should consider special-casing the local cell for large n.
3780 * Likewise for PSetSPrefs.
3782 * s - number of ids in array l[] -- NOT index of last id
3783 * l - array of cell ids which have volumes that need to be sorted
3784 * vlonly - sort vl servers or file servers?
3787 ReSortCells_cb(struct cell *cell, void *arg)
3789 afs_int32 *p = (afs_int32 *) arg;
3790 afs_int32 *l = p + 1;
3793 for (i = 0; i < s; i++) {
3794 if (l[i] == cell->cellNum) {
3795 ObtainWriteLock(&cell->lock, 690);
3796 afs_SortServers(cell->cellHosts, AFS_MAXCELLHOSTS);
3797 ReleaseWriteLock(&cell->lock);
3805 ReSortCells(int s, afs_int32 * l, int vlonly)
3813 p = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * (s + 1));
3815 memcpy(p + 1, l, s * sizeof(afs_int32));
3816 afs_TraverseCells(&ReSortCells_cb, p);
3817 afs_osi_Free(p, sizeof(afs_int32) * (s + 1));
3821 ObtainReadLock(&afs_xvolume);
3822 for (i = 0; i < NVOLS; i++) {
3823 for (j = afs_volumes[i]; j; j = j->next) {
3824 for (k = 0; k < s; k++)
3825 if (j->cell == l[k]) {
3826 ObtainWriteLock(&j->lock, 233);
3827 afs_SortServers(j->serverHost, AFS_MAXHOSTS);
3828 ReleaseWriteLock(&j->lock);
3833 ReleaseReadLock(&afs_xvolume);
3837 static int debugsetsp = 0;
3839 afs_setsprefs(struct spref *sp, unsigned int num, unsigned int vlonly)
3842 int i, j, k, matches, touchedSize;
3843 struct server *srvr = NULL;
3844 afs_int32 touched[34];
3848 for (k = 0; k < num; sp++, k++) {
3850 afs_warn("sp host=%x, rank=%d\n", sp->host.s_addr, sp->rank);
3853 ObtainReadLock(&afs_xserver);
3855 i = SHash(sp->host.s_addr);
3856 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3857 if (sa->sa_ip == sp->host.s_addr) {
3859 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
3860 || (sa->sa_portal == AFS_FSPORT);
3861 if ((!vlonly && isfs) || (vlonly && !isfs)) {
3868 if (sa && matches) { /* found one! */
3870 afs_warn("sa ip=%x, ip_rank=%d\n", sa->sa_ip, sa->sa_iprank);
3872 sa->sa_iprank = sp->rank + afs_randomMod15();
3873 afs_SortOneServer(sa->server);
3876 /* if we don't know yet what cell it's in, this is moot */
3877 for (j = touchedSize - 1;
3878 j >= 0 && touched[j] != srvr->cell->cellNum; j--)
3879 /* is it in our list of touched cells ? */ ;
3880 if (j < 0) { /* no, it's not */
3881 touched[touchedSize++] = srvr->cell->cellNum;
3882 if (touchedSize >= 32) { /* watch for ovrflow */
3883 ReleaseReadLock(&afs_xserver);
3884 ReSortCells(touchedSize, touched, vlonly);
3886 ObtainReadLock(&afs_xserver);
3892 ReleaseReadLock(&afs_xserver);
3893 /* if we didn't find one, start to create one. */
3894 /* Note that it doesn't have a cell yet... */
3896 afs_uint32 temp = sp->host.s_addr;
3898 afs_GetServer(&temp, 1, 0, (vlonly ? AFS_VLPORT : AFS_FSPORT),
3899 WRITE_LOCK, (afsUUID *) 0, 0);
3900 srvr->addr->sa_iprank = sp->rank + afs_randomMod15();
3901 afs_PutServer(srvr, WRITE_LOCK);
3903 } /* for all cited preferences */
3905 ReSortCells(touchedSize, touched, vlonly);
3910 * VIOC_SETPREFS (46) - Set server ranks
3912 * \param[in] ain the sprefs value you want the sprefs to be set to
3913 * \param[out] aout not in use
3916 * Error if the afs daemon hasn't started yet
3918 * Error if the user doesn't have super-user credentials
3920 * Error if the struct setsprefs is too large or if it multiplied
3921 * by the number of servers is too large
3923 * \post set the sprefs using the afs_setsprefs() function
3925 DECL_PIOCTL(PSetSPrefs)
3927 struct setspref *ssp;
3931 AFS_STATCNT(PSetSPrefs);
3933 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3934 return EIO; /* Inappropriate ioctl for device */
3936 if (!afs_osi_suser(*acred))
3939 /* The I/O handling here is ghastly, as it relies on overrunning the ends
3940 * of arrays. But, i'm not quite brave enough to change it yet. */
3942 ainSize = ain->remaining;
3944 if (ainSize < sizeof(struct setspref))
3947 ssp = (struct setspref *)ainPtr;
3948 if (ainSize < (sizeof(struct setspref)
3949 + sizeof(struct spref) * ssp->num_servers-1))
3952 afs_setsprefs(&(ssp->servers[0]), ssp->num_servers,
3953 (ssp->flags & DBservers));
3958 * VIOC_SETPREFS33 (42) - Set server ranks (deprecated)
3960 * \param[in] ain the server preferences to be set
3961 * \param[out] aout not in use
3963 * \retval EIO Error if the afs daemon hasn't started yet
3964 * \retval EACCES Error if the user doesn't have super-user credentials
3966 * \post set the server preferences, calling a function
3968 * \notes this may only be performed by the local root user.
3970 DECL_PIOCTL(PSetSPrefs33)
3972 AFS_STATCNT(PSetSPrefs);
3973 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3974 return EIO; /* Inappropriate ioctl for device */
3977 if (!afs_osi_suser(*acred))
3980 afs_setsprefs((struct spref *)afs_pd_where(ain),
3981 afs_pd_remaining(ain) / sizeof(struct spref),
3987 * VIOC_GETSPREFS (43) - Get server ranks
3991 * \param[in] ain the server preferences to get
3992 * \param[out] aout the server preferences information
3994 * \retval EIO Error if the afs daemon hasn't started yet
3995 * \retval ENOENT Error if the sprefrequest is too large
3997 * \post Get the sprefs
4000 * in the hash table of server structs, all servers with the same
4001 * IP address; will be on the same overflow chain; This could be
4002 * sped slightly in some circumstances by having it cache the
4003 * immediately previous slot in the hash table and some
4004 * supporting information; Only reports file servers now.
4006 DECL_PIOCTL(PGetSPrefs)
4008 struct sprefrequest spin; /* input */
4009 struct sprefinfo *spout; /* output */
4010 struct spref *srvout; /* one output component */
4011 int i, j; /* counters for hash table traversal */
4012 struct server *srvr; /* one of CM's server structs */
4014 int vlonly; /* just return vlservers ? */
4017 AFS_STATCNT(PGetSPrefs);
4018 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4019 return EIO; /* Inappropriate ioctl for device */
4021 /* Work out from the size whether we've got a new, or old, style pioctl */
4022 if (afs_pd_remaining(ain) < sizeof(struct sprefrequest)) {
4023 if (afs_pd_getBytes(ain, &spin, sizeof(struct sprefrequest_33)) != 0)
4028 if (afs_pd_getBytes(ain, &spin, sizeof(struct sprefrequest)) != 0)
4030 vlonly = (spin.flags & DBservers);
4033 /* This code relies on overflowing arrays. It's ghastly, but I'm not
4034 * quite brave enough to tackle it yet ...
4037 /* struct sprefinfo includes 1 server struct... that size gets added
4038 * in during the loop that follows.
4040 spout = afs_pd_inline(aout,
4041 sizeof(struct sprefinfo) - sizeof(struct spref));
4042 spout->next_offset = spin.offset;
4043 spout->num_servers = 0;
4044 srvout = spout->servers;
4046 ObtainReadLock(&afs_xserver);
4047 for (i = 0, j = 0; j < NSERVERS; j++) { /* sift through hash table */
4048 for (sa = afs_srvAddrs[j]; sa; sa = sa->next_bkt, i++) {
4049 if (spin.offset > (unsigned short)i) {
4050 continue; /* catch up to where we left off */
4052 spout->next_offset++;
4055 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
4056 || (sa->sa_portal == AFS_FSPORT);
4058 if ((vlonly && isfs) || (!vlonly && !isfs)) {
4059 /* only report ranks for vl servers */
4063 /* Check we've actually got the space we're about to use */
4064 if (afs_pd_inline(aout, sizeof(struct spref)) == NULL) {
4065 ReleaseReadLock(&afs_xserver); /* no more room! */
4069 srvout->host.s_addr = sa->sa_ip;
4070 srvout->rank = sa->sa_iprank;
4071 spout->num_servers++;
4075 ReleaseReadLock(&afs_xserver);
4077 spout->next_offset = 0; /* start over from the beginning next time */
4082 /* Enable/Disable the specified exporter. Must be root to disable an exporter */
4083 int afs_NFSRootOnly = 1;
4085 * VIOC_EXPORTAFS (39) - Export afs to nfs clients
4090 * an integer containing the desired exportee flags
4092 * an integer containing the current exporter flags
4094 * \retval ENODEV Error if the exporter doesn't exist
4095 * \retval EACCES Error if the user doesn't have super-user credentials
4098 * Changes the state of various values to reflect the change
4099 * of the export values between nfs and afs.
4101 * \notes Legacy code obtained from IBM.
4103 DECL_PIOCTL(PExportAfs)
4105 afs_int32 export, newint = 0;
4106 afs_int32 type, changestate, handleValue, convmode, pwsync, smounts;
4107 afs_int32 rempags = 0, pagcb = 0;
4108 register struct afs_exporter *exporter;
4110 AFS_STATCNT(PExportAfs);
4111 if (afs_pd_getInt(ain, &handleValue) != 0)
4113 type = handleValue >> 24;
4118 exporter = exporter_find(type);
4120 export = handleValue & 3;
4121 changestate = handleValue & 0xfff;
4122 smounts = (handleValue >> 2) & 3;
4123 pwsync = (handleValue >> 4) & 3;
4124 convmode = (handleValue >> 6) & 3;
4125 rempags = (handleValue >> 8) & 3;
4126 pagcb = (handleValue >> 10) & 3;
4128 changestate = (handleValue >> 16) & 0x1;
4129 convmode = (handleValue >> 16) & 0x2;
4130 pwsync = (handleValue >> 16) & 0x4;
4131 smounts = (handleValue >> 16) & 0x8;
4132 export = handleValue & 0xff;
4135 /* Failed finding desired exporter; */
4139 handleValue = exporter->exp_states;
4140 if (afs_pd_putInt(aout, handleValue) != 0)
4143 if (!afs_osi_suser(*acred))
4144 return EACCES; /* Only superuser can do this */
4148 exporter->exp_states |= EXP_EXPORTED;
4150 exporter->exp_states &= ~EXP_EXPORTED;
4154 exporter->exp_states |= EXP_UNIXMODE;
4156 exporter->exp_states &= ~EXP_UNIXMODE;
4160 exporter->exp_states |= EXP_PWSYNC;
4162 exporter->exp_states &= ~EXP_PWSYNC;
4166 afs_NFSRootOnly = 0;
4167 exporter->exp_states |= EXP_SUBMOUNTS;
4169 afs_NFSRootOnly = 1;
4170 exporter->exp_states &= ~EXP_SUBMOUNTS;
4175 exporter->exp_states |= EXP_CLIPAGS;
4177 exporter->exp_states &= ~EXP_CLIPAGS;
4181 exporter->exp_states |= EXP_CALLBACK;
4183 exporter->exp_states &= ~EXP_CALLBACK;
4185 handleValue = exporter->exp_states;
4186 if (afs_pd_putInt(aout, handleValue) != 0)
4190 exporter->exp_states |= EXP_EXPORTED;
4192 exporter->exp_states &= ~EXP_EXPORTED;
4194 exporter->exp_states |= EXP_UNIXMODE;
4196 exporter->exp_states &= ~EXP_UNIXMODE;
4198 exporter->exp_states |= EXP_PWSYNC;
4200 exporter->exp_states &= ~EXP_PWSYNC;
4202 afs_NFSRootOnly = 0;
4203 exporter->exp_states |= EXP_SUBMOUNTS;
4205 afs_NFSRootOnly = 1;
4206 exporter->exp_states &= ~EXP_SUBMOUNTS;
4215 * VIOC_GAG (44) - Silence Cache Manager
4219 * \param[in] ain the flags to either gag or de-gag the cache manager
4220 * \param[out] aout not in use
4222 * \retval EACCES Error if the user doesn't have super-user credentials
4224 * \post set the gag flags, then show these flags
4228 struct gaginfo *gagflags;
4230 if (!afs_osi_suser(*acred))
4233 gagflags = afs_pd_inline(ain, sizeof(*gagflags));
4234 if (gagflags == NULL)
4236 afs_showflags = gagflags->showflags;
4242 * VIOC_TWIDDLE (45) - Adjust RX knobs
4246 * \param[in] ain the previous settings of the 'knobs'
4247 * \param[out] aout not in use
4249 * \retval EACCES Error if the user doesn't have super-user credentials
4251 * \post build out the struct rxp, from a struct rx
4253 DECL_PIOCTL(PTwiddleRx)
4255 struct rxparams *rxp;
4257 if (!afs_osi_suser(*acred))
4260 rxp = afs_pd_inline(ain, sizeof(*rxp));
4264 if (rxp->rx_initReceiveWindow)
4265 rx_initReceiveWindow = rxp->rx_initReceiveWindow;
4266 if (rxp->rx_maxReceiveWindow)
4267 rx_maxReceiveWindow = rxp->rx_maxReceiveWindow;
4268 if (rxp->rx_initSendWindow)
4269 rx_initSendWindow = rxp->rx_initSendWindow;
4270 if (rxp->rx_maxSendWindow)
4271 rx_maxSendWindow = rxp->rx_maxSendWindow;
4272 if (rxp->rxi_nSendFrags)
4273 rxi_nSendFrags = rxp->rxi_nSendFrags;
4274 if (rxp->rxi_nRecvFrags)
4275 rxi_nRecvFrags = rxp->rxi_nRecvFrags;
4276 if (rxp->rxi_OrphanFragSize)
4277 rxi_OrphanFragSize = rxp->rxi_OrphanFragSize;
4278 if (rxp->rx_maxReceiveSize) {
4279 rx_maxReceiveSize = rxp->rx_maxReceiveSize;
4280 rx_maxReceiveSizeUser = rxp->rx_maxReceiveSize;
4282 if (rxp->rx_MyMaxSendSize)
4283 rx_MyMaxSendSize = rxp->rx_MyMaxSendSize;
4289 * VIOC_GETINITPARAMS (49) - Get initial cache manager parameters
4293 * \param[in] ain not in use
4294 * \param[out] aout initial cache manager params
4297 * Error if the initial parameters are bigger than some PIGGYSIZE
4299 * \post return the initial cache manager parameters
4301 DECL_PIOCTL(PGetInitParams)
4303 if (sizeof(struct cm_initparams) > PIGGYSIZE)
4306 return afs_pd_putBytes(aout, &cm_initParams,
4307 sizeof(struct cm_initparams));
4311 #ifdef AFS_SGI65_ENV
4312 /* They took crget() from us, so fake it. */
4317 cr = crdup(get_current_cred());
4318 memset(cr, 0, sizeof(cred_t));
4319 #if CELL || CELL_PREPARE
4327 * VIOC_GETRXKCRYPT (55) - Get rxkad encryption flag
4331 * \param[in] ain not in use
4332 * \param[out] aout value of cryptall
4334 * \post Turns on, or disables, rxkad encryption by setting the cryptall global
4336 DECL_PIOCTL(PGetRxkcrypt)
4338 return afs_pd_putInt(aout, cryptall);
4342 * VIOC_SETRXKCRYPT (56) - Set rxkad encryption flag
4346 * \param[in] ain the argument whether or not things should be encrypted
4347 * \param[out] aout not in use
4350 * Error if the user doesn't have super-user credentials
4352 * Error if the input is too big, or if the input is outside the
4353 * bounds of what it can be set to
4355 * \post set whether or not things should be encrypted
4358 * may need to be modified at a later date to take into account
4359 * other values for cryptall (beyond true or false)
4361 DECL_PIOCTL(PSetRxkcrypt)
4365 if (!afs_osi_suser(*acred))
4367 if (afs_pd_getInt(ain, &tmpval) != 0)
4369 /* if new mappings added later this will need to be changed */
4370 if (tmpval != 0 && tmpval != 1)
4376 #ifdef AFS_NEED_CLIENTCONTEXT
4378 * Create new credentials to correspond to a remote user with given
4379 * <hostaddr, uid, g0, g1>. This allows a server running as root to
4380 * provide pioctl (and other) services to foreign clients (i.e. nfs
4381 * clients) by using this call to `become' the client.
4384 #define PIOCTL_HEADER 6
4386 HandleClientContext(struct afs_ioctl *ablob, int *com,
4387 afs_ucred_t **acred, afs_ucred_t *credp)
4390 afs_uint32 hostaddr;
4391 afs_int32 uid, g0, g1, i, code, pag, exporter_type, isroot = 0;
4392 struct afs_exporter *exporter, *outexporter;
4393 afs_ucred_t *newcred;
4394 struct unixuser *au;
4395 afs_uint32 comp = *com & 0xff00;
4397 #if defined(AFS_SUN510_ENV)
4401 #if defined(AFS_SGIMP_ENV)
4402 osi_Assert(ISAFS_GLOCK());
4404 AFS_STATCNT(HandleClientContext);
4405 if (ablob->in_size < PIOCTL_HEADER * sizeof(afs_int32)) {
4406 /* Must at least include the PIOCTL_HEADER header words
4407 * required by the protocol */
4408 return EINVAL; /* Too small to be good */
4410 ain = inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
4411 AFS_COPYIN(ablob->in, ain, PIOCTL_HEADER * sizeof(afs_int32), code);
4413 osi_FreeLargeSpace(inData);
4417 /* Extract information for remote user */
4418 hostaddr = *((afs_uint32 *) ain);
4419 ain += sizeof(hostaddr);
4420 uid = *((afs_uint32 *) ain);
4422 g0 = *((afs_uint32 *) ain);
4424 g1 = *((afs_uint32 *) ain);
4426 *com = *((afs_uint32 *) ain);
4427 ain += sizeof(afs_int32);
4428 exporter_type = *((afs_uint32 *) ain);/* In case we support more than NFS */
4431 * Of course, one must be root for most of these functions, but
4432 * we'll allow (for knfs) you to set things if the pag is 0 and
4433 * you're setting tokens or unlogging.
4436 if (!afs_osi_suser(credp)) {
4437 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
4438 /* Since SGI's suser() returns explicit failure after the call.. */
4441 /* check for acceptable opcodes for normal folks, which are, so far,
4442 * get/set tokens, sysname, and unlog.
4444 if (i != 9 && i != 3 && i != 38 && i != 8) {
4445 osi_FreeLargeSpace(inData);
4450 ablob->in_size -= PIOCTL_HEADER * sizeof(afs_int32);
4451 ablob->in += PIOCTL_HEADER * sizeof(afs_int32);
4452 osi_FreeLargeSpace(inData);
4455 * We map uid 0 to nobody to match the mapping that the nfs
4456 * server does and to ensure that the suser() calls in the afs
4457 * code fails for remote client roots.
4459 uid = afs_nobody; /* NFS_NOBODY == -2 */
4463 #ifdef AFS_AIX41_ENV
4466 afs_set_cr_gid(newcred, isroot ? RMTUSER_REQ_PRIV : RMTUSER_REQ);
4467 #ifdef AFS_AIX51_ENV
4468 newcred->cr_groupset.gs_union.un_groups[0] = g0;
4469 newcred->cr_groupset.gs_union.un_groups[1] = g1;
4470 #elif defined(AFS_LINUX26_ENV)
4471 # ifdef AFS_LINUX26_ONEGROUP_ENV
4472 set_cr_group_info(newcred, groups_alloc(1)); /* nothing sets this */
4473 l = (((g0-0x3f00) & 0x3fff) << 14) | ((g1-0x3f00) & 0x3fff);
4474 h = ((g0-0x3f00) >> 14);
4475 h = ((g1-0x3f00) >> 14) + h + h + h;
4476 GROUP_AT(cr_group_info(newcred), 0) = ((h << 28) | l);
4478 set_cr_group_info(newcred, groups_alloc(2));
4479 GROUP_AT(cr_group_info(newcred), 0) = g0;
4480 GROUP_AT(cr_group_info(newcred), 1) = g1;
4482 #elif defined(AFS_SUN510_ENV)
4485 crsetgroups(newcred, 2, gids);
4487 newcred->cr_groups[0] = g0;
4488 newcred->cr_groups[1] = g1;
4491 newcred->cr_ngrps = 2;
4492 #elif !defined(AFS_LINUX26_ENV) && !defined(AFS_SUN510_ENV)
4493 # if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_FBSD80_ENV)
4494 newcred->cr_ngroups = 2;
4496 for (i = 2; i < NGROUPS; i++)
4497 newcred->cr_groups[i] = NOGROUP;
4500 if (!(exporter = exporter_find(exporter_type))) {
4501 /* Exporter wasn't initialized or an invalid exporter type */
4505 if (exporter->exp_states & EXP_PWSYNC) {
4506 if (uid != afs_cr_uid(credp)) {
4508 return ENOEXEC; /* XXX Find a better errno XXX */
4511 afs_set_cr_uid(newcred, uid); /* Only temporary */
4512 code = EXP_REQHANDLER(exporter, &newcred, hostaddr, &pag, &outexporter);
4513 /* The client's pag is the only unique identifier for it */
4514 afs_set_cr_uid(newcred, pag);
4516 if (!code && *com == PSETPAG) {
4517 /* Special case for 'setpag' */
4518 afs_uint32 pagvalue = genpag();
4520 au = afs_GetUser(pagvalue, -1, WRITE_LOCK); /* a new unixuser struct */
4522 * Note that we leave the 'outexporter' struct held so it won't
4525 au->exporter = outexporter;
4526 if (ablob->out_size >= 4) {
4527 AFS_COPYOUT((char *)&pagvalue, ablob->out, sizeof(afs_int32),
4530 afs_PutUser(au, WRITE_LOCK);
4533 return PSETPAG; /* Special return for setpag */
4535 EXP_RELE(outexporter);
4538 *com = (*com) | comp;
4541 #endif /* AFS_NEED_CLIENTCONTEXT */
4545 * VIOC_GETCPREFS (50) - Get client interface
4549 * \param[in] ain sprefrequest input
4550 * \param[out] aout spref information
4552 * \retval EIO Error if the afs daemon hasn't started yet
4553 * \retval EINVAL Error if some of the standard args aren't set
4556 * get all interface addresses and other information of the client
4559 DECL_PIOCTL(PGetCPrefs)
4561 struct sprefrequest *spin; /* input */
4562 struct sprefinfo *spout; /* output */
4563 struct spref *srvout; /* one output component */
4567 AFS_STATCNT(PGetCPrefs);
4568 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4569 return EIO; /* Inappropriate ioctl for device */
4571 spin = afs_pd_inline(ain, sizeof(*spin));
4575 /* Output spout relies on writing past the end of arrays. It's horrible,
4576 * but I'm not quite brave enough to tackle it yet */
4577 spout = (struct sprefinfo *)aout->ptr;
4579 maxNumber = spin->num_servers; /* max addrs this time */
4580 srvout = spout->servers;
4582 ObtainReadLock(&afs_xinterface);
4584 /* copy out the client interface information from the
4585 * kernel data structure "interface" to the output buffer
4587 for (i = spin->offset, j = 0; (i < afs_cb_interface.numberOfInterfaces)
4588 && (j < maxNumber); i++, j++, srvout++)
4589 srvout->host.s_addr = afs_cb_interface.addr_in[i];
4591 spout->num_servers = j;
4592 aout->ptr += sizeof(struct sprefinfo) + (j - 1) * sizeof(struct spref);
4594 if (i >= afs_cb_interface.numberOfInterfaces)
4595 spout->next_offset = 0; /* start from beginning again */
4597 spout->next_offset = spin->offset + j;
4599 ReleaseReadLock(&afs_xinterface);
4604 * VIOC_SETCPREFS (51) - Set client interface
4608 * \param[in] ain the interfaces you want set
4609 * \param[out] aout not in use
4611 * \retval EIO Error if the afs daemon hasn't started yet
4612 * \retval EINVAL Error if the input is too large for the struct
4613 * \retval ENOMEM Error if there are too many servers
4615 * \post set the callbak interfaces addresses to those of the hosts
4617 DECL_PIOCTL(PSetCPrefs)
4621 struct setspref *sin;
4624 AFS_STATCNT(PSetCPrefs);
4625 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4626 return EIO; /* Inappropriate ioctl for device */
4628 /* Yuck. Input to this function relies on reading past the end of
4629 * structures. Bodge it for now.
4632 ainSize = ain->remaining;
4634 sin = (struct setspref *)ainPtr;
4636 if (ainSize < sizeof(struct setspref))
4638 #if 0 /* num_servers is unsigned */
4639 if (sin->num_servers < 0)
4642 if (sin->num_servers > AFS_MAX_INTERFACE_ADDR)
4645 ObtainWriteLock(&afs_xinterface, 412);
4646 afs_cb_interface.numberOfInterfaces = sin->num_servers;
4647 for (i = 0; (unsigned short)i < sin->num_servers; i++)
4648 afs_cb_interface.addr_in[i] = sin->servers[i].host.s_addr;
4650 ReleaseWriteLock(&afs_xinterface);
4655 * VIOC_AFS_FLUSHMOUNT (52) - Flush mount symlink data
4660 * the last part of a path to a mount point, which tells us what to flush
4665 * Error if some of the initial arguments aren't set
4667 * Error if the initial argument for the mount point isn't a directory
4669 * Error if the dcache entry isn't set
4672 * remove all of the mount data from the dcache regarding a
4673 * certain mount point
4675 DECL_PIOCTL(PFlushMount)
4677 register afs_int32 code;
4678 register struct vcache *tvc;
4679 register struct dcache *tdc;
4680 struct VenusFid tfid;
4683 struct sysname_info sysState;
4684 afs_size_t offset, len;
4686 AFS_STATCNT(PFlushMount);
4690 if (afs_pd_getStringPtr(ain, &mount) != 0)
4693 code = afs_VerifyVCache(avc, areq);
4696 if (vType(avc) != VDIR) {
4699 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
4702 Check_AtSys(avc, mount, &sysState, areq);
4703 ObtainReadLock(&tdc->lock);
4705 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
4706 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
4707 ReleaseReadLock(&tdc->lock);
4708 afs_PutDCache(tdc); /* we're done with the data */
4709 bufp = sysState.name;
4713 tfid.Cell = avc->f.fid.Cell;
4714 tfid.Fid.Volume = avc->f.fid.Fid.Volume;
4715 if (!tfid.Fid.Unique && (avc->f.states & CForeign)) {
4716 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
4718 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
4724 if (tvc->mvstat != 1) {
4729 #ifdef AFS_BOZONLOCK_ENV
4730 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
4732 ObtainWriteLock(&tvc->lock, 649);
4733 ObtainWriteLock(&afs_xcbhash, 650);
4734 afs_DequeueCallback(tvc);
4735 tvc->f.states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
4736 ReleaseWriteLock(&afs_xcbhash);
4737 /* now find the disk cache entries */
4738 afs_TryToSmush(tvc, *acred, 1);
4739 osi_dnlc_purgedp(tvc);
4740 if (tvc->linkData && !(tvc->f.states & CCore)) {
4741 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
4742 tvc->linkData = NULL;
4744 ReleaseWriteLock(&tvc->lock);
4745 #ifdef AFS_BOZONLOCK_ENV
4746 afs_BozonUnlock(&tvc->pvnLock, tvc);
4750 if (sysState.allocked)
4751 osi_FreeLargeSpace(bufp);
4756 * VIOC_RXSTAT_PROC (53) - Control process RX statistics
4760 * \param[in] ain the flags that control which stats to use
4761 * \param[out] aout not in use
4763 * \retval EACCES Error if the user doesn't have super-user credentials
4764 * \retval EINVAL Error if the flag input is too long
4767 * either enable process RPCStats, disable process RPCStats,
4768 * or clear the process RPCStats
4770 DECL_PIOCTL(PRxStatProc)
4774 if (!afs_osi_suser(*acred))
4777 if (afs_pd_getInt(ain, &flags) != 0)
4780 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK))
4783 if (flags & AFSCALL_RXSTATS_ENABLE) {
4784 rx_enableProcessRPCStats();
4786 if (flags & AFSCALL_RXSTATS_DISABLE) {
4787 rx_disableProcessRPCStats();
4789 if (flags & AFSCALL_RXSTATS_CLEAR) {
4790 rx_clearProcessRPCStats(AFS_RX_STATS_CLEAR_ALL);
4797 * VIOC_RXSTAT_PEER (54) - Control peer RX statistics
4801 * \param[in] ain the flags that control which statistics to use
4802 * \param[out] aout not in use
4804 * \retval EACCES Error if the user doesn't have super-user credentials
4805 * \retval EINVAL Error if the flag input is too long
4808 * either enable peer RPCStatws, disable peer RPCStats,
4809 * or clear the peer RPCStats
4811 DECL_PIOCTL(PRxStatPeer)
4815 if (!afs_osi_suser(*acred))
4818 if (afs_pd_getInt(ain, &flags) != 0)
4821 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK))
4824 if (flags & AFSCALL_RXSTATS_ENABLE) {
4825 rx_enablePeerRPCStats();
4827 if (flags & AFSCALL_RXSTATS_DISABLE) {
4828 rx_disablePeerRPCStats();
4830 if (flags & AFSCALL_RXSTATS_CLEAR) {
4831 rx_clearPeerRPCStats(AFS_RX_STATS_CLEAR_ALL);
4836 DECL_PIOCTL(PPrefetchFromTape)
4838 register afs_int32 code, code1;
4839 afs_int32 bytes, outval;
4840 struct afs_conn *tc;
4841 struct rx_call *tcall;
4842 struct AFSVolSync tsync;
4843 struct AFSFetchStatus OutStatus;
4844 struct AFSCallBack CallBack;
4845 struct VenusFid tfid;
4849 AFS_STATCNT(PSetAcl);
4853 Fid = afs_pd_inline(ain, sizeof(struct AFSFid));
4855 Fid = &avc->f.fid.Fid;
4857 tfid.Cell = avc->f.fid.Cell;
4858 tfid.Fid.Volume = Fid->Volume;
4859 tfid.Fid.Vnode = Fid->Vnode;
4860 tfid.Fid.Unique = Fid->Unique;
4862 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
4864 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
4865 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &avc->f.fid);
4868 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
4869 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &tvc->f.fid);
4872 tc = afs_Conn(&tvc->f.fid, areq, SHARED_LOCK);
4876 tcall = rx_NewCall(tc->id);
4878 StartRXAFS_FetchData(tcall, (struct AFSFid *)&tvc->f.fid.Fid, 0,
4881 bytes = rx_Read(tcall, (char *)&outval, sizeof(afs_int32));
4883 EndRXAFS_FetchData(tcall, &OutStatus, &CallBack, &tsync);
4885 code1 = rx_EndCall(tcall, code);
4889 } while (afs_Analyze
4890 (tc, code, &tvc->f.fid, areq, AFS_STATS_FS_RPCIDX_RESIDENCYRPCS,
4891 SHARED_LOCK, NULL));
4892 /* This call is done only to have the callback things handled correctly */
4893 afs_FetchStatus(tvc, &tfid, areq, &OutStatus);
4899 return afs_pd_putInt(aout, outval);
4904 register afs_int32 code;
4905 struct afs_conn *tc;
4907 struct FsCmdInputs *Inputs;
4908 struct FsCmdOutputs *Outputs;
4909 struct VenusFid tfid;
4915 Inputs = afs_pd_inline(ain, sizeof(*Inputs));
4919 Outputs = afs_pd_inline(aout, sizeof(*Outputs));
4920 if (Outputs == NULL)
4925 Fid = &avc->f.fid.Fid;
4927 tfid.Cell = avc->f.fid.Cell;
4928 tfid.Fid.Volume = Fid->Volume;
4929 tfid.Fid.Vnode = Fid->Vnode;
4930 tfid.Fid.Unique = Fid->Unique;
4932 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
4933 afs_Trace3(afs_iclSetp, CM_TRACE_RESIDCMD, ICL_TYPE_POINTER, tvc,
4934 ICL_TYPE_INT32, Inputs->command, ICL_TYPE_FID, &tfid);
4938 if (Inputs->command) {
4940 tc = afs_Conn(&tvc->f.fid, areq, SHARED_LOCK);
4944 RXAFS_FsCmd(tc->id, Fid, Inputs,
4945 (struct FsCmdOutputs *)aout);
4949 } while (afs_Analyze
4950 (tc, code, &tvc->f.fid, areq,
4951 AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK, NULL));
4952 /* This call is done to have the callback things handled correctly */
4953 afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
4954 } else { /* just a status request, return also link data */
4956 Outputs->code = afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
4957 Outputs->chars[0] = 0;
4958 if (vType(tvc) == VLNK) {
4959 ObtainWriteLock(&tvc->lock, 555);
4960 if (afs_HandleLink(tvc, areq) == 0)
4961 strncpy((char *)&Outputs->chars, tvc->linkData, MAXCMDCHARS);
4962 ReleaseWriteLock(&tvc->lock);
4971 DECL_PIOCTL(PNewUuid)
4973 /*AFS_STATCNT(PNewUuid); */
4974 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
4975 return EIO; /* Inappropriate ioctl for device */
4977 if (!afs_osi_suser(*acred))
4980 ObtainWriteLock(&afs_xinterface, 555);
4981 afs_uuid_create(&afs_cb_interface.uuid);
4982 ReleaseWriteLock(&afs_xinterface);
4983 ForceAllNewConnections();
4987 #if defined(AFS_CACHE_BYPASS)
4989 DECL_PIOCTL(PSetCachingThreshold)
4991 afs_int32 getting = 1;
4992 afs_int32 setting = 1;
4993 afs_int32 threshold;
4995 if (afs_pd_getInt(ain, &threshold) != 0)
5001 if (setting == 0 && getting == 0)
5005 * If setting, set first, and return the value now in effect
5008 if (!afs_osi_suser(*acred))
5010 cache_bypass_threshold = threshold;
5011 afs_warn("Cache Bypass Threshold set to: %d\n", threshold);
5012 /* TODO: move to separate pioctl, or enhance pioctl */
5013 cache_bypass_strategy = LARGE_FILES_BYPASS_CACHE;
5016 /* Return the current size threshold */
5018 return afs_pd_putInt(aout, cache_bypass_threshold);
5023 #endif /* defined(AFS_CACHE_BYPASS) */
5025 DECL_PIOCTL(PCallBackAddr)
5028 afs_uint32 addr, code;
5032 struct afs_conn *tc;
5034 struct unixuser *tu;
5035 struct srvAddr **addrs;
5037 /*AFS_STATCNT(PCallBackAddr); */
5038 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
5039 return EIO; /* Inappropriate ioctl for device */
5041 if (!afs_osi_suser(acred))
5044 if (afs_pd_getInt(ain, &addr) != 0)
5047 ObtainReadLock(&afs_xinterface);
5048 for (i = 0; (unsigned short)i < afs_cb_interface.numberOfInterfaces; i++) {
5049 if (afs_cb_interface.addr_in[i] == addr)
5053 ReleaseWriteLock(&afs_xinterface);
5055 if (afs_cb_interface.addr_in[i] != addr)
5058 ObtainReadLock(&afs_xserver); /* Necessary? */
5059 ObtainReadLock(&afs_xsrvAddr);
5062 for (i = 0; i < NSERVERS; i++) {
5063 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
5068 addrs = afs_osi_Alloc(srvAddrCount * sizeof(*addrs));
5070 for (i = 0; i < NSERVERS; i++) {
5071 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
5072 if (j >= srvAddrCount)
5078 ReleaseReadLock(&afs_xsrvAddr);
5079 ReleaseReadLock(&afs_xserver);
5081 for (i = 0; i < j; i++) {
5087 /* vlserver has no callback conn */
5088 if (sa->sa_portal == AFS_VLPORT) {
5092 if (!ts->cell) /* not really an active server, anyway, it must */
5093 continue; /* have just been added by setsprefs */
5095 /* get a connection, even if host is down; bumps conn ref count */
5096 tu = afs_GetUser(areq->uid, ts->cell->cellNum, SHARED_LOCK);
5097 tc = afs_ConnBySA(sa, ts->cell->fsport, ts->cell->cellNum, tu,
5098 1 /*force */ , 1 /*create */ , SHARED_LOCK);
5099 afs_PutUser(tu, SHARED_LOCK);
5103 if ((sa->sa_flags & SRVADDR_ISDOWN) || afs_HaveCallBacksFrom(ts)) {
5104 if (sa->sa_flags & SRVADDR_ISDOWN) {
5105 rx_SetConnDeadTime(tc->id, 3);
5107 #ifdef RX_ENABLE_LOCKS
5109 #endif /* RX_ENABLE_LOCKS */
5110 code = RXAFS_CallBackRxConnAddr(tc->id, &addr);
5111 #ifdef RX_ENABLE_LOCKS
5113 #endif /* RX_ENABLE_LOCKS */
5115 afs_PutConn(tc, SHARED_LOCK); /* done with it now */
5116 } /* Outer loop over addrs */
5117 #endif /* UKERNEL */
5121 DECL_PIOCTL(PDiscon)
5123 #ifdef AFS_DISCON_ENV
5124 static afs_int32 mode = 1; /* Start up in 'off' */
5125 afs_int32 force = 0;
5129 if (afs_pd_getBytes(ain, &flags, 3) == 0) {
5130 if (!afs_osi_suser(*acred))
5134 mode = flags[0] - 1;
5136 afs_ConflictPolicy = flags[1] - 1;
5141 * All of these numbers are hard coded in fs.c. If they
5142 * change here, they should change there and vice versa
5145 case 0: /* Disconnect ("offline" mode), breaking all callbacks */
5146 if (!AFS_IS_DISCONNECTED) {
5147 ObtainWriteLock(&afs_discon_lock, 999);
5148 afs_DisconGiveUpCallbacks();
5149 afs_RemoveAllConns();
5150 afs_is_disconnected = 1;
5151 afs_is_discon_rw = 1;
5152 ReleaseWriteLock(&afs_discon_lock);
5155 case 1: /* Fully connected, ("online" mode). */
5156 ObtainWriteLock(&afs_discon_lock, 998);
5159 afs_MarkAllServersUp();
5160 code = afs_ResyncDisconFiles(areq, *acred);
5163 if (code && !force) {
5164 afs_warnuser("Files not synchronized properly, still in discon state. \n"
5165 "Please retry or use \"force\".\n");
5169 afs_DisconDiscardAll(*acred);
5171 afs_ClearAllStatdFlag();
5172 afs_is_disconnected = 0;
5173 afs_is_discon_rw = 0;
5174 afs_warnuser("\nSync succeeded. You are back online.\n");
5177 ReleaseWriteLock(&afs_discon_lock);
5189 return afs_pd_putInt(aout, mode);
5195 DECL_PIOCTL(PNFSNukeCreds)
5198 register afs_int32 i;
5199 register struct unixuser *tu;
5201 AFS_STATCNT(PUnlog);
5202 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
5203 return EIO; /* Inappropriate ioctl for device */
5205 if (afs_pd_getUint(ain, &addr) != 0)
5208 if (afs_cr_gid(*acred) == RMTUSER_REQ_PRIV && !addr) {
5209 tu = afs_GetUser(areq->uid, -1, SHARED_LOCK);
5210 if (!tu->exporter || !(addr = EXP_GETHOST(tu->exporter))) {
5211 afs_PutUser(tu, SHARED_LOCK);
5214 afs_PutUser(tu, SHARED_LOCK);
5215 } else if (!afs_osi_suser(acred)) {
5219 ObtainWriteLock(&afs_xuser, 227);
5220 for (i = 0; i < NUSERS; i++) {
5221 for (tu = afs_users[i]; tu; tu = tu->next) {
5222 if (tu->exporter && EXP_CHECKHOST(tu->exporter, addr)) {
5224 tu->states &= ~UHasTokens;
5225 /* security is not having to say you're sorry */
5226 memset(&tu->ct, 0, sizeof(struct ClearToken));
5228 ReleaseWriteLock(&afs_xuser);
5229 afs_ResetUserConns(tu);
5231 ObtainWriteLock(&afs_xuser, 228);
5233 /* set the expire times to 0, causes
5234 * afs_GCUserData to remove this entry
5236 tu->ct.EndTimestamp = 0;
5238 #endif /* UKERNEL */
5242 ReleaseWriteLock(&afs_xuser);