4 * Copyright (C) 1998, 1999 Martin von Löwis
5 * Copyright (C) 1998 Joseph Malicki
6 * Copyright (C) 1999 Werner Seiler
10 /* This defines __cpu_to_le16 on Linux 2.1 and higher. */
11 #include <asm/byteorder.h>
15 #define CPU_TO_LE16(a) __cpu_to_le16(a)
16 #define CPU_TO_LE32(a) __cpu_to_le32(a)
17 #define CPU_TO_LE64(a) __cpu_to_le64(a)
19 #define LE16_TO_CPU(a) __cpu_to_le16(a)
20 #define LE32_TO_CPU(a) __cpu_to_le32(a)
21 #define LE64_TO_CPU(a) __cpu_to_le64(a)
25 #ifdef __LITTLE_ENDIAN
27 #define CPU_TO_LE16(a) (a)
28 #define CPU_TO_LE32(a) (a)
29 #define CPU_TO_LE64(a) (a)
30 #define LE16_TO_CPU(a) (a)
31 #define LE32_TO_CPU(a) (a)
32 #define LE64_TO_CPU(a) (a)
36 /* Routines for big-endian machines */
39 /* We hope its big-endian, not PDP-endian :) */
40 #define CPU_TO_LE16(a) ((((a)&0xFF) << 8)|((a) >> 8))
41 #define CPU_TO_LE32(a) ((((a) & 0xFF) << 24) | (((a) & 0xFF00) << 8) | \
42 (((a) & 0xFF0000) >> 8) | ((a) >> 24))
43 #define CPU_TO_LE64(a) ((CPU_TO_LE32(a)<<32)|CPU_TO_LE32((a)>>32)
45 #define LE16_TO_CPU(a) CPU_TO_LE16(a)
46 #define LE32_TO_CPU(a) CPU_TO_LE32(a)
47 #define LE64_TO_CPU(a) CPU_TO_LE64(a)
51 #error Please define Endianness - __BIG_ENDIAN or __LITTLE_ENDIAN or add OS-specific macros
53 #endif /* __BIG_ENDIAN */
54 #endif /* __LITTLE_ENDIAN */
55 #endif /* __cpu_to_le16 */
57 #define NTFS_GETU8(p) (*(ntfs_u8*)(p))
58 #define NTFS_GETU16(p) ((ntfs_u16)LE16_TO_CPU(*(ntfs_u16*)(p)))
59 #define NTFS_GETU24(p) ((ntfs_u32)NTFS_GETU16(p) | ((ntfs_u32)NTFS_GETU8(((char*)(p))+2)<<16))
60 #define NTFS_GETU32(p) ((ntfs_u32)LE32_TO_CPU(*(ntfs_u32*)(p)))
61 #define NTFS_GETU40(p) ((ntfs_u64)NTFS_GETU32(p)|(((ntfs_u64)NTFS_GETU8(((char*)(p))+4))<<32))
62 #define NTFS_GETU48(p) ((ntfs_u64)NTFS_GETU32(p)|(((ntfs_u64)NTFS_GETU16(((char*)(p))+4))<<32))
63 #define NTFS_GETU56(p) ((ntfs_u64)NTFS_GETU32(p)|(((ntfs_u64)NTFS_GETU24(((char*)(p))+4))<<32))
64 #define NTFS_GETU64(p) ((ntfs_u64)LE64_TO_CPU(*(ntfs_u64*)(p)))
66 /* Macros writing unsigned integers */
67 #define NTFS_PUTU8(p,v) ((*(ntfs_u8*)(p))=(v))
68 #define NTFS_PUTU16(p,v) ((*(ntfs_u16*)(p))=CPU_TO_LE16(v))
69 #define NTFS_PUTU24(p,v) NTFS_PUTU16(p,(v) & 0xFFFF);\
70 NTFS_PUTU8(((char*)(p))+2,(v)>>16)
71 #define NTFS_PUTU32(p,v) ((*(ntfs_u32*)(p))=CPU_TO_LE32(v))
72 #define NTFS_PUTU64(p,v) ((*(ntfs_u64*)(p))=CPU_TO_LE64(v))
74 /* Macros reading signed integers */
75 #define NTFS_GETS8(p) ((*(ntfs_s8*)(p)))
76 #define NTFS_GETS16(p) ((ntfs_s16)LE16_TO_CPU(*(short*)(p)))
77 #define NTFS_GETS24(p) (NTFS_GETU24(p) < 0x800000 ? (int)NTFS_GETU24(p) : (int)(NTFS_GETU24(p) - 0x1000000))
78 #define NTFS_GETS32(p) ((ntfs_s32)LE32_TO_CPU(*(int*)(p)))
79 #define NTFS_GETS40(p) (((ntfs_s64)NTFS_GETU32(p)) | (((ntfs_s64)NTFS_GETS8(((char*)(p))+4)) << 32))
80 #define NTFS_GETS48(p) (((ntfs_s64)NTFS_GETU32(p)) | (((ntfs_s64)NTFS_GETS16(((char*)(p))+4)) << 32))
81 #define NTFS_GETS56(p) (((ntfs_s64)NTFS_GETU32(p)) | (((ntfs_s64)NTFS_GETS24(((char*)(p))+4)) << 32))
82 #define NTFS_GETS64(p) ((ntfs_s64)NTFS_GETU64(p))
84 #define NTFS_PUTS8(p,v) NTFS_PUTU8(p,v)
85 #define NTFS_PUTS16(p,v) NTFS_PUTU16(p,v)
86 #define NTFS_PUTS24(p,v) NTFS_PUTU24(p,v)
87 #define NTFS_PUTS32(p,v) NTFS_PUTU32(p,v)