so there is no way to know the size occupied by data ?

I want to find out how many disk blocks are used by only data (and not metadata) by a file.

But as far as I can tell, if the file has holes, then there is no way to know this.

You can find out the logical size of the file (physical size + hole blocks).
You can get the physical size of the file (data + metadata).
But no matter what calculation you do or whatever program you write, you cannot get the blocks occupied by data.

What metadata are you worried about?

Are you on an XFS system?

What is the actual requirement here?

That cannot be true because a disk file system driver is a program which does calculations.

hmm, I am sorry, by metadata I think I meant Indirect blocks

what I mean is, whatever shell cmds I have to get a file size.. they will give me the total disk space occuiped by the file (data + other stuff). But I want to know whats the space occupied by data only.

ls -ls for example...

Here 104 is the total physical disk space occupied by the file. As far as I understand this includes space occupied by data, metadata, Indirect blocks, (Inode) etc etc...

Sure, a file system level program might be able to give the answer.. but how can a user level program find out the number of data blocks ?

(A program might read the file and calculate the number of blocks read, but if the file has holes.. it will read those too.. )

http://www.unix.com/high-level-programming/37375-locate-holes-sparse-file.html

The most portable solution is "dd" the file into another file and compare the difference, dd will happily write out the full size.