For the question to make sense, let me guide you through the whole test case, so please bear with me.
Let's create a file.
echo 0 > ~/SAMPLE
This makes a simple file that is 2 bytes in size (echo appends new line by default, and that doesn't hurt the example).
stat -f "%b %Z" ~/SAMPLE
The output:
8 2
As expected, this file allocated 8 blocks and is 2 bytes in size (Get Info in Finder tells us that is it 2 bytes long and 4k on disk, which is 8 blocks * 512 bytes per block), so it is all good.
Now let's add an attribute, a resource fork in particular:
xattr -w com.apple.ResourceFork 000000 ~/SAMPLE
Let's call stat again:
stat -f "%b %Z" ~/SAMPLE
The output:
16 2
After adding the resource fork attribute, the file system allocated 16 blocks for this file.
ls -l@ ~/SAMPLE
The output:
com.apple.ResourceFork 6
To sum it up: We added 6 bytes to the resource fork and this file now allocates 16 blocks (from only 8 before adding the resource fork), has the content of only 2 bytes and the resource fork has 6 bytes.
If we run this file through the NSURL API, we get this:
NSURL *url = [NSURL fileURLWithPath:@"~/SAMPLE"];
[url getResourceValue:&size forKey:NSURLFileSizeKey error:nil]; // output: 2
[url getResourceValue:&size forKey:NSURLFileAllocatedSizeKey error:nil]; // output: 4096
[url getResourceValue:&size forKey:NSURLTotalFileAllocatedSizeKey error:nil]; // output: 8192
So my question is, if were to use just the system calls (bash or the system API), how would we get 4096, the result for the NSURLFileAllocatedSizeKey key?
The NSURLFileSizeKey is easy - we can just use ls -l for example, also for NSURLTotalFileAllocatedSizeKey - we can use the number of blocks from stat (16) and multiply by 512, but how do we get the value for NSURLFileAllocatedSizeKey, which is 4096 in this case?
From my understanding, it would be the value returned by the NSURLFileAllocatedSizeKey key if we were to delete the resource fork attribute, but how do we get that value using system APIs or bash?