-
Notifications
You must be signed in to change notification settings - Fork 256
/
find.h
298 lines (264 loc) · 11.2 KB
/
find.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
/*
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2001-2010 Free Software Foundation Europe e.V.
Copyright (C) 2011-2012 Planets Communications B.V.
Copyright (C) 2013-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
License as published by the Free Software Foundation and included
in the file LICENSE.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
// Kern Sibbald MMI
/**
* @file
* File types as returned by FindFiles()
*/
#ifndef BAREOS_FINDLIB_FIND_H_
#define BAREOS_FINDLIB_FIND_H_
#include "include/fileopts.h"
#include "bfile.h"
#include "lib/htable.h"
#include "lib/dlist.h"
#include "lib/alist.h"
#include <dirent.h>
#define NAMELEN(dirent) (strlen((dirent)->d_name))
#include <sys/file.h>
#if !defined(HAVE_WIN32) || defined(HAVE_MINGW)
# include <sys/param.h>
#endif
#if !defined(HAVE_UTIMES) && !defined(HAVE_LUTIMES)
# include <utime.h>
#endif
#define MODE_RALL (S_IRUSR | S_IRGRP | S_IROTH)
#include "lib/fnmatch.h"
#ifndef HAVE_REGEX_H
# include "lib/bregex.h"
#else
# include <regex.h>
#endif
#ifdef USE_READDIR_R
# ifndef HAVE_READDIR_R
int Readdir_r(DIR* dirp, struct dirent* entry, struct dirent** result);
# endif
#endif
// For options FO_xxx values see src/fileopts.h
enum
{
state_none,
state_options,
state_include,
state_error
};
typedef enum
{
check_shadow_none,
check_shadow_local_warn,
check_shadow_local_remove,
check_shadow_global_warn,
check_shadow_global_remove
} b_fileset_shadow_type;
typedef enum
{
size_match_none,
size_match_approx,
size_match_smaller,
size_match_greater,
size_match_range
} b_sz_match_type;
struct s_sz_matching {
b_sz_match_type type{size_match_none};
uint64_t begin_size{};
uint64_t end_size{};
};
struct s_included_file {
struct s_included_file* next;
char options[FOPTS_BYTES]; /**< Backup options */
uint32_t cipher; /**< Encryption cipher forced by fileset */
uint32_t algo; /**< Compression algorithm. 4 letters stored as an integer */
int level; /**< Compression level */
int len; /**< Length of fname */
int pattern; /**< Set if wild card pattern */
struct s_sz_matching* size_match; /**< Perform size matching ? */
b_fileset_shadow_type shadow_type; /**< Perform fileset shadowing check ? */
char VerifyOpts[20]; /**< Options for verify */
char fname[1];
};
struct s_excluded_file {
struct s_excluded_file* next;
int len;
char fname[1];
};
#define MAX_OPTS 20
// File options structure
struct findFOPTS {
char flags[FOPTS_BYTES]{}; /**< Backup options */
uint32_t Encryption_cipher{}; /**< Encryption cipher forced by fileset */
uint32_t Compress_algo{}; /**< Compression algorithm. 4 letters stored as an
integer */
int Compress_level{}; /**< Compression level */
int StripPath{}; /**< Strip path count */
struct s_sz_matching* size_match{}; /**< Perform size matching ? */
b_fileset_shadow_type shadow_type{
check_shadow_none}; /**< Perform fileset shadowing check ? */
char VerifyOpts[MAX_OPTS]{}; /**< Verify options */
char AccurateOpts[MAX_OPTS]{}; /**< Accurate mode options */
char BaseJobOpts[MAX_OPTS]{}; /**< Basejob mode options */
char* plugin{}; /**< Plugin that handle this section */
alist<regex_t*> regex; /**< Regex string(s) */
alist<regex_t*> regexdir; /**< Regex string(s) for directories */
alist<regex_t*> regexfile; /**< Regex string(s) for files */
alist<const char*> wild; /**< Wild card strings */
alist<const char*> wilddir; /**< Wild card strings for directories */
alist<const char*> wildfile; /**< Wild card strings for files */
alist<const char*> wildbase; /**< Wild card strings for basenames */
alist<const char*> base; /**< List of base names */
alist<const char*> fstype; /**< File system type limitation */
alist<const char*> Drivetype; /**< Drive type limitation */
};
// This is either an include item or an exclude item
struct findIncludeExcludeItem {
findFOPTS* current_opts; /**< Points to current options structure */
alist<findFOPTS*> opts_list; /**< Options list */
dlist<dlistString> name_list; /**< Filename list -- holds dlistString */
dlist<dlistString> plugin_list; /**< Plugin list -- holds dlistString */
alist<const char*> ignoredir; /**< Ignore directories with this file(s) */
};
// FileSet Resource
struct findFILESET {
int state;
findIncludeExcludeItem* incexe; /**< Current item */
alist<findIncludeExcludeItem*> include_list;
alist<findIncludeExcludeItem*> exclude_list;
};
// OSX resource fork.
struct HfsPlusInfo {
unsigned long length{0}; /**< Mandatory field */
char fndrinfo[32]{}; /**< Finder Info */
off_t rsrclength{0}; /**< Size of resource fork */
};
/**
* Structure for keeping track of hard linked files, we
* keep an entry for each hardlinked file that we save,
* which is the first one found. For all the other files that
* are linked to this one, we save only the directory
* entry so we can link it.
*/
struct CurLink {
struct hlink link;
dev_t dev; /**< Device */
ino_t ino; /**< Inode with device is unique */
uint32_t FileIndex; /**< Bareos FileIndex of this file */
int32_t digest_stream; /**< Digest type if needed */
uint32_t digest_len; /**< Digest len if needed */
char* digest; /**< Checksum of the file if needed */
char name[1]; /**< The name */
};
using LinkHash
= htable<htable_binary_key, CurLink, MonotonicBuffer::Size::Medium>;
/**
* Definition of the FindFiles packet passed as the
* first argument to the FindFiles callback subroutine.
*/
/* clang-format off */
struct FindFilesPacket {
char* top_fname{nullptr}; /**< Full filename before descending */
char* fname{nullptr}; /**< Full filename */
char* link{nullptr}; /**< Link if file linked */
char* object_name{nullptr}; /**< Object name */
char* object{nullptr}; /**< Restore object */
char* plugin{nullptr}; /**< Current Options{Plugin=} name */
POOLMEM* sys_fname{nullptr}; /**< System filename */
POOLMEM* fname_save{nullptr}; /**< Save when stripping path */
POOLMEM* link_save{nullptr}; /**< Save when stripping path */
POOLMEM* ignoredir_fname{nullptr}; /**< Used to ignore directories */
char* digest{nullptr}; /**< Set to file digest when the file is a hardlink */
struct stat statp{}; /**< Stat packet */
uint32_t digest_len{0}; /**< Set to the digest len when the file is a hardlink*/
int32_t digest_stream{0}; /**< Set to digest type when the file is hardlink */
int32_t FileIndex{0}; /**< FileIndex of this file */
int32_t LinkFI{0}; /**< FileIndex of main hard linked file */
int32_t delta_seq{0}; /**< Delta Sequence number */
int32_t object_index{0}; /**< Object index */
int32_t object_len{0}; /**< Object length */
int32_t object_compression{0}; /**< Type of compression for object */
int type{0}; /**< FT_ type from above */
int ff_errno{0}; /**< Errno */
BareosFilePacket bfd; /**< Bareos file descriptor */
time_t save_time{0}; /**< Start of incremental time */
bool accurate_found{false}; /**< Found in the accurate hash (valid after
CheckChanges()) */
bool dereference{false}; /**< Follow links (not implemented) */
bool null_output_device{false}; /**< Using null output device */
bool incremental{false}; /**< Incremental save */
bool no_read{false}; /**< Do not read this file when using Plugin */
char VerifyOpts[MAX_OPTS]{};
char AccurateOpts[MAX_OPTS]{};
char BaseJobOpts[MAX_OPTS]{};
struct s_included_file* included_files_list{nullptr};
struct s_excluded_file* excluded_files_list{nullptr};
struct s_excluded_file* excluded_paths_list{nullptr};
findFILESET* fileset{nullptr};
int (*FileSave)(JobControlRecord*,
FindFilesPacket*,
bool){}; /**< User's callback */
int (*PluginSave)(JobControlRecord*,
FindFilesPacket*,
bool){}; /**< User's callback */
bool (*CheckFct)(
JobControlRecord*,
FindFilesPacket*){}; /**< Optional user fct to check file changes */
// Values set by AcceptFile while processing Options
char flags[FOPTS_BYTES]{}; /**< Backup options */
uint32_t Compress_algo{0}; /**< Compression algorithm. 4 letters stored as an integer */
int Compress_level{0}; /**< Compression level */
int StripPath{0}; /**< Strip path count */
struct s_sz_matching* size_match{nullptr}; /**< Perform size matching ? */
bool cmd_plugin{false}; /**< Set if we have a command plugin */
bool opt_plugin{false}; /**< Set if we have an option plugin */
alist<const char*> fstypes; /**< Allowed file system types */
alist<const char*> drivetypes; /**< Allowed drive types */
// List of all hard linked files found
LinkHash* linkhash{nullptr}; /**< Hard linked files */
struct CurLink* linked{nullptr}; /**< Set if this file is hard linked */
/*
* Darwin specific things.
* To avoid clutter, we always include rsrc_bfd and volhas_attrlist.
*/
BareosFilePacket rsrc_bfd; /**< Fd for resource forks */
bool volhas_attrlist{false}; /**< Volume supports getattrlist() */
HfsPlusInfo hfsinfo; /**< Finder Info and resource fork size */
};
/* clang-format on */
FindFilesPacket* init_find_files();
void SetFindOptions(FindFilesPacket* ff, bool incremental, time_t mtime);
void SetFindChangedFunction(FindFilesPacket* ff,
bool CheckFct(JobControlRecord* jcr,
FindFilesPacket* ff));
int FindFiles(JobControlRecord* jcr,
FindFilesPacket* ff,
int file_sub(JobControlRecord*, FindFilesPacket* ff_pkt, bool),
int PluginSub(JobControlRecord*, FindFilesPacket* ff_pkt, bool));
bool MatchFiles(JobControlRecord* jcr,
FindFilesPacket* ff,
int sub(JobControlRecord*, FindFilesPacket* ff_pkt, bool));
void TermFindFiles(FindFilesPacket* ff);
bool IsInFileset(FindFilesPacket* ff);
bool AcceptFile(FindFilesPacket* ff);
findIncludeExcludeItem* allocate_new_incexe(void);
findIncludeExcludeItem* new_exclude(findFILESET* fileset);
findIncludeExcludeItem* new_include(findFILESET* fileset);
findIncludeExcludeItem* new_preinclude(findFILESET* fileset);
findIncludeExcludeItem* new_preexclude(findFILESET* fileset);
findFOPTS* start_options(FindFilesPacket* ff);
void NewOptions(FindFilesPacket* ff, findIncludeExcludeItem* incexe);
#include "acl.h"
#include "xattr.h"
#endif // BAREOS_FINDLIB_FIND_H_