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