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