From 47d16e7e7ffde80bf244225ea74e985e570ea1ab Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Mon, 9 Feb 2009 22:46:29 -0500 Subject: [PATCH] [Bug 6069] Add a fstatvfs function for libsmbclient - 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 | 101 +++++++++++++++++++++++++++++++++++ source/libsmb/libsmb_stat.c | 27 +++++++++- 2 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 examples/libsmbclient/testfstatvfs.c diff --git a/examples/libsmbclient/testfstatvfs.c b/examples/libsmbclient/testfstatvfs.c new file mode 100644 index 00000000000..9db70cf476a --- /dev/null +++ b/examples/libsmbclient/testfstatvfs.c @@ -0,0 +1,101 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#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; +} diff --git a/source/libsmb/libsmb_stat.c b/source/libsmb/libsmb_stat.c index a9c36475239..71dc1d1cfa9 100644 --- a/source/libsmb/libsmb_stat.c +++ b/source/libsmb/libsmb_stat.c @@ -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; } -- 2.11.4.GIT