Consultor Eletrônico



Kbase 18292: C Program to Determine Your File System Block Size
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   7/3/2009
Status: Verified

GOAL:

Sample C program which can be used to determine file system block size.

GOAL:

How to find the Operating System blocksize using a C program?

GOAL:

Finding the Operating blocksize using a C program?

GOAL:

How to programmatically check file system block size.

FACT(s) (Environment):

Unix

FIX:

On some UNIX Operating Systems, it can be difficult to determine the file system block size once it has been created.
On HP-UX you can get this information by the simple command:

df -g <mount point of file system>

Example: df -g /usr

If you cannot find any OS manual references on how to get the block size, try the C program below. 1) Use your editor to write and save fssize.c.
2) Compile with "cc fssize.c -o fssize" OR "make fssize".

/* fssize.c */

#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>

main(argc, argv)
int argc;
char *argv[];

{
int ret;
struct stat bur;

if (argc == 1)
{
ret = stat(argv[0], &bur);
}
else
{
ret = stat(argv[1], &bur);
}

if (ret < 0)

{
printf("stat failed, errno = %d\n",errno);
exit();
}

printf("File system block size is = %d\n",bur.st_blksize);
}
3) Run the generated executable fssize to get the file system block size.

NOTE: This program is NOT supported. It has been tested on several UNIX systems but may or may not compile and run on your system. See your UNIX manual if the stat() function fails.