fstatvfs()--Get File System Information by Descriptor


  Syntax
 #include <sys/statvfs.h>

 int fstatvfs(int fildes, struct statvfs *buf);  
  Service Program Name: QP0LLIB1

  Default Public Authority: *USE

  Threadsafe: Conditional; see Usage Notes.

The fstatvfs() function gets status information about the file system that contains the file referenced by the open file descriptor fildes. The information is stored in the area of memory indicated by the buf argument. The status information is returned in a statvfs structure, as defined in the <sys/statvfs.h> header file.


Parameters

fildes
(Input) The file descriptor of the file from which file system information is required.
buf
(Output) A pointer to the area to which the information should be written.

The elements of the statvfs structure are described in statvfs()--Get File System Information. Signed fields of the statvfs structure that are not supported by the mounted file system will be set to -1.

Authorities

Start of change No authorization is required. End of change



Return Value

0
fstatvfs() was successful. The information is returned in buf.
-1
fstatvfs() was not successful. The errno global variable is set to indicate the error.

Error Conditions

If fstatvfs() is not successful, errno usually indicates one of the following errors. Under some conditions, errno could indicate an error other than those listed here.

Error condition Additional information
[EACCES]

If you are accessing a remote file through the Network File System, update operations to file permissions at the server are not reflected at the client until updates to data that is stored locally by the Network File System take place. (Several options on the Add Mounted File System (ADDMFS) command determine the time between refresh operations of local data.) Access to a remote file may also fail due to different mappings of user IDs (UID) or group IDs (GID) on the local and remote systems.

[EAGAIN]  
[EBADF]  
[EBADFID]  
[EBADNAME]  
[EBUSY]  
[ECONVERT]  
[EDAMAGE]  
[EFAULT]  
[EFILECVT]  
[EINTR]  
[EINVAL]  
[EIO]  
[ELOOP]  
[ENAMETOOLONG]  
[ENOENT]  
[ENOMEM]  
[ENOSPC]  
[ENOTAVAIL]  
[ENOTDIR]  
[ENOTSAFE]  
[EPERM]  
[ESTALE]

If you are accessing a remote file through the Network File System, the file may have been deleted at the server.

[EUNKNOWN]  

If interaction with a file server is required to access the object, errno could indicate one of the following errors:

Error condition Additional information
[EADDRNOTAVAIL]  
[ECONNABORTED]  
[ECONNREFUSED]  
[ECONNRESET]  
[EHOSTDOWN]  
[EHOSTUNREACH]  
[ENETDOWN]  
[ENETRESET]  
[ENETUNREACH]  
[ESTALE]

If you are accessing a remote file through the Network File System, the file may have been deleted at the server.

[ETIMEDOUT]  
[EUNATCH]  


Error Messages

The following messages may be sent from this function:

Message ID Error Message Text
CPE3418 E Possible APAR condition or hardware failure.
CPFA0D4 E File system error occurred. Error number &1.
CPF3CF2 E Error(s) occurred during running of &1 API.
CPF9872 E Program or service program &1 in library &2 ended. Reason code &3.


Usage Notes

  1. This function will fail with error code [ENOTSAFE] when all the following conditions are true:
  2. "Root" (/) and QOpenSys File System Differences

    These file systems return the f_flag field with the ST_NOSUID flag bit turned off. However, support for the setuid/setgid semantics is limited to the ability to store and retrieve the S_ISUID and S_ISGID flags when these file systems are accessed from the Network File System server.


  3. Network File System Differences

    Local access to remote files through the Network File System may produce unexpected results due to conditions at the server. Once a file is open, subsequent requests to perform operations on the file can fail because file attributes are checked at the server on each request. If permissions on the file are made more restrictive at the server or the file is unlinked or made unavailable by the server for another client, your operation on an open file descriptor will fail when the local Network File System receives these updates. The local Network File System also impacts operations that retrieve file attributes. Recent changes at the server may not be available at your client yet, and old values may be returned from operations. (Several options on the Add Mounted File System (ADDMFS) command determine the time between refresh operations of local data.)


  4. When you develop in C-based languages and an application is compiled with the _LARGE_FILES macro defined, the fstatvfs() API will be mapped to a call to the fstatvfs64(). Additionally, the struct statvfs data type will be mapped to a struct statvfs64.

Related Information


Example

See Code disclaimer information for information pertaining to code examples.

The following example gets status information about a file system:

#include <sys/statvfs.h>
#include <stdio.h>

main() {
  struct statvfs info;
  int fildes;

  if (-1 == (fildes = open("/",O_RDONLY)))
    perror("open() error");
  else if (-1 == fstatvfs(fildes, &info))
      perror("fstatvfs() error");
  else {
    puts("fstatvfs() returned the following information");
    puts("about the Root ('/') file system:");
    printf("  f_bsize    : %u\n", info.f_bsize);
    printf("  f_blocks   : %08X%08X\n",
                           *((int *)&info.f_blocks[0]),
                           *((int *)&info.f_blocks[4]));
    printf("  f_bfree    : %08X%08X\n",
                           *((int *)&info.f_bfree[0]),
                           *((int *)&info.f_bfree[4]));
    printf("  f_files    : %u\n", info.f_files);
    printf("  f_ffree    : %u\n", info.f_ffree);
    printf("  f_fsid     : %u\n", info.f_fsid);
    printf("  f_flag     : %X\n", info.f_flag);
    printf("  f_namemax  : %u\n", info.f_namemax);
    printf("  f_pathmax  : %u\n", info.f_pathmax);
    printf("  f_basetype : %s\n", info.f_basetype);
  }
}

Output: The following information will vary from file system to file system.

statvfs() returned the following information
about the Root ('/') file system:
  f_bsize    : 4096
  f_blocks   : 00000000002BF800
  f_bfree    : 0000000000091703
  f_files    : 4294967295
  f_ffree    : 4294967295
  f_fsid     : 0
  f_flag     : 1A
  f_namemax  : 255
  f_pathmax  : 4294967295
  f_basetype : "root" (/)


API introduced: V4R2
Top | UNIX-Type APIs | APIs by category