]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/stored/protos.h
Backport more master code
[bacula/bacula] / bacula / src / stored / protos.h
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2000-2012 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  * Protypes for stored -- Kern Sibbald MM  
30  *
31  */
32
33 /* From stored.c */
34 uint32_t new_VolSessionId();
35
36 /* From acquire.c */
37 DCR     *acquire_device_for_append(DCR *dcr);
38 bool     acquire_device_for_read(DCR *dcr);
39 bool     release_device(DCR *dcr);
40 bool     clean_device(DCR *dcr);
41 DCR     *new_dcr(JCR *jcr, DCR *dcr, DEVICE *dev);
42 void     free_dcr(DCR *dcr);
43
44 /* From append.c */
45 bool send_attrs_to_dir(JCR *jcr, DEV_RECORD *rec);
46
47 /* From askdir.c */
48 enum get_vol_info_rw {
49    GET_VOL_INFO_FOR_WRITE,
50    GET_VOL_INFO_FOR_READ
51 };
52 bool    dir_get_volume_info(DCR *dcr, enum get_vol_info_rw);
53 bool    dir_find_next_appendable_volume(DCR *dcr);
54 bool    dir_update_volume_info(DCR *dcr, bool label, bool update_LastWritten);
55 bool    dir_ask_sysop_to_create_appendable_volume(DCR *dcr);
56 bool    dir_ask_sysop_to_mount_volume(DCR *dcr, int mode);
57 bool    dir_update_file_attributes(DCR *dcr, DEV_RECORD *rec);
58 bool    dir_send_job_status(JCR *jcr);
59 bool    dir_create_jobmedia_record(DCR *dcr, bool zero=false);
60 bool    dir_update_device(JCR *jcr, DEVICE *dev);
61 bool    dir_update_changer(JCR *jcr, AUTOCHANGER *changer);
62
63 /* authenticate.c */
64 int     authenticate_director(JCR *jcr);
65 int     authenticate_filed(JCR *jcr);
66
67 /* From autochanger.c */
68 bool     init_autochangers();
69 int      autoload_device(DCR *dcr, int writing, BSOCK *dir);
70 bool     autochanger_cmd(DCR *dcr, BSOCK *dir, const char *cmd);
71 bool     unload_autochanger(DCR *dcr, int loaded);
72 bool     unload_dev(DCR *dcr, DEVICE *dev);
73 char    *edit_device_codes(DCR *dcr, char *omsg, const char *imsg, const char *cmd);
74 int      get_autochanger_loaded_slot(DCR *dcr);
75
76 /* From block.c */
77 void    dump_block(DEV_BLOCK *b, const char *msg);
78 DEV_BLOCK *new_block(DEVICE *dev);
79 DEV_BLOCK *dup_block(DEV_BLOCK *eblock);
80 void    init_block_write(DEV_BLOCK *block);
81 void    empty_block(DEV_BLOCK *block);
82 void    free_block(DEV_BLOCK *block);
83 void    print_block_read_errors(JCR *jcr, DEV_BLOCK *block);
84 void    ser_block_header(DEV_BLOCK *block);
85
86 /* From butil.c -- utilities for SD tool programs */
87 void    print_ls_output(const char *fname, const char *link, int type, struct stat *statp);
88 JCR    *setup_jcr(const char *name, char *dev_name, BSR *bsr,
89                   const char *VolumeName, int mode);
90 void    display_tape_error_status(JCR *jcr, DEVICE *dev);
91
92
93 /* From dev.c */
94 DEVICE  *init_dev(JCR *jcr, DEVRES *device);
95 bool     can_open_mounted_dev(DEVICE *dev);
96 bool     load_dev(DEVICE *dev);
97 int      write_block(DEVICE *dev);
98 uint32_t status_dev(DEVICE *dev);
99 void     attach_jcr_to_device(DEVICE *dev, JCR *jcr);
100 void     detach_jcr_from_device(DEVICE *dev, JCR *jcr);
101 JCR     *next_attached_jcr(DEVICE *dev, JCR *jcr);
102 void     init_device_wait_timers(DCR *dcr);
103 void     init_jcr_device_wait_timers(JCR *jcr);
104 bool     double_dev_wait_time(DEVICE *dev);
105
106 /* Get info about device */
107 char *   dev_vol_name(DEVICE *dev);
108
109 /* From dvd.c */
110 int     dvd_open_next_part(DCR *dcr);
111 bool    dvd_write_part(DCR *dcr); 
112 bool    dvd_close_job(DCR *dcr);
113 void    make_mounted_dvd_filename(DEVICE *dev, POOL_MEM &archive_name);
114 void    make_spooled_dvd_filename(DEVICE *dev, POOL_MEM &archive_name);
115 bool    truncate_dvd(DCR *dcr);
116 bool    check_can_write_on_non_blank_dvd(DCR *dcr);
117 int     find_num_dvd_parts(DCR *dcr);
118 boffset_t   lseek_dvd(DCR *dcr, boffset_t offset, int whence);
119 void    dvd_remove_empty_part(DCR *dcr);
120
121 /* From device.c */
122 bool     open_device(DCR *dcr);
123 bool     first_open_device(DCR *dcr);
124 bool     fixup_device_block_write_error(DCR *dcr, int retries=4);
125 void     set_start_vol_position(DCR *dcr);
126 void     set_new_volume_parameters(DCR *dcr);
127 void     set_new_file_parameters(DCR *dcr);
128
129 /* From dircmd.c */
130 void     *handle_connection_request(void *arg);
131
132
133 /* From fd_cmds.c */
134 void     run_job(JCR *jcr);
135 void     do_fd_commands(JCR *jcr);
136
137 /* From job.c */
138 void     stored_free_jcr(JCR *jcr);
139 void     connection_from_filed(void *arg);
140 void     handle_filed_connection(BSOCK *fd, char *job_name);
141
142 /* From label.c */
143 int      read_dev_volume_label(DCR *dcr);
144 int      read_dvd_volume_label(DCR *dcr, bool write);
145 void     create_session_label(DCR *dcr, DEV_RECORD *rec, int label);
146 void     create_volume_label(DEVICE *dev, const char *VolName, const char *PoolName, bool dvdnow);
147 #define ANSI_VOL_LABEL 0
148 #define ANSI_EOF_LABEL 1
149 #define ANSI_EOV_LABEL 2
150 bool     write_ansi_ibm_labels(DCR *dcr, int type, const char *VolName);
151 int      read_ansi_ibm_label(DCR *dcr);
152 bool     write_session_label(DCR *dcr, int label);
153 void     dump_volume_label(DEVICE *dev);
154 void     dump_label_record(DEVICE *dev, DEV_RECORD *rec, int verbose);
155 bool     unser_volume_label(DEVICE *dev, DEV_RECORD *rec);
156 bool     unser_session_label(SESSION_LABEL *label, DEV_RECORD *rec);
157 bool     write_new_volume_label_to_dev(DCR *dcr, const char *VolName, 
158             const char *PoolName, bool relabel, bool dvdnow);
159
160 /* From locks.c */
161 void     _lock_device(const char *file, int line, DEVICE *dev);
162 void     _unlock_device(const char *file, int line, DEVICE *dev);
163 void     _block_device(const char *file, int line, DEVICE *dev, int state);
164 void     _unblock_device(const char *file, int line, DEVICE *dev);
165 void     _steal_device_lock(const char *file, int line, DEVICE *dev, bsteal_lock_t *hold, int state);
166 void     _give_back_device_lock(const char *file, int line, DEVICE *dev, bsteal_lock_t *hold);
167
168
169 /* From match_bsr.c */
170 int      match_bsr(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec,
171               SESSION_LABEL *sesrec, JCR *jcr);
172 int      match_bsr_block(BSR *bsr, DEV_BLOCK *block);
173 void     position_bsr_block(BSR *bsr, DEV_BLOCK *block);
174 BSR     *find_next_bsr(BSR *root_bsr, DEVICE *dev);
175 bool     is_this_bsr_done(BSR *bsr, DEV_RECORD *rec);
176 uint64_t get_bsr_start_addr(BSR *bsr, 
177                             uint32_t *file=NULL,
178                             uint32_t *block=NULL);
179
180
181 /* From mount.c */
182 bool     mount_next_read_volume(DCR *dcr);
183
184 /* From parse_bsr.c */
185 BSR     *parse_bsr(JCR *jcr, char *lf);
186 void     dump_bsr(BSR *bsr, bool recurse);
187 void     free_bsr(BSR *bsr);
188 void     free_restore_volume_list(JCR *jcr);
189 void     create_restore_volume_list(JCR *jcr);
190
191 /* From record.c */
192 const char *FI_to_ascii(char *buf, int fi);
193 const char *stream_to_ascii(char *buf, int stream, int fi);
194 bool        write_record_to_block(DCR *dcr, DEV_RECORD *rec);
195 bool        can_write_record_to_block(DEV_BLOCK *block, DEV_RECORD *rec);
196 bool        read_record_from_block(DCR *dcr, DEV_RECORD *rec);
197 DEV_RECORD *new_record();
198 void        free_record(DEV_RECORD *rec);
199 void        empty_record(DEV_RECORD *rec);
200 uint64_t get_record_address(DEV_RECORD *rec);
201
202 /* From read_record.c */
203 bool read_records(DCR *dcr,
204        bool record_cb(DCR *dcr, DEV_RECORD *rec),
205        bool mount_cb(DCR *dcr));
206
207 /* From reserve.c */
208 void    init_reservations_lock();
209 void    term_reservations_lock();
210 void    _lock_reservations(const char *file="**Unknown**", int line=0);
211 void    _unlock_reservations();
212 void    _lock_volumes(const char *file="**Unknown**", int line=0);
213 void    _unlock_volumes();
214 void    unreserve_device(DCR *dcr);
215 void    send_drive_reserve_messages(JCR *jcr, void sendit(const char *msg, int len, void *sarg), void *arg);
216 bool    find_suitable_device_for_job(JCR *jcr, RCTX &rctx);
217 int     search_res_for_device(RCTX &rctx);
218 void    release_reserve_messages(JCR *jcr);
219
220 extern int reservations_lock_count;
221
222 #ifdef  SD_DEBUG_LOCK
223
224 #define lock_reservations() \
225          do { Dmsg3(sd_dbglvl, "lock_reservations at %s:%d precnt=%d\n", \
226               __FILE__, __LINE__, \
227               reservations_lock_count); \
228               _lock_reservations(__FILE__, __LINE__); \
229               Dmsg0(sd_dbglvl, "lock_reservations: got lock\n"); \
230          } while (0)
231 #define unlock_reservations() \
232          do { Dmsg3(sd_dbglvl, "unlock_reservations at %s:%d precnt=%d\n", \
233               __FILE__, __LINE__, \
234               reservations_lock_count); \
235                    _unlock_reservations(); } while (0)
236
237 #define lock_volumes() \
238          do { Dmsg3(sd_dbglvl, "lock_volumes at %s:%d precnt=%d\n", \
239               __FILE__, __LINE__, \
240               vol_list_lock_count); \
241               _lock_volumes(__FILE__, __LINE__); \
242               Dmsg0(sd_dbglvl, "lock_volumes: got lock\n"); \
243          } while (0)
244
245 #define unlock_volumes() \
246          do { Dmsg3(sd_dbglvl, "unlock_volumes at %s:%d precnt=%d\n", \
247               __FILE__, __LINE__, \
248               vol_list_lock_count); \
249                    _unlock_volumes(); } while (0)
250
251 #else
252
253 #define lock_reservations() _lock_reservations(__FILE__, __LINE__)
254 #define unlock_reservations() _unlock_reservations()
255 #define lock_volumes() _lock_volumes(__FILE__, __LINE__)
256 #define unlock_volumes() _unlock_volumes()
257
258 #endif
259
260 /* From vol_mgr.c */
261 void    init_vol_list_lock();
262 void    term_vol_list_lock();
263 VOLRES *reserve_volume(DCR *dcr, const char *VolumeName);
264 VOLRES *find_volume(const char *VolumeName);
265 bool    free_volume(DEVICE *dev);
266 bool    is_vol_list_empty();
267 dlist  *dup_vol_list(JCR *jcr);
268 void    free_temp_vol_list(dlist *temp_vol_list);
269 bool    volume_unused(DCR *dcr);
270 void    create_volume_lists();
271 void    free_volume_lists();
272 void    list_volumes(void sendit(const char *msg, int len, void *sarg), void *arg);
273 bool    is_volume_in_use(DCR *dcr);
274 extern  int vol_list_lock_count;
275 void    add_read_volume(JCR *jcr, const char *VolumeName);
276 void    remove_read_volume(JCR *jcr, const char *VolumeName);
277
278
279 /* From spool.c */
280 bool    begin_data_spool          (DCR *dcr);
281 bool    discard_data_spool        (DCR *dcr);
282 bool    commit_data_spool         (DCR *dcr);
283 bool    are_attributes_spooled    (JCR *jcr);
284 bool    begin_attribute_spool     (JCR *jcr);
285 bool    discard_attribute_spool   (JCR *jcr);
286 bool    commit_attribute_spool    (JCR *jcr);
287 bool    write_block_to_spool_file (DCR *dcr);
288 void    list_spool_stats          (void sendit(const char *msg, int len, void *sarg), void *arg);
289
290 /* From wait.c */
291 int wait_for_sysop(DCR *dcr);
292 bool wait_for_device(JCR *jcr, int &retries);