2 * SPDX-License-Identifier: BSD-2-Clause
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #ifndef _SYS_CCOMPAT_H
29 #define _SYS_CCOMPAT_H
31 #if __FreeBSD_version < 1300051
32 #define vm_page_valid(m) (m)->valid = VM_PAGE_BITS_ALL
33 #define vm_page_do_sunbusy(m)
34 #define vm_page_none_valid(m) ((m)->valid == 0)
36 #define vm_page_do_sunbusy(m) vm_page_sunbusy(m)
39 #if __FreeBSD_version < 1300074
40 #define VOP_UNLOCK1(x) VOP_UNLOCK(x, 0)
42 #define VOP_UNLOCK1(x) VOP_UNLOCK(x)
45 #if __FreeBSD_version < 1300064
46 #define VN_IS_DOOMED(vp) ((vp)->v_iflag & VI_DOOMED)
49 #if __FreeBSD_version < 1300068
50 #define VFS_VOP_VECTOR_REGISTER(x)
53 #if __FreeBSD_version >= 1300076
54 #define getnewvnode_reserve_() getnewvnode_reserve()
56 #define getnewvnode_reserve_() getnewvnode_reserve(1)
59 #if __FreeBSD_version < 1300102
60 #define ASSERT_VOP_IN_SEQC(zp)
61 #define MNTK_FPLOOKUP 0
62 #define vn_seqc_write_begin(vp)
63 #define vn_seqc_write_end(vp)
65 #ifndef VFS_SMR_DECLARE
66 #define VFS_SMR_DECLARE
68 #ifndef VFS_SMR_ZONE_SET
69 #define VFS_SMR_ZONE_SET(zone)
74 struct hlist_node
*next
, **pprev
;
78 struct hlist_node
*first
;
85 #define hlist_for_each(p, head) \
86 for (p = (head)->first; p; p = (p)->next)
88 #define hlist_entry(ptr, type, field) container_of(ptr, type, field)
90 #define container_of(ptr, type, member) \
93 const __typeof(((type *)0)->member) *__p = (ptr); \
94 (type *)((uintptr_t)__p - offsetof(type, member)); \
98 hlist_add_head(struct hlist_node
*n
, struct hlist_head
*h
)
101 if (h
->first
!= NULL
)
102 h
->first
->pprev
= &n
->next
;
103 WRITE_ONCE(h
->first
, n
);
104 n
->pprev
= &h
->first
;
108 hlist_del(struct hlist_node
*n
)
110 WRITE_ONCE(*(n
->pprev
), n
->next
);
112 n
->next
->pprev
= n
->pprev
;
115 #define READ_ONCE(x) ({ \
116 __typeof(x) __var = ({ \
124 #define HLIST_HEAD_INIT { }
125 #define HLIST_HEAD(name) struct hlist_head name = HLIST_HEAD_INIT
126 #define INIT_HLIST_HEAD(head) (head)->first = NULL
128 #define INIT_HLIST_NODE(node) \
130 (node)->next = NULL; \
131 (node)->pprev = NULL; \
136 atomic_read(const atomic_t
*v
)
138 return (READ_ONCE(v
->counter
));
142 atomic_inc(atomic_t
*v
)
144 return (atomic_fetchadd_int(&v
->counter
, 1) + 1);
148 atomic_dec(atomic_t
*v
)
150 return (atomic_fetchadd_int(&v
->counter
, -1) - 1);