192717Sphk/*
298542Smckusick * Copyright (c) 2002 Networks Associates Technology, Inc.
398542Smckusick * All rights reserved.
498542Smckusick *
598542Smckusick * This software was developed for the FreeBSD Project by Marshall
698542Smckusick * Kirk McKusick and Network Associates Laboratories, the Security
798542Smckusick * Research Division of Network Associates, Inc. under DARPA/SPAWAR
898542Smckusick * contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA CHATS
9110884Smckusick * research program.
1098542Smckusick *
1192717Sphk * Copyright (c) 1980, 1989, 1993
1292717Sphk *	The Regents of the University of California.  All rights reserved.
1392717Sphk *
1492717Sphk * Redistribution and use in source and binary forms, with or without
1592717Sphk * modification, are permitted provided that the following conditions
1692717Sphk * are met:
1792717Sphk * 1. Redistributions of source code must retain the above copyright
1892717Sphk *    notice, this list of conditions and the following disclaimer.
1992717Sphk * 2. Redistributions in binary form must reproduce the above copyright
2092717Sphk *    notice, this list of conditions and the following disclaimer in the
2192717Sphk *    documentation and/or other materials provided with the distribution.
2292717Sphk * 4. Neither the name of the University nor the names of its contributors
2392717Sphk *    may be used to endorse or promote products derived from this software
2492717Sphk *    without specific prior written permission.
2592717Sphk *
2692717Sphk * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2792717Sphk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2892717Sphk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2992717Sphk * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3092717Sphk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3192717Sphk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3292717Sphk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3392717Sphk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3492717Sphk * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3592717Sphk * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3692717Sphk * SUCH DAMAGE.
3792717Sphk *
3892717Sphk * $FreeBSD$
3992717Sphk */
4092717Sphk
41110671Sjmallett#include <libufs.h>
4292717Sphk
4392717Sphk/*
44203764Smckusick * The following two constants set the default block and fragment sizes.
45203764Smckusick * Both constants must be a power of 2 and meet the following constraints:
46203764Smckusick *	MINBSIZE <= DESBLKSIZE <= MAXBSIZE
47203764Smckusick *	sectorsize <= DESFRAGSIZE <= DESBLKSIZE
48203764Smckusick *	DESBLKSIZE / DESFRAGSIZE <= 8
49203764Smckusick */
50222319Smckusick#define	DFL_FRAGSIZE	4096
51222319Smckusick#define	DFL_BLKSIZE	32768
52203764Smckusick
53203764Smckusick/*
54203764Smckusick * Cylinder groups may have up to MAXBLKSPERCG blocks. The actual
55203764Smckusick * number used depends upon how much information can be stored
56203764Smckusick * in a cylinder group map which must fit in a single file system
57203764Smckusick * block. The default is to use as many as possible blocks per group.
58203764Smckusick */
59203764Smckusick#define	MAXBLKSPERCG	0x7fffffff	/* desired fs_fpg ("infinity") */
60203764Smckusick
61203764Smckusick/*
62203764Smckusick * MAXBLKPG determines the maximum number of data blocks which are
63203764Smckusick * placed in a single cylinder group. The default is one indirect
64203764Smckusick * block worth of data blocks.
65203764Smckusick */
66203764Smckusick#define MAXBLKPG(bsize)	((bsize) / sizeof(ufs2_daddr_t))
67203764Smckusick
68203764Smckusick/*
69203764Smckusick * Each file system has a number of inodes statically allocated.
70203764Smckusick * We allocate one inode slot per NFPI fragments, expecting this
71203764Smckusick * to be far more than we will ever need.
72203764Smckusick */
73228794Smckusick#define	NFPI		2
74203764Smckusick
75203764Smckusick/*
7692717Sphk * variables set up by front end.
7792717Sphk */
78174675Sphkextern int	Eflag;		/* Erase previous disk contents */
79110174Sgordonextern int	Lflag;		/* add a volume label */
80102231Strhodesextern int	Nflag;		/* run mkfs without writing file system */
81102231Strhodesextern int	Oflag;		/* build UFS1 format file system */
8292722Sphkextern int	Rflag;		/* regression test */
83102231Strhodesextern int	Uflag;		/* enable soft updates for file system */
84227081Sedextern int	jflag;		/* enable soft updates journaling for filesys */
85174675Sphkextern int	Xflag;		/* exit in middle of newfs for testing */
86163842Spjdextern int	Jflag;		/* enable gjournal for file system */
87126254Srwatsonextern int	lflag;		/* enable multilabel MAC for file system */
88140603Swesextern int	nflag;		/* do not create .snap directory */
89216798Skibextern int	tflag;		/* enable TRIM */
90174011Syarextern intmax_t	fssize;		/* file system size */
91242379Straszextern off_t	mediasize;	/* device size */
92204909Ssobomaxextern int	sectorsize;	/* bytes/sector */
9392717Sphkextern int	realsectorsize;	/* bytes/sector in hardware*/
94204919Ssobomaxextern int	fsize;		/* fragment size */
95204919Ssobomaxextern int	bsize;		/* block size */
96204919Ssobomaxextern int	maxbsize;	/* maximum clustering */
97204919Ssobomaxextern int	maxblkspercg;	/* maximum blocks per cylinder group */
9892717Sphkextern int	minfree;	/* free space threshold */
99248623Smckusickextern int	metaspace;	/* space held for metadata blocks */
10092717Sphkextern int	opt;		/* optimization preference (space or time) */
101204919Ssobomaxextern int	density;	/* number of bytes per inode */
102204919Ssobomaxextern int	maxcontig;	/* max contiguous blocks to allocate */
103204919Ssobomaxextern int	maxbpg;		/* maximum blocks per file in a cyl group */
104204919Ssobomaxextern int	avgfilesize;	/* expected average file size */
105204919Ssobomaxextern int	avgfilesperdir;	/* expected number of files per directory */
106110174Sgordonextern u_char	*volumelabel;	/* volume label for filesystem */
107110671Sjmallettextern struct uufsd disk;	/* libufs disk structure */
10895357Sphk
109185588Sluigi/*
110185588Sluigi * To override a limitation in libufs, export the offset (in sectors) of the
111185588Sluigi * partition on the underlying media (file or disk). The value is used as
112185588Sluigi * an offset for all accesses to the media through bread(), which is only
113185588Sluigi * invoked directly in this program.
114185588Sluigi * For bwrite() we need a different approach, namely override the library
115185588Sluigi * version with one defined here. This is because bwrite() is called also
116185588Sluigi * by the library function sbwrite() which we cannot intercept nor want to
117185588Sluigi * rewrite. As a consequence, the internal version of bwrite() adds the
118185588Sluigi * partition offset itself when calling the underlying function, pwrite().
119185588Sluigi *
120185588Sluigi * XXX This info really ought to go into the struct uufsd, at which point
121185588Sluigi * we can remove the above hack.
122185588Sluigi */
123185588Sluigiextern ufs2_daddr_t part_ofs;	/* partition offset in blocks */
124185588Sluigi
12595357Sphkvoid mkfs (struct partition *, char *);
126