w_statfs() — Get the file system status

Standards

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

Format

#include <sys/statfs.h>

int w_statfs(const char *filesystem, struct w_statfs *statbuf, size_t length);

General description

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().
statbuf
A buffer that the status information is put into. The status information is mapped by the sys/statfs.h header file.
int statfs_len
Length of statfs
int statfs_blksize
Block size
unsigned int statfs_total_space
Total space in block size units
unsigned int statfs_used_space
Allocated space in block size units
unsigned int statfs_free_space
Space available to unprivileged users in block size units
length
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.

Special behavior for XPG4.2: w_statfs() is replaced by w_statvfs().

Returned value

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

If unsuccessful, w_statfs() returns -1 and sets errno to one of the following values:
Error Code
Description
EINVAL
A parameter was incorrectly specified.

Example

CELEBW36
⁄* CELEBW36 *⁄
#define _OPEN_SYS
#include <sys⁄statfs.h>
#include <stdio.h>

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

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

Related information