mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Viacheslav Dubeyko <slava@dubeyko.com>
To: Ozgun Kultekin <ozgunkultekin@gmail.com>,
	glaubitz@physik.fu-berlin.de,  frank.li@vivo.com
Cc: linux-fsdevel@vger.kernel.org, yangguikun19@qq.com,
	stable@vger.kernel.org, 	linux-kernel@vger.kernel.org,
	kovalev@altlinux.org, brauner@kernel.org,
		cengiz.can@canonical.com
Subject: Re: [PATCH v5 3/3] hfs/hfsplus: name the node descriptor size and the first record offset
Date: Tue, 01 Dec 2026 15:16:25 -0800	[thread overview]
Message-ID: <7fc082eba40694435649186517018d7ea5b475a9.camel@dubeyko.com> (raw)
In-Reply-To: <20261201094246.80197-4-ozgunkultekin@gmail.com>

On Tue, 2026-12-01 at 01:42 -0800, Ozgun Kultekin wrote:
> Both drivers spell the size of struct hfs_bnode_desc, which is also
> the
> offset of record 0 in a node, in several ways: the literal 14 in
> brec.c
> and btree.c, a local node_desc_size in hfs_bnode_split() of both
> drivers, local desc_size variables in hfsplus_fs.h, and
> sizeof(struct hfs_bnode_desc) in bnode.c, btree.c and
> hfsplus/xattr.c.
> 
> Add two names next to the structure: HFS_BNODE_DESC_SIZE for the size
> and HFS_BNODE_FIRST_REC_OFF for the offset of record 0, and use them
> everywhere. In hfs_btree_inc_height() keep the offset of the child
> pointer in a local variable and write its length as sizeof(cnid)
> instead of 4. Align the conditions next to the changed lines.
> 
> No functional change.
> 
> Suggested-by: Viacheslav Dubeyko <slava@dubeyko.com>
> Signed-off-by: Ozgun Kultekin <ozgunkultekin@gmail.com>
> ---
> 
> Notes:
>     v5: rebased on the hfs tree for-next branch; hfs_bnode_split() in
> hfs
>         now has the node_desc_size local from "hfs: fix orphaned b-
> tree
>         node in hfs_bnode_split()", converted like the hfsplus one.
>         map_node_bits in hfsplus/xattr.c reordered to
>         (node_size - ...) * 8, as suggested by Viacheslav.
>     v4:
> https://lore.kernel.org/all/20261127045416.1160-4-ozgunkultekin@gmail.com/
>     v3:
> https://lore.kernel.org/all/20261119005943.37851-2-ozgunkultekin@gmail.com/
> 
>  fs/hfs/bnode.c             |  2 +-
>  fs/hfs/brec.c              | 47 ++++++++++++++++++--------------
>  fs/hfs/btree.c             |  9 ++++---
>  fs/hfsplus/bnode.c         |  2 +-
>  fs/hfsplus/brec.c          | 55 +++++++++++++++++++++---------------
> --
>  fs/hfsplus/btree.c         |  9 ++++---
>  fs/hfsplus/hfsplus_fs.h    |  8 +++---
>  fs/hfsplus/xattr.c         |  8 +++---
>  include/linux/hfs_common.h |  6 +++++
>  9 files changed, 83 insertions(+), 63 deletions(-)
> 
> diff --git a/fs/hfs/bnode.c b/fs/hfs/bnode.c
> index f2781afea7..f976e4092a 100644
> --- a/fs/hfs/bnode.c
> +++ b/fs/hfs/bnode.c
> @@ -429,7 +429,7 @@ struct hfs_bnode *hfs_bnode_find(struct hfs_btree
> *tree, u32 num)
>  
>  	rec_off = tree->node_size - 2;
>  	off = hfs_bnode_read_u16(node, rec_off);
> -	if (off != sizeof(struct hfs_bnode_desc))
> +	if (off != HFS_BNODE_FIRST_REC_OFF)
>  		goto node_error;
>  	for (i = 1; i <= node->num_recs; off = next_off, i++) {
>  		rec_off -= 2;
> diff --git a/fs/hfs/brec.c b/fs/hfs/brec.c
> index 15520b2b15..d6ba3722ec 100644
> --- a/fs/hfs/brec.c
> +++ b/fs/hfs/brec.c
> @@ -157,8 +157,8 @@ int hfs_brec_insert(struct hfs_find_data *fd,
> void *entry, u32 entry_len)
>  		entry_len = sizeof(cnid);
>  
>  		/* get index key */
> -		hfs_bnode_read_key(new_node, fd->search_key, 14,
> -				   fd->key_capacity);
> +		hfs_bnode_read_key(new_node, fd->search_key,
> +				   HFS_BNODE_FIRST_REC_OFF, fd-
> >key_capacity);
>  		__hfs_brec_find(fd->bnode, fd);
>  
>  		hfs_bnode_put(new_node);
> @@ -257,7 +257,6 @@ static struct hfs_bnode *hfs_bnode_split(struct
> hfs_find_data *fd)
>  	int num_recs, new_rec_off, new_off, old_rec_off;
>  	int data_start, data_end, size;
>  	size_t rec_off_tbl_size;
> -	size_t node_desc_size = sizeof(struct hfs_bnode_desc);
>  	size_t rec_size = sizeof(__be16);
>  
>  	tree = fd->tree;
> @@ -287,7 +286,7 @@ static struct hfs_bnode *hfs_bnode_split(struct
> hfs_find_data *fd)
>  
>  	rec_off_tbl_size = node->num_recs * rec_size;
>  	size = tree->node_size / 2;
> -	size -= node_desc_size;
> +	size -= HFS_BNODE_DESC_SIZE;
>  	size -= rec_off_tbl_size;
>  	old_rec_off = tree->node_size - (2 * rec_size);
>  
> @@ -319,14 +318,14 @@ static struct hfs_bnode *hfs_bnode_split(struct
> hfs_find_data *fd)
>  		hfs_bnode_get(new_node);
>  		fd->bnode = new_node;
>  		fd->record -= num_recs;
> -		fd->keyoffset -= data_start - node_desc_size;
> -		fd->entryoffset -= data_start - node_desc_size;
> +		fd->keyoffset -= data_start -
> HFS_BNODE_FIRST_REC_OFF;
> +		fd->entryoffset -= data_start -
> HFS_BNODE_FIRST_REC_OFF;
>  	}
>  	new_node->num_recs = node->num_recs - num_recs;
>  	node->num_recs = num_recs;
>  
>  	new_rec_off = tree->node_size - rec_size;
> -	new_off = node_desc_size;
> +	new_off = HFS_BNODE_FIRST_REC_OFF;
>  	size = data_start - new_off;
>  	num_recs = new_node->num_recs;
>  	data_end = data_start;
> @@ -339,8 +338,8 @@ static struct hfs_bnode *hfs_bnode_split(struct
> hfs_find_data *fd)
>  		num_recs--;
>  	}
>  	hfs_bnode_write_u16(new_node, new_rec_off, new_off);
> -	hfs_bnode_copy(new_node, node_desc_size,
> -			node, data_start, data_end - data_start);
> +	hfs_bnode_copy(new_node, HFS_BNODE_FIRST_REC_OFF,
> +		       node, data_start, data_end - data_start);
>  
>  	/* update new bnode header */
>  	node_desc.next = cpu_to_be32(new_node->next);
> @@ -404,7 +403,8 @@ static int hfs_brec_update_parent(struct
> hfs_find_data *fd)
>  
>  	/* size difference between old and new key */
>  	if (tree->attributes & HFS_TREE_VARIDXKEYS)
> -		newkeylen = (hfs_bnode_read_u8(node, 14) | 1) + 1;
> +		newkeylen =
> +			(hfs_bnode_read_u8(node,
> HFS_BNODE_FIRST_REC_OFF) | 1) + 1;
>  	else
>  		fd->keylength = newkeylen = tree->max_key_len + 1;

