How to get the filesystem block size



Linux
It is very easy to know what is the size in bytes of the blocks of a filesystem. This solution was provided by OSOR on LinuxQuestions.org - thanks a lot!

Write a file called blocks.c with the following C-source text in it:

#include <stdio.h>
#include <stdlib.h>
#include <sys/statvfs.h>

int main(int argc, char *argv[])
{
        struct statvfs buf;
        if(statvfs(argv[1], &buf))
                {
                printf("Usage: blocks <block device>\n");
                exit(EXIT_FAILURE);
                }
        else
                {
                printf("File system block size: %lu\n", buf.f_bsize);
                printf("Fundamental file system block size: %lu\n", buf.f_frsize);
                }

        exit(EXIT_SUCCESS);
}

Compile the whole thing with make blocks and run the program - e.g. "./blocks /dev/hda1".



Windows

fsutil fsinfo ntfsinfo <drive letter>

Have a look at the value of "Bytes Per Cluster".