Fixed compiler warning.
[Samba.git] / source / smbd / vfs-wrap.c
bloba9d8a32430e5555f184fc22d42beedf67f875160
1 #define OLD_NTDOMAIN 1
2 /*
3 Unix SMB/Netbios implementation.
4 Version 1.9.
5 Wrap disk only vfs functions to sidestep dodgy compilers.
6 Copyright (C) Tim Potter 1998
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "includes.h"
25 /* Check for NULL pointer parameters in vfswrap_* functions */
27 #define VFS_CHECK_NULL
29 /* We don't want to have NULL function pointers lying around. Someone
30 is sure to try and execute them. These stubs are used to prevent
31 this possibility. */
33 int vfswrap_dummy_connect(connection_struct *conn, char *service, char *user)
35 return 0; /* Return >= 0 for success */
38 void vfswrap_dummy_disconnect(connection_struct *conn)
42 /* Disk operations */
44 SMB_BIG_UINT vfswrap_disk_free(connection_struct *conn, char *path, BOOL small_query, SMB_BIG_UINT *bsize,
45 SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
47 SMB_BIG_UINT result;
49 #ifdef VFS_CHECK_NULL
50 if ((path == NULL) || (bsize == NULL) || (dfree == NULL) ||
51 (dsize == NULL)) {
53 smb_panic("NULL pointer passed to vfswrap_disk_free() function\n");
55 #endif
57 result = sys_disk_free(path, small_query, bsize, dfree, dsize);
58 return result;
61 /* Directory operations */
63 DIR *vfswrap_opendir(connection_struct *conn, char *fname)
65 DIR *result;
67 START_PROFILE(syscall_opendir);
69 #ifdef VFS_CHECK_NULL
70 if (fname == NULL) {
71 smb_panic("NULL pointer passed to vfswrap_opendir()\n");
73 #endif
75 result = opendir(fname);
76 END_PROFILE(syscall_opendir);
77 return result;
80 struct dirent *vfswrap_readdir(connection_struct *conn, DIR *dirp)
82 struct dirent *result;
84 START_PROFILE(syscall_readdir);
86 #ifdef VFS_CHECK_NULL
87 if (dirp == NULL) {
88 smb_panic("NULL pointer passed to vfswrap_readdir()\n");
90 #endif
92 result = readdir(dirp);
93 END_PROFILE(syscall_readdir);
94 return result;
97 int vfswrap_mkdir(connection_struct *conn, char *path, mode_t mode)
99 int result;
101 START_PROFILE(syscall_mkdir);
103 #ifdef VFS_CHECK_NULL
104 if (path == NULL) {
105 smb_panic("NULL pointer passed to vfswrap_mkdir()\n");
107 #endif
109 result = mkdir(path, mode);
110 END_PROFILE(syscall_mkdir);
111 return result;
114 int vfswrap_rmdir(connection_struct *conn, char *path)
116 int result;
118 START_PROFILE(syscall_rmdir);
120 #ifdef VFS_CHECK_NULL
121 if (path == NULL) {
122 smb_panic("NULL pointer passed to vfswrap_rmdir()\n");
124 #endif
126 result = rmdir(path);
127 END_PROFILE(syscall_rmdir);
128 return result;
131 int vfswrap_closedir(connection_struct *conn, DIR *dirp)
133 int result;
135 START_PROFILE(syscall_closedir);
137 #ifdef VFS_CHECK_NULL
138 if (dirp == NULL) {
139 smb_panic("NULL pointer passed to vfswrap_closedir()\n");
141 #endif
143 result = closedir(dirp);
144 END_PROFILE(syscall_closedir);
145 return result;
148 /* File operations */
150 int vfswrap_open(connection_struct *conn, char *fname, int flags, mode_t mode)
152 int result;
154 START_PROFILE(syscall_open);
156 #ifdef VFS_CHECK_NULL
157 if (fname == NULL) {
158 smb_panic("NULL pointer passed to vfswrap_open()\n");
160 #endif
162 result = sys_open(fname, flags, mode);
163 END_PROFILE(syscall_open);
164 return result;
167 int vfswrap_close(files_struct *fsp, int fd)
169 int result;
171 START_PROFILE(syscall_close);
173 result = close(fd);
174 END_PROFILE(syscall_close);
175 return result;
178 ssize_t vfswrap_read(files_struct *fsp, int fd, char *data, size_t n)
180 ssize_t result;
182 START_PROFILE_BYTES(syscall_read, n);
184 #ifdef VFS_CHECK_NULL
185 if (data == NULL) {
186 smb_panic("NULL pointer passed to vfswrap_read()\n");
188 #endif
190 result = read(fd, data, n);
191 END_PROFILE(syscall_read);
192 return result;
195 ssize_t vfswrap_write(files_struct *fsp, int fd, char *data, size_t n)
197 ssize_t result;
199 START_PROFILE_BYTES(syscall_write, n);
201 #ifdef VFS_CHECK_NULL
202 if (data == NULL) {
203 smb_panic("NULL pointer passed to vfswrap_write()\n");
205 #endif
207 result = write(fd, data, n);
208 END_PROFILE(syscall_write);
209 return result;
212 SMB_OFF_T vfswrap_lseek(files_struct *fsp, int filedes, SMB_OFF_T offset, int whence)
214 SMB_OFF_T result;
216 START_PROFILE(syscall_lseek);
218 result = sys_lseek(filedes, offset, whence);
219 END_PROFILE(syscall_lseek);
220 return result;
223 int vfswrap_rename(connection_struct *conn, char *old, char *new)
225 int result;
227 START_PROFILE(syscall_rename);
229 #ifdef VFS_CHECK_NULL
230 if ((old == NULL) || (new == NULL)) {
231 smb_panic("NULL pointer passed to vfswrap_rename()\n");
233 #endif
235 result = rename(old, new);
236 END_PROFILE(syscall_rename);
237 return result;
240 int vfswrap_fsync(files_struct *fsp, int fd)
242 #ifdef HAVE_FSYNC
243 int result;
245 START_PROFILE(syscall_fsync);
247 result = fsync(fd);
248 END_PROFILE(syscall_fsync);
249 return result;
250 #else
251 return 0;
252 #endif
255 int vfswrap_stat(connection_struct *conn, char *fname, SMB_STRUCT_STAT *sbuf)
257 int result;
259 START_PROFILE(syscall_stat);
261 #ifdef VFS_CHECK_NULL
262 if ((fname == NULL) || (sbuf == NULL)) {
263 smb_panic("NULL pointer passed to vfswrap_stat()\n");
265 #endif
267 result = sys_stat(fname, sbuf);
268 END_PROFILE(syscall_stat);
269 return result;
272 int vfswrap_fstat(files_struct *fsp, int fd, SMB_STRUCT_STAT *sbuf)
274 int result;
276 START_PROFILE(syscall_fstat);
278 #ifdef VFS_CHECK_NULL
279 if (sbuf == NULL) {
280 smb_panic("NULL pointer passed to vfswrap_fstat()\n");
282 #endif
284 result = sys_fstat(fd, sbuf);
285 END_PROFILE(syscall_fstat);
286 return result;
289 int vfswrap_lstat(connection_struct *conn, char *path, SMB_STRUCT_STAT *sbuf)
291 int result;
293 START_PROFILE(syscall_lstat);
295 #ifdef VFS_CHECK_NULL
296 if ((path == NULL) || (sbuf == NULL)) {
297 smb_panic("NULL pointer passed to vfswrap_lstat()\n");
299 #endif
301 result = sys_lstat(path, sbuf);
302 END_PROFILE(syscall_lstat);
303 return result;
306 int vfswrap_unlink(connection_struct *conn, char *path)
308 int result;
310 START_PROFILE(syscall_unlink);
312 #ifdef VFS_CHECK_NULL
313 if (path == NULL) {
314 smb_panic("NULL pointer passed to vfswrap_unlink()\n");
316 #endif
318 result = unlink(path);
319 END_PROFILE(syscall_unlink);
320 return result;
323 int vfswrap_chmod(connection_struct *conn, char *path, mode_t mode)
325 int result;
327 START_PROFILE(syscall_chmod);
329 #ifdef VFS_CHECK_NULL
330 if (path == NULL) {
331 smb_panic("NULL pointer passed to vfswrap_chmod()\n");
333 #endif
335 result = chmod(path, mode);
336 END_PROFILE(syscall_chmod);
337 return result;
340 int vfswrap_chown(connection_struct *conn, char *path, uid_t uid, gid_t gid)
342 int result;
344 START_PROFILE(syscall_chown);
346 #ifdef VFS_CHECK_NULL
347 if (path == NULL) {
348 smb_panic("NULL pointer passed to vfswrap_chown()\n");
350 #endif
352 result = sys_chown(path, uid, gid);
353 END_PROFILE(syscall_chown);
354 return result;
357 int vfswrap_chdir(connection_struct *conn, char *path)
359 int result;
361 START_PROFILE(syscall_chdir);
363 #ifdef VFS_CHECK_NULL
364 if (path == NULL) {
365 smb_panic("NULL pointer passed to vfswrap_chdir()\n");
367 #endif
369 result = chdir(path);
370 END_PROFILE(syscall_chdir);
371 return result;
374 char *vfswrap_getwd(connection_struct *conn, char *path)
376 char *result;
378 START_PROFILE(syscall_getwd);
380 #ifdef VFS_CHECK_NULL
381 if (path == NULL) {
382 smb_panic("NULL pointer passed to vfswrap_getwd()\n");
384 #endif
386 result = sys_getwd(path);
387 END_PROFILE(syscall_getwd);
388 return result;
391 int vfswrap_utime(connection_struct *conn, char *path, struct utimbuf *times)
393 int result;
395 START_PROFILE(syscall_utime);
397 #ifdef VFS_CHECK_NULL
398 if ((path == NULL) || (times == NULL)) {
399 smb_panic("NULL pointer passed to vfswrap_utime()\n");
401 #endif
403 result = utime(path, times);
404 END_PROFILE(syscall_utime);
405 return result;
408 int vfswrap_ftruncate(files_struct *fsp, int fd, SMB_OFF_T len)
410 int result = -1;
411 START_PROFILE(syscall_ftruncate);
413 #ifdef HAVE_FTRUNCATE_EXTEND
414 result = sys_ftruncate(fd, len);
415 END_PROFILE(syscall_ftruncate);
416 return result;
417 #else
419 /* According to W. R. Stevens advanced UNIX prog. Pure 4.3 BSD cannot
420 extend a file with ftruncate. Provide alternate implementation
421 for this */
423 struct vfs_ops *vfs_ops = fsp->conn->vfs_ops;
424 SMB_STRUCT_STAT st;
425 char c = 0;
426 SMB_OFF_T currpos;
428 currpos = vfs_ops->lseek(fsp, (SMB_OFF_T)0, SEEK_CUR);
429 if(currpos == -1) {
430 goto done;
433 /* Do an fstat to see if the file is longer than
434 the requested size (call ftruncate),
435 or shorter, in which case seek to len - 1 and write 1
436 byte of zero */
437 if(vfs_ops->fstat(fsp, &st)<0) {
438 goto done;
441 #ifdef S_ISFIFO
442 if (S_ISFIFO(st.st_mode)) {
443 result = 0;
444 goto done;
446 #endif
448 if(st.st_size == len) {
449 result = 0;
450 goto done;
453 if(st.st_size > len) {
454 /* Yes this is *deliberately* sys_ftruncate ! JRA */
455 result = sys_ftruncate(fd, len);
456 goto done;
459 if(vfs_ops->lseek(fsp, len-1, SEEK_SET) != len -1) {
460 goto done;
463 if(vfs_ops->write(fsp, &c, 1)!=1) {
464 goto done;
467 /* Seek to where we were */
468 if(vfs_ops->lseek(fsp, currpos, SEEK_SET) != currpos) {
469 goto done;
471 done:
473 END_PROFILE(syscall_ftruncate);
474 return result;
475 #endif
479 BOOL vfswrap_lock(files_struct *fsp, int fd, int op, SMB_OFF_T offset, SMB_OFF_T count, int type)
481 BOOL result;
483 START_PROFILE(syscall_fcntl_lock);
485 result = fcntl_lock(fd, op, offset, count,type);
486 END_PROFILE(syscall_fcntl_lock);
487 return result;
490 size_t vfswrap_fget_nt_acl(files_struct *fsp, int fd, SEC_DESC **ppdesc)
492 return get_nt_acl(fsp, ppdesc);
495 size_t vfswrap_get_nt_acl(files_struct *fsp, char *name, SEC_DESC **ppdesc)
497 return get_nt_acl(fsp, ppdesc);
500 BOOL vfswrap_fset_nt_acl(files_struct *fsp, int fd, uint32 security_info_sent, SEC_DESC *psd)
502 return set_nt_acl(fsp, security_info_sent, psd);
505 BOOL vfswrap_set_nt_acl(files_struct *fsp, char *name, uint32 security_info_sent, SEC_DESC *psd)
507 return set_nt_acl(fsp, security_info_sent, psd);
509 #undef OLD_NTDOMAIN