NAME
kvm_getfiles
—
survey open files
SYNOPSIS
#include <kvm.h>
#include <sys/types.h>
#include <sys/sysctl.h>
struct kinfo_file *
kvm_getfiles
(kvm_t
*kd, int op,
int arg,
size_t elemsize,
int *cnt);
DESCRIPTION
kvm_getfiles
()
returns a (sub-)set of the open files in the kernel indicated by
kd. The op and
arg arguments constitute a predicate which limits the
set of files returned. The value of op describes the
filtering predicate as follows:
KERN_FILE_BYFILE
- all open files with type arg (0 for all files)
KERN_FILE_BYPID
- files opened by process ID arg (-1 for all processes)
KERN_FILE_BYUID
- files opened by processes with effective user ID arg (-1 for all users)
Files associated with a process will include information about the process that has the file open.
For KERN_FILE_BYFILE
the recognized file
types are defined in
<sys/file.h>
:
DTYPE_VNODE
- files and devices
DTYPE_SOCKET
- sockets, regardless of domain
DTYPE_PIPE
- pipes and FIFOs
DTYPE_KQUEUE
- kqueues
Only the first elemsize
bytes of each array entry are returned. If the size of the
kinfo_file structure increases in size in a future
release of OpenBSD, the kernel will only return the
requested amount of data for each array entry and programs that use
kvm_getfiles
()
will continue to function without the need for recompilation.
RETURN VALUES
The files are returned as a contiguous array of
kinfo_file structures. The number of structures found
is returned in the reference parameter cnt. This
memory is owned by kvm and will be overwritten by subsequent calls to
kvm_getfiles
() and destroyed by
kvm_close
(). Data should be copied out if it needs
to be saved.
kvm_getfiles
() will return
NULL
on failure.
ERRORS
kvm_getfiles
() will fail if:
- [
ENOMEM
] - Could not allocate enough memory for internal buffer.
- [
ESRCH
] - The op argument has
KERN_FILE_BYPID
value and the process specified by arg was not found.
SEE ALSO
kvm(3), kvm_geterr(3), kvm_nlist(3), kvm_open(3), kvm_read(3)
BUGS
This routine does not belong in the kvm interface.