e433602e180f24ee3ccfa4cb3580347f9f692b94
[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 #ifdef AFS_FBSD50_ENV
31     glocked = ISAFS_GLOCK();
32     if (glocked)
33         AFS_GUNLOCK();
34 #endif
35
36     flags = 0;
37     flags = LOCKLEAF;
38     if (followlink)
39         flags |= FOLLOW;
40     else
41         flags |= NOFOLLOW;
42 #ifdef AFS_FBSD80_ENV
43     flags |= MPSAFE; /* namei must take GIANT if needed */
44 #endif
45     NDINIT(&n, LOOKUP, flags, seg, aname, curthread);
46     if ((error = namei(&n)) != 0) {
47 #ifdef AFS_FBSD50_ENV
48         if (glocked)
49             AFS_GLOCK();
50 #endif
51         return error;
52     }
53     *vpp = n.ni_vp;
54     /* XXX should we do this?  Usually NOT (matt) */
55 #if defined(AFS_FBSD80_ENV)
56     /*VOP_UNLOCK(n.ni_vp, 0);*/
57 #else
58     VOP_UNLOCK(n.ni_vp, 0, curthread);
59 #endif
60     NDFREE(&n, NDF_ONLY_PNBUF);
61 #ifdef AFS_FBSD50_ENV
62     if (glocked)
63         AFS_GLOCK();
64 #endif
65     return 0;
66 }
67
68 /*
69  * does not implement security features of kern_time.c:settime()
70  */
71 void
72 afs_osi_SetTime(osi_timeval_t * atv)
73 {
74 #ifdef AFS_FBSD50_ENV
75     printf("afs attempted to set clock; use \"afsd -nosettime\"\n");
76 #else
77     struct timespec ts;
78     struct timeval tv, delta;
79     int s;
80
81     AFS_GUNLOCK();
82     s = splclock();
83     microtime(&tv);
84     delta = *atv;
85     timevalsub(&delta, &tv);
86     ts.tv_sec = atv->tv_sec;
87     ts.tv_nsec = atv->tv_usec * 1000;
88     set_timecounter(&ts);
89     (void)splsoftclock();
90     lease_updatetime(delta.tv_sec);
91     splx(s);
92     resettodr();
93     AFS_GLOCK();
94 #endif
95 }
96
97 /*
98  * Replace all of the bogus special-purpose memory allocators...
99  */
100 void *
101 osi_fbsd_alloc(size_t size, int dropglobal)
102 {
103         void *rv;
104 #ifdef AFS_FBSD50_ENV
105         int glocked;
106
107         if (dropglobal) {
108             glocked = ISAFS_GLOCK();
109             if (glocked)
110                 AFS_GUNLOCK();
111             rv = malloc(size, M_AFS, M_WAITOK);
112             if (glocked)
113                 AFS_GLOCK();
114         } else
115 #endif
116             rv = malloc(size, M_AFS, M_NOWAIT);
117
118         return (rv);
119 }
120
121 void
122 osi_fbsd_free(void *p)
123 {
124        free(p, M_AFS);
125 }