]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - wimboot/wimboot-2.7.3/src/wim.h
1.1.07 release
[Ventoy.git] / wimboot / wimboot-2.7.3 / src / wim.h
1 #ifndef _WIM_H
2 #define _WIM_H
3
4 /*
5 * Copyright (C) 2014 Michael Brown <mbrown@fensystems.co.uk>.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301, USA.
21 */
22
23 /**
24 * @file
25 *
26 * WIM images
27 *
28 * The file format is documented in the document "Windows Imaging File
29 * Format (WIM)", available from
30 *
31 * http://www.microsoft.com/en-us/download/details.aspx?id=13096
32 *
33 * The wimlib source code is also a useful reference.
34 *
35 */
36
37 #include <stdint.h>
38
39 /** A WIM resource header */
40 struct wim_resource_header {
41 /** Compressed length and flags */
42 uint64_t zlen__flags;
43 /** Offset */
44 uint64_t offset;
45 /** Uncompressed length */
46 uint64_t len;
47 } __attribute__ (( packed ));
48
49 /** WIM resource header length mask */
50 #define WIM_RESHDR_ZLEN_MASK 0x00ffffffffffffffULL
51
52 /** WIM resource header flags */
53 enum wim_resource_header_flags {
54 /** Resource contains metadata */
55 WIM_RESHDR_METADATA = ( 0x02ULL << 56 ),
56 /** Resource is compressed */
57 WIM_RESHDR_COMPRESSED = ( 0x04ULL << 56 ),
58 /** Resource is compressed using packed streams */
59 WIM_RESHDR_PACKED_STREAMS = ( 0x10ULL << 56 ),
60 };
61
62 /** A WIM header */
63 struct wim_header {
64 /** Signature */
65 uint8_t signature[8];
66 /** Header length */
67 uint32_t header_len;
68 /** Verson */
69 uint32_t version;
70 /** Flags */
71 uint32_t flags;
72 /** Chunk length */
73 uint32_t chunk_len;
74 /** GUID */
75 uint8_t guid[16];
76 /** Part number */
77 uint16_t part;
78 /** Total number of parts */
79 uint16_t parts;
80 /** Number of images */
81 uint32_t images;
82 /** Lookup table */
83 struct wim_resource_header lookup;
84 /** XML data */
85 struct wim_resource_header xml;
86 /** Boot metadata */
87 struct wim_resource_header boot;
88 /** Boot index */
89 uint32_t boot_index;
90 /** Integrity table */
91 struct wim_resource_header integrity;
92 /** Reserved */
93 uint8_t reserved[60];
94 } __attribute__ (( packed ));;
95
96 /** WIM header flags */
97 enum wim_header_flags {
98 /** WIM uses Xpress compresson */
99 WIM_HDR_XPRESS = 0x00020000,
100 /** WIM uses LZX compression */
101 WIM_HDR_LZX = 0x00040000,
102 };
103
104 /** A WIM file hash */
105 struct wim_hash {
106 /** SHA-1 hash */
107 uint8_t sha1[20];
108 } __attribute__ (( packed ));
109
110 /** A WIM lookup table entry */
111 struct wim_lookup_entry {
112 /** Resource header */
113 struct wim_resource_header resource;
114 /** Part number */
115 uint16_t part;
116 /** Reference count */
117 uint32_t refcnt;
118 /** Hash */
119 struct wim_hash hash;
120 } __attribute__ (( packed ));
121
122 /** WIM chunk length */
123 #define WIM_CHUNK_LEN 32768
124
125 /** A WIM chunk buffer */
126 struct wim_chunk_buffer {
127 /** Data */
128 uint8_t data[WIM_CHUNK_LEN];
129 };
130
131 /** Security data */
132 struct wim_security_header {
133 /** Length */
134 uint32_t len;
135 /** Number of entries */
136 uint32_t count;
137 } __attribute__ (( packed ));
138
139 /** Directory entry */
140 struct wim_directory_entry {
141 /** Length */
142 uint64_t len;
143 /** Attributes */
144 uint32_t attributes;
145 /** Security ID */
146 uint32_t security;
147 /** Subdirectory offset */
148 uint64_t subdir;
149 /** Reserved */
150 uint8_t reserved1[16];
151 /** Creation time */
152 uint64_t created;
153 /** Last access time */
154 uint64_t accessed;
155 /** Last written time */
156 uint64_t written;
157 /** Hash */
158 struct wim_hash hash;
159 /** Reserved */
160 uint8_t reserved2[12];
161 /** Streams */
162 uint16_t streams;
163 /** Short name length */
164 uint16_t short_name_len;
165 /** Name length */
166 uint16_t name_len;
167 } __attribute__ (( packed ));
168
169 /** Normal file */
170 #define WIM_ATTR_NORMAL 0x00000080UL
171
172 /** No security information exists for this file */
173 #define WIM_NO_SECURITY 0xffffffffUL
174
175 /** Windows complains if the time fields are left at zero */
176 #define WIM_MAGIC_TIME 0x1a7b83d2ad93000ULL
177
178 extern int wim_header ( struct vdisk_file *file, struct wim_header *header );
179 extern int wim_count ( struct vdisk_file *file, struct wim_header *header,
180 unsigned int *count );
181 extern int wim_metadata ( struct vdisk_file *file, struct wim_header *header,
182 unsigned int index, struct wim_resource_header *meta);
183 extern int wim_read ( struct vdisk_file *file, struct wim_header *header,
184 struct wim_resource_header *resource, void *data,
185 size_t offset, size_t len );
186 extern int wim_path ( struct vdisk_file *file, struct wim_header *header,
187 struct wim_resource_header *meta, const wchar_t *path,
188 size_t *offset, struct wim_directory_entry *direntry );
189 extern int wim_file ( struct vdisk_file *file, struct wim_header *header,
190 struct wim_resource_header *meta, const wchar_t *path,
191 struct wim_resource_header *resource );
192 extern int wim_dir_len ( struct vdisk_file *file, struct wim_header *header,
193 struct wim_resource_header *meta, size_t offset,
194 size_t *len );
195
196 #endif /* _WIM_H */