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