xref: /freebsd/sbin/newfs/newfs.h (revision c66ec88fed842fbaad62c30d510644ceb7bd2d71)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 2002 Networks Associates Technology, Inc.
5  * All rights reserved.
6  *
7  * This software was developed for the FreeBSD Project by Marshall
8  * Kirk McKusick and Network Associates Laboratories, the Security
9  * Research Division of Network Associates, Inc. under DARPA/SPAWAR
10  * contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA CHATS
11  * research program.
12  *
13  * Copyright (c) 1980, 1989, 1993
14  *	The Regents of the University of California.  All rights reserved.
15  *
16  * Redistribution and use in source and binary forms, with or without
17  * modification, are permitted provided that the following conditions
18  * are met:
19  * 1. Redistributions of source code must retain the above copyright
20  *    notice, this list of conditions and the following disclaimer.
21  * 2. Redistributions in binary form must reproduce the above copyright
22  *    notice, this list of conditions and the following disclaimer in the
23  *    documentation and/or other materials provided with the distribution.
24  * 3. Neither the name of the University nor the names of its contributors
25  *    may be used to endorse or promote products derived from this software
26  *    without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38  * SUCH DAMAGE.
39  *
40  * $FreeBSD$
41  */
42 
43 #include <libufs.h>
44 
45 /*
46  * The following two constants set the default block and fragment sizes.
47  * Both constants must be a power of 2 and meet the following constraints:
48  *	MINBSIZE <= DESBLKSIZE <= MAXBSIZE
49  *	sectorsize <= DESFRAGSIZE <= DESBLKSIZE
50  *	DESBLKSIZE / DESFRAGSIZE <= 8
51  */
52 #define	DFL_FRAGSIZE	4096
53 #define	DFL_BLKSIZE	32768
54 
55 /*
56  * Cylinder groups may have up to MAXBLKSPERCG blocks. The actual
57  * number used depends upon how much information can be stored
58  * in a cylinder group map which must fit in a single file system
59  * block. The default is to use as many as possible blocks per group.
60  */
61 #define	MAXBLKSPERCG	0x7fffffff	/* desired fs_fpg ("infinity") */
62 
63 /*
64  * MAXBLKPG determines the maximum number of data blocks which are
65  * placed in a single cylinder group. The default is one indirect
66  * block worth of data blocks.
67  */
68 #define MAXBLKPG(bsize)	((bsize) / sizeof(ufs2_daddr_t))
69 
70 /*
71  * Each file system has a number of inodes statically allocated.
72  * We allocate one inode slot per NFPI fragments, expecting this
73  * to be far more than we will ever need.
74  */
75 #define	NFPI		2
76 
77 /*
78  * variables set up by front end.
79  */
80 extern int	Eflag;		/* Erase previous disk contents */
81 extern int	Lflag;		/* add a volume label */
82 extern int	Nflag;		/* run mkfs without writing file system */
83 extern int	Oflag;		/* build UFS1 format file system */
84 extern int	Rflag;		/* regression test */
85 extern int	Uflag;		/* enable soft updates for file system */
86 extern int	jflag;		/* enable soft updates journaling for filesys */
87 extern int	Xflag;		/* exit in middle of newfs for testing */
88 extern int	Jflag;		/* enable gjournal for file system */
89 extern int	lflag;		/* enable multilabel MAC for file system */
90 extern int	nflag;		/* do not create .snap directory */
91 extern int	tflag;		/* enable TRIM */
92 extern intmax_t	fssize;		/* file system size */
93 extern off_t	mediasize;	/* device size */
94 extern int	sectorsize;	/* bytes/sector */
95 extern int	realsectorsize;	/* bytes/sector in hardware*/
96 extern int	fsize;		/* fragment size */
97 extern int	bsize;		/* block size */
98 extern int	maxbsize;	/* maximum clustering */
99 extern int	maxblkspercg;	/* maximum blocks per cylinder group */
100 extern int	minfree;	/* free space threshold */
101 extern int	metaspace;	/* space held for metadata blocks */
102 extern int	opt;		/* optimization preference (space or time) */
103 extern int	density;	/* number of bytes per inode */
104 extern int	maxcontig;	/* max contiguous blocks to allocate */
105 extern int	maxbpg;		/* maximum blocks per file in a cyl group */
106 extern int	avgfilesize;	/* expected average file size */
107 extern int	avgfilesperdir;	/* expected number of files per directory */
108 extern u_char	*volumelabel;	/* volume label for filesystem */
109 extern struct uufsd disk;	/* libufs disk structure */
110 
111 /*
112  * To override a limitation in libufs, export the offset (in sectors) of the
113  * partition on the underlying media (file or disk). The value is used as
114  * an offset for all accesses to the media through bread(), which is only
115  * invoked directly in this program.
116  * For bwrite() we need a different approach, namely override the library
117  * version with one defined here. This is because bwrite() is called also
118  * by the library function sbwrite() which we cannot intercept nor want to
119  * rewrite. As a consequence, the internal version of bwrite() adds the
120  * partition offset itself when calling the underlying function, pwrite().
121  *
122  * XXX This info really ought to go into the struct uufsd, at which point
123  * we can remove the above hack.
124  */
125 extern ufs2_daddr_t part_ofs;	/* partition offset in blocks */
126 
127 void mkfs (struct partition *, char *);
128