Skip to content

Commit c9306a9

Browse files
author
Kent Overstreet
committed
bcachefs: Check for unlinked, non-empty dirs in check_inode()
We want to check for this early so it can be reattached if necessary in check_unreachable_inodes(); better than letting it be deleted and having the children reattached, losing their filenames. Signed-off-by: Kent Overstreet <[email protected]>
1 parent c7da5ee commit c9306a9

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

fs/bcachefs/fsck.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,23 @@ static int check_inode(struct btree_trans *trans,
10831083
do_update = true;
10841084
}
10851085

1086+
if (S_ISDIR(u.bi_mode) && (u.bi_flags & BCH_INODE_unlinked)) {
1087+
/* Check for this early so that check_unreachable_inode() will reattach it */
1088+
1089+
ret = bch2_empty_dir_snapshot(trans, k.k->p.offset, 0, k.k->p.snapshot);
1090+
if (ret && ret != -BCH_ERR_ENOTEMPTY_dir_not_empty)
1091+
goto err;
1092+
1093+
fsck_err_on(ret, trans, inode_dir_unlinked_but_not_empty,
1094+
"dir unlinked but not empty\n%s",
1095+
(printbuf_reset(&buf),
1096+
bch2_inode_unpacked_to_text(&buf, &u),
1097+
buf.buf));
1098+
u.bi_flags &= ~BCH_INODE_unlinked;
1099+
do_update = true;
1100+
ret = 0;
1101+
}
1102+
10861103
if ((u.bi_flags & (BCH_INODE_i_size_dirty|BCH_INODE_unlinked)) &&
10871104
bch2_key_has_snapshot_overwrites(trans, BTREE_ID_inodes, k.k->p)) {
10881105
struct bpos new_min_pos;

fs/bcachefs/sb-errors_format.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ enum bch_fsck_flags {
221221
x(inode_dir_wrong_nlink, 205, FSCK_AUTOFIX) \
222222
x(inode_dir_multiple_links, 206, FSCK_AUTOFIX) \
223223
x(inode_dir_missing_backpointer, 284, FSCK_AUTOFIX) \
224+
x(inode_dir_unlinked_but_not_empty, 286, FSCK_AUTOFIX) \
224225
x(inode_multiple_links_but_nlink_0, 207, FSCK_AUTOFIX) \
225226
x(inode_wrong_backpointer, 208, FSCK_AUTOFIX) \
226227
x(inode_wrong_nlink, 209, FSCK_AUTOFIX) \
@@ -297,7 +298,7 @@ enum bch_fsck_flags {
297298
x(accounting_key_replicas_devs_unsorted, 280, FSCK_AUTOFIX) \
298299
x(accounting_key_version_0, 282, FSCK_AUTOFIX) \
299300
x(logged_op_but_clean, 283, FSCK_AUTOFIX) \
300-
x(MAX, 286, 0)
301+
x(MAX, 287, 0)
301302

302303
enum bch_sb_error_id {
303304
#define x(t, n, ...) BCH_FSCK_ERR_##t = n,

0 commit comments

Comments
 (0)