From 1a74ee64eb835c3395fe763c42fd36e2a720f441 Mon Sep 17 00:00:00 2001 From: Brian Burkhalter Date: Thu, 6 Feb 2025 19:11:35 +0000 Subject: [PATCH] 8349092: File.getFreeSpace violates specification if quotas are in effect (win) Reviewed-by: naoto --- .../windows/classes/java/io/WinNTFileSystem.java | 9 ++++++++- test/jdk/java/io/File/GetXSpace.java | 10 ++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/java.base/windows/classes/java/io/WinNTFileSystem.java b/src/java.base/windows/classes/java/io/WinNTFileSystem.java index af6531edd01..dd567be1827 100644 --- a/src/java.base/windows/classes/java/io/WinNTFileSystem.java +++ b/src/java.base/windows/classes/java/io/WinNTFileSystem.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2025, 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 @@ -584,6 +584,13 @@ final class WinNTFileSystem extends FileSystem { @Override public long getSpace(File f, int t) { if (f.exists()) { + // the value for the number of bytes of free space returned by the + // native layer is not used here as it represents the number of free + // bytes not considering quotas, whereas the value returned for the + // number of usable bytes does respect quotas, and it is required + // that free space <= total space + if (t == SPACE_FREE) + t = SPACE_USABLE; return getSpace0(f, t); } return 0; diff --git a/test/jdk/java/io/File/GetXSpace.java b/test/jdk/java/io/File/GetXSpace.java index 512ea51780b..9142676cedb 100644 --- a/test/jdk/java/io/File/GetXSpace.java +++ b/test/jdk/java/io/File/GetXSpace.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2025, 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 @@ -23,7 +23,7 @@ /** * @test - * @bug 4057701 6286712 6364377 8181919 + * @bug 4057701 6286712 6364377 8181919 8349092 * @requires (os.family == "linux" | os.family == "mac" | * os.family == "windows") * @summary Basic functionality of File.get-X-Space methods. @@ -176,6 +176,12 @@ public class GetXSpace { long fs = f.getFreeSpace(); long us = f.getUsableSpace(); + // Verify inequalities us <= fs <= ts (JDK-8349092) + if (fs > ts) + throw new RuntimeException(f + " free space " + fs + " > total space " + ts); + if (us > fs) + throw new RuntimeException(f + " usable space " + fs + " > free space " + ts); + out.format("%s (%d):%n", s.name(), s.size()); String fmt = " %-4s total = %12d free = %12d usable = %12d%n"; String method = Platform.isWindows() & isCDDrive(s.name()) ? "getCDDriveSpace" : "getSpace0";