Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8087288

File.get{Free,Total,Usable}Space may return unexpected results with >2TB file systems

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 9
    • 9
    • core-libs
    • Mac OS X

    • b70
    • os_x

        The printed output of this class may return incorrect values for large file systems:

        public class FileGetSpace {
            public static void main(String[] args) throws Throwable {
                String pathname = "/mnt";
                File file = new File(pathname);
                long total = file.getTotalSpace();
                long free = file.getFreeSpace();
                long usable = file.getUsableSpace();
                System.out.printf("total: %d free: %d usable: %d\n",
                    total, free, usable);
            }
        }

        For example, the output of the command 'df -k' for mounted file system "node.domain.com:/export" was

        $ df -k /mnt
        Filesystem 1024-blocks Used Available Capacity iused ifree %iused Mounted on
        node.domain.com:/export 7456395490 5480807360 1975588130 74% 262591304 3951176261 6% /mnt

        and the output of the above test class was

        total: 1038279215616 free: 2023002245632 usable: 2023002245632

        Whereas the free space 2023002245632/1024 = 1975588130 is correct, the total space 1038279215616/1024 = 1013944546 most certainly is not.

        A fix similar to that for JDK-8081843 appears to be in order.

              bpb Brian Burkhalter
              bpb Brian Burkhalter
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: