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"
15 #include "afsincludes.h"
16 #include <sys/namei.h>
19 #define PATHBUFLEN 256
22 #ifdef AFS_DARWIN80_ENV
23 static thread_t vfs_context_owner;
25 /* works like PFlushVolumeData */
27 darwin_notify_perms(struct unixuser *auser, int event)
30 struct afs_q *tq, *uq = NULL;
31 struct vcache *tvc, *hnext;
32 int isglock = ISAFS_GLOCK();
37 if (!afs_darwin_fsevents)
41 VATTR_SET(&va, va_mode, 0777);
42 if (event & UTokensObtained)
43 VATTR_SET(&va, va_uid, auser->uid);
45 VATTR_SET(&va, va_uid, -2); /* nobody */
49 if (!(vfs_context_owner == current_thread())) {
54 ObtainReadLock(&afs_xvcache);
55 for (i = 0; i < VCSIZE; i++) {
56 for (tq = afs_vhashTV[i].prev; tq != &afs_vhashTV[i]; tq = uq) {
59 if (tvc->f.states & CDeadVnode) {
60 /* we can afford to be best-effort */
63 /* no per-file acls, so only notify on directories */
64 if (!(vp = AFSTOV(tvc)) || !vnode_isdir(AFSTOV(tvc)))
66 /* dynroot object. no callbacks. anonymous ACL. just no. */
67 if (afs_IsDynrootFid(tvc))
69 /* no fake fsevents on mount point sources. leaks refs */
72 /* if it's being reclaimed, just pass */
81 ReleaseReadLock(&afs_xvcache);
82 ObtainWriteLock(&tvc->lock, 234);
83 tvc->f.states |= CEvent;
85 vnode_setattr(vp, &va, afs_osi_ctxtp);
86 tvc->f.states &= ~CEvent;
89 ReleaseWriteLock(&tvc->lock);
90 ObtainReadLock(&afs_xvcache);
91 /* our tvc ptr is still good until now */
95 ReleaseReadLock(&afs_xvcache);
103 osi_lookupname_user(user_addr_t aname, enum uio_seg seg, int followlink,
104 struct vnode **vpp) {
105 char tname[PATHBUFLEN];
109 if (seg == AFS_UIOUSER) { /* XXX 64bit */
110 AFS_COPYINSTR(aname, tname, sizeof(tname), &len, code);
113 return osi_lookupname(tname, seg, followlink, vpp);
115 return osi_lookupname(CAST_DOWN(char *, aname), seg, followlink, vpp);
120 osi_lookupname(char *aname, enum uio_seg seg, int followlink,
121 struct vnode **vpp) {
127 flags |= VNODE_LOOKUP_NOFOLLOW;
128 ctx=vfs_context_create(NULL);
129 code = vnode_lookup(aname, flags, vpp, ctx);
130 if (!code) { /* get a usecount */
134 vfs_context_rele(ctx);
139 osi_lookupname(char *aname, enum uio_seg seg, int followlink,
150 NDINIT(&n, LOOKUP, flags, seg, aname, current_proc());
151 if (error = namei(&n))
154 /* should we do this? */
155 VOP_UNLOCK(n.ni_vp, 0, current_proc());
161 * afs_suser() returns true if the caller is superuser, false otherwise.
163 * Note that it must NOT set errno.
166 afs_suser(void *credp)
169 struct proc *p = current_proc();
171 #ifdef AFS_DARWIN80_ENV
172 if ((error = proc_suser(p)) == 0) {
177 if ((error = suser(p->p_ucred, &p->p_acflag)) == 0) {
184 #ifdef AFS_DARWIN80_ENV
186 afsio_darwin_partialcopy(uio_t auio, int size)
193 if (proc_is64bit(current_proc())) {
194 res = uio_create(uio_iovcnt(auio), uio_offset(auio),
195 uio_isuserspace(auio) ? UIO_USERSPACE64 : UIO_SYSSPACE32,
198 res = uio_create(uio_iovcnt(auio), uio_offset(auio),
199 uio_isuserspace(auio) ? UIO_USERSPACE32 : UIO_SYSSPACE32,
203 for (i = 0;i < uio_iovcnt(auio) && size > 0;i++) {
204 if (uio_getiov(auio, i, &iovaddr, &iovsize))
208 if (uio_addiov(res, iovaddr, iovsize))
215 vfs_context_t afs_osi_ctxtp;
216 int afs_osi_ctxtp_initialized;
217 static proc_t vfs_context_curproc;
221 get_vfs_context(void)
223 int isglock = ISAFS_GLOCK();
227 if (afs_osi_ctxtp_initialized) {
232 osi_Assert(vfs_context_owner != current_thread());
233 if (afs_osi_ctxtp && current_proc() == vfs_context_curproc) {
235 vfs_context_owner = current_thread();
240 while (afs_osi_ctxtp && vfs_context_ref) {
241 afs_osi_Sleep(&afs_osi_ctxtp);
242 if (afs_osi_ctxtp_initialized) {
248 vfs_context_rele(afs_osi_ctxtp);
250 afs_osi_ctxtp = vfs_context_create(NULL);
251 vfs_context_owner = current_thread();
252 vfs_context_curproc = current_proc();
258 put_vfs_context(void)
260 int isglock = ISAFS_GLOCK();
264 if (afs_osi_ctxtp_initialized) {
269 if (vfs_context_owner == current_thread())
270 vfs_context_owner = (thread_t)0;
272 afs_osi_Wakeup(&afs_osi_ctxtp);
278 afs_cdev_nop_openclose(dev_t dev, int flags, int devtype,struct proc *p)
284 afs_cdev_ioctl(dev_t dev, u_long cmd, caddr_t data, int fflag, struct proc *p) {
285 unsigned int retval=0;
286 int code, is64 = proc_is64bit(p);
287 struct afssysargs *a = (struct afssysargs *)data;
288 struct afssysargs64 *a64 = (struct afssysargs64 *)data;
290 if (((unsigned int)cmd != VIOC_SYSCALL) &&
291 ((unsigned int)cmd != VIOC_SYSCALL64))
294 if (((unsigned int)cmd == VIOC_SYSCALL64) && (is64 == 0))
297 if (((unsigned int)cmd == VIOC_SYSCALL) && (is64 != 0))
300 code=afs3_syscall(p, data, &retval);
304 if ((!is64) && retval && a->syscall != AFSCALL_CALL
305 && a->param1 != AFSOP_CACHEINODE)
307 printf("SSCall(%d,%d) is returning non-error value %d\n", a->syscall, a->param1, retval);
309 if ((is64) && retval && a64->syscall != AFSCALL_CALL
310 && a64->param1 != AFSOP_CACHEINODE)
312 printf("SSCall(%d,%llx) is returning non-error value %d\n", a64->syscall, a64->param1, retval);
318 a64->retval = retval;