1 #ifndef _WIMLIB_APPLY_H
2 #define _WIMLIB_APPLY_H
4 #include "wimlib/compiler.h"
5 #include "wimlib/file_io.h"
6 #include "wimlib/list.h"
7 #include "wimlib/progress.h"
8 #include "wimlib/types.h"
11 /* These can be treated as counts (for required_features) or booleans (for
12 * supported_features). */
14 unsigned long archive_files;
15 unsigned long hidden_files;
16 unsigned long system_files;
17 unsigned long compressed_files;
18 unsigned long encrypted_files;
19 unsigned long encrypted_directories;
20 unsigned long not_context_indexed_files;
21 unsigned long sparse_files;
22 unsigned long named_data_streams;
23 unsigned long hard_links;
24 unsigned long reparse_points;
25 unsigned long symlink_reparse_points;
26 unsigned long other_reparse_points;
27 unsigned long security_descriptors;
28 unsigned long short_names;
29 unsigned long unix_data;
30 unsigned long timestamps;
31 unsigned long case_sensitive_filenames;
34 struct blob_descriptor;
35 struct read_blob_list_callbacks;
36 struct apply_operations;
40 /* The WIMStruct from which files are being extracted from the currently
44 /* The target of the extraction, usually the path to a directory. */
47 /* Length of @target in tchars. */
50 /* Extraction flags (WIMLIB_EXTRACT_FLAG_*) */
53 /* User-provided progress function, or NULL if not specified. */
54 wimlib_progress_func_t progfunc;
57 /* Progress data buffer, with progress.extract initialized. */
58 union wimlib_progress_info progress;
60 /* Features required to extract the files (with counts) */
61 struct wim_features required_features;
63 /* Features supported by the extraction mode (with booleans) */
64 struct wim_features supported_features;
66 /* The members below should not be used outside of extract.c */
67 const struct apply_operations *apply_ops;
69 unsigned long invalid_sequence;
70 unsigned long num_blobs_remaining;
71 struct list_head blob_list;
72 const struct read_blob_list_callbacks *saved_cbs;
73 struct blob_descriptor *cur_blob;
75 struct filedes tmpfile_fd;
77 unsigned int count_until_file_progress;
80 /* Maximum number of UNIX file descriptors, NTFS attributes, or Windows file
81 * handles that can be opened simultaneously to extract a blob to multiple
83 #define MAX_OPEN_FILES 512
86 extract_progress(struct apply_ctx *ctx, enum wimlib_progress_msg msg)
88 return call_progress(ctx->progfunc, msg, &ctx->progress, ctx->progctx);
92 do_file_extract_progress(struct apply_ctx *ctx, enum wimlib_progress_msg msg);
94 #define COUNT_PER_FILE_PROGRESS 256
97 maybe_do_file_progress(struct apply_ctx *ctx, enum wimlib_progress_msg msg)
99 ctx->progress.extract.current_file_count++;
100 if (unlikely(!--ctx->count_until_file_progress))
101 return do_file_extract_progress(ctx, msg);
106 start_file_structure_phase(struct apply_ctx *ctx, u64 end_file_count);
109 start_file_metadata_phase(struct apply_ctx *ctx, u64 end_file_count);
111 /* Report that a file was created, prior to blob extraction. */
113 report_file_created(struct apply_ctx *ctx)
115 return maybe_do_file_progress(ctx, WIMLIB_PROGRESS_MSG_EXTRACT_FILE_STRUCTURE);
118 /* Report that file metadata was applied, after blob extraction. */
120 report_file_metadata_applied(struct apply_ctx *ctx)
122 return maybe_do_file_progress(ctx, WIMLIB_PROGRESS_MSG_EXTRACT_METADATA);
126 end_file_structure_phase(struct apply_ctx *ctx);
129 end_file_metadata_phase(struct apply_ctx *ctx);
132 report_apply_error(struct apply_ctx *ctx, int error_code, const tchar *path)
134 return report_error(ctx->progfunc, ctx->progctx, error_code, path);
137 /* Returns any of the aliases of an inode that are being extracted. */
138 #define inode_first_extraction_dentry(inode) \
139 list_first_entry(&(inode)->i_extraction_aliases, \
140 struct wim_dentry, d_extraction_alias_node)
143 extract_blob_list(struct apply_ctx *ctx,
144 const struct read_blob_list_callbacks *cbs);
147 * Represents an extraction backend.
149 struct apply_operations {
151 /* Name of the extraction backend. */
155 * Query the features supported by the extraction backend.
158 * The target string that was provided by the user. (Often a
159 * directory, but extraction backends are free to interpret this
162 * @supported_features
163 * A structure, each of whose members represents a feature that may
164 * be supported by the extraction backend. For each feature that
165 * the extraction backend supports, this routine must set the
166 * corresponding member to a nonzero value.
168 * Return 0 if successful; otherwise a positive wimlib error code.
170 int (*get_supported_features)(const tchar *target,
171 struct wim_features *supported_features);
174 * Main extraction routine.
176 * The extraction backend is provided a list of dentries that have been
177 * prepared for extraction. It is free to extract them in any way that
178 * it chooses. Ideally, it should choose a method that maximizes
181 * The target string will be provided in ctx->common.target. This might
182 * be a directory, although extraction backends are free to interpret it
183 * as they wish. TODO: in some cases, the common extraction code also
184 * interprets the target string. This should be completely isolated to
185 * extraction backends.
187 * The extraction flags will be provided in ctx->common.extract_flags.
188 * Extraction backends should examine them and implement the behaviors
189 * for as many flags as possible. Some flags are already handled by the
190 * common extraction code. TODO: this needs to be better formalized.
192 * @dentry_list, the list of dentries, will be ordered such that the
193 * ancestor of any dentry always precedes any descendents. Unless
194 * @single_tree_only is set, it's possible that the dentries consist of
195 * multiple disconnected trees.
197 * 'd_extraction_name' and 'd_extraction_name_nchars' of each dentry
198 * will be set to indicate the actual name with which the dentry should
199 * be extracted. This may or may not be the same as 'file_name'.
200 * TODO: really, the extraction backends should be responsible for
201 * generating 'd_extraction_name'.
203 * Each dentry will refer to a valid inode in 'd_inode'.
204 * 'd_inode->i_extraction_aliases' will contain a list of just the
205 * dentries of that inode being extracted. This will be a (possibly
206 * nonproper) subset of the 'd_inode->i_dentry' list.
208 * The blobs required to be extracted will already be prepared in
209 * 'apply_ctx'. The extraction backend should call extract_blob_list()
212 * The will_extract_dentry() utility function, given an arbitrary dentry
213 * in the WIM image (which may not be in the extraction list), can be
214 * used to determine if that dentry is in the extraction list.
216 * Return 0 if successful; otherwise a positive wimlib error code.
218 int (*extract)(struct list_head *dentry_list, struct apply_ctx *ctx);
221 * Query whether the unnamed data stream of the specified file will be
222 * extracted as "externally backed". If so, the extraction backend is
223 * assumed to handle this separately, and the common extraction code
224 * will not register a usage of the unnamed data stream's blob.
226 * This routine is optional.
229 * < 0 if the file will *not* be externally backed.
230 * = 0 if the file will be externally backed.
231 * > 0 (wimlib error code) if another error occurred.
233 int (*will_externally_back)(struct wim_dentry *dentry, struct apply_ctx *ctx);
236 * Size of the backend-specific extraction context. It must contain
237 * 'struct apply_ctx' as its first member.
242 * Set this if the extraction backend only supports extracting dentries
243 * that form a single tree, not multiple trees.
245 bool single_tree_only;
249 extern const struct apply_operations win32_apply_ops;
251 extern const struct apply_operations unix_apply_ops;
255 extern const struct apply_operations ntfs_3g_apply_ops;
258 #endif /* _WIMLIB_APPLY_H */