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