]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/cats/bvfs.h
Backport from Bacula Enterprise
[bacula/bacula] / bacula / src / cats / bvfs.h
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2015 Kern Sibbald
5    Copyright (C) 2000-2014 Free Software Foundation Europe e.V.
6
7    The original author of Bacula is Kern Sibbald, with contributions
8    from many others, a complete list can be found in the file AUTHORS.
9
10    You may use this file and others of this release according to the
11    license defined in the LICENSE file, which includes the Affero General
12    Public License, v3.0 ("AGPLv3") and some additional permissions and
13    terms pursuant to its AGPLv3 Section 7.
14
15    This notice must be preserved when any source code is 
16    conveyed and/or propagated.
17
18    Bacula(R) is a registered trademark of Kern Sibbald.
19 */
20
21
22 #ifndef __BVFS_H_
23 #define __BVFS_H_ 1
24
25
26 /*
27  * This object can be use to browse the catalog
28  *
29  * Bvfs fs;
30  * fs.set_jobid(10);
31  * fs.update_cache();
32  * fs.ch_dir("/");
33  * fs.ls_dirs();
34  * fs.ls_files();
35  */
36
37 /* Helper for result handler */
38 typedef enum {
39    BVFS_FILE_RECORD  = 'F',
40    BVFS_DIR_RECORD   = 'D',
41    BVFS_FILE_VERSION = 'V',
42    BVFS_VOLUME_LIST  = 'L'
43 } bvfs_handler_type;
44
45 typedef enum {
46    BVFS_Type    = 0,            /* Could be D, F, V, L */
47    BVFS_PathId  = 1, 
48    BVFS_FilenameId = 2,
49
50    BVFS_Name    = 3,
51    BVFS_JobId   = 4,
52
53    BVFS_LStat   = 5,            /* Can be empty for missing directories */
54    BVFS_FileId  = 6,            /* Can be empty for missing directories */
55
56    /* Only if File Version record */
57    BVFS_Md5     = 3,
58    BVFS_VolName = 7,
59    BVFS_VolInchanger = 8
60 } bvfs_row_index;
61
62 class Bvfs {
63
64 public:
65    Bvfs(JCR *j, BDB *mdb);
66    virtual ~Bvfs();
67
68    void set_jobid(JobId_t id);
69    void set_jobids(char *ids);
70
71    char *get_jobids() {
72       return jobids;
73    }
74
75    void set_limit(uint32_t max) {
76       limit = max;
77    }
78
79    void set_offset(uint32_t nb) {
80       offset = nb;
81    }
82
83    void set_pattern(char *p) {
84       uint32_t len = strlen(p);
85       pattern = check_pool_memory_size(pattern, len*2+1);
86       db->bdb_escape_string(jcr, pattern, p, len);
87    }
88
89    void set_filename(char *p) {
90       uint32_t len = strlen(p);
91       filename = check_pool_memory_size(filename, len*2+1);
92       db->bdb_escape_string(jcr, filename, p, len);
93    }
94
95    /* Get the root point */
96    DBId_t get_root();
97
98    /* It's much better to access Path though their PathId, it
99     * avoids mistakes with string encoding
100     */
101    void ch_dir(DBId_t pathid) {
102       reset_offset();
103       pwd_id = pathid;
104    }
105
106    /*
107     * Returns true if the directory exists
108     */
109    bool ch_dir(const char *path);
110
111    bool ls_files();             /* Returns true if we have more files to read */
112    bool ls_dirs();              /* Returns true if we have more dir to read */
113    void ls_special_dirs();      /* get . and .. */
114    void get_all_file_versions(DBId_t pathid, FileId_t fnid, const char *client);
115
116    void update_cache();
117
118    /* bfileview */
119    void fv_update_cache();
120
121    void set_see_all_versions(bool val) {
122       see_all_versions = val;
123    }
124
125    void set_see_copies(bool val) {
126       see_copies = val;
127    }
128
129    void filter_jobid();         /* Call after set_username */
130
131    void set_username(char *user) {
132       if (user) {
133          username = bstrdup(user);
134       }
135    }
136
137    char *escape_list(alist *list);
138
139    bool copy_acl(alist *list) {
140       if (!list ||
141           (list->size() > 0 &&
142            (strcasecmp((char *)list->get(0), "*all*") == 0)))
143       {
144          return false;
145       }
146       return true;
147    }
148
149    /* Keep a pointer to various ACLs */
150    void set_job_acl(alist *lst) {
151       job_acl = copy_acl(lst)?lst:NULL;
152    }
153    void set_fileset_acl(alist *lst) {
154       fileset_acl = copy_acl(lst)?lst:NULL;
155    }
156    void set_client_acl(alist *lst) {
157       client_acl = copy_acl(lst)?lst:NULL;
158    }
159    void set_pool_acl(alist *lst) {
160       pool_acl = copy_acl(lst)?lst:NULL;
161    }
162
163    void set_handler(DB_RESULT_HANDLER *h, void *ctx) {
164       list_entries = h;
165       user_data = ctx;
166    }
167
168    DBId_t get_pwd() {
169       return pwd_id;
170    }
171
172    ATTR *get_attr() {
173       return attr;
174    }
175
176    JCR *get_jcr() {
177       return jcr;
178    }
179
180    void reset_offset() {
181       offset=0;
182    }
183
184    void next_offset() {
185       offset+=limit;
186    }
187
188    /* Clear all cache */
189    void clear_cache();
190
191    /* Compute restore list */
192    bool compute_restore_list(char *fileid, char *dirid, char *hardlink,
193                              char *output_table);
194
195    /* Drop previous restore list */
196    bool drop_restore_list(char *output_table);
197
198    /* for internal use */
199    int _handle_path(void *, int, char **);
200
201    /* Handle Delta parts if any */
202    void insert_missing_delta(char *output_table, int64_t *res);
203
204    /* Get a list of volumes */
205    void get_volumes(FileId_t fileid);
206
207 private:
208    Bvfs(const Bvfs &);               /* prohibit pass by value */
209    Bvfs & operator = (const Bvfs &); /* prohibit class assignment */
210
211    JCR *jcr;
212    BDB *db;
213    POOLMEM *jobids;
214    char *username;              /* Used with Bweb */
215
216    POOLMEM *prev_dir; /* ls_dirs query returns all versions, take the 1st one */
217    POOLMEM *pattern;
218    POOLMEM *filename;
219
220    POOLMEM *tmp;
221    POOLMEM *escaped_list;
222
223    /* Pointer to Console ACL */
224    alist *job_acl;
225    alist *client_acl;
226    alist *fileset_acl;
227    alist *pool_acl;
228
229    ATTR *attr;        /* Can be use by handler to call decode_stat() */
230
231    uint32_t limit;
232    uint32_t offset;
233    uint32_t nb_record;          /* number of records of the last query */
234    DBId_t pwd_id;               /* Current pathid */
235    DBId_t dir_filenameid;       /* special FilenameId where Name='' */
236
237    bool see_all_versions;
238    bool see_copies;
239
240    DBId_t get_dir_filenameid();
241
242    /* bfileview */
243    void fv_get_big_files(int64_t pathid, int64_t min_size, int32_t limit);
244    void fv_update_size_and_count(int64_t pathid, int64_t size, int64_t count);
245    void fv_compute_size_and_count(int64_t pathid, int64_t *size, int64_t *count);
246    void fv_get_current_size_and_count(int64_t pathid, int64_t *size, int64_t *count);
247    void fv_get_size_and_count(int64_t pathid, int64_t *size, int64_t *count);
248
249    DB_RESULT_HANDLER *list_entries;
250    void *user_data;
251 };
252
253 #define bvfs_is_dir(row) ((row)[BVFS_Type][0] == BVFS_DIR_RECORD)
254 #define bvfs_is_file(row) ((row)[BVFS_Type][0] == BVFS_FILE_RECORD)
255 #define bvfs_is_version(row) ((row)[BVFS_Type][0] == BVFS_FILE_VERSION)
256 #define bvfs_is_volume_list(row) ((row)[BVFS_Type][0] == BVFS_VOLUME_LIST)
257
258 void bvfs_update_fv_cache(JCR *jcr, BDB *mdb, char *jobids);
259 int bvfs_update_path_hierarchy_cache(JCR *jcr, BDB *mdb, char *jobids);
260 void bvfs_update_cache(JCR *jcr, BDB *mdb);
261 char *bvfs_parent_dir(char *path);
262
263 /* Return the basename of the with the trailing /  (update the given string)
264  * TODO: see in the rest of bacula if we don't have
265  * this function already
266  */
267 char *bvfs_basename_dir(char *path);
268
269
270 #endif /* __BVFS_H_ */