Make mkfs -N work again (was trying to read filesystem).

Correct calculation of number of inodes from density for small filesystems.
Add a '-n inodes' option so that the desired number of inodes can be
explicitly given - init needs this for mfs /dev, -i density is too crude.
This commit is contained in:
dsl 2003-09-11 12:19:44 +00:00
parent be42cc58d7
commit a83765310a
5 changed files with 55 additions and 16 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: extern.h,v 1.10 2003/09/03 19:29:12 dsl Exp $ */
/* $NetBSD: extern.h,v 1.11 2003/09/11 12:19:44 dsl Exp $ */
/*
* Copyright (c) 1997 Christos Zoulas. All rights reserved.
@ -47,6 +47,7 @@ extern int cpgflg; /* cylinders/cylinder group flag was given */
extern int minfree; /* free space threshold */
extern int opt; /* optimization preference (space or time) */
extern int density; /* number of bytes per inode */
extern int num_inodes; /* number of inodes (overrides density) */
extern int maxcontig; /* max contiguous blocks to allocate */
extern int maxbpg; /* maximum blocks per file in a cyl group */
extern int maxblkspercg;

View File

@ -1,4 +1,4 @@
/* $NetBSD: mkfs.c,v 1.80 2003/09/10 17:25:14 dsl Exp $ */
/* $NetBSD: mkfs.c,v 1.81 2003/09/11 12:19:44 dsl Exp $ */
/*
* Copyright (c) 1980, 1989, 1993
@ -73,7 +73,7 @@
#if 0
static char sccsid[] = "@(#)mkfs.c 8.11 (Berkeley) 5/3/95";
#else
__RCSID("$NetBSD: mkfs.c,v 1.80 2003/09/10 17:25:14 dsl Exp $");
__RCSID("$NetBSD: mkfs.c,v 1.81 2003/09/11 12:19:44 dsl Exp $");
#endif
#endif /* not lint */
@ -356,15 +356,23 @@ mkfs(struct partition *pp, const char *fsys, int fi, int fo,
(long long)sblock.fs_size, sblock.fs_iblkno + 3 * sblock.fs_frag);
exit(23);
}
/*
* Calculate 'per inode block' so we can allocate less than 1 fragment
* per inode - useful for /dev.
*/
fragsperinodeblk = MAX(numfrags(&sblock, density * INOPB(&sblock)), 1);
inodeblks = (sblock.fs_size - sblock.fs_iblkno - 2 * sblock.fs_frag) /
(sblock.fs_frag + fragsperinodeblk);
if (num_inodes != 0)
inodeblks = howmany(num_inodes, INOPB(&sblock));
else {
/*
* Calculate 'per inode block' so we can allocate less than
* 1 fragment per inode - useful for /dev.
*/
fragsperinodeblk = MAX(numfrags(&sblock,
density * INOPB(&sblock)), 1);
inodeblks = (sblock.fs_size - sblock.fs_iblkno) /
(sblock.fs_frag + fragsperinodeblk);
}
if (inodeblks == 0)
inodeblks = 1;
/* Ensure that there are at least 2 data blocks (or we fail below) */
if (inodeblks > (sblock.fs_size - sblock.fs_iblkno)/sblock.fs_frag - 2)
inodeblks = (sblock.fs_size-sblock.fs_iblkno)/sblock.fs_frag-2;
/* Even UFS2 limits number of inodes to 2^31 (fs_ipg is int32_t) */
if (inodeblks * INOPB(&sblock) >= 1ull << 31)
inodeblks = ((1ull << 31) - NBBY) / INOPB(&sblock);
@ -1369,6 +1377,9 @@ zap_old_sblock(int sblkoff)
};
const struct fsm *fsm;
if (Nflag)
return;
if (cg0_data == 0)
/* For FFSv1 this could include all the inodes. */
cg0_data = cgsblock(&sblock, 0) * sblock.fs_fsize + iobufsize;

View File

@ -1,4 +1,4 @@
.\" $NetBSD: mount_mfs.8,v 1.10 2003/08/21 16:02:32 dsl Exp $
.\" $NetBSD: mount_mfs.8,v 1.11 2003/09/11 12:19:44 dsl Exp $
.\"
.\" Copyright (c) 1983, 1987, 1991, 1993, 1994
.\" The Regents of the University of California. All rights reserved.
@ -46,6 +46,7 @@
.Op Fl g Ar groupname
.Op Fl i Ar bytes-per-inode
.Op Fl m Ar free-space
.Op Fl n Ar inodes
.Op Fl o Ar options
.Op Fl p Ar permissions
.Op Fl s Ar size
@ -178,6 +179,15 @@ The default value used is 5%.
See
.Xr tunefs 8
for more details on how to set this option.
.It Fl n Ar inodes
This specifies the number of inodes for the filesystem.
If both
.Fl i
and
.Fl n
are specified then
.Fl n
takes precedence.
.It Fl o
Options are specified with a
.Fl o

