summaryrefslogtreecommitdiff
path: root/libbcachefs/dirent.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbcachefs/dirent.c')
-rw-r--r--libbcachefs/dirent.c72
1 files changed, 25 insertions, 47 deletions
diff --git a/libbcachefs/dirent.c b/libbcachefs/dirent.c
index 3ec0b4c5..9a400085 100644
--- a/libbcachefs/dirent.c
+++ b/libbcachefs/dirent.c
@@ -64,8 +64,7 @@ static bool dirent_cmp_bkey(struct bkey_s_c _l, struct bkey_s_c _r)
const struct bch_hash_desc bch2_dirent_hash_desc = {
.btree_id = BTREE_ID_DIRENTS,
- .key_type = BCH_DIRENT,
- .whiteout_type = BCH_DIRENT_WHITEOUT,
+ .key_type = KEY_TYPE_dirent,
.hash_key = dirent_hash_key,
.hash_bkey = dirent_hash_bkey,
.cmp_key = dirent_cmp_key,
@@ -74,58 +73,37 @@ const struct bch_hash_desc bch2_dirent_hash_desc = {
const char *bch2_dirent_invalid(const struct bch_fs *c, struct bkey_s_c k)
{
- struct bkey_s_c_dirent d;
+ struct bkey_s_c_dirent d = bkey_s_c_to_dirent(k);
unsigned len;
- switch (k.k->type) {
- case BCH_DIRENT:
- if (bkey_val_bytes(k.k) < sizeof(struct bch_dirent))
- return "value too small";
-
- d = bkey_s_c_to_dirent(k);
- len = bch2_dirent_name_bytes(d);
-
- if (!len)
- return "empty name";
+ if (bkey_val_bytes(k.k) < sizeof(struct bch_dirent))
+ return "value too small";
- /*
- * older versions of bcachefs were buggy and creating dirent
- * keys that were bigger than necessary:
- */
- if (bkey_val_u64s(k.k) > dirent_val_u64s(len + 7))
- return "value too big";
+ len = bch2_dirent_name_bytes(d);
+ if (!len)
+ return "empty name";
- if (len > BCH_NAME_MAX)
- return "dirent name too big";
+ /*
+ * older versions of bcachefs were buggy and creating dirent
+ * keys that were bigger than necessary:
+ */
+ if (bkey_val_u64s(k.k) > dirent_val_u64s(len + 7))
+ return "value too big";
- return NULL;
- case BCH_DIRENT_WHITEOUT:
- return bkey_val_bytes(k.k) != 0
- ? "value size should be zero"
- : NULL;
+ if (len > BCH_NAME_MAX)
+ return "dirent name too big";
- default:
- return "invalid type";
- }
+ return NULL;
}
void bch2_dirent_to_text(struct printbuf *out, struct bch_fs *c,
struct bkey_s_c k)
{
- struct bkey_s_c_dirent d;
-
- switch (k.k->type) {
- case BCH_DIRENT:
- d = bkey_s_c_to_dirent(k);
-
- bch_scnmemcpy(out, d.v->d_name,
- bch2_dirent_name_bytes(d));
- pr_buf(out, " -> %llu", d.v->d_inum);
- break;
- case BCH_DIRENT_WHITEOUT:
- pr_buf(out, "whiteout");
- break;
- }
+ struct bkey_s_c_dirent d = bkey_s_c_to_dirent(k);
+
+ bch_scnmemcpy(out, d.v->d_name,
+ bch2_dirent_name_bytes(d));
+ pr_buf(out, " -> %llu", d.v->d_inum);
}
static struct bkey_i_dirent *dirent_create_key(struct btree_trans *trans,
@@ -286,7 +264,7 @@ int bch2_dirent_rename(struct btree_trans *trans,
* overwrite old_dst - just make sure to use a
* whiteout when deleting src:
*/
- new_src->k.type = BCH_DIRENT_WHITEOUT;
+ new_src->k.type = KEY_TYPE_whiteout;
}
} else {
/* Check if we need a whiteout to delete src: */
@@ -297,7 +275,7 @@ int bch2_dirent_rename(struct btree_trans *trans,
return ret;
if (ret)
- new_src->k.type = BCH_DIRENT_WHITEOUT;
+ new_src->k.type = KEY_TYPE_whiteout;
}
}
@@ -360,7 +338,7 @@ int bch2_empty_dir(struct bch_fs *c, u64 dir_inum)
if (k.k->p.inode > dir_inum)
break;
- if (k.k->type == BCH_DIRENT) {
+ if (k.k->type == KEY_TYPE_dirent) {
ret = -ENOTEMPTY;
break;
}
@@ -384,7 +362,7 @@ int bch2_readdir(struct bch_fs *c, struct file *file,
for_each_btree_key(&iter, c, BTREE_ID_DIRENTS,
POS(inode->v.i_ino, ctx->pos), 0, k) {
- if (k.k->type != BCH_DIRENT)
+ if (k.k->type != KEY_TYPE_dirent)
continue;
dirent = bkey_s_c_to_dirent(k);