2 * lkud.c -- device lookup functions 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.
34 * lkud.c -- lookup device
36 * The caller may define:
38 * HASBLKDEV to activate block device lookup
42 #include "../machine.h"
44 #if defined(HASBLKDEV) || defined(USE_LIB_LKUPDEV)
47 static char copyright[] =
48 "@(#) Copyright 1997 Purdue Research Foundation.\nAll rights reserved.\n";
49 static char *rcsid = "$Id: lkud.c,v 1.7 2008/10/21 16:12:36 abe Exp $";
50 # endif /* !defined(lint) */
54 #else /* !defined(HASBLKDEV) && !defined(USE_LIB_LKUPDEV) */
55 char lkud_d1[] = "d"; char *lkud_d2 = lkud_d1;
56 #endif /* defined(HASBLKDEV) || defined(USE_LIB_LKUPDEV) */
60 #if defined(HASBLKDEV)
62 * lkupbdev() - look up a block device
66 lkupbdev(dev, rdev, i, r)
67 dev_t *dev; /* pointer to device number */
68 dev_t *rdev; /* pointer to raw device number */
69 int i; /* inode match status */
70 int r; /* if 1, rebuild the device cache with
71 * rereaddev() when no match is found
72 * and HASDCACHE is defined and
75 INODETYPE inode = (INODETYPE)0;
81 return((struct l_dev *)NULL);
88 * Search block device table for match.
91 # if defined(HASDCACHE)
95 # endif /* defined(HASDCACHE) */
100 mid = (low + hi) / 2;
102 if (*rdev < dp->rdev)
104 else if (*rdev > dp->rdev)
107 if ((i == 0) || (ty != 1) || (inode == dp->inode)) {
109 # if defined(HASDCACHE)
110 if (DCunsafe && !dp->v && !vfy_dev(dp))
112 # endif /* defined(HASDCACHE) */
116 if (inode < dp->inode)
123 # if defined(HASDCACHE)
128 # endif /* defined(HASDCACHE) */
130 return((struct l_dev *)NULL);
132 #endif /* defined(HASBLKDEV) */
135 #if defined(USE_LIB_LKUPDEV)
137 * lkupdev() - look up a character device
141 lkupdev(dev, rdev, i, r)
142 dev_t *dev; /* pointer to device number */
143 dev_t *rdev; /* pointer to raw device number */
144 int i; /* inode match status */
145 int r; /* if 1, rebuild the device cache with
146 * rereaddev() when no match is found
147 * and HASDCACHE is defined and
150 INODETYPE inode = (INODETYPE)0;
156 return((struct l_dev *)NULL);
163 * Search device table for match.
166 # if defined(HASDCACHE)
170 # endif /* defined(HASDCACHE) */
175 mid = (low + hi) / 2;
177 if (*rdev < dp->rdev)
179 else if (*rdev > dp->rdev)
182 if ((i == 0) || (ty != 1) || (inode == dp->inode)) {
184 # if defined(HASDCACHE)
185 if (DCunsafe && !dp->v && !vfy_dev(dp))
187 # endif /* defined(HASDCACHE) */
191 if (inode < dp->inode)
198 # if defined(HASDCACHE)
203 # endif /* defined(HASDCACHE) */
205 return((struct l_dev *)NULL);
207 #endif /* defined(USE_LIB_LKUPDEV) */