aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirk McKusick <mckusick@FreeBSD.org>2020-10-25 01:36:33 +0000
committerKirk McKusick <mckusick@FreeBSD.org>2020-10-25 01:36:33 +0000
commit6eb925f8450ffbb849195f26e26bfd4eadbcfb1d (patch)
tree5b66b6c812f36de7bae2ed24e8a3b5b14e0b3879
parent996d40f91d7c3ca1b4efa11a4f59ee47c924eab1 (diff)
downloadsrc-6eb925f8450ffbb849195f26e26bfd4eadbcfb1d.tar.gz
src-6eb925f8450ffbb849195f26e26bfd4eadbcfb1d.zip
Filesystem utilities that modify the filesystem (growfs(8), tunefs(8),
and fsirand(8)) should check the filesystem status and require that fsck(8) be run if it is unclean. This requirement is not imposed on fsdb(8) or clri(8) since they may be used to clean up a filesystem. MFC after: 2 weeks Sponsored by: Netflix
Notes
Notes: svn path=/head/; revision=367035
-rw-r--r--sbin/fsirand/fsirand.c6
-rw-r--r--sbin/growfs/growfs.c6
-rw-r--r--sbin/tunefs/tunefs.c41
3 files changed, 36 insertions, 17 deletions
diff --git a/sbin/fsirand/fsirand.c b/sbin/fsirand/fsirand.c
index 48ffcbaf0665..c4db8848f18b 100644
--- a/sbin/fsirand/fsirand.c
+++ b/sbin/fsirand/fsirand.c
@@ -134,6 +134,12 @@ fsirand(char *device)
return (1);
}
}
+ /*
+ * Check for unclean filesystem.
+ */
+ if (sblock->fs_clean == 0 ||
+ (sblock->fs_flags & (FS_UNCLEAN | FS_NEEDSFSCK)) != 0)
+ errx(1, "%s is not clean - run fsck.\n", device);
if (sblock->fs_magic == FS_UFS1_MAGIC &&
sblock->fs_old_inodefmt < FS_44INODEFMT) {
diff --git a/sbin/growfs/growfs.c b/sbin/growfs/growfs.c
index 45d5f258c8ed..d1098210f088 100644
--- a/sbin/growfs/growfs.c
+++ b/sbin/growfs/growfs.c
@@ -1460,6 +1460,12 @@ main(int argc, char **argv)
errc(1, ret, "unable to read superblock");
}
}
+ /*
+ * Check for unclean filesystem.
+ */
+ if (fs->fs_clean == 0 ||
+ (fs->fs_flags & (FS_UNCLEAN | FS_NEEDSFSCK)) != 0)
+ errx(1, "%s is not clean - run fsck.\n", *argv);
memcpy(&osblock, fs, fs->fs_sbsize);
free(fs);
memcpy((void *)&fsun1, (void *)&fsun2, osblock.fs_sbsize);
diff --git a/sbin/tunefs/tunefs.c b/sbin/tunefs/tunefs.c
index 40bcbb1487f2..2eca8e0a3e36 100644
--- a/sbin/tunefs/tunefs.c
+++ b/sbin/tunefs/tunefs.c
@@ -115,12 +115,12 @@ main(int argc, char *argv[])
switch (ch) {
case 'A':
- found_arg = 1;
+ found_arg++;
Aflag++;
break;
case 'a':
- found_arg = 1;
+ found_arg++;
name = "POSIX.1e ACLs";
avalue = optarg;
if (strcmp(avalue, "enable") &&
@@ -132,7 +132,7 @@ main(int argc, char *argv[])
break;
case 'e':
- found_arg = 1;
+ found_arg++;
name = "maximum blocks per file in a cylinder group";
evalue = atoi(optarg);
if (evalue < 1)
@@ -142,7 +142,7 @@ main(int argc, char *argv[])
break;
case 'f':
- found_arg = 1;
+ found_arg++;
name = "average file size";
fvalue = atoi(optarg);
if (fvalue < 1)
@@ -152,7 +152,7 @@ main(int argc, char *argv[])
break;
case 'j':
- found_arg = 1;
+ found_arg++;
name = "softdep journaled file system";
jvalue = optarg;
if (strcmp(jvalue, "enable") &&
@@ -164,7 +164,7 @@ main(int argc, char *argv[])
break;
case 'J':
- found_arg = 1;
+ found_arg++;
name = "gjournaled file system";
Jvalue = optarg;
if (strcmp(Jvalue, "enable") &&
@@ -176,7 +176,7 @@ main(int argc, char *argv[])
break;
case 'k':
- found_arg = 1;
+ found_arg++;
name = "space to hold for metadata blocks";
kvalue = atoi(optarg);
if (kvalue < 0)
@@ -185,7 +185,7 @@ main(int argc, char *argv[])
break;
case 'L':
- found_arg = 1;
+ found_arg++;
name = "volume label";
Lvalue = optarg;
i = -1;
@@ -205,7 +205,7 @@ main(int argc, char *argv[])
break;
case 'l':
- found_arg = 1;
+ found_arg++;
name = "multilabel MAC file system";
lvalue = optarg;
if (strcmp(lvalue, "enable") &&
@@ -217,7 +217,7 @@ main(int argc, char *argv[])
break;
case 'm':
- found_arg = 1;
+ found_arg++;
name = "minimum percentage of free space";
mvalue = atoi(optarg);
if (mvalue < 0 || mvalue > 99)
@@ -226,7 +226,7 @@ main(int argc, char *argv[])
break;
case 'N':
- found_arg = 1;
+ found_arg++;
name = "NFSv4 ACLs";
Nvalue = optarg;
if (strcmp(Nvalue, "enable") &&
@@ -238,7 +238,7 @@ main(int argc, char *argv[])
break;
case 'n':
- found_arg = 1;
+ found_arg++;
name = "soft updates";
nvalue = optarg;
if (strcmp(nvalue, "enable") != 0 &&
@@ -250,7 +250,7 @@ main(int argc, char *argv[])
break;
case 'o':
- found_arg = 1;
+ found_arg++;
name = "optimization preference";
if (strcmp(optarg, "space") == 0)
ovalue = FS_OPTSPACE;
@@ -264,12 +264,12 @@ main(int argc, char *argv[])
break;
case 'p':
- found_arg = 1;
+ found_arg++;
pflag = 1;
break;
case 's':
- found_arg = 1;
+ found_arg++;
name = "expected number of files per directory";
svalue = atoi(optarg);
if (svalue < 1)
@@ -279,7 +279,7 @@ main(int argc, char *argv[])
break;
case 'S':
- found_arg = 1;
+ found_arg++;
name = "Softdep Journal Size";
Svalue = atoi(optarg);
if (Svalue < SUJ_MIN)
@@ -288,7 +288,7 @@ main(int argc, char *argv[])
break;
case 't':
- found_arg = 1;
+ found_arg++;
name = "trim";
tvalue = optarg;
if (strcmp(tvalue, "enable") != 0 &&
@@ -310,6 +310,13 @@ main(int argc, char *argv[])
on = special = argv[0];
if (ufs_disk_fillout(&disk, special) == -1)
goto err;
+ /*
+ * Check for unclean filesystem.
+ */
+ if ((sblock.fs_clean == 0 ||
+ (sblock.fs_flags & (FS_UNCLEAN | FS_NEEDSFSCK)) != 0) &&
+ (found_arg > 1 || !pflag))
+ errx(1, "%s is not clean - run fsck.\n", special);
if (disk.d_name != special) {
if (statfs(special, &stfs) != 0)
warn("Can't stat %s", special);