From 9655c24691072dc162e49cfa5604c11e98b545d9 Mon Sep 17 00:00:00 2001 From: christos Date: Thu, 9 Apr 2020 14:44:38 +0000 Subject: [PATCH] Refresh the superblock in memory if changing a mounted partition. --- sbin/tunefs/tunefs.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/sbin/tunefs/tunefs.c b/sbin/tunefs/tunefs.c index 1e819d2efd19..a0a7382b0c16 100644 --- a/sbin/tunefs/tunefs.c +++ b/sbin/tunefs/tunefs.c @@ -1,4 +1,4 @@ -/* $NetBSD: tunefs.c,v 1.50 2019/04/12 01:14:37 pgoyette Exp $ */ +/* $NetBSD: tunefs.c,v 1.51 2020/04/09 14:44:38 christos Exp $ */ /* * Copyright (c) 1983, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1993\ #if 0 static char sccsid[] = "@(#)tunefs.c 8.3 (Berkeley) 5/3/95"; #else -__RCSID("$NetBSD: tunefs.c,v 1.50 2019/04/12 01:14:37 pgoyette Exp $"); +__RCSID("$NetBSD: tunefs.c,v 1.51 2020/04/09 14:44:38 christos Exp $"); #endif #endif /* not lint */ @@ -47,10 +47,12 @@ __RCSID("$NetBSD: tunefs.c,v 1.50 2019/04/12 01:14:37 pgoyette Exp $"); * tunefs: change layout parameters to an existing file system. */ #include +#include #include #include #include +#include #include #include @@ -103,9 +105,10 @@ main(int argc, char *argv[]) const char *special, *chg[2]; char device[MAXPATHLEN]; int maxbpg, minfree, optim, secsize; - int avgfilesize, avgfpdir; + int avgfilesize, avgfpdir, active; long long logfilesize; int secshift, fsbtodb; + struct statvfs sfs; Aflag = Fflag = Nflag = 0; maxbpg = minfree = optim = secsize = -1; @@ -203,6 +206,7 @@ main(int argc, char *argv[]) fi = openpartition(special, openflags, device, sizeof(device)); special = device; } + active = fstatvfs(fi, &sfs) != -1; if (fi == -1) err(1, "%s", special); getsb(&sblock, special); @@ -365,6 +369,18 @@ main(int argc, char *argv[]) /* write superblock to original coordinates (use old dev_bsize!) */ bwrite(sblockloc, buf.data, SBLOCKSIZE, special); + if (active) { + struct ufs_args args; + args.fspec = sfs.f_mntfromname; + if (mount(MOUNT_FFS, sfs.f_mntonname, sfs.f_flag | MNT_UPDATE, + &args, sizeof args) == -1) + warn("mount"); + else + printf("%s: mount of %s on %s updated\n", + getprogname(), sfs.f_mntfromname, sfs.f_mntonname); + } + + /* correct dev_bsize from possibly changed superblock data */ dev_bsize = sblock.fs_fsize / FFS_FSBTODB(&sblock, 1);