You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After a quick look it seems that FileStat.blocks() uses _stat64 on Windows to calculate the number from st_size, which is seriously wrong
public long blocks() {
return (layout.st_size.get(memory) + 512 - 1) / 512;
}
A file may have less number of blocks allocated (like sparse files and compressed files), or no blocks allocated at all (called resident files on Windows, inline files on Linux). So you can't divide the size by 512 to get the number of blocks. You must call the function GetCompressedFileSize() instead. Alternatively you can use the command fsutil file layout to get that information
On Linux
The st_blocks field indicates the number of blocks allocated to the file, 512-byte units. (This may be smaller than st_size/512 when the file has holes.) https://linux.die.net/man/2/stat64
so it'll work for sparse files, but I'm not sure if it works for inline files and compressed files. If it doesn't return the number of real blocks for those then you must use whatever system call du is using
And why is there no documents for the interfaces? I couldn't understand why blocks() assumes block size as 512 (which is incorrect in most cases) until I read the stat64 man page
The text was updated successfully, but these errors were encountered:
After a quick look it seems that
FileStat.blocks()
uses_stat64
on Windows to calculate the number fromst_size
, which is seriously wrongA file may have less number of blocks allocated (like sparse files and compressed files), or no blocks allocated at all (called resident files on Windows, inline files on Linux). So you can't divide the size by 512 to get the number of blocks. You must call the function
GetCompressedFileSize()
instead. Alternatively you can use the commandfsutil file layout
to get that informationOn Linux
so it'll work for sparse files, but I'm not sure if it works for inline files and compressed files. If it doesn't return the number of real blocks for those then you must use whatever system call
du
is usingAnd why is there no documents for the interfaces? I couldn't understand why
blocks()
assumes block size as 512 (which is incorrect in most cases) until I read the stat64 man pageThe text was updated successfully, but these errors were encountered: