Chapter Contents

Previous

Next
w_statfs

w_statfs



Get File System Status Information

Portability: SAS/C extension


SYNOPSIS
DESCRIPTION
RETURN VALUE
PORTABILITY
EXAMPLE
RELATED FUNCTIONS


SYNOPSIS

#include <sys/statfs.h>

int w_statfs(const char *fileSystem, struct w_statfs *statInfo,
             size_t infoSize);


DESCRIPTION

w_statfs gets file system status information. The following arguments are required:

fileSystem
is the name of the file system for which status information is to be provided. File system names can be obtained by using the w_getmntent function.

statInfo
is a pointer to a w_statfs structure that is declared in the <sys/statfs.h> header. The following elements of this structure provide file system status information:

int statfs_len
is the size of the w_statfs structure.

int statfs_blksize
is the block size for the file system.

unsigned int statfs_total_space
is the total number of blocks used by the file system.

unsigned int statfs_free_space
is the number of free blocks available to unprivileged users.

infoSize
specifies the number of bytes of information to be stored. If infoSize is larger than the size of the w_statfs structure, then all of the information is stored; if it is shorter than the structure, then only a portion of the information is stored; and if infoSize is 0 , then no information is stored. A value of 0 for infoSize may be used to test whether or not a file system exists.


RETURN VALUE

If successful, w_statfs returns the number of bytes stored. If infoSize is 0 , the total number of bytes of information available is returned. A -1 is returned if unsuccessful.


PORTABILITY

The w_statfs function may be useful in USS applications; however, it is not defined by the POSIX.1 standard and should not be used in portable applications.


EXAMPLE

The following example illustrates the use of w_statfs to obtain file system status information:

#include <sys/types.h>
#include <sys/statfs.h>
#include <sys/stat.h>
#include <string.h>
#include <stdio.h>
  
main()
{
   const char fileSys[] = "POSIX.FILE.SYSTEM";
   char *mountPoint = "/u/userid/dev";
   char *mountType = "HFS     ";
   struct w_statfs workArea;

      /* Initialize work area.               */
   memset(&workArea, 0x00, sizeof(workArea));

      /* Mount file system.                  */
   if (mount(mountPoint, fileSys, mountType, MTM_RDWR, 0, NULL) != 0)
      perror("error mounting file system");

      /* Get file system status information. */
   if (w_statfs(fileSys, &workArea, sizeof(workArea)) == -1)
      perror("w_statfs error");
   else
      printf("Length = %dn", workArea.statfs_len);
      printf("Block Size = %dn", workArea.statfs_blksize);
      printf("Blocks Used = %un", workArea.statfs_total_space);
      printf("Blocks Allocated = %un", workArea.statfs_used_space);
      printf("Free Space = %un", workArea.statfs_free_space);
}


RELATED FUNCTIONS

w_statfs , w_getmntent


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.