All of lore.kernel.org
 help / color / mirror / Atom feed
* Fix mkfs.jffs endian macros
@ 2004-11-09 23:10 Todd Poynor
  0 siblings, 0 replies; only message in thread
From: Todd Poynor @ 2004-11-09 23:10 UTC (permalink / raw)
  To: linux-mtd

Any objection to committing a patch for mkfs.jffs to get rid of the use of
no-longer-userspace-safe kernel macros for endian conversions? -- Todd

Index: mkfs.jffs.c
===================================================================
RCS file: /home/cvs/mtd/util/mkfs.jffs.c,v
retrieving revision 1.12
diff -u -r1.12 mkfs.jffs.c
--- mkfs.jffs.c	5 May 2004 18:33:33 -0000	1.12
+++ mkfs.jffs.c	9 Nov 2004 22:56:02 -0000
@@ -20,6 +20,31 @@
 #include <asm/byteorder.h>
 #include <ctype.h>
 
+#define swab16(x) \
+        ((__u16)( \
+                (((__u16)(x) & (__u16)0x00ffU) << 8) | \
+                (((__u16)(x) & (__u16)0xff00U) >> 8) ))
+#define swab32(x) \
+        ((__u32)( \
+                (((__u32)(x) & (__u32)0x000000ffUL) << 24) | \
+                (((__u32)(x) & (__u32)0x0000ff00UL) <<  8) | \
+                (((__u32)(x) & (__u32)0x00ff0000UL) >>  8) | \
+                (((__u32)(x) & (__u32)0xff000000UL) >> 24) ))
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+#define cpu_to_le16(x) ({ __u16 _x = x; swab16(_x); })
+#define cpu_to_le32(x) ({ __u32 _x = x; swab32(_x); })
+#define cpu_to_be16(x) (x)
+#define cpu_to_be32(x) (x)
+#else
+#define cpu_to_le16(x) (x)
+#define cpu_to_le32(x) (x)
+#define cpu_to_be16(x) ({ __u16 _x = x; swab16(_x); })
+#define cpu_to_be32(x) ({ __u32 _x = x; swab32(_x); })
+#endif
+#define le32_to_cpu(x) cpu_to_le32(x)
+#define be32_to_cpu(x) cpu_to_be32(x)
+
 #define BLOCK_SIZE 1024
 #define JFFS_MAGIC 0x34383931 /* "1984" */
 #define JFFS_MAX_NAME_LEN 256
@@ -184,10 +209,10 @@
     *adr = val;
     break;
   case ENDIAN_LITTLE:
-    *adr = __cpu_to_le32(val);
+    *adr = cpu_to_le32(val);
     break;
   case ENDIAN_BIG:
-    *adr = __cpu_to_be32(val);
+    *adr = cpu_to_be32(val);
     break;
   }
 }
@@ -199,10 +224,10 @@
     *adr = val;
     break;
   case ENDIAN_LITTLE:
-    *adr = __cpu_to_le16(val);
+    *adr = cpu_to_le16(val);
     break;
   case ENDIAN_BIG:
-    *adr = __cpu_to_be16(val);
+    *adr = cpu_to_be16(val);
     break;
   }
 }
@@ -216,10 +241,10 @@
     val = *adr;
     break;
   case ENDIAN_LITTLE:
-    val = __le32_to_cpu(*adr);
+    val = le32_to_cpu(*adr);
     break;
   case ENDIAN_BIG:
-    val = __be32_to_cpu(*adr);
+    val = be32_to_cpu(*adr);
     break;
   }
   return val;
@@ -322,10 +347,10 @@
           tmp = st.st_rdev;
           break;
         case ENDIAN_LITTLE:
-          tmp = __cpu_to_le16(st.st_rdev);
+          tmp = cpu_to_le16(st.st_rdev);
           break;
         case ENDIAN_BIG:
-          tmp = __cpu_to_be16(st.st_rdev);
+          tmp = cpu_to_be16(st.st_rdev);
           break;
       }
       fwrite((char *)&tmp, sizeof(st.st_rdev) / 4, 1, fs);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-11-09 23:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-09 23:10 Fix mkfs.jffs endian macros Todd Poynor

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.