http://downloads.netgear.com/files/GPL/DM111PSP_v3.61d_GPL.tar.gz
[bcm963xx.git] / hostTools / squashfs / read_fs.h
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 Phillip Lougher <plougher@users.sourceforge.net>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2,
11  * or (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  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21  *
22  * mksquashfs.h
23  *
24  */
25
26 /*
27  * macros used to swap each structure entry, taking into account
28  * bitfields and different bitfield placing conventions on differing architectures
29  */
30 #if __BYTE_ORDER == __BIG_ENDIAN
31         /* convert from big endian to little endian */
32 #define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, b_pos)
33 #else
34         /* convert from little endian to big endian */ 
35 #define SQUASHFS_SWAP(value, p, pos, tbits) _SQUASHFS_SWAP(value, p, pos, tbits, 64 - tbits - b_pos)
36 #endif
37
38 #define _SQUASHFS_SWAP(value, p, pos, tbits, SHIFT) {\
39         int bits;\
40         int b_pos = pos % 8;\
41         unsigned long long val = 0;\
42         unsigned char *s = (unsigned char *)p + (pos / 8);\
43         unsigned char *d = ((unsigned char *) &val) + 7;\
44         for(bits = 0; bits < (tbits + b_pos); bits += 8) \
45                 *d-- = *s++;\
46         value = (val >> (SHIFT))/* & ((1 << tbits) - 1)*/;\
47 }
48 #define SQUASHFS_MEMSET(s, d, n)        memset(s, 0, n);