Skip to content

Commit 1c6051b

Browse files
author
Kent Overstreet
committed
bcachefs: Check for directories with no backpointers
It's legal for regular files to have missing backpointers (due to hardlinks), and fsck should automatically add them, but for directories this is an error that should be flagged. Signed-off-by: Kent Overstreet <[email protected]>
1 parent 260af15 commit 1c6051b

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

fs/bcachefs/fsck.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,6 +1826,21 @@ static int check_dirent_inode_dirent(struct btree_trans *trans,
18261826
if (inode_points_to_dirent(target, d))
18271827
return 0;
18281828

1829+
if (!target->bi_dir &&
1830+
!target->bi_dir_offset) {
1831+
fsck_err_on(S_ISDIR(target->bi_mode),
1832+
trans, inode_dir_missing_backpointer,
1833+
"directory with missing backpointer\n%s",
1834+
(bch2_bkey_val_to_text(&buf, c, d.s_c),
1835+
prt_printf(&buf, "\n "),
1836+
bch2_inode_unpacked_to_text(&buf, target),
1837+
buf.buf));
1838+
1839+
target->bi_dir = d.k->p.inode;
1840+
target->bi_dir_offset = d.k->p.offset;
1841+
return __bch2_fsck_write_inode(trans, target, target_snapshot);
1842+
}
1843+
18291844
if (bch2_inode_should_have_bp(target) &&
18301845
!fsck_err(trans, inode_wrong_backpointer,
18311846
"dirent points to inode that does not point back:\n %s",
@@ -1835,13 +1850,6 @@ static int check_dirent_inode_dirent(struct btree_trans *trans,
18351850
buf.buf)))
18361851
goto err;
18371852

1838-
if (!target->bi_dir &&
1839-
!target->bi_dir_offset) {
1840-
target->bi_dir = d.k->p.inode;
1841-
target->bi_dir_offset = d.k->p.offset;
1842-
return __bch2_fsck_write_inode(trans, target, target_snapshot);
1843-
}
1844-
18451853
struct bkey_s_c_dirent bp_dirent = dirent_get_by_pos(trans, &bp_iter,
18461854
SPOS(target->bi_dir, target->bi_dir_offset, target_snapshot));
18471855
ret = bkey_err(bp_dirent);

fs/bcachefs/sb-errors_format.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ enum bch_fsck_flags {
219219
x(inode_i_sectors_wrong, 204, FSCK_AUTOFIX) \
220220
x(inode_dir_wrong_nlink, 205, FSCK_AUTOFIX) \
221221
x(inode_dir_multiple_links, 206, FSCK_AUTOFIX) \
222+
x(inode_dir_missing_backpointer, 284, FSCK_AUTOFIX) \
222223
x(inode_multiple_links_but_nlink_0, 207, FSCK_AUTOFIX) \
223224
x(inode_wrong_backpointer, 208, FSCK_AUTOFIX) \
224225
x(inode_wrong_nlink, 209, FSCK_AUTOFIX) \
@@ -295,7 +296,7 @@ enum bch_fsck_flags {
295296
x(accounting_key_replicas_devs_unsorted, 280, FSCK_AUTOFIX) \
296297
x(accounting_key_version_0, 282, FSCK_AUTOFIX) \
297298
x(logged_op_but_clean, 283, FSCK_AUTOFIX) \
298-
x(MAX, 284, 0)
299+
x(MAX, 285, 0)
299300

300301
enum bch_sb_error_id {
301302
#define x(t, n, ...) BCH_FSCK_ERR_##t = n,

0 commit comments

Comments
 (0)