fsck_snap Add a test for duplicate inodes on the persistent snapshot list. diff -r 0db3ce0fc892 -r 88c9be1ed73e sbin/fsck_ffs/setup.c --- sbin/fsck_ffs/setup.c +++ sbin/fsck_ffs/setup.c @@ -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; +}