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.
20 * Application Programming Interface (API) definition for Bacula Plugins
22 * Kern Sibbald, October 2007
25 #ifndef __FD_PLUGINS_H
26 #define __FD_PLUGINS_H
30 /* Workaround for SGI IRIX 6.5 */
31 #define _LANGUAGE_C_PLUS_PLUS 1
34 #define _THREAD_SAFE 1
35 #define _POSIX_PTHREAD_SEMANTICS 1
36 #define _FILE_OFFSET_BITS 64
37 #define _LARGEFILE_SOURCE 1
38 #define _LARGE_FILES 1
39 #endif /* ! _BACULA_H */
41 #include <sys/types.h>
43 #if defined(HAVE_WIN32)
44 #if defined(HAVE_MINGW)
45 #include "mingwconfig.h"
47 #include "winconfig.h"
49 #else /* !HAVE_WIN32 */
56 #include "../src/version.h"
58 #include "lib/plugins.h"
61 #include "../win32/filed/vss.h"
65 * This packet is used for the restore objects
66 * It is passed to the plugin when restoring
69 struct restore_object_pkt {
70 int32_t pkt_size; /* size of this packet */
71 char *object_name; /* Object name */
72 char *object; /* restore object data to save */
73 char *plugin_name; /* Plugin name */
74 int32_t object_type; /* FT_xx for this file */
75 int32_t object_len; /* restore object length */
76 int32_t object_full_len; /* restore object uncompressed length */
77 int32_t object_index; /* restore object index */
78 int32_t object_compression; /* set to compression type */
79 int32_t stream; /* attribute stream id */
80 uint32_t JobId; /* JobId object came from */
81 int32_t pkt_end; /* end packet sentinel */
85 * This packet is used for file save info transfer.
88 int32_t pkt_size; /* size of this packet */
89 char *fname; /* Full path and filename */
90 char *link; /* Link name if any */
91 struct stat statp; /* System stat() packet for file */
92 int32_t type; /* FT_xx for this file */
93 uint64_t flags; /* Bacula internal flags */
94 bool no_read; /* During the save, the file should not be saved */
95 bool portable; /* set if data format is portable */
96 bool accurate_found; /* Found in accurate list (valid after check_changes()) */
97 char *cmd; /* command */
98 uint32_t delta_seq; /* Delta sequence number */
99 char *object_name; /* Object name to create */
100 char *object; /* restore object data to save */
101 int32_t object_len; /* restore object length */
102 int32_t index; /* restore object index */
103 int32_t pkt_end; /* end packet sentinel */
107 * This packet is used for file restore info transfer.
110 int32_t pkt_size; /* size of this packet */
111 int32_t stream; /* attribute stream id */
112 int32_t data_stream; /* id of data stream to follow */
113 int32_t type; /* file type FT */
114 int32_t file_index; /* file index */
115 int32_t LinkFI; /* file index to data if hard link */
116 uid_t uid; /* userid */
117 struct stat statp; /* decoded stat packet */
118 const char *attrEx; /* extended attributes if any */
119 const char *ofname; /* output filename */
120 const char *olname; /* output link name */
121 const char *where; /* where */
122 const char *RegexWhere; /* regex where */
123 int replace; /* replace flag */
124 int create_status; /* status from createFile() */
125 uint32_t delta_seq; /* Delta sequence number */
126 int32_t pkt_end; /* end packet sentinel */
138 int32_t pkt_size; /* Size of this packet */
139 int32_t func; /* Function code */
140 int32_t count; /* read/write count */
141 int32_t flags; /* Open flags */
142 mode_t mode; /* permissions for created files */
143 char *buf; /* read/write buffer */
144 const char *fname; /* open filename */
145 int32_t status; /* return status */
146 int32_t io_errno; /* errno code */
147 int32_t lerror; /* Win32 error code */
148 int32_t whence; /* lseek argument */
149 boffset_t offset; /* lseek argument or in bread current offset*/
150 bool win32; /* Win32 GetLastError returned */
151 int32_t pkt_end; /* end packet sentinel */
154 /****************************************************************************
156 * Bacula definitions *
158 ****************************************************************************/
160 /* Bacula Variable Ids */
173 bVarVssDllHandle = 12,
181 bVarPrevJobName = 20,
182 bVarPrefixLinks = 21,
183 bVarInteractiveSession = 22
186 /* Events that are passed to plugin */
190 bEventStartBackupJob = 3,
191 bEventEndBackupJob = 4,
192 bEventStartRestoreJob = 5,
193 bEventEndRestoreJob = 6,
194 bEventStartVerifyJob = 7,
195 bEventEndVerifyJob = 8,
196 bEventBackupCommand = 9,
197 bEventRestoreCommand = 10,
198 bEventEstimateCommand = 11,
201 bEventCancelCommand = 14, /* Executed by another thread */
202 bEventVssBackupAddComponents = 15, /* Just before bEventVssPrepareSnapshot */
203 bEventVssRestoreLoadComponentMetadata = 16,
204 bEventVssRestoreSetComponentsSelected = 17,
205 bEventRestoreObject = 18,
206 bEventEndFileSet = 19,
207 bEventPluginCommand = 20, /* Sent during FileSet creation */
208 bEventVssBeforeCloseRestore = 21,
209 /* Add drives to VSS snapshot
210 * argument: char[27] drivelist
211 * You need to add them without duplicates,
212 * see fd_common.h add_drive() copy_drives() to get help
214 bEventVssPrepareSnapshot = 22,
215 bEventOptionPlugin = 23,
216 bEventHandleBackupFile = 24, /* Used with Options Plugin */
217 bEventComponentInfo = 25 /* Plugin component */
220 typedef struct s_bEvent {
224 typedef struct s_baculaInfo {
229 /* Bacula Core Routines -- not used within a plugin */
231 struct BFILE; /* forward referenced */
233 void load_fd_plugins(const char *plugin_dir);
234 void new_plugins(JCR *jcr);
235 void free_plugins(JCR *jcr);
236 void generate_plugin_event(JCR *jcr, bEventType event, void *value=NULL);
237 bool send_plugin_name(JCR *jcr, BSOCK *sd, bool start);
238 bool plugin_name_stream(JCR *jcr, char *name);
239 int plugin_create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace);
240 bool plugin_set_attributes(JCR *jcr, ATTR *attr, BFILE *ofd);
241 int plugin_save(JCR *jcr, FF_PKT *ff_pkt, bool top_level);
242 int plugin_estimate(JCR *jcr, FF_PKT *ff_pkt, bool top_level);
243 bool plugin_check_file(JCR *jcr, char *fname);
244 bRC plugin_option_handle_file(JCR *jcr, FF_PKT *ff_pkt, struct save_pkt *sp);
252 * Bacula interface version and function pointers --
253 * i.e. callbacks from the plugin to Bacula
255 typedef struct s_baculaFuncs {
258 bRC (*registerBaculaEvents)(bpContext *ctx, ...);
259 bRC (*getBaculaValue)(bpContext *ctx, bVariable var, void *value);
260 bRC (*setBaculaValue)(bpContext *ctx, bVariable var, void *value);
261 bRC (*JobMessage)(bpContext *ctx, const char *file, int line,
262 int type, utime_t mtime, const char *fmt, ...);
263 bRC (*DebugMessage)(bpContext *ctx, const char *file, int line,
264 int level, const char *fmt, ...);
265 void *(*baculaMalloc)(bpContext *ctx, const char *file, int line,
267 void (*baculaFree)(bpContext *ctx, const char *file, int line, void *mem);
268 bRC (*AddExclude)(bpContext *ctx, const char *file);
269 bRC (*AddInclude)(bpContext *ctx, const char *file);
270 bRC (*AddOptions)(bpContext *ctx, const char *opts);
271 bRC (*AddRegex)(bpContext *ctx, const char *item, int type);
272 bRC (*AddWild)(bpContext *ctx, const char *item, int type);
273 bRC (*NewOptions)(bpContext *ctx);
274 bRC (*NewInclude)(bpContext *ctx);
275 bRC (*NewPreInclude)(bpContext *ctx);
276 bRC (*checkChanges)(bpContext *ctx, struct save_pkt *sp);
277 bRC (*AcceptFile)(bpContext *ctx, struct save_pkt *sp); /* Need fname and statp */
283 /****************************************************************************
285 * Plugin definitions *
287 ****************************************************************************/
294 # define FD_PLUGIN_MAGIC "*FDPluginData*"
296 #define FD_PLUGIN_INTERFACE_VERSION ( 13 )
298 typedef struct s_pluginInfo {
301 const char *plugin_magic;
302 const char *plugin_license;
303 const char *plugin_author;
304 const char *plugin_date;
305 const char *plugin_version;
306 const char *plugin_description;
310 * This is a set of function pointers that Bacula can call
313 typedef struct s_pluginFuncs {
316 bRC (*newPlugin)(bpContext *ctx);
317 bRC (*freePlugin)(bpContext *ctx);
318 bRC (*getPluginValue)(bpContext *ctx, pVariable var, void *value);
319 bRC (*setPluginValue)(bpContext *ctx, pVariable var, void *value);
320 bRC (*handlePluginEvent)(bpContext *ctx, bEvent *event, void *value);
321 bRC (*startBackupFile)(bpContext *ctx, struct save_pkt *sp);
322 bRC (*endBackupFile)(bpContext *ctx);
323 bRC (*startRestoreFile)(bpContext *ctx, const char *cmd);
324 bRC (*endRestoreFile)(bpContext *ctx);
325 bRC (*pluginIO)(bpContext *ctx, struct io_pkt *io);
326 bRC (*createFile)(bpContext *ctx, struct restore_pkt *rp);
327 bRC (*setFileAttributes)(bpContext *ctx, struct restore_pkt *rp);
328 bRC (*checkFile)(bpContext *ctx, char *fname);
331 #define plug_func(plugin) ((pFuncs *)(plugin->pfuncs))
332 #define plug_info(plugin) ((pInfo *)(plugin->pinfo))
338 #endif /* __FD_PLUGINS_H */