added lseek() to smbwrapper
authorAndrew Tridgell <tridge@samba.org>
Sat, 3 Oct 1998 11:54:20 +0000 (11:54 +0000)
committerAndrew Tridgell <tridge@samba.org>
Sat, 3 Oct 1998 11:54:20 +0000 (11:54 +0000)
source/smbwrapper/smbw.c
source/smbwrapper/smbw.h

index 3ee48007d58d84f1ea16ebff1d7e4536303209cd..5392cf1abc8206a770c9f883310d72a881ec2afd 100644 (file)
@@ -436,10 +436,11 @@ struct smbw_server *smbw_server(char *server, char *share)
 
        /* some programs play with file descriptors fairly intimately. We
           try to get out of the way by duping to a high fd number */
-       if (fcntl(SMBW_CLI_FD, F_GETFD) && errno == EBADF) {
-               if (dup2(srv->cli.fd, SMBW_CLI_FD) == SMBW_CLI_FD) {
+       if (fcntl(SMBW_CLI_FD + srv->cli.fd, F_GETFD) && errno == EBADF) {
+               if (dup2(srv->cli.fd,SMBW_CLI_FD+srv->cli.fd) == 
+                   srv->cli.fd+SMBW_CLI_FD) {
                        close(srv->cli.fd);
-                       srv->cli.fd = SMBW_CLI_FD;
+                       srv->cli.fd += SMBW_CLI_FD;
                }
        }
 
@@ -516,6 +517,9 @@ static BOOL smbw_getatr(struct smbw_server *srv, char *path,
        if (cli_qpathinfo(&srv->cli, path, c_time, a_time, m_time,
                          size, mode)) return True;
 
+       /* if this is NT then don't bother with the getatr */
+       if (srv->cli.capabilities & CAP_NT_SMBS) return False;
+
        if (cli_getatr(&srv->cli, path, mode, size, m_time)) {
                a_time = c_time = m_time;
                return True;
@@ -800,9 +804,9 @@ int smbw_fstat(int fd, struct stat *st)
                return ret;
        }
 
-       DEBUG(4,("%s - getattrE\n", __FUNCTION__));
-
-       if (!cli_getattrE(&file->srv->cli, file->cli_fd, 
+       if (!cli_qfileinfo(&file->srv->cli, file->cli_fd, 
+                         &mode, &size, &c_time, &a_time, &m_time) &&
+           !cli_getattrE(&file->srv->cli, file->cli_fd, 
                          &mode, &size, &c_time, &a_time, &m_time)) {
                errno = EINVAL;
                smbw_busy--;
@@ -1405,3 +1409,46 @@ int smbw_chmod(const char *fname, mode_t newmode)
        smbw_busy--;
        return -1;
 }
+
+/***************************************************** 
+a wrapper for lseek()
+*******************************************************/
+ssize_t smbw_lseek(int fd, off_t offset, int whence)
+{
+       struct smbw_file *file;
+       uint32 size;
+
+       DEBUG(4,("%s\n", __FUNCTION__));
+
+       smbw_busy++;
+
+       file = smbw_file(fd);
+       if (!file) {
+               errno = EBADF;
+               smbw_busy--;
+               return -1;
+       }
+
+       switch (whence) {
+       case SEEK_SET:
+               file->offset = offset;
+               break;
+       case SEEK_CUR:
+               file->offset += offset;
+               break;
+       case SEEK_END:
+               if (!cli_qfileinfo(&file->srv->cli, file->cli_fd, 
+                                  NULL, &size, NULL, NULL, NULL) &&
+                   !cli_getattrE(&file->srv->cli, file->cli_fd, 
+                                 NULL, &size, NULL, NULL, NULL)) {
+                       errno = EINVAL;
+                       smbw_busy--;
+                       return -1;
+               }
+               file->offset = size + offset;
+               break;
+       }
+
+       smbw_busy--;
+       return file->offset;
+}
index 60a339181bad8aebac1a176f14789f9f6857f114..71dce3b321bd6f2813f57a7f253b9acff525a9fc 100644 (file)
@@ -22,7 +22,7 @@
 #define SMBW_PREFIX "/smb/"
 
 #define SMBW_FD_OFFSET 1024
-#define SMBW_CLI_FD 1023
+#define SMBW_CLI_FD 512
 #define SMBW_MAX_OPEN 2048
 
 #define SMBW_FILE_MODE (S_IFREG | 0644)