How do I find out the compressed / uncompressed file sizes on btrfs?

I am using btrfs on one of my hard drives. I would like to know the actual file size and the compressed file size on btrfs. I am interested in seeing the compression ratios per file . For example ntfs file system can give you such information.

I am using compress-force=zlib option in my fstab. And I am using Debian Squeeze 3.2.0-0.bpo.4-amd64

thanks


Solution 1:

there is third party tool that can do this.

https://github.com/kilobyte/compsize

usage:

ayush@devbox:/code/compsize$ sudo compsize /opt
Processed 54036 files, 42027 regular extents (42028 refs), 27150 inline.
Type       Perc     Disk Usage   Uncompressed Referenced  
Data        82%      5.3G         6.4G         6.4G       
none       100%      4.3G         4.3G         4.3G       
zlib        37%      427M         1.1G         1.1G       
lzo         56%      588M         1.0G         1.0G  

Solution 2:

An interesting question, but it seems like that would be a negative for now.

According to the offical FAQ (https://btrfs.wiki.kernel.org/index.php/FAQ) the reason being that the information is just not stored in the file system. There is a patch for the kernel (https://patchwork.kernel.org/patch/117782/) but again, this only counts the blocks used (so the ratio is rounded to the block size, thus off by upto 4KB).

If a utility was made (would be possible) it would be extremely inefficient. The program would have to decompress the file to determine the compression ratio.