From ea341c79b19ca9f3ddcfdd31caea54b1c815a3b0 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sun, 1 Nov 2015 15:05:12 +0000 Subject: win32: improve implementation of statfs The WIN32 calls should be passed the root directory of the filesystem. --- libbb/find_mount_point.c | 2 +- win32/statfs.c | 24 ++++++++++++------------ win32/sys/statfs.h | 1 - 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/libbb/find_mount_point.c b/libbb/find_mount_point.c index b9bc1dd76..de314a3c7 100644 --- a/libbb/find_mount_point.c +++ b/libbb/find_mount_point.c @@ -27,7 +27,7 @@ struct mntent* FAST_FUNC find_mount_point(const char *name, int subdir_too) #if ENABLE_PLATFORM_MINGW32 static char mnt_fsname[4]; static char mnt_dir[4]; - struct mntent my_mount_entry = { mnt_fsname, mnt_dir, "", "", 0, 0 }; + static struct mntent my_mount_entry = { mnt_fsname, mnt_dir, "", "", 0, 0 }; char *current, *path; DWORD len; #endif diff --git a/win32/statfs.c b/win32/statfs.c index 9e6703849..a35c9adea 100644 --- a/win32/statfs.c +++ b/win32/statfs.c @@ -10,22 +10,24 @@ int statfs(const char *file, struct statfs *buf) ULONGLONG total_number_of_bytes; ULONGLONG total_number_of_free_bytes; /* for everyone - bfree */ DWORD serial, namelen, flags; - char drive[4], fsname[100]; + char fsname[100]; + struct mntent *mnt; + if ( (mnt=find_mount_point(file, 0)) == NULL ) { + return -1; + } + + file = mnt->mnt_dir; if ( !GetDiskFreeSpaceEx(file, (PULARGE_INTEGER) &free_bytes_available, (PULARGE_INTEGER) &total_number_of_bytes, (PULARGE_INTEGER) &total_number_of_free_bytes) ) { + errno = err_win_to_posix(GetLastError()); 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) ) { + errno = err_win_to_posix(GetLastError()); return -1; } @@ -64,16 +66,14 @@ int statfs(const char *file, struct statfs *buf) 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; buf->f_bfree = total_number_of_free_bytes / buf->f_bsize; buf->f_bavail = free_bytes_available / buf->f_bsize; - buf->f_files = -1; - buf->f_ffree = -1; - buf->f_favail = -1; + buf->f_files = UINT32_MAX; + buf->f_ffree = UINT32_MAX; buf->f_fsid = serial; - buf->f_flag = -1; + buf->f_flag = UINT64_MAX; buf->f_namelen = namelen; return 0; diff --git a/win32/sys/statfs.h b/win32/sys/statfs.h index 7cef6df73..498f41e50 100644 --- a/win32/sys/statfs.h +++ b/win32/sys/statfs.h @@ -12,7 +12,6 @@ struct statfs { 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; -- cgit v1.2.3-55-g6feb