]> wimlib.net Git - wimlib/blob - include/wimlib/apply.h
Support file counts for extract file structure and metadata progress
[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 #define COUNT_PER_FILE_PROGRESS 256
92
93 static inline int
94 maybe_do_file_progress(struct apply_ctx *ctx, enum wimlib_progress_msg msg)
95 {
96         ctx->progress.extract.current_file_count++;
97         if (unlikely(!--ctx->count_until_file_progress))
98                 return do_file_extract_progress(ctx, msg);
99         return 0;
100 }
101
102 extern int
103 start_file_structure_phase(struct apply_ctx *ctx, uint64_t end_file_count);
104
105 extern int
106 start_file_metadata_phase(struct apply_ctx *ctx, uint64_t end_file_count);
107
108 /* Report that a file was created, prior to stream extraction.  */
109 static inline int
110 report_file_created(struct apply_ctx *ctx)
111 {
112         return maybe_do_file_progress(ctx, WIMLIB_PROGRESS_MSG_EXTRACT_FILE_STRUCTURE);
113 }
114
115 /* Report that file metadata was applied, after stream extraction.  */
116 static inline int
117 report_file_metadata_applied(struct apply_ctx *ctx)
118 {
119         return maybe_do_file_progress(ctx, WIMLIB_PROGRESS_MSG_EXTRACT_METADATA);
120 }
121
122 extern int
123 end_file_structure_phase(struct apply_ctx *ctx);
124
125 extern int
126 end_file_metadata_phase(struct apply_ctx *ctx);
127
128 /* Returns any of the aliases of an inode that are being extracted.  */
129 #define inode_first_extraction_dentry(inode)            \
130         list_first_entry(&(inode)->i_extraction_aliases,        \
131                          struct wim_dentry, d_extraction_alias_node)
132
133 extern int
134 extract_stream_list(struct apply_ctx *ctx,
135                     const struct read_stream_list_callbacks *cbs);
136
137 struct apply_operations {
138         const char *name;
139         int (*get_supported_features)(const tchar *target,
140                                       struct wim_features *supported_features);
141
142         int (*extract)(struct list_head *dentry_list, struct apply_ctx *ctx);
143
144         size_t context_size;
145         bool single_tree_only;
146 };
147
148 #ifdef __WIN32__
149   extern const struct apply_operations win32_apply_ops;
150 #else
151   extern const struct apply_operations unix_apply_ops;
152 #endif
153
154 #ifdef WITH_NTFS_3G
155   extern const struct apply_operations ntfs_3g_apply_ops;
156 #endif
157
158 #endif /* _WIMLIB_APPLY_H */