]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/findlib/find.h
f0324da3db33ea60fc863b04f96adfbe22c85c20
[bacula/bacula] / bacula / src / findlib / find.h
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2001-2010 Free Software Foundation Europe e.V.
5
6    The main author of Bacula is Kern Sibbald, with contributions from
7    many others, a complete list can be found in the file AUTHORS.
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version two of the GNU General Public
10    License as published by the Free Software Foundation and included
11    in the file LICENSE.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23    Bacula® is a registered trademark of Kern Sibbald.
24    The licensor of Bacula is the Free Software Foundation Europe
25    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26    Switzerland, email:ftf@fsfeurope.org.
27 */
28 /*
29  * File types as returned by find_files()
30  *
31  *     Kern Sibbald MMI
32  */
33
34 #ifndef __FILES_H
35 #define __FILES_H
36
37 #include "jcr.h"
38 #include "bfile.h"
39 #include "../filed/fd_plugins.h"
40
41 #ifdef HAVE_DIRENT_H
42 #include <dirent.h>
43 #define NAMELEN(dirent) (strlen((dirent)->d_name))
44 #endif
45
46 #include <sys/file.h>
47 #if !defined(HAVE_WIN32) || defined(HAVE_MINGW)
48 #include <sys/param.h>
49 #endif
50 #if HAVE_UTIME_H
51 #include <utime.h>
52 #else
53 struct utimbuf {
54     long actime;
55     long modtime;
56 };
57 #endif
58
59 #define MODE_RALL (S_IRUSR|S_IRGRP|S_IROTH)
60
61 #include "lib/fnmatch.h"
62 // #include "lib/enh_fnmatch.h"
63
64 #ifndef HAVE_REGEX_H
65 #include "lib/bregex.h"
66 #else
67 #include <regex.h>
68 #endif
69
70 #ifndef HAVE_READDIR_R
71 int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result);
72 #endif
73
74 /*  
75  * Options saved int "options" of the include/exclude lists.
76  * They are directly jammed ito  "flag" of ff packet
77  */
78 #define FO_MD5          (1<<1)        /* Do MD5 checksum */
79 #define FO_GZIP         (1<<2)        /* Do Zlib compression */
80 #define FO_NO_RECURSION (1<<3)        /* no recursion in directories */
81 #define FO_MULTIFS      (1<<4)        /* multiple file systems */
82 #define FO_SPARSE       (1<<5)        /* do sparse file checking */
83 #define FO_IF_NEWER     (1<<6)        /* replace if newer */
84 #define FO_NOREPLACE    (1<<7)        /* never replace */
85 #define FO_READFIFO     (1<<8)        /* read data from fifo */
86 #define FO_SHA1         (1<<9)        /* Do SHA1 checksum */
87 #define FO_PORTABLE     (1<<10)       /* Use portable data format -- no BackupWrite */
88 #define FO_MTIMEONLY    (1<<11)       /* Use mtime rather than mtime & ctime */
89 #define FO_KEEPATIME    (1<<12)       /* Reset access time */
90 #define FO_EXCLUDE      (1<<13)       /* Exclude file */
91 #define FO_ACL          (1<<14)       /* Backup ACLs */
92 #define FO_NO_HARDLINK  (1<<15)       /* don't handle hard links */
93 #define FO_IGNORECASE   (1<<16)       /* Ignore file name case */
94 #define FO_HFSPLUS      (1<<17)       /* Resource forks and Finder Info */
95 #define FO_WIN32DECOMP  (1<<18)       /* Use BackupRead decomposition */
96 #define FO_SHA256       (1<<19)       /* Do SHA256 checksum */
97 #define FO_SHA512       (1<<20)       /* Do SHA512 checksum */
98 #define FO_ENCRYPT      (1<<21)       /* Encrypt data stream */
99 #define FO_NOATIME      (1<<22)       /* Use O_NOATIME to prevent atime change */
100 #define FO_ENHANCEDWILD (1<<23)       /* Enhanced wild card processing */
101 #define FO_CHKCHANGES   (1<<24)       /* Check if file have been modified during backup */
102 #define FO_STRIPPATH    (1<<25)       /* Check for stripping path */
103 #define FO_HONOR_NODUMP (1<<26)       /* honor NODUMP flag */
104 #define FO_XATTR        (1<<27)       /* Backup Extended Attributes */
105
106 struct s_included_file {
107    struct s_included_file *next;
108    uint32_t options;                  /* backup options */
109    int level;                         /* compression level */
110    int len;                           /* length of fname */
111    int pattern;                       /* set if wild card pattern */
112    char VerifyOpts[20];               /* Options for verify */
113    char fname[1];
114 };
115
116 struct s_excluded_file {
117    struct s_excluded_file *next;
118    int len;
119    char fname[1];
120 };
121
122 /* FileSet definitions very similar to the resource
123  *  contained in the Director because the components
124  *  of the structure are passed by the Director to the
125  *  File daemon and recompiled back into this structure
126  */
127 #undef  MAX_FOPTS
128 #define MAX_FOPTS 30
129
130 enum {
131    state_none,
132    state_options,
133    state_include,
134    state_error
135 };
136
137 /* File options structure */
138 struct findFOPTS {
139    uint32_t flags;                    /* options in bits */
140    int GZIP_level;                    /* GZIP level */
141    int strip_path;                    /* strip path count */
142    char VerifyOpts[MAX_FOPTS];        /* verify options */
143    char AccurateOpts[MAX_FOPTS];      /* accurate mode options */
144    char BaseJobOpts[MAX_FOPTS];       /* basejob mode options */
145    alist regex;                       /* regex string(s) */
146    alist regexdir;                    /* regex string(s) for directories */
147    alist regexfile;                   /* regex string(s) for files */
148    alist wild;                        /* wild card strings */
149    alist wilddir;                     /* wild card strings for directories */
150    alist wildfile;                    /* wild card strings for files */
151    alist wildbase;                    /* wild card strings for basenames */
152    alist base;                        /* list of base names */
153    alist fstype;                      /* file system type limitation */
154    alist drivetype;                   /* drive type limitation */
155 };
156
157
158 /* This is either an include item or an exclude item */
159 struct findINCEXE {
160    findFOPTS *current_opts;           /* points to current options structure */
161    alist opts_list;                   /* options list */
162    dlist name_list;                   /* filename list -- holds dlistString */
163    dlist plugin_list;                 /* plugin list -- holds dlistString */
164    char *ignoredir;                   /* ignore directories with this file */
165 };
166
167 /*
168  *   FileSet Resource
169  *
170  */
171 struct findFILESET {
172    int state;
173    findINCEXE *incexe;                /* current item */
174    alist include_list;
175    alist exclude_list;
176 };
177
178 struct HFSPLUS_INFO {
179    unsigned long length;              /* Mandatory field */
180    char fndrinfo[32];                 /* Finder Info */
181    off_t rsrclength;                  /* Size of resource fork */
182 };
183
184 /*
185  * Definition of the find_files packet passed as the
186  * first argument to the find_files callback subroutine.
187  */
188 struct FF_PKT {
189    char *top_fname;                   /* full filename before descending */
190    char *fname;                       /* full filename */
191    char *link;                        /* link if file linked */
192    char *object;                      /* restore object */
193    POOLMEM *sys_fname;                /* system filename */
194    POOLMEM *fname_save;               /* save when stripping path */
195    POOLMEM *link_save;                /* save when stripping path */
196    struct stat statp;                 /* stat packet */
197    int32_t FileIndex;                 /* FileIndex of this file */
198    int32_t LinkFI;                    /* FileIndex of main hard linked file */
199    int32_t object_len;                /* Object length */
200    struct f_link *linked;             /* Set if this file is hard linked */
201    int type;                          /* FT_ type from above */
202    int ff_errno;                      /* errno */
203    BFILE bfd;                         /* Bacula file descriptor */
204    time_t save_time;                  /* start of incremental time */
205    bool dereference;                  /* follow links (not implemented) */
206    bool null_output_device;           /* using null output device */
207    bool incremental;                  /* incremental save */
208    char VerifyOpts[20];
209    char AccurateOpts[20];
210    char BaseJobOpts[20];
211    struct s_included_file *included_files_list;
212    struct s_excluded_file *excluded_files_list;
213    struct s_excluded_file *excluded_paths_list;
214    findFILESET *fileset;
215    int (*file_save)(JCR *, FF_PKT *, bool); /* User's callback */
216    int (*plugin_save)(JCR *, FF_PKT *, bool); /* User's callback */
217    bool (*check_fct)(JCR *, FF_PKT *); /* optionnal user fct to check file changes */
218
219    /* Values set by accept_file while processing Options */
220    uint32_t flags;                    /* backup options */
221    int GZIP_level;                    /* compression level */
222    int strip_path;                    /* strip path count */
223    bool cmd_plugin;                   /* set if we have a command plugin */
224    alist fstypes;                     /* allowed file system types */
225    alist drivetypes;                  /* allowed drive types */
226
227    /* List of all hard linked files found */
228    struct f_link **linkhash;          /* hard linked files */
229
230    /* Darwin specific things.
231     * To avoid clutter, we always include rsrc_bfd and volhas_attrlist */
232    BFILE rsrc_bfd;                    /* fd for resource forks */
233    bool volhas_attrlist;              /* Volume supports getattrlist() */
234    struct HFSPLUS_INFO hfsinfo;       /* Finder Info and resource fork size */
235 };
236
237
238 #include "protos.h"
239
240 #endif /* __FILES_H */