2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include "afs/param.h"
14 #include "afs/sysincludes.h" /* Standard vendor system headers */
16 #include "h/syscallargs.h"
19 #include "h/sysproto.h"
22 #include <sys/ioctl.h>
23 #include <sys/ioccom.h>
25 #include "afsincludes.h" /* Afs-based standard headers */
26 #include "afs/afs_stats.h" /* afs statistics */
28 #include "afs/afs_bypasscache.h"
29 #include "rx/rx_globals.h"
32 struct VenusFid afs_rootFid;
33 afs_int32 afs_waitForever = 0;
34 short afs_waitForeverCount = 0;
35 afs_int32 afs_showflags = GAGUSER | GAGCONSOLE; /* show all messages */
37 afs_int32 afs_is_disconnected;
38 afs_int32 afs_is_discon_rw;
39 /* On reconnection, turn this knob on until it finishes,
42 afs_int32 afs_in_sync = 0;
50 * A set of handy little functions for encoding and decoding
51 * pioctls without losing your marbles, or memory integrity
55 afs_pd_alloc(struct afs_pdata *apd, size_t size)
58 if (size > AFS_LRALLOCSIZ)
59 apd->ptr = osi_Alloc(size + 1);
61 apd->ptr = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
66 apd->remaining = size;
72 afs_pd_free(struct afs_pdata *apd)
77 if (apd->remaining > AFS_LRALLOCSIZ)
78 osi_Free(apd->ptr, apd->remaining + 1);
80 osi_FreeLargeSpace(apd->ptr);
87 afs_pd_where(struct afs_pdata *apd)
89 return apd ? apd->ptr : NULL;
93 afs_pd_remaining(struct afs_pdata *apd)
95 return apd ? apd->remaining : 0;
99 afs_pd_skip(struct afs_pdata *apd, size_t skip)
101 if (apd == NULL || apd->remaining < skip)
103 apd->remaining -= skip;
110 afs_pd_getBytes(struct afs_pdata *apd, void *dest, size_t bytes)
112 if (apd == NULL || apd->remaining < bytes)
114 apd->remaining -= bytes;
115 memcpy(dest, apd->ptr, bytes);
121 afs_pd_getInt(struct afs_pdata *apd, afs_int32 *val)
123 return afs_pd_getBytes(apd, val, sizeof(*val));
127 afs_pd_getUint(struct afs_pdata *apd, afs_uint32 *val)
129 return afs_pd_getBytes(apd, val, sizeof(*val));
133 afs_pd_inline(struct afs_pdata *apd, size_t bytes)
137 if (apd == NULL || apd->remaining < bytes)
142 apd->remaining -= bytes;
149 afs_pd_xdrStart(struct afs_pdata *apd, XDR *xdrs, enum xdr_op op) {
150 xdrmem_create(xdrs, apd->ptr, apd->remaining, op);
154 afs_pd_xdrEnd(struct afs_pdata *apd, XDR *xdrs) {
157 pos = xdr_getpos(xdrs);
159 apd->remaining -= pos;
166 afs_pd_getString(struct afs_pdata *apd, char *str, size_t maxLen)
170 if (apd == NULL || apd->remaining <= 0)
172 len = strlen(apd->ptr) + 1;
175 memcpy(str, apd->ptr, len);
177 apd->remaining -= len;
182 afs_pd_getStringPtr(struct afs_pdata *apd, char **str)
186 if (apd == NULL || apd->remaining <= 0)
188 len = strlen(apd->ptr) + 1;
191 apd->remaining -= len;
196 afs_pd_putBytes(struct afs_pdata *apd, const void *bytes, size_t len)
198 if (apd == NULL || apd->remaining < len)
200 memcpy(apd->ptr, bytes, len);
202 apd->remaining -= len;
207 afs_pd_putInt(struct afs_pdata *apd, afs_int32 val)
209 return afs_pd_putBytes(apd, &val, sizeof(val));
213 afs_pd_putString(struct afs_pdata *apd, char *str) {
215 /* Add 1 so we copy the NULL too */
216 return afs_pd_putBytes(apd, str, strlen(str) +1);
220 * \defgroup pioctl Path IOCTL functions
222 * DECL_PIOCTL is a macro defined to contain the following parameters for functions:
225 * the AFS vcache structure in use by pioctl
229 * the AFS vrequest structure
231 * an afs_pdata block describing the data received from the caller
233 * an afs_pdata block describing a pre-allocated block for output
235 * UNIX credentials structure underlying the operation
238 #define DECL_PIOCTL(x) \
239 static int x(struct vcache *avc, int afun, struct vrequest *areq, \
240 struct afs_pdata *ain, struct afs_pdata *aout, \
243 /* Prototypes for pioctl routines */
244 DECL_PIOCTL(PGetFID);
245 DECL_PIOCTL(PSetAcl);
246 DECL_PIOCTL(PStoreBehind);
247 DECL_PIOCTL(PGCPAGs);
248 DECL_PIOCTL(PGetAcl);
251 DECL_PIOCTL(PGetFileCell);
252 DECL_PIOCTL(PGetWSCell);
253 DECL_PIOCTL(PGetUserCell);
254 DECL_PIOCTL(PSetTokens);
255 DECL_PIOCTL(PSetTokens2);
256 DECL_PIOCTL(PGetVolumeStatus);
257 DECL_PIOCTL(PSetVolumeStatus);
259 DECL_PIOCTL(PNewStatMount);
260 DECL_PIOCTL(PGetTokens);
261 DECL_PIOCTL(PGetTokens2);
263 DECL_PIOCTL(PMariner);
264 DECL_PIOCTL(PCheckServers);
265 DECL_PIOCTL(PCheckVolNames);
266 DECL_PIOCTL(PCheckAuth);
267 DECL_PIOCTL(PFindVolume);
268 DECL_PIOCTL(PViceAccess);
269 DECL_PIOCTL(PSetCacheSize);
270 DECL_PIOCTL(PGetCacheSize);
271 DECL_PIOCTL(PRemoveCallBack);
272 DECL_PIOCTL(PNewCell);
273 DECL_PIOCTL(PNewAlias);
274 DECL_PIOCTL(PListCells);
275 DECL_PIOCTL(PListAliases);
276 DECL_PIOCTL(PRemoveMount);
277 DECL_PIOCTL(PGetCellStatus);
278 DECL_PIOCTL(PSetCellStatus);
279 DECL_PIOCTL(PFlushVolumeData);
280 DECL_PIOCTL(PGetVnodeXStatus);
281 DECL_PIOCTL(PGetVnodeXStatus2);
282 DECL_PIOCTL(PSetSysName);
283 DECL_PIOCTL(PSetSPrefs);
284 DECL_PIOCTL(PSetSPrefs33);
285 DECL_PIOCTL(PGetSPrefs);
286 DECL_PIOCTL(PExportAfs);
288 DECL_PIOCTL(PTwiddleRx);
289 DECL_PIOCTL(PGetInitParams);
290 DECL_PIOCTL(PGetRxkcrypt);
291 DECL_PIOCTL(PSetRxkcrypt);
292 DECL_PIOCTL(PGetCPrefs);
293 DECL_PIOCTL(PSetCPrefs);
294 DECL_PIOCTL(PFlushMount);
295 DECL_PIOCTL(PRxStatProc);
296 DECL_PIOCTL(PRxStatPeer);
297 DECL_PIOCTL(PPrefetchFromTape);
299 DECL_PIOCTL(PCallBackAddr);
300 DECL_PIOCTL(PDiscon);
301 DECL_PIOCTL(PNFSNukeCreds);
302 DECL_PIOCTL(PNewUuid);
303 DECL_PIOCTL(PPrecache);
304 DECL_PIOCTL(PGetPAG);
305 #if defined(AFS_CACHE_BYPASS) && defined(AFS_LINUX24_ENV)
306 DECL_PIOCTL(PSetCachingThreshold);
310 * A macro that says whether we're going to need HandleClientContext().
311 * This is currently used only by the nfs translator.
313 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
314 #define AFS_NEED_CLIENTCONTEXT
317 /* Prototypes for private routines */
318 #ifdef AFS_NEED_CLIENTCONTEXT
319 static int HandleClientContext(struct afs_ioctl *ablob, int *com,
323 int HandleIoctl(struct vcache *avc, afs_int32 acom,
324 struct afs_ioctl *adata);
325 int afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
326 struct afs_ioctl *ablob, int afollow,
327 afs_ucred_t **acred);
328 static int Prefetch(uparmtype apath, struct afs_ioctl *adata, int afollow,
331 typedef int (*pioctlFunction) (struct vcache *, int, struct vrequest *,
332 struct afs_pdata *, struct afs_pdata *,
335 static pioctlFunction VpioctlSw[] = {
340 PGetVolumeStatus, /* 4 */
341 PSetVolumeStatus, /* 5 */
346 PCheckServers, /* 10 */
347 PCheckVolNames, /* 11 */
349 PBogus, /* 13 -- used to be quick check time */
350 PFindVolume, /* 14 */
351 PBogus, /* 15 -- prefetch is now special-cased; see pioctl code! */
352 PBogus, /* 16 -- used to be testing code */
353 PNoop, /* 17 -- used to be enable group */
354 PNoop, /* 18 -- used to be disable group */
355 PBogus, /* 19 -- used to be list group */
356 PViceAccess, /* 20 */
357 PUnlog, /* 21 -- unlog *is* unpag in this system */
358 PGetFID, /* 22 -- get file ID */
359 PBogus, /* 23 -- used to be waitforever */
360 PSetCacheSize, /* 24 */
361 PRemoveCallBack, /* 25 -- flush only the callback */
364 PRemoveMount, /* 28 -- delete mount point */
365 PNewStatMount, /* 29 -- new style mount point stat */
366 PGetFileCell, /* 30 -- get cell name for input file */
367 PGetWSCell, /* 31 -- get cell name for workstation */
368 PMariner, /* 32 - set/get mariner host */
369 PGetUserCell, /* 33 -- get cell name for user */
370 PBogus, /* 34 -- Enable/Disable logging */
371 PGetCellStatus, /* 35 */
372 PSetCellStatus, /* 36 */
373 PFlushVolumeData, /* 37 -- flush all data from a volume */
374 PSetSysName, /* 38 - Set system name */
375 PExportAfs, /* 39 - Export Afs to remote nfs clients */
376 PGetCacheSize, /* 40 - get cache size and usage */
377 PGetVnodeXStatus, /* 41 - get vcache's special status */
378 PSetSPrefs33, /* 42 - Set CM Server preferences... */
379 PGetSPrefs, /* 43 - Get CM Server preferences... */
380 PGag, /* 44 - turn off/on all CM messages */
381 PTwiddleRx, /* 45 - adjust some RX params */
382 PSetSPrefs, /* 46 - Set CM Server preferences... */
383 PStoreBehind, /* 47 - set degree of store behind to be done */
384 PGCPAGs, /* 48 - disable automatic pag gc-ing */
385 PGetInitParams, /* 49 - get initial cm params */
386 PGetCPrefs, /* 50 - get client interface addresses */
387 PSetCPrefs, /* 51 - set client interface addresses */
388 PFlushMount, /* 52 - flush mount symlink data */
389 PRxStatProc, /* 53 - control process RX statistics */
390 PRxStatPeer, /* 54 - control peer RX statistics */
391 PGetRxkcrypt, /* 55 -- Get rxkad encryption flag */
392 PSetRxkcrypt, /* 56 -- Set rxkad encryption flag */
393 PBogus, /* 57 -- arla: set file prio */
394 PBogus, /* 58 -- arla: fallback getfh */
395 PBogus, /* 59 -- arla: fallback fhopen */
396 PBogus, /* 60 -- arla: controls xfsdebug */
397 PBogus, /* 61 -- arla: controls arla debug */
398 PBogus, /* 62 -- arla: debug interface */
399 PBogus, /* 63 -- arla: print xfs status */
400 PBogus, /* 64 -- arla: force cache check */
401 PBogus, /* 65 -- arla: break callback */
402 PPrefetchFromTape, /* 66 -- MR-AFS: prefetch file from tape */
403 PFsCmd, /* 67 -- RXOSD: generic commnd interface */
404 PBogus, /* 68 -- arla: fetch stats */
405 PGetVnodeXStatus2, /* 69 - get caller access and some vcache status */
408 static pioctlFunction CpioctlSw[] = {
410 PNewAlias, /* 1 -- create new cell alias */
411 PListAliases, /* 2 -- list cell aliases */
412 PCallBackAddr, /* 3 -- request addr for callback rxcon */
414 PDiscon, /* 5 -- get/set discon mode */
425 static pioctlFunction OpioctlSw[] = {
427 PNFSNukeCreds, /* 1 -- nuke all creds for NFS client */
428 #if defined(AFS_CACHE_BYPASS) && defined(AFS_LINUX24_ENV)
429 PSetCachingThreshold /* 2 -- get/set cache-bypass size threshold */
431 PNoop /* 2 -- get/set cache-bypass size threshold */
435 #define PSetClientContext 99 /* Special pioctl to setup caller's creds */
436 int afs_nobody = NFS_NOBODY;
439 HandleIoctl(struct vcache *avc, afs_int32 acom,
440 struct afs_ioctl *adata)
445 AFS_STATCNT(HandleIoctl);
447 switch (acom & 0xff) {
449 avc->f.states |= CSafeStore;
451 /* SXW - Should we force a MetaData flush for this flag setting */
454 /* case 2 used to be abort store, but this is no longer provided,
455 * since it is impossible to implement under normal Unix.
459 /* return the name of the cell this file is open on */
463 tcell = afs_GetCell(avc->f.fid.Cell, READ_LOCK);
465 i = strlen(tcell->cellName) + 1; /* bytes to copy out */
467 if (i > adata->out_size) {
468 /* 0 means we're not interested in the output */
469 if (adata->out_size != 0)
473 AFS_COPYOUT(tcell->cellName, adata->out, i, code);
475 afs_PutCell(tcell, READ_LOCK);
481 case 49: /* VIOC_GETINITPARAMS */
482 if (adata->out_size < sizeof(struct cm_initparams)) {
485 AFS_COPYOUT(&cm_initParams, adata->out,
486 sizeof(struct cm_initparams), code);
498 return code; /* so far, none implemented */
502 /* For aix we don't temporarily bypass ioctl(2) but rather do our
503 * thing directly in the vnode layer call, VNOP_IOCTL; thus afs_ioctl
504 * is now called from afs_gn_ioctl.
507 afs_ioctl(struct vcache *tvc, int cmd, int arg)
509 struct afs_ioctl data;
512 AFS_STATCNT(afs_ioctl);
513 if (((cmd >> 8) & 0xff) == 'V') {
514 /* This is a VICEIOCTL call */
515 AFS_COPYIN(arg, (caddr_t) & data, sizeof(data), error);
518 error = HandleIoctl(tvc, cmd, &data);
521 /* No-op call; just return. */
525 # if defined(AFS_AIX32_ENV)
526 # if defined(AFS_AIX51_ENV)
529 kioctl(int fdes, int com, caddr_t arg, caddr_t ext, caddr_t arg2,
531 # else /* __64BIT__ */
533 kioctl32(int fdes, int com, caddr_t arg, caddr_t ext, caddr_t arg2,
535 # endif /* __64BIT__ */
538 kioctl(int fdes, int com, caddr_t arg, caddr_t ext)
539 # endif /* AFS_AIX51_ENV */
544 # ifdef AFS_AIX51_ENV
547 } u_uap, *uap = &u_uap;
550 int ioctlDone = 0, code = 0;
552 AFS_STATCNT(afs_xioctl);
556 # ifdef AFS_AIX51_ENV
560 if (setuerror(getf(uap->fd, &fd))) {
563 if (fd->f_type == DTYPE_VNODE) {
564 /* good, this is a vnode; next see if it is an AFS vnode */
565 tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */
566 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
567 /* This is an AFS vnode */
568 if (((uap->com >> 8) & 0xff) == 'V') {
569 struct afs_ioctl *datap;
571 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
572 code=copyin_afs_ioctl((char *)uap->arg, datap);
574 osi_FreeSmallSpace(datap);
576 # if defined(AFS_AIX41_ENV)
579 return (setuerror(code), code);
581 code = HandleIoctl(tvc, uap->com, datap);
582 osi_FreeSmallSpace(datap);
585 # if defined(AFS_AIX41_ENV)
592 # if defined(AFS_AIX41_ENV)
594 # if defined(AFS_AIX51_ENV)
596 code = okioctl(fdes, com, arg, ext, arg2, arg3);
597 # else /* __64BIT__ */
598 code = okioctl32(fdes, com, arg, ext, arg2, arg3);
599 # endif /* __64BIT__ */
600 # else /* !AFS_AIX51_ENV */
601 code = okioctl(fdes, com, arg, ext);
602 # endif /* AFS_AIX51_ENV */
604 # elif defined(AFS_AIX32_ENV)
605 okioctl(fdes, com, arg, ext);
608 # if defined(KERNEL_HAVE_UERROR)
611 # if !defined(AFS_AIX41_ENV)
612 return (getuerror()? -1 : u.u_ioctlrv);
614 return getuerror()? -1 : 0;
621 #elif defined(AFS_SGI_ENV)
622 # if defined(AFS_SGI65_ENV)
623 afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
624 rval_t * rvalp, struct vopbd * vbds)
626 afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
627 rval_t * rvalp, struct vopbd * vbds)
630 struct afs_ioctl data;
636 AFS_STATCNT(afs_ioctl);
637 if (((cmd >> 8) & 0xff) == 'V') {
638 /* This is a VICEIOCTL call */
639 error = copyin_afs_ioctl(arg, &data);
642 locked = ISAFS_GLOCK();
645 error = HandleIoctl(tvc, cmd, &data);
650 /* No-op call; just return. */
654 #elif defined(AFS_SUN5_ENV)
655 struct afs_ioctl_sys {
662 afs_xioctl(struct afs_ioctl_sys *uap, rval_t *rvp)
666 int ioctlDone = 0, code = 0;
668 AFS_STATCNT(afs_xioctl);
672 if (fd->f_vnode->v_type == VREG || fd->f_vnode->v_type == VDIR) {
673 tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */
674 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
675 /* This is an AFS vnode */
676 if (((uap->com >> 8) & 0xff) == 'V') {
677 struct afs_ioctl *datap;
679 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
680 code=copyin_afs_ioctl((char *)uap->arg, datap);
682 osi_FreeSmallSpace(datap);
687 code = HandleIoctl(tvc, uap->com, datap);
688 osi_FreeSmallSpace(datap);
696 code = ioctl(uap, rvp);
700 #elif defined(AFS_LINUX22_ENV)
701 struct afs_ioctl_sys {
706 afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
709 struct afs_ioctl_sys ua, *uap = &ua;
713 AFS_STATCNT(afs_xioctl);
718 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
719 /* This is an AFS vnode */
720 if (((uap->com >> 8) & 0xff) == 'V') {
721 struct afs_ioctl *datap;
723 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
724 code = copyin_afs_ioctl((char *)uap->arg, datap);
726 osi_FreeSmallSpace(datap);
730 code = HandleIoctl(tvc, uap->com, datap);
731 osi_FreeSmallSpace(datap);
739 #elif defined(AFS_DARWIN_ENV) && !defined(AFS_DARWIN80_ENV)
747 afs_xioctl(afs_proc_t *p, struct ioctl_args *uap, register_t *retval)
751 int ioctlDone = 0, code = 0;
753 AFS_STATCNT(afs_xioctl);
754 if ((code = fdgetf(p, uap->fd, &fd)))
756 if (fd->f_type == DTYPE_VNODE) {
757 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
758 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
759 /* This is an AFS vnode */
760 if (((uap->com >> 8) & 0xff) == 'V') {
761 struct afs_ioctl *datap;
763 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
764 code = copyin_afs_ioctl((char *)uap->arg, datap);
766 osi_FreeSmallSpace(datap);
770 code = HandleIoctl(tvc, uap->com, datap);
771 osi_FreeSmallSpace(datap);
779 return ioctl(p, uap, retval);
783 #elif defined(AFS_XBSD_ENV)
784 # if defined(AFS_FBSD_ENV)
787 afs_xioctl(struct thread *td, struct ioctl_args *uap,
790 afs_proc_t *p = td->td_proc;
791 # elif defined(AFS_NBSD_ENV)
793 afs_xioctl(afs_proc_t *p, const struct sys_ioctl_args *uap, register_t *retval)
803 afs_xioctl(afs_proc_t *p, const struct ioctl_args *uap, register_t *retval)
806 struct filedesc *fdp;
808 int ioctlDone = 0, code = 0;
811 AFS_STATCNT(afs_xioctl);
812 #if defined(AFS_NBSD40_ENV)
813 fdp = p->l_proc->p_fd;
817 #if defined(AFS_NBSD50_ENV)
818 if ((fd = fd_getfile(SCARG(uap, fd))) == NULL)
821 if ((uap->fd >= fdp->fd_nfiles)
822 || ((fd = fdp->fd_ofiles[uap->fd]) == NULL))
825 if ((fd->f_flag & (FREAD | FWRITE)) == 0)
827 /* first determine whether this is any sort of vnode */
828 if (fd->f_type == DTYPE_VNODE) {
829 /* good, this is a vnode; next see if it is an AFS vnode */
830 # if defined(AFS_OBSD_ENV)
832 IsAfsVnode((struct vnode *)fd->
833 f_data) ? VTOAFS((struct vnode *)fd->f_data) : NULL;
835 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
837 if (tvc && IsAfsVnode((struct vnode *)fd->f_data)) {
838 /* This is an AFS vnode */
839 #if defined(AFS_NBSD50_ENV)
840 if (((SCARG(uap, com) >> 8) & 0xff) == 'V') {
842 if (((uap->com >> 8) & 0xff) == 'V') {
844 struct afs_ioctl *datap;
846 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
847 #if defined(AFS_NBSD50_ENV)
848 code = copyin_afs_ioctl(SCARG(uap, data), datap);
850 code = copyin_afs_ioctl((char *)uap->arg, datap);
853 osi_FreeSmallSpace(datap);
857 #if defined(AFS_NBSD50_ENV)
858 code = HandleIoctl(tvc, SCARG(uap, com), datap);
860 code = HandleIoctl(tvc, uap->com, datap);
862 osi_FreeSmallSpace(datap);
869 #if defined(AFS_NBSD50_ENV)
870 fd_putfile(SCARG(uap, fd));
874 # if defined(AFS_FBSD_ENV)
875 # if (__FreeBSD_version >= 900044)
876 return sys_ioctl(td, uap);
878 return ioctl(td, uap);
880 # elif defined(AFS_OBSD_ENV)
881 code = sys_ioctl(p, uap, retval);
882 # elif defined(AFS_NBSD_ENV)
883 code = sys_ioctl(p, uap, retval);
889 #elif defined(UKERNEL)
897 } *uap = (struct a *)get_user_struct()->u_ap;
900 int ioctlDone = 0, code = 0;
902 AFS_STATCNT(afs_xioctl);
907 /* first determine whether this is any sort of vnode */
908 if (fd->f_type == DTYPE_VNODE) {
909 /* good, this is a vnode; next see if it is an AFS vnode */
910 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
911 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
912 /* This is an AFS vnode */
913 if (((uap->com >> 8) & 0xff) == 'V') {
914 struct afs_ioctl *datap;
916 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
917 code=copyin_afs_ioctl((char *)uap->arg, datap);
919 osi_FreeSmallSpace(datap);
922 return (setuerror(code), code);
924 code = HandleIoctl(tvc, uap->com, datap);
925 osi_FreeSmallSpace(datap);
938 #endif /* AFS_HPUX102_ENV */
940 #if defined(AFS_SGI_ENV)
941 /* "pioctl" system call entry point; just pass argument to the parameterized
950 afs_pioctl(struct pioctlargs *uap, rval_t * rvp)
954 AFS_STATCNT(afs_pioctl);
956 code = afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow);
958 # ifdef AFS_SGI64_ENV
965 #elif defined(AFS_FBSD_ENV)
967 afs_pioctl(struct thread *td, void *args, int *retval)
974 } *uap = (struct a *)args;
976 AFS_STATCNT(afs_pioctl);
977 return (afs_syscall_pioctl
978 (uap->path, uap->cmd, uap->cmarg, uap->follow, td->td_ucred));
981 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
983 afs_pioctl(afs_proc_t *p, void *args, int *retval)
990 } *uap = (struct a *)args;
992 AFS_STATCNT(afs_pioctl);
993 # if defined(AFS_DARWIN80_ENV) || defined(AFS_NBSD40_ENV)
994 return (afs_syscall_pioctl
995 (uap->path, uap->cmd, uap->cmarg, uap->follow,
998 return (afs_syscall_pioctl
999 (uap->path, uap->cmd, uap->cmarg, uap->follow,
1000 # if defined(AFS_FBSD_ENV)
1003 p->p_cred->pc_ucred));
1010 /* macro to avoid adding any more #ifdef's to pioctl code. */
1011 #if defined(AFS_LINUX22_ENV) || defined(AFS_AIX41_ENV)
1012 #define PIOCTL_FREE_CRED() crfree(credp)
1014 #define PIOCTL_FREE_CRED()
1019 afs_syscall_pioctl(char *path, unsigned int com, caddr_t cmarg, int follow,
1020 rval_t *vvp, afs_ucred_t *credp)
1022 #ifdef AFS_DARWIN100_ENV
1023 afs_syscall64_pioctl(user_addr_t path, unsigned int com, user_addr_t cmarg,
1024 int follow, afs_ucred_t *credp)
1025 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1026 afs_syscall_pioctl(char *path, unsigned int com, caddr_t cmarg, int follow,
1029 afs_syscall_pioctl(char *path, unsigned int com, caddr_t cmarg, int follow)
1033 struct afs_ioctl data;
1034 #ifdef AFS_NEED_CLIENTCONTEXT
1035 afs_ucred_t *tmpcred = NULL;
1037 #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)
1038 afs_ucred_t *foreigncreds = NULL;
1041 struct vnode *vp = NULL;
1042 #ifdef AFS_AIX41_ENV
1043 struct ucred *credp = crref(); /* don't free until done! */
1045 #ifdef AFS_LINUX22_ENV
1046 cred_t *credp = crref(); /* don't free until done! */
1050 AFS_STATCNT(afs_syscall_pioctl);
1052 follow = 1; /* compat. with old venus */
1053 code = copyin_afs_ioctl(cmarg, &data);
1056 #if defined(KERNEL_HAVE_UERROR)
1061 if ((com & 0xff) == PSetClientContext) {
1062 #ifdef AFS_NEED_CLIENTCONTEXT
1063 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV)
1064 code = HandleClientContext(&data, &com, &foreigncreds, credp);
1066 code = HandleClientContext(&data, &com, &foreigncreds, osi_curcred());
1070 crfree(foreigncreds);
1073 #if defined(KERNEL_HAVE_UERROR)
1074 return (setuerror(code), code);
1079 #else /* AFS_NEED_CLIENTCONTEXT */
1081 #endif /* AFS_NEED_CLIENTCONTEXT */
1083 #ifdef AFS_NEED_CLIENTCONTEXT
1086 * We could have done without temporary setting the u.u_cred below
1087 * (foreigncreds could be passed as param the pioctl modules)
1088 * but calls such as afs_osi_suser() doesn't allow that since it
1089 * references u.u_cred directly. We could, of course, do something
1090 * like afs_osi_suser(cred) which, I think, is better since it
1091 * generalizes and supports multi cred environments...
1093 #if defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
1095 credp = foreigncreds;
1096 #elif defined(AFS_AIX41_ENV)
1097 tmpcred = crref(); /* XXX */
1098 crset(foreigncreds);
1099 #elif defined(AFS_HPUX101_ENV)
1100 tmpcred = p_cred(u.u_procp);
1101 set_p_cred(u.u_procp, foreigncreds);
1102 #elif defined(AFS_SGI_ENV)
1103 tmpcred = OSI_GET_CURRENT_CRED();
1104 OSI_SET_CURRENT_CRED(foreigncreds);
1107 u.u_cred = foreigncreds;
1110 #endif /* AFS_NEED_CLIENTCONTEXT */
1111 if ((com & 0xff) == 15) {
1112 /* special case prefetch so entire pathname eval occurs in helper process.
1113 * otherwise, the pioctl call is essentially useless */
1114 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1116 Prefetch(path, &data, follow,
1117 foreigncreds ? foreigncreds : credp);
1119 code = Prefetch(path, &data, follow, osi_curcred());
1122 #if defined(KERNEL_HAVE_UERROR)
1129 #ifdef AFS_AIX41_ENV
1131 lookupname(path, USR, follow, NULL, &vp,
1132 foreigncreds ? foreigncreds : credp);
1134 #ifdef AFS_LINUX22_ENV
1135 code = gop_lookupname_user(path, AFS_UIOUSER, follow, &dp);
1137 vp = (struct vnode *)dp->d_inode;
1139 code = gop_lookupname_user(path, AFS_UIOUSER, follow, &vp);
1140 #if defined(AFS_FBSD80_ENV) /* XXX check on 7x */
1143 #endif /* AFS_FBSD80_ENV */
1144 #endif /* AFS_LINUX22_ENV */
1145 #endif /* AFS_AIX41_ENV */
1149 #if defined(KERNEL_HAVE_UERROR)
1157 #if defined(AFS_SUN510_ENV)
1158 if (vp && !IsAfsVnode(vp)) {
1159 struct vnode *realvp;
1161 #ifdef AFS_SUN511_ENV
1162 (VOP_REALVP(vp, &realvp, NULL) == 0)
1164 (VOP_REALVP(vp, &realvp) == 0)
1167 struct vnode *oldvp = vp;
1175 /* now make the call if we were passed no file, or were passed an AFS file */
1176 if (!vp || IsAfsVnode(vp)) {
1177 #if defined(AFS_SUN5_ENV)
1178 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1179 #elif defined(AFS_AIX41_ENV)
1181 struct ucred *cred1, *cred2;
1184 cred1 = cred2 = foreigncreds;
1186 cred1 = cred2 = credp;
1188 code = afs_HandlePioctl(vp, com, &data, follow, &cred1);
1189 if (cred1 != cred2) {
1190 /* something changed the creds */
1194 #elif defined(AFS_HPUX101_ENV)
1196 struct ucred *cred = p_cred(u.u_procp);
1197 code = afs_HandlePioctl(vp, com, &data, follow, &cred);
1199 #elif defined(AFS_SGI_ENV)
1202 credp = OSI_GET_CURRENT_CRED();
1203 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1205 #elif defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1206 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1207 #elif defined(UKERNEL)
1208 code = afs_HandlePioctl(vp, com, &data, follow,
1209 &(get_user_struct()->u_cred));
1211 code = afs_HandlePioctl(vp, com, &data, follow, &u.u_cred);
1214 #if defined(KERNEL_HAVE_UERROR)
1217 code = EINVAL; /* not in /afs */
1222 #if defined(AFS_NEED_CLIENTCONTEXT)
1224 #ifdef AFS_AIX41_ENV
1225 crset(tmpcred); /* restore original credentials */
1227 #if defined(AFS_HPUX101_ENV)
1228 set_p_cred(u.u_procp, tmpcred); /* restore original credentials */
1229 #elif defined(AFS_SGI_ENV)
1230 OSI_SET_CURRENT_CRED(tmpcred); /* restore original credentials */
1231 #elif defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
1232 credp = tmpcred; /* restore original credentials */
1234 osi_curcred() = tmpcred; /* restore original credentials */
1235 #endif /* AFS_HPUX101_ENV */
1236 crfree(foreigncreds);
1239 #endif /* AFS_NEED_CLIENTCONTEXT */
1241 #ifdef AFS_LINUX22_ENV
1243 * Holding the global lock when calling dput can cause a deadlock
1244 * when the kernel calls back into afs_dentry_iput
1250 #if defined(AFS_FBSD80_ENV)
1251 if (VOP_ISLOCKED(vp))
1253 #endif /* AFS_FBSD80_ENV */
1254 AFS_RELE(vp); /* put vnode back */
1258 #if defined(KERNEL_HAVE_UERROR)
1261 return (getuerror());
1267 #ifdef AFS_DARWIN100_ENV
1269 afs_syscall_pioctl(char * path, unsigned int com, caddr_t cmarg,
1270 int follow, afs_ucred_t *credp)
1272 return afs_syscall64_pioctl(CAST_USER_ADDR_T(path), com,
1273 CAST_USER_ADDR_T((unsigned int)cmarg), follow,
1278 #define MAXPIOCTLTOKENLEN \
1279 (3*sizeof(afs_int32)+MAXKTCTICKETLEN+sizeof(struct ClearToken)+MAXKTCREALMLEN)
1282 afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
1283 struct afs_ioctl *ablob, int afollow,
1284 afs_ucred_t **acred)
1287 struct vrequest treq;
1289 afs_int32 function, device;
1290 struct afs_pdata input, output;
1291 struct afs_pdata copyInput, copyOutput;
1293 pioctlFunction *pioctlSw;
1295 struct afs_fakestat_state fakestate;
1297 memset(&input, 0, sizeof(input));
1298 memset(&output, 0, sizeof(output));
1300 avc = avp ? VTOAFS(avp) : NULL;
1301 afs_Trace3(afs_iclSetp, CM_TRACE_PIOCTL, ICL_TYPE_INT32, acom & 0xff,
1302 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, afollow);
1303 AFS_STATCNT(HandlePioctl);
1305 code = afs_InitReq(&treq, *acred);
1309 afs_InitFakeStat(&fakestate);
1311 code = afs_EvalFakeStat(&avc, &fakestate, &treq);
1315 device = (acom & 0xff00) >> 8;
1317 case 'V': /* Original pioctls */
1318 pioctlSw = VpioctlSw;
1319 pioctlSwSize = sizeof(VpioctlSw);
1321 case 'C': /* Coordinated/common pioctls */
1322 pioctlSw = CpioctlSw;
1323 pioctlSwSize = sizeof(CpioctlSw);
1325 case 'O': /* Coordinated/common pioctls */
1326 pioctlSw = OpioctlSw;
1327 pioctlSwSize = sizeof(OpioctlSw);
1333 function = acom & 0xff;
1334 if (function >= (pioctlSwSize / sizeof(char *))) {
1339 /* Do all range checking before continuing */
1340 if (ablob->in_size > MAXPIOCTLTOKENLEN ||
1341 ablob->in_size < 0 || ablob->out_size < 0) {
1346 code = afs_pd_alloc(&input, ablob->in_size);
1350 if (ablob->in_size > 0) {
1351 AFS_COPYIN(ablob->in, input.ptr, ablob->in_size, code);
1352 input.ptr[input.remaining] = '\0';
1357 if ((function == 8 && device == 'V') ||
1358 (function == 7 && device == 'C')) { /* PGetTokens */
1359 code = afs_pd_alloc(&output, MAXPIOCTLTOKENLEN);
1361 code = afs_pd_alloc(&output, AFS_LRALLOCSIZ);
1367 copyOutput = output;
1370 (*pioctlSw[function]) (avc, function, &treq, ©Input,
1371 ©Output, acred);
1373 outSize = copyOutput.ptr - output.ptr;
1375 if (code == 0 && ablob->out_size > 0) {
1376 if (outSize > ablob->out_size) {
1377 code = E2BIG; /* data wont fit in user buffer */
1378 } else if (outSize) {
1379 AFS_COPYOUT(output.ptr, ablob->out, outSize, code);
1384 afs_pd_free(&input);
1385 afs_pd_free(&output);
1387 afs_PutFakeStat(&fakestate);
1388 return afs_CheckCode(code, &treq, 41);
1392 * VIOCGETFID (22) - Get file ID quickly
1396 * \param[in] ain not in use
1397 * \param[out] aout fid of requested file
1399 * \retval EINVAL Error if some of the initial arguments aren't set
1401 * \post get the file id of some file
1403 DECL_PIOCTL(PGetFID)
1405 AFS_STATCNT(PGetFID);
1408 if (afs_pd_putBytes(aout, &avc->f.fid, sizeof(struct VenusFid)) != 0)
1414 * VIOCSETAL (1) - Set access control list
1418 * \param[in] ain the ACL being set
1419 * \param[out] aout the ACL being set returned
1421 * \retval EINVAL Error if some of the standard args aren't set
1423 * \post Changed ACL, via direct writing to the wire
1426 dummy_PSetAcl(char *ain, char *aout)
1431 DECL_PIOCTL(PSetAcl)
1434 struct afs_conn *tconn;
1435 struct AFSOpaque acl;
1436 struct AFSVolSync tsync;
1437 struct AFSFetchStatus OutStatus;
1438 struct rx_connection *rxconn;
1441 AFS_STATCNT(PSetAcl);
1445 if (afs_pd_getStringPtr(ain, &acl.AFSOpaque_val) != 0)
1447 acl.AFSOpaque_len = strlen(acl.AFSOpaque_val) + 1;
1448 if (acl.AFSOpaque_len > 1024)
1452 tconn = afs_Conn(&avc->f.fid, areq, SHARED_LOCK, &rxconn);
1454 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREACL);
1457 RXAFS_StoreACL(rxconn, (struct AFSFid *)&avc->f.fid.Fid,
1458 &acl, &OutStatus, &tsync);
1463 } while (afs_Analyze
1464 (tconn, rxconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_STOREACL,
1465 SHARED_LOCK, NULL));
1467 /* now we've forgotten all of the access info */
1468 ObtainWriteLock(&afs_xcbhash, 455);
1470 afs_DequeueCallback(avc);
1471 avc->f.states &= ~(CStatd | CUnique);
1472 ReleaseWriteLock(&afs_xcbhash);
1473 if (avc->f.fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
1474 osi_dnlc_purgedp(avc);
1476 /* SXW - Should we flush metadata here? */
1480 int afs_defaultAsynchrony = 0;
1483 * VIOC_STOREBEHIND (47) Adjust store asynchrony
1487 * \param[in] ain sbstruct (store behind structure) input
1488 * \param[out] aout resulting sbstruct
1491 * Error if the user doesn't have super-user credentials
1493 * Error if there isn't enough access to not check the mode bits
1496 * Changes either the default asynchrony (the amount of data that
1497 * can remain to be written when the cache manager returns control
1498 * to the user), or the asyncrony for the specified file.
1500 DECL_PIOCTL(PStoreBehind)
1502 struct sbstruct sbr;
1504 if (afs_pd_getBytes(ain, &sbr, sizeof(struct sbstruct)) != 0)
1507 if (sbr.sb_default != -1) {
1508 if (afs_osi_suser(*acred))
1509 afs_defaultAsynchrony = sbr.sb_default;
1514 if (avc && (sbr.sb_thisfile != -1)) {
1516 (avc, PRSFS_WRITE | PRSFS_ADMINISTER, areq, DONT_CHECK_MODE_BITS))
1517 avc->asynchrony = sbr.sb_thisfile;
1522 memset(&sbr, 0, sizeof(sbr));
1523 sbr.sb_default = afs_defaultAsynchrony;
1525 sbr.sb_thisfile = avc->asynchrony;
1528 return afs_pd_putBytes(aout, &sbr, sizeof(sbr));
1532 * VIOC_GCPAGS (48) - Disable automatic PAG gc'ing
1536 * \param[in] ain not in use
1537 * \param[out] aout not in use
1539 * \retval EACCES Error if the user doesn't have super-user credentials
1541 * \post set the gcpags to GCPAGS_USERDISABLED
1543 DECL_PIOCTL(PGCPAGs)
1545 if (!afs_osi_suser(*acred)) {
1548 afs_gcpags = AFS_GCPAGS_USERDISABLED;
1553 * VIOCGETAL (2) - Get access control list
1557 * \param[in] ain not in use
1558 * \param[out] aout the ACL
1560 * \retval EINVAL Error if some of the standard args aren't set
1561 * \retval ERANGE Error if the vnode of the file id is too large
1562 * \retval -1 Error if getting the ACL failed
1564 * \post Obtain the ACL, based on file ID
1567 * There is a hack to tell which type of ACL is being returned, checks
1568 * the top 2-bytes of the input size to judge what type of ACL it is,
1569 * only for dfs xlator ACLs
1571 DECL_PIOCTL(PGetAcl)
1573 struct AFSOpaque acl;
1574 struct AFSVolSync tsync;
1575 struct AFSFetchStatus OutStatus;
1577 struct afs_conn *tconn;
1579 struct rx_connection *rxconn;
1582 AFS_STATCNT(PGetAcl);
1585 Fid.Volume = avc->f.fid.Fid.Volume;
1586 Fid.Vnode = avc->f.fid.Fid.Vnode;
1587 Fid.Unique = avc->f.fid.Fid.Unique;
1588 if (avc->f.states & CForeign) {
1590 * For a dfs xlator acl we have a special hack so that the
1591 * xlator will distinguish which type of acl will return. So
1592 * we currently use the top 2-bytes (vals 0-4) to tell which
1593 * type of acl to bring back. Horrible hack but this will
1594 * cause the least number of changes to code size and interfaces.
1596 if (Fid.Vnode & 0xc0000000)
1598 Fid.Vnode |= (ain->remaining << 30);
1600 acl.AFSOpaque_val = aout->ptr;
1602 tconn = afs_Conn(&avc->f.fid, areq, SHARED_LOCK, &rxconn);
1604 acl.AFSOpaque_val[0] = '\0';
1605 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHACL);
1607 code = RXAFS_FetchACL(rxconn, &Fid, &acl, &OutStatus, &tsync);
1612 } while (afs_Analyze
1613 (tconn, rxconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_FETCHACL,
1614 SHARED_LOCK, NULL));
1617 if (acl.AFSOpaque_len == 0)
1618 afs_pd_skip(aout, 1); /* leave the NULL */
1620 afs_pd_skip(aout, acl.AFSOpaque_len); /* Length of the ACL */
1626 * PNoop returns success. Used for functions which are not implemented
1627 * or are no longer in use.
1631 * \retval Always returns success
1634 * Functions involved in this:
1635 * 17 (VIOCENGROUP) -- used to be enable group;
1636 * 18 (VIOCDISGROUP) -- used to be disable group;
1637 * 2 (?) -- get/set cache-bypass size threshold
1646 * PBogus returns fail. Used for functions which are not implemented or
1647 * are no longer in use.
1651 * \retval EINVAL Always returns this value
1654 * Functions involved in this:
1660 * 13 (VIOCGETTIME) -- used to be quick check time;
1661 * 15 (VIOCPREFETCH) -- prefetch is now special-cased; see pioctl code!;
1662 * 16 (VIOCNOP) -- used to be testing code;
1663 * 19 (VIOCLISTGROUPS) -- used to be list group;
1664 * 23 (VIOCWAITFOREVER) -- used to be waitforever;
1665 * 57 (VIOC_FPRIOSTATUS) -- arla: set file prio;
1666 * 58 (VIOC_FHGET) -- arla: fallback getfh;
1667 * 59 (VIOC_FHOPEN) -- arla: fallback fhopen;
1668 * 60 (VIOC_XFSDEBUG) -- arla: controls xfsdebug;
1669 * 61 (VIOC_ARLADEBUG) -- arla: controls arla debug;
1670 * 62 (VIOC_AVIATOR) -- arla: debug interface;
1671 * 63 (VIOC_XFSDEBUG_PRINT) -- arla: print xfs status;
1672 * 64 (VIOC_CALCULATE_CACHE) -- arla: force cache check;
1673 * 65 (VIOC_BREAKCELLBACK) -- arla: break callback;
1674 * 68 (?) -- arla: fetch stats;
1678 AFS_STATCNT(PBogus);
1683 * VIOC_FILE_CELL_NAME (30) - Get cell in which file lives
1687 * \param[in] ain not in use (avc used to pass in file id)
1688 * \param[out] aout cell name
1690 * \retval EINVAL Error if some of the standard args aren't set
1691 * \retval ESRCH Error if the file isn't part of a cell
1693 * \post Get a cell based on a passed in file id
1695 DECL_PIOCTL(PGetFileCell)
1699 AFS_STATCNT(PGetFileCell);
1702 tcell = afs_GetCell(avc->f.fid.Cell, READ_LOCK);
1706 if (afs_pd_putString(aout, tcell->cellName) != 0)
1709 afs_PutCell(tcell, READ_LOCK);
1714 * VIOC_GET_WS_CELL (31) - Get cell in which workstation lives
1718 * \param[in] ain not in use
1719 * \param[out] aout cell name
1722 * Error if the afs daemon hasn't started yet
1724 * Error if the machine isn't part of a cell, for whatever reason
1726 * \post Get the primary cell that the machine is a part of.
1728 DECL_PIOCTL(PGetWSCell)
1730 struct cell *tcell = NULL;
1732 AFS_STATCNT(PGetWSCell);
1733 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1734 return EIO; /* Inappropriate ioctl for device */
1736 tcell = afs_GetPrimaryCell(READ_LOCK);
1737 if (!tcell) /* no primary cell? */
1740 if (afs_pd_putString(aout, tcell->cellName) != 0)
1742 afs_PutCell(tcell, READ_LOCK);
1747 * VIOC_GET_PRIMARY_CELL (33) - Get primary cell for caller
1751 * \param[in] ain not in use (user id found via areq)
1752 * \param[out] aout cell name
1755 * Error if the user id doesn't have a primary cell specified
1757 * \post Get the primary cell for a certain user, based on the user's uid
1759 DECL_PIOCTL(PGetUserCell)
1762 struct unixuser *tu;
1765 AFS_STATCNT(PGetUserCell);
1766 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1767 return EIO; /* Inappropriate ioctl for device */
1769 /* return the cell name of the primary cell for this user */
1770 i = UHash(areq->uid);
1771 ObtainWriteLock(&afs_xuser, 224);
1772 for (tu = afs_users[i]; tu; tu = tu->next) {
1773 if (tu->uid == areq->uid && (tu->states & UPrimary)) {
1775 ReleaseWriteLock(&afs_xuser);
1776 afs_LockUser(tu, READ_LOCK, 0);
1781 tcell = afs_GetCell(tu->cell, READ_LOCK);
1782 afs_PutUser(tu, READ_LOCK);
1786 if (afs_pd_putString(aout, tcell->cellName) != 0)
1788 afs_PutCell(tcell, READ_LOCK);
1791 ReleaseWriteLock(&afs_xuser);
1796 /* Work out which cell we're changing tokens for */
1798 _settok_tokenCell(char *cellName, int *cellNum, int *primary) {
1806 if (cellName && strlen(cellName) > 0) {
1807 cell = afs_GetCellByName(cellName, READ_LOCK);
1809 cell = afs_GetPrimaryCell(READ_LOCK);
1820 *cellNum = cell->cellNum;
1821 afs_PutCell(cell, READ_LOCK);
1828 _settok_setParentPag(afs_ucred_t **cred) {
1830 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1832 osi_procname(procname, 256);
1833 afs_warnuser("Process %d (%s) tried to change pags in PSetTokens\n",
1834 MyPidxx2Pid(MyPidxx), procname);
1835 return setpag(osi_curproc(), cred, -1, &pag, 1);
1837 return setpag(cred, -1, &pag, 1);
1842 * VIOCSETTOK (3) - Set authentication tokens
1846 * \param[in] ain the krb tickets from which to set the afs tokens
1847 * \param[out] aout not in use
1850 * Error if the ticket is either too long or too short
1852 * Error if the AFS initState is below 101
1854 * Error if the cell for which the Token is being set can't be found
1857 * Set the Tokens for a specific cell name, unless there is none set,
1858 * then default to primary
1861 DECL_PIOCTL(PSetTokens)
1866 struct unixuser *tu;
1867 struct ClearToken clear;
1871 struct vrequest treq;
1872 afs_int32 flag, set_parent_pag = 0;
1874 AFS_STATCNT(PSetTokens);
1875 if (!afs_resourceinit_flag) {
1879 if (afs_pd_getInt(ain, &stLen) != 0)
1882 stp = afs_pd_where(ain); /* remember where the ticket is */
1883 if (stLen < 0 || stLen > MAXKTCTICKETLEN)
1884 return EINVAL; /* malloc may fail */
1885 if (afs_pd_skip(ain, stLen) != 0)
1888 if (afs_pd_getInt(ain, &size) != 0)
1890 if (size != sizeof(struct ClearToken))
1893 if (afs_pd_getBytes(ain, &clear, sizeof(struct ClearToken)) !=0)
1896 if (clear.AuthHandle == -1)
1897 clear.AuthHandle = 999; /* more rxvab compat stuff */
1899 if (afs_pd_remaining(ain) != 0) {
1900 /* still stuff left? we've got primary flag and cell name.
1903 if (afs_pd_getInt(ain, &flag) != 0)
1906 /* some versions of gcc appear to need != 0 in order to get this
1908 if ((flag & 0x8000) != 0) { /* XXX Use Constant XXX */
1913 if (afs_pd_getStringPtr(ain, &cellName) != 0)
1916 code = _settok_tokenCell(cellName, &cellNum, NULL);
1920 /* default to primary cell, primary id */
1921 code = _settok_tokenCell(NULL, &cellNum, &flag);
1926 if (set_parent_pag) {
1927 if (_settok_setParentPag(acred) == 0) {
1928 afs_InitReq(&treq, *acred);
1933 /* now we just set the tokens */
1934 tu = afs_GetUser(areq->uid, cellNum, WRITE_LOCK);
1935 /* Set tokens destroys any that are already there */
1936 afs_FreeTokens(&tu->tokens);
1937 afs_AddRxkadToken(&tu->tokens, stp, stLen, &clear);
1939 afs_stats_cmfullperf.authent.TicketUpdates++;
1940 afs_ComputePAGStats();
1941 #endif /* AFS_NOSTATS */
1942 tu->states |= UHasTokens;
1943 tu->states &= ~UTokensBad;
1944 afs_SetPrimary(tu, flag);
1945 tu->tokenTime = osi_Time();
1946 afs_ResetUserConns(tu);
1947 afs_NotifyUser(tu, UTokensObtained);
1948 afs_PutUser(tu, WRITE_LOCK);
1954 * VIOCGETVOLSTAT (4) - Get volume status
1958 * \param[in] ain not in use
1959 * \param[out] aout status of the volume
1961 * \retval EINVAL Error if some of the standard args aren't set
1964 * The status of a volume (based on the FID of the volume), or an
1965 * offline message /motd
1967 DECL_PIOCTL(PGetVolumeStatus)
1970 char *offLineMsg = afs_osi_Alloc(256);
1971 char *motd = afs_osi_Alloc(256);
1972 struct afs_conn *tc;
1974 struct AFSFetchVolumeStatus volstat;
1976 struct rx_connection *rxconn;
1979 osi_Assert(offLineMsg != NULL);
1980 osi_Assert(motd != NULL);
1981 AFS_STATCNT(PGetVolumeStatus);
1988 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK, &rxconn);
1990 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS);
1993 RXAFS_GetVolumeStatus(rxconn, avc->f.fid.Fid.Volume, &volstat,
1994 &Name, &offLineMsg, &motd);
1999 } while (afs_Analyze
2000 (tc, rxconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS,
2001 SHARED_LOCK, NULL));
2005 /* Copy all this junk into msg->im_data, keeping track of the lengths. */
2006 if (afs_pd_putBytes(aout, &volstat, sizeof(VolumeStatus)) != 0)
2008 if (afs_pd_putString(aout, volName) != 0)
2010 if (afs_pd_putString(aout, offLineMsg) != 0)
2012 if (afs_pd_putString(aout, motd) != 0)
2015 afs_osi_Free(offLineMsg, 256);
2016 afs_osi_Free(motd, 256);
2021 * VIOCSETVOLSTAT (5) - Set volume status
2026 * values to set the status at, offline message, message of the day,
2027 * volume name, minimum quota, maximum quota
2029 * status of a volume, offlines messages, minimum quota, maximumm quota
2032 * Error if some of the standard args aren't set
2034 * Error if the volume is read only, or a backup volume
2036 * Error if the volume can't be accessed
2038 * Error if the volume name, offline message, and motd are too big
2041 * Set the status of a volume, including any offline messages,
2042 * a minimum quota, and a maximum quota
2044 DECL_PIOCTL(PSetVolumeStatus)
2049 struct afs_conn *tc;
2051 struct AFSFetchVolumeStatus volstat;
2052 struct AFSStoreVolumeStatus storeStat;
2054 struct rx_connection *rxconn;
2057 AFS_STATCNT(PSetVolumeStatus);
2061 tvp = afs_GetVolume(&avc->f.fid, areq, READ_LOCK);
2063 if (tvp->states & (VRO | VBackup)) {
2064 afs_PutVolume(tvp, READ_LOCK);
2067 afs_PutVolume(tvp, READ_LOCK);
2072 if (afs_pd_getBytes(ain, &volstat, sizeof(AFSFetchVolumeStatus)) != 0)
2075 if (afs_pd_getStringPtr(ain, &volName) != 0)
2077 if (strlen(volName) > 32)
2080 if (afs_pd_getStringPtr(ain, &offLineMsg) != 0)
2082 if (strlen(offLineMsg) > 256)
2085 if (afs_pd_getStringPtr(ain, &motd) != 0)
2087 if (strlen(motd) > 256)
2090 /* Done reading ... */
2093 if (volstat.MinQuota != -1) {
2094 storeStat.MinQuota = volstat.MinQuota;
2095 storeStat.Mask |= AFS_SETMINQUOTA;
2097 if (volstat.MaxQuota != -1) {
2098 storeStat.MaxQuota = volstat.MaxQuota;
2099 storeStat.Mask |= AFS_SETMAXQUOTA;
2102 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK, &rxconn);
2104 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS);
2107 RXAFS_SetVolumeStatus(rxconn, avc->f.fid.Fid.Volume, &storeStat,
2108 volName, offLineMsg, motd);
2113 } while (afs_Analyze
2114 (tc, rxconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS,
2115 SHARED_LOCK, NULL));
2119 /* we are sending parms back to make compat. with prev system. should
2120 * change interface later to not ask for current status, just set new
2123 if (afs_pd_putBytes(aout, &volstat, sizeof(VolumeStatus)) != 0)
2125 if (afs_pd_putString(aout, volName) != 0)
2127 if (afs_pd_putString(aout, offLineMsg) != 0)
2129 if (afs_pd_putString(aout, motd) != 0)
2136 * VIOCFLUSH (6) - Invalidate cache entry
2140 * \param[in] ain not in use
2141 * \param[out] aout not in use
2143 * \retval EINVAL Error if some of the standard args aren't set
2145 * \post Flush any information the cache manager has on an entry
2149 AFS_STATCNT(PFlush);
2152 #ifdef AFS_BOZONLOCK_ENV
2153 afs_BozonLock(&avc->pvnLock, avc); /* Since afs_TryToSmush will do a pvn_vptrunc */
2155 ObtainWriteLock(&avc->lock, 225);
2156 afs_ResetVCache(avc, *acred, 0);
2157 ReleaseWriteLock(&avc->lock);
2158 #ifdef AFS_BOZONLOCK_ENV
2159 afs_BozonUnlock(&avc->pvnLock, avc);
2165 * VIOC_AFS_STAT_MT_PT (29) - Stat mount point
2170 * the last component in a path, related to mountpoint that we're
2171 * looking for information about
2173 * volume, cell, link data
2175 * \retval EINVAL Error if some of the standard args aren't set
2176 * \retval ENOTDIR Error if the 'mount point' argument isn't a directory
2177 * \retval EIO Error if the link data can't be accessed
2179 * \post Get the volume, and cell, as well as the link data for a mount point
2181 DECL_PIOCTL(PNewStatMount)
2186 struct VenusFid tfid;
2189 struct sysname_info sysState;
2190 afs_size_t offset, len;
2192 AFS_STATCNT(PNewStatMount);
2196 if (afs_pd_getStringPtr(ain, &name) != 0)
2199 code = afs_VerifyVCache(avc, areq);
2202 if (vType(avc) != VDIR) {
2205 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
2208 Check_AtSys(avc, name, &sysState, areq);
2209 ObtainReadLock(&tdc->lock);
2211 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
2212 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
2213 ReleaseReadLock(&tdc->lock);
2214 afs_PutDCache(tdc); /* we're done with the data */
2215 bufp = sysState.name;
2219 tfid.Cell = avc->f.fid.Cell;
2220 tfid.Fid.Volume = avc->f.fid.Fid.Volume;
2221 if (!tfid.Fid.Unique && (avc->f.states & CForeign)) {
2222 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
2224 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
2230 if (tvc->mvstat != 1) {
2235 ObtainWriteLock(&tvc->lock, 226);
2236 code = afs_HandleLink(tvc, areq);
2238 if (tvc->linkData) {
2239 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
2242 /* we have the data */
2243 if (afs_pd_putString(aout, tvc->linkData) != 0)
2249 ReleaseWriteLock(&tvc->lock);
2252 if (sysState.allocked)
2253 osi_FreeLargeSpace(bufp);
2258 * A helper function to get the n'th cell which a particular user has tokens
2259 * for. This is racy. If new tokens are added whilst we're iterating, then
2260 * we may return some cells twice. If tokens expire mid run, then we'll
2261 * miss some cells from our output. So, could be better, but that would
2262 * require an interface change.
2265 static struct unixuser *
2266 getNthCell(afs_int32 uid, afs_int32 iterator) {
2268 struct unixuser *tu = NULL;
2271 ObtainReadLock(&afs_xuser);
2272 for (tu = afs_users[i]; tu; tu = tu->next) {
2273 if (tu->uid == uid && (tu->states & UHasTokens)) {
2274 if (iterator-- == 0)
2275 break; /* are we done yet? */
2281 ReleaseReadLock(&afs_xuser);
2283 afs_LockUser(tu, READ_LOCK, 0);
2290 * VIOCGETTOK (8) - Get authentication tokens
2294 * \param[in] ain cellid to return tokens for
2295 * \param[out] aout token
2298 * Error if the afs daemon hasn't started yet
2300 * Error if the input parameter is out of the bounds of the available
2303 * Error if there aren't tokens for this cell
2306 * If the input paramater exists, get the token that corresponds to
2307 * the parameter value, if there is no token at this value, get the
2308 * token for the first cell
2310 * \notes "it's a weird interface (from comments in the code)"
2313 DECL_PIOCTL(PGetTokens)
2316 struct unixuser *tu = NULL;
2317 union tokenUnion *token;
2318 afs_int32 iterator = 0;
2323 AFS_STATCNT(PGetTokens);
2324 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2325 return EIO; /* Inappropriate ioctl for device */
2327 /* weird interface. If input parameter is present, it is an integer and
2328 * we're supposed to return the parm'th tokens for this unix uid.
2329 * If not present, we just return tokens for cell 1.
2330 * If counter out of bounds, return EDOM.
2331 * If no tokens for the particular cell, return ENOTCONN.
2332 * Also, if this mysterious parm is present, we return, along with the
2333 * tokens, the primary cell indicator (an afs_int32 0) and the cell name
2334 * at the end, in that order.
2336 newStyle = (afs_pd_remaining(ain) > 0);
2338 if (afs_pd_getInt(ain, &iterator) != 0)
2342 tu = getNthCell(areq->uid, iterator);
2344 cellNum = afs_GetPrimaryCellNum();
2346 tu = afs_FindUser(areq->uid, cellNum, READ_LOCK);
2351 if (!(tu->states & UHasTokens)
2352 || !afs_HasUsableTokens(tu->tokens, osi_Time())) {
2353 tu->states |= (UTokensBad | UNeedsReset);
2354 afs_NotifyUser(tu, UTokensDropped);
2355 afs_PutUser(tu, READ_LOCK);
2358 token = afs_FindToken(tu->tokens, RX_SECIDX_KAD);
2360 /* If they don't have an RXKAD token, but do have other tokens,
2361 * then sadly there's nothing this interface can do to help them. */
2365 /* for compat, we try to return 56 byte tix if they fit */
2366 iterator = token->rxkad.ticketLen;
2368 iterator = 56; /* # of bytes we're returning */
2370 if (afs_pd_putInt(aout, iterator) != 0)
2372 if (afs_pd_putBytes(aout, token->rxkad.ticket, token->rxkad.ticketLen) != 0)
2374 if (token->rxkad.ticketLen < 56) {
2375 /* Tokens are always 56 bytes or larger */
2376 if (afs_pd_skip(aout, iterator - token->rxkad.ticketLen) != 0) {
2381 if (afs_pd_putInt(aout, sizeof(struct ClearToken)) != 0)
2383 if (afs_pd_putBytes(aout, &token->rxkad.clearToken,
2384 sizeof(struct ClearToken)) != 0)
2388 /* put out primary id and cell name, too */
2389 iterator = (tu->states & UPrimary ? 1 : 0);
2390 if (afs_pd_putInt(aout, iterator) != 0)
2392 tcell = afs_GetCell(tu->cell, READ_LOCK);
2394 if (afs_pd_putString(aout, tcell->cellName) != 0)
2396 afs_PutCell(tcell, READ_LOCK);
2398 if (afs_pd_putString(aout, "") != 0)
2401 /* Got here, all is good */
2404 afs_PutUser(tu, READ_LOCK);
2409 * VIOCUNLOG (9) - Invalidate tokens
2413 * \param[in] ain not in use
2414 * \param[out] aout not in use
2416 * \retval EIO Error if the afs daemon hasn't been started yet
2418 * \post remove tokens from a user, specified by the user id
2420 * \notes sets the token's time to 0, which then causes it to be removed
2421 * \notes Unlog is the same as un-pag in OpenAFS
2426 struct unixuser *tu;
2428 AFS_STATCNT(PUnlog);
2429 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2430 return EIO; /* Inappropriate ioctl for device */
2432 i = UHash(areq->uid);
2433 ObtainWriteLock(&afs_xuser, 227);
2434 for (tu = afs_users[i]; tu; tu = tu->next) {
2435 if (tu->uid == areq->uid) {
2437 ReleaseWriteLock(&afs_xuser);
2439 afs_LockUser(tu, WRITE_LOCK, 366);
2441 tu->states &= ~UHasTokens;
2442 afs_FreeTokens(&tu->tokens);
2443 afs_NotifyUser(tu, UTokensDropped);
2444 /* We have to drop the lock over the call to afs_ResetUserConns,
2445 * since it obtains the afs_xvcache lock. We could also keep
2446 * the lock, and modify ResetUserConns to take parm saying we
2447 * obtained the lock already, but that is overkill. By keeping
2448 * the "tu" pointer held over the released lock, we guarantee
2449 * that we won't lose our place, and that we'll pass over
2450 * every user conn that existed when we began this call.
2452 afs_ResetUserConns(tu);
2453 afs_PutUser(tu, WRITE_LOCK);
2454 ObtainWriteLock(&afs_xuser, 228);
2456 /* set the expire times to 0, causes
2457 * afs_GCUserData to remove this entry
2460 #endif /* UKERNEL */
2463 ReleaseWriteLock(&afs_xuser);
2468 * VIOC_AFS_MARINER_HOST (32) - Get/set mariner (cache manager monitor) host
2472 * \param[in] ain host address to be set
2473 * \param[out] aout old host address
2476 * depending on whether or not a variable is set, either get the host
2477 * for the cache manager monitor, or set the old address and give it
2480 * \notes Errors turn off mariner
2482 DECL_PIOCTL(PMariner)
2484 afs_int32 newHostAddr;
2485 afs_int32 oldHostAddr;
2487 AFS_STATCNT(PMariner);
2489 memcpy((char *)&oldHostAddr, (char *)&afs_marinerHost,
2492 oldHostAddr = 0xffffffff; /* disabled */
2494 if (afs_pd_getInt(ain, &newHostAddr) != 0)
2497 if (newHostAddr == 0xffffffff) {
2498 /* disable mariner operations */
2500 } else if (newHostAddr) {
2502 afs_marinerHost = newHostAddr;
2505 if (afs_pd_putInt(aout, oldHostAddr) != 0)
2512 * VIOCCKSERV (10) - Check that servers are up
2516 * \param[in] ain name of the cell
2517 * \param[out] aout current down server list
2519 * \retval EIO Error if the afs daemon hasn't started yet
2520 * \retval EACCES Error if the user doesn't have super-user credentials
2521 * \retval ENOENT Error if we are unable to obtain the cell
2524 * Either a fast check (where it doesn't contact servers) or a
2525 * local check (checks local cell only)
2527 DECL_PIOCTL(PCheckServers)
2532 char *cellName = NULL;
2534 struct chservinfo *pcheck;
2536 AFS_STATCNT(PCheckServers);
2538 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2539 return EIO; /* Inappropriate ioctl for device */
2541 /* This is tricky, because we need to peak at the datastream to see
2542 * what we're getting. For now, let's cheat. */
2544 /* ain contains either an int32 or a string */
2545 if (ain->remaining == 0)
2548 if (*(afs_int32 *)ain->ptr == 0x12345678) { /* For afs3.3 version */
2549 pcheck = afs_pd_inline(ain, sizeof(*pcheck));
2553 if (pcheck->tinterval >= 0) {
2554 if (afs_pd_putInt(aout, afs_probe_interval) != 0)
2556 if (pcheck->tinterval > 0) {
2557 if (!afs_osi_suser(*acred))
2559 afs_probe_interval = pcheck->tinterval;
2563 temp = pcheck->tflags;
2565 cellName = pcheck->tbuffer;
2566 } else { /* For pre afs3.3 versions */
2567 if (afs_pd_getInt(ain, &temp) != 0)
2569 if (afs_pd_remaining(ain) > 0) {
2570 if (afs_pd_getStringPtr(ain, &cellName) != 0)
2576 * 1: fast check, don't contact servers.
2577 * 2: local cell only.
2580 /* have cell name, too */
2581 cellp = afs_GetCellByName(cellName, READ_LOCK);
2586 if (!cellp && (temp & 2)) {
2587 /* use local cell */
2588 cellp = afs_GetPrimaryCell(READ_LOCK);
2590 if (!(temp & 1)) { /* if not fast, call server checker routine */
2591 afs_CheckServers(1, cellp); /* check down servers */
2592 afs_CheckServers(0, cellp); /* check up servers */
2594 /* now return the current down server list */
2595 ObtainReadLock(&afs_xserver);
2596 for (i = 0; i < NSERVERS; i++) {
2597 for (ts = afs_servers[i]; ts; ts = ts->next) {
2598 if (cellp && ts->cell != cellp)
2599 continue; /* cell spec'd and wrong */
2600 if ((ts->flags & SRVR_ISDOWN)
2601 && ts->addr->sa_portal != ts->cell->vlport) {
2602 afs_pd_putInt(aout, ts->addr->sa_ip);
2606 ReleaseReadLock(&afs_xserver);
2608 afs_PutCell(cellp, READ_LOCK);
2613 * VIOCCKBACK (11) - Check backup volume mappings
2617 * \param[in] ain not in use
2618 * \param[out] aout not in use
2620 * \retval EIO Error if the afs daemon hasn't started yet
2623 * Check the root volume, and then check the names if the volume
2624 * check variable is set to force, has expired, is busy, or if
2625 * the mount points variable is set
2627 DECL_PIOCTL(PCheckVolNames)
2629 AFS_STATCNT(PCheckVolNames);
2630 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2631 return EIO; /* Inappropriate ioctl for device */
2633 afs_CheckRootVolume();
2634 afs_CheckVolumeNames(AFS_VOLCHECK_FORCE | AFS_VOLCHECK_EXPIRED |
2635 AFS_VOLCHECK_BUSY | AFS_VOLCHECK_MTPTS);
2640 * VIOCCKCONN (12) - Check connections for a user
2644 * \param[in] ain not in use
2645 * \param[out] aout not in use
2648 * Error if no user is specififed, the user has no tokens set,
2649 * or if the user's tokens are bad
2652 * check to see if a user has the correct authentication.
2653 * If so, allow access.
2655 * \notes Check the connections to all the servers specified
2657 DECL_PIOCTL(PCheckAuth)
2661 struct sa_conn_vector *tcv;
2662 struct unixuser *tu;
2665 AFS_STATCNT(PCheckAuth);
2666 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2667 return EIO; /* Inappropriate ioctl for device */
2670 tu = afs_GetUser(areq->uid, 1, READ_LOCK); /* check local cell authentication */
2674 /* we have a user */
2675 ObtainReadLock(&afs_xsrvAddr);
2676 ObtainReadLock(&afs_xconn);
2678 /* any tokens set? */
2679 if ((tu->states & UHasTokens) == 0)
2681 /* all connections in cell 1 working? */
2682 for (i = 0; i < NSERVERS; i++) {
2683 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2684 for (tcv = sa->conns; tcv; tcv = tcv->next) {
2685 if (tcv->user == tu && (tu->states & UTokensBad))
2690 ReleaseReadLock(&afs_xsrvAddr);
2691 ReleaseReadLock(&afs_xconn);
2692 afs_PutUser(tu, READ_LOCK);
2694 if (afs_pd_putInt(aout, retValue) != 0)
2700 Prefetch(uparmtype apath, struct afs_ioctl *adata, int afollow,
2705 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2711 AFS_STATCNT(Prefetch);
2714 tp = osi_AllocLargeSpace(1024);
2715 AFS_COPYINSTR(apath, tp, 1024, &bufferSize, code);
2717 osi_FreeLargeSpace(tp);
2720 if (afs_BBusy()) { /* do this as late as possible */
2721 osi_FreeLargeSpace(tp);
2722 return EWOULDBLOCK; /* pretty close */
2724 afs_BQueue(BOP_PATH, (struct vcache *)0, 0, 0, acred, (afs_size_t) 0,
2725 (afs_size_t) 0, tp, (void *)0, (void *)0);
2730 * VIOCWHEREIS (14) - Find out where a volume is located
2734 * \param[in] ain not in use
2735 * \param[out] aout volume location
2737 * \retval EINVAL Error if some of the default arguments don't exist
2738 * \retval ENODEV Error if there is no such volume
2740 * \post fine a volume, based on a volume file id
2742 * \notes check each of the servers specified
2744 DECL_PIOCTL(PFindVolume)
2751 AFS_STATCNT(PFindVolume);
2754 tvp = afs_GetVolume(&avc->f.fid, areq, READ_LOCK);
2758 for (i = 0; i < AFS_MAXHOSTS; i++) {
2759 ts = tvp->serverHost[i];
2762 if (afs_pd_putInt(aout, ts->addr->sa_ip) != 0) {
2767 if (i < AFS_MAXHOSTS) {
2768 /* still room for terminating NULL, add it on */
2769 if (afs_pd_putInt(aout, 0) != 0) {
2775 afs_PutVolume(tvp, READ_LOCK);
2780 * VIOCACCESS (20) - Access using PRS_FS bits
2784 * \param[in] ain PRS_FS bits
2785 * \param[out] aout not in use
2787 * \retval EINVAL Error if some of the initial arguments aren't set
2788 * \retval EACCES Error if access is denied
2790 * \post check to make sure access is allowed
2792 DECL_PIOCTL(PViceAccess)
2797 AFS_STATCNT(PViceAccess);
2801 code = afs_VerifyVCache(avc, areq);
2805 if (afs_pd_getInt(ain, &temp) != 0)
2808 code = afs_AccessOK(avc, temp, areq, CHECK_MODE_BITS);
2816 * VIOC_GETPAG (13) - Get PAG value
2820 * \param[in] ain not in use
2821 * \param[out] aout PAG value or NOPAG
2823 * \post get PAG value for the caller's cred
2825 DECL_PIOCTL(PGetPAG)
2829 pag = PagInCred(*acred);
2831 return afs_pd_putInt(aout, pag);
2834 DECL_PIOCTL(PPrecache)
2838 /*AFS_STATCNT(PPrecache);*/
2839 if (!afs_osi_suser(*acred))
2842 if (afs_pd_getInt(ain, &newValue) != 0)
2845 afs_preCache = newValue*1024;
2850 * VIOCSETCACHESIZE (24) - Set venus cache size in 1000 units
2854 * \param[in] ain the size the venus cache should be set to
2855 * \param[out] aout not in use
2857 * \retval EACCES Error if the user doesn't have super-user credentials
2858 * \retval EROFS Error if the cache is set to be in memory
2861 * Set the cache size based on user input. If no size is given,
2862 * set it to the default OpenAFS cache size.
2865 * recompute the general cache parameters for every single block allocated
2867 DECL_PIOCTL(PSetCacheSize)
2872 AFS_STATCNT(PSetCacheSize);
2874 if (!afs_osi_suser(*acred))
2876 /* too many things are setup initially in mem cache version */
2877 if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
2879 if (afs_pd_getInt(ain, &newValue) != 0)
2882 afs_cacheBlocks = afs_stats_cmperf.cacheBlocksOrig;
2884 if (newValue < afs_min_cache)
2885 afs_cacheBlocks = afs_min_cache;
2887 afs_cacheBlocks = newValue;
2889 afs_stats_cmperf.cacheBlocksTotal = afs_cacheBlocks;
2890 afs_ComputeCacheParms(); /* recompute basic cache parameters */
2891 afs_MaybeWakeupTruncateDaemon();
2892 while (waitcnt++ < 100 && afs_cacheBlocks < afs_blocksUsed) {
2893 afs_osi_Wait(1000, 0, 0);
2894 afs_MaybeWakeupTruncateDaemon();
2899 #define MAXGCSTATS 16
2901 * VIOCGETCACHEPARMS (40) - Get cache stats
2905 * \param[in] ain afs index flags
2906 * \param[out] aout cache blocks, blocks used, blocks files (in an array)
2908 * \post Get the cache blocks, and how many of the cache blocks there are
2910 DECL_PIOCTL(PGetCacheSize)
2912 afs_int32 results[MAXGCSTATS];
2914 struct dcache * tdc;
2917 AFS_STATCNT(PGetCacheSize);
2919 if (afs_pd_remaining(ain) == sizeof(afs_int32)) {
2920 afs_pd_getInt(ain, &flags); /* can't error, we just checked size */
2921 } else if (afs_pd_remaining(ain) == 0) {
2927 memset(results, 0, sizeof(results));
2928 results[0] = afs_cacheBlocks;
2929 results[1] = afs_blocksUsed;
2930 results[2] = afs_cacheFiles;
2933 for (i = 0; i < afs_cacheFiles; i++) {
2934 if (afs_indexFlags[i] & IFFree) results[3]++;
2936 } else if (2 == flags){
2937 for (i = 0; i < afs_cacheFiles; i++) {
2938 if (afs_indexFlags[i] & IFFree) results[3]++;
2939 if (afs_indexFlags[i] & IFEverUsed) results[4]++;
2940 if (afs_indexFlags[i] & IFDataMod) results[5]++;
2941 if (afs_indexFlags[i] & IFDirtyPages) results[6]++;
2942 if (afs_indexFlags[i] & IFAnyPages) results[7]++;
2943 if (afs_indexFlags[i] & IFDiscarded) results[8]++;
2945 tdc = afs_indexTable[i];
2948 size = tdc->validPos;
2949 if ( 0 < size && size < (1<<12) ) results[10]++;
2950 else if (size < (1<<14) ) results[11]++;
2951 else if (size < (1<<16) ) results[12]++;
2952 else if (size < (1<<18) ) results[13]++;
2953 else if (size < (1<<20) ) results[14]++;
2954 else if (size >= (1<<20) ) results[15]++;
2958 return afs_pd_putBytes(aout, results, sizeof(results));
2962 * VIOCFLUSHCB (25) - Flush callback only
2966 * \param[in] ain not in use
2967 * \param[out] aout not in use
2969 * \retval EINVAL Error if some of the standard args aren't set
2970 * \retval 0 0 returned if the volume is set to read-only
2973 * Flushes callbacks, by setting the length of callbacks to one,
2974 * setting the next callback to be sent to the CB_DROPPED value,
2975 * and then dequeues everything else.
2977 DECL_PIOCTL(PRemoveCallBack)
2979 struct afs_conn *tc;
2981 struct AFSCallBack CallBacks_Array[1];
2982 struct AFSCBFids theFids;
2983 struct AFSCBs theCBs;
2984 struct rx_connection *rxconn;
2987 AFS_STATCNT(PRemoveCallBack);
2990 if (avc->f.states & CRO)
2991 return 0; /* read-only-ness can't change */
2992 ObtainWriteLock(&avc->lock, 229);
2993 theFids.AFSCBFids_len = 1;
2994 theCBs.AFSCBs_len = 1;
2995 theFids.AFSCBFids_val = (struct AFSFid *)&avc->f.fid.Fid;
2996 theCBs.AFSCBs_val = CallBacks_Array;
2997 CallBacks_Array[0].CallBackType = CB_DROPPED;
2998 if (avc->callback) {
3000 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK, &rxconn);
3002 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
3004 code = RXAFS_GiveUpCallBacks(rxconn, &theFids, &theCBs);
3008 /* don't set code on failure since we wouldn't use it */
3009 } while (afs_Analyze
3010 (tc, rxconn, code, &avc->f.fid, areq,
3011 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK, NULL));
3013 ObtainWriteLock(&afs_xcbhash, 457);
3014 afs_DequeueCallback(avc);
3016 avc->f.states &= ~(CStatd | CUnique);
3017 ReleaseWriteLock(&afs_xcbhash);
3018 if (avc->f.fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
3019 osi_dnlc_purgedp(avc);
3021 ReleaseWriteLock(&avc->lock);
3026 * VIOCNEWCELL (26) - Configure new cell
3031 * the name of the cell, the hosts that will be a part of the cell,
3032 * whether or not it's linked with another cell, the other cell it's
3033 * linked with, the file server port, and the volume server port
3037 * \retval EIO Error if the afs daemon hasn't started yet
3038 * \retval EACCES Error if the user doesn't have super-user cedentials
3039 * \retval EINVAL Error if some 'magic' var doesn't have a certain bit set
3041 * \post creates a new cell
3043 DECL_PIOCTL(PNewCell)
3045 afs_int32 cellHosts[AFS_MAXCELLHOSTS], magic = 0;
3046 char *newcell = NULL;
3047 char *linkedcell = NULL;
3049 afs_int32 linkedstate = 0;
3050 afs_int32 fsport = 0, vlport = 0;
3053 AFS_STATCNT(PNewCell);
3054 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3055 return EIO; /* Inappropriate ioctl for device */
3057 if (!afs_osi_suser(*acred))
3060 if (afs_pd_getInt(ain, &magic) != 0)
3062 if (magic != 0x12345678)
3065 /* A 3.4 fs newcell command will pass an array of AFS_MAXCELLHOSTS
3066 * server addresses while the 3.5 fs newcell command passes
3067 * AFS_MAXHOSTS. To figure out which is which, check if the cellname
3070 * This whole logic is bogus, because it relies on the newer command
3071 * sending its 12th address as 0.
3073 if ((afs_pd_remaining(ain) < AFS_MAXCELLHOSTS +3) * sizeof(afs_int32))
3076 newcell = afs_pd_where(ain) + (AFS_MAXCELLHOSTS + 3) * sizeof(afs_int32);
3077 if (newcell[0] != '\0') {
3080 skip = AFS_MAXHOSTS - AFS_MAXCELLHOSTS;
3083 /* AFS_MAXCELLHOSTS (=8) is less than AFS_MAXHOSTS (=13) */
3084 if (afs_pd_getBytes(ain, &cellHosts,
3085 AFS_MAXCELLHOSTS * sizeof(afs_int32)) != 0)
3087 if (afs_pd_skip(ain, skip * sizeof(afs_int32)) !=0)
3090 if (afs_pd_getInt(ain, &fsport) != 0)
3093 fsport = 0; /* Privileged ports not allowed */
3095 if (afs_pd_getInt(ain, &vlport) != 0)
3098 vlport = 0; /* Privileged ports not allowed */
3100 if (afs_pd_getInt(ain, &ls) != 0)
3103 if (afs_pd_getStringPtr(ain, &newcell) != 0)
3107 if (afs_pd_getStringPtr(ain, &linkedcell) != 0)
3109 linkedstate |= CLinkedCell;
3112 linkedstate |= CNoSUID; /* setuid is disabled by default for fs newcell */
3114 afs_NewCell(newcell, cellHosts, linkedstate, linkedcell, fsport,
3119 DECL_PIOCTL(PNewAlias)
3121 /* create a new cell alias */
3122 char *realName, *aliasName;
3124 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3125 return EIO; /* Inappropriate ioctl for device */
3127 if (!afs_osi_suser(*acred))
3130 if (afs_pd_getStringPtr(ain, &aliasName) != 0)
3132 if (afs_pd_getStringPtr(ain, &realName) != 0)
3135 return afs_NewCellAlias(aliasName, realName);
3139 * VIOCGETCELL (27) - Get cell info
3143 * \param[in] ain The cell index of a specific cell
3144 * \param[out] aout list of servers in the cell
3146 * \retval EIO Error if the afs daemon hasn't started yet
3147 * \retval EDOM Error if there is no cell asked about
3149 * \post Lists the cell's server names and and addresses
3151 DECL_PIOCTL(PListCells)
3153 afs_int32 whichCell;
3154 struct cell *tcell = 0;
3158 AFS_STATCNT(PListCells);
3159 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3160 return EIO; /* Inappropriate ioctl for device */
3162 if (afs_pd_getInt(ain, &whichCell) != 0)
3165 tcell = afs_GetCellByIndex(whichCell, READ_LOCK);
3171 for (i = 0; i < AFS_MAXCELLHOSTS; i++) {
3172 if (tcell->cellHosts[i] == 0)
3174 if (afs_pd_putInt(aout, tcell->cellHosts[i]->addr->sa_ip) != 0)
3177 for (;i < AFS_MAXCELLHOSTS; i++) {
3178 if (afs_pd_putInt(aout, 0) != 0)
3181 if (afs_pd_putString(aout, tcell->cellName) != 0)
3186 afs_PutCell(tcell, READ_LOCK);
3190 DECL_PIOCTL(PListAliases)
3192 afs_int32 whichAlias;
3193 struct cell_alias *tcalias = 0;
3196 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3197 return EIO; /* Inappropriate ioctl for device */
3199 if (afs_pd_getInt(ain, &whichAlias) != 0)
3202 tcalias = afs_GetCellAlias(whichAlias);
3203 if (tcalias == NULL)
3207 if (afs_pd_putString(aout, tcalias->alias) != 0)
3209 if (afs_pd_putString(aout, tcalias->cell) != 0)
3214 afs_PutCellAlias(tcalias);
3219 * VIOC_AFS_DELETE_MT_PT (28) - Delete mount point
3223 * \param[in] ain the name of the file in this dir to remove
3224 * \param[out] aout not in use
3227 * Error if some of the standard args aren't set
3229 * Error if the argument to remove is not a directory
3231 * Error if there is no cache to remove the mount point from or
3232 * if a vcache doesn't exist
3235 * Ensure that everything is OK before deleting the mountpoint.
3236 * If not, don't delete. Delete a mount point based on a file id.
3238 DECL_PIOCTL(PRemoveMount)
3243 struct sysname_info sysState;
3244 afs_size_t offset, len;
3245 struct afs_conn *tc;
3248 struct AFSFetchStatus OutDirStatus;
3249 struct VenusFid tfid;
3250 struct AFSVolSync tsync;
3251 struct rx_connection *rxconn;
3254 /* "ain" is the name of the file in this dir to remove */
3256 AFS_STATCNT(PRemoveMount);
3259 if (afs_pd_getStringPtr(ain, &name) != 0)
3262 code = afs_VerifyVCache(avc, areq);
3265 if (vType(avc) != VDIR)
3268 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1); /* test for error below */
3271 Check_AtSys(avc, name, &sysState, areq);
3272 ObtainReadLock(&tdc->lock);
3274 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
3275 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
3276 ReleaseReadLock(&tdc->lock);
3277 bufp = sysState.name;
3282 tfid.Cell = avc->f.fid.Cell;
3283 tfid.Fid.Volume = avc->f.fid.Fid.Volume;
3284 if (!tfid.Fid.Unique && (avc->f.states & CForeign)) {
3285 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
3287 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3294 if (tvc->mvstat != 1) {
3300 ObtainWriteLock(&tvc->lock, 230);
3301 code = afs_HandleLink(tvc, areq);
3303 if (tvc->linkData) {
3304 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
3309 ReleaseWriteLock(&tvc->lock);
3310 osi_dnlc_purgedp(tvc);
3316 ObtainWriteLock(&avc->lock, 231);
3317 osi_dnlc_remove(avc, bufp, tvc);
3319 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK, &rxconn);
3321 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE);
3324 RXAFS_RemoveFile(rxconn, (struct AFSFid *)&avc->f.fid.Fid, bufp,
3325 &OutDirStatus, &tsync);
3330 } while (afs_Analyze
3331 (tc, rxconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_REMOVEFILE,
3332 SHARED_LOCK, NULL));
3337 ReleaseWriteLock(&avc->lock);
3341 /* we have the thing in the cache */
3342 ObtainWriteLock(&tdc->lock, 661);
3343 if (afs_LocalHero(avc, tdc, &OutDirStatus, 1)) {
3344 /* we can do it locally */
3345 code = afs_dir_Delete(tdc, bufp);
3347 ZapDCE(tdc); /* surprise error -- invalid value */
3351 ReleaseWriteLock(&tdc->lock);
3352 afs_PutDCache(tdc); /* drop ref count */
3354 avc->f.states &= ~CUnique; /* For the dfs xlator */
3355 ReleaseWriteLock(&avc->lock);
3358 if (sysState.allocked)
3359 osi_FreeLargeSpace(bufp);
3364 * VIOC_GETCELLSTATUS (35) - Get cell status info
3368 * \param[in] ain The cell you want status information on
3369 * \param[out] aout cell state (as a struct)
3371 * \retval EIO Error if the afs daemon hasn't started yet
3372 * \retval ENOENT Error if the cell doesn't exist
3374 * \post Returns the state of the cell as defined in a struct cell
3376 DECL_PIOCTL(PGetCellStatus)
3382 AFS_STATCNT(PGetCellStatus);
3383 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3384 return EIO; /* Inappropriate ioctl for device */
3386 if (afs_pd_getStringPtr(ain, &cellName) != 0)
3389 tcell = afs_GetCellByName(cellName, READ_LOCK);
3392 temp = tcell->states;
3393 afs_PutCell(tcell, READ_LOCK);
3395 return afs_pd_putInt(aout, temp);
3399 * VIOC_SETCELLSTATUS (36) - Set corresponding info
3404 * The cell you want to set information about, and the values you
3409 * \retval EIO Error if the afs daemon hasn't started yet
3410 * \retval EACCES Error if the user doesn't have super-user credentials
3413 * Set the state of the cell in a defined struct cell, based on
3414 * whether or not SetUID is allowed
3416 DECL_PIOCTL(PSetCellStatus)
3420 afs_int32 flags0, flags1;
3422 if (!afs_osi_suser(*acred))
3424 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3425 return EIO; /* Inappropriate ioctl for device */
3427 if (afs_pd_getInt(ain, &flags0) != 0)
3429 if (afs_pd_getInt(ain, &flags1) != 0)
3431 if (afs_pd_getStringPtr(ain, &cellName) != 0)
3434 tcell = afs_GetCellByName(cellName, WRITE_LOCK);
3437 if (flags0 & CNoSUID)
3438 tcell->states |= CNoSUID;
3440 tcell->states &= ~CNoSUID;
3441 afs_PutCell(tcell, WRITE_LOCK);
3446 * VIOC_FLUSHVOLUME (37) - Flush whole volume's data
3450 * \param[in] ain not in use (args in avc)
3451 * \param[out] aout not in use
3453 * \retval EINVAL Error if some of the standard args aren't set
3454 * \retval EIO Error if the afs daemon hasn't started yet
3457 * Flush all cached contents of a volume. Exactly what stays and what
3458 * goes depends on the platform.
3461 * Does not flush a file that a user has open and is using, because
3462 * it will be re-created on next write. Also purges the dnlc,
3463 * because things are screwed up.
3465 DECL_PIOCTL(PFlushVolumeData)
3471 afs_int32 cell, volume;
3472 struct afs_q *tq, *uq;
3473 #ifdef AFS_DARWIN80_ENV
3477 AFS_STATCNT(PFlushVolumeData);
3480 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3481 return EIO; /* Inappropriate ioctl for device */
3483 volume = avc->f.fid.Fid.Volume; /* who to zap */
3484 cell = avc->f.fid.Cell;
3487 * Clear stat'd flag from all vnodes from this volume; this will
3488 * invalidate all the vcaches associated with the volume.
3491 ObtainReadLock(&afs_xvcache);
3492 i = VCHashV(&avc->f.fid);
3493 for (tq = afs_vhashTV[i].prev; tq != &afs_vhashTV[i]; tq = uq) {
3496 if (tvc->f.fid.Fid.Volume == volume && tvc->f.fid.Cell == cell) {
3497 if (tvc->f.states & CVInit) {
3498 ReleaseReadLock(&afs_xvcache);
3499 afs_osi_Sleep(&tvc->f.states);
3502 #ifdef AFS_DARWIN80_ENV
3503 if (tvc->f.states & CDeadVnode) {
3504 ReleaseReadLock(&afs_xvcache);
3505 afs_osi_Sleep(&tvc->f.states);
3511 if (vnode_ref(vp)) {
3520 ReleaseReadLock(&afs_xvcache);
3521 #ifdef AFS_BOZONLOCK_ENV
3522 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
3524 ObtainWriteLock(&tvc->lock, 232);
3525 afs_ResetVCache(tvc, *acred, 1);
3526 ReleaseWriteLock(&tvc->lock);
3527 #ifdef AFS_BOZONLOCK_ENV
3528 afs_BozonUnlock(&tvc->pvnLock, tvc);
3530 #ifdef AFS_DARWIN80_ENV
3531 vnode_put(AFSTOV(tvc));
3533 ObtainReadLock(&afs_xvcache);
3535 /* our tvc ptr is still good until now */
3539 ReleaseReadLock(&afs_xvcache);
3542 ObtainWriteLock(&afs_xdcache, 328); /* needed to flush any stuff */
3543 for (i = 0; i < afs_cacheFiles; i++) {
3544 if (!(afs_indexFlags[i] & IFEverUsed))
3545 continue; /* never had any data */
3546 tdc = afs_GetValidDSlot(i);
3550 if (tdc->refCount <= 1) { /* too high, in use by running sys call */
3551 ReleaseReadLock(&tdc->tlock);
3552 if (tdc->f.fid.Fid.Volume == volume && tdc->f.fid.Cell == cell) {
3553 if (!(afs_indexFlags[i] & (IFDataMod | IFFree | IFDiscarded))) {
3554 /* if the file is modified, but has a ref cnt of only 1,
3555 * then someone probably has the file open and is writing
3556 * into it. Better to skip flushing such a file, it will be
3557 * brought back immediately on the next write anyway.
3559 * Skip if already freed.
3561 * If we *must* flush, then this code has to be rearranged
3562 * to call afs_storeAllSegments() first */
3563 afs_FlushDCache(tdc);
3567 ReleaseReadLock(&tdc->tlock);
3569 afs_PutDCache(tdc); /* bumped by getdslot */
3571 ReleaseWriteLock(&afs_xdcache);
3573 ObtainReadLock(&afs_xvolume);
3574 for (i = 0; i < NVOLS; i++) {
3575 for (tv = afs_volumes[i]; tv; tv = tv->next) {
3576 if (tv->volume == volume) {
3577 afs_ResetVolumeInfo(tv);
3582 ReleaseReadLock(&afs_xvolume);
3584 /* probably, a user is doing this, probably, because things are screwed up.
3585 * maybe it's the dnlc's fault? */
3592 * VIOCGETVCXSTATUS (41) - gets vnode x status
3597 * not in use (avc used)
3599 * vcxstat: the file id, the data version, any lock, the parent vnode,
3600 * the parent unique id, the trunc position, the callback, cbExpires,
3601 * what access is being made, what files are open,
3602 * any users executing/writing, the flock count, the states,
3606 * Error if some of the initial default arguments aren't set
3608 * Error if access to check the mode bits is denied
3611 * gets stats for the vnode, a struct listed in vcxstat
3613 DECL_PIOCTL(PGetVnodeXStatus)
3616 struct vcxstat stat;
3619 /* AFS_STATCNT(PGetVnodeXStatus); */
3622 code = afs_VerifyVCache(avc, areq);
3625 if (vType(avc) == VDIR)
3626 mode = PRSFS_LOOKUP;
3629 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
3632 memset(&stat, 0, sizeof(struct vcxstat));
3633 stat.fid = avc->f.fid;
3634 hset32(stat.DataVersion, hgetlo(avc->f.m.DataVersion));
3635 stat.lock = avc->lock;
3636 stat.parentVnode = avc->f.parent.vnode;
3637 stat.parentUnique = avc->f.parent.unique;
3638 hset(stat.flushDV, avc->flushDV);
3639 hset(stat.mapDV, avc->mapDV);
3640 stat.truncPos = avc->f.truncPos;
3641 { /* just grab the first two - won't break anything... */
3642 struct axscache *ac;
3644 for (i = 0, ac = avc->Access; ac && i < CPSIZE; i++, ac = ac->next) {
3645 stat.randomUid[i] = ac->uid;
3646 stat.randomAccess[i] = ac->axess;
3649 stat.callback = afs_data_pointer_to_int32(avc->callback);
3650 stat.cbExpires = avc->cbExpires;
3651 stat.anyAccess = avc->f.anyAccess;
3652 stat.opens = avc->opens;
3653 stat.execsOrWriters = avc->execsOrWriters;
3654 stat.flockCount = avc->flockCount;
3655 stat.mvstat = avc->mvstat;
3656 stat.states = avc->f.states;
3657 return afs_pd_putBytes(aout, &stat, sizeof(struct vcxstat));
3661 DECL_PIOCTL(PGetVnodeXStatus2)
3664 struct vcxstat2 stat;
3669 code = afs_VerifyVCache(avc, areq);
3672 if (vType(avc) == VDIR)
3673 mode = PRSFS_LOOKUP;
3676 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
3679 memset(&stat, 0, sizeof(struct vcxstat2));
3681 stat.cbExpires = avc->cbExpires;
3682 stat.anyAccess = avc->f.anyAccess;
3683 stat.mvstat = avc->mvstat;
3684 stat.callerAccess = afs_GetAccessBits(avc, ~0, areq);
3686 return afs_pd_putBytes(aout, &stat, sizeof(struct vcxstat2));
3691 * VIOC_AFS_SYSNAME (38) - Change @sys value
3695 * \param[in] ain new value for @sys
3696 * \param[out] aout count, entry, list (debug values?)
3699 * Error if afsd isn't running, the new sysname is too large,
3700 * the new sysname causes issues (starts with a . or ..),
3701 * there is no PAG set in the credentials, or the user of a PAG
3704 * Error if the user doesn't have super-user credentials
3707 * Set the value of @sys if these things work: if the input isn't
3708 * too long or if input doesn't start with . or ..
3711 * We require root for local sysname changes, but not for remote
3712 * (since we don't really believe remote uids anyway)
3713 * outname[] shouldn't really be needed- this is left as an
3714 * exercise for the reader.
3716 DECL_PIOCTL(PSetSysName)
3718 char *inname = NULL;
3719 char outname[MAXSYSNAME];
3720 afs_int32 setsysname;
3722 struct afs_exporter *exporter;
3723 struct unixuser *au;
3724 afs_int32 pag, error;
3725 int t, count, num = 0, allpags = 0;
3727 struct afs_pdata validate;
3729 AFS_STATCNT(PSetSysName);
3730 if (!afs_globalVFS) {
3731 /* Afsd is NOT running; disable it */
3732 #if defined(KERNEL_HAVE_UERROR)
3733 return (setuerror(EINVAL), EINVAL);
3738 if (afs_pd_getInt(ain, &setsysname) != 0)
3740 if (setsysname & 0x8000) {
3742 setsysname &= ~0x8000;
3747 if (setsysname < 0 || setsysname > MAXNUMSYSNAMES)
3750 for (count = 0; count < setsysname; count++) {
3751 if (afs_pd_getStringPtr(&validate, &inname) != 0)
3754 if (t >= MAXSYSNAME || t <= 0)
3756 /* check for names that can shoot us in the foot */
3757 if (inname[0] == '.' && (inname[1] == 0
3758 || (inname[1] == '.' && inname[2] == 0)))
3761 /* args ok, so go back to the beginning of that section */
3763 if (afs_pd_getStringPtr(ain, &inname) != 0)
3767 if (afs_cr_gid(*acred) == RMTUSER_REQ ||
3768 afs_cr_gid(*acred) == RMTUSER_REQ_PRIV) { /* Handles all exporters */
3769 if (allpags && afs_cr_gid(*acred) != RMTUSER_REQ_PRIV) {
3772 pag = PagInCred(*acred);
3774 return EINVAL; /* Better than panicing */
3776 if (!(au = afs_FindUser(pag, -1, READ_LOCK))) {
3777 return EINVAL; /* Better than panicing */
3779 if (!(exporter = au->exporter)) {
3780 afs_PutUser(au, READ_LOCK);
3781 return EINVAL; /* Better than panicing */
3783 error = EXP_SYSNAME(exporter, inname, &sysnamelist,
3786 if (error == ENODEV)
3787 foundname = 0; /* sysname not set yet! */
3789 afs_PutUser(au, READ_LOCK);
3794 strcpy(outname, sysnamelist[0]);
3796 afs_PutUser(au, READ_LOCK);
3800 /* Not xlating, so local case */
3802 osi_Panic("PSetSysName: !afs_sysname\n");
3803 if (!setsysname) { /* user just wants the info */
3804 strcpy(outname, afs_sysname);
3805 foundname = afs_sysnamecount;
3806 sysnamelist = afs_sysnamelist;
3807 } else { /* Local guy; only root can change sysname */
3808 if (!afs_osi_suser(*acred))
3811 /* allpags makes no sense for local use */
3815 /* clear @sys entries from the dnlc, once afs_lookup can
3816 * do lookups of @sys entries and thinks it can trust them */
3817 /* privs ok, store the entry, ... */
3819 if (strlen(inname) >= MAXSYSNAME-1)
3821 strcpy(afs_sysname, inname);
3823 if (setsysname > 1) { /* ... or list */
3824 for (count = 1; count < setsysname; ++count) {
3825 if (!afs_sysnamelist[count])
3827 ("PSetSysName: no afs_sysnamelist entry to write\n");
3828 if (afs_pd_getString(ain, afs_sysnamelist[count],
3833 afs_sysnamecount = setsysname;
3838 if (afs_pd_putInt(aout, foundname) != 0)
3841 if (afs_pd_putString(aout, outname) != 0)
3843 for (count = 1; count < foundname; ++count) { /* ... or list. */
3844 if (!sysnamelist[count])
3846 ("PSetSysName: no afs_sysnamelist entry to read\n");
3847 t = strlen(sysnamelist[count]);
3848 if (t >= MAXSYSNAME)
3849 osi_Panic("PSetSysName: sysname entry garbled\n");
3850 if (afs_pd_putString(aout, sysnamelist[count]) != 0)
3858 /* sequential search through the list of touched cells is not a good
3859 * long-term solution here. For small n, though, it should be just
3860 * fine. Should consider special-casing the local cell for large n.
3861 * Likewise for PSetSPrefs.
3863 * s - number of ids in array l[] -- NOT index of last id
3864 * l - array of cell ids which have volumes that need to be sorted
3865 * vlonly - sort vl servers or file servers?
3868 ReSortCells_cb(struct cell *cell, void *arg)
3870 afs_int32 *p = (afs_int32 *) arg;
3871 afs_int32 *l = p + 1;
3874 for (i = 0; i < s; i++) {
3875 if (l[i] == cell->cellNum) {
3876 ObtainWriteLock(&cell->lock, 690);
3877 afs_SortServers(cell->cellHosts, AFS_MAXCELLHOSTS);
3878 ReleaseWriteLock(&cell->lock);
3886 ReSortCells(int s, afs_int32 * l, int vlonly)
3894 p = afs_osi_Alloc(sizeof(afs_int32) * (s + 1));
3895 osi_Assert(p != NULL);
3897 memcpy(p + 1, l, s * sizeof(afs_int32));
3898 afs_TraverseCells(&ReSortCells_cb, p);
3899 afs_osi_Free(p, sizeof(afs_int32) * (s + 1));
3903 ObtainReadLock(&afs_xvolume);
3904 for (i = 0; i < NVOLS; i++) {
3905 for (j = afs_volumes[i]; j; j = j->next) {
3906 for (k = 0; k < s; k++)
3907 if (j->cell == l[k]) {
3908 ObtainWriteLock(&j->lock, 233);
3909 afs_SortServers(j->serverHost, AFS_MAXHOSTS);
3910 ReleaseWriteLock(&j->lock);
3915 ReleaseReadLock(&afs_xvolume);
3919 static int debugsetsp = 0;
3921 afs_setsprefs(struct spref *sp, unsigned int num, unsigned int vlonly)
3924 int i, j, k, matches, touchedSize;
3925 struct server *srvr = NULL;
3926 afs_int32 touched[34];
3930 for (k = 0; k < num; sp++, k++) {
3932 afs_warn("sp host=%x, rank=%d\n", sp->host.s_addr, sp->rank);
3935 ObtainReadLock(&afs_xserver);
3937 i = SHash(sp->host.s_addr);
3938 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3939 if (sa->sa_ip == sp->host.s_addr) {
3941 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
3942 || (sa->sa_portal == AFS_FSPORT);
3943 if ((!vlonly && isfs) || (vlonly && !isfs)) {
3950 if (sa && matches) { /* found one! */
3952 afs_warn("sa ip=%x, ip_rank=%d\n", sa->sa_ip, sa->sa_iprank);
3954 sa->sa_iprank = sp->rank + afs_randomMod15();
3955 afs_SortOneServer(sa->server);
3958 /* if we don't know yet what cell it's in, this is moot */
3959 for (j = touchedSize - 1;
3960 j >= 0 && touched[j] != srvr->cell->cellNum; j--)
3961 /* is it in our list of touched cells ? */ ;
3962 if (j < 0) { /* no, it's not */
3963 touched[touchedSize++] = srvr->cell->cellNum;
3964 if (touchedSize >= 32) { /* watch for ovrflow */
3965 ReleaseReadLock(&afs_xserver);
3966 ReSortCells(touchedSize, touched, vlonly);
3968 ObtainReadLock(&afs_xserver);
3974 ReleaseReadLock(&afs_xserver);
3975 /* if we didn't find one, start to create one. */
3976 /* Note that it doesn't have a cell yet... */
3978 afs_uint32 temp = sp->host.s_addr;
3980 afs_GetServer(&temp, 1, 0, (vlonly ? AFS_VLPORT : AFS_FSPORT),
3981 WRITE_LOCK, (afsUUID *) 0, 0, NULL);
3982 srvr->addr->sa_iprank = sp->rank + afs_randomMod15();
3983 afs_PutServer(srvr, WRITE_LOCK);
3985 } /* for all cited preferences */
3987 ReSortCells(touchedSize, touched, vlonly);
3992 * VIOC_SETPREFS (46) - Set server ranks
3994 * \param[in] ain the sprefs value you want the sprefs to be set to
3995 * \param[out] aout not in use
3998 * Error if the afs daemon hasn't started yet
4000 * Error if the user doesn't have super-user credentials
4002 * Error if the struct setsprefs is too large or if it multiplied
4003 * by the number of servers is too large
4005 * \post set the sprefs using the afs_setsprefs() function
4007 DECL_PIOCTL(PSetSPrefs)
4009 struct setspref *ssp;
4013 AFS_STATCNT(PSetSPrefs);
4015 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4016 return EIO; /* Inappropriate ioctl for device */
4018 if (!afs_osi_suser(*acred))
4021 /* The I/O handling here is ghastly, as it relies on overrunning the ends
4022 * of arrays. But, i'm not quite brave enough to change it yet. */
4024 ainSize = ain->remaining;
4026 if (ainSize < sizeof(struct setspref))
4029 ssp = (struct setspref *)ainPtr;
4030 if (ainSize < (sizeof(struct setspref)
4031 + sizeof(struct spref) * (ssp->num_servers-1)))
4034 afs_setsprefs(&(ssp->servers[0]), ssp->num_servers,
4035 (ssp->flags & DBservers));
4040 * VIOC_SETPREFS33 (42) - Set server ranks (deprecated)
4042 * \param[in] ain the server preferences to be set
4043 * \param[out] aout not in use
4045 * \retval EIO Error if the afs daemon hasn't started yet
4046 * \retval EACCES Error if the user doesn't have super-user credentials
4048 * \post set the server preferences, calling a function
4050 * \notes this may only be performed by the local root user.
4052 DECL_PIOCTL(PSetSPrefs33)
4054 AFS_STATCNT(PSetSPrefs);
4055 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4056 return EIO; /* Inappropriate ioctl for device */
4059 if (!afs_osi_suser(*acred))
4062 afs_setsprefs((struct spref *)afs_pd_where(ain),
4063 afs_pd_remaining(ain) / sizeof(struct spref),
4069 * VIOC_GETSPREFS (43) - Get server ranks
4073 * \param[in] ain the server preferences to get
4074 * \param[out] aout the server preferences information
4076 * \retval EIO Error if the afs daemon hasn't started yet
4077 * \retval ENOENT Error if the sprefrequest is too large
4079 * \post Get the sprefs
4082 * in the hash table of server structs, all servers with the same
4083 * IP address; will be on the same overflow chain; This could be
4084 * sped slightly in some circumstances by having it cache the
4085 * immediately previous slot in the hash table and some
4086 * supporting information; Only reports file servers now.
4088 DECL_PIOCTL(PGetSPrefs)
4090 struct sprefrequest spin; /* input */
4091 struct sprefinfo *spout; /* output */
4092 struct spref *srvout; /* one output component */
4093 int i, j; /* counters for hash table traversal */
4094 struct server *srvr; /* one of CM's server structs */
4096 int vlonly; /* just return vlservers ? */
4099 AFS_STATCNT(PGetSPrefs);
4100 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4101 return EIO; /* Inappropriate ioctl for device */
4103 /* Work out from the size whether we've got a new, or old, style pioctl */
4104 if (afs_pd_remaining(ain) < sizeof(struct sprefrequest)) {
4105 if (afs_pd_getBytes(ain, &spin, sizeof(struct sprefrequest_33)) != 0)
4110 if (afs_pd_getBytes(ain, &spin, sizeof(struct sprefrequest)) != 0)
4112 vlonly = (spin.flags & DBservers);
4115 /* This code relies on overflowing arrays. It's ghastly, but I'm not
4116 * quite brave enough to tackle it yet ...
4119 /* struct sprefinfo includes 1 server struct... that size gets added
4120 * in during the loop that follows.
4122 spout = afs_pd_inline(aout,
4123 sizeof(struct sprefinfo) - sizeof(struct spref));
4124 spout->next_offset = spin.offset;
4125 spout->num_servers = 0;
4126 srvout = spout->servers;
4128 ObtainReadLock(&afs_xserver);
4129 for (i = 0, j = 0; j < NSERVERS; j++) { /* sift through hash table */
4130 for (sa = afs_srvAddrs[j]; sa; sa = sa->next_bkt, i++) {
4131 if (spin.offset > (unsigned short)i) {
4132 continue; /* catch up to where we left off */
4134 spout->next_offset++;
4137 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
4138 || (sa->sa_portal == AFS_FSPORT);
4140 if ((vlonly && isfs) || (!vlonly && !isfs)) {
4141 /* only report ranks for vl servers */
4145 /* Check we've actually got the space we're about to use */
4146 if (afs_pd_inline(aout, sizeof(struct spref)) == NULL) {
4147 ReleaseReadLock(&afs_xserver); /* no more room! */
4151 srvout->host.s_addr = sa->sa_ip;
4152 srvout->rank = sa->sa_iprank;
4153 spout->num_servers++;
4157 ReleaseReadLock(&afs_xserver);
4159 spout->next_offset = 0; /* start over from the beginning next time */
4164 /* Enable/Disable the specified exporter. Must be root to disable an exporter */
4165 int afs_NFSRootOnly = 1;
4167 * VIOC_EXPORTAFS (39) - Export afs to nfs clients
4172 * an integer containing the desired exportee flags
4174 * an integer containing the current exporter flags
4176 * \retval ENODEV Error if the exporter doesn't exist
4177 * \retval EACCES Error if the user doesn't have super-user credentials
4180 * Changes the state of various values to reflect the change
4181 * of the export values between nfs and afs.
4183 * \notes Legacy code obtained from IBM.
4185 DECL_PIOCTL(PExportAfs)
4187 afs_int32 export, newint = 0;
4188 afs_int32 type, changestate, handleValue, convmode, pwsync, smounts;
4189 afs_int32 rempags = 0, pagcb = 0;
4190 struct afs_exporter *exporter;
4192 AFS_STATCNT(PExportAfs);
4193 if (afs_pd_getInt(ain, &handleValue) != 0)
4195 type = handleValue >> 24;
4200 exporter = exporter_find(type);
4202 export = handleValue & 3;
4203 changestate = handleValue & 0xfff;
4204 smounts = (handleValue >> 2) & 3;
4205 pwsync = (handleValue >> 4) & 3;
4206 convmode = (handleValue >> 6) & 3;
4207 rempags = (handleValue >> 8) & 3;
4208 pagcb = (handleValue >> 10) & 3;
4210 changestate = (handleValue >> 16) & 0x1;
4211 convmode = (handleValue >> 16) & 0x2;
4212 pwsync = (handleValue >> 16) & 0x4;
4213 smounts = (handleValue >> 16) & 0x8;
4214 export = handleValue & 0xff;
4217 /* Failed finding desired exporter; */
4221 handleValue = exporter->exp_states;
4222 if (afs_pd_putInt(aout, handleValue) != 0)
4225 if (!afs_osi_suser(*acred))
4226 return EACCES; /* Only superuser can do this */
4230 exporter->exp_states |= EXP_EXPORTED;
4232 exporter->exp_states &= ~EXP_EXPORTED;
4236 exporter->exp_states |= EXP_UNIXMODE;
4238 exporter->exp_states &= ~EXP_UNIXMODE;
4242 exporter->exp_states |= EXP_PWSYNC;
4244 exporter->exp_states &= ~EXP_PWSYNC;
4248 afs_NFSRootOnly = 0;
4249 exporter->exp_states |= EXP_SUBMOUNTS;
4251 afs_NFSRootOnly = 1;
4252 exporter->exp_states &= ~EXP_SUBMOUNTS;
4257 exporter->exp_states |= EXP_CLIPAGS;
4259 exporter->exp_states &= ~EXP_CLIPAGS;
4263 exporter->exp_states |= EXP_CALLBACK;
4265 exporter->exp_states &= ~EXP_CALLBACK;
4267 handleValue = exporter->exp_states;
4268 if (afs_pd_putInt(aout, handleValue) != 0)
4272 exporter->exp_states |= EXP_EXPORTED;
4274 exporter->exp_states &= ~EXP_EXPORTED;
4276 exporter->exp_states |= EXP_UNIXMODE;
4278 exporter->exp_states &= ~EXP_UNIXMODE;
4280 exporter->exp_states |= EXP_PWSYNC;
4282 exporter->exp_states &= ~EXP_PWSYNC;
4284 afs_NFSRootOnly = 0;
4285 exporter->exp_states |= EXP_SUBMOUNTS;
4287 afs_NFSRootOnly = 1;
4288 exporter->exp_states &= ~EXP_SUBMOUNTS;
4297 * VIOC_GAG (44) - Silence Cache Manager
4301 * \param[in] ain the flags to either gag or de-gag the cache manager
4302 * \param[out] aout not in use
4304 * \retval EACCES Error if the user doesn't have super-user credentials
4306 * \post set the gag flags, then show these flags
4310 struct gaginfo *gagflags;
4312 if (!afs_osi_suser(*acred))
4315 gagflags = afs_pd_inline(ain, sizeof(*gagflags));
4316 if (gagflags == NULL)
4318 afs_showflags = gagflags->showflags;
4324 * VIOC_TWIDDLE (45) - Adjust RX knobs
4328 * \param[in] ain the previous settings of the 'knobs'
4329 * \param[out] aout not in use
4331 * \retval EACCES Error if the user doesn't have super-user credentials
4333 * \post build out the struct rxp, from a struct rx
4335 DECL_PIOCTL(PTwiddleRx)
4337 struct rxparams *rxp;
4339 if (!afs_osi_suser(*acred))
4342 rxp = afs_pd_inline(ain, sizeof(*rxp));
4346 if (rxp->rx_initReceiveWindow)
4347 rx_initReceiveWindow = rxp->rx_initReceiveWindow;
4348 if (rxp->rx_maxReceiveWindow)
4349 rx_maxReceiveWindow = rxp->rx_maxReceiveWindow;
4350 if (rxp->rx_initSendWindow)
4351 rx_initSendWindow = rxp->rx_initSendWindow;
4352 if (rxp->rx_maxSendWindow)
4353 rx_maxSendWindow = rxp->rx_maxSendWindow;
4354 if (rxp->rxi_nSendFrags)
4355 rxi_nSendFrags = rxp->rxi_nSendFrags;
4356 if (rxp->rxi_nRecvFrags)
4357 rxi_nRecvFrags = rxp->rxi_nRecvFrags;
4358 if (rxp->rxi_OrphanFragSize)
4359 rxi_OrphanFragSize = rxp->rxi_OrphanFragSize;
4360 if (rxp->rx_maxReceiveSize) {
4361 rx_maxReceiveSize = rxp->rx_maxReceiveSize;
4362 rx_maxReceiveSizeUser = rxp->rx_maxReceiveSize;
4364 if (rxp->rx_MyMaxSendSize)
4365 rx_MyMaxSendSize = rxp->rx_MyMaxSendSize;
4371 * VIOC_GETINITPARAMS (49) - Get initial cache manager parameters
4375 * \param[in] ain not in use
4376 * \param[out] aout initial cache manager params
4379 * Error if the initial parameters are bigger than some PIGGYSIZE
4381 * \post return the initial cache manager parameters
4383 DECL_PIOCTL(PGetInitParams)
4385 if (sizeof(struct cm_initparams) > PIGGYSIZE)
4388 return afs_pd_putBytes(aout, &cm_initParams,
4389 sizeof(struct cm_initparams));
4392 #ifdef AFS_SGI65_ENV
4393 /* They took crget() from us, so fake it. */
4398 cr = crdup(get_current_cred());
4399 memset(cr, 0, sizeof(cred_t));
4400 #if CELL || CELL_PREPARE
4408 * VIOC_GETRXKCRYPT (55) - Get rxkad encryption flag
4412 * \param[in] ain not in use
4413 * \param[out] aout value of cryptall
4415 * \post Turns on, or disables, rxkad encryption by setting the cryptall global
4417 DECL_PIOCTL(PGetRxkcrypt)
4419 return afs_pd_putInt(aout, cryptall);
4423 * VIOC_SETRXKCRYPT (56) - Set rxkad encryption flag
4427 * \param[in] ain the argument whether or not things should be encrypted
4428 * \param[out] aout not in use
4431 * Error if the user doesn't have super-user credentials
4433 * Error if the input is too big, or if the input is outside the
4434 * bounds of what it can be set to
4436 * \post set whether or not things should be encrypted
4439 * may need to be modified at a later date to take into account
4440 * other values for cryptall (beyond true or false)
4442 DECL_PIOCTL(PSetRxkcrypt)
4446 if (!afs_osi_suser(*acred))
4448 if (afs_pd_getInt(ain, &tmpval) != 0)
4450 /* if new mappings added later this will need to be changed */
4451 if (tmpval != 0 && tmpval != 1)
4457 #ifdef AFS_NEED_CLIENTCONTEXT
4459 * Create new credentials to correspond to a remote user with given
4460 * <hostaddr, uid, g0, g1>. This allows a server running as root to
4461 * provide pioctl (and other) services to foreign clients (i.e. nfs
4462 * clients) by using this call to `become' the client.
4465 #define PIOCTL_HEADER 6
4467 HandleClientContext(struct afs_ioctl *ablob, int *com,
4468 afs_ucred_t **acred, afs_ucred_t *credp)
4471 afs_uint32 hostaddr;
4472 afs_int32 uid, g0, g1, i, code, pag, exporter_type, isroot = 0;
4473 struct afs_exporter *exporter, *outexporter;
4474 afs_ucred_t *newcred;
4475 struct unixuser *au;
4476 afs_uint32 comp = *com & 0xff00;
4478 #if defined(AFS_SUN510_ENV)
4482 #if defined(AFS_SGIMP_ENV)
4483 osi_Assert(ISAFS_GLOCK());
4485 AFS_STATCNT(HandleClientContext);
4486 if (ablob->in_size < PIOCTL_HEADER * sizeof(afs_int32)) {
4487 /* Must at least include the PIOCTL_HEADER header words
4488 * required by the protocol */
4489 return EINVAL; /* Too small to be good */
4491 ain = inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
4492 AFS_COPYIN(ablob->in, ain, PIOCTL_HEADER * sizeof(afs_int32), code);
4494 osi_FreeLargeSpace(inData);
4498 /* Extract information for remote user */
4499 hostaddr = *((afs_uint32 *) ain);
4500 ain += sizeof(hostaddr);
4501 uid = *((afs_uint32 *) ain);
4503 g0 = *((afs_uint32 *) ain);
4505 g1 = *((afs_uint32 *) ain);
4507 *com = *((afs_uint32 *) ain);
4508 ain += sizeof(afs_int32);
4509 exporter_type = *((afs_uint32 *) ain);/* In case we support more than NFS */
4512 * Of course, one must be root for most of these functions, but
4513 * we'll allow (for knfs) you to set things if the pag is 0 and
4514 * you're setting tokens or unlogging.
4517 if (!afs_osi_suser(credp)) {
4518 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
4519 /* Since SGI's suser() returns explicit failure after the call.. */
4522 /* check for acceptable opcodes for normal folks, which are, so far,
4523 * get/set tokens, sysname, and unlog.
4525 if (i != 9 && i != 3 && i != 38 && i != 8) {
4526 osi_FreeLargeSpace(inData);
4531 ablob->in_size -= PIOCTL_HEADER * sizeof(afs_int32);
4532 ablob->in += PIOCTL_HEADER * sizeof(afs_int32);
4533 osi_FreeLargeSpace(inData);
4536 * We map uid 0 to nobody to match the mapping that the nfs
4537 * server does and to ensure that the suser() calls in the afs
4538 * code fails for remote client roots.
4540 uid = afs_nobody; /* NFS_NOBODY == -2 */
4544 #ifdef AFS_AIX41_ENV
4547 afs_set_cr_gid(newcred, isroot ? RMTUSER_REQ_PRIV : RMTUSER_REQ);
4548 #ifdef AFS_AIX51_ENV
4549 newcred->cr_groupset.gs_union.un_groups[0] = g0;
4550 newcred->cr_groupset.gs_union.un_groups[1] = g1;
4551 #elif defined(AFS_LINUX26_ENV)
4552 # ifdef AFS_LINUX26_ONEGROUP_ENV
4553 afs_set_cr_group_info(newcred, groups_alloc(1)); /* nothing sets this */
4554 l = (((g0-0x3f00) & 0x3fff) << 14) | ((g1-0x3f00) & 0x3fff);
4555 h = ((g0-0x3f00) >> 14);
4556 h = ((g1-0x3f00) >> 14) + h + h + h;
4557 GROUP_AT(afs_cr_group_info(newcred), 0) = ((h << 28) | l);
4559 afs_set_cr_group_info(newcred, groups_alloc(2));
4560 GROUP_AT(afs_cr_group_info(newcred), 0) = g0;
4561 GROUP_AT(afs_cr_group_info(newcred), 1) = g1;
4563 #elif defined(AFS_SUN510_ENV)
4566 crsetgroups(newcred, 2, gids);
4568 newcred->cr_groups[0] = g0;
4569 newcred->cr_groups[1] = g1;
4572 newcred->cr_ngrps = 2;
4573 #elif !defined(AFS_LINUX26_ENV) && !defined(AFS_SUN510_ENV)
4574 # if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_FBSD80_ENV)
4575 newcred->cr_ngroups = 2;
4577 for (i = 2; i < NGROUPS; i++)
4578 newcred->cr_groups[i] = NOGROUP;
4581 if (!(exporter = exporter_find(exporter_type))) {
4582 /* Exporter wasn't initialized or an invalid exporter type */
4586 if (exporter->exp_states & EXP_PWSYNC) {
4587 if (uid != afs_cr_uid(credp)) {
4589 return ENOEXEC; /* XXX Find a better errno XXX */
4592 afs_set_cr_uid(newcred, uid); /* Only temporary */
4593 code = EXP_REQHANDLER(exporter, &newcred, hostaddr, &pag, &outexporter);
4594 /* The client's pag is the only unique identifier for it */
4595 afs_set_cr_uid(newcred, pag);
4597 if (!code && *com == PSETPAG) {
4598 /* Special case for 'setpag' */
4599 afs_uint32 pagvalue = genpag();
4601 au = afs_GetUser(pagvalue, -1, WRITE_LOCK); /* a new unixuser struct */
4603 * Note that we leave the 'outexporter' struct held so it won't
4606 au->exporter = outexporter;
4607 if (ablob->out_size >= 4) {
4608 AFS_COPYOUT((char *)&pagvalue, ablob->out, sizeof(afs_int32),
4611 afs_PutUser(au, WRITE_LOCK);
4614 return PSETPAG; /* Special return for setpag */
4616 EXP_RELE(outexporter);
4619 *com = (*com) | comp;
4622 #endif /* AFS_NEED_CLIENTCONTEXT */
4626 * VIOC_GETCPREFS (50) - Get client interface
4630 * \param[in] ain sprefrequest input
4631 * \param[out] aout spref information
4633 * \retval EIO Error if the afs daemon hasn't started yet
4634 * \retval EINVAL Error if some of the standard args aren't set
4637 * get all interface addresses and other information of the client
4640 DECL_PIOCTL(PGetCPrefs)
4642 struct sprefrequest *spin; /* input */
4643 struct sprefinfo *spout; /* output */
4644 struct spref *srvout; /* one output component */
4648 AFS_STATCNT(PGetCPrefs);
4649 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4650 return EIO; /* Inappropriate ioctl for device */
4652 spin = afs_pd_inline(ain, sizeof(*spin));
4656 /* Output spout relies on writing past the end of arrays. It's horrible,
4657 * but I'm not quite brave enough to tackle it yet */
4658 spout = (struct sprefinfo *)aout->ptr;
4660 maxNumber = spin->num_servers; /* max addrs this time */
4661 srvout = spout->servers;
4663 ObtainReadLock(&afs_xinterface);
4665 /* copy out the client interface information from the
4666 * kernel data structure "interface" to the output buffer
4668 for (i = spin->offset, j = 0; (i < afs_cb_interface.numberOfInterfaces)
4669 && (j < maxNumber); i++, j++, srvout++)
4670 srvout->host.s_addr = afs_cb_interface.addr_in[i];
4672 spout->num_servers = j;
4673 aout->ptr += sizeof(struct sprefinfo) + (j - 1) * sizeof(struct spref);
4675 if (i >= afs_cb_interface.numberOfInterfaces)
4676 spout->next_offset = 0; /* start from beginning again */
4678 spout->next_offset = spin->offset + j;
4680 ReleaseReadLock(&afs_xinterface);
4685 * VIOC_SETCPREFS (51) - Set client interface
4689 * \param[in] ain the interfaces you want set
4690 * \param[out] aout not in use
4692 * \retval EIO Error if the afs daemon hasn't started yet
4693 * \retval EINVAL Error if the input is too large for the struct
4694 * \retval ENOMEM Error if there are too many servers
4696 * \post set the callbak interfaces addresses to those of the hosts
4698 DECL_PIOCTL(PSetCPrefs)
4702 struct setspref *sin;
4705 AFS_STATCNT(PSetCPrefs);
4706 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4707 return EIO; /* Inappropriate ioctl for device */
4709 /* Yuck. Input to this function relies on reading past the end of
4710 * structures. Bodge it for now.
4713 ainSize = ain->remaining;
4715 sin = (struct setspref *)ainPtr;
4717 if (ainSize < sizeof(struct setspref))
4719 #if 0 /* num_servers is unsigned */
4720 if (sin->num_servers < 0)
4723 if (sin->num_servers > AFS_MAX_INTERFACE_ADDR)
4726 ObtainWriteLock(&afs_xinterface, 412);
4727 afs_cb_interface.numberOfInterfaces = sin->num_servers;
4728 for (i = 0; (unsigned short)i < sin->num_servers; i++)
4729 afs_cb_interface.addr_in[i] = sin->servers[i].host.s_addr;
4731 ReleaseWriteLock(&afs_xinterface);
4736 * VIOC_AFS_FLUSHMOUNT (52) - Flush mount symlink data
4741 * the last part of a path to a mount point, which tells us what to flush
4746 * Error if some of the initial arguments aren't set
4748 * Error if the initial argument for the mount point isn't a directory
4750 * Error if the dcache entry isn't set
4753 * remove all of the mount data from the dcache regarding a
4754 * certain mount point
4756 DECL_PIOCTL(PFlushMount)
4761 struct VenusFid tfid;
4764 struct sysname_info sysState;
4765 afs_size_t offset, len;
4767 AFS_STATCNT(PFlushMount);
4771 if (afs_pd_getStringPtr(ain, &mount) != 0)
4774 code = afs_VerifyVCache(avc, areq);
4777 if (vType(avc) != VDIR) {
4780 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
4783 Check_AtSys(avc, mount, &sysState, areq);
4784 ObtainReadLock(&tdc->lock);
4786 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
4787 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
4788 ReleaseReadLock(&tdc->lock);
4789 afs_PutDCache(tdc); /* we're done with the data */
4790 bufp = sysState.name;
4794 tfid.Cell = avc->f.fid.Cell;
4795 tfid.Fid.Volume = avc->f.fid.Fid.Volume;
4796 if (!tfid.Fid.Unique && (avc->f.states & CForeign)) {
4797 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
4799 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
4805 if (tvc->mvstat != 1) {
4810 #ifdef AFS_BOZONLOCK_ENV
4811 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
4813 ObtainWriteLock(&tvc->lock, 649);
4814 ObtainWriteLock(&afs_xcbhash, 650);
4815 afs_DequeueCallback(tvc);
4816 tvc->f.states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
4817 ReleaseWriteLock(&afs_xcbhash);
4818 /* now find the disk cache entries */
4819 afs_TryToSmush(tvc, *acred, 1);
4820 osi_dnlc_purgedp(tvc);
4821 if (tvc->linkData && !(tvc->f.states & CCore)) {
4822 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
4823 tvc->linkData = NULL;
4825 ReleaseWriteLock(&tvc->lock);
4826 #ifdef AFS_BOZONLOCK_ENV
4827 afs_BozonUnlock(&tvc->pvnLock, tvc);
4831 if (sysState.allocked)
4832 osi_FreeLargeSpace(bufp);
4837 * VIOC_RXSTAT_PROC (53) - Control process RX statistics
4841 * \param[in] ain the flags that control which stats to use
4842 * \param[out] aout not in use
4844 * \retval EACCES Error if the user doesn't have super-user credentials
4845 * \retval EINVAL Error if the flag input is too long
4848 * either enable process RPCStats, disable process RPCStats,
4849 * or clear the process RPCStats
4851 DECL_PIOCTL(PRxStatProc)
4855 if (!afs_osi_suser(*acred))
4858 if (afs_pd_getInt(ain, &flags) != 0)
4861 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK))
4864 if (flags & AFSCALL_RXSTATS_ENABLE) {
4865 rx_enableProcessRPCStats();
4867 if (flags & AFSCALL_RXSTATS_DISABLE) {
4868 rx_disableProcessRPCStats();
4870 if (flags & AFSCALL_RXSTATS_CLEAR) {
4871 rx_clearProcessRPCStats(AFS_RX_STATS_CLEAR_ALL);
4878 * VIOC_RXSTAT_PEER (54) - Control peer RX statistics
4882 * \param[in] ain the flags that control which statistics to use
4883 * \param[out] aout not in use
4885 * \retval EACCES Error if the user doesn't have super-user credentials
4886 * \retval EINVAL Error if the flag input is too long
4889 * either enable peer RPCStatws, disable peer RPCStats,
4890 * or clear the peer RPCStats
4892 DECL_PIOCTL(PRxStatPeer)
4896 if (!afs_osi_suser(*acred))
4899 if (afs_pd_getInt(ain, &flags) != 0)
4902 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK))
4905 if (flags & AFSCALL_RXSTATS_ENABLE) {
4906 rx_enablePeerRPCStats();
4908 if (flags & AFSCALL_RXSTATS_DISABLE) {
4909 rx_disablePeerRPCStats();
4911 if (flags & AFSCALL_RXSTATS_CLEAR) {
4912 rx_clearPeerRPCStats(AFS_RX_STATS_CLEAR_ALL);
4917 DECL_PIOCTL(PPrefetchFromTape)
4921 struct afs_conn *tc;
4922 struct rx_call *tcall;
4923 struct AFSVolSync tsync;
4924 struct AFSFetchStatus OutStatus;
4925 struct AFSCallBack CallBack;
4926 struct VenusFid tfid;
4929 struct rx_connection *rxconn;
4931 AFS_STATCNT(PPrefetchFromTape);
4935 Fid = afs_pd_inline(ain, sizeof(struct AFSFid));
4937 Fid = &avc->f.fid.Fid;
4939 tfid.Cell = avc->f.fid.Cell;
4940 tfid.Fid.Volume = Fid->Volume;
4941 tfid.Fid.Vnode = Fid->Vnode;
4942 tfid.Fid.Unique = Fid->Unique;
4944 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
4946 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
4947 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &avc->f.fid);
4950 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
4951 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &tvc->f.fid);
4954 tc = afs_Conn(&tvc->f.fid, areq, SHARED_LOCK, &rxconn);
4958 tcall = rx_NewCall(rxconn);
4960 StartRXAFS_FetchData(tcall, (struct AFSFid *)&tvc->f.fid.Fid, 0,
4963 rx_Read(tcall, (char *)&outval, sizeof(afs_int32));
4965 EndRXAFS_FetchData(tcall, &OutStatus, &CallBack, &tsync);
4967 code = rx_EndCall(tcall, code);
4971 } while (afs_Analyze
4972 (tc, rxconn, code, &tvc->f.fid, areq, AFS_STATS_FS_RPCIDX_RESIDENCYRPCS,
4973 SHARED_LOCK, NULL));
4974 /* This call is done only to have the callback things handled correctly */
4975 afs_FetchStatus(tvc, &tfid, areq, &OutStatus);
4981 return afs_pd_putInt(aout, outval);
4987 struct afs_conn *tc;
4989 struct FsCmdInputs *Inputs;
4990 struct FsCmdOutputs *Outputs;
4991 struct VenusFid tfid;
4993 struct rx_connection *rxconn;
4998 Inputs = afs_pd_inline(ain, sizeof(*Inputs));
5002 Outputs = afs_pd_inline(aout, sizeof(*Outputs));
5003 if (Outputs == NULL)
5008 Fid = &avc->f.fid.Fid;
5010 tfid.Cell = avc->f.fid.Cell;
5011 tfid.Fid.Volume = Fid->Volume;
5012 tfid.Fid.Vnode = Fid->Vnode;
5013 tfid.Fid.Unique = Fid->Unique;
5015 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
5016 afs_Trace3(afs_iclSetp, CM_TRACE_RESIDCMD, ICL_TYPE_POINTER, tvc,
5017 ICL_TYPE_INT32, Inputs->command, ICL_TYPE_FID, &tfid);
5021 if (Inputs->command) {
5023 tc = afs_Conn(&tvc->f.fid, areq, SHARED_LOCK, &rxconn);
5027 RXAFS_FsCmd(rxconn, Fid, Inputs,
5028 (struct FsCmdOutputs *)aout);
5032 } while (afs_Analyze
5033 (tc, rxconn, code, &tvc->f.fid, areq,
5034 AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK, NULL));
5035 /* This call is done to have the callback things handled correctly */
5036 afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
5037 } else { /* just a status request, return also link data */
5039 Outputs->code = afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
5040 Outputs->chars[0] = 0;
5041 if (vType(tvc) == VLNK) {
5042 ObtainWriteLock(&tvc->lock, 555);
5043 if (afs_HandleLink(tvc, areq) == 0)
5044 strncpy((char *)&Outputs->chars, tvc->linkData, MAXCMDCHARS);
5045 ReleaseWriteLock(&tvc->lock);
5054 DECL_PIOCTL(PNewUuid)
5056 /*AFS_STATCNT(PNewUuid); */
5057 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
5058 return EIO; /* Inappropriate ioctl for device */
5060 if (!afs_osi_suser(*acred))
5063 ObtainWriteLock(&afs_xinterface, 555);
5064 afs_uuid_create(&afs_cb_interface.uuid);
5065 ReleaseWriteLock(&afs_xinterface);
5066 ForceAllNewConnections();
5070 #if defined(AFS_CACHE_BYPASS) && defined(AFS_LINUX24_ENV)
5072 DECL_PIOCTL(PSetCachingThreshold)
5074 afs_int32 getting = 1;
5075 afs_int32 setting = 1;
5076 afs_int32 threshold = AFS_CACHE_BYPASS_DISABLED;
5078 if (afs_pd_getInt(ain, &threshold) != 0)
5084 if (setting == 0 && getting == 0)
5088 * If setting, set first, and return the value now in effect
5091 if (!afs_osi_suser(*acred))
5093 cache_bypass_threshold = threshold;
5094 afs_warn("Cache Bypass Threshold set to: %d\n", threshold);
5095 /* TODO: move to separate pioctl, or enhance pioctl */
5096 if (threshold == AFS_CACHE_BYPASS_DISABLED)
5097 cache_bypass_strategy = NEVER_BYPASS_CACHE;
5098 else if (!threshold)
5099 cache_bypass_strategy = ALWAYS_BYPASS_CACHE;
5101 cache_bypass_strategy = LARGE_FILES_BYPASS_CACHE;
5104 /* Return the current size threshold */
5106 return afs_pd_putInt(aout, cache_bypass_threshold);
5111 #endif /* defined(AFS_CACHE_BYPASS) */
5113 DECL_PIOCTL(PCallBackAddr)
5116 afs_uint32 addr, code;
5120 struct afs_conn *tc;
5122 struct unixuser *tu;
5123 struct srvAddr **addrs;
5124 struct rx_connection *rxconn;
5126 /*AFS_STATCNT(PCallBackAddr); */
5127 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
5128 return EIO; /* Inappropriate ioctl for device */
5130 if (!afs_osi_suser(acred))
5133 if (afs_pd_getInt(ain, &addr) != 0)
5136 ObtainReadLock(&afs_xinterface);
5137 for (i = 0; (unsigned short)i < afs_cb_interface.numberOfInterfaces; i++) {
5138 if (afs_cb_interface.addr_in[i] == addr)
5142 ReleaseWriteLock(&afs_xinterface);
5144 if (afs_cb_interface.addr_in[i] != addr)
5147 ObtainReadLock(&afs_xserver); /* Necessary? */
5148 ObtainReadLock(&afs_xsrvAddr);
5151 for (i = 0; i < NSERVERS; i++) {
5152 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
5157 addrs = afs_osi_Alloc(srvAddrCount * sizeof(*addrs));
5158 osi_Assert(addrs != NULL);
5160 for (i = 0; i < NSERVERS; i++) {
5161 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
5162 if (j >= srvAddrCount)
5168 ReleaseReadLock(&afs_xsrvAddr);
5169 ReleaseReadLock(&afs_xserver);
5171 for (i = 0; i < j; i++) {
5177 /* vlserver has no callback conn */
5178 if (sa->sa_portal == AFS_VLPORT) {
5182 if (!ts->cell) /* not really an active server, anyway, it must */
5183 continue; /* have just been added by setsprefs */
5185 /* get a connection, even if host is down; bumps conn ref count */
5186 tu = afs_GetUser(areq->uid, ts->cell->cellNum, SHARED_LOCK);
5187 tc = afs_ConnBySA(sa, ts->cell->fsport, ts->cell->cellNum, tu,
5188 1 /*force */ , 1 /*create */ , SHARED_LOCK, 0, &rxconn);
5189 afs_PutUser(tu, SHARED_LOCK);
5193 if ((sa->sa_flags & SRVADDR_ISDOWN) || afs_HaveCallBacksFrom(ts)) {
5194 if (sa->sa_flags & SRVADDR_ISDOWN) {
5195 rx_SetConnDeadTime(rxconn, 3);
5197 #ifdef RX_ENABLE_LOCKS
5199 #endif /* RX_ENABLE_LOCKS */
5200 code = RXAFS_CallBackRxConnAddr(rxconn, &addr);
5201 #ifdef RX_ENABLE_LOCKS
5203 #endif /* RX_ENABLE_LOCKS */
5205 afs_PutConn(tc, rxconn, SHARED_LOCK); /* done with it now */
5206 } /* Outer loop over addrs */
5207 #endif /* UKERNEL */
5211 DECL_PIOCTL(PDiscon)
5213 static afs_int32 mode = 1; /* Start up in 'off' */
5214 afs_int32 force = 0;
5217 struct vrequest lreq;
5219 if (afs_pd_getBytes(ain, &flags, 4) == 0) {
5220 if (!afs_osi_suser(*acred))
5224 mode = flags[0] - 1;
5226 afs_ConflictPolicy = flags[1] - 1;
5230 /* Fake InitReq support for UID override */
5231 memset(&lreq, 0, sizeof(lreq));
5232 lreq.uid = flags[3];
5233 areq = &lreq; /* override areq we got */
5237 * All of these numbers are hard coded in fs.c. If they
5238 * change here, they should change there and vice versa
5241 case 0: /* Disconnect ("offline" mode), breaking all callbacks */
5242 if (!AFS_IS_DISCONNECTED) {
5243 ObtainWriteLock(&afs_discon_lock, 999);
5244 afs_DisconGiveUpCallbacks();
5245 afs_RemoveAllConns();
5246 afs_is_disconnected = 1;
5247 afs_is_discon_rw = 1;
5248 ReleaseWriteLock(&afs_discon_lock);
5251 case 1: /* Fully connected, ("online" mode). */
5252 ObtainWriteLock(&afs_discon_lock, 998);
5255 afs_MarkAllServersUp();
5256 code = afs_ResyncDisconFiles(areq, *acred);
5259 if (code && !force) {
5260 afs_warnuser("Files not synchronized properly, still in discon state. \n"
5261 "Please retry or use \"force\".\n");
5265 afs_DisconDiscardAll(*acred);
5267 afs_ClearAllStatdFlag();
5268 afs_is_disconnected = 0;
5269 afs_is_discon_rw = 0;
5270 afs_warnuser("\nSync succeeded. You are back online.\n");
5273 ReleaseWriteLock(&afs_discon_lock);
5285 return afs_pd_putInt(aout, mode);
5288 #define MAX_PIOCTL_TOKENS 10
5290 DECL_PIOCTL(PSetTokens2)
5293 int i, cellNum, primaryFlag;
5295 struct unixuser *tu;
5296 struct vrequest treq;
5297 struct ktc_setTokenData tokenSet;
5298 struct ktc_tokenUnion decodedToken;
5300 memset(&tokenSet, 0, sizeof(tokenSet));
5302 AFS_STATCNT(PSetTokens2);
5303 if (!afs_resourceinit_flag)
5306 afs_pd_xdrStart(ain, &xdrs, XDR_DECODE);
5308 if (!xdr_ktc_setTokenData(&xdrs, &tokenSet)) {
5309 afs_pd_xdrEnd(ain, &xdrs);
5313 afs_pd_xdrEnd(ain, &xdrs);
5315 /* We limit each PAG to 10 tokens to prevent a malicous (or runaway)
5316 * process from using up the whole of the kernel memory by allocating
5319 if (tokenSet.tokens.tokens_len > MAX_PIOCTL_TOKENS) {
5320 xdr_free((xdrproc_t) xdr_ktc_setTokenData, &tokenSet);
5324 code = _settok_tokenCell(tokenSet.cell, &cellNum, &primaryFlag);
5326 xdr_free((xdrproc_t) xdr_ktc_setTokenData, &tokenSet);
5330 if (tokenSet.flags & AFSTOKEN_EX_SETPAG) {
5331 if (_settok_setParentPag(acred) == 0) {
5332 afs_InitReq(&treq, *acred);
5337 tu = afs_GetUser(areq->uid, cellNum, WRITE_LOCK);
5338 /* Free any tokens that we've already got */
5339 afs_FreeTokens(&tu->tokens);
5341 /* Iterate across the set of tokens we've received, and stuff them
5342 * into this user's tokenJar
5344 for (i=0; i < tokenSet.tokens.tokens_len; i++) {
5345 xdrmem_create(&xdrs,
5346 tokenSet.tokens.tokens_val[i].token_opaque_val,
5347 tokenSet.tokens.tokens_val[i].token_opaque_len,
5350 memset(&decodedToken, 0, sizeof(decodedToken));
5351 if (!xdr_ktc_tokenUnion(&xdrs, &decodedToken)) {
5359 afs_AddTokenFromPioctl(&tu->tokens, &decodedToken);
5360 /* This is untidy - the old token interface supported passing
5361 * the primaryFlag as part of the token interface. Current
5362 * OpenAFS userland never sets this, but it's specified as being
5363 * part of the XG interface, so we should probably still support
5364 * it. Rather than add it to our AddToken interface, just handle
5367 if (decodedToken.at_type == AFSTOKEN_UNION_KAD) {
5368 if (decodedToken.ktc_tokenUnion_u.at_kad.rk_primary_flag)
5372 /* XXX - We should think more about destruction here. It's likely that
5373 * there is key material in what we're about to throw away, which
5374 * we really should zero out before giving back to the allocator */
5375 xdr_free((xdrproc_t) xdr_ktc_tokenUnion, &decodedToken);
5378 tu->states |= UHasTokens;
5379 tu->states &= ~UTokensBad;
5380 afs_SetPrimary(tu, primaryFlag);
5381 tu->tokenTime = osi_Time();
5383 xdr_free((xdrproc_t) xdr_ktc_setTokenData, &tokenSet);
5386 afs_ResetUserConns(tu);
5387 afs_PutUser(tu, WRITE_LOCK);
5392 DECL_PIOCTL(PGetTokens2)
5394 struct cell *cell = NULL;
5395 struct unixuser *tu = NULL;
5397 char *cellName = NULL;
5402 struct ktc_setTokenData tokenSet;
5404 AFS_STATCNT(PGetTokens);
5405 if (!afs_resourceinit_flag)
5408 memset(&tokenSet, 0, sizeof(tokenSet));
5410 /* No input data - return tokens for primary cell */
5411 /* 4 octets of data is an iterator count */
5412 /* Otherwise, treat as string & return tokens for that cell name */
5414 if (afs_pd_remaining(ain) == sizeof(afs_int32)) {
5415 /* Integer iterator - return tokens for the n'th cell found for user */
5416 if (afs_pd_getInt(ain, &iterator) != 0)
5418 tu = getNthCell(areq->uid, iterator);
5420 if (afs_pd_remaining(ain) > 0) {
5421 if (afs_pd_getStringPtr(ain, &cellName) != 0)
5426 code = _settok_tokenCell(cellName, &cellNum, NULL);
5429 tu = afs_FindUser(areq->uid, cellNum, READ_LOCK);
5436 if (!(tu->states & UHasTokens)
5437 || !afs_HasValidTokens(tu->tokens, now)) {
5438 tu->states |= (UTokensBad | UNeedsReset);
5439 afs_PutUser(tu, READ_LOCK);
5443 code = afs_ExtractTokensForPioctl(tu->tokens, now, &tokenSet);
5447 cell = afs_GetCell(tu->cell, READ_LOCK);
5448 tokenSet.cell = cell->cellName;
5449 afs_pd_xdrStart(aout, &xdrs, XDR_ENCODE);
5450 if (!xdr_ktc_setTokenData(&xdrs, &tokenSet)) {
5454 afs_pd_xdrEnd(aout, &xdrs);
5457 tokenSet.cell = NULL;
5460 afs_PutUser(tu, READ_LOCK);
5462 afs_PutCell(cell, READ_LOCK);
5463 xdr_free((xdrproc_t)xdr_ktc_setTokenData, &tokenSet);
5468 DECL_PIOCTL(PNFSNukeCreds)
5472 struct unixuser *tu;
5474 AFS_STATCNT(PUnlog);
5475 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
5476 return EIO; /* Inappropriate ioctl for device */
5478 if (afs_pd_getUint(ain, &addr) != 0)
5481 if (afs_cr_gid(*acred) == RMTUSER_REQ_PRIV && !addr) {
5482 tu = afs_GetUser(areq->uid, -1, SHARED_LOCK);
5483 if (!tu->exporter || !(addr = EXP_GETHOST(tu->exporter))) {
5484 afs_PutUser(tu, SHARED_LOCK);
5487 afs_PutUser(tu, SHARED_LOCK);
5488 } else if (!afs_osi_suser(acred)) {
5492 ObtainWriteLock(&afs_xuser, 227);
5493 for (i = 0; i < NUSERS; i++) {
5494 for (tu = afs_users[i]; tu; tu = tu->next) {
5495 if (tu->exporter && EXP_CHECKHOST(tu->exporter, addr)) {
5497 ReleaseWriteLock(&afs_xuser);
5499 afs_LockUser(tu, WRITE_LOCK, 367);
5501 tu->states &= ~UHasTokens;
5502 afs_FreeTokens(&tu->tokens);
5503 afs_ResetUserConns(tu);
5504 afs_PutUser(tu, WRITE_LOCK);
5505 ObtainWriteLock(&afs_xuser, 228);
5507 /* set the expire times to 0, causes
5508 * afs_GCUserData to remove this entry
5511 #endif /* UKERNEL */
5515 ReleaseWriteLock(&afs_xuser);