2 Unix SMB/Netbios implementation.
4 Wrap disk only vfs functions to sidestep dodgy compilers.
5 Copyright (C) Tim Potter 1998
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.
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.
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.
24 /* Check for NULL pointer parameters in vfswrap_* functions */
26 #define VFS_CHECK_NULL
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
32 int vfswrap_dummy_connect(connection_struct *conn, char *service, char *user)
34 return 0; /* Return >= 0 for success */
37 void vfswrap_dummy_disconnect(connection_struct *conn)
43 SMB_BIG_UINT vfswrap_disk_free(connection_struct *conn, char *path, BOOL small_query, SMB_BIG_UINT *bsize,
44 SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
49 if ((path == NULL) || (bsize == NULL) || (dfree == NULL) ||
52 smb_panic("NULL pointer passed to vfswrap_disk_free() function\n");
56 result = sys_disk_free(path, small_query, bsize, dfree, dsize);
60 /* Directory operations */
62 DIR *vfswrap_opendir(connection_struct *conn, char *fname)
66 START_PROFILE(syscall_opendir);
70 smb_panic("NULL pointer passed to vfswrap_opendir()\n");
74 result = opendir(fname);
75 END_PROFILE(syscall_opendir);
79 struct dirent *vfswrap_readdir(connection_struct *conn, DIR *dirp)
81 struct dirent *result;
83 START_PROFILE(syscall_readdir);
87 smb_panic("NULL pointer passed to vfswrap_readdir()\n");
91 result = readdir(dirp);
92 END_PROFILE(syscall_readdir);
96 int vfswrap_mkdir(connection_struct *conn, char *path, mode_t mode)
100 START_PROFILE(syscall_mkdir);
102 #ifdef VFS_CHECK_NULL
104 smb_panic("NULL pointer passed to vfswrap_mkdir()\n");
108 result = mkdir(path, mode);
109 END_PROFILE(syscall_mkdir);
113 int vfswrap_rmdir(connection_struct *conn, char *path)
117 START_PROFILE(syscall_rmdir);
119 #ifdef VFS_CHECK_NULL
121 smb_panic("NULL pointer passed to vfswrap_rmdir()\n");
125 result = rmdir(path);
126 END_PROFILE(syscall_rmdir);
130 int vfswrap_closedir(connection_struct *conn, DIR *dirp)
134 START_PROFILE(syscall_closedir);
136 #ifdef VFS_CHECK_NULL
138 smb_panic("NULL pointer passed to vfswrap_closedir()\n");
142 result = closedir(dirp);
143 END_PROFILE(syscall_closedir);
147 /* File operations */
149 int vfswrap_open(connection_struct *conn, char *fname, int flags, mode_t mode)
153 START_PROFILE(syscall_open);
155 #ifdef VFS_CHECK_NULL
157 smb_panic("NULL pointer passed to vfswrap_open()\n");
161 result = sys_open(fname, flags, mode);
162 END_PROFILE(syscall_open);
166 int vfswrap_close(files_struct *fsp, int fd)
170 START_PROFILE(syscall_close);
173 END_PROFILE(syscall_close);
177 ssize_t vfswrap_read(files_struct *fsp, int fd, char *data, size_t n)
181 START_PROFILE_BYTES(syscall_read, n);
183 #ifdef VFS_CHECK_NULL
185 smb_panic("NULL pointer passed to vfswrap_read()\n");
189 result = read(fd, data, n);
190 END_PROFILE(syscall_read);
194 ssize_t vfswrap_write(files_struct *fsp, int fd, char *data, size_t n)
198 START_PROFILE_BYTES(syscall_write, n);
200 #ifdef VFS_CHECK_NULL
202 smb_panic("NULL pointer passed to vfswrap_write()\n");
206 result = write(fd, data, n);
207 END_PROFILE(syscall_write);
211 SMB_OFF_T vfswrap_lseek(files_struct *fsp, int filedes, SMB_OFF_T offset, int whence)
215 START_PROFILE(syscall_lseek);
217 result = sys_lseek(filedes, offset, whence);
218 END_PROFILE(syscall_lseek);
222 int vfswrap_rename(connection_struct *conn, char *old, char *new)
226 START_PROFILE(syscall_rename);
228 #ifdef VFS_CHECK_NULL
229 if ((old == NULL) || (new == NULL)) {
230 smb_panic("NULL pointer passed to vfswrap_rename()\n");
234 result = rename(old, new);
235 END_PROFILE(syscall_rename);
239 int vfswrap_fsync(files_struct *fsp, int fd)
244 START_PROFILE(syscall_fsync);
247 END_PROFILE(syscall_fsync);
254 int vfswrap_stat(connection_struct *conn, char *fname, SMB_STRUCT_STAT *sbuf)
258 START_PROFILE(syscall_stat);
260 #ifdef VFS_CHECK_NULL
261 if ((fname == NULL) || (sbuf == NULL)) {
262 smb_panic("NULL pointer passed to vfswrap_stat()\n");
266 result = sys_stat(fname, sbuf);
267 END_PROFILE(syscall_stat);
271 int vfswrap_fstat(files_struct *fsp, int fd, SMB_STRUCT_STAT *sbuf)
275 START_PROFILE(syscall_fstat);
277 #ifdef VFS_CHECK_NULL
279 smb_panic("NULL pointer passed to vfswrap_fstat()\n");
283 result = sys_fstat(fd, sbuf);
284 END_PROFILE(syscall_fstat);
288 int vfswrap_lstat(connection_struct *conn, char *path, SMB_STRUCT_STAT *sbuf)
292 START_PROFILE(syscall_lstat);
294 #ifdef VFS_CHECK_NULL
295 if ((path == NULL) || (sbuf == NULL)) {
296 smb_panic("NULL pointer passed to vfswrap_lstat()\n");
300 result = sys_lstat(path, sbuf);
301 END_PROFILE(syscall_lstat);
305 int vfswrap_unlink(connection_struct *conn, char *path)
309 START_PROFILE(syscall_unlink);
311 #ifdef VFS_CHECK_NULL
313 smb_panic("NULL pointer passed to vfswrap_unlink()\n");
317 result = unlink(path);
318 END_PROFILE(syscall_unlink);
322 int vfswrap_chmod(connection_struct *conn, char *path, mode_t mode)
326 START_PROFILE(syscall_chmod);
328 #ifdef VFS_CHECK_NULL
330 smb_panic("NULL pointer passed to vfswrap_chmod()\n");
334 result = chmod(path, mode);
335 END_PROFILE(syscall_chmod);
339 int vfswrap_chown(connection_struct *conn, char *path, uid_t uid, gid_t gid)
343 START_PROFILE(syscall_chown);
345 #ifdef VFS_CHECK_NULL
347 smb_panic("NULL pointer passed to vfswrap_chown()\n");
351 result = sys_chown(path, uid, gid);
352 END_PROFILE(syscall_chown);
356 int vfswrap_chdir(connection_struct *conn, char *path)
360 START_PROFILE(syscall_chdir);
362 #ifdef VFS_CHECK_NULL
364 smb_panic("NULL pointer passed to vfswrap_chdir()\n");
368 result = chdir(path);
369 END_PROFILE(syscall_chdir);
373 char *vfswrap_getwd(connection_struct *conn, char *path)
377 START_PROFILE(syscall_getwd);
379 #ifdef VFS_CHECK_NULL
381 smb_panic("NULL pointer passed to vfswrap_getwd()\n");
385 result = sys_getwd(path);
386 END_PROFILE(syscall_getwd);
390 int vfswrap_utime(connection_struct *conn, char *path, struct utimbuf *times)
394 START_PROFILE(syscall_utime);
396 #ifdef VFS_CHECK_NULL
397 if ((path == NULL) || (times == NULL)) {
398 smb_panic("NULL pointer passed to vfswrap_utime()\n");
402 result = utime(path, times);
403 END_PROFILE(syscall_utime);
407 int vfswrap_ftruncate(files_struct *fsp, int fd, SMB_OFF_T len)
410 START_PROFILE(syscall_ftruncate);
412 #ifdef HAVE_FTRUNCATE_EXTEND
413 result = sys_ftruncate(fd, len);
414 END_PROFILE(syscall_ftruncate);
418 /* According to W. R. Stevens advanced UNIX prog. Pure 4.3 BSD cannot
419 extend a file with ftruncate. Provide alternate implementation
422 struct vfs_ops *vfs_ops = fsp->conn->vfs_ops;
427 currpos = vfs_ops->lseek(fsp, (SMB_OFF_T)0, SEEK_CUR);
432 /* Do an fstat to see if the file is longer than
433 the requested size (call ftruncate),
434 or shorter, in which case seek to len - 1 and write 1
436 if(vfs_ops->fstat(fsp, &st)<0) {
441 if (S_ISFIFO(st.st_mode)) {
447 if(st.st_size == len) {
452 if(st.st_size > len) {
453 /* Yes this is *deliberately* sys_ftruncate ! JRA */
454 result = sys_ftruncate(fd, len);
458 if(vfs_ops->lseek(fsp, len-1, SEEK_SET) != len -1) {
462 if(vfs_ops->write(fsp, &c, 1)!=1) {
466 /* Seek to where we were */
467 if(vfs_ops->lseek(fsp, currpos, SEEK_SET) != currpos) {
474 END_PROFILE(syscall_ftruncate);
478 BOOL vfswrap_lock(files_struct *fsp, int fd, int op, SMB_OFF_T offset, SMB_OFF_T count, int type)
482 START_PROFILE(syscall_fcntl_lock);
484 result = fcntl_lock(fd, op, offset, count,type);
485 END_PROFILE(syscall_fcntl_lock);
489 size_t vfswrap_fget_nt_acl(files_struct *fsp, int fd, SEC_DESC **ppdesc)
491 return get_nt_acl(fsp, ppdesc);
494 size_t vfswrap_get_nt_acl(files_struct *fsp, char *name, SEC_DESC **ppdesc)
496 return get_nt_acl(fsp, ppdesc);
499 BOOL vfswrap_fset_nt_acl(files_struct *fsp, int fd, uint32 security_info_sent, SEC_DESC *psd)
501 return set_nt_acl(fsp, security_info_sent, psd);
504 BOOL vfswrap_set_nt_acl(files_struct *fsp, char *name, uint32 security_info_sent, SEC_DESC *psd)
506 return set_nt_acl(fsp, security_info_sent, psd);