mirror of
https://git.FreeBSD.org/src.git
synced 2024-11-24 07:40:52 +00:00
Merge from Lite2:
- use new getvfsbyname() and mount(2) interface (mount_mfs) - use new fs include files - updated inode / cg layout calculations (?)
This commit is contained in:
parent
87564113d7
commit
75e2941193
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=23682
@ -5,6 +5,7 @@ SRCS= dkcksum.c getmntopts.c newfs.c mkfs.c
|
||||
MAN8= newfs.8
|
||||
|
||||
MOUNT= ${.CURDIR}/../mount
|
||||
CFLAGS+= -D_NEW_VFSCONF
|
||||
CFLAGS+=-DMFS -I${MOUNT}
|
||||
.PATH: ${MOUNT} ${.CURDIR}/../disklabel
|
||||
|
||||
|
@ -32,7 +32,7 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)mkfs.c 8.3 (Berkeley) 2/3/94";
|
||||
static char sccsid[] = "@(#)mkfs.c 8.11 (Berkeley) 5/3/95";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <unistd.h>
|
||||
@ -124,6 +124,7 @@ struct dinode zino[MAXBSIZE / sizeof(struct dinode)];
|
||||
int fsi, fso;
|
||||
daddr_t alloc();
|
||||
static int charsperline();
|
||||
long calcipg();
|
||||
|
||||
mkfs(pp, fsys, fi, fo)
|
||||
struct partition *pp;
|
||||
@ -133,6 +134,7 @@ mkfs(pp, fsys, fi, fo)
|
||||
register long i, mincpc, mincpg, inospercg;
|
||||
long cylno, rpos, blk, j, warn = 0;
|
||||
long used, mincpgcnt, bpcg;
|
||||
off_t usedb;
|
||||
long mapcramped, inodecramped;
|
||||
long postblsize, rotblsize, totalsbsize;
|
||||
int ppid, status, fd;
|
||||
@ -350,8 +352,7 @@ mkfs(pp, fsys, fi, fo)
|
||||
* Ensure that cylinder group with mincpg has enough space for inodes.
|
||||
*/
|
||||
inodecramped = 0;
|
||||
used *= sectorsize;
|
||||
inospercg = roundup((mincpg * bpcg - used) / density, INOPB(&sblock));
|
||||
inospercg = calcipg(mincpg, bpcg, &usedb);
|
||||
sblock.fs_ipg = inospercg;
|
||||
while (inospercg > MAXIPG(&sblock)) {
|
||||
inodecramped = 1;
|
||||
@ -359,8 +360,9 @@ mkfs(pp, fsys, fi, fo)
|
||||
sblock.fs_bsize == MINBSIZE)
|
||||
break;
|
||||
printf("With a block size of %d %s %d\n", sblock.fs_bsize,
|
||||
"minimum bytes per inode is",
|
||||
(mincpg * bpcg - used) / MAXIPG(&sblock) + 1);
|
||||
"minimum bytes per inode is",
|
||||
(int)((mincpg * (off_t)bpcg - usedb)
|
||||
/ MAXIPG(&sblock) + 1));
|
||||
sblock.fs_bsize >>= 1;
|
||||
sblock.fs_frag >>= 1;
|
||||
sblock.fs_fragshift -= 1;
|
||||
@ -371,14 +373,14 @@ mkfs(pp, fsys, fi, fo)
|
||||
break;
|
||||
}
|
||||
mincpg = sblock.fs_cpg;
|
||||
inospercg =
|
||||
roundup((mincpg * bpcg - used) / density, INOPB(&sblock));
|
||||
inospercg = calcipg(mincpg, bpcg, &usedb);
|
||||
sblock.fs_ipg = inospercg;
|
||||
}
|
||||
if (inodecramped) {
|
||||
if (inospercg > MAXIPG(&sblock)) {
|
||||
printf("Minimum bytes per inode is %d\n",
|
||||
(mincpg * bpcg - used) / MAXIPG(&sblock) + 1);
|
||||
(int)((mincpg * (off_t)bpcg - usedb)
|
||||
/ MAXIPG(&sblock) + 1));
|
||||
} else if (!mapcramped) {
|
||||
printf("With %d bytes per inode, ", density);
|
||||
printf("minimum cylinders per group is %d\n", mincpg);
|
||||
@ -413,13 +415,11 @@ mkfs(pp, fsys, fi, fo)
|
||||
/*
|
||||
* Must ensure there is enough space for inodes.
|
||||
*/
|
||||
sblock.fs_ipg = roundup((sblock.fs_cpg * bpcg - used) / density,
|
||||
INOPB(&sblock));
|
||||
sblock.fs_ipg = calcipg(sblock.fs_cpg, bpcg, &usedb);
|
||||
while (sblock.fs_ipg > MAXIPG(&sblock)) {
|
||||
inodecramped = 1;
|
||||
sblock.fs_cpg -= mincpc;
|
||||
sblock.fs_ipg = roundup((sblock.fs_cpg * bpcg - used) / density,
|
||||
INOPB(&sblock));
|
||||
sblock.fs_ipg = calcipg(sblock.fs_cpg, bpcg, &usedb);
|
||||
}
|
||||
/*
|
||||
* Must ensure there is enough space to hold block map.
|
||||
@ -427,8 +427,7 @@ mkfs(pp, fsys, fi, fo)
|
||||
while (CGSIZE(&sblock) > sblock.fs_bsize) {
|
||||
mapcramped = 1;
|
||||
sblock.fs_cpg -= mincpc;
|
||||
sblock.fs_ipg = roundup((sblock.fs_cpg * bpcg - used) / density,
|
||||
INOPB(&sblock));
|
||||
sblock.fs_ipg = calcipg(sblock.fs_cpg, bpcg, &usedb);
|
||||
}
|
||||
sblock.fs_fpg = (sblock.fs_cpg * sblock.fs_spc) / NSPF(&sblock);
|
||||
if ((sblock.fs_cpg * sblock.fs_spc) % NSPB(&sblock) != 0) {
|
||||
@ -495,13 +494,13 @@ mkfs(pp, fsys, fi, fo)
|
||||
if (sblock.fs_nrpos == 8 && sblock.fs_cpc <= 16) {
|
||||
/* use old static table space */
|
||||
sblock.fs_postbloff = (char *)(&sblock.fs_opostbl[0][0]) -
|
||||
(char *)(&sblock.fs_link);
|
||||
(char *)(&sblock.fs_firstfield);
|
||||
sblock.fs_rotbloff = &sblock.fs_space[0] -
|
||||
(u_char *)(&sblock.fs_link);
|
||||
(u_char *)(&sblock.fs_firstfield);
|
||||
} else {
|
||||
/* use dynamic table space */
|
||||
sblock.fs_postbloff = &sblock.fs_space[0] -
|
||||
(u_char *)(&sblock.fs_link);
|
||||
(u_char *)(&sblock.fs_firstfield);
|
||||
sblock.fs_rotbloff = sblock.fs_postbloff + postblsize;
|
||||
totalsbsize += postblsize;
|
||||
}
|
||||
@ -711,7 +710,7 @@ initcg(cylno, utime)
|
||||
if (cylno == 0)
|
||||
dupper += howmany(sblock.fs_cssize, sblock.fs_fsize);
|
||||
cs = fscs + cylno;
|
||||
bzero(&acg, sblock.fs_cgsize);
|
||||
memset(&acg, 0, sblock.fs_cgsize);
|
||||
acg.cg_time = utime;
|
||||
acg.cg_magic = CG_MAGIC;
|
||||
acg.cg_cgx = cylno;
|
||||
@ -723,7 +722,7 @@ initcg(cylno, utime)
|
||||
acg.cg_ndblk = dmax - cbase;
|
||||
if (sblock.fs_contigsumsize > 0)
|
||||
acg.cg_nclusterblks = acg.cg_ndblk / sblock.fs_frag;
|
||||
acg.cg_btotoff = &acg.cg_space[0] - (u_char *)(&acg.cg_link);
|
||||
acg.cg_btotoff = &acg.cg_space[0] - (u_char *)(&acg.cg_firstfield);
|
||||
acg.cg_boff = acg.cg_btotoff + sblock.fs_cpg * sizeof(long);
|
||||
acg.cg_iusedoff = acg.cg_boff +
|
||||
sblock.fs_cpg * sblock.fs_nrpos * sizeof(short);
|
||||
@ -742,7 +741,7 @@ initcg(cylno, utime)
|
||||
acg.cg_nextfreeoff = acg.cg_clusteroff + howmany
|
||||
(sblock.fs_cpg * sblock.fs_spc / NSPB(&sblock), NBBY);
|
||||
}
|
||||
if (acg.cg_nextfreeoff - (long)(&acg.cg_link) > sblock.fs_cgsize) {
|
||||
if (acg.cg_nextfreeoff - (long)(&acg.cg_firstfield) > sblock.fs_cgsize) {
|
||||
printf("Panic: cylinder group too big\n");
|
||||
exit(37);
|
||||
}
|
||||
@ -799,7 +798,7 @@ initcg(cylno, utime)
|
||||
}
|
||||
}
|
||||
if (sblock.fs_contigsumsize > 0) {
|
||||
long *sump = cg_clustersum(&acg);
|
||||
int32_t *sump = cg_clustersum(&acg);
|
||||
u_char *mapp = cg_clustersfree(&acg);
|
||||
int map = *mapp++;
|
||||
int bit = 1;
|
||||
@ -888,9 +887,9 @@ fsinit(utime)
|
||||
/*
|
||||
* initialize the node
|
||||
*/
|
||||
node.di_atime.tv_sec = utime;
|
||||
node.di_mtime.tv_sec = utime;
|
||||
node.di_ctime.tv_sec = utime;
|
||||
node.di_atime = utime;
|
||||
node.di_mtime = utime;
|
||||
node.di_ctime = utime;
|
||||
#ifdef LOSTDIR
|
||||
/*
|
||||
* create the lost+found directory
|
||||
@ -898,12 +897,12 @@ fsinit(utime)
|
||||
if (Oflag) {
|
||||
(void)makedir((struct direct *)olost_found_dir, 2);
|
||||
for (i = DIRBLKSIZ; i < sblock.fs_bsize; i += DIRBLKSIZ)
|
||||
bcopy(&olost_found_dir[2], &buf[i],
|
||||
memmove(&buf[i], &olost_found_dir[2],
|
||||
DIRSIZ(0, &olost_found_dir[2]));
|
||||
} else {
|
||||
(void)makedir(lost_found_dir, 2);
|
||||
for (i = DIRBLKSIZ; i < sblock.fs_bsize; i += DIRBLKSIZ)
|
||||
bcopy(&lost_found_dir[2], &buf[i],
|
||||
memmove(&buf[i], &lost_found_dir[2],
|
||||
DIRSIZ(0, &lost_found_dir[2]));
|
||||
}
|
||||
node.di_mode = IFDIR | UMASK;
|
||||
@ -946,12 +945,12 @@ makedir(protodir, entries)
|
||||
spcleft = DIRBLKSIZ;
|
||||
for (cp = buf, i = 0; i < entries - 1; i++) {
|
||||
protodir[i].d_reclen = DIRSIZ(0, &protodir[i]);
|
||||
bcopy(&protodir[i], cp, protodir[i].d_reclen);
|
||||
memmove(cp, &protodir[i], protodir[i].d_reclen);
|
||||
cp += protodir[i].d_reclen;
|
||||
spcleft -= protodir[i].d_reclen;
|
||||
}
|
||||
protodir[i].d_reclen = spcleft;
|
||||
bcopy(&protodir[i], cp, DIRSIZ(0, &protodir[i]));
|
||||
memmove(cp, &protodir[i], DIRSIZ(0, &protodir[i]));
|
||||
return (DIRBLKSIZ);
|
||||
}
|
||||
|
||||
@ -984,7 +983,8 @@ alloc(size, mode)
|
||||
goth:
|
||||
blkno = fragstoblks(&sblock, d);
|
||||
clrblock(&sblock, cg_blksfree(&acg), blkno);
|
||||
clrbit(cg_clustersfree(&acg), blkno);
|
||||
if (sblock.fs_contigsumsize > 0)
|
||||
clrbit(cg_clustersfree(&acg), blkno);
|
||||
acg.cg_cs.cs_nbfree--;
|
||||
sblock.fs_cstotal.cs_nbfree--;
|
||||
fscs[0].cs_nbfree--;
|
||||
@ -1009,6 +1009,43 @@ alloc(size, mode)
|
||||
return (d);
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate number of inodes per group.
|
||||
*/
|
||||
long
|
||||
calcipg(cpg, bpcg, usedbp)
|
||||
long cpg;
|
||||
long bpcg;
|
||||
off_t *usedbp;
|
||||
{
|
||||
int i;
|
||||
long ipg, new_ipg, ncg, ncyl;
|
||||
off_t usedb;
|
||||
|
||||
/*
|
||||
* Prepare to scale by fssize / (number of sectors in cylinder groups).
|
||||
* Note that fssize is still in sectors, not filesystem blocks.
|
||||
*/
|
||||
ncyl = howmany(fssize, secpercyl);
|
||||
ncg = howmany(ncyl, cpg);
|
||||
/*
|
||||
* Iterate a few times to allow for ipg depending on itself.
|
||||
*/
|
||||
ipg = 0;
|
||||
for (i = 0; i < 10; i++) {
|
||||
usedb = (sblock.fs_iblkno + ipg / INOPF(&sblock))
|
||||
* NSPF(&sblock) * (off_t)sectorsize;
|
||||
new_ipg = (cpg * (quad_t)bpcg - usedb) / density * fssize
|
||||
/ ncg / secpercyl / cpg;
|
||||
new_ipg = roundup(new_ipg, INOPB(&sblock));
|
||||
if (new_ipg == ipg)
|
||||
break;
|
||||
ipg = new_ipg;
|
||||
}
|
||||
*usedbp = usedb;
|
||||
return (ipg);
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate an inode on the disk
|
||||
*/
|
||||
@ -1097,7 +1134,7 @@ realloc(ptr, size)
|
||||
|
||||
if ((p = malloc(size)) == NULL)
|
||||
return (NULL);
|
||||
bcopy(ptr, p, size);
|
||||
memmove(p, ptr, size);
|
||||
free(ptr);
|
||||
return (p);
|
||||
}
|
||||
@ -1113,7 +1150,7 @@ calloc(size, numelm)
|
||||
|
||||
size *= numelm;
|
||||
base = malloc(size);
|
||||
bzero(base, size);
|
||||
memset(base, 0, size);
|
||||
return (base);
|
||||
}
|
||||
|
||||
@ -1138,7 +1175,7 @@ rdfs(bno, size, bf)
|
||||
int n;
|
||||
|
||||
if (mfs) {
|
||||
bcopy(membase + bno * sectorsize, bf, size);
|
||||
memmove(bf, membase + bno * sectorsize, size);
|
||||
return;
|
||||
}
|
||||
if (lseek(fsi, (off_t)bno * sectorsize, 0) < 0) {
|
||||
@ -1165,7 +1202,7 @@ wtfs(bno, size, bf)
|
||||
int n;
|
||||
|
||||
if (mfs) {
|
||||
bcopy(bf, membase + bno * sectorsize, size);
|
||||
memmove(membase + bno * sectorsize, bf, size);
|
||||
return;
|
||||
}
|
||||
if (Nflag)
|
||||
|
@ -29,9 +29,9 @@
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)newfs.8 8.3 (Berkeley) 3/27/94
|
||||
.\" @(#)newfs.8 8.6 (Berkeley) 5/3/95
|
||||
.\"
|
||||
.Dd March 27, 1994
|
||||
.Dd May 3, 1995
|
||||
.Dt NEWFS 8
|
||||
.Os BSD 4.2
|
||||
.Sh NAME
|
||||
@ -42,6 +42,7 @@
|
||||
.Nm newfs
|
||||
.Op Fl NO
|
||||
.Op Fl S Ar sector-size
|
||||
.Op Fl T Ar disktype
|
||||
.Op Fl a Ar maxcontig
|
||||
.Op Fl b Ar block-size
|
||||
.Op Fl c Ar cylinders
|
||||
@ -52,6 +53,7 @@
|
||||
.Op Fl k Ar skew
|
||||
.Op Fl l Ar interleave
|
||||
.Op Fl m Ar free space
|
||||
.Op Fl n Ar rotational positions
|
||||
.Op Fl o Ar optimization
|
||||
.Op Fl p Ar sectors
|
||||
.Op Fl r Ar revolutions
|
||||
@ -72,6 +74,7 @@
|
||||
.Op Fl f Ar frag-size
|
||||
.Op Fl i Ar bytes
|
||||
.Op Fl m Ar free space
|
||||
.Op Fl n Ar rotational positions
|
||||
.Op Fl o Ar options
|
||||
.Op Fl s Ar size
|
||||
.Ar special node
|
||||
@ -108,7 +111,10 @@ The parameters to
|
||||
.Nm mount_mfs
|
||||
are the same as those to
|
||||
.Nm newfs .
|
||||
The special file is only used to read the disk label which provides
|
||||
If the
|
||||
.Fl T
|
||||
flag is specified (see below), the special file is unused.
|
||||
Otherwise, it is only used to read the disk label which provides
|
||||
a set of configuration parameters for the memory based file system.
|
||||
The special file is typically that of the primary swap area,
|
||||
since that is where the file system will be backed up when
|
||||
@ -132,6 +138,10 @@ without really creating the file system.
|
||||
Creates a 4.3BSD format filesystem.
|
||||
This options is primarily used to build root filesystems
|
||||
that can be understood by older boot ROMs.
|
||||
.It Fl T
|
||||
Uses information for the specified disk from
|
||||
.Pa /etc/disktab
|
||||
instead of trying to get the information from a disklabel.
|
||||
.It Fl a Ar maxcontig
|
||||
This specifies the maximum number of contiguous blocks that will be
|
||||
laid out before forcing a rotational delay (see the
|
||||
@ -153,6 +163,7 @@ The default is 0 milliseconds.
|
||||
See
|
||||
.Xr tunefs 8
|
||||
for more details on how to set this option.
|
||||
.ne 1i
|
||||
.It Fl e Ar maxbpg
|
||||
This indicates the maximum number of blocks any single file can
|
||||
allocate out of a cylinder group before it is forced to begin
|
||||
@ -234,6 +245,7 @@ They are not counted as part of the sectors/track
|
||||
since they are not available to the file system for data allocation.
|
||||
.It Fl r Ar revolutions/minute
|
||||
The speed of the disk in revolutions per minute.
|
||||
.ne 1i
|
||||
.It Fl t Ar #tracks/cylinder
|
||||
The number of tracks/cylinder available for data allocation by the file
|
||||
system.
|
||||
|
@ -32,7 +32,7 @@
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)newfs.c 8.8 (Berkeley) 4/18/94";
|
||||
static char sccsid[] = "@(#)newfs.c 8.13 (Berkeley) 5/1/95";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
@ -52,7 +52,9 @@ static char copyright[] =
|
||||
#include <sys/mount.h>
|
||||
|
||||
#include <ufs/ufs/dir.h>
|
||||
#include <ufs/ufs/dinode.h>
|
||||
#include <ufs/ffs/fs.h>
|
||||
#include <ufs/ufs/ufsmount.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
@ -216,10 +218,11 @@ main(argc, argv)
|
||||
int fsi, fso, len, n;
|
||||
char *cp, *s1, *s2, *special, *opstring, buf[BUFSIZ];
|
||||
#ifdef MFS
|
||||
struct vfsconf *vfc;
|
||||
struct vfsconf vfc;
|
||||
int error;
|
||||
#endif
|
||||
|
||||
if (progname = rindex(*argv, '/'))
|
||||
if (progname = strrchr(*argv, '/'))
|
||||
++progname;
|
||||
else
|
||||
progname = *argv;
|
||||
@ -353,7 +356,7 @@ main(argc, argv)
|
||||
usage();
|
||||
|
||||
special = argv[0];
|
||||
cp = rindex(special, '/');
|
||||
cp = strrchr(special, '/');
|
||||
if (cp == 0) {
|
||||
/*
|
||||
* No path prefix; try /dev/r%s then /dev/%s.
|
||||
@ -406,8 +409,9 @@ main(argc, argv)
|
||||
if ((st.st_mode & S_IFMT) != S_IFCHR && !mfs)
|
||||
printf("%s: %s: not a character-special device\n",
|
||||
progname, special);
|
||||
cp = index(argv[0], '\0') - 1;
|
||||
if (cp == 0 || (*cp < 'a' || *cp > 'h') && !isdigit(*cp))
|
||||
cp = strchr(argv[0], '\0') - 1;
|
||||
if (cp == (char *)-1 ||
|
||||
(*cp < 'a' || *cp > 'h') && !isdigit(*cp))
|
||||
fatal("%s: can't figure out file system partition",
|
||||
argv[0]);
|
||||
#ifdef COMPAT
|
||||
@ -566,17 +570,17 @@ main(argc, argv)
|
||||
args.base = membase;
|
||||
args.size = fssize * sectorsize;
|
||||
|
||||
vfc = getvfsbyname("mfs");
|
||||
if(!vfc && vfsisloadable("mfs")) {
|
||||
if(vfsload("mfs")) {
|
||||
err(1, "vfsload(mfs)");
|
||||
}
|
||||
error = getvfsbyname("mfs", &vfc);
|
||||
if (error && vfsisloadable("mfs")) {
|
||||
if (vfsload("mfs"))
|
||||
fatal("vfsload(mfs)");
|
||||
endvfsent(); /* flush cache */
|
||||
vfc = getvfsbyname("mfs");
|
||||
error = getvfsbyname("mfs", &vfc);
|
||||
}
|
||||
if (error)
|
||||
fatal("mfs filesystem not available");
|
||||
|
||||
if (mount(vfc ? vfc->vfc_index : MOUNT_MFS, argv[1], mntflags,
|
||||
&args) < 0)
|
||||
if (mount(vfc.vfc_name, argv[1], mntflags, &args) < 0)
|
||||
fatal("%s: %s", argv[1], strerror(errno));
|
||||
if(filename) {
|
||||
munmap(membase,fssize * sectorsize);
|
||||
|
Loading…
Reference in New Issue
Block a user