freebsd: track RELENG_8
[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 #ifdef AFS_FBSD50_ENV
24 /* serious cheating */
25 #undef curproc
26 #define curproc curthread
27 #endif
28
29 int
30 osi_lookupname(char *aname, enum uio_seg seg, int followlink,
31                struct vnode **vpp)
32 {
33     struct nameidata n;
34     int flags, error, glocked;
35
36 #ifdef AFS_FBSD50_ENV
37     glocked = ISAFS_GLOCK();
38     if (glocked)
39         AFS_GUNLOCK();
40 #endif
41
42     flags = 0;
43     flags = LOCKLEAF;
44     if (followlink)
45         flags |= FOLLOW;
46     else
47         flags |= NOFOLLOW;
48 #ifdef AFS_FBSD80_ENV
49     flags |= MPSAFE; /* namei must take GIANT if needed */
50 #endif
51     NDINIT(&n, LOOKUP, flags, seg, aname, curproc);
52     if ((error = namei(&n)) != 0) {
53 #ifdef AFS_FBSD50_ENV
54         if (glocked)
55             AFS_GLOCK();
56 #endif
57         return error;
58     }
59     *vpp = n.ni_vp;
60     /* XXX should we do this?  Usually NOT (matt) */
61 #if defined(AFS_FBSD80_ENV)
62     /*VOP_UNLOCK(n.ni_vp, 0);*/
63 #elif defined(AFS_FBSD50_ENV)
64     VOP_UNLOCK(n.ni_vp, 0, curthread);
65 #else
66     VOP_UNLOCK(n.ni_vp, 0, curproc);
67 #endif
68     NDFREE(&n, NDF_ONLY_PNBUF);
69 #ifdef AFS_FBSD50_ENV
70     if (glocked)
71         AFS_GLOCK();
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 glocked;
114
115         if (dropglobal) {
116             glocked = ISAFS_GLOCK();
117             if (glocked)
118                 AFS_GUNLOCK();
119             rv = malloc(size, M_AFS, M_WAITOK);
120             if (glocked)
121                 AFS_GLOCK();
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        free(p, M_AFS);
133 }