openbsd-20031007
[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 SetAfsVnode(vn)         /* nothing; done in getnewvnode() */
44 #define IsAfsVnode(vn)  ((vn)->v_op == afs_vnodeop_p)
45 #define AFS_HOLD(vp)    afs_nbsd_ref(vp)
46 #define AFS_RELE(vp)    afs_nbsd_rele(vp)
47 #define VN_HOLD(vp)     afs_vget((vp), 0)
48 #define osi_vnhold(avc, r) afs_vget(AFSTOV(avc), 0)
49 #define va_nodeid       va_fileid
50 #define vnode_t         struct vnode
51 #define vSetType(vc, type)      AFSTOV(vc)->v_type = (type)
52 #define vSetVfsp(vc, vfsp)      AFSTOV(vc)->v_mount = (vfsp)
53 #define vType(vc)               (vc)->v->v_type
54
55 /* uio */
56 #define afsio_iov       uio_iov
57 #define afsio_iovcnt    uio_iovcnt
58 #define afsio_offset    uio_offset
59 #define afsio_resid     uio_resid
60 #define afsio_seg       uio_segflg
61 #define AFS_UIOSYS      UIO_SYSSPACE
62 #define AFS_UIOUSER     UIO_USERSPACE
63
64 /* malloc */
65 #define AFS_KALLOC(s)   afs_nbsd_Alloc(s)
66 #define AFS_KFREE(p, s) afs_nbsd_Free((p), (s))
67
68 /* proc, cred */
69 #define AFS_PROC        struct proc
70 #define AFS_UCRED       ucred
71 #define afs_suser()     afs_osi_suser(osi_curcred())
72 #define getpid()        curproc
73 #define osi_curcred()   (curproc->p_cred->pc_ucred)
74 #define osi_curproc()   curproc
75 #define p_rcred         p_ucred
76
77 /* time */
78 extern struct timeval time;
79 #define afs_hz          hz
80 #define osi_GetTime(x)  microtime(x)
81 #define osi_Time()      (time.tv_sec)
82
83 /* str */
84 #define afs_strcasecmp(s1, s2)  strncasecmp((s1), (s2), 65535)
85 #ifdef AFS_OBSD34_ENV
86 #define strcpy(s1, s2)          afs_strcpy((s1), (s2))
87 #define strcat(s1, s2)          afs_strcat((s1), (s2))
88 #else
89 #define afs_strcat(s1, s2)      strcat((s1), (s2))
90 #endif
91
92 /* other */
93 #define afs_bufferpages bufpages
94 #ifndef iodone
95 #define iodone biodone
96 #endif
97 #define PAGESIZE        8192
98 #define printk          printf  /* for RX version of xdr_* */
99 #define setgroups       sys_setgroups
100 #define UVM
101
102 /* This is not always in scope yet */
103 struct vcache;
104
105 extern int afs_nbsd_lookupname(char *fnamep, enum uio_seg segflg,
106                                int followlink, struct vnode **dirvpp,
107                                struct vnode **compvpp);
108 extern void afs_nbsd_getnewvnode(struct vcache *tvc);
109 extern void afs_nbsd_ref(struct vnode *);
110 extern void afs_nbsd_rele(struct vnode *);
111 extern void *afs_nbsd_Alloc(size_t asize);
112 extern void afs_nbsd_Free(void *p, size_t asize);
113 extern int afs_vget();
114
115 #define gop_lookupname(fnamep, segflg, followlink, dirvpp, compvpp) \
116         afs_nbsd_lookupname((fnamep), (segflg), (followlink), (dirvpp), (compvpp))
117
118 #ifdef KERNEL
119 extern int (**afs_vnodeop_p) ();
120
121 #ifdef AFS_GLOBAL_SUNLOCK
122 extern struct proc *afs_global_owner;
123 extern struct lock afs_global_lock;
124 #define AFS_GLOCK() \
125     do { \
126         osi_Assert(curproc); \
127         lockmgr(&afs_global_lock, LK_EXCLUSIVE, 0, curproc); \
128         osi_Assert(afs_global_owner == NULL); \
129         afs_global_owner = curproc; \
130     } while (0)
131 #define AFS_GUNLOCK() \
132     do { \
133         osi_Assert(curproc); \
134         osi_Assert(afs_global_owner == curproc); \
135         afs_global_owner = NULL; \
136         lockmgr(&afs_global_lock, LK_RELEASE, 0, curproc); \
137     } while(0)
138 #define ISAFS_GLOCK() (afs_global_owner == curproc && curproc)
139 #else
140 extern struct simplelock afs_global_lock;
141 #define AFS_GLOCK()
142 #define AFS_GUNLOCK()
143 #define AFS_ASSERT_GLOCK()
144 #define ISAFS_GLOCK() 1
145 #endif
146 #define AFS_RXGLOCK()
147 #define AFS_RXGUNLOCK()
148 #define ISAFS_RXGLOCK() 1
149
150 #undef SPLVAR
151 #define SPLVAR int splvar
152 #undef NETPRI
153 #define NETPRI splvar=splnet()
154 #undef USERPRI
155 #define USERPRI splx(splvar)
156 #endif /* KERNEL */
157
158 #endif /* _OSI_MACHDEP_H_ */