1.\" $OpenBSD: kvm_getfiles.3,v 1.16 2013/10/22 16:40:27 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: October 22 2013 $ 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 66.It Dv KERN_FILE_BYPID 67files opened by process ID 68.Fa arg 69(\-1 for all processes) 70.It Dv KERN_FILE_BYUID 71files opened by processes with effective user ID 72.Fa arg 73.El 74.Pp 75Files associated with a process will include information about 76the process that has the file open. 77.Pp 78Only the first 79.Fa elemsize 80bytes of each array entry are returned. 81If the size of the 82.Vt kinfo_file 83structure increases in size in a future release of 84.Ox , 85the kernel will only return the requested amount of data for 86each array entry and programs that use 87.Fn kvm_getfiles 88will continue to function without the need for recompilation. 89.Pp 90The files are returned as a contiguous array of 91.Vt kinfo_file 92structures. 93The number of structures found is returned in the reference parameter 94.Fa cnt . 95This memory is owned by kvm and will be overwritten by subsequent calls to 96.Fn kvm_getfiles 97and destroyed by 98.Fn kvm_close . 99Data should be copied out if it needs to be saved. 100.Sh RETURN VALUES 101.Fn kvm_getfiles 102will return 103.Dv NULL 104on failure. 105.Sh SEE ALSO 106.Xr kvm 3 , 107.Xr kvm_geterr 3 , 108.Xr kvm_nlist 3 , 109.Xr kvm_open 3 , 110.Xr kvm_read 3 111.Sh BUGS 112This routine does not belong in the kvm interface. 113