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