FBSD: deal with kernel API rename
[openafs.git] / src / afs / FBSD / 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 /* 
11  * osi_misc.c
12  *
13  */
14
15 #include <afsconfig.h>
16 #include "afs/param.h"
17
18
19 #include "afs/sysincludes.h"    /* Standard vendor system headers */
20 #include "afsincludes.h"        /* Afs-based standard headers */
21 #include <sys/namei.h>
22
23 int
24 osi_lookupname(char *aname, enum uio_seg seg, int followlink,
25                struct vnode **vpp)
26 {
27     struct nameidata n;
28     int flags, error, glocked;
29
30     glocked = ISAFS_GLOCK();
31     if (glocked)
32         AFS_GUNLOCK();
33
34     flags = LOCKLEAF | MPSAFE; /* namei must take Giant if needed */
35     if (followlink)
36         flags |= FOLLOW;
37     else
38         flags |= NOFOLLOW;
39     NDINIT(&n, LOOKUP, flags, seg, aname, curthread);
40     if ((error = namei(&n)) != 0) {
41         if (glocked)
42             AFS_GLOCK();
43         return error;
44     }
45     *vpp = n.ni_vp;
46     /* XXX should we do this?  Usually NOT (matt) */
47 #if defined(AFS_FBSD80_ENV)
48     /*VOP_UNLOCK(n.ni_vp, 0);*/
49 #else
50     VOP_UNLOCK(n.ni_vp, 0, curthread);
51 #endif
52     NDFREE(&n, NDF_ONLY_PNBUF);
53     if (glocked)
54         AFS_GLOCK();
55     return 0;
56 }
57
58 /*
59  * does not implement security features of kern_time.c:settime()
60  */
61 void
62 afs_osi_SetTime(osi_timeval_t * atv)
63 {
64     printf("afs attempted to set clock; use \"afsd -nosettime\"\n");
65 }
66
67 /*
68  * Replace all of the bogus special-purpose memory allocators...
69  */
70 void *
71 osi_fbsd_alloc(size_t size, int dropglobal)
72 {
73         void *rv;
74         int glocked;
75
76         if (dropglobal) {
77             glocked = ISAFS_GLOCK();
78             if (glocked)
79                 AFS_GUNLOCK();
80             rv = malloc(size, M_AFS, M_WAITOK);
81             if (glocked)
82                 AFS_GLOCK();
83         } else
84             rv = malloc(size, M_AFS, M_NOWAIT);
85
86         return (rv);
87 }
88
89 void
90 osi_fbsd_free(void *p)
91 {
92        free(p, M_AFS);
93 }