2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2017 Kern Sibbald
6 The original author of Bacula is Kern Sibbald, with contributions
7 from many others, a complete list can be found in the file AUTHORS.
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.
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
22 * Written by Kern Sibbald, MM
26 uint32_t new_VolSessionId();
29 DCR *acquire_device_for_append(DCR *dcr);
30 bool acquire_device_for_read(DCR *dcr);
31 bool release_device(DCR *dcr);
32 bool clean_device(DCR *dcr);
33 DCR *new_dcr(JCR *jcr, DCR *dcr, DEVICE *dev, bool writing=true);
34 void free_dcr(DCR *dcr);
37 bool send_attrs_to_dir(JCR *jcr, DEV_RECORD *rec);
40 enum get_vol_info_rw {
41 GET_VOL_INFO_FOR_WRITE,
44 bool dir_get_volume_info(DCR *dcr, const char *VolumeName, enum get_vol_info_rw);
45 bool dir_find_next_appendable_volume(DCR *dcr);
46 bool dir_update_volume_info(DCR *dcr, bool label, bool update_LastWritten,
48 bool dir_ask_sysop_to_create_appendable_volume(DCR *dcr);
49 bool dir_ask_sysop_to_mount_volume(DCR *dcr, bool read_access);
50 bool dir_update_file_attributes(DCR *dcr, DEV_RECORD *rec);
51 bool dir_send_job_status(JCR *jcr);
52 bool dir_create_jobmedia_record(DCR *dcr, bool zero=false);
53 void create_jobmedia_queue(JCR *jcr);
54 bool flush_jobmedia_queue(JCR *jcr);
55 bool dir_update_device(JCR *jcr, DEVICE *dev);
56 bool dir_update_changer(JCR *jcr, AUTOCHANGER *changer);
58 /* class AskDirHandler allows btool's utilities to overwrite the functions above
59 * and even to overwrite the functions in their own sub-class like in btape
63 /* this class should be an abstract class */
66 virtual ~AskDirHandler() {}
67 virtual bool dir_find_next_appendable_volume(DCR *dcr) { return 1;}
68 virtual bool dir_update_volume_info(DCR *dcr, bool relabel, bool update_LastWritten, bool use_dcr) { return 1; }
69 virtual bool dir_create_jobmedia_record(DCR *dcr, bool zero) { return 1; }
70 virtual bool flush_jobmedia_queue(JCR *jcr) { return true; }
71 virtual bool dir_ask_sysop_to_create_appendable_volume(DCR *dcr) { return 1; }
72 virtual bool dir_update_file_attributes(DCR *dcr, DEV_RECORD *rec) { return 1;}
73 virtual bool dir_send_job_status(JCR *jcr) {return 1;}
74 virtual bool dir_ask_sysop_to_mount_volume(DCR *dcr, bool writing);
75 virtual bool dir_get_volume_info(DCR *dcr, const char *VolumeName, enum get_vol_info_rw writing);
78 class BtoolsAskDirHandler: public AskDirHandler
80 /* if AskDirHandler was an abstract class, implement the method here */
82 BtoolsAskDirHandler() {}
83 virtual ~BtoolsAskDirHandler() {}
86 /* activate the functions provided by the btool's handler */
87 AskDirHandler *init_askdir_handler(AskDirHandler *new_askdir_handler);
90 bool authenticate_director(JCR *jcr);
91 int authenticate_filed(JCR *jcr, BSOCK *fd, int FDVersion);
92 bool authenticate_storagedaemon(JCR *jcr);
94 /* From autochanger.c */
95 bool init_autochangers();
96 int autoload_device(DCR *dcr, bool writing, BSOCK *dir);
97 bool autochanger_cmd(DCR *dcr, BSOCK *dir, const char *cmd);
98 bool unload_autochanger(DCR *dcr, int loaded);
99 bool unload_dev(DCR *dcr, DEVICE *dev);
100 char *edit_device_codes(DCR *dcr, char *omsg, const char *imsg, const char *cmd);
101 int get_autochanger_loaded_slot(DCR *dcr);
104 void dump_block(DEVICE *dev, DEV_BLOCK *b, const char *msg, bool force=false);
105 DEV_BLOCK *dup_block(DEV_BLOCK *eblock);
106 void init_block_write(DEV_BLOCK *block);
107 void empty_block(DEV_BLOCK *block);
108 void free_block(DEV_BLOCK *block);
109 void print_block_read_errors(JCR *jcr, DEV_BLOCK *block);
110 void ser_block_header(DEV_BLOCK *block);
111 bool is_block_empty(DEV_BLOCK *block);
112 bool terminate_writing_volume(DCR *dcr);
114 /* From block_util.c */
115 bool terminate_writing_volume(DCR *dcr);
116 bool is_user_volume_size_reached(DCR *dcr, bool quiet);
117 bool check_for_newvol_or_newfile(DCR *dcr);
118 bool do_new_file_bookkeeping(DCR *dcr);
119 void reread_last_block(DCR *dcr);
122 /* From butil.c -- utilities for SD tool programs */
124 void print_ls_output(const char *fname, const char *link, int type, struct stat *statp);
125 JCR *setup_jcr(const char *name, char *dev_name, BSR *bsr,
126 const char *VolumeName, bool writing, bool read_dedup_data=true);
127 void display_tape_error_status(JCR *jcr, DEVICE *dev);
131 void sd_list_loaded_drivers(alist *list);
132 DEVICE *init_dev(JCR *jcr, DEVRES *device, bool adata=false);
133 bool can_open_mounted_dev(DEVICE *dev);
134 bool load_dev(DEVICE *dev);
135 int write_block(DEVICE *dev);
136 uint32_t status_dev(DEVICE *dev);
137 void attach_jcr_to_device(DEVICE *dev, JCR *jcr);
138 void detach_jcr_from_device(DEVICE *dev, JCR *jcr);
139 JCR *next_attached_jcr(DEVICE *dev, JCR *jcr);
140 void init_device_wait_timers(DCR *dcr);
141 void init_jcr_device_wait_timers(JCR *jcr);
142 bool double_dev_wait_time(DEVICE *dev);
145 bool first_open_device(DCR *dcr);
146 bool fixup_device_block_write_error(DCR *dcr, int retries=4);
147 void set_start_vol_position(DCR *dcr);
148 void set_new_volume_parameters(DCR *dcr);
149 void set_new_file_parameters(DCR *dcr);
152 void *handle_connection_request(void *arg);
153 extern int use_new_match_all; /* Temp variable, to be removed when the new code is tested */
156 void run_job(JCR *jcr);
157 void do_fd_commands(JCR *jcr);
158 bool do_handle_command(JCR *jcr);
159 void do_client_commands(JCR *jcr);
162 void stored_free_jcr(JCR *jcr);
165 bool validate_dir_hello(JCR* jcr);
166 bool send_hello_ok(BSOCK *bs);
167 bool send_sorry(BSOCK *bs);
168 bool send_hello_sd(JCR *jcr, char *Job);
169 bool send_hello_client(JCR *jcr, char *Job);
170 bool read_client_hello(JCR *jcr);
171 bool is_client_connection(BSOCK *bs);
172 void handle_client_connection(BSOCK *fd);
175 void create_session_label(DCR *dcr, DEV_RECORD *rec, int label);
176 void create_volume_header(DEVICE *dev, const char *VolName, const char *PoolName, bool no_prelabel);
177 #define ANSI_VOL_LABEL 0
178 #define ANSI_EOF_LABEL 1
179 #define ANSI_EOV_LABEL 2
180 bool write_ansi_ibm_labels(DCR *dcr, int type, const char *VolName);
181 int read_ansi_ibm_label(DCR *dcr);
182 bool write_session_label(DCR *dcr, int label);
183 int dump_label_record(DEVICE *dev, DEV_RECORD *rec, int verbose, bool check_err);
184 bool unser_volume_label(DEVICE *dev, DEV_RECORD *rec);
185 bool unser_session_label(SESSION_LABEL *label, DEV_RECORD *rec);
188 void _lock_device(const char *file, int line, DEVICE *dev);
189 void _unlock_device(const char *file, int line, DEVICE *dev);
190 void _block_device(const char *file, int line, DEVICE *dev, int state);
191 void _unblock_device(const char *file, int line, DEVICE *dev);
192 bool _obtain_device_block(const char *file, int line, DEVICE *dev, bsteal_lock_t *hold, int state);
193 void _give_back_device_block(const char *file, int line, DEVICE *dev, bsteal_lock_t *hold);
196 /* From match_bsr.c */
197 int match_bsr(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec,
198 SESSION_LABEL *sesrec, JCR *jcr);
199 int match_bsr_block(BSR *bsr, DEV_BLOCK *block);
200 void position_bsr_block(BSR *bsr, DEV_BLOCK *block);
201 BSR *find_next_bsr(BSR *root_bsr, DEVICE *dev);
202 bool is_this_bsr_done(JCR *jcr, BSR *bsr, DEV_RECORD *rec);
203 uint64_t get_bsr_start_addr(BSR *bsr);
206 bool mount_next_read_volume(DCR *dcr);
208 /* From parse_bsr.c */
210 BSR *parse_bsr(JCR *jcr, char *lf);
211 void dump_bsr(DEVICE *dev, BSR *bsr, bool recurse);
212 void free_bsr(BSR *bsr);
213 void free_restore_volume_list(JCR *jcr);
214 void create_restore_volume_list(JCR *jcr, bool add_to_read_list);
217 const char *FI_to_ascii(char *buf, int fi);
218 const char *stream_to_ascii(char *buf, int stream, int fi);
219 const char *stream_to_ascii_ex(char *buf, int stream, int fi);
220 bool write_record_to_block(DCR *dcr, DEV_RECORD *rec);
221 bool can_write_record_to_block(DEV_BLOCK *block, DEV_RECORD *rec);
222 bool read_record_from_block(DCR *dcr, DEV_RECORD *rec);
223 DEV_RECORD *new_record();
224 void free_record(DEV_RECORD *rec);
225 void empty_record(DEV_RECORD *rec);
226 uint64_t get_record_address(DEV_RECORD *rec);
227 uint64_t get_record_start_address(DEV_RECORD *rec);
228 bool flush_adata_to_device(DCR *dcr);
230 /* From record_util.c */
231 void dump_record(DEV_RECORD *rec);
233 /* From read_record.c */
234 bool read_records(DCR *dcr,
235 bool record_cb(DCR *dcr, DEV_RECORD *rec),
236 bool mount_cb(DCR *dcr));
239 void init_reservations_lock();
240 void term_reservations_lock();
241 void send_drive_reserve_messages(JCR *jcr, void sendit(const char *msg, int len, void *sarg), void *arg);
242 bool find_suitable_device_for_job(JCR *jcr, RCTX &rctx);
243 int search_res_for_device(RCTX &rctx);
244 void release_reserve_messages(JCR *jcr);
246 extern int reservations_lock_count;
249 void _dbg_list_one_device(DEVICE *dev, const char *f, int l);
250 #define dbg_list_one_device(x, dev) if (chk_dbglvl(x)) \
251 _dbg_list_one_device(dev, __FILE__, __LINE__)
254 void init_vol_list_lock();
255 void term_vol_list_lock();
256 VOLRES *reserve_volume(DCR *dcr, const char *VolumeName);
257 bool free_volume(DEVICE *dev);
258 bool is_vol_list_empty();
259 dlist *dup_vol_list(JCR *jcr);
260 void free_temp_vol_list(dlist *temp_vol_list);
261 bool volume_unused(DCR *dcr);
262 void create_volume_lists();
263 void free_volume_lists();
264 void list_volumes(void sendit(const char *msg, int len, void *sarg), void *arg);
265 bool is_volume_in_use(DCR *dcr);
266 extern int vol_list_lock_count;
267 void add_read_volume(JCR *jcr, const char *VolumeName);
268 void remove_read_volume(JCR *jcr, const char *VolumeName);
272 bool begin_data_spool (DCR *dcr);
273 bool discard_data_spool (DCR *dcr);
274 bool commit_data_spool (DCR *dcr);
275 bool are_attributes_spooled (JCR *jcr);
276 bool begin_attribute_spool (JCR *jcr);
277 bool discard_attribute_spool (JCR *jcr);
278 bool commit_attribute_spool (JCR *jcr);
279 bool write_block_to_spool_file (DCR *dcr);
280 void list_spool_stats (void sendit(const char *msg, int len, void *sarg), void *arg);
282 /* From tape_alert.c */
283 extern void alert_callback(void *ctx, const char *short_msg,
284 const char *long_msg, char *Volume,
285 int severity, int flags, int alertno, utime_t alert_time);
288 int wait_for_sysop(DCR *dcr);
289 bool wait_for_any_device(JCR *jcr, int &retries);
290 bool wait_for_device(DCR *dcr, int &retries);
293 void store_protocol(LEX *lc, RES_ITEM *item, int index, int pass);
294 void store_uri_style(LEX *lc, RES_ITEM *item, int index, int pass);
295 void store_truncate(LEX *lc, RES_ITEM *item, int index, int pass);
296 void store_upload(LEX *lc, RES_ITEM *item, int index, int pass);
297 void store_devtype(LEX *lc, RES_ITEM *item, int index, int pass);
298 void store_cloud_driver(LEX *lc, RES_ITEM *item, int index, int pass);
299 void store_maxblocksize(LEX *lc, RES_ITEM *item, int index, int pass);