xref: /openbsd/lib/libkvm/kvm_getfiles.3 (revision 8529ddd3)
1.\"	$OpenBSD: kvm_getfiles.3,v 1.17 2015/02/11 03:03:08 guenther Exp $
2.\"	$NetBSD: kvm_getfiles.3,v 1.3 1996/03/18 22:33:23 thorpej Exp $
3.\"
4.\" Copyright (c) 1992, 1993
5.\"	The Regents of the University of California.  All rights reserved.
6.\"
7.\" This code is derived from software developed by the Computer Systems
8.\" Engineering group at Lawrence Berkeley Laboratory under DARPA contract
9.\" BG 91-66 and contributed to Berkeley.
10.\"
11.\" Redistribution and use in source and binary forms, with or without
12.\" modification, are permitted provided that the following conditions
13.\" are met:
14.\" 1. Redistributions of source code must retain the above copyright
15.\"    notice, this list of conditions and the following disclaimer.
16.\" 2. Redistributions in binary form must reproduce the above copyright
17.\"    notice, this list of conditions and the following disclaimer in the
18.\"    documentation and/or other materials provided with the distribution.
19.\" 3. Neither the name of the University nor the names of its contributors
20.\"    may be used to endorse or promote products derived from this software
21.\"    without specific prior written permission.
22.\"
23.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33.\" SUCH DAMAGE.
34.\"
35.\"     @(#)kvm_getfiles.3	8.2 (Berkeley) 4/19/94
36.\"
37.Dd $Mdocdate: February 11 2015 $
38.Dt KVM_GETFILES 3
39.Os
40.Sh NAME
41.Nm kvm_getfiles
42.Nd survey open files
43.Sh SYNOPSIS
44.In kvm.h
45.In sys/types.h
46.In sys/sysctl.h
47.Ft struct kinfo_file *
48.Fn kvm_getfiles "kvm_t *kd" "int op" "int arg" "size_t elemsize" "int *cnt"
49.Sh DESCRIPTION
50.Fn kvm_getfiles
51returns a (sub-)set of the open files in the kernel indicated by
52.Fa kd .
53The
54.Fa op
55and
56.Fa arg
57arguments constitute a predicate which limits the set of files
58returned.
59The value of
60.Fa op
61describes the filtering predicate as follows:
62.Pp
63.Bl -tag -width 20n -offset indent -compact
64.It Dv KERN_FILE_BYFILE
65all open files with type
66.Fa arg
67(0 for all files)
68.It Dv KERN_FILE_BYPID
69files opened by process ID
70.Fa arg
71(\-1 for all processes)
72.It Dv KERN_FILE_BYUID
73files opened by processes with effective user ID
74.Fa arg
75(\-1 for all users)
76.El
77.Pp
78Files associated with a process will include information about
79the process that has the file open.
80.Pp
81For
82.Dv KERN_FILE_BYFILE
83the recognized file types are defined in
84.In sys/file.h :
85.Pp
86.Bl -tag -width 20n -offset indent -compact
87.It Dv DTYPE_VNODE
88files and devices
89.It Dv DTYPE_SOCKET
90sockets, regardless of domain
91.It Dv DTYPE_PIPE
92pipes and FIFOs
93.It Dv DTYPE_KQUEUE
94kqueues
95.It Dv DTYPE_SYSTRACE
96systrace control files
97.El
98.Pp
99Only the first
100.Fa elemsize
101bytes of each array entry are returned.
102If the size of the
103.Vt kinfo_file
104structure increases in size in a future release of
105.Ox ,
106the kernel will only return the requested amount of data for
107each array entry and programs that use
108.Fn kvm_getfiles
109will continue to function without the need for recompilation.
110.Pp
111The files are returned as a contiguous array of
112.Vt kinfo_file
113structures.
114The number of structures found is returned in the reference parameter
115.Fa cnt .
116This memory is owned by kvm and will be overwritten by subsequent calls to
117.Fn kvm_getfiles
118and destroyed by
119.Fn kvm_close .
120Data should be copied out if it needs to be saved.
121.Sh RETURN VALUES
122.Fn kvm_getfiles
123will return
124.Dv NULL
125on failure.
126.Sh SEE ALSO
127.Xr kvm 3 ,
128.Xr kvm_geterr 3 ,
129.Xr kvm_nlist 3 ,
130.Xr kvm_open 3 ,
131.Xr kvm_read 3
132.Sh BUGS
133This routine does not belong in the kvm interface.
134