I wanted to know a way to find out wich is the disk's block size through a function or a compiler constant in C..
thanks
I wanted to know a way to find out wich is the disk's block size through a function or a compiler constant in C..
thanks
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.
statvfs() reports on a filesystem. stat() reports on a given file. Almost always this is going to be the same, but since you asked for the result from a filesystem the correct answer for POSIX systems is to call statvfs().
I found another way to solve my problem.
There is a function at gcc that returns the page size.
I solved my problem using getpagesize()
printf("%d\n",getpagesize());