]> wimlib.net Git - wimlib/blob - include/wimlib/apply.h
Use read_stream_list() for extraction
[wimlib] / include / wimlib / apply.h
1 #ifndef _WIMLIB_APPLY_H
2 #define _WIMLIB_APPLY_H
3
4 #include "wimlib/file_io.h"
5 #include "wimlib/types.h"
6 #include "wimlib/list.h"
7 #include "wimlib.h"
8
9 struct wim_lookup_table_entry;
10 struct wimlib_unix_data;
11 struct wim_dentry;
12 struct apply_ctx;
13
14 /* Path to extracted file, or "cookie" identifying the file (e.g. inode number).
15  * */
16 typedef union {
17         const tchar *path;
18         u64 cookie;
19 } file_spec_t;
20
21 /*
22  * struct apply_operations -  Callback functions for a specific extraction
23  * mode/backend.  These are lower-level functions that are called by the generic
24  * code in extract.c.
25  *
26  * Unless otherwise specified, the callbacks in this structure are expected to
27  * return 0 on success or a WIMLIB_ERR_* value on failure as well as set errno.
28  * When possible, error messages should NOT be printed as they are handled by
29  * the generic code.
30  *
31  * Many callbacks are optional, but to extract the most data from the WIM
32  * format, as many as possible should be provided, and the corresponding
33  * features should be marked as supported in start_extract().
34  */
35 struct apply_operations {
36
37         /* OPTIONAL:  Name of this extraction mode.  */
38         const tchar *name;
39
40         /* REQUIRED:  Fill in ctx->supported_features with nonzero values for
41          * features supported by the extraction mode and volume.  This callback
42          * can also be used to do any setup needed to access the volume.  */
43         int (*start_extract)
44                 (const tchar *path, struct apply_ctx *ctx);
45
46         /* OPTIONAL:  If root_directory_is_special is set:  provide this
47          * callback to determine whether the path corresponds to the root of the
48          * target volume (%true) or not (%false).  */
49         bool (*target_is_root)
50                 (const tchar *target);
51
52         /* REQUIRED:  Create a file.  */
53         int (*create_file)
54                 (const tchar *path, struct apply_ctx *ctx, u64 *cookie_ret);
55
56         /* REQUIRED:  Create a directory.  */
57         int (*create_directory)
58                 (const tchar *path, struct apply_ctx *ctx, u64 *cookie_ret);
59
60         /* OPTIONAL:  Create a hard link.  In start_extract(), set
61          * ctx->supported_features.hard_links if supported.  */
62         int (*create_hardlink)
63                 (const tchar *oldpath, const tchar *newpath,
64                  struct apply_ctx *ctx);
65
66         /* OPTIONAL:  Create a symbolic link.  In start_extract(), set
67          * ctx->supported_features.symlink_reparse_points if supported.  */
68         int (*create_symlink)
69                 (const tchar *oldpath, const tchar *newpath,
70                  struct apply_ctx *ctx);
71
72         /* REQUIRED:  Extract unnamed data stream.  */
73         int (*extract_unnamed_stream)
74                 (file_spec_t file, struct wim_lookup_table_entry *lte,
75                  struct apply_ctx *ctx);
76
77         /* OPTIONAL:  Extracted named data stream.  In start_extract(), set
78          * ctx->supported_features.alternate_data_streams if supported.  */
79         int (*extract_named_stream)
80                 (file_spec_t file, const utf16lechar *stream_name,
81                  size_t stream_name_nchars, struct wim_lookup_table_entry *lte,
82                  struct apply_ctx *ctx);
83
84         /* OPTIONAL:  Extracted encrypted stream.  In start_extract(), set
85          * ctx->supported_features.encrypted_files if supported.  */
86         int (*extract_encrypted_stream)
87                 (const tchar *path, struct wim_lookup_table_entry *lte,
88                  struct apply_ctx *ctx);
89
90         /* OPTIONAL:  Set file attributes.  Calling code calls this if non-NULL.
91          */
92         int (*set_file_attributes)
93                 (const tchar *path, u32 attributes, struct apply_ctx *ctx,
94                  unsigned pass);
95
96         /* OPTIONAL:  Set reparse data.  In start_extract(), set
97          * ctx->supported_features.reparse_data if supported.  */
98         int (*set_reparse_data)
99                 (const tchar *path, const u8 *rpbuf, u16 rpbuflen,
100                  struct apply_ctx *ctx);
101
102         /* OPTIONAL:  Set short (DOS) filename.  In start_extract(), set
103          * ctx->supported_features.short_name if supported.  */
104         int (*set_short_name)
105                 (const tchar *path, const utf16lechar *short_name,
106                  size_t short_name_nchars, struct apply_ctx *ctx);
107
108         /* OPTIONAL:  Set Windows NT security descriptor.  In start_extract(),
109          * set ctx->supported_features.security_descriptors if supported.  */
110         int (*set_security_descriptor)
111                 (const tchar *path, const u8 *desc, size_t desc_size,
112                  struct apply_ctx *ctx);
113
114         /* OPTIONAL:  Set wimlib-specific UNIX data.  In start_extract(), set
115          * ctx->supported_features.unix_data if supported.  */
116         int (*set_unix_data)
117                 (const tchar *path, const struct wimlib_unix_data *data,
118                  struct apply_ctx *ctx);
119
120         /* OPTIONAL:  Set timestamps.  Calling code calls this if non-NULL.  */
121         int (*set_timestamps)
122                 (const tchar *path, u64 creation_time, u64 last_write_time,
123                  u64 last_access_time, struct apply_ctx *ctx);
124
125         /* OPTIONAL:  Called after the extraction operation has succeeded.  */
126         int (*finish_extract)
127                 (struct apply_ctx *ctx);
128
129         /* OPTIONAL:  Called after the extraction operation has failed.  */
130         int (*abort_extract)
131                 (struct apply_ctx *ctx);
132
133         /* REQUIRED:  Path separator character to use when building paths.  */
134         tchar path_separator;
135
136         /* REQUIRED:  Maximum path length, in tchars, including the
137          * null-terminator.  */
138         unsigned path_max;
139
140         /* OPTIONAL:  String to prefix every path with.  */
141         const tchar *path_prefix;
142
143         /* OPTIONAL:  Length of path_prefix in tchars.  */
144         unsigned path_prefix_nchars;
145
146         /* OPTIONAL:  Set to 1 if paths must be prefixed by the name of the
147          * extraction target (i.e. if it's interpreted as a directory).  */
148         unsigned requires_target_in_paths : 1;
149
150         /* OPTIONAL:  Like above, but operations require real (absolute) path.
151          * */
152         unsigned requires_realtarget_in_paths : 1;
153
154         /* OPTIONAL:  Set to 1 if realpath() can be used to get the real
155          * (absolute) path of a file on the target volume before it's been
156          * created.  */
157         unsigned realpath_works_on_nonexisting_files : 1;
158
159         /* OPTIONAL:  Set to 1 if this extraction mode supports case sensitive
160          * filenames.  */
161         unsigned supports_case_sensitive_filenames : 1;
162
163         /* OPTIONAL:  Set to 1 if the root directory of the volume (see
164          * target_is_root() callback) should not be explicitly extracted.  */
165         unsigned root_directory_is_special : 1;
166
167         /* OPTIONAL:  Set to 1 if extraction cookie, or inode number, is stored
168          * in create_file() and create_directory() callbacks.  This cookie will
169          * then be passed to callbacks taking a 'file_spec_t', rather than the
170          * path.  */
171         unsigned uses_cookies : 1;
172
173         /* OPTIONAL:  Set to 1 if set_file_attributes() needs to be called a
174          * second time towards the end of the extraction.  */
175         unsigned requires_final_set_attributes_pass : 1;
176
177         /* OPTIONAL:  Set to 1 if extract_encrypted_stream() must be used to
178          * create encrypted files.  */
179         unsigned extract_encrypted_stream_creates_file : 1;
180
181         /* OPTIONAL:  Set to 1 if a link to a file with corresponding short name
182          * must be created before all links to the same file without
183          * corresponding short names.  */
184         unsigned requires_short_name_reordering : 1;
185 };
186
187 struct wim_features {
188         unsigned long archive_files;
189         unsigned long hidden_files;
190         unsigned long system_files;
191         unsigned long compressed_files;
192         unsigned long encrypted_files;
193         unsigned long encrypted_directories;
194         unsigned long not_context_indexed_files;
195         unsigned long sparse_files;
196         unsigned long named_data_streams;
197         unsigned long hard_links;
198         unsigned long reparse_points;
199         unsigned long symlink_reparse_points;
200         unsigned long other_reparse_points;
201         unsigned long security_descriptors;
202         unsigned long short_names;
203         unsigned long unix_data;
204 };
205
206 /* Context for an apply (extract) operation.  */
207 struct apply_ctx {
208         WIMStruct *wim;
209         int extract_flags;
210         const tchar *target;
211         size_t target_nchars;
212         wimlib_progress_func_t progress_func;
213         union wimlib_progress_info progress;
214         struct wim_dentry *extract_root;
215         const struct apply_operations *ops;
216         struct wim_features supported_features;
217         u32 supported_attributes_mask;
218         struct list_head stream_list;
219         tchar *realtarget;
220         size_t realtarget_nchars;
221         unsigned long invalid_sequence;
222         unsigned long partial_security_descriptors;
223         unsigned long no_security_descriptors;
224         struct filedes tmpfile_fd;
225         tchar *tmpfile_name;
226         u64 num_streams_remaining;
227         bool root_dentry_is_special;
228         uint64_t next_progress;
229         intptr_t private[8];
230 };
231
232 #ifdef __WIN32__
233   extern const struct apply_operations win32_apply_ops;
234 #else
235   extern const struct apply_operations unix_apply_ops;
236 #endif
237
238 #ifdef WITH_NTFS_3G
239   extern const struct apply_operations ntfs_3g_apply_ops;
240 #endif
241
242 #endif /* _WIMLIB_APPLY_H */