1 /* $NetBSD: getdevmajor.c,v 1.6 2012/03/13 21:13:35 christos Exp $ */
4 * Copyright (c) 2004 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
35 #include <sys/cdefs.h>
36 #if defined(LIBC_SCCS) && !defined(lint)
37 __RCSID("$NetBSD: getdevmajor.c,v 1.6 2012/03/13 21:13:35 christos Exp $");
38 #endif /* LIBC_SCCS and not lint */
40 #include "namespace.h"
41 #include <sys/types.h>
43 #include <sys/param.h>
44 #include <sys/sysctl.h>
51 __weak_alias(getdevmajor
,_getdevmajor
)
55 * XXX temporary alias because getdevmajor() was renamed
56 * in -current for some time
58 dev_t
__getdevmajor50(const char *, mode_t
);
60 __getdevmajor50(const char *name
, mode_t type
)
63 return (dev_t
)getdevmajor(name
, type
);
67 getdevmajor(const char *name
, mode_t type
)
69 struct kinfo_drivers kd
[200], *kdp
= &kd
[0];
70 size_t i
, sz
= sizeof(kd
);
72 devmajor_t n
= NODEVMAJOR
;
74 if (type
!= S_IFCHR
&& type
!= S_IFBLK
) {
80 rc
= sysctlbyname("kern.drivers", kdp
, &sz
, NULL
, 0);
86 if ((kdp
= malloc(sz
)) == NULL
)
93 for (i
= 0; i
< sz
; i
++) {
94 if (strcmp(name
, kdp
[i
].d_name
) == 0) {