134f4824ca2832cc9b176965582a1ec5f00a7b41
[openafs.git] / src / afs / FBSD / osi_machdep.h
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  *
12  * FBSD OSI header file. Extends afs_osi.h.
13  *
14  * afs_osi.h includes this file, which is the only way this file should
15  * be included in a source file. This file can redefine macros declared in
16  * afs_osi.h.
17  */
18
19 #ifndef _OSI_MACHDEP_H_
20 #define _OSI_MACHDEP_H_
21
22 #include <sys/lock.h>
23 #include <sys/time.h>
24 #include <sys/mutex.h>
25 #include <sys/vnode.h>
26 #if defined(AFS_FBSD80_ENV)
27 #include <sys/priv.h>
28 #endif
29
30 /*
31  * Time related macros
32  */
33 #define osi_Time()      time_second
34 #define afs_hz          hz
35
36 typedef struct ucred afs_ucred_t;
37 typedef struct proc afs_proc_t;
38
39 #define afs_bufferpages bufpages
40 #ifndef iodone
41 #define iodone biodone
42 #endif
43
44 #define VSUID           S_ISUID
45 #define VSGID           S_ISGID
46
47 #define osi_vnhold(avc,r)       vref(AFSTOV(avc))
48
49 #define vType(vc)               AFSTOV(vc)->v_type
50 #define vSetVfsp(vc, vfsp)      AFSTOV(vc)->v_mount = (vfsp)
51 #define vSetType(vc, type)      AFSTOV(vc)->v_type = (type)
52 #if defined(AFS_FBSD60_ENV) && defined(KERNEL)
53 extern struct vop_vector afs_vnodeops;
54 # define IsAfsVnode(v) ((v)->v_op == &afs_vnodeops)
55 #else
56 extern int (**afs_vnodeop_p) ();
57 # define IsAfsVnode(v)           ((v)->v_op == afs_vnodeop_p)
58 #endif
59 #define SetAfsVnode(v)          /* nothing; done in getnewvnode() */
60
61 #if defined(AFS_FBSD80_ENV)
62 #define osi_vinvalbuf(vp, flags, slpflag, slptimeo) \
63   vinvalbuf((vp), (flags), (slpflag), (slptimeo))
64 #else
65 #define osi_vinvalbuf(vp, flags, slpflag, slptimeo) \
66   vinvalbuf((vp), (flags), (curthread), (slpflag), (slptimeo))
67 #define osi_curproc() (curthread)
68 #endif
69
70 #undef gop_lookupname
71 #define gop_lookupname osi_lookupname
72
73 #undef gop_lookupname_user
74 #define gop_lookupname_user osi_lookupname
75
76 #define afs_strcat(s1, s2)      strcat((s1), (s2))
77
78 /* malloc */
79 extern void *osi_fbsd_alloc(size_t size, int dropglobal);
80 extern void osi_fbsd_free(void *p);
81
82 #define afs_osi_Alloc_NoSleep(size) osi_fbsd_alloc((size), 0)
83
84 #ifdef AFS_FBSD80_ENV
85 #define VN_RELE(vp)                             \
86   do {                                          \
87     vrele(vp);                                  \
88   } while(0);
89 #else
90 #define VN_RELE(vp)             vrele(vp)
91 #endif
92 #define VN_HOLD(vp)             VREF(vp)
93
94 #undef afs_suser
95 #if defined(AFS_FBSD80_ENV)
96 /* OpenAFS-specific privileges negotiated for FreeBSD, thanks due to
97  * Ben Kaduk */
98 #define osi_suser_client_settings(x)   (!priv_check(curthread, PRIV_AFS_ADMIN))
99 #define osi_suser_afs_daemon(x)   (!priv_check(curthread, PRIV_AFS_DAEMON))
100 #define afs_suser(x) (osi_suser_client_settings((x)) && osi_suser_afs_daemon((x)))
101 #else
102 #define afs_suser(x)    (!suser(curthread))
103 #endif
104
105 #undef osi_getpid
106 #define VT_AFS          "afs"
107 #define VROOT           VV_ROOT
108 #define v_flag          v_vflag
109 #define osi_curcred()   (curthread->td_ucred)
110 #define osi_curproc()   (curthread)
111 #define osi_getpid()    (curthread->td_proc->p_pid)
112 #define simple_lock(x)  mtx_lock(x)
113 #define simple_unlock(x) mtx_unlock(x)
114 #define        gop_rdwr(rw,gp,base,len,offset,segflg,unit,cred,aresid) \
115   vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(unit),(cred),(cred),(aresid), curthread)
116 extern struct mtx afs_global_mtx;
117 extern struct thread *afs_global_owner;
118 #define AFS_GLOCK() \
119     do { \
120         mtx_assert(&afs_global_mtx, (MA_NOTOWNED)); \
121         mtx_lock(&afs_global_mtx); \
122         mtx_assert(&afs_global_mtx, (MA_OWNED|MA_NOTRECURSED)); \
123     } while (0)
124 #define AFS_GUNLOCK() \
125     do { \
126         mtx_assert(&afs_global_mtx, (MA_OWNED|MA_NOTRECURSED)); \
127         mtx_unlock(&afs_global_mtx); \
128     } while (0)
129 #define ISAFS_GLOCK() (mtx_owned(&afs_global_mtx))
130 # if defined(AFS_FBSD80_ENV) && defined(WITNESS)
131 #  define osi_InitGlock() \
132         do { \
133             memset(&afs_global_mtx, 0, sizeof(struct mtx)); \
134             mtx_init(&afs_global_mtx, "AFS global lock", NULL, MTX_DEF); \
135             afs_global_owner = 0; \
136         } while(0)
137 # else
138 #  define osi_InitGlock() \
139     do { \
140         mtx_init(&afs_global_mtx, "AFS global lock", NULL, MTX_DEF); \
141         afs_global_owner = 0; \
142     } while (0)
143 # endif
144
145 #undef SPLVAR
146 #define SPLVAR
147 #undef NETPRI
148 #define NETPRI
149 #undef USERPRI
150 #define USERPRI
151
152 #define osi_procname(procname, size) strncpy(procname, curproc->p_comm, size)
153
154 #endif /* _OSI_MACHDEP_H_ */