--- sbin/newfs/newfs.c.orig Thu Mar 9 14:35:02 2006 +++ sbin/newfs/newfs.c Fri Feb 16 12:58:32 2007 @@ -30,23 +30,6 @@ * SUCH DAMAGE. */ -#ifndef lint -static char copyright[] = -"@(#) Copyright (c) 1983, 1989, 1993, 1994\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)newfs.c 8.8 (Berkeley) 4/18/94"; -#else -static char rcsid[] = "$OpenBSD: newfs.c,v 1.52 2006/03/09 13:35:02 pedro Exp $"; -#endif -#endif /* not lint */ - -/* - * newfs: friendly front end to mkfs - */ #include #include #include @@ -90,8 +73,6 @@ void mkfs(struct partition *, char *, in void rewritelabel(char *, int, struct disklabel *); u_short dkcksum(struct disklabel *); -#define COMPAT /* allow non-labeled disks */ - /* * The following two constants set the default block and fragment sizes. * Both constants must be a power of 2 and meet the following constraints: @@ -111,21 +92,6 @@ u_short dkcksum(struct disklabel *); #define DESCPG 65536 /* desired fs_cpg */ /* - * ROTDELAY gives the minimum number of milliseconds to initiate - * another disk transfer on the same cylinder. It is used in - * determining the rotationally optimal layout for disk blocks - * within a file; the default of fs_rotdelay is 0ms. - */ -#define ROTDELAY 0 - -/* - * MAXBLKPG determines the maximum number of data blocks which are - * placed in a single cylinder group. The default is one indirect - * block worth of data blocks. - */ -#define MAXBLKPG(bsize) ((bsize) / sizeof(daddr_t)) - -/* * Each file system has a number of inodes statically allocated. * We allocate one inode slot per NFPI fragments, expecting this * to be far more than we will ever need. @@ -134,42 +100,24 @@ u_short dkcksum(struct disklabel *); int mfs; /* run as the memory based filesystem */ int Nflag; /* run without writing file system */ -int Oflag; /* format as an 4.3BSD file system */ int fssize; /* file system size */ int ntracks; /* # tracks/cylinder */ int nsectors; /* # sectors/track */ -int nphyssectors; /* # sectors/track including spares */ int secpercyl; /* sectors per cylinder */ -int trackspares = -1; /* spare sectors per track */ -int cylspares = -1; /* spare sectors per cylinder */ int sectorsize; /* bytes/sector */ int realsectorsize; /* bytes/sector in hardware */ -int rpm; /* revolutions/minute of drive */ -int interleave; /* hardware sector interleave */ -int trackskew = -1; /* sector 0 skew, per track */ int fsize = 0; /* fragment size */ int bsize = 0; /* block size */ int cpg; /* cylinders/cylinder group */ int cpgflg; /* cylinders/cylinder group flag was given */ -int minfree = MINFREE; /* free space threshold */ -int opt = DEFAULTOPT; /* optimization preference (space or time) */ int reqopt = -1; /* opt preference has not been specified */ int density; /* number of bytes per inode */ -int maxcontig = 0; /* max contiguous blocks to allocate */ -int rotdelay = ROTDELAY; /* rotational delay between blocks */ -int maxbpg; /* maximum blocks per file in a cyl group */ -int avgfilesize = AVFILESIZ;/* expected average file size */ -int avgfilesperdir = AFPDIR;/* expected number of files per directory */ -int bbsize = BBSIZE; /* boot block size */ -int sbsize = SBSIZE; /* superblock size */ int mntflags = MNT_ASYNC; /* flags to be passed to mount */ int quiet = 0; /* quiet flag */ u_long memleft; /* virtual memory available */ caddr_t membase; /* start address of memory based filesystem */ -#ifdef COMPAT char *disktype; int unlabeled; -#endif char device[MAXPATHLEN]; @@ -195,7 +143,7 @@ main(int argc, char *argv[]) struct statfs *mp; struct rlimit rl; int fsi = -1, fso, len, n, ncyls, maxpartitions; - char *cp, *s1, *s2, *special, *opstring; + char *cp = NULL, *s1, *s2, *special, *opstring; #ifdef MFS char mountfromname[BUFSIZ]; char *pop = NULL; @@ -204,9 +152,9 @@ main(int argc, char *argv[]) struct stat mountpoint; int status; #endif - uid_t mfsuid; - gid_t mfsgid; - mode_t mfsmode; + uid_t mfsuid = 0; + gid_t mfsgid = 0; + mode_t mfsmode = 0; char *fstype = NULL; char **saveargv = argv; int ffs = 1; @@ -218,124 +166,46 @@ main(int argc, char *argv[]) if (maxpartitions > 26) fatal("insane maxpartitions value %d", maxpartitions); - opstring = mfs ? - "P:T:a:b:c:d:e:f:i:m:o:s:" : - "NOS:T:a:b:c:d:e:f:g:h:i:k:l:m:o:p:qr:s:t:u:x:z:"; + opstring = mfs ? "P:T:b:f:i:o:s:" : "NS:T:b:f:i:qs:t:"; while ((ch = getopt(argc, argv, opstring)) != -1) { switch (ch) { case 'N': Nflag = 1; break; - case 'O': - Oflag = 1; - break; case 'S': if ((sectorsize = atoi(optarg)) <= 0) fatal("%s: bad sector size", optarg); break; -#ifdef COMPAT case 'T': disktype = optarg; break; -#endif - case 'a': - if ((maxcontig = atoi(optarg)) <= 0) - fatal("%s: bad maximum contiguous blocks\n", - optarg); - break; case 'b': if ((bsize = atoi(optarg)) < 0) fatal("%s: bad block size", optarg); break; - case 'c': - if ((cpg = atoi(optarg)) <= 0) - fatal("%s: bad cylinders/group", optarg); - cpgflg++; - break; - case 'd': - if ((rotdelay = atoi(optarg)) < 0) - fatal("%s: bad rotational delay\n", optarg); - break; - case 'e': - if ((maxbpg = atoi(optarg)) <= 0) - fatal("%s: bad blocks per file in a cylinder group\n", - optarg); - break; case 'f': if ((fsize = atoi(optarg)) <= 0) fatal("%s: bad fragment size", optarg); break; - case 'g': - if ((avgfilesize = atoi(optarg)) <= 0) - fatal("%s: bad average file size", optarg); - break; - case 'h': - if ((avgfilesperdir = atoi(optarg)) <= 0) - fatal("%s: bad average files per dir", optarg); - break; case 'i': if ((density = atoi(optarg)) <= 0) fatal("%s: bad bytes per inode\n", optarg); break; - case 'k': - if ((trackskew = atoi(optarg)) < 0) - fatal("%s: bad track skew", optarg); - break; - case 'l': - if ((interleave = atoi(optarg)) <= 0) - fatal("%s: bad interleave", optarg); - break; - case 'm': - if ((minfree = atoi(optarg)) < 0 || minfree > 99) - fatal("%s: bad free space %%\n", optarg); - break; case 'o': - if (mfs) - getmntopts(optarg, mopts, &mntflags); - else { - if (strcmp(optarg, "space") == 0) - reqopt = opt = FS_OPTSPACE; - else if (strcmp(optarg, "time") == 0) - reqopt = opt = FS_OPTTIME; - else - fatal("%s: unknown optimization " - "preference: use `space' or `time'."); - } + getmntopts(optarg, mopts, &mntflags); break; - case 'p': - if ((trackspares = atoi(optarg)) < 0) - fatal("%s: bad spare sectors per track", - optarg); - break; case 'q': quiet = 1; break; - case 'r': - if ((rpm = atoi(optarg)) <= 0) - fatal("%s: bad revolutions/minute\n", optarg); - break; case 's': if ((fssize = atoi(optarg)) <= 0) fatal("%s: bad file system size", optarg); break; - case 'z': - if ((ntracks = atoi(optarg)) <= 0) - fatal("%s: bad total tracks", optarg); - break; case 't': fstype = optarg; if (strcmp(fstype, "ffs")) ffs = 0; break; - case 'u': - if ((nsectors = atoi(optarg)) <= 0) - fatal("%s: bad sectors/track", optarg); - break; - case 'x': - if ((cylspares = atoi(optarg)) < 0) - fatal("%s: bad spare sectors per cylinder", - optarg); - break; #ifdef MFS case 'P': pop = optarg; @@ -447,15 +317,12 @@ main(int argc, char *argv[]) ++mp; } } -#ifdef COMPAT if (mfs && disktype != NULL) { lp = (struct disklabel *)getdiskbyname(disktype); if (lp == NULL) fatal("%s: unknown disk type", disktype); pp = &lp->d_partitions[1]; - } else -#endif - { + } else { fsi = open(special, O_RDONLY); if (fsi < 0) fatal("%s: %s", special, strerror(errno)); @@ -487,11 +354,6 @@ havelabel: if (fssize > pp->p_size && !mfs) fatal("%s: maximum file system size on the `%c' partition is %d", argv[0], *cp, pp->p_size); - if (rpm == 0) { - rpm = lp->d_rpm; - if (rpm <= 0) - rpm = 3600; - } if (ntracks == 0) { ntracks = lp->d_ntracks; if (ntracks <= 0) @@ -507,16 +369,6 @@ havelabel: if (sectorsize <= 0) fatal("%s: no default sector size", argv[0]); } - if (trackskew == -1) { - trackskew = lp->d_trackskew; - if (trackskew < 0) - trackskew = 0; - } - if (interleave == 0) { - interleave = lp->d_interleave; - if (interleave <= 0) - interleave = 1; - } if (fsize == 0) { fsize = pp->p_fsize; if (fsize <= 0) @@ -527,44 +379,14 @@ havelabel: if (bsize <= 0) bsize = MIN(DFL_BLKSIZE, 8 * fsize); } - /* - * Maxcontig sets the default for the maximum number of blocks - * that may be allocated sequentially. With filesystem clustering - * it is possible to allocate contiguous blocks up to the maximum - * transfer size permitted by the controller or buffering. - */ - if (maxcontig == 0) - maxcontig = MAX(1, MIN(MAXPHYS, MAXBSIZE) / bsize - 1); if (density == 0) density = NFPI * fsize; - if (minfree < MINFREE && opt != FS_OPTSPACE && reqopt == -1) { - fprintf(stderr, "Warning: changing optimization to space "); - fprintf(stderr, "because minfree is less than %d%%\n", MINFREE); - opt = FS_OPTSPACE; - } - if (trackspares == -1) { - trackspares = lp->d_sparespertrack; - if (trackspares < 0) - trackspares = 0; - } - nphyssectors = nsectors + trackspares; - if (cylspares == -1) { - cylspares = lp->d_sparespercyl; - if (cylspares < 0) - cylspares = 0; - } - secpercyl = nsectors * ntracks - cylspares; + secpercyl = nsectors * ntracks; if (secpercyl != lp->d_secpercyl) fprintf(stderr, "%s (%d) %s (%lu)\n", "Warning: calculated sectors per cylinder", secpercyl, "disagrees with disk label", (unsigned long)lp->d_secpercyl); - if (maxbpg == 0) - maxbpg = MAXBLKPG(bsize); -#ifdef notdef /* label may be 0 if faked up by kernel */ - bbsize = lp->d_bbsize; - sbsize = lp->d_sbsize; -#endif oldpartition = *pp; realsectorsize = sectorsize; if (sectorsize < DEV_BSIZE) { @@ -572,7 +394,6 @@ havelabel: sectorsize = DEV_BSIZE; nsectors /= secperblk; - nphyssectors /= secperblk; secpercyl /= secperblk; fssize /= secperblk; pp->p_size /= secperblk; @@ -581,7 +402,6 @@ havelabel: sectorsize = DEV_BSIZE; nsectors *= blkpersec; - nphyssectors *= blkpersec; secpercyl *= blkpersec; fssize *= blkpersec; pp->p_size *= blkpersec; @@ -690,11 +510,7 @@ havelabel: exit(0); } -#ifdef COMPAT char lmsg[] = "%s: can't read disk label; disk type must be specified"; -#else -char lmsg[] = "%s: can't read disk label"; -#endif struct disklabel * getdisklabel(char *s, int fd) @@ -702,7 +518,6 @@ getdisklabel(char *s, int fd) static struct disklabel lab; if (ioctl(fd, DIOCGDINFO, (char *)&lab) < 0) { -#ifdef COMPAT if (disktype) { struct disklabel *lp; @@ -712,7 +527,6 @@ getdisklabel(char *s, int fd) fatal("%s: unknown disk type", disktype); return (lp); } -#endif warn("ioctl (GDINFO)"); fatal(lmsg, s); } @@ -722,10 +536,8 @@ getdisklabel(char *s, int fd) void rewritelabel(char *s, int fd, struct disklabel *lp) { -#ifdef COMPAT if (unlabeled) return; -#endif lp->d_checksum = 0; lp->d_checksum = dkcksum(lp); if (ioctl(fd, DIOCWDINFO, (char *)lp) < 0) { @@ -795,35 +607,16 @@ struct fsoptions { int mfs_too; } fsopts[] = { { "-N do not create file system, just print out parameters", 0 }, - { "-O create a 4.3BSD format filesystem", 0 }, #ifdef MFS { "-P src populate mfs filesystem", 2 }, #endif { "-S sector size", 0 }, -#ifdef COMPAT { "-T disktype", 0 }, -#endif - { "-a maximum contiguous blocks", 1 }, { "-b block size", 1 }, - { "-c cylinders/group", 1 }, - { "-d rotational delay between contiguous blocks", 1 }, - { "-e maximum blocks per file in a cylinder group", 1 }, { "-f frag size", 1 }, - { "-g average file size", 0 }, - { "-h average files per directory", 0 }, { "-i number of bytes per inode", 1 }, - { "-k sector 0 skew, per track", 0 }, - { "-l hardware sector interleave", 0 }, - { "-m minimum free space %%", 1 }, - { "-n number of distinguished rotational positions", 0 }, - { "-o optimization preference (`space' or `time')", 1 }, - { "-p spare sectors per track", 0 }, - { "-r revolutions/minute", 0 }, { "-s file system size (sectors)", 1 }, { "-t file system type", 0 }, - { "-u sectors/track", 0 }, - { "-x spare sectors per cylinder", 0 }, - { "-z tracks/cylinder", 0 }, { NULL, NULL } }; --- sbin/newfs/mkfs.c.orig Fri Feb 16 12:58:22 2007 +++ sbin/newfs/mkfs.c Fri Feb 16 12:58:44 2007 @@ -30,14 +30,6 @@ * SUCH DAMAGE. */ -#ifndef lint -#if 0 -static char sccsid[] = "@(#)mkfs.c 8.3 (Berkeley) 2/3/94"; -#else -static char rcsid[] = "$OpenBSD: mkfs.c,v 1.50 2006/03/09 13:35:02 pedro Exp $"; -#endif -#endif /* not lint */ - #include #include #include @@ -59,10 +51,6 @@ static char rcsid[] = "$OpenBSD: mkfs.c, #endif /* - * make file system for cylinder-group style file systems - */ - -/* * We limit the size of the inode map to be no more than a * third of the cylinder group space, since we must leave at * least an equal amount of space for the block map. @@ -76,45 +64,28 @@ static char rcsid[] = "$OpenBSD: mkfs.c, #define POWEROF2(num) (((num) & ((num) - 1)) == 0) /* - * For each cylinder we keep track of the availability of blocks at different - * rotational positions, so that we can lay out the data to be picked - * up with minimum rotational latency. NRPOS is the default number of - * rotational positions that we distinguish. With NRPOS of 8 the resolution - * of our summary information is 2ms for a typical 3600 rpm drive. Caching - * and zoning pretty much defeats rotational optimization, so we now use a - * default of 1. + * MAXBLKPG determines the maximum number of data blocks which are + * placed in a single cylinder group. The default is one indirect + * block worth of data blocks. */ -#define NRPOS 1 /* number distinct rotational positions */ +#define MAXBLKPG(bsize) ((bsize) / sizeof(daddr_t)) /* * variables set up by front end. */ extern int mfs; /* run as the memory based filesystem */ extern int Nflag; /* run mkfs without writing file system */ -extern int Oflag; /* format as an 4.3BSD file system */ extern int fssize; /* file system size */ extern int ntracks; /* # tracks/cylinder */ extern int nsectors; /* # sectors/track */ -extern int nphyssectors; /* # sectors/track including spares */ extern int secpercyl; /* sectors per cylinder */ extern int sectorsize; /* bytes/sector */ -extern int rpm; /* revolutions/minute of drive */ -extern int interleave; /* hardware sector interleave */ -extern int trackskew; /* sector 0 skew, per track */ extern int fsize; /* fragment size */ extern int bsize; /* block size */ extern int cpg; /* cylinders/cylinder group */ 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 maxcontig; /* max contiguous blocks to allocate */ -extern int rotdelay; /* rotational delay between blocks */ extern int maxbpg; /* maximum blocks per file in a cyl group */ -extern int bbsize; /* boot block size */ -extern int sbsize; /* superblock size */ -extern int avgfilesize; /* expected average file size */ -extern int avgfilesperdir; /* expected number of files per directory */ extern int quiet; /* quiet flag */ extern caddr_t membase; /* start address of memory based filesystem */ @@ -206,13 +177,8 @@ mkfs(struct partition *pp, char *fsys, i } fsi = fi; fso = fo; - if (Oflag) { - sblock.fs_inodefmt = FS_42INODEFMT; - sblock.fs_maxsymlinklen = 0; - } else { - sblock.fs_inodefmt = FS_44INODEFMT; - sblock.fs_maxsymlinklen = MAXSYMLINKLEN_UFS1; - } + sblock.fs_inodefmt = FS_44INODEFMT; + sblock.fs_maxsymlinklen = MAXSYMLINKLEN_UFS1; /* * Validate the given file system size. * Verify that its last block can actually be accessed. @@ -233,14 +199,8 @@ recalc: /* * collect and verify the filesystem density info */ - sblock.fs_avgfilesize = avgfilesize; - sblock.fs_avgfpdir = avgfilesperdir; - if (sblock.fs_avgfilesize <= 0) - errx(14, "illegal expected average file size %d", - sblock.fs_avgfilesize); - if (sblock.fs_avgfpdir <= 0) - errx(15, "illegal expected number of files per directory %d", - sblock.fs_avgfpdir); + sblock.fs_avgfilesize = AVFILESIZ; + sblock.fs_avgfpdir = AFPDIR; /* * collect and verify the block and fragment sizes */ @@ -286,16 +246,16 @@ recalc: sblock.fs_fsize, sblock.fs_bsize, sblock.fs_bsize / MAXFRAG); } - sblock.fs_nrpos = NRPOS; + sblock.fs_nrpos = 1; sblock.fs_nindir = sblock.fs_bsize / sizeof(daddr_t); sblock.fs_inopb = sblock.fs_bsize / sizeof(struct ufs1_dinode); sblock.fs_nspf = sblock.fs_fsize / sectorsize; for (sblock.fs_fsbtodb = 0, i = NSPF(&sblock); i > 1; i >>= 1) sblock.fs_fsbtodb++; sblock.fs_sblkno = - roundup(howmany(bbsize + sbsize, sblock.fs_fsize), sblock.fs_frag); + roundup(howmany(BBSIZE + SBSIZE, sblock.fs_fsize), sblock.fs_frag); sblock.fs_cblkno = (daddr_t)(sblock.fs_sblkno + - roundup(howmany(sbsize, sblock.fs_fsize), sblock.fs_frag)); + roundup(howmany(SBSIZE, sblock.fs_fsize), sblock.fs_frag)); sblock.fs_iblkno = sblock.fs_cblkno + sblock.fs_frag; sblock.fs_cgoffset = roundup( howmany(sblock.fs_nsect, NSPF(&sblock)), sblock.fs_frag); @@ -332,8 +292,6 @@ recalc: */ sblock.fs_cpg = mincpg; sblock.fs_ipg = inospercg; - if (maxcontig > 1) - sblock.fs_contigsumsize = MIN(maxcontig, FS_MAXCONTIG); mapcramped = 0; /* A cylinder group *must* fit inside one block so force it if not. */ if (CGSIZE(&sblock) > sblock.fs_bsize && secpercyl > 1024 && ntracks > 1) { @@ -505,9 +463,9 @@ recalc: * are not powers of two, because more cylinders must be described * by the tables before the rotational pattern repeats (fs_cpc). */ - sblock.fs_interleave = interleave; - sblock.fs_trackskew = trackskew; - sblock.fs_npsect = nphyssectors; + sblock.fs_interleave = 1; + sblock.fs_trackskew = 0; + sblock.fs_npsect = sblock.fs_spc; sblock.fs_postblformat = FS_DYNAMICPOSTBLFMT; sblock.fs_sbsize = fragroundup(&sblock, sizeof(struct fs)); if (sblock.fs_sbsize > SBSIZE) @@ -596,12 +554,12 @@ next: if ((fscs = calloc(1, sblock.fs_cssize)) == NULL) err(1, "cg summary"); sblock.fs_magic = FS_MAGIC; - sblock.fs_rotdelay = rotdelay; - sblock.fs_minfree = minfree; - sblock.fs_maxcontig = maxcontig; - sblock.fs_maxbpg = maxbpg; - sblock.fs_rps = rpm / 60; - sblock.fs_optim = opt; + sblock.fs_rotdelay = 0; + sblock.fs_minfree = MINFREE; + sblock.fs_maxcontig = 0; + sblock.fs_maxbpg = MAXBLKPG(bsize); + sblock.fs_rps = 60; + sblock.fs_optim = DEFAULTOPT; sblock.fs_cgrotor = 0; sblock.fs_ffs1_cstotal.cs_ndir = 0; sblock.fs_ffs1_cstotal.cs_nbfree = 0; @@ -672,7 +630,7 @@ next: sblock.fs_ffs1_time = utime; /* don't write magic until we are done */ sblock.fs_magic = 0; - wtfs((int)SBOFF / sectorsize, sbsize, (char *)&sblock); + wtfs((int)SBOFF / sectorsize, SBSIZE, (char *)&sblock); sblock.fs_magic = FS_MAGIC; for (i = 0; i < sblock.fs_cssize; i += sblock.fs_bsize) wtfs(fsbtodb(&sblock, sblock.fs_ffs1_csaddr + numfrags(&sblock, i)), @@ -684,9 +642,9 @@ next: */ for (cylno = 0; cylno < sblock.fs_ncg; cylno++) wtfs(fsbtodb(&sblock, cgsblock(&sblock, cylno)), - sbsize, (char *)&sblock); + SBSIZE, (char *)&sblock); /* done, can write with magic now */ - wtfs((int)SBOFF / sectorsize, sbsize, (char *)&sblock); + wtfs((int)SBOFF / sectorsize, SBSIZE, (char *)&sblock); /* * Update information about this partion in pack * label, to that it may be updated on disk. @@ -731,27 +689,13 @@ initcg(int cylno, time_t utime) acg.cg_ncyl = sblock.fs_cpg; acg.cg_niblk = sblock.fs_ipg; 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_firstfield); acg.cg_boff = acg.cg_btotoff + sblock.fs_cpg * sizeof(int32_t); acg.cg_iusedoff = acg.cg_boff + sblock.fs_cpg * sblock.fs_nrpos * sizeof(int16_t); acg.cg_freeoff = acg.cg_iusedoff + howmany(sblock.fs_ipg, NBBY); - if (sblock.fs_contigsumsize <= 0) { - acg.cg_nextfreeoff = acg.cg_freeoff + - howmany(sblock.fs_cpg * sblock.fs_spc / NSPF(&sblock), NBBY); - } else { - acg.cg_clustersumoff = acg.cg_freeoff + howmany - (sblock.fs_cpg * sblock.fs_spc / NSPF(&sblock), NBBY) - - sizeof(int32_t); - acg.cg_clustersumoff = - roundup(acg.cg_clustersumoff, sizeof(int32_t)); - acg.cg_clusteroff = acg.cg_clustersumoff + - (sblock.fs_contigsumsize + 1) * sizeof(int32_t); - acg.cg_nextfreeoff = acg.cg_clusteroff + howmany - (sblock.fs_cpg * sblock.fs_spc / NSPB(&sblock), NBBY); - } + acg.cg_nextfreeoff = acg.cg_freeoff + + howmany(sblock.fs_cpg * sblock.fs_spc / NSPF(&sblock), NBBY); if (acg.cg_nextfreeoff > sblock.fs_cgsize) errx(37, "panic: cylinder group too big"); acg.cg_cs.cs_nifree += sblock.fs_ipg; @@ -774,8 +718,6 @@ initcg(int cylno, time_t utime) for (d = 0; d < dlower; d += sblock.fs_frag) { blkno = d / sblock.fs_frag; setblock(&sblock, cg_blksfree(&acg), blkno); - if (sblock.fs_contigsumsize > 0) - setbit(cg_clustersfree(&acg), blkno); acg.cg_cs.cs_nbfree++; cg_blktot(&acg)[cbtocylno(&sblock, d)]++; cg_blks(&sblock, &acg, cbtocylno(&sblock, d)) @@ -794,8 +736,6 @@ initcg(int cylno, time_t utime) for (d = dupper; d + sblock.fs_frag <= dmax - cbase; ) { blkno = d / sblock.fs_frag; setblock(&sblock, cg_blksfree(&acg), blkno); - if (sblock.fs_contigsumsize > 0) - setbit(cg_clustersfree(&acg), blkno); acg.cg_cs.cs_nbfree++; cg_blktot(&acg)[cbtocylno(&sblock, d)]++; cg_blks(&sblock, &acg, cbtocylno(&sblock, d)) @@ -809,35 +749,6 @@ initcg(int cylno, time_t utime) acg.cg_cs.cs_nffree++; } } - if (sblock.fs_contigsumsize > 0) { - int32_t *sump = cg_clustersum(&acg); - u_char *mapp = cg_clustersfree(&acg); - int map = *mapp++; - int bit = 1; - int run = 0; - - for (i = 0; i < acg.cg_nclusterblks; i++) { - if ((map & bit) != 0) { - run++; - } else if (run != 0) { - if (run > sblock.fs_contigsumsize) - run = sblock.fs_contigsumsize; - sump[run]++; - run = 0; - } - if ((i & (NBBY - 1)) != (NBBY - 1)) { - bit <<= 1; - } else { - map = *mapp++; - bit = 1; - } - } - if (run != 0) { - if (run > sblock.fs_contigsumsize) - run = sblock.fs_contigsumsize; - sump[run]++; - } - } sblock.fs_ffs1_cstotal.cs_ndir += acg.cg_cs.cs_ndir; sblock.fs_ffs1_cstotal.cs_nffree += acg.cg_cs.cs_nffree; sblock.fs_ffs1_cstotal.cs_nbfree += acg.cg_cs.cs_nbfree; @@ -852,19 +763,13 @@ initcg(int cylno, time_t utime) */ struct ufs1_dinode node; -#ifdef LOSTDIR -#define PREDEFDIR 3 -#else #define PREDEFDIR 2 -#endif struct direct root_dir[] = { { ROOTINO, sizeof(struct direct), DT_DIR, 1, "." }, { ROOTINO, sizeof(struct direct), DT_DIR, 2, ".." }, -#ifdef LOSTDIR - { LOSTFOUNDINO, sizeof(struct direct), DT_DIR, 10, "lost+found" }, -#endif }; + struct odirect { u_int32_t d_ino; u_int16_t d_reclen; @@ -873,22 +778,7 @@ struct odirect { } oroot_dir[] = { { ROOTINO, sizeof(struct direct), 1, "." }, { ROOTINO, sizeof(struct direct), 2, ".." }, -#ifdef LOSTDIR - { LOSTFOUNDINO, sizeof(struct direct), 10, "lost+found" }, -#endif }; -#ifdef LOSTDIR -struct direct lost_found_dir[] = { - { LOSTFOUNDINO, sizeof(struct direct), DT_DIR, 1, "." }, - { ROOTINO, sizeof(struct direct), DT_DIR, 2, ".." }, - { 0, DIRBLKSIZ, 0, 0, 0 }, -}; -struct odirect olost_found_dir[] = { - { LOSTFOUNDINO, sizeof(struct direct), 1, "." }, - { ROOTINO, sizeof(struct direct), 2, ".." }, - { 0, DIRBLKSIZ, 0, 0 }, -}; -#endif int fsinit(time_t utime, mode_t mfsmode, uid_t mfsuid, gid_t mfsgid) @@ -899,35 +789,7 @@ fsinit(time_t utime, mode_t mfsmode, uid node.di_atime = utime; node.di_mtime = utime; node.di_ctime = utime; -#ifdef LOSTDIR /* - * create the lost+found directory - */ - if (Oflag) { - int i; - - (void)makedir((struct direct *)olost_found_dir, 2); - for (i = DIRBLKSIZ; i < sblock.fs_bsize; i += DIRBLKSIZ) - memcpy(&buf[i], &olost_found_dir[2], - DIRSIZ(0, &olost_found_dir[2])); - } else { - int i; - - (void)makedir(lost_found_dir, 2); - for (i = DIRBLKSIZ; i < sblock.fs_bsize; i += DIRBLKSIZ) - memcpy(&buf[i], &lost_found_dir[2], - DIRSIZ(0, &lost_found_dir[2])); - } - node.di_mode = IFDIR | 1700; - node.di_nlink = 2; - node.di_size = sblock.fs_bsize; - if ((node.di_db[0] = alloc(node.di_size, node.di_mode)) == 0) - return (1); - node.di_blocks = btodb(fragroundup(&sblock, node.di_size)); - wtfs(fsbtodb(&sblock, node.di_db[0]), node.di_size, buf); - iput(&node, LOSTFOUNDINO); -#endif - /* * create the root directory */ if (mfs) { @@ -940,10 +802,7 @@ fsinit(time_t utime, mode_t mfsmode, uid node.di_gid = getegid(); } node.di_nlink = PREDEFDIR; - if (Oflag) - node.di_size = makedir((struct direct *)oroot_dir, PREDEFDIR); - else - node.di_size = makedir(root_dir, PREDEFDIR); + node.di_size = makedir(root_dir, PREDEFDIR); if ((node.di_db[0] = alloc(sblock.fs_fsize, node.di_mode)) == 0) return (1); node.di_blocks = btodb(fragroundup(&sblock, node.di_size)); @@ -1001,8 +860,6 @@ alloc(int size, int mode) goth: blkno = fragstoblks(&sblock, d); clrblock(&sblock, cg_blksfree(&acg), blkno); - if (sblock.fs_contigsumsize > 0) - clrbit(cg_clustersfree(&acg), blkno); acg.cg_cs.cs_nbfree--; sblock.fs_ffs1_cstotal.cs_nbfree--; fscs[0].cs_nbfree--; --- sbin/newfs/newfs.8.orig Tue Nov 14 11:28:11 2006 +++ sbin/newfs/newfs.8 Fri Feb 16 12:58:32 2007 @@ -39,41 +39,21 @@ .Sh SYNOPSIS .Nm newfs .Bk -words -.Op Fl NOq -.Op Fl a Ar maxcontig +.Op Fl Nq .Op Fl b Ar block-size -.Op Fl c Ar cylinders -.Op Fl d Ar rotdelay -.Op Fl e Ar maxbpg .Op Fl f Ar frag-size -.Op Fl g Ar avgfilesize -.Op Fl h Ar avgfpdir .Op Fl i Ar bytes -.Op Fl k Ar skew -.Op Fl l Ar interleave -.Op Fl m Ar free-space -.Op Fl o Ar optimization -.Op Fl p Ar sectors -.Op Fl r Ar revolutions .Op Fl S Ar sector-size .Op Fl s Ar size .Op Fl t Ar fstype -.Op Fl u Ar sectors -.Op Fl x Ar sectors -.Op Fl z Ar tracks .Ar special .Ek .Pp .Nm mount_mfs .Bk -words -.Op Fl a Ar maxcontig .Op Fl b Ar block-size -.Op Fl c Ar cylinders -.Op Fl d Ar rotdelay -.Op Fl e Ar maxbpg .Op Fl f Ar frag-size .Op Fl i Ar bytes -.Op Fl m Ar free space .Op Fl o Ar options .Op Fl P Ar file .Op Fl s Ar size @@ -84,7 +64,7 @@ Before running .Nm or .Nm mount_mfs , -the disk must be labeled using +the disk should be labeled using .Xr disklabel 8 . .Nm builds a file system on the specified @@ -92,7 +72,7 @@ builds a file system on the specified device, basing its defaults on the information in the disk label. Typically the defaults are reasonable, although -.Nm +.Xr tunefs 8 has numerous options to allow the defaults to be selectively overridden. .Pp .Nm mount_mfs @@ -138,78 +118,21 @@ file system (or list the inode generatio .Pp The following options define the general layout policies: .Bl -tag -width Fl -.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 -.Fl d -option). -The default value depends on the block size -(4 for 16KB blocks, 8 for 8KB blocks, and 16 for 4KB blocks). -See -.Xr tunefs 8 -for more details on how to set this option. .It Fl b Ar block-size The block size of the file system, in bytes. The default is 16KB. -.It Fl c Ar cylinders -The number of cylinders per cylinder group in a file system. -The default is to use as many as fit with the other parameters given. -.It Fl d Ar rotdelay -This specifies the expected time (in milliseconds) to service a transfer -completion interrupt and initiate a new transfer on the same disk. -The default is 0 milliseconds. -See -.Xr tunefs 8 -for more details on how to set this option. -.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 -allocating blocks from another cylinder group. -The default is about one quarter of the total blocks in a cylinder group. -See -.Xr tunefs 8 -for more details on how to set this option. .It Fl f Ar frag-size The fragment size of the file system in bytes. The default is 2048. -.It Fl g Ar avgfilesize -The expected average file size for the file system in bytes. -.It Fl h Ar avgfpdir The expected average number of files per directory on the file system. .It Fl i Ar bytes This specifies the density of inodes in the file system. The default is to create an inode for each 8192 bytes of data space. If fewer inodes are desired, a larger number should be used; to create more inodes a smaller number should be given. -.It Fl m Ar free-space -The percentage of space reserved from normal users; the minimum free -space threshold. -The default value used is 5%. -See -.Xr tunefs 8 -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 O -Creates a -.Bx 4.3 -format file system. -This option is primarily used to build root file systems -that can be understood by older boot ROMs. -.It Fl o Ar optimization -.Ar space -or -.Ar time . -The file system can either be instructed to try to minimize the time spent -allocating blocks, or to try to minimize the space fragmentation on the disk. -Unless an optimization has been specified, if the value of minfree -(see above) is less than 5%, the default is to optimize for space; -if the value of minfree is greater than or equal to 5%, -the default is to optimize for time. -See -.Xr tunefs 8 -for more details on how to set this option. .It Fl q Operate in quiet mode. With this option, @@ -243,50 +166,12 @@ it impossible for .Xr fsck 8 to find the alternate superblocks if the standard superblock is lost. .Bl -tag -width Fl -.It Fl k Ar skew -Used to describe perturbations in the media format to compensate for -a slow controller. -Track skew is the offset of sector 0 on track N relative to sector 0 -on track N\-1 on the same cylinder. -.It Fl l Ar interleave -Used to describe perturbations in the media format to compensate for -a slow controller. -Interleave is physical sector interleave on each track, -specified as the denominator of the ratio: -.Dl sectors read/sectors passed over -Thus an interleave of 1/1 implies contiguous layout, while 1/2 implies -logical sector 0 is separated by one sector from logical sector 1. -.It Fl p Ar sectors -Spare sectors (bad sector replacements) are physical sectors that occupy -space at the end of each track. -They are not counted as part of the sectors/track -.Pq Fl u -since they are not available to the file system for data allocation. -.It Fl r Ar revolutions -The speed of the disk in revolutions per minute. .It Fl S Ar sector-size The size of a sector in bytes (almost never anything but 512). .It Fl t Ar fstype Set the file system type of which file system you wish to create. .Nm will be smart enough to run the alternate newfs_XXX program instead. -.It Fl u Ar sectors -The number of sectors per track available for data allocation by the file -system. -This does not include sectors reserved at the end of each track for bad -block replacement (see the -.Fl p -option). -.It Fl x Ar sectors -Spare sectors (bad sector replacements) are physical sectors that occupy -space at the end of the last track in the cylinder. -They are deducted from the sectors/track -.Pq Fl u -of the last track of each cylinder since they are not available to the file -system for data allocation. -.It Fl z Ar tracks -The number of tracks/cylinder available for data allocation by the file -system. .El .Pp The options to the