aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirk McKusick <mckusick@FreeBSD.org>2021-04-26 23:47:27 +0000
committerKirk McKusick <mckusick@FreeBSD.org>2021-04-26 23:48:30 +0000
commit84a0e3f95700733695115fb2a9d84d6666efe5d9 (patch)
tree9e64bbc31cbbfed5892830fb9aa5579d4834fdd7
parent61aea7fa3c2a567245b36bf664fac0c15573c19e (diff)
downloadsrc-84a0e3f95700733695115fb2a9d84d6666efe5d9.tar.gz
src-84a0e3f95700733695115fb2a9d84d6666efe5d9.zip
Make fsck_ffs more persistent in creating a lost+found directory.
When fsck_ffs is running in interactive mode and finds unlinked files, it offers to either unlink them or place them in a lost+found directory. If the lost+found directory option is requested and no lost+found directory exists, fsck_ffs offers to create one. When creating one, it must allocate an inode and a filesystem block. It attempts to allocate them from the first cylinder group. If the first cylinder group has a bad check hash, it gives up. This change expands the search into later cylinder groups when the first one fails with a bad check hash. Reported by: Chuck Silvers Tested by: Chuck Silvers MFC after: 1 week Sponsored by: Netflix
-rw-r--r--sbin/fsck_ffs/dir.c2
-rw-r--r--sbin/fsck_ffs/fsutil.c6
-rw-r--r--sbin/fsck_ffs/inode.c19
3 files changed, 19 insertions, 8 deletions
diff --git a/sbin/fsck_ffs/dir.c b/sbin/fsck_ffs/dir.c
index e88d1650ce5a..e806f113ff16 100644
--- a/sbin/fsck_ffs/dir.c
+++ b/sbin/fsck_ffs/dir.c
@@ -801,6 +801,8 @@ allocdir(ino_t parent, ino_t request, int mode)
struct dirtemplate *dirp;
ino = allocino(request, IFDIR|mode);
+ if (ino == 0)
+ return (0);
dirp = &dirhead;
dirp->dot_ino = ino;
dirp->dotdot_ino = parent;
diff --git a/sbin/fsck_ffs/fsutil.c b/sbin/fsck_ffs/fsutil.c
index ca19f6726af5..276d543dedc6 100644
--- a/sbin/fsck_ffs/fsutil.c
+++ b/sbin/fsck_ffs/fsutil.c
@@ -1048,8 +1048,10 @@ allocblk(long frags)
cg = dtog(&sblock, i + j);
cgbp = cglookup(cg);
cgp = cgbp->b_un.b_cg;
- if (!check_cgmagic(cg, cgbp, 0))
- return (0);
+ if (!check_cgmagic(cg, cgbp, 0)) {
+ i = (cg + 1) * sblock.fs_fpg - sblock.fs_frag;
+ continue;
+ }
baseblk = dtogd(&sblock, i + j);
for (k = 0; k < frags; k++) {
setbmap(i + j + k);
diff --git a/sbin/fsck_ffs/inode.c b/sbin/fsck_ffs/inode.c
index 020a69dd72f8..d4e5723f559f 100644
--- a/sbin/fsck_ffs/inode.c
+++ b/sbin/fsck_ffs/inode.c
@@ -902,22 +902,29 @@ allocino(ino_t request, int type)
union dinode *dp;
struct bufarea *cgbp;
struct cg *cgp;
- int cg;
+ int cg, anyino;
- if (request == 0)
+ anyino = 0;
+ if (request == 0) {
request = UFS_ROOTINO;
- else if (inoinfo(request)->ino_state != USTATE)
+ anyino = 1;
+ } else if (inoinfo(request)->ino_state != USTATE)
return (0);
+retry:
for (ino = request; ino < maxino; ino++)
if (inoinfo(ino)->ino_state == USTATE)
break;
- if (ino == maxino)
+ if (ino >= maxino)
return (0);
cg = ino_to_cg(&sblock, ino);
cgbp = cglookup(cg);
cgp = cgbp->b_un.b_cg;
- if (!check_cgmagic(cg, cgbp, 0))
- return (0);
+ if (!check_cgmagic(cg, cgbp, 0)) {
+ if (anyino == 0)
+ return (0);
+ request = (cg + 1) * sblock.fs_ipg;
+ goto retry;
+ }
setbit(cg_inosused(cgp), ino % sblock.fs_ipg);
cgp->cg_cs.cs_nifree--;
switch (type & IFMT) {