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"
31 struct VenusFid afs_rootFid;
32 afs_int32 afs_waitForever = 0;
33 short afs_waitForeverCount = 0;
34 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;
51 * A set of handy little functions for encoding and decoding
52 * pioctls without losing your marbles, or memory integrity
56 afs_pd_alloc(struct afs_pdata *apd, size_t size)
59 if (size > AFS_LRALLOCSIZ)
60 apd->ptr = osi_Alloc(size + 1);
62 apd->ptr = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
67 apd->remaining = size;
73 afs_pd_free(struct afs_pdata *apd)
78 if (apd->remaining > AFS_LRALLOCSIZ)
79 osi_Free(apd->ptr, apd->remaining + 1);
81 osi_FreeLargeSpace(apd->ptr);
88 afs_pd_where(struct afs_pdata *apd)
90 return apd ? apd->ptr : NULL;
94 afs_pd_remaining(struct afs_pdata *apd)
96 return apd ? apd->remaining : 0;
100 afs_pd_skip(struct afs_pdata *apd, size_t skip)
102 if (apd == NULL || apd->remaining < skip)
104 apd->remaining -= skip;
111 afs_pd_getInt(struct afs_pdata *apd, afs_int32 *val)
113 if (apd == NULL || apd->remaining < sizeof(afs_int32))
115 apd->remaining -= sizeof(afs_int32);
116 *val = *(afs_int32 *)apd->ptr;
117 apd->ptr += sizeof(afs_int32);
122 afs_pd_getUint(struct afs_pdata *apd, afs_uint32 *val)
124 return afs_pd_getInt(apd, (afs_int32 *)val);
128 afs_pd_getBytes(struct afs_pdata *apd, void *dest, size_t bytes)
130 if (apd == NULL || apd->remaining < bytes)
132 apd->remaining -= bytes;
133 memcpy(dest, apd->ptr, bytes);
139 afs_pd_inline(struct afs_pdata *apd, size_t bytes)
143 if (apd == NULL || apd->remaining < bytes)
148 apd->remaining -= bytes;
155 afs_pd_getString(struct afs_pdata *apd, char *str, size_t maxLen)
159 if (apd == NULL || apd->remaining <= 0)
161 len = strlen(apd->ptr) + 1;
164 memcpy(str, apd->ptr, len);
166 apd->remaining -= len;
171 afs_pd_getStringPtr(struct afs_pdata *apd, char **str)
175 if (apd == NULL || apd->remaining <= 0)
177 len = strlen(apd->ptr) + 1;
180 apd->remaining -= len;
185 afs_pd_putInt(struct afs_pdata *apd, afs_int32 val)
187 if (apd == NULL || apd->remaining < sizeof(afs_int32))
189 *(afs_int32 *)apd->ptr = val;
190 apd->ptr += sizeof(afs_int32);
191 apd->remaining -= sizeof(afs_int32);
197 afs_pd_putBytes(struct afs_pdata *apd, const void *bytes, size_t len)
199 if (apd == NULL || apd->remaining < len)
201 memcpy(apd->ptr, bytes, len);
203 apd->remaining -= len;
208 afs_pd_putString(struct afs_pdata *apd, char *str) {
210 /* Add 1 so we copy the NULL too */
211 return afs_pd_putBytes(apd, str, strlen(str) +1);
215 * \defgroup pioctl Path IOCTL functions
217 * DECL_PIOCTL is a macro defined to contain the following parameters for functions:
220 * the AFS vcache structure in use by pioctl
224 * the AFS vrequest structure
226 * an afs_pdata block describing the data received from the caller
228 * an afs_pdata block describing a pre-allocated block for output
230 * UNIX credentials structure underlying the operation
233 #define DECL_PIOCTL(x) \
234 static int x(struct vcache *avc, int afun, struct vrequest *areq, \
235 struct afs_pdata *ain, struct afs_pdata *aout, \
238 /* Prototypes for pioctl routines */
239 DECL_PIOCTL(PGetFID);
240 DECL_PIOCTL(PSetAcl);
241 DECL_PIOCTL(PStoreBehind);
242 DECL_PIOCTL(PGCPAGs);
243 DECL_PIOCTL(PGetAcl);
246 DECL_PIOCTL(PGetFileCell);
247 DECL_PIOCTL(PGetWSCell);
248 DECL_PIOCTL(PGetUserCell);
249 DECL_PIOCTL(PSetTokens);
250 DECL_PIOCTL(PGetVolumeStatus);
251 DECL_PIOCTL(PSetVolumeStatus);
253 DECL_PIOCTL(PNewStatMount);
254 DECL_PIOCTL(PGetTokens);
256 DECL_PIOCTL(PMariner);
257 DECL_PIOCTL(PCheckServers);
258 DECL_PIOCTL(PCheckVolNames);
259 DECL_PIOCTL(PCheckAuth);
260 DECL_PIOCTL(PFindVolume);
261 DECL_PIOCTL(PViceAccess);
262 DECL_PIOCTL(PSetCacheSize);
263 DECL_PIOCTL(PGetCacheSize);
264 DECL_PIOCTL(PRemoveCallBack);
265 DECL_PIOCTL(PNewCell);
266 DECL_PIOCTL(PNewAlias);
267 DECL_PIOCTL(PListCells);
268 DECL_PIOCTL(PListAliases);
269 DECL_PIOCTL(PRemoveMount);
270 DECL_PIOCTL(PGetCellStatus);
271 DECL_PIOCTL(PSetCellStatus);
272 DECL_PIOCTL(PFlushVolumeData);
273 DECL_PIOCTL(PGetVnodeXStatus);
274 DECL_PIOCTL(PGetVnodeXStatus2);
275 DECL_PIOCTL(PSetSysName);
276 DECL_PIOCTL(PSetSPrefs);
277 DECL_PIOCTL(PSetSPrefs33);
278 DECL_PIOCTL(PGetSPrefs);
279 DECL_PIOCTL(PExportAfs);
281 DECL_PIOCTL(PTwiddleRx);
282 DECL_PIOCTL(PGetInitParams);
283 DECL_PIOCTL(PGetRxkcrypt);
284 DECL_PIOCTL(PSetRxkcrypt);
285 DECL_PIOCTL(PGetCPrefs);
286 DECL_PIOCTL(PSetCPrefs);
287 DECL_PIOCTL(PFlushMount);
288 DECL_PIOCTL(PRxStatProc);
289 DECL_PIOCTL(PRxStatPeer);
290 DECL_PIOCTL(PPrefetchFromTape);
292 DECL_PIOCTL(PCallBackAddr);
293 DECL_PIOCTL(PDiscon);
294 DECL_PIOCTL(PNFSNukeCreds);
295 DECL_PIOCTL(PNewUuid);
296 DECL_PIOCTL(PPrecache);
297 DECL_PIOCTL(PGetPAG);
298 #if defined(AFS_CACHE_BYPASS)
299 DECL_PIOCTL(PSetCachingThreshold);
300 DECL_PIOCTL(PSetCachingBlkSize);
304 * A macro that says whether we're going to need HandleClientContext().
305 * This is currently used only by the nfs translator.
307 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
308 #define AFS_NEED_CLIENTCONTEXT
311 /* Prototypes for private routines */
312 #ifdef AFS_NEED_CLIENTCONTEXT
313 static int HandleClientContext(struct afs_ioctl *ablob, int *com,
317 int HandleIoctl(register struct vcache *avc, register afs_int32 acom,
318 struct afs_ioctl *adata);
319 int afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
320 register struct afs_ioctl *ablob, int afollow,
321 afs_ucred_t **acred);
322 static int Prefetch(uparmtype apath, struct afs_ioctl *adata, int afollow,
325 typedef int (*pioctlFunction) (struct vcache *, int, struct vrequest *,
326 struct afs_pdata *, struct afs_pdata *,
329 static pioctlFunction VpioctlSw[] = {
334 PGetVolumeStatus, /* 4 */
335 PSetVolumeStatus, /* 5 */
340 PCheckServers, /* 10 */
341 PCheckVolNames, /* 11 */
343 PBogus, /* 13 -- used to be quick check time */
344 PFindVolume, /* 14 */
345 PBogus, /* 15 -- prefetch is now special-cased; see pioctl code! */
346 PBogus, /* 16 -- used to be testing code */
347 PNoop, /* 17 -- used to be enable group */
348 PNoop, /* 18 -- used to be disable group */
349 PBogus, /* 19 -- used to be list group */
350 PViceAccess, /* 20 */
351 PUnlog, /* 21 -- unlog *is* unpag in this system */
352 PGetFID, /* 22 -- get file ID */
353 PBogus, /* 23 -- used to be waitforever */
354 PSetCacheSize, /* 24 */
355 PRemoveCallBack, /* 25 -- flush only the callback */
358 PRemoveMount, /* 28 -- delete mount point */
359 PNewStatMount, /* 29 -- new style mount point stat */
360 PGetFileCell, /* 30 -- get cell name for input file */
361 PGetWSCell, /* 31 -- get cell name for workstation */
362 PMariner, /* 32 - set/get mariner host */
363 PGetUserCell, /* 33 -- get cell name for user */
364 PBogus, /* 34 -- Enable/Disable logging */
365 PGetCellStatus, /* 35 */
366 PSetCellStatus, /* 36 */
367 PFlushVolumeData, /* 37 -- flush all data from a volume */
368 PSetSysName, /* 38 - Set system name */
369 PExportAfs, /* 39 - Export Afs to remote nfs clients */
370 PGetCacheSize, /* 40 - get cache size and usage */
371 PGetVnodeXStatus, /* 41 - get vcache's special status */
372 PSetSPrefs33, /* 42 - Set CM Server preferences... */
373 PGetSPrefs, /* 43 - Get CM Server preferences... */
374 PGag, /* 44 - turn off/on all CM messages */
375 PTwiddleRx, /* 45 - adjust some RX params */
376 PSetSPrefs, /* 46 - Set CM Server preferences... */
377 PStoreBehind, /* 47 - set degree of store behind to be done */
378 PGCPAGs, /* 48 - disable automatic pag gc-ing */
379 PGetInitParams, /* 49 - get initial cm params */
380 PGetCPrefs, /* 50 - get client interface addresses */
381 PSetCPrefs, /* 51 - set client interface addresses */
382 PFlushMount, /* 52 - flush mount symlink data */
383 PRxStatProc, /* 53 - control process RX statistics */
384 PRxStatPeer, /* 54 - control peer RX statistics */
385 PGetRxkcrypt, /* 55 -- Get rxkad encryption flag */
386 PSetRxkcrypt, /* 56 -- Set rxkad encryption flag */
387 PBogus, /* 57 -- arla: set file prio */
388 PBogus, /* 58 -- arla: fallback getfh */
389 PBogus, /* 59 -- arla: fallback fhopen */
390 PBogus, /* 60 -- arla: controls xfsdebug */
391 PBogus, /* 61 -- arla: controls arla debug */
392 PBogus, /* 62 -- arla: debug interface */
393 PBogus, /* 63 -- arla: print xfs status */
394 PBogus, /* 64 -- arla: force cache check */
395 PBogus, /* 65 -- arla: break callback */
396 PPrefetchFromTape, /* 66 -- MR-AFS: prefetch file from tape */
397 PFsCmd, /* 67 -- RXOSD: generic commnd interface */
398 PBogus, /* 68 -- arla: fetch stats */
399 PGetVnodeXStatus2, /* 69 - get caller access and some vcache status */
402 static pioctlFunction CpioctlSw[] = {
404 PNewAlias, /* 1 -- create new cell alias */
405 PListAliases, /* 2 -- list cell aliases */
406 PCallBackAddr, /* 3 -- request addr for callback rxcon */
408 PDiscon, /* 5 -- get/set discon mode */
419 static pioctlFunction OpioctlSw[] = {
421 PNFSNukeCreds, /* 1 -- nuke all creds for NFS client */
422 #if defined(AFS_CACHE_BYPASS)
423 PSetCachingThreshold /* 2 -- get/set cache-bypass size threshold */
425 PNoop /* 2 -- get/set cache-bypass size threshold */
429 #define PSetClientContext 99 /* Special pioctl to setup caller's creds */
430 int afs_nobody = NFS_NOBODY;
433 HandleIoctl(register struct vcache *avc, register afs_int32 acom,
434 struct afs_ioctl *adata)
436 register afs_int32 code;
439 AFS_STATCNT(HandleIoctl);
441 switch (acom & 0xff) {
443 avc->f.states |= CSafeStore;
445 /* SXW - Should we force a MetaData flush for this flag setting */
448 /* case 2 used to be abort store, but this is no longer provided,
449 * since it is impossible to implement under normal Unix.
453 /* return the name of the cell this file is open on */
454 register struct cell *tcell;
455 register afs_int32 i;
457 tcell = afs_GetCell(avc->f.fid.Cell, READ_LOCK);
459 i = strlen(tcell->cellName) + 1; /* bytes to copy out */
461 if (i > adata->out_size) {
462 /* 0 means we're not interested in the output */
463 if (adata->out_size != 0)
467 AFS_COPYOUT(tcell->cellName, adata->out, i, code);
469 afs_PutCell(tcell, READ_LOCK);
475 case 49: /* VIOC_GETINITPARAMS */
476 if (adata->out_size < sizeof(struct cm_initparams)) {
479 AFS_COPYOUT(&cm_initParams, adata->out,
480 sizeof(struct cm_initparams), code);
492 return code; /* so far, none implemented */
496 /* For aix we don't temporarily bypass ioctl(2) but rather do our
497 * thing directly in the vnode layer call, VNOP_IOCTL; thus afs_ioctl
498 * is now called from afs_gn_ioctl.
501 afs_ioctl(struct vcache *tvc, int cmd, int arg)
503 struct afs_ioctl data;
506 AFS_STATCNT(afs_ioctl);
507 if (((cmd >> 8) & 0xff) == 'V') {
508 /* This is a VICEIOCTL call */
509 AFS_COPYIN(arg, (caddr_t) & data, sizeof(data), error);
512 error = HandleIoctl(tvc, cmd, &data);
515 /* No-op call; just return. */
519 # if defined(AFS_AIX32_ENV)
520 # if defined(AFS_AIX51_ENV)
523 kioctl(int fdes, int com, caddr_t arg, caddr_t ext, caddr_t arg2,
525 # else /* __64BIT__ */
527 kioctl32(int fdes, int com, caddr_t arg, caddr_t ext, caddr_t arg2,
529 # endif /* __64BIT__ */
532 kioctl(int fdes, int com, caddr_t arg, caddr_t ext)
533 # endif /* AFS_AIX51_ENV */
538 # ifdef AFS_AIX51_ENV
541 } u_uap, *uap = &u_uap;
543 register struct vcache *tvc;
544 register int ioctlDone = 0, code = 0;
546 AFS_STATCNT(afs_xioctl);
550 # ifdef AFS_AIX51_ENV
554 if (setuerror(getf(uap->fd, &fd))) {
557 if (fd->f_type == DTYPE_VNODE) {
558 /* good, this is a vnode; next see if it is an AFS vnode */
559 tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */
560 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
561 /* This is an AFS vnode */
562 if (((uap->com >> 8) & 0xff) == 'V') {
563 register struct afs_ioctl *datap;
566 (struct afs_ioctl *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
567 code=copyin_afs_ioctl((char *)uap->arg, datap);
569 osi_FreeSmallSpace(datap);
571 # if defined(AFS_AIX41_ENV)
574 return (setuerror(code), code);
576 code = HandleIoctl(tvc, uap->com, datap);
577 osi_FreeSmallSpace(datap);
580 # if defined(AFS_AIX41_ENV)
587 # if defined(AFS_AIX41_ENV)
589 # if defined(AFS_AIX51_ENV)
591 code = okioctl(fdes, com, arg, ext, arg2, arg3);
592 # else /* __64BIT__ */
593 code = okioctl32(fdes, com, arg, ext, arg2, arg3);
594 # endif /* __64BIT__ */
595 # else /* !AFS_AIX51_ENV */
596 code = okioctl(fdes, com, arg, ext);
597 # endif /* AFS_AIX51_ENV */
599 # elif defined(AFS_AIX32_ENV)
600 okioctl(fdes, com, arg, ext);
603 # if defined(KERNEL_HAVE_UERROR)
606 # if !defined(AFS_AIX41_ENV)
607 return (getuerror()? -1 : u.u_ioctlrv);
609 return getuerror()? -1 : 0;
616 #elif defined(AFS_SGI_ENV)
617 # if defined(AFS_SGI65_ENV)
618 afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
619 rval_t * rvalp, struct vopbd * vbds)
621 afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
622 rval_t * rvalp, struct vopbd * vbds)
625 struct afs_ioctl data;
631 AFS_STATCNT(afs_ioctl);
632 if (((cmd >> 8) & 0xff) == 'V') {
633 /* This is a VICEIOCTL call */
634 error = copyin_afs_ioctl(arg, &data);
637 locked = ISAFS_GLOCK();
640 error = HandleIoctl(tvc, cmd, &data);
645 /* No-op call; just return. */
649 #elif defined(AFS_SUN5_ENV)
650 struct afs_ioctl_sys {
657 afs_xioctl(struct afs_ioctl_sys *uap, rval_t *rvp)
660 register struct vcache *tvc;
661 register int ioctlDone = 0, code = 0;
663 AFS_STATCNT(afs_xioctl);
664 # if defined(AFS_SUN57_ENV)
668 # elif defined(AFS_SUN54_ENV)
673 if (code = getf(uap->fd, &fd)) {
677 if (fd->f_vnode->v_type == VREG || fd->f_vnode->v_type == VDIR) {
678 tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */
679 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
680 /* This is an AFS vnode */
681 if (((uap->com >> 8) & 0xff) == 'V') {
682 register struct afs_ioctl *datap;
685 (struct afs_ioctl *)osi_AllocSmallSpace(AFS_SMALLOCSIZ);
686 code=copyin_afs_ioctl((char *)uap->arg, datap);
688 osi_FreeSmallSpace(datap);
690 # if defined(AFS_SUN54_ENV)
697 code = HandleIoctl(tvc, uap->com, datap);
698 osi_FreeSmallSpace(datap);
704 # if defined(AFS_SUN57_ENV)
706 # elif defined(AFS_SUN54_ENV)
712 code = ioctl(uap, rvp);
716 #elif defined(AFS_LINUX22_ENV)
717 struct afs_ioctl_sys {
722 afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
725 struct afs_ioctl_sys ua, *uap = &ua;
726 register struct vcache *tvc;
727 register int ioctlDone = 0, code = 0;
729 AFS_STATCNT(afs_xioctl);
734 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
735 /* This is an AFS vnode */
736 if (((uap->com >> 8) & 0xff) == 'V') {
737 register struct afs_ioctl *datap;
739 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
740 code = copyin_afs_ioctl((char *)uap->arg, datap);
742 osi_FreeSmallSpace(datap);
746 code = HandleIoctl(tvc, uap->com, datap);
747 osi_FreeSmallSpace(datap);
756 #elif defined(AFS_DARWIN_ENV) && !defined(AFS_DARWIN80_ENV)
764 afs_xioctl(afs_proc_t *p, register struct ioctl_args *uap, register_t *retval)
767 register struct vcache *tvc;
768 register int ioctlDone = 0, code = 0;
770 AFS_STATCNT(afs_xioctl);
771 if ((code = fdgetf(p, uap->fd, &fd)))
773 if (fd->f_type == DTYPE_VNODE) {
774 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
775 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
776 /* This is an AFS vnode */
777 if (((uap->com >> 8) & 0xff) == 'V') {
778 register struct afs_ioctl *datap;
780 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
781 code = copyin_afs_ioctl((char *)uap->arg, datap);
783 osi_FreeSmallSpace(datap);
787 code = HandleIoctl(tvc, uap->com, datap);
788 osi_FreeSmallSpace(datap);
796 return ioctl(p, uap, retval);
800 #elif defined(AFS_XBSD_ENV)
801 # if defined(AFS_FBSD_ENV)
804 afs_xioctl(struct thread *td, register struct ioctl_args *uap,
807 afs_proc_t *p = td->td_proc;
816 afs_xioctl(afs_proc_t *p, register struct ioctl_args *uap, register_t *retval)
819 register struct filedesc *fdp;
820 register struct vcache *tvc;
821 register int ioctlDone = 0, code = 0;
824 AFS_STATCNT(afs_xioctl);
825 # if defined(AFS_NBSD40_ENV)
826 fdp = p->l_proc->p_fd;
830 if ((u_int) uap->fd >= fdp->fd_nfiles
831 || (fd = fdp->fd_ofiles[uap->fd]) == NULL)
833 if ((fd->f_flag & (FREAD | FWRITE)) == 0)
835 /* first determine whether this is any sort of vnode */
836 if (fd->f_type == DTYPE_VNODE) {
837 /* good, this is a vnode; next see if it is an AFS vnode */
838 # if defined(AFS_OBSD_ENV)
840 IsAfsVnode((struct vnode *)fd->
841 f_data) ? VTOAFS((struct vnode *)fd->f_data) : NULL;
843 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
845 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
846 /* This is an AFS vnode */
847 if (((uap->com >> 8) & 0xff) == 'V') {
848 register struct afs_ioctl *datap;
850 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
851 code = copyin_afs_ioctl((char *)uap->arg, datap);
853 osi_FreeSmallSpace(datap);
857 code = HandleIoctl(tvc, uap->com, datap);
858 osi_FreeSmallSpace(datap);
866 # if defined(AFS_FBSD_ENV)
867 return ioctl(td, uap);
868 # elif defined(AFS_OBSD_ENV)
869 code = sys_ioctl(p, uap, retval);
870 # elif defined(AFS_NBSD_ENV)
871 struct lwp *l = osi_curproc();
872 code = sys_ioctl(l, uap, retval);
878 #elif defined(UKERNEL)
886 } *uap = (struct a *)get_user_struct()->u_ap;
887 register struct file *fd;
888 register struct vcache *tvc;
889 register int ioctlDone = 0, code = 0;
891 AFS_STATCNT(afs_xioctl);
896 /* first determine whether this is any sort of vnode */
897 if (fd->f_type == DTYPE_VNODE) {
898 /* good, this is a vnode; next see if it is an AFS vnode */
899 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
900 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
901 /* This is an AFS vnode */
902 if (((uap->com >> 8) & 0xff) == 'V') {
903 register struct afs_ioctl *datap;
905 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
906 code=copyin_afs_ioctl((char *)uap->arg, datap);
908 osi_FreeSmallSpace(datap);
911 return (setuerror(code), code);
913 code = HandleIoctl(tvc, uap->com, datap);
914 osi_FreeSmallSpace(datap);
927 #endif /* AFS_HPUX102_ENV */
929 #if defined(AFS_SGI_ENV)
930 /* "pioctl" system call entry point; just pass argument to the parameterized
939 afs_pioctl(struct pioctlargs *uap, rval_t * rvp)
943 AFS_STATCNT(afs_pioctl);
945 code = afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow);
947 # ifdef AFS_SGI64_ENV
954 #elif defined(AFS_FBSD_ENV)
956 afs_pioctl(struct thread *td, void *args, int *retval)
963 } *uap = (struct a *)args;
965 AFS_STATCNT(afs_pioctl);
966 return (afs_syscall_pioctl
967 (uap->path, uap->cmd, uap->cmarg, uap->follow, td->td_ucred));
970 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
972 afs_pioctl(afs_proc_t *p, void *args, int *retval)
979 } *uap = (struct a *)args;
981 AFS_STATCNT(afs_pioctl);
982 # if defined(AFS_DARWIN80_ENV) || defined(AFS_NBSD40_ENV)
983 return (afs_syscall_pioctl
984 (uap->path, uap->cmd, uap->cmarg, uap->follow,
987 return (afs_syscall_pioctl
988 (uap->path, uap->cmd, uap->cmarg, uap->follow,
989 # if defined(AFS_FBSD_ENV)
992 p->p_cred->pc_ucred));
999 /* macro to avoid adding any more #ifdef's to pioctl code. */
1000 #if defined(AFS_LINUX22_ENV) || defined(AFS_AIX41_ENV)
1001 #define PIOCTL_FREE_CRED() crfree(credp)
1003 #define PIOCTL_FREE_CRED()
1008 afs_syscall_pioctl(char *path, unsigned int com, caddr_t cmarg, int follow,
1009 rval_t *vvp, afs_ucred_t *credp)
1011 #ifdef AFS_DARWIN100_ENV
1012 afs_syscall64_pioctl(user_addr_t path, unsigned int com, user_addr_t cmarg,
1013 int follow, afs_ucred_t *credp)
1014 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1015 afs_syscall_pioctl(char *path, unsigned int com, caddr_t cmarg, int follow,
1018 afs_syscall_pioctl(char *path, unsigned int com, caddr_t cmarg, int follow)
1022 struct afs_ioctl data;
1023 #ifdef AFS_NEED_CLIENTCONTEXT
1024 afs_ucred_t *tmpcred = NULL;
1026 #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)
1027 afs_ucred_t *foreigncreds = NULL;
1029 register afs_int32 code = 0;
1030 struct vnode *vp = NULL;
1031 #ifdef AFS_AIX41_ENV
1032 struct ucred *credp = crref(); /* don't free until done! */
1034 #ifdef AFS_LINUX22_ENV
1035 cred_t *credp = crref(); /* don't free until done! */
1039 AFS_STATCNT(afs_syscall_pioctl);
1041 follow = 1; /* compat. with old venus */
1042 code = copyin_afs_ioctl(cmarg, &data);
1045 #if defined(KERNEL_HAVE_UERROR)
1050 if ((com & 0xff) == PSetClientContext) {
1051 #ifdef AFS_NEED_CLIENTCONTEXT
1052 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV)
1053 code = HandleClientContext(&data, &com, &foreigncreds, credp);
1055 code = HandleClientContext(&data, &com, &foreigncreds, osi_curcred());
1059 crfree(foreigncreds);
1062 #if defined(KERNEL_HAVE_UERROR)
1063 return (setuerror(code), code);
1068 #else /* AFS_NEED_CLIENTCONTEXT */
1070 #endif /* AFS_NEED_CLIENTCONTEXT */
1072 #ifdef AFS_NEED_CLIENTCONTEXT
1075 * We could have done without temporary setting the u.u_cred below
1076 * (foreigncreds could be passed as param the pioctl modules)
1077 * but calls such as afs_osi_suser() doesn't allow that since it
1078 * references u.u_cred directly. We could, of course, do something
1079 * like afs_osi_suser(cred) which, I think, is better since it
1080 * generalizes and supports multi cred environments...
1082 #if defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
1084 credp = foreigncreds;
1085 #elif defined(AFS_AIX41_ENV)
1086 tmpcred = crref(); /* XXX */
1087 crset(foreigncreds);
1088 #elif defined(AFS_HPUX101_ENV)
1089 tmpcred = p_cred(u.u_procp);
1090 set_p_cred(u.u_procp, foreigncreds);
1091 #elif defined(AFS_SGI_ENV)
1092 tmpcred = OSI_GET_CURRENT_CRED();
1093 OSI_SET_CURRENT_CRED(foreigncreds);
1096 u.u_cred = foreigncreds;
1099 #endif /* AFS_NEED_CLIENTCONTEXT */
1100 if ((com & 0xff) == 15) {
1101 /* special case prefetch so entire pathname eval occurs in helper process.
1102 * otherwise, the pioctl call is essentially useless */
1103 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1105 Prefetch(path, &data, follow,
1106 foreigncreds ? foreigncreds : credp);
1108 code = Prefetch(path, &data, follow, osi_curcred());
1111 #if defined(KERNEL_HAVE_UERROR)
1118 #ifdef AFS_AIX41_ENV
1120 lookupname(path, USR, follow, NULL, &vp,
1121 foreigncreds ? foreigncreds : credp);
1123 #ifdef AFS_LINUX22_ENV
1124 code = gop_lookupname_user(path, AFS_UIOUSER, follow, &dp);
1126 vp = (struct vnode *)dp->d_inode;
1128 code = gop_lookupname_user(path, AFS_UIOUSER, follow, &vp);
1129 #if defined(AFS_FBSD80_ENV) /* XXX check on 7x */
1132 #endif /* AFS_FBSD80_ENV */
1133 #endif /* AFS_LINUX22_ENV */
1134 #endif /* AFS_AIX41_ENV */
1138 #if defined(KERNEL_HAVE_UERROR)
1146 #if defined(AFS_SUN510_ENV)
1147 if (vp && !IsAfsVnode(vp)) {
1148 struct vnode *realvp;
1150 #ifdef AFS_SUN511_ENV
1151 (VOP_REALVP(vp, &realvp, NULL) == 0)
1153 (VOP_REALVP(vp, &realvp) == 0)
1156 struct vnode *oldvp = vp;
1164 /* now make the call if we were passed no file, or were passed an AFS file */
1165 if (!vp || IsAfsVnode(vp)) {
1166 #if defined(AFS_SUN5_ENV)
1167 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1168 #elif defined(AFS_AIX41_ENV)
1170 struct ucred *cred1, *cred2;
1173 cred1 = cred2 = foreigncreds;
1175 cred1 = cred2 = credp;
1177 code = afs_HandlePioctl(vp, com, &data, follow, &cred1);
1178 if (cred1 != cred2) {
1179 /* something changed the creds */
1183 #elif defined(AFS_HPUX101_ENV)
1185 struct ucred *cred = p_cred(u.u_procp);
1186 code = afs_HandlePioctl(vp, com, &data, follow, &cred);
1188 #elif defined(AFS_SGI_ENV)
1191 credp = OSI_GET_CURRENT_CRED();
1192 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1194 #elif defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1195 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1196 #elif defined(UKERNEL)
1197 code = afs_HandlePioctl(vp, com, &data, follow,
1198 &(get_user_struct()->u_cred));
1200 code = afs_HandlePioctl(vp, com, &data, follow, &u.u_cred);
1203 #if defined(KERNEL_HAVE_UERROR)
1206 code = EINVAL; /* not in /afs */
1211 #if defined(AFS_NEED_CLIENTCONTEXT)
1213 #ifdef AFS_AIX41_ENV
1214 crset(tmpcred); /* restore original credentials */
1216 #if defined(AFS_HPUX101_ENV)
1217 set_p_cred(u.u_procp, tmpcred); /* restore original credentials */
1218 #elif defined(AFS_SGI_ENV)
1219 OSI_SET_CURRENT_CRED(tmpcred); /* restore original credentials */
1220 #elif defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
1221 credp = tmpcred; /* restore original credentials */
1223 osi_curcred() = tmpcred; /* restore original credentials */
1224 #endif /* AFS_HPUX101_ENV */
1225 crfree(foreigncreds);
1228 #endif /* AFS_NEED_CLIENTCONTEXT */
1230 #ifdef AFS_LINUX22_ENV
1233 #if defined(AFS_FBSD80_ENV)
1234 if (VOP_ISLOCKED(vp))
1236 #endif /* AFS_FBSD80_ENV */
1237 AFS_RELE(vp); /* put vnode back */
1241 #if defined(KERNEL_HAVE_UERROR)
1244 return (getuerror());
1250 #ifdef AFS_DARWIN100_ENV
1252 afs_syscall_pioctl(char * path, unsigned int com, caddr_t cmarg,
1253 int follow, afs_ucred_t *credp)
1255 return afs_syscall64_pioctl(CAST_USER_ADDR_T(path), com,
1256 CAST_USER_ADDR_T((unsigned int)cmarg), follow,
1261 #define MAXPIOCTLTOKENLEN \
1262 (3*sizeof(afs_int32)+MAXKTCTICKETLEN+sizeof(struct ClearToken)+MAXKTCREALMLEN)
1265 afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
1266 register struct afs_ioctl *ablob, int afollow,
1267 afs_ucred_t **acred)
1270 struct vrequest treq;
1271 register afs_int32 code;
1272 register afs_int32 function, device;
1273 struct afs_pdata input, output;
1274 struct afs_pdata copyInput, copyOutput;
1276 pioctlFunction *pioctlSw;
1278 struct afs_fakestat_state fakestate;
1280 memset(&input, 0, sizeof(input));
1281 memset(&output, 0, sizeof(output));
1283 avc = avp ? VTOAFS(avp) : NULL;
1284 afs_Trace3(afs_iclSetp, CM_TRACE_PIOCTL, ICL_TYPE_INT32, acom & 0xff,
1285 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, afollow);
1286 AFS_STATCNT(HandlePioctl);
1288 code = afs_InitReq(&treq, *acred);
1292 afs_InitFakeStat(&fakestate);
1294 code = afs_EvalFakeStat(&avc, &fakestate, &treq);
1298 device = (acom & 0xff00) >> 8;
1300 case 'V': /* Original pioctls */
1301 pioctlSw = VpioctlSw;
1302 pioctlSwSize = sizeof(VpioctlSw);
1304 case 'C': /* Coordinated/common pioctls */
1305 pioctlSw = CpioctlSw;
1306 pioctlSwSize = sizeof(CpioctlSw);
1308 case 'O': /* Coordinated/common pioctls */
1309 pioctlSw = OpioctlSw;
1310 pioctlSwSize = sizeof(OpioctlSw);
1316 function = acom & 0xff;
1317 if (function >= (pioctlSwSize / sizeof(char *))) {
1322 /* Do all range checking before continuing */
1323 if (ablob->in_size > MAXPIOCTLTOKENLEN ||
1324 ablob->in_size < 0 || ablob->out_size < 0) {
1329 code = afs_pd_alloc(&input, ablob->in_size);
1333 if (ablob->in_size > 0) {
1334 AFS_COPYIN(ablob->in, input.ptr, ablob->in_size, code);
1335 input.ptr[input.remaining] = '\0';
1340 if (function == 8 && device == 'V') { /* PGetTokens */
1341 code = afs_pd_alloc(&output, MAXPIOCTLTOKENLEN);
1343 code = afs_pd_alloc(&output, AFS_LRALLOCSIZ);
1349 copyOutput = output;
1352 (*pioctlSw[function]) (avc, function, &treq, ©Input,
1353 ©Output, acred);
1355 outSize = copyOutput.ptr - output.ptr;
1357 if (code == 0 && ablob->out_size > 0) {
1358 if (outSize > ablob->out_size) {
1359 code = E2BIG; /* data wont fit in user buffer */
1360 } else if (outSize) {
1361 AFS_COPYOUT(output.ptr, ablob->out, outSize, code);
1366 afs_pd_free(&input);
1367 afs_pd_free(&output);
1369 afs_PutFakeStat(&fakestate);
1370 return afs_CheckCode(code, &treq, 41);
1374 * VIOCGETFID (22) - Get file ID quickly
1378 * \param[in] ain not in use
1379 * \param[out] aout fid of requested file
1381 * \retval EINVAL Error if some of the initial arguments aren't set
1383 * \post get the file id of some file
1385 DECL_PIOCTL(PGetFID)
1387 AFS_STATCNT(PGetFID);
1390 if (afs_pd_putBytes(aout, &avc->f.fid, sizeof(struct VenusFid)) != 0)
1396 * VIOCSETAL (1) - Set access control list
1400 * \param[in] ain the ACL being set
1401 * \param[out] aout the ACL being set returned
1403 * \retval EINVAL Error if some of the standard args aren't set
1405 * \post Changed ACL, via direct writing to the wire
1408 dummy_PSetAcl(char *ain, char *aout)
1413 DECL_PIOCTL(PSetAcl)
1415 register afs_int32 code;
1416 struct afs_conn *tconn;
1417 struct AFSOpaque acl;
1418 struct AFSVolSync tsync;
1419 struct AFSFetchStatus OutStatus;
1422 AFS_STATCNT(PSetAcl);
1426 if (afs_pd_getStringPtr(ain, &acl.AFSOpaque_val) != 0)
1428 acl.AFSOpaque_len = strlen(acl.AFSOpaque_val) + 1;
1429 if (acl.AFSOpaque_len > 1024)
1433 tconn = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
1435 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREACL);
1438 RXAFS_StoreACL(tconn->id, (struct AFSFid *)&avc->f.fid.Fid,
1439 &acl, &OutStatus, &tsync);
1444 } while (afs_Analyze
1445 (tconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_STOREACL,
1446 SHARED_LOCK, NULL));
1448 /* now we've forgotten all of the access info */
1449 ObtainWriteLock(&afs_xcbhash, 455);
1451 afs_DequeueCallback(avc);
1452 avc->f.states &= ~(CStatd | CUnique);
1453 ReleaseWriteLock(&afs_xcbhash);
1454 if (avc->f.fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
1455 osi_dnlc_purgedp(avc);
1457 /* SXW - Should we flush metadata here? */
1461 int afs_defaultAsynchrony = 0;
1464 * VIOC_STOREBEHIND (47) Adjust store asynchrony
1468 * \param[in] ain sbstruct (store behind structure) input
1469 * \param[out] aout resulting sbstruct
1472 * Error if the user doesn't have super-user credentials
1474 * Error if there isn't enough access to not check the mode bits
1477 * Changes either the default asynchrony (the amount of data that
1478 * can remain to be written when the cache manager returns control
1479 * to the user), or the asyncrony for the specified file.
1481 DECL_PIOCTL(PStoreBehind)
1483 struct sbstruct sbr;
1485 if (afs_pd_getBytes(ain, &sbr, sizeof(struct sbstruct)) != 0)
1488 if (sbr.sb_default != -1) {
1489 if (afs_osi_suser(*acred))
1490 afs_defaultAsynchrony = sbr.sb_default;
1495 if (avc && (sbr.sb_thisfile != -1)) {
1497 (avc, PRSFS_WRITE | PRSFS_ADMINISTER, areq, DONT_CHECK_MODE_BITS))
1498 avc->asynchrony = sbr.sb_thisfile;
1503 memset(&sbr, 0, sizeof(sbr));
1504 sbr.sb_default = afs_defaultAsynchrony;
1506 sbr.sb_thisfile = avc->asynchrony;
1509 return afs_pd_putBytes(aout, &sbr, sizeof(sbr));
1513 * VIOC_GCPAGS (48) - Disable automatic PAG gc'ing
1517 * \param[in] ain not in use
1518 * \param[out] aout not in use
1520 * \retval EACCES Error if the user doesn't have super-user credentials
1522 * \post set the gcpags to GCPAGS_USERDISABLED
1524 DECL_PIOCTL(PGCPAGs)
1526 if (!afs_osi_suser(*acred)) {
1529 afs_gcpags = AFS_GCPAGS_USERDISABLED;
1534 * VIOCGETAL (2) - Get access control list
1538 * \param[in] ain not in use
1539 * \param[out] aout the ACL
1541 * \retval EINVAL Error if some of the standard args aren't set
1542 * \retval ERANGE Error if the vnode of the file id is too large
1543 * \retval -1 Error if getting the ACL failed
1545 * \post Obtain the ACL, based on file ID
1548 * There is a hack to tell which type of ACL is being returned, checks
1549 * the top 2-bytes of the input size to judge what type of ACL it is,
1550 * only for dfs xlator ACLs
1552 DECL_PIOCTL(PGetAcl)
1554 struct AFSOpaque acl;
1555 struct AFSVolSync tsync;
1556 struct AFSFetchStatus OutStatus;
1558 struct afs_conn *tconn;
1562 AFS_STATCNT(PGetAcl);
1565 Fid.Volume = avc->f.fid.Fid.Volume;
1566 Fid.Vnode = avc->f.fid.Fid.Vnode;
1567 Fid.Unique = avc->f.fid.Fid.Unique;
1568 if (avc->f.states & CForeign) {
1570 * For a dfs xlator acl we have a special hack so that the
1571 * xlator will distinguish which type of acl will return. So
1572 * we currently use the top 2-bytes (vals 0-4) to tell which
1573 * type of acl to bring back. Horrible hack but this will
1574 * cause the least number of changes to code size and interfaces.
1576 if (Fid.Vnode & 0xc0000000)
1578 Fid.Vnode |= (ain->remaining << 30);
1580 acl.AFSOpaque_val = aout->ptr;
1582 tconn = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
1584 acl.AFSOpaque_val[0] = '\0';
1585 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHACL);
1587 code = RXAFS_FetchACL(tconn->id, &Fid, &acl, &OutStatus, &tsync);
1592 } while (afs_Analyze
1593 (tconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_FETCHACL,
1594 SHARED_LOCK, NULL));
1597 if (acl.AFSOpaque_len == 0)
1598 afs_pd_skip(aout, 1); /* leave the NULL */
1600 afs_pd_skip(aout, acl.AFSOpaque_len); /* Length of the ACL */
1606 * PNoop returns success. Used for functions which are not implemented
1607 * or are no longer in use.
1611 * \retval Always returns success
1614 * Functions involved in this:
1615 * 17 (VIOCENGROUP) -- used to be enable group;
1616 * 18 (VIOCDISGROUP) -- used to be disable group;
1617 * 2 (?) -- get/set cache-bypass size threshold
1626 * PBogus returns fail. Used for functions which are not implemented or
1627 * are no longer in use.
1631 * \retval EINVAL Always returns this value
1634 * Functions involved in this:
1640 * 13 (VIOCGETTIME) -- used to be quick check time;
1641 * 15 (VIOCPREFETCH) -- prefetch is now special-cased; see pioctl code!;
1642 * 16 (VIOCNOP) -- used to be testing code;
1643 * 19 (VIOCLISTGROUPS) -- used to be list group;
1644 * 23 (VIOCWAITFOREVER) -- used to be waitforever;
1645 * 57 (VIOC_FPRIOSTATUS) -- arla: set file prio;
1646 * 58 (VIOC_FHGET) -- arla: fallback getfh;
1647 * 59 (VIOC_FHOPEN) -- arla: fallback fhopen;
1648 * 60 (VIOC_XFSDEBUG) -- arla: controls xfsdebug;
1649 * 61 (VIOC_ARLADEBUG) -- arla: controls arla debug;
1650 * 62 (VIOC_AVIATOR) -- arla: debug interface;
1651 * 63 (VIOC_XFSDEBUG_PRINT) -- arla: print xfs status;
1652 * 64 (VIOC_CALCULATE_CACHE) -- arla: force cache check;
1653 * 65 (VIOC_BREAKCELLBACK) -- arla: break callback;
1654 * 68 (?) -- arla: fetch stats;
1658 AFS_STATCNT(PBogus);
1663 * VIOC_FILE_CELL_NAME (30) - Get cell in which file lives
1667 * \param[in] ain not in use (avc used to pass in file id)
1668 * \param[out] aout cell name
1670 * \retval EINVAL Error if some of the standard args aren't set
1671 * \retval ESRCH Error if the file isn't part of a cell
1673 * \post Get a cell based on a passed in file id
1675 DECL_PIOCTL(PGetFileCell)
1677 register struct cell *tcell;
1679 AFS_STATCNT(PGetFileCell);
1682 tcell = afs_GetCell(avc->f.fid.Cell, READ_LOCK);
1686 if (afs_pd_putString(aout, tcell->cellName) != 0)
1689 afs_PutCell(tcell, READ_LOCK);
1694 * VIOC_GET_WS_CELL (31) - Get cell in which workstation lives
1698 * \param[in] ain not in use
1699 * \param[out] aout cell name
1702 * Error if the afs daemon hasn't started yet
1704 * Error if the machine isn't part of a cell, for whatever reason
1706 * \post Get the primary cell that the machine is a part of.
1708 DECL_PIOCTL(PGetWSCell)
1710 struct cell *tcell = NULL;
1712 AFS_STATCNT(PGetWSCell);
1713 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1714 return EIO; /* Inappropriate ioctl for device */
1716 tcell = afs_GetPrimaryCell(READ_LOCK);
1717 if (!tcell) /* no primary cell? */
1720 if (afs_pd_putString(aout, tcell->cellName) != 0)
1722 afs_PutCell(tcell, READ_LOCK);
1727 * VIOC_GET_PRIMARY_CELL (33) - Get primary cell for caller
1731 * \param[in] ain not in use (user id found via areq)
1732 * \param[out] aout cell name
1735 * Error if the user id doesn't have a primary cell specified
1737 * \post Get the primary cell for a certain user, based on the user's uid
1739 DECL_PIOCTL(PGetUserCell)
1741 register afs_int32 i;
1742 register struct unixuser *tu;
1743 register struct cell *tcell;
1745 AFS_STATCNT(PGetUserCell);
1746 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1747 return EIO; /* Inappropriate ioctl for device */
1749 /* return the cell name of the primary cell for this user */
1750 i = UHash(areq->uid);
1751 ObtainWriteLock(&afs_xuser, 224);
1752 for (tu = afs_users[i]; tu; tu = tu->next) {
1753 if (tu->uid == areq->uid && (tu->states & UPrimary)) {
1755 ReleaseWriteLock(&afs_xuser);
1760 tcell = afs_GetCell(tu->cell, READ_LOCK);
1761 afs_PutUser(tu, WRITE_LOCK);
1765 if (afs_pd_putString(aout, tcell->cellName) != 0)
1767 afs_PutCell(tcell, READ_LOCK);
1770 ReleaseWriteLock(&afs_xuser);
1776 * VIOCSETTOK (3) - Set authentication tokens
1780 * \param[in] ain the krb tickets from which to set the afs tokens
1781 * \param[out] aout not in use
1784 * Error if the ticket is either too long or too short
1786 * Error if the AFS initState is below 101
1788 * Error if the cell for which the Token is being set can't be found
1791 * Set the Tokens for a specific cell name, unless there is none set,
1792 * then default to primary
1795 DECL_PIOCTL(PSetTokens)
1798 register struct unixuser *tu;
1799 struct ClearToken clear;
1800 register struct cell *tcell;
1804 struct vrequest treq;
1805 afs_int32 flag, set_parent_pag = 0;
1807 AFS_STATCNT(PSetTokens);
1808 if (!afs_resourceinit_flag) {
1812 if (afs_pd_getInt(ain, &stLen) != 0)
1815 stp = afs_pd_where(ain); /* remember where the ticket is */
1816 if (stLen < 0 || stLen > MAXKTCTICKETLEN)
1817 return EINVAL; /* malloc may fail */
1818 if (afs_pd_skip(ain, stLen) != 0)
1821 if (afs_pd_getInt(ain, &i) != 0)
1823 if (i != sizeof(struct ClearToken))
1826 if (afs_pd_getBytes(ain, &clear, sizeof(struct ClearToken)) !=0)
1829 if (clear.AuthHandle == -1)
1830 clear.AuthHandle = 999; /* more rxvab compat stuff */
1832 if (afs_pd_remaining(ain) != 0) {
1833 /* still stuff left? we've got primary flag and cell name.
1836 if (afs_pd_getInt(ain, &flag) != 0)
1839 /* some versions of gcc appear to need != 0 in order to get this
1841 if ((flag & 0x8000) != 0) { /* XXX Use Constant XXX */
1846 if (afs_pd_getStringPtr(ain, &cellName) != 0)
1849 /* rest is cell name, look it up */
1850 tcell = afs_GetCellByName(cellName, READ_LOCK);
1854 /* default to primary cell, primary id */
1855 flag = 1; /* primary id */
1856 tcell = afs_GetPrimaryCell(READ_LOCK);
1861 afs_PutCell(tcell, READ_LOCK);
1862 if (set_parent_pag) {
1864 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1866 osi_procname(procname, 256);
1867 afs_warnuser("Process %d (%s) tried to change pags in PSetTokens\n",
1868 MyPidxx2Pid(MyPidxx), procname);
1869 if (!setpag(osi_curproc(), acred, -1, &pag, 1)) {
1871 if (!setpag(acred, -1, &pag, 1)) {
1873 afs_InitReq(&treq, *acred);
1877 /* now we just set the tokens */
1878 tu = afs_GetUser(areq->uid, i, WRITE_LOCK); /* i has the cell # */
1879 tu->vid = clear.ViceId;
1880 if (tu->stp != NULL) {
1881 afs_osi_Free(tu->stp, tu->stLen);
1883 tu->stp = (char *)afs_osi_Alloc(stLen);
1884 if (tu->stp == NULL) {
1888 memcpy(tu->stp, stp, stLen);
1891 afs_stats_cmfullperf.authent.TicketUpdates++;
1892 afs_ComputePAGStats();
1893 #endif /* AFS_NOSTATS */
1894 tu->states |= UHasTokens;
1895 tu->states &= ~UTokensBad;
1896 afs_SetPrimary(tu, flag);
1897 tu->tokenTime = osi_Time();
1898 afs_ResetUserConns(tu);
1899 afs_NotifyUser(tu, UTokensObtained);
1900 afs_PutUser(tu, WRITE_LOCK);
1916 * VIOCGETVOLSTAT (4) - Get volume status
1920 * \param[in] ain not in use
1921 * \param[out] aout status of the volume
1923 * \retval EINVAL Error if some of the standard args aren't set
1926 * The status of a volume (based on the FID of the volume), or an
1927 * offline message /motd
1929 DECL_PIOCTL(PGetVolumeStatus)
1932 char *offLineMsg = afs_osi_Alloc(256);
1933 char *motd = afs_osi_Alloc(256);
1934 register struct afs_conn *tc;
1935 register afs_int32 code = 0;
1936 struct AFSFetchVolumeStatus volstat;
1940 AFS_STATCNT(PGetVolumeStatus);
1947 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
1949 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS);
1952 RXAFS_GetVolumeStatus(tc->id, avc->f.fid.Fid.Volume, &volstat,
1953 &Name, &offLineMsg, &motd);
1958 } while (afs_Analyze
1959 (tc, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS,
1960 SHARED_LOCK, NULL));
1964 /* Copy all this junk into msg->im_data, keeping track of the lengths. */
1965 if (afs_pd_putBytes(aout, &volstat, sizeof(VolumeStatus)) != 0)
1967 if (afs_pd_putString(aout, volName) != 0)
1969 if (afs_pd_putString(aout, offLineMsg) != 0)
1971 if (afs_pd_putString(aout, motd) != 0)
1974 afs_osi_Free(offLineMsg, 256);
1975 afs_osi_Free(motd, 256);
1980 * VIOCSETVOLSTAT (5) - Set volume status
1985 * values to set the status at, offline message, message of the day,
1986 * volume name, minimum quota, maximum quota
1988 * status of a volume, offlines messages, minimum quota, maximumm quota
1991 * Error if some of the standard args aren't set
1993 * Error if the volume is read only, or a backup volume
1995 * Error if the volume can't be accessed
1997 * Error if the volume name, offline message, and motd are too big
2000 * Set the status of a volume, including any offline messages,
2001 * a minimum quota, and a maximum quota
2003 DECL_PIOCTL(PSetVolumeStatus)
2008 register struct afs_conn *tc;
2009 register afs_int32 code = 0;
2010 struct AFSFetchVolumeStatus volstat;
2011 struct AFSStoreVolumeStatus storeStat;
2012 register struct volume *tvp;
2015 AFS_STATCNT(PSetVolumeStatus);
2019 tvp = afs_GetVolume(&avc->f.fid, areq, READ_LOCK);
2021 if (tvp->states & (VRO | VBackup)) {
2022 afs_PutVolume(tvp, READ_LOCK);
2025 afs_PutVolume(tvp, READ_LOCK);
2030 if (afs_pd_getBytes(ain, &volstat, sizeof(AFSFetchVolumeStatus)) != 0)
2033 if (afs_pd_getStringPtr(ain, &volName) != 0)
2035 if (strlen(volName) > 32)
2038 if (afs_pd_getStringPtr(ain, &offLineMsg) != 0)
2040 if (strlen(offLineMsg) > 256)
2043 if (afs_pd_getStringPtr(ain, &motd) != 0)
2045 if (strlen(motd) > 256)
2048 /* Done reading ... */
2051 if (volstat.MinQuota != -1) {
2052 storeStat.MinQuota = volstat.MinQuota;
2053 storeStat.Mask |= AFS_SETMINQUOTA;
2055 if (volstat.MaxQuota != -1) {
2056 storeStat.MaxQuota = volstat.MaxQuota;
2057 storeStat.Mask |= AFS_SETMAXQUOTA;
2060 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
2062 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS);
2065 RXAFS_SetVolumeStatus(tc->id, avc->f.fid.Fid.Volume, &storeStat,
2066 volName, offLineMsg, motd);
2071 } while (afs_Analyze
2072 (tc, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS,
2073 SHARED_LOCK, NULL));
2077 /* we are sending parms back to make compat. with prev system. should
2078 * change interface later to not ask for current status, just set new
2081 if (afs_pd_putBytes(aout, &volstat, sizeof(VolumeStatus)) != 0)
2083 if (afs_pd_putString(aout, volName) != 0)
2085 if (afs_pd_putString(aout, offLineMsg) != 0)
2087 if (afs_pd_putString(aout, motd) != 0)
2094 * VIOCFLUSH (6) - Invalidate cache entry
2098 * \param[in] ain not in use
2099 * \param[out] aout not in use
2101 * \retval EINVAL Error if some of the standard args aren't set
2103 * \post Flush any information the cache manager has on an entry
2107 AFS_STATCNT(PFlush);
2110 #ifdef AFS_BOZONLOCK_ENV
2111 afs_BozonLock(&avc->pvnLock, avc); /* Since afs_TryToSmush will do a pvn_vptrunc */
2113 ObtainWriteLock(&avc->lock, 225);
2114 afs_ResetVCache(avc, *acred);
2115 ReleaseWriteLock(&avc->lock);
2116 #ifdef AFS_BOZONLOCK_ENV
2117 afs_BozonUnlock(&avc->pvnLock, avc);
2123 * VIOC_AFS_STAT_MT_PT (29) - Stat mount point
2128 * the last component in a path, related to mountpoint that we're
2129 * looking for information about
2131 * volume, cell, link data
2133 * \retval EINVAL Error if some of the standard args aren't set
2134 * \retval ENOTDIR Error if the 'mount point' argument isn't a directory
2135 * \retval EIO Error if the link data can't be accessed
2137 * \post Get the volume, and cell, as well as the link data for a mount point
2139 DECL_PIOCTL(PNewStatMount)
2141 register afs_int32 code;
2142 register struct vcache *tvc;
2143 register struct dcache *tdc;
2144 struct VenusFid tfid;
2147 struct sysname_info sysState;
2148 afs_size_t offset, len;
2150 AFS_STATCNT(PNewStatMount);
2154 if (afs_pd_getStringPtr(ain, &name) != 0)
2157 code = afs_VerifyVCache(avc, areq);
2160 if (vType(avc) != VDIR) {
2163 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
2166 Check_AtSys(avc, name, &sysState, areq);
2167 ObtainReadLock(&tdc->lock);
2169 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
2170 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
2171 ReleaseReadLock(&tdc->lock);
2172 afs_PutDCache(tdc); /* we're done with the data */
2173 bufp = sysState.name;
2177 tfid.Cell = avc->f.fid.Cell;
2178 tfid.Fid.Volume = avc->f.fid.Fid.Volume;
2179 if (!tfid.Fid.Unique && (avc->f.states & CForeign)) {
2180 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
2182 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
2188 if (tvc->mvstat != 1) {
2193 ObtainWriteLock(&tvc->lock, 226);
2194 code = afs_HandleLink(tvc, areq);
2196 if (tvc->linkData) {
2197 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
2200 /* we have the data */
2201 if (afs_pd_putString(aout, tvc->linkData) != 0)
2207 ReleaseWriteLock(&tvc->lock);
2210 if (sysState.allocked)
2211 osi_FreeLargeSpace(bufp);
2216 * VIOCGETTOK (8) - Get authentication tokens
2220 * \param[in] ain cellid to return tokens for
2221 * \param[out] aout token
2224 * Error if the afs daemon hasn't started yet
2226 * Error if the input parameter is out of the bounds of the available
2229 * Error if there aren't tokens for this cell
2232 * If the input paramater exists, get the token that corresponds to
2233 * the parameter value, if there is no token at this value, get the
2234 * token for the first cell
2236 * \notes "it's a weird interface (from comments in the code)"
2239 DECL_PIOCTL(PGetTokens)
2241 register struct cell *tcell;
2242 register afs_int32 i;
2243 register struct unixuser *tu;
2244 afs_int32 iterator = 0;
2248 AFS_STATCNT(PGetTokens);
2249 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2250 return EIO; /* Inappropriate ioctl for device */
2252 /* weird interface. If input parameter is present, it is an integer and
2253 * we're supposed to return the parm'th tokens for this unix uid.
2254 * If not present, we just return tokens for cell 1.
2255 * If counter out of bounds, return EDOM.
2256 * If no tokens for the particular cell, return ENOTCONN.
2257 * Also, if this mysterious parm is present, we return, along with the
2258 * tokens, the primary cell indicator (an afs_int32 0) and the cell name
2259 * at the end, in that order.
2261 newStyle = (afs_pd_remaining(ain) > 0);
2263 if (afs_pd_getInt(ain, &iterator) != 0)
2266 i = UHash(areq->uid);
2267 ObtainReadLock(&afs_xuser);
2268 for (tu = afs_users[i]; tu; tu = tu->next) {
2270 if (tu->uid == areq->uid && (tu->states & UHasTokens)) {
2271 if (iterator-- == 0)
2272 break; /* are we done yet? */
2275 if (tu->uid == areq->uid && afs_IsPrimaryCellNum(tu->cell))
2281 * No need to hold a read lock on each user entry
2285 ReleaseReadLock(&afs_xuser);
2290 if (((tu->states & UHasTokens) == 0)
2291 || (tu->ct.EndTimestamp < osi_Time())) {
2292 tu->states |= (UTokensBad | UNeedsReset);
2293 afs_NotifyUser(tu, UTokensDropped);
2294 afs_PutUser(tu, READ_LOCK);
2297 iterator = tu->stLen; /* for compat, we try to return 56 byte tix if they fit */
2299 iterator = 56; /* # of bytes we're returning */
2301 if (afs_pd_putInt(aout, iterator) != 0)
2303 if (afs_pd_putBytes(aout, tu->stp, tu->stLen) != 0)
2305 if (tu->stLen < 56) {
2306 /* Tokens are always 56 bytes or larger */
2307 if (afs_pd_skip(aout, iterator - tu->stLen) != 0) {
2312 if (afs_pd_putInt(aout, sizeof(struct ClearToken)) != 0)
2314 if (afs_pd_putBytes(aout, &tu->ct, sizeof(struct ClearToken)) != 0)
2318 /* put out primary id and cell name, too */
2319 iterator = (tu->states & UPrimary ? 1 : 0);
2320 if (afs_pd_putInt(aout, iterator) != 0)
2322 tcell = afs_GetCell(tu->cell, READ_LOCK);
2324 if (afs_pd_putString(aout, tcell->cellName) != 0)
2326 afs_PutCell(tcell, READ_LOCK);
2328 if (afs_pd_putString(aout, "") != 0)
2331 /* Got here, all is good */
2334 afs_PutUser(tu, READ_LOCK);
2339 * VIOCUNLOG (9) - Invalidate tokens
2343 * \param[in] ain not in use
2344 * \param[out] aout not in use
2346 * \retval EIO Error if the afs daemon hasn't been started yet
2348 * \post remove tokens from a user, specified by the user id
2350 * \notes sets the token's time to 0, which then causes it to be removed
2351 * \notes Unlog is the same as un-pag in OpenAFS
2355 register afs_int32 i;
2356 register struct unixuser *tu;
2358 AFS_STATCNT(PUnlog);
2359 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2360 return EIO; /* Inappropriate ioctl for device */
2362 i = UHash(areq->uid);
2363 ObtainWriteLock(&afs_xuser, 227);
2364 for (tu = afs_users[i]; tu; tu = tu->next) {
2365 if (tu->uid == areq->uid) {
2367 tu->states &= ~UHasTokens;
2368 /* security is not having to say you're sorry */
2369 memset(&tu->ct, 0, sizeof(struct ClearToken));
2371 ReleaseWriteLock(&afs_xuser);
2372 afs_NotifyUser(tu, UTokensDropped);
2373 /* We have to drop the lock over the call to afs_ResetUserConns,
2374 * since it obtains the afs_xvcache lock. We could also keep
2375 * the lock, and modify ResetUserConns to take parm saying we
2376 * obtained the lock already, but that is overkill. By keeping
2377 * the "tu" pointer held over the released lock, we guarantee
2378 * that we won't lose our place, and that we'll pass over
2379 * every user conn that existed when we began this call.
2381 afs_ResetUserConns(tu);
2383 ObtainWriteLock(&afs_xuser, 228);
2385 /* set the expire times to 0, causes
2386 * afs_GCUserData to remove this entry
2388 tu->ct.EndTimestamp = 0;
2390 #endif /* UKERNEL */
2393 ReleaseWriteLock(&afs_xuser);
2398 * VIOC_AFS_MARINER_HOST (32) - Get/set mariner (cache manager monitor) host
2402 * \param[in] ain host address to be set
2403 * \param[out] aout old host address
2406 * depending on whether or not a variable is set, either get the host
2407 * for the cache manager monitor, or set the old address and give it
2410 * \notes Errors turn off mariner
2412 DECL_PIOCTL(PMariner)
2414 afs_int32 newHostAddr;
2415 afs_int32 oldHostAddr;
2417 AFS_STATCNT(PMariner);
2419 memcpy((char *)&oldHostAddr, (char *)&afs_marinerHost,
2422 oldHostAddr = 0xffffffff; /* disabled */
2424 if (afs_pd_getInt(ain, &newHostAddr) != 0)
2427 if (newHostAddr == 0xffffffff) {
2428 /* disable mariner operations */
2430 } else if (newHostAddr) {
2432 afs_marinerHost = newHostAddr;
2435 if (afs_pd_putInt(aout, oldHostAddr) != 0)
2442 * VIOCCKSERV (10) - Check that servers are up
2446 * \param[in] ain name of the cell
2447 * \param[out] aout current down server list
2449 * \retval EIO Error if the afs daemon hasn't started yet
2450 * \retval EACCES Error if the user doesn't have super-user credentials
2451 * \retval ENOENT Error if we are unable to obtain the cell
2454 * Either a fast check (where it doesn't contact servers) or a
2455 * local check (checks local cell only)
2457 DECL_PIOCTL(PCheckServers)
2460 register struct server *ts;
2462 char *cellName = NULL;
2464 struct chservinfo *pcheck;
2466 AFS_STATCNT(PCheckServers);
2468 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2469 return EIO; /* Inappropriate ioctl for device */
2471 /* This is tricky, because we need to peak at the datastream to see
2472 * what we're getting. For now, let's cheat. */
2474 /* ain contains either an int32 or a string */
2475 if (ain->remaining == 0)
2478 if (*(afs_int32 *)ain->ptr == 0x12345678) { /* For afs3.3 version */
2479 pcheck = afs_pd_inline(ain, sizeof(*pcheck));
2483 if (pcheck->tinterval >= 0) {
2484 if (afs_pd_putInt(aout, afs_probe_interval) != 0)
2486 if (pcheck->tinterval > 0) {
2487 if (!afs_osi_suser(*acred))
2489 afs_probe_interval = pcheck->tinterval;
2493 temp = pcheck->tflags;
2495 cellName = pcheck->tbuffer;
2496 } else { /* For pre afs3.3 versions */
2497 if (afs_pd_getInt(ain, &temp) != 0)
2499 if (afs_pd_remaining(ain) > 0) {
2500 if (afs_pd_getStringPtr(ain, &cellName) != 0)
2506 * 1: fast check, don't contact servers.
2507 * 2: local cell only.
2510 /* have cell name, too */
2511 cellp = afs_GetCellByName(cellName, READ_LOCK);
2516 if (!cellp && (temp & 2)) {
2517 /* use local cell */
2518 cellp = afs_GetPrimaryCell(READ_LOCK);
2520 if (!(temp & 1)) { /* if not fast, call server checker routine */
2521 afs_CheckServers(1, cellp); /* check down servers */
2522 afs_CheckServers(0, cellp); /* check up servers */
2524 /* now return the current down server list */
2525 ObtainReadLock(&afs_xserver);
2526 for (i = 0; i < NSERVERS; i++) {
2527 for (ts = afs_servers[i]; ts; ts = ts->next) {
2528 if (cellp && ts->cell != cellp)
2529 continue; /* cell spec'd and wrong */
2530 if ((ts->flags & SRVR_ISDOWN)
2531 && ts->addr->sa_portal != ts->cell->vlport) {
2532 afs_pd_putInt(aout, ts->addr->sa_ip);
2536 ReleaseReadLock(&afs_xserver);
2538 afs_PutCell(cellp, READ_LOCK);
2543 * VIOCCKBACK (11) - Check backup volume mappings
2547 * \param[in] ain not in use
2548 * \param[out] aout not in use
2550 * \retval EIO Error if the afs daemon hasn't started yet
2553 * Check the root volume, and then check the names if the volume
2554 * check variable is set to force, has expired, is busy, or if
2555 * the mount points variable is set
2557 DECL_PIOCTL(PCheckVolNames)
2559 AFS_STATCNT(PCheckVolNames);
2560 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2561 return EIO; /* Inappropriate ioctl for device */
2563 afs_CheckRootVolume();
2564 afs_CheckVolumeNames(AFS_VOLCHECK_FORCE | AFS_VOLCHECK_EXPIRED |
2565 AFS_VOLCHECK_BUSY | AFS_VOLCHECK_MTPTS);
2570 * VIOCCKCONN (12) - Check connections for a user
2574 * \param[in] ain not in use
2575 * \param[out] aout not in use
2578 * Error if no user is specififed, the user has no tokens set,
2579 * or if the user's tokens are bad
2582 * check to see if a user has the correct authentication.
2583 * If so, allow access.
2585 * \notes Check the connections to all the servers specified
2587 DECL_PIOCTL(PCheckAuth)
2591 struct afs_conn *tc;
2592 struct unixuser *tu;
2595 AFS_STATCNT(PCheckAuth);
2596 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2597 return EIO; /* Inappropriate ioctl for device */
2600 tu = afs_GetUser(areq->uid, 1, READ_LOCK); /* check local cell authentication */
2604 /* we have a user */
2605 ObtainReadLock(&afs_xsrvAddr);
2606 ObtainReadLock(&afs_xconn);
2608 /* any tokens set? */
2609 if ((tu->states & UHasTokens) == 0)
2611 /* all connections in cell 1 working? */
2612 for (i = 0; i < NSERVERS; i++) {
2613 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2614 for (tc = sa->conns; tc; tc = tc->next) {
2615 if (tc->user == tu && (tu->states & UTokensBad))
2620 ReleaseReadLock(&afs_xsrvAddr);
2621 ReleaseReadLock(&afs_xconn);
2622 afs_PutUser(tu, READ_LOCK);
2624 if (afs_pd_putInt(aout, retValue) != 0)
2630 Prefetch(uparmtype apath, struct afs_ioctl *adata, int afollow,
2634 register afs_int32 code;
2635 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN57_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2641 AFS_STATCNT(Prefetch);
2644 tp = osi_AllocLargeSpace(1024);
2645 AFS_COPYINSTR(apath, tp, 1024, &bufferSize, code);
2647 osi_FreeLargeSpace(tp);
2650 if (afs_BBusy()) { /* do this as late as possible */
2651 osi_FreeLargeSpace(tp);
2652 return EWOULDBLOCK; /* pretty close */
2654 afs_BQueue(BOP_PATH, (struct vcache *)0, 0, 0, acred, (afs_size_t) 0,
2655 (afs_size_t) 0, tp, (void *)0, (void *)0);
2660 * VIOCWHEREIS (14) - Find out where a volume is located
2664 * \param[in] ain not in use
2665 * \param[out] aout volume location
2667 * \retval EINVAL Error if some of the default arguments don't exist
2668 * \retval ENODEV Error if there is no such volume
2670 * \post fine a volume, based on a volume file id
2672 * \notes check each of the servers specified
2674 DECL_PIOCTL(PFindVolume)
2676 register struct volume *tvp;
2677 register struct server *ts;
2678 register afs_int32 i;
2681 AFS_STATCNT(PFindVolume);
2684 tvp = afs_GetVolume(&avc->f.fid, areq, READ_LOCK);
2688 for (i = 0; i < AFS_MAXHOSTS; i++) {
2689 ts = tvp->serverHost[i];
2692 if (afs_pd_putInt(aout, ts->addr->sa_ip) != 0) {
2697 if (i < AFS_MAXHOSTS) {
2698 /* still room for terminating NULL, add it on */
2699 if (afs_pd_putInt(aout, 0) != 0) {
2705 afs_PutVolume(tvp, READ_LOCK);
2710 * VIOCACCESS (20) - Access using PRS_FS bits
2714 * \param[in] ain PRS_FS bits
2715 * \param[out] aout not in use
2717 * \retval EINVAL Error if some of the initial arguments aren't set
2718 * \retval EACCES Error if access is denied
2720 * \post check to make sure access is allowed
2722 DECL_PIOCTL(PViceAccess)
2724 register afs_int32 code;
2727 AFS_STATCNT(PViceAccess);
2731 code = afs_VerifyVCache(avc, areq);
2735 if (afs_pd_getInt(ain, &temp) != 0)
2738 code = afs_AccessOK(avc, temp, areq, CHECK_MODE_BITS);
2746 * VIOC_GETPAG (13) - Get PAG value
2750 * \param[in] ain not in use
2751 * \param[out] aout PAG value or NOPAG
2753 * \post get PAG value for the caller's cred
2755 DECL_PIOCTL(PGetPAG)
2759 pag = PagInCred(*acred);
2761 return afs_pd_putInt(aout, pag);
2764 DECL_PIOCTL(PPrecache)
2768 /*AFS_STATCNT(PPrecache);*/
2769 if (!afs_osi_suser(*acred))
2772 if (afs_pd_getInt(ain, &newValue) != 0)
2775 afs_preCache = newValue*1024;
2780 * VIOCSETCACHESIZE (24) - Set venus cache size in 1000 units
2784 * \param[in] ain the size the venus cache should be set to
2785 * \param[out] aout not in use
2787 * \retval EACCES Error if the user doesn't have super-user credentials
2788 * \retval EROFS Error if the cache is set to be in memory
2791 * Set the cache size based on user input. If no size is given,
2792 * set it to the default OpenAFS cache size.
2795 * recompute the general cache parameters for every single block allocated
2797 DECL_PIOCTL(PSetCacheSize)
2802 AFS_STATCNT(PSetCacheSize);
2804 if (!afs_osi_suser(*acred))
2806 /* too many things are setup initially in mem cache version */
2807 if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
2809 if (afs_pd_getInt(ain, &newValue) != 0)
2812 afs_cacheBlocks = afs_stats_cmperf.cacheBlocksOrig;
2814 if (newValue < afs_min_cache)
2815 afs_cacheBlocks = afs_min_cache;
2817 afs_cacheBlocks = newValue;
2819 afs_stats_cmperf.cacheBlocksTotal = afs_cacheBlocks;
2820 afs_ComputeCacheParms(); /* recompute basic cache parameters */
2821 afs_MaybeWakeupTruncateDaemon();
2822 while (waitcnt++ < 100 && afs_cacheBlocks < afs_blocksUsed) {
2823 afs_osi_Wait(1000, 0, 0);
2824 afs_MaybeWakeupTruncateDaemon();
2829 #define MAXGCSTATS 16
2831 * VIOCGETCACHEPARMS (40) - Get cache stats
2835 * \param[in] ain afs index flags
2836 * \param[out] aout cache blocks, blocks used, blocks files (in an array)
2838 * \post Get the cache blocks, and how many of the cache blocks there are
2840 DECL_PIOCTL(PGetCacheSize)
2842 afs_int32 results[MAXGCSTATS];
2844 register struct dcache * tdc;
2847 AFS_STATCNT(PGetCacheSize);
2849 if (afs_pd_remaining(ain) == sizeof(afs_int32)) {
2850 afs_pd_getInt(ain, &flags); /* can't error, we just checked size */
2851 } else if (afs_pd_remaining(ain) == 0) {
2857 memset(results, 0, sizeof(results));
2858 results[0] = afs_cacheBlocks;
2859 results[1] = afs_blocksUsed;
2860 results[2] = afs_cacheFiles;
2863 for (i = 0; i < afs_cacheFiles; i++) {
2864 if (afs_indexFlags[i] & IFFree) results[3]++;
2866 } else if (2 == flags){
2867 for (i = 0; i < afs_cacheFiles; i++) {
2868 if (afs_indexFlags[i] & IFFree) results[3]++;
2869 if (afs_indexFlags[i] & IFEverUsed) results[4]++;
2870 if (afs_indexFlags[i] & IFDataMod) results[5]++;
2871 if (afs_indexFlags[i] & IFDirtyPages) results[6]++;
2872 if (afs_indexFlags[i] & IFAnyPages) results[7]++;
2873 if (afs_indexFlags[i] & IFDiscarded) results[8]++;
2875 tdc = afs_indexTable[i];
2878 size = tdc->validPos;
2879 if ( 0 < size && size < (1<<12) ) results[10]++;
2880 else if (size < (1<<14) ) results[11]++;
2881 else if (size < (1<<16) ) results[12]++;
2882 else if (size < (1<<18) ) results[13]++;
2883 else if (size < (1<<20) ) results[14]++;
2884 else if (size >= (1<<20) ) results[15]++;
2888 return afs_pd_putBytes(aout, results, sizeof(results));
2892 * VIOCFLUSHCB (25) - Flush callback only
2896 * \param[in] ain not in use
2897 * \param[out] aout not in use
2899 * \retval EINVAL Error if some of the standard args aren't set
2900 * \retval 0 0 returned if the volume is set to read-only
2903 * Flushes callbacks, by setting the length of callbacks to one,
2904 * setting the next callback to be sent to the CB_DROPPED value,
2905 * and then dequeues everything else.
2907 DECL_PIOCTL(PRemoveCallBack)
2909 register struct afs_conn *tc;
2910 register afs_int32 code = 0;
2911 struct AFSCallBack CallBacks_Array[1];
2912 struct AFSCBFids theFids;
2913 struct AFSCBs theCBs;
2916 AFS_STATCNT(PRemoveCallBack);
2919 if (avc->f.states & CRO)
2920 return 0; /* read-only-ness can't change */
2921 ObtainWriteLock(&avc->lock, 229);
2922 theFids.AFSCBFids_len = 1;
2923 theCBs.AFSCBs_len = 1;
2924 theFids.AFSCBFids_val = (struct AFSFid *)&avc->f.fid.Fid;
2925 theCBs.AFSCBs_val = CallBacks_Array;
2926 CallBacks_Array[0].CallBackType = CB_DROPPED;
2927 if (avc->callback) {
2929 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
2931 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
2933 code = RXAFS_GiveUpCallBacks(tc->id, &theFids, &theCBs);
2937 /* don't set code on failure since we wouldn't use it */
2938 } while (afs_Analyze
2939 (tc, code, &avc->f.fid, areq,
2940 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK, NULL));
2942 ObtainWriteLock(&afs_xcbhash, 457);
2943 afs_DequeueCallback(avc);
2945 avc->f.states &= ~(CStatd | CUnique);
2946 ReleaseWriteLock(&afs_xcbhash);
2947 if (avc->f.fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
2948 osi_dnlc_purgedp(avc);
2950 ReleaseWriteLock(&avc->lock);
2955 * VIOCNEWCELL (26) - Configure new cell
2960 * the name of the cell, the hosts that will be a part of the cell,
2961 * whether or not it's linked with another cell, the other cell it's
2962 * linked with, the file server port, and the volume server port
2966 * \retval EIO Error if the afs daemon hasn't started yet
2967 * \retval EACCES Error if the user doesn't have super-user cedentials
2968 * \retval EINVAL Error if some 'magic' var doesn't have a certain bit set
2970 * \post creates a new cell
2972 DECL_PIOCTL(PNewCell)
2974 afs_int32 cellHosts[AFS_MAXCELLHOSTS], magic = 0;
2975 char *newcell = NULL;
2976 char *linkedcell = NULL;
2978 afs_int32 linkedstate = 0;
2979 afs_int32 fsport = 0, vlport = 0;
2982 AFS_STATCNT(PNewCell);
2983 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2984 return EIO; /* Inappropriate ioctl for device */
2986 if (!afs_osi_suser(*acred))
2989 if (afs_pd_getInt(ain, &magic) != 0)
2991 if (magic != 0x12345678)
2994 /* A 3.4 fs newcell command will pass an array of AFS_MAXCELLHOSTS
2995 * server addresses while the 3.5 fs newcell command passes
2996 * AFS_MAXHOSTS. To figure out which is which, check if the cellname
2999 * This whole logic is bogus, because it relies on the newer command
3000 * sending its 12th address as 0.
3002 if ((afs_pd_remaining(ain) < AFS_MAXCELLHOSTS +3) * sizeof(afs_int32))
3005 newcell = afs_pd_where(ain) + (AFS_MAXCELLHOSTS + 3) * sizeof(afs_int32);
3006 if (newcell[0] != '\0') {
3009 skip = AFS_MAXHOSTS - AFS_MAXCELLHOSTS;
3012 /* AFS_MAXCELLHOSTS (=8) is less than AFS_MAXHOSTS (=13) */
3013 if (afs_pd_getBytes(ain, &cellHosts,
3014 AFS_MAXCELLHOSTS * sizeof(afs_int32)) != 0)
3016 if (afs_pd_skip(ain, skip * sizeof(afs_int32)) !=0)
3019 if (afs_pd_getInt(ain, &fsport) != 0)
3022 fsport = 0; /* Privileged ports not allowed */
3024 if (afs_pd_getInt(ain, &vlport) != 0)
3027 vlport = 0; /* Privileged ports not allowed */
3029 if (afs_pd_getInt(ain, &ls) != 0)
3032 if (afs_pd_getStringPtr(ain, &newcell) != 0)
3036 if (afs_pd_getStringPtr(ain, &linkedcell) != 0)
3038 linkedstate |= CLinkedCell;
3041 linkedstate |= CNoSUID; /* setuid is disabled by default for fs newcell */
3043 afs_NewCell(newcell, cellHosts, linkedstate, linkedcell, fsport,
3048 DECL_PIOCTL(PNewAlias)
3050 /* create a new cell alias */
3051 char *realName, *aliasName;
3053 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3054 return EIO; /* Inappropriate ioctl for device */
3056 if (!afs_osi_suser(*acred))
3059 if (afs_pd_getStringPtr(ain, &aliasName) != 0)
3061 if (afs_pd_getStringPtr(ain, &realName) != 0)
3064 return afs_NewCellAlias(aliasName, realName);
3068 * VIOCGETCELL (27) - Get cell info
3072 * \param[in] ain The cell index of a specific cell
3073 * \param[out] aout list of servers in the cell
3075 * \retval EIO Error if the afs daemon hasn't started yet
3076 * \retval EDOM Error if there is no cell asked about
3078 * \post Lists the cell's server names and and addresses
3080 DECL_PIOCTL(PListCells)
3082 afs_int32 whichCell;
3083 register struct cell *tcell = 0;
3084 register afs_int32 i;
3087 AFS_STATCNT(PListCells);
3088 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3089 return EIO; /* Inappropriate ioctl for device */
3091 if (afs_pd_getInt(ain, &whichCell) != 0)
3094 tcell = afs_GetCellByIndex(whichCell, READ_LOCK);
3100 for (i = 0; i < AFS_MAXCELLHOSTS; i++) {
3101 if (tcell->cellHosts[i] == 0)
3103 if (afs_pd_putInt(aout, tcell->cellHosts[i]->addr->sa_ip) != 0)
3106 for (;i < AFS_MAXCELLHOSTS; i++) {
3107 if (afs_pd_putInt(aout, 0) != 0)
3110 if (afs_pd_putString(aout, tcell->cellName) != 0)
3115 afs_PutCell(tcell, READ_LOCK);
3119 DECL_PIOCTL(PListAliases)
3121 afs_int32 whichAlias;
3122 register struct cell_alias *tcalias = 0;
3125 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3126 return EIO; /* Inappropriate ioctl for device */
3128 if (afs_pd_getInt(ain, &whichAlias) != 0)
3131 tcalias = afs_GetCellAlias(whichAlias);
3132 if (tcalias == NULL)
3136 if (afs_pd_putString(aout, tcalias->alias) != 0)
3138 if (afs_pd_putString(aout, tcalias->cell) != 0)
3143 afs_PutCellAlias(tcalias);
3148 * VIOC_AFS_DELETE_MT_PT (28) - Delete mount point
3152 * \param[in] ain the name of the file in this dir to remove
3153 * \param[out] aout not in use
3156 * Error if some of the standard args aren't set
3158 * Error if the argument to remove is not a directory
3160 * Error if there is no cache to remove the mount point from or
3161 * if a vcache doesn't exist
3164 * Ensure that everything is OK before deleting the mountpoint.
3165 * If not, don't delete. Delete a mount point based on a file id.
3167 DECL_PIOCTL(PRemoveMount)
3169 register afs_int32 code;
3172 struct sysname_info sysState;
3173 afs_size_t offset, len;
3174 register struct afs_conn *tc;
3175 register struct dcache *tdc;
3176 register struct vcache *tvc;
3177 struct AFSFetchStatus OutDirStatus;
3178 struct VenusFid tfid;
3179 struct AFSVolSync tsync;
3182 /* "ain" is the name of the file in this dir to remove */
3184 AFS_STATCNT(PRemoveMount);
3187 if (afs_pd_getStringPtr(ain, &name) != 0)
3190 code = afs_VerifyVCache(avc, areq);
3193 if (vType(avc) != VDIR)
3196 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1); /* test for error below */
3199 Check_AtSys(avc, name, &sysState, areq);
3200 ObtainReadLock(&tdc->lock);
3202 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
3203 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
3204 ReleaseReadLock(&tdc->lock);
3205 bufp = sysState.name;
3210 tfid.Cell = avc->f.fid.Cell;
3211 tfid.Fid.Volume = avc->f.fid.Fid.Volume;
3212 if (!tfid.Fid.Unique && (avc->f.states & CForeign)) {
3213 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
3215 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3222 if (tvc->mvstat != 1) {
3228 ObtainWriteLock(&tvc->lock, 230);
3229 code = afs_HandleLink(tvc, areq);
3231 if (tvc->linkData) {
3232 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
3237 ReleaseWriteLock(&tvc->lock);
3238 osi_dnlc_purgedp(tvc);
3244 ObtainWriteLock(&avc->lock, 231);
3245 osi_dnlc_remove(avc, bufp, tvc);
3247 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
3249 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE);
3252 RXAFS_RemoveFile(tc->id, (struct AFSFid *)&avc->f.fid.Fid, bufp,
3253 &OutDirStatus, &tsync);
3258 } while (afs_Analyze
3259 (tc, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_REMOVEFILE,
3260 SHARED_LOCK, NULL));
3265 ReleaseWriteLock(&avc->lock);
3269 /* we have the thing in the cache */
3270 ObtainWriteLock(&tdc->lock, 661);
3271 if (afs_LocalHero(avc, tdc, &OutDirStatus, 1)) {
3272 /* we can do it locally */
3273 code = afs_dir_Delete(tdc, bufp);
3275 ZapDCE(tdc); /* surprise error -- invalid value */
3279 ReleaseWriteLock(&tdc->lock);
3280 afs_PutDCache(tdc); /* drop ref count */
3282 avc->f.states &= ~CUnique; /* For the dfs xlator */
3283 ReleaseWriteLock(&avc->lock);
3286 if (sysState.allocked)
3287 osi_FreeLargeSpace(bufp);
3292 * VIOC_GETCELLSTATUS (35) - Get cell status info
3296 * \param[in] ain The cell you want status information on
3297 * \param[out] aout cell state (as a struct)
3299 * \retval EIO Error if the afs daemon hasn't started yet
3300 * \retval ENOENT Error if the cell doesn't exist
3302 * \post Returns the state of the cell as defined in a struct cell
3304 DECL_PIOCTL(PGetCellStatus)
3306 register struct cell *tcell;
3310 AFS_STATCNT(PGetCellStatus);
3311 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3312 return EIO; /* Inappropriate ioctl for device */
3314 if (afs_pd_getStringPtr(ain, &cellName) != 0)
3317 tcell = afs_GetCellByName(cellName, READ_LOCK);
3320 temp = tcell->states;
3321 afs_PutCell(tcell, READ_LOCK);
3323 return afs_pd_putInt(aout, temp);
3327 * VIOC_SETCELLSTATUS (36) - Set corresponding info
3332 * The cell you want to set information about, and the values you
3337 * \retval EIO Error if the afs daemon hasn't started yet
3338 * \retval EACCES Error if the user doesn't have super-user credentials
3341 * Set the state of the cell in a defined struct cell, based on
3342 * whether or not SetUID is allowed
3344 DECL_PIOCTL(PSetCellStatus)
3346 register struct cell *tcell;
3348 afs_int32 flags0, flags1;
3350 if (!afs_osi_suser(*acred))
3352 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3353 return EIO; /* Inappropriate ioctl for device */
3355 if (afs_pd_getInt(ain, &flags0) != 0)
3357 if (afs_pd_getInt(ain, &flags1) != 0)
3359 if (afs_pd_getStringPtr(ain, &cellName) != 0)
3362 tcell = afs_GetCellByName(cellName, WRITE_LOCK);
3365 if (flags0 & CNoSUID)
3366 tcell->states |= CNoSUID;
3368 tcell->states &= ~CNoSUID;
3369 afs_PutCell(tcell, WRITE_LOCK);
3374 * VIOC_FLUSHVOLUME (37) - Flush whole volume's data
3378 * \param[in] ain not in use (args in avc)
3379 * \param[out] aout not in use
3381 * \retval EINVAL Error if some of the standard args aren't set
3382 * \retval EIO Error if the afs daemon hasn't started yet
3385 * Flush all cached contents of a volume. Exactly what stays and what
3386 * goes depends on the platform.
3389 * Does not flush a file that a user has open and is using, because
3390 * it will be re-created on next write. Also purges the dnlc,
3391 * because things are screwed up.
3393 DECL_PIOCTL(PFlushVolumeData)
3395 register afs_int32 i;
3396 register struct dcache *tdc;
3397 register struct vcache *tvc;
3398 register struct volume *tv;
3399 afs_int32 cell, volume;
3400 struct afs_q *tq, *uq;
3401 #ifdef AFS_DARWIN80_ENV
3405 AFS_STATCNT(PFlushVolumeData);
3408 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3409 return EIO; /* Inappropriate ioctl for device */
3411 volume = avc->f.fid.Fid.Volume; /* who to zap */
3412 cell = avc->f.fid.Cell;
3415 * Clear stat'd flag from all vnodes from this volume; this will
3416 * invalidate all the vcaches associated with the volume.
3419 ObtainReadLock(&afs_xvcache);
3420 i = VCHashV(&avc->f.fid);
3421 for (tq = afs_vhashTV[i].prev; tq != &afs_vhashTV[i]; tq = uq) {
3424 if (tvc->f.fid.Fid.Volume == volume && tvc->f.fid.Cell == cell) {
3425 if (tvc->f.states & CVInit) {
3426 ReleaseReadLock(&afs_xvcache);
3427 afs_osi_Sleep(&tvc->f.states);
3430 #ifdef AFS_DARWIN80_ENV
3431 if (tvc->f.states & CDeadVnode) {
3432 if (!(tvc->f.states & CBulkFetching)) {
3433 ReleaseReadLock(&afs_xvcache);
3434 afs_osi_Sleep(&tvc->f.states);
3439 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
3440 VN_HOLD(AFSTOV(tvc));
3441 #elif defined(AFS_DARWIN80_ENV)
3445 if (vnode_ref(vp)) {
3451 if (tvc->f.states & (CBulkFetching|CDeadVnode)) {
3453 vnode_recycle(AFSTOV(tvc));
3459 ReleaseReadLock(&afs_xvcache);
3460 #ifdef AFS_BOZONLOCK_ENV
3461 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
3463 ObtainWriteLock(&tvc->lock, 232);
3465 ObtainWriteLock(&afs_xcbhash, 458);
3466 afs_DequeueCallback(tvc);
3467 tvc->f.states &= ~(CStatd | CDirty);
3468 ReleaseWriteLock(&afs_xcbhash);
3469 if (tvc->f.fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
3470 osi_dnlc_purgedp(tvc);
3471 afs_TryToSmush(tvc, *acred, 1);
3472 ReleaseWriteLock(&tvc->lock);
3473 #ifdef AFS_BOZONLOCK_ENV
3474 afs_BozonUnlock(&tvc->pvnLock, tvc);
3476 #ifdef AFS_DARWIN80_ENV
3477 vnode_put(AFSTOV(tvc));
3479 ObtainReadLock(&afs_xvcache);
3481 /* our tvc ptr is still good until now */
3485 ReleaseReadLock(&afs_xvcache);
3488 ObtainWriteLock(&afs_xdcache, 328); /* needed to flush any stuff */
3489 for (i = 0; i < afs_cacheFiles; i++) {
3490 if (!(afs_indexFlags[i] & IFEverUsed))
3491 continue; /* never had any data */
3492 tdc = afs_GetDSlot(i, NULL);
3493 if (tdc->refCount <= 1) { /* too high, in use by running sys call */
3494 ReleaseReadLock(&tdc->tlock);
3495 if (tdc->f.fid.Fid.Volume == volume && tdc->f.fid.Cell == cell) {
3496 if (!(afs_indexFlags[i] & IFDataMod)) {
3497 /* if the file is modified, but has a ref cnt of only 1,
3498 * then someone probably has the file open and is writing
3499 * into it. Better to skip flushing such a file, it will be
3500 * brought back immediately on the next write anyway.
3502 * If we *must* flush, then this code has to be rearranged
3503 * to call afs_storeAllSegments() first */
3504 afs_FlushDCache(tdc);
3508 ReleaseReadLock(&tdc->tlock);
3510 afs_PutDCache(tdc); /* bumped by getdslot */
3512 ReleaseWriteLock(&afs_xdcache);
3514 ObtainReadLock(&afs_xvolume);
3515 for (i = 0; i < NVOLS; i++) {
3516 for (tv = afs_volumes[i]; tv; tv = tv->next) {
3517 if (tv->volume == volume) {
3518 afs_ResetVolumeInfo(tv);
3523 ReleaseReadLock(&afs_xvolume);
3525 /* probably, a user is doing this, probably, because things are screwed up.
3526 * maybe it's the dnlc's fault? */
3533 * VIOCGETVCXSTATUS (41) - gets vnode x status
3538 * not in use (avc used)
3540 * vcxstat: the file id, the data version, any lock, the parent vnode,
3541 * the parent unique id, the trunc position, the callback, cbExpires,
3542 * what access is being made, what files are open,
3543 * any users executing/writing, the flock count, the states,
3547 * Error if some of the initial default arguments aren't set
3549 * Error if access to check the mode bits is denied
3552 * gets stats for the vnode, a struct listed in vcxstat
3554 DECL_PIOCTL(PGetVnodeXStatus)
3556 register afs_int32 code;
3557 struct vcxstat stat;
3560 /* AFS_STATCNT(PGetVnodeXStatus); */
3563 code = afs_VerifyVCache(avc, areq);
3566 if (vType(avc) == VDIR)
3567 mode = PRSFS_LOOKUP;
3570 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
3573 memset(&stat, 0, sizeof(struct vcxstat));
3574 stat.fid = avc->f.fid;
3575 hset32(stat.DataVersion, hgetlo(avc->f.m.DataVersion));
3576 stat.lock = avc->lock;
3577 stat.parentVnode = avc->f.parent.vnode;
3578 stat.parentUnique = avc->f.parent.unique;
3579 hset(stat.flushDV, avc->flushDV);
3580 hset(stat.mapDV, avc->mapDV);
3581 stat.truncPos = avc->f.truncPos;
3582 { /* just grab the first two - won't break anything... */
3583 struct axscache *ac;
3585 for (i = 0, ac = avc->Access; ac && i < CPSIZE; i++, ac = ac->next) {
3586 stat.randomUid[i] = ac->uid;
3587 stat.randomAccess[i] = ac->axess;
3590 stat.callback = afs_data_pointer_to_int32(avc->callback);
3591 stat.cbExpires = avc->cbExpires;
3592 stat.anyAccess = avc->f.anyAccess;
3593 stat.opens = avc->opens;
3594 stat.execsOrWriters = avc->execsOrWriters;
3595 stat.flockCount = avc->flockCount;
3596 stat.mvstat = avc->mvstat;
3597 stat.states = avc->f.states;
3598 return afs_pd_putBytes(aout, &stat, sizeof(struct vcxstat));
3602 DECL_PIOCTL(PGetVnodeXStatus2)
3604 register afs_int32 code;
3605 struct vcxstat2 stat;
3610 code = afs_VerifyVCache(avc, areq);
3613 if (vType(avc) == VDIR)
3614 mode = PRSFS_LOOKUP;
3617 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
3620 memset(&stat, 0, sizeof(struct vcxstat2));
3622 stat.cbExpires = avc->cbExpires;
3623 stat.anyAccess = avc->f.anyAccess;
3624 stat.mvstat = avc->mvstat;
3625 stat.callerAccess = afs_GetAccessBits(avc, ~0, areq);
3627 return afs_pd_putBytes(aout, &stat, sizeof(struct vcxstat2));
3632 * VIOC_AFS_SYSNAME (38) - Change @sys value
3636 * \param[in] ain new value for @sys
3637 * \param[out] aout count, entry, list (debug values?)
3640 * Error if afsd isn't running, the new sysname is too large,
3641 * the new sysname causes issues (starts with a . or ..),
3642 * there is no PAG set in the credentials, or the user of a PAG
3645 * Error if the user doesn't have super-user credentials
3648 * Set the value of @sys if these things work: if the input isn't
3649 * too long or if input doesn't start with . or ..
3652 * We require root for local sysname changes, but not for remote
3653 * (since we don't really believe remote uids anyway)
3654 * outname[] shouldn't really be needed- this is left as an
3655 * exercise for the reader.
3657 DECL_PIOCTL(PSetSysName)
3659 char *inname = NULL;
3660 char outname[MAXSYSNAME];
3661 afs_int32 setsysname;
3663 register struct afs_exporter *exporter;
3664 register struct unixuser *au;
3665 register afs_int32 pag, error;
3666 int t, count, num = 0, allpags = 0;
3668 struct afs_pdata validate;
3670 AFS_STATCNT(PSetSysName);
3671 if (!afs_globalVFS) {
3672 /* Afsd is NOT running; disable it */
3673 #if defined(KERNEL_HAVE_UERROR)
3674 return (setuerror(EINVAL), EINVAL);
3679 if (afs_pd_getInt(ain, &setsysname) != 0)
3681 if (setsysname & 0x8000) {
3683 setsysname &= ~0x8000;
3688 if (setsysname < 0 || setsysname > MAXNUMSYSNAMES)
3691 for (count = 0; count < setsysname; count++) {
3692 if (afs_pd_getStringPtr(&validate, &inname) != 0)
3695 if (t >= MAXSYSNAME || t <= 0)
3697 /* check for names that can shoot us in the foot */
3698 if (inname[0] == '.' && (inname[1] == 0
3699 || (inname[1] == '.' && inname[2] == 0)))
3702 /* args ok, so go back to the beginning of that section */
3704 if (afs_pd_getStringPtr(ain, &inname) != 0)
3708 if (afs_cr_gid(*acred) == RMTUSER_REQ ||
3709 afs_cr_gid(*acred) == RMTUSER_REQ_PRIV) { /* Handles all exporters */
3710 if (allpags && afs_cr_gid(*acred) != RMTUSER_REQ_PRIV) {
3713 pag = PagInCred(*acred);
3715 return EINVAL; /* Better than panicing */
3717 if (!(au = afs_FindUser(pag, -1, READ_LOCK))) {
3718 return EINVAL; /* Better than panicing */
3720 if (!(exporter = au->exporter)) {
3721 afs_PutUser(au, READ_LOCK);
3722 return EINVAL; /* Better than panicing */
3724 error = EXP_SYSNAME(exporter, inname, &sysnamelist,
3727 if (error == ENODEV)
3728 foundname = 0; /* sysname not set yet! */
3730 afs_PutUser(au, READ_LOCK);
3735 strcpy(outname, sysnamelist[0]);
3737 afs_PutUser(au, READ_LOCK);
3741 /* Not xlating, so local case */
3743 osi_Panic("PSetSysName: !afs_sysname\n");
3744 if (!setsysname) { /* user just wants the info */
3745 strcpy(outname, afs_sysname);
3746 foundname = afs_sysnamecount;
3747 sysnamelist = afs_sysnamelist;
3748 } else { /* Local guy; only root can change sysname */
3749 if (!afs_osi_suser(*acred))
3752 /* allpags makes no sense for local use */
3756 /* clear @sys entries from the dnlc, once afs_lookup can
3757 * do lookups of @sys entries and thinks it can trust them */
3758 /* privs ok, store the entry, ... */
3760 if (strlen(inname) >= MAXSYSNAME-1)
3762 strcpy(afs_sysname, inname);
3764 if (setsysname > 1) { /* ... or list */
3765 for (count = 1; count < setsysname; ++count) {
3766 if (!afs_sysnamelist[count])
3768 ("PSetSysName: no afs_sysnamelist entry to write\n");
3769 if (afs_pd_getString(ain, afs_sysnamelist[count],
3774 afs_sysnamecount = setsysname;