Restructuring of the code to remove dos_ChDir/dos_GetWd and re-vector them
[jra/samba/.git] / source3 / smbd / vfs-wrap.c
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 1.9.
4 s   Wrap disk only vfs functions to sidestep dodgy compilers.
5    Copyright (C) Tim Potter 1998
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 2 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, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23
24 /* Check for NULL pointer parameters in vfswrap_* functions */
25
26 #define VFS_CHECK_NULL
27
28 /* We don't want to have NULL function pointers lying around.  Someone
29    is sure to try and execute them.  These stubs are used to prevent
30    this possibility. */
31
32 int vfswrap_dummy_connect(struct vfs_connection_struct *conn, char *service,
33                           char *user)
34 {
35     return 0;    /* Return >= 0 for success */
36 }
37
38 void vfswrap_dummy_disconnect(void)
39 {
40 }
41
42 /* Disk operations */
43
44 SMB_BIG_UINT vfswrap_disk_free(char *path, BOOL small_query, SMB_BIG_UINT *bsize, 
45                                SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
46 {
47     SMB_BIG_UINT result;
48
49 #ifdef VFS_CHECK_NULL
50     if ((path == NULL) || (bsize == NULL) || (dfree == NULL) ||
51         (dsize == NULL)) {
52         
53         smb_panic("NULL pointer passed to vfswrap_disk_free() function\n");
54     }
55 #endif
56
57     result = sys_disk_free(path, small_query, bsize, dfree, dsize);
58     return result;
59 }
60     
61 /* Directory operations */
62
63 DIR *vfswrap_opendir(char *fname)
64 {
65     DIR *result;
66
67 #ifdef VFS_CHECK_NULL
68     if (fname == NULL) {
69         smb_panic("NULL pointer passed to vfswrap_opendir()\n");
70     }
71 #endif
72
73     result = opendir(fname);
74     return result;
75 }
76
77 struct dirent *vfswrap_readdir(DIR *dirp)
78 {
79     struct dirent *result;
80
81 #ifdef VFS_CHECK_NULL
82     if (dirp == NULL) {
83         smb_panic("NULL pointer passed to vfswrap_readdir()\n");
84     }
85 #endif
86
87     result = readdir(dirp);
88     return result;
89 }
90
91 int vfswrap_mkdir(char *path, mode_t mode)
92 {
93     int result;
94
95 #ifdef VFS_CHECK_NULL
96     if (path == NULL) {
97         smb_panic("NULL pointer passed to vfswrap_mkdir()\n");
98     }
99 #endif
100
101     result = mkdir(path, mode);
102     return result;
103 }
104
105 int vfswrap_rmdir(char *path)
106 {
107     int result;
108
109 #ifdef VFS_CHECK_NULL
110     if (path == NULL) {
111         smb_panic("NULL pointer passed to vfswrap_rmdir()\n");
112     }
113 #endif
114
115     result = rmdir(path);
116     return result;
117 }
118
119 int vfswrap_closedir(DIR *dirp)
120 {
121     int result;
122
123 #ifdef VFS_CHECK_NULL
124     if (dirp == NULL) {
125         smb_panic("NULL pointer passed to vfswrap_closedir()\n");
126     }
127 #endif
128
129     result = closedir(dirp);
130     return result;
131 }
132
133 /* File operations */
134     
135 int vfswrap_open(char *fname, int flags, mode_t mode)
136 {
137     int result;
138
139 #ifdef VFS_CHECK_NULL
140     if (fname == NULL) {
141         smb_panic("NULL pointer passed to vfswrap_open()\n");
142     }
143 #endif
144
145     result = sys_open(fname, flags, mode);
146     return result;
147 }
148
149 int vfswrap_close(int fd)
150 {
151     int result;
152
153     result = close(fd);
154     return result;
155 }
156
157 ssize_t vfswrap_read(int fd, char *data, size_t n)
158 {
159     ssize_t result;
160
161 #ifdef VFS_CHECK_NULL
162     if (data == NULL) {
163         smb_panic("NULL pointer passed to vfswrap_read()\n");
164     }
165 #endif
166
167     result = read(fd, data, n);
168     return result;
169 }
170
171 ssize_t vfswrap_write(int fd, char *data, size_t n)
172 {
173     ssize_t result;
174
175 #ifdef VFS_CHECK_NULL
176     if (data == NULL) {
177         smb_panic("NULL pointer passed to vfswrap_write()\n");
178     }
179 #endif
180
181     result = write(fd, data, n);
182     return result;
183 }
184
185 SMB_OFF_T vfswrap_lseek(int filedes, SMB_OFF_T offset, int whence)
186 {
187     SMB_OFF_T result;
188
189     result = sys_lseek(filedes, offset, whence);
190     return result;
191 }
192
193 int vfswrap_rename(char *old, char *new)
194 {
195     int result;
196
197 #ifdef VFS_CHECK_NULL
198     if ((old == NULL) || (new == NULL)) {
199         smb_panic("NULL pointer passed to vfswrap_rename()\n");
200     }
201 #endif
202
203     result = rename(old, new);
204     return result;
205 }
206
207 int vfswrap_fsync(int fd)
208 {
209 #ifdef HAVE_FSYNC
210     return fsync(fd);
211 #else
212         return 0;
213 #endif
214 }
215
216 int vfswrap_stat(char *fname, SMB_STRUCT_STAT *sbuf)
217 {
218     int result;
219
220 #ifdef VFS_CHECK_NULL
221     if ((fname == NULL) || (sbuf == NULL)) {
222         smb_panic("NULL pointer passed to vfswrap_stat()\n");
223     }
224 #endif
225
226     result = sys_stat(fname, sbuf);
227     return result;
228 }
229
230 int vfswrap_fstat(int fd, SMB_STRUCT_STAT *sbuf)
231 {
232     int result;
233
234 #ifdef VFS_CHECK_NULL
235     if (sbuf == NULL) {
236         smb_panic("NULL pointer passed to vfswrap_fstat()\n");
237     }
238 #endif
239
240     result = sys_fstat(fd, sbuf);
241     return result;
242 }
243
244 int vfswrap_lstat(char *path, 
245                   SMB_STRUCT_STAT *sbuf)
246 {
247     int result;
248
249 #ifdef VFS_CHECK_NULL
250     if ((path == NULL) || (sbuf == NULL)) {
251         smb_panic("NULL pointer passed to vfswrap_lstat()\n");
252     }
253 #endif
254
255     result = sys_lstat(path, sbuf);
256     return result;
257 }
258
259 int vfswrap_unlink(char *path)
260 {
261     int result;
262
263 #ifdef VFS_CHECK_NULL
264     if (path == NULL) {
265         smb_panic("NULL pointer passed to vfswrap_unlink()\n");
266     }
267 #endif
268
269     result = unlink(path);
270     return result;
271 }
272
273 int vfswrap_chmod(char *path, mode_t mode)
274 {
275     int result;
276
277 #ifdef VFS_CHECK_NULL
278     if (path == NULL) {
279         smb_panic("NULL pointer passed to vfswrap_chmod()\n");
280     }
281 #endif
282
283     result = chmod(path, mode);
284     return result;
285 }
286
287 int vfswrap_chown(char *path, uid_t uid, gid_t gid)
288 {
289     int result;
290
291 #ifdef VFS_CHECK_NULL
292     if (path == NULL) {
293         smb_panic("NULL pointer passed to vfswrap_chown()\n");
294     }
295 #endif
296
297     result = sys_chown(path, uid, gid);
298     return result;
299 }
300
301 int vfswrap_chdir(char *path)
302 {
303 #ifdef VFS_CHECK_NULL
304     if (path == NULL) {
305         smb_panic("NULL pointer passed to vfswrap_chdir()\n");
306     }
307 #endif
308
309         return chdir(path);
310 }
311
312 char *vfswrap_getwd(char *path)
313 {
314 #ifdef VFS_CHECK_NULL
315     if (path == NULL) {
316         smb_panic("NULL pointer passed to vfswrap_getwd()\n");
317     }
318 #endif
319
320         return sys_getwd(path);
321 }
322
323 int vfswrap_utime(char *path, struct utimbuf *times)
324 {
325     int result;
326
327 #ifdef VFS_CHECK_NULL
328     if ((path == NULL) || (times == NULL)) {
329         smb_panic("NULL pointer passed to vfswrap_utime()\n");
330     }
331 #endif
332
333     result = utime(path, times);
334     return result;
335 }
336
337 int vfswrap_ftruncate(int fd, SMB_OFF_T offset)
338 {
339     int result;
340
341     result = sys_ftruncate(fd, offset);
342     return result;
343 }
344
345 BOOL vfswrap_lock(int fd, int op, SMB_OFF_T offset, SMB_OFF_T count, int type)
346 {
347         return fcntl_lock(fd, op, offset, count,type);
348 }
349
350 #if 0
351 size_t vfswrap_get_nt_acl(files_struct *fsp, SEC_DESC **ppdesc)
352 {
353 }
354
355 BOOL vfswrap_set_nt_acl(files_struct *fsp, uint32 security_info_sent, SEC_DESC *psd)
356 {
357 }
358 #endif