2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include "afs/param.h"
14 #include "afs/sysincludes.h" /* Standard vendor system headers */
16 #include "h/syscallargs.h"
19 #include "h/sysproto.h"
22 #include <sys/ioctl.h>
23 #include <sys/ioccom.h>
25 #include "afsincludes.h" /* Afs-based standard headers */
26 #include "afs/afs_stats.h" /* afs statistics */
28 #include "afs/afs_bypasscache.h"
29 #include "rx/rx_globals.h"
32 struct VenusFid afs_rootFid;
33 afs_int32 afs_waitForever = 0;
34 short afs_waitForeverCount = 0;
35 afs_int32 afs_showflags = GAGUSER | GAGCONSOLE; /* show all messages */
37 afs_int32 afs_is_disconnected;
38 afs_int32 afs_is_discon_rw;
39 /* On reconnection, turn this knob on until it finishes,
42 afs_int32 afs_in_sync = 0;
50 * A set of handy little functions for encoding and decoding
51 * pioctls without losing your marbles, or memory integrity
55 afs_pd_alloc(struct afs_pdata *apd, size_t size)
58 if (size > AFS_LRALLOCSIZ)
59 apd->ptr = osi_Alloc(size + 1);
61 apd->ptr = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
66 apd->remaining = size;
72 afs_pd_free(struct afs_pdata *apd)
77 if (apd->remaining > AFS_LRALLOCSIZ)
78 osi_Free(apd->ptr, apd->remaining + 1);
80 osi_FreeLargeSpace(apd->ptr);
87 afs_pd_where(struct afs_pdata *apd)
89 return apd ? apd->ptr : NULL;
93 afs_pd_remaining(struct afs_pdata *apd)
95 return apd ? apd->remaining : 0;
99 afs_pd_skip(struct afs_pdata *apd, size_t skip)
101 if (apd == NULL || apd->remaining < skip)
103 apd->remaining -= skip;
110 afs_pd_getInt(struct afs_pdata *apd, afs_int32 *val)
112 if (apd == NULL || apd->remaining < sizeof(afs_int32))
114 apd->remaining -= sizeof(afs_int32);
115 *val = *(afs_int32 *)apd->ptr;
116 apd->ptr += sizeof(afs_int32);
121 afs_pd_getUint(struct afs_pdata *apd, afs_uint32 *val)
123 return afs_pd_getInt(apd, (afs_int32 *)val);
127 afs_pd_getBytes(struct afs_pdata *apd, void *dest, size_t bytes)
129 if (apd == NULL || apd->remaining < bytes)
131 apd->remaining -= bytes;
132 memcpy(dest, apd->ptr, bytes);
138 afs_pd_inline(struct afs_pdata *apd, size_t bytes)
142 if (apd == NULL || apd->remaining < bytes)
147 apd->remaining -= bytes;
154 afs_pd_xdrStart(struct afs_pdata *apd, XDR *xdrs, enum xdr_op op) {
155 xdrmem_create(xdrs, apd->ptr, apd->remaining, op);
159 afs_pd_xdrEnd(struct afs_pdata *apd, XDR *xdrs) {
162 pos = xdr_getpos(xdrs);
164 apd->remaining -= pos;
171 afs_pd_getString(struct afs_pdata *apd, char *str, size_t maxLen)
175 if (apd == NULL || apd->remaining <= 0)
177 len = strlen(apd->ptr) + 1;
180 memcpy(str, apd->ptr, len);
182 apd->remaining -= len;
187 afs_pd_getStringPtr(struct afs_pdata *apd, char **str)
191 if (apd == NULL || apd->remaining <= 0)
193 len = strlen(apd->ptr) + 1;
196 apd->remaining -= len;
201 afs_pd_putInt(struct afs_pdata *apd, afs_int32 val)
203 if (apd == NULL || apd->remaining < sizeof(afs_int32))
205 *(afs_int32 *)apd->ptr = val;
206 apd->ptr += sizeof(afs_int32);
207 apd->remaining -= sizeof(afs_int32);
213 afs_pd_putBytes(struct afs_pdata *apd, const void *bytes, size_t len)
215 if (apd == NULL || apd->remaining < len)
217 memcpy(apd->ptr, bytes, len);
219 apd->remaining -= len;
224 afs_pd_putString(struct afs_pdata *apd, char *str) {
226 /* Add 1 so we copy the NULL too */
227 return afs_pd_putBytes(apd, str, strlen(str) +1);
231 * \defgroup pioctl Path IOCTL functions
233 * DECL_PIOCTL is a macro defined to contain the following parameters for functions:
236 * the AFS vcache structure in use by pioctl
240 * the AFS vrequest structure
242 * an afs_pdata block describing the data received from the caller
244 * an afs_pdata block describing a pre-allocated block for output
246 * UNIX credentials structure underlying the operation
249 #define DECL_PIOCTL(x) \
250 static int x(struct vcache *avc, int afun, struct vrequest *areq, \
251 struct afs_pdata *ain, struct afs_pdata *aout, \
254 /* Prototypes for pioctl routines */
255 DECL_PIOCTL(PGetFID);
256 DECL_PIOCTL(PSetAcl);
257 DECL_PIOCTL(PStoreBehind);
258 DECL_PIOCTL(PGCPAGs);
259 DECL_PIOCTL(PGetAcl);
262 DECL_PIOCTL(PGetFileCell);
263 DECL_PIOCTL(PGetWSCell);
264 DECL_PIOCTL(PGetUserCell);
265 DECL_PIOCTL(PSetTokens);
266 DECL_PIOCTL(PSetTokens2);
267 DECL_PIOCTL(PGetVolumeStatus);
268 DECL_PIOCTL(PSetVolumeStatus);
270 DECL_PIOCTL(PNewStatMount);
271 DECL_PIOCTL(PGetTokens);
273 DECL_PIOCTL(PMariner);
274 DECL_PIOCTL(PCheckServers);
275 DECL_PIOCTL(PCheckVolNames);
276 DECL_PIOCTL(PCheckAuth);
277 DECL_PIOCTL(PFindVolume);
278 DECL_PIOCTL(PViceAccess);
279 DECL_PIOCTL(PSetCacheSize);
280 DECL_PIOCTL(PGetCacheSize);
281 DECL_PIOCTL(PRemoveCallBack);
282 DECL_PIOCTL(PNewCell);
283 DECL_PIOCTL(PNewAlias);
284 DECL_PIOCTL(PListCells);
285 DECL_PIOCTL(PListAliases);
286 DECL_PIOCTL(PRemoveMount);
287 DECL_PIOCTL(PGetCellStatus);
288 DECL_PIOCTL(PSetCellStatus);
289 DECL_PIOCTL(PFlushVolumeData);
290 DECL_PIOCTL(PGetVnodeXStatus);
291 DECL_PIOCTL(PGetVnodeXStatus2);
292 DECL_PIOCTL(PSetSysName);
293 DECL_PIOCTL(PSetSPrefs);
294 DECL_PIOCTL(PSetSPrefs33);
295 DECL_PIOCTL(PGetSPrefs);
296 DECL_PIOCTL(PExportAfs);
298 DECL_PIOCTL(PTwiddleRx);
299 DECL_PIOCTL(PGetInitParams);
300 DECL_PIOCTL(PGetRxkcrypt);
301 DECL_PIOCTL(PSetRxkcrypt);
302 DECL_PIOCTL(PGetCPrefs);
303 DECL_PIOCTL(PSetCPrefs);
304 DECL_PIOCTL(PFlushMount);
305 DECL_PIOCTL(PRxStatProc);
306 DECL_PIOCTL(PRxStatPeer);
307 DECL_PIOCTL(PPrefetchFromTape);
309 DECL_PIOCTL(PCallBackAddr);
310 DECL_PIOCTL(PDiscon);
311 DECL_PIOCTL(PNFSNukeCreds);
312 DECL_PIOCTL(PNewUuid);
313 DECL_PIOCTL(PPrecache);
314 DECL_PIOCTL(PGetPAG);
315 #if defined(AFS_CACHE_BYPASS)
316 DECL_PIOCTL(PSetCachingThreshold);
320 * A macro that says whether we're going to need HandleClientContext().
321 * This is currently used only by the nfs translator.
323 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
324 #define AFS_NEED_CLIENTCONTEXT
327 /* Prototypes for private routines */
328 #ifdef AFS_NEED_CLIENTCONTEXT
329 static int HandleClientContext(struct afs_ioctl *ablob, int *com,
333 int HandleIoctl(struct vcache *avc, afs_int32 acom,
334 struct afs_ioctl *adata);
335 int afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
336 struct afs_ioctl *ablob, int afollow,
337 afs_ucred_t **acred);
338 static int Prefetch(uparmtype apath, struct afs_ioctl *adata, int afollow,
341 typedef int (*pioctlFunction) (struct vcache *, int, struct vrequest *,
342 struct afs_pdata *, struct afs_pdata *,
345 static pioctlFunction VpioctlSw[] = {
350 PGetVolumeStatus, /* 4 */
351 PSetVolumeStatus, /* 5 */
356 PCheckServers, /* 10 */
357 PCheckVolNames, /* 11 */
359 PBogus, /* 13 -- used to be quick check time */
360 PFindVolume, /* 14 */
361 PBogus, /* 15 -- prefetch is now special-cased; see pioctl code! */
362 PBogus, /* 16 -- used to be testing code */
363 PNoop, /* 17 -- used to be enable group */
364 PNoop, /* 18 -- used to be disable group */
365 PBogus, /* 19 -- used to be list group */
366 PViceAccess, /* 20 */
367 PUnlog, /* 21 -- unlog *is* unpag in this system */
368 PGetFID, /* 22 -- get file ID */
369 PBogus, /* 23 -- used to be waitforever */
370 PSetCacheSize, /* 24 */
371 PRemoveCallBack, /* 25 -- flush only the callback */
374 PRemoveMount, /* 28 -- delete mount point */
375 PNewStatMount, /* 29 -- new style mount point stat */
376 PGetFileCell, /* 30 -- get cell name for input file */
377 PGetWSCell, /* 31 -- get cell name for workstation */
378 PMariner, /* 32 - set/get mariner host */
379 PGetUserCell, /* 33 -- get cell name for user */
380 PBogus, /* 34 -- Enable/Disable logging */
381 PGetCellStatus, /* 35 */
382 PSetCellStatus, /* 36 */
383 PFlushVolumeData, /* 37 -- flush all data from a volume */
384 PSetSysName, /* 38 - Set system name */
385 PExportAfs, /* 39 - Export Afs to remote nfs clients */
386 PGetCacheSize, /* 40 - get cache size and usage */
387 PGetVnodeXStatus, /* 41 - get vcache's special status */
388 PSetSPrefs33, /* 42 - Set CM Server preferences... */
389 PGetSPrefs, /* 43 - Get CM Server preferences... */
390 PGag, /* 44 - turn off/on all CM messages */
391 PTwiddleRx, /* 45 - adjust some RX params */
392 PSetSPrefs, /* 46 - Set CM Server preferences... */
393 PStoreBehind, /* 47 - set degree of store behind to be done */
394 PGCPAGs, /* 48 - disable automatic pag gc-ing */
395 PGetInitParams, /* 49 - get initial cm params */
396 PGetCPrefs, /* 50 - get client interface addresses */
397 PSetCPrefs, /* 51 - set client interface addresses */
398 PFlushMount, /* 52 - flush mount symlink data */
399 PRxStatProc, /* 53 - control process RX statistics */
400 PRxStatPeer, /* 54 - control peer RX statistics */
401 PGetRxkcrypt, /* 55 -- Get rxkad encryption flag */
402 PSetRxkcrypt, /* 56 -- Set rxkad encryption flag */
403 PBogus, /* 57 -- arla: set file prio */
404 PBogus, /* 58 -- arla: fallback getfh */
405 PBogus, /* 59 -- arla: fallback fhopen */
406 PBogus, /* 60 -- arla: controls xfsdebug */
407 PBogus, /* 61 -- arla: controls arla debug */
408 PBogus, /* 62 -- arla: debug interface */
409 PBogus, /* 63 -- arla: print xfs status */
410 PBogus, /* 64 -- arla: force cache check */
411 PBogus, /* 65 -- arla: break callback */
412 PPrefetchFromTape, /* 66 -- MR-AFS: prefetch file from tape */
413 PFsCmd, /* 67 -- RXOSD: generic commnd interface */
414 PBogus, /* 68 -- arla: fetch stats */
415 PGetVnodeXStatus2, /* 69 - get caller access and some vcache status */
418 static pioctlFunction CpioctlSw[] = {
420 PNewAlias, /* 1 -- create new cell alias */
421 PListAliases, /* 2 -- list cell aliases */
422 PCallBackAddr, /* 3 -- request addr for callback rxcon */
424 PDiscon, /* 5 -- get/set discon mode */
435 static pioctlFunction OpioctlSw[] = {
437 PNFSNukeCreds, /* 1 -- nuke all creds for NFS client */
438 #if defined(AFS_CACHE_BYPASS)
439 PSetCachingThreshold /* 2 -- get/set cache-bypass size threshold */
441 PNoop /* 2 -- get/set cache-bypass size threshold */
445 #define PSetClientContext 99 /* Special pioctl to setup caller's creds */
446 int afs_nobody = NFS_NOBODY;
449 HandleIoctl(struct vcache *avc, afs_int32 acom,
450 struct afs_ioctl *adata)
455 AFS_STATCNT(HandleIoctl);
457 switch (acom & 0xff) {
459 avc->f.states |= CSafeStore;
461 /* SXW - Should we force a MetaData flush for this flag setting */
464 /* case 2 used to be abort store, but this is no longer provided,
465 * since it is impossible to implement under normal Unix.
469 /* return the name of the cell this file is open on */
473 tcell = afs_GetCell(avc->f.fid.Cell, READ_LOCK);
475 i = strlen(tcell->cellName) + 1; /* bytes to copy out */
477 if (i > adata->out_size) {
478 /* 0 means we're not interested in the output */
479 if (adata->out_size != 0)
483 AFS_COPYOUT(tcell->cellName, adata->out, i, code);
485 afs_PutCell(tcell, READ_LOCK);
491 case 49: /* VIOC_GETINITPARAMS */
492 if (adata->out_size < sizeof(struct cm_initparams)) {
495 AFS_COPYOUT(&cm_initParams, adata->out,
496 sizeof(struct cm_initparams), code);
508 return code; /* so far, none implemented */
512 /* For aix we don't temporarily bypass ioctl(2) but rather do our
513 * thing directly in the vnode layer call, VNOP_IOCTL; thus afs_ioctl
514 * is now called from afs_gn_ioctl.
517 afs_ioctl(struct vcache *tvc, int cmd, int arg)
519 struct afs_ioctl data;
522 AFS_STATCNT(afs_ioctl);
523 if (((cmd >> 8) & 0xff) == 'V') {
524 /* This is a VICEIOCTL call */
525 AFS_COPYIN(arg, (caddr_t) & data, sizeof(data), error);
528 error = HandleIoctl(tvc, cmd, &data);
531 /* No-op call; just return. */
535 # if defined(AFS_AIX32_ENV)
536 # if defined(AFS_AIX51_ENV)
539 kioctl(int fdes, int com, caddr_t arg, caddr_t ext, caddr_t arg2,
541 # else /* __64BIT__ */
543 kioctl32(int fdes, int com, caddr_t arg, caddr_t ext, caddr_t arg2,
545 # endif /* __64BIT__ */
548 kioctl(int fdes, int com, caddr_t arg, caddr_t ext)
549 # endif /* AFS_AIX51_ENV */
554 # ifdef AFS_AIX51_ENV
557 } u_uap, *uap = &u_uap;
560 int ioctlDone = 0, code = 0;
562 AFS_STATCNT(afs_xioctl);
566 # ifdef AFS_AIX51_ENV
570 if (setuerror(getf(uap->fd, &fd))) {
573 if (fd->f_type == DTYPE_VNODE) {
574 /* good, this is a vnode; next see if it is an AFS vnode */
575 tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */
576 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
577 /* This is an AFS vnode */
578 if (((uap->com >> 8) & 0xff) == 'V') {
579 struct afs_ioctl *datap;
582 (struct afs_ioctl *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
583 code=copyin_afs_ioctl((char *)uap->arg, datap);
585 osi_FreeSmallSpace(datap);
587 # if defined(AFS_AIX41_ENV)
590 return (setuerror(code), code);
592 code = HandleIoctl(tvc, uap->com, datap);
593 osi_FreeSmallSpace(datap);
596 # if defined(AFS_AIX41_ENV)
603 # if defined(AFS_AIX41_ENV)
605 # if defined(AFS_AIX51_ENV)
607 code = okioctl(fdes, com, arg, ext, arg2, arg3);
608 # else /* __64BIT__ */
609 code = okioctl32(fdes, com, arg, ext, arg2, arg3);
610 # endif /* __64BIT__ */
611 # else /* !AFS_AIX51_ENV */
612 code = okioctl(fdes, com, arg, ext);
613 # endif /* AFS_AIX51_ENV */
615 # elif defined(AFS_AIX32_ENV)
616 okioctl(fdes, com, arg, ext);
619 # if defined(KERNEL_HAVE_UERROR)
622 # if !defined(AFS_AIX41_ENV)
623 return (getuerror()? -1 : u.u_ioctlrv);
625 return getuerror()? -1 : 0;
632 #elif defined(AFS_SGI_ENV)
633 # if defined(AFS_SGI65_ENV)
634 afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
635 rval_t * rvalp, struct vopbd * vbds)
637 afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
638 rval_t * rvalp, struct vopbd * vbds)
641 struct afs_ioctl data;
647 AFS_STATCNT(afs_ioctl);
648 if (((cmd >> 8) & 0xff) == 'V') {
649 /* This is a VICEIOCTL call */
650 error = copyin_afs_ioctl(arg, &data);
653 locked = ISAFS_GLOCK();
656 error = HandleIoctl(tvc, cmd, &data);
661 /* No-op call; just return. */
665 #elif defined(AFS_SUN5_ENV)
666 struct afs_ioctl_sys {
673 afs_xioctl(struct afs_ioctl_sys *uap, rval_t *rvp)
677 int ioctlDone = 0, code = 0;
679 AFS_STATCNT(afs_xioctl);
680 # if defined(AFS_SUN57_ENV)
684 # elif defined(AFS_SUN54_ENV)
689 if (code = getf(uap->fd, &fd)) {
693 if (fd->f_vnode->v_type == VREG || fd->f_vnode->v_type == VDIR) {
694 tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */
695 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
696 /* This is an AFS vnode */
697 if (((uap->com >> 8) & 0xff) == 'V') {
698 struct afs_ioctl *datap;
701 (struct afs_ioctl *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
702 code=copyin_afs_ioctl((char *)uap->arg, datap);
704 osi_FreeSmallSpace(datap);
706 # if defined(AFS_SUN54_ENV)
713 code = HandleIoctl(tvc, uap->com, datap);
714 osi_FreeSmallSpace(datap);
720 # if defined(AFS_SUN57_ENV)
722 # elif defined(AFS_SUN54_ENV)
728 code = ioctl(uap, rvp);
732 #elif defined(AFS_LINUX22_ENV)
733 struct afs_ioctl_sys {
738 afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
741 struct afs_ioctl_sys ua, *uap = &ua;
743 int ioctlDone = 0, code = 0;
745 AFS_STATCNT(afs_xioctl);
750 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
751 /* This is an AFS vnode */
752 if (((uap->com >> 8) & 0xff) == 'V') {
753 struct afs_ioctl *datap;
755 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
756 code = copyin_afs_ioctl((char *)uap->arg, datap);
758 osi_FreeSmallSpace(datap);
762 code = HandleIoctl(tvc, uap->com, datap);
763 osi_FreeSmallSpace(datap);
772 #elif defined(AFS_DARWIN_ENV) && !defined(AFS_DARWIN80_ENV)
780 afs_xioctl(afs_proc_t *p, struct ioctl_args *uap, register_t *retval)
784 int ioctlDone = 0, code = 0;
786 AFS_STATCNT(afs_xioctl);
787 if ((code = fdgetf(p, uap->fd, &fd)))
789 if (fd->f_type == DTYPE_VNODE) {
790 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
791 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
792 /* This is an AFS vnode */
793 if (((uap->com >> 8) & 0xff) == 'V') {
794 struct afs_ioctl *datap;
796 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
797 code = copyin_afs_ioctl((char *)uap->arg, datap);
799 osi_FreeSmallSpace(datap);
803 code = HandleIoctl(tvc, uap->com, datap);
804 osi_FreeSmallSpace(datap);
812 return ioctl(p, uap, retval);
816 #elif defined(AFS_XBSD_ENV)
817 # if defined(AFS_FBSD_ENV)
820 afs_xioctl(struct thread *td, struct ioctl_args *uap,
823 afs_proc_t *p = td->td_proc;
832 afs_xioctl(afs_proc_t *p, struct ioctl_args *uap, register_t *retval)
835 struct filedesc *fdp;
837 int ioctlDone = 0, code = 0;
840 AFS_STATCNT(afs_xioctl);
841 # if defined(AFS_NBSD40_ENV)
842 fdp = p->l_proc->p_fd;
846 if ((u_int) uap->fd >= fdp->fd_nfiles
847 || (fd = fdp->fd_ofiles[uap->fd]) == NULL)
849 if ((fd->f_flag & (FREAD | FWRITE)) == 0)
851 /* first determine whether this is any sort of vnode */
852 if (fd->f_type == DTYPE_VNODE) {
853 /* good, this is a vnode; next see if it is an AFS vnode */
854 # if defined(AFS_OBSD_ENV)
856 IsAfsVnode((struct vnode *)fd->
857 f_data) ? VTOAFS((struct vnode *)fd->f_data) : NULL;
859 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
861 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
862 /* This is an AFS vnode */
863 if (((uap->com >> 8) & 0xff) == 'V') {
864 struct afs_ioctl *datap;
866 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
867 code = copyin_afs_ioctl((char *)uap->arg, datap);
869 osi_FreeSmallSpace(datap);
873 code = HandleIoctl(tvc, uap->com, datap);
874 osi_FreeSmallSpace(datap);
882 # if defined(AFS_FBSD_ENV)
883 return ioctl(td, uap);
884 # elif defined(AFS_OBSD_ENV)
885 code = sys_ioctl(p, uap, retval);
886 # elif defined(AFS_NBSD_ENV)
887 struct lwp *l = osi_curproc();
888 code = sys_ioctl(l, uap, retval);
894 #elif defined(UKERNEL)
902 } *uap = (struct a *)get_user_struct()->u_ap;
905 int ioctlDone = 0, code = 0;
907 AFS_STATCNT(afs_xioctl);
912 /* first determine whether this is any sort of vnode */
913 if (fd->f_type == DTYPE_VNODE) {
914 /* good, this is a vnode; next see if it is an AFS vnode */
915 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
916 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
917 /* This is an AFS vnode */
918 if (((uap->com >> 8) & 0xff) == 'V') {
919 struct afs_ioctl *datap;
921 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
922 code=copyin_afs_ioctl((char *)uap->arg, datap);
924 osi_FreeSmallSpace(datap);
927 return (setuerror(code), code);
929 code = HandleIoctl(tvc, uap->com, datap);
930 osi_FreeSmallSpace(datap);
943 #endif /* AFS_HPUX102_ENV */
945 #if defined(AFS_SGI_ENV)
946 /* "pioctl" system call entry point; just pass argument to the parameterized
955 afs_pioctl(struct pioctlargs *uap, rval_t * rvp)
959 AFS_STATCNT(afs_pioctl);
961 code = afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow);
963 # ifdef AFS_SGI64_ENV
970 #elif defined(AFS_FBSD_ENV)
972 afs_pioctl(struct thread *td, void *args, int *retval)
979 } *uap = (struct a *)args;
981 AFS_STATCNT(afs_pioctl);
982 return (afs_syscall_pioctl
983 (uap->path, uap->cmd, uap->cmarg, uap->follow, td->td_ucred));
986 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
988 afs_pioctl(afs_proc_t *p, void *args, int *retval)
995 } *uap = (struct a *)args;
997 AFS_STATCNT(afs_pioctl);
998 # if defined(AFS_DARWIN80_ENV) || defined(AFS_NBSD40_ENV)
999 return (afs_syscall_pioctl
1000 (uap->path, uap->cmd, uap->cmarg, uap->follow,
1003 return (afs_syscall_pioctl
1004 (uap->path, uap->cmd, uap->cmarg, uap->follow,
1005 # if defined(AFS_FBSD_ENV)
1008 p->p_cred->pc_ucred));
1015 /* macro to avoid adding any more #ifdef's to pioctl code. */
1016 #if defined(AFS_LINUX22_ENV) || defined(AFS_AIX41_ENV)
1017 #define PIOCTL_FREE_CRED() crfree(credp)
1019 #define PIOCTL_FREE_CRED()
1024 afs_syscall_pioctl(char *path, unsigned int com, caddr_t cmarg, int follow,
1025 rval_t *vvp, afs_ucred_t *credp)
1027 #ifdef AFS_DARWIN100_ENV
1028 afs_syscall64_pioctl(user_addr_t path, unsigned int com, user_addr_t cmarg,
1029 int follow, afs_ucred_t *credp)
1030 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1031 afs_syscall_pioctl(char *path, unsigned int com, caddr_t cmarg, int follow,
1034 afs_syscall_pioctl(char *path, unsigned int com, caddr_t cmarg, int follow)
1038 struct afs_ioctl data;
1039 #ifdef AFS_NEED_CLIENTCONTEXT
1040 afs_ucred_t *tmpcred = NULL;
1042 #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)
1043 afs_ucred_t *foreigncreds = NULL;
1046 struct vnode *vp = NULL;
1047 #ifdef AFS_AIX41_ENV
1048 struct ucred *credp = crref(); /* don't free until done! */
1050 #ifdef AFS_LINUX22_ENV
1051 cred_t *credp = crref(); /* don't free until done! */
1055 AFS_STATCNT(afs_syscall_pioctl);
1057 follow = 1; /* compat. with old venus */
1058 code = copyin_afs_ioctl(cmarg, &data);
1061 #if defined(KERNEL_HAVE_UERROR)
1066 if ((com & 0xff) == PSetClientContext) {
1067 #ifdef AFS_NEED_CLIENTCONTEXT
1068 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV)
1069 code = HandleClientContext(&data, &com, &foreigncreds, credp);
1071 code = HandleClientContext(&data, &com, &foreigncreds, osi_curcred());
1075 crfree(foreigncreds);
1078 #if defined(KERNEL_HAVE_UERROR)
1079 return (setuerror(code), code);
1084 #else /* AFS_NEED_CLIENTCONTEXT */
1086 #endif /* AFS_NEED_CLIENTCONTEXT */
1088 #ifdef AFS_NEED_CLIENTCONTEXT
1091 * We could have done without temporary setting the u.u_cred below
1092 * (foreigncreds could be passed as param the pioctl modules)
1093 * but calls such as afs_osi_suser() doesn't allow that since it
1094 * references u.u_cred directly. We could, of course, do something
1095 * like afs_osi_suser(cred) which, I think, is better since it
1096 * generalizes and supports multi cred environments...
1098 #if defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
1100 credp = foreigncreds;
1101 #elif defined(AFS_AIX41_ENV)
1102 tmpcred = crref(); /* XXX */
1103 crset(foreigncreds);
1104 #elif defined(AFS_HPUX101_ENV)
1105 tmpcred = p_cred(u.u_procp);
1106 set_p_cred(u.u_procp, foreigncreds);
1107 #elif defined(AFS_SGI_ENV)
1108 tmpcred = OSI_GET_CURRENT_CRED();
1109 OSI_SET_CURRENT_CRED(foreigncreds);
1112 u.u_cred = foreigncreds;
1115 #endif /* AFS_NEED_CLIENTCONTEXT */
1116 if ((com & 0xff) == 15) {
1117 /* special case prefetch so entire pathname eval occurs in helper process.
1118 * otherwise, the pioctl call is essentially useless */
1119 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1121 Prefetch(path, &data, follow,
1122 foreigncreds ? foreigncreds : credp);
1124 code = Prefetch(path, &data, follow, osi_curcred());
1127 #if defined(KERNEL_HAVE_UERROR)
1134 #ifdef AFS_AIX41_ENV
1136 lookupname(path, USR, follow, NULL, &vp,
1137 foreigncreds ? foreigncreds : credp);
1139 #ifdef AFS_LINUX22_ENV
1140 code = gop_lookupname_user(path, AFS_UIOUSER, follow, &dp);
1142 vp = (struct vnode *)dp->d_inode;
1144 code = gop_lookupname_user(path, AFS_UIOUSER, follow, &vp);
1145 #if defined(AFS_FBSD80_ENV) /* XXX check on 7x */
1148 #endif /* AFS_FBSD80_ENV */
1149 #endif /* AFS_LINUX22_ENV */
1150 #endif /* AFS_AIX41_ENV */
1154 #if defined(KERNEL_HAVE_UERROR)
1162 #if defined(AFS_SUN510_ENV)
1163 if (vp && !IsAfsVnode(vp)) {
1164 struct vnode *realvp;
1166 #ifdef AFS_SUN511_ENV
1167 (VOP_REALVP(vp, &realvp, NULL) == 0)
1169 (VOP_REALVP(vp, &realvp) == 0)
1172 struct vnode *oldvp = vp;
1180 /* now make the call if we were passed no file, or were passed an AFS file */
1181 if (!vp || IsAfsVnode(vp)) {
1182 #if defined(AFS_SUN5_ENV)
1183 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1184 #elif defined(AFS_AIX41_ENV)
1186 struct ucred *cred1, *cred2;
1189 cred1 = cred2 = foreigncreds;
1191 cred1 = cred2 = credp;
1193 code = afs_HandlePioctl(vp, com, &data, follow, &cred1);
1194 if (cred1 != cred2) {
1195 /* something changed the creds */
1199 #elif defined(AFS_HPUX101_ENV)
1201 struct ucred *cred = p_cred(u.u_procp);
1202 code = afs_HandlePioctl(vp, com, &data, follow, &cred);
1204 #elif defined(AFS_SGI_ENV)
1207 credp = OSI_GET_CURRENT_CRED();
1208 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1210 #elif defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1211 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1212 #elif defined(UKERNEL)
1213 code = afs_HandlePioctl(vp, com, &data, follow,
1214 &(get_user_struct()->u_cred));
1216 code = afs_HandlePioctl(vp, com, &data, follow, &u.u_cred);
1219 #if defined(KERNEL_HAVE_UERROR)
1222 code = EINVAL; /* not in /afs */
1227 #if defined(AFS_NEED_CLIENTCONTEXT)
1229 #ifdef AFS_AIX41_ENV
1230 crset(tmpcred); /* restore original credentials */
1232 #if defined(AFS_HPUX101_ENV)
1233 set_p_cred(u.u_procp, tmpcred); /* restore original credentials */
1234 #elif defined(AFS_SGI_ENV)
1235 OSI_SET_CURRENT_CRED(tmpcred); /* restore original credentials */
1236 #elif defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
1237 credp = tmpcred; /* restore original credentials */
1239 osi_curcred() = tmpcred; /* restore original credentials */
1240 #endif /* AFS_HPUX101_ENV */
1241 crfree(foreigncreds);
1244 #endif /* AFS_NEED_CLIENTCONTEXT */
1246 #ifdef AFS_LINUX22_ENV
1249 #if defined(AFS_FBSD80_ENV)
1250 if (VOP_ISLOCKED(vp))
1252 #endif /* AFS_FBSD80_ENV */
1253 AFS_RELE(vp); /* put vnode back */
1257 #if defined(KERNEL_HAVE_UERROR)
1260 return (getuerror());
1266 #ifdef AFS_DARWIN100_ENV
1268 afs_syscall_pioctl(char * path, unsigned int com, caddr_t cmarg,
1269 int follow, afs_ucred_t *credp)
1271 return afs_syscall64_pioctl(CAST_USER_ADDR_T(path), com,
1272 CAST_USER_ADDR_T((unsigned int)cmarg), follow,
1277 #define MAXPIOCTLTOKENLEN \
1278 (3*sizeof(afs_int32)+MAXKTCTICKETLEN+sizeof(struct ClearToken)+MAXKTCREALMLEN)
1281 afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
1282 struct afs_ioctl *ablob, int afollow,
1283 afs_ucred_t **acred)
1286 struct vrequest treq;
1288 afs_int32 function, device;
1289 struct afs_pdata input, output;
1290 struct afs_pdata copyInput, copyOutput;
1292 pioctlFunction *pioctlSw;
1294 struct afs_fakestat_state fakestate;
1296 memset(&input, 0, sizeof(input));
1297 memset(&output, 0, sizeof(output));
1299 avc = avp ? VTOAFS(avp) : NULL;
1300 afs_Trace3(afs_iclSetp, CM_TRACE_PIOCTL, ICL_TYPE_INT32, acom & 0xff,
1301 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, afollow);
1302 AFS_STATCNT(HandlePioctl);
1304 code = afs_InitReq(&treq, *acred);
1308 afs_InitFakeStat(&fakestate);
1310 code = afs_EvalFakeStat(&avc, &fakestate, &treq);
1314 device = (acom & 0xff00) >> 8;
1316 case 'V': /* Original pioctls */
1317 pioctlSw = VpioctlSw;
1318 pioctlSwSize = sizeof(VpioctlSw);
1320 case 'C': /* Coordinated/common pioctls */
1321 pioctlSw = CpioctlSw;
1322 pioctlSwSize = sizeof(CpioctlSw);
1324 case 'O': /* Coordinated/common pioctls */
1325 pioctlSw = OpioctlSw;
1326 pioctlSwSize = sizeof(OpioctlSw);
1332 function = acom & 0xff;
1333 if (function >= (pioctlSwSize / sizeof(char *))) {
1338 /* Do all range checking before continuing */
1339 if (ablob->in_size > MAXPIOCTLTOKENLEN ||
1340 ablob->in_size < 0 || ablob->out_size < 0) {
1345 code = afs_pd_alloc(&input, ablob->in_size);
1349 if (ablob->in_size > 0) {
1350 AFS_COPYIN(ablob->in, input.ptr, ablob->in_size, code);
1351 input.ptr[input.remaining] = '\0';
1356 if (function == 8 && device == 'V') { /* PGetTokens */
1357 code = afs_pd_alloc(&output, MAXPIOCTLTOKENLEN);
1359 code = afs_pd_alloc(&output, AFS_LRALLOCSIZ);
1365 copyOutput = output;
1368 (*pioctlSw[function]) (avc, function, &treq, ©Input,
1369 ©Output, acred);
1371 outSize = copyOutput.ptr - output.ptr;
1373 if (code == 0 && ablob->out_size > 0) {
1374 if (outSize > ablob->out_size) {
1375 code = E2BIG; /* data wont fit in user buffer */
1376 } else if (outSize) {
1377 AFS_COPYOUT(output.ptr, ablob->out, outSize, code);
1382 afs_pd_free(&input);
1383 afs_pd_free(&output);
1385 afs_PutFakeStat(&fakestate);
1386 return afs_CheckCode(code, &treq, 41);
1390 * VIOCGETFID (22) - Get file ID quickly
1394 * \param[in] ain not in use
1395 * \param[out] aout fid of requested file
1397 * \retval EINVAL Error if some of the initial arguments aren't set
1399 * \post get the file id of some file
1401 DECL_PIOCTL(PGetFID)
1403 AFS_STATCNT(PGetFID);
1406 if (afs_pd_putBytes(aout, &avc->f.fid, sizeof(struct VenusFid)) != 0)
1412 * VIOCSETAL (1) - Set access control list
1416 * \param[in] ain the ACL being set
1417 * \param[out] aout the ACL being set returned
1419 * \retval EINVAL Error if some of the standard args aren't set
1421 * \post Changed ACL, via direct writing to the wire
1424 dummy_PSetAcl(char *ain, char *aout)
1429 DECL_PIOCTL(PSetAcl)
1432 struct afs_conn *tconn;
1433 struct AFSOpaque acl;
1434 struct AFSVolSync tsync;
1435 struct AFSFetchStatus OutStatus;
1438 AFS_STATCNT(PSetAcl);
1442 if (afs_pd_getStringPtr(ain, &acl.AFSOpaque_val) != 0)
1444 acl.AFSOpaque_len = strlen(acl.AFSOpaque_val) + 1;
1445 if (acl.AFSOpaque_len > 1024)
1449 tconn = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
1451 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREACL);
1454 RXAFS_StoreACL(tconn->id, (struct AFSFid *)&avc->f.fid.Fid,
1455 &acl, &OutStatus, &tsync);
1460 } while (afs_Analyze
1461 (tconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_STOREACL,
1462 SHARED_LOCK, NULL));
1464 /* now we've forgotten all of the access info */
1465 ObtainWriteLock(&afs_xcbhash, 455);
1467 afs_DequeueCallback(avc);
1468 avc->f.states &= ~(CStatd | CUnique);
1469 ReleaseWriteLock(&afs_xcbhash);
1470 if (avc->f.fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
1471 osi_dnlc_purgedp(avc);
1473 /* SXW - Should we flush metadata here? */
1477 int afs_defaultAsynchrony = 0;
1480 * VIOC_STOREBEHIND (47) Adjust store asynchrony
1484 * \param[in] ain sbstruct (store behind structure) input
1485 * \param[out] aout resulting sbstruct
1488 * Error if the user doesn't have super-user credentials
1490 * Error if there isn't enough access to not check the mode bits
1493 * Changes either the default asynchrony (the amount of data that
1494 * can remain to be written when the cache manager returns control
1495 * to the user), or the asyncrony for the specified file.
1497 DECL_PIOCTL(PStoreBehind)
1499 struct sbstruct sbr;
1501 if (afs_pd_getBytes(ain, &sbr, sizeof(struct sbstruct)) != 0)
1504 if (sbr.sb_default != -1) {
1505 if (afs_osi_suser(*acred))
1506 afs_defaultAsynchrony = sbr.sb_default;
1511 if (avc && (sbr.sb_thisfile != -1)) {
1513 (avc, PRSFS_WRITE | PRSFS_ADMINISTER, areq, DONT_CHECK_MODE_BITS))
1514 avc->asynchrony = sbr.sb_thisfile;
1519 memset(&sbr, 0, sizeof(sbr));
1520 sbr.sb_default = afs_defaultAsynchrony;
1522 sbr.sb_thisfile = avc->asynchrony;
1525 return afs_pd_putBytes(aout, &sbr, sizeof(sbr));
1529 * VIOC_GCPAGS (48) - Disable automatic PAG gc'ing
1533 * \param[in] ain not in use
1534 * \param[out] aout not in use
1536 * \retval EACCES Error if the user doesn't have super-user credentials
1538 * \post set the gcpags to GCPAGS_USERDISABLED
1540 DECL_PIOCTL(PGCPAGs)
1542 if (!afs_osi_suser(*acred)) {
1545 afs_gcpags = AFS_GCPAGS_USERDISABLED;
1550 * VIOCGETAL (2) - Get access control list
1554 * \param[in] ain not in use
1555 * \param[out] aout the ACL
1557 * \retval EINVAL Error if some of the standard args aren't set
1558 * \retval ERANGE Error if the vnode of the file id is too large
1559 * \retval -1 Error if getting the ACL failed
1561 * \post Obtain the ACL, based on file ID
1564 * There is a hack to tell which type of ACL is being returned, checks
1565 * the top 2-bytes of the input size to judge what type of ACL it is,
1566 * only for dfs xlator ACLs
1568 DECL_PIOCTL(PGetAcl)
1570 struct AFSOpaque acl;
1571 struct AFSVolSync tsync;
1572 struct AFSFetchStatus OutStatus;
1574 struct afs_conn *tconn;
1578 AFS_STATCNT(PGetAcl);
1581 Fid.Volume = avc->f.fid.Fid.Volume;
1582 Fid.Vnode = avc->f.fid.Fid.Vnode;
1583 Fid.Unique = avc->f.fid.Fid.Unique;
1584 if (avc->f.states & CForeign) {
1586 * For a dfs xlator acl we have a special hack so that the
1587 * xlator will distinguish which type of acl will return. So
1588 * we currently use the top 2-bytes (vals 0-4) to tell which
1589 * type of acl to bring back. Horrible hack but this will
1590 * cause the least number of changes to code size and interfaces.
1592 if (Fid.Vnode & 0xc0000000)
1594 Fid.Vnode |= (ain->remaining << 30);
1596 acl.AFSOpaque_val = aout->ptr;
1598 tconn = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
1600 acl.AFSOpaque_val[0] = '\0';
1601 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHACL);
1603 code = RXAFS_FetchACL(tconn->id, &Fid, &acl, &OutStatus, &tsync);
1608 } while (afs_Analyze
1609 (tconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_FETCHACL,
1610 SHARED_LOCK, NULL));
1613 if (acl.AFSOpaque_len == 0)
1614 afs_pd_skip(aout, 1); /* leave the NULL */
1616 afs_pd_skip(aout, acl.AFSOpaque_len); /* Length of the ACL */
1622 * PNoop returns success. Used for functions which are not implemented
1623 * or are no longer in use.
1627 * \retval Always returns success
1630 * Functions involved in this:
1631 * 17 (VIOCENGROUP) -- used to be enable group;
1632 * 18 (VIOCDISGROUP) -- used to be disable group;
1633 * 2 (?) -- get/set cache-bypass size threshold
1642 * PBogus returns fail. Used for functions which are not implemented or
1643 * are no longer in use.
1647 * \retval EINVAL Always returns this value
1650 * Functions involved in this:
1656 * 13 (VIOCGETTIME) -- used to be quick check time;
1657 * 15 (VIOCPREFETCH) -- prefetch is now special-cased; see pioctl code!;
1658 * 16 (VIOCNOP) -- used to be testing code;
1659 * 19 (VIOCLISTGROUPS) -- used to be list group;
1660 * 23 (VIOCWAITFOREVER) -- used to be waitforever;
1661 * 57 (VIOC_FPRIOSTATUS) -- arla: set file prio;
1662 * 58 (VIOC_FHGET) -- arla: fallback getfh;
1663 * 59 (VIOC_FHOPEN) -- arla: fallback fhopen;
1664 * 60 (VIOC_XFSDEBUG) -- arla: controls xfsdebug;
1665 * 61 (VIOC_ARLADEBUG) -- arla: controls arla debug;
1666 * 62 (VIOC_AVIATOR) -- arla: debug interface;
1667 * 63 (VIOC_XFSDEBUG_PRINT) -- arla: print xfs status;
1668 * 64 (VIOC_CALCULATE_CACHE) -- arla: force cache check;
1669 * 65 (VIOC_BREAKCELLBACK) -- arla: break callback;
1670 * 68 (?) -- arla: fetch stats;
1674 AFS_STATCNT(PBogus);
1679 * VIOC_FILE_CELL_NAME (30) - Get cell in which file lives
1683 * \param[in] ain not in use (avc used to pass in file id)
1684 * \param[out] aout cell name
1686 * \retval EINVAL Error if some of the standard args aren't set
1687 * \retval ESRCH Error if the file isn't part of a cell
1689 * \post Get a cell based on a passed in file id
1691 DECL_PIOCTL(PGetFileCell)
1695 AFS_STATCNT(PGetFileCell);
1698 tcell = afs_GetCell(avc->f.fid.Cell, READ_LOCK);
1702 if (afs_pd_putString(aout, tcell->cellName) != 0)
1705 afs_PutCell(tcell, READ_LOCK);
1710 * VIOC_GET_WS_CELL (31) - Get cell in which workstation lives
1714 * \param[in] ain not in use
1715 * \param[out] aout cell name
1718 * Error if the afs daemon hasn't started yet
1720 * Error if the machine isn't part of a cell, for whatever reason
1722 * \post Get the primary cell that the machine is a part of.
1724 DECL_PIOCTL(PGetWSCell)
1726 struct cell *tcell = NULL;
1728 AFS_STATCNT(PGetWSCell);
1729 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1730 return EIO; /* Inappropriate ioctl for device */
1732 tcell = afs_GetPrimaryCell(READ_LOCK);
1733 if (!tcell) /* no primary cell? */
1736 if (afs_pd_putString(aout, tcell->cellName) != 0)
1738 afs_PutCell(tcell, READ_LOCK);
1743 * VIOC_GET_PRIMARY_CELL (33) - Get primary cell for caller
1747 * \param[in] ain not in use (user id found via areq)
1748 * \param[out] aout cell name
1751 * Error if the user id doesn't have a primary cell specified
1753 * \post Get the primary cell for a certain user, based on the user's uid
1755 DECL_PIOCTL(PGetUserCell)
1758 struct unixuser *tu;
1761 AFS_STATCNT(PGetUserCell);
1762 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1763 return EIO; /* Inappropriate ioctl for device */
1765 /* return the cell name of the primary cell for this user */
1766 i = UHash(areq->uid);
1767 ObtainWriteLock(&afs_xuser, 224);
1768 for (tu = afs_users[i]; tu; tu = tu->next) {
1769 if (tu->uid == areq->uid && (tu->states & UPrimary)) {
1771 ReleaseWriteLock(&afs_xuser);
1776 tcell = afs_GetCell(tu->cell, READ_LOCK);
1777 afs_PutUser(tu, WRITE_LOCK);
1781 if (afs_pd_putString(aout, tcell->cellName) != 0)
1783 afs_PutCell(tcell, READ_LOCK);
1786 ReleaseWriteLock(&afs_xuser);
1791 /* Work out which cell we're changing tokens for */
1793 _settok_tokenCell(char *cellName, int *cellNum, int *primary) {
1797 if (cellName && strlen(cellName) > 0) {
1798 cell = afs_GetCellByName(cellName, READ_LOCK);
1800 cell = afs_GetPrimaryCell(READ_LOCK);
1811 *cellNum = cell->cellNum;
1812 afs_PutCell(cell, READ_LOCK);
1819 _settok_setParentPag(afs_ucred_t **cred) {
1821 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1823 osi_procname(procname, 256);
1824 afs_warnuser("Process %d (%s) tried to change pags in PSetTokens\n",
1825 MyPidxx2Pid(MyPidxx), procname);
1826 return setpag(osi_curporc(), cred, -1, &pag, 1);
1828 return setpag(cred, -1, &pag, 1);
1833 * VIOCSETTOK (3) - Set authentication tokens
1837 * \param[in] ain the krb tickets from which to set the afs tokens
1838 * \param[out] aout not in use
1841 * Error if the ticket is either too long or too short
1843 * Error if the AFS initState is below 101
1845 * Error if the cell for which the Token is being set can't be found
1848 * Set the Tokens for a specific cell name, unless there is none set,
1849 * then default to primary
1852 DECL_PIOCTL(PSetTokens)
1857 struct unixuser *tu;
1858 struct ClearToken clear;
1862 struct vrequest treq;
1863 afs_int32 flag, set_parent_pag = 0;
1865 AFS_STATCNT(PSetTokens);
1866 if (!afs_resourceinit_flag) {
1870 if (afs_pd_getInt(ain, &stLen) != 0)
1873 stp = afs_pd_where(ain); /* remember where the ticket is */
1874 if (stLen < 0 || stLen > MAXKTCTICKETLEN)
1875 return EINVAL; /* malloc may fail */
1876 if (afs_pd_skip(ain, stLen) != 0)
1879 if (afs_pd_getInt(ain, &size) != 0)
1881 if (size != sizeof(struct ClearToken))
1884 if (afs_pd_getBytes(ain, &clear, sizeof(struct ClearToken)) !=0)
1887 if (clear.AuthHandle == -1)
1888 clear.AuthHandle = 999; /* more rxvab compat stuff */
1890 if (afs_pd_remaining(ain) != 0) {
1891 /* still stuff left? we've got primary flag and cell name.
1894 if (afs_pd_getInt(ain, &flag) != 0)
1897 /* some versions of gcc appear to need != 0 in order to get this
1899 if ((flag & 0x8000) != 0) { /* XXX Use Constant XXX */
1904 if (afs_pd_getStringPtr(ain, &cellName) != 0)
1907 code = _settok_tokenCell(cellName, &cellNum, NULL);
1911 /* default to primary cell, primary id */
1912 code = _settok_tokenCell(NULL, &cellNum, &flag);
1917 if (set_parent_pag) {
1918 if (_settok_setParentPag(acred) == 0) {
1919 afs_InitReq(&treq, *acred);
1924 /* now we just set the tokens */
1925 tu = afs_GetUser(areq->uid, cellNum, WRITE_LOCK);
1926 /* Set tokens destroys any that are already there */
1927 afs_FreeTokens(&tu->tokens);
1928 afs_AddRxkadToken(&tu->tokens, stp, stLen, &clear);
1930 afs_stats_cmfullperf.authent.TicketUpdates++;
1931 afs_ComputePAGStats();
1932 #endif /* AFS_NOSTATS */
1933 tu->states |= UHasTokens;
1934 tu->states &= ~UTokensBad;
1935 afs_SetPrimary(tu, flag);
1936 tu->tokenTime = osi_Time();
1937 afs_ResetUserConns(tu);
1938 afs_NotifyUser(tu, UTokensObtained);
1939 afs_PutUser(tu, WRITE_LOCK);
1945 * VIOCGETVOLSTAT (4) - Get volume status
1949 * \param[in] ain not in use
1950 * \param[out] aout status of the volume
1952 * \retval EINVAL Error if some of the standard args aren't set
1955 * The status of a volume (based on the FID of the volume), or an
1956 * offline message /motd
1958 DECL_PIOCTL(PGetVolumeStatus)
1961 char *offLineMsg = afs_osi_Alloc(256);
1962 char *motd = afs_osi_Alloc(256);
1963 struct afs_conn *tc;
1965 struct AFSFetchVolumeStatus volstat;
1969 AFS_STATCNT(PGetVolumeStatus);
1976 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
1978 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS);
1981 RXAFS_GetVolumeStatus(tc->id, avc->f.fid.Fid.Volume, &volstat,
1982 &Name, &offLineMsg, &motd);
1987 } while (afs_Analyze
1988 (tc, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS,
1989 SHARED_LOCK, NULL));
1993 /* Copy all this junk into msg->im_data, keeping track of the lengths. */
1994 if (afs_pd_putBytes(aout, &volstat, sizeof(VolumeStatus)) != 0)
1996 if (afs_pd_putString(aout, volName) != 0)
1998 if (afs_pd_putString(aout, offLineMsg) != 0)
2000 if (afs_pd_putString(aout, motd) != 0)
2003 afs_osi_Free(offLineMsg, 256);
2004 afs_osi_Free(motd, 256);
2009 * VIOCSETVOLSTAT (5) - Set volume status
2014 * values to set the status at, offline message, message of the day,
2015 * volume name, minimum quota, maximum quota
2017 * status of a volume, offlines messages, minimum quota, maximumm quota
2020 * Error if some of the standard args aren't set
2022 * Error if the volume is read only, or a backup volume
2024 * Error if the volume can't be accessed
2026 * Error if the volume name, offline message, and motd are too big
2029 * Set the status of a volume, including any offline messages,
2030 * a minimum quota, and a maximum quota
2032 DECL_PIOCTL(PSetVolumeStatus)
2037 struct afs_conn *tc;
2039 struct AFSFetchVolumeStatus volstat;
2040 struct AFSStoreVolumeStatus storeStat;
2044 AFS_STATCNT(PSetVolumeStatus);
2048 tvp = afs_GetVolume(&avc->f.fid, areq, READ_LOCK);
2050 if (tvp->states & (VRO | VBackup)) {
2051 afs_PutVolume(tvp, READ_LOCK);
2054 afs_PutVolume(tvp, READ_LOCK);
2059 if (afs_pd_getBytes(ain, &volstat, sizeof(AFSFetchVolumeStatus)) != 0)
2062 if (afs_pd_getStringPtr(ain, &volName) != 0)
2064 if (strlen(volName) > 32)
2067 if (afs_pd_getStringPtr(ain, &offLineMsg) != 0)
2069 if (strlen(offLineMsg) > 256)
2072 if (afs_pd_getStringPtr(ain, &motd) != 0)
2074 if (strlen(motd) > 256)
2077 /* Done reading ... */
2080 if (volstat.MinQuota != -1) {
2081 storeStat.MinQuota = volstat.MinQuota;
2082 storeStat.Mask |= AFS_SETMINQUOTA;
2084 if (volstat.MaxQuota != -1) {
2085 storeStat.MaxQuota = volstat.MaxQuota;
2086 storeStat.Mask |= AFS_SETMAXQUOTA;
2089 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
2091 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS);
2094 RXAFS_SetVolumeStatus(tc->id, avc->f.fid.Fid.Volume, &storeStat,
2095 volName, offLineMsg, motd);
2100 } while (afs_Analyze
2101 (tc, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS,
2102 SHARED_LOCK, NULL));
2106 /* we are sending parms back to make compat. with prev system. should
2107 * change interface later to not ask for current status, just set new
2110 if (afs_pd_putBytes(aout, &volstat, sizeof(VolumeStatus)) != 0)
2112 if (afs_pd_putString(aout, volName) != 0)
2114 if (afs_pd_putString(aout, offLineMsg) != 0)
2116 if (afs_pd_putString(aout, motd) != 0)
2123 * VIOCFLUSH (6) - Invalidate cache entry
2127 * \param[in] ain not in use
2128 * \param[out] aout not in use
2130 * \retval EINVAL Error if some of the standard args aren't set
2132 * \post Flush any information the cache manager has on an entry
2136 AFS_STATCNT(PFlush);
2139 #ifdef AFS_BOZONLOCK_ENV
2140 afs_BozonLock(&avc->pvnLock, avc); /* Since afs_TryToSmush will do a pvn_vptrunc */
2142 ObtainWriteLock(&avc->lock, 225);
2143 afs_ResetVCache(avc, *acred);
2144 ReleaseWriteLock(&avc->lock);
2145 #ifdef AFS_BOZONLOCK_ENV
2146 afs_BozonUnlock(&avc->pvnLock, avc);
2152 * VIOC_AFS_STAT_MT_PT (29) - Stat mount point
2157 * the last component in a path, related to mountpoint that we're
2158 * looking for information about
2160 * volume, cell, link data
2162 * \retval EINVAL Error if some of the standard args aren't set
2163 * \retval ENOTDIR Error if the 'mount point' argument isn't a directory
2164 * \retval EIO Error if the link data can't be accessed
2166 * \post Get the volume, and cell, as well as the link data for a mount point
2168 DECL_PIOCTL(PNewStatMount)
2173 struct VenusFid tfid;
2176 struct sysname_info sysState;
2177 afs_size_t offset, len;
2179 AFS_STATCNT(PNewStatMount);
2183 if (afs_pd_getStringPtr(ain, &name) != 0)
2186 code = afs_VerifyVCache(avc, areq);
2189 if (vType(avc) != VDIR) {
2192 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
2195 Check_AtSys(avc, name, &sysState, areq);
2196 ObtainReadLock(&tdc->lock);
2198 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
2199 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
2200 ReleaseReadLock(&tdc->lock);
2201 afs_PutDCache(tdc); /* we're done with the data */
2202 bufp = sysState.name;
2206 tfid.Cell = avc->f.fid.Cell;
2207 tfid.Fid.Volume = avc->f.fid.Fid.Volume;
2208 if (!tfid.Fid.Unique && (avc->f.states & CForeign)) {
2209 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
2211 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
2217 if (tvc->mvstat != 1) {
2222 ObtainWriteLock(&tvc->lock, 226);
2223 code = afs_HandleLink(tvc, areq);
2225 if (tvc->linkData) {
2226 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
2229 /* we have the data */
2230 if (afs_pd_putString(aout, tvc->linkData) != 0)
2236 ReleaseWriteLock(&tvc->lock);
2239 if (sysState.allocked)
2240 osi_FreeLargeSpace(bufp);
2245 * VIOCGETTOK (8) - Get authentication tokens
2249 * \param[in] ain cellid to return tokens for
2250 * \param[out] aout token
2253 * Error if the afs daemon hasn't started yet
2255 * Error if the input parameter is out of the bounds of the available
2258 * Error if there aren't tokens for this cell
2261 * If the input paramater exists, get the token that corresponds to
2262 * the parameter value, if there is no token at this value, get the
2263 * token for the first cell
2265 * \notes "it's a weird interface (from comments in the code)"
2268 DECL_PIOCTL(PGetTokens)
2272 struct unixuser *tu;
2273 union tokenUnion *token;
2274 afs_int32 iterator = 0;
2278 AFS_STATCNT(PGetTokens);
2279 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2280 return EIO; /* Inappropriate ioctl for device */
2282 /* weird interface. If input parameter is present, it is an integer and
2283 * we're supposed to return the parm'th tokens for this unix uid.
2284 * If not present, we just return tokens for cell 1.
2285 * If counter out of bounds, return EDOM.
2286 * If no tokens for the particular cell, return ENOTCONN.
2287 * Also, if this mysterious parm is present, we return, along with the
2288 * tokens, the primary cell indicator (an afs_int32 0) and the cell name
2289 * at the end, in that order.
2291 newStyle = (afs_pd_remaining(ain) > 0);
2293 if (afs_pd_getInt(ain, &iterator) != 0)
2296 i = UHash(areq->uid);
2297 ObtainReadLock(&afs_xuser);
2298 for (tu = afs_users[i]; tu; tu = tu->next) {
2300 if (tu->uid == areq->uid && (tu->states & UHasTokens)) {
2301 if (iterator-- == 0)
2302 break; /* are we done yet? */
2305 if (tu->uid == areq->uid && afs_IsPrimaryCellNum(tu->cell))
2311 * No need to hold a read lock on each user entry
2315 ReleaseReadLock(&afs_xuser);
2320 if (!(tu->states & UHasTokens)
2321 || !afs_HasUsableTokens(tu->tokens, osi_Time())) {
2322 tu->states |= (UTokensBad | UNeedsReset);
2323 afs_NotifyUser(tu, UTokensDropped);
2324 afs_PutUser(tu, READ_LOCK);
2327 token = afs_FindToken(tu->tokens, RX_SECIDX_KAD);
2329 /* for compat, we try to return 56 byte tix if they fit */
2330 iterator = token->rxkad.ticketLen;
2332 iterator = 56; /* # of bytes we're returning */
2334 if (afs_pd_putInt(aout, iterator) != 0)
2336 if (afs_pd_putBytes(aout, token->rxkad.ticket, token->rxkad.ticketLen) != 0)
2338 if (token->rxkad.ticketLen < 56) {
2339 /* Tokens are always 56 bytes or larger */
2340 if (afs_pd_skip(aout, iterator - token->rxkad.ticketLen) != 0) {
2345 if (afs_pd_putInt(aout, sizeof(struct ClearToken)) != 0)
2347 if (afs_pd_putBytes(aout, &token->rxkad.clearToken,
2348 sizeof(struct ClearToken)) != 0)
2352 /* put out primary id and cell name, too */
2353 iterator = (tu->states & UPrimary ? 1 : 0);
2354 if (afs_pd_putInt(aout, iterator) != 0)
2356 tcell = afs_GetCell(tu->cell, READ_LOCK);
2358 if (afs_pd_putString(aout, tcell->cellName) != 0)
2360 afs_PutCell(tcell, READ_LOCK);
2362 if (afs_pd_putString(aout, "") != 0)
2365 /* Got here, all is good */
2368 afs_PutUser(tu, READ_LOCK);
2373 * VIOCUNLOG (9) - Invalidate tokens
2377 * \param[in] ain not in use
2378 * \param[out] aout not in use
2380 * \retval EIO Error if the afs daemon hasn't been started yet
2382 * \post remove tokens from a user, specified by the user id
2384 * \notes sets the token's time to 0, which then causes it to be removed
2385 * \notes Unlog is the same as un-pag in OpenAFS
2390 struct unixuser *tu;
2392 AFS_STATCNT(PUnlog);
2393 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2394 return EIO; /* Inappropriate ioctl for device */
2396 i = UHash(areq->uid);
2397 ObtainWriteLock(&afs_xuser, 227);
2398 for (tu = afs_users[i]; tu; tu = tu->next) {
2399 if (tu->uid == areq->uid) {
2400 tu->states &= ~UHasTokens;
2401 afs_FreeTokens(&tu->tokens);
2403 ReleaseWriteLock(&afs_xuser);
2404 afs_NotifyUser(tu, UTokensDropped);
2405 /* We have to drop the lock over the call to afs_ResetUserConns,
2406 * since it obtains the afs_xvcache lock. We could also keep
2407 * the lock, and modify ResetUserConns to take parm saying we
2408 * obtained the lock already, but that is overkill. By keeping
2409 * the "tu" pointer held over the released lock, we guarantee
2410 * that we won't lose our place, and that we'll pass over
2411 * every user conn that existed when we began this call.
2413 afs_ResetUserConns(tu);
2415 ObtainWriteLock(&afs_xuser, 228);
2417 /* set the expire times to 0, causes
2418 * afs_GCUserData to remove this entry
2421 #endif /* UKERNEL */
2424 ReleaseWriteLock(&afs_xuser);
2429 * VIOC_AFS_MARINER_HOST (32) - Get/set mariner (cache manager monitor) host
2433 * \param[in] ain host address to be set
2434 * \param[out] aout old host address
2437 * depending on whether or not a variable is set, either get the host
2438 * for the cache manager monitor, or set the old address and give it
2441 * \notes Errors turn off mariner
2443 DECL_PIOCTL(PMariner)
2445 afs_int32 newHostAddr;
2446 afs_int32 oldHostAddr;
2448 AFS_STATCNT(PMariner);
2450 memcpy((char *)&oldHostAddr, (char *)&afs_marinerHost,
2453 oldHostAddr = 0xffffffff; /* disabled */
2455 if (afs_pd_getInt(ain, &newHostAddr) != 0)
2458 if (newHostAddr == 0xffffffff) {
2459 /* disable mariner operations */
2461 } else if (newHostAddr) {
2463 afs_marinerHost = newHostAddr;
2466 if (afs_pd_putInt(aout, oldHostAddr) != 0)
2473 * VIOCCKSERV (10) - Check that servers are up
2477 * \param[in] ain name of the cell
2478 * \param[out] aout current down server list
2480 * \retval EIO Error if the afs daemon hasn't started yet
2481 * \retval EACCES Error if the user doesn't have super-user credentials
2482 * \retval ENOENT Error if we are unable to obtain the cell
2485 * Either a fast check (where it doesn't contact servers) or a
2486 * local check (checks local cell only)
2488 DECL_PIOCTL(PCheckServers)
2493 char *cellName = NULL;
2495 struct chservinfo *pcheck;
2497 AFS_STATCNT(PCheckServers);
2499 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2500 return EIO; /* Inappropriate ioctl for device */
2502 /* This is tricky, because we need to peak at the datastream to see
2503 * what we're getting. For now, let's cheat. */
2505 /* ain contains either an int32 or a string */
2506 if (ain->remaining == 0)
2509 if (*(afs_int32 *)ain->ptr == 0x12345678) { /* For afs3.3 version */
2510 pcheck = afs_pd_inline(ain, sizeof(*pcheck));
2514 if (pcheck->tinterval >= 0) {
2515 if (afs_pd_putInt(aout, afs_probe_interval) != 0)
2517 if (pcheck->tinterval > 0) {
2518 if (!afs_osi_suser(*acred))
2520 afs_probe_interval = pcheck->tinterval;
2524 temp = pcheck->tflags;
2526 cellName = pcheck->tbuffer;
2527 } else { /* For pre afs3.3 versions */
2528 if (afs_pd_getInt(ain, &temp) != 0)
2530 if (afs_pd_remaining(ain) > 0) {
2531 if (afs_pd_getStringPtr(ain, &cellName) != 0)
2537 * 1: fast check, don't contact servers.
2538 * 2: local cell only.
2541 /* have cell name, too */
2542 cellp = afs_GetCellByName(cellName, READ_LOCK);
2547 if (!cellp && (temp & 2)) {
2548 /* use local cell */
2549 cellp = afs_GetPrimaryCell(READ_LOCK);
2551 if (!(temp & 1)) { /* if not fast, call server checker routine */
2552 afs_CheckServers(1, cellp); /* check down servers */
2553 afs_CheckServers(0, cellp); /* check up servers */
2555 /* now return the current down server list */
2556 ObtainReadLock(&afs_xserver);
2557 for (i = 0; i < NSERVERS; i++) {
2558 for (ts = afs_servers[i]; ts; ts = ts->next) {
2559 if (cellp && ts->cell != cellp)
2560 continue; /* cell spec'd and wrong */
2561 if ((ts->flags & SRVR_ISDOWN)
2562 && ts->addr->sa_portal != ts->cell->vlport) {
2563 afs_pd_putInt(aout, ts->addr->sa_ip);
2567 ReleaseReadLock(&afs_xserver);
2569 afs_PutCell(cellp, READ_LOCK);
2574 * VIOCCKBACK (11) - Check backup volume mappings
2578 * \param[in] ain not in use
2579 * \param[out] aout not in use
2581 * \retval EIO Error if the afs daemon hasn't started yet
2584 * Check the root volume, and then check the names if the volume
2585 * check variable is set to force, has expired, is busy, or if
2586 * the mount points variable is set
2588 DECL_PIOCTL(PCheckVolNames)
2590 AFS_STATCNT(PCheckVolNames);
2591 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2592 return EIO; /* Inappropriate ioctl for device */
2594 afs_CheckRootVolume();
2595 afs_CheckVolumeNames(AFS_VOLCHECK_FORCE | AFS_VOLCHECK_EXPIRED |
2596 AFS_VOLCHECK_BUSY | AFS_VOLCHECK_MTPTS);
2601 * VIOCCKCONN (12) - Check connections for a user
2605 * \param[in] ain not in use
2606 * \param[out] aout not in use
2609 * Error if no user is specififed, the user has no tokens set,
2610 * or if the user's tokens are bad
2613 * check to see if a user has the correct authentication.
2614 * If so, allow access.
2616 * \notes Check the connections to all the servers specified
2618 DECL_PIOCTL(PCheckAuth)
2622 struct afs_conn *tc;
2623 struct unixuser *tu;
2626 AFS_STATCNT(PCheckAuth);
2627 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2628 return EIO; /* Inappropriate ioctl for device */
2631 tu = afs_GetUser(areq->uid, 1, READ_LOCK); /* check local cell authentication */
2635 /* we have a user */
2636 ObtainReadLock(&afs_xsrvAddr);
2637 ObtainReadLock(&afs_xconn);
2639 /* any tokens set? */
2640 if ((tu->states & UHasTokens) == 0)
2642 /* all connections in cell 1 working? */
2643 for (i = 0; i < NSERVERS; i++) {
2644 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2645 for (tc = sa->conns; tc; tc = tc->next) {
2646 if (tc->user == tu && (tu->states & UTokensBad))
2651 ReleaseReadLock(&afs_xsrvAddr);
2652 ReleaseReadLock(&afs_xconn);
2653 afs_PutUser(tu, READ_LOCK);
2655 if (afs_pd_putInt(aout, retValue) != 0)
2661 Prefetch(uparmtype apath, struct afs_ioctl *adata, int afollow,
2666 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2672 AFS_STATCNT(Prefetch);
2675 tp = osi_AllocLargeSpace(1024);
2676 AFS_COPYINSTR(apath, tp, 1024, &bufferSize, code);
2678 osi_FreeLargeSpace(tp);
2681 if (afs_BBusy()) { /* do this as late as possible */
2682 osi_FreeLargeSpace(tp);
2683 return EWOULDBLOCK; /* pretty close */
2685 afs_BQueue(BOP_PATH, (struct vcache *)0, 0, 0, acred, (afs_size_t) 0,
2686 (afs_size_t) 0, tp, (void *)0, (void *)0);
2691 * VIOCWHEREIS (14) - Find out where a volume is located
2695 * \param[in] ain not in use
2696 * \param[out] aout volume location
2698 * \retval EINVAL Error if some of the default arguments don't exist
2699 * \retval ENODEV Error if there is no such volume
2701 * \post fine a volume, based on a volume file id
2703 * \notes check each of the servers specified
2705 DECL_PIOCTL(PFindVolume)
2712 AFS_STATCNT(PFindVolume);
2715 tvp = afs_GetVolume(&avc->f.fid, areq, READ_LOCK);
2719 for (i = 0; i < AFS_MAXHOSTS; i++) {
2720 ts = tvp->serverHost[i];
2723 if (afs_pd_putInt(aout, ts->addr->sa_ip) != 0) {
2728 if (i < AFS_MAXHOSTS) {
2729 /* still room for terminating NULL, add it on */
2730 if (afs_pd_putInt(aout, 0) != 0) {
2736 afs_PutVolume(tvp, READ_LOCK);
2741 * VIOCACCESS (20) - Access using PRS_FS bits
2745 * \param[in] ain PRS_FS bits
2746 * \param[out] aout not in use
2748 * \retval EINVAL Error if some of the initial arguments aren't set
2749 * \retval EACCES Error if access is denied
2751 * \post check to make sure access is allowed
2753 DECL_PIOCTL(PViceAccess)
2758 AFS_STATCNT(PViceAccess);
2762 code = afs_VerifyVCache(avc, areq);
2766 if (afs_pd_getInt(ain, &temp) != 0)
2769 code = afs_AccessOK(avc, temp, areq, CHECK_MODE_BITS);
2777 * VIOC_GETPAG (13) - Get PAG value
2781 * \param[in] ain not in use
2782 * \param[out] aout PAG value or NOPAG
2784 * \post get PAG value for the caller's cred
2786 DECL_PIOCTL(PGetPAG)
2790 pag = PagInCred(*acred);
2792 return afs_pd_putInt(aout, pag);
2795 DECL_PIOCTL(PPrecache)
2799 /*AFS_STATCNT(PPrecache);*/
2800 if (!afs_osi_suser(*acred))
2803 if (afs_pd_getInt(ain, &newValue) != 0)
2806 afs_preCache = newValue*1024;
2811 * VIOCSETCACHESIZE (24) - Set venus cache size in 1000 units
2815 * \param[in] ain the size the venus cache should be set to
2816 * \param[out] aout not in use
2818 * \retval EACCES Error if the user doesn't have super-user credentials
2819 * \retval EROFS Error if the cache is set to be in memory
2822 * Set the cache size based on user input. If no size is given,
2823 * set it to the default OpenAFS cache size.
2826 * recompute the general cache parameters for every single block allocated
2828 DECL_PIOCTL(PSetCacheSize)
2833 AFS_STATCNT(PSetCacheSize);
2835 if (!afs_osi_suser(*acred))
2837 /* too many things are setup initially in mem cache version */
2838 if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
2840 if (afs_pd_getInt(ain, &newValue) != 0)
2843 afs_cacheBlocks = afs_stats_cmperf.cacheBlocksOrig;
2845 if (newValue < afs_min_cache)
2846 afs_cacheBlocks = afs_min_cache;
2848 afs_cacheBlocks = newValue;
2850 afs_stats_cmperf.cacheBlocksTotal = afs_cacheBlocks;
2851 afs_ComputeCacheParms(); /* recompute basic cache parameters */
2852 afs_MaybeWakeupTruncateDaemon();
2853 while (waitcnt++ < 100 && afs_cacheBlocks < afs_blocksUsed) {
2854 afs_osi_Wait(1000, 0, 0);
2855 afs_MaybeWakeupTruncateDaemon();
2860 #define MAXGCSTATS 16
2862 * VIOCGETCACHEPARMS (40) - Get cache stats
2866 * \param[in] ain afs index flags
2867 * \param[out] aout cache blocks, blocks used, blocks files (in an array)
2869 * \post Get the cache blocks, and how many of the cache blocks there are
2871 DECL_PIOCTL(PGetCacheSize)
2873 afs_int32 results[MAXGCSTATS];
2875 struct dcache * tdc;
2878 AFS_STATCNT(PGetCacheSize);
2880 if (afs_pd_remaining(ain) == sizeof(afs_int32)) {
2881 afs_pd_getInt(ain, &flags); /* can't error, we just checked size */
2882 } else if (afs_pd_remaining(ain) == 0) {
2888 memset(results, 0, sizeof(results));
2889 results[0] = afs_cacheBlocks;
2890 results[1] = afs_blocksUsed;
2891 results[2] = afs_cacheFiles;
2894 for (i = 0; i < afs_cacheFiles; i++) {
2895 if (afs_indexFlags[i] & IFFree) results[3]++;
2897 } else if (2 == flags){
2898 for (i = 0; i < afs_cacheFiles; i++) {
2899 if (afs_indexFlags[i] & IFFree) results[3]++;
2900 if (afs_indexFlags[i] & IFEverUsed) results[4]++;
2901 if (afs_indexFlags[i] & IFDataMod) results[5]++;
2902 if (afs_indexFlags[i] & IFDirtyPages) results[6]++;
2903 if (afs_indexFlags[i] & IFAnyPages) results[7]++;
2904 if (afs_indexFlags[i] & IFDiscarded) results[8]++;
2906 tdc = afs_indexTable[i];
2909 size = tdc->validPos;
2910 if ( 0 < size && size < (1<<12) ) results[10]++;
2911 else if (size < (1<<14) ) results[11]++;
2912 else if (size < (1<<16) ) results[12]++;
2913 else if (size < (1<<18) ) results[13]++;
2914 else if (size < (1<<20) ) results[14]++;
2915 else if (size >= (1<<20) ) results[15]++;
2919 return afs_pd_putBytes(aout, results, sizeof(results));
2923 * VIOCFLUSHCB (25) - Flush callback only
2927 * \param[in] ain not in use
2928 * \param[out] aout not in use
2930 * \retval EINVAL Error if some of the standard args aren't set
2931 * \retval 0 0 returned if the volume is set to read-only
2934 * Flushes callbacks, by setting the length of callbacks to one,
2935 * setting the next callback to be sent to the CB_DROPPED value,
2936 * and then dequeues everything else.
2938 DECL_PIOCTL(PRemoveCallBack)
2940 struct afs_conn *tc;
2942 struct AFSCallBack CallBacks_Array[1];
2943 struct AFSCBFids theFids;
2944 struct AFSCBs theCBs;
2947 AFS_STATCNT(PRemoveCallBack);
2950 if (avc->f.states & CRO)
2951 return 0; /* read-only-ness can't change */
2952 ObtainWriteLock(&avc->lock, 229);
2953 theFids.AFSCBFids_len = 1;
2954 theCBs.AFSCBs_len = 1;
2955 theFids.AFSCBFids_val = (struct AFSFid *)&avc->f.fid.Fid;
2956 theCBs.AFSCBs_val = CallBacks_Array;
2957 CallBacks_Array[0].CallBackType = CB_DROPPED;
2958 if (avc->callback) {
2960 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
2962 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
2964 code = RXAFS_GiveUpCallBacks(tc->id, &theFids, &theCBs);
2968 /* don't set code on failure since we wouldn't use it */
2969 } while (afs_Analyze
2970 (tc, code, &avc->f.fid, areq,
2971 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK, NULL));
2973 ObtainWriteLock(&afs_xcbhash, 457);
2974 afs_DequeueCallback(avc);
2976 avc->f.states &= ~(CStatd | CUnique);
2977 ReleaseWriteLock(&afs_xcbhash);
2978 if (avc->f.fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
2979 osi_dnlc_purgedp(avc);
2981 ReleaseWriteLock(&avc->lock);
2986 * VIOCNEWCELL (26) - Configure new cell
2991 * the name of the cell, the hosts that will be a part of the cell,
2992 * whether or not it's linked with another cell, the other cell it's
2993 * linked with, the file server port, and the volume server port
2997 * \retval EIO Error if the afs daemon hasn't started yet
2998 * \retval EACCES Error if the user doesn't have super-user cedentials
2999 * \retval EINVAL Error if some 'magic' var doesn't have a certain bit set
3001 * \post creates a new cell
3003 DECL_PIOCTL(PNewCell)
3005 afs_int32 cellHosts[AFS_MAXCELLHOSTS], magic = 0;
3006 char *newcell = NULL;
3007 char *linkedcell = NULL;
3009 afs_int32 linkedstate = 0;
3010 afs_int32 fsport = 0, vlport = 0;
3013 AFS_STATCNT(PNewCell);
3014 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3015 return EIO; /* Inappropriate ioctl for device */
3017 if (!afs_osi_suser(*acred))
3020 if (afs_pd_getInt(ain, &magic) != 0)
3022 if (magic != 0x12345678)
3025 /* A 3.4 fs newcell command will pass an array of AFS_MAXCELLHOSTS
3026 * server addresses while the 3.5 fs newcell command passes
3027 * AFS_MAXHOSTS. To figure out which is which, check if the cellname
3030 * This whole logic is bogus, because it relies on the newer command
3031 * sending its 12th address as 0.
3033 if ((afs_pd_remaining(ain) < AFS_MAXCELLHOSTS +3) * sizeof(afs_int32))
3036 newcell = afs_pd_where(ain) + (AFS_MAXCELLHOSTS + 3) * sizeof(afs_int32);
3037 if (newcell[0] != '\0') {
3040 skip = AFS_MAXHOSTS - AFS_MAXCELLHOSTS;
3043 /* AFS_MAXCELLHOSTS (=8) is less than AFS_MAXHOSTS (=13) */
3044 if (afs_pd_getBytes(ain, &cellHosts,
3045 AFS_MAXCELLHOSTS * sizeof(afs_int32)) != 0)
3047 if (afs_pd_skip(ain, skip * sizeof(afs_int32)) !=0)
3050 if (afs_pd_getInt(ain, &fsport) != 0)
3053 fsport = 0; /* Privileged ports not allowed */
3055 if (afs_pd_getInt(ain, &vlport) != 0)
3058 vlport = 0; /* Privileged ports not allowed */
3060 if (afs_pd_getInt(ain, &ls) != 0)
3063 if (afs_pd_getStringPtr(ain, &newcell) != 0)
3067 if (afs_pd_getStringPtr(ain, &linkedcell) != 0)
3069 linkedstate |= CLinkedCell;
3072 linkedstate |= CNoSUID; /* setuid is disabled by default for fs newcell */
3074 afs_NewCell(newcell, cellHosts, linkedstate, linkedcell, fsport,
3079 DECL_PIOCTL(PNewAlias)
3081 /* create a new cell alias */
3082 char *realName, *aliasName;
3084 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3085 return EIO; /* Inappropriate ioctl for device */
3087 if (!afs_osi_suser(*acred))
3090 if (afs_pd_getStringPtr(ain, &aliasName) != 0)
3092 if (afs_pd_getStringPtr(ain, &realName) != 0)
3095 return afs_NewCellAlias(aliasName, realName);
3099 * VIOCGETCELL (27) - Get cell info
3103 * \param[in] ain The cell index of a specific cell
3104 * \param[out] aout list of servers in the cell
3106 * \retval EIO Error if the afs daemon hasn't started yet
3107 * \retval EDOM Error if there is no cell asked about
3109 * \post Lists the cell's server names and and addresses
3111 DECL_PIOCTL(PListCells)
3113 afs_int32 whichCell;
3114 struct cell *tcell = 0;
3118 AFS_STATCNT(PListCells);
3119 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3120 return EIO; /* Inappropriate ioctl for device */
3122 if (afs_pd_getInt(ain, &whichCell) != 0)
3125 tcell = afs_GetCellByIndex(whichCell, READ_LOCK);
3131 for (i = 0; i < AFS_MAXCELLHOSTS; i++) {
3132 if (tcell->cellHosts[i] == 0)
3134 if (afs_pd_putInt(aout, tcell->cellHosts[i]->addr->sa_ip) != 0)
3137 for (;i < AFS_MAXCELLHOSTS; i++) {
3138 if (afs_pd_putInt(aout, 0) != 0)
3141 if (afs_pd_putString(aout, tcell->cellName) != 0)
3146 afs_PutCell(tcell, READ_LOCK);
3150 DECL_PIOCTL(PListAliases)
3152 afs_int32 whichAlias;
3153 struct cell_alias *tcalias = 0;
3156 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3157 return EIO; /* Inappropriate ioctl for device */
3159 if (afs_pd_getInt(ain, &whichAlias) != 0)
3162 tcalias = afs_GetCellAlias(whichAlias);
3163 if (tcalias == NULL)
3167 if (afs_pd_putString(aout, tcalias->alias) != 0)
3169 if (afs_pd_putString(aout, tcalias->cell) != 0)
3174 afs_PutCellAlias(tcalias);
3179 * VIOC_AFS_DELETE_MT_PT (28) - Delete mount point
3183 * \param[in] ain the name of the file in this dir to remove
3184 * \param[out] aout not in use
3187 * Error if some of the standard args aren't set
3189 * Error if the argument to remove is not a directory
3191 * Error if there is no cache to remove the mount point from or
3192 * if a vcache doesn't exist
3195 * Ensure that everything is OK before deleting the mountpoint.
3196 * If not, don't delete. Delete a mount point based on a file id.
3198 DECL_PIOCTL(PRemoveMount)
3203 struct sysname_info sysState;
3204 afs_size_t offset, len;
3205 struct afs_conn *tc;
3208 struct AFSFetchStatus OutDirStatus;
3209 struct VenusFid tfid;
3210 struct AFSVolSync tsync;
3213 /* "ain" is the name of the file in this dir to remove */
3215 AFS_STATCNT(PRemoveMount);
3218 if (afs_pd_getStringPtr(ain, &name) != 0)
3221 code = afs_VerifyVCache(avc, areq);
3224 if (vType(avc) != VDIR)
3227 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1); /* test for error below */
3230 Check_AtSys(avc, name, &sysState, areq);
3231 ObtainReadLock(&tdc->lock);
3233 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
3234 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
3235 ReleaseReadLock(&tdc->lock);
3236 bufp = sysState.name;
3241 tfid.Cell = avc->f.fid.Cell;
3242 tfid.Fid.Volume = avc->f.fid.Fid.Volume;
3243 if (!tfid.Fid.Unique && (avc->f.states & CForeign)) {
3244 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
3246 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3253 if (tvc->mvstat != 1) {
3259 ObtainWriteLock(&tvc->lock, 230);
3260 code = afs_HandleLink(tvc, areq);
3262 if (tvc->linkData) {
3263 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
3268 ReleaseWriteLock(&tvc->lock);
3269 osi_dnlc_purgedp(tvc);
3275 ObtainWriteLock(&avc->lock, 231);
3276 osi_dnlc_remove(avc, bufp, tvc);
3278 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
3280 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE);
3283 RXAFS_RemoveFile(tc->id, (struct AFSFid *)&avc->f.fid.Fid, bufp,
3284 &OutDirStatus, &tsync);
3289 } while (afs_Analyze
3290 (tc, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_REMOVEFILE,
3291 SHARED_LOCK, NULL));
3296 ReleaseWriteLock(&avc->lock);
3300 /* we have the thing in the cache */
3301 ObtainWriteLock(&tdc->lock, 661);
3302 if (afs_LocalHero(avc, tdc, &OutDirStatus, 1)) {
3303 /* we can do it locally */
3304 code = afs_dir_Delete(tdc, bufp);
3306 ZapDCE(tdc); /* surprise error -- invalid value */
3310 ReleaseWriteLock(&tdc->lock);
3311 afs_PutDCache(tdc); /* drop ref count */
3313 avc->f.states &= ~CUnique; /* For the dfs xlator */
3314 ReleaseWriteLock(&avc->lock);
3317 if (sysState.allocked)
3318 osi_FreeLargeSpace(bufp);
3323 * VIOC_GETCELLSTATUS (35) - Get cell status info
3327 * \param[in] ain The cell you want status information on
3328 * \param[out] aout cell state (as a struct)
3330 * \retval EIO Error if the afs daemon hasn't started yet
3331 * \retval ENOENT Error if the cell doesn't exist
3333 * \post Returns the state of the cell as defined in a struct cell
3335 DECL_PIOCTL(PGetCellStatus)
3341 AFS_STATCNT(PGetCellStatus);
3342 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3343 return EIO; /* Inappropriate ioctl for device */
3345 if (afs_pd_getStringPtr(ain, &cellName) != 0)
3348 tcell = afs_GetCellByName(cellName, READ_LOCK);
3351 temp = tcell->states;
3352 afs_PutCell(tcell, READ_LOCK);
3354 return afs_pd_putInt(aout, temp);
3358 * VIOC_SETCELLSTATUS (36) - Set corresponding info
3363 * The cell you want to set information about, and the values you
3368 * \retval EIO Error if the afs daemon hasn't started yet
3369 * \retval EACCES Error if the user doesn't have super-user credentials
3372 * Set the state of the cell in a defined struct cell, based on
3373 * whether or not SetUID is allowed
3375 DECL_PIOCTL(PSetCellStatus)
3379 afs_int32 flags0, flags1;
3381 if (!afs_osi_suser(*acred))
3383 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3384 return EIO; /* Inappropriate ioctl for device */
3386 if (afs_pd_getInt(ain, &flags0) != 0)
3388 if (afs_pd_getInt(ain, &flags1) != 0)
3390 if (afs_pd_getStringPtr(ain, &cellName) != 0)
3393 tcell = afs_GetCellByName(cellName, WRITE_LOCK);
3396 if (flags0 & CNoSUID)
3397 tcell->states |= CNoSUID;
3399 tcell->states &= ~CNoSUID;
3400 afs_PutCell(tcell, WRITE_LOCK);
3405 * VIOC_FLUSHVOLUME (37) - Flush whole volume's data
3409 * \param[in] ain not in use (args in avc)
3410 * \param[out] aout not in use
3412 * \retval EINVAL Error if some of the standard args aren't set
3413 * \retval EIO Error if the afs daemon hasn't started yet
3416 * Flush all cached contents of a volume. Exactly what stays and what
3417 * goes depends on the platform.
3420 * Does not flush a file that a user has open and is using, because
3421 * it will be re-created on next write. Also purges the dnlc,
3422 * because things are screwed up.
3424 DECL_PIOCTL(PFlushVolumeData)
3430 afs_int32 cell, volume;
3431 struct afs_q *tq, *uq;
3432 #ifdef AFS_DARWIN80_ENV
3436 AFS_STATCNT(PFlushVolumeData);
3439 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3440 return EIO; /* Inappropriate ioctl for device */
3442 volume = avc->f.fid.Fid.Volume; /* who to zap */
3443 cell = avc->f.fid.Cell;
3446 * Clear stat'd flag from all vnodes from this volume; this will
3447 * invalidate all the vcaches associated with the volume.
3450 ObtainReadLock(&afs_xvcache);
3451 i = VCHashV(&avc->f.fid);
3452 for (tq = afs_vhashTV[i].prev; tq != &afs_vhashTV[i]; tq = uq) {
3455 if (tvc->f.fid.Fid.Volume == volume && tvc->f.fid.Cell == cell) {
3456 if (tvc->f.states & CVInit) {
3457 ReleaseReadLock(&afs_xvcache);
3458 afs_osi_Sleep(&tvc->f.states);
3461 #ifdef AFS_DARWIN80_ENV
3462 if (tvc->f.states & CDeadVnode) {
3463 if (!(tvc->f.states & CBulkFetching)) {
3464 ReleaseReadLock(&afs_xvcache);
3465 afs_osi_Sleep(&tvc->f.states);
3472 if (vnode_ref(vp)) {
3478 if (tvc->f.states & (CBulkFetching|CDeadVnode)) {
3480 vnode_recycle(AFSTOV(tvc));
3486 ReleaseReadLock(&afs_xvcache);
3487 #ifdef AFS_BOZONLOCK_ENV
3488 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
3490 ObtainWriteLock(&tvc->lock, 232);
3492 ObtainWriteLock(&afs_xcbhash, 458);
3493 afs_DequeueCallback(tvc);
3494 tvc->f.states &= ~(CStatd | CDirty);
3495 ReleaseWriteLock(&afs_xcbhash);
3496 if (tvc->f.fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
3497 osi_dnlc_purgedp(tvc);
3498 afs_TryToSmush(tvc, *acred, 1);
3499 ReleaseWriteLock(&tvc->lock);
3500 #ifdef AFS_BOZONLOCK_ENV
3501 afs_BozonUnlock(&tvc->pvnLock, tvc);
3503 #ifdef AFS_DARWIN80_ENV
3504 vnode_put(AFSTOV(tvc));
3506 ObtainReadLock(&afs_xvcache);
3508 /* our tvc ptr is still good until now */
3512 ReleaseReadLock(&afs_xvcache);
3515 ObtainWriteLock(&afs_xdcache, 328); /* needed to flush any stuff */
3516 for (i = 0; i < afs_cacheFiles; i++) {
3517 if (!(afs_indexFlags[i] & IFEverUsed))
3518 continue; /* never had any data */
3519 tdc = afs_GetDSlot(i, NULL);
3520 if (tdc->refCount <= 1) { /* too high, in use by running sys call */
3521 ReleaseReadLock(&tdc->tlock);
3522 if (tdc->f.fid.Fid.Volume == volume && tdc->f.fid.Cell == cell) {
3523 if (!(afs_indexFlags[i] & IFDataMod)) {
3524 /* if the file is modified, but has a ref cnt of only 1,
3525 * then someone probably has the file open and is writing
3526 * into it. Better to skip flushing such a file, it will be
3527 * brought back immediately on the next write anyway.
3529 * If we *must* flush, then this code has to be rearranged
3530 * to call afs_storeAllSegments() first */
3531 afs_FlushDCache(tdc);
3535 ReleaseReadLock(&tdc->tlock);
3537 afs_PutDCache(tdc); /* bumped by getdslot */
3539 ReleaseWriteLock(&afs_xdcache);
3541 ObtainReadLock(&afs_xvolume);
3542 for (i = 0; i < NVOLS; i++) {
3543 for (tv = afs_volumes[i]; tv; tv = tv->next) {
3544 if (tv->volume == volume) {
3545 afs_ResetVolumeInfo(tv);
3550 ReleaseReadLock(&afs_xvolume);
3552 /* probably, a user is doing this, probably, because things are screwed up.
3553 * maybe it's the dnlc's fault? */
3560 * VIOCGETVCXSTATUS (41) - gets vnode x status
3565 * not in use (avc used)
3567 * vcxstat: the file id, the data version, any lock, the parent vnode,
3568 * the parent unique id, the trunc position, the callback, cbExpires,
3569 * what access is being made, what files are open,
3570 * any users executing/writing, the flock count, the states,
3574 * Error if some of the initial default arguments aren't set
3576 * Error if access to check the mode bits is denied
3579 * gets stats for the vnode, a struct listed in vcxstat
3581 DECL_PIOCTL(PGetVnodeXStatus)
3584 struct vcxstat stat;
3587 /* AFS_STATCNT(PGetVnodeXStatus); */
3590 code = afs_VerifyVCache(avc, areq);
3593 if (vType(avc) == VDIR)
3594 mode = PRSFS_LOOKUP;
3597 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
3600 memset(&stat, 0, sizeof(struct vcxstat));
3601 stat.fid = avc->f.fid;
3602 hset32(stat.DataVersion, hgetlo(avc->f.m.DataVersion));
3603 stat.lock = avc->lock;
3604 stat.parentVnode = avc->f.parent.vnode;
3605 stat.parentUnique = avc->f.parent.unique;
3606 hset(stat.flushDV, avc->flushDV);
3607 hset(stat.mapDV, avc->mapDV);
3608 stat.truncPos = avc->f.truncPos;
3609 { /* just grab the first two - won't break anything... */
3610 struct axscache *ac;
3612 for (i = 0, ac = avc->Access; ac && i < CPSIZE; i++, ac = ac->next) {
3613 stat.randomUid[i] = ac->uid;
3614 stat.randomAccess[i] = ac->axess;
3617 stat.callback = afs_data_pointer_to_int32(avc->callback);
3618 stat.cbExpires = avc->cbExpires;
3619 stat.anyAccess = avc->f.anyAccess;
3620 stat.opens = avc->opens;
3621 stat.execsOrWriters = avc->execsOrWriters;
3622 stat.flockCount = avc->flockCount;
3623 stat.mvstat = avc->mvstat;
3624 stat.states = avc->f.states;
3625 return afs_pd_putBytes(aout, &stat, sizeof(struct vcxstat));
3629 DECL_PIOCTL(PGetVnodeXStatus2)
3632 struct vcxstat2 stat;
3637 code = afs_VerifyVCache(avc, areq);
3640 if (vType(avc) == VDIR)
3641 mode = PRSFS_LOOKUP;
3644 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
3647 memset(&stat, 0, sizeof(struct vcxstat2));
3649 stat.cbExpires = avc->cbExpires;
3650 stat.anyAccess = avc->f.anyAccess;
3651 stat.mvstat = avc->mvstat;
3652 stat.callerAccess = afs_GetAccessBits(avc, ~0, areq);
3654 return afs_pd_putBytes(aout, &stat, sizeof(struct vcxstat2));
3659 * VIOC_AFS_SYSNAME (38) - Change @sys value
3663 * \param[in] ain new value for @sys
3664 * \param[out] aout count, entry, list (debug values?)
3667 * Error if afsd isn't running, the new sysname is too large,
3668 * the new sysname causes issues (starts with a . or ..),
3669 * there is no PAG set in the credentials, or the user of a PAG
3672 * Error if the user doesn't have super-user credentials
3675 * Set the value of @sys if these things work: if the input isn't
3676 * too long or if input doesn't start with . or ..
3679 * We require root for local sysname changes, but not for remote
3680 * (since we don't really believe remote uids anyway)
3681 * outname[] shouldn't really be needed- this is left as an
3682 * exercise for the reader.
3684 DECL_PIOCTL(PSetSysName)
3686 char *inname = NULL;
3687 char outname[MAXSYSNAME];
3688 afs_int32 setsysname;
3690 struct afs_exporter *exporter;
3691 struct unixuser *au;
3692 afs_int32 pag, error;
3693 int t, count, num = 0, allpags = 0;
3695 struct afs_pdata validate;
3697 AFS_STATCNT(PSetSysName);
3698 if (!afs_globalVFS) {
3699 /* Afsd is NOT running; disable it */
3700 #if defined(KERNEL_HAVE_UERROR)
3701 return (setuerror(EINVAL), EINVAL);
3706 if (afs_pd_getInt(ain, &setsysname) != 0)
3708 if (setsysname & 0x8000) {
3710 setsysname &= ~0x8000;
3715 if (setsysname < 0 || setsysname > MAXNUMSYSNAMES)
3718 for (count = 0; count < setsysname; count++) {
3719 if (afs_pd_getStringPtr(&validate, &inname) != 0)
3722 if (t >= MAXSYSNAME || t <= 0)
3724 /* check for names that can shoot us in the foot */
3725 if (inname[0] == '.' && (inname[1] == 0
3726 || (inname[1] == '.' && inname[2] == 0)))
3729 /* args ok, so go back to the beginning of that section */
3731 if (afs_pd_getStringPtr(ain, &inname) != 0)
3735 if (afs_cr_gid(*acred) == RMTUSER_REQ ||
3736 afs_cr_gid(*acred) == RMTUSER_REQ_PRIV) { /* Handles all exporters */
3737 if (allpags && afs_cr_gid(*acred) != RMTUSER_REQ_PRIV) {
3740 pag = PagInCred(*acred);
3742 return EINVAL; /* Better than panicing */
3744 if (!(au = afs_FindUser(pag, -1, READ_LOCK))) {
3745 return EINVAL; /* Better than panicing */
3747 if (!(exporter = au->exporter)) {
3748 afs_PutUser(au, READ_LOCK);
3749 return EINVAL; /* Better than panicing */
3751 error = EXP_SYSNAME(exporter, inname, &sysnamelist,
3754 if (error == ENODEV)
3755 foundname = 0; /* sysname not set yet! */
3757 afs_PutUser(au, READ_LOCK);
3762 strcpy(outname, sysnamelist[0]);
3764 afs_PutUser(au, READ_LOCK);
3768 /* Not xlating, so local case */
3770 osi_Panic("PSetSysName: !afs_sysname\n");
3771 if (!setsysname) { /* user just wants the info */
3772 strcpy(outname, afs_sysname);
3773 foundname = afs_sysnamecount;
3774 sysnamelist = afs_sysnamelist;
3775 } else { /* Local guy; only root can change sysname */
3776 if (!afs_osi_suser(*acred))
3779 /* allpags makes no sense for local use */
3783 /* clear @sys entries from the dnlc, once afs_lookup can
3784 * do lookups of @sys entries and thinks it can trust them */
3785 /* privs ok, store the entry, ... */
3787 if (strlen(inname) >= MAXSYSNAME-1)
3789 strcpy(afs_sysname, inname);
3791 if (setsysname > 1) { /* ... or list */
3792 for (count = 1; count < setsysname; ++count) {
3793 if (!afs_sysnamelist[count])
3795 ("PSetSysName: no afs_sysnamelist entry to write\n");
3796 if (afs_pd_getString(ain, afs_sysnamelist[count],
3801 afs_sysnamecount = setsysname;
3806 if (afs_pd_putInt(aout, foundname) != 0)
3809 if (afs_pd_putString(aout, outname) != 0)
3811 for (count = 1; count < foundname; ++count) { /* ... or list. */
3812 if (!sysnamelist[count])
3814 ("PSetSysName: no afs_sysnamelist entry to read\n");
3815 t = strlen(sysnamelist[count]);
3816 if (t >= MAXSYSNAME)
3817 osi_Panic("PSetSysName: sysname entry garbled\n");
3818 if (afs_pd_putString(aout, sysnamelist[count]) != 0)
3826 /* sequential search through the list of touched cells is not a good
3827 * long-term solution here. For small n, though, it should be just
3828 * fine. Should consider special-casing the local cell for large n.
3829 * Likewise for PSetSPrefs.
3831 * s - number of ids in array l[] -- NOT index of last id
3832 * l - array of cell ids which have volumes that need to be sorted
3833 * vlonly - sort vl servers or file servers?
3836 ReSortCells_cb(struct cell *cell, void *arg)
3838 afs_int32 *p = (afs_int32 *) arg;
3839 afs_int32 *l = p + 1;
3842 for (i = 0; i < s; i++) {
3843 if (l[i] == cell->cellNum) {
3844 ObtainWriteLock(&cell->lock, 690);
3845 afs_SortServers(cell->cellHosts, AFS_MAXCELLHOSTS);
3846 ReleaseWriteLock(&cell->lock);
3854 ReSortCells(int s, afs_int32 * l, int vlonly)
3862 p = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * (s + 1));
3864 memcpy(p + 1, l, s * sizeof(afs_int32));
3865 afs_TraverseCells(&ReSortCells_cb, p);
3866 afs_osi_Free(p, sizeof(afs_int32) * (s + 1));
3870 ObtainReadLock(&afs_xvolume);
3871 for (i = 0; i < NVOLS; i++) {
3872 for (j = afs_volumes[i]; j; j = j->next) {
3873 for (k = 0; k < s; k++)
3874 if (j->cell == l[k]) {
3875 ObtainWriteLock(&j->lock, 233);
3876 afs_SortServers(j->serverHost, AFS_MAXHOSTS);
3877 ReleaseWriteLock(&j->lock);
3882 ReleaseReadLock(&afs_xvolume);
3886 static int debugsetsp = 0;
3888 afs_setsprefs(struct spref *sp, unsigned int num, unsigned int vlonly)
3891 int i, j, k, matches, touchedSize;
3892 struct server *srvr = NULL;
3893 afs_int32 touched[34];
3897 for (k = 0; k < num; sp++, k++) {
3899 afs_warn("sp host=%x, rank=%d\n", sp->host.s_addr, sp->rank);
3902 ObtainReadLock(&afs_xserver);
3904 i = SHash(sp->host.s_addr);
3905 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3906 if (sa->sa_ip == sp->host.s_addr) {
3908 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
3909 || (sa->sa_portal == AFS_FSPORT);
3910 if ((!vlonly && isfs) || (vlonly && !isfs)) {
3917 if (sa && matches) { /* found one! */
3919 afs_warn("sa ip=%x, ip_rank=%d\n", sa->sa_ip, sa->sa_iprank);
3921 sa->sa_iprank = sp->rank + afs_randomMod15();
3922 afs_SortOneServer(sa->server);
3925 /* if we don't know yet what cell it's in, this is moot */
3926 for (j = touchedSize - 1;
3927 j >= 0 && touched[j] != srvr->cell->cellNum; j--)
3928 /* is it in our list of touched cells ? */ ;
3929 if (j < 0) { /* no, it's not */
3930 touched[touchedSize++] = srvr->cell->cellNum;
3931 if (touchedSize >= 32) { /* watch for ovrflow */
3932 ReleaseReadLock(&afs_xserver);
3933 ReSortCells(touchedSize, touched, vlonly);
3935 ObtainReadLock(&afs_xserver);
3941 ReleaseReadLock(&afs_xserver);
3942 /* if we didn't find one, start to create one. */
3943 /* Note that it doesn't have a cell yet... */
3945 afs_uint32 temp = sp->host.s_addr;
3947 afs_GetServer(&temp, 1, 0, (vlonly ? AFS_VLPORT : AFS_FSPORT),
3948 WRITE_LOCK, (afsUUID *) 0, 0);
3949 srvr->addr->sa_iprank = sp->rank + afs_randomMod15();
3950 afs_PutServer(srvr, WRITE_LOCK);
3952 } /* for all cited preferences */
3954 ReSortCells(touchedSize, touched, vlonly);
3959 * VIOC_SETPREFS (46) - Set server ranks
3961 * \param[in] ain the sprefs value you want the sprefs to be set to
3962 * \param[out] aout not in use
3965 * Error if the afs daemon hasn't started yet
3967 * Error if the user doesn't have super-user credentials
3969 * Error if the struct setsprefs is too large or if it multiplied
3970 * by the number of servers is too large
3972 * \post set the sprefs using the afs_setsprefs() function
3974 DECL_PIOCTL(PSetSPrefs)
3976 struct setspref *ssp;
3980 AFS_STATCNT(PSetSPrefs);
3982 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3983 return EIO; /* Inappropriate ioctl for device */
3985 if (!afs_osi_suser(*acred))
3988 /* The I/O handling here is ghastly, as it relies on overrunning the ends
3989 * of arrays. But, i'm not quite brave enough to change it yet. */
3991 ainSize = ain->remaining;
3993 if (ainSize < sizeof(struct setspref))
3996 ssp = (struct setspref *)ainPtr;
3997 if (ainSize < (sizeof(struct setspref)
3998 + sizeof(struct spref) * ssp->num_servers-1))
4001 afs_setsprefs(&(ssp->servers[0]), ssp->num_servers,
4002 (ssp->flags & DBservers));
4007 * VIOC_SETPREFS33 (42) - Set server ranks (deprecated)
4009 * \param[in] ain the server preferences to be set
4010 * \param[out] aout not in use
4012 * \retval EIO Error if the afs daemon hasn't started yet
4013 * \retval EACCES Error if the user doesn't have super-user credentials
4015 * \post set the server preferences, calling a function
4017 * \notes this may only be performed by the local root user.
4019 DECL_PIOCTL(PSetSPrefs33)
4021 AFS_STATCNT(PSetSPrefs);
4022 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4023 return EIO; /* Inappropriate ioctl for device */
4026 if (!afs_osi_suser(*acred))
4029 afs_setsprefs((struct spref *)afs_pd_where(ain),
4030 afs_pd_remaining(ain) / sizeof(struct spref),
4036 * VIOC_GETSPREFS (43) - Get server ranks
4040 * \param[in] ain the server preferences to get
4041 * \param[out] aout the server preferences information
4043 * \retval EIO Error if the afs daemon hasn't started yet
4044 * \retval ENOENT Error if the sprefrequest is too large
4046 * \post Get the sprefs
4049 * in the hash table of server structs, all servers with the same
4050 * IP address; will be on the same overflow chain; This could be
4051 * sped slightly in some circumstances by having it cache the
4052 * immediately previous slot in the hash table and some
4053 * supporting information; Only reports file servers now.
4055 DECL_PIOCTL(PGetSPrefs)
4057 struct sprefrequest spin; /* input */
4058 struct sprefinfo *spout; /* output */
4059 struct spref *srvout; /* one output component */
4060 int i, j; /* counters for hash table traversal */
4061 struct server *srvr; /* one of CM's server structs */
4063 int vlonly; /* just return vlservers ? */
4066 AFS_STATCNT(PGetSPrefs);
4067 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4068 return EIO; /* Inappropriate ioctl for device */
4070 /* Work out from the size whether we've got a new, or old, style pioctl */
4071 if (afs_pd_remaining(ain) < sizeof(struct sprefrequest)) {
4072 if (afs_pd_getBytes(ain, &spin, sizeof(struct sprefrequest_33)) != 0)
4077 if (afs_pd_getBytes(ain, &spin, sizeof(struct sprefrequest)) != 0)
4079 vlonly = (spin.flags & DBservers);
4082 /* This code relies on overflowing arrays. It's ghastly, but I'm not
4083 * quite brave enough to tackle it yet ...
4086 /* struct sprefinfo includes 1 server struct... that size gets added
4087 * in during the loop that follows.
4089 spout = afs_pd_inline(aout,
4090 sizeof(struct sprefinfo) - sizeof(struct spref));
4091 spout->next_offset = spin.offset;
4092 spout->num_servers = 0;
4093 srvout = spout->servers;
4095 ObtainReadLock(&afs_xserver);
4096 for (i = 0, j = 0; j < NSERVERS; j++) { /* sift through hash table */
4097 for (sa = afs_srvAddrs[j]; sa; sa = sa->next_bkt, i++) {
4098 if (spin.offset > (unsigned short)i) {
4099 continue; /* catch up to where we left off */
4101 spout->next_offset++;
4104 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
4105 || (sa->sa_portal == AFS_FSPORT);
4107 if ((vlonly && isfs) || (!vlonly && !isfs)) {
4108 /* only report ranks for vl servers */
4112 /* Check we've actually got the space we're about to use */
4113 if (afs_pd_inline(aout, sizeof(struct spref)) == NULL) {
4114 ReleaseReadLock(&afs_xserver); /* no more room! */
4118 srvout->host.s_addr = sa->sa_ip;
4119 srvout->rank = sa->sa_iprank;
4120 spout->num_servers++;
4124 ReleaseReadLock(&afs_xserver);
4126 spout->next_offset = 0; /* start over from the beginning next time */
4131 /* Enable/Disable the specified exporter. Must be root to disable an exporter */
4132 int afs_NFSRootOnly = 1;
4134 * VIOC_EXPORTAFS (39) - Export afs to nfs clients
4139 * an integer containing the desired exportee flags
4141 * an integer containing the current exporter flags
4143 * \retval ENODEV Error if the exporter doesn't exist
4144 * \retval EACCES Error if the user doesn't have super-user credentials
4147 * Changes the state of various values to reflect the change
4148 * of the export values between nfs and afs.
4150 * \notes Legacy code obtained from IBM.
4152 DECL_PIOCTL(PExportAfs)
4154 afs_int32 export, newint = 0;
4155 afs_int32 type, changestate, handleValue, convmode, pwsync, smounts;
4156 afs_int32 rempags = 0, pagcb = 0;
4157 struct afs_exporter *exporter;
4159 AFS_STATCNT(PExportAfs);
4160 if (afs_pd_getInt(ain, &handleValue) != 0)
4162 type = handleValue >> 24;
4167 exporter = exporter_find(type);
4169 export = handleValue & 3;
4170 changestate = handleValue & 0xfff;
4171 smounts = (handleValue >> 2) & 3;
4172 pwsync = (handleValue >> 4) & 3;
4173 convmode = (handleValue >> 6) & 3;
4174 rempags = (handleValue >> 8) & 3;
4175 pagcb = (handleValue >> 10) & 3;
4177 changestate = (handleValue >> 16) & 0x1;
4178 convmode = (handleValue >> 16) & 0x2;
4179 pwsync = (handleValue >> 16) & 0x4;
4180 smounts = (handleValue >> 16) & 0x8;
4181 export = handleValue & 0xff;
4184 /* Failed finding desired exporter; */
4188 handleValue = exporter->exp_states;
4189 if (afs_pd_putInt(aout, handleValue) != 0)
4192 if (!afs_osi_suser(*acred))
4193 return EACCES; /* Only superuser can do this */
4197 exporter->exp_states |= EXP_EXPORTED;
4199 exporter->exp_states &= ~EXP_EXPORTED;
4203 exporter->exp_states |= EXP_UNIXMODE;
4205 exporter->exp_states &= ~EXP_UNIXMODE;
4209 exporter->exp_states |= EXP_PWSYNC;
4211 exporter->exp_states &= ~EXP_PWSYNC;
4215 afs_NFSRootOnly = 0;
4216 exporter->exp_states |= EXP_SUBMOUNTS;
4218 afs_NFSRootOnly = 1;
4219 exporter->exp_states &= ~EXP_SUBMOUNTS;
4224 exporter->exp_states |= EXP_CLIPAGS;
4226 exporter->exp_states &= ~EXP_CLIPAGS;
4230 exporter->exp_states |= EXP_CALLBACK;
4232 exporter->exp_states &= ~EXP_CALLBACK;
4234 handleValue = exporter->exp_states;
4235 if (afs_pd_putInt(aout, handleValue) != 0)
4239 exporter->exp_states |= EXP_EXPORTED;
4241 exporter->exp_states &= ~EXP_EXPORTED;
4243 exporter->exp_states |= EXP_UNIXMODE;
4245 exporter->exp_states &= ~EXP_UNIXMODE;
4247 exporter->exp_states |= EXP_PWSYNC;
4249 exporter->exp_states &= ~EXP_PWSYNC;
4251 afs_NFSRootOnly = 0;
4252 exporter->exp_states |= EXP_SUBMOUNTS;
4254 afs_NFSRootOnly = 1;
4255 exporter->exp_states &= ~EXP_SUBMOUNTS;
4264 * VIOC_GAG (44) - Silence Cache Manager
4268 * \param[in] ain the flags to either gag or de-gag the cache manager
4269 * \param[out] aout not in use
4271 * \retval EACCES Error if the user doesn't have super-user credentials
4273 * \post set the gag flags, then show these flags
4277 struct gaginfo *gagflags;
4279 if (!afs_osi_suser(*acred))
4282 gagflags = afs_pd_inline(ain, sizeof(*gagflags));
4283 if (gagflags == NULL)
4285 afs_showflags = gagflags->showflags;
4291 * VIOC_TWIDDLE (45) - Adjust RX knobs
4295 * \param[in] ain the previous settings of the 'knobs'
4296 * \param[out] aout not in use
4298 * \retval EACCES Error if the user doesn't have super-user credentials
4300 * \post build out the struct rxp, from a struct rx
4302 DECL_PIOCTL(PTwiddleRx)
4304 struct rxparams *rxp;
4306 if (!afs_osi_suser(*acred))
4309 rxp = afs_pd_inline(ain, sizeof(*rxp));
4313 if (rxp->rx_initReceiveWindow)
4314 rx_initReceiveWindow = rxp->rx_initReceiveWindow;
4315 if (rxp->rx_maxReceiveWindow)
4316 rx_maxReceiveWindow = rxp->rx_maxReceiveWindow;
4317 if (rxp->rx_initSendWindow)
4318 rx_initSendWindow = rxp->rx_initSendWindow;
4319 if (rxp->rx_maxSendWindow)
4320 rx_maxSendWindow = rxp->rx_maxSendWindow;
4321 if (rxp->rxi_nSendFrags)
4322 rxi_nSendFrags = rxp->rxi_nSendFrags;
4323 if (rxp->rxi_nRecvFrags)
4324 rxi_nRecvFrags = rxp->rxi_nRecvFrags;
4325 if (rxp->rxi_OrphanFragSize)
4326 rxi_OrphanFragSize = rxp->rxi_OrphanFragSize;
4327 if (rxp->rx_maxReceiveSize) {
4328 rx_maxReceiveSize = rxp->rx_maxReceiveSize;
4329 rx_maxReceiveSizeUser = rxp->rx_maxReceiveSize;
4331 if (rxp->rx_MyMaxSendSize)
4332 rx_MyMaxSendSize = rxp->rx_MyMaxSendSize;
4338 * VIOC_GETINITPARAMS (49) - Get initial cache manager parameters
4342 * \param[in] ain not in use
4343 * \param[out] aout initial cache manager params
4346 * Error if the initial parameters are bigger than some PIGGYSIZE
4348 * \post return the initial cache manager parameters
4350 DECL_PIOCTL(PGetInitParams)
4352 if (sizeof(struct cm_initparams) > PIGGYSIZE)
4355 return afs_pd_putBytes(aout, &cm_initParams,
4356 sizeof(struct cm_initparams));
4360 #ifdef AFS_SGI65_ENV
4361 /* They took crget() from us, so fake it. */
4366 cr = crdup(get_current_cred());
4367 memset(cr, 0, sizeof(cred_t));
4368 #if CELL || CELL_PREPARE
4376 * VIOC_GETRXKCRYPT (55) - Get rxkad encryption flag
4380 * \param[in] ain not in use
4381 * \param[out] aout value of cryptall
4383 * \post Turns on, or disables, rxkad encryption by setting the cryptall global
4385 DECL_PIOCTL(PGetRxkcrypt)
4387 return afs_pd_putInt(aout, cryptall);
4391 * VIOC_SETRXKCRYPT (56) - Set rxkad encryption flag
4395 * \param[in] ain the argument whether or not things should be encrypted
4396 * \param[out] aout not in use
4399 * Error if the user doesn't have super-user credentials
4401 * Error if the input is too big, or if the input is outside the
4402 * bounds of what it can be set to
4404 * \post set whether or not things should be encrypted
4407 * may need to be modified at a later date to take into account
4408 * other values for cryptall (beyond true or false)
4410 DECL_PIOCTL(PSetRxkcrypt)
4414 if (!afs_osi_suser(*acred))
4416 if (afs_pd_getInt(ain, &tmpval) != 0)
4418 /* if new mappings added later this will need to be changed */
4419 if (tmpval != 0 && tmpval != 1)
4425 #ifdef AFS_NEED_CLIENTCONTEXT
4427 * Create new credentials to correspond to a remote user with given
4428 * <hostaddr, uid, g0, g1>. This allows a server running as root to
4429 * provide pioctl (and other) services to foreign clients (i.e. nfs
4430 * clients) by using this call to `become' the client.
4433 #define PIOCTL_HEADER 6
4435 HandleClientContext(struct afs_ioctl *ablob, int *com,
4436 afs_ucred_t **acred, afs_ucred_t *credp)
4439 afs_uint32 hostaddr;
4440 afs_int32 uid, g0, g1, i, code, pag, exporter_type, isroot = 0;
4441 struct afs_exporter *exporter, *outexporter;
4442 afs_ucred_t *newcred;
4443 struct unixuser *au;
4444 afs_uint32 comp = *com & 0xff00;
4446 #if defined(AFS_SUN510_ENV)
4450 #if defined(AFS_SGIMP_ENV)
4451 osi_Assert(ISAFS_GLOCK());
4453 AFS_STATCNT(HandleClientContext);
4454 if (ablob->in_size < PIOCTL_HEADER * sizeof(afs_int32)) {
4455 /* Must at least include the PIOCTL_HEADER header words
4456 * required by the protocol */
4457 return EINVAL; /* Too small to be good */
4459 ain = inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
4460 AFS_COPYIN(ablob->in, ain, PIOCTL_HEADER * sizeof(afs_int32), code);
4462 osi_FreeLargeSpace(inData);
4466 /* Extract information for remote user */
4467 hostaddr = *((afs_uint32 *) ain);
4468 ain += sizeof(hostaddr);
4469 uid = *((afs_uint32 *) ain);
4471 g0 = *((afs_uint32 *) ain);
4473 g1 = *((afs_uint32 *) ain);
4475 *com = *((afs_uint32 *) ain);
4476 ain += sizeof(afs_int32);
4477 exporter_type = *((afs_uint32 *) ain);/* In case we support more than NFS */
4480 * Of course, one must be root for most of these functions, but
4481 * we'll allow (for knfs) you to set things if the pag is 0 and
4482 * you're setting tokens or unlogging.
4485 if (!afs_osi_suser(credp)) {
4486 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
4487 /* Since SGI's suser() returns explicit failure after the call.. */
4490 /* check for acceptable opcodes for normal folks, which are, so far,
4491 * get/set tokens, sysname, and unlog.
4493 if (i != 9 && i != 3 && i != 38 && i != 8) {
4494 osi_FreeLargeSpace(inData);
4499 ablob->in_size -= PIOCTL_HEADER * sizeof(afs_int32);
4500 ablob->in += PIOCTL_HEADER * sizeof(afs_int32);
4501 osi_FreeLargeSpace(inData);
4504 * We map uid 0 to nobody to match the mapping that the nfs
4505 * server does and to ensure that the suser() calls in the afs
4506 * code fails for remote client roots.
4508 uid = afs_nobody; /* NFS_NOBODY == -2 */
4512 #ifdef AFS_AIX41_ENV
4515 afs_set_cr_gid(newcred, isroot ? RMTUSER_REQ_PRIV : RMTUSER_REQ);
4516 #ifdef AFS_AIX51_ENV
4517 newcred->cr_groupset.gs_union.un_groups[0] = g0;
4518 newcred->cr_groupset.gs_union.un_groups[1] = g1;
4519 #elif defined(AFS_LINUX26_ENV)
4520 # ifdef AFS_LINUX26_ONEGROUP_ENV
4521 afs_set_cr_group_info(newcred, groups_alloc(1)); /* nothing sets this */
4522 l = (((g0-0x3f00) & 0x3fff) << 14) | ((g1-0x3f00) & 0x3fff);
4523 h = ((g0-0x3f00) >> 14);
4524 h = ((g1-0x3f00) >> 14) + h + h + h;
4525 GROUP_AT(afs_cr_group_info(newcred), 0) = ((h << 28) | l);
4527 afs_set_cr_group_info(newcred, groups_alloc(2));
4528 GROUP_AT(afs_cr_group_info(newcred), 0) = g0;
4529 GROUP_AT(afs_cr_group_info(newcred), 1) = g1;
4531 #elif defined(AFS_SUN510_ENV)
4534 crsetgroups(newcred, 2, gids);
4536 newcred->cr_groups[0] = g0;
4537 newcred->cr_groups[1] = g1;
4540 newcred->cr_ngrps = 2;
4541 #elif !defined(AFS_LINUX26_ENV) && !defined(AFS_SUN510_ENV)
4542 # if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_FBSD80_ENV)
4543 newcred->cr_ngroups = 2;
4545 for (i = 2; i < NGROUPS; i++)
4546 newcred->cr_groups[i] = NOGROUP;
4549 if (!(exporter = exporter_find(exporter_type))) {
4550 /* Exporter wasn't initialized or an invalid exporter type */
4554 if (exporter->exp_states & EXP_PWSYNC) {
4555 if (uid != afs_cr_uid(credp)) {
4557 return ENOEXEC; /* XXX Find a better errno XXX */
4560 afs_set_cr_uid(newcred, uid); /* Only temporary */
4561 code = EXP_REQHANDLER(exporter, &newcred, hostaddr, &pag, &outexporter);
4562 /* The client's pag is the only unique identifier for it */
4563 afs_set_cr_uid(newcred, pag);
4565 if (!code && *com == PSETPAG) {
4566 /* Special case for 'setpag' */
4567 afs_uint32 pagvalue = genpag();
4569 au = afs_GetUser(pagvalue, -1, WRITE_LOCK); /* a new unixuser struct */
4571 * Note that we leave the 'outexporter' struct held so it won't
4574 au->exporter = outexporter;
4575 if (ablob->out_size >= 4) {
4576 AFS_COPYOUT((char *)&pagvalue, ablob->out, sizeof(afs_int32),
4579 afs_PutUser(au, WRITE_LOCK);
4582 return PSETPAG; /* Special return for setpag */
4584 EXP_RELE(outexporter);
4587 *com = (*com) | comp;
4590 #endif /* AFS_NEED_CLIENTCONTEXT */
4594 * VIOC_GETCPREFS (50) - Get client interface
4598 * \param[in] ain sprefrequest input
4599 * \param[out] aout spref information
4601 * \retval EIO Error if the afs daemon hasn't started yet
4602 * \retval EINVAL Error if some of the standard args aren't set
4605 * get all interface addresses and other information of the client
4608 DECL_PIOCTL(PGetCPrefs)
4610 struct sprefrequest *spin; /* input */
4611 struct sprefinfo *spout; /* output */
4612 struct spref *srvout; /* one output component */
4616 AFS_STATCNT(PGetCPrefs);
4617 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4618 return EIO; /* Inappropriate ioctl for device */
4620 spin = afs_pd_inline(ain, sizeof(*spin));
4624 /* Output spout relies on writing past the end of arrays. It's horrible,
4625 * but I'm not quite brave enough to tackle it yet */
4626 spout = (struct sprefinfo *)aout->ptr;
4628 maxNumber = spin->num_servers; /* max addrs this time */
4629 srvout = spout->servers;
4631 ObtainReadLock(&afs_xinterface);
4633 /* copy out the client interface information from the
4634 * kernel data structure "interface" to the output buffer
4636 for (i = spin->offset, j = 0; (i < afs_cb_interface.numberOfInterfaces)
4637 && (j < maxNumber); i++, j++, srvout++)
4638 srvout->host.s_addr = afs_cb_interface.addr_in[i];
4640 spout->num_servers = j;
4641 aout->ptr += sizeof(struct sprefinfo) + (j - 1) * sizeof(struct spref);
4643 if (i >= afs_cb_interface.numberOfInterfaces)
4644 spout->next_offset = 0; /* start from beginning again */
4646 spout->next_offset = spin->offset + j;
4648 ReleaseReadLock(&afs_xinterface);
4653 * VIOC_SETCPREFS (51) - Set client interface
4657 * \param[in] ain the interfaces you want set
4658 * \param[out] aout not in use
4660 * \retval EIO Error if the afs daemon hasn't started yet
4661 * \retval EINVAL Error if the input is too large for the struct
4662 * \retval ENOMEM Error if there are too many servers
4664 * \post set the callbak interfaces addresses to those of the hosts
4666 DECL_PIOCTL(PSetCPrefs)
4670 struct setspref *sin;
4673 AFS_STATCNT(PSetCPrefs);
4674 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4675 return EIO; /* Inappropriate ioctl for device */
4677 /* Yuck. Input to this function relies on reading past the end of
4678 * structures. Bodge it for now.
4681 ainSize = ain->remaining;
4683 sin = (struct setspref *)ainPtr;
4685 if (ainSize < sizeof(struct setspref))
4687 #if 0 /* num_servers is unsigned */
4688 if (sin->num_servers < 0)
4691 if (sin->num_servers > AFS_MAX_INTERFACE_ADDR)
4694 ObtainWriteLock(&afs_xinterface, 412);
4695 afs_cb_interface.numberOfInterfaces = sin->num_servers;
4696 for (i = 0; (unsigned short)i < sin->num_servers; i++)
4697 afs_cb_interface.addr_in[i] = sin->servers[i].host.s_addr;
4699 ReleaseWriteLock(&afs_xinterface);
4704 * VIOC_AFS_FLUSHMOUNT (52) - Flush mount symlink data
4709 * the last part of a path to a mount point, which tells us what to flush
4714 * Error if some of the initial arguments aren't set
4716 * Error if the initial argument for the mount point isn't a directory
4718 * Error if the dcache entry isn't set
4721 * remove all of the mount data from the dcache regarding a
4722 * certain mount point
4724 DECL_PIOCTL(PFlushMount)
4729 struct VenusFid tfid;
4732 struct sysname_info sysState;
4733 afs_size_t offset, len;
4735 AFS_STATCNT(PFlushMount);
4739 if (afs_pd_getStringPtr(ain, &mount) != 0)
4742 code = afs_VerifyVCache(avc, areq);
4745 if (vType(avc) != VDIR) {
4748 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
4751 Check_AtSys(avc, mount, &sysState, areq);
4752 ObtainReadLock(&tdc->lock);
4754 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
4755 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
4756 ReleaseReadLock(&tdc->lock);
4757 afs_PutDCache(tdc); /* we're done with the data */
4758 bufp = sysState.name;
4762 tfid.Cell = avc->f.fid.Cell;
4763 tfid.Fid.Volume = avc->f.fid.Fid.Volume;
4764 if (!tfid.Fid.Unique && (avc->f.states & CForeign)) {
4765 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
4767 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
4773 if (tvc->mvstat != 1) {
4778 #ifdef AFS_BOZONLOCK_ENV
4779 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
4781 ObtainWriteLock(&tvc->lock, 649);
4782 ObtainWriteLock(&afs_xcbhash, 650);
4783 afs_DequeueCallback(tvc);
4784 tvc->f.states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
4785 ReleaseWriteLock(&afs_xcbhash);
4786 /* now find the disk cache entries */
4787 afs_TryToSmush(tvc, *acred, 1);
4788 osi_dnlc_purgedp(tvc);
4789 if (tvc->linkData && !(tvc->f.states & CCore)) {
4790 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
4791 tvc->linkData = NULL;
4793 ReleaseWriteLock(&tvc->lock);
4794 #ifdef AFS_BOZONLOCK_ENV
4795 afs_BozonUnlock(&tvc->pvnLock, tvc);
4799 if (sysState.allocked)
4800 osi_FreeLargeSpace(bufp);
4805 * VIOC_RXSTAT_PROC (53) - Control process RX statistics
4809 * \param[in] ain the flags that control which stats to use
4810 * \param[out] aout not in use
4812 * \retval EACCES Error if the user doesn't have super-user credentials
4813 * \retval EINVAL Error if the flag input is too long
4816 * either enable process RPCStats, disable process RPCStats,
4817 * or clear the process RPCStats
4819 DECL_PIOCTL(PRxStatProc)
4823 if (!afs_osi_suser(*acred))
4826 if (afs_pd_getInt(ain, &flags) != 0)
4829 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK))
4832 if (flags & AFSCALL_RXSTATS_ENABLE) {
4833 rx_enableProcessRPCStats();
4835 if (flags & AFSCALL_RXSTATS_DISABLE) {
4836 rx_disableProcessRPCStats();
4838 if (flags & AFSCALL_RXSTATS_CLEAR) {
4839 rx_clearProcessRPCStats(AFS_RX_STATS_CLEAR_ALL);
4846 * VIOC_RXSTAT_PEER (54) - Control peer RX statistics
4850 * \param[in] ain the flags that control which statistics to use
4851 * \param[out] aout not in use
4853 * \retval EACCES Error if the user doesn't have super-user credentials
4854 * \retval EINVAL Error if the flag input is too long
4857 * either enable peer RPCStatws, disable peer RPCStats,
4858 * or clear the peer RPCStats
4860 DECL_PIOCTL(PRxStatPeer)
4864 if (!afs_osi_suser(*acred))
4867 if (afs_pd_getInt(ain, &flags) != 0)
4870 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK))
4873 if (flags & AFSCALL_RXSTATS_ENABLE) {
4874 rx_enablePeerRPCStats();
4876 if (flags & AFSCALL_RXSTATS_DISABLE) {
4877 rx_disablePeerRPCStats();
4879 if (flags & AFSCALL_RXSTATS_CLEAR) {
4880 rx_clearPeerRPCStats(AFS_RX_STATS_CLEAR_ALL);
4885 DECL_PIOCTL(PPrefetchFromTape)
4887 afs_int32 code, code1;
4888 afs_int32 bytes, outval;
4889 struct afs_conn *tc;
4890 struct rx_call *tcall;
4891 struct AFSVolSync tsync;
4892 struct AFSFetchStatus OutStatus;
4893 struct AFSCallBack CallBack;
4894 struct VenusFid tfid;
4898 AFS_STATCNT(PSetAcl);
4902 Fid = afs_pd_inline(ain, sizeof(struct AFSFid));
4904 Fid = &avc->f.fid.Fid;
4906 tfid.Cell = avc->f.fid.Cell;
4907 tfid.Fid.Volume = Fid->Volume;
4908 tfid.Fid.Vnode = Fid->Vnode;
4909 tfid.Fid.Unique = Fid->Unique;
4911 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
4913 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
4914 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &avc->f.fid);
4917 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
4918 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &tvc->f.fid);
4921 tc = afs_Conn(&tvc->f.fid, areq, SHARED_LOCK);
4925 tcall = rx_NewCall(tc->id);
4927 StartRXAFS_FetchData(tcall, (struct AFSFid *)&tvc->f.fid.Fid, 0,
4930 bytes = rx_Read(tcall, (char *)&outval, sizeof(afs_int32));
4932 EndRXAFS_FetchData(tcall, &OutStatus, &CallBack, &tsync);
4934 code1 = rx_EndCall(tcall, code);
4938 } while (afs_Analyze
4939 (tc, code, &tvc->f.fid, areq, AFS_STATS_FS_RPCIDX_RESIDENCYRPCS,
4940 SHARED_LOCK, NULL));
4941 /* This call is done only to have the callback things handled correctly */
4942 afs_FetchStatus(tvc, &tfid, areq, &OutStatus);
4948 return afs_pd_putInt(aout, outval);
4954 struct afs_conn *tc;
4956 struct FsCmdInputs *Inputs;
4957 struct FsCmdOutputs *Outputs;
4958 struct VenusFid tfid;
4964 Inputs = afs_pd_inline(ain, sizeof(*Inputs));
4968 Outputs = afs_pd_inline(aout, sizeof(*Outputs));
4969 if (Outputs == NULL)
4974 Fid = &avc->f.fid.Fid;
4976 tfid.Cell = avc->f.fid.Cell;
4977 tfid.Fid.Volume = Fid->Volume;
4978 tfid.Fid.Vnode = Fid->Vnode;
4979 tfid.Fid.Unique = Fid->Unique;
4981 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
4982 afs_Trace3(afs_iclSetp, CM_TRACE_RESIDCMD, ICL_TYPE_POINTER, tvc,
4983 ICL_TYPE_INT32, Inputs->command, ICL_TYPE_FID, &tfid);
4987 if (Inputs->command) {
4989 tc = afs_Conn(&tvc->f.fid, areq, SHARED_LOCK);
4993 RXAFS_FsCmd(tc->id, Fid, Inputs,
4994 (struct FsCmdOutputs *)aout);
4998 } while (afs_Analyze
4999 (tc, code, &tvc->f.fid, areq,
5000 AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK, NULL));
5001 /* This call is done to have the callback things handled correctly */
5002 afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
5003 } else { /* just a status request, return also link data */
5005 Outputs->code = afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
5006 Outputs->chars[0] = 0;
5007 if (vType(tvc) == VLNK) {
5008 ObtainWriteLock(&tvc->lock, 555);
5009 if (afs_HandleLink(tvc, areq) == 0)
5010 strncpy((char *)&Outputs->chars, tvc->linkData, MAXCMDCHARS);
5011 ReleaseWriteLock(&tvc->lock);
5020 DECL_PIOCTL(PNewUuid)
5022 /*AFS_STATCNT(PNewUuid); */
5023 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
5024 return EIO; /* Inappropriate ioctl for device */
5026 if (!afs_osi_suser(*acred))
5029 ObtainWriteLock(&afs_xinterface, 555);
5030 afs_uuid_create(&afs_cb_interface.uuid);
5031 ReleaseWriteLock(&afs_xinterface);
5032 ForceAllNewConnections();
5036 #if defined(AFS_CACHE_BYPASS)
5038 DECL_PIOCTL(PSetCachingThreshold)
5040 afs_int32 getting = 1;
5041 afs_int32 setting = 1;
5042 afs_int32 threshold = AFS_CACHE_BYPASS_DISABLED;
5044 if (afs_pd_getInt(ain, &threshold) != 0)
5050 if (setting == 0 && getting == 0)
5054 * If setting, set first, and return the value now in effect
5057 if (!afs_osi_suser(*acred))
5059 cache_bypass_threshold = threshold;
5060 afs_warn("Cache Bypass Threshold set to: %d\n", threshold);
5061 /* TODO: move to separate pioctl, or enhance pioctl */
5062 cache_bypass_strategy = LARGE_FILES_BYPASS_CACHE;
5065 /* Return the current size threshold */
5067 return afs_pd_putInt(aout, cache_bypass_threshold);
5072 #endif /* defined(AFS_CACHE_BYPASS) */
5074 DECL_PIOCTL(PCallBackAddr)
5077 afs_uint32 addr, code;
5081 struct afs_conn *tc;
5083 struct unixuser *tu;
5084 struct srvAddr **addrs;
5086 /*AFS_STATCNT(PCallBackAddr); */
5087 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
5088 return EIO; /* Inappropriate ioctl for device */
5090 if (!afs_osi_suser(acred))
5093 if (afs_pd_getInt(ain, &addr) != 0)
5096 ObtainReadLock(&afs_xinterface);
5097 for (i = 0; (unsigned short)i < afs_cb_interface.numberOfInterfaces; i++) {
5098 if (afs_cb_interface.addr_in[i] == addr)
5102 ReleaseWriteLock(&afs_xinterface);
5104 if (afs_cb_interface.addr_in[i] != addr)
5107 ObtainReadLock(&afs_xserver); /* Necessary? */
5108 ObtainReadLock(&afs_xsrvAddr);
5111 for (i = 0; i < NSERVERS; i++) {
5112 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
5117 addrs = afs_osi_Alloc(srvAddrCount * sizeof(*addrs));
5119 for (i = 0; i < NSERVERS; i++) {
5120 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
5121 if (j >= srvAddrCount)
5127 ReleaseReadLock(&afs_xsrvAddr);
5128 ReleaseReadLock(&afs_xserver);
5130 for (i = 0; i < j; i++) {
5136 /* vlserver has no callback conn */
5137 if (sa->sa_portal == AFS_VLPORT) {
5141 if (!ts->cell) /* not really an active server, anyway, it must */
5142 continue; /* have just been added by setsprefs */
5144 /* get a connection, even if host is down; bumps conn ref count */
5145 tu = afs_GetUser(areq->uid, ts->cell->cellNum, SHARED_LOCK);
5146 tc = afs_ConnBySA(sa, ts->cell->fsport, ts->cell->cellNum, tu,
5147 1 /*force */ , 1 /*create */ , SHARED_LOCK);
5148 afs_PutUser(tu, SHARED_LOCK);
5152 if ((sa->sa_flags & SRVADDR_ISDOWN) || afs_HaveCallBacksFrom(ts)) {
5153 if (sa->sa_flags & SRVADDR_ISDOWN) {
5154 rx_SetConnDeadTime(tc->id, 3);
5156 #ifdef RX_ENABLE_LOCKS
5158 #endif /* RX_ENABLE_LOCKS */
5159 code = RXAFS_CallBackRxConnAddr(tc->id, &addr);
5160 #ifdef RX_ENABLE_LOCKS
5162 #endif /* RX_ENABLE_LOCKS */
5164 afs_PutConn(tc, SHARED_LOCK); /* done with it now */
5165 } /* Outer loop over addrs */
5166 #endif /* UKERNEL */
5170 DECL_PIOCTL(PDiscon)
5172 static afs_int32 mode = 1; /* Start up in 'off' */
5173 afs_int32 force = 0;
5176 struct vrequest lreq;
5178 if (afs_pd_getBytes(ain, &flags, 4) == 0) {
5179 if (!afs_osi_suser(*acred))
5183 mode = flags[0] - 1;
5185 afs_ConflictPolicy = flags[1] - 1;
5189 /* Fake InitReq support for UID override */
5190 memset(&lreq, 0, sizeof(lreq));
5191 lreq.uid = flags[3];
5192 areq = &lreq; /* override areq we got */
5196 * All of these numbers are hard coded in fs.c. If they
5197 * change here, they should change there and vice versa
5200 case 0: /* Disconnect ("offline" mode), breaking all callbacks */
5201 if (!AFS_IS_DISCONNECTED) {
5202 ObtainWriteLock(&afs_discon_lock, 999);
5203 afs_DisconGiveUpCallbacks();
5204 afs_RemoveAllConns();
5205 afs_is_disconnected = 1;
5206 afs_is_discon_rw = 1;
5207 ReleaseWriteLock(&afs_discon_lock);
5210 case 1: /* Fully connected, ("online" mode). */
5211 ObtainWriteLock(&afs_discon_lock, 998);
5214 afs_MarkAllServersUp();
5215 code = afs_ResyncDisconFiles(areq, *acred);
5218 if (code && !force) {
5219 afs_warnuser("Files not synchronized properly, still in discon state. \n"
5220 "Please retry or use \"force\".\n");
5224 afs_DisconDiscardAll(*acred);
5226 afs_ClearAllStatdFlag();
5227 afs_is_disconnected = 0;
5228 afs_is_discon_rw = 0;
5229 afs_warnuser("\nSync succeeded. You are back online.\n");
5232 ReleaseWriteLock(&afs_discon_lock);
5244 return afs_pd_putInt(aout, mode);
5247 #define MAX_PIOCTL_TOKENS 10
5249 DECL_PIOCTL(PSetTokens2)
5252 int i, cellNum, primaryFlag;
5254 struct unixuser *tu;
5255 struct vrequest treq;
5256 struct ktc_setTokenData tokenSet;
5257 struct ktc_tokenUnion decodedToken;
5259 memset(&tokenSet, 0, sizeof(tokenSet));
5261 AFS_STATCNT(PSetTokens2);
5262 if (!afs_resourceinit_flag)
5265 afs_pd_xdrStart(ain, &xdrs, XDR_DECODE);
5267 if (!xdr_ktc_setTokenData(&xdrs, &tokenSet)) {
5268 afs_pd_xdrEnd(ain, &xdrs);
5272 afs_pd_xdrEnd(ain, &xdrs);
5274 /* We limit each PAG to 10 tokens to prevent a malicous (or runaway)
5275 * process from using up the whole of the kernel memory by allocating
5278 if (tokenSet.tokens.tokens_len > MAX_PIOCTL_TOKENS) {
5279 xdr_free((xdrproc_t) xdr_ktc_setTokenData, &tokenSet);
5283 code = _settok_tokenCell(tokenSet.cell, &cellNum, &primaryFlag);
5285 xdr_free((xdrproc_t) xdr_ktc_setTokenData, &tokenSet);
5289 if (tokenSet.flags & AFSTOKEN_EX_SETPAG) {
5290 if (_settok_setParentPag(acred) == 0) {
5291 afs_InitReq(&treq, *acred);
5296 tu = afs_GetUser(areq->uid, cellNum, WRITE_LOCK);
5297 /* Free any tokens that we've already got */
5298 afs_FreeTokens(&tu->tokens);
5300 /* Iterate across the set of tokens we've received, and stuff them
5301 * into this user's tokenJar
5303 for (i=0; i < tokenSet.tokens.tokens_len; i++) {
5304 xdrmem_create(&xdrs,
5305 tokenSet.tokens.tokens_val[i].token_opaque_val,
5306 tokenSet.tokens.tokens_val[i].token_opaque_len,
5309 memset(&decodedToken, 0, sizeof(decodedToken));
5310 if (!xdr_ktc_tokenUnion(&xdrs, &decodedToken)) {
5318 afs_AddTokenFromPioctl(&tu->tokens, &decodedToken);
5319 /* This is untidy - the old token interface supported passing
5320 * the primaryFlag as part of the token interface. Current
5321 * OpenAFS userland never sets this, but it's specified as being
5322 * part of the XG interface, so we should probably still support
5323 * it. Rather than add it to our AddToken interface, just handle
5326 if (decodedToken.at_type == AFSTOKEN_UNION_KAD) {
5327 if (decodedToken.ktc_tokenUnion_u.at_kad.rk_primary_flag)
5331 /* XXX - We should think more about destruction here. It's likely that
5332 * there is key material in what we're about to throw away, which
5333 * we really should zero out before giving back to the allocator */
5334 xdr_free((xdrproc_t) xdr_ktc_tokenUnion, &decodedToken);
5337 tu->states |= UHasTokens;
5338 tu->states &= ~UTokensBad;
5339 afs_SetPrimary(tu, primaryFlag);
5340 tu->tokenTime = osi_Time();
5342 xdr_free((xdrproc_t) xdr_ktc_setTokenData, &tokenSet);
5345 afs_ResetUserConns(tu);
5346 afs_PutUser(tu, WRITE_LOCK);
5351 DECL_PIOCTL(PNFSNukeCreds)
5355 struct unixuser *tu;
5357 AFS_STATCNT(PUnlog);
5358 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
5359 return EIO; /* Inappropriate ioctl for device */
5361 if (afs_pd_getUint(ain, &addr) != 0)
5364 if (afs_cr_gid(*acred) == RMTUSER_REQ_PRIV && !addr) {
5365 tu = afs_GetUser(areq->uid, -1, SHARED_LOCK);
5366 if (!tu->exporter || !(addr = EXP_GETHOST(tu->exporter))) {
5367 afs_PutUser(tu, SHARED_LOCK);
5370 afs_PutUser(tu, SHARED_LOCK);
5371 } else if (!afs_osi_suser(acred)) {
5375 ObtainWriteLock(&afs_xuser, 227);
5376 for (i = 0; i < NUSERS; i++) {
5377 for (tu = afs_users[i]; tu; tu = tu->next) {
5378 if (tu->exporter && EXP_CHECKHOST(tu->exporter, addr)) {
5379 tu->states &= ~UHasTokens;
5380 afs_FreeTokens(&tu->tokens);
5382 ReleaseWriteLock(&afs_xuser);
5383 afs_ResetUserConns(tu);
5385 ObtainWriteLock(&afs_xuser, 228);
5387 /* set the expire times to 0, causes
5388 * afs_GCUserData to remove this entry
5391 #endif /* UKERNEL */
5395 ReleaseWriteLock(&afs_xuser);