drat.
authorAndrew Tridgell <tridge@samba.org>
Sat, 3 Oct 1998 16:34:57 +0000 (16:34 +0000)
committerAndrew Tridgell <tridge@samba.org>
Sat, 3 Oct 1998 16:34:57 +0000 (16:34 +0000)
on Linux 2.0 libc detects the lack of getdents in the kernel and used
opendir() etc. so we need to implement those ...

it would be needed for a port to others OSes anyway I suppose.
(This used to be commit e3fd861590dd27cc643c2d8d0cb5a5651c84d9ac)

source3/Makefile.in
source3/smbwrapper/closedir.c [new file with mode: 0644]
source3/smbwrapper/opendir.c [new file with mode: 0644]
source3/smbwrapper/readdir.c [new file with mode: 0644]
source3/smbwrapper/realcalls.h
source3/smbwrapper/seekdir.c [new file with mode: 0644]
source3/smbwrapper/smbw.c
source3/smbwrapper/telldir.c [new file with mode: 0644]

index eb7972fcf68872dfd8e82266a4ef94c634536c36..a8301303f1b00c92633f1e92c9caf9b1b314b5c5 100644 (file)
@@ -201,6 +201,8 @@ SMBWRAPPER_OBJ = smbwrapper/open.o smbwrapper/stat.o \
                smbwrapper/rename.o smbwrapper/utime.o smbwrapper/chown.o \
                smbwrapper/chmod.o smbwrapper/lseek.o smbwrapper/getcwd.o \
                smbwrapper/mkdir.o smbwrapper/rmdir.o smbwrapper/fchdir.o \
+               smbwrapper/opendir.o smbwrapper/readdir.o smbwrapper/telldir.o \
+               smbwrapper/seekdir.o smbwrapper/closedir.o \
                $(LIBSMB_OBJ) $(PARAM_OBJ) \
                 $(UBIQX_OBJ) $(LIB_OBJ)
 
diff --git a/source3/smbwrapper/closedir.c b/source3/smbwrapper/closedir.c
new file mode 100644 (file)
index 0000000..8e487ab
--- /dev/null
@@ -0,0 +1,36 @@
+/* 
+   Unix SMB/Netbios implementation.
+   Version 2.0
+   SMB wrapper functions
+   Copyright (C) Andrew Tridgell 1998
+   
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+
+#include "wrapper.h"
+
+#ifdef linux
+__asm__(".globl __closedir; __closedir = closedir");
+#endif
+
+ int closedir(DIR *dir)
+{
+       if (smbw_dirp(dir)) {
+               return smbw_closedir(dir);
+       }
+
+       return real_closedir(dir);
+}
diff --git a/source3/smbwrapper/opendir.c b/source3/smbwrapper/opendir.c
new file mode 100644 (file)
index 0000000..2dfb3db
--- /dev/null
@@ -0,0 +1,36 @@
+/* 
+   Unix SMB/Netbios implementation.
+   Version 2.0
+   SMB wrapper functions
+   Copyright (C) Andrew Tridgell 1998
+   
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+
+#include "wrapper.h"
+
+#ifdef linux
+__asm__(".globl __opendir; __opendir = opendir");
+#endif
+
+ DIR *opendir(const char *name)
+{
+       if (smbw_path(name)) {
+               return smbw_opendir(name);
+       }
+
+       return real_opendir(name);
+}
diff --git a/source3/smbwrapper/readdir.c b/source3/smbwrapper/readdir.c
new file mode 100644 (file)
index 0000000..f232a26
--- /dev/null
@@ -0,0 +1,36 @@
+/* 
+   Unix SMB/Netbios implementation.
+   Version 2.0
+   SMB wrapper functions
+   Copyright (C) Andrew Tridgell 1998
+   
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+
+#include "wrapper.h"
+
+#ifdef linux
+__asm__(".globl __readdir; __readdir = readdir");
+#endif
+
+ struct dirent *readdir(DIR *dir)
+{
+       if (smbw_dirp(dir)) {
+               return smbw_readdir(dir);
+       }
+
+       return real_readdir(dir);
+}
index 53f110fe4ab9e5ff8441e677a67d03a6b98dab2c..a5eb046962a30c15226ce8385e15e158e9c2faa9 100644 (file)
 
 #ifdef linux
 struct dirent *__libc_readdir(DIR * dir);
-#define real_readdir(dir)              (__libc_readdir(dirp))
+#define real_readdir(dir)              (__libc_readdir(dir))
+#define real_opendir(fn)               (__libc_opendir(fn))
+#define real_telldir(dir)              (__libc_telldir(dir))
+#define real_closedir(dir)             (__libc_closedir(dir))
+#define real_seekdir(dir, ofs)          (__libc_seekdir(dir, ofs))
 #else
 #define real_readdir(dirp)             ((struct dirent *)syscall(SYS_readdir,(dirp)))
+#define real_opendir(fn)               ((DIR *)syscall(SYS_opendir,(fn)))
 /* if needed define SYS_readdir so that readdir gets compiled */
 #endif
 
