From d1c6dbc9a5c6bf2d3d8de0467a391348f54dbaa6 Mon Sep 17 00:00:00 2001 From: Aneesh Kumar K.V Date: Mon, 9 Nov 2009 20:00:14 +0530 Subject: [PATCH 3/5] richacl: use little endian presentation in the xattr format This patch changes the xattr representation of richacl to little endian format similar to posix acl. Signed-off-by: Aneesh Kumar K.V --- include/byteorder.h | 19 +++++++++++++++++++ include/richacl_xattr.h | 1 + lib/richacl.c | 32 ++++++++++++++++---------------- 3 files changed, 36 insertions(+), 16 deletions(-) create mode 100644 include/byteorder.h diff --git a/include/byteorder.h b/include/byteorder.h new file mode 100644 index 0000000..a04a86c --- /dev/null +++ b/include/byteorder.h @@ -0,0 +1,19 @@ +#include + +#if __BYTE_ORDER == __BIG_ENDIAN +# define cpu_to_le16(w16) le16_to_cpu(w16) +# define le16_to_cpu(w16) ((u_int16_t)((u_int16_t)(w16) >> 8) | \ + (u_int16_t)((u_int16_t)(w16) << 8)) +# define cpu_to_le32(w32) le32_to_cpu(w32) +# define le32_to_cpu(w32) ((u_int32_t)( (u_int32_t)(w32) >>24) | \ + (u_int32_t)(((u_int32_t)(w32) >> 8) & 0xFF00) | \ + (u_int32_t)(((u_int32_t)(w32) << 8) & 0xFF0000) | \ + (u_int32_t)( (u_int32_t)(w32) <<24)) +#elif __BYTE_ORDER == __LITTLE_ENDIAN +# define cpu_to_le16(w16) ((u_int16_t)(w16)) +# define le16_to_cpu(w16) ((u_int16_t)(w16)) +# define cpu_to_le32(w32) ((u_int32_t)(w32)) +# define le32_to_cpu(w32) ((u_int32_t)(w32)) +#else +# error unknown endianess? +#endif diff --git a/include/richacl_xattr.h b/include/richacl_xattr.h index 517dd3f..bbd53e1 100644 --- a/include/richacl_xattr.h +++ b/include/richacl_xattr.h @@ -3,6 +3,7 @@ #include #include +#include "byteorder.h" struct richace_xattr { uint16_t e_type; diff --git a/lib/richacl.c b/lib/richacl.c index 14ee4eb..def02d1 100644 --- a/lib/richacl.c +++ b/lib/richacl.c @@ -266,7 +266,7 @@ static struct richacl *richacl_from_xattr(const void *value, size_t size) xattr_acl->a_version != ACL4_XATTR_VERSION) goto fail_einval; - count = ntohs(xattr_acl->a_count); + count = le16_to_cpu(xattr_acl->a_count); if (count > ACL4_XATTR_MAX_COUNT) goto fail_einval; @@ -275,9 +275,9 @@ static struct richacl *richacl_from_xattr(const void *value, size_t size) return NULL; acl->a_flags = xattr_acl->a_flags; - acl->a_owner_mask = ntohl(xattr_acl->a_owner_mask); - acl->a_group_mask = ntohl(xattr_acl->a_group_mask); - acl->a_other_mask = ntohl(xattr_acl->a_other_mask); + acl->a_owner_mask = le32_to_cpu(xattr_acl->a_owner_mask); + acl->a_group_mask = le32_to_cpu(xattr_acl->a_group_mask); + acl->a_other_mask = le32_to_cpu(xattr_acl->a_other_mask); richacl_for_each_entry(ace, acl) { const char *who = (void *)(xattr_ace + 1), *end; @@ -289,10 +289,10 @@ static struct richacl *richacl_from_xattr(const void *value, size_t size) if (!end) goto fail_einval; - ace->e_type = ntohs(xattr_ace->e_type); - ace->e_flags = ntohs(xattr_ace->e_flags); - ace->e_mask = ntohl(xattr_ace->e_mask); - ace->u.e_id = ntohl(xattr_ace->e_id); + ace->e_type = le16_to_cpu(xattr_ace->e_type); + ace->e_flags = le16_to_cpu(xattr_ace->e_flags); + ace->e_mask = le32_to_cpu(xattr_ace->e_mask); + ace->u.e_id = le32_to_cpu(xattr_ace->e_id); if (who == end) { if (ace->u.e_id == -1) @@ -332,17 +332,17 @@ static void richacl_to_xattr(const struct richacl *acl, void *buffer) xattr_acl->a_version = ACL4_XATTR_VERSION; xattr_acl->a_flags = acl->a_flags; - xattr_acl->a_count = htons(acl->a_count); + xattr_acl->a_count = cpu_to_le16(acl->a_count); - xattr_acl->a_owner_mask = htonl(acl->a_owner_mask); - xattr_acl->a_group_mask = htonl(acl->a_group_mask); - xattr_acl->a_other_mask = htonl(acl->a_other_mask); + xattr_acl->a_owner_mask = cpu_to_le32(acl->a_owner_mask); + xattr_acl->a_group_mask = cpu_to_le32(acl->a_group_mask); + xattr_acl->a_other_mask = cpu_to_le32(acl->a_other_mask); xattr_ace = (void *)(xattr_acl + 1); richacl_for_each_entry(ace, acl) { - xattr_ace->e_type = htons(ace->e_type); - xattr_ace->e_flags = htons(ace->e_flags & ACE4_VALID_FLAGS); - xattr_ace->e_mask = htonl(ace->e_mask); + xattr_ace->e_type = cpu_to_le16(ace->e_type); + xattr_ace->e_flags = cpu_to_le16(ace->e_flags & ACE4_VALID_FLAGS); + xattr_ace->e_mask = cpu_to_le32(ace->e_mask); if (richace_get_who(ace)) { int sz = ALIGN(strlen(ace->u.e_who) + 1, 4); @@ -351,7 +351,7 @@ static void richacl_to_xattr(const struct richacl *acl, void *buffer) strcpy(xattr_ace->e_who, ace->u.e_who); xattr_ace = (void *)xattr_ace->e_who + sz; } else { - xattr_ace->e_id = htonl(ace->u.e_id); + xattr_ace->e_id = cpu_to_le32(ace->u.e_id); memset(xattr_ace->e_who, 0, 4); xattr_ace = (void *)xattr_ace->e_who + 4; } -- 1.6.5.2.74.g610f9