Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F153815516
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
118 KB
Referenced Files
None
Subscribers
None
View Options
Index: stable/8/sbin/atacontrol
===================================================================
--- stable/8/sbin/atacontrol (revision 218079)
+++ stable/8/sbin/atacontrol (revision 218080)
Property changes on: stable/8/sbin/atacontrol
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/atacontrol:r216798
Index: stable/8/sbin/bsdlabel
===================================================================
--- stable/8/sbin/bsdlabel (revision 218079)
+++ stable/8/sbin/bsdlabel (revision 218080)
Property changes on: stable/8/sbin/bsdlabel
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/bsdlabel:r216798
Index: stable/8/sbin/camcontrol
===================================================================
--- stable/8/sbin/camcontrol (revision 218079)
+++ stable/8/sbin/camcontrol (revision 218080)
Property changes on: stable/8/sbin/camcontrol
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/camcontrol:r216798
Index: stable/8/sbin/ddb
===================================================================
--- stable/8/sbin/ddb (revision 218079)
+++ stable/8/sbin/ddb (revision 218080)
Property changes on: stable/8/sbin/ddb
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/ddb:r216798
Index: stable/8/sbin/devd
===================================================================
--- stable/8/sbin/devd (revision 218079)
+++ stable/8/sbin/devd (revision 218080)
Property changes on: stable/8/sbin/devd
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/devd:r216798
Index: stable/8/sbin/devfs
===================================================================
--- stable/8/sbin/devfs (revision 218079)
+++ stable/8/sbin/devfs (revision 218080)
Property changes on: stable/8/sbin/devfs
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/devfs:r216798
Index: stable/8/sbin/dhclient
===================================================================
--- stable/8/sbin/dhclient (revision 218079)
+++ stable/8/sbin/dhclient (revision 218080)
Property changes on: stable/8/sbin/dhclient
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/dhclient:r216798
Index: stable/8/sbin/dump
===================================================================
--- stable/8/sbin/dump (revision 218079)
+++ stable/8/sbin/dump (revision 218080)
Property changes on: stable/8/sbin/dump
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/dump:r216798
Index: stable/8/sbin/dumpfs/dumpfs.c
===================================================================
--- stable/8/sbin/dumpfs/dumpfs.c (revision 218079)
+++ stable/8/sbin/dumpfs/dumpfs.c (revision 218080)
@@ -1,483 +1,485 @@
/*
* Copyright (c) 2009 Robert N. M. Watson
* All rights reserved.
*
* This software was developed at the University of Cambridge Computer
* Laboratory with support from a grant from Google, Inc.
*
* Copyright (c) 2002 Networks Associates Technology, Inc.
* All rights reserved.
*
* This software was developed for the FreeBSD Project by Marshall
* Kirk McKusick and Network Associates Laboratories, the Security
* Research Division of Network Associates, Inc. under DARPA/SPAWAR
* contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA CHATS
* research program.
*
* Copyright (c) 1983, 1992, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef lint
static const char copyright[] =
"@(#) Copyright (c) 1983, 1992, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
#if 0
static char sccsid[] = "@(#)dumpfs.c 8.5 (Berkeley) 4/29/95";
#endif
static const char rcsid[] =
"$FreeBSD$";
#endif /* not lint */
#include <sys/param.h>
#include <sys/time.h>
#include <sys/disklabel.h>
#include <ufs/ufs/dinode.h>
#include <ufs/ffs/fs.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <fstab.h>
#include <libufs.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define afs disk.d_fs
#define acg disk.d_cg
struct uufsd disk;
int dumpfs(const char *);
int dumpcg(void);
int dumpfreespace(const char *, int);
void dumpfreespacecg(int);
int marshal(const char *);
void pbits(void *, int);
void pblklist(void *, int, off_t, int);
void ufserr(const char *);
void usage(void) __dead2;
int
main(int argc, char *argv[])
{
const char *name;
int ch, dofreespace, domarshal, eval;
dofreespace = domarshal = eval = 0;
while ((ch = getopt(argc, argv, "fm")) != -1) {
switch (ch) {
case 'f':
dofreespace++;
break;
case 'm':
domarshal = 1;
break;
case '?':
default:
usage();
}
}
argc -= optind;
argv += optind;
if (argc < 1)
usage();
if (dofreespace && domarshal)
usage();
if (dofreespace > 2)
usage();
while ((name = *argv++) != NULL) {
if (ufs_disk_fillout(&disk, name) == -1) {
ufserr(name);
eval |= 1;
continue;
}
if (dofreespace)
eval |= dumpfreespace(name, dofreespace);
else if (domarshal)
eval |= marshal(name);
else
eval |= dumpfs(name);
ufs_disk_close(&disk);
}
exit(eval);
}
int
dumpfs(const char *name)
{
time_t fstime;
int64_t fssize;
int32_t fsflags;
int i;
switch (disk.d_ufs) {
case 2:
fssize = afs.fs_size;
fstime = afs.fs_time;
printf("magic\t%x (UFS2)\ttime\t%s",
afs.fs_magic, ctime(&fstime));
printf("superblock location\t%jd\tid\t[ %x %x ]\n",
(intmax_t)afs.fs_sblockloc, afs.fs_id[0], afs.fs_id[1]);
printf("ncg\t%d\tsize\t%jd\tblocks\t%jd\n",
afs.fs_ncg, (intmax_t)fssize, (intmax_t)afs.fs_dsize);
break;
case 1:
fssize = afs.fs_old_size;
fstime = afs.fs_old_time;
printf("magic\t%x (UFS1)\ttime\t%s",
afs.fs_magic, ctime(&fstime));
printf("id\t[ %08x %08x ]\n", afs.fs_id[0], afs.fs_id[1]);
printf("ncg\t%d\tsize\t%jd\tblocks\t%jd\n",
afs.fs_ncg, (intmax_t)fssize, (intmax_t)afs.fs_dsize);
break;
default:
goto err;
}
printf("bsize\t%d\tshift\t%d\tmask\t0x%08x\n",
afs.fs_bsize, afs.fs_bshift, afs.fs_bmask);
printf("fsize\t%d\tshift\t%d\tmask\t0x%08x\n",
afs.fs_fsize, afs.fs_fshift, afs.fs_fmask);
printf("frag\t%d\tshift\t%d\tfsbtodb\t%d\n",
afs.fs_frag, afs.fs_fragshift, afs.fs_fsbtodb);
printf("minfree\t%d%%\toptim\t%s\tsymlinklen %d\n",
afs.fs_minfree, afs.fs_optim == FS_OPTSPACE ? "space" : "time",
afs.fs_maxsymlinklen);
switch (disk.d_ufs) {
case 2:
printf("%s %d\tmaxbpg\t%d\tmaxcontig %d\tcontigsumsize %d\n",
"maxbsize", afs.fs_maxbsize, afs.fs_maxbpg,
afs.fs_maxcontig, afs.fs_contigsumsize);
printf("nbfree\t%jd\tndir\t%jd\tnifree\t%jd\tnffree\t%jd\n",
(intmax_t)afs.fs_cstotal.cs_nbfree,
(intmax_t)afs.fs_cstotal.cs_ndir,
(intmax_t)afs.fs_cstotal.cs_nifree,
(intmax_t)afs.fs_cstotal.cs_nffree);
printf("bpg\t%d\tfpg\t%d\tipg\t%d\tunrefs\t%jd\n",
afs.fs_fpg / afs.fs_frag, afs.fs_fpg, afs.fs_ipg,
(intmax_t)afs.fs_unrefs);
printf("nindir\t%d\tinopb\t%d\tmaxfilesize\t%ju\n",
afs.fs_nindir, afs.fs_inopb,
(uintmax_t)afs.fs_maxfilesize);
printf("sbsize\t%d\tcgsize\t%d\tcsaddr\t%jd\tcssize\t%d\n",
afs.fs_sbsize, afs.fs_cgsize, (intmax_t)afs.fs_csaddr,
afs.fs_cssize);
break;
case 1:
printf("maxbpg\t%d\tmaxcontig %d\tcontigsumsize %d\n",
afs.fs_maxbpg, afs.fs_maxcontig, afs.fs_contigsumsize);
printf("nbfree\t%d\tndir\t%d\tnifree\t%d\tnffree\t%d\n",
afs.fs_old_cstotal.cs_nbfree, afs.fs_old_cstotal.cs_ndir,
afs.fs_old_cstotal.cs_nifree, afs.fs_old_cstotal.cs_nffree);
printf("cpg\t%d\tbpg\t%d\tfpg\t%d\tipg\t%d\n",
afs.fs_old_cpg, afs.fs_fpg / afs.fs_frag, afs.fs_fpg,
afs.fs_ipg);
printf("nindir\t%d\tinopb\t%d\tnspf\t%d\tmaxfilesize\t%ju\n",
afs.fs_nindir, afs.fs_inopb, afs.fs_old_nspf,
(uintmax_t)afs.fs_maxfilesize);
printf("sbsize\t%d\tcgsize\t%d\tcgoffset %d\tcgmask\t0x%08x\n",
afs.fs_sbsize, afs.fs_cgsize, afs.fs_old_cgoffset,
afs.fs_old_cgmask);
printf("csaddr\t%d\tcssize\t%d\n",
afs.fs_old_csaddr, afs.fs_cssize);
printf("rotdelay %dms\trps\t%d\ttrackskew %d\tinterleave %d\n",
afs.fs_old_rotdelay, afs.fs_old_rps, afs.fs_old_trackskew,
afs.fs_old_interleave);
printf("nsect\t%d\tnpsect\t%d\tspc\t%d\n",
afs.fs_old_nsect, afs.fs_old_npsect, afs.fs_old_spc);
break;
default:
goto err;
}
printf("sblkno\t%d\tcblkno\t%d\tiblkno\t%d\tdblkno\t%d\n",
afs.fs_sblkno, afs.fs_cblkno, afs.fs_iblkno, afs.fs_dblkno);
printf("cgrotor\t%d\tfmod\t%d\tronly\t%d\tclean\t%d\n",
afs.fs_cgrotor, afs.fs_fmod, afs.fs_ronly, afs.fs_clean);
printf("avgfpdir %d\tavgfilesize %d\n",
afs.fs_avgfpdir, afs.fs_avgfilesize);
printf("flags\t");
if (afs.fs_old_flags & FS_FLAGS_UPDATED)
fsflags = afs.fs_flags;
else
fsflags = afs.fs_old_flags;
if (fsflags == 0)
printf("none");
if (fsflags & FS_UNCLEAN)
printf("unclean ");
if (fsflags & FS_DOSOFTDEP)
printf("soft-updates ");
if (fsflags & FS_NEEDSFSCK)
printf("needs fsck run ");
if (fsflags & FS_INDEXDIRS)
printf("indexed directories ");
if (fsflags & FS_ACLS)
printf("acls ");
if (fsflags & FS_MULTILABEL)
printf("multilabel ");
if (fsflags & FS_GJOURNAL)
printf("gjournal ");
if (fsflags & FS_FLAGS_UPDATED)
printf("fs_flags expanded ");
if (fsflags & FS_NFS4ACLS)
printf("nfsv4acls ");
+ if (fsflags & FS_TRIM)
+ printf("trim ");
fsflags &= ~(FS_UNCLEAN | FS_DOSOFTDEP | FS_NEEDSFSCK | FS_INDEXDIRS |
FS_ACLS | FS_MULTILABEL | FS_GJOURNAL | FS_FLAGS_UPDATED |
- FS_NFS4ACLS);
+ FS_NFS4ACLS | FS_TRIM);
if (fsflags != 0)
printf("unknown flags (%#x)", fsflags);
putchar('\n');
printf("fsmnt\t%s\n", afs.fs_fsmnt);
printf("volname\t%s\tswuid\t%ju\n",
afs.fs_volname, (uintmax_t)afs.fs_swuid);
printf("\ncs[].cs_(nbfree,ndir,nifree,nffree):\n\t");
afs.fs_csp = calloc(1, afs.fs_cssize);
if (bread(&disk, fsbtodb(&afs, afs.fs_csaddr), afs.fs_csp, afs.fs_cssize) == -1)
goto err;
for (i = 0; i < afs.fs_ncg; i++) {
struct csum *cs = &afs.fs_cs(&afs, i);
if (i && i % 4 == 0)
printf("\n\t");
printf("(%d,%d,%d,%d) ",
cs->cs_nbfree, cs->cs_ndir, cs->cs_nifree, cs->cs_nffree);
}
printf("\n");
if (fssize % afs.fs_fpg) {
if (disk.d_ufs == 1)
printf("cylinders in last group %d\n",
howmany(afs.fs_old_size % afs.fs_fpg,
afs.fs_old_spc / afs.fs_old_nspf));
printf("blocks in last group %ld\n\n",
(long)((fssize % afs.fs_fpg) / afs.fs_frag));
}
while ((i = cgread(&disk)) != 0) {
if (i == -1 || dumpcg())
goto err;
}
return (0);
err: ufserr(name);
return (1);
}
int
dumpcg(void)
{
time_t cgtime;
off_t cur;
int i, j;
printf("\ncg %d:\n", disk.d_lcg);
cur = fsbtodb(&afs, cgtod(&afs, disk.d_lcg)) * disk.d_bsize;
switch (disk.d_ufs) {
case 2:
cgtime = acg.cg_time;
printf("magic\t%x\ttell\t%jx\ttime\t%s",
acg.cg_magic, (intmax_t)cur, ctime(&cgtime));
printf("cgx\t%d\tndblk\t%d\tniblk\t%d\tinitiblk %d\tunrefs %d\n",
acg.cg_cgx, acg.cg_ndblk, acg.cg_niblk, acg.cg_initediblk,
acg.cg_unrefs);
break;
case 1:
cgtime = acg.cg_old_time;
printf("magic\t%x\ttell\t%jx\ttime\t%s",
acg.cg_magic, (intmax_t)cur, ctime(&cgtime));
printf("cgx\t%d\tncyl\t%d\tniblk\t%d\tndblk\t%d\n",
acg.cg_cgx, acg.cg_old_ncyl, acg.cg_old_niblk,
acg.cg_ndblk);
break;
default:
break;
}
printf("nbfree\t%d\tndir\t%d\tnifree\t%d\tnffree\t%d\n",
acg.cg_cs.cs_nbfree, acg.cg_cs.cs_ndir,
acg.cg_cs.cs_nifree, acg.cg_cs.cs_nffree);
printf("rotor\t%d\tirotor\t%d\tfrotor\t%d\nfrsum",
acg.cg_rotor, acg.cg_irotor, acg.cg_frotor);
for (i = 1, j = 0; i < afs.fs_frag; i++) {
printf("\t%d", acg.cg_frsum[i]);
j += i * acg.cg_frsum[i];
}
printf("\nsum of frsum: %d", j);
if (afs.fs_contigsumsize > 0) {
for (i = 1; i < afs.fs_contigsumsize; i++) {
if ((i - 1) % 8 == 0)
printf("\nclusters %d-%d:", i,
afs.fs_contigsumsize - 1 < i + 7 ?
afs.fs_contigsumsize - 1 : i + 7);
printf("\t%d", cg_clustersum(&acg)[i]);
}
printf("\nclusters size %d and over: %d\n",
afs.fs_contigsumsize,
cg_clustersum(&acg)[afs.fs_contigsumsize]);
printf("clusters free:\t");
pbits(cg_clustersfree(&acg), acg.cg_nclusterblks);
} else
printf("\n");
printf("inodes used:\t");
pbits(cg_inosused(&acg), afs.fs_ipg);
printf("blks free:\t");
pbits(cg_blksfree(&acg), afs.fs_fpg);
return (0);
}
int
dumpfreespace(const char *name, int fflag)
{
int i;
while ((i = cgread(&disk)) != 0) {
if (i == -1)
goto err;
dumpfreespacecg(fflag);
}
return (0);
err:
ufserr(name);
return (1);
}
void
dumpfreespacecg(int fflag)
{
pblklist(cg_blksfree(&acg), afs.fs_fpg, disk.d_lcg * afs.fs_fpg,
fflag);
}
int
marshal(const char *name)
{
struct fs *fs;
fs = &disk.d_fs;
printf("# newfs command for %s (%s)\n", name, disk.d_name);
printf("newfs ");
if (fs->fs_volname[0] != '\0')
printf("-L %s ", fs->fs_volname);
printf("-O %d ", disk.d_ufs);
if (fs->fs_flags & FS_DOSOFTDEP)
printf("-U ");
printf("-a %d ", fs->fs_maxcontig);
printf("-b %d ", fs->fs_bsize);
/* -c is dumb */
printf("-d %d ", fs->fs_maxbsize);
printf("-e %d ", fs->fs_maxbpg);
printf("-f %d ", fs->fs_fsize);
printf("-g %d ", fs->fs_avgfilesize);
printf("-h %d ", fs->fs_avgfpdir);
/* -i is dumb */
/* -j..l unimplemented */
printf("-m %d ", fs->fs_minfree);
/* -n unimplemented */
printf("-o ");
switch (fs->fs_optim) {
case FS_OPTSPACE:
printf("space ");
break;
case FS_OPTTIME:
printf("time ");
break;
default:
printf("unknown ");
break;
}
/* -p..r unimplemented */
printf("-s %jd ", (intmax_t)fsbtodb(fs, fs->fs_size));
printf("%s ", disk.d_name);
printf("\n");
return 0;
}
void
pbits(void *vp, int max)
{
int i;
char *p;
int count, j;
for (count = i = 0, p = vp; i < max; i++)
if (isset(p, i)) {
if (count)
printf(",%s", count % 6 ? " " : "\n\t");
count++;
printf("%d", i);
j = i;
while ((i+1)<max && isset(p, i+1))
i++;
if (i != j)
printf("-%d", i);
}
printf("\n");
}
void
pblklist(void *vp, int max, off_t offset, int fflag)
{
int i, j;
char *p;
for (i = 0, p = vp; i < max; i++) {
if (isset(p, i)) {
printf("%jd", (intmax_t)(i + offset));
if (fflag < 2) {
j = i;
while ((i+1)<max && isset(p, i+1))
i++;
if (i != j)
printf("-%jd", (intmax_t)(i + offset));
}
printf("\n");
}
}
}
void
ufserr(const char *name)
{
if (disk.d_error != NULL)
warnx("%s: %s", name, disk.d_error);
else if (errno)
warn("%s", name);
}
void
usage(void)
{
(void)fprintf(stderr, "usage: dumpfs [-fm] filesys | device\n");
exit(1);
}
Index: stable/8/sbin/dumpfs
===================================================================
--- stable/8/sbin/dumpfs (revision 218079)
+++ stable/8/sbin/dumpfs (revision 218080)
Property changes on: stable/8/sbin/dumpfs
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/dumpfs:r216798
Index: stable/8/sbin/fdisk
===================================================================
--- stable/8/sbin/fdisk (revision 218079)
+++ stable/8/sbin/fdisk (revision 218080)
Property changes on: stable/8/sbin/fdisk
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/fdisk:r216798
Index: stable/8/sbin/fsck
===================================================================
--- stable/8/sbin/fsck (revision 218079)
+++ stable/8/sbin/fsck (revision 218080)
Property changes on: stable/8/sbin/fsck
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/fsck:r216798
Index: stable/8/sbin/fsck_ffs
===================================================================
--- stable/8/sbin/fsck_ffs (revision 218079)
+++ stable/8/sbin/fsck_ffs (revision 218080)
Property changes on: stable/8/sbin/fsck_ffs
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/fsck_ffs:r216798
Index: stable/8/sbin/fsck_msdosfs
===================================================================
--- stable/8/sbin/fsck_msdosfs (revision 218079)
+++ stable/8/sbin/fsck_msdosfs (revision 218080)
Property changes on: stable/8/sbin/fsck_msdosfs
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/fsck_msdosfs:r216798
Index: stable/8/sbin/fsirand
===================================================================
--- stable/8/sbin/fsirand (revision 218079)
+++ stable/8/sbin/fsirand (revision 218080)
Property changes on: stable/8/sbin/fsirand
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/fsirand:r216798
Index: stable/8/sbin/geom/class/multipath
===================================================================
--- stable/8/sbin/geom/class/multipath (revision 218079)
+++ stable/8/sbin/geom/class/multipath (revision 218080)
Property changes on: stable/8/sbin/geom/class/multipath
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/geom/class/multipath:r216798
Index: stable/8/sbin/geom/class/part
===================================================================
--- stable/8/sbin/geom/class/part (revision 218079)
+++ stable/8/sbin/geom/class/part (revision 218080)
Property changes on: stable/8/sbin/geom/class/part
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/geom/class/part:r216798
Index: stable/8/sbin/geom/class/sched/gsched.8
===================================================================
--- stable/8/sbin/geom/class/sched/gsched.8 (revision 218079)
+++ stable/8/sbin/geom/class/sched/gsched.8 (revision 218080)
Property changes on: stable/8/sbin/geom/class/sched/gsched.8
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/geom/class/sched/gsched.8:r216798
Index: stable/8/sbin/geom/class/stripe
===================================================================
--- stable/8/sbin/geom/class/stripe (revision 218079)
+++ stable/8/sbin/geom/class/stripe (revision 218080)
Property changes on: stable/8/sbin/geom/class/stripe
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/geom/class/stripe:r216798
Index: stable/8/sbin/geom
===================================================================
--- stable/8/sbin/geom (revision 218079)
+++ stable/8/sbin/geom (revision 218080)
Property changes on: stable/8/sbin/geom
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/geom:r216798
Index: stable/8/sbin/ggate
===================================================================
--- stable/8/sbin/ggate (revision 218079)
+++ stable/8/sbin/ggate (revision 218080)
Property changes on: stable/8/sbin/ggate
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/ggate:r216798
Index: stable/8/sbin/growfs
===================================================================
--- stable/8/sbin/growfs (revision 218079)
+++ stable/8/sbin/growfs (revision 218080)
Property changes on: stable/8/sbin/growfs
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/growfs:r216798
Index: stable/8/sbin/hastctl
===================================================================
--- stable/8/sbin/hastctl (revision 218079)
+++ stable/8/sbin/hastctl (revision 218080)
Property changes on: stable/8/sbin/hastctl
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/hastctl:r216798
Index: stable/8/sbin/hastd
===================================================================
--- stable/8/sbin/hastd (revision 218079)
+++ stable/8/sbin/hastd (revision 218080)
Property changes on: stable/8/sbin/hastd
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/hastd:r216798
Index: stable/8/sbin/ifconfig
===================================================================
--- stable/8/sbin/ifconfig (revision 218079)
+++ stable/8/sbin/ifconfig (revision 218080)
Property changes on: stable/8/sbin/ifconfig
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/ifconfig:r216798
Index: stable/8/sbin/ipfw
===================================================================
--- stable/8/sbin/ipfw (revision 218079)
+++ stable/8/sbin/ipfw (revision 218080)
Property changes on: stable/8/sbin/ipfw
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/ipfw:r216798
Index: stable/8/sbin/iscontrol
===================================================================
--- stable/8/sbin/iscontrol (revision 218079)
+++ stable/8/sbin/iscontrol (revision 218080)
Property changes on: stable/8/sbin/iscontrol
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/iscontrol:r216798
Index: stable/8/sbin/kldload
===================================================================
--- stable/8/sbin/kldload (revision 218079)
+++ stable/8/sbin/kldload (revision 218080)
Property changes on: stable/8/sbin/kldload
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/kldload:r216798
Index: stable/8/sbin/kldstat
===================================================================
--- stable/8/sbin/kldstat (revision 218079)
+++ stable/8/sbin/kldstat (revision 218080)
Property changes on: stable/8/sbin/kldstat
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/kldstat:r216798
Index: stable/8/sbin/mdconfig
===================================================================
--- stable/8/sbin/mdconfig (revision 218079)
+++ stable/8/sbin/mdconfig (revision 218080)
Property changes on: stable/8/sbin/mdconfig
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/mdconfig:r216798
Index: stable/8/sbin/mksnap_ffs
===================================================================
--- stable/8/sbin/mksnap_ffs (revision 218079)
+++ stable/8/sbin/mksnap_ffs (revision 218080)
Property changes on: stable/8/sbin/mksnap_ffs
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/mksnap_ffs:r216798
Index: stable/8/sbin/mount
===================================================================
--- stable/8/sbin/mount (revision 218079)
+++ stable/8/sbin/mount (revision 218080)
Property changes on: stable/8/sbin/mount
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/mount:r216798
Index: stable/8/sbin/mount_cd9660
===================================================================
--- stable/8/sbin/mount_cd9660 (revision 218079)
+++ stable/8/sbin/mount_cd9660 (revision 218080)
Property changes on: stable/8/sbin/mount_cd9660
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/mount_cd9660:r216798
Index: stable/8/sbin/mount_msdosfs
===================================================================
--- stable/8/sbin/mount_msdosfs (revision 218079)
+++ stable/8/sbin/mount_msdosfs (revision 218080)
Property changes on: stable/8/sbin/mount_msdosfs
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/mount_msdosfs:r216798
Index: stable/8/sbin/mount_nfs
===================================================================
--- stable/8/sbin/mount_nfs (revision 218079)
+++ stable/8/sbin/mount_nfs (revision 218080)
Property changes on: stable/8/sbin/mount_nfs
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/mount_nfs:r216798
Index: stable/8/sbin/natd
===================================================================
--- stable/8/sbin/natd (revision 218079)
+++ stable/8/sbin/natd (revision 218080)
Property changes on: stable/8/sbin/natd
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/natd:r216798
Index: stable/8/sbin/newfs/mkfs.c
===================================================================
--- stable/8/sbin/newfs/mkfs.c (revision 218079)
+++ stable/8/sbin/newfs/mkfs.c (revision 218080)
@@ -1,1151 +1,1153 @@
/*
* Copyright (c) 2002 Networks Associates Technology, Inc.
* All rights reserved.
*
* This software was developed for the FreeBSD Project by Marshall
* Kirk McKusick and Network Associates Laboratories, the Security
* Research Division of Network Associates, Inc. under DARPA/SPAWAR
* contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA CHATS
* research program.
*
* Copyright (c) 1980, 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#if 0
#ifndef lint
static char sccsid[] = "@(#)mkfs.c 8.11 (Berkeley) 5/3/95";
#endif /* not lint */
#endif
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <err.h>
#include <grp.h>
#include <limits.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/param.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <ufs/ufs/dinode.h>
#include <ufs/ufs/dir.h>
#include <ufs/ffs/fs.h>
#include <sys/disklabel.h>
#include <sys/file.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include "newfs.h"
/*
* make file system for cylinder-group style file systems
*/
#define UMASK 0755
#define POWEROF2(num) (((num) & ((num) - 1)) == 0)
static struct csum *fscs;
#define sblock disk.d_fs
#define acg disk.d_cg
union dinode {
struct ufs1_dinode dp1;
struct ufs2_dinode dp2;
};
#define DIP(dp, field) \
((sblock.fs_magic == FS_UFS1_MAGIC) ? \
(dp)->dp1.field : (dp)->dp2.field)
static caddr_t iobuf;
static long iobufsize;
static ufs2_daddr_t alloc(int size, int mode);
static int charsperline(void);
static void clrblock(struct fs *, unsigned char *, int);
static void fsinit(time_t);
static int ilog2(int);
static void initcg(int, time_t);
static int isblock(struct fs *, unsigned char *, int);
static void iput(union dinode *, ino_t);
static int makedir(struct direct *, int);
static void setblock(struct fs *, unsigned char *, int);
static void wtfs(ufs2_daddr_t, int, char *);
static u_int32_t newfs_random(void);
static int
do_sbwrite(struct uufsd *disk)
{
if (!disk->d_sblock)
disk->d_sblock = disk->d_fs.fs_sblockloc / disk->d_bsize;
return (pwrite(disk->d_fd, &disk->d_fs, SBLOCKSIZE, (off_t)((part_ofs +
disk->d_sblock) * disk->d_bsize)));
}
void
mkfs(struct partition *pp, char *fsys)
{
int fragsperinode, optimalfpg, origdensity, minfpg, lastminfpg;
long i, j, csfrags;
uint cg;
time_t utime;
quad_t sizepb;
int width;
ino_t maxinum;
int minfragsperinode; /* minimum ratio of frags to inodes */
char tmpbuf[100]; /* XXX this will break in about 2,500 years */
union {
struct fs fdummy;
char cdummy[SBLOCKSIZE];
} dummy;
#define fsdummy dummy.fdummy
#define chdummy dummy.cdummy
/*
* Our blocks == sector size, and the version of UFS we are using is
* specified by Oflag.
*/
disk.d_bsize = sectorsize;
disk.d_ufs = Oflag;
if (Rflag) {
utime = 1000000000;
} else {
time(&utime);
arc4random_stir();
}
sblock.fs_old_flags = FS_FLAGS_UPDATED;
sblock.fs_flags = 0;
if (Uflag)
sblock.fs_flags |= FS_DOSOFTDEP;
if (Lflag)
strlcpy(sblock.fs_volname, volumelabel, MAXVOLLEN);
if (Jflag)
sblock.fs_flags |= FS_GJOURNAL;
if (lflag)
sblock.fs_flags |= FS_MULTILABEL;
+ if (tflag)
+ sblock.fs_flags |= FS_TRIM;
/*
* Validate the given file system size.
* Verify that its last block can actually be accessed.
* Convert to file system fragment sized units.
*/
if (fssize <= 0) {
printf("preposterous size %jd\n", (intmax_t)fssize);
exit(13);
}
wtfs(fssize - (realsectorsize / DEV_BSIZE), realsectorsize,
(char *)&sblock);
/*
* collect and verify the file system density info
*/
sblock.fs_avgfilesize = avgfilesize;
sblock.fs_avgfpdir = avgfilesperdir;
if (sblock.fs_avgfilesize <= 0)
printf("illegal expected average file size %d\n",
sblock.fs_avgfilesize), exit(14);
if (sblock.fs_avgfpdir <= 0)
printf("illegal expected number of files per directory %d\n",
sblock.fs_avgfpdir), exit(15);
restart:
/*
* collect and verify the block and fragment sizes
*/
sblock.fs_bsize = bsize;
sblock.fs_fsize = fsize;
if (!POWEROF2(sblock.fs_bsize)) {
printf("block size must be a power of 2, not %d\n",
sblock.fs_bsize);
exit(16);
}
if (!POWEROF2(sblock.fs_fsize)) {
printf("fragment size must be a power of 2, not %d\n",
sblock.fs_fsize);
exit(17);
}
if (sblock.fs_fsize < sectorsize) {
printf("increasing fragment size from %d to sector size (%d)\n",
sblock.fs_fsize, sectorsize);
sblock.fs_fsize = sectorsize;
}
if (sblock.fs_bsize > MAXBSIZE) {
printf("decreasing block size from %d to maximum (%d)\n",
sblock.fs_bsize, MAXBSIZE);
sblock.fs_bsize = MAXBSIZE;
}
if (sblock.fs_bsize < MINBSIZE) {
printf("increasing block size from %d to minimum (%d)\n",
sblock.fs_bsize, MINBSIZE);
sblock.fs_bsize = MINBSIZE;
}
if (sblock.fs_fsize > MAXBSIZE) {
printf("decreasing fragment size from %d to maximum (%d)\n",
sblock.fs_fsize, MAXBSIZE);
sblock.fs_fsize = MAXBSIZE;
}
if (sblock.fs_bsize < sblock.fs_fsize) {
printf("increasing block size from %d to fragment size (%d)\n",
sblock.fs_bsize, sblock.fs_fsize);
sblock.fs_bsize = sblock.fs_fsize;
}
if (sblock.fs_fsize * MAXFRAG < sblock.fs_bsize) {
printf(
"increasing fragment size from %d to block size / %d (%d)\n",
sblock.fs_fsize, MAXFRAG, sblock.fs_bsize / MAXFRAG);
sblock.fs_fsize = sblock.fs_bsize / MAXFRAG;
}
if (maxbsize == 0)
maxbsize = bsize;
if (maxbsize < bsize || !POWEROF2(maxbsize)) {
sblock.fs_maxbsize = sblock.fs_bsize;
printf("Extent size set to %d\n", sblock.fs_maxbsize);
} else if (sblock.fs_maxbsize > FS_MAXCONTIG * sblock.fs_bsize) {
sblock.fs_maxbsize = FS_MAXCONTIG * sblock.fs_bsize;
printf("Extent size reduced to %d\n", sblock.fs_maxbsize);
} else {
sblock.fs_maxbsize = maxbsize;
}
/*
* Maxcontig sets the default for the maximum number of blocks
* that may be allocated sequentially. With file system 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, MAXPHYS / bsize);
sblock.fs_maxcontig = maxcontig;
if (sblock.fs_maxcontig < sblock.fs_maxbsize / sblock.fs_bsize) {
sblock.fs_maxcontig = sblock.fs_maxbsize / sblock.fs_bsize;
printf("Maxcontig raised to %d\n", sblock.fs_maxbsize);
}
if (sblock.fs_maxcontig > 1)
sblock.fs_contigsumsize = MIN(sblock.fs_maxcontig,FS_MAXCONTIG);
sblock.fs_bmask = ~(sblock.fs_bsize - 1);
sblock.fs_fmask = ~(sblock.fs_fsize - 1);
sblock.fs_qbmask = ~sblock.fs_bmask;
sblock.fs_qfmask = ~sblock.fs_fmask;
sblock.fs_bshift = ilog2(sblock.fs_bsize);
sblock.fs_fshift = ilog2(sblock.fs_fsize);
sblock.fs_frag = numfrags(&sblock, sblock.fs_bsize);
sblock.fs_fragshift = ilog2(sblock.fs_frag);
if (sblock.fs_frag > MAXFRAG) {
printf("fragment size %d is still too small (can't happen)\n",
sblock.fs_bsize / MAXFRAG);
exit(21);
}
sblock.fs_fsbtodb = ilog2(sblock.fs_fsize / sectorsize);
sblock.fs_size = fssize = dbtofsb(&sblock, fssize);
/*
* Before the filesystem is finally initialized, mark it
* as incompletely initialized.
*/
sblock.fs_magic = FS_BAD_MAGIC;
if (Oflag == 1) {
sblock.fs_sblockloc = SBLOCK_UFS1;
sblock.fs_nindir = sblock.fs_bsize / sizeof(ufs1_daddr_t);
sblock.fs_inopb = sblock.fs_bsize / sizeof(struct ufs1_dinode);
sblock.fs_maxsymlinklen = ((NDADDR + NIADDR) *
sizeof(ufs1_daddr_t));
sblock.fs_old_inodefmt = FS_44INODEFMT;
sblock.fs_old_cgoffset = 0;
sblock.fs_old_cgmask = 0xffffffff;
sblock.fs_old_size = sblock.fs_size;
sblock.fs_old_rotdelay = 0;
sblock.fs_old_rps = 60;
sblock.fs_old_nspf = sblock.fs_fsize / sectorsize;
sblock.fs_old_cpg = 1;
sblock.fs_old_interleave = 1;
sblock.fs_old_trackskew = 0;
sblock.fs_old_cpc = 0;
sblock.fs_old_postblformat = 1;
sblock.fs_old_nrpos = 1;
} else {
sblock.fs_sblockloc = SBLOCK_UFS2;
sblock.fs_nindir = sblock.fs_bsize / sizeof(ufs2_daddr_t);
sblock.fs_inopb = sblock.fs_bsize / sizeof(struct ufs2_dinode);
sblock.fs_maxsymlinklen = ((NDADDR + NIADDR) *
sizeof(ufs2_daddr_t));
}
sblock.fs_sblkno =
roundup(howmany(sblock.fs_sblockloc + SBLOCKSIZE, sblock.fs_fsize),
sblock.fs_frag);
sblock.fs_cblkno = sblock.fs_sblkno +
roundup(howmany(SBLOCKSIZE, sblock.fs_fsize), sblock.fs_frag);
sblock.fs_iblkno = sblock.fs_cblkno + sblock.fs_frag;
sblock.fs_maxfilesize = sblock.fs_bsize * NDADDR - 1;
for (sizepb = sblock.fs_bsize, i = 0; i < NIADDR; i++) {
sizepb *= NINDIR(&sblock);
sblock.fs_maxfilesize += sizepb;
}
/*
* It's impossible to create a snapshot in case that fs_maxfilesize
* is smaller than the fssize.
*/
if (sblock.fs_maxfilesize < (u_quad_t)fssize) {
warnx("WARNING: You will be unable to create snapshots on this "
"file system. Correct by using a larger blocksize.");
}
/*
* Calculate the number of blocks to put into each cylinder group.
*
* This algorithm selects the number of blocks per cylinder
* group. The first goal is to have at least enough data blocks
* in each cylinder group to meet the density requirement. Once
* this goal is achieved we try to expand to have at least
* MINCYLGRPS cylinder groups. Once this goal is achieved, we
* pack as many blocks into each cylinder group map as will fit.
*
* We start by calculating the smallest number of blocks that we
* can put into each cylinder group. If this is too big, we reduce
* the density until it fits.
*/
maxinum = (((int64_t)(1)) << 32) - INOPB(&sblock);
minfragsperinode = 1 + fssize / maxinum;
if (density == 0) {
density = MAX(NFPI, minfragsperinode) * fsize;
} else if (density < minfragsperinode * fsize) {
origdensity = density;
density = minfragsperinode * fsize;
fprintf(stderr, "density increased from %d to %d\n",
origdensity, density);
}
origdensity = density;
for (;;) {
fragsperinode = MAX(numfrags(&sblock, density), 1);
if (fragsperinode < minfragsperinode) {
bsize <<= 1;
fsize <<= 1;
printf("Block size too small for a file system %s %d\n",
"of this size. Increasing blocksize to", bsize);
goto restart;
}
minfpg = fragsperinode * INOPB(&sblock);
if (minfpg > sblock.fs_size)
minfpg = sblock.fs_size;
sblock.fs_ipg = INOPB(&sblock);
sblock.fs_fpg = roundup(sblock.fs_iblkno +
sblock.fs_ipg / INOPF(&sblock), sblock.fs_frag);
if (sblock.fs_fpg < minfpg)
sblock.fs_fpg = minfpg;
sblock.fs_ipg = roundup(howmany(sblock.fs_fpg, fragsperinode),
INOPB(&sblock));
sblock.fs_fpg = roundup(sblock.fs_iblkno +
sblock.fs_ipg / INOPF(&sblock), sblock.fs_frag);
if (sblock.fs_fpg < minfpg)
sblock.fs_fpg = minfpg;
sblock.fs_ipg = roundup(howmany(sblock.fs_fpg, fragsperinode),
INOPB(&sblock));
if (CGSIZE(&sblock) < (unsigned long)sblock.fs_bsize)
break;
density -= sblock.fs_fsize;
}
if (density != origdensity)
printf("density reduced from %d to %d\n", origdensity, density);
/*
* Start packing more blocks into the cylinder group until
* it cannot grow any larger, the number of cylinder groups
* drops below MINCYLGRPS, or we reach the size requested.
* For UFS1 inodes per cylinder group are stored in an int16_t
* so fs_ipg is limited to 2^15 - 1.
*/
for ( ; sblock.fs_fpg < maxblkspercg; sblock.fs_fpg += sblock.fs_frag) {
sblock.fs_ipg = roundup(howmany(sblock.fs_fpg, fragsperinode),
INOPB(&sblock));
if (Oflag > 1 || (Oflag == 1 && sblock.fs_ipg <= 0x7fff)) {
if (sblock.fs_size / sblock.fs_fpg < MINCYLGRPS)
break;
if (CGSIZE(&sblock) < (unsigned long)sblock.fs_bsize)
continue;
if (CGSIZE(&sblock) == (unsigned long)sblock.fs_bsize)
break;
}
sblock.fs_fpg -= sblock.fs_frag;
sblock.fs_ipg = roundup(howmany(sblock.fs_fpg, fragsperinode),
INOPB(&sblock));
break;
}
/*
* Check to be sure that the last cylinder group has enough blocks
* to be viable. If it is too small, reduce the number of blocks
* per cylinder group which will have the effect of moving more
* blocks into the last cylinder group.
*/
optimalfpg = sblock.fs_fpg;
for (;;) {
sblock.fs_ncg = howmany(sblock.fs_size, sblock.fs_fpg);
lastminfpg = roundup(sblock.fs_iblkno +
sblock.fs_ipg / INOPF(&sblock), sblock.fs_frag);
if (sblock.fs_size < lastminfpg) {
printf("Filesystem size %jd < minimum size of %d\n",
(intmax_t)sblock.fs_size, lastminfpg);
exit(28);
}
if (sblock.fs_size % sblock.fs_fpg >= lastminfpg ||
sblock.fs_size % sblock.fs_fpg == 0)
break;
sblock.fs_fpg -= sblock.fs_frag;
sblock.fs_ipg = roundup(howmany(sblock.fs_fpg, fragsperinode),
INOPB(&sblock));
}
if (optimalfpg != sblock.fs_fpg)
printf("Reduced frags per cylinder group from %d to %d %s\n",
optimalfpg, sblock.fs_fpg, "to enlarge last cyl group");
sblock.fs_cgsize = fragroundup(&sblock, CGSIZE(&sblock));
sblock.fs_dblkno = sblock.fs_iblkno + sblock.fs_ipg / INOPF(&sblock);
if (Oflag == 1) {
sblock.fs_old_spc = sblock.fs_fpg * sblock.fs_old_nspf;
sblock.fs_old_nsect = sblock.fs_old_spc;
sblock.fs_old_npsect = sblock.fs_old_spc;
sblock.fs_old_ncyl = sblock.fs_ncg;
}
/*
* fill in remaining fields of the super block
*/
sblock.fs_csaddr = cgdmin(&sblock, 0);
sblock.fs_cssize =
fragroundup(&sblock, sblock.fs_ncg * sizeof(struct csum));
fscs = (struct csum *)calloc(1, sblock.fs_cssize);
if (fscs == NULL)
errx(31, "calloc failed");
sblock.fs_sbsize = fragroundup(&sblock, sizeof(struct fs));
if (sblock.fs_sbsize > SBLOCKSIZE)
sblock.fs_sbsize = SBLOCKSIZE;
sblock.fs_minfree = minfree;
if (maxbpg == 0)
sblock.fs_maxbpg = MAXBLKPG(sblock.fs_bsize);
else
sblock.fs_maxbpg = maxbpg;
sblock.fs_optim = opt;
sblock.fs_cgrotor = 0;
sblock.fs_pendingblocks = 0;
sblock.fs_pendinginodes = 0;
sblock.fs_fmod = 0;
sblock.fs_ronly = 0;
sblock.fs_state = 0;
sblock.fs_clean = 1;
sblock.fs_id[0] = (long)utime;
sblock.fs_id[1] = newfs_random();
sblock.fs_fsmnt[0] = '\0';
csfrags = howmany(sblock.fs_cssize, sblock.fs_fsize);
sblock.fs_dsize = sblock.fs_size - sblock.fs_sblkno -
sblock.fs_ncg * (sblock.fs_dblkno - sblock.fs_sblkno);
sblock.fs_cstotal.cs_nbfree =
fragstoblks(&sblock, sblock.fs_dsize) -
howmany(csfrags, sblock.fs_frag);
sblock.fs_cstotal.cs_nffree =
fragnum(&sblock, sblock.fs_size) +
(fragnum(&sblock, csfrags) > 0 ?
sblock.fs_frag - fragnum(&sblock, csfrags) : 0);
sblock.fs_cstotal.cs_nifree = sblock.fs_ncg * sblock.fs_ipg - ROOTINO;
sblock.fs_cstotal.cs_ndir = 0;
sblock.fs_dsize -= csfrags;
sblock.fs_time = utime;
if (Oflag == 1) {
sblock.fs_old_time = utime;
sblock.fs_old_dsize = sblock.fs_dsize;
sblock.fs_old_csaddr = sblock.fs_csaddr;
sblock.fs_old_cstotal.cs_ndir = sblock.fs_cstotal.cs_ndir;
sblock.fs_old_cstotal.cs_nbfree = sblock.fs_cstotal.cs_nbfree;
sblock.fs_old_cstotal.cs_nifree = sblock.fs_cstotal.cs_nifree;
sblock.fs_old_cstotal.cs_nffree = sblock.fs_cstotal.cs_nffree;
}
/*
* Dump out summary information about file system.
*/
# define B2MBFACTOR (1 / (1024.0 * 1024.0))
printf("%s: %.1fMB (%jd sectors) block size %d, fragment size %d\n",
fsys, (float)sblock.fs_size * sblock.fs_fsize * B2MBFACTOR,
(intmax_t)fsbtodb(&sblock, sblock.fs_size), sblock.fs_bsize,
sblock.fs_fsize);
printf("\tusing %d cylinder groups of %.2fMB, %d blks, %d inodes.\n",
sblock.fs_ncg, (float)sblock.fs_fpg * sblock.fs_fsize * B2MBFACTOR,
sblock.fs_fpg / sblock.fs_frag, sblock.fs_ipg);
if (sblock.fs_flags & FS_DOSOFTDEP)
printf("\twith soft updates\n");
# undef B2MBFACTOR
if (Eflag && !Nflag) {
printf("Erasing sectors [%jd...%jd]\n",
sblock.fs_sblockloc / disk.d_bsize,
fsbtodb(&sblock, sblock.fs_size) - 1);
berase(&disk, sblock.fs_sblockloc / disk.d_bsize,
sblock.fs_size * sblock.fs_fsize - sblock.fs_sblockloc);
}
/*
* Wipe out old UFS1 superblock(s) if necessary.
*/
if (!Nflag && Oflag != 1) {
i = bread(&disk, part_ofs + SBLOCK_UFS1 / disk.d_bsize, chdummy, SBLOCKSIZE);
if (i == -1)
err(1, "can't read old UFS1 superblock: %s", disk.d_error);
if (fsdummy.fs_magic == FS_UFS1_MAGIC) {
fsdummy.fs_magic = 0;
bwrite(&disk, part_ofs + SBLOCK_UFS1 / disk.d_bsize,
chdummy, SBLOCKSIZE);
for (cg = 0; cg < fsdummy.fs_ncg; cg++)
bwrite(&disk, part_ofs + fsbtodb(&fsdummy,
cgsblock(&fsdummy, cg)), chdummy, SBLOCKSIZE);
}
}
if (!Nflag)
do_sbwrite(&disk);
if (Xflag == 1) {
printf("** Exiting on Xflag 1\n");
exit(0);
}
if (Xflag == 2)
printf("** Leaving BAD MAGIC on Xflag 2\n");
else
sblock.fs_magic = (Oflag != 1) ? FS_UFS2_MAGIC : FS_UFS1_MAGIC;
/*
* Now build the cylinders group blocks and
* then print out indices of cylinder groups.
*/
printf("super-block backups (for fsck -b #) at:\n");
i = 0;
width = charsperline();
/*
* allocate space for superblock, cylinder group map, and
* two sets of inode blocks.
*/
if (sblock.fs_bsize < SBLOCKSIZE)
iobufsize = SBLOCKSIZE + 3 * sblock.fs_bsize;
else
iobufsize = 4 * sblock.fs_bsize;
if ((iobuf = calloc(1, iobufsize)) == 0) {
printf("Cannot allocate I/O buffer\n");
exit(38);
}
/*
* Make a copy of the superblock into the buffer that we will be
* writing out in each cylinder group.
*/
bcopy((char *)&sblock, iobuf, SBLOCKSIZE);
for (cg = 0; cg < sblock.fs_ncg; cg++) {
initcg(cg, utime);
j = snprintf(tmpbuf, sizeof(tmpbuf), " %jd%s",
(intmax_t)fsbtodb(&sblock, cgsblock(&sblock, cg)),
cg < (sblock.fs_ncg-1) ? "," : "");
if (j < 0)
tmpbuf[j = 0] = '\0';
if (i + j >= width) {
printf("\n");
i = 0;
}
i += j;
printf("%s", tmpbuf);
fflush(stdout);
}
printf("\n");
if (Nflag)
exit(0);
/*
* Now construct the initial file system,
* then write out the super-block.
*/
fsinit(utime);
if (Oflag == 1) {
sblock.fs_old_cstotal.cs_ndir = sblock.fs_cstotal.cs_ndir;
sblock.fs_old_cstotal.cs_nbfree = sblock.fs_cstotal.cs_nbfree;
sblock.fs_old_cstotal.cs_nifree = sblock.fs_cstotal.cs_nifree;
sblock.fs_old_cstotal.cs_nffree = sblock.fs_cstotal.cs_nffree;
}
if (Xflag == 3) {
printf("** Exiting on Xflag 3\n");
exit(0);
}
if (!Nflag) {
do_sbwrite(&disk);
/*
* For UFS1 filesystems with a blocksize of 64K, the first
* alternate superblock resides at the location used for
* the default UFS2 superblock. As there is a valid
* superblock at this location, the boot code will use
* it as its first choice. Thus we have to ensure that
* all of its statistcs on usage are correct.
*/
if (Oflag == 1 && sblock.fs_bsize == 65536)
wtfs(fsbtodb(&sblock, cgsblock(&sblock, 0)),
sblock.fs_bsize, (char *)&sblock);
}
for (i = 0; i < sblock.fs_cssize; i += sblock.fs_bsize)
wtfs(fsbtodb(&sblock, sblock.fs_csaddr + numfrags(&sblock, i)),
sblock.fs_cssize - i < sblock.fs_bsize ?
sblock.fs_cssize - i : sblock.fs_bsize,
((char *)fscs) + i);
/*
* Update information about this partion in pack
* label, to that it may be updated on disk.
*/
if (pp != NULL) {
pp->p_fstype = FS_BSDFFS;
pp->p_fsize = sblock.fs_fsize;
pp->p_frag = sblock.fs_frag;
pp->p_cpg = sblock.fs_fpg;
}
}
/*
* Initialize a cylinder group.
*/
void
initcg(int cylno, time_t utime)
{
long blkno, start;
uint i, j, d, dlower, dupper;
ufs2_daddr_t cbase, dmax;
struct ufs1_dinode *dp1;
struct ufs2_dinode *dp2;
struct csum *cs;
/*
* Determine block bounds for cylinder group.
* Allow space for super block summary information in first
* cylinder group.
*/
cbase = cgbase(&sblock, cylno);
dmax = cbase + sblock.fs_fpg;
if (dmax > sblock.fs_size)
dmax = sblock.fs_size;
dlower = cgsblock(&sblock, cylno) - cbase;
dupper = cgdmin(&sblock, cylno) - cbase;
if (cylno == 0)
dupper += howmany(sblock.fs_cssize, sblock.fs_fsize);
cs = &fscs[cylno];
memset(&acg, 0, sblock.fs_cgsize);
acg.cg_time = utime;
acg.cg_magic = CG_MAGIC;
acg.cg_cgx = cylno;
acg.cg_niblk = sblock.fs_ipg;
acg.cg_initediblk = sblock.fs_ipg < 2 * INOPB(&sblock) ?
sblock.fs_ipg : 2 * INOPB(&sblock);
acg.cg_ndblk = dmax - cbase;
if (sblock.fs_contigsumsize > 0)
acg.cg_nclusterblks = acg.cg_ndblk / sblock.fs_frag;
start = &acg.cg_space[0] - (u_char *)(&acg.cg_firstfield);
if (Oflag == 2) {
acg.cg_iusedoff = start;
} else {
acg.cg_old_ncyl = sblock.fs_old_cpg;
acg.cg_old_time = acg.cg_time;
acg.cg_time = 0;
acg.cg_old_niblk = acg.cg_niblk;
acg.cg_niblk = 0;
acg.cg_initediblk = 0;
acg.cg_old_btotoff = start;
acg.cg_old_boff = acg.cg_old_btotoff +
sblock.fs_old_cpg * sizeof(int32_t);
acg.cg_iusedoff = acg.cg_old_boff +
sblock.fs_old_cpg * sizeof(u_int16_t);
}
acg.cg_freeoff = acg.cg_iusedoff + howmany(sblock.fs_ipg, CHAR_BIT);
acg.cg_nextfreeoff = acg.cg_freeoff + howmany(sblock.fs_fpg, CHAR_BIT);
if (sblock.fs_contigsumsize > 0) {
acg.cg_clustersumoff =
roundup(acg.cg_nextfreeoff, sizeof(u_int32_t));
acg.cg_clustersumoff -= sizeof(u_int32_t);
acg.cg_clusteroff = acg.cg_clustersumoff +
(sblock.fs_contigsumsize + 1) * sizeof(u_int32_t);
acg.cg_nextfreeoff = acg.cg_clusteroff +
howmany(fragstoblks(&sblock, sblock.fs_fpg), CHAR_BIT);
}
if (acg.cg_nextfreeoff > (unsigned)sblock.fs_cgsize) {
printf("Panic: cylinder group too big\n");
exit(37);
}
acg.cg_cs.cs_nifree += sblock.fs_ipg;
if (cylno == 0)
for (i = 0; i < (long)ROOTINO; i++) {
setbit(cg_inosused(&acg), i);
acg.cg_cs.cs_nifree--;
}
if (cylno > 0) {
/*
* In cylno 0, beginning space is reserved
* for boot and super blocks.
*/
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++;
}
}
if ((i = dupper % sblock.fs_frag)) {
acg.cg_frsum[sblock.fs_frag - i]++;
for (d = dupper + sblock.fs_frag - i; dupper < d; dupper++) {
setbit(cg_blksfree(&acg), dupper);
acg.cg_cs.cs_nffree++;
}
}
for (d = dupper; d + sblock.fs_frag <= acg.cg_ndblk;
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++;
}
if (d < acg.cg_ndblk) {
acg.cg_frsum[acg.cg_ndblk - d]++;
for (; d < acg.cg_ndblk; d++) {
setbit(cg_blksfree(&acg), d);
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 & (CHAR_BIT - 1)) != CHAR_BIT - 1)
bit <<= 1;
else {
map = *mapp++;
bit = 1;
}
}
if (run != 0) {
if (run > sblock.fs_contigsumsize)
run = sblock.fs_contigsumsize;
sump[run]++;
}
}
*cs = acg.cg_cs;
/*
* Write out the duplicate super block, the cylinder group map
* and two blocks worth of inodes in a single write.
*/
start = sblock.fs_bsize > SBLOCKSIZE ? sblock.fs_bsize : SBLOCKSIZE;
bcopy((char *)&acg, &iobuf[start], sblock.fs_cgsize);
start += sblock.fs_bsize;
dp1 = (struct ufs1_dinode *)(&iobuf[start]);
dp2 = (struct ufs2_dinode *)(&iobuf[start]);
for (i = 0; i < acg.cg_initediblk; i++) {
if (sblock.fs_magic == FS_UFS1_MAGIC) {
dp1->di_gen = newfs_random();
dp1++;
} else {
dp2->di_gen = newfs_random();
dp2++;
}
}
wtfs(fsbtodb(&sblock, cgsblock(&sblock, cylno)), iobufsize, iobuf);
/*
* For the old file system, we have to initialize all the inodes.
*/
if (Oflag == 1) {
for (i = 2 * sblock.fs_frag;
i < sblock.fs_ipg / INOPF(&sblock);
i += sblock.fs_frag) {
dp1 = (struct ufs1_dinode *)(&iobuf[start]);
for (j = 0; j < INOPB(&sblock); j++) {
dp1->di_gen = newfs_random();
dp1++;
}
wtfs(fsbtodb(&sblock, cgimin(&sblock, cylno) + i),
sblock.fs_bsize, &iobuf[start]);
}
}
}
/*
* initialize the file system
*/
#define ROOTLINKCNT 3
struct direct root_dir[] = {
{ ROOTINO, sizeof(struct direct), DT_DIR, 1, "." },
{ ROOTINO, sizeof(struct direct), DT_DIR, 2, ".." },
{ ROOTINO + 1, sizeof(struct direct), DT_DIR, 5, ".snap" },
};
#define SNAPLINKCNT 2
struct direct snap_dir[] = {
{ ROOTINO + 1, sizeof(struct direct), DT_DIR, 1, "." },
{ ROOTINO, sizeof(struct direct), DT_DIR, 2, ".." },
};
void
fsinit(time_t utime)
{
union dinode node;
struct group *grp;
gid_t gid;
int entries;
memset(&node, 0, sizeof node);
if ((grp = getgrnam("operator")) != NULL) {
gid = grp->gr_gid;
} else {
warnx("Cannot retrieve operator gid, using gid 0.");
gid = 0;
}
entries = (nflag) ? ROOTLINKCNT - 1: ROOTLINKCNT;
if (sblock.fs_magic == FS_UFS1_MAGIC) {
/*
* initialize the node
*/
node.dp1.di_atime = utime;
node.dp1.di_mtime = utime;
node.dp1.di_ctime = utime;
/*
* create the root directory
*/
node.dp1.di_mode = IFDIR | UMASK;
node.dp1.di_nlink = entries;
node.dp1.di_size = makedir(root_dir, entries);
node.dp1.di_db[0] = alloc(sblock.fs_fsize, node.dp1.di_mode);
node.dp1.di_blocks =
btodb(fragroundup(&sblock, node.dp1.di_size));
wtfs(fsbtodb(&sblock, node.dp1.di_db[0]), sblock.fs_fsize,
iobuf);
iput(&node, ROOTINO);
if (!nflag) {
/*
* create the .snap directory
*/
node.dp1.di_mode |= 020;
node.dp1.di_gid = gid;
node.dp1.di_nlink = SNAPLINKCNT;
node.dp1.di_size = makedir(snap_dir, SNAPLINKCNT);
node.dp1.di_db[0] =
alloc(sblock.fs_fsize, node.dp1.di_mode);
node.dp1.di_blocks =
btodb(fragroundup(&sblock, node.dp1.di_size));
wtfs(fsbtodb(&sblock, node.dp1.di_db[0]),
sblock.fs_fsize, iobuf);
iput(&node, ROOTINO + 1);
}
} else {
/*
* initialize the node
*/
node.dp2.di_atime = utime;
node.dp2.di_mtime = utime;
node.dp2.di_ctime = utime;
node.dp2.di_birthtime = utime;
/*
* create the root directory
*/
node.dp2.di_mode = IFDIR | UMASK;
node.dp2.di_nlink = entries;
node.dp2.di_size = makedir(root_dir, entries);
node.dp2.di_db[0] = alloc(sblock.fs_fsize, node.dp2.di_mode);
node.dp2.di_blocks =
btodb(fragroundup(&sblock, node.dp2.di_size));
wtfs(fsbtodb(&sblock, node.dp2.di_db[0]), sblock.fs_fsize,
iobuf);
iput(&node, ROOTINO);
if (!nflag) {
/*
* create the .snap directory
*/
node.dp2.di_mode |= 020;
node.dp2.di_gid = gid;
node.dp2.di_nlink = SNAPLINKCNT;
node.dp2.di_size = makedir(snap_dir, SNAPLINKCNT);
node.dp2.di_db[0] =
alloc(sblock.fs_fsize, node.dp2.di_mode);
node.dp2.di_blocks =
btodb(fragroundup(&sblock, node.dp2.di_size));
wtfs(fsbtodb(&sblock, node.dp2.di_db[0]),
sblock.fs_fsize, iobuf);
iput(&node, ROOTINO + 1);
}
}
}
/*
* construct a set of directory entries in "iobuf".
* return size of directory.
*/
int
makedir(struct direct *protodir, int entries)
{
char *cp;
int i, spcleft;
spcleft = DIRBLKSIZ;
memset(iobuf, 0, DIRBLKSIZ);
for (cp = iobuf, i = 0; i < entries - 1; i++) {
protodir[i].d_reclen = DIRSIZ(0, &protodir[i]);
memmove(cp, &protodir[i], protodir[i].d_reclen);
cp += protodir[i].d_reclen;
spcleft -= protodir[i].d_reclen;
}
protodir[i].d_reclen = spcleft;
memmove(cp, &protodir[i], DIRSIZ(0, &protodir[i]));
return (DIRBLKSIZ);
}
/*
* allocate a block or frag
*/
ufs2_daddr_t
alloc(int size, int mode)
{
int i, blkno, frag;
uint d;
bread(&disk, part_ofs + fsbtodb(&sblock, cgtod(&sblock, 0)), (char *)&acg,
sblock.fs_cgsize);
if (acg.cg_magic != CG_MAGIC) {
printf("cg 0: bad magic number\n");
exit(38);
}
if (acg.cg_cs.cs_nbfree == 0) {
printf("first cylinder group ran out of space\n");
exit(39);
}
for (d = 0; d < acg.cg_ndblk; d += sblock.fs_frag)
if (isblock(&sblock, cg_blksfree(&acg), d / sblock.fs_frag))
goto goth;
printf("internal error: can't find block in cyl 0\n");
exit(40);
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_cstotal.cs_nbfree--;
fscs[0].cs_nbfree--;
if (mode & IFDIR) {
acg.cg_cs.cs_ndir++;
sblock.fs_cstotal.cs_ndir++;
fscs[0].cs_ndir++;
}
if (size != sblock.fs_bsize) {
frag = howmany(size, sblock.fs_fsize);
fscs[0].cs_nffree += sblock.fs_frag - frag;
sblock.fs_cstotal.cs_nffree += sblock.fs_frag - frag;
acg.cg_cs.cs_nffree += sblock.fs_frag - frag;
acg.cg_frsum[sblock.fs_frag - frag]++;
for (i = frag; i < sblock.fs_frag; i++)
setbit(cg_blksfree(&acg), d + i);
}
/* XXX cgwrite(&disk, 0)??? */
wtfs(fsbtodb(&sblock, cgtod(&sblock, 0)), sblock.fs_cgsize,
(char *)&acg);
return ((ufs2_daddr_t)d);
}
/*
* Allocate an inode on the disk
*/
void
iput(union dinode *ip, ino_t ino)
{
ufs2_daddr_t d;
int c;
c = ino_to_cg(&sblock, ino);
bread(&disk, part_ofs + fsbtodb(&sblock, cgtod(&sblock, 0)), (char *)&acg,
sblock.fs_cgsize);
if (acg.cg_magic != CG_MAGIC) {
printf("cg 0: bad magic number\n");
exit(31);
}
acg.cg_cs.cs_nifree--;
setbit(cg_inosused(&acg), ino);
wtfs(fsbtodb(&sblock, cgtod(&sblock, 0)), sblock.fs_cgsize,
(char *)&acg);
sblock.fs_cstotal.cs_nifree--;
fscs[0].cs_nifree--;
if (ino >= (unsigned long)sblock.fs_ipg * sblock.fs_ncg) {
printf("fsinit: inode value out of range (%d).\n", ino);
exit(32);
}
d = fsbtodb(&sblock, ino_to_fsba(&sblock, ino));
bread(&disk, part_ofs + d, (char *)iobuf, sblock.fs_bsize);
if (sblock.fs_magic == FS_UFS1_MAGIC)
((struct ufs1_dinode *)iobuf)[ino_to_fsbo(&sblock, ino)] =
ip->dp1;
else
((struct ufs2_dinode *)iobuf)[ino_to_fsbo(&sblock, ino)] =
ip->dp2;
wtfs(d, sblock.fs_bsize, (char *)iobuf);
}
/*
* possibly write to disk
*/
static void
wtfs(ufs2_daddr_t bno, int size, char *bf)
{
if (Nflag)
return;
if (bwrite(&disk, part_ofs + bno, bf, size) < 0)
err(36, "wtfs: %d bytes at sector %jd", size, (intmax_t)bno);
}
/*
* check if a block is available
*/
static int
isblock(struct fs *fs, unsigned char *cp, int h)
{
unsigned char mask;
switch (fs->fs_frag) {
case 8:
return (cp[h] == 0xff);
case 4:
mask = 0x0f << ((h & 0x1) << 2);
return ((cp[h >> 1] & mask) == mask);
case 2:
mask = 0x03 << ((h & 0x3) << 1);
return ((cp[h >> 2] & mask) == mask);
case 1:
mask = 0x01 << (h & 0x7);
return ((cp[h >> 3] & mask) == mask);
default:
fprintf(stderr, "isblock bad fs_frag %d\n", fs->fs_frag);
return (0);
}
}
/*
* take a block out of the map
*/
static void
clrblock(struct fs *fs, unsigned char *cp, int h)
{
switch ((fs)->fs_frag) {
case 8:
cp[h] = 0;
return;
case 4:
cp[h >> 1] &= ~(0x0f << ((h & 0x1) << 2));
return;
case 2:
cp[h >> 2] &= ~(0x03 << ((h & 0x3) << 1));
return;
case 1:
cp[h >> 3] &= ~(0x01 << (h & 0x7));
return;
default:
fprintf(stderr, "clrblock bad fs_frag %d\n", fs->fs_frag);
return;
}
}
/*
* put a block into the map
*/
static void
setblock(struct fs *fs, unsigned char *cp, int h)
{
switch (fs->fs_frag) {
case 8:
cp[h] = 0xff;
return;
case 4:
cp[h >> 1] |= (0x0f << ((h & 0x1) << 2));
return;
case 2:
cp[h >> 2] |= (0x03 << ((h & 0x3) << 1));
return;
case 1:
cp[h >> 3] |= (0x01 << (h & 0x7));
return;
default:
fprintf(stderr, "setblock bad fs_frag %d\n", fs->fs_frag);
return;
}
}
/*
* Determine the number of characters in a
* single line.
*/
static int
charsperline(void)
{
int columns;
char *cp;
struct winsize ws;
columns = 0;
if (ioctl(0, TIOCGWINSZ, &ws) != -1)
columns = ws.ws_col;
if (columns == 0 && (cp = getenv("COLUMNS")))
columns = atoi(cp);
if (columns == 0)
columns = 80; /* last resort */
return (columns);
}
static int
ilog2(int val)
{
u_int n;
for (n = 0; n < sizeof(n) * CHAR_BIT; n++)
if (1 << n == val)
return (n);
errx(1, "ilog2: %d is not a power of 2\n", val);
}
/*
* For the regression test, return predictable random values.
* Otherwise use a true random number generator.
*/
static u_int32_t
newfs_random(void)
{
static int nextnum = 1;
if (Rflag)
return (nextnum++);
return (arc4random());
}
Index: stable/8/sbin/newfs/newfs.8
===================================================================
--- stable/8/sbin/newfs/newfs.8 (revision 218079)
+++ stable/8/sbin/newfs/newfs.8 (revision 218080)
@@ -1,304 +1,312 @@
.\" Copyright (c) 1983, 1987, 1991, 1993, 1994
.\" The Regents of the University of California. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)newfs.8 8.6 (Berkeley) 5/3/95
.\" $FreeBSD$
.\"
-.Dd March 21, 2008
+.Dd December 9, 2010
.Dt NEWFS 8
.Os
.Sh NAME
.Nm newfs
.Nd construct a new UFS1/UFS2 file system
.Sh SYNOPSIS
.Nm
-.Op Fl EJNUln
+.Op Fl EJNUlnt
.Op Fl L Ar volname
.Op Fl O Ar filesystem-type
.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 blocks-per-cylinder-group
.Op Fl d Ar max-extent-size
.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 m Ar free-space
.Op Fl o Ar optimization
.Op Fl p Ar partition
.Op Fl r Ar reserved
.Op Fl s Ar size
.Ar special
.Sh DESCRIPTION
The
.Nm
utility is used to initialize and clear file systems before first use.
The
.Nm
utility builds a file system on the specified special file.
(We often refer to the
.Dq special file
as the
.Dq disk ,
although the special file need not be a physical disk.
In fact, it need not even be special.)
Typically the defaults are reasonable, however
.Nm
has numerous options to allow the defaults to be selectively overridden.
.Pp
The following options define the general layout policies:
.Bl -tag -width indent
.It Fl E
Erase the content of the disk before making the filesystem.
The reserved area in front of the superblock (for bootcode) will not be erased.
This is a relevant option for flash based storage devices that use
wear levelling algorithms.
NB: Erasing may take as long time as writing every sector on the disk.
.It Fl J
Enable journaling on the new file system via gjournal.
See
.Xr gjournal 8
for details.
.It Fl L Ar volname
Add a volume label to the new file system.
.It Fl N
Cause the file system parameters to be printed out
without really creating the file system.
.It Fl O Ar filesystem-type
Use 1 to specify that a UFS1 format file system be built;
use 2 to specify that a UFS2 format file system be built.
The default format is UFS2.
.It Fl T Ar disktype
For backward compatibility.
.It Fl U
Enable soft updates on the new file system.
.It Fl a Ar maxcontig
Specify the maximum number of contiguous blocks that will be
laid out before forcing a rotational delay.
The default value is 16.
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.
It must be a power of 2.
The
default size is 16384 bytes, and the smallest allowable size is 4096 bytes.
The optimal block:fragment ratio is 8:1.
Other ratios are possible, but are not recommended,
and may produce poor results.
.It Fl c Ar blocks-per-cylinder-group
The number of blocks per cylinder group in a file system.
The default is to compute the maximum allowed by the other parameters.
This value is
dependent on a number of other parameters, in particular the block size
and the number of bytes per inode.
.It Fl d Ar max-extent-size
The file system may choose to store large files using extents.
This parameter specifies the largest extent size that may be used.
It is presently limited to its default value which is 16 times
the file system blocksize.
.It Fl e Ar maxbpg
Indicate 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.
It must be a power of two
ranging in value between
.Ar blocksize Ns /8
and
.Ar blocksize .
The default is 2048 bytes.
.It Fl g Ar avgfilesize
The expected average file size for the file system.
.It Fl h Ar avgfpdir
The expected average number of files per directory on the file system.
.It Fl i Ar bytes
Specify the density of inodes in the file system.
The default is to create an inode for every
.Pq 4 * Ar frag-size
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.
One inode is required for each distinct file, so this value effectively
specifies the average file size on the file system.
.It Fl l
Enable multilabel MAC on the new file system.
.It Fl m Ar free-space
The percentage of space reserved from normal users; the minimum free
space threshold.
The default value used is
defined by
.Dv MINFREE
from
.In ufs/ffs/fs.h ,
currently 8%.
See
.Xr tunefs 8
for more details on how to set this option.
.It Fl n
Do not create a
.Pa .snap
directory on the new file system.
The resulting file system will not support snapshot generation, so
.Xr dump 8
in live mode and background
.Xr fsck 8
will not function properly.
The traditional
.Xr fsck 8
and offline
.Xr dump 8
will work on the file system.
This option is intended primarily for memory or vnode-backed file systems that
do not require
.Xr dump 8
or
.Xr fsck 8
support.
.It Fl o Ar optimization
.Cm ( space
or
.Cm 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.
If the value of minfree (see above) is less than 8%,
the default is to optimize for
.Cm space ;
if the value of minfree is greater than or equal to 8%,
the default is to optimize for
.Cm time .
See
.Xr tunefs 8
for more details on how to set this option.
.It Fl p Ar partition
The partition name (a..h) you want to use in case the underlying image
is a file, so you don't have access to individual partitions through the
filesystem.
Can also be used with a device, e.g.
.Nm
.Fl p Ar f
.Ar /dev/da1s3
is equivalent to
.Nm
.Ar /dev/da1s3f .
.It Fl r Ar reserved
The size, in sectors, of reserved space
at the end of the partition specified in
.Ar special .
This space will not be occupied by the file system;
it can be used by other consumers such as
.Xr geom 4 .
Defaults to 0.
.It Fl s Ar size
The size of the file system in sectors.
This value defaults to the size of the
raw partition specified in
.Ar special
less the
.Ar reserved
space at its end (see
.Fl r ) .
A
.Ar size
of 0 can also be used to choose the default value.
A valid
.Ar size
value cannot be larger than the default one,
which means that the file system cannot extend into the reserved space.
+.It Fl t
+Turn on the TRIM enable flag.
+If enabled, and if the underlying device supports the BIO_DELETE
+command, the file system will send a delete request to the underlying
+device for each freed block.
+The trim enable flag is typically set when the underlying device
+uses flash-memory as the device can use the delete command to
+pre-zero or at least avoid copying blocks that have been deleted.
.El
.Pp
The following options override the standard sizes for the disk geometry.
Their default values are taken from the disk label.
Changing these defaults is useful only when using
.Nm
to build a file system whose raw image will eventually be used on a
different type of disk than the one on which it is initially created
(for example on a write-once disk).
Note that changing any of these values from their defaults will make
it impossible for
.Xr fsck 8
to find the alternate superblocks if the standard superblock is lost.
.Bl -tag -width indent
.It Fl S Ar sector-size
The size of a sector in bytes (almost never anything but 512).
.El
.Sh EXAMPLES
.Dl newfs /dev/ad3s1a
.Pp
Creates a new ufs file system on
.Pa ad3s1a .
The
.Nm
utility will use a block size of 16384 bytes, a fragment size of 2048 bytes
and the largest possible number of blocks per cylinders group.
These values tend to produce better performance for most applications
than the historical defaults
(8192 byte block size and 1024 byte fragment size).
This large fragment size may lead to much wasted space
on file systems that contain many small files.
.Sh SEE ALSO
.Xr fdformat 1 ,
.Xr geom 4 ,
.Xr disktab 5 ,
.Xr fs 5 ,
.Xr bsdlabel 8 ,
.Xr camcontrol 8 ,
.Xr dump 8 ,
.Xr dumpfs 8 ,
.Xr fsck 8 ,
.Xr gjournal 8 ,
.Xr mount 8 ,
.Xr tunefs 8 ,
.Xr gvinum 8
.Rs
.%A M. McKusick
.%A W. Joy
.%A S. Leffler
.%A R. Fabry
.%T A Fast File System for UNIX
.%J ACM Transactions on Computer Systems 2
.%V 3
.%P pp 181-197
.%D August 1984
.%O (reprinted in the BSD System Manager's Manual)
.Re
.Sh HISTORY
The
.Nm
utility appeared in
.Bx 4.2 .
Index: stable/8/sbin/newfs/newfs.c
===================================================================
--- stable/8/sbin/newfs/newfs.c (revision 218079)
+++ stable/8/sbin/newfs/newfs.c (revision 218080)
@@ -1,483 +1,488 @@
/*
* Copyright (c) 2002 Networks Associates Technology, Inc.
* All rights reserved.
*
* This software was developed for the FreeBSD Project by Marshall
* Kirk McKusick and Network Associates Laboratories, the Security
* Research Division of Network Associates, Inc. under DARPA/SPAWAR
* contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA CHATS
* research program.
*
* Copyright (c) 1983, 1989, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#if 0
#ifndef lint
static const 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
static char sccsid[] = "@(#)newfs.c 8.13 (Berkeley) 5/1/95";
#endif /* not lint */
#endif
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
/*
* newfs: friendly front end to mkfs
*/
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/disk.h>
#include <sys/disklabel.h>
#include <sys/file.h>
#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 <err.h>
#include <errno.h>
#include <inttypes.h>
#include <paths.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <unistd.h>
#include "newfs.h"
int Eflag; /* Erase previous disk contents */
int Lflag; /* add a volume label */
int Nflag; /* run without writing file system */
int Oflag = 2; /* file system format (1 => UFS1, 2 => UFS2) */
int Rflag; /* regression test */
int Uflag; /* enable soft updates for file system */
int Xflag = 0; /* exit in middle of newfs for testing */
int Jflag; /* enable gjournal for file system */
int lflag; /* enable multilabel for file system */
int nflag; /* do not create .snap directory */
+int tflag; /* enable TRIM */
intmax_t fssize; /* file system size */
int sectorsize; /* bytes/sector */
int realsectorsize; /* bytes/sector in hardware */
int fsize = 0; /* fragment size */
int bsize = 0; /* block size */
int maxbsize = 0; /* maximum clustering */
int maxblkspercg = MAXBLKSPERCG; /* maximum blocks per cylinder group */
int minfree = MINFREE; /* free space threshold */
int opt = DEFAULTOPT; /* optimization preference (space or time) */
int density; /* number of bytes per inode */
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 */
int avgfilesperdir = AFPDIR;/* expected number of files per directory */
u_char *volumelabel = NULL; /* volume label for filesystem */
struct uufsd disk; /* libufs disk structure */
static char device[MAXPATHLEN];
static u_char bootarea[BBSIZE];
static int is_file; /* work on a file, not a device */
static char *dkname;
static char *disktype;
static int unlabeled;
static void getfssize(intmax_t *, const char *p, intmax_t, intmax_t);
static struct disklabel *getdisklabel(char *s);
static void rewritelabel(char *s, struct disklabel *lp);
static void usage(void);
ufs2_daddr_t part_ofs; /* partition offset in blocks, used with files */
int
main(int argc, char *argv[])
{
struct partition *pp;
struct disklabel *lp;
struct partition oldpartition;
struct stat st;
char *cp, *special;
intmax_t reserved;
int ch, i;
off_t mediasize;
char part_name; /* partition name, default to full disk */
part_name = 'c';
reserved = 0;
while ((ch = getopt(argc, argv,
- "EJL:NO:RS:T:UXa:b:c:d:e:f:g:h:i:lm:no:p:r:s:")) != -1)
+ "EJL:NO:RS:T:UXa:b:c:d:e:f:g:h:i:lm:no:p:r:s:t")) != -1)
switch (ch) {
case 'E':
Eflag = 1;
break;
case 'J':
Jflag = 1;
break;
case 'L':
volumelabel = optarg;
i = -1;
while (isalnum(volumelabel[++i]));
if (volumelabel[i] != '\0') {
errx(1, "bad volume label. Valid characters are alphanumerics.");
}
if (strlen(volumelabel) >= MAXVOLLEN) {
errx(1, "bad volume label. Length is longer than %d.",
MAXVOLLEN);
}
Lflag = 1;
break;
case 'N':
Nflag = 1;
break;
case 'O':
if ((Oflag = atoi(optarg)) < 1 || Oflag > 2)
errx(1, "%s: bad file system format value",
optarg);
break;
case 'R':
Rflag = 1;
break;
case 'S':
if ((sectorsize = atoi(optarg)) <= 0)
errx(1, "%s: bad sector size", optarg);
break;
case 'T':
disktype = optarg;
break;
case 'U':
Uflag = 1;
break;
case 'X':
Xflag++;
break;
case 'a':
if ((maxcontig = atoi(optarg)) <= 0)
errx(1, "%s: bad maximum contiguous blocks",
optarg);
break;
case 'b':
if ((bsize = atoi(optarg)) < MINBSIZE)
errx(1, "%s: block size too small, min is %d",
optarg, MINBSIZE);
if (bsize > MAXBSIZE)
errx(1, "%s: block size too large, max is %d",
optarg, MAXBSIZE);
break;
case 'c':
if ((maxblkspercg = atoi(optarg)) <= 0)
errx(1, "%s: bad blocks per cylinder group",
optarg);
break;
case 'd':
if ((maxbsize = atoi(optarg)) < MINBSIZE)
errx(1, "%s: bad extent block size", optarg);
break;
case 'e':
if ((maxbpg = atoi(optarg)) <= 0)
errx(1, "%s: bad blocks per file in a cylinder group",
optarg);
break;
case 'f':
if ((fsize = atoi(optarg)) <= 0)
errx(1, "%s: bad fragment size", optarg);
break;
case 'g':
if ((avgfilesize = atoi(optarg)) <= 0)
errx(1, "%s: bad average file size", optarg);
break;
case 'h':
if ((avgfilesperdir = atoi(optarg)) <= 0)
errx(1, "%s: bad average files per dir", optarg);
break;
case 'i':
if ((density = atoi(optarg)) <= 0)
errx(1, "%s: bad bytes per inode", optarg);
break;
case 'l':
lflag = 1;
break;
case 'm':
if ((minfree = atoi(optarg)) < 0 || minfree > 99)
errx(1, "%s: bad free space %%", optarg);
break;
case 'n':
nflag = 1;
break;
case 'o':
if (strcmp(optarg, "space") == 0)
opt = FS_OPTSPACE;
else if (strcmp(optarg, "time") == 0)
opt = FS_OPTTIME;
else
errx(1,
"%s: unknown optimization preference: use `space' or `time'",
optarg);
break;
case 'r':
errno = 0;
reserved = strtoimax(optarg, &cp, 0);
if (errno != 0 || cp == optarg ||
*cp != '\0' || reserved < 0)
errx(1, "%s: bad reserved size", optarg);
break;
case 'p':
is_file = 1;
part_name = optarg[0];
break;
case 's':
errno = 0;
fssize = strtoimax(optarg, &cp, 0);
if (errno != 0 || cp == optarg ||
*cp != '\0' || fssize < 0)
errx(1, "%s: bad file system size", optarg);
break;
+ case 't':
+ tflag = 1;
+ break;
case '?':
default:
usage();
}
argc -= optind;
argv += optind;
if (argc != 1)
usage();
special = argv[0];
if (!special[0])
err(1, "empty file/special name");
cp = strrchr(special, '/');
if (cp == 0) {
/*
* No path prefix; try prefixing _PATH_DEV.
*/
snprintf(device, sizeof(device), "%s%s", _PATH_DEV, special);
special = device;
}
if (is_file) {
/* bypass ufs_disk_fillout_blank */
bzero( &disk, sizeof(disk));
disk.d_bsize = 1;
disk.d_name = special;
disk.d_fd = open(special, O_RDONLY);
if (disk.d_fd < 0 ||
(!Nflag && ufs_disk_write(&disk) == -1))
errx(1, "%s: ", special);
} else if (ufs_disk_fillout_blank(&disk, special) == -1 ||
(!Nflag && ufs_disk_write(&disk) == -1)) {
if (disk.d_error != NULL)
errx(1, "%s: %s", special, disk.d_error);
else
err(1, "%s", special);
}
if (fstat(disk.d_fd, &st) < 0)
err(1, "%s", special);
if ((st.st_mode & S_IFMT) != S_IFCHR) {
warn("%s: not a character-special device", special);
is_file = 1; /* assume it is a file */
dkname = special;
if (sectorsize == 0)
sectorsize = 512;
mediasize = st.st_size;
/* set fssize from the partition */
} else {
if (sectorsize == 0)
if (ioctl(disk.d_fd, DIOCGSECTORSIZE, §orsize) == -1)
sectorsize = 0; /* back out on error for safety */
if (sectorsize && ioctl(disk.d_fd, DIOCGMEDIASIZE, &mediasize) != -1)
getfssize(&fssize, special, mediasize / sectorsize, reserved);
}
pp = NULL;
lp = getdisklabel(special);
if (lp != NULL) {
if (!is_file) /* already set for files */
part_name = special[strlen(special) - 1];
if ((part_name < 'a' || part_name - 'a' >= MAXPARTITIONS) &&
!isdigit(part_name))
errx(1, "%s: can't figure out file system partition",
special);
cp = &part_name;
if (isdigit(*cp))
pp = &lp->d_partitions[RAW_PART];
else
pp = &lp->d_partitions[*cp - 'a'];
oldpartition = *pp;
if (pp->p_size == 0)
errx(1, "%s: `%c' partition is unavailable",
special, *cp);
if (pp->p_fstype == FS_BOOT)
errx(1, "%s: `%c' partition overlaps boot program",
special, *cp);
getfssize(&fssize, special, pp->p_size, reserved);
if (sectorsize == 0)
sectorsize = lp->d_secsize;
if (fsize == 0)
fsize = pp->p_fsize;
if (bsize == 0)
bsize = pp->p_frag * pp->p_fsize;
if (is_file)
part_ofs = pp->p_offset;
}
if (sectorsize <= 0)
errx(1, "%s: no default sector size", special);
if (fsize <= 0)
fsize = MAX(DFL_FRAGSIZE, sectorsize);
if (bsize <= 0)
bsize = MIN(DFL_BLKSIZE, 8 * fsize);
if (minfree < MINFREE && opt != FS_OPTSPACE) {
fprintf(stderr, "Warning: changing optimization to space ");
fprintf(stderr, "because minfree is less than %d%%\n", MINFREE);
opt = FS_OPTSPACE;
}
realsectorsize = sectorsize;
if (sectorsize != DEV_BSIZE) { /* XXX */
int secperblk = sectorsize / DEV_BSIZE;
sectorsize = DEV_BSIZE;
fssize *= secperblk;
if (pp != NULL)
pp->p_size *= secperblk;
}
mkfs(pp, special);
if (!unlabeled) {
if (realsectorsize != DEV_BSIZE)
pp->p_size /= realsectorsize / DEV_BSIZE;
if (!Nflag && bcmp(pp, &oldpartition, sizeof(oldpartition)))
rewritelabel(special, lp);
}
ufs_disk_close(&disk);
exit(0);
}
void
getfssize(intmax_t *fsz, const char *s, intmax_t disksize, intmax_t reserved)
{
intmax_t available;
available = disksize - reserved;
if (available <= 0)
errx(1, "%s: reserved not less than device size %jd",
s, disksize);
if (*fsz == 0)
*fsz = available;
else if (*fsz > available)
errx(1, "%s: maximum file system size is %jd",
s, available);
}
struct disklabel *
getdisklabel(char *s)
{
static struct disklabel lab;
struct disklabel *lp;
if (is_file) {
if (read(disk.d_fd, bootarea, BBSIZE) != BBSIZE)
err(4, "cannot read bootarea");
if (bsd_disklabel_le_dec(
bootarea + (0 /* labeloffset */ +
1 /* labelsoffset */ * sectorsize),
&lab, MAXPARTITIONS))
errx(1, "no valid label found");
lp = &lab;
return &lab;
}
if (ioctl(disk.d_fd, DIOCGDINFO, (char *)&lab) != -1)
return (&lab);
unlabeled++;
if (disktype) {
lp = getdiskbyname(disktype);
if (lp != NULL)
return (lp);
}
return (NULL);
}
void
rewritelabel(char *s, struct disklabel *lp)
{
if (unlabeled)
return;
lp->d_checksum = 0;
lp->d_checksum = dkcksum(lp);
if (is_file) {
bsd_disklabel_le_enc(bootarea + 0 /* labeloffset */ +
1 /* labelsoffset */ * sectorsize, lp);
lseek(disk.d_fd, 0, SEEK_SET);
if (write(disk.d_fd, bootarea, BBSIZE) != BBSIZE)
errx(1, "cannot write label");
return;
}
if (ioctl(disk.d_fd, DIOCWDINFO, (char *)lp) == -1)
warn("ioctl (WDINFO): %s: can't rewrite disk label", s);
}
static void
usage()
{
fprintf(stderr,
"usage: %s [ -fsoptions ] special-device%s\n",
getprogname(),
" [device-type]");
fprintf(stderr, "where fsoptions are:\n");
fprintf(stderr, "\t-E Erase previous disk content\n");
fprintf(stderr, "\t-J Enable journaling via gjournal\n");
fprintf(stderr, "\t-L volume label to add to superblock\n");
fprintf(stderr,
"\t-N do not create file system, just print out parameters\n");
fprintf(stderr, "\t-O file system format: 1 => UFS1, 2 => UFS2\n");
fprintf(stderr, "\t-R regression test, suppress random factors\n");
fprintf(stderr, "\t-S sector size\n");
fprintf(stderr, "\t-T disktype\n");
fprintf(stderr, "\t-U enable soft updates\n");
fprintf(stderr, "\t-a maximum contiguous blocks\n");
fprintf(stderr, "\t-b block size\n");
fprintf(stderr, "\t-c blocks per cylinders group\n");
fprintf(stderr, "\t-d maximum extent size\n");
fprintf(stderr, "\t-e maximum blocks per file in a cylinder group\n");
fprintf(stderr, "\t-f frag size\n");
fprintf(stderr, "\t-g average file size\n");
fprintf(stderr, "\t-h average files per directory\n");
fprintf(stderr, "\t-i number of bytes per inode\n");
fprintf(stderr, "\t-l enable multilabel MAC\n");
fprintf(stderr, "\t-n do not create .snap directory\n");
fprintf(stderr, "\t-m minimum free space %%\n");
fprintf(stderr, "\t-o optimization preference (`space' or `time')\n");
fprintf(stderr, "\t-p partition name (a..h)\n");
fprintf(stderr, "\t-r reserved sectors at the end of device\n");
fprintf(stderr, "\t-s file system size (sectors)\n");
+ fprintf(stderr, "\t-t enable TRIM\n");
exit(1);
}
Index: stable/8/sbin/newfs/newfs.h
===================================================================
--- stable/8/sbin/newfs/newfs.h (revision 218079)
+++ stable/8/sbin/newfs/newfs.h (revision 218080)
@@ -1,121 +1,122 @@
/*
* Copyright (c) 2002 Networks Associates Technology, Inc.
* All rights reserved.
*
* This software was developed for the FreeBSD Project by Marshall
* Kirk McKusick and Network Associates Laboratories, the Security
* Research Division of Network Associates, Inc. under DARPA/SPAWAR
* contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA CHATS
* research program.
*
* Copyright (c) 1980, 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <libufs.h>
/*
* The following two constants set the default block and fragment sizes.
* Both constants must be a power of 2 and meet the following constraints:
* MINBSIZE <= DESBLKSIZE <= MAXBSIZE
* sectorsize <= DESFRAGSIZE <= DESBLKSIZE
* DESBLKSIZE / DESFRAGSIZE <= 8
*/
#define DFL_FRAGSIZE 2048
#define DFL_BLKSIZE 16384
/*
* Cylinder groups may have up to MAXBLKSPERCG blocks. The actual
* number used depends upon how much information can be stored
* in a cylinder group map which must fit in a single file system
* block. The default is to use as many as possible blocks per group.
*/
#define MAXBLKSPERCG 0x7fffffff /* desired fs_fpg ("infinity") */
/*
* 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(ufs2_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.
*/
#define NFPI 4
/*
* variables set up by front end.
*/
extern int Eflag; /* Erase previous disk contents */
extern int Lflag; /* add a volume label */
extern int Nflag; /* run mkfs without writing file system */
extern int Oflag; /* build UFS1 format file system */
extern int Rflag; /* regression test */
extern int Uflag; /* enable soft updates for file system */
extern int Xflag; /* exit in middle of newfs for testing */
extern int Jflag; /* enable gjournal for file system */
extern int lflag; /* enable multilabel MAC for file system */
extern int nflag; /* do not create .snap directory */
+extern int tflag; /* enable TRIM */
extern intmax_t fssize; /* file system size */
extern int sectorsize; /* bytes/sector */
extern int realsectorsize; /* bytes/sector in hardware*/
extern int fsize; /* fragment size */
extern int bsize; /* block size */
extern int maxbsize; /* maximum clustering */
extern int maxblkspercg; /* maximum blocks per cylinder group */
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 maxbpg; /* maximum blocks per file in a cyl group */
extern int avgfilesize; /* expected average file size */
extern int avgfilesperdir; /* expected number of files per directory */
extern u_char *volumelabel; /* volume label for filesystem */
extern struct uufsd disk; /* libufs disk structure */
/*
* To override a limitation in libufs, export the offset (in sectors) of the
* partition on the underlying media (file or disk). The value is used as
* an offset for all accesses to the media through bread(), which is only
* invoked directly in this program.
* For bwrite() we need a different approach, namely override the library
* version with one defined here. This is because bwrite() is called also
* by the library function sbwrite() which we cannot intercept nor want to
* rewrite. As a consequence, the internal version of bwrite() adds the
* partition offset itself when calling the underlying function, pwrite().
*
* XXX This info really ought to go into the struct uufsd, at which point
* we can remove the above hack.
*/
extern ufs2_daddr_t part_ofs; /* partition offset in blocks */
void mkfs (struct partition *, char *);
Index: stable/8/sbin/newfs
===================================================================
--- stable/8/sbin/newfs (revision 218079)
+++ stable/8/sbin/newfs (revision 218080)
Property changes on: stable/8/sbin/newfs
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/newfs:r216798
Index: stable/8/sbin/newfs_msdos
===================================================================
--- stable/8/sbin/newfs_msdos (revision 218079)
+++ stable/8/sbin/newfs_msdos (revision 218080)
Property changes on: stable/8/sbin/newfs_msdos
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/newfs_msdos:r216798
Index: stable/8/sbin/ping6
===================================================================
--- stable/8/sbin/ping6 (revision 218079)
+++ stable/8/sbin/ping6 (revision 218080)
Property changes on: stable/8/sbin/ping6
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/ping6:r216798
Index: stable/8/sbin/reboot
===================================================================
--- stable/8/sbin/reboot (revision 218079)
+++ stable/8/sbin/reboot (revision 218080)
Property changes on: stable/8/sbin/reboot
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/reboot:r216798
Index: stable/8/sbin/restore
===================================================================
--- stable/8/sbin/restore (revision 218079)
+++ stable/8/sbin/restore (revision 218080)
Property changes on: stable/8/sbin/restore
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/restore:r216798
Index: stable/8/sbin/route
===================================================================
--- stable/8/sbin/route (revision 218079)
+++ stable/8/sbin/route (revision 218080)
Property changes on: stable/8/sbin/route
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/route:r216798
Index: stable/8/sbin/routed
===================================================================
--- stable/8/sbin/routed (revision 218079)
+++ stable/8/sbin/routed (revision 218080)
Property changes on: stable/8/sbin/routed
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/routed:r216798
Index: stable/8/sbin/setkey
===================================================================
--- stable/8/sbin/setkey (revision 218079)
+++ stable/8/sbin/setkey (revision 218080)
Property changes on: stable/8/sbin/setkey
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/setkey:r216798
Index: stable/8/sbin/spppcontrol
===================================================================
--- stable/8/sbin/spppcontrol (revision 218079)
+++ stable/8/sbin/spppcontrol (revision 218080)
Property changes on: stable/8/sbin/spppcontrol
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/spppcontrol:r216798
Index: stable/8/sbin/sysctl
===================================================================
--- stable/8/sbin/sysctl (revision 218079)
+++ stable/8/sbin/sysctl (revision 218080)
Property changes on: stable/8/sbin/sysctl
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/sysctl:r216798
Index: stable/8/sbin/tunefs/tunefs.8
===================================================================
--- stable/8/sbin/tunefs/tunefs.8 (revision 218079)
+++ stable/8/sbin/tunefs/tunefs.8 (revision 218080)
@@ -1,177 +1,186 @@
.\" Copyright (c) 1983, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)tunefs.8 8.2 (Berkeley) 12/11/93
.\" $FreeBSD$
.\"
-.Dd August 13, 2007
+.Dd December 9, 2010
.Dt TUNEFS 8
.Os
.Sh NAME
.Nm tunefs
.Nd tune up an existing file system
.Sh SYNOPSIS
.Nm
.Op Fl A
.Op Fl a Cm enable | disable
.Op Fl e Ar maxbpg
.Op Fl f Ar avgfilesize
.Op Fl J Cm enable | disable
.Op Fl L Ar volname
.Op Fl l Cm enable | disable
.Op Fl m Ar minfree
.Op Fl N Cm enable | disable
.Op Fl n Cm enable | disable
.Op Fl o Cm space | time
.Op Fl p
.Op Fl s Ar avgfpdir
+.Op Fl t Cm enable | disable
.Ar special | filesystem
.Sh DESCRIPTION
The
.Nm
utility is designed to change the dynamic parameters of a file system
which affect the layout policies.
The
.Nm
utility cannot be run on an active file system.
To change an active file system,
it must be downgraded to read-only or unmounted.
.Pp
The parameters which are to be changed are indicated by the flags
given below:
.Bl -tag -width indent
.It Fl A
The file system has several backups of the super-block.
Specifying
this option will cause all backups to be modified as well as the
primary super-block.
This is potentially dangerous - use with caution.
.It Fl a Cm enable | disable
Turn on/off the administrative POSIX.1e ACL enable flag.
.It Fl e Ar maxbpg
Indicate 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.
Typically this value is set to about one quarter of the total blocks
in a cylinder group.
The intent is to prevent any single file from using up all the
blocks in a single cylinder group,
thus degrading access times for all files subsequently allocated
in that cylinder group.
The effect of this limit is to cause big files to do long seeks
more frequently than if they were allowed to allocate all the blocks
in a cylinder group before seeking elsewhere.
For file systems with exclusively large files,
this parameter should be set higher.
.It Fl f Ar avgfilesize
Specify the expected average file size.
.It Fl J Cm enable | disable
Turn on/off gjournal flag.
.It Fl L Ar volname
Add/modify an optional file system volume label.
.It Fl l Cm enable | disable
Turn on/off MAC multilabel flag.
.It Fl m Ar minfree
Specify the percentage of space held back
from normal users; the minimum free space threshold.
The default value used is 8%.
Note that lowering the threshold can adversely affect performance:
.Bl -bullet
.It
Settings of 5% and less force space optimization to
always be used which will greatly increase the overhead for file
writes.
.It
The file system's ability to avoid fragmentation will be reduced
when the total free space, including the reserve, drops below 15%.
As free space approaches zero, throughput can degrade by up to a
factor of three over the performance obtained at a 10% threshold.
.El
.Pp
If the value is raised above the current usage level,
users will be unable to allocate files until enough files have
been deleted to get under the higher threshold.
.It Fl N Cm enable | disable
Turn on/off the administrative NFSv4 ACL enable flag.
.It Fl n Cm enable | disable
Turn on/off soft updates.
.It Fl o Cm space | time
The file system can either try to minimize the time spent
allocating blocks, or it can attempt to minimize the space
fragmentation on the disk.
Optimization for space has much
higher overhead for file writes.
The kernel normally changes the preference automatically as
the percent fragmentation changes on the file system.
.It Fl p
Show a summary of what the current tunable settings
are on the selected file system.
More detailed information can be
obtained from the
.Xr dumpfs 8
utility.
.It Fl s Ar avgfpdir
Specify the expected number of files per directory.
+.It Fl t Cm enable | disable
+Turn on/off the TRIM enable flag.
+If enabled, and if the underlying device supports the BIO_DELETE
+command, the file system will send a delete request to the underlying
+device for each freed block.
+The trim enable flag is typically set when the underlying device
+uses flash-memory as the device can use the delete command to
+pre-zero or at least avoid copying blocks that have been deleted.
.El
.Pp
At least one of the above flags is required.
.Sh FILES
.Bl -tag -width ".Pa /etc/fstab"
.It Pa /etc/fstab
read this to determine the device file for a
specified mount point.
.El
.Sh SEE ALSO
.Xr fs 5 ,
.Xr dumpfs 8 ,
.Xr gjournal 8 ,
.Xr newfs 8
.Rs
.%A M. McKusick
.%A W. Joy
.%A S. Leffler
.%A R. Fabry
.%T "A Fast File System for UNIX"
.%J "ACM Transactions on Computer Systems 2"
.%N 3
.%P pp 181-197
.%D August 1984
.%O "(reprinted in the BSD System Manager's Manual, SMM:5)"
.Re
.Sh HISTORY
The
.Nm
utility appeared in
.Bx 4.2 .
.Sh BUGS
This utility should work on active file systems.
To change the root file system, the system must be rebooted
after the file system is tuned.
.\" Take this out and a Unix Daemon will dog your steps from now until
.\" the time_t's wrap around.
.Pp
You can tune a file system, but you cannot tune a fish.
Index: stable/8/sbin/tunefs/tunefs.c
===================================================================
--- stable/8/sbin/tunefs/tunefs.c (revision 218079)
+++ stable/8/sbin/tunefs/tunefs.c (revision 218080)
@@ -1,500 +1,535 @@
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#if 0
#ifndef lint
static const char copyright[] =
"@(#) Copyright (c) 1983, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)tunefs.c 8.2 (Berkeley) 4/19/94";
#endif /* not lint */
#endif
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
/*
* tunefs: change layout parameters to an existing file system.
*/
#include <sys/param.h>
#include <sys/mount.h>
#include <sys/disklabel.h>
#include <sys/stat.h>
#include <ufs/ufs/ufsmount.h>
#include <ufs/ufs/dinode.h>
#include <ufs/ffs/fs.h>
#include <ctype.h>
#include <err.h>
#include <fcntl.h>
#include <fstab.h>
#include <libufs.h>
#include <paths.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
/* the optimization warning string template */
#define OPTWARN "should optimize for %s with minfree %s %d%%"
struct uufsd disk;
#define sblock disk.d_fs
void usage(void);
void printfs(void);
int
main(int argc, char *argv[])
{
char *avalue, *Jvalue, *Lvalue, *lvalue, *Nvalue, *nvalue;
+ char *tvalue;
const char *special, *on;
const char *name;
int active;
int Aflag, aflag, eflag, evalue, fflag, fvalue, Jflag, Lflag, lflag;
int mflag, mvalue, Nflag, nflag, oflag, ovalue, pflag, sflag, svalue;
+ int tflag;
int ch, found_arg, i;
const char *chg[2];
struct ufs_args args;
struct statfs stfs;
if (argc < 3)
usage();
Aflag = aflag = eflag = fflag = Jflag = Lflag = lflag = mflag = 0;
- Nflag = nflag = oflag = pflag = sflag = 0;
+ Nflag = nflag = oflag = pflag = sflag = tflag = 0;
avalue = Jvalue = Lvalue = lvalue = Nvalue = nvalue = NULL;
evalue = fvalue = mvalue = ovalue = svalue = 0;
active = 0;
found_arg = 0; /* At least one arg is required. */
- while ((ch = getopt(argc, argv, "Aa:e:f:J:L:l:m:N:n:o:ps:")) != -1)
+ while ((ch = getopt(argc, argv, "Aa:e:f:J:L:l:m:N:n:o:ps:t:")) != -1)
switch (ch) {
case 'A':
found_arg = 1;
Aflag++;
break;
case 'a':
found_arg = 1;
name = "POSIX.1e ACLs";
avalue = optarg;
if (strcmp(avalue, "enable") &&
strcmp(avalue, "disable")) {
errx(10, "bad %s (options are %s)",
name, "`enable' or `disable'");
}
aflag = 1;
break;
case 'e':
found_arg = 1;
name = "maximum blocks per file in a cylinder group";
evalue = atoi(optarg);
if (evalue < 1)
errx(10, "%s must be >= 1 (was %s)",
name, optarg);
eflag = 1;
break;
case 'f':
found_arg = 1;
name = "average file size";
fvalue = atoi(optarg);
if (fvalue < 1)
errx(10, "%s must be >= 1 (was %s)",
name, optarg);
fflag = 1;
break;
case 'J':
found_arg = 1;
name = "gjournaled file system";
Jvalue = optarg;
if (strcmp(Jvalue, "enable") &&
strcmp(Jvalue, "disable")) {
errx(10, "bad %s (options are %s)",
name, "`enable' or `disable'");
}
Jflag = 1;
break;
case 'L':
found_arg = 1;
name = "volume label";
Lvalue = optarg;
i = -1;
while (isalnum(Lvalue[++i]));
if (Lvalue[i] != '\0') {
errx(10,
"bad %s. Valid characters are alphanumerics.",
name);
}
if (strlen(Lvalue) >= MAXVOLLEN) {
errx(10, "bad %s. Length is longer than %d.",
name, MAXVOLLEN - 1);
}
Lflag = 1;
break;
case 'l':
found_arg = 1;
name = "multilabel MAC file system";
lvalue = optarg;
if (strcmp(lvalue, "enable") &&
strcmp(lvalue, "disable")) {
errx(10, "bad %s (options are %s)",
name, "`enable' or `disable'");
}
lflag = 1;
break;
case 'm':
found_arg = 1;
name = "minimum percentage of free space";
mvalue = atoi(optarg);
if (mvalue < 0 || mvalue > 99)
errx(10, "bad %s (%s)", name, optarg);
mflag = 1;
break;
case 'N':
found_arg = 1;
name = "NFSv4 ACLs";
Nvalue = optarg;
if (strcmp(Nvalue, "enable") &&
strcmp(Nvalue, "disable")) {
errx(10, "bad %s (options are %s)",
name, "`enable' or `disable'");
}
Nflag = 1;
break;
case 'n':
found_arg = 1;
name = "soft updates";
nvalue = optarg;
if (strcmp(nvalue, "enable") != 0 &&
strcmp(nvalue, "disable") != 0) {
errx(10, "bad %s (options are %s)",
name, "`enable' or `disable'");
}
nflag = 1;
break;
case 'o':
found_arg = 1;
name = "optimization preference";
if (strcmp(optarg, "space") == 0)
ovalue = FS_OPTSPACE;
else if (strcmp(optarg, "time") == 0)
ovalue = FS_OPTTIME;
else
errx(10,
"bad %s (options are `space' or `time')",
name);
oflag = 1;
break;
case 'p':
found_arg = 1;
pflag = 1;
break;
case 's':
found_arg = 1;
name = "expected number of files per directory";
svalue = atoi(optarg);
if (svalue < 1)
errx(10, "%s must be >= 1 (was %s)",
name, optarg);
sflag = 1;
break;
+ case 't':
+ found_arg = 1;
+ name = "trim";
+ tvalue = optarg;
+ if (strcmp(tvalue, "enable") != 0 &&
+ strcmp(tvalue, "disable") != 0) {
+ errx(10, "bad %s (options are %s)",
+ name, "`enable' or `disable'");
+ }
+ tflag = 1;
+ break;
+
default:
usage();
}
argc -= optind;
argv += optind;
if (found_arg == 0 || argc != 1)
usage();
on = special = argv[0];
if (ufs_disk_fillout(&disk, special) == -1)
goto err;
if (disk.d_name != special) {
special = disk.d_name;
if (statfs(special, &stfs) == 0 &&
strcmp(special, stfs.f_mntonname) == 0)
active = 1;
}
if (pflag) {
printfs();
exit(0);
}
if (Lflag) {
name = "volume label";
strlcpy(sblock.fs_volname, Lvalue, MAXVOLLEN);
}
if (aflag) {
name = "POSIX.1e ACLs";
if (strcmp(avalue, "enable") == 0) {
if (sblock.fs_flags & FS_ACLS) {
warnx("%s remains unchanged as enabled", name);
} else if (sblock.fs_flags & FS_NFS4ACLS) {
warnx("%s and NFSv4 ACLs are mutually "
"exclusive", name);
} else {
sblock.fs_flags |= FS_ACLS;
warnx("%s set", name);
}
} else if (strcmp(avalue, "disable") == 0) {
if ((~sblock.fs_flags & FS_ACLS) ==
FS_ACLS) {
warnx("%s remains unchanged as disabled",
name);
} else {
sblock.fs_flags &= ~FS_ACLS;
warnx("%s cleared", name);
}
}
}
if (eflag) {
name = "maximum blocks per file in a cylinder group";
if (sblock.fs_maxbpg == evalue)
warnx("%s remains unchanged as %d", name, evalue);
else {
warnx("%s changes from %d to %d",
name, sblock.fs_maxbpg, evalue);
sblock.fs_maxbpg = evalue;
}
}
if (fflag) {
name = "average file size";
if (sblock.fs_avgfilesize == (unsigned)fvalue) {
warnx("%s remains unchanged as %d", name, fvalue);
}
else {
warnx("%s changes from %d to %d",
name, sblock.fs_avgfilesize, fvalue);
sblock.fs_avgfilesize = fvalue;
}
}
if (Jflag) {
name = "gjournal";
if (strcmp(Jvalue, "enable") == 0) {
if (sblock.fs_flags & FS_GJOURNAL) {
warnx("%s remains unchanged as enabled", name);
} else {
sblock.fs_flags |= FS_GJOURNAL;
warnx("%s set", name);
}
} else if (strcmp(Jvalue, "disable") == 0) {
if ((~sblock.fs_flags & FS_GJOURNAL) ==
FS_GJOURNAL) {
warnx("%s remains unchanged as disabled",
name);
} else {
sblock.fs_flags &= ~FS_GJOURNAL;
warnx("%s cleared", name);
}
}
}
if (lflag) {
name = "multilabel";
if (strcmp(lvalue, "enable") == 0) {
if (sblock.fs_flags & FS_MULTILABEL) {
warnx("%s remains unchanged as enabled", name);
} else {
sblock.fs_flags |= FS_MULTILABEL;
warnx("%s set", name);
}
} else if (strcmp(lvalue, "disable") == 0) {
if ((~sblock.fs_flags & FS_MULTILABEL) ==
FS_MULTILABEL) {
warnx("%s remains unchanged as disabled",
name);
} else {
sblock.fs_flags &= ~FS_MULTILABEL;
warnx("%s cleared", name);
}
}
}
if (mflag) {
name = "minimum percentage of free space";
if (sblock.fs_minfree == mvalue)
warnx("%s remains unchanged as %d%%", name, mvalue);
else {
warnx("%s changes from %d%% to %d%%",
name, sblock.fs_minfree, mvalue);
sblock.fs_minfree = mvalue;
if (mvalue >= MINFREE && sblock.fs_optim == FS_OPTSPACE)
warnx(OPTWARN, "time", ">=", MINFREE);
if (mvalue < MINFREE && sblock.fs_optim == FS_OPTTIME)
warnx(OPTWARN, "space", "<", MINFREE);
}
}
if (Nflag) {
name = "NFSv4 ACLs";
if (strcmp(Nvalue, "enable") == 0) {
if (sblock.fs_flags & FS_NFS4ACLS) {
warnx("%s remains unchanged as enabled", name);
} else if (sblock.fs_flags & FS_ACLS) {
warnx("%s and POSIX.1e ACLs are mutually "
"exclusive", name);
} else {
sblock.fs_flags |= FS_NFS4ACLS;
warnx("%s set", name);
}
} else if (strcmp(Nvalue, "disable") == 0) {
if ((~sblock.fs_flags & FS_NFS4ACLS) ==
FS_NFS4ACLS) {
warnx("%s remains unchanged as disabled",
name);
} else {
sblock.fs_flags &= ~FS_NFS4ACLS;
warnx("%s cleared", name);
}
}
}
if (nflag) {
name = "soft updates";
if (strcmp(nvalue, "enable") == 0) {
if (sblock.fs_flags & FS_DOSOFTDEP)
warnx("%s remains unchanged as enabled", name);
else if (sblock.fs_clean == 0) {
warnx("%s cannot be enabled until fsck is run",
name);
} else {
sblock.fs_flags |= FS_DOSOFTDEP;
warnx("%s set", name);
}
} else if (strcmp(nvalue, "disable") == 0) {
if ((~sblock.fs_flags & FS_DOSOFTDEP) == FS_DOSOFTDEP)
warnx("%s remains unchanged as disabled", name);
else {
sblock.fs_flags &= ~FS_DOSOFTDEP;
warnx("%s cleared", name);
}
}
}
if (oflag) {
name = "optimization preference";
chg[FS_OPTSPACE] = "space";
chg[FS_OPTTIME] = "time";
if (sblock.fs_optim == ovalue)
warnx("%s remains unchanged as %s", name, chg[ovalue]);
else {
warnx("%s changes from %s to %s",
name, chg[sblock.fs_optim], chg[ovalue]);
sblock.fs_optim = ovalue;
if (sblock.fs_minfree >= MINFREE &&
ovalue == FS_OPTSPACE)
warnx(OPTWARN, "time", ">=", MINFREE);
if (sblock.fs_minfree < MINFREE && ovalue == FS_OPTTIME)
warnx(OPTWARN, "space", "<", MINFREE);
}
}
if (sflag) {
name = "expected number of files per directory";
if (sblock.fs_avgfpdir == (unsigned)svalue) {
warnx("%s remains unchanged as %d", name, svalue);
}
else {
warnx("%s changes from %d to %d",
name, sblock.fs_avgfpdir, svalue);
sblock.fs_avgfpdir = svalue;
}
}
+ if (tflag) {
+ name = "issue TRIM to the disk";
+ if (strcmp(tvalue, "enable") == 0) {
+ if (sblock.fs_flags & FS_TRIM)
+ warnx("%s remains unchanged as enabled", name);
+ else {
+ sblock.fs_flags |= FS_TRIM;
+ warnx("%s set", name);
+ }
+ } else if (strcmp(tvalue, "disable") == 0) {
+ if ((~sblock.fs_flags & FS_TRIM) == FS_TRIM)
+ warnx("%s remains unchanged as disabled", name);
+ else {
+ sblock.fs_flags &= ~FS_TRIM;
+ warnx("%s cleared", name);
+ }
+ }
+ }
if (sbwrite(&disk, Aflag) == -1)
goto err;
ufs_disk_close(&disk);
if (active) {
bzero(&args, sizeof(args));
if (mount("ufs", on,
stfs.f_flags | MNT_UPDATE | MNT_RELOAD, &args) < 0)
err(9, "%s: reload", special);
warnx("file system reloaded");
}
exit(0);
err:
if (disk.d_error != NULL)
errx(11, "%s: %s", special, disk.d_error);
else
err(12, "%s", special);
}
void
usage(void)
{
- fprintf(stderr, "%s\n%s\n%s\n%s\n",
+ fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n",
"usage: tunefs [-A] [-a enable | disable] [-e maxbpg] [-f avgfilesize]",
" [-J enable | disable ] [-L volname] [-l enable | disable]",
" [-m minfree] [-N enable | disable] [-n enable | disable]",
-" [-o space | time] [-p] [-s avgfpdir] special | filesystem");
+" [-o space | time] [-p] [-s avgfpdir] [-t enable | disable]",
+" special | filesystem");
exit(2);
}
void
printfs(void)
{
warnx("POSIX.1e ACLs: (-a) %s",
(sblock.fs_flags & FS_ACLS)? "enabled" : "disabled");
warnx("NFSv4 ACLs: (-N) %s",
(sblock.fs_flags & FS_NFS4ACLS)? "enabled" : "disabled");
warnx("MAC multilabel: (-l) %s",
(sblock.fs_flags & FS_MULTILABEL)? "enabled" : "disabled");
warnx("soft updates: (-n) %s",
(sblock.fs_flags & FS_DOSOFTDEP)? "enabled" : "disabled");
warnx("gjournal: (-J) %s",
(sblock.fs_flags & FS_GJOURNAL)? "enabled" : "disabled");
+ warnx("trim: (-t) %s",
+ (sblock.fs_flags & FS_TRIM)? "enabled" : "disabled");
warnx("maximum blocks per file in a cylinder group: (-e) %d",
sblock.fs_maxbpg);
warnx("average file size: (-f) %d",
sblock.fs_avgfilesize);
warnx("average number of files in a directory: (-s) %d",
sblock.fs_avgfpdir);
warnx("minimum percentage of free space: (-m) %d%%",
sblock.fs_minfree);
warnx("optimization preference: (-o) %s",
sblock.fs_optim == FS_OPTSPACE ? "space" : "time");
if (sblock.fs_minfree >= MINFREE &&
sblock.fs_optim == FS_OPTSPACE)
warnx(OPTWARN, "time", ">=", MINFREE);
if (sblock.fs_minfree < MINFREE &&
sblock.fs_optim == FS_OPTTIME)
warnx(OPTWARN, "space", "<", MINFREE);
warnx("volume label: (-L) %s",
sblock.fs_volname);
}
Index: stable/8/sbin/tunefs
===================================================================
--- stable/8/sbin/tunefs (revision 218079)
+++ stable/8/sbin/tunefs (revision 218080)
Property changes on: stable/8/sbin/tunefs
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/tunefs:r216798
Index: stable/8/sbin/umount
===================================================================
--- stable/8/sbin/umount (revision 218079)
+++ stable/8/sbin/umount (revision 218080)
Property changes on: stable/8/sbin/umount
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin/umount:r216798
Index: stable/8/sbin
===================================================================
--- stable/8/sbin (revision 218079)
+++ stable/8/sbin (revision 218080)
Property changes on: stable/8/sbin
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
Merged /head/sbin:r216798
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Sat, Apr 25, 11:46 PM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
32097661
Default Alt Text
(118 KB)
Attached To
Mode
rS FreeBSD src repository - subversion
Attached
Detach File
Event Timeline
Log In to Comment