2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2015 Kern Sibbald
5 Copyright (C) 2000-2014 Free Software Foundation Europe e.V.
7 The original author of Bacula is Kern Sibbald, with contributions
8 from many others, a complete list can be found in the file AUTHORS.
10 You may use this file and others of this release according to the
11 license defined in the LICENSE file, which includes the Affero General
12 Public License, v3.0 ("AGPLv3") and some additional permissions and
13 terms pursuant to its AGPLv3 Section 7.
15 This notice must be preserved when any source code is
16 conveyed and/or propagated.
18 Bacula(R) is a registered trademark of Kern Sibbald.
23 * Written by Kern Sibbald, MM
27 uint32_t new_VolSessionId();
30 DCR *acquire_device_for_append(DCR *dcr);
31 bool acquire_device_for_read(DCR *dcr);
32 bool release_device(DCR *dcr);
33 bool clean_device(DCR *dcr);
34 DCR *new_dcr(JCR *jcr, DCR *dcr, DEVICE *dev, bool writing=true);
35 void free_dcr(DCR *dcr);
38 bool send_attrs_to_dir(JCR *jcr, DEV_RECORD *rec);
41 enum get_vol_info_rw {
42 GET_VOL_INFO_FOR_WRITE,
45 bool dir_get_volume_info(DCR *dcr, enum get_vol_info_rw);
46 bool dir_find_next_appendable_volume(DCR *dcr);
47 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);
59 bool authenticate_director(JCR *jcr);
60 int authenticate_filed(JCR *jcr, BSOCK *fd, int FDVersion);
61 bool authenticate_storagedaemon(JCR *jcr);
63 /* From autochanger.c */
64 bool init_autochangers();
65 int autoload_device(DCR *dcr, bool writing, BSOCK *dir);
66 bool autochanger_cmd(DCR *dcr, BSOCK *dir, const char *cmd);
67 bool unload_autochanger(DCR *dcr, int loaded);
68 bool unload_dev(DCR *dcr, DEVICE *dev);
69 char *edit_device_codes(DCR *dcr, char *omsg, const char *imsg, const char *cmd);
70 int get_autochanger_loaded_slot(DCR *dcr);
73 void dump_block(DEV_BLOCK *b, const char *msg);
74 DEV_BLOCK *new_block(DEVICE *dev);
75 DEV_BLOCK *dup_block(DEV_BLOCK *eblock);
76 void init_block_write(DEV_BLOCK *block);
77 void empty_block(DEV_BLOCK *block);
78 void free_block(DEV_BLOCK *block);
79 void print_block_read_errors(JCR *jcr, DEV_BLOCK *block);
80 void ser_block_header(DEV_BLOCK *block);
81 bool is_block_empty(DEV_BLOCK *block);
82 bool terminate_writing_volume(DCR *dcr);
84 /* From block_util.c */
85 bool terminate_writing_volume(DCR *dcr);
86 bool user_volume_size_reached(DCR *dcr, bool quiet);
87 bool check_for_newvol_or_newfile(DCR *dcr);
89 /* From butil.c -- utilities for SD tool programs */
91 void print_ls_output(const char *fname, const char *link, int type, struct stat *statp);
92 JCR *setup_jcr(const char *name, char *dev_name, BSR *bsr,
93 const char *VolumeName, bool writing, bool read_dedup_data=true);
94 void display_tape_error_status(JCR *jcr, DEVICE *dev);
98 DEVICE *init_dev(JCR *jcr, DEVRES *device);
99 bool can_open_mounted_dev(DEVICE *dev);
100 bool load_dev(DEVICE *dev);
101 int write_block(DEVICE *dev);
102 uint32_t status_dev(DEVICE *dev);
103 void attach_jcr_to_device(DEVICE *dev, JCR *jcr);
104 void detach_jcr_from_device(DEVICE *dev, JCR *jcr);
105 JCR *next_attached_jcr(DEVICE *dev, JCR *jcr);
106 void init_device_wait_timers(DCR *dcr);
107 void init_jcr_device_wait_timers(JCR *jcr);
108 bool double_dev_wait_time(DEVICE *dev);
111 int dvd_open_next_part(DCR *dcr);
112 bool dvd_write_part(DCR *dcr);
113 bool dvd_close_job(DCR *dcr);
114 void make_mounted_dvd_filename(DEVICE *dev, POOL_MEM &archive_name);
115 void make_spooled_dvd_filename(DEVICE *dev, POOL_MEM &archive_name);
116 bool truncate_dvd(DCR *dcr);
117 bool check_can_write_on_non_blank_dvd(DCR *dcr);
118 int find_num_dvd_parts(DCR *dcr);
119 boffset_t lseek_dvd(DCR *dcr, boffset_t offset, int whence);
120 void dvd_remove_empty_part(DCR *dcr);
123 bool open_device(DCR *dcr);
124 bool first_open_device(DCR *dcr);
125 bool fixup_device_block_write_error(DCR *dcr, int retries=4);
126 void set_start_vol_position(DCR *dcr);
127 void set_new_volume_parameters(DCR *dcr);
128 void set_new_file_parameters(DCR *dcr);
131 void *handle_connection_request(void *arg);
135 void run_job(JCR *jcr);
136 void do_fd_commands(JCR *jcr);
137 bool do_handle_command(JCR *jcr);
138 void do_client_commands(JCR *jcr);
141 void stored_free_jcr(JCR *jcr);
144 bool validate_dir_hello(JCR* jcr);
145 bool send_hello_ok(BSOCK *bs);
146 bool send_sorry(BSOCK *bs);
147 bool send_hello_sd(JCR *jcr, char *Job);
148 bool send_hello_client(JCR *jcr, char *Job);
149 bool read_client_hello(JCR *jcr);
150 bool is_client_connection(BSOCK *bs);
151 void handle_client_connection(BSOCK *fd);
154 int read_dev_volume_label(DCR *dcr);
155 int read_dvd_volume_label(DCR *dcr, bool write);
156 void create_session_label(DCR *dcr, DEV_RECORD *rec, int label);
157 void create_volume_header(DEVICE *dev, const char *VolName, const char *PoolName, bool dvdnow);
158 #define ANSI_VOL_LABEL 0
159 #define ANSI_EOF_LABEL 1
160 #define ANSI_EOV_LABEL 2
161 bool write_ansi_ibm_labels(DCR *dcr, int type, const char *VolName);
162 int read_ansi_ibm_label(DCR *dcr);
163 bool write_session_label(DCR *dcr, int label);
164 void dump_volume_label(DEVICE *dev);
165 int dump_label_record(DEVICE *dev, DEV_RECORD *rec, int verbose, bool check_err);
166 bool unser_volume_label(DEVICE *dev, DEV_RECORD *rec);
167 bool unser_session_label(SESSION_LABEL *label, DEV_RECORD *rec);
168 bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName,
169 const char *PoolName, bool relabel, bool dvdnow);
172 void _lock_device(const char *file, int line, DEVICE *dev);
173 void _unlock_device(const char *file, int line, DEVICE *dev);
174 void _block_device(const char *file, int line, DEVICE *dev, int state);
175 void _unblock_device(const char *file, int line, DEVICE *dev);
176 void _steal_device_lock(const char *file, int line, DEVICE *dev, bsteal_lock_t *hold, int state);
177 void _give_back_device_lock(const char *file, int line, DEVICE *dev, bsteal_lock_t *hold);
180 /* From match_bsr.c */
181 int match_bsr(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec,
182 SESSION_LABEL *sesrec, JCR *jcr);
183 int match_bsr_block(BSR *bsr, DEV_BLOCK *block);
184 void position_bsr_block(BSR *bsr, DEV_BLOCK *block);
185 BSR *find_next_bsr(BSR *root_bsr, DEVICE *dev);
186 bool is_this_bsr_done(BSR *bsr, DEV_RECORD *rec);
187 uint64_t get_bsr_start_addr(BSR *bsr,
189 uint32_t *block=NULL);
193 bool mount_next_read_volume(DCR *dcr);
195 /* From parse_bsr.c */
196 BSR *parse_bsr(JCR *jcr, char *lf);
197 void dump_bsr(BSR *bsr, bool recurse);
198 void free_bsr(BSR *bsr);
199 void free_restore_volume_list(JCR *jcr);
200 void create_restore_volume_list(JCR *jcr);
203 const char *FI_to_ascii(char *buf, int fi);
204 const char *stream_to_ascii(char *buf, int stream, int fi);
205 bool write_record_to_block(DCR *dcr, DEV_RECORD *rec);
206 bool can_write_record_to_block(DEV_BLOCK *block, DEV_RECORD *rec);
207 bool read_record_from_block(DCR *dcr, DEV_RECORD *rec);
208 DEV_RECORD *new_record();
209 void free_record(DEV_RECORD *rec);
210 void empty_record(DEV_RECORD *rec);
211 uint64_t get_record_address(DEV_RECORD *rec);
212 bool flush_adata_to_device(DCR *dcr);
214 /* From read_record.c */
215 bool read_records(DCR *dcr,
216 bool record_cb(DCR *dcr, DEV_RECORD *rec),
217 bool mount_cb(DCR *dcr));
220 void init_reservations_lock();
221 void term_reservations_lock();
222 void send_drive_reserve_messages(JCR *jcr, void sendit(const char *msg, int len, void *sarg), void *arg);
223 bool find_suitable_device_for_job(JCR *jcr, RCTX &rctx);
224 int search_res_for_device(RCTX &rctx);
225 void release_reserve_messages(JCR *jcr);
227 extern int reservations_lock_count;
230 void _dbg_list_one_device(DEVICE *dev, const char *f, int l);
231 #define dbg_list_one_device(x, dev) if (chk_dbglvl(x)) \
232 _dbg_list_one_device(dev, __FILE__, __LINE__)
235 void init_vol_list_lock();
236 void term_vol_list_lock();
237 VOLRES *reserve_volume(DCR *dcr, const char *VolumeName);
238 bool free_volume(DEVICE *dev);
239 bool is_vol_list_empty();
240 dlist *dup_vol_list(JCR *jcr);
241 void free_temp_vol_list(dlist *temp_vol_list);
242 bool volume_unused(DCR *dcr);
243 void create_volume_lists();
244 void free_volume_lists();
245 void list_volumes(void sendit(const char *msg, int len, void *sarg), void *arg);
246 bool is_volume_in_use(DCR *dcr);
247 extern int vol_list_lock_count;
248 void add_read_volume(JCR *jcr, const char *VolumeName);
249 void remove_read_volume(JCR *jcr, const char *VolumeName);
253 bool begin_data_spool (DCR *dcr);
254 bool discard_data_spool (DCR *dcr);
255 bool commit_data_spool (DCR *dcr);
256 bool are_attributes_spooled (JCR *jcr);
257 bool begin_attribute_spool (JCR *jcr);
258 bool discard_attribute_spool (JCR *jcr);
259 bool commit_attribute_spool (JCR *jcr);
260 bool write_block_to_spool_file (DCR *dcr);
261 void list_spool_stats (void sendit(const char *msg, int len, void *sarg), void *arg);
264 int wait_for_sysop(DCR *dcr);
265 bool wait_for_any_device(JCR *jcr, int &retries);
266 bool wait_for_device(DCR *dcr, int &retries);
269 void store_devtype(LEX *lc, RES_ITEM *item, int index, int pass);
270 void store_maxblocksize(LEX *lc, RES_ITEM *item, int index, int pass);