From 81d958ea6cc8ce98b69148896ebced6458a9715a Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Mon, 6 Jan 2014 12:05:09 +0000 Subject: Extend WIN32 statfs to include type, fsid and namelen --- include/platform.h | 1 - win32/statfs.c | 36 +++++++++++++++++++++++++++++++++--- win32/sys/statfs.h | 23 +++++++++++++++++++++++ win32/sys/vfs.h | 18 +----------------- 4 files changed, 57 insertions(+), 21 deletions(-) create mode 100644 win32/sys/statfs.h 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; # undef HAVE_VASPRINTF # undef HAVE_UNLOCKED_STDIO # undef HAVE_UNLOCKED_LINE_OPS -# undef HAVE_SYS_STATFS_H #endif #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 @@ #include "libbb.h" /* - * Code from libguestfs + * Code from libguestfs (with addition of GetVolumeInformation call) */ int statfs(const char *file, struct statfs *buf) { ULONGLONG free_bytes_available; /* for user - similar to bavail */ ULONGLONG total_number_of_bytes; ULONGLONG total_number_of_free_bytes; /* for everyone - bfree */ + DWORD serial, namelen, flags; + char drive[4], fsname[100]; if ( !GetDiskFreeSpaceEx(file, (PULARGE_INTEGER) &free_bytes_available, (PULARGE_INTEGER) &total_number_of_bytes, @@ -16,6 +18,17 @@ int statfs(const char *file, struct statfs *buf) return -1; } + if ( strlen(file) == 2 && file[1] == ':' ) { + /* GetVolumeInformation wants a backslash */ + strcat(strcpy(drive, file), "\\"); + file = drive; + } + + if ( !GetVolumeInformation(file, NULL, 0, &serial, &namelen, &flags, + fsname, 100) ) { + return -1; + } + /* XXX I couldn't determine how to get block size. MSDN has a * unhelpful hard-coded list here: * http://support.microsoft.com/kb/140365 @@ -34,6 +47,23 @@ int statfs(const char *file, struct statfs *buf) else buf->f_bsize = 65536; + /* + * Valid filesystem names don't seem to be documented. The following + * are present in Wine. + */ + if ( strcmp(fsname, "NTFS") == 0 ) { + buf->f_type = 0x5346544e; + } + else if ( strcmp(fsname, "FAT") == 0 || strcmp(fsname, "FAT32") == 0 ) { + buf->f_type = 0x4006; + } + else if ( strcmp(fsname, "CDFS") == 0 ) { + buf->f_type = 0x9660; + } + else { + buf->f_type = 0; + } + /* As with stat, -1 indicates a field is not known. */ buf->f_frsize = buf->f_bsize; buf->f_blocks = total_number_of_bytes / buf->f_bsize; @@ -42,9 +72,9 @@ int statfs(const char *file, struct statfs *buf) buf->f_files = -1; buf->f_ffree = -1; buf->f_favail = -1; - buf->f_fsid = -1; + buf->f_fsid = serial; buf->f_flag = -1; - buf->f_namemax = FILENAME_MAX; + buf->f_namelen = namelen; return 0; } 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 @@ +#ifndef _SYS_STATFS_H +#define _SYS_STATFS_H 1 + +#include + +struct statfs { + int f_type; + uint64_t f_bsize; + uint64_t f_frsize; + uint64_t f_blocks; + uint64_t f_bfree; + uint64_t f_bavail; + uint64_t f_files; + uint64_t f_ffree; + uint64_t f_favail; + uint64_t f_fsid; + uint64_t f_flag; + uint64_t f_namelen; +}; + +extern int statfs(const char *file, struct statfs *buf); + +#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 @@ -#include - -struct statfs { - uint64_t f_bsize; - uint64_t f_frsize; - uint64_t f_blocks; - uint64_t f_bfree; - uint64_t f_bavail; - uint64_t f_files; - uint64_t f_ffree; - uint64_t f_favail; - uint64_t f_fsid; - uint64_t f_flag; - uint64_t f_namemax; -}; - -extern int statfs(const char *file, struct statfs *buf); +#include -- cgit v1.2.3-55-g6feb