Deleted Added
full compact
subr_hints.c (83595) subr_hints.c (94936)
1/*-
2 * Copyright (c) 2000,2001 Peter Wemm <peter@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 2000,2001 Peter Wemm <peter@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/sys/kern/subr_hints.c 83595 2001-09-17 21:27:41Z peter $
26 * $FreeBSD: head/sys/kern/subr_hints.c 94936 2002-04-17 13:06:36Z mux $
27 */
28
29#include <sys/param.h>
27 */
28
29#include <sys/param.h>
30#include <sys/lock.h>
31#include <sys/sx.h>
30#include <sys/systm.h>
31#include <sys/bus.h>
32
33/*
34 * Access functions for device resources.
35 */
36
32#include <sys/systm.h>
33#include <sys/bus.h>
34
35/*
36 * Access functions for device resources.
37 */
38
39static int checkmethod = 1;
37static char *hintp;
38
39/*
40 * Evil wildcarding resource string lookup.
41 * This walks the supplied env string table and returns a match.
42 * The start point can be remembered for incremental searches.
43 */
44static int
45res_find(int *line, int *startln,
46 const char *name, int *unit, const char *resname, const char *value,
47 const char **ret_name, int *ret_namelen, int *ret_unit,
48 const char **ret_resname, int *ret_resnamelen, const char **ret_value)
49{
40static char *hintp;
41
42/*
43 * Evil wildcarding resource string lookup.
44 * This walks the supplied env string table and returns a match.
45 * The start point can be remembered for incremental searches.
46 */
47static int
48res_find(int *line, int *startln,
49 const char *name, int *unit, const char *resname, const char *value,
50 const char **ret_name, int *ret_namelen, int *ret_unit,
51 const char **ret_resname, int *ret_resnamelen, const char **ret_value)
52{
50 int n = 0, hit;
53 int n = 0, hit, use_kenv, i = 0;
51 char r_name[32];
52 int r_unit;
53 char r_resname[32];
54 char r_value[128];
55 const char *s, *cp;
56 char *p;
57
54 char r_name[32];
55 int r_unit;
56 char r_resname[32];
57 char r_value[128];
58 const char *s, *cp;
59 char *p;
60
58 if (hintp == NULL) {
61 use_kenv = 0;
62 if (checkmethod) {
59 switch (hintmode) {
60 case 0: /* config supplied nothing */
63 switch (hintmode) {
64 case 0: /* config supplied nothing */
61 hintp = kern_envp;
62 break;
63 case 1: /* static hints only */
64 hintp = static_hints;
65 break;
66 case 1: /* static hints only */
67 hintp = static_hints;
68 checkmethod = 0;
65 break;
66 case 2: /* fallback mode */
69 break;
70 case 2: /* fallback mode */
67 cp = kern_envp;
68 while (cp) {
69 if (strncmp(cp, "hint.", 5) == 0) {
70 cp = NULL;
71 hintp = kern_envp;
72 break;
71 if (dynamic_kenv) {
72 sx_slock(&kenv_lock);
73 cp = kenvp[0];
74 for (i = 0; cp != NULL; cp = kenvp[++i]) {
75 if (!strncmp(cp, "hint.", 5)) {
76 use_kenv = 1;
77 checkmethod = 0;
78 break;
79 }
73 }
80 }
74 while (*cp != '\0')
81 sx_sunlock(&kenv_lock);
82 } else {
83 cp = kern_envp;
84 while (cp) {
85 if (strncmp(cp, "hint.", 5) == 0) {
86 cp = NULL;
87 hintp = kern_envp;
88 break;
89 }
90 while (*cp != '\0')
91 cp++;
75 cp++;
92 cp++;
76 cp++;
77 if (*cp == '\0') {
78 cp = NULL;
79 hintp = static_hints;
80 break;
93 if (*cp == '\0') {
94 cp = NULL;
95 hintp = static_hints;
96 break;
97 }
81 }
82 }
83 break;
84 default:
85 break;
86 }
98 }
99 }
100 break;
101 default:
102 break;
103 }
87 if (hintp == NULL)
88 hintp = kern_envp;
104 if (hintp == NULL) {
105 if (dynamic_kenv) {
106 use_kenv = 1;
107 checkmethod = 0;
108 } else
109 hintp = kern_envp;
110 }
89 }
90
111 }
112
91 cp = hintp;
113 if (use_kenv) {
114 sx_slock(&kenv_lock);
115 i = 0;
116 cp = kenvp[0];
117 if (cp == NULL) {
118 sx_sunlock(&kenv_lock);
119 return (ENOENT);
120 }
121 } else {
122 cp = hintp;
123 }
92 while (cp) {
93 hit = 1;
94 (*line)++;
95 if (strncmp(cp, "hint.", 5) != 0)
96 hit = 0;
97 else
98 n = sscanf(cp, "hint.%32[^.].%d.%32[^=]=%128s",
99 r_name, &r_unit, r_resname, r_value);

--- 11 unchanged lines hidden (view full) ---

111 if (hit && unit && *unit != r_unit)
112 hit = 0;
113 if (hit && resname && strcmp(resname, r_resname) != 0)
114 hit = 0;
115 if (hit && value && strcmp(value, r_value) != 0)
116 hit = 0;
117 if (hit)
118 break;
124 while (cp) {
125 hit = 1;
126 (*line)++;
127 if (strncmp(cp, "hint.", 5) != 0)
128 hit = 0;
129 else
130 n = sscanf(cp, "hint.%32[^.].%d.%32[^=]=%128s",
131 r_name, &r_unit, r_resname, r_value);

--- 11 unchanged lines hidden (view full) ---

143 if (hit && unit && *unit != r_unit)
144 hit = 0;
145 if (hit && resname && strcmp(resname, r_resname) != 0)
146 hit = 0;
147 if (hit && value && strcmp(value, r_value) != 0)
148 hit = 0;
149 if (hit)
150 break;
151 if (use_kenv)
152 cp = kenvp[++i];
119 while (*cp != '\0')
120 cp++;
121 cp++;
122 if (*cp == '\0') {
123 cp = NULL;
124 break;
125 }
126 }
153 while (*cp != '\0')
154 cp++;
155 cp++;
156 if (*cp == '\0') {
157 cp = NULL;
158 break;
159 }
160 }
161 if (use_kenv)
162 sx_sunlock(&kenv_lock);
127 if (cp == NULL)
128 return ENOENT;
129
130 s = cp;
131 /* This is a bit of a hack, but at least is reentrant */
132 /* Note that it returns some !unterminated! strings. */
133 s = index(s, '.') + 1; /* start of device */
134 if (ret_name)

--- 193 unchanged lines hidden ---
163 if (cp == NULL)
164 return ENOENT;
165
166 s = cp;
167 /* This is a bit of a hack, but at least is reentrant */
168 /* Note that it returns some !unterminated! strings. */
169 s = index(s, '.') + 1; /* start of device */
170 if (ret_name)

--- 193 unchanged lines hidden ---