replace: Add check for variable program_invocation_short_name
[bbaumbach/samba-autobuild/.git] / lib / util / gpfswrap.c
1 /*
2  *  Unix SMB/CIFS implementation.
3  *  Wrapper for GPFS library
4  *  Copyright (C) Volker Lendecke 2005
5  *  Copyright (C) Christof Schmitt 2015
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 3 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #include "replace.h"
22 #include "gpfswrap.h"
23
24 static int (*gpfs_set_share_fn)(int fd, unsigned int allow, unsigned int deny);
25 static int (*gpfs_set_lease_fn)(int fd, unsigned int type);
26 static int (*gpfs_getacl_fn)(char *pathname, int flags, void *acl);
27 static int (*gpfs_putacl_fn)(char *pathname, int flags, void *acl);
28 static int (*gpfs_get_realfilename_path_fn)(char *pathname, char *filenamep,
29                                             int *len);
30 static int (*gpfs_set_winattrs_path_fn)(char *pathname, int flags,
31                                         struct gpfs_winattr *attrs);
32 static int (*gpfs_set_winattrs_fn)(int fd, int flags,
33                                    struct gpfs_winattr *attrs);
34 static int (*gpfs_get_winattrs_path_fn)(char *pathname,
35                                         struct gpfs_winattr *attrs);
36 static int (*gpfs_get_winattrs_fn)(int fd, struct gpfs_winattr *attrs);
37 static int (*gpfs_prealloc_fn)(int fd, gpfs_off64_t start, gpfs_off64_t bytes);
38 static int (*gpfs_ftruncate_fn)(int fd, gpfs_off64_t length);
39 static int (*gpfs_lib_init_fn)(int flags);
40 static int (*gpfs_set_times_path_fn)(char *pathname, int flags,
41                                      gpfs_timestruc_t times[4]);
42 static int (*gpfs_quotactl_fn)(char *pathname, int cmd, int id, void *bufp);
43 static int (*gpfs_getfilesetid_fn)(char *pathname, char *name, int *idp);
44 static int (*gpfs_init_trace_fn)(void);
45 static int (*gpfs_query_trace_fn)(void);
46 static void (*gpfs_add_trace_fn)(int level, const char *msg);
47 static void (*gpfs_fini_trace_fn)(void);
48
49 int gpfswrap_init(void)
50 {
51         static void *l;
52
53         if (l != NULL) {
54                 return 0;
55         }
56
57         l = dlopen("libgpfs.so", RTLD_LAZY);
58         if (l == NULL) {
59                 return -1;
60         }
61
62         gpfs_set_share_fn             = dlsym(l, "gpfs_set_share");
63         gpfs_set_lease_fn             = dlsym(l, "gpfs_set_lease");
64         gpfs_getacl_fn                = dlsym(l, "gpfs_getacl");
65         gpfs_putacl_fn                = dlsym(l, "gpfs_putacl");
66         gpfs_get_realfilename_path_fn = dlsym(l, "gpfs_get_realfilename_path");
67         gpfs_set_winattrs_path_fn     = dlsym(l, "gpfs_set_winattrs_path");
68         gpfs_set_winattrs_fn          = dlsym(l, "gpfs_set_winattrs");
69         gpfs_get_winattrs_path_fn     = dlsym(l, "gpfs_get_winattrs_path");
70         gpfs_get_winattrs_fn          = dlsym(l, "gpfs_get_winattrs");
71         gpfs_prealloc_fn              = dlsym(l, "gpfs_prealloc");
72         gpfs_ftruncate_fn             = dlsym(l, "gpfs_ftruncate");
73         gpfs_lib_init_fn              = dlsym(l, "gpfs_lib_init");
74         gpfs_set_times_path_fn        = dlsym(l, "gpfs_set_times_path");
75         gpfs_quotactl_fn              = dlsym(l, "gpfs_quotactl");
76         gpfs_getfilesetid_fn          = dlsym(l, "gpfs_getfilesetid");
77         gpfs_init_trace_fn            = dlsym(l, "gpfs_init_trace");
78         gpfs_query_trace_fn           = dlsym(l, "gpfs_query_trace");
79         gpfs_add_trace_fn             = dlsym(l, "gpfs_add_trace");
80         gpfs_fini_trace_fn            = dlsym(l, "gpfs_fini_trace");
81
82         return 0;
83 }
84
85 int gpfswrap_set_share(int fd, unsigned int allow, unsigned int deny)
86 {
87         if (gpfs_set_share_fn == NULL) {
88                 errno = ENOSYS;
89                 return -1;
90         }
91
92         return gpfs_set_share_fn(fd, allow, deny);
93 }
94
95 int gpfswrap_set_lease(int fd, unsigned int type)
96 {
97         if (gpfs_set_lease_fn == NULL) {
98                 errno = ENOSYS;
99                 return -1;
100         }
101
102         return gpfs_set_lease_fn(fd, type);
103 }
104
105 int gpfswrap_getacl(char *pathname, int flags, void *acl)
106 {
107         if (gpfs_getacl_fn == NULL) {
108                 errno = ENOSYS;
109                 return -1;
110         }
111
112         return gpfs_getacl_fn(pathname, flags, acl);
113 }
114
115 int gpfswrap_putacl(char *pathname, int flags, void *acl)
116 {
117         if (gpfs_putacl_fn == NULL) {
118                 errno = ENOSYS;
119                 return -1;
120         }
121
122         return gpfs_putacl_fn(pathname, flags, acl);
123 }
124
125 int gpfswrap_get_realfilename_path(char *pathname, char *filenamep, int *len)
126 {
127         if (gpfs_get_realfilename_path_fn == NULL) {
128                 errno = ENOSYS;
129                 return -1;
130         }
131
132         return gpfs_get_realfilename_path_fn(pathname, filenamep, len);
133 }
134
135 int gpfswrap_set_winattrs_path(char *pathname, int flags,
136                                struct gpfs_winattr *attrs)
137 {
138         if (gpfs_set_winattrs_path_fn == NULL) {
139                 errno = ENOSYS;
140                 return -1;
141         }
142
143         return gpfs_set_winattrs_path_fn(pathname, flags, attrs);
144 }
145
146 int gpfswrap_set_winattrs(int fd, int flags, struct gpfs_winattr *attrs)
147 {
148         if (gpfs_set_winattrs_fn == NULL) {
149                 errno = ENOSYS;
150                 return -1;
151         }
152
153         return gpfs_set_winattrs_fn(fd, flags, attrs);
154 }
155
156 int gpfswrap_get_winattrs_path(char *pathname, struct gpfs_winattr *attrs)
157 {
158         if (gpfs_get_winattrs_path_fn == NULL) {
159                 errno = ENOSYS;
160                 return -1;
161         }
162
163         return gpfs_get_winattrs_path_fn(pathname, attrs);
164 }
165
166 int gpfswrap_get_winattrs(int fd, struct gpfs_winattr *attrs)
167 {
168         if (gpfs_get_winattrs_fn == NULL) {
169                 errno = ENOSYS;
170                 return -1;
171         }
172
173         return gpfs_get_winattrs_fn(fd, attrs);
174 }
175
176 int gpfswrap_prealloc(int fd, gpfs_off64_t start, gpfs_off64_t bytes)
177 {
178         if (gpfs_prealloc_fn == NULL) {
179                 errno = ENOSYS;
180                 return -1;
181         }
182
183         return gpfs_prealloc_fn(fd, start, bytes);
184 }
185
186 int gpfswrap_ftruncate(int fd, gpfs_off64_t length)
187 {
188         if (gpfs_ftruncate_fn == NULL) {
189                 errno = ENOSYS;
190                 return -1;
191         }
192
193         return gpfs_ftruncate_fn(fd, length);
194 }
195
196 int gpfswrap_lib_init(int flags)
197 {
198         if (gpfs_lib_init_fn == NULL) {
199                 errno = ENOSYS;
200                 return -1;
201         }
202
203         return gpfs_lib_init_fn(flags);
204 }
205
206 int gpfswrap_set_times_path(char *pathname, int flags,
207                             gpfs_timestruc_t times[4])
208 {
209         if (gpfs_set_times_path_fn == NULL) {
210                 errno = ENOSYS;
211                 return -1;
212         }
213
214         return gpfs_set_times_path_fn(pathname, flags, times);
215 }
216
217 int gpfswrap_quotactl(char *pathname, int cmd, int id, void *bufp)
218 {
219         if (gpfs_quotactl_fn == NULL) {
220                 errno = ENOSYS;
221                 return -1;
222         }
223
224         return gpfs_quotactl_fn(pathname, cmd, id, bufp);
225 }
226
227 int gpfswrap_getfilesetid(char *pathname, char *name, int *idp)
228 {
229         if (gpfs_getfilesetid_fn == NULL) {
230                 errno = ENOSYS;
231                 return -1;
232         }
233
234         return gpfs_getfilesetid_fn(pathname, name, idp);
235 }
236
237 int gpfswrap_init_trace(void)
238 {
239         if (gpfs_init_trace_fn == NULL) {
240                 errno = ENOSYS;
241                 return -1;
242         }
243
244         return gpfs_init_trace_fn();
245 }
246
247 int gpfswrap_query_trace(void)
248 {
249         if (gpfs_query_trace_fn == NULL) {
250                 errno = ENOSYS;
251                 return -1;
252         }
253
254         return gpfs_query_trace_fn();
255 }
256
257 void gpfswrap_add_trace(int level, const char *msg)
258 {
259         if (gpfs_add_trace_fn == NULL) {
260                 return;
261         }
262
263         gpfs_add_trace_fn(level, msg);
264 }
265
266 void gpfswrap_fini_trace(void)
267 {
268         if (gpfs_fini_trace_fn == NULL) {
269                 return;
270         }
271
272         gpfs_fini_trace_fn();
273 }