]> wimlib.net Git - wimlib/blob - include/wimlib/apply.h
Add WIMLIB_PROGRESS_MSG_EXTRACT_{FILE_STRUCTURE,METADATA}
[wimlib] / include / wimlib / apply.h
1 #ifndef _WIMLIB_APPLY_H
2 #define _WIMLIB_APPLY_H
3
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"
9 #include "wimlib.h"
10
11 /* These can be treated as counts (for required_features) or booleans (for
12  * supported_features).  */
13 struct wim_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;
32 };
33
34 struct wim_lookup_table_entry;
35 struct read_stream_list_callbacks;
36
37 struct apply_ctx {
38         /* The WIMStruct from which files are being extracted from the currently
39          * selected image.  */
40         WIMStruct *wim;
41
42         /* The target of the extraction, usually the path to a directory.  */
43         const tchar *target;
44
45         /* Length of @target in tchars.  */
46         size_t target_nchars;
47
48         /* Extraction flags (WIMLIB_EXTRACT_FLAG_*)  */
49         int extract_flags;
50
51         /* User-provided progress function, or NULL if not specified.  */
52         wimlib_progress_func_t progfunc;
53         void *progctx;
54
55         /* Progress data buffer, with progress.extract initialized.  */
56         union wimlib_progress_info progress;
57
58         /* Features required to extract the files (with counts)  */
59         struct wim_features required_features;
60
61         /* Features supported by the extraction mode (with booleans)  */
62         struct wim_features supported_features;
63
64         /* The members below should not be used outside of extract.c  */
65         u64 next_progress;
66         unsigned long invalid_sequence;
67         unsigned long num_streams_remaining;
68         struct list_head stream_list;
69         const struct read_stream_list_callbacks *saved_cbs;
70         struct wim_lookup_table_entry *cur_stream;
71         u64 cur_stream_offset;
72         struct filedes tmpfile_fd;
73         tchar *tmpfile_name;
74         unsigned int count_until_file_progress;
75 };
76
77 /* Maximum number of UNIX file descriptors, NTFS attributes, or Windows file
78  * handles that can be opened simultaneously to extract a single-instance
79  * stream to multiple destinations.  */
80 #define MAX_OPEN_STREAMS 512
81
82 static inline int
83 extract_progress(struct apply_ctx *ctx, enum wimlib_progress_msg msg)
84 {
85         return call_progress(ctx->progfunc, msg, &ctx->progress, ctx->progctx);
86 }
87
88 extern int
89 do_file_extract_progress(struct apply_ctx *ctx, enum wimlib_progress_msg msg);
90
91 static inline int
92 maybe_do_file_progress(struct apply_ctx *ctx, enum wimlib_progress_msg msg)
93 {
94         if (unlikely(!--ctx->count_until_file_progress))
95                 return do_file_extract_progress(ctx, msg);
96         return 0;
97 }
98
99 /* Call this to reset the counter for report_file_created() and
100  * report_file_metadata_applied().  */
101 static inline void
102 reset_file_progress(struct apply_ctx *ctx)
103 {
104         ctx->count_until_file_progress = 1;
105 }
106
107 /* Report that a file was created, prior to stream extraction.  */
108 static inline int
109 report_file_created(struct apply_ctx *ctx)
110 {
111         return maybe_do_file_progress(ctx, WIMLIB_PROGRESS_MSG_EXTRACT_FILE_STRUCTURE);
112 }
113
114 /* Report that file metadata was applied, after stream extraction.  */
115 static inline int
116 report_file_metadata_applied(struct apply_ctx *ctx)
117 {
118         return maybe_do_file_progress(ctx, WIMLIB_PROGRESS_MSG_EXTRACT_METADATA);
119 }
120
121 /* Returns any of the aliases of an inode that are being extracted.  */
122 #define inode_first_extraction_dentry(inode)            \
123         list_first_entry(&(inode)->i_extraction_aliases,        \
124                          struct wim_dentry, d_extraction_alias_node)
125
126 extern int
127 extract_stream_list(struct apply_ctx *ctx,
128                     const struct read_stream_list_callbacks *cbs);
129
130 struct apply_operations {
131         const char *name;
132         int (*get_supported_features)(const tchar *target,
133                                       struct wim_features *supported_features);
134
135         int (*extract)(struct list_head *dentry_list, struct apply_ctx *ctx);
136
137         size_t context_size;
138         bool single_tree_only;
139 };
140
141 #ifdef __WIN32__
142   extern const struct apply_operations win32_apply_ops;
143 #else
144   extern const struct apply_operations unix_apply_ops;
145 #endif
146
147 #ifdef WITH_NTFS_3G
148   extern const struct apply_operations ntfs_3g_apply_ops;
149 #endif
150
151 #endif /* _WIMLIB_APPLY_H */