Whamcloud - gitweb
b=13934
[fs/lustre-release.git] / lustre / utils / create_iam.c
index 5268802..914b0b4 100644 (file)
@@ -103,6 +103,19 @@ enum {
         LVAR_ROUND = LVAR_PAD - 1
 };
 
+/**
+ * Stores \a val at \a dst, where the latter is possibly unaligned. Uses
+ * memcpy(). This macro is needed to avoid dependency of user level tools on
+ * the kernel headers.
+ */
+#define STORE_UNALIGNED(val, dst)                       \
+({                                                      \
+        typeof(val) __val = (val);                      \
+                                                        \
+        CLASSERT(sizeof(val) == sizeof(*(dst)));        \
+        memcpy(dst, &__val, sizeof(*(dst)));            \
+})
+
 static void lfix_root(void *buf,
                       int blocksize, int keysize, int ptrsize, int recsize)
 {
@@ -144,9 +157,9 @@ static void lfix_root(void *buf,
         entry += keysize;
         /* now @entry points to <ptr> */
         if (ptrsize == 4)
-                *(u_int32_t *)entry = cpu_to_le32(1);
+                STORE_UNALIGNED(cpu_to_le32(1), (u_int32_t *)entry);
         else
-                *(u_int64_t *)entry = cpu_to_le64(1);
+                STORE_UNALIGNED(cpu_to_le64(1), (u_int64_t *)entry);
 }
 
 static void lfix_leaf(void *buf,
@@ -208,9 +221,9 @@ static void lvar_root(void *buf,
         entry += sizeof(lvar_hash_t);
         /* now @entry points to <ptr> */
         if (ptrsize == 4)
-                *(u_int32_t *)entry = cpu_to_le32(1);
+                STORE_UNALIGNED(cpu_to_le32(1), (u_int32_t *)entry);
         else
-                *(u_int64_t *)entry = cpu_to_le64(1);
+                STORE_UNALIGNED(cpu_to_le64(1), (u_int64_t *)entry);
 }
 
 static int lvar_esize(int namelen, int recsize)