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);
670 # if defined(AFS_SUN57_ENV)
674 # elif defined(AFS_SUN54_ENV)
679 if (code = getf(uap->fd, &fd)) {
683 if (fd->f_vnode->v_type == VREG || fd->f_vnode->v_type == VDIR) {
684 tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */
685 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
686 /* This is an AFS vnode */
687 if (((uap->com >> 8) & 0xff) == 'V') {
688 struct afs_ioctl *datap;
691 (struct afs_ioctl *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
692 code=copyin_afs_ioctl((char *)uap->arg, datap);
694 osi_FreeSmallSpace(datap);
696 # if defined(AFS_SUN54_ENV)
703 code = HandleIoctl(tvc, uap->com, datap);
704 osi_FreeSmallSpace(datap);
710 # if defined(AFS_SUN57_ENV)
712 # elif defined(AFS_SUN54_ENV)
718 code = ioctl(uap, rvp);
722 #elif defined(AFS_LINUX22_ENV)
723 struct afs_ioctl_sys {
728 afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
731 struct afs_ioctl_sys ua, *uap = &ua;
733 int ioctlDone = 0, code = 0;
735 AFS_STATCNT(afs_xioctl);
740 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
741 /* This is an AFS vnode */
742 if (((uap->com >> 8) & 0xff) == 'V') {
743 struct afs_ioctl *datap;
745 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
746 code = copyin_afs_ioctl((char *)uap->arg, datap);
748 osi_FreeSmallSpace(datap);
752 code = HandleIoctl(tvc, uap->com, datap);
753 osi_FreeSmallSpace(datap);
762 #elif defined(AFS_DARWIN_ENV) && !defined(AFS_DARWIN80_ENV)
770 afs_xioctl(afs_proc_t *p, struct ioctl_args *uap, register_t *retval)
774 int ioctlDone = 0, code = 0;
776 AFS_STATCNT(afs_xioctl);
777 if ((code = fdgetf(p, uap->fd, &fd)))
779 if (fd->f_type == DTYPE_VNODE) {
780 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
781 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
782 /* This is an AFS vnode */
783 if (((uap->com >> 8) & 0xff) == 'V') {
784 struct afs_ioctl *datap;
786 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
787 code = copyin_afs_ioctl((char *)uap->arg, datap);
789 osi_FreeSmallSpace(datap);
793 code = HandleIoctl(tvc, uap->com, datap);
794 osi_FreeSmallSpace(datap);
802 return ioctl(p, uap, retval);
806 #elif defined(AFS_XBSD_ENV)
807 # if defined(AFS_FBSD_ENV)
810 afs_xioctl(struct thread *td, struct ioctl_args *uap,
813 afs_proc_t *p = td->td_proc;
822 afs_xioctl(afs_proc_t *p, struct ioctl_args *uap, register_t *retval)
825 struct filedesc *fdp;
827 int ioctlDone = 0, code = 0;
830 AFS_STATCNT(afs_xioctl);
831 # if defined(AFS_NBSD40_ENV)
832 fdp = p->l_proc->p_fd;
836 if ((u_int) uap->fd >= fdp->fd_nfiles
837 || (fd = fdp->fd_ofiles[uap->fd]) == NULL)
839 if ((fd->f_flag & (FREAD | FWRITE)) == 0)
841 /* first determine whether this is any sort of vnode */
842 if (fd->f_type == DTYPE_VNODE) {
843 /* good, this is a vnode; next see if it is an AFS vnode */
844 # if defined(AFS_OBSD_ENV)
846 IsAfsVnode((struct vnode *)fd->
847 f_data) ? VTOAFS((struct vnode *)fd->f_data) : NULL;
849 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
851 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
852 /* This is an AFS vnode */
853 if (((uap->com >> 8) & 0xff) == 'V') {
854 struct afs_ioctl *datap;
856 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
857 code = copyin_afs_ioctl((char *)uap->arg, datap);
859 osi_FreeSmallSpace(datap);
863 code = HandleIoctl(tvc, uap->com, datap);
864 osi_FreeSmallSpace(datap);
872 # if defined(AFS_FBSD_ENV)
873 return ioctl(td, uap);
874 # elif defined(AFS_OBSD_ENV)
875 code = sys_ioctl(p, uap, retval);
876 # elif defined(AFS_NBSD_ENV)
877 struct lwp *l = osi_curproc();
878 code = sys_ioctl(l, uap, retval);
884 #elif defined(UKERNEL)
892 } *uap = (struct a *)get_user_struct()->u_ap;
895 int ioctlDone = 0, code = 0;
897 AFS_STATCNT(afs_xioctl);
902 /* first determine whether this is any sort of vnode */
903 if (fd->f_type == DTYPE_VNODE) {
904 /* good, this is a vnode; next see if it is an AFS vnode */
905 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
906 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
907 /* This is an AFS vnode */
908 if (((uap->com >> 8) & 0xff) == 'V') {
909 struct afs_ioctl *datap;
911 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
912 code=copyin_afs_ioctl((char *)uap->arg, datap);
914 osi_FreeSmallSpace(datap);
917 return (setuerror(code), code);
919 code = HandleIoctl(tvc, uap->com, datap);
920 osi_FreeSmallSpace(datap);
933 #endif /* AFS_HPUX102_ENV */
935 #if defined(AFS_SGI_ENV)
936 /* "pioctl" system call entry point; just pass argument to the parameterized
945 afs_pioctl(struct pioctlargs *uap, rval_t * rvp)
949 AFS_STATCNT(afs_pioctl);
951 code = afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow);
953 # ifdef AFS_SGI64_ENV
960 #elif defined(AFS_FBSD_ENV)
962 afs_pioctl(struct thread *td, void *args, int *retval)
969 } *uap = (struct a *)args;
971 AFS_STATCNT(afs_pioctl);
972 return (afs_syscall_pioctl
973 (uap->path, uap->cmd, uap->cmarg, uap->follow, td->td_ucred));
976 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
978 afs_pioctl(afs_proc_t *p, void *args, int *retval)
985 } *uap = (struct a *)args;
987 AFS_STATCNT(afs_pioctl);
988 # if defined(AFS_DARWIN80_ENV) || defined(AFS_NBSD40_ENV)
989 return (afs_syscall_pioctl
990 (uap->path, uap->cmd, uap->cmarg, uap->follow,
993 return (afs_syscall_pioctl
994 (uap->path, uap->cmd, uap->cmarg, uap->follow,
995 # if defined(AFS_FBSD_ENV)
998 p->p_cred->pc_ucred));
1005 /* macro to avoid adding any more #ifdef's to pioctl code. */
1006 #if defined(AFS_LINUX22_ENV) || defined(AFS_AIX41_ENV)
1007 #define PIOCTL_FREE_CRED() crfree(credp)
1009 #define PIOCTL_FREE_CRED()
1014 afs_syscall_pioctl(char *path, unsigned int com, caddr_t cmarg, int follow,
1015 rval_t *vvp, afs_ucred_t *credp)
1017 #ifdef AFS_DARWIN100_ENV
1018 afs_syscall64_pioctl(user_addr_t path, unsigned int com, user_addr_t cmarg,
1019 int follow, afs_ucred_t *credp)
1020 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1021 afs_syscall_pioctl(char *path, unsigned int com, caddr_t cmarg, int follow,
1024 afs_syscall_pioctl(char *path, unsigned int com, caddr_t cmarg, int follow)
1028 struct afs_ioctl data;
1029 #ifdef AFS_NEED_CLIENTCONTEXT
1030 afs_ucred_t *tmpcred = NULL;
1032 #if defined(AFS_NEED_CLIENTCONTEXT) || defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1033 afs_ucred_t *foreigncreds = NULL;
1036 struct vnode *vp = NULL;
1037 #ifdef AFS_AIX41_ENV
1038 struct ucred *credp = crref(); /* don't free until done! */
1040 #ifdef AFS_LINUX22_ENV
1041 cred_t *credp = crref(); /* don't free until done! */
1045 AFS_STATCNT(afs_syscall_pioctl);
1047 follow = 1; /* compat. with old venus */
1048 code = copyin_afs_ioctl(cmarg, &data);
1051 #if defined(KERNEL_HAVE_UERROR)
1056 if ((com & 0xff) == PSetClientContext) {
1057 #ifdef AFS_NEED_CLIENTCONTEXT
1058 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV)
1059 code = HandleClientContext(&data, &com, &foreigncreds, credp);
1061 code = HandleClientContext(&data, &com, &foreigncreds, osi_curcred());
1065 crfree(foreigncreds);
1068 #if defined(KERNEL_HAVE_UERROR)
1069 return (setuerror(code), code);
1074 #else /* AFS_NEED_CLIENTCONTEXT */
1076 #endif /* AFS_NEED_CLIENTCONTEXT */
1078 #ifdef AFS_NEED_CLIENTCONTEXT
1081 * We could have done without temporary setting the u.u_cred below
1082 * (foreigncreds could be passed as param the pioctl modules)
1083 * but calls such as afs_osi_suser() doesn't allow that since it
1084 * references u.u_cred directly. We could, of course, do something
1085 * like afs_osi_suser(cred) which, I think, is better since it
1086 * generalizes and supports multi cred environments...
1088 #if defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
1090 credp = foreigncreds;
1091 #elif defined(AFS_AIX41_ENV)
1092 tmpcred = crref(); /* XXX */
1093 crset(foreigncreds);
1094 #elif defined(AFS_HPUX101_ENV)
1095 tmpcred = p_cred(u.u_procp);
1096 set_p_cred(u.u_procp, foreigncreds);
1097 #elif defined(AFS_SGI_ENV)
1098 tmpcred = OSI_GET_CURRENT_CRED();
1099 OSI_SET_CURRENT_CRED(foreigncreds);
1102 u.u_cred = foreigncreds;
1105 #endif /* AFS_NEED_CLIENTCONTEXT */
1106 if ((com & 0xff) == 15) {
1107 /* special case prefetch so entire pathname eval occurs in helper process.
1108 * otherwise, the pioctl call is essentially useless */
1109 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1111 Prefetch(path, &data, follow,
1112 foreigncreds ? foreigncreds : credp);
1114 code = Prefetch(path, &data, follow, osi_curcred());
1117 #if defined(KERNEL_HAVE_UERROR)
1124 #ifdef AFS_AIX41_ENV
1126 lookupname(path, USR, follow, NULL, &vp,
1127 foreigncreds ? foreigncreds : credp);
1129 #ifdef AFS_LINUX22_ENV
1130 code = gop_lookupname_user(path, AFS_UIOUSER, follow, &dp);
1132 vp = (struct vnode *)dp->d_inode;
1134 code = gop_lookupname_user(path, AFS_UIOUSER, follow, &vp);
1135 #if defined(AFS_FBSD80_ENV) /* XXX check on 7x */
1138 #endif /* AFS_FBSD80_ENV */
1139 #endif /* AFS_LINUX22_ENV */
1140 #endif /* AFS_AIX41_ENV */
1144 #if defined(KERNEL_HAVE_UERROR)
1152 #if defined(AFS_SUN510_ENV)
1153 if (vp && !IsAfsVnode(vp)) {
1154 struct vnode *realvp;
1156 #ifdef AFS_SUN511_ENV
1157 (VOP_REALVP(vp, &realvp, NULL) == 0)
1159 (VOP_REALVP(vp, &realvp) == 0)
1162 struct vnode *oldvp = vp;
1170 /* now make the call if we were passed no file, or were passed an AFS file */
1171 if (!vp || IsAfsVnode(vp)) {
1172 #if defined(AFS_SUN5_ENV)
1173 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1174 #elif defined(AFS_AIX41_ENV)
1176 struct ucred *cred1, *cred2;
1179 cred1 = cred2 = foreigncreds;
1181 cred1 = cred2 = credp;
1183 code = afs_HandlePioctl(vp, com, &data, follow, &cred1);
1184 if (cred1 != cred2) {
1185 /* something changed the creds */
1189 #elif defined(AFS_HPUX101_ENV)
1191 struct ucred *cred = p_cred(u.u_procp);
1192 code = afs_HandlePioctl(vp, com, &data, follow, &cred);
1194 #elif defined(AFS_SGI_ENV)
1197 credp = OSI_GET_CURRENT_CRED();
1198 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1200 #elif defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1201 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1202 #elif defined(UKERNEL)
1203 code = afs_HandlePioctl(vp, com, &data, follow,
1204 &(get_user_struct()->u_cred));
1206 code = afs_HandlePioctl(vp, com, &data, follow, &u.u_cred);
1209 #if defined(KERNEL_HAVE_UERROR)
1212 code = EINVAL; /* not in /afs */
1217 #if defined(AFS_NEED_CLIENTCONTEXT)
1219 #ifdef AFS_AIX41_ENV
1220 crset(tmpcred); /* restore original credentials */
1222 #if defined(AFS_HPUX101_ENV)
1223 set_p_cred(u.u_procp, tmpcred); /* restore original credentials */
1224 #elif defined(AFS_SGI_ENV)
1225 OSI_SET_CURRENT_CRED(tmpcred); /* restore original credentials */
1226 #elif defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
1227 credp = tmpcred; /* restore original credentials */
1229 osi_curcred() = tmpcred; /* restore original credentials */
1230 #endif /* AFS_HPUX101_ENV */
1231 crfree(foreigncreds);
1234 #endif /* AFS_NEED_CLIENTCONTEXT */
1236 #ifdef AFS_LINUX22_ENV
1239 #if defined(AFS_FBSD80_ENV)
1240 if (VOP_ISLOCKED(vp))
1242 #endif /* AFS_FBSD80_ENV */
1243 AFS_RELE(vp); /* put vnode back */
1247 #if defined(KERNEL_HAVE_UERROR)
1250 return (getuerror());
1256 #ifdef AFS_DARWIN100_ENV
1258 afs_syscall_pioctl(char * path, unsigned int com, caddr_t cmarg,
1259 int follow, afs_ucred_t *credp)
1261 return afs_syscall64_pioctl(CAST_USER_ADDR_T(path), com,
1262 CAST_USER_ADDR_T((unsigned int)cmarg), follow,
1267 #define MAXPIOCTLTOKENLEN \
1268 (3*sizeof(afs_int32)+MAXKTCTICKETLEN+sizeof(struct ClearToken)+MAXKTCREALMLEN)
1271 afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
1272 struct afs_ioctl *ablob, int afollow,
1273 afs_ucred_t **acred)
1276 struct vrequest treq;
1278 afs_int32 function, device;
1279 struct afs_pdata input, output;
1280 struct afs_pdata copyInput, copyOutput;
1282 pioctlFunction *pioctlSw;
1284 struct afs_fakestat_state fakestate;
1286 memset(&input, 0, sizeof(input));
1287 memset(&output, 0, sizeof(output));
1289 avc = avp ? VTOAFS(avp) : NULL;
1290 afs_Trace3(afs_iclSetp, CM_TRACE_PIOCTL, ICL_TYPE_INT32, acom & 0xff,
1291 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, afollow);
1292 AFS_STATCNT(HandlePioctl);
1294 code = afs_InitReq(&treq, *acred);
1298 afs_InitFakeStat(&fakestate);
1300 code = afs_EvalFakeStat(&avc, &fakestate, &treq);
1304 device = (acom & 0xff00) >> 8;
1306 case 'V': /* Original pioctls */
1307 pioctlSw = VpioctlSw;
1308 pioctlSwSize = sizeof(VpioctlSw);
1310 case 'C': /* Coordinated/common pioctls */
1311 pioctlSw = CpioctlSw;
1312 pioctlSwSize = sizeof(CpioctlSw);
1314 case 'O': /* Coordinated/common pioctls */
1315 pioctlSw = OpioctlSw;
1316 pioctlSwSize = sizeof(OpioctlSw);
1322 function = acom & 0xff;
1323 if (function >= (pioctlSwSize / sizeof(char *))) {
1328 /* Do all range checking before continuing */
1329 if (ablob->in_size > MAXPIOCTLTOKENLEN ||
1330 ablob->in_size < 0 || ablob->out_size < 0) {
1335 code = afs_pd_alloc(&input, ablob->in_size);
1339 if (ablob->in_size > 0) {
1340 AFS_COPYIN(ablob->in, input.ptr, ablob->in_size, code);
1341 input.ptr[input.remaining] = '\0';
1346 if ((function == 8 && device == 'V') ||
1347 (function == 7 && device == 'C')) { /* PGetTokens */
1348 code = afs_pd_alloc(&output, MAXPIOCTLTOKENLEN);
1350 code = afs_pd_alloc(&output, AFS_LRALLOCSIZ);
1356 copyOutput = output;
1359 (*pioctlSw[function]) (avc, function, &treq, ©Input,
1360 ©Output, acred);
1362 outSize = copyOutput.ptr - output.ptr;
1364 if (code == 0 && ablob->out_size > 0) {
1365 if (outSize > ablob->out_size) {
1366 code = E2BIG; /* data wont fit in user buffer */
1367 } else if (outSize) {
1368 AFS_COPYOUT(output.ptr, ablob->out, outSize, code);
1373 afs_pd_free(&input);
1374 afs_pd_free(&output);
1376 afs_PutFakeStat(&fakestate);
1377 return afs_CheckCode(code, &treq, 41);
1381 * VIOCGETFID (22) - Get file ID quickly
1385 * \param[in] ain not in use
1386 * \param[out] aout fid of requested file
1388 * \retval EINVAL Error if some of the initial arguments aren't set
1390 * \post get the file id of some file
1392 DECL_PIOCTL(PGetFID)
1394 AFS_STATCNT(PGetFID);
1397 if (afs_pd_putBytes(aout, &avc->f.fid, sizeof(struct VenusFid)) != 0)
1403 * VIOCSETAL (1) - Set access control list
1407 * \param[in] ain the ACL being set
1408 * \param[out] aout the ACL being set returned
1410 * \retval EINVAL Error if some of the standard args aren't set
1412 * \post Changed ACL, via direct writing to the wire
1415 dummy_PSetAcl(char *ain, char *aout)
1420 DECL_PIOCTL(PSetAcl)
1423 struct afs_conn *tconn;
1424 struct AFSOpaque acl;
1425 struct AFSVolSync tsync;
1426 struct AFSFetchStatus OutStatus;
1429 AFS_STATCNT(PSetAcl);
1433 if (afs_pd_getStringPtr(ain, &acl.AFSOpaque_val) != 0)
1435 acl.AFSOpaque_len = strlen(acl.AFSOpaque_val) + 1;
1436 if (acl.AFSOpaque_len > 1024)
1440 tconn = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
1442 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREACL);
1445 RXAFS_StoreACL(tconn->id, (struct AFSFid *)&avc->f.fid.Fid,
1446 &acl, &OutStatus, &tsync);
1451 } while (afs_Analyze
1452 (tconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_STOREACL,
1453 SHARED_LOCK, NULL));
1455 /* now we've forgotten all of the access info */
1456 ObtainWriteLock(&afs_xcbhash, 455);
1458 afs_DequeueCallback(avc);
1459 avc->f.states &= ~(CStatd | CUnique);
1460 ReleaseWriteLock(&afs_xcbhash);
1461 if (avc->f.fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
1462 osi_dnlc_purgedp(avc);
1464 /* SXW - Should we flush metadata here? */
1468 int afs_defaultAsynchrony = 0;
1471 * VIOC_STOREBEHIND (47) Adjust store asynchrony
1475 * \param[in] ain sbstruct (store behind structure) input
1476 * \param[out] aout resulting sbstruct
1479 * Error if the user doesn't have super-user credentials
1481 * Error if there isn't enough access to not check the mode bits
1484 * Changes either the default asynchrony (the amount of data that
1485 * can remain to be written when the cache manager returns control
1486 * to the user), or the asyncrony for the specified file.
1488 DECL_PIOCTL(PStoreBehind)
1490 struct sbstruct sbr;
1492 if (afs_pd_getBytes(ain, &sbr, sizeof(struct sbstruct)) != 0)
1495 if (sbr.sb_default != -1) {
1496 if (afs_osi_suser(*acred))
1497 afs_defaultAsynchrony = sbr.sb_default;
1502 if (avc && (sbr.sb_thisfile != -1)) {
1504 (avc, PRSFS_WRITE | PRSFS_ADMINISTER, areq, DONT_CHECK_MODE_BITS))
1505 avc->asynchrony = sbr.sb_thisfile;
1510 memset(&sbr, 0, sizeof(sbr));
1511 sbr.sb_default = afs_defaultAsynchrony;
1513 sbr.sb_thisfile = avc->asynchrony;
1516 return afs_pd_putBytes(aout, &sbr, sizeof(sbr));
1520 * VIOC_GCPAGS (48) - Disable automatic PAG gc'ing
1524 * \param[in] ain not in use
1525 * \param[out] aout not in use
1527 * \retval EACCES Error if the user doesn't have super-user credentials
1529 * \post set the gcpags to GCPAGS_USERDISABLED
1531 DECL_PIOCTL(PGCPAGs)
1533 if (!afs_osi_suser(*acred)) {
1536 afs_gcpags = AFS_GCPAGS_USERDISABLED;
1541 * VIOCGETAL (2) - Get access control list
1545 * \param[in] ain not in use
1546 * \param[out] aout the ACL
1548 * \retval EINVAL Error if some of the standard args aren't set
1549 * \retval ERANGE Error if the vnode of the file id is too large
1550 * \retval -1 Error if getting the ACL failed
1552 * \post Obtain the ACL, based on file ID
1555 * There is a hack to tell which type of ACL is being returned, checks
1556 * the top 2-bytes of the input size to judge what type of ACL it is,
1557 * only for dfs xlator ACLs
1559 DECL_PIOCTL(PGetAcl)
1561 struct AFSOpaque acl;
1562 struct AFSVolSync tsync;
1563 struct AFSFetchStatus OutStatus;
1565 struct afs_conn *tconn;
1569 AFS_STATCNT(PGetAcl);
1572 Fid.Volume = avc->f.fid.Fid.Volume;
1573 Fid.Vnode = avc->f.fid.Fid.Vnode;
1574 Fid.Unique = avc->f.fid.Fid.Unique;
1575 if (avc->f.states & CForeign) {
1577 * For a dfs xlator acl we have a special hack so that the
1578 * xlator will distinguish which type of acl will return. So
1579 * we currently use the top 2-bytes (vals 0-4) to tell which
1580 * type of acl to bring back. Horrible hack but this will
1581 * cause the least number of changes to code size and interfaces.
1583 if (Fid.Vnode & 0xc0000000)
1585 Fid.Vnode |= (ain->remaining << 30);
1587 acl.AFSOpaque_val = aout->ptr;
1589 tconn = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
1591 acl.AFSOpaque_val[0] = '\0';
1592 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHACL);
1594 code = RXAFS_FetchACL(tconn->id, &Fid, &acl, &OutStatus, &tsync);
1599 } while (afs_Analyze
1600 (tconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_FETCHACL,
1601 SHARED_LOCK, NULL));
1604 if (acl.AFSOpaque_len == 0)
1605 afs_pd_skip(aout, 1); /* leave the NULL */
1607 afs_pd_skip(aout, acl.AFSOpaque_len); /* Length of the ACL */
1613 * PNoop returns success. Used for functions which are not implemented
1614 * or are no longer in use.
1618 * \retval Always returns success
1621 * Functions involved in this:
1622 * 17 (VIOCENGROUP) -- used to be enable group;
1623 * 18 (VIOCDISGROUP) -- used to be disable group;
1624 * 2 (?) -- get/set cache-bypass size threshold
1633 * PBogus returns fail. Used for functions which are not implemented or
1634 * are no longer in use.
1638 * \retval EINVAL Always returns this value
1641 * Functions involved in this:
1647 * 13 (VIOCGETTIME) -- used to be quick check time;
1648 * 15 (VIOCPREFETCH) -- prefetch is now special-cased; see pioctl code!;
1649 * 16 (VIOCNOP) -- used to be testing code;
1650 * 19 (VIOCLISTGROUPS) -- used to be list group;
1651 * 23 (VIOCWAITFOREVER) -- used to be waitforever;
1652 * 57 (VIOC_FPRIOSTATUS) -- arla: set file prio;
1653 * 58 (VIOC_FHGET) -- arla: fallback getfh;
1654 * 59 (VIOC_FHOPEN) -- arla: fallback fhopen;
1655 * 60 (VIOC_XFSDEBUG) -- arla: controls xfsdebug;
1656 * 61 (VIOC_ARLADEBUG) -- arla: controls arla debug;
1657 * 62 (VIOC_AVIATOR) -- arla: debug interface;
1658 * 63 (VIOC_XFSDEBUG_PRINT) -- arla: print xfs status;
1659 * 64 (VIOC_CALCULATE_CACHE) -- arla: force cache check;
1660 * 65 (VIOC_BREAKCELLBACK) -- arla: break callback;
1661 * 68 (?) -- arla: fetch stats;
1665 AFS_STATCNT(PBogus);
1670 * VIOC_FILE_CELL_NAME (30) - Get cell in which file lives
1674 * \param[in] ain not in use (avc used to pass in file id)
1675 * \param[out] aout cell name
1677 * \retval EINVAL Error if some of the standard args aren't set
1678 * \retval ESRCH Error if the file isn't part of a cell
1680 * \post Get a cell based on a passed in file id
1682 DECL_PIOCTL(PGetFileCell)
1686 AFS_STATCNT(PGetFileCell);
1689 tcell = afs_GetCell(avc->f.fid.Cell, READ_LOCK);
1693 if (afs_pd_putString(aout, tcell->cellName) != 0)
1696 afs_PutCell(tcell, READ_LOCK);
1701 * VIOC_GET_WS_CELL (31) - Get cell in which workstation lives
1705 * \param[in] ain not in use
1706 * \param[out] aout cell name
1709 * Error if the afs daemon hasn't started yet
1711 * Error if the machine isn't part of a cell, for whatever reason
1713 * \post Get the primary cell that the machine is a part of.
1715 DECL_PIOCTL(PGetWSCell)
1717 struct cell *tcell = NULL;
1719 AFS_STATCNT(PGetWSCell);
1720 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1721 return EIO; /* Inappropriate ioctl for device */
1723 tcell = afs_GetPrimaryCell(READ_LOCK);
1724 if (!tcell) /* no primary cell? */
1727 if (afs_pd_putString(aout, tcell->cellName) != 0)
1729 afs_PutCell(tcell, READ_LOCK);
1734 * VIOC_GET_PRIMARY_CELL (33) - Get primary cell for caller
1738 * \param[in] ain not in use (user id found via areq)
1739 * \param[out] aout cell name
1742 * Error if the user id doesn't have a primary cell specified
1744 * \post Get the primary cell for a certain user, based on the user's uid
1746 DECL_PIOCTL(PGetUserCell)
1749 struct unixuser *tu;
1752 AFS_STATCNT(PGetUserCell);
1753 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1754 return EIO; /* Inappropriate ioctl for device */
1756 /* return the cell name of the primary cell for this user */
1757 i = UHash(areq->uid);
1758 ObtainWriteLock(&afs_xuser, 224);
1759 for (tu = afs_users[i]; tu; tu = tu->next) {
1760 if (tu->uid == areq->uid && (tu->states & UPrimary)) {
1762 ReleaseWriteLock(&afs_xuser);
1767 tcell = afs_GetCell(tu->cell, READ_LOCK);
1768 afs_PutUser(tu, WRITE_LOCK);
1772 if (afs_pd_putString(aout, tcell->cellName) != 0)
1774 afs_PutCell(tcell, READ_LOCK);
1777 ReleaseWriteLock(&afs_xuser);
1782 /* Work out which cell we're changing tokens for */
1784 _settok_tokenCell(char *cellName, int *cellNum, int *primary) {
1792 if (cellName && strlen(cellName) > 0) {
1793 cell = afs_GetCellByName(cellName, READ_LOCK);
1795 cell = afs_GetPrimaryCell(READ_LOCK);
1806 *cellNum = cell->cellNum;
1807 afs_PutCell(cell, READ_LOCK);
1814 _settok_setParentPag(afs_ucred_t **cred) {
1816 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1818 osi_procname(procname, 256);
1819 afs_warnuser("Process %d (%s) tried to change pags in PSetTokens\n",
1820 MyPidxx2Pid(MyPidxx), procname);
1821 return setpag(osi_curproc(), cred, -1, &pag, 1);
1823 return setpag(cred, -1, &pag, 1);
1828 * VIOCSETTOK (3) - Set authentication tokens
1832 * \param[in] ain the krb tickets from which to set the afs tokens
1833 * \param[out] aout not in use
1836 * Error if the ticket is either too long or too short
1838 * Error if the AFS initState is below 101
1840 * Error if the cell for which the Token is being set can't be found
1843 * Set the Tokens for a specific cell name, unless there is none set,
1844 * then default to primary
1847 DECL_PIOCTL(PSetTokens)
1852 struct unixuser *tu;
1853 struct ClearToken clear;
1857 struct vrequest treq;
1858 afs_int32 flag, set_parent_pag = 0;
1860 AFS_STATCNT(PSetTokens);
1861 if (!afs_resourceinit_flag) {
1865 if (afs_pd_getInt(ain, &stLen) != 0)
1868 stp = afs_pd_where(ain); /* remember where the ticket is */
1869 if (stLen < 0 || stLen > MAXKTCTICKETLEN)
1870 return EINVAL; /* malloc may fail */
1871 if (afs_pd_skip(ain, stLen) != 0)
1874 if (afs_pd_getInt(ain, &size) != 0)
1876 if (size != sizeof(struct ClearToken))
1879 if (afs_pd_getBytes(ain, &clear, sizeof(struct ClearToken)) !=0)
1882 if (clear.AuthHandle == -1)
1883 clear.AuthHandle = 999; /* more rxvab compat stuff */
1885 if (afs_pd_remaining(ain) != 0) {
1886 /* still stuff left? we've got primary flag and cell name.
1889 if (afs_pd_getInt(ain, &flag) != 0)
1892 /* some versions of gcc appear to need != 0 in order to get this
1894 if ((flag & 0x8000) != 0) { /* XXX Use Constant XXX */
1899 if (afs_pd_getStringPtr(ain, &cellName) != 0)
1902 code = _settok_tokenCell(cellName, &cellNum, NULL);
1906 /* default to primary cell, primary id */
1907 code = _settok_tokenCell(NULL, &cellNum, &flag);
1912 if (set_parent_pag) {
1913 if (_settok_setParentPag(acred) == 0) {
1914 afs_InitReq(&treq, *acred);
1919 /* now we just set the tokens */
1920 tu = afs_GetUser(areq->uid, cellNum, WRITE_LOCK);
1921 /* Set tokens destroys any that are already there */
1922 afs_FreeTokens(&tu->tokens);
1923 afs_AddRxkadToken(&tu->tokens, stp, stLen, &clear);
1925 afs_stats_cmfullperf.authent.TicketUpdates++;
1926 afs_ComputePAGStats();
1927 #endif /* AFS_NOSTATS */
1928 tu->states |= UHasTokens;
1929 tu->states &= ~UTokensBad;
1930 afs_SetPrimary(tu, flag);
1931 tu->tokenTime = osi_Time();
1932 afs_ResetUserConns(tu);
1933 afs_NotifyUser(tu, UTokensObtained);
1934 afs_PutUser(tu, WRITE_LOCK);
1940 * VIOCGETVOLSTAT (4) - Get volume status
1944 * \param[in] ain not in use
1945 * \param[out] aout status of the volume
1947 * \retval EINVAL Error if some of the standard args aren't set
1950 * The status of a volume (based on the FID of the volume), or an
1951 * offline message /motd
1953 DECL_PIOCTL(PGetVolumeStatus)
1956 char *offLineMsg = afs_osi_Alloc(256);
1957 char *motd = afs_osi_Alloc(256);
1958 struct afs_conn *tc;
1960 struct AFSFetchVolumeStatus volstat;
1964 osi_Assert(offLineMsg != NULL);
1965 osi_Assert(motd != NULL);
1966 AFS_STATCNT(PGetVolumeStatus);
1973 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
1975 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS);
1978 RXAFS_GetVolumeStatus(tc->id, avc->f.fid.Fid.Volume, &volstat,
1979 &Name, &offLineMsg, &motd);
1984 } while (afs_Analyze
1985 (tc, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS,
1986 SHARED_LOCK, NULL));
1990 /* Copy all this junk into msg->im_data, keeping track of the lengths. */
1991 if (afs_pd_putBytes(aout, &volstat, sizeof(VolumeStatus)) != 0)
1993 if (afs_pd_putString(aout, volName) != 0)
1995 if (afs_pd_putString(aout, offLineMsg) != 0)
1997 if (afs_pd_putString(aout, motd) != 0)
2000 afs_osi_Free(offLineMsg, 256);
2001 afs_osi_Free(motd, 256);
2006 * VIOCSETVOLSTAT (5) - Set volume status
2011 * values to set the status at, offline message, message of the day,
2012 * volume name, minimum quota, maximum quota
2014 * status of a volume, offlines messages, minimum quota, maximumm quota
2017 * Error if some of the standard args aren't set
2019 * Error if the volume is read only, or a backup volume
2021 * Error if the volume can't be accessed
2023 * Error if the volume name, offline message, and motd are too big
2026 * Set the status of a volume, including any offline messages,
2027 * a minimum quota, and a maximum quota
2029 DECL_PIOCTL(PSetVolumeStatus)
2034 struct afs_conn *tc;
2036 struct AFSFetchVolumeStatus volstat;
2037 struct AFSStoreVolumeStatus storeStat;
2041 AFS_STATCNT(PSetVolumeStatus);
2045 tvp = afs_GetVolume(&avc->f.fid, areq, READ_LOCK);
2047 if (tvp->states & (VRO | VBackup)) {
2048 afs_PutVolume(tvp, READ_LOCK);
2051 afs_PutVolume(tvp, READ_LOCK);
2056 if (afs_pd_getBytes(ain, &volstat, sizeof(AFSFetchVolumeStatus)) != 0)
2059 if (afs_pd_getStringPtr(ain, &volName) != 0)
2061 if (strlen(volName) > 32)
2064 if (afs_pd_getStringPtr(ain, &offLineMsg) != 0)
2066 if (strlen(offLineMsg) > 256)
2069 if (afs_pd_getStringPtr(ain, &motd) != 0)
2071 if (strlen(motd) > 256)
2074 /* Done reading ... */
2077 if (volstat.MinQuota != -1) {
2078 storeStat.MinQuota = volstat.MinQuota;
2079 storeStat.Mask |= AFS_SETMINQUOTA;
2081 if (volstat.MaxQuota != -1) {
2082 storeStat.MaxQuota = volstat.MaxQuota;
2083 storeStat.Mask |= AFS_SETMAXQUOTA;
2086 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
2088 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS);
2091 RXAFS_SetVolumeStatus(tc->id, avc->f.fid.Fid.Volume, &storeStat,
2092 volName, offLineMsg, motd);
2097 } while (afs_Analyze
2098 (tc, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS,
2099 SHARED_LOCK, NULL));
2103 /* we are sending parms back to make compat. with prev system. should
2104 * change interface later to not ask for current status, just set new
2107 if (afs_pd_putBytes(aout, &volstat, sizeof(VolumeStatus)) != 0)
2109 if (afs_pd_putString(aout, volName) != 0)
2111 if (afs_pd_putString(aout, offLineMsg) != 0)
2113 if (afs_pd_putString(aout, motd) != 0)
2120 * VIOCFLUSH (6) - Invalidate cache entry
2124 * \param[in] ain not in use
2125 * \param[out] aout not in use
2127 * \retval EINVAL Error if some of the standard args aren't set
2129 * \post Flush any information the cache manager has on an entry
2133 AFS_STATCNT(PFlush);
2136 #ifdef AFS_BOZONLOCK_ENV
2137 afs_BozonLock(&avc->pvnLock, avc); /* Since afs_TryToSmush will do a pvn_vptrunc */
2139 ObtainWriteLock(&avc->lock, 225);
2140 afs_ResetVCache(avc, *acred);
2141 ReleaseWriteLock(&avc->lock);
2142 #ifdef AFS_BOZONLOCK_ENV
2143 afs_BozonUnlock(&avc->pvnLock, avc);
2149 * VIOC_AFS_STAT_MT_PT (29) - Stat mount point
2154 * the last component in a path, related to mountpoint that we're
2155 * looking for information about
2157 * volume, cell, link data
2159 * \retval EINVAL Error if some of the standard args aren't set
2160 * \retval ENOTDIR Error if the 'mount point' argument isn't a directory
2161 * \retval EIO Error if the link data can't be accessed
2163 * \post Get the volume, and cell, as well as the link data for a mount point
2165 DECL_PIOCTL(PNewStatMount)
2170 struct VenusFid tfid;
2173 struct sysname_info sysState;
2174 afs_size_t offset, len;
2176 AFS_STATCNT(PNewStatMount);
2180 if (afs_pd_getStringPtr(ain, &name) != 0)
2183 code = afs_VerifyVCache(avc, areq);
2186 if (vType(avc) != VDIR) {
2189 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
2192 Check_AtSys(avc, name, &sysState, areq);
2193 ObtainReadLock(&tdc->lock);
2195 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
2196 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
2197 ReleaseReadLock(&tdc->lock);
2198 afs_PutDCache(tdc); /* we're done with the data */
2199 bufp = sysState.name;
2203 tfid.Cell = avc->f.fid.Cell;
2204 tfid.Fid.Volume = avc->f.fid.Fid.Volume;
2205 if (!tfid.Fid.Unique && (avc->f.states & CForeign)) {
2206 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
2208 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
2214 if (tvc->mvstat != 1) {
2219 ObtainWriteLock(&tvc->lock, 226);
2220 code = afs_HandleLink(tvc, areq);
2222 if (tvc->linkData) {
2223 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
2226 /* we have the data */
2227 if (afs_pd_putString(aout, tvc->linkData) != 0)
2233 ReleaseWriteLock(&tvc->lock);
2236 if (sysState.allocked)
2237 osi_FreeLargeSpace(bufp);
2242 * A helper function to get the n'th cell which a particular user has tokens
2243 * for. This is racy. If new tokens are added whilst we're iterating, then
2244 * we may return some cells twice. If tokens expire mid run, then we'll
2245 * miss some cells from our output. So, could be better, but that would
2246 * require an interface change.
2249 static struct unixuser *
2250 getNthCell(afs_int32 uid, afs_int32 iterator) {
2252 struct unixuser *tu = NULL;
2255 ObtainReadLock(&afs_xuser);
2256 for (tu = afs_users[i]; tu; tu = tu->next) {
2257 if (tu->uid == uid && (tu->states & UHasTokens)) {
2258 if (iterator-- == 0)
2259 break; /* are we done yet? */
2265 ReleaseReadLock(&afs_xuser);
2270 * VIOCGETTOK (8) - Get authentication tokens
2274 * \param[in] ain cellid to return tokens for
2275 * \param[out] aout token
2278 * Error if the afs daemon hasn't started yet
2280 * Error if the input parameter is out of the bounds of the available
2283 * Error if there aren't tokens for this cell
2286 * If the input paramater exists, get the token that corresponds to
2287 * the parameter value, if there is no token at this value, get the
2288 * token for the first cell
2290 * \notes "it's a weird interface (from comments in the code)"
2293 DECL_PIOCTL(PGetTokens)
2296 struct unixuser *tu = NULL;
2297 union tokenUnion *token;
2298 afs_int32 iterator = 0;
2303 AFS_STATCNT(PGetTokens);
2304 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2305 return EIO; /* Inappropriate ioctl for device */
2307 /* weird interface. If input parameter is present, it is an integer and
2308 * we're supposed to return the parm'th tokens for this unix uid.
2309 * If not present, we just return tokens for cell 1.
2310 * If counter out of bounds, return EDOM.
2311 * If no tokens for the particular cell, return ENOTCONN.
2312 * Also, if this mysterious parm is present, we return, along with the
2313 * tokens, the primary cell indicator (an afs_int32 0) and the cell name
2314 * at the end, in that order.
2316 newStyle = (afs_pd_remaining(ain) > 0);
2318 if (afs_pd_getInt(ain, &iterator) != 0)
2322 tu = getNthCell(areq->uid, iterator);
2324 cellNum = afs_GetPrimaryCellNum();
2326 tu = afs_FindUser(areq->uid, cellNum, READ_LOCK);
2331 if (!(tu->states & UHasTokens)
2332 || !afs_HasUsableTokens(tu->tokens, osi_Time())) {
2333 tu->states |= (UTokensBad | UNeedsReset);
2334 afs_NotifyUser(tu, UTokensDropped);
2335 afs_PutUser(tu, READ_LOCK);
2338 token = afs_FindToken(tu->tokens, RX_SECIDX_KAD);
2340 /* If they don't have an RXKAD token, but do have other tokens,
2341 * then sadly there's nothing this interface can do to help them. */
2345 /* for compat, we try to return 56 byte tix if they fit */
2346 iterator = token->rxkad.ticketLen;
2348 iterator = 56; /* # of bytes we're returning */
2350 if (afs_pd_putInt(aout, iterator) != 0)
2352 if (afs_pd_putBytes(aout, token->rxkad.ticket, token->rxkad.ticketLen) != 0)
2354 if (token->rxkad.ticketLen < 56) {
2355 /* Tokens are always 56 bytes or larger */
2356 if (afs_pd_skip(aout, iterator - token->rxkad.ticketLen) != 0) {
2361 if (afs_pd_putInt(aout, sizeof(struct ClearToken)) != 0)
2363 if (afs_pd_putBytes(aout, &token->rxkad.clearToken,
2364 sizeof(struct ClearToken)) != 0)
2368 /* put out primary id and cell name, too */
2369 iterator = (tu->states & UPrimary ? 1 : 0);
2370 if (afs_pd_putInt(aout, iterator) != 0)
2372 tcell = afs_GetCell(tu->cell, READ_LOCK);
2374 if (afs_pd_putString(aout, tcell->cellName) != 0)
2376 afs_PutCell(tcell, READ_LOCK);
2378 if (afs_pd_putString(aout, "") != 0)
2381 /* Got here, all is good */
2384 afs_PutUser(tu, READ_LOCK);
2389 * VIOCUNLOG (9) - Invalidate tokens
2393 * \param[in] ain not in use
2394 * \param[out] aout not in use
2396 * \retval EIO Error if the afs daemon hasn't been started yet
2398 * \post remove tokens from a user, specified by the user id
2400 * \notes sets the token's time to 0, which then causes it to be removed
2401 * \notes Unlog is the same as un-pag in OpenAFS
2406 struct unixuser *tu;
2408 AFS_STATCNT(PUnlog);
2409 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2410 return EIO; /* Inappropriate ioctl for device */
2412 i = UHash(areq->uid);
2413 ObtainWriteLock(&afs_xuser, 227);
2414 for (tu = afs_users[i]; tu; tu = tu->next) {
2415 if (tu->uid == areq->uid) {
2416 tu->states &= ~UHasTokens;
2417 afs_FreeTokens(&tu->tokens);
2419 ReleaseWriteLock(&afs_xuser);
2420 afs_NotifyUser(tu, UTokensDropped);
2421 /* We have to drop the lock over the call to afs_ResetUserConns,
2422 * since it obtains the afs_xvcache lock. We could also keep
2423 * the lock, and modify ResetUserConns to take parm saying we
2424 * obtained the lock already, but that is overkill. By keeping
2425 * the "tu" pointer held over the released lock, we guarantee
2426 * that we won't lose our place, and that we'll pass over
2427 * every user conn that existed when we began this call.
2429 afs_ResetUserConns(tu);
2431 ObtainWriteLock(&afs_xuser, 228);
2433 /* set the expire times to 0, causes
2434 * afs_GCUserData to remove this entry
2437 #endif /* UKERNEL */
2440 ReleaseWriteLock(&afs_xuser);
2445 * VIOC_AFS_MARINER_HOST (32) - Get/set mariner (cache manager monitor) host
2449 * \param[in] ain host address to be set
2450 * \param[out] aout old host address
2453 * depending on whether or not a variable is set, either get the host
2454 * for the cache manager monitor, or set the old address and give it
2457 * \notes Errors turn off mariner
2459 DECL_PIOCTL(PMariner)
2461 afs_int32 newHostAddr;
2462 afs_int32 oldHostAddr;
2464 AFS_STATCNT(PMariner);
2466 memcpy((char *)&oldHostAddr, (char *)&afs_marinerHost,
2469 oldHostAddr = 0xffffffff; /* disabled */
2471 if (afs_pd_getInt(ain, &newHostAddr) != 0)
2474 if (newHostAddr == 0xffffffff) {
2475 /* disable mariner operations */
2477 } else if (newHostAddr) {
2479 afs_marinerHost = newHostAddr;
2482 if (afs_pd_putInt(aout, oldHostAddr) != 0)
2489 * VIOCCKSERV (10) - Check that servers are up
2493 * \param[in] ain name of the cell
2494 * \param[out] aout current down server list
2496 * \retval EIO Error if the afs daemon hasn't started yet
2497 * \retval EACCES Error if the user doesn't have super-user credentials
2498 * \retval ENOENT Error if we are unable to obtain the cell
2501 * Either a fast check (where it doesn't contact servers) or a
2502 * local check (checks local cell only)
2504 DECL_PIOCTL(PCheckServers)
2509 char *cellName = NULL;
2511 struct chservinfo *pcheck;
2513 AFS_STATCNT(PCheckServers);
2515 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2516 return EIO; /* Inappropriate ioctl for device */
2518 /* This is tricky, because we need to peak at the datastream to see
2519 * what we're getting. For now, let's cheat. */
2521 /* ain contains either an int32 or a string */
2522 if (ain->remaining == 0)
2525 if (*(afs_int32 *)ain->ptr == 0x12345678) { /* For afs3.3 version */
2526 pcheck = afs_pd_inline(ain, sizeof(*pcheck));
2530 if (pcheck->tinterval >= 0) {
2531 if (afs_pd_putInt(aout, afs_probe_interval) != 0)
2533 if (pcheck->tinterval > 0) {
2534 if (!afs_osi_suser(*acred))
2536 afs_probe_interval = pcheck->tinterval;
2540 temp = pcheck->tflags;
2542 cellName = pcheck->tbuffer;
2543 } else { /* For pre afs3.3 versions */
2544 if (afs_pd_getInt(ain, &temp) != 0)
2546 if (afs_pd_remaining(ain) > 0) {
2547 if (afs_pd_getStringPtr(ain, &cellName) != 0)
2553 * 1: fast check, don't contact servers.
2554 * 2: local cell only.
2557 /* have cell name, too */
2558 cellp = afs_GetCellByName(cellName, READ_LOCK);
2563 if (!cellp && (temp & 2)) {
2564 /* use local cell */
2565 cellp = afs_GetPrimaryCell(READ_LOCK);
2567 if (!(temp & 1)) { /* if not fast, call server checker routine */
2568 afs_CheckServers(1, cellp); /* check down servers */
2569 afs_CheckServers(0, cellp); /* check up servers */
2571 /* now return the current down server list */
2572 ObtainReadLock(&afs_xserver);
2573 for (i = 0; i < NSERVERS; i++) {
2574 for (ts = afs_servers[i]; ts; ts = ts->next) {
2575 if (cellp && ts->cell != cellp)
2576 continue; /* cell spec'd and wrong */
2577 if ((ts->flags & SRVR_ISDOWN)
2578 && ts->addr->sa_portal != ts->cell->vlport) {
2579 afs_pd_putInt(aout, ts->addr->sa_ip);
2583 ReleaseReadLock(&afs_xserver);
2585 afs_PutCell(cellp, READ_LOCK);
2590 * VIOCCKBACK (11) - Check backup volume mappings
2594 * \param[in] ain not in use
2595 * \param[out] aout not in use
2597 * \retval EIO Error if the afs daemon hasn't started yet
2600 * Check the root volume, and then check the names if the volume
2601 * check variable is set to force, has expired, is busy, or if
2602 * the mount points variable is set
2604 DECL_PIOCTL(PCheckVolNames)
2606 AFS_STATCNT(PCheckVolNames);
2607 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2608 return EIO; /* Inappropriate ioctl for device */
2610 afs_CheckRootVolume();
2611 afs_CheckVolumeNames(AFS_VOLCHECK_FORCE | AFS_VOLCHECK_EXPIRED |
2612 AFS_VOLCHECK_BUSY | AFS_VOLCHECK_MTPTS);
2617 * VIOCCKCONN (12) - Check connections for a user
2621 * \param[in] ain not in use
2622 * \param[out] aout not in use
2625 * Error if no user is specififed, the user has no tokens set,
2626 * or if the user's tokens are bad
2629 * check to see if a user has the correct authentication.
2630 * If so, allow access.
2632 * \notes Check the connections to all the servers specified
2634 DECL_PIOCTL(PCheckAuth)
2638 struct sa_conn_vector *tcv;
2639 struct unixuser *tu;
2642 AFS_STATCNT(PCheckAuth);
2643 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2644 return EIO; /* Inappropriate ioctl for device */
2647 tu = afs_GetUser(areq->uid, 1, READ_LOCK); /* check local cell authentication */
2651 /* we have a user */
2652 ObtainReadLock(&afs_xsrvAddr);
2653 ObtainReadLock(&afs_xconn);
2655 /* any tokens set? */
2656 if ((tu->states & UHasTokens) == 0)
2658 /* all connections in cell 1 working? */
2659 for (i = 0; i < NSERVERS; i++) {
2660 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2661 for (tcv = sa->conns; tcv; tcv = tcv->next) {
2662 if (tcv->user == tu && (tu->states & UTokensBad))
2667 ReleaseReadLock(&afs_xsrvAddr);
2668 ReleaseReadLock(&afs_xconn);
2669 afs_PutUser(tu, READ_LOCK);
2671 if (afs_pd_putInt(aout, retValue) != 0)
2677 Prefetch(uparmtype apath, struct afs_ioctl *adata, int afollow,
2682 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2688 AFS_STATCNT(Prefetch);
2691 tp = osi_AllocLargeSpace(1024);
2692 AFS_COPYINSTR(apath, tp, 1024, &bufferSize, code);
2694 osi_FreeLargeSpace(tp);
2697 if (afs_BBusy()) { /* do this as late as possible */
2698 osi_FreeLargeSpace(tp);
2699 return EWOULDBLOCK; /* pretty close */
2701 afs_BQueue(BOP_PATH, (struct vcache *)0, 0, 0, acred, (afs_size_t) 0,
2702 (afs_size_t) 0, tp, (void *)0, (void *)0);
2707 * VIOCWHEREIS (14) - Find out where a volume is located
2711 * \param[in] ain not in use
2712 * \param[out] aout volume location
2714 * \retval EINVAL Error if some of the default arguments don't exist
2715 * \retval ENODEV Error if there is no such volume
2717 * \post fine a volume, based on a volume file id
2719 * \notes check each of the servers specified
2721 DECL_PIOCTL(PFindVolume)
2728 AFS_STATCNT(PFindVolume);
2731 tvp = afs_GetVolume(&avc->f.fid, areq, READ_LOCK);
2735 for (i = 0; i < AFS_MAXHOSTS; i++) {
2736 ts = tvp->serverHost[i];
2739 if (afs_pd_putInt(aout, ts->addr->sa_ip) != 0) {
2744 if (i < AFS_MAXHOSTS) {
2745 /* still room for terminating NULL, add it on */
2746 if (afs_pd_putInt(aout, 0) != 0) {
2752 afs_PutVolume(tvp, READ_LOCK);
2757 * VIOCACCESS (20) - Access using PRS_FS bits
2761 * \param[in] ain PRS_FS bits
2762 * \param[out] aout not in use
2764 * \retval EINVAL Error if some of the initial arguments aren't set
2765 * \retval EACCES Error if access is denied
2767 * \post check to make sure access is allowed
2769 DECL_PIOCTL(PViceAccess)
2774 AFS_STATCNT(PViceAccess);
2778 code = afs_VerifyVCache(avc, areq);
2782 if (afs_pd_getInt(ain, &temp) != 0)
2785 code = afs_AccessOK(avc, temp, areq, CHECK_MODE_BITS);
2793 * VIOC_GETPAG (13) - Get PAG value
2797 * \param[in] ain not in use
2798 * \param[out] aout PAG value or NOPAG
2800 * \post get PAG value for the caller's cred
2802 DECL_PIOCTL(PGetPAG)
2806 pag = PagInCred(*acred);
2808 return afs_pd_putInt(aout, pag);
2811 DECL_PIOCTL(PPrecache)
2815 /*AFS_STATCNT(PPrecache);*/
2816 if (!afs_osi_suser(*acred))
2819 if (afs_pd_getInt(ain, &newValue) != 0)
2822 afs_preCache = newValue*1024;
2827 * VIOCSETCACHESIZE (24) - Set venus cache size in 1000 units
2831 * \param[in] ain the size the venus cache should be set to
2832 * \param[out] aout not in use
2834 * \retval EACCES Error if the user doesn't have super-user credentials
2835 * \retval EROFS Error if the cache is set to be in memory
2838 * Set the cache size based on user input. If no size is given,
2839 * set it to the default OpenAFS cache size.
2842 * recompute the general cache parameters for every single block allocated
2844 DECL_PIOCTL(PSetCacheSize)
2849 AFS_STATCNT(PSetCacheSize);
2851 if (!afs_osi_suser(*acred))
2853 /* too many things are setup initially in mem cache version */
2854 if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
2856 if (afs_pd_getInt(ain, &newValue) != 0)
2859 afs_cacheBlocks = afs_stats_cmperf.cacheBlocksOrig;
2861 if (newValue < afs_min_cache)
2862 afs_cacheBlocks = afs_min_cache;
2864 afs_cacheBlocks = newValue;
2866 afs_stats_cmperf.cacheBlocksTotal = afs_cacheBlocks;
2867 afs_ComputeCacheParms(); /* recompute basic cache parameters */
2868 afs_MaybeWakeupTruncateDaemon();
2869 while (waitcnt++ < 100 && afs_cacheBlocks < afs_blocksUsed) {
2870 afs_osi_Wait(1000, 0, 0);
2871 afs_MaybeWakeupTruncateDaemon();
2876 #define MAXGCSTATS 16
2878 * VIOCGETCACHEPARMS (40) - Get cache stats
2882 * \param[in] ain afs index flags
2883 * \param[out] aout cache blocks, blocks used, blocks files (in an array)
2885 * \post Get the cache blocks, and how many of the cache blocks there are
2887 DECL_PIOCTL(PGetCacheSize)
2889 afs_int32 results[MAXGCSTATS];
2891 struct dcache * tdc;
2894 AFS_STATCNT(PGetCacheSize);
2896 if (afs_pd_remaining(ain) == sizeof(afs_int32)) {
2897 afs_pd_getInt(ain, &flags); /* can't error, we just checked size */
2898 } else if (afs_pd_remaining(ain) == 0) {
2904 memset(results, 0, sizeof(results));
2905 results[0] = afs_cacheBlocks;
2906 results[1] = afs_blocksUsed;
2907 results[2] = afs_cacheFiles;
2910 for (i = 0; i < afs_cacheFiles; i++) {
2911 if (afs_indexFlags[i] & IFFree) results[3]++;
2913 } else if (2 == flags){
2914 for (i = 0; i < afs_cacheFiles; i++) {
2915 if (afs_indexFlags[i] & IFFree) results[3]++;
2916 if (afs_indexFlags[i] & IFEverUsed) results[4]++;
2917 if (afs_indexFlags[i] & IFDataMod) results[5]++;
2918 if (afs_indexFlags[i] & IFDirtyPages) results[6]++;
2919 if (afs_indexFlags[i] & IFAnyPages) results[7]++;
2920 if (afs_indexFlags[i] & IFDiscarded) results[8]++;
2922 tdc = afs_indexTable[i];
2925 size = tdc->validPos;
2926 if ( 0 < size && size < (1<<12) ) results[10]++;
2927 else if (size < (1<<14) ) results[11]++;
2928 else if (size < (1<<16) ) results[12]++;
2929 else if (size < (1<<18) ) results[13]++;
2930 else if (size < (1<<20) ) results[14]++;
2931 else if (size >= (1<<20) ) results[15]++;
2935 return afs_pd_putBytes(aout, results, sizeof(results));
2939 * VIOCFLUSHCB (25) - Flush callback only
2943 * \param[in] ain not in use
2944 * \param[out] aout not in use
2946 * \retval EINVAL Error if some of the standard args aren't set
2947 * \retval 0 0 returned if the volume is set to read-only
2950 * Flushes callbacks, by setting the length of callbacks to one,
2951 * setting the next callback to be sent to the CB_DROPPED value,
2952 * and then dequeues everything else.
2954 DECL_PIOCTL(PRemoveCallBack)
2956 struct afs_conn *tc;
2958 struct AFSCallBack CallBacks_Array[1];
2959 struct AFSCBFids theFids;
2960 struct AFSCBs theCBs;
2963 AFS_STATCNT(PRemoveCallBack);
2966 if (avc->f.states & CRO)
2967 return 0; /* read-only-ness can't change */
2968 ObtainWriteLock(&avc->lock, 229);
2969 theFids.AFSCBFids_len = 1;
2970 theCBs.AFSCBs_len = 1;
2971 theFids.AFSCBFids_val = (struct AFSFid *)&avc->f.fid.Fid;
2972 theCBs.AFSCBs_val = CallBacks_Array;
2973 CallBacks_Array[0].CallBackType = CB_DROPPED;
2974 if (avc->callback) {
2976 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
2978 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
2980 code = RXAFS_GiveUpCallBacks(tc->id, &theFids, &theCBs);
2984 /* don't set code on failure since we wouldn't use it */
2985 } while (afs_Analyze
2986 (tc, code, &avc->f.fid, areq,
2987 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK, NULL));
2989 ObtainWriteLock(&afs_xcbhash, 457);
2990 afs_DequeueCallback(avc);
2992 avc->f.states &= ~(CStatd | CUnique);
2993 ReleaseWriteLock(&afs_xcbhash);
2994 if (avc->f.fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
2995 osi_dnlc_purgedp(avc);
2997 ReleaseWriteLock(&avc->lock);
3002 * VIOCNEWCELL (26) - Configure new cell
3007 * the name of the cell, the hosts that will be a part of the cell,
3008 * whether or not it's linked with another cell, the other cell it's
3009 * linked with, the file server port, and the volume server port
3013 * \retval EIO Error if the afs daemon hasn't started yet
3014 * \retval EACCES Error if the user doesn't have super-user cedentials
3015 * \retval EINVAL Error if some 'magic' var doesn't have a certain bit set
3017 * \post creates a new cell
3019 DECL_PIOCTL(PNewCell)
3021 afs_int32 cellHosts[AFS_MAXCELLHOSTS], magic = 0;
3022 char *newcell = NULL;
3023 char *linkedcell = NULL;
3025 afs_int32 linkedstate = 0;
3026 afs_int32 fsport = 0, vlport = 0;
3029 AFS_STATCNT(PNewCell);
3030 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3031 return EIO; /* Inappropriate ioctl for device */
3033 if (!afs_osi_suser(*acred))
3036 if (afs_pd_getInt(ain, &magic) != 0)
3038 if (magic != 0x12345678)
3041 /* A 3.4 fs newcell command will pass an array of AFS_MAXCELLHOSTS
3042 * server addresses while the 3.5 fs newcell command passes
3043 * AFS_MAXHOSTS. To figure out which is which, check if the cellname
3046 * This whole logic is bogus, because it relies on the newer command
3047 * sending its 12th address as 0.
3049 if ((afs_pd_remaining(ain) < AFS_MAXCELLHOSTS +3) * sizeof(afs_int32))
3052 newcell = afs_pd_where(ain) + (AFS_MAXCELLHOSTS + 3) * sizeof(afs_int32);
3053 if (newcell[0] != '\0') {
3056 skip = AFS_MAXHOSTS - AFS_MAXCELLHOSTS;
3059 /* AFS_MAXCELLHOSTS (=8) is less than AFS_MAXHOSTS (=13) */
3060 if (afs_pd_getBytes(ain, &cellHosts,
3061 AFS_MAXCELLHOSTS * sizeof(afs_int32)) != 0)
3063 if (afs_pd_skip(ain, skip * sizeof(afs_int32)) !=0)
3066 if (afs_pd_getInt(ain, &fsport) != 0)
3069 fsport = 0; /* Privileged ports not allowed */
3071 if (afs_pd_getInt(ain, &vlport) != 0)
3074 vlport = 0; /* Privileged ports not allowed */
3076 if (afs_pd_getInt(ain, &ls) != 0)
3079 if (afs_pd_getStringPtr(ain, &newcell) != 0)
3083 if (afs_pd_getStringPtr(ain, &linkedcell) != 0)
3085 linkedstate |= CLinkedCell;
3088 linkedstate |= CNoSUID; /* setuid is disabled by default for fs newcell */
3090 afs_NewCell(newcell, cellHosts, linkedstate, linkedcell, fsport,
3095 DECL_PIOCTL(PNewAlias)
3097 /* create a new cell alias */
3098 char *realName, *aliasName;
3100 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3101 return EIO; /* Inappropriate ioctl for device */
3103 if (!afs_osi_suser(*acred))
3106 if (afs_pd_getStringPtr(ain, &aliasName) != 0)
3108 if (afs_pd_getStringPtr(ain, &realName) != 0)
3111 return afs_NewCellAlias(aliasName, realName);
3115 * VIOCGETCELL (27) - Get cell info
3119 * \param[in] ain The cell index of a specific cell
3120 * \param[out] aout list of servers in the cell
3122 * \retval EIO Error if the afs daemon hasn't started yet
3123 * \retval EDOM Error if there is no cell asked about
3125 * \post Lists the cell's server names and and addresses
3127 DECL_PIOCTL(PListCells)
3129 afs_int32 whichCell;
3130 struct cell *tcell = 0;
3134 AFS_STATCNT(PListCells);
3135 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3136 return EIO; /* Inappropriate ioctl for device */
3138 if (afs_pd_getInt(ain, &whichCell) != 0)
3141 tcell = afs_GetCellByIndex(whichCell, READ_LOCK);
3147 for (i = 0; i < AFS_MAXCELLHOSTS; i++) {
3148 if (tcell->cellHosts[i] == 0)
3150 if (afs_pd_putInt(aout, tcell->cellHosts[i]->addr->sa_ip) != 0)
3153 for (;i < AFS_MAXCELLHOSTS; i++) {
3154 if (afs_pd_putInt(aout, 0) != 0)
3157 if (afs_pd_putString(aout, tcell->cellName) != 0)
3162 afs_PutCell(tcell, READ_LOCK);
3166 DECL_PIOCTL(PListAliases)
3168 afs_int32 whichAlias;
3169 struct cell_alias *tcalias = 0;
3172 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3173 return EIO; /* Inappropriate ioctl for device */
3175 if (afs_pd_getInt(ain, &whichAlias) != 0)
3178 tcalias = afs_GetCellAlias(whichAlias);
3179 if (tcalias == NULL)
3183 if (afs_pd_putString(aout, tcalias->alias) != 0)
3185 if (afs_pd_putString(aout, tcalias->cell) != 0)
3190 afs_PutCellAlias(tcalias);
3195 * VIOC_AFS_DELETE_MT_PT (28) - Delete mount point
3199 * \param[in] ain the name of the file in this dir to remove
3200 * \param[out] aout not in use
3203 * Error if some of the standard args aren't set
3205 * Error if the argument to remove is not a directory
3207 * Error if there is no cache to remove the mount point from or
3208 * if a vcache doesn't exist
3211 * Ensure that everything is OK before deleting the mountpoint.
3212 * If not, don't delete. Delete a mount point based on a file id.
3214 DECL_PIOCTL(PRemoveMount)
3219 struct sysname_info sysState;
3220 afs_size_t offset, len;
3221 struct afs_conn *tc;
3224 struct AFSFetchStatus OutDirStatus;
3225 struct VenusFid tfid;
3226 struct AFSVolSync tsync;
3229 /* "ain" is the name of the file in this dir to remove */
3231 AFS_STATCNT(PRemoveMount);
3234 if (afs_pd_getStringPtr(ain, &name) != 0)
3237 code = afs_VerifyVCache(avc, areq);
3240 if (vType(avc) != VDIR)
3243 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1); /* test for error below */
3246 Check_AtSys(avc, name, &sysState, areq);
3247 ObtainReadLock(&tdc->lock);
3249 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
3250 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
3251 ReleaseReadLock(&tdc->lock);
3252 bufp = sysState.name;
3257 tfid.Cell = avc->f.fid.Cell;
3258 tfid.Fid.Volume = avc->f.fid.Fid.Volume;
3259 if (!tfid.Fid.Unique && (avc->f.states & CForeign)) {
3260 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
3262 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3269 if (tvc->mvstat != 1) {
3275 ObtainWriteLock(&tvc->lock, 230);
3276 code = afs_HandleLink(tvc, areq);
3278 if (tvc->linkData) {
3279 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
3284 ReleaseWriteLock(&tvc->lock);
3285 osi_dnlc_purgedp(tvc);
3291 ObtainWriteLock(&avc->lock, 231);
3292 osi_dnlc_remove(avc, bufp, tvc);
3294 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
3296 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE);
3299 RXAFS_RemoveFile(tc->id, (struct AFSFid *)&avc->f.fid.Fid, bufp,
3300 &OutDirStatus, &tsync);
3305 } while (afs_Analyze
3306 (tc, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_REMOVEFILE,
3307 SHARED_LOCK, NULL));
3312 ReleaseWriteLock(&avc->lock);
3316 /* we have the thing in the cache */
3317 ObtainWriteLock(&tdc->lock, 661);
3318 if (afs_LocalHero(avc, tdc, &OutDirStatus, 1)) {
3319 /* we can do it locally */
3320 code = afs_dir_Delete(tdc, bufp);
3322 ZapDCE(tdc); /* surprise error -- invalid value */
3326 ReleaseWriteLock(&tdc->lock);
3327 afs_PutDCache(tdc); /* drop ref count */
3329 avc->f.states &= ~CUnique; /* For the dfs xlator */
3330 ReleaseWriteLock(&avc->lock);
3333 if (sysState.allocked)
3334 osi_FreeLargeSpace(bufp);
3339 * VIOC_GETCELLSTATUS (35) - Get cell status info
3343 * \param[in] ain The cell you want status information on
3344 * \param[out] aout cell state (as a struct)
3346 * \retval EIO Error if the afs daemon hasn't started yet
3347 * \retval ENOENT Error if the cell doesn't exist
3349 * \post Returns the state of the cell as defined in a struct cell
3351 DECL_PIOCTL(PGetCellStatus)
3357 AFS_STATCNT(PGetCellStatus);
3358 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3359 return EIO; /* Inappropriate ioctl for device */
3361 if (afs_pd_getStringPtr(ain, &cellName) != 0)
3364 tcell = afs_GetCellByName(cellName, READ_LOCK);
3367 temp = tcell->states;
3368 afs_PutCell(tcell, READ_LOCK);
3370 return afs_pd_putInt(aout, temp);
3374 * VIOC_SETCELLSTATUS (36) - Set corresponding info
3379 * The cell you want to set information about, and the values you
3384 * \retval EIO Error if the afs daemon hasn't started yet
3385 * \retval EACCES Error if the user doesn't have super-user credentials
3388 * Set the state of the cell in a defined struct cell, based on
3389 * whether or not SetUID is allowed
3391 DECL_PIOCTL(PSetCellStatus)
3395 afs_int32 flags0, flags1;
3397 if (!afs_osi_suser(*acred))
3399 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3400 return EIO; /* Inappropriate ioctl for device */
3402 if (afs_pd_getInt(ain, &flags0) != 0)
3404 if (afs_pd_getInt(ain, &flags1) != 0)
3406 if (afs_pd_getStringPtr(ain, &cellName) != 0)
3409 tcell = afs_GetCellByName(cellName, WRITE_LOCK);
3412 if (flags0 & CNoSUID)
3413 tcell->states |= CNoSUID;
3415 tcell->states &= ~CNoSUID;
3416 afs_PutCell(tcell, WRITE_LOCK);
3421 * VIOC_FLUSHVOLUME (37) - Flush whole volume's data
3425 * \param[in] ain not in use (args in avc)
3426 * \param[out] aout not in use
3428 * \retval EINVAL Error if some of the standard args aren't set
3429 * \retval EIO Error if the afs daemon hasn't started yet
3432 * Flush all cached contents of a volume. Exactly what stays and what
3433 * goes depends on the platform.
3436 * Does not flush a file that a user has open and is using, because
3437 * it will be re-created on next write. Also purges the dnlc,
3438 * because things are screwed up.
3440 DECL_PIOCTL(PFlushVolumeData)
3446 afs_int32 cell, volume;
3447 struct afs_q *tq, *uq;
3448 #ifdef AFS_DARWIN80_ENV
3452 AFS_STATCNT(PFlushVolumeData);
3455 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3456 return EIO; /* Inappropriate ioctl for device */
3458 volume = avc->f.fid.Fid.Volume; /* who to zap */
3459 cell = avc->f.fid.Cell;
3462 * Clear stat'd flag from all vnodes from this volume; this will
3463 * invalidate all the vcaches associated with the volume.
3466 ObtainReadLock(&afs_xvcache);
3467 i = VCHashV(&avc->f.fid);
3468 for (tq = afs_vhashTV[i].prev; tq != &afs_vhashTV[i]; tq = uq) {
3471 if (tvc->f.fid.Fid.Volume == volume && tvc->f.fid.Cell == cell) {
3472 if (tvc->f.states & CVInit) {
3473 ReleaseReadLock(&afs_xvcache);
3474 afs_osi_Sleep(&tvc->f.states);
3477 #ifdef AFS_DARWIN80_ENV
3478 if (tvc->f.states & CDeadVnode) {
3479 if (!(tvc->f.states & CBulkFetching)) {
3480 ReleaseReadLock(&afs_xvcache);
3481 afs_osi_Sleep(&tvc->f.states);
3488 if (vnode_ref(vp)) {
3494 if (tvc->f.states & (CBulkFetching|CDeadVnode)) {
3496 vnode_recycle(AFSTOV(tvc));
3502 ReleaseReadLock(&afs_xvcache);
3503 #ifdef AFS_BOZONLOCK_ENV
3504 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
3506 ObtainWriteLock(&tvc->lock, 232);
3508 ObtainWriteLock(&afs_xcbhash, 458);
3509 afs_DequeueCallback(tvc);
3510 tvc->f.states &= ~(CStatd | CDirty);
3511 ReleaseWriteLock(&afs_xcbhash);
3512 if (tvc->f.fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
3513 osi_dnlc_purgedp(tvc);
3514 afs_TryToSmush(tvc, *acred, 1);
3515 ReleaseWriteLock(&tvc->lock);
3516 #ifdef AFS_BOZONLOCK_ENV
3517 afs_BozonUnlock(&tvc->pvnLock, tvc);
3519 #ifdef AFS_DARWIN80_ENV
3520 vnode_put(AFSTOV(tvc));
3522 ObtainReadLock(&afs_xvcache);
3524 /* our tvc ptr is still good until now */
3528 ReleaseReadLock(&afs_xvcache);
3531 ObtainWriteLock(&afs_xdcache, 328); /* needed to flush any stuff */
3532 for (i = 0; i < afs_cacheFiles; i++) {
3533 if (!(afs_indexFlags[i] & IFEverUsed))
3534 continue; /* never had any data */
3535 tdc = afs_GetDSlot(i, NULL);
3536 if (tdc->refCount <= 1) { /* too high, in use by running sys call */
3537 ReleaseReadLock(&tdc->tlock);
3538 if (tdc->f.fid.Fid.Volume == volume && tdc->f.fid.Cell == cell) {
3539 if (!(afs_indexFlags[i] & IFDataMod)) {
3540 /* if the file is modified, but has a ref cnt of only 1,
3541 * then someone probably has the file open and is writing
3542 * into it. Better to skip flushing such a file, it will be
3543 * brought back immediately on the next write anyway.
3545 * If we *must* flush, then this code has to be rearranged
3546 * to call afs_storeAllSegments() first */
3547 afs_FlushDCache(tdc);
3551 ReleaseReadLock(&tdc->tlock);
3553 afs_PutDCache(tdc); /* bumped by getdslot */
3555 ReleaseWriteLock(&afs_xdcache);
3557 ObtainReadLock(&afs_xvolume);
3558 for (i = 0; i < NVOLS; i++) {
3559 for (tv = afs_volumes[i]; tv; tv = tv->next) {
3560 if (tv->volume == volume) {
3561 afs_ResetVolumeInfo(tv);
3566 ReleaseReadLock(&afs_xvolume);
3568 /* probably, a user is doing this, probably, because things are screwed up.
3569 * maybe it's the dnlc's fault? */
3576 * VIOCGETVCXSTATUS (41) - gets vnode x status
3581 * not in use (avc used)
3583 * vcxstat: the file id, the data version, any lock, the parent vnode,
3584 * the parent unique id, the trunc position, the callback, cbExpires,
3585 * what access is being made, what files are open,
3586 * any users executing/writing, the flock count, the states,
3590 * Error if some of the initial default arguments aren't set
3592 * Error if access to check the mode bits is denied
3595 * gets stats for the vnode, a struct listed in vcxstat
3597 DECL_PIOCTL(PGetVnodeXStatus)
3600 struct vcxstat stat;
3603 /* AFS_STATCNT(PGetVnodeXStatus); */
3606 code = afs_VerifyVCache(avc, areq);
3609 if (vType(avc) == VDIR)
3610 mode = PRSFS_LOOKUP;
3613 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
3616 memset(&stat, 0, sizeof(struct vcxstat));
3617 stat.fid = avc->f.fid;
3618 hset32(stat.DataVersion, hgetlo(avc->f.m.DataVersion));
3619 stat.lock = avc->lock;
3620 stat.parentVnode = avc->f.parent.vnode;
3621 stat.parentUnique = avc->f.parent.unique;
3622 hset(stat.flushDV, avc->flushDV);
3623 hset(stat.mapDV, avc->mapDV);
3624 stat.truncPos = avc->f.truncPos;
3625 { /* just grab the first two - won't break anything... */
3626 struct axscache *ac;
3628 for (i = 0, ac = avc->Access; ac && i < CPSIZE; i++, ac = ac->next) {
3629 stat.randomUid[i] = ac->uid;
3630 stat.randomAccess[i] = ac->axess;
3633 stat.callback = afs_data_pointer_to_int32(avc->callback);
3634 stat.cbExpires = avc->cbExpires;
3635 stat.anyAccess = avc->f.anyAccess;
3636 stat.opens = avc->opens;
3637 stat.execsOrWriters = avc->execsOrWriters;
3638 stat.flockCount = avc->flockCount;
3639 stat.mvstat = avc->mvstat;
3640 stat.states = avc->f.states;
3641 return afs_pd_putBytes(aout, &stat, sizeof(struct vcxstat));
3645 DECL_PIOCTL(PGetVnodeXStatus2)
3648 struct vcxstat2 stat;
3653 code = afs_VerifyVCache(avc, areq);
3656 if (vType(avc) == VDIR)
3657 mode = PRSFS_LOOKUP;
3660 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
3663 memset(&stat, 0, sizeof(struct vcxstat2));
3665 stat.cbExpires = avc->cbExpires;
3666 stat.anyAccess = avc->f.anyAccess;
3667 stat.mvstat = avc->mvstat;
3668 stat.callerAccess = afs_GetAccessBits(avc, ~0, areq);
3670 return afs_pd_putBytes(aout, &stat, sizeof(struct vcxstat2));
3675 * VIOC_AFS_SYSNAME (38) - Change @sys value
3679 * \param[in] ain new value for @sys
3680 * \param[out] aout count, entry, list (debug values?)
3683 * Error if afsd isn't running, the new sysname is too large,
3684 * the new sysname causes issues (starts with a . or ..),
3685 * there is no PAG set in the credentials, or the user of a PAG
3688 * Error if the user doesn't have super-user credentials
3691 * Set the value of @sys if these things work: if the input isn't
3692 * too long or if input doesn't start with . or ..
3695 * We require root for local sysname changes, but not for remote
3696 * (since we don't really believe remote uids anyway)
3697 * outname[] shouldn't really be needed- this is left as an
3698 * exercise for the reader.
3700 DECL_PIOCTL(PSetSysName)
3702 char *inname = NULL;
3703 char outname[MAXSYSNAME];
3704 afs_int32 setsysname;
3706 struct afs_exporter *exporter;
3707 struct unixuser *au;
3708 afs_int32 pag, error;
3709 int t, count, num = 0, allpags = 0;
3711 struct afs_pdata validate;
3713 AFS_STATCNT(PSetSysName);
3714 if (!afs_globalVFS) {
3715 /* Afsd is NOT running; disable it */
3716 #if defined(KERNEL_HAVE_UERROR)
3717 return (setuerror(EINVAL), EINVAL);
3722 if (afs_pd_getInt(ain, &setsysname) != 0)
3724 if (setsysname & 0x8000) {
3726 setsysname &= ~0x8000;
3731 if (setsysname < 0 || setsysname > MAXNUMSYSNAMES)
3734 for (count = 0; count < setsysname; count++) {
3735 if (afs_pd_getStringPtr(&validate, &inname) != 0)
3738 if (t >= MAXSYSNAME || t <= 0)
3740 /* check for names that can shoot us in the foot */
3741 if (inname[0] == '.' && (inname[1] == 0
3742 || (inname[1] == '.' && inname[2] == 0)))
3745 /* args ok, so go back to the beginning of that section */
3747 if (afs_pd_getStringPtr(ain, &inname) != 0)
3751 if (afs_cr_gid(*acred) == RMTUSER_REQ ||
3752 afs_cr_gid(*acred) == RMTUSER_REQ_PRIV) { /* Handles all exporters */
3753 if (allpags && afs_cr_gid(*acred) != RMTUSER_REQ_PRIV) {
3756 pag = PagInCred(*acred);
3758 return EINVAL; /* Better than panicing */
3760 if (!(au = afs_FindUser(pag, -1, READ_LOCK))) {
3761 return EINVAL; /* Better than panicing */
3763 if (!(exporter = au->exporter)) {
3764 afs_PutUser(au, READ_LOCK);
3765 return EINVAL; /* Better than panicing */
3767 error = EXP_SYSNAME(exporter, inname, &sysnamelist,
3770 if (error == ENODEV)
3771 foundname = 0; /* sysname not set yet! */
3773 afs_PutUser(au, READ_LOCK);
3778 strcpy(outname, sysnamelist[0]);
3780 afs_PutUser(au, READ_LOCK);
3784 /* Not xlating, so local case */
3786 osi_Panic("PSetSysName: !afs_sysname\n");
3787 if (!setsysname) { /* user just wants the info */
3788 strcpy(outname, afs_sysname);