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_getBytes(struct afs_pdata *apd, void *dest, size_t bytes)
112 if (apd == NULL || apd->remaining < bytes)
114 apd->remaining -= bytes;
115 memcpy(dest, apd->ptr, bytes);
121 afs_pd_getInt(struct afs_pdata *apd, afs_int32 *val)
123 return afs_pd_getBytes(apd, val, sizeof(*val));
127 afs_pd_getUint(struct afs_pdata *apd, afs_uint32 *val)
129 return afs_pd_getBytes(apd, val, sizeof(*val));
133 afs_pd_inline(struct afs_pdata *apd, size_t bytes)
137 if (apd == NULL || apd->remaining < bytes)
142 apd->remaining -= bytes;
149 afs_pd_xdrStart(struct afs_pdata *apd, XDR *xdrs, enum xdr_op op) {
150 xdrmem_create(xdrs, apd->ptr, apd->remaining, op);
154 afs_pd_xdrEnd(struct afs_pdata *apd, XDR *xdrs) {
157 pos = xdr_getpos(xdrs);
159 apd->remaining -= pos;
166 afs_pd_getString(struct afs_pdata *apd, char *str, size_t maxLen)
170 if (apd == NULL || apd->remaining <= 0)
172 len = strlen(apd->ptr) + 1;
175 memcpy(str, apd->ptr, len);
177 apd->remaining -= len;
182 afs_pd_getStringPtr(struct afs_pdata *apd, char **str)
186 if (apd == NULL || apd->remaining <= 0)
188 len = strlen(apd->ptr) + 1;
191 apd->remaining -= len;
196 afs_pd_putBytes(struct afs_pdata *apd, const void *bytes, size_t len)
198 if (apd == NULL || apd->remaining < len)
200 memcpy(apd->ptr, bytes, len);
202 apd->remaining -= len;
207 afs_pd_putInt(struct afs_pdata *apd, afs_int32 val)
209 return afs_pd_putBytes(apd, &val, sizeof(val));
213 afs_pd_putString(struct afs_pdata *apd, char *str) {
215 /* Add 1 so we copy the NULL too */
216 return afs_pd_putBytes(apd, str, strlen(str) +1);
220 * \defgroup pioctl Path IOCTL functions
222 * DECL_PIOCTL is a macro defined to contain the following parameters for functions:
225 * the AFS vcache structure in use by pioctl
229 * the AFS vrequest structure
231 * an afs_pdata block describing the data received from the caller
233 * an afs_pdata block describing a pre-allocated block for output
235 * UNIX credentials structure underlying the operation
238 #define DECL_PIOCTL(x) \
239 static int x(struct vcache *avc, int afun, struct vrequest *areq, \
240 struct afs_pdata *ain, struct afs_pdata *aout, \
243 /* Prototypes for pioctl routines */
244 DECL_PIOCTL(PGetFID);
245 DECL_PIOCTL(PSetAcl);
246 DECL_PIOCTL(PStoreBehind);
247 DECL_PIOCTL(PGCPAGs);
248 DECL_PIOCTL(PGetAcl);
251 DECL_PIOCTL(PGetFileCell);
252 DECL_PIOCTL(PGetWSCell);
253 DECL_PIOCTL(PGetUserCell);
254 DECL_PIOCTL(PSetTokens);
255 DECL_PIOCTL(PSetTokens2);
256 DECL_PIOCTL(PGetVolumeStatus);
257 DECL_PIOCTL(PSetVolumeStatus);
259 DECL_PIOCTL(PNewStatMount);
260 DECL_PIOCTL(PGetTokens);
261 DECL_PIOCTL(PGetTokens2);
263 DECL_PIOCTL(PMariner);
264 DECL_PIOCTL(PCheckServers);
265 DECL_PIOCTL(PCheckVolNames);
266 DECL_PIOCTL(PCheckAuth);
267 DECL_PIOCTL(PFindVolume);
268 DECL_PIOCTL(PViceAccess);
269 DECL_PIOCTL(PSetCacheSize);
270 DECL_PIOCTL(PGetCacheSize);
271 DECL_PIOCTL(PRemoveCallBack);
272 DECL_PIOCTL(PNewCell);
273 DECL_PIOCTL(PNewAlias);
274 DECL_PIOCTL(PListCells);
275 DECL_PIOCTL(PListAliases);
276 DECL_PIOCTL(PRemoveMount);
277 DECL_PIOCTL(PGetCellStatus);
278 DECL_PIOCTL(PSetCellStatus);
279 DECL_PIOCTL(PFlushVolumeData);
280 DECL_PIOCTL(PGetVnodeXStatus);
281 DECL_PIOCTL(PGetVnodeXStatus2);
282 DECL_PIOCTL(PSetSysName);
283 DECL_PIOCTL(PSetSPrefs);
284 DECL_PIOCTL(PSetSPrefs33);
285 DECL_PIOCTL(PGetSPrefs);
286 DECL_PIOCTL(PExportAfs);
288 DECL_PIOCTL(PTwiddleRx);
289 DECL_PIOCTL(PGetInitParams);
290 DECL_PIOCTL(PGetRxkcrypt);
291 DECL_PIOCTL(PSetRxkcrypt);
292 DECL_PIOCTL(PGetCPrefs);
293 DECL_PIOCTL(PSetCPrefs);
294 DECL_PIOCTL(PFlushMount);
295 DECL_PIOCTL(PRxStatProc);
296 DECL_PIOCTL(PRxStatPeer);
297 DECL_PIOCTL(PPrefetchFromTape);
299 DECL_PIOCTL(PCallBackAddr);
300 DECL_PIOCTL(PDiscon);
301 DECL_PIOCTL(PNFSNukeCreds);
302 DECL_PIOCTL(PNewUuid);
303 DECL_PIOCTL(PPrecache);
304 DECL_PIOCTL(PGetPAG);
305 #if defined(AFS_CACHE_BYPASS)
306 DECL_PIOCTL(PSetCachingThreshold);
310 * A macro that says whether we're going to need HandleClientContext().
311 * This is currently used only by the nfs translator.
313 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
314 #define AFS_NEED_CLIENTCONTEXT
317 /* Prototypes for private routines */
318 #ifdef AFS_NEED_CLIENTCONTEXT
319 static int HandleClientContext(struct afs_ioctl *ablob, int *com,
323 int HandleIoctl(struct vcache *avc, afs_int32 acom,
324 struct afs_ioctl *adata);
325 int afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
326 struct afs_ioctl *ablob, int afollow,
327 afs_ucred_t **acred);
328 static int Prefetch(uparmtype apath, struct afs_ioctl *adata, int afollow,
331 typedef int (*pioctlFunction) (struct vcache *, int, struct vrequest *,
332 struct afs_pdata *, struct afs_pdata *,
335 static pioctlFunction VpioctlSw[] = {
340 PGetVolumeStatus, /* 4 */
341 PSetVolumeStatus, /* 5 */
346 PCheckServers, /* 10 */
347 PCheckVolNames, /* 11 */
349 PBogus, /* 13 -- used to be quick check time */
350 PFindVolume, /* 14 */
351 PBogus, /* 15 -- prefetch is now special-cased; see pioctl code! */
352 PBogus, /* 16 -- used to be testing code */
353 PNoop, /* 17 -- used to be enable group */
354 PNoop, /* 18 -- used to be disable group */
355 PBogus, /* 19 -- used to be list group */
356 PViceAccess, /* 20 */
357 PUnlog, /* 21 -- unlog *is* unpag in this system */
358 PGetFID, /* 22 -- get file ID */
359 PBogus, /* 23 -- used to be waitforever */
360 PSetCacheSize, /* 24 */
361 PRemoveCallBack, /* 25 -- flush only the callback */
364 PRemoveMount, /* 28 -- delete mount point */
365 PNewStatMount, /* 29 -- new style mount point stat */
366 PGetFileCell, /* 30 -- get cell name for input file */
367 PGetWSCell, /* 31 -- get cell name for workstation */
368 PMariner, /* 32 - set/get mariner host */
369 PGetUserCell, /* 33 -- get cell name for user */
370 PBogus, /* 34 -- Enable/Disable logging */
371 PGetCellStatus, /* 35 */
372 PSetCellStatus, /* 36 */
373 PFlushVolumeData, /* 37 -- flush all data from a volume */
374 PSetSysName, /* 38 - Set system name */
375 PExportAfs, /* 39 - Export Afs to remote nfs clients */
376 PGetCacheSize, /* 40 - get cache size and usage */
377 PGetVnodeXStatus, /* 41 - get vcache's special status */
378 PSetSPrefs33, /* 42 - Set CM Server preferences... */
379 PGetSPrefs, /* 43 - Get CM Server preferences... */
380 PGag, /* 44 - turn off/on all CM messages */
381 PTwiddleRx, /* 45 - adjust some RX params */
382 PSetSPrefs, /* 46 - Set CM Server preferences... */
383 PStoreBehind, /* 47 - set degree of store behind to be done */
384 PGCPAGs, /* 48 - disable automatic pag gc-ing */
385 PGetInitParams, /* 49 - get initial cm params */
386 PGetCPrefs, /* 50 - get client interface addresses */
387 PSetCPrefs, /* 51 - set client interface addresses */
388 PFlushMount, /* 52 - flush mount symlink data */
389 PRxStatProc, /* 53 - control process RX statistics */
390 PRxStatPeer, /* 54 - control peer RX statistics */
391 PGetRxkcrypt, /* 55 -- Get rxkad encryption flag */
392 PSetRxkcrypt, /* 56 -- Set rxkad encryption flag */
393 PBogus, /* 57 -- arla: set file prio */
394 PBogus, /* 58 -- arla: fallback getfh */
395 PBogus, /* 59 -- arla: fallback fhopen */
396 PBogus, /* 60 -- arla: controls xfsdebug */
397 PBogus, /* 61 -- arla: controls arla debug */
398 PBogus, /* 62 -- arla: debug interface */
399 PBogus, /* 63 -- arla: print xfs status */
400 PBogus, /* 64 -- arla: force cache check */
401 PBogus, /* 65 -- arla: break callback */
402 PPrefetchFromTape, /* 66 -- MR-AFS: prefetch file from tape */
403 PFsCmd, /* 67 -- RXOSD: generic commnd interface */
404 PBogus, /* 68 -- arla: fetch stats */
405 PGetVnodeXStatus2, /* 69 - get caller access and some vcache status */
408 static pioctlFunction CpioctlSw[] = {
410 PNewAlias, /* 1 -- create new cell alias */
411 PListAliases, /* 2 -- list cell aliases */
412 PCallBackAddr, /* 3 -- request addr for callback rxcon */
414 PDiscon, /* 5 -- get/set discon mode */
425 static pioctlFunction OpioctlSw[] = {
427 PNFSNukeCreds, /* 1 -- nuke all creds for NFS client */
428 #if defined(AFS_CACHE_BYPASS)
429 PSetCachingThreshold /* 2 -- get/set cache-bypass size threshold */
431 PNoop /* 2 -- get/set cache-bypass size threshold */
435 #define PSetClientContext 99 /* Special pioctl to setup caller's creds */
436 int afs_nobody = NFS_NOBODY;
439 HandleIoctl(struct vcache *avc, afs_int32 acom,
440 struct afs_ioctl *adata)
445 AFS_STATCNT(HandleIoctl);
447 switch (acom & 0xff) {
449 avc->f.states |= CSafeStore;
451 /* SXW - Should we force a MetaData flush for this flag setting */
454 /* case 2 used to be abort store, but this is no longer provided,
455 * since it is impossible to implement under normal Unix.
459 /* return the name of the cell this file is open on */
463 tcell = afs_GetCell(avc->f.fid.Cell, READ_LOCK);
465 i = strlen(tcell->cellName) + 1; /* bytes to copy out */
467 if (i > adata->out_size) {
468 /* 0 means we're not interested in the output */
469 if (adata->out_size != 0)
473 AFS_COPYOUT(tcell->cellName, adata->out, i, code);
475 afs_PutCell(tcell, READ_LOCK);
481 case 49: /* VIOC_GETINITPARAMS */
482 if (adata->out_size < sizeof(struct cm_initparams)) {
485 AFS_COPYOUT(&cm_initParams, adata->out,
486 sizeof(struct cm_initparams), code);
498 return code; /* so far, none implemented */
502 /* For aix we don't temporarily bypass ioctl(2) but rather do our
503 * thing directly in the vnode layer call, VNOP_IOCTL; thus afs_ioctl
504 * is now called from afs_gn_ioctl.
507 afs_ioctl(struct vcache *tvc, int cmd, int arg)
509 struct afs_ioctl data;
512 AFS_STATCNT(afs_ioctl);
513 if (((cmd >> 8) & 0xff) == 'V') {
514 /* This is a VICEIOCTL call */
515 AFS_COPYIN(arg, (caddr_t) & data, sizeof(data), error);
518 error = HandleIoctl(tvc, cmd, &data);
521 /* No-op call; just return. */
525 # if defined(AFS_AIX32_ENV)
526 # if defined(AFS_AIX51_ENV)
529 kioctl(int fdes, int com, caddr_t arg, caddr_t ext, caddr_t arg2,
531 # else /* __64BIT__ */
533 kioctl32(int fdes, int com, caddr_t arg, caddr_t ext, caddr_t arg2,
535 # endif /* __64BIT__ */
538 kioctl(int fdes, int com, caddr_t arg, caddr_t ext)
539 # endif /* AFS_AIX51_ENV */
544 # ifdef AFS_AIX51_ENV
547 } u_uap, *uap = &u_uap;
550 int ioctlDone = 0, code = 0;
552 AFS_STATCNT(afs_xioctl);
556 # ifdef AFS_AIX51_ENV
560 if (setuerror(getf(uap->fd, &fd))) {
563 if (fd->f_type == DTYPE_VNODE) {
564 /* good, this is a vnode; next see if it is an AFS vnode */
565 tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */
566 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
567 /* This is an AFS vnode */
568 if (((uap->com >> 8) & 0xff) == 'V') {
569 struct afs_ioctl *datap;
572 (struct afs_ioctl *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
573 code=copyin_afs_ioctl((char *)uap->arg, datap);
575 osi_FreeSmallSpace(datap);
577 # if defined(AFS_AIX41_ENV)
580 return (setuerror(code), code);
582 code = HandleIoctl(tvc, uap->com, datap);
583 osi_FreeSmallSpace(datap);
586 # if defined(AFS_AIX41_ENV)
593 # if defined(AFS_AIX41_ENV)
595 # if defined(AFS_AIX51_ENV)
597 code = okioctl(fdes, com, arg, ext, arg2, arg3);
598 # else /* __64BIT__ */
599 code = okioctl32(fdes, com, arg, ext, arg2, arg3);
600 # endif /* __64BIT__ */
601 # else /* !AFS_AIX51_ENV */
602 code = okioctl(fdes, com, arg, ext);
603 # endif /* AFS_AIX51_ENV */
605 # elif defined(AFS_AIX32_ENV)
606 okioctl(fdes, com, arg, ext);
609 # if defined(KERNEL_HAVE_UERROR)
612 # if !defined(AFS_AIX41_ENV)
613 return (getuerror()? -1 : u.u_ioctlrv);
615 return getuerror()? -1 : 0;
622 #elif defined(AFS_SGI_ENV)
623 # if defined(AFS_SGI65_ENV)
624 afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
625 rval_t * rvalp, struct vopbd * vbds)
627 afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
628 rval_t * rvalp, struct vopbd * vbds)
631 struct afs_ioctl data;
637 AFS_STATCNT(afs_ioctl);
638 if (((cmd >> 8) & 0xff) == 'V') {
639 /* This is a VICEIOCTL call */
640 error = copyin_afs_ioctl(arg, &data);
643 locked = ISAFS_GLOCK();
646 error = HandleIoctl(tvc, cmd, &data);
651 /* No-op call; just return. */
655 #elif defined(AFS_SUN5_ENV)
656 struct afs_ioctl_sys {
663 afs_xioctl(struct afs_ioctl_sys *uap, rval_t *rvp)
667 int ioctlDone = 0, code = 0;
669 AFS_STATCNT(afs_xioctl);
670 # if defined(AFS_SUN57_ENV)
674 # elif defined(AFS_SUN54_ENV)
679 if (code = getf(uap->fd, &fd)) {
683 if (fd->f_vnode->v_type == VREG || fd->f_vnode->v_type == VDIR) {
684 tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */
685 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
686 /* This is an AFS vnode */
687 if (((uap->com >> 8) & 0xff) == 'V') {
688 struct afs_ioctl *datap;
691 (struct afs_ioctl *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
692 code=copyin_afs_ioctl((char *)uap->arg, datap);
694 osi_FreeSmallSpace(datap);
696 # if defined(AFS_SUN54_ENV)
703 code = HandleIoctl(tvc, uap->com, datap);
704 osi_FreeSmallSpace(datap);
710 # if defined(AFS_SUN57_ENV)
712 # elif defined(AFS_SUN54_ENV)
718 code = ioctl(uap, rvp);
722 #elif defined(AFS_LINUX22_ENV)
723 struct afs_ioctl_sys {
728 afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
731 struct afs_ioctl_sys ua, *uap = &ua;
733 int ioctlDone = 0, code = 0;
735 AFS_STATCNT(afs_xioctl);
740 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
741 /* This is an AFS vnode */
742 if (((uap->com >> 8) & 0xff) == 'V') {
743 struct afs_ioctl *datap;
745 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
746 code = copyin_afs_ioctl((char *)uap->arg, datap);
748 osi_FreeSmallSpace(datap);
752 code = HandleIoctl(tvc, uap->com, datap);
753 osi_FreeSmallSpace(datap);
762 #elif defined(AFS_DARWIN_ENV) && !defined(AFS_DARWIN80_ENV)
770 afs_xioctl(afs_proc_t *p, struct ioctl_args *uap, register_t *retval)
774 int ioctlDone = 0, code = 0;
776 AFS_STATCNT(afs_xioctl);
777 if ((code = fdgetf(p, uap->fd, &fd)))
779 if (fd->f_type == DTYPE_VNODE) {
780 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
781 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
782 /* This is an AFS vnode */
783 if (((uap->com >> 8) & 0xff) == 'V') {
784 struct afs_ioctl *datap;
786 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
787 code = copyin_afs_ioctl((char *)uap->arg, datap);
789 osi_FreeSmallSpace(datap);
793 code = HandleIoctl(tvc, uap->com, datap);
794 osi_FreeSmallSpace(datap);
802 return ioctl(p, uap, retval);
806 #elif defined(AFS_XBSD_ENV)
807 # if defined(AFS_FBSD_ENV)
810 afs_xioctl(struct thread *td, struct ioctl_args *uap,
813 afs_proc_t *p = td->td_proc;
822 afs_xioctl(afs_proc_t *p, struct ioctl_args *uap, register_t *retval)
825 struct filedesc *fdp;
827 int ioctlDone = 0, code = 0;
830 AFS_STATCNT(afs_xioctl);
831 # if defined(AFS_NBSD40_ENV)
832 fdp = p->l_proc->p_fd;
836 if ((u_int) uap->fd >= fdp->fd_nfiles
837 || (fd = fdp->fd_ofiles[uap->fd]) == NULL)
839 if ((fd->f_flag & (FREAD | FWRITE)) == 0)
841 /* first determine whether this is any sort of vnode */
842 if (fd->f_type == DTYPE_VNODE) {
843 /* good, this is a vnode; next see if it is an AFS vnode */
844 # if defined(AFS_OBSD_ENV)
846 IsAfsVnode((struct vnode *)fd->
847 f_data) ? VTOAFS((struct vnode *)fd->f_data) : NULL;
849 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
851 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
852 /* This is an AFS vnode */
853 if (((uap->com >> 8) & 0xff) == 'V') {
854 struct afs_ioctl *datap;
856 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
857 code = copyin_afs_ioctl((char *)uap->arg, datap);
859 osi_FreeSmallSpace(datap);
863 code = HandleIoctl(tvc, uap->com, datap);
864 osi_FreeSmallSpace(datap);
872 # if defined(AFS_FBSD_ENV)
873 return ioctl(td, uap);
874 # elif defined(AFS_OBSD_ENV)
875 code = sys_ioctl(p, uap, retval);
876 # elif defined(AFS_NBSD_ENV)
877 struct lwp *l = osi_curproc();
878 code = sys_ioctl(l, uap, retval);
884 #elif defined(UKERNEL)
892 } *uap = (struct a *)get_user_struct()->u_ap;
895 int ioctlDone = 0, code = 0;
897 AFS_STATCNT(afs_xioctl);
902 /* first determine whether this is any sort of vnode */
903 if (fd->f_type == DTYPE_VNODE) {
904 /* good, this is a vnode; next see if it is an AFS vnode */
905 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
906 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
907 /* This is an AFS vnode */
908 if (((uap->com >> 8) & 0xff) == 'V') {
909 struct afs_ioctl *datap;
911 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
912 code=copyin_afs_ioctl((char *)uap->arg, datap);
914 osi_FreeSmallSpace(datap);
917 return (setuerror(code), code);
919 code = HandleIoctl(tvc, uap->com, datap);
920 osi_FreeSmallSpace(datap);
933 #endif /* AFS_HPUX102_ENV */
935 #if defined(AFS_SGI_ENV)
936 /* "pioctl" system call entry point; just pass argument to the parameterized
945 afs_pioctl(struct pioctlargs *uap, rval_t * rvp)
949 AFS_STATCNT(afs_pioctl);
951 code = afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow);
953 # ifdef AFS_SGI64_ENV
960 #elif defined(AFS_FBSD_ENV)
962 afs_pioctl(struct thread *td, void *args, int *retval)
969 } *uap = (struct a *)args;
971 AFS_STATCNT(afs_pioctl);
972 return (afs_syscall_pioctl
973 (uap->path, uap->cmd, uap->cmarg, uap->follow, td->td_ucred));
976 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
978 afs_pioctl(afs_proc_t *p, void *args, int *retval)
985 } *uap = (struct a *)args;
987 AFS_STATCNT(afs_pioctl);
988 # if defined(AFS_DARWIN80_ENV) || defined(AFS_NBSD40_ENV)
989 return (afs_syscall_pioctl
990 (uap->path, uap->cmd, uap->cmarg, uap->follow,
993 return (afs_syscall_pioctl
994 (uap->path, uap->cmd, uap->cmarg, uap->follow,
995 # if defined(AFS_FBSD_ENV)
998 p->p_cred->pc_ucred));
1005 /* macro to avoid adding any more #ifdef's to pioctl code. */
1006 #if defined(AFS_LINUX22_ENV) || defined(AFS_AIX41_ENV)
1007 #define PIOCTL_FREE_CRED() crfree(credp)
1009 #define PIOCTL_FREE_CRED()
1014 afs_syscall_pioctl(char *path, unsigned int com, caddr_t cmarg, int follow,
1015 rval_t *vvp, afs_ucred_t *credp)
1017 #ifdef AFS_DARWIN100_ENV
1018 afs_syscall64_pioctl(user_addr_t path, unsigned int com, user_addr_t cmarg,
1019 int follow, afs_ucred_t *credp)
1020 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1021 afs_syscall_pioctl(char *path, unsigned int com, caddr_t cmarg, int follow,
1024 afs_syscall_pioctl(char *path, unsigned int com, caddr_t cmarg, int follow)
1028 struct afs_ioctl data;
1029 #ifdef AFS_NEED_CLIENTCONTEXT
1030 afs_ucred_t *tmpcred = NULL;
1032 #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)
1033 afs_ucred_t *foreigncreds = NULL;
1036 struct vnode *vp = NULL;
1037 #ifdef AFS_AIX41_ENV
1038 struct ucred *credp = crref(); /* don't free until done! */
1040 #ifdef AFS_LINUX22_ENV
1041 cred_t *credp = crref(); /* don't free until done! */
1045 AFS_STATCNT(afs_syscall_pioctl);
1047 follow = 1; /* compat. with old venus */
1048 code = copyin_afs_ioctl(cmarg, &data);
1051 #if defined(KERNEL_HAVE_UERROR)
1056 if ((com & 0xff) == PSetClientContext) {
1057 #ifdef AFS_NEED_CLIENTCONTEXT
1058 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV)
1059 code = HandleClientContext(&data, &com, &foreigncreds, credp);
1061 code = HandleClientContext(&data, &com, &foreigncreds, osi_curcred());
1065 crfree(foreigncreds);
1068 #if defined(KERNEL_HAVE_UERROR)
1069 return (setuerror(code), code);
1074 #else /* AFS_NEED_CLIENTCONTEXT */
1076 #endif /* AFS_NEED_CLIENTCONTEXT */
1078 #ifdef AFS_NEED_CLIENTCONTEXT
1081 * We could have done without temporary setting the u.u_cred below
1082 * (foreigncreds could be passed as param the pioctl modules)
1083 * but calls such as afs_osi_suser() doesn't allow that since it
1084 * references u.u_cred directly. We could, of course, do something
1085 * like afs_osi_suser(cred) which, I think, is better since it
1086 * generalizes and supports multi cred environments...
1088 #if defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
1090 credp = foreigncreds;
1091 #elif defined(AFS_AIX41_ENV)
1092 tmpcred = crref(); /* XXX */
1093 crset(foreigncreds);
1094 #elif defined(AFS_HPUX101_ENV)
1095 tmpcred = p_cred(u.u_procp);
1096 set_p_cred(u.u_procp, foreigncreds);
1097 #elif defined(AFS_SGI_ENV)
1098 tmpcred = OSI_GET_CURRENT_CRED();
1099 OSI_SET_CURRENT_CRED(foreigncreds);
1102 u.u_cred = foreigncreds;
1105 #endif /* AFS_NEED_CLIENTCONTEXT */
1106 if ((com & 0xff) == 15) {
1107 /* special case prefetch so entire pathname eval occurs in helper process.
1108 * otherwise, the pioctl call is essentially useless */
1109 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1111 Prefetch(path, &data, follow,
1112 foreigncreds ? foreigncreds : credp);
1114 code = Prefetch(path, &data, follow, osi_curcred());
1117 #if defined(KERNEL_HAVE_UERROR)
1124 #ifdef AFS_AIX41_ENV
1126 lookupname(path, USR, follow, NULL, &vp,
1127 foreigncreds ? foreigncreds : credp);
1129 #ifdef AFS_LINUX22_ENV
1130 code = gop_lookupname_user(path, AFS_UIOUSER, follow, &dp);
1132 vp = (struct vnode *)dp->d_inode;
1134 code = gop_lookupname_user(path, AFS_UIOUSER, follow, &vp);
1135 #if defined(AFS_FBSD80_ENV) /* XXX check on 7x */
1138 #endif /* AFS_FBSD80_ENV */
1139 #endif /* AFS_LINUX22_ENV */
1140 #endif /* AFS_AIX41_ENV */
1144 #if defined(KERNEL_HAVE_UERROR)
1152 #if defined(AFS_SUN510_ENV)
1153 if (vp && !IsAfsVnode(vp)) {
1154 struct vnode *realvp;
1156 #ifdef AFS_SUN511_ENV
1157 (VOP_REALVP(vp, &realvp, NULL) == 0)
1159 (VOP_REALVP(vp, &realvp) == 0)
1162 struct vnode *oldvp = vp;
1170 /* now make the call if we were passed no file, or were passed an AFS file */
1171 if (!vp || IsAfsVnode(vp)) {
1172 #if defined(AFS_SUN5_ENV)
1173 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1174 #elif defined(AFS_AIX41_ENV)
1176 struct ucred *cred1, *cred2;
1179 cred1 = cred2 = foreigncreds;
1181 cred1 = cred2 = credp;
1183 code = afs_HandlePioctl(vp, com, &data, follow, &cred1);
1184 if (cred1 != cred2) {
1185 /* something changed the creds */
1189 #elif defined(AFS_HPUX101_ENV)
1191 struct ucred *cred = p_cred(u.u_procp);
1192 code = afs_HandlePioctl(vp, com, &data, follow, &cred);
1194 #elif defined(AFS_SGI_ENV)
1197 credp = OSI_GET_CURRENT_CRED();
1198 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1200 #elif defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1201 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1202 #elif defined(UKERNEL)
1203 code = afs_HandlePioctl(vp, com, &data, follow,
1204 &(get_user_struct()->u_cred));
1206 code = afs_HandlePioctl(vp, com, &data, follow, &u.u_cred);
1209 #if defined(KERNEL_HAVE_UERROR)
1212 code = EINVAL; /* not in /afs */
1217 #if defined(AFS_NEED_CLIENTCONTEXT)
1219 #ifdef AFS_AIX41_ENV
1220 crset(tmpcred); /* restore original credentials */
1222 #if defined(AFS_HPUX101_ENV)
1223 set_p_cred(u.u_procp, tmpcred); /* restore original credentials */
1224 #elif defined(AFS_SGI_ENV)
1225 OSI_SET_CURRENT_CRED(tmpcred); /* restore original credentials */
1226 #elif defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
1227 credp = tmpcred; /* restore original credentials */
1229 osi_curcred() = tmpcred; /* restore original credentials */
1230 #endif /* AFS_HPUX101_ENV */
1231 crfree(foreigncreds);
1234 #endif /* AFS_NEED_CLIENTCONTEXT */
1236 #ifdef AFS_LINUX22_ENV
1239 #if defined(AFS_FBSD80_ENV)
1240 if (VOP_ISLOCKED(vp))
1242 #endif /* AFS_FBSD80_ENV */
1243 AFS_RELE(vp); /* put vnode back */
1247 #if defined(KERNEL_HAVE_UERROR)
1250 return (getuerror());
1256 #ifdef AFS_DARWIN100_ENV
1258 afs_syscall_pioctl(char * path, unsigned int com, caddr_t cmarg,
1259 int follow, afs_ucred_t *credp)
1261 return afs_syscall64_pioctl(CAST_USER_ADDR_T(path), com,
1262 CAST_USER_ADDR_T((unsigned int)cmarg), follow,
1267 #define MAXPIOCTLTOKENLEN \
1268 (3*sizeof(afs_int32)+MAXKTCTICKETLEN+sizeof(struct ClearToken)+MAXKTCREALMLEN)
1271 afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
1272 struct afs_ioctl *ablob, int afollow,
1273 afs_ucred_t **acred)
1276 struct vrequest treq;
1278 afs_int32 function, device;
1279 struct afs_pdata input, output;
1280 struct afs_pdata copyInput, copyOutput;
1282 pioctlFunction *pioctlSw;
1284 struct afs_fakestat_state fakestate;
1286 memset(&input, 0, sizeof(input));
1287 memset(&output, 0, sizeof(output));
1289 avc = avp ? VTOAFS(avp) : NULL;
1290 afs_Trace3(afs_iclSetp, CM_TRACE_PIOCTL, ICL_TYPE_INT32, acom & 0xff,
1291 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, afollow);
1292 AFS_STATCNT(HandlePioctl);
1294 code = afs_InitReq(&treq, *acred);
1298 afs_InitFakeStat(&fakestate);
1300 code = afs_EvalFakeStat(&avc, &fakestate, &treq);
1304 device = (acom & 0xff00) >> 8;
1306 case 'V': /* Original pioctls */
1307 pioctlSw = VpioctlSw;
1308 pioctlSwSize = sizeof(VpioctlSw);
1310 case 'C': /* Coordinated/common pioctls */
1311 pioctlSw = CpioctlSw;
1312 pioctlSwSize = sizeof(CpioctlSw);
1314 case 'O': /* Coordinated/common pioctls */
1315 pioctlSw = OpioctlSw;
1316 pioctlSwSize = sizeof(OpioctlSw);
1322 function = acom & 0xff;
1323 if (function >= (pioctlSwSize / sizeof(char *))) {
1328 /* Do all range checking before continuing */
1329 if (ablob->in_size > MAXPIOCTLTOKENLEN ||
1330 ablob->in_size < 0 || ablob->out_size < 0) {
1335 code = afs_pd_alloc(&input, ablob->in_size);
1339 if (ablob->in_size > 0) {
1340 AFS_COPYIN(ablob->in, input.ptr, ablob->in_size, code);
1341 input.ptr[input.remaining] = '\0';
1346 if ((function == 8 && device == 'V') ||
1347 (function == 7 && device == 'C')) { /* PGetTokens */
1348 code = afs_pd_alloc(&output, MAXPIOCTLTOKENLEN);
1350 code = afs_pd_alloc(&output, AFS_LRALLOCSIZ);
1356 copyOutput = output;
1359 (*pioctlSw[function]) (avc, function, &treq, ©Input,
1360 ©Output, acred);
1362 outSize = copyOutput.ptr - output.ptr;
1364 if (code == 0 && ablob->out_size > 0) {
1365 if (outSize > ablob->out_size) {
1366 code = E2BIG; /* data wont fit in user buffer */
1367 } else if (outSize) {
1368 AFS_COPYOUT(output.ptr, ablob->out, outSize, code);
1373 afs_pd_free(&input);
1374 afs_pd_free(&output);
1376 afs_PutFakeStat(&fakestate);
1377 return afs_CheckCode(code, &treq, 41);
1381 * VIOCGETFID (22) - Get file ID quickly
1385 * \param[in] ain not in use
1386 * \param[out] aout fid of requested file
1388 * \retval EINVAL Error if some of the initial arguments aren't set
1390 * \post get the file id of some file
1392 DECL_PIOCTL(PGetFID)
1394 AFS_STATCNT(PGetFID);
1397 if (afs_pd_putBytes(aout, &avc->f.fid, sizeof(struct VenusFid)) != 0)
1403 * VIOCSETAL (1) - Set access control list
1407 * \param[in] ain the ACL being set
1408 * \param[out] aout the ACL being set returned
1410 * \retval EINVAL Error if some of the standard args aren't set
1412 * \post Changed ACL, via direct writing to the wire
1415 dummy_PSetAcl(char *ain, char *aout)
1420 DECL_PIOCTL(PSetAcl)
1423 struct afs_conn *tconn;
1424 struct AFSOpaque acl;
1425 struct AFSVolSync tsync;
1426 struct AFSFetchStatus OutStatus;
1429 AFS_STATCNT(PSetAcl);
1433 if (afs_pd_getStringPtr(ain, &acl.AFSOpaque_val) != 0)
1435 acl.AFSOpaque_len = strlen(acl.AFSOpaque_val) + 1;
1436 if (acl.AFSOpaque_len > 1024)
1440 tconn = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
1442 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREACL);
1445 RXAFS_StoreACL(tconn->id, (struct AFSFid *)&avc->f.fid.Fid,
1446 &acl, &OutStatus, &tsync);
1451 } while (afs_Analyze
1452 (tconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_STOREACL,
1453 SHARED_LOCK, NULL));
1455 /* now we've forgotten all of the access info */
1456 ObtainWriteLock(&afs_xcbhash, 455);
1458 afs_DequeueCallback(avc);
1459 avc->f.states &= ~(CStatd | CUnique);
1460 ReleaseWriteLock(&afs_xcbhash);
1461 if (avc->f.fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
1462 osi_dnlc_purgedp(avc);
1464 /* SXW - Should we flush metadata here? */
1468 int afs_defaultAsynchrony = 0;
1471 * VIOC_STOREBEHIND (47) Adjust store asynchrony
1475 * \param[in] ain sbstruct (store behind structure) input
1476 * \param[out] aout resulting sbstruct
1479 * Error if the user doesn't have super-user credentials
1481 * Error if there isn't enough access to not check the mode bits
1484 * Changes either the default asynchrony (the amount of data that
1485 * can remain to be written when the cache manager returns control
1486 * to the user), or the asyncrony for the specified file.
1488 DECL_PIOCTL(PStoreBehind)
1490 struct sbstruct sbr;
1492 if (afs_pd_getBytes(ain, &sbr, sizeof(struct sbstruct)) != 0)
1495 if (sbr.sb_default != -1) {
1496 if (afs_osi_suser(*acred))
1497 afs_defaultAsynchrony = sbr.sb_default;
1502 if (avc && (sbr.sb_thisfile != -1)) {
1504 (avc, PRSFS_WRITE | PRSFS_ADMINISTER, areq, DONT_CHECK_MODE_BITS))
1505 avc->asynchrony = sbr.sb_thisfile;
1510 memset(&sbr, 0, sizeof(sbr));
1511 sbr.sb_default = afs_defaultAsynchrony;
1513 sbr.sb_thisfile = avc->asynchrony;
1516 return afs_pd_putBytes(aout, &sbr, sizeof(sbr));
1520 * VIOC_GCPAGS (48) - Disable automatic PAG gc'ing
1524 * \param[in] ain not in use
1525 * \param[out] aout not in use
1527 * \retval EACCES Error if the user doesn't have super-user credentials
1529 * \post set the gcpags to GCPAGS_USERDISABLED
1531 DECL_PIOCTL(PGCPAGs)
1533 if (!afs_osi_suser(*acred)) {
1536 afs_gcpags = AFS_GCPAGS_USERDISABLED;
1541 * VIOCGETAL (2) - Get access control list
1545 * \param[in] ain not in use
1546 * \param[out] aout the ACL
1548 * \retval EINVAL Error if some of the standard args aren't set
1549 * \retval ERANGE Error if the vnode of the file id is too large
1550 * \retval -1 Error if getting the ACL failed
1552 * \post Obtain the ACL, based on file ID
1555 * There is a hack to tell which type of ACL is being returned, checks
1556 * the top 2-bytes of the input size to judge what type of ACL it is,
1557 * only for dfs xlator ACLs
1559 DECL_PIOCTL(PGetAcl)
1561 struct AFSOpaque acl;
1562 struct AFSVolSync tsync;
1563 struct AFSFetchStatus OutStatus;
1565 struct afs_conn *tconn;
1569 AFS_STATCNT(PGetAcl);
1572 Fid.Volume = avc->f.fid.Fid.Volume;
1573 Fid.Vnode = avc->f.fid.Fid.Vnode;
1574 Fid.Unique = avc->f.fid.Fid.Unique;
1575 if (avc->f.states & CForeign) {
1577 * For a dfs xlator acl we have a special hack so that the
1578 * xlator will distinguish which type of acl will return. So
1579 * we currently use the top 2-bytes (vals 0-4) to tell which
1580 * type of acl to bring back. Horrible hack but this will
1581 * cause the least number of changes to code size and interfaces.
1583 if (Fid.Vnode & 0xc0000000)
1585 Fid.Vnode |= (ain->remaining << 30);
1587 acl.AFSOpaque_val = aout->ptr;
1589 tconn = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
1591 acl.AFSOpaque_val[0] = '\0';
1592 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHACL);
1594 code = RXAFS_FetchACL(tconn->id, &Fid, &acl, &OutStatus, &tsync);
1599 } while (afs_Analyze
1600 (tconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_FETCHACL,
1601 SHARED_LOCK, NULL));
1604 if (acl.AFSOpaque_len == 0)
1605 afs_pd_skip(aout, 1); /* leave the NULL */
1607 afs_pd_skip(aout, acl.AFSOpaque_len); /* Length of the ACL */
1613 * PNoop returns success. Used for functions which are not implemented
1614 * or are no longer in use.
1618 * \retval Always returns success
1621 * Functions involved in this:
1622 * 17 (VIOCENGROUP) -- used to be enable group;
1623 * 18 (VIOCDISGROUP) -- used to be disable group;
1624 * 2 (?) -- get/set cache-bypass size threshold
1633 * PBogus returns fail. Used for functions which are not implemented or
1634 * are no longer in use.
1638 * \retval EINVAL Always returns this value
1641 * Functions involved in this:
1647 * 13 (VIOCGETTIME) -- used to be quick check time;
1648 * 15 (VIOCPREFETCH) -- prefetch is now special-cased; see pioctl code!;
1649 * 16 (VIOCNOP) -- used to be testing code;
1650 * 19 (VIOCLISTGROUPS) -- used to be list group;
1651 * 23 (VIOCWAITFOREVER) -- used to be waitforever;
1652 * 57 (VIOC_FPRIOSTATUS) -- arla: set file prio;
1653 * 58 (VIOC_FHGET) -- arla: fallback getfh;
1654 * 59 (VIOC_FHOPEN) -- arla: fallback fhopen;
1655 * 60 (VIOC_XFSDEBUG) -- arla: controls xfsdebug;
1656 * 61 (VIOC_ARLADEBUG) -- arla: controls arla debug;
1657 * 62 (VIOC_AVIATOR) -- arla: debug interface;
1658 * 63 (VIOC_XFSDEBUG_PRINT) -- arla: print xfs status;
1659 * 64 (VIOC_CALCULATE_CACHE) -- arla: force cache check;
1660 * 65 (VIOC_BREAKCELLBACK) -- arla: break callback;
1661 * 68 (?) -- arla: fetch stats;
1665 AFS_STATCNT(PBogus);
1670 * VIOC_FILE_CELL_NAME (30) - Get cell in which file lives
1674 * \param[in] ain not in use (avc used to pass in file id)
1675 * \param[out] aout cell name
1677 * \retval EINVAL Error if some of the standard args aren't set
1678 * \retval ESRCH Error if the file isn't part of a cell
1680 * \post Get a cell based on a passed in file id
1682 DECL_PIOCTL(PGetFileCell)
1686 AFS_STATCNT(PGetFileCell);
1689 tcell = afs_GetCell(avc->f.fid.Cell, READ_LOCK);
1693 if (afs_pd_putString(aout, tcell->cellName) != 0)
1696 afs_PutCell(tcell, READ_LOCK);
1701 * VIOC_GET_WS_CELL (31) - Get cell in which workstation lives
1705 * \param[in] ain not in use
1706 * \param[out] aout cell name
1709 * Error if the afs daemon hasn't started yet
1711 * Error if the machine isn't part of a cell, for whatever reason
1713 * \post Get the primary cell that the machine is a part of.
1715 DECL_PIOCTL(PGetWSCell)
1717 struct cell *tcell = NULL;
1719 AFS_STATCNT(PGetWSCell);
1720 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1721 return EIO; /* Inappropriate ioctl for device */
1723 tcell = afs_GetPrimaryCell(READ_LOCK);
1724 if (!tcell) /* no primary cell? */
1727 if (afs_pd_putString(aout, tcell->cellName) != 0)
1729 afs_PutCell(tcell, READ_LOCK);
1734 * VIOC_GET_PRIMARY_CELL (33) - Get primary cell for caller
1738 * \param[in] ain not in use (user id found via areq)
1739 * \param[out] aout cell name
1742 * Error if the user id doesn't have a primary cell specified
1744 * \post Get the primary cell for a certain user, based on the user's uid
1746 DECL_PIOCTL(PGetUserCell)
1749 struct unixuser *tu;
1752 AFS_STATCNT(PGetUserCell);
1753 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1754 return EIO; /* Inappropriate ioctl for device */
1756 /* return the cell name of the primary cell for this user */
1757 i = UHash(areq->uid);
1758 ObtainWriteLock(&afs_xuser, 224);
1759 for (tu = afs_users[i]; tu; tu = tu->next) {
1760 if (tu->uid == areq->uid && (tu->states & UPrimary)) {
1762 ReleaseWriteLock(&afs_xuser);
1767 tcell = afs_GetCell(tu->cell, READ_LOCK);
1768 afs_PutUser(tu, WRITE_LOCK);
1772 if (afs_pd_putString(aout, tcell->cellName) != 0)
1774 afs_PutCell(tcell, READ_LOCK);
1777 ReleaseWriteLock(&afs_xuser);
1782 /* Work out which cell we're changing tokens for */
1784 _settok_tokenCell(char *cellName, int *cellNum, int *primary) {
1788 if (cellName && strlen(cellName) > 0) {
1789 cell = afs_GetCellByName(cellName, READ_LOCK);
1791 cell = afs_GetPrimaryCell(READ_LOCK);
1802 *cellNum = cell->cellNum;
1803 afs_PutCell(cell, READ_LOCK);
1810 _settok_setParentPag(afs_ucred_t **cred) {
1812 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1814 osi_procname(procname, 256);
1815 afs_warnuser("Process %d (%s) tried to change pags in PSetTokens\n",
1816 MyPidxx2Pid(MyPidxx), procname);
1817 return setpag(osi_curproc(), cred, -1, &pag, 1);
1819 return setpag(cred, -1, &pag, 1);
1824 * VIOCSETTOK (3) - Set authentication tokens
1828 * \param[in] ain the krb tickets from which to set the afs tokens
1829 * \param[out] aout not in use
1832 * Error if the ticket is either too long or too short
1834 * Error if the AFS initState is below 101
1836 * Error if the cell for which the Token is being set can't be found
1839 * Set the Tokens for a specific cell name, unless there is none set,
1840 * then default to primary
1843 DECL_PIOCTL(PSetTokens)
1848 struct unixuser *tu;
1849 struct ClearToken clear;
1853 struct vrequest treq;
1854 afs_int32 flag, set_parent_pag = 0;
1856 AFS_STATCNT(PSetTokens);
1857 if (!afs_resourceinit_flag) {
1861 if (afs_pd_getInt(ain, &stLen) != 0)
1864 stp = afs_pd_where(ain); /* remember where the ticket is */
1865 if (stLen < 0 || stLen > MAXKTCTICKETLEN)
1866 return EINVAL; /* malloc may fail */
1867 if (afs_pd_skip(ain, stLen) != 0)
1870 if (afs_pd_getInt(ain, &size) != 0)
1872 if (size != sizeof(struct ClearToken))
1875 if (afs_pd_getBytes(ain, &clear, sizeof(struct ClearToken)) !=0)
1878 if (clear.AuthHandle == -1)
1879 clear.AuthHandle = 999; /* more rxvab compat stuff */
1881 if (afs_pd_remaining(ain) != 0) {
1882 /* still stuff left? we've got primary flag and cell name.
1885 if (afs_pd_getInt(ain, &flag) != 0)
1888 /* some versions of gcc appear to need != 0 in order to get this
1890 if ((flag & 0x8000) != 0) { /* XXX Use Constant XXX */
1895 if (afs_pd_getStringPtr(ain, &cellName) != 0)
1898 code = _settok_tokenCell(cellName, &cellNum, NULL);
1902 /* default to primary cell, primary id */
1903 code = _settok_tokenCell(NULL, &cellNum, &flag);
1908 if (set_parent_pag) {
1909 if (_settok_setParentPag(acred) == 0) {
1910 afs_InitReq(&treq, *acred);
1915 /* now we just set the tokens */
1916 tu = afs_GetUser(areq->uid, cellNum, WRITE_LOCK);
1917 /* Set tokens destroys any that are already there */
1918 afs_FreeTokens(&tu->tokens);
1919 afs_AddRxkadToken(&tu->tokens, stp, stLen, &clear);
1921 afs_stats_cmfullperf.authent.TicketUpdates++;
1922 afs_ComputePAGStats();
1923 #endif /* AFS_NOSTATS */
1924 tu->states |= UHasTokens;
1925 tu->states &= ~UTokensBad;
1926 afs_SetPrimary(tu, flag);
1927 tu->tokenTime = osi_Time();
1928 afs_ResetUserConns(tu);
1929 afs_NotifyUser(tu, UTokensObtained);
1930 afs_PutUser(tu, WRITE_LOCK);
1936 * VIOCGETVOLSTAT (4) - Get volume status
1940 * \param[in] ain not in use
1941 * \param[out] aout status of the volume
1943 * \retval EINVAL Error if some of the standard args aren't set
1946 * The status of a volume (based on the FID of the volume), or an
1947 * offline message /motd
1949 DECL_PIOCTL(PGetVolumeStatus)
1952 char *offLineMsg = afs_osi_Alloc(256);
1953 char *motd = afs_osi_Alloc(256);
1954 struct afs_conn *tc;
1956 struct AFSFetchVolumeStatus volstat;
1960 AFS_STATCNT(PGetVolumeStatus);
1967 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
1969 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS);
1972 RXAFS_GetVolumeStatus(tc->id, avc->f.fid.Fid.Volume, &volstat,
1973 &Name, &offLineMsg, &motd);
1978 } while (afs_Analyze
1979 (tc, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS,
1980 SHARED_LOCK, NULL));
1984 /* Copy all this junk into msg->im_data, keeping track of the lengths. */
1985 if (afs_pd_putBytes(aout, &volstat, sizeof(VolumeStatus)) != 0)
1987 if (afs_pd_putString(aout, volName) != 0)
1989 if (afs_pd_putString(aout, offLineMsg) != 0)
1991 if (afs_pd_putString(aout, motd) != 0)
1994 afs_osi_Free(offLineMsg, 256);
1995 afs_osi_Free(motd, 256);
2000 * VIOCSETVOLSTAT (5) - Set volume status
2005 * values to set the status at, offline message, message of the day,
2006 * volume name, minimum quota, maximum quota
2008 * status of a volume, offlines messages, minimum quota, maximumm quota
2011 * Error if some of the standard args aren't set
2013 * Error if the volume is read only, or a backup volume
2015 * Error if the volume can't be accessed
2017 * Error if the volume name, offline message, and motd are too big
2020 * Set the status of a volume, including any offline messages,
2021 * a minimum quota, and a maximum quota
2023 DECL_PIOCTL(PSetVolumeStatus)
2028 struct afs_conn *tc;
2030 struct AFSFetchVolumeStatus volstat;
2031 struct AFSStoreVolumeStatus storeStat;
2035 AFS_STATCNT(PSetVolumeStatus);
2039 tvp = afs_GetVolume(&avc->f.fid, areq, READ_LOCK);
2041 if (tvp->states & (VRO | VBackup)) {
2042 afs_PutVolume(tvp, READ_LOCK);
2045 afs_PutVolume(tvp, READ_LOCK);
2050 if (afs_pd_getBytes(ain, &volstat, sizeof(AFSFetchVolumeStatus)) != 0)
2053 if (afs_pd_getStringPtr(ain, &volName) != 0)
2055 if (strlen(volName) > 32)
2058 if (afs_pd_getStringPtr(ain, &offLineMsg) != 0)
2060 if (strlen(offLineMsg) > 256)
2063 if (afs_pd_getStringPtr(ain, &motd) != 0)
2065 if (strlen(motd) > 256)
2068 /* Done reading ... */
2071 if (volstat.MinQuota != -1) {
2072 storeStat.MinQuota = volstat.MinQuota;
2073 storeStat.Mask |= AFS_SETMINQUOTA;
2075 if (volstat.MaxQuota != -1) {
2076 storeStat.MaxQuota = volstat.MaxQuota;
2077 storeStat.Mask |= AFS_SETMAXQUOTA;
2080 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
2082 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS);
2085 RXAFS_SetVolumeStatus(tc->id, avc->f.fid.Fid.Volume, &storeStat,
2086 volName, offLineMsg, motd);
2091 } while (afs_Analyze
2092 (tc, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS,
2093 SHARED_LOCK, NULL));
2097 /* we are sending parms back to make compat. with prev system. should
2098 * change interface later to not ask for current status, just set new
2101 if (afs_pd_putBytes(aout, &volstat, sizeof(VolumeStatus)) != 0)
2103 if (afs_pd_putString(aout, volName) != 0)
2105 if (afs_pd_putString(aout, offLineMsg) != 0)
2107 if (afs_pd_putString(aout, motd) != 0)
2114 * VIOCFLUSH (6) - Invalidate cache entry
2118 * \param[in] ain not in use
2119 * \param[out] aout not in use
2121 * \retval EINVAL Error if some of the standard args aren't set
2123 * \post Flush any information the cache manager has on an entry
2127 AFS_STATCNT(PFlush);
2130 #ifdef AFS_BOZONLOCK_ENV
2131 afs_BozonLock(&avc->pvnLock, avc); /* Since afs_TryToSmush will do a pvn_vptrunc */
2133 ObtainWriteLock(&avc->lock, 225);
2134 afs_ResetVCache(avc, *acred);
2135 ReleaseWriteLock(&avc->lock);
2136 #ifdef AFS_BOZONLOCK_ENV
2137 afs_BozonUnlock(&avc->pvnLock, avc);
2143 * VIOC_AFS_STAT_MT_PT (29) - Stat mount point
2148 * the last component in a path, related to mountpoint that we're
2149 * looking for information about
2151 * volume, cell, link data
2153 * \retval EINVAL Error if some of the standard args aren't set
2154 * \retval ENOTDIR Error if the 'mount point' argument isn't a directory
2155 * \retval EIO Error if the link data can't be accessed
2157 * \post Get the volume, and cell, as well as the link data for a mount point
2159 DECL_PIOCTL(PNewStatMount)
2164 struct VenusFid tfid;
2167 struct sysname_info sysState;
2168 afs_size_t offset, len;
2170 AFS_STATCNT(PNewStatMount);
2174 if (afs_pd_getStringPtr(ain, &name) != 0)
2177 code = afs_VerifyVCache(avc, areq);
2180 if (vType(avc) != VDIR) {
2183 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
2186 Check_AtSys(avc, name, &sysState, areq);
2187 ObtainReadLock(&tdc->lock);
2189 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
2190 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
2191 ReleaseReadLock(&tdc->lock);
2192 afs_PutDCache(tdc); /* we're done with the data */
2193 bufp = sysState.name;
2197 tfid.Cell = avc->f.fid.Cell;
2198 tfid.Fid.Volume = avc->f.fid.Fid.Volume;
2199 if (!tfid.Fid.Unique && (avc->f.states & CForeign)) {
2200 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
2202 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
2208 if (tvc->mvstat != 1) {
2213 ObtainWriteLock(&tvc->lock, 226);
2214 code = afs_HandleLink(tvc, areq);
2216 if (tvc->linkData) {
2217 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
2220 /* we have the data */
2221 if (afs_pd_putString(aout, tvc->linkData) != 0)
2227 ReleaseWriteLock(&tvc->lock);
2230 if (sysState.allocked)
2231 osi_FreeLargeSpace(bufp);
2236 * A helper function to get the n'th cell which a particular user has tokens
2237 * for. This is racy. If new tokens are added whilst we're iterating, then
2238 * we may return some cells twice. If tokens expire mid run, then we'll
2239 * miss some cells from our output. So, could be better, but that would
2240 * require an interface change.
2243 static struct unixuser *
2244 getNthCell(afs_int32 uid, afs_int32 iterator) {
2246 struct unixuser *tu = NULL;
2249 ObtainReadLock(&afs_xuser);
2250 for (tu = afs_users[i]; tu; tu = tu->next) {
2251 if (tu->uid == uid && (tu->states & UHasTokens)) {
2252 if (iterator-- == 0)
2253 break; /* are we done yet? */
2259 ReleaseReadLock(&afs_xuser);
2264 * VIOCGETTOK (8) - Get authentication tokens
2268 * \param[in] ain cellid to return tokens for
2269 * \param[out] aout token
2272 * Error if the afs daemon hasn't started yet
2274 * Error if the input parameter is out of the bounds of the available
2277 * Error if there aren't tokens for this cell
2280 * If the input paramater exists, get the token that corresponds to
2281 * the parameter value, if there is no token at this value, get the
2282 * token for the first cell
2284 * \notes "it's a weird interface (from comments in the code)"
2287 DECL_PIOCTL(PGetTokens)
2290 struct unixuser *tu = NULL;
2291 union tokenUnion *token;
2292 afs_int32 iterator = 0;
2297 AFS_STATCNT(PGetTokens);
2298 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2299 return EIO; /* Inappropriate ioctl for device */
2301 /* weird interface. If input parameter is present, it is an integer and
2302 * we're supposed to return the parm'th tokens for this unix uid.
2303 * If not present, we just return tokens for cell 1.
2304 * If counter out of bounds, return EDOM.
2305 * If no tokens for the particular cell, return ENOTCONN.
2306 * Also, if this mysterious parm is present, we return, along with the
2307 * tokens, the primary cell indicator (an afs_int32 0) and the cell name
2308 * at the end, in that order.
2310 newStyle = (afs_pd_remaining(ain) > 0);
2312 if (afs_pd_getInt(ain, &iterator) != 0)
2316 tu = getNthCell(areq->uid, iterator);
2318 cellNum = afs_GetPrimaryCellNum();
2320 tu = afs_FindUser(areq->uid, cellNum, READ_LOCK);
2325 if (!(tu->states & UHasTokens)
2326 || !afs_HasUsableTokens(tu->tokens, osi_Time())) {
2327 tu->states |= (UTokensBad | UNeedsReset);
2328 afs_NotifyUser(tu, UTokensDropped);
2329 afs_PutUser(tu, READ_LOCK);
2332 token = afs_FindToken(tu->tokens, RX_SECIDX_KAD);
2334 /* for compat, we try to return 56 byte tix if they fit */
2335 iterator = token->rxkad.ticketLen;
2337 iterator = 56; /* # of bytes we're returning */
2339 if (afs_pd_putInt(aout, iterator) != 0)
2341 if (afs_pd_putBytes(aout, token->rxkad.ticket, token->rxkad.ticketLen) != 0)
2343 if (token->rxkad.ticketLen < 56) {
2344 /* Tokens are always 56 bytes or larger */
2345 if (afs_pd_skip(aout, iterator - token->rxkad.ticketLen) != 0) {
2350 if (afs_pd_putInt(aout, sizeof(struct ClearToken)) != 0)
2352 if (afs_pd_putBytes(aout, &token->rxkad.clearToken,
2353 sizeof(struct ClearToken)) != 0)
2357 /* put out primary id and cell name, too */
2358 iterator = (tu->states & UPrimary ? 1 : 0);
2359 if (afs_pd_putInt(aout, iterator) != 0)
2361 tcell = afs_GetCell(tu->cell, READ_LOCK);
2363 if (afs_pd_putString(aout, tcell->cellName) != 0)
2365 afs_PutCell(tcell, READ_LOCK);
2367 if (afs_pd_putString(aout, "") != 0)
2370 /* Got here, all is good */
2373 afs_PutUser(tu, READ_LOCK);
2378 * VIOCUNLOG (9) - Invalidate tokens
2382 * \param[in] ain not in use
2383 * \param[out] aout not in use
2385 * \retval EIO Error if the afs daemon hasn't been started yet
2387 * \post remove tokens from a user, specified by the user id
2389 * \notes sets the token's time to 0, which then causes it to be removed
2390 * \notes Unlog is the same as un-pag in OpenAFS
2395 struct unixuser *tu;
2397 AFS_STATCNT(PUnlog);
2398 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2399 return EIO; /* Inappropriate ioctl for device */
2401 i = UHash(areq->uid);
2402 ObtainWriteLock(&afs_xuser, 227);
2403 for (tu = afs_users[i]; tu; tu = tu->next) {
2404 if (tu->uid == areq->uid) {
2405 tu->states &= ~UHasTokens;
2406 afs_FreeTokens(&tu->tokens);
2408 ReleaseWriteLock(&afs_xuser);
2409 afs_NotifyUser(tu, UTokensDropped);
2410 /* We have to drop the lock over the call to afs_ResetUserConns,
2411 * since it obtains the afs_xvcache lock. We could also keep
2412 * the lock, and modify ResetUserConns to take parm saying we
2413 * obtained the lock already, but that is overkill. By keeping
2414 * the "tu" pointer held over the released lock, we guarantee
2415 * that we won't lose our place, and that we'll pass over
2416 * every user conn that existed when we began this call.
2418 afs_ResetUserConns(tu);
2420 ObtainWriteLock(&afs_xuser, 228);
2422 /* set the expire times to 0, causes
2423 * afs_GCUserData to remove this entry
2426 #endif /* UKERNEL */
2429 ReleaseWriteLock(&afs_xuser);
2434 * VIOC_AFS_MARINER_HOST (32) - Get/set mariner (cache manager monitor) host
2438 * \param[in] ain host address to be set
2439 * \param[out] aout old host address
2442 * depending on whether or not a variable is set, either get the host
2443 * for the cache manager monitor, or set the old address and give it
2446 * \notes Errors turn off mariner
2448 DECL_PIOCTL(PMariner)
2450 afs_int32 newHostAddr;
2451 afs_int32 oldHostAddr;
2453 AFS_STATCNT(PMariner);
2455 memcpy((char *)&oldHostAddr, (char *)&afs_marinerHost,
2458 oldHostAddr = 0xffffffff; /* disabled */
2460 if (afs_pd_getInt(ain, &newHostAddr) != 0)
2463 if (newHostAddr == 0xffffffff) {
2464 /* disable mariner operations */
2466 } else if (newHostAddr) {
2468 afs_marinerHost = newHostAddr;
2471 if (afs_pd_putInt(aout, oldHostAddr) != 0)
2478 * VIOCCKSERV (10) - Check that servers are up
2482 * \param[in] ain name of the cell
2483 * \param[out] aout current down server list
2485 * \retval EIO Error if the afs daemon hasn't started yet
2486 * \retval EACCES Error if the user doesn't have super-user credentials
2487 * \retval ENOENT Error if we are unable to obtain the cell
2490 * Either a fast check (where it doesn't contact servers) or a
2491 * local check (checks local cell only)
2493 DECL_PIOCTL(PCheckServers)
2498 char *cellName = NULL;
2500 struct chservinfo *pcheck;
2502 AFS_STATCNT(PCheckServers);
2504 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2505 return EIO; /* Inappropriate ioctl for device */
2507 /* This is tricky, because we need to peak at the datastream to see
2508 * what we're getting. For now, let's cheat. */
2510 /* ain contains either an int32 or a string */
2511 if (ain->remaining == 0)
2514 if (*(afs_int32 *)ain->ptr == 0x12345678) { /* For afs3.3 version */
2515 pcheck = afs_pd_inline(ain, sizeof(*pcheck));
2519 if (pcheck->tinterval >= 0) {
2520 if (afs_pd_putInt(aout, afs_probe_interval) != 0)
2522 if (pcheck->tinterval > 0) {
2523 if (!afs_osi_suser(*acred))
2525 afs_probe_interval = pcheck->tinterval;
2529 temp = pcheck->tflags;
2531 cellName = pcheck->tbuffer;
2532 } else { /* For pre afs3.3 versions */
2533 if (afs_pd_getInt(ain, &temp) != 0)
2535 if (afs_pd_remaining(ain) > 0) {
2536 if (afs_pd_getStringPtr(ain, &cellName) != 0)
2542 * 1: fast check, don't contact servers.
2543 * 2: local cell only.
2546 /* have cell name, too */
2547 cellp = afs_GetCellByName(cellName, READ_LOCK);
2552 if (!cellp && (temp & 2)) {
2553 /* use local cell */
2554 cellp = afs_GetPrimaryCell(READ_LOCK);
2556 if (!(temp & 1)) { /* if not fast, call server checker routine */
2557 afs_CheckServers(1, cellp); /* check down servers */
2558 afs_CheckServers(0, cellp); /* check up servers */
2560 /* now return the current down server list */
2561 ObtainReadLock(&afs_xserver);
2562 for (i = 0; i < NSERVERS; i++) {
2563 for (ts = afs_servers[i]; ts; ts = ts->next) {
2564 if (cellp && ts->cell != cellp)
2565 continue; /* cell spec'd and wrong */
2566 if ((ts->flags & SRVR_ISDOWN)
2567 && ts->addr->sa_portal != ts->cell->vlport) {
2568 afs_pd_putInt(aout, ts->addr->sa_ip);
2572 ReleaseReadLock(&afs_xserver);
2574 afs_PutCell(cellp, READ_LOCK);
2579 * VIOCCKBACK (11) - Check backup volume mappings
2583 * \param[in] ain not in use
2584 * \param[out] aout not in use
2586 * \retval EIO Error if the afs daemon hasn't started yet
2589 * Check the root volume, and then check the names if the volume
2590 * check variable is set to force, has expired, is busy, or if
2591 * the mount points variable is set
2593 DECL_PIOCTL(PCheckVolNames)
2595 AFS_STATCNT(PCheckVolNames);
2596 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2597 return EIO; /* Inappropriate ioctl for device */
2599 afs_CheckRootVolume();
2600 afs_CheckVolumeNames(AFS_VOLCHECK_FORCE | AFS_VOLCHECK_EXPIRED |
2601 AFS_VOLCHECK_BUSY | AFS_VOLCHECK_MTPTS);
2606 * VIOCCKCONN (12) - Check connections for a user
2610 * \param[in] ain not in use
2611 * \param[out] aout not in use
2614 * Error if no user is specififed, the user has no tokens set,
2615 * or if the user's tokens are bad
2618 * check to see if a user has the correct authentication.
2619 * If so, allow access.
2621 * \notes Check the connections to all the servers specified
2623 DECL_PIOCTL(PCheckAuth)
2627 struct afs_conn *tc;
2628 struct unixuser *tu;
2631 AFS_STATCNT(PCheckAuth);
2632 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2633 return EIO; /* Inappropriate ioctl for device */
2636 tu = afs_GetUser(areq->uid, 1, READ_LOCK); /* check local cell authentication */
2640 /* we have a user */
2641 ObtainReadLock(&afs_xsrvAddr);
2642 ObtainReadLock(&afs_xconn);
2644 /* any tokens set? */
2645 if ((tu->states & UHasTokens) == 0)
2647 /* all connections in cell 1 working? */
2648 for (i = 0; i < NSERVERS; i++) {
2649 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2650 for (tc = sa->conns; tc; tc = tc->next) {
2651 if (tc->user == tu && (tu->states & UTokensBad))
2656 ReleaseReadLock(&afs_xsrvAddr);
2657 ReleaseReadLock(&afs_xconn);
2658 afs_PutUser(tu, READ_LOCK);
2660 if (afs_pd_putInt(aout, retValue) != 0)
2666 Prefetch(uparmtype apath, struct afs_ioctl *adata, int afollow,
2671 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2677 AFS_STATCNT(Prefetch);
2680 tp = osi_AllocLargeSpace(1024);
2681 AFS_COPYINSTR(apath, tp, 1024, &bufferSize, code);
2683 osi_FreeLargeSpace(tp);
2686 if (afs_BBusy()) { /* do this as late as possible */
2687 osi_FreeLargeSpace(tp);
2688 return EWOULDBLOCK; /* pretty close */
2690 afs_BQueue(BOP_PATH, (struct vcache *)0, 0, 0, acred, (afs_size_t) 0,
2691 (afs_size_t) 0, tp, (void *)0, (void *)0);
2696 * VIOCWHEREIS (14) - Find out where a volume is located
2700 * \param[in] ain not in use
2701 * \param[out] aout volume location
2703 * \retval EINVAL Error if some of the default arguments don't exist
2704 * \retval ENODEV Error if there is no such volume
2706 * \post fine a volume, based on a volume file id
2708 * \notes check each of the servers specified
2710 DECL_PIOCTL(PFindVolume)
2717 AFS_STATCNT(PFindVolume);
2720 tvp = afs_GetVolume(&avc->f.fid, areq, READ_LOCK);
2724 for (i = 0; i < AFS_MAXHOSTS; i++) {
2725 ts = tvp->serverHost[i];
2728 if (afs_pd_putInt(aout, ts->addr->sa_ip) != 0) {
2733 if (i < AFS_MAXHOSTS) {
2734 /* still room for terminating NULL, add it on */
2735 if (afs_pd_putInt(aout, 0) != 0) {
2741 afs_PutVolume(tvp, READ_LOCK);
2746 * VIOCACCESS (20) - Access using PRS_FS bits
2750 * \param[in] ain PRS_FS bits
2751 * \param[out] aout not in use
2753 * \retval EINVAL Error if some of the initial arguments aren't set
2754 * \retval EACCES Error if access is denied
2756 * \post check to make sure access is allowed
2758 DECL_PIOCTL(PViceAccess)
2763 AFS_STATCNT(PViceAccess);
2767 code = afs_VerifyVCache(avc, areq);
2771 if (afs_pd_getInt(ain, &temp) != 0)
2774 code = afs_AccessOK(avc, temp, areq, CHECK_MODE_BITS);
2782 * VIOC_GETPAG (13) - Get PAG value
2786 * \param[in] ain not in use
2787 * \param[out] aout PAG value or NOPAG
2789 * \post get PAG value for the caller's cred
2791 DECL_PIOCTL(PGetPAG)
2795 pag = PagInCred(*acred);
2797 return afs_pd_putInt(aout, pag);
2800 DECL_PIOCTL(PPrecache)
2804 /*AFS_STATCNT(PPrecache);*/
2805 if (!afs_osi_suser(*acred))
2808 if (afs_pd_getInt(ain, &newValue) != 0)
2811 afs_preCache = newValue*1024;
2816 * VIOCSETCACHESIZE (24) - Set venus cache size in 1000 units
2820 * \param[in] ain the size the venus cache should be set to
2821 * \param[out] aout not in use
2823 * \retval EACCES Error if the user doesn't have super-user credentials
2824 * \retval EROFS Error if the cache is set to be in memory
2827 * Set the cache size based on user input. If no size is given,
2828 * set it to the default OpenAFS cache size.
2831 * recompute the general cache parameters for every single block allocated
2833 DECL_PIOCTL(PSetCacheSize)
2838 AFS_STATCNT(PSetCacheSize);
2840 if (!afs_osi_suser(*acred))
2842 /* too many things are setup initially in mem cache version */
2843 if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
2845 if (afs_pd_getInt(ain, &newValue) != 0)
2848 afs_cacheBlocks = afs_stats_cmperf.cacheBlocksOrig;
2850 if (newValue < afs_min_cache)
2851 afs_cacheBlocks = afs_min_cache;
2853 afs_cacheBlocks = newValue;
2855 afs_stats_cmperf.cacheBlocksTotal = afs_cacheBlocks;
2856 afs_ComputeCacheParms(); /* recompute basic cache parameters */
2857 afs_MaybeWakeupTruncateDaemon();
2858 while (waitcnt++ < 100 && afs_cacheBlocks < afs_blocksUsed) {
2859 afs_osi_Wait(1000, 0, 0);
2860 afs_MaybeWakeupTruncateDaemon();
2865 #define MAXGCSTATS 16
2867 * VIOCGETCACHEPARMS (40) - Get cache stats
2871 * \param[in] ain afs index flags
2872 * \param[out] aout cache blocks, blocks used, blocks files (in an array)
2874 * \post Get the cache blocks, and how many of the cache blocks there are
2876 DECL_PIOCTL(PGetCacheSize)
2878 afs_int32 results[MAXGCSTATS];
2880 struct dcache * tdc;
2883 AFS_STATCNT(PGetCacheSize);
2885 if (afs_pd_remaining(ain) == sizeof(afs_int32)) {
2886 afs_pd_getInt(ain, &flags); /* can't error, we just checked size */
2887 } else if (afs_pd_remaining(ain) == 0) {
2893 memset(results, 0, sizeof(results));
2894 results[0] = afs_cacheBlocks;
2895 results[1] = afs_blocksUsed;
2896 results[2] = afs_cacheFiles;
2899 for (i = 0; i < afs_cacheFiles; i++) {
2900 if (afs_indexFlags[i] & IFFree) results[3]++;
2902 } else if (2 == flags){
2903 for (i = 0; i < afs_cacheFiles; i++) {
2904 if (afs_indexFlags[i] & IFFree) results[3]++;
2905 if (afs_indexFlags[i] & IFEverUsed) results[4]++;
2906 if (afs_indexFlags[i] & IFDataMod) results[5]++;
2907 if (afs_indexFlags[i] & IFDirtyPages) results[6]++;
2908 if (afs_indexFlags[i] & IFAnyPages) results[7]++;
2909 if (afs_indexFlags[i] & IFDiscarded) results[8]++;
2911 tdc = afs_indexTable[i];
2914 size = tdc->validPos;
2915 if ( 0 < size && size < (1<<12) ) results[10]++;
2916 else if (size < (1<<14) ) results[11]++;
2917 else if (size < (1<<16) ) results[12]++;
2918 else if (size < (1<<18) ) results[13]++;
2919 else if (size < (1<<20) ) results[14]++;
2920 else if (size >= (1<<20) ) results[15]++;
2924 return afs_pd_putBytes(aout, results, sizeof(results));
2928 * VIOCFLUSHCB (25) - Flush callback only
2932 * \param[in] ain not in use
2933 * \param[out] aout not in use
2935 * \retval EINVAL Error if some of the standard args aren't set
2936 * \retval 0 0 returned if the volume is set to read-only
2939 * Flushes callbacks, by setting the length of callbacks to one,
2940 * setting the next callback to be sent to the CB_DROPPED value,
2941 * and then dequeues everything else.
2943 DECL_PIOCTL(PRemoveCallBack)
2945 struct afs_conn *tc;
2947 struct AFSCallBack CallBacks_Array[1];
2948 struct AFSCBFids theFids;
2949 struct AFSCBs theCBs;
2952 AFS_STATCNT(PRemoveCallBack);
2955 if (avc->f.states & CRO)
2956 return 0; /* read-only-ness can't change */
2957 ObtainWriteLock(&avc->lock, 229);
2958 theFids.AFSCBFids_len = 1;
2959 theCBs.AFSCBs_len = 1;
2960 theFids.AFSCBFids_val = (struct AFSFid *)&avc->f.fid.Fid;
2961 theCBs.AFSCBs_val = CallBacks_Array;
2962 CallBacks_Array[0].CallBackType = CB_DROPPED;
2963 if (avc->callback) {
2965 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
2967 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
2969 code = RXAFS_GiveUpCallBacks(tc->id, &theFids, &theCBs);
2973 /* don't set code on failure since we wouldn't use it */
2974 } while (afs_Analyze
2975 (tc, code, &avc->f.fid, areq,
2976 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK, NULL));
2978 ObtainWriteLock(&afs_xcbhash, 457);
2979 afs_DequeueCallback(avc);
2981 avc->f.states &= ~(CStatd | CUnique);
2982 ReleaseWriteLock(&afs_xcbhash);
2983 if (avc->f.fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
2984 osi_dnlc_purgedp(avc);
2986 ReleaseWriteLock(&avc->lock);
2991 * VIOCNEWCELL (26) - Configure new cell
2996 * the name of the cell, the hosts that will be a part of the cell,
2997 * whether or not it's linked with another cell, the other cell it's
2998 * linked with, the file server port, and the volume server port
3002 * \retval EIO Error if the afs daemon hasn't started yet
3003 * \retval EACCES Error if the user doesn't have super-user cedentials
3004 * \retval EINVAL Error if some 'magic' var doesn't have a certain bit set
3006 * \post creates a new cell
3008 DECL_PIOCTL(PNewCell)
3010 afs_int32 cellHosts[AFS_MAXCELLHOSTS], magic = 0;
3011 char *newcell = NULL;
3012 char *linkedcell = NULL;
3014 afs_int32 linkedstate = 0;
3015 afs_int32 fsport = 0, vlport = 0;
3018 AFS_STATCNT(PNewCell);
3019 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3020 return EIO; /* Inappropriate ioctl for device */
3022 if (!afs_osi_suser(*acred))
3025 if (afs_pd_getInt(ain, &magic) != 0)
3027 if (magic != 0x12345678)
3030 /* A 3.4 fs newcell command will pass an array of AFS_MAXCELLHOSTS
3031 * server addresses while the 3.5 fs newcell command passes
3032 * AFS_MAXHOSTS. To figure out which is which, check if the cellname
3035 * This whole logic is bogus, because it relies on the newer command
3036 * sending its 12th address as 0.
3038 if ((afs_pd_remaining(ain) < AFS_MAXCELLHOSTS +3) * sizeof(afs_int32))
3041 newcell = afs_pd_where(ain) + (AFS_MAXCELLHOSTS + 3) * sizeof(afs_int32);
3042 if (newcell[0] != '\0') {
3045 skip = AFS_MAXHOSTS - AFS_MAXCELLHOSTS;
3048 /* AFS_MAXCELLHOSTS (=8) is less than AFS_MAXHOSTS (=13) */
3049 if (afs_pd_getBytes(ain, &cellHosts,
3050 AFS_MAXCELLHOSTS * sizeof(afs_int32)) != 0)
3052 if (afs_pd_skip(ain, skip * sizeof(afs_int32)) !=0)
3055 if (afs_pd_getInt(ain, &fsport) != 0)
3058 fsport = 0; /* Privileged ports not allowed */
3060 if (afs_pd_getInt(ain, &vlport) != 0)
3063 vlport = 0; /* Privileged ports not allowed */
3065 if (afs_pd_getInt(ain, &ls) != 0)
3068 if (afs_pd_getStringPtr(ain, &newcell) != 0)
3072 if (afs_pd_getStringPtr(ain, &linkedcell) != 0)
3074 linkedstate |= CLinkedCell;
3077 linkedstate |= CNoSUID; /* setuid is disabled by default for fs newcell */
3079 afs_NewCell(newcell, cellHosts, linkedstate, linkedcell, fsport,
3084 DECL_PIOCTL(PNewAlias)
3086 /* create a new cell alias */
3087 char *realName, *aliasName;
3089 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3090 return EIO; /* Inappropriate ioctl for device */
3092 if (!afs_osi_suser(*acred))
3095 if (afs_pd_getStringPtr(ain, &aliasName) != 0)
3097 if (afs_pd_getStringPtr(ain, &realName) != 0)
3100 return afs_NewCellAlias(aliasName, realName);
3104 * VIOCGETCELL (27) - Get cell info
3108 * \param[in] ain The cell index of a specific cell
3109 * \param[out] aout list of servers in the cell
3111 * \retval EIO Error if the afs daemon hasn't started yet
3112 * \retval EDOM Error if there is no cell asked about
3114 * \post Lists the cell's server names and and addresses
3116 DECL_PIOCTL(PListCells)
3118 afs_int32 whichCell;
3119 struct cell *tcell = 0;
3123 AFS_STATCNT(PListCells);
3124 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3125 return EIO; /* Inappropriate ioctl for device */
3127 if (afs_pd_getInt(ain, &whichCell) != 0)
3130 tcell = afs_GetCellByIndex(whichCell, READ_LOCK);
3136 for (i = 0; i < AFS_MAXCELLHOSTS; i++) {
3137 if (tcell->cellHosts[i] == 0)
3139 if (afs_pd_putInt(aout, tcell->cellHosts[i]->addr->sa_ip) != 0)
3142 for (;i < AFS_MAXCELLHOSTS; i++) {
3143 if (afs_pd_putInt(aout, 0) != 0)
3146 if (afs_pd_putString(aout, tcell->cellName) != 0)
3151 afs_PutCell(tcell, READ_LOCK);
3155 DECL_PIOCTL(PListAliases)
3157 afs_int32 whichAlias;
3158 struct cell_alias *tcalias = 0;
3161 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3162 return EIO; /* Inappropriate ioctl for device */
3164 if (afs_pd_getInt(ain, &whichAlias) != 0)
3167 tcalias = afs_GetCellAlias(whichAlias);
3168 if (tcalias == NULL)
3172 if (afs_pd_putString(aout, tcalias->alias) != 0)
3174 if (afs_pd_putString(aout, tcalias->cell) != 0)
3179 afs_PutCellAlias(tcalias);
3184 * VIOC_AFS_DELETE_MT_PT (28) - Delete mount point
3188 * \param[in] ain the name of the file in this dir to remove
3189 * \param[out] aout not in use
3192 * Error if some of the standard args aren't set
3194 * Error if the argument to remove is not a directory
3196 * Error if there is no cache to remove the mount point from or
3197 * if a vcache doesn't exist
3200 * Ensure that everything is OK before deleting the mountpoint.
3201 * If not, don't delete. Delete a mount point based on a file id.
3203 DECL_PIOCTL(PRemoveMount)
3208 struct sysname_info sysState;
3209 afs_size_t offset, len;
3210 struct afs_conn *tc;
3213 struct AFSFetchStatus OutDirStatus;
3214 struct VenusFid tfid;
3215 struct AFSVolSync tsync;
3218 /* "ain" is the name of the file in this dir to remove */
3220 AFS_STATCNT(PRemoveMount);
3223 if (afs_pd_getStringPtr(ain, &name) != 0)
3226 code = afs_VerifyVCache(avc, areq);
3229 if (vType(avc) != VDIR)
3232 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1); /* test for error below */
3235 Check_AtSys(avc, name, &sysState, areq);
3236 ObtainReadLock(&tdc->lock);
3238 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
3239 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
3240 ReleaseReadLock(&tdc->lock);
3241 bufp = sysState.name;
3246 tfid.Cell = avc->f.fid.Cell;
3247 tfid.Fid.Volume = avc->f.fid.Fid.Volume;
3248 if (!tfid.Fid.Unique && (avc->f.states & CForeign)) {
3249 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
3251 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3258 if (tvc->mvstat != 1) {
3264 ObtainWriteLock(&tvc->lock, 230);
3265 code = afs_HandleLink(tvc, areq);
3267 if (tvc->linkData) {
3268 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
3273 ReleaseWriteLock(&tvc->lock);
3274 osi_dnlc_purgedp(tvc);
3280 ObtainWriteLock(&avc->lock, 231);
3281 osi_dnlc_remove(avc, bufp, tvc);
3283 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
3285 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE);
3288 RXAFS_RemoveFile(tc->id, (struct AFSFid *)&avc->f.fid.Fid, bufp,
3289 &OutDirStatus, &tsync);
3294 } while (afs_Analyze
3295 (tc, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_REMOVEFILE,
3296 SHARED_LOCK, NULL));
3301 ReleaseWriteLock(&avc->lock);
3305 /* we have the thing in the cache */
3306 ObtainWriteLock(&tdc->lock, 661);
3307 if (afs_LocalHero(avc, tdc, &OutDirStatus, 1)) {
3308 /* we can do it locally */
3309 code = afs_dir_Delete(tdc, bufp);
3311 ZapDCE(tdc); /* surprise error -- invalid value */
3315 ReleaseWriteLock(&tdc->lock);
3316 afs_PutDCache(tdc); /* drop ref count */
3318 avc->f.states &= ~CUnique; /* For the dfs xlator */
3319 ReleaseWriteLock(&avc->lock);
3322 if (sysState.allocked)
3323 osi_FreeLargeSpace(bufp);
3328 * VIOC_GETCELLSTATUS (35) - Get cell status info
3332 * \param[in] ain The cell you want status information on
3333 * \param[out] aout cell state (as a struct)
3335 * \retval EIO Error if the afs daemon hasn't started yet
3336 * \retval ENOENT Error if the cell doesn't exist
3338 * \post Returns the state of the cell as defined in a struct cell
3340 DECL_PIOCTL(PGetCellStatus)
3346 AFS_STATCNT(PGetCellStatus);
3347 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3348 return EIO; /* Inappropriate ioctl for device */
3350 if (afs_pd_getStringPtr(ain, &cellName) != 0)
3353 tcell = afs_GetCellByName(cellName, READ_LOCK);
3356 temp = tcell->states;
3357 afs_PutCell(tcell, READ_LOCK);
3359 return afs_pd_putInt(aout, temp);
3363 * VIOC_SETCELLSTATUS (36) - Set corresponding info
3368 * The cell you want to set information about, and the values you
3373 * \retval EIO Error if the afs daemon hasn't started yet
3374 * \retval EACCES Error if the user doesn't have super-user credentials
3377 * Set the state of the cell in a defined struct cell, based on
3378 * whether or not SetUID is allowed
3380 DECL_PIOCTL(PSetCellStatus)
3384 afs_int32 flags0, flags1;
3386 if (!afs_osi_suser(*acred))
3388 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3389 return EIO; /* Inappropriate ioctl for device */
3391 if (afs_pd_getInt(ain, &flags0) != 0)
3393 if (afs_pd_getInt(ain, &flags1) != 0)
3395 if (afs_pd_getStringPtr(ain, &cellName) != 0)
3398 tcell = afs_GetCellByName(cellName, WRITE_LOCK);
3401 if (flags0 & CNoSUID)
3402 tcell->states |= CNoSUID;
3404 tcell->states &= ~CNoSUID;
3405 afs_PutCell(tcell, WRITE_LOCK);
3410 * VIOC_FLUSHVOLUME (37) - Flush whole volume's data
3414 * \param[in] ain not in use (args in avc)
3415 * \param[out] aout not in use
3417 * \retval EINVAL Error if some of the standard args aren't set
3418 * \retval EIO Error if the afs daemon hasn't started yet
3421 * Flush all cached contents of a volume. Exactly what stays and what
3422 * goes depends on the platform.
3425 * Does not flush a file that a user has open and is using, because
3426 * it will be re-created on next write. Also purges the dnlc,
3427 * because things are screwed up.
3429 DECL_PIOCTL(PFlushVolumeData)
3435 afs_int32 cell, volume;
3436 struct afs_q *tq, *uq;
3437 #ifdef AFS_DARWIN80_ENV
3441 AFS_STATCNT(PFlushVolumeData);
3444 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3445 return EIO; /* Inappropriate ioctl for device */
3447 volume = avc->f.fid.Fid.Volume; /* who to zap */
3448 cell = avc->f.fid.Cell;
3451 * Clear stat'd flag from all vnodes from this volume; this will
3452 * invalidate all the vcaches associated with the volume.
3455 ObtainReadLock(&afs_xvcache);
3456 i = VCHashV(&avc->f.fid);
3457 for (tq = afs_vhashTV[i].prev; tq != &afs_vhashTV[i]; tq = uq) {
3460 if (tvc->f.fid.Fid.Volume == volume && tvc->f.fid.Cell == cell) {
3461 if (tvc->f.states & CVInit) {
3462 ReleaseReadLock(&afs_xvcache);
3463 afs_osi_Sleep(&tvc->f.states);
3466 #ifdef AFS_DARWIN80_ENV
3467 if (tvc->f.states & CDeadVnode) {
3468 if (!(tvc->f.states & CBulkFetching)) {
3469 ReleaseReadLock(&afs_xvcache);
3470 afs_osi_Sleep(&tvc->f.states);
3477 if (vnode_ref(vp)) {
3483 if (tvc->f.states & (CBulkFetching|CDeadVnode)) {
3485 vnode_recycle(AFSTOV(tvc));
3491 ReleaseReadLock(&afs_xvcache);
3492 #ifdef AFS_BOZONLOCK_ENV
3493 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
3495 ObtainWriteLock(&tvc->lock, 232);
3497 ObtainWriteLock(&afs_xcbhash, 458);
3498 afs_DequeueCallback(tvc);
3499 tvc->f.states &= ~(CStatd | CDirty);
3500 ReleaseWriteLock(&afs_xcbhash);
3501 if (tvc->f.fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
3502 osi_dnlc_purgedp(tvc);
3503 afs_TryToSmush(tvc, *acred, 1);
3504 ReleaseWriteLock(&tvc->lock);
3505 #ifdef AFS_BOZONLOCK_ENV
3506 afs_BozonUnlock(&tvc->pvnLock, tvc);
3508 #ifdef AFS_DARWIN80_ENV
3509 vnode_put(AFSTOV(tvc));
3511 ObtainReadLock(&afs_xvcache);
3513 /* our tvc ptr is still good until now */
3517 ReleaseReadLock(&afs_xvcache);
3520 ObtainWriteLock(&afs_xdcache, 328); /* needed to flush any stuff */
3521 for (i = 0; i < afs_cacheFiles; i++) {
3522 if (!(afs_indexFlags[i] & IFEverUsed))
3523 continue; /* never had any data */
3524 tdc = afs_GetDSlot(i, NULL);
3525 if (tdc->refCount <= 1) { /* too high, in use by running sys call */
3526 ReleaseReadLock(&tdc->tlock);
3527 if (tdc->f.fid.Fid.Volume == volume && tdc->f.fid.Cell == cell) {
3528 if (!(afs_indexFlags[i] & IFDataMod)) {
3529 /* if the file is modified, but has a ref cnt of only 1,
3530 * then someone probably has the file open and is writing
3531 * into it. Better to skip flushing such a file, it will be
3532 * brought back immediately on the next write anyway.
3534 * If we *must* flush, then this code has to be rearranged
3535 * to call afs_storeAllSegments() first */
3536 afs_FlushDCache(tdc);
3540 ReleaseReadLock(&tdc->tlock);
3542 afs_PutDCache(tdc); /* bumped by getdslot */
3544 ReleaseWriteLock(&afs_xdcache);
3546 ObtainReadLock(&afs_xvolume);
3547 for (i = 0; i < NVOLS; i++) {
3548 for (tv = afs_volumes[i]; tv; tv = tv->next) {
3549 if (tv->volume == volume) {
3550 afs_ResetVolumeInfo(tv);
3555 ReleaseReadLock(&afs_xvolume);
3557 /* probably, a user is doing this, probably, because things are screwed up.
3558 * maybe it's the dnlc's fault? */
3565 * VIOCGETVCXSTATUS (41) - gets vnode x status
3570 * not in use (avc used)
3572 * vcxstat: the file id, the data version, any lock, the parent vnode,
3573 * the parent unique id, the trunc position, the callback, cbExpires,
3574 * what access is being made, what files are open,
3575 * any users executing/writing, the flock count, the states,
3579 * Error if some of the initial default arguments aren't set
3581 * Error if access to check the mode bits is denied
3584 * gets stats for the vnode, a struct listed in vcxstat
3586 DECL_PIOCTL(PGetVnodeXStatus)
3589 struct vcxstat stat;
3592 /* AFS_STATCNT(PGetVnodeXStatus); */
3595 code = afs_VerifyVCache(avc, areq);
3598 if (vType(avc) == VDIR)
3599 mode = PRSFS_LOOKUP;
3602 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
3605 memset(&stat, 0, sizeof(struct vcxstat));
3606 stat.fid = avc->f.fid;
3607 hset32(stat.DataVersion, hgetlo(avc->f.m.DataVersion));
3608 stat.lock = avc->lock;
3609 stat.parentVnode = avc->f.parent.vnode;
3610 stat.parentUnique = avc->f.parent.unique;
3611 hset(stat.flushDV, avc->flushDV);
3612 hset(stat.mapDV, avc->mapDV);
3613 stat.truncPos = avc->f.truncPos;
3614 { /* just grab the first two - won't break anything... */
3615 struct axscache *ac;
3617 for (i = 0, ac = avc->Access; ac && i < CPSIZE; i++, ac = ac->next) {
3618 stat.randomUid[i] = ac->uid;
3619 stat.randomAccess[i] = ac->axess;
3622 stat.callback = afs_data_pointer_to_int32(avc->callback);
3623 stat.cbExpires = avc->cbExpires;
3624 stat.anyAccess = avc->f.anyAccess;
3625 stat.opens = avc->opens;
3626 stat.execsOrWriters = avc->execsOrWriters;
3627 stat.flockCount = avc->flockCount;
3628 stat.mvstat = avc->mvstat;
3629 stat.states = avc->f.states;
3630 return afs_pd_putBytes(aout, &stat, sizeof(struct vcxstat));
3634 DECL_PIOCTL(PGetVnodeXStatus2)
3637 struct vcxstat2 stat;
3642 code = afs_VerifyVCache(avc, areq);
3645 if (vType(avc) == VDIR)
3646 mode = PRSFS_LOOKUP;
3649 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
3652 memset(&stat, 0, sizeof(struct vcxstat2));
3654 stat.cbExpires = avc->cbExpires;
3655 stat.anyAccess = avc->f.anyAccess;
3656 stat.mvstat = avc->mvstat;
3657 stat.callerAccess = afs_GetAccessBits(avc, ~0, areq);
3659 return afs_pd_putBytes(aout, &stat, sizeof(struct vcxstat2));
3664 * VIOC_AFS_SYSNAME (38) - Change @sys value
3668 * \param[in] ain new value for @sys
3669 * \param[out] aout count, entry, list (debug values?)
3672 * Error if afsd isn't running, the new sysname is too large,
3673 * the new sysname causes issues (starts with a . or ..),
3674 * there is no PAG set in the credentials, or the user of a PAG
3677 * Error if the user doesn't have super-user credentials
3680 * Set the value of @sys if these things work: if the input isn't
3681 * too long or if input doesn't start with . or ..
3684 * We require root for local sysname changes, but not for remote
3685 * (since we don't really believe remote uids anyway)
3686 * outname[] shouldn't really be needed- this is left as an
3687 * exercise for the reader.
3689 DECL_PIOCTL(PSetSysName)
3691 char *inname = NULL;
3692 char outname[MAXSYSNAME];
3693 afs_int32 setsysname;
3695 struct afs_exporter *exporter;
3696 struct unixuser *au;
3697 afs_int32 pag, error;
3698 int t, count, num = 0, allpags = 0;
3700 struct afs_pdata validate;
3702 AFS_STATCNT(PSetSysName);
3703 if (!afs_globalVFS) {
3704 /* Afsd is NOT running; disable it */
3705 #if defined(KERNEL_HAVE_UERROR)
3706 return (setuerror(EINVAL), EINVAL);
3711 if (afs_pd_getInt(ain, &setsysname) != 0)
3713 if (setsysname & 0x8000) {
3715 setsysname &= ~0x8000;
3720 if (setsysname < 0 || setsysname > MAXNUMSYSNAMES)
3723 for (count = 0; count < setsysname; count++) {
3724 if (afs_pd_getStringPtr(&validate, &inname) != 0)
3727 if (t >= MAXSYSNAME || t <= 0)
3729 /* check for names that can shoot us in the foot */
3730 if (inname[0] == '.' && (inname[1] == 0
3731 || (inname[1] == '.' && inname[2] == 0)))
3734 /* args ok, so go back to the beginning of that section */
3736 if (afs_pd_getStringPtr(ain, &inname) != 0)
3740 if (afs_cr_gid(*acred) == RMTUSER_REQ ||
3741 afs_cr_gid(*acred) == RMTUSER_REQ_PRIV) { /* Handles all exporters */
3742 if (allpags && afs_cr_gid(*acred) != RMTUSER_REQ_PRIV) {
3745 pag = PagInCred(*acred);
3747 return EINVAL; /* Better than panicing */
3749 if (!(au = afs_FindUser(pag, -1, READ_LOCK))) {
3750 return EINVAL; /* Better than panicing */
3752 if (!(exporter = au->exporter)) {
3753 afs_PutUser(au, READ_LOCK);
3754 return EINVAL; /* Better than panicing */
3756 error = EXP_SYSNAME(exporter, inname, &sysnamelist,
3759 if (error == ENODEV)
3760 foundname = 0; /* sysname not set yet! */
3762 afs_PutUser(au, READ_LOCK);
3767 strcpy(outname, sysnamelist[0]);
3769 afs_PutUser(au, READ_LOCK);
3773 /* Not xlating, so local case */
3775 osi_Panic("PSetSysName: !afs_sysname\n");
3776 if (!setsysname) { /* user just wants the info */
3777 strcpy(outname, afs_sysname);
3778 foundname = afs_sysnamecount;
3779 sysnamelist = afs_sysnamelist;
3780 } else { /* Local guy; only root can change sysname */
3781 if (!afs_osi_suser(*acred))
3784 /* allpags makes no sense for local use */
3788 /* clear @sys entries from the dnlc, once afs_lookup can
3789 * do lookups of @sys entries and thinks it can trust them */
3790 /* privs ok, store the entry, ... */
3792 if (strlen(inname) >= MAXSYSNAME-1)
3794 strcpy(afs_sysname, inname);
3796 if (setsysname > 1) { /* ... or list */
3797 for (count = 1; count < setsysname; ++count) {
3798 if (!afs_sysnamelist[count])
3800 ("PSetSysName: no afs_sysnamelist entry to write\n");
3801 if (afs_pd_getString(ain, afs_sysnamelist[count],
3806 afs_sysnamecount = setsysname;
3811 if (afs_pd_putInt(aout, foundname) != 0)
3814 if (afs_pd_putString(aout, outname) != 0)
3816 for (count = 1; count < foundname; ++count) { /* ... or list. */
3817 if (!sysnamelist[count])
3819 ("PSetSysName: no afs_sysnamelist entry to read\n");
3820 t = strlen(sysnamelist[count]);
3821 if (t >= MAXSYSNAME)
3822 osi_Panic("PSetSysName: sysname entry garbled\n");
3823 if (afs_pd_putString(aout, sysnamelist[count]) != 0)
3831 /* sequential search through the list of touched cells is not a good
3832 * long-term solution here. For small n, though, it should be just
3833 * fine. Should consider special-casing the local cell for large n.
3834 * Likewise for PSetSPrefs.
3836 * s - number of ids in array l[] -- NOT index of last id
3837 * l - array of cell ids which have volumes that need to be sorted
3838 * vlonly - sort vl servers or file servers?
3841 ReSortCells_cb(struct cell *cell, void *arg)
3843 afs_int32 *p = (afs_int32 *) arg;
3844 afs_int32 *l = p + 1;
3847 for (i = 0; i < s; i++) {
3848 if (l[i] == cell->cellNum) {
3849 ObtainWriteLock(&cell->lock, 690);
3850 afs_SortServers(cell->cellHosts, AFS_MAXCELLHOSTS);
3851 ReleaseWriteLock(&cell->lock);
3859 ReSortCells(int s, afs_int32 * l, int vlonly)
3867 p = (afs_int32 *) afs_osi_Alloc(sizeof(afs_int32) * (s + 1));
3869 memcpy(p + 1, l, s * sizeof(afs_int32));
3870 afs_TraverseCells(&ReSortCells_cb, p);
3871 afs_osi_Free(p, sizeof(afs_int32) * (s + 1));
3875 ObtainReadLock(&afs_xvolume);
3876 for (i = 0; i < NVOLS; i++) {
3877 for (j = afs_volumes[i]; j; j = j->next) {
3878 for (k = 0; k < s; k++)
3879 if (j->cell == l[k]) {
3880 ObtainWriteLock(&j->lock, 233);
3881 afs_SortServers(j->serverHost, AFS_MAXHOSTS);
3882 ReleaseWriteLock(&j->lock);
3887 ReleaseReadLock(&afs_xvolume);
3891 static int debugsetsp = 0;
3893 afs_setsprefs(struct spref *sp, unsigned int num, unsigned int vlonly)
3896 int i, j, k, matches, touchedSize;
3897 struct server *srvr = NULL;
3898 afs_int32 touched[34];
3902 for (k = 0; k < num; sp++, k++) {
3904 afs_warn("sp host=%x, rank=%d\n", sp->host.s_addr, sp->rank);
3907 ObtainReadLock(&afs_xserver);
3909 i = SHash(sp->host.s_addr);
3910 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3911 if (sa->sa_ip == sp->host.s_addr) {
3913 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
3914 || (sa->sa_portal == AFS_FSPORT);
3915 if ((!vlonly && isfs) || (vlonly && !isfs)) {
3922 if (sa && matches) { /* found one! */
3924 afs_warn("sa ip=%x, ip_rank=%d\n", sa->sa_ip, sa->sa_iprank);
3926 sa->sa_iprank = sp->rank + afs_randomMod15();
3927 afs_SortOneServer(sa->server);
3930 /* if we don't know yet what cell it's in, this is moot */
3931 for (j = touchedSize - 1;
3932 j >= 0 && touched[j] != srvr->cell->cellNum; j--)
3933 /* is it in our list of touched cells ? */ ;
3934 if (j < 0) { /* no, it's not */
3935 touched[touchedSize++] = srvr->cell->cellNum;
3936 if (touchedSize >= 32) { /* watch for ovrflow */
3937 ReleaseReadLock(&afs_xserver);
3938 ReSortCells(touchedSize, touched, vlonly);
3940 ObtainReadLock(&afs_xserver);
3946 ReleaseReadLock(&afs_xserver);
3947 /* if we didn't find one, start to create one. */
3948 /* Note that it doesn't have a cell yet... */
3950 afs_uint32 temp = sp->host.s_addr;
3952 afs_GetServer(&temp, 1, 0, (vlonly ? AFS_VLPORT : AFS_FSPORT),
3953 WRITE_LOCK, (afsUUID *) 0, 0);
3954 srvr->addr->sa_iprank = sp->rank + afs_randomMod15();
3955 afs_PutServer(srvr, WRITE_LOCK);
3957 } /* for all cited preferences */
3959 ReSortCells(touchedSize, touched, vlonly);
3964 * VIOC_SETPREFS (46) - Set server ranks
3966 * \param[in] ain the sprefs value you want the sprefs to be set to
3967 * \param[out] aout not in use
3970 * Error if the afs daemon hasn't started yet
3972 * Error if the user doesn't have super-user credentials
3974 * Error if the struct setsprefs is too large or if it multiplied
3975 * by the number of servers is too large
3977 * \post set the sprefs using the afs_setsprefs() function
3979 DECL_PIOCTL(PSetSPrefs)
3981 struct setspref *ssp;
3985 AFS_STATCNT(PSetSPrefs);
3987 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3988 return EIO; /* Inappropriate ioctl for device */
3990 if (!afs_osi_suser(*acred))
3993 /* The I/O handling here is ghastly, as it relies on overrunning the ends
3994 * of arrays. But, i'm not quite brave enough to change it yet. */
3996 ainSize = ain->remaining;
3998 if (ainSize < sizeof(struct setspref))
4001 ssp = (struct setspref *)ainPtr;
4002 if (ainSize < (sizeof(struct setspref)
4003 + sizeof(struct spref) * ssp->num_servers-1))
4006 afs_setsprefs(&(ssp->servers[0]), ssp->num_servers,
4007 (ssp->flags & DBservers));
4012 * VIOC_SETPREFS33 (42) - Set server ranks (deprecated)
4014 * \param[in] ain the server preferences to be set
4015 * \param[out] aout not in use
4017 * \retval EIO Error if the afs daemon hasn't started yet
4018 * \retval EACCES Error if the user doesn't have super-user credentials
4020 * \post set the server preferences, calling a function
4022 * \notes this may only be performed by the local root user.
4024 DECL_PIOCTL(PSetSPrefs33)
4026 AFS_STATCNT(PSetSPrefs);
4027 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4028 return EIO; /* Inappropriate ioctl for device */
4031 if (!afs_osi_suser(*acred))
4034 afs_setsprefs((struct spref *)afs_pd_where(ain),
4035 afs_pd_remaining(ain) / sizeof(struct spref),
4041 * VIOC_GETSPREFS (43) - Get server ranks
4045 * \param[in] ain the server preferences to get
4046 * \param[out] aout the server preferences information
4048 * \retval EIO Error if the afs daemon hasn't started yet
4049 * \retval ENOENT Error if the sprefrequest is too large
4051 * \post Get the sprefs
4054 * in the hash table of server structs, all servers with the same
4055 * IP address; will be on the same overflow chain; This could be
4056 * sped slightly in some circumstances by having it cache the
4057 * immediately previous slot in the hash table and some
4058 * supporting information; Only reports file servers now.
4060 DECL_PIOCTL(PGetSPrefs)
4062 struct sprefrequest spin; /* input */
4063 struct sprefinfo *spout; /* output */
4064 struct spref *srvout; /* one output component */
4065 int i, j; /* counters for hash table traversal */
4066 struct server *srvr; /* one of CM's server structs */
4068 int vlonly; /* just return vlservers ? */
4071 AFS_STATCNT(PGetSPrefs);
4072 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4073 return EIO; /* Inappropriate ioctl for device */
4075 /* Work out from the size whether we've got a new, or old, style pioctl */
4076 if (afs_pd_remaining(ain) < sizeof(struct sprefrequest)) {
4077 if (afs_pd_getBytes(ain, &spin, sizeof(struct sprefrequest_33)) != 0)
4082 if (afs_pd_getBytes(ain, &spin, sizeof(struct sprefrequest)) != 0)
4084 vlonly = (spin.flags & DBservers);
4087 /* This code relies on overflowing arrays. It's ghastly, but I'm not
4088 * quite brave enough to tackle it yet ...
4091 /* struct sprefinfo includes 1 server struct... that size gets added
4092 * in during the loop that follows.
4094 spout = afs_pd_inline(aout,
4095 sizeof(struct sprefinfo) - sizeof(struct spref));
4096 spout->next_offset = spin.offset;
4097 spout->num_servers = 0;
4098 srvout = spout->servers;
4100 ObtainReadLock(&afs_xserver);
4101 for (i = 0, j = 0; j < NSERVERS; j++) { /* sift through hash table */
4102 for (sa = afs_srvAddrs[j]; sa; sa = sa->next_bkt, i++) {
4103 if (spin.offset > (unsigned short)i) {
4104 continue; /* catch up to where we left off */
4106 spout->next_offset++;
4109 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
4110 || (sa->sa_portal == AFS_FSPORT);
4112 if ((vlonly && isfs) || (!vlonly && !isfs)) {
4113 /* only report ranks for vl servers */
4117 /* Check we've actually got the space we're about to use */
4118 if (afs_pd_inline(aout, sizeof(struct spref)) == NULL) {
4119 ReleaseReadLock(&afs_xserver); /* no more room! */
4123 srvout->host.s_addr = sa->sa_ip;
4124 srvout->rank = sa->sa_iprank;
4125 spout->num_servers++;
4129 ReleaseReadLock(&afs_xserver);
4131 spout->next_offset = 0; /* start over from the beginning next time */
4136 /* Enable/Disable the specified exporter. Must be root to disable an exporter */
4137 int afs_NFSRootOnly = 1;
4139 * VIOC_EXPORTAFS (39) - Export afs to nfs clients
4144 * an integer containing the desired exportee flags
4146 * an integer containing the current exporter flags
4148 * \retval ENODEV Error if the exporter doesn't exist
4149 * \retval EACCES Error if the user doesn't have super-user credentials
4152 * Changes the state of various values to reflect the change
4153 * of the export values between nfs and afs.
4155 * \notes Legacy code obtained from IBM.
4157 DECL_PIOCTL(PExportAfs)
4159 afs_int32 export, newint = 0;
4160 afs_int32 type, changestate, handleValue, convmode, pwsync, smounts;
4161 afs_int32 rempags = 0, pagcb = 0;
4162 struct afs_exporter *exporter;
4164 AFS_STATCNT(PExportAfs);
4165 if (afs_pd_getInt(ain, &handleValue) != 0)
4167 type = handleValue >> 24;
4172 exporter = exporter_find(type);
4174 export = handleValue & 3;
4175 changestate = handleValue & 0xfff;
4176 smounts = (handleValue >> 2) & 3;
4177 pwsync = (handleValue >> 4) & 3;
4178 convmode = (handleValue >> 6) & 3;
4179 rempags = (handleValue >> 8) & 3;
4180 pagcb = (handleValue >> 10) & 3;
4182 changestate = (handleValue >> 16) & 0x1;
4183 convmode = (handleValue >> 16) & 0x2;
4184 pwsync = (handleValue >> 16) & 0x4;
4185 smounts = (handleValue >> 16) & 0x8;
4186 export = handleValue & 0xff;
4189 /* Failed finding desired exporter; */
4193 handleValue = exporter->exp_states;
4194 if (afs_pd_putInt(aout, handleValue) != 0)
4197 if (!afs_osi_suser(*acred))
4198 return EACCES; /* Only superuser can do this */
4202 exporter->exp_states |= EXP_EXPORTED;
4204 exporter->exp_states &= ~EXP_EXPORTED;
4208 exporter->exp_states |= EXP_UNIXMODE;
4210 exporter->exp_states &= ~EXP_UNIXMODE;
4214 exporter->exp_states |= EXP_PWSYNC;
4216 exporter->exp_states &= ~EXP_PWSYNC;
4220 afs_NFSRootOnly = 0;
4221 exporter->exp_states |= EXP_SUBMOUNTS;
4223 afs_NFSRootOnly = 1;
4224 exporter->exp_states &= ~EXP_SUBMOUNTS;
4229 exporter->exp_states |= EXP_CLIPAGS;
4231 exporter->exp_states &= ~EXP_CLIPAGS;
4235 exporter->exp_states |= EXP_CALLBACK;
4237 exporter->exp_states &= ~EXP_CALLBACK;
4239 handleValue = exporter->exp_states;
4240 if (afs_pd_putInt(aout, handleValue) != 0)
4244 exporter->exp_states |= EXP_EXPORTED;
4246 exporter->exp_states &= ~EXP_EXPORTED;
4248 exporter->exp_states |= EXP_UNIXMODE;
4250 exporter->exp_states &= ~EXP_UNIXMODE;
4252 exporter->exp_states |= EXP_PWSYNC;
4254 exporter->exp_states &= ~EXP_PWSYNC;
4256 afs_NFSRootOnly = 0;
4257 exporter->exp_states |= EXP_SUBMOUNTS;
4259 afs_NFSRootOnly = 1;
4260 exporter->exp_states &= ~EXP_SUBMOUNTS;
4269 * VIOC_GAG (44) - Silence Cache Manager
4273 * \param[in] ain the flags to either gag or de-gag the cache manager
4274 * \param[out] aout not in use
4276 * \retval EACCES Error if the user doesn't have super-user credentials
4278 * \post set the gag flags, then show these flags
4282 struct gaginfo *gagflags;
4284 if (!afs_osi_suser(*acred))
4287 gagflags = afs_pd_inline(ain, sizeof(*gagflags));
4288 if (gagflags == NULL)
4290 afs_showflags = gagflags->showflags;
4296 * VIOC_TWIDDLE (45) - Adjust RX knobs
4300 * \param[in] ain the previous settings of the 'knobs'
4301 * \param[out] aout not in use
4303 * \retval EACCES Error if the user doesn't have super-user credentials
4305 * \post build out the struct rxp, from a struct rx
4307 DECL_PIOCTL(PTwiddleRx)
4309 struct rxparams *rxp;
4311 if (!afs_osi_suser(*acred))
4314 rxp = afs_pd_inline(ain, sizeof(*rxp));
4318 if (rxp->rx_initReceiveWindow)
4319 rx_initReceiveWindow = rxp->rx_initReceiveWindow;
4320 if (rxp->rx_maxReceiveWindow)
4321 rx_maxReceiveWindow = rxp->rx_maxReceiveWindow;
4322 if (rxp->rx_initSendWindow)
4323 rx_initSendWindow = rxp->rx_initSendWindow;
4324 if (rxp->rx_maxSendWindow)
4325 rx_maxSendWindow = rxp->rx_maxSendWindow;
4326 if (rxp->rxi_nSendFrags)
4327 rxi_nSendFrags = rxp->rxi_nSendFrags;
4328 if (rxp->rxi_nRecvFrags)
4329 rxi_nRecvFrags = rxp->rxi_nRecvFrags;
4330 if (rxp->rxi_OrphanFragSize)
4331 rxi_OrphanFragSize = rxp->rxi_OrphanFragSize;
4332 if (rxp->rx_maxReceiveSize) {
4333 rx_maxReceiveSize = rxp->rx_maxReceiveSize;
4334 rx_maxReceiveSizeUser = rxp->rx_maxReceiveSize;
4336 if (rxp->rx_MyMaxSendSize)
4337 rx_MyMaxSendSize = rxp->rx_MyMaxSendSize;
4343 * VIOC_GETINITPARAMS (49) - Get initial cache manager parameters
4347 * \param[in] ain not in use
4348 * \param[out] aout initial cache manager params
4351 * Error if the initial parameters are bigger than some PIGGYSIZE
4353 * \post return the initial cache manager parameters
4355 DECL_PIOCTL(PGetInitParams)
4357 if (sizeof(struct cm_initparams) > PIGGYSIZE)
4360 return afs_pd_putBytes(aout, &cm_initParams,
4361 sizeof(struct cm_initparams));
4365 #ifdef AFS_SGI65_ENV
4366 /* They took crget() from us, so fake it. */
4371 cr = crdup(get_current_cred());
4372 memset(cr, 0, sizeof(cred_t));
4373 #if CELL || CELL_PREPARE
4381 * VIOC_GETRXKCRYPT (55) - Get rxkad encryption flag
4385 * \param[in] ain not in use
4386 * \param[out] aout value of cryptall
4388 * \post Turns on, or disables, rxkad encryption by setting the cryptall global
4390 DECL_PIOCTL(PGetRxkcrypt)
4392 return afs_pd_putInt(aout, cryptall);
4396 * VIOC_SETRXKCRYPT (56) - Set rxkad encryption flag
4400 * \param[in] ain the argument whether or not things should be encrypted
4401 * \param[out] aout not in use
4404 * Error if the user doesn't have super-user credentials
4406 * Error if the input is too big, or if the input is outside the
4407 * bounds of what it can be set to
4409 * \post set whether or not things should be encrypted
4412 * may need to be modified at a later date to take into account
4413 * other values for cryptall (beyond true or false)
4415 DECL_PIOCTL(PSetRxkcrypt)
4419 if (!afs_osi_suser(*acred))
4421 if (afs_pd_getInt(ain, &tmpval) != 0)
4423 /* if new mappings added later this will need to be changed */
4424 if (tmpval != 0 && tmpval != 1)
4430 #ifdef AFS_NEED_CLIENTCONTEXT
4432 * Create new credentials to correspond to a remote user with given
4433 * <hostaddr, uid, g0, g1>. This allows a server running as root to
4434 * provide pioctl (and other) services to foreign clients (i.e. nfs
4435 * clients) by using this call to `become' the client.
4438 #define PIOCTL_HEADER 6
4440 HandleClientContext(struct afs_ioctl *ablob, int *com,
4441 afs_ucred_t **acred, afs_ucred_t *credp)
4444 afs_uint32 hostaddr;
4445 afs_int32 uid, g0, g1, i, code, pag, exporter_type, isroot = 0;
4446 struct afs_exporter *exporter, *outexporter;
4447 afs_ucred_t *newcred;
4448 struct unixuser *au;
4449 afs_uint32 comp = *com & 0xff00;
4451 #if defined(AFS_SUN510_ENV)
4455 #if defined(AFS_SGIMP_ENV)
4456 osi_Assert(ISAFS_GLOCK());
4458 AFS_STATCNT(HandleClientContext);
4459 if (ablob->in_size < PIOCTL_HEADER * sizeof(afs_int32)) {
4460 /* Must at least include the PIOCTL_HEADER header words
4461 * required by the protocol */
4462 return EINVAL; /* Too small to be good */
4464 ain = inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
4465 AFS_COPYIN(ablob->in, ain, PIOCTL_HEADER * sizeof(afs_int32), code);
4467 osi_FreeLargeSpace(inData);
4471 /* Extract information for remote user */
4472 hostaddr = *((afs_uint32 *) ain);
4473 ain += sizeof(hostaddr);
4474 uid = *((afs_uint32 *) ain);
4476 g0 = *((afs_uint32 *) ain);
4478 g1 = *((afs_uint32 *) ain);
4480 *com = *((afs_uint32 *) ain);
4481 ain += sizeof(afs_int32);
4482 exporter_type = *((afs_uint32 *) ain);/* In case we support more than NFS */
4485 * Of course, one must be root for most of these functions, but
4486 * we'll allow (for knfs) you to set things if the pag is 0 and
4487 * you're setting tokens or unlogging.
4490 if (!afs_osi_suser(credp)) {
4491 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
4492 /* Since SGI's suser() returns explicit failure after the call.. */
4495 /* check for acceptable opcodes for normal folks, which are, so far,
4496 * get/set tokens, sysname, and unlog.
4498 if (i != 9 && i != 3 && i != 38 && i != 8) {
4499 osi_FreeLargeSpace(inData);
4504 ablob->in_size -= PIOCTL_HEADER * sizeof(afs_int32);
4505 ablob->in += PIOCTL_HEADER * sizeof(afs_int32);
4506 osi_FreeLargeSpace(inData);
4509 * We map uid 0 to nobody to match the mapping that the nfs
4510 * server does and to ensure that the suser() calls in the afs
4511 * code fails for remote client roots.
4513 uid = afs_nobody; /* NFS_NOBODY == -2 */
4517 #ifdef AFS_AIX41_ENV
4520 afs_set_cr_gid(newcred, isroot ? RMTUSER_REQ_PRIV : RMTUSER_REQ);
4521 #ifdef AFS_AIX51_ENV
4522 newcred->cr_groupset.gs_union.un_groups[0] = g0;
4523 newcred->cr_groupset.gs_union.un_groups[1] = g1;
4524 #elif defined(AFS_LINUX26_ENV)
4525 # ifdef AFS_LINUX26_ONEGROUP_ENV
4526 afs_set_cr_group_info(newcred, groups_alloc(1)); /* nothing sets this */
4527 l = (((g0-0x3f00) & 0x3fff) << 14) | ((g1-0x3f00) & 0x3fff);
4528 h = ((g0-0x3f00) >> 14);
4529 h = ((g1-0x3f00) >> 14) + h + h + h;
4530 GROUP_AT(afs_cr_group_info(newcred), 0) = ((h << 28) | l);
4532 afs_set_cr_group_info(newcred, groups_alloc(2));
4533 GROUP_AT(afs_cr_group_info(newcred), 0) = g0;
4534 GROUP_AT(afs_cr_group_info(newcred), 1) = g1;
4536 #elif defined(AFS_SUN510_ENV)
4539 crsetgroups(newcred, 2, gids);
4541 newcred->cr_groups[0] = g0;
4542 newcred->cr_groups[1] = g1;
4545 newcred->cr_ngrps = 2;
4546 #elif !defined(AFS_LINUX26_ENV) && !defined(AFS_SUN510_ENV)
4547 # if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_FBSD80_ENV)
4548 newcred->cr_ngroups = 2;
4550 for (i = 2; i < NGROUPS; i++)
4551 newcred->cr_groups[i] = NOGROUP;
4554 if (!(exporter = exporter_find(exporter_type))) {
4555 /* Exporter wasn't initialized or an invalid exporter type */
4559 if (exporter->exp_states & EXP_PWSYNC) {
4560 if (uid != afs_cr_uid(credp)) {
4562 return ENOEXEC; /* XXX Find a better errno XXX */
4565 afs_set_cr_uid(newcred, uid); /* Only temporary */
4566 code = EXP_REQHANDLER(exporter, &newcred, hostaddr, &pag, &outexporter);
4567 /* The client's pag is the only unique identifier for it */
4568 afs_set_cr_uid(newcred, pag);
4570 if (!code && *com == PSETPAG) {
4571 /* Special case for 'setpag' */
4572 afs_uint32 pagvalue = genpag();
4574 au = afs_GetUser(pagvalue, -1, WRITE_LOCK); /* a new unixuser struct */
4576 * Note that we leave the 'outexporter' struct held so it won't
4579 au->exporter = outexporter;
4580 if (ablob->out_size >= 4) {
4581 AFS_COPYOUT((char *)&pagvalue, ablob->out, sizeof(afs_int32),
4584 afs_PutUser(au, WRITE_LOCK);
4587 return PSETPAG; /* Special return for setpag */
4589 EXP_RELE(outexporter);
4592 *com = (*com) | comp;
4595 #endif /* AFS_NEED_CLIENTCONTEXT */
4599 * VIOC_GETCPREFS (50) - Get client interface
4603 * \param[in] ain sprefrequest input
4604 * \param[out] aout spref information
4606 * \retval EIO Error if the afs daemon hasn't started yet
4607 * \retval EINVAL Error if some of the standard args aren't set
4610 * get all interface addresses and other information of the client
4613 DECL_PIOCTL(PGetCPrefs)
4615 struct sprefrequest *spin; /* input */
4616 struct sprefinfo *spout; /* output */
4617 struct spref *srvout; /* one output component */
4621 AFS_STATCNT(PGetCPrefs);
4622 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4623 return EIO; /* Inappropriate ioctl for device */
4625 spin = afs_pd_inline(ain, sizeof(*spin));
4629 /* Output spout relies on writing past the end of arrays. It's horrible,
4630 * but I'm not quite brave enough to tackle it yet */
4631 spout = (struct sprefinfo *)aout->ptr;
4633 maxNumber = spin->num_servers; /* max addrs this time */
4634 srvout = spout->servers;
4636 ObtainReadLock(&afs_xinterface);
4638 /* copy out the client interface information from the
4639 * kernel data structure "interface" to the output buffer
4641 for (i = spin->offset, j = 0; (i < afs_cb_interface.numberOfInterfaces)
4642 && (j < maxNumber); i++, j++, srvout++)
4643 srvout->host.s_addr = afs_cb_interface.addr_in[i];
4645 spout->num_servers = j;
4646 aout->ptr += sizeof(struct sprefinfo) + (j - 1) * sizeof(struct spref);
4648 if (i >= afs_cb_interface.numberOfInterfaces)
4649 spout->next_offset = 0; /* start from beginning again */
4651 spout->next_offset = spin->offset + j;
4653 ReleaseReadLock(&afs_xinterface);
4658 * VIOC_SETCPREFS (51) - Set client interface
4662 * \param[in] ain the interfaces you want set
4663 * \param[out] aout not in use
4665 * \retval EIO Error if the afs daemon hasn't started yet
4666 * \retval EINVAL Error if the input is too large for the struct
4667 * \retval ENOMEM Error if there are too many servers
4669 * \post set the callbak interfaces addresses to those of the hosts
4671 DECL_PIOCTL(PSetCPrefs)
4675 struct setspref *sin;
4678 AFS_STATCNT(PSetCPrefs);
4679 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4680 return EIO; /* Inappropriate ioctl for device */
4682 /* Yuck. Input to this function relies on reading past the end of
4683 * structures. Bodge it for now.
4686 ainSize = ain->remaining;
4688 sin = (struct setspref *)ainPtr;
4690 if (ainSize < sizeof(struct setspref))
4692 #if 0 /* num_servers is unsigned */
4693 if (sin->num_servers < 0)
4696 if (sin->num_servers > AFS_MAX_INTERFACE_ADDR)
4699 ObtainWriteLock(&afs_xinterface, 412);
4700 afs_cb_interface.numberOfInterfaces = sin->num_servers;
4701 for (i = 0; (unsigned short)i < sin->num_servers; i++)
4702 afs_cb_interface.addr_in[i] = sin->servers[i].host.s_addr;
4704 ReleaseWriteLock(&afs_xinterface);
4709 * VIOC_AFS_FLUSHMOUNT (52) - Flush mount symlink data
4714 * the last part of a path to a mount point, which tells us what to flush
4719 * Error if some of the initial arguments aren't set
4721 * Error if the initial argument for the mount point isn't a directory
4723 * Error if the dcache entry isn't set
4726 * remove all of the mount data from the dcache regarding a
4727 * certain mount point
4729 DECL_PIOCTL(PFlushMount)
4734 struct VenusFid tfid;
4737 struct sysname_info sysState;
4738 afs_size_t offset, len;
4740 AFS_STATCNT(PFlushMount);
4744 if (afs_pd_getStringPtr(ain, &mount) != 0)
4747 code = afs_VerifyVCache(avc, areq);
4750 if (vType(avc) != VDIR) {
4753 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
4756 Check_AtSys(avc, mount, &sysState, areq);
4757 ObtainReadLock(&tdc->lock);
4759 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
4760 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
4761 ReleaseReadLock(&tdc->lock);
4762 afs_PutDCache(tdc); /* we're done with the data */
4763 bufp = sysState.name;
4767 tfid.Cell = avc->f.fid.Cell;
4768 tfid.Fid.Volume = avc->f.fid.Fid.Volume;
4769 if (!tfid.Fid.Unique && (avc->f.states & CForeign)) {
4770 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
4772 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
4778 if (tvc->mvstat != 1) {
4783 #ifdef AFS_BOZONLOCK_ENV
4784 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
4786 ObtainWriteLock(&tvc->lock, 649);
4787 ObtainWriteLock(&afs_xcbhash, 650);
4788 afs_DequeueCallback(tvc);
4789 tvc->f.states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
4790 ReleaseWriteLock(&afs_xcbhash);
4791 /* now find the disk cache entries */
4792 afs_TryToSmush(tvc, *acred, 1);
4793 osi_dnlc_purgedp(tvc);
4794 if (tvc->linkData && !(tvc->f.states & CCore)) {
4795 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
4796 tvc->linkData = NULL;
4798 ReleaseWriteLock(&tvc->lock);
4799 #ifdef AFS_BOZONLOCK_ENV
4800 afs_BozonUnlock(&tvc->pvnLock, tvc);
4804 if (sysState.allocked)
4805 osi_FreeLargeSpace(bufp);
4810 * VIOC_RXSTAT_PROC (53) - Control process RX statistics
4814 * \param[in] ain the flags that control which stats to use
4815 * \param[out] aout not in use
4817 * \retval EACCES Error if the user doesn't have super-user credentials
4818 * \retval EINVAL Error if the flag input is too long
4821 * either enable process RPCStats, disable process RPCStats,
4822 * or clear the process RPCStats
4824 DECL_PIOCTL(PRxStatProc)
4828 if (!afs_osi_suser(*acred))
4831 if (afs_pd_getInt(ain, &flags) != 0)
4834 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK))
4837 if (flags & AFSCALL_RXSTATS_ENABLE) {
4838 rx_enableProcessRPCStats();
4840 if (flags & AFSCALL_RXSTATS_DISABLE) {
4841 rx_disableProcessRPCStats();
4843 if (flags & AFSCALL_RXSTATS_CLEAR) {
4844 rx_clearProcessRPCStats(AFS_RX_STATS_CLEAR_ALL);
4851 * VIOC_RXSTAT_PEER (54) - Control peer RX statistics
4855 * \param[in] ain the flags that control which statistics to use
4856 * \param[out] aout not in use
4858 * \retval EACCES Error if the user doesn't have super-user credentials
4859 * \retval EINVAL Error if the flag input is too long
4862 * either enable peer RPCStatws, disable peer RPCStats,
4863 * or clear the peer RPCStats
4865 DECL_PIOCTL(PRxStatPeer)
4869 if (!afs_osi_suser(*acred))
4872 if (afs_pd_getInt(ain, &flags) != 0)
4875 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK))
4878 if (flags & AFSCALL_RXSTATS_ENABLE) {
4879 rx_enablePeerRPCStats();
4881 if (flags & AFSCALL_RXSTATS_DISABLE) {
4882 rx_disablePeerRPCStats();
4884 if (flags & AFSCALL_RXSTATS_CLEAR) {
4885 rx_clearPeerRPCStats(AFS_RX_STATS_CLEAR_ALL);
4890 DECL_PIOCTL(PPrefetchFromTape)
4892 afs_int32 code, code1;
4893 afs_int32 bytes, outval;
4894 struct afs_conn *tc;
4895 struct rx_call *tcall;
4896 struct AFSVolSync tsync;
4897 struct AFSFetchStatus OutStatus;
4898 struct AFSCallBack CallBack;
4899 struct VenusFid tfid;
4903 AFS_STATCNT(PSetAcl);
4907 Fid = afs_pd_inline(ain, sizeof(struct AFSFid));
4909 Fid = &avc->f.fid.Fid;
4911 tfid.Cell = avc->f.fid.Cell;
4912 tfid.Fid.Volume = Fid->Volume;
4913 tfid.Fid.Vnode = Fid->Vnode;
4914 tfid.Fid.Unique = Fid->Unique;
4916 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
4918 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
4919 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &avc->f.fid);
4922 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
4923 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &tvc->f.fid);
4926 tc = afs_Conn(&tvc->f.fid, areq, SHARED_LOCK);
4930 tcall = rx_NewCall(tc->id);
4932 StartRXAFS_FetchData(tcall, (struct AFSFid *)&tvc->f.fid.Fid, 0,
4935 bytes = rx_Read(tcall, (char *)&outval, sizeof(afs_int32));
4937 EndRXAFS_FetchData(tcall, &OutStatus, &CallBack, &tsync);
4939 code1 = rx_EndCall(tcall, code);
4943 } while (afs_Analyze
4944 (tc, code, &tvc->f.fid, areq, AFS_STATS_FS_RPCIDX_RESIDENCYRPCS,
4945 SHARED_LOCK, NULL));
4946 /* This call is done only to have the callback things handled correctly */
4947 afs_FetchStatus(tvc, &tfid, areq, &OutStatus);
4953 return afs_pd_putInt(aout, outval);
4959 struct afs_conn *tc;
4961 struct FsCmdInputs *Inputs;
4962 struct FsCmdOutputs *Outputs;
4963 struct VenusFid tfid;
4969 Inputs = afs_pd_inline(ain, sizeof(*Inputs));
4973 Outputs = afs_pd_inline(aout, sizeof(*Outputs));
4974 if (Outputs == NULL)
4979 Fid = &avc->f.fid.Fid;
4981 tfid.Cell = avc->f.fid.Cell;
4982 tfid.Fid.Volume = Fid->Volume;
4983 tfid.Fid.Vnode = Fid->Vnode;
4984 tfid.Fid.Unique = Fid->Unique;
4986 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
4987 afs_Trace3(afs_iclSetp, CM_TRACE_RESIDCMD, ICL_TYPE_POINTER, tvc,
4988 ICL_TYPE_INT32, Inputs->command, ICL_TYPE_FID, &tfid);
4992 if (Inputs->command) {
4994 tc = afs_Conn(&tvc->f.fid, areq, SHARED_LOCK);
4998 RXAFS_FsCmd(tc->id, Fid, Inputs,
4999 (struct FsCmdOutputs *)aout);
5003 } while (afs_Analyze
5004 (tc, code, &tvc->f.fid, areq,
5005 AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK, NULL));
5006 /* This call is done to have the callback things handled correctly */
5007 afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
5008 } else { /* just a status request, return also link data */
5010 Outputs->code = afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
5011 Outputs->chars[0] = 0;
5012 if (vType(tvc) == VLNK) {
5013 ObtainWriteLock(&tvc->lock, 555);
5014 if (afs_HandleLink(tvc, areq) == 0)
5015 strncpy((char *)&Outputs->chars, tvc->linkData, MAXCMDCHARS);
5016 ReleaseWriteLock(&tvc->lock);
5025 DECL_PIOCTL(PNewUuid)
5027 /*AFS_STATCNT(PNewUuid); */
5028 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
5029 return EIO; /* Inappropriate ioctl for device */
5031 if (!afs_osi_suser(*acred))
5034 ObtainWriteLock(&afs_xinterface, 555);
5035 afs_uuid_create(&afs_cb_interface.uuid);
5036 ReleaseWriteLock(&afs_xinterface);
5037 ForceAllNewConnections();
5041 #if defined(AFS_CACHE_BYPASS)
5043 DECL_PIOCTL(PSetCachingThreshold)
5045 afs_int32 getting = 1;
5046 afs_int32 setting = 1;
5047 afs_int32 threshold = AFS_CACHE_BYPASS_DISABLED;
5049 if (afs_pd_getInt(ain, &threshold) != 0)
5055 if (setting == 0 && getting == 0)
5059 * If setting, set first, and return the value now in effect
5062 if (!afs_osi_suser(*acred))
5064 cache_bypass_threshold = threshold;
5065 afs_warn("Cache Bypass Threshold set to: %d\n", threshold);
5066 /* TODO: move to separate pioctl, or enhance pioctl */
5067 cache_bypass_strategy = LARGE_FILES_BYPASS_CACHE;
5070 /* Return the current size threshold */
5072 return afs_pd_putInt(aout, cache_bypass_threshold);
5077 #endif /* defined(AFS_CACHE_BYPASS) */
5079 DECL_PIOCTL(PCallBackAddr)
5082 afs_uint32 addr, code;
5086 struct afs_conn *tc;
5088 struct unixuser *tu;
5089 struct srvAddr **addrs;
5091 /*AFS_STATCNT(PCallBackAddr); */
5092 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
5093 return EIO; /* Inappropriate ioctl for device */
5095 if (!afs_osi_suser(acred))
5098 if (afs_pd_getInt(ain, &addr) != 0)
5101 ObtainReadLock(&afs_xinterface);
5102 for (i = 0; (unsigned short)i < afs_cb_interface.numberOfInterfaces; i++) {
5103 if (afs_cb_interface.addr_in[i] == addr)
5107 ReleaseWriteLock(&afs_xinterface);
5109 if (afs_cb_interface.addr_in[i] != addr)
5112 ObtainReadLock(&afs_xserver); /* Necessary? */
5113 ObtainReadLock(&afs_xsrvAddr);
5116 for (i = 0; i < NSERVERS; i++) {
5117 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
5122 addrs = afs_osi_Alloc(srvAddrCount * sizeof(*addrs));
5124 for (i = 0; i < NSERVERS; i++) {
5125 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
5126 if (j >= srvAddrCount)
5132 ReleaseReadLock(&afs_xsrvAddr);
5133 ReleaseReadLock(&afs_xserver);
5135 for (i = 0; i < j; i++) {
5141 /* vlserver has no callback conn */
5142 if (sa->sa_portal == AFS_VLPORT) {
5146 if (!ts->cell) /* not really an active server, anyway, it must */
5147 continue; /* have just been added by setsprefs */
5149 /* get a connection, even if host is down; bumps conn ref count */
5150 tu = afs_GetUser(areq->uid, ts->cell->cellNum, SHARED_LOCK);
5151 tc = afs_ConnBySA(sa, ts->cell->fsport, ts->cell->cellNum, tu,
5152 1 /*force */ , 1 /*create */ , SHARED_LOCK);
5153 afs_PutUser(tu, SHARED_LOCK);
5157 if ((sa->sa_flags & SRVADDR_ISDOWN) || afs_HaveCallBacksFrom(ts)) {
5158 if (sa->sa_flags & SRVADDR_ISDOWN) {
5159 rx_SetConnDeadTime(tc->id, 3);
5161 #ifdef RX_ENABLE_LOCKS
5163 #endif /* RX_ENABLE_LOCKS */
5164 code = RXAFS_CallBackRxConnAddr(tc->id, &addr);
5165 #ifdef RX_ENABLE_LOCKS
5167 #endif /* RX_ENABLE_LOCKS */
5169 afs_PutConn(tc, SHARED_LOCK); /* done with it now */
5170 } /* Outer loop over addrs */
5171 #endif /* UKERNEL */
5175 DECL_PIOCTL(PDiscon)
5177 static afs_int32 mode = 1; /* Start up in 'off' */
5178 afs_int32 force = 0;
5181 struct vrequest lreq;
5183 if (afs_pd_getBytes(ain, &flags, 4) == 0) {
5184 if (!afs_osi_suser(*acred))
5188 mode = flags[0] - 1;
5190 afs_ConflictPolicy = flags[1] - 1;
5194 /* Fake InitReq support for UID override */
5195 memset(&lreq, 0, sizeof(lreq));
5196 lreq.uid = flags[3];
5197 areq = &lreq; /* override areq we got */
5201 * All of these numbers are hard coded in fs.c. If they
5202 * change here, they should change there and vice versa
5205 case 0: /* Disconnect ("offline" mode), breaking all callbacks */
5206 if (!AFS_IS_DISCONNECTED) {
5207 ObtainWriteLock(&afs_discon_lock, 999);
5208 afs_DisconGiveUpCallbacks();
5209 afs_RemoveAllConns();
5210 afs_is_disconnected = 1;
5211 afs_is_discon_rw = 1;
5212 ReleaseWriteLock(&afs_discon_lock);
5215 case 1: /* Fully connected, ("online" mode). */
5216 ObtainWriteLock(&afs_discon_lock, 998);
5219 afs_MarkAllServersUp();
5220 code = afs_ResyncDisconFiles(areq, *acred);
5223 if (code && !force) {
5224 afs_warnuser("Files not synchronized properly, still in discon state. \n"
5225 "Please retry or use \"force\".\n");
5229 afs_DisconDiscardAll(*acred);
5231 afs_ClearAllStatdFlag();
5232 afs_is_disconnected = 0;
5233 afs_is_discon_rw = 0;
5234 afs_warnuser("\nSync succeeded. You are back online.\n");
5237 ReleaseWriteLock(&afs_discon_lock);
5249 return afs_pd_putInt(aout, mode);
5252 #define MAX_PIOCTL_TOKENS 10
5254 DECL_PIOCTL(PSetTokens2)
5257 int i, cellNum, primaryFlag;
5259 struct unixuser *tu;
5260 struct vrequest treq;
5261 struct ktc_setTokenData tokenSet;
5262 struct ktc_tokenUnion decodedToken;
5264 memset(&tokenSet, 0, sizeof(tokenSet));
5266 AFS_STATCNT(PSetTokens2);
5267 if (!afs_resourceinit_flag)
5270 afs_pd_xdrStart(ain, &xdrs, XDR_DECODE);
5272 if (!xdr_ktc_setTokenData(&xdrs, &tokenSet)) {
5273 afs_pd_xdrEnd(ain, &xdrs);
5277 afs_pd_xdrEnd(ain, &xdrs);
5279 /* We limit each PAG to 10 tokens to prevent a malicous (or runaway)
5280 * process from using up the whole of the kernel memory by allocating
5283 if (tokenSet.tokens.tokens_len > MAX_PIOCTL_TOKENS) {
5284 xdr_free((xdrproc_t) xdr_ktc_setTokenData, &tokenSet);
5288 code = _settok_tokenCell(tokenSet.cell, &cellNum, &primaryFlag);
5290 xdr_free((xdrproc_t) xdr_ktc_setTokenData, &tokenSet);
5294 if (tokenSet.flags & AFSTOKEN_EX_SETPAG) {
5295 if (_settok_setParentPag(acred) == 0) {
5296 afs_InitReq(&treq, *acred);
5301 tu = afs_GetUser(areq->uid, cellNum, WRITE_LOCK);
5302 /* Free any tokens that we've already got */
5303 afs_FreeTokens(&tu->tokens);
5305 /* Iterate across the set of tokens we've received, and stuff them
5306 * into this user's tokenJar
5308 for (i=0; i < tokenSet.tokens.tokens_len; i++) {
5309 xdrmem_create(&xdrs,
5310 tokenSet.tokens.tokens_val[i].token_opaque_val,
5311 tokenSet.tokens.tokens_val[i].token_opaque_len,
5314 memset(&decodedToken, 0, sizeof(decodedToken));
5315 if (!xdr_ktc_tokenUnion(&xdrs, &decodedToken)) {
5323 afs_AddTokenFromPioctl(&tu->tokens, &decodedToken);
5324 /* This is untidy - the old token interface supported passing
5325 * the primaryFlag as part of the token interface. Current
5326 * OpenAFS userland never sets this, but it's specified as being
5327 * part of the XG interface, so we should probably still support
5328 * it. Rather than add it to our AddToken interface, just handle
5331 if (decodedToken.at_type == AFSTOKEN_UNION_KAD) {
5332 if (decodedToken.ktc_tokenUnion_u.at_kad.rk_primary_flag)
5336 /* XXX - We should think more about destruction here. It's likely that
5337 * there is key material in what we're about to throw away, which
5338 * we really should zero out before giving back to the allocator */
5339 xdr_free((xdrproc_t) xdr_ktc_tokenUnion, &decodedToken);
5342 tu->states |= UHasTokens;
5343 tu->states &= ~UTokensBad;
5344 afs_SetPrimary(tu, primaryFlag);
5345 tu->tokenTime = osi_Time();
5347 xdr_free((xdrproc_t) xdr_ktc_setTokenData, &tokenSet);
5350 afs_ResetUserConns(tu);
5351 afs_PutUser(tu, WRITE_LOCK);
5356 DECL_PIOCTL(PGetTokens2)
5359 struct unixuser *tu = NULL;
5361 char *cellName = NULL;
5366 struct ktc_setTokenData tokenSet;
5368 AFS_STATCNT(PGetTokens);
5369 if (!afs_resourceinit_flag)
5372 memset(&tokenSet, 0, sizeof(tokenSet));
5374 /* No input data - return tokens for primary cell */
5375 /* 4 octets of data is an iterator count */
5376 /* Otherwise, treat as string & return tokens for that cell name */
5378 if (afs_pd_remaining(ain) == sizeof(afs_int32)) {
5379 /* Integer iterator - return tokens for the n'th cell found for user */
5380 if (afs_pd_getInt(ain, &iterator) != 0)
5382 tu = getNthCell(areq->uid, iterator);
5384 if (afs_pd_remaining(ain) > 0) {
5385 if (afs_pd_getStringPtr(ain, &cellName) != 0)
5390 code = _settok_tokenCell(cellName, &cellNum, NULL);
5393 tu = afs_FindUser(areq->uid, cellNum, READ_LOCK);
5400 if (!(tu->states & UHasTokens)
5401 || !afs_HasValidTokens(tu->tokens, now)) {
5402 tu->states |= (UTokensBad | UNeedsReset);
5403 afs_PutUser(tu, READ_LOCK);
5407 code = afs_ExtractTokensForPioctl(tu->tokens, now, &tokenSet);
5411 cell = afs_GetCell(tu->cell, READ_LOCK);
5412 tokenSet.cell = cell->cellName;
5413 afs_pd_xdrStart(aout, &xdrs, XDR_ENCODE);
5414 if (!xdr_ktc_setTokenData(&xdrs, &tokenSet)) {
5418 afs_pd_xdrEnd(aout, &xdrs);
5421 tokenSet.cell = NULL;
5424 afs_PutUser(tu, READ_LOCK);
5426 afs_PutCell(cell, READ_LOCK);
5427 xdr_free((xdrproc_t)xdr_ktc_setTokenData, &tokenSet);
5432 DECL_PIOCTL(PNFSNukeCreds)
5436 struct unixuser *tu;
5438 AFS_STATCNT(PUnlog);
5439 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
5440 return EIO; /* Inappropriate ioctl for device */
5442 if (afs_pd_getUint(ain, &addr) != 0)
5445 if (afs_cr_gid(*acred) == RMTUSER_REQ_PRIV && !addr) {
5446 tu = afs_GetUser(areq->uid, -1, SHARED_LOCK);
5447 if (!tu->exporter || !(addr = EXP_GETHOST(tu->exporter))) {
5448 afs_PutUser(tu, SHARED_LOCK);
5451 afs_PutUser(tu, SHARED_LOCK);
5452 } else if (!afs_osi_suser(acred)) {
5456 ObtainWriteLock(&afs_xuser, 227);
5457 for (i = 0; i < NUSERS; i++) {
5458 for (tu = afs_users[i]; tu; tu = tu->next) {
5459 if (tu->exporter && EXP_CHECKHOST(tu->exporter, addr)) {
5460 tu->states &= ~UHasTokens;
5461 afs_FreeTokens(&tu->tokens);
5463 ReleaseWriteLock(&afs_xuser);
5464 afs_ResetUserConns(tu);
5466 ObtainWriteLock(&afs_xuser, 228);
5468 /* set the expire times to 0, causes
5469 * afs_GCUserData to remove this entry
5472 #endif /* UKERNEL */
5476 ReleaseWriteLock(&afs_xuser);