s3 libsmbclient: Fix fstatvfs to be more portable
[jra/samba/.git] / examples / libsmbclient / teststatvfs.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         ret = smbc_statvfs(path, &statvfsbuf);
41
42         if (ret < 0)
43         {
44             perror("fstatvfs");
45         }
46         else
47         {
48             printf("\n");
49             printf("Block Size: %lu\n", statvfsbuf.f_bsize);
50             printf("Fragment Size: %lu\n", statvfsbuf.f_frsize);
51             printf("Blocks: %llu\n", statvfsbuf.f_blocks);
52             printf("Free Blocks: %llu\n", statvfsbuf.f_bfree);
53             printf("Available Blocks: %llu\n", statvfsbuf.f_bavail);
54             printf("Files : %llu\n", statvfsbuf.f_files);
55             printf("Free Files: %llu\n", statvfsbuf.f_ffree);
56             printf("Available Files: %llu\n", statvfsbuf.f_favail);
57             printf("File System ID: %lu\n", statvfsbuf.f_fsid);
58             printf("\n");
59
60             printf("Flags: 0x%lx\n", statvfsbuf.f_flag);
61             printf("Extended Features: ");
62
63             if (statvfsbuf.f_flag & SMBC_VFS_FEATURE_NO_UNIXCIFS)
64             {
65                 printf("NO_UNIXCIFS ");
66             }
67             else
68             {
69                 printf("unixcifs ");
70             }
71
72             if (statvfsbuf.f_flag & SMBC_VFS_FEATURE_CASE_INSENSITIVE)
73             {
74                 printf("CASE_INSENSITIVE ");
75             }
76             else
77             {
78                 printf("case_sensitive ");
79             }
80
81             if (statvfsbuf.f_flag & SMBC_VFS_FEATURE_DFS)
82             {
83                 printf("DFS ");
84             }
85             else
86             {
87                 printf("no_dfs ");
88             }
89
90             printf("\n");
91         }
92     }
93
94     return 0; 
95 }