Any way to access fstat.st_blocks from Java (UnixFileAttributesView)

Alan Bateman Alan.Bateman at oracle.com
Fri Jun 28 14:18:06 UTC 2019


On 28/06/2019 11:32, Uwe Schindler wrote:
> Hi,
>
> i browsed through the JDK source code to find a way if the allocated block size of a file can be found using any FileAttributeView. There is the hidden unix one, which allows access to most of the "st_xxxx" constants like st_size, but the st_blocks and st_blksize ones are missing. Is this intended?
>
> The use case for this is to find the actual size allocation of a file on disk (e.g., if it's sparse or for SAMFS if its currently only on band archive (in this case the block size is 0).
>
> Any hints to get the file size on disk from Java that uses the st_blocks and st_blksize behind the scenes?
>
There isn't anything at this time. You are right that the "unix" view 
could expose a "blocks" attribute. The block size is already exposed by 
FileStore::getBlockSize - the motivation for that was sizing and 
aligning buffers for use with direct I/O.

-Alan


More information about the nio-dev mailing list