Blame lib/prfp.c

Packit Service 603f59
/*
Packit Service 603f59
 * prfp.c -- process_file() function for lsof library
Packit Service 603f59
 */
Packit Service 603f59
Packit Service 603f59
Packit Service 603f59
/*
Packit Service 603f59
 * Copyright 1997 Purdue Research Foundation, West Lafayette, Indiana
Packit Service 603f59
 * 47907.  All rights reserved.
Packit Service 603f59
 *
Packit Service 603f59
 * Written by Victor A. Abell
Packit Service 603f59
 *
Packit Service 603f59
 * This software is not subject to any license of the American Telephone
Packit Service 603f59
 * and Telegraph Company or the Regents of the University of California.
Packit Service 603f59
 *
Packit Service 603f59
 * Permission is granted to anyone to use this software for any purpose on
Packit Service 603f59
 * any computer system, and to alter it and redistribute it freely, subject
Packit Service 603f59
 * to the following restrictions:
Packit Service 603f59
 *
Packit Service 603f59
 * 1. Neither the authors nor Purdue University are responsible for any
Packit Service 603f59
 *    consequences of the use of this software.
Packit Service 603f59
 *
Packit Service 603f59
 * 2. The origin of this software must not be misrepresented, either by
Packit Service 603f59
 *    explicit claim or by omission.  Credit to the authors and Purdue
Packit Service 603f59
 *    University must appear in documentation and sources.
Packit Service 603f59
 *
Packit Service 603f59
 * 3. Altered versions must be plainly marked as such, and must not be
Packit Service 603f59
 *    misrepresented as being the original software.
Packit Service 603f59
 *
Packit Service 603f59
 * 4. This notice may not be removed or altered.
Packit Service 603f59
 */
Packit Service 603f59
Packit Service 603f59
Packit Service 603f59
#include "../machine.h"
Packit Service 603f59
Packit Service 603f59
#if	defined(USE_LIB_PROCESS_FILE)
Packit Service 603f59
Packit Service 603f59
# if	!defined(lint)
Packit Service 603f59
static char copyright[] =
Packit Service 603f59
"@(#) Copyright 1997 Purdue Research Foundation.\nAll rights reserved.\n";
Packit Service 603f59
static char *rcsid = "$Id: prfp.c,v 1.15 2018/02/14 14:21:08 abe Exp $";
Packit Service 603f59
# endif	/* !defined(lint) */
Packit Service 603f59
Packit Service 603f59
#include "../lsof.h"
Packit Service 603f59
Packit Service 603f59
Packit Service 603f59
/*
Packit Service 603f59
 * process_file() - process file
Packit Service 603f59
 */
Packit Service 603f59
Packit Service 603f59
/*
Packit Service 603f59
 * The caller may define:
Packit Service 603f59
 *
Packit Service 603f59
 *	FILEPTR	as the name of the location to store a pointer
Packit Service 603f59
 *			to the current file struct -- e.g.,
Packit Service 603f59
 *
Packit Service 603f59
 *			struct file *foobar;
Packit Service 603f59
 *			#define FILEPTR	foobar
Packit Service 603f59
 */
Packit Service 603f59
Packit Service 603f59
void
Packit Service 603f59
process_file(fp)
Packit Service 603f59
	KA_T fp;			/* kernel file structure address */
