Deleted Added
full compact
subr_hints.c (229272) subr_hints.c (240067)
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

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

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
27#include <sys/cdefs.h>
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

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

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
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/kern/subr_hints.c 229272 2012-01-02 12:12:10Z ed $");
28__FBSDID("$FreeBSD: head/sys/kern/subr_hints.c 240067 2012-09-03 08:52:05Z ray $");
29
30#include <sys/param.h>
31#include <sys/lock.h>
29
30#include <sys/param.h>
31#include <sys/lock.h>
32#include <sys/malloc.h>
32#include <sys/mutex.h>
33#include <sys/systm.h>
33#include <sys/mutex.h>
34#include <sys/systm.h>
35#include <sys/sysctl.h>
34#include <sys/bus.h>
35
36/*
37 * Access functions for device resources.
38 */
39
40static int checkmethod = 1;
41static int use_kenv;
42static char *hintp;
43
44/*
36#include <sys/bus.h>
37
38/*
39 * Access functions for device resources.
40 */
41
42static int checkmethod = 1;
43static int use_kenv;
44static char *hintp;
45
46/*
47 * Define kern.hintmode sysctl, which only accept value 2, that cause to
48 * switch from Static KENV mode to Dynamic KENV. So systems that have hints
49 * compiled into kernel will be able to see/modify KENV (and hints too).
50 */
51
52static int
53sysctl_hintmode(SYSCTL_HANDLER_ARGS)
54{
55 int error, i, from_kenv, value, eqidx;
56 const char *cp;
57 char *line, *eq;
58
59 from_kenv = 0;
60 cp = kern_envp;
61 value = hintmode;
62
63 /* Fetch candidate for new hintmode value */
64 error = sysctl_handle_int(oidp, &value, 0, req);
65 if (error || !req->newptr)
66 return (error);
67
68 if (value != 2)
69 /* Only accept swithing to hintmode 2 */
70 return (EINVAL);
71
72 /* Migrate from static to dynamic hints */
73 switch (hintmode) {
74 case 0:
75 if (dynamic_kenv)
76 /* Already here */
77 hintmode = value; /* XXX: Need we switch or not ? */
78 return (0);
79 from_kenv = 1;
80 cp = kern_envp;
81 break;
82 case 1:
83 cp = static_hints;
84 break;
85 case 2:
86 /* Nothing to do, hintmode already 2 */
87 return (0);
88 }
89
90 while (cp) {
91 i = strlen(cp);
92 if (i == 0)
93 break;
94 if (from_kenv) {
95 if (strncmp(cp, "hint.", 5) != 0)
96 /* kenv can have not only hints */
97 continue;
98 }
99 eq = strchr(cp, '=');
100 if (!eq)
101 /* Bad hint value */
102 continue;
103 eqidx = eq - cp;
104
105 line = malloc(i+1, M_TEMP, M_WAITOK);
106 strcpy(line, cp);
107 line[eqidx] = '\0';
108 setenv(line, line + eqidx + 1);
109 free(line, M_TEMP);
110 cp += i + 1;
111 }
112
113 hintmode = value;
114 use_kenv = 1;
115 return (0);
116}
117
118SYSCTL_PROC(_kern, OID_AUTO, hintmode, CTLTYPE_INT|CTLFLAG_RW,
119 &hintmode, 0, sysctl_hintmode, "I", "Get/set current hintmode");
120
121/*
45 * Evil wildcarding resource string lookup.
46 * This walks the supplied env string table and returns a match.
47 * The start point can be remembered for incremental searches.
48 */
49static int
50res_find(int *line, int *startln,
51 const char *name, int *unit, const char *resname, const char *value,
52 const char **ret_name, int *ret_namelen, int *ret_unit,

--- 330 unchanged lines hidden ---
122 * Evil wildcarding resource string lookup.
123 * This walks the supplied env string table and returns a match.
124 * The start point can be remembered for incremental searches.
125 */
126static int
127res_find(int *line, int *startln,
128 const char *name, int *unit, const char *resname, const char *value,
129 const char **ret_name, int *ret_namelen, int *ret_unit,

--- 330 unchanged lines hidden ---