]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
A previous change incorrectly deals with the capacity of file system - the
authorOliver Kurth <okurth@vmware.com>
Fri, 20 Dec 2019 20:25:52 +0000 (12:25 -0800)
committerOliver Kurth <okurth@vmware.com>
Fri, 20 Dec 2019 20:25:52 +0000 (12:25 -0800)
file system size - and the amount of free space the file system has.

Revert the change; fix a function header; comments to make it clear
what not to break in the future.

open-vm-tools/lib/file/filePosix.c

index 24aa3a4549f7210d6cfeac0d311db5addb174127..1970e273e7f35436471bd9c2cd7c2dacca097139 100644 (file)
@@ -52,6 +52,7 @@
 #if defined(__linux__)
 #   include <pwd.h>
 #endif
+
 #if defined(__APPLE__)
 #include <TargetConditionals.h>
 #endif
@@ -992,7 +993,7 @@ File_SetFilePermissions(const char *pathName,  // IN:
  *-----------------------------------------------------------------------------
  */
 
-Bool
+static Bool
 FilePosixGetParent(char **canPath)  // IN/OUT: Canonical file path
 {
    char *pathName;
@@ -1049,7 +1050,6 @@ File_GetParent(char **canPath)  // IN/OUT: Canonical file path
 }
 
 
-#if !defined(__APPLE__) || TARGET_OS_IPHONE
 /*
  *----------------------------------------------------------------------
  *
@@ -1130,7 +1130,7 @@ File_GetFreeSpace(const char *pathName,  // IN: File name
    }
 
    if (FileGetStats(fullPath, doNotAscend, &statfsbuf)) {
-      ret = (uint64) statfsbuf.f_bavail * statfsbuf.f_bsize;
+      ret = (uint64) statfsbuf.f_bavail * statfsbuf.f_bsize;  // available space
    } else {
       Warning("%s: Couldn't statfs %s\n", __func__, fullPath);
       ret = -1;
@@ -1140,7 +1140,6 @@ File_GetFreeSpace(const char *pathName,  // IN: File name
 
    return ret;
 }
-#endif
 
 
 #if defined(VMX86_SERVER)
@@ -1608,8 +1607,10 @@ File_SupportsOptimisticLock(const char *pathName)  // IN:
  *
  * File_GetCapacity --
  *
- *      Return the total capacity (in bytes) available to the user on a disk
- *      where a file is or would be
+ *      Return the total capacity (in bytes) of the file system that the
+ *      specified file resides on. This is not be confused with the
+ *      amount of free space available in the file system the specified
+ *      file resides on.
  *
  * Results:
  *      -1 if error (reported to the user)
@@ -1623,7 +1624,25 @@ File_SupportsOptimisticLock(const char *pathName)  // IN:
 uint64
 File_GetCapacity(const char *pathName)  // IN: Path name
 {
-   return File_GetFreeSpace(pathName, FALSE);
+   uint64 ret;
+   char *fullPath;
+   struct statfs statfsbuf;
+
+   fullPath = File_FullPath(pathName);
+   if (fullPath == NULL) {
+      return -1;
+   }
+
+   if (FileGetStats(fullPath, FALSE, &statfsbuf)) {
+      ret = (uint64) statfsbuf.f_blocks * statfsbuf.f_bsize; // FS size
+   } else {
+      Warning(LGPFX" %s: Couldn't statfs\n", __func__);
+      ret = -1;
+   }
+
+   Posix_Free(fullPath);
+
+   return ret;
 }