xref: /openbsd/lib/libkvm/kvm_getfiles.3 (revision e5dd7070)
1.\"	$OpenBSD: kvm_getfiles.3,v 1.19 2016/05/04 01:32:04 zhuk 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: May 4 2016 $
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.El
96.Pp
97Only the first
98.Fa elemsize
99bytes of each array entry are returned.
100If the size of the
101.Vt kinfo_file
102structure increases in size in a future release of
103.Ox ,
104the kernel will only return the requested amount of data for
105each array entry and programs that use
106.Fn kvm_getfiles
107will continue to function without the need for recompilation.
108.Sh RETURN VALUES
109The files are returned as a contiguous array of
110.Vt kinfo_file
111structures.
112The number of structures found is returned in the reference parameter
113.Fa cnt .
114This memory is owned by kvm and will be overwritten by subsequent calls to
115.Fn kvm_getfiles
116and destroyed by
117.Fn kvm_close .
118Data should be copied out if it needs to be saved.
119.Pp
120.Fn kvm_getfiles
121will return
122.Dv NULL
123on failure.
124.Sh ERRORS
125.Fn kvm_getfiles
126will fail if:
127.Bl -tag -width Er
128.It Bq Er ENOMEM
129Could not allocate enough memory for internal buffer.
130.It Bq Er ESRCH
131The
132.Fa op
133argument has
134.Dv KERN_FILE_BYPID
135value and the process specified by
136.Fa arg
137was not found.
138.El
139.Sh SEE ALSO
140.Xr kvm 3 ,
141.Xr kvm_geterr 3 ,
142.Xr kvm_nlist 3 ,
143.Xr kvm_open 3 ,
144.Xr kvm_read 3
145.Sh BUGS
146This routine does not belong in the kvm interface.
147