xref: /openbsd-src/lib/libkvm/kvm_getfiles.3 (revision 43003dfe3ad45d1698bed8a37f2b0f5b14f20d4f)
1.\"	$OpenBSD: kvm_getfiles.3,v 1.12 2009/06/07 03:09:34 millert 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: June 7 2009 $
38.Dt KVM_GETFILES 3
39.Os
40.Sh NAME
41.Nm kvm_getfiles
42.Nd survey open files
43.Sh SYNOPSIS
44.Fd #include <kvm.h>
45.Fd #include <sys/types.h>
46.Fd #define _KERNEL
47.Fd #include <sys/file.h>
48.Fd #undef _KERNEL
49.\" .Fa kvm_t *kd
50.Ft char *
51.Fn kvm_getfiles "kvm_t *kd" "int op" "int arg" "int *cnt"
52.Ft struct kinfo_file2 *
53.Fn kvm_getfile2 "kvm_t *kd" "int op" "int arg" "size_t elemsize" "int *cnt"
54.Sh DESCRIPTION
55.Fn kvm_getfiles
56returns a (sub-)set of the open files in the kernel indicated by
57.Fa kd .
58The
59.Fa op
60and
61.Fa arg
62arguments constitute a predicate which limits the set of files
63returned.
64No predicates are currently defined.
65.Pp
66The number of processes found is returned in the reference parameter
67.Fa cnt .
68The files are returned as a contiguous array of file structures,
69preceded by the address of the first file entry in the kernel.
70This memory is owned by kvm and is not guaranteed to be persistent across
71subsequent kvm library calls.
72Data should be copied out if it needs to be saved.
73.Pp
74.Fn kvm_getfile2
75is similar to
76.Fn kvm_getfiles
77but returns an array of
78.Vt kinfo_file2
79structures.
80Additionally, only the first
81.Fa elemsize
82bytes of each array entry are returned.
83If the size of the
84.Vt kinfo_file2
85structure increases in size in a future release of
86.Ox ,
87the kernel will only return the requested amount of data for
88each array entry and programs that use
89.Fn kvm_getfile2
90will continue to function without the need for recompilation.
91The
92.Fa op
93and
94.Fa arg
95arguments constitute a predicate which limits the set of processes returned.
96The value of
97.Fa op
98describes the filtering predicate as follows:
99.Pp
100.Bl -tag -width 20n -offset indent -compact
101.It Dv KERN_FILE_BYFILE
102all open files
103.It Dv KERN_PROC_BYPID
104files opened by process ID
105.Fa arg
106(\-1 for all processes)
107.It Dv KERN_FILE_BYUID
108files opened by processes with effective user ID
109.Fa arg
110.El
111.Pp
112Files associated with a process will include information about
113the process that has the file open.
114.Pp
115The files are returned as a contiguous array of
116.Vt kinfo_file2
117structures.
118The number of structures found is returned in the reference parameter
119.Fa cnt .
120This memory is owned by kvm and will be overwritten by subsequent calls to
121.Fn kvm_getfile2
122and destroyed by
123.Fn kvm_close .
124Data should be copied out if it needs to be saved.
125.Sh RETURN VALUES
126.Fn kvm_getfiles
127and
128.Fn kvm_getfile2
129will return
130.Dv NULL
131on failure.
132.Sh SEE ALSO
133.Xr kvm 3 ,
134.Xr kvm_close 3 ,
135.Xr kvm_geterr 3 ,
136.Xr kvm_nlist 3 ,
137.Xr kvm_open 3 ,
138.Xr kvm_openfiles 3 ,
139.Xr kvm_read 3 ,
140.Xr kvm_write 3
141.Sh BUGS
142This routine does not belong in the kvm interface.
143