]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/cats/bvfs.h
Add a new Bvfs class that implements brestore instant navigation
[bacula/bacula] / bacula / src / cats / bvfs.h
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2000-2009 Free Software Foundation Europe e.V.
5
6    The main author of Bacula is Kern Sibbald, with contributions from
7    many others, a complete list can be found in the file AUTHORS.
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version two of the GNU General Public
10    License as published by the Free Software Foundation and included
11    in the file LICENSE.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23    Bacula® is a registered trademark of Kern Sibbald.
24    The licensor of Bacula is the Free Software Foundation Europe
25    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26    Switzerland, email:ftf@fsfeurope.org.
27 */
28
29
30 #ifndef __BVFS_H_
31 #define __BVFS_H_ 1
32
33
34 /* 
35  * This object can be use to browse the catalog
36  *
37  * Bvfs fs;
38  * fs.set_jobid(10);
39  * fs.update_cache();
40  * fs.ch_dir("/");
41  * fs.ls_dirs();
42  * fs.ls_files();
43  */
44
45 class Bvfs {
46
47 public:
48    Bvfs(JCR *j, B_DB *mdb) {
49       jcr = j;
50       jcr->inc_use_count();
51       db = mdb;                 /* need to inc ref count */
52       jobids = get_pool_memory(PM_NAME);
53       pattern = get_pool_memory(PM_NAME);
54       *pattern = *jobids = 0;
55       dir_filenameid = pwd_id = offset = 0;
56       see_copies = see_all_version = false;
57       limit = 1000;
58    }
59
60    virtual ~Bvfs() {
61       free_pool_memory(jobids);
62       free_pool_memory(pattern);
63       jcr->dec_use_count();
64    }
65
66    void set_jobid(JobId_t id) {
67       Mmsg(jobids, "%lld", (uint64_t)id);
68    }
69
70    void set_jobids(char *ids) {
71       pm_strcpy(jobids, ids);
72    }
73
74    void set_limit(uint32_t max) {
75       limit = max;
76    }
77
78    void set_offset(uint32_t nb) {
79       offset = nb;
80    }
81
82    void set_pattern(char *p) {
83       uint32_t len = strlen(p)*2+1;
84       pattern = check_pool_memory_size(pattern, len);
85       db_escape_string(jcr, db, pattern, p, len);
86    }
87
88    /* Get the root point */
89    DBId_t get_root();
90
91    /* It's much better to access Path though their PathId, it
92     * avoids mistakes with string encoding
93     */
94    void ch_dir(DBId_t pathid) {
95       pwd_id = pathid;
96    }
97
98    /* 
99     * Returns true if the directory exists
100     */
101    bool ch_dir(char *path);
102
103    void ls_files();
104    void ls_dirs();
105    void ls_special_dirs();      /* get . and .. */
106    void get_all_file_versions(DBId_t pathid, DBId_t fnid, char *client);
107
108    void update_cache();
109
110    void set_see_all_version(bool val) {
111       see_all_version = val;
112    }
113
114    void set_see_copies(bool val) {
115       see_copies = val;
116    }
117
118 private:   
119    JCR *jcr;
120    B_DB *db;
121    POOLMEM *jobids;
122    uint32_t limit;
123    uint32_t offset;
124    POOLMEM *pattern;
125    DBId_t pwd_id;
126    DBId_t dir_filenameid;
127
128    bool see_all_version;
129    bool see_copies;
130
131    DBId_t get_dir_filenameid();
132 };
133
134 void bvfs_update_path_hierarchy_cache(JCR *jcr, B_DB *mdb, char *jobids);
135 void bvfs_update_cache(JCR *jcr, B_DB *mdb);
136 char *bvfs_parent_dir(char *path);
137
138 /* Return the basename of the with the trailing /  (update the given string)
139  * TODO: see in the rest of bacula if we don't have
140  * this function already
141  */
142 char *bvfs_basename_dir(char *path);
143
144
145 #endif /* __BVFS_H_ */