1 /*
2    Bacula(R) - The Network Backup Solution
3 
4    Copyright (C) 2000-2015 Kern Sibbald
5 
6    The original author of Bacula is Kern Sibbald, with contributions
7    from many others, a complete list can be found in the file AUTHORS.
8 
9    You may use this file and others of this release according to the
10    license defined in the LICENSE file, which includes the Affero General
11    Public License, v3.0 ("AGPLv3") and some additional permissions and
12    terms pursuant to its AGPLv3 Section 7.
13 
14    This notice must be preserved when any source code is
15    conveyed and/or propagated.
16 
17    Bacula(R) is a registered trademark of Kern Sibbald.
18 */
19 /*
20  * File types as returned by find_files()
21  *
22  *     Kern Sibbald MMI
23  */
24 
25 #ifndef __FILES_H
26 #define __FILES_H
27 
28 #include "jcr.h"
29 #include "fileopts.h"
30 #include "bfile.h"
31 #include "../filed/fd_plugins.h"
32 
33 #ifdef HAVE_DIRENT_H
34 #include <dirent.h>
35 #endif
36 
37 #include <sys/file.h>
38 #if !defined(HAVE_WIN32) || defined(HAVE_MINGW)
39 #include <sys/param.h>
40 #endif
41 #if HAVE_UTIME_H
42 #include <utime.h>
43 #else
44 struct utimbuf {
45     long actime;
46     long modtime;
47 };
48 #endif
49 
50 #define MODE_RALL (S_IRUSR|S_IRGRP|S_IROTH)
51 
52 #include "lib/fnmatch.h"
53 // #include "lib/enh_fnmatch.h"
54 
55 #ifndef HAVE_REGEX_H
56 #include "lib/bregex.h"
57 #else
58 #include <regex.h>
59 #endif
60 
61 /* For options FO_xxx values see src/fileopts.h */
62 
63 struct s_included_file {
64    struct s_included_file *next;
65    uint64_t options;                  /* backup options */
66    uint32_t algo;                     /* compression algorithm. 4 letters stored as an interger */
67    int Compress_level;                /* compression level */
68    int len;                           /* length of fname */
69    int pattern;                       /* set if wild card pattern */
70    char VerifyOpts[20];               /* Options for verify */
71    char fname[1];
72 };
73 
74 struct s_excluded_file {
75    struct s_excluded_file *next;
76    int len;
77    char fname[1];
78 };
79 
80 /* FileSet definitions very similar to the resource
81  *  contained in the Director because the components
82  *  of the structure are passed by the Director to the
83  *  File daemon and recompiled back into this structure
84  */
85 #undef  MAX_FOPTS
86 #define MAX_FOPTS 30
87 
88 enum {
89    state_none,
90    state_options,
91    state_include,
92    state_error
93 };
94 
95 /* File options structure */
96 struct findFOPTS {
97    uint64_t flags;                    /* options in bits */
98    uint32_t Compress_algo;            /* compression algorithm. 4 letters stored as an interger */
99    int Compress_level;                /* compression level */
100    int strip_path;                    /* strip path count */
101    char VerifyOpts[MAX_FOPTS];        /* verify options */
102    char AccurateOpts[MAX_FOPTS];      /* accurate mode options */
103    char BaseJobOpts[MAX_FOPTS];       /* basejob mode options */
104    char *plugin;                      /* Plugin that handle this section */
105    alist regex;                       /* regex string(s) */
106    alist regexdir;                    /* regex string(s) for directories */
107    alist regexfile;                   /* regex string(s) for files */
108    alist wild;                        /* wild card strings */
109    alist wilddir;                     /* wild card strings for directories */
110    alist wildfile;                    /* wild card strings for files */
111    alist wildbase;                    /* wild card strings for basenames */
112    alist base;                        /* list of base names */
113    alist fstype;                      /* file system type limitation */
114    alist drivetype;                   /* drive type limitation */
115 };
116 
117 
118 /* This is either an include item or an exclude item */
119 struct findINCEXE {
120    findFOPTS *current_opts;           /* points to current options structure */
121    alist opts_list;                   /* options list */
122    dlist name_list;                   /* filename list -- holds dlistString */
123    dlist plugin_list;                 /* plugin list -- holds dlistString */
124    char *ignoredir;                   /* ignore directories with this file */
125 };
126 
127 /*
128  *   FileSet Resource
129  *
130  */
131 struct findFILESET {
132    int state;
133    findINCEXE *incexe;                /* current item */
134    alist include_list;
135    alist exclude_list;
136 };
137 
138 struct HFSPLUS_INFO {
139    unsigned long length;              /* Mandatory field */
140    char fndrinfo[32];                 /* Finder Info */
141    off_t rsrclength;                  /* Size of resource fork */
142 };
143 
144 /*
145  * Definition of the find_files packet passed as the
146  * first argument to the find_files callback subroutine.
147  */
148 struct FF_PKT {
149    char *top_fname;                   /* full filename before descending */
150    char *fname;                       /* full filename */
151    char *link;                        /* link if file linked */
152    char *object_name;                 /* Object name */
153    char *object;                      /* restore object */
154    char *plugin;                      /* Current Options{Plugin=} name */
155 
156    /* Specific snapshot part */
157    char *volume_path;                 /* volume path */
158    char *snapshot_path;               /* snapshot path */
159    char *top_fname_save;
160    POOLMEM *snap_fname;               /* buffer used when stripping path */
161    POOLMEM *snap_top_fname;
162    bool strip_snap_path;              /* convert snapshot path or not */
163    bool (*snapshot_convert_fct)(JCR *jcr, FF_PKT *ff, dlist *filelist, dlistString *node);
164 
165    POOLMEM *sys_fname;                /* system filename */
166    POOLMEM *fname_save;               /* save when stripping path */
167    POOLMEM *link_save;                /* save when stripping path */
168    POOLMEM *ignoredir_fname;          /* used to ignore directories */
169    char *digest;                      /* set to file digest when the file is a hardlink */
170    struct stat statp;                 /* stat packet */
171    uint32_t digest_len;               /* set to the digest len when the file is a hardlink*/
172    int32_t digest_stream;             /* set to digest type when the file is hardlink */
173    int32_t FileIndex;                 /* FileIndex of this file */
174    int32_t LinkFI;                    /* FileIndex of main hard linked file */
175    int32_t delta_seq;                 /* Delta Sequence number */
176    int32_t object_index;              /* Object index */
177    int32_t object_len;                /* Object length */
178    int32_t object_compression;        /* Type of compression for object */
179    struct f_link *linked;             /* Set if this file is hard linked */
180    int type;                          /* FT_ type from above */
181    int ff_errno;                      /* errno */
182    BFILE bfd;                         /* Bacula file descriptor */
183    time_t save_time;                  /* start of incremental time */
184    bool accurate_found;               /* Found in the accurate hash (valid after check_changes()) */
185    bool dereference;                  /* follow links (not implemented) */
186    bool null_output_device;           /* using null output device */
187    bool incremental;                  /* incremental save */
188    bool no_read;                      /* Do not read this file when using Plugin */
189    char VerifyOpts[20];
190    char AccurateOpts[20];
191    char BaseJobOpts[20];
192    struct s_included_file *included_files_list;
193    struct s_excluded_file *excluded_files_list;
194    struct s_excluded_file *excluded_paths_list;
195    findFILESET *fileset;
196    int (*file_save)(JCR *, FF_PKT *, bool); /* User's callback */
197    int (*plugin_save)(JCR *, FF_PKT *, bool); /* User's callback */
198    bool (*check_fct)(JCR *, FF_PKT *); /* optionnal user fct to check file changes */
199 
200    /* Values set by accept_file while processing Options */
201    uint64_t flags;                    /* backup options */
202    uint32_t Compress_algo;            /* compression algorithm. 4 letters stored as an interger */
203    int Compress_level;                /* compression level */
204    int strip_path;                    /* strip path count */
205    bool cmd_plugin;                   /* set if we have a command plugin */
206    bool opt_plugin;                   /* set if we have an option plugin */
207    rblist *mtab_list;                 /* List of mtab entries */
208    uint64_t last_fstype;              /* cache last file system type */
209    char last_fstypename[32];          /* cache last file system type name */
210    alist fstypes;                     /* allowed file system types */
211    alist drivetypes;                  /* allowed drive types */
212    alist mount_points;                /* Possible mount points to be snapshotted */
213 
214    /* List of all hard linked files found */
215    struct f_link **linkhash;          /* hard linked files */
216 
217    /* Darwin specific things.
218     * To avoid clutter, we always include rsrc_bfd and volhas_attrlist */
219    BFILE rsrc_bfd;                    /* fd for resource forks */
220    bool volhas_attrlist;              /* Volume supports getattrlist() */
221    struct HFSPLUS_INFO hfsinfo;       /* Finder Info and resource fork size */
222 };
223 
224 typedef void (mtab_handler_t)(void *user_ctx, struct stat *st,
225                const char *fstype, const char *mountpoint,
226                const char *mntopts, const char *fsname);
227 bool read_mtab(mtab_handler_t *mtab_handler, void *user_ctx);
228 
229 #include "protos.h"
230 
231 #endif /* __FILES_H */
232