1/*
2 * node.c - common node reading functions for lsof
3 */
4
5
6/*
7 * Copyright 1994 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#ifndef lint
33static char copyright[] =
34"@(#) Copyright 1994 Purdue Research Foundation.\nAll rights reserved.\n";
35static char *rcsid = "$Id: node.c,v 1.5 2000/08/01 17:08:05 abe Exp $";
36#endif
37
38
39#include "lsof.h"
40
41
42/*
43 * print_kptr() - print kernel pointer
44 */
45
46char *
47print_kptr(kp, buf, bufl)
48	KA_T kp;			/* kernel pointer address */
49	char *buf;			/* optional destination buffer */
50	size_t bufl;			/* size of buf[] */
51{
52	static char dbuf[32];
53
54	(void) snpf(buf ? buf : dbuf,
55		    buf ? bufl : sizeof(dbuf),
56		    KA_T_FMT_X, kp);
57	return(buf ? buf : dbuf);
58}
59
60
61#if	defined(HASCDRNODE)
62/*
63 * readcdrnode() - read CD-ROM node
64 */
65
66int
67readcdrnode(ca, c)
68	KA_T ca;			/* cdrnode kernel address */
69	struct cdrnode *c;		/* cdrnode buffer */
70{
71	if (kread((KA_T)ca, (char *)c, sizeof(struct cdrnode))) {
72	    (void) snpf(Namech, Namechl, "can't read cdrnode at %s",
73		print_kptr(ca, (char *)NULL, 0));
74	    return(1);
75	}
76	return(0);
77}
78#endif	/* defined(HASCDRNODE) */
79
80
81#if	defined(HASFIFONODE)
82/*
83 * readfifonode() - read fifonode
84 */
85
86int
87readfifonode(fa, f)
88	KA_T fa;			/* fifonode kernel address */
89	struct fifonode *f;		/* fifonode buffer */
90{
91	if (kread((KA_T)fa, (char *)f, sizeof(struct fifonode))) {
92	    (void) snpf(Namech, Namechl, "can't read fifonode at %s",
93		print_kptr(fa, (char *)NULL, 0));
94	    return(1);
95	}
96	return(0);
97}
98#endif	/* defined(HASFIFONODE) */
99
100
101#if	defined(HASGNODE)
102/*
103 * readgnode() - read gnode
104 */
105
106int
107readgnode(ga, g)
108	KA_T ga;			/* gnode kernel address */
109	struct gnode *g;		/* gnode buffer */
110{
111	if (kread((KA_T)ga, (char *)g, sizeof(struct gnode))) {
112	    (void) snpf(Namech, Namechl, "can't read gnode at %s",
113		print_kptr(ga, (char *)NULL, 0));
114	    return(1);
115	}
116	return(0);
117}
118#endif	/* defined(HASGNODE) */
119
120
121#if	defined(HASHSNODE)
122/*
123 * readhsnode() - read High Sierra file system node
124 */
125
126int
127readhsnode(ha, h)
128	KA_T ha;			/* hsnode kernel address */
129	struct hsnode *h;		/* hsnode buffer */
130{
131	if (kread((KA_T)ha, (char *)h, sizeof(struct hsnode))) {
132	    (void) snpf(Namech, Namechl, "can't read hsnode at %s",
133		print_kptr(ha, (char *)NULL, 0));
134	    return(1);
135	}
136	return(0);
137}
138#endif	/* defined(HASHSNODE) */
139
140
141#if	defined(HASINODE)
142/*
143 * readinode() - read inode
144 */
145
146int
147readinode(ia, i)
148	KA_T ia;			/* inode kernel address */
149	struct inode *i;		/* inode buffer */
150{
151	if (kread((KA_T)ia, (char *)i, sizeof(struct inode))) {
152	    (void) snpf(Namech, Namechl, "can't read inode at %s",
153		print_kptr(ia, (char *)NULL, 0));
154	    return(1);
155	}
156	return(0);
157}
158#endif	/* defined(HASINODE) */
159
160
161#if	defined(HASPIPENODE)
162/*
163 * readpipenode() - read pipe node
164 */
165
166int
167readpipenode(pa, p)
168	KA_T pa;			/* pipe node kernel address */
169	struct pipenode *p;		/* pipe node buffer */
170{
171	if (kread((KA_T)pa, (char *)p, sizeof(struct pipenode))) {
172	    (void) snpf(Namech, Namechl, "can't read pipenode at %s",
173		print_kptr(pa, (char *)NULL, 0));
174	    return(1);
175	}
176	return(0);
177}
178#endif	/* defined(HASPIPENODE) */
179
180
181#if	defined(HASRNODE)
182/*
183 * readrnode() - read rnode
184 */
185
186int
187readrnode(ra, r)
188	KA_T ra;			/* rnode kernel space address */
189	struct rnode *r;		/* rnode buffer pointer */
190{
191	if (kread((KA_T)ra, (char *)r, sizeof(struct rnode))) {
192	    (void) snpf(Namech, Namechl, "can't read rnode at %s",
193		print_kptr(ra, (char *)NULL, 0));
194	    return(1);
195	}
196	return(0);
197}
198#endif	/* defined(HASRNODE) */
199
200
201#if	defined(HASSNODE)
202/*
203 * readsnode() - read snode
204 */
205
206int
207readsnode(sa, s)
208	KA_T sa;			/* snode kernel space address */
209	struct snode *s;		/* snode buffer pointer */
210{
211	if (kread((KA_T)sa, (char *)s, sizeof(struct snode))) {
212	    (void) snpf(Namech, Namechl, "can't read snode at %s",
213		print_kptr(sa, (char *)NULL, 0));
214	    return(1);
215	}
216	return(0);
217}
218#endif	/* defined(HASSNODE) */
219
220
221#if	defined(HASTMPNODE)
222/*
223 * readtnode() - read tmpnode
224 */
225
226int
227readtnode(ta, t)
228	KA_T ta;			/* tmpnode kernel space address */
229	struct tmpnode *t;		/* tmpnode buffer pointer */
230{
231	if (kread((KA_T)ta, (char *)t, sizeof(struct tmpnode))) {
232	    (void) snpf(Namech, Namechl, "can't read tmpnode at %s",
233		print_kptr(ta, (char *)NULL, 0));
234	    return(1);
235	}
236	return(0);
237}
238#endif	/* defined(HASTMPNODE) */
239
240
241#if	defined(HASVNODE)
242/*
243 * readvnode() - read vnode
244 */
245
246int
247readvnode(va, v)
248	KA_T va;			/* vnode kernel space address */
249	struct vnode *v;		/* vnode buffer pointer */
250{
251	if (kread((KA_T)va, (char *)v, sizeof(struct vnode))) {
252	    (void) snpf(Namech, Namechl, "can't read vnode at %s",
253		print_kptr(va, (char *)NULL, 0));
254	    return(1);
255	}
256	return(0);
257}
258#endif	/* defined(HASVNODE) */
259