5 * Copyright (C) 2014 Michael Brown <mbrown@fensystems.co.uk>.
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.
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.
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
28 * The file format is documented in the document "Windows Imaging File
29 * Format (WIM)", available from
31 * http://www.microsoft.com/en-us/download/details.aspx?id=13096
33 * The wimlib source code is also a useful reference.
39 /** A WIM resource header */
40 struct wim_resource_header
{
41 /** Compressed length and flags */
45 /** Uncompressed length */
47 } __attribute__ (( packed
));
49 /** WIM resource header length mask */
50 #define WIM_RESHDR_ZLEN_MASK 0x00ffffffffffffffULL
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 ),
78 /** Total number of parts */
80 /** Number of images */
83 struct wim_resource_header lookup
;
85 struct wim_resource_header xml
;
87 struct wim_resource_header boot
;
90 /** Integrity table */
91 struct wim_resource_header integrity
;
94 } __attribute__ (( packed
));;
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,
104 /** A WIM file hash */
108 } __attribute__ (( packed
));
110 /** A WIM lookup table entry */
111 struct wim_lookup_entry
{
112 /** Resource header */
113 struct wim_resource_header resource
;
116 /** Reference count */
119 struct wim_hash hash
;
120 } __attribute__ (( packed
));
122 /** WIM chunk length */
123 #define WIM_CHUNK_LEN 32768
125 /** A WIM chunk buffer */
126 struct wim_chunk_buffer
{
128 uint8_t data
[WIM_CHUNK_LEN
];
132 struct wim_security_header
{
135 /** Number of entries */
137 } __attribute__ (( packed
));
139 /** Directory entry */
140 struct wim_directory_entry
{
147 /** Subdirectory offset */
150 uint8_t reserved1
[16];
153 /** Last access time */
155 /** Last written time */
158 struct wim_hash hash
;
160 uint8_t reserved2
[12];
163 /** Short name length */
164 uint16_t short_name_len
;
167 } __attribute__ (( packed
));
170 #define WIM_ATTR_NORMAL 0x00000080UL
172 /** No security information exists for this file */
173 #define WIM_NO_SECURITY 0xffffffffUL
175 /** Windows complains if the time fields are left at zero */
176 #define WIM_MAGIC_TIME 0x1a7b83d2ad93000ULL
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
,