summaryrefslogtreecommitdiff
path: root/source3/smbwrapper
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>1998-10-03 16:34:57 +0000
committerAndrew Tridgell <tridge@samba.org>1998-10-03 16:34:57 +0000
commit1fa3478aaf5a40a0eb37f8f5679707d23231e276 (patch)
tree09dfadb60520f4c4157d8ed9d328c84f50399023 /source3/smbwrapper
parent8d4c7326212f23d2a255def7f7e9c992eb752911 (diff)
downloadsamba-1fa3478aaf5a40a0eb37f8f5679707d23231e276.tar.gz
samba-1fa3478aaf5a40a0eb37f8f5679707d23231e276.tar.bz2
samba-1fa3478aaf5a40a0eb37f8f5679707d23231e276.zip
drat.
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)
Diffstat (limited to 'source3/smbwrapper')
-rw-r--r--source3/smbwrapper/closedir.c36
-rw-r--r--source3/smbwrapper/opendir.c36
-rw-r--r--source3/smbwrapper/readdir.c36
-rw-r--r--source3/smbwrapper/realcalls.h7
-rw-r--r--source3/smbwrapper/seekdir.c37
-rw-r--r--source3/smbwrapper/smbw.c79
-rw-r--r--source3/smbwrapper/telldir.c36
7 files changed, 261 insertions, 6 deletions
diff --git a/source3/smbwrapper/closedir.c b/source3/smbwrapper/closedir.c
new file mode 100644
index 0000000000..8e487abe47
--- /dev/null
+++ b/source3/smbwrapper/closedir.c
@@ -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
index 0000000000..2dfb3dbf21
--- /dev/null
+++ b/source3/smbwrapper/opendir.c
@@ -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
index 0000000000..f232a2609e
--- /dev/null
+++ b/source3/smbwrapper/readdir.c
@@ -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);
+}
diff --git a/source3/smbwrapper/realcalls.h b/source3/smbwrapper/realcalls.h
index 53f110fe4a..a5eb046962 100644
--- a/source3/smbwrapper/realcalls.h
+++ b/source3/smbwrapper/realcalls.h
@@ -21,9 +21,14 @@
#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
index 0000000000..b30b8b899c
--- /dev/null
+++ b/source3/smbwrapper/seekdir.c
@@ -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);
+}
diff --git a/source3/smbwrapper/smbw.c b/source3/smbwrapper/smbw.c
index 11d680befa..973f667068 100644
--- a/source3/smbwrapper/smbw.c
+++ b/source3/smbwrapper/smbw.c
@@ -497,6 +497,19 @@ struct smbw_dir *smbw_dir(int fd)
}
/*****************************************************
+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
*******************************************************/
void smbw_setup_stat(struct stat *st, char *fname, size_t size, int mode)
@@ -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
index 0000000000..d8bd3572a2
--- /dev/null
+++ b/source3/smbwrapper/telldir.c
@@ -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);
+}