View File

@ -1,4 +1,4 @@
.\" $NetBSD: newfs.8,v 1.55 2003/09/03 19:38:04 dsl Exp $
.\" $NetBSD: newfs.8,v 1.56 2003/09/11 12:19:44 dsl Exp $
.\"
.\" Copyright (c) 1983, 1987, 1991, 1993, 1994
.\" The Regents of the University of California. All rights reserved.
@ -47,6 +47,7 @@
.Op Fl h Ar avgfpdir
.Op Fl i Ar bytes-per-inode
.Op Fl m Ar free-space
.Op Fl n Ar inodes
.Op Fl O Ar filesystem-format
.Op Fl o Ar optimization
.Op Fl S Ar sector-size
@ -191,6 +192,15 @@ for more details on how to set this option.
.It Fl N
Causes the file system parameters to be printed out
without really creating the file system.
.It Fl n Ar inodes
This specifies the number of inodes for the filesystem.
If both
.Fl i
and
.Fl n
are specified then
.Fl n
takes precedence.
.It Fl O Ar filesystem-format
Select the filesystem-format
.Bl -tag -width 3n -offset indent -compact

View File

@ -1,4 +1,4 @@
/* $NetBSD: newfs.c,v 1.69 2003/09/03 19:29:14 dsl Exp $ */
/* $NetBSD: newfs.c,v 1.70 2003/09/11 12:19:45 dsl Exp $ */
/*
* Copyright (c) 1983, 1989, 1993, 1994
@ -78,7 +78,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1989, 1993, 1994\n\
#if 0
static char sccsid[] = "@(#)newfs.c 8.13 (Berkeley) 5/1/95";
#else
__RCSID("$NetBSD: newfs.c,v 1.69 2003/09/03 19:29:14 dsl Exp $");
__RCSID("$NetBSD: newfs.c,v 1.70 2003/09/11 12:19:45 dsl Exp $");
#endif
#endif /* not lint */
@ -196,6 +196,7 @@ int maxbsize = 0; /* maximum clustering */
int minfree = MINFREE; /* free space threshold */
int opt = DEFAULTOPT; /* optimization preference (space or time) */
int density; /* number of bytes per inode */
int num_inodes; /* number of inoder (overrides density) */
int maxcontig = 0; /* max contiguous blocks to allocate */
int maxbpg; /* maximum blocks per file in a cyl group */
int avgfilesize = AVFILESIZ;/* expected average file size */
@ -252,8 +253,8 @@ main(int argc, char *argv[])
errx(1, "insane maxpartitions value %d", maxpartitions);
opstring = mfs ?
"NT:a:b:c:d:e:f:g:h:i:m:o:p:s:u:" :
"B:FINO:S:T:Za:b:c:d:e:f:g:h:i:l:m:o:p:r:s:u:v:";
"NT:a:b:c:d:e:f:g:h:i:m:n:o:p:s:u:" :
"B:FINO:S:T:Za:b:c:d:e:f:g:h:i:l:m:n:o:p:r:s:u:v:";
while ((ch = getopt(argc, argv, opstring)) != -1)
switch (ch) {
case 'B':
@ -335,6 +336,10 @@ main(int argc, char *argv[])
minfree = strsuftoi("free space %",
optarg, 0, 99);
break;
case 'n':
num_inodes = strsuftoi("number of inodes",
optarg, 1, INT_MAX);
break;
case 'o':
if (mfs)
getmntopts(optarg, mopts, &mntflags, 0);
@ -467,6 +472,7 @@ main(int argc, char *argv[])
err(1, "writing image");
bufrem -= i;
}
free(buf);
}
}
@ -875,6 +881,7 @@ struct help_strings {
{ BOTH, "-h avgfpdir\taverage files per directory" },
{ BOTH, "-i density\tnumber of bytes per inode" },
{ BOTH, "-m minfree\tminimum free space %%" },
{ BOTH, "-n inodes\tnumder of inodes" },
{ BOTH, "-o optim\toptimization preference (`space' or `time')"
},
{ MFS_MOUNT, "-p perm\t\tpermissions (in octal)" },