xref: /minix3/sys/ufs/lfs/lfs.h (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: lfs.h,v 1.194 2015/10/03 08:29:34 dholland Exp $	*/
284d9c625SLionel Sambuc 
384d9c625SLionel Sambuc /*  from NetBSD: dinode.h,v 1.22 2013/01/22 09:39:18 dholland Exp  */
484d9c625SLionel Sambuc /*  from NetBSD: dir.h,v 1.21 2009/07/22 04:49:19 dholland Exp  */
5d65f6f70SBen Gras 
6d65f6f70SBen Gras /*-
7d65f6f70SBen Gras  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
8d65f6f70SBen Gras  * All rights reserved.
9d65f6f70SBen Gras  *
10d65f6f70SBen Gras  * This code is derived from software contributed to The NetBSD Foundation
11d65f6f70SBen Gras  * by Konrad E. Schroder <perseant@hhhh.org>.
12d65f6f70SBen Gras  *
13d65f6f70SBen Gras  * Redistribution and use in source and binary forms, with or without
14d65f6f70SBen Gras  * modification, are permitted provided that the following conditions
15d65f6f70SBen Gras  * are met:
16d65f6f70SBen Gras  * 1. Redistributions of source code must retain the above copyright
17d65f6f70SBen Gras  *    notice, this list of conditions and the following disclaimer.
18d65f6f70SBen Gras  * 2. Redistributions in binary form must reproduce the above copyright
19d65f6f70SBen Gras  *    notice, this list of conditions and the following disclaimer in the
20d65f6f70SBen Gras  *    documentation and/or other materials provided with the distribution.
21d65f6f70SBen Gras  *
22d65f6f70SBen Gras  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23d65f6f70SBen Gras  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24d65f6f70SBen Gras  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25d65f6f70SBen Gras  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26d65f6f70SBen Gras  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27d65f6f70SBen Gras  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28d65f6f70SBen Gras  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29d65f6f70SBen Gras  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30d65f6f70SBen Gras  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31d65f6f70SBen Gras  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32d65f6f70SBen Gras  * POSSIBILITY OF SUCH DAMAGE.
33d65f6f70SBen Gras  */
34d65f6f70SBen Gras /*-
35d65f6f70SBen Gras  * Copyright (c) 1991, 1993
36d65f6f70SBen Gras  *	The Regents of the University of California.  All rights reserved.
37d65f6f70SBen Gras  *
38d65f6f70SBen Gras  * Redistribution and use in source and binary forms, with or without
39d65f6f70SBen Gras  * modification, are permitted provided that the following conditions
40d65f6f70SBen Gras  * are met:
41d65f6f70SBen Gras  * 1. Redistributions of source code must retain the above copyright
42d65f6f70SBen Gras  *    notice, this list of conditions and the following disclaimer.
43d65f6f70SBen Gras  * 2. Redistributions in binary form must reproduce the above copyright
44d65f6f70SBen Gras  *    notice, this list of conditions and the following disclaimer in the
45d65f6f70SBen Gras  *    documentation and/or other materials provided with the distribution.
46d65f6f70SBen Gras  * 3. Neither the name of the University nor the names of its contributors
47d65f6f70SBen Gras  *    may be used to endorse or promote products derived from this software
48d65f6f70SBen Gras  *    without specific prior written permission.
49d65f6f70SBen Gras  *
50d65f6f70SBen Gras  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51d65f6f70SBen Gras  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52d65f6f70SBen Gras  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53d65f6f70SBen Gras  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54d65f6f70SBen Gras  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55d65f6f70SBen Gras  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56d65f6f70SBen Gras  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57d65f6f70SBen Gras  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58d65f6f70SBen Gras  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59d65f6f70SBen Gras  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60d65f6f70SBen Gras  * SUCH DAMAGE.
61d65f6f70SBen Gras  *
62d65f6f70SBen Gras  *	@(#)lfs.h	8.9 (Berkeley) 5/8/95
63d65f6f70SBen Gras  */
6484d9c625SLionel Sambuc /*
6584d9c625SLionel Sambuc  * Copyright (c) 2002 Networks Associates Technology, Inc.
6684d9c625SLionel Sambuc  * All rights reserved.
6784d9c625SLionel Sambuc  *
6884d9c625SLionel Sambuc  * This software was developed for the FreeBSD Project by Marshall
6984d9c625SLionel Sambuc  * Kirk McKusick and Network Associates Laboratories, the Security
7084d9c625SLionel Sambuc  * Research Division of Network Associates, Inc. under DARPA/SPAWAR
7184d9c625SLionel Sambuc  * contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA CHATS
7284d9c625SLionel Sambuc  * research program
7384d9c625SLionel Sambuc  *
7484d9c625SLionel Sambuc  * Copyright (c) 1982, 1989, 1993
7584d9c625SLionel Sambuc  *	The Regents of the University of California.  All rights reserved.
7684d9c625SLionel Sambuc  * (c) UNIX System Laboratories, Inc.
7784d9c625SLionel Sambuc  * All or some portions of this file are derived from material licensed
7884d9c625SLionel Sambuc  * to the University of California by American Telephone and Telegraph
7984d9c625SLionel Sambuc  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8084d9c625SLionel Sambuc  * the permission of UNIX System Laboratories, Inc.
8184d9c625SLionel Sambuc  *
8284d9c625SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
8384d9c625SLionel Sambuc  * modification, are permitted provided that the following conditions
8484d9c625SLionel Sambuc  * are met:
8584d9c625SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
8684d9c625SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
8784d9c625SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
8884d9c625SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
8984d9c625SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
9084d9c625SLionel Sambuc  * 3. Neither the name of the University nor the names of its contributors
9184d9c625SLionel Sambuc  *    may be used to endorse or promote products derived from this software
9284d9c625SLionel Sambuc  *    without specific prior written permission.
9384d9c625SLionel Sambuc  *
9484d9c625SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
9584d9c625SLionel Sambuc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
9684d9c625SLionel Sambuc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
9784d9c625SLionel Sambuc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
9884d9c625SLionel Sambuc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
9984d9c625SLionel Sambuc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
10084d9c625SLionel Sambuc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
10184d9c625SLionel Sambuc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
10284d9c625SLionel Sambuc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
10384d9c625SLionel Sambuc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
10484d9c625SLionel Sambuc  * SUCH DAMAGE.
10584d9c625SLionel Sambuc  *
10684d9c625SLionel Sambuc  *	@(#)dinode.h	8.9 (Berkeley) 3/29/95
10784d9c625SLionel Sambuc  */
10884d9c625SLionel Sambuc /*
10984d9c625SLionel Sambuc  * Copyright (c) 1982, 1986, 1989, 1993
11084d9c625SLionel Sambuc  *	The Regents of the University of California.  All rights reserved.
11184d9c625SLionel Sambuc  * (c) UNIX System Laboratories, Inc.
11284d9c625SLionel Sambuc  * All or some portions of this file are derived from material licensed
11384d9c625SLionel Sambuc  * to the University of California by American Telephone and Telegraph
11484d9c625SLionel Sambuc  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
11584d9c625SLionel Sambuc  * the permission of UNIX System Laboratories, Inc.
11684d9c625SLionel Sambuc  *
11784d9c625SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
11884d9c625SLionel Sambuc  * modification, are permitted provided that the following conditions
11984d9c625SLionel Sambuc  * are met:
12084d9c625SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
12184d9c625SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
12284d9c625SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
12384d9c625SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
12484d9c625SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
12584d9c625SLionel Sambuc  * 3. Neither the name of the University nor the names of its contributors
12684d9c625SLionel Sambuc  *    may be used to endorse or promote products derived from this software
12784d9c625SLionel Sambuc  *    without specific prior written permission.
12884d9c625SLionel Sambuc  *
12984d9c625SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
13084d9c625SLionel Sambuc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
13184d9c625SLionel Sambuc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
13284d9c625SLionel Sambuc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
13384d9c625SLionel Sambuc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
13484d9c625SLionel Sambuc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
13584d9c625SLionel Sambuc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
13684d9c625SLionel Sambuc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
13784d9c625SLionel Sambuc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
13884d9c625SLionel Sambuc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
13984d9c625SLionel Sambuc  * SUCH DAMAGE.
14084d9c625SLionel Sambuc  *
14184d9c625SLionel Sambuc  *	@(#)dir.h	8.5 (Berkeley) 4/27/95
14284d9c625SLionel Sambuc  */
14384d9c625SLionel Sambuc 
14484d9c625SLionel Sambuc /*
14584d9c625SLionel Sambuc  * NOTE: COORDINATE ON-DISK FORMAT CHANGES WITH THE FREEBSD PROJECT.
14684d9c625SLionel Sambuc  */
147d65f6f70SBen Gras 
148d65f6f70SBen Gras #ifndef _UFS_LFS_LFS_H_
149d65f6f70SBen Gras #define _UFS_LFS_LFS_H_
150d65f6f70SBen Gras 
151*0a6a1f1dSLionel Sambuc #if !defined(_KERNEL) && !defined(_STANDALONE)
152*0a6a1f1dSLionel Sambuc #include <stddef.h> /* for offsetof */
153*0a6a1f1dSLionel Sambuc #endif
154*0a6a1f1dSLionel Sambuc 
155d65f6f70SBen Gras #include <sys/rwlock.h>
156d65f6f70SBen Gras #include <sys/mutex.h>
157d65f6f70SBen Gras #include <sys/queue.h>
158d65f6f70SBen Gras #include <sys/condvar.h>
15984d9c625SLionel Sambuc #include <sys/mount.h>
16084d9c625SLionel Sambuc #include <sys/pool.h>
161d65f6f70SBen Gras 
162d65f6f70SBen Gras /*
163d65f6f70SBen Gras  * Compile-time options for LFS.
164d65f6f70SBen Gras  */
165d65f6f70SBen Gras #define LFS_IFIND_RETRIES  16
166d65f6f70SBen Gras #define LFS_LOGLENGTH      1024 /* size of debugging log */
167d65f6f70SBen Gras #define LFS_MAX_ACTIVE	   10	/* Dirty segments before ckp forced */
168d65f6f70SBen Gras 
169d65f6f70SBen Gras /*
170d65f6f70SBen Gras  * Fixed filesystem layout parameters
171d65f6f70SBen Gras  */
172d65f6f70SBen Gras #define	LFS_LABELPAD	8192		/* LFS label size */
173d65f6f70SBen Gras #define	LFS_SBPAD	8192		/* LFS superblock size */
174d65f6f70SBen Gras 
175d65f6f70SBen Gras #define	LFS_UNUSED_INUM	0		/* 0: out of band inode number */
176d65f6f70SBen Gras #define	LFS_IFILE_INUM	1		/* 1: IFILE inode number */
177d65f6f70SBen Gras 					/* 2: Root inode number */
17884d9c625SLionel Sambuc #define	LFS_LOSTFOUNDINO 3		/* 3: lost+found inode number */
179d65f6f70SBen Gras #define	LFS_FIRST_INUM	4		/* 4: first free inode number */
180d65f6f70SBen Gras 
18184d9c625SLionel Sambuc /*
18284d9c625SLionel Sambuc  * The root inode is the root of the file system.  Inode 0 can't be used for
18384d9c625SLionel Sambuc  * normal purposes and historically bad blocks were linked to inode 1, thus
18484d9c625SLionel Sambuc  * the root inode is 2.  (Inode 1 is no longer used for this purpose, however
18584d9c625SLionel Sambuc  * numerous dump tapes make this assumption, so we are stuck with it).
18684d9c625SLionel Sambuc  */
18784d9c625SLionel Sambuc #define	ULFS_ROOTINO	((ino_t)2)
18884d9c625SLionel Sambuc 
18984d9c625SLionel Sambuc /*
19084d9c625SLionel Sambuc  * The Whiteout inode# is a dummy non-zero inode number which will
19184d9c625SLionel Sambuc  * never be allocated to a real file.  It is used as a place holder
19284d9c625SLionel Sambuc  * in the directory entry which has been tagged as a LFS_DT_WHT entry.
19384d9c625SLionel Sambuc  * See the comments about ULFS_ROOTINO above.
19484d9c625SLionel Sambuc  */
19584d9c625SLionel Sambuc #define	ULFS_WINO	((ino_t)1)
19684d9c625SLionel Sambuc 
19784d9c625SLionel Sambuc 
198d65f6f70SBen Gras #define	LFS_V1_SUMMARY_SIZE	512     /* V1 fixed summary size */
199d65f6f70SBen Gras #define	LFS_DFL_SUMMARY_SIZE	512	/* Default summary size */
200d65f6f70SBen Gras 
201d65f6f70SBen Gras #define LFS_MAXNAMLEN	255		/* maximum name length in a dir */
202d65f6f70SBen Gras 
20384d9c625SLionel Sambuc #define ULFS_NXADDR	2
20484d9c625SLionel Sambuc #define	ULFS_NDADDR	12		/* Direct addresses in inode. */
20584d9c625SLionel Sambuc #define	ULFS_NIADDR	3		/* Indirect addresses in inode. */
20684d9c625SLionel Sambuc 
20784d9c625SLionel Sambuc /*
20884d9c625SLionel Sambuc  * Adjustable filesystem parameters
20984d9c625SLionel Sambuc  */
210d65f6f70SBen Gras #ifndef LFS_ATIME_IFILE
211d65f6f70SBen Gras # define LFS_ATIME_IFILE 0 /* Store atime info in ifile (optional in LFSv1) */
212d65f6f70SBen Gras #endif
213d65f6f70SBen Gras #define LFS_MARKV_MAXBLKCNT	65536	/* Max block count for lfs_markv() */
214d65f6f70SBen Gras 
215d65f6f70SBen Gras /*
21684d9c625SLionel Sambuc  * Directories
217d65f6f70SBen Gras  */
218d65f6f70SBen Gras 
21984d9c625SLionel Sambuc /*
220*0a6a1f1dSLionel Sambuc  * Directories in LFS are files; they use the same inode and block
221*0a6a1f1dSLionel Sambuc  * mapping structures that regular files do. The directory per se is
222*0a6a1f1dSLionel Sambuc  * manifested in the file contents: an unordered, unstructured
223*0a6a1f1dSLionel Sambuc  * sequence of variable-size directory entries.
22484d9c625SLionel Sambuc  *
225*0a6a1f1dSLionel Sambuc  * This format and structure is taken (via what was originally shared
226*0a6a1f1dSLionel Sambuc  * ufs-level code) from FFS. Each directory entry is a fixed header
227*0a6a1f1dSLionel Sambuc  * followed by a string, the total length padded to a 4-byte boundary.
228*0a6a1f1dSLionel Sambuc  * All strings include a null terminator; the maximum string length
229*0a6a1f1dSLionel Sambuc  * is LFS_MAXNAMLEN, which is 255.
23084d9c625SLionel Sambuc  *
231*0a6a1f1dSLionel Sambuc  * The directory entry header structure (struct lfs_dirheader) is just
232*0a6a1f1dSLionel Sambuc  * the header information. A complete entry is this plus a null-
233*0a6a1f1dSLionel Sambuc  * terminated name following it, plus some amount of padding. The
234*0a6a1f1dSLionel Sambuc  * length of the name (not including the null terminator) is given by
235*0a6a1f1dSLionel Sambuc  * the namlen field of the header; the complete record length,
236*0a6a1f1dSLionel Sambuc  * including the null terminator and padding, is given by the reclen
237*0a6a1f1dSLionel Sambuc  * field of the header. The record length is always 4-byte aligned.
238*0a6a1f1dSLionel Sambuc  * (Even on 64-bit volumes, the record length is only 4-byte aligned,
239*0a6a1f1dSLionel Sambuc  * not 8-byte.)
240*0a6a1f1dSLionel Sambuc  *
241*0a6a1f1dSLionel Sambuc  * Historically, FFS directories were/are organized into blocks of
242*0a6a1f1dSLionel Sambuc  * size DIRBLKSIZE that can be written atomically to disk at the
243*0a6a1f1dSLionel Sambuc  * hardware level. Directory entries are not allowed to cross the
244*0a6a1f1dSLionel Sambuc  * boundaries of these blocks. The resulting atomicity is important
245*0a6a1f1dSLionel Sambuc  * for the integrity of FFS volumes; however, for LFS it's irrelevant.
246*0a6a1f1dSLionel Sambuc  * All we have to care about is not writing out directories that
247*0a6a1f1dSLionel Sambuc  * confuse earlier ufs-based versions of the LFS code.
248*0a6a1f1dSLionel Sambuc  *
249*0a6a1f1dSLionel Sambuc  * This means [to be determined]. (XXX)
250*0a6a1f1dSLionel Sambuc  *
251*0a6a1f1dSLionel Sambuc  * As DIRBLKSIZE in its FFS sense is hardware-dependent, and file
252*0a6a1f1dSLionel Sambuc  * system images do from time to time move to different hardware, code
253*0a6a1f1dSLionel Sambuc  * that reads directories should be prepared to handle directories
254*0a6a1f1dSLionel Sambuc  * written in a context where DIRBLKSIZE was different (smaller or
255*0a6a1f1dSLionel Sambuc  * larger) than its current value. Note however that it is not
256*0a6a1f1dSLionel Sambuc  * sensible for DIRBLKSIZE to be larger than the volume fragment size,
257*0a6a1f1dSLionel Sambuc  * and not practically possible for it to be larger than the volume
258*0a6a1f1dSLionel Sambuc  * block size.
259*0a6a1f1dSLionel Sambuc  *
260*0a6a1f1dSLionel Sambuc  * Some further notes:
261*0a6a1f1dSLionel Sambuc  *    - the LFS_DIRSIZ macro provides the minimum space needed to hold
262*0a6a1f1dSLionel Sambuc  *      a directory entry.
263*0a6a1f1dSLionel Sambuc  *    - any particular entry may be arbitrarily larger (which is why the
264*0a6a1f1dSLionel Sambuc  *      header stores both the entry size and the name size) to pad out
265*0a6a1f1dSLionel Sambuc  *      unused space.
266*0a6a1f1dSLionel Sambuc  *    - historically the padding in an entry is not necessarily zeroed
267*0a6a1f1dSLionel Sambuc  *      but may contain trash.
268*0a6a1f1dSLionel Sambuc  *    - dp->d_reclen is the size of the entry. This is always 4-byte
269*0a6a1f1dSLionel Sambuc  *      aligned.
270*0a6a1f1dSLionel Sambuc  *    - dp->d_namlen is the length of the string, and should always be
271*0a6a1f1dSLionel Sambuc  *      the same as strlen(dp->d_name).
272*0a6a1f1dSLionel Sambuc  *    - in particular, space available in an entry is given by
273*0a6a1f1dSLionel Sambuc  *      dp->d_reclen - LFS_DIRSIZ(dp), and all space available within a
274*0a6a1f1dSLionel Sambuc  *      directory block is tucked away within an existing entry.
275*0a6a1f1dSLionel Sambuc  *    - all space within a directory block is part of some entry.
276*0a6a1f1dSLionel Sambuc  *    - therefore, inserting a new entry requires finding and
277*0a6a1f1dSLionel Sambuc  *      splitting a suitable existing entry, and when entries are
278*0a6a1f1dSLionel Sambuc  *      removed their space is merged into the entry ahead of them.
279*0a6a1f1dSLionel Sambuc  *    - an empty/unused entry has d_ino set to 0. This normally only
280*0a6a1f1dSLionel Sambuc  *      appears in the first entry in a block, as elsewhere the unused
281*0a6a1f1dSLionel Sambuc  *      entry should have been merged into the one before it. However,
282*0a6a1f1dSLionel Sambuc  *      fsck leaves such entries behind so they must be tolerated
283*0a6a1f1dSLionel Sambuc  *      elsewhere.
284*0a6a1f1dSLionel Sambuc  *    - a completely empty directory block has one entry whose
285*0a6a1f1dSLionel Sambuc  *      d_reclen is DIRBLKSIZ and whose d_ino is 0.
286*0a6a1f1dSLionel Sambuc  *
287*0a6a1f1dSLionel Sambuc  * The "old directory format" referenced by the fs->lfs_isolddirfmt
288*0a6a1f1dSLionel Sambuc  * flag (and some other things) refers to when the type field was
289*0a6a1f1dSLionel Sambuc  * added to directory entries. This change was made to FFS in the 80s,
290*0a6a1f1dSLionel Sambuc  * well before LFS was first written; there should be no LFS volumes
291*0a6a1f1dSLionel Sambuc  * (and certainly no LFS v2-format volumes or LFS64 volumes) where the
292*0a6a1f1dSLionel Sambuc  * old format pertains. All of the related logic should probably be
293*0a6a1f1dSLionel Sambuc  * removed; however, it hasn't been yet, and we get to carry it around
294*0a6a1f1dSLionel Sambuc  * until we can be conclusively sure it isn't needed.
295*0a6a1f1dSLionel Sambuc  *
296*0a6a1f1dSLionel Sambuc  * In the "old directory format" there is no type field and the namlen
297*0a6a1f1dSLionel Sambuc  * field is correspondingly 16 bits wide. On big-endian volumes this
298*0a6a1f1dSLionel Sambuc  * has no effect: namlen cannot exceed 255, so the upper byte is
299*0a6a1f1dSLionel Sambuc  * always 0 and this reads back from the type field as LFS_DT_UNKNOWN.
300*0a6a1f1dSLionel Sambuc  * On little-endian volumes, the namlen field will always be 0 and
301*0a6a1f1dSLionel Sambuc  * the namlen value needs to be read out of the type field. (The type
302*0a6a1f1dSLionel Sambuc  * is always LFS_DT_UNKNOWN.) The directory accessor functions take
303*0a6a1f1dSLionel Sambuc  * care of this so nothing else needs to be aware of it.
304*0a6a1f1dSLionel Sambuc  *
305*0a6a1f1dSLionel Sambuc  * LFS_OLDDIRFMT and LFS_NEWDIRFMT are code numbers for the old and
306*0a6a1f1dSLionel Sambuc  * new directory format respectively. These codes do not appear on
307*0a6a1f1dSLionel Sambuc  * disk; they're generated from a runtime macro called FSFMT() that's
308*0a6a1f1dSLionel Sambuc  * cued by other things. This is why (confusingly) LFS_OLDDIRFMT is 1
309*0a6a1f1dSLionel Sambuc  * and LFS_NEWDIRFMT is 0.
310*0a6a1f1dSLionel Sambuc  *
311*0a6a1f1dSLionel Sambuc  * FSFMT(), LFS_OLDDIRFMT, and LFS_NEWDIRFMT should be removed. (XXX)
31284d9c625SLionel Sambuc  */
313d65f6f70SBen Gras 
31484d9c625SLionel Sambuc /*
31584d9c625SLionel Sambuc  * Directory block size.
31684d9c625SLionel Sambuc  */
31784d9c625SLionel Sambuc #undef	LFS_DIRBLKSIZ
31884d9c625SLionel Sambuc #define	LFS_DIRBLKSIZ	DEV_BSIZE
319d65f6f70SBen Gras 
32084d9c625SLionel Sambuc /*
321*0a6a1f1dSLionel Sambuc  * Convert between stat structure type codes and directory entry type codes.
32284d9c625SLionel Sambuc  */
32384d9c625SLionel Sambuc #define	LFS_IFTODT(mode)	(((mode) & 0170000) >> 12)
32484d9c625SLionel Sambuc #define	LFS_DTTOIF(dirtype)	((dirtype) << 12)
325d65f6f70SBen Gras 
32684d9c625SLionel Sambuc /*
32784d9c625SLionel Sambuc  * Theoretically, directories can be more than 2Gb in length; however, in
32884d9c625SLionel Sambuc  * practice this seems unlikely. So, we define the type doff_t as a 32-bit
32984d9c625SLionel Sambuc  * quantity to keep down the cost of doing lookup on a 32-bit machine.
33084d9c625SLionel Sambuc  */
33184d9c625SLionel Sambuc #define	doff_t		int32_t
33284d9c625SLionel Sambuc #define	lfs_doff_t	int32_t
33384d9c625SLionel Sambuc #define	LFS_MAXDIRSIZE	(0x7fffffff)
33484d9c625SLionel Sambuc 
33584d9c625SLionel Sambuc /*
33684d9c625SLionel Sambuc  * File types for d_type
33784d9c625SLionel Sambuc  */
33884d9c625SLionel Sambuc #define	LFS_DT_UNKNOWN	 0
33984d9c625SLionel Sambuc #define	LFS_DT_FIFO	 1
34084d9c625SLionel Sambuc #define	LFS_DT_CHR	 2
34184d9c625SLionel Sambuc #define	LFS_DT_DIR	 4
34284d9c625SLionel Sambuc #define	LFS_DT_BLK	 6
34384d9c625SLionel Sambuc #define	LFS_DT_REG	 8
34484d9c625SLionel Sambuc #define	LFS_DT_LNK	10
34584d9c625SLionel Sambuc #define	LFS_DT_SOCK	12
34684d9c625SLionel Sambuc #define	LFS_DT_WHT	14
34784d9c625SLionel Sambuc 
34884d9c625SLionel Sambuc /*
34984d9c625SLionel Sambuc  * (See notes above)
35084d9c625SLionel Sambuc  */
351*0a6a1f1dSLionel Sambuc 
352*0a6a1f1dSLionel Sambuc struct lfs_dirheader32 {
353*0a6a1f1dSLionel Sambuc 	u_int32_t dh_ino;		/* inode number of entry */
354*0a6a1f1dSLionel Sambuc 	u_int16_t dh_reclen;		/* length of this record */
355*0a6a1f1dSLionel Sambuc 	u_int8_t  dh_type; 		/* file type, see below */
356*0a6a1f1dSLionel Sambuc 	u_int8_t  dh_namlen;		/* length of string in d_name */
35784d9c625SLionel Sambuc };
35884d9c625SLionel Sambuc 
359*0a6a1f1dSLionel Sambuc struct lfs_dirheader64 {
360*0a6a1f1dSLionel Sambuc 	u_int32_t dh_inoA;		/* inode number of entry */
361*0a6a1f1dSLionel Sambuc 	u_int32_t dh_inoB;		/* inode number of entry */
362*0a6a1f1dSLionel Sambuc 	u_int16_t dh_reclen;		/* length of this record */
363*0a6a1f1dSLionel Sambuc 	u_int8_t  dh_type; 		/* file type, see below */
364*0a6a1f1dSLionel Sambuc 	u_int8_t  dh_namlen;		/* length of string in d_name */
365*0a6a1f1dSLionel Sambuc };
366*0a6a1f1dSLionel Sambuc 
367*0a6a1f1dSLionel Sambuc union lfs_dirheader {
368*0a6a1f1dSLionel Sambuc 	struct lfs_dirheader64 u_64;
369*0a6a1f1dSLionel Sambuc 	struct lfs_dirheader32 u_32;
370*0a6a1f1dSLionel Sambuc };
371*0a6a1f1dSLionel Sambuc 
372*0a6a1f1dSLionel Sambuc typedef union lfs_dirheader LFS_DIRHEADER;
373*0a6a1f1dSLionel Sambuc 
37484d9c625SLionel Sambuc /*
375*0a6a1f1dSLionel Sambuc  * Template for manipulating directories.
37684d9c625SLionel Sambuc  */
377*0a6a1f1dSLionel Sambuc 
378*0a6a1f1dSLionel Sambuc struct lfs_dirtemplate32 {
379*0a6a1f1dSLionel Sambuc 	struct lfs_dirheader32	dot_header;
38084d9c625SLionel Sambuc 	char			dot_name[4];	/* must be multiple of 4 */
381*0a6a1f1dSLionel Sambuc 	struct lfs_dirheader32	dotdot_header;
38284d9c625SLionel Sambuc 	char			dotdot_name[4];	/* ditto */
38384d9c625SLionel Sambuc };
38484d9c625SLionel Sambuc 
385*0a6a1f1dSLionel Sambuc struct lfs_dirtemplate64 {
386*0a6a1f1dSLionel Sambuc 	struct lfs_dirheader64	dot_header;
387*0a6a1f1dSLionel Sambuc 	char			dot_name[4];	/* must be multiple of 4 */
388*0a6a1f1dSLionel Sambuc 	struct lfs_dirheader64	dotdot_header;
389*0a6a1f1dSLionel Sambuc 	char			dotdot_name[4];	/* ditto */
390*0a6a1f1dSLionel Sambuc };
391*0a6a1f1dSLionel Sambuc 
392*0a6a1f1dSLionel Sambuc union lfs_dirtemplate {
393*0a6a1f1dSLionel Sambuc 	struct lfs_dirtemplate64 u_64;
394*0a6a1f1dSLionel Sambuc 	struct lfs_dirtemplate32 u_32;
395*0a6a1f1dSLionel Sambuc };
396*0a6a1f1dSLionel Sambuc 
397*0a6a1f1dSLionel Sambuc #if 0
39884d9c625SLionel Sambuc /*
39984d9c625SLionel Sambuc  * This is the old format of directories, sans type element.
40084d9c625SLionel Sambuc  */
40184d9c625SLionel Sambuc struct lfs_odirtemplate {
40284d9c625SLionel Sambuc 	u_int32_t	dot_ino;
40384d9c625SLionel Sambuc 	int16_t		dot_reclen;
40484d9c625SLionel Sambuc 	u_int16_t	dot_namlen;
40584d9c625SLionel Sambuc 	char		dot_name[4];	/* must be multiple of 4 */
40684d9c625SLionel Sambuc 	u_int32_t	dotdot_ino;
40784d9c625SLionel Sambuc 	int16_t		dotdot_reclen;
40884d9c625SLionel Sambuc 	u_int16_t	dotdot_namlen;
40984d9c625SLionel Sambuc 	char		dotdot_name[4];	/* ditto */
41084d9c625SLionel Sambuc };
411*0a6a1f1dSLionel Sambuc #endif
41284d9c625SLionel Sambuc 
41384d9c625SLionel Sambuc /*
41484d9c625SLionel Sambuc  * Inodes
41584d9c625SLionel Sambuc  */
41684d9c625SLionel Sambuc 
41784d9c625SLionel Sambuc /*
41884d9c625SLionel Sambuc  * A dinode contains all the meta-data associated with a LFS file.
41984d9c625SLionel Sambuc  * This structure defines the on-disk format of a dinode. Since
42084d9c625SLionel Sambuc  * this structure describes an on-disk structure, all its fields
42184d9c625SLionel Sambuc  * are defined by types with precise widths.
42284d9c625SLionel Sambuc  */
42384d9c625SLionel Sambuc 
424*0a6a1f1dSLionel Sambuc struct lfs32_dinode {
42584d9c625SLionel Sambuc 	u_int16_t	di_mode;	/*   0: IFMT, permissions; see below. */
42684d9c625SLionel Sambuc 	int16_t		di_nlink;	/*   2: File link count. */
42784d9c625SLionel Sambuc 	u_int32_t	di_inumber;	/*   4: Inode number. */
42884d9c625SLionel Sambuc 	u_int64_t	di_size;	/*   8: File byte count. */
42984d9c625SLionel Sambuc 	int32_t		di_atime;	/*  16: Last access time. */
43084d9c625SLionel Sambuc 	int32_t		di_atimensec;	/*  20: Last access time. */
43184d9c625SLionel Sambuc 	int32_t		di_mtime;	/*  24: Last modified time. */
43284d9c625SLionel Sambuc 	int32_t		di_mtimensec;	/*  28: Last modified time. */
43384d9c625SLionel Sambuc 	int32_t		di_ctime;	/*  32: Last inode change time. */
43484d9c625SLionel Sambuc 	int32_t		di_ctimensec;	/*  36: Last inode change time. */
43584d9c625SLionel Sambuc 	int32_t		di_db[ULFS_NDADDR]; /*  40: Direct disk blocks. */
43684d9c625SLionel Sambuc 	int32_t		di_ib[ULFS_NIADDR]; /*  88: Indirect disk blocks. */
43784d9c625SLionel Sambuc 	u_int32_t	di_flags;	/* 100: Status flags (chflags). */
43884d9c625SLionel Sambuc 	u_int32_t	di_blocks;	/* 104: Blocks actually held. */
43984d9c625SLionel Sambuc 	int32_t		di_gen;		/* 108: Generation number. */
44084d9c625SLionel Sambuc 	u_int32_t	di_uid;		/* 112: File owner. */
44184d9c625SLionel Sambuc 	u_int32_t	di_gid;		/* 116: File group. */
44284d9c625SLionel Sambuc 	u_int64_t	di_modrev;	/* 120: i_modrev for NFSv4 */
44384d9c625SLionel Sambuc };
44484d9c625SLionel Sambuc 
445*0a6a1f1dSLionel Sambuc struct lfs64_dinode {
44684d9c625SLionel Sambuc 	u_int16_t	di_mode;	/*   0: IFMT, permissions; see below. */
44784d9c625SLionel Sambuc 	int16_t		di_nlink;	/*   2: File link count. */
44884d9c625SLionel Sambuc 	u_int32_t	di_uid;		/*   4: File owner. */
44984d9c625SLionel Sambuc 	u_int32_t	di_gid;		/*   8: File group. */
45084d9c625SLionel Sambuc 	u_int32_t	di_blksize;	/*  12: Inode blocksize. */
45184d9c625SLionel Sambuc 	u_int64_t	di_size;	/*  16: File byte count. */
45284d9c625SLionel Sambuc 	u_int64_t	di_blocks;	/*  24: Bytes actually held. */
45384d9c625SLionel Sambuc 	int64_t		di_atime;	/*  32: Last access time. */
45484d9c625SLionel Sambuc 	int64_t		di_mtime;	/*  40: Last modified time. */
45584d9c625SLionel Sambuc 	int64_t		di_ctime;	/*  48: Last inode change time. */
45684d9c625SLionel Sambuc 	int64_t		di_birthtime;	/*  56: Inode creation time. */
45784d9c625SLionel Sambuc 	int32_t		di_mtimensec;	/*  64: Last modified time. */
45884d9c625SLionel Sambuc 	int32_t		di_atimensec;	/*  68: Last access time. */
45984d9c625SLionel Sambuc 	int32_t		di_ctimensec;	/*  72: Last inode change time. */
46084d9c625SLionel Sambuc 	int32_t		di_birthnsec;	/*  76: Inode creation time. */
46184d9c625SLionel Sambuc 	int32_t		di_gen;		/*  80: Generation number. */
46284d9c625SLionel Sambuc 	u_int32_t	di_kernflags;	/*  84: Kernel flags. */
46384d9c625SLionel Sambuc 	u_int32_t	di_flags;	/*  88: Status flags (chflags). */
46484d9c625SLionel Sambuc 	int32_t		di_extsize;	/*  92: External attributes block. */
46584d9c625SLionel Sambuc 	int64_t		di_extb[ULFS_NXADDR];/* 96: External attributes block. */
46684d9c625SLionel Sambuc 	int64_t		di_db[ULFS_NDADDR]; /* 112: Direct disk blocks. */
46784d9c625SLionel Sambuc 	int64_t		di_ib[ULFS_NIADDR]; /* 208: Indirect disk blocks. */
46884d9c625SLionel Sambuc 	u_int64_t	di_modrev;	/* 232: i_modrev for NFSv4 */
469*0a6a1f1dSLionel Sambuc 	u_int64_t	di_inumber;	/* 240: Inode number */
470*0a6a1f1dSLionel Sambuc 	u_int64_t	di_spare[1];	/* 244: Reserved; currently unused */
471*0a6a1f1dSLionel Sambuc };
472*0a6a1f1dSLionel Sambuc 
473*0a6a1f1dSLionel Sambuc union lfs_dinode {
474*0a6a1f1dSLionel Sambuc 	struct lfs64_dinode u_64;
475*0a6a1f1dSLionel Sambuc 	struct lfs32_dinode u_32;
47684d9c625SLionel Sambuc };
47784d9c625SLionel Sambuc 
47884d9c625SLionel Sambuc /*
47984d9c625SLionel Sambuc  * The di_db fields may be overlaid with other information for
48084d9c625SLionel Sambuc  * file types that do not have associated disk storage. Block
48184d9c625SLionel Sambuc  * and character devices overlay the first data block with their
48284d9c625SLionel Sambuc  * dev_t value. Short symbolic links place their path in the
48384d9c625SLionel Sambuc  * di_db area.
48484d9c625SLionel Sambuc  */
48584d9c625SLionel Sambuc #define	di_rdev		di_db[0]
48684d9c625SLionel Sambuc 
48784d9c625SLionel Sambuc /* Size of the on-disk inode. */
488*0a6a1f1dSLionel Sambuc //#define	LFS_DINODE1_SIZE	(sizeof(struct ulfs1_dinode))	/* 128 */
489*0a6a1f1dSLionel Sambuc //#define	LFS_DINODE2_SIZE	(sizeof(struct ulfs2_dinode))
49084d9c625SLionel Sambuc 
49184d9c625SLionel Sambuc /* File types, found in the upper bits of di_mode. */
49284d9c625SLionel Sambuc #define	LFS_IFMT	0170000		/* Mask of file type. */
49384d9c625SLionel Sambuc #define	LFS_IFIFO	0010000		/* Named pipe (fifo). */
49484d9c625SLionel Sambuc #define	LFS_IFCHR	0020000		/* Character device. */
49584d9c625SLionel Sambuc #define	LFS_IFDIR	0040000		/* Directory file. */
49684d9c625SLionel Sambuc #define	LFS_IFBLK	0060000		/* Block device. */
49784d9c625SLionel Sambuc #define	LFS_IFREG	0100000		/* Regular file. */
49884d9c625SLionel Sambuc #define	LFS_IFLNK	0120000		/* Symbolic link. */
49984d9c625SLionel Sambuc #define	LFS_IFSOCK	0140000		/* UNIX domain socket. */
50084d9c625SLionel Sambuc #define	LFS_IFWHT	0160000		/* Whiteout. */
50184d9c625SLionel Sambuc 
50284d9c625SLionel Sambuc /*
503d65f6f70SBen Gras  * "struct buf" associated definitions
504d65f6f70SBen Gras  */
505d65f6f70SBen Gras 
506d65f6f70SBen Gras /* Unassigned disk addresses. */
507d65f6f70SBen Gras #define	UNASSIGNED	-1
508d65f6f70SBen Gras #define UNWRITTEN	-2
509d65f6f70SBen Gras 
510d65f6f70SBen Gras /* Unused logical block number */
511d65f6f70SBen Gras #define LFS_UNUSED_LBN	-1
512d65f6f70SBen Gras 
513d65f6f70SBen Gras /*
514d65f6f70SBen Gras  * "struct inode" associated definitions
515d65f6f70SBen Gras  */
516d65f6f70SBen Gras 
517d65f6f70SBen Gras /* For convenience */
518d65f6f70SBen Gras #define IN_ALLMOD (IN_MODIFIED|IN_ACCESS|IN_CHANGE|IN_UPDATE|IN_MODIFY|IN_ACCESSED|IN_CLEANING)
519d65f6f70SBen Gras 
520d65f6f70SBen Gras /*
521d65f6f70SBen Gras  * On-disk and in-memory checkpoint segment usage structure.
522d65f6f70SBen Gras  */
523d65f6f70SBen Gras typedef struct segusage SEGUSE;
524d65f6f70SBen Gras struct segusage {
525d65f6f70SBen Gras 	u_int32_t su_nbytes;		/* 0: number of live bytes */
526d65f6f70SBen Gras 	u_int32_t su_olastmod;		/* 4: SEGUSE last modified timestamp */
527d65f6f70SBen Gras 	u_int16_t su_nsums;		/* 8: number of summaries in segment */
528d65f6f70SBen Gras 	u_int16_t su_ninos;		/* 10: number of inode blocks in seg */
529d65f6f70SBen Gras 
530d65f6f70SBen Gras #define	SEGUSE_ACTIVE		0x01	/*  segment currently being written */
531d65f6f70SBen Gras #define	SEGUSE_DIRTY		0x02	/*  segment has data in it */
532d65f6f70SBen Gras #define	SEGUSE_SUPERBLOCK	0x04	/*  segment contains a superblock */
533d65f6f70SBen Gras #define SEGUSE_ERROR		0x08	/*  cleaner: do not clean segment */
534d65f6f70SBen Gras #define SEGUSE_EMPTY		0x10	/*  segment is empty */
535d65f6f70SBen Gras #define SEGUSE_INVAL		0x20	/*  segment is invalid */
536d65f6f70SBen Gras 	u_int32_t su_flags;		/* 12: segment flags */
537d65f6f70SBen Gras 	u_int64_t su_lastmod;		/* 16: last modified timestamp */
538d65f6f70SBen Gras };
539d65f6f70SBen Gras 
540d65f6f70SBen Gras typedef struct segusage_v1 SEGUSE_V1;
541d65f6f70SBen Gras struct segusage_v1 {
542d65f6f70SBen Gras 	u_int32_t su_nbytes;		/* 0: number of live bytes */
543d65f6f70SBen Gras 	u_int32_t su_lastmod;		/* 4: SEGUSE last modified timestamp */
544d65f6f70SBen Gras 	u_int16_t su_nsums;		/* 8: number of summaries in segment */
545d65f6f70SBen Gras 	u_int16_t su_ninos;		/* 10: number of inode blocks in seg */
546d65f6f70SBen Gras 	u_int32_t su_flags;		/* 12: segment flags  */
547d65f6f70SBen Gras };
548d65f6f70SBen Gras 
549d65f6f70SBen Gras /*
550d65f6f70SBen Gras  * On-disk file information.  One per file with data blocks in the segment.
551*0a6a1f1dSLionel Sambuc  *
552*0a6a1f1dSLionel Sambuc  * The FINFO structure is a header; it is followed by fi_nblocks block
553*0a6a1f1dSLionel Sambuc  * pointers, which are logical block numbers of the file. (These are the
554*0a6a1f1dSLionel Sambuc  * blocks of the file present in this segment.)
555d65f6f70SBen Gras  */
556*0a6a1f1dSLionel Sambuc 
557*0a6a1f1dSLionel Sambuc typedef struct finfo64 FINFO64;
558*0a6a1f1dSLionel Sambuc struct finfo64 {
559*0a6a1f1dSLionel Sambuc 	u_int32_t fi_nblocks;		/* number of blocks */
560*0a6a1f1dSLionel Sambuc 	u_int32_t fi_version;		/* version number */
561*0a6a1f1dSLionel Sambuc 	u_int64_t fi_ino;		/* inode number */
562*0a6a1f1dSLionel Sambuc 	u_int32_t fi_lastlength;	/* length of last block in array */
563*0a6a1f1dSLionel Sambuc 	u_int32_t fi_pad;		/* unused */
564*0a6a1f1dSLionel Sambuc };
565*0a6a1f1dSLionel Sambuc 
566*0a6a1f1dSLionel Sambuc typedef struct finfo32 FINFO32;
567*0a6a1f1dSLionel Sambuc struct finfo32 {
568d65f6f70SBen Gras 	u_int32_t fi_nblocks;		/* number of blocks */
569d65f6f70SBen Gras 	u_int32_t fi_version;		/* version number */
570d65f6f70SBen Gras 	u_int32_t fi_ino;		/* inode number */
571d65f6f70SBen Gras 	u_int32_t fi_lastlength;	/* length of last block in array */
572d65f6f70SBen Gras };
573*0a6a1f1dSLionel Sambuc 
574*0a6a1f1dSLionel Sambuc typedef union finfo {
575*0a6a1f1dSLionel Sambuc 	struct finfo64 u_64;
576*0a6a1f1dSLionel Sambuc 	struct finfo32 u_32;
577*0a6a1f1dSLionel Sambuc } FINFO;
578*0a6a1f1dSLionel Sambuc 
579*0a6a1f1dSLionel Sambuc /*
580*0a6a1f1dSLionel Sambuc  * inode info (part of the segment summary)
581*0a6a1f1dSLionel Sambuc  *
582*0a6a1f1dSLionel Sambuc  * Each one of these is just a block number; wrapping the structure
583*0a6a1f1dSLionel Sambuc  * around it gives more contextual information in the code about
584*0a6a1f1dSLionel Sambuc  * what's going on.
585*0a6a1f1dSLionel Sambuc  */
586*0a6a1f1dSLionel Sambuc 
587*0a6a1f1dSLionel Sambuc typedef struct iinfo64 {
588*0a6a1f1dSLionel Sambuc 	uint64_t ii_block;		/* block number */
589*0a6a1f1dSLionel Sambuc } IINFO64;
590*0a6a1f1dSLionel Sambuc 
591*0a6a1f1dSLionel Sambuc typedef struct iinfo32 {
592*0a6a1f1dSLionel Sambuc 	uint32_t ii_block;		/* block number */
593*0a6a1f1dSLionel Sambuc } IINFO32;
594*0a6a1f1dSLionel Sambuc 
595*0a6a1f1dSLionel Sambuc typedef union iinfo {
596*0a6a1f1dSLionel Sambuc 	struct iinfo64 u_64;
597*0a6a1f1dSLionel Sambuc 	struct iinfo32 u_32;
598*0a6a1f1dSLionel Sambuc } IINFO;
599d65f6f70SBen Gras 
600d65f6f70SBen Gras /*
601d65f6f70SBen Gras  * Index file inode entries.
602d65f6f70SBen Gras  */
603*0a6a1f1dSLionel Sambuc 
604*0a6a1f1dSLionel Sambuc /* magic value for daddrs */
605d65f6f70SBen Gras #define	LFS_UNUSED_DADDR	0	/* out-of-band daddr */
606*0a6a1f1dSLionel Sambuc /* magic value for if_nextfree */
607d65f6f70SBen Gras #define LFS_ORPHAN_NEXTFREE	(~(u_int32_t)0) /* indicate orphaned file */
608*0a6a1f1dSLionel Sambuc 
609*0a6a1f1dSLionel Sambuc typedef struct ifile64 IFILE64;
610*0a6a1f1dSLionel Sambuc struct ifile64 {
611*0a6a1f1dSLionel Sambuc 	u_int32_t if_version;		/* inode version number */
612*0a6a1f1dSLionel Sambuc 	u_int32_t if_atime_nsec;	/* and nanoseconds */
613*0a6a1f1dSLionel Sambuc 	u_int64_t if_atime_sec;		/* Last access time, seconds */
614*0a6a1f1dSLionel Sambuc 	int64_t	  if_daddr;		/* inode disk address */
615*0a6a1f1dSLionel Sambuc 	u_int64_t if_nextfree;		/* next-unallocated inode */
616*0a6a1f1dSLionel Sambuc };
617*0a6a1f1dSLionel Sambuc 
618*0a6a1f1dSLionel Sambuc typedef struct ifile32 IFILE32;
619*0a6a1f1dSLionel Sambuc struct ifile32 {
620*0a6a1f1dSLionel Sambuc 	u_int32_t if_version;		/* inode version number */
621*0a6a1f1dSLionel Sambuc 	int32_t	  if_daddr;		/* inode disk address */
622d65f6f70SBen Gras 	u_int32_t if_nextfree;		/* next-unallocated inode */
623d65f6f70SBen Gras 	u_int32_t if_atime_sec;		/* Last access time, seconds */
624d65f6f70SBen Gras 	u_int32_t if_atime_nsec;	/* and nanoseconds */
625d65f6f70SBen Gras };
626d65f6f70SBen Gras 
627d65f6f70SBen Gras typedef struct ifile_v1 IFILE_V1;
628d65f6f70SBen Gras struct ifile_v1 {
629d65f6f70SBen Gras 	u_int32_t if_version;		/* inode version number */
630d65f6f70SBen Gras 	int32_t	  if_daddr;		/* inode disk address */
631d65f6f70SBen Gras 	u_int32_t if_nextfree;		/* next-unallocated inode */
632d65f6f70SBen Gras #if LFS_ATIME_IFILE
633*0a6a1f1dSLionel Sambuc #error "this cannot work"
634d65f6f70SBen Gras 	struct timespec if_atime;	/* Last access time */
635d65f6f70SBen Gras #endif
636d65f6f70SBen Gras };
637d65f6f70SBen Gras 
638d65f6f70SBen Gras /*
639*0a6a1f1dSLionel Sambuc  * Note: struct ifile_v1 is often handled by accessing the first three
640*0a6a1f1dSLionel Sambuc  * fields of struct ifile32. (XXX: Blah.  This should be cleaned up as
641*0a6a1f1dSLionel Sambuc  * it may in some cases violate the strict-aliasing rules.)
642d65f6f70SBen Gras  */
643*0a6a1f1dSLionel Sambuc typedef union ifile {
644*0a6a1f1dSLionel Sambuc 	struct ifile64 u_64;
645*0a6a1f1dSLionel Sambuc 	struct ifile32 u_32;
646*0a6a1f1dSLionel Sambuc 	struct ifile_v1 u_v1;
647*0a6a1f1dSLionel Sambuc } IFILE;
648d65f6f70SBen Gras 
649d65f6f70SBen Gras /*
650d65f6f70SBen Gras  * Cleaner information structure.  This resides in the ifile and is used
651d65f6f70SBen Gras  * to pass information from the kernel to the cleaner.
652d65f6f70SBen Gras  */
653*0a6a1f1dSLionel Sambuc 
654*0a6a1f1dSLionel Sambuc /* flags for ->flags */
655d65f6f70SBen Gras #define LFS_CLEANER_MUST_CLEAN	0x01
656*0a6a1f1dSLionel Sambuc 
657*0a6a1f1dSLionel Sambuc typedef struct _cleanerinfo32 {
658*0a6a1f1dSLionel Sambuc 	u_int32_t clean;		/* 0: number of clean segments */
659*0a6a1f1dSLionel Sambuc 	u_int32_t dirty;		/* 4: number of dirty segments */
660*0a6a1f1dSLionel Sambuc 	int32_t   bfree;		/* 8: disk blocks free */
661*0a6a1f1dSLionel Sambuc 	int32_t	  avail;		/* 12: disk blocks available */
662*0a6a1f1dSLionel Sambuc 	u_int32_t free_head;		/* 16: head of the inode free list */
663*0a6a1f1dSLionel Sambuc 	u_int32_t free_tail;		/* 20: tail of the inode free list */
664*0a6a1f1dSLionel Sambuc 	u_int32_t flags;		/* 24: status word from the kernel */
665*0a6a1f1dSLionel Sambuc } CLEANERINFO32;
666*0a6a1f1dSLionel Sambuc 
667*0a6a1f1dSLionel Sambuc typedef struct _cleanerinfo64 {
668*0a6a1f1dSLionel Sambuc 	u_int32_t clean;		/* 0: number of clean segments */
669*0a6a1f1dSLionel Sambuc 	u_int32_t dirty;		/* 4: number of dirty segments */
670*0a6a1f1dSLionel Sambuc 	int64_t   bfree;		/* 8: disk blocks free */
671*0a6a1f1dSLionel Sambuc 	int64_t	  avail;		/* 16: disk blocks available */
672*0a6a1f1dSLionel Sambuc 	u_int64_t free_head;		/* 24: head of the inode free list */
673*0a6a1f1dSLionel Sambuc 	u_int64_t free_tail;		/* 32: tail of the inode free list */
674*0a6a1f1dSLionel Sambuc 	u_int32_t flags;		/* 40: status word from the kernel */
675*0a6a1f1dSLionel Sambuc 	u_int32_t pad;			/* 44: must be 64-bit aligned */
676*0a6a1f1dSLionel Sambuc } CLEANERINFO64;
677*0a6a1f1dSLionel Sambuc 
678*0a6a1f1dSLionel Sambuc /* this must not go to disk directly of course */
679*0a6a1f1dSLionel Sambuc typedef union _cleanerinfo {
680*0a6a1f1dSLionel Sambuc 	CLEANERINFO32 u_32;
681*0a6a1f1dSLionel Sambuc 	CLEANERINFO64 u_64;
682d65f6f70SBen Gras } CLEANERINFO;
683d65f6f70SBen Gras 
684d65f6f70SBen Gras /*
685d65f6f70SBen Gras  * On-disk segment summary information
686d65f6f70SBen Gras  */
687d65f6f70SBen Gras 
688*0a6a1f1dSLionel Sambuc /* magic value for ss_magic */
689*0a6a1f1dSLionel Sambuc #define SS_MAGIC	0x061561
690*0a6a1f1dSLionel Sambuc 
691*0a6a1f1dSLionel Sambuc /* flags for ss_flags */
692d65f6f70SBen Gras #define	SS_DIROP	0x01		/* segment begins a dirop */
693d65f6f70SBen Gras #define	SS_CONT		0x02		/* more partials to finish this write*/
694d65f6f70SBen Gras #define	SS_CLEAN	0x04		/* written by the cleaner */
695d65f6f70SBen Gras #define	SS_RFW		0x08		/* written by the roll-forward agent */
69684d9c625SLionel Sambuc #define	SS_RECLAIM	0x10		/* written by the roll-forward agent */
697*0a6a1f1dSLionel Sambuc 
698*0a6a1f1dSLionel Sambuc /* type used for reading checksum signatures from metadata structures */
699*0a6a1f1dSLionel Sambuc typedef uint32_t lfs_checkword;
700*0a6a1f1dSLionel Sambuc 
701*0a6a1f1dSLionel Sambuc typedef struct segsum_v1 SEGSUM_V1;
702*0a6a1f1dSLionel Sambuc struct segsum_v1 {
703*0a6a1f1dSLionel Sambuc 	u_int32_t ss_sumsum;		/* 0: check sum of summary block */
704*0a6a1f1dSLionel Sambuc 	u_int32_t ss_datasum;		/* 4: check sum of data */
705*0a6a1f1dSLionel Sambuc 	u_int32_t ss_magic;		/* 8: segment summary magic number */
706*0a6a1f1dSLionel Sambuc 	int32_t	  ss_next;		/* 12: next segment */
707*0a6a1f1dSLionel Sambuc 	u_int32_t ss_create;		/* 16: creation time stamp */
708*0a6a1f1dSLionel Sambuc 	u_int16_t ss_nfinfo;		/* 20: number of file info structures */
709*0a6a1f1dSLionel Sambuc 	u_int16_t ss_ninos;		/* 22: number of inodes in summary */
710d65f6f70SBen Gras 	u_int16_t ss_flags;		/* 24: used for directory operations */
711d65f6f70SBen Gras 	u_int16_t ss_pad;		/* 26: extra space */
712d65f6f70SBen Gras 	/* FINFO's and inode daddr's... */
713d65f6f70SBen Gras };
714d65f6f70SBen Gras 
715*0a6a1f1dSLionel Sambuc typedef struct segsum32 SEGSUM32;
716*0a6a1f1dSLionel Sambuc struct segsum32 {
717d65f6f70SBen Gras 	u_int32_t ss_sumsum;		/* 0: check sum of summary block */
718d65f6f70SBen Gras 	u_int32_t ss_datasum;		/* 4: check sum of data */
719d65f6f70SBen Gras 	u_int32_t ss_magic;		/* 8: segment summary magic number */
720*0a6a1f1dSLionel Sambuc 	int32_t	  ss_next;		/* 12: next segment (disk address) */
721d65f6f70SBen Gras 	u_int32_t ss_ident;		/* 16: roll-forward fsid */
722d65f6f70SBen Gras 	u_int16_t ss_nfinfo;		/* 20: number of file info structures */
723d65f6f70SBen Gras 	u_int16_t ss_ninos;		/* 22: number of inodes in summary */
724d65f6f70SBen Gras 	u_int16_t ss_flags;		/* 24: used for directory operations */
72584d9c625SLionel Sambuc 	u_int8_t  ss_pad[2];		/* 26: extra space */
72684d9c625SLionel Sambuc 	u_int32_t ss_reclino;           /* 28: inode being reclaimed */
727d65f6f70SBen Gras 	u_int64_t ss_serial;		/* 32: serial number */
728d65f6f70SBen Gras 	u_int64_t ss_create;		/* 40: time stamp */
729d65f6f70SBen Gras 	/* FINFO's and inode daddr's... */
730d65f6f70SBen Gras };
731d65f6f70SBen Gras 
732*0a6a1f1dSLionel Sambuc typedef struct segsum64 SEGSUM64;
733*0a6a1f1dSLionel Sambuc struct segsum64 {
734*0a6a1f1dSLionel Sambuc 	u_int32_t ss_sumsum;		/* 0: check sum of summary block */
735*0a6a1f1dSLionel Sambuc 	u_int32_t ss_datasum;		/* 4: check sum of data */
736*0a6a1f1dSLionel Sambuc 	u_int32_t ss_magic;		/* 8: segment summary magic number */
737*0a6a1f1dSLionel Sambuc 	u_int32_t ss_ident;		/* 12: roll-forward fsid */
738*0a6a1f1dSLionel Sambuc 	int64_t	  ss_next;		/* 16: next segment (disk address) */
739*0a6a1f1dSLionel Sambuc 	u_int16_t ss_nfinfo;		/* 24: number of file info structures */
740*0a6a1f1dSLionel Sambuc 	u_int16_t ss_ninos;		/* 26: number of inodes in summary */
741*0a6a1f1dSLionel Sambuc 	u_int16_t ss_flags;		/* 28: used for directory operations */
742*0a6a1f1dSLionel Sambuc 	u_int8_t  ss_pad[2];		/* 30: extra space */
743*0a6a1f1dSLionel Sambuc 	u_int64_t ss_reclino;           /* 32: inode being reclaimed */
744*0a6a1f1dSLionel Sambuc 	u_int64_t ss_serial;		/* 40: serial number */
745*0a6a1f1dSLionel Sambuc 	u_int64_t ss_create;		/* 48: time stamp */
746*0a6a1f1dSLionel Sambuc 	/* FINFO's and inode daddr's... */
747*0a6a1f1dSLionel Sambuc };
748*0a6a1f1dSLionel Sambuc 
749*0a6a1f1dSLionel Sambuc typedef union segsum SEGSUM;
750*0a6a1f1dSLionel Sambuc union segsum {
751*0a6a1f1dSLionel Sambuc 	struct segsum64 u_64;
752*0a6a1f1dSLionel Sambuc 	struct segsum32 u_32;
753*0a6a1f1dSLionel Sambuc 	struct segsum_v1 u_v1;
754*0a6a1f1dSLionel Sambuc };
755d65f6f70SBen Gras 
756d65f6f70SBen Gras 
757d65f6f70SBen Gras /*
758d65f6f70SBen Gras  * On-disk super block.
759*0a6a1f1dSLionel Sambuc  *
760*0a6a1f1dSLionel Sambuc  * We have separate superblock structures for the 32-bit and 64-bit
761*0a6a1f1dSLionel Sambuc  * LFS, and accessor functions to hide the differences.
762*0a6a1f1dSLionel Sambuc  *
763*0a6a1f1dSLionel Sambuc  * For lfs64, the format version is always 2; version 1 lfs is old.
764*0a6a1f1dSLionel Sambuc  * For both, the inode format version is 0; for lfs32 this selects the
765*0a6a1f1dSLionel Sambuc  * same 32-bit inode as always, and for lfs64 this selects the larger
766*0a6a1f1dSLionel Sambuc  * 64-bit inode structure we got from ffsv2.
767*0a6a1f1dSLionel Sambuc  *
768*0a6a1f1dSLionel Sambuc  * In lfs64:
769*0a6a1f1dSLionel Sambuc  *   - inode numbers are still 32 bit
770*0a6a1f1dSLionel Sambuc  *   - segments may not be larger than 4G (counted in bytes)
771*0a6a1f1dSLionel Sambuc  *   - there may not be more than 2^32 (or perhaps 2^31) segments
772*0a6a1f1dSLionel Sambuc  *   - the total volume size is limited to 2^63 frags and/or 2^63
773*0a6a1f1dSLionel Sambuc  *     disk blocks, and probably in practice 2^63 bytes.
774d65f6f70SBen Gras  */
775*0a6a1f1dSLionel Sambuc 
776d65f6f70SBen Gras #define	       LFS_MAGIC       		0x070162
777*0a6a1f1dSLionel Sambuc #define        LFS_MAGIC_SWAPPED	0x62010700
778*0a6a1f1dSLionel Sambuc 
779*0a6a1f1dSLionel Sambuc #define        LFS64_MAGIC     		0x19620701
780*0a6a1f1dSLionel Sambuc #define        LFS64_MAGIC_SWAPPED      0x01076219
781*0a6a1f1dSLionel Sambuc 
782d65f6f70SBen Gras #define	       LFS_VERSION     		2
783*0a6a1f1dSLionel Sambuc 
784*0a6a1f1dSLionel Sambuc #define LFS_MIN_SBINTERVAL     5	/* min superblock segment spacing */
785*0a6a1f1dSLionel Sambuc #define LFS_MAXNUMSB	       10	/* max number of superblocks */
786*0a6a1f1dSLionel Sambuc 
787*0a6a1f1dSLionel Sambuc /* flags for dlfs_pflags */
788*0a6a1f1dSLionel Sambuc #define LFS_PF_CLEAN 0x1
789*0a6a1f1dSLionel Sambuc 
790*0a6a1f1dSLionel Sambuc /* Inode format versions */
791*0a6a1f1dSLionel Sambuc #define LFS_44INODEFMT 0
792*0a6a1f1dSLionel Sambuc #define LFS_MAXINODEFMT 0
793*0a6a1f1dSLionel Sambuc 
794*0a6a1f1dSLionel Sambuc struct dlfs {
795*0a6a1f1dSLionel Sambuc 	u_int32_t dlfs_magic;	  /* 0: magic number */
796d65f6f70SBen Gras 	u_int32_t dlfs_version;	  /* 4: version number */
797d65f6f70SBen Gras 
798d65f6f70SBen Gras 	u_int32_t dlfs_size;	  /* 8: number of blocks in fs (v1) */
799d65f6f70SBen Gras 				  /*	number of frags in fs (v2) */
800d65f6f70SBen Gras 	u_int32_t dlfs_ssize;	  /* 12: number of blocks per segment (v1) */
801d65f6f70SBen Gras 				  /*	 number of bytes per segment (v2) */
802d65f6f70SBen Gras 	u_int32_t dlfs_dsize;	  /* 16: number of disk blocks in fs */
803d65f6f70SBen Gras 	u_int32_t dlfs_bsize;	  /* 20: file system block size */
804d65f6f70SBen Gras 	u_int32_t dlfs_fsize;	  /* 24: size of frag blocks in fs */
805d65f6f70SBen Gras 	u_int32_t dlfs_frag;	  /* 28: number of frags in a block in fs */
806d65f6f70SBen Gras 
807d65f6f70SBen Gras /* Checkpoint region. */
808*0a6a1f1dSLionel Sambuc 	u_int32_t dlfs_freehd;	  /* 32: start of the free inode list */
809*0a6a1f1dSLionel Sambuc 	int32_t   dlfs_bfree;	  /* 36: number of free frags */
810d65f6f70SBen Gras 	u_int32_t dlfs_nfiles;	  /* 40: number of allocated inodes */
811d65f6f70SBen Gras 	int32_t	  dlfs_avail;	  /* 44: blocks available for writing */
812d65f6f70SBen Gras 	int32_t	  dlfs_uinodes;	  /* 48: inodes in cache not yet on disk */
813d65f6f70SBen Gras 	int32_t	  dlfs_idaddr;	  /* 52: inode file disk address */
814d65f6f70SBen Gras 	u_int32_t dlfs_ifile;	  /* 56: inode file inode number */
815d65f6f70SBen Gras 	int32_t	  dlfs_lastseg;	  /* 60: address of last segment written */
816d65f6f70SBen Gras 	int32_t	  dlfs_nextseg;	  /* 64: address of next segment to write */
817d65f6f70SBen Gras 	int32_t	  dlfs_curseg;	  /* 68: current segment being written */
818d65f6f70SBen Gras 	int32_t	  dlfs_offset;	  /* 72: offset in curseg for next partial */
819d65f6f70SBen Gras 	int32_t	  dlfs_lastpseg;  /* 76: address of last partial written */
820d65f6f70SBen Gras 	u_int32_t dlfs_inopf;	  /* 80: v1: time stamp; v2: inodes per frag */
821d65f6f70SBen Gras 
822d65f6f70SBen Gras /* These are configuration parameters. */
823d65f6f70SBen Gras 	u_int32_t dlfs_minfree;	  /* 84: minimum percentage of free blocks */
824d65f6f70SBen Gras 
825d65f6f70SBen Gras /* These fields can be computed from the others. */
826d65f6f70SBen Gras 	u_int64_t dlfs_maxfilesize; /* 88: maximum representable file size */
827*0a6a1f1dSLionel Sambuc 	u_int32_t dlfs_fsbpseg;	    /* 96: frags (fsb) per segment */
828d65f6f70SBen Gras 	u_int32_t dlfs_inopb;	  /* 100: inodes per block */
829d65f6f70SBen Gras 	u_int32_t dlfs_ifpb;	  /* 104: IFILE entries per block */
830d65f6f70SBen Gras 	u_int32_t dlfs_sepb;	  /* 108: SEGUSE entries per block */
831d65f6f70SBen Gras 	u_int32_t dlfs_nindir;	  /* 112: indirect pointers per block */
832d65f6f70SBen Gras 	u_int32_t dlfs_nseg;	  /* 116: number of segments */
833d65f6f70SBen Gras 	u_int32_t dlfs_nspf;	  /* 120: number of sectors per fragment */
834d65f6f70SBen Gras 	u_int32_t dlfs_cleansz;	  /* 124: cleaner info size in blocks */
835d65f6f70SBen Gras 	u_int32_t dlfs_segtabsz;  /* 128: segment table size in blocks */
836d65f6f70SBen Gras 	u_int32_t dlfs_segmask;	  /* 132: calculate offset within a segment */
837d65f6f70SBen Gras 	u_int32_t dlfs_segshift;  /* 136: fast mult/div for segments */
838d65f6f70SBen Gras 	u_int32_t dlfs_bshift;	  /* 140: calc block number from file offset */
839d65f6f70SBen Gras 	u_int32_t dlfs_ffshift;	  /* 144: fast mult/div for frag from file */
840d65f6f70SBen Gras 	u_int32_t dlfs_fbshift;	  /* 148: fast mult/div for frag from block */
841d65f6f70SBen Gras 	u_int64_t dlfs_bmask;	  /* 152: calc block offset from file offset */
842d65f6f70SBen Gras 	u_int64_t dlfs_ffmask;	  /* 160: calc frag offset from file offset */
843d65f6f70SBen Gras 	u_int64_t dlfs_fbmask;	  /* 168: calc frag offset from block offset */
844d65f6f70SBen Gras 	u_int32_t dlfs_blktodb;	  /* 176: blktodb and dbtoblk shift constant */
845d65f6f70SBen Gras 	u_int32_t dlfs_sushift;	  /* 180: fast mult/div for segusage table */
846d65f6f70SBen Gras 
847d65f6f70SBen Gras 	int32_t	  dlfs_maxsymlinklen; /* 184: max length of an internal symlink */
848*0a6a1f1dSLionel Sambuc 				  /* 188: superblock disk offsets */
849d65f6f70SBen Gras 	int32_t	  dlfs_sboffs[LFS_MAXNUMSB];
850d65f6f70SBen Gras 
851d65f6f70SBen Gras 	u_int32_t dlfs_nclean;	  /* 228: Number of clean segments */
852d65f6f70SBen Gras 	u_char	  dlfs_fsmnt[MNAMELEN];	 /* 232: name mounted on */
853d65f6f70SBen Gras 	u_int16_t dlfs_pflags;	  /* 322: file system persistent flags */
854d65f6f70SBen Gras 	int32_t	  dlfs_dmeta;	  /* 324: total number of dirty summaries */
855d65f6f70SBen Gras 	u_int32_t dlfs_minfreeseg; /* 328: segments not counted in bfree */
856d65f6f70SBen Gras 	u_int32_t dlfs_sumsize;	  /* 332: size of summary blocks */
857d65f6f70SBen Gras 	u_int64_t dlfs_serial;	  /* 336: serial number */
858d65f6f70SBen Gras 	u_int32_t dlfs_ibsize;	  /* 344: size of inode blocks */
859*0a6a1f1dSLionel Sambuc 	int32_t	  dlfs_s0addr;	  /* 348: start of segment 0 */
860d65f6f70SBen Gras 	u_int64_t dlfs_tstamp;	  /* 352: time stamp */
861d65f6f70SBen Gras 	u_int32_t dlfs_inodefmt;  /* 360: inode format version */
862d65f6f70SBen Gras 	u_int32_t dlfs_interleave; /* 364: segment interleave */
863d65f6f70SBen Gras 	u_int32_t dlfs_ident;	  /* 368: per-fs identifier */
86484d9c625SLionel Sambuc 	u_int32_t dlfs_fsbtodb;	  /* 372: fsbtodb and dbtodsb shift constant */
865d65f6f70SBen Gras 	u_int32_t dlfs_resvseg;   /* 376: segments reserved for the cleaner */
866d65f6f70SBen Gras 	int8_t	  dlfs_pad[128];  /* 380: round to 512 bytes */
867d65f6f70SBen Gras /* Checksum -- last valid disk field. */
868d65f6f70SBen Gras 	u_int32_t dlfs_cksum;	  /* 508: checksum for superblock checking */
869d65f6f70SBen Gras };
870d65f6f70SBen Gras 
871*0a6a1f1dSLionel Sambuc struct dlfs64 {
872*0a6a1f1dSLionel Sambuc 	u_int32_t dlfs_magic;	  /* 0: magic number */
873*0a6a1f1dSLionel Sambuc 	u_int32_t dlfs_version;	  /* 4: version number (2) */
874*0a6a1f1dSLionel Sambuc 
875*0a6a1f1dSLionel Sambuc 	u_int64_t dlfs_size;	  /* 8: number of frags in fs (v2) */
876*0a6a1f1dSLionel Sambuc 	u_int64_t dlfs_dsize;	  /* 16: number of disk blocks in fs */
877*0a6a1f1dSLionel Sambuc 	u_int32_t dlfs_ssize;	  /* 24: number of bytes per segment (v2) */
878*0a6a1f1dSLionel Sambuc 	u_int32_t dlfs_bsize;	  /* 28: file system block size */
879*0a6a1f1dSLionel Sambuc 	u_int32_t dlfs_fsize;	  /* 32: size of frag blocks in fs */
880*0a6a1f1dSLionel Sambuc 	u_int32_t dlfs_frag;	  /* 36: number of frags in a block in fs */
881*0a6a1f1dSLionel Sambuc 
882*0a6a1f1dSLionel Sambuc /* Checkpoint region. */
883*0a6a1f1dSLionel Sambuc 	u_int64_t dlfs_freehd;	  /* 40: start of the free inode list */
884*0a6a1f1dSLionel Sambuc 	u_int64_t dlfs_nfiles;	  /* 48: number of allocated inodes */
885*0a6a1f1dSLionel Sambuc 	int64_t   dlfs_bfree;	  /* 56: number of free frags */
886*0a6a1f1dSLionel Sambuc 	int64_t	  dlfs_avail;	  /* 64: blocks available for writing */
887*0a6a1f1dSLionel Sambuc 	int64_t	  dlfs_idaddr;	  /* 72: inode file disk address */
888*0a6a1f1dSLionel Sambuc 	int32_t	  dlfs_uinodes;	  /* 80: inodes in cache not yet on disk */
889*0a6a1f1dSLionel Sambuc 	u_int32_t dlfs_unused_0;  /* 84: not used */
890*0a6a1f1dSLionel Sambuc 	int64_t	  dlfs_lastseg;	  /* 88: address of last segment written */
891*0a6a1f1dSLionel Sambuc 	int64_t	  dlfs_nextseg;	  /* 96: address of next segment to write */
892*0a6a1f1dSLionel Sambuc 	int64_t	  dlfs_curseg;	  /* 104: current segment being written */
893*0a6a1f1dSLionel Sambuc 	int64_t	  dlfs_offset;	  /* 112: offset in curseg for next partial */
894*0a6a1f1dSLionel Sambuc 	int64_t	  dlfs_lastpseg;  /* 120: address of last partial written */
895*0a6a1f1dSLionel Sambuc 	u_int32_t dlfs_inopf;	  /* 128: inodes per frag */
896*0a6a1f1dSLionel Sambuc 
897*0a6a1f1dSLionel Sambuc /* These are configuration parameters. */
898*0a6a1f1dSLionel Sambuc 	u_int32_t dlfs_minfree;	  /* 132: minimum percentage of free blocks */
899*0a6a1f1dSLionel Sambuc 
900*0a6a1f1dSLionel Sambuc /* These fields can be computed from the others. */
901*0a6a1f1dSLionel Sambuc 	u_int64_t dlfs_maxfilesize; /* 136: maximum representable file size */
902*0a6a1f1dSLionel Sambuc 	u_int32_t dlfs_fsbpseg;	  /* 144: frags (fsb) per segment */
903*0a6a1f1dSLionel Sambuc 	u_int32_t dlfs_inopb;	  /* 148: inodes per block */
904*0a6a1f1dSLionel Sambuc 	u_int32_t dlfs_ifpb;	  /* 152: IFILE entries per block */
905*0a6a1f1dSLionel Sambuc 	u_int32_t dlfs_sepb;	  /* 156: SEGUSE entries per block */
906*0a6a1f1dSLionel Sambuc 	u_int32_t dlfs_nindir;	  /* 160: indirect pointers per block */
907*0a6a1f1dSLionel Sambuc 	u_int32_t dlfs_nseg;	  /* 164: number of segments */
908*0a6a1f1dSLionel Sambuc 	u_int32_t dlfs_nspf;	  /* 168: number of sectors per fragment */
909*0a6a1f1dSLionel Sambuc 	u_int32_t dlfs_cleansz;	  /* 172: cleaner info size in blocks */
910*0a6a1f1dSLionel Sambuc 	u_int32_t dlfs_segtabsz;  /* 176: segment table size in blocks */
911*0a6a1f1dSLionel Sambuc 	u_int32_t dlfs_bshift;	  /* 180: calc block number from file offset */
912*0a6a1f1dSLionel Sambuc 	u_int32_t dlfs_ffshift;	  /* 184: fast mult/div for frag from file */
913*0a6a1f1dSLionel Sambuc 	u_int32_t dlfs_fbshift;	  /* 188: fast mult/div for frag from block */
914*0a6a1f1dSLionel Sambuc 	u_int64_t dlfs_bmask;	  /* 192: calc block offset from file offset */
915*0a6a1f1dSLionel Sambuc 	u_int64_t dlfs_ffmask;	  /* 200: calc frag offset from file offset */
916*0a6a1f1dSLionel Sambuc 	u_int64_t dlfs_fbmask;	  /* 208: calc frag offset from block offset */
917*0a6a1f1dSLionel Sambuc 	u_int32_t dlfs_blktodb;	  /* 216: blktodb and dbtoblk shift constant */
918*0a6a1f1dSLionel Sambuc 	u_int32_t dlfs_sushift;	  /* 220: fast mult/div for segusage table */
919*0a6a1f1dSLionel Sambuc 
920*0a6a1f1dSLionel Sambuc 				  /* 224: superblock disk offsets */
921*0a6a1f1dSLionel Sambuc 	int64_t	   dlfs_sboffs[LFS_MAXNUMSB];
922*0a6a1f1dSLionel Sambuc 
923*0a6a1f1dSLionel Sambuc 	int32_t	  dlfs_maxsymlinklen; /* 304: max len of an internal symlink */
924*0a6a1f1dSLionel Sambuc 	u_int32_t dlfs_nclean;	  /* 308: Number of clean segments */
925*0a6a1f1dSLionel Sambuc 	u_char	  dlfs_fsmnt[MNAMELEN];	 /* 312: name mounted on */
926*0a6a1f1dSLionel Sambuc 	u_int16_t dlfs_pflags;	  /* 402: file system persistent flags */
927*0a6a1f1dSLionel Sambuc 	int32_t	  dlfs_dmeta;	  /* 404: total number of dirty summaries */
928*0a6a1f1dSLionel Sambuc 	u_int32_t dlfs_minfreeseg; /* 408: segments not counted in bfree */
929*0a6a1f1dSLionel Sambuc 	u_int32_t dlfs_sumsize;	  /* 412: size of summary blocks */
930*0a6a1f1dSLionel Sambuc 	u_int32_t dlfs_ibsize;	  /* 416: size of inode blocks */
931*0a6a1f1dSLionel Sambuc 	u_int32_t dlfs_inodefmt;  /* 420: inode format version */
932*0a6a1f1dSLionel Sambuc 	u_int64_t dlfs_serial;	  /* 424: serial number */
933*0a6a1f1dSLionel Sambuc 	int64_t	  dlfs_s0addr;	  /* 432: start of segment 0 */
934*0a6a1f1dSLionel Sambuc 	u_int64_t dlfs_tstamp;	  /* 440: time stamp */
935*0a6a1f1dSLionel Sambuc 	u_int32_t dlfs_interleave; /* 448: segment interleave */
936*0a6a1f1dSLionel Sambuc 	u_int32_t dlfs_ident;	  /* 452: per-fs identifier */
937*0a6a1f1dSLionel Sambuc 	u_int32_t dlfs_fsbtodb;	  /* 456: fsbtodb and dbtodsb shift constant */
938*0a6a1f1dSLionel Sambuc 	u_int32_t dlfs_resvseg;   /* 460: segments reserved for the cleaner */
939*0a6a1f1dSLionel Sambuc 	int8_t	  dlfs_pad[44];   /* 464: round to 512 bytes */
940*0a6a1f1dSLionel Sambuc /* Checksum -- last valid disk field. */
941*0a6a1f1dSLionel Sambuc 	u_int32_t dlfs_cksum;	  /* 508: checksum for superblock checking */
942*0a6a1f1dSLionel Sambuc };
943*0a6a1f1dSLionel Sambuc 
944d65f6f70SBen Gras /* Type used for the inode bitmap */
945d65f6f70SBen Gras typedef u_int32_t lfs_bm_t;
946d65f6f70SBen Gras 
947d65f6f70SBen Gras /*
948d65f6f70SBen Gras  * Linked list of segments whose byte count needs updating following a
949d65f6f70SBen Gras  * file truncation.
950d65f6f70SBen Gras  */
951d65f6f70SBen Gras struct segdelta {
952d65f6f70SBen Gras 	long segnum;
953d65f6f70SBen Gras 	size_t num;
954d65f6f70SBen Gras 	LIST_ENTRY(segdelta) list;
955d65f6f70SBen Gras };
956d65f6f70SBen Gras 
957d65f6f70SBen Gras /*
958d65f6f70SBen Gras  * In-memory super block.
959d65f6f70SBen Gras  */
960d65f6f70SBen Gras struct lfs {
961*0a6a1f1dSLionel Sambuc 	union {				/* on-disk parameters */
962*0a6a1f1dSLionel Sambuc 		struct dlfs u_32;
963*0a6a1f1dSLionel Sambuc 		struct dlfs64 u_64;
964*0a6a1f1dSLionel Sambuc 	} lfs_dlfs_u;
965d65f6f70SBen Gras 
966d65f6f70SBen Gras /* These fields are set at mount time and are meaningless on disk. */
967*0a6a1f1dSLionel Sambuc 	unsigned lfs_is64 : 1,		/* are we lfs64 or lfs32? */
968*0a6a1f1dSLionel Sambuc 		lfs_dobyteswap : 1,	/* are we opposite-endian? */
969*0a6a1f1dSLionel Sambuc 		lfs_hasolddirfmt : 1;	/* dir entries have no d_type */
970*0a6a1f1dSLionel Sambuc 
971d65f6f70SBen Gras 	struct segment *lfs_sp;		/* current segment being written */
972d65f6f70SBen Gras 	struct vnode *lfs_ivnode;	/* vnode for the ifile */
973d65f6f70SBen Gras 	u_int32_t  lfs_seglock;		/* single-thread the segment writer */
974d65f6f70SBen Gras 	pid_t	  lfs_lockpid;		/* pid of lock holder */
975d65f6f70SBen Gras 	lwpid_t	  lfs_locklwp;		/* lwp of lock holder */
976d65f6f70SBen Gras 	u_int32_t lfs_iocount;		/* number of ios pending */
977d65f6f70SBen Gras 	u_int32_t lfs_writer;		/* don't allow any dirops to start */
978d65f6f70SBen Gras 	u_int32_t lfs_dirops;		/* count of active directory ops */
979d65f6f70SBen Gras 	u_int32_t lfs_dirvcount;	/* count of VDIROP nodes in this fs */
980d65f6f70SBen Gras 	u_int32_t lfs_doifile;		/* Write ifile blocks on next write */
981d65f6f70SBen Gras 	u_int32_t lfs_nactive;		/* Number of segments since last ckp */
982d65f6f70SBen Gras 	int8_t	  lfs_fmod;		/* super block modified flag */
983d65f6f70SBen Gras 	int8_t	  lfs_ronly;		/* mounted read-only flag */
984d65f6f70SBen Gras #define LFS_NOTYET  0x01
985d65f6f70SBen Gras #define LFS_IFDIRTY 0x02
986d65f6f70SBen Gras #define LFS_WARNED  0x04
987d65f6f70SBen Gras #define LFS_UNDIROP 0x08
988d65f6f70SBen Gras 	int8_t	  lfs_flags;		/* currently unused flag */
989d65f6f70SBen Gras 	u_int16_t lfs_activesb;		/* toggle between superblocks */
990d65f6f70SBen Gras 	daddr_t	  lfs_sbactive;		/* disk address of current sb write */
991d65f6f70SBen Gras 	struct vnode *lfs_flushvp;	/* vnode being flushed */
992d65f6f70SBen Gras 	int lfs_flushvp_fakevref;	/* fake vref count for flushvp */
993d65f6f70SBen Gras 	struct vnode *lfs_unlockvp;	/* being inactivated in lfs_segunlock */
994d65f6f70SBen Gras 	u_int32_t lfs_diropwait;	/* # procs waiting on dirop flush */
995d65f6f70SBen Gras 	size_t lfs_devbsize;		/* Device block size */
996d65f6f70SBen Gras 	size_t lfs_devbshift;		/* Device block shift */
997d65f6f70SBen Gras 	krwlock_t lfs_fraglock;
998d65f6f70SBen Gras 	krwlock_t lfs_iflock;		/* Ifile lock */
999d65f6f70SBen Gras 	kcondvar_t lfs_stopcv;		/* Wrap lock */
1000d65f6f70SBen Gras 	struct lwp *lfs_stoplwp;
1001d65f6f70SBen Gras 	pid_t lfs_rfpid;		/* Process ID of roll-forward agent */
1002d65f6f70SBen Gras 	int	  lfs_nadirop;		/* number of active dirop nodes */
1003d65f6f70SBen Gras 	long	  lfs_ravail;		/* blocks pre-reserved for writing */
1004d65f6f70SBen Gras 	long	  lfs_favail;		/* blocks pre-reserved for writing */
100584d9c625SLionel Sambuc 	struct lfs_res_blk *lfs_resblk;	/* Reserved memory for pageout */
1006d65f6f70SBen Gras 	TAILQ_HEAD(, inode) lfs_dchainhd; /* dirop vnodes */
1007d65f6f70SBen Gras 	TAILQ_HEAD(, inode) lfs_pchainhd; /* paging vnodes */
1008d65f6f70SBen Gras #define LFS_RESHASH_WIDTH 17
1009d65f6f70SBen Gras 	LIST_HEAD(, lfs_res_blk) lfs_reshash[LFS_RESHASH_WIDTH];
1010d65f6f70SBen Gras 	int	  lfs_pdflush;		 /* pagedaemon wants us to flush */
1011d65f6f70SBen Gras 	u_int32_t **lfs_suflags;	/* Segment use flags */
1012d65f6f70SBen Gras #ifdef _KERNEL
1013d65f6f70SBen Gras 	struct pool lfs_clpool;		/* Pool for struct lfs_cluster */
1014d65f6f70SBen Gras 	struct pool lfs_bpppool;	/* Pool for bpp */
1015d65f6f70SBen Gras 	struct pool lfs_segpool;	/* Pool for struct segment */
1016d65f6f70SBen Gras #endif /* _KERNEL */
1017d65f6f70SBen Gras #define LFS_MAX_CLEANIND 64
1018*0a6a1f1dSLionel Sambuc 	daddr_t  lfs_cleanint[LFS_MAX_CLEANIND]; /* Active cleaning intervals */
1019d65f6f70SBen Gras 	int 	 lfs_cleanind;		/* Index into intervals */
1020d65f6f70SBen Gras 	int lfs_sleepers;		/* # procs sleeping this fs */
1021d65f6f70SBen Gras 	int lfs_pages;			/* dirty pages blaming this fs */
1022d65f6f70SBen Gras 	lfs_bm_t *lfs_ino_bitmap;	/* Inuse inodes bitmap */
1023d65f6f70SBen Gras 	int lfs_nowrap;			/* Suspend log wrap */
1024d65f6f70SBen Gras 	int lfs_wrappass;		/* Allow first log wrap requester to pass */
1025d65f6f70SBen Gras 	int lfs_wrapstatus;		/* Wrap status */
102684d9c625SLionel Sambuc 	int lfs_reclino;		/* Inode being reclaimed */
1027*0a6a1f1dSLionel Sambuc 	daddr_t lfs_startseg;           /* Segment we started writing at */
1028d65f6f70SBen Gras 	LIST_HEAD(, segdelta) lfs_segdhd;	/* List of pending trunc accounting events */
102984d9c625SLionel Sambuc 
103084d9c625SLionel Sambuc #ifdef _KERNEL
103184d9c625SLionel Sambuc 	/* ULFS-level information */
103284d9c625SLionel Sambuc 	u_int32_t um_flags;			/* ULFS flags (below) */
103384d9c625SLionel Sambuc 	u_long	um_nindir;			/* indirect ptrs per block */
103484d9c625SLionel Sambuc 	u_long	um_lognindir;			/* log2 of um_nindir */
103584d9c625SLionel Sambuc 	u_long	um_bptrtodb;			/* indir ptr to disk block */
103684d9c625SLionel Sambuc 	u_long	um_seqinc;			/* inc between seq blocks */
103784d9c625SLionel Sambuc 	int um_maxsymlinklen;
103884d9c625SLionel Sambuc 	int um_dirblksiz;
103984d9c625SLionel Sambuc 	u_int64_t um_maxfilesize;
104084d9c625SLionel Sambuc 
104184d9c625SLionel Sambuc 	/* Stuff used by quota2 code, not currently operable */
104284d9c625SLionel Sambuc 	unsigned lfs_use_quota2 : 1;
104384d9c625SLionel Sambuc 	uint32_t lfs_quota_magic;
104484d9c625SLionel Sambuc 	uint8_t lfs_quota_flags;
104584d9c625SLionel Sambuc 	uint64_t lfs_quotaino[2];
1046*0a6a1f1dSLionel Sambuc 
1047*0a6a1f1dSLionel Sambuc 	/* Sleep address replacing &lfs_avail inside the on-disk superblock */
1048*0a6a1f1dSLionel Sambuc 	/* XXX: should be replaced with a condvar */
1049*0a6a1f1dSLionel Sambuc 	int lfs_availsleep;
1050*0a6a1f1dSLionel Sambuc 	/* This one replaces &lfs_nextseg... all ditto */
1051*0a6a1f1dSLionel Sambuc 	int lfs_nextsegsleep;
105284d9c625SLionel Sambuc #endif
1053d65f6f70SBen Gras };
1054d65f6f70SBen Gras 
1055d65f6f70SBen Gras /*
1056d65f6f70SBen Gras  * Structures used by lfs_bmapv and lfs_markv to communicate information
1057d65f6f70SBen Gras  * about inodes and data blocks.
1058d65f6f70SBen Gras  */
1059d65f6f70SBen Gras typedef struct block_info {
1060*0a6a1f1dSLionel Sambuc 	u_int64_t bi_inode;		/* inode # */
1061*0a6a1f1dSLionel Sambuc 	int64_t	bi_lbn;			/* logical block w/in file */
1062*0a6a1f1dSLionel Sambuc 	int64_t	bi_daddr;		/* disk address of block */
1063*0a6a1f1dSLionel Sambuc 	u_int64_t bi_segcreate;		/* origin segment create time */
1064*0a6a1f1dSLionel Sambuc 	int	bi_version;		/* file version number */
1065*0a6a1f1dSLionel Sambuc 	int	bi_size;		/* size of the block (if fragment) */
1066*0a6a1f1dSLionel Sambuc 	void	*bi_bp;			/* data buffer */
1067*0a6a1f1dSLionel Sambuc } BLOCK_INFO;
1068*0a6a1f1dSLionel Sambuc 
1069*0a6a1f1dSLionel Sambuc /* Compatibility for 7.0 binaries */
1070*0a6a1f1dSLionel Sambuc typedef struct block_info_70 {
1071d65f6f70SBen Gras 	u_int32_t bi_inode;		/* inode # */
1072d65f6f70SBen Gras 	int32_t	bi_lbn;			/* logical block w/in file */
1073d65f6f70SBen Gras 	int32_t	bi_daddr;		/* disk address of block */
1074d65f6f70SBen Gras 	u_int64_t bi_segcreate;		/* origin segment create time */
1075d65f6f70SBen Gras 	int	bi_version;		/* file version number */
1076d65f6f70SBen Gras 	void	*bi_bp;			/* data buffer */
1077d65f6f70SBen Gras 	int	bi_size;		/* size of the block (if fragment) */
1078*0a6a1f1dSLionel Sambuc } BLOCK_INFO_70;
1079d65f6f70SBen Gras 
1080d65f6f70SBen Gras /* Compatibility for 1.5 binaries */
1081d65f6f70SBen Gras typedef struct block_info_15 {
1082d65f6f70SBen Gras 	u_int32_t bi_inode;		/* inode # */
1083d65f6f70SBen Gras 	int32_t	bi_lbn;			/* logical block w/in file */
1084d65f6f70SBen Gras 	int32_t	bi_daddr;		/* disk address of block */
1085d65f6f70SBen Gras 	u_int32_t bi_segcreate;		/* origin segment create time */
1086d65f6f70SBen Gras 	int	bi_version;		/* file version number */
1087d65f6f70SBen Gras 	void	*bi_bp;			/* data buffer */
1088d65f6f70SBen Gras 	int	bi_size;		/* size of the block (if fragment) */
1089d65f6f70SBen Gras } BLOCK_INFO_15;
1090d65f6f70SBen Gras 
1091*0a6a1f1dSLionel Sambuc /*
1092*0a6a1f1dSLionel Sambuc  * 32/64-bit-clean pointer to block pointers. This points into
1093*0a6a1f1dSLionel Sambuc  * already-existing storage; it is mostly used to access the block
1094*0a6a1f1dSLionel Sambuc  * pointers following a FINFO.
1095*0a6a1f1dSLionel Sambuc  */
1096*0a6a1f1dSLionel Sambuc union lfs_blocks {
1097*0a6a1f1dSLionel Sambuc 	int64_t *b64;
1098*0a6a1f1dSLionel Sambuc 	int32_t *b32;
1099*0a6a1f1dSLionel Sambuc };
1100*0a6a1f1dSLionel Sambuc 
1101d65f6f70SBen Gras /* In-memory description of a segment about to be written. */
1102d65f6f70SBen Gras struct segment {
1103d65f6f70SBen Gras 	struct lfs	 *fs;		/* file system pointer */
1104d65f6f70SBen Gras 	struct buf	**bpp;		/* pointer to buffer array */
1105d65f6f70SBen Gras 	struct buf	**cbpp;		/* pointer to next available bp */
1106d65f6f70SBen Gras 	struct buf	**start_bpp;	/* pointer to first bp in this set */
1107d65f6f70SBen Gras 	struct buf	 *ibp;		/* buffer pointer to inode page */
1108*0a6a1f1dSLionel Sambuc 	union lfs_dinode *idp;          /* pointer to ifile dinode */
1109*0a6a1f1dSLionel Sambuc 	FINFO *fip;			/* current fileinfo pointer */
1110d65f6f70SBen Gras 	struct vnode	 *vp;		/* vnode being gathered */
1111d65f6f70SBen Gras 	void	 *segsum;		/* segment summary info */
1112d65f6f70SBen Gras 	u_int32_t ninodes;		/* number of inodes in this segment */
1113d65f6f70SBen Gras 	int32_t seg_bytes_left;		/* bytes left in segment */
1114d65f6f70SBen Gras 	int32_t sum_bytes_left;		/* bytes left in summary block */
1115d65f6f70SBen Gras 	u_int32_t seg_number;		/* number of this segment */
1116*0a6a1f1dSLionel Sambuc 	union lfs_blocks start_lbp;	/* beginning lbn for this set */
1117d65f6f70SBen Gras 
111884d9c625SLionel Sambuc #define SEGM_CKP	0x0001		/* doing a checkpoint */
111984d9c625SLionel Sambuc #define SEGM_CLEAN	0x0002		/* cleaner call; don't sort */
112084d9c625SLionel Sambuc #define SEGM_SYNC	0x0004		/* wait for segment */
112184d9c625SLionel Sambuc #define SEGM_PROT	0x0008		/* don't inactivate at segunlock */
112284d9c625SLionel Sambuc #define SEGM_PAGEDAEMON	0x0010		/* pagedaemon called us */
112384d9c625SLionel Sambuc #define SEGM_WRITERD	0x0020		/* LFS writed called us */
112484d9c625SLionel Sambuc #define SEGM_FORCE_CKP	0x0040		/* Force checkpoint right away */
112584d9c625SLionel Sambuc #define SEGM_RECLAIM	0x0080		/* Writing to reclaim vnode */
112684d9c625SLionel Sambuc #define SEGM_SINGLE	0x0100		/* Opportunistic writevnodes */
1127d65f6f70SBen Gras 	u_int16_t seg_flags;		/* run-time flags for this segment */
1128d65f6f70SBen Gras 	u_int32_t seg_iocount;		/* number of ios pending */
1129d65f6f70SBen Gras 	int	  ndupino;		/* number of duplicate inodes */
1130d65f6f70SBen Gras };
1131d65f6f70SBen Gras 
1132d65f6f70SBen Gras /* Statistics Counters */
1133d65f6f70SBen Gras struct lfs_stats {	/* Must match sysctl list in lfs_vfsops.h ! */
1134d65f6f70SBen Gras 	u_int	segsused;
1135d65f6f70SBen Gras 	u_int	psegwrites;
1136d65f6f70SBen Gras 	u_int	psyncwrites;
1137d65f6f70SBen Gras 	u_int	pcleanwrites;
1138d65f6f70SBen Gras 	u_int	blocktot;
1139d65f6f70SBen Gras 	u_int	cleanblocks;
1140d65f6f70SBen Gras 	u_int	ncheckpoints;
1141d65f6f70SBen Gras 	u_int	nwrites;
1142d65f6f70SBen Gras 	u_int	nsync_writes;
1143d65f6f70SBen Gras 	u_int	wait_exceeded;
1144d65f6f70SBen Gras 	u_int	write_exceeded;
1145d65f6f70SBen Gras 	u_int	flush_invoked;
1146d65f6f70SBen Gras 	u_int	vflush_invoked;
1147d65f6f70SBen Gras 	u_int	clean_inlocked;
1148d65f6f70SBen Gras 	u_int	clean_vnlocked;
1149d65f6f70SBen Gras 	u_int   segs_reclaimed;
1150d65f6f70SBen Gras };
1151d65f6f70SBen Gras 
1152d65f6f70SBen Gras /* Fcntls to take the place of the lfs syscalls */
1153d65f6f70SBen Gras struct lfs_fcntl_markv {
1154d65f6f70SBen Gras 	BLOCK_INFO *blkiov;	/* blocks to relocate */
1155*0a6a1f1dSLionel Sambuc 	int blkcnt;		/* number of blocks (limited to 65536) */
1156d65f6f70SBen Gras };
1157d65f6f70SBen Gras 
1158d65f6f70SBen Gras #define LFCNSEGWAITALL	_FCNR_FSPRIV('L', 14, struct timeval)
1159d65f6f70SBen Gras #define LFCNSEGWAIT	_FCNR_FSPRIV('L', 15, struct timeval)
1160*0a6a1f1dSLionel Sambuc #define LFCNBMAPV	_FCNRW_FSPRIV('L', 16, struct lfs_fcntl_markv)
1161*0a6a1f1dSLionel Sambuc #define LFCNMARKV	_FCNRW_FSPRIV('L', 17, struct lfs_fcntl_markv)
1162d65f6f70SBen Gras #define LFCNRECLAIM	 _FCNO_FSPRIV('L', 4)
1163d65f6f70SBen Gras 
1164d65f6f70SBen Gras struct lfs_fhandle {
1165d65f6f70SBen Gras 	char space[28];	/* FHANDLE_SIZE_COMPAT (but used from userland too) */
1166d65f6f70SBen Gras };
1167d65f6f70SBen Gras #define LFCNREWIND       _FCNR_FSPRIV('L', 6, int)
1168d65f6f70SBen Gras #define LFCNINVAL        _FCNR_FSPRIV('L', 7, int)
1169d65f6f70SBen Gras #define LFCNRESIZE       _FCNR_FSPRIV('L', 8, int)
1170d65f6f70SBen Gras #define LFCNWRAPSTOP	 _FCNR_FSPRIV('L', 9, int)
1171d65f6f70SBen Gras #define LFCNWRAPGO	 _FCNR_FSPRIV('L', 10, int)
1172d65f6f70SBen Gras #define LFCNIFILEFH	 _FCNW_FSPRIV('L', 11, struct lfs_fhandle)
1173d65f6f70SBen Gras #define LFCNWRAPPASS	 _FCNR_FSPRIV('L', 12, int)
1174d65f6f70SBen Gras # define LFS_WRAP_GOING   0x0
1175d65f6f70SBen Gras # define LFS_WRAP_WAITING 0x1
1176d65f6f70SBen Gras #define LFCNWRAPSTATUS	 _FCNW_FSPRIV('L', 13, int)
1177d65f6f70SBen Gras 
1178d65f6f70SBen Gras /* Debug segment lock */
1179d65f6f70SBen Gras #ifdef notyet
1180d65f6f70SBen Gras # define ASSERT_SEGLOCK(fs) KASSERT(LFS_SEGLOCK_HELD(fs))
1181d65f6f70SBen Gras # define ASSERT_NO_SEGLOCK(fs) KASSERT(!LFS_SEGLOCK_HELD(fs))
1182d65f6f70SBen Gras # define ASSERT_DUNNO_SEGLOCK(fs)
1183d65f6f70SBen Gras # define ASSERT_MAYBE_SEGLOCK(fs)
1184d65f6f70SBen Gras #else /* !notyet */
1185d65f6f70SBen Gras # define ASSERT_DUNNO_SEGLOCK(fs) \
1186d65f6f70SBen Gras 	DLOG((DLOG_SEG, "lfs func %s seglock wrong (%d)\n", __func__, \
1187d65f6f70SBen Gras 		LFS_SEGLOCK_HELD(fs)))
1188d65f6f70SBen Gras # define ASSERT_SEGLOCK(fs) do {					\
1189d65f6f70SBen Gras 	if (!LFS_SEGLOCK_HELD(fs)) {					\
1190d65f6f70SBen Gras 		DLOG((DLOG_SEG, "lfs func %s seglock wrong (0)\n", __func__)); \
1191d65f6f70SBen Gras 	}								\
1192d65f6f70SBen Gras } while(0)
1193d65f6f70SBen Gras # define ASSERT_NO_SEGLOCK(fs) do {					\
1194d65f6f70SBen Gras 	if (LFS_SEGLOCK_HELD(fs)) {					\
1195d65f6f70SBen Gras 		DLOG((DLOG_SEG, "lfs func %s seglock wrong (1)\n", __func__)); \
1196d65f6f70SBen Gras 	}								\
1197d65f6f70SBen Gras } while(0)
1198d65f6f70SBen Gras # define ASSERT_MAYBE_SEGLOCK(x)
1199d65f6f70SBen Gras #endif /* !notyet */
1200d65f6f70SBen Gras 
120184d9c625SLionel Sambuc /*
120284d9c625SLionel Sambuc  * Arguments to mount LFS filesystems
120384d9c625SLionel Sambuc  */
120484d9c625SLionel Sambuc struct ulfs_args {
120584d9c625SLionel Sambuc 	char	*fspec;			/* block special device to mount */
120684d9c625SLionel Sambuc };
120784d9c625SLionel Sambuc 
1208d65f6f70SBen Gras __BEGIN_DECLS
1209d65f6f70SBen Gras void lfs_itimes(struct inode *, const struct timespec *,
1210d65f6f70SBen Gras     const struct timespec *, const struct timespec *);
1211d65f6f70SBen Gras __END_DECLS
1212d65f6f70SBen Gras 
1213d65f6f70SBen Gras #endif /* !_UFS_LFS_LFS_H_ */
1214