Skip to content

Commit 010c894

Browse files
author
Kent Overstreet
committed
bcachefs: Check for casefolded dirents in non casefolded dirs
Check for mismatches between casefold dirents and casefold directories. A mismatch will cause lookups to fail, as we'll be doing the lookup with the casefolded name, which won't match the non-casefolded dirent, and vice versa. Reported-by: Christopher Snowhill <[email protected]> Signed-off-by: Kent Overstreet <[email protected]>
1 parent ecd76c5 commit 010c894

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

fs/bcachefs/fsck.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2190,6 +2190,41 @@ static int check_dirent(struct btree_trans *trans, struct btree_iter *iter,
21902190

21912191
struct bkey_s_c_dirent d = bkey_s_c_to_dirent(k);
21922192

2193+
/* check casefold */
2194+
if (fsck_err_on(d.v->d_casefold != !!hash_info->cf_encoding,
2195+
trans, dirent_casefold_mismatch,
2196+
"dirent casefold does not match dir casefold\n%s",
2197+
(printbuf_reset(&buf),
2198+
bch2_bkey_val_to_text(&buf, c, k),
2199+
buf.buf))) {
2200+
struct qstr name = bch2_dirent_get_name(d);
2201+
u32 subvol = d.v->d_type == DT_SUBVOL
2202+
? d.v->d_parent_subvol
2203+
: 0;
2204+
u64 target = d.v->d_type == DT_SUBVOL
2205+
? d.v->d_child_subvol
2206+
: d.v->d_inum;
2207+
u64 dir_offset;
2208+
2209+
ret = bch2_hash_delete_at(trans,
2210+
bch2_dirent_hash_desc, hash_info, iter,
2211+
BTREE_UPDATE_internal_snapshot_node) ?:
2212+
bch2_dirent_create_snapshot(trans, subvol,
2213+
d.k->p.inode, d.k->p.snapshot,
2214+
hash_info,
2215+
d.v->d_type,
2216+
&name,
2217+
target,
2218+
&dir_offset,
2219+
BTREE_ITER_with_updates|
2220+
BTREE_UPDATE_internal_snapshot_node|
2221+
STR_HASH_must_create) ?:
2222+
bch2_trans_commit(trans, NULL, NULL, BCH_TRANS_COMMIT_no_enospc);
2223+
2224+
/* might need another check_dirents pass */
2225+
goto out;
2226+
}
2227+
21932228
if (d.v->d_type == DT_SUBVOL) {
21942229
ret = check_dirent_to_subvol(trans, iter, d);
21952230
if (ret)

fs/bcachefs/sb-errors_format.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,15 @@ enum bch_fsck_flags {
209209
x(subvol_to_missing_root, 188, 0) \
210210
x(subvol_root_wrong_bi_subvol, 189, FSCK_AUTOFIX) \
211211
x(bkey_in_missing_snapshot, 190, 0) \
212+
x(bkey_in_deleted_snapshot, 315, 0) \
212213
x(inode_pos_inode_nonzero, 191, 0) \
213214
x(inode_pos_blockdev_range, 192, 0) \
214215
x(inode_alloc_cursor_inode_bad, 301, 0) \
215216
x(inode_unpack_error, 193, 0) \
216217
x(inode_str_hash_invalid, 194, 0) \
217218
x(inode_v3_fields_start_bad, 195, 0) \
218219
x(inode_snapshot_mismatch, 196, 0) \
220+
x(snapshot_key_missing_inode_snapshot, 314, 0) \
219221
x(inode_unlinked_but_clean, 197, 0) \
220222
x(inode_unlinked_but_nlink_nonzero, 198, 0) \
221223
x(inode_unlinked_and_not_open, 281, 0) \
@@ -237,6 +239,8 @@ enum bch_fsck_flags {
237239
x(inode_unreachable, 210, FSCK_AUTOFIX) \
238240
x(inode_journal_seq_in_future, 299, FSCK_AUTOFIX) \
239241
x(inode_i_sectors_underflow, 312, FSCK_AUTOFIX) \
242+
x(inode_has_case_insensitive_not_set, 316, FSCK_AUTOFIX) \
243+
x(inode_parent_has_case_insensitive_not_set, 317, FSCK_AUTOFIX) \
240244
x(vfs_inode_i_blocks_underflow, 311, FSCK_AUTOFIX) \
241245
x(vfs_inode_i_blocks_not_zero_at_truncate, 313, FSCK_AUTOFIX) \
242246
x(deleted_inode_but_clean, 211, FSCK_AUTOFIX) \
@@ -262,6 +266,7 @@ enum bch_fsck_flags {
262266
x(dirent_to_overwritten_inode, 302, 0) \
263267
x(dirent_to_missing_subvol, 230, 0) \
264268
x(dirent_to_itself, 231, 0) \
269+
x(dirent_casefold_mismatch, 318, FSCK_AUTOFIX) \
265270
x(quota_type_invalid, 232, 0) \
266271
x(xattr_val_size_too_small, 233, 0) \
267272
x(xattr_val_size_too_big, 234, 0) \
@@ -301,6 +306,7 @@ enum bch_fsck_flags {
301306
x(btree_ptr_v2_written_0, 268, 0) \
302307
x(subvol_snapshot_bad, 269, 0) \
303308
x(subvol_inode_bad, 270, 0) \
309+
x(subvol_missing, 308, FSCK_AUTOFIX) \
304310
x(alloc_key_stripe_sectors_wrong, 271, FSCK_AUTOFIX) \
305311
x(accounting_mismatch, 272, FSCK_AUTOFIX) \
306312
x(accounting_replicas_not_marked, 273, 0) \
@@ -322,7 +328,7 @@ enum bch_fsck_flags {
322328
x(dirent_stray_data_after_cf_name, 305, 0) \
323329
x(rebalance_work_incorrectly_set, 309, FSCK_AUTOFIX) \
324330
x(rebalance_work_incorrectly_unset, 310, FSCK_AUTOFIX) \
325-
x(MAX, 314, 0)
331+
x(MAX, 319, 0)
326332

327333
enum bch_sb_error_id {
328334
#define x(t, n, ...) BCH_FSCK_ERR_##t = n,

0 commit comments

Comments
 (0)