xref: /openbsd-src/lib/libkvm/kvm_getfiles.3 (revision 871d93bc08c063bba3b3e8b8d1caee986a057a7d)
1*871d93bcSzhuk.\"	$OpenBSD: kvm_getfiles.3,v 1.19 2016/05/04 01:32:04 zhuk Exp $
215f0ebb0Sderaadt.\"	$NetBSD: kvm_getfiles.3,v 1.3 1996/03/18 22:33:23 thorpej Exp $
315f0ebb0Sderaadt.\"
4df930be7Sderaadt.\" Copyright (c) 1992, 1993
5df930be7Sderaadt.\"	The Regents of the University of California.  All rights reserved.
6df930be7Sderaadt.\"
7df930be7Sderaadt.\" This code is derived from software developed by the Computer Systems
8df930be7Sderaadt.\" Engineering group at Lawrence Berkeley Laboratory under DARPA contract
9df930be7Sderaadt.\" BG 91-66 and contributed to Berkeley.
10df930be7Sderaadt.\"
11df930be7Sderaadt.\" Redistribution and use in source and binary forms, with or without
12df930be7Sderaadt.\" modification, are permitted provided that the following conditions
13df930be7Sderaadt.\" are met:
14df930be7Sderaadt.\" 1. Redistributions of source code must retain the above copyright
15df930be7Sderaadt.\"    notice, this list of conditions and the following disclaimer.
16df930be7Sderaadt.\" 2. Redistributions in binary form must reproduce the above copyright
17df930be7Sderaadt.\"    notice, this list of conditions and the following disclaimer in the
18df930be7Sderaadt.\"    documentation and/or other materials provided with the distribution.
196580fee3Smillert.\" 3. Neither the name of the University nor the names of its contributors
20df930be7Sderaadt.\"    may be used to endorse or promote products derived from this software
21df930be7Sderaadt.\"    without specific prior written permission.
22df930be7Sderaadt.\"
23df930be7Sderaadt.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24df930be7Sderaadt.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25df930be7Sderaadt.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26df930be7Sderaadt.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27df930be7Sderaadt.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28df930be7Sderaadt.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29df930be7Sderaadt.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30df930be7Sderaadt.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31df930be7Sderaadt.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32df930be7Sderaadt.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33df930be7Sderaadt.\" SUCH DAMAGE.
34df930be7Sderaadt.\"
35df930be7Sderaadt.\"     @(#)kvm_getfiles.3	8.2 (Berkeley) 4/19/94
36df930be7Sderaadt.\"
37*871d93bcSzhuk.Dd $Mdocdate: May 4 2016 $
38df930be7Sderaadt.Dt KVM_GETFILES 3
39df930be7Sderaadt.Os
40df930be7Sderaadt.Sh NAME
41df930be7Sderaadt.Nm kvm_getfiles
42df930be7Sderaadt.Nd survey open files
43df930be7Sderaadt.Sh SYNOPSIS
4486f9d4cdStedu.In kvm.h
4586f9d4cdStedu.In sys/types.h
46cef0bbe1Sguenther.In sys/sysctl.h
47cef0bbe1Sguenther.Ft struct kinfo_file *
48cef0bbe1Sguenther.Fn kvm_getfiles "kvm_t *kd" "int op" "int arg" "size_t elemsize" "int *cnt"
49df930be7Sderaadt.Sh DESCRIPTION
50df930be7Sderaadt.Fn kvm_getfiles
51df930be7Sderaadtreturns a (sub-)set of the open files in the kernel indicated by
52df930be7Sderaadt.Fa kd .
53df930be7SderaadtThe
54df930be7Sderaadt.Fa op
55df930be7Sderaadtand
56df930be7Sderaadt.Fa arg
57df930be7Sderaadtarguments constitute a predicate which limits the set of files
582bb07095Saaronreturned.
599dc8fca8SmillertThe value of
609dc8fca8Smillert.Fa op
619dc8fca8Smillertdescribes the filtering predicate as follows:
629dc8fca8Smillert.Pp
639dc8fca8Smillert.Bl -tag -width 20n -offset indent -compact
649dc8fca8Smillert.It Dv KERN_FILE_BYFILE
654aba674dSguentherall open files with type
664aba674dSguenther.Fa arg
674aba674dSguenther(0 for all files)
68e79425c8Sguenther.It Dv KERN_FILE_BYPID
699dc8fca8Smillertfiles opened by process ID
709dc8fca8Smillert.Fa arg
719dc8fca8Smillert(\-1 for all processes)
729dc8fca8Smillert.It Dv KERN_FILE_BYUID
739dc8fca8Smillertfiles opened by processes with effective user ID
749dc8fca8Smillert.Fa arg
754aba674dSguenther(\-1 for all users)
769dc8fca8Smillert.El
779dc8fca8Smillert.Pp
789dc8fca8SmillertFiles associated with a process will include information about
799dc8fca8Smillertthe process that has the file open.
809dc8fca8Smillert.Pp
814aba674dSguentherFor
824aba674dSguenther.Dv KERN_FILE_BYFILE
834aba674dSguentherthe recognized file types are defined in
844aba674dSguenther.In sys/file.h :
854aba674dSguenther.Pp
864aba674dSguenther.Bl -tag -width 20n -offset indent -compact
874aba674dSguenther.It Dv DTYPE_VNODE
884aba674dSguentherfiles and devices
894aba674dSguenther.It Dv DTYPE_SOCKET
904aba674dSguenthersockets, regardless of domain
914aba674dSguenther.It Dv DTYPE_PIPE
924aba674dSguentherpipes and FIFOs
934aba674dSguenther.It Dv DTYPE_KQUEUE
944aba674dSguentherkqueues
954aba674dSguenther.El
964aba674dSguenther.Pp
97cef0bbe1SguentherOnly the first
98cef0bbe1Sguenther.Fa elemsize
99cef0bbe1Sguentherbytes of each array entry are returned.
100cef0bbe1SguentherIf the size of the
101cef0bbe1Sguenther.Vt kinfo_file
102cef0bbe1Sguentherstructure increases in size in a future release of
103cef0bbe1Sguenther.Ox ,
104cef0bbe1Sguentherthe kernel will only return the requested amount of data for
105cef0bbe1Sguenthereach array entry and programs that use
106cef0bbe1Sguenther.Fn kvm_getfiles
107cef0bbe1Sguentherwill continue to function without the need for recompilation.
108*871d93bcSzhuk.Sh RETURN VALUES
1099dc8fca8SmillertThe files are returned as a contiguous array of
110cef0bbe1Sguenther.Vt kinfo_file
1119dc8fca8Smillertstructures.
1129dc8fca8SmillertThe number of structures found is returned in the reference parameter
1139dc8fca8Smillert.Fa cnt .
1149dc8fca8SmillertThis memory is owned by kvm and will be overwritten by subsequent calls to
115cef0bbe1Sguenther.Fn kvm_getfiles
1169dc8fca8Smillertand destroyed by
1179dc8fca8Smillert.Fn kvm_close .
1189dc8fca8SmillertData should be copied out if it needs to be saved.
119*871d93bcSzhuk.Pp
120df930be7Sderaadt.Fn kvm_getfiles
12102ecd0d2Saaronwill return
12202ecd0d2Saaron.Dv NULL
12302ecd0d2Saaronon failure.
124*871d93bcSzhuk.Sh ERRORS
125*871d93bcSzhuk.Fn kvm_getfiles
126*871d93bcSzhukwill fail if:
127*871d93bcSzhuk.Bl -tag -width Er
128*871d93bcSzhuk.It Bq Er ENOMEM
129*871d93bcSzhukCould not allocate enough memory for internal buffer.
130*871d93bcSzhuk.It Bq Er ESRCH
131*871d93bcSzhukThe
132*871d93bcSzhuk.Fa op
133*871d93bcSzhukargument has
134*871d93bcSzhuk.Dv KERN_FILE_BYPID
135*871d93bcSzhukvalue and the process specified by
136*871d93bcSzhuk.Fa arg
137*871d93bcSzhukwas not found.
138*871d93bcSzhuk.El
139df930be7Sderaadt.Sh SEE ALSO
140df930be7Sderaadt.Xr kvm 3 ,
141350bb3b8Salex.Xr kvm_geterr 3 ,
142350bb3b8Salex.Xr kvm_nlist 3 ,
143df930be7Sderaadt.Xr kvm_open 3 ,
144376bc393Sjmc.Xr kvm_read 3
145cdafad35Sjmc.Sh BUGS
146cdafad35SjmcThis routine does not belong in the kvm interface.
147