View Single Post
Old 09-01-2007, 07:10 PM   #2
HCL Maintainer
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 76
I think some versions of dumpfs or equivalent will emit this information, though the utility is filesystem-specific (e.g., for ext2, you could use “dumpe2fs -h /path/to/block/device”). I don’t think there is any standard utility that does this for any filesystem, although I’m not sure why not. For example, you could do this (which is portable across all POSIX systems):
#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("File system block size: %lu\n", buf.f_bsize);
	printf("Fundamental file system block size: %lu\n", buf.f_frsize);

Compile the program with “make blocks” (assuming you call it “blocks.c”). Then just run the program as “./blocks /path/to/mountpoint” (notice that the path is not to the block device, but to the mountpoint — e.g., instead of “/dev/sda1” use “/usr”).