git: f1549d7d5229 - main - Write out corrected superblock when creating a UFS/FFS snapshot.

From: Kirk McKusick <mckusick_at_FreeBSD.org>
Date: Tue, 13 Jun 2023 07:22:44 UTC
The branch main has been updated by mckusick:

URL: https://cgit.FreeBSD.org/src/commit/?id=f1549d7d522995bf5d821ae08cc2f500ba545285

commit f1549d7d522995bf5d821ae08cc2f500ba545285
Author:     Kirk McKusick <mckusick@FreeBSD.org>
AuthorDate: 2023-06-13 07:21:43 +0000
Commit:     Kirk McKusick <mckusick@FreeBSD.org>
CommitDate: 2023-06-13 07:22:13 +0000

    Write out corrected superblock when creating a UFS/FFS snapshot.
    
    When taking a snapshot on a UFS version 1 filesystem we need to
    call ffs_oldfscompat_write() to unwind any in-memory changes that
    were made to the superblock before writing it. The cause of this bug
    was that the trimmed down maximum file size was not being reverted.
    
    PR:           271352
    Tested-by:    Peter Holm
    MFC-after:    1 week
    Sponsored-by: The FreeBSD Foundation
---
 sys/ufs/ffs/ffs_snapshot.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/sys/ufs/ffs/ffs_snapshot.c b/sys/ufs/ffs/ffs_snapshot.c
index 8c3fcdbf72b9..fa744f0fab79 100644
--- a/sys/ufs/ffs/ffs_snapshot.c
+++ b/sys/ufs/ffs/ffs_snapshot.c
@@ -207,7 +207,7 @@ ffs_snapshot(struct mount *mp, char *snapfile)
 	long snaplistsize = 0;
 	int32_t *lp;
 	void *space;
-	struct fs *copy_fs = NULL, *fs;
+	struct fs *copy_fs = NULL, *fs, *bpfs;
 	struct thread *td = curthread;
 	struct inode *ip, *xp;
 	struct buf *bp, *nbp, *ibp;
@@ -828,8 +828,10 @@ resumefs:
 	} else {
 		loc = blkoff(fs, fs->fs_sblockloc);
 		copy_fs->fs_fmod = 0;
-		copy_fs->fs_ckhash = ffs_calc_sbhash(copy_fs);
-		bcopy((char *)copy_fs, &nbp->b_data[loc], (u_int)fs->fs_sbsize);
+		bpfs = (struct fs *)&nbp->b_data[loc];
+		bcopy((caddr_t)copy_fs, (caddr_t)bpfs, (u_int)fs->fs_sbsize);
+		ffs_oldfscompat_write(bpfs, ump);
+		bpfs->fs_ckhash = ffs_calc_sbhash(bpfs);
 		bawrite(nbp);
 	}
 	/*