Second try: attempt to import Lite2's newfs.

This commit is contained in:
bde 1996-10-15 08:40:58 +00:00
parent d9a51bde4c
commit e59ddf1629
3 changed files with 107 additions and 50 deletions

View File

@ -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>
@ -118,6 +118,7 @@ struct dinode zino[MAXBSIZE / sizeof(struct dinode)];
int fsi, fso;
daddr_t alloc();
long calcipg();
mkfs(pp, fsys, fi, fo)
struct partition *pp;
@ -127,6 +128,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;
@ -308,8 +310,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;
@ -317,8 +318,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;
@ -329,14 +331,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);
@ -371,13 +373,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.
@ -385,8 +385,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) {
@ -453,13 +452,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;
}
@ -562,6 +561,7 @@ mkfs(pp, fsys, fi, fo)
sblock.fs_cstotal.cs_nffree = 0;
sblock.fs_fmod = 0;
sblock.fs_ronly = 0;
sblock.fs_clean = 1;
/*
* Dump out summary information about file system.
*/
@ -587,7 +587,7 @@ mkfs(pp, fsys, fi, fo)
initcg(cylno, utime);
if (mfs)
continue;
if (cylno % 9 == 0)
if (cylno % 8 == 0)
printf("\n");
printf(" %d,", fsbtodb(&sblock, cgsblock(&sblock, cylno)));
}
@ -660,7 +660,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;
@ -672,7 +672,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);
@ -691,7 +691,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);
}
@ -748,7 +748,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;
@ -837,9 +837,9 @@ fsinit(utime)
/*
* initialize the node
*/
node.di_atime.ts_sec = utime;
node.di_mtime.ts_sec = utime;
node.di_ctime.ts_sec = utime;
node.di_atime = utime;
node.di_mtime = utime;
node.di_ctime = utime;
#ifdef LOSTDIR
/*
* create the lost+found directory
@ -847,12 +847,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;
@ -895,12 +895,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);
}
@ -933,7 +933,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--;
@ -958,6 +959,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
*/
@ -1046,7 +1084,7 @@ realloc(ptr, size)
if ((p = malloc(size)) == NULL)
return (NULL);
bcopy(ptr, p, size);
memmove(p, ptr, size);
free(ptr);
return (p);
}
@ -1062,7 +1100,7 @@ calloc(size, numelm)
size *= numelm;
base = malloc(size);
bzero(base, size);
memset(base, 0, size);
return (base);
}
@ -1087,7 +1125,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) {
@ -1114,7 +1152,7 @@ wtfs(bno, size, bf)
int n;
if (mfs) {
bcopy(bf, membase + bno * sectorsize, size);
memmove(membase + bno * sectorsize, bf, size);
return;
}
if (Nflag)

View File

@ -29,20 +29,21 @@
.\" 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
.Nm newfs ,
.Nm mfs
.Nm mount_mfs
.Nd construct a new file system
.Sh SYNOPSIS
.Nm newfs
.Op Fl NO
.Op Fl S Ar sector-size
.Op Fl a maxcontig
.Op Fl T Ar disktype
.Op Fl a Ar maxcontig
.Op Fl b Ar block-size
.Op Fl c Ar cylinders
.Op Fl d Ar rotdelay
@ -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
@ -62,7 +64,8 @@
.Ar special
.Nm mount_mfs
.Op Fl N
.Op Fl a maxcontig
.Op Fl T Ar disktype
.Op Fl a Ar maxcontig
.Op Fl b Ar block-size
.Op Fl c Ar cylinders
.Op Fl d Ar rotdelay
@ -70,6 +73,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
@ -107,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
@ -123,6 +130,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
@ -144,6 +155,7 @@ The default is 4 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
@ -166,6 +178,9 @@ The default value used is 10%.
See
.Xr tunefs 8
for more details on how to set this option.
.It Fl n Ar rotational\ positions
Determines how many rotational time slots there are in
one revolution of the disk.
.It Fl o Ar optimization\ preference
.Pq ``space'' or ``time''
The file system can either be instructed to try to minimize the time spent
@ -216,6 +231,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.

View File

@ -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>
@ -195,7 +197,7 @@ main(argc, argv)
int fsi, fso, len, n;
char *cp, *s1, *s2, *special, *opstring, buf[BUFSIZ];
if (progname = rindex(*argv, '/'))
if (progname = strrchr(*argv, '/'))
++progname;
else
progname = *argv;
@ -275,7 +277,7 @@ main(argc, argv)
break;
case 'o':
if (mfs)
getmntopts(optarg, mopts, &mntflags);
getmntopts(optarg, mopts, &mntflags, 0);
else {
if (strcmp(optarg, "space") == 0)
opt = FS_OPTSPACE;
@ -322,7 +324,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.
@ -375,8 +377,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
@ -447,7 +450,7 @@ main(argc, argv)
* transfer size permitted by the controller or buffering.
*/
if (maxcontig == 0)
maxcontig = MAX(1, MIN(MAXPHYS, MAXBSIZE) / bsize - 1);
maxcontig = MAX(1, MIN(MAXPHYS, MAXBSIZE) / bsize);
if (density == 0)
density = NFPI * fsize;
if (minfree < MINFREE && opt != FS_OPTSPACE) {
@ -498,7 +501,7 @@ main(argc, argv)
if (realsectorsize != DEV_BSIZE)
pp->p_size *= DEV_BSIZE / realsectorsize;
#endif
if (!Nflag && bcmp(pp, &oldpartition, sizeof(oldpartition)))
if (!Nflag && memcmp(pp, &oldpartition, sizeof(oldpartition)))
rewritelabel(special, fso, lp);
if (!Nflag)
close(fso);
@ -516,7 +519,7 @@ main(argc, argv)
args.export.ex_flags = 0;
args.base = membase;
args.size = fssize * sectorsize;
if (mount(MOUNT_MFS, argv[1], mntflags, &args) < 0)
if (mount("mfs", argv[1], mntflags, &args) < 0)
fatal("%s: %s", argv[1], strerror(errno));
}
#endif
@ -588,7 +591,7 @@ rewritelabel(s, fd, lp)
cfd = open(specname, O_WRONLY);
if (cfd < 0)
fatal("%s: %s", specname, strerror(errno));
bzero(blk, sizeof(blk));
memset(blk, 0, sizeof(blk));
*(struct disklabel *)(blk + LABELOFFSET) = *lp;
alt = lp->d_ncylinders * lp->d_secpercyl - lp->d_nsectors;
for (i = 1; i < 11 && i < lp->d_nsectors; i += 2) {