Subversion Repositories QNX 8.QNX8 IFS tool

Rev

Rev 16 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
16 pmbaty 1
// Hex Workshop structures library
2
 
1 pmbaty 3
#include "standard-types.hsl"
4
 
5
#pragma displayname("QNX Neutrino IFS in-kernel filesystem structures")
6
#pragma byteorder(little_endian)
7
 
8
 
9
// startup header (256 bytes)
10
typedef struct startup_header_s
11
{
12
                           // I - used by the QNX IPL
13
                           // S - used by the startup program
14
   unsigned __int8 signature[4];      // [I ] Header signature, "\xeb\x7e\xff\x00"
15
#pragma verify match_var_int("signature[0]", "0xeb")
16
#pragma verify match_var_int("signature[1]", "0x7e")
17
#pragma verify match_var_int("signature[2]", "0xff")
18
#pragma verify match_var_int("signature[3]", "0x00")
19
   unsigned __int16 version;       // [I ] Header version, i.e. 1
20
   unsigned __int8 flags1;         // [IS] Misc flags, 0x21 (= 0x20 | STARTUP_HDR_FLAGS1_VIRTUAL)
21
   unsigned __int8 flags2;         // [  ] No flags defined yet (0)
22
   unsigned __int16 header_size;   // [ S] sizeof(struct startup_header), i.e. 256
23
#pragma verify match_var_int("header_size", "256")
24
   unsigned __int16 machine;       // [IS] Machine type from elfdefinitions.h, i.e. 0x003E --> _ELF_DEFINE_EM(EM_X86_64, 62, "AMD x86-64 architecture")
25
   unsigned __int32 startup_vaddr; // [I ] Virtual Address to transfer to after IPL is done, here 0x01403008 (appears in "Entry" column for "startup.*")
26
   unsigned __int32 paddr_bias;    // [ S] Value to add to physical address to get a value to put into a pointer and indirected through, here 0 (no indirections)
27
   unsigned __int32 image_paddr;   // [IS] Physical address of image, here 0x01400f30 (appears in "Offset" column for "startup-header" which is the first entry/start of file)
28
   unsigned __int32 ram_paddr;     // [IS] Physical address of RAM to copy image to (startup_size bytes copied), here 0x01400f30 (same as above)
29
   unsigned __int32 ram_size;      // [ S] Amount of RAM used by the startup program and executables contained in the file system, here 0x00cd6128 i.e. 13 459 752 dec. which is 13 Mb. i.e. IFS file size minus 0x9eee
30
   unsigned __int32 startup_size;  // [I ] Size of startup (never compressed), here 0x02f148 or 192 840 bytes
31
   unsigned __int32 stored_size;   // [I ] Size of entire image, here 0x00cd6128 (same as ram_size)
32
   unsigned __int32 imagefs_paddr; // [IS] Set by IPL to where the imagefs is when startup runs (0)
33
   unsigned __int32 imagefs_size;  // [ S] Size of uncompressed imagefs, here 0x00ca6fe0 or 13 266 912 bytes
34
   unsigned __int16 preboot_size;  // [I ] Size of loaded before header, here 0xf30 or 3888 bytes (size of "bios.boot" file))
35
   unsigned __int16 zero0;         // [  ] Zeros
36
   unsigned __int32 zero[1];       // [  ] Zeros
37
   unsigned __int64 addr_off;      // [ S] Offset to add to startup_vaddr, image_paddr, ram_paddr, and imagefs_paddr members, here zero (0)
38
   unsigned __int32 info[48];      // [IS] Array of startup_info* structures (zero filled)
39
} startup_header;
40
 
41
 
26 pmbaty 42
typedef struct startup_trailer_v1_s
43
{
44
   unsigned __int32 cksum; // checksum from start of header to start of trailer
45
} startup_trailer_v1_t;
46
 
