user177800
user177800

Reputation:

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 32k sector size that have lots of large video files. I want to be able to get this value at runtime.

Upvotes: 4

Views: 3236

Answers (3)

Foredecker
Foredecker

Reputation: 7491

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.

Upvotes: 2

tyranid
tyranid

Reputation: 13318

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.

Upvotes: 4

ennuikiller
ennuikiller

Reputation: 46985

#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);
}

Upvotes: 2

Related Questions