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