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);
272 DECL_PIOCTL(PGetTokens2);
274 DECL_PIOCTL(PMariner);
275 DECL_PIOCTL(PCheckServers);
276 DECL_PIOCTL(PCheckVolNames);
277 DECL_PIOCTL(PCheckAuth);
278 DECL_PIOCTL(PFindVolume);
279 DECL_PIOCTL(PViceAccess);
280 DECL_PIOCTL(PSetCacheSize);
281 DECL_PIOCTL(PGetCacheSize);
282 DECL_PIOCTL(PRemoveCallBack);
283 DECL_PIOCTL(PNewCell);
284 DECL_PIOCTL(PNewAlias);
285 DECL_PIOCTL(PListCells);
286 DECL_PIOCTL(PListAliases);
287 DECL_PIOCTL(PRemoveMount);
288 DECL_PIOCTL(PGetCellStatus);
289 DECL_PIOCTL(PSetCellStatus);
290 DECL_PIOCTL(PFlushVolumeData);
291 DECL_PIOCTL(PGetVnodeXStatus);
292 DECL_PIOCTL(PGetVnodeXStatus2);
293 DECL_PIOCTL(PSetSysName);
294 DECL_PIOCTL(PSetSPrefs);
295 DECL_PIOCTL(PSetSPrefs33);
296 DECL_PIOCTL(PGetSPrefs);
297 DECL_PIOCTL(PExportAfs);
299 DECL_PIOCTL(PTwiddleRx);
300 DECL_PIOCTL(PGetInitParams);
301 DECL_PIOCTL(PGetRxkcrypt);
302 DECL_PIOCTL(PSetRxkcrypt);
303 DECL_PIOCTL(PGetCPrefs);
304 DECL_PIOCTL(PSetCPrefs);
305 DECL_PIOCTL(PFlushMount);
306 DECL_PIOCTL(PRxStatProc);
307 DECL_PIOCTL(PRxStatPeer);
308 DECL_PIOCTL(PPrefetchFromTape);
310 DECL_PIOCTL(PCallBackAddr);
311 DECL_PIOCTL(PDiscon);
312 DECL_PIOCTL(PNFSNukeCreds);
313 DECL_PIOCTL(PNewUuid);
314 DECL_PIOCTL(PPrecache);
315 DECL_PIOCTL(PGetPAG);
316 #if defined(AFS_CACHE_BYPASS)
317 DECL_PIOCTL(PSetCachingThreshold);
321 * A macro that says whether we're going to need HandleClientContext().
322 * This is currently used only by the nfs translator.
324 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
325 #define AFS_NEED_CLIENTCONTEXT
328 /* Prototypes for private routines */
329 #ifdef AFS_NEED_CLIENTCONTEXT
330 static int HandleClientContext(struct afs_ioctl *ablob, int *com,
334 int HandleIoctl(struct vcache *avc, afs_int32 acom,
335 struct afs_ioctl *adata);
336 int afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
337 struct afs_ioctl *ablob, int afollow,
338 afs_ucred_t **acred);
339 static int Prefetch(uparmtype apath, struct afs_ioctl *adata, int afollow,
342 typedef int (*pioctlFunction) (struct vcache *, int, struct vrequest *,
343 struct afs_pdata *, struct afs_pdata *,
346 static pioctlFunction VpioctlSw[] = {
351 PGetVolumeStatus, /* 4 */
352 PSetVolumeStatus, /* 5 */
357 PCheckServers, /* 10 */
358 PCheckVolNames, /* 11 */
360 PBogus, /* 13 -- used to be quick check time */
361 PFindVolume, /* 14 */
362 PBogus, /* 15 -- prefetch is now special-cased; see pioctl code! */
363 PBogus, /* 16 -- used to be testing code */
364 PNoop, /* 17 -- used to be enable group */
365 PNoop, /* 18 -- used to be disable group */
366 PBogus, /* 19 -- used to be list group */
367 PViceAccess, /* 20 */
368 PUnlog, /* 21 -- unlog *is* unpag in this system */
369 PGetFID, /* 22 -- get file ID */
370 PBogus, /* 23 -- used to be waitforever */
371 PSetCacheSize, /* 24 */
372 PRemoveCallBack, /* 25 -- flush only the callback */
375 PRemoveMount, /* 28 -- delete mount point */
376 PNewStatMount, /* 29 -- new style mount point stat */
377 PGetFileCell, /* 30 -- get cell name for input file */
378 PGetWSCell, /* 31 -- get cell name for workstation */
379 PMariner, /* 32 - set/get mariner host */
380 PGetUserCell, /* 33 -- get cell name for user */
381 PBogus, /* 34 -- Enable/Disable logging */
382 PGetCellStatus, /* 35 */
383 PSetCellStatus, /* 36 */
384 PFlushVolumeData, /* 37 -- flush all data from a volume */
385 PSetSysName, /* 38 - Set system name */
386 PExportAfs, /* 39 - Export Afs to remote nfs clients */
387 PGetCacheSize, /* 40 - get cache size and usage */
388 PGetVnodeXStatus, /* 41 - get vcache's special status */
389 PSetSPrefs33, /* 42 - Set CM Server preferences... */
390 PGetSPrefs, /* 43 - Get CM Server preferences... */
391 PGag, /* 44 - turn off/on all CM messages */
392 PTwiddleRx, /* 45 - adjust some RX params */
393 PSetSPrefs, /* 46 - Set CM Server preferences... */
394 PStoreBehind, /* 47 - set degree of store behind to be done */
395 PGCPAGs, /* 48 - disable automatic pag gc-ing */
396 PGetInitParams, /* 49 - get initial cm params */
397 PGetCPrefs, /* 50 - get client interface addresses */
398 PSetCPrefs, /* 51 - set client interface addresses */
399 PFlushMount, /* 52 - flush mount symlink data */
400 PRxStatProc, /* 53 - control process RX statistics */
401 PRxStatPeer, /* 54 - control peer RX statistics */
402 PGetRxkcrypt, /* 55 -- Get rxkad encryption flag */
403 PSetRxkcrypt, /* 56 -- Set rxkad encryption flag */
404 PBogus, /* 57 -- arla: set file prio */
405 PBogus, /* 58 -- arla: fallback getfh */
406 PBogus, /* 59 -- arla: fallback fhopen */
407 PBogus, /* 60 -- arla: controls xfsdebug */
408 PBogus, /* 61 -- arla: controls arla debug */
409 PBogus, /* 62 -- arla: debug interface */
410 PBogus, /* 63 -- arla: print xfs status */
411 PBogus, /* 64 -- arla: force cache check */
412 PBogus, /* 65 -- arla: break callback */
413 PPrefetchFromTape, /* 66 -- MR-AFS: prefetch file from tape */
414 PFsCmd, /* 67 -- RXOSD: generic commnd interface */
415 PBogus, /* 68 -- arla: fetch stats */
416 PGetVnodeXStatus2, /* 69 - get caller access and some vcache status */
419 static pioctlFunction CpioctlSw[] = {
421 PNewAlias, /* 1 -- create new cell alias */
422 PListAliases, /* 2 -- list cell aliases */
423 PCallBackAddr, /* 3 -- request addr for callback rxcon */
425 PDiscon, /* 5 -- get/set discon mode */
436 static pioctlFunction OpioctlSw[] = {
438 PNFSNukeCreds, /* 1 -- nuke all creds for NFS client */
439 #if defined(AFS_CACHE_BYPASS)
440 PSetCachingThreshold /* 2 -- get/set cache-bypass size threshold */
442 PNoop /* 2 -- get/set cache-bypass size threshold */
446 #define PSetClientContext 99 /* Special pioctl to setup caller's creds */
447 int afs_nobody = NFS_NOBODY;
450 HandleIoctl(struct vcache *avc, afs_int32 acom,
451 struct afs_ioctl *adata)
456 AFS_STATCNT(HandleIoctl);
458 switch (acom & 0xff) {
460 avc->f.states |= CSafeStore;
462 /* SXW - Should we force a MetaData flush for this flag setting */
465 /* case 2 used to be abort store, but this is no longer provided,
466 * since it is impossible to implement under normal Unix.
470 /* return the name of the cell this file is open on */
474 tcell = afs_GetCell(avc->f.fid.Cell, READ_LOCK);
476 i = strlen(tcell->cellName) + 1; /* bytes to copy out */
478 if (i > adata->out_size) {
479 /* 0 means we're not interested in the output */
480 if (adata->out_size != 0)
484 AFS_COPYOUT(tcell->cellName, adata->out, i, code);
486 afs_PutCell(tcell, READ_LOCK);
492 case 49: /* VIOC_GETINITPARAMS */
493 if (adata->out_size < sizeof(struct cm_initparams)) {
496 AFS_COPYOUT(&cm_initParams, adata->out,
497 sizeof(struct cm_initparams), code);
509 return code; /* so far, none implemented */
513 /* For aix we don't temporarily bypass ioctl(2) but rather do our
514 * thing directly in the vnode layer call, VNOP_IOCTL; thus afs_ioctl
515 * is now called from afs_gn_ioctl.
518 afs_ioctl(struct vcache *tvc, int cmd, int arg)
520 struct afs_ioctl data;
523 AFS_STATCNT(afs_ioctl);
524 if (((cmd >> 8) & 0xff) == 'V') {
525 /* This is a VICEIOCTL call */
526 AFS_COPYIN(arg, (caddr_t) & data, sizeof(data), error);
529 error = HandleIoctl(tvc, cmd, &data);
532 /* No-op call; just return. */
536 # if defined(AFS_AIX32_ENV)
537 # if defined(AFS_AIX51_ENV)
540 kioctl(int fdes, int com, caddr_t arg, caddr_t ext, caddr_t arg2,
542 # else /* __64BIT__ */
544 kioctl32(int fdes, int com, caddr_t arg, caddr_t ext, caddr_t arg2,
546 # endif /* __64BIT__ */
549 kioctl(int fdes, int com, caddr_t arg, caddr_t ext)
550 # endif /* AFS_AIX51_ENV */
555 # ifdef AFS_AIX51_ENV
558 } u_uap, *uap = &u_uap;
561 int ioctlDone = 0, code = 0;
563 AFS_STATCNT(afs_xioctl);
567 # ifdef AFS_AIX51_ENV
571 if (setuerror(getf(uap->fd, &fd))) {
574 if (fd->f_type == DTYPE_VNODE) {
575 /* good, this is a vnode; next see if it is an AFS vnode */
576 tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */
577 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
578 /* This is an AFS vnode */
579 if (((uap->com >> 8) & 0xff) == 'V') {
580 struct afs_ioctl *datap;
583 (struct afs_ioctl *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
584 code=copyin_afs_ioctl((char *)uap->arg, datap);
586 osi_FreeSmallSpace(datap);
588 # if defined(AFS_AIX41_ENV)
591 return (setuerror(code), code);
593 code = HandleIoctl(tvc, uap->com, datap);
594 osi_FreeSmallSpace(datap);
597 # if defined(AFS_AIX41_ENV)
604 # if defined(AFS_AIX41_ENV)
606 # if defined(AFS_AIX51_ENV)
608 code = okioctl(fdes, com, arg, ext, arg2, arg3);
609 # else /* __64BIT__ */
610 code = okioctl32(fdes, com, arg, ext, arg2, arg3);
611 # endif /* __64BIT__ */
612 # else /* !AFS_AIX51_ENV */
613 code = okioctl(fdes, com, arg, ext);
614 # endif /* AFS_AIX51_ENV */
616 # elif defined(AFS_AIX32_ENV)
617 okioctl(fdes, com, arg, ext);
620 # if defined(KERNEL_HAVE_UERROR)
623 # if !defined(AFS_AIX41_ENV)
624 return (getuerror()? -1 : u.u_ioctlrv);
626 return getuerror()? -1 : 0;
633 #elif defined(AFS_SGI_ENV)
634 # if defined(AFS_SGI65_ENV)
635 afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
636 rval_t * rvalp, struct vopbd * vbds)
638 afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
639 rval_t * rvalp, struct vopbd * vbds)
642 struct afs_ioctl data;
648 AFS_STATCNT(afs_ioctl);
649 if (((cmd >> 8) & 0xff) == 'V') {
650 /* This is a VICEIOCTL call */
651 error = copyin_afs_ioctl(arg, &data);
654 locked = ISAFS_GLOCK();
657 error = HandleIoctl(tvc, cmd, &data);
662 /* No-op call; just return. */
666 #elif defined(AFS_SUN5_ENV)
667 struct afs_ioctl_sys {
674 afs_xioctl(struct afs_ioctl_sys *uap, rval_t *rvp)
678 int ioctlDone = 0, code = 0;
680 AFS_STATCNT(afs_xioctl);
681 # if defined(AFS_SUN57_ENV)
685 # elif defined(AFS_SUN54_ENV)
690 if (code = getf(uap->fd, &fd)) {
694 if (fd->f_vnode->v_type == VREG || fd->f_vnode->v_type == VDIR) {
695 tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */
696 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
697 /* This is an AFS vnode */
698 if (((uap->com >> 8) & 0xff) == 'V') {
699 struct afs_ioctl *datap;
702 (struct afs_ioctl *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
703 code=copyin_afs_ioctl((char *)uap->arg, datap);
705 osi_FreeSmallSpace(datap);
707 # if defined(AFS_SUN54_ENV)
714 code = HandleIoctl(tvc, uap->com, datap);
715 osi_FreeSmallSpace(datap);
721 # if defined(AFS_SUN57_ENV)
723 # elif defined(AFS_SUN54_ENV)
729 code = ioctl(uap, rvp);
733 #elif defined(AFS_LINUX22_ENV)
734 struct afs_ioctl_sys {
739 afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
742 struct afs_ioctl_sys ua, *uap = &ua;
744 int ioctlDone = 0, code = 0;
746 AFS_STATCNT(afs_xioctl);
751 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
752 /* This is an AFS vnode */
753 if (((uap->com >> 8) & 0xff) == 'V') {
754 struct afs_ioctl *datap;
756 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
757 code = copyin_afs_ioctl((char *)uap->arg, datap);
759 osi_FreeSmallSpace(datap);
763 code = HandleIoctl(tvc, uap->com, datap);
764 osi_FreeSmallSpace(datap);
773 #elif defined(AFS_DARWIN_ENV) && !defined(AFS_DARWIN80_ENV)
781 afs_xioctl(afs_proc_t *p, struct ioctl_args *uap, register_t *retval)
785 int ioctlDone = 0, code = 0;
787 AFS_STATCNT(afs_xioctl);
788 if ((code = fdgetf(p, uap->fd, &fd)))
790 if (fd->f_type == DTYPE_VNODE) {
791 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
792 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
793 /* This is an AFS vnode */
794 if (((uap->com >> 8) & 0xff) == 'V') {
795 struct afs_ioctl *datap;
797 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
798 code = copyin_afs_ioctl((char *)uap->arg, datap);
800 osi_FreeSmallSpace(datap);
804 code = HandleIoctl(tvc, uap->com, datap);
805 osi_FreeSmallSpace(datap);
813 return ioctl(p, uap, retval);
817 #elif defined(AFS_XBSD_ENV)
818 # if defined(AFS_FBSD_ENV)
821 afs_xioctl(struct thread *td, struct ioctl_args *uap,
824 afs_proc_t *p = td->td_proc;
833 afs_xioctl(afs_proc_t *p, struct ioctl_args *uap, register_t *retval)
836 struct filedesc *fdp;
838 int ioctlDone = 0, code = 0;
841 AFS_STATCNT(afs_xioctl);
842 # if defined(AFS_NBSD40_ENV)
843 fdp = p->l_proc->p_fd;
847 if ((u_int) uap->fd >= fdp->fd_nfiles
848 || (fd = fdp->fd_ofiles[uap->fd]) == NULL)
850 if ((fd->f_flag & (FREAD | FWRITE)) == 0)
852 /* first determine whether this is any sort of vnode */
853 if (fd->f_type == DTYPE_VNODE) {
854 /* good, this is a vnode; next see if it is an AFS vnode */
855 # if defined(AFS_OBSD_ENV)
857 IsAfsVnode((struct vnode *)fd->
858 f_data) ? VTOAFS((struct vnode *)fd->f_data) : NULL;
860 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
862 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
863 /* This is an AFS vnode */
864 if (((uap->com >> 8) & 0xff) == 'V') {
865 struct afs_ioctl *datap;
867 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
868 code = copyin_afs_ioctl((char *)uap->arg, datap);
870 osi_FreeSmallSpace(datap);
874 code = HandleIoctl(tvc, uap->com, datap);
875 osi_FreeSmallSpace(datap);
883 # if defined(AFS_FBSD_ENV)
884 return ioctl(td, uap);
885 # elif defined(AFS_OBSD_ENV)
886 code = sys_ioctl(p, uap, retval);
887 # elif defined(AFS_NBSD_ENV)
888 struct lwp *l = osi_curproc();
889 code = sys_ioctl(l, uap, retval);
895 #elif defined(UKERNEL)
903 } *uap = (struct a *)get_user_struct()->u_ap;
906 int ioctlDone = 0, code = 0;
908 AFS_STATCNT(afs_xioctl);
913 /* first determine whether this is any sort of vnode */
914 if (fd->f_type == DTYPE_VNODE) {
915 /* good, this is a vnode; next see if it is an AFS vnode */
916 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
917 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
918 /* This is an AFS vnode */
919 if (((uap->com >> 8) & 0xff) == 'V') {
920 struct afs_ioctl *datap;
922 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
923 code=copyin_afs_ioctl((char *)uap->arg, datap);
925 osi_FreeSmallSpace(datap);
928 return (setuerror(code), code);
930 code = HandleIoctl(tvc, uap->com, datap);
931 osi_FreeSmallSpace(datap);
944 #endif /* AFS_HPUX102_ENV */
946 #if defined(AFS_SGI_ENV)
947 /* "pioctl" system call entry point; just pass argument to the parameterized
956 afs_pioctl(struct pioctlargs *uap, rval_t * rvp)
960 AFS_STATCNT(afs_pioctl);
962 code = afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow);
964 # ifdef AFS_SGI64_ENV
971 #elif defined(AFS_FBSD_ENV)
973 afs_pioctl(struct thread *td, void *args, int *retval)
980 } *uap = (struct a *)args;
982 AFS_STATCNT(afs_pioctl);
983 return (afs_syscall_pioctl
984 (uap->path, uap->cmd, uap->cmarg, uap->follow, td->td_ucred));
987 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
989 afs_pioctl(afs_proc_t *p, void *args, int *retval)
996 } *uap = (struct a *)args;
998 AFS_STATCNT(afs_pioctl);
999 # if defined(AFS_DARWIN80_ENV) || defined(AFS_NBSD40_ENV)
1000 return (afs_syscall_pioctl
1001 (uap->path, uap->cmd, uap->cmarg, uap->follow,
1004 return (afs_syscall_pioctl
1005 (uap->path, uap->cmd, uap->cmarg, uap->follow,
1006 # if defined(AFS_FBSD_ENV)
1009 p->p_cred->pc_ucred));
1016 /* macro to avoid adding any more #ifdef's to pioctl code. */
1017 #if defined(AFS_LINUX22_ENV) || defined(AFS_AIX41_ENV)
1018 #define PIOCTL_FREE_CRED() crfree(credp)
1020 #define PIOCTL_FREE_CRED()
1025 afs_syscall_pioctl(char *path, unsigned int com, caddr_t cmarg, int follow,
1026 rval_t *vvp, afs_ucred_t *credp)
1028 #ifdef AFS_DARWIN100_ENV
1029 afs_syscall64_pioctl(user_addr_t path, unsigned int com, user_addr_t cmarg,
1030 int follow, afs_ucred_t *credp)
1031 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1032 afs_syscall_pioctl(char *path, unsigned int com, caddr_t cmarg, int follow,
1035 afs_syscall_pioctl(char *path, unsigned int com, caddr_t cmarg, int follow)
1039 struct afs_ioctl data;
1040 #ifdef AFS_NEED_CLIENTCONTEXT
1041 afs_ucred_t *tmpcred = NULL;
1043 #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)
1044 afs_ucred_t *foreigncreds = NULL;
1047 struct vnode *vp = NULL;
1048 #ifdef AFS_AIX41_ENV
1049 struct ucred *credp = crref(); /* don't free until done! */
1051 #ifdef AFS_LINUX22_ENV
1052 cred_t *credp = crref(); /* don't free until done! */
1056 AFS_STATCNT(afs_syscall_pioctl);
1058 follow = 1; /* compat. with old venus */
1059 code = copyin_afs_ioctl(cmarg, &data);
1062 #if defined(KERNEL_HAVE_UERROR)
1067 if ((com & 0xff) == PSetClientContext) {
1068 #ifdef AFS_NEED_CLIENTCONTEXT
1069 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV)
1070 code = HandleClientContext(&data, &com, &foreigncreds, credp);
1072 code = HandleClientContext(&data, &com, &foreigncreds, osi_curcred());
1076 crfree(foreigncreds);
1079 #if defined(KERNEL_HAVE_UERROR)
1080 return (setuerror(code), code);
1085 #else /* AFS_NEED_CLIENTCONTEXT */
1087 #endif /* AFS_NEED_CLIENTCONTEXT */
1089 #ifdef AFS_NEED_CLIENTCONTEXT
1092 * We could have done without temporary setting the u.u_cred below
1093 * (foreigncreds could be passed as param the pioctl modules)
1094 * but calls such as afs_osi_suser() doesn't allow that since it
1095 * references u.u_cred directly. We could, of course, do something
1096 * like afs_osi_suser(cred) which, I think, is better since it
1097 * generalizes and supports multi cred environments...
1099 #if defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
1101 credp = foreigncreds;
1102 #elif defined(AFS_AIX41_ENV)
1103 tmpcred = crref(); /* XXX */
1104 crset(foreigncreds);
1105 #elif defined(AFS_HPUX101_ENV)
1106 tmpcred = p_cred(u.u_procp);
1107 set_p_cred(u.u_procp, foreigncreds);
1108 #elif defined(AFS_SGI_ENV)
1109 tmpcred = OSI_GET_CURRENT_CRED();
1110 OSI_SET_CURRENT_CRED(foreigncreds);
1113 u.u_cred = foreigncreds;
1116 #endif /* AFS_NEED_CLIENTCONTEXT */
1117 if ((com & 0xff) == 15) {
1118 /* special case prefetch so entire pathname eval occurs in helper process.
1119 * otherwise, the pioctl call is essentially useless */
1120 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1122 Prefetch(path, &data, follow,
1123 foreigncreds ? foreigncreds : credp);
1125 code = Prefetch(path, &data, follow, osi_curcred());
1128 #if defined(KERNEL_HAVE_UERROR)
1135 #ifdef AFS_AIX41_ENV
1137 lookupname(path, USR, follow, NULL, &vp,
1138 foreigncreds ? foreigncreds : credp);
1140 #ifdef AFS_LINUX22_ENV
1141 code = gop_lookupname_user(path, AFS_UIOUSER, follow, &dp);
1143 vp = (struct vnode *)dp->d_inode;
1145 code = gop_lookupname_user(path, AFS_UIOUSER, follow, &vp);
1146 #if defined(AFS_FBSD80_ENV) /* XXX check on 7x */
1149 #endif /* AFS_FBSD80_ENV */
1150 #endif /* AFS_LINUX22_ENV */
1151 #endif /* AFS_AIX41_ENV */
1155 #if defined(KERNEL_HAVE_UERROR)
1163 #if defined(AFS_SUN510_ENV)
1164 if (vp && !IsAfsVnode(vp)) {
1165 struct vnode *realvp;
1167 #ifdef AFS_SUN511_ENV
1168 (VOP_REALVP(vp, &realvp, NULL) == 0)
1170 (VOP_REALVP(vp, &realvp) == 0)
1173 struct vnode *oldvp = vp;
1181 /* now make the call if we were passed no file, or were passed an AFS file */
1182 if (!vp || IsAfsVnode(vp)) {
1183 #if defined(AFS_SUN5_ENV)
1184 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1185 #elif defined(AFS_AIX41_ENV)
1187 struct ucred *cred1, *cred2;
1190 cred1 = cred2 = foreigncreds;
1192 cred1 = cred2 = credp;
1194 code = afs_HandlePioctl(vp, com, &data, follow, &cred1);
1195 if (cred1 != cred2) {
1196 /* something changed the creds */
1200 #elif defined(AFS_HPUX101_ENV)
1202 struct ucred *cred = p_cred(u.u_procp);
1203 code = afs_HandlePioctl(vp, com, &data, follow, &cred);
1205 #elif defined(AFS_SGI_ENV)
1208 credp = OSI_GET_CURRENT_CRED();
1209 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1211 #elif defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1212 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1213 #elif defined(UKERNEL)
1214 code = afs_HandlePioctl(vp, com, &data, follow,
1215 &(get_user_struct()->u_cred));
1217 code = afs_HandlePioctl(vp, com, &data, follow, &u.u_cred);
1220 #if defined(KERNEL_HAVE_UERROR)
1223 code = EINVAL; /* not in /afs */
1228 #if defined(AFS_NEED_CLIENTCONTEXT)
1230 #ifdef AFS_AIX41_ENV
1231 crset(tmpcred); /* restore original credentials */
1233 #if defined(AFS_HPUX101_ENV)
1234 set_p_cred(u.u_procp, tmpcred); /* restore original credentials */
1235 #elif defined(AFS_SGI_ENV)
1236 OSI_SET_CURRENT_CRED(tmpcred); /* restore original credentials */
1237 #elif defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
1238 credp = tmpcred; /* restore original credentials */
1240 osi_curcred() = tmpcred; /* restore original credentials */
1241 #endif /* AFS_HPUX101_ENV */
1242 crfree(foreigncreds);
1245 #endif /* AFS_NEED_CLIENTCONTEXT */
1247 #ifdef AFS_LINUX22_ENV
1250 #if defined(AFS_FBSD80_ENV)
1251 if (VOP_ISLOCKED(vp))
1253 #endif /* AFS_FBSD80_ENV */
1254 AFS_RELE(vp); /* put vnode back */
1258 #if defined(KERNEL_HAVE_UERROR)
1261 return (getuerror());
1267 #ifdef AFS_DARWIN100_ENV
1269 afs_syscall_pioctl(char * path, unsigned int com, caddr_t cmarg,
1270 int follow, afs_ucred_t *credp)
1272 return afs_syscall64_pioctl(CAST_USER_ADDR_T(path), com,
1273 CAST_USER_ADDR_T((unsigned int)cmarg), follow,
1278 #define MAXPIOCTLTOKENLEN \
1279 (3*sizeof(afs_int32)+MAXKTCTICKETLEN+sizeof(struct ClearToken)+MAXKTCREALMLEN)
1282 afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
1283 struct afs_ioctl *ablob, int afollow,
1284 afs_ucred_t **acred)
1287 struct vrequest treq;
1289 afs_int32 function, device;
1290 struct afs_pdata input, output;
1291 struct afs_pdata copyInput, copyOutput;
1293 pioctlFunction *pioctlSw;
1295 struct afs_fakestat_state fakestate;
1297 memset(&input, 0, sizeof(input));
1298 memset(&output, 0, sizeof(output));
1300 avc = avp ? VTOAFS(avp) : NULL;
1301 afs_Trace3(afs_iclSetp, CM_TRACE_PIOCTL, ICL_TYPE_INT32, acom & 0xff,
1302 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, afollow);
1303 AFS_STATCNT(HandlePioctl);
1305 code = afs_InitReq(&treq, *acred);
1309 afs_InitFakeStat(&fakestate);
1311 code = afs_EvalFakeStat(&avc, &fakestate, &treq);
1315 device = (acom & 0xff00) >> 8;
1317 case 'V': /* Original pioctls */
1318 pioctlSw = VpioctlSw;
1319 pioctlSwSize = sizeof(VpioctlSw);
1321 case 'C': /* Coordinated/common pioctls */
1322 pioctlSw = CpioctlSw;
1323 pioctlSwSize = sizeof(CpioctlSw);
1325 case 'O': /* Coordinated/common pioctls */
1326 pioctlSw = OpioctlSw;
1327 pioctlSwSize = sizeof(OpioctlSw);
1333 function = acom & 0xff;
1334 if (function >= (pioctlSwSize / sizeof(char *))) {
1339 /* Do all range checking before continuing */
1340 if (ablob->in_size > MAXPIOCTLTOKENLEN ||
1341 ablob->in_size < 0 || ablob->out_size < 0) {
1346 code = afs_pd_alloc(&input, ablob->in_size);
1350 if (ablob->in_size > 0) {
1351 AFS_COPYIN(ablob->in, input.ptr, ablob->in_size, code);
1352 input.ptr[input.remaining] = '\0';
1357 if ((function == 8 && device == 'V') ||
1358 (function == 7 && device == 'C')) { /* PGetTokens */
1359 code = afs_pd_alloc(&output, MAXPIOCTLTOKENLEN);
1361 code = afs_pd_alloc(&output, AFS_LRALLOCSIZ);
1367 copyOutput = output;
1370 (*pioctlSw[function]) (avc, function, &treq, ©Input,
1371 ©Output, acred);
1373 outSize = copyOutput.ptr - output.ptr;
1375 if (code == 0 && ablob->out_size > 0) {
1376 if (outSize > ablob->out_size) {
1377 code = E2BIG; /* data wont fit in user buffer */
1378 } else if (outSize) {
1379 AFS_COPYOUT(output.ptr, ablob->out, outSize, code);
1384 afs_pd_free(&input);
1385 afs_pd_free(&output);
1387 afs_PutFakeStat(&fakestate);
1388 return afs_CheckCode(code, &treq, 41);
1392 * VIOCGETFID (22) - Get file ID quickly
1396 * \param[in] ain not in use
1397 * \param[out] aout fid of requested file
1399 * \retval EINVAL Error if some of the initial arguments aren't set
1401 * \post get the file id of some file
1403 DECL_PIOCTL(PGetFID)
1405 AFS_STATCNT(PGetFID);
1408 if (afs_pd_putBytes(aout, &avc->f.fid, sizeof(struct VenusFid)) != 0)
1414 * VIOCSETAL (1) - Set access control list
1418 * \param[in] ain the ACL being set
1419 * \param[out] aout the ACL being set returned
1421 * \retval EINVAL Error if some of the standard args aren't set
1423 * \post Changed ACL, via direct writing to the wire
1426 dummy_PSetAcl(char *ain, char *aout)
1431 DECL_PIOCTL(PSetAcl)
1434 struct afs_conn *tconn;
1435 struct AFSOpaque acl;
1436 struct AFSVolSync tsync;
1437 struct AFSFetchStatus OutStatus;
1440 AFS_STATCNT(PSetAcl);
1444 if (afs_pd_getStringPtr(ain, &acl.AFSOpaque_val) != 0)
1446 acl.AFSOpaque_len = strlen(acl.AFSOpaque_val) + 1;
1447 if (acl.AFSOpaque_len > 1024)
1451 tconn = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
1453 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREACL);
1456 RXAFS_StoreACL(tconn->id, (struct AFSFid *)&avc->f.fid.Fid,
1457 &acl, &OutStatus, &tsync);
1462 } while (afs_Analyze
1463 (tconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_STOREACL,
1464 SHARED_LOCK, NULL));
1466 /* now we've forgotten all of the access info */
1467 ObtainWriteLock(&afs_xcbhash, 455);
1469 afs_DequeueCallback(avc);
1470 avc->f.states &= ~(CStatd | CUnique);
1471 ReleaseWriteLock(&afs_xcbhash);
1472 if (avc->f.fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
1473 osi_dnlc_purgedp(avc);
1475 /* SXW - Should we flush metadata here? */
1479 int afs_defaultAsynchrony = 0;
1482 * VIOC_STOREBEHIND (47) Adjust store asynchrony
1486 * \param[in] ain sbstruct (store behind structure) input
1487 * \param[out] aout resulting sbstruct
1490 * Error if the user doesn't have super-user credentials
1492 * Error if there isn't enough access to not check the mode bits
1495 * Changes either the default asynchrony (the amount of data that
1496 * can remain to be written when the cache manager returns control
1497 * to the user), or the asyncrony for the specified file.
1499 DECL_PIOCTL(PStoreBehind)
1501 struct sbstruct sbr;
1503 if (afs_pd_getBytes(ain, &sbr, sizeof(struct sbstruct)) != 0)
1506 if (sbr.sb_default != -1) {
1507 if (afs_osi_suser(*acred))
1508 afs_defaultAsynchrony = sbr.sb_default;
1513 if (avc && (sbr.sb_thisfile != -1)) {
1515 (avc, PRSFS_WRITE | PRSFS_ADMINISTER, areq, DONT_CHECK_MODE_BITS))
1516 avc->asynchrony = sbr.sb_thisfile;
1521 memset(&sbr, 0, sizeof(sbr));
1522 sbr.sb_default = afs_defaultAsynchrony;
1524 sbr.sb_thisfile = avc->asynchrony;
1527 return afs_pd_putBytes(aout, &sbr, sizeof(sbr));
1531 * VIOC_GCPAGS (48) - Disable automatic PAG gc'ing
1535 * \param[in] ain not in use
1536 * \param[out] aout not in use
1538 * \retval EACCES Error if the user doesn't have super-user credentials
1540 * \post set the gcpags to GCPAGS_USERDISABLED
1542 DECL_PIOCTL(PGCPAGs)
1544 if (!afs_osi_suser(*acred)) {
1547 afs_gcpags = AFS_GCPAGS_USERDISABLED;
1552 * VIOCGETAL (2) - Get access control list
1556 * \param[in] ain not in use
1557 * \param[out] aout the ACL
1559 * \retval EINVAL Error if some of the standard args aren't set
1560 * \retval ERANGE Error if the vnode of the file id is too large
1561 * \retval -1 Error if getting the ACL failed
1563 * \post Obtain the ACL, based on file ID
1566 * There is a hack to tell which type of ACL is being returned, checks
1567 * the top 2-bytes of the input size to judge what type of ACL it is,
1568 * only for dfs xlator ACLs
1570 DECL_PIOCTL(PGetAcl)
1572 struct AFSOpaque acl;
1573 struct AFSVolSync tsync;
1574 struct AFSFetchStatus OutStatus;
1576 struct afs_conn *tconn;
1580 AFS_STATCNT(PGetAcl);
1583 Fid.Volume = avc->f.fid.Fid.Volume;
1584 Fid.Vnode = avc->f.fid.Fid.Vnode;
1585 Fid.Unique = avc->f.fid.Fid.Unique;
1586 if (avc->f.states & CForeign) {
1588 * For a dfs xlator acl we have a special hack so that the
1589 * xlator will distinguish which type of acl will return. So
1590 * we currently use the top 2-bytes (vals 0-4) to tell which
1591 * type of acl to bring back. Horrible hack but this will
1592 * cause the least number of changes to code size and interfaces.
1594 if (Fid.Vnode & 0xc0000000)
1596 Fid.Vnode |= (ain->remaining << 30);
1598 acl.AFSOpaque_val = aout->ptr;
1600 tconn = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
1602 acl.AFSOpaque_val[0] = '\0';
1603 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHACL);
1605 code = RXAFS_FetchACL(tconn->id, &Fid, &acl, &OutStatus, &tsync);
1610 } while (afs_Analyze
1611 (tconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_FETCHACL,
1612 SHARED_LOCK, NULL));
1615 if (acl.AFSOpaque_len == 0)
1616 afs_pd_skip(aout, 1); /* leave the NULL */
1618 afs_pd_skip(aout, acl.AFSOpaque_len); /* Length of the ACL */
1624 * PNoop returns success. Used for functions which are not implemented
1625 * or are no longer in use.
1629 * \retval Always returns success
1632 * Functions involved in this:
1633 * 17 (VIOCENGROUP) -- used to be enable group;
1634 * 18 (VIOCDISGROUP) -- used to be disable group;
1635 * 2 (?) -- get/set cache-bypass size threshold
1644 * PBogus returns fail. Used for functions which are not implemented or
1645 * are no longer in use.
1649 * \retval EINVAL Always returns this value
1652 * Functions involved in this:
1658 * 13 (VIOCGETTIME) -- used to be quick check time;
1659 * 15 (VIOCPREFETCH) -- prefetch is now special-cased; see pioctl code!;
1660 * 16 (VIOCNOP) -- used to be testing code;
1661 * 19 (VIOCLISTGROUPS) -- used to be list group;
1662 * 23 (VIOCWAITFOREVER) -- used to be waitforever;
1663 * 57 (VIOC_FPRIOSTATUS) -- arla: set file prio;
1664 * 58 (VIOC_FHGET) -- arla: fallback getfh;
1665 * 59 (VIOC_FHOPEN) -- arla: fallback fhopen;
1666 * 60 (VIOC_XFSDEBUG) -- arla: controls xfsdebug;
1667 * 61 (VIOC_ARLADEBUG) -- arla: controls arla debug;
1668 * 62 (VIOC_AVIATOR) -- arla: debug interface;
1669 * 63 (VIOC_XFSDEBUG_PRINT) -- arla: print xfs status;
1670 * 64 (VIOC_CALCULATE_CACHE) -- arla: force cache check;
1671 * 65 (VIOC_BREAKCELLBACK) -- arla: break callback;
1672 * 68 (?) -- arla: fetch stats;
1676 AFS_STATCNT(PBogus);
1681 * VIOC_FILE_CELL_NAME (30) - Get cell in which file lives
1685 * \param[in] ain not in use (avc used to pass in file id)
1686 * \param[out] aout cell name
1688 * \retval EINVAL Error if some of the standard args aren't set
1689 * \retval ESRCH Error if the file isn't part of a cell
1691 * \post Get a cell based on a passed in file id
1693 DECL_PIOCTL(PGetFileCell)
1697 AFS_STATCNT(PGetFileCell);
1700 tcell = afs_GetCell(avc->f.fid.Cell, READ_LOCK);
1704 if (afs_pd_putString(aout, tcell->cellName) != 0)
1707 afs_PutCell(tcell, READ_LOCK);
1712 * VIOC_GET_WS_CELL (31) - Get cell in which workstation lives
1716 * \param[in] ain not in use
1717 * \param[out] aout cell name
1720 * Error if the afs daemon hasn't started yet
1722 * Error if the machine isn't part of a cell, for whatever reason
1724 * \post Get the primary cell that the machine is a part of.
1726 DECL_PIOCTL(PGetWSCell)
1728 struct cell *tcell = NULL;
1730 AFS_STATCNT(PGetWSCell);
1731 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1732 return EIO; /* Inappropriate ioctl for device */
1734 tcell = afs_GetPrimaryCell(READ_LOCK);
1735 if (!tcell) /* no primary cell? */
1738 if (afs_pd_putString(aout, tcell->cellName) != 0)
1740 afs_PutCell(tcell, READ_LOCK);
1745 * VIOC_GET_PRIMARY_CELL (33) - Get primary cell for caller
1749 * \param[in] ain not in use (user id found via areq)
1750 * \param[out] aout cell name
1753 * Error if the user id doesn't have a primary cell specified
1755 * \post Get the primary cell for a certain user, based on the user's uid
1757 DECL_PIOCTL(PGetUserCell)
1760 struct unixuser *tu;
1763 AFS_STATCNT(PGetUserCell);
1764 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1765 return EIO; /* Inappropriate ioctl for device */
1767 /* return the cell name of the primary cell for this user */
1768 i = UHash(areq->uid);
1769 ObtainWriteLock(&afs_xuser, 224);
1770 for (tu = afs_users[i]; tu; tu = tu->next) {
1771 if (tu->uid == areq->uid && (tu->states & UPrimary)) {
1773 ReleaseWriteLock(&afs_xuser);
1778 tcell = afs_GetCell(tu->cell, READ_LOCK);
1779 afs_PutUser(tu, WRITE_LOCK);
1783 if (afs_pd_putString(aout, tcell->cellName) != 0)
1785 afs_PutCell(tcell, READ_LOCK);
1788 ReleaseWriteLock(&afs_xuser);
1793 /* Work out which cell we're changing tokens for */
1795 _settok_tokenCell(char *cellName, int *cellNum, int *primary) {
1799 if (cellName && strlen(cellName) > 0) {
1800 cell = afs_GetCellByName(cellName, READ_LOCK);
1802 cell = afs_GetPrimaryCell(READ_LOCK);
1813 *cellNum = cell->cellNum;
1814 afs_PutCell(cell, READ_LOCK);
1821 _settok_setParentPag(afs_ucred_t **cred) {
1823 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1825 osi_procname(procname, 256);
1826 afs_warnuser("Process %d (%s) tried to change pags in PSetTokens\n",
1827 MyPidxx2Pid(MyPidxx), procname);
1828 return setpag(osi_curproc(), cred, -1, &pag, 1);
1830 return setpag(cred, -1, &pag, 1);
1835 * VIOCSETTOK (3) - Set authentication tokens
1839 * \param[in] ain the krb tickets from which to set the afs tokens
1840 * \param[out] aout not in use
1843 * Error if the ticket is either too long or too short
1845 * Error if the AFS initState is below 101
1847 * Error if the cell for which the Token is being set can't be found
1850 * Set the Tokens for a specific cell name, unless there is none set,
1851 * then default to primary
1854 DECL_PIOCTL(PSetTokens)
1859 struct unixuser *tu;
1860 struct ClearToken clear;
1864 struct vrequest treq;
1865 afs_int32 flag, set_parent_pag = 0;
1867 AFS_STATCNT(PSetTokens);
1868 if (!afs_resourceinit_flag) {
1872 if (afs_pd_getInt(ain, &stLen) != 0)
1875 stp = afs_pd_where(ain); /* remember where the ticket is */
1876 if (stLen < 0 || stLen > MAXKTCTICKETLEN)
1877 return EINVAL; /* malloc may fail */
1878 if (afs_pd_skip(ain, stLen) != 0)
1881 if (afs_pd_getInt(ain, &size) != 0)
1883 if (size != sizeof(struct ClearToken))
1886 if (afs_pd_getBytes(ain, &clear, sizeof(struct ClearToken)) !=0)
1889 if (clear.AuthHandle == -1)
1890 clear.AuthHandle = 999; /* more rxvab compat stuff */
1892 if (afs_pd_remaining(ain) != 0) {
1893 /* still stuff left? we've got primary flag and cell name.
1896 if (afs_pd_getInt(ain, &flag) != 0)
1899 /* some versions of gcc appear to need != 0 in order to get this
1901 if ((flag & 0x8000) != 0) { /* XXX Use Constant XXX */
1906 if (afs_pd_getStringPtr(ain, &cellName) != 0)
1909 code = _settok_tokenCell(cellName, &cellNum, NULL);
1913 /* default to primary cell, primary id */
1914 code = _settok_tokenCell(NULL, &cellNum, &flag);
1919 if (set_parent_pag) {
1920 if (_settok_setParentPag(acred) == 0) {
1921 afs_InitReq(&treq, *acred);
1926 /* now we just set the tokens */
1927 tu = afs_GetUser(areq->uid, cellNum, WRITE_LOCK);
1928 /* Set tokens destroys any that are already there */
1929 afs_FreeTokens(&tu->tokens);
1930 afs_AddRxkadToken(&tu->tokens, stp, stLen, &clear);
1932 afs_stats_cmfullperf.authent.TicketUpdates++;
1933 afs_ComputePAGStats();
1934 #endif /* AFS_NOSTATS */
1935 tu->states |= UHasTokens;
1936 tu->states &= ~UTokensBad;
1937 afs_SetPrimary(tu, flag);
1938 tu->tokenTime = osi_Time();
1939 afs_ResetUserConns(tu);
1940 afs_NotifyUser(tu, UTokensObtained);
1941 afs_PutUser(tu, WRITE_LOCK);
1947 * VIOCGETVOLSTAT (4) - Get volume status
1951 * \param[in] ain not in use
1952 * \param[out] aout status of the volume
1954 * \retval EINVAL Error if some of the standard args aren't set
1957 * The status of a volume (based on the FID of the volume), or an
1958 * offline message /motd
1960 DECL_PIOCTL(PGetVolumeStatus)
1963 char *offLineMsg = afs_osi_Alloc(256);
1964 char *motd = afs_osi_Alloc(256);
1965 struct afs_conn *tc;
1967 struct AFSFetchVolumeStatus volstat;
1971 AFS_STATCNT(PGetVolumeStatus);
1978 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
1980 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS);
1983 RXAFS_GetVolumeStatus(tc->id, avc->f.fid.Fid.Volume, &volstat,
1984 &Name, &offLineMsg, &motd);
1989 } while (afs_Analyze
1990 (tc, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS,
1991 SHARED_LOCK, NULL));
1995 /* Copy all this junk into msg->im_data, keeping track of the lengths. */
1996 if (afs_pd_putBytes(aout, &volstat, sizeof(VolumeStatus)) != 0)
1998 if (afs_pd_putString(aout, volName) != 0)
2000 if (afs_pd_putString(aout, offLineMsg) != 0)
2002 if (afs_pd_putString(aout, motd) != 0)
2005 afs_osi_Free(offLineMsg, 256);
2006 afs_osi_Free(motd, 256);
2011 * VIOCSETVOLSTAT (5) - Set volume status
2016 * values to set the status at, offline message, message of the day,
2017 * volume name, minimum quota, maximum quota
2019 * status of a volume, offlines messages, minimum quota, maximumm quota
2022 * Error if some of the standard args aren't set
2024 * Error if the volume is read only, or a backup volume
2026 * Error if the volume can't be accessed
2028 * Error if the volume name, offline message, and motd are too big
2031 * Set the status of a volume, including any offline messages,
2032 * a minimum quota, and a maximum quota
2034 DECL_PIOCTL(PSetVolumeStatus)
2039 struct afs_conn *tc;
2041 struct AFSFetchVolumeStatus volstat;
2042 struct AFSStoreVolumeStatus storeStat;
2046 AFS_STATCNT(PSetVolumeStatus);
2050 tvp = afs_GetVolume(&avc->f.fid, areq, READ_LOCK);
2052 if (tvp->states & (VRO | VBackup)) {
2053 afs_PutVolume(tvp, READ_LOCK);
2056 afs_PutVolume(tvp, READ_LOCK);
2061 if (afs_pd_getBytes(ain, &volstat, sizeof(AFSFetchVolumeStatus)) != 0)
2064 if (afs_pd_getStringPtr(ain, &volName) != 0)
2066 if (strlen(volName) > 32)
2069 if (afs_pd_getStringPtr(ain, &offLineMsg) != 0)
2071 if (strlen(offLineMsg) > 256)
2074 if (afs_pd_getStringPtr(ain, &motd) != 0)
2076 if (strlen(motd) > 256)
2079 /* Done reading ... */
2082 if (volstat.MinQuota != -1) {
2083 storeStat.MinQuota = volstat.MinQuota;
2084 storeStat.Mask |= AFS_SETMINQUOTA;
2086 if (volstat.MaxQuota != -1) {
2087 storeStat.MaxQuota = volstat.MaxQuota;
2088 storeStat.Mask |= AFS_SETMAXQUOTA;
2091 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
2093 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS);
2096 RXAFS_SetVolumeStatus(tc->id, avc->f.fid.Fid.Volume, &storeStat,
2097 volName, offLineMsg, motd);
2102 } while (afs_Analyze
2103 (tc, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS,
2104 SHARED_LOCK, NULL));
2108 /* we are sending parms back to make compat. with prev system. should
2109 * change interface later to not ask for current status, just set new
2112 if (afs_pd_putBytes(aout, &volstat, sizeof(VolumeStatus)) != 0)
2114 if (afs_pd_putString(aout, volName) != 0)
2116 if (afs_pd_putString(aout, offLineMsg) != 0)
2118 if (afs_pd_putString(aout, motd) != 0)
2125 * VIOCFLUSH (6) - Invalidate cache entry
2129 * \param[in] ain not in use
2130 * \param[out] aout not in use
2132 * \retval EINVAL Error if some of the standard args aren't set
2134 * \post Flush any information the cache manager has on an entry
2138 AFS_STATCNT(PFlush);
2141 #ifdef AFS_BOZONLOCK_ENV
2142 afs_BozonLock(&avc->pvnLock, avc); /* Since afs_TryToSmush will do a pvn_vptrunc */
2144 ObtainWriteLock(&avc->lock, 225);
2145 afs_ResetVCache(avc, *acred);
2146 ReleaseWriteLock(&avc->lock);
2147 #ifdef AFS_BOZONLOCK_ENV
2148 afs_BozonUnlock(&avc->pvnLock, avc);
2154 * VIOC_AFS_STAT_MT_PT (29) - Stat mount point
2159 * the last component in a path, related to mountpoint that we're
2160 * looking for information about
2162 * volume, cell, link data
2164 * \retval EINVAL Error if some of the standard args aren't set
2165 * \retval ENOTDIR Error if the 'mount point' argument isn't a directory
2166 * \retval EIO Error if the link data can't be accessed
2168 * \post Get the volume, and cell, as well as the link data for a mount point
2170 DECL_PIOCTL(PNewStatMount)
2175 struct VenusFid tfid;
2178 struct sysname_info sysState;
2179 afs_size_t offset, len;
2181 AFS_STATCNT(PNewStatMount);
2185 if (afs_pd_getStringPtr(ain, &name) != 0)
2188 code = afs_VerifyVCache(avc, areq);
2191 if (vType(avc) != VDIR) {
2194 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
2197 Check_AtSys(avc, name, &sysState, areq);
2198 ObtainReadLock(&tdc->lock);
2200 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
2201 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
2202 ReleaseReadLock(&tdc->lock);
2203 afs_PutDCache(tdc); /* we're done with the data */
2204 bufp = sysState.name;
2208 tfid.Cell = avc->f.fid.Cell;
2209 tfid.Fid.Volume = avc->f.fid.Fid.Volume;
2210 if (!tfid.Fid.Unique && (avc->f.states & CForeign)) {
2211 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
2213 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
2219 if (tvc->mvstat != 1) {
2224 ObtainWriteLock(&tvc->lock, 226);
2225 code = afs_HandleLink(tvc, areq);
2227 if (tvc->linkData) {
2228 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
2231 /* we have the data */
2232 if (afs_pd_putString(aout, tvc->linkData) != 0)
2238 ReleaseWriteLock(&tvc->lock);
2241 if (sysState.allocked)
2242 osi_FreeLargeSpace(bufp);
2247 * A helper function to get the n'th cell which a particular user has tokens
2248 * for. This is racy. If new tokens are added whilst we're iterating, then
2249 * we may return some cells twice. If tokens expire mid run, then we'll
2250 * miss some cells from our output. So, could be better, but that would
2251 * require an interface change.
2254 static struct unixuser *
2255 getNthCell(afs_int32 uid, afs_int32 iterator) {
2257 struct unixuser *tu = NULL;
2260 ObtainReadLock(&afs_xuser);
2261 for (tu = afs_users[i]; tu; tu = tu->next) {
2262 if (tu->uid == uid && (tu->states & UHasTokens)) {
2263 if (iterator-- == 0)
2264 break; /* are we done yet? */
2270 ReleaseReadLock(&afs_xuser);
2275 * VIOCGETTOK (8) - Get authentication tokens
2279 * \param[in] ain cellid to return tokens for
2280 * \param[out] aout token
2283 * Error if the afs daemon hasn't started yet
2285 * Error if the input parameter is out of the bounds of the available
2288 * Error if there aren't tokens for this cell
2291 * If the input paramater exists, get the token that corresponds to
2292 * the parameter value, if there is no token at this value, get the
2293 * token for the first cell
2295 * \notes "it's a weird interface (from comments in the code)"
2298 DECL_PIOCTL(PGetTokens)
2301 struct unixuser *tu = NULL;
2302 union tokenUnion *token;
2303 afs_int32 iterator = 0;
2308 AFS_STATCNT(PGetTokens);
2309 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2310 return EIO; /* Inappropriate ioctl for device */
2312 /* weird interface. If input parameter is present, it is an integer and
2313 * we're supposed to return the parm'th tokens for this unix uid.
2314 * If not present, we just return tokens for cell 1.
2315 * If counter out of bounds, return EDOM.
2316 * If no tokens for the particular cell, return ENOTCONN.
2317 * Also, if this mysterious parm is present, we return, along with the
2318 * tokens, the primary cell indicator (an afs_int32 0) and the cell name
2319 * at the end, in that order.
2321 newStyle = (afs_pd_remaining(ain) > 0);
2323 if (afs_pd_getInt(ain, &iterator) != 0)
2327 tu = getNthCell(areq->uid, iterator);
2329 cellNum = afs_GetPrimaryCellNum();
2331 tu = afs_FindUser(areq->uid, cellNum, READ_LOCK);
2336 if (!(tu->states & UHasTokens)
2337 || !afs_HasUsableTokens(tu->tokens, osi_Time())) {
2338 tu->states |= (UTokensBad | UNeedsReset);
2339 afs_NotifyUser(tu, UTokensDropped);
2340 afs_PutUser(tu, READ_LOCK);
2343 token = afs_FindToken(tu->tokens, RX_SECIDX_KAD);
2345 /* for compat, we try to return 56 byte tix if they fit */
2346 iterator = token->rxkad.ticketLen;
2348 iterator = 56; /* # of bytes we're returning */
2350 if (afs_pd_putInt(aout, iterator) != 0)
2352 if (afs_pd_putBytes(aout, token->rxkad.ticket, token->rxkad.ticketLen) != 0)
2354 if (token->rxkad.ticketLen < 56) {
2355 /* Tokens are always 56 bytes or larger */
2356 if (afs_pd_skip(aout, iterator - token->rxkad.ticketLen) != 0) {
2361 if (afs_pd_putInt(aout, sizeof(struct ClearToken)) != 0)
2363 if (afs_pd_putBytes(aout, &token->rxkad.clearToken,
2364 sizeof(struct ClearToken)) != 0)
2368 /* put out primary id and cell name, too */
2369 iterator = (tu->states & UPrimary ? 1 : 0);
2370 if (afs_pd_putInt(aout, iterator) != 0)
2372 tcell = afs_GetCell(tu->cell, READ_LOCK);
2374 if (afs_pd_putString(aout, tcell->cellName) != 0)
2376 afs_PutCell(tcell, READ_LOCK);
2378 if (afs_pd_putString(aout, "") != 0)
2381 /* Got here, all is good */
2384 afs_PutUser(tu, READ_LOCK);
2389 * VIOCUNLOG (9) - Invalidate tokens
2393 * \param[in] ain not in use
2394 * \param[out] aout not in use
2396 * \retval EIO Error if the afs daemon hasn't been started yet
2398 * \post remove tokens from a user, specified by the user id
2400 * \notes sets the token's time to 0, which then causes it to be removed
2401 * \notes Unlog is the same as un-pag in OpenAFS
2406 struct unixuser *tu;
2408 AFS_STATCNT(PUnlog);
2409 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2410 return EIO; /* Inappropriate ioctl for device */
2412 i = UHash(areq->uid);
2413 ObtainWriteLock(&afs_xuser, 227);
2414 for (tu = afs_users[i]; tu; tu = tu->next) {
2415 if (tu->uid == areq->uid) {
2416 tu->states &= ~UHasTokens;
2417 afs_FreeTokens(&tu->tokens);
2419 ReleaseWriteLock(&afs_xuser);
2420 afs_NotifyUser(tu, UTokensDropped);
2421 /* We have to drop the lock over the call to afs_ResetUserConns,
2422 * since it obtains the afs_xvcache lock. We could also keep
2423 * the lock, and modify ResetUserConns to take parm saying we
2424 * obtained the lock already, but that is overkill. By keeping
2425 * the "tu" pointer held over the released lock, we guarantee
2426 * that we won't lose our place, and that we'll pass over
2427 * every user conn that existed when we began this call.
2429 afs_ResetUserConns(tu);
2431 ObtainWriteLock(&afs_xuser, 228);
2433 /* set the expire times to 0, causes
2434 * afs_GCUserData to remove this entry
2437 #endif /* UKERNEL */
2440 ReleaseWriteLock(&afs_xuser);
2445 * VIOC_AFS_MARINER_HOST (32) - Get/set mariner (cache manager monitor) host
2449 * \param[in] ain host address to be set
2450 * \param[out] aout old host address
2453 * depending on whether or not a variable is set, either get the host
2454 * for the cache manager monitor, or set the old address and give it
2457 * \notes Errors turn off mariner
2459 DECL_PIOCTL(PMariner)
2461 afs_int32 newHostAddr;
2462 afs_int32 oldHostAddr;
2464 AFS_STATCNT(PMariner);
2466 memcpy((char *)&oldHostAddr, (char *)&afs_marinerHost,
2469 oldHostAddr = 0xffffffff; /* disabled */
2471 if (afs_pd_getInt(ain, &newHostAddr) != 0)
2474 if (newHostAddr == 0xffffffff) {
2475 /* disable mariner operations */
2477 } else if (newHostAddr) {
2479 afs_marinerHost = newHostAddr;
2482 if (afs_pd_putInt(aout, oldHostAddr) != 0)
2489 * VIOCCKSERV (10) - Check that servers are up
2493 * \param[in] ain name of the cell
2494 * \param[out] aout current down server list
2496 * \retval EIO Error if the afs daemon hasn't started yet
2497 * \retval EACCES Error if the user doesn't have super-user credentials
2498 * \retval ENOENT Error if we are unable to obtain the cell
2501 * Either a fast check (where it doesn't contact servers) or a
2502 * local check (checks local cell only)
2504 DECL_PIOCTL(PCheckServers)
2509 char *cellName = NULL;
2511 struct chservinfo *pcheck;
2513 AFS_STATCNT(PCheckServers);
2515 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2516 return EIO; /* Inappropriate ioctl for device */
2518 /* This is tricky, because we need to peak at the datastream to see
2519 * what we're getting. For now, let's cheat. */
2521 /* ain contains either an int32 or a string */
2522 if (ain->remaining == 0)
2525 if (*(afs_int32 *)ain->ptr == 0x12345678) { /* For afs3.3 version */
2526 pcheck = afs_pd_inline(ain, sizeof(*pcheck));
2530 if (pcheck->tinterval >= 0) {
2531 if (afs_pd_putInt(aout, afs_probe_interval) != 0)
2533 if (pcheck->tinterval > 0) {
2534 if (!afs_osi_suser(*acred))
2536 afs_probe_interval = pcheck->tinterval;
2540 temp = pcheck->tflags;
2542 cellName = pcheck->tbuffer;
2543 } else { /* For pre afs3.3 versions */
2544 if (afs_pd_getInt(ain, &temp) != 0)
2546 if (afs_pd_remaining(ain) > 0) {
2547 if (afs_pd_getStringPtr(ain, &cellName) != 0)
2553 * 1: fast check, don't contact servers.
2554 * 2: local cell only.
2557 /* have cell name, too */
2558 cellp = afs_GetCellByName(cellName, READ_LOCK);
2563 if (!cellp && (temp & 2)) {
2564 /* use local cell */
2565 cellp = afs_GetPrimaryCell(READ_LOCK);
2567 if (!(temp & 1)) { /* if not fast, call server checker routine */
2568 afs_CheckServers(1, cellp); /* check down servers */
2569 afs_CheckServers(0, cellp); /* check up servers */
2571 /* now return the current down server list */
2572 ObtainReadLock(&afs_xserver);
2573 for (i = 0; i < NSERVERS; i++) {
2574 for (ts = afs_servers[i]; ts; ts = ts->next) {
2575 if (cellp && ts->cell != cellp)
2576 continue; /* cell spec'd and wrong */
2577 if ((ts->flags & SRVR_ISDOWN)
2578 && ts->addr->sa_portal != ts->cell->vlport) {
2579 afs_pd_putInt(aout, ts->addr->sa_ip);
2583 ReleaseReadLock(&afs_xserver);
2585 afs_PutCell(cellp, READ_LOCK);
2590 * VIOCCKBACK (11) - Check backup volume mappings
2594 * \param[in] ain not in use
2595 * \param[out] aout not in use
2597 * \retval EIO Error if the afs daemon hasn't started yet
2600 * Check the root volume, and then check the names if the volume
2601 * check variable is set to force, has expired, is busy, or if
2602 * the mount points variable is set
2604 DECL_PIOCTL(PCheckVolNames)
2606 AFS_STATCNT(PCheckVolNames);
2607 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2608 return EIO; /* Inappropriate ioctl for device */
2610 afs_CheckRootVolume();
2611 afs_CheckVolumeNames(AFS_VOLCHECK_FORCE | AFS_VOLCHECK_EXPIRED |
2612 AFS_VOLCHECK_BUSY | AFS_VOLCHECK_MTPTS);
2617 * VIOCCKCONN (12) - Check connections for a user
2621 * \param[in] ain not in use
2622 * \param[out] aout not in use
2625 * Error if no user is specififed, the user has no tokens set,
2626 * or if the user's tokens are bad
2629 * check to see if a user has the correct authentication.
2630 * If so, allow access.
2632 * \notes Check the connections to all the servers specified
2634 DECL_PIOCTL(PCheckAuth)
2638 struct afs_conn *tc;
2639 struct unixuser *tu;
2642 AFS_STATCNT(PCheckAuth);
2643 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2644 return EIO; /* Inappropriate ioctl for device */
2647 tu = afs_GetUser(areq->uid, 1, READ_LOCK); /* check local cell authentication */
2651 /* we have a user */
2652 ObtainReadLock(&afs_xsrvAddr);
2653 ObtainReadLock(&afs_xconn);
2655 /* any tokens set? */
2656 if ((tu->states & UHasTokens) == 0)
2658 /* all connections in cell 1 working? */
2659 for (i = 0; i < NSERVERS; i++) {
2660 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2661 for (tc = sa->conns; tc; tc = tc->next) {
2662 if (tc->user == tu && (tu->states & UTokensBad))
2667 ReleaseReadLock(&afs_xsrvAddr);
2668 ReleaseReadLock(&afs_xconn);
2669 afs_PutUser(tu, READ_LOCK);
2671 if (afs_pd_putInt(aout, retValue) != 0)
2677 Prefetch(uparmtype apath, struct afs_ioctl *adata, int afollow,
2682 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2688 AFS_STATCNT(Prefetch);
2691 tp = osi_AllocLargeSpace(1024);
2692 AFS_COPYINSTR(apath, tp, 1024, &bufferSize, code);
2694 osi_FreeLargeSpace(tp);
2697 if (afs_BBusy()) { /* do this as late as possible */
2698 osi_FreeLargeSpace(tp);
2699 return EWOULDBLOCK; /* pretty close */
2701 afs_BQueue(BOP_PATH, (struct vcache *)0, 0, 0, acred, (afs_size_t) 0,
2702 (afs_size_t) 0, tp, (void *)0, (void *)0);
2707 * VIOCWHEREIS (14) - Find out where a volume is located
2711 * \param[in] ain not in use
2712 * \param[out] aout volume location
2714 * \retval EINVAL Error if some of the default arguments don't exist
2715 * \retval ENODEV Error if there is no such volume
2717 * \post fine a volume, based on a volume file id
2719 * \notes check each of the servers specified
2721 DECL_PIOCTL(PFindVolume)
2728 AFS_STATCNT(PFindVolume);
2731 tvp = afs_GetVolume(&avc->f.fid, areq, READ_LOCK);
2735 for (i = 0; i < AFS_MAXHOSTS; i++) {
2736 ts = tvp->serverHost[i];
2739 if (afs_pd_putInt(aout, ts->addr->sa_ip) != 0) {
2744 if (i < AFS_MAXHOSTS) {
2745 /* still room for terminating NULL, add it on */
2746 if (afs_pd_putInt(aout, 0) != 0) {
2752 afs_PutVolume(tvp, READ_LOCK);
2757 * VIOCACCESS (20) - Access using PRS_FS bits
2761 * \param[in] ain PRS_FS bits
2762 * \param[out] aout not in use
2764 * \retval EINVAL Error if some of the initial arguments aren't set
2765 * \retval EACCES Error if access is denied
2767 * \post check to make sure access is allowed
2769 DECL_PIOCTL(PViceAccess)
2774 AFS_STATCNT(PViceAccess);
2778 code = afs_VerifyVCache(avc, areq);
2782 if (afs_pd_getInt(ain, &temp) != 0)
2785 code = afs_AccessOK(avc, temp, areq, CHECK_MODE_BITS);
2793 * VIOC_GETPAG (13) - Get PAG value
2797 * \param[in] ain not in use
2798 * \param[out] aout PAG value or NOPAG
2800 * \post get PAG value for the caller's cred
2802 DECL_PIOCTL(PGetPAG)
2806 pag = PagInCred(*acred);
2808 return afs_pd_putInt(aout, pag);
2811 DECL_PIOCTL(PPrecache)
2815 /*AFS_STATCNT(PPrecache);*/
2816 if (!afs_osi_suser(*acred))
2819 if (afs_pd_getInt(ain, &newValue) != 0)
2822 afs_preCache = newValue*1024;
2827 * VIOCSETCACHESIZE (24) - Set venus cache size in 1000 units
2831 * \param[in] ain the size the venus cache should be set to
2832 * \param[out] aout not in use
2834 * \retval EACCES Error if the user doesn't have super-user credentials
2835 * \retval EROFS Error if the cache is set to be in memory
2838 * Set the cache size based on user input. If no size is given,
2839 * set it to the default OpenAFS cache size.
2842 * recompute the general cache parameters for every single block allocated
2844 DECL_PIOCTL(PSetCacheSize)
2849 AFS_STATCNT(PSetCacheSize);
2851 if (!afs_osi_suser(*acred))
2853 /* too many things are setup initially in mem cache version */
2854 if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
2856 if (afs_pd_getInt(ain, &newValue) != 0)
2859 afs_cacheBlocks = afs_stats_cmperf.cacheBlocksOrig;
2861 if (newValue < afs_min_cache)
2862 afs_cacheBlocks = afs_min_cache;
2864 afs_cacheBlocks = newValue;
2866 afs_stats_cmperf.cacheBlocksTotal = afs_cacheBlocks;
2867 afs_ComputeCacheParms(); /* recompute basic cache parameters */
2868 afs_MaybeWakeupTruncateDaemon();
2869 while (waitcnt++ < 100 && afs_cacheBlocks < afs_blocksUsed) {
2870 afs_osi_Wait(1000, 0, 0);
2871 afs_MaybeWakeupTruncateDaemon();
2876 #define MAXGCSTATS 16
2878 * VIOCGETCACHEPARMS (40) - Get cache stats
2882 * \param[in] ain afs index flags
2883 * \param[out] aout cache blocks, blocks used, blocks files (in an array)
2885 * \post Get the cache blocks, and how many of the cache blocks there are
2887 DECL_PIOCTL(PGetCacheSize)
2889 afs_int32 results[MAXGCSTATS];
2891 struct dcache * tdc;
2894 AFS_STATCNT(PGetCacheSize);
2896 if (afs_pd_remaining(ain) == sizeof(afs_int32)) {
2897 afs_pd_getInt(ain, &flags); /* can't error, we just checked size */
2898 } else if (afs_pd_remaining(ain) == 0) {
2904 memset(results, 0, sizeof(results));
2905 results[0] = afs_cacheBlocks;
2906 results[1] = afs_blocksUsed;
2907 results[2] = afs_cacheFiles;
2910 for (i = 0; i < afs_cacheFiles; i++) {
2911 if (afs_indexFlags[i] & IFFree) results[3]++;
2913 } else if (2 == flags){
2914 for (i = 0; i < afs_cacheFiles; i++) {
2915 if (afs_indexFlags[i] & IFFree) results[3]++;
2916 if (afs_indexFlags[i] & IFEverUsed) results[4]++;
2917 if (afs_indexFlags[i] & IFDataMod) results[5]++;
2918 if (afs_indexFlags[i] & IFDirtyPages) results[6]++;
2919 if (afs_indexFlags[i] & IFAnyPages) results[7]++;
2920 if (afs_indexFlags[i] & IFDiscarded) results[8]++;
2922 tdc = afs_indexTable[i];
2925 size = tdc->validPos;
2926 if ( 0 < size && size < (1<<12) ) results[10]++;
2927 else if (size < (1<<14) ) results[11]++;
2928 else if (size < (1<<16) ) results[12]++;
2929 else if (size < (1<<18) ) results[13]++;
2930 else if (size < (1<<20) ) results[14]++;
2931 else if (size >= (1<<20) ) results[15]++;
2935 return afs_pd_putBytes(aout, results, sizeof(results));
2939 * VIOCFLUSHCB (25) - Flush callback only
2943 * \param[in] ain not in use
2944 * \param[out] aout not in use
2946 * \retval EINVAL Error if some of the standard args aren't set
2947 * \retval 0 0 returned if the volume is set to read-only
2950 * Flushes callbacks, by setting the length of callbacks to one,
2951 * setting the next callback to be sent to the CB_DROPPED value,
2952 * and then dequeues everything else.
2954 DECL_PIOCTL(PRemoveCallBack)
2956 struct afs_conn *tc;
2958 struct AFSCallBack CallBacks_Array[1];
2959 struct AFSCBFids theFids;
2960 struct AFSCBs theCBs;
2963 AFS_STATCNT(PRemoveCallBack);
2966 if (avc->f.states & CRO)
2967 return 0; /* read-only-ness can't change */
2968 ObtainWriteLock(&avc->lock, 229);
2969 theFids.AFSCBFids_len = 1;
2970 theCBs.AFSCBs_len = 1;
2971 theFids.AFSCBFids_val = (struct AFSFid *)&avc->f.fid.Fid;
2972 theCBs.AFSCBs_val = CallBacks_Array;
2973 CallBacks_Array[0].CallBackType = CB_DROPPED;
2974 if (avc->callback) {
2976 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
2978 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
2980 code = RXAFS_GiveUpCallBacks(tc->id, &theFids, &theCBs);
2984 /* don't set code on failure since we wouldn't use it */
2985 } while (afs_Analyze
2986 (tc, code, &avc->f.fid, areq,
2987 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK, NULL));
2989 ObtainWriteLock(&afs_xcbhash, 457);
2990 afs_DequeueCallback(avc);
2992 avc->f.states &= ~(CStatd | CUnique);
2993 ReleaseWriteLock(&afs_xcbhash);
2994 if (avc->f.fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
2995 osi_dnlc_purgedp(avc);
2997 ReleaseWriteLock(&avc->lock);
3002 * VIOCNEWCELL (26) - Configure new cell
3007 * the name of the cell, the hosts that will be a part of the cell,
3008 * whether or not it's linked with another cell, the other cell it's
3009 * linked with, the file server port, and the volume server port
3013 * \retval EIO Error if the afs daemon hasn't started yet
3014 * \retval EACCES Error if the user doesn't have super-user cedentials
3015 * \retval EINVAL Error if some 'magic' var doesn't have a certain bit set
3017 * \post creates a new cell
3019 DECL_PIOCTL(PNewCell)
3021 afs_int32 cellHosts[AFS_MAXCELLHOSTS], magic = 0;
3022 char *newcell = NULL;
3023 char *linkedcell = NULL;
3025 afs_int32 linkedstate = 0;
3026 afs_int32 fsport = 0, vlport = 0;
3029 AFS_STATCNT(PNewCell);
3030 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3031 return EIO; /* Inappropriate ioctl for device */
3033 if (!afs_osi_suser(*acred))
3036 if (afs_pd_getInt(ain, &magic) != 0)
3038 if (magic != 0x12345678)
3041 /* A 3.4 fs newcell command will pass an array of AFS_MAXCELLHOSTS
3042 * server addresses while the 3.5 fs newcell command passes
3043 * AFS_MAXHOSTS. To figure out which is which, check if the cellname
3046 * This whole logic is bogus, because it relies on the newer command
3047 * sending its 12th address as 0.
3049 if ((afs_pd_remaining(ain) < AFS_MAXCELLHOSTS +3) * sizeof(afs_int32))
3052 newcell = afs_pd_where(ain) + (AFS_MAXCELLHOSTS + 3) * sizeof(afs_int32);
3053 if (newcell[0] != '\0') {
3056 skip = AFS_MAXHOSTS - AFS_MAXCELLHOSTS;
3059 /* AFS_MAXCELLHOSTS (=8) is less than AFS_MAXHOSTS (=13) */
3060 if (afs_pd_getBytes(ain, &cellHosts,
3061 AFS_MAXCELLHOSTS * sizeof(afs_int32)) != 0)
3063 if (afs_pd_skip(ain, skip * sizeof(afs_int32)) !=0)
3066 if (afs_pd_getInt(ain, &fsport) != 0)
3069 fsport = 0; /* Privileged ports not allowed */
3071 if (afs_pd_getInt(ain, &vlport) != 0)
3074 vlport = 0; /* Privileged ports not allowed */
3076 if (afs_pd_getInt(ain, &ls) != 0)
3079 if (afs_pd_getStringPtr(ain, &newcell) != 0)
3083 if (afs_pd_getStringPtr(ain, &linkedcell) != 0)
3085 linkedstate |= CLinkedCell;
3088 linkedstate |= CNoSUID; /* setuid is disabled by default for fs newcell */
3090 afs_NewCell(newcell, cellHosts, linkedstate, linkedcell, fsport,
3095 DECL_PIOCTL(PNewAlias)
3097 /* create a new cell alias */
3098 char *realName, *aliasName;
3100 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3101 return EIO; /* Inappropriate ioctl for device */
3103 if (!afs_osi_suser(*acred))
3106 if (afs_pd_getStringPtr(ain, &aliasName) != 0)
3108 if (afs_pd_getStringPtr(ain, &realName) != 0)
3111 return afs_NewCellAlias(aliasName, realName);
3115 * VIOCGETCELL (27) - Get cell info
3119 * \param[in] ain The cell index of a specific cell
3120 * \param[out] aout list of servers in the cell
3122 * \retval EIO Error if the afs daemon hasn't started yet
3123 * \retval EDOM Error if there is no cell asked about
3125 * \post Lists the cell's server names and and addresses
3127 DECL_PIOCTL(PListCells)
3129 afs_int32 whichCell;
3130 struct cell *tcell = 0;
3134 AFS_STATCNT(PListCells);
3135 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3136 return EIO; /* Inappropriate ioctl for device */
3138 if (afs_pd_getInt(ain, &whichCell) != 0)
3141 tcell = afs_GetCellByIndex(whichCell, READ_LOCK);
3147 for (i = 0; i < AFS_MAXCELLHOSTS; i++) {
3148 if (tcell->cellHosts[i] == 0)
3150 if (afs_pd_putInt(aout, tcell->cellHosts[i]->addr->sa_ip) != 0)
3153 for (;i < AFS_MAXCELLHOSTS; i++) {
3154 if (afs_pd_putInt(aout, 0) != 0)
3157 if (afs_pd_putString(aout, tcell->cellName) != 0)
3162 afs_PutCell(tcell, READ_LOCK);
3166 DECL_PIOCTL(PListAliases)
3168 afs_int32 whichAlias;
3169 struct cell_alias *tcalias = 0;
3172 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3173 return EIO; /* Inappropriate ioctl for device */
3175 if (afs_pd_getInt(ain, &whichAlias) != 0)
3178 tcalias = afs_GetCellAlias(whichAlias);
3179 if (tcalias == NULL)
3183 if (afs_pd_putString(aout, tcalias->alias) != 0)
3185 if (afs_pd_putString(aout, tcalias->cell) != 0)
3190 afs_PutCellAlias(tcalias);
3195 * VIOC_AFS_DELETE_MT_PT (28) - Delete mount point
3199 * \param[in] ain the name of the file in this dir to remove
3200 * \param[out] aout not in use
3203 * Error if some of the standard args aren't set
3205 * Error if the argument to remove is not a directory
3207 * Error if there is no cache to remove the mount point from or
3208 * if a vcache doesn't exist
3211 * Ensure that everything is OK before deleting the mountpoint.
3212 * If not, don't delete. Delete a mount point based on a file id.
3214 DECL_PIOCTL(PRemoveMount)
3219 struct sysname_info sysState;
3220 afs_size_t offset, len;
3221 struct afs_conn *tc;
3224 struct AFSFetchStatus OutDirStatus;
3225 struct VenusFid tfid;
3226 struct AFSVolSync tsync;
3229 /* "ain" is the name of the file in this dir to remove */
3231 AFS_STATCNT(PRemoveMount);
3234 if (afs_pd_getStringPtr(ain, &name) != 0)
3237 code = afs_VerifyVCache(avc, areq);
3240 if (vType(avc) != VDIR)
3243 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1); /* test for error below */
3246 Check_AtSys(avc, name, &sysState, areq);
3247 ObtainReadLock(&tdc->lock);
3249 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
3250 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
3251 ReleaseReadLock(&tdc->lock);
3252 bufp = sysState.name;
3257 tfid.Cell = avc->f.fid.Cell;
3258 tfid.Fid.Volume = avc->f.fid.Fid.Volume;
3259 if (!tfid.Fid.Unique && (avc->f.states & CForeign)) {
3260 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
3262 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3269 if (tvc->mvstat != 1) {
3275 ObtainWriteLock(&tvc->lock, 230);
3276 code = afs_HandleLink(tvc, areq);
3278 if (tvc->linkData) {
3279 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
3284 ReleaseWriteLock(&tvc->lock);
3285 osi_dnlc_purgedp(tvc);
3291 ObtainWriteLock(&avc->lock, 231);
3292 osi_dnlc_remove(avc, bufp, tvc);
3294 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
3296 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE);
3299 RXAFS_RemoveFile(tc->id, (struct AFSFid *)&avc->f.fid.Fid, bufp,
3300 &OutDirStatus, &tsync);
3305 } while (afs_Analyze
3306 (tc, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_REMOVEFILE,
3307 SHARED_LOCK, NULL));
3312 ReleaseWriteLock(&avc->lock);
3316 /* we have the thing in the cache */
3317 ObtainWriteLock(&tdc->lock, 661);
3318 if (afs_LocalHero(avc, tdc, &OutDirStatus, 1)) {
3319 /* we can do it locally */
3320 code = afs_dir_Delete(tdc, bufp);
3322 ZapDCE(tdc); /* surprise error -- invalid value */
3326 ReleaseWriteLock(&tdc->lock);
3327 afs_PutDCache(tdc); /* drop ref count */
3329 avc->f.states &= ~CUnique; /* For the dfs xlator */
3330 ReleaseWriteLock(&avc->lock);
3333 if (sysState.allocked)
3334 osi_FreeLargeSpace(bufp);
3339 * VIOC_GETCELLSTATUS (35) - Get cell status info
3343 * \param[in] ain The cell you want status information on
3344 * \param[out] aout cell state (as a struct)
3346 * \retval EIO Error if the afs daemon hasn't started yet
3347 * \retval ENOENT Error if the cell doesn't exist
3349 * \post Returns the state of the cell as defined in a struct cell
3351 DECL_PIOCTL(PGetCellStatus)
3357 AFS_STATCNT(PGetCellStatus);
3358 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3359 return EIO; /* Inappropriate ioctl for device */
3361 if (afs_pd_getStringPtr(ain, &cellName) != 0)
3364 tcell = afs_GetCellByName(cellName, READ_LOCK);
3367 temp = tcell->states;
3368 afs_PutCell(tcell, READ_LOCK);
3370 return afs_pd_putInt(aout, temp);
3374 * VIOC_SETCELLSTATUS (36) - Set corresponding info
3379 * The cell you want to set information about, and the values you
3384 * \retval EIO Error if the afs daemon hasn't started yet
3385 * \retval EACCES Error if the user doesn't have super-user credentials
3388 * Set the state of the cell in a defined struct cell, based on
3389 * whether or not SetUID is allowed
3391 DECL_PIOCTL(PSetCellStatus)
3395 afs_int32 flags0, flags1;
3397 if (!afs_osi_suser(*acred))
3399 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3400 return EIO; /* Inappropriate ioctl for device */
3402 if (afs_pd_getInt(ain, &flags0) != 0)
3404 if (afs_pd_getInt(ain, &flags1) != 0)
3406 if (afs_pd_getStringPtr(ain, &cellName) != 0)
3409 tcell = afs_GetCellByName(cellName, WRITE_LOCK);
3412 if (flags0 & CNoSUID)
3413 tcell->states |= CNoSUID;
3415 tcell->states &= ~CNoSUID;
3416 afs_PutCell(tcell, WRITE_LOCK);
3421 * VIOC_FLUSHVOLUME (37) - Flush whole volume's data
3425 * \param[in] ain not in use (args in avc)
3426 * \param[out] aout not in use
3428 * \retval EINVAL Error if some of the standard args aren't set
3429 * \retval EIO Error if the afs daemon hasn't started yet
3432 * Flush all cached contents of a volume. Exactly what stays and what
3433 * goes depends on the platform.
3436 * Does not flush a file that a user has open and is using, because
3437 * it will be re-created on next write. Also purges the dnlc,
3438 * because things are screwed up.
3440 DECL_PIOCTL(PFlushVolumeData)
3446 afs_int32 cell, volume;
3447 struct afs_q *tq, *uq;
3448 #ifdef AFS_DARWIN80_ENV
3452 AFS_STATCNT(PFlushVolumeData);
3455 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3456 return EIO; /* Inappropriate ioctl for device */
3458 volume = avc->f.fid.Fid.Volume; /* who to zap */
3459 cell = avc->f.fid.Cell;
3462 * Clear stat'd flag from all vnodes from this volume; this will
3463 * invalidate all the vcaches associated with the volume.
3466 ObtainReadLock(&afs_xvcache);
3467 i = VCHashV(&avc->f.fid);
3468 for (tq = afs_vhashTV[i].prev; tq != &afs_vhashTV[i]; tq = uq) {
3471 if (tvc->f.fid.Fid.Volume == volume && tvc->f.fid.Cell == cell) {
3472 if (tvc->f.states & CVInit) {
3473 ReleaseReadLock(&afs_xvcache);
3474 afs_osi_Sleep(&tvc->f.states);
3477 #ifdef AFS_DARWIN80_ENV
3478 if (tvc->f.states & CDeadVnode) {
3479 if (!(tvc->f.states & CBulkFetching)) {
3480 ReleaseReadLock(&afs_xvcache);
3481 afs_osi_Sleep(&tvc->f.states);
3488 if (vnode_ref(vp)) {
3494 if (tvc->f.states & (CBulkFetching|CDeadVnode)) {
3496 vnode_recycle(AFSTOV(tvc));
3502 ReleaseReadLock(&afs_xvcache);
3503 #ifdef AFS_BOZONLOCK_ENV
3504 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
3506 ObtainWriteLock(&tvc->lock, 232);
3508 ObtainWriteLock(&afs_xcbhash, 458);
3509 afs_DequeueCallback(tvc);
3510 tvc->f.states &= ~(CStatd | CDirty);
3511 ReleaseWriteLock(&afs_xcbhash);
3512 if (tvc->f.fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
3513 osi_dnlc_purgedp(tvc);
3514 afs_TryToSmush(tvc, *acred, 1);
3515 ReleaseWriteLock(&tvc->lock);
3516 #ifdef AFS_BOZONLOCK_ENV
3517 afs_BozonUnlock(&tvc->pvnLock, tvc);
3519 #ifdef AFS_DARWIN80_ENV
3520 vnode_put(AFSTOV(tvc));
3522 ObtainReadLock(&afs_xvcache);
3524 /* our tvc ptr is still good until now */
3528 ReleaseReadLock(&afs_xvcache);
3531 ObtainWriteLock(&afs_xdcache, 328); /* needed to flush any stuff */
3532 for (i = 0; i < afs_cacheFiles; i++) {
3533 if (!(afs_indexFlags[i] & IFEverUsed))
3534 continue; /* never had any data */
3535 tdc = afs_GetDSlot(i, NULL);
3536 if (tdc->refCount <= 1) { /* too high, in use by running sys call */
3537 ReleaseReadLock(&tdc->tlock);
3538 if (tdc->f.fid.Fid.Volume == volume && tdc->f.fid.Cell == cell) {
3539 if (!(afs_indexFlags[i] & IFDataMod)) {
3540 /* if the file is modified, but has a ref cnt of only 1,
3541 * then someone probably has the file open and is writing
3542 * into it. Better to skip flushing such a file, it will be
3543 * brought back immediately on the next write anyway.
3545 * If we *must* flush, then this code has to be rearranged
3546 * to call afs_storeAllSegments() first */
3547 afs_FlushDCache(tdc);
3551 ReleaseReadLock(&tdc->tlock);
3553 afs_PutDCache(tdc); /* bumped by getdslot */
3555 ReleaseWriteLock(&afs_xdcache);
3557 ObtainReadLock(&afs_xvolume);
3558 for (i = 0; i < NVOLS; i++) {
3559 for (tv = afs_volumes[i]; tv; tv = tv->next) {
3560 if (tv->volume == volume) {
3561 afs_ResetVolumeInfo(tv);
3566 ReleaseReadLock(&afs_xvolume);
3568 /* probably, a user is doing this, probably, because things are screwed up.
3569 * maybe it's the dnlc's fault? */
3576 * VIOCGETVCXSTATUS (41) - gets vnode x status
3581 * not in use (avc used)
3583 * vcxstat: the file id, the data version, any lock, the parent vnode,
3584 * the parent unique id, the trunc position, the callback, cbExpires,
3585 * what access is being made, what files are open,
3586 * any users executing/writing, the flock count, the states,
3590 * Error if some of the initial default arguments aren't set
3592 * Error if access to check the mode bits is denied
3595 * gets stats for the vnode, a struct listed in vcxstat
3597 DECL_PIOCTL(PGetVnodeXStatus)
3600 struct vcxstat stat;
3603 /* AFS_STATCNT(PGetVnodeXStatus); */
3606 code = afs_VerifyVCache(avc, areq);
3609 if (vType(avc) == VDIR)
3610 mode = PRSFS_LOOKUP;
3613 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
3616 memset(&stat, 0, sizeof(struct vcxstat));
3617 stat.fid = avc->f.fid;
3618 hset32(stat.DataVersion, hgetlo(avc->f.m.DataVersion));
3619 stat.lock = avc->lock;
3620 stat.parentVnode = avc->f.parent.vnode;
3621 stat.parentUnique = avc->f.parent.unique;
3622 hset(stat.flushDV, avc->flushDV);
3623 hset(stat.mapDV, avc->mapDV);
3624 stat.truncPos = avc->f.truncPos;
3625 { /* just grab the first two - won't break anything... */
3626 struct axscache *ac;
3628 for (i = 0, ac = avc->Access; ac && i < CPSIZE; i++, ac = ac->next) {
3629 stat.randomUid[i] = ac->uid;
3630 stat.randomAccess[i] = ac->axess;
3633 stat.callback = afs_data_pointer_to_int32(avc->callback);
3634 stat.cbExpires = avc->cbExpires;
3635 stat.anyAccess = avc->f.anyAccess;
3636 stat.opens = avc->opens;
3637 stat.execsOrWriters = avc->execsOrWriters;
3638 stat.flockCount = avc->flockCount;
3639 stat.mvstat = avc->mvstat;
3640 stat.states = avc->f.states;
3641 return afs_pd_putBytes(aout, &stat, sizeof(struct vcxstat));
3645 DECL_PIOCTL(PGetVnodeXStatus2)
3648 struct vcxstat2 stat;
3653 code = afs_VerifyVCache(avc, areq);
3656 if (vType(avc) == VDIR)
3657 mode = PRSFS_LOOKUP;
3660 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
3663 memset(&stat, 0, sizeof(struct vcxstat2));
3665 stat.cbExpires = avc->cbExpires;
3666 stat.anyAccess = avc->f.anyAccess;
3667 stat.mvstat = avc->mvstat;
3668 stat.callerAccess = afs_GetAccessBits(avc, ~0, areq);
3670 return afs_pd_putBytes(aout, &stat, sizeof(struct vcxstat2));
3675 * VIOC_AFS_SYSNAME (38) - Change @sys value
3679 * \param[in] ain new value for @sys
3680 * \param[out] aout count, entry, list (debug values?)
3683 * Error if afsd isn't running, the new sysname is too large,
3684 * the new sysname causes issues (starts with a . or ..),
3685 * there is no PAG set in the credentials, or the user of a PAG
3688 * Error if the user doesn't have super-user credentials
3691 * Set the value of @sys if these things work: if the input isn't
3692 * too long or if input doesn't start with . or ..
3695 * We require root for local sysname changes, but not for remote
3696 * (since we don't really believe remote uids anyway)
3697 * outname[] shouldn't really be needed- this is left as an
3698 * exercise for the reader.
3700 DECL_PIOCTL(PSetSysName)
3702 char *inname = NULL;
3703 char outname[MAXSYSNAME];
3704 afs_int32 setsysname;
3706 struct afs_exporter *exporter;
3707 struct unixuser *au;
3708 afs_int32 pag, error;
3709 int t, count, num = 0, allpags = 0;
3711 struct afs_pdata validate;
3713 AFS_STATCNT(PSetSysName);
3714 if (!afs_globalVFS) {
3715 /* Afsd is NOT running; disable it */
3716 #if defined(KERNEL_HAVE_UERROR)
3717 return (setuerror(EINVAL), EINVAL);
3722 if (afs_pd_getInt(ain, &setsysname) != 0)
3724 if (setsysname & 0x8000) {
3726 setsysname &= ~0x8000;
3731 if (setsysname < 0 || setsysname > MAXNUMSYSNAMES)
3734 for (count = 0; count < setsysname; count++) {
3735 if (afs_pd_getStringPtr(&validate, &inname) != 0)
3738 if (t >= MAXSYSNAME || t <= 0)
3740 /* check for names that can shoot us in the foot */
3741 if (inname[0] == '.' && (inname[1] == 0
3742 || (inname[1] == '.' && inname[2] == 0)))
3745 /* args ok, so go back to the beginning of that section */
3747 if (afs_pd_getStringPtr(ain, &inname) != 0)
3751 if (afs_cr_gid(*acred) == RMTUSER_REQ ||
3752 afs_cr_gid(*acred) == RMTUSER_REQ_PRIV) { /* Handles all exporters */
3753 if (allpags && afs_cr_gid(*acred) != RMTUSER_REQ_PRIV) {
3756 pag = PagInCred(*acred);
3758 return EINVAL; /* Better than panicing */
3760 if (!(au = afs_FindUser(pag, -1, READ_LOCK))) {
3761 return EINVAL; /* Better than panicing */
3763 if (!(exporter = au->exporter)) {
3764 afs_PutUser(au, READ_LOCK);
3765 return EINVAL; /* Better than panicing */
3767 error = EXP_SYSNAME(exporter, inname, &sysnamelist,
3770 if (error == ENODEV)
3771 foundname = 0; /* sysname not set yet! */
3773 afs_PutUser(au, READ_LOCK);
3778 strcpy(outname, sysnamelist[0]);
3780 afs_PutUser(au, READ_LOCK);
3784 /* Not xlating, so local case */
3786 osi_Panic("PSetSysName: !afs_sysname\n");
3787 if (!setsysname) { /* user just wants the info */
3788 strcpy(outname, afs_sysname);
3789 foundname = afs_sysnamecount;
3790 sysnamelist = afs_sysnamelist;
3791 } else { /* Local guy; only root can change sysname */
3792 if (!afs_osi_suser(*acred))
3795 /* allpags makes no sense for local use */
3799 /* clear @sys entries from the dnlc, once afs_lookup can
3800 * do lookups of @sys entries and thinks it can trust them */
3801 /* privs ok, store the entry, ... */
3803 if (strlen(inname) >= MAXSYSNAME-1)
3805 strcpy(afs_sysname, inname);
3807 if (setsysname > 1) { /* ... or list */
3808 for (count = 1; count < setsysname; ++count) {
3809 if (!afs_sysnamelist[count])
3811 ("PSetSysName: no afs_sysnamelist entry to write\n");
3812 if (afs_pd_getString(ain, afs_sysnamelist[count],
3817 afs_sysnamecount = setsysname;
3822 if (afs_pd_putInt(aout, foundname) != 0)
3825 if (afs_pd_putString(aout, outname) != 0)
3827 for (count = 1; count < foundname; ++count) { /* ... or list. */
3828 if (!sysnamelist[count])
3830 ("PSetSysName: no afs_sysnamelist entry to read\n");
3831 t = strlen(sysnamelist[count]);
3832 if (t >= MAXSYSNAME)
3833 osi_Panic("PSetSysName: sysname entry garbled\n");
3834 if (afs_pd_putString(aout, sysnamelist[count]) != 0)
3842 /* sequential search through the list of touched cells is not a good
3843 * long-term solution here. For small n, though, it should be just
3844 * fine. Should consider special-casing the local cell for large n.
3845 * Likewise for PSetSPrefs.
3847 * s - number of ids in array l[] -- NOT index of last id
3848 * l - array of cell ids which have volumes that need to be sorted
3849 * vlonly - sort vl servers or file servers?
3852 ReSortCells_cb(struct cell *cell, void *arg)
3854 afs_int32 *p = (afs_int32 *) arg;
3855 afs_int32 *l = p + 1;
3858 for (i = 0; i < s; i++) {
3859 if (l[i] == cell->cellNum) {
3860 ObtainWriteLock(&cell->lock, 690);
3861 afs_SortServers(cell->cellHosts, AFS_MAXCELLHOSTS);
3862 ReleaseWriteLock(&cell->lock);
3870 ReSortCells(int s, afs_int32 * l, int vlonly)
3878 p = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * (s + 1));
3880 memcpy(p + 1, l, s * sizeof(afs_int32));
3881 afs_TraverseCells(&ReSortCells_cb, p);
3882 afs_osi_Free(p, sizeof(afs_int32) * (s + 1));
3886 ObtainReadLock(&afs_xvolume);
3887 for (i = 0; i < NVOLS; i++) {
3888 for (j = afs_volumes[i]; j; j = j->next) {
3889 for (k = 0; k < s; k++)
3890 if (j->cell == l[k]) {
3891 ObtainWriteLock(&j->lock, 233);
3892 afs_SortServers(j->serverHost, AFS_MAXHOSTS);
3893 ReleaseWriteLock(&j->lock);
3898 ReleaseReadLock(&afs_xvolume);
3902 static int debugsetsp = 0;
3904 afs_setsprefs(struct spref *sp, unsigned int num, unsigned int vlonly)
3907 int i, j, k, matches, touchedSize;
3908 struct server *srvr = NULL;
3909 afs_int32 touched[34];
3913 for (k = 0; k < num; sp++, k++) {
3915 afs_warn("sp host=%x, rank=%d\n", sp->host.s_addr, sp->rank);
3918 ObtainReadLock(&afs_xserver);
3920 i = SHash(sp->host.s_addr);
3921 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3922 if (sa->sa_ip == sp->host.s_addr) {
3924 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
3925 || (sa->sa_portal == AFS_FSPORT);
3926 if ((!vlonly && isfs) || (vlonly && !isfs)) {
3933 if (sa && matches) { /* found one! */
3935 afs_warn("sa ip=%x, ip_rank=%d\n", sa->sa_ip, sa->sa_iprank);
3937 sa->sa_iprank = sp->rank + afs_randomMod15();
3938 afs_SortOneServer(sa->server);
3941 /* if we don't know yet what cell it's in, this is moot */
3942 for (j = touchedSize - 1;
3943 j >= 0 && touched[j] != srvr->cell->cellNum; j--)
3944 /* is it in our list of touched cells ? */ ;
3945 if (j < 0) { /* no, it's not */
3946 touched[touchedSize++] = srvr->cell->cellNum;
3947 if (touchedSize >= 32) { /* watch for ovrflow */
3948 ReleaseReadLock(&afs_xserver);
3949 ReSortCells(touchedSize, touched, vlonly);
3951 ObtainReadLock(&afs_xserver);
3957 ReleaseReadLock(&afs_xserver);
3958 /* if we didn't find one, start to create one. */
3959 /* Note that it doesn't have a cell yet... */
3961 afs_uint32 temp = sp->host.s_addr;
3963 afs_GetServer(&temp, 1, 0, (vlonly ? AFS_VLPORT : AFS_FSPORT),
3964 WRITE_LOCK, (afsUUID *) 0, 0);
3965 srvr->addr->sa_iprank = sp->rank + afs_randomMod15();
3966 afs_PutServer(srvr, WRITE_LOCK);
3968 } /* for all cited preferences */
3970 ReSortCells(touchedSize, touched, vlonly);
3975 * VIOC_SETPREFS (46) - Set server ranks
3977 * \param[in] ain the sprefs value you want the sprefs to be set to
3978 * \param[out] aout not in use
3981 * Error if the afs daemon hasn't started yet
3983 * Error if the user doesn't have super-user credentials
3985 * Error if the struct setsprefs is too large or if it multiplied
3986 * by the number of servers is too large
3988 * \post set the sprefs using the afs_setsprefs() function
3990 DECL_PIOCTL(PSetSPrefs)
3992 struct setspref *ssp;
3996 AFS_STATCNT(PSetSPrefs);
3998 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3999 return EIO; /* Inappropriate ioctl for device */
4001 if (!afs_osi_suser(*acred))
4004 /* The I/O handling here is ghastly, as it relies on overrunning the ends
4005 * of arrays. But, i'm not quite brave enough to change it yet. */
4007 ainSize = ain->remaining;
4009 if (ainSize < sizeof(struct setspref))
4012 ssp = (struct setspref *)ainPtr;
4013 if (ainSize < (sizeof(struct setspref)
4014 + sizeof(struct spref) * ssp->num_servers-1))
4017 afs_setsprefs(&(ssp->servers[0]), ssp->num_servers,
4018 (ssp->flags & DBservers));
4023 * VIOC_SETPREFS33 (42) - Set server ranks (deprecated)
4025 * \param[in] ain the server preferences to be set
4026 * \param[out] aout not in use
4028 * \retval EIO Error if the afs daemon hasn't started yet
4029 * \retval EACCES Error if the user doesn't have super-user credentials
4031 * \post set the server preferences, calling a function
4033 * \notes this may only be performed by the local root user.
4035 DECL_PIOCTL(PSetSPrefs33)
4037 AFS_STATCNT(PSetSPrefs);
4038 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4039 return EIO; /* Inappropriate ioctl for device */
4042 if (!afs_osi_suser(*acred))
4045 afs_setsprefs((struct spref *)afs_pd_where(ain),
4046 afs_pd_remaining(ain) / sizeof(struct spref),
4052 * VIOC_GETSPREFS (43) - Get server ranks
4056 * \param[in] ain the server preferences to get
4057 * \param[out] aout the server preferences information
4059 * \retval EIO Error if the afs daemon hasn't started yet
4060 * \retval ENOENT Error if the sprefrequest is too large
4062 * \post Get the sprefs
4065 * in the hash table of server structs, all servers with the same
4066 * IP address; will be on the same overflow chain; This could be
4067 * sped slightly in some circumstances by having it cache the
4068 * immediately previous slot in the hash table and some
4069 * supporting information; Only reports file servers now.
4071 DECL_PIOCTL(PGetSPrefs)
4073 struct sprefrequest spin; /* input */
4074 struct sprefinfo *spout; /* output */
4075 struct spref *srvout; /* one output component */
4076 int i, j; /* counters for hash table traversal */
4077 struct server *srvr; /* one of CM's server structs */
4079 int vlonly; /* just return vlservers ? */
4082 AFS_STATCNT(PGetSPrefs);
4083 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4084 return EIO; /* Inappropriate ioctl for device */
4086 /* Work out from the size whether we've got a new, or old, style pioctl */
4087 if (afs_pd_remaining(ain) < sizeof(struct sprefrequest)) {
4088 if (afs_pd_getBytes(ain, &spin, sizeof(struct sprefrequest_33)) != 0)
4093 if (afs_pd_getBytes(ain, &spin, sizeof(struct sprefrequest)) != 0)
4095 vlonly = (spin.flags & DBservers);
4098 /* This code relies on overflowing arrays. It's ghastly, but I'm not
4099 * quite brave enough to tackle it yet ...
4102 /* struct sprefinfo includes 1 server struct... that size gets added
4103 * in during the loop that follows.
4105 spout = afs_pd_inline(aout,
4106 sizeof(struct sprefinfo) - sizeof(struct spref));
4107 spout->next_offset = spin.offset;
4108 spout->num_servers = 0;
4109 srvout = spout->servers;
4111 ObtainReadLock(&afs_xserver);
4112 for (i = 0, j = 0; j < NSERVERS; j++) { /* sift through hash table */
4113 for (sa = afs_srvAddrs[j]; sa; sa = sa->next_bkt, i++) {
4114 if (spin.offset > (unsigned short)i) {
4115 continue; /* catch up to where we left off */
4117 spout->next_offset++;
4120 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
4121 || (sa->sa_portal == AFS_FSPORT);
4123 if ((vlonly && isfs) || (!vlonly && !isfs)) {
4124 /* only report ranks for vl servers */
4128 /* Check we've actually got the space we're about to use */
4129 if (afs_pd_inline(aout, sizeof(struct spref)) == NULL) {
4130 ReleaseReadLock(&afs_xserver); /* no more room! */
4134 srvout->host.s_addr = sa->sa_ip;
4135 srvout->rank = sa->sa_iprank;
4136 spout->num_servers++;
4140 ReleaseReadLock(&afs_xserver);
4142 spout->next_offset = 0; /* start over from the beginning next time */
4147 /* Enable/Disable the specified exporter. Must be root to disable an exporter */
4148 int afs_NFSRootOnly = 1;
4150 * VIOC_EXPORTAFS (39) - Export afs to nfs clients
4155 * an integer containing the desired exportee flags
4157 * an integer containing the current exporter flags
4159 * \retval ENODEV Error if the exporter doesn't exist
4160 * \retval EACCES Error if the user doesn't have super-user credentials
4163 * Changes the state of various values to reflect the change
4164 * of the export values between nfs and afs.
4166 * \notes Legacy code obtained from IBM.
4168 DECL_PIOCTL(PExportAfs)
4170 afs_int32 export, newint = 0;
4171 afs_int32 type, changestate, handleValue, convmode, pwsync, smounts;
4172 afs_int32 rempags = 0, pagcb = 0;
4173 struct afs_exporter *exporter;
4175 AFS_STATCNT(PExportAfs);
4176 if (afs_pd_getInt(ain, &handleValue) != 0)
4178 type = handleValue >> 24;
4183 exporter = exporter_find(type);
4185 export = handleValue & 3;
4186 changestate = handleValue & 0xfff;
4187 smounts = (handleValue >> 2) & 3;
4188 pwsync = (handleValue >> 4) & 3;
4189 convmode = (handleValue >> 6) & 3;
4190 rempags = (handleValue >> 8) & 3;
4191 pagcb = (handleValue >> 10) & 3;
4193 changestate = (handleValue >> 16) & 0x1;
4194 convmode = (handleValue >> 16) & 0x2;
4195 pwsync = (handleValue >> 16) & 0x4;
4196 smounts = (handleValue >> 16) & 0x8;
4197 export = handleValue & 0xff;
4200 /* Failed finding desired exporter; */
4204 handleValue = exporter->exp_states;
4205 if (afs_pd_putInt(aout, handleValue) != 0)
4208 if (!afs_osi_suser(*acred))
4209 return EACCES; /* Only superuser can do this */
4213 exporter->exp_states |= EXP_EXPORTED;
4215 exporter->exp_states &= ~EXP_EXPORTED;
4219 exporter->exp_states |= EXP_UNIXMODE;
4221 exporter->exp_states &= ~EXP_UNIXMODE;
4225 exporter->exp_states |= EXP_PWSYNC;
4227 exporter->exp_states &= ~EXP_PWSYNC;
4231 afs_NFSRootOnly = 0;
4232 exporter->exp_states |= EXP_SUBMOUNTS;
4234 afs_NFSRootOnly = 1;
4235 exporter->exp_states &= ~EXP_SUBMOUNTS;
4240 exporter->exp_states |= EXP_CLIPAGS;
4242 exporter->exp_states &= ~EXP_CLIPAGS;
4246 exporter->exp_states |= EXP_CALLBACK;
4248 exporter->exp_states &= ~EXP_CALLBACK;
4250 handleValue = exporter->exp_states;
4251 if (afs_pd_putInt(aout, handleValue) != 0)
4255 exporter->exp_states |= EXP_EXPORTED;
4257 exporter->exp_states &= ~EXP_EXPORTED;
4259 exporter->exp_states |= EXP_UNIXMODE;
4261 exporter->exp_states &= ~EXP_UNIXMODE;
4263 exporter->exp_states |= EXP_PWSYNC;
4265 exporter->exp_states &= ~EXP_PWSYNC;
4267 afs_NFSRootOnly = 0;
4268 exporter->exp_states |= EXP_SUBMOUNTS;
4270 afs_NFSRootOnly = 1;
4271 exporter->exp_states &= ~EXP_SUBMOUNTS;
4280 * VIOC_GAG (44) - Silence Cache Manager
4284 * \param[in] ain the flags to either gag or de-gag the cache manager
4285 * \param[out] aout not in use
4287 * \retval EACCES Error if the user doesn't have super-user credentials
4289 * \post set the gag flags, then show these flags
4293 struct gaginfo *gagflags;
4295 if (!afs_osi_suser(*acred))
4298 gagflags = afs_pd_inline(ain, sizeof(*gagflags));
4299 if (gagflags == NULL)
4301 afs_showflags = gagflags->showflags;
4307 * VIOC_TWIDDLE (45) - Adjust RX knobs
4311 * \param[in] ain the previous settings of the 'knobs'
4312 * \param[out] aout not in use
4314 * \retval EACCES Error if the user doesn't have super-user credentials
4316 * \post build out the struct rxp, from a struct rx
4318 DECL_PIOCTL(PTwiddleRx)
4320 struct rxparams *rxp;
4322 if (!afs_osi_suser(*acred))
4325 rxp = afs_pd_inline(ain, sizeof(*rxp));
4329 if (rxp->rx_initReceiveWindow)
4330 rx_initReceiveWindow = rxp->rx_initReceiveWindow;
4331 if (rxp->rx_maxReceiveWindow)
4332 rx_maxReceiveWindow = rxp->rx_maxReceiveWindow;
4333 if (rxp->rx_initSendWindow)
4334 rx_initSendWindow = rxp->rx_initSendWindow;
4335 if (rxp->rx_maxSendWindow)
4336 rx_maxSendWindow = rxp->rx_maxSendWindow;
4337 if (rxp->rxi_nSendFrags)
4338 rxi_nSendFrags = rxp->rxi_nSendFrags;
4339 if (rxp->rxi_nRecvFrags)
4340 rxi_nRecvFrags = rxp->rxi_nRecvFrags;
4341 if (rxp->rxi_OrphanFragSize)
4342 rxi_OrphanFragSize = rxp->rxi_OrphanFragSize;
4343 if (rxp->rx_maxReceiveSize) {
4344 rx_maxReceiveSize = rxp->rx_maxReceiveSize;
4345 rx_maxReceiveSizeUser = rxp->rx_maxReceiveSize;
4347 if (rxp->rx_MyMaxSendSize)
4348 rx_MyMaxSendSize = rxp->rx_MyMaxSendSize;
4354 * VIOC_GETINITPARAMS (49) - Get initial cache manager parameters
4358 * \param[in] ain not in use
4359 * \param[out] aout initial cache manager params
4362 * Error if the initial parameters are bigger than some PIGGYSIZE
4364 * \post return the initial cache manager parameters
4366 DECL_PIOCTL(PGetInitParams)
4368 if (sizeof(struct cm_initparams) > PIGGYSIZE)
4371 return afs_pd_putBytes(aout, &cm_initParams,
4372 sizeof(struct cm_initparams));
4376 #ifdef AFS_SGI65_ENV
4377 /* They took crget() from us, so fake it. */
4382 cr = crdup(get_current_cred());
4383 memset(cr, 0, sizeof(cred_t));
4384 #if CELL || CELL_PREPARE
4392 * VIOC_GETRXKCRYPT (55) - Get rxkad encryption flag
4396 * \param[in] ain not in use
4397 * \param[out] aout value of cryptall
4399 * \post Turns on, or disables, rxkad encryption by setting the cryptall global
4401 DECL_PIOCTL(PGetRxkcrypt)
4403 return afs_pd_putInt(aout, cryptall);
4407 * VIOC_SETRXKCRYPT (56) - Set rxkad encryption flag
4411 * \param[in] ain the argument whether or not things should be encrypted
4412 * \param[out] aout not in use
4415 * Error if the user doesn't have super-user credentials
4417 * Error if the input is too big, or if the input is outside the
4418 * bounds of what it can be set to
4420 * \post set whether or not things should be encrypted
4423 * may need to be modified at a later date to take into account
4424 * other values for cryptall (beyond true or false)
4426 DECL_PIOCTL(PSetRxkcrypt)
4430 if (!afs_osi_suser(*acred))
4432 if (afs_pd_getInt(ain, &tmpval) != 0)
4434 /* if new mappings added later this will need to be changed */
4435 if (tmpval != 0 && tmpval != 1)
4441 #ifdef AFS_NEED_CLIENTCONTEXT
4443 * Create new credentials to correspond to a remote user with given
4444 * <hostaddr, uid, g0, g1>. This allows a server running as root to
4445 * provide pioctl (and other) services to foreign clients (i.e. nfs
4446 * clients) by using this call to `become' the client.
4449 #define PIOCTL_HEADER 6
4451 HandleClientContext(struct afs_ioctl *ablob, int *com,
4452 afs_ucred_t **acred, afs_ucred_t *credp)
4455 afs_uint32 hostaddr;
4456 afs_int32 uid, g0, g1, i, code, pag, exporter_type, isroot = 0;
4457 struct afs_exporter *exporter, *outexporter;
4458 afs_ucred_t *newcred;
4459 struct unixuser *au;
4460 afs_uint32 comp = *com & 0xff00;
4462 #if defined(AFS_SUN510_ENV)
4466 #if defined(AFS_SGIMP_ENV)
4467 osi_Assert(ISAFS_GLOCK());
4469 AFS_STATCNT(HandleClientContext);
4470 if (ablob->in_size < PIOCTL_HEADER * sizeof(afs_int32)) {
4471 /* Must at least include the PIOCTL_HEADER header words
4472 * required by the protocol */
4473 return EINVAL; /* Too small to be good */
4475 ain = inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
4476 AFS_COPYIN(ablob->in, ain, PIOCTL_HEADER * sizeof(afs_int32), code);
4478 osi_FreeLargeSpace(inData);
4482 /* Extract information for remote user */
4483 hostaddr = *((afs_uint32 *) ain);
4484 ain += sizeof(hostaddr);
4485 uid = *((afs_uint32 *) ain);
4487 g0 = *((afs_uint32 *) ain);
4489 g1 = *((afs_uint32 *) ain);
4491 *com = *((afs_uint32 *) ain);
4492 ain += sizeof(afs_int32);
4493 exporter_type = *((afs_uint32 *) ain);/* In case we support more than NFS */
4496 * Of course, one must be root for most of these functions, but
4497 * we'll allow (for knfs) you to set things if the pag is 0 and
4498 * you're setting tokens or unlogging.
4501 if (!afs_osi_suser(credp)) {
4502 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
4503 /* Since SGI's suser() returns explicit failure after the call.. */
4506 /* check for acceptable opcodes for normal folks, which are, so far,
4507 * get/set tokens, sysname, and unlog.
4509 if (i != 9 && i != 3 && i != 38 && i != 8) {
4510 osi_FreeLargeSpace(inData);
4515 ablob->in_size -= PIOCTL_HEADER * sizeof(afs_int32);
4516 ablob->in += PIOCTL_HEADER * sizeof(afs_int32);
4517 osi_FreeLargeSpace(inData);
4520 * We map uid 0 to nobody to match the mapping that the nfs
4521 * server does and to ensure that the suser() calls in the afs
4522 * code fails for remote client roots.
4524 uid = afs_nobody; /* NFS_NOBODY == -2 */
4528 #ifdef AFS_AIX41_ENV
4531 afs_set_cr_gid(newcred, isroot ? RMTUSER_REQ_PRIV : RMTUSER_REQ);
4532 #ifdef AFS_AIX51_ENV
4533 newcred->cr_groupset.gs_union.un_groups[0] = g0;
4534 newcred->cr_groupset.gs_union.un_groups[1] = g1;
4535 #elif defined(AFS_LINUX26_ENV)
4536 # ifdef AFS_LINUX26_ONEGROUP_ENV
4537 afs_set_cr_group_info(newcred, groups_alloc(1)); /* nothing sets this */
4538 l = (((g0-0x3f00) & 0x3fff) << 14) | ((g1-0x3f00) & 0x3fff);
4539 h = ((g0-0x3f00) >> 14);
4540 h = ((g1-0x3f00) >> 14) + h + h + h;
4541 GROUP_AT(afs_cr_group_info(newcred), 0) = ((h << 28) | l);
4543 afs_set_cr_group_info(newcred, groups_alloc(2));
4544 GROUP_AT(afs_cr_group_info(newcred), 0) = g0;
4545 GROUP_AT(afs_cr_group_info(newcred), 1) = g1;
4547 #elif defined(AFS_SUN510_ENV)
4550 crsetgroups(newcred, 2, gids);
4552 newcred->cr_groups[0] = g0;
4553 newcred->cr_groups[1] = g1;
4556 newcred->cr_ngrps = 2;
4557 #elif !defined(AFS_LINUX26_ENV) && !defined(AFS_SUN510_ENV)
4558 # if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_FBSD80_ENV)
4559 newcred->cr_ngroups = 2;
4561 for (i = 2; i < NGROUPS; i++)
4562 newcred->cr_groups[i] = NOGROUP;
4565 if (!(exporter = exporter_find(exporter_type))) {
4566 /* Exporter wasn't initialized or an invalid exporter type */
4570 if (exporter->exp_states & EXP_PWSYNC) {
4571 if (uid != afs_cr_uid(credp)) {
4573 return ENOEXEC; /* XXX Find a better errno XXX */
4576 afs_set_cr_uid(newcred, uid); /* Only temporary */
4577 code = EXP_REQHANDLER(exporter, &newcred, hostaddr, &pag, &outexporter);
4578 /* The client's pag is the only unique identifier for it */
4579 afs_set_cr_uid(newcred, pag);
4581 if (!code && *com == PSETPAG) {
4582 /* Special case for 'setpag' */
4583 afs_uint32 pagvalue = genpag();
4585 au = afs_GetUser(pagvalue, -1, WRITE_LOCK); /* a new unixuser struct */
4587 * Note that we leave the 'outexporter' struct held so it won't
4590 au->exporter = outexporter;
4591 if (ablob->out_size >= 4) {
4592 AFS_COPYOUT((char *)&pagvalue, ablob->out, sizeof(afs_int32),
4595 afs_PutUser(au, WRITE_LOCK);
4598 return PSETPAG; /* Special return for setpag */
4600 EXP_RELE(outexporter);
4603 *com = (*com) | comp;
4606 #endif /* AFS_NEED_CLIENTCONTEXT */
4610 * VIOC_GETCPREFS (50) - Get client interface
4614 * \param[in] ain sprefrequest input
4615 * \param[out] aout spref information
4617 * \retval EIO Error if the afs daemon hasn't started yet
4618 * \retval EINVAL Error if some of the standard args aren't set
4621 * get all interface addresses and other information of the client
4624 DECL_PIOCTL(PGetCPrefs)
4626 struct sprefrequest *spin; /* input */
4627 struct sprefinfo *spout; /* output */
4628 struct spref *srvout; /* one output component */
4632 AFS_STATCNT(PGetCPrefs);
4633 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4634 return EIO; /* Inappropriate ioctl for device */
4636 spin = afs_pd_inline(ain, sizeof(*spin));
4640 /* Output spout relies on writing past the end of arrays. It's horrible,
4641 * but I'm not quite brave enough to tackle it yet */
4642 spout = (struct sprefinfo *)aout->ptr;
4644 maxNumber = spin->num_servers; /* max addrs this time */
4645 srvout = spout->servers;
4647 ObtainReadLock(&afs_xinterface);
4649 /* copy out the client interface information from the
4650 * kernel data structure "interface" to the output buffer
4652 for (i = spin->offset, j = 0; (i < afs_cb_interface.numberOfInterfaces)
4653 && (j < maxNumber); i++, j++, srvout++)
4654 srvout->host.s_addr = afs_cb_interface.addr_in[i];
4656 spout->num_servers = j;
4657 aout->ptr += sizeof(struct sprefinfo) + (j - 1) * sizeof(struct spref);
4659 if (i >= afs_cb_interface.numberOfInterfaces)
4660 spout->next_offset = 0; /* start from beginning again */
4662 spout->next_offset = spin->offset + j;
4664 ReleaseReadLock(&afs_xinterface);
4669 * VIOC_SETCPREFS (51) - Set client interface
4673 * \param[in] ain the interfaces you want set
4674 * \param[out] aout not in use
4676 * \retval EIO Error if the afs daemon hasn't started yet
4677 * \retval EINVAL Error if the input is too large for the struct
4678 * \retval ENOMEM Error if there are too many servers
4680 * \post set the callbak interfaces addresses to those of the hosts
4682 DECL_PIOCTL(PSetCPrefs)
4686 struct setspref *sin;
4689 AFS_STATCNT(PSetCPrefs);
4690 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4691 return EIO; /* Inappropriate ioctl for device */
4693 /* Yuck. Input to this function relies on reading past the end of
4694 * structures. Bodge it for now.
4697 ainSize = ain->remaining;
4699 sin = (struct setspref *)ainPtr;
4701 if (ainSize < sizeof(struct setspref))
4703 #if 0 /* num_servers is unsigned */
4704 if (sin->num_servers < 0)
4707 if (sin->num_servers > AFS_MAX_INTERFACE_ADDR)
4710 ObtainWriteLock(&afs_xinterface, 412);
4711 afs_cb_interface.numberOfInterfaces = sin->num_servers;
4712 for (i = 0; (unsigned short)i < sin->num_servers; i++)
4713 afs_cb_interface.addr_in[i] = sin->servers[i].host.s_addr;
4715 ReleaseWriteLock(&afs_xinterface);
4720 * VIOC_AFS_FLUSHMOUNT (52) - Flush mount symlink data
4725 * the last part of a path to a mount point, which tells us what to flush
4730 * Error if some of the initial arguments aren't set
4732 * Error if the initial argument for the mount point isn't a directory
4734 * Error if the dcache entry isn't set
4737 * remove all of the mount data from the dcache regarding a
4738 * certain mount point
4740 DECL_PIOCTL(PFlushMount)
4745 struct VenusFid tfid;
4748 struct sysname_info sysState;
4749 afs_size_t offset, len;
4751 AFS_STATCNT(PFlushMount);
4755 if (afs_pd_getStringPtr(ain, &mount) != 0)
4758 code = afs_VerifyVCache(avc, areq);
4761 if (vType(avc) != VDIR) {
4764 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
4767 Check_AtSys(avc, mount, &sysState, areq);
4768 ObtainReadLock(&tdc->lock);
4770 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
4771 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
4772 ReleaseReadLock(&tdc->lock);
4773 afs_PutDCache(tdc); /* we're done with the data */
4774 bufp = sysState.name;
4778 tfid.Cell = avc->f.fid.Cell;
4779 tfid.Fid.Volume = avc->f.fid.Fid.Volume;
4780 if (!tfid.Fid.Unique && (avc->f.states & CForeign)) {
4781 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
4783 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
4789 if (tvc->mvstat != 1) {
4794 #ifdef AFS_BOZONLOCK_ENV
4795 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
4797 ObtainWriteLock(&tvc->lock, 649);
4798 ObtainWriteLock(&afs_xcbhash, 650);
4799 afs_DequeueCallback(tvc);
4800 tvc->f.states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
4801 ReleaseWriteLock(&afs_xcbhash);
4802 /* now find the disk cache entries */
4803 afs_TryToSmush(tvc, *acred, 1);
4804 osi_dnlc_purgedp(tvc);
4805 if (tvc->linkData && !(tvc->f.states & CCore)) {
4806 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
4807 tvc->linkData = NULL;
4809 ReleaseWriteLock(&tvc->lock);
4810 #ifdef AFS_BOZONLOCK_ENV
4811 afs_BozonUnlock(&tvc->pvnLock, tvc);
4815 if (sysState.allocked)
4816 osi_FreeLargeSpace(bufp);
4821 * VIOC_RXSTAT_PROC (53) - Control process RX statistics
4825 * \param[in] ain the flags that control which stats to use
4826 * \param[out] aout not in use
4828 * \retval EACCES Error if the user doesn't have super-user credentials
4829 * \retval EINVAL Error if the flag input is too long
4832 * either enable process RPCStats, disable process RPCStats,
4833 * or clear the process RPCStats
4835 DECL_PIOCTL(PRxStatProc)
4839 if (!afs_osi_suser(*acred))
4842 if (afs_pd_getInt(ain, &flags) != 0)
4845 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK))
4848 if (flags & AFSCALL_RXSTATS_ENABLE) {
4849 rx_enableProcessRPCStats();
4851 if (flags & AFSCALL_RXSTATS_DISABLE) {
4852 rx_disableProcessRPCStats();
4854 if (flags & AFSCALL_RXSTATS_CLEAR) {
4855 rx_clearProcessRPCStats(AFS_RX_STATS_CLEAR_ALL);
4862 * VIOC_RXSTAT_PEER (54) - Control peer RX statistics
4866 * \param[in] ain the flags that control which statistics to use
4867 * \param[out] aout not in use
4869 * \retval EACCES Error if the user doesn't have super-user credentials
4870 * \retval EINVAL Error if the flag input is too long
4873 * either enable peer RPCStatws, disable peer RPCStats,
4874 * or clear the peer RPCStats
4876 DECL_PIOCTL(PRxStatPeer)
4880 if (!afs_osi_suser(*acred))
4883 if (afs_pd_getInt(ain, &flags) != 0)
4886 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK))
4889 if (flags & AFSCALL_RXSTATS_ENABLE) {
4890 rx_enablePeerRPCStats();
4892 if (flags & AFSCALL_RXSTATS_DISABLE) {
4893 rx_disablePeerRPCStats();
4895 if (flags & AFSCALL_RXSTATS_CLEAR) {
4896 rx_clearPeerRPCStats(AFS_RX_STATS_CLEAR_ALL);
4901 DECL_PIOCTL(PPrefetchFromTape)
4903 afs_int32 code, code1;
4904 afs_int32 bytes, outval;
4905 struct afs_conn *tc;
4906 struct rx_call *tcall;
4907 struct AFSVolSync tsync;
4908 struct AFSFetchStatus OutStatus;
4909 struct AFSCallBack CallBack;
4910 struct VenusFid tfid;
4914 AFS_STATCNT(PSetAcl);
4918 Fid = afs_pd_inline(ain, sizeof(struct AFSFid));
4920 Fid = &avc->f.fid.Fid;
4922 tfid.Cell = avc->f.fid.Cell;
4923 tfid.Fid.Volume = Fid->Volume;
4924 tfid.Fid.Vnode = Fid->Vnode;
4925 tfid.Fid.Unique = Fid->Unique;
4927 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
4929 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
4930 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &avc->f.fid);
4933 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
4934 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &tvc->f.fid);
4937 tc = afs_Conn(&tvc->f.fid, areq, SHARED_LOCK);
4941 tcall = rx_NewCall(tc->id);
4943 StartRXAFS_FetchData(tcall, (struct AFSFid *)&tvc->f.fid.Fid, 0,
4946 bytes = rx_Read(tcall, (char *)&outval, sizeof(afs_int32));
4948 EndRXAFS_FetchData(tcall, &OutStatus, &CallBack, &tsync);
4950 code1 = rx_EndCall(tcall, code);
4954 } while (afs_Analyze
4955 (tc, code, &tvc->f.fid, areq, AFS_STATS_FS_RPCIDX_RESIDENCYRPCS,
4956 SHARED_LOCK, NULL));
4957 /* This call is done only to have the callback things handled correctly */
4958 afs_FetchStatus(tvc, &tfid, areq, &OutStatus);
4964 return afs_pd_putInt(aout, outval);
4970 struct afs_conn *tc;
4972 struct FsCmdInputs *Inputs;
4973 struct FsCmdOutputs *Outputs;
4974 struct VenusFid tfid;
4980 Inputs = afs_pd_inline(ain, sizeof(*Inputs));
4984 Outputs = afs_pd_inline(aout, sizeof(*Outputs));
4985 if (Outputs == NULL)
4990 Fid = &avc->f.fid.Fid;
4992 tfid.Cell = avc->f.fid.Cell;
4993 tfid.Fid.Volume = Fid->Volume;
4994 tfid.Fid.Vnode = Fid->Vnode;
4995 tfid.Fid.Unique = Fid->Unique;
4997 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
4998 afs_Trace3(afs_iclSetp, CM_TRACE_RESIDCMD, ICL_TYPE_POINTER, tvc,
4999 ICL_TYPE_INT32, Inputs->command, ICL_TYPE_FID, &tfid);
5003 if (Inputs->command) {
5005 tc = afs_Conn(&tvc->f.fid, areq, SHARED_LOCK);
5009 RXAFS_FsCmd(tc->id, Fid, Inputs,
5010 (struct FsCmdOutputs *)aout);
5014 } while (afs_Analyze
5015 (tc, code, &tvc->f.fid, areq,
5016 AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK, NULL));
5017 /* This call is done to have the callback things handled correctly */
5018 afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
5019 } else { /* just a status request, return also link data */
5021 Outputs->code = afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
5022 Outputs->chars[0] = 0;
5023 if (vType(tvc) == VLNK) {
5024 ObtainWriteLock(&tvc->lock, 555);
5025 if (afs_HandleLink(tvc, areq) == 0)
5026 strncpy((char *)&Outputs->chars, tvc->linkData, MAXCMDCHARS);
5027 ReleaseWriteLock(&tvc->lock);
5036 DECL_PIOCTL(PNewUuid)
5038 /*AFS_STATCNT(PNewUuid); */
5039 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
5040 return EIO; /* Inappropriate ioctl for device */
5042 if (!afs_osi_suser(*acred))
5045 ObtainWriteLock(&afs_xinterface, 555);
5046 afs_uuid_create(&afs_cb_interface.uuid);
5047 ReleaseWriteLock(&afs_xinterface);
5048 ForceAllNewConnections();
5052 #if defined(AFS_CACHE_BYPASS)
5054 DECL_PIOCTL(PSetCachingThreshold)
5056 afs_int32 getting = 1;
5057 afs_int32 setting = 1;
5058 afs_int32 threshold = AFS_CACHE_BYPASS_DISABLED;
5060 if (afs_pd_getInt(ain, &threshold) != 0)
5066 if (setting == 0 && getting == 0)
5070 * If setting, set first, and return the value now in effect
5073 if (!afs_osi_suser(*acred))
5075 cache_bypass_threshold = threshold;
5076 afs_warn("Cache Bypass Threshold set to: %d\n", threshold);
5077 /* TODO: move to separate pioctl, or enhance pioctl */
5078 cache_bypass_strategy = LARGE_FILES_BYPASS_CACHE;
5081 /* Return the current size threshold */
5083 return afs_pd_putInt(aout, cache_bypass_threshold);
5088 #endif /* defined(AFS_CACHE_BYPASS) */
5090 DECL_PIOCTL(PCallBackAddr)
5093 afs_uint32 addr, code;
5097 struct afs_conn *tc;
5099 struct unixuser *tu;
5100 struct srvAddr **addrs;
5102 /*AFS_STATCNT(PCallBackAddr); */
5103 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
5104 return EIO; /* Inappropriate ioctl for device */
5106 if (!afs_osi_suser(acred))
5109 if (afs_pd_getInt(ain, &addr) != 0)
5112 ObtainReadLock(&afs_xinterface);
5113 for (i = 0; (unsigned short)i < afs_cb_interface.numberOfInterfaces; i++) {
5114 if (afs_cb_interface.addr_in[i] == addr)
5118 ReleaseWriteLock(&afs_xinterface);
5120 if (afs_cb_interface.addr_in[i] != addr)
5123 ObtainReadLock(&afs_xserver); /* Necessary? */
5124 ObtainReadLock(&afs_xsrvAddr);
5127 for (i = 0; i < NSERVERS; i++) {
5128 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
5133 addrs = afs_osi_Alloc(srvAddrCount * sizeof(*addrs));
5135 for (i = 0; i < NSERVERS; i++) {
5136 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
5137 if (j >= srvAddrCount)
5143 ReleaseReadLock(&afs_xsrvAddr);
5144 ReleaseReadLock(&afs_xserver);
5146 for (i = 0; i < j; i++) {
5152 /* vlserver has no callback conn */
5153 if (sa->sa_portal == AFS_VLPORT) {
5157 if (!ts->cell) /* not really an active server, anyway, it must */
5158 continue; /* have just been added by setsprefs */
5160 /* get a connection, even if host is down; bumps conn ref count */
5161 tu = afs_GetUser(areq->uid, ts->cell->cellNum, SHARED_LOCK);
5162 tc = afs_ConnBySA(sa, ts->cell->fsport, ts->cell->cellNum, tu,
5163 1 /*force */ , 1 /*create */ , SHARED_LOCK);
5164 afs_PutUser(tu, SHARED_LOCK);
5168 if ((sa->sa_flags & SRVADDR_ISDOWN) || afs_HaveCallBacksFrom(ts)) {
5169 if (sa->sa_flags & SRVADDR_ISDOWN) {
5170 rx_SetConnDeadTime(tc->id, 3);
5172 #ifdef RX_ENABLE_LOCKS
5174 #endif /* RX_ENABLE_LOCKS */
5175 code = RXAFS_CallBackRxConnAddr(tc->id, &addr);
5176 #ifdef RX_ENABLE_LOCKS
5178 #endif /* RX_ENABLE_LOCKS */
5180 afs_PutConn(tc, SHARED_LOCK); /* done with it now */
5181 } /* Outer loop over addrs */
5182 #endif /* UKERNEL */
5186 DECL_PIOCTL(PDiscon)
5188 static afs_int32 mode = 1; /* Start up in 'off' */
5189 afs_int32 force = 0;
5192 struct vrequest lreq;
5194 if (afs_pd_getBytes(ain, &flags, 4) == 0) {
5195 if (!afs_osi_suser(*acred))
5199 mode = flags[0] - 1;
5201 afs_ConflictPolicy = flags[1] - 1;
5205 /* Fake InitReq support for UID override */
5206 memset(&lreq, 0, sizeof(lreq));
5207 lreq.uid = flags[3];
5208 areq = &lreq; /* override areq we got */
5212 * All of these numbers are hard coded in fs.c. If they
5213 * change here, they should change there and vice versa
5216 case 0: /* Disconnect ("offline" mode), breaking all callbacks */
5217 if (!AFS_IS_DISCONNECTED) {
5218 ObtainWriteLock(&afs_discon_lock, 999);
5219 afs_DisconGiveUpCallbacks();
5220 afs_RemoveAllConns();
5221 afs_is_disconnected = 1;
5222 afs_is_discon_rw = 1;
5223 ReleaseWriteLock(&afs_discon_lock);
5226 case 1: /* Fully connected, ("online" mode). */
5227 ObtainWriteLock(&afs_discon_lock, 998);
5230 afs_MarkAllServersUp();
5231 code = afs_ResyncDisconFiles(areq, *acred);
5234 if (code && !force) {
5235 afs_warnuser("Files not synchronized properly, still in discon state. \n"
5236 "Please retry or use \"force\".\n");
5240 afs_DisconDiscardAll(*acred);
5242 afs_ClearAllStatdFlag();
5243 afs_is_disconnected = 0;
5244 afs_is_discon_rw = 0;
5245 afs_warnuser("\nSync succeeded. You are back online.\n");
5248 ReleaseWriteLock(&afs_discon_lock);
5260 return afs_pd_putInt(aout, mode);
5263 #define MAX_PIOCTL_TOKENS 10
5265 DECL_PIOCTL(PSetTokens2)
5268 int i, cellNum, primaryFlag;
5270 struct unixuser *tu;
5271 struct vrequest treq;
5272 struct ktc_setTokenData tokenSet;
5273 struct ktc_tokenUnion decodedToken;
5275 memset(&tokenSet, 0, sizeof(tokenSet));
5277 AFS_STATCNT(PSetTokens2);
5278 if (!afs_resourceinit_flag)
5281 afs_pd_xdrStart(ain, &xdrs, XDR_DECODE);
5283 if (!xdr_ktc_setTokenData(&xdrs, &tokenSet)) {
5284 afs_pd_xdrEnd(ain, &xdrs);
5288 afs_pd_xdrEnd(ain, &xdrs);
5290 /* We limit each PAG to 10 tokens to prevent a malicous (or runaway)
5291 * process from using up the whole of the kernel memory by allocating
5294 if (tokenSet.tokens.tokens_len > MAX_PIOCTL_TOKENS) {
5295 xdr_free((xdrproc_t) xdr_ktc_setTokenData, &tokenSet);
5299 code = _settok_tokenCell(tokenSet.cell, &cellNum, &primaryFlag);
5301 xdr_free((xdrproc_t) xdr_ktc_setTokenData, &tokenSet);
5305 if (tokenSet.flags & AFSTOKEN_EX_SETPAG) {
5306 if (_settok_setParentPag(acred) == 0) {
5307 afs_InitReq(&treq, *acred);
5312 tu = afs_GetUser(areq->uid, cellNum, WRITE_LOCK);
5313 /* Free any tokens that we've already got */
5314 afs_FreeTokens(&tu->tokens);
5316 /* Iterate across the set of tokens we've received, and stuff them
5317 * into this user's tokenJar
5319 for (i=0; i < tokenSet.tokens.tokens_len; i++) {
5320 xdrmem_create(&xdrs,
5321 tokenSet.tokens.tokens_val[i].token_opaque_val,
5322 tokenSet.tokens.tokens_val[i].token_opaque_len,
5325 memset(&decodedToken, 0, sizeof(decodedToken));
5326 if (!xdr_ktc_tokenUnion(&xdrs, &decodedToken)) {
5334 afs_AddTokenFromPioctl(&tu->tokens, &decodedToken);
5335 /* This is untidy - the old token interface supported passing
5336 * the primaryFlag as part of the token interface. Current
5337 * OpenAFS userland never sets this, but it's specified as being
5338 * part of the XG interface, so we should probably still support
5339 * it. Rather than add it to our AddToken interface, just handle
5342 if (decodedToken.at_type == AFSTOKEN_UNION_KAD) {
5343 if (decodedToken.ktc_tokenUnion_u.at_kad.rk_primary_flag)
5347 /* XXX - We should think more about destruction here. It's likely that
5348 * there is key material in what we're about to throw away, which
5349 * we really should zero out before giving back to the allocator */
5350 xdr_free((xdrproc_t) xdr_ktc_tokenUnion, &decodedToken);
5353 tu->states |= UHasTokens;
5354 tu->states &= ~UTokensBad;
5355 afs_SetPrimary(tu, primaryFlag);
5356 tu->tokenTime = osi_Time();
5358 xdr_free((xdrproc_t) xdr_ktc_setTokenData, &tokenSet);
5361 afs_ResetUserConns(tu);
5362 afs_PutUser(tu, WRITE_LOCK);
5367 DECL_PIOCTL(PGetTokens2)
5370 struct unixuser *tu = NULL;
5372 char *cellName = NULL;
5377 struct ktc_setTokenData tokenSet;
5379 AFS_STATCNT(PGetTokens);
5380 if (!afs_resourceinit_flag)
5383 memset(&tokenSet, 0, sizeof(tokenSet));
5385 /* No input data - return tokens for primary cell */
5386 /* 4 octets of data is an iterator count */
5387 /* Otherwise, treat as string & return tokens for that cell name */
5389 if (afs_pd_remaining(ain) == sizeof(afs_int32)) {
5390 /* Integer iterator - return tokens for the n'th cell found for user */
5391 if (afs_pd_getInt(ain, &iterator) != 0)
5393 tu = getNthCell(areq->uid, iterator);
5395 if (afs_pd_remaining(ain) > 0) {
5396 if (afs_pd_getStringPtr(ain, &cellName) != 0)
5401 code = _settok_tokenCell(cellName, &cellNum, NULL);
5404 tu = afs_FindUser(areq->uid, cellNum, READ_LOCK);
5411 if (!(tu->states & UHasTokens)
5412 || !afs_HasValidTokens(tu->tokens, now)) {
5413 tu->states |= (UTokensBad | UNeedsReset);
5414 afs_PutUser(tu, READ_LOCK);
5418 code = afs_ExtractTokensForPioctl(tu->tokens, now, &tokenSet);
5422 cell = afs_GetCell(tu->cell, READ_LOCK);
5423 tokenSet.cell = cell->cellName;
5424 afs_pd_xdrStart(aout, &xdrs, XDR_ENCODE);
5425 if (!xdr_ktc_setTokenData(&xdrs, &tokenSet)) {
5429 afs_pd_xdrEnd(aout, &xdrs);
5432 tokenSet.cell = NULL;
5435 afs_PutUser(tu, READ_LOCK);
5437 afs_PutCell(cell, READ_LOCK);
5438 xdr_free((xdrproc_t)xdr_ktc_setTokenData, &tokenSet);
5443 DECL_PIOCTL(PNFSNukeCreds)
5447 struct unixuser *tu;
5449 AFS_STATCNT(PUnlog);
5450 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
5451 return EIO; /* Inappropriate ioctl for device */
5453 if (afs_pd_getUint(ain, &addr) != 0)
5456 if (afs_cr_gid(*acred) == RMTUSER_REQ_PRIV && !addr) {
5457 tu = afs_GetUser(areq->uid, -1, SHARED_LOCK);
5458 if (!tu->exporter || !(addr = EXP_GETHOST(tu->exporter))) {
5459 afs_PutUser(tu, SHARED_LOCK);
5462 afs_PutUser(tu, SHARED_LOCK);
5463 } else if (!afs_osi_suser(acred)) {
5467 ObtainWriteLock(&afs_xuser, 227);
5468 for (i = 0; i < NUSERS; i++) {
5469 for (tu = afs_users[i]; tu; tu = tu->next) {
5470 if (tu->exporter && EXP_CHECKHOST(tu->exporter, addr)) {
5471 tu->states &= ~UHasTokens;
5472 afs_FreeTokens(&tu->tokens);
5474 ReleaseWriteLock(&afs_xuser);
5475 afs_ResetUserConns(tu);
5477 ObtainWriteLock(&afs_xuser, 228);
5479 /* set the expire times to 0, causes
5480 * afs_GCUserData to remove this entry
5483 #endif /* UKERNEL */
5487 ReleaseWriteLock(&afs_xuser);