Skip to content

Commit f7bb106

Browse files
committed
[GR-64488] TruffleFile API does not allow discovery of free and used space on filesystem.
PullRequest: graal/20816
2 parents 8a58595 + ea03f73 commit f7bb106

File tree

10 files changed

+715
-18
lines changed

10 files changed

+715
-18
lines changed

sdk/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This changelog summarizes major changes between GraalVM SDK versions. The main f
1111
* GR-61448 Compilation id (`CompId`) was added to the `opt done` truffle compilation logs. This id matches the compilation id in the output of deoptimization, compilation and code cache logs on HotSpot and SubstrateVM.
1212
* GR-31495 Added the ability to specify language and instrument specific options using `Source.Builder.option(String, String)`. See the language and or tool specific documentation for available options. Available source options may also be reflected using `Instrument.getSourceOptions()` and `Language.getSourceOptions()`.
1313
* GR-55223 The option sandbox.MaxStackFrames is no longer mandatory for the UNTRUSTED polyglot sandbox policy thanks to improved deoptimization handling of compiled code.
14+
* GR-64488 FileSystem implementations can now provide disk-related metadata, including [total space](https://www.graalvm.org/truffle/javadoc/org/graalvm/polyglot/io/FileSystem.html##getFileStoreTotalSpace(java.nio.file.Path)), [usable space](https://www.graalvm.org/truffle/javadoc/org/graalvm/polyglot/io/FileSystem.html#getFileStoreUsableSpace(java.nio.file.Path)), [unallocated space](https://www.graalvm.org/truffle/javadoc/org/graalvm/polyglot/io/FileSystem.html#getFileStoreUnallocatedSpace(java.nio.file.Path)), [block size](https://www.graalvm.org/truffle/javadoc/org/graalvm/polyglot/io/FileSystem.html#getFileStoreBlockSize(java.nio.file.Path)), and [read-only status](https://www.graalvm.org/truffle/javadoc/org/graalvm/polyglot/io/FileSystem.html#isFileStoreReadOnly(java.nio.file.Path)).
1415

1516
## Version 24.2.0
1617
* GR-54905 When using Truffle NFI with the Panama backend, native access must now be granted to the Truffle module instead of the NFI Panama module. Use the `--enable-native-access=org.graalvm.truffle` Java command line option to enable the native access for the NFI Panama backend.

sdk/src/org.graalvm.polyglot/snapshot.sigtest

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,12 +707,17 @@ meth public abstract java.nio.file.Path parsePath(java.lang.String)
707707
meth public abstract java.nio.file.Path parsePath(java.net.URI)
708708
meth public abstract java.nio.file.Path toAbsolutePath(java.nio.file.Path)
709709
meth public abstract void delete(java.nio.file.Path) throws java.io.IOException
710+
meth public boolean isFileStoreReadOnly(java.nio.file.Path) throws java.io.IOException
710711
meth public java.lang.String getMimeType(java.nio.file.Path)
711712
meth public java.lang.String getPathSeparator()
712713
meth public java.lang.String getSeparator()
713714
meth public java.nio.charset.Charset getEncoding(java.nio.file.Path)
714715
meth public java.nio.file.Path getTempDirectory()
715716
meth public java.nio.file.Path readSymbolicLink(java.nio.file.Path) throws java.io.IOException
717+
meth public long getFileStoreBlockSize(java.nio.file.Path) throws java.io.IOException
718+
meth public long getFileStoreTotalSpace(java.nio.file.Path) throws java.io.IOException
719+
meth public long getFileStoreUnallocatedSpace(java.nio.file.Path) throws java.io.IOException
720+
meth public long getFileStoreUsableSpace(java.nio.file.Path) throws java.io.IOException
716721
meth public static org.graalvm.polyglot.io.FileSystem allowInternalResourceAccess(org.graalvm.polyglot.io.FileSystem)
717722
meth public static org.graalvm.polyglot.io.FileSystem allowLanguageHomeAccess(org.graalvm.polyglot.io.FileSystem)
718723
anno 0 java.lang.Deprecated(boolean forRemoval=false, java.lang.String since="")

sdk/src/org.graalvm.polyglot/src/org/graalvm/polyglot/io/FileSystem.java

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -435,6 +435,96 @@ default boolean isSameFile(Path path1, Path path2, LinkOption... options) throws
435435
return toRealPath(path1, options).equals(toRealPath(path2, options));
436436
}
437437

