How can I get the filesystem sector size from unix/linux/osx and windows?
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 开发者_如何学JAVA32k sector size that have lots of large video files. I want to be able to get this value at runtime.
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.
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
int page_size = getpagesize();
printf("The page size is %d\n", page_size);
exit(0);
}
On Windows, call the GetSystemInfo() function
void WINAPI GetSystemInfo(
__out LPSYSTEM_INFO lpSystemInfo
);
Then access the dwPageSize value in the returned SYSTEM_INFO structure. This size is guaranteed to give file system page aligment. For example, use this size for reading and writing files in unbuffered mode.
If you need the volumen sector size, simply call GetDiskFreeSpace() function then read the lpBytesPerSector value.
精彩评论