/* * dlsof.h - FreeBSD 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.45 2013/01/02 17:01:43 abe Exp $ */ #if !defined(FREEBSD_LSOF_H) #define FREEBSD_LSOF_H 1 #include #include #include #include #include #include # if FREEBSDV>=4000 # if FREEBSDV>=5000 # if FREEBSDV<6020 # if defined(__alpha__) /* * For Alpha below 6.2, #include before #define'ing _KERNEL. * Then #define PCPU_MD_FIELDS independently. This hack avoids a compiler * complaint about register use. */ #include #define PCPU_MD_FIELDS \ struct alpha_pcb pc_idlepcb; /* pcb for idling */ \ u_int64_t pc_idlepcbphys; /* pa of pc_idlepcb */ \ u_int64_t pc_pending_ipis; /* pending IPI's */ \ u_int32_t pc_next_asn; /* next ASN to alloc */ \ u_int32_t pc_current_asngen /* ASN rollover check */ # endif /* defined(__alpha__) */ # endif /* FREEBSDV<6020 */ #define _KERNEL 1 # endif /* FREEBSDV>=5000 */ # 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 FreeBSD 9 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 "fbsd_minor.h" # endif /* defined(HAS_CONF_MINOR) */ # if FREEBSDV>=5000 #undef _KERNEL # endif /* FREEBSDV>=5000 */ # endif /* FREEBSDV>=4000 */ #include #include #define NFS #define m_stat mnt_stat # if FREEBSDV>=3020 #define _KERNEL # endif /* FREEBSDV>=3020 */ #include # if FREEBSDV>=3020 # 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 # endif /* FREEBSDV>=3020 */ #include #include #include #include #include #include # if FREEBSDV>=3000 #undef INADDR_LOOPBACK # endif /* FREEBSDV>=3000 */ #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 # if FREEBSDV<2000 #include #include #include #include # else /* FREEBSDV>=2000 */ #include #include # if FREEBSDV>=4000 && FREEBSDV<5000 # if defined(__alpha__) || defined(__sparc64__) #define dev_t void * # endif /* defined(__alpha__) || defined(__sparc64__) */ # endif /* FREEBSDV>=4000 && FREEBSDV<5000 */ #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) */ # if FREEBSDV>=5010 #undef i_devvp # endif /* FREEBSDV>=5010 */ # if FREEBSDV>=4000 && FREEBSDV<5000 # if defined(__alpha__) || defined(__sparc64__) #undef dev_t # endif /* defined(__alpha__) || defined(__sparc64__) */ # endif /* FREEBSDV>=4000 && FREEBSDV<5000 */ # if FREEBSDV<2020 #include # endif /* FREEBSDV<2020 */ # endif /* FREEBSDV<2000 */ # if FREEBSDV<5000 #include # else /* FREEBSDV>=5000 */ #include # endif /* FREEBSDV<5000 */ # if defined(HASRPCV2H) #include # endif /* defined(HASRPCV2H) */ # if FREEBSDV>=5000 #include #include # else /* FREEBSDV<5000 */ #include #include # endif /* FREEBSDV>=5000 */ #include #include #undef TRUE #undef FALSE # if FREEBSDV<2000 #include # else /* FREEBSDV>=2000 */ #include # endif /* FREEBSDV<2000 */ # if defined(HASFDESCFS) #define _KERNEL #define KERNEL # if FREEBSDV>=5000 #include # else /* FREEBSDV<5000 */ #include # endif /* FREEBSDV>=5000 */ #undef _KERNEL #undef KERNEL # endif /* defined(HASFDESCFS) */ # if defined(HASNULLFS) #define _KERNEL #define KERNEL struct vop_generic_args; # if FREEBSDV>=5000 #include # else /* FREEBSDV<5000 */ #include # endif /* FREEBSDV>=5000 */ #undef _KERNEL #undef KERNEL # endif /* defined(HASNULLFS) */ # if defined(HASPROCFS) # if FREEBSDV<2000 #include # else /* FREEBSDV>=2000 */ # if FREEBSDV<5000 #include # endif /* FREEBSDV<5000 */ #include # endif /* FREEBSDV<2000 */ #define PNSIZ 5 # endif /* defined(HASPROCFS) */ # if defined(HASPSEUDOFS) #include # endif /* defined(HASPSEUDOFS) */ # if defined(HAS_ZFS) #include "dzfs.h" # endif /* defined(HAS_ZFS) */ # if FREEBSDV<2000 #define P_COMM p_comm #define P_FD p_fd #define P_PID p_pid #define P_PGID p_pgrp #define P_STAT p_stat #define P_VMSPACE p_vmspace # else /* FREEBSDV>=2000 */ # if FREEBSDV<5000 #define P_ADDR kp_eproc.e_paddr #define P_COMM kp_proc.p_comm #define P_FD kp_proc.p_fd #define P_PID kp_proc.p_pid #define P_PGID kp_eproc.e_pgid #define P_PPID kp_eproc.e_ppid #define P_STAT kp_proc.p_stat #define P_VMSPACE kp_proc.p_vmspace # else /* FREEBSDV>=5000 */ #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 # endif /* FREEBSDV<5000 */ # endif /* FREEBSDV<2000 */ #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 #define pause pause_kernel_lsof #define setenv setenv_kernel_lsof #define uintfptr_t int #define _SYS_LIBKERN_H_ #include /* * Attempt to remove the circumventions. */ #undef _SYS_LIBKERN_H_ #undef intrmask_t_lsof #undef log_kernel_lsof #undef pause_kernel_lsof #undef setenv_kernel_lsof #undef uintfptr_t #undef _KERNEL #undef KERNEL # if defined(DTYPE_KQUEUE) #define HASKQUEUE /* has the kqueue file type */ # if FREEBSDV>=4090 #define _KERNEL # endif /* FREEBSDV>=4090 */ #include # if FREEBSDV>=4090 #undef _KERNEL # endif /* FREEBSDV>=4090 */ # endif /* defined(DTYPE_KQUEUE) */ # if FREEBSDV<2000 #include # else /* FREEBSDV>=2000 */ struct vop_advlock_args { int dummy; }; /* to pacify lf_advlock() prototype */ # if FREEBSDV>=5000 #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 # endif /* FREEBSDV>=5000 */ #include # endif /* FREEBSDV<2000 */ #include # if FREEBSDV>=2020 # if FREEBSDV>=4090 #define _KERNEL # endif /* FREEBSDV>=4090 */ #include # if FREEBSDV>=4090 #undef _KERNEL # endif /* FREEBSDV>=4090 */ # if defined(HASVMLOCKH) #include # endif /* defined(HASVMLOCKH) */ #include # endif /* FREEBSDV>=2020 */ #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 # if FREEBSDV>=2020 #undef B_NEEDCOMMIT # if FREEBSDV>=5000 #include # endif /* FREEBSDV>=5000 */ #include #include # if FREEBSDV<5000 #include # endif /* FREEBSDV<5000 */ # endif /* FREEBSDV>=2020 */ #include #define COMP_P const void #define DEVINCR 1024 /* device table malloc() increment */ # if !defined(FREEBSD_KA_T) # if FREEBSDV<2000 typedef off_t KA_T; # else /* FREEBSDV>=2000 */ typedef u_long KA_T; # endif /* FREEBSDV<2000 */ # endif /* !defined(FREEBSD_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; # if FREEBSDV>=2000 extern kvm_t *Kd; # endif /* FREEBSDV>=2000 */ # 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 */ # if FREEBSDV>=2000 extern struct kinfo_proc *P; /* local process table copy */ # endif /* FREEBSDV>=2000 */ 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 */ }; # if FREEBSDV==4100 || FREEBSDV==4110 #define XDR_VOID (xdrproc_t)xdr_void #define XDR_PMAPLIST (xdrproc_t)xdr_pmaplist # endif /* FREEBSDV==4100 || FREEBSDV==4110 */ # if FREEBSDV>=5000 #define XDR_VOID (const xdrproc_t)xdr_void #define XDR_PMAPLIST (const xdrproc_t)xdr_pmaplist # endif /* FREEBSDV>=5000 */ /* * 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 FREEBSDV<4000 || (FREEBSDV>=4000 && defined(HASNAMECACHE)) #include # else /* FREEBSDV>=4000 && !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 /* FREEBSDV<4000 || (FREEBSDV>=4000 && 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 */ # if FREEBSDV<2005 #define NCACHE_NXT nc_nxt /* link in NCACHE */ # else /* FREEBSDV>=2005 */ # if FREEBSDV<2010 #define NCACHE_NXT nc_lru.tqe_next /* link in NCACHE */ # else /* FREEBSDV>=2010 */ #include #define NCACHE_NXT nc_hash.le_next /* link in NCACHE */ # endif /* FREEBSDV<2010 */ # endif /* FREEBSDV<2005 */ #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) */ #if FREEBSDV>=5000 #define VNODE_VFLAG v_iflag #define NCACHE_VROOT VV_ROOT #endif /* FREEBSDV>=5000 */ #endif /* defined(FREEBSD_LSOF_H) */