w_statvfs() — Get the file system status

Standards

Standards / Extensions C or C++ Dependencies
z/OS® UNIX both  

Format

#define _OPEN_SOURCE 2
#include <sys/statvfs.h>

int w_statvfs(const char *filesystem, struct statvfs *buffer, size_t buflen);

General description

The w_statvfs() function gets status about a specific file system.
filesystem
The name of the file system for which status is being retrieved. This file system name can be one of the following:
  • The name specified in the FILESYSTEM parameter of the ROOT or MOUNT statements in the BPXPRMxx parmlib member.
  • The name specified in a TSO/E MOUNT command.
  • The name returned on a previous call to w_getmntent().
buffer
A buffer that the status information is put into. The information is returned in a statvfs structure, as defined in the sys/statvfs.h header file. The elements of this structure are described in statvfs() — Get file system information.
buflen
The length of the buffer. The length of the buffer and the length of the structure are compared, and the shorter of the two is used to determine how much information to return in the buffer.

If the buffer length is zero, only the return value is returned. A process can use a length of zero to detect if a file system exists or not.

Returned value

If successful, w_statvfs() returns the length of the data in the buffer.

If unsuccessful, w_statvfs() returns -1 and sets errno to one of the following values:
Error Code
Description
EINVAL
A parameter was specified incorrectly. For example, the file system name (filesystem) was not found.

Example

#define _OPEN_SOURCE 2
#include <sys/statvfs.h>
#include <stdio.h>

main() {
  char fs[]="POSIX.ROOT.FS";
  struct statvfs buf;

  if (w_statvfs(fs, &buf, sizeof(buf)) == -1)
    perror("w_statvfs() error");
  else {
    printf("each block in %s is %d bytes big\n", fs,
           buf.f_frsize);
    printf("there are %d blocks available out of a total of %d\n",
           buf.f_bavail, buf.f_blocks);
    printf("in bytes, that's %.0f bytes free out of a total of %.0f\n",
           ((double)buf.f_bavail * buf.f_frsize),
           ((double)buf.f_blocks * buf.f_frsize));
  }
}
Output:
each block in POSIX.ROOT.FS is 4096 bytes big
there are 2089 blocks available out of a total of 2400
in bytes, that's 8556544 bytes free out of a total of 9830400

Related information