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);