2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include "afs/param.h"
14 #include "afs/sysincludes.h" /* Standard vendor system headers */
16 #include "h/syscallargs.h"
19 #include "h/sysproto.h"
22 #include <sys/ioctl.h>
23 #include <sys/ioccom.h>
25 #include "afsincludes.h" /* Afs-based standard headers */
26 #include "afs/afs_stats.h" /* afs statistics */
28 #include "afs/afs_bypasscache.h"
29 #include "rx/rx_globals.h"
32 extern int afs_rmtsys_enable;
33 struct VenusFid afs_rootFid;
34 afs_int32 afs_waitForever = 0;
35 short afs_waitForeverCount = 0;
36 afs_int32 afs_showflags = GAGUSER | GAGCONSOLE; /* show all messages */
38 afs_int32 afs_is_disconnected;
39 afs_int32 afs_is_discon_rw;
40 /* On reconnection, turn this knob on until it finishes,
43 afs_int32 afs_in_sync = 0;
51 * A set of handy little functions for encoding and decoding
52 * pioctls without losing your marbles, or memory integrity
56 afs_pd_alloc(struct afs_pdata *apd, size_t size)
59 if (size > AFS_LRALLOCSIZ)
60 apd->ptr = osi_Alloc(size + 1);
62 apd->ptr = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
67 apd->remaining = size;
73 afs_pd_free(struct afs_pdata *apd)
78 if (apd->remaining > AFS_LRALLOCSIZ)
79 osi_Free(apd->ptr, apd->remaining + 1);
81 osi_FreeLargeSpace(apd->ptr);
88 afs_pd_where(struct afs_pdata *apd)
90 return apd ? apd->ptr : NULL;
94 afs_pd_remaining(struct afs_pdata *apd)
96 return apd ? apd->remaining : 0;
100 afs_pd_skip(struct afs_pdata *apd, size_t skip)
102 if (apd == NULL || apd->remaining < skip)
104 apd->remaining -= skip;
111 afs_pd_getBytes(struct afs_pdata *apd, void *dest, size_t bytes)
113 if (apd == NULL || apd->remaining < bytes)
115 apd->remaining -= bytes;
116 memcpy(dest, apd->ptr, bytes);
122 afs_pd_getInt(struct afs_pdata *apd, afs_int32 *val)
124 return afs_pd_getBytes(apd, val, sizeof(*val));
128 afs_pd_getUint(struct afs_pdata *apd, afs_uint32 *val)
130 return afs_pd_getBytes(apd, val, sizeof(*val));
134 afs_pd_inline(struct afs_pdata *apd, size_t bytes)
138 if (apd == NULL || apd->remaining < bytes)
143 apd->remaining -= bytes;
150 afs_pd_xdrStart(struct afs_pdata *apd, XDR *xdrs, enum xdr_op op) {
151 xdrmem_create(xdrs, apd->ptr, apd->remaining, op);
155 afs_pd_xdrEnd(struct afs_pdata *apd, XDR *xdrs) {
158 pos = xdr_getpos(xdrs);
160 apd->remaining -= pos;
167 afs_pd_getString(struct afs_pdata *apd, char *str, size_t maxLen)
171 if (apd == NULL || apd->remaining <= 0)
173 len = strlen(apd->ptr) + 1;
176 memcpy(str, apd->ptr, len);
178 apd->remaining -= len;
183 afs_pd_getStringPtr(struct afs_pdata *apd, char **str)
187 if (apd == NULL || apd->remaining <= 0)
189 len = strlen(apd->ptr) + 1;
192 apd->remaining -= len;
197 afs_pd_putBytes(struct afs_pdata *apd, const void *bytes, size_t len)
199 if (apd == NULL || apd->remaining < len)
201 memcpy(apd->ptr, bytes, len);
203 apd->remaining -= len;
208 afs_pd_putInt(struct afs_pdata *apd, afs_int32 val)
210 return afs_pd_putBytes(apd, &val, sizeof(val));
214 afs_pd_putString(struct afs_pdata *apd, char *str) {
216 /* Add 1 so we copy the NULL too */
217 return afs_pd_putBytes(apd, str, strlen(str) +1);
221 * \defgroup pioctl Path IOCTL functions
223 * DECL_PIOCTL is a macro defined to contain the following parameters for functions:
226 * the AFS vcache structure in use by pioctl
230 * the AFS vrequest structure
232 * an afs_pdata block describing the data received from the caller
234 * an afs_pdata block describing a pre-allocated block for output
236 * UNIX credentials structure underlying the operation
239 #define DECL_PIOCTL(x) \
240 static int x(struct vcache *avc, int afun, struct vrequest *areq, \
241 struct afs_pdata *ain, struct afs_pdata *aout, \
244 /* Prototypes for pioctl routines */
245 DECL_PIOCTL(PGetFID);
246 DECL_PIOCTL(PSetAcl);
247 DECL_PIOCTL(PStoreBehind);
248 DECL_PIOCTL(PGCPAGs);
249 DECL_PIOCTL(PGetAcl);
252 DECL_PIOCTL(PGetFileCell);
253 DECL_PIOCTL(PGetWSCell);
254 DECL_PIOCTL(PGetUserCell);
255 DECL_PIOCTL(PSetTokens);
256 DECL_PIOCTL(PSetTokens2);
257 DECL_PIOCTL(PGetVolumeStatus);
258 DECL_PIOCTL(PSetVolumeStatus);
260 DECL_PIOCTL(PNewStatMount);
261 DECL_PIOCTL(PGetTokens);
262 DECL_PIOCTL(PGetTokens2);
264 DECL_PIOCTL(PMariner);
265 DECL_PIOCTL(PCheckServers);
266 DECL_PIOCTL(PCheckVolNames);
267 DECL_PIOCTL(PCheckAuth);
268 DECL_PIOCTL(PFindVolume);
269 DECL_PIOCTL(PViceAccess);
270 DECL_PIOCTL(PSetCacheSize);
271 DECL_PIOCTL(PGetCacheSize);
272 DECL_PIOCTL(PRemoveCallBack);
273 DECL_PIOCTL(PNewCell);
274 DECL_PIOCTL(PNewAlias);
275 DECL_PIOCTL(PListCells);
276 DECL_PIOCTL(PListAliases);
277 DECL_PIOCTL(PRemoveMount);
278 DECL_PIOCTL(PGetCellStatus);
279 DECL_PIOCTL(PSetCellStatus);
280 DECL_PIOCTL(PFlushVolumeData);
281 DECL_PIOCTL(PFlushAllVolumeData);
282 DECL_PIOCTL(PGetVnodeXStatus);
283 DECL_PIOCTL(PGetVnodeXStatus2);
284 DECL_PIOCTL(PSetSysName);
285 DECL_PIOCTL(PSetSPrefs);
286 DECL_PIOCTL(PSetSPrefs33);
287 DECL_PIOCTL(PGetSPrefs);
288 DECL_PIOCTL(PExportAfs);
290 DECL_PIOCTL(PTwiddleRx);
291 DECL_PIOCTL(PGetInitParams);
292 DECL_PIOCTL(PGetRxkcrypt);
293 DECL_PIOCTL(PSetRxkcrypt);
294 DECL_PIOCTL(PGetCPrefs);
295 DECL_PIOCTL(PSetCPrefs);
296 DECL_PIOCTL(PFlushMount);
297 DECL_PIOCTL(PRxStatProc);
298 DECL_PIOCTL(PRxStatPeer);
299 DECL_PIOCTL(PPrefetchFromTape);
301 DECL_PIOCTL(PCallBackAddr);
302 DECL_PIOCTL(PDiscon);
303 DECL_PIOCTL(PNFSNukeCreds);
304 DECL_PIOCTL(PNewUuid);
305 DECL_PIOCTL(PPrecache);
306 DECL_PIOCTL(PGetPAG);
307 #if defined(AFS_CACHE_BYPASS) && defined(AFS_LINUX24_ENV)
308 DECL_PIOCTL(PSetCachingThreshold);
312 * A macro that says whether we're going to need HandleClientContext().
313 * This is currently used only by the nfs translator.
315 #if !defined(AFS_NONFSTRANS) || defined(AFS_AIX_IAUTH_ENV)
316 #define AFS_NEED_CLIENTCONTEXT
319 /* Prototypes for private routines */
320 #ifdef AFS_NEED_CLIENTCONTEXT
321 static int HandleClientContext(struct afs_ioctl *ablob, int *com,
325 int HandleIoctl(struct vcache *avc, afs_int32 acom,
326 struct afs_ioctl *adata);
327 int afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
328 struct afs_ioctl *ablob, int afollow,
329 afs_ucred_t **acred);
330 static int Prefetch(uparmtype apath, struct afs_ioctl *adata, int afollow,
333 typedef int (*pioctlFunction) (struct vcache *, int, struct vrequest *,
334 struct afs_pdata *, struct afs_pdata *,
337 static pioctlFunction VpioctlSw[] = {
342 PGetVolumeStatus, /* 4 */
343 PSetVolumeStatus, /* 5 */
348 PCheckServers, /* 10 */
349 PCheckVolNames, /* 11 */
351 PBogus, /* 13 -- used to be quick check time */
352 PFindVolume, /* 14 */
353 PBogus, /* 15 -- prefetch is now special-cased; see pioctl code! */
354 PBogus, /* 16 -- used to be testing code */
355 PNoop, /* 17 -- used to be enable group */
356 PNoop, /* 18 -- used to be disable group */
357 PBogus, /* 19 -- used to be list group */
358 PViceAccess, /* 20 */
359 PUnlog, /* 21 -- unlog *is* unpag in this system */
360 PGetFID, /* 22 -- get file ID */
361 PBogus, /* 23 -- used to be waitforever */
362 PSetCacheSize, /* 24 */
363 PRemoveCallBack, /* 25 -- flush only the callback */
366 PRemoveMount, /* 28 -- delete mount point */
367 PNewStatMount, /* 29 -- new style mount point stat */
368 PGetFileCell, /* 30 -- get cell name for input file */
369 PGetWSCell, /* 31 -- get cell name for workstation */
370 PMariner, /* 32 - set/get mariner host */
371 PGetUserCell, /* 33 -- get cell name for user */
372 PBogus, /* 34 -- Enable/Disable logging */
373 PGetCellStatus, /* 35 */
374 PSetCellStatus, /* 36 */
375 PFlushVolumeData, /* 37 -- flush all data from a volume */
376 PSetSysName, /* 38 - Set system name */
377 PExportAfs, /* 39 - Export Afs to remote nfs clients */
378 PGetCacheSize, /* 40 - get cache size and usage */
379 PGetVnodeXStatus, /* 41 - get vcache's special status */
380 PSetSPrefs33, /* 42 - Set CM Server preferences... */
381 PGetSPrefs, /* 43 - Get CM Server preferences... */
382 PGag, /* 44 - turn off/on all CM messages */
383 PTwiddleRx, /* 45 - adjust some RX params */
384 PSetSPrefs, /* 46 - Set CM Server preferences... */
385 PStoreBehind, /* 47 - set degree of store behind to be done */
386 PGCPAGs, /* 48 - disable automatic pag gc-ing */
387 PGetInitParams, /* 49 - get initial cm params */
388 PGetCPrefs, /* 50 - get client interface addresses */
389 PSetCPrefs, /* 51 - set client interface addresses */
390 PFlushMount, /* 52 - flush mount symlink data */
391 PRxStatProc, /* 53 - control process RX statistics */
392 PRxStatPeer, /* 54 - control peer RX statistics */
393 PGetRxkcrypt, /* 55 -- Get rxkad encryption flag */
394 PSetRxkcrypt, /* 56 -- Set rxkad encryption flag */
395 PBogus, /* 57 -- arla: set file prio */
396 PBogus, /* 58 -- arla: fallback getfh */
397 PBogus, /* 59 -- arla: fallback fhopen */
398 PBogus, /* 60 -- arla: controls xfsdebug */
399 PBogus, /* 61 -- arla: controls arla debug */
400 PBogus, /* 62 -- arla: debug interface */
401 PBogus, /* 63 -- arla: print xfs status */
402 PBogus, /* 64 -- arla: force cache check */
403 PBogus, /* 65 -- arla: break callback */
404 PPrefetchFromTape, /* 66 -- MR-AFS: prefetch file from tape */
405 PFsCmd, /* 67 -- RXOSD: generic commnd interface */
406 PBogus, /* 68 -- arla: fetch stats */
407 PGetVnodeXStatus2, /* 69 - get caller access and some vcache status */
410 static pioctlFunction CpioctlSw[] = {
412 PNewAlias, /* 1 -- create new cell alias */
413 PListAliases, /* 2 -- list cell aliases */
414 PCallBackAddr, /* 3 -- request addr for callback rxcon */
416 PDiscon, /* 5 -- get/set discon mode */
425 PFlushAllVolumeData, /* 14 */
428 static pioctlFunction OpioctlSw[] = {
430 PNFSNukeCreds, /* 1 -- nuke all creds for NFS client */
431 #if defined(AFS_CACHE_BYPASS) && defined(AFS_LINUX24_ENV)
432 PSetCachingThreshold /* 2 -- get/set cache-bypass size threshold */
434 PNoop /* 2 -- get/set cache-bypass size threshold */
438 #define PSetClientContext 99 /* Special pioctl to setup caller's creds */
439 int afs_nobody = NFS_NOBODY;
442 HandleIoctl(struct vcache *avc, afs_int32 acom,
443 struct afs_ioctl *adata)
448 AFS_STATCNT(HandleIoctl);
450 switch (acom & 0xff) {
452 avc->f.states |= CSafeStore;
454 /* SXW - Should we force a MetaData flush for this flag setting */
457 /* case 2 used to be abort store, but this is no longer provided,
458 * since it is impossible to implement under normal Unix.
462 /* return the name of the cell this file is open on */
466 tcell = afs_GetCell(avc->f.fid.Cell, READ_LOCK);
468 i = strlen(tcell->cellName) + 1; /* bytes to copy out */
470 if (i > adata->out_size) {
471 /* 0 means we're not interested in the output */
472 if (adata->out_size != 0)
476 AFS_COPYOUT(tcell->cellName, adata->out, i, code);
478 afs_PutCell(tcell, READ_LOCK);
484 case 49: /* VIOC_GETINITPARAMS */
485 if (adata->out_size < sizeof(struct cm_initparams)) {
488 AFS_COPYOUT(&cm_initParams, adata->out,
489 sizeof(struct cm_initparams), code);
501 return code; /* so far, none implemented */
505 /* For aix we don't temporarily bypass ioctl(2) but rather do our
506 * thing directly in the vnode layer call, VNOP_IOCTL; thus afs_ioctl
507 * is now called from afs_gn_ioctl.
510 afs_ioctl(struct vcache *tvc, int cmd, int arg)
512 struct afs_ioctl data;
515 AFS_STATCNT(afs_ioctl);
516 if (((cmd >> 8) & 0xff) == 'V') {
517 /* This is a VICEIOCTL call */
518 AFS_COPYIN(arg, (caddr_t) & data, sizeof(data), error);
521 error = HandleIoctl(tvc, cmd, &data);
524 /* No-op call; just return. */
528 # if defined(AFS_AIX32_ENV)
529 # if defined(AFS_AIX51_ENV)
532 kioctl(int fdes, int com, caddr_t arg, caddr_t ext, caddr_t arg2,
534 # else /* __64BIT__ */
536 kioctl32(int fdes, int com, caddr_t arg, caddr_t ext, caddr_t arg2,
538 # endif /* __64BIT__ */
541 kioctl(int fdes, int com, caddr_t arg, caddr_t ext)
542 # endif /* AFS_AIX51_ENV */
547 # ifdef AFS_AIX51_ENV
550 } u_uap, *uap = &u_uap;
553 int ioctlDone = 0, code = 0;
555 AFS_STATCNT(afs_xioctl);
559 # ifdef AFS_AIX51_ENV
563 if (setuerror(getf(uap->fd, &fd))) {
566 if (fd->f_type == DTYPE_VNODE) {
567 /* good, this is a vnode; next see if it is an AFS vnode */
568 tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */
569 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
570 /* This is an AFS vnode */
571 if (((uap->com >> 8) & 0xff) == 'V') {
572 struct afs_ioctl *datap;
574 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
575 code=copyin_afs_ioctl((char *)uap->arg, datap);
577 osi_FreeSmallSpace(datap);
579 # if defined(AFS_AIX41_ENV)
582 return (setuerror(code), code);
584 code = HandleIoctl(tvc, uap->com, datap);
585 osi_FreeSmallSpace(datap);
588 # if defined(AFS_AIX41_ENV)
595 # if defined(AFS_AIX41_ENV)
597 # if defined(AFS_AIX51_ENV)
599 code = okioctl(fdes, com, arg, ext, arg2, arg3);
600 # else /* __64BIT__ */
601 code = okioctl32(fdes, com, arg, ext, arg2, arg3);
602 # endif /* __64BIT__ */
603 # else /* !AFS_AIX51_ENV */
604 code = okioctl(fdes, com, arg, ext);
605 # endif /* AFS_AIX51_ENV */
607 # elif defined(AFS_AIX32_ENV)
608 okioctl(fdes, com, arg, ext);
611 # if defined(KERNEL_HAVE_UERROR)
614 # if !defined(AFS_AIX41_ENV)
615 return (getuerror()? -1 : u.u_ioctlrv);
617 return getuerror()? -1 : 0;
624 #elif defined(AFS_SGI_ENV)
625 # if defined(AFS_SGI65_ENV)
626 afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
627 rval_t * rvalp, struct vopbd * vbds)
629 afs_ioctl(OSI_VN_DECL(tvc), int cmd, void *arg, int flag, cred_t * cr,
630 rval_t * rvalp, struct vopbd * vbds)
633 struct afs_ioctl data;
639 AFS_STATCNT(afs_ioctl);
640 if (((cmd >> 8) & 0xff) == 'V') {
641 /* This is a VICEIOCTL call */
642 error = copyin_afs_ioctl(arg, &data);
645 locked = ISAFS_GLOCK();
648 error = HandleIoctl(tvc, cmd, &data);
653 /* No-op call; just return. */
657 #elif defined(AFS_SUN5_ENV)
658 struct afs_ioctl_sys {
665 afs_xioctl(struct afs_ioctl_sys *uap, rval_t *rvp)
669 int ioctlDone = 0, code = 0;
671 AFS_STATCNT(afs_xioctl);
675 if (fd->f_vnode->v_type == VREG || fd->f_vnode->v_type == VDIR) {
676 tvc = VTOAFS(fd->f_vnode); /* valid, given a vnode */
677 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
678 /* This is an AFS vnode */
679 if (((uap->com >> 8) & 0xff) == 'V') {
680 struct afs_ioctl *datap;
682 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
683 code=copyin_afs_ioctl((char *)uap->arg, datap);
685 osi_FreeSmallSpace(datap);
690 code = HandleIoctl(tvc, uap->com, datap);
691 osi_FreeSmallSpace(datap);
699 code = ioctl(uap, rvp);
703 #elif defined(AFS_LINUX22_ENV)
704 struct afs_ioctl_sys {
709 afs_xioctl(struct inode *ip, struct file *fp, unsigned int com,
712 struct afs_ioctl_sys ua, *uap = &ua;
716 AFS_STATCNT(afs_xioctl);
721 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
722 /* This is an AFS vnode */
723 if (((uap->com >> 8) & 0xff) == 'V') {
724 struct afs_ioctl *datap;
726 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
727 code = copyin_afs_ioctl((char *)uap->arg, datap);
729 osi_FreeSmallSpace(datap);
733 code = HandleIoctl(tvc, uap->com, datap);
734 osi_FreeSmallSpace(datap);
742 #elif defined(AFS_DARWIN_ENV) && !defined(AFS_DARWIN80_ENV)
750 afs_xioctl(afs_proc_t *p, struct ioctl_args *uap, register_t *retval)
754 int ioctlDone = 0, code = 0;
756 AFS_STATCNT(afs_xioctl);
757 if ((code = fdgetf(p, uap->fd, &fd)))
759 if (fd->f_type == DTYPE_VNODE) {
760 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
761 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
762 /* This is an AFS vnode */
763 if (((uap->com >> 8) & 0xff) == 'V') {
764 struct afs_ioctl *datap;
766 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
767 code = copyin_afs_ioctl((char *)uap->arg, datap);
769 osi_FreeSmallSpace(datap);
773 code = HandleIoctl(tvc, uap->com, datap);
774 osi_FreeSmallSpace(datap);
782 return ioctl(p, uap, retval);
786 #elif defined(AFS_XBSD_ENV)
787 # if defined(AFS_FBSD_ENV)
790 afs_xioctl(struct thread *td, struct ioctl_args *uap,
793 afs_proc_t *p = td->td_proc;
794 # elif defined(AFS_NBSD_ENV)
796 afs_xioctl(afs_proc_t *p, const struct sys_ioctl_args *uap, register_t *retval)
806 afs_xioctl(afs_proc_t *p, const struct ioctl_args *uap, register_t *retval)
809 struct filedesc *fdp;
811 int ioctlDone = 0, code = 0;
814 AFS_STATCNT(afs_xioctl);
815 #if defined(AFS_NBSD40_ENV)
816 fdp = p->l_proc->p_fd;
820 #if defined(AFS_NBSD50_ENV)
821 if ((fd = fd_getfile(SCARG(uap, fd))) == NULL)
823 #elif defined(AFS_FBSD100_ENV)
824 if ((uap->fd >= fdp->fd_nfiles)
825 || ((fd = fdp->fd_ofiles[uap->fd].fde_file) == NULL))
828 if ((uap->fd >= fdp->fd_nfiles)
829 || ((fd = fdp->fd_ofiles[uap->fd]) == NULL))
832 if ((fd->f_flag & (FREAD | FWRITE)) == 0)
834 /* first determine whether this is any sort of vnode */
835 if (fd->f_type == DTYPE_VNODE) {
836 /* good, this is a vnode; next see if it is an AFS vnode */
837 # if defined(AFS_OBSD_ENV)
839 IsAfsVnode((struct vnode *)fd->
840 f_data) ? VTOAFS((struct vnode *)fd->f_data) : NULL;
842 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
844 if (tvc && IsAfsVnode((struct vnode *)fd->f_data)) {
845 /* This is an AFS vnode */
846 #if defined(AFS_NBSD50_ENV)
847 if (((SCARG(uap, com) >> 8) & 0xff) == 'V') {
849 if (((uap->com >> 8) & 0xff) == 'V') {
851 struct afs_ioctl *datap;
853 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
854 #if defined(AFS_NBSD50_ENV)
855 code = copyin_afs_ioctl(SCARG(uap, data), datap);
857 code = copyin_afs_ioctl((char *)uap->arg, datap);
860 osi_FreeSmallSpace(datap);
864 #if defined(AFS_NBSD50_ENV)
865 code = HandleIoctl(tvc, SCARG(uap, com), datap);
867 code = HandleIoctl(tvc, uap->com, datap);
869 osi_FreeSmallSpace(datap);
876 #if defined(AFS_NBSD50_ENV)
877 fd_putfile(SCARG(uap, fd));
881 # if defined(AFS_FBSD_ENV)
882 # if (__FreeBSD_version >= 900044)
883 return sys_ioctl(td, uap);
885 return ioctl(td, uap);
887 # elif defined(AFS_OBSD_ENV)
888 code = sys_ioctl(p, uap, retval);
889 # elif defined(AFS_NBSD_ENV)
890 code = sys_ioctl(p, uap, retval);
896 #elif defined(UKERNEL)
904 } *uap = (struct a *)get_user_struct()->u_ap;
907 int ioctlDone = 0, code = 0;
909 AFS_STATCNT(afs_xioctl);
914 /* first determine whether this is any sort of vnode */
915 if (fd->f_type == DTYPE_VNODE) {
916 /* good, this is a vnode; next see if it is an AFS vnode */
917 tvc = VTOAFS((struct vnode *)fd->f_data); /* valid, given a vnode */
918 if (tvc && IsAfsVnode(AFSTOV(tvc))) {
919 /* This is an AFS vnode */
920 if (((uap->com >> 8) & 0xff) == 'V') {
921 struct afs_ioctl *datap;
923 datap = osi_AllocSmallSpace(AFS_SMALLOCSIZ);
924 code=copyin_afs_ioctl((char *)uap->arg, datap);
926 osi_FreeSmallSpace(datap);
929 return (setuerror(code), code);
931 code = HandleIoctl(tvc, uap->com, datap);
932 osi_FreeSmallSpace(datap);
945 #endif /* AFS_HPUX102_ENV */
947 #if defined(AFS_SGI_ENV)
948 /* "pioctl" system call entry point; just pass argument to the parameterized
957 afs_pioctl(struct pioctlargs *uap, rval_t * rvp)
961 AFS_STATCNT(afs_pioctl);
963 code = afs_syscall_pioctl(uap->path, uap->cmd, uap->cmarg, uap->follow);
965 # ifdef AFS_SGI64_ENV
972 #elif defined(AFS_FBSD_ENV)
974 afs_pioctl(struct thread *td, void *args, int *retval)
981 } *uap = (struct a *)args;
983 AFS_STATCNT(afs_pioctl);
984 return (afs_syscall_pioctl
985 (uap->path, uap->cmd, uap->cmarg, uap->follow, td->td_ucred));
988 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
990 afs_pioctl(afs_proc_t *p, void *args, int *retval)
997 } *uap = (struct a *)args;
999 AFS_STATCNT(afs_pioctl);
1000 # if defined(AFS_DARWIN80_ENV) || defined(AFS_NBSD40_ENV)
1001 return (afs_syscall_pioctl
1002 (uap->path, uap->cmd, uap->cmarg, uap->follow,
1005 return (afs_syscall_pioctl
1006 (uap->path, uap->cmd, uap->cmarg, uap->follow,
1007 # if defined(AFS_FBSD_ENV)
1010 p->p_cred->pc_ucred));
1017 /* macro to avoid adding any more #ifdef's to pioctl code. */
1018 #if defined(AFS_LINUX22_ENV) || defined(AFS_AIX41_ENV)
1019 #define PIOCTL_FREE_CRED() crfree(credp)
1021 #define PIOCTL_FREE_CRED()
1026 afs_syscall_pioctl(char *path, unsigned int com, caddr_t cmarg, int follow,
1027 rval_t *vvp, afs_ucred_t *credp)
1029 #ifdef AFS_DARWIN100_ENV
1030 afs_syscall64_pioctl(user_addr_t path, unsigned int com, user_addr_t cmarg,
1031 int follow, afs_ucred_t *credp)
1032 #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1033 afs_syscall_pioctl(char *path, unsigned int com, caddr_t cmarg, int follow,
1036 afs_syscall_pioctl(char *path, unsigned int com, caddr_t cmarg, int follow)
1040 struct afs_ioctl data;
1041 #ifdef AFS_NEED_CLIENTCONTEXT
1042 afs_ucred_t *tmpcred = NULL;
1044 #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)
1045 afs_ucred_t *foreigncreds = NULL;
1048 struct vnode *vp = NULL;
1049 #ifdef AFS_AIX41_ENV
1050 struct ucred *credp = crref(); /* don't free until done! */
1052 #ifdef AFS_LINUX22_ENV
1053 cred_t *credp = crref(); /* don't free until done! */
1057 AFS_STATCNT(afs_syscall_pioctl);
1059 follow = 1; /* compat. with old venus */
1060 code = copyin_afs_ioctl(cmarg, &data);
1063 #if defined(KERNEL_HAVE_UERROR)
1068 if ((com & 0xff) == PSetClientContext) {
1069 #ifdef AFS_NEED_CLIENTCONTEXT
1070 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV)
1071 code = HandleClientContext(&data, &com, &foreigncreds, credp);
1073 code = HandleClientContext(&data, &com, &foreigncreds, osi_curcred());
1077 crfree(foreigncreds);
1080 #if defined(KERNEL_HAVE_UERROR)
1081 return (setuerror(code), code);
1086 #else /* AFS_NEED_CLIENTCONTEXT */
1088 #endif /* AFS_NEED_CLIENTCONTEXT */
1090 #ifdef AFS_NEED_CLIENTCONTEXT
1093 * We could have done without temporary setting the u.u_cred below
1094 * (foreigncreds could be passed as param the pioctl modules)
1095 * but calls such as afs_osi_suser() doesn't allow that since it
1096 * references u.u_cred directly. We could, of course, do something
1097 * like afs_osi_suser(cred) which, I think, is better since it
1098 * generalizes and supports multi cred environments...
1100 #if defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
1102 credp = foreigncreds;
1103 #elif defined(AFS_AIX41_ENV)
1104 tmpcred = crref(); /* XXX */
1105 crset(foreigncreds);
1106 #elif defined(AFS_HPUX101_ENV)
1107 tmpcred = p_cred(u.u_procp);
1108 set_p_cred(u.u_procp, foreigncreds);
1109 #elif defined(AFS_SGI_ENV)
1110 tmpcred = OSI_GET_CURRENT_CRED();
1111 OSI_SET_CURRENT_CRED(foreigncreds);
1114 u.u_cred = foreigncreds;
1117 #endif /* AFS_NEED_CLIENTCONTEXT */
1118 if ((com & 0xff) == 15) {
1119 /* special case prefetch so entire pathname eval occurs in helper process.
1120 * otherwise, the pioctl call is essentially useless */
1121 #if defined(AFS_SUN5_ENV) || defined(AFS_AIX41_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1123 Prefetch(path, &data, follow,
1124 foreigncreds ? foreigncreds : credp);
1126 code = Prefetch(path, &data, follow, osi_curcred());
1129 #if defined(KERNEL_HAVE_UERROR)
1136 #ifdef AFS_AIX41_ENV
1138 lookupname(path, USR, follow, NULL, &vp,
1139 foreigncreds ? foreigncreds : credp);
1141 #ifdef AFS_LINUX22_ENV
1142 code = gop_lookupname_user(path, AFS_UIOUSER, follow, &dp);
1144 vp = (struct vnode *)dp->d_inode;
1146 code = gop_lookupname_user(path, AFS_UIOUSER, follow, &vp);
1147 #endif /* AFS_LINUX22_ENV */
1148 #endif /* AFS_AIX41_ENV */
1152 #if defined(KERNEL_HAVE_UERROR)
1160 #if defined(AFS_SUN510_ENV)
1161 if (vp && !IsAfsVnode(vp)) {
1162 struct vnode *realvp;
1164 #ifdef AFS_SUN511_ENV
1165 (VOP_REALVP(vp, &realvp, NULL) == 0)
1167 (VOP_REALVP(vp, &realvp) == 0)
1170 struct vnode *oldvp = vp;
1178 /* now make the call if we were passed no file, or were passed an AFS file */
1179 if (!vp || IsAfsVnode(vp)) {
1180 #if defined(AFS_SUN5_ENV)
1181 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1182 #elif defined(AFS_AIX41_ENV)
1184 struct ucred *cred1, *cred2;
1187 cred1 = cred2 = foreigncreds;
1189 cred1 = cred2 = credp;
1191 code = afs_HandlePioctl(vp, com, &data, follow, &cred1);
1192 if (cred1 != cred2) {
1193 /* something changed the creds */
1197 #elif defined(AFS_HPUX101_ENV)
1199 struct ucred *cred = p_cred(u.u_procp);
1200 code = afs_HandlePioctl(vp, com, &data, follow, &cred);
1202 #elif defined(AFS_SGI_ENV)
1205 credp = OSI_GET_CURRENT_CRED();
1206 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1208 #elif defined(AFS_LINUX22_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1209 code = afs_HandlePioctl(vp, com, &data, follow, &credp);
1210 #elif defined(UKERNEL)
1211 code = afs_HandlePioctl(vp, com, &data, follow,
1212 &(get_user_struct()->u_cred));
1214 code = afs_HandlePioctl(vp, com, &data, follow, &u.u_cred);
1217 #if defined(KERNEL_HAVE_UERROR)
1220 code = EINVAL; /* not in /afs */
1225 #if defined(AFS_NEED_CLIENTCONTEXT)
1227 #ifdef AFS_AIX41_ENV
1228 crset(tmpcred); /* restore original credentials */
1230 #if defined(AFS_HPUX101_ENV)
1231 set_p_cred(u.u_procp, tmpcred); /* restore original credentials */
1232 #elif defined(AFS_SGI_ENV)
1233 OSI_SET_CURRENT_CRED(tmpcred); /* restore original credentials */
1234 #elif defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV)
1235 credp = tmpcred; /* restore original credentials */
1237 osi_curcred() = tmpcred; /* restore original credentials */
1238 #endif /* AFS_HPUX101_ENV */
1239 crfree(foreigncreds);
1242 #endif /* AFS_NEED_CLIENTCONTEXT */
1244 #ifdef AFS_LINUX22_ENV
1246 * Holding the global lock when calling dput can cause a deadlock
1247 * when the kernel calls back into afs_dentry_iput
1253 #if defined(AFS_FBSD80_ENV)
1254 if (VOP_ISLOCKED(vp))
1256 #endif /* AFS_FBSD80_ENV */
1257 AFS_RELE(vp); /* put vnode back */
1261 #if defined(KERNEL_HAVE_UERROR)
1264 return (getuerror());
1270 #ifdef AFS_DARWIN100_ENV
1272 afs_syscall_pioctl(char * path, unsigned int com, caddr_t cmarg,
1273 int follow, afs_ucred_t *credp)
1275 return afs_syscall64_pioctl(CAST_USER_ADDR_T(path), com,
1276 CAST_USER_ADDR_T((unsigned int)cmarg), follow,
1281 #define MAXPIOCTLTOKENLEN \
1282 (3*sizeof(afs_int32)+MAXKTCTICKETLEN+sizeof(struct ClearToken)+MAXKTCREALMLEN)
1285 afs_HandlePioctl(struct vnode *avp, afs_int32 acom,
1286 struct afs_ioctl *ablob, int afollow,
1287 afs_ucred_t **acred)
1290 struct vrequest treq;
1292 afs_int32 function, device;
1293 struct afs_pdata input, output;
1294 struct afs_pdata copyInput, copyOutput;
1296 pioctlFunction *pioctlSw;
1298 struct afs_fakestat_state fakestate;
1300 memset(&input, 0, sizeof(input));
1301 memset(&output, 0, sizeof(output));
1303 avc = avp ? VTOAFS(avp) : NULL;
1304 afs_Trace3(afs_iclSetp, CM_TRACE_PIOCTL, ICL_TYPE_INT32, acom & 0xff,
1305 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, afollow);
1306 AFS_STATCNT(HandlePioctl);
1308 code = afs_InitReq(&treq, *acred);
1312 afs_InitFakeStat(&fakestate);
1314 code = afs_EvalFakeStat(&avc, &fakestate, &treq);
1318 device = (acom & 0xff00) >> 8;
1320 case 'V': /* Original pioctls */
1321 pioctlSw = VpioctlSw;
1322 pioctlSwSize = sizeof(VpioctlSw);
1324 case 'C': /* Coordinated/common pioctls */
1325 pioctlSw = CpioctlSw;
1326 pioctlSwSize = sizeof(CpioctlSw);
1328 case 'O': /* Coordinated/common pioctls */
1329 pioctlSw = OpioctlSw;
1330 pioctlSwSize = sizeof(OpioctlSw);
1336 function = acom & 0xff;
1337 if (function >= (pioctlSwSize / sizeof(char *))) {
1342 /* Do all range checking before continuing */
1343 if (ablob->in_size > MAXPIOCTLTOKENLEN ||
1344 ablob->in_size < 0 || ablob->out_size < 0) {
1349 code = afs_pd_alloc(&input, ablob->in_size);
1353 if (ablob->in_size > 0) {
1354 AFS_COPYIN(ablob->in, input.ptr, ablob->in_size, code);
1355 input.ptr[input.remaining] = '\0';
1360 if ((function == 8 && device == 'V') ||
1361 (function == 7 && device == 'C')) { /* PGetTokens */
1362 code = afs_pd_alloc(&output, MAXPIOCTLTOKENLEN);
1364 code = afs_pd_alloc(&output, AFS_LRALLOCSIZ);
1370 copyOutput = output;
1373 (*pioctlSw[function]) (avc, function, &treq, ©Input,
1374 ©Output, acred);
1376 outSize = copyOutput.ptr - output.ptr;
1378 if (code == 0 && ablob->out_size > 0) {
1379 if (outSize > ablob->out_size) {
1380 code = E2BIG; /* data wont fit in user buffer */
1381 } else if (outSize) {
1382 AFS_COPYOUT(output.ptr, ablob->out, outSize, code);
1387 afs_pd_free(&input);
1388 afs_pd_free(&output);
1390 afs_PutFakeStat(&fakestate);
1391 return afs_CheckCode(code, &treq, 41);
1395 * VIOCGETFID (22) - Get file ID quickly
1399 * \param[in] ain not in use
1400 * \param[out] aout fid of requested file
1402 * \retval EINVAL Error if some of the initial arguments aren't set
1404 * \post get the file id of some file
1406 DECL_PIOCTL(PGetFID)
1408 AFS_STATCNT(PGetFID);
1411 if (afs_pd_putBytes(aout, &avc->f.fid, sizeof(struct VenusFid)) != 0)
1417 * VIOCSETAL (1) - Set access control list
1421 * \param[in] ain the ACL being set
1422 * \param[out] aout the ACL being set returned
1424 * \retval EINVAL Error if some of the standard args aren't set
1426 * \post Changed ACL, via direct writing to the wire
1429 dummy_PSetAcl(char *ain, char *aout)
1434 DECL_PIOCTL(PSetAcl)
1437 struct afs_conn *tconn;
1438 struct AFSOpaque acl;
1439 struct AFSVolSync tsync;
1440 struct AFSFetchStatus OutStatus;
1441 struct rx_connection *rxconn;
1444 AFS_STATCNT(PSetAcl);
1448 if (afs_pd_getStringPtr(ain, &acl.AFSOpaque_val) != 0)
1450 acl.AFSOpaque_len = strlen(acl.AFSOpaque_val) + 1;
1451 if (acl.AFSOpaque_len > 1024)
1455 tconn = afs_Conn(&avc->f.fid, areq, SHARED_LOCK, &rxconn);
1457 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREACL);
1460 RXAFS_StoreACL(rxconn, (struct AFSFid *)&avc->f.fid.Fid,
1461 &acl, &OutStatus, &tsync);
1466 } while (afs_Analyze
1467 (tconn, rxconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_STOREACL,
1468 SHARED_LOCK, NULL));
1470 /* now we've forgotten all of the access info */
1471 ObtainWriteLock(&afs_xcbhash, 455);
1473 afs_DequeueCallback(avc);
1474 avc->f.states &= ~(CStatd | CUnique);
1475 ReleaseWriteLock(&afs_xcbhash);
1476 if (avc->f.fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
1477 osi_dnlc_purgedp(avc);
1479 /* SXW - Should we flush metadata here? */
1483 int afs_defaultAsynchrony = 0;
1486 * VIOC_STOREBEHIND (47) Adjust store asynchrony
1490 * \param[in] ain sbstruct (store behind structure) input
1491 * \param[out] aout resulting sbstruct
1494 * Error if the user doesn't have super-user credentials
1496 * Error if there isn't enough access to not check the mode bits
1499 * Changes either the default asynchrony (the amount of data that
1500 * can remain to be written when the cache manager returns control
1501 * to the user), or the asyncrony for the specified file.
1503 DECL_PIOCTL(PStoreBehind)
1505 struct sbstruct sbr;
1507 if (afs_pd_getBytes(ain, &sbr, sizeof(struct sbstruct)) != 0)
1510 if (sbr.sb_default != -1) {
1511 if (afs_osi_suser(*acred))
1512 afs_defaultAsynchrony = sbr.sb_default;
1517 if (avc && (sbr.sb_thisfile != -1)) {
1519 (avc, PRSFS_WRITE | PRSFS_ADMINISTER, areq, DONT_CHECK_MODE_BITS))
1520 avc->asynchrony = sbr.sb_thisfile;
1525 memset(&sbr, 0, sizeof(sbr));
1526 sbr.sb_default = afs_defaultAsynchrony;
1528 sbr.sb_thisfile = avc->asynchrony;
1531 return afs_pd_putBytes(aout, &sbr, sizeof(sbr));
1535 * VIOC_GCPAGS (48) - Disable automatic PAG gc'ing
1539 * \param[in] ain not in use
1540 * \param[out] aout not in use
1542 * \retval EACCES Error if the user doesn't have super-user credentials
1544 * \post set the gcpags to GCPAGS_USERDISABLED
1546 DECL_PIOCTL(PGCPAGs)
1548 if (!afs_osi_suser(*acred)) {
1551 afs_gcpags = AFS_GCPAGS_USERDISABLED;
1556 * VIOCGETAL (2) - Get access control list
1560 * \param[in] ain not in use
1561 * \param[out] aout the ACL
1563 * \retval EINVAL Error if some of the standard args aren't set
1564 * \retval ERANGE Error if the vnode of the file id is too large
1565 * \retval -1 Error if getting the ACL failed
1567 * \post Obtain the ACL, based on file ID
1570 * There is a hack to tell which type of ACL is being returned, checks
1571 * the top 2-bytes of the input size to judge what type of ACL it is,
1572 * only for dfs xlator ACLs
1574 DECL_PIOCTL(PGetAcl)
1576 struct AFSOpaque acl;
1577 struct AFSVolSync tsync;
1578 struct AFSFetchStatus OutStatus;
1580 struct afs_conn *tconn;
1582 struct rx_connection *rxconn;
1585 AFS_STATCNT(PGetAcl);
1588 Fid.Volume = avc->f.fid.Fid.Volume;
1589 Fid.Vnode = avc->f.fid.Fid.Vnode;
1590 Fid.Unique = avc->f.fid.Fid.Unique;
1591 if (avc->f.states & CForeign) {
1593 * For a dfs xlator acl we have a special hack so that the
1594 * xlator will distinguish which type of acl will return. So
1595 * we currently use the top 2-bytes (vals 0-4) to tell which
1596 * type of acl to bring back. Horrible hack but this will
1597 * cause the least number of changes to code size and interfaces.
1599 if (Fid.Vnode & 0xc0000000)
1601 Fid.Vnode |= (ain->remaining << 30);
1603 acl.AFSOpaque_val = aout->ptr;
1605 tconn = afs_Conn(&avc->f.fid, areq, SHARED_LOCK, &rxconn);
1607 acl.AFSOpaque_val[0] = '\0';
1608 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHACL);
1610 code = RXAFS_FetchACL(rxconn, &Fid, &acl, &OutStatus, &tsync);
1615 } while (afs_Analyze
1616 (tconn, rxconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_FETCHACL,
1617 SHARED_LOCK, NULL));
1620 if (acl.AFSOpaque_len == 0)
1621 afs_pd_skip(aout, 1); /* leave the NULL */
1623 afs_pd_skip(aout, acl.AFSOpaque_len); /* Length of the ACL */
1629 * PNoop returns success. Used for functions which are not implemented
1630 * or are no longer in use.
1634 * \retval Always returns success
1637 * Functions involved in this:
1638 * 17 (VIOCENGROUP) -- used to be enable group;
1639 * 18 (VIOCDISGROUP) -- used to be disable group;
1640 * 2 (?) -- get/set cache-bypass size threshold
1649 * PBogus returns fail. Used for functions which are not implemented or
1650 * are no longer in use.
1654 * \retval EINVAL Always returns this value
1657 * Functions involved in this:
1663 * 13 (VIOCGETTIME) -- used to be quick check time;
1664 * 15 (VIOCPREFETCH) -- prefetch is now special-cased; see pioctl code!;
1665 * 16 (VIOCNOP) -- used to be testing code;
1666 * 19 (VIOCLISTGROUPS) -- used to be list group;
1667 * 23 (VIOCWAITFOREVER) -- used to be waitforever;
1668 * 57 (VIOC_FPRIOSTATUS) -- arla: set file prio;
1669 * 58 (VIOC_FHGET) -- arla: fallback getfh;
1670 * 59 (VIOC_FHOPEN) -- arla: fallback fhopen;
1671 * 60 (VIOC_XFSDEBUG) -- arla: controls xfsdebug;
1672 * 61 (VIOC_ARLADEBUG) -- arla: controls arla debug;
1673 * 62 (VIOC_AVIATOR) -- arla: debug interface;
1674 * 63 (VIOC_XFSDEBUG_PRINT) -- arla: print xfs status;
1675 * 64 (VIOC_CALCULATE_CACHE) -- arla: force cache check;
1676 * 65 (VIOC_BREAKCELLBACK) -- arla: break callback;
1677 * 68 (?) -- arla: fetch stats;
1681 AFS_STATCNT(PBogus);
1686 * VIOC_FILE_CELL_NAME (30) - Get cell in which file lives
1690 * \param[in] ain not in use (avc used to pass in file id)
1691 * \param[out] aout cell name
1693 * \retval EINVAL Error if some of the standard args aren't set
1694 * \retval ESRCH Error if the file isn't part of a cell
1696 * \post Get a cell based on a passed in file id
1698 DECL_PIOCTL(PGetFileCell)
1702 AFS_STATCNT(PGetFileCell);
1705 tcell = afs_GetCell(avc->f.fid.Cell, READ_LOCK);
1709 if (afs_pd_putString(aout, tcell->cellName) != 0)
1712 afs_PutCell(tcell, READ_LOCK);
1717 * VIOC_GET_WS_CELL (31) - Get cell in which workstation lives
1721 * \param[in] ain not in use
1722 * \param[out] aout cell name
1725 * Error if the afs daemon hasn't started yet
1727 * Error if the machine isn't part of a cell, for whatever reason
1729 * \post Get the primary cell that the machine is a part of.
1731 DECL_PIOCTL(PGetWSCell)
1733 struct cell *tcell = NULL;
1735 AFS_STATCNT(PGetWSCell);
1736 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1737 return EIO; /* Inappropriate ioctl for device */
1739 tcell = afs_GetPrimaryCell(READ_LOCK);
1740 if (!tcell) /* no primary cell? */
1743 if (afs_pd_putString(aout, tcell->cellName) != 0)
1745 afs_PutCell(tcell, READ_LOCK);
1750 * VIOC_GET_PRIMARY_CELL (33) - Get primary cell for caller
1754 * \param[in] ain not in use (user id found via areq)
1755 * \param[out] aout cell name
1758 * Error if the user id doesn't have a primary cell specified
1760 * \post Get the primary cell for a certain user, based on the user's uid
1762 DECL_PIOCTL(PGetUserCell)
1765 struct unixuser *tu;
1768 AFS_STATCNT(PGetUserCell);
1769 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
1770 return EIO; /* Inappropriate ioctl for device */
1772 /* return the cell name of the primary cell for this user */
1773 i = UHash(areq->uid);
1774 ObtainWriteLock(&afs_xuser, 224);
1775 for (tu = afs_users[i]; tu; tu = tu->next) {
1776 if (tu->uid == areq->uid && (tu->states & UPrimary)) {
1778 ReleaseWriteLock(&afs_xuser);
1779 afs_LockUser(tu, READ_LOCK, 0);
1784 tcell = afs_GetCell(tu->cell, READ_LOCK);
1785 afs_PutUser(tu, READ_LOCK);
1789 if (afs_pd_putString(aout, tcell->cellName) != 0)
1791 afs_PutCell(tcell, READ_LOCK);
1794 ReleaseWriteLock(&afs_xuser);
1799 /* Work out which cell we're changing tokens for */
1801 _settok_tokenCell(char *cellName, int *cellNum, int *primary) {
1809 if (cellName && strlen(cellName) > 0) {
1810 cell = afs_GetCellByName(cellName, READ_LOCK);
1812 cell = afs_GetPrimaryCell(READ_LOCK);
1823 *cellNum = cell->cellNum;
1824 afs_PutCell(cell, READ_LOCK);
1831 _settok_setParentPag(afs_ucred_t **cred) {
1833 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
1835 osi_procname(procname, 256);
1836 afs_warnuser("Process %d (%s) tried to change pags in PSetTokens\n",
1837 MyPidxx2Pid(MyPidxx), procname);
1838 return setpag(osi_curproc(), cred, -1, &pag, 1);
1840 return setpag(cred, -1, &pag, 1);
1845 * VIOCSETTOK (3) - Set authentication tokens
1849 * \param[in] ain the krb tickets from which to set the afs tokens
1850 * \param[out] aout not in use
1853 * Error if the ticket is either too long or too short
1855 * Error if the AFS initState is below 101
1857 * Error if the cell for which the Token is being set can't be found
1860 * Set the Tokens for a specific cell name, unless there is none set,
1861 * then default to primary
1864 DECL_PIOCTL(PSetTokens)
1869 struct unixuser *tu;
1870 struct ClearToken clear;
1874 struct vrequest treq;
1875 afs_int32 flag, set_parent_pag = 0;
1877 AFS_STATCNT(PSetTokens);
1878 if (!afs_resourceinit_flag) {
1882 if (afs_pd_getInt(ain, &stLen) != 0)
1885 stp = afs_pd_where(ain); /* remember where the ticket is */
1886 if (stLen < 0 || stLen > MAXKTCTICKETLEN)
1887 return EINVAL; /* malloc may fail */
1888 if (afs_pd_skip(ain, stLen) != 0)
1891 if (afs_pd_getInt(ain, &size) != 0)
1893 if (size != sizeof(struct ClearToken))
1896 if (afs_pd_getBytes(ain, &clear, sizeof(struct ClearToken)) !=0)
1899 if (clear.AuthHandle == -1)
1900 clear.AuthHandle = 999; /* more rxvab compat stuff */
1902 if (afs_pd_remaining(ain) != 0) {
1903 /* still stuff left? we've got primary flag and cell name.
1906 if (afs_pd_getInt(ain, &flag) != 0)
1909 /* some versions of gcc appear to need != 0 in order to get this
1911 if ((flag & 0x8000) != 0) { /* XXX Use Constant XXX */
1916 if (afs_pd_getStringPtr(ain, &cellName) != 0)
1919 code = _settok_tokenCell(cellName, &cellNum, NULL);
1923 /* default to primary cell, primary id */
1924 code = _settok_tokenCell(NULL, &cellNum, &flag);
1929 if (set_parent_pag) {
1930 if (_settok_setParentPag(acred) == 0) {
1931 afs_InitReq(&treq, *acred);
1936 /* now we just set the tokens */
1937 tu = afs_GetUser(areq->uid, cellNum, WRITE_LOCK);
1938 /* Set tokens destroys any that are already there */
1939 afs_FreeTokens(&tu->tokens);
1940 afs_AddRxkadToken(&tu->tokens, stp, stLen, &clear);
1942 afs_stats_cmfullperf.authent.TicketUpdates++;
1943 afs_ComputePAGStats();
1944 #endif /* AFS_NOSTATS */
1945 tu->states |= UHasTokens;
1946 tu->states &= ~UTokensBad;
1947 afs_SetPrimary(tu, flag);
1948 tu->tokenTime = osi_Time();
1949 afs_ResetUserConns(tu);
1950 afs_NotifyUser(tu, UTokensObtained);
1951 afs_PutUser(tu, WRITE_LOCK);
1957 * VIOCGETVOLSTAT (4) - Get volume status
1961 * \param[in] ain not in use
1962 * \param[out] aout status of the volume
1964 * \retval EINVAL Error if some of the standard args aren't set
1967 * The status of a volume (based on the FID of the volume), or an
1968 * offline message /motd
1970 DECL_PIOCTL(PGetVolumeStatus)
1973 char *offLineMsg = afs_osi_Alloc(256);
1974 char *motd = afs_osi_Alloc(256);
1975 struct afs_conn *tc;
1977 struct AFSFetchVolumeStatus volstat;
1979 struct rx_connection *rxconn;
1982 osi_Assert(offLineMsg != NULL);
1983 osi_Assert(motd != NULL);
1984 AFS_STATCNT(PGetVolumeStatus);
1991 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK, &rxconn);
1993 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS);
1996 RXAFS_GetVolumeStatus(rxconn, avc->f.fid.Fid.Volume, &volstat,
1997 &Name, &offLineMsg, &motd);
2002 } while (afs_Analyze
2003 (tc, rxconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_GETVOLUMESTATUS,
2004 SHARED_LOCK, NULL));
2008 /* Copy all this junk into msg->im_data, keeping track of the lengths. */
2009 if (afs_pd_putBytes(aout, &volstat, sizeof(VolumeStatus)) != 0)
2011 if (afs_pd_putString(aout, volName) != 0)
2013 if (afs_pd_putString(aout, offLineMsg) != 0)
2015 if (afs_pd_putString(aout, motd) != 0)
2018 afs_osi_Free(offLineMsg, 256);
2019 afs_osi_Free(motd, 256);
2024 * VIOCSETVOLSTAT (5) - Set volume status
2029 * values to set the status at, offline message, message of the day,
2030 * volume name, minimum quota, maximum quota
2032 * status of a volume, offlines messages, minimum quota, maximumm quota
2035 * Error if some of the standard args aren't set
2037 * Error if the volume is read only, or a backup volume
2039 * Error if the volume can't be accessed
2041 * Error if the volume name, offline message, and motd are too big
2044 * Set the status of a volume, including any offline messages,
2045 * a minimum quota, and a maximum quota
2047 DECL_PIOCTL(PSetVolumeStatus)
2052 struct afs_conn *tc;
2054 struct AFSFetchVolumeStatus volstat;
2055 struct AFSStoreVolumeStatus storeStat;
2057 struct rx_connection *rxconn;
2060 AFS_STATCNT(PSetVolumeStatus);
2064 tvp = afs_GetVolume(&avc->f.fid, areq, READ_LOCK);
2066 if (tvp->states & (VRO | VBackup)) {
2067 afs_PutVolume(tvp, READ_LOCK);
2070 afs_PutVolume(tvp, READ_LOCK);
2075 if (afs_pd_getBytes(ain, &volstat, sizeof(AFSFetchVolumeStatus)) != 0)
2078 if (afs_pd_getStringPtr(ain, &volName) != 0)
2080 if (strlen(volName) > 32)
2083 if (afs_pd_getStringPtr(ain, &offLineMsg) != 0)
2085 if (strlen(offLineMsg) > 256)
2088 if (afs_pd_getStringPtr(ain, &motd) != 0)
2090 if (strlen(motd) > 256)
2093 /* Done reading ... */
2096 if (volstat.MinQuota != -1) {
2097 storeStat.MinQuota = volstat.MinQuota;
2098 storeStat.Mask |= AFS_SETMINQUOTA;
2100 if (volstat.MaxQuota != -1) {
2101 storeStat.MaxQuota = volstat.MaxQuota;
2102 storeStat.Mask |= AFS_SETMAXQUOTA;
2105 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK, &rxconn);
2107 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS);
2110 RXAFS_SetVolumeStatus(rxconn, avc->f.fid.Fid.Volume, &storeStat,
2111 volName, offLineMsg, motd);
2116 } while (afs_Analyze
2117 (tc, rxconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_SETVOLUMESTATUS,
2118 SHARED_LOCK, NULL));
2122 /* we are sending parms back to make compat. with prev system. should
2123 * change interface later to not ask for current status, just set new
2126 if (afs_pd_putBytes(aout, &volstat, sizeof(VolumeStatus)) != 0)
2128 if (afs_pd_putString(aout, volName) != 0)
2130 if (afs_pd_putString(aout, offLineMsg) != 0)
2132 if (afs_pd_putString(aout, motd) != 0)
2139 * VIOCFLUSH (6) - Invalidate cache entry
2143 * \param[in] ain not in use
2144 * \param[out] aout not in use
2146 * \retval EINVAL Error if some of the standard args aren't set
2148 * \post Flush any information the cache manager has on an entry
2152 AFS_STATCNT(PFlush);
2155 #ifdef AFS_BOZONLOCK_ENV
2156 afs_BozonLock(&avc->pvnLock, avc); /* Since afs_TryToSmush will do a pvn_vptrunc */
2158 ObtainWriteLock(&avc->lock, 225);
2159 afs_ResetVCache(avc, *acred, 0);
2160 ReleaseWriteLock(&avc->lock);
2161 #ifdef AFS_BOZONLOCK_ENV
2162 afs_BozonUnlock(&avc->pvnLock, avc);
2168 * VIOC_AFS_STAT_MT_PT (29) - Stat mount point
2173 * the last component in a path, related to mountpoint that we're
2174 * looking for information about
2176 * volume, cell, link data
2178 * \retval EINVAL Error if some of the standard args aren't set
2179 * \retval ENOTDIR Error if the 'mount point' argument isn't a directory
2180 * \retval EIO Error if the link data can't be accessed
2182 * \post Get the volume, and cell, as well as the link data for a mount point
2184 DECL_PIOCTL(PNewStatMount)
2189 struct VenusFid tfid;
2192 struct sysname_info sysState;
2193 afs_size_t offset, len;
2195 AFS_STATCNT(PNewStatMount);
2199 if (afs_pd_getStringPtr(ain, &name) != 0)
2202 code = afs_VerifyVCache(avc, areq);
2205 if (vType(avc) != VDIR) {
2208 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
2211 Check_AtSys(avc, name, &sysState, areq);
2212 ObtainReadLock(&tdc->lock);
2214 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
2215 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
2216 ReleaseReadLock(&tdc->lock);
2217 afs_PutDCache(tdc); /* we're done with the data */
2218 bufp = sysState.name;
2222 tfid.Cell = avc->f.fid.Cell;
2223 tfid.Fid.Volume = avc->f.fid.Fid.Volume;
2224 if (!tfid.Fid.Unique && (avc->f.states & CForeign)) {
2225 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
2227 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
2233 if (tvc->mvstat != 1) {
2238 ObtainWriteLock(&tvc->lock, 226);
2239 code = afs_HandleLink(tvc, areq);
2241 if (tvc->linkData) {
2242 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
2245 /* we have the data */
2246 if (afs_pd_putString(aout, tvc->linkData) != 0)
2252 ReleaseWriteLock(&tvc->lock);
2255 if (sysState.allocked)
2256 osi_FreeLargeSpace(bufp);
2261 * A helper function to get the n'th cell which a particular user has tokens
2262 * for. This is racy. If new tokens are added whilst we're iterating, then
2263 * we may return some cells twice. If tokens expire mid run, then we'll
2264 * miss some cells from our output. So, could be better, but that would
2265 * require an interface change.
2268 static struct unixuser *
2269 getNthCell(afs_int32 uid, afs_int32 iterator) {
2271 struct unixuser *tu = NULL;
2274 ObtainReadLock(&afs_xuser);
2275 for (tu = afs_users[i]; tu; tu = tu->next) {
2276 if (tu->uid == uid && (tu->states & UHasTokens)) {
2277 if (iterator-- == 0)
2278 break; /* are we done yet? */
2284 ReleaseReadLock(&afs_xuser);
2286 afs_LockUser(tu, READ_LOCK, 0);
2293 * VIOCGETTOK (8) - Get authentication tokens
2297 * \param[in] ain cellid to return tokens for
2298 * \param[out] aout token
2301 * Error if the afs daemon hasn't started yet
2303 * Error if the input parameter is out of the bounds of the available
2306 * Error if there aren't tokens for this cell
2309 * If the input paramater exists, get the token that corresponds to
2310 * the parameter value, if there is no token at this value, get the
2311 * token for the first cell
2313 * \notes "it's a weird interface (from comments in the code)"
2316 DECL_PIOCTL(PGetTokens)
2319 struct unixuser *tu = NULL;
2320 union tokenUnion *token;
2321 afs_int32 iterator = 0;
2326 AFS_STATCNT(PGetTokens);
2327 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2328 return EIO; /* Inappropriate ioctl for device */
2330 /* weird interface. If input parameter is present, it is an integer and
2331 * we're supposed to return the parm'th tokens for this unix uid.
2332 * If not present, we just return tokens for cell 1.
2333 * If counter out of bounds, return EDOM.
2334 * If no tokens for the particular cell, return ENOTCONN.
2335 * Also, if this mysterious parm is present, we return, along with the
2336 * tokens, the primary cell indicator (an afs_int32 0) and the cell name
2337 * at the end, in that order.
2339 newStyle = (afs_pd_remaining(ain) > 0);
2341 if (afs_pd_getInt(ain, &iterator) != 0)
2345 tu = getNthCell(areq->uid, iterator);
2347 cellNum = afs_GetPrimaryCellNum();
2349 tu = afs_FindUser(areq->uid, cellNum, READ_LOCK);
2354 if (!(tu->states & UHasTokens)
2355 || !afs_HasUsableTokens(tu->tokens, osi_Time())) {
2356 tu->states |= (UTokensBad | UNeedsReset);
2357 afs_NotifyUser(tu, UTokensDropped);
2358 afs_PutUser(tu, READ_LOCK);
2361 token = afs_FindToken(tu->tokens, RX_SECIDX_KAD);
2363 /* If they don't have an RXKAD token, but do have other tokens,
2364 * then sadly there's nothing this interface can do to help them. */
2368 /* for compat, we try to return 56 byte tix if they fit */
2369 iterator = token->rxkad.ticketLen;
2371 iterator = 56; /* # of bytes we're returning */
2373 if (afs_pd_putInt(aout, iterator) != 0)
2375 if (afs_pd_putBytes(aout, token->rxkad.ticket, token->rxkad.ticketLen) != 0)
2377 if (token->rxkad.ticketLen < 56) {
2378 /* Tokens are always 56 bytes or larger */
2379 if (afs_pd_skip(aout, iterator - token->rxkad.ticketLen) != 0) {
2384 if (afs_pd_putInt(aout, sizeof(struct ClearToken)) != 0)
2386 if (afs_pd_putBytes(aout, &token->rxkad.clearToken,
2387 sizeof(struct ClearToken)) != 0)
2391 /* put out primary id and cell name, too */
2392 iterator = (tu->states & UPrimary ? 1 : 0);
2393 if (afs_pd_putInt(aout, iterator) != 0)
2395 tcell = afs_GetCell(tu->cell, READ_LOCK);
2397 if (afs_pd_putString(aout, tcell->cellName) != 0)
2399 afs_PutCell(tcell, READ_LOCK);
2401 if (afs_pd_putString(aout, "") != 0)
2404 /* Got here, all is good */
2407 afs_PutUser(tu, READ_LOCK);
2412 * VIOCUNLOG (9) - Invalidate tokens
2416 * \param[in] ain not in use
2417 * \param[out] aout not in use
2419 * \retval EIO Error if the afs daemon hasn't been started yet
2421 * \post remove tokens from a user, specified by the user id
2423 * \notes sets the token's time to 0, which then causes it to be removed
2424 * \notes Unlog is the same as un-pag in OpenAFS
2429 struct unixuser *tu;
2431 AFS_STATCNT(PUnlog);
2432 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2433 return EIO; /* Inappropriate ioctl for device */
2435 i = UHash(areq->uid);
2436 ObtainWriteLock(&afs_xuser, 227);
2437 for (tu = afs_users[i]; tu; tu = tu->next) {
2438 if (tu->uid == areq->uid) {
2440 ReleaseWriteLock(&afs_xuser);
2442 afs_LockUser(tu, WRITE_LOCK, 366);
2444 tu->states &= ~UHasTokens;
2445 afs_FreeTokens(&tu->tokens);
2446 afs_NotifyUser(tu, UTokensDropped);
2447 /* We have to drop the lock over the call to afs_ResetUserConns,
2448 * since it obtains the afs_xvcache lock. We could also keep
2449 * the lock, and modify ResetUserConns to take parm saying we
2450 * obtained the lock already, but that is overkill. By keeping
2451 * the "tu" pointer held over the released lock, we guarantee
2452 * that we won't lose our place, and that we'll pass over
2453 * every user conn that existed when we began this call.
2455 afs_ResetUserConns(tu);
2456 afs_PutUser(tu, WRITE_LOCK);
2457 ObtainWriteLock(&afs_xuser, 228);
2459 /* set the expire times to 0, causes
2460 * afs_GCUserData to remove this entry
2463 #endif /* UKERNEL */
2466 ReleaseWriteLock(&afs_xuser);
2471 * VIOC_AFS_MARINER_HOST (32) - Get/set mariner (cache manager monitor) host
2475 * \param[in] ain host address to be set
2476 * \param[out] aout old host address
2479 * depending on whether or not a variable is set, either get the host
2480 * for the cache manager monitor, or set the old address and give it
2483 * \notes Errors turn off mariner
2485 DECL_PIOCTL(PMariner)
2487 afs_int32 newHostAddr;
2488 afs_int32 oldHostAddr;
2490 AFS_STATCNT(PMariner);
2492 memcpy((char *)&oldHostAddr, (char *)&afs_marinerHost,
2495 oldHostAddr = 0xffffffff; /* disabled */
2497 if (afs_pd_getInt(ain, &newHostAddr) != 0)
2500 if (newHostAddr == 0xffffffff) {
2501 /* disable mariner operations */
2503 } else if (newHostAddr) {
2505 afs_marinerHost = newHostAddr;
2508 if (afs_pd_putInt(aout, oldHostAddr) != 0)
2515 * VIOCCKSERV (10) - Check that servers are up
2519 * \param[in] ain name of the cell
2520 * \param[out] aout current down server list
2522 * \retval EIO Error if the afs daemon hasn't started yet
2523 * \retval EACCES Error if the user doesn't have super-user credentials
2524 * \retval ENOENT Error if we are unable to obtain the cell
2527 * Either a fast check (where it doesn't contact servers) or a
2528 * local check (checks local cell only)
2530 DECL_PIOCTL(PCheckServers)
2535 char *cellName = NULL;
2537 struct chservinfo *pcheck;
2539 AFS_STATCNT(PCheckServers);
2541 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2542 return EIO; /* Inappropriate ioctl for device */
2544 /* This is tricky, because we need to peak at the datastream to see
2545 * what we're getting. For now, let's cheat. */
2547 /* ain contains either an int32 or a string */
2548 if (ain->remaining == 0)
2551 if (*(afs_int32 *)ain->ptr == 0x12345678) { /* For afs3.3 version */
2552 pcheck = afs_pd_inline(ain, sizeof(*pcheck));
2556 if (pcheck->tinterval >= 0) {
2557 if (afs_pd_putInt(aout, afs_probe_interval) != 0)
2559 if (pcheck->tinterval > 0) {
2560 if (!afs_osi_suser(*acred))
2562 afs_probe_interval = pcheck->tinterval;
2566 temp = pcheck->tflags;
2568 cellName = pcheck->tbuffer;
2569 } else { /* For pre afs3.3 versions */
2570 if (afs_pd_getInt(ain, &temp) != 0)
2572 if (afs_pd_remaining(ain) > 0) {
2573 if (afs_pd_getStringPtr(ain, &cellName) != 0)
2579 * 1: fast check, don't contact servers.
2580 * 2: local cell only.
2583 /* have cell name, too */
2584 cellp = afs_GetCellByName(cellName, READ_LOCK);
2589 if (!cellp && (temp & 2)) {
2590 /* use local cell */
2591 cellp = afs_GetPrimaryCell(READ_LOCK);
2593 if (!(temp & 1)) { /* if not fast, call server checker routine */
2594 afs_CheckServers(1, cellp); /* check down servers */
2595 afs_CheckServers(0, cellp); /* check up servers */
2597 /* now return the current down server list */
2598 ObtainReadLock(&afs_xserver);
2599 for (i = 0; i < NSERVERS; i++) {
2600 for (ts = afs_servers[i]; ts; ts = ts->next) {
2601 if (cellp && ts->cell != cellp)
2602 continue; /* cell spec'd and wrong */
2603 if ((ts->flags & SRVR_ISDOWN)
2604 && ts->addr->sa_portal != ts->cell->vlport) {
2605 afs_pd_putInt(aout, ts->addr->sa_ip);
2609 ReleaseReadLock(&afs_xserver);
2611 afs_PutCell(cellp, READ_LOCK);
2616 * VIOCCKBACK (11) - Check backup volume mappings
2620 * \param[in] ain not in use
2621 * \param[out] aout not in use
2623 * \retval EIO Error if the afs daemon hasn't started yet
2626 * Check the root volume, and then check the names if the volume
2627 * check variable is set to force, has expired, is busy, or if
2628 * the mount points variable is set
2630 DECL_PIOCTL(PCheckVolNames)
2632 AFS_STATCNT(PCheckVolNames);
2633 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2634 return EIO; /* Inappropriate ioctl for device */
2636 afs_CheckRootVolume();
2637 afs_CheckVolumeNames(AFS_VOLCHECK_FORCE | AFS_VOLCHECK_EXPIRED |
2638 AFS_VOLCHECK_BUSY | AFS_VOLCHECK_MTPTS);
2643 * VIOCCKCONN (12) - Check connections for a user
2647 * \param[in] ain not in use
2648 * \param[out] aout not in use
2651 * Error if no user is specififed, the user has no tokens set,
2652 * or if the user's tokens are bad
2655 * check to see if a user has the correct authentication.
2656 * If so, allow access.
2658 * \notes Check the connections to all the servers specified
2660 DECL_PIOCTL(PCheckAuth)
2664 struct sa_conn_vector *tcv;
2665 struct unixuser *tu;
2668 AFS_STATCNT(PCheckAuth);
2669 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
2670 return EIO; /* Inappropriate ioctl for device */
2673 tu = afs_GetUser(areq->uid, 1, READ_LOCK); /* check local cell authentication */
2677 /* we have a user */
2678 ObtainReadLock(&afs_xsrvAddr);
2679 ObtainReadLock(&afs_xconn);
2681 /* any tokens set? */
2682 if ((tu->states & UHasTokens) == 0)
2684 /* all connections in cell 1 working? */
2685 for (i = 0; i < NSERVERS; i++) {
2686 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
2687 for (tcv = sa->conns; tcv; tcv = tcv->next) {
2688 if (tcv->user == tu && (tu->states & UTokensBad))
2693 ReleaseReadLock(&afs_xsrvAddr);
2694 ReleaseReadLock(&afs_xconn);
2695 afs_PutUser(tu, READ_LOCK);
2697 if (afs_pd_putInt(aout, retValue) != 0)
2703 Prefetch(uparmtype apath, struct afs_ioctl *adata, int afollow,
2708 #if defined(AFS_SGI61_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
2714 AFS_STATCNT(Prefetch);
2717 tp = osi_AllocLargeSpace(1024);
2718 AFS_COPYINSTR(apath, tp, 1024, &bufferSize, code);
2720 osi_FreeLargeSpace(tp);
2723 if (afs_BBusy()) { /* do this as late as possible */
2724 osi_FreeLargeSpace(tp);
2725 return EWOULDBLOCK; /* pretty close */
2727 afs_BQueue(BOP_PATH, (struct vcache *)0, 0, 0, acred, (afs_size_t) 0,
2728 (afs_size_t) 0, tp, (void *)0, (void *)0);
2733 * VIOCWHEREIS (14) - Find out where a volume is located
2737 * \param[in] ain not in use
2738 * \param[out] aout volume location
2740 * \retval EINVAL Error if some of the default arguments don't exist
2741 * \retval ENODEV Error if there is no such volume
2743 * \post fine a volume, based on a volume file id
2745 * \notes check each of the servers specified
2747 DECL_PIOCTL(PFindVolume)
2754 AFS_STATCNT(PFindVolume);
2757 tvp = afs_GetVolume(&avc->f.fid, areq, READ_LOCK);
2761 for (i = 0; i < AFS_MAXHOSTS; i++) {
2762 ts = tvp->serverHost[i];
2765 if (afs_pd_putInt(aout, ts->addr->sa_ip) != 0) {
2770 if (i < AFS_MAXHOSTS) {
2771 /* still room for terminating NULL, add it on */
2772 if (afs_pd_putInt(aout, 0) != 0) {
2778 afs_PutVolume(tvp, READ_LOCK);
2783 * VIOCACCESS (20) - Access using PRS_FS bits
2787 * \param[in] ain PRS_FS bits
2788 * \param[out] aout not in use
2790 * \retval EINVAL Error if some of the initial arguments aren't set
2791 * \retval EACCES Error if access is denied
2793 * \post check to make sure access is allowed
2795 DECL_PIOCTL(PViceAccess)
2800 AFS_STATCNT(PViceAccess);
2804 code = afs_VerifyVCache(avc, areq);
2808 if (afs_pd_getInt(ain, &temp) != 0)
2811 code = afs_AccessOK(avc, temp, areq, CHECK_MODE_BITS);
2819 * VIOC_GETPAG (13) - Get PAG value
2823 * \param[in] ain not in use
2824 * \param[out] aout PAG value or NOPAG
2826 * \post get PAG value for the caller's cred
2828 DECL_PIOCTL(PGetPAG)
2832 pag = PagInCred(*acred);
2834 return afs_pd_putInt(aout, pag);
2837 DECL_PIOCTL(PPrecache)
2841 /*AFS_STATCNT(PPrecache);*/
2842 if (!afs_osi_suser(*acred))
2845 if (afs_pd_getInt(ain, &newValue) != 0)
2848 afs_preCache = newValue*1024;
2853 * VIOCSETCACHESIZE (24) - Set venus cache size in 1000 units
2857 * \param[in] ain the size the venus cache should be set to
2858 * \param[out] aout not in use
2860 * \retval EACCES Error if the user doesn't have super-user credentials
2861 * \retval EROFS Error if the cache is set to be in memory
2864 * Set the cache size based on user input. If no size is given,
2865 * set it to the default OpenAFS cache size.
2868 * recompute the general cache parameters for every single block allocated
2870 DECL_PIOCTL(PSetCacheSize)
2875 AFS_STATCNT(PSetCacheSize);
2877 if (!afs_osi_suser(*acred))
2879 /* too many things are setup initially in mem cache version */
2880 if (cacheDiskType == AFS_FCACHE_TYPE_MEM)
2882 if (afs_pd_getInt(ain, &newValue) != 0)
2885 afs_cacheBlocks = afs_stats_cmperf.cacheBlocksOrig;
2887 if (newValue < afs_min_cache)
2888 afs_cacheBlocks = afs_min_cache;
2890 afs_cacheBlocks = newValue;
2892 afs_stats_cmperf.cacheBlocksTotal = afs_cacheBlocks;
2893 afs_ComputeCacheParms(); /* recompute basic cache parameters */
2894 afs_MaybeWakeupTruncateDaemon();
2895 while (waitcnt++ < 100 && afs_cacheBlocks < afs_blocksUsed) {
2896 afs_osi_Wait(1000, 0, 0);
2897 afs_MaybeWakeupTruncateDaemon();
2902 #define MAXGCSTATS 16
2904 * VIOCGETCACHEPARMS (40) - Get cache stats
2908 * \param[in] ain afs index flags
2909 * \param[out] aout cache blocks, blocks used, blocks files (in an array)
2911 * \post Get the cache blocks, and how many of the cache blocks there are
2913 DECL_PIOCTL(PGetCacheSize)
2915 afs_int32 results[MAXGCSTATS];
2917 struct dcache * tdc;
2920 AFS_STATCNT(PGetCacheSize);
2922 if (afs_pd_remaining(ain) == sizeof(afs_int32)) {
2923 afs_pd_getInt(ain, &flags); /* can't error, we just checked size */
2924 } else if (afs_pd_remaining(ain) == 0) {
2930 memset(results, 0, sizeof(results));
2931 results[0] = afs_cacheBlocks;
2932 results[1] = afs_blocksUsed;
2933 results[2] = afs_cacheFiles;
2936 for (i = 0; i < afs_cacheFiles; i++) {
2937 if (afs_indexFlags[i] & IFFree) results[3]++;
2939 } else if (2 == flags){
2940 for (i = 0; i < afs_cacheFiles; i++) {
2941 if (afs_indexFlags[i] & IFFree) results[3]++;
2942 if (afs_indexFlags[i] & IFEverUsed) results[4]++;
2943 if (afs_indexFlags[i] & IFDataMod) results[5]++;
2944 if (afs_indexFlags[i] & IFDirtyPages) results[6]++;
2945 if (afs_indexFlags[i] & IFAnyPages) results[7]++;
2946 if (afs_indexFlags[i] & IFDiscarded) results[8]++;
2948 tdc = afs_indexTable[i];
2951 size = tdc->validPos;
2952 if ( 0 < size && size < (1<<12) ) results[10]++;
2953 else if (size < (1<<14) ) results[11]++;
2954 else if (size < (1<<16) ) results[12]++;
2955 else if (size < (1<<18) ) results[13]++;
2956 else if (size < (1<<20) ) results[14]++;
2957 else if (size >= (1<<20) ) results[15]++;
2961 return afs_pd_putBytes(aout, results, sizeof(results));
2965 * VIOCFLUSHCB (25) - Flush callback only
2969 * \param[in] ain not in use
2970 * \param[out] aout not in use
2972 * \retval EINVAL Error if some of the standard args aren't set
2973 * \retval 0 0 returned if the volume is set to read-only
2976 * Flushes callbacks, by setting the length of callbacks to one,
2977 * setting the next callback to be sent to the CB_DROPPED value,
2978 * and then dequeues everything else.
2980 DECL_PIOCTL(PRemoveCallBack)
2982 struct afs_conn *tc;
2984 struct AFSCallBack CallBacks_Array[1];
2985 struct AFSCBFids theFids;
2986 struct AFSCBs theCBs;
2987 struct rx_connection *rxconn;
2990 AFS_STATCNT(PRemoveCallBack);
2993 if (avc->f.states & CRO)
2994 return 0; /* read-only-ness can't change */
2995 ObtainWriteLock(&avc->lock, 229);
2996 theFids.AFSCBFids_len = 1;
2997 theCBs.AFSCBs_len = 1;
2998 theFids.AFSCBFids_val = (struct AFSFid *)&avc->f.fid.Fid;
2999 theCBs.AFSCBs_val = CallBacks_Array;
3000 CallBacks_Array[0].CallBackType = CB_DROPPED;
3001 if (avc->callback) {
3003 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK, &rxconn);
3005 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
3007 code = RXAFS_GiveUpCallBacks(rxconn, &theFids, &theCBs);
3011 /* don't set code on failure since we wouldn't use it */
3012 } while (afs_Analyze
3013 (tc, rxconn, code, &avc->f.fid, areq,
3014 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK, NULL));
3016 ObtainWriteLock(&afs_xcbhash, 457);
3017 afs_DequeueCallback(avc);
3019 avc->f.states &= ~(CStatd | CUnique);
3020 ReleaseWriteLock(&afs_xcbhash);
3021 if (avc->f.fid.Fid.Vnode & 1 || (vType(avc) == VDIR))
3022 osi_dnlc_purgedp(avc);
3024 ReleaseWriteLock(&avc->lock);
3029 * VIOCNEWCELL (26) - Configure new cell
3034 * the name of the cell, the hosts that will be a part of the cell,
3035 * whether or not it's linked with another cell, the other cell it's
3036 * linked with, the file server port, and the volume server port
3040 * \retval EIO Error if the afs daemon hasn't started yet
3041 * \retval EACCES Error if the user doesn't have super-user cedentials
3042 * \retval EINVAL Error if some 'magic' var doesn't have a certain bit set
3044 * \post creates a new cell
3046 DECL_PIOCTL(PNewCell)
3048 afs_int32 cellHosts[AFS_MAXCELLHOSTS], magic = 0;
3049 char *newcell = NULL;
3050 char *linkedcell = NULL;
3052 afs_int32 linkedstate = 0;
3053 afs_int32 fsport = 0, vlport = 0;
3056 AFS_STATCNT(PNewCell);
3057 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3058 return EIO; /* Inappropriate ioctl for device */
3060 if (!afs_osi_suser(*acred))
3063 if (afs_pd_getInt(ain, &magic) != 0)
3065 if (magic != 0x12345678)
3068 /* A 3.4 fs newcell command will pass an array of AFS_MAXCELLHOSTS
3069 * server addresses while the 3.5 fs newcell command passes
3070 * AFS_MAXHOSTS. To figure out which is which, check if the cellname
3073 * This whole logic is bogus, because it relies on the newer command
3074 * sending its 12th address as 0.
3076 if ((afs_pd_remaining(ain) < AFS_MAXCELLHOSTS +3) * sizeof(afs_int32))
3079 newcell = afs_pd_where(ain) + (AFS_MAXCELLHOSTS + 3) * sizeof(afs_int32);
3080 if (newcell[0] != '\0') {
3083 skip = AFS_MAXHOSTS - AFS_MAXCELLHOSTS;
3086 /* AFS_MAXCELLHOSTS (=8) is less than AFS_MAXHOSTS (=13) */
3087 if (afs_pd_getBytes(ain, &cellHosts,
3088 AFS_MAXCELLHOSTS * sizeof(afs_int32)) != 0)
3090 if (afs_pd_skip(ain, skip * sizeof(afs_int32)) !=0)
3093 if (afs_pd_getInt(ain, &fsport) != 0)
3096 fsport = 0; /* Privileged ports not allowed */
3098 if (afs_pd_getInt(ain, &vlport) != 0)
3101 vlport = 0; /* Privileged ports not allowed */
3103 if (afs_pd_getInt(ain, &ls) != 0)
3106 if (afs_pd_getStringPtr(ain, &newcell) != 0)
3110 if (afs_pd_getStringPtr(ain, &linkedcell) != 0)
3112 linkedstate |= CLinkedCell;
3115 linkedstate |= CNoSUID; /* setuid is disabled by default for fs newcell */
3117 afs_NewCell(newcell, cellHosts, linkedstate, linkedcell, fsport,
3122 DECL_PIOCTL(PNewAlias)
3124 /* create a new cell alias */
3125 char *realName, *aliasName;
3127 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3128 return EIO; /* Inappropriate ioctl for device */
3130 if (!afs_osi_suser(*acred))
3133 if (afs_pd_getStringPtr(ain, &aliasName) != 0)
3135 if (afs_pd_getStringPtr(ain, &realName) != 0)
3138 return afs_NewCellAlias(aliasName, realName);
3142 * VIOCGETCELL (27) - Get cell info
3146 * \param[in] ain The cell index of a specific cell
3147 * \param[out] aout list of servers in the cell
3149 * \retval EIO Error if the afs daemon hasn't started yet
3150 * \retval EDOM Error if there is no cell asked about
3152 * \post Lists the cell's server names and and addresses
3154 DECL_PIOCTL(PListCells)
3156 afs_int32 whichCell;
3157 struct cell *tcell = 0;
3161 AFS_STATCNT(PListCells);
3162 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3163 return EIO; /* Inappropriate ioctl for device */
3165 if (afs_pd_getInt(ain, &whichCell) != 0)
3168 tcell = afs_GetCellByIndex(whichCell, READ_LOCK);
3174 for (i = 0; i < AFS_MAXCELLHOSTS; i++) {
3175 if (tcell->cellHosts[i] == 0)
3177 if (afs_pd_putInt(aout, tcell->cellHosts[i]->addr->sa_ip) != 0)
3180 for (;i < AFS_MAXCELLHOSTS; i++) {
3181 if (afs_pd_putInt(aout, 0) != 0)
3184 if (afs_pd_putString(aout, tcell->cellName) != 0)
3189 afs_PutCell(tcell, READ_LOCK);
3193 DECL_PIOCTL(PListAliases)
3195 afs_int32 whichAlias;
3196 struct cell_alias *tcalias = 0;
3199 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3200 return EIO; /* Inappropriate ioctl for device */
3202 if (afs_pd_getInt(ain, &whichAlias) != 0)
3205 tcalias = afs_GetCellAlias(whichAlias);
3206 if (tcalias == NULL)
3210 if (afs_pd_putString(aout, tcalias->alias) != 0)
3212 if (afs_pd_putString(aout, tcalias->cell) != 0)
3217 afs_PutCellAlias(tcalias);
3222 * VIOC_AFS_DELETE_MT_PT (28) - Delete mount point
3226 * \param[in] ain the name of the file in this dir to remove
3227 * \param[out] aout not in use
3230 * Error if some of the standard args aren't set
3232 * Error if the argument to remove is not a directory
3234 * Error if there is no cache to remove the mount point from or
3235 * if a vcache doesn't exist
3238 * Ensure that everything is OK before deleting the mountpoint.
3239 * If not, don't delete. Delete a mount point based on a file id.
3241 DECL_PIOCTL(PRemoveMount)
3246 struct sysname_info sysState;
3247 afs_size_t offset, len;
3248 struct afs_conn *tc;
3251 struct AFSFetchStatus OutDirStatus;
3252 struct VenusFid tfid;
3253 struct AFSVolSync tsync;
3254 struct rx_connection *rxconn;
3257 /* "ain" is the name of the file in this dir to remove */
3259 AFS_STATCNT(PRemoveMount);
3262 if (afs_pd_getStringPtr(ain, &name) != 0)
3265 code = afs_VerifyVCache(avc, areq);
3268 if (vType(avc) != VDIR)
3271 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1); /* test for error below */
3274 Check_AtSys(avc, name, &sysState, areq);
3275 ObtainReadLock(&tdc->lock);
3277 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
3278 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
3279 ReleaseReadLock(&tdc->lock);
3280 bufp = sysState.name;
3285 tfid.Cell = avc->f.fid.Cell;
3286 tfid.Fid.Volume = avc->f.fid.Fid.Volume;
3287 if (!tfid.Fid.Unique && (avc->f.states & CForeign)) {
3288 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
3290 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
3297 if (tvc->mvstat != 1) {
3303 ObtainWriteLock(&tvc->lock, 230);
3304 code = afs_HandleLink(tvc, areq);
3306 if (tvc->linkData) {
3307 if ((tvc->linkData[0] != '#') && (tvc->linkData[0] != '%'))
3312 ReleaseWriteLock(&tvc->lock);
3313 osi_dnlc_purgedp(tvc);
3319 ObtainWriteLock(&avc->lock, 231);
3320 osi_dnlc_remove(avc, bufp, tvc);
3322 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK, &rxconn);
3324 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE);
3327 RXAFS_RemoveFile(rxconn, (struct AFSFid *)&avc->f.fid.Fid, bufp,
3328 &OutDirStatus, &tsync);
3333 } while (afs_Analyze
3334 (tc, rxconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_REMOVEFILE,
3335 SHARED_LOCK, NULL));
3340 ReleaseWriteLock(&avc->lock);
3344 /* we have the thing in the cache */
3345 ObtainWriteLock(&tdc->lock, 661);
3346 if (afs_LocalHero(avc, tdc, &OutDirStatus, 1)) {
3347 /* we can do it locally */
3348 code = afs_dir_Delete(tdc, bufp);
3350 ZapDCE(tdc); /* surprise error -- invalid value */
3354 ReleaseWriteLock(&tdc->lock);
3355 afs_PutDCache(tdc); /* drop ref count */
3357 avc->f.states &= ~CUnique; /* For the dfs xlator */
3358 ReleaseWriteLock(&avc->lock);
3361 if (sysState.allocked)
3362 osi_FreeLargeSpace(bufp);
3367 * VIOC_GETCELLSTATUS (35) - Get cell status info
3371 * \param[in] ain The cell you want status information on
3372 * \param[out] aout cell state (as a struct)
3374 * \retval EIO Error if the afs daemon hasn't started yet
3375 * \retval ENOENT Error if the cell doesn't exist
3377 * \post Returns the state of the cell as defined in a struct cell
3379 DECL_PIOCTL(PGetCellStatus)
3385 AFS_STATCNT(PGetCellStatus);
3386 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3387 return EIO; /* Inappropriate ioctl for device */
3389 if (afs_pd_getStringPtr(ain, &cellName) != 0)
3392 tcell = afs_GetCellByName(cellName, READ_LOCK);
3395 temp = tcell->states;
3396 afs_PutCell(tcell, READ_LOCK);
3398 return afs_pd_putInt(aout, temp);
3402 * VIOC_SETCELLSTATUS (36) - Set corresponding info
3407 * The cell you want to set information about, and the values you
3412 * \retval EIO Error if the afs daemon hasn't started yet
3413 * \retval EACCES Error if the user doesn't have super-user credentials
3416 * Set the state of the cell in a defined struct cell, based on
3417 * whether or not SetUID is allowed
3419 DECL_PIOCTL(PSetCellStatus)
3423 afs_int32 flags0, flags1;
3425 if (!afs_osi_suser(*acred))
3427 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3428 return EIO; /* Inappropriate ioctl for device */
3430 if (afs_pd_getInt(ain, &flags0) != 0)
3432 if (afs_pd_getInt(ain, &flags1) != 0)
3434 if (afs_pd_getStringPtr(ain, &cellName) != 0)
3437 tcell = afs_GetCellByName(cellName, WRITE_LOCK);
3440 if (flags0 & CNoSUID)
3441 tcell->states |= CNoSUID;
3443 tcell->states &= ~CNoSUID;
3444 afs_PutCell(tcell, WRITE_LOCK);
3449 FlushVolumeData(struct VenusFid *afid, afs_ucred_t * acred)
3457 afs_int32 volume = 0;
3458 struct afs_q *tq, *uq;
3459 #ifdef AFS_DARWIN80_ENV
3466 volume = afid->Fid.Volume; /* who to zap */
3471 * Clear stat'd flag from all vnodes from this volume; this will
3472 * invalidate all the vcaches associated with the volume.
3475 ObtainReadLock(&afs_xvcache);
3476 for (i = (afid ? VCHashV(afid) : 0); i < VCSIZE; i = (afid ? VCSIZE : i+1)) {
3477 for (tq = afs_vhashTV[i].prev; tq != &afs_vhashTV[i]; tq = uq) {
3480 if (all || (tvc->f.fid.Fid.Volume == volume && tvc->f.fid.Cell == cell)) {
3481 if (tvc->f.states & CVInit) {
3482 ReleaseReadLock(&afs_xvcache);
3483 afs_osi_Sleep(&tvc->f.states);
3486 #ifdef AFS_DARWIN80_ENV
3487 if (tvc->f.states & CDeadVnode) {
3488 ReleaseReadLock(&afs_xvcache);
3489 afs_osi_Sleep(&tvc->f.states);
3495 if (vnode_ref(vp)) {
3504 ReleaseReadLock(&afs_xvcache);
3505 #ifdef AFS_BOZONLOCK_ENV
3506 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
3508 ObtainWriteLock(&tvc->lock, 232);
3509 afs_ResetVCache(tvc, acred, 1);
3510 ReleaseWriteLock(&tvc->lock);
3511 #ifdef AFS_BOZONLOCK_ENV
3512 afs_BozonUnlock(&tvc->pvnLock, tvc);
3514 #ifdef AFS_DARWIN80_ENV
3515 vnode_put(AFSTOV(tvc));
3517 ObtainReadLock(&afs_xvcache);
3519 /* our tvc ptr is still good until now */
3524 ReleaseReadLock(&afs_xvcache);
3527 ObtainWriteLock(&afs_xdcache, 328); /* needed to flush any stuff */
3528 for (i = 0; i < afs_cacheFiles; i++) {
3529 if (!(afs_indexFlags[i] & IFEverUsed))
3530 continue; /* never had any data */
3531 tdc = afs_GetValidDSlot(i);
3535 if (tdc->refCount <= 1) { /* too high, in use by running sys call */
3536 ReleaseReadLock(&tdc->tlock);
3537 if (all || (tdc->f.fid.Fid.Volume == volume && tdc->f.fid.Cell == cell)) {
3538 if (!(afs_indexFlags[i] & (IFDataMod | IFFree | IFDiscarded))) {
3539 /* if the file is modified, but has a ref cnt of only 1,
3540 * then someone probably has the file open and is writing
3541 * into it. Better to skip flushing such a file, it will be
3542 * brought back immediately on the next write anyway.
3544 * Skip if already freed.
3546 * If we *must* flush, then this code has to be rearranged
3547 * to call afs_storeAllSegments() first */
3548 afs_FlushDCache(tdc);
3552 ReleaseReadLock(&tdc->tlock);
3554 afs_PutDCache(tdc); /* bumped by getdslot */
3556 ReleaseWriteLock(&afs_xdcache);
3558 ObtainReadLock(&afs_xvolume);
3559 for (i = 0; i < NVOLS; i++) {
3560 for (tv = afs_volumes[i]; tv; tv = tv->next) {
3561 if (all || tv->volume == volume) {
3562 afs_ResetVolumeInfo(tv);
3567 ReleaseReadLock(&afs_xvolume);
3569 /* probably, a user is doing this, probably, because things are screwed up.
3570 * maybe it's the dnlc's fault? */
3575 * VIOC_FLUSHVOLUME (37) - Flush whole volume's data
3579 * \param[in] ain not in use (args in avc)
3580 * \param[out] aout not in use
3582 * \retval EINVAL Error if some of the standard args aren't set
3583 * \retval EIO Error if the afs daemon hasn't started yet
3586 * Flush all cached contents of a volume. Exactly what stays and what
3587 * goes depends on the platform.
3590 * Does not flush a file that a user has open and is using, because
3591 * it will be re-created on next write. Also purges the dnlc,
3592 * because things are screwed up.
3594 DECL_PIOCTL(PFlushVolumeData)
3596 AFS_STATCNT(PFlushVolumeData);
3599 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3600 return EIO; /* Inappropriate ioctl for device */
3602 FlushVolumeData(&avc->f.fid, *acred);
3607 * VIOC_FLUSHALL (14) - Flush whole volume's data for all volumes
3611 * \param[in] ain not in use
3612 * \param[out] aout not in use
3614 * \retval EINVAL Error if some of the standard args aren't set
3615 * \retval EIO Error if the afs daemon hasn't started yet
3618 * Flush all cached contents. Exactly what stays and what
3619 * goes depends on the platform.
3622 * Does not flush a file that a user has open and is using, because
3623 * it will be re-created on next write. Also purges the dnlc,
3624 * because things are screwed up.
3626 DECL_PIOCTL(PFlushAllVolumeData)
3628 AFS_STATCNT(PFlushAllVolumeData);
3630 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
3631 return EIO; /* Inappropriate ioctl for device */
3633 FlushVolumeData(NULL, *acred);
3638 * VIOCGETVCXSTATUS (41) - gets vnode x status
3643 * not in use (avc used)
3645 * vcxstat: the file id, the data version, any lock, the parent vnode,
3646 * the parent unique id, the trunc position, the callback, cbExpires,
3647 * what access is being made, what files are open,
3648 * any users executing/writing, the flock count, the states,
3652 * Error if some of the initial default arguments aren't set
3654 * Error if access to check the mode bits is denied
3657 * gets stats for the vnode, a struct listed in vcxstat
3659 DECL_PIOCTL(PGetVnodeXStatus)
3662 struct vcxstat stat;
3665 /* AFS_STATCNT(PGetVnodeXStatus); */
3668 code = afs_VerifyVCache(avc, areq);
3671 if (vType(avc) == VDIR)
3672 mode = PRSFS_LOOKUP;
3675 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
3678 memset(&stat, 0, sizeof(struct vcxstat));
3679 stat.fid = avc->f.fid;
3680 hset32(stat.DataVersion, hgetlo(avc->f.m.DataVersion));
3681 stat.lock = avc->lock;
3682 stat.parentVnode = avc->f.parent.vnode;
3683 stat.parentUnique = avc->f.parent.unique;
3684 hset(stat.flushDV, avc->flushDV);
3685 hset(stat.mapDV, avc->mapDV);
3686 stat.truncPos = avc->f.truncPos;
3687 { /* just grab the first two - won't break anything... */
3688 struct axscache *ac;
3690 for (i = 0, ac = avc->Access; ac && i < CPSIZE; i++, ac = ac->next) {
3691 stat.randomUid[i] = ac->uid;
3692 stat.randomAccess[i] = ac->axess;
3695 stat.callback = afs_data_pointer_to_int32(avc->callback);
3696 stat.cbExpires = avc->cbExpires;
3697 stat.anyAccess = avc->f.anyAccess;
3698 stat.opens = avc->opens;
3699 stat.execsOrWriters = avc->execsOrWriters;
3700 stat.flockCount = avc->flockCount;
3701 stat.mvstat = avc->mvstat;
3702 stat.states = avc->f.states;
3703 return afs_pd_putBytes(aout, &stat, sizeof(struct vcxstat));
3707 DECL_PIOCTL(PGetVnodeXStatus2)
3710 struct vcxstat2 stat;
3715 code = afs_VerifyVCache(avc, areq);
3718 if (vType(avc) == VDIR)
3719 mode = PRSFS_LOOKUP;
3722 if (!afs_AccessOK(avc, mode, areq, CHECK_MODE_BITS))
3725 memset(&stat, 0, sizeof(struct vcxstat2));
3727 stat.cbExpires = avc->cbExpires;
3728 stat.anyAccess = avc->f.anyAccess;
3729 stat.mvstat = avc->mvstat;
3730 stat.callerAccess = afs_GetAccessBits(avc, ~0, areq);
3732 return afs_pd_putBytes(aout, &stat, sizeof(struct vcxstat2));
3737 * VIOC_AFS_SYSNAME (38) - Change @sys value
3741 * \param[in] ain new value for @sys
3742 * \param[out] aout count, entry, list (debug values?)
3745 * Error if afsd isn't running, the new sysname is too large,
3746 * the new sysname causes issues (starts with a . or ..),
3747 * there is no PAG set in the credentials, or the user of a PAG
3750 * Error if the user doesn't have super-user credentials
3753 * Set the value of @sys if these things work: if the input isn't
3754 * too long or if input doesn't start with . or ..
3757 * We require root for local sysname changes, but not for remote
3758 * (since we don't really believe remote uids anyway)
3759 * outname[] shouldn't really be needed- this is left as an
3760 * exercise for the reader.
3762 DECL_PIOCTL(PSetSysName)
3764 char *inname = NULL;
3765 char outname[MAXSYSNAME];
3766 afs_int32 setsysname;
3768 struct afs_exporter *exporter;
3769 struct unixuser *au;
3770 afs_int32 pag, error;
3771 int t, count, num = 0, allpags = 0;
3773 struct afs_pdata validate;
3775 AFS_STATCNT(PSetSysName);
3776 if (!afs_globalVFS) {
3777 /* Afsd is NOT running; disable it */
3778 #if defined(KERNEL_HAVE_UERROR)
3779 return (setuerror(EINVAL), EINVAL);
3784 if (afs_pd_getInt(ain, &setsysname) != 0)
3786 if (setsysname & 0x8000) {
3788 setsysname &= ~0x8000;
3793 if (setsysname < 0 || setsysname > MAXNUMSYSNAMES)
3796 for (count = 0; count < setsysname; count++) {
3797 if (afs_pd_getStringPtr(&validate, &inname) != 0)
3800 if (t >= MAXSYSNAME || t <= 0)
3802 /* check for names that can shoot us in the foot */
3803 if (inname[0] == '.' && (inname[1] == 0
3804 || (inname[1] == '.' && inname[2] == 0)))
3807 /* args ok, so go back to the beginning of that section */
3809 if (afs_pd_getStringPtr(ain, &inname) != 0)
3813 if (afs_rmtsys_enable && (afs_cr_gid(*acred) == RMTUSER_REQ ||
3814 afs_cr_gid(*acred) == RMTUSER_REQ_PRIV)) { /* Handles all exporters */
3815 if (allpags && afs_cr_gid(*acred) != RMTUSER_REQ_PRIV) {
3818 pag = PagInCred(*acred);
3820 return EINVAL; /* Better than panicing */
3822 if (!(au = afs_FindUser(pag, -1, READ_LOCK))) {
3823 return EINVAL; /* Better than panicing */
3825 if (!(exporter = au->exporter)) {
3826 afs_PutUser(au, READ_LOCK);
3827 return EINVAL; /* Better than panicing */
3829 error = EXP_SYSNAME(exporter, inname, &sysnamelist,
3832 if (error == ENODEV)
3833 foundname = 0; /* sysname not set yet! */
3835 afs_PutUser(au, READ_LOCK);
3840 strcpy(outname, sysnamelist[0]);
3842 afs_PutUser(au, READ_LOCK);
3846 /* Not xlating, so local case */
3848 osi_Panic("PSetSysName: !afs_sysname\n");
3849 if (!setsysname) { /* user just wants the info */
3850 strcpy(outname, afs_sysname);
3851 foundname = afs_sysnamecount;
3852 sysnamelist = afs_sysnamelist;
3853 } else { /* Local guy; only root can change sysname */
3854 if (!afs_osi_suser(*acred))
3857 /* allpags makes no sense for local use */
3861 /* clear @sys entries from the dnlc, once afs_lookup can
3862 * do lookups of @sys entries and thinks it can trust them */
3863 /* privs ok, store the entry, ... */
3865 if (strlen(inname) >= MAXSYSNAME-1)
3867 strcpy(afs_sysname, inname);
3869 if (setsysname > 1) { /* ... or list */
3870 for (count = 1; count < setsysname; ++count) {
3871 if (!afs_sysnamelist[count])
3873 ("PSetSysName: no afs_sysnamelist entry to write\n");
3874 if (afs_pd_getString(ain, afs_sysnamelist[count],
3879 afs_sysnamecount = setsysname;
3884 if (afs_pd_putInt(aout, foundname) != 0)
3887 if (afs_pd_putString(aout, outname) != 0)
3889 for (count = 1; count < foundname; ++count) { /* ... or list. */
3890 if (!sysnamelist[count])
3892 ("PSetSysName: no afs_sysnamelist entry to read\n");
3893 t = strlen(sysnamelist[count]);
3894 if (t >= MAXSYSNAME)
3895 osi_Panic("PSetSysName: sysname entry garbled\n");
3896 if (afs_pd_putString(aout, sysnamelist[count]) != 0)
3904 /* sequential search through the list of touched cells is not a good
3905 * long-term solution here. For small n, though, it should be just
3906 * fine. Should consider special-casing the local cell for large n.
3907 * Likewise for PSetSPrefs.
3909 * s - number of ids in array l[] -- NOT index of last id
3910 * l - array of cell ids which have volumes that need to be sorted
3911 * vlonly - sort vl servers or file servers?
3914 ReSortCells_cb(struct cell *cell, void *arg)
3916 afs_int32 *p = (afs_int32 *) arg;
3917 afs_int32 *l = p + 1;
3920 for (i = 0; i < s; i++) {
3921 if (l[i] == cell->cellNum) {
3922 ObtainWriteLock(&cell->lock, 690);
3923 afs_SortServers(cell->cellHosts, AFS_MAXCELLHOSTS);
3924 ReleaseWriteLock(&cell->lock);
3932 ReSortCells(int s, afs_int32 * l, int vlonly)
3940 p = afs_osi_Alloc(sizeof(afs_int32) * (s + 1));
3941 osi_Assert(p != NULL);
3943 memcpy(p + 1, l, s * sizeof(afs_int32));
3944 afs_TraverseCells(&ReSortCells_cb, p);
3945 afs_osi_Free(p, sizeof(afs_int32) * (s + 1));
3949 ObtainReadLock(&afs_xvolume);
3950 for (i = 0; i < NVOLS; i++) {
3951 for (j = afs_volumes[i]; j; j = j->next) {
3952 for (k = 0; k < s; k++)
3953 if (j->cell == l[k]) {
3954 ObtainWriteLock(&j->lock, 233);
3955 afs_SortServers(j->serverHost, AFS_MAXHOSTS);
3956 ReleaseWriteLock(&j->lock);
3961 ReleaseReadLock(&afs_xvolume);
3965 static int debugsetsp = 0;
3967 afs_setsprefs(struct spref *sp, unsigned int num, unsigned int vlonly)
3970 int i, j, k, matches, touchedSize;
3971 struct server *srvr = NULL;
3972 afs_int32 touched[34];
3976 for (k = 0; k < num; sp++, k++) {
3978 afs_warn("sp host=%x, rank=%d\n", sp->host.s_addr, sp->rank);
3981 ObtainReadLock(&afs_xserver);
3983 i = SHash(sp->host.s_addr);
3984 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
3985 if (sa->sa_ip == sp->host.s_addr) {
3987 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
3988 || (sa->sa_portal == AFS_FSPORT);
3989 if ((!vlonly && isfs) || (vlonly && !isfs)) {
3996 if (sa && matches) { /* found one! */
3998 afs_warn("sa ip=%x, ip_rank=%d\n", sa->sa_ip, sa->sa_iprank);
4000 sa->sa_iprank = sp->rank + afs_randomMod15();
4001 afs_SortOneServer(sa->server);
4004 /* if we don't know yet what cell it's in, this is moot */
4005 for (j = touchedSize - 1;
4006 j >= 0 && touched[j] != srvr->cell->cellNum; j--)
4007 /* is it in our list of touched cells ? */ ;
4008 if (j < 0) { /* no, it's not */
4009 touched[touchedSize++] = srvr->cell->cellNum;
4010 if (touchedSize >= 32) { /* watch for ovrflow */
4011 ReleaseReadLock(&afs_xserver);
4012 ReSortCells(touchedSize, touched, vlonly);
4014 ObtainReadLock(&afs_xserver);
4020 ReleaseReadLock(&afs_xserver);
4021 /* if we didn't find one, start to create one. */
4022 /* Note that it doesn't have a cell yet... */
4024 afs_uint32 temp = sp->host.s_addr;
4026 afs_GetServer(&temp, 1, 0, (vlonly ? AFS_VLPORT : AFS_FSPORT),
4027 WRITE_LOCK, (afsUUID *) 0, 0, NULL);
4028 srvr->addr->sa_iprank = sp->rank + afs_randomMod15();
4029 afs_PutServer(srvr, WRITE_LOCK);
4031 } /* for all cited preferences */
4033 ReSortCells(touchedSize, touched, vlonly);
4038 * VIOC_SETPREFS (46) - Set server ranks
4040 * \param[in] ain the sprefs value you want the sprefs to be set to
4041 * \param[out] aout not in use
4044 * Error if the afs daemon hasn't started yet
4046 * Error if the user doesn't have super-user credentials
4048 * Error if the struct setsprefs is too large or if it multiplied
4049 * by the number of servers is too large
4051 * \post set the sprefs using the afs_setsprefs() function
4053 DECL_PIOCTL(PSetSPrefs)
4055 struct setspref *ssp;
4059 AFS_STATCNT(PSetSPrefs);
4061 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4062 return EIO; /* Inappropriate ioctl for device */
4064 if (!afs_osi_suser(*acred))
4067 /* The I/O handling here is ghastly, as it relies on overrunning the ends
4068 * of arrays. But, i'm not quite brave enough to change it yet. */
4070 ainSize = ain->remaining;
4072 if (ainSize < sizeof(struct setspref))
4075 ssp = (struct setspref *)ainPtr;
4076 if (ainSize < (sizeof(struct setspref)
4077 + sizeof(struct spref) * (ssp->num_servers-1)))
4080 afs_setsprefs(&(ssp->servers[0]), ssp->num_servers,
4081 (ssp->flags & DBservers));
4086 * VIOC_SETPREFS33 (42) - Set server ranks (deprecated)
4088 * \param[in] ain the server preferences to be set
4089 * \param[out] aout not in use
4091 * \retval EIO Error if the afs daemon hasn't started yet
4092 * \retval EACCES Error if the user doesn't have super-user credentials
4094 * \post set the server preferences, calling a function
4096 * \notes this may only be performed by the local root user.
4098 DECL_PIOCTL(PSetSPrefs33)
4100 AFS_STATCNT(PSetSPrefs);
4101 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4102 return EIO; /* Inappropriate ioctl for device */
4105 if (!afs_osi_suser(*acred))
4108 afs_setsprefs((struct spref *)afs_pd_where(ain),
4109 afs_pd_remaining(ain) / sizeof(struct spref),
4115 * VIOC_GETSPREFS (43) - Get server ranks
4119 * \param[in] ain the server preferences to get
4120 * \param[out] aout the server preferences information
4122 * \retval EIO Error if the afs daemon hasn't started yet
4123 * \retval ENOENT Error if the sprefrequest is too large
4125 * \post Get the sprefs
4128 * in the hash table of server structs, all servers with the same
4129 * IP address; will be on the same overflow chain; This could be
4130 * sped slightly in some circumstances by having it cache the
4131 * immediately previous slot in the hash table and some
4132 * supporting information; Only reports file servers now.
4134 DECL_PIOCTL(PGetSPrefs)
4136 struct sprefrequest spin; /* input */
4137 struct sprefinfo *spout; /* output */
4138 struct spref *srvout; /* one output component */
4139 int i, j; /* counters for hash table traversal */
4140 struct server *srvr; /* one of CM's server structs */
4142 int vlonly; /* just return vlservers ? */
4145 AFS_STATCNT(PGetSPrefs);
4146 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4147 return EIO; /* Inappropriate ioctl for device */
4149 /* Work out from the size whether we've got a new, or old, style pioctl */
4150 if (afs_pd_remaining(ain) < sizeof(struct sprefrequest)) {
4151 if (afs_pd_getBytes(ain, &spin, sizeof(struct sprefrequest_33)) != 0)
4156 if (afs_pd_getBytes(ain, &spin, sizeof(struct sprefrequest)) != 0)
4158 vlonly = (spin.flags & DBservers);
4161 /* This code relies on overflowing arrays. It's ghastly, but I'm not
4162 * quite brave enough to tackle it yet ...
4165 /* struct sprefinfo includes 1 server struct... that size gets added
4166 * in during the loop that follows.
4168 spout = afs_pd_inline(aout,
4169 sizeof(struct sprefinfo) - sizeof(struct spref));
4170 spout->next_offset = spin.offset;
4171 spout->num_servers = 0;
4172 srvout = spout->servers;
4174 ObtainReadLock(&afs_xserver);
4175 for (i = 0, j = 0; j < NSERVERS; j++) { /* sift through hash table */
4176 for (sa = afs_srvAddrs[j]; sa; sa = sa->next_bkt, i++) {
4177 if (spin.offset > (unsigned short)i) {
4178 continue; /* catch up to where we left off */
4180 spout->next_offset++;
4183 isfs = (srvr->cell && (sa->sa_portal == srvr->cell->fsport))
4184 || (sa->sa_portal == AFS_FSPORT);
4186 if ((vlonly && isfs) || (!vlonly && !isfs)) {
4187 /* only report ranks for vl servers */
4191 /* Check we've actually got the space we're about to use */
4192 if (afs_pd_inline(aout, sizeof(struct spref)) == NULL) {
4193 ReleaseReadLock(&afs_xserver); /* no more room! */
4197 srvout->host.s_addr = sa->sa_ip;
4198 srvout->rank = sa->sa_iprank;
4199 spout->num_servers++;
4203 ReleaseReadLock(&afs_xserver);
4205 spout->next_offset = 0; /* start over from the beginning next time */
4210 /* Enable/Disable the specified exporter. Must be root to disable an exporter */
4211 int afs_NFSRootOnly = 1;
4213 * VIOC_EXPORTAFS (39) - Export afs to nfs clients
4218 * an integer containing the desired exportee flags
4220 * an integer containing the current exporter flags
4222 * \retval ENODEV Error if the exporter doesn't exist
4223 * \retval EACCES Error if the user doesn't have super-user credentials
4226 * Changes the state of various values to reflect the change
4227 * of the export values between nfs and afs.
4229 * \notes Legacy code obtained from IBM.
4231 DECL_PIOCTL(PExportAfs)
4233 afs_int32 export, newint = 0;
4234 afs_int32 type, changestate, handleValue, convmode, pwsync, smounts;
4235 afs_int32 rempags = 0, pagcb = 0;
4236 struct afs_exporter *exporter;
4238 AFS_STATCNT(PExportAfs);
4239 if (afs_pd_getInt(ain, &handleValue) != 0)
4241 type = handleValue >> 24;
4246 exporter = exporter_find(type);
4248 export = handleValue & 3;
4249 changestate = handleValue & 0xfff;
4250 smounts = (handleValue >> 2) & 3;
4251 pwsync = (handleValue >> 4) & 3;
4252 convmode = (handleValue >> 6) & 3;
4253 rempags = (handleValue >> 8) & 3;
4254 pagcb = (handleValue >> 10) & 3;
4256 changestate = (handleValue >> 16) & 0x1;
4257 convmode = (handleValue >> 16) & 0x2;
4258 pwsync = (handleValue >> 16) & 0x4;
4259 smounts = (handleValue >> 16) & 0x8;
4260 export = handleValue & 0xff;
4263 /* Failed finding desired exporter; */
4267 handleValue = exporter->exp_states;
4268 if (afs_pd_putInt(aout, handleValue) != 0)
4271 if (!afs_osi_suser(*acred))
4272 return EACCES; /* Only superuser can do this */
4276 exporter->exp_states |= EXP_EXPORTED;
4278 exporter->exp_states &= ~EXP_EXPORTED;
4282 exporter->exp_states |= EXP_UNIXMODE;
4284 exporter->exp_states &= ~EXP_UNIXMODE;
4288 exporter->exp_states |= EXP_PWSYNC;
4290 exporter->exp_states &= ~EXP_PWSYNC;
4294 afs_NFSRootOnly = 0;
4295 exporter->exp_states |= EXP_SUBMOUNTS;
4297 afs_NFSRootOnly = 1;
4298 exporter->exp_states &= ~EXP_SUBMOUNTS;
4303 exporter->exp_states |= EXP_CLIPAGS;
4305 exporter->exp_states &= ~EXP_CLIPAGS;
4309 exporter->exp_states |= EXP_CALLBACK;
4311 exporter->exp_states &= ~EXP_CALLBACK;
4313 handleValue = exporter->exp_states;
4314 if (afs_pd_putInt(aout, handleValue) != 0)
4318 exporter->exp_states |= EXP_EXPORTED;
4320 exporter->exp_states &= ~EXP_EXPORTED;
4322 exporter->exp_states |= EXP_UNIXMODE;
4324 exporter->exp_states &= ~EXP_UNIXMODE;
4326 exporter->exp_states |= EXP_PWSYNC;
4328 exporter->exp_states &= ~EXP_PWSYNC;
4330 afs_NFSRootOnly = 0;
4331 exporter->exp_states |= EXP_SUBMOUNTS;
4333 afs_NFSRootOnly = 1;
4334 exporter->exp_states &= ~EXP_SUBMOUNTS;
4343 * VIOC_GAG (44) - Silence Cache Manager
4347 * \param[in] ain the flags to either gag or de-gag the cache manager
4348 * \param[out] aout not in use
4350 * \retval EACCES Error if the user doesn't have super-user credentials
4352 * \post set the gag flags, then show these flags
4356 struct gaginfo *gagflags;
4358 if (!afs_osi_suser(*acred))
4361 gagflags = afs_pd_inline(ain, sizeof(*gagflags));
4362 if (gagflags == NULL)
4364 afs_showflags = gagflags->showflags;
4370 * VIOC_TWIDDLE (45) - Adjust RX knobs
4374 * \param[in] ain the previous settings of the 'knobs'
4375 * \param[out] aout not in use
4377 * \retval EACCES Error if the user doesn't have super-user credentials
4379 * \post build out the struct rxp, from a struct rx
4381 DECL_PIOCTL(PTwiddleRx)
4383 struct rxparams *rxp;
4385 if (!afs_osi_suser(*acred))
4388 rxp = afs_pd_inline(ain, sizeof(*rxp));
4392 if (rxp->rx_initReceiveWindow)
4393 rx_initReceiveWindow = rxp->rx_initReceiveWindow;
4394 if (rxp->rx_maxReceiveWindow)
4395 rx_maxReceiveWindow = rxp->rx_maxReceiveWindow;
4396 if (rxp->rx_initSendWindow)
4397 rx_initSendWindow = rxp->rx_initSendWindow;
4398 if (rxp->rx_maxSendWindow)
4399 rx_maxSendWindow = rxp->rx_maxSendWindow;
4400 if (rxp->rxi_nSendFrags)
4401 rxi_nSendFrags = rxp->rxi_nSendFrags;
4402 if (rxp->rxi_nRecvFrags)
4403 rxi_nRecvFrags = rxp->rxi_nRecvFrags;
4404 if (rxp->rxi_OrphanFragSize)
4405 rxi_OrphanFragSize = rxp->rxi_OrphanFragSize;
4406 if (rxp->rx_maxReceiveSize) {
4407 rx_maxReceiveSize = rxp->rx_maxReceiveSize;
4408 rx_maxReceiveSizeUser = rxp->rx_maxReceiveSize;
4410 if (rxp->rx_MyMaxSendSize)
4411 rx_MyMaxSendSize = rxp->rx_MyMaxSendSize;
4417 * VIOC_GETINITPARAMS (49) - Get initial cache manager parameters
4421 * \param[in] ain not in use
4422 * \param[out] aout initial cache manager params
4425 * Error if the initial parameters are bigger than some PIGGYSIZE
4427 * \post return the initial cache manager parameters
4429 DECL_PIOCTL(PGetInitParams)
4431 if (sizeof(struct cm_initparams) > PIGGYSIZE)
4434 return afs_pd_putBytes(aout, &cm_initParams,
4435 sizeof(struct cm_initparams));
4438 #ifdef AFS_SGI65_ENV
4439 /* They took crget() from us, so fake it. */
4444 cr = crdup(get_current_cred());
4445 memset(cr, 0, sizeof(cred_t));
4446 #if CELL || CELL_PREPARE
4454 * VIOC_GETRXKCRYPT (55) - Get rxkad encryption flag
4458 * \param[in] ain not in use
4459 * \param[out] aout value of cryptall
4461 * \post Turns on, or disables, rxkad encryption by setting the cryptall global
4463 DECL_PIOCTL(PGetRxkcrypt)
4465 return afs_pd_putInt(aout, cryptall);
4469 * VIOC_SETRXKCRYPT (56) - Set rxkad encryption flag
4473 * \param[in] ain the argument whether or not things should be encrypted
4474 * \param[out] aout not in use
4477 * Error if the user doesn't have super-user credentials
4479 * Error if the input is too big, or if the input is outside the
4480 * bounds of what it can be set to
4482 * \post set whether or not things should be encrypted
4485 * may need to be modified at a later date to take into account
4486 * other values for cryptall (beyond true or false)
4488 DECL_PIOCTL(PSetRxkcrypt)
4492 if (!afs_osi_suser(*acred))
4494 if (afs_pd_getInt(ain, &tmpval) != 0)
4496 /* if new mappings added later this will need to be changed */
4497 if (tmpval != 0 && tmpval != 1)
4503 #ifdef AFS_NEED_CLIENTCONTEXT
4505 * Create new credentials to correspond to a remote user with given
4506 * <hostaddr, uid, g0, g1>. This allows a server running as root to
4507 * provide pioctl (and other) services to foreign clients (i.e. nfs
4508 * clients) by using this call to `become' the client.
4511 #define PIOCTL_HEADER 6
4513 HandleClientContext(struct afs_ioctl *ablob, int *com,
4514 afs_ucred_t **acred, afs_ucred_t *credp)
4517 afs_uint32 hostaddr;
4518 afs_int32 uid, g0, g1, i, code, pag, exporter_type, isroot = 0;
4519 struct afs_exporter *exporter, *outexporter;
4520 afs_ucred_t *newcred;
4521 struct unixuser *au;
4522 afs_uint32 comp = *com & 0xff00;
4524 #if defined(AFS_SUN510_ENV)
4528 #if defined(AFS_SGIMP_ENV)
4529 osi_Assert(ISAFS_GLOCK());
4531 AFS_STATCNT(HandleClientContext);
4532 if (ablob->in_size < PIOCTL_HEADER * sizeof(afs_int32)) {
4533 /* Must at least include the PIOCTL_HEADER header words
4534 * required by the protocol */
4535 return EINVAL; /* Too small to be good */
4537 ain = inData = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
4538 AFS_COPYIN(ablob->in, ain, PIOCTL_HEADER * sizeof(afs_int32), code);
4540 osi_FreeLargeSpace(inData);
4544 /* Extract information for remote user */
4545 hostaddr = *((afs_uint32 *) ain);
4546 ain += sizeof(hostaddr);
4547 uid = *((afs_uint32 *) ain);
4549 g0 = *((afs_uint32 *) ain);
4551 g1 = *((afs_uint32 *) ain);
4553 *com = *((afs_uint32 *) ain);
4554 ain += sizeof(afs_int32);
4555 exporter_type = *((afs_uint32 *) ain);/* In case we support more than NFS */
4558 * Of course, one must be root for most of these functions, but
4559 * we'll allow (for knfs) you to set things if the pag is 0 and
4560 * you're setting tokens or unlogging.
4563 if (!afs_osi_suser(credp)) {
4564 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
4565 /* Since SGI's suser() returns explicit failure after the call.. */
4568 /* check for acceptable opcodes for normal folks, which are, so far,
4569 * get/set tokens, sysname, and unlog.
4571 if (i != 9 && i != 3 && i != 38 && i != 8) {
4572 osi_FreeLargeSpace(inData);
4577 ablob->in_size -= PIOCTL_HEADER * sizeof(afs_int32);
4578 ablob->in += PIOCTL_HEADER * sizeof(afs_int32);
4579 osi_FreeLargeSpace(inData);
4582 * We map uid 0 to nobody to match the mapping that the nfs
4583 * server does and to ensure that the suser() calls in the afs
4584 * code fails for remote client roots.
4586 uid = afs_nobody; /* NFS_NOBODY == -2 */
4590 #ifdef AFS_AIX41_ENV
4593 afs_set_cr_gid(newcred, isroot ? RMTUSER_REQ_PRIV : RMTUSER_REQ);
4594 #ifdef AFS_AIX51_ENV
4595 newcred->cr_groupset.gs_union.un_groups[0] = g0;
4596 newcred->cr_groupset.gs_union.un_groups[1] = g1;
4597 #elif defined(AFS_LINUX26_ENV)
4598 # ifdef AFS_LINUX26_ONEGROUP_ENV
4599 afs_set_cr_group_info(newcred, groups_alloc(1)); /* nothing sets this */
4600 l = (((g0-0x3f00) & 0x3fff) << 14) | ((g1-0x3f00) & 0x3fff);
4601 h = ((g0-0x3f00) >> 14);
4602 h = ((g1-0x3f00) >> 14) + h + h + h;
4603 GROUP_AT(afs_cr_group_info(newcred), 0) = ((h << 28) | l);
4605 afs_set_cr_group_info(newcred, groups_alloc(2));
4606 GROUP_AT(afs_cr_group_info(newcred), 0) = g0;
4607 GROUP_AT(afs_cr_group_info(newcred), 1) = g1;
4609 #elif defined(AFS_SUN510_ENV)
4612 crsetgroups(newcred, 2, gids);
4614 newcred->cr_groups[0] = g0;
4615 newcred->cr_groups[1] = g1;
4618 newcred->cr_ngrps = 2;
4619 #elif !defined(AFS_LINUX26_ENV) && !defined(AFS_SUN510_ENV)
4620 # if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_LINUX22_ENV) || defined(AFS_FBSD80_ENV)
4621 newcred->cr_ngroups = 2;
4623 for (i = 2; i < NGROUPS; i++)
4624 newcred->cr_groups[i] = NOGROUP;
4627 if (!(exporter = exporter_find(exporter_type))) {
4628 /* Exporter wasn't initialized or an invalid exporter type */
4632 if (exporter->exp_states & EXP_PWSYNC) {
4633 if (uid != afs_cr_uid(credp)) {
4635 return ENOEXEC; /* XXX Find a better errno XXX */
4638 afs_set_cr_uid(newcred, uid); /* Only temporary */
4639 code = EXP_REQHANDLER(exporter, &newcred, hostaddr, &pag, &outexporter);
4640 /* The client's pag is the only unique identifier for it */
4641 afs_set_cr_uid(newcred, pag);
4643 if (!code && *com == PSETPAG) {
4644 /* Special case for 'setpag' */
4645 afs_uint32 pagvalue = genpag();
4647 au = afs_GetUser(pagvalue, -1, WRITE_LOCK); /* a new unixuser struct */
4649 * Note that we leave the 'outexporter' struct held so it won't
4652 au->exporter = outexporter;
4653 if (ablob->out_size >= 4) {
4654 AFS_COPYOUT((char *)&pagvalue, ablob->out, sizeof(afs_int32),
4657 afs_PutUser(au, WRITE_LOCK);
4660 return PSETPAG; /* Special return for setpag */
4662 EXP_RELE(outexporter);
4665 *com = (*com) | comp;
4668 #endif /* AFS_NEED_CLIENTCONTEXT */
4672 * VIOC_GETCPREFS (50) - Get client interface
4676 * \param[in] ain sprefrequest input
4677 * \param[out] aout spref information
4679 * \retval EIO Error if the afs daemon hasn't started yet
4680 * \retval EINVAL Error if some of the standard args aren't set
4683 * get all interface addresses and other information of the client
4686 DECL_PIOCTL(PGetCPrefs)
4688 struct sprefrequest *spin; /* input */
4689 struct sprefinfo *spout; /* output */
4690 struct spref *srvout; /* one output component */
4694 AFS_STATCNT(PGetCPrefs);
4695 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4696 return EIO; /* Inappropriate ioctl for device */
4698 spin = afs_pd_inline(ain, sizeof(*spin));
4702 /* Output spout relies on writing past the end of arrays. It's horrible,
4703 * but I'm not quite brave enough to tackle it yet */
4704 spout = (struct sprefinfo *)aout->ptr;
4706 maxNumber = spin->num_servers; /* max addrs this time */
4707 srvout = spout->servers;
4709 ObtainReadLock(&afs_xinterface);
4711 /* copy out the client interface information from the
4712 * kernel data structure "interface" to the output buffer
4714 for (i = spin->offset, j = 0; (i < afs_cb_interface.numberOfInterfaces)
4715 && (j < maxNumber); i++, j++, srvout++)
4716 srvout->host.s_addr = afs_cb_interface.addr_in[i];
4718 spout->num_servers = j;
4719 aout->ptr += sizeof(struct sprefinfo) + (j - 1) * sizeof(struct spref);
4721 if (i >= afs_cb_interface.numberOfInterfaces)
4722 spout->next_offset = 0; /* start from beginning again */
4724 spout->next_offset = spin->offset + j;
4726 ReleaseReadLock(&afs_xinterface);
4731 * VIOC_SETCPREFS (51) - Set client interface
4735 * \param[in] ain the interfaces you want set
4736 * \param[out] aout not in use
4738 * \retval EIO Error if the afs daemon hasn't started yet
4739 * \retval EINVAL Error if the input is too large for the struct
4740 * \retval ENOMEM Error if there are too many servers
4742 * \post set the callbak interfaces addresses to those of the hosts
4744 DECL_PIOCTL(PSetCPrefs)
4748 struct setspref *sin;
4751 AFS_STATCNT(PSetCPrefs);
4752 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
4753 return EIO; /* Inappropriate ioctl for device */
4755 /* Yuck. Input to this function relies on reading past the end of
4756 * structures. Bodge it for now.
4759 ainSize = ain->remaining;
4761 sin = (struct setspref *)ainPtr;
4763 if (ainSize < sizeof(struct setspref))
4765 #if 0 /* num_servers is unsigned */
4766 if (sin->num_servers < 0)
4769 if (sin->num_servers > AFS_MAX_INTERFACE_ADDR)
4772 ObtainWriteLock(&afs_xinterface, 412);
4773 afs_cb_interface.numberOfInterfaces = sin->num_servers;
4774 for (i = 0; (unsigned short)i < sin->num_servers; i++)
4775 afs_cb_interface.addr_in[i] = sin->servers[i].host.s_addr;
4777 ReleaseWriteLock(&afs_xinterface);
4782 * VIOC_AFS_FLUSHMOUNT (52) - Flush mount symlink data
4787 * the last part of a path to a mount point, which tells us what to flush
4792 * Error if some of the initial arguments aren't set
4794 * Error if the initial argument for the mount point isn't a directory
4796 * Error if the dcache entry isn't set
4799 * remove all of the mount data from the dcache regarding a
4800 * certain mount point
4802 DECL_PIOCTL(PFlushMount)
4807 struct VenusFid tfid;
4810 struct sysname_info sysState;
4811 afs_size_t offset, len;
4813 AFS_STATCNT(PFlushMount);
4817 if (afs_pd_getStringPtr(ain, &mount) != 0)
4820 code = afs_VerifyVCache(avc, areq);
4823 if (vType(avc) != VDIR) {
4826 tdc = afs_GetDCache(avc, (afs_size_t) 0, areq, &offset, &len, 1);
4829 Check_AtSys(avc, mount, &sysState, areq);
4830 ObtainReadLock(&tdc->lock);
4832 code = afs_dir_Lookup(tdc, sysState.name, &tfid.Fid);
4833 } while (code == ENOENT && Next_AtSys(avc, areq, &sysState));
4834 ReleaseReadLock(&tdc->lock);
4835 afs_PutDCache(tdc); /* we're done with the data */
4836 bufp = sysState.name;
4840 tfid.Cell = avc->f.fid.Cell;
4841 tfid.Fid.Volume = avc->f.fid.Fid.Volume;
4842 if (!tfid.Fid.Unique && (avc->f.states & CForeign)) {
4843 tvc = afs_LookupVCache(&tfid, areq, NULL, avc, bufp);
4845 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
4851 if (tvc->mvstat != 1) {
4856 #ifdef AFS_BOZONLOCK_ENV
4857 afs_BozonLock(&tvc->pvnLock, tvc); /* Since afs_TryToSmush will do a pvn_vptrunc */
4859 ObtainWriteLock(&tvc->lock, 649);
4860 ObtainWriteLock(&afs_xcbhash, 650);
4861 afs_DequeueCallback(tvc);
4862 tvc->f.states &= ~(CStatd | CDirty); /* next reference will re-stat cache entry */
4863 ReleaseWriteLock(&afs_xcbhash);
4864 /* now find the disk cache entries */
4865 afs_TryToSmush(tvc, *acred, 1);
4866 osi_dnlc_purgedp(tvc);
4867 if (tvc->linkData && !(tvc->f.states & CCore)) {
4868 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
4869 tvc->linkData = NULL;
4871 ReleaseWriteLock(&tvc->lock);
4872 #ifdef AFS_BOZONLOCK_ENV
4873 afs_BozonUnlock(&tvc->pvnLock, tvc);
4877 if (sysState.allocked)
4878 osi_FreeLargeSpace(bufp);
4883 * VIOC_RXSTAT_PROC (53) - Control process RX statistics
4887 * \param[in] ain the flags that control which stats to use
4888 * \param[out] aout not in use
4890 * \retval EACCES Error if the user doesn't have super-user credentials
4891 * \retval EINVAL Error if the flag input is too long
4894 * either enable process RPCStats, disable process RPCStats,
4895 * or clear the process RPCStats
4897 DECL_PIOCTL(PRxStatProc)
4901 if (!afs_osi_suser(*acred))
4904 if (afs_pd_getInt(ain, &flags) != 0)
4907 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK))
4910 if (flags & AFSCALL_RXSTATS_ENABLE) {
4911 rx_enableProcessRPCStats();
4913 if (flags & AFSCALL_RXSTATS_DISABLE) {
4914 rx_disableProcessRPCStats();
4916 if (flags & AFSCALL_RXSTATS_CLEAR) {
4917 rx_clearProcessRPCStats(AFS_RX_STATS_CLEAR_ALL);
4924 * VIOC_RXSTAT_PEER (54) - Control peer RX statistics
4928 * \param[in] ain the flags that control which statistics to use
4929 * \param[out] aout not in use
4931 * \retval EACCES Error if the user doesn't have super-user credentials
4932 * \retval EINVAL Error if the flag input is too long
4935 * either enable peer RPCStatws, disable peer RPCStats,
4936 * or clear the peer RPCStats
4938 DECL_PIOCTL(PRxStatPeer)
4942 if (!afs_osi_suser(*acred))
4945 if (afs_pd_getInt(ain, &flags) != 0)
4948 if (!(flags & AFSCALL_RXSTATS_MASK) || (flags & ~AFSCALL_RXSTATS_MASK))
4951 if (flags & AFSCALL_RXSTATS_ENABLE) {
4952 rx_enablePeerRPCStats();
4954 if (flags & AFSCALL_RXSTATS_DISABLE) {
4955 rx_disablePeerRPCStats();
4957 if (flags & AFSCALL_RXSTATS_CLEAR) {
4958 rx_clearPeerRPCStats(AFS_RX_STATS_CLEAR_ALL);
4963 DECL_PIOCTL(PPrefetchFromTape)
4967 struct afs_conn *tc;
4968 struct rx_call *tcall;
4969 struct AFSVolSync tsync;
4970 struct AFSFetchStatus OutStatus;
4971 struct AFSCallBack CallBack;
4972 struct VenusFid tfid;
4975 struct rx_connection *rxconn;
4977 AFS_STATCNT(PPrefetchFromTape);
4981 Fid = afs_pd_inline(ain, sizeof(struct AFSFid));
4983 Fid = &avc->f.fid.Fid;
4985 tfid.Cell = avc->f.fid.Cell;
4986 tfid.Fid.Volume = Fid->Volume;
4987 tfid.Fid.Vnode = Fid->Vnode;
4988 tfid.Fid.Unique = Fid->Unique;
4990 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
4992 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
4993 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &avc->f.fid);
4996 afs_Trace3(afs_iclSetp, CM_TRACE_PREFETCHCMD, ICL_TYPE_POINTER, tvc,
4997 ICL_TYPE_FID, &tfid, ICL_TYPE_FID, &tvc->f.fid);
5000 tc = afs_Conn(&tvc->f.fid, areq, SHARED_LOCK, &rxconn);
5004 tcall = rx_NewCall(rxconn);
5006 StartRXAFS_FetchData(tcall, (struct AFSFid *)&tvc->f.fid.Fid, 0,
5009 rx_Read(tcall, (char *)&outval, sizeof(afs_int32));
5011 EndRXAFS_FetchData(tcall, &OutStatus, &CallBack, &tsync);
5013 code = rx_EndCall(tcall, code);
5017 } while (afs_Analyze
5018 (tc, rxconn, code, &tvc->f.fid, areq, AFS_STATS_FS_RPCIDX_RESIDENCYRPCS,
5019 SHARED_LOCK, NULL));
5020 /* This call is done only to have the callback things handled correctly */
5021 afs_FetchStatus(tvc, &tfid, areq, &OutStatus);
5027 return afs_pd_putInt(aout, outval);
5033 struct afs_conn *tc;
5035 struct FsCmdInputs *Inputs;
5036 struct FsCmdOutputs *Outputs;
5037 struct VenusFid tfid;
5039 struct rx_connection *rxconn;
5044 Inputs = afs_pd_inline(ain, sizeof(*Inputs));
5048 Outputs = afs_pd_inline(aout, sizeof(*Outputs));
5049 if (Outputs == NULL)
5054 Fid = &avc->f.fid.Fid;
5056 tfid.Cell = avc->f.fid.Cell;
5057 tfid.Fid.Volume = Fid->Volume;
5058 tfid.Fid.Vnode = Fid->Vnode;
5059 tfid.Fid.Unique = Fid->Unique;
5061 tvc = afs_GetVCache(&tfid, areq, NULL, NULL);
5062 afs_Trace3(afs_iclSetp, CM_TRACE_RESIDCMD, ICL_TYPE_POINTER, tvc,
5063 ICL_TYPE_INT32, Inputs->command, ICL_TYPE_FID, &tfid);
5067 if (Inputs->command) {
5069 tc = afs_Conn(&tvc->f.fid, areq, SHARED_LOCK, &rxconn);
5073 RXAFS_FsCmd(rxconn, Fid, Inputs,
5074 (struct FsCmdOutputs *)aout);
5078 } while (afs_Analyze
5079 (tc, rxconn, code, &tvc->f.fid, areq,
5080 AFS_STATS_FS_RPCIDX_RESIDENCYRPCS, SHARED_LOCK, NULL));
5081 /* This call is done to have the callback things handled correctly */
5082 afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
5083 } else { /* just a status request, return also link data */
5085 Outputs->code = afs_FetchStatus(tvc, &tfid, areq, &Outputs->status);
5086 Outputs->chars[0] = 0;
5087 if (vType(tvc) == VLNK) {
5088 ObtainWriteLock(&tvc->lock, 555);
5089 if (afs_HandleLink(tvc, areq) == 0)
5090 strncpy((char *)&Outputs->chars, tvc->linkData, MAXCMDCHARS);
5091 ReleaseWriteLock(&tvc->lock);
5100 DECL_PIOCTL(PNewUuid)
5102 /*AFS_STATCNT(PNewUuid); */
5103 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
5104 return EIO; /* Inappropriate ioctl for device */
5106 if (!afs_osi_suser(*acred))
5109 ObtainWriteLock(&afs_xinterface, 555);
5110 afs_uuid_create(&afs_cb_interface.uuid);
5111 ReleaseWriteLock(&afs_xinterface);
5112 ForceAllNewConnections();
5116 #if defined(AFS_CACHE_BYPASS) && defined(AFS_LINUX24_ENV)
5118 DECL_PIOCTL(PSetCachingThreshold)
5120 afs_int32 getting = 1;
5121 afs_int32 setting = 1;
5122 afs_int32 threshold = AFS_CACHE_BYPASS_DISABLED;
5124 if (afs_pd_getInt(ain, &threshold) != 0)
5130 if (setting == 0 && getting == 0)
5134 * If setting, set first, and return the value now in effect
5137 if (!afs_osi_suser(*acred))
5139 cache_bypass_threshold = threshold;
5140 afs_warn("Cache Bypass Threshold set to: %d\n", threshold);
5141 /* TODO: move to separate pioctl, or enhance pioctl */
5142 if (threshold == AFS_CACHE_BYPASS_DISABLED)
5143 cache_bypass_strategy = NEVER_BYPASS_CACHE;
5144 else if (!threshold)
5145 cache_bypass_strategy = ALWAYS_BYPASS_CACHE;
5147 cache_bypass_strategy = LARGE_FILES_BYPASS_CACHE;
5150 /* Return the current size threshold */
5152 return afs_pd_putInt(aout, cache_bypass_threshold);
5157 #endif /* defined(AFS_CACHE_BYPASS) */
5159 DECL_PIOCTL(PCallBackAddr)
5162 afs_uint32 addr, code;
5166 struct afs_conn *tc;
5168 struct unixuser *tu;
5169 struct srvAddr **addrs;
5170 struct rx_connection *rxconn;
5172 /*AFS_STATCNT(PCallBackAddr); */
5173 if (!afs_resourceinit_flag) /* afs deamons havn't started yet */
5174 return EIO; /* Inappropriate ioctl for device */
5176 if (!afs_osi_suser(acred))
5179 if (afs_pd_getInt(ain, &addr) != 0)
5182 ObtainReadLock(&afs_xinterface);
5183 for (i = 0; (unsigned short)i < afs_cb_interface.numberOfInterfaces; i++) {
5184 if (afs_cb_interface.addr_in[i] == addr)
5188 ReleaseWriteLock(&afs_xinterface);
5190 if (afs_cb_interface.addr_in[i] != addr)
5193 ObtainReadLock(&afs_xserver); /* Necessary? */
5194 ObtainReadLock(&afs_xsrvAddr);
5197 for (i = 0; i < NSERVERS; i++) {
5198 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
5203 addrs = afs_osi_Alloc(srvAddrCount * sizeof(*addrs));
5204 osi_Assert(addrs != NULL);
5206 for (i = 0; i < NSERVERS; i++) {
5207 for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
5208 if (j >= srvAddrCount)
5214 ReleaseReadLock(&afs_xsrvAddr);
5215 ReleaseReadLock(&afs_xserver);
5217 for (i = 0; i < j; i++) {
5223 /* vlserver has no callback conn */
5224 if (sa->sa_portal == AFS_VLPORT) {
5228 if (!ts->cell) /* not really an active server, anyway, it must */
5229 continue; /* have just been added by setsprefs */
5231 /* get a connection, even if host is down; bumps conn ref count */
5232 tu = afs_GetUser(areq->uid, ts->cell->cellNum, SHARED_LOCK);
5233 tc = afs_ConnBySA(sa, ts->cell->fsport, ts->cell->cellNum, tu,
5234 1 /*force */ , 1 /*create */ , SHARED_LOCK, 0, &rxconn);
5235 afs_PutUser(tu, SHARED_LOCK);
5239 if ((sa->sa_flags & SRVADDR_ISDOWN) || afs_HaveCallBacksFrom(ts)) {
5240 if (sa->sa_flags & SRVADDR_ISDOWN) {
5241 rx_SetConnDeadTime(rxconn, 3);
5243 #ifdef RX_ENABLE_LOCKS
5245 #endif /* RX_ENABLE_LOCKS */
5246 code = RXAFS_CallBackRxConnAddr(rxconn, &addr);
5247 #ifdef RX_ENABLE_LOCKS
5249 #endif /* RX_ENABLE_LOCKS */
5251 afs_PutConn(tc, rxconn, SHARED_LOCK); /* done with it now */
5252 } /* Outer loop over addrs */
5253 #endif /* UKERNEL */
5257 DECL_PIOCTL(PDiscon)
5259 static afs_int32 mode = 1; /* Start up in 'off' */
5260 afs_int32 force = 0;
5263 struct vrequest lreq;
5265 if (afs_pd_getBytes(ain, &flags, 4) == 0) {
5266 if (!afs_osi_suser(*acred))
5270 mode = flags[0] - 1;
5272 afs_ConflictPolicy = flags[1] - 1;
5276 /* Fake InitReq support for UID override */
5277 memset(&lreq, 0, sizeof(lreq));
5278 lreq.uid = flags[3];
5279 areq = &lreq; /* override areq we got */
5283 * All of these numbers are hard coded in fs.c. If they
5284 * change here, they should change there and vice versa
5287 case 0: /* Disconnect ("offline" mode), breaking all callbacks */
5288 if (!AFS_IS_DISCONNECTED) {
5289 ObtainWriteLock(&afs_discon_lock, 999);
5290 afs_DisconGiveUpCallbacks();
5291 afs_RemoveAllConns();
5292 afs_is_disconnected = 1;
5293 afs_is_discon_rw = 1;
5294 ReleaseWriteLock(&afs_discon_lock);
5297 case 1: /* Fully connected, ("online" mode). */
5298 ObtainWriteLock(&afs_discon_lock, 998);
5301 afs_MarkAllServersUp();
5302 code = afs_ResyncDisconFiles(areq, *acred);
5305 if (code && !force) {
5306 afs_warnuser("Files not synchronized properly, still in discon state. \n"
5307 "Please retry or use \"force\".\n");
5311 afs_DisconDiscardAll(*acred);
5313 afs_ClearAllStatdFlag();
5314 afs_is_disconnected = 0;
5315 afs_is_discon_rw = 0;
5316 afs_warnuser("\nSync succeeded. You are back online.\n");
5319 ReleaseWriteLock(&afs_discon_lock);
5331 return afs_pd_putInt(aout, mode);
5334 #define MAX_PIOCTL_TOKENS 10
5336 DECL_PIOCTL(PSetTokens2)
5339 int i, cellNum, primaryFlag;
5341 struct unixuser *tu;
5342 struct vrequest treq;
5343 struct ktc_setTokenData tokenSet;
5344 struct ktc_tokenUnion decodedToken;
5346 memset(&tokenSet, 0, sizeof(tokenSet));
5348 AFS_STATCNT(PSetTokens2);
5349 if (!afs_resourceinit_flag)
5352 afs_pd_xdrStart(ain, &xdrs, XDR_DECODE);
5354 if (!xdr_ktc_setTokenData(&xdrs, &tokenSet)) {
5355 afs_pd_xdrEnd(ain, &xdrs);
5359 afs_pd_xdrEnd(ain, &xdrs);
5361 /* We limit each PAG to 10 tokens to prevent a malicous (or runaway)
5362 * process from using up the whole of the kernel memory by allocating
5365 if (tokenSet.tokens.tokens_len > MAX_PIOCTL_TOKENS) {
5366 xdr_free((xdrproc_t) xdr_ktc_setTokenData, &tokenSet);
5370 code = _settok_tokenCell(tokenSet.cell, &cellNum, &primaryFlag);
5372 xdr_free((xdrproc_t) xdr_ktc_setTokenData, &tokenSet);
5376 if (tokenSet.flags & AFSTOKEN_EX_SETPAG) {
5377 #if defined(AFS_LINUX26_ENV)
5378 afs_ucred_t *old_cred = *acred;
5380 if (_settok_setParentPag(acred) == 0) {
5381 #if defined(AFS_LINUX26_ENV)
5382 /* setpag() may have changed our credentials */
5386 afs_InitReq(&treq, *acred);
5391 tu = afs_GetUser(areq->uid, cellNum, WRITE_LOCK);
5392 /* Free any tokens that we've already got */
5393 afs_FreeTokens(&tu->tokens);
5395 /* Iterate across the set of tokens we've received, and stuff them
5396 * into this user's tokenJar
5398 for (i=0; i < tokenSet.tokens.tokens_len; i++) {
5399 xdrmem_create(&xdrs,
5400 tokenSet.tokens.tokens_val[i].token_opaque_val,
5401 tokenSet.tokens.tokens_val[i].token_opaque_len,
5404 memset(&decodedToken, 0, sizeof(decodedToken));
5405 if (!xdr_ktc_tokenUnion(&xdrs, &decodedToken)) {
5413 afs_AddTokenFromPioctl(&tu->tokens, &decodedToken);
5414 /* This is untidy - the old token interface supported passing
5415 * the primaryFlag as part of the token interface. Current
5416 * OpenAFS userland never sets this, but it's specified as being
5417 * part of the XG interface, so we should probably still support
5418 * it. Rather than add it to our AddToken interface, just handle
5421 if (decodedToken.at_type == AFSTOKEN_UNION_KAD) {
5422 if (decodedToken.ktc_tokenUnion_u.at_kad.rk_primary_flag)
5426 /* XXX - We should think more about destruction here. It's likely that
5427 * there is key material in what we're about to throw away, which
5428 * we really should zero out before giving back to the allocator */
5429 xdr_free((xdrproc_t) xdr_ktc_tokenUnion, &decodedToken);
5432 tu->states |= UHasTokens;
5433 tu->states &= ~UTokensBad;
5434 afs_SetPrimary(tu, primaryFlag);
5435 tu->tokenTime = osi_Time();
5437 xdr_free((xdrproc_t) xdr_ktc_setTokenData, &tokenSet);
5440 afs_ResetUserConns(tu);
5441 afs_PutUser(tu, WRITE_LOCK);
5446 DECL_PIOCTL(PGetTokens2)
5448 struct cell *cell = NULL;
5449 struct unixuser *tu = NULL;
5451 char *cellName = NULL;
5456 struct ktc_setTokenData tokenSet;
5458 AFS_STATCNT(PGetTokens);
5459 if (!afs_resourceinit_flag)
5462 memset(&tokenSet, 0, sizeof(tokenSet));
5464 /* No input data - return tokens for primary cell */
5465 /* 4 octets of data is an iterator count */
5466 /* Otherwise, treat as string & return tokens for that cell name */
5468 if (afs_pd_remaining(ain) == sizeof(afs_int32)) {
5469 /* Integer iterator - return tokens for the n'th cell found for user */
5470 if (afs_pd_getInt(ain, &iterator) != 0)
5472 tu = getNthCell(areq->uid, iterator);
5474 if (afs_pd_remaining(ain) > 0) {
5475 if (afs_pd_getStringPtr(ain, &cellName) != 0)
5480 code = _settok_tokenCell(cellName, &cellNum, NULL);
5483 tu = afs_FindUser(areq->uid, cellNum, READ_LOCK);
5490 if (!(tu->states & UHasTokens)
5491 || !afs_HasValidTokens(tu->tokens, now)) {
5492 tu->states |= (UTokensBad | UNeedsReset);
5493 afs_PutUser(tu, READ_LOCK);
5497 code = afs_ExtractTokensForPioctl(tu->tokens, now, &tokenSet);
5501 cell = afs_GetCell(tu->cell, READ_LOCK);
5502 tokenSet.cell = cell->cellName;
5503 afs_pd_xdrStart(aout, &xdrs, XDR_ENCODE);
5504 if (!xdr_ktc_setTokenData(&xdrs, &tokenSet)) {
5508 afs_pd_xdrEnd(aout, &xdrs);
5511 tokenSet.cell = NULL;
5514 afs_PutUser(tu, READ_LOCK);
5516 afs_PutCell(cell, READ_LOCK);
5517 xdr_free((xdrproc_t)xdr_ktc_setTokenData, &tokenSet);
5522 DECL_PIOCTL(PNFSNukeCreds)
5526 struct unixuser *tu;
5528 AFS_STATCNT(PUnlog);
5529 if (!afs_resourceinit_flag) /* afs daemons haven't started yet */
5530 return EIO; /* Inappropriate ioctl for device */
5532 if (afs_pd_getUint(ain, &addr) != 0)
5535 if (afs_cr_gid(*acred) == RMTUSER_REQ_PRIV && !addr) {
5536 tu = afs_GetUser(areq->uid, -1, SHARED_LOCK);
5537 if (!tu->exporter || !(addr = EXP_GETHOST(tu->exporter))) {
5538 afs_PutUser(tu, SHARED_LOCK);
5541 afs_PutUser(tu, SHARED_LOCK);
5542 } else if (!afs_osi_suser(acred)) {
5546 ObtainWriteLock(&afs_xuser, 227);
5547 for (i = 0; i < NUSERS; i++) {
5548 for (tu = afs_users[i]; tu; tu = tu->next) {
5549 if (tu->exporter && EXP_CHECKHOST(tu->exporter, addr)) {
5551 ReleaseWriteLock(&afs_xuser);
5553 afs_LockUser(tu, WRITE_LOCK, 367);
5555 tu->states &= ~UHasTokens;
5556 afs_FreeTokens(&tu->tokens);
5557 afs_ResetUserConns(tu);
5558 afs_PutUser(tu, WRITE_LOCK);
5559 ObtainWriteLock(&afs_xuser, 228);
5561 /* set the expire times to 0, causes
5562 * afs_GCUserData to remove this entry
5565 #endif /* UKERNEL */
5569 ReleaseWriteLock(&afs_xuser);