aboutsummaryrefslogtreecommitdiff
path: root/win32/statfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'win32/statfs.c')
-rw-r--r--win32/statfs.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/win32/statfs.c b/win32/statfs.c
new file mode 100644
index 000000000..8424d58fa
--- /dev/null
+++ b/win32/statfs.c
@@ -0,0 +1,50 @@
1#include <sys/vfs.h>
2#include "libbb.h"
3
4/*
5 * Code from libguestfs
6 */
7int statfs(const char *file, struct statfs *buf)
8{
9 ULONGLONG free_bytes_available; /* for user - similar to bavail */
10 ULONGLONG total_number_of_bytes;
11 ULONGLONG total_number_of_free_bytes; /* for everyone - bfree */
12
13 if ( !GetDiskFreeSpaceEx(file, (PULARGE_INTEGER) &free_bytes_available,
14 (PULARGE_INTEGER) &total_number_of_bytes,
15 (PULARGE_INTEGER) &total_number_of_free_bytes) ) {
16 return -1;
17 }
18
19 /* XXX I couldn't determine how to get block size. MSDN has a
20 * unhelpful hard-coded list here:
21 * http://support.microsoft.com/kb/140365
22 * but this depends on the filesystem type, the size of the disk and
23 * the version of Windows. So this code assumes the disk is NTFS
24 * and the version of Windows is >= Win2K.
25 */
26 if (total_number_of_bytes < UINT64_C(16) * 1024 * 1024 * 1024 * 1024)
27 buf->f_bsize = 4096;
28 else if (total_number_of_bytes < UINT64_C(32) * 1024 * 1024 * 1024 * 1024)
29 buf->f_bsize = 8192;
30 else if (total_number_of_bytes < UINT64_C(64) * 1024 * 1024 * 1024 * 1024)
31 buf->f_bsize = 16384;
32 else if (total_number_of_bytes < UINT64_C(128) * 1024 * 1024 * 1024 * 1024)
33 buf->f_bsize = 32768;
34 else
35 buf->f_bsize = 65536;
36
37 /* As with stat, -1 indicates a field is not known. */
38 buf->f_frsize = buf->f_bsize;
39 buf->f_blocks = total_number_of_bytes / buf->f_bsize;
40 buf->f_bfree = total_number_of_free_bytes / buf->f_bsize;
41 buf->f_bavail = free_bytes_available / buf->f_bsize;
42 buf->f_files = -1;
43 buf->f_ffree = -1;
44 buf->f_favail = -1;
45 buf->f_fsid = -1;
46 buf->f_flag = -1;
47 buf->f_namemax = FILENAME_MAX;
48
49 return 0;
50}