freebsd-20040310
[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  * Implements:
14  * afs_suser
15  */
16
17 #include <afsconfig.h>
18 #include "afs/param.h"
19
20 RCSID
21     ("$Header$");
22
23 #include "afs/sysincludes.h"    /* Standard vendor system headers */
24 #include "afsincludes.h"        /* Afs-based standard headers */
25 #include <sys/namei.h>
26
27 #ifdef AFS_FBSD50_ENV
28 /* serious cheating */
29 #undef curproc
30 #define curproc curthread
31 #endif
32
33 int
34 osi_lookupname(char *aname, enum uio_seg seg, int followlink,
35                struct vnode **dirvpp, struct vnode **vpp)
36 {
37     struct nameidata n;
38     int flags, error, wasowned;
39
40 #ifdef AFS_FBSD50_ENV
41     wasowned = mtx_owned(&afs_global_mtx);
42     if (wasowned)
43         mtx_unlock(&afs_global_mtx);
44 #endif
45
46     flags = 0;
47     flags = LOCKLEAF;
48     if (followlink)
49         flags |= FOLLOW;
50     else
51         flags |= NOFOLLOW;
52     /*   if (dirvpp) flags|=WANTPARENT; *//* XXX LOCKPARENT? */
53     NDINIT(&n, LOOKUP, flags, seg, aname, curproc);
54     if ((error = namei(&n)) != 0) {
55 #ifdef AFS_FBSD50_ENV
56         if (wasowned)
57             mtx_lock(&afs_global_mtx);
58 #endif
59         return error;
60     }
61     *vpp = n.ni_vp;
62 /*
63    if (dirvpp)
64       *dirvpp = n.ni_dvp;
65 */
66     /* should we do this? */
67     VOP_UNLOCK(n.ni_vp, 0, curproc);
68     NDFREE(&n, NDF_ONLY_PNBUF);
69 #ifdef AFS_FBSD50_ENV
70     if (wasowned)
71         mtx_lock(&afs_global_mtx);
72 #endif
73     return 0;
74 }
75
76 /*
77  * does not implement security features of kern_time.c:settime()
78  */
79 void
80 afs_osi_SetTime(osi_timeval_t * atv)
81 {
82 #ifdef AFS_FBSD50_ENV
83     printf("afs attempted to set clock; use \"afsd -nosettime\"\n");
84 #else
85     struct timespec ts;
86     struct timeval tv, delta;
87     int s;
88
89     AFS_GUNLOCK();
90     s = splclock();
91     microtime(&tv);
92     delta = *atv;
93     timevalsub(&delta, &tv);
94     ts.tv_sec = atv->tv_sec;
95     ts.tv_nsec = atv->tv_usec * 1000;
96     set_timecounter(&ts);
97     (void)splsoftclock();
98     lease_updatetime(delta.tv_sec);
99     splx(s);
100     resettodr();
101     AFS_GLOCK();
102 #endif
103 }
104
105 /*
106  * Replace all of the bogus special-purpose memory allocators...
107  */
108 void *
109 osi_fbsd_alloc(size_t size, int dropglobal)
110 {
111         void *rv;
112 #ifdef AFS_FBSD50_ENV
113         int wasowned;
114
115         if (dropglobal) {
116                 wasowned = mtx_owned(&afs_global_mtx);
117                 if (wasowned)
118                         mtx_unlock(&afs_global_mtx);
119                 rv = malloc(size, M_AFS, M_WAITOK);
120                 if (wasowned)
121                         mtx_lock(&afs_global_mtx);
122         } else
123 #endif
124                 rv = malloc(size, M_AFS, M_NOWAIT);
125
126         return (rv);
127 }
128
129 void
130 osi_fbsd_free(void *p)
131 {
132
133         free(p, M_AFS);
134 }
135
136 void
137 osi_AllocMoreSSpace(afs_int32 preallocs)
138 {
139         ;
140 }
141
142 void
143 osi_FreeLargeSpace(void *p)
144 {
145         osi_fbsd_free(p);
146 }
147
148 void
149 osi_FreeSmallSpace(void *p)
150 {
151         osi_fbsd_free(p);
152 }
153
154 void *
155 osi_AllocLargeSpace(size_t size)
156 {
157         AFS_ASSERT_GLOCK();
158         AFS_STATCNT(osi_AllocLargeSpace);
159         return (osi_fbsd_alloc(size, 1));
160 }
161
162 void *
163 osi_AllocSmallSpace(size_t size)
164 {
165         AFS_ASSERT_GLOCK();
166         AFS_STATCNT(osi_AllocSmallSpace);
167         return (osi_fbsd_alloc(size, 1));
168 }
169
170 void
171 shutdown_osinet(void)
172 {
173         ;
174 }