2 Unix SMB/Netbios implementation.
5 Copyright (C) Andrew Tridgell 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.
23 /* we don't want prototypes for this code */
28 int open(const char *name
, int flags
, mode_t mode
)
30 if (smbw_path(name
)) {
31 return smbw_open(name
, flags
, mode
);
34 return real_open(name
, flags
, mode
);
38 int _open(const char *name
, int flags
, mode_t mode
)
40 return open(name
, flags
, mode
);
43 int __open(const char *name
, int flags
, mode_t mode
)
45 return open(name
, flags
, mode
);
51 int open64(const char *name
, int flags
, mode_t mode
)
53 if (smbw_path(name
)) {
54 return smbw_open(name
, flags
, mode
);
57 return real_open64(name
, flags
, mode
);
61 #ifndef NO_OPEN64_ALIAS
63 int _open64(const char *name
, int flags
, mode_t mode
)
65 return open64(name
, flags
, mode
);
68 int __open64(const char *name
, int flags
, mode_t mode
)
70 return open64(name
, flags
, mode
);
76 ssize_t
pread(int fd
, void *buf
, size_t size
, off_t ofs
)
79 return smbw_pread(fd
, buf
, size
, ofs
);
82 return real_pread(fd
, buf
, size
, ofs
);
87 ssize_t
pread64(int fd
, void *buf
, size_t size
, off64_t ofs
)
90 return smbw_pread(fd
, buf
, size
, ofs
);
93 return real_pread64(fd
, buf
, size
, ofs
);
98 ssize_t
pwrite(int fd
, void *buf
, size_t size
, off_t ofs
)
101 return smbw_pwrite(fd
, buf
, size
, ofs
);
104 return real_pwrite(fd
, buf
, size
, ofs
);
109 ssize_t
pwrite64(int fd
, void *buf
, size_t size
, off64_t ofs
)
112 return smbw_pwrite(fd
, buf
, size
, ofs
);
115 return real_pwrite64(fd
, buf
, size
, ofs
);
120 int chdir(const char *name
)
122 return smbw_chdir(name
);
126 int __chdir(const char *name
)
131 int _chdir(const char *name
)
141 return smbw_close(fd
);
144 return real_close(fd
);
163 return smbw_fchdir(fd
);
166 return real_fchdir(fd
);
182 int fcntl(int fd
, int cmd
, long arg
)
185 return smbw_fcntl(fd
, cmd
, arg
);
188 return real_fcntl(fd
, cmd
, arg
);
193 int __fcntl(int fd
, int cmd
, long arg
)
195 return fcntl(fd
, cmd
, arg
);
198 int _fcntl(int fd
, int cmd
, long arg
)
200 return fcntl(fd
, cmd
, arg
);
207 int getdents(int fd
, struct dirent
*dirp
, unsigned int count
)
210 return smbw_getdents(fd
, dirp
, count
);
213 return real_getdents(fd
, dirp
, count
);
217 #ifdef HAVE___GETDENTS
218 int __getdents(int fd
, struct dirent
*dirp
, unsigned int count
)
220 return getdents(fd
, dirp
, count
);
223 int _getdents(int fd
, struct dirent
*dirp
, unsigned int count
)
225 return getdents(fd
, dirp
, count
);
230 off_t
lseek(int fd
, off_t offset
, int whence
)
233 return smbw_lseek(fd
, offset
, whence
);
236 return real_lseek(fd
, offset
, whence
);
240 off_t
__lseek(int fd
, off_t offset
, int whence
)
242 return lseek(fd
, offset
, whence
);
245 off_t
_lseek(int fd
, off_t offset
, int whence
)
247 return lseek(fd
, offset
, whence
);
252 ssize_t
read(int fd
, void *buf
, size_t count
)
255 return smbw_read(fd
, buf
, count
);
258 return real_read(fd
, buf
, count
);
262 ssize_t
__read(int fd
, void *buf
, size_t count
)
264 return read(fd
, buf
, count
);
267 ssize_t
_read(int fd
, void *buf
, size_t count
)
269 return read(fd
, buf
, count
);
274 ssize_t
write(int fd
, void *buf
, size_t count
)
277 return smbw_write(fd
, buf
, count
);
280 return real_write(fd
, buf
, count
);
284 ssize_t
__write(int fd
, void *buf
, size_t count
)
286 return write(fd
, buf
, count
);
289 ssize_t
_write(int fd
, void *buf
, size_t count
)
291 return write(fd
, buf
, count
);
297 int access(const char *name
, int mode
)
299 if (smbw_path(name
)) {
300 return smbw_access(name
, mode
);
303 return real_access(name
, mode
);
308 int chmod(const char *name
,mode_t mode
)
310 if (smbw_path(name
)) {
311 return smbw_chmod(name
, mode
);
314 return real_chmod(name
, mode
);
319 int chown(const char *name
,uid_t owner
, gid_t group
)
321 if (smbw_path(name
)) {
322 return smbw_chown(name
, owner
, group
);
325 return real_chown(name
, owner
, group
);
329 int __fxstat(int vers
, int fd
, struct stat
*st
)
331 struct kernel_stat kbuf
;
335 return smbw_fstat(fd
, st
);
339 case _STAT_VER_LINUX_OLD
:
340 /* Nothing to do. The struct is in the form the kernel expects
342 return real_fstat(fd
, (struct kernel_stat
*)st
);
345 case _STAT_VER_LINUX
:
346 /* Do the system call. */
347 ret
= real_fstat(fd
, &kbuf
);
349 st
->st_dev
= kbuf
.st_dev
;
353 st
->st_ino
= kbuf
.st_ino
;
354 st
->st_mode
= kbuf
.st_mode
;
355 st
->st_nlink
= kbuf
.st_nlink
;
356 st
->st_uid
= kbuf
.st_uid
;
357 st
->st_gid
= kbuf
.st_gid
;
358 st
->st_rdev
= kbuf
.st_rdev
;
362 st
->st_size
= kbuf
.st_size
;
363 st
->st_blksize
= kbuf
.st_blksize
;
364 st
->st_blocks
= kbuf
.st_blocks
;
365 st
->st_atime
= kbuf
.st_atime
;
366 #ifdef _HAVE___UNUSED1
369 st
->st_mtime
= kbuf
.st_mtime
;
370 #ifdef _HAVE___UNUSED2
373 st
->st_ctime
= kbuf
.st_ctime
;
374 #ifdef _HAVE___UNUSED3
377 #ifdef _HAVE___UNUSED4
380 #ifdef _HAVE___UNUSED5
393 char *getcwd(char *buf
, size_t size
)
395 return smbw_getcwd(buf
, size
);
400 int __lxstat(int vers
, const char *name
, struct stat
*st
)
402 struct kernel_stat kbuf
;
405 if (smbw_path(name
)) {
406 return smbw_stat(name
, st
);
410 case _STAT_VER_LINUX_OLD
:
411 /* Nothing to do. The struct is in the form the kernel expects
413 return real_lstat(name
, (struct kernel_stat
*)st
);
416 case _STAT_VER_LINUX
:
417 /* Do the system call. */
418 ret
= real_lstat(name
, &kbuf
);
420 st
->st_dev
= kbuf
.st_dev
;
424 st
->st_ino
= kbuf
.st_ino
;
425 st
->st_mode
= kbuf
.st_mode
;
426 st
->st_nlink
= kbuf
.st_nlink
;
427 st
->st_uid
= kbuf
.st_uid
;
428 st
->st_gid
= kbuf
.st_gid
;
429 st
->st_rdev
= kbuf
.st_rdev
;
433 st
->st_size
= kbuf
.st_size
;
434 st
->st_blksize
= kbuf
.st_blksize
;
435 st
->st_blocks
= kbuf
.st_blocks
;
436 st
->st_atime
= kbuf
.st_atime
;
437 #ifdef _HAVE___UNUSED1
440 st
->st_mtime
= kbuf
.st_mtime
;
441 #ifdef _HAVE___UNUSED2
444 st
->st_ctime
= kbuf
.st_ctime
;
445 #ifdef _HAVE___UNUSED3
448 #ifdef _HAVE___UNUSED4
451 #ifdef _HAVE___UNUSED5
464 int mkdir(const char *name
, mode_t mode
)
466 if (smbw_path(name
)) {
467 return smbw_mkdir(name
, mode
);
470 return real_mkdir(name
, mode
);
475 int __xstat(int vers
, const char *name
, struct stat
*st
)
477 struct kernel_stat kbuf
;
480 if (smbw_path(name
)) {
481 return smbw_stat(name
, st
);
485 case _STAT_VER_LINUX_OLD
:
486 /* Nothing to do. The struct is in the form the kernel expects
488 return real_stat(name
, (struct kernel_stat
*)st
);
491 case _STAT_VER_LINUX
:
492 /* Do the system call. */
493 ret
= real_stat(name
, &kbuf
);
495 st
->st_dev
= kbuf
.st_dev
;
499 st
->st_ino
= kbuf
.st_ino
;
500 st
->st_mode
= kbuf
.st_mode
;
501 st
->st_nlink
= kbuf
.st_nlink
;
502 st
->st_uid
= kbuf
.st_uid
;
503 st
->st_gid
= kbuf
.st_gid
;
504 st
->st_rdev
= kbuf
.st_rdev
;
508 st
->st_size
= kbuf
.st_size
;
509 st
->st_blksize
= kbuf
.st_blksize
;
510 st
->st_blocks
= kbuf
.st_blocks
;
511 st
->st_atime
= kbuf
.st_atime
;
512 #ifdef _HAVE___UNUSED1
515 st
->st_mtime
= kbuf
.st_mtime
;
516 #ifdef _HAVE___UNUSED2
519 st
->st_ctime
= kbuf
.st_ctime
;
520 #ifdef _HAVE___UNUSED3
523 #ifdef _HAVE___UNUSED4
526 #ifdef _HAVE___UNUSED5
538 int stat(const char *name
, struct stat
*st
)
541 return __xstat(_STAT_VER
, name
, st
);
543 if (smbw_path(name
)) {
544 return smbw_stat(name
, st
);
546 return real_stat(name
, st
);
550 int lstat(const char *name
, struct stat
*st
)
553 return __lxstat(_STAT_VER
, name
, st
);
555 if (smbw_path(name
)) {
556 return smbw_stat(name
, st
);
558 return real_lstat(name
, st
);
562 int fstat(int fd
, struct stat
*st
)
565 return __fxstat(_STAT_VER
, fd
, st
);
568 return smbw_fstat(fd
, st
);
570 return real_fstat(fd
, st
);
575 int unlink(const char *name
)
577 if (smbw_path(name
)) {
578 return smbw_unlink(name
);
581 return real_unlink(name
);
586 int utime(const char *name
,void *tvp
)
588 if (smbw_path(name
)) {
589 return smbw_utime(name
, tvp
);
592 return real_utime(name
, tvp
);
597 int utimes(const char *name
,const struct timeval tvp
[2])
599 if (smbw_path(name
)) {
600 return smbw_utimes(name
, tvp
);
603 return real_utimes(name
, tvp
);
607 int readlink(char *path
, char *buf
, size_t bufsize
)
609 if (smbw_path(path
)) {
610 return smbw_readlink(path
, buf
, bufsize
);
613 return real_readlink(path
, buf
, bufsize
);
617 int rename(const char *oldname
,const char *newname
)
620 p1
= smbw_path(oldname
);
621 p2
= smbw_path(newname
);
623 /* can't cross filesystem boundaries */
628 return smbw_rename(oldname
, newname
);
631 return real_rename(oldname
, newname
);
634 int rmdir(const char *name
)
636 if (smbw_path(name
)) {
637 return smbw_rmdir(name
);
640 return real_rmdir(name
);
644 int symlink(const char *topath
,const char *frompath
)
647 p1
= smbw_path(topath
);
648 p2
= smbw_path(frompath
);
650 /* can't handle symlinks */
655 return real_symlink(topath
, frompath
);
667 int dup2(int oldfd
, int newfd
)
669 if (smbw_fd(newfd
)) {
673 if (smbw_fd(oldfd
)) {
674 return smbw_dup2(oldfd
, newfd
);
677 return real_dup2(oldfd
, newfd
);
681 DIR *opendir(const char *name
)
683 if (smbw_path(name
)) {
684 return smbw_opendir(name
);
687 return real_opendir(name
);
692 struct dirent
*readdir(DIR *dir
)
694 if (smbw_dirp(dir
)) {
695 return smbw_readdir(dir
);
698 return real_readdir(dir
);
703 int closedir(DIR *dir
)
705 if (smbw_dirp(dir
)) {
706 return smbw_closedir(dir
);
709 return real_closedir(dir
);
714 off_t
telldir(DIR *dir
)
716 if (smbw_dirp(dir
)) {
717 return smbw_telldir(dir
);
720 return real_telldir(dir
);
725 #if SEEKDIR_RETURNS_VOID
730 seekdir(DIR *dir
, off_t offset
)
732 if (smbw_dirp(dir
)) {
733 smbw_seekdir(dir
, offset
);
737 real_seekdir(dir
, offset
);
739 #ifndef SEEKDIR_RETURNS_VOID
746 #ifndef NO_ACL_WRAPPER
747 int acl(const char *pathp
, int cmd
, int nentries
, aclent_t
*aclbufp
)
749 if (smbw_path(pathp
)) {
760 real_acl(pathp
, cmd
, nentries
, aclbufp
);
764 #ifndef NO_FACL_WRAPPER
765 int facl(int fd
, int cmd
, int nentries
, aclent_t
*aclbufp
)
778 real_facl(fd
, cmd
, nentries
, aclbufp
);
782 int creat(const char *path
, mode_t mode
)
784 return open(path
, O_WRONLY
|O_CREAT
|O_TRUNC
, mode
);
788 int creat64(const char *path
, mode_t mode
)
790 return open64(path
, O_WRONLY
|O_CREAT
|O_TRUNC
, mode
);
795 static void stat64_convert(struct stat
*st
, struct stat64
*st64
)
797 st64
->st_size
= st
->st_size
;
798 st64
->st_mode
= st
->st_mode
;
799 st64
->st_ino
= st
->st_ino
;
800 st64
->st_dev
= st
->st_dev
;
801 st64
->st_rdev
= st
->st_rdev
;
802 st64
->st_nlink
= st
->st_nlink
;
803 st64
->st_uid
= st
->st_uid
;
804 st64
->st_gid
= st
->st_gid
;
805 st64
->st_atime
= st
->st_atime
;
806 st64
->st_mtime
= st
->st_mtime
;
807 st64
->st_ctime
= st
->st_ctime
;
808 st64
->st_blksize
= st
->st_blksize
;
809 st64
->st_blocks
= st
->st_blocks
;
812 int stat64(const char *name
, struct stat64
*st64
)
814 if (smbw_path(name
)) {
816 int ret
= stat(name
, &st
);
817 stat64_convert(&st
, st64
);
820 return real_stat64(name
, st64
);
823 int fstat64(int fd
, struct stat64
*st64
)
827 int ret
= fstat(fd
, &st
);
828 stat64_convert(&st
, st64
);
831 return real_fstat64(fd
, st64
);
834 int lstat64(const char *name
, struct stat64
*st64
)
836 if (smbw_path(name
)) {
838 int ret
= lstat(name
, &st
);
839 stat64_convert(&st
, st64
);
842 return real_lstat64(name
, st64
);
847 offset_t
llseek(int fd
, offset_t ofs
, int whence
)
850 return lseek(fd
, ofs
, whence
);
852 return real_llseek(fd
, ofs
, whence
);
856 #ifdef HAVE_READDIR64
857 static void dirent64_convert(struct dirent
*d
, struct dirent64
*d64
)
859 d64
->d_ino
= d
->d_ino
;
860 d64
->d_off
= d
->d_off
;
861 d64
->d_reclen
= d
->d_reclen
;
862 strcpy(d64
->d_name
, d
->d_name
);
865 struct dirent64
*readdir64(DIR *dir
)
867 if (smbw_dirp(dir
)) {
875 dirent64_convert(d
, &dbuf
.d64
);
878 return real_readdir64(dir
);