Module Name: src Committed By: hannken Date: Fri Oct 5 09:49:23 UTC 2018
Modified Files: src/sbin/fsck_ffs: setup.c Log Message: Add a test for duplicate inodes on the persistent snapshot list. To generate a diff of this commit: cvs rdiff -u -r1.101 -r1.102 src/sbin/fsck_ffs/setup.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sbin/fsck_ffs/setup.c diff -u src/sbin/fsck_ffs/setup.c:1.101 src/sbin/fsck_ffs/setup.c:1.102 --- src/sbin/fsck_ffs/setup.c:1.101 Wed Feb 8 16:11:40 2017 +++ src/sbin/fsck_ffs/setup.c Fri Oct 5 09:49:23 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: setup.c,v 1.101 2017/02/08 16:11:40 rin Exp $ */ +/* $NetBSD: setup.c,v 1.102 2018/10/05 09:49:23 hannken Exp $ */ /* * Copyright (c) 1980, 1986, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)setup.c 8.10 (Berkeley) 5/9/95"; #else -__RCSID("$NetBSD: setup.c,v 1.101 2017/02/08 16:11:40 rin Exp $"); +__RCSID("$NetBSD: setup.c,v 1.102 2018/10/05 09:49:23 hannken Exp $"); #endif #endif /* not lint */ @@ -73,6 +73,7 @@ static int readsb(int); #ifndef NO_APPLE_UFS static int readappleufs(void); #endif +static int check_snapinum(void); int16_t sblkpostbl[256]; @@ -341,6 +342,14 @@ setup(const char *dev, const char *origd dirty(&asblk); } } + if (check_snapinum()) { + if (preen) + printf(" (FIXED)\n"); + if (preen || reply("FIX") == 1) { + sbdirty(); + dirty(&asblk); + } + } if (is_ufs2 || sblock->fs_old_inodefmt >= FS_44INODEFMT) { if (sblock->fs_maxfilesize != maxfilesize) { pwarn("INCORRECT MAXFILESIZE=%lld IN SUPERBLOCK", @@ -1094,3 +1103,42 @@ calcsb(const char *dev, int devfd, struc } return (1); } + +/* + * Test the list of snapshot inode numbers for duplicates and repair. + */ +static int +check_snapinum(void) +{ + int loc, loc2, res; + int *snapinum = &sblock->fs_snapinum[0]; + + res = 0; + + if (isappleufs) + return 0; + + for (loc = 0; loc < FSMAXSNAP; loc++) { + if (snapinum[loc] == 0) + break; + for (loc2 = loc + 1; loc2 < FSMAXSNAP; loc2++) { + if (snapinum[loc2] == 0 || + snapinum[loc2] == snapinum[loc]) + break; + } + if (loc2 >= FSMAXSNAP || snapinum[loc2] == 0) + continue; + pwarn("SNAPSHOT INODE %u ALREADY ON LIST%s", snapinum[loc2], + (res ? "" : "\n")); + res = 1; + for (loc2 = loc + 1; loc2 < FSMAXSNAP; loc2++) { + if (snapinum[loc2] == 0) + break; + snapinum[loc2 - 1] = snapinum[loc2]; + } + snapinum[loc2 - 1] = 0; + loc--; + } + + return res; +}