tizen 2.3.1 release
[external/lsof.git] / lib / prfp.c
1 /*
2  * prfp.c -- process_file() function for lsof library
3  */
4
5
6 /*
7  * Copyright 1997 Purdue Research Foundation, West Lafayette, Indiana
8  * 47907.  All rights reserved.
9  *
10  * Written by Victor A. Abell
11  *
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.
14  *
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:
18  *
19  * 1. Neither the authors nor Purdue University are responsible for any
20  *    consequences of the use of this software.
21  *
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.
25  *
26  * 3. Altered versions must be plainly marked as such, and must not be
27  *    misrepresented as being the original software.
28  *
29  * 4. This notice may not be removed or altered.
30  */
31
32
33 #include "../machine.h"
34
35 #if     defined(USE_LIB_PROCESS_FILE)
36
37 # if    !defined(lint)
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) */
42
43 #include "../lsof.h"
44
45
46 /*
47  * process_file() - process file
48  */
49
50 /*
51  * The caller may define:
52  *
53  *      FILEPTR as the name of the location to store a pointer
54  *                      to the current file struct -- e.g.,
55  *
56  *                      struct file *foobar;
57  *                      #define FILEPTR foobar
58  */
59
60 void
61 process_file(fp)
62         KA_T fp;                        /* kernel file structure address */
63 {
64         struct file f;
65         int flag;
66         char tbuf[32];
67
68 #if     defined(FILEPTR)
69 /*
70  * Save file structure address for process_node().
71  */
72         FILEPTR = &f;
73 #endif  /* defined(FILEPTR) */
74
75 /*
76  * Read file structure.
77  */
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));
81             enter_nm(Namech);
82             return;
83         }
84         Lf->off = (SZOFFTYPE)f.f_offset;
85         if (f.f_count) {
86
87         /*
88          * Construct access code.
89          */
90             if ((flag = (f.f_flag & (FREAD | FWRITE))) == FREAD)
91                 Lf->access = 'r';
92             else if (flag == FWRITE)
93                 Lf->access = 'w';
94             else if (flag == (FREAD | FWRITE))
95                 Lf->access = 'u';
96
97 #if     defined(HASFSTRUCT)
98         /*
99          * Save file structure values.
100          */
101
102 # if    !defined(HASNOFSCOUNT)
103             if (Fsv & FSV_CT) {
104                 Lf->fct = (long)f.f_count;
105                 Lf->fsv |= FSV_CT;
106             }
107 # endif /* !defined(HASNOFSCOUNT) */
108
109 # if    !defined(HASNOFSADDR)
110             if (Fsv & FSV_FA) {
111                 Lf->fsa = fp;
112                 Lf->fsv |= FSV_FA;
113             }
114 # endif /* !defined(HASNOFSADDR) */
115
116 # if    !defined(HASNOFSFLAGS)
117             if (Fsv & FSV_FG) {
118                 Lf->ffg = (long)f.f_flag;
119                 Lf->fsv |= FSV_FG;
120             }
121 # endif /* !defined(HASNOFSFLAGS) */
122
123 # if    !defined(HASNOFSNADDR)
124             if (Fsv & FSV_NI) {
125                 Lf->fna = (KA_T)f.f_data;
126                 Lf->fsv |= FSV_NI;
127             }
128 # endif /* !defined(HASNOFSNADDR) */
129 #endif  /* defined(HASFSTRUCT) */
130
131         /*
132          * Process structure by its type.
133          */
134             switch (f.f_type) {
135
136
137 #if     defined(DTYPE_PIPE)
138             case DTYPE_PIPE:
139 # if    defined(HASPIPEFN)
140                 if (!Selinet)
141                     HASPIPEFN((KA_T)f.f_data);
142 # endif /* defined(HASPIPEFN) */
143                 return;
144 #endif  /* defined(DTYPE_PIPE) */
145
146 #if     defined(DTYPE_GNODE)
147             case DTYPE_GNODE:
148 #endif  /* defined(DTYPE_GNODE) */
149
150 #if     defined(DTYPE_INODE)
151             case DTYPE_INODE:
152 #endif  /* defined(DTYPE_INODE) */
153
154 #if     defined(DTYPE_PORT)
155             case DTYPE_PORT:
156 #endif  /* defined(DTYPE_PORT) */
157
158 #if     defined(DTYPE_VNODE)
159             case DTYPE_VNODE:
160 #endif  /* defined(DTYPE_VNODE) */
161
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) */
167
168                 return;
169             case DTYPE_SOCKET:
170                 process_socket((KA_T)f.f_data);
171                 return;
172
173 #if     defined(HASKQUEUE)
174             case DTYPE_KQUEUE:
175                 process_kqueue((KA_T)f.f_data);
176                 return;
177 #endif  /* defined(HASKQUEUE) */
178
179 #if     defined(HASPSXSEM)
180             case DTYPE_PSXSEM:
181                 process_psxsem((KA_T)f.f_data);
182                 return;
183 #endif  /* defined(HASPSXSEM) */
184
185 #if     defined(HASPSXSHM)
186             case DTYPE_PSXSHM:
187                 process_psxshm((KA_T)f.f_data);
188                 return;
189 #endif  /* defined(HASPSXSHM) */
190
191 #if     defined(HASPRIVFILETYPE)
192             case PRIVFILETYPE:
193                 HASPRIVFILETYPE((KA_T)f.f_data);
194                 return;
195 #endif  /* defined(HASPRIVFILETYPE) */
196
197             default:
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));
203                     enter_nm(Namech);
204                     return;
205                 }
206             }
207         }
208         enter_nm("no more information");
209 }
210 #else   /* !defined(USE_LIB_PROCESS_FILE) */
211 char prfp_d1[] = "d"; char *prfp_d2 = prfp_d1;
212 #endif  /* defined(USE_LIB_PROCESS_FILE) */