Re: [PATCH 5/8] rpdfs: add basic file data initialization
Zach Brown <[email protected]> Mon, 27 Apr 2026 15:36:04 -0700
| Newsgroups | dev.linux.lists.rpdfs-devel |
|---|---|
| Message-ID | <[email protected]> |
On Fri, Apr 24, 2026 at 04:05:17PM +0200, Valerie Aurora wrote:
> Initialize the file data root, plus a few simple routines to calculate
> mapping block levels. Rename the field in the inode from "data" to
> "data_root" to avoid confusion with the "data" member of struct
> rpdfs_block_handle.
> +/*
> + * Calculate the index of the block reference for this logical block
> + * within an mapping block at this level (1 = pointers to data blocks).
> + */
> +static u32 calc_ref_ind(u64 lblk, int level)
> +{
> + u32 ind;
> + int i;
> +
> + BUG_ON(level < 1);
> +
> + for (i = 1; i < level; i++)
> + lblk >>= RPDFS_DATA_REFS_PER_BLK_SHIFT;
> +
> + ind = lblk & (RPDFS_DATA_REFS_PER_BLK - 1ULL);
This could be a much smaller ">> ((level - 1) * shift) & mask". And
let's have a specific _MASK define instead of the -1 by hand.
> +static u8 height_from_lblk(u64 lblk)
> +{
> + u8 height = 2;
> +
> + if (lblk == 0)
> + return 1;
> +
> + while (lblk >>= RPDFS_DATA_REFS_PER_BLK_SHIFT)
> + height++;
> +
> + return height;
Similarly, this could be something involving "fls() / _SHIFT" while being
careful with the various +1/-1 fenceposts.
- z