]> wimlib.net Git - wimlib/blob - include/wimlib/wim.h
Add wimlib_set_output_{pack_chunk_size,compression_type}()
[wimlib] / include / wimlib / wim.h
1 #ifndef _WIMLIB_WIM_H
2 #define _WIMLIB_WIM_H
3
4 #include "wimlib/header.h"
5 #include "wimlib/types.h"
6 #include "wimlib/file_io.h"
7 #include "wimlib/list.h"
8
9 struct wim_info;
10 struct wim_lookup_table;
11 struct wim_image_metadata;
12
13 /* The opaque structure exposed to the wimlib API. */
14 struct WIMStruct {
15
16         /* File descriptor for the WIM file, opened for reading.  in_fd.fd is -1
17          * if the WIM file has not been opened or there is no associated file
18          * backing it yet. */
19         struct filedes in_fd;
20
21         /* File descriptor, opened either for writing only or for
22          * reading+writing, for the WIM file (if any) currently being written.
23          * */
24         struct filedes out_fd;
25
26         /* The name of the WIM file (if any) that has been opened. */
27         tchar *filename;
28
29         /* The lookup table for the WIM file. */
30         struct wim_lookup_table *lookup_table;
31
32         /* Information retrieved from the XML data, arranged in an orderly
33          * manner. */
34         struct wim_info *wim_info;
35
36         /* Array of the image metadata, one for each image in the WIM. */
37         struct wim_image_metadata **image_metadata;
38
39         /* The header of the WIM file. */
40         struct wim_header hdr;
41
42         /* Temporary field */
43         void *private;
44
45         struct wimlib_decompressor *decompressor;
46         enum wimlib_compression_type decompressor_ctype;
47         u32 decompressor_max_block_size;
48
49         struct list_head subwims;
50
51         struct list_head subwim_node;
52
53         /* The currently selected image, indexed starting at 1.  If not 0,
54          * subtract 1 from this to get the index of the current image in the
55          * image_metadata array. */
56         int current_image;
57
58         /* Have any images been deleted? */
59         u8 deletion_occurred : 1;
60
61         /* Do we know that all the stream reference counts in the WIM are
62          * correct?  If so, this is set to 1 and deletions are safe; otherwise
63          * this is set to 0 and deletions are not safe until reference counts
64          * are recalculated.  (This is due to a bug in M$'s software that
65          * generates WIMs with invalid reference counts.)  */
66         u8 refcnts_ok : 1;
67
68         u8 wim_locked : 1;
69
70         u8 guid_set_explicitly : 1;
71
72         /* One of WIMLIB_COMPRESSION_TYPE_*, cached from the header flags. */
73         u8 compression_type;
74
75         /* Overridden compression type for wimlib_overwrite() or wimlib_write().
76          * Can be changed by wimlib_set_output_compression_type(); otherwise is
77          * the same as compression_type.  */
78         u8 out_compression_type;
79
80         /* Compression type for writing packed streams; can be set with
81          * wimlib_set_output_pack_compression_type().  */
82         u8 out_pack_compression_type;
83
84         /* Uncompressed size of compressed chunks in this WIM (cached from
85          * header).  */
86         u32 chunk_size;
87
88         /* Overridden chunk size for wimlib_overwrite() or wimlib_write().  Can
89          * be changed by wimlib_set_output_chunk_size(); otherwise is the same
90          * as chunk_size.  */
91         u32 out_chunk_size;
92
93         /* Chunk size for writing packed streams; can be set with
94          * wimlib_set_output_pack_chunk_size().  */
95         u32 out_pack_chunk_size;
96 };
97
98 static inline bool wim_is_pipable(const WIMStruct *wim)
99 {
100         return (wim->hdr.magic == PWM_MAGIC);
101 }
102
103 static inline bool wim_has_integrity_table(const WIMStruct *wim)
104 {
105         return (wim->hdr.integrity_table_reshdr.offset_in_wim != 0);
106 }
107
108 static inline bool wim_has_metadata(const WIMStruct *wim)
109 {
110         return (wim->image_metadata != NULL || wim->hdr.image_count == 0);
111 }
112
113 extern int
114 wim_recalculate_refcnts(WIMStruct *wim);
115
116 extern int
117 set_wim_hdr_cflags(int ctype, struct wim_header *hdr);
118
119 extern int
120 init_wim_header(struct wim_header *hdr, int ctype, u32 chunk_size);
121
122 extern int
123 read_wim_header(WIMStruct *wim, struct wim_header *hdr);
124
125 extern int
126 write_wim_header(const struct wim_header *hdr, struct filedes *out_fd);
127
128 extern int
129 write_wim_header_at_offset(const struct wim_header *hdr, struct filedes *out_fd,
130                            off_t offset);
131
132 extern int
133 write_wim_header_flags(u32 hdr_flags, struct filedes *out_fd);
134
135 extern int
136 rename_wim_path(WIMStruct *wim, const tchar *from, const tchar *to);
137
138 extern int
139 select_wim_image(WIMStruct *wim, int image);
140
141 extern int
142 for_image(WIMStruct *wim, int image, int (*visitor)(WIMStruct *));
143
144 extern int
145 wim_checksum_unhashed_streams(WIMStruct *wim);
146
147 extern int
148 reopen_wim(WIMStruct *wim);
149
150 /* Internal open flags (pass to open_wim_as_WIMStruct(), not wimlib_open_wim())
151  */
152 #define WIMLIB_OPEN_FLAG_FROM_PIPE      0x80000000
153 #define WIMLIB_OPEN_MASK_PUBLIC         0x7fffffff
154
155 extern int
156 open_wim_as_WIMStruct(const void *wim_filename_or_fd, int open_flags,
157                       WIMStruct **wim_ret,
158                       wimlib_progress_func_t progress_func);
159
160 extern int
161 close_wim(WIMStruct *wim);
162
163 extern int
164 can_modify_wim(WIMStruct *wim);
165
166 extern int
167 can_delete_from_wim(WIMStruct *wim);
168
169 #endif /* _WIMLIB_WIM_H */