]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/cats/bvfs.h
Merge branch 'master' into basejobv3
[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 /* Helper for result handler */
46 typedef enum {
47    BVFS_FILE_RECORD  = 5,
48    BVFS_DIR_RECORD   = 4,
49    BVFS_FILE_VERSION = 6
50 } bvfs_handler_type;
51
52 typedef enum {
53    BVFS_Id      = 0,
54    BVFS_Name    = 1,
55    BVFS_JobId   = 2,
56    BVFS_LStat   = 3,
57
58    BVFS_FileId  = 4,         /* Only if File record */
59 } bvfs_row_index;
60
61 class Bvfs {
62
63 public:
64    Bvfs(JCR *j, B_DB *mdb);
65    virtual ~Bvfs();
66
67    void set_jobid(JobId_t id) {
68       Mmsg(jobids, "%lld", (uint64_t)id);
69    }
70
71    void set_jobids(char *ids) {
72       pm_strcpy(jobids, ids);
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)*2+1;
85       pattern = check_pool_memory_size(pattern, len);
86       db_escape_string(jcr, db, pattern, p, len);
87    }
88
89    /* Get the root point */
90    DBId_t get_root();
91
92    /* It's much better to access Path though their PathId, it
93     * avoids mistakes with string encoding
94     */
95    void ch_dir(DBId_t pathid) {
96       pwd_id = pathid;
97    }
98
99    /* 
100     * Returns true if the directory exists
101     */
102    bool ch_dir(char *path);
103
104    void ls_files();
105    void ls_dirs();
106    void ls_special_dirs();      /* get . and .. */
107    void get_all_file_versions(DBId_t pathid, DBId_t fnid, char *client);
108
109    void update_cache();
110
111    void set_see_all_version(bool val) {
112       see_all_version = val;
113    }
114
115    void set_see_copies(bool val) {
116       see_copies = val;
117    }
118
119    void set_handler(DB_RESULT_HANDLER *h, void *ctx) {
120       list_entries = h;
121       user_data = ctx;
122    }
123
124    ATTR *get_attr() {
125       return attr;
126    }
127
128    JCR *get_jcr() {
129       return jcr;
130    }
131
132 private:   
133    JCR *jcr;
134    B_DB *db;
135    POOLMEM *jobids;
136    uint32_t limit;
137    uint32_t offset;
138    POOLMEM *pattern;
139    DBId_t pwd_id;
140    DBId_t dir_filenameid;
141    ATTR *attr;
142
143    bool see_all_version;
144    bool see_copies;
145
146    DBId_t get_dir_filenameid();
147    
148    DB_RESULT_HANDLER *list_entries;
149    void *user_data;
150 };
151
152 void bvfs_update_path_hierarchy_cache(JCR *jcr, B_DB *mdb, char *jobids);
153 void bvfs_update_cache(JCR *jcr, B_DB *mdb);
154 char *bvfs_parent_dir(char *path);
155
156 /* Return the basename of the with the trailing /  (update the given string)
157  * TODO: see in the rest of bacula if we don't have
158  * this function already
159  */
160 char *bvfs_basename_dir(char *path);
161
162
163 #endif /* __BVFS_H_ */