1/* 2 * macros to convert each packed bitfield structure from little endian to big 3 * endian and vice versa. These are needed when creating a filesystem on a 4 * machine with different byte ordering to the target architecture. 5 * 6 * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007 7 * Phillip Lougher <phillip@lougher.demon.co.uK> 8 * 9 * This program is free software; you can redistribute it and/or 10 * modify it under the terms of the GNU General Public License 11 * as published by the Free Software Foundation; either version 2, 12 * or (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with this program; if not, write to the Free Software 21 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 * 23 * mksquashfs.h 24 * 25 */ 26 27/* 28 * macros used to swap each structure entry, taking into account 29 * bitfields and different bitfield placing conventions on differing architectures 30 */ 31#if __BYTE_ORDER == __BIG_ENDIAN 32 /* convert from big endian to little endian */ 33#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos) 34#else 35 /* convert from little endian to big endian */ 36#define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos) 37#endif 38 39#define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\ 40 int bits;\ 41 int b_pos = pos % 8;\ 42 unsigned long long val = (long long) value << (SHIFT);\ 43 unsigned char *s = ((unsigned char *) &val) + 7;\ 44 unsigned char *d = ((unsigned char *)p) + (pos / 8);\ 45 for(bits = 0; bits < (tbits + b_pos); bits += 8) \ 46 *d++ |= *s--;\ 47} 48#define SQUASHFS_MEMSET(s, d, n) memset(d, 0, n); 49