We need to use key_capacity here. Am I right? Please, rework it.

>  	hfs_dbg("rec %d, keylength %d, newkeylen %d\n",
> @@ -443,7 +443,8 @@ static int hfs_brec_update_parent(struct
> hfs_find_data *fd)
>  	hfs_bnode_move(parent, start_off + diff, start_off,
>  		       end_off - start_off);
>  skip:
> -	hfs_bnode_copy(parent, fd->keyoffset, node, 14, newkeylen);
> +	hfs_bnode_copy(parent, fd->keyoffset, node,
> HFS_BNODE_FIRST_REC_OFF,
> +		       newkeylen);
>  	if (!(tree->attributes & HFS_TREE_VARIDXKEYS))
>  		hfs_bnode_write_u8(parent, fd->keyoffset, newkeylen
> - 1);
>  	hfs_bnode_dump(parent);
> @@ -460,8 +461,8 @@ static int hfs_brec_update_parent(struct
> hfs_find_data *fd)
>  		}
>  		fd->bnode = hfs_bnode_find(tree, new_node->parent);
>  		/* create index key and entry */
> -		hfs_bnode_read_key(new_node, fd->search_key, 14,
> -				   fd->key_capacity);
> +		hfs_bnode_read_key(new_node, fd->search_key,
> +				   HFS_BNODE_FIRST_REC_OFF, fd-
> >key_capacity);
>  		cnid = cpu_to_be32(new_node->this);
>  
>  		__hfs_brec_find(fd->bnode, fd);
> @@ -473,7 +474,8 @@ static int hfs_brec_update_parent(struct
> hfs_find_data *fd)
>  			if (new_node == node)
>  				goto out;
>  			/* restore search_key */
> -			hfs_bnode_read_key(node, fd->search_key, 14,
> +			hfs_bnode_read_key(node, fd->search_key,
> +					   HFS_BNODE_FIRST_REC_OFF,
>  					   fd->key_capacity);
>  		}
>  		new_node = NULL;
> @@ -491,6 +493,7 @@ static int hfs_btree_inc_height(struct hfs_btree
> *tree)
>  	struct hfs_bnode *node, *new_node;
>  	struct hfs_bnode_desc node_desc;
>  	int key_size, rec;
> +	u32 cnid_off;
>  	__be32 cnid;
>  
>  	node = NULL;
> @@ -528,28 +531,32 @@ static int hfs_btree_inc_height(struct
> hfs_btree *tree)
>  	hfs_bnode_write(new_node, &node_desc, 0, sizeof(node_desc));
>  
>  	rec = tree->node_size - 2;
> -	hfs_bnode_write_u16(new_node, rec, 14);
> +	hfs_bnode_write_u16(new_node, rec, HFS_BNODE_FIRST_REC_OFF);
>  
>  	if (node) {
>  		/* insert old root idx into new root */
>  		node->parent = tree->root;
>  		if (node->type == HFS_NODE_LEAF ||
>  		    tree->attributes & HFS_TREE_VARIDXKEYS)
> -			key_size = hfs_bnode_read_u8(node, 14) + 1;
> +			key_size =
> +				hfs_bnode_read_u8(node,
> HFS_BNODE_FIRST_REC_OFF) + 1;
>  		else
>  			key_size = tree->max_key_len + 1;

Ditto. We need to use key_capacity here. Am I right? Please, rework it.

> -		hfs_bnode_copy(new_node, 14, node, 14, key_size);
> +		hfs_bnode_copy(new_node, HFS_BNODE_FIRST_REC_OFF,
> +			       node, HFS_BNODE_FIRST_REC_OFF,
> key_size);
>  
>  		if (!(tree->attributes & HFS_TREE_VARIDXKEYS)) {
>  			key_size = tree->max_key_len + 1;
> -			hfs_bnode_write_u8(new_node, 14, tree-
> >max_key_len);
> +			hfs_bnode_write_u8(new_node,
> HFS_BNODE_FIRST_REC_OFF,
> +					   tree->max_key_len);
>  		}
>  		key_size = (key_size + 1) & -2;
>  		cnid = cpu_to_be32(node->this);
> -		hfs_bnode_write(new_node, &cnid, 14 + key_size, 4);
> +		cnid_off = HFS_BNODE_FIRST_REC_OFF + key_size;
> +		hfs_bnode_write(new_node, &cnid, cnid_off,
> sizeof(cnid));
>  
>  		rec -= 2;
> -		hfs_bnode_write_u16(new_node, rec, 14 + key_size +
> 4);
> +		hfs_bnode_write_u16(new_node, rec, cnid_off +
> sizeof(cnid));
>  
>  		hfs_bnode_put(node);
>  	}
> diff --git a/fs/hfs/btree.c b/fs/hfs/btree.c
> index f070384031..c3cd94f219 100644
> --- a/fs/hfs/btree.c
> +++ b/fs/hfs/btree.c
> @@ -216,7 +216,7 @@ struct hfs_btree *hfs_btree_open(struct
> super_block *sb, u32 id, btree_keycmp ke
>  
>  	/* Load the header */
>  	head = (struct hfs_btree_header_rec
> *)(kmap_local_folio(folio, 0) +
> -					       sizeof(struct
> hfs_bnode_desc));
> +					      
> HFS_BNODE_FIRST_REC_OFF);
>  	tree->root = be32_to_cpu(head->root);
>  	tree->leaf_count = be32_to_cpu(head->leaf_count);
>  	tree->leaf_head = be32_to_cpu(head->leaf_head);
> @@ -312,7 +312,7 @@ void hfs_btree_write(struct hfs_btree *tree)
>  	/* Load the header */
>  	page = node->page[0];
>  	head = (struct hfs_btree_header_rec *)(kmap_local_page(page)
> +
> -					       sizeof(struct
> hfs_bnode_desc));
> +					      
> HFS_BNODE_FIRST_REC_OFF);
>  
>  	head->root = cpu_to_be32(tree->root);
>  	head->leaf_count = cpu_to_be32(tree->leaf_count);
> @@ -356,8 +356,9 @@ static struct hfs_bnode *hfs_bmap_new_bmap(struct
> hfs_bnode *prev, u32 idx)
>  	desc.num_recs = cpu_to_be16(1);
>  	desc.reserved = 0;
>  	hfs_bnode_write(node, &desc, 0, sizeof(desc));
> -	hfs_bnode_write_u16(node, 14, 0x8000);
> -	hfs_bnode_write_u16(node, tree->node_size - 2, 14);
> +	hfs_bnode_write_u16(node, HFS_BNODE_FIRST_REC_OFF, 0x8000);
> +	hfs_bnode_write_u16(node, tree->node_size - 2,
> +			    HFS_BNODE_FIRST_REC_OFF);
>  	hfs_bnode_write_u16(node, tree->node_size - 4, tree-
> >node_size - 6);
>  
>  	return node;
> diff --git a/fs/hfsplus/bnode.c b/fs/hfsplus/bnode.c
> index 144348bdbf..d91714e97b 100644
> --- a/fs/hfsplus/bnode.c
> +++ b/fs/hfsplus/bnode.c
> @@ -592,7 +592,7 @@ struct hfs_bnode *hfs_bnode_find(struct hfs_btree
> *tree, u32 num)
>  
>  	rec_off = tree->node_size - 2;
>  	off = hfs_bnode_read_u16(node, rec_off);
> -	if (off != sizeof(struct hfs_bnode_desc))
> +	if (off != HFS_BNODE_FIRST_REC_OFF)
>  		goto node_error;
>  	for (i = 1; i <= node->num_recs; off = next_off, i++) {
>  		rec_off -= 2;
> diff --git a/fs/hfsplus/brec.c b/fs/hfsplus/brec.c
> index c9fb6873ac..c56ca7a852 100644
> --- a/fs/hfsplus/brec.c
> +++ b/fs/hfsplus/brec.c
> @@ -167,8 +167,8 @@ int hfs_brec_insert(struct hfs_find_data *fd,
> void *entry, u32 entry_len)
>  		entry_len = sizeof(cnid);
>  
>  		/* get index key */
> -		hfs_bnode_read_key(new_node, fd->search_key, 14,
> -				   fd->key_capacity);
> +		hfs_bnode_read_key(new_node, fd->search_key,
> +				   HFS_BNODE_FIRST_REC_OFF, fd-
> >key_capacity);
>  		__hfs_brec_find(fd->bnode, fd, hfs_find_rec_by_key);
>  
>  		hfs_bnode_put(new_node);
> @@ -260,7 +260,6 @@ static struct hfs_bnode *hfs_bnode_split(struct
> hfs_find_data *fd)
>  	int num_recs, new_rec_off, new_off, old_rec_off;
>  	int data_start, data_end, size;
>  	size_t rec_off_tbl_size;
> -	size_t node_desc_size = sizeof(struct hfs_bnode_desc);
>  	size_t rec_size = sizeof(__be16);
>  
>  	tree = fd->tree;
> @@ -290,7 +289,7 @@ static struct hfs_bnode *hfs_bnode_split(struct
> hfs_find_data *fd)
>  
>  	rec_off_tbl_size = node->num_recs * rec_size;
>  	size = tree->node_size / 2;
> -	size -= node_desc_size;
> +	size -= HFS_BNODE_DESC_SIZE;
>  	size -= rec_off_tbl_size;
>  	old_rec_off = tree->node_size - (2 * rec_size);
>  
> @@ -322,14 +321,14 @@ static struct hfs_bnode *hfs_bnode_split(struct
> hfs_find_data *fd)
>  		hfs_bnode_get(new_node);
>  		fd->bnode = new_node;
>  		fd->record -= num_recs;
> -		fd->keyoffset -= data_start - node_desc_size;
> -		fd->entryoffset -= data_start - node_desc_size;
> +		fd->keyoffset -= data_start -
> HFS_BNODE_FIRST_REC_OFF;
> +		fd->entryoffset -= data_start -
> HFS_BNODE_FIRST_REC_OFF;
>  	}
>  	new_node->num_recs = node->num_recs - num_recs;
>  	node->num_recs = num_recs;
>  
>  	new_rec_off = tree->node_size - rec_size;
> -	new_off = node_desc_size;
> +	new_off = HFS_BNODE_FIRST_REC_OFF;
>  	size = data_start - new_off;
>  	num_recs = new_node->num_recs;
>  	data_end = data_start;
> @@ -342,8 +341,8 @@ static struct hfs_bnode *hfs_bnode_split(struct
> hfs_find_data *fd)
>  		num_recs--;
>  	}
>  	hfs_bnode_write_u16(new_node, new_rec_off, new_off);
> -	hfs_bnode_copy(new_node, node_desc_size,
> -			node, data_start, data_end - data_start);
> +	hfs_bnode_copy(new_node, HFS_BNODE_FIRST_REC_OFF,
> +		       node, data_start, data_end - data_start);
>  
>  	/* update new bnode header */
>  	node_desc.next = cpu_to_be32(new_node->next);
> @@ -410,8 +409,9 @@ static int hfs_brec_update_parent(struct
> hfs_find_data *fd)
>  
>  	/* size difference between old and new key */
>  	if ((tree->attributes & HFS_TREE_VARIDXKEYS) ||
> -				(tree->cnid == HFSPLUS_ATTR_CNID))
> -		newkeylen = hfs_bnode_read_u16(node, 14) + 2;
> +	    (tree->cnid == HFSPLUS_ATTR_CNID))
> +		newkeylen =
> +			hfs_bnode_read_u16(node,
> HFS_BNODE_FIRST_REC_OFF) + 2;
>  	else
>  		fd->keylength = newkeylen = tree->max_key_len + 2;

