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