]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/cats/bvfs.h
bvfs: add clear_cache function
[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 three of the GNU Affero 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 Affero 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  = 'F',
48    BVFS_DIR_RECORD   = 'D',
49    BVFS_FILE_VERSION = 'V'
50 } bvfs_handler_type;
51
52 typedef enum {
53    BVFS_Type    = 0,            /* Could be D, F, V */
54    BVFS_PathId  = 1, 
55    BVFS_FilenameId = 2,
56
57    BVFS_Name    = 3,
58    BVFS_JobId   = 4,
59
60    BVFS_LStat   = 5,            /* Can be empty for missing directories */
61    BVFS_FileId  = 6,            /* Can be empty for missing directories */
62
63    /* Only if File Version record */
64    BVFS_Md5     = 3,
65    BVFS_VolName = 7,
66    BVFS_VolInchanger = 8
67 } bvfs_row_index;
68
69 class Bvfs {
70
71 public:
72    Bvfs(JCR *j, B_DB *mdb);
73    virtual ~Bvfs();
74
75    void set_jobid(JobId_t id);
76    void set_jobids(char *ids);
77
78    void set_limit(uint32_t max) {
79       limit = max;
80    }
81
82    void set_offset(uint32_t nb) {
83       offset = nb;
84    }
85
86    void set_pattern(char *p) {
87       uint32_t len = strlen(p);
88       pattern = check_pool_memory_size(pattern, len*2+1);
89       db_escape_string(jcr, db, pattern, p, len);
90    }
91
92    /* Get the root point */
93    DBId_t get_root();
94
95    /* It's much better to access Path though their PathId, it
96     * avoids mistakes with string encoding
97     */
98    void ch_dir(DBId_t pathid) {
99       reset_offset();
100       pwd_id = pathid;
101    }
102
103    /* 
104     * Returns true if the directory exists
105     */
106    bool ch_dir(const char *path);
107
108    bool ls_files();             /* Returns true if we have more files to read */
109    bool ls_dirs();              /* Returns true if we have more dir to read */
110    void ls_special_dirs();      /* get . and .. */
111    void get_all_file_versions(DBId_t pathid, DBId_t fnid, const char *client);
112
113    void update_cache();
114
115    void set_see_all_versions(bool val) {
116       see_all_versions = val;
117    }
118
119    void set_see_copies(bool val) {
120       see_copies = val;
121    }
122
123    void filter_jobid();         /* Call after set_username */
124
125    void set_username(char *user) {
126       if (user) {
127          username = bstrdup(user);
128       }
129    }
130
131    void set_handler(DB_RESULT_HANDLER *h, void *ctx) {
132       list_entries = h;
133       user_data = ctx;
134    }
135
136    DBId_t get_pwd() {
137       return pwd_id;
138    }
139
140    ATTR *get_attr() {
141       return attr;
142    }
143
144    JCR *get_jcr() {
145       return jcr;
146    }
147
148    void reset_offset() {
149       offset=0;
150    }
151
152    void next_offset() {
153       offset+=limit;
154    }
155
156    /* Clear all cache */
157    void clear_cache();
158
159    /* Compute restore list */
160    bool compute_restore_list(char *fileid, char *dirid, char *hardlink, 
161                              char *output_table);
162    
163    /* Drop previous restore list */
164    bool drop_restore_list(char *output_table);
165
166    /* for internal use */
167    int _handle_path(void *, int, char **);
168    
169 private:
170    Bvfs(const Bvfs &);               /* prohibit pass by value */
171    Bvfs & operator = (const Bvfs &); /* prohibit class assignment */
172
173    JCR *jcr;
174    B_DB *db;
175    POOLMEM *jobids;
176    char *username;              /* Used with Bweb */
177    uint32_t limit;
178    uint32_t offset;
179    uint32_t nb_record;          /* number of records of the last query */
180    POOLMEM *pattern;
181    DBId_t pwd_id;               /* Current pathid */
182    DBId_t dir_filenameid;       /* special FilenameId where Name='' */
183    POOLMEM *prev_dir; /* ls_dirs query returns all versions, take the 1st one */
184    ATTR *attr;        /* Can be use by handler to call decode_stat() */
185
186    bool see_all_versions;
187    bool see_copies;
188
189    DBId_t get_dir_filenameid();
190
191    DB_RESULT_HANDLER *list_entries;
192    void *user_data;
193 };
194
195 #define bvfs_is_dir(row) ((row)[BVFS_Type][0] == BVFS_DIR_RECORD)
196 #define bvfs_is_file(row) ((row)[BVFS_Type][0] == BVFS_FILE_RECORD)
197 #define bvfs_is_version(row) ((row)[BVFS_Type][0] == BVFS_FILE_VERSION)
198
199
200 void bvfs_update_path_hierarchy_cache(JCR *jcr, B_DB *mdb, char *jobids);
201 void bvfs_update_cache(JCR *jcr, B_DB *mdb);
202 char *bvfs_parent_dir(char *path);
203
204 /* Return the basename of the with the trailing /  (update the given string)
205  * TODO: see in the rest of bacula if we don't have
206  * this function already
207  */
208 char *bvfs_basename_dir(char *path);
209
210
211 #endif /* __BVFS_H_ */