8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems
authorbpb
Fri, 12 Jun 2015 17:05:26 -0700
changeset 31144 8154c9d7bc32
parent 31143 35889b7bb6e9
child 31145 af4093895e5f
8087288: File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems Summary: On Mac OS X replace statvfs64() and struct statvfs64 with statfs() and struct statfs, respectively, and f_frsize with f_bsize. Reviewed-by: alanb
jdk/src/java.base/unix/native/libjava/UnixFileSystem_md.c
--- a/jdk/src/java.base/unix/native/libjava/UnixFileSystem_md.c	Fri Jun 12 16:40:05 2015 -0400
+++ b/jdk/src/java.base/unix/native/libjava/UnixFileSystem_md.c	Fri Jun 12 17:05:26 2015 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,7 +27,12 @@
 #include <sys/types.h>
 #include <sys/time.h>
 #include <sys/stat.h>
+#ifdef MACOSX
+#include <sys/param.h>
+#include <sys/mount.h>
+#else
 #include <sys/statvfs.h>
+#endif
 #include <string.h>
 #include <stdlib.h>
 #include <dlfcn.h>
@@ -46,8 +51,10 @@
 #define dirent64 dirent
 #define readdir64_r readdir_r
 #define stat64 stat
+#ifndef MACOSX
 #define statvfs64 statvfs
 #endif
+#endif
 
 /* -- Field IDs -- */
 
@@ -432,8 +439,32 @@
     jlong rv = 0L;
 
     WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
+#ifdef MACOSX
+        struct statfs fsstat;
+#else
         struct statvfs64 fsstat;
+#endif
         memset(&fsstat, 0, sizeof(fsstat));
+#ifdef MACOSX
+        if (statfs(path, &fsstat) == 0) {
+            switch(t) {
+                case java_io_FileSystem_SPACE_TOTAL:
+                    rv = jlong_mul(long_to_jlong(fsstat.f_bsize),
+                                   long_to_jlong(fsstat.f_blocks));
+                    break;
+                case java_io_FileSystem_SPACE_FREE:
+                    rv = jlong_mul(long_to_jlong(fsstat.f_bsize),
+                                   long_to_jlong(fsstat.f_bfree));
+                    break;
+                case java_io_FileSystem_SPACE_USABLE:
+                    rv = jlong_mul(long_to_jlong(fsstat.f_bsize),
+                                   long_to_jlong(fsstat.f_bavail));
+                    break;
+                default:
+                    assert(0);
+            }
+        }
+#else
         if (statvfs64(path, &fsstat) == 0) {
             switch(t) {
             case java_io_FileSystem_SPACE_TOTAL:
@@ -452,6 +483,7 @@
                 assert(0);
             }
         }
+#endif
     } END_PLATFORM_STRING(env, path);
     return rv;
 }