aboutsummaryrefslogtreecommitdiff
path: root/sbin/growfs
diff options
context:
space:
mode:
Diffstat (limited to 'sbin/growfs')
-rw-r--r--sbin/growfs/Makefile7
-rw-r--r--sbin/growfs/debug.c9
-rw-r--r--sbin/growfs/growfs.820
-rw-r--r--sbin/growfs/growfs.c58
-rw-r--r--sbin/growfs/tests/Makefile1
-rwxr-xr-xsbin/growfs/tests/legacy_test.pl6
6 files changed, 41 insertions, 60 deletions
diff --git a/sbin/growfs/Makefile b/sbin/growfs/Makefile
index 3f72e6ac625f..b5b3d99f287d 100644
--- a/sbin/growfs/Makefile
+++ b/sbin/growfs/Makefile
@@ -1,17 +1,12 @@
-# @(#)Makefile 8.8 (Berkeley) 6/21/2000
-#
# $TSHeader: src/sbin/growfs/Makefile,v 1.4 2000/12/05 19:45:24 tomsoft Exp $
#
.include <src.opts.mk>
-.PATH: ${.CURDIR:H}/mount
-
PACKAGE=ufs
PROG= growfs
-SRCS= growfs.c getmntopts.c
+SRCS= growfs.c
MAN= growfs.8
-CFLAGS+=-I${.CURDIR:H}/mount
.if defined(GFSDBG)
SRCS+= debug.c
diff --git a/sbin/growfs/debug.c b/sbin/growfs/debug.c
index e0dfc997fcf6..3fe7e26e3e50 100644
--- a/sbin/growfs/debug.c
+++ b/sbin/growfs/debug.c
@@ -41,11 +41,6 @@
*
*/
-#ifndef lint
-static const char rcsid[] =
- "$FreeBSD$";
-#endif /* not lint */
-
#include <sys/param.h>
#include <limits.h>
@@ -62,7 +57,7 @@ static FILE *dbg_log = NULL;
static unsigned int indent = 0;
/*
- * prototypes not done here, as they come with debug.h
+ * prototypes are not done here, as they come with debug.h
*/
/*
@@ -310,8 +305,6 @@ dbg_dump_fs(struct fs *sb, const char *comment)
sb->fs_avgfilesize);
fprintf(dbg_log, "avgfpdir int32_t 0x%08x\n",
sb->fs_avgfpdir);
- fprintf(dbg_log, "save_cgsize int32_t 0x%08x\n",
- sb->fs_save_cgsize);
fprintf(dbg_log, "flags int32_t 0x%08x\n",
sb->fs_flags);
fprintf(dbg_log, "contigsumsize int32_t 0x%08x\n",
diff --git a/sbin/growfs/growfs.8 b/sbin/growfs/growfs.8
index f83c3c00cf1f..f23817b0afbe 100644
--- a/sbin/growfs/growfs.8
+++ b/sbin/growfs/growfs.8
@@ -36,7 +36,7 @@
.\"
.\" $TSHeader: src/sbin/growfs/growfs.8,v 1.3 2000/12/12 19:31:00 tomsoft Exp $
.\"
-.Dd December 13, 2017
+.Dd January 23, 2025
.Dt GROWFS 8
.Os
.Sh NAME
@@ -55,22 +55,15 @@ Before running
.Nm
the partition or slice containing the file system must be extended using
.Xr gpart 8 .
-If you are using volumes you must enlarge them by using
-.Xr gvinum 8 .
The
.Nm
utility extends the size of the file system on the specified special file.
The following options are available:
-.Bl -tag -width indent
+.Bl -tag -width "-s size"
.It Fl N
.Dq Test mode .
Causes the new file system parameters to be printed out without actually
enlarging the file system.
-.It Fl y
-Causes
-.Nm
-to assume yes
-as the answer to all operator questions.
.It Fl s Ar size
Determines the
.Ar size
@@ -87,7 +80,16 @@ This value defaults to the size of the raw partition specified in
(in other words,
.Nm
will enlarge the file system to the size of the entire partition).
+.It Fl y
+Causes
+.Nm
+to assume yes
+as the answer to all operator questions.
.El
+.Sh EXIT STATUS
+Exit status is 0 on success, and >= 1 on errors.
+Errors recoverable by user action are indicated by 2.
+OS errors, which are usually not recoverable, are indicated by 3 or greater.
.Sh EXAMPLES
Expand root file system to fill up available space:
.Dl growfs /
diff --git a/sbin/growfs/growfs.c b/sbin/growfs/growfs.c
index fc314d19a4e3..9a48287107e7 100644
--- a/sbin/growfs/growfs.c
+++ b/sbin/growfs/growfs.c
@@ -45,14 +45,6 @@
*
*/
-#ifndef lint
-static const char copyright[] =
-"@(#) Copyright (c) 2000 Christoph Herrmann, Thomas-Henning von Kamptz\n\
-Copyright (c) 1980, 1989, 1993 The Regents of the University of California.\n\
-All rights reserved.\n";
-#endif /* not lint */
-
-#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
@@ -147,7 +139,7 @@ growfs(int fsi, int fso, unsigned int Nflag)
*/
fscs = (struct csum *)calloc((size_t)1, (size_t)sblock.fs_cssize);
if (fscs == NULL)
- errx(1, "calloc failed");
+ errx(3, "calloc failed");
memcpy(fscs, osblock.fs_csp, osblock.fs_cssize);
free(osblock.fs_csp);
osblock.fs_csp = NULL;
@@ -240,7 +232,7 @@ growfs(int fsi, int fso, unsigned int Nflag)
*
* We probably should rather change the summary for the cylinder group
* statistics here to the value of what would be in there, if the file
- * system were created initially with the new size. Therefor we still
+ * system were created initially with the new size. Therefore we still
* need to find an easy way of calculating that.
* Possibly we can try to read the first superblock copy and apply the
* "diffed" stats between the old and new superblock by still copying
@@ -259,7 +251,7 @@ growfs(int fsi, int fso, unsigned int Nflag)
* and all the alternates back to disk.
*/
if (!Nflag && sbput(fso, &sblock, sblock.fs_ncg) != 0)
- errc(2, EIO, "could not write updated superblock");
+ errc(3, EIO, "could not write updated superblock");
DBG_PRINT0("fscs written\n");
#ifdef FS_DEBUG
@@ -687,7 +679,7 @@ updjcg(int cylno, time_t modtime, int fsi, int fso, unsigned int Nflag)
sblock.fs_frag);
} else {
/*
- * Lets rejoin a possible partially growed
+ * Lets rejoin a possible partially grown
* fragment.
*/
k = 0;
@@ -713,7 +705,7 @@ updjcg(int cylno, time_t modtime, int fsi, int fso, unsigned int Nflag)
j++;
}
/*
- * Lets rejoin a possible partially growed fragment.
+ * Lets rejoin a possible partially grown fragment.
*/
k = 0;
while (isset(cg_blksfree(&acg), i) &&
@@ -741,7 +733,7 @@ updjcg(int cylno, time_t modtime, int fsi, int fso, unsigned int Nflag)
}
/*
- * Handle the last new block if there are stll some new fragments left.
+ * Handle the last new block if there are still some new fragments left.
* Here we don't have to bother about the cluster summary or the even
* the rotational layout table.
*/
@@ -1339,7 +1331,7 @@ main(int argc, char **argv)
size <<= 30;
size <<= 10;
} else
- errx(1, "unknown suffix on -s argument");
+ errx(2, "unknown suffix on -s argument");
break;
case 'v': /* for compatibility to newfs */
break;
@@ -1364,23 +1356,23 @@ main(int argc, char **argv)
statfsp = getmntpoint(*argv);
device = getdev(*argv, statfsp);
if (device == NULL)
- errx(1, "cannot find special device for %s", *argv);
+ errx(2, "cannot find special device for %s", *argv);
fsi = open(device, O_RDONLY);
if (fsi < 0)
- err(1, "%s", device);
+ err(3, "%s", device);
/*
* Try to guess the slice size if not specified.
*/
if (ioctl(fsi, DIOCGMEDIASIZE, &mediasize) == -1)
- err(1,"DIOCGMEDIASIZE");
+ err(3,"DIOCGMEDIASIZE");
/*
* Check if that partition is suitable for growing a file system.
*/
if (mediasize < 1)
- errx(1, "partition is unavailable");
+ errx(2, "partition is unavailable");
/*
* Read the current superblock, and take a backup.
@@ -1388,16 +1380,16 @@ main(int argc, char **argv)
if ((ret = sbget(fsi, &fs, UFS_STDSB, 0)) != 0) {
switch (ret) {
case ENOENT:
- errx(1, "superblock not recognized");
+ errx(2, "superblock not recognized");
default:
- errc(1, ret, "unable to read superblock");
+ errc(3, ret, "unable to read superblock");
}
}
/*
* Check for filesystem that was unclean at mount time.
*/
if ((fs->fs_flags & (FS_UNCLEAN | FS_NEEDSFSCK)) != 0)
- errx(1, "%s is not clean - run fsck.\n", *argv);
+ errx(2, "%s is not clean - run fsck.\n", *argv);
memcpy(&osblock, fs, fs->fs_sbsize);
free(fs);
memcpy((void *)&fsun1, (void *)&fsun2, osblock.fs_sbsize);
@@ -1418,7 +1410,7 @@ main(int argc, char **argv)
mediasize,
"B", HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
- errx(1, "requested size %s is larger "
+ errx(2, "requested size %s is larger "
"than the available %s", oldsizebuf, newsizebuf);
}
}
@@ -1439,7 +1431,7 @@ main(int argc, char **argv)
if (size == (uint64_t)(osblock.fs_size * osblock.fs_fsize))
errx(0, "requested size %s is equal to the current "
"filesystem size %s", newsizebuf, oldsizebuf);
- errx(1, "requested size %s is smaller than the current "
+ errx(2, "requested size %s is smaller than the current "
"filesystem size %s", newsizebuf, oldsizebuf);
}
@@ -1451,7 +1443,7 @@ main(int argc, char **argv)
* Are we really growing?
*/
if (osblock.fs_size >= sblock.fs_size) {
- errx(1, "we are not growing (%jd->%jd)",
+ errx(3, "we are not growing (%jd->%jd)",
(intmax_t)osblock.fs_size, (intmax_t)sblock.fs_size);
}
@@ -1461,7 +1453,7 @@ main(int argc, char **argv)
if (yflag == 0) {
for (j = 0; j < FSMAXSNAP; j++) {
if (sblock.fs_snapinum[j]) {
- errx(1, "active snapshot found in file system; "
+ errx(2, "active snapshot found in file system; "
"please remove all snapshots before "
"using growfs");
}
@@ -1506,14 +1498,14 @@ main(int argc, char **argv)
if (statfsp != NULL && (statfsp->f_flags & MNT_RDONLY) == 0) {
fso = open(_PATH_UFSSUSPEND, O_RDWR);
if (fso == -1)
- err(1, "unable to open %s", _PATH_UFSSUSPEND);
+ err(3, "unable to open %s", _PATH_UFSSUSPEND);
error = ioctl(fso, UFSSUSPEND, &statfsp->f_fsid);
if (error != 0)
- err(1, "UFSSUSPEND");
+ err(3, "UFSSUSPEND");
} else {
fso = open(device, O_WRONLY);
if (fso < 0)
- err(1, "%s", device);
+ err(3, "%s", device);
}
}
@@ -1522,7 +1514,7 @@ main(int argc, char **argv)
*/
testbuf = malloc(sblock.fs_fsize);
if (testbuf == NULL)
- err(1, "malloc");
+ err(3, "malloc");
rdfs((ufs2_daddr_t)((size - sblock.fs_fsize) / DEV_BSIZE),
sblock.fs_fsize, testbuf, fsi);
wtfs((ufs2_daddr_t)((size - sblock.fs_fsize) / DEV_BSIZE),
@@ -1577,7 +1569,7 @@ main(int argc, char **argv)
fragroundup(&sblock, sblock.fs_ncg * sizeof(struct csum));
if (osblock.fs_size >= sblock.fs_size)
- errx(1, "not enough new space");
+ errx(3, "not enough new space");
DBG_PRINT0("sblock calculated\n");
@@ -1591,11 +1583,11 @@ main(int argc, char **argv)
if (statfsp != NULL && (statfsp->f_flags & MNT_RDONLY) == 0) {
error = ioctl(fso, UFSRESUME);
if (error != 0)
- err(1, "UFSRESUME");
+ err(3, "UFSRESUME");
}
error = close(fso);
if (error != 0)
- err(1, "close");
+ err(3, "close");
if (statfsp != NULL && (statfsp->f_flags & MNT_RDONLY) != 0 &&
chkdoreload(statfsp, warn) != 0)
exit(9);
diff --git a/sbin/growfs/tests/Makefile b/sbin/growfs/tests/Makefile
index 270eb46ce958..a23b430f58fa 100644
--- a/sbin/growfs/tests/Makefile
+++ b/sbin/growfs/tests/Makefile
@@ -1,4 +1,3 @@
-
TAP_TESTS_PERL= legacy_test
.include <bsd.test.mk>
diff --git a/sbin/growfs/tests/legacy_test.pl b/sbin/growfs/tests/legacy_test.pl
index 7ae2e59422d8..e2b145fa7f35 100755
--- a/sbin/growfs/tests/legacy_test.pl
+++ b/sbin/growfs/tests/legacy_test.pl
@@ -30,9 +30,9 @@ sub fsck_md {
sub setsize {
my ($partszMB, $unitszMB) = @_;
- open my $fd, "|-", "bsdlabel -R md$unit /dev/stdin" or die;
- print $fd "a: ", ($partszMB * BLKS_PER_MB), " 0 4.2BSD 1024 8192\n";
- print $fd "c: ", ($unitszMB * BLKS_PER_MB), " 0 unused 0 0\n";
+ open my $fd, "|-", "gpart restore -F md$unit" or die;
+ print $fd "BSD 8\n";
+ print $fd "1 freebsd-ufs 0 ", ($partszMB * BLKS_PER_MB), "\n";
close $fd;
}