Linux – stat file system sizes

linuxstat

With stat 8.13 on a Debian based Linux – among many others – the following FORMAT directives (--format=) are offered:

In combination with --file-system (-f):

  • %s Block size (for faster transfers)
  • %S Fundamental block size (for block counts)

Question(s): What exactly is meant?

My best guess is that %s, %S equals %b (display in Blocks) and %B (display block's size), where the latter are for files and the first two are for file systems. Is that correct?

Best Answer

   %S     fundamental block size (for block counts)

tells you how big each block is on the file system. On most file systems, this is the smallest amount of space any file can take up. Each file uses a multiple of this.

For example,

$ echo > a           # create a file containing a single byte
$ du -h a            # see how much disk space it's using
4.0K    a
$ stat -f -c '%S' .  # see what stat thinks the block size is
4096
$ tune2fs -l /dev/mydrive | grep '^Block size'
4096

I'm not 100% sure it always works like this. For example, I expect it could also decide to print 512 or 1024, even if the underlying block size is different, provided stat -c %b FILE * stat -f -c %S FILE = du --block-size=1 FILE. The exact implementation would depend on the file system.


%s     block size (for faster transfers)

suggests how many bytes you should read at a time if you're copying large files, for example what you should use as the bs (blocksize) parameter when using dd. But on the systems I checked, it always prints 4096, even where larger values might be faster. See Is there a way to determine the optimal value for the bs parameter to dd? for more discussion of that.


Technically, this information (and all the information from stat -f) comes from the statvfs system call.

%s corresponds to the f_bsize field, and %S is f_frsize.

So you could look into their precise meanings starting with the statvfs man page

 unsigned long  f_bsize;    /* Filesystem block size */
 unsigned long  f_frsize;   /* Fragment size */
Related Question