/src/samba/lib/util/gpfswrap.c
Line | Count | Source |
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_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_fn)(int fd, int flags, |
33 | | struct gpfs_winattr *attrs); |
34 | | static int (*gpfs_get_winattrs_fn)(int fd, struct gpfs_winattr *attrs); |
35 | | static int (*gpfs_ftruncate_fn)(int fd, gpfs_off64_t length); |
36 | | static int (*gpfs_lib_init_fn)(int flags); |
37 | | static int (*gpfs_set_times_fn)(int fd, int flags, gpfs_timestruc_t times[4]); |
38 | | static int (*gpfs_set_times_path_fn)(char *path, |
39 | | int flags, |
40 | | gpfs_timestruc_t times[4]); |
41 | | static int (*gpfs_quotactl_fn)(const char *pathname, |
42 | | int cmd, |
43 | | int id, |
44 | | void *bufp); |
45 | | static int (*gpfs_init_trace_fn)(void); |
46 | | static int (*gpfs_query_trace_fn)(void); |
47 | | static void (*gpfs_add_trace_fn)(int level, const char *msg); |
48 | | static void (*gpfs_fini_trace_fn)(void); |
49 | | |
50 | | int gpfswrap_init(void) |
51 | 0 | { |
52 | 0 | static void *l; |
53 | |
|
54 | 0 | if (l != NULL) { |
55 | 0 | return 0; |
56 | 0 | } |
57 | | |
58 | 0 | l = dlopen("libgpfs.so", RTLD_LAZY); |
59 | 0 | if (l == NULL) { |
60 | 0 | return -1; |
61 | 0 | } |
62 | | |
63 | 0 | gpfs_set_share_fn = dlsym(l, "gpfs_set_share"); |
64 | 0 | gpfs_set_lease_fn = dlsym(l, "gpfs_set_lease"); |
65 | 0 | gpfs_fgetacl_fn = dlsym(l, "gpfs_getacl_fd"); |
66 | 0 | gpfs_putacl_fn = dlsym(l, "gpfs_putacl"); |
67 | 0 | gpfs_get_realfilename_path_fn = dlsym(l, "gpfs_get_realfilename_path"); |
68 | 0 | gpfs_register_cifs_export_fn = dlsym(l, "gpfs_register_cifs_export"); |
69 | 0 | gpfs_set_winattrs_fn = dlsym(l, "gpfs_set_winattrs"); |
70 | 0 | gpfs_get_winattrs_fn = dlsym(l, "gpfs_get_winattrs"); |
71 | 0 | gpfs_ftruncate_fn = dlsym(l, "gpfs_ftruncate"); |
72 | 0 | gpfs_lib_init_fn = dlsym(l, "gpfs_lib_init"); |
73 | 0 | gpfs_set_times_fn = dlsym(l, "gpfs_set_times"); |
74 | 0 | gpfs_set_times_path_fn = dlsym(l, "gpfs_set_times_path"); |
75 | 0 | gpfs_quotactl_fn = dlsym(l, "gpfs_quotactl"); |
76 | 0 | gpfs_init_trace_fn = dlsym(l, "gpfs_init_trace"); |
77 | 0 | gpfs_query_trace_fn = dlsym(l, "gpfs_query_trace"); |
78 | 0 | gpfs_add_trace_fn = dlsym(l, "gpfs_add_trace"); |
79 | 0 | gpfs_fini_trace_fn = dlsym(l, "gpfs_fini_trace"); |
80 | |
|
81 | 0 | return 0; |
82 | 0 | } |
83 | | |
84 | | int gpfswrap_set_share(int fd, unsigned int allow, unsigned int deny) |
85 | 0 | { |
86 | 0 | if (gpfs_set_share_fn == NULL) { |
87 | 0 | errno = ENOSYS; |
88 | 0 | return -1; |
89 | 0 | } |
90 | | |
91 | 0 | return gpfs_set_share_fn(fd, allow, deny); |
92 | 0 | } |
93 | | |
94 | | int gpfswrap_set_lease(int fd, unsigned int type) |
95 | 0 | { |
96 | 0 | if (gpfs_set_lease_fn == NULL) { |
97 | 0 | errno = ENOSYS; |
98 | 0 | return -1; |
99 | 0 | } |
100 | | |
101 | 0 | return gpfs_set_lease_fn(fd, type); |
102 | 0 | } |
103 | | |
104 | | int gpfswrap_fgetacl(int fd, int flags, void *acl) |
105 | 0 | { |
106 | 0 | if (gpfs_fgetacl_fn == NULL) { |
107 | 0 | errno = ENOSYS; |
108 | 0 | return -1; |
109 | 0 | } |
110 | | |
111 | 0 | return gpfs_fgetacl_fn(fd, flags, acl); |
112 | 0 | } |
113 | | |
114 | | int gpfswrap_putacl(const char *pathname, int flags, void *acl) |
115 | 0 | { |
116 | 0 | if (gpfs_putacl_fn == NULL) { |
117 | 0 | errno = ENOSYS; |
118 | 0 | return -1; |
119 | 0 | } |
120 | | |
121 | 0 | return gpfs_putacl_fn(pathname, flags, acl); |
122 | 0 | } |
123 | | |
124 | | int gpfswrap_get_realfilename_path(const char *pathname, |
125 | | char *filenamep, |
126 | | int *len) |
127 | 0 | { |
128 | 0 | if (gpfs_get_realfilename_path_fn == NULL) { |
129 | 0 | errno = ENOSYS; |
130 | 0 | return -1; |
131 | 0 | } |
132 | | |
133 | 0 | return gpfs_get_realfilename_path_fn(pathname, filenamep, len); |
134 | 0 | } |
135 | | |
136 | | int gpfswrap_register_cifs_export(void) |
137 | 0 | { |
138 | 0 | if (gpfs_register_cifs_export_fn == NULL) { |
139 | 0 | errno = ENOSYS; |
140 | 0 | return -1; |
141 | 0 | } |
142 | | |
143 | 0 | return gpfs_register_cifs_export_fn(); |
144 | 0 | } |
145 | | |
146 | | int gpfswrap_set_winattrs(int fd, int flags, struct gpfs_winattr *attrs) |
147 | 0 | { |
148 | 0 | if (gpfs_set_winattrs_fn == NULL) { |
149 | 0 | errno = ENOSYS; |
150 | 0 | return -1; |
151 | 0 | } |
152 | | |
153 | 0 | return gpfs_set_winattrs_fn(fd, flags, attrs); |
154 | 0 | } |
155 | | |
156 | | int gpfswrap_get_winattrs(int fd, struct gpfs_winattr *attrs) |
157 | 0 | { |
158 | 0 | if (gpfs_get_winattrs_fn == NULL) { |
159 | 0 | errno = ENOSYS; |
160 | 0 | return -1; |
161 | 0 | } |
162 | | |
163 | 0 | return gpfs_get_winattrs_fn(fd, attrs); |
164 | 0 | } |
165 | | |
166 | | int gpfswrap_ftruncate(int fd, gpfs_off64_t length) |
167 | 0 | { |
168 | 0 | if (gpfs_ftruncate_fn == NULL) { |
169 | 0 | errno = ENOSYS; |
170 | 0 | return -1; |
171 | 0 | } |
172 | | |
173 | 0 | return gpfs_ftruncate_fn(fd, length); |
174 | 0 | } |
175 | | |
176 | | int gpfswrap_lib_init(int flags) |
177 | 0 | { |
178 | 0 | if (gpfs_lib_init_fn == NULL) { |
179 | 0 | errno = ENOSYS; |
180 | 0 | return -1; |
181 | 0 | } |
182 | | |
183 | 0 | return gpfs_lib_init_fn(flags); |
184 | 0 | } |
185 | | |
186 | | int gpfswrap_set_times(int fd, int flags, gpfs_timestruc_t times[4]) |
187 | 0 | { |
188 | 0 | if (gpfs_set_times_fn == NULL) { |
189 | 0 | errno = ENOSYS; |
190 | 0 | return -1; |
191 | 0 | } |
192 | | |
193 | 0 | return gpfs_set_times_fn(fd, flags, times); |
194 | 0 | } |
195 | | |
196 | | int gpfswrap_set_times_path(char *path, int flags, gpfs_timestruc_t times[4]) |
197 | 0 | { |
198 | 0 | if (gpfs_set_times_path_fn == NULL) { |
199 | 0 | errno = ENOSYS; |
200 | 0 | return -1; |
201 | 0 | } |
202 | | |
203 | 0 | return gpfs_set_times_path_fn(path, flags, times); |
204 | 0 | } |
205 | | |
206 | | int gpfswrap_quotactl(const char *pathname, int cmd, int id, void *bufp) |
207 | 0 | { |
208 | 0 | if (gpfs_quotactl_fn == NULL) { |
209 | 0 | errno = ENOSYS; |
210 | 0 | return -1; |
211 | 0 | } |
212 | | |
213 | 0 | return gpfs_quotactl_fn(pathname, cmd, id, bufp); |
214 | 0 | } |
215 | | |
216 | | int gpfswrap_init_trace(void) |
217 | 0 | { |
218 | 0 | if (gpfs_init_trace_fn == NULL) { |
219 | 0 | errno = ENOSYS; |
220 | 0 | return -1; |
221 | 0 | } |
222 | | |
223 | 0 | return gpfs_init_trace_fn(); |
224 | 0 | } |
225 | | |
226 | | int gpfswrap_query_trace(void) |
227 | 0 | { |
228 | 0 | if (gpfs_query_trace_fn == NULL) { |
229 | 0 | errno = ENOSYS; |
230 | 0 | return -1; |
231 | 0 | } |
232 | | |
233 | 0 | return gpfs_query_trace_fn(); |
234 | 0 | } |
235 | | |
236 | | void gpfswrap_add_trace(int level, const char *msg) |
237 | 0 | { |
238 | 0 | if (gpfs_add_trace_fn == NULL) { |
239 | 0 | return; |
240 | 0 | } |
241 | | |
242 | 0 | gpfs_add_trace_fn(level, msg); |
243 | 0 | } |
244 | | |
245 | | void gpfswrap_fini_trace(void) |
246 | 0 | { |
247 | 0 | if (gpfs_fini_trace_fn == NULL) { |
248 | 0 | return; |
249 | 0 | } |
250 | | |
251 | 0 | gpfs_fini_trace_fn(); |
252 | 0 | } |