2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2017 Kern Sibbald
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.
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.
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
25 * This object can be use to browse the catalog
35 /* Helper for result handler */
37 BVFS_FILE_RECORD = 'F',
38 BVFS_DIR_RECORD = 'D',
39 BVFS_FILE_VERSION = 'V',
40 BVFS_VOLUME_LIST = 'L',
41 BVFS_DELTA_RECORD = 'd',
45 BVFS_Type = 0, /* Could be D, F, V, L */
49 BVFS_Name = 3, /* Can be empty for File version */
52 BVFS_LStat = 5, /* Can be empty for missing directories */
53 BVFS_FileId = 6, /* Can be empty for missing directories */
55 /* Only if Path record */
58 /* Only if File Version record */
61 BVFS_VolInchanger = 9,
63 /* Only if Delta record */
71 Bvfs(JCR *j, BDB *mdb);
74 void set_compute_delta(bool val) {
78 /* Return the number of jobids after the filter */
79 int set_jobid(JobId_t id);
80 int set_jobids(char *ids);
86 void set_limit(uint32_t max) {
90 void set_offset(uint32_t nb) {
94 void set_pattern(char *p) {
95 uint32_t len = strlen(p);
96 pattern = check_pool_memory_size(pattern, len*2+1);
97 db->bdb_escape_string(jcr, pattern, p, len);
100 void set_filename(char *p) {
101 uint32_t len = strlen(p);
102 filename = check_pool_memory_size(filename, len*2+1);
103 db->bdb_escape_string(jcr, filename, p, len);
106 /* Get the root point */
109 /* It's much better to access Path though their PathId, it
110 * avoids mistakes with string encoding
112 bool ch_dir(DBId_t pathid);
115 * Returns true if the directory exists
117 bool ch_dir(const char *path);
119 bool ls_files(); /* Returns true if we have more files to read */
120 bool ls_dirs(); /* Returns true if we have more dir to read */
121 void ls_special_dirs(); /* get . and .. */
122 void get_all_file_versions(DBId_t pathid, FileId_t fnid, const char *client);
127 void fv_update_cache();
129 void set_see_all_versions(bool val) {
130 see_all_versions = val;
133 void set_see_copies(bool val) {
137 DBId_t get_dir_filenameid();
139 int filter_jobid(); /* Call after set_username, returns the number of jobids */
141 void set_username(char *user) {
143 username = bstrdup(user);
147 char *escape_list(alist *list);
149 bool copy_acl(alist *list) {
152 (strcasecmp((char *)list->get(0), "*all*") == 0)))
159 /* Keep a pointer to various ACLs */
160 void set_job_acl(alist *lst) {
161 job_acl = copy_acl(lst)?lst:NULL;
164 void set_fileset_acl(alist *lst) {
165 fileset_acl = copy_acl(lst)?lst:NULL;
168 void set_client_acl(alist *lst) {
169 client_acl = copy_acl(lst)?lst:NULL;
172 void set_pool_acl(alist *lst) {
173 pool_acl = copy_acl(lst)?lst:NULL;
176 void set_handler(DB_RESULT_HANDLER *h, void *ctx) {
193 void reset_offset() {
201 /* Clear all cache */
204 /* Compute restore list */
205 bool compute_restore_list(char *fileid, char *dirid, char *hardlink,
208 /* Drop previous restore list */
209 bool drop_restore_list(char *output_table);
211 /* for internal use */
212 int _handle_path(void *, int, char **);
214 /* Handle Delta parts if any */
215 void insert_missing_delta(char *output_table, int64_t *res);
217 /* Get a list of volumes */
218 void get_volumes(FileId_t fileid);
220 /* Get Delta parts of a file */
221 bool get_delta(FileId_t fileid);
223 /* Check if the parent directories are accessible */
224 bool check_path_access(DBId_t pathid);
226 /* Check if the full path is authorized by the current set of ACLs */
227 bool check_full_path_access(int nb, sellist *sel, db_list_ctx *toexcl);
231 int check_dirs; /* When it's 1, we check the against directory_acl */
232 bool can_access(struct stat *st);
233 bool can_access_dir(const char *path);
236 Bvfs(const Bvfs &); /* prohibit pass by value */
237 Bvfs & operator = (const Bvfs &); /* prohibit class assignment */
242 char *username; /* Used with Bweb */
244 POOLMEM *prev_dir; /* ls_dirs query returns all versions, take the 1st one */
249 POOLMEM *escaped_list;
251 /* Pointer to Console ACL */
258 ATTR *attr; /* Can be use by handler to call decode_stat() */
262 uint32_t nb_record; /* number of records of the last query */
263 DBId_t pwd_id; /* Current pathid */
264 DBId_t dir_filenameid; /* special FilenameId where Name='' */
266 bool see_all_versions;
270 db_list_ctx fileid_to_delete; /* used also by check_path_access */
271 bool need_to_check_permissions();
275 void fv_get_big_files(int64_t pathid, int64_t min_size, int32_t limit);
276 void fv_update_size_and_count(int64_t pathid, int64_t size, int64_t count);
277 void fv_compute_size_and_count(int64_t pathid, int64_t *size, int64_t *count);
278 void fv_get_current_size_and_count(int64_t pathid, int64_t *size, int64_t *count);
279 void fv_get_size_and_count(int64_t pathid, int64_t *size, int64_t *count);
281 DB_RESULT_HANDLER *list_entries;
285 #define bvfs_is_dir(row) ((row)[BVFS_Type][0] == BVFS_DIR_RECORD)
286 #define bvfs_is_file(row) ((row)[BVFS_Type][0] == BVFS_FILE_RECORD)
287 #define bvfs_is_version(row) ((row)[BVFS_Type][0] == BVFS_FILE_VERSION)
288 #define bvfs_is_volume_list(row) ((row)[BVFS_Type][0] == BVFS_VOLUME_LIST)
289 #define bvfs_is_delta_list(row) ((row)[BVFS_Type][0] == BVFS_DELTA_RECORD)
291 void bvfs_update_fv_cache(JCR *jcr, BDB *mdb, char *jobids);
292 int bvfs_update_path_hierarchy_cache(JCR *jcr, BDB *mdb, char *jobids);
293 void bvfs_update_cache(JCR *jcr, BDB *mdb);
294 char *bvfs_parent_dir(char *path);
296 /* Return the basename of the with the trailing / (update the given string)
297 * TODO: see in the rest of bacula if we don't have
298 * this function already
300 char *bvfs_basename_dir(char *path);
302 #endif /* __BVFS_H_ */