47
typedef struct startup_trailer_v2_s
48
{
49
   unsigned __int8 sha512[64]; // SHA512 from start of header to start of trailer
50
   unsigned __int32 cksum; // checksum from start of header to start of this member
51
} startup_trailer_v2_t;
52
 
53
 
1 pmbaty 54
// image header (92 bytes)
55
typedef struct image_header_s
56
{
57
   unsigned __int8 signature[7]; // image filesystem signature, i.e. "imagefs"
58
#pragma verify match_var_int("signature[0]", "0x69")
59
#pragma verify match_var_int("signature[1]", "0x6d")
60
#pragma verify match_var_int("signature[2]", "0x61")
61
#pragma verify match_var_int("signature[3]", "0x67")
62
#pragma verify match_var_int("signature[4]", "0x65")
63
#pragma verify match_var_int("signature[5]", "0x66")
64
#pragma verify match_var_int("signature[6]", "0x73")
65
   unsigned __int8 flags; // endian neutral flags, 0x1c
66
   unsigned __int32 image_size; // size from header to end of trailer (here 0xca6fe0 or 13 266 912)
67
   unsigned __int32 hdr_dir_size; // size from header to last dirent (here 0x12b8 or 4792)
68
   unsigned __int32 dir_offset; // offset from header to first dirent (here 0x5c or 92)
69
#pragma verify match_var_int("dir_offset", "92")
70
   unsigned __int32 boot_ino[4]; // inode of files for bootstrap pgms (here 0xa0000002, 0, 0, 0)
71
   unsigned __int32 script_ino; // inode of file for script (here 3)
72
   unsigned __int32 chain_paddr; // offset to next filesystem signature (0)
73
   unsigned __int32 spare[10]; // zerofill
74
   unsigned __int32 mountflags; // default _MOUNT_* from sys/iomsg.h (0)
75
   char mountpoint[4]; // default mountpoint for image ("/" + "\0\0\0")
76
} image_header_t;
77
 
78
 
79
#pragma hide()
80
typedef struct fsentry_header_s
81
{
82
   unsigned __int16 size; // size of dirent
83
   unsigned __int16 extattr_offset; // if zero, no extattr data
84
   unsigned __int32 ino; // if zero, skip entry
85
   unsigned __int32 mode; // mode and perms of entry
86
   unsigned __int32 gid;
87
   unsigned __int32 uid;
88
   unsigned __int32 mtime;
89
} fsentry_header_t;
90
#pragma show()
91
 
92
 
93
typedef struct fsentry_dir_s // when (mode & S_IFMT) == S_IFDIR
94
{
95
   fsentry_header_t header;
96
__verify(((header.mode & 0x4000) == 0x4000) && ((header.mode & 0xa000) != 0xa000));
97
   char path[header.size - 24]; // null terminated path (no leading slash)
98
} fsentry_dir_t;
99
 
100
 
101
typedef struct fsentry_file_s // when (mode & S_IFMT) == S_IFREG
102
{
103
   fsentry_header_t header;
104
__verify(((header.mode & 0x8000) == 0x8000) && ((header.mode & 0xa000) != 0xa000));
105
   unsigned __int32 offset; // offset from header
106
   unsigned __int32 size;
107
   char path[header.size - 24 - 8]; // null terminated path (no leading slash)
108
} fsentry_file_t;
109
 
110
 
111
typedef struct fsentry_symlink_s // when (mode & S_IFMT) == S_IFLNK
112
{
113
   fsentry_header_t header;
114
__verify((header.mode & 0xa000) == 0xa000);
115
   unsigned __int16 sym_offset;
116
   unsigned __int16 sym_size;
117
   char path_and_symlink[header.size - 24 - 4]; // null terminated path (no leading slash)
118
} fsentry_symlink_t;
119
 
120
 
