source: branches/samba-3.3.x/examples/libsmbclient/testfstatvfs.c@ 1003

Last change on this file since 1003 was 374, checked in by Herwig Bauernfeind, 16 years ago

Update Samba 3.3 to 3.3.10 (new files)

File size: 3.0 KB
Line 
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"
10
11
12int main(int argc, char * argv[])
13{
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;
22
23 smbc_init(get_auth_data_fn, debug);
24
25 for (;;)
26 {
27 fprintf(stdout, "Path: ");
28 *path = '\0';
29 fgets(path, sizeof(path) - 1, stdin);
30 if (strlen(path) == 0)
31 {
32 return 0;
33 }
34
35 p = path + strlen(path) - 1;
36 if (*p == '\n')
37 {
38 *p = '\0';
39 }
40
41 /* Determine if it's a file or a folder */
42 if (smbc_stat(path, &statbuf) < 0)
43 {
44 perror("smbc_stat");
45 continue;
46 }
47
48 if (S_ISREG(statbuf.st_mode))
49 {
50 if ((fd = smbc_open(path, O_RDONLY, 0)) < 0)
51 {
52 perror("smbc_open");
53 continue;
54 }
55 }
56 else
57 {
58 if ((fd = smbc_opendir(path)) < 0)
59 {
60 perror("smbc_opendir");
61 continue;
62 }
63 }
64
65 ret = smbc_fstatvfs(fd, &statvfsbuf);
66
67 smbc_close(fd);
68
69 if (ret < 0)
70 {
71 perror("fstatvfs");
72 }
73 else
74 {
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", statvfsbuf.f_blocks);
79 printf("Free Blocks: %llu\n", statvfsbuf.f_bfree);
80 printf("Available Blocks: %llu\n", statvfsbuf.f_bavail);
81 printf("Files : %llu\n", statvfsbuf.f_files);
82 printf("Free Files: %llu\n", statvfsbuf.f_ffree);
83 printf("Available Files: %llu\n", statvfsbuf.f_favail);
84 printf("File System ID: %lu\n", statvfsbuf.f_fsid);
85 printf("\n");
86
87 printf("Flags: 0x%lx\n", statvfsbuf.f_flag);
88 printf("Extended Features: ");
89
90 if (statvfsbuf.f_flag & SMBC_VFS_FEATURE_NO_UNIXCIFS)
91 {
92 printf("NO_UNIXCIFS ");
93 }
94 else
95 {
96 printf("unixcifs ");
97 }
98
99 if (statvfsbuf.f_flag & SMBC_VFS_FEATURE_CASE_INSENSITIVE)
100 {
101 printf("CASE_INSENSITIVE ");
102 }
103 else
104 {
105 printf("case_sensitive ");
106 }
107
108 if (statvfsbuf.f_flag & SMBC_VFS_FEATURE_DFS)
109 {
110 printf("DFS ");
111 }
112 else
113 {
114 printf("no_dfs ");
115 }
116
117 printf("\n");
118 }
119 }
120
121 return 0;
122}
Note: See TracBrowser for help on using the repository browser.