1 #ifndef _WIMLIB_APPLY_H
2 #define _WIMLIB_APPLY_H
4 #include "wimlib/file_io.h"
5 #include "wimlib/types.h"
6 #include "wimlib/list.h"
9 struct wim_lookup_table_entry;
10 struct wimlib_unix_data;
14 /* Path to extracted file, or "cookie" identifying the file (e.g. inode number).
22 * struct apply_operations - Callback functions for a specific extraction
23 * mode/backend. These are lower-level functions that are called by the generic
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
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().
35 struct apply_operations {
37 /* OPTIONAL: Name of this extraction mode. */
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. */
44 (const tchar *path, struct apply_ctx *ctx);
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);
52 /* REQUIRED: Create a file. */
54 (const tchar *path, struct apply_ctx *ctx, u64 *cookie_ret);
56 /* REQUIRED: Create a directory. */
57 int (*create_directory)
58 (const tchar *path, struct apply_ctx *ctx, u64 *cookie_ret);
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);
66 /* OPTIONAL: Create a symbolic link. In start_extract(), set
67 * ctx->supported_features.symlink_reparse_points if supported. */
69 (const tchar *oldpath, const tchar *newpath,
70 struct apply_ctx *ctx);
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, struct wim_dentry *dentry);
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);
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);
90 /* OPTIONAL: Set file attributes. Calling code calls this if non-NULL.
92 int (*set_file_attributes)
93 (const tchar *path, u32 attributes, struct apply_ctx *ctx,
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);
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);
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);
114 /* OPTIONAL: Set wimlib-specific UNIX data. In start_extract(), set
115 * ctx->supported_features.unix_data if supported. */
117 (const tchar *path, const struct wimlib_unix_data *data,
118 struct apply_ctx *ctx);
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);
125 /* OPTIONAL: Called after the extraction operation has succeeded. */
126 int (*finish_extract)
127 (struct apply_ctx *ctx);
129 /* OPTIONAL: Called after the extraction operation has failed. */
131 (struct apply_ctx *ctx);
133 /* REQUIRED: Path separator character to use when building paths. */
134 tchar path_separator;
136 /* REQUIRED: Maximum path length, in tchars, including the
137 * null-terminator. */
140 /* OPTIONAL: String to prefix every path with. */
141 const tchar *path_prefix;
143 /* OPTIONAL: Length of path_prefix in tchars. */
144 unsigned path_prefix_nchars;
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;
150 /* OPTIONAL: Like above, but operations require real (absolute) path.
152 unsigned requires_realtarget_in_paths : 1;
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
157 unsigned realpath_works_on_nonexisting_files : 1;
159 /* OPTIONAL: Set to 1 if this extraction mode supports case sensitive
161 unsigned supports_case_sensitive_filenames : 1;
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;
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
171 unsigned uses_cookies : 1;
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;
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;
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;
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;
206 /* Context for an apply (extract) operation. */
211 size_t target_nchars;
212 wimlib_progress_func_t progress_func;
213 union wimlib_progress_info progress;
214 const struct apply_operations *ops;
215 struct list_head stream_list;
216 struct wim_features supported_features;
217 bool root_dentry_is_special;
218 u32 supported_attributes_mask;
220 struct wim_dentry *target_dentry;
222 size_t realtarget_nchars;
223 unsigned long invalid_sequence;
224 unsigned long partial_security_descriptors;
225 unsigned long no_security_descriptors;
226 struct wim_lookup_table_entry *cur_stream;
227 struct filedes tmpfile_fd;
229 u64 num_streams_remaining;
230 uint64_t next_progress;
231 intptr_t private[10];
235 extern const struct apply_operations win32_apply_ops;
237 extern const struct apply_operations unix_apply_ops;
241 extern const struct apply_operations ntfs_3g_apply_ops;
244 #endif /* _WIMLIB_APPLY_H */