gpfswrap: Add wrapper for gpfs_register_cifs_export
[Samba.git] / lib / util / gpfswrap.c
blob2f15bf452cf6ab6a6a4043729d392fa457d0fd07
1 /*
2 * Unix SMB/CIFS implementation.
3 * Wrapper for GPFS library
4 * Copyright (C) Volker Lendecke 2005
5 * Copyright (C) Christof Schmitt 2015
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.
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.
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/>.
21 #include "replace.h"
22 #include "gpfswrap.h"
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_fgetacl_fn)(int fd, int flags, void *acl);
27 static int (*gpfs_putacl_fn)(const char *pathname, int flags, void *acl);
28 static int (*gpfs_get_realfilename_path_fn)(const char *pathname,
29 char *filenamep,
30 int *len);
31 static int (*gpfs_register_cifs_export_fn)(void);
32 static int (*gpfs_set_winattrs_path_fn)(const char *pathname,
33 int flags,
34 struct gpfs_winattr *attrs);
35 static int (*gpfs_set_winattrs_fn)(int fd, int flags,
36 struct gpfs_winattr *attrs);
37 static int (*gpfs_get_winattrs_fn)(int fd, struct gpfs_winattr *attrs);
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_fn)(int fd, int flags, gpfs_timestruc_t times[4]);
41 static int (*gpfs_set_times_path_fn)(char *path,
42 int flags,
43 gpfs_timestruc_t times[4]);
44 static int (*gpfs_quotactl_fn)(const char *pathname,
45 int cmd,
46 int id,
47 void *bufp);
48 static int (*gpfs_init_trace_fn)(void);
49 static int (*gpfs_query_trace_fn)(void);
50 static void (*gpfs_add_trace_fn)(int level, const char *msg);
51 static void (*gpfs_fini_trace_fn)(void);
52 static int (*gpfs_fstat_x_fn)(int fd, unsigned int *litemask,
53 struct gpfs_iattr64 *iattr, size_t len);
54 static int (*gpfs_stat_x_fn)(const char *pathname, unsigned int *litemask,
55 struct gpfs_iattr64 *iattr, size_t len);
57 int gpfswrap_init(void)
59 static void *l;
61 if (l != NULL) {
62 return 0;
65 l = dlopen("libgpfs.so", RTLD_LAZY);
66 if (l == NULL) {
67 return -1;
70 gpfs_set_share_fn = dlsym(l, "gpfs_set_share");
71 gpfs_set_lease_fn = dlsym(l, "gpfs_set_lease");
72 gpfs_fgetacl_fn = dlsym(l, "gpfs_getacl_fd");
73 gpfs_putacl_fn = dlsym(l, "gpfs_putacl");
74 gpfs_get_realfilename_path_fn = dlsym(l, "gpfs_get_realfilename_path");
75 gpfs_register_cifs_export_fn = dlsym(l, "gpfs_register_cifs_export");
76 gpfs_set_winattrs_path_fn = dlsym(l, "gpfs_set_winattrs_path");
77 gpfs_set_winattrs_fn = dlsym(l, "gpfs_set_winattrs");
78 gpfs_get_winattrs_fn = dlsym(l, "gpfs_get_winattrs");
79 gpfs_ftruncate_fn = dlsym(l, "gpfs_ftruncate");
80 gpfs_lib_init_fn = dlsym(l, "gpfs_lib_init");
81 gpfs_set_times_fn = dlsym(l, "gpfs_set_times");
82 gpfs_set_times_path_fn = dlsym(l, "gpfs_set_times_path");
83 gpfs_quotactl_fn = dlsym(l, "gpfs_quotactl");
84 gpfs_init_trace_fn = dlsym(l, "gpfs_init_trace");
85 gpfs_query_trace_fn = dlsym(l, "gpfs_query_trace");
86 gpfs_add_trace_fn = dlsym(l, "gpfs_add_trace");
87 gpfs_fini_trace_fn = dlsym(l, "gpfs_fini_trace");
88 gpfs_fstat_x_fn = dlsym(l, "gpfs_fstat_x");
89 gpfs_stat_x_fn = dlsym(l, "gpfs_stat_x");
91 return 0;
94 int gpfswrap_set_share(int fd, unsigned int allow, unsigned int deny)
96 if (gpfs_set_share_fn == NULL) {
97 errno = ENOSYS;
98 return -1;
101 return gpfs_set_share_fn(fd, allow, deny);
104 int gpfswrap_set_lease(int fd, unsigned int type)
106 if (gpfs_set_lease_fn == NULL) {
107 errno = ENOSYS;
108 return -1;
111 return gpfs_set_lease_fn(fd, type);
114 int gpfswrap_fgetacl(int fd, int flags, void *acl)
116 if (gpfs_fgetacl_fn == NULL) {
117 errno = ENOSYS;
118 return -1;
121 return gpfs_fgetacl_fn(fd, flags, acl);
124 int gpfswrap_putacl(const char *pathname, int flags, void *acl)
126 if (gpfs_putacl_fn == NULL) {
127 errno = ENOSYS;
128 return -1;
131 return gpfs_putacl_fn(pathname, flags, acl);
134 int gpfswrap_get_realfilename_path(const char *pathname,
135 char *filenamep,
136 int *len)
138 if (gpfs_get_realfilename_path_fn == NULL) {
139 errno = ENOSYS;
140 return -1;
143 return gpfs_get_realfilename_path_fn(pathname, filenamep, len);
146 int gpfswrap_register_cifs_export(void)
148 if (gpfs_register_cifs_export_fn == NULL) {
149 errno = ENOSYS;
150 return -1;
153 return gpfs_register_cifs_export_fn();
156 int gpfswrap_set_winattrs_path(const char *pathname,
157 int flags,
158 struct gpfs_winattr *attrs)
160 if (gpfs_set_winattrs_path_fn == NULL) {
161 errno = ENOSYS;
162 return -1;
165 return gpfs_set_winattrs_path_fn(pathname, flags, attrs);
168 int gpfswrap_set_winattrs(int fd, int flags, struct gpfs_winattr *attrs)
170 if (gpfs_set_winattrs_fn == NULL) {
171 errno = ENOSYS;
172 return -1;
175 return gpfs_set_winattrs_fn(fd, flags, attrs);
178 int gpfswrap_get_winattrs(int fd, struct gpfs_winattr *attrs)
180 if (gpfs_get_winattrs_fn == NULL) {
181 errno = ENOSYS;
182 return -1;
185 return gpfs_get_winattrs_fn(fd, attrs);
188 int gpfswrap_ftruncate(int fd, gpfs_off64_t length)
190 if (gpfs_ftruncate_fn == NULL) {
191 errno = ENOSYS;
192 return -1;
195 return gpfs_ftruncate_fn(fd, length);
198 int gpfswrap_lib_init(int flags)
200 if (gpfs_lib_init_fn == NULL) {
201 errno = ENOSYS;
202 return -1;
205 return gpfs_lib_init_fn(flags);
208 int gpfswrap_set_times(int fd, int flags, gpfs_timestruc_t times[4])
210 if (gpfs_set_times_fn == NULL) {
211 errno = ENOSYS;
212 return -1;
215 return gpfs_set_times_fn(fd, flags, times);
218 int gpfswrap_set_times_path(char *path, int flags, gpfs_timestruc_t times[4])
220 if (gpfs_set_times_path_fn == NULL) {
221 errno = ENOSYS;
222 return -1;
225 return gpfs_set_times_path_fn(path, flags, times);
228 int gpfswrap_quotactl(const char *pathname, int cmd, int id, void *bufp)
230 if (gpfs_quotactl_fn == NULL) {
231 errno = ENOSYS;
232 return -1;
235 return gpfs_quotactl_fn(pathname, cmd, id, bufp);
238 int gpfswrap_init_trace(void)
240 if (gpfs_init_trace_fn == NULL) {
241 errno = ENOSYS;
242 return -1;
245 return gpfs_init_trace_fn();
248 int gpfswrap_query_trace(void)
250 if (gpfs_query_trace_fn == NULL) {
251 errno = ENOSYS;
252 return -1;
255 return gpfs_query_trace_fn();
258 void gpfswrap_add_trace(int level, const char *msg)
260 if (gpfs_add_trace_fn == NULL) {
261 return;
264 gpfs_add_trace_fn(level, msg);
267 void gpfswrap_fini_trace(void)
269 if (gpfs_fini_trace_fn == NULL) {
270 return;
273 gpfs_fini_trace_fn();
276 int gpfswrap_fstat_x(int fd, unsigned int *litemask,
277 struct gpfs_iattr64 *iattr, size_t len)
279 if (gpfs_fstat_x_fn == NULL) {
280 errno = ENOSYS;
281 return -1;
284 return gpfs_fstat_x_fn(fd, litemask, iattr, len);
287 int gpfswrap_stat_x(const char *pathname, unsigned int *litemask,
288 struct gpfs_iattr64 *iattr, size_t len)
290 if (gpfs_stat_x_fn == NULL) {
291 errno = ENOSYS;
292 return -1;
295 return gpfs_stat_x_fn(pathname, litemask, iattr, len);