438+
/**
439+
* Returns the size, in bytes, of the file store that contains the given {@code path}. If the
440+
* file store's size exceeds {@link Long#MAX_VALUE}, {@code Long.MAX_VALUE} is returned.
441+
*
442+
* @param path the path whose file store size is to be determined
443+
* @return the size of the file store in bytes
444+
* @throws UnsupportedOperationException if the file system does not support retrieving file
445+
* store information
446+
* @throws IOException if an I/O error occurs while accessing the file store
447+
* @throws SecurityException if the {@link FileSystem} implementation denied the operation
448+
* @since 25.0.0
449+
*/
450+
default long getFileStoreTotalSpace(Path path) throws IOException {
451+
throw new UnsupportedOperationException("GetFileStoreTotalSpace is not supported");
452+
}
453+
454+
/**
455+
* Returns the number of unallocated bytes in the file store that contains the given
456+
* {@code path}. The returned value represents the raw free space on the storage device,
457+
* regardless of access permissions or user quotas. If the number of unallocated bytes exceeds
458+
* {@link Long#MAX_VALUE}, {@code Long.MAX_VALUE} is returned. Note that the value may be
459+
* imprecise, as it can change at any time due to external I/O operations, including those
460+
* performed outside this virtual machine.
461+
*
462+
* @param path the path whose file store is to be queried
463+
* @return the number of unallocated bytes
464+
* @throws UnsupportedOperationException if the file system does not support retrieving file
465+
* store information
466+
* @throws IOException if an I/O error occurs while accessing the file store
467+
* @throws SecurityException if the {@link FileSystem} implementation denied the operation
468+
* @since 25.0.0
469+
*/
470+
default long getFileStoreUnallocatedSpace(Path path) throws IOException {
471+
throw new UnsupportedOperationException("GetFileStoreUnallocatedSpace is not supported");
472+
}
473+
474+
/**
475+
* Returns the number of bytes available to this Java virtual machine on the file store that
476+
* contains the given {@code path}. Unlike {@link #getFileStoreUnallocatedSpace(Path)}, this
477+
* method accounts for operating system level restrictions, user quotas, and file system
478+
* permissions, and therefore may return a smaller value. If the available space exceeds
479+
* {@link Long#MAX_VALUE}, {@code Long.MAX_VALUE} is returned. Note that the returned value may
480+
* be imprecise, as it can change at any time due to external I/O activity, including operations
481+
* performed outside this virtual machine.
482+
*
483+
* @param path the path whose file store is to be queried
484+
* @return the number of usable bytes available to this Java virtual machine
485+
* @throws UnsupportedOperationException if the file system does not support retrieving file
486+
* store information
487+
* @throws IOException if an I/O error occurs while accessing the file store
488+
* @throws SecurityException if the {@link FileSystem} implementation denied the operation
489+
* @since 25.0.0
490+
*/
491+
default long getFileStoreUsableSpace(Path path) throws IOException {
492+
throw new UnsupportedOperationException("GetFileStoreUsableSpace is not supported");
493+
}
494+
495+
/**
496+
* Returns the number of bytes per block in the file store that contains the given {@code path}.
497+
*
498+
* @param path the path whose file store is to be queried
499+
* @return the block size
500+
* @throws UnsupportedOperationException if the file system does not support retrieving file
501+
* store information
502+
* @throws IOException if an I/O error occurs while accessing the file store
503+
* @throws SecurityException if the {@link FileSystem} implementation denied the operation
504+
* @since 25.0.0
505+
*/
506+
default long getFileStoreBlockSize(Path path) throws IOException {
507+
throw new UnsupportedOperationException("GetFileStoreBlockSize is not supported");
508+
}
509+
510+
/**
511+
* Determines whether the file store containing the given {@code path} is read-only.
512+
* <p>
513+
* Note that even if the file store is not read-only, individual write operations may still be
514+
* denied due to restrictions imposed by the {@link FileSystem} implementation, operating system
515+
* level policies, user quotas, or file system permissions.
516+
*
517+
* @param path the path whose file store is to be queried
518+
* @throws UnsupportedOperationException if the file system does not support retrieving file
519+
* store information
520+
* @throws IOException if an I/O error occurs while accessing the file store
521+
* @throws SecurityException if the {@link FileSystem} implementation denied the operation
522+
* @since 25.0.0
523+
*/
524+
default boolean isFileStoreReadOnly(Path path) throws IOException {
525+
throw new UnsupportedOperationException("IsFileStoreReadOnly is not supported");
526+
}
527+
438528
/**
439529
* Creates a {@link FileSystem} implementation based on the host Java NIO. The returned instance
440530
* can be used as a delegate by a decorating {@link FileSystem}.

truffle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ This changelog summarizes major changes between Truffle versions relevant to lan
2222
* Automatic reference type tracking based on assumptions, eliminating redundant type checks.
2323
* Automatic single-assignment tracking based on assumptions allowing languages to assume that a property is effectively final (i.e. stays unchanged after the initial assignment) as well as constant-fold values of a constant receiver with a known shape.
2424
* You can still disable the new layout and switch back to the previous implementation using the system property: `-Dtruffle.object.LayoutFactory=com.oracle.truffle.api.object.CoreLayoutFactory`.
25+
* GR-64488 Added `TruffleFile#getFileStoreInfo()` providing access to disk-related metadata such as total size, usable space, unallocated space and block size.
2526

2627
## Version 24.2.0
2728
* GR-60636 Truffle now stops compiling when the code cache fills up on HotSpot. A warning is printed when that happens.

0 commit comments

Comments
 (0)