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) && defined(AFS_LINUX24_ENV)
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) && defined(AFS_LINUX24_ENV)
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);
673 if (fd->f_vnode->v_type == VREG || fd->f_vnode->v_type == VDIR) {
674 tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */
675 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
676 /* This is an AFS vnode */
677 if (((uap->com >> 8) & 0xff) == 'V') {
678 struct afs_ioctl *datap;
681 (struct afs_ioctl *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
682 code=copyin_afs_ioctl((char *)uap->arg, datap);
684 osi_FreeSmallSpace(datap);
689 code = HandleIoctl(tvc, uap->com, datap);
690 osi_FreeSmallSpace(datap);
698 code = ioctl(uap, rvp);
702 #elif defined(AFS_LINUX22_ENV)
703 struct afs_ioctl_sys {
708 afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
711 struct afs_ioctl_sys ua, *uap = &ua;
715 AFS_STATCNT(afs_xioctl);
720 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
721 /* This is an AFS vnode */
722 if (((uap->com >> 8) & 0xff) == 'V') {
723 struct afs_ioctl *datap;
725 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
726 code = copyin_afs_ioctl((char *)uap->arg, datap);
728 osi_FreeSmallSpace(datap);
732 code = HandleIoctl(tvc, uap->com, datap);
733 osi_FreeSmallSpace(datap);
741 #elif defined(AFS_DARWIN_ENV) && !defined(AFS_DARWIN80_ENV)
749 afs_xioctl(afs_proc_t *p, struct ioctl_args *uap, register_t *retval)
753 int ioctlDone = 0, code = 0;
755 AFS_STATCNT(afs_xioctl);
756 if ((code = fdgetf(p, uap->fd, &fd)))
758 if (fd->f_type == DTYPE_VNODE) {
759 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
760 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
761 /* This is an AFS vnode */
762 if (((uap->com >> 8) & 0xff) == 'V') {
763 struct afs_ioctl *datap;
765 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
766 code = copyin_afs_ioctl((char *)uap->arg, datap);
768 osi_FreeSmallSpace(datap);
772 code = HandleIoctl(tvc, uap->com, datap);
773 osi_FreeSmallSpace(datap);
781 return ioctl(p, uap, retval);
785 #elif defined(AFS_XBSD_ENV)
786 # if defined(AFS_FBSD_ENV)
789 afs_xioctl(struct thread *td, struct ioctl_args *uap,
792 afs_proc_t *p = td->td_proc;
793 # elif defined(AFS_NBSD_ENV)
795 afs_xioctl(afs_proc_t *p, const struct sys_ioctl_args *uap, register_t *retval)
805 afs_xioctl(afs_proc_t *p, const struct ioctl_args *uap, register_t *retval)
808 struct filedesc *fdp;
810 int ioctlDone = 0, code = 0;
813 AFS_STATCNT(afs_xioctl);
814 #if defined(AFS_NBSD40_ENV)
815 fdp = p->l_proc->p_fd;
819 #if defined(AFS_NBSD50_ENV)
820 if ((fd = fd_getfile(SCARG(uap, fd))) == NULL)
823 if ((uap->fd >= fdp->fd_nfiles)
824 || ((fd = fdp->fd_ofiles[uap->fd]) == NULL))
827 if ((fd->f_flag & (FREAD | FWRITE)) == 0)
829 /* first determine whether this is any sort of vnode */
830 if (fd->f_type == DTYPE_VNODE) {
831 /* good, this is a vnode; next see if it is an AFS vnode */
832 # if defined(AFS_OBSD_ENV)
834 IsAfsVnode((struct vnode *)fd->
835 f_data) ? VTOAFS((struct vnode *)fd->f_data) : NULL;
837 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
839 if (tvc && IsAfsVnode((struct vnode *)fd->f_data)) {
840 /* This is an AFS vnode */
841 #if defined(AFS_NBSD50_ENV)
842 if (((SCARG(uap, com) >> 8) & 0xff) == 'V') {
844 if (((uap->com >> 8) & 0xff) == 'V') {
846 struct afs_ioctl *datap;
848 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
849 #if defined(AFS_NBSD50_ENV)
850 code = copyin_afs_ioctl(SCARG(uap, data), datap);
852 code = copyin_afs_ioctl((char *)uap->arg, datap);
855 osi_FreeSmallSpace(datap);
859 #if defined(AFS_NBSD50_ENV)
860 code = HandleIoctl(tvc, SCARG(uap, com), datap);
862 code = HandleIoctl(tvc, uap->com, datap);
864 osi_FreeSmallSpace(datap);
871 #if defined(AFS_NBSD50_ENV)
872 fd_putfile(SCARG(uap, fd));
876 # if defined(AFS_FBSD_ENV)
877 # if (__FreeBSD_version >= 900044)
878 return sys_ioctl(td, uap);
880 return ioctl(td, uap);
882 # elif defined(AFS_OBSD_ENV)
883 code = sys_ioctl(p, uap, retval);
884 # elif defined(AFS_NBSD_ENV)
885 code = sys_ioctl(p, uap, retval);
891 #elif defined(UKERNEL)
899 } *uap = (struct a *)get_user_struct()->u_ap;
902 int ioctlDone = 0, code = 0;
904 AFS_STATCNT(afs_xioctl);
909 /* first determine whether this is any sort of vnode */
910 if (fd->f_type == DTYPE_VNODE) {
911 /* good, this is a vnode; next see if it is an AFS vnode */
912 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
913 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
914 /* This is an AFS vnode */
915 if (((uap->com >> 8) & 0xff) == 'V') {
916 struct afs_ioctl *datap;
918 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
919 code=copyin_afs_ioctl((char *)uap->arg, datap);
921 osi_FreeSmallSpace(datap);
924 return (setuerror(code), code);
926 code = HandleIoctl(tvc, uap->com, datap);
927 osi_FreeSmallSpace(datap);
940 #endif /* AFS_HPUX102_ENV */
942 #if defined(AFS_SGI_ENV)
943 /* "pioctl" system call entry point; just pass argument to the parameterized
952 afs_pioctl(struct pioctlargs *uap, rval_t * rvp)
956 AFS_STATCNT(afs_pioctl);
958 code = afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow);
960 # ifdef AFS_SGI64_ENV
967 #elif defined(AFS_FBSD_ENV)
969 afs_pioctl(struct thread *td, void *args, int *retval)
976 } *uap = (struct a *)args;
978 AFS_STATCNT(afs_pioctl);
979 return (afs_syscall_pioctl
980 (uap->path, uap->cmd, uap->cmarg, uap->follow, td->td_ucred));
983 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
985 afs_pioctl(afs_proc_t *p, void *args, int *retval)
992 } *uap = (struct a *)args;
994 AFS_STATCNT(afs_pioctl);
995 # if defined(AFS_DARWIN80_ENV) || defined(AFS_NBSD40_ENV)
996 return (afs_syscall_pioctl
997 (uap->path, uap->cmd, uap->cmarg, uap->follow,
1000 return (afs_syscall_pioctl
1001 (uap->path, uap->cmd, uap->cmarg, uap->follow,
1002 # if defined(AFS_FBSD_ENV)
1005 p->p_cred->pc_ucred));
1012 /* macro to avoid adding any more #ifdef's to pioctl code. */
1013 #if defined(AFS_LINUX22_ENV) || defined(AFS_AIX41_ENV)
1014 #define PIOCTL_FREE_CRED() crfree(credp)
1016 #define PIOCTL_FREE_CRED()
1021 afs_syscall_pioctl(char *path, unsigned int com, caddr_t cmarg, int follow,
1022 rval_t *vvp, afs_ucred_t *credp)
1024 #ifdef AFS_DARWIN100_ENV
1025 afs_syscall64_pioctl(user_addr_t path, unsigned int com, user_addr_t cmarg,
1026 int follow, afs_ucred_t *credp)
1027 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1028 afs_syscall_pioctl(char *path, unsigned int com, caddr_t cmarg, int follow,
1031 afs_syscall_pioctl(char *path, unsigned int com, caddr_t cmarg, int follow)
1035 struct afs_ioctl data;
1036 #ifdef AFS_NEED_CLIENTCONTEXT
1037 afs_ucred_t *tmpcred = NULL;
1039 #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)
1040 afs_ucred_t *foreigncreds = NULL;
1043 struct vnode *vp = NULL;
1044 #ifdef AFS_AIX41_ENV
1045 struct ucred *credp = crref(); /* don't free until done! */
1047 #ifdef AFS_LINUX22_ENV
1048 cred_t *credp = crref(); /* don't free until done! */
1052 AFS_STATCNT(afs_syscall_pioctl);
1054 follow = 1; /* compat. with old venus */
1055 code = copyin_afs_ioctl(cmarg, &data);
1058 #if defined(KERNEL_HAVE_UERROR)
1063 if ((com & 0xff) == PSetClientContext) {
1064 #ifdef AFS_NEED_CLIENTCONTEXT
1065 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV)
1066 code = HandleClientContext(&data, &com, &foreigncreds, credp);
1068 code = HandleClientContext(&data, &com, &foreigncreds, osi_curcred());
1072 crfree(foreigncreds);
1075 #if defined(KERNEL_HAVE_UERROR)
1076 return (setuerror(code), code);
1081 #else /* AFS_NEED_CLIENTCONTEXT */
1083 #endif /* AFS_NEED_CLIENTCONTEXT */
1085 #ifdef AFS_NEED_CLIENTCONTEXT
1088 * We could have done without temporary setting the u.u_cred below
1089 * (foreigncreds could be passed as param the pioctl modules)
1090 * but calls such as afs_osi_suser() doesn't allow that since it
1091 * references u.u_cred directly. We could, of course, do something
1092 * like afs_osi_suser(cred) which, I think, is better since it
1093 * generalizes and supports multi cred environments...
1095 #if defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
1097 credp = foreigncreds;
1098 #elif defined(AFS_AIX41_ENV)
1099 tmpcred = crref(); /* XXX */
1100 crset(foreigncreds);
1101 #elif defined(AFS_HPUX101_ENV)
1102 tmpcred = p_cred(u.u_procp);
1103 set_p_cred(u.u_procp, foreigncreds);
1104 #elif defined(AFS_SGI_ENV)
1105 tmpcred = OSI_GET_CURRENT_CRED();
1106 OSI_SET_CURRENT_CRED(foreigncreds);
1109 u.u_cred = foreigncreds;
1112 #endif /* AFS_NEED_CLIENTCONTEXT */
1113 if ((com & 0xff) == 15) {
1114 /* special case prefetch so entire pathname eval occurs in helper process.
1115 * otherwise, the pioctl call is essentially useless */
1116 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1118 Prefetch(path, &data, follow,
1119 foreigncreds ? foreigncreds : credp);
1121 code = Prefetch(path, &data, follow, osi_curcred());
1124 #if defined(KERNEL_HAVE_UERROR)
1131 #ifdef AFS_AIX41_ENV
1133 lookupname(path, USR, follow, NULL, &vp,
1134 foreigncreds ? foreigncreds : credp);
1136 #ifdef AFS_LINUX22_ENV
1137 code = gop_lookupname_user(path, AFS_UIOUSER, follow, &dp);
1139 vp = (struct vnode *)dp->d_inode;
1141 code = gop_lookupname_user(path, AFS_UIOUSER, follow, &vp);
1142 #if defined(AFS_FBSD80_ENV) /* XXX check on 7x */
1145 #endif /* AFS_FBSD80_ENV */
1146 #endif /* AFS_LINUX22_ENV */
1147 #endif /* AFS_AIX41_ENV */
1151 #if defined(KERNEL_HAVE_UERROR)
1159 #if defined(AFS_SUN510_ENV)
1160 if (vp && !IsAfsVnode(vp)) {
1161 struct vnode *realvp;
1163 #ifdef AFS_SUN511_ENV
1164 (VOP_REALVP(vp, &realvp, NULL) == 0)
1166 (VOP_REALVP(vp, &realvp) == 0)
1169 struct vnode *oldvp = vp;
1177 /* now make the call if we were passed no file, or were passed an AFS file */
1178 if (!vp || IsAfsVnode(vp)) {
1179 #if defined(AFS_SUN5_ENV)
1180 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1181 #elif defined(AFS_AIX41_ENV)
1183 struct ucred *cred1, *cred2;
1186 cred1 = cred2 = foreigncreds;
1188 cred1 = cred2 = credp;
1190 code = afs_HandlePioctl(vp, com, &data, follow, &cred1);
1191 if (cred1 != cred2) {
1192 /* something changed the creds */
1196 #elif defined(AFS_HPUX101_ENV)
1198 struct ucred *cred = p_cred(u.u_procp);
1199 code = afs_HandlePioctl(vp, com, &data, follow, &cred);
1201 #elif defined(AFS_SGI_ENV)
1204 credp = OSI_GET_CURRENT_CRED();
1205 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1207 #elif defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1208 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1209 #elif defined(UKERNEL)
1210 code = afs_HandlePioctl(vp, com, &data, follow,
1211 &(get_user_struct()->u_cred));
1213 code = afs_HandlePioctl(vp, com, &data, follow, &u.u_cred);
1216 #if defined(KERNEL_HAVE_UERROR)
1219 code = EINVAL; /* not in /afs */
1224 #if defined(AFS_NEED_CLIENTCONTEXT)
1226 #ifdef AFS_AIX41_ENV
1227 crset(tmpcred); /* restore original credentials */
1229 #if defined(AFS_HPUX101_ENV)
1230 set_p_cred(u.u_procp, tmpcred); /* restore original credentials */
1231 #elif defined(AFS_SGI_ENV)
1232 OSI_SET_CURRENT_CRED(tmpcred); /* restore original credentials */
1233 #elif defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
1234 credp = tmpcred; /* restore original credentials */
1236 osi_curcred() = tmpcred; /* restore original credentials */
1237 #endif /* AFS_HPUX101_ENV */
1238 crfree(foreigncreds);
1241 #endif /* AFS_NEED_CLIENTCONTEXT */
1243 #ifdef AFS_LINUX22_ENV
1246 #if defined(AFS_FBSD80_ENV)
1247 if (VOP_ISLOCKED(vp))
1249 #endif /* AFS_FBSD80_ENV */
1250 AFS_RELE(vp); /* put vnode back */
1254 #if defined(KERNEL_HAVE_UERROR)
1257 return (getuerror());
1263 #ifdef AFS_DARWIN100_ENV
1265 afs_syscall_pioctl(char * path, unsigned int com, caddr_t cmarg,
1266 int follow, afs_ucred_t *credp)
1268 return afs_syscall64_pioctl(CAST_USER_ADDR_T(path), com,
1269 CAST_USER_ADDR_T((unsigned int)cmarg), follow,
1274 #define MAXPIOCTLTOKENLEN \
1275 (3*sizeof(afs_int32)+MAXKTCTICKETLEN+sizeof(struct ClearToken)+MAXKTCREALMLEN)
1278 afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
1279 struct afs_ioctl *ablob, int afollow,
1280 afs_ucred_t **acred)
1283 struct vrequest treq;
1285 afs_int32 function, device;
1286 struct afs_pdata input, output;
1287 struct afs_pdata copyInput, copyOutput;
1289 pioctlFunction *pioctlSw;
1291 struct afs_fakestat_state fakestate;
1293 memset(&input, 0, sizeof(input));
1294 memset(&output, 0, sizeof(output));
1296 avc = avp ? VTOAFS(avp) : NULL;
1297 afs_Trace3(afs_iclSetp, CM_TRACE_PIOCTL, ICL_TYPE_INT32, acom & 0xff,
1298 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, afollow);
1299 AFS_STATCNT(HandlePioctl);
1301 code = afs_InitReq(&treq, *acred);
1305 afs_InitFakeStat(&fakestate);
1307 code = afs_EvalFakeStat(&avc, &fakestate, &treq);
1311 device = (acom & 0xff00) >> 8;
1313 case 'V': /* Original pioctls */
1314 pioctlSw = VpioctlSw;
1315 pioctlSwSize = sizeof(VpioctlSw);
1317 case 'C': /* Coordinated/common pioctls */
1318 pioctlSw = CpioctlSw;
1319 pioctlSwSize = sizeof(CpioctlSw);
1321 case 'O': /* Coordinated/common pioctls */
1322 pioctlSw = OpioctlSw;
1323 pioctlSwSize = sizeof(OpioctlSw);
1329 function = acom & 0xff;
1330 if (function >= (pioctlSwSize / sizeof(char *))) {
1335 /* Do all range checking before continuing */
1336 if (ablob->in_size > MAXPIOCTLTOKENLEN ||
1337 ablob->in_size < 0 || ablob->out_size < 0) {
1342 code = afs_pd_alloc(&input, ablob->in_size);
1346 if (ablob->in_size > 0) {
1347 AFS_COPYIN(ablob->in, input.ptr, ablob->in_size, code);
1348 input.ptr[input.remaining] = '\0';
1353 if ((function == 8 && device == 'V') ||
1354 (function == 7 && device == 'C')) { /* PGetTokens */
1355 code = afs_pd_alloc(&output, MAXPIOCTLTOKENLEN);
1357 code = afs_pd_alloc(&output, AFS_LRALLOCSIZ);
1363 copyOutput = output;
1366 (*pioctlSw[function]) (avc, function, &treq, ©Input,
1367 ©Output, acred);
1369 outSize = copyOutput.ptr - output.ptr;
1371 if (code == 0 && ablob->out_size > 0) {
1372 if (outSize > ablob->out_size) {
1373 code = E2BIG; /* data wont fit in user buffer */
1374 } else if (outSize) {
1375 AFS_COPYOUT(output.ptr, ablob->out, outSize, code);
1380 afs_pd_free(&input);
1381 afs_pd_free(&output);
1383 afs_PutFakeStat(&fakestate);
1384 return afs_CheckCode(code, &treq, 41);
1388 * VIOCGETFID (22) - Get file ID quickly
1392 * \param[in] ain not in use
1393 * \param[out] aout fid of requested file
1395 * \retval EINVAL Error if some of the initial arguments aren't set
1397 * \post get the file id of some file
1399 DECL_PIOCTL(PGetFID)
1401 AFS_STATCNT(PGetFID);
1404 if (afs_pd_putBytes(aout, &avc->f.fid, sizeof(struct VenusFid)) != 0)
1410 * VIOCSETAL (1) - Set access control list
1414 * \param[in] ain the ACL being set
1415 * \param[out] aout the ACL being set returned
1417 * \retval EINVAL Error if some of the standard args aren't set
1419 * \post Changed ACL, via direct writing to the wire
1422 dummy_PSetAcl(char *ain, char *aout)
1427 DECL_PIOCTL(PSetAcl)
1430 struct afs_conn *tconn;
1431 struct AFSOpaque acl;
1432 struct AFSVolSync tsync;
1433 struct AFSFetchStatus OutStatus;
1434 struct rx_connection *rxconn;
1437 AFS_STATCNT(PSetAcl);
1441 if (afs_pd_getStringPtr(ain, &acl.AFSOpaque_val) != 0)
1443 acl.AFSOpaque_len = strlen(acl.AFSOpaque_val) + 1;
1444 if (acl.AFSOpaque_len > 1024)
1448 tconn = afs_Conn(&avc->f.fid, areq, SHARED_LOCK, &rxconn);
1450 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREACL);
1453 RXAFS_StoreACL(rxconn, (struct AFSFid *)&avc->f.fid.Fid,
1454 &acl, &OutStatus, &tsync);
1459 } while (afs_Analyze
1460 (tconn, rxconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_STOREACL,
1461 SHARED_LOCK, NULL));
1463 /* now we've forgotten all of the access info */
1464 ObtainWriteLock(&afs_xcbhash, 455);
1466 afs_DequeueCallback(avc);
1467 avc->f.states &= ~(CStatd | CUnique);
1468 ReleaseWriteLock(&afs_xcbhash);
1469 if (avc->f.fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
1470 osi_dnlc_purgedp(avc);
1472 /* SXW - Should we flush metadata here? */
1476 int afs_defaultAsynchrony = 0;
1479 * VIOC_STOREBEHIND (47) Adjust store asynchrony
1483 * \param[in] ain sbstruct (store behind structure) input
1484 * \param[out] aout resulting sbstruct
1487 * Error if the user doesn't have super-user credentials
1489 * Error if there isn't enough access to not check the mode bits
1492 * Changes either the default asynchrony (the amount of data that
1493 * can remain to be written when the cache manager returns control
1494 * to the user), or the asyncrony for the specified file.
1496 DECL_PIOCTL(PStoreBehind)
1498 struct sbstruct sbr;
1500 if (afs_pd_getBytes(ain, &sbr, sizeof(struct sbstruct)) != 0)
1503 if (sbr.sb_default != -1) {
1504 if (afs_osi_suser(*acred))
1505 afs_defaultAsynchrony = sbr.sb_default;
1510 if (avc && (sbr.sb_thisfile != -1)) {
1512 (avc, PRSFS_WRITE | PRSFS_ADMINISTER, areq, DONT_CHECK_MODE_BITS))
1513 avc->asynchrony = sbr.sb_thisfile;
1518 memset(&sbr, 0, sizeof(sbr));
1519 sbr.sb_default = afs_defaultAsynchrony;
1521 sbr.sb_thisfile = avc->asynchrony;
1524 return afs_pd_putBytes(aout, &sbr, sizeof(sbr));
1528 * VIOC_GCPAGS (48) - Disable automatic PAG gc'ing
1532 * \param[in] ain not in use
1533 * \param[out] aout not in use
1535 * \retval EACCES Error if the user doesn't have super-user credentials
1537 * \post set the gcpags to GCPAGS_USERDISABLED
1539 DECL_PIOCTL(PGCPAGs)
1541 if (!afs_osi_suser(*acred)) {
1544 afs_gcpags = AFS_GCPAGS_USERDISABLED;
1549 * VIOCGETAL (2) - Get access control list
1553 * \param[in] ain not in use
1554 * \param[out] aout the ACL
1556 * \retval EINVAL Error if some of the standard args aren't set
1557 * \retval ERANGE Error if the vnode of the file id is too large
1558 * \retval -1 Error if getting the ACL failed
1560 * \post Obtain the ACL, based on file ID
1563 * There is a hack to tell which type of ACL is being returned, checks
1564 * the top 2-bytes of the input size to judge what type of ACL it is,
1565 * only for dfs xlator ACLs
1567 DECL_PIOCTL(PGetAcl)
1569 struct AFSOpaque acl;
1570 struct AFSVolSync tsync;
1571 struct AFSFetchStatus OutStatus;
1573 struct afs_conn *tconn;
1575 struct rx_connection *rxconn;
1578 AFS_STATCNT(PGetAcl);
1581 Fid.Volume = avc->f.fid.Fid.Volume;
1582 Fid.Vnode = avc->f.fid.Fid.Vnode;
1583 Fid.Unique = avc->f.fid.Fid.Unique;
1584 if (avc->f.states & CForeign) {
1586 * For a dfs xlator acl we have a special hack so that the
1587 * xlator will distinguish which type of acl will return. So
1588 * we currently use the top 2-bytes (vals 0-4) to tell which
1589 * type of acl to bring back. Horrible hack but this will
1590 * cause the least number of changes to code size and interfaces.
1592 if (Fid.Vnode & 0xc0000000)
1594 Fid.Vnode |= (ain->remaining << 30);
1596 acl.AFSOpaque_val = aout->ptr;
1598 tconn = afs_Conn(&avc->f.fid, areq, SHARED_LOCK, &rxconn);
1600 acl.AFSOpaque_val[0] = '\0';
1601 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHACL);
1603 code = RXAFS_FetchACL(rxconn, &Fid, &acl, &OutStatus, &tsync);
1608 } while (afs_Analyze
1609 (tconn, rxconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_FETCHACL,
1610 SHARED_LOCK, NULL));
1613 if (acl.AFSOpaque_len == 0)
1614 afs_pd_skip(aout, 1); /* leave the NULL */
1616 afs_pd_skip(aout, acl.AFSOpaque_len); /* Length of the ACL */
1622 * PNoop returns success. Used for functions which are not implemented
1623 * or are no longer in use.
1627 * \retval Always returns success
1630 * Functions involved in this:
1631 * 17 (VIOCENGROUP) -- used to be enable group;
1632 * 18 (VIOCDISGROUP) -- used to be disable group;
1633 * 2 (?) -- get/set cache-bypass size threshold
1642 * PBogus returns fail. Used for functions which are not implemented or
1643 * are no longer in use.
1647 * \retval EINVAL Always returns this value
1650 * Functions involved in this:
1656 * 13 (VIOCGETTIME) -- used to be quick check time;
1657 * 15 (VIOCPREFETCH) -- prefetch is now special-cased; see pioctl code!;
1658 * 16 (VIOCNOP) -- used to be testing code;
1659 * 19 (VIOCLISTGROUPS) -- used to be list group;
1660 * 23 (VIOCWAITFOREVER) -- used to be waitforever;
1661 * 57 (VIOC_FPRIOSTATUS) -- arla: set file prio;
1662 * 58 (VIOC_FHGET) -- arla: fallback getfh;
1663 * 59 (VIOC_FHOPEN) -- arla: fallback fhopen;
1664 * 60 (VIOC_XFSDEBUG) -- arla: controls xfsdebug;
1665 * 61 (VIOC_ARLADEBUG) -- arla: controls arla debug;
1666 * 62 (VIOC_AVIATOR) -- arla: debug interface;
1667 * 63 (VIOC_XFSDEBUG_PRINT) -- arla: print xfs status;
1668 * 64 (VIOC_CALCULATE_CACHE) -- arla: force cache check;
1669 * 65 (VIOC_BREAKCELLBACK) -- arla: break callback;
1670 * 68 (?) -- arla: fetch stats;
1674 AFS_STATCNT(PBogus);
1679 * VIOC_FILE_CELL_NAME (30) - Get cell in which file lives
1683 * \param[in] ain not in use (avc used to pass in file id)
1684 * \param[out] aout cell name
1686 * \retval EINVAL Error if some of the standard args aren't set
1687 * \retval ESRCH Error if the file isn't part of a cell
1689 * \post Get a cell based on a passed in file id
1691 DECL_PIOCTL(PGetFileCell)
1695 AFS_STATCNT(PGetFileCell);
1698 tcell = afs_GetCell(avc->f.fid.Cell, READ_LOCK);
1702 if (afs_pd_putString(aout, tcell->cellName) != 0)
1705 afs_PutCell(tcell, READ_LOCK);
1710 * VIOC_GET_WS_CELL (31) - Get cell in which workstation lives
1714 * \param[in] ain not in use
1715 * \param[out] aout cell name
1718 * Error if the afs daemon hasn't started yet
1720 * Error if the machine isn't part of a cell, for whatever reason
1722 * \post Get the primary cell that the machine is a part of.
1724 DECL_PIOCTL(PGetWSCell)
1726 struct cell *tcell = NULL;
1728 AFS_STATCNT(PGetWSCell);
1729 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1730 return EIO; /* Inappropriate ioctl for device */
1732 tcell = afs_GetPrimaryCell(READ_LOCK);
1733 if (!tcell) /* no primary cell? */
1736 if (afs_pd_putString(aout, tcell->cellName) != 0)
1738 afs_PutCell(tcell, READ_LOCK);
1743 * VIOC_GET_PRIMARY_CELL (33) - Get primary cell for caller
1747 * \param[in] ain not in use (user id found via areq)
1748 * \param[out] aout cell name
1751 * Error if the user id doesn't have a primary cell specified
1753 * \post Get the primary cell for a certain user, based on the user's uid
1755 DECL_PIOCTL(PGetUserCell)
1758 struct unixuser *tu;
1761 AFS_STATCNT(PGetUserCell);
1762 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1763 return EIO; /* Inappropriate ioctl for device */
1765 /* return the cell name of the primary cell for this user */
1766 i = UHash(areq->uid);
1767 ObtainWriteLock(&afs_xuser, 224);
1768 for (tu = afs_users[i]; tu; tu = tu->next) {
1769 if (tu->uid == areq->uid && (tu->states & UPrimary)) {
1771 ReleaseWriteLock(&afs_xuser);
1772 afs_LockUser(tu, READ_LOCK, 0);
1777 tcell = afs_GetCell(tu->cell, READ_LOCK);
1778 afs_PutUser(tu, READ_LOCK);
1782 if (afs_pd_putString(aout, tcell->cellName) != 0)
1784 afs_PutCell(tcell, READ_LOCK);
1787 ReleaseWriteLock(&afs_xuser);
1792 /* Work out which cell we're changing tokens for */
1794 _settok_tokenCell(char *cellName, int *cellNum, int *primary) {
1802 if (cellName && strlen(cellName) > 0) {
1803 cell = afs_GetCellByName(cellName, READ_LOCK);
1805 cell = afs_GetPrimaryCell(READ_LOCK);
1816 *cellNum = cell->cellNum;
1817 afs_PutCell(cell, READ_LOCK);
1824 _settok_setParentPag(afs_ucred_t **cred) {
1826 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1828 osi_procname(procname, 256);
1829 afs_warnuser("Process %d (%s) tried to change pags in PSetTokens\n",
1830 MyPidxx2Pid(MyPidxx), procname);
1831 return setpag(osi_curproc(), cred, -1, &pag, 1);
1833 return setpag(cred, -1, &pag, 1);
1838 * VIOCSETTOK (3) - Set authentication tokens
1842 * \param[in] ain the krb tickets from which to set the afs tokens
1843 * \param[out] aout not in use
1846 * Error if the ticket is either too long or too short
1848 * Error if the AFS initState is below 101
1850 * Error if the cell for which the Token is being set can't be found
1853 * Set the Tokens for a specific cell name, unless there is none set,
1854 * then default to primary
1857 DECL_PIOCTL(PSetTokens)
1862 struct unixuser *tu;
1863 struct ClearToken clear;
1867 struct vrequest treq;
1868 afs_int32 flag, set_parent_pag = 0;
1870 AFS_STATCNT(PSetTokens);
1871 if (!afs_resourceinit_flag) {
1875 if (afs_pd_getInt(ain, &stLen) != 0)
1878 stp = afs_pd_where(ain); /* remember where the ticket is */
1879 if (stLen < 0 || stLen > MAXKTCTICKETLEN)
1880 return EINVAL; /* malloc may fail */
1881 if (afs_pd_skip(ain, stLen) != 0)
1884 if (afs_pd_getInt(ain, &size) != 0)
1886 if (size != sizeof(struct ClearToken))
1889 if (afs_pd_getBytes(ain, &clear, sizeof(struct ClearToken)) !=0)
1892 if (clear.AuthHandle == -1)
1893 clear.AuthHandle = 999; /* more rxvab compat stuff */
1895 if (afs_pd_remaining(ain) != 0) {
1896 /* still stuff left? we've got primary flag and cell name.
1899 if (afs_pd_getInt(ain, &flag) != 0)
1902 /* some versions of gcc appear to need != 0 in order to get this
1904 if ((flag & 0x8000) != 0) { /* XXX Use Constant XXX */
1909 if (afs_pd_getStringPtr(ain, &cellName) != 0)
1912 code = _settok_tokenCell(cellName, &cellNum, NULL);
1916 /* default to primary cell, primary id */
1917 code = _settok_tokenCell(NULL, &cellNum, &flag);
1922 if (set_parent_pag) {
1923 if (_settok_setParentPag(acred) == 0) {
1924 afs_InitReq(&treq, *acred);
1929 /* now we just set the tokens */
1930 tu = afs_GetUser(areq->uid, cellNum, WRITE_LOCK);
1931 /* Set tokens destroys any that are already there */
1932 afs_FreeTokens(&tu->tokens);
1933 afs_AddRxkadToken(&tu->tokens, stp, stLen, &clear);
1935 afs_stats_cmfullperf.authent.TicketUpdates++;
1936 afs_ComputePAGStats();
1937 #endif /* AFS_NOSTATS */
1938 tu->states |= UHasTokens;
1939 tu->states &= ~UTokensBad;
1940 afs_SetPrimary(tu, flag);
1941 tu->tokenTime = osi_Time();
1942 afs_ResetUserConns(tu);
1943 afs_NotifyUser(tu, UTokensObtained);
1944 afs_PutUser(tu, WRITE_LOCK);
1950 * VIOCGETVOLSTAT (4) - Get volume status
1954 * \param[in] ain not in use
1955 * \param[out] aout status of the volume
1957 * \retval EINVAL Error if some of the standard args aren't set
1960 * The status of a volume (based on the FID of the volume), or an
1961 * offline message /motd
1963 DECL_PIOCTL(PGetVolumeStatus)
1966 char *offLineMsg = afs_osi_Alloc(256);
1967 char *motd = afs_osi_Alloc(256);
1968 struct afs_conn *tc;
1970 struct AFSFetchVolumeStatus volstat;
1972 struct rx_connection *rxconn;
1975 osi_Assert(offLineMsg != NULL);
1976 osi_Assert(motd != NULL);
1977 AFS_STATCNT(PGetVolumeStatus);
1984 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK, &rxconn);
1986 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS);
1989 RXAFS_GetVolumeStatus(rxconn, avc->f.fid.Fid.Volume, &volstat,
1990 &Name, &offLineMsg, &motd);
1995 } while (afs_Analyze
1996 (tc, rxconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS,
1997 SHARED_LOCK, NULL));
2001 /* Copy all this junk into msg->im_data, keeping track of the lengths. */
2002 if (afs_pd_putBytes(aout, &volstat, sizeof(VolumeStatus)) != 0)
2004 if (afs_pd_putString(aout, volName) != 0)
2006 if (afs_pd_putString(aout, offLineMsg) != 0)
2008 if (afs_pd_putString(aout, motd) != 0)
2011 afs_osi_Free(offLineMsg, 256);
2012 afs_osi_Free(motd, 256);
2017 * VIOCSETVOLSTAT (5) - Set volume status
2022 * values to set the status at, offline message, message of the day,
2023 * volume name, minimum quota, maximum quota
2025 * status of a volume, offlines messages, minimum quota, maximumm quota
2028 * Error if some of the standard args aren't set
2030 * Error if the volume is read only, or a backup volume
2032 * Error if the volume can't be accessed
2034 * Error if the volume name, offline message, and motd are too big
2037 * Set the status of a volume, including any offline messages,
2038 * a minimum quota, and a maximum quota
2040 DECL_PIOCTL(PSetVolumeStatus)
2045 struct afs_conn *tc;
2047 struct AFSFetchVolumeStatus volstat;
2048 struct AFSStoreVolumeStatus storeStat;
2050 struct rx_connection *rxconn;
2053 AFS_STATCNT(PSetVolumeStatus);
2057 tvp = afs_GetVolume(&avc->f.fid, areq, READ_LOCK);
2059 if (tvp->states & (VRO | VBackup)) {
2060 afs_PutVolume(tvp, READ_LOCK);
2063 afs_PutVolume(tvp, READ_LOCK);
2068 if (afs_pd_getBytes(ain, &volstat, sizeof(AFSFetchVolumeStatus)) != 0)
2071 if (afs_pd_getStringPtr(ain, &volName) != 0)
2073 if (strlen(volName) > 32)
2076 if (afs_pd_getStringPtr(ain, &offLineMsg) != 0)
2078 if (strlen(offLineMsg) > 256)
2081 if (afs_pd_getStringPtr(ain, &motd) != 0)
2083 if (strlen(motd) > 256)
2086 /* Done reading ... */
2089 if (volstat.MinQuota != -1) {
2090 storeStat.MinQuota = volstat.MinQuota;
2091 storeStat.Mask |= AFS_SETMINQUOTA;
2093 if (volstat.MaxQuota != -1) {
2094 storeStat.MaxQuota = volstat.MaxQuota;
2095 storeStat.Mask |= AFS_SETMAXQUOTA;
2098 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK, &rxconn);
2100 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS);
2103 RXAFS_SetVolumeStatus(rxconn, avc->f.fid.Fid.Volume, &storeStat,
2104 volName, offLineMsg, motd);
2109 } while (afs_Analyze
2110 (tc, rxconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS,
2111 SHARED_LOCK, NULL));
2115 /* we are sending parms back to make compat. with prev system. should
2116 * change interface later to not ask for current status, just set new
2119 if (afs_pd_putBytes(aout, &volstat, sizeof(VolumeStatus)) != 0)
2121 if (afs_pd_putString(aout, volName) != 0)
2123 if (afs_pd_putString(aout, offLineMsg) != 0)
2125 if (afs_pd_putString(aout, motd) != 0)
2132 * VIOCFLUSH (6) - Invalidate cache entry
2136 * \param[in] ain not in use
2137 * \param[out] aout not in use
2139 * \retval EINVAL Error if some of the standard args aren't set
2141 * \post Flush any information the cache manager has on an entry
2145 AFS_STATCNT(PFlush);
2148 #ifdef AFS_BOZONLOCK_ENV
2149 afs_BozonLock(&avc->pvnLock, avc); /* Since afs_TryToSmush will do a pvn_vptrunc */
2151 ObtainWriteLock(&avc->lock, 225);
2152 afs_ResetVCache(avc, *acred);
2153 ReleaseWriteLock(&avc->lock);
2154 #ifdef AFS_BOZONLOCK_ENV
2155 afs_BozonUnlock(&avc->pvnLock, avc);
2161 * VIOC_AFS_STAT_MT_PT (29) - Stat mount point
2166 * the last component in a path, related to mountpoint that we're
2167 * looking for information about
2169 * volume, cell, link data
2171 * \retval EINVAL Error if some of the standard args aren't set
2172 * \retval ENOTDIR Error if the 'mount point' argument isn't a directory
2173 * \retval EIO Error if the link data can't be accessed
2175 * \post Get the volume, and cell, as well as the link data for a mount point
2177 DECL_PIOCTL(PNewStatMount)
2182 struct VenusFid tfid;
2185 struct sysname_info sysState;
2186 afs_size_t offset, len;
2188 AFS_STATCNT(PNewStatMount);
2192 if (afs_pd_getStringPtr(ain, &name) != 0)
2195 code = afs_VerifyVCache(avc, areq);
2198 if (vType(avc) != VDIR) {
2201 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
2204 Check_AtSys(avc, name, &sysState, areq);
2205 ObtainReadLock(&tdc->lock);
2207 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
2208 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
2209 ReleaseReadLock(&tdc->lock);
2210 afs_PutDCache(tdc); /* we're done with the data */
2211 bufp = sysState.name;
2215 tfid.Cell = avc->f.fid.Cell;
2216 tfid.Fid.Volume = avc->f.fid.Fid.Volume;
2217 if (!tfid.Fid.Unique && (avc->f.states & CForeign)) {
2218 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
2220 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
2226 if (tvc->mvstat != 1) {
2231 ObtainWriteLock(&tvc->lock, 226);
2232 code = afs_HandleLink(tvc, areq);
2234 if (tvc->linkData) {
2235 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
2238 /* we have the data */
2239 if (afs_pd_putString(aout, tvc->linkData) != 0)
2245 ReleaseWriteLock(&tvc->lock);
2248 if (sysState.allocked)
2249 osi_FreeLargeSpace(bufp);
2254 * A helper function to get the n'th cell which a particular user has tokens
2255 * for. This is racy. If new tokens are added whilst we're iterating, then
2256 * we may return some cells twice. If tokens expire mid run, then we'll
2257 * miss some cells from our output. So, could be better, but that would
2258 * require an interface change.
2261 static struct unixuser *
2262 getNthCell(afs_int32 uid, afs_int32 iterator) {
2264 struct unixuser *tu = NULL;
2267 ObtainReadLock(&afs_xuser);
2268 for (tu = afs_users[i]; tu; tu = tu->next) {
2269 if (tu->uid == uid && (tu->states & UHasTokens)) {
2270 if (iterator-- == 0)
2271 break; /* are we done yet? */
2277 ReleaseReadLock(&afs_xuser);
2279 afs_LockUser(tu, READ_LOCK, 0);
2286 * VIOCGETTOK (8) - Get authentication tokens
2290 * \param[in] ain cellid to return tokens for
2291 * \param[out] aout token
2294 * Error if the afs daemon hasn't started yet
2296 * Error if the input parameter is out of the bounds of the available
2299 * Error if there aren't tokens for this cell
2302 * If the input paramater exists, get the token that corresponds to
2303 * the parameter value, if there is no token at this value, get the
2304 * token for the first cell
2306 * \notes "it's a weird interface (from comments in the code)"
2309 DECL_PIOCTL(PGetTokens)
2312 struct unixuser *tu = NULL;
2313 union tokenUnion *token;
2314 afs_int32 iterator = 0;
2319 AFS_STATCNT(PGetTokens);
2320 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2321 return EIO; /* Inappropriate ioctl for device */
2323 /* weird interface. If input parameter is present, it is an integer and
2324 * we're supposed to return the parm'th tokens for this unix uid.
2325 * If not present, we just return tokens for cell 1.
2326 * If counter out of bounds, return EDOM.
2327 * If no tokens for the particular cell, return ENOTCONN.
2328 * Also, if this mysterious parm is present, we return, along with the
2329 * tokens, the primary cell indicator (an afs_int32 0) and the cell name
2330 * at the end, in that order.
2332 newStyle = (afs_pd_remaining(ain) > 0);
2334 if (afs_pd_getInt(ain, &iterator) != 0)
2338 tu = getNthCell(areq->uid, iterator);
2340 cellNum = afs_GetPrimaryCellNum();
2342 tu = afs_FindUser(areq->uid, cellNum, READ_LOCK);
2347 if (!(tu->states & UHasTokens)
2348 || !afs_HasUsableTokens(tu->tokens, osi_Time())) {
2349 tu->states |= (UTokensBad | UNeedsReset);
2350 afs_NotifyUser(tu, UTokensDropped);
2351 afs_PutUser(tu, READ_LOCK);
2354 token = afs_FindToken(tu->tokens, RX_SECIDX_KAD);
2356 /* If they don't have an RXKAD token, but do have other tokens,
2357 * then sadly there's nothing this interface can do to help them. */
2361 /* for compat, we try to return 56 byte tix if they fit */
2362 iterator = token->rxkad.ticketLen;
2364 iterator = 56; /* # of bytes we're returning */
2366 if (afs_pd_putInt(aout, iterator) != 0)
2368 if (afs_pd_putBytes(aout, token->rxkad.ticket, token->rxkad.ticketLen) != 0)
2370 if (token->rxkad.ticketLen < 56) {
2371 /* Tokens are always 56 bytes or larger */
2372 if (afs_pd_skip(aout, iterator - token->rxkad.ticketLen) != 0) {
2377 if (afs_pd_putInt(aout, sizeof(struct ClearToken)) != 0)
2379 if (afs_pd_putBytes(aout, &token->rxkad.clearToken,
2380 sizeof(struct ClearToken)) != 0)
2384 /* put out primary id and cell name, too */
2385 iterator = (tu->states & UPrimary ? 1 : 0);
2386 if (afs_pd_putInt(aout, iterator) != 0)
2388 tcell = afs_GetCell(tu->cell, READ_LOCK);
2390 if (afs_pd_putString(aout, tcell->cellName) != 0)
2392 afs_PutCell(tcell, READ_LOCK);
2394 if (afs_pd_putString(aout, "") != 0)
2397 /* Got here, all is good */
2400 afs_PutUser(tu, READ_LOCK);
2405 * VIOCUNLOG (9) - Invalidate tokens
2409 * \param[in] ain not in use
2410 * \param[out] aout not in use
2412 * \retval EIO Error if the afs daemon hasn't been started yet
2414 * \post remove tokens from a user, specified by the user id
2416 * \notes sets the token's time to 0, which then causes it to be removed
2417 * \notes Unlog is the same as un-pag in OpenAFS
2422 struct unixuser *tu;
2424 AFS_STATCNT(PUnlog);
2425 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2426 return EIO; /* Inappropriate ioctl for device */
2428 i = UHash(areq->uid);
2429 ObtainWriteLock(&afs_xuser, 227);
2430 for (tu = afs_users[i]; tu; tu = tu->next) {
2431 if (tu->uid == areq->uid) {
2433 ReleaseWriteLock(&afs_xuser);
2435 afs_LockUser(tu, WRITE_LOCK, 366);
2437 tu->states &= ~UHasTokens;
2438 afs_FreeTokens(&tu->tokens);
2439 afs_NotifyUser(tu, UTokensDropped);
2440 /* We have to drop the lock over the call to afs_ResetUserConns,
2441 * since it obtains the afs_xvcache lock. We could also keep
2442 * the lock, and modify ResetUserConns to take parm saying we
2443 * obtained the lock already, but that is overkill. By keeping
2444 * the "tu" pointer held over the released lock, we guarantee
2445 * that we won't lose our place, and that we'll pass over
2446 * every user conn that existed when we began this call.
2448 afs_ResetUserConns(tu);
2449 afs_PutUser(tu, WRITE_LOCK);
2450 ObtainWriteLock(&afs_xuser, 228);
2452 /* set the expire times to 0, causes
2453 * afs_GCUserData to remove this entry
2456 #endif /* UKERNEL */
2459 ReleaseWriteLock(&afs_xuser);
2464 * VIOC_AFS_MARINER_HOST (32) - Get/set mariner (cache manager monitor) host
2468 * \param[in] ain host address to be set
2469 * \param[out] aout old host address
2472 * depending on whether or not a variable is set, either get the host
2473 * for the cache manager monitor, or set the old address and give it
2476 * \notes Errors turn off mariner
2478 DECL_PIOCTL(PMariner)
2480 afs_int32 newHostAddr;
2481 afs_int32 oldHostAddr;
2483 AFS_STATCNT(PMariner);
2485 memcpy((char *)&oldHostAddr, (char *)&afs_marinerHost,
2488 oldHostAddr = 0xffffffff; /* disabled */
2490 if (afs_pd_getInt(ain, &newHostAddr) != 0)
2493 if (newHostAddr == 0xffffffff) {
2494 /* disable mariner operations */
2496 } else if (newHostAddr) {
2498 afs_marinerHost = newHostAddr;
2501 if (afs_pd_putInt(aout, oldHostAddr) != 0)
2508 * VIOCCKSERV (10) - Check that servers are up
2512 * \param[in] ain name of the cell
2513 * \param[out] aout current down server list
2515 * \retval EIO Error if the afs daemon hasn't started yet
2516 * \retval EACCES Error if the user doesn't have super-user credentials
2517 * \retval ENOENT Error if we are unable to obtain the cell
2520 * Either a fast check (where it doesn't contact servers) or a
2521 * local check (checks local cell only)
2523 DECL_PIOCTL(PCheckServers)
2528 char *cellName = NULL;
2530 struct chservinfo *pcheck;
2532 AFS_STATCNT(PCheckServers);
2534 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2535 return EIO; /* Inappropriate ioctl for device */
2537 /* This is tricky, because we need to peak at the datastream to see
2538 * what we're getting. For now, let's cheat. */
2540 /* ain contains either an int32 or a string */
2541 if (ain->remaining == 0)
2544 if (*(afs_int32 *)ain->ptr == 0x12345678) { /* For afs3.3 version */
2545 pcheck = afs_pd_inline(ain, sizeof(*pcheck));
2549 if (pcheck->tinterval >= 0) {
2550 if (afs_pd_putInt(aout, afs_probe_interval) != 0)
2552 if (pcheck->tinterval > 0) {
2553 if (!afs_osi_suser(*acred))
2555 afs_probe_interval = pcheck->tinterval;
2559 temp = pcheck->tflags;
2561 cellName = pcheck->tbuffer;
2562 } else { /* For pre afs3.3 versions */
2563 if (afs_pd_getInt(ain, &temp) != 0)
2565 if (afs_pd_remaining(ain) > 0) {
2566 if (afs_pd_getStringPtr(ain, &cellName) != 0)
2572 * 1: fast check, don't contact servers.
2573 * 2: local cell only.
2576 /* have cell name, too */
2577 cellp = afs_GetCellByName(cellName, READ_LOCK);
2582 if (!cellp && (temp & 2)) {
2583 /* use local cell */
2584 cellp = afs_GetPrimaryCell(READ_LOCK);
2586 if (!(temp & 1)) { /* if not fast, call server checker routine */
2587 afs_CheckServers(1, cellp); /* check down servers */
2588 afs_CheckServers(0, cellp); /* check up servers */
2590 /* now return the current down server list */
2591 ObtainReadLock(&afs_xserver);
2592 for (i = 0; i < NSERVERS; i++) {
2593 for (ts = afs_servers[i]; ts; ts = ts->next) {
2594 if (cellp && ts->cell != cellp)
2595 continue; /* cell spec'd and wrong */
2596 if ((ts->flags & SRVR_ISDOWN)
2597 && ts->addr->sa_portal != ts->cell->vlport) {
2598 afs_pd_putInt(aout, ts->addr->sa_ip);
2602 ReleaseReadLock(&afs_xserver);
2604 afs_PutCell(cellp, READ_LOCK);
2609 * VIOCCKBACK (11) - Check backup volume mappings
2613 * \param[in] ain not in use
2614 * \param[out] aout not in use
2616 * \retval EIO Error if the afs daemon hasn't started yet
2619 * Check the root volume, and then check the names if the volume
2620 * check variable is set to force, has expired, is busy, or if
2621 * the mount points variable is set
2623 DECL_PIOCTL(PCheckVolNames)
2625 AFS_STATCNT(PCheckVolNames);
2626 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2627 return EIO; /* Inappropriate ioctl for device */
2629 afs_CheckRootVolume();
2630 afs_CheckVolumeNames(AFS_VOLCHECK_FORCE | AFS_VOLCHECK_EXPIRED |
2631 AFS_VOLCHECK_BUSY | AFS_VOLCHECK_MTPTS);
2636 * VIOCCKCONN (12) - Check connections for a user
2640 * \param[in] ain not in use
2641 * \param[out] aout not in use
2644 * Error if no user is specififed, the user has no tokens set,
2645 * or if the user's tokens are bad
2648 * check to see if a user has the correct authentication.
2649 * If so, allow access.
2651 * \notes Check the connections to all the servers specified
2653 DECL_PIOCTL(PCheckAuth)
2657 struct sa_conn_vector *tcv;
2658 struct unixuser *tu;
2661 AFS_STATCNT(PCheckAuth);
2662 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2663 return EIO; /* Inappropriate ioctl for device */
2666 tu = afs_GetUser(areq->uid, 1, READ_LOCK); /* check local cell authentication */
2670 /* we have a user */
2671 ObtainReadLock(&afs_xsrvAddr);
2672 ObtainReadLock(&afs_xconn);
2674 /* any tokens set? */
2675 if ((tu->states & UHasTokens) == 0)
2677 /* all connections in cell 1 working? */
2678 for (i = 0; i < NSERVERS; i++) {
2679 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2680 for (tcv = sa->conns; tcv; tcv = tcv->next) {
2681 if (tcv->user == tu && (tu->states & UTokensBad))
2686 ReleaseReadLock(&afs_xsrvAddr);
2687 ReleaseReadLock(&afs_xconn);
2688 afs_PutUser(tu, READ_LOCK);
2690 if (afs_pd_putInt(aout, retValue) != 0)
2696 Prefetch(uparmtype apath, struct afs_ioctl *adata, int afollow,
2701 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2707 AFS_STATCNT(Prefetch);
2710 tp = osi_AllocLargeSpace(1024);
2711 AFS_COPYINSTR(apath, tp, 1024, &bufferSize, code);
2713 osi_FreeLargeSpace(tp);
2716 if (afs_BBusy()) { /* do this as late as possible */
2717 osi_FreeLargeSpace(tp);
2718 return EWOULDBLOCK; /* pretty close */
2720 afs_BQueue(BOP_PATH, (struct vcache *)0, 0, 0, acred, (afs_size_t) 0,
2721 (afs_size_t) 0, tp, (void *)0, (void *)0);
2726 * VIOCWHEREIS (14) - Find out where a volume is located
2730 * \param[in] ain not in use
2731 * \param[out] aout volume location
2733 * \retval EINVAL Error if some of the default arguments don't exist
2734 * \retval ENODEV Error if there is no such volume
2736 * \post fine a volume, based on a volume file id
2738 * \notes check each of the servers specified
2740 DECL_PIOCTL(PFindVolume)
2747 AFS_STATCNT(PFindVolume);
2750 tvp = afs_GetVolume(&avc->f.fid, areq, READ_LOCK);
2754 for (i = 0; i < AFS_MAXHOSTS; i++) {
2755 ts = tvp->serverHost[i];
2758 if (afs_pd_putInt(aout, ts->addr->sa_ip) != 0) {
2763 if (i < AFS_MAXHOSTS) {
2764 /* still room for terminating NULL, add it on */
2765 if (afs_pd_putInt(aout, 0) != 0) {
2771 afs_PutVolume(tvp, READ_LOCK);
2776 * VIOCACCESS (20) - Access using PRS_FS bits
2780 * \param[in] ain PRS_FS bits
2781 * \param[out] aout not in use
2783 * \retval EINVAL Error if some of the initial arguments aren't set
2784 * \retval EACCES Error if access is denied
2786 * \post check to make sure access is allowed
2788 DECL_PIOCTL(PViceAccess)
2793 AFS_STATCNT(PViceAccess);
2797 code = afs_VerifyVCache(avc, areq);
2801 if (afs_pd_getInt(ain, &temp) != 0)
2804 code = afs_AccessOK(avc, temp, areq, CHECK_MODE_BITS);
2812 * VIOC_GETPAG (13) - Get PAG value
2816 * \param[in] ain not in use
2817 * \param[out] aout PAG value or NOPAG
2819 * \post get PAG value for the caller's cred
2821 DECL_PIOCTL(PGetPAG)
2825 pag = PagInCred(*acred);
2827 return afs_pd_putInt(aout, pag);
2830 DECL_PIOCTL(PPrecache)
2834 /*AFS_STATCNT(PPrecache);*/
2835 if (!afs_osi_suser(*acred))
2838 if (afs_pd_getInt(ain, &newValue) != 0)
2841 afs_preCache = newValue*1024;
2846 * VIOCSETCACHESIZE (24) - Set venus cache size in 1000 units
2850 * \param[in] ain the size the venus cache should be set to
2851 * \param[out] aout not in use
2853 * \retval EACCES Error if the user doesn't have super-user credentials
2854 * \retval EROFS Error if the cache is set to be in memory
2857 * Set the cache size based on user input. If no size is given,
2858 * set it to the default OpenAFS cache size.
2861 * recompute the general cache parameters for every single block allocated
2863 DECL_PIOCTL(PSetCacheSize)
2868 AFS_STATCNT(PSetCacheSize);
2870 if (!afs_osi_suser(*acred))
2872 /* too many things are setup initially in mem cache version */
2873 if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
2875 if (afs_pd_getInt(ain, &newValue) != 0)
2878 afs_cacheBlocks = afs_stats_cmperf.cacheBlocksOrig;
2880 if (newValue < afs_min_cache)
2881 afs_cacheBlocks = afs_min_cache;
2883 afs_cacheBlocks = newValue;
2885 afs_stats_cmperf.cacheBlocksTotal = afs_cacheBlocks;
2886 afs_ComputeCacheParms(); /* recompute basic cache parameters */
2887 afs_MaybeWakeupTruncateDaemon();
2888 while (waitcnt++ < 100 && afs_cacheBlocks < afs_blocksUsed) {
2889 afs_osi_Wait(1000, 0, 0);
2890 afs_MaybeWakeupTruncateDaemon();
2895 #define MAXGCSTATS 16
2897 * VIOCGETCACHEPARMS (40) - Get cache stats
2901 * \param[in] ain afs index flags
2902 * \param[out] aout cache blocks, blocks used, blocks files (in an array)
2904 * \post Get the cache blocks, and how many of the cache blocks there are
2906 DECL_PIOCTL(PGetCacheSize)
2908 afs_int32 results[MAXGCSTATS];
2910 struct dcache * tdc;
2913 AFS_STATCNT(PGetCacheSize);
2915 if (afs_pd_remaining(ain) == sizeof(afs_int32)) {
2916 afs_pd_getInt(ain, &flags); /* can't error, we just checked size */
2917 } else if (afs_pd_remaining(ain) == 0) {
2923 memset(results, 0, sizeof(results));
2924 results[0] = afs_cacheBlocks;
2925 results[1] = afs_blocksUsed;
2926 results[2] = afs_cacheFiles;
2929 for (i = 0; i < afs_cacheFiles; i++) {
2930 if (afs_indexFlags[i] & IFFree) results[3]++;
2932 } else if (2 == flags){
2933 for (i = 0; i < afs_cacheFiles; i++) {
2934 if (afs_indexFlags[i] & IFFree) results[3]++;
2935 if (afs_indexFlags[i] & IFEverUsed) results[4]++;
2936 if (afs_indexFlags[i] & IFDataMod) results[5]++;
2937 if (afs_indexFlags[i] & IFDirtyPages) results[6]++;
2938 if (afs_indexFlags[i] & IFAnyPages) results[7]++;
2939 if (afs_indexFlags[i] & IFDiscarded) results[8]++;
2941 tdc = afs_indexTable[i];
2944 size = tdc->validPos;
2945 if ( 0 < size && size < (1<<12) ) results[10]++;
2946 else if (size < (1<<14) ) results[11]++;
2947 else if (size < (1<<16) ) results[12]++;
2948 else if (size < (1<<18) ) results[13]++;
2949 else if (size < (1<<20) ) results[14]++;
2950 else if (size >= (1<<20) ) results[15]++;
2954 return afs_pd_putBytes(aout, results, sizeof(results));
2958 * VIOCFLUSHCB (25) - Flush callback only
2962 * \param[in] ain not in use
2963 * \param[out] aout not in use
2965 * \retval EINVAL Error if some of the standard args aren't set
2966 * \retval 0 0 returned if the volume is set to read-only
2969 * Flushes callbacks, by setting the length of callbacks to one,
2970 * setting the next callback to be sent to the CB_DROPPED value,
2971 * and then dequeues everything else.
2973 DECL_PIOCTL(PRemoveCallBack)
2975 struct afs_conn *tc;
2977 struct AFSCallBack CallBacks_Array[1];
2978 struct AFSCBFids theFids;
2979 struct AFSCBs theCBs;
2980 struct rx_connection *rxconn;
2983 AFS_STATCNT(PRemoveCallBack);
2986 if (avc->f.states & CRO)
2987 return 0; /* read-only-ness can't change */
2988 ObtainWriteLock(&avc->lock, 229);
2989 theFids.AFSCBFids_len = 1;
2990 theCBs.AFSCBs_len = 1;
2991 theFids.AFSCBFids_val = (struct AFSFid *)&avc->f.fid.Fid;
2992 theCBs.AFSCBs_val = CallBacks_Array;
2993 CallBacks_Array[0].CallBackType = CB_DROPPED;
2994 if (avc->callback) {
2996 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK, &rxconn);
2998 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
3000 code = RXAFS_GiveUpCallBacks(rxconn, &theFids, &theCBs);
3004 /* don't set code on failure since we wouldn't use it */
3005 } while (afs_Analyze
3006 (tc, rxconn, code, &avc->f.fid, areq,
3007 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK, NULL));
3009 ObtainWriteLock(&afs_xcbhash, 457);
3010 afs_DequeueCallback(avc);
3012 avc->f.states &= ~(CStatd | CUnique);
3013 ReleaseWriteLock(&afs_xcbhash);
3014 if (avc->f.fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
3015 osi_dnlc_purgedp(avc);
3017 ReleaseWriteLock(&avc->lock);
3022 * VIOCNEWCELL (26) - Configure new cell
3027 * the name of the cell, the hosts that will be a part of the cell,
3028 * whether or not it's linked with another cell, the other cell it's
3029 * linked with, the file server port, and the volume server port
3033 * \retval EIO Error if the afs daemon hasn't started yet
3034 * \retval EACCES Error if the user doesn't have super-user cedentials
3035 * \retval EINVAL Error if some 'magic' var doesn't have a certain bit set
3037 * \post creates a new cell
3039 DECL_PIOCTL(PNewCell)
3041 afs_int32 cellHosts[AFS_MAXCELLHOSTS], magic = 0;
3042 char *newcell = NULL;
3043 char *linkedcell = NULL;
3045 afs_int32 linkedstate = 0;
3046 afs_int32 fsport = 0, vlport = 0;
3049 AFS_STATCNT(PNewCell);
3050 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3051 return EIO; /* Inappropriate ioctl for device */
3053 if (!afs_osi_suser(*acred))
3056 if (afs_pd_getInt(ain, &magic) != 0)
3058 if (magic != 0x12345678)
3061 /* A 3.4 fs newcell command will pass an array of AFS_MAXCELLHOSTS
3062 * server addresses while the 3.5 fs newcell command passes
3063 * AFS_MAXHOSTS. To figure out which is which, check if the cellname
3066 * This whole logic is bogus, because it relies on the newer command
3067 * sending its 12th address as 0.
3069 if ((afs_pd_remaining(ain) < AFS_MAXCELLHOSTS +3) * sizeof(afs_int32))
3072 newcell = afs_pd_where(ain) + (AFS_MAXCELLHOSTS + 3) * sizeof(afs_int32);
3073 if (newcell[0] != '\0') {
3076 skip = AFS_MAXHOSTS - AFS_MAXCELLHOSTS;
3079 /* AFS_MAXCELLHOSTS (=8) is less than AFS_MAXHOSTS (=13) */
3080 if (afs_pd_getBytes(ain, &cellHosts,
3081 AFS_MAXCELLHOSTS * sizeof(afs_int32)) != 0)
3083 if (afs_pd_skip(ain, skip * sizeof(afs_int32)) !=0)
3086 if (afs_pd_getInt(ain, &fsport) != 0)
3089 fsport = 0; /* Privileged ports not allowed */
3091 if (afs_pd_getInt(ain, &vlport) != 0)
3094 vlport = 0; /* Privileged ports not allowed */
3096 if (afs_pd_getInt(ain, &ls) != 0)
3099 if (afs_pd_getStringPtr(ain, &newcell) != 0)
3103 if (afs_pd_getStringPtr(ain, &linkedcell) != 0)
3105 linkedstate |= CLinkedCell;
3108 linkedstate |= CNoSUID; /* setuid is disabled by default for fs newcell */
3110 afs_NewCell(newcell, cellHosts, linkedstate, linkedcell, fsport,
3115 DECL_PIOCTL(PNewAlias)
3117 /* create a new cell alias */
3118 char *realName, *aliasName;
3120 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3121 return EIO; /* Inappropriate ioctl for device */
3123 if (!afs_osi_suser(*acred))
3126 if (afs_pd_getStringPtr(ain, &aliasName) != 0)
3128 if (afs_pd_getStringPtr(ain, &realName) != 0)
3131 return afs_NewCellAlias(aliasName, realName);
3135 * VIOCGETCELL (27) - Get cell info
3139 * \param[in] ain The cell index of a specific cell
3140 * \param[out] aout list of servers in the cell
3142 * \retval EIO Error if the afs daemon hasn't started yet
3143 * \retval EDOM Error if there is no cell asked about
3145 * \post Lists the cell's server names and and addresses
3147 DECL_PIOCTL(PListCells)
3149 afs_int32 whichCell;
3150 struct cell *tcell = 0;
3154 AFS_STATCNT(PListCells);
3155 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3156 return EIO; /* Inappropriate ioctl for device */
3158 if (afs_pd_getInt(ain, &whichCell) != 0)
3161 tcell = afs_GetCellByIndex(whichCell, READ_LOCK);
3167 for (i = 0; i < AFS_MAXCELLHOSTS; i++) {
3168 if (tcell->cellHosts[i] == 0)
3170 if (afs_pd_putInt(aout, tcell->cellHosts[i]->addr->sa_ip) != 0)
3173 for (;i < AFS_MAXCELLHOSTS; i++) {
3174 if (afs_pd_putInt(aout, 0) != 0)
3177 if (afs_pd_putString(aout, tcell->cellName) != 0)
3182 afs_PutCell(tcell, READ_LOCK);
3186 DECL_PIOCTL(PListAliases)
3188 afs_int32 whichAlias;
3189 struct cell_alias *tcalias = 0;
3192 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3193 return EIO; /* Inappropriate ioctl for device */
3195 if (afs_pd_getInt(ain, &whichAlias) != 0)
3198 tcalias = afs_GetCellAlias(whichAlias);
3199 if (tcalias == NULL)
3203 if (afs_pd_putString(aout, tcalias->alias) != 0)
3205 if (afs_pd_putString(aout, tcalias->cell) != 0)
3210 afs_PutCellAlias(tcalias);
3215 * VIOC_AFS_DELETE_MT_PT (28) - Delete mount point
3219 * \param[in] ain the name of the file in this dir to remove
3220 * \param[out] aout not in use
3223 * Error if some of the standard args aren't set
3225 * Error if the argument to remove is not a directory
3227 * Error if there is no cache to remove the mount point from or
3228 * if a vcache doesn't exist
3231 * Ensure that everything is OK before deleting the mountpoint.
3232 * If not, don't delete. Delete a mount point based on a file id.
3234 DECL_PIOCTL(PRemoveMount)
3239 struct sysname_info sysState;
3240 afs_size_t offset, len;
3241 struct afs_conn *tc;
3244 struct AFSFetchStatus OutDirStatus;
3245 struct VenusFid tfid;
3246 struct AFSVolSync tsync;
3247 struct rx_connection *rxconn;
3250 /* "ain" is the name of the file in this dir to remove */
3252 AFS_STATCNT(PRemoveMount);
3255 if (afs_pd_getStringPtr(ain, &name) != 0)
3258 code = afs_VerifyVCache(avc, areq);
3261 if (vType(avc) != VDIR)
3264 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1); /* test for error below */
3267 Check_AtSys(avc, name, &sysState, areq);
3268 ObtainReadLock(&tdc->lock);
3270 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
3271 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
3272 ReleaseReadLock(&tdc->lock);
3273 bufp = sysState.name;
3278 tfid.Cell = avc->f.fid.Cell;
3279 tfid.Fid.Volume = avc->f.fid.Fid.Volume;
3280 if (!tfid.Fid.Unique && (avc->f.states & CForeign)) {
3281 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
3283 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3290 if (tvc->mvstat != 1) {
3296 ObtainWriteLock(&tvc->lock, 230);
3297 code = afs_HandleLink(tvc, areq);
3299 if (tvc->linkData) {
3300 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
3305 ReleaseWriteLock(&tvc->lock);
3306 osi_dnlc_purgedp(tvc);
3312 ObtainWriteLock(&avc->lock, 231);
3313 osi_dnlc_remove(avc, bufp, tvc);
3315 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK, &rxconn);
3317 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE);
3320 RXAFS_RemoveFile(rxconn, (struct AFSFid *)&avc->f.fid.Fid, bufp,
3321 &OutDirStatus, &tsync);
3326 } while (afs_Analyze
3327 (tc, rxconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_REMOVEFILE,
3328 SHARED_LOCK, NULL));
3333 ReleaseWriteLock(&avc->lock);
3337 /* we have the thing in the cache */
3338 ObtainWriteLock(&tdc->lock, 661);
3339 if (afs_LocalHero(avc, tdc, &OutDirStatus, 1)) {
3340 /* we can do it locally */
3341 code = afs_dir_Delete(tdc, bufp);
3343 ZapDCE(tdc); /* surprise error -- invalid value */
3347 ReleaseWriteLock(&tdc->lock);
3348 afs_PutDCache(tdc); /* drop ref count */
3350 avc->f.states &= ~CUnique; /* For the dfs xlator */
3351 ReleaseWriteLock(&avc->lock);
3354 if (sysState.allocked)
3355 osi_FreeLargeSpace(bufp);
3360 * VIOC_GETCELLSTATUS (35) - Get cell status info
3364 * \param[in] ain The cell you want status information on
3365 * \param[out] aout cell state (as a struct)
3367 * \retval EIO Error if the afs daemon hasn't started yet
3368 * \retval ENOENT Error if the cell doesn't exist
3370 * \post Returns the state of the cell as defined in a struct cell
3372 DECL_PIOCTL(PGetCellStatus)
3378 AFS_STATCNT(PGetCellStatus);
3379 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3380 return EIO; /* Inappropriate ioctl for device */
3382 if (afs_pd_getStringPtr(ain, &cellName) != 0)
3385 tcell = afs_GetCellByName(cellName, READ_LOCK);
3388 temp = tcell->states;
3389 afs_PutCell(tcell, READ_LOCK);
3391 return afs_pd_putInt(aout, temp);
3395 * VIOC_SETCELLSTATUS (36) - Set corresponding info
3400 * The cell you want to set information about, and the values you
3405 * \retval EIO Error if the afs daemon hasn't started yet
3406 * \retval EACCES Error if the user doesn't have super-user credentials
3409 * Set the state of the cell in a defined struct cell, based on
3410 * whether or not SetUID is allowed
3412 DECL_PIOCTL(PSetCellStatus)
3416 afs_int32 flags0, flags1;
3418 if (!afs_osi_suser(*acred))
3420 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3421 return EIO; /* Inappropriate ioctl for device */
3423 if (afs_pd_getInt(ain, &flags0) != 0)
3425 if (afs_pd_getInt(ain, &flags1) != 0)
3427 if (afs_pd_getStringPtr(ain, &cellName) != 0)
3430 tcell = afs_GetCellByName(cellName, WRITE_LOCK);
3433 if (flags0 & CNoSUID)
3434 tcell->states |= CNoSUID;
3436 tcell->states &= ~CNoSUID;
3437 afs_PutCell(tcell, WRITE_LOCK);
3442 * VIOC_FLUSHVOLUME (37) - Flush whole volume's data
3446 * \param[in] ain not in use (args in avc)
3447 * \param[out] aout not in use
3449 * \retval EINVAL Error if some of the standard args aren't set
3450 * \retval EIO Error if the afs daemon hasn't started yet
3453 * Flush all cached contents of a volume. Exactly what stays and what
3454 * goes depends on the platform.
3457 * Does not flush a file that a user has open and is using, because
3458 * it will be re-created on next write. Also purges the dnlc,
3459 * because things are screwed up.
3461 DECL_PIOCTL(PFlushVolumeData)
3467 afs_int32 cell, volume;
3468 struct afs_q *tq, *uq;
3469 #ifdef AFS_DARWIN80_ENV
3473 AFS_STATCNT(PFlushVolumeData);
3476 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3477 return EIO; /* Inappropriate ioctl for device */
3479 volume = avc->f.fid.Fid.Volume; /* who to zap */
3480 cell = avc->f.fid.Cell;
3483 * Clear stat'd flag from all vnodes from this volume; this will
3484 * invalidate all the vcaches associated with the volume.
3487 ObtainReadLock(&afs_xvcache);
3488 i = VCHashV(&avc->f.fid);
3489 for (tq = afs_vhashTV[i].prev; tq != &afs_vhashTV[i]; tq = uq) {
3492 if (tvc->f.fid.Fid.Volume == volume && tvc->f.fid.Cell == cell) {
3493 if (tvc->f.states & CVInit) {
3494 ReleaseReadLock(&afs_xvcache);
3495 afs_osi_Sleep(&tvc->f.states);
3498 #ifdef AFS_DARWIN80_ENV
3499 if (tvc->f.states & CDeadVnode) {
3500 ReleaseReadLock(&afs_xvcache);
3501 afs_osi_Sleep(&tvc->f.states);
3507 if (vnode_ref(vp)) {
3516 ReleaseReadLock(&afs_xvcache);
3517 #ifdef AFS_BOZONLOCK_ENV
3518 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
3520 ObtainWriteLock(&tvc->lock, 232);
3522 ObtainWriteLock(&afs_xcbhash, 458);
3523 afs_DequeueCallback(tvc);
3524 tvc->f.states &= ~(CStatd | CDirty);
3525 ReleaseWriteLock(&afs_xcbhash);
3526 if (tvc->f.fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
3527 osi_dnlc_purgedp(tvc);
3528 afs_TryToSmush(tvc, *acred, 1);
3529 ReleaseWriteLock(&tvc->lock);
3530 #ifdef AFS_BOZONLOCK_ENV
3531 afs_BozonUnlock(&tvc->pvnLock, tvc);
3533 #ifdef AFS_DARWIN80_ENV
3534 vnode_put(AFSTOV(tvc));
3536 ObtainReadLock(&afs_xvcache);
3538 /* our tvc ptr is still good until now */
3542 ReleaseReadLock(&afs_xvcache);
3545 ObtainWriteLock(&afs_xdcache, 328); /* needed to flush any stuff */
3546 for (i = 0; i < afs_cacheFiles; i++) {
3547 if (!(afs_indexFlags[i] & IFEverUsed))
3548 continue; /* never had any data */
3549 tdc = afs_GetDSlot(i, NULL);
3550 if (tdc->refCount <= 1) { /* too high, in use by running sys call */
3551 ReleaseReadLock(&tdc->tlock);
3552 if (tdc->f.fid.Fid.Volume == volume && tdc->f.fid.Cell == cell) {
3553 if (!(afs_indexFlags[i] & IFDataMod)) {
3554 /* if the file is modified, but has a ref cnt of only 1,
3555 * then someone probably has the file open and is writing
3556 * into it. Better to skip flushing such a file, it will be
3557 * brought back immediately on the next write anyway.
3559 * If we *must* flush, then this code has to be rearranged
3560 * to call afs_storeAllSegments() first */
3561 afs_FlushDCache(tdc);
3565 ReleaseReadLock(&tdc->tlock);
3567 afs_PutDCache(tdc); /* bumped by getdslot */
3569 ReleaseWriteLock(&afs_xdcache);
3571 ObtainReadLock(&afs_xvolume);
3572 for (i = 0; i < NVOLS; i++) {
3573 for (tv = afs_volumes[i]; tv; tv = tv->next) {
3574 if (tv->volume == volume) {
3575 afs_ResetVolumeInfo(tv);
3580 ReleaseReadLock(&afs_xvolume);
3582 /* probably, a user is doing this, probably, because things are screwed up.
3583 * maybe it's the dnlc's fault? */
3590 * VIOCGETVCXSTATUS (41) - gets vnode x status
3595 * not in use (avc used)
3597 * vcxstat: the file id, the data version, any lock, the parent vnode,
3598 * the parent unique id, the trunc position, the callback, cbExpires,
3599 * what access is being made, what files are open,
3600 * any users executing/writing, the flock count, the states,
3604 * Error if some of the initial default arguments aren't set
3606 * Error if access to check the mode bits is denied
3609 * gets stats for the vnode, a struct listed in vcxstat
3611 DECL_PIOCTL(PGetVnodeXStatus)
3614 struct vcxstat stat;
3617 /* AFS_STATCNT(PGetVnodeXStatus); */
3620 code = afs_VerifyVCache(avc, areq);
3623 if (vType(avc) == VDIR)
3624 mode = PRSFS_LOOKUP;
3627 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
3630 memset(&stat, 0, sizeof(struct vcxstat));
3631 stat.fid = avc->f.fid;
3632 hset32(stat.DataVersion, hgetlo(avc->f.m.DataVersion));
3633 stat.lock = avc->lock;
3634 stat.parentVnode = avc->f.parent.vnode;
3635 stat.parentUnique = avc->f.parent.unique;
3636 hset(stat.flushDV, avc->flushDV);
3637 hset(stat.mapDV, avc->mapDV);
3638 stat.truncPos = avc->f.truncPos;
3639 { /* just grab the first two - won't break anything... */
3640 struct axscache *ac;
3642 for (i = 0, ac = avc->Access; ac && i < CPSIZE; i++, ac = ac->next) {
3643 stat.randomUid[i] = ac->uid;
3644 stat.randomAccess[i] = ac->axess;
3647 stat.callback = afs_data_pointer_to_int32(avc->callback);
3648 stat.cbExpires = avc->cbExpires;
3649 stat.anyAccess = avc->f.anyAccess;
3650 stat.opens = avc->opens;
3651 stat.execsOrWriters = avc->execsOrWriters;
3652 stat.flockCount = avc->flockCount;
3653 stat.mvstat = avc->mvstat;
3654 stat.states = avc->f.states;
3655 return afs_pd_putBytes(aout, &stat, sizeof(struct vcxstat));
3659 DECL_PIOCTL(PGetVnodeXStatus2)
3662 struct vcxstat2 stat;
3667 code = afs_VerifyVCache(avc, areq);
3670 if (vType(avc) == VDIR)
3671 mode = PRSFS_LOOKUP;
3674 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
3677 memset(&stat, 0, sizeof(struct vcxstat2));
3679 stat.cbExpires = avc->cbExpires;
3680 stat.anyAccess = avc->f.anyAccess;
3681 stat.mvstat = avc->mvstat;
3682 stat.callerAccess = afs_GetAccessBits(avc, ~0, areq);
3684 return afs_pd_putBytes(aout, &stat, sizeof(struct vcxstat2));
3689 * VIOC_AFS_SYSNAME (38) - Change @sys value
3693 * \param[in] ain new value for @sys
3694 * \param[out] aout count, entry, list (debug values?)
3697 * Error if afsd isn't running, the new sysname is too large,
3698 * the new sysname causes issues (starts with a . or ..),
3699 * there is no PAG set in the credentials, or the user of a PAG
3702 * Error if the user doesn't have super-user credentials
3705 * Set the value of @sys if these things work: if the input isn't
3706 * too long or if input doesn't start with . or ..
3709 * We require root for local sysname changes, but not for remote
3710 * (since we don't really believe remote uids anyway)
3711 * outname[] shouldn't really be needed- this is left as an
3712 * exercise for the reader.
3714 DECL_PIOCTL(PSetSysName)
3716 char *inname = NULL;
3717 char outname[MAXSYSNAME];
3718 afs_int32 setsysname;
3720 struct afs_exporter *exporter;
3721 struct unixuser *au;
3722 afs_int32 pag, error;
3723 int t, count, num = 0, allpags = 0;
3725 struct afs_pdata validate;
3727 AFS_STATCNT(PSetSysName);
3728 if (!afs_globalVFS) {
3729 /* Afsd is NOT running; disable it */
3730 #if defined(KERNEL_HAVE_UERROR)
3731 return (setuerror(EINVAL), EINVAL);
3736 if (afs_pd_getInt(ain, &setsysname) != 0)
3738 if (setsysname & 0x8000) {
3740 setsysname &= ~0x8000;
3745 if (setsysname < 0 || setsysname > MAXNUMSYSNAMES)
3748 for (count = 0; count < setsysname; count++) {
3749 if (afs_pd_getStringPtr(&validate, &inname) != 0)
3752 if (t >= MAXSYSNAME || t <= 0)
3754 /* check for names that can shoot us in the foot */
3755 if (inname[0] == '.' && (inname[1] == 0
3756 || (inname[1] == '.' && inname[2] == 0)))
3759 /* args ok, so go back to the beginning of that section */
3761 if (afs_pd_getStringPtr(ain, &inname) != 0)
3765 if (afs_cr_gid(*acred) == RMTUSER_REQ ||
3766 afs_cr_gid(*acred) == RMTUSER_REQ_PRIV) { /* Handles all exporters */
3767 if (allpags && afs_cr_gid(*acred) != RMTUSER_REQ_PRIV) {
3770 pag = PagInCred(*acred);
3772 return EINVAL; /* Better than panicing */
3774 if (!(au = afs_FindUser(pag, -1, READ_LOCK))) {
3775 return EINVAL; /* Better than panicing */
3777 if (!(exporter = au->exporter)) {
3778 afs_PutUser(au, READ_LOCK);
3779 return EINVAL; /* Better than panicing */
3781 error = EXP_SYSNAME(exporter, inname, &sysnamelist,
3784 if (error == ENODEV)
3785 foundname = 0; /* sysname not set yet! */
3787 afs_PutUser(au, READ_LOCK);
3792 strcpy(outname, sysnamelist[0]);
3794 afs_PutUser(au, READ_LOCK);
3798 /* Not xlating, so local case */
3800 osi_Panic("PSetSysName: !afs_sysname\n");
3801 if (!setsysname) { /* user just wants the info */
3802 strcpy(outname, afs_sysname);
3803 foundname = afs_sysnamecount;
3804 sysnamelist = afs_sysnamelist;
3805 } else { /* Local guy; only root can change sysname */
3806 if (!afs_osi_suser(*acred))
3809 /* allpags makes no sense for local use */
3813 /* clear @sys entries from the dnlc, once afs_lookup can
3814 * do lookups of @sys entries and thinks it can trust them */
3815 /* privs ok, store the entry, ... */
3817 if (strlen(inname) >= MAXSYSNAME-1)
3819 strcpy(afs_sysname, inname);
3821 if (setsysname > 1) { /* ... or list */
3822 for (count = 1; count < setsysname; ++count) {
3823 if (!afs_sysnamelist[count])
3825 ("PSetSysName: no afs_sysnamelist entry to write\n");
3826 if (afs_pd_getString(ain, afs_sysnamelist[count],
3831 afs_sysnamecount = setsysname;
3836 if (afs_pd_putInt(aout, foundname) != 0)
3839 if (afs_pd_putString(aout, outname) != 0)
3841 for (count = 1; count < foundname; ++count) { /* ... or list. */
3842 if (!sysnamelist[count])
3844 ("PSetSysName: no afs_sysnamelist entry to read\n");
3845 t = strlen(sysnamelist[count]);
3846 if (t >= MAXSYSNAME)
3847 osi_Panic("PSetSysName: sysname entry garbled\n");
3848 if (afs_pd_putString(aout, sysnamelist[count]) != 0)
3856 /* sequential search through the list of touched cells is not a good
3857 * long-term solution here. For small n, though, it should be just
3858 * fine. Should consider special-casing the local cell for large n.
3859 * Likewise for PSetSPrefs.
3861 * s - number of ids in array l[] -- NOT index of last id
3862 * l - array of cell ids which have volumes that need to be sorted
3863 * vlonly - sort vl servers or file servers?
3866 ReSortCells_cb(struct cell *cell, void *arg)
3868 afs_int32 *p = (afs_int32 *) arg;
3869 afs_int32 *l = p + 1;
3872 for (i = 0; i < s; i++) {
3873 if (l[i] == cell->cellNum) {
3874 ObtainWriteLock(&cell->lock, 690);
3875 afs_SortServers(cell->cellHosts, AFS_MAXCELLHOSTS);
3876 ReleaseWriteLock(&cell->lock);
3884 ReSortCells(int s, afs_int32 * l, int vlonly)
3892 p = afs_osi_Alloc(sizeof(afs_int32) * (s + 1));
3893 osi_Assert(p != NULL);
3895 memcpy(p + 1, l, s * sizeof(afs_int32));
3896 afs_TraverseCells(&ReSortCells_cb, p);
3897 afs_osi_Free(p, sizeof(afs_int32) * (s + 1));
3901 ObtainReadLock(&afs_xvolume);
3902 for (i = 0; i < NVOLS; i++) {
3903 for (j = afs_volumes[i]; j; j = j->next) {
3904 for (k = 0; k < s; k++)
3905 if (j->cell == l[k]) {
3906 ObtainWriteLock(&j->lock, 233);
3907 afs_SortServers(j->serverHost, AFS_MAXHOSTS);
3908 ReleaseWriteLock(&j->lock);
3913 ReleaseReadLock(&afs_xvolume);
3917 static int debugsetsp = 0;
3919 afs_setsprefs(struct spref *sp, unsigned int num, unsigned int vlonly)
3922 int i, j, k, matches, touchedSize;
3923 struct server *srvr = NULL;
3924 afs_int32 touched[34];
3928 for (k = 0; k < num; sp++, k++) {
3930 afs_warn("sp host=%x, rank=%d\n", sp->host.s_addr, sp->rank);
3933 ObtainReadLock(&afs_xserver);
3935 i = SHash(sp->host.s_addr);
3936 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3937 if (sa->sa_ip == sp->host.s_addr) {
3939 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
3940 || (sa->sa_portal == AFS_FSPORT);
3941 if ((!vlonly && isfs) || (vlonly && !isfs)) {
3948 if (sa && matches) { /* found one! */
3950 afs_warn("sa ip=%x, ip_rank=%d\n", sa->sa_ip, sa->sa_iprank);
3952 sa->sa_iprank = sp->rank + afs_randomMod15();
3953 afs_SortOneServer(sa->server);
3956 /* if we don't know yet what cell it's in, this is moot */
3957 for (j = touchedSize - 1;
3958 j >= 0 && touched[j] != srvr->cell->cellNum; j--)
3959 /* is it in our list of touched cells ? */ ;
3960 if (j < 0) { /* no, it's not */
3961 touched[touchedSize++] = srvr->cell->cellNum;
3962 if (touchedSize >= 32) { /* watch for ovrflow */
3963 ReleaseReadLock(&afs_xserver);
3964 ReSortCells(touchedSize, touched, vlonly);
3966 ObtainReadLock(&afs_xserver);
3972 ReleaseReadLock(&afs_xserver);
3973 /* if we didn't find one, start to create one. */
3974 /* Note that it doesn't have a cell yet... */
3976 afs_uint32 temp = sp->host.s_addr;
3978 afs_GetServer(&temp, 1, 0, (vlonly ? AFS_VLPORT : AFS_FSPORT),
3979 WRITE_LOCK, (afsUUID *) 0, 0, NULL);
3980 srvr->addr->sa_iprank = sp->rank + afs_randomMod15();
3981 afs_PutServer(srvr, WRITE_LOCK);
3983 } /* for all cited preferences */
3985 ReSortCells(touchedSize, touched, vlonly);
3990 * VIOC_SETPREFS (46) - Set server ranks
3992 * \param[in] ain the sprefs value you want the sprefs to be set to
3993 * \param[out] aout not in use
3996 * Error if the afs daemon hasn't started yet
3998 * Error if the user doesn't have super-user credentials
4000 * Error if the struct setsprefs is too large or if it multiplied
4001 * by the number of servers is too large
4003 * \post set the sprefs using the afs_setsprefs() function
4005 DECL_PIOCTL(PSetSPrefs)
4007 struct setspref *ssp;
4011 AFS_STATCNT(PSetSPrefs);
4013 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4014 return EIO; /* Inappropriate ioctl for device */
4016 if (!afs_osi_suser(*acred))
4019 /* The I/O handling here is ghastly, as it relies on overrunning the ends
4020 * of arrays. But, i'm not quite brave enough to change it yet. */
4022 ainSize = ain->remaining;
4024 if (ainSize < sizeof(struct setspref))
4027 ssp = (struct setspref *)ainPtr;
4028 if (ainSize < (sizeof(struct setspref)
4029 + sizeof(struct spref) * (ssp->num_servers-1)))
4032 afs_setsprefs(&(ssp->servers[0]), ssp->num_servers,
4033 (ssp->flags & DBservers));
4038 * VIOC_SETPREFS33 (42) - Set server ranks (deprecated)
4040 * \param[in] ain the server preferences to be set
4041 * \param[out] aout not in use
4043 * \retval EIO Error if the afs daemon hasn't started yet
4044 * \retval EACCES Error if the user doesn't have super-user credentials
4046 * \post set the server preferences, calling a function
4048 * \notes this may only be performed by the local root user.
4050 DECL_PIOCTL(PSetSPrefs33)
4052 AFS_STATCNT(PSetSPrefs);
4053 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4054 return EIO; /* Inappropriate ioctl for device */
4057 if (!afs_osi_suser(*acred))
4060 afs_setsprefs((struct spref *)afs_pd_where(ain),
4061 afs_pd_remaining(ain) / sizeof(struct spref),
4067 * VIOC_GETSPREFS (43) - Get server ranks
4071 * \param[in] ain the server preferences to get
4072 * \param[out] aout the server preferences information
4074 * \retval EIO Error if the afs daemon hasn't started yet
4075 * \retval ENOENT Error if the sprefrequest is too large
4077 * \post Get the sprefs
4080 * in the hash table of server structs, all servers with the same
4081 * IP address; will be on the same overflow chain; This could be
4082 * sped slightly in some circumstances by having it cache the
4083 * immediately previous slot in the hash table and some
4084 * supporting information; Only reports file servers now.
4086 DECL_PIOCTL(PGetSPrefs)
4088 struct sprefrequest spin; /* input */
4089 struct sprefinfo *spout; /* output */
4090 struct spref *srvout; /* one output component */
4091 int i, j; /* counters for hash table traversal */
4092 struct server *srvr; /* one of CM's server structs */
4094 int vlonly; /* just return vlservers ? */
4097 AFS_STATCNT(PGetSPrefs);
4098 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4099 return EIO; /* Inappropriate ioctl for device */
4101 /* Work out from the size whether we've got a new, or old, style pioctl */
4102 if (afs_pd_remaining(ain) < sizeof(struct sprefrequest)) {
4103 if (afs_pd_getBytes(ain, &spin, sizeof(struct sprefrequest_33)) != 0)
4108 if (afs_pd_getBytes(ain, &spin, sizeof(struct sprefrequest)) != 0)
4110 vlonly = (spin.flags & DBservers);
4113 /* This code relies on overflowing arrays. It's ghastly, but I'm not
4114 * quite brave enough to tackle it yet ...
4117 /* struct sprefinfo includes 1 server struct... that size gets added
4118 * in during the loop that follows.
4120 spout = afs_pd_inline(aout,
4121 sizeof(struct sprefinfo) - sizeof(struct spref));
4122 spout->next_offset = spin.offset;
4123 spout->num_servers = 0;
4124 srvout = spout->servers;
4126 ObtainReadLock(&afs_xserver);
4127 for (i = 0, j = 0; j < NSERVERS; j++) { /* sift through hash table */
4128 for (sa = afs_srvAddrs[j]; sa; sa = sa->next_bkt, i++) {
4129 if (spin.offset > (unsigned short)i) {
4130 continue; /* catch up to where we left off */
4132 spout->next_offset++;
4135 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
4136 || (sa->sa_portal == AFS_FSPORT);
4138 if ((vlonly && isfs) || (!vlonly && !isfs)) {
4139 /* only report ranks for vl servers */
4143 /* Check we've actually got the space we're about to use */
4144 if (afs_pd_inline(aout, sizeof(struct spref)) == NULL) {
4145 ReleaseReadLock(&afs_xserver); /* no more room! */
4149 srvout->host.s_addr = sa->sa_ip;
4150 srvout->rank = sa->sa_iprank;
4151 spout->num_servers++;
4155 ReleaseReadLock(&afs_xserver);
4157 spout->next_offset = 0; /* start over from the beginning next time */
4162 /* Enable/Disable the specified exporter. Must be root to disable an exporter */
4163 int afs_NFSRootOnly = 1;
4165 * VIOC_EXPORTAFS (39) - Export afs to nfs clients
4170 * an integer containing the desired exportee flags
4172 * an integer containing the current exporter flags
4174 * \retval ENODEV Error if the exporter doesn't exist
4175 * \retval EACCES Error if the user doesn't have super-user credentials
4178 * Changes the state of various values to reflect the change
4179 * of the export values between nfs and afs.
4181 * \notes Legacy code obtained from IBM.
4183 DECL_PIOCTL(PExportAfs)
4185 afs_int32 export, newint = 0;
4186 afs_int32 type, changestate, handleValue, convmode, pwsync, smounts;
4187 afs_int32 rempags = 0, pagcb = 0;
4188 struct afs_exporter *exporter;
4190 AFS_STATCNT(PExportAfs);
4191 if (afs_pd_getInt(ain, &handleValue) != 0)
4193 type = handleValue >> 24;
4198 exporter = exporter_find(type);
4200 export = handleValue & 3;
4201 changestate = handleValue & 0xfff;
4202 smounts = (handleValue >> 2) & 3;
4203 pwsync = (handleValue >> 4) & 3;
4204 convmode = (handleValue >> 6) & 3;
4205 rempags = (handleValue >> 8) & 3;
4206 pagcb = (handleValue >> 10) & 3;
4208 changestate = (handleValue >> 16) & 0x1;
4209 convmode = (handleValue >> 16) & 0x2;
4210 pwsync = (handleValue >> 16) & 0x4;
4211 smounts = (handleValue >> 16) & 0x8;
4212 export = handleValue & 0xff;
4215 /* Failed finding desired exporter; */
4219 handleValue = exporter->exp_states;
4220 if (afs_pd_putInt(aout, handleValue) != 0)
4223 if (!afs_osi_suser(*acred))
4224 return EACCES; /* Only superuser can do this */
4228 exporter->exp_states |= EXP_EXPORTED;
4230 exporter->exp_states &= ~EXP_EXPORTED;
4234 exporter->exp_states |= EXP_UNIXMODE;
4236 exporter->exp_states &= ~EXP_UNIXMODE;
4240 exporter->exp_states |= EXP_PWSYNC;
4242 exporter->exp_states &= ~EXP_PWSYNC;
4246 afs_NFSRootOnly = 0;
4247 exporter->exp_states |= EXP_SUBMOUNTS;
4249 afs_NFSRootOnly = 1;
4250 exporter->exp_states &= ~EXP_SUBMOUNTS;
4255 exporter->exp_states |= EXP_CLIPAGS;
4257 exporter->exp_states &= ~EXP_CLIPAGS;
4261 exporter->exp_states |= EXP_CALLBACK;
4263 exporter->exp_states &= ~EXP_CALLBACK;
4265 handleValue = exporter->exp_states;
4266 if (afs_pd_putInt(aout, handleValue) != 0)
4270 exporter->exp_states |= EXP_EXPORTED;
4272 exporter->exp_states &= ~EXP_EXPORTED;
4274 exporter->exp_states |= EXP_UNIXMODE;
4276 exporter->exp_states &= ~EXP_UNIXMODE;
4278 exporter->exp_states |= EXP_PWSYNC;
4280 exporter->exp_states &= ~EXP_PWSYNC;
4282 afs_NFSRootOnly = 0;
4283 exporter->exp_states |= EXP_SUBMOUNTS;
4285 afs_NFSRootOnly = 1;
4286 exporter->exp_states &= ~EXP_SUBMOUNTS;
4295 * VIOC_GAG (44) - Silence Cache Manager
4299 * \param[in] ain the flags to either gag or de-gag the cache manager
4300 * \param[out] aout not in use
4302 * \retval EACCES Error if the user doesn't have super-user credentials
4304 * \post set the gag flags, then show these flags
4308 struct gaginfo *gagflags;
4310 if (!afs_osi_suser(*acred))
4313 gagflags = afs_pd_inline(ain, sizeof(*gagflags));
4314 if (gagflags == NULL)
4316 afs_showflags = gagflags->showflags;
4322 * VIOC_TWIDDLE (45) - Adjust RX knobs
4326 * \param[in] ain the previous settings of the 'knobs'
4327 * \param[out] aout not in use
4329 * \retval EACCES Error if the user doesn't have super-user credentials
4331 * \post build out the struct rxp, from a struct rx
4333 DECL_PIOCTL(PTwiddleRx)
4335 struct rxparams *rxp;
4337 if (!afs_osi_suser(*acred))
4340 rxp = afs_pd_inline(ain, sizeof(*rxp));
4344 if (rxp->rx_initReceiveWindow)
4345 rx_initReceiveWindow = rxp->rx_initReceiveWindow;
4346 if (rxp->rx_maxReceiveWindow)
4347 rx_maxReceiveWindow = rxp->rx_maxReceiveWindow;
4348 if (rxp->rx_initSendWindow)
4349 rx_initSendWindow = rxp->rx_initSendWindow;
4350 if (rxp->rx_maxSendWindow)
4351 rx_maxSendWindow = rxp->rx_maxSendWindow;
4352 if (rxp->rxi_nSendFrags)
4353 rxi_nSendFrags = rxp->rxi_nSendFrags;
4354 if (rxp->rxi_nRecvFrags)
4355 rxi_nRecvFrags = rxp->rxi_nRecvFrags;
4356 if (rxp->rxi_OrphanFragSize)
4357 rxi_OrphanFragSize = rxp->rxi_OrphanFragSize;
4358 if (rxp->rx_maxReceiveSize) {
4359 rx_maxReceiveSize = rxp->rx_maxReceiveSize;
4360 rx_maxReceiveSizeUser = rxp->rx_maxReceiveSize;
4362 if (rxp->rx_MyMaxSendSize)
4363 rx_MyMaxSendSize = rxp->rx_MyMaxSendSize;
4369 * VIOC_GETINITPARAMS (49) - Get initial cache manager parameters
4373 * \param[in] ain not in use
4374 * \param[out] aout initial cache manager params
4377 * Error if the initial parameters are bigger than some PIGGYSIZE
4379 * \post return the initial cache manager parameters
4381 DECL_PIOCTL(PGetInitParams)
4383 if (sizeof(struct cm_initparams) > PIGGYSIZE)
4386 return afs_pd_putBytes(aout, &cm_initParams,
4387 sizeof(struct cm_initparams));
4390 #ifdef AFS_SGI65_ENV
4391 /* They took crget() from us, so fake it. */
4396 cr = crdup(get_current_cred());
4397 memset(cr, 0, sizeof(cred_t));
4398 #if CELL || CELL_PREPARE
4406 * VIOC_GETRXKCRYPT (55) - Get rxkad encryption flag
4410 * \param[in] ain not in use
4411 * \param[out] aout value of cryptall
4413 * \post Turns on, or disables, rxkad encryption by setting the cryptall global
4415 DECL_PIOCTL(PGetRxkcrypt)
4417 return afs_pd_putInt(aout, cryptall);
4421 * VIOC_SETRXKCRYPT (56) - Set rxkad encryption flag
4425 * \param[in] ain the argument whether or not things should be encrypted
4426 * \param[out] aout not in use
4429 * Error if the user doesn't have super-user credentials
4431 * Error if the input is too big, or if the input is outside the
4432 * bounds of what it can be set to
4434 * \post set whether or not things should be encrypted
4437 * may need to be modified at a later date to take into account
4438 * other values for cryptall (beyond true or false)
4440 DECL_PIOCTL(PSetRxkcrypt)
4444 if (!afs_osi_suser(*acred))
4446 if (afs_pd_getInt(ain, &tmpval) != 0)
4448 /* if new mappings added later this will need to be changed */
4449 if (tmpval != 0 && tmpval != 1)
4455 #ifdef AFS_NEED_CLIENTCONTEXT
4457 * Create new credentials to correspond to a remote user with given
4458 * <hostaddr, uid, g0, g1>. This allows a server running as root to
4459 * provide pioctl (and other) services to foreign clients (i.e. nfs
4460 * clients) by using this call to `become' the client.
4463 #define PIOCTL_HEADER 6
4465 HandleClientContext(struct afs_ioctl *ablob, int *com,
4466 afs_ucred_t **acred, afs_ucred_t *credp)
4469 afs_uint32 hostaddr;
4470 afs_int32 uid, g0, g1, i, code, pag, exporter_type, isroot = 0;
4471 struct afs_exporter *exporter, *outexporter;
4472 afs_ucred_t *newcred;
4473 struct unixuser *au;
4474 afs_uint32 comp = *com & 0xff00;
4476 #if defined(AFS_SUN510_ENV)
4480 #if defined(AFS_SGIMP_ENV)
4481 osi_Assert(ISAFS_GLOCK());
4483 AFS_STATCNT(HandleClientContext);
4484 if (ablob->in_size < PIOCTL_HEADER * sizeof(afs_int32)) {
4485 /* Must at least include the PIOCTL_HEADER header words
4486 * required by the protocol */
4487 return EINVAL; /* Too small to be good */
4489 ain = inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
4490 AFS_COPYIN(ablob->in, ain, PIOCTL_HEADER * sizeof(afs_int32), code);
4492 osi_FreeLargeSpace(inData);
4496 /* Extract information for remote user */
4497 hostaddr = *((afs_uint32 *) ain);
4498 ain += sizeof(hostaddr);
4499 uid = *((afs_uint32 *) ain);
4501 g0 = *((afs_uint32 *) ain);
4503 g1 = *((afs_uint32 *) ain);
4505 *com = *((afs_uint32 *) ain);
4506 ain += sizeof(afs_int32);
4507 exporter_type = *((afs_uint32 *) ain);/* In case we support more than NFS */
4510 * Of course, one must be root for most of these functions, but
4511 * we'll allow (for knfs) you to set things if the pag is 0 and
4512 * you're setting tokens or unlogging.
4515 if (!afs_osi_suser(credp)) {
4516 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
4517 /* Since SGI's suser() returns explicit failure after the call.. */
4520 /* check for acceptable opcodes for normal folks, which are, so far,
4521 * get/set tokens, sysname, and unlog.
4523 if (i != 9 && i != 3 && i != 38 && i != 8) {
4524 osi_FreeLargeSpace(inData);
4529 ablob->in_size -= PIOCTL_HEADER * sizeof(afs_int32);
4530 ablob->in += PIOCTL_HEADER * sizeof(afs_int32);
4531 osi_FreeLargeSpace(inData);
4534 * We map uid 0 to nobody to match the mapping that the nfs
4535 * server does and to ensure that the suser() calls in the afs
4536 * code fails for remote client roots.
4538 uid = afs_nobody; /* NFS_NOBODY == -2 */
4542 #ifdef AFS_AIX41_ENV
4545 afs_set_cr_gid(newcred, isroot ? RMTUSER_REQ_PRIV : RMTUSER_REQ);
4546 #ifdef AFS_AIX51_ENV
4547 newcred->cr_groupset.gs_union.un_groups[0] = g0;
4548 newcred->cr_groupset.gs_union.un_groups[1] = g1;
4549 #elif defined(AFS_LINUX26_ENV)
4550 # ifdef AFS_LINUX26_ONEGROUP_ENV
4551 afs_set_cr_group_info(newcred, groups_alloc(1)); /* nothing sets this */
4552 l = (((g0-0x3f00) & 0x3fff) << 14) | ((g1-0x3f00) & 0x3fff);
4553 h = ((g0-0x3f00) >> 14);
4554 h = ((g1-0x3f00) >> 14) + h + h + h;
4555 GROUP_AT(afs_cr_group_info(newcred), 0) = ((h << 28) | l);
4557 afs_set_cr_group_info(newcred, groups_alloc(2));
4558 GROUP_AT(afs_cr_group_info(newcred), 0) = g0;
4559 GROUP_AT(afs_cr_group_info(newcred), 1) = g1;
4561 #elif defined(AFS_SUN510_ENV)
4564 crsetgroups(newcred, 2, gids);
4566 newcred->cr_groups[0] = g0;
4567 newcred->cr_groups[1] = g1;
4570 newcred->cr_ngrps = 2;
4571 #elif !defined(AFS_LINUX26_ENV) && !defined(AFS_SUN510_ENV)
4572 # if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_FBSD80_ENV)
4573 newcred->cr_ngroups = 2;
4575 for (i = 2; i < NGROUPS; i++)
4576 newcred->cr_groups[i] = NOGROUP;
4579 if (!(exporter = exporter_find(exporter_type))) {
4580 /* Exporter wasn't initialized or an invalid exporter type */
4584 if (exporter->exp_states & EXP_PWSYNC) {
4585 if (uid != afs_cr_uid(credp)) {
4587 return ENOEXEC; /* XXX Find a better errno XXX */
4590 afs_set_cr_uid(newcred, uid); /* Only temporary */
4591 code = EXP_REQHANDLER(exporter, &newcred, hostaddr, &pag, &outexporter);
4592 /* The client's pag is the only unique identifier for it */
4593 afs_set_cr_uid(newcred, pag);
4595 if (!code && *com == PSETPAG) {
4596 /* Special case for 'setpag' */
4597 afs_uint32 pagvalue = genpag();
4599 au = afs_GetUser(pagvalue, -1, WRITE_LOCK); /* a new unixuser struct */
4601 * Note that we leave the 'outexporter' struct held so it won't
4604 au->exporter = outexporter;
4605 if (ablob->out_size >= 4) {
4606 AFS_COPYOUT((char *)&pagvalue, ablob->out, sizeof(afs_int32),
4609 afs_PutUser(au, WRITE_LOCK);
4612 return PSETPAG; /* Special return for setpag */
4614 EXP_RELE(outexporter);
4617 *com = (*com) | comp;
4620 #endif /* AFS_NEED_CLIENTCONTEXT */
4624 * VIOC_GETCPREFS (50) - Get client interface
4628 * \param[in] ain sprefrequest input
4629 * \param[out] aout spref information
4631 * \retval EIO Error if the afs daemon hasn't started yet
4632 * \retval EINVAL Error if some of the standard args aren't set
4635 * get all interface addresses and other information of the client
4638 DECL_PIOCTL(PGetCPrefs)
4640 struct sprefrequest *spin; /* input */
4641 struct sprefinfo *spout; /* output */
4642 struct spref *srvout; /* one output component */
4646 AFS_STATCNT(PGetCPrefs);
4647 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4648 return EIO; /* Inappropriate ioctl for device */
4650 spin = afs_pd_inline(ain, sizeof(*spin));
4654 /* Output spout relies on writing past the end of arrays. It's horrible,
4655 * but I'm not quite brave enough to tackle it yet */
4656 spout = (struct sprefinfo *)aout->ptr;
4658 maxNumber = spin->num_servers; /* max addrs this time */
4659 srvout = spout->servers;
4661 ObtainReadLock(&afs_xinterface);
4663 /* copy out the client interface information from the
4664 * kernel data structure "interface" to the output buffer
4666 for (i = spin->offset, j = 0; (i < afs_cb_interface.numberOfInterfaces)
4667 && (j < maxNumber); i++, j++, srvout++)
4668 srvout->host.s_addr = afs_cb_interface.addr_in[i];
4670 spout->num_servers = j;
4671 aout->ptr += sizeof(struct sprefinfo) + (j - 1) * sizeof(struct spref);
4673 if (i >= afs_cb_interface.numberOfInterfaces)
4674 spout->next_offset = 0; /* start from beginning again */
4676 spout->next_offset = spin->offset + j;
4678 ReleaseReadLock(&afs_xinterface);
4683 * VIOC_SETCPREFS (51) - Set client interface
4687 * \param[in] ain the interfaces you want set
4688 * \param[out] aout not in use
4690 * \retval EIO Error if the afs daemon hasn't started yet
4691 * \retval EINVAL Error if the input is too large for the struct
4692 * \retval ENOMEM Error if there are too many servers
4694 * \post set the callbak interfaces addresses to those of the hosts
4696 DECL_PIOCTL(PSetCPrefs)
4700 struct setspref *sin;
4703 AFS_STATCNT(PSetCPrefs);
4704 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4705 return EIO; /* Inappropriate ioctl for device */
4707 /* Yuck. Input to this function relies on reading past the end of
4708 * structures. Bodge it for now.
4711 ainSize = ain->remaining;
4713 sin = (struct setspref *)ainPtr;
4715 if (ainSize < sizeof(struct setspref))
4717 #if 0 /* num_servers is unsigned */
4718 if (sin->num_servers < 0)
4721 if (sin->num_servers > AFS_MAX_INTERFACE_ADDR)
4724 ObtainWriteLock(&afs_xinterface, 412);
4725 afs_cb_interface.numberOfInterfaces = sin->num_servers;
4726 for (i = 0; (unsigned short)i < sin->num_servers; i++)
4727 afs_cb_interface.addr_in[i] = sin->servers[i].host.s_addr;
4729 ReleaseWriteLock(&afs_xinterface);
4734 * VIOC_AFS_FLUSHMOUNT (52) - Flush mount symlink data
4739 * the last part of a path to a mount point, which tells us what to flush
4744 * Error if some of the initial arguments aren't set
4746 * Error if the initial argument for the mount point isn't a directory
4748 * Error if the dcache entry isn't set
4751 * remove all of the mount data from the dcache regarding a
4752 * certain mount point
4754 DECL_PIOCTL(PFlushMount)
4759 struct VenusFid tfid;
4762 struct sysname_info sysState;
4763 afs_size_t offset, len;
4765 AFS_STATCNT(PFlushMount);
4769 if (afs_pd_getStringPtr(ain, &mount) != 0)
4772 code = afs_VerifyVCache(avc, areq);
4775 if (vType(avc) != VDIR) {
4778 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
4781 Check_AtSys(avc, mount, &sysState, areq);
4782 ObtainReadLock(&tdc->lock);
4784 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
4785 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
4786 ReleaseReadLock(&tdc->lock);
4787 afs_PutDCache(tdc); /* we're done with the data */
4788 bufp = sysState.name;
4792 tfid.Cell = avc->f.fid.Cell;
4793 tfid.Fid.Volume = avc->f.fid.Fid.Volume;
4794 if (!tfid.Fid.Unique && (avc->f.states & CForeign)) {
4795 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
4797 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
4803 if (tvc->mvstat != 1) {
4808 #ifdef AFS_BOZONLOCK_ENV
4809 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
4811 ObtainWriteLock(&tvc->lock, 649);
4812 ObtainWriteLock(&afs_xcbhash, 650);
4813 afs_DequeueCallback(tvc);
4814 tvc->f.states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
4815 ReleaseWriteLock(&afs_xcbhash);
4816 /* now find the disk cache entries */
4817 afs_TryToSmush(tvc, *acred, 1);
4818 osi_dnlc_purgedp(tvc);
4819 if (tvc->linkData && !(tvc->f.states & CCore)) {
4820 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
4821 tvc->linkData = NULL;
4823 ReleaseWriteLock(&tvc->lock);
4824 #ifdef AFS_BOZONLOCK_ENV
4825 afs_BozonUnlock(&tvc->pvnLock, tvc);
4829 if (sysState.allocked)
4830 osi_FreeLargeSpace(bufp);
4835 * VIOC_RXSTAT_PROC (53) - Control process RX statistics
4839 * \param[in] ain the flags that control which stats to use
4840 * \param[out] aout not in use
4842 * \retval EACCES Error if the user doesn't have super-user credentials
4843 * \retval EINVAL Error if the flag input is too long
4846 * either enable process RPCStats, disable process RPCStats,
4847 * or clear the process RPCStats
4849 DECL_PIOCTL(PRxStatProc)
4853 if (!afs_osi_suser(*acred))
4856 if (afs_pd_getInt(ain, &flags) != 0)
4859 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK))
4862 if (flags & AFSCALL_RXSTATS_ENABLE) {
4863 rx_enableProcessRPCStats();
4865 if (flags & AFSCALL_RXSTATS_DISABLE) {
4866 rx_disableProcessRPCStats();
4868 if (flags & AFSCALL_RXSTATS_CLEAR) {
4869 rx_clearProcessRPCStats(AFS_RX_STATS_CLEAR_ALL);
4876 * VIOC_RXSTAT_PEER (54) - Control peer RX statistics
4880 * \param[in] ain the flags that control which statistics to use
4881 * \param[out] aout not in use
4883 * \retval EACCES Error if the user doesn't have super-user credentials
4884 * \retval EINVAL Error if the flag input is too long
4887 * either enable peer RPCStatws, disable peer RPCStats,
4888 * or clear the peer RPCStats
4890 DECL_PIOCTL(PRxStatPeer)
4894 if (!afs_osi_suser(*acred))
4897 if (afs_pd_getInt(ain, &flags) != 0)
4900 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK))
4903 if (flags & AFSCALL_RXSTATS_ENABLE) {
4904 rx_enablePeerRPCStats();
4906 if (flags & AFSCALL_RXSTATS_DISABLE) {
4907 rx_disablePeerRPCStats();
4909 if (flags & AFSCALL_RXSTATS_CLEAR) {
4910 rx_clearPeerRPCStats(AFS_RX_STATS_CLEAR_ALL);
4915 DECL_PIOCTL(PPrefetchFromTape)
4919 struct afs_conn *tc;
4920 struct rx_call *tcall;
4921 struct AFSVolSync tsync;
4922 struct AFSFetchStatus OutStatus;
4923 struct AFSCallBack CallBack;
4924 struct VenusFid tfid;
4927 struct rx_connection *rxconn;
4929 AFS_STATCNT(PPrefetchFromTape);
4933 Fid = afs_pd_inline(ain, sizeof(struct AFSFid));
4935 Fid = &avc->f.fid.Fid;
4937 tfid.Cell = avc->f.fid.Cell;
4938 tfid.Fid.Volume = Fid->Volume;
4939 tfid.Fid.Vnode = Fid->Vnode;
4940 tfid.Fid.Unique = Fid->Unique;
4942 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
4944 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
4945 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &avc->f.fid);
4948 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
4949 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &tvc->f.fid);
4952 tc = afs_Conn(&tvc->f.fid, areq, SHARED_LOCK, &rxconn);
4956 tcall = rx_NewCall(rxconn);
4958 StartRXAFS_FetchData(tcall, (struct AFSFid *)&tvc->f.fid.Fid, 0,
4961 rx_Read(tcall, (char *)&outval, sizeof(afs_int32));
4963 EndRXAFS_FetchData(tcall, &OutStatus, &CallBack, &tsync);
4965 code = rx_EndCall(tcall, code);
4969 } while (afs_Analyze
4970 (tc, rxconn, code, &tvc->f.fid, areq, AFS_STATS_FS_RPCIDX_RESIDENCYRPCS,
4971 SHARED_LOCK, NULL));
4972 /* This call is done only to have the callback things handled correctly */
4973 afs_FetchStatus(tvc, &tfid, areq, &OutStatus);
4979 return afs_pd_putInt(aout, outval);
4985 struct afs_conn *tc;
4987 struct FsCmdInputs *Inputs;
4988 struct FsCmdOutputs *Outputs;
4989 struct VenusFid tfid;
4991 struct rx_connection *rxconn;
4996 Inputs = afs_pd_inline(ain, sizeof(*Inputs));
5000 Outputs = afs_pd_inline(aout, sizeof(*Outputs));
5001 if (Outputs == NULL)
5006 Fid = &avc->f.fid.Fid;
5008 tfid.Cell = avc->f.fid.Cell;
5009 tfid.Fid.Volume = Fid->Volume;
5010 tfid.Fid.Vnode = Fid->Vnode;
5011 tfid.Fid.Unique = Fid->Unique;
5013 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
5014 afs_Trace3(afs_iclSetp, CM_TRACE_RESIDCMD, ICL_TYPE_POINTER, tvc,
5015 ICL_TYPE_INT32, Inputs->command, ICL_TYPE_FID, &tfid);
5019 if (Inputs->command) {
5021 tc = afs_Conn(&tvc->f.fid, areq, SHARED_LOCK, &rxconn);
5025 RXAFS_FsCmd(rxconn, Fid, Inputs,
5026 (struct FsCmdOutputs *)aout);
5030 } while (afs_Analyze
5031 (tc, rxconn, code, &tvc->f.fid, areq,
5032 AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK, NULL));
5033 /* This call is done to have the callback things handled correctly */
5034 afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
5035 } else { /* just a status request, return also link data */
5037 Outputs->code = afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
5038 Outputs->chars[0] = 0;
5039 if (vType(tvc) == VLNK) {
5040 ObtainWriteLock(&tvc->lock, 555);
5041 if (afs_HandleLink(tvc, areq) == 0)
5042 strncpy((char *)&Outputs->chars, tvc->linkData, MAXCMDCHARS);
5043 ReleaseWriteLock(&tvc->lock);
5052 DECL_PIOCTL(PNewUuid)
5054 /*AFS_STATCNT(PNewUuid); */
5055 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
5056 return EIO; /* Inappropriate ioctl for device */
5058 if (!afs_osi_suser(*acred))
5061 ObtainWriteLock(&afs_xinterface, 555);
5062 afs_uuid_create(&afs_cb_interface.uuid);
5063 ReleaseWriteLock(&afs_xinterface);
5064 ForceAllNewConnections();
5068 #if defined(AFS_CACHE_BYPASS) && defined(AFS_LINUX24_ENV)
5070 DECL_PIOCTL(PSetCachingThreshold)
5072 afs_int32 getting = 1;
5073 afs_int32 setting = 1;
5074 afs_int32 threshold = AFS_CACHE_BYPASS_DISABLED;
5076 if (afs_pd_getInt(ain, &threshold) != 0)
5082 if (setting == 0 && getting == 0)
5086 * If setting, set first, and return the value now in effect
5089 if (!afs_osi_suser(*acred))
5091 cache_bypass_threshold = threshold;
5092 afs_warn("Cache Bypass Threshold set to: %d\n", threshold);
5093 /* TODO: move to separate pioctl, or enhance pioctl */
5094 cache_bypass_strategy = LARGE_FILES_BYPASS_CACHE;
5097 /* Return the current size threshold */
5099 return afs_pd_putInt(aout, cache_bypass_threshold);
5104 #endif /* defined(AFS_CACHE_BYPASS) */
5106 DECL_PIOCTL(PCallBackAddr)
5109 afs_uint32 addr, code;
5113 struct afs_conn *tc;
5115 struct unixuser *tu;
5116 struct srvAddr **addrs;
5117 struct rx_connection *rxconn;
5119 /*AFS_STATCNT(PCallBackAddr); */
5120 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
5121 return EIO; /* Inappropriate ioctl for device */
5123 if (!afs_osi_suser(acred))
5126 if (afs_pd_getInt(ain, &addr) != 0)
5129 ObtainReadLock(&afs_xinterface);
5130 for (i = 0; (unsigned short)i < afs_cb_interface.numberOfInterfaces; i++) {
5131 if (afs_cb_interface.addr_in[i] == addr)
5135 ReleaseWriteLock(&afs_xinterface);
5137 if (afs_cb_interface.addr_in[i] != addr)
5140 ObtainReadLock(&afs_xserver); /* Necessary? */
5141 ObtainReadLock(&afs_xsrvAddr);
5144 for (i = 0; i < NSERVERS; i++) {
5145 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
5150 addrs = afs_osi_Alloc(srvAddrCount * sizeof(*addrs));
5151 osi_Assert(addrs != NULL);
5153 for (i = 0; i < NSERVERS; i++) {
5154 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
5155 if (j >= srvAddrCount)
5161 ReleaseReadLock(&afs_xsrvAddr);
5162 ReleaseReadLock(&afs_xserver);
5164 for (i = 0; i < j; i++) {
5170 /* vlserver has no callback conn */
5171 if (sa->sa_portal == AFS_VLPORT) {
5175 if (!ts->cell) /* not really an active server, anyway, it must */
5176 continue; /* have just been added by setsprefs */
5178 /* get a connection, even if host is down; bumps conn ref count */
5179 tu = afs_GetUser(areq->uid, ts->cell->cellNum, SHARED_LOCK);
5180 tc = afs_ConnBySA(sa, ts->cell->fsport, ts->cell->cellNum, tu,
5181 1 /*force */ , 1 /*create */ , SHARED_LOCK, &rxconn);
5182 afs_PutUser(tu, SHARED_LOCK);
5186 if ((sa->sa_flags & SRVADDR_ISDOWN) || afs_HaveCallBacksFrom(ts)) {
5187 if (sa->sa_flags & SRVADDR_ISDOWN) {
5188 rx_SetConnDeadTime(rxconn, 3);
5190 #ifdef RX_ENABLE_LOCKS
5192 #endif /* RX_ENABLE_LOCKS */
5193 code = RXAFS_CallBackRxConnAddr(rxconn, &addr);
5194 #ifdef RX_ENABLE_LOCKS
5196 #endif /* RX_ENABLE_LOCKS */
5198 afs_PutConn(tc, rxconn, SHARED_LOCK); /* done with it now */
5199 } /* Outer loop over addrs */
5200 #endif /* UKERNEL */
5204 DECL_PIOCTL(PDiscon)
5206 static afs_int32 mode = 1; /* Start up in 'off' */
5207 afs_int32 force = 0;
5210 struct vrequest lreq;
5212 if (afs_pd_getBytes(ain, &flags, 4) == 0) {
5213 if (!afs_osi_suser(*acred))
5217 mode = flags[0] - 1;
5219 afs_ConflictPolicy = flags[1] - 1;
5223 /* Fake InitReq support for UID override */
5224 memset(&lreq, 0, sizeof(lreq));
5225 lreq.uid = flags[3];
5226 areq = &lreq; /* override areq we got */
5230 * All of these numbers are hard coded in fs.c. If they
5231 * change here, they should change there and vice versa
5234 case 0: /* Disconnect ("offline" mode), breaking all callbacks */
5235 if (!AFS_IS_DISCONNECTED) {
5236 ObtainWriteLock(&afs_discon_lock, 999);
5237 afs_DisconGiveUpCallbacks();
5238 afs_RemoveAllConns();
5239 afs_is_disconnected = 1;
5240 afs_is_discon_rw = 1;
5241 ReleaseWriteLock(&afs_discon_lock);
5244 case 1: /* Fully connected, ("online" mode). */
5245 ObtainWriteLock(&afs_discon_lock, 998);
5248 afs_MarkAllServersUp();
5249 code = afs_ResyncDisconFiles(areq, *acred);
5252 if (code && !force) {
5253 afs_warnuser("Files not synchronized properly, still in discon state. \n"
5254 "Please retry or use \"force\".\n");
5258 afs_DisconDiscardAll(*acred);
5260 afs_ClearAllStatdFlag();
5261 afs_is_disconnected = 0;
5262 afs_is_discon_rw = 0;
5263 afs_warnuser("\nSync succeeded. You are back online.\n");
5266 ReleaseWriteLock(&afs_discon_lock);
5278 return afs_pd_putInt(aout, mode);
5281 #define MAX_PIOCTL_TOKENS 10
5283 DECL_PIOCTL(PSetTokens2)
5286 int i, cellNum, primaryFlag;
5288 struct unixuser *tu;
5289 struct vrequest treq;
5290 struct ktc_setTokenData tokenSet;
5291 struct ktc_tokenUnion decodedToken;
5293 memset(&tokenSet, 0, sizeof(tokenSet));
5295 AFS_STATCNT(PSetTokens2);
5296 if (!afs_resourceinit_flag)
5299 afs_pd_xdrStart(ain, &xdrs, XDR_DECODE);
5301 if (!xdr_ktc_setTokenData(&xdrs, &tokenSet)) {
5302 afs_pd_xdrEnd(ain, &xdrs);
5306 afs_pd_xdrEnd(ain, &xdrs);
5308 /* We limit each PAG to 10 tokens to prevent a malicous (or runaway)
5309 * process from using up the whole of the kernel memory by allocating
5312 if (tokenSet.tokens.tokens_len > MAX_PIOCTL_TOKENS) {
5313 xdr_free((xdrproc_t) xdr_ktc_setTokenData, &tokenSet);
5317 code = _settok_tokenCell(tokenSet.cell, &cellNum, &primaryFlag);
5319 xdr_free((xdrproc_t) xdr_ktc_setTokenData, &tokenSet);
5323 if (tokenSet.flags & AFSTOKEN_EX_SETPAG) {
5324 if (_settok_setParentPag(acred) == 0) {
5325 afs_InitReq(&treq, *acred);
5330 tu = afs_GetUser(areq->uid, cellNum, WRITE_LOCK);
5331 /* Free any tokens that we've already got */
5332 afs_FreeTokens(&tu->tokens);
5334 /* Iterate across the set of tokens we've received, and stuff them
5335 * into this user's tokenJar
5337 for (i=0; i < tokenSet.tokens.tokens_len; i++) {
5338 xdrmem_create(&xdrs,
5339 tokenSet.tokens.tokens_val[i].token_opaque_val,
5340 tokenSet.tokens.tokens_val[i].token_opaque_len,
5343 memset(&decodedToken, 0, sizeof(decodedToken));
5344 if (!xdr_ktc_tokenUnion(&xdrs, &decodedToken)) {
5352 afs_AddTokenFromPioctl(&tu->tokens, &decodedToken);
5353 /* This is untidy - the old token interface supported passing
5354 * the primaryFlag as part of the token interface. Current
5355 * OpenAFS userland never sets this, but it's specified as being
5356 * part of the XG interface, so we should probably still support
5357 * it. Rather than add it to our AddToken interface, just handle
5360 if (decodedToken.at_type == AFSTOKEN_UNION_KAD) {
5361 if (decodedToken.ktc_tokenUnion_u.at_kad.rk_primary_flag)
5365 /* XXX - We should think more about destruction here. It's likely that
5366 * there is key material in what we're about to throw away, which
5367 * we really should zero out before giving back to the allocator */
5368 xdr_free((xdrproc_t) xdr_ktc_tokenUnion, &decodedToken);
5371 tu->states |= UHasTokens;
5372 tu->states &= ~UTokensBad;
5373 afs_SetPrimary(tu, primaryFlag);
5374 tu->tokenTime = osi_Time();
5376 xdr_free((xdrproc_t) xdr_ktc_setTokenData, &tokenSet);
5379 afs_ResetUserConns(tu);
5380 afs_PutUser(tu, WRITE_LOCK);
5385 DECL_PIOCTL(PGetTokens2)
5387 struct cell *cell = NULL;
5388 struct unixuser *tu = NULL;
5390 char *cellName = NULL;
5395 struct ktc_setTokenData tokenSet;
5397 AFS_STATCNT(PGetTokens);
5398 if (!afs_resourceinit_flag)
5401 memset(&tokenSet, 0, sizeof(tokenSet));
5403 /* No input data - return tokens for primary cell */
5404 /* 4 octets of data is an iterator count */
5405 /* Otherwise, treat as string & return tokens for that cell name */
5407 if (afs_pd_remaining(ain) == sizeof(afs_int32)) {
5408 /* Integer iterator - return tokens for the n'th cell found for user */
5409 if (afs_pd_getInt(ain, &iterator) != 0)
5411 tu = getNthCell(areq->uid, iterator);
5413 if (afs_pd_remaining(ain) > 0) {
5414 if (afs_pd_getStringPtr(ain, &cellName) != 0)
5419 code = _settok_tokenCell(cellName, &cellNum, NULL);
5422 tu = afs_FindUser(areq->uid, cellNum, READ_LOCK);
5429 if (!(tu->states & UHasTokens)
5430 || !afs_HasValidTokens(tu->tokens, now)) {
5431 tu->states |= (UTokensBad | UNeedsReset);
5432 afs_PutUser(tu, READ_LOCK);
5436 code = afs_ExtractTokensForPioctl(tu->tokens, now, &tokenSet);
5440 cell = afs_GetCell(tu->cell, READ_LOCK);
5441 tokenSet.cell = cell->cellName;
5442 afs_pd_xdrStart(aout, &xdrs, XDR_ENCODE);
5443 if (!xdr_ktc_setTokenData(&xdrs, &tokenSet)) {
5447 afs_pd_xdrEnd(aout, &xdrs);
5450 tokenSet.cell = NULL;
5453 afs_PutUser(tu, READ_LOCK);
5455 afs_PutCell(cell, READ_LOCK);
5456 xdr_free((xdrproc_t)xdr_ktc_setTokenData, &tokenSet);
5461 DECL_PIOCTL(PNFSNukeCreds)
5465 struct unixuser *tu;
5467 AFS_STATCNT(PUnlog);
5468 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
5469 return EIO; /* Inappropriate ioctl for device */
5471 if (afs_pd_getUint(ain, &addr) != 0)
5474 if (afs_cr_gid(*acred) == RMTUSER_REQ_PRIV && !addr) {
5475 tu = afs_GetUser(areq->uid, -1, SHARED_LOCK);
5476 if (!tu->exporter || !(addr = EXP_GETHOST(tu->exporter))) {
5477 afs_PutUser(tu, SHARED_LOCK);
5480 afs_PutUser(tu, SHARED_LOCK);
5481 } else if (!afs_osi_suser(acred)) {
5485 ObtainWriteLock(&afs_xuser, 227);
5486 for (i = 0; i < NUSERS; i++) {
5487 for (tu = afs_users[i]; tu; tu = tu->next) {
5488 if (tu->exporter && EXP_CHECKHOST(tu->exporter, addr)) {
5490 ReleaseWriteLock(&afs_xuser);
5492 afs_LockUser(tu, WRITE_LOCK, 367);
5494 tu->states &= ~UHasTokens;
5495 afs_FreeTokens(&tu->tokens);
5496 afs_ResetUserConns(tu);
5497 afs_PutUser(tu, WRITE_LOCK);
5498 ObtainWriteLock(&afs_xuser, 228);
5500 /* set the expire times to 0, causes
5501 * afs_GCUserData to remove this entry
5504 #endif /* UKERNEL */
5508 ReleaseWriteLock(&afs_xuser);