]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/plugins/fd/fd_common.h
9f9cdf57afadb9ef0a0da501eb61b8728a3c1dae
[bacula/bacula] / bacula / src / plugins / fd / fd_common.h
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2010-2010 Bacula Systems(R) SA
5
6    The main author of Bacula is Kern Sibbald, with contributions from
7    many others, a complete list can be found in the file AUTHORS.
8    This program is Free Software; you can modify it under the terms of
9    version three of the GNU Affero General Public License as published by the Free
10    Software Foundation, which is listed in the file LICENSE.
11
12    This program is distributed in the hope that it will be useful, but
13    WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15    General Public License for more details.
16
17    You should have received a copy of the GNU Affero General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20    02110-1301, USA.
21
22    Bacula® is a registered trademark of Kern Sibbald.
23    Bacula Systems(R) is a trademark of Bacula Systems SA.
24    Bacula Enterprise(TM) is a trademark of Bacula Systems SA.
25
26    The licensor of Bacula Enterprise(TM) is Bacula Systems(R) SA,
27    Rue Galilee 5, 1400 Yverdon-les-Bains, Switzerland.
28 */
29
30 /* You can include this file to your plugin to have
31  * access to some common tools and utilities provided by Bacula
32  */
33
34 #ifndef PCOMMON_H
35 #define PCOMMON_H
36
37 #define JT_BACKUP                'B'  /* Backup Job */
38 #define JT_RESTORE               'R'  /* Restore Job */
39
40 #define L_FULL                   'F'  /* Full backup */
41 #define L_INCREMENTAL            'I'  /* since last backup */
42 #define L_DIFFERENTIAL           'D'  /* since last full backup */
43
44 #ifndef DLL_IMP_EXP
45 # if defined(BUILDING_DLL)
46 #   define DLL_IMP_EXP   __declspec(dllexport)
47 # elif defined(USING_DLL)
48 #   define DLL_IMP_EXP   __declspec(dllimport)
49 # else
50 #   define DLL_IMP_EXP
51 # endif
52 #endif
53
54 DLL_IMP_EXP void *sm_malloc(const char *fname, int lineno, unsigned int nbytes);
55 DLL_IMP_EXP void sm_free(const char *file, int line, void *fp);
56 DLL_IMP_EXP void *reallymalloc(const char *fname, int lineno, unsigned int nbytes);
57 DLL_IMP_EXP void reallyfree(const char *file, int line, void *fp);
58
59 #ifndef bmalloc
60 # define bmalloc(s)      sm_malloc(__FILE__, __LINE__, (s))
61 # define bfree(o)        sm_free(__FILE__, __LINE__, (o))
62 #endif
63
64 #define SM_CHECK sm_check(__FILE__, __LINE__, false)
65
66 #ifdef malloc
67 #undef malloc
68 #undef free
69 #endif
70
71 #define malloc(s)    sm_malloc(__FILE__, __LINE__, (s))
72 #define free(o)      sm_free(__FILE__, __LINE__, (o))
73
74 inline void *operator new(size_t size, char const * file, int line)
75 {
76    void *pnew = sm_malloc(file,line, size);
77    memset((char *)pnew, 0, size);
78    return pnew;
79 }
80
81 inline void *operator new[](size_t size, char const * file, int line)
82 {
83    void *pnew = sm_malloc(file, line, size);
84    memset((char *)pnew, 0, size);
85    return pnew;
86 }
87
88 inline void *operator new(size_t size)
89 {
90    void *pnew = sm_malloc(__FILE__, __LINE__, size);
91    memset((char *)pnew, 0, size);
92    return pnew;
93 }
94
95 inline void *operator new[](size_t size)
96 {
97    void *pnew = sm_malloc(__FILE__, __LINE__, size);
98    memset((char *)pnew, 0, size);
99    return pnew;
100 }
101
102 #define new   new(__FILE__, __LINE__)
103
104 inline void operator delete(void *buf)
105 {
106    sm_free( __FILE__, __LINE__, buf);
107 }
108
109 inline void operator delete[] (void *buf)
110 {
111   sm_free(__FILE__, __LINE__, buf);
112 }
113
114 #define Dmsg(context, level,  ...) bfuncs->DebugMessage(context, __FILE__, __LINE__, level, __VA_ARGS__ )
115 #define Jmsg(context, type,  ...) bfuncs->JobMessage(context, __FILE__, __LINE__, type, 0, __VA_ARGS__ )
116
117
118 #ifdef USE_ADD_DRIVE
119 /* Keep drive letters for windows vss snapshot */
120 static void add_drive(char *drives, int *nCount, char *fname) {
121    if (strlen(fname) >= 2 && B_ISALPHA(fname[0]) && fname[1] == ':') {
122       /* always add in uppercase */
123       char ch = toupper(fname[0]);
124       /* if not found in string, add drive letter */
125       if (!strchr(drives,ch)) {
126          drives[*nCount] = ch;
127          drives[*nCount+1] = 0;
128          (*nCount)++;
129       }                                
130    }
131 }
132
133 /* Copy our drive list to Bacula core list */
134 static void copy_drives(char *drives, char *dest) {
135    int last = strlen(dest);     /* dest is 27 bytes long */
136    for (char *p = drives; *p && last < 26; p++) {
137       if (!strchr(dest, *p)) {
138          dest[last++] = *p;
139          dest[last] = 0;
140       }
141    }
142 }
143 #endif
144
145 #endif