]> wimlib.net Git - wimlib/blob - include/wimlib/wim.h
fc36c51991a534f32a551aff1659c8aacc7dec19
[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         WIMStruct *master_wim;
46
47         struct list_head resource_wims;
48
49         struct list_head resource_wim_node;
50
51         /* The currently selected image, indexed starting at 1.  If not 0,
52          * subtract 1 from this to get the index of the current image in the
53          * image_metadata array. */
54         int current_image;
55
56         /* Have any images been deleted? */
57         u8 deletion_occurred : 1;
58
59         /* Do we know that all the stream reference counts in the WIM are
60          * correct?  If so, this is set to 1 and deletions are safe; otherwise
61          * this is set to 0 and deletions are not safe until reference counts
62          * are recalculated.  (This is due to a bug in M$'s software that
63          * generates WIMs with invalid reference counts.)  */
64         u8 refcnts_ok : 1;
65
66         u8 wim_locked : 1;
67
68         u8 being_unmerged : 1;
69
70         u8 is_owned_by_master : 1;
71
72         /* One of WIMLIB_COMPRESSION_TYPE_*, cached from the header flags. */
73         u8 compression_type : 2;
74 };
75
76 static inline bool wim_is_pipable(const WIMStruct *wim)
77 {
78         return (wim->hdr.magic == PWM_MAGIC);
79 }
80
81 static inline bool wim_has_integrity_table(const WIMStruct *wim)
82 {
83         return (wim->hdr.integrity.offset != 0);
84 }
85
86 static inline bool wim_has_metadata(const WIMStruct *wim)
87 {
88         return (wim->image_metadata != NULL || wim->hdr.image_count == 0);
89 }
90
91 extern void
92 wim_recalculate_refcnts(WIMStruct *wim);
93
94 extern int
95 init_wim_header(struct wim_header *hdr, int ctype);
96
97 extern int
98 read_wim_header(const tchar *filename, struct filedes *in_fd,
99                 struct wim_header *hdr);
100
101 extern int
102 write_wim_header(const struct wim_header *hdr, struct filedes *out_fd);
103
104 extern int
105 write_wim_header_at_offset(const struct wim_header *hdr, struct filedes *out_fd,
106                            off_t offset);
107
108 extern int
109 write_wim_header_flags(u32 hdr_flags, struct filedes *out_fd);
110
111 extern int
112 rename_wim_path(WIMStruct *wim, const tchar *from, const tchar *to);
113
114 extern int
115 select_wim_image(WIMStruct *wim, int image);
116
117 extern int
118 for_image(WIMStruct *wim, int image, int (*visitor)(WIMStruct *));
119
120 extern int
121 wim_checksum_unhashed_streams(WIMStruct *wim);
122
123 extern int
124 reopen_wim(WIMStruct *wim);
125
126 /* Internal open flags (pass to open_wim_as_WIMStruct(), not wimlib_open_wim())
127  */
128 #define WIMLIB_OPEN_FLAG_FROM_PIPE      0x80000000
129 #define WIMLIB_OPEN_MASK_PUBLIC         0x7fffffff
130
131 extern int
132 open_wim_as_WIMStruct(const void *wim_filename_or_fd, int open_flags,
133                       WIMStruct **wim_ret,
134                       wimlib_progress_func_t progress_func);
135
136 extern int
137 close_wim(WIMStruct *wim);
138
139 extern int
140 can_modify_wim(WIMStruct *wim);
141
142 extern int
143 can_delete_from_wim(WIMStruct *wim);
144
145 #endif /* _WIMLIB_WIM_H */