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