Ditto. We need to use key_capacity here. Am I right? Please, rework it.

>  	hfs_dbg("rec %d, keylength %d, newkeylen %d\n",
> @@ -451,7 +451,8 @@ static int hfs_brec_update_parent(struct
> hfs_find_data *fd)
>  	hfs_bnode_move(parent, start_off + diff, start_off,
>  		       end_off - start_off);
>  skip:
> -	hfs_bnode_copy(parent, fd->keyoffset, node, 14, newkeylen);
> +	hfs_bnode_copy(parent, fd->keyoffset, node,
> HFS_BNODE_FIRST_REC_OFF,
> +		       newkeylen);
>  	hfs_bnode_dump(parent);
>  
>  	hfs_bnode_put(node);
> @@ -466,8 +467,8 @@ static int hfs_brec_update_parent(struct
> hfs_find_data *fd)
>  		}
>  		fd->bnode = hfs_bnode_find(tree, new_node->parent);
>  		/* create index key and entry */
> -		hfs_bnode_read_key(new_node, fd->search_key, 14,
> -				   fd->key_capacity);
> +		hfs_bnode_read_key(new_node, fd->search_key,
> +				   HFS_BNODE_FIRST_REC_OFF, fd-
> >key_capacity);
>  		cnid = cpu_to_be32(new_node->this);
>  
>  		__hfs_brec_find(fd->bnode, fd, hfs_find_rec_by_key);
> @@ -479,7 +480,8 @@ static int hfs_brec_update_parent(struct
> hfs_find_data *fd)
>  			if (new_node == node)
>  				goto out;
>  			/* restore search_key */
> -			hfs_bnode_read_key(node, fd->search_key, 14,
> +			hfs_bnode_read_key(node, fd->search_key,
> +					   HFS_BNODE_FIRST_REC_OFF,
>  					   fd->key_capacity);
>  		}
>  		new_node = NULL;
> @@ -497,6 +499,7 @@ static int hfs_btree_inc_height(struct hfs_btree
> *tree)
>  	struct hfs_bnode *node, *new_node;
>  	struct hfs_bnode_desc node_desc;
>  	int key_size, rec;
> +	u32 cnid_off;
>  	__be32 cnid;
>  
>  	node = NULL;
> @@ -534,29 +537,33 @@ static int hfs_btree_inc_height(struct
> hfs_btree *tree)
>  	hfs_bnode_write(new_node, &node_desc, 0, sizeof(node_desc));
>  
>  	rec = tree->node_size - 2;
> -	hfs_bnode_write_u16(new_node, rec, 14);
> +	hfs_bnode_write_u16(new_node, rec, HFS_BNODE_FIRST_REC_OFF);
>  
>  	if (node) {
>  		/* insert old root idx into new root */
>  		node->parent = tree->root;
>  		if (node->type == HFS_NODE_LEAF ||
> -				tree->attributes &
> HFS_TREE_VARIDXKEYS ||
> -				tree->cnid == HFSPLUS_ATTR_CNID)
> -			key_size = hfs_bnode_read_u16(node, 14) + 2;
> +		    tree->attributes & HFS_TREE_VARIDXKEYS ||
> +		    tree->cnid == HFSPLUS_ATTR_CNID)
> +			key_size =
> +				hfs_bnode_read_u16(node,
> HFS_BNODE_FIRST_REC_OFF) + 2;
>  		else
>  			key_size = tree->max_key_len + 2;

