lfs_accessors.h revision 1.11 1 1.11 dholland /* $NetBSD: lfs_accessors.h,v 1.11 2015/08/12 18:26:27 dholland Exp $ */
2 1.1 dholland
3 1.1 dholland /* from NetBSD: lfs.h,v 1.165 2015/07/24 06:59:32 dholland Exp */
4 1.1 dholland /* from NetBSD: dinode.h,v 1.22 2013/01/22 09:39:18 dholland Exp */
5 1.1 dholland /* from NetBSD: dir.h,v 1.21 2009/07/22 04:49:19 dholland Exp */
6 1.1 dholland
7 1.1 dholland /*-
8 1.1 dholland * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
9 1.1 dholland * All rights reserved.
10 1.1 dholland *
11 1.1 dholland * This code is derived from software contributed to The NetBSD Foundation
12 1.1 dholland * by Konrad E. Schroder <perseant (at) hhhh.org>.
13 1.1 dholland *
14 1.1 dholland * Redistribution and use in source and binary forms, with or without
15 1.1 dholland * modification, are permitted provided that the following conditions
16 1.1 dholland * are met:
17 1.1 dholland * 1. Redistributions of source code must retain the above copyright
18 1.1 dholland * notice, this list of conditions and the following disclaimer.
19 1.1 dholland * 2. Redistributions in binary form must reproduce the above copyright
20 1.1 dholland * notice, this list of conditions and the following disclaimer in the
21 1.1 dholland * documentation and/or other materials provided with the distribution.
22 1.1 dholland *
23 1.1 dholland * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24 1.1 dholland * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 1.1 dholland * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 1.1 dholland * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
27 1.1 dholland * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 1.1 dholland * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 1.1 dholland * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 1.1 dholland * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 1.1 dholland * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 1.1 dholland * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 1.1 dholland * POSSIBILITY OF SUCH DAMAGE.
34 1.1 dholland */
35 1.1 dholland /*-
36 1.1 dholland * Copyright (c) 1991, 1993
37 1.1 dholland * The Regents of the University of California. All rights reserved.
38 1.1 dholland *
39 1.1 dholland * Redistribution and use in source and binary forms, with or without
40 1.1 dholland * modification, are permitted provided that the following conditions
41 1.1 dholland * are met:
42 1.1 dholland * 1. Redistributions of source code must retain the above copyright
43 1.1 dholland * notice, this list of conditions and the following disclaimer.
44 1.1 dholland * 2. Redistributions in binary form must reproduce the above copyright
45 1.1 dholland * notice, this list of conditions and the following disclaimer in the
46 1.1 dholland * documentation and/or other materials provided with the distribution.
47 1.1 dholland * 3. Neither the name of the University nor the names of its contributors
48 1.1 dholland * may be used to endorse or promote products derived from this software
49 1.1 dholland * without specific prior written permission.
50 1.1 dholland *
51 1.1 dholland * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
52 1.1 dholland * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 1.1 dholland * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 1.1 dholland * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
55 1.1 dholland * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 1.1 dholland * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 1.1 dholland * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 1.1 dholland * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 1.1 dholland * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 1.1 dholland * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 1.1 dholland * SUCH DAMAGE.
62 1.1 dholland *
63 1.1 dholland * @(#)lfs.h 8.9 (Berkeley) 5/8/95
64 1.1 dholland */
65 1.1 dholland /*
66 1.1 dholland * Copyright (c) 2002 Networks Associates Technology, Inc.
67 1.1 dholland * All rights reserved.
68 1.1 dholland *
69 1.1 dholland * This software was developed for the FreeBSD Project by Marshall
70 1.1 dholland * Kirk McKusick and Network Associates Laboratories, the Security
71 1.1 dholland * Research Division of Network Associates, Inc. under DARPA/SPAWAR
72 1.1 dholland * contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA CHATS
73 1.1 dholland * research program
74 1.1 dholland *
75 1.1 dholland * Copyright (c) 1982, 1989, 1993
76 1.1 dholland * The Regents of the University of California. All rights reserved.
77 1.1 dholland * (c) UNIX System Laboratories, Inc.
78 1.1 dholland * All or some portions of this file are derived from material licensed
79 1.1 dholland * to the University of California by American Telephone and Telegraph
80 1.1 dholland * Co. or Unix System Laboratories, Inc. and are reproduced herein with
81 1.1 dholland * the permission of UNIX System Laboratories, Inc.
82 1.1 dholland *
83 1.1 dholland * Redistribution and use in source and binary forms, with or without
84 1.1 dholland * modification, are permitted provided that the following conditions
85 1.1 dholland * are met:
86 1.1 dholland * 1. Redistributions of source code must retain the above copyright
87 1.1 dholland * notice, this list of conditions and the following disclaimer.
88 1.1 dholland * 2. Redistributions in binary form must reproduce the above copyright
89 1.1 dholland * notice, this list of conditions and the following disclaimer in the
90 1.1 dholland * documentation and/or other materials provided with the distribution.
91 1.1 dholland * 3. Neither the name of the University nor the names of its contributors
92 1.1 dholland * may be used to endorse or promote products derived from this software
93 1.1 dholland * without specific prior written permission.
94 1.1 dholland *
95 1.1 dholland * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
96 1.1 dholland * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
97 1.1 dholland * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
98 1.1 dholland * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
99 1.1 dholland * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
100 1.1 dholland * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
101 1.1 dholland * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
102 1.1 dholland * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
103 1.1 dholland * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
104 1.1 dholland * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
105 1.1 dholland * SUCH DAMAGE.
106 1.1 dholland *
107 1.1 dholland * @(#)dinode.h 8.9 (Berkeley) 3/29/95
108 1.1 dholland */
109 1.1 dholland /*
110 1.1 dholland * Copyright (c) 1982, 1986, 1989, 1993
111 1.1 dholland * The Regents of the University of California. All rights reserved.
112 1.1 dholland * (c) UNIX System Laboratories, Inc.
113 1.1 dholland * All or some portions of this file are derived from material licensed
114 1.1 dholland * to the University of California by American Telephone and Telegraph
115 1.1 dholland * Co. or Unix System Laboratories, Inc. and are reproduced herein with
116 1.1 dholland * the permission of UNIX System Laboratories, Inc.
117 1.1 dholland *
118 1.1 dholland * Redistribution and use in source and binary forms, with or without
119 1.1 dholland * modification, are permitted provided that the following conditions
120 1.1 dholland * are met:
121 1.1 dholland * 1. Redistributions of source code must retain the above copyright
122 1.1 dholland * notice, this list of conditions and the following disclaimer.
123 1.1 dholland * 2. Redistributions in binary form must reproduce the above copyright
124 1.1 dholland * notice, this list of conditions and the following disclaimer in the
125 1.1 dholland * documentation and/or other materials provided with the distribution.
126 1.1 dholland * 3. Neither the name of the University nor the names of its contributors
127 1.1 dholland * may be used to endorse or promote products derived from this software
128 1.1 dholland * without specific prior written permission.
129 1.1 dholland *
130 1.1 dholland * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
131 1.1 dholland * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
132 1.1 dholland * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
133 1.1 dholland * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
134 1.1 dholland * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
135 1.1 dholland * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
136 1.1 dholland * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
137 1.1 dholland * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
138 1.1 dholland * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
139 1.1 dholland * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
140 1.1 dholland * SUCH DAMAGE.
141 1.1 dholland *
142 1.1 dholland * @(#)dir.h 8.5 (Berkeley) 4/27/95
143 1.1 dholland */
144 1.1 dholland
145 1.1 dholland #ifndef _UFS_LFS_LFS_ACCESSORS_H_
146 1.1 dholland #define _UFS_LFS_LFS_ACCESSORS_H_
147 1.1 dholland
148 1.11 dholland #if !defined(_KERNEL) && !defined(_STANDALONE)
149 1.11 dholland #include <assert.h>
150 1.11 dholland #define KASSERT assert
151 1.11 dholland #endif
152 1.11 dholland
153 1.1 dholland /*
154 1.9 dholland * STRUCT_LFS is used by the libsa code to get accessors that work
155 1.9 dholland * with struct salfs instead of struct lfs, and by the cleaner to
156 1.9 dholland * get accessors that work with struct clfs.
157 1.9 dholland */
158 1.9 dholland
159 1.9 dholland #ifndef STRUCT_LFS
160 1.9 dholland #define STRUCT_LFS struct lfs
161 1.9 dholland #endif
162 1.9 dholland
163 1.9 dholland
164 1.9 dholland /*
165 1.1 dholland * Maximum length of a symlink that can be stored within the inode.
166 1.1 dholland */
167 1.1 dholland #define ULFS1_MAXSYMLINKLEN ((ULFS_NDADDR + ULFS_NIADDR) * sizeof(int32_t))
168 1.1 dholland #define ULFS2_MAXSYMLINKLEN ((ULFS_NDADDR + ULFS_NIADDR) * sizeof(int64_t))
169 1.1 dholland
170 1.1 dholland #define ULFS_MAXSYMLINKLEN(ip) \
171 1.1 dholland ((ip)->i_ump->um_fstype == ULFS1) ? \
172 1.1 dholland ULFS1_MAXSYMLINKLEN : ULFS2_MAXSYMLINKLEN
173 1.1 dholland
174 1.1 dholland /*
175 1.1 dholland * "struct buf" associated definitions
176 1.1 dholland */
177 1.1 dholland
178 1.1 dholland # define LFS_LOCK_BUF(bp) do { \
179 1.1 dholland if (((bp)->b_flags & B_LOCKED) == 0 && bp->b_iodone == NULL) { \
180 1.1 dholland mutex_enter(&lfs_lock); \
181 1.1 dholland ++locked_queue_count; \
182 1.1 dholland locked_queue_bytes += bp->b_bufsize; \
183 1.1 dholland mutex_exit(&lfs_lock); \
184 1.1 dholland } \
185 1.1 dholland (bp)->b_flags |= B_LOCKED; \
186 1.1 dholland } while (0)
187 1.1 dholland
188 1.1 dholland # define LFS_UNLOCK_BUF(bp) do { \
189 1.1 dholland if (((bp)->b_flags & B_LOCKED) != 0 && bp->b_iodone == NULL) { \
190 1.1 dholland mutex_enter(&lfs_lock); \
191 1.1 dholland --locked_queue_count; \
192 1.1 dholland locked_queue_bytes -= bp->b_bufsize; \
193 1.1 dholland if (locked_queue_count < LFS_WAIT_BUFS && \
194 1.1 dholland locked_queue_bytes < LFS_WAIT_BYTES) \
195 1.1 dholland cv_broadcast(&locked_queue_cv); \
196 1.1 dholland mutex_exit(&lfs_lock); \
197 1.1 dholland } \
198 1.1 dholland (bp)->b_flags &= ~B_LOCKED; \
199 1.1 dholland } while (0)
200 1.1 dholland
201 1.1 dholland /*
202 1.1 dholland * "struct inode" associated definitions
203 1.1 dholland */
204 1.1 dholland
205 1.1 dholland #define LFS_SET_UINO(ip, flags) do { \
206 1.1 dholland if (((flags) & IN_ACCESSED) && !((ip)->i_flag & IN_ACCESSED)) \
207 1.1 dholland lfs_sb_adduinodes((ip)->i_lfs, 1); \
208 1.1 dholland if (((flags) & IN_CLEANING) && !((ip)->i_flag & IN_CLEANING)) \
209 1.1 dholland lfs_sb_adduinodes((ip)->i_lfs, 1); \
210 1.1 dholland if (((flags) & IN_MODIFIED) && !((ip)->i_flag & IN_MODIFIED)) \
211 1.1 dholland lfs_sb_adduinodes((ip)->i_lfs, 1); \
212 1.1 dholland (ip)->i_flag |= (flags); \
213 1.1 dholland } while (0)
214 1.1 dholland
215 1.1 dholland #define LFS_CLR_UINO(ip, flags) do { \
216 1.1 dholland if (((flags) & IN_ACCESSED) && ((ip)->i_flag & IN_ACCESSED)) \
217 1.1 dholland lfs_sb_subuinodes((ip)->i_lfs, 1); \
218 1.1 dholland if (((flags) & IN_CLEANING) && ((ip)->i_flag & IN_CLEANING)) \
219 1.1 dholland lfs_sb_subuinodes((ip)->i_lfs, 1); \
220 1.1 dholland if (((flags) & IN_MODIFIED) && ((ip)->i_flag & IN_MODIFIED)) \
221 1.1 dholland lfs_sb_subuinodes((ip)->i_lfs, 1); \
222 1.1 dholland (ip)->i_flag &= ~(flags); \
223 1.1 dholland if (lfs_sb_getuinodes((ip)->i_lfs) < 0) { \
224 1.1 dholland panic("lfs_uinodes < 0"); \
225 1.1 dholland } \
226 1.1 dholland } while (0)
227 1.1 dholland
228 1.1 dholland #define LFS_ITIMES(ip, acc, mod, cre) \
229 1.1 dholland while ((ip)->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE | IN_MODIFY)) \
230 1.1 dholland lfs_itimes(ip, acc, mod, cre)
231 1.1 dholland
232 1.1 dholland /*
233 1.1 dholland * On-disk and in-memory checkpoint segment usage structure.
234 1.1 dholland */
235 1.1 dholland
236 1.1 dholland #define SEGUPB(fs) (lfs_sb_getsepb(fs))
237 1.1 dholland #define SEGTABSIZE_SU(fs) \
238 1.1 dholland ((lfs_sb_getnseg(fs) + SEGUPB(fs) - 1) / lfs_sb_getsepb(fs))
239 1.1 dholland
240 1.1 dholland #ifdef _KERNEL
241 1.1 dholland # define SHARE_IFLOCK(F) \
242 1.1 dholland do { \
243 1.1 dholland rw_enter(&(F)->lfs_iflock, RW_READER); \
244 1.1 dholland } while(0)
245 1.1 dholland # define UNSHARE_IFLOCK(F) \
246 1.1 dholland do { \
247 1.1 dholland rw_exit(&(F)->lfs_iflock); \
248 1.1 dholland } while(0)
249 1.1 dholland #else /* ! _KERNEL */
250 1.1 dholland # define SHARE_IFLOCK(F)
251 1.1 dholland # define UNSHARE_IFLOCK(F)
252 1.1 dholland #endif /* ! _KERNEL */
253 1.1 dholland
254 1.1 dholland /* Read in the block with a specific segment usage entry from the ifile. */
255 1.1 dholland #define LFS_SEGENTRY(SP, F, IN, BP) do { \
256 1.1 dholland int _e; \
257 1.1 dholland SHARE_IFLOCK(F); \
258 1.1 dholland VTOI((F)->lfs_ivnode)->i_flag |= IN_ACCESS; \
259 1.1 dholland if ((_e = bread((F)->lfs_ivnode, \
260 1.1 dholland ((IN) / lfs_sb_getsepb(F)) + lfs_sb_getcleansz(F), \
261 1.1 dholland lfs_sb_getbsize(F), 0, &(BP))) != 0) \
262 1.1 dholland panic("lfs: ifile read: %d", _e); \
263 1.6 dholland if (lfs_sb_getversion(F) == 1) \
264 1.1 dholland (SP) = (SEGUSE *)((SEGUSE_V1 *)(BP)->b_data + \
265 1.1 dholland ((IN) & (lfs_sb_getsepb(F) - 1))); \
266 1.1 dholland else \
267 1.1 dholland (SP) = (SEGUSE *)(BP)->b_data + ((IN) % lfs_sb_getsepb(F)); \
268 1.1 dholland UNSHARE_IFLOCK(F); \
269 1.1 dholland } while (0)
270 1.1 dholland
271 1.1 dholland #define LFS_WRITESEGENTRY(SP, F, IN, BP) do { \
272 1.1 dholland if ((SP)->su_nbytes == 0) \
273 1.1 dholland (SP)->su_flags |= SEGUSE_EMPTY; \
274 1.1 dholland else \
275 1.1 dholland (SP)->su_flags &= ~SEGUSE_EMPTY; \
276 1.1 dholland (F)->lfs_suflags[(F)->lfs_activesb][(IN)] = (SP)->su_flags; \
277 1.1 dholland LFS_BWRITE_LOG(BP); \
278 1.1 dholland } while (0)
279 1.1 dholland
280 1.1 dholland /*
281 1.11 dholland * FINFO (file info) entries.
282 1.11 dholland */
283 1.11 dholland
284 1.11 dholland /* Size of an on-disk block pointer, e.g. in an indirect block. */
285 1.11 dholland /* XXX: move to a more suitable location in this file */
286 1.11 dholland #define LFS_BLKPTRSIZE(fs) ((fs)->lfs_is64 ? sizeof(int64_t) : sizeof(int32_t))
287 1.11 dholland
288 1.11 dholland /* Full size of the provided FINFO record, including its block pointers. */
289 1.11 dholland #define FINFO_FULLSIZE(fs, fip) \
290 1.11 dholland (FINFOSIZE + (fip)->fi_nblocks * LFS_BLKPTRSIZE(fs))
291 1.11 dholland
292 1.11 dholland #define NEXT_FINFO(fs, fip) \
293 1.11 dholland ((FINFO *)((char *)(fip) + FINFO_FULLSIZE(fs, fip)))
294 1.11 dholland
295 1.11 dholland /*
296 1.1 dholland * Index file inode entries.
297 1.1 dholland */
298 1.1 dholland
299 1.1 dholland /*
300 1.1 dholland * LFSv1 compatibility code is not allowed to touch if_atime, since it
301 1.1 dholland * may not be mapped!
302 1.1 dholland */
303 1.1 dholland /* Read in the block with a specific inode from the ifile. */
304 1.1 dholland #define LFS_IENTRY(IP, F, IN, BP) do { \
305 1.1 dholland int _e; \
306 1.1 dholland SHARE_IFLOCK(F); \
307 1.1 dholland VTOI((F)->lfs_ivnode)->i_flag |= IN_ACCESS; \
308 1.1 dholland if ((_e = bread((F)->lfs_ivnode, \
309 1.1 dholland (IN) / lfs_sb_getifpb(F) + lfs_sb_getcleansz(F) + lfs_sb_getsegtabsz(F), \
310 1.1 dholland lfs_sb_getbsize(F), 0, &(BP))) != 0) \
311 1.1 dholland panic("lfs: ifile ino %d read %d", (int)(IN), _e); \
312 1.10 dholland if ((F)->lfs_is64) { \
313 1.10 dholland (IP) = (IFILE *)((IFILE64 *)(BP)->b_data + \
314 1.10 dholland (IN) % lfs_sb_getifpb(F)); \
315 1.10 dholland } else if (lfs_sb_getversion(F) > 1) { \
316 1.10 dholland (IP) = (IFILE *)((IFILE32 *)(BP)->b_data + \
317 1.10 dholland (IN) % lfs_sb_getifpb(F)); \
318 1.10 dholland } else { \
319 1.1 dholland (IP) = (IFILE *)((IFILE_V1 *)(BP)->b_data + \
320 1.1 dholland (IN) % lfs_sb_getifpb(F)); \
321 1.10 dholland } \
322 1.1 dholland UNSHARE_IFLOCK(F); \
323 1.1 dholland } while (0)
324 1.1 dholland
325 1.10 dholland #define LFS_DEF_IF_ACCESSOR(type, type32, field) \
326 1.10 dholland static __unused inline type \
327 1.10 dholland lfs_if_get##field(STRUCT_LFS *fs, IFILE *ifp) \
328 1.10 dholland { \
329 1.10 dholland if (fs->lfs_is64) { \
330 1.10 dholland return ifp->u_64.if_##field; \
331 1.10 dholland } else { \
332 1.10 dholland return ifp->u_32.if_##field; \
333 1.10 dholland } \
334 1.10 dholland } \
335 1.10 dholland static __unused inline void \
336 1.10 dholland lfs_if_set##field(STRUCT_LFS *fs, IFILE *ifp, type val) \
337 1.10 dholland { \
338 1.10 dholland if (fs->lfs_is64) { \
339 1.10 dholland type *p = &ifp->u_64.if_##field; \
340 1.10 dholland (void)p; \
341 1.10 dholland ifp->u_64.if_##field = val; \
342 1.10 dholland } else { \
343 1.10 dholland type32 *p = &ifp->u_32.if_##field; \
344 1.10 dholland (void)p; \
345 1.10 dholland ifp->u_32.if_##field = val; \
346 1.10 dholland } \
347 1.10 dholland } \
348 1.10 dholland
349 1.10 dholland LFS_DEF_IF_ACCESSOR(u_int32_t, u_int32_t, version);
350 1.10 dholland LFS_DEF_IF_ACCESSOR(int64_t, int32_t, daddr);
351 1.10 dholland LFS_DEF_IF_ACCESSOR(u_int64_t, u_int32_t, nextfree);
352 1.10 dholland LFS_DEF_IF_ACCESSOR(u_int32_t, u_int32_t, atime_sec);
353 1.10 dholland LFS_DEF_IF_ACCESSOR(u_int32_t, u_int32_t, atime_nsec);
354 1.10 dholland
355 1.1 dholland /*
356 1.1 dholland * Cleaner information structure. This resides in the ifile and is used
357 1.1 dholland * to pass information from the kernel to the cleaner.
358 1.1 dholland */
359 1.1 dholland
360 1.1 dholland #define CLEANSIZE_SU(fs) \
361 1.9 dholland ((((fs)->lfs_is64 ? sizeof(CLEANERINFO64) : sizeof(CLEANERINFO32)) + \
362 1.9 dholland lfs_sb_getbsize(fs) - 1) >> lfs_sb_getbshift(fs))
363 1.9 dholland
364 1.9 dholland #define LFS_DEF_CI_ACCESSOR(type, type32, field) \
365 1.9 dholland static __unused inline type \
366 1.9 dholland lfs_ci_get##field(STRUCT_LFS *fs, CLEANERINFO *cip) \
367 1.9 dholland { \
368 1.9 dholland if (fs->lfs_is64) { \
369 1.9 dholland return cip->u_64.field; \
370 1.9 dholland } else { \
371 1.9 dholland return cip->u_32.field; \
372 1.9 dholland } \
373 1.9 dholland } \
374 1.9 dholland static __unused inline void \
375 1.9 dholland lfs_ci_set##field(STRUCT_LFS *fs, CLEANERINFO *cip, type val) \
376 1.9 dholland { \
377 1.9 dholland if (fs->lfs_is64) { \
378 1.9 dholland type *p = &cip->u_64.field; \
379 1.9 dholland (void)p; \
380 1.9 dholland cip->u_64.field = val; \
381 1.9 dholland } else { \
382 1.9 dholland type32 *p = &cip->u_32.field; \
383 1.9 dholland (void)p; \
384 1.9 dholland cip->u_32.field = val; \
385 1.9 dholland } \
386 1.9 dholland } \
387 1.9 dholland
388 1.9 dholland LFS_DEF_CI_ACCESSOR(u_int32_t, u_int32_t, clean);
389 1.9 dholland LFS_DEF_CI_ACCESSOR(u_int32_t, u_int32_t, dirty);
390 1.9 dholland LFS_DEF_CI_ACCESSOR(int64_t, int32_t, bfree);
391 1.9 dholland LFS_DEF_CI_ACCESSOR(int64_t, int32_t, avail);
392 1.9 dholland LFS_DEF_CI_ACCESSOR(u_int64_t, u_int32_t, free_head);
393 1.9 dholland LFS_DEF_CI_ACCESSOR(u_int64_t, u_int32_t, free_tail);
394 1.9 dholland LFS_DEF_CI_ACCESSOR(u_int32_t, u_int32_t, flags);
395 1.9 dholland
396 1.9 dholland static __unused inline void
397 1.9 dholland lfs_ci_shiftcleantodirty(STRUCT_LFS *fs, CLEANERINFO *cip, unsigned num)
398 1.9 dholland {
399 1.9 dholland lfs_ci_setclean(fs, cip, lfs_ci_getclean(fs, cip) - num);
400 1.9 dholland lfs_ci_setdirty(fs, cip, lfs_ci_getdirty(fs, cip) + num);
401 1.9 dholland }
402 1.9 dholland
403 1.9 dholland static __unused inline void
404 1.9 dholland lfs_ci_shiftdirtytoclean(STRUCT_LFS *fs, CLEANERINFO *cip, unsigned num)
405 1.9 dholland {
406 1.9 dholland lfs_ci_setdirty(fs, cip, lfs_ci_getdirty(fs, cip) - num);
407 1.9 dholland lfs_ci_setclean(fs, cip, lfs_ci_getclean(fs, cip) + num);
408 1.9 dholland }
409 1.1 dholland
410 1.1 dholland /* Read in the block with the cleaner info from the ifile. */
411 1.1 dholland #define LFS_CLEANERINFO(CP, F, BP) do { \
412 1.1 dholland SHARE_IFLOCK(F); \
413 1.1 dholland VTOI((F)->lfs_ivnode)->i_flag |= IN_ACCESS; \
414 1.1 dholland if (bread((F)->lfs_ivnode, \
415 1.1 dholland (daddr_t)0, lfs_sb_getbsize(F), 0, &(BP))) \
416 1.1 dholland panic("lfs: ifile read"); \
417 1.1 dholland (CP) = (CLEANERINFO *)(BP)->b_data; \
418 1.1 dholland UNSHARE_IFLOCK(F); \
419 1.1 dholland } while (0)
420 1.1 dholland
421 1.1 dholland /*
422 1.1 dholland * Synchronize the Ifile cleaner info with current avail and bfree.
423 1.1 dholland */
424 1.1 dholland #define LFS_SYNC_CLEANERINFO(cip, fs, bp, w) do { \
425 1.1 dholland mutex_enter(&lfs_lock); \
426 1.9 dholland if ((w) || lfs_ci_getbfree(fs, cip) != lfs_sb_getbfree(fs) || \
427 1.9 dholland lfs_ci_getavail(fs, cip) != lfs_sb_getavail(fs) - fs->lfs_ravail - \
428 1.1 dholland fs->lfs_favail) { \
429 1.9 dholland lfs_ci_setbfree(fs, cip, lfs_sb_getbfree(fs)); \
430 1.9 dholland lfs_ci_setavail(fs, cip, lfs_sb_getavail(fs) - fs->lfs_ravail - \
431 1.9 dholland fs->lfs_favail); \
432 1.1 dholland if (((bp)->b_flags & B_GATHERED) == 0) { \
433 1.1 dholland fs->lfs_flags |= LFS_IFDIRTY; \
434 1.1 dholland } \
435 1.1 dholland mutex_exit(&lfs_lock); \
436 1.1 dholland (void) LFS_BWRITE_LOG(bp); /* Ifile */ \
437 1.1 dholland } else { \
438 1.1 dholland mutex_exit(&lfs_lock); \
439 1.1 dholland brelse(bp, 0); \
440 1.1 dholland } \
441 1.1 dholland } while (0)
442 1.1 dholland
443 1.1 dholland /*
444 1.1 dholland * Get the head of the inode free list.
445 1.1 dholland * Always called with the segment lock held.
446 1.1 dholland */
447 1.1 dholland #define LFS_GET_HEADFREE(FS, CIP, BP, FREEP) do { \
448 1.6 dholland if (lfs_sb_getversion(FS) > 1) { \
449 1.1 dholland LFS_CLEANERINFO((CIP), (FS), (BP)); \
450 1.9 dholland lfs_sb_setfreehd(FS, lfs_ci_getfree_head(FS, CIP)); \
451 1.1 dholland brelse(BP, 0); \
452 1.1 dholland } \
453 1.1 dholland *(FREEP) = lfs_sb_getfreehd(FS); \
454 1.1 dholland } while (0)
455 1.1 dholland
456 1.1 dholland #define LFS_PUT_HEADFREE(FS, CIP, BP, VAL) do { \
457 1.1 dholland lfs_sb_setfreehd(FS, VAL); \
458 1.6 dholland if (lfs_sb_getversion(FS) > 1) { \
459 1.1 dholland LFS_CLEANERINFO((CIP), (FS), (BP)); \
460 1.9 dholland lfs_ci_setfree_head(FS, CIP, VAL); \
461 1.1 dholland LFS_BWRITE_LOG(BP); \
462 1.1 dholland mutex_enter(&lfs_lock); \
463 1.1 dholland (FS)->lfs_flags |= LFS_IFDIRTY; \
464 1.1 dholland mutex_exit(&lfs_lock); \
465 1.1 dholland } \
466 1.1 dholland } while (0)
467 1.1 dholland
468 1.1 dholland #define LFS_GET_TAILFREE(FS, CIP, BP, FREEP) do { \
469 1.1 dholland LFS_CLEANERINFO((CIP), (FS), (BP)); \
470 1.9 dholland *(FREEP) = lfs_ci_getfree_tail(FS, CIP); \
471 1.1 dholland brelse(BP, 0); \
472 1.1 dholland } while (0)
473 1.1 dholland
474 1.1 dholland #define LFS_PUT_TAILFREE(FS, CIP, BP, VAL) do { \
475 1.1 dholland LFS_CLEANERINFO((CIP), (FS), (BP)); \
476 1.9 dholland lfs_ci_setfree_tail(FS, CIP, VAL); \
477 1.1 dholland LFS_BWRITE_LOG(BP); \
478 1.1 dholland mutex_enter(&lfs_lock); \
479 1.1 dholland (FS)->lfs_flags |= LFS_IFDIRTY; \
480 1.1 dholland mutex_exit(&lfs_lock); \
481 1.1 dholland } while (0)
482 1.1 dholland
483 1.1 dholland /*
484 1.1 dholland * On-disk segment summary information
485 1.1 dholland */
486 1.1 dholland
487 1.11 dholland #define SEGSUM_SIZE(fs) \
488 1.11 dholland (fs->lfs_is64 ? sizeof(SEGSUM64) : \
489 1.11 dholland lfs_sb_getversion(fs) > 1 ? sizeof(SEGSUM32) : sizeof(SEGSUM_V1))
490 1.11 dholland
491 1.11 dholland /*
492 1.11 dholland * The SEGSUM structure is followed by FINFO structures. Get the pointer
493 1.11 dholland * to the first FINFO.
494 1.11 dholland *
495 1.11 dholland * XXX this can't be a macro yet; this file needs to be resorted.
496 1.11 dholland */
497 1.11 dholland #if 0
498 1.11 dholland static __unused inline FINFO *
499 1.11 dholland segsum_finfobase(STRUCT_LFS *fs, SEGSUM *ssp)
500 1.11 dholland {
501 1.11 dholland return (FINFO *)((char *)ssp) + SEGSUM_SIZE(fs);
502 1.11 dholland }
503 1.11 dholland #else
504 1.11 dholland #define SEGSUM_FINFOBASE(fs, ssp) \
505 1.11 dholland ((FINFO *)((char *)(ssp)) + SEGSUM_SIZE(fs));
506 1.11 dholland #endif
507 1.11 dholland
508 1.11 dholland #define LFS_DEF_SS_ACCESSOR(type, type32, field) \
509 1.11 dholland static __unused inline type \
510 1.11 dholland lfs_ss_get##field(STRUCT_LFS *fs, SEGSUM *ssp) \
511 1.11 dholland { \
512 1.11 dholland if (fs->lfs_is64) { \
513 1.11 dholland return ssp->u_64.ss_##field; \
514 1.11 dholland } else { \
515 1.11 dholland return ssp->u_32.ss_##field; \
516 1.11 dholland } \
517 1.11 dholland } \
518 1.11 dholland static __unused inline void \
519 1.11 dholland lfs_ss_set##field(STRUCT_LFS *fs, SEGSUM *ssp, type val) \
520 1.11 dholland { \
521 1.11 dholland if (fs->lfs_is64) { \
522 1.11 dholland type *p = &ssp->u_64.ss_##field; \
523 1.11 dholland (void)p; \
524 1.11 dholland ssp->u_64.ss_##field = val; \
525 1.11 dholland } else { \
526 1.11 dholland type32 *p = &ssp->u_32.ss_##field; \
527 1.11 dholland (void)p; \
528 1.11 dholland ssp->u_32.ss_##field = val; \
529 1.11 dholland } \
530 1.11 dholland } \
531 1.11 dholland
532 1.11 dholland LFS_DEF_SS_ACCESSOR(uint32_t, uint32_t, sumsum);
533 1.11 dholland LFS_DEF_SS_ACCESSOR(uint32_t, uint32_t, datasum);
534 1.11 dholland LFS_DEF_SS_ACCESSOR(uint32_t, uint32_t, magic);
535 1.11 dholland LFS_DEF_SS_ACCESSOR(uint32_t, uint32_t, ident);
536 1.11 dholland LFS_DEF_SS_ACCESSOR(int64_t, int32_t, next);
537 1.11 dholland LFS_DEF_SS_ACCESSOR(uint16_t, uint16_t, nfinfo);
538 1.11 dholland LFS_DEF_SS_ACCESSOR(uint16_t, uint16_t, ninos);
539 1.11 dholland LFS_DEF_SS_ACCESSOR(uint16_t, uint16_t, flags);
540 1.11 dholland LFS_DEF_SS_ACCESSOR(uint64_t, uint32_t, reclino);
541 1.11 dholland LFS_DEF_SS_ACCESSOR(uint64_t, uint64_t, serial);
542 1.11 dholland LFS_DEF_SS_ACCESSOR(uint64_t, uint64_t, create);
543 1.11 dholland
544 1.11 dholland static __unused inline size_t
545 1.11 dholland lfs_ss_getsumstart(STRUCT_LFS *fs)
546 1.11 dholland {
547 1.11 dholland /* These are actually all the same. */
548 1.11 dholland if (fs->lfs_is64) {
549 1.11 dholland return offsetof(SEGSUM64, ss_datasum);
550 1.11 dholland } else /* if (lfs_sb_getversion(fs) > 1) */ {
551 1.11 dholland return offsetof(SEGSUM32, ss_datasum);
552 1.11 dholland } /* else {
553 1.11 dholland return offsetof(SEGSUM_V1, ss_datasum);
554 1.11 dholland } */
555 1.11 dholland /*
556 1.11 dholland * XXX ^^^ until this file is resorted lfs_sb_getversion isn't
557 1.11 dholland * defined yet.
558 1.11 dholland */
559 1.11 dholland }
560 1.11 dholland
561 1.11 dholland static __unused inline uint32_t
562 1.11 dholland lfs_ss_getocreate(STRUCT_LFS *fs, SEGSUM *ssp)
563 1.11 dholland {
564 1.11 dholland KASSERT(fs->lfs_is64 == 0);
565 1.11 dholland /* XXX need to resort this file before we can do this */
566 1.11 dholland //KASSERT(lfs_sb_getversion(fs) == 1);
567 1.11 dholland
568 1.11 dholland return ssp->u_v1.ss_create;
569 1.11 dholland }
570 1.11 dholland
571 1.11 dholland static __unused inline void
572 1.11 dholland lfs_ss_setocreate(STRUCT_LFS *fs, SEGSUM *ssp, uint32_t val)
573 1.11 dholland {
574 1.11 dholland KASSERT(fs->lfs_is64 == 0);
575 1.11 dholland /* XXX need to resort this file before we can do this */
576 1.11 dholland //KASSERT(lfs_sb_getversion(fs) == 1);
577 1.11 dholland
578 1.11 dholland ssp->u_v1.ss_create = val;
579 1.11 dholland }
580 1.11 dholland
581 1.1 dholland
582 1.1 dholland /*
583 1.1 dholland * Super block.
584 1.1 dholland */
585 1.1 dholland
586 1.1 dholland /*
587 1.1 dholland * Generate accessors for the on-disk superblock fields with cpp.
588 1.1 dholland */
589 1.1 dholland
590 1.3 dholland #define LFS_DEF_SB_ACCESSOR_FULL(type, type32, field) \
591 1.1 dholland static __unused inline type \
592 1.1 dholland lfs_sb_get##field(STRUCT_LFS *fs) \
593 1.1 dholland { \
594 1.7 dholland if (fs->lfs_is64) { \
595 1.7 dholland return fs->lfs_dlfs_u.u_64.dlfs_##field; \
596 1.7 dholland } else { \
597 1.7 dholland return fs->lfs_dlfs_u.u_32.dlfs_##field; \
598 1.7 dholland } \
599 1.1 dholland } \
600 1.1 dholland static __unused inline void \
601 1.1 dholland lfs_sb_set##field(STRUCT_LFS *fs, type val) \
602 1.1 dholland { \
603 1.7 dholland if (fs->lfs_is64) { \
604 1.7 dholland fs->lfs_dlfs_u.u_64.dlfs_##field = val; \
605 1.7 dholland } else { \
606 1.7 dholland fs->lfs_dlfs_u.u_32.dlfs_##field = val; \
607 1.7 dholland } \
608 1.1 dholland } \
609 1.1 dholland static __unused inline void \
610 1.1 dholland lfs_sb_add##field(STRUCT_LFS *fs, type val) \
611 1.1 dholland { \
612 1.7 dholland if (fs->lfs_is64) { \
613 1.7 dholland type *p64 = &fs->lfs_dlfs_u.u_64.dlfs_##field; \
614 1.7 dholland *p64 += val; \
615 1.7 dholland } else { \
616 1.7 dholland type32 *p32 = &fs->lfs_dlfs_u.u_32.dlfs_##field; \
617 1.7 dholland *p32 += val; \
618 1.7 dholland } \
619 1.1 dholland } \
620 1.1 dholland static __unused inline void \
621 1.1 dholland lfs_sb_sub##field(STRUCT_LFS *fs, type val) \
622 1.1 dholland { \
623 1.7 dholland if (fs->lfs_is64) { \
624 1.7 dholland type *p64 = &fs->lfs_dlfs_u.u_64.dlfs_##field; \
625 1.7 dholland *p64 -= val; \
626 1.7 dholland } else { \
627 1.7 dholland type32 *p32 = &fs->lfs_dlfs_u.u_32.dlfs_##field; \
628 1.7 dholland *p32 -= val; \
629 1.7 dholland } \
630 1.1 dholland }
631 1.1 dholland
632 1.3 dholland #define LFS_DEF_SB_ACCESSOR(t, f) LFS_DEF_SB_ACCESSOR_FULL(t, t, f)
633 1.3 dholland
634 1.7 dholland #define LFS_DEF_SB_ACCESSOR_32ONLY(type, field, val64) \
635 1.7 dholland static __unused inline type \
636 1.7 dholland lfs_sb_get##field(STRUCT_LFS *fs) \
637 1.7 dholland { \
638 1.7 dholland if (fs->lfs_is64) { \
639 1.7 dholland return val64; \
640 1.7 dholland } else { \
641 1.7 dholland return fs->lfs_dlfs_u.u_32.dlfs_##field; \
642 1.7 dholland } \
643 1.7 dholland }
644 1.7 dholland
645 1.1 dholland #define lfs_magic lfs_dlfs.dlfs_magic
646 1.6 dholland LFS_DEF_SB_ACCESSOR(u_int32_t, version);
647 1.3 dholland LFS_DEF_SB_ACCESSOR_FULL(u_int64_t, u_int32_t, size);
648 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int32_t, ssize);
649 1.4 dholland LFS_DEF_SB_ACCESSOR_FULL(u_int64_t, u_int32_t, dsize);
650 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int32_t, bsize);
651 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int32_t, fsize);
652 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int32_t, frag);
653 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int32_t, freehd);
654 1.4 dholland LFS_DEF_SB_ACCESSOR_FULL(int64_t, int32_t, bfree);
655 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int32_t, nfiles);
656 1.4 dholland LFS_DEF_SB_ACCESSOR_FULL(int64_t, int32_t, avail);
657 1.1 dholland LFS_DEF_SB_ACCESSOR(int32_t, uinodes);
658 1.5 dholland LFS_DEF_SB_ACCESSOR_FULL(int64_t, int32_t, idaddr);
659 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int32_t, ifile);
660 1.5 dholland LFS_DEF_SB_ACCESSOR_FULL(int64_t, int32_t, lastseg);
661 1.5 dholland LFS_DEF_SB_ACCESSOR_FULL(int64_t, int32_t, nextseg);
662 1.5 dholland LFS_DEF_SB_ACCESSOR_FULL(int64_t, int32_t, curseg);
663 1.5 dholland LFS_DEF_SB_ACCESSOR_FULL(int64_t, int32_t, offset);
664 1.5 dholland LFS_DEF_SB_ACCESSOR_FULL(int64_t, int32_t, lastpseg);
665 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int32_t, inopf);
666 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int32_t, minfree);
667 1.1 dholland LFS_DEF_SB_ACCESSOR(uint64_t, maxfilesize);
668 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int32_t, fsbpseg);
669 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int32_t, inopb);
670 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int32_t, ifpb);
671 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int32_t, sepb);
672 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int32_t, nindir);
673 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int32_t, nseg);
674 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int32_t, nspf);
675 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int32_t, cleansz);
676 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int32_t, segtabsz);
677 1.7 dholland LFS_DEF_SB_ACCESSOR_32ONLY(u_int32_t, segmask, 0);
678 1.7 dholland LFS_DEF_SB_ACCESSOR_32ONLY(u_int32_t, segshift, 0);
679 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int64_t, bmask);
680 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int32_t, bshift);
681 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int64_t, ffmask);
682 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int32_t, ffshift);
683 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int64_t, fbmask);
684 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int32_t, fbshift);
685 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int32_t, blktodb);
686 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int32_t, fsbtodb);
687 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int32_t, sushift);
688 1.1 dholland LFS_DEF_SB_ACCESSOR(int32_t, maxsymlinklen);
689 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int32_t, cksum);
690 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int16_t, pflags);
691 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int32_t, nclean);
692 1.1 dholland LFS_DEF_SB_ACCESSOR(int32_t, dmeta);
693 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int32_t, minfreeseg);
694 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int32_t, sumsize);
695 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int64_t, serial);
696 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int32_t, ibsize);
697 1.5 dholland LFS_DEF_SB_ACCESSOR_FULL(int64_t, int32_t, s0addr);
698 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int64_t, tstamp);
699 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int32_t, inodefmt);
700 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int32_t, interleave);
701 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int32_t, ident);
702 1.1 dholland LFS_DEF_SB_ACCESSOR(u_int32_t, resvseg);
703 1.1 dholland
704 1.1 dholland /* special-case accessors */
705 1.1 dholland
706 1.1 dholland /*
707 1.1 dholland * the v1 otstamp field lives in what's now dlfs_inopf
708 1.1 dholland */
709 1.1 dholland #define lfs_sb_getotstamp(fs) lfs_sb_getinopf(fs)
710 1.1 dholland #define lfs_sb_setotstamp(fs, val) lfs_sb_setinopf(fs, val)
711 1.1 dholland
712 1.1 dholland /*
713 1.1 dholland * lfs_sboffs is an array
714 1.1 dholland */
715 1.1 dholland static __unused inline int32_t
716 1.2 dholland lfs_sb_getsboff(STRUCT_LFS *fs, unsigned n)
717 1.1 dholland {
718 1.1 dholland #ifdef KASSERT /* ugh */
719 1.1 dholland KASSERT(n < LFS_MAXNUMSB);
720 1.1 dholland #endif
721 1.7 dholland if (fs->lfs_is64) {
722 1.7 dholland return fs->lfs_dlfs_u.u_64.dlfs_sboffs[n];
723 1.7 dholland } else {
724 1.7 dholland return fs->lfs_dlfs_u.u_32.dlfs_sboffs[n];
725 1.7 dholland }
726 1.1 dholland }
727 1.1 dholland static __unused inline void
728 1.2 dholland lfs_sb_setsboff(STRUCT_LFS *fs, unsigned n, int32_t val)
729 1.1 dholland {
730 1.1 dholland #ifdef KASSERT /* ugh */
731 1.1 dholland KASSERT(n < LFS_MAXNUMSB);
732 1.1 dholland #endif
733 1.7 dholland if (fs->lfs_is64) {
734 1.7 dholland fs->lfs_dlfs_u.u_64.dlfs_sboffs[n] = val;
735 1.7 dholland } else {
736 1.7 dholland fs->lfs_dlfs_u.u_32.dlfs_sboffs[n] = val;
737 1.7 dholland }
738 1.1 dholland }
739 1.1 dholland
740 1.1 dholland /*
741 1.1 dholland * lfs_fsmnt is a string
742 1.1 dholland */
743 1.1 dholland static __unused inline const char *
744 1.2 dholland lfs_sb_getfsmnt(STRUCT_LFS *fs)
745 1.1 dholland {
746 1.7 dholland if (fs->lfs_is64) {
747 1.7 dholland return fs->lfs_dlfs_u.u_64.dlfs_fsmnt;
748 1.7 dholland } else {
749 1.7 dholland return fs->lfs_dlfs_u.u_32.dlfs_fsmnt;
750 1.7 dholland }
751 1.7 dholland }
752 1.7 dholland
753 1.7 dholland static __unused inline void
754 1.7 dholland lfs_sb_setfsmnt(STRUCT_LFS *fs, const char *str)
755 1.7 dholland {
756 1.7 dholland if (fs->lfs_is64) {
757 1.7 dholland (void)strncpy(fs->lfs_dlfs_u.u_64.dlfs_fsmnt, str,
758 1.7 dholland sizeof(fs->lfs_dlfs_u.u_64.dlfs_fsmnt));
759 1.7 dholland } else {
760 1.7 dholland (void)strncpy(fs->lfs_dlfs_u.u_32.dlfs_fsmnt, str,
761 1.7 dholland sizeof(fs->lfs_dlfs_u.u_32.dlfs_fsmnt));
762 1.7 dholland }
763 1.1 dholland }
764 1.1 dholland
765 1.8 dholland /* Highest addressable fsb */
766 1.8 dholland #define LFS_MAX_DADDR(fs) \
767 1.8 dholland ((fs)->lfs_is64 ? 0x7fffffffffffffff : 0x7fffffff)
768 1.8 dholland
769 1.1 dholland /* LFS_NINDIR is the number of indirects in a file system block. */
770 1.1 dholland #define LFS_NINDIR(fs) (lfs_sb_getnindir(fs))
771 1.1 dholland
772 1.1 dholland /* LFS_INOPB is the number of inodes in a secondary storage block. */
773 1.1 dholland #define LFS_INOPB(fs) (lfs_sb_getinopb(fs))
774 1.1 dholland /* LFS_INOPF is the number of inodes in a fragment. */
775 1.1 dholland #define LFS_INOPF(fs) (lfs_sb_getinopf(fs))
776 1.1 dholland
777 1.1 dholland #define lfs_blkoff(fs, loc) ((int)((loc) & lfs_sb_getbmask(fs)))
778 1.1 dholland #define lfs_fragoff(fs, loc) /* calculates (loc % fs->lfs_fsize) */ \
779 1.1 dholland ((int)((loc) & lfs_sb_getffmask(fs)))
780 1.1 dholland
781 1.4 dholland /* XXX: lowercase these as they're no longer macros */
782 1.4 dholland /* Frags to diskblocks */
783 1.4 dholland static __unused inline uint64_t
784 1.4 dholland LFS_FSBTODB(STRUCT_LFS *fs, uint64_t b)
785 1.4 dholland {
786 1.1 dholland #if defined(_KERNEL)
787 1.4 dholland return b << (lfs_sb_getffshift(fs) - DEV_BSHIFT);
788 1.1 dholland #else
789 1.4 dholland return b << lfs_sb_getfsbtodb(fs);
790 1.1 dholland #endif
791 1.4 dholland }
792 1.4 dholland /* Diskblocks to frags */
793 1.4 dholland static __unused inline uint64_t
794 1.4 dholland LFS_DBTOFSB(STRUCT_LFS *fs, uint64_t b)
795 1.4 dholland {
796 1.4 dholland #if defined(_KERNEL)
797 1.4 dholland return b >> (lfs_sb_getffshift(fs) - DEV_BSHIFT);
798 1.4 dholland #else
799 1.4 dholland return b >> lfs_sb_getfsbtodb(fs);
800 1.4 dholland #endif
801 1.4 dholland }
802 1.1 dholland
803 1.1 dholland #define lfs_lblkno(fs, loc) ((loc) >> lfs_sb_getbshift(fs))
804 1.1 dholland #define lfs_lblktosize(fs, blk) ((blk) << lfs_sb_getbshift(fs))
805 1.1 dholland
806 1.4 dholland /* Frags to bytes */
807 1.4 dholland static __unused inline uint64_t
808 1.4 dholland lfs_fsbtob(STRUCT_LFS *fs, uint64_t b)
809 1.4 dholland {
810 1.4 dholland return b << lfs_sb_getffshift(fs);
811 1.4 dholland }
812 1.4 dholland /* Bytes to frags */
813 1.4 dholland static __unused inline uint64_t
814 1.4 dholland lfs_btofsb(STRUCT_LFS *fs, uint64_t b)
815 1.4 dholland {
816 1.4 dholland return b >> lfs_sb_getffshift(fs);
817 1.4 dholland }
818 1.1 dholland
819 1.1 dholland #define lfs_numfrags(fs, loc) /* calculates (loc / fs->lfs_fsize) */ \
820 1.1 dholland ((loc) >> lfs_sb_getffshift(fs))
821 1.1 dholland #define lfs_blkroundup(fs, size)/* calculates roundup(size, lfs_sb_getbsize(fs)) */ \
822 1.1 dholland ((off_t)(((size) + lfs_sb_getbmask(fs)) & (~lfs_sb_getbmask(fs))))
823 1.1 dholland #define lfs_fragroundup(fs, size)/* calculates roundup(size, fs->lfs_fsize) */ \
824 1.1 dholland ((off_t)(((size) + lfs_sb_getffmask(fs)) & (~lfs_sb_getffmask(fs))))
825 1.1 dholland #define lfs_fragstoblks(fs, frags)/* calculates (frags / fs->fs_frag) */ \
826 1.1 dholland ((frags) >> lfs_sb_getfbshift(fs))
827 1.1 dholland #define lfs_blkstofrags(fs, blks)/* calculates (blks * fs->fs_frag) */ \
828 1.1 dholland ((blks) << lfs_sb_getfbshift(fs))
829 1.1 dholland #define lfs_fragnum(fs, fsb) /* calculates (fsb % fs->lfs_frag) */ \
830 1.1 dholland ((fsb) & ((fs)->lfs_frag - 1))
831 1.1 dholland #define lfs_blknum(fs, fsb) /* calculates rounddown(fsb, fs->lfs_frag) */ \
832 1.1 dholland ((fsb) &~ ((fs)->lfs_frag - 1))
833 1.1 dholland #define lfs_dblksize(fs, dp, lbn) \
834 1.1 dholland (((lbn) >= ULFS_NDADDR || (dp)->di_size >= ((lbn) + 1) << lfs_sb_getbshift(fs)) \
835 1.1 dholland ? lfs_sb_getbsize(fs) \
836 1.1 dholland : (lfs_fragroundup(fs, lfs_blkoff(fs, (dp)->di_size))))
837 1.1 dholland
838 1.6 dholland #define lfs_segsize(fs) (lfs_sb_getversion(fs) == 1 ? \
839 1.1 dholland lfs_lblktosize((fs), lfs_sb_getssize(fs)) : \
840 1.1 dholland lfs_sb_getssize(fs))
841 1.4 dholland /* XXX segtod produces a result in frags despite the 'd' */
842 1.4 dholland #define lfs_segtod(fs, seg) (lfs_btofsb(fs, lfs_segsize(fs)) * (seg))
843 1.1 dholland #define lfs_dtosn(fs, daddr) /* block address to segment number */ \
844 1.1 dholland ((uint32_t)(((daddr) - lfs_sb_gets0addr(fs)) / lfs_segtod((fs), 1)))
845 1.1 dholland #define lfs_sntod(fs, sn) /* segment number to disk address */ \
846 1.1 dholland ((daddr_t)(lfs_segtod((fs), (sn)) + lfs_sb_gets0addr(fs)))
847 1.1 dholland
848 1.4 dholland /* XXX, blah. make this appear only if struct inode is defined */
849 1.4 dholland #ifdef _UFS_LFS_LFS_INODE_H_
850 1.4 dholland static __unused inline uint32_t
851 1.4 dholland lfs_blksize(STRUCT_LFS *fs, struct inode *ip, uint64_t lbn)
852 1.4 dholland {
853 1.4 dholland if (lbn >= ULFS_NDADDR || ip->i_ffs1_size >= (lbn + 1) << lfs_sb_getbshift(fs)) {
854 1.4 dholland return lfs_sb_getbsize(fs);
855 1.4 dholland } else {
856 1.4 dholland return lfs_fragroundup(fs, lfs_blkoff(fs, ip->i_ffs1_size));
857 1.4 dholland }
858 1.4 dholland }
859 1.4 dholland #endif
860 1.4 dholland
861 1.4 dholland
862 1.1 dholland /*
863 1.1 dholland * Macros for determining free space on the disk, with the variable metadata
864 1.1 dholland * of segment summaries and inode blocks taken into account.
865 1.1 dholland */
866 1.1 dholland /*
867 1.1 dholland * Estimate number of clean blocks not available for writing because
868 1.1 dholland * they will contain metadata or overhead. This is calculated as
869 1.1 dholland *
870 1.1 dholland * E = ((C * M / D) * D + (0) * (T - D)) / T
871 1.1 dholland * or more simply
872 1.1 dholland * E = (C * M) / T
873 1.1 dholland *
874 1.1 dholland * where
875 1.1 dholland * C is the clean space,
876 1.1 dholland * D is the dirty space,
877 1.1 dholland * M is the dirty metadata, and
878 1.1 dholland * T = C + D is the total space on disk.
879 1.1 dholland *
880 1.1 dholland * This approximates the old formula of E = C * M / D when D is close to T,
881 1.1 dholland * but avoids falsely reporting "disk full" when the sample size (D) is small.
882 1.1 dholland */
883 1.1 dholland #define LFS_EST_CMETA(F) (int32_t)(( \
884 1.1 dholland (lfs_sb_getdmeta(F) * (int64_t)lfs_sb_getnclean(F)) / \
885 1.1 dholland (lfs_sb_getnseg(F))))
886 1.1 dholland
887 1.1 dholland /* Estimate total size of the disk not including metadata */
888 1.1 dholland #define LFS_EST_NONMETA(F) (lfs_sb_getdsize(F) - lfs_sb_getdmeta(F) - LFS_EST_CMETA(F))
889 1.1 dholland
890 1.1 dholland /* Estimate number of blocks actually available for writing */
891 1.1 dholland #define LFS_EST_BFREE(F) (lfs_sb_getbfree(F) > LFS_EST_CMETA(F) ? \
892 1.1 dholland lfs_sb_getbfree(F) - LFS_EST_CMETA(F) : 0)
893 1.1 dholland
894 1.1 dholland /* Amount of non-meta space not available to mortal man */
895 1.1 dholland #define LFS_EST_RSVD(F) (int32_t)((LFS_EST_NONMETA(F) * \
896 1.1 dholland (u_int64_t)lfs_sb_getminfree(F)) / \
897 1.1 dholland 100)
898 1.1 dholland
899 1.4 dholland /* Can credential C write BB blocks? XXX: kauth_cred_geteuid is abusive */
900 1.1 dholland #define ISSPACE(F, BB, C) \
901 1.1 dholland ((((C) == NOCRED || kauth_cred_geteuid(C) == 0) && \
902 1.1 dholland LFS_EST_BFREE(F) >= (BB)) || \
903 1.1 dholland (kauth_cred_geteuid(C) != 0 && IS_FREESPACE(F, BB)))
904 1.1 dholland
905 1.1 dholland /* Can an ordinary user write BB blocks */
906 1.1 dholland #define IS_FREESPACE(F, BB) \
907 1.1 dholland (LFS_EST_BFREE(F) >= (BB) + LFS_EST_RSVD(F))
908 1.1 dholland
909 1.1 dholland /*
910 1.1 dholland * The minimum number of blocks to create a new inode. This is:
911 1.1 dholland * directory direct block (1) + ULFS_NIADDR indirect blocks + inode block (1) +
912 1.1 dholland * ifile direct block (1) + ULFS_NIADDR indirect blocks = 3 + 2 * ULFS_NIADDR blocks.
913 1.1 dholland */
914 1.1 dholland #define LFS_NRESERVE(F) (lfs_btofsb((F), (2 * ULFS_NIADDR + 3) << lfs_sb_getbshift(F)))
915 1.1 dholland
916 1.1 dholland
917 1.1 dholland
918 1.1 dholland #endif /* _UFS_LFS_LFS_ACCESSORS_H_ */
919