2 * prfp.c -- process_file() function for lsof library
7 * Copyright 1997 Purdue Research Foundation, West Lafayette, Indiana
8 * 47907. All rights reserved.
10 * Written by Victor A. Abell
12 * This software is not subject to any license of the American Telephone
13 * and Telegraph Company or the Regents of the University of California.
15 * Permission is granted to anyone to use this software for any purpose on
16 * any computer system, and to alter it and redistribute it freely, subject
17 * to the following restrictions:
19 * 1. Neither the authors nor Purdue University are responsible for any
20 * consequences of the use of this software.
22 * 2. The origin of this software must not be misrepresented, either by
23 * explicit claim or by omission. Credit to the authors and Purdue
24 * University must appear in documentation and sources.
26 * 3. Altered versions must be plainly marked as such, and must not be
27 * misrepresented as being the original software.
29 * 4. This notice may not be removed or altered.
33 #include "../machine.h"
35 #if defined(USE_LIB_PROCESS_FILE)
38 static char copyright[] =
39 "@(#) Copyright 1997 Purdue Research Foundation.\nAll rights reserved.\n";
40 static char *rcsid = "$Id: prfp.c,v 1.14 2008/10/21 16:12:36 abe Exp $";
41 # endif /* !defined(lint) */
47 * process_file() - process file
51 * The caller may define:
53 * FILEPTR as the name of the location to store a pointer
54 * to the current file struct -- e.g.,
56 * struct file *foobar;
57 * #define FILEPTR foobar
62 KA_T fp; /* kernel file structure address */
70 * Save file structure address for process_node().
73 #endif /* defined(FILEPTR) */
76 * Read file structure.
78 if (kread((KA_T)fp, (char *)&f, sizeof(f))) {
79 (void) snpf(Namech, Namechl, "can't read file struct from %s",
80 print_kptr(fp, (char *)NULL, 0));
84 Lf->off = (SZOFFTYPE)f.f_offset;
88 * Construct access code.
90 if ((flag = (f.f_flag & (FREAD | FWRITE))) == FREAD)
92 else if (flag == FWRITE)
94 else if (flag == (FREAD | FWRITE))
97 #if defined(HASFSTRUCT)
99 * Save file structure values.
102 # if !defined(HASNOFSCOUNT)
104 Lf->fct = (long)f.f_count;
107 # endif /* !defined(HASNOFSCOUNT) */
109 # if !defined(HASNOFSADDR)
114 # endif /* !defined(HASNOFSADDR) */
116 # if !defined(HASNOFSFLAGS)
118 Lf->ffg = (long)f.f_flag;
121 # endif /* !defined(HASNOFSFLAGS) */
123 # if !defined(HASNOFSNADDR)
125 Lf->fna = (KA_T)f.f_data;
128 # endif /* !defined(HASNOFSNADDR) */
129 #endif /* defined(HASFSTRUCT) */
132 * Process structure by its type.
137 #if defined(DTYPE_PIPE)
139 # if defined(HASPIPEFN)
141 HASPIPEFN((KA_T)f.f_data);
142 # endif /* defined(HASPIPEFN) */
144 #endif /* defined(DTYPE_PIPE) */
146 #if defined(DTYPE_GNODE)
148 #endif /* defined(DTYPE_GNODE) */
150 #if defined(DTYPE_INODE)
152 #endif /* defined(DTYPE_INODE) */
154 #if defined(DTYPE_PORT)
156 #endif /* defined(DTYPE_PORT) */
158 #if defined(DTYPE_VNODE)
160 #endif /* defined(DTYPE_VNODE) */
162 #if defined(HASF_VNODE)
163 process_node((KA_T)f.f_vnode);
164 #else /* !defined(HASF_VNODE) */
165 process_node((KA_T)f.f_data);
166 #endif /* defined(HASF_VNODE) */
170 process_socket((KA_T)f.f_data);
173 #if defined(HASKQUEUE)
175 process_kqueue((KA_T)f.f_data);
177 #endif /* defined(HASKQUEUE) */
179 #if defined(HASPSXSEM)
181 process_psxsem((KA_T)f.f_data);
183 #endif /* defined(HASPSXSEM) */
185 #if defined(HASPSXSHM)
187 process_psxshm((KA_T)f.f_data);
189 #endif /* defined(HASPSXSHM) */
191 #if defined(HASPRIVFILETYPE)
193 HASPRIVFILETYPE((KA_T)f.f_data);
195 #endif /* defined(HASPRIVFILETYPE) */
198 if (f.f_type || f.f_ops) {
199 (void) snpf(Namech, Namechl,
200 "%s file struct, ty=%#x, op=%s",
201 print_kptr(fp, tbuf, sizeof(tbuf)), (int)f.f_type,
202 print_kptr((KA_T)f.f_ops, (char *)NULL, 0));
208 enter_nm("no more information");
210 #else /* !defined(USE_LIB_PROCESS_FILE) */
211 char prfp_d1[] = "d"; char *prfp_d2 = prfp_d1;
212 #endif /* defined(USE_LIB_PROCESS_FILE) */