[Ocfs2-tools-devel] [PATCH 05/23] libocfs2: Fill out the ocfs2_XXX_to_YYY() conversion APIs.
Mark Fasheh
mfasheh at suse.com
Wed Aug 13 13:37:19 PDT 2008
On Mon, Aug 11, 2008 at 05:31:57PM -0700, Joel Becker wrote:
> ocfs2 often needs to convert sizes from clusters to blocks to bytes. We
> only provided a few of these functions in ocfs2.h. This adds the
> complete set:
>
> ocfs2_clusters_to_blocks()
> ocfs2_blocks_to_clusters()
> ocfs2_clusters_to_bytes()
> ocfs2_bytes_to_clusters()
> ocfs2_blocks_to_bytes()
> ocfs2_bytes_to_blocks()
> ocfs2_clusters_in_blocks()
> ocfs2_clusters_in_bytes()
> ocfs2_blocks_in_bytes()
>
> The container functions (ocfs2_XXX_in_YYY()) only go one direction; the
> other direction is answered correctly by ocfs2_YYY_to_XXX().
>
> While we're here, we standardize the handling of value overflows. Some
> of the existing functions would cast an uint64_t to uint32_t without
> checking. The caller just gets the lower 32bits, regardless of how they
> wrapped. All functions now return UINTxx_MAX on overflow. This is not
> a value that can be checked - UINTxx_MAX could have been the exact
> answer - but it is a safer return than the lower 32bits. Users of this
> function should prevent overflow by checking bounds before calling the
> conversion.
Great, that's exactly how things should happen imho.
Signed-off-by: Mark Fasheh <mfasheh at suse.com>
--
Mark Fasheh
More information about the Ocfs2-tools-devel
mailing list