Here I quoate from Antonio's FAQ on his implementation of ext2
compression, the relevant section on how he implements it:
2.1 When does de/compression really occur ?
--------------------------------------------
Compression really occurs when the inode is put, i.e. closed by every
process that have a reference to it. Writing to a compressed file is
done as if the file were not compressed (uncompressed data is written
to the disk), but the file is marked dirty. When the inode is put, and
if the file is dirty, the kernel scans every cluster and compresses
those that are not compressed. Unneeded blocks are freed again.
Decompression occurs when needed, i.e. every time the kernel wants to
read a compressed cluster. Of course, the cluster remains compressed
on the disk. But this means that we will have to uncompress the
cluster every time it is accessed.
He uses, IMHO wisely, the 'chattr +c' to determine that a file has been
or has not been compressed.
Also, it is not the filesystem structures, simply the data that is
compressed. Therefore, more data could be wiped out because it is
compressed in an event of a block device corruption, but the
filesystem itself is no more suceptible to corruption than without
the compression.
(hope I said that right).
-- Todd Fries