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