pstat.c (5f9ab4b0014130cc2f2bf2787480bc3f6d68020f) pstat.c (eeebf53e244286e35ddfa05ba2c1b5d2936b4e83)
1/*-
2 * Copyright (c) 1980, 1991, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 2002 Networks Associates Technologies, Inc.
5 * All rights reserved.
6 *
7 * Portions of this software were developed for the FreeBSD Project by
8 * ThinkSec AS and NAI Labs, the Security Research Division of Network

--- 40 unchanged lines hidden (view full) ---

49static char sccsid[] = "@(#)pstat.c 8.16 (Berkeley) 5/9/95";
50#endif
51static const char rcsid[] =
52 "$FreeBSD$";
53#endif /* not lint */
54
55#include <sys/param.h>
56#include <sys/time.h>
1/*-
2 * Copyright (c) 1980, 1991, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 2002 Networks Associates Technologies, Inc.
5 * All rights reserved.
6 *
7 * Portions of this software were developed for the FreeBSD Project by
8 * ThinkSec AS and NAI Labs, the Security Research Division of Network

--- 40 unchanged lines hidden (view full) ---

49static char sccsid[] = "@(#)pstat.c 8.16 (Berkeley) 5/9/95";
50#endif
51static const char rcsid[] =
52 "$FreeBSD$";
53#endif /* not lint */
54
55#include <sys/param.h>
56#include <sys/time.h>
57#define _KERNEL
58#include <sys/file.h>
57#include <sys/file.h>
59#include <sys/uio.h>
60#undef _KERNEL
61#include <sys/stat.h>
62#include <sys/stdint.h>
63#include <sys/ioctl.h>
64#include <sys/ioctl_compat.h> /* XXX NTTYDISC is too well hidden */
65#include <sys/tty.h>
66#include <sys/conf.h>
67#include <sys/blist.h>
68

--- 301 unchanged lines hidden (view full) ---

370 (void)printf("%d\n", xt->xt_line);
371 break;
372 }
373}
374
375static void
376filemode(void)
377{
58#include <sys/stat.h>
59#include <sys/stdint.h>
60#include <sys/ioctl.h>
61#include <sys/ioctl_compat.h> /* XXX NTTYDISC is too well hidden */
62#include <sys/tty.h>
63#include <sys/conf.h>
64#include <sys/blist.h>
65

--- 301 unchanged lines hidden (view full) ---

367 (void)printf("%d\n", xt->xt_line);
368 break;
369 }
370}
371
372static void
373filemode(void)
374{
378 struct file *fp;
379 struct file *addr;
375 struct xfile *fp;
380 char *buf, flagbuf[16], *fbp;
381 int maxf, openf;
382 size_t len;
383 static char *dtypes[] = { "???", "inode", "socket" };
376 char *buf, flagbuf[16], *fbp;
377 int maxf, openf;
378 size_t len;
379 static char *dtypes[] = { "???", "inode", "socket" };
380 int i;
384
385 if (kd != NULL) {
386 if (kvm_read(kd, nl[NL_MAXFILES].n_value,
387 &maxf, sizeof maxf) != sizeof maxf ||
388 kvm_read(kd, nl[NL_NFILES].n_value,
389 &openf, sizeof openf) != sizeof openf)
390 errx(1, "kvm_read(): %s", kvm_geterr(kd));
391 } else {

--- 4 unchanged lines hidden (view full) ---

396 }
397
398 if (totalflag) {
399 (void)printf("%3d/%3d files\n", openf, maxf);
400 return;
401 }
402 if (getfiles(&buf, &len) == -1)
403 return;
381
382 if (kd != NULL) {
383 if (kvm_read(kd, nl[NL_MAXFILES].n_value,
384 &maxf, sizeof maxf) != sizeof maxf ||
385 kvm_read(kd, nl[NL_NFILES].n_value,
386 &openf, sizeof openf) != sizeof openf)
387 errx(1, "kvm_read(): %s", kvm_geterr(kd));
388 } else {

--- 4 unchanged lines hidden (view full) ---

393 }
394
395 if (totalflag) {
396 (void)printf("%3d/%3d files\n", openf, maxf);
397 return;
398 }
399 if (getfiles(&buf, &len) == -1)
400 return;
404 /*
405 * Getfiles returns in malloc'd memory a pointer to the first file
406 * structure, and then an array of file structs (whose addresses are
407 * derivable from the previous entry).
408 */
409 addr = LIST_FIRST((struct filelist *)buf);
410 fp = (struct file *)(buf + sizeof(struct filelist));
411 openf = (len - sizeof(struct filelist)) / sizeof(struct file);
412
401 openf = len / sizeof *fp;
413 (void)printf("%d/%d open files\n", openf, maxf);
414 (void)printf(" LOC TYPE FLG CNT MSG DATA OFFSET\n");
402 (void)printf("%d/%d open files\n", openf, maxf);
403 (void)printf(" LOC TYPE FLG CNT MSG DATA OFFSET\n");
415 for (; (char *)fp < buf + len; addr = LIST_NEXT(fp, f_list), fp++) {
416 if ((unsigned)fp->f_type > DTYPE_SOCKET)
404 for (fp = (struct xfile *)buf, i = 0; i < openf; ++fp, ++i) {
405 if ((unsigned)fp->xf_type > DTYPE_SOCKET)
417 continue;
406 continue;
418 (void)printf("%8lx ", (u_long)(void *)addr);
419 (void)printf("%-8.8s", dtypes[fp->f_type]);
407 (void)printf("%8jx ", (uintmax_t)(uintptr_t)fp->xf_file);
408 (void)printf("%-8.8s", dtypes[fp->xf_type]);
420 fbp = flagbuf;
409 fbp = flagbuf;
421 if (fp->f_flag & FREAD)
410 if (fp->xf_flag & FREAD)
422 *fbp++ = 'R';
411 *fbp++ = 'R';
423 if (fp->f_flag & FWRITE)
412 if (fp->xf_flag & FWRITE)
424 *fbp++ = 'W';
413 *fbp++ = 'W';
425 if (fp->f_flag & FAPPEND)
414 if (fp->xf_flag & FAPPEND)
426 *fbp++ = 'A';
415 *fbp++ = 'A';
427 if (fp->f_flag & FASYNC)
416 if (fp->xf_flag & FASYNC)
428 *fbp++ = 'I';
429 *fbp = '\0';
417 *fbp++ = 'I';
418 *fbp = '\0';
430 (void)printf("%6s %3d", flagbuf, fp->f_count);
431 (void)printf(" %3d", fp->f_msgcount);
432 (void)printf(" %8lx", (u_long)(void *)fp->f_data);
433 (void)printf(" %jx\n", (uintmax_t)fp->f_offset);
419 (void)printf("%6s %3d", flagbuf, fp->xf_count);
420 (void)printf(" %3d", fp->xf_msgcount);
421 (void)printf(" %8lx", (u_long)(void *)fp->xf_data);
422 (void)printf(" %jx\n", (uintmax_t)fp->xf_offset);
434 }
435 free(buf);
436}
437
438static int
439getfiles(char **abuf, size_t *alen)
440{
441 size_t len;

--- 149 unchanged lines hidden ---
423 }
424 free(buf);
425}
426
427static int
428getfiles(char **abuf, size_t *alen)
429{
430 size_t len;

--- 149 unchanged lines hidden ---