]> wimlib.net Git - wimlib/blob - include/wimlib/apply.h
resource.c: Cleanup and refactor
[wimlib] / include / wimlib / apply.h
1 #ifndef _WIMLIB_APPLY_H
2 #define _WIMLIB_APPLY_H
3
4 #include "wimlib/types.h"
5 #include "wimlib/list.h"
6 #include "wimlib.h"
7
8 struct wim_lookup_table_entry;
9 struct wimlib_unix_data;
10 struct wim_dentry;
11 struct apply_ctx;
12
13 /* Path to extracted file, or "cookie" identifying the file (e.g. inode number).
14  * */
15 typedef union {
16         const tchar *path;
17         u64 cookie;
18 } file_spec_t;
19
20 /*
21  * struct apply_operations -  Callback functions for a specific extraction
22  * mode/backend.  These are lower-level functions that are called by the generic
23  * code in extract.c.
24  *
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
28  * the generic code.
29  *
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().
33  */
34 struct apply_operations {
35
36         /* OPTIONAL:  Name of this extraction mode.  */
37         const tchar *name;
38
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.  */
42         int (*start_extract)
43                 (const tchar *path, struct apply_ctx *ctx);
44
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);
50
51         /* REQUIRED:  Create a file.  */
52         int (*create_file)
53                 (const tchar *path, struct apply_ctx *ctx, u64 *cookie_ret);
54
55         /* REQUIRED:  Create a directory.  */
56         int (*create_directory)
57                 (const tchar *path, struct apply_ctx *ctx, u64 *cookie_ret);
58
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);
64
65         /* OPTIONAL:  Create a symbolic link.  In start_extract(), set
66          * ctx->supported_features.symlink_reparse_points if supported.  */
67         int (*create_symlink)
68                 (const tchar *oldpath, const tchar *newpath,
69                  struct apply_ctx *ctx);
70
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);
75
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);
82
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);
88
89         /* OPTIONAL:  Set file attributes.  Calling code calls this if non-NULL.
90          */
91         int (*set_file_attributes)
92                 (const tchar *path, u32 attributes, struct apply_ctx *ctx,
93                  unsigned pass);
94
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);
100
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);
106
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);
112
113         /* OPTIONAL:  Set wimlib-specific UNIX data.  In start_extract(), set
114          * ctx->supported_features.unix_data if supported.  */
115         int (*set_unix_data)
116                 (const tchar *path, const struct wimlib_unix_data *data,
117                  struct apply_ctx *ctx);
118
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);
123
124         /* OPTIONAL:  Called after the extraction operation has succeeded.  */
125         int (*finish_extract)
126                 (struct apply_ctx *ctx);
127
128         /* OPTIONAL:  Called after the extraction operation has failed.  */
129         int (*abort_extract)
130                 (struct apply_ctx *ctx);
131
132         /* REQUIRED:  Path separator character to use when building paths.  */
133         tchar path_separator;
134
135         /* REQUIRED:  Maximum path length, in tchars, including the
136          * null-terminator.  */
137         unsigned path_max;
138
139         /* OPTIONAL:  String to prefix every path with.  */
140         const tchar *path_prefix;
141
142         /* OPTIONAL:  Length of path_prefix in tchars.  */
143         unsigned path_prefix_nchars;
144
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;
148
149         /* OPTIONAL:  Like above, but operations require real (absolute) path.
150          * */
151         unsigned requires_realtarget_in_paths : 1;
152
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
155          * created.  */
156         unsigned realpath_works_on_nonexisting_files : 1;
157
158         /* OPTIONAL:  Set to 1 if this extraction mode supports case sensitive
159          * filenames.  */
160         unsigned supports_case_sensitive_filenames : 1;
161
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;
165
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
169          * path.  */
170         unsigned uses_cookies : 1;
171
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;
175
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;
179
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;
184 };
185
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;
203 };
204
205 /* Context for an apply (extract) operation.  */
206 struct apply_ctx {
207         WIMStruct *wim;
208         int extract_flags;
209         const tchar *target;
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;
218         tchar *realtarget;
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;
226         intptr_t private[8];
227 };
228
229 #ifdef __WIN32__
230   extern const struct apply_operations win32_apply_ops;
231 #else
232   extern const struct apply_operations unix_apply_ops;
233 #endif
234
235 #ifdef WITH_NTFS_3G
236   extern const struct apply_operations ntfs_3g_apply_ops;
237 #endif
238
239 #endif /* _WIMLIB_APPLY_H */