Ditto. We need to use key_capacity here. Am I right? Please, rework it.

Thanks,
Slava.

> -		hfs_bnode_copy(new_node, 14, node, 14, key_size);
> +		hfs_bnode_copy(new_node, HFS_BNODE_FIRST_REC_OFF,
> +			       node, HFS_BNODE_FIRST_REC_OFF,
> key_size);
>  
>  		if (!(tree->attributes & HFS_TREE_VARIDXKEYS) &&
> -				(tree->cnid != HFSPLUS_ATTR_CNID)) {
> +		    (tree->cnid != HFSPLUS_ATTR_CNID)) {
>  			key_size = tree->max_key_len + 2;
> -			hfs_bnode_write_u16(new_node, 14, tree-
> >max_key_len);
> +			hfs_bnode_write_u16(new_node,
> HFS_BNODE_FIRST_REC_OFF,
> +					    tree->max_key_len);
>  		}
>  		cnid = cpu_to_be32(node->this);
> -		hfs_bnode_write(new_node, &cnid, 14 + key_size, 4);
> +		cnid_off = HFS_BNODE_FIRST_REC_OFF + key_size;
> +		hfs_bnode_write(new_node, &cnid, cnid_off,
> sizeof(cnid));
>  
>  		rec -= 2;
> -		hfs_bnode_write_u16(new_node, rec, 14 + key_size +
> 4);
> +		hfs_bnode_write_u16(new_node, rec, cnid_off +
> sizeof(cnid));
>  
>  		hfs_bnode_put(node);
>  	}
> diff --git a/fs/hfsplus/btree.c b/fs/hfsplus/btree.c
> index 0a9b32d5c5..c42f655e71 100644
> --- a/fs/hfsplus/btree.c
> +++ b/fs/hfsplus/btree.c
> @@ -322,7 +322,7 @@ struct hfs_btree *hfs_btree_open(struct
> super_block *sb, u32 id)
>  
>  	/* Load the header */
>  	head = (struct hfs_btree_header_rec *)(kmap_local_page(page)
> +
> -		sizeof(struct hfs_bnode_desc));
> +		HFS_BNODE_FIRST_REC_OFF);
>  	tree->root = be32_to_cpu(head->root);
>  	tree->leaf_count = be32_to_cpu(head->leaf_count);
>  	tree->leaf_head = be32_to_cpu(head->leaf_head);
> @@ -454,7 +454,7 @@ int hfs_btree_write(struct hfs_btree *tree)
>  	/* Load the header */
>  	page = node->page[0];
>  	head = (struct hfs_btree_header_rec *)(kmap_local_page(page)
> +
> -		sizeof(struct hfs_bnode_desc));
> +		HFS_BNODE_FIRST_REC_OFF);
>  
>  	head->root = cpu_to_be32(tree->root);
>  	head->leaf_count = cpu_to_be32(tree->leaf_count);
> @@ -497,8 +497,9 @@ static struct hfs_bnode *hfs_bmap_new_bmap(struct
> hfs_bnode *prev, u32 idx)
>  	desc.num_recs = cpu_to_be16(1);
>  	desc.reserved = 0;
>  	hfs_bnode_write(node, &desc, 0, sizeof(desc));
> -	hfs_bnode_write_u16(node, 14, 0x8000);
> -	hfs_bnode_write_u16(node, tree->node_size - 2, 14);
> +	hfs_bnode_write_u16(node, HFS_BNODE_FIRST_REC_OFF, 0x8000);
> +	hfs_bnode_write_u16(node, tree->node_size - 2,
> +			    HFS_BNODE_FIRST_REC_OFF);
>  	hfs_bnode_write_u16(node, tree->node_size - 4, tree-
> >node_size - 6);
>  
>  	return node;
> diff --git a/fs/hfsplus/hfsplus_fs.h b/fs/hfsplus/hfsplus_fs.h
> index 3d33f2df0b..43062f056f 100644
> --- a/fs/hfsplus/hfsplus_fs.h
> +++ b/fs/hfsplus/hfsplus_fs.h
> @@ -659,16 +659,15 @@ bool hfs_bnode_num_recs_invalid(struct
> hfs_bnode *node)
>  	u32 table_size;
>  	u32 area_size;
>  	u32 rec_size = sizeof(__be16);
> -	u32 desc_size = sizeof(struct hfs_bnode_desc);
>  
>  	if (!node || !node->tree)
>  		return true;
>  
>  	node_size = node->tree->node_size;
> -	if (node_size < desc_size)
> +	if (node_size < HFS_BNODE_DESC_SIZE)
>  		return true;
>  
> -	area_size = node_size - desc_size;
> +	area_size = node_size - HFS_BNODE_DESC_SIZE;
>  	table_size = ((u32)node->num_recs + 1) * rec_size;
>  
>  	return table_size > area_size;
> @@ -691,12 +690,11 @@ bool hfs_brec_offsets_invalid(struct hfs_bnode
> *node, u16 off, u16 next_off)
>  	u32 table_size;
>  	u32 table_start;
>  	u32 rec_size = sizeof(__be16);
> -	u32 desc_size = sizeof(struct hfs_bnode_desc);
>  
>  	if (!node || !node->tree)
>  		return true;
>  
> -	if (off < desc_size || (off & 1))
> +	if (off < HFS_BNODE_FIRST_REC_OFF || (off & 1))
>  		return true;
>  
>  	if (next_off <= off ||
> diff --git a/fs/hfsplus/xattr.c b/fs/hfsplus/xattr.c
> index 3aeca4d177..37e04fa253 100644
> --- a/fs/hfsplus/xattr.c
> +++ b/fs/hfsplus/xattr.c
> @@ -80,7 +80,7 @@ static u32 hfsplus_init_header_node(struct inode
> *attr_file,
>  	desc = (struct hfs_bnode_desc *)buf;
>  	desc->type = HFS_NODE_HEADER;
>  	desc->num_recs =
> cpu_to_be16(HFSPLUS_BTREE_HDR_NODE_RECS_COUNT);
> -	offset = sizeof(struct hfs_bnode_desc);
> +	offset = HFS_BNODE_FIRST_REC_OFF;
>  	*--rec_offsets = cpu_to_be16(offset);
>  
>  	head = (struct hfs_btree_header_rec *)(buf + offset);
> @@ -102,8 +102,8 @@ static u32 hfsplus_init_header_node(struct inode
> *attr_file,
>  		u32 map_node_bits;
>  
>  		desc->next = cpu_to_be32(be32_to_cpu(head-
> >leaf_tail) + 1);
> -		map_node_bits = 8 * (node_size - sizeof(struct
> hfs_bnode_desc) -
> -					(2 * sizeof(u16)) - 2);
> +		map_node_bits = (node_size - HFS_BNODE_DESC_SIZE -
> +				 (sizeof(u16) * 2) - 2) * 8;
>  		map_nodes = (be32_to_cpu(head->node_count) -
>  				hdr_node_map_rec_bits +
>  				(map_node_bits - 1)) /
> map_node_bits;
> @@ -163,7 +163,7 @@ static void hfsplus_init_map_node(u8 *buf, u16
> node_size, u32 next_node)
>  	rec_offsets = (__be16 *)(buf + node_size);
>  
>  	/* record #1 */
> -	offset = sizeof(struct hfs_bnode_desc);
> +	offset = HFS_BNODE_FIRST_REC_OFF;
>  	*--rec_offsets = cpu_to_be16(offset);
>  
>  	/* record #2 */
> diff --git a/include/linux/hfs_common.h b/include/linux/hfs_common.h
> index eb119a1c56..10324627f9 100644
> --- a/include/linux/hfs_common.h
> +++ b/include/linux/hfs_common.h
> @@ -495,6 +495,12 @@ struct hfs_bnode_desc {
>  	u16 reserved;
>  } __packed;
>  
> +/* Size of the node descriptor at the start of every node */
> +#define HFS_BNODE_DESC_SIZE	sizeof(struct hfs_bnode_desc)
> +
> +/* Offset of record 0, which follows the node descriptor */
> +#define HFS_BNODE_FIRST_REC_OFF	HFS_BNODE_DESC_SIZE
> +
>  /* HFS/HFS+ BTree node types */
>  #define HFS_NODE_INDEX	0x00	/* An internal (index) node */
>  #define HFS_NODE_HEADER	0x01	/* The tree header node
> (node 0) */

      reply	other threads:[~2026-12-01 23:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20261127045416.1160-1-ozgunkultekin@gmail.com>
2026-12-01  9:42 ` [PATCH v5 0/3] hfs/hfsplus: pass the key buffer size to hfs_bnode_read_key() Ozgun Kultekin
2026-12-01  9:42   ` [PATCH v5 1/3] hfsplus: " Ozgun Kultekin
2026-12-01 23:08     ` Viacheslav Dubeyko
2026-12-01  9:42   ` [PATCH v5 2/3] hfs: " Ozgun Kultekin
2026-12-01 23:10     ` Viacheslav Dubeyko
2026-12-01  9:42   ` [PATCH v5 3/3] hfs/hfsplus: name the node descriptor size and the first record offset Ozgun Kultekin
2026-12-01 23:16     ` Viacheslav Dubeyko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7fc082eba40694435649186517018d7ea5b475a9.camel@dubeyko.com \
    --to=slava@dubeyko.com \
    --cc=brauner@kernel.org \
    --cc=cengiz.can@canonical.com \
    --cc=frank.li@vivo.com \
    --cc=glaubitz@physik.fu-berlin.de \
    --cc=kovalev@altlinux.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ozgunkultekin@gmail.com \
    --cc=stable@vger.kernel.org \
    --cc=yangguikun19@qq.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®