Skip to content

Commit

Permalink
Filesystem utilities that modify the filesystem (growfs(8), tunefs(8),
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Kirk McKusick authored and Kirk McKusick committed Oct 25, 2020
1 parent 996d40f commit 6eb925f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
6 changes: 6 additions & 0 deletions sbin/fsirand/fsirand.c
Expand Up @@ -134,6 +134,12 @@ fsirand(char *device)
return (1); 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 && if (sblock->fs_magic == FS_UFS1_MAGIC &&
sblock->fs_old_inodefmt < FS_44INODEFMT) { sblock->fs_old_inodefmt < FS_44INODEFMT) {
Expand Down
6 changes: 6 additions & 0 deletions sbin/growfs/growfs.c
Expand Up @@ -1460,6 +1460,12 @@ main(int argc, char **argv)
errc(1, ret, "unable to read superblock"); 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); memcpy(&osblock, fs, fs->fs_sbsize);
free(fs); free(fs);
memcpy((void *)&fsun1, (void *)&fsun2, osblock.fs_sbsize); memcpy((void *)&fsun1, (void *)&fsun2, osblock.fs_sbsize);
Expand Down
41 changes: 24 additions & 17 deletions sbin/tunefs/tunefs.c
Expand Up @@ -115,12 +115,12 @@ main(int argc, char *argv[])
switch (ch) { switch (ch) {


case 'A': case 'A':
found_arg = 1; found_arg++;
Aflag++; Aflag++;
break; break;


case 'a': case 'a':
found_arg = 1; found_arg++;
name = "POSIX.1e ACLs"; name = "POSIX.1e ACLs";
avalue = optarg; avalue = optarg;
if (strcmp(avalue, "enable") && if (strcmp(avalue, "enable") &&
Expand All @@ -132,7 +132,7 @@ main(int argc, char *argv[])
break; break;


case 'e': case 'e':
found_arg = 1; found_arg++;
name = "maximum blocks per file in a cylinder group"; name = "maximum blocks per file in a cylinder group";
evalue = atoi(optarg); evalue = atoi(optarg);
if (evalue < 1) if (evalue < 1)
Expand All @@ -142,7 +142,7 @@ main(int argc, char *argv[])
break; break;


case 'f': case 'f':
found_arg = 1; found_arg++;
name = "average file size"; name = "average file size";
fvalue = atoi(optarg); fvalue = atoi(optarg);
if (fvalue < 1) if (fvalue < 1)
Expand All @@ -152,7 +152,7 @@ main(int argc, char *argv[])
break; break;


case 'j': case 'j':
found_arg = 1; found_arg++;
name = "softdep journaled file system"; name = "softdep journaled file system";
jvalue = optarg; jvalue = optarg;
if (strcmp(jvalue, "enable") && if (strcmp(jvalue, "enable") &&
Expand All @@ -164,7 +164,7 @@ main(int argc, char *argv[])
break; break;


case 'J': case 'J':
found_arg = 1; found_arg++;
name = "gjournaled file system"; name = "gjournaled file system";
Jvalue = optarg; Jvalue = optarg;
if (strcmp(Jvalue, "enable") && if (strcmp(Jvalue, "enable") &&
Expand All @@ -176,7 +176,7 @@ main(int argc, char *argv[])
break; break;


case 'k': case 'k':
found_arg = 1; found_arg++;
name = "space to hold for metadata blocks"; name = "space to hold for metadata blocks";
kvalue = atoi(optarg); kvalue = atoi(optarg);
if (kvalue < 0) if (kvalue < 0)
Expand All @@ -185,7 +185,7 @@ main(int argc, char *argv[])
break; break;


case 'L': case 'L':
found_arg = 1; found_arg++;
name = "volume label"; name = "volume label";
Lvalue = optarg; Lvalue = optarg;
i = -1; i = -1;
Expand All @@ -205,7 +205,7 @@ main(int argc, char *argv[])
break; break;


case 'l': case 'l':
found_arg = 1; found_arg++;
name = "multilabel MAC file system"; name = "multilabel MAC file system";
lvalue = optarg; lvalue = optarg;
if (strcmp(lvalue, "enable") && if (strcmp(lvalue, "enable") &&
Expand All @@ -217,7 +217,7 @@ main(int argc, char *argv[])
break; break;


case 'm': case 'm':
found_arg = 1; found_arg++;
name = "minimum percentage of free space"; name = "minimum percentage of free space";
mvalue = atoi(optarg); mvalue = atoi(optarg);
if (mvalue < 0 || mvalue > 99) if (mvalue < 0 || mvalue > 99)
Expand All @@ -226,7 +226,7 @@ main(int argc, char *argv[])
break; break;


case 'N': case 'N':
found_arg = 1; found_arg++;
name = "NFSv4 ACLs"; name = "NFSv4 ACLs";
Nvalue = optarg; Nvalue = optarg;
if (strcmp(Nvalue, "enable") && if (strcmp(Nvalue, "enable") &&
Expand All @@ -238,7 +238,7 @@ main(int argc, char *argv[])
break; break;


case 'n': case 'n':
found_arg = 1; found_arg++;
name = "soft updates"; name = "soft updates";
nvalue = optarg; nvalue = optarg;
if (strcmp(nvalue, "enable") != 0 && if (strcmp(nvalue, "enable") != 0 &&
Expand All @@ -250,7 +250,7 @@ main(int argc, char *argv[])
break; break;


case 'o': case 'o':
found_arg = 1; found_arg++;
name = "optimization preference"; name = "optimization preference";
if (strcmp(optarg, "space") == 0) if (strcmp(optarg, "space") == 0)
ovalue = FS_OPTSPACE; ovalue = FS_OPTSPACE;
Expand All @@ -264,12 +264,12 @@ main(int argc, char *argv[])
break; break;


case 'p': case 'p':
found_arg = 1; found_arg++;
pflag = 1; pflag = 1;
break; break;


case 's': case 's':
found_arg = 1; found_arg++;
name = "expected number of files per directory"; name = "expected number of files per directory";
svalue = atoi(optarg); svalue = atoi(optarg);
if (svalue < 1) if (svalue < 1)
Expand All @@ -279,7 +279,7 @@ main(int argc, char *argv[])
break; break;


case 'S': case 'S':
found_arg = 1; found_arg++;
name = "Softdep Journal Size"; name = "Softdep Journal Size";
Svalue = atoi(optarg); Svalue = atoi(optarg);
if (Svalue < SUJ_MIN) if (Svalue < SUJ_MIN)
Expand All @@ -288,7 +288,7 @@ main(int argc, char *argv[])
break; break;


case 't': case 't':
found_arg = 1; found_arg++;
name = "trim"; name = "trim";
tvalue = optarg; tvalue = optarg;
if (strcmp(tvalue, "enable") != 0 && if (strcmp(tvalue, "enable") != 0 &&
Expand All @@ -310,6 +310,13 @@ main(int argc, char *argv[])
on = special = argv[0]; on = special = argv[0];
if (ufs_disk_fillout(&disk, special) == -1) if (ufs_disk_fillout(&disk, special) == -1)
goto err; 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 (disk.d_name != special) {
if (statfs(special, &stfs) != 0) if (statfs(special, &stfs) != 0)
warn("Can't stat %s", special); warn("Can't stat %s", special);
Expand Down

0 comments on commit 6eb925f

Please sign in to comment.