diff -Nru dialects/bsdsunix.orig/Makefile dialects/bsdsunix/Makefile --- dialects/bsdsunix.orig/Makefile 1970-01-01 01:00:00.000000000 +0100 +++ dialects/bsdsunix/Makefile 2016-10-03 18:24:47.418696000 +0200 @@ -0,0 +1,162 @@ + +# BSDSUniX Makefile remainder +# +# $Id: Makefile,v 1.12 2009/03/25 19:23:06 abe Exp $ + +PROG= lsof + +BIN= ${DESTDIR} + +DOC= ${DESTDIR} + +I=/usr/include +S=/usr/include/sys +L=/usr/include/local +P= + +CDEF= +CDEFS= ${CDEF} ${CFGF} +INCL= ${DINC} +CFLAGS= ${CDEFS} ${INCL} ${DEBUG} + +GRP= + +HDR= lsof.h lsof_fields.h dlsof.h machine.h proto.h dproto.h dzfs.h + +SRC= dmnt.c dnode.c dnode1.c dnode2.c dproc.c dsock.c dstore.c \ + arg.c main.c misc.c node.c print.c proc.c store.c usage.c \ + util.c + +OBJ= dmnt.o dnode.o dnode1.o dnode2.o dproc.o dsock.o dstore.o \ + arg.o main.o misc.o node.o print.o proc.o store.o usage.o \ + util.o + +MAN= lsof.8 + +OTHER= + +SHELL= /bin/sh + +SOURCE= Makefile ${OTHER} ${MAN} ${HDR} ${SRC} + +all: ${PROG} + +${PROG}: ${LIB} ${P} ${OBJ} + ${CC} -o $@ ${CFLAGS} ${OBJ} ${CFGL} + +clean: FRC + rm -f Makefile.bak ${PROG} a.out core errs lint.out tags *.o version.h + rm -f machine.h.old new_machine.h + (cd lib; ${MAKE} -f Makefile.skel clean) + +install: all FRC + @echo '' + @echo 'Please write your own install rule. Lsof should be installed' + @echo 'setgid to the group that can can read /dev/kmem. Normally' + @echo 'that is the kmem group. Your install rule actions might look' + @echo 'something like this:' + @echo '' + @echo ' install -cs -m 2755 -g $${GRP} $${PROG} $${BIN}/$${PROG}' + @echo ' install -c -m 444 $${MAN} $${DOC}/$${MAN}' + @echo '' + @echo 'You will have to complete the skeletons for the BIN, DOC, and' + @echo 'GRP strings given at the beginning of this Makefile, e.g.,' + @echo '' + @echo ' BIN= $${DESTDIR}/usr/local/etc' + @echo ' DOC= $${DESTDIR}/usr/local/man/man8' + @echo ' GRP= kmem' + @echo '' + +${LIB}: FRC + (cd lib; ${MAKE} DEBUG="${DEBUG}" CFGF="${CFGF}") + +version.h: FRC + @echo Constructing version.h + @rm -f version.h + @echo '#define LSOF_BLDCMT "${LSOF_BLDCMT}"' > version.h; + @echo '#define LSOF_CC "${CC}"' >> version.h + @echo '#define LSOF_CCV "${CCV}"' >> version.h + @echo '#define LSOF_CCDATE "'`date`'"' >> version.h + @echo '#define LSOF_CCFLAGS "'`echo ${CFLAGS} | sed 's/\\\\(/\\(/g' | sed 's/\\\\)/\\)/g' | sed 's/"/\\\\"/g'`'"' >> version.h + @if [ "X${LSOF_HOST}" = "X" ]; then \ + echo '#define LSOF_HOST "'`uname -n`'"' >> version.h; \ + else \ + if [ "${LSOF_HOST}" = "none" ]; then \ + echo '#define LSOF_HOST ""' >> version.h; \ + else \ + echo '#define LSOF_HOST "${LSOF_HOST}"' >> version.h; \ + fi \ + fi + @echo '#define LSOF_LDFLAGS "${CFGL}"' >> version.h + @if [ "X${LSOF_LOGNAME}" = "X" ]; then \ + echo '#define LSOF_LOGNAME "${LOGNAME}"' >> version.h; \ + else \ + if [ "${LSOF_LOGNAME}" = "none" ]; then \ + echo '#define LSOF_LOGNAME ""' >> version.h; \ + else \ + echo '#define LSOF_LOGNAME "${LSOF_LOGNAME}"' >> version.h; \ + fi; \ + fi + @if [ "X${LSOF_SYSINFO}" = "X" ]; then \ + echo '#define LSOF_SYSINFO "'`uname -a`'"' >> version.h; \ + else \ + if [ "${LSOF_SYSINFO}" = "none" ]; then \ + echo '#define LSOF_SYSINFO ""' >> version.h; \ + else \ + echo '#define LSOF_SYSINFO "${LSOF_SYSINFO}"' >> version.h; \ + fi \ + fi + @if [ "X${LSOF_USER}" = "X" ]; then \ + echo '#define LSOF_USER "${USER}"' >> version.h; \ + else \ + if [ "${LSOF_USER}" = "none" ]; then \ + echo '#define LSOF_USER ""' >> version.h; \ + else \ + echo '#define LSOF_USER "${LSOF_USER}"' >> version.h; \ + fi \ + fi + @sed '/VN/s/.ds VN \(.*\)/#define LSOF_VERSION "\1"/' < version >> version.h + +FRC: + +# DO NOT DELETE THIS LINE - make depend DEPENDS ON IT + +dmnt.o: ${HDR} dmnt.c + +dnode.o: ${HDR} dnode.c + +dnode1.o: ${HDR} dnode1.c + +dnode2.o: dzfs.h dnode2.c + @if [ -f ./Makefile.zfs ]; then \ + ${MAKE} -f Makefile.zfs dnode2.o; \ + else \ + echo "${CC} ${CFLAGS} -c dnode2.c"; \ + ${CC} ${CFLAGS} -c dnode2.c; \ + fi; + +dproc.o: ${HDR} dproc.c + +dsock.o: ${HDR} dsock.c + +dstore.o: ${HDR} dstore.c + +arg.o: ${HDR} arg.c + +main.o: ${HDR} main.c + +misc.o: ${HDR} misc.c + +node.o: ${HDR} node.c + +print.o: ${HDR} print.c + +proc.o: ${HDR} proc.c + +store.o: ${HDR} store.c + +usage.o: ${HDR} version.h usage.c + +util.o: ${HDR} util.c + +# *** Do not add anything here - It will go away. *** diff -Nru dialects/bsdsunix.orig/Makefile.zfs dialects/bsdsunix/Makefile.zfs --- dialects/bsdsunix.orig/Makefile.zfs 1970-01-01 01:00:00.000000000 +0100 +++ dialects/bsdsunix/Makefile.zfs 2016-10-03 18:25:00.832825000 +0200 @@ -0,0 +1,17 @@ + +# Makefile.zfs -- BSDSUniX Makefile remainder for ZFS modules +# +# $Id: Makefile.zfs,v 1.3 2011/08/07 22:51:28 abe Exp $ + +CFLAGS+=-D_SOLARIS_C_SOURCE +CFLAGS+=${DEBUG} +CFLAGS+=-I${OPENSOLARIS}/compat/opensolaris +CFLAGS+=-I${OPENSOLARIS}/contrib/opensolaris/uts/common/fs/zfs +CFLAGS+=-I${OPENSOLARIS}/contrib/opensolaris/uts/common/zmod +CFLAGS+=-I${OPENSOLARIS}/contrib/opensolaris/uts/common +CFLAGS+=-I${OPENSOLARIS}/contrib/opensolaris/common/zfs +CFLAGS+=-I${OPENSOLARIS}/contrib/opensolaris/common +CFLAGS+=-I${.CURDIR}/usr/src/include +CFLAGS+=-I`pwd` + +dnode2.o: dzfs.h dnode2.c diff -Nru dialects/bsdsunix.orig/Mksrc dialects/bsdsunix/Mksrc --- dialects/bsdsunix.orig/Mksrc 1970-01-01 01:00:00.000000000 +0100 +++ dialects/bsdsunix/Mksrc 2016-10-03 18:25:20.338834000 +0200 @@ -0,0 +1,29 @@ +#!/bin/sh +# +# Mksrc - make BSDSUniX source files +# +# WARNING: This script assumes it is running from the main directory +# of the lsof, version 4 distribution. +# +# One environment variable applies: +# +# LSOF_MKC is the method for creating the source files. +# It defaults to "ln -s". A common alternative is "cp". +# +# $Id: Mksrc,v 1.5 2008/04/15 13:31:47 abe Exp $ + + +D=dialects/bsdsunix +L="dlsof.h dmnt.c dnode.c dnode1.c dnode2.c dproc.c dproto.h dsock.c dstore.c dzfs.h machine.h" + +for i in $L +do + rm -f $i + $LSOF_MKC $D/$i $i + echo "$LSOF_MKC $D/$i $i" +done + +# For ZFS + +rm -f vnode_if.h +touch vnode_if.h diff -Nru dialects/bsdsunix.orig/dlsof.h dialects/bsdsunix/dlsof.h --- dialects/bsdsunix.orig/dlsof.h 1970-01-01 01:00:00.000000000 +0100 +++ dialects/bsdsunix/dlsof.h 2016-10-03 18:39:01.161224000 +0200 @@ -0,0 +1,523 @@ +/* + * dlsof.h - BSDSUniX header file for lsof + */ + + +/* + * Copyright 1994 Purdue Research Foundation, West Lafayette, Indiana + * 47907. All rights reserved. + * + * Written by Victor A. Abell + * + * This software is not subject to any license of the American Telephone + * and Telegraph Company or the Regents of the University of California. + * + * Permission is granted to anyone to use this software for any purpose on + * any computer system, and to alter it and redistribute it freely, subject + * to the following restrictions: + * + * 1. Neither the authors nor Purdue University are responsible for any + * consequences of the use of this software. + * + * 2. The origin of this software must not be misrepresented, either by + * explicit claim or by omission. Credit to the authors and Purdue + * University must appear in documentation and sources. + * + * 3. Altered versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 4. This notice may not be removed or altered. + */ + + +/* + * $Id: dlsof.h,v 1.47 2015/07/07 20:23:43 abe Exp $ + */ + + +#if !defined(BSDSUNIX_LSOF_H) +#define BSDSUNIX_LSOF_H 1 + +#include +#include +#include +#include +#include +#include + +#define _KERNEL 1 + +# if defined(HAS_VM_MEMATTR_T) +/* + * The d_mmap2_t function typedef in may need the definition + * of vm_memattr_t for a pointer, but that definition is only available + * under _KERNEL in . Defining _KERNEL before including + * causes many compilation problems, so this expediency + * (hack) is used when the vm_memattr_t definition is needed. + */ +#define vm_memattr_t void +# endif /* defined(HAS_VM_MEMATTR_T) */ + +# if defined(NEEDS_BOOLEAN_T) +/* + * In BSDSUniX 1 and above the boolean_t typedef is also needed and is also + * under _KERNEL in . + */ + +#define boolean_t int +# endif /* defined(NEEDS_BOOLEAN_T) */ + +#include + +# if defined(HAS_VM_MEMATTR_T) +#undef vm_memattr_t +# endif /* defined(HAS_VM_MEMATTR_T) */ + +# if defined(NEEDS_BOOLEAN_T) +#undef boolean_t +# endif /* defined(NEEDS_BOOLEAN_T) */ + +# if defined(HAS_CONF_MINOR) +#undef minor +#include "bsdsux_minor.h" +# endif /* defined(HAS_CONF_MINOR) */ + +#undef _KERNEL + +#include +#include +#define NFS +#define m_stat mnt_stat + +#define _KERNEL + +#include + +# if defined(__clang__) +/* + * This definition is needed when clang is used, because must + * be #include'd when _KERNEL is defined and that causes the getmntinfo() + * function prototype to be skipped. + */ +int getmntinfo(struct statfs **, int); +# endif /* defined(__clang__) */ + +#undef _KERNEL + +#include +#include +#include +#include +#include +#include + +#undef INADDR_LOOPBACK + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +# if defined(HAS_KVM_VNODE) +#define _KVM_VNODE +# endif /* defined(HAS_KVM_VNODE) */ +#include +# if defined(HAS_KVM_VNODE) +#undef _KVM_VNODE +# endif /* defined(HAS_KVM_VNODE) */ + +#include +#include +#define pmap RPC_pmap +#include +#include +#undef pmap + +#include +#include + +#include + +# if defined(HAS_UFS1_2) +#define _KERNEL +struct vop_getextattr_args; +struct vop_deleteextattr_args; +struct vop_setextattr_args; +#include +#define psignal LSOF_psignal +#define panicstr bp + +# if defined(__clang__) +/* + * Two clang work-arounds... + */ +#define KASSERT(exp,msg) do {} while (0) +#include +# endif /* defined(__clang__) */ + +#include + +# if defined(__clang__) +/* + * Undo the clang work-arounds. + */ +#undef KASSERT +# endif /* defined(__clang__) */ + +#undef psignal +#undef panicstr +#undef _KERNEL +# endif /* defined(HAS_UFS1_2) */ + +#undef i_devvp + +#include + +# if defined(HASRPCV2H) +#include +# endif /* defined(HASRPCV2H) */ + +#include +#include + +#include +#include +#undef TRUE +#undef FALSE + +#include + +# if defined(HASFDESCFS) +#define _KERNEL +#define KERNEL +#include +#undef _KERNEL +#undef KERNEL +# endif /* defined(HASFDESCFS) */ + +# if defined(HASNULLFS) +#define _KERNEL +#define KERNEL +struct vop_generic_args; +#include +#undef _KERNEL +#undef KERNEL +# endif /* defined(HASNULLFS) */ + +# if defined(HASPROCFS) +#include + +#define PNSIZ 5 +# endif /* defined(HASPROCFS) */ + +# if defined(HASPSEUDOFS) +#include +# endif /* defined(HASPSEUDOFS) */ + +# if defined(HAS_ZFS) +#include "dzfs.h" +# endif /* defined(HAS_ZFS) */ + +#define P_ADDR ki_paddr +#define P_COMM ki_comm +#define P_FD ki_fd +#define P_PID ki_pid +#define P_PGID ki_pgid +#define P_PPID ki_ppid +#define P_STAT ki_stat +#define P_VMSPACE ki_vmspace + +#include + +#define _KERNEL +#define KERNEL +#include + +/* + * The following circumventions were first needed in FreeBSD 8.0-CURRENT some + * time in August 2008 to avoid conflicts in /usr/src/sys/sys/libkern.h> and + * /usr/src/sys/sys/systm.h, called by or the header files it + * #include's when KERNEL or _KERNEL is #define'd. + * + * The circumventions may be needed or may be erroneous for earlier FreeBSD + * versions where testing was not possible. + */ + +# if defined(__clang__) +/* + * This work-around is needed when using clang, because must + * be #include'd under KERNEL and that causes the open() function prototype + * definition to be skipped. + */ +int open(const char *, int, ...); +# endif /* defined(__clang__) */ + +#define intrmask_t int +#define log log_kernel_lsof + +# if !defined(HAS_PAUSE_SBT) +#define pause pause_kernel_lsof +# endif /* !defined(HAS_PAUSE_SBT) */ + +#define asprintf asprintf_kernel_lsof +#define setenv setenv_kernel_lsof +#define vasprintf vasprintf_kernel_lsof +#define uintfptr_t int +#define _SYS_LIBKERN_H_ +#include + +/* + * Attempt to remove the circumventions. + */ + +#undef _SYS_LIBKERN_H_ +#undef asprintf_kernel_lsof +#undef intrmask_t_lsof +#undef log_kernel_lsof + +# if !defined(HAS_PAUSE_SBT) +#undef pause_kernel_lsof +# endif /* !defined(HAS_PAUSE_SBT) */ + +#undef setenv_kernel_lsof +#undef vasprintf_kernel_lsof +#undef uintfptr_t +#undef _KERNEL +#undef KERNEL + +# if defined(DTYPE_KQUEUE) +#define HASKQUEUE /* has the kqueue file type */ +#define _KERNEL +#include +#undef _KERNEL +# endif /* defined(DTYPE_KQUEUE) */ + +struct vop_advlock_args { int dummy; }; /* to pacify lf_advlock() prototype */ +#undef MALLOC_DECLARE +#define MALLOC_DECLARE(type) extern struct malloc_type type[1] + /* to pacify */ +#define _KERNEL + +# if defined(HAS_SYS_SX_H) +#include +# endif /* defined(HAS_SYS_SX_H) */ + +# if defined(HAS_SI_PRIV) || defined(HAS_CONF_MINOR) || defined(HAS_CDEV2PRIV) +#include +# endif /* defined(SI_PRIV) || defined(HAS_CONF_MINOR) || defined(HAS_CDEV2PRIV) */ + +#include +#undef _KERNEL +#include + +#define _KERNEL +#include +#undef _KERNEL +# if defined(HASVMLOCKH) +#include +# endif /* defined(HASVMLOCKH) */ +#include + +#include + +/* + * Compensate for removal of MAP_ENTRY_IS_A_MAP from , + * This work-around was supplied by John Polstra . + */ + +# if defined(MAP_ENTRY_IS_SUB_MAP) && !defined(MAP_ENTRY_IS_A_MAP) +#define MAP_ENTRY_IS_A_MAP 0 +# endif /* defined(MAP_ENTRY_IS_SUB_MAP) && !defined(MAP_ENTRY_IS_A_MAP) */ + +#include +#include + +#undef B_NEEDCOMMIT + +#include + +#include +#include + +#include + + +#define COMP_P const void +#define DEVINCR 1024 /* device table malloc() increment */ + +# if !defined(BSDSUNIX_KA_T) +typedef u_long KA_T; +# endif /* !defined(BSDSUNIX_KA_T) */ + +#define KMEM "/dev/kmem" +#define MALLOC_P void +#define FREE_P MALLOC_P +#define MALLOC_S size_t +#define MAXSYSCMDL MAXCOMLEN /* max system command name length */ + +# if defined(N_UNIXV) +#define N_UNIX_TMP(x) #x +#define N_UNIX_STR(x) N_UNIX_TMP(x) +#define N_UNIX N_UNIX_STR(N_UNIXV) +# endif /* defined(N_UNIXV) */ + +#define QSORT_P void + +# if !defined(READLEN_T) +#define READLEN_T int +# endif /* !defined(READLEN_T) */ + +#define STRNCPY_L size_t +#define SWAP "/dev/drum" +#define SZOFFTYPE unsigned long long + /* size and offset internal storage + * type */ +#define SZOFFPSPEC "ll" /* SZOFFTYPE print specification + * modifier */ + + +/* + * Global storage definitions (including their structure definitions) + */ + +struct file * Cfp; + +extern kvm_t *Kd; + +# if defined(P_ADDR) +extern KA_T Kpa; +# endif /* defined(P_ADDR) */ + +struct l_vfs { + KA_T addr; /* kernel address */ + fsid_t fsid; /* file system ID */ + +# if defined(MOUNT_NONE) + short type; /* type of file system */ +# else /* !defined(MOUNT_NONE) */ + char *typnm; /* file system type name */ +# endif /* defined(MOUNT_NONE) */ + + char *dir; /* mounted directory */ + char *fsname; /* file system name */ + struct l_vfs *next; /* forward link */ +}; +extern struct l_vfs *Lvfs; + +struct mounts { + char *dir; /* directory (mounted on) */ + char *fsname; /* file system + * (symbolic links unresolved) */ + char *fsnmres; /* file system + * (symbolic links resolved) */ + dev_t dev; /* directory st_dev */ + dev_t rdev; /* directory st_rdev */ + INODETYPE inode; /* directory st_ino */ + mode_t mode; /* directory st_mode */ + mode_t fs_mode; /* file system st_mode */ + struct mounts *next; /* forward link */ +}; + +#define X_NCACHE "ncache" +#define X_NCSIZE "ncsize" +#define NL_NAME n_name + +extern int Np; /* number of kernel processes */ + +extern struct kinfo_proc *P; /* local process table copy */ + +struct sfile { + char *aname; /* argument file name */ + char *name; /* file name (after readlink()) */ + char *devnm; /* device name (optional) */ + dev_t dev; /* device */ + dev_t rdev; /* raw device */ + u_short mode; /* S_IFMT mode bits from stat() */ + int type; /* file type: 0 = file system + * 1 = regular file */ + INODETYPE i; /* inode number */ + int f; /* file found flag */ + struct sfile *next; /* forward link */ + +}; + +#define XDR_VOID (const xdrproc_t)xdr_void +#define XDR_PMAPLIST (const xdrproc_t)xdr_pmaplist + + +/* + * Definitions for rdev.c + */ + +#define DIRTYPE dirent +#define HASDNAMLEN 1 /* struct DIRTYPE has d_namlen element */ + + +/* + * Definitions for rnam.c and rnmh.c + */ + +# if defined(HASNCACHE) +#include +# if defined(HASNAMECACHE) +#include +# else /* !defined(HASNAMECACHE) */ +/* + * The namecache struct definition should come from a header file that + * can be #include'd, but it has been moved to a kernel source file in + * 4.0-current for some reason unclear to me. + * + * So we must take the risk of defining it here. !!!! DANGER !!!! + */ + +struct namecache { + LIST_ENTRY(namecache) nc_hash; /* hash chain */ + LIST_ENTRY(namecache) nc_src; /* source vnode list */ + TAILQ_ENTRY(namecache) nc_dst; /* destination vnode list */ + struct vnode *nc_dvp; /* vnode of parent of name */ + struct vnode *nc_vp; /* vnode the name refers to */ + u_char nc_flag; /* flag bits */ + u_char nc_nlen; /* length of name */ + char nc_name[16]; /* segment name -- Strictly composed, + * the size of nc_name[] should be zero + * and rnmh.c in lsof/lib should read + * the name with a separate call to + * kvm_read(). Since that causes extra + * (and slow) calls to kvm_read(), the + * size is set here to an experimentally + * derived guess. The same experiment + * didn't reveal any extra kvm_read() + * suggesting the guess is a safe one. + * (VAA, 10 Apr 2002) */ +}; +# endif /* defined(HASNAMECACHE) */ + +#define NCACHE namecache /* kernel's structure name */ +#define NCACHE_NM nc_name /* name in NCACHE */ +#define NCACHE_NMLEN nc_nlen /* name length in NCACHE */ + +#include +#define NCACHE_NXT nc_hash.le_next /* link in NCACHE */ + +#define NCACHE_NODEADDR nc_vp /* node address in NCACHE */ +#define NCACHE_PARADDR nc_dvp /* parent node address in NCACHE */ + +# if defined(HASNCVPID) +#define NCACHE_NODEID nc_vpid /* node ID in NCACHE */ +#define NCACHE_PARID nc_dvpid /* parent node ID in NCACHE */ +# endif /* DEFINED(HASNCVPID) */ +# endif /* defined(HASNCACHE) */ + +#define VNODE_VFLAG v_iflag +#define NCACHE_VROOT VV_ROOT + +#endif /* defined(BSDSUNIX_LSOF_H) */ diff -Nru dialects/bsdsunix.orig/dmnt.c dialects/bsdsunix/dmnt.c --- dialects/bsdsunix.orig/dmnt.c 1970-01-01 01:00:00.000000000 +0100 +++ dialects/bsdsunix/dmnt.c 2016-10-03 18:41:04.670735000 +0200 @@ -0,0 +1,456 @@ +/* + * dmnt.c - BSDSUniX mount support functions for lsof + */ + + +/* + * Copyright 1994 Purdue Research Foundation, West Lafayette, Indiana + * 47907. All rights reserved. + * + * Written by Victor A. Abell + * + * This software is not subject to any license of the American Telephone + * and Telegraph Company or the Regents of the University of California. + * + * Permission is granted to anyone to use this software for any purpose on + * any computer system, and to alter it and redistribute it freely, subject + * to the following restrictions: + * + * 1. Neither the authors nor Purdue University are responsible for any + * consequences of the use of this software. + * + * 2. The origin of this software must not be misrepresented, either by + * explicit claim or by omission. Credit to the authors and Purdue + * University must appear in documentation and sources. + * + * 3. Altered versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 4. This notice may not be removed or altered. + */ + +#ifndef lint +static char copyright[] = +"@(#) Copyright 1994 Purdue Research Foundation.\nAll rights reserved.\n"; +static char *rcsid = "$Id: dmnt.c,v 1.17 2013/01/02 17:01:43 abe Exp $"; +#endif + + +#include "lsof.h" + + +/* + * Local static information + */ + +static struct mounts *Lmi = (struct mounts *)NULL; /* local mount info */ +static int Lmist = 0; /* Lmi status */ + +#undef HAS_MNT_NAMES + +# if defined(MOUNT_NONE) +static char *mnt_names[] = INITMOUNTNAMES; +#define HAS_MNT_NAMES 1 +# endif /* defined(MOUNT_NONE)) */ + + +#if defined(HAS_NO_SI_UDEV) +/* + * Dev2Udev() -- convert a kernel device number to a user device number + */ + +dev_t +Dev2Udev(c) + +# if defined(HAS_CONF_MINOR) || defined(HAS_CDEV2PRIV) + KA_T c; +# else /* !defined(HAS_CONF_MINOR) && !defined(HAS_CDEV2PRIV) */ + struct cdev *c; +# endif /* defined(HAS_CONF_MINOR) || defined(HAS_CDEV2PRIV) */ + +{ + +# if !defined(HAS_CONF_MINOR) && !defined(HAS_CDEV2PRIV) + char *cp; + char *dn = (char *)NULL; + char *ln = (char *)NULL; + struct statfs *mb; + int n, sr; + static u_int s; + struct stat sb; + static int ss = 0; +# endif /* !defined(HAS_CONF_MINOR) && !defined(HAS_CDEV2PRIV) */ + +# if defined(HAS_CONF_MINOR) || defined(HAS_CDEV2PRIV) + KA_T ca; + struct cdev_priv cp; + + if (!c) + return(NODEV); + +# if defined(HAS_CDEV2PRIV) + ca = (KA_T)cdev2priv((struct cdev *)c); +# else /* !defined(HAS_CDEV2PRIV) */ + ca = (KA_T)member2struct(cdev_priv, cdp_c, c); +# endif /* defined(HAS_CDEV2PRIV) */ + + if (kread((KA_T)ca, (char *)&cp, sizeof(cp))) + return(NODEV); + return((dev_t)cp.cdp_inode); +# else /* !defined(HAS_CONF_MINOR) && !defined(HAS_CDEV2PRIV) */ +# if defined(HAS_SI_PRIV) +/* + * If the cdev structure has a private sub-structure, read it. + */ + struct cdev_priv sp; + + if (!c->si_priv || kread((KA_T)c->si_priv, (char *)&sp, sizeof(sp))) + return(0); +# endif /* defined(HAS_SI_PRIV) */ + + if (ss) { + +# if defined(HAS_SI_PRIV) + return(sp.cdp_inode ^ s); +# else /* !defined(HAS_SI_PRIV) */ + return(c->si_inode ^ s); +# endif /* defined(HAS_SI_PRIV) */ + + } + +/* + * Determine the random udev seed from stat(2) operations on "/" and + * its device. + */ + if ((n = getmntinfo(&mb, MNT_NOWAIT)) <= 0) { + (void) fprintf(stderr, "%s: no mount information\n", Pn); + Exit(1); + } + for (; n; n--, mb++) { + +# if defined(MOUNT_NONE) + if (mb->f_type == MOUNT_NONE || mb->f_type >= MOUNT_MAXTYPE) +# else /* !defined(MOUNT_NONE) */ + if (!mb->f_type) +# endif /* defined(MOUNT_NONE) */ + + continue; + /* + * Get the real directory name. Ignore all but the root directory; + * safely stat("/"). + */ + if (dn) + (void) free((FREE_P *)dn); + if (!(dn = mkstrcpy(mb->f_mntonname, (MALLOC_S *)NULL))) { + +Dev2Udev_no_space: + + (void) fprintf(stderr, "%s: no space for mount at ", Pn); + safestrprt(mb->f_mntonname, stderr, 0); + (void) fprintf(stderr, " ("); + safestrprt(mb->f_mntfromname, stderr, 0); + (void) fprintf(stderr, ")\n"); + Exit(1); + } + if (!(ln = Readlink(dn))) { + if (!Fwarn) { + (void) fprintf(stderr, + " Output information may be incomplete.\n"); + } + continue; + } + if (ln != dn) { + (void) free((FREE_P *)dn); + dn = ln; + } + ln = (char *)NULL; + if (strcmp(dn, "/")) + continue; + if (statsafely(dn, &sb)) + continue; + /* + * Get the real device name and safely stat(2) it. + */ + (void) free((FREE_P *)dn); + if (!(dn = mkstrcpy(mb->f_mntfromname, (MALLOC_S *)NULL))) + goto Dev2Udev_no_space; + ln = Readlink(dn); + if ((sr = statsafely(ln, &sb))) { + + /* + * If the device stat(2) failed, see if the device name indicates + * an NFS mount, a cd9660 device, or a ZFS mount. If any condition + * is true, set the user device number seed to zero. + */ + if (((cp = strrchr(ln, ':')) && (*(cp + 1) == '/')) + || !strcasecmp(mb->f_fstypename, "cd9660") + || !strcasecmp(mb->f_fstypename, "zfs") + ) { + ss = 1; + s = (u_int)0; + } + } + if (ln != dn) + (void) free((FREE_P *)ln); + ln = (char *)NULL; + (void) free((FREE_P *)dn); + dn = (char *)NULL; + if (sr && !ss) + continue; + if (!ss) { + ss = 1; + s = (u_int)sb.st_ino ^ (u_int)sb.st_rdev; + } + break; + } +/* + * Free string copies, as required. + */ + if (dn) + (void) free((FREE_P *)dn); + if (ln) + (void) free((FREE_P *)ln); +/* + * If the device seed is known, return its application to the cdev structure's + * inode. + */ + if (ss) { + +# if defined(HAS_SI_PRIV) + return(sp.cdp_inode ^ s); +# else /* !defined(HAS_SI_PRIV) */ + return(c->si_inode ^ s); +# endif /* defined(HAS_SI_PRIV) */ + + } + (void) fprintf(stderr, "%s: can't determine user device random seed.\n", Pn); + Exit(1); + +# endif /* !defined(HAS_CONF_MINOR) */ + +} +#endif /* defined(HAS_NO_SI_UDEV) */ + + +/* + * readmnt() - read mount table + */ + +struct mounts * +readmnt() +{ + char *dn = (char *)NULL; + char *ln; + struct statfs *mb; + struct mounts *mtp; + int n; + struct stat sb; + +#if defined(HASPROCFS) + unsigned char procfs = 0; +#endif /* defined(HASPROCFS) */ + + if (Lmi || Lmist) + return(Lmi); +/* + * Access mount information. + */ + if ((n = getmntinfo(&mb, MNT_NOWAIT)) <= 0) { + (void) fprintf(stderr, "%s: no mount information\n", Pn); + return(0); + } +/* + * Read mount information. + */ + for (; n; n--, mb++) { + +#if defined(MOUNT_NONE) + if (mb->f_type == MOUNT_NONE || mb->f_type >= MOUNT_MAXTYPE) +#else /* !defined(MOUNT_NONE) */ + if (!mb->f_type) +#endif /* defined(MOUNT_NONE) */ + + continue; + /* + * Interpolate a possible symbolic directory link. + */ + if (dn) + (void) free((FREE_P *)dn); + if (!(dn = mkstrcpy(mb->f_mntonname, (MALLOC_S *)NULL))) { + +no_space_for_mount: + + (void) fprintf(stderr, "%s: no space for mount at ", Pn); + safestrprt(mb->f_mntonname, stderr, 0); + (void) fprintf(stderr, " ("); + safestrprt(mb->f_mntfromname, stderr, 0); + (void) fprintf(stderr, ")\n"); + Exit(1); + } + if (!(ln = Readlink(dn))) { + if (!Fwarn) { + (void) fprintf(stderr, + " Output information may be incomplete.\n"); + } + continue; + } + if (ln != dn) { + (void) free((FREE_P *)dn); + dn = ln; + } + if (*dn != '/') + continue; + /* + * Stat() the directory. + */ + if (statsafely(dn, &sb)) { + if (!Fwarn) { + (void) fprintf(stderr, "%s: WARNING: can't stat() ", Pn); + +#if defined(HAS_MNT_NAMES) + safestrprt(mnt_names[mb->f_type], stderr, 0); +#else /* !defined(HAS_MNT_NAMES) */ + safestrprt(mb->f_fstypename, stderr, 0); +#endif /* defined(HAS_MNT_NAMES) */ + + (void) fprintf(stderr, " file system "); + safestrprt(mb->f_mntonname, stderr, 1); + (void) fprintf(stderr, + " Output information may be incomplete.\n"); + } + (void) bzero((char *)&sb, sizeof(sb)); + sb.st_dev = (dev_t)mb->f_fsid.val[0]; + sb.st_mode = S_IFDIR | 0777; + if (!Fwarn) { + (void) fprintf(stderr, + " assuming \"dev=%x\" from mount table\n", + sb.st_dev); + } + } + /* + * Allocate and fill a local mount structure. + */ + if (!(mtp = (struct mounts *)malloc(sizeof(struct mounts)))) + goto no_space_for_mount; + mtp->dir = dn; + dn = (char *)NULL; + +#if defined(HASPROCFS) + +#if defined(MOUNT_NONE) + if (mb->f_type == MOUNT_PROCFS) +#else /* !defined(MOUNT_NONE) */ + if (strcasecmp(mb->f_fstypename, "procfs") == 0) +#endif /* defined(MOUNT_NONE) */ + + { + + /* + * Save information on exactly one procfs file system. + */ + if (procfs) + Mtprocfs = (struct mounts *)NULL; + else { + procfs = 1; + Mtprocfs = mtp; + } + } +#endif /* defined(HASPROCFS) */ + + mtp->next = Lmi; + mtp->dev = sb.st_dev; + mtp->rdev = sb.st_rdev; + mtp->inode = (INODETYPE)sb.st_ino; + mtp->mode = sb.st_mode; + /* + * Interpolate a possible file system (mounted-on) device name link. + */ + if (!(dn = mkstrcpy(mb->f_mntfromname, (MALLOC_S *)NULL))) + goto no_space_for_mount; + mtp->fsname = dn; + ln = Readlink(dn); + dn = (char *)NULL; + /* + * Stat() the file system (mounted-on) name and add file system + * information to the local mount table entry. + */ + if (!ln || statsafely(ln, &sb)) + sb.st_mode = 0; + mtp->fsnmres = ln; + mtp->fs_mode = sb.st_mode; + Lmi = mtp; + } +/* + * Clean up and return the local mount info table address. + */ + if (dn) + (void) free((FREE_P *)dn); + Lmist = 1; + return(Lmi); +} + + +/* + * readvfs() - read vfs structure + */ + +struct l_vfs * +readvfs(vm) + KA_T vm; /* kernel mount address from vnode */ +{ + struct mount m; + struct l_vfs *vp; +/* + * Search for match on existing entry. + */ + for (vp = Lvfs; vp; vp = vp->next) { + if (vm == vp->addr) + return(vp); + } +/* + * Read the (new) mount structure, allocate a local entry, and fill it. + */ + if (kread((KA_T)vm, (char *)&m, sizeof(m)) != 0) + return((struct l_vfs *)NULL); + if (!(vp = (struct l_vfs *)malloc(sizeof(struct l_vfs)))) { + (void) fprintf(stderr, "%s: PID %d, no space for vfs\n", + Pn, Lp->pid); + Exit(1); + } + if (!(vp->dir = mkstrcpy(m.m_stat.f_mntonname, (MALLOC_S *)NULL)) + || !(vp->fsname = mkstrcpy(m.m_stat.f_mntfromname, (MALLOC_S *)NULL))) + { + (void) fprintf(stderr, "%s: PID %d, no space for mount names\n", + Pn, Lp->pid); + Exit(1); + } + vp->addr = vm; + vp->fsid = m.m_stat.f_fsid; + +#if defined(MOUNT_NONE) + vp->type = m.m_stat.f_type; +#else /* !defined(MOUNT_NONE) */ + { + int len; + + if ((len = strlen(m.m_stat.f_fstypename))) { + if (len > (MFSNAMELEN - 1)) + len = MFSNAMELEN - 1; + if (!(vp->typnm = mkstrcat(m.m_stat.f_fstypename, len, + (char *)NULL, -1, (char *)NULL, -1, + (MALLOC_S *)NULL))) + { + (void) fprintf(stderr, + "%s: no space for fs type name: ", Pn); + safestrprt(m.m_stat.f_fstypename, stderr, 1); + Exit(1); + } + } else + vp->typnm = ""; + } +#endif /* defined(MOUNT_NONE) */ + + vp->next = Lvfs; + Lvfs = vp; + return(vp); +} diff -Nru dialects/bsdsunix.orig/dnode.c dialects/bsdsunix/dnode.c --- dialects/bsdsunix.orig/dnode.c 1970-01-01 01:00:00.000000000 +0100 +++ dialects/bsdsunix/dnode.c 2016-10-03 19:01:29.064803000 +0200 @@ -0,0 +1,1497 @@ +/* + * dnode.c - BSDSUniX node functions for lsof + */ + + +/* + * Copyright 1994 Purdue Research Foundation, West Lafayette, Indiana + * 47907. All rights reserved. + * + * Written by Victor A. Abell + * + * This software is not subject to any license of the American Telephone + * and Telegraph Company or the Regents of the University of California. + * + * Permission is granted to anyone to use this software for any purpose on + * any computer system, and to alter it and redistribute it freely, subject + * to the following restrictions: + * + * 1. Neither the authors nor Purdue University are responsible for any + * consequences of the use of this software. + * + * 2. The origin of this software must not be misrepresented, either by + * explicit claim or by omission. Credit to the authors and Purdue + * University must appear in documentation and sources. + * + * 3. Altered versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 4. This notice may not be removed or altered. + */ + +#ifndef lint +static char copyright[] = +"@(#) Copyright 1994 Purdue Research Foundation.\nAll rights reserved.\n"; +static char *rcsid = "$Id: dnode.c,v 1.44 2015/07/07 20:23:43 abe Exp abe $"; +#endif + + +#include "lsof.h" + +#if defined(HAS_LOCKF_ENTRY) +#include "./lockf_owner.h" +#endif /* defined(HAS_LOCKF_ENTRY) */ + +#if defined(HAS_ZFS) +#include "dzfs.h" +#endif /* defined(HAS_ZFS) */ + + +#if defined(HASFDESCFS) && HASFDESCFS==1 +_PROTOTYPE(static int lkup_dev_tty,(dev_t *dr, INODETYPE *ir)); +#endif /* defined(HASFDESCFS) && HASFDESCFS==1 */ + + +#if defined(HAS_TMPFS) +#define _KERNEL +#include +#undef _KERNEL +#endif /* defined(HAS_TMPFS) */ + +_PROTOTYPE(static void get_lock_state,(KA_T f)); + + +/* + * get_lock_state() -- get the lock state + */ + +static void +get_lock_state(f) + KA_T f; /* inode's lock pointer */ +{ + struct lockf lf; /* lockf structure */ + int lt; /* lock type */ + +#if defined(HAS_LOCKF_ENTRY) + struct lockf_entry le; /* lock_entry structure */ + KA_T lef, lep; /* lock_entry pointers */ + struct lock_owner lo; /* lock owner structure */ + + if (!f || kread(f, (char *)&lf, sizeof(lf))) + return; + if (!(lef = (KA_T)lf.ls_active.lh_first)) + return; + lep = lef; + do { + if (kread(lep, (char *)&le, sizeof(le))) + return; + if (!le.lf_owner + || kread((KA_T)le.lf_owner, (char *)&lo, sizeof(lo))) + continue; + if (lo.lo_pid == (pid_t)Lp->pid) { + if (le.lf_start == (off_t)0 + && le.lf_end == 0x7fffffffffffffffLL) + lt = 1; + else + lt = 0; + if (le.lf_type == F_RDLCK) + Lf->lock = lt ? 'R' : 'r'; + else if (le.lf_type == F_WRLCK) + Lf->lock = lt ? 'W' : 'w'; + else if (le.lf_type == (F_RDLCK | F_WRLCK)) + Lf->lock = 'u'; + return; + } + } while ((lep = (KA_T)le.lf_link.le_next) && (lep != lef)); +#else /* !defined(HAS_LOCKF_ENTRY) */ + + unsigned char l; /* lock status */ + KA_T lfp; /* lockf structure pointer */ + + if ((lfp = f)) { + + /* + * Determine the lock state. + */ + do { + if (kread(lfp, (char *)&lf, sizeof(lf))) + break; + l = 0; + switch (lf.lf_flags & (F_FLOCK|F_POSIX)) { + case F_FLOCK: + if (Cfp && (struct file *)lf.lf_id == Cfp) + l = 1; + break; + case F_POSIX: + +# if defined(P_ADDR) + if ((KA_T)lf.lf_id == Kpa) + l = 1; +# endif /* defined(P_ADDR) */ + + break; + } + if (!l) + continue; + if (lf.lf_start == (off_t)0 + && lf.lf_end == 0xffffffffffffffffLL) + lt = 1; + else + lt = 0; + if (lf.lf_type == F_RDLCK) + Lf->lock = lt ? 'R' : 'r'; + else if (lf.lf_type == F_WRLCK) + Lf->lock = lt ? 'W' : 'w'; + else if (lf.lf_type == (F_RDLCK | F_WRLCK)) + Lf->lock = 'u'; + break; + } while ((lfp = (KA_T)lf.lf_next) && (lfp != f)); + } +#endif /* defined(HAS_LOCKF_ENTRY) */ + +} + + +#if defined(HASPROCFS) +_PROTOTYPE(static void getmemsz,(pid_t pid)); + + +/* + * getmemsz() - get memory size of a /proc//mem entry + */ + +static void +getmemsz(pid) + pid_t pid; +{ + int n; + struct kinfo_proc *p; + struct vmspace vm; + + for (n = 0, p = P; n < Np; n++, p++) { + if (p->P_PID == pid) { + if (!p->P_VMSPACE + || kread((KA_T)p->P_VMSPACE, (char *)&vm, sizeof(vm))) + return; + Lf->sz = (SZOFFTYPE)ctob(vm.vm_tsize+vm.vm_dsize+vm.vm_ssize); + Lf->sz_def = 1; + return; + } + } +} +#endif /* defined(HASPROCFS) */ + + +#if defined(HASFDESCFS) && HASFDESCFS==1 +/* + * lkup_dev_tty() - look up /dev/tty + */ + +static int +lkup_dev_tty(dr, ir) + dev_t *dr; /* place to return device number */ + INODETYPE *ir; /* place to return inode number */ +{ + int i; + + readdev(0); + +# if defined(HASDCACHE) + +lkup_dev_tty_again: + +# endif /* defined(HASDCACHE) */ + + for (i = 0; i < Ndev; i++) { + if (strcmp(Devtp[i].name, "/dev/tty") == 0) { + +# if defined(HASDCACHE) + if (DCunsafe && !Devtp[i].v && !vfy_dev(&Devtp[i])) + goto lkup_dev_tty_again; +# endif /* defined(HASDCACHE) */ + + *dr = Devtp[i].rdev; + *ir = Devtp[i].inode; + return(1); + } + } + +# if defined(HASDCACHE) + if (DCunsafe) { + (void) rereaddev(); + goto lkup_dev_tty_again; + } +# endif /* defined(HASDCACHE) */ + + return(-1); +} +#endif /* defined(HASFDESCFS) && HASFDESCFS==1 */ + + +#if defined(HASKQUEUE) +/* + * process_kqueue() -- process kqueue file + * + * Strictly speaking this function should appear in dfile.c, because it is + * a file processing function. However, the Net and Open BSD sources don't + * require a dfile.c, so this is the next best location for the function. + */ + +void +process_kqueue(ka) + KA_T ka; /* kqueue file structure address */ +{ + struct kqueue kq; /* kqueue structure */ + + (void) snpf(Lf->type, sizeof(Lf->type), "KQUEUE"); + enter_dev_ch(print_kptr(ka, (char *)NULL, 0)); + if (!ka || kread(ka, (char *)&kq, sizeof(kq))) + return; + (void) snpf(Namech, Namechl, "count=%d, state=%#x", kq.kq_count, + kq.kq_state); + enter_nm(Namech); +} +#endif /* defined(HASKQUEUE) */ + + +/* + * process_node() - process vnode + */ + +void +process_node(va) + KA_T va; /* vnode kernel space address */ +{ + dev_t dev, rdev; + unsigned char devs; + unsigned char rdevs; + char dev_ch[32], *ep; + struct inode *i; + struct nfsnode *n; + size_t sz; + char *ty; + enum vtype type; + struct vnode *v, vb; + struct l_vfs *vfs; + + struct inode ib; + struct nfsnode nb; +#if !defined(HAS_CONF_MINOR) && !defined(HAS_CDEV2PRIV) + struct cdev si; +#endif /* !defined(HAS_CONF_MINOR) && !defined(HAS_CDEV2PRIV) */ + +#if defined(HAS9660FS) + dev_t iso_dev; + int iso_dev_def, iso_stat; + INODETYPE iso_ino; + long iso_links; + SZOFFTYPE iso_sz; +#endif /* defined(HAS9660FS) */ + +#if defined(HASFDESCFS) + struct fdescnode *f; + +# if HASFDESCFS==1 + static dev_t f_tty_dev; + static INODETYPE f_tty_ino; + static int f_tty_s = 0; +# endif /* HASFDESCFS==1 */ + + struct fdescnode fb; + +#endif /* defined(HASFDESCFS) */ + +#if defined(HASFUSEFS) + dev_t fuse_dev; + int fuse_dev_def, fuse_stat; + INODETYPE fuse_ino; + long fuse_links; + SZOFFTYPE fuse_sz; +#endif /* defined(HASFUSEFS) */ + +# if defined(HAS_UFS1_2) + int ufst; + struct ufsmount um; + struct ufs1_dinode d1; + struct ufs2_dinode d2; +# endif /* !defined(HAS_UFS1_2) */ + +# if !defined(HAS_CONF_MINOR) && !defined(HAS_CDEV2PRIV) + struct cdev cd; +# endif /* !defined(HAS_CONF_MINOR) && !defined(HAS_CDEV2PRIV) */ + + int cds; + struct devfs_dirent de; + struct devfs_dirent *d; + char vtbuf[32]; + char *vtbp; + enum vtagtype { VT_DEVFS, VT_FDESC, VT_FUSEFS, VT_ISOFS, VT_PSEUDOFS, + VT_NFS, VT_NULL, VT_TMPFS, VT_UFS, VT_ZFS, VT_UNKNOWN + }; + +# if defined(HAS_TMPFS) + struct tmpfs_node tn; + struct tmpfs_node *tnp; +# endif /* defined(HAS_TMPFS) */ + +#if defined(HASNULLFS) +# if !defined(HASPRINTDEV) + char dbuf[32]; +# endif /* !defined(HASPRINTDEV) */ + char *dp, *np, tbuf[1024]; + struct null_node nu; + int sc = 0; +#endif /* defined(HASNULLFS) */ + +#if defined(HASPROCFS) + struct pfsnode *p; + struct procfsid *pfi; + static int pgsz = -1; + struct vmspace vm; + + struct pfsnode pb; +#endif /* defined(HASPROCFS) */ + +#if defined(HASPSEUDOFS) + struct pfs_node pn; + struct pfs_node *pnp; +#endif /* defined(HASPSEUDOFS) */ + +#if defined(HAS_ZFS) + zfs_info_t *z = (zfs_info_t *)NULL; + zfs_info_t zi; + char *zm = (char *)NULL; +#else /* !defined(HAS_ZFS) */ + static unsigned char zw = 0; +#endif /* HAS_VFS */ + + enum vtagtype vtag; /* placed here to use the + * artificial vtagtype + * definition required for + * BSDSUNIX */ + +#if defined(HASNULLFS) + +process_overlaid_node: + + if (++sc > 1024) { + (void) snpf(Namech, Namechl, "too many overlaid nodes"); + enter_nm(Namech); + return; + } +#endif /* defined(HASNULLFS) */ + +/* + * Initialize miscellaneous variables. This is done so that processing an + * overlaid node will be a fresh start. + */ + devs = rdevs = 0; + i = (struct inode *)NULL; + n = (struct nfsnode *)NULL; + Namech[0] = '\0'; + +#if defined(HAS9660FS) + iso_dev_def = iso_stat = 0; +#endif /* defined(HAS9660FS) */ + +#if defined(HASFDESCFS) + f = (struct fdescnode *)NULL; +#endif /* defined(HASFDESCFS) */ + +#if defined(HASFUSEFS) + fuse_dev_def = fuse_stat = 0; +#endif /* defined(HASFUSEFS) */ + + cds = 0; + d = (struct devfs_dirent *)NULL; +# if defined(HAS_UFS1_2) + ufst = 0; +# endif /* !defined(HAS_UFS1_2) */ + +#if defined(HASPROCFS) + p = (struct pfsnode *)NULL; +#endif /* defined(HASPROCFS) */ + +#if defined(HASPSEUDOFS) + pnp = (struct pfs_node *)NULL; +#endif /* defined(HASPSEUDOFS) */ + +# if defined(HAS_TMPFS) + tnp = (struct tmpfs_node *)NULL; +# endif /* defined(HAS_TMPFS) */ + + +#if defined(HAS_ZFS) + z = (zfs_info_t *)NULL; + zm = (char *)NULL; +#endif /* defined(HAS_ZFS) */ + +/* + * Read the vnode. + */ + if ( ! va) { + enter_nm("no vnode address"); + return; + } + v = &vb; + if (readvnode(va, v)) { + enter_nm(Namech); + return; + } + +#if defined(HASNCACHE) + Lf->na = va; +# if defined(HASNCVPID) + Lf->id = v->v_id; +# endif /* defined(HASNCVPID) */ +#endif /* defined(HASNCACHE) */ + +#if defined(HASFSTRUCT) + Lf->fna = va; + Lf->fsv |= FSV_NI; +#endif /* defined(HASFSTRUCT) */ + +/* + * Get the vnode type. + */ + if (!v->v_mount) + vfs = (struct l_vfs *)NULL; + else { + vfs = readvfs((KA_T)v->v_mount); + if (vfs) { + +#if defined(MOUNT_NONE) + switch (vfs->type) { + case MOUNT_NFS: + Ntype = N_NFS; + break; + +# if defined(HASPROCFS) + case MOUNT_PROCFS: + Ntype = N_PROC; + break; +# endif /* defined(HASPROCFS) */ + } +#else /* !defined(MOUNT_NONE) */ + if (strcasecmp(vfs->typnm, "nfs") == 0) + Ntype = N_NFS; + +# if defined(HASPROCFS) + else if (strcasecmp(vfs->typnm, "procfs") == 0) + Ntype = N_PROC; +# endif /* defined(HASPROCFS) */ + +# if defined(HASPSEUDOFS) + else if (strcasecmp(vfs->typnm, "pseudofs") == 0) + Ntype = N_PSEU; +# endif /* defined(HASPSEUDOFS) */ + +# if defined(HAS_TMPFS) + else if (strcasecmp(vfs->typnm, "tmpfs") == 0) + Ntype = N_TMP; +# endif /* defined(HAS_TMPFS) */ +#endif /* defined(MOUNT_NONE) */ + + } + } + if (Ntype == N_REGLR) { + switch (v->v_type) { + case VFIFO: + Ntype = N_FIFO; + break; + default: + break; + } + } + + if (((v->v_type == VCHR) || (v->v_type == VBLK)) + && v->v_rdev + +# if !defined(HAS_CONF_MINOR) && !defined(HAS_CDEV2PRIV) + && !kread((KA_T)v->v_rdev, (char *)&cd, sizeof(cd)) +# endif /* !defined(HAS_CONF_MINOR) && !defined(HAS_CDEV2PRIV) */ + + ) { + cds = 1; + } + +/* + * Define the specific node pointer. + */ + + vtag = VT_UNKNOWN; + if (v->v_tag && !kread((KA_T)v->v_tag, (char *)&vtbuf, sizeof(vtbuf))) + { + vtbuf[sizeof(vtbuf) - 1] = '\0'; + vtbp = vtbuf; + if (!strcmp(vtbuf, "ufs")) + vtag = VT_UFS; + else if (!strcmp(vtbuf, "zfs")) { + +#if !defined(HAS_ZFS) + if (!Fwarn && !zw) { + (void) fprintf(stderr, + "%s: WARNING: no ZFS support has been defined.\n", + Pn); + (void) fprintf(stderr, + " See 00FAQ for more information.\n"); + zw = 1; + } +#else /* defined(HAS_ZFS) */ + vtag = VT_ZFS; +#endif /* !defined(HAS_ZFS) */ + + } else if (!strcmp(vtbuf, "devfs")) + vtag = VT_DEVFS; + else if (!strcmp(vtbuf, "nfs")) + vtag = VT_NFS; + else if (!strcmp(vtbuf, "newnfs")) + vtag = VT_NFS; + else if (!strcmp(vtbuf, "oldnfs")) + vtag = VT_NFS; + else if (!strcmp(vtbuf, "isofs")) + vtag = VT_ISOFS; + else if (!strcmp(vtbuf, "pseudofs")) + vtag = VT_PSEUDOFS; + else if (!strcmp(vtbuf, "null")) + vtag = VT_NULL; + else if (!strcmp(vtbuf, "fdesc")) + vtag = VT_FDESC; + else if (!strcmp(vtbuf, "fuse")) + vtag = VT_FUSEFS; + else if (!strcmp(vtbuf, "tmpfs")) + vtag = VT_TMPFS; + } else + vtbp = "(unknown)"; + + switch (vtag) { + + case VT_DEVFS: + if (!v->v_data + || kread((KA_T)v->v_data, (char *)&de, sizeof(de))) + { + (void) snpf(Namech, Namechl, "no devfs node: %s", + print_kptr((KA_T)v->v_data, (char *)NULL, 0)); + enter_nm(Namech); + return; + } + d = &de; + if (v->v_type == VDIR) { + if (!d->de_dir + || kread((KA_T)d->de_dir, (char *)&de, sizeof(de))) { + (void) snpf(Namech, Namechl, "no devfs dir node: %s", + print_kptr((KA_T)d->de_dir, (char *)NULL, 0)); + enter_nm(Namech); + return; + } + } + break; + +#if defined(HASFDESCFS) + case VT_FDESC: + + if (kread((KA_T)v->v_data, (char *)&fb, sizeof(fb)) != 0) { + (void) snpf(Namech, Namechl, "can't read fdescnode at: %s", + print_kptr((KA_T)v->v_data, (char *)NULL, 0)); + enter_nm(Namech); + return; + } + f = &fb; + break; +#endif /* defined(HASFDESCFS) */ + +#if defined(HASFUSEFS) + case VT_FUSEFS: + if (read_fuse_node(v, &fuse_dev, &fuse_dev_def, &fuse_ino, + &fuse_links, &fuse_sz)) + { + (void) snpf(Namech, Namechl, "no fuse node: %s", + print_kptr((KA_T)v->v_data, (char *)NULL, 0)); + enter_nm(Namech); + return; + } + fuse_stat = 1; + break; +#endif /* defined(HASFUSEFS) */ + +#if defined(HAS9660FS) + case VT_ISOFS: + if (read_iso_node(v, &iso_dev, &iso_dev_def, &iso_ino, &iso_links, + &iso_sz)) + { + (void) snpf(Namech, Namechl, "no iso node: %s", + print_kptr((KA_T)v->v_data, (char *)NULL, 0)); + enter_nm(Namech); + return; + } + iso_stat = 1; + break; +#endif /* defined(HAS9660FS) */ + + break; + case VT_NFS: + + if (!v->v_data + || kread((KA_T)v->v_data, (char *)&nb, sizeof(nb))) { + (void) snpf(Namech, Namechl, "no nfs node: %s", + print_kptr((KA_T)v->v_data, (char *)NULL, 0)); + enter_nm(Namech); + return; + } + n = &nb; + + break; + +#if defined(HASNULLFS) + case VT_NULL: + if (sc == 1) { + + /* + * If this is the first null_node, enter a name addition containing + * the mounted-on directory, the file system name, and the device + * number. + */ + if (vfs && (vfs->dir || vfs->fsname || vfs->fsid.val[0])) { + if (vfs->fsid.val[0]) { + +#if defined(HASPRINTDEV) + dp = HASPRINTDEV(Lf, &dev); +#else /* !defined(HASPRINTDEV) */ + (void) snpf(dbuf, sizeof(dbuf) - 1, "%d,%d", + GET_MAJ_DEV(dev), GET_MIN_DEV(dev)); + dbuf[sizeof(dbuf) - 1] = '\0'; + dp = dbuf; +#endif /* defined(HASPRINTDEV) */ + + } else + dp = (char *)NULL; + (void) snpf(tbuf, sizeof(tbuf) - 1, + "(nullfs%s%s%s%s%s%s%s)", + (vfs && vfs->fsname) ? " " : "", + (vfs && vfs->fsname) ? vfs->fsname : "", + (vfs && vfs->dir) ? " on " : "", + (vfs && vfs->dir) ? vfs->dir : "", + (dp && vfs && vfs->dir) ? " (" : "", + (dp && vfs && vfs->dir) ? dp : "", + (dp && vfs && vfs->dir) ? ")" : ""); + tbuf[sizeof(tbuf) - 1] = '\0'; + np = tbuf; + } else + np = "(nullfs)"; + (void) add_nma(np, (int)strlen(np)); + } + if (!v->v_data + || kread((KA_T)v->v_data, (char *)&nu, sizeof(nu))) { + (void) snpf(Namech, Namechl, "can't read null_node at: %s", + print_kptr((KA_T)v->v_data, (char *)NULL, 0)); + enter_nm(Namech); + return; + } + if (!nu.null_lowervp) { + (void) snpf(Namech, Namechl, "null_node overlays nothing"); + enter_nm(Namech); + return; + } + va = (KA_T)nu.null_lowervp; + goto process_overlaid_node; +#endif /* defined(HASNULLFS) */ + +#if defined(HASPROCFS) + case VT_PROCFS: + + if (!v->v_data + || kread((KA_T)v->v_data, (char *)&pb, sizeof(pb))) { + (void) snpf(Namech, Namechl, "no pfs node: %s", + print_kptr((KA_T)v->v_data, (char *)NULL, 0)); + enter_nm(Namech); + return; + } + p = &pb; + + break; +#endif /* defined(HASPROCFS) */ + +#if defined(HASPSEUDOFS) + case VT_PSEUDOFS: + if (!v->v_data + || kread((KA_T)v->v_data, (char *)&pn, sizeof(pn))) { + (void) snpf(Namech, Namechl, "no pfs_node: %s", + print_kptr((KA_T)v->v_data, (char *)NULL, 0)); + enter_nm(Namech); + return; + } + pnp = &pn; + break; +#endif /* defined(HASPSEUDOFS) */ + +# if defined(HAS_TMPFS) + case VT_TMPFS: + if (!v->v_data + || kread((KA_T)v->v_data, (char *)&tn, sizeof(tn))) { + (void) snpf(Namech, Namechl, "no tmpfs_node: %s", + print_kptr((KA_T)v->v_data, (char *)NULL, 0)); + enter_nm(Namech); + return; + } + tnp = &tn; + break; +# endif /* defined(HAS_TMPFS) */ + + case VT_UFS: + + if (!v->v_data + || kread((KA_T)v->v_data, (char *)&ib, sizeof(ib))) { + (void) snpf(Namech, Namechl, "no ufs node: %s", + print_kptr((KA_T)v->v_data, (char *)NULL, 0)); + enter_nm(Namech); + return; + } + i = &ib; + +# if defined(HAS_UFS1_2) + if (i->i_ump && !kread((KA_T)i->i_ump, (char *)&um, sizeof(um))) { + if (um.um_fstype == UFS1) { + if (i->i_din1 + && !kread((KA_T)i->i_din1, (char *)&d1, sizeof(d1))) + ufst = 1; + } else { + if (i->i_din2 + && !kread((KA_T)i->i_din2, (char *)&d2, sizeof(d2))) + ufst = 2; + } + } +# endif /* defined(HAS_UFS1_2) */ + +#if defined(HAS_V_LOCKF) + if (v->v_lockf) + (void) get_lock_state((KA_T)v->v_lockf); +#else /* !defined(HAS_V_LOCKF) */ + if (i->i_lockf) + (void) get_lock_state((KA_T)i->i_lockf); +#endif /* defined(HAS_V_LOCKF) */ + + break; + +#if defined(HAS_ZFS) + case VT_ZFS: + memset((void *)&zi, 0, sizeof(zfs_info_t)); + if (!v->v_data + || (zm = readzfsnode((KA_T)v->v_data, &zi, + ((v->v_vflag & VV_ROOT) ? 1 : 0))) + ) { + (void) snpf(Namech, Namechl, "%s: %s", zm, + print_kptr((KA_T)v->v_data, (char *)NULL, 0)); + enter_nm(Namech); + return; + } + z = &zi; + +#if defined(HAS_V_LOCKF) + if (v->v_lockf) + (void) get_lock_state((KA_T)v->v_lockf); +#else /* !defined(HAS_V_LOCKF) */ + if (z->lockf) + (void) get_lock_state((KA_T)z->lockf); +#endif /* defined(HAS_V_LOCKF) */ + + break; +#endif /* defined(HAS_ZFS) */ + + default: + if (v->v_type == VBAD || v->v_type == VNON) + break; + + (void) snpf(Namech, Namechl, "unknown file system type: %s", vtbp); + + enter_nm(Namech); + return; + } +/* + * Get device and type for printing. + */ + type = v->v_type; + if (n) { + dev = n->n_vattr.va_fsid; + devs = 1; + if ((type == VCHR) || (type == VBLK)) { + rdev = n->n_vattr.va_rdev; + rdevs = 1; + } + } else if (i) { + + if (i->i_dev + +# if !defined(HAS_CONF_MINOR) && !defined(HAS_CDEV2PRIV) + && !kread((KA_T)i->i_dev, (char *)&si, sizeof(si)) +# endif /* !defined(HAS_CONF_MINOR) && !defined(HAS_CDEV2PRIV) */ + + ) { + +# if defined(HAS_NO_SI_UDEV) +# if defined(HAS_CONF_MINOR) || defined(HAS_CDEV2PRIV) + dev = Dev2Udev((KA_T)i->i_dev); +# else /* !defined(HAS_CONF_MINOR) && !defined(HAS_CDEV2PRIV) */ + dev = Dev2Udev(&si); +# endif /* defined(HAS_CONF_MINOR) || defined(HAS_CDEV2PRIV) */ +# else /* !defined(HAS_NO_SI_UDEV) */ + dev = si.si_udev; +# endif /* defined(HAS_NO_SI_UDEV) */ + + devs = 1; + } + + if ((type == VCHR) || (type == VBLK)) { + +# if defined(HAS_UFS1_2) + if (ufst == 1) { + rdev = d1.di_rdev; + rdevs = 1; + } else if (ufst == 2) { + rdev = d2.di_rdev; + rdevs = 1; + } else +# endif /* defined(HAS_UFS1_2) */ + + if (cds) { + +# if defined(HAS_NO_SI_UDEV) +# if defined(HAS_CONF_MINOR) || defined(HAS_CDEV2PRIV) + rdev = Dev2Udev((KA_T)v->v_rdev); +# else /* !defined(HAS_CONF_MINOR) && !defined(HAS_CDEV2PRIV) */ + rdev = Dev2Udev(&cd); +# endif /* defined(HAS_CONF_MINOR) || defined(HAS_CDEV2PRIV) */ +# else /* !defined(HAS_NO_SI_UDEV) */ + rdev = cd.si_udev; +# endif /* defined(HAS_NO_SI_UDEV) */ + + rdevs = 1; + } + + } + } + +#if defined(HAS_ZFS) + else if (z) { + + /* + * Record information returned by readzfsnode(). + */ + if (vfs) { + dev = vfs->fsid.val[0]; + devs = 1; + } + if ((type == VCHR) || (type == VBLK)) { + if (z->rdev_def) { + rdev = z->rdev; + rdevs = 1; + } + } + } +#endif /* defined(HAS_ZFS) */ + +#if defined(HASFDESCFS) && (defined(HASFDLINK) || HASFDESCFS==1) + else if (f) { + +# if defined(HASFDLINK) + if (f->fd_link + && kread((KA_T)f->fd_link, Namech, Namechl - 1) == 0) + Namech[Namechl - 1] = '\0'; + +# if HASFDESCFS==1 + else +# endif /* HASFDESFS==1 */ +# endif /* defined(HASFDLINK) */ + +# if HASFDESCFS==1 + if (f->fd_type == Fctty) { + if (f_tty_s == 0) + f_tty_s = lkup_dev_tty(&f_tty_dev, &f_tty_ino); + if (f_tty_s == 1) { + dev = f_tty_dev; + Lf->inode = f_tty_ino; + devs = Lf->inp_ty = 1; + } + } +# endif /* HASFDESFS==1 */ + + } +#endif /* defined(HASFDESCFS) && (defined(HASFDLINK) || HASFDESCFS==1) */ + +#if defined(HAS9660FS) + else if (iso_stat && iso_dev_def) { + dev = iso_dev; + devs = Lf->inp_ty = 1; + } +#endif /* defined(HAS9660FS) */ + +#if defined(HASFUSEFS) + else if (fuse_stat && fuse_dev_def) { + dev = fuse_dev; + devs = Lf->inp_ty = 1; + } +#endif /* defined(HASFUSEFS) */ + + else if (d) { + if (vfs) { + dev = vfs->fsid.val[0]; + devs = 1; + } else { + dev = DevDev; + devs = 1; + } + if (type == VCHR) { + +# if defined(HAS_UFS1_2) + if (ufst == 1) { + rdev = d1.di_rdev; + rdevs = 1; + } else if (ufst == 2) { + rdev = d2.di_rdev; + rdevs = 1; + } else +# endif /* defined(HAS_UFS1_2) */ + + if (cds) { + +# if defined(HAS_NO_SI_UDEV) +# if defined(HAS_CONF_MINOR) || defined(HAS_CDEV2PRIV) + rdev = Dev2Udev((KA_T)v->v_rdev); +# else /* !defined(HAS_CONF_MINOR) && !defined(HAS_CDEV2PRIV) */ + rdev = Dev2Udev(&cd); +# endif /* defined(HAS_CONF_MINOR) || defined(HAS_CDEV2PRIV) */ +# else /* !defined(HAS_NO_SI_UDEV) */ + rdev = cd.si_udev; +# endif /* defined(HAS_NO_SI_UDEV) */ + + rdevs = 1; + } + } + } + +#if defined(HASPSEUDOFS) + else if (pnp) { + if (vfs) { + dev = vfs->fsid.val[0]; + devs = 1; + } + } +#endif /* defined(HASPSEUDOFS) */ + +# if defined(HAS_TMPFS) + else if (tnp) { + if (vfs) { + dev = vfs->fsid.val[0]; + devs = 1; + } + if (tnp->tn_type == VBLK || tnp->tn_type == VCHR) { + rdev = tnp->tn_rdev; + rdevs = 1; + } + } +# endif /* defined(HAS_TMPFS) */ + +/* + * Obtain the inode number. + */ + if (i) { + Lf->inode = (INODETYPE)i->i_number; + Lf->inp_ty = 1; + } + +#if defined(HAS_ZFS) + else if (z) { + if (z->ino_def) { + Lf->inode = z->ino; + Lf->inp_ty = 1; + } + } +#endif /* defined(HAS_ZFS) */ + + else if (n) { + Lf->inode = (INODETYPE)n->n_vattr.va_fileid; + Lf->inp_ty = 1; + } + +#if defined(HAS9660FS) + else if (iso_stat) { + Lf->inode = iso_ino; + Lf->inp_ty = 1; + } +#endif /* defined(HAS9660FS) */ + +#if defined(HASFUSEFS) + else if (fuse_stat) { + Lf->inode = fuse_ino; + Lf->inp_ty = 1; + } +#endif /* defined(HASFUSEFS) */ + +#if defined(HASPROCFS) + else if (p) { + Lf->inode = (INODETYPE)p->pfs_fileno; + Lf->inp_ty = 1; + } +#endif /* defined(HASPROCFS) */ + +#if defined(HASPSEUDOFS) + else if (pnp) { + Lf->inode = (INODETYPE)pnp->pn_fileno; + Lf->inp_ty = 1; + } +#endif /* defined(HASPSEUDOFS) */ + + else if (d) { + Lf->inode = (INODETYPE)d->de_inode; + Lf->inp_ty = 1; + } + +# if defined(HAS_TMPFS) + else if (tnp) { + Lf->inode = (INODETYPE)tnp->tn_id; + Lf->inp_ty = 1; + } +# endif /* defined(HAS_TMPFS) */ + +/* + * Obtain the file size. + */ + if (Foffset) + Lf->off_def = 1; + else { + switch (Ntype) { + case N_FIFO: + if (!Fsize) + Lf->off_def = 1; + break; + case N_NFS: + if (n) { + Lf->sz = (SZOFFTYPE)n->n_vattr.va_size; + Lf->sz_def = 1; + } + break; + +#if defined(HASPROCFS) + case N_PROC: + + if (p) { + switch(p->pfs_type) { + case Proot: + case Pproc: + Lf->sz = (SZOFFTYPE)DEV_BSIZE; + Lf->sz_def = 1; + break; + case Pmem: + (void) getmemsz(p->pfs_pid); + break; + case Pregs: + Lf->sz = (SZOFFTYPE)sizeof(struct reg); + Lf->sz_def = 1; + break; + case Pfpregs: + Lf->sz = (SZOFFTYPE)sizeof(struct fpreg); + Lf->sz_def = 1; + break; + } + } +#endif /* defined(HASPROCFS) */ + +#if defined(HASPSEUDOFS) + case N_PSEU: + Lf->sz = 0; + Lf->sz_def = 1; + break; +#endif /* defined(PSEUDOFS) */ + + case N_REGLR: + if (type == VREG || type == VDIR) { + if (i) { + +#if defined(HAS_UFS1_2) + if (ufst == 1) + Lf->sz = (SZOFFTYPE)d1.di_size; + else if (ufst == 2) + Lf->sz = (SZOFFTYPE)d2.di_size; + else +#endif /* defined(HAS_UFS1_2) */ + + Lf->sz = (SZOFFTYPE)i->i_size; + Lf->sz_def = 1; + } + + +#if defined(HAS_ZFS) + else if (z) { + if (z->sz_def) { + Lf->sz = z->sz; + Lf->sz_def = 1; + } + } +#endif /* defined(HAS_ZFS) */ + + +#if defined(HAS9660FS) + else if (iso_stat) { + Lf->sz = (SZOFFTYPE)iso_sz; + Lf->sz_def = 1; + } + +#endif /* defined(HAS9660FS) */ + +#if defined(HASFUSEFS) + else if (fuse_stat) { + Lf->sz = (SZOFFTYPE)fuse_sz; + Lf->sz_def = 1; + } +#endif /* defined(HASFUSEFS) */ + + } + else if ((type == VCHR || type == VBLK) && !Fsize) + Lf->off_def = 1; + break; + +# if defined(HAS_TMPFS) + case N_TMP: + if ((tnp->tn_type == VBLK || tnp->tn_type == VCHR) + && !Fsize) { + Lf->off_def = 1; + } else { + Lf->sz = (SZOFFTYPE)tnp->tn_size; + Lf->sz_def = 1; + } + break; +# endif /* defined(HAS_TMPFS) */ + + } + } +/* + * Record the link count. + */ + if (Fnlink) { + switch(Ntype) { + case N_NFS: + if (n) { + Lf->nlink = (long)n->n_vattr.va_nlink; + Lf->nlink_def = 1; + } + break; + case N_REGLR: + if (i) { + +#if defined(HASEFFNLINK) + Lf->nlink = (long)i->HASEFFNLINK; +#else /* !defined(HASEFFNLINK) */ + Lf->nlink = (long)i->i_nlink; +#endif /* defined(HASEFFNLINK) */ + + Lf->nlink_def = 1; + } + +#if defined(HAS_ZFS) + else if (z) { + if (z->nl_def) { + Lf->nlink = z->nl; + Lf->nlink_def = 1; + } + } +#endif /* defined(HAS_ZFS) */ + +#if defined(HAS9660FS) + else if (iso_stat) { + Lf->nlink = iso_links; + Lf->nlink_def = 1; + } +#endif /* defined(HAS9660FS) */ + +#if defined(HASFUSEFS) + else if (fuse_stat) { + Lf->nlink = fuse_links; + Lf->nlink_def = 1; + } +#endif /* defined(HASFUSEFS) */ + + else if (d) { + Lf->nlink = d->de_links; + Lf->nlink_def = 1; + } + + break; + +#if defined(HASPSEUODOFS) + case N_PSEU: + if (pnp) { + Lf->nlink = 1L; + Lf->nlink_def = 1; + } + break; +#endif /* defined(HASPSEUODOFS) */ + +# if defined(HAS_TMPFS) + case N_TMP: + if (tnp) { + Lf->nlink = (long)tnp->tn_links; + Lf->nlink_def = 1; + } + break; +# endif /* defined(HAS_TMPFS) */ + + } + if (Lf->nlink_def && Nlink && (Lf->nlink < Nlink)) + Lf->sf |= SELNLINK; + } +/* + * Record an NFS file selection. + */ + if (Ntype == N_NFS && Fnfs) + Lf->sf |= SELNFS; +/* + * Save the file system names. + */ + if (vfs) { + Lf->fsdir = vfs->dir; + Lf->fsdev = vfs->fsname; + } +/* + * Save the device numbers and their states. + * + * Format the vnode type, and possibly the device name. + */ + Lf->dev = dev; + Lf->dev_def = devs; + Lf->rdev = rdev; + Lf->rdev_def = rdevs; + switch (type) { + case VNON: + ty ="VNON"; + break; + case VREG: + case VDIR: + ty = (type == VREG) ? "VREG" : "VDIR"; + break; + case VBLK: + ty = "VBLK"; + Ntype = N_BLK; + break; + case VCHR: + ty = "VCHR"; + Ntype = N_CHR; + break; + case VLNK: + ty = "VLNK"; + break; + +#if defined(VSOCK) + case VSOCK: + ty = "SOCK"; + break; +#endif /* defined(VSOCK) */ + + case VBAD: + ty = "VBAD"; + break; + case VFIFO: + ty = "FIFO"; + break; + default: + (void) snpf(Lf->type, sizeof(Lf->type), "%04o", (type & 0xfff)); + ty = (char *)NULL; + } + if (ty) + (void) snpf(Lf->type, sizeof(Lf->type), "%s", ty); + Lf->ntype = Ntype; +/* + * Handle some special cases: + * + * ioctl(fd, TIOCNOTTY) files; + * memory node files; + * /proc files. + */ + + if (type == VBAD) + (void) snpf(Namech, Namechl, "(revoked)"); + + + +#if defined(HASPROCFS) + else if (p) { + Lf->dev_def = Lf->rdev_def = 0; + + ty = (char *)NULL; + (void) snpf(Namech, Namechl, "/%s", HASPROCFS); + switch (p->pfs_type) { + case Proot: + ty = "PDIR"; + break; + case Pproc: + ep = endnm(&sz); + (void) snpf(ep, sz, "/%d", p->pfs_pid); + ty = "PDIR"; + break; + case Pfile: + ep = endnm(&sz); + (void) snpf(ep, sz, "/%d/file", p->pfs_pid); + ty = "PFIL"; + break; + case Pmem: + ep = endnm(&sz); + (void) snpf(ep, sz, "/%d/mem", p->pfs_pid); + ty = "PMEM"; + break; + case Pregs: + ep = endnm(&sz); + (void) snpf(ep, sz, "/%d/regs", p->pfs_pid); + ty = "PREG"; + break; + case Pfpregs: + ep = endnm(&sz); + (void) snpf(ep, sz, "/%d/fpregs", p->pfs_pid); + ty = "PFPR"; + break; + case Pctl: + ep = endnm(&sz); + (void) snpf(ep, sz, "/%d/ctl", p->pfs_pid); + ty = "PCTL"; + break; + case Pstatus: + ep = endnm(&sz); + (void) snpf(ep, sz, "/%d/status", p->pfs_pid); + ty = "PSTA"; + break; + case Pnote: + ep = endnm(&sz); + (void) snpf(ep, sz, "/%d/note", p->pfs_pid); + ty = "PNTF"; + break; + case Pnotepg: + ep = endnm(&sz); + (void) snpf(ep, sz, "/%d/notepg", p->pfs_pid); + ty = "PGID"; + break; + case Pmap: + ep = endnm(&sz); + (void) snpf(ep, sz, "/%d/map", p->pfs_pid); + ty = "PMAP"; + break; + case Ptype: + ep = endnm(&sz); + (void) snpf(ep, sz, "/%d/etype", p->pfs_pid); + ty = "PETY"; + break; + } + if (ty) + (void) snpf(Lf->type, sizeof(Lf->type), "%s", ty); + enter_nm(Namech); + + } +#endif /* defined(HASPROCFS) */ + +#if defined(HASBLKDEV) +/* + * If this is a VBLK file and it's missing an inode number, try to + * supply one. + */ + if ((Lf->inp_ty == 0) && (type == VBLK)) + find_bl_ino(); +#endif /* defined(HASBLKDEV) */ + +/* + * If this is a VCHR file and it's missing an inode number, try to + * supply one. + */ + if ((Lf->inp_ty == 0) && (type == VCHR)) + find_ch_ino(); +/* + * Test for specified file. + */ + +#if defined(HASPROCFS) + if (Ntype == N_PROC) { + if (Procsrch) { + Procfind = 1; + Lf->sf |= SELNM; + } else { + for (pfi = Procfsid; pfi; pfi = pfi->next) { + if ((pfi->pid && pfi->pid == p->pfs_pid) + +# if defined(HASPINODEN) + || (Lf->inp_ty == 1 && Lf->inode == pfi->inode) +# else /* !defined(HASPINODEN) */ + if (pfi->pid == p->pfs_pid) +# endif /* defined(HASPINODEN) */ + + ) { + pfi->f = 1; + if (!Namech[0]) + (void) snpf(Namech, Namechl, "%s", pfi->nm); + Lf->sf |= SELNM; + break; + } + } + } + } else +#endif /* defined(HASPROCFS) */ + + { + if (Sfile && is_file_named((char *)NULL, + ((type == VCHR) || (type == VBLK)) ? 1 + : 0)) + Lf->sf |= SELNM; + } +/* + * Enter name characters. + */ + if (Namech[0]) + enter_nm(Namech); +} + +/* + * process_pipe() - process a file structure whose type is DTYPE_PIPE + */ + +void +process_pipe(pa) + KA_T pa; /* pipe structure address */ +{ + char dev_ch[32], *ep; + struct pipe p; + size_t sz; + + if (!pa || kread(pa, (char *)&p, sizeof(p))) { + (void) snpf(Namech, Namechl, + "can't read DTYPE_PIPE pipe struct: %s", + print_kptr((KA_T)pa, (char *)NULL, 0)); + enter_nm(Namech); + return; + } + (void) snpf(Lf->type, sizeof(Lf->type), "PIPE"); + (void) snpf(dev_ch, sizeof(dev_ch), "%s", + print_kptr(pa, (char *)NULL, 0)); + enter_dev_ch(dev_ch); + if (Foffset) + Lf->off_def = 1; + else { + Lf->sz = (SZOFFTYPE)p.pipe_buffer.size; + Lf->sz_def = 1; + } + if (p.pipe_peer) + (void) snpf(Namech, Namechl, "->%s", + print_kptr((KA_T)p.pipe_peer, (char *)NULL, 0)); + else + Namech[0] = '\0'; + if (p.pipe_buffer.cnt) { + ep = endnm(&sz); + (void) snpf(ep, sz, ", cnt=%d", p.pipe_buffer.cnt); + } + if (p.pipe_buffer.in) { + ep = endnm(&sz); + (void) snpf(ep, sz, ", in=%d", p.pipe_buffer.in); + } + if (p.pipe_buffer.out) { + ep = endnm(&sz); + (void) snpf(ep, sz, ", out=%d", p.pipe_buffer.out); + } +/* + * Enter name characters. + */ + if (Namech[0]) + enter_nm(Namech); +} diff -Nru dialects/bsdsunix.orig/dnode1.c dialects/bsdsunix/dnode1.c --- dialects/bsdsunix.orig/dnode1.c 1970-01-01 01:00:00.000000000 +0100 +++ dialects/bsdsunix/dnode1.c 2016-10-03 18:47:03.674719000 +0200 @@ -0,0 +1,150 @@ +/* + * dnode1.c - FreeBSD node functions for lsof + * + * This module must be separate to keep separate the multiple kernel inode + * structure definitions. + */ + + +/* + * Copyright 1995 Purdue Research Foundation, West Lafayette, Indiana + * 47907. All rights reserved. + * + * Written by Victor A. Abell + * + * This software is not subject to any license of the American Telephone + * and Telegraph Company or the Regents of the University of California. + * + * Permission is granted to anyone to use this software for any purpose on + * any computer system, and to alter it and redistribute it freely, subject + * to the following restrictions: + * + * 1. Neither the authors nor Purdue University are responsible for any + * consequences of the use of this software. + * + * 2. The origin of this software must not be misrepresented, either by + * explicit claim or by omission. Credit to the authors and Purdue + * University must appear in documentation and sources. + * + * 3. Altered versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 4. This notice may not be removed or altered. + */ + +#ifndef lint +static char copyright[] = +"@(#) Copyright 1994 Purdue Research Foundation.\nAll rights reserved.\n"; +static char *rcsid = "$Id: dnode1.c,v 1.10 2008/10/21 16:16:06 abe Exp abe $"; +#endif + + +#include "lsof.h" + +#if defined(HAS9660FS) + +/* + * Do a little preparation for #include'ing cd9660_node.h, then #include it. + */ + +#undef i_size +#undef doff_t +#undef IN_ACCESS + +# if defined(__alpha__) +#define dev_t void * +# endif /* defined(__alpha__) */ + +#include "cd9660_node.h" + +# if defined(HAS_NO_ISO_DEV) +#define _KERNEL +#include +#undef _KERNEL +# endif /* defined(HAS_NO_ISO_DEV) */ + +# if defined(__alpha__) +#undef dev_t +# endif /* defined(__alpha__) */ + + +/* + * read_iso_node() -- read CD 9660 iso_node + */ + +int +read_iso_node(v, d, dd, ino, nl, sz) + struct vnode *v; /* containing vnode */ + dev_t *d; /* returned device number */ + int *dd; /* returned device-defined flag */ + INODETYPE *ino; /* returned inode number */ + long *nl; /* returned number of links */ + SZOFFTYPE *sz; /* returned size */ +{ + + struct iso_node i; + + struct cdev udev; +# if defined(HAS_NO_ISO_DEV) + struct iso_mnt im; +# endif /* defined(HAS_NO_ISO_DEV) */ + + if (!v->v_data + || kread((KA_T)v->v_data, (char *)&i, sizeof(i))) + return(1); + +# if defined(HAS_NO_ISO_DEV) + if (i.i_mnt && !kread((KA_T)i.i_mnt, (char *)&im, sizeof(im)) + && im.im_dev && !kread((KA_T)im.im_dev, (char *)&udev, sizeof(udev))) +# else /* !defined(HAS_NO_ISO_DEV) */ + if (i.i_dev && !kread((KA_T)i.i_dev, (char *)&udev, sizeof(udev))) +# endif /* defined(HAS_NO_ISO_DEV) */ + + { + +# if defined(HAS_NO_SI_UDEV) + *d = Dev2Udev(&udev); +# else /* !defined(HAS_NO_SI_UDEV) */ + *d = udev.si_udev; +# endif /* defined(HAS_NO_SI_UDEV) */ + + *dd = 1; + } + + *ino = (INODETYPE)i.i_number; + *nl = (long)i.inode.iso_links; + *sz = (SZOFFTYPE)i.i_size; + + return(0); +} +#endif /* defined(HAS9660FS) */ + + +#if defined(HASFUSEFS) +#include +/* + * read_fuse_node() -- read FUSE file system fuse_node + */ + +int +read_fuse_node(v, d, dd, ino, nl, sz) + struct vnode *v; /* containing vnode */ + dev_t *d; /* returned device number */ + int *dd; /* returned device-defined flag */ + INODETYPE *ino; /* returned inode number */ + long *nl; /* returned number of links */ + SZOFFTYPE *sz; /* returned size */ +{ + struct fuse_vnode_data fn; /* FUSE node */ + + if (!v->v_data + || kread((KA_T)v->v_data, (char *)&fn, sizeof(fn))) + return(1); + *d = fn.cached_attrs.va_fsid; + *dd = 1; + *ino = (INODETYPE)fn.cached_attrs.va_fileid; + *nl = (long)fn.cached_attrs.va_nlink; + *sz = (SZOFFTYPE)fn.cached_attrs.va_size; + return(0); +} +#endif /* defined(HASFUSEFS) */ diff -Nru dialects/bsdsunix.orig/dnode2.c dialects/bsdsunix/dnode2.c --- dialects/bsdsunix.orig/dnode2.c 1970-01-01 01:00:00.000000000 +0100 +++ dialects/bsdsunix/dnode2.c 2016-10-03 18:47:34.924924000 +0200 @@ -0,0 +1,152 @@ +/* + * dnode2.c - BSDSUniX ZFS node functions for lsof + * + * This module must be separate to permit use of the OpenSolaris ZFS header + * files. + */ + + +/* + * Copyright 2008 Purdue Research Foundation, West Lafayette, Indiana + * 47907. All rights reserved. + * + * Written by Victor A. Abell + * + * This software is not subject to any license of the American Telephone + * and Telegraph Company or the Regents of the University of California. + * + * Permission is granted to anyone to use this software for any purpose on + * any computer system, and to alter it and redistribute it freely, subject + * to the following restrictions: + * + * 1. Neither the authors nor Purdue University are responsible for any + * consequences of the use of this software. + * + * 2. The origin of this software must not be misrepresented, either by + * explicit claim or by omission. Credit to the authors and Purdue + * University must appear in documentation and sources. + * + * 3. Altered versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 4. This notice may not be removed or altered. + */ + +#ifndef lint +static char copyright[] = +"@(#) Copyright 2008 Purdue Research Foundation.\nAll rights reserved.\n"; +static char *rcsid = "$Id: dnode2.c,v 1.6 2015/07/07 20:23:43 abe Exp $"; +#endif + + +#if defined(HAS_ZFS) + +#define _KERNEL + +# if defined(__clang__) +/* + * A clang workaround... + * + * Note: clang's complaint about VOP_FSYNC can't be avoided. + */ +#define VOP_UNLOCK(vp, f) ((void)0) +# endif /* defined(__clang__) */ + +#include +#undef _KERNEL + +#include "dzfs.h" + + +/* + * readzfsnode() -- read the ZFS node + */ + +char * +readzfsnode(za, zi, vr) + KA_T za; /* ZFS node address */ + zfs_info_t *zi; /* return ZFS info structure pointer */ + int vr; /* vnode's (v_flag & VROOT) */ +{ + struct znode zn; /* ZFS node */ + +# if defined(HAS_Z_PHYS) + znode_phys_t zp; /* ZFS physical node */ +# else /* !defined(HAS_Z_PHYS) */ + KA_T ka; /* temporary kernel address */ + zfsvfs_t zv; /* znode's zfsvfs structure */ +# endif /* defined(HAS_Z_PHYS) */ + + if (!za + || kread(za, (char *)&zn, sizeof(zn)) + ) { + if (!za) + return("No ZFS node address"); + return("Can't read znode"); + } +/* + * Return items contained in the znode. + */ + zi->ino = (INODETYPE)zn.z_id; + zi->ino_def = 1; + +# if !defined(HAS_V_LOCKF) + zi->lockf = (KA_T)zn.z_lockf; +# endif /* !defined(HAS_V_LOCKF) */ + +# if defined(HAS_Z_PHYS) +/* + * If the physical znode exists in this ZFS implementation, read it. + */ + if (!zn.z_phys + || kread((KA_T)zn.z_phys, (char *)&zp, sizeof(zp)) + ) { + if (!zn.z_phys) + return("No physical znode address"); + return("Can't read physical znode"); + } +/* + * Return items contained in the physical znode. + */ + zi->nl = (long)zp.zp_links; + zi->rdev = zp.zp_rdev; + zi->sz = (SZOFFTYPE)zp.zp_size; + zi->nl_def = zi->rdev_def = zi->sz_def = 1; +# else /* !defined(HAS_Z_PHYS) */ +/* + * If this implementation has no physical znode, return items now contained + * in the znode. + */ + zi->nl = (long)zn.z_links; + if (vr && (ka = (KA_T)zn.z_zfsvfs)) { + if (!kread(ka, (char *)&zv, sizeof(zv))) { + if ((zn.z_id == zv.z_root) + && (zv.z_ctldir != NULL) + && (zv.z_show_ctldir) + ) { + zi->nl++; + } + } + } + zi->sz = (SZOFFTYPE)zn.z_size; + zi->nl_def = zi->sz_def = 1; +# endif /* defined(HAS_Z_PHYS) */ + + return((char *)NULL); +} + + + + +# if defined(__GNUC__) && defined(HAS_CV_TIMEDWAIT_SBT) +/* + * A gcc work-around + */ + +int _cv_timedwait_sbt(struct cv *cvp, struct lock_object *lock, + sbintime_t sbt, sbintime_t pr, int flags) +{ + return(0); +} +# endif /* defined(__GNUC__) && HAS_CV_TIMEDWAIT_SBT */ +#endif /* defined(HAS_ZFS) */ diff -Nru dialects/bsdsunix.orig/dproc.c dialects/bsdsunix/dproc.c --- dialects/bsdsunix.orig/dproc.c 1970-01-01 01:00:00.000000000 +0100 +++ dialects/bsdsunix/dproc.c 2016-10-03 18:50:49.163774000 +0200 @@ -0,0 +1,657 @@ +/* + * dproc.c - BSDSUniX process access functions for lsof + */ + + +/* + * Copyright 1994 Purdue Research Foundation, West Lafayette, Indiana + * 47907. All rights reserved. + * + * Written by Victor A. Abell + * + * This software is not subject to any license of the American Telephone + * and Telegraph Company or the Regents of the University of California. + * + * Permission is granted to anyone to use this software for any purpose on + * any computer system, and to alter it and redistribute it freely, subject + * to the following restrictions: + * + * 1. Neither the authors nor Purdue University are responsible for any + * consequences of the use of this software. + * + * 2. The origin of this software must not be misrepresented, either by + * explicit claim or by omission. Credit to the authors and Purdue + * University must appear in documentation and sources. + * + * 3. Altered versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 4. This notice may not be removed or altered. + */ + +#ifndef lint +static char copyright[] = +"@(#) Copyright 1994 Purdue Research Foundation.\nAll rights reserved.\n"; +static char *rcsid = "$Id: dproc.c,v 1.19 2015/07/07 20:23:43 abe Exp $"; +#endif + +#include "lsof.h" + + +_PROTOTYPE(static void enter_vn_text,(KA_T va, int *n)); +_PROTOTYPE(static void get_kernel_access,(void)); +_PROTOTYPE(static void process_text,(KA_T vm)); + + +/* + * Local static values + */ + +static MALLOC_S Nv = 0; /* allocated Vp[] entries */ +static KA_T *Vp = NULL; /* vnode address cache */ + + +/* + * enter_vn_text() - enter a vnode text reference + */ + +static void +enter_vn_text(va, n) + KA_T va; /* vnode address */ + int *n; /* Vp[] entries in use */ +{ + int i; +/* + * Ignore the request if the vnode has already been entered. + */ + for (i = 0; i < *n; i++) { + if (va == Vp[i]) + return; + } +/* + * Save the text file information. + */ + alloc_lfile(" txt", -1); + Cfp = (struct file *)NULL; + process_node(va); + if (Lf->sf) + link_lfile(); + if (i >= Nv) { + + /* + * Allocate space for remembering the vnode. + */ + Nv += 10; + if (!Vp) + Vp=(KA_T *)malloc((MALLOC_S)(sizeof(struct vnode *)*10)); + else + Vp=(KA_T *)realloc((MALLOC_P *)Vp,(MALLOC_S)(Nv*sizeof(KA_T))); + if (!Vp) { + (void) fprintf(stderr, "%s: no txt ptr space, PID %d\n", + Pn, Lp->pid); + Exit(1); + } + } +/* + * Remember the vnode. + */ + Vp[*n] = va; + (*n)++; +} + + +/* + * gather_proc_info() -- gather process information + */ + +void +gather_proc_info() +{ + short cckreg; /* conditional status of regular file + * checking: + * 0 = unconditionally check + * 1 = conditionally check */ + short ckscko; /* socket file only checking status: + * 0 = none + * 1 = check only socket files, + * including TCP and UDP + * streams with eXPORT data, + * where supported */ + struct filedesc fd; + int i, nf; + MALLOC_S nb; + +#if defined(HAS_FILEDESCENT) + typedef struct filedescent ofb_t; +#else /* !defined(HAS_FILEDESCENT) */ + typedef struct file* ofb_t; +#endif /* defined(HAS_FILEDESCENT) */ + +#if defined(HAS_FDESCENTTBL) + struct fdescenttbl fdt; + KA_T fa; +#endif /* defined(HAS_FDESCENTTBL) */ + + static ofb_t *ofb = NULL; + static int ofbb = 0; + int pgid, pid; + int ppid = 0; + short pss, sf; + int px; + int tid; /* thread (task) ID */ + uid_t uid; + + struct kinfo_proc *p; + +#if defined(HASFSTRUCT) && !defined(HAS_FILEDESCENT) + static char *pof = (char *)NULL; + static int pofb = 0; +#endif /* defined(HASFSTRUCT) && !defiled(HAS_FILEDESCENT) */ + +/* + * Define socket and regular file conditional processing flags. + * + * If only socket files have been selected, or socket files have been + * selected, ANDed with other selection options, enable the skipping of + * regular files. + * + * If socket files and some process options have been selected, enable + * conditional skipping of regular file; i.e., regular files will be skipped + * unless they belong to a process selected by one of the specified options. + */ + if (Selflags & SELNW) { + + /* + * Some network files selection options have been specified. + */ + if (Fand || !(Selflags & ~SELNW)) { + + /* + * Selection ANDing or only network file options have been + * specified, so set unconditional skipping of regular files + * and socket file only checking. + */ + cckreg = 0; + ckscko = 1; + } else { + + /* + * If ORed file selection options have been specified, or no + * ORed process selection options have been specified, enable + * unconditional file checking and clear socket file only + * checking. + * + * If only ORed process selection options have been specified, + * enable conditional file skipping and socket file only checking. + */ + if ((Selflags & SELFILE) || !(Selflags & SELPROC)) + cckreg = ckscko = 0; + else + cckreg = ckscko = 1; + } + } else { + + /* + * No network file selection options were specified. Enable + * unconditional file checking and clear socket file only checking. + */ + cckreg = ckscko = 0; + } +/* + * Read the process table. + */ + + +# if !defined(KERN_PROC_PROC) +#define KERN_PROC_PROC KERN_PROC_ALL +# endif /* !defined(KERN_PROC_PROC) */ + + if ((P = kvm_getprocs(Kd, Ftask ? KERN_PROC_ALL : KERN_PROC_PROC, + 0, &Np)) + == NULL) + + { + (void) fprintf(stderr, "%s: can't read process table: %s\n", + Pn, + + kvm_geterr(Kd) + + ); + Exit(1); + } +/* + * Examine proc structures and their associated information. + */ + + for (p = P, px = 0; px < Np; p++, px++) + + { + + if (p->P_STAT == 0 || p->P_STAT == SZOMB) + continue; + pgid = p->P_PGID; + uid = p->ki_uid; + +#if defined(HASPPID) + ppid = p->P_PPID; +#endif /* defined(HASPPID) */ + +#if defined(HASTASKS) + /* + * See if process,including its tasks, is excluded. + */ + tid = Ftask ? (int)p->ki_tid : 0; + if (is_proc_excl(p->P_PID, pgid, (UID_ARG)uid, &pss, &sf, tid)) + continue; +#else /* !defined(HASTASKS) */ + /* + * See if process is excluded. + */ + if (is_proc_excl(p->P_PID, pgid, (UID_ARG)uid, &pss, &sf)) + continue; +#endif /* defined(HASTASKS) */ + + /* + * Read file structure pointers. + */ + if (!p->P_FD + || kread((KA_T)p->P_FD, (char *)&fd, sizeof(fd))) + continue; + +#if defined(HAS_FDESCENTTBL) + if (!fd.fd_files + || kread((KA_T)fd.fd_files, (char *)&fdt, sizeof(fdt))) + continue; + if (!fd.fd_refcnt || fd.fd_lastfile > fdt.fdt_nfiles) + continue; +#else /* !defined(HAS_FDESCENTTBL) */ + if (!fd.fd_refcnt || fd.fd_lastfile > fd.fd_nfiles) + continue; +#endif /* defined(HAS_FDESCENTTBL) */ + + /* + * Allocate a local process structure. + */ + if (is_cmd_excl(p->P_COMM, &pss, &sf)) + continue; + if (cckreg) { + + /* + * If conditional checking of regular files is enabled, enable + * socket file only checking, based on the process' selection + * status. + */ + ckscko = (sf & SELPROC) ? 0 : 1; + } + alloc_lproc(p->P_PID, pgid, ppid, (UID_ARG)uid, p->P_COMM, + (int)pss, (int)sf); + Plf = (struct lfile *)NULL; + +#if defined(HASTASKS) + /* + * Save the task (thread) ID. + */ + Lp->tid = tid; +#endif /* defined(HASTASKS) */ + +#if defined(P_ADDR) + /* + * Save the kernel proc struct address, if P_ADDR is defined. + */ + Kpa = (KA_T)p->P_ADDR; +#endif /* defined(P_ADDR) */ + + /* + * Save current working directory information. + */ + if (!ckscko && fd.fd_cdir) { + alloc_lfile(CWD, -1); + Cfp = (struct file *)NULL; + process_node((KA_T)fd.fd_cdir); + if (Lf->sf) + link_lfile(); + } + /* + * Save root directory information. + */ + if (!ckscko && fd.fd_rdir) { + alloc_lfile(RTD, -1); + Cfp = (struct file *)NULL; + process_node((KA_T)fd.fd_rdir); + if (Lf->sf) + link_lfile(); + } + + /* + * Save jail directory information. + */ + if (!ckscko && fd.fd_jdir) { + alloc_lfile("jld", -1); + Cfp = (struct file *)NULL; + process_node((KA_T)fd.fd_jdir); + if (Lf->sf) + link_lfile(); + } + + /* + * Save information on the text file. + */ + if (!ckscko && p->P_VMSPACE) + process_text((KA_T)p->P_VMSPACE); + /* + * Read open file structure pointers. + */ + +#if defined(HAS_FDESCENTTBL) + if ((nf = fdt.fdt_nfiles) <= 0) + continue; +#else /* !defined(HAS_FDESCENTTBL) */ + if (!fd.fd_ofiles || (nf = fd.fd_nfiles) <= 0) + continue; +#endif /* defined(HAS_FDESCENTTBL) */ + + nb = (MALLOC_S)(sizeof(ofb_t) * nf); + if (nb > ofbb) { + if (!ofb) + ofb = (ofb_t *)malloc(nb); + else + ofb = (ofb_t *)realloc((MALLOC_P *)ofb, nb); + if (!ofb) { + (void) fprintf(stderr, "%s: PID %d, no file * space\n", + Pn, p->P_PID); + Exit(1); + } + ofbb = nb; + } + +#if defined(HAS_FDESCENTTBL) + fa = (KA_T)fd.fd_files + + (KA_T)offsetof(struct fdescenttbl, fdt_ofiles); + if (kread(fa, (char *)ofb, nb)) + continue; +#else /* !defined(HAS_FDESCENTTBL) */ + if (kread((KA_T)fd.fd_ofiles, (char *)ofb, nb)) + continue; +#endif /* defined(HAS_FDESCENTTBL) */ + + +#if defined(HASFSTRUCT) && !defined(HAS_FILEDESCENT) + if (Fsv & FSV_FG) { + nb = (MALLOC_S)(sizeof(char) * nf); + if (nb > pofb) { + if (!pof) + pof = (char *)malloc(nb); + else + pof = (char *)realloc((MALLOC_P *)pof, nb); + if (!pof) { + (void) fprintf(stderr, + "%s: PID %d, no file flag space\n", Pn, p->P_PID); + Exit(1); + } + pofb = nb; + } + if (!fd.fd_ofileflags || kread((KA_T)fd.fd_ofileflags, pof, nb)) + zeromem(pof, nb); + } +#endif /* defined(HASFSTRUCT) && !defined(HAS_FILEDESCENT) */ + + /* + * Save information on file descriptors. + */ + for (i = 0; i < nf; i++) { + +#if defined(HAS_FILEDESCENT) + if ((Cfp = ofb[i].fde_file)) +#else /* !defined(HAS_FILEDESCENT) */ + if ((Cfp = ofb[i])) +#endif /* defined(HAS_FILEDESCENT) */ + + { + alloc_lfile(NULL, i); + process_file((KA_T)Cfp); + if (Lf->sf) { + +#if defined(HASFSTRUCT) + if (Fsv & FSV_FG) +# if defined(HAS_FILEDESCENT) + Lf->pof = (long)ofb[i].fde_flags; +# else /* !defined(HAS_FILEDESCENT) */ + Lf->pof = (long)pof[i]; +# endif /* defined(HAS_FILEDESCENT) */ +#endif /* defined(HASFSTRUCT) */ + + link_lfile(); + } + } + } + /* + * Unless threads (tasks) are being processed, examine results. + */ + if (!Ftask) { + if (examine_lproc()) + return; + } + } +} + + +/* + * get_kernel_access() - get access to kernel memory + */ + +static void +get_kernel_access() +{ + +/* + * Check kernel version. + */ + (void) ckkv("BSDSUniX", LSOF_VSTR, (char *)NULL, (char *)NULL); +/* + * Set name list file path. + */ + if (!Nmlst) + +#if defined(N_UNIX) + Nmlst = N_UNIX; +#else /* !defined(N_UNIX) */ + { + if (!(Nmlst = get_nlist_path(1))) { + (void) fprintf(stderr, + "%s: can't get kernel name list path\n", Pn); + Exit(1); + } + } +#endif /* defined(N_UNIX) */ + +#if defined(WILLDROPGID) +/* + * If kernel memory isn't coming from KMEM, drop setgid permission + * before attempting to open the (Memory) file. + */ + if (Memory) + (void) dropgid(); +#else /* !defined(WILLDROPGID) */ +/* + * See if the non-KMEM memory and the name list files are readable. + */ + if ((Memory && !is_readable(Memory, 1)) + || (Nmlst && !is_readable(Nmlst, 1))) + Exit(1); +#endif /* defined(WILLDROPGID) */ + +/* + * Open kernel memory access. + */ + + if ((Kd = kvm_open(Nmlst, Memory, NULL, O_RDONLY, NULL)) == NULL) + + { + (void) fprintf(stderr, + "%s: kvm_open%s(execfile=%s, corefile=%s): %s\n", + Pn, + + "", + + Nmlst ? Nmlst : "default", + Memory ? Memory : + +#if defined(_PATH_MEM) + _PATH_MEM, +#else /* !defined(_PATH_MEM) */ + "default", +#endif /* defined(_PATH_MEM) */ + + strerror(errno)); + Exit(1); + } + (void) build_Nl(Drive_Nl); + if (kvm_nlist(Kd, Nl) < 0) { + (void) fprintf(stderr, "%s: can't read namelist from %s\n", + Pn, Nmlst); + Exit(1); + } + +#if defined(WILLDROPGID) +/* + * Drop setgid permission, if necessary. + */ + if (!Memory) + (void) dropgid(); +#endif /* defined(WILLDROPGID) */ + +} + + +#if !defined(N_UNIX) +/* + * get_nlist_path() - get kernel name list path + */ + +char * +get_nlist_path(ap) + int ap; /* on success, return an allocated path + * string pointer if 1; return a + * constant character pointer if 0; + * return NULL if failure */ +{ + const char *bf; + static char *bfc; + MALLOC_S bfl; +/* + * Get bootfile name. + */ + if ((bf = getbootfile())) { + if (!ap) + return(""); + bfl = (MALLOC_S)(strlen(bf) + 1); + if (!(bfc = (char *)malloc(bfl))) { + (void) fprintf(stderr, + "%s: can't allocate %d bytes for boot file path: %s\n", + Pn, (int)bfl, bf); + Exit(1); + } + (void) snpf(bfc, bfl, "%s", bf); + return(bfc); + } + return((char *)NULL); +} +#endif /* !defined(N_UNIX) */ + + +/* + * initialize() - perform all initialization + */ + +void +initialize() +{ + get_kernel_access(); +} + + +/* + * kread() - read from kernel memory + */ + +int +kread(addr, buf, len) + KA_T addr; /* kernel memory address */ + char *buf; /* buffer to receive data */ + READLEN_T len; /* length to read */ +{ + int br; + + br = kvm_read(Kd, (u_long)addr, buf, len); + + return((br == len) ? 0 : 1); +} + + +/* + * process_text() - process text information + */ +void +process_text(vm) + KA_T vm; /* vm space pointer */ +{ + int i, j; + KA_T ka; + int n = 0; + struct vm_map_entry vmme, *e; + struct vm_object vmo; + struct vmspace vmsp; + + +/* + * Read the vmspace structure for the process. + */ + if (kread(vm, (char *)&vmsp, sizeof(vmsp))) + return; +/* + * Read the vm_map structure. Search its vm_map_entry structure list. + */ + for (i = 0; i < vmsp.vm_map.nentries; i++) { + + /* + * Read the next vm_map_entry. + */ + if (i == 0) + e = &vmsp.vm_map.header; + else { + if (!(ka = (KA_T)e->next)) + return; + e = &vmme; + if (kread(ka, (char *)e, sizeof(vmme))) + return; + } + +#if defined(MAP_ENTRY_IS_A_MAP) + if (e->eflags & (MAP_ENTRY_IS_A_MAP|MAP_ENTRY_IS_SUB_MAP)) +#else /* !defined(MAP_ENTRY_IS_A_MAP) */ + if (e->is_a_map || e->is_sub_map) +#endif /* defined(MAP_ENTRY_IS_A_MAP) */ + + continue; + /* + * Read the map entry's object and the object's shadow. + * an OBJT_VNODE object type. + */ + for (j = 0, ka = (KA_T)e->object.vm_object; + j < 2 && ka; + j++, + + ka = (KA_T)vmo.backing_object + ) + { + if (kread(ka, (char *)&vmo, sizeof(vmo))) + break; + + if (vmo.type != OBJT_VNODE + || vmo.handle == (void *)NULL) + continue; + (void) (enter_vn_text((KA_T)vmo.handle, &n)); + + } + } +} diff -Nru dialects/bsdsunix.orig/dproto.h dialects/bsdsunix/dproto.h --- dialects/bsdsunix.orig/dproto.h 1970-01-01 01:00:00.000000000 +0100 +++ dialects/bsdsunix/dproto.h 2016-10-03 18:51:37.690335000 +0200 @@ -0,0 +1,68 @@ +/* + * dproto.h - BSDSUniX function prototypes for lsof + * + * The _PROTOTYPE macro is defined in the common proto.h. + */ + + +/* + * Copyright 1994 Purdue Research Foundation, West Lafayette, Indiana + * 47907. All rights reserved. + * + * Written by Victor A. Abell + * + * This software is not subject to any license of the American Telephone + * and Telegraph Company or the Regents of the University of California. + * + * Permission is granted to anyone to use this software for any purpose on + * any computer system, and to alter it and redistribute it freely, subject + * to the following restrictions: + * + * 1. Neither the authors nor Purdue University are responsible for any + * consequences of the use of this software. + * + * 2. The origin of this software must not be misrepresented, either by + * explicit claim or by omission. Credit to the authors and Purdue + * University must appear in documentation and sources. + * + * 3. Altered versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 4. This notice may not be removed or altered. + */ + + +/* + * $Id: dproto.h,v 1.14 2009/03/25 19:23:06 abe Exp abe $ + */ + + +#if defined(HAS_NO_SI_UDEV) +# if defined(HAS_CONF_MINOR)|| defined(HAS_CDEV2PRIV) +_PROTOTYPE(extern dev_t Dev2Udev,(KA_T c)); +# else /* !defined(HAS_CONF_MINOR) && !defined(HAS_CDEV2PRIV) */ +_PROTOTYPE(extern dev_t Dev2Udev,(struct cdev *c)); +# endif /* defined(HAS_CONF_MINOR) || defined(HAS_CDEV2PRIV) */ +#endif /* defined(HAS_NO_SI_UDEV) */ + +#if !defined(N_UNIX) +_PROTOTYPE(extern char *get_nlist_path,(int ap)); +#endif /* !defined(N_UNIX) */ + +_PROTOTYPE(extern int is_file_named,(char *p, int cd)); +_PROTOTYPE(extern void process_socket,(KA_T sa)); +_PROTOTYPE(extern struct l_vfs *readvfs,(KA_T vm)); + +#if defined(HASKQUEUE) +_PROTOTYPE(extern void process_kqueue,(KA_T ka)); +#endif /* defined(HASKQUEUE) */ + +_PROTOTYPE(extern void process_pipe,(KA_T pa)); + +#if defined(HASFUSEFS) +_PROTOTYPE(extern int read_fuse_node,(struct vnode *v, dev_t *d, int *dd, INODETYPE *ino, long *nl, SZOFFTYPE *sz)); +#endif /* defined(HASFUSEFS) */ + +#if defined(HAS9660FS) +_PROTOTYPE(extern int read_iso_node,(struct vnode *v, dev_t *d, int *dd, INODETYPE *ino, long *nl, SZOFFTYPE *sz)); +#endif /* defined(HAS9660FS) */ diff -Nru dialects/bsdsunix.orig/dsock.c dialects/bsdsunix/dsock.c --- dialects/bsdsunix.orig/dsock.c 1970-01-01 01:00:00.000000000 +0100 +++ dialects/bsdsunix/dsock.c 2016-10-03 18:52:45.817148000 +0200 @@ -0,0 +1,517 @@ +/* + * dsock.c - NSDSUniX socket processing functions for lsof + */ + + +/* + * Copyright 1994 Purdue Research Foundation, West Lafayette, Indiana + * 47907. All rights reserved. + * + * Written by Victor A. Abell + * + * This software is not subject to any license of the American Telephone + * and Telegraph Company or the Regents of the University of California. + * + * Permission is granted to anyone to use this software for any purpose on + * any computer system, and to alter it and redistribute it freely, subject + * to the following restrictions: + * + * 1. Neither the authors nor Purdue University are responsible for any + * consequences of the use of this software. + * + * 2. The origin of this software must not be misrepresented, either by + * explicit claim or by omission. Credit to the authors and Purdue + * University must appear in documentation and sources. + * + * 3. Altered versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 4. This notice may not be removed or altered. + */ + +#ifndef lint +static char copyright[] = +"@(#) Copyright 1994 Purdue Research Foundation.\nAll rights reserved.\n"; +static char *rcsid = "$Id: dsock.c,v 1.30 2015/07/07 20:23:43 abe Exp $"; +#endif + + +#include "lsof.h" + + +#if defined(HASIPv6) + +/* + * IPv6_2_IPv4() -- macro to define the address of an IPv4 address contained + * in an IPv6 address + */ + +#define IPv6_2_IPv4(v6) (((uint8_t *)((struct in6_addr *)v6)->s6_addr)+12) + +# if defined(HAS_NO_6PORT) +/* + * If the in_pcb structure no longer has the KAME accommodations of + * in6p_[fl]port, redefine them to inp_[fl]port. + */ + +#define in6p_fport inp_fport +#define in6p_lport inp_lport +# endif /* defined(HAS_NO_6PORT) */ + +# if defined(HAS_NO_6PPCB) +/* + * If the in_pcb structure no longer has the KAME accommodation of in6p_pcb, + * redefine it to inp_ppcb. + */ + +#define in6p_ppcb inp_ppcb +# endif /* defined(HAS_NO_6PPCB) */ +#endif /* defined(HASIPv6) */ + +#if defined(HAS_SB_CCC) +#define SOCK_CC sb_ccc +#else /* !defined(HAS_SB_CCC) */ +#define SOCK_CC sb_cc +#endif /* defined(HAS_SB_CCC) */ + + +/* + * Local function prototypes + */ + +_PROTOTYPE(static int ckstate,(KA_T ta, struct tcpcb *t, int fam)); + + +/* + * ckstate() -- read TCP control block and check TCP state for inclusion + * or exclusion + * return: -1 == no TCP CB available + * 0 == TCP DB available; continue processing file + * 1 == stop processing file + */ + +static int +ckstate(ta, t, fam) + KA_T ta; /* TCP control block address */ + struct tcpcb *t; /* TCP control block receptor */ + int fam; /* protocol family */ +{ + int tsnx; +/* + * Read TCP control block. + */ + if (kread(ta, (char *)t, sizeof(struct tcpcb))) + return(-1); + if (TcpStXn || TcpStIn) { + + /* + * If there are TCP state inclusions or exclusions, check them. + */ + tsnx = (int)t->t_state + TcpStOff; + if (TcpStXn) { + if (TcpStX[tsnx]) { + Lf->sf &= ~SELNET; + Lf->sf |= SELEXCLF; + return(1); + } + } + if (TcpStIn) { + if (TcpStI[tsnx]) { + TcpStI[tsnx] = 2; + Lf->sf |= SELNET; + } else { + Lf->sf &= ~SELNET; + Lf->sf |= SELEXCLF; + return(1); + } + } + } + if (!(Lf->sf & SELNET) && !TcpStIn) { + + /* + * See if this TCP file should be selected. + */ + if (Fnet) { + if (!FnetTy + || ((FnetTy == 4) && (fam == AF_INET)) + +#if defined(HASIPv6) + || ((FnetTy == 6) && (fam == AF_INET6)) +#endif /* defined(HASIPv6) */ + + ) { + Lf->sf |= SELNET; + } + } + } + return(0); +} + + +/* + * process_socket() - process socket + */ + +void +process_socket(sa) + KA_T sa; /* socket address in kernel */ +{ + struct domain d; + unsigned char *fa = (unsigned char *)NULL; + int fam; + int fp, lp; + struct inpcb inp; + unsigned char *la = (unsigned char *)NULL; + struct protosw p; + struct socket s; + struct tcpcb t; + int ts = -1; + struct unpcb uc, unp; + struct sockaddr_un *ua = NULL; + struct sockaddr_un un; + + int unl; + +#if defined(HASIPv6) && !defined(HASINRIAIPv6) + struct in6pcb in6p; +#endif /* defined(HASIPv6) && !defined(HASINRIAIPv6) */ + + (void) snpf(Lf->type, sizeof(Lf->type), "sock"); + Lf->inp_ty = 2; +/* + * Read the socket, protocol, and domain structures. + */ + if (!sa) { + enter_nm("no socket address"); + return; + } + if (kread(sa, (char *) &s, sizeof(s))) { + (void) snpf(Namech, Namechl, "can't read socket struct from %s", + print_kptr(sa, (char *)NULL, 0)); + enter_nm(Namech); + return; + } + if (!s.so_type) { + enter_nm("no socket type"); + return; + } + if (!s.so_proto + || kread((KA_T)s.so_proto, (char *)&p, sizeof(p))) { + (void) snpf(Namech, Namechl, "can't read protocol switch from %s", + print_kptr((KA_T)s.so_proto, (char *)NULL, 0)); + enter_nm(Namech); + return; + } + if (!p.pr_domain + || kread((KA_T)p.pr_domain, (char *)&d, sizeof(d))) { + (void) snpf(Namech, Namechl, "can't read domain struct from %s", + print_kptr((KA_T)p.pr_domain, (char *)NULL, 0)); + enter_nm(Namech); + return; + } +/* + * Save size information. + */ + if (Fsize) { + if (Lf->access == 'r') + Lf->sz = (SZOFFTYPE)s.so_rcv.SOCK_CC; + else if (Lf->access == 'w') + Lf->sz = (SZOFFTYPE)s.so_snd.SOCK_CC; + else + Lf->sz = (SZOFFTYPE)(s.so_rcv.SOCK_CC + s.so_snd.SOCK_CC); + Lf->sz_def = 1; + } else + Lf->off_def = 1; + +#if defined(HASTCPTPIQ) + Lf->lts.rq = s.so_rcv.SOCK_CC; + Lf->lts.sq = s.so_snd.SOCK_CC; + Lf->lts.rqs = Lf->lts.sqs = 1; +#endif /* defined(HASTCPTPIQ) */ + +#if defined(HASSOOPT) + Lf->lts.ltm = (unsigned int)s.so_linger; + Lf->lts.opt = (unsigned int)s.so_options; + Lf->lts.pqlen = (unsigned int)s.so_incqlen; + Lf->lts.qlen = (unsigned int)s.so_qlen; + Lf->lts.qlim = (unsigned int)s.so_qlimit; + Lf->lts.rbsz = (unsigned long)s.so_rcv.sb_mbmax; + Lf->lts.sbsz = (unsigned long)s.so_snd.sb_mbmax; + Lf->lts.pqlens = Lf->lts.qlens = Lf->lts.qlims = Lf->lts.rbszs + = Lf->lts.sbszs = (unsigned char)1; +#endif /* defined(HASSOOPT) */ + +#if defined(HASSOSTATE) + Lf->lts.ss = (unsigned int)s.so_state; +# if defined(HASSBSTATE) + Lf->lts.sbs_rcv = s.so_rcv.sb_state; + Lf->lts.sbs_snd = s.so_snd.sb_state; +# endif /* defined(HASSBSTATE) */ +#endif /* defined(HASSOSTATE) */ + +/* + * Process socket by the associated domain family. + */ + switch ((fam = d.dom_family)) { +/* + * Process an Internet domain socket. + */ + case AF_INET: + +#if defined(HASIPv6) + case AF_INET6: +#endif /* defined(HASIPv6) */ + + if (Fnet) { + if (!FnetTy + || ((FnetTy == 4) && (fam == AF_INET)) + +#if defined(HASIPv6) + || ((FnetTy == 6) && (fam == AF_INET6)) +#endif /* defined(HASIPv6) */ + + ) { + if (!TcpStIn && !UdpStIn) + Lf->sf |= SELNET; + } + } + printiproto(p.pr_protocol); + +#if defined(HASIPv6) + (void) snpf(Lf->type, sizeof(Lf->type), + (fam == AF_INET) ? "IPv4" : "IPv6"); +#else /* !defined(HASIPv6) */ + (void) snpf(Lf->type, sizeof(Lf->type), "inet"); +#endif /* defined(HASIPv6) */ + +#if defined(HASIPv6) && !defined(HASINRIAIPv6) + if (fam == AF_INET6) { + + /* + * Read IPv6 protocol control block. + */ + if (!s.so_pcb + || kread((KA_T)s.so_pcb, (char *)&in6p, sizeof(in6p))) { + (void) snpf(Namech, Namechl, "can't read in6pcb at %s", + print_kptr((KA_T)s.so_pcb, (char *)NULL, 0)); + enter_nm(Namech); + return; + } + /* + * Save IPv6 address information. + */ + if (p.pr_protocol == IPPROTO_TCP) { + if (in6p.in6p_ppcb) { + if ((ts = ckstate((KA_T)in6p.in6p_ppcb, &t, fam)) == 1) + return; + } + } + enter_dev_ch(print_kptr((KA_T)(in6p.in6p_ppcb ? in6p.in6p_ppcb + : s.so_pcb), + (char *)NULL, 0)); + la = (unsigned char *)&in6p.in6p_laddr; + lp = (int)ntohs(in6p.in6p_lport); + if (!IN6_IS_ADDR_UNSPECIFIED(&in6p.in6p_faddr) + || in6p.in6p_fport) + { + fa = (unsigned char *)&in6p.in6p_faddr; + fp = (int)ntohs(in6p.in6p_fport); + } + } else +#endif /* defined(HASIPv6) && !defined(HASINRIAIPv6) */ + + { + + /* + * Read Ipv4 or IPv6 (INRIA) protocol control block. + */ + if (!s.so_pcb + || kread((KA_T) s.so_pcb, (char *) &inp, sizeof(inp))) { + if (!s.so_pcb) { + (void) snpf(Namech, Namechl, "no PCB%s%s", + +#if defined(HASSBSTATE) + (s.so_snd.sb_state & SBS_CANTSENDMORE) ? +#else /* !defined(HASSBSTATE) */ + (s.so_state & SS_CANTSENDMORE) ? +#endif /* defined(HASSBSTATE) */ + + ", CANTSENDMORE" : "", +#if defined(HASSBSTATE) + (s.so_rcv.sb_state & SBS_CANTRCVMORE) ? +#else /* !defined(HASSBSTATE) */ + (s.so_state & SS_CANTRCVMORE) ? +#endif /* defined(HASSBSTATE) */ + + ", CANTRCVMORE" : ""); + } else { + (void) snpf(Namech, Namechl, "can't read inpcb at %s", + print_kptr((KA_T)s.so_pcb, (char *)NULL, 0)); + } + enter_nm(Namech); + return; + } + if (p.pr_protocol == IPPROTO_TCP) { + if (inp.inp_ppcb) { + if ((ts = ckstate((KA_T)inp.inp_ppcb, &t, fam)) == 1) + return; + } + } + enter_dev_ch(print_kptr((KA_T)(inp.inp_ppcb ? inp.inp_ppcb + : s.so_pcb), + (char *)NULL, 0)); + lp = (int)ntohs(inp.inp_lport); + if (fam == AF_INET) { + + /* + * Save IPv4 address information. + */ + la = (unsigned char *)&inp.inp_laddr; + if (inp.inp_faddr.s_addr != INADDR_ANY || inp.inp_fport) { + fa = (unsigned char *)&inp.inp_faddr; + fp = (int)ntohs(inp.inp_fport); + } + } + +#if defined(HASIPv6) && defined(HASINRIAIPv6) + else { + la = (unsigned char *)&inp.inp_laddr6; + if (!IN6_IS_ADDR_UNSPECIFIED(&inp.inp_faddr6) + || inp.inp_fport) + { + fa = (unsigned char *)&inp.inp_faddr6; + fp = (int)ntohs(inp.inp_fport); + } + } +#endif /* defined(HASIPv6) && defined(HASINRIAIPv6) */ + + } + + +#if defined(HASIPv6) + if ((fam == AF_INET6) + && ((la && IN6_IS_ADDR_V4MAPPED((struct in6_addr *)la)) + || ((fa && IN6_IS_ADDR_V4MAPPED((struct in6_addr *)fa))))) { + + /* + * Adjust for IPv4 addresses mapped in IPv6 addresses. + */ + if (la) + la = (unsigned char *)IPv6_2_IPv4(la); + if (fa) + fa = (unsigned char *)IPv6_2_IPv4(fa); + fam = AF_INET; + } +#endif /* defined(HASIPv6) */ + + /* + * Enter local and remote addresses by address family. + */ + if (fa || la) + (void) ent_inaddr(la, lp, fa, fp, fam); + if (ts == 0) { + Lf->lts.type = 0; + Lf->lts.state.i = (int)t.t_state; + +#if defined(HASTCPOPT) + Lf->lts.mss = (unsigned long)t.t_maxseg; + Lf->lts.msss = (unsigned char)1; + Lf->lts.topt = (unsigned int)t.t_flags; +#endif /* defined(HASTCPOPT) */ + + } + break; +/* + * Process a ROUTE domain socket. + */ + case AF_ROUTE: + (void) snpf(Lf->type, sizeof(Lf->type), "rte"); + if (s.so_pcb) + enter_dev_ch(print_kptr((KA_T)(s.so_pcb), (char *)NULL, 0)); + else + (void) snpf(Namech, Namechl, "no protocol control block"); + if (!Fsize) + Lf->off_def = 1; + break; +/* + * Process a Unix domain socket. + */ + case AF_UNIX: + if (Funix) + Lf->sf |= SELUNX; + (void) snpf(Lf->type, sizeof(Lf->type), "unix"); + /* + * Read Unix protocol control block and the Unix address structure. + */ + + enter_dev_ch(print_kptr(sa, (char *)NULL, 0)); + if (kread((KA_T) s.so_pcb, (char *) &unp, sizeof(unp))) { + (void) snpf(Namech, Namechl, "can't read unpcb at %s", + print_kptr((KA_T)s.so_pcb, (char *)NULL, 0)); + break; + } + if ((struct socket *)sa != unp.unp_socket) { + (void) snpf(Namech, Namechl, "unp_socket (%s) mismatch", + print_kptr((KA_T)unp.unp_socket, (char *)NULL, 0)); + break; + } + if (unp.unp_addr) { + + if (kread((KA_T)unp.unp_addr, (char *)&un, sizeof(un))) + + { + (void) snpf(Namech, Namechl, "can't read unp_addr at %s", + print_kptr((KA_T)unp.unp_addr, (char *)NULL, 0)); + break; + } + + ua = &un; + + } + if (!ua) { + ua = &un; + (void) bzero((char *)ua, sizeof(un)); + ua->sun_family = AF_UNSPEC; + } + /* + * Print information on Unix socket that has no address bound + * to it, although it may be connected to another Unix domain + * socket as a pipe. + */ + if (ua->sun_family != AF_UNIX) { + if (ua->sun_family == AF_UNSPEC) { + if (unp.unp_conn) { + if (kread((KA_T)unp.unp_conn, (char *)&uc, sizeof(uc))) + (void) snpf(Namech, Namechl, + "can't read unp_conn at %s", + print_kptr((KA_T)unp.unp_conn,(char *)NULL,0)); + else + (void) snpf(Namech, Namechl, "->%s", + print_kptr((KA_T)uc.unp_socket,(char *)NULL,0)); + } else + (void) snpf(Namech, Namechl, "->(none)"); + } else + (void) snpf(Namech, Namechl, "unknown sun_family (%d)", + ua->sun_family); + break; + } + if (ua->sun_path[0]) { + + unl = ua->sun_len - offsetof(struct sockaddr_un, sun_path); + if ((unl < 0) || (unl >= sizeof(ua->sun_path))) + unl = sizeof(ua->sun_path) - 1; + ua->sun_path[unl] = '\0'; + + if (ua->sun_path[0] && Sfile && is_file_named(ua->sun_path, 0)) + Lf->sf |= SELNM; + if (ua->sun_path[0] && !Namech[0]) + (void) snpf(Namech, Namechl, "%s", ua->sun_path); + } else + (void) snpf(Namech, Namechl, "no address"); + break; + default: + printunkaf(fam, 1); + } + if (Namech[0]) + enter_nm(Namech); +} diff -Nru dialects/bsdsunix.orig/dstore.c dialects/bsdsunix/dstore.c --- dialects/bsdsunix.orig/dstore.c 1970-01-01 01:00:00.000000000 +0100 +++ dialects/bsdsunix/dstore.c 2016-10-03 18:54:14.556804000 +0200 @@ -0,0 +1,112 @@ +/* + * dstore.c - NSDSUniX global storage for lsof + */ + + +/* + * Copyright 1994 Purdue Research Foundation, West Lafayette, Indiana + * 47907. All rights reserved. + * + * Written by Victor A. Abell + * + * This software is not subject to any license of the American Telephone + * and Telegraph Company or the Regents of the University of California. + * + * Permission is granted to anyone to use this software for any purpose on + * any computer system, and to alter it and redistribute it freely, subject + * to the following restrictions: + * + * 1. Neither the authors nor Purdue University are responsible for any + * consequences of the use of this software. + * + * 2. The origin of this software must not be misrepresented, either by + * explicit claim or by omission. Credit to the authors and Purdue + * University must appear in documentation and sources. + * + * 3. Altered versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 4. This notice may not be removed or altered. + */ + +#ifndef lint +static char copyright[] = +"@(#) Copyright 1994 Purdue Research Foundation.\nAll rights reserved.\n"; +static char *rcsid = "$Id: dstore.c,v 1.8 2008/04/15 13:31:47 abe Exp $"; +#endif + + +#include "lsof.h" + +struct file *Cfp; /* curent file's file struct pointer */ + + +/* + * Drive_Nl -- table to drive the building of Nl[] via build_Nl() + * (See lsof.h and misc.c.) + */ + +struct drive_Nl Drive_Nl[] = { + { X_NCACHE, "_nchashtbl" }, + { X_NCSIZE, "_nchash" }, + { "", "" }, + { NULL, NULL } +}; + +kvm_t *Kd = NULL; /* kvm descriptor */ + +#if defined(P_ADDR) +KA_T Kpa; /* kernel proc struct address */ +#endif /* defined(P_ADDR) */ + +struct l_vfs *Lvfs = NULL; /* local vfs structure table */ + +int Np = 0; /* number of kernel processes */ + +struct kinfo_proc *P = NULL; /* local process table copy */ + +#if defined(HASFSTRUCT) +/* + * Pff_tab[] - table for printing file flags + */ + +struct pff_tab Pff_tab[] = { + { (long)FREAD, FF_READ }, + { (long)FWRITE, FF_WRITE }, + { (long)FNONBLOCK, FF_NBLOCK }, + { (long)FNDELAY, FF_NDELAY }, + { (long)FAPPEND, FF_APPEND }, + { (long)FASYNC, FF_ASYNC }, + { (long)FFSYNC, FF_FSYNC }, + +# if defined(FMARK) + { (long)FMARK, FF_MARK }, +# endif /* defined(FMARK) */ + +# if defined(FDEFER) + { (long)FDEFER, FF_DEFER }, +# endif /* defined(FDEFER) */ + + { (long)FHASLOCK, FF_HASLOCK }, + { (long)O_NOCTTY, FF_NOCTTY }, + { (long)0, NULL } +}; + + +/* + * Pof_tab[] - table for print process open file flags + */ + +struct pff_tab Pof_tab[] = { + +# if defined(UF_EXCLOSE) + { (long)UF_EXCLOSE, POF_CLOEXEC }, +# endif /* defined(UF_EXCLOSE) */ + +# if defined(UF_MAPPED) + { (long)UF_MAPPED, POF_MAPPED }, +# endif /* defined(UF_MAPPED) */ + + { (long)0, NULL } +}; +#endif /* defined(HASFSTRUCT) */ diff -Nru dialects/bsdsunix.orig/dzfs.h dialects/bsdsunix/dzfs.h --- dialects/bsdsunix.orig/dzfs.h 1970-01-01 01:00:00.000000000 +0100 +++ dialects/bsdsunix/dzfs.h 2016-10-03 18:55:18.515594000 +0200 @@ -0,0 +1,108 @@ +/* + * dzfs.h - BSDSUniX header file for ZFS + */ + + +/* + * Copyright 2008 Purdue Research Foundation, West Lafayette, Indiana + * 47907. All rights reserved. + * + * Written by Victor A. Abell + * + * This software is not subject to any license of the American Telephone + * and Telegraph Company or the Regents of the University of California. + * + * Permission is granted to anyone to use this software for any purpose on + * any computer system, and to alter it and redistribute it freely, subject + * to the following restrictions: + * + * 1. Neither the authors nor Purdue University are responsible for any + * consequences of the use of this software. + * + * 2. The origin of this software must not be misrepresented, either by + * explicit claim or by omission. Credit to the authors and Purdue + * University must appear in documentation and sources. + * + * 3. Altered versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 4. This notice may not be removed or altered. + */ + + +/* + * $Id: dzfs.h,v 1.3 2011/08/07 22:51:28 abe Exp $ + */ + + +#if !defined(BSDSUNIX_ZFS_H) +#define BSDSUNIX_ZFS_H 1 +# if defined(HAS_ZFS) + + +/* + * The _PROTOTYPE macro provides strict ANSI C prototypes if __STDC__ + * is defined, and old-style K&R prototypes otherwise. + * + * (With thanks to Andy Tanenbaum) + */ + +# if defined(__STDC__) +#define _PROTOTYPE(function, params) function params +# else /* !defined(__STDC__) */ +#define _PROTOTYPE(function, params) function() +# endif /* defined(__STDC__) */ + + +/* + * The following define keeps gcc>=2.7 from complaining about the failure + * of the Exit() function to return. + * + * Paul Eggert supplied it. + */ + +# if defined(__GNUC__) && !(__GNUC__<2 || (__GNUC__==2 && __GNUC_MINOR__<7)) +#define exiting __attribute__((__noreturn__)) +# else /* !gcc || gcc<2.7 */ +#define exiting +# endif /* gcc && gcc>=2.7 */ + +# if !defined(INODETYPE) +#define INODETYPE unsigned long long +# endif /* !defined(INODETYPE) */ + +# if !defined(BSDSUNIX_KA_T) +typedef u_long KA_T; +#define BSDSUNIX_KA_T 1 /* for dlsof.h */ +# endif /* !defined(BSDSUNIX_KA_T) */ + +# if !defined(READLEN_T) +#define READLEN_T int +# endif /* !defined(READLEN_T) */ + +# if !defined(SZOFFTYPE) +#define SZOFFTYPE unsigned long long +# endif /* !defined(SZOFFTYPE) */ + + +/* + * Structure for passing znode info + */ + +typedef struct zfs_info { + INODETYPE ino; /* inode number */ + KA_T lockf; /* znode's z_lockf pointer */ + long nl; /* number of links */ + dev_t rdev; /* "raw" device number */ + SZOFFTYPE sz; /* size */ + unsigned char ino_def; /* ino defined status */ + unsigned char nl_def; /* nl defined status */ + unsigned char rdev_def; /* rdev defined status */ + unsigned char sz_def; /* sz defined status */ +} zfs_info_t; + +_PROTOTYPE(extern int kread,(KA_T addr, char *buf, READLEN_T len)); +_PROTOTYPE(extern char *readzfsnode,(KA_T va, zfs_info_t *zi, int vr)); + +# endif /* defined(HAS_ZFS) */ +#endif /* defined(BSDSUNIX_DZFS_H) */ diff -Nru dialects/bsdsunix.orig/include/procfs/pfsnode.h dialects/bsdsunix/include/procfs/pfsnode.h --- dialects/bsdsunix.orig/include/procfs/pfsnode.h 1970-01-01 01:00:00.000000000 +0100 +++ dialects/bsdsunix/include/procfs/pfsnode.h 2016-01-05 19:31:36.000000000 +0100 @@ -0,0 +1,217 @@ +/* + * Copyright (c) 1993 Paul Kranenburg + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Paul Kranenburg. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software withough specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $Id: pfsnode.h,v 1.1 1993/12/12 12:26:39 davidg Exp $ + */ + +/* + * This structure defines the control data for the proc file system. + */ + +struct pfsnode { + struct pfsnode *pfs_next; /* next on list */ + struct vnode *pfs_vnode; /* vnode associated with this pfsnode */ + pid_t pfs_pid; /* associated process */ + u_short pfs_mode; /* mode bits for stat() */ + uid_t pfs_uid; /* process' owner */ + gid_t pfs_gid; /* process' group */ + u_long pfs_vflags; /* chflags() flags */ + u_long pfs_flags; /* open flags */ + struct vmspace *pfs_vs; +}; + +struct pfsnode *pfshead; + +/* + * Format of a directory entry in /proc + */ +struct pfsdent { + unsigned long d_fileno; + unsigned short d_reclen; + unsigned short d_namlen; + char d_nam[8]; +}; +#define PFSDENTSIZE (sizeof(struct direct) - MAXNAMELEN + 8) + +#ifndef DIRBLKSIZ +#define DIRBLKSIZ DEV_BSIZE +#endif + +#ifdef DEBUG +int pfs_debug; +#endif + +/* + * Convert between pfsnode pointers and vnode pointers + */ +#define VTOPFS(vp) ((struct pfsnode *)(vp)->v_data) +#define PFSTOV(pfsp) ((pfsp)->pfs_vnode) + +/* + * Prototypes for PFS operations on vnodes. + */ +int pfs_badop(); +int pfs_doio(); +int pfs_lookup __P(( \ + struct vnode *vp, \ + struct nameidata *ndp, \ + struct proc *p)); +#define pfs_create ((int (*) __P(( \ + struct nameidata *ndp, \ + struct vattr *vap, \ + struct proc *p))) pfs_badop) +#define pfs_mknod ((int (*) __P(( \ + struct nameidata *ndp, \ + struct vattr *vap, \ + struct ucred *cred, \ + struct proc *p))) pfs_badop) +int pfs_open __P(( + struct vnode *vp, + int mode, + struct ucred *cred, + struct proc *p)); +int pfs_close __P(( + struct vnode *vp, + int fflag, + struct ucred *cred, + struct proc *p)); +int pfs_access __P(( + struct vnode *vp, + int mode, + struct ucred *cred, + struct proc *p)); +int pfs_getattr __P(( + struct vnode *vp, + struct vattr *vap, + struct ucred *cred, + struct proc *p)); +int pfs_setattr __P(( + struct vnode *vp, + struct vattr *vap, + struct ucred *cred, + struct proc *p)); +#define pfs_read ((int (*) __P(( \ + struct vnode *vp, \ + struct uio *uio, \ + int ioflag, \ + struct ucred *cred))) pfs_doio) +#define pfs_write ((int (*) __P(( \ + struct vnode *vp, \ + struct uio *uio, \ + int ioflag, \ + struct ucred *cred))) pfs_doio) +int pfs_ioctl __P(( + struct vnode *vp, + int command, + caddr_t data, + int fflag, + struct ucred *cred, + struct proc *p)); +#define pfs_select ((int (*) __P(( \ + struct vnode *vp, \ + int which, \ + int fflags, \ + struct ucred *cred, \ + struct proc *p))) pfs_badop) +#define pfs_mmap ((int (*) __P(( \ + struct vnode *vp, \ + int fflags, \ + struct ucred *cred, \ + struct proc *p))) pfs_badop) +#define pfs_fsync ((int (*) __P(( \ + struct vnode *vp, \ + int fflags, \ + struct ucred *cred, \ + int waitfor, \ + struct proc *p))) pfs_badop) +#define pfs_seek ((int (*) __P(( \ + struct vnode *vp, \ + off_t oldoff, \ + off_t newoff, \ + struct ucred *cred))) pfs_badop) +#define pfs_remove ((int (*) __P(( \ + struct nameidata *ndp, \ + struct proc *p))) pfs_badop) +#define pfs_link ((int (*) __P(( \ + struct vnode *vp, \ + struct nameidata *ndp, \ + struct proc *p))) pfs_badop) +#define pfs_rename ((int (*) __P(( \ + struct nameidata *fndp, \ + struct nameidata *tdnp, \ + struct proc *p))) pfs_badop) +#define pfs_mkdir ((int (*) __P(( \ + struct nameidata *ndp, \ + struct vattr *vap, \ + struct proc *p))) pfs_badop) +#define pfs_rmdir ((int (*) __P(( \ + struct nameidata *ndp, \ + struct proc *p))) pfs_badop) +#define pfs_symlink ((int (*) __P(( \ + struct nameidata *ndp, \ + struct vattr *vap, \ + char *target, \ + struct proc *p))) pfs_badop) +int pfs_readdir __P(( + struct vnode *vp, + struct uio *uio, + struct ucred *cred, + int *eofflagp)); +#define pfs_readlink ((int (*) __P(( \ + struct vnode *vp, \ + struct uio *uio, \ + struct ucred *cred))) pfs_badop) +#define pfs_abortop ((int (*) __P(( \ + struct nameidata *ndp))) pfs_badop) +int pfs_inactive __P(( + struct vnode *vp, + struct proc *p)); +int pfs_reclaim __P(( + struct vnode *vp)); +#define pfs_lock ((int (*) __P(( \ + struct vnode *vp))) nullop) +#define pfs_unlock ((int (*) __P(( \ + struct vnode *vp))) nullop) +int pfs_bmap __P(( + struct vnode *vp, + daddr_t bn, + struct vnode **vpp, + daddr_t *bnp)); +int pfs_strategy __P(( + struct buf *bp)); +void pfs_print __P(( + struct vnode *vp)); +#define pfs_islocked ((int (*) __P(( \ + struct vnode *vp))) nullop) +#define pfs_advlock ((int (*) __P(( \ + struct vnode *vp, \ + caddr_t id, \ + int op, \ + struct flock *fl, \ + int flags))) pfs_badop) diff -Nru dialects/bsdsunix.orig/machine.h dialects/bsdsunix/machine.h --- dialects/bsdsunix.orig/machine.h 1970-01-01 01:00:00.000000000 +0100 +++ dialects/bsdsunix/machine.h 2016-10-03 18:56:58.154930000 +0200 @@ -0,0 +1,661 @@ +/* + * machine.h - BSDSUniX definitions for lsof + */ + + +/* + * Copyright 1994 Purdue Research Foundation, West Lafayette, Indiana + * 47907. All rights reserved. + * + * Written by Victor A. Abell + * + * This software is not subject to any license of the American Telephone + * and Telegraph Company or the Regents of the University of California. + * + * Permission is granted to anyone to use this software for any purpose on + * any computer system, and to alter it and redistribute it freely, subject + * to the following restrictions: + * + * 1. Neither the authors nor Purdue University are responsible for any + * consequences of the use of this software. + * + * 2. The origin of this software must not be misrepresented, either by + * explicit claim or by omission. Credit to the authors and Purdue + * University must appear in documentation and sources. + * + * 3. Altered versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 4. This notice may not be removed or altered. + */ + + +/* + * $Id: machine.h,v 1.39 2015/07/07 20:23:43 abe Exp $ + */ + + +#if !defined(LSOF_MACHINE_H) +#define LSOF_MACHINE_H 1 + +#include + +# if defined(HAS_CONF_MINOR) +#undef minor +# endif /* defined(HAS_CONF_MINOR) */ + +#if defined(HASCPUMASK_T) +/* + * In BSDSUniX >= 1.0 when the cpumask_t typedef is present, it may be defined + * in only if _KERNEL is predefined. However, predefining + * _KERNEL before #include'ing causes redefinition errors for + * boolean_t and vm_page_t when is #include'd with _KERNEL + * predefined. Since lsof must have _KERNEL predefined when is + * #include'd, the expedient choice is made to duplicate the cpumask_t typedef + * here. + * + * Note: the Configure script defines HASCPUMASK_T if and + * both have cpumask_t references and if the reference in + * is valid only when _KERNEL is defined. + */ + +typedef __cpumask_t cpumask_t; +#endif /* defined(HASCPUMASK_T) */ + +#if defined(NEEDS_BOOL_TYPEDEF) +/* + * Under FreeBSD 10.0 on the i386 architecture the bool typedef is not defined + * unless is #included under _KERNEL. As explained with + * cpumask_t, #include'ing under _KERNEL causes other problems. + * Hence Configure specifies that bool be typedef'd here specifically for the + * i386 architecture on FreeBSD 10.0. + */ +# if __STDC_VERSION__<199901L && __GNUC__<3 && !defined(__INTEL_COMPILER) +typedef int _Bool; +# endif /*__STDC_VERSION__<199901L && __GNUC__<3 && !defined(__INTEL_COMPILER)*/ +typedef _Bool bool; +#endif /* defined(NEEDS_BOOL_TYPEDEF) */ + +#include + + +/* + * CAN_USE_CLNT_CREATE is defined for those dialects where RPC clnt_create() + * can be used to obtain a CLIENT handle in lieu of clnttcp_create(). + */ + +#define CAN_USE_CLNT_CREATE 1 + + +/* + * DEVDEV_PATH defines the path to the directory that contains device + * nodes. + */ + +#define DEVDEV_PATH "/dev" + + +/* + * GET_MAX_FD is defined for those dialects that provide a function other than + * getdtablesize() to obtain the maximum file descriptor number plus one. + */ + +/* #define GET_MAX_FD ? */ + + +/* + * HASAOPT is defined for those dialects that have AFS support; it specifies + * that the default path to an alternate AFS kernel name list file may be + * supplied with the -A option. + */ + +/* #define HASAOPT 1 */ + + +/* + * HASBLKDEV is defined for those dialects that want block device information + * recorded in BDevtp[]. + */ + + + +/* + * HASDCACHE is defined for those dialects that support a device cache + * file. + * + * HASENVDC defined the name of an environment variable that contains the + * device cache file path. The HASENVDC environment variable is ignored when + * the lsof process is setuid(root) or its real UID is 0. + * + * HASPERSDC defines the format for the last component of a personal device + * cache file path. The first will be the home directory of the real UID that + * executes lsof. + * + * HASPERSDCPATH defines the environment variable whose value is the middle + * component of the personal device cache file path. The middle component + * follows the home directory and precedes the results of applying HASPERSDC. + * The HASPERSDCPATH environment variable is ignored when the lsof process is + * setuid(root) or its real UID is 0. + * + * HASSYSDC defines a public device cache file path. When it's defined, it's + * used as the path from which to read the device cache. + * + * Consult the 00DCACHE and 00FAQ files of the lsof distribution for more + * information on device cache file path construction. + */ + +#define HASDCACHE 1 +#define HASENVDC "LSOFDEVCACHE" +#define HASPERSDC "%h/%p.lsof_%L" +#define HASPERSDCPATH "LSOFPERSDCPATH" +/* #define HASSYSDC "/your/choice/of/path" */ + + +/* + * HASCDRNODE is defined for those dialects that have CD-ROM nodes. + */ + +/* #define HASCDRNODE 1 */ + + +/* + * HASFIFONODE is defined for those dialects that have FIFO nodes. + */ + +/* #define HASFIFONODE 1 */ + + +/* + * HASFSINO is defined for those dialects that have the file system + * inode element, fs_ino, in the lfile structure definition in lsof.h. + */ + +/* #define HASFSINO 1 */ + + +/* + * HASFSTRUCT is defined if the dialect has a file structure. + * + * FSV_DEFAULT defines the default set of file structure values to list. + * It defaults to zero (0), but may be made up of a combination of the + * FSV_* symbols from lsof.h. + * + * HASNOFSADDR -- has no file structure address + * HASNOFSFLAGS -- has no file structure flags + * HASNOFSCOUNT -- has no file structure count + * HASNOFSNADDR -- has no file structure node address + */ + +#define HASFSTRUCT 1 +/* #define FSV_DEFAULT FSV_? | FSV_? | FSV_? */ +/* #define HASNOFSADDR 1 has no file structure address */ +/* #define HASNOFSFLAGS 1 has no file structure flags */ +/* #define HASNOFSCOUNT 1 has no file structure count */ +/* #define HASNOFSNADDR 1 has no file structure node address */ + + +/* + * HASGNODE is defined for those dialects that have gnodes. + */ + +/* #define HASGNODE 1 */ + + +/* + * HASHSNODE is defined for those dialects that have High Sierra nodes. + */ + +/* #define HASHSNODE 1 */ + + +/* + * HASINODE is defined for those dialects that have inodes and wish to + * use readinode() from node.c. + */ + +#define HASINODE 1 + + +/* + * HASINTSIGNAL is defined for those dialects whose signal function returns + * an int. + */ + +/* #define HASINTSIGNAL 1 */ + + +/* + * HASKERNIDCK is defined for those dialects that support the comparison of + * the build to running kernel identity. + */ + +#define HASKERNIDCK 1 + + +/* + * HASKOPT is defined for those dialects that support the -k option of + * reading the kernel's name list from an optional file. + */ + +#define HASKOPT 1 + + +/* + * HASLFILEADD is defined for those dialects that need additional elements + * in struct lfile. The HASLFILEADD definition is a macro that defines + * them. If any of the additional elements need to be preset in the + * alloc_lfile() function of proc.c, the SETLFILEADD macro may be defined + * to do that. + * + * If any additional elements need to be cleared in alloc_lfile() or in the + * free_proc() function of proc.c, the CLRLFILEADD macro may be defined to + * do that. Note that CLRLFILEADD takes one argument, the pointer to the + * lfile struct. The CLRLFILEADD macro is expected to expand to statements + * that are complete -- i.e., have terminating semi-colons -- so the macro is + * called without a terminating semicolon by proc.c. + * + * The HASXOPT definition may be used to select the conditions under which + * private lfile elements are used. + */ + +/* #define HASLFILEADD int ... */ +/* #define CLRLFILEADD(lf) (lf)->... = (type)NULL; */ +/* #define SETLFILEADD Lf->... */ + + +/* + * HASMNTSTAT indicates the dialect supports the mount stat(2) result option + * in its l_vfs and mounts structures. + */ + +/* #define HASMNTSTAT 1 */ + + +/* + * HASMNTSUP is defined for those dialects that support the mount supplement + * option. + */ + +/* #define HASMNTSUP 1 */ + + +/* + * HASMOPT is defined for those dialects that support the reading of + * kernel memory from an alternate file. + */ + +#define HASMOPT 1 + + +/* + * HASNCACHE is defined for those dialects that have a kernel name cache + * that lsof can search. A value of 1 directs printname() to prefix the + * cache value with the file system directory name; 2, avoid the prefix. + * + * NCACHELDPFX is a set of C commands to execute before calling ncache_load(). + * + * NCACHELDSFX is a set of C commands to execute after calling ncache_load(). + */ + +#define HASNCACHE 1 +/* #define NCACHELDPFX ??? */ +/* #define NCACHELDSFX ??? */ + + +/* + * HASNLIST is defined for those dialects that use nlist() to acccess + * kernel symbols. + */ + +#define HASNLIST 1 + + +/* + * HASPIPEFN is defined for those dialects that have a special function to + * process DTYPE_PIPE file structure entries. Its value is the name of the + * function. + * + * NOTE: don't forget to define a prototype for this function in dproto.h. + */ + +#define HASPIPEFN process_pipe + + +/* + * HASPIPENODE is defined for those dialects that have pipe nodes. + */ + +/* #define HASPIPENODE 1 */ + + +/* + * HASPMAPENABLED is defined when the reporting of portmapper registration + * info is enabled by default. + */ + +/* #define HASPMAPENABLED 1 */ + + +/* + * HASPPID is defined for those dialects that support identification of + * the parent process IDentifier (PPID) of a process. + */ + +#define HASPPID 1 + + +/* + * HASPRINTDEV, HASPRINTINO, HASPRINTNM, HASPRINTOFF, and HASPRINTSZ + * define private dialect-specific functions for printing DEVice numbers, + * INOde numbers, NaMes, file OFFsets, and file SiZes. The functions are + * called from print_file(). + */ + +/* #define HASPRINTDEV print_dev? */ +/* #define HASPRINTINO print_ino? */ +/* #define HASPRINTNM print_nm? */ +/* #define HASPRINTOFF print_off? */ +/* #define HASPRINTSZ print_sz? */ + + +/* + * HASPRIVFILETYPE and PRIVFILETYPE are defined for dialects that have a + * file structure type that isn't defined by a DTYPE_* symbol. They are + * used in lib/prfp.c to select the type's processing. + * + * PRIVFILETYPE is the definition of the f_type value in the file struct. + * + * HASPRIVFILETYPE is the name of the processing function. + */ + +/* #define HASPRIVFILETYPE process_shmf? */ +/* #define PRIVFILETYPE ?? */ + + +/* + * HASPRIVNMCACHE is defined for dialects that have a private method for + * printing cached NAME column values for some files. HASPRIVNAMECACHE + * is defined to be the name of the function. + * + * The function takes one argument, a struct lfile pointer to the file, and + * returns non-zero if it prints a name to stdout. + */ + +/* #define HASPRIVNMCACHE */ + + +/* + * HASPRIVPRIPP is defined for dialects that have a private function for + * printing IP protocol names. When HASPRIVPRIPP isn't defined, the + * IP protocol name printing function defaults to printiprto(). + */ + +/* #define HASPRIVPRIPP 1 */ + + +/* + * HASPROCFS is defined for those dialects that have a proc file system -- + * usually /proc and usually in SYSV4 derivatives. For FreeBSD 2.0 and + * above the Configure script defines HASPROCFS when it can find + * /usr/src/sys/miscfs/procfs/procfs.h; below 2.0, Configure always defines + * HASPROCFS. + * + * HASFSTYPE is defined as 1 for those systems that have a file system type + * string, st_fstype, in the stat() buffer; 2, for those systems that have a + * file system type integer in the stat() buffer, named MOUNTS_STAT_FSTYPE; + * 0, for systems whose stat(2) structure has no file system type member. The + * additional symbols MOUNTS_FSTYPE, RMNT_FSTYPE, and RMNT_STAT_FSTYPE may be + * defined in dlsof.h to direct how the readmnt() function in lib/rmnt.c + * preserves these stat(2) and getmntent(3) buffer values in the local mounts + * structure. + * + * The defined value is the string that names the file system type. + * + * The HASPROCFS definition usually must be accompanied by the HASFSTYPE + * definition and the providing of an fstype element in the local mounts + * structure (defined in dlsof.h). + * + * The HASPROCFS definition may be accompanied by the HASPINODEN definition. + * HASPINODEN specifies that searching for files in HASPROCFS is to be done + * by inode number. + */ + +# if defined(HASPROCFS) +#undef HASPROCFS +#define HASPROCFS "proc" +# endif /* defined(HASPROCFS) */ + +/* #define HASPROCFS "proc?" */ +/* #define HASFSTYPE 1 */ + +#define HASPINODEN 1 + + +/* + * HASRNODE is defined for those dialects that have rnodes. + */ + +/* #define HASRNODE 1 */ + + +/* + * Define HASSECURITY to restrict the listing of all open files to the + * root user. When HASSECURITY is defined, the non-root user may list + * only files whose processes have the same user ID as the real user ID + * (the one that its user logged on with) of the lsof process. + */ + +/* #define HASSECURITY 1 */ + + +/* + * If HASSECURITY is defined, define HASNOSOCKSECURITY to allow users + * restricted by HASSECURITY to list any open socket files, provide their + * listing is selected by the "-i" option. + */ + +/* #define HASNOSOCKSECURITY 1 */ + + +/* + * HASSETLOCALE is defined for those dialects that have and + * setlocale(). + * + * If the dialect also has wide character support for language locales, + * HASWIDECHAR activates lsof's wide character support and WIDECHARINCL + * defines the header file (if any) that must be #include'd to use the + * mblen() and mbtowc() functions. + */ + +#define HASSETLOCALE 1 + +#define HASWIDECHAR 1 + +/* #define WIDECHARINCL */ + + +/* + * HASSNODE is defined for those dialects that have snodes. + */ + +/* #define HASSNODE 1 */ + + +/* + * HASTASKS is defined for those dialects that have task reporting support. + */ + +/* #define HASTASKS 1 */ + + +/* + * HASSOOPT, HASSOSTATE and HASTCPOPT define the availability of information + * on socket options (SO_* symbols), socket states (SS_* symbols) and TCP + * options. + */ + +#define HASSOOPT 1 /* has socket option information */ +#define HASSOSTATE 1 /* has socket state information */ +#define HASTCPOPT 1 /* has TCP options or flags */ + + +/* + * Define HASSPECDEVD to be the name of a function that handles the results + * of a successful stat(2) of a file name argument. + * + * For example, HASSPECDEVD() for Darwin makes sure that st_dev is set to + * what stat("/dev") returns -- i.e., what's in DevDev. + * + * The function takes two arguments: + * + * 1: pointer to the full path name of file + * 2: pointer to the stat(2) result + * + * The function returns void. + */ + +/* #define HASSPECDEVD process_dev_stat */ + + +/* + * HASSTREAMS is defined for those dialects that support streams. + */ + +/* #define HASSTREAMS 1 */ + + +/* + * HASTCPTPIQ is defined for dialects where it is possible to report the + * TCP/TPI Recv-Q and Send-Q values produced by netstat. + */ + +#define HASTCPTPIQ 1 + + +/* + * HASTCPTPIW is defined for dialects where it is possible to report the + * TCP/TPI send and receive window sizes produced by netstat. + */ + +/* #define HASTCPTPIW 1 */ + + +/* + * HASTCPUDPSTATE is defined for dialects that have TCP and UDP state + * support -- i.e., for the "-stcp|udp:state" option and its associated + * speed improvements. + */ + +#define HASTCPUDPSTATE 1 + + +/* + * HASTMPNODE is defined for those dialects that have tmpnodes. + */ + +/* #define HASTMPNODE 1 */ + + +/* + * HASVNODE is defined for those dialects that use the Sun virtual file system + * node, the vnode. BSD derivatives usually do; System V derivatives prior + * to R4 usually don't. + * doesn't. + */ + +#define HASVNODE 1 + + +/* + * HASXOPT is defined for those dialects that have an X option. It + * defines the text for the usage display. HASXOPT_VALUE defines the + * option's default binary value -- 0 or 1. + */ + +/* #define HASXOPT "help text for X option" */ +/* #define HASXOPT_VALUE 1 */ + + +/* + * INODETYPE and INODEPSPEC define the internal node number type and its + * printf specification modifier. These need not be defined and lsof.h + * can be allowed to define defaults. + * + * These are defined here, because they must be used in dlsof.h. + */ + +#define INODETYPE unsigned long long + /* inode number internal storage type */ +#define INODEPSPEC "ll" /* INODETYPE printf specification + * modifier */ + + +/* + * UID_ARG defines the size of a User ID number when it is passed + * as a function argument. + */ + +#define UID_ARG int + + +/* + * Each USE_LIB_ is defined for dialects that use the + * in the lsof library. + * + * Note: other definitions and operations may be required to condition the + * library function source code. They may be found in the dialect dlsof.h + * header files. + */ + +#define USE_LIB_CKKV 1 /* ckkv.c */ +/* #define USE_LIB_COMPLETEVFS 1 cvfs.c */ +#define USE_LIB_FIND_CH_INO 1 /* fino.c */ +#define USE_LIB_IS_FILE_NAMED 1 /* isfn.c */ +#define USE_LIB_LKUPDEV 1 /* lkud.c */ +#define USE_LIB_PRINTDEVNAME 1 /* pdvn.c */ +#define USE_LIB_PROCESS_FILE 1 /* prfp.c */ +#define USE_LIB_PRINT_TCPTPI 1 /* ptti.c */ +#define USE_LIB_READDEV 1 /* rdev.c */ +/* #define USE_LIB_READMNT 1 rmnt.c */ +/* #define USE_LIB_REGEX 1 regex.c */ + +#define USE_LIB_RNMH 1 /* rnmh.c */ + +/* #define USE_LIB_RNCH 1 rnch.c */ +/* #define USE_LIB_SNPF 1 snpf.c */ +#define snpf snprintf /* use the system's snprintf() */ + + +/* + * WARNDEVACCESS is defined for those dialects that should issue a warning + * when lsof can't access /dev (or /device) or one of its sub-directories. + * The warning can be inhibited by the lsof caller with the -w option. + */ + +#define WARNDEVACCESS 1 + + +/* + * WARNINGSTATE is defined for those dialects that want to suppress all lsof + * warning messages. + */ + +/* #define WARNINGSTATE 1 warnings are enabled by default */ + + +/* + * WILLDROPGID is defined for those dialects whose lsof executable runs + * setgid(not_real_GID) and whose setgid power can be relinquished after + * the dialect's initialize() function has been executed. + */ + +#define WILLDROPGID 1 + + +/* + * zeromem is a macro that uses bzero or memset. + */ + +#define zeromem(a, l) memset(a, 0, l) + +#endif /* !defined(LSOF_MACHINE_H) */