1 /* 2 Bacula(R) - The Network Backup Solution 3 4 Copyright (C) 2000-2020 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 Dedup_level; /* Dedup level */ 68 int Compress_level; /* compression level */ 69 int len; /* length of fname */ 70 int pattern; /* set if wild card pattern */ 71 char VerifyOpts[20]; /* Options for verify */ 72 char fname[1]; 73 }; 74 75 struct s_excluded_file { 76 struct s_excluded_file *next; 77 int len; 78 char fname[1]; 79 }; 80 81 /* FileSet definitions very similar to the resource 82 * contained in the Director because the components 83 * of the structure are passed by the Director to the 84 * File daemon and recompiled back into this structure 85 */ 86 #undef MAX_FOPTS 87 #define MAX_FOPTS 30 88 89 enum { 90 state_none, 91 state_options, 92 state_include, 93 state_error 94 }; 95 96 /* File options structure */ 97 struct findFOPTS { 98 uint64_t flags; /* options in bits */ 99 uint32_t Compress_algo; /* compression algorithm. 4 letters stored as an interger */ 100 int Compress_level; /* compression level */ 101 int Dedup_level; /* dedup level 0=None, 1=Global, 2=Client */ 102 int strip_path; /* strip path count */ 103 char VerifyOpts[MAX_FOPTS]; /* verify options */ 104 char AccurateOpts[MAX_FOPTS]; /* accurate mode options */ 105 char BaseJobOpts[MAX_FOPTS]; /* basejob mode options */ 106 char *plugin; /* Plugin that handle this section */ 107 alist regex; /* regex string(s) */ 108 alist regexdir; /* regex string(s) for directories */ 109 alist regexfile; /* regex string(s) for files */ 110 alist wild; /* wild card strings */ 111 alist wilddir; /* wild card strings for directories */ 112 alist wildfile; /* wild card strings for files */ 113 alist wildbase; /* wild card strings for basenames */ 114 alist base; /* list of base names */ 115 alist fstype; /* file system type limitation */ 116 alist drivetype; /* drive type limitation */ 117 }; 118 119 120 /* This is either an include item or an exclude item */ 121 struct findINCEXE { 122 findFOPTS *current_opts; /* points to current options structure */ 123 alist opts_list; /* options list */ 124 dlist name_list; /* filename list -- holds dlistString */ 125 dlist plugin_list; /* plugin list -- holds dlistString */ 126 char *ignoredir; /* ignore directories with this file */ 127 bool list_drives; /* list drives on win32 (File=/) */ 128 }; 129 130 /* 131 * FileSet Resource 132 * 133 */ 134 struct findFILESET { 135 int state; 136 findINCEXE *incexe; /* current item */ 137 alist include_list; 138 alist exclude_list; 139 }; 140 141 struct HFSPLUS_INFO { 142 unsigned long length; /* Mandatory field */ 143 char fndrinfo[32]; /* Finder Info */ 144 off_t rsrclength; /* Size of resource fork */ 145 }; 146 147 /* 148 * Definition of the find_files packet passed as the 149 * first argument to the find_files callback subroutine. 150 */ 151 struct FF_PKT { 152 char *top_fname; /* full filename before descending */ 153 char *fname; /* full filename */ 154 char *snap_fname; /* the path on the snapshot or fname */ 155 char *link; /* link if file linked */ 156 char *object_name; /* Object name */ 157 char *object; /* restore object */ 158 char *plugin; /* Current Options{Plugin=} name */ 159 160 /* Specific snapshot part */ 161 char *volume_path; /* volume path */ 162 char *snapshot_path; /* snapshot path */ 163 char *top_fname_save; 164 POOLMEM *snap_top_fname; 165 bool (*snapshot_convert_fct)(JCR *jcr, FF_PKT *ff, dlist *filelist, dlistString *node); 166 bool root_of_volume; /* the root of a volume, like C:\ or C:\mount_point\ssd */ 167 168 POOLMEM *fname_save; /* save when stripping path */ 169 POOLMEM *link_save; /* save when stripping path */ 170 POOLMEM *ignoredir_fname; /* used to ignore directories */ 171 char *digest; /* set to file digest when the file is a hardlink */ 172 struct stat statp; /* stat packet */ 173 uint32_t digest_len; /* set to the digest len when the file is a hardlink*/ 174 int32_t digest_stream; /* set to digest type when the file is hardlink */ 175 int32_t FileIndex; /* FileIndex of this file */ 176 int32_t LinkFI; /* FileIndex of main hard linked file */ 177 int32_t delta_seq; /* Delta Sequence number */ 178 int32_t object_index; /* Object index */ 179 int32_t object_len; /* Object length */ 180 int32_t object_compression; /* Type of compression for object */ 181 struct f_link *linked; /* Set if this file is hard linked */ 182 int type; /* FT_ type from above */ 183 int ff_errno; /* errno */ 184 BFILE bfd; /* Bacula file descriptor */ 185 time_t save_time; /* start of incremental time */ 186 bool accurate_found; /* Found in the accurate hash (valid after check_changes()) */ 187 bool dereference; /* follow links (not implemented) */ 188 bool null_output_device; /* using null output device */ 189 bool incremental; /* incremental save */ 190 bool no_read; /* Do not read this file when using Plugin */ 191 char VerifyOpts[20]; 192 char AccurateOpts[20]; 193 char BaseJobOpts[20]; 194 struct s_included_file *included_files_list; 195 struct s_excluded_file *excluded_files_list; 196 struct s_excluded_file *excluded_paths_list; 197 findFILESET *fileset; 198 int (*file_save)(JCR *, FF_PKT *, bool); /* User's callback */ 199 int (*plugin_save)(JCR *, FF_PKT *, bool); /* User's callback */ 200 bool (*check_fct)(JCR *, FF_PKT *); /* optionnal user fct to check file changes */ 201 202 /* Values set by accept_file while processing Options */ 203 uint64_t flags; /* backup options */ 204 uint32_t Compress_algo; /* compression algorithm. 4 letters stored as an interger */ 205 int Compress_level; /* compression level */ 206 int Dedup_level; /* dedup level 0=None, 1=Global, 2=Client */ 207 int strip_path; /* strip path count */ 208 bool cmd_plugin; /* set if we have a command plugin */ 209 bool opt_plugin; /* set if we have an option plugin */ 210 rblist *mtab_list; /* List of mtab entries */ 211 uint64_t last_fstype; /* cache last file system type */ 212 char last_fstypename[32]; /* cache last file system type name */ 213 alist fstypes; /* allowed file system types */ 214 alist drivetypes; /* allowed drive types */ 215 alist mount_points; /* Possible mount points to be snapshotted */ 216 217 /* List of all hard linked files found */ 218 struct f_link **linkhash; /* hard linked files */ 219 220 /* Darwin specific things. 221 * To avoid clutter, we always include rsrc_bfd and volhas_attrlist */ 222 BFILE rsrc_bfd; /* fd for resource forks */ 223 bool volhas_attrlist; /* Volume supports getattrlist() */ 224 struct HFSPLUS_INFO hfsinfo; /* Finder Info and resource fork size */ 225 }; 226 227 typedef void (mtab_handler_t)(void *user_ctx, struct stat *st, 228 const char *fstype, const char *mountpoint, 229 const char *mntopts, const char *fsname); 230 bool read_mtab(mtab_handler_t *mtab_handler, void *user_ctx); 231 232 #include "protos.h" 233 234 #endif /* __FILES_H */ 235