From c0fdd37e5a79229aa4efbe5e714bbf1bb8216b4d Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Tue, 23 Jun 2020 12:41:47 -0700 Subject: [PATCH] scoutfs-utils: add get_unaligned helpers Signed-off-by: Zach Brown --- utils/src/util.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/utils/src/util.h b/utils/src/util.h index d7fa787e..637fdf5b 100644 --- a/utils/src/util.h +++ b/utils/src/util.h @@ -6,6 +6,8 @@ #include #include +#include "sparse.h" + /* * Generate build warnings if the condition is false but generate no * code at run time if it's true. @@ -85,6 +87,17 @@ do { \ ((unsigned long)log2l((long double)x)); \ }) +#define emit_get_unaligned_le(nr) \ +static inline __u##nr get_unaligned_le##nr(void *buf) \ +{ \ + __le##nr x; \ + memcpy(&x, buf, sizeof(x)); \ + return le##nr##_to_cpu(x); \ +} +emit_get_unaligned_le(16) +emit_get_unaligned_le(32) +emit_get_unaligned_le(64) + /* * return -1,0,+1 based on the memcmp comparison of the minimum of their * two lengths. If their min shared bytes are equal but the lengths