[comp.unix.xenix] SCO V2.3 fstatfs bug?

tmm33@leah.Albany.Edu (Terry McCoy) (09/30/89)

I having a problem with the values that are returned by system calls statfs and
fstatfs.  I am getting values for the size of one block in the file system as
4000000 Hex bytes.  Below is a small program that will demonstrate the problem.
If anyone has a fix or a work around to determine how many bytes are available
in the file system please let me know.

/* =============================================================================
This program looks at the file system and print out the number of free blocks
that are available and the size of the block, values are printed in HEX.  Also
the total amount of free space in the file system is printed in decimal.
============================================================================= */

    /*  Libraries to include  */
#include  <stdio.h>
#include  <sys/fcntl.h>
#include  <sys/types.h>
#include  <sys/statfs.h>

 int            fd_dummy;           /* file descriptor for the "dummy_file" */
 struct statfs  file_system;        /* structure of statics about file system */

main()
{
  if((fd_dummy = open("dummy_file", O_RDWR|O_CREAT|O_EXCL,0600)) != -1)
  {
    if(fstatfs(fd_dummy, &file_system, sizeof(struct statfs), 0) == 0)
    {
      printf("Looking at the file system\n");
      printf("Block size = %lx  Blocks free = %lx\n",
                                      file_system.f_bsize, file_system.f_bfree);
      printf("Amount of free disk space available = %ld\n",
                                   (file_system.f_bsize * file_system.f_bfree));
      close(fd_dummy);
      unlink("dummy_file");
    }
    else
      perror("Couldn't statics about file system");
  }
  else
    perror("Couldn't create/open the dummy file");
}

Terry McCoy
SUNY Albany National Lightning Detection Network
Research Foundation  -  State University of New York at Albany
------------------------------------------------------------------------------
internet:    tmm33@leah.albany.edu
Phone:       (518) 442-4588
Snail Mail:  Terry McCoy ES-235
             SUNY Albany
             1400 Washington Ave.
             Albany, NY 12222

cpcahil@virtech.UUCP (Conor P. Cahill) (09/30/89)

>       printf("Block size = %lx  Blocks free = %lx\n",
                             ^^^
>                                     file_system.f_bsize, file_system.f_bfree);

The f_bsize element of the statfs structure is a short, not a long.

-- 
+-----------------------------------------------------------------------+
| Conor P. Cahill     uunet!virtech!cpcahil      	703-430-9247	!
| Virtual Technologies Inc.,    P. O. Box 876,   Sterling, VA 22170     |
+-----------------------------------------------------------------------+