]> wimlib.net Git - wimlib/blob - include/wimlib/apply.h
NTFS-3g apply: Open extracted files by MFT reference
[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 char *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                 (file_spec_t file, 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
94         /* OPTIONAL:  Set reparse data.  In start_extract(), set
95          * ctx->supported_features.reparse_data if supported.  */
96         int (*set_reparse_data)
97                 (const tchar *path, const u8 *rpbuf, u16 rpbuflen,
98                  struct apply_ctx *ctx);
99
100         /* OPTIONAL:  Set short (DOS) filename.  In start_extract(), set
101          * ctx->supported_features.short_name if supported.  */
102         int (*set_short_name)
103                 (const tchar *path, const utf16lechar *short_name,
104                  size_t short_name_nchars, struct apply_ctx *ctx);
105
106         /* OPTIONAL:  Set Windows NT security descriptor.  In start_extract(),
107          * set ctx->supported_features.security_descriptors if supported.  */
108         int (*set_security_descriptor)
109                 (const tchar *path, const u8 *desc, size_t desc_size,
110                  struct apply_ctx *ctx);
111
112         /* OPTIONAL:  Set wimlib-specific UNIX data.  In start_extract(), set
113          * ctx->supported_features.unix_data if supported.  */
114         int (*set_unix_data)
115                 (const tchar *path, const struct wimlib_unix_data *data,
116                  struct apply_ctx *ctx);
117
118         /* OPTIONAL:  Set timestamps.  Calling code calls this if non-NULL.  */
119         int (*set_timestamps)
120                 (const tchar *path, u64 creation_time, u64 last_write_time,
121                  u64 last_access_time, struct apply_ctx *ctx);
122
123         /* OPTIONAL:  Called after the extraction operation has succeeded.  */
124         int (*finish_extract)
125                 (struct apply_ctx *ctx);
126
127         /* OPTIONAL:  Called after the extraction operation has failed.  */
128         int (*abort_extract)
129                 (struct apply_ctx *ctx);
130
131         /* REQUIRED:  Path separator character to use when building paths.  */
132         tchar path_separator;
133
134         /* REQUIRED:  Maximum path length, in tchars, including the
135          * null-terminator.  */
136         unsigned path_max;
137
138         /* OPTIONAL:  String to prefix every path with.  */
139         const tchar *path_prefix;
140
141         /* OPTIONAL:  Length of path_prefix in tchars.  */
142         unsigned path_prefix_nchars;
143
144         /* OPTIONAL:  Set to 1 if paths must be prefixed by the name of the
145          * extraction target (i.e. if it's interpreted as a directory).  */
146         unsigned requires_target_in_paths : 1;
147
148         /* OPTIONAL:  Like above, but operations require real (absolute) path.
149          * */
150         unsigned requires_realtarget_in_paths : 1;
151
152         /* OPTIONAL:  Set to 1 if realpath() can be used to get the real
153          * (absolute) path of a file on the target volume before it's been
154          * created.  */
155         unsigned realpath_works_on_nonexisting_files : 1;
156
157         /* OPTIONAL:  Set to 1 if this extraction mode supports case sensitive
158          * filenames.  */
159         unsigned supports_case_sensitive_filenames : 1;
160
161         /* OPTIONAL:  Set to 1 if the root directory of the volume (see
162          * target_is_root() callback) should not be explicitly extracted.  */
163         unsigned root_directory_is_special : 1;
164
165         /* OPTIONAL:  Set to 1 if extraction cookie, or inode number, is stored
166          * in create_file() and create_directory() callbacks.  This cookie will
167          * then be passed to callbacks taking a 'file_spec_t', rather than the
168          * path.  */
169         unsigned uses_cookies : 1;
170 };
171
172 struct wim_features {
173         unsigned long archive_files;
174         unsigned long hidden_files;
175         unsigned long system_files;
176         unsigned long compressed_files;
177         unsigned long encrypted_files;
178         unsigned long not_context_indexed_files;
179         unsigned long sparse_files;
180         unsigned long named_data_streams;
181         unsigned long hard_links;
182         unsigned long reparse_points;
183         unsigned long symlink_reparse_points;
184         unsigned long other_reparse_points;
185         unsigned long security_descriptors;
186         unsigned long short_names;
187         unsigned long unix_data;
188 };
189
190 /* Context for an apply (extract) operation.  */
191 struct apply_ctx {
192         WIMStruct *wim;
193         int extract_flags;
194         const tchar *target;
195         size_t target_nchars;
196         wimlib_progress_func_t progress_func;
197         union wimlib_progress_info progress;
198         struct wim_dentry *extract_root;
199         const struct apply_operations *ops;
200         struct wim_features supported_features;
201         struct list_head stream_list;
202         tchar *realtarget;
203         size_t realtarget_nchars;
204         unsigned long invalid_sequence;
205         u64 num_streams_remaining;
206         bool root_dentry_is_special;
207         uint64_t next_progress;
208         intptr_t private[8];
209 };
210
211 #ifdef __WIN32__
212   extern const struct apply_operations win32_apply_ops;
213 #else
214   extern const struct apply_operations unix_apply_ops;
215 #endif
216
217 #ifdef WITH_NTFS_3G
218   extern const struct apply_operations ntfs_3g_apply_ops;
219 #endif
220
221 #endif /* _WIMLIB_APPLY_H */