s3 libsmbclient: Fix fstatvfs to be more portable
[samba.git] / examples / libsmbclient / testfstatvfs.c
1 #include <sys/types.h>
2 #include <stdio.h> 
3 #include <unistd.h>
4 #include <string.h> 
5 #include <time.h> 
6 #include <errno.h>
7 #include <libsmbclient.h> 
8 #include "get_auth_data_fn.h"
9
10
11 int main(int argc, char * argv[]) 
12
13     int             i;
14     int             fd;
15     int             ret;
16     int             debug = 0;
17     char *          p;
18     char            path[2048];
19     struct stat     statbuf;
20     struct smbc_statvfs  statvfsbuf;
21     
22     smbc_init(get_auth_data_fn, debug); 
23     
24     for (;;)
25     {
26         fprintf(stdout, "Path: ");
27         *path = '\0';
28         fgets(path, sizeof(path) - 1, stdin);
29         if (strlen(path) == 0)
30         {
31             return 0;
32         }
33
34         p = path + strlen(path) - 1;
35         if (*p == '\n')
36         {
37             *p = '\0';
38         }
39     
40         /* Determine if it's a file or a folder */
41         if (smbc_stat(path, &statbuf) < 0)
42         {
43             perror("smbc_stat");
44             continue;
45         }
46
47         if (S_ISREG(statbuf.st_mode))
48         {
49             if ((fd = smbc_open(path, O_RDONLY, 0)) < 0)
50             {
51                 perror("smbc_open");
52                 continue;
53             }
54         }
55         else
56         {
57             if ((fd = smbc_opendir(path)) < 0)
58             {
59                 perror("smbc_opendir");
60                 continue;
61             }
62         }
63
64         ret = smbc_fstatvfs(fd, &statvfsbuf);
65
66         smbc_close(fd);
67
68         if (ret < 0)
69         {
70             perror("fstatvfs");
71         }
72         else
73         {
74             printf("\n");
75             printf("Block Size: %lu\n", statvfsbuf.f_bsize);
76             printf("Fragment Size: %lu\n", statvfsbuf.f_frsize);
77             printf("Blocks: %llu\n", statvfsbuf.f_blocks);
78             printf("Free Blocks: %llu\n", statvfsbuf.f_bfree);
79             printf("Available Blocks: %llu\n", statvfsbuf.f_bavail);
80             printf("Files : %llu\n", statvfsbuf.f_files);
81             printf("Free Files: %llu\n", statvfsbuf.f_ffree);
82             printf("Available Files: %llu\n", statvfsbuf.f_favail);
83             printf("File System ID: %lu\n", statvfsbuf.f_fsid);
84             printf("\n");
85
86             printf("Flags: 0x%lx\n", statvfsbuf.f_flag);
87             printf("Extended Features: ");
88
89             if (statvfsbuf.f_flag & SMBC_VFS_FEATURE_NO_UNIXCIFS)
90             {
91                 printf("NO_UNIXCIFS ");
92             }
93             else
94             {
95                 printf("unixcifs ");
96             }
97
98             if (statvfsbuf.f_flag & SMBC_VFS_FEATURE_CASE_INSENSITIVE)
99             {
100                 printf("CASE_INSENSITIVE ");
101             }
102             else
103             {
104                 printf("case_sensitive ");
105             }
106
107             if (statvfsbuf.f_flag & SMBC_VFS_FEATURE_DFS)
108             {
109                 printf("DFS ");
110             }
111             else
112             {
113                 printf("no_dfs ");
114             }
115
116             printf("\n");
117         }
118     }
119
120     return 0; 
121 }