extract.c: Fix for running out of file handles
[wimlib] / include / wimlib / apply.h
1 #ifndef _WIMLIB_APPLY_H
2 #define _WIMLIB_APPLY_H
3
4 #include "wimlib/file_io.h"
5 #include "wimlib/list.h"
6 #include "wimlib/progress.h"
7 #include "wimlib/types.h"
8 #include "wimlib.h"
9
10 /* These can be treated as counts (for required_features) or booleans (for
11  * supported_features).  */
12 struct wim_features {
13         unsigned long archive_files;
14         unsigned long hidden_files;
15         unsigned long system_files;
16         unsigned long compressed_files;
17         unsigned long encrypted_files;
18         unsigned long encrypted_directories;
19         unsigned long not_context_indexed_files;
20         unsigned long sparse_files;
21         unsigned long named_data_streams;
22         unsigned long hard_links;
23         unsigned long reparse_points;
24         unsigned long symlink_reparse_points;
25         unsigned long other_reparse_points;
26         unsigned long security_descriptors;
27         unsigned long short_names;
28         unsigned long unix_data;
29         unsigned long timestamps;
30         unsigned long case_sensitive_filenames;
31 };
32
33 struct wim_lookup_table_entry;
34 struct read_stream_list_callbacks;
35
36 struct apply_ctx {
37         /* The WIMStruct from which files are being extracted from the currently
38          * selected image.  */
39         WIMStruct *wim;
40
41         /* The target of the extraction, usually the path to a directory.  */
42         const tchar *target;
43
44         /* Length of @target in tchars.  */
45         size_t target_nchars;
46
47         /* Extraction flags (WIMLIB_EXTRACT_FLAG_*)  */
48         int extract_flags;
49
50         /* User-provided progress function, or NULL if not specified.  */
51         wimlib_progress_func_t progfunc;
52         void *progctx;
53
54         /* Progress data buffer, with progress.extract initialized.  */
55         union wimlib_progress_info progress;
56
57         /* Features required to extract the files (with counts)  */
58         struct wim_features required_features;
59
60         /* Features supported by the extraction mode (with booleans)  */
61         struct wim_features supported_features;
62
63         /* The members below should not be used outside of extract.c  */
64         u64 next_progress;
65         unsigned long invalid_sequence;
66         unsigned long num_streams_remaining;
67         struct list_head stream_list;
68         const struct read_stream_list_callbacks *saved_cbs;
69         struct wim_lookup_table_entry *cur_stream;
70         struct filedes tmpfile_fd;
71         tchar *tmpfile_name;
72 };
73
74 /* Maximum number of UNIX file descriptors, NTFS attributes, or Windows file
75  * handles that can be opened simultaneously to extract a single-instance
76  * stream to multiple destinations.  */
77 #define MAX_OPEN_STREAMS 512
78
79 static inline int
80 extract_progress(struct apply_ctx *ctx, enum wimlib_progress_msg msg)
81 {
82         return call_progress(ctx->progfunc, msg, &ctx->progress, ctx->progctx);
83 }
84
85 /* Returns any of the aliases of an inode that are being extracted.  */
86 #define inode_first_extraction_dentry(inode)            \
87         list_first_entry(&(inode)->i_extraction_aliases,        \
88                          struct wim_dentry, d_extraction_alias_node)
89
90 extern int
91 extract_stream_list(struct apply_ctx *ctx,
92                     const struct read_stream_list_callbacks *cbs);
93
94 struct apply_operations {
95         const char *name;
96         int (*get_supported_features)(const tchar *target,
97                                       struct wim_features *supported_features);
98
99         int (*extract)(struct list_head *dentry_list, struct apply_ctx *ctx);
100
101         size_t context_size;
102         bool single_tree_only;
103 };
104
105 #ifdef __WIN32__
106   extern const struct apply_operations win32_apply_ops;
107 #else
108   extern const struct apply_operations unix_apply_ops;
109 #endif
110
111 #ifdef WITH_NTFS_3G
112   extern const struct apply_operations ntfs_3g_apply_ops;
113 #endif
114
115 #endif /* _WIMLIB_APPLY_H */