Why does stat(2) .st_blocks reflect ZFS compression? #11533
-
(For context: st_blocks is what In systemd/systemd#18353, @poettering wrote:
I think this is an interesting question. On the hand, the Linux stat(2) manpage states:
Which suggests that a file that isn't sparse should have On the other hand, one could argue that POSIX seems silent on this topic. Is there a rationale for the original decision to make st_blocks reflect ZFS compression? Should this be revisited? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
We interpret this to mean that For traditional filesystems (verified on ext2 and Solaris UFS), I don't think it's reasonable for applications to make assumptions about the relationship between |
Beta Was this translation helpful? Give feedback.
-
That's a good question. It appears that the definition of
Unlike Linux's man page it makes no mention of why a file might take fewer physical blocks to store on disk. This is really an internal implementation detail that user space shouldn't need to concern itself with. This philosophy is the same on FreeBSD and it's man page says something very similar.
Only the Linux man pages calls out sparse files as the sole reason why https://en.wikipedia.org/wiki/Comparison_of_file_systems#Allocation_and_layout_policies Since the POSIX standards never clearly specified how this should be handled it was interpreted to mean the amount of space allocated on disk. Since as you mentioned that's just more useful.
|
Beta Was this translation helpful? Give feedback.
-
Sparse files are just a special/simple case of compression. |
Beta Was this translation helpful? Give feedback.
That's a good question. It appears that the definition of
st_blocks
has been interpreted somewhat differently between platforms. This behavior was originally implemented on Solaris and it was defined in the man page as:Unlike Linux's man page it makes no mention of why a file might take fewer physical blocks to store on disk. This is really an internal implementation detail that user space shouldn't need to concern itself with. This philosophy is the same on FreeBSD and it's man page says something very similar.