121
typedef struct fsentry_device_s // when (mode & S_IFMT) == S_IF<CHR|BLK|FIFO|NAM|SOCK>
122
{
123
   fsentry_header_t header;
124
__verify(((header.mode & 0x4000) != 0x4000) && ((header.mode & 0x8000) != 0x8000) && ((header.mode & 0xa000) != 0xa000));
125
   unsigned __int32 dev;
126
   unsigned __int32 rdev;
127
   char path[header.size - 24 - 8]; // null terminated path (no leading slash)
128
} fsentry_device_t;
129
 
130
 
26 pmbaty 131
typedef struct image_trailer_v1_s
1 pmbaty 132
{
133
   unsigned __int32 cksum; // checksum from start of header to start of trailer
26 pmbaty 134
} image_trailer_v1_t;
10 pmbaty 135
 
26 pmbaty 136
typedef struct image_trailer_v2_s
137
{
138
   unsigned __int8 sha512[64]; // SHA512 from start of header to start of trailer
139
   unsigned __int32 cksum; // checksum from start of header to start of this member
140
} image_trailer_v2_t;
10 pmbaty 141
 
142
 
143
 
144
 
145
 
26 pmbaty 146
 
10 pmbaty 147
// Executable and Linkable Format program header structure type definition
148
typedef struct elf32_program_header_s
149
{
11 pmbaty 150
   unsigned __int32 segment_type;   // offset 0: type of segment (0: unused table entry, 1: loadable, 2: dynamic linking information, 3: interpreter information, 4: auxiliary information, 5: reserved, 6: this very segment, 7: TLS template)
151
   unsigned __int32 file_offset;    // offset 4: file offset of this segment
152
   unsigned __int32 virtual_addr;   // offset 8: virtual address where this segment should be mapped in memory
153
   unsigned __int32 physical_addr;  // offset 12: on systems where this is relevant, PHYSICAL address where this segment should be mapped in memory
154
   unsigned __int32 size_in_file;   // offset 16: size of this segment in the ELF file (may be zero)
155
   unsigned __int32 size_in_memory; // offset 20: size of this segment in memory (may be zero)
156
   unsigned __int32 segment_flags;  // offset 24: bitmap of segment flags (1: executable, 2: writable, 4: readable)
157
   unsigned __int32 alignment;      // offset 28: memory alignment (0 or 1 mean non alignment, else must be a power of 2 where virtual_addr == file_offset % alignment)
158
} elf32_program_header_t;
10 pmbaty 159
typedef struct elf64_program_header_s
160
{
11 pmbaty 161
   unsigned __int32 segment_type;   // offset 0: type of segment (0: unused table entry, 1: loadable, 2: dynamic linking information, 3: interpreter information, 4: auxiliary information, 5: reserved, 6: this very segment, 7: TLS template)
162
   unsigned __int32 segment_flags;  // offset 4: bitmap of segment flags (1: executable, 2: writable, 4: readable)
163
   unsigned __int64 file_offset;    // offset 8: file offset of this segment
164
   unsigned __int64 virtual_addr;   // offset 16: virtual address where this segment should be mapped in memory
165
   unsigned __int64 physical_addr;  // offset 24: on systems where this is relevant, PHYSICAL address where this segment should be mapped in memory
166
   unsigned __int64 size_in_file;   // offset 32: size of this segment in the ELF file (may be zero)
167
   unsigned __int64 size_in_memory; // offset 40: size of this segment in memory (may be zero)
168
   unsigned __int64 alignment;      // offset 48: memory alignment (0 or 1 mean non alignment, else must be a power of 2 where virtual_addr == file_offset % alignment)
169
} elf64_program_header_t;
10 pmbaty 170
 
171
 
172
// Executable and Linkable Format section header structure type definition
173
typedef struct elf32_section_header_s
174
{
11 pmbaty 175
   unsigned __int32 name_offset;  // offset 0: offset in the string table of the name of this section
176
   unsigned __int32 type;         // offset 4:
177
   unsigned __int32 flags;        // offset 8:
178
   unsigned __int32 virtual_addr; // offset 12: address in virtual memory where this section may be loaded
179
   unsigned __int32 file_offset;  // offset 16: offset of this section in the ELF file
180
   unsigned __int32 size;         // offset 20: size of this section
181
   unsigned __int32 linked_index; // offset 24: optional section index of an associated section
182
   unsigned __int32 info;         // offset 28: optional extra information
183
   unsigned __int32 alignment;    // offset 32: required memory alignment (must be a power of 2)
184
   unsigned __int32 entry_size;   // offset 36: for table-like sections, size of an element in the table
185
} elf32_section_header_t;
10 pmbaty 186
typedef struct elf64_section_header_s
11 pmbaty 187
{
188
   unsigned __int32 name_offset;  // offset 0: offset in the string table of the name of this section
189
   unsigned __int32 type;         // offset 4:
190
   unsigned __int64 flags;        // offset 8:
191
   unsigned __int64 virtual_addr; // offset 16: address in virtual memory where this section may be loaded
192
   unsigned __int64 file_offset;  // offset 24: offset of this section in the ELF file
193
   unsigned __int64 size;         // offset 32: size of this section
194
   unsigned __int32 linked_index; // offset 40: optional section index of an associated section
195
   unsigned __int32 info;         // offset 44: optional extra information
196
   unsigned __int64 alignment;    // offset 48: required memory alignment (must be a power of 2)
197
   unsigned __int64 entry_size;   // offset 56: for table-like sections, size of an element in the table
198
} elf64_section_header_t;
10 pmbaty 199
 
200
 
201
// Executable and Linkable Format dynamic section entry structure type definition
202
typedef struct elf32_dynamic_section_entry_s
203
{
11 pmbaty 204
   __int32 tag; // dynamic entry type (one of ELF_DT_xxx #defines)
205
   unsigned __int32 integer_or_pointer; // value as integer
206
} elf32_dynamic_section_entry_t;
207
typedef struct elf64_dynamic_section_entry_s
10 pmbaty 208
{
11 pmbaty 209
   __int64 tag; // dynamic entry type (one of ELF_DT_xxx #defines)
210
   unsigned __int64 integer_or_pointer; // value as intege
211
} elf64_dynamic_section_entry_t;
16 pmbaty 212
 
213
 
214
// Executable and Linkable Format master header structure type definition
215
typedef struct elf32_header_s
216
{
217
   unsigned __int32 magic;                     // offset 0: "\x7f" + "ELF"
218
   unsigned char platform_size;                // offset 4: 1 = 32-bit, 2 = 64-bit
219
   __verify((magic == __byteflip32 (0x7f454c46)) && (platform_size == 1));
220
   unsigned char endianness;                   // offset 5: 1 = little endian, 2 = big endian
221
   unsigned char header_version;               // offset 6: typically 1
222
   unsigned char os_abi;                       // offset 7: 0 = SysV, 1 = HP/UX, 2 = NetBSD, 3 = Linux, 4 = GNU/Hurd, 6 = Solaris, 7 = AIX, 8 = IRIX, 9 = FreeBSD, 10 = Tru64, 11 = Novell, 12 = OpenBSD, 13 = OpenVMS, 14 = NonStop kernel, 15 = AROS, 16 = FenixOS, 17 = Nuxi CloudABI, 18 = OpenVOS
223
   unsigned char spare[8];                     // offset 8: zeroes
224
   unsigned __int16 type;                        // offset 16: 1 = relocatable, 2 = executable, 3 = shared, 4 = core dump
225
   unsigned __int16 instruction_set;             // offset 18: 2 = Sparc, 3 = i386, 8 = MIPS, 20 = PowerPC, 40 = ARM, 42 = SuperH, 50 = IA-64, 62 = x86_64, 183 = AArch64, 243 = RISC-V
226
   unsigned __int32 elf_version;                 // offset 20: typically 1
227
   unsigned __int32 entrypoint_offset;           // offset 24: offset to program entrypoint
228
   unsigned __int32 program_header_table_offset; // offset 28: offset to program header table
229
   unsigned __int32 section_header_table_offset; // offset 32: offset to section header table
230
   unsigned __int32 flags;                       // offset 36: flags (architecture-dependent, none for x86)
231
   unsigned __int16 header_size;                 // offset 40: size of ELF header, 52 for 32-bit ELF and 64 for 64-bit ELF -- DO NOT USE sizeof() ON THE elf_header_s STRUCT BECAUSE OF THE UNION! WRITE THE CORRECT SIZE YOURSELF!
232
   unsigned __int16 program_header_item_size;    // offset 42: size of an entry in the program header table
233
   unsigned __int16 program_header_table_len;    // offset 44: number of entries in the program header table
234
   unsigned __int16 section_header_item_size;    // offset 46: size of an entry in the section header table
235
   unsigned __int16 section_header_table_len;    // offset 48: number of entries in the section header table
236
   unsigned __int16 section_header_names_idx;    // offset 50: index of the entry in the section header table that contains the section names
237
 
238
   elf32_program_header_t program_headers[program_header_table_len];
239
} elf32_header_t;
240
 
