aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2014-01-06 12:05:09 +0000
committerRon Yorston <rmy@pobox.com>2014-01-06 12:05:09 +0000
commit81d958ea6cc8ce98b69148896ebced6458a9715a (patch)
tree89bca683c049a98fa1967f02a23dba2918f19af9
parent5e8fad1617439c6dacfa04e677f4664b0377e340 (diff)
downloadbusybox-w32-81d958ea6cc8ce98b69148896ebced6458a9715a.tar.gz
busybox-w32-81d958ea6cc8ce98b69148896ebced6458a9715a.tar.bz2
busybox-w32-81d958ea6cc8ce98b69148896ebced6458a9715a.zip
Extend WIN32 statfs to include type, fsid and namelen
-rw-r--r--include/platform.h1
-rw-r--r--win32/statfs.c36
-rw-r--r--win32/sys/statfs.h23
-rw-r--r--win32/sys/vfs.h18
4 files changed, 57 insertions, 21 deletions
diff --git a/include/platform.h b/include/platform.h
index 66615b400..e52dd7ba5 100644
--- a/include/platform.h
+++ b/include/platform.h
@@ -421,7 +421,6 @@ typedef unsigned smalluint;
421# undef HAVE_VASPRINTF 421# undef HAVE_VASPRINTF
422# undef HAVE_UNLOCKED_STDIO 422# undef HAVE_UNLOCKED_STDIO
423# undef HAVE_UNLOCKED_LINE_OPS 423# undef HAVE_UNLOCKED_LINE_OPS
424# undef HAVE_SYS_STATFS_H
425#endif 424#endif
426 425
427#if defined(__WATCOMC__) 426#if defined(__WATCOMC__)
diff --git a/win32/statfs.c b/win32/statfs.c
index 8424d58fa..9e6703849 100644
--- a/win32/statfs.c
+++ b/win32/statfs.c
@@ -2,13 +2,15 @@
2#include "libbb.h" 2#include "libbb.h"
3 3
4/* 4/*
5 * Code from libguestfs 5 * Code from libguestfs (with addition of GetVolumeInformation call)
6 */ 6 */
7int statfs(const char *file, struct statfs *buf) 7int statfs(const char *file, struct statfs *buf)
8{ 8{
9 ULONGLONG free_bytes_available; /* for user - similar to bavail */ 9 ULONGLONG free_bytes_available; /* for user - similar to bavail */
10 ULONGLONG total_number_of_bytes; 10 ULONGLONG total_number_of_bytes;
11 ULONGLONG total_number_of_free_bytes; /* for everyone - bfree */ 11 ULONGLONG total_number_of_free_bytes; /* for everyone - bfree */
12 DWORD serial, namelen, flags;
13 char drive[4], fsname[100];
12 14
13 if ( !GetDiskFreeSpaceEx(file, (PULARGE_INTEGER) &free_bytes_available, 15 if ( !GetDiskFreeSpaceEx(file, (PULARGE_INTEGER) &free_bytes_available,
14 (PULARGE_INTEGER) &total_number_of_bytes, 16 (PULARGE_INTEGER) &total_number_of_bytes,
@@ -16,6 +18,17 @@ int statfs(const char *file, struct statfs *buf)
16 return -1; 18 return -1;
17 } 19 }
18 20
21 if ( strlen(file) == 2 && file[1] == ':' ) {
22 /* GetVolumeInformation wants a backslash */
23 strcat(strcpy(drive, file), "\\");
24 file = drive;
25 }
26
27 if ( !GetVolumeInformation(file, NULL, 0, &serial, &namelen, &flags,
28 fsname, 100) ) {
29 return -1;
30 }
31
19 /* XXX I couldn't determine how to get block size. MSDN has a 32 /* XXX I couldn't determine how to get block size. MSDN has a
20 * unhelpful hard-coded list here: 33 * unhelpful hard-coded list here:
21 * http://support.microsoft.com/kb/140365 34 * http://support.microsoft.com/kb/140365
@@ -34,6 +47,23 @@ int statfs(const char *file, struct statfs *buf)
34 else 47 else
35 buf->f_bsize = 65536; 48 buf->f_bsize = 65536;
36 49
50 /*
51 * Valid filesystem names don't seem to be documented. The following
52 * are present in Wine.
53 */
54 if ( strcmp(fsname, "NTFS") == 0 ) {
55 buf->f_type = 0x5346544e;
56 }
57 else if ( strcmp(fsname, "FAT") == 0 || strcmp(fsname, "FAT32") == 0 ) {
58 buf->f_type = 0x4006;
59 }
60 else if ( strcmp(fsname, "CDFS") == 0 ) {
61 buf->f_type = 0x9660;
62 }
63 else {
64 buf->f_type = 0;
65 }
66
37 /* As with stat, -1 indicates a field is not known. */ 67 /* As with stat, -1 indicates a field is not known. */
38 buf->f_frsize = buf->f_bsize; 68 buf->f_frsize = buf->f_bsize;
39 buf->f_blocks = total_number_of_bytes / buf->f_bsize; 69 buf->f_blocks = total_number_of_bytes / buf->f_bsize;
@@ -42,9 +72,9 @@ int statfs(const char *file, struct statfs *buf)
42 buf->f_files = -1; 72 buf->f_files = -1;
43 buf->f_ffree = -1; 73 buf->f_ffree = -1;
44 buf->f_favail = -1; 74 buf->f_favail = -1;
45 buf->f_fsid = -1; 75 buf->f_fsid = serial;
46 buf->f_flag = -1; 76 buf->f_flag = -1;
47 buf->f_namemax = FILENAME_MAX; 77 buf->f_namelen = namelen;
48 78
49 return 0; 79 return 0;
50} 80}
diff --git a/win32/sys/statfs.h b/win32/sys/statfs.h
new file mode 100644
index 000000000..7cef6df73
--- /dev/null
+++ b/win32/sys/statfs.h
@@ -0,0 +1,23 @@
1#ifndef _SYS_STATFS_H
2#define _SYS_STATFS_H 1
3
4#include <stdint.h>
5
6struct statfs {
7 int f_type;
8 uint64_t f_bsize;
9 uint64_t f_frsize;
10 uint64_t f_blocks;
11 uint64_t f_bfree;
12 uint64_t f_bavail;
13 uint64_t f_files;
14 uint64_t f_ffree;
15 uint64_t f_favail;
16 uint64_t f_fsid;
17 uint64_t f_flag;
18 uint64_t f_namelen;
19};
20
21extern int statfs(const char *file, struct statfs *buf);
22
23#endif
diff --git a/win32/sys/vfs.h b/win32/sys/vfs.h
index cb7bda9af..a899db276 100644
--- a/win32/sys/vfs.h
+++ b/win32/sys/vfs.h
@@ -1,17 +1 @@
1#include <stdint.h> #include <sys/statfs.h>
2
3struct statfs {
4 uint64_t f_bsize;
5 uint64_t f_frsize;
6 uint64_t f_blocks;
7 uint64_t f_bfree;
8 uint64_t f_bavail;
9 uint64_t f_files;
10 uint64_t f_ffree;
11 uint64_t f_favail;
12 uint64_t f_fsid;
13 uint64_t f_flag;
14 uint64_t f_namemax;
15};
16
17extern int statfs(const char *file, struct statfs *buf);