gpfs: Include gpfs_fcntl.h only from vfs_gpfs header file
[bbaumbach/samba-autobuild/.git] / source3 / modules / gpfs.c
1 /*
2  *  Unix SMB/CIFS implementation.
3  *  Provide a connection to GPFS specific features
4  *  Copyright (C) Volker Lendecke 2005
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 3 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #include "includes.h"
21 #include "system/filesys.h"
22 #include "smbd/smbd.h"
23
24 #include <fcntl.h>
25 #include "vfs_gpfs.h"
26
27 static int (*gpfs_set_share_fn)(int fd, unsigned int allow, unsigned int deny);
28 static int (*gpfs_set_lease_fn)(int fd, unsigned int type);
29 static int (*gpfs_getacl_fn)(char *pathname, int flags, void *acl);
30 static int (*gpfs_putacl_fn)(char *pathname, int flags, void *acl);
31 static int (*gpfs_get_realfilename_path_fn)(char *pathname, char *filenamep,
32                                             int *len);
33 static int (*gpfs_set_winattrs_path_fn)(char *pathname, int flags,
34                                         struct gpfs_winattr *attrs);
35 static int (*gpfs_get_winattrs_path_fn)(char *pathname,
36                                         struct gpfs_winattr *attrs);
37 static int (*gpfs_get_winattrs_fn)(int fd, struct gpfs_winattr *attrs);
38 static int (*gpfs_prealloc_fn)(int fd, gpfs_off64_t start, gpfs_off64_t bytes);
39 static int (*gpfs_ftruncate_fn)(int fd, gpfs_off64_t length);
40 static int (*gpfs_lib_init_fn)(int flags);
41 static int (*gpfs_set_times_path_fn)(char *pathname, int flags,
42                                      gpfs_timestruc_t times[4]);
43 static int (*gpfs_quotactl_fn)(char *pathname, int cmd, int id, void *bufp);
44 static int (*gpfs_fcntl_fn)(int fd, void *argp);
45 static int (*gpfs_getfilesetid_fn)(char *pathname, char *name, int *idp);
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_fcntl_fn                 = dlsym(l, "gpfs_fcntl");
74         gpfs_getfilesetid_fn          = dlsym(l, "gpfs_getfilesetid");
75
76         return 0;
77 }
78
79 int gpfswrap_set_share(int fd, unsigned int allow, unsigned int deny)
80 {
81         if (gpfs_set_share_fn == NULL) {
82                 errno = ENOSYS;
83                 return -1;
84         }
85
86         return gpfs_set_share_fn(fd, allow, deny);
87 }
88
89 int gpfswrap_set_lease(int fd, unsigned int type)
90 {
91         if (gpfs_set_lease_fn == NULL) {
92                 errno = ENOSYS;
93                 return -1;
94         }
95
96         return gpfs_set_lease_fn(fd, type);
97 }
98
99 int gpfswrap_getacl(char *pathname, int flags, void *acl)
100 {
101         if (gpfs_getacl_fn == NULL) {
102                 errno = ENOSYS;
103                 return -1;
104         }
105
106         return gpfs_getacl_fn(pathname, flags, acl);
107 }
108
109 int gpfswrap_putacl(char *pathname, int flags, void *acl)
110 {
111         if (gpfs_putacl_fn == NULL) {
112                 errno = ENOSYS;
113                 return -1;
114         }
115
116         return gpfs_putacl_fn(pathname, flags, acl);
117 }
118
119 int gpfswrap_get_realfilename_path(char *pathname, char *filenamep, int *len)
120 {
121         if (gpfs_get_realfilename_path_fn == NULL) {
122                 errno = ENOSYS;
123                 return -1;
124         }
125
126         return gpfs_get_realfilename_path_fn(pathname, filenamep, len);
127 }
128
129 int gpfswrap_set_winattrs_path(char *pathname, int flags,
130                                struct gpfs_winattr *attrs)
131 {
132         if (gpfs_set_winattrs_path_fn == NULL) {
133                 errno = ENOSYS;
134                 return -1;
135         }
136
137         return gpfs_set_winattrs_path_fn(pathname, flags, attrs);
138 }
139
140 int gpfswrap_get_winattrs_path(char *pathname, struct gpfs_winattr *attrs)
141 {
142         if (gpfs_get_winattrs_path_fn == NULL) {
143                 errno = ENOSYS;
144                 return -1;
145         }
146
147         return gpfs_get_winattrs_path_fn(pathname, attrs);
148 }
149
150 int gpfswrap_get_winattrs(int fd, struct gpfs_winattr *attrs)
151 {
152         if (gpfs_get_winattrs_fn == NULL) {
153                 errno = ENOSYS;
154                 return -1;
155         }
156
157         return gpfs_get_winattrs_fn(fd, attrs);
158 }
159
160 int gpfswrap_prealloc(int fd, gpfs_off64_t start, gpfs_off64_t bytes)
161 {
162         if (gpfs_prealloc_fn == NULL) {
163                 errno = ENOSYS;
164                 return -1;
165         }
166
167         return gpfs_prealloc_fn(fd, start, bytes);
168 }
169
170 int gpfswrap_ftruncate(int fd, gpfs_off64_t length)
171 {
172         if (gpfs_ftruncate_fn == NULL) {
173                 errno = ENOSYS;
174                 return -1;
175         }
176
177         return gpfs_ftruncate_fn(fd, length);
178 }
179
180 int gpfswrap_lib_init(int flags)
181 {
182         if (gpfs_lib_init_fn == NULL) {
183                 errno = ENOSYS;
184                 return -1;
185         }
186
187         return gpfs_lib_init_fn(flags);
188 }
189
190 int gpfswrap_set_times_path(char *pathname, int flags,
191                             gpfs_timestruc_t times[4])
192 {
193         if (gpfs_set_times_path_fn == NULL) {
194                 errno = ENOSYS;
195                 return -1;
196         }
197
198         return gpfs_set_times_path_fn(pathname, flags, times);
199 }
200
201 int gpfswrap_quotactl(char *pathname, int cmd, int id, void *bufp)
202 {
203         if (gpfs_quotactl_fn == NULL) {
204                 errno = ENOSYS;
205                 return -1;
206         }
207
208         return gpfs_quotactl_fn(pathname, cmd, id, bufp);
209 }
210
211 int gpfswrap_fcntl(int fd, void *argp)
212 {
213         if (gpfs_fcntl_fn == NULL) {
214                 errno = ENOSYS;
215                 return -1;
216         }
217
218         return gpfs_fcntl_fn(fd, argp);
219 }
220
221 int gpfswrap_getfilesetid(char *pathname, char *name, int *idp)
222 {
223         if (gpfs_getfilesetid_fn == NULL) {
224                 errno = ENOSYS;
225                 return -1;
226         }
227
228         return gpfs_getfilesetid_fn(pathname, name, idp);
229 }