Next: loadPlugin Up: Bacula FD Plugin API Previous: Normal vs Command Plugins Contents Index

# Loading Plugins

Once the File daemon loads the plugins, it asks the OS for the two entry points (loadPlugin and unloadPlugin) then calls the loadPlugin entry point (see below).

Bacula passes information to the plugin through this call and it gets back information that it needs to use the plugin. Later, Bacula will call particular functions that are defined by the loadPlugin interface.

When Bacula is finished with the plugin (when Bacula is going to exit), it will call the unloadPlugin entry point.

The two entry points are:

    bRC loadPlugin(bInfo *lbinfo, bFuncs *lbfuncs, pInfo **pinfo, pFuncs **pfuncs)

    and

    bRC unloadPlugin()

both these external entry points to the shared object are defined as C entry points to avoid name mangling complications with C++. However, the shared object can actually be written in any language (preferrably C or C++) providing that it follows C language calling conventions.

The definitions for bRC and the arguments are src/filed/fd-plugins.h and so this header file needs to be included in your plugin. It along with src/lib/plugins.h define basically the whole plugin interface. Within this header file, it includes the following files:

    #include <sys/types.h>
    #include "config.h"
    #include "bc_types.h"
    #include "lib/plugins.h"
    #include <sys/stat.h>

Aside from the bc_types.h and confit.h headers, the plugin definition uses the minimum code from Bacula. The bc_types.h file is required to ensure that the data type defintions in arguments correspond to the Bacula core code.

The return codes are defined as:

    typedef enum {
      bRC_OK    = 0,                         /* OK */
      bRC_Stop  = 1,                         /* Stop calling other plugins */
      bRC_Error = 2,                         /* Some kind of error */
      bRC_More  = 3,                         /* More files to backup */
    } bRC;

At a future point in time, we hope to make the Bacula libbac.a into a shared object so that the plugin can use much more of Bacula's infrastructure, but for this first cut, we have tried to minimize the dependence on Bacula.

Next: loadPlugin Up: Bacula FD Plugin API Previous: Normal vs Command Plugins Contents Index