]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/plugins/fd/fd_common.h
Backport from BEE
[bacula/bacula] / bacula / src / plugins / fd / fd_common.h
1 /*
2 /*
3    Bacula® - The Network Backup Solution
4
5    Copyright (C) 2010-2014 Free Software Foundation Europe e.V.
6
7    The main author of Bacula is Kern Sibbald, with contributions from many
8    others, a complete list can be found in the file AUTHORS.
9
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.
14
15    Bacula® is a registered trademark of Kern Sibbald.
16
17 */
18
19 /* You can include this file to your plugin to have
20  * access to some common tools and utilities provided by Bacula
21  */
22
23 #ifndef PCOMMON_H
24 #define PCOMMON_H
25
26 #define JT_BACKUP                'B'  /* Backup Job */
27 #define JT_RESTORE               'R'  /* Restore Job */
28
29 #define L_FULL                   'F'  /* Full backup */
30 #define L_INCREMENTAL            'I'  /* since last backup */
31 #define L_DIFFERENTIAL           'D'  /* since last full backup */
32
33 #ifndef DLL_IMP_EXP
34 # if defined(BUILDING_DLL)
35 #   define DLL_IMP_EXP   __declspec(dllexport)
36 # elif defined(USING_DLL)
37 #   define DLL_IMP_EXP   __declspec(dllimport)
38 # else
39 #   define DLL_IMP_EXP
40 # endif
41 #endif
42
43 DLL_IMP_EXP void *sm_malloc(const char *fname, int lineno, unsigned int nbytes);
44 DLL_IMP_EXP void sm_free(const char *file, int line, void *fp);
45 DLL_IMP_EXP void *reallymalloc(const char *fname, int lineno, unsigned int nbytes);
46 DLL_IMP_EXP void reallyfree(const char *file, int line, void *fp);
47
48 #ifndef bmalloc
49 # define bmalloc(s)      sm_malloc(__FILE__, __LINE__, (s))
50 # define bfree(o)        sm_free(__FILE__, __LINE__, (o))
51 #endif
52
53 #define SM_CHECK sm_check(__FILE__, __LINE__, false)
54
55 #ifdef malloc
56 #undef malloc
57 #undef free
58 #endif
59
60 #define malloc(s)    sm_malloc(__FILE__, __LINE__, (s))
61 #define free(o)      sm_free(__FILE__, __LINE__, (o))
62
63 inline void *operator new(size_t size, char const * file, int line)
64 {
65    void *pnew = sm_malloc(file,line, size);
66    memset((char *)pnew, 0, size);
67    return pnew;
68 }
69
70 inline void *operator new[](size_t size, char const * file, int line)
71 {
72    void *pnew = sm_malloc(file, line, size);
73    memset((char *)pnew, 0, size);
74    return pnew;
75 }
76
77 inline void *operator new(size_t size)
78 {
79    void *pnew = sm_malloc(__FILE__, __LINE__, size);
80    memset((char *)pnew, 0, size);
81    return pnew;
82 }
83
84 inline void *operator new[](size_t size)
85 {
86    void *pnew = sm_malloc(__FILE__, __LINE__, size);
87    memset((char *)pnew, 0, size);
88    return pnew;
89 }
90
91 #define new   new(__FILE__, __LINE__)
92
93 inline void operator delete(void *buf)
94 {
95    sm_free( __FILE__, __LINE__, buf);
96 }
97
98 inline void operator delete[] (void *buf)
99 {
100   sm_free(__FILE__, __LINE__, buf);
101 }
102
103 #define Dmsg(context, level,  ...) bfuncs->DebugMessage(context, __FILE__, __LINE__, level, __VA_ARGS__ )
104 #define Jmsg(context, type,  ...) bfuncs->JobMessage(context, __FILE__, __LINE__, type, 0, __VA_ARGS__ )
105
106
107 #ifdef USE_ADD_DRIVE
108 /* Keep drive letters for windows vss snapshot */
109 static void add_drive(char *drives, int *nCount, char *fname) {
110    if (strlen(fname) >= 2 && B_ISALPHA(fname[0]) && fname[1] == ':') {
111       /* always add in uppercase */
112       char ch = toupper(fname[0]);
113       /* if not found in string, add drive letter */
114       if (!strchr(drives,ch)) {
115          drives[*nCount] = ch;
116          drives[*nCount+1] = 0;
117          (*nCount)++;
118       }
119    }
120 }
121
122 /* Copy our drive list to Bacula core list */
123 static void copy_drives(char *drives, char *dest) {
124    int last = strlen(dest);     /* dest is 27 bytes long */
125    for (char *p = drives; *p && last < 26; p++) {
126       if (!strchr(dest, *p)) {
127          dest[last++] = *p;
128          dest[last] = 0;
129       }
130    }
131 }
132 #endif
133
134 #endif