CVS commit: src/usr.bin/fstat
Module Name:src Committed By: christos Date: Wed Aug 26 23:08:29 UTC 2020 Modified Files: src/usr.bin/fstat: fstat.c Log Message: Provide a helpful error message if we don't have privs to read kernel addresses. To generate a diff of this commit: cvs rdiff -u -r1.113 -r1.114 src/usr.bin/fstat/fstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/fstat.c diff -u src/usr.bin/fstat/fstat.c:1.113 src/usr.bin/fstat/fstat.c:1.114 --- src/usr.bin/fstat/fstat.c:1.113 Fri Sep 6 13:08:22 2019 +++ src/usr.bin/fstat/fstat.c Wed Aug 26 19:08:29 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: fstat.c,v 1.113 2019/09/06 17:08:22 christos Exp $ */ +/* $NetBSD: fstat.c,v 1.114 2020/08/26 23:08:29 christos Exp $ */ /*- * Copyright (c) 1988, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19 #if 0 static char sccsid[] = "@(#)fstat.c 8.3 (Berkeley) 5/2/95"; #else -__RCSID("$NetBSD: fstat.c,v 1.113 2019/09/06 17:08:22 christos Exp $"); +__RCSID("$NetBSD: fstat.c,v 1.114 2020/08/26 23:08:29 christos Exp $"); #endif #endif /* not lint */ @@ -181,6 +181,7 @@ static void vtrans(struct file *, struct static void ftrans(fdfile_t *, int); static void ptrans(struct file *, struct pipe *, int); static void kdriver_init(void); +static void check_privs(void); int main(int argc, char **argv) @@ -244,6 +245,8 @@ main(int argc, char **argv) usage(); } + check_privs(); + kdriver_init(); if (*(argv += optind)) { @@ -309,6 +312,23 @@ main(int argc, char **argv) return 0; } +static void +check_privs(void) +{ + int expaddr; + size_t expsize = sizeof(expaddr); + const char *expname = "kern.expose_address"; + + if (geteuid() == 0) + return; + + if (sysctlbyname(expname, &expaddr, &expsize, NULL, 0) == -1) + err(EXIT_FAILURE, "Can't get sysctl `%s'", expname); + if (expaddr == 0) + errx(EXIT_FAILURE, "This program does not work without " + "sysctl `%s' being set", expname); +} + static const char *Uname, *Comm; pid_t Pid;
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: christos Date: Sat May 2 18:42:30 UTC 2020 Modified Files: src/usr.bin/fstat: misc.c Log Message: nuke random stuff that does not exist anymore. To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/usr.bin/fstat/misc.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/misc.c diff -u src/usr.bin/fstat/misc.c:1.22 src/usr.bin/fstat/misc.c:1.23 --- src/usr.bin/fstat/misc.c:1.22 Fri Sep 6 13:08:22 2019 +++ src/usr.bin/fstat/misc.c Sat May 2 14:42:30 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: misc.c,v 1.22 2019/09/06 17:08:22 christos Exp $ */ +/* $NetBSD: misc.c,v 1.23 2020/05/02 18:42:30 christos Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__RCSID("$NetBSD: misc.c,v 1.22 2019/09/06 17:08:22 christos Exp $"); +__RCSID("$NetBSD: misc.c,v 1.23 2020/05/02 18:42:30 christos Exp $"); #include #include @@ -207,35 +207,6 @@ p_mqueue(struct file *f) } static int -p_rnd(struct file *f) -{ - struct cprng_strong { - char cs_name[16]; - int cs_flags; - /*...*/ - } str; - struct rnd_ctx { - struct cprng_strong *rc_cprng; - bool rc_hard; - } ctx; - char buf[1024]; - - if (!KVM_READ(f->f_data, &ctx, sizeof(ctx))) { - dprintf("can't read rnd_ctx at %p for pid %d", f->f_data, Pid); - return 0; - } - if (!KVM_READ(ctx.rc_cprng, &str, sizeof(str))) { - dprintf("can't read cprng_strong at %p for pid %d", f->f_data,\ - Pid); - return 0; - } - snprintb(buf, sizeof(buf), CPRNG_FMT, str.cs_flags); - (void)printf("* rnd \"%s\" flags %s", str.cs_name, buf); - oprint(f, "\n"); - return 0; -} - -static int p_kqueue(struct file *f) { struct kqueue kq; @@ -281,7 +252,8 @@ pmisc(struct file *f, const char *name) case NL_KQUEUE: return p_kqueue(f); case NL_RND: - return p_rnd(f); + printf("* random %p", f->f_data); + break; case NL_SEM: return p_sem(f); case NL_TAP:
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: msaitoh Date: Tue Jun 26 10:00:25 UTC 2018 Modified Files: src/usr.bin/fstat: misc.c Log Message: Print BPF direction correctly. To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/usr.bin/fstat/misc.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/misc.c diff -u src/usr.bin/fstat/misc.c:1.19 src/usr.bin/fstat/misc.c:1.20 --- src/usr.bin/fstat/misc.c:1.19 Tue Jun 26 06:48:03 2018 +++ src/usr.bin/fstat/misc.c Tue Jun 26 10:00:25 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: misc.c,v 1.19 2018/06/26 06:48:03 msaitoh Exp $ */ +/* $NetBSD: misc.c,v 1.20 2018/06/26 10:00:25 msaitoh Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__RCSID("$NetBSD: misc.c,v 1.19 2018/06/26 06:48:03 msaitoh Exp $"); +__RCSID("$NetBSD: misc.c,v 1.20 2018/06/26 10:00:25 msaitoh Exp $"); #include #include @@ -142,8 +142,12 @@ p_bpf(struct file *f) (void)printf(", promisc"); if (bpf.bd_immediate) (void)printf(", immed"); - if (bpf.bd_direction) - (void)printf(", direction"); + if (bpf.bd_direction == BPF_D_IN) + (void)printf(", in"); + else if (bpf.bd_direction == BPF_D_INOUT) + (void)printf(", inout"); + else if (bpf.bd_direction == BPF_D_OUT) + (void)printf(", out"); if (bpf.bd_jitcode != NULL) (void)printf(", jit"); if (bpf.bd_async)
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: nat Date: Mon Jun 4 01:42:49 UTC 2018 Modified Files: src/usr.bin/fstat: misc.c Log Message: Update fstat for audio(4) and pad(4) devices. XXX - pullup 8. Ok christos@. To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/usr.bin/fstat/misc.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/misc.c diff -u src/usr.bin/fstat/misc.c:1.17 src/usr.bin/fstat/misc.c:1.18 --- src/usr.bin/fstat/misc.c:1.17 Fri Dec 30 21:08:23 2016 +++ src/usr.bin/fstat/misc.c Mon Jun 4 01:42:49 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: misc.c,v 1.17 2016/12/30 21:08:23 christos Exp $ */ +/* $NetBSD: misc.c,v 1.18 2018/06/04 01:42:49 nat Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__RCSID("$NetBSD: misc.c,v 1.17 2016/12/30 21:08:23 christos Exp $"); +__RCSID("$NetBSD: misc.c,v 1.18 2018/06/04 01:42:49 nat Exp $"); #include #include @@ -102,7 +102,11 @@ static struct nlist nl[] = { { .n_name = "vnops" }, #define NL_XENEVT 17 { .n_name = "xenevt_fileops" }, -#define NL_MAX 18 +#define NL_AUDIO 18 +{ .n_name = "audio_fileops" }, +#define NL_PAD 19 +{ .n_name = "pad_fileops" }, +#define NL_MAX 20 { .n_name = NULL } }; @@ -277,6 +281,12 @@ pmisc(struct file *f, const char *name) case NL_CRYPTO: printf("* crypto %p\n", f->f_data); return 0; + case NL_AUDIO: + printf("* audio %p\n", f->f_data); + return 0; + case NL_PAD: + printf("* pad %p\n", f->f_data); + return 0; case NL_MAX: printf("* %s ops=%p %p\n", name, f->f_ops, f->f_data); return 0;
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: christos Date: Fri Dec 30 21:08:23 UTC 2016 Modified Files: src/usr.bin/fstat: fstat.c misc.c Log Message: Print the interface for bpf. To generate a diff of this commit: cvs rdiff -u -r1.110 -r1.111 src/usr.bin/fstat/fstat.c cvs rdiff -u -r1.16 -r1.17 src/usr.bin/fstat/misc.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/fstat.c diff -u src/usr.bin/fstat/fstat.c:1.110 src/usr.bin/fstat/fstat.c:1.111 --- src/usr.bin/fstat/fstat.c:1.110 Tue Dec 22 18:35:21 2015 +++ src/usr.bin/fstat/fstat.c Fri Dec 30 16:08:23 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: fstat.c,v 1.110 2015/12/22 23:35:21 christos Exp $ */ +/* $NetBSD: fstat.c,v 1.111 2016/12/30 21:08:23 christos Exp $ */ /*- * Copyright (c) 1988, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19 #if 0 static char sccsid[] = "@(#)fstat.c 8.3 (Berkeley) 5/2/95"; #else -__RCSID("$NetBSD: fstat.c,v 1.110 2015/12/22 23:35:21 christos Exp $"); +__RCSID("$NetBSD: fstat.c,v 1.111 2016/12/30 21:08:23 christos Exp $"); #endif #endif /* not lint */ @@ -651,23 +651,23 @@ vtrans(struct vnode *vp, int i, int flag char buf[1024]; (void)snprintb(buf, sizeof(buf), VNODE_FLAGBITS, vn.v_iflag | vn.v_vflag | vn.v_uflag); - (void)printf(" flags %s\n", buf); + (void)printf(" flags %s\n", buf); return; } else if (badtype) { - (void)printf(" - - %10s-\n", badtype); + (void)printf(" - - %10s-\n", badtype); return; } if (nflg) - (void)printf(" %2llu,%-2llu", + (void)printf(" %2llu,%-2llu", (unsigned long long)major(fst.fsid), (unsigned long long)minor(fst.fsid)); else - (void)printf(" %-8s", getmnton(vn.v_mount)); + (void)printf(" %-8s", getmnton(vn.v_mount)); if (nflg) (void)snprintf(mode, sizeof mode, "%o", fst.mode); else strmode(fst.mode, mode); - (void)printf(" %7"PRIu64" %*s", fst.fileid, nflg ? 5 : 10, mode); + (void)printf(" %7"PRIu64" %*s", fst.fileid, nflg ? 5 : 10, mode); switch (vn.v_type) { case VBLK: case VCHR: { Index: src/usr.bin/fstat/misc.c diff -u src/usr.bin/fstat/misc.c:1.16 src/usr.bin/fstat/misc.c:1.17 --- src/usr.bin/fstat/misc.c:1.16 Sat Jan 23 11:12:03 2016 +++ src/usr.bin/fstat/misc.c Fri Dec 30 16:08:23 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: misc.c,v 1.16 2016/01/23 16:12:03 christos Exp $ */ +/* $NetBSD: misc.c,v 1.17 2016/12/30 21:08:23 christos Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__RCSID("$NetBSD: misc.c,v 1.16 2016/01/23 16:12:03 christos Exp $"); +__RCSID("$NetBSD: misc.c,v 1.17 2016/12/30 21:08:23 christos Exp $"); #include #include @@ -113,12 +113,25 @@ static int p_bpf(struct file *f) { struct bpf_d bpf; + struct bpf_if bi; + struct ifnet ifn; + + strlcpy(ifn.if_xname, "???", sizeof(ifn.if_xname)); if (!KVM_READ(f->f_data, &bpf, sizeof(bpf))) { dprintf("can't read bpf at %p for pid %d", f->f_data, Pid); return 0; } - (void)printf("* bpf rec=%lu, dr=%lu, cap=%lu, pid=%lu", + if (bpf.bd_bif != NULL) { + if (!KVM_READ(bpf.bd_bif, &bi, sizeof(bi))) + dprintf("can't read bpf interface at %p for pid %d", + bpf.bd_bif, Pid); + if (bi.bif_ifp != NULL) + if (!KVM_READ(bi.bif_ifp, &ifn, sizeof(ifn))) +dprintf("can't read net interfsace" +" at %p for pid %d", bi.bif_ifp, Pid); + } + (void)printf("* bpf@%s rec=%lu, dr=%lu, cap=%lu, pid=%lu", ifn.if_xname, bpf.bd_rcount, bpf.bd_dcount, bpf.bd_ccount, (unsigned long)bpf.bd_pid); if (bpf.bd_promisc)
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: christos Date: Sat Jan 23 16:12:03 UTC 2016 Modified Files: src/usr.bin/fstat: Makefile misc.c tmpfs.c Log Message: put _KMEMUSER in the Makefile To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 src/usr.bin/fstat/Makefile cvs rdiff -u -r1.15 -r1.16 src/usr.bin/fstat/misc.c cvs rdiff -u -r1.9 -r1.10 src/usr.bin/fstat/tmpfs.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/Makefile diff -u src/usr.bin/fstat/Makefile:1.23 src/usr.bin/fstat/Makefile:1.24 --- src/usr.bin/fstat/Makefile:1.23 Sat Sep 10 14:34:54 2011 +++ src/usr.bin/fstat/Makefile Sat Jan 23 11:12:03 2016 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.23 2011/09/10 18:34:54 christos Exp $ +# $NetBSD: Makefile,v 1.24 2016/01/23 16:12:03 christos Exp $ # from: @(#)Makefile 8.1 (Berkeley) 6/6/93 .include @@ -16,6 +16,7 @@ CPPFLAGS+= -I${NETBSDSRCDIR}/sys .if (${USE_INET6} != "no") CPPFLAGS+=-DINET6 .endif +CPPFLAGS+=-D_KMEMUSER LDADD+=-lutil DPADD+=${LIBUTIL} Index: src/usr.bin/fstat/misc.c diff -u src/usr.bin/fstat/misc.c:1.15 src/usr.bin/fstat/misc.c:1.16 --- src/usr.bin/fstat/misc.c:1.15 Wed Dec 30 13:15:38 2015 +++ src/usr.bin/fstat/misc.c Sat Jan 23 11:12:03 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: misc.c,v 1.15 2015/12/30 18:15:38 christos Exp $ */ +/* $NetBSD: misc.c,v 1.16 2016/01/23 16:12:03 christos Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -30,9 +30,8 @@ */ #include -__RCSID("$NetBSD: misc.c,v 1.15 2015/12/30 18:15:38 christos Exp $"); +__RCSID("$NetBSD: misc.c,v 1.16 2016/01/23 16:12:03 christos Exp $"); -#define _KMEMUSER #include #include #include Index: src/usr.bin/fstat/tmpfs.c diff -u src/usr.bin/fstat/tmpfs.c:1.9 src/usr.bin/fstat/tmpfs.c:1.10 --- src/usr.bin/fstat/tmpfs.c:1.9 Sat May 28 21:00:50 2011 +++ src/usr.bin/fstat/tmpfs.c Sat Jan 23 11:12:03 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: tmpfs.c,v 1.9 2011/05/29 01:00:50 rmind Exp $ */ +/* $NetBSD: tmpfs.c,v 1.10 2016/01/23 16:12:03 christos Exp $ */ /*- * Copyright (c) 2006 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: tmpfs.c,v 1.9 2011/05/29 01:00:50 rmind Exp $"); +__RCSID("$NetBSD: tmpfs.c,v 1.10 2016/01/23 16:12:03 christos Exp $"); #include #include @@ -37,9 +37,7 @@ __RCSID("$NetBSD: tmpfs.c,v 1.9 2011/05/ #include #include -#define _KMEMUSER #include -#undef _KMEMUSER #include #include
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: christos Date: Wed Dec 30 18:15:38 UTC 2015 Modified Files: src/usr.bin/fstat: misc.c Log Message: Add rnd ops. To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/usr.bin/fstat/misc.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/misc.c diff -u src/usr.bin/fstat/misc.c:1.14 src/usr.bin/fstat/misc.c:1.15 --- src/usr.bin/fstat/misc.c:1.14 Sun Aug 10 12:44:37 2014 +++ src/usr.bin/fstat/misc.c Wed Dec 30 13:15:38 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: misc.c,v 1.14 2014/08/10 16:44:37 tls Exp $ */ +/* $NetBSD: misc.c,v 1.15 2015/12/30 18:15:38 christos Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__RCSID("$NetBSD: misc.c,v 1.14 2014/08/10 16:44:37 tls Exp $"); +__RCSID("$NetBSD: misc.c,v 1.15 2015/12/30 18:15:38 christos Exp $"); #define _KMEMUSER #include @@ -87,19 +87,21 @@ static struct nlist nl[] = { { .n_name = "pipeops" }, #define NL_PUTTER 9 { .n_name = "putter_fileops", }, -#define NL_SEM 10 +#define NL_RND 10 +{ .n_name = "rnd_fileops", }, +#define NL_SEM 11 { .n_name = "semops", }, -#define NL_SOCKET 11 +#define NL_SOCKET 12 { .n_name = "socketops" }, -#define NL_SVR4_NET 12 +#define NL_SVR4_NET 13 { .n_name = "svr4_netops" }, -#define NL_SVR4_32_NET 13 +#define NL_SVR4_32_NET 14 { .n_name = "svr4_32_netops" }, -#define NL_TAP 14 +#define NL_TAP 15 { .n_name = "tap_fileops", }, -#define NL_VNOPS 15 +#define NL_VNOPS 16 { .n_name = "vnops" }, -#define NL_XENEVT 16 +#define NL_XENEVT 17 { .n_name = "xenevt_fileops" }, #define NL_MAX 18 { .n_name = NULL } @@ -182,6 +184,34 @@ p_mqueue(struct file *f) } static int +p_rnd(struct file *f) +{ + struct cprng_strong { + char cs_name[16]; + int cs_flags; + /*...*/ + } str; + struct rnd_ctx { + struct cprng_strong *rc_cprng; + bool rc_hard; + } ctx; + char buf[1024]; + + if (!KVM_READ(f->f_data, &ctx, sizeof(ctx))) { + dprintf("can't read rnd_ctx at %p for pid %d", f->f_data, Pid); + return 0; + } + if (!KVM_READ(ctx.rc_cprng, &str, sizeof(str))) { + dprintf("can't read cprng_strong at %p for pid %d", f->f_data,\ + Pid); + return 0; + } + snprintb(buf, sizeof(buf), CPRNG_FMT, str.cs_flags); + (void)printf("* rnd \"%s\" flags %s\n", str.cs_name, buf); + return 0; +} + +static int p_kqueue(struct file *f) { struct kqueue kq; @@ -225,6 +255,8 @@ pmisc(struct file *f, const char *name) return p_mqueue(f); case NL_KQUEUE: return p_kqueue(f); + case NL_RND: + return p_rnd(f); case NL_SEM: return p_sem(f); case NL_TAP:
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: christos Date: Tue Dec 22 23:35:21 UTC 2015 Modified Files: src/usr.bin/fstat: fstat.c Log Message: print the tag symbolically if we don't support it. To generate a diff of this commit: cvs rdiff -u -r1.109 -r1.110 src/usr.bin/fstat/fstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/fstat.c diff -u src/usr.bin/fstat/fstat.c:1.109 src/usr.bin/fstat/fstat.c:1.110 --- src/usr.bin/fstat/fstat.c:1.109 Sun Mar 8 01:46:51 2015 +++ src/usr.bin/fstat/fstat.c Tue Dec 22 18:35:21 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: fstat.c,v 1.109 2015/03/08 06:46:51 mlelstv Exp $ */ +/* $NetBSD: fstat.c,v 1.110 2015/12/22 23:35:21 christos Exp $ */ /*- * Copyright (c) 1988, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19 #if 0 static char sccsid[] = "@(#)fstat.c 8.3 (Berkeley) 5/2/95"; #else -__RCSID("$NetBSD: fstat.c,v 1.109 2015/03/08 06:46:51 mlelstv Exp $"); +__RCSID("$NetBSD: fstat.c,v 1.110 2015/12/22 23:35:21 christos Exp $"); #endif #endif /* not lint */ @@ -532,6 +532,9 @@ ftrans(fdfile_t *fp, int i) } static const char dead[] = "dead"; +static const char *vnode_tag[] = { + VNODE_TAGS +}; static const char * vfilestat(struct vnode *vp, struct filestat *fsp) @@ -588,8 +591,9 @@ vfilestat(struct vnode *vp, struct files break; default: { static char unknown[10]; - (void)snprintf(unknown, sizeof unknown, - "?(%x)", vp->v_tag); + (void)snprintf(unknown, sizeof unknown, "%s(%#x)", + (size_t)vp->v_tag < __arraycount(vnode_tag) ? + vnode_tag[vp->v_tag] : "?", vp->v_tag); badtype = unknown; break; }
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: mlelstv Date: Sun Mar 8 06:46:51 UTC 2015 Modified Files: src/usr.bin/fstat: fstat.c Log Message: Resolve names of datagram services correctly. To generate a diff of this commit: cvs rdiff -u -r1.108 -r1.109 src/usr.bin/fstat/fstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/fstat.c diff -u src/usr.bin/fstat/fstat.c:1.108 src/usr.bin/fstat/fstat.c:1.109 --- src/usr.bin/fstat/fstat.c:1.108 Fri Feb 14 20:43:34 2014 +++ src/usr.bin/fstat/fstat.c Sun Mar 8 06:46:51 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: fstat.c,v 1.108 2014/02/14 20:43:34 christos Exp $ */ +/* $NetBSD: fstat.c,v 1.109 2015/03/08 06:46:51 mlelstv Exp $ */ /*- * Copyright (c) 1988, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19 #if 0 static char sccsid[] = "@(#)fstat.c 8.3 (Berkeley) 5/2/95"; #else -__RCSID("$NetBSD: fstat.c,v 1.108 2014/02/14 20:43:34 christos Exp $"); +__RCSID("$NetBSD: fstat.c,v 1.109 2015/03/08 06:46:51 mlelstv Exp $"); #endif #endif /* not lint */ @@ -165,10 +165,10 @@ static const char *layer_filestat(stru static int msdosfs_filestat(struct vnode *, struct filestat *); static int nfs_filestat(struct vnode *, struct filestat *); static const char *inet_addrstr(char *, size_t, const struct in_addr *, -uint16_t); +uint16_t, bool); #ifdef INET6 static const char *inet6_addrstr(char *, size_t, const struct in6_addr *, -uint16_t); +uint16_t, bool); #endif static const char *at_addrstr(char *, size_t, const struct sockaddr_at *); static void socktrans(struct socket *, int); @@ -877,11 +877,14 @@ getmnton(struct mount *m) } static const char * -inet_addrstr(char *buf, size_t len, const struct in_addr *a, uint16_t p) +inet_addrstr(char *buf, size_t len, const struct in_addr *a, uint16_t p, bool isdg) { char addr[256], serv[256]; struct sockaddr_in sin; - const int niflags = nflg ? (NI_NUMERICHOST|NI_NUMERICSERV) : 0; + const int niflags = + (nflg ? (NI_NUMERICHOST|NI_NUMERICSERV) : 0) | + (isdg ? NI_DGRAM : 0); + (void)memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; @@ -914,11 +917,13 @@ inet_addrstr(char *buf, size_t len, cons #ifdef INET6 static const char * -inet6_addrstr(char *buf, size_t len, const struct in6_addr *a, uint16_t p) +inet6_addrstr(char *buf, size_t len, const struct in6_addr *a, uint16_t p, bool isdg) { char addr[256], serv[256]; struct sockaddr_in6 sin6; - const int niflags = nflg ? (NI_NUMERICHOST|NI_NUMERICSERV) : 0; + const int niflags = + (nflg ? (NI_NUMERICHOST|NI_NUMERICSERV) : 0) | + (isdg ? NI_DGRAM : 0); (void)memset(&sin6, 0, sizeof(sin6)); sin6.sin6_family = AF_INET6; @@ -1010,6 +1015,7 @@ socktrans(struct socket *sock, int i) int len; char dname[32]; char lbuf[512], fbuf[512], pbuf[24]; + bool isdgram; pbuf[0] = '\0'; /* fill in socket */ @@ -1054,12 +1060,14 @@ socktrans(struct socket *sock, int i) */ fbuf[0] = '\0'; lbuf[0] = '\0'; + isdgram = false; switch(dom.dom_family) { case AF_INET: getinetproto(pbuf, sizeof(pbuf), proto.pr_protocol); switch (proto.pr_protocol) { - case IPPROTO_TCP: case IPPROTO_UDP: + isdgram = true; + case IPPROTO_TCP: if (so.so_pcb == NULL) break; if (kvm_read(kd, (u_long)so.so_pcb, (char *)&inpcb, @@ -1068,9 +1076,9 @@ socktrans(struct socket *sock, int i) goto bad; } inet_addrstr(lbuf, sizeof(lbuf), &inpcb.inp_laddr, - ntohs(inpcb.inp_lport)); + ntohs(inpcb.inp_lport), isdgram); inet_addrstr(fbuf, sizeof(fbuf), &inpcb.inp_faddr, - ntohs(inpcb.inp_fport)); + ntohs(inpcb.inp_fport), isdgram); break; default: break; @@ -1080,8 +1088,9 @@ socktrans(struct socket *sock, int i) case AF_INET6: getinetproto(pbuf, sizeof(pbuf), proto.pr_protocol); switch (proto.pr_protocol) { - case IPPROTO_TCP: case IPPROTO_UDP: + isdgram = true; + case IPPROTO_TCP: if (so.so_pcb == NULL) break; if (kvm_read(kd, (u_long)so.so_pcb, (char *)&in6pcb, @@ -1090,9 +1099,9 @@ socktrans(struct socket *sock, int i) goto bad; } inet6_addrstr(lbuf, sizeof(lbuf), &in6pcb.in6p_laddr, - ntohs(in6pcb.in6p_lport)); + ntohs(in6pcb.in6p_lport), isdgram); inet6_addrstr(fbuf, sizeof(fbuf), &in6pcb.in6p_faddr, - ntohs(in6pcb.in6p_fport)); + ntohs(in6pcb.in6p_fport), isdgram); break; default: break;
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: christos Date: Fri Feb 14 20:43:35 UTC 2014 Modified Files: src/usr.bin/fstat: fstat.c Log Message: fix protocol printing order. To generate a diff of this commit: cvs rdiff -u -r1.107 -r1.108 src/usr.bin/fstat/fstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/fstat.c diff -u src/usr.bin/fstat/fstat.c:1.107 src/usr.bin/fstat/fstat.c:1.108 --- src/usr.bin/fstat/fstat.c:1.107 Thu Jan 16 22:28:01 2014 +++ src/usr.bin/fstat/fstat.c Fri Feb 14 15:43:34 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: fstat.c,v 1.107 2014/01/17 03:28:01 christos Exp $ */ +/* $NetBSD: fstat.c,v 1.108 2014/02/14 20:43:34 christos Exp $ */ /*- * Copyright (c) 1988, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19 #if 0 static char sccsid[] = "@(#)fstat.c 8.3 (Berkeley) 5/2/95"; #else -__RCSID("$NetBSD: fstat.c,v 1.107 2014/01/17 03:28:01 christos Exp $"); +__RCSID("$NetBSD: fstat.c,v 1.108 2014/02/14 20:43:34 christos Exp $"); #endif #endif /* not lint */ @@ -158,8 +158,8 @@ static const char *const dtypes[] = { static void dofiles(struct kinfo_proc2 *); static int ext2fs_filestat(struct vnode *, struct filestat *); static int getfname(const char *); -static void getinetproto(int); -static void getatproto(int); +static void getinetproto(char *, size_t, int); +static void getatproto(char *, size_t, int); static char *getmnton(struct mount *); static const char *layer_filestat(struct vnode *, struct filestat *); static int msdosfs_filestat(struct vnode *, struct filestat *); @@ -1009,8 +1009,9 @@ socktrans(struct socket *sock, int i) struct ddpcb ddpcb; int len; char dname[32]; - char lbuf[512], fbuf[512]; + char lbuf[512], fbuf[512], pbuf[24]; + pbuf[0] = '\0'; /* fill in socket */ if (!KVM_READ(sock, &so, sizeof(struct socket))) { dprintf("can't read sock at %p", sock); @@ -1055,7 +1056,7 @@ socktrans(struct socket *sock, int i) lbuf[0] = '\0'; switch(dom.dom_family) { case AF_INET: - getinetproto(proto.pr_protocol); + getinetproto(pbuf, sizeof(pbuf), proto.pr_protocol); switch (proto.pr_protocol) { case IPPROTO_TCP: case IPPROTO_UDP: @@ -1077,7 +1078,7 @@ socktrans(struct socket *sock, int i) break; #ifdef INET6 case AF_INET6: - getinetproto(proto.pr_protocol); + getinetproto(pbuf, sizeof(pbuf), proto.pr_protocol); switch (proto.pr_protocol) { case IPPROTO_TCP: case IPPROTO_UDP: @@ -1163,7 +1164,7 @@ again: } break; case AF_APPLETALK: - getatproto(proto.pr_protocol); + getatproto(pbuf, sizeof(pbuf), proto.pr_protocol); if (so.so_pcb) { if (kvm_read(kd, (u_long)so.so_pcb, (char *)&ddpcb, sizeof(ddpcb)) != sizeof(ddpcb)){ @@ -1186,6 +1187,8 @@ again: else (void)printf("* %s %s", dname, stypename[so.so_type]); + if (pbuf[0]) + printf("%s", pbuf); if (fbuf[0] || lbuf[0]) printf(" %s%s%s", fbuf, (fbuf[0] && lbuf[0]) ? " <-> " : "", lbuf); @@ -1236,7 +1239,7 @@ misctrans(struct file *file, int i) * print name of protocol number */ static void -getinetproto(int number) +getinetproto(char *buf, size_t len, int number) { const char *cp; @@ -1262,10 +1265,10 @@ getinetproto(int number) case IPPROTO_ICMPV6: cp ="icmp6"; break; default: - (void)printf(" %d", number); + (void)snprintf(buf, len, " %d", number); return; } - (void)printf(" %s", cp); + (void)snprintf(buf, len, " %s", cp); } /* @@ -1273,7 +1276,7 @@ getinetproto(int number) * print name of protocol number */ static void -getatproto(int number) +getatproto(char *buf, size_t len, int number) { const char *cp; @@ -1283,10 +1286,10 @@ getatproto(int number) case ATPROTO_AARP: cp ="aarp"; break; default: - (void)printf(" %d", number); + (void)snprintf(buf, len, " %d", number); return; } - (void)printf(" %s", cp); + (void)snprintf(buf, len, " %s", cp); } static int
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: christos Date: Fri Jan 17 03:28:01 UTC 2014 Modified Files: src/usr.bin/fstat: fstat.c Log Message: make fstat -f search for unix sockets. To generate a diff of this commit: cvs rdiff -u -r1.106 -r1.107 src/usr.bin/fstat/fstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/fstat.c diff -u src/usr.bin/fstat/fstat.c:1.106 src/usr.bin/fstat/fstat.c:1.107 --- src/usr.bin/fstat/fstat.c:1.106 Sun Dec 15 13:56:59 2013 +++ src/usr.bin/fstat/fstat.c Thu Jan 16 22:28:01 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: fstat.c,v 1.106 2013/12/15 18:56:59 mlelstv Exp $ */ +/* $NetBSD: fstat.c,v 1.107 2014/01/17 03:28:01 christos Exp $ */ /*- * Copyright (c) 1988, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19 #if 0 static char sccsid[] = "@(#)fstat.c 8.3 (Berkeley) 5/2/95"; #else -__RCSID("$NetBSD: fstat.c,v 1.106 2013/12/15 18:56:59 mlelstv Exp $"); +__RCSID("$NetBSD: fstat.c,v 1.107 2014/01/17 03:28:01 christos Exp $"); #endif #endif /* not lint */ @@ -510,8 +510,7 @@ ftrans(fdfile_t *fp, int i) vtrans(file.f_data, i, file.f_flag, (long)fdfile.ff_file); break; case DTYPE_SOCKET: - if (checkfile == 0) - socktrans(file.f_data, i); + socktrans(file.f_data, i); break; case DTYPE_PIPE: if (checkfile == 0) @@ -598,37 +597,49 @@ vfilestat(struct vnode *vp, struct files return badtype; } -static void -vtrans(struct vnode *vp, int i, int flag, long addr) +static int +checkfs(struct vnode *vp, struct vnode *vn, struct filestat *fst, +const char **type, const char **fname) { - struct vnode vn; - struct filestat fst; - char mode[15], rw[3]; - const char *badtype, *filename; - - filename = NULL; - if (!KVM_READ(vp, &vn, sizeof(struct vnode))) { + *fname = NULL; + if (!KVM_READ(vp, vn, sizeof(*vn))) { dprintf("can't read vnode at %p for pid %d", vp, Pid); - return; + return 0; } - badtype = vfilestat(&vn, &fst); + *type = vfilestat(vn, fst); if (checkfile) { int fsmatch = 0; DEVS *d; - - if (badtype && badtype != dead) - return; - for (d = devs; d != NULL; d = d->next) - if (d->fsid == fst.fsid) { +#if 0 + if (*type && *type != dead) + return 0; +#endif + for (d = devs; d != NULL; d = d->next) { + if (d->fsid == fst->fsid) { fsmatch = 1; -if (d->ino == fst.fileid) { - filename = d->name; +if (d->ino == fst->fileid) { + *fname = d->name; break; } } - if (fsmatch == 0 || (filename == NULL && fsflg == 0)) - return; + } + if (fsmatch == 0 || (*fname == NULL && fsflg == 0)) + return 0; } + return 1; +} + +static void +vtrans(struct vnode *vp, int i, int flag, long addr) +{ + struct vnode vn; + char mode[15], rw[3]; + const char *badtype, *filename; + struct filestat fst; + + if (!checkfs(vp, &vn, &fst, &badtype, &filename)) + return; + if (Aflg) (void)printf("%*lx ", 2*(int)(sizeof(void*)), addr); PREFIX(i); @@ -999,7 +1010,6 @@ socktrans(struct socket *sock, int i) int len; char dname[32]; char lbuf[512], fbuf[512]; - PREFIX(i); /* fill in socket */ if (!KVM_READ(sock, &so, sizeof(struct socket))) { @@ -1019,6 +1029,9 @@ socktrans(struct socket *sock, int i) goto bad; } + if (checkfile && dom.dom_family != AF_LOCAL) + return; + if ((len = kvm_read(kd, (u_long)dom.dom_name, dname, sizeof(dname) - 1)) != sizeof(dname) -1) { dprintf("can't read domain name at %p", dom.dom_name); @@ -1027,11 +1040,6 @@ socktrans(struct socket *sock, int i) else dname[len] = '\0'; - if ((u_short)so.so_type > STYPEMAX) - (void)printf("* %s ?%d", dname, so.so_type); - else - (void)printf("* %s %s", dname, stypename[so.so_type]); - /* * protocol specific formatting * @@ -1112,6 +1120,16 @@ again: dprintf("can't read unpcb at %p", so.so_pcb); goto bad; } + if (checkfile) { +struct vnode vn; +struct filestat fst; +const char *badtype, *filename; +if (unpcb.unp_vnode == NULL) + return; +if (!checkfs(unpcb.unp_vnode, &vn, &fst, +&badtype, &filename)) + return; + } if (unpcb.unp_addr) { struct sockaddr_un *sun = @@ -1162,6 +1180,12 @@ again: (uintmax_t)(uintptr_t)sock); break; } + PREFIX(i); + if ((u_short)so.so_type > STYPEMAX) + (void)printf("* %s ?%d", dname, so.so_type); + else + (void)printf("* %s %s", dname, stypename[so.so_type]); + if (fbuf[0] || lbuf[0]) printf(" %s%s%s", fbuf, (fbuf[0] && lbuf[0]) ? " <-> " : "", lbuf);
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: mlelstv Date: Sun Dec 15 18:56:59 UTC 2013 Modified Files: src/usr.bin/fstat: fstat.c Log Message: Fix output for -A -f ... To generate a diff of this commit: cvs rdiff -u -r1.105 -r1.106 src/usr.bin/fstat/fstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/fstat.c diff -u src/usr.bin/fstat/fstat.c:1.105 src/usr.bin/fstat/fstat.c:1.106 --- src/usr.bin/fstat/fstat.c:1.105 Sun Dec 15 09:21:03 2013 +++ src/usr.bin/fstat/fstat.c Sun Dec 15 18:56:59 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: fstat.c,v 1.105 2013/12/15 09:21:03 wiz Exp $ */ +/* $NetBSD: fstat.c,v 1.106 2013/12/15 18:56:59 mlelstv Exp $ */ /*- * Copyright (c) 1988, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19 #if 0 static char sccsid[] = "@(#)fstat.c 8.3 (Berkeley) 5/2/95"; #else -__RCSID("$NetBSD: fstat.c,v 1.105 2013/12/15 09:21:03 wiz Exp $"); +__RCSID("$NetBSD: fstat.c,v 1.106 2013/12/15 18:56:59 mlelstv Exp $"); #endif #endif /* not lint */ @@ -502,7 +502,7 @@ ftrans(fdfile_t *fp, int i) i, fdfile.ff_file, Pid); return; } - if (Aflg && file.f_type != DTYPE_VNODE) + if (Aflg && file.f_type != DTYPE_VNODE && checkfile == 0) (void)printf("%*lx ", 2*(int)(sizeof(void*)), (long)fdfile.ff_file); switch (file.f_type) {
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: wiz Date: Sun Dec 15 09:21:03 UTC 2013 Modified Files: src/usr.bin/fstat: fstat.c Log Message: sync usage with man page To generate a diff of this commit: cvs rdiff -u -r1.104 -r1.105 src/usr.bin/fstat/fstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/fstat.c diff -u src/usr.bin/fstat/fstat.c:1.104 src/usr.bin/fstat/fstat.c:1.105 --- src/usr.bin/fstat/fstat.c:1.104 Sun Dec 15 08:16:24 2013 +++ src/usr.bin/fstat/fstat.c Sun Dec 15 09:21:03 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: fstat.c,v 1.104 2013/12/15 08:16:24 mlelstv Exp $ */ +/* $NetBSD: fstat.c,v 1.105 2013/12/15 09:21:03 wiz Exp $ */ /*- * Copyright (c) 1988, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19 #if 0 static char sccsid[] = "@(#)fstat.c 8.3 (Berkeley) 5/2/95"; #else -__RCSID("$NetBSD: fstat.c,v 1.104 2013/12/15 08:16:24 mlelstv Exp $"); +__RCSID("$NetBSD: fstat.c,v 1.105 2013/12/15 09:21:03 wiz Exp $"); #endif #endif /* not lint */ @@ -1325,7 +1325,7 @@ getftype(enum vtype v_type) static void usage(void) { - (void)fprintf(stderr, "Usage: %s [-Afnv] [-p pid] [-u user] " - "[-N system] [-M core] [file ...]\n", getprogname()); + (void)fprintf(stderr, "Usage: %s [-Afnv] [-M core] [-N system] " + "[-p pid] [-u user] [file ...]\n", getprogname()); exit(1); }
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: wiz Date: Sun Dec 15 09:20:48 UTC 2013 Modified Files: src/usr.bin/fstat: fstat.1 Log Message: Sort SYNOPSIS and option descriptions. Bump date for previous. To generate a diff of this commit: cvs rdiff -u -r1.32 -r1.33 src/usr.bin/fstat/fstat.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/fstat.1 diff -u src/usr.bin/fstat/fstat.1:1.32 src/usr.bin/fstat/fstat.1:1.33 --- src/usr.bin/fstat/fstat.1:1.32 Sun Dec 15 08:16:24 2013 +++ src/usr.bin/fstat/fstat.1 Sun Dec 15 09:20:48 2013 @@ -1,4 +1,4 @@ -.\" $NetBSD: fstat.1,v 1.32 2013/12/15 08:16:24 mlelstv Exp $ +.\" $NetBSD: fstat.1,v 1.33 2013/12/15 09:20:48 wiz Exp $ .\" .\" Copyright (c) 1987, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" from: @(#)fstat.1 8.3 (Berkeley) 2/25/94 .\" -.Dd September 5, 2011 +.Dd December 15, 2013 .Dt FSTAT 1 .Os .Sh NAME @@ -37,7 +37,7 @@ .Nd display status of open files .Sh SYNOPSIS .Nm -.Op Fl fnAv +.Op Fl Afnv .Op Fl M Ar core .Op Fl N Ar system .Op Fl p Ar pid @@ -55,6 +55,11 @@ reports on all open files in the system. .Pp Options: .Bl -tag -width Ds +.It Fl A +Add an output column with the address of the kernel object (vnode or file), +that can be matched with +.Xr pstat 8 +output. .It Fl f Restrict examination to files open in the same file systems as the named file arguments, or to the file system containing the @@ -87,11 +92,6 @@ and print the mode of the file in octal Report all files open by the specified process. .It Fl u Report all files open by the specified user. -.It Fl A -Add an output column with the address of the kernel object (vnode or file), -that can be matched with -.Xr pstat 8 -output. .It Fl v Verbose mode. Print error messages upon failures to locate particular
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: mlelstv Date: Sun Dec 15 08:16:24 UTC 2013 Modified Files: src/usr.bin/fstat: fstat.1 fstat.c Log Message: New -A option. Add an output column with the address of the kernel object (vnode or file) that can be matched with prstat(8) output. To generate a diff of this commit: cvs rdiff -u -r1.31 -r1.32 src/usr.bin/fstat/fstat.1 cvs rdiff -u -r1.103 -r1.104 src/usr.bin/fstat/fstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/fstat.1 diff -u src/usr.bin/fstat/fstat.1:1.31 src/usr.bin/fstat/fstat.1:1.32 --- src/usr.bin/fstat/fstat.1:1.31 Wed Oct 3 19:35:08 2012 +++ src/usr.bin/fstat/fstat.1 Sun Dec 15 08:16:24 2013 @@ -1,4 +1,4 @@ -.\" $NetBSD: fstat.1,v 1.31 2012/10/03 19:35:08 wiz Exp $ +.\" $NetBSD: fstat.1,v 1.32 2013/12/15 08:16:24 mlelstv Exp $ .\" .\" Copyright (c) 1987, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -37,7 +37,7 @@ .Nd display status of open files .Sh SYNOPSIS .Nm -.Op Fl fnv +.Op Fl fnAv .Op Fl M Ar core .Op Fl N Ar system .Op Fl p Ar pid @@ -87,6 +87,11 @@ and print the mode of the file in octal Report all files open by the specified process. .It Fl u Report all files open by the specified user. +.It Fl A +Add an output column with the address of the kernel object (vnode or file), +that can be matched with +.Xr pstat 8 +output. .It Fl v Verbose mode. Print error messages upon failures to locate particular Index: src/usr.bin/fstat/fstat.c diff -u src/usr.bin/fstat/fstat.c:1.103 src/usr.bin/fstat/fstat.c:1.104 --- src/usr.bin/fstat/fstat.c:1.103 Sat Oct 19 15:56:05 2013 +++ src/usr.bin/fstat/fstat.c Sun Dec 15 08:16:24 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: fstat.c,v 1.103 2013/10/19 15:56:05 christos Exp $ */ +/* $NetBSD: fstat.c,v 1.104 2013/12/15 08:16:24 mlelstv Exp $ */ /*- * Copyright (c) 1988, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19 #if 0 static char sccsid[] = "@(#)fstat.c 8.3 (Berkeley) 5/2/95"; #else -__RCSID("$NetBSD: fstat.c,v 1.103 2013/10/19 15:56:05 christos Exp $"); +__RCSID("$NetBSD: fstat.c,v 1.104 2013/12/15 08:16:24 mlelstv Exp $"); #endif #endif /* not lint */ @@ -133,6 +133,7 @@ static int fsflg, /* show files on same uflg; /* show files open by a particular (effective) user */ static int checkfile; /* true if restricting to particular files or filesystems */ static int nflg; /* (numerical) display f.s. and rdev as dev_t */ +static int Aflg; /* prefix with address of file structure */ int vflg; /* display errors in locating kernel data objects etc... */ static fdfile_t **ofiles; /* buffer of pointers to file structures */ @@ -175,7 +176,7 @@ static void misctrans(struct file *, int static int ufs_filestat(struct vnode *, struct filestat *); static void usage(void) __dead; static const char *vfilestat(struct vnode *, struct filestat *); -static void vtrans(struct vnode *, int, int); +static void vtrans(struct vnode *, int, int, long); static void ftrans(fdfile_t *, int); static void ptrans(struct file *, struct pipe *, int); static void kdriver_init(void); @@ -195,7 +196,7 @@ main(int argc, char **argv) arg = 0; what = KERN_PROC_ALL; nlistf = memf = NULL; - while ((ch = getopt(argc, argv, "fnp:u:vN:M:")) != -1) + while ((ch = getopt(argc, argv, "fnAp:u:vN:M:")) != -1) switch((char)ch) { case 'f': fsflg = 1; @@ -209,6 +210,9 @@ main(int argc, char **argv) case 'n': nflg = 1; break; + case 'A': + Aflg = 1; + break; case 'p': if (pflg++) usage(); @@ -277,6 +281,8 @@ main(int argc, char **argv) if ((p = kvm_getproc2(kd, what, arg, sizeof *p, &cnt)) == NULL) { errx(1, "%s", kvm_geterr(kd)); } + if (Aflg) + (void)printf("%-*s ", 2*(int)(sizeof(void*)), "ADDR"); if (nflg) (void)printf("%s", "USER CMD PID FD DEV INUM MODE SZ|DV R/W"); @@ -444,11 +450,11 @@ dofiles(struct kinfo_proc2 *p) * root directory vnode, if one */ if (cwdi.cwdi_rdir) - vtrans(cwdi.cwdi_rdir, RDIR, FREAD); + vtrans(cwdi.cwdi_rdir, RDIR, FREAD, (long)cwdi.cwdi_rdir); /* * current working directory vnode */ - vtrans(cwdi.cwdi_cdir, CDIR, FREAD); + vtrans(cwdi.cwdi_cdir, CDIR, FREAD, (long)cwdi.cwdi_cdir); #if 0 /* * Disable for now, since p->p_tracep appears to point to a ktr_desc * @@ -496,9 +502,12 @@ ftrans(fdfile_t *fp, int i) i, fdfile.ff_file, Pid); return; } + if (Aflg && file.f_type != DTYPE_VNODE) + (void)printf("%*lx ", + 2*(int)(sizeof(void*)), (long)fdfile.ff_file); switch (file.f_type) { case DTYPE_VNODE: - vtrans(file.f_data, i, file.f_flag); + vtrans(file.f_data, i, file.f_flag, (long)fdfile.ff_file); break; case DTYPE_SOCKET: if (checkfile == 0) @@ -590,7 +599,7 @@ vfilestat(struct vnode *vp, struct files } static void -vtrans(struct vnode *vp, int i, int flag) +vtrans(struct vnode *vp
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: christos Date: Fri Oct 18 20:18:42 UTC 2013 Modified Files: src/usr.bin/fstat: fstat.c Log Message: avoid pointer gymnastics To generate a diff of this commit: cvs rdiff -u -r1.100 -r1.101 src/usr.bin/fstat/fstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/fstat.c diff -u src/usr.bin/fstat/fstat.c:1.100 src/usr.bin/fstat/fstat.c:1.101 --- src/usr.bin/fstat/fstat.c:1.100 Sat Nov 24 19:36:23 2012 +++ src/usr.bin/fstat/fstat.c Fri Oct 18 16:18:42 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: fstat.c,v 1.100 2012/11/25 00:36:23 christos Exp $ */ +/* $NetBSD: fstat.c,v 1.101 2013/10/18 20:18:42 christos Exp $ */ /*- * Copyright (c) 1988, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19 #if 0 static char sccsid[] = "@(#)fstat.c 8.3 (Berkeley) 5/2/95"; #else -__RCSID("$NetBSD: fstat.c,v 1.100 2012/11/25 00:36:23 christos Exp $"); +__RCSID("$NetBSD: fstat.c,v 1.101 2013/10/18 20:18:42 christos Exp $"); #endif #endif /* not lint */ @@ -895,6 +895,7 @@ inet6_addrstr(char *buf, size_t len, con { char addr[256], serv[256]; struct sockaddr_in6 sin6; + uint16_t ad2; const int niflags = nflg ? (NI_NUMERICHOST|NI_NUMERICSERV) : 0; (void)memset(&sin6, 0, sizeof(sin6)); @@ -903,10 +904,9 @@ inet6_addrstr(char *buf, size_t len, con sin6.sin6_addr = *a; sin6.sin6_port = htons(p); - if (IN6_IS_ADDR_LINKLOCAL(a) && - *(u_int16_t *)&sin6.sin6_addr.s6_addr[2] != 0) { - sin6.sin6_scope_id = - ntohs(*(uint16_t *)&sin6.sin6_addr.s6_addr[2]); + memcpy(&ad2, &sin6.sin6_addr.s6_addr[2], sizeof(ad2)); + if (IN6_IS_ADDR_LINKLOCAL(a) && ad2 != 0) { + sin6.sin6_scope_id = ntohs(ad2); sin6.sin6_addr.s6_addr[2] = 0; sin6.sin6_addr.s6_addr[3] = 0; }
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: christos Date: Sun Nov 25 15:30:29 UTC 2012 Modified Files: src/usr.bin/fstat: misc.c Log Message: support printing rnd descriptor info To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/usr.bin/fstat/misc.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/misc.c diff -u src/usr.bin/fstat/misc.c:1.10 src/usr.bin/fstat/misc.c:1.11 --- src/usr.bin/fstat/misc.c:1.10 Sat Nov 24 20:05:49 2012 +++ src/usr.bin/fstat/misc.c Sun Nov 25 10:30:28 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: misc.c,v 1.10 2012/11/25 01:05:49 christos Exp $ */ +/* $NetBSD: misc.c,v 1.11 2012/11/25 15:30:28 christos Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__RCSID("$NetBSD: misc.c,v 1.10 2012/11/25 01:05:49 christos Exp $"); +__RCSID("$NetBSD: misc.c,v 1.11 2012/11/25 15:30:28 christos Exp $"); #define _KMEMUSER #include @@ -50,6 +50,10 @@ __RCSID("$NetBSD: misc.c,v 1.10 2012/11/ #include #define copyout_t int #include +#define _LIB_LIBKERN_LIBKERN_H_ +#define mutex_enter(a) +#define mutex_exit(a) +#include #undef _KERNEL #include #include @@ -57,6 +61,7 @@ __RCSID("$NetBSD: misc.c,v 1.10 2012/11/ #include #include +#include #include #include #include "fstat.h" @@ -96,7 +101,9 @@ static struct nlist nl[] = { { .n_name = "vnops" }, #define NL_XENEVT 16 { .n_name = "xenevt_fileops" }, -#define NL_MAX 17 +#define NL_RND 17 +{ .n_name = "rnd_fileops" }, +#define NL_MAX 18 { .n_name = NULL } }; @@ -189,6 +196,35 @@ p_kqueue(struct file *f) return 0; } +static int +p_rnd(struct file *f) +{ + rp_ctx_t rp; + + if (!KVM_READ(f->f_data, &rp, sizeof(rp))) { + dprintf("can't read rnd at %p for pid %d", f->f_data, Pid); + return 0; + } + (void)printf("* rnd "); + if (rp.hard) + printf("bytesonkey=%d, ", rp.bytesonkey); + if (rp.cprng) { + cprng_strong_t cprng; + if (!KVM_READ(rp.cprng, &cprng, sizeof(cprng))) { + dprintf("can't read rnd cprng at %p for pid %d", + rp.cprng, Pid); + } else { + char buf[128]; + snprintb(buf, sizeof(buf), CPRNG_FMT, cprng.flags); + (void)printf("name=%s, serial=%d%s, flags=%s\n", + cprng.name, cprng.entropy_serial, + cprng.reseed_pending ? ", reseed" : "", buf); + return 0; + } + } + printf("\n"); + return 0; +} int pmisc(struct file *f, const char *name) { @@ -222,6 +258,8 @@ pmisc(struct file *f, const char *name) return p_kqueue(f); case NL_SEM: return p_sem(f); + case NL_RND: + return p_rnd(f); case NL_TAP: printf("* tap %lu\n", (unsigned long)(intptr_t)f->f_data); return 0; @@ -229,7 +267,7 @@ pmisc(struct file *f, const char *name) printf("* crypto %p\n", f->f_data); return 0; case NL_MAX: - printf("* %s %p\n", name, f->f_data); + printf("* %s ops=%p %p\n", name, f->f_ops, f->f_data); return 0; default: printf("* %s %p\n", nl[i].n_name, f->f_data);
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: christos Date: Sun Nov 25 01:05:49 UTC 2012 Modified Files: src/usr.bin/fstat: misc.c Log Message: return stuff for ksem To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/usr.bin/fstat/misc.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/misc.c diff -u src/usr.bin/fstat/misc.c:1.9 src/usr.bin/fstat/misc.c:1.10 --- src/usr.bin/fstat/misc.c:1.9 Sat Oct 27 18:38:07 2012 +++ src/usr.bin/fstat/misc.c Sat Nov 24 20:05:49 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: misc.c,v 1.9 2012/10/27 22:38:07 alnsn Exp $ */ +/* $NetBSD: misc.c,v 1.10 2012/11/25 01:05:49 christos Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__RCSID("$NetBSD: misc.c,v 1.9 2012/10/27 22:38:07 alnsn Exp $"); +__RCSID("$NetBSD: misc.c,v 1.10 2012/11/25 01:05:49 christos Exp $"); #define _KMEMUSER #include @@ -48,6 +48,8 @@ __RCSID("$NetBSD: misc.c,v 1.9 2012/10/2 #include #define _KERNEL #include +#define copyout_t int +#include #undef _KERNEL #include #include @@ -55,6 +57,7 @@ __RCSID("$NetBSD: misc.c,v 1.9 2012/10/2 #include #include +#include #include #include "fstat.h" @@ -105,7 +108,7 @@ p_bpf(struct file *f) { struct bpf_d bpf; - if (!KVM_READ(f->f_data, &bpf, sizeof (bpf))) { + if (!KVM_READ(f->f_data, &bpf, sizeof(bpf))) { dprintf("can't read bpf at %p for pid %d", f->f_data, Pid); return 0; } @@ -133,11 +136,39 @@ p_bpf(struct file *f) } static int +p_sem(struct file *f) +{ + ksem_t ks; + if (!KVM_READ(f->f_data, &ks, sizeof(ks))) { + dprintf("can't read sem at %p for pid %d", f->f_data, Pid); + return 0; + } + (void)printf("* ksem ref=%u, value=%u, waiters=%u, flags=0x%x, " + "mode=%o, uid=%u, gid=%u", ks.ks_ref, ks.ks_value, ks.ks_waiters, + ks.ks_flags, ks.ks_mode, ks.ks_uid, ks.ks_gid); + if (ks.ks_name && ks.ks_namelen) { + char buf[64]; + if (ks.ks_namelen >= sizeof(buf)) + ks.ks_namelen = sizeof(buf) - 1; + if (!KVM_READ(ks.ks_name, buf, ks.ks_namelen)) { + dprintf("can't read sem name at %p for pid %d", + ks.ks_name, Pid); + } else { + buf[ks.ks_namelen] = '\0'; + (void)printf(", name=%s\n", buf); + return 0; + } + } + (void)printf("\n"); + return 0; +} + +static int p_mqueue(struct file *f) { struct mqueue mq; - if (!KVM_READ(f->f_data, &mq, sizeof (mq))) { + if (!KVM_READ(f->f_data, &mq, sizeof(mq))) { dprintf("can't read mqueue at %p for pid %d", f->f_data, Pid); return 0; } @@ -150,7 +181,7 @@ p_kqueue(struct file *f) { struct kqueue kq; - if (!KVM_READ(f->f_data, &kq, sizeof (kq))) { + if (!KVM_READ(f->f_data, &kq, sizeof(kq))) { dprintf("can't read kqueue at %p for pid %d", f->f_data, Pid); return 0; } @@ -167,8 +198,17 @@ pmisc(struct file *f, const char *name) if ((n = KVM_NLIST(nl)) == -1) errx(1, "Cannot list kernel symbols (%s)", KVM_GETERR()); - else if (n != 0 && vflg) - warnx("Could not find %d symbols", n); + else if (n != 0 && vflg) { + char buf[1024]; + buf[0] = '\0'; + for (struct nlist *l = nl; l->n_name != NULL; l++) { +if (l->n_value != 0) + continue; +strlcat(buf, ", ", sizeof(buf)); +strlcat(buf, l->n_name, sizeof(buf)); + } + warnx("Could not find %d symbols: %s", n, buf + 2); + } } for (i = 0; i < NL_MAX; i++) if ((uintptr_t)f->f_ops == nl[i].n_value) @@ -180,6 +220,8 @@ pmisc(struct file *f, const char *name) return p_mqueue(f); case NL_KQUEUE: return p_kqueue(f); + case NL_SEM: + return p_sem(f); case NL_TAP: printf("* tap %lu\n", (unsigned long)(intptr_t)f->f_data); return 0;
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: christos Date: Sun Nov 25 00:36:24 UTC 2012 Modified Files: src/usr.bin/fstat: fstat.c Log Message: - add more debugging. - in misctrans() we need the file index not the file type. To generate a diff of this commit: cvs rdiff -u -r1.99 -r1.100 src/usr.bin/fstat/fstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/fstat.c diff -u src/usr.bin/fstat/fstat.c:1.99 src/usr.bin/fstat/fstat.c:1.100 --- src/usr.bin/fstat/fstat.c:1.99 Thu Oct 18 22:49:52 2012 +++ src/usr.bin/fstat/fstat.c Sat Nov 24 19:36:23 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: fstat.c,v 1.99 2012/10/19 02:49:52 christos Exp $ */ +/* $NetBSD: fstat.c,v 1.100 2012/11/25 00:36:23 christos Exp $ */ /*- * Copyright (c) 1988, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19 #if 0 static char sccsid[] = "@(#)fstat.c 8.3 (Berkeley) 5/2/95"; #else -__RCSID("$NetBSD: fstat.c,v 1.99 2012/10/19 02:49:52 christos Exp $"); +__RCSID("$NetBSD: fstat.c,v 1.100 2012/11/25 00:36:23 christos Exp $"); #endif #endif /* not lint */ @@ -170,7 +170,7 @@ static const char *inet6_addrstr(char *, #endif static const char *at_addrstr(char *, size_t, const struct sockaddr_at *); static void socktrans(struct socket *, int); -static void misctrans(struct file *); +static void misctrans(struct file *, int); static int ufs_filestat(struct vnode *, struct filestat *); static void usage(void) __dead; static const char *vfilestat(struct vnode *, struct filestat *); @@ -485,8 +485,11 @@ ftrans(fdfile_t *fp, int i) i, fp, Pid); return; } - if (fdfile.ff_file == NULL) + if (fdfile.ff_file == NULL) { + dprintf("null ff_file for %d at %p for pid %d", + i, fp, Pid); return; + } if (!KVM_READ(fdfile.ff_file, &file, sizeof(file))) { dprintf("can't read file %d at %p for pid %d", i, fdfile.ff_file, Pid); @@ -510,7 +513,7 @@ ftrans(fdfile_t *fp, int i) case DTYPE_MQUEUE: case DTYPE_SEM: if (checkfile == 0) - misctrans(&file); + misctrans(&file, i); break; default: dprintf("unknown file type %d for file %d of pid %d", @@ -1192,10 +1195,10 @@ bad: } static void -misctrans(struct file *file) +misctrans(struct file *file, int i) { - PREFIX((int)file->f_type); + PREFIX(i); pmisc(file, dtypes[file->f_type]); }
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: alnsn Date: Sat Oct 27 22:38:07 UTC 2012 Modified Files: src/usr.bin/fstat: misc.c Log Message: Report jit'ed bpf fildes in fstat. To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/usr.bin/fstat/misc.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/misc.c diff -u src/usr.bin/fstat/misc.c:1.8 src/usr.bin/fstat/misc.c:1.9 --- src/usr.bin/fstat/misc.c:1.8 Sat Sep 10 18:34:40 2011 +++ src/usr.bin/fstat/misc.c Sat Oct 27 22:38:07 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: misc.c,v 1.8 2011/09/10 18:34:40 christos Exp $ */ +/* $NetBSD: misc.c,v 1.9 2012/10/27 22:38:07 alnsn Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__RCSID("$NetBSD: misc.c,v 1.8 2011/09/10 18:34:40 christos Exp $"); +__RCSID("$NetBSD: misc.c,v 1.9 2012/10/27 22:38:07 alnsn Exp $"); #define _KMEMUSER #include @@ -118,6 +118,8 @@ p_bpf(struct file *f) (void)printf(", immed"); if (bpf.bd_seesent) (void)printf(", seesent"); + if (bpf.bd_jitcode != NULL) + (void)printf(", jit"); if (bpf.bd_async) (void)printf(", asyncgrp=%lu", (unsigned long)bpf.bd_pgid); if (bpf.bd_state == BPF_IDLE)
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: christos Date: Fri Oct 19 02:49:52 UTC 2012 Modified Files: src/usr.bin/fstat: fstat.c Log Message: print major device numbers symbolically from kinfo_drivers To generate a diff of this commit: cvs rdiff -u -r1.98 -r1.99 src/usr.bin/fstat/fstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/fstat.c diff -u src/usr.bin/fstat/fstat.c:1.98 src/usr.bin/fstat/fstat.c:1.99 --- src/usr.bin/fstat/fstat.c:1.98 Thu Oct 18 22:11:25 2012 +++ src/usr.bin/fstat/fstat.c Thu Oct 18 22:49:52 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: fstat.c,v 1.98 2012/10/19 02:11:25 christos Exp $ */ +/* $NetBSD: fstat.c,v 1.99 2012/10/19 02:49:52 christos Exp $ */ /*- * Copyright (c) 1988, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19 #if 0 static char sccsid[] = "@(#)fstat.c 8.3 (Berkeley) 5/2/95"; #else -__RCSID("$NetBSD: fstat.c,v 1.98 2012/10/19 02:11:25 christos Exp $"); +__RCSID("$NetBSD: fstat.c,v 1.99 2012/10/19 02:49:52 christos Exp $"); #endif #endif /* not lint */ @@ -177,6 +177,7 @@ static const char *vfilestat(struct vn static void vtrans(struct vnode *, int, int); static void ftrans(fdfile_t *, int); static void ptrans(struct file *, struct pipe *, int); +static void kdriver_init(void); int main(int argc, char **argv) @@ -234,6 +235,8 @@ main(int argc, char **argv) usage(); } + kdriver_init(); + if (*(argv += optind)) { for (; *argv; ++argv) { if (getfname(*argv)) @@ -314,6 +317,89 @@ pid_t Pid; break; \ } +static struct kinfo_drivers *kdriver; +static size_t kdriverlen; + +static int +kdriver_comp(const void *a, const void *b) +{ + const struct kinfo_drivers *ka = a; + const struct kinfo_drivers *kb = b; + int kac = ka->d_cmajor == -1 ? 0 : ka->d_cmajor; + int kbc = kb->d_cmajor == -1 ? 0 : kb->d_cmajor; + int kab = ka->d_bmajor == -1 ? 0 : ka->d_bmajor; + int kbb = kb->d_bmajor == -1 ? 0 : kb->d_bmajor; + int c = kac - kbc; + if (c == 0) + return kab - kbb; + else + return c; +} + +static const char * +kdriver_search(int type, dev_t num) +{ + struct kinfo_drivers k, *kp; + static char buf[64]; + + if (nflg) + goto out; + + if (type == VBLK) { + k.d_bmajor = num; + k.d_cmajor = -1; + } else { + k.d_bmajor = -1; + k.d_cmajor = num; + } + kp = bsearch(&k, kdriver, kdriverlen, sizeof(*kdriver), kdriver_comp); + if (kp) + return kp->d_name; +out: + snprintf(buf, sizeof(buf), "%llu", (unsigned long long)num); + return buf; +} + + +static void +kdriver_init(void) +{ + size_t sz; + int error; + static const int name[2] = { CTL_KERN, KERN_DRIVERS }; + + error = sysctl(name, __arraycount(name), NULL, &sz, NULL, 0); + if (error == -1) { + warn("sysctl kern.drivers"); + return; + } + + if (sz % sizeof(*kdriver)) { + warnx("bad size %zu for kern.drivers", sz); + return; + } + + kdriver = malloc(sz); + if (kdriver == NULL) { + warn("malloc"); + return; + } + + error = sysctl(name, __arraycount(name), kdriver, &sz, NULL, 0); + if (error == -1) { + warn("sysctl kern.drivers"); + return; + } + + kdriverlen = sz / sizeof(*kdriver); + qsort(kdriver, kdriverlen, sizeof(*kdriver), kdriver_comp); +#ifdef DEBUG + for (size_t i = 0; i < kdriverlen; i++) + printf("%d %d %s\n", kdriver[i].d_cmajor, kdriver[i].d_bmajor, + kdriver[i].d_name); +#endif +} + /* * print open files attributed to this process */ @@ -559,8 +645,8 @@ vtrans(struct vnode *vp, int i, int flag if (nflg || ((name = devname(fst.rdev, vn.v_type == VCHR ? S_IFCHR : S_IFBLK)) == NULL)) - (void)printf(" %2llu,%-2llu", - (unsigned long long)major(fst.rdev), + (void)printf(" %s,%-2llu", + kdriver_search(vn.v_type, major(fst.rdev)), (unsigned long long)minor(fst.rdev)); else (void)printf(" %6s", name);
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: christos Date: Fri Oct 19 02:11:25 UTC 2012 Modified Files: src/usr.bin/fstat: fstat.c Log Message: more info for unix sockets. XXX: chroot handling To generate a diff of this commit: cvs rdiff -u -r1.97 -r1.98 src/usr.bin/fstat/fstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/fstat.c diff -u src/usr.bin/fstat/fstat.c:1.97 src/usr.bin/fstat/fstat.c:1.98 --- src/usr.bin/fstat/fstat.c:1.97 Wed Sep 26 19:01:04 2012 +++ src/usr.bin/fstat/fstat.c Thu Oct 18 22:11:25 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: fstat.c,v 1.97 2012/09/26 23:01:04 christos Exp $ */ +/* $NetBSD: fstat.c,v 1.98 2012/10/19 02:11:25 christos Exp $ */ /*- * Copyright (c) 1988, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19 #if 0 static char sccsid[] = "@(#)fstat.c 8.3 (Berkeley) 5/2/95"; #else -__RCSID("$NetBSD: fstat.c,v 1.97 2012/09/26 23:01:04 christos Exp $"); +__RCSID("$NetBSD: fstat.c,v 1.98 2012/10/19 02:11:25 christos Exp $"); #endif #endif /* not lint */ @@ -1000,12 +1000,10 @@ socktrans(struct socket *sock, int i) /* print address of pcb and connected pcb */ if (so.so_pcb) { char shoconn[4], *cp; + void *pcb[2]; + size_t p = 0; - if (kvm_read(kd, (u_long)so.so_pcb, (char *)&unpcb, - sizeof(struct unpcb)) != sizeof(struct unpcb)){ -dprintf("can't read unpcb at %p", so.so_pcb); -goto bad; - } + pcb[0] = so.so_pcb; cp = shoconn; if (!(so.so_state & SS_CANTRCVMORE)) @@ -1014,6 +1012,13 @@ socktrans(struct socket *sock, int i) if (!(so.so_state & SS_CANTSENDMORE)) *cp++ = '>'; *cp = '\0'; +again: + if (kvm_read(kd, (u_long)pcb[p], (char *)&unpcb, + sizeof(struct unpcb)) != sizeof(struct unpcb)){ +dprintf("can't read unpcb at %p", so.so_pcb); +goto bad; + } + if (unpcb.unp_addr) { struct sockaddr_un *sun = malloc(unpcb.unp_addrlen); @@ -1027,15 +1032,22 @@ socktrans(struct socket *sock, int i) unpcb.unp_addr); free(sun); } else { - snprintf(fbuf, sizeof(fbuf), " %s %s", - shoconn, sun->sun_path); + snprintf(fbuf, sizeof(fbuf), " %s %s %s", + shoconn, sun->sun_path, + p == 0 ? "[creat]" : "[using]"); free(sun); break; } } - if (unpcb.unp_conn) -snprintf(fbuf, sizeof(fbuf), " %s %lx", shoconn, -(long)unpcb.unp_conn); + if (unpcb.unp_conn) { +if (p == 0) { + pcb[++p] = unpcb.unp_conn; + goto again; +} else + snprintf(fbuf, sizeof(fbuf), + " %p %s %p", pcb[0], shoconn, + pcb[1]); + } } break; case AF_APPLETALK:
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: wiz Date: Wed Oct 3 19:35:08 UTC 2012 Modified Files: src/usr.bin/fstat: fstat.1 Log Message: - In the example for `-f', reference a directory that is actually available in a default installation (/usr/src isn't); - put together two lines which belong to the same sentence; - remove a spurious space character; - remove unneeded consecutive argument for `.Nm' macro. >From Bug Hunting. To generate a diff of this commit: cvs rdiff -u -r1.30 -r1.31 src/usr.bin/fstat/fstat.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/fstat.1 diff -u src/usr.bin/fstat/fstat.1:1.30 src/usr.bin/fstat/fstat.1:1.31 --- src/usr.bin/fstat/fstat.1:1.30 Sat Oct 8 22:16:03 2011 +++ src/usr.bin/fstat/fstat.1 Wed Oct 3 19:35:08 2012 @@ -1,4 +1,4 @@ -.\" $NetBSD: fstat.1,v 1.30 2011/10/08 22:16:03 jnemeth Exp $ +.\" $NetBSD: fstat.1,v 1.31 2012/10/03 19:35:08 wiz Exp $ .\" .\" Copyright (c) 1987, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -61,9 +61,9 @@ the named file arguments, or to the file current directory if there are no additional filename arguments. For example, to find all files open in the file system where the directory -.Pa /usr/src +.Pa /var/log resides, type -.Dq Li fstat -f /usr/src . +.Dq Li fstat -f /var/log . Please see the .Sx BUGS section for issues with this option. @@ -96,8 +96,7 @@ these data structures are dynamically cr possible for them to disappear while .Nm is running. -This -is normal and unavoidable since the rest of the system is running while +This is normal and unavoidable since the rest of the system is running while .Nm itself is running. .It Ar @@ -233,7 +232,7 @@ and a full duplex socket shows a double .Pq Dq \*[Lt]-\*[Gt] . .Pp For internet sockets -.Nm fstat +.Nm also attempts to print the internet address and port for the local end of a connection. If the socket is connected, it also prints the remote internet address
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: christos Date: Wed Sep 26 23:01:04 UTC 2012 Modified Files: src/usr.bin/fstat: fstat.c Log Message: fix non-numeric address and port printing. To generate a diff of this commit: cvs rdiff -u -r1.96 -r1.97 src/usr.bin/fstat/fstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/fstat.c diff -u src/usr.bin/fstat/fstat.c:1.96 src/usr.bin/fstat/fstat.c:1.97 --- src/usr.bin/fstat/fstat.c:1.96 Sat Mar 24 17:51:23 2012 +++ src/usr.bin/fstat/fstat.c Wed Sep 26 19:01:04 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: fstat.c,v 1.96 2012/03/24 21:51:23 christos Exp $ */ +/* $NetBSD: fstat.c,v 1.97 2012/09/26 23:01:04 christos Exp $ */ /*- * Copyright (c) 1988, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19 #if 0 static char sccsid[] = "@(#)fstat.c 8.3 (Berkeley) 5/2/95"; #else -__RCSID("$NetBSD: fstat.c,v 1.96 2012/03/24 21:51:23 christos Exp $"); +__RCSID("$NetBSD: fstat.c,v 1.97 2012/09/26 23:01:04 christos Exp $"); #endif #endif /* not lint */ @@ -767,31 +767,36 @@ getmnton(struct mount *m) static const char * inet_addrstr(char *buf, size_t len, const struct in_addr *a, uint16_t p) { - char addr[256]; + char addr[256], serv[256]; + struct sockaddr_in sin; + const int niflags = nflg ? (NI_NUMERICHOST|NI_NUMERICSERV) : 0; + + (void)memset(&sin, 0, sizeof(sin)); + sin.sin_family = AF_INET; + sin.sin_len = sizeof(sin); + sin.sin_addr = *a; + sin.sin_port = htons(p); + + serv[0] = '\0'; + + if (getnameinfo((struct sockaddr *)&sin, sin.sin_len, + addr, sizeof(addr), serv, sizeof(serv), niflags)) { + if (inet_ntop(AF_INET, a, addr, sizeof(addr)) == NULL) + strlcpy(addr, "invalid", sizeof(addr)); + } + + if (serv[0] == '\0') + snprintf(serv, sizeof(serv), "%u", p); if (a->s_addr == INADDR_ANY) { if (p == 0) - addr[0] = '\0'; + buf[0] = '\0'; else - strlcpy(addr, "*", sizeof(addr)); - } else { - struct sockaddr_in sin; - const int niflags = NI_NUMERICHOST; - - (void)memset(&sin, 0, sizeof(sin)); - sin.sin_family = AF_INET6; - sin.sin_len = sizeof(sin); - sin.sin_addr = *a; - - if (getnameinfo((struct sockaddr *)&sin, sin.sin_len, - addr, sizeof(addr), NULL, 0, niflags)) - if (inet_ntop(AF_INET, a, addr, sizeof(addr)) == NULL) -strlcpy(addr, "invalid", sizeof(addr)); + snprintf(buf, len, "*:%s", serv); + return buf; } - if (addr[0]) - snprintf(buf, len, "%s:%u", addr, p); - else - strlcpy(buf, addr, len); + + snprintf(buf, len, "%s:%s", addr, serv); return buf; } @@ -799,39 +804,47 @@ inet_addrstr(char *buf, size_t len, cons static const char * inet6_addrstr(char *buf, size_t len, const struct in6_addr *a, uint16_t p) { - char addr[256]; + char addr[256], serv[256]; + struct sockaddr_in6 sin6; + const int niflags = nflg ? (NI_NUMERICHOST|NI_NUMERICSERV) : 0; + + (void)memset(&sin6, 0, sizeof(sin6)); + sin6.sin6_family = AF_INET6; + sin6.sin6_len = sizeof(sin6); + sin6.sin6_addr = *a; + sin6.sin6_port = htons(p); + + if (IN6_IS_ADDR_LINKLOCAL(a) && + *(u_int16_t *)&sin6.sin6_addr.s6_addr[2] != 0) { + sin6.sin6_scope_id = + ntohs(*(uint16_t *)&sin6.sin6_addr.s6_addr[2]); + sin6.sin6_addr.s6_addr[2] = 0; + sin6.sin6_addr.s6_addr[3] = 0; + } + + serv[0] = '\0'; + + if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len, + addr, sizeof(addr), serv, sizeof(serv), niflags)) { + if (inet_ntop(AF_INET6, a, addr, sizeof(addr)) == NULL) + strlcpy(addr, "invalid", sizeof(addr)); + } + + if (serv[0] == '\0') + snprintf(serv, sizeof(serv), "%u", p); if (IN6_IS_ADDR_UNSPECIFIED(a)) { if (p == 0) - addr[0] = '\0'; + buf[0] = '\0'; else - strlcpy(addr, "*", sizeof(addr)); - } else { - struct sockaddr_in6 sin6; - const int niflags = NI_NUMERICHOST; - - (void)memset(&sin6, 0, sizeof(sin6)); - sin6.sin6_family = AF_INET6; - sin6.sin6_len = sizeof(sin6); - sin6.sin6_addr = *a; - - if (IN6_IS_ADDR_LINKLOCAL(a) && - *(u_int16_t *)&sin6.sin6_addr.s6_addr[2] != 0) { - sin6.sin6_scope_id = -ntohs(*(uint16_t *)&sin6.sin6_addr.s6_addr[2]); - sin6.sin6_addr.s6_addr[2] = 0; - sin6.sin6_addr.s6_addr[3] = 0; - } - - if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len, - addr, sizeof(addr), NULL, 0, niflags)) - if (inet_ntop(AF_INET6, a, addr, sizeof(addr)) == NULL) -strlcpy(addr, "invalid", sizeof(addr)); + snprintf(buf, len, "*:%s", serv); + return buf; } - if (addr[0]) - snprintf(buf, len, "[%s]:%u", addr, p); + + if (strchr(addr, ':') == NULL) + snprintf(buf, len, "%s:%s", addr, serv); else - strlcpy(buf, addr, len); + snprintf(buf, len, "[%s]:%s", addr, serv); return buf; }
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: christos Date: Sat Mar 24 21:51:23 UTC 2012 Modified Files: src/usr.bin/fstat: fstat.c Log Message: byte swap the inet6 ports. To generate a diff of this commit: cvs rdiff -u -r1.95 -r1.96 src/usr.bin/fstat/fstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/fstat.c diff -u src/usr.bin/fstat/fstat.c:1.95 src/usr.bin/fstat/fstat.c:1.96 --- src/usr.bin/fstat/fstat.c:1.95 Sun Oct 9 17:16:00 2011 +++ src/usr.bin/fstat/fstat.c Sat Mar 24 17:51:23 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: fstat.c,v 1.95 2011/10/09 21:16:00 chs Exp $ */ +/* $NetBSD: fstat.c,v 1.96 2012/03/24 21:51:23 christos Exp $ */ /*- * Copyright (c) 1988, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19 #if 0 static char sccsid[] = "@(#)fstat.c 8.3 (Berkeley) 5/2/95"; #else -__RCSID("$NetBSD: fstat.c,v 1.95 2011/10/09 21:16:00 chs Exp $"); +__RCSID("$NetBSD: fstat.c,v 1.96 2012/03/24 21:51:23 christos Exp $"); #endif #endif /* not lint */ @@ -974,9 +974,9 @@ socktrans(struct socket *sock, int i) goto bad; } inet6_addrstr(lbuf, sizeof(lbuf), &in6pcb.in6p_laddr, - in6pcb.in6p_lport); + ntohs(in6pcb.in6p_lport)); inet6_addrstr(fbuf, sizeof(fbuf), &in6pcb.in6p_faddr, - in6pcb.in6p_fport); + ntohs(in6pcb.in6p_fport)); break; default: break;
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: chs Date: Sun Oct 9 21:16:00 UTC 2011 Modified Files: src/usr.bin/fstat: fstat.c Log Message: fix rdev reporting for UFS2 and ext2fs. To generate a diff of this commit: cvs rdiff -u -r1.94 -r1.95 src/usr.bin/fstat/fstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/fstat.c diff -u src/usr.bin/fstat/fstat.c:1.94 src/usr.bin/fstat/fstat.c:1.95 --- src/usr.bin/fstat/fstat.c:1.94 Fri Sep 23 07:31:39 2011 +++ src/usr.bin/fstat/fstat.c Sun Oct 9 21:16:00 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: fstat.c,v 1.94 2011/09/23 07:31:39 mrg Exp $ */ +/* $NetBSD: fstat.c,v 1.95 2011/10/09 21:16:00 chs Exp $ */ /*- * Copyright (c) 1988, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19 #if 0 static char sccsid[] = "@(#)fstat.c 8.3 (Berkeley) 5/2/95"; #else -__RCSID("$NetBSD: fstat.c,v 1.94 2011/09/23 07:31:39 mrg Exp $"); +__RCSID("$NetBSD: fstat.c,v 1.95 2011/10/09 21:16:00 chs Exp $"); #endif #endif /* not lint */ @@ -57,12 +57,13 @@ __RCSID("$NetBSD: fstat.c,v 1.94 2011/09 #include #include #include +#define _KERNEL +#include +#undef _KERNEL #define _KERNEL #include #include -#undef _KERNEL -#define _KERNEL -#include +#include #undef _KERNEL #define NFS #include @@ -583,6 +584,7 @@ static int ufs_filestat(struct vnode *vp, struct filestat *fsp) { struct inode inode; + struct ufsmount ufsmount; union dinode { struct ufs1_dinode dp1; struct ufs2_dinode dp2; @@ -593,23 +595,35 @@ ufs_filestat(struct vnode *vp, struct fi return 0; } - if (!KVM_READ(inode.i_din.ffs1_din, &dip, sizeof(struct ufs1_dinode))) { - dprintf("can't read dinode at %p for pid %d", - inode.i_din.ffs1_din, Pid); + if (!KVM_READ(inode.i_ump, &ufsmount, sizeof (struct ufsmount))) { + dprintf("can't read ufsmount at %p for pid %d", inode.i_ump, Pid); return 0; } - if (inode.i_size == dip.dp1.di_size) - fsp->rdev = dip.dp1.di_rdev; - else { + + switch (ufsmount.um_fstype) { + case UFS1: if (!KVM_READ(inode.i_din.ffs1_din, &dip, + sizeof(struct ufs1_dinode))) { + dprintf("can't read dinode at %p for pid %d", +inode.i_din.ffs1_din, Pid); + return 0; + } + fsp->rdev = dip.dp1.di_rdev; + break; + case UFS2: + if (!KVM_READ(inode.i_din.ffs2_din, &dip, sizeof(struct ufs2_dinode))) { dprintf("can't read dinode at %p for pid %d", - inode.i_din.ffs1_din, Pid); + inode.i_din.ffs2_din, Pid); return 0; } fsp->rdev = dip.dp2.di_rdev; + break; + default: + dprintf("unknown ufs type %ld for pid %d", + ufsmount.um_fstype, Pid); + break; } - fsp->fsid = inode.i_dev & 0x; fsp->fileid = inode.i_number; fsp->mode = (mode_t)inode.i_mode; @@ -622,8 +636,7 @@ static int ext2fs_filestat(struct vnode *vp, struct filestat *fsp) { struct inode inode; - u_int16_t mode; - u_int32_t size; + struct ext2fs_dinode dinode; if (!KVM_READ(VTOI(vp), &inode, sizeof (inode))) { dprintf("can't read inode at %p for pid %d", VTOI(vp), Pid); @@ -632,20 +645,15 @@ ext2fs_filestat(struct vnode *vp, struct fsp->fsid = inode.i_dev & 0x; fsp->fileid = inode.i_number; - if (!KVM_READ(&inode.i_e2fs_mode, &mode, sizeof mode)) { - dprintf("can't read inode %p's mode at %p for pid %d", VTOI(vp), - &inode.i_e2fs_mode, Pid); + if (!KVM_READ(inode.i_din.e2fs_din, &dinode, sizeof dinode)) { + dprintf("can't read ext2fs_dinode at %p for pid %d", + inode.i_din.e2fs_din, Pid); return 0; } - fsp->mode = mode; + fsp->mode = dinode.e2di_mode; + fsp->size = dinode.e2di_size; + fsp->rdev = dinode.e2di_rdev; - if (!KVM_READ(&inode.i_e2fs_size, &size, sizeof size)) { - dprintf("can't read inode %p's size at %p for pid %d", VTOI(vp), - &inode.i_e2fs_size, Pid); - return 0; - } - fsp->size = size; - fsp->rdev = 0; /* XXX */ return 1; }
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: jnemeth Date: Sat Oct 8 22:16:03 UTC 2011 Modified Files: src/usr.bin/fstat: fstat.1 Log Message: add an xref to fstat(2) To generate a diff of this commit: cvs rdiff -u -r1.29 -r1.30 src/usr.bin/fstat/fstat.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/fstat.1 diff -u src/usr.bin/fstat/fstat.1:1.29 src/usr.bin/fstat/fstat.1:1.30 --- src/usr.bin/fstat/fstat.1:1.29 Tue Sep 6 19:22:05 2011 +++ src/usr.bin/fstat/fstat.1 Sat Oct 8 22:16:03 2011 @@ -1,4 +1,4 @@ -.\" $NetBSD: fstat.1,v 1.29 2011/09/06 19:22:05 wiz Exp $ +.\" $NetBSD: fstat.1,v 1.30 2011/10/08 22:16:03 jnemeth Exp $ .\" .\" Copyright (c) 1987, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -248,6 +248,7 @@ is used to indicate an INADDR_ANY bindin .Xr sockstat 1 , .Xr systat 1 , .Xr vmstat 1 , +.Xr fstat 2 , .Xr iostat 8 , .Xr pstat 8 .Sh HISTORY
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: mrg Date: Fri Sep 23 07:31:39 UTC 2011 Modified Files: src/usr.bin/fstat: fstat.c Log Message: apply some (uintptr_t) so that printing printers works on i386 (likely all 32 bit.) To generate a diff of this commit: cvs rdiff -u -r1.93 -r1.94 src/usr.bin/fstat/fstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/fstat.c diff -u src/usr.bin/fstat/fstat.c:1.93 src/usr.bin/fstat/fstat.c:1.94 --- src/usr.bin/fstat/fstat.c:1.93 Thu Sep 22 17:27:50 2011 +++ src/usr.bin/fstat/fstat.c Fri Sep 23 07:31:39 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: fstat.c,v 1.93 2011/09/22 17:27:50 christos Exp $ */ +/* $NetBSD: fstat.c,v 1.94 2011/09/23 07:31:39 mrg Exp $ */ /*- * Copyright (c) 1988, 1993 @@ -39,7 +39,7 @@ #if 0 static char sccsid[] = "@(#)fstat.c 8.3 (Berkeley) 5/2/95"; #else -__RCSID("$NetBSD: fstat.c,v 1.93 2011/09/22 17:27:50 christos Exp $"); +__RCSID("$NetBSD: fstat.c,v 1.94 2011/09/23 07:31:39 mrg Exp $"); #endif #endif /* not lint */ @@ -1032,14 +1032,14 @@ default: /* print protocol number and socket address */ snprintf(fbuf, sizeof(fbuf), " %d %jx", proto.pr_protocol, - (uintmax_t)sock); + (uintmax_t)(uintptr_t)sock); break; } if (fbuf[0] || lbuf[0]) printf(" %s%s%s", fbuf, (fbuf[0] && lbuf[0]) ? " <-> " : "", lbuf); else if (so.so_pcb) - printf(" %jx", (uintmax_t)so.so_pcb); + printf(" %jx", (uintmax_t)(uintptr_t)so.so_pcb); (void)printf("\n"); return; bad:
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: christos Date: Thu Sep 22 17:27:50 UTC 2011 Modified Files: src/usr.bin/fstat: fstat.c Log Message: - factor out common code in the inet and inet6 printing. - add appletalk (ddp) support. To generate a diff of this commit: cvs rdiff -u -r1.92 -r1.93 src/usr.bin/fstat/fstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/fstat.c diff -u src/usr.bin/fstat/fstat.c:1.92 src/usr.bin/fstat/fstat.c:1.93 --- src/usr.bin/fstat/fstat.c:1.92 Sat Sep 10 14:35:28 2011 +++ src/usr.bin/fstat/fstat.c Thu Sep 22 13:27:50 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: fstat.c,v 1.92 2011/09/10 18:35:28 christos Exp $ */ +/* $NetBSD: fstat.c,v 1.93 2011/09/22 17:27:50 christos Exp $ */ /*- * Copyright (c) 1988, 1993 @@ -39,7 +39,7 @@ #if 0 static char sccsid[] = "@(#)fstat.c 8.3 (Berkeley) 5/2/95"; #else -__RCSID("$NetBSD: fstat.c,v 1.92 2011/09/10 18:35:28 christos Exp $"); +__RCSID("$NetBSD: fstat.c,v 1.93 2011/09/22 17:27:50 christos Exp $"); #endif #endif /* not lint */ @@ -91,6 +91,9 @@ #include #endif +#include +#include + #include #include @@ -153,13 +156,18 @@ static int ext2fs_filestat(struct vnode *, struct filestat *); static int getfname(const char *); static void getinetproto(int); +static void getatproto(int); static char *getmnton(struct mount *); static const char *layer_filestat(struct vnode *, struct filestat *); static int msdosfs_filestat(struct vnode *, struct filestat *); static int nfs_filestat(struct vnode *, struct filestat *); +static const char *inet_addrstr(char *, size_t, const struct in_addr *, +uint16_t); #ifdef INET6 -static const char *inet6_addrstr(struct in6_addr *); +static const char *inet6_addrstr(char *, size_t, const struct in6_addr *, +uint16_t); #endif +static const char *at_addrstr(char *, size_t, const struct sockaddr_at *); static void socktrans(struct socket *, int); static void misctrans(struct file *); static int ufs_filestat(struct vnode *, struct filestat *); @@ -748,33 +756,110 @@ return mt->mntonname; } +static const char * +inet_addrstr(char *buf, size_t len, const struct in_addr *a, uint16_t p) +{ + char addr[256]; + + if (a->s_addr == INADDR_ANY) { + if (p == 0) + addr[0] = '\0'; + else + strlcpy(addr, "*", sizeof(addr)); + } else { + struct sockaddr_in sin; + const int niflags = NI_NUMERICHOST; + + (void)memset(&sin, 0, sizeof(sin)); + sin.sin_family = AF_INET6; + sin.sin_len = sizeof(sin); + sin.sin_addr = *a; + + if (getnameinfo((struct sockaddr *)&sin, sin.sin_len, + addr, sizeof(addr), NULL, 0, niflags)) + if (inet_ntop(AF_INET, a, addr, sizeof(addr)) == NULL) +strlcpy(addr, "invalid", sizeof(addr)); + } + if (addr[0]) + snprintf(buf, len, "%s:%u", addr, p); + else + strlcpy(buf, addr, len); + return buf; +} + #ifdef INET6 static const char * -inet6_addrstr(struct in6_addr *p) +inet6_addrstr(char *buf, size_t len, const struct in6_addr *a, uint16_t p) { - struct sockaddr_in6 sin6; - static char hbuf[NI_MAXHOST]; - const int niflags = NI_NUMERICHOST; - - (void)memset(&sin6, 0, sizeof(sin6)); - sin6.sin6_family = AF_INET6; - sin6.sin6_len = sizeof(struct sockaddr_in6); - sin6.sin6_addr = *p; - if (IN6_IS_ADDR_LINKLOCAL(p) && - *(u_int16_t *)&sin6.sin6_addr.s6_addr[2] != 0) { - sin6.sin6_scope_id = - ntohs(*(u_int16_t *)&sin6.sin6_addr.s6_addr[2]); - sin6.sin6_addr.s6_addr[2] = sin6.sin6_addr.s6_addr[3] = 0; - } - - if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len, - hbuf, sizeof(hbuf), NULL, 0, niflags)) - return "invalid"; + char addr[256]; - return hbuf; + if (IN6_IS_ADDR_UNSPECIFIED(a)) { + if (p == 0) + addr[0] = '\0'; + else + strlcpy(addr, "*", sizeof(addr)); + } else { + struct sockaddr_in6 sin6; + const int niflags = NI_NUMERICHOST; + + (void)memset(&sin6, 0, sizeof(sin6)); + sin6.sin6_family = AF_INET6; + sin6.sin6_len = sizeof(sin6); + sin6.sin6_addr = *a; + + if (IN6_IS_ADDR_LINKLOCAL(a) && + *(u_int16_t *)&sin6.sin6_addr.s6_addr[2] != 0) { + sin6.sin6_scope_id = +ntohs(*(uint16_t *)&sin6.sin6_addr.s6_addr[2]); + sin6.sin6_addr.s6_addr[2] = 0; + sin6.sin6_addr.s6_addr[3] = 0; + } + + if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len, + addr, sizeof(addr), NULL, 0, niflags)) + if (inet_ntop(AF_INET6, a, addr, sizeof(addr)) == NULL) +strlcpy(addr, "invalid", sizeof(addr)); + } + if (addr[0]) + snprintf(buf, len, "[%s]:%u", addr, p); + else + strlcpy(buf, addr, len); + + return buf; } #endif +static const char * +at_addrstr(char *buf, size_t len, const struct sockaddr_at *sat) +{ + const struct netrange *nr = &sat->sat_range.r_netrange; + const struct at_addr *at = &sat->sat_addr; + char addr[64], phase[64], range[64]; + + if (sat->sat_port || at->s_net || at->s_node) { + if (at->s_net || at->s_node) + snprintf(addr, sizeof(addr), "%u.%u:%u", + nt
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: christos Date: Sat Sep 10 18:35:28 UTC 2011 Modified Files: src/usr.bin/fstat: fstat.c Log Message: - remove bogus casts - print recycled vnode flags To generate a diff of this commit: cvs rdiff -u -r1.91 -r1.92 src/usr.bin/fstat/fstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/fstat.c diff -u src/usr.bin/fstat/fstat.c:1.91 src/usr.bin/fstat/fstat.c:1.92 --- src/usr.bin/fstat/fstat.c:1.91 Sat Sep 3 09:24:19 2011 +++ src/usr.bin/fstat/fstat.c Sat Sep 10 14:35:28 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: fstat.c,v 1.91 2011/09/03 13:24:19 christos Exp $ */ +/* $NetBSD: fstat.c,v 1.92 2011/09/10 18:35:28 christos Exp $ */ /*- * Copyright (c) 1988, 1993 @@ -39,7 +39,7 @@ #if 0 static char sccsid[] = "@(#)fstat.c 8.3 (Berkeley) 5/2/95"; #else -__RCSID("$NetBSD: fstat.c,v 1.91 2011/09/03 13:24:19 christos Exp $"); +__RCSID("$NetBSD: fstat.c,v 1.92 2011/09/10 18:35:28 christos Exp $"); #endif #endif /* not lint */ @@ -106,6 +106,7 @@ #include #include #include +#include #include "fstat.h" @@ -358,7 +359,7 @@ * ktrace vnode, if one */ if (p->p_tracep) - ftrans((struct file *)(intptr_t)p->p_tracep, TRACE); + ftrans(p->p_tracep, TRACE); #endif /* * open files @@ -398,15 +399,15 @@ } switch (file.f_type) { case DTYPE_VNODE: - vtrans((struct vnode *)file.f_data, i, file.f_flag); + vtrans(file.f_data, i, file.f_flag); break; case DTYPE_SOCKET: if (checkfile == 0) - socktrans((struct socket *)file.f_data, i); + socktrans(file.f_data, i); break; case DTYPE_PIPE: if (checkfile == 0) - ptrans(&file, (struct pipe *)file.f_data, i); + ptrans(&file, file.f_data, i); break; case DTYPE_MISC: case DTYPE_KQUEUE: @@ -423,17 +424,22 @@ } } +static const char dead[] = "dead"; + static const char * vfilestat(struct vnode *vp, struct filestat *fsp) { const char *badtype = NULL; - if (vp->v_type == VNON || vp->v_tag == VT_NON) + if (vp->v_type == VNON) badtype = "none"; else if (vp->v_type == VBAD) badtype = "bad"; else switch (vp->v_tag) { + case VT_NON: + badtype = dead; + break; case VT_UFS: case VT_LFS: case VT_MFS: @@ -502,7 +508,7 @@ int fsmatch = 0; DEVS *d; - if (badtype) + if (badtype && badtype != dead) return; for (d = devs; d != NULL; d = d->next) if (d->fsid == fst.fsid) { @@ -516,7 +522,13 @@ return; } PREFIX(i); - if (badtype) { + if (badtype == dead) { + char buf[1024]; + (void)snprintb(buf, sizeof(buf), VNODE_FLAGBITS, + vn.v_iflag | vn.v_vflag | vn.v_uflag); + (void)printf(" flags %s\n", buf); + return; + } else if (badtype) { (void)printf(" - - %10s-\n", badtype); return; }
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: christos Date: Sat Sep 10 18:34:54 UTC 2011 Modified Files: src/usr.bin/fstat: Makefile Log Message: add libutil. To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/usr.bin/fstat/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/Makefile diff -u src/usr.bin/fstat/Makefile:1.22 src/usr.bin/fstat/Makefile:1.23 --- src/usr.bin/fstat/Makefile:1.22 Tue Apr 14 18:15:20 2009 +++ src/usr.bin/fstat/Makefile Sat Sep 10 14:34:54 2011 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.22 2009/04/14 22:15:20 lukem Exp $ +# $NetBSD: Makefile,v 1.23 2011/09/10 18:34:54 christos Exp $ # from: @(#)Makefile 8.1 (Berkeley) 6/6/93 .include @@ -17,4 +17,7 @@ CPPFLAGS+=-DINET6 .endif +LDADD+=-lutil +DPADD+=${LIBUTIL} + .include
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: christos Date: Sat Sep 10 18:34:40 UTC 2011 Modified Files: src/usr.bin/fstat: misc.c Log Message: add all the possible fileops here, and if there is one we know about print that instead of the passed name. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/usr.bin/fstat/misc.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/misc.c diff -u src/usr.bin/fstat/misc.c:1.7 src/usr.bin/fstat/misc.c:1.8 --- src/usr.bin/fstat/misc.c:1.7 Mon Jul 13 17:44:32 2009 +++ src/usr.bin/fstat/misc.c Sat Sep 10 14:34:40 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: misc.c,v 1.7 2009/07/13 21:44:32 christos Exp $ */ +/* $NetBSD: misc.c,v 1.8 2011/09/10 18:34:40 christos Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__RCSID("$NetBSD: misc.c,v 1.7 2009/07/13 21:44:32 christos Exp $"); +__RCSID("$NetBSD: misc.c,v 1.8 2011/09/10 18:34:40 christos Exp $"); #define _KMEMUSER #include @@ -59,23 +59,41 @@ #include "fstat.h" static struct nlist nl[] = { -#define NL_KQUEUE 0 +#define NL_BPF 0 +{ .n_name = "bpf_fileops", }, +#define NL_CRYPTO 1 +{ .n_name = "cryptofops" }, +#define NL_DMIO 2 +{ .n_name = "dmio_fileops", }, +#define NL_DRVCTL 3 +{ .n_name = "drvctl_fileops", }, +#define NL_DTV_DEMUX 4 +{ .n_name = "dtv_demux_fileops", }, +#define NL_FILEMON 5 +{ .n_name = "filemon_fileops", }, +#define NL_KQUEUE 6 { .n_name = "kqueueops" }, -#define NL_MQUEUE 1 +#define NL_MQUEUE 7 { .n_name = "mqops" }, -#define NL_PIPE 2 +#define NL_PIPE 8 { .n_name = "pipeops" }, -#define NL_SOCKET 3 +#define NL_PUTTER 9 +{ .n_name = "putter_fileops", }, +#define NL_SEM 10 +{ .n_name = "semops", }, +#define NL_SOCKET 11 { .n_name = "socketops" }, -#define NL_VNOPS 4 -{ .n_name = "vnops" }, -#define NL_CRYPTO 5 -{ .n_name = "cryptofops" }, -#define NL_BPF 6 -{ .n_name = "bpf_fileops", }, -#define NL_TAP 7 +#define NL_SVR4_NET 12 +{ .n_name = "svr4_netops" }, +#define NL_SVR4_32_NET 13 +{ .n_name = "svr4_32_netops" }, +#define NL_TAP 14 { .n_name = "tap_fileops", }, -#define NL_MAX 8 +#define NL_VNOPS 15 +{ .n_name = "vnops" }, +#define NL_XENEVT 16 +{ .n_name = "xenevt_fileops" }, +#define NL_MAX 17 { .n_name = NULL } }; @@ -166,8 +184,11 @@ case NL_CRYPTO: printf("* crypto %p\n", f->f_data); return 0; - default: + case NL_MAX: printf("* %s %p\n", name, f->f_data); return 0; + default: + printf("* %s %p\n", nl[i].n_name, f->f_data); + return 0; } }
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: wiz Date: Tue Sep 6 19:22:05 UTC 2011 Modified Files: src/usr.bin/fstat: fstat.1 Log Message: Remove trailing whitespace and use Sx for section crossreference. To generate a diff of this commit: cvs rdiff -u -r1.28 -r1.29 src/usr.bin/fstat/fstat.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/fstat.1 diff -u src/usr.bin/fstat/fstat.1:1.28 src/usr.bin/fstat/fstat.1:1.29 --- src/usr.bin/fstat/fstat.1:1.28 Tue Sep 6 11:31:47 2011 +++ src/usr.bin/fstat/fstat.1 Tue Sep 6 19:22:05 2011 @@ -1,4 +1,4 @@ -.\" $NetBSD: fstat.1,v 1.28 2011/09/06 11:31:47 christos Exp $ +.\" $NetBSD: fstat.1,v 1.29 2011/09/06 19:22:05 wiz Exp $ .\" .\" Copyright (c) 1987, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -64,7 +64,9 @@ .Pa /usr/src resides, type .Dq Li fstat -f /usr/src . -Please see the BUGS section for issues with this option. +Please see the +.Sx BUGS +section for issues with this option. .It Fl M Extract values associated with the name list from the specified core instead of the default @@ -214,7 +216,7 @@ command would print for TCP, UDP, and .Ux domain. -For kernels compiled with +For kernels compiled with .Dv PIPE_SOCKETPAIR pipes appear as connected .Ux
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: christos Date: Tue Sep 6 11:31:47 UTC 2011 Modified Files: src/usr.bin/fstat: fstat.1 Log Message: move UNIX socket mention in the BUGS section. To generate a diff of this commit: cvs rdiff -u -r1.27 -r1.28 src/usr.bin/fstat/fstat.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/fstat.1 diff -u src/usr.bin/fstat/fstat.1:1.27 src/usr.bin/fstat/fstat.1:1.28 --- src/usr.bin/fstat/fstat.1:1.27 Mon Sep 5 14:27:31 2011 +++ src/usr.bin/fstat/fstat.1 Tue Sep 6 07:31:47 2011 @@ -1,4 +1,4 @@ -.\" $NetBSD: fstat.1,v 1.27 2011/09/05 18:27:31 wiz Exp $ +.\" $NetBSD: fstat.1,v 1.28 2011/09/06 11:31:47 christos Exp $ .\" .\" Copyright (c) 1987, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" from: @(#)fstat.1 8.3 (Berkeley) 2/25/94 .\" -.Dd September 3, 2011 +.Dd September 5, 2011 .Dt FSTAT 1 .Os .Sh NAME @@ -64,14 +64,7 @@ .Pa /usr/src resides, type .Dq Li fstat -f /usr/src . -Note that this will not list -.Dv AF_LOCAL -domain sockets open in the file system. -To find all the -.Dv AF_LOCAL -domain sockets, use -.Nm -to list all the sockets, and look for the ones that belong in the file system. +Please see the BUGS section for issues with this option. .It Fl M Extract values associated with the name list from the specified core instead of the default @@ -207,9 +200,11 @@ For TCP, it is the address of the tcpcb, and for UDP, the inpcb (socket pcb). For .Ux -domain sockets, its the address of the socket pcb and the address -of the connected pcb (if connected). -Otherwise the protocol number and address of the socket itself are printed. +domain sockets, its the address of the socket pcb and the name of the +file if available. +Otherwise the address of the connected pcb is printed (if connected). +For other domains, the protocol number and address of the socket itself +are printed. The attempt is to make enough information available to permit further analysis without duplicating .Xr netstat 1 . @@ -219,10 +214,11 @@ command would print for TCP, UDP, and .Ux domain. -Note that since pipes are implemented using sockets, a pipe appears as a -connected +For kernels compiled with +.Dv PIPE_SOCKETPAIR +pipes appear as connected .Ux -domain stream socket. +domain stream sockets. A unidirectional .Ux domain socket indicates the direction of flow with an arrow @@ -268,3 +264,16 @@ .Nm does not attempt to translate the internet address and port numbers into symbolic names. +.Pp +Note that the +.Fl f +option will not list +.Ux +domain sockets open in the file system, because the pathnames in the sockets +may not be absolute and are not deterministic. +To find all the +.Ux +domain sockets, use +.Nm +to list all the sockets, and look for the ones that maybe belong in the +file system.
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: wiz Date: Mon Sep 5 18:27:31 UTC 2011 Modified Files: src/usr.bin/fstat: fstat.1 Log Message: Remove duplicate RCS Id and split file system. To generate a diff of this commit: cvs rdiff -u -r1.26 -r1.27 src/usr.bin/fstat/fstat.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/fstat.1 diff -u src/usr.bin/fstat/fstat.1:1.26 src/usr.bin/fstat/fstat.1:1.27 --- src/usr.bin/fstat/fstat.1:1.26 Sat Sep 3 13:22:55 2011 +++ src/usr.bin/fstat/fstat.1 Mon Sep 5 18:27:31 2011 @@ -1,4 +1,4 @@ -.\" $NetBSD: fstat.1,v 1.26 2011/09/03 13:22:55 christos Exp $ +.\" $NetBSD: fstat.1,v 1.27 2011/09/05 18:27:31 wiz Exp $ .\" .\" Copyright (c) 1987, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -28,7 +28,6 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)fstat.1 8.3 (Berkeley) 2/25/94 -.\" $NetBSD: fstat.1,v 1.26 2011/09/03 13:22:55 christos Exp $ .\" .Dd September 3, 2011 .Dt FSTAT 1 @@ -57,22 +56,22 @@ Options: .Bl -tag -width Ds .It Fl f -Restrict examination to files open in the same filesystems as -the named file arguments, or to the filesystem containing the +Restrict examination to files open in the same file systems as +the named file arguments, or to the file system containing the current directory if there are no additional filename arguments. -For example, to find all files open in the filesystem where the +For example, to find all files open in the file system where the directory .Pa /usr/src resides, type .Dq Li fstat -f /usr/src . Note that this will not list .Dv AF_LOCAL -domain sockets open in the filesystem. +domain sockets open in the file system. To find all the .Dv AF_LOCAL domain sockets, use .Nm -to list all the sockets, and look for the ones that belong in the filesystem. +to list all the sockets, and look for the ones that belong in the file system. .It Fl M Extract values associated with the name list from the specified core instead of the default @@ -82,7 +81,7 @@ .Pa /netbsd . .It Fl n Numerical format. -Print the device number (maj,min) of the filesystem +Print the device number (maj,min) of the file system the file resides in rather than the mount point name; for special files, print the device number that the special device refers to rather than the filename @@ -146,7 +145,7 @@ If the .Fl n flag wasn't specified, this header is present and is the -pathname that the filesystem the file resides in is mounted on. +pathname that the file system the file resides in is mounted on. .It Li DEV If the .Fl n @@ -185,7 +184,7 @@ .Dq w indicates open for writing. This field is useful when trying to find the processes that are -preventing a filesystem from being downgraded to read-only. +preventing a file system from being downgraded to read-only. .It Li NAME If filename arguments are specified and the .Fl f
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: christos Date: Sat Sep 3 13:24:19 UTC 2011 Modified Files: src/usr.bin/fstat: fstat.c Log Message: - minor KNF - for system processes (0, 1) where fd_lastfile == -1, fail early. - instead of printing the pcb connection address, print the pathname if possible for unix domain sockets. To generate a diff of this commit: cvs rdiff -u -r1.90 -r1.91 src/usr.bin/fstat/fstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/fstat.c diff -u src/usr.bin/fstat/fstat.c:1.90 src/usr.bin/fstat/fstat.c:1.91 --- src/usr.bin/fstat/fstat.c:1.90 Wed Apr 13 20:35:35 2011 +++ src/usr.bin/fstat/fstat.c Sat Sep 3 09:24:19 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: fstat.c,v 1.90 2011/04/14 00:35:35 rmind Exp $ */ +/* $NetBSD: fstat.c,v 1.91 2011/09/03 13:24:19 christos Exp $ */ /*- * Copyright (c) 1988, 1993 @@ -39,7 +39,7 @@ #if 0 static char sccsid[] = "@(#)fstat.c 8.3 (Berkeley) 5/2/95"; #else -__RCSID("$NetBSD: fstat.c,v 1.90 2011/04/14 00:35:35 rmind Exp $"); +__RCSID("$NetBSD: fstat.c,v 1.91 2011/09/03 13:24:19 christos Exp $"); #endif #endif /* not lint */ @@ -322,11 +322,15 @@ if (p->p_fd == 0 || p->p_cwdi == 0) return; if (!KVM_READ(p->p_fd, &filed, sizeof (filed))) { - warnx("can't read filedesc at %p for pid %d", (void *)(uintptr_t)p->p_fd, Pid); + warnx("can't read filedesc at %p for pid %d", + (void *)(uintptr_t)p->p_fd, Pid); return; } + if (filed.fd_lastfile == -1) + return; if (!KVM_READ(p->p_cwdi, &cwdi, sizeof(cwdi))) { - warnx("can't read cwdinfo at %p for pid %d", (void *)(uintptr_t)p->p_cwdi, Pid); + warnx("can't read cwdinfo at %p for pid %d", + (void *)(uintptr_t)p->p_cwdi, Pid); return; } if (!KVM_READ(filed.fd_dt, &dt, sizeof(dt))) { @@ -335,7 +339,8 @@ } if ((unsigned)filed.fd_lastfile >= dt.dt_nfiles || filed.fd_freefile > filed.fd_lastfile + 1) { - dprintf("filedesc corrupted at %p for pid %d", (void *)(uintptr_t)p->p_fd, Pid); + dprintf("filedesc corrupted at %p for pid %d", + (void *)(uintptr_t)p->p_fd, Pid); return; } /* @@ -476,7 +481,7 @@ break; } } - return (badtype); + return badtype; } static void @@ -685,21 +690,21 @@ if (!KVM_READ(VTOLAYER(vp), &layer_node, sizeof(layer_node))) { dprintf("can't read layer_node at %p for pid %d", VTOLAYER(vp), Pid); - return ("error"); + return "error"; } if (!KVM_READ(vp->v_mount, &mount, sizeof(struct mount))) { dprintf("can't read mount struct at %p for pid %d", vp->v_mount, Pid); - return ("error"); + return "error"; } vp = layer_node.layer_lowervp; if (!KVM_READ(vp, &vn, sizeof(struct vnode))) { dprintf("can't read vnode at %p for pid %d", vp, Pid); - return ("error"); + return "error"; } if ((badtype = vfilestat(&vn, fsp)) == NULL) fsp->fsid = mount.mnt_stat.f_fsidx.__fsid_val[0]; - return (badtype); + return badtype; } static char * @@ -715,10 +720,10 @@ for (mt = mhead; mt != NULL; mt = mt->next) if (m == mt->m) - return (mt->mntonname); + return mt->mntonname; if (!KVM_READ(m, &mount, sizeof(struct mount))) { warnx("can't read mount table at %p", m); - return (NULL); + return NULL; } if ((mt = malloc(sizeof (struct mtab))) == NULL) { err(1, "malloc(%u)", (unsigned int)sizeof(struct mtab)); @@ -728,7 +733,7 @@ MNAMELEN); mt->next = mhead; mhead = mt; - return (mt->mntonname); + return mt->mntonname; } #ifdef INET6 @@ -925,22 +930,42 @@ case AF_LOCAL: /* print address of pcb and connected pcb */ if (so.so_pcb) { + char shoconn[4], *cp; + (void)printf(" %lx", (long)so.so_pcb); if (kvm_read(kd, (u_long)so.so_pcb, (char *)&unpcb, sizeof(struct unpcb)) != sizeof(struct unpcb)){ dprintf("can't read unpcb at %p", so.so_pcb); goto bad; } - if (unpcb.unp_conn) { -char shoconn[4], *cp; -cp = shoconn; -if (!(so.so_state & SS_CANTRCVMORE)) - *cp++ = '<'; -*cp++ = '-'; -if (!(so.so_state & SS_CANTSENDMORE)) - *cp++ = '>'; -*cp = '\0'; + cp = shoconn; + if (!(so.so_state & SS_CANTRCVMORE)) +*cp++ = '<'; + *cp++ = '-'; + if (!(so.so_state & SS_CANTSENDMORE)) +*cp++ = '>'; + *cp = '\0'; + if (unpcb.unp_addr) { +struct sockaddr_un *sun = + malloc(unpcb.unp_addrlen); +if (sun == NULL) +err(1, "malloc(%zu)", + unpcb.unp_addrlen); +if (kvm_read(kd, (u_long)unpcb.unp_addr, +sun, unpcb.unp_addrlen) != +(ssize_t)unpcb.unp_addrlen) { + dprintf("can't read sun at %p", + unpcb.unp_addr); + free(sun); +} else { + (void)printf(" %s %s", + shoconn, sun->sun_path); + free(sun); + break; +} + } + if (unpcb.unp_conn) { (void)printf(" %s %lx", shoconn, (long)unpcb.unp_conn); } @@ -1037,8 +1062,8 @@ warn("stat(%s)", filename); return 0; } - if
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: christos Date: Sat Sep 3 13:22:56 UTC 2011 Modified Files: src/usr.bin/fstat: fstat.1 Log Message: Mention that fstat -f will not list open unix sockets on that filesystem. To generate a diff of this commit: cvs rdiff -u -r1.25 -r1.26 src/usr.bin/fstat/fstat.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/fstat.1 diff -u src/usr.bin/fstat/fstat.1:1.25 src/usr.bin/fstat/fstat.1:1.26 --- src/usr.bin/fstat/fstat.1:1.25 Sun Jan 4 12:19:39 2009 +++ src/usr.bin/fstat/fstat.1 Sat Sep 3 09:22:55 2011 @@ -1,4 +1,4 @@ -.\" $NetBSD: fstat.1,v 1.25 2009/01/04 17:19:39 wiz Exp $ +.\" $NetBSD: fstat.1,v 1.26 2011/09/03 13:22:55 christos Exp $ .\" .\" Copyright (c) 1987, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -28,9 +28,9 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)fstat.1 8.3 (Berkeley) 2/25/94 -.\" $NetBSD: fstat.1,v 1.25 2009/01/04 17:19:39 wiz Exp $ +.\" $NetBSD: fstat.1,v 1.26 2011/09/03 13:22:55 christos Exp $ .\" -.Dd January 4, 2009 +.Dd September 3, 2011 .Dt FSTAT 1 .Os .Sh NAME @@ -65,6 +65,14 @@ .Pa /usr/src resides, type .Dq Li fstat -f /usr/src . +Note that this will not list +.Dv AF_LOCAL +domain sockets open in the filesystem. +To find all the +.Dv AF_LOCAL +domain sockets, use +.Nm +to list all the sockets, and look for the ones that belong in the filesystem. .It Fl M Extract values associated with the name list from the specified core instead of the default
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: rmind Date: Thu Apr 14 00:35:35 UTC 2011 Modified Files: src/usr.bin/fstat: fstat.c Log Message: Add DTYPE_SEM. To generate a diff of this commit: cvs rdiff -u -r1.89 -r1.90 src/usr.bin/fstat/fstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/fstat.c diff -u src/usr.bin/fstat/fstat.c:1.89 src/usr.bin/fstat/fstat.c:1.90 --- src/usr.bin/fstat/fstat.c:1.89 Sun May 24 21:41:44 2009 +++ src/usr.bin/fstat/fstat.c Thu Apr 14 00:35:35 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: fstat.c,v 1.89 2009/05/24 21:41:44 ad Exp $ */ +/* $NetBSD: fstat.c,v 1.90 2011/04/14 00:35:35 rmind Exp $ */ /*- * Copyright (c) 1988, 1993 @@ -39,7 +39,7 @@ #if 0 static char sccsid[] = "@(#)fstat.c 8.3 (Berkeley) 5/2/95"; #else -__RCSID("$NetBSD: fstat.c,v 1.89 2009/05/24 21:41:44 ad Exp $"); +__RCSID("$NetBSD: fstat.c,v 1.90 2011/04/14 00:35:35 rmind Exp $"); #endif #endif /* not lint */ @@ -407,6 +407,7 @@ case DTYPE_KQUEUE: case DTYPE_CRYPTO: case DTYPE_MQUEUE: + case DTYPE_SEM: if (checkfile == 0) misctrans(&file); break;
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: christos Date: Mon Jul 13 21:44:32 UTC 2009 Modified Files: src/usr.bin/fstat: misc.c Log Message: move _KMEMUSER higher! To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/usr.bin/fstat/misc.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/misc.c diff -u src/usr.bin/fstat/misc.c:1.6 src/usr.bin/fstat/misc.c:1.7 --- src/usr.bin/fstat/misc.c:1.6 Mon Jul 13 17:43:24 2009 +++ src/usr.bin/fstat/misc.c Mon Jul 13 17:44:32 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: misc.c,v 1.6 2009/07/13 21:43:24 christos Exp $ */ +/* $NetBSD: misc.c,v 1.7 2009/07/13 21:44:32 christos Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -30,11 +30,11 @@ */ #include -__RCSID("$NetBSD: misc.c,v 1.6 2009/07/13 21:43:24 christos Exp $"); +__RCSID("$NetBSD: misc.c,v 1.7 2009/07/13 21:44:32 christos Exp $"); +#define _KMEMUSER #include #include -#define _KMEMUSER #include #include #include
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: christos Date: Mon Jul 13 21:43:24 UTC 2009 Modified Files: src/usr.bin/fstat: misc.c Log Message: need _KMEMUSER too. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/usr.bin/fstat/misc.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/misc.c diff -u src/usr.bin/fstat/misc.c:1.5 src/usr.bin/fstat/misc.c:1.6 --- src/usr.bin/fstat/misc.c:1.5 Mon Jul 13 13:57:35 2009 +++ src/usr.bin/fstat/misc.c Mon Jul 13 17:43:24 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: misc.c,v 1.5 2009/07/13 17:57:35 christos Exp $ */ +/* $NetBSD: misc.c,v 1.6 2009/07/13 21:43:24 christos Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -30,10 +30,11 @@ */ #include -__RCSID("$NetBSD: misc.c,v 1.5 2009/07/13 17:57:35 christos Exp $"); +__RCSID("$NetBSD: misc.c,v 1.6 2009/07/13 21:43:24 christos Exp $"); #include #include +#define _KMEMUSER #include #include #include
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: christos Date: Mon Jul 13 17:57:35 UTC 2009 Modified Files: src/usr.bin/fstat: misc.c Log Message: sys/mqueue.h needs sys/types.h now To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/usr.bin/fstat/misc.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/misc.c diff -u src/usr.bin/fstat/misc.c:1.4 src/usr.bin/fstat/misc.c:1.5 --- src/usr.bin/fstat/misc.c:1.4 Sun Apr 12 02:36:12 2009 +++ src/usr.bin/fstat/misc.c Mon Jul 13 13:57:35 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: misc.c,v 1.4 2009/04/12 06:36:12 lukem Exp $ */ +/* $NetBSD: misc.c,v 1.5 2009/07/13 17:57:35 christos Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -30,10 +30,11 @@ */ #include -__RCSID("$NetBSD: misc.c,v 1.4 2009/04/12 06:36:12 lukem Exp $"); +__RCSID("$NetBSD: misc.c,v 1.5 2009/07/13 17:57:35 christos Exp $"); #include #include +#include #include #include #include
CVS commit: src/usr.bin/fstat
Module Name:src Committed By: lukem Date: Sun Apr 12 06:36:12 UTC 2009 Modified Files: src/usr.bin/fstat: fstat.c fstat.h isofs.c misc.c ntfs.c ptyfs.c tmpfs.c Log Message: Fix sign-compare issues. To generate a diff of this commit: cvs rdiff -u -r1.87 -r1.88 src/usr.bin/fstat/fstat.c cvs rdiff -u -r1.8 -r1.9 src/usr.bin/fstat/fstat.h cvs rdiff -u -r1.6 -r1.7 src/usr.bin/fstat/isofs.c cvs rdiff -u -r1.3 -r1.4 src/usr.bin/fstat/misc.c cvs rdiff -u -r1.11 -r1.12 src/usr.bin/fstat/ntfs.c cvs rdiff -u -r1.5 -r1.6 src/usr.bin/fstat/ptyfs.c cvs rdiff -u -r1.7 -r1.8 src/usr.bin/fstat/tmpfs.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/fstat/fstat.c diff -u src/usr.bin/fstat/fstat.c:1.87 src/usr.bin/fstat/fstat.c:1.88 --- src/usr.bin/fstat/fstat.c:1.87 Mon Dec 29 00:59:08 2008 +++ src/usr.bin/fstat/fstat.c Sun Apr 12 06:36:12 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: fstat.c,v 1.87 2008/12/29 00:59:08 christos Exp $ */ +/* $NetBSD: fstat.c,v 1.88 2009/04/12 06:36:12 lukem Exp $ */ /*- * Copyright (c) 1988, 1993 @@ -39,7 +39,7 @@ #if 0 static char sccsid[] = "@(#)fstat.c 8.3 (Berkeley) 5/2/95"; #else -__RCSID("$NetBSD: fstat.c,v 1.87 2008/12/29 00:59:08 christos Exp $"); +__RCSID("$NetBSD: fstat.c,v 1.88 2009/04/12 06:36:12 lukem Exp $"); #endif #endif /* not lint */ @@ -519,7 +519,7 @@ (void)snprintf(mode, sizeof mode, "%o", fst.mode); else strmode(fst.mode, mode); - (void)printf(" %7lu %*s", (unsigned long)fst.fileid, nflg ? 5 : 10, mode); + (void)printf(" %7"PRIu64" %*s", fst.fileid, nflg ? 5 : 10, mode); switch (vn.v_type) { case VBLK: case VCHR: { @@ -580,7 +580,7 @@ } fsp->fsid = inode.i_dev & 0x; - fsp->fileid = (long)inode.i_number; + fsp->fileid = inode.i_number; fsp->mode = (mode_t)inode.i_mode; fsp->size = inode.i_size; @@ -599,7 +599,7 @@ return 0; } fsp->fsid = inode.i_dev & 0x; - fsp->fileid = (long)inode.i_number; + fsp->fileid = inode.i_number; if (!KVM_READ(&inode.i_e2fs_mode, &mode, sizeof mode)) { dprintf("can't read inode %p's mode at %p for pid %d", VTOI(vp), Index: src/usr.bin/fstat/fstat.h diff -u src/usr.bin/fstat/fstat.h:1.8 src/usr.bin/fstat/fstat.h:1.9 --- src/usr.bin/fstat/fstat.h:1.8 Tue Jul 22 22:58:04 2008 +++ src/usr.bin/fstat/fstat.h Sun Apr 12 06:36:12 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: fstat.h,v 1.8 2008/07/22 22:58:04 christos Exp $ */ +/* $NetBSD: fstat.h,v 1.9 2009/04/12 06:36:12 lukem Exp $ */ /*- * Copyright (c) 1988, 1993 * The Regents of the University of California. All rights reserved. @@ -30,7 +30,7 @@ struct filestat { long fsid; - long fileid; + ino_t fileid; mode_t mode; off_t size; dev_t rdev; @@ -40,7 +40,8 @@ * a kvm_read that returns true if everything is read */ #define KVM_READ(kaddr, paddr, len) \ - (kvm_read(kd, (u_long)(kaddr), (void *)(paddr), (len)) == (len)) + ((size_t)kvm_read(kd, (u_long)(kaddr), (void *)(paddr), (len)) \ + == (size_t)(len)) #define KVM_NLIST(nl) \ kvm_nlist(kd, (nl)) #define KVM_GETERR() \ Index: src/usr.bin/fstat/isofs.c diff -u src/usr.bin/fstat/isofs.c:1.6 src/usr.bin/fstat/isofs.c:1.7 --- src/usr.bin/fstat/isofs.c:1.6 Thu May 11 11:56:38 2006 +++ src/usr.bin/fstat/isofs.c Sun Apr 12 06:36:12 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: isofs.c,v 1.6 2006/05/11 11:56:38 yamt Exp $ */ +/* $NetBSD: isofs.c,v 1.7 2009/04/12 06:36:12 lukem Exp $ */ /*- * Copyright (c) 1988, 1993 * The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ */ #include -__RCSID("$NetBSD: isofs.c,v 1.6 2006/05/11 11:56:38 yamt Exp $"); +__RCSID("$NetBSD: isofs.c,v 1.7 2009/04/12 06:36:12 lukem Exp $"); #include #include @@ -54,7 +54,7 @@ return 0; } fsp->fsid = inode.i_dev & 0x; - fsp->fileid = (long)inode.i_number; + fsp->fileid = inode.i_number; fsp->mode = inode.inode.iso_mode; fsp->size = inode.i_size; fsp->rdev = inode.i_dev; Index: src/usr.bin/fstat/misc.c diff -u src/usr.bin/fstat/misc.c:1.3 src/usr.bin/fstat/misc.c:1.4 --- src/usr.bin/fstat/misc.c:1.3 Thu Feb 26 17:30:51 2009 +++ src/usr.bin/fstat/misc.c Sun Apr 12 06:36:12 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: misc.c,v 1.3 2009/02/26 17:30:51 christos Exp $ */ +/* $NetBSD: misc.c,v 1.4 2009/04/12 06:36:12 lukem Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__RCSID("$NetBSD: misc.c,v 1.3 2009/02/26 17:30:51 christos Exp $"); +__RCSID("$NetBSD: misc.c,v 1.4 2009/04/12 06:36:12 lukem Exp $"); #include #include @@ -149,7 +149,7 @@ warnx("Could not find %d symbols", n); } for (i = 0; i < NL_MAX; i++) - if ((intptr_t)f->f_ops == nl[i].n_value) + if ((uintptr_t)f->f_ops == nl[i].n_value) break; switch (i) { case NL_BPF: Index: src/usr.bin/fstat/ntfs.c diff -u src/usr.bin/fstat/ntfs.c:1.11 src/usr.bin/fstat/ntfs.c:1.12 --- src/usr.bin/fstat/ntfs.c:1.11 Mon