s3:libsmb/libsmb_dir: make use of cli_state_remote_name()
[Samba.git] / examples / libsmbclient / testfstatvfs.c
blob73f42d446ab00955c0638ed835ab81199e3a51aa
1 #include <sys/types.h>
2 #include <sys/statvfs.h>
3 #include <stdio.h>
4 #include <unistd.h>
5 #include <string.h>
6 #include <time.h>
7 #include <errno.h>
8 #include <libsmbclient.h>
9 #include "get_auth_data_fn.h"
12 int main(int argc, char * argv[])
14 int i;
15 int fd;
16 int ret;
17 int debug = 0;
18 char * p;
19 char path[2048];
20 struct stat statbuf;
21 struct statvfs statvfsbuf;
23 smbc_init(get_auth_data_fn, debug);
25 for (;;)
27 fprintf(stdout, "Path: ");
28 *path = '\0';
29 fgets(path, sizeof(path) - 1, stdin);
30 if (strlen(path) == 0)
32 return 0;
35 p = path + strlen(path) - 1;
36 if (*p == '\n')
38 *p = '\0';
41 /* Determine if it's a file or a folder */
42 if (smbc_stat(path, &statbuf) < 0)
44 perror("smbc_stat");
45 continue;
48 if (S_ISREG(statbuf.st_mode))
50 if ((fd = smbc_open(path, O_RDONLY, 0)) < 0)
52 perror("smbc_open");
53 continue;
56 else
58 if ((fd = smbc_opendir(path)) < 0)
60 perror("smbc_opendir");
61 continue;
65 ret = smbc_fstatvfs(fd, &statvfsbuf);
67 smbc_close(fd);
69 if (ret < 0)
71 perror("fstatvfs");
73 else
75 printf("\n");
76 printf("Block Size: %lu\n", statvfsbuf.f_bsize);
77 printf("Fragment Size: %lu\n", statvfsbuf.f_frsize);
78 printf("Blocks: %llu\n",
79 (unsigned long long) statvfsbuf.f_blocks);
80 printf("Free Blocks: %llu\n",
81 (unsigned long long) statvfsbuf.f_bfree);
82 printf("Available Blocks: %llu\n",
83 (unsigned long long) statvfsbuf.f_bavail);
84 printf("Files : %llu\n",
85 (unsigned long long) statvfsbuf.f_files);
86 printf("Free Files: %llu\n",
87 (unsigned long long) statvfsbuf.f_ffree);
88 printf("Available Files: %llu\n",
89 (unsigned long long) statvfsbuf.f_favail);
90 printf("File System ID: %lu\n",
91 (unsigned long) statvfsbuf.f_fsid);
92 printf("\n");
94 printf("Flags: 0x%lx\n", statvfsbuf.f_flag);
95 printf("Extended Features: ");
97 if (statvfsbuf.f_flag & SMBC_VFS_FEATURE_NO_UNIXCIFS)
99 printf("NO_UNIXCIFS ");
101 else
103 printf("unixcifs ");
106 if (statvfsbuf.f_flag & SMBC_VFS_FEATURE_CASE_INSENSITIVE)
108 printf("CASE_INSENSITIVE ");
110 else
112 printf("case_sensitive ");
115 if (statvfsbuf.f_flag & SMBC_VFS_FEATURE_DFS)
117 printf("DFS ");
119 else
121 printf("no_dfs ");
124 printf("\n");
128 return 0;