35#include <sys/kernel.h>
36#include <sys/malloc.h>
38#include <sys/sysctl.h>
68 while (cp && *cp !=
'\0') {
76 line =
malloc(i + 1, M_TEMP, M_WAITOK);
78 line[eqidx] = line[i] =
'\0';
108 if (strncmp(cp,
"hint.", 5) == 0)
125res_find(
char **hintp_cookie,
int *line,
int *startln,
126 const char *
name,
int *unit,
const char *resname,
const char *
value,
127 const char **ret_name,
int *ret_namelen,
int *ret_unit,
128 const char **ret_resname,
int *ret_resnamelen,
const char **ret_value)
137 bool dyn_used =
false;
146 if (*hintp_cookie == NULL) {
156 for (i = 0; cp != NULL; cp =
kenvp[++i]) {
157 if (!strncmp(cp,
"hint.", 5)) {
200 hintp = static_hints;
212 *hintp_cookie = hintp;
214 hintp = *hintp_cookie;
233 namelen = strlen(
name);
237 if (strncmp(cp,
"hint.", 5) != 0)
239 if (
name && strncmp(cp + 5,
name, namelen) != 0)
241 n =
sscanf(cp + 5,
"%32[^.].%d.%32[^=]=%127s", r_name, &r_unit,
244 printf(
"CONFIG: invalid hint '%s'\n", cp);
249 if (startln && *startln >= 0 && *line < *startln)
251 if (
name && strcmp(
name, r_name) != 0)
253 if (unit && *unit != r_unit)
255 if (resname && strcmp(resname, r_resname) != 0)
284 s = strchr(s,
'.') + 1;
287 s = strchr(s,
'.') + 1;
288 if (ret_namelen && ret_name)
289 *ret_namelen = s - *ret_name - 1;
292 s = strchr(s,
'.') + 1;
295 s = strchr(s,
'=') + 1;
296 if (ret_resnamelen && ret_resname)
297 *ret_resnamelen = s - *ret_resname - 1;
301 *startln = *line + 1;
311 const char *
name,
int *unit,
const char *resname,
const char *
value,
312 const char **ret_name,
int *ret_namelen,
int *ret_unit,
313 const char **ret_resname,
int *ret_resnamelen,
const char **ret_value)
324 ret_name, ret_namelen, ret_unit, ret_resname, ret_resnamelen,
333 ret_name, ret_namelen, ret_unit, ret_resname, ret_resnamelen,
351 NULL, NULL, NULL, NULL, NULL, &str);
356 val = strtoul(str, &op, 0);
375 NULL, NULL, NULL, NULL, NULL, &str);
380 val = strtoul(str, &op, 0);
397 NULL, NULL, NULL, NULL, NULL, &str);
410 static char stringbuf[256];
411 static int offset = 0;
418 if ((offset + len + 1) > 255)
420 bcopy(s, &stringbuf[offset], len);
421 stringbuf[offset + len] =
'\0';
422 ret = &stringbuf[offset];
437 const char *resname,
const char *
value)
439 const char *found_name;
447 &found_name, &found_namelen, &found_unit, NULL, NULL, NULL);
465 const char *resname,
const char *
value)
473 NULL, NULL, &found_unit, NULL, NULL, NULL);
504 const char *retname, *retvalue;
510 &retname, NULL, NULL, NULL, NULL, &retvalue);
514 retname -= strlen(
"hint.");
515 len = retvalue - retname - 1;
516 if (len >
sizeof(varname) - 1)
517 return (ENAMETOOLONG);
518 memcpy(varname, retname, len);
int testenv(const char *name)
int kern_setenv(const char *name, const char *value)
int kern_unsetenv(const char *name)
void *() malloc(size_t size, struct malloc_type *mtp, int flags)
void free(void *addr, struct malloc_type *mtp)
static void static_hints_to_env(void *data __unused)
int resource_disabled(const char *name, int unit)
static bool hintenv_merged
static int resource_find(int *line, int *startln, const char *name, int *unit, const char *resname, const char *value, const char **ret_name, int *ret_namelen, int *ret_unit, const char **ret_resname, int *ret_resnamelen, const char **ret_value)
int resource_unset_value(const char *name, int unit, const char *resname)
static bool _res_checkenv(char *envp)
SYSINIT(hintenv, SI_SUB_KMEM+1, SI_ORDER_SECOND, static_hints_to_env, NULL)
int resource_long_value(const char *name, int unit, const char *resname, long *result)
int resource_find_dev(int *anchor, const char *name, int *unit, const char *resname, const char *value)
int resource_find_match(int *anchor, const char **name, int *unit, const char *resname, const char *value)
int resource_string_value(const char *name, int unit, const char *resname, const char **result)
int resource_int_value(const char *name, int unit, const char *resname, int *result)
static const char * resource_string_copy(const char *s, int len)
static int res_find(char **hintp_cookie, int *line, int *startln, const char *name, int *unit, const char *resname, const char *value, const char **ret_name, int *ret_namelen, int *ret_unit, const char **ret_resname, int *ret_resnamelen, const char **ret_value)
int printf(const char *fmt,...)
int sscanf(const char *ibuf, const char *fmt,...)