How can I get the filesystem sector size from unix/linux/osx and windows?

c, linux, macos, unix, windows

Solution

I think you want statvfs (if by pagesize you mean sector size?) which from what I remember works linux and OSX. I think you need to use the f_bsize field but I unfortunately do not have a linux box to test against atm.

For windows you want the GetDiskFreeSpace function.

Problem

I want to be able to determine at runtime what the sector size is for a give filesystem. C code is acceptable. for example I format my Data partitions with a 32k sector size that have lots of large video files. I want to be able to get this value at runtime.

Original source