* Copyright (c) 1989 The Regents of the University of California.
* %sccs.include.redist.c%
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid
[] = "@(#)kvm_file.c 5.1 (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
* File list interface for kvm. pstat, fstat and netstat are
* users of this code, so we've factored it out into a separate module.
* Thus, we keep this grunge out of the other kvm applications (i.e.,
* most other applications are interested only in open/close/read/nlist).
#include <vm/swap_pager.h>
#define KREAD(kd, addr, obj) \
(kvm_read(kd, addr, (char *)(obj), sizeof(*obj)) != sizeof(*obj))
kvm_deadfiles(kd
, op
, arg
, filehead_o
, nfiles
)
int buflen
= kd
->arglen
, needed
= buflen
, error
, n
= 0;
struct file
*fp
, file
, *filehead
;
register char *where
= kd
->argspc
;
if (buflen
> sizeof (filehead
)) {
if (KREAD(kd
, filehead_o
, &filehead
)) {
_kvm_err(kd
, kd
->program
, "can't read filehead");
buflen
-= sizeof (filehead
);
where
+= sizeof (filehead
);
*(struct file
**)kd
->argspc
= filehead
;
* followed by an array of file structures
for (fp
= filehead
; fp
!= NULL
; fp
= fp
->f_filef
) {
if (buflen
> sizeof (struct file
)) {
if (KREAD(kd
, (off_t
)fp
, ((struct file
*)where
))) {
_kvm_err(kd
, kd
->program
, "can't read kfp");
buflen
-= sizeof (struct file
);
where
+= sizeof (struct file
);
_kvm_err(kd
, kd
->program
, "inconsistant nfiles");
kvm_getfiles(kd
, op
, arg
, cnt
)
struct file
*filehead
, *fp
, *fplim
;
st
= getkerninfo(op
, NULL
, &size
, arg
);
_kvm_syserr(kd
, kd
->program
, "kvm_getprocs");
kd
->argspc
= (char *)_kvm_malloc(kd
, st
);
else if (kd
->arglen
< st
)
kd
->argspc
= (char *)_kvm_realloc(kd
, kd
->argspc
, st
);
st
= getkerninfo(op
, kd
->argspc
, &size
, arg
);
if (st
< sizeof(filehead
)) {
_kvm_syserr(kd
, kd
->program
, "kvm_getfiles");
filehead
= *(struct file
**)kd
->argspc
;
fp
= (struct file
*)(kd
->argspc
+ sizeof (filehead
));
fplim
= (struct file
*)(kd
->argspc
+ size
);
for (nfiles
= 0; filehead
&& (fp
< fplim
); nfiles
++, fp
++)
nl
[0].n_name
= "_filehead";
nl
[1].n_name
= "_nfiles";
if (kvm_nlist(kd
, nl
) != 0) {
for (p
= nl
; p
->n_type
!= 0; ++p
)
_kvm_err(kd
, kd
->program
,
"%s: no such symbol", p
->n_name
);
if (KREAD(kd
, nl
[0].n_value
, &nfiles
)) {
_kvm_err(kd
, kd
->program
, "can't read nfiles");
size
= sizeof(filehead
) + (nfiles
+ 10) * sizeof(struct file
);
kd
->argspc
= (char *)_kvm_malloc(kd
, st
);
else if (kd
->arglen
< st
)
kd
->argspc
= (char *)_kvm_realloc(kd
, kd
->argspc
, st
);
nfiles
= kvm_deadfiles(kd
, op
, arg
, nl
[1].n_value
, nfiles
);