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 extern int afs_rmtsys_enable;
33 struct VenusFid afs_rootFid;
34 afs_int32 afs_waitForever = 0;
35 short afs_waitForeverCount = 0;
36 afs_int32 afs_showflags = GAGUSER | GAGCONSOLE; /* show all messages */
38 afs_int32 afs_is_disconnected;
39 afs_int32 afs_is_discon_rw;
40 /* On reconnection, turn this knob on until it finishes,
43 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)
58 /* Ensure that we give caller at least one trailing guard byte
59 * for the NUL terminator. */
60 if (size >= AFS_LRALLOCSIZ)
61 apd->ptr = osi_Alloc(size + 1);
63 apd->ptr = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
68 /* Clear it all now, including the guard byte. */
69 if (size >= AFS_LRALLOCSIZ)
70 memset(apd->ptr, 0, size + 1);
72 memset(apd->ptr, 0, AFS_LRALLOCSIZ);
74 /* Don't tell the caller about the guard byte. */
75 apd->remaining = size;
81 afs_pd_free(struct afs_pdata *apd)
86 if (apd->remaining >= AFS_LRALLOCSIZ)
87 osi_Free(apd->ptr, apd->remaining + 1);
89 osi_FreeLargeSpace(apd->ptr);
96 afs_pd_where(struct afs_pdata *apd)
98 return apd ? apd->ptr : NULL;
102 afs_pd_remaining(struct afs_pdata *apd)
104 return apd ? apd->remaining : 0;
108 afs_pd_skip(struct afs_pdata *apd, size_t skip)
110 if (apd == NULL || apd->remaining < skip)
112 apd->remaining -= skip;
119 afs_pd_getBytes(struct afs_pdata *apd, void *dest, size_t bytes)
121 if (apd == NULL || apd->remaining < bytes)
123 apd->remaining -= bytes;
124 memcpy(dest, apd->ptr, bytes);
130 afs_pd_getInt(struct afs_pdata *apd, afs_int32 *val)
132 return afs_pd_getBytes(apd, val, sizeof(*val));
136 afs_pd_getUint(struct afs_pdata *apd, afs_uint32 *val)
138 return afs_pd_getBytes(apd, val, sizeof(*val));
142 afs_pd_inline(struct afs_pdata *apd, size_t bytes)
146 if (apd == NULL || apd->remaining < bytes)
151 apd->remaining -= bytes;
158 afs_pd_xdrStart(struct afs_pdata *apd, XDR *xdrs, enum xdr_op op) {
159 xdrmem_create(xdrs, apd->ptr, apd->remaining, op);
163 afs_pd_xdrEnd(struct afs_pdata *apd, XDR *xdrs) {
166 pos = xdr_getpos(xdrs);
168 apd->remaining -= pos;
175 afs_pd_getString(struct afs_pdata *apd, char *str, size_t maxLen)
179 if (apd == NULL || apd->remaining <= 0)
181 len = strlen(apd->ptr) + 1;
184 memcpy(str, apd->ptr, len);
186 apd->remaining -= len;
191 afs_pd_getStringPtr(struct afs_pdata *apd, char **str)
195 if (apd == NULL || apd->remaining <= 0)
197 len = strlen(apd->ptr) + 1;
200 apd->remaining -= len;
205 afs_pd_putBytes(struct afs_pdata *apd, const void *bytes, size_t len)
207 if (apd == NULL || apd->remaining < len)
209 memcpy(apd->ptr, bytes, len);
211 apd->remaining -= len;
216 afs_pd_putInt(struct afs_pdata *apd, afs_int32 val)
218 return afs_pd_putBytes(apd, &val, sizeof(val));
222 afs_pd_putString(struct afs_pdata *apd, char *str) {
224 /* Add 1 so we copy the NULL too */
225 return afs_pd_putBytes(apd, str, strlen(str) +1);
229 * \defgroup pioctl Path IOCTL functions
231 * DECL_PIOCTL is a macro defined to contain the following parameters for functions:
234 * the AFS vcache structure in use by pioctl
238 * the AFS vrequest structure
240 * an afs_pdata block describing the data received from the caller
242 * an afs_pdata block describing a pre-allocated block for output
244 * UNIX credentials structure underlying the operation
247 #define DECL_PIOCTL(x) \
248 static int x(struct vcache *avc, int afun, struct vrequest *areq, \
249 struct afs_pdata *ain, struct afs_pdata *aout, \
252 /* Prototypes for pioctl routines */
253 DECL_PIOCTL(PGetFID);
254 DECL_PIOCTL(PSetAcl);
255 DECL_PIOCTL(PStoreBehind);
256 DECL_PIOCTL(PGCPAGs);
257 DECL_PIOCTL(PGetAcl);
260 DECL_PIOCTL(PGetFileCell);
261 DECL_PIOCTL(PGetWSCell);
262 DECL_PIOCTL(PGetUserCell);
263 DECL_PIOCTL(PSetTokens);
264 DECL_PIOCTL(PSetTokens2);
265 DECL_PIOCTL(PGetVolumeStatus);
266 DECL_PIOCTL(PSetVolumeStatus);
268 DECL_PIOCTL(PNewStatMount);
269 DECL_PIOCTL(PGetTokens);
270 DECL_PIOCTL(PGetTokens2);
272 DECL_PIOCTL(PMariner);
273 DECL_PIOCTL(PCheckServers);
274 DECL_PIOCTL(PCheckVolNames);
275 DECL_PIOCTL(PCheckAuth);
276 DECL_PIOCTL(PFindVolume);
277 DECL_PIOCTL(PViceAccess);
278 DECL_PIOCTL(PSetCacheSize);
279 DECL_PIOCTL(PGetCacheSize);
280 DECL_PIOCTL(PRemoveCallBack);
281 DECL_PIOCTL(PNewCell);
282 DECL_PIOCTL(PNewAlias);
283 DECL_PIOCTL(PListCells);
284 DECL_PIOCTL(PListAliases);
285 DECL_PIOCTL(PRemoveMount);
286 DECL_PIOCTL(PGetCellStatus);
287 DECL_PIOCTL(PSetCellStatus);
288 DECL_PIOCTL(PFlushVolumeData);
289 DECL_PIOCTL(PFlushAllVolumeData);
290 DECL_PIOCTL(PGetVnodeXStatus);
291 DECL_PIOCTL(PGetVnodeXStatus2);
292 DECL_PIOCTL(PSetSysName);
293 DECL_PIOCTL(PSetSPrefs);
294 DECL_PIOCTL(PSetSPrefs33);
295 DECL_PIOCTL(PGetSPrefs);
296 DECL_PIOCTL(PExportAfs);
298 DECL_PIOCTL(PTwiddleRx);
299 DECL_PIOCTL(PGetInitParams);
300 DECL_PIOCTL(PGetRxkcrypt);
301 DECL_PIOCTL(PSetRxkcrypt);
302 DECL_PIOCTL(PGetCPrefs);
303 DECL_PIOCTL(PSetCPrefs);
304 DECL_PIOCTL(PFlushMount);
305 DECL_PIOCTL(PRxStatProc);
306 DECL_PIOCTL(PRxStatPeer);
307 DECL_PIOCTL(PPrefetchFromTape);
309 DECL_PIOCTL(PCallBackAddr);
310 DECL_PIOCTL(PDiscon);
311 DECL_PIOCTL(PNFSNukeCreds);
312 DECL_PIOCTL(PNewUuid);
313 DECL_PIOCTL(PPrecache);
314 DECL_PIOCTL(PGetPAG);
315 #if defined(AFS_CACHE_BYPASS) && defined(AFS_LINUX24_ENV)
316 DECL_PIOCTL(PSetCachingThreshold);
320 * A macro that says whether we're going to need HandleClientContext().
321 * This is currently used only by the nfs translator.
323 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
324 #define AFS_NEED_CLIENTCONTEXT
327 /* Prototypes for private routines */
328 #ifdef AFS_NEED_CLIENTCONTEXT
329 static int HandleClientContext(struct afs_ioctl *ablob, int *com,
333 int HandleIoctl(struct vcache *avc, afs_int32 acom,
334 struct afs_ioctl *adata);
335 int afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
336 struct afs_ioctl *ablob, int afollow,
337 afs_ucred_t **acred);
338 static int Prefetch(uparmtype apath, struct afs_ioctl *adata, int afollow,
341 typedef int (*pioctlFunction) (struct vcache *, int, struct vrequest *,
342 struct afs_pdata *, struct afs_pdata *,
345 static pioctlFunction VpioctlSw[] = {
350 PGetVolumeStatus, /* 4 */
351 PSetVolumeStatus, /* 5 */
356 PCheckServers, /* 10 */
357 PCheckVolNames, /* 11 */
359 PBogus, /* 13 -- used to be quick check time */
360 PFindVolume, /* 14 */
361 PBogus, /* 15 -- prefetch is now special-cased; see pioctl code! */
362 PBogus, /* 16 -- used to be testing code */
363 PNoop, /* 17 -- used to be enable group */
364 PNoop, /* 18 -- used to be disable group */
365 PBogus, /* 19 -- used to be list group */
366 PViceAccess, /* 20 */
367 PUnlog, /* 21 -- unlog *is* unpag in this system */
368 PGetFID, /* 22 -- get file ID */
369 PBogus, /* 23 -- used to be waitforever */
370 PSetCacheSize, /* 24 */
371 PRemoveCallBack, /* 25 -- flush only the callback */
374 PRemoveMount, /* 28 -- delete mount point */
375 PNewStatMount, /* 29 -- new style mount point stat */
376 PGetFileCell, /* 30 -- get cell name for input file */
377 PGetWSCell, /* 31 -- get cell name for workstation */
378 PMariner, /* 32 - set/get mariner host */
379 PGetUserCell, /* 33 -- get cell name for user */
380 PBogus, /* 34 -- Enable/Disable logging */
381 PGetCellStatus, /* 35 */
382 PSetCellStatus, /* 36 */
383 PFlushVolumeData, /* 37 -- flush all data from a volume */
384 PSetSysName, /* 38 - Set system name */
385 PExportAfs, /* 39 - Export Afs to remote nfs clients */
386 PGetCacheSize, /* 40 - get cache size and usage */
387 PGetVnodeXStatus, /* 41 - get vcache's special status */
388 PSetSPrefs33, /* 42 - Set CM Server preferences... */
389 PGetSPrefs, /* 43 - Get CM Server preferences... */
390 PGag, /* 44 - turn off/on all CM messages */
391 PTwiddleRx, /* 45 - adjust some RX params */
392 PSetSPrefs, /* 46 - Set CM Server preferences... */
393 PStoreBehind, /* 47 - set degree of store behind to be done */
394 PGCPAGs, /* 48 - disable automatic pag gc-ing */
395 PGetInitParams, /* 49 - get initial cm params */
396 PGetCPrefs, /* 50 - get client interface addresses */
397 PSetCPrefs, /* 51 - set client interface addresses */
398 PFlushMount, /* 52 - flush mount symlink data */
399 PRxStatProc, /* 53 - control process RX statistics */
400 PRxStatPeer, /* 54 - control peer RX statistics */
401 PGetRxkcrypt, /* 55 -- Get rxkad encryption flag */
402 PSetRxkcrypt, /* 56 -- Set rxkad encryption flag */
403 PBogus, /* 57 -- arla: set file prio */
404 PBogus, /* 58 -- arla: fallback getfh */
405 PBogus, /* 59 -- arla: fallback fhopen */
406 PBogus, /* 60 -- arla: controls xfsdebug */
407 PBogus, /* 61 -- arla: controls arla debug */
408 PBogus, /* 62 -- arla: debug interface */
409 PBogus, /* 63 -- arla: print xfs status */
410 PBogus, /* 64 -- arla: force cache check */
411 PBogus, /* 65 -- arla: break callback */
412 PPrefetchFromTape, /* 66 -- MR-AFS: prefetch file from tape */
413 PFsCmd, /* 67 -- RXOSD: generic commnd interface */
414 PBogus, /* 68 -- arla: fetch stats */
415 PGetVnodeXStatus2, /* 69 - get caller access and some vcache status */
418 static pioctlFunction CpioctlSw[] = {
420 PNewAlias, /* 1 -- create new cell alias */
421 PListAliases, /* 2 -- list cell aliases */
422 PCallBackAddr, /* 3 -- request addr for callback rxcon */
424 PDiscon, /* 5 -- get/set discon mode */
433 PFlushAllVolumeData, /* 14 */
436 static pioctlFunction OpioctlSw[] = {
438 PNFSNukeCreds, /* 1 -- nuke all creds for NFS client */
439 #if defined(AFS_CACHE_BYPASS) && defined(AFS_LINUX24_ENV)
440 PSetCachingThreshold /* 2 -- get/set cache-bypass size threshold */
442 PNoop /* 2 -- get/set cache-bypass size threshold */
446 #define PSetClientContext 99 /* Special pioctl to setup caller's creds */
447 int afs_nobody = NFS_NOBODY;
450 HandleIoctl(struct vcache *avc, afs_int32 acom,
451 struct afs_ioctl *adata)
456 AFS_STATCNT(HandleIoctl);
458 switch (acom & 0xff) {
460 avc->f.states |= CSafeStore;
462 /* SXW - Should we force a MetaData flush for this flag setting */
465 /* case 2 used to be abort store, but this is no longer provided,
466 * since it is impossible to implement under normal Unix.
470 /* return the name of the cell this file is open on */
474 tcell = afs_GetCell(avc->f.fid.Cell, READ_LOCK);
476 i = strlen(tcell->cellName) + 1; /* bytes to copy out */
478 if (i > adata->out_size) {
479 /* 0 means we're not interested in the output */
480 if (adata->out_size != 0)
484 AFS_COPYOUT(tcell->cellName, adata->out, i, code);
486 afs_PutCell(tcell, READ_LOCK);
492 case 49: /* VIOC_GETINITPARAMS */
493 if (adata->out_size < sizeof(struct cm_initparams)) {
496 AFS_COPYOUT(&cm_initParams, adata->out,
497 sizeof(struct cm_initparams), code);
509 return code; /* so far, none implemented */
513 /* For aix we don't temporarily bypass ioctl(2) but rather do our
514 * thing directly in the vnode layer call, VNOP_IOCTL; thus afs_ioctl
515 * is now called from afs_gn_ioctl.
518 afs_ioctl(struct vcache *tvc, int cmd, int arg)
520 struct afs_ioctl data;
523 AFS_STATCNT(afs_ioctl);
524 if (((cmd >> 8) & 0xff) == 'V') {
525 /* This is a VICEIOCTL call */
526 AFS_COPYIN(arg, (caddr_t) & data, sizeof(data), error);
529 error = HandleIoctl(tvc, cmd, &data);
532 /* No-op call; just return. */
536 # if defined(AFS_AIX32_ENV)
537 # if defined(AFS_AIX51_ENV)
540 kioctl(int fdes, int com, caddr_t arg, caddr_t ext, caddr_t arg2,
542 # else /* __64BIT__ */
544 kioctl32(int fdes, int com, caddr_t arg, caddr_t ext, caddr_t arg2,
546 # endif /* __64BIT__ */
549 kioctl(int fdes, int com, caddr_t arg, caddr_t ext)
550 # endif /* AFS_AIX51_ENV */
555 # ifdef AFS_AIX51_ENV
558 } u_uap, *uap = &u_uap;
561 int ioctlDone = 0, code = 0;
563 AFS_STATCNT(afs_xioctl);
567 # ifdef AFS_AIX51_ENV
571 if (setuerror(getf(uap->fd, &fd))) {
574 if (fd->f_type == DTYPE_VNODE) {
575 /* good, this is a vnode; next see if it is an AFS vnode */
576 tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */
577 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
578 /* This is an AFS vnode */
579 if (((uap->com >> 8) & 0xff) == 'V') {
580 struct afs_ioctl *datap;
582 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
583 code=copyin_afs_ioctl((char *)uap->arg, datap);
585 osi_FreeSmallSpace(datap);
587 # if defined(AFS_AIX41_ENV)
590 return (setuerror(code), code);
592 code = HandleIoctl(tvc, uap->com, datap);
593 osi_FreeSmallSpace(datap);
596 # if defined(AFS_AIX41_ENV)
603 # if defined(AFS_AIX41_ENV)
605 # if defined(AFS_AIX51_ENV)
607 code = okioctl(fdes, com, arg, ext, arg2, arg3);
608 # else /* __64BIT__ */
609 code = okioctl32(fdes, com, arg, ext, arg2, arg3);
610 # endif /* __64BIT__ */
611 # else /* !AFS_AIX51_ENV */
612 code = okioctl(fdes, com, arg, ext);
613 # endif /* AFS_AIX51_ENV */
615 # elif defined(AFS_AIX32_ENV)
616 okioctl(fdes, com, arg, ext);
619 # if defined(KERNEL_HAVE_UERROR)
622 # if !defined(AFS_AIX41_ENV)
623 return (getuerror()? -1 : u.u_ioctlrv);
625 return getuerror()? -1 : 0;
632 #elif defined(AFS_SGI_ENV)
633 # if defined(AFS_SGI65_ENV)
634 afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
635 rval_t * rvalp, struct vopbd * vbds)
637 afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
638 rval_t * rvalp, struct vopbd * vbds)
641 struct afs_ioctl data;
647 AFS_STATCNT(afs_ioctl);
648 if (((cmd >> 8) & 0xff) == 'V') {
649 /* This is a VICEIOCTL call */
650 error = copyin_afs_ioctl(arg, &data);
653 locked = ISAFS_GLOCK();
656 error = HandleIoctl(tvc, cmd, &data);
661 /* No-op call; just return. */
665 #elif defined(AFS_SUN5_ENV)
666 struct afs_ioctl_sys {
673 afs_xioctl(struct afs_ioctl_sys *uap, rval_t *rvp)
677 int ioctlDone = 0, code = 0;
679 AFS_STATCNT(afs_xioctl);
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;
690 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
691 code=copyin_afs_ioctl((char *)uap->arg, datap);
693 osi_FreeSmallSpace(datap);
698 code = HandleIoctl(tvc, uap->com, datap);
699 osi_FreeSmallSpace(datap);
707 code = ioctl(uap, rvp);
711 #elif defined(AFS_LINUX22_ENV)
712 struct afs_ioctl_sys {
717 afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
720 struct afs_ioctl_sys ua, *uap = &ua;
724 AFS_STATCNT(afs_xioctl);
729 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
730 /* This is an AFS vnode */
731 if (((uap->com >> 8) & 0xff) == 'V') {
732 struct afs_ioctl *datap;
734 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
735 code = copyin_afs_ioctl((char *)uap->arg, datap);
737 osi_FreeSmallSpace(datap);
741 code = HandleIoctl(tvc, uap->com, datap);
742 osi_FreeSmallSpace(datap);
750 #elif defined(AFS_DARWIN_ENV) && !defined(AFS_DARWIN80_ENV)
758 afs_xioctl(afs_proc_t *p, struct ioctl_args *uap, register_t *retval)
762 int ioctlDone = 0, code = 0;
764 AFS_STATCNT(afs_xioctl);
765 if ((code = fdgetf(p, uap->fd, &fd)))
767 if (fd->f_type == DTYPE_VNODE) {
768 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
769 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
770 /* This is an AFS vnode */
771 if (((uap->com >> 8) & 0xff) == 'V') {
772 struct afs_ioctl *datap;
774 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
775 code = copyin_afs_ioctl((char *)uap->arg, datap);
777 osi_FreeSmallSpace(datap);
781 code = HandleIoctl(tvc, uap->com, datap);
782 osi_FreeSmallSpace(datap);
790 return ioctl(p, uap, retval);
794 #elif defined(AFS_XBSD_ENV)
795 # if defined(AFS_FBSD_ENV)
798 afs_xioctl(struct thread *td, struct ioctl_args *uap,
801 afs_proc_t *p = td->td_proc;
802 # elif defined(AFS_NBSD_ENV)
804 afs_xioctl(afs_proc_t *p, const struct sys_ioctl_args *uap, register_t *retval)
814 afs_xioctl(afs_proc_t *p, const struct ioctl_args *uap, register_t *retval)
817 struct filedesc *fdp;
819 int ioctlDone = 0, code = 0;
822 AFS_STATCNT(afs_xioctl);
823 #if defined(AFS_NBSD40_ENV)
824 fdp = p->l_proc->p_fd;
828 #if defined(AFS_NBSD50_ENV)
829 if ((fd = fd_getfile(SCARG(uap, fd))) == NULL)
831 #elif defined(AFS_FBSD_ENV)
832 if ((uap->fd >= fdp->fd_nfiles)
833 || ((fd = fdp->fd_ofiles[uap->fd].fde_file) == NULL))
836 if ((uap->fd >= fdp->fd_nfiles)
837 || ((fd = fdp->fd_ofiles[uap->fd]) == NULL))
840 if ((fd->f_flag & (FREAD | FWRITE)) == 0)
842 /* first determine whether this is any sort of vnode */
843 if (fd->f_type == DTYPE_VNODE) {
844 /* good, this is a vnode; next see if it is an AFS vnode */
845 # if defined(AFS_OBSD_ENV)
847 IsAfsVnode((struct vnode *)fd->
848 f_data) ? VTOAFS((struct vnode *)fd->f_data) : NULL;
850 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
852 if (tvc && IsAfsVnode((struct vnode *)fd->f_data)) {
853 /* This is an AFS vnode */
854 #if defined(AFS_NBSD50_ENV)
855 if (((SCARG(uap, com) >> 8) & 0xff) == 'V') {
857 if (((uap->com >> 8) & 0xff) == 'V') {
859 struct afs_ioctl *datap;
861 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
862 #if defined(AFS_NBSD50_ENV)
863 code = copyin_afs_ioctl(SCARG(uap, data), datap);
865 code = copyin_afs_ioctl((char *)uap->arg, datap);
868 osi_FreeSmallSpace(datap);
872 #if defined(AFS_NBSD50_ENV)
873 code = HandleIoctl(tvc, SCARG(uap, com), datap);
875 code = HandleIoctl(tvc, uap->com, datap);
877 osi_FreeSmallSpace(datap);
884 #if defined(AFS_NBSD50_ENV)
885 fd_putfile(SCARG(uap, fd));
889 # if defined(AFS_FBSD_ENV)
890 return sys_ioctl(td, uap);
891 # elif defined(AFS_OBSD_ENV)
892 code = sys_ioctl(p, uap, retval);
893 # elif defined(AFS_NBSD_ENV)
894 code = sys_ioctl(p, uap, retval);
900 #elif defined(UKERNEL)
908 } *uap = (struct a *)get_user_struct()->u_ap;
911 int ioctlDone = 0, code = 0;
913 AFS_STATCNT(afs_xioctl);
918 /* first determine whether this is any sort of vnode */
919 if (fd->f_type == DTYPE_VNODE) {
920 /* good, this is a vnode; next see if it is an AFS vnode */
921 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
922 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
923 /* This is an AFS vnode */
924 if (((uap->com >> 8) & 0xff) == 'V') {
925 struct afs_ioctl *datap;
927 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
928 code=copyin_afs_ioctl((char *)uap->arg, datap);
930 osi_FreeSmallSpace(datap);
933 return (setuerror(code), code);
935 code = HandleIoctl(tvc, uap->com, datap);
936 osi_FreeSmallSpace(datap);
949 #endif /* AFS_HPUX102_ENV */
951 #if defined(AFS_SGI_ENV)
952 /* "pioctl" system call entry point; just pass argument to the parameterized
961 afs_pioctl(struct pioctlargs *uap, rval_t * rvp)
965 AFS_STATCNT(afs_pioctl);
967 code = afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow);
969 # ifdef AFS_SGI64_ENV
976 #elif defined(AFS_FBSD_ENV)
978 afs_pioctl(struct thread *td, void *args, int *retval)
985 } *uap = (struct a *)args;
987 AFS_STATCNT(afs_pioctl);
988 return (afs_syscall_pioctl
989 (uap->path, uap->cmd, uap->cmarg, uap->follow, td->td_ucred));
992 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
994 afs_pioctl(afs_proc_t *p, void *args, int *retval)
1001 } *uap = (struct a *)args;
1003 AFS_STATCNT(afs_pioctl);
1004 # if defined(AFS_DARWIN80_ENV) || defined(AFS_NBSD40_ENV)
1005 return (afs_syscall_pioctl
1006 (uap->path, uap->cmd, uap->cmarg, uap->follow,
1009 return (afs_syscall_pioctl
1010 (uap->path, uap->cmd, uap->cmarg, uap->follow,
1011 # if defined(AFS_FBSD_ENV)
1014 p->p_cred->pc_ucred));
1021 /* macro to avoid adding any more #ifdef's to pioctl code. */
1022 #if defined(AFS_LINUX22_ENV) || defined(AFS_AIX41_ENV)
1023 #define PIOCTL_FREE_CRED() crfree(credp)
1025 #define PIOCTL_FREE_CRED()
1030 afs_syscall_pioctl(char *path, unsigned int com, caddr_t cmarg, int follow,
1031 rval_t *vvp, afs_ucred_t *credp)
1033 #ifdef AFS_DARWIN100_ENV
1034 afs_syscall64_pioctl(user_addr_t path, unsigned int com, user_addr_t cmarg,
1035 int follow, afs_ucred_t *credp)
1036 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1037 afs_syscall_pioctl(char *path, unsigned int com, caddr_t cmarg, int follow,
1040 afs_syscall_pioctl(char *path, unsigned int com, caddr_t cmarg, int follow)
1044 struct afs_ioctl data;
1045 #ifdef AFS_NEED_CLIENTCONTEXT
1046 afs_ucred_t *tmpcred = NULL;
1048 #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)
1049 afs_ucred_t *foreigncreds = NULL;
1052 struct vnode *vp = NULL;
1053 #ifdef AFS_AIX41_ENV
1054 struct ucred *credp = crref(); /* don't free until done! */
1056 #ifdef AFS_LINUX22_ENV
1057 cred_t *credp = crref(); /* don't free until done! */
1061 AFS_STATCNT(afs_syscall_pioctl);
1063 follow = 1; /* compat. with old venus */
1064 code = copyin_afs_ioctl(cmarg, &data);
1067 #if defined(KERNEL_HAVE_UERROR)
1072 if ((com & 0xff) == PSetClientContext) {
1073 #ifdef AFS_NEED_CLIENTCONTEXT
1074 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV)
1075 code = HandleClientContext(&data, &com, &foreigncreds, credp);
1077 code = HandleClientContext(&data, &com, &foreigncreds, osi_curcred());
1081 crfree(foreigncreds);
1084 #if defined(KERNEL_HAVE_UERROR)
1085 return (setuerror(code), code);
1090 #else /* AFS_NEED_CLIENTCONTEXT */
1092 #endif /* AFS_NEED_CLIENTCONTEXT */
1094 #ifdef AFS_NEED_CLIENTCONTEXT
1097 * We could have done without temporary setting the u.u_cred below
1098 * (foreigncreds could be passed as param the pioctl modules)
1099 * but calls such as afs_osi_suser() doesn't allow that since it
1100 * references u.u_cred directly. We could, of course, do something
1101 * like afs_osi_suser(cred) which, I think, is better since it
1102 * generalizes and supports multi cred environments...
1104 #if defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
1106 credp = foreigncreds;
1107 #elif defined(AFS_AIX41_ENV)
1108 tmpcred = crref(); /* XXX */
1109 crset(foreigncreds);
1110 #elif defined(AFS_HPUX101_ENV)
1111 tmpcred = p_cred(u.u_procp);
1112 set_p_cred(u.u_procp, foreigncreds);
1113 #elif defined(AFS_SGI_ENV)
1114 tmpcred = OSI_GET_CURRENT_CRED();
1115 OSI_SET_CURRENT_CRED(foreigncreds);
1118 u.u_cred = foreigncreds;
1121 #endif /* AFS_NEED_CLIENTCONTEXT */
1124 if ((com & 0xff00) >> 8 == 'V' && (com & 0xff) == 15) {
1125 /* special case prefetch so entire pathname eval occurs in helper process.
1126 * otherwise, the pioctl call is essentially useless */
1127 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1129 Prefetch(path, &data, follow,
1130 foreigncreds ? foreigncreds : credp);
1132 code = Prefetch(path, &data, follow, osi_curcred());
1135 #if defined(KERNEL_HAVE_UERROR)
1142 #ifdef AFS_AIX41_ENV
1144 lookupname(path, USR, follow, NULL, &vp,
1145 foreigncreds ? foreigncreds : credp);
1147 #ifdef AFS_LINUX22_ENV
1148 code = gop_lookupname_user(path, AFS_UIOUSER, follow, &dp);
1150 vp = (struct vnode *)dp->d_inode;
1152 code = gop_lookupname_user(path, AFS_UIOUSER, follow, &vp);
1153 #endif /* AFS_LINUX22_ENV */
1154 #endif /* AFS_AIX41_ENV */
1158 #if defined(KERNEL_HAVE_UERROR)
1166 #if defined(AFS_SUN510_ENV)
1167 if (vp && !IsAfsVnode(vp)) {
1168 struct vnode *realvp;
1170 #ifdef AFS_SUN511_ENV
1171 (VOP_REALVP(vp, &realvp, NULL) == 0)
1173 (VOP_REALVP(vp, &realvp) == 0)
1176 struct vnode *oldvp = vp;
1184 /* now make the call if we were passed no file, or were passed an AFS file */
1185 if (!vp || IsAfsVnode(vp)) {
1186 #if defined(AFS_SUN5_ENV)
1187 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1188 #elif defined(AFS_AIX41_ENV)
1190 struct ucred *cred1, *cred2;
1193 cred1 = cred2 = foreigncreds;
1195 cred1 = cred2 = credp;
1197 code = afs_HandlePioctl(vp, com, &data, follow, &cred1);
1198 if (cred1 != cred2) {
1199 /* something changed the creds */
1203 #elif defined(AFS_HPUX101_ENV)
1205 struct ucred *cred = p_cred(u.u_procp);
1206 code = afs_HandlePioctl(vp, com, &data, follow, &cred);
1208 #elif defined(AFS_SGI_ENV)
1211 credp = OSI_GET_CURRENT_CRED();
1212 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1214 #elif defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1215 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1216 #elif defined(UKERNEL)
1217 code = afs_HandlePioctl(vp, com, &data, follow,
1218 &(get_user_struct()->u_cred));
1220 code = afs_HandlePioctl(vp, com, &data, follow, &u.u_cred);
1223 #if defined(KERNEL_HAVE_UERROR)
1226 code = EINVAL; /* not in /afs */
1231 #if defined(AFS_NEED_CLIENTCONTEXT)
1233 #ifdef AFS_AIX41_ENV
1234 crset(tmpcred); /* restore original credentials */
1236 #if defined(AFS_HPUX101_ENV)
1237 set_p_cred(u.u_procp, tmpcred); /* restore original credentials */
1238 #elif defined(AFS_SGI_ENV)
1239 OSI_SET_CURRENT_CRED(tmpcred); /* restore original credentials */
1240 #elif defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
1241 credp = tmpcred; /* restore original credentials */
1243 osi_curcred() = tmpcred; /* restore original credentials */
1244 #endif /* AFS_HPUX101_ENV */
1245 crfree(foreigncreds);
1248 #endif /* AFS_NEED_CLIENTCONTEXT */
1250 #ifdef AFS_LINUX22_ENV
1252 * Holding the global lock when calling dput can cause a deadlock
1253 * when the kernel calls back into afs_dentry_iput
1259 #if defined(AFS_FBSD_ENV)
1260 if (VOP_ISLOCKED(vp))
1262 #endif /* AFS_FBSD_ENV */
1263 AFS_RELE(vp); /* put vnode back */
1267 #if defined(KERNEL_HAVE_UERROR)
1270 return (getuerror());
1276 #ifdef AFS_DARWIN100_ENV
1278 afs_syscall_pioctl(char * path, unsigned int com, caddr_t cmarg,
1279 int follow, afs_ucred_t *credp)
1281 return afs_syscall64_pioctl(CAST_USER_ADDR_T(path), com,
1282 CAST_USER_ADDR_T((unsigned int)cmarg), follow,
1287 #define MAXPIOCTLTOKENLEN \
1288 (3*sizeof(afs_int32)+MAXKTCTICKETLEN+sizeof(struct ClearToken)+MAXKTCREALMLEN)
1291 afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
1292 struct afs_ioctl *ablob, int afollow,
1293 afs_ucred_t **acred)
1296 struct vrequest *treq = NULL;
1298 afs_int32 function, device;
1299 struct afs_pdata input, output;
1300 struct afs_pdata copyInput, copyOutput;
1302 pioctlFunction *pioctlSw;
1304 struct afs_fakestat_state fakestate;
1306 memset(&input, 0, sizeof(input));
1307 memset(&output, 0, sizeof(output));
1309 avc = avp ? VTOAFS(avp) : NULL;
1310 afs_Trace3(afs_iclSetp, CM_TRACE_PIOCTL, ICL_TYPE_INT32, acom & 0xff,
1311 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, afollow);
1312 AFS_STATCNT(HandlePioctl);
1314 code = afs_CreateReq(&treq, *acred);
1318 afs_InitFakeStat(&fakestate);
1320 code = afs_EvalFakeStat(&avc, &fakestate, treq);
1324 device = (acom & 0xff00) >> 8;
1326 case 'V': /* Original pioctls */
1327 pioctlSw = VpioctlSw;
1328 pioctlSwSize = sizeof(VpioctlSw);
1330 case 'C': /* Coordinated/common pioctls */
1331 pioctlSw = CpioctlSw;
1332 pioctlSwSize = sizeof(CpioctlSw);
1334 case 'O': /* Coordinated/common pioctls */
1335 pioctlSw = OpioctlSw;
1336 pioctlSwSize = sizeof(OpioctlSw);
1342 function = acom & 0xff;
1343 if (function >= (pioctlSwSize / sizeof(char *))) {
1348 /* Do all range checking before continuing */
1349 if (ablob->in_size > MAXPIOCTLTOKENLEN ||
1350 ablob->in_size < 0 || ablob->out_size < 0) {
1355 code = afs_pd_alloc(&input, ablob->in_size);
1359 if (ablob->in_size > 0) {
1360 AFS_COPYIN(ablob->in, input.ptr, ablob->in_size, code);
1361 input.ptr[input.remaining] = '\0';
1366 if ((function == 8 && device == 'V') ||
1367 (function == 7 && device == 'C')) { /* PGetTokens */
1368 code = afs_pd_alloc(&output, MAXPIOCTLTOKENLEN);
1370 code = afs_pd_alloc(&output, AFS_LRALLOCSIZ);
1376 copyOutput = output;
1379 (*pioctlSw[function]) (avc, function, treq, ©Input,
1380 ©Output, acred);
1382 outSize = copyOutput.ptr - output.ptr;
1384 if (code == 0 && ablob->out_size > 0) {
1385 if (outSize > ablob->out_size) {
1386 code = E2BIG; /* data wont fit in user buffer */
1387 } else if (outSize) {
1388 AFS_COPYOUT(output.ptr, ablob->out, outSize, code);
1393 afs_pd_free(&input);
1394 afs_pd_free(&output);
1396 afs_PutFakeStat(&fakestate);
1397 code = afs_CheckCode(code, treq, 41);
1398 afs_DestroyReq(treq);
1403 * VIOCGETFID (22) - Get file ID quickly
1407 * \param[in] ain not in use
1408 * \param[out] aout fid of requested file
1410 * \retval EINVAL Error if some of the initial arguments aren't set
1412 * \post get the file id of some file
1414 DECL_PIOCTL(PGetFID)
1416 AFS_STATCNT(PGetFID);
1419 if (afs_pd_putBytes(aout, &avc->f.fid, sizeof(struct VenusFid)) != 0)
1425 * VIOCSETAL (1) - Set access control list
1429 * \param[in] ain the ACL being set
1430 * \param[out] aout the ACL being set returned
1432 * \retval EINVAL Error if some of the standard args aren't set
1434 * \post Changed ACL, via direct writing to the wire
1437 dummy_PSetAcl(char *ain, char *aout)
1442 DECL_PIOCTL(PSetAcl)
1445 struct afs_conn *tconn;
1446 struct AFSOpaque acl;
1447 struct AFSVolSync tsync;
1448 struct AFSFetchStatus OutStatus;
1449 struct rx_connection *rxconn;
1452 AFS_STATCNT(PSetAcl);
1456 if (afs_pd_getStringPtr(ain, &acl.AFSOpaque_val) != 0)
1458 acl.AFSOpaque_len = strlen(acl.AFSOpaque_val) + 1;
1459 if (acl.AFSOpaque_len > 1024)
1463 tconn = afs_Conn(&avc->f.fid, areq, SHARED_LOCK, &rxconn);
1465 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREACL);
1468 RXAFS_StoreACL(rxconn, (struct AFSFid *)&avc->f.fid.Fid,
1469 &acl, &OutStatus, &tsync);
1474 } while (afs_Analyze
1475 (tconn, rxconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_STOREACL,
1476 SHARED_LOCK, NULL));
1478 /* now we've forgotten all of the access info */
1479 afs_StaleVCacheFlags(avc, AFS_STALEVC_CLEARCB, CUnique);
1481 /* SXW - Should we flush metadata here? */
1486 int afs_defaultAsynchrony = 0;
1489 * VIOC_STOREBEHIND (47) Adjust store asynchrony
1493 * \param[in] ain sbstruct (store behind structure) input
1494 * \param[out] aout resulting sbstruct
1497 * Error if the user doesn't have super-user credentials
1499 * Error if there isn't enough access to not check the mode bits
1502 * Changes either the default asynchrony (the amount of data that
1503 * can remain to be written when the cache manager returns control
1504 * to the user), or the asyncrony for the specified file.
1506 DECL_PIOCTL(PStoreBehind)
1508 struct sbstruct sbr;
1510 if (afs_pd_getBytes(ain, &sbr, sizeof(struct sbstruct)) != 0)
1513 if (sbr.sb_default != -1) {
1514 if (afs_osi_suser(*acred))
1515 afs_defaultAsynchrony = sbr.sb_default;
1520 if (avc && (sbr.sb_thisfile != -1)) {
1522 (avc, PRSFS_WRITE | PRSFS_ADMINISTER, areq, DONT_CHECK_MODE_BITS))
1523 avc->asynchrony = sbr.sb_thisfile;
1528 memset(&sbr, 0, sizeof(sbr));
1529 sbr.sb_default = afs_defaultAsynchrony;
1531 sbr.sb_thisfile = avc->asynchrony;
1534 return afs_pd_putBytes(aout, &sbr, sizeof(sbr));
1538 * VIOC_GCPAGS (48) - Disable automatic PAG gc'ing
1542 * \param[in] ain not in use
1543 * \param[out] aout not in use
1545 * \retval EACCES Error if the user doesn't have super-user credentials
1547 * \post set the gcpags to GCPAGS_USERDISABLED
1549 DECL_PIOCTL(PGCPAGs)
1551 if (!afs_osi_suser(*acred)) {
1554 afs_gcpags = AFS_GCPAGS_USERDISABLED;
1559 * VIOCGETAL (2) - Get access control list
1563 * \param[in] ain not in use
1564 * \param[out] aout the ACL
1566 * \retval EINVAL Error if some of the standard args aren't set
1567 * \retval ERANGE Error if the vnode of the file id is too large
1568 * \retval -1 Error if getting the ACL failed
1570 * \post Obtain the ACL, based on file ID
1573 * There is a hack to tell which type of ACL is being returned, checks
1574 * the top 2-bytes of the input size to judge what type of ACL it is,
1575 * only for dfs xlator ACLs
1577 DECL_PIOCTL(PGetAcl)
1579 struct AFSOpaque acl;
1580 struct AFSVolSync tsync;
1581 struct AFSFetchStatus OutStatus;
1583 struct afs_conn *tconn;
1585 struct rx_connection *rxconn;
1588 AFS_STATCNT(PGetAcl);
1591 Fid.Volume = avc->f.fid.Fid.Volume;
1592 Fid.Vnode = avc->f.fid.Fid.Vnode;
1593 Fid.Unique = avc->f.fid.Fid.Unique;
1594 if (avc->f.states & CForeign) {
1596 * For a dfs xlator acl we have a special hack so that the
1597 * xlator will distinguish which type of acl will return. So
1598 * we currently use the top 2-bytes (vals 0-4) to tell which
1599 * type of acl to bring back. Horrible hack but this will
1600 * cause the least number of changes to code size and interfaces.
1602 if (Fid.Vnode & 0xc0000000)
1604 Fid.Vnode |= (ain->remaining << 30);
1606 acl.AFSOpaque_val = aout->ptr;
1608 tconn = afs_Conn(&avc->f.fid, areq, SHARED_LOCK, &rxconn);
1610 acl.AFSOpaque_val[0] = '\0';
1611 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHACL);
1613 code = RXAFS_FetchACL(rxconn, &Fid, &acl, &OutStatus, &tsync);
1618 } while (afs_Analyze
1619 (tconn, rxconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_FETCHACL,
1620 SHARED_LOCK, NULL));
1623 if (acl.AFSOpaque_len == 0)
1624 afs_pd_skip(aout, 1); /* leave the NULL */
1626 afs_pd_skip(aout, acl.AFSOpaque_len); /* Length of the ACL */
1632 * PNoop returns success. Used for functions which are not implemented
1633 * or are no longer in use.
1637 * \retval Always returns success
1640 * Functions involved in this:
1641 * 17 (VIOCENGROUP) -- used to be enable group;
1642 * 18 (VIOCDISGROUP) -- used to be disable group;
1643 * 2 (?) -- get/set cache-bypass size threshold
1652 * PBogus returns fail. Used for functions which are not implemented or
1653 * are no longer in use.
1657 * \retval EINVAL Always returns this value
1660 * Functions involved in this:
1666 * 13 (VIOCGETTIME) -- used to be quick check time;
1667 * 15 (VIOCPREFETCH) -- prefetch is now special-cased; see pioctl code!;
1668 * 16 (VIOCNOP) -- used to be testing code;
1669 * 19 (VIOCLISTGROUPS) -- used to be list group;
1670 * 23 (VIOCWAITFOREVER) -- used to be waitforever;
1671 * 57 (VIOC_FPRIOSTATUS) -- arla: set file prio;
1672 * 58 (VIOC_FHGET) -- arla: fallback getfh;
1673 * 59 (VIOC_FHOPEN) -- arla: fallback fhopen;
1674 * 60 (VIOC_XFSDEBUG) -- arla: controls xfsdebug;
1675 * 61 (VIOC_ARLADEBUG) -- arla: controls arla debug;
1676 * 62 (VIOC_AVIATOR) -- arla: debug interface;
1677 * 63 (VIOC_XFSDEBUG_PRINT) -- arla: print xfs status;
1678 * 64 (VIOC_CALCULATE_CACHE) -- arla: force cache check;
1679 * 65 (VIOC_BREAKCELLBACK) -- arla: break callback;
1680 * 68 (?) -- arla: fetch stats;
1684 AFS_STATCNT(PBogus);
1689 * VIOC_FILE_CELL_NAME (30) - Get cell in which file lives
1693 * \param[in] ain not in use (avc used to pass in file id)
1694 * \param[out] aout cell name
1696 * \retval EINVAL Error if some of the standard args aren't set
1697 * \retval ESRCH Error if the file isn't part of a cell
1699 * \post Get a cell based on a passed in file id
1701 DECL_PIOCTL(PGetFileCell)
1705 AFS_STATCNT(PGetFileCell);
1708 tcell = afs_GetCell(avc->f.fid.Cell, READ_LOCK);
1712 if (afs_pd_putString(aout, tcell->cellName) != 0)
1715 afs_PutCell(tcell, READ_LOCK);
1720 * VIOC_GET_WS_CELL (31) - Get cell in which workstation lives
1724 * \param[in] ain not in use
1725 * \param[out] aout cell name
1728 * Error if the afs daemon hasn't started yet
1730 * Error if the machine isn't part of a cell, for whatever reason
1732 * \post Get the primary cell that the machine is a part of.
1734 DECL_PIOCTL(PGetWSCell)
1736 struct cell *tcell = NULL;
1738 AFS_STATCNT(PGetWSCell);
1739 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1740 return EIO; /* Inappropriate ioctl for device */
1742 tcell = afs_GetPrimaryCell(READ_LOCK);
1743 if (!tcell) /* no primary cell? */
1746 if (afs_pd_putString(aout, tcell->cellName) != 0)
1748 afs_PutCell(tcell, READ_LOCK);
1753 * VIOC_GET_PRIMARY_CELL (33) - Get primary cell for caller
1757 * \param[in] ain not in use (user id found via areq)
1758 * \param[out] aout cell name
1761 * Error if the user id doesn't have a primary cell specified
1763 * \post Get the primary cell for a certain user, based on the user's uid
1765 DECL_PIOCTL(PGetUserCell)
1768 struct unixuser *tu;
1771 AFS_STATCNT(PGetUserCell);
1772 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1773 return EIO; /* Inappropriate ioctl for device */
1775 /* return the cell name of the primary cell for this user */
1776 i = UHash(areq->uid);
1777 ObtainWriteLock(&afs_xuser, 224);
1778 for (tu = afs_users[i]; tu; tu = tu->next) {
1779 if (tu->uid == areq->uid && (tu->states & UPrimary)) {
1781 ReleaseWriteLock(&afs_xuser);
1782 afs_LockUser(tu, READ_LOCK, 0);
1787 tcell = afs_GetCell(tu->cell, READ_LOCK);
1788 afs_PutUser(tu, READ_LOCK);
1792 if (afs_pd_putString(aout, tcell->cellName) != 0)
1794 afs_PutCell(tcell, READ_LOCK);
1797 ReleaseWriteLock(&afs_xuser);
1802 /* Work out which cell we're changing tokens for */
1804 _settok_tokenCell(char *cellName, int *cellNum, int *primary) {
1812 if (cellName && strlen(cellName) > 0) {
1813 cell = afs_GetCellByName(cellName, READ_LOCK);
1815 cell = afs_GetPrimaryCell(READ_LOCK);
1826 *cellNum = cell->cellNum;
1827 afs_PutCell(cell, READ_LOCK);
1834 _settok_setParentPag(afs_ucred_t **cred) {
1836 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1838 osi_procname(procname, 256);
1839 afs_warnuser("Process %d (%s) tried to change pags in PSetTokens\n",
1840 MyPidxx2Pid(MyPidxx), procname);
1841 return setpag(osi_curproc(), cred, -1, &pag, 1);
1843 return setpag(cred, -1, &pag, 1);
1848 * VIOCSETTOK (3) - Set authentication tokens
1852 * \param[in] ain the krb tickets from which to set the afs tokens
1853 * \param[out] aout not in use
1856 * Error if the ticket is either too long or too short
1858 * Error if the AFS initState is below 101
1860 * Error if the cell for which the Token is being set can't be found
1863 * Set the Tokens for a specific cell name, unless there is none set,
1864 * then default to primary
1867 DECL_PIOCTL(PSetTokens)
1872 struct unixuser *tu;
1873 struct ClearToken clear;
1877 struct vrequest *treq = NULL;
1878 afs_int32 flag, set_parent_pag = 0;
1880 AFS_STATCNT(PSetTokens);
1881 if (!afs_resourceinit_flag) {
1885 if (afs_pd_getInt(ain, &stLen) != 0)
1888 stp = afs_pd_where(ain); /* remember where the ticket is */
1889 if (stLen < 0 || stLen > MAXKTCTICKETLEN)
1890 return EINVAL; /* malloc may fail */
1891 if (afs_pd_skip(ain, stLen) != 0)
1894 if (afs_pd_getInt(ain, &size) != 0)
1896 if (size != sizeof(struct ClearToken))
1899 if (afs_pd_getBytes(ain, &clear, sizeof(struct ClearToken)) !=0)
1902 if (clear.AuthHandle == -1)
1903 clear.AuthHandle = 999; /* more rxvab compat stuff */
1905 if (afs_pd_remaining(ain) != 0) {
1906 /* still stuff left? we've got primary flag and cell name.
1909 if (afs_pd_getInt(ain, &flag) != 0)
1912 /* some versions of gcc appear to need != 0 in order to get this
1914 if ((flag & 0x8000) != 0) { /* XXX Use Constant XXX */
1919 if (afs_pd_getStringPtr(ain, &cellName) != 0)
1922 code = _settok_tokenCell(cellName, &cellNum, NULL);
1926 /* default to primary cell, primary id */
1927 code = _settok_tokenCell(NULL, &cellNum, &flag);
1932 if (set_parent_pag) {
1933 if (_settok_setParentPag(acred) == 0) {
1934 code = afs_CreateReq(&treq, *acred);
1942 /* now we just set the tokens */
1943 tu = afs_GetUser(areq->uid, cellNum, WRITE_LOCK);
1944 /* Set tokens destroys any that are already there */
1945 afs_FreeTokens(&tu->tokens);
1946 afs_AddRxkadToken(&tu->tokens, stp, stLen, &clear);
1948 afs_stats_cmfullperf.authent.TicketUpdates++;
1949 afs_ComputePAGStats();
1950 #endif /* AFS_NOSTATS */
1951 tu->states |= UHasTokens;
1952 tu->states &= ~UTokensBad;
1953 afs_SetPrimary(tu, flag);
1954 tu->tokenTime = osi_Time();
1955 afs_ResetUserConns(tu);
1956 afs_NotifyUser(tu, UTokensObtained);
1957 afs_PutUser(tu, WRITE_LOCK);
1958 afs_DestroyReq(treq);
1964 * VIOCGETVOLSTAT (4) - Get volume status
1968 * \param[in] ain not in use
1969 * \param[out] aout status of the volume
1971 * \retval EINVAL Error if some of the standard args aren't set
1974 * The status of a volume (based on the FID of the volume), or an
1975 * offline message /motd
1977 DECL_PIOCTL(PGetVolumeStatus)
1980 char *offLineMsg = afs_osi_Alloc(256);
1981 char *motd = afs_osi_Alloc(256);
1982 struct afs_conn *tc;
1984 struct AFSFetchVolumeStatus volstat;
1986 struct rx_connection *rxconn;
1989 osi_Assert(offLineMsg != NULL);
1990 osi_Assert(motd != NULL);
1991 AFS_STATCNT(PGetVolumeStatus);
1998 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK, &rxconn);
2000 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS);
2003 RXAFS_GetVolumeStatus(rxconn, avc->f.fid.Fid.Volume, &volstat,
2004 &Name, &offLineMsg, &motd);
2009 } while (afs_Analyze
2010 (tc, rxconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS,
2011 SHARED_LOCK, NULL));
2015 /* Copy all this junk into msg->im_data, keeping track of the lengths. */
2016 if (afs_pd_putBytes(aout, &volstat, sizeof(VolumeStatus)) != 0)
2018 if (afs_pd_putString(aout, volName) != 0)
2020 if (afs_pd_putString(aout, offLineMsg) != 0)
2022 if (afs_pd_putString(aout, motd) != 0)
2025 afs_osi_Free(offLineMsg, 256);
2026 afs_osi_Free(motd, 256);
2031 * VIOCSETVOLSTAT (5) - Set volume status
2036 * values to set the status at, offline message, message of the day,
2037 * volume name, minimum quota, maximum quota
2039 * status of a volume, offlines messages, minimum quota, maximumm quota
2042 * Error if some of the standard args aren't set
2044 * Error if the volume is read only, or a backup volume
2046 * Error if the volume can't be accessed
2048 * Error if the volume name, offline message, and motd are too big
2051 * Set the status of a volume, including any offline messages,
2052 * a minimum quota, and a maximum quota
2054 DECL_PIOCTL(PSetVolumeStatus)
2059 struct afs_conn *tc;
2061 struct AFSFetchVolumeStatus volstat;
2062 struct AFSStoreVolumeStatus storeStat;
2064 struct rx_connection *rxconn;
2067 AFS_STATCNT(PSetVolumeStatus);
2070 memset(&storeStat, 0, sizeof(storeStat));
2072 tvp = afs_GetVolume(&avc->f.fid, areq, READ_LOCK);
2074 if (tvp->states & (VRO | VBackup)) {
2075 afs_PutVolume(tvp, READ_LOCK);
2078 afs_PutVolume(tvp, READ_LOCK);
2083 if (afs_pd_getBytes(ain, &volstat, sizeof(AFSFetchVolumeStatus)) != 0)
2086 if (afs_pd_getStringPtr(ain, &volName) != 0)
2088 if (strlen(volName) > 32)
2091 if (afs_pd_getStringPtr(ain, &offLineMsg) != 0)
2093 if (strlen(offLineMsg) > 256)
2096 if (afs_pd_getStringPtr(ain, &motd) != 0)
2098 if (strlen(motd) > 256)
2101 /* Done reading ... */
2104 if (volstat.MinQuota != -1) {
2105 storeStat.MinQuota = volstat.MinQuota;
2106 storeStat.Mask |= AFS_SETMINQUOTA;
2108 if (volstat.MaxQuota != -1) {
2109 storeStat.MaxQuota = volstat.MaxQuota;
2110 storeStat.Mask |= AFS_SETMAXQUOTA;
2113 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK, &rxconn);
2115 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS);
2118 RXAFS_SetVolumeStatus(rxconn, avc->f.fid.Fid.Volume, &storeStat,
2119 volName, offLineMsg, motd);
2124 } while (afs_Analyze
2125 (tc, rxconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS,
2126 SHARED_LOCK, NULL));
2130 /* we are sending parms back to make compat. with prev system. should
2131 * change interface later to not ask for current status, just set new
2134 if (afs_pd_putBytes(aout, &volstat, sizeof(VolumeStatus)) != 0)
2136 if (afs_pd_putString(aout, volName) != 0)
2138 if (afs_pd_putString(aout, offLineMsg) != 0)
2140 if (afs_pd_putString(aout, motd) != 0)
2147 * VIOCFLUSH (6) - Invalidate cache entry
2151 * \param[in] ain not in use
2152 * \param[out] aout not in use
2154 * \retval EINVAL Error if some of the standard args aren't set
2156 * \post Flush any information the cache manager has on an entry
2160 AFS_STATCNT(PFlush);
2163 ObtainWriteLock(&avc->lock, 225);
2164 afs_ResetVCache(avc, *acred, 0);
2165 ReleaseWriteLock(&avc->lock);
2170 * VIOC_AFS_STAT_MT_PT (29) - Stat mount point
2175 * the last component in a path, related to mountpoint that we're
2176 * looking for information about
2178 * volume, cell, link data
2180 * \retval EINVAL Error if some of the standard args aren't set
2181 * \retval ENOTDIR Error if the 'mount point' argument isn't a directory
2182 * \retval EIO Error if the link data can't be accessed
2184 * \post Get the volume, and cell, as well as the link data for a mount point
2186 DECL_PIOCTL(PNewStatMount)
2191 struct VenusFid tfid;
2194 struct sysname_info sysState;
2195 afs_size_t offset, len;
2197 AFS_STATCNT(PNewStatMount);
2201 if (afs_pd_getStringPtr(ain, &name) != 0)
2204 code = afs_VerifyVCache(avc, areq);
2207 if (vType(avc) != VDIR) {
2210 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
2213 Check_AtSys(avc, name, &sysState, areq);
2214 ObtainReadLock(&tdc->lock);
2216 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
2217 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
2218 ReleaseReadLock(&tdc->lock);
2219 afs_PutDCache(tdc); /* we're done with the data */
2220 bufp = sysState.name;
2224 tfid.Cell = avc->f.fid.Cell;
2225 tfid.Fid.Volume = avc->f.fid.Fid.Volume;
2226 if (!tfid.Fid.Unique && (avc->f.states & CForeign)) {
2227 tvc = afs_LookupVCache(&tfid, areq, avc, bufp);
2229 tvc = afs_GetVCache(&tfid, areq);
2235 if (tvc->mvstat != AFS_MVSTAT_MTPT) {
2240 ObtainWriteLock(&tvc->lock, 226);
2241 code = afs_HandleLink(tvc, areq);
2243 if (tvc->linkData) {
2244 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
2247 /* we have the data */
2248 if (afs_pd_putString(aout, tvc->linkData) != 0)
2254 ReleaseWriteLock(&tvc->lock);
2257 if (sysState.allocked)
2258 osi_FreeLargeSpace(bufp);
2263 * A helper function to get the n'th cell which a particular user has tokens
2264 * for. This is racy. If new tokens are added whilst we're iterating, then
2265 * we may return some cells twice. If tokens expire mid run, then we'll
2266 * miss some cells from our output. So, could be better, but that would
2267 * require an interface change.
2270 static struct unixuser *
2271 getNthCell(afs_int32 uid, afs_int32 iterator) {
2273 struct unixuser *tu = NULL;
2275 if (iterator > afs_cellindex)
2276 return NULL; /* no point in looking */
2279 ObtainReadLock(&afs_xuser);
2280 for (tu = afs_users[i]; tu; tu = tu->next) {
2281 if (tu->uid == uid && (tu->states & UHasTokens)) {
2282 if (iterator-- == 0)
2283 break; /* are we done yet? */
2289 ReleaseReadLock(&afs_xuser);
2291 afs_LockUser(tu, READ_LOCK, 0);
2298 * VIOCGETTOK (8) - Get authentication tokens
2302 * \param[in] ain cellid to return tokens for
2303 * \param[out] aout token
2306 * Error if the afs daemon hasn't started yet
2308 * Error if the input parameter is out of the bounds of the available
2311 * Error if there aren't tokens for this cell
2314 * If the input paramater exists, get the token that corresponds to
2315 * the parameter value, if there is no token at this value, get the
2316 * token for the first cell
2318 * \notes "it's a weird interface (from comments in the code)"
2321 DECL_PIOCTL(PGetTokens)
2324 struct unixuser *tu = NULL;
2325 union tokenUnion *token;
2326 afs_int32 iterator = 0;
2331 AFS_STATCNT(PGetTokens);
2332 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2333 return EIO; /* Inappropriate ioctl for device */
2335 /* weird interface. If input parameter is present, it is an integer and
2336 * we're supposed to return the parm'th tokens for this unix uid.
2337 * If not present, we just return tokens for cell 1.
2338 * If counter out of bounds, return EDOM.
2339 * If no tokens for the particular cell, return ENOTCONN.
2340 * Also, if this mysterious parm is present, we return, along with the
2341 * tokens, the primary cell indicator (an afs_int32 0) and the cell name
2342 * at the end, in that order.
2344 newStyle = (afs_pd_remaining(ain) > 0);
2346 if (afs_pd_getInt(ain, &iterator) != 0)
2350 tu = getNthCell(areq->uid, iterator);
2352 cellNum = afs_GetPrimaryCellNum();
2354 tu = afs_FindUser(areq->uid, cellNum, READ_LOCK);
2359 if (!(tu->states & UHasTokens)
2360 || !afs_HasUsableTokens(tu->tokens, osi_Time())) {
2361 tu->states |= (UTokensBad | UNeedsReset);
2362 afs_NotifyUser(tu, UTokensDropped);
2363 afs_PutUser(tu, READ_LOCK);
2366 token = afs_FindToken(tu->tokens, RX_SECIDX_KAD);
2368 /* If they don't have an RXKAD token, but do have other tokens,
2369 * then sadly there's nothing this interface can do to help them. */
2373 /* for compat, we try to return 56 byte tix if they fit */
2374 iterator = token->rxkad.ticketLen;
2376 iterator = 56; /* # of bytes we're returning */
2378 if (afs_pd_putInt(aout, iterator) != 0)
2380 if (afs_pd_putBytes(aout, token->rxkad.ticket, token->rxkad.ticketLen) != 0)
2382 if (token->rxkad.ticketLen < 56) {
2383 /* Tokens are always 56 bytes or larger */
2384 if (afs_pd_skip(aout, iterator - token->rxkad.ticketLen) != 0) {
2389 if (afs_pd_putInt(aout, sizeof(struct ClearToken)) != 0)
2391 if (afs_pd_putBytes(aout, &token->rxkad.clearToken,
2392 sizeof(struct ClearToken)) != 0)
2396 /* put out primary id and cell name, too */
2397 iterator = (tu->states & UPrimary ? 1 : 0);
2398 if (afs_pd_putInt(aout, iterator) != 0)
2400 tcell = afs_GetCell(tu->cell, READ_LOCK);
2402 if (afs_pd_putString(aout, tcell->cellName) != 0)
2404 afs_PutCell(tcell, READ_LOCK);
2406 if (afs_pd_putString(aout, "") != 0)
2409 /* Got here, all is good */
2412 afs_PutUser(tu, READ_LOCK);
2417 * VIOCUNLOG (9) - Invalidate tokens
2421 * \param[in] ain not in use
2422 * \param[out] aout not in use
2424 * \retval EIO Error if the afs daemon hasn't been started yet
2426 * \post remove tokens from a user, specified by the user id
2428 * \notes sets the token's time to 0, which then causes it to be removed
2429 * \notes Unlog is the same as un-pag in OpenAFS
2434 struct unixuser *tu;
2436 AFS_STATCNT(PUnlog);
2437 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2438 return EIO; /* Inappropriate ioctl for device */
2440 i = UHash(areq->uid);
2441 ObtainWriteLock(&afs_xuser, 227);
2442 for (tu = afs_users[i]; tu; tu = tu->next) {
2443 if (tu->uid == areq->uid) {
2445 ReleaseWriteLock(&afs_xuser);
2447 afs_LockUser(tu, WRITE_LOCK, 366);
2449 tu->states &= ~UHasTokens;
2450 afs_FreeTokens(&tu->tokens);
2451 afs_NotifyUser(tu, UTokensDropped);
2452 /* We have to drop the lock over the call to afs_ResetUserConns,
2453 * since it obtains the afs_xvcache lock. We could also keep
2454 * the lock, and modify ResetUserConns to take parm saying we
2455 * obtained the lock already, but that is overkill. By keeping
2456 * the "tu" pointer held over the released lock, we guarantee
2457 * that we won't lose our place, and that we'll pass over
2458 * every user conn that existed when we began this call.
2460 afs_ResetUserConns(tu);
2461 afs_PutUser(tu, WRITE_LOCK);
2462 ObtainWriteLock(&afs_xuser, 228);
2464 /* set the expire times to 0, causes
2465 * afs_GCUserData to remove this entry
2468 #endif /* UKERNEL */
2471 ReleaseWriteLock(&afs_xuser);
2476 * VIOC_AFS_MARINER_HOST (32) - Get/set mariner (cache manager monitor) host
2480 * \param[in] ain host address to be set
2481 * \param[out] aout old host address
2484 * depending on whether or not a variable is set, either get the host
2485 * for the cache manager monitor, or set the old address and give it
2488 * \notes Errors turn off mariner
2490 DECL_PIOCTL(PMariner)
2492 afs_int32 newHostAddr;
2493 afs_int32 oldHostAddr;
2495 AFS_STATCNT(PMariner);
2497 memcpy((char *)&oldHostAddr, (char *)&afs_marinerHost,
2500 oldHostAddr = 0xffffffff; /* disabled */
2502 if (afs_pd_getInt(ain, &newHostAddr) != 0)
2505 if (newHostAddr == 0xffffffff) {
2506 /* disable mariner operations */
2508 } else if (newHostAddr) {
2510 afs_marinerHost = newHostAddr;
2513 if (afs_pd_putInt(aout, oldHostAddr) != 0)
2520 * VIOCCKSERV (10) - Check that servers are up
2524 * \param[in] ain name of the cell
2525 * \param[out] aout current down server list
2527 * \retval EIO Error if the afs daemon hasn't started yet
2528 * \retval EACCES Error if the user doesn't have super-user credentials
2529 * \retval ENOENT Error if we are unable to obtain the cell
2532 * Either a fast check (where it doesn't contact servers) or a
2533 * local check (checks local cell only)
2535 DECL_PIOCTL(PCheckServers)
2540 char *cellName = NULL;
2542 struct chservinfo *pcheck;
2544 AFS_STATCNT(PCheckServers);
2546 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2547 return EIO; /* Inappropriate ioctl for device */
2549 /* This is tricky, because we need to peak at the datastream to see
2550 * what we're getting. For now, let's cheat. */
2552 /* ain contains either an int32 or a string */
2553 if (ain->remaining == 0)
2556 if (*(afs_int32 *)ain->ptr == 0x12345678) { /* For afs3.3 version */
2557 pcheck = afs_pd_inline(ain, sizeof(*pcheck));
2561 if (pcheck->tinterval >= 0) {
2562 if (afs_pd_putInt(aout, afs_probe_interval) != 0)
2564 if (pcheck->tinterval > 0) {
2565 if (!afs_osi_suser(*acred))
2567 afs_probe_interval = pcheck->tinterval;
2571 temp = pcheck->tflags;
2573 cellName = pcheck->tbuffer;
2574 } else { /* For pre afs3.3 versions */
2575 if (afs_pd_getInt(ain, &temp) != 0)
2577 if (afs_pd_remaining(ain) > 0) {
2578 if (afs_pd_getStringPtr(ain, &cellName) != 0)
2584 * 1: fast check, don't contact servers.
2585 * 2: local cell only.
2588 /* have cell name, too */
2589 cellp = afs_GetCellByName(cellName, READ_LOCK);
2594 if (!cellp && (temp & 2)) {
2595 /* use local cell */
2596 cellp = afs_GetPrimaryCell(READ_LOCK);
2598 if (!(temp & 1)) { /* if not fast, call server checker routine */
2599 afs_CheckServers(1, cellp); /* check down servers */
2600 afs_CheckServers(0, cellp); /* check up servers */
2602 /* now return the current down server list */
2603 ObtainReadLock(&afs_xserver);
2604 for (i = 0; i < NSERVERS; i++) {
2605 for (ts = afs_servers[i]; ts; ts = ts->next) {
2606 if (cellp && ts->cell != cellp)
2607 continue; /* cell spec'd and wrong */
2608 if ((ts->flags & SRVR_ISDOWN)
2609 && ts->addr->sa_portal != ts->cell->vlport) {
2610 afs_pd_putInt(aout, ts->addr->sa_ip);
2614 ReleaseReadLock(&afs_xserver);
2616 afs_PutCell(cellp, READ_LOCK);
2621 * VIOCCKBACK (11) - Check backup volume mappings
2625 * \param[in] ain not in use
2626 * \param[out] aout not in use
2628 * \retval EIO Error if the afs daemon hasn't started yet
2631 * Check the root volume, and then check the names if the volume
2632 * check variable is set to force, has expired, is busy, or if
2633 * the mount points variable is set
2635 DECL_PIOCTL(PCheckVolNames)
2637 AFS_STATCNT(PCheckVolNames);
2638 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2639 return EIO; /* Inappropriate ioctl for device */
2641 afs_CheckRootVolume();
2642 afs_CheckVolumeNames(AFS_VOLCHECK_FORCE | AFS_VOLCHECK_EXPIRED |
2643 AFS_VOLCHECK_BUSY | AFS_VOLCHECK_MTPTS);
2648 * VIOCCKCONN (12) - Check connections for a user
2652 * \param[in] ain not in use
2653 * \param[out] aout not in use
2656 * Error if no user is specififed, the user has no tokens set,
2657 * or if the user's tokens are bad
2660 * check to see if a user has the correct authentication.
2661 * If so, allow access.
2663 * \notes Check the connections to all the servers specified
2665 DECL_PIOCTL(PCheckAuth)
2669 struct sa_conn_vector *tcv;
2670 struct unixuser *tu;
2673 AFS_STATCNT(PCheckAuth);
2674 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2675 return EIO; /* Inappropriate ioctl for device */
2678 tu = afs_GetUser(areq->uid, 1, READ_LOCK); /* check local cell authentication */
2682 /* we have a user */
2683 ObtainReadLock(&afs_xsrvAddr);
2684 ObtainReadLock(&afs_xconn);
2686 /* any tokens set? */
2687 if ((tu->states & UHasTokens) == 0)
2689 /* all connections in cell 1 working? */
2690 for (i = 0; i < NSERVERS; i++) {
2691 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2692 for (tcv = sa->conns; tcv; tcv = tcv->next) {
2693 if (tcv->user == tu && (tu->states & UTokensBad))
2698 ReleaseReadLock(&afs_xsrvAddr);
2699 ReleaseReadLock(&afs_xconn);
2700 afs_PutUser(tu, READ_LOCK);
2702 if (afs_pd_putInt(aout, retValue) != 0)
2708 Prefetch(uparmtype apath, struct afs_ioctl *adata, int afollow,
2713 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2719 AFS_STATCNT(Prefetch);
2722 tp = osi_AllocLargeSpace(1024);
2723 AFS_COPYINSTR(apath, tp, 1024, &bufferSize, code);
2725 osi_FreeLargeSpace(tp);
2728 if (afs_BBusy()) { /* do this as late as possible */
2729 osi_FreeLargeSpace(tp);
2730 return EWOULDBLOCK; /* pretty close */
2732 afs_BQueue(BOP_PATH, (struct vcache *)0, 0, 0, acred, (afs_size_t) 0,
2733 (afs_size_t) 0, tp, (void *)0, (void *)0);
2738 * VIOCWHEREIS (14) - Find out where a volume is located
2742 * \param[in] ain not in use
2743 * \param[out] aout volume location
2745 * \retval EINVAL Error if some of the default arguments don't exist
2746 * \retval ENODEV Error if there is no such volume
2748 * \post fine a volume, based on a volume file id
2750 * \notes check each of the servers specified
2752 DECL_PIOCTL(PFindVolume)
2759 AFS_STATCNT(PFindVolume);
2762 tvp = afs_GetVolume(&avc->f.fid, areq, READ_LOCK);
2766 for (i = 0; i < AFS_MAXHOSTS; i++) {
2767 ts = tvp->serverHost[i];
2770 if (afs_pd_putInt(aout, ts->addr->sa_ip) != 0) {
2775 if (i < AFS_MAXHOSTS) {
2776 /* still room for terminating NULL, add it on */
2777 if (afs_pd_putInt(aout, 0) != 0) {
2783 afs_PutVolume(tvp, READ_LOCK);
2788 * VIOCACCESS (20) - Access using PRS_FS bits
2792 * \param[in] ain PRS_FS bits
2793 * \param[out] aout not in use
2795 * \retval EINVAL Error if some of the initial arguments aren't set
2796 * \retval EACCES Error if access is denied
2798 * \post check to make sure access is allowed
2800 DECL_PIOCTL(PViceAccess)
2805 AFS_STATCNT(PViceAccess);
2809 code = afs_VerifyVCache(avc, areq);
2813 if (afs_pd_getInt(ain, &temp) != 0)
2816 code = afs_AccessOK(avc, temp, areq, CHECK_MODE_BITS);
2824 * VIOC_GETPAG (13) - Get PAG value
2828 * \param[in] ain not in use
2829 * \param[out] aout PAG value or NOPAG
2831 * \post get PAG value for the caller's cred
2833 DECL_PIOCTL(PGetPAG)
2837 pag = PagInCred(*acred);
2839 return afs_pd_putInt(aout, pag);
2842 DECL_PIOCTL(PPrecache)
2846 /*AFS_STATCNT(PPrecache);*/
2847 if (!afs_osi_suser(*acred))
2850 if (afs_pd_getInt(ain, &newValue) != 0)
2853 afs_preCache = newValue*1024;
2858 * VIOCSETCACHESIZE (24) - Set venus cache size in 1000 units
2862 * \param[in] ain the size the venus cache should be set to
2863 * \param[out] aout not in use
2865 * \retval EACCES Error if the user doesn't have super-user credentials
2866 * \retval EROFS Error if the cache is set to be in memory
2869 * Set the cache size based on user input. If no size is given,
2870 * set it to the default OpenAFS cache size.
2873 * recompute the general cache parameters for every single block allocated
2875 DECL_PIOCTL(PSetCacheSize)
2880 AFS_STATCNT(PSetCacheSize);
2882 if (!afs_osi_suser(*acred))
2884 /* too many things are setup initially in mem cache version */
2885 if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
2887 if (afs_pd_getInt(ain, &newValue) != 0)
2890 afs_cacheBlocks = afs_stats_cmperf.cacheBlocksOrig;
2892 if (newValue < afs_min_cache)
2893 afs_cacheBlocks = afs_min_cache;
2895 afs_cacheBlocks = newValue;
2897 afs_stats_cmperf.cacheBlocksTotal = afs_cacheBlocks;
2898 afs_ComputeCacheParms(); /* recompute basic cache parameters */
2899 afs_MaybeWakeupTruncateDaemon();
2900 while (waitcnt++ < 100 && afs_cacheBlocks < afs_blocksUsed) {
2901 afs_osi_Wait(1000, 0, 0);
2902 afs_MaybeWakeupTruncateDaemon();
2907 #define MAXGCSTATS 16
2909 * VIOCGETCACHEPARMS (40) - Get cache stats
2913 * \param[in] ain afs index flags
2914 * \param[out] aout cache blocks, blocks used, blocks files (in an array)
2916 * \post Get the cache blocks, and how many of the cache blocks there are
2918 DECL_PIOCTL(PGetCacheSize)
2920 afs_int32 results[MAXGCSTATS];
2922 struct dcache * tdc;
2925 AFS_STATCNT(PGetCacheSize);
2927 if (afs_pd_remaining(ain) == sizeof(afs_int32)) {
2928 afs_pd_getInt(ain, &flags); /* can't error, we just checked size */
2929 } else if (afs_pd_remaining(ain) == 0) {
2935 memset(results, 0, sizeof(results));
2936 results[0] = afs_cacheBlocks;
2937 results[1] = afs_blocksUsed;
2938 results[2] = afs_cacheFiles;
2941 for (i = 0; i < afs_cacheFiles; i++) {
2942 if (afs_indexFlags[i] & IFFree) results[3]++;
2944 } else if (2 == flags){
2945 for (i = 0; i < afs_cacheFiles; i++) {
2946 if (afs_indexFlags[i] & IFFree) results[3]++;
2947 if (afs_indexFlags[i] & IFEverUsed) results[4]++;
2948 if (afs_indexFlags[i] & IFDataMod) results[5]++;
2949 if (afs_indexFlags[i] & IFDirtyPages) results[6]++;
2950 if (afs_indexFlags[i] & IFAnyPages) results[7]++;
2951 if (afs_indexFlags[i] & IFDiscarded) results[8]++;
2953 tdc = afs_indexTable[i];
2955 afs_size_t size = tdc->validPos;
2958 if ( 0 <= size && size < (1<<12) ) results[10]++;
2959 else if (size < (1<<14) ) results[11]++;
2960 else if (size < (1<<16) ) results[12]++;
2961 else if (size < (1<<18) ) results[13]++;
2962 else if (size < (1<<20) ) results[14]++;
2963 else if (size >= (1<<20) ) results[15]++;
2967 return afs_pd_putBytes(aout, results, sizeof(results));
2971 * VIOCFLUSHCB (25) - Flush callback only
2975 * \param[in] ain not in use
2976 * \param[out] aout not in use
2978 * \retval EINVAL Error if some of the standard args aren't set
2979 * \retval 0 0 returned if the volume is set to read-only
2982 * Flushes callbacks, by setting the length of callbacks to one,
2983 * setting the next callback to be sent to the CB_DROPPED value,
2984 * and then dequeues everything else.
2986 DECL_PIOCTL(PRemoveCallBack)
2988 struct afs_conn *tc;
2990 struct AFSCallBack CallBacks_Array[1];
2991 struct AFSCBFids theFids;
2992 struct AFSCBs theCBs;
2993 struct rx_connection *rxconn;
2996 AFS_STATCNT(PRemoveCallBack);
2999 if (avc->f.states & CRO)
3000 return 0; /* read-only-ness can't change */
3001 ObtainWriteLock(&avc->lock, 229);
3002 theFids.AFSCBFids_len = 1;
3003 theCBs.AFSCBs_len = 1;
3004 theFids.AFSCBFids_val = (struct AFSFid *)&avc->f.fid.Fid;
3005 theCBs.AFSCBs_val = CallBacks_Array;
3006 CallBacks_Array[0].CallBackType = CB_DROPPED;
3007 if (avc->callback) {
3009 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK, &rxconn);
3011 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
3013 code = RXAFS_GiveUpCallBacks(rxconn, &theFids, &theCBs);
3017 /* don't set code on failure since we wouldn't use it */
3018 } while (afs_Analyze
3019 (tc, rxconn, code, &avc->f.fid, areq,
3020 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK, NULL));
3022 afs_StaleVCacheFlags(avc, AFS_STALEVC_CLEARCB, CUnique);
3024 ReleaseWriteLock(&avc->lock);
3029 * VIOCNEWCELL (26) - Configure new cell
3034 * the name of the cell, the hosts that will be a part of the cell,
3035 * whether or not it's linked with another cell, the other cell it's
3036 * linked with, the file server port, and the volume server port
3040 * \retval EIO Error if the afs daemon hasn't started yet
3041 * \retval EACCES Error if the user doesn't have super-user cedentials
3042 * \retval EINVAL Error if some 'magic' var doesn't have a certain bit set
3044 * \post creates a new cell
3046 DECL_PIOCTL(PNewCell)
3048 afs_int32 cellHosts[AFS_MAXCELLHOSTS], magic = 0;
3049 char *newcell = NULL;
3050 char *linkedcell = NULL;
3052 afs_int32 linkedstate = 0;
3053 afs_int32 fsport = 0, vlport = 0;
3056 AFS_STATCNT(PNewCell);
3057 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3058 return EIO; /* Inappropriate ioctl for device */
3060 if (!afs_osi_suser(*acred))
3063 if (afs_pd_getInt(ain, &magic) != 0)
3065 if (magic != 0x12345678)
3068 /* A 3.4 fs newcell command will pass an array of AFS_MAXCELLHOSTS
3069 * server addresses while the 3.5 fs newcell command passes
3070 * AFS_MAXHOSTS. To figure out which is which, check if the cellname
3073 * This whole logic is bogus, because it relies on the newer command
3074 * sending its 12th address as 0.
3076 if (afs_pd_remaining(ain) < (AFS_MAXCELLHOSTS + 3) * sizeof(afs_int32))
3079 newcell = afs_pd_where(ain) + (AFS_MAXCELLHOSTS + 3) * sizeof(afs_int32);
3080 if (newcell[0] != '\0') {
3083 skip = AFS_MAXHOSTS - AFS_MAXCELLHOSTS;
3086 /* AFS_MAXCELLHOSTS (=8) is less than AFS_MAXHOSTS (=13) */
3087 if (afs_pd_getBytes(ain, &cellHosts,
3088 AFS_MAXCELLHOSTS * sizeof(afs_int32)) != 0)
3090 if (afs_pd_skip(ain, skip * sizeof(afs_int32)) !=0)
3093 if (afs_pd_getInt(ain, &fsport) != 0)
3096 fsport = 0; /* Privileged ports not allowed */
3098 if (afs_pd_getInt(ain, &vlport) != 0)
3101 vlport = 0; /* Privileged ports not allowed */
3103 if (afs_pd_getInt(ain, &ls) != 0)
3106 if (afs_pd_getStringPtr(ain, &newcell) != 0)
3110 if (afs_pd_getStringPtr(ain, &linkedcell) != 0)
3112 linkedstate |= CLinkedCell;
3115 linkedstate |= CNoSUID; /* setuid is disabled by default for fs newcell */
3117 afs_NewCell(newcell, cellHosts, linkedstate, linkedcell, fsport,
3122 DECL_PIOCTL(PNewAlias)
3124 /* create a new cell alias */
3125 char *realName, *aliasName;
3127 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3128 return EIO; /* Inappropriate ioctl for device */
3130 if (!afs_osi_suser(*acred))
3133 if (afs_pd_getStringPtr(ain, &aliasName) != 0)
3135 if (afs_pd_getStringPtr(ain, &realName) != 0)
3138 return afs_NewCellAlias(aliasName, realName);
3142 * VIOCGETCELL (27) - Get cell info
3146 * \param[in] ain The cell index of a specific cell
3147 * \param[out] aout list of servers in the cell
3149 * \retval EIO Error if the afs daemon hasn't started yet
3150 * \retval EDOM Error if there is no cell asked about
3152 * \post Lists the cell's server names and and addresses
3154 DECL_PIOCTL(PListCells)
3156 afs_int32 whichCell;
3157 struct cell *tcell = 0;
3161 AFS_STATCNT(PListCells);
3162 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3163 return EIO; /* Inappropriate ioctl for device */
3165 if (afs_pd_getInt(ain, &whichCell) != 0)
3168 tcell = afs_GetCellByIndex(whichCell, READ_LOCK);
3174 for (i = 0; i < AFS_MAXCELLHOSTS; i++) {
3175 if (tcell->cellHosts[i] == 0)
3177 if (afs_pd_putInt(aout, tcell->cellHosts[i]->addr->sa_ip) != 0)
3180 for (;i < AFS_MAXCELLHOSTS; i++) {
3181 if (afs_pd_putInt(aout, 0) != 0)
3184 if (afs_pd_putString(aout, tcell->cellName) != 0)
3189 afs_PutCell(tcell, READ_LOCK);
3193 DECL_PIOCTL(PListAliases)
3195 afs_int32 whichAlias;
3196 struct cell_alias *tcalias = 0;
3199 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3200 return EIO; /* Inappropriate ioctl for device */
3202 if (afs_pd_getInt(ain, &whichAlias) != 0)
3205 tcalias = afs_GetCellAlias(whichAlias);
3206 if (tcalias == NULL)
3210 if (afs_pd_putString(aout, tcalias->alias) != 0)
3212 if (afs_pd_putString(aout, tcalias->cell) != 0)
3217 afs_PutCellAlias(tcalias);
3222 * VIOC_AFS_DELETE_MT_PT (28) - Delete mount point
3226 * \param[in] ain the name of the file in this dir to remove
3227 * \param[out] aout not in use
3230 * Error if some of the standard args aren't set
3232 * Error if the argument to remove is not a directory
3234 * Error if there is no cache to remove the mount point from or
3235 * if a vcache doesn't exist
3238 * Ensure that everything is OK before deleting the mountpoint.
3239 * If not, don't delete. Delete a mount point based on a file id.
3241 DECL_PIOCTL(PRemoveMount)
3246 struct sysname_info sysState;
3247 afs_size_t offset, len;
3248 struct afs_conn *tc;
3251 struct AFSFetchStatus OutDirStatus;
3252 struct VenusFid tfid;
3253 struct AFSVolSync tsync;
3254 struct rx_connection *rxconn;
3257 /* "ain" is the name of the file in this dir to remove */
3259 AFS_STATCNT(PRemoveMount);
3262 if (afs_pd_getStringPtr(ain, &name) != 0)
3265 code = afs_VerifyVCache(avc, areq);
3268 if (vType(avc) != VDIR)
3271 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1); /* test for error below */
3274 Check_AtSys(avc, name, &sysState, areq);
3275 ObtainReadLock(&tdc->lock);
3277 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
3278 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
3279 ReleaseReadLock(&tdc->lock);
3280 bufp = sysState.name;
3285 tfid.Cell = avc->f.fid.Cell;
3286 tfid.Fid.Volume = avc->f.fid.Fid.Volume;
3287 if (!tfid.Fid.Unique && (avc->f.states & CForeign)) {
3288 tvc = afs_LookupVCache(&tfid, areq, avc, bufp);
3290 tvc = afs_GetVCache(&tfid, areq);
3297 if (tvc->mvstat != AFS_MVSTAT_MTPT) {
3303 ObtainWriteLock(&tvc->lock, 230);
3304 code = afs_HandleLink(tvc, areq);
3306 if (tvc->linkData) {
3307 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
3312 ReleaseWriteLock(&tvc->lock);
3313 osi_dnlc_purgedp(tvc);
3319 ObtainWriteLock(&avc->lock, 231);
3320 osi_dnlc_remove(avc, bufp, tvc);
3322 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK, &rxconn);
3324 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE);
3327 RXAFS_RemoveFile(rxconn, (struct AFSFid *)&avc->f.fid.Fid, bufp,
3328 &OutDirStatus, &tsync);
3333 } while (afs_Analyze
3334 (tc, rxconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_REMOVEFILE,
3335 SHARED_LOCK, NULL));
3340 ReleaseWriteLock(&avc->lock);
3344 /* we have the thing in the cache */
3345 ObtainWriteLock(&tdc->lock, 661);
3346 if (afs_LocalHero(avc, tdc, &OutDirStatus, 1)) {
3347 /* we can do it locally */
3348 code = afs_dir_Delete(tdc, bufp);
3350 ZapDCE(tdc); /* surprise error -- invalid value */
3354 ReleaseWriteLock(&tdc->lock);
3355 afs_PutDCache(tdc); /* drop ref count */
3357 avc->f.states &= ~CUnique; /* For the dfs xlator */
3358 ReleaseWriteLock(&avc->lock);
3361 if (sysState.allocked)
3362 osi_FreeLargeSpace(bufp);
3367 * VIOC_GETCELLSTATUS (35) - Get cell status info
3371 * \param[in] ain The cell you want status information on
3372 * \param[out] aout cell state (as a struct)
3374 * \retval EIO Error if the afs daemon hasn't started yet
3375 * \retval ENOENT Error if the cell doesn't exist
3377 * \post Returns the state of the cell as defined in a struct cell
3379 DECL_PIOCTL(PGetCellStatus)
3385 AFS_STATCNT(PGetCellStatus);
3386 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3387 return EIO; /* Inappropriate ioctl for device */
3389 if (afs_pd_getStringPtr(ain, &cellName) != 0)
3392 tcell = afs_GetCellByName(cellName, READ_LOCK);
3395 temp = tcell->states;
3396 afs_PutCell(tcell, READ_LOCK);
3398 return afs_pd_putInt(aout, temp);
3402 * VIOC_SETCELLSTATUS (36) - Set corresponding info
3407 * The cell you want to set information about, and the values you
3412 * \retval EIO Error if the afs daemon hasn't started yet
3413 * \retval EACCES Error if the user doesn't have super-user credentials
3416 * Set the state of the cell in a defined struct cell, based on
3417 * whether or not SetUID is allowed
3419 DECL_PIOCTL(PSetCellStatus)
3423 afs_int32 flags0, flags1;
3425 if (!afs_osi_suser(*acred))
3427 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3428 return EIO; /* Inappropriate ioctl for device */
3430 if (afs_pd_getInt(ain, &flags0) != 0)
3432 if (afs_pd_getInt(ain, &flags1) != 0)
3434 if (afs_pd_getStringPtr(ain, &cellName) != 0)
3437 tcell = afs_GetCellByName(cellName, WRITE_LOCK);
3440 if (flags0 & CNoSUID)
3441 tcell->states |= CNoSUID;
3443 tcell->states &= ~CNoSUID;
3444 afs_PutCell(tcell, WRITE_LOCK);
3449 FlushVolumeData(struct VenusFid *afid, afs_ucred_t * acred)
3457 afs_int32 volume = 0;
3458 struct afs_q *tq, *uq;
3460 #ifdef AFS_DARWIN80_ENV
3467 volume = afid->Fid.Volume; /* who to zap */
3472 * Clear stat'd flag from all vnodes from this volume; this will
3473 * invalidate all the vcaches associated with the volume.
3476 ObtainReadLock(&afs_xvcache);
3477 for (i = (afid ? VCHashV(afid) : 0); i < VCSIZE; i = (afid ? VCSIZE : i+1)) {
3478 for (tq = afs_vhashTV[i].prev; tq != &afs_vhashTV[i]; tq = uq) {
3481 if (all || (tvc->f.fid.Fid.Volume == volume && tvc->f.fid.Cell == cell)) {
3482 if (tvc->f.states & CVInit) {
3483 ReleaseReadLock(&afs_xvcache);
3484 afs_osi_Sleep(&tvc->f.states);
3487 #ifdef AFS_DARWIN80_ENV
3488 if (tvc->f.states & CDeadVnode) {
3489 ReleaseReadLock(&afs_xvcache);
3490 afs_osi_Sleep(&tvc->f.states);
3496 if (vnode_ref(vp)) {
3505 ReleaseReadLock(&afs_xvcache);
3506 ObtainWriteLock(&tvc->lock, 232);
3507 afs_ResetVCache(tvc, acred, 1);
3508 ReleaseWriteLock(&tvc->lock);
3509 #ifdef AFS_DARWIN80_ENV
3510 vnode_put(AFSTOV(tvc));
3512 ObtainReadLock(&afs_xvcache);
3514 /* our tvc ptr is still good until now */
3519 ReleaseReadLock(&afs_xvcache);
3522 ObtainWriteLock(&afs_xdcache, 328); /* needed to flush any stuff */
3523 for (i = 0; i < afs_cacheFiles; i++) {
3524 if (!(afs_indexFlags[i] & IFEverUsed))
3525 continue; /* never had any data */
3526 tdc = afs_GetValidDSlot(i);
3531 if (tdc->refCount <= 1) { /* too high, in use by running sys call */
3532 ReleaseReadLock(&tdc->tlock);
3533 if (all || (tdc->f.fid.Fid.Volume == volume && tdc->f.fid.Cell == cell)) {
3534 if (!(afs_indexFlags[i] & (IFDataMod | IFFree | IFDiscarded))) {
3535 /* if the file is modified, but has a ref cnt of only 1,
3536 * then someone probably has the file open and is writing
3537 * into it. Better to skip flushing such a file, it will be
3538 * brought back immediately on the next write anyway.
3540 * Skip if already freed.
3542 * If we *must* flush, then this code has to be rearranged
3543 * to call afs_storeAllSegments() first */
3544 afs_FlushDCache(tdc);
3548 ReleaseReadLock(&tdc->tlock);
3550 afs_PutDCache(tdc); /* bumped by getdslot */
3552 ReleaseWriteLock(&afs_xdcache);
3554 ObtainReadLock(&afs_xvolume);
3555 for (i = all ? 0 : VHash(volume); i < NVOLS; i++) {
3556 for (tv = afs_volumes[i]; tv; tv = tv->next) {
3557 if (all || tv->volume == volume) {
3558 afs_ResetVolumeInfo(tv);
3565 ReleaseReadLock(&afs_xvolume);
3567 /* probably, a user is doing this, probably, because things are screwed up.
3568 * maybe it's the dnlc's fault? */
3574 * VIOC_FLUSHVOLUME (37) - Flush whole volume's data
3578 * \param[in] ain not in use (args in avc)
3579 * \param[out] aout not in use
3581 * \retval EINVAL Error if some of the standard args aren't set
3582 * \retval EIO Error if the afs daemon hasn't started yet
3585 * Flush all cached contents of a volume. Exactly what stays and what
3586 * goes depends on the platform.
3589 * Does not flush a file that a user has open and is using, because
3590 * it will be re-created on next write. Also purges the dnlc,
3591 * because things are screwed up.
3593 DECL_PIOCTL(PFlushVolumeData)
3595 AFS_STATCNT(PFlushVolumeData);
3598 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3599 return EIO; /* Inappropriate ioctl for device */
3601 return FlushVolumeData(&avc->f.fid, *acred);
3605 * VIOC_FLUSHALL (14) - Flush whole volume's data for all volumes
3609 * \param[in] ain not in use
3610 * \param[out] aout not in use
3612 * \retval EINVAL Error if some of the standard args aren't set
3613 * \retval EIO Error if the afs daemon hasn't started yet
3616 * Flush all cached contents. Exactly what stays and what
3617 * goes depends on the platform.
3620 * Does not flush a file that a user has open and is using, because
3621 * it will be re-created on next write. Also purges the dnlc,
3622 * because things are screwed up.
3624 DECL_PIOCTL(PFlushAllVolumeData)
3626 AFS_STATCNT(PFlushAllVolumeData);
3628 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3629 return EIO; /* Inappropriate ioctl for device */
3631 return FlushVolumeData(NULL, *acred);
3635 * VIOCGETVCXSTATUS (41) - gets vnode x status
3640 * not in use (avc used)
3642 * vcxstat: the file id, the data version, any lock, the parent vnode,
3643 * the parent unique id, the trunc position, the callback, cbExpires,
3644 * what access is being made, what files are open,
3645 * any users executing/writing, the flock count, the states,
3649 * Error if some of the initial default arguments aren't set
3651 * Error if access to check the mode bits is denied
3654 * gets stats for the vnode, a struct listed in vcxstat
3656 DECL_PIOCTL(PGetVnodeXStatus)
3659 struct vcxstat stat;
3662 /* AFS_STATCNT(PGetVnodeXStatus); */
3665 code = afs_VerifyVCache(avc, areq);
3668 if (vType(avc) == VDIR)
3669 mode = PRSFS_LOOKUP;
3672 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
3675 memset(&stat, 0, sizeof(struct vcxstat));
3676 stat.fid = avc->f.fid;
3677 hset32(stat.DataVersion, hgetlo(avc->f.m.DataVersion));
3678 stat.lock = avc->lock;
3679 stat.parentVnode = avc->f.parent.vnode;
3680 stat.parentUnique = avc->f.parent.unique;
3681 hset(stat.flushDV, avc->flushDV);
3682 hset(stat.mapDV, avc->mapDV);
3683 stat.truncPos = avc->f.truncPos;
3684 { /* just grab the first two - won't break anything... */
3685 struct axscache *ac;
3687 for (i = 0, ac = avc->Access; ac && i < CPSIZE; i++, ac = ac->next) {
3688 stat.randomUid[i] = ac->uid;
3689 stat.randomAccess[i] = ac->axess;
3692 stat.callback = afs_data_pointer_to_int32(avc->callback);
3693 stat.cbExpires = avc->cbExpires;
3694 stat.anyAccess = avc->f.anyAccess;
3695 stat.opens = avc->opens;
3696 stat.execsOrWriters = avc->execsOrWriters;
3697 stat.flockCount = avc->flockCount;
3698 stat.mvstat = avc->mvstat;
3699 stat.states = avc->f.states;
3700 return afs_pd_putBytes(aout, &stat, sizeof(struct vcxstat));
3704 DECL_PIOCTL(PGetVnodeXStatus2)
3707 struct vcxstat2 stat;
3712 code = afs_VerifyVCache(avc, areq);
3715 if (vType(avc) == VDIR)
3716 mode = PRSFS_LOOKUP;
3719 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
3722 memset(&stat, 0, sizeof(struct vcxstat2));
3724 stat.cbExpires = avc->cbExpires;
3725 stat.anyAccess = avc->f.anyAccess;
3726 stat.mvstat = avc->mvstat;
3727 stat.callerAccess = afs_GetAccessBits(avc, ~0, areq);
3729 return afs_pd_putBytes(aout, &stat, sizeof(struct vcxstat2));
3734 * VIOC_AFS_SYSNAME (38) - Change @sys value
3738 * \param[in] ain new value for @sys
3739 * \param[out] aout count, entry, list (debug values?)
3742 * Error if afsd isn't running, the new sysname is too large,
3743 * the new sysname causes issues (starts with a . or ..),
3744 * there is no PAG set in the credentials, or the user of a PAG
3747 * Error if the user doesn't have super-user credentials
3750 * Set the value of @sys if these things work: if the input isn't
3751 * too long or if input doesn't start with . or ..
3754 * We require root for local sysname changes, but not for remote
3755 * (since we don't really believe remote uids anyway)
3756 * outname[] shouldn't really be needed- this is left as an
3757 * exercise for the reader.
3759 DECL_PIOCTL(PSetSysName)
3761 char *inname = NULL;
3762 char outname[MAXSYSNAME];
3763 afs_int32 setsysname;
3765 struct afs_exporter *exporter;
3766 struct unixuser *au;
3767 afs_int32 pag, error;
3768 int t, count, num = 0, allpags = 0;
3770 struct afs_pdata validate;
3772 AFS_STATCNT(PSetSysName);
3773 if (!afs_globalVFS) {
3774 /* Afsd is NOT running; disable it */
3775 #if defined(KERNEL_HAVE_UERROR)
3776 return (setuerror(EINVAL), EINVAL);
3781 if (afs_pd_getInt(ain, &setsysname) != 0)
3783 if (setsysname & 0x8000) {
3785 setsysname &= ~0x8000;
3790 if (setsysname < 0 || setsysname > MAXNUMSYSNAMES)
3793 for (count = 0; count < setsysname; count++) {
3794 if (afs_pd_getStringPtr(&validate, &inname) != 0)
3797 if (t >= MAXSYSNAME || t <= 0)
3799 /* check for names that can shoot us in the foot */
3800 if (inname[0] == '.' && (inname[1] == 0
3801 || (inname[1] == '.' && inname[2] == 0)))
3804 /* args ok, so go back to the beginning of that section */
3806 if (afs_pd_getStringPtr(ain, &inname) != 0)
3810 if (afs_rmtsys_enable && (afs_cr_gid(*acred) == RMTUSER_REQ ||
3811 afs_cr_gid(*acred) == RMTUSER_REQ_PRIV)) { /* Handles all exporters */
3812 if (allpags && afs_cr_gid(*acred) != RMTUSER_REQ_PRIV) {
3815 pag = PagInCred(*acred);
3817 return EINVAL; /* Better than panicing */
3819 if (!(au = afs_FindUser(pag, -1, READ_LOCK))) {
3820 return EINVAL; /* Better than panicing */
3822 if (!(exporter = au->exporter)) {
3823 afs_PutUser(au, READ_LOCK);
3824 return EINVAL; /* Better than panicing */
3826 error = EXP_SYSNAME(exporter, inname, &sysnamelist,
3829 if (error == ENODEV)
3830 foundname = 0; /* sysname not set yet! */
3832 afs_PutUser(au, READ_LOCK);
3837 strcpy(outname, sysnamelist[0]);
3839 afs_PutUser(au, READ_LOCK);
3843 /* Not xlating, so local case */
3845 osi_Panic("PSetSysName: !afs_sysname\n");
3846 if (!setsysname) { /* user just wants the info */
3847 strcpy(outname, afs_sysname);
3848 foundname = afs_sysnamecount;
3849 sysnamelist = afs_sysnamelist;
3850 } else { /* Local guy; only root can change sysname */
3851 if (!afs_osi_suser(*acred))
3854 /* allpags makes no sense for local use */
3858 /* clear @sys entries from the dnlc, once afs_lookup can
3859 * do lookups of @sys entries and thinks it can trust them */
3860 /* privs ok, store the entry, ... */
3862 if (strlen(inname) >= MAXSYSNAME-1)
3864 strcpy(afs_sysname, inname);
3866 if (setsysname > 1) { /* ... or list */
3867 for (count = 1; count < setsysname; ++count) {
3868 if (!afs_sysnamelist[count])
3870 ("PSetSysName: no afs_sysnamelist entry to write\n");
3871 if (afs_pd_getString(ain, afs_sysnamelist[count],
3876 afs_sysnamecount = setsysname;
3881 if (afs_pd_putInt(aout, foundname) != 0)
3884 if (afs_pd_putString(aout, outname) != 0)
3886 for (count = 1; count < foundname; ++count) { /* ... or list. */
3887 if (!sysnamelist[count])
3889 ("PSetSysName: no afs_sysnamelist entry to read\n");
3890 t = strlen(sysnamelist[count]);
3891 if (t >= MAXSYSNAME)
3892 osi_Panic("PSetSysName: sysname entry garbled\n");
3893 if (afs_pd_putString(aout, sysnamelist[count]) != 0)
3901 /* sequential search through the list of touched cells is not a good
3902 * long-term solution here. For small n, though, it should be just
3903 * fine. Should consider special-casing the local cell for large n.
3904 * Likewise for PSetSPrefs.
3906 * s - number of ids in array l[] -- NOT index of last id
3907 * l - array of cell ids which have volumes that need to be sorted
3908 * vlonly - sort vl servers or file servers?
3911 ReSortCells_cb(struct cell *cell, void *arg)
3913 afs_int32 *p = (afs_int32 *) arg;
3914 afs_int32 *l = p + 1;
3917 for (i = 0; i < s; i++) {
3918 if (l[i] == cell->cellNum) {
3919 ObtainWriteLock(&cell->lock, 690);
3920 afs_SortServers(cell->cellHosts, AFS_MAXCELLHOSTS);
3921 ReleaseWriteLock(&cell->lock);
3929 ReSortCells(int s, afs_int32 * l, int vlonly)
3937 p = afs_osi_Alloc(sizeof(afs_int32) * (s + 1));
3938 osi_Assert(p != NULL);
3940 memcpy(p + 1, l, s * sizeof(afs_int32));
3941 afs_TraverseCells(&ReSortCells_cb, p);
3942 afs_osi_Free(p, sizeof(afs_int32) * (s + 1));
3946 ObtainReadLock(&afs_xvolume);
3947 for (i = 0; i < NVOLS; i++) {
3948 for (j = afs_volumes[i]; j; j = j->next) {
3949 for (k = 0; k < s; k++)
3950 if (j->cell == l[k]) {
3951 ObtainWriteLock(&j->lock, 233);
3952 afs_SortServers(j->serverHost, AFS_MAXHOSTS);
3953 ReleaseWriteLock(&j->lock);
3958 ReleaseReadLock(&afs_xvolume);
3962 static int debugsetsp = 0;
3964 afs_setsprefs(struct spref *sp, unsigned int num, unsigned int vlonly)
3967 int i, j, k, matches, touchedSize;
3968 struct server *srvr = NULL;
3969 afs_int32 touched[34];
3973 for (k = 0; k < num; sp++, k++) {
3975 afs_warn("sp host=%x, rank=%d\n", sp->host.s_addr, sp->rank);
3978 ObtainReadLock(&afs_xserver);
3980 i = SHash(sp->host.s_addr);
3981 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3982 if (sa->sa_ip == sp->host.s_addr) {
3984 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
3985 || (sa->sa_portal == AFS_FSPORT);
3986 if ((!vlonly && isfs) || (vlonly && !isfs)) {
3993 if (sa && matches) { /* found one! */
3995 afs_warn("sa ip=%x, ip_rank=%d\n", sa->sa_ip, sa->sa_iprank);
3997 sa->sa_iprank = sp->rank + afs_randomMod15();
3998 afs_SortOneServer(sa->server);
4001 /* if we don't know yet what cell it's in, this is moot */
4002 for (j = touchedSize - 1;
4003 j >= 0 && touched[j] != srvr->cell->cellNum; j--)
4004 /* is it in our list of touched cells ? */ ;
4005 if (j < 0) { /* no, it's not */
4006 touched[touchedSize++] = srvr->cell->cellNum;
4007 if (touchedSize >= 32) { /* watch for ovrflow */
4008 ReleaseReadLock(&afs_xserver);
4009 ReSortCells(touchedSize, touched, vlonly);
4011 ObtainReadLock(&afs_xserver);
4017 ReleaseReadLock(&afs_xserver);
4018 /* if we didn't find one, start to create one. */
4019 /* Note that it doesn't have a cell yet... */
4021 afs_uint32 temp = sp->host.s_addr;
4023 afs_GetServer(&temp, 1, 0, (vlonly ? AFS_VLPORT : AFS_FSPORT),
4024 WRITE_LOCK, (afsUUID *) 0, 0, NULL);
4025 srvr->addr->sa_iprank = sp->rank + afs_randomMod15();
4026 afs_PutServer(srvr, WRITE_LOCK);
4028 } /* for all cited preferences */
4030 ReSortCells(touchedSize, touched, vlonly);
4035 * VIOC_SETPREFS (46) - Set server ranks
4037 * \param[in] ain the sprefs value you want the sprefs to be set to
4038 * \param[out] aout not in use
4041 * Error if the afs daemon hasn't started yet
4043 * Error if the user doesn't have super-user credentials
4045 * Error if the struct setsprefs is too large or if it multiplied
4046 * by the number of servers is too large
4048 * \post set the sprefs using the afs_setsprefs() function
4050 DECL_PIOCTL(PSetSPrefs)
4052 struct setspref *ssp;
4056 AFS_STATCNT(PSetSPrefs);
4058 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4059 return EIO; /* Inappropriate ioctl for device */
4061 if (!afs_osi_suser(*acred))
4064 /* The I/O handling here is ghastly, as it relies on overrunning the ends
4065 * of arrays. But, i'm not quite brave enough to change it yet. */
4067 ainSize = ain->remaining;
4069 if (ainSize < sizeof(struct setspref))
4072 ssp = (struct setspref *)ainPtr;
4073 if (ainSize < (sizeof(struct setspref)
4074 + sizeof(struct spref) * (ssp->num_servers-1)))
4077 afs_setsprefs(&(ssp->servers[0]), ssp->num_servers,
4078 (ssp->flags & DBservers));
4083 * VIOC_SETPREFS33 (42) - Set server ranks (deprecated)
4085 * \param[in] ain the server preferences to be set
4086 * \param[out] aout not in use
4088 * \retval EIO Error if the afs daemon hasn't started yet
4089 * \retval EACCES Error if the user doesn't have super-user credentials
4091 * \post set the server preferences, calling a function
4093 * \notes this may only be performed by the local root user.
4095 DECL_PIOCTL(PSetSPrefs33)
4097 AFS_STATCNT(PSetSPrefs);
4098 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4099 return EIO; /* Inappropriate ioctl for device */
4102 if (!afs_osi_suser(*acred))
4105 afs_setsprefs((struct spref *)afs_pd_where(ain),
4106 afs_pd_remaining(ain) / sizeof(struct spref),
4112 * VIOC_GETSPREFS (43) - Get server ranks
4116 * \param[in] ain the server preferences to get
4117 * \param[out] aout the server preferences information
4119 * \retval EIO Error if the afs daemon hasn't started yet
4120 * \retval ENOENT Error if the sprefrequest is too large
4122 * \post Get the sprefs
4125 * in the hash table of server structs, all servers with the same
4126 * IP address; will be on the same overflow chain; This could be
4127 * sped slightly in some circumstances by having it cache the
4128 * immediately previous slot in the hash table and some
4129 * supporting information; Only reports file servers now.
4131 DECL_PIOCTL(PGetSPrefs)
4133 struct sprefrequest spin; /* input */
4134 struct sprefinfo *spout; /* output */
4135 struct spref *srvout; /* one output component */
4136 int i, j; /* counters for hash table traversal */
4137 struct server *srvr; /* one of CM's server structs */
4139 int vlonly; /* just return vlservers ? */
4142 AFS_STATCNT(PGetSPrefs);
4143 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4144 return EIO; /* Inappropriate ioctl for device */
4146 /* Work out from the size whether we've got a new, or old, style pioctl */
4147 if (afs_pd_remaining(ain) < sizeof(struct sprefrequest)) {
4148 if (afs_pd_getBytes(ain, &spin, sizeof(struct sprefrequest_33)) != 0)
4153 if (afs_pd_getBytes(ain, &spin, sizeof(struct sprefrequest)) != 0)
4155 vlonly = (spin.flags & DBservers);
4158 /* This code relies on overflowing arrays. It's ghastly, but I'm not
4159 * quite brave enough to tackle it yet ...
4162 /* struct sprefinfo includes 1 server struct... that size gets added
4163 * in during the loop that follows.
4165 spout = afs_pd_inline(aout,
4166 sizeof(struct sprefinfo) - sizeof(struct spref));
4167 spout->next_offset = spin.offset;
4168 spout->num_servers = 0;
4169 srvout = spout->servers;
4171 ObtainReadLock(&afs_xserver);
4172 for (i = 0, j = 0; j < NSERVERS; j++) { /* sift through hash table */
4173 for (sa = afs_srvAddrs[j]; sa; sa = sa->next_bkt, i++) {
4174 if (spin.offset > (unsigned short)i) {
4175 continue; /* catch up to where we left off */
4177 spout->next_offset++;
4180 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
4181 || (sa->sa_portal == AFS_FSPORT);
4183 if ((vlonly && isfs) || (!vlonly && !isfs)) {
4184 /* only report ranks for vl servers */
4188 /* Check we've actually got the space we're about to use */
4189 if (afs_pd_inline(aout, sizeof(struct spref)) == NULL) {
4190 ReleaseReadLock(&afs_xserver); /* no more room! */
4194 srvout->host.s_addr = sa->sa_ip;
4195 srvout->rank = sa->sa_iprank;
4196 spout->num_servers++;
4200 ReleaseReadLock(&afs_xserver);
4202 spout->next_offset = 0; /* start over from the beginning next time */
4207 /* Enable/Disable the specified exporter. Must be root to disable an exporter */
4208 int afs_NFSRootOnly = 1;
4210 * VIOC_EXPORTAFS (39) - Export afs to nfs clients
4215 * an integer containing the desired exportee flags
4217 * an integer containing the current exporter flags
4219 * \retval ENODEV Error if the exporter doesn't exist
4220 * \retval EACCES Error if the user doesn't have super-user credentials
4223 * Changes the state of various values to reflect the change
4224 * of the export values between nfs and afs.
4226 * \notes Legacy code obtained from IBM.
4228 DECL_PIOCTL(PExportAfs)
4230 afs_int32 export, newint = 0;
4231 afs_int32 type, changestate, handleValue, convmode, pwsync, smounts;
4232 afs_int32 rempags = 0, pagcb = 0;
4233 struct afs_exporter *exporter;
4235 AFS_STATCNT(PExportAfs);
4236 if (afs_pd_getInt(ain, &handleValue) != 0)
4238 type = handleValue >> 24;
4243 exporter = exporter_find(type);
4245 export = handleValue & 3;
4246 changestate = handleValue & 0xfff;
4247 smounts = (handleValue >> 2) & 3;
4248 pwsync = (handleValue >> 4) & 3;
4249 convmode = (handleValue >> 6) & 3;
4250 rempags = (handleValue >> 8) & 3;
4251 pagcb = (handleValue >> 10) & 3;
4253 changestate = (handleValue >> 16) & 0x1;
4254 convmode = (handleValue >> 16) & 0x2;
4255 pwsync = (handleValue >> 16) & 0x4;
4256 smounts = (handleValue >> 16) & 0x8;
4257 export = handleValue & 0xff;
4260 /* Failed finding desired exporter; */
4264 handleValue = exporter->exp_states;
4265 if (afs_pd_putInt(aout, handleValue) != 0)
4268 if (!afs_osi_suser(*acred))
4269 return EACCES; /* Only superuser can do this */
4273 exporter->exp_states |= EXP_EXPORTED;
4275 exporter->exp_states &= ~EXP_EXPORTED;
4279 exporter->exp_states |= EXP_UNIXMODE;
4281 exporter->exp_states &= ~EXP_UNIXMODE;
4285 exporter->exp_states |= EXP_PWSYNC;
4287 exporter->exp_states &= ~EXP_PWSYNC;
4291 afs_NFSRootOnly = 0;
4292 exporter->exp_states |= EXP_SUBMOUNTS;
4294 afs_NFSRootOnly = 1;
4295 exporter->exp_states &= ~EXP_SUBMOUNTS;
4300 exporter->exp_states |= EXP_CLIPAGS;
4302 exporter->exp_states &= ~EXP_CLIPAGS;
4306 exporter->exp_states |= EXP_CALLBACK;
4308 exporter->exp_states &= ~EXP_CALLBACK;
4310 handleValue = exporter->exp_states;
4311 if (afs_pd_putInt(aout, handleValue) != 0)
4315 exporter->exp_states |= EXP_EXPORTED;
4317 exporter->exp_states &= ~EXP_EXPORTED;
4319 exporter->exp_states |= EXP_UNIXMODE;
4321 exporter->exp_states &= ~EXP_UNIXMODE;
4323 exporter->exp_states |= EXP_PWSYNC;
4325 exporter->exp_states &= ~EXP_PWSYNC;
4327 afs_NFSRootOnly = 0;
4328 exporter->exp_states |= EXP_SUBMOUNTS;
4330 afs_NFSRootOnly = 1;
4331 exporter->exp_states &= ~EXP_SUBMOUNTS;
4340 * VIOC_GAG (44) - Silence Cache Manager
4344 * \param[in] ain the flags to either gag or de-gag the cache manager
4345 * \param[out] aout not in use
4347 * \retval EACCES Error if the user doesn't have super-user credentials
4349 * \post set the gag flags, then show these flags
4353 struct gaginfo *gagflags;
4355 if (!afs_osi_suser(*acred))
4358 gagflags = afs_pd_inline(ain, sizeof(*gagflags));
4359 if (gagflags == NULL)
4361 afs_showflags = gagflags->showflags;
4367 * VIOC_TWIDDLE (45) - Adjust RX knobs
4371 * \param[in] ain the previous settings of the 'knobs'
4372 * \param[out] aout not in use
4374 * \retval EACCES Error if the user doesn't have super-user credentials
4376 * \post build out the struct rxp, from a struct rx
4378 DECL_PIOCTL(PTwiddleRx)
4380 struct rxparams *rxp;
4382 if (!afs_osi_suser(*acred))
4385 rxp = afs_pd_inline(ain, sizeof(*rxp));
4389 if (rxp->rx_initReceiveWindow)
4390 rx_initReceiveWindow = rxp->rx_initReceiveWindow;
4391 if (rxp->rx_maxReceiveWindow)
4392 rx_maxReceiveWindow = rxp->rx_maxReceiveWindow;
4393 if (rxp->rx_initSendWindow)
4394 rx_initSendWindow = rxp->rx_initSendWindow;
4395 if (rxp->rx_maxSendWindow)
4396 rx_maxSendWindow = rxp->rx_maxSendWindow;
4397 if (rxp->rxi_nSendFrags)
4398 rxi_nSendFrags = rxp->rxi_nSendFrags;
4399 if (rxp->rxi_nRecvFrags)
4400 rxi_nRecvFrags = rxp->rxi_nRecvFrags;
4401 if (rxp->rxi_OrphanFragSize)
4402 rxi_OrphanFragSize = rxp->rxi_OrphanFragSize;
4403 if (rxp->rx_maxReceiveSize) {
4404 rx_maxReceiveSize = rxp->rx_maxReceiveSize;
4405 rx_maxReceiveSizeUser = rxp->rx_maxReceiveSize;
4407 if (rxp->rx_MyMaxSendSize)
4408 rx_MyMaxSendSize = rxp->rx_MyMaxSendSize;
4414 * VIOC_GETINITPARAMS (49) - Get initial cache manager parameters
4418 * \param[in] ain not in use
4419 * \param[out] aout initial cache manager params
4422 * Error if the initial parameters are bigger than some PIGGYSIZE
4424 * \post return the initial cache manager parameters
4426 DECL_PIOCTL(PGetInitParams)
4428 if (sizeof(struct cm_initparams) > PIGGYSIZE)
4431 return afs_pd_putBytes(aout, &cm_initParams,
4432 sizeof(struct cm_initparams));
4435 #ifdef AFS_SGI65_ENV
4436 /* They took crget() from us, so fake it. */
4441 cr = crdup(get_current_cred());
4442 memset(cr, 0, sizeof(cred_t));
4443 #if CELL || CELL_PREPARE
4451 * VIOC_GETRXKCRYPT (55) - Get rxkad encryption flag
4455 * \param[in] ain not in use
4456 * \param[out] aout value of cryptall
4458 * \post Turns on, or disables, rxkad encryption by setting the cryptall global
4460 DECL_PIOCTL(PGetRxkcrypt)
4462 return afs_pd_putInt(aout, cryptall);
4466 * VIOC_SETRXKCRYPT (56) - Set rxkad encryption flag
4470 * \param[in] ain the argument whether or not things should be encrypted
4471 * \param[out] aout not in use
4474 * Error if the user doesn't have super-user credentials
4476 * Error if the input is too big, or if the input is outside the
4477 * bounds of what it can be set to
4479 * \post set whether or not things should be encrypted
4482 * may need to be modified at a later date to take into account
4483 * other values for cryptall (beyond true or false)
4485 DECL_PIOCTL(PSetRxkcrypt)
4489 if (!afs_osi_suser(*acred))
4491 if (afs_pd_getInt(ain, &tmpval) != 0)
4493 /* if new mappings added later this will need to be changed */
4494 if (tmpval != 0 && tmpval != 1)
4500 #ifdef AFS_NEED_CLIENTCONTEXT
4502 * Create new credentials to correspond to a remote user with given
4503 * <hostaddr, uid, g0, g1>. This allows a server running as root to
4504 * provide pioctl (and other) services to foreign clients (i.e. nfs
4505 * clients) by using this call to `become' the client.
4508 #define PIOCTL_HEADER 6
4510 HandleClientContext(struct afs_ioctl *ablob, int *com,
4511 afs_ucred_t **acred, afs_ucred_t *credp)
4514 afs_uint32 hostaddr;
4515 afs_int32 uid, g0, g1, i, code, pag, exporter_type, isroot = 0;
4516 struct afs_exporter *exporter, *outexporter;
4517 afs_ucred_t *newcred;
4518 struct unixuser *au;
4519 afs_uint32 comp = *com & 0xff00;
4521 #if defined(AFS_SUN510_ENV)
4525 #if defined(AFS_SGIMP_ENV)
4526 osi_Assert(ISAFS_GLOCK());
4528 AFS_STATCNT(HandleClientContext);
4529 if (ablob->in_size < PIOCTL_HEADER * sizeof(afs_int32)) {
4530 /* Must at least include the PIOCTL_HEADER header words
4531 * required by the protocol */
4532 return EINVAL; /* Too small to be good */
4534 ain = inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
4535 AFS_COPYIN(ablob->in, ain, PIOCTL_HEADER * sizeof(afs_int32), code);
4537 osi_FreeLargeSpace(inData);
4541 /* Extract information for remote user */
4542 hostaddr = *((afs_uint32 *) ain);
4543 ain += sizeof(hostaddr);
4544 uid = *((afs_uint32 *) ain);
4546 g0 = *((afs_uint32 *) ain);
4548 g1 = *((afs_uint32 *) ain);
4550 *com = *((afs_uint32 *) ain);
4551 ain += sizeof(afs_int32);
4552 exporter_type = *((afs_uint32 *) ain);/* In case we support more than NFS */
4555 * Of course, one must be root for most of these functions, but
4556 * we'll allow (for knfs) you to set things if the pag is 0 and
4557 * you're setting tokens or unlogging.
4560 if (!afs_osi_suser(credp)) {
4561 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
4562 /* Since SGI's suser() returns explicit failure after the call.. */
4565 /* check for acceptable opcodes for normal folks, which are, so far,
4566 * get/set tokens, sysname, and unlog.
4568 if (i != 9 && i != 3 && i != 38 && i != 8) {
4569 osi_FreeLargeSpace(inData);
4574 ablob->in_size -= PIOCTL_HEADER * sizeof(afs_int32);
4575 ablob->in += PIOCTL_HEADER * sizeof(afs_int32);
4576 osi_FreeLargeSpace(inData);
4579 * We map uid 0 to nobody to match the mapping that the nfs
4580 * server does and to ensure that the suser() calls in the afs
4581 * code fails for remote client roots.
4583 uid = afs_nobody; /* NFS_NOBODY == -2 */
4587 #ifdef AFS_AIX41_ENV
4590 afs_set_cr_gid(newcred, isroot ? RMTUSER_REQ_PRIV : RMTUSER_REQ);
4591 #ifdef AFS_AIX51_ENV
4592 newcred->cr_groupset.gs_union.un_groups[0] = g0;
4593 newcred->cr_groupset.gs_union.un_groups[1] = g1;
4594 #elif defined(AFS_LINUX26_ENV)
4595 # ifdef AFS_PAG_ONEGROUP_ENV
4596 afs_set_cr_group_info(newcred, groups_alloc(1)); /* nothing sets this */
4597 l = (((g0-0x3f00) & 0x3fff) << 14) | ((g1-0x3f00) & 0x3fff);
4598 h = ((g0-0x3f00) >> 14);
4599 h = ((g1-0x3f00) >> 14) + h + h + h;
4600 GROUP_AT(afs_cr_group_info(newcred), 0) = ((h << 28) | l);
4602 afs_set_cr_group_info(newcred, groups_alloc(2));
4603 GROUP_AT(afs_cr_group_info(newcred), 0) = g0;
4604 GROUP_AT(afs_cr_group_info(newcred), 1) = g1;
4606 #elif defined(AFS_SUN510_ENV)
4607 # ifdef AFS_PAG_ONEGROUP_ENV
4608 gids[0] = afs_get_pag_from_groups(g0, g1);
4609 crsetgroups(newcred, 1, gids);
4613 crsetgroups(newcred, 2, gids);
4614 # endif /* !AFS_PAG_ONEGROUP_ENV */
4616 newcred->cr_groups[0] = g0;
4617 newcred->cr_groups[1] = g1;
4620 newcred->cr_ngrps = 2;
4621 #elif !defined(AFS_LINUX26_ENV) && !defined(AFS_SUN510_ENV)
4622 # if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_FBSD_ENV)
4623 newcred->cr_ngroups = 2;
4625 for (i = 2; i < NGROUPS; i++)
4626 newcred->cr_groups[i] = NOGROUP;
4629 if (!(exporter = exporter_find(exporter_type))) {
4630 /* Exporter wasn't initialized or an invalid exporter type */
4634 if (exporter->exp_states & EXP_PWSYNC) {
4635 if (uid != afs_cr_uid(credp)) {
4637 return ENOEXEC; /* XXX Find a better errno XXX */
4640 afs_set_cr_uid(newcred, uid); /* Only temporary */
4641 code = EXP_REQHANDLER(exporter, &newcred, hostaddr, &pag, &outexporter);
4642 /* The client's pag is the only unique identifier for it */
4643 afs_set_cr_uid(newcred, pag);
4645 if (!code && *com == PSETPAG) {
4646 /* Special case for 'setpag' */
4647 afs_uint32 pagvalue = genpag();
4649 au = afs_GetUser(pagvalue, -1, WRITE_LOCK); /* a new unixuser struct */
4651 * Note that we leave the 'outexporter' struct held so it won't
4654 au->exporter = outexporter;
4655 if (ablob->out_size >= 4) {
4656 AFS_COPYOUT((char *)&pagvalue, ablob->out, sizeof(afs_int32),
4659 afs_PutUser(au, WRITE_LOCK);
4662 return PSETPAG; /* Special return for setpag */
4664 EXP_RELE(outexporter);
4667 *com = (*com) | comp;
4670 #endif /* AFS_NEED_CLIENTCONTEXT */
4674 * VIOC_GETCPREFS (50) - Get client interface
4678 * \param[in] ain sprefrequest input
4679 * \param[out] aout spref information
4681 * \retval EIO Error if the afs daemon hasn't started yet
4682 * \retval EINVAL Error if some of the standard args aren't set
4685 * get all interface addresses and other information of the client
4688 DECL_PIOCTL(PGetCPrefs)
4690 struct sprefrequest *spin; /* input */
4691 struct sprefinfo *spout; /* output */
4692 struct spref *srvout; /* one output component */
4696 AFS_STATCNT(PGetCPrefs);
4697 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4698 return EIO; /* Inappropriate ioctl for device */
4700 spin = afs_pd_inline(ain, sizeof(*spin));
4704 /* Output spout relies on writing past the end of arrays. It's horrible,
4705 * but I'm not quite brave enough to tackle it yet */
4706 spout = (struct sprefinfo *)aout->ptr;
4708 maxNumber = spin->num_servers; /* max addrs this time */
4709 srvout = spout->servers;
4711 ObtainReadLock(&afs_xinterface);
4713 /* copy out the client interface information from the
4714 * kernel data structure "interface" to the output buffer
4716 for (i = spin->offset, j = 0; (i < afs_cb_interface.numberOfInterfaces)
4717 && (j < maxNumber); i++, j++, srvout++)
4718 srvout->host.s_addr = afs_cb_interface.addr_in[i];
4720 spout->num_servers = j;
4721 aout->ptr += sizeof(struct sprefinfo) + (j - 1) * sizeof(struct spref);
4723 if (i >= afs_cb_interface.numberOfInterfaces)
4724 spout->next_offset = 0; /* start from beginning again */
4726 spout->next_offset = spin->offset + j;
4728 ReleaseReadLock(&afs_xinterface);
4733 * VIOC_SETCPREFS (51) - Set client interface
4737 * \param[in] ain the interfaces you want set
4738 * \param[out] aout not in use
4740 * \retval EIO Error if the afs daemon hasn't started yet
4741 * \retval EINVAL Error if the input is too large for the struct
4742 * \retval ENOMEM Error if there are too many servers
4744 * \post set the callbak interfaces addresses to those of the hosts
4746 DECL_PIOCTL(PSetCPrefs)
4750 struct setspref *sin;
4753 AFS_STATCNT(PSetCPrefs);
4754 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4755 return EIO; /* Inappropriate ioctl for device */
4757 /* Yuck. Input to this function relies on reading past the end of
4758 * structures. Bodge it for now.
4761 ainSize = ain->remaining;
4763 sin = (struct setspref *)ainPtr;
4765 if (ainSize < sizeof(struct setspref))
4767 if (sin->num_servers > AFS_MAX_INTERFACE_ADDR)
4770 ObtainWriteLock(&afs_xinterface, 412);
4771 afs_cb_interface.numberOfInterfaces = sin->num_servers;
4772 for (i = 0; (unsigned short)i < sin->num_servers; i++)
4773 afs_cb_interface.addr_in[i] = sin->servers[i].host.s_addr;
4775 ReleaseWriteLock(&afs_xinterface);
4780 * VIOC_AFS_FLUSHMOUNT (52) - Flush mount symlink data
4785 * the last part of a path to a mount point, which tells us what to flush
4790 * Error if some of the initial arguments aren't set
4792 * Error if the initial argument for the mount point isn't a directory
4794 * Error if the dcache entry isn't set
4797 * remove all of the mount data from the dcache regarding a
4798 * certain mount point
4800 DECL_PIOCTL(PFlushMount)
4805 struct VenusFid tfid;
4808 struct sysname_info sysState;
4809 afs_size_t offset, len;
4811 AFS_STATCNT(PFlushMount);
4815 if (afs_pd_getStringPtr(ain, &mount) != 0)
4818 code = afs_VerifyVCache(avc, areq);
4821 if (vType(avc) != VDIR) {
4824 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
4827 Check_AtSys(avc, mount, &sysState, areq);
4828 ObtainReadLock(&tdc->lock);
4830 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
4831 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
4832 ReleaseReadLock(&tdc->lock);
4833 afs_PutDCache(tdc); /* we're done with the data */
4834 bufp = sysState.name;
4838 tfid.Cell = avc->f.fid.Cell;
4839 tfid.Fid.Volume = avc->f.fid.Fid.Volume;
4840 if (!tfid.Fid.Unique && (avc->f.states & CForeign)) {
4841 tvc = afs_LookupVCache(&tfid, areq, avc, bufp);
4843 tvc = afs_GetVCache(&tfid, areq);
4849 if (tvc->mvstat != AFS_MVSTAT_MTPT) {
4854 ObtainWriteLock(&tvc->lock, 649);
4855 /* next reference will re-stat cache entry */
4856 afs_StaleVCacheFlags(tvc, 0, CDirty);
4857 /* now find the disk cache entries */
4858 afs_TryToSmush(tvc, *acred, 1);
4859 if (tvc->linkData && !(tvc->f.states & CCore)) {
4860 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
4861 tvc->linkData = NULL;
4863 ReleaseWriteLock(&tvc->lock);
4866 if (sysState.allocked)
4867 osi_FreeLargeSpace(bufp);
4872 * VIOC_RXSTAT_PROC (53) - Control process RX statistics
4876 * \param[in] ain the flags that control which stats to use
4877 * \param[out] aout not in use
4879 * \retval EACCES Error if the user doesn't have super-user credentials
4880 * \retval EINVAL Error if the flag input is too long
4883 * either enable process RPCStats, disable process RPCStats,
4884 * or clear the process RPCStats
4886 DECL_PIOCTL(PRxStatProc)
4890 if (!afs_osi_suser(*acred))
4893 if (afs_pd_getInt(ain, &flags) != 0)
4896 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK))
4899 if (flags & AFSCALL_RXSTATS_ENABLE) {
4900 rx_enableProcessRPCStats();
4902 if (flags & AFSCALL_RXSTATS_DISABLE) {
4903 rx_disableProcessRPCStats();
4905 if (flags & AFSCALL_RXSTATS_CLEAR) {
4906 rx_clearProcessRPCStats(AFS_RX_STATS_CLEAR_ALL);
4913 * VIOC_RXSTAT_PEER (54) - Control peer RX statistics
4917 * \param[in] ain the flags that control which statistics to use
4918 * \param[out] aout not in use
4920 * \retval EACCES Error if the user doesn't have super-user credentials
4921 * \retval EINVAL Error if the flag input is too long
4924 * either enable peer RPCStatws, disable peer RPCStats,
4925 * or clear the peer RPCStats
4927 DECL_PIOCTL(PRxStatPeer)
4931 if (!afs_osi_suser(*acred))
4934 if (afs_pd_getInt(ain, &flags) != 0)
4937 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK))
4940 if (flags & AFSCALL_RXSTATS_ENABLE) {
4941 rx_enablePeerRPCStats();
4943 if (flags & AFSCALL_RXSTATS_DISABLE) {
4944 rx_disablePeerRPCStats();
4946 if (flags & AFSCALL_RXSTATS_CLEAR) {
4947 rx_clearPeerRPCStats(AFS_RX_STATS_CLEAR_ALL);
4952 DECL_PIOCTL(PPrefetchFromTape)
4956 struct afs_conn *tc;
4957 struct rx_call *tcall;
4958 struct AFSVolSync tsync;
4959 struct AFSFetchStatus OutStatus;
4960 struct AFSCallBack CallBack;
4961 struct VenusFid tfid;
4964 struct rx_connection *rxconn;
4966 AFS_STATCNT(PPrefetchFromTape);
4970 Fid = afs_pd_inline(ain, sizeof(struct AFSFid));
4972 Fid = &avc->f.fid.Fid;
4974 tfid.Cell = avc->f.fid.Cell;
4975 tfid.Fid.Volume = Fid->Volume;
4976 tfid.Fid.Vnode = Fid->Vnode;
4977 tfid.Fid.Unique = Fid->Unique;
4979 tvc = afs_GetVCache(&tfid, areq);
4981 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
4982 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &avc->f.fid);
4985 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
4986 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &tvc->f.fid);
4989 tc = afs_Conn(&tvc->f.fid, areq, SHARED_LOCK, &rxconn);
4993 tcall = rx_NewCall(rxconn);
4995 StartRXAFS_FetchData(tcall, (struct AFSFid *)&tvc->f.fid.Fid, 0,
4998 rx_Read(tcall, (char *)&outval, sizeof(afs_int32));
5000 EndRXAFS_FetchData(tcall, &OutStatus, &CallBack, &tsync);
5002 code = rx_EndCall(tcall, code);
5006 } while (afs_Analyze
5007 (tc, rxconn, code, &tvc->f.fid, areq, AFS_STATS_FS_RPCIDX_RESIDENCYRPCS,
5008 SHARED_LOCK, NULL));
5009 /* This call is done only to have the callback things handled correctly */
5010 afs_FetchStatus(tvc, &tfid, areq, &OutStatus);
5016 return afs_pd_putInt(aout, outval);
5022 struct afs_conn *tc;
5024 struct FsCmdInputs *Inputs;
5025 struct FsCmdOutputs *Outputs;
5026 struct VenusFid tfid;
5028 struct rx_connection *rxconn;
5033 Inputs = afs_pd_inline(ain, sizeof(*Inputs));
5037 Outputs = afs_pd_inline(aout, sizeof(*Outputs));
5038 if (Outputs == NULL)
5043 Fid = &avc->f.fid.Fid;
5045 tfid.Cell = avc->f.fid.Cell;
5046 tfid.Fid.Volume = Fid->Volume;
5047 tfid.Fid.Vnode = Fid->Vnode;
5048 tfid.Fid.Unique = Fid->Unique;
5050 tvc = afs_GetVCache(&tfid, areq);
5051 afs_Trace3(afs_iclSetp, CM_TRACE_RESIDCMD, ICL_TYPE_POINTER, tvc,
5052 ICL_TYPE_INT32, Inputs->command, ICL_TYPE_FID, &tfid);
5056 if (Inputs->command) {
5058 tc = afs_Conn(&tvc->f.fid, areq, SHARED_LOCK, &rxconn);
5062 RXAFS_FsCmd(rxconn, Fid, Inputs, Outputs);
5066 } while (afs_Analyze
5067 (tc, rxconn, code, &tvc->f.fid, areq,
5068 AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK, NULL));
5069 /* This call is done to have the callback things handled correctly */
5070 afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
5071 } else { /* just a status request, return also link data */
5073 Outputs->code = afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
5074 Outputs->chars[0] = 0;
5075 if (vType(tvc) == VLNK) {
5076 ObtainWriteLock(&tvc->lock, 555);
5077 if (afs_HandleLink(tvc, areq) == 0)
5078 strncpy((char *)&Outputs->chars, tvc->linkData, MAXCMDCHARS);
5079 ReleaseWriteLock(&tvc->lock);
5088 DECL_PIOCTL(PNewUuid)
5090 /*AFS_STATCNT(PNewUuid); */
5091 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
5092 return EIO; /* Inappropriate ioctl for device */
5094 if (!afs_osi_suser(*acred))
5097 ObtainWriteLock(&afs_xinterface, 555);
5098 afs_uuid_create(&afs_cb_interface.uuid);
5099 ReleaseWriteLock(&afs_xinterface);
5100 ForceAllNewConnections();
5104 #if defined(AFS_CACHE_BYPASS) && defined(AFS_LINUX24_ENV)
5106 DECL_PIOCTL(PSetCachingThreshold)
5108 afs_int32 getting = 1;
5109 afs_int32 setting = 1;
5110 afs_int32 threshold = AFS_CACHE_BYPASS_DISABLED;
5112 if (afs_pd_getInt(ain, &threshold) != 0)
5118 if (setting == 0 && getting == 0)
5122 * If setting, set first, and return the value now in effect
5125 if (!afs_osi_suser(*acred))
5127 cache_bypass_threshold = threshold;
5128 afs_warn("Cache Bypass Threshold set to: %d\n", threshold);
5129 /* TODO: move to separate pioctl, or enhance pioctl */
5130 if (threshold == AFS_CACHE_BYPASS_DISABLED)
5131 cache_bypass_strategy = NEVER_BYPASS_CACHE;
5132 else if (!threshold)
5133 cache_bypass_strategy = ALWAYS_BYPASS_CACHE;
5135 cache_bypass_strategy = LARGE_FILES_BYPASS_CACHE;
5138 /* Return the current size threshold */
5140 return afs_pd_putInt(aout, cache_bypass_threshold);
5145 #endif /* defined(AFS_CACHE_BYPASS) */
5147 DECL_PIOCTL(PCallBackAddr)
5154 struct afs_conn *tc;
5155 afs_int32 i, j, addr;
5156 struct unixuser *tu;
5157 struct srvAddr **addrs;
5158 struct rx_connection *rxconn;
5160 /*AFS_STATCNT(PCallBackAddr); */
5161 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
5162 return EIO; /* Inappropriate ioctl for device */
5164 if (!afs_osi_suser(*acred))
5167 if (afs_pd_getInt(ain, &addr) != 0)
5170 ObtainReadLock(&afs_xinterface);
5171 for (i = 0; (unsigned short)i < afs_cb_interface.numberOfInterfaces; i++) {
5172 if (afs_cb_interface.addr_in[i] == addr)
5176 ReleaseWriteLock(&afs_xinterface);
5178 if (afs_cb_interface.addr_in[i] != addr)
5181 ObtainReadLock(&afs_xserver); /* Necessary? */
5182 ObtainReadLock(&afs_xsrvAddr);
5185 for (i = 0; i < NSERVERS; i++) {
5186 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
5191 addrs = afs_osi_Alloc(srvAddrCount * sizeof(*addrs));
5192 osi_Assert(addrs != NULL);
5194 for (i = 0; i < NSERVERS; i++) {
5195 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
5196 if (j >= srvAddrCount)
5202 ReleaseReadLock(&afs_xsrvAddr);
5203 ReleaseReadLock(&afs_xserver);
5205 for (i = 0; i < j; i++) {
5211 /* vlserver has no callback conn */
5212 if (sa->sa_portal == AFS_VLPORT) {
5216 if (!ts->cell) /* not really an active server, anyway, it must */
5217 continue; /* have just been added by setsprefs */
5219 /* get a connection, even if host is down; bumps conn ref count */
5220 tu = afs_GetUser(areq->uid, ts->cell->cellNum, SHARED_LOCK);
5221 tc = afs_ConnBySA(sa, ts->cell->fsport, ts->cell->cellNum, tu,
5222 1 /*force */ , 1 /*create */ , SHARED_LOCK, 0, &rxconn);
5223 afs_PutUser(tu, SHARED_LOCK);
5227 if ((sa->sa_flags & SRVADDR_ISDOWN) || afs_HaveCallBacksFrom(ts)) {
5228 if (sa->sa_flags & SRVADDR_ISDOWN) {
5229 rx_SetConnDeadTime(rxconn, 3);
5231 #ifdef RX_ENABLE_LOCKS
5233 #endif /* RX_ENABLE_LOCKS */
5234 code = RXAFS_CallBackRxConnAddr(rxconn, &addr);
5235 #ifdef RX_ENABLE_LOCKS
5237 #endif /* RX_ENABLE_LOCKS */
5239 afs_PutConn(tc, rxconn, SHARED_LOCK); /* done with it now */
5240 } /* Outer loop over addrs */
5241 afs_osi_Free(addrs, srvAddrCount * sizeof(*addrs));
5242 #endif /* UKERNEL */
5246 DECL_PIOCTL(PDiscon)
5248 static afs_int32 mode = 1; /* Start up in 'off' */
5249 afs_int32 force = 0;
5252 struct vrequest lreq;
5254 if (afs_pd_getBytes(ain, &flags, 4) == 0) {
5255 if (!afs_osi_suser(*acred))
5259 mode = flags[0] - 1;
5261 afs_ConflictPolicy = flags[1] - 1;
5265 /* Fake InitReq support for UID override */
5266 memset(&lreq, 0, sizeof(lreq));
5267 lreq.uid = flags[3];
5268 areq = &lreq; /* override areq we got */
5272 * All of these numbers are hard coded in fs.c. If they
5273 * change here, they should change there and vice versa
5276 case 0: /* Disconnect ("offline" mode), breaking all callbacks */
5277 if (!AFS_IS_DISCONNECTED) {
5278 ObtainWriteLock(&afs_discon_lock, 999);
5279 afs_DisconGiveUpCallbacks();
5280 afs_RemoveAllConns();
5281 afs_is_disconnected = 1;
5282 afs_is_discon_rw = 1;
5283 ReleaseWriteLock(&afs_discon_lock);
5286 case 1: /* Fully connected, ("online" mode). */
5287 ObtainWriteLock(&afs_discon_lock, 998);
5290 afs_MarkAllServersUp();
5291 code = afs_ResyncDisconFiles(areq, *acred);
5294 if (code && !force) {
5295 afs_warnuser("Files not synchronized properly, still in discon state. \n"
5296 "Please retry or use \"force\".\n");
5300 afs_DisconDiscardAll(*acred);
5302 afs_ClearAllStatdFlag();
5303 afs_is_disconnected = 0;
5304 afs_is_discon_rw = 0;
5305 afs_warnuser("\nSync succeeded. You are back online.\n");
5308 ReleaseWriteLock(&afs_discon_lock);
5320 return afs_pd_putInt(aout, mode);
5323 #define MAX_PIOCTL_TOKENS 10
5325 DECL_PIOCTL(PSetTokens2)
5328 int i, cellNum, primaryFlag;
5330 struct unixuser *tu;
5331 struct vrequest *treq = NULL;
5332 struct ktc_setTokenData tokenSet;
5333 struct ktc_tokenUnion decodedToken;
5335 memset(&tokenSet, 0, sizeof(tokenSet));
5337 AFS_STATCNT(PSetTokens2);
5338 if (!afs_resourceinit_flag)
5341 afs_pd_xdrStart(ain, &xdrs, XDR_DECODE);
5343 if (!xdr_ktc_setTokenData(&xdrs, &tokenSet)) {
5344 afs_pd_xdrEnd(ain, &xdrs);
5348 afs_pd_xdrEnd(ain, &xdrs);
5350 /* We limit each PAG to 10 tokens to prevent a malicous (or runaway)
5351 * process from using up the whole of the kernel memory by allocating
5354 if (tokenSet.tokens.tokens_len > MAX_PIOCTL_TOKENS) {
5355 xdr_free((xdrproc_t) xdr_ktc_setTokenData, &tokenSet);
5359 code = _settok_tokenCell(tokenSet.cell, &cellNum, &primaryFlag);
5361 xdr_free((xdrproc_t) xdr_ktc_setTokenData, &tokenSet);
5365 if (tokenSet.flags & AFSTOKEN_EX_SETPAG) {
5366 #if defined(AFS_LINUX26_ENV)
5367 afs_ucred_t *old_cred = *acred;
5369 if (_settok_setParentPag(acred) == 0) {
5370 #if defined(AFS_LINUX26_ENV)
5371 /* setpag() may have changed our credentials */
5375 code = afs_CreateReq(&treq, *acred);
5377 xdr_free((xdrproc_t) xdr_ktc_setTokenData, &tokenSet);
5384 tu = afs_GetUser(areq->uid, cellNum, WRITE_LOCK);
5385 /* Free any tokens that we've already got */
5386 afs_FreeTokens(&tu->tokens);
5388 /* Iterate across the set of tokens we've received, and stuff them
5389 * into this user's tokenJar
5391 for (i=0; i < tokenSet.tokens.tokens_len; i++) {
5392 xdrmem_create(&xdrs,
5393 tokenSet.tokens.tokens_val[i].token_opaque_val,
5394 tokenSet.tokens.tokens_val[i].token_opaque_len,
5397 memset(&decodedToken, 0, sizeof(decodedToken));
5398 if (!xdr_ktc_tokenUnion(&xdrs, &decodedToken)) {
5406 afs_AddTokenFromPioctl(&tu->tokens, &decodedToken);
5407 /* This is untidy - the old token interface supported passing
5408 * the primaryFlag as part of the token interface. Current
5409 * OpenAFS userland never sets this, but it's specified as being
5410 * part of the XG interface, so we should probably still support
5411 * it. Rather than add it to our AddToken interface, just handle
5414 if (decodedToken.at_type == AFSTOKEN_UNION_KAD) {
5415 if (decodedToken.ktc_tokenUnion_u.at_kad.rk_primary_flag)
5419 /* XXX - We should think more about destruction here. It's likely that
5420 * there is key material in what we're about to throw away, which
5421 * we really should zero out before giving back to the allocator */
5422 xdr_free((xdrproc_t) xdr_ktc_tokenUnion, &decodedToken);
5425 tu->states |= UHasTokens;
5426 tu->states &= ~UTokensBad;
5427 afs_SetPrimary(tu, primaryFlag);
5428 tu->tokenTime = osi_Time();
5430 xdr_free((xdrproc_t) xdr_ktc_setTokenData, &tokenSet);
5433 afs_ResetUserConns(tu);
5434 afs_PutUser(tu, WRITE_LOCK);
5435 afs_DestroyReq(treq);
5441 * VIOC_GETTOK2 (7) - Return a user's nth token, or token for a cell by
5446 * \param[in] ain EITHER a string cellname
5447 * OR an integer 'iterator' to specify the nth
5450 * \param[out] aout XDR-encoded tokens from the user's tokenJar
5452 * \retval EINVAL invalid input (bad integer, or invalid string)
5453 * unable to extract token(s)
5454 * \retval ENOMEM insufficient memory (returned from called routines)
5455 * \retval EDOM (integer) request was out of bounds or the user has no tokens
5456 * \retval ENOTCONN user found but has no valid token(s)
5457 * \retval E2BIG token(s) do not fit in the output buffer
5460 DECL_PIOCTL(PGetTokens2)
5462 struct cell *cell = NULL;
5463 struct unixuser *tu = NULL;
5465 char *cellName = NULL;
5468 int integer_in = 1; /* assume integer input */
5471 struct ktc_setTokenData tokenSet;
5473 AFS_STATCNT(PGetTokens);
5474 if (!afs_resourceinit_flag)
5477 memset(&tokenSet, 0, sizeof(tokenSet));
5479 /* No input data - return tokens for primary cell */
5480 /* 4 octets of data is PROBABLY an iterator count */
5481 /* Otherwise, treat as string & return tokens for that cell name */
5483 if (afs_pd_remaining(ain) == sizeof(afs_int32)) {
5484 char *scratch = afs_pd_where(ain);
5486 if (scratch[3] == '\0' && strlen(scratch) == 3)
5493 /* The misleadingly-named getNthCell actually return the nth valid
5494 * token found for the specified user; there can never be a gap
5495 * in the ordinals at this level.
5497 if (afs_pd_getInt(ain, &iterator) != 0)
5499 tu = getNthCell(areq->uid, iterator);
5501 if (afs_pd_remaining(ain) > 0) {
5502 if (afs_pd_getStringPtr(ain, &cellName) != 0)
5507 code = _settok_tokenCell(cellName, &cellNum, NULL);
5510 tu = afs_FindUser(areq->uid, cellNum, READ_LOCK);
5517 if (!(tu->states & UHasTokens)
5518 || !afs_HasValidTokens(tu->tokens, now)) {
5519 tu->states |= (UTokensBad | UNeedsReset);
5520 afs_PutUser(tu, READ_LOCK);
5524 code = afs_ExtractTokensForPioctl(tu->tokens, now, &tokenSet);
5528 cell = afs_GetCell(tu->cell, READ_LOCK);
5529 tokenSet.cell = cell->cellName;
5530 afs_pd_xdrStart(aout, &xdrs, XDR_ENCODE);
5531 if (!xdr_ktc_setTokenData(&xdrs, &tokenSet)) {
5535 afs_pd_xdrEnd(aout, &xdrs);
5538 tokenSet.cell = NULL;
5541 afs_PutUser(tu, READ_LOCK);
5543 afs_PutCell(cell, READ_LOCK);
5544 xdr_free((xdrproc_t)xdr_ktc_setTokenData, &tokenSet);
5549 DECL_PIOCTL(PNFSNukeCreds)
5553 struct unixuser *tu;
5555 AFS_STATCNT(PUnlog);
5556 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
5557 return EIO; /* Inappropriate ioctl for device */
5559 if (afs_pd_getUint(ain, &addr) != 0)
5562 if (afs_cr_gid(*acred) == RMTUSER_REQ_PRIV && !addr) {
5563 tu = afs_GetUser(areq->uid, -1, SHARED_LOCK);
5564 if (!tu->exporter || !(addr = EXP_GETHOST(tu->exporter))) {
5565 afs_PutUser(tu, SHARED_LOCK);
5568 afs_PutUser(tu, SHARED_LOCK);
5569 } else if (!afs_osi_suser(*acred)) {
5573 ObtainWriteLock(&afs_xuser, 227);
5574 for (i = 0; i < NUSERS; i++) {
5575 for (tu = afs_users[i]; tu; tu = tu->next) {
5576 if (tu->exporter && EXP_CHECKHOST(tu->exporter, addr)) {
5578 ReleaseWriteLock(&afs_xuser);
5580 afs_LockUser(tu, WRITE_LOCK, 367);
5582 tu->states &= ~UHasTokens;
5583 afs_FreeTokens(&tu->tokens);
5584 afs_ResetUserConns(tu);
5585 afs_PutUser(tu, WRITE_LOCK);
5586 ObtainWriteLock(&afs_xuser, 228);
5588 /* set the expire times to 0, causes
5589 * afs_GCUserData to remove this entry
5592 #endif /* UKERNEL */
5596 ReleaseWriteLock(&afs_xuser);