]> www.infradead.org Git - mtd-utils.git/commitdiff
Consolidate the swab macros into one location
authorJosh Boyer <jwboyer@gmail.com>
Tue, 16 May 2006 10:39:27 +0000 (05:39 -0500)
committerJosh Boyer <jwboyer@gmail.com>
Tue, 16 May 2006 10:39:27 +0000 (05:39 -0500)
Signed-off-by: Josh Boyer <jwboyer@gmail.com>
docfdisk.c
include/mtd_swab.h [new file with mode: 0644]
mkfs.jffs.c
nftl_format.c
nftldump.c
rfddump.c

index 4d82bde2b0a7facaf052503c3d39edbcaedcfa93..b275df9f9c2038445acca6d396833a9999810a36 100644 (file)
 #include <asm/types.h>
 #include <mtd/mtd-user.h>
 #include <mtd/inftl-user.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); })
-#else
-#define cpu_to_le16(x) (x)
-#define cpu_to_le32(x) (x)
-#endif
-#define le32_to_cpu(x) cpu_to_le32(x)
-#define le16_to_cpu(x) cpu_to_le16(x)
+#include <mtd_swab.h>
 
 unsigned char *buf;
 
diff --git a/include/mtd_swab.h b/include/mtd_swab.h
new file mode 100644 (file)
index 0000000..05732a9
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef MTD_SWAB_H
+#define MTD_SWAB_H
+
+#include <endian.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 le16_to_cpu(x) cpu_to_le16(x)
+#define be16_to_cpu(x) cpu_to_be16(x)
+#define le32_to_cpu(x) cpu_to_le32(x)
+#define be32_to_cpu(x) cpu_to_be32(x)
+
+#endif
index 942a09322482989071ab5ac5a48604bdc4379864..7e8de966e6e5827266aabc695146749b035c98b4 100644 (file)
 #include <dirent.h>
 #include <unistd.h>
 #include <linux/types.h>
-#include <asm/byteorder.h>
+#include <mtd_swab.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" */
index a04411a16134c5a2b823abb0012f4c37a6aa9368..b0a80cff7439118cf5b59387647219e27d1c0086 100644 (file)
 #include <mtd/mtd-user.h>
 #include <mtd/nftl-user.h>
 #include <mtd/inftl-user.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); })
-#else
-#define cpu_to_le16(x) (x)
-#define cpu_to_le32(x) (x)
-#endif
-#define le32_to_cpu(x) cpu_to_le32(x)
-#define le16_to_cpu(x) cpu_to_le16(x)
+#include <mtd_swab.h>
 
 unsigned char BadUnitTable[MAX_ERASE_ZONES];
 unsigned char *readbuf;
index fc97b581dc0f38b1d3f7b09996d5304b07c26b25..59aa7d77b2f498898119b8b46b089969bb633718 100644 (file)
@@ -38,6 +38,7 @@
 #include <asm/types.h>
 #include <mtd/mtd-user.h>
 #include <mtd/nftl-user.h>
+#include <mtd_swab.h>
 
 static struct NFTLMediaHeader MedHead[2];
 static mtd_info_t meminfo;
@@ -50,26 +51,10 @@ static int NumMedHeads;
 
 static unsigned char BadUnitTable[MAX_ERASE_ZONES];
 
-/* some byte swabbing stuff from include/linux/byteorder/ */
-#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 == __LITTLE_ENDIAN
-#define cpu_to_le16(x) (x)
-#define cpu_to_le32(x) (x)
 #define SWAP16(x) do { ; } while(0)
 #define SWAP32(x) do { ; } while(0)
 #else
-#define cpu_to_le16(x) swab16(x)
-#define cpu_to_le32(x) swab32(x)
 #define SWAP16(x) do { x = swab16(x); } while(0)
 #define SWAP32(x) do { x = swab32(x); } while(0)
 #endif
index 268e610cb661154e888d4d508ea6cd1faaa64139..f5884abefb101b061720fdd803d359cfcbb2b94c 100644 (file)
--- a/rfddump.c
+++ b/rfddump.c
@@ -25,7 +25,7 @@
 
 #include <mtd/mtd-user.h>
 #include <linux/types.h>
-#include <asm/byteorder.h>
+#include <mtd_swab.h>
 
 /* next is an array of mapping for each corresponding sector */
 #define RFD_MAGIC              0x9193
@@ -137,7 +137,7 @@ int build_block_map(struct rfd *rfd, int fd, int block)
                return -1;
        }
 
-       if (__le16_to_cpu(rfd->header[0]) != RFD_MAGIC) {
+       if (le16_to_cpu(rfd->header[0]) != RFD_MAGIC) {
                if (rfd->verbose)
                        printf("Block #%02d: Magic missing\n", block);
 
@@ -146,7 +146,7 @@ int build_block_map(struct rfd *rfd, int fd, int block)
 
        sectors =  0;
        for (i=0; i<rfd->data_sectors; i++) {
-               __u16 entry = __le16_to_cpu(rfd->header[i + HEADER_MAP_OFFSET]);
+               __u16 entry = le16_to_cpu(rfd->header[i + HEADER_MAP_OFFSET]);
 
                if (entry == SECTOR_FREE || entry == SECTOR_DELETED)
                        continue;