]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/stored/protos.h
deb8d6c706b98cd120b89ab5c97677a14bb7c4db
[bacula/bacula] / bacula / src / stored / protos.h
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2000-2007 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 plus additions
11    that are listed 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 John Walker.
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 DCR     *new_dcr(JCR *jcr, DEVICE *dev);
42 void     free_dcr(DCR *dcr);
43 void     detach_dcr_from_dev(DCR *dcr);
44
45 /* From askdir.c */
46 enum get_vol_info_rw {
47    GET_VOL_INFO_FOR_WRITE,
48    GET_VOL_INFO_FOR_READ
49 };
50 bool    dir_get_volume_info(DCR *dcr, enum get_vol_info_rw);
51 bool    dir_find_next_appendable_volume(DCR *dcr);
52 bool    dir_update_volume_info(DCR *dcr, bool label);
53 bool    dir_ask_sysop_to_create_appendable_volume(DCR *dcr);
54 bool    dir_ask_sysop_to_mount_volume(DCR *dcr);
55 bool    dir_update_file_attributes(DCR *dcr, DEV_RECORD *rec);
56 bool    dir_send_job_status(JCR *jcr);
57 bool    dir_create_jobmedia_record(DCR *dcr);
58 bool    dir_update_device(JCR *jcr, DEVICE *dev);
59 bool    dir_update_changer(JCR *jcr, AUTOCHANGER *changer);
60
61 /* authenticate.c */
62 int     authenticate_director(JCR *jcr);
63 int     authenticate_filed(JCR *jcr);
64
65 /* From autochanger.c */
66 bool     init_autochangers();
67 int      autoload_device(DCR *dcr, int writing, BSOCK *dir);
68 bool     autochanger_cmd(DCR *dcr, BSOCK *dir, const char *cmd);
69 bool     unload_autochanger(DCR *dcr, int loaded);
70 char    *edit_device_codes(DCR *dcr, char *omsg, const char *imsg, const char *cmd);
71 int      get_autochanger_loaded_slot(DCR *dcr);
72
73 /* From block.c */
74 void    dump_block(DEV_BLOCK *b, const char *msg);
75 DEV_BLOCK *new_block(DEVICE *dev);
76 DEV_BLOCK *dup_block(DEV_BLOCK *eblock);
77 void    init_block_write(DEV_BLOCK *block);
78 void    empty_block(DEV_BLOCK *block);
79 void    free_block(DEV_BLOCK *block);
80 bool    write_block_to_device(DCR *dcr);
81 bool    write_block_to_dev(DCR *dcr);
82 void    print_block_read_errors(JCR *jcr, DEV_BLOCK *block);
83 void    ser_block_header(DEV_BLOCK *block);
84
85 #define CHECK_BLOCK_NUMBERS    true
86 #define NO_BLOCK_NUMBER_CHECK  false
87 bool    read_block_from_device(DCR *dcr, bool check_block_numbers);
88 bool    read_block_from_dev(DCR *dcr, bool check_block_numbers);
89
90 /* 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, int mode);
94 void    display_tape_error_status(JCR *jcr, DEVICE *dev);
95
96
97 /* From dev.c */
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);
109
110 /* Get info about device */
111 char *   dev_vol_name(DEVICE *dev);
112
113 /* From dvd.c */
114 int     dvd_open_next_part(DCR *dcr);
115 bool    dvd_write_part(DCR *dcr); 
116 bool    dvd_close_job(DCR *dcr);
117 void    make_mounted_dvd_filename(DEVICE *dev, POOL_MEM &archive_name);
118 void    make_spooled_dvd_filename(DEVICE *dev, POOL_MEM &archive_name);
119 bool    truncate_dvd(DCR *dcr);
120 bool    check_can_write_on_non_blank_dvd(DCR *dcr);
121 int     find_num_dvd_parts(DCR *dcr);
122 boffset_t   lseek_dvd(DCR *dcr, boffset_t offset, int whence);
123 void    dvd_remove_empty_part(DCR *dcr);
124
125 /* From device.c */
126 bool     open_device(DCR *dcr);
127 bool     first_open_device(DCR *dcr);
128 bool     fixup_device_block_write_error(DCR *dcr);
129 void     _lock_device(const char *file, int line, DEVICE *dev);
130 void     _unlock_device(const char *file, int line, DEVICE *dev);
131 void     _block_device(const char *file, int line, DEVICE *dev, int state);
132 void     _unblock_device(const char *file, int line, DEVICE *dev);
133 void     _steal_device_lock(const char *file, int line, DEVICE *dev, bsteal_lock_t *hold, int state);
134 void     _give_back_device_lock(const char *file, int line, DEVICE *dev, bsteal_lock_t *hold);
135 void     set_new_volume_parameters(DCR *dcr);
136 void     set_new_file_parameters(DCR *dcr);
137 bool     is_device_unmounted(DEVICE *dev);
138
139 /* From dircmd.c */
140 void     *handle_connection_request(void *arg);
141
142
143 /* From fd_cmds.c */
144 void     run_job(JCR *jcr);
145 bool     get_bootstrap_file(JCR *jcr, BSOCK *bsock);
146 void     do_fd_commands(JCR *jcr);
147
148 /* From job.c */
149 void     stored_free_jcr(JCR *jcr);
150 void     connection_from_filed(void *arg);
151 void     handle_filed_connection(BSOCK *fd, char *job_name);
152
153 /* From label.c */
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_label(DEVICE *dev, const char *VolName, const char *PoolName, bool dvdnow);
158 bool     write_new_volume_label_to_dev(DCR *dcr, const char *VolName, 
159            const char *PoolName, bool relabel, bool dvdnow);
160 #define ANSI_VOL_LABEL 0
161 #define ANSI_EOF_LABEL 1
162 #define ANSI_EOV_LABEL 2
163 bool     write_ansi_ibm_labels(DCR *dcr, int type, const char *VolName);
164 int      read_ansi_ibm_label(DCR *dcr);
165 bool     write_session_label(DCR *dcr, int label);
166 bool     write_volume_label_to_block(DCR *dcr);
167 bool     rewrite_volume_label(DCR *dcr, bool recycle);
168 void     dump_volume_label(DEVICE *dev);
169 void     dump_label_record(DEVICE *dev, DEV_RECORD *rec, int verbose);
170 bool     unser_volume_label(DEVICE *dev, DEV_RECORD *rec);
171 bool     unser_session_label(SESSION_LABEL *label, DEV_RECORD *rec);
172
173 /* From match_bsr.c */
174 int      match_bsr(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec,
175               SESSION_LABEL *sesrec);
176 int      match_bsr_block(BSR *bsr, DEV_BLOCK *block);
177 void     position_bsr_block(BSR *bsr, DEV_BLOCK *block);
178 BSR     *find_next_bsr(BSR *root_bsr, DEVICE *dev);
179 bool     is_this_bsr_done(BSR *bsr, DEV_RECORD *rec);
180
181 /* From mount.c */
182 bool     mount_next_write_volume(DCR *dcr, bool release);
183 bool     mount_next_read_volume(DCR *dcr);
184 void     mark_volume_in_error(DCR *dcr);
185
186 /* From parse_bsr.c */
187 BSR     *parse_bsr(JCR *jcr, char *lf);
188 void     dump_bsr(BSR *bsr, bool recurse);
189 void     free_bsr(BSR *bsr);
190 VOL_LIST *new_restore_volume();
191 int      add_restore_volume(JCR *jcr, VOL_LIST *vol);
192 void     free_restore_volume_list(JCR *jcr);
193 void     create_restore_volume_list(JCR *jcr);
194
195 /* From record.c */
196 const char *FI_to_ascii(char *buf, int fi);
197 const char *stream_to_ascii(char *buf, int stream, int fi);
198 bool        write_record_to_block(DEV_BLOCK *block, DEV_RECORD *rec);
199 bool        can_write_record_to_block(DEV_BLOCK *block, DEV_RECORD *rec);
200 bool        read_record_from_block(DCR *dcr, DEV_BLOCK *block, DEV_RECORD *rec);
201 DEV_RECORD *new_record();
202 void        free_record(DEV_RECORD *rec);
203 void        empty_record(DEV_RECORD *rec);
204
205 /* From read_record.c */
206 bool read_records(DCR *dcr,
207        bool record_cb(DCR *dcr, DEV_RECORD *rec),
208        bool mount_cb(DCR *dcr));
209
210 /* From reserve.c */
211 void    init_reservations_lock();
212 void    term_reservations_lock();
213 void    _lock_reservations();
214 void    _unlock_reservations();
215 void    _lock_volumes();
216 void    _unlock_volumes();
217 void    release_volume(DCR *dcr);
218 VOLRES *reserve_volume(DCR *dcr, const char *VolumeName);
219 VOLRES *find_volume(const char *VolumeName);
220 bool    free_volume(DEVICE *dev);
221 void    unreserve_device(DCR *dcr);
222 bool    volume_unused(DCR *dcr);
223 void    create_volume_list();
224 void    free_volume_list();
225 void    list_volumes(void sendit(const char *msg, int len, void *sarg), void *arg);
226 bool    is_volume_in_use(DCR *dcr);
227 void    send_drive_reserve_messages(JCR *jcr, void sendit(const char *msg, int len, void *sarg), void *arg);
228 bool    find_suitable_device_for_job(JCR *jcr, RCTX &rctx);
229 int     search_res_for_device(RCTX &rctx);
230 void    release_msgs(JCR *jcr);
231
232 extern int reservations_lock_count;
233 extern int vol_list_lock_count;
234
235 #ifdef  SD_DEBUG_LOCK
236
237 #define lock_reservations() \
238          do { Dmsg4(sd_dbglvl, "lock_reservations at %s:%d precnt=%d JobId=%u\n", \
239               __FILE__, __LINE__, \
240               reservations_lock_count, get_jobid_from_tid(pthread_self())); \
241               _lock_reservations(); \
242               Dmsg1(sd_dbglvl, "lock_reservations: got lock JobId=%u\n", \
243                get_jobid_from_tid(pthread_self())); \
244          } while (0)
245 #define unlock_reservations() \
246          do { Dmsg4(sd_dbglvl, "unlock_reservations at %s:%d precnt=%d JobId=%u\n", \
247               __FILE__, __LINE__, \
248               reservations_lock_count, get_jobid_from_tid(pthread_self())); \
249                    _unlock_reservations(); } while (0)
250
251 #define lock_volumes() \
252          do { Dmsg4(sd_dbglvl, "lock_volumes at %s:%d precnt=%d JobId=%u\n", \
253               __FILE__, __LINE__, \
254               vol_list_lock_count, get_jobid_from_tid(pthread_self())); \
255               _lock_volumes(); \
256               Dmsg1(sd_dbglvl, "lock_volumes: got lock JobId=%u\n", \
257                get_jobid_from_tid(pthread_self())); \
258          } while (0)
259
260 #define unlock_volumes() \
261          do { Dmsg4(sd_dbglvl, "unlock_volumes at %s:%d precnt=%d JobId=%u\n", \
262               __FILE__, __LINE__, \
263               vol_list_lock_count, get_jobid_from_tid(pthread_self())); \
264                    _unlock_volumes(); } while (0)
265
266 #else
267
268 #define lock_reservations() _lock_reservations()
269 #define unlock_reservations() _unlock_reservations()
270 #define lock_volumes() _lock_volumes()
271 #define unlock_volumes() _unlock_volumes()
272
273 #endif
274
275
276
277 /* From spool.c */
278 bool    begin_data_spool          (DCR *dcr);
279 bool    discard_data_spool        (DCR *dcr);
280 bool    commit_data_spool         (DCR *dcr);
281 bool    are_attributes_spooled    (JCR *jcr);
282 bool    begin_attribute_spool     (JCR *jcr);
283 bool    discard_attribute_spool   (JCR *jcr);
284 bool    commit_attribute_spool    (JCR *jcr);
285 bool    write_block_to_spool_file (DCR *dcr);
286 void    list_spool_stats          (void sendit(const char *msg, int len, void *sarg), void *arg);
287
288 /* From wait.c */
289 int wait_for_sysop(DCR *dcr);
290 bool wait_for_device(JCR *jcr, int &retries);