3 Unix SMB/Netbios implementation.
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.
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
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)
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)
50 if ((path == NULL) || (bsize == NULL) || (dfree == NULL) ||
53 smb_panic("NULL pointer passed to vfswrap_disk_free() function\n");
57 result = sys_disk_free(path, small_query, bsize, dfree, dsize);
61 /* Directory operations */
63 DIR *vfswrap_opendir(connection_struct *conn, char *fname)
67 START_PROFILE(syscall_opendir);
71 smb_panic("NULL pointer passed to vfswrap_opendir()\n");
75 result = opendir(fname);
76 END_PROFILE(syscall_opendir);
80 struct dirent *vfswrap_readdir(connection_struct *conn, DIR *dirp)
82 struct dirent *result;
84 START_PROFILE(syscall_readdir);
88 smb_panic("NULL pointer passed to vfswrap_readdir()\n");
92 result = readdir(dirp);
93 END_PROFILE(syscall_readdir);
97 int vfswrap_mkdir(connection_struct *conn, char *path, mode_t mode)
101 START_PROFILE(syscall_mkdir);
103 #ifdef VFS_CHECK_NULL
105 smb_panic("NULL pointer passed to vfswrap_mkdir()\n");
109 result = mkdir(path, mode);
110 END_PROFILE(syscall_mkdir);
114 int vfswrap_rmdir(connection_struct *conn, char *path)
118 START_PROFILE(syscall_rmdir);
120 #ifdef VFS_CHECK_NULL
122 smb_panic("NULL pointer passed to vfswrap_rmdir()\n");
126 result = rmdir(path);
127 END_PROFILE(syscall_rmdir);
131 int vfswrap_closedir(connection_struct *conn, DIR *dirp)
135 START_PROFILE(syscall_closedir);
137 #ifdef VFS_CHECK_NULL
139 smb_panic("NULL pointer passed to vfswrap_closedir()\n");
143 result = closedir(dirp);
144 END_PROFILE(syscall_closedir);
148 /* File operations */
150 int vfswrap_open(connection_struct *conn, char *fname, int flags, mode_t mode)
154 START_PROFILE(syscall_open);
156 #ifdef VFS_CHECK_NULL
158 smb_panic("NULL pointer passed to vfswrap_open()\n");
162 result = sys_open(fname, flags, mode);
163 END_PROFILE(syscall_open);
167 int vfswrap_close(files_struct *fsp, int fd)
171 START_PROFILE(syscall_close);
174 END_PROFILE(syscall_close);
178 ssize_t vfswrap_read(files_struct *fsp, int fd, char *data, size_t n)
182 START_PROFILE_BYTES(syscall_read, n);
184 #ifdef VFS_CHECK_NULL
186 smb_panic("NULL pointer passed to vfswrap_read()\n");
190 result = read(fd, data, n);
191 END_PROFILE(syscall_read);
195 ssize_t vfswrap_write(files_struct *fsp, int fd, char *data, size_t n)
199 START_PROFILE_BYTES(syscall_write, n);
201 #ifdef VFS_CHECK_NULL
203 smb_panic("NULL pointer passed to vfswrap_write()\n");
207 result = write(fd, data, n);
208 END_PROFILE(syscall_write);
212 SMB_OFF_T vfswrap_lseek(files_struct *fsp, int filedes, SMB_OFF_T offset, int whence)
216 START_PROFILE(syscall_lseek);
218 result = sys_lseek(filedes, offset, whence);
219 END_PROFILE(syscall_lseek);
223 int vfswrap_rename(connection_struct *conn, char *old, char *new)
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");
235 result = rename(old, new);
236 END_PROFILE(syscall_rename);
240 int vfswrap_fsync(files_struct *fsp, int fd)
245 START_PROFILE(syscall_fsync);
248 END_PROFILE(syscall_fsync);
255 int vfswrap_stat(connection_struct *conn, char *fname, SMB_STRUCT_STAT *sbuf)
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");
267 result = sys_stat(fname, sbuf);
268 END_PROFILE(syscall_stat);
272 int vfswrap_fstat(files_struct *fsp, int fd, SMB_STRUCT_STAT *sbuf)
276 START_PROFILE(syscall_fstat);
278 #ifdef VFS_CHECK_NULL
280 smb_panic("NULL pointer passed to vfswrap_fstat()\n");
284 result = sys_fstat(fd, sbuf);
285 END_PROFILE(syscall_fstat);
289 int vfswrap_lstat(connection_struct *conn, char *path, SMB_STRUCT_STAT *sbuf)
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");
301 result = sys_lstat(path, sbuf);
302 END_PROFILE(syscall_lstat);
306 int vfswrap_unlink(connection_struct *conn, char *path)
310 START_PROFILE(syscall_unlink);
312 #ifdef VFS_CHECK_NULL
314 smb_panic("NULL pointer passed to vfswrap_unlink()\n");
318 result = unlink(path);
319 END_PROFILE(syscall_unlink);
323 int vfswrap_chmod(connection_struct *conn, char *path, mode_t mode)
327 START_PROFILE(syscall_chmod);
329 #ifdef VFS_CHECK_NULL
331 smb_panic("NULL pointer passed to vfswrap_chmod()\n");
335 result = chmod(path, mode);
336 END_PROFILE(syscall_chmod);
340 int vfswrap_chown(connection_struct *conn, char *path, uid_t uid, gid_t gid)
344 START_PROFILE(syscall_chown);
346 #ifdef VFS_CHECK_NULL
348 smb_panic("NULL pointer passed to vfswrap_chown()\n");
352 result = sys_chown(path, uid, gid);
353 END_PROFILE(syscall_chown);
357 int vfswrap_chdir(connection_struct *conn, char *path)
361 START_PROFILE(syscall_chdir);
363 #ifdef VFS_CHECK_NULL
365 smb_panic("NULL pointer passed to vfswrap_chdir()\n");
369 result = chdir(path);
370 END_PROFILE(syscall_chdir);
374 char *vfswrap_getwd(connection_struct *conn, char *path)
378 START_PROFILE(syscall_getwd);
380 #ifdef VFS_CHECK_NULL
382 smb_panic("NULL pointer passed to vfswrap_getwd()\n");
386 result = sys_getwd(path);
387 END_PROFILE(syscall_getwd);
391 int vfswrap_utime(connection_struct *conn, char *path, struct utimbuf *times)
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");
403 result = utime(path, times);
404 END_PROFILE(syscall_utime);
408 int vfswrap_ftruncate(files_struct *fsp, int fd, SMB_OFF_T len)
411 START_PROFILE(syscall_ftruncate);
413 #ifdef HAVE_FTRUNCATE_EXTEND
414 result = sys_ftruncate(fd, len);
415 END_PROFILE(syscall_ftruncate);
419 /* According to W. R. Stevens advanced UNIX prog. Pure 4.3 BSD cannot
420 extend a file with ftruncate. Provide alternate implementation
423 struct vfs_ops *vfs_ops = fsp->conn->vfs_ops;
428 currpos = vfs_ops->lseek(fsp, (SMB_OFF_T)0, SEEK_CUR);
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
437 if(vfs_ops->fstat(fsp, &st)<0) {
442 if (S_ISFIFO(st.st_mode)) {
448 if(st.st_size == len) {
453 if(st.st_size > len) {
454 /* Yes this is *deliberately* sys_ftruncate ! JRA */
455 result = sys_ftruncate(fd, len);
459 if(vfs_ops->lseek(fsp, len-1, SEEK_SET) != len -1) {
463 if(vfs_ops->write(fsp, &c, 1)!=1) {
467 /* Seek to where we were */
468 if(vfs_ops->lseek(fsp, currpos, SEEK_SET) != currpos) {
475 END_PROFILE(syscall_ftruncate);
479 BOOL vfswrap_lock(files_struct *fsp, int fd, int op, SMB_OFF_T offset, SMB_OFF_T count, int type)
483 START_PROFILE(syscall_fcntl_lock);
485 result = fcntl_lock(fd, op, offset, count,type);
486 END_PROFILE(syscall_fcntl_lock);
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);