talloc: release 2.4.2
[Samba.git] / examples / libsmbclient / testfstatvfs.c
blob9a4063e490c65035a0ff58b72f6c0255fff38949
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 fd;
15 int ret;
16 int debug = 0;
17 char * p;
18 char path[2048];
19 struct stat statbuf;
20 struct statvfs statvfsbuf;
22 smbc_init(get_auth_data_fn, debug);
24 for (;;)
26 fprintf(stdout, "Path: ");
27 *path = '\0';
28 p = fgets(path, sizeof(path) - 1, stdin);
29 if (p == NULL) {
30 fprintf(stderr, "failed to read from stdin\n");
31 return 1;
33 if (strlen(path) == 0)
35 return 0;
38 p = path + strlen(path) - 1;
39 if (*p == '\n')
41 *p = '\0';
44 /* Determine if it's a file or a folder */
45 if (smbc_stat(path, &statbuf) < 0)
47 perror("smbc_stat");
48 continue;
51 if (S_ISREG(statbuf.st_mode))
53 if ((fd = smbc_open(path, O_RDONLY, 0)) < 0)
55 perror("smbc_open");
56 continue;
59 else
61 if ((fd = smbc_opendir(path)) < 0)
63 perror("smbc_opendir");
64 continue;
68 ret = smbc_fstatvfs(fd, &statvfsbuf);
70 smbc_close(fd);
72 if (ret < 0)
74 perror("fstatvfs");
76 else
78 printf("\n");
79 printf("Block Size: %lu\n", statvfsbuf.f_bsize);
80 printf("Fragment Size: %lu\n", statvfsbuf.f_frsize);
81 printf("Blocks: %llu\n",
82 (unsigned long long) statvfsbuf.f_blocks);
83 printf("Free Blocks: %llu\n",
84 (unsigned long long) statvfsbuf.f_bfree);
85 printf("Available Blocks: %llu\n",
86 (unsigned long long) statvfsbuf.f_bavail);
87 printf("Files : %llu\n",
88 (unsigned long long) statvfsbuf.f_files);
89 printf("Free Files: %llu\n",
90 (unsigned long long) statvfsbuf.f_ffree);
91 printf("Available Files: %llu\n",
92 (unsigned long long) statvfsbuf.f_favail);
93 #ifdef HAVE_FSID_INT
94 printf("File System ID: %lu\n",
95 (unsigned long) statvfsbuf.f_fsid);
96 #endif
97 printf("\n");
99 printf("Flags: 0x%lx\n", statvfsbuf.f_flag);
100 printf("Extended Features: ");
102 if (statvfsbuf.f_flag & SMBC_VFS_FEATURE_NO_UNIXCIFS)
104 printf("NO_UNIXCIFS ");
106 else
108 printf("unixcifs ");
111 if (statvfsbuf.f_flag & SMBC_VFS_FEATURE_CASE_INSENSITIVE)
113 printf("CASE_INSENSITIVE ");
115 else
117 printf("case_sensitive ");
120 if (statvfsbuf.f_flag & SMBC_VFS_FEATURE_DFS)
122 printf("DFS ");
124 else
126 printf("no_dfs ");
129 printf("\n");
133 return 0;