Packit Service 603f59
{
Packit Service 603f59
	struct file f;
Packit Service 603f59
	int flag;
Packit Service 603f59
	char tbuf[32];
Packit Service 603f59
Packit Service 603f59
#if	defined(FILEPTR)
Packit Service 603f59
/*
Packit Service 603f59
 * Save file structure address for process_node().
Packit Service 603f59
 */
Packit Service 603f59
	FILEPTR = &f;
Packit Service 603f59
#endif	/* defined(FILEPTR) */
Packit Service 603f59
Packit Service 603f59
/*
Packit Service 603f59
 * Read file structure.
Packit Service 603f59
 */
Packit Service 603f59
	if (kread((KA_T)fp, (char *)&f, sizeof(f))) {
Packit Service 603f59
	    (void) snpf(Namech, Namechl, "can't read file struct from %s",
Packit Service 603f59
		print_kptr(fp, (char *)NULL, 0));
Packit Service 603f59
	    enter_nm(Namech);
Packit Service 603f59
	    return;
Packit Service 603f59
	}
Packit Service 603f59
	Lf->off = (SZOFFTYPE)f.f_offset;
Packit Service 603f59
	if (f.f_count) {
Packit Service 603f59
Packit Service 603f59
	/*
Packit Service 603f59
	 * Construct access code.
Packit Service 603f59
	 */
Packit Service 603f59
	    if ((flag = (f.f_flag & (FREAD | FWRITE))) == FREAD)
Packit Service 603f59
		Lf->access = 'r';
Packit Service 603f59
	    else if (flag == FWRITE)
Packit Service 603f59
		Lf->access = 'w';
Packit Service 603f59
	    else if (flag == (FREAD | FWRITE))
Packit Service 603f59
		Lf->access = 'u';
Packit Service 603f59
Packit Service 603f59
#if	defined(HASFSTRUCT)
Packit Service 603f59
	/*
Packit Service 603f59
	 * Save file structure values.
Packit Service 603f59
	 */
Packit Service 603f59
Packit Service 603f59
# if	!defined(HASNOFSCOUNT)
Packit Service 603f59
	    if (Fsv & FSV_CT) {
Packit Service 603f59
		Lf->fct = (long)f.f_count;
Packit Service 603f59
		Lf->fsv |= FSV_CT;
Packit Service 603f59
	    }
Packit Service 603f59
# endif	/* !defined(HASNOFSCOUNT) */
Packit Service 603f59
Packit Service 603f59
# if	!defined(HASNOFSADDR)
Packit Service 603f59
	    if (Fsv & FSV_FA) {
Packit Service 603f59
		Lf->fsa = fp;
Packit Service 603f59
		Lf->fsv |= FSV_FA;
Packit Service 603f59
	    }
Packit Service 603f59
# endif	/* !defined(HASNOFSADDR) */
Packit Service 603f59
Packit Service 603f59
# if	!defined(HASNOFSFLAGS)
Packit Service 603f59
	    if (Fsv & FSV_FG) {
Packit Service 603f59
		Lf->ffg = (long)f.f_flag;
Packit Service 603f59
		Lf->fsv |= FSV_FG;
Packit Service 603f59
	    }
Packit Service 603f59
# endif	/* !defined(HASNOFSFLAGS) */
Packit Service 603f59
Packit Service 603f59
# if	!defined(HASNOFSNADDR)
Packit Service 603f59
	    if (Fsv & FSV_NI) {
Packit Service 603f59
		Lf->fna = (KA_T)f.f_data;
Packit Service 603f59
		Lf->fsv |= FSV_NI;
Packit Service 603f59
	    }
Packit Service 603f59
# endif	/* !defined(HASNOFSNADDR) */
Packit Service 603f59
#endif	/* defined(HASFSTRUCT) */
Packit Service 603f59
Packit Service 603f59
	/*
Packit Service 603f59
	 * Process structure by its type.
Packit Service 603f59
	 */
Packit Service 603f59
	    switch (f.f_type) {
Packit Service 603f59
Packit Service 603f59
Packit Service 603f59
#if	defined(DTYPE_PIPE)
Packit Service 603f59
	    case DTYPE_PIPE:
Packit Service 603f59
# if	defined(HASPIPEFN)
Packit Service 603f59
		if (!Selinet)
Packit Service 603f59
		    HASPIPEFN((KA_T)f.f_data);
Packit Service 603f59
# endif	/* defined(HASPIPEFN) */
Packit Service 603f59
		return;
Packit Service 603f59
#endif	/* defined(DTYPE_PIPE) */
Packit Service 603f59
Packit Service 603f59
#if	defined(DTYPE_PTS)
Packit Service 603f59
	    case DTYPE_PTS:
Packit Service 603f59
# if	defined(HASPTSFN)
Packit Service 603f59
		HASPTSFN((KA_T)f.f_data);
Packit Service 603f59
# endif	/* defined(HASPTSFN) */
Packit Service 603f59
		return;
Packit Service 603f59
#endif	/* defined(DTYPE_PIPE) */
Packit Service 603f59
Packit Service 603f59
#if	defined(DTYPE_FIFO)
Packit Service 603f59
	    case DTYPE_FIFO:
Packit Service 603f59
#endif	/* defined(DTYPE_FIFO) */
Packit Service 603f59
Packit Service 603f59
#if	defined(DTYPE_GNODE)
Packit Service 603f59
	    case DTYPE_GNODE:
Packit Service 603f59
#endif	/* defined(DTYPE_GNODE) */
Packit Service 603f59
Packit Service 603f59
#if	defined(DTYPE_INODE)
Packit Service 603f59
	    case DTYPE_INODE:
Packit Service 603f59
#endif	/* defined(DTYPE_INODE) */
Packit Service 603f59
Packit Service 603f59
#if	defined(DTYPE_PORT)
Packit Service 603f59
	    case DTYPE_PORT:
Packit Service 603f59
#endif	/* defined(DTYPE_PORT) */
Packit Service 603f59
Packit Service 603f59
#if	defined(DTYPE_VNODE)
Packit Service 603f59
	    case DTYPE_VNODE:
Packit Service 603f59
#endif	/* defined(DTYPE_VNODE) */
Packit Service 603f59
Packit Service 603f59
#if	defined(HASF_VNODE)
Packit Service 603f59
		process_node((KA_T)f.f_vnode);
Packit Service 603f59
#else	/* !defined(HASF_VNODE) */
Packit Service 603f59
		process_node((KA_T)f.f_data);
Packit Service 603f59
#endif	/* defined(HASF_VNODE) */
Packit Service 603f59
Packit Service 603f59
		return;
Packit Service 603f59
	    case DTYPE_SOCKET:
Packit Service 603f59
		process_socket((KA_T)f.f_data);
Packit Service 603f59
		return;
Packit Service 603f59
Packit Service 603f59
#if	defined(HASKQUEUE)
Packit Service 603f59
	    case DTYPE_KQUEUE:
Packit Service 603f59
		process_kqueue((KA_T)f.f_data);
Packit Service 603f59
		return;
Packit Service 603f59
#endif	/* defined(HASKQUEUE) */
Packit Service 603f59
Packit Service 603f59
#if	defined(HASPSXSEM)
Packit Service 603f59
	    case DTYPE_PSXSEM:
Packit Service 603f59
		process_psxsem((KA_T)f.f_data);
Packit Service 603f59
		return;
Packit Service 603f59
#endif	/* defined(HASPSXSEM) */
Packit Service 603f59
Packit Service 603f59
#if	defined(HASPSXSHM)
Packit Service 603f59
	    case DTYPE_PSXSHM:
Packit Service 603f59
		process_psxshm((KA_T)f.f_data);
Packit Service 603f59
		return;
Packit Service 603f59
#endif	/* defined(HASPSXSHM) */
Packit Service 603f59
Packit Service 603f59
#if	defined(HASPRIVFILETYPE)
Packit Service 603f59
	    case PRIVFILETYPE:
Packit Service 603f59
		HASPRIVFILETYPE((KA_T)f.f_data);
Packit Service 603f59
		return;
Packit Service 603f59
#endif	/* defined(HASPRIVFILETYPE) */
Packit Service 603f59
Packit Service 603f59
	    default:
Packit Service 603f59
Packit Service 603f59
#if	defined(X_BADFILEOPS)
Packit Service 603f59
		if (X_bfopsa && f.f_ops && (X_bfopsa == (KA_T)f.f_ops)) {
Packit Service 603f59
		    (void) snpf(Namech, Namechl,
Packit Service 603f59
			"no more information; ty=%d file may be closing",
Packit Service 603f59
			(int)f.f_type);
Packit Service 603f59
		    enter_nm(Namech);
Packit Service 603f59
		    return;
Packit Service 603f59
		}
Packit Service 603f59
#endif	/* defined(X_BADFILEOPS) */
Packit Service 603f59
Packit Service 603f59
		if (f.f_type || f.f_ops) {
Packit Service 603f59
		    (void) snpf(Namech, Namechl,
Packit Service 603f59
			"%s file struct, ty=%d, op=%s",
Packit Service 603f59
			print_kptr(fp, tbuf, sizeof(tbuf)), (int)f.f_type,
Packit Service 603f59
			print_kptr((KA_T)f.f_ops, (char *)NULL, 0));
Packit Service 603f59
		    enter_nm(Namech);
Packit Service 603f59
		    return;
Packit Service 603f59
		}
Packit Service 603f59
	    }
Packit Service 603f59
	}
Packit Service 603f59
	enter_nm("no more information");
Packit Service 603f59
}
Packit Service 603f59
#else	/* !defined(USE_LIB_PROCESS_FILE) */
Packit Service 603f59
char prfp_d1[] = "d"; char *prfp_d2 = prfp_d1;
Packit Service 603f59
#endif	/* defined(USE_LIB_PROCESS_FILE) */