obsd-glock-decl-20051115
[openafs.git] / src / afs / OBSD / 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  * OpenBSD 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 /* $Id$ */
20
21 #ifndef _OSI_MACHDEP_H_
22 #define _OSI_MACHDEP_H_
23
24 #include <sys/lock.h>
25
26 extern struct simplelock afs_rxglobal_lock;
27
28 #define M_AFSFID        (M_TEMP-1)
29 #define M_AFSBUFHDR     (M_TEMP-2)
30 #define M_AFSBUFFER     (M_TEMP-3)
31 #define M_AFSGENERIC    (M_TEMP-4)
32
33 /* vfs */
34 #define osi_vfs         mount
35 #define osi_vfs_bsize   mnt_stat.f_bsize
36 #define osi_vfs_fsid    mnt_stat.f_fsid
37 #define vfs_bsize       mnt_stat.f_bsize
38 #define vfs_fsid        mnt_stat.f_fsid
39 #define vfs_vnodecovered mnt_vnodecovered
40 #define v_vfsp          v_mount
41
42 /* vnode */
43 #define VN_HOLD(vp)     afs_vget((vp), 0)
44 #define VN_RELE(vp)     vrele(vp)
45 #define osi_vnhold(avc, r) afs_vget(AFSTOV(avc), 0)
46 #define va_nodeid       va_fileid
47 #define vnode_t         struct vnode
48
49 /* uio */
50 #define afsio_iov       uio_iov
51 #define afsio_iovcnt    uio_iovcnt
52 #define afsio_offset    uio_offset
53 #define afsio_resid     uio_resid
54 #define afsio_seg       uio_segflg
55 #define AFS_UIOSYS      UIO_SYSSPACE
56 #define AFS_UIOUSER     UIO_USERSPACE
57
58 /* malloc */
59 #define AFS_KALLOC(s)   afs_nbsd_Alloc(s)
60 #define AFS_KFREE(p, s) afs_nbsd_Free((p), (s))
61
62 /* proc, cred */
63 #define AFS_PROC        struct proc
64 #define AFS_UCRED       ucred
65 #define afs_suser(x)    afs_osi_suser(osi_curcred())
66 #define getpid()        curproc
67 #define osi_curcred()   (curproc->p_cred->pc_ucred)
68 #define osi_curproc()   curproc
69 #define p_rcred         p_ucred
70
71 /* time */
72 #define afs_hz          hz
73 #define osi_GetTime(x)  microtime(x)
74 #define osi_Time()      (time.tv_sec)
75
76 /* str */
77 #define afs_strcasecmp(s1, s2)  strncasecmp((s1), (s2), 65535)
78 #ifdef AFS_OBSD34_ENV
79 #define strcpy(s1, s2)          afs_strcpy((s1), (s2))
80 #define strcat(s1, s2)          afs_strcat((s1), (s2))
81 #else
82 #define afs_strcat(s1, s2)      strcat((s1), (s2))
83 #endif
84
85 /* other */
86 #define afs_bufferpages bufpages
87 #ifndef iodone
88 #define iodone biodone
89 #endif
90 #define PAGESIZE        8192
91 #define printk          printf  /* for RX version of xdr_* */
92 #define setgroups       sys_setgroups
93 #define UVM
94
95 /* This is not always in scope yet */
96 struct vcache;
97
98 extern int afs_nbsd_lookupname(char *fnamep, enum uio_seg segflg,
99                                int followlink, struct vnode **compvpp);
100 extern void afs_nbsd_getnewvnode(struct vcache *tvc);
101 extern void *afs_nbsd_Alloc(size_t asize);
102 extern void afs_nbsd_Free(void *p, size_t asize);
103 extern int afs_vget();
104
105 #undef gop_lookupname
106 #define gop_lookupname(fnamep, segflg, followlink, compvpp) \
107         afs_nbsd_lookupname((fnamep), (segflg), (followlink), (compvpp))
108
109 #ifdef KERNEL
110
111 #ifdef AFS_GLOBAL_SUNLOCK
112 extern struct proc *afs_global_owner;
113 extern struct lock afs_global_lock;
114 #define AFS_GLOCK() \
115     do { \
116         osi_Assert(curproc); \
117         lockmgr(&afs_global_lock, LK_EXCLUSIVE, 0, curproc); \
118         osi_Assert(afs_global_owner == NULL); \
119         afs_global_owner = curproc; \
120     } while (0)
121 #define AFS_GUNLOCK() \
122     do { \
123         osi_Assert(curproc); \
124         osi_Assert(afs_global_owner == curproc); \
125         afs_global_owner = NULL; \
126         lockmgr(&afs_global_lock, LK_RELEASE, 0, curproc); \
127     } while(0)
128 #define ISAFS_GLOCK() (afs_global_owner == curproc && curproc)
129 #else
130 extern struct lock afs_global_lock;
131 #define AFS_GLOCK()
132 #define AFS_GUNLOCK()
133 #define AFS_ASSERT_GLOCK()
134 #define ISAFS_GLOCK() 1
135 #endif
136
137 #undef SPLVAR
138 #define SPLVAR int splvar
139 #undef NETPRI
140 #define NETPRI splvar=splnet()
141 #undef USERPRI
142 #define USERPRI splx(splvar)
143 #endif /* KERNEL */
144
145 #endif /* _OSI_MACHDEP_H_ */