241
typedef struct elf64_header_s
242
{
243
   unsigned __int32 magic;                     // offset 0: "\x7f" + "ELF"
244
   unsigned char platform_size;                // offset 4: 1 = 32-bit, 2 = 64-bit
245
   __verify((magic == __byteflip32 (0x7f454c46)) && (platform_size == 2));
246
   unsigned char endianness;                   // offset 5: 1 = little endian, 2 = big endian
247
   unsigned char header_version;               // offset 6: typically 1
248
   unsigned char os_abi;                       // offset 7: 0 = SysV, 1 = HP/UX, 2 = NetBSD, 3 = Linux, 4 = GNU/Hurd, 6 = Solaris, 7 = AIX, 8 = IRIX, 9 = FreeBSD, 10 = Tru64, 11 = Novell, 12 = OpenBSD, 13 = OpenVMS, 14 = NonStop kernel, 15 = AROS, 16 = FenixOS, 17 = Nuxi CloudABI, 18 = OpenVOS
249
   unsigned char spare[8];                     // offset 8: zeroes
250
   unsigned __int16 type;                        // offset 16: 1 = relocatable, 2 = executable, 3 = shared, 4 = core dump
251
   unsigned __int16 instruction_set;             // offset 18: 2 = Sparc, 3 = i386, 8 = MIPS, 20 = PowerPC, 40 = ARM, 42 = SuperH, 50 = IA-64, 62 = x86_64, 183 = AArch64, 243 = RISC-V
252
   unsigned __int32 elf_version;                 // offset 20: typically 1
253
   unsigned __int64 entrypoint_offset;           // offset 24: program entry offset
254
   unsigned __int64 program_header_table_offset; // offset 32: offset to program header table
255
   unsigned __int64 section_header_table_offset; // offset 40: offset to section header table
256
   unsigned __int32 flags;                       // offset 48: flags (architecture-dependent, none for x86)
257
   unsigned __int16 header_size;                 // offset 52: size of ELF header, 52 for 32-bit ELF and 64 for 64-bit ELF
258
   unsigned __int16 program_header_item_size;    // offset 54: size of an entry in the program header table
259
   unsigned __int16 program_header_table_len;    // offset 56: number of entries in the program header table
260
   unsigned __int16 section_header_item_size;    // offset 58: size of an entry in the section header table
261
   unsigned __int16 section_header_table_len;    // offset 60: number of entries in the section header table
262
   unsigned __int16 section_header_names_idx;    // offset 62: index of the entry in the section header table that contains the section names
263
 
264
   elf64_program_header_t program_headers[program_header_table_len];
265
} elf64_header_t;