I am working on a high-performance I / O program, and I am trying to find a better way to determine the physical (rather than logical) size of the bytes of the deviceโs disk blocks using C ++. My research so far has led me to the following piece of code:
#include <iostream>
#include <sys/stat.h>
#include <stdio.h>
#include <errno.h>
int main(int argc, char ** argv)
{
struct stat info;
char * device = "/mnt/hdb1";
if (stat(device, &info))
{
printf("stat() error");
strerror(errno);
exit(1);
}
printf("Prefered block size for '%s' is %i byte\n", device, info.st_blksize);
return 0;
}
The man pages say the following about st_blksize:
The st_blksize field gives the "preferred" block size for efficient file system I / O. (Writing to a file in smaller fragments can result in inefficient read-modify-rewrite.)
but does not mention that st_blksizeis the size of a logical or physical disk.
, st_blksize, , POSIX OS .
user152949