I wanted to know a way to find out what the disk's block size is through a function or a compiler constant in C.
In a file system, a block is the largest contiguous amount of disk space that can be allocated to a file and also the largest amount of data that can be transferred in a single I/O operation. The block size determines the maximum size of a read request or write request that a file system sends to the I/O device driver.
Use the lsmem command to find out the size of your memory blocks. In the example, the block size is 256 MB. Alternatively, you can read /sys/devices/system/memory/block_size_bytes. This sysfs attribute contains the block size in byte in hexadecimal notation.
The dd command reports on the number of blocks it reads and writes. The number after the + is a count of the partial blocks that were copied. The default block size is 512 bytes.
The info about you using gcc compiler is not interesting, since compilers are not interested in the block size of the filesystem, they are not even aware of the fact that a filesystem can exist... the answer is system specific (MS Windows? GNU/Linux or other *nix/*nix like OS?); on POSIX you have the stat
function, you can use it to have the stat struct, which contains the field st_blksize
(blocksize for filesystem I/O) which could be what you're interested in.
ADD
Example
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
int main()
{
struct stat fi;
stat("/", &fi);
printf("%d\n", fi.st_blksize);
return 0;
}
Tells you about the filesystem used on / (root); e.g. for me, it outputs 4096.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With