bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1 | /* |
| 2 | byteorder.h (12.01.10) |
| 3 | Endianness stuff. exFAT uses little-endian byte order. |
| 4 | |
bigbiff bigbiff | 61cdc02 | 2013-08-08 08:35:06 -0400 | [diff] [blame] | 5 | Free exFAT implementation. |
Matt Mower | 09ef1e4 | 2015-12-13 11:29:45 -0600 | [diff] [blame] | 6 | Copyright (C) 2010-2015 Andrew Nayenko |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 7 | |
bigbiff bigbiff | 61cdc02 | 2013-08-08 08:35:06 -0400 | [diff] [blame] | 8 | This program is free software; you can redistribute it and/or modify |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 9 | it under the terms of the GNU General Public License as published by |
bigbiff bigbiff | 61cdc02 | 2013-08-08 08:35:06 -0400 | [diff] [blame] | 10 | the Free Software Foundation, either version 2 of the License, or |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 11 | (at your option) any later version. |
| 12 | |
| 13 | This program is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
bigbiff bigbiff | 61cdc02 | 2013-08-08 08:35:06 -0400 | [diff] [blame] | 18 | You should have received a copy of the GNU General Public License along |
| 19 | with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | #ifndef BYTEORDER_H_INCLUDED |
| 24 | #define BYTEORDER_H_INCLUDED |
| 25 | |
Matt Mower | 09ef1e4 | 2015-12-13 11:29:45 -0600 | [diff] [blame] | 26 | #include "platform.h" |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 27 | #include <stdint.h> |
Matt Mower | 09ef1e4 | 2015-12-13 11:29:45 -0600 | [diff] [blame] | 28 | #include <stddef.h> |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 29 | |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 30 | typedef struct { uint16_t __u16; } le16_t; |
| 31 | typedef struct { uint32_t __u32; } le32_t; |
| 32 | typedef struct { uint64_t __u64; } le64_t; |
| 33 | |
Matt Mower | 09ef1e4 | 2015-12-13 11:29:45 -0600 | [diff] [blame] | 34 | #if EXFAT_BYTE_ORDER == EXFAT_LITTLE_ENDIAN |
| 35 | |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 36 | static inline uint16_t le16_to_cpu(le16_t v) { return v.__u16; } |
| 37 | static inline uint32_t le32_to_cpu(le32_t v) { return v.__u32; } |
| 38 | static inline uint64_t le64_to_cpu(le64_t v) { return v.__u64; } |
| 39 | |
| 40 | static inline le16_t cpu_to_le16(uint16_t v) { le16_t t = {v}; return t; } |
| 41 | static inline le32_t cpu_to_le32(uint32_t v) { le32_t t = {v}; return t; } |
| 42 | static inline le64_t cpu_to_le64(uint64_t v) { le64_t t = {v}; return t; } |
Matt Mower | 09ef1e4 | 2015-12-13 11:29:45 -0600 | [diff] [blame] | 43 | |
| 44 | typedef size_t bitmap_t; |
| 45 | |
| 46 | #elif EXFAT_BYTE_ORDER == EXFAT_BIG_ENDIAN |
| 47 | |
| 48 | static inline uint16_t le16_to_cpu(le16_t v) |
| 49 | { return exfat_bswap16(v.__u16); } |
| 50 | static inline uint32_t le32_to_cpu(le32_t v) |
| 51 | { return exfat_bswap32(v.__u32); } |
| 52 | static inline uint64_t le64_to_cpu(le64_t v) |
| 53 | { return exfat_bswap64(v.__u64); } |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 54 | |
| 55 | static inline le16_t cpu_to_le16(uint16_t v) |
Matt Mower | 09ef1e4 | 2015-12-13 11:29:45 -0600 | [diff] [blame] | 56 | { le16_t t = {exfat_bswap16(v)}; return t; } |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 57 | static inline le32_t cpu_to_le32(uint32_t v) |
Matt Mower | 09ef1e4 | 2015-12-13 11:29:45 -0600 | [diff] [blame] | 58 | { le32_t t = {exfat_bswap32(v)}; return t; } |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 59 | static inline le64_t cpu_to_le64(uint64_t v) |
Matt Mower | 09ef1e4 | 2015-12-13 11:29:45 -0600 | [diff] [blame] | 60 | { le64_t t = {exfat_bswap64(v)}; return t; } |
| 61 | |
| 62 | typedef unsigned char bitmap_t; |
| 63 | |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 64 | #else |
| 65 | #error Wow! You have a PDP machine?! |
| 66 | #endif |
| 67 | |
| 68 | #endif /* ifndef BYTEORDER_H_INCLUDED */ |