1 #ifndef _WIMLIB_SCAN_H
2 #define _WIMLIB_SCAN_H
3 
4 #include "wimlib.h"
5 #include "wimlib/inode_table.h"
6 #include "wimlib/list.h"
7 #include "wimlib/progress.h"
8 #include "wimlib/security.h"
9 #include "wimlib/textfile.h"
10 #include "wimlib/util.h"
11 
12 struct blob_table;
13 struct wim_dentry;
14 struct wim_inode;
15 
16 struct capture_config {
17 
18 	/* List of path patterns to exclude  */
19 	struct string_list exclusion_pats;
20 
21 	/* List of path patterns to include, overriding exclusion_pats  */
22 	struct string_list exclusion_exception_pats;
23 
24 	void *buf;
25 };
26 
27 /* Scan parameters: common parameters to implementations of building an
28  * in-memory dentry tree from an external directory structure.  */
29 struct scan_params {
30 
31 	/* The blob table within which any new blobs discovered during the scan
32 	 * will be deduplicated.  */
33 	struct blob_table *blob_table;
34 
35 	/* List of new blobs that have been discovered without their SHA-1
36 	 * message digests having been calculated (as a shortcut).  */
37 	struct list_head *unhashed_blobs;
38 
39 	/* Map from (inode number, device number) pair to inode for new inodes
40 	 * that have been discovered so far.  */
41 	struct wim_inode_table *inode_table;
42 
43 	/* The set of unique security descriptors to which each newly
44 	 * discovered, unique security descriptor will be added.  */
45 	struct wim_sd_set *sd_set;
46 
47 	/* The capture configuration in effect, or NULL if none.  */
48 	struct capture_config *config;
49 
50 	/* Flags that affect the scan operation (WIMLIB_ADD_FLAG_*) */
51 	int add_flags;
52 
53 	/* If non-NULL, the user-supplied progress function. */
54 	wimlib_progress_func_t progfunc;
55 	void *progctx;
56 
57 	/* Progress data.  */
58 	union wimlib_progress_info progress;
59 
60 	/* Path to the file or directory currently being scanned */
61 	tchar *cur_path;
62 	size_t cur_path_nchars;
63 	size_t cur_path_alloc_nchars;
64 
65 	/* Length of the prefix of 'cur_path' which names the root of the
66 	 * directory tree currently being scanned */
67 	size_t root_path_nchars;
68 
69 	/* Can be used by the scan implementation.  */
70 	u64 capture_root_ino;
71 	u64 capture_root_dev;
72 };
73 
74 /* scan.c */
75 
76 extern int
77 do_scan_progress(struct scan_params *params, int status,
78 		 const struct wim_inode *inode);
79 
80 extern int
81 mangle_pat(tchar *pat, const tchar *path, unsigned long line_no);
82 
83 extern int
84 read_capture_config(const tchar *config_file, const void *buf,
85 		    size_t bufsize, struct capture_config *config);
86 
87 extern void
88 destroy_capture_config(struct capture_config *config);
89 
90 extern bool
91 match_pattern_list(const tchar *path, const struct string_list *list,
92 		   int match_flags);
93 
94 extern int
95 try_exclude(const struct scan_params *params);
96 
97 typedef int (*scan_tree_t)(struct wim_dentry **, const tchar *,
98 			   struct scan_params *);
99 
100 #ifdef WITH_NTFS_3G
101 /* ntfs-3g_capture.c */
102 extern int
103 ntfs_3g_build_dentry_tree(struct wim_dentry **root_ret,
104 			  const tchar *device, struct scan_params *params);
105 #endif
106 
107 #ifdef __WIN32__
108 /* win32_capture.c */
109 extern int
110 win32_build_dentry_tree(struct wim_dentry **root_ret,
111 			const tchar *root_disk_path,
112 			struct scan_params *params);
113 #define platform_default_scan_tree win32_build_dentry_tree
114 #else
115 /* unix_capture.c */
116 extern int
117 unix_build_dentry_tree(struct wim_dentry **root_ret,
118 		       const tchar *root_disk_path, struct scan_params *params);
119 #define platform_default_scan_tree unix_build_dentry_tree
120 #endif
121 
122 #ifdef ENABLE_TEST_SUPPORT
123 extern int
124 generate_dentry_tree(struct wim_dentry **root_ret,
125 		     const tchar *root_disk_path, struct scan_params *params);
126 #endif
127 
128 #define WIMLIB_ADD_FLAG_ROOT	0x80000000
129 
130 static inline int
report_scan_error(struct scan_params * params,int error_code)131 report_scan_error(struct scan_params *params, int error_code)
132 {
133 	return report_error(params->progfunc, params->progctx, error_code,
134 			    params->cur_path);
135 }
136 
137 extern bool
138 should_ignore_filename(const tchar *name, int name_nchars);
139 
140 extern void
141 attach_scanned_tree(struct wim_dentry *parent, struct wim_dentry *child,
142 		    struct blob_table *blob_table);
143 
144 extern int
145 pathbuf_init(struct scan_params *params, const tchar *root_path);
146 
147 extern const tchar *
148 pathbuf_append_name(struct scan_params *params, const tchar *name,
149 		    size_t name_nchars, size_t *orig_path_nchars_ret);
150 
151 extern void
152 pathbuf_truncate(struct scan_params *params, size_t nchars);
153 
154 #endif /* _WIMLIB_SCAN_H */
155