c776154661bc2dfca0f20e97cc6c3d2aa48551c5
[openafs.git] / src / afs / DARWIN / osi_misc.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
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
8  */
9
10 #include <afsconfig.h>
11 #include "afs/param.h"
12
13 RCSID
14     ("$Header$");
15
16 #include "afs/sysincludes.h"
17 #include "afsincludes.h"
18 #include <sys/namei.h>
19
20 #ifdef AFS_DARWIN80_ENV
21 int
22 osi_lookupname(char *aname, enum uio_seg seg, int followlink,
23                struct vnode **vpp) {
24   vfs_context_t ctx;
25   char tname[PATHBUFLEN];
26   int len, code, flags;
27
28   if (seg == AFS_UIOUSER) { /* XXX 64bit */
29      AFS_COPYINSTR(aname, tname, PATHBUFLEN, code);
30      if (code)
31        return code;
32      aname=tname;
33   }
34   flags = 0
35   if (!followlink)
36         flag |= VNODE_LOOKUP_NOFOLLOW;
37   ctx=vfs_context_create(NULL);
38   code = vnode_lookup(aname, flags, vpp, ctx);
39   vfs_context_rele(ctx);
40   return code;
41 }
42 #else
43 int
44 osi_lookupname(char *aname, enum uio_seg seg, int followlink,
45                struct vnode **vpp)
46 {
47     struct nameidata n;
48     int flags, error;
49     flags = 0;
50     flags = LOCKLEAF;
51     if (followlink)
52         flags |= FOLLOW;
53     else
54         flags |= NOFOLLOW;
55     NDINIT(&n, LOOKUP, flags, seg, aname, current_proc());
56     if (error = namei(&n))
57         return error;
58     *vpp = n.ni_vp;
59    /* should we do this? */
60     VOP_UNLOCK(n.ni_vp, 0, current_proc());
61     return 0;
62 }
63 #endif
64
65 /*
66  * afs_suser() returns true if the caller is superuser, false otherwise.
67  *
68  * Note that it must NOT set errno.
69  */
70 int
71 afs_suser(void *credp)
72 {
73     int error;
74     struct proc *p = current_proc();
75
76 #if AFS_DARWIN80_ENV
77     return proc_suser(p);
78 #else
79     if ((error = suser(p->p_ucred, &p->p_acflag)) == 0) {
80         return (1);
81     }
82     return (0);
83 #endif
84 }
85
86 #ifdef AFS_DARWIN80_ENV
87 uio_t afsio_darwin_partialcopy(uio_t auio, int size) {
88    uio_t res;
89    int index;
90    user_addr_t iovaddr;
91    user_size_r iovsize;
92
93    /* XXX 64 bit userspaace? */
94    res = uio_create(uio_iovcnt(auio), uio_offset(auio),
95                     uio_isuserspace(auio) ? UIO_USERSPACE32 : UIO_SYSSPACE32,
96                     uio_rw(auio));
97
98    for (i = 0;i < uio_iovcnt(auio) && size > 0;i++) {
99        if (uio_getiov(auio, index, &iovaddr, &iovsize))
100            break;
101        if (iovsize > size)
102           iovsize = size;
103        if (uio_addiov(res, iovaddr, iovsize))
104           break;
105        size -= iovsize;
106    }
107    return res;
108 }
109 #endif