Magellan Linux

Contents of /trunk/linterm_tools/fw_builder/bundle-tools/fwstruct.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 658 - (show annotations) (download)
Mon Jan 14 16:57:24 2008 UTC (16 years, 3 months ago) by niro
File MIME type: text/plain
File size: 2119 byte(s)
initial import

1 /*
2 Contains some structures used by fwpack and fwextract
3 Copyright (C) 2005 Wilmer van der Gaast <wilmer@gaast.net>
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the second version of the GNU
7 General Public License as published by the Free Software
8 Foundation.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20 #pragma pack(1)
21
22 struct header
23 {
24 u_int16_t hsize; /* Confusing: hsize == header size */
25 u_int8_t fnlen;
26 u_int32_t bios_flag;
27 u_int32_t offset;
28 u_int32_t fsize; /* file/contents size */
29 u_int32_t time;
30 u_int32_t checksum;
31 u_int8_t sys_flag[3];
32 char fn[0];
33 };
34
35 struct index
36 {
37 struct header *h;
38 struct index *next;
39 off_t idx_offset;
40 char *realfile;
41 };
42
43 #if BYTE_ORDER == BIG_ENDIAN
44 #define cvt32(x) ((((x)&0xff)<<24) | (((x)&0xff00)<<8) | (((x)&0xff0000)>>8) | (((x)&0xff000000)>>24))
45 #define cvt16(x) ((((x)&0xff)<< 8) | (((x)&0xff00)>>8))
46 #else
47 #define cvt32(x) (x)
48 #define cvt16(x) (x)
49 #endif
50
51 void cvtheader( struct header *h )
52 {
53 #if BYTE_ORDER == BIG_ENDIAN
54 h->hsize = cvt16( h->hsize );
55 h->bios_flag = cvt32( h->bios_flag );
56 h->offset = cvt32( h->offset );
57 h->fsize = cvt32( h->fsize );
58 h->time = cvt32( h->time );
59 h->checksum = cvt32( h->checksum );
60 #endif
61 }
62
63 void structcheck( void )
64 {
65 unsigned int test = 1;
66
67 if( ( *((char*)&test) == 1 && BYTE_ORDER == BIG_ENDIAN ) || ( *((char*)&test) == 0 && BYTE_ORDER == LITTLE_ENDIAN ) )
68 {
69 fprintf( stderr, "Program compiled for wrong byte order.\n" );
70 exit( 1 );
71 }
72
73 if( sizeof( struct header ) != 26 )
74 {
75 fprintf( stderr, "sizeof(struct header) must be 26, does your compiler understand #pragma pack?\n" );
76 exit( 1 );
77 }
78 }