]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
[Bug 6069] Add a fstatvfs function for libsmbclient
authorDerrell Lipman <derrell.lipman@unwireduniverse.com>
Tue, 10 Feb 2009 03:46:29 +0000 (22:46 -0500)
committerKarolin Seeger <kseeger@samba.org>
Mon, 16 Feb 2009 08:56:59 +0000 (09:56 +0100)
- Complete the implementation of the f_flag field. We now return a flag
  indicatin UNIX CIFS, CASE SENSITIVE, and/or DFS support.

Derrell
(cherry picked from commit df15e8f84d108f8e9df1408155b0f9ccc44da3fe)

examples/libsmbclient/testfstatvfs.c [new file with mode: 0644]
source/libsmb/libsmb_stat.c

diff --git a/examples/libsmbclient/testfstatvfs.c b/examples/libsmbclient/testfstatvfs.c
new file mode 100644 (file)
index 0000000..9db70cf
--- /dev/null
@@ -0,0 +1,101 @@
+#include <sys/types.h>
+#include <sys/statvfs.h>
+#include <stdio.h> 
+#include <unistd.h>
+#include <string.h> 
+#include <time.h> 
+#include <errno.h>
+#include <libsmbclient.h> 
+#include "get_auth_data_fn.h"
+
+
+int main(int argc, char * argv[]) 
+{ 
+    int             i;
+    int             fd;
+    int             ret;
+    int             debug = 0;
+    char *          p;
+    char            path[2048];
+    struct stat     statbuf;
+    struct statvfs  statvfsbuf;
+    
+    smbc_init(get_auth_data_fn, debug); 
+    
+    for (;;)
+    {
+        fprintf(stdout, "Path: ");
+        *path = '\0';
+        fgets(path, sizeof(path) - 1, stdin);
+        if (strlen(path) == 0)
+        {
+            return 0;
+        }
+
+        p = path + strlen(path) - 1;
+        if (*p == '\n')
+        {
+            *p = '\0';
+        }
+    
+        /* Determine if it's a file or a folder */
+        if (smbc_stat(path, &statbuf) < 0)
+        {
+            perror("smbc_stat");
+            continue;
+        }
+
+        if (S_ISREG(statbuf.st_mode))
+        {
+            if ((fd = smbc_open(path, O_RDONLY, 0)) < 0)
+            {
+                perror("smbc_open");
+                continue;
+            }
+        }
+        else
+        {
+            if ((fd = smbc_opendir(path)) < 0)
+            {
+                perror("smbc_opendir");
+                continue;
+            }
+        }
+
+        ret = smbc_fstatvfs(fd, &statvfsbuf);
+
+        smbc_close(fd);
+
+        if (ret < 0)
+        {
+            perror("fstatvfs");
+        }
+        else if (statvfsbuf.f_flag == 0)
+        {
+            printf("No capabilities found\n");
+        }
+        else
+        {
+            printf("Capabilities: ");
+
+            if (statvfsbuf.f_flag & SMBC_VFS_CAP_UNIXCIFS)
+            {
+                printf("UNIXCIFS ");
+            }
+
+            if (statvfsbuf.f_flag & SMBC_VFS_CAP_CASE_SENSITIVE)
+            {
+                printf("CASE_SENSITIVE ");
+            }
+
+            if (statvfsbuf.f_flag & SMBC_VFS_CAP_DFS)
+            {
+                printf("DFS ");
+            }
+
+            printf("\n");
+        }
+    }
+
+    return 0; 
+}
index a9c36475239bbbec995e94db97c57d017ff2fd5f..71dc1d1cfa9dee1aa8582facd48988499962a7df 100644 (file)
@@ -310,14 +310,37 @@ SMBC_fstatvfs_ctx(SMBCCTX *context,
                   SMBCFILE *file,
                   struct statvfs *st)
 {
+       uint32 fs_attrs = 0;
+       struct cli_state *cli = file->srv->cli;
+
         /* Initialize all fields (at least until we actually use them) */
         memset(st, 0, sizeof(*st));
 
         /* See if the server has UNIX CIFS support */
-        if (SERVER_HAS_UNIX_CIFS(file->srv->cli))
-        {
+        if (SERVER_HAS_UNIX_CIFS(cli)) {
                 st->f_flag |= SMBC_VFS_CAP_UNIXCIFS;
         }
 
+        /* See if the share is case sensitive */
+        if (!cli_get_fs_attr_info(cli, &fs_attrs)) {
+                /*
+                 * We can't determine the case sensitivity of
+                 * the share. We have no choice but to use the
+                 * user-specified case sensitivity setting.
+                 */
+                if (smbc_getOptionCaseSensitive(context)) {
+                        st->f_flag |= SMBC_VFS_CAP_CASE_SENSITIVE;
+                }
+        } else {
+                if (fs_attrs & FILE_CASE_SENSITIVE_SEARCH) {
+                        st->f_flag |= SMBC_VFS_CAP_CASE_SENSITIVE;
+                }
+        }
+
+        /* See if DFS is supported */
+       if ((cli->capabilities & CAP_DFS) && cli->dfsroot) {
+                st->f_flag |= SMBC_VFS_CAP_DFS;
+        }
+
         return 0;
 }