[Previous]
[Contents]
[Next]

fsys_fdinfo()

query a resource manager for information about a file

Synopsis:

#include <sys/fsys.h>
int fsys_fdinfo( pid_t server,
                 pid_t pid,
                 int fd,
                 struct _fsys_info_entry *info );

Description:

The fsys_fdinfo() function queries the server (that is, resource manager) for information about the file associated with the descriptor fd that belongs to process pid.

If the specified pid/fd combination isn't found, the server returns information on the next highest fd for the same pid or if no higher fd exists, information for the lowest fd of a subsequent pid is returned.

On success, the structure pointed to by info contains at least the following members:

Type Member Description
mpid_t pid Process ID
short int fd File descriptor
off_t offset Current seek position
off_t fsize File size
short unsigned fflags Bitmask version of oflags. See <fcntl.h>.
short unsigned share Share mode; see <share.h>
char path[PATH_MAX + 1] Pathname of the file

Under some circumstances the pathname (that is, path) may not be known (for example, a pipe or a file for which all links have been removed). In such cases the server sets path to be a string such as:

Returns:

0
Success - the structure pointed to by info contains information about the first valid pid/fd combination found.

The pid and fd for which information is returned is specified in the structure. You may use this information (after incrementing the fd) to continue searching for further information on the same pid or other pids.

-1
Failure - errno is set, and the info structure isn't filled.

Errors:

ENOSYS
The fsys_fdinfo() function isn't supported for this fd.
EINVAL
No pid/fd combination was found.
ESRCH
The server pid doesn't exist.

Examples:

#include <sys/fsys.h>
#include <stdio.h>
#include <errno.h>
/*
 * Display information about a file
 * that is opened to the 'server'
 * by 'pid' with handle 'fd'
 */
void main( int argc, char *argv[] )
  {
    pid_t server, pid;
    int fd;
    struct _fsys_info_entry info;

    server = atoi( argv[1] );
    if( strcmp( argv[2], "all" ) == 0 ) {
      pid = 1;
      fd = 0;
      while( fsys_fdinfo( server, pid, fd, &info ) == 0 ) {
        printf( "%5d  %2d  %7ld/%7ld  %s\n",
          info.pid, info.fd, info.offset, info.fsize,
          info.path);
        pid = info.pid;
        fd = info.fd + 1;
      }
      if( errno != EINVAL )
        perror( "Can't obtain information" );
    } else {
      pid = atoi( argv[2] );
      fd = atoi( argv[3] );
      if( fsys_fdinfo( server, pid, fd, &info ) == 0 ) {
        printf( "Pid: %d, fd %d\n", info.pid, info.fd );
        printf( "is at offset %ld of %ld\n",
          info.offset, info.fsize );
        printf( "in file %s\n", info.path );
      } else
        perror( "Can't obtain information" );
    }
  }

Classification:

QNX

Safety:
Interrupt handler No
Signal handler Yes, but modifies errno
Thread Yes

See also:

errno, open(), dev_fdinfo()


[Previous]
[Contents]
[Next]