From: Joshua Ashton Date: Sun, 13 Aug 2023 16:49:12 +0000 (+0100) Subject: bcachefs: Split out dirent alloc and name initialization X-Git-Tag: v6.15-rc1~146^2~90 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=76872d46b7fa8b6dc8303de4ed45a9ac6ed92f91;p=thirdparty%2Flinux.git bcachefs: Split out dirent alloc and name initialization Splits out the code that allocates the dirent and initializes the name to make things easier to implement casefolding in a future commit. Cc: André Almeida Cc: Gabriel Krisman Bertazi Signed-off-by: Joshua Ashton Signed-off-by: Kent Overstreet --- diff --git a/fs/bcachefs/dirent.c b/fs/bcachefs/dirent.c index 27737aaa03a64..7dcc180007268 100644 --- a/fs/bcachefs/dirent.c +++ b/fs/bcachefs/dirent.c @@ -163,15 +163,13 @@ void bch2_dirent_to_text(struct printbuf *out, struct bch_fs *c, struct bkey_s_c prt_printf(out, " type %s", bch2_d_type_str(d.v->d_type)); } -static struct bkey_i_dirent *dirent_create_key(struct btree_trans *trans, - subvol_inum dir, u8 type, - const struct qstr *name, u64 dst) +static struct bkey_i_dirent *dirent_alloc_key(struct btree_trans *trans, + subvol_inum dir, + u8 type, + int name_len, u64 dst) { struct bkey_i_dirent *dirent; - unsigned u64s = BKEY_U64s + dirent_val_u64s(name->len); - - if (name->len > BCH_NAME_MAX) - return ERR_PTR(-ENAMETOOLONG); + unsigned u64s = BKEY_U64s + dirent_val_u64s(name_len); BUG_ON(u64s > U8_MAX); @@ -191,11 +189,35 @@ static struct bkey_i_dirent *dirent_create_key(struct btree_trans *trans, dirent->v.d_type = type; - memcpy(dirent->v.d_name, name->name, name->len); - memset(dirent->v.d_name + name->len, 0, - bkey_val_bytes(&dirent->k) - - offsetof(struct bch_dirent, d_name) - - name->len); + return dirent; +} + +static void dirent_init_regular_name(struct bkey_i_dirent *dirent, + const struct qstr *name) +{ + memcpy(&dirent->v.d_name[0], name->name, name->len); + memset(&dirent->v.d_name[name->len], 0, + bkey_val_bytes(&dirent->k) - + offsetof(struct bch_dirent, d_name) - + name->len); +} + +static struct bkey_i_dirent *dirent_create_key(struct btree_trans *trans, + subvol_inum dir, + u8 type, + const struct qstr *name, + u64 dst) +{ + struct bkey_i_dirent *dirent; + + if (name->len > BCH_NAME_MAX) + return ERR_PTR(-ENAMETOOLONG); + + dirent = dirent_alloc_key(trans, dir, type, name->len, dst); + if (IS_ERR(dirent)) + return dirent; + + dirent_init_regular_name(dirent, name); EBUG_ON(bch2_dirent_name_bytes(dirent_i_to_s_c(dirent)) != name->len);