diff --git a/source3/smbwrapper/seekdir.c b/source3/smbwrapper/seekdir.c
new file mode 100644 (file)
index 0000000..b30b8b8
--- /dev/null
@@ -0,0 +1,37 @@
+/* 
+   Unix SMB/Netbios implementation.
+   Version 2.0
+   SMB wrapper functions
+   Copyright (C) Andrew Tridgell 1998
+   
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+
+#include "wrapper.h"
+
+#ifdef linux
+__asm__(".globl __seekdir; __seekdir = seekdir");
+#endif
+
+ void seekdir(DIR *dir, off_t offset)
+{
+       if (smbw_dirp(dir)) {
+               smbw_seekdir(dir, offset);
+               return;
+       }
+
+       real_seekdir(dir, offset);
+}
index 11d680befa441bdb90ad1a3df3aa23011ac5dc16..973f667068987092642ddaf37aae85cafcd03298 100644 (file)
@@ -496,6 +496,19 @@ struct smbw_dir *smbw_dir(int fd)
        return NULL;
 }
 
+/***************************************************** 
+check if a DIR* is one of ours
+*******************************************************/
+BOOL smbw_dirp(struct smbw_dir *d)
+{
+       struct smbw_dir *dir;
+
+       for (dir=smbw_dirs;dir;dir=dir->next) {
+               if (dir == d) return True;
+       }
+       return False;
+}
+
 /***************************************************** 
 setup basic info in a stat structure
 *******************************************************/
@@ -596,7 +609,7 @@ void smbw_share_add(const char *share, uint32 type, const char *comment)
 /***************************************************** 
 open a directory on the server
 *******************************************************/
-int smbw_dir_open(const char *fname, int flags)
+int smbw_dir_open(const char *fname)
 {
        fstring server, share;
        pstring path;
@@ -722,7 +735,7 @@ int smbw_open(const char *fname, int flags, mode_t mode)
        }
        if (fd == -1) {
                /* it might be a directory. Maybe we should use chkpath? */
-               fd = smbw_dir_open(fname, flags);
+               fd = smbw_dir_open(fname);
                smbw_busy--;
                return fd;
        }
@@ -1068,9 +1081,7 @@ int smbw_getdents(unsigned int fd, struct dirent *dirp, int count)
        while (count>=sizeof(*dirp) && (dir->offset < dir->count)) {
                dirp->d_off = (dir->offset+1)*sizeof(*dirp);
                dirp->d_reclen = sizeof(*dirp);
-               /* what's going on with the -1 here? maybe d_type
-                   isn't really there? */
-               safe_strcpy(&dirp->d_name[-1], dir->list[dir->offset].name, 
+               safe_strcpy(&dirp->d_name[0], dir->list[dir->offset].name, 
                            sizeof(dirp->d_name)-1);
                dirp->d_ino = smbw_inode(dir->list[dir->offset].name);
                dir->offset++;
@@ -1661,3 +1672,61 @@ int smbw_fchdir(unsigned int fd)
        
        return chdir(dir->path);
 }
+
+/***************************************************** 
+open a directory on the server
+*******************************************************/
+DIR *smbw_opendir(const char *fname)
+{
+       int fd;
+
+       smbw_busy++;
+
+       fd = smbw_dir_open(fname);
+
+       if (fd == -1) {
+               smbw_busy--;
+               return NULL;
+       }
+
+       smbw_busy--;
+
+       return (DIR *)smbw_dir(fd);
+}
+
+/***************************************************** 
+read one entry from a directory
+*******************************************************/
+struct dirent *smbw_readdir(struct smbw_dir *d)
+{
+       static struct dirent de;
+
+       if (smbw_getdents(d->fd, &de, sizeof(struct dirent)) > 0) 
+               return &de;
+
+       return NULL;
+}
+
+/***************************************************** 
+close a DIR*
+*******************************************************/
+int smbw_closedir(struct smbw_dir *d)
+{
+       return smbw_close(d->fd);
+}
+
+/***************************************************** 
+seek in a directory
+*******************************************************/
+void smbw_seekdir(struct smbw_dir *d, off_t offset)
+{
+       smbw_dir_lseek(d->fd,offset, SEEK_SET);
+}
+
+/***************************************************** 
+current loc in a directory
+*******************************************************/
+off_t smbw_telldir(struct smbw_dir *d)
+{
+       return smbw_dir_lseek(d->fd,0,SEEK_CUR);
+}
diff --git a/source3/smbwrapper/telldir.c b/source3/smbwrapper/telldir.c
new file mode 100644 (file)
index 0000000..d8bd357
--- /dev/null
@@ -0,0 +1,36 @@
+/* 
+   Unix SMB/Netbios implementation.
+   Version 2.0
+   SMB wrapper functions
+   Copyright (C) Andrew Tridgell 1998
+   
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+
+#include "wrapper.h"
+
+#ifdef linux
+__asm__(".globl __telldir; __telldir = telldir");
+#endif
+
+ off_t telldir(DIR *dir)
+{
+       if (smbw_dirp(dir)) {
+               return smbw_telldir(dir);
+       }
+
+       return real_telldir(dir);
+}