2 * Copyright (c) 2004, 2005 Christophe Varoqui
3 * Copyright (c) 2005 Benjamin Marzinski, Redhat
4 * Copyright (c) 2005 Edward Goggin, EMC
17 #include "blacklist.h"
21 #include "../libcheckers/checkers.h"
24 find_hwe (vector hwtable, char * vendor, char * product)
27 struct hwentry *hwe, *ret = NULL;
30 vector_foreach_slot (hwtable, hwe, i) {
31 if (regcomp(&vre, hwe->vendor, REG_EXTENDED|REG_NOSUB))
33 if (regcomp(&pre, hwe->product, REG_EXTENDED|REG_NOSUB)) {
37 if (!regexec(&vre, vendor, 0, NULL, 0) &&
38 !regexec(&pre, product, 0, NULL, 0))
50 extern struct mpentry *
51 find_mpe (char * wwid)
59 vector_foreach_slot (conf->mptable, mpe, i)
60 if (mpe->wwid && !strcmp(mpe->wwid, wwid))
67 get_mpe_wwid (char * alias)
75 vector_foreach_slot (conf->mptable, mpe, i)
76 if (mpe->alias && strcmp(mpe->alias, alias) == 0)
83 free_hwe (struct hwentry * hwe)
107 FREE(hwe->hwhandler);
113 free_hwtable (vector hwtable)
116 struct hwentry * hwe;
121 vector_foreach_slot (hwtable, hwe, i)
124 vector_free(hwtable);
128 free_mpe (struct mpentry * mpe)
149 free_mptable (vector mptable)
152 struct mpentry * mpe;
157 vector_foreach_slot (mptable, mpe, i)
160 vector_free(mptable);
166 struct mpentry * mpe = (struct mpentry *)
167 MALLOC(sizeof(struct mpentry));
172 static struct hwentry *
175 struct hwentry * hwe = (struct hwentry *)
176 MALLOC(sizeof(struct hwentry));
182 set_param_str(char * str)
195 dst = (char *)MALLOC(len + 1);
205 dup_hwe (vector hwtable, char * vendor, char * product)
207 struct hwentry * hwe = find_hwe(hwtable, vendor, product);
216 store_hwe (vector hwtable, char * vendor, char * product, int pgp,
219 struct hwentry * hwe;
221 if (dup_hwe(hwtable, vendor, product))
229 hwe->vendor = set_param_str(vendor);
234 hwe->product = set_param_str(product);
243 hwe->getuid = set_param_str(getuid);
245 hwe->getuid = set_default(DEFAULT_GETUID);
250 if (!vector_alloc_slot(hwtable))
253 vector_set_slot(hwtable, hwe);
261 store_hwe_ext (vector hwtable, char * vendor, char * product, int pgp,
262 char * getuid, char * getprio, char * hwhandler,
263 char * features, char * checker, int pgfailback)
265 struct hwentry * hwe;
267 if (dup_hwe(hwtable, vendor, product))
275 hwe->vendor = set_param_str(vendor);
280 hwe->product = set_param_str(product);
289 hwe->getuid = set_param_str(getuid);
291 hwe->getuid = set_default(DEFAULT_GETUID);
297 hwe->getprio = set_param_str(getprio);
302 hwe->hwhandler = set_param_str(hwhandler);
304 hwe->hwhandler = set_default(DEFAULT_HWHANDLER);
310 hwe->features = set_param_str(features);
312 hwe->features = set_default(DEFAULT_FEATURES);
318 hwe->checker_index = get_checker_id(checker);
320 hwe->checker_index = get_checker_id(DEFAULT_CHECKER);
322 hwe->pgfailback = pgfailback;
324 if (!vector_alloc_slot(hwtable))
327 vector_set_slot(hwtable, hwe);
337 return (struct config *)MALLOC(sizeof(struct config));
341 free_config (struct config * conf)
350 FREE(conf->udev_dir);
353 FREE(conf->selector);
355 if (conf->default_getuid)
356 FREE(conf->default_getuid);
358 if (conf->default_getprio)
359 FREE(conf->default_getprio);
362 FREE(conf->features);
364 if (conf->default_hwhandler)
365 FREE(conf->default_hwhandler);
367 free_blacklist(conf->blist);
368 free_mptable(conf->mptable);
369 free_hwtable(conf->hwtable);
375 load_config (char * file)
378 conf = alloc_config();
386 if (!conf->verbosity)
389 conf->dev_type = DEV_NONE;
391 conf->bindings_file = DEFAULT_BINDINGS_FILE;
394 * read the config file
396 if (filepresent(file)) {
397 if (init_data(file, init_keywords)) {
398 condlog(0, "error parsing config file");
404 * fill the voids left in the config file
406 if (conf->hwtable == NULL) {
407 conf->hwtable = vector_alloc();
413 if (setup_default_hwtable(conf->hwtable))
416 if (conf->blist == NULL) {
417 conf->blist = vector_alloc();
422 if (setup_default_blist(conf->blist))
425 if (conf->mptable == NULL) {
426 conf->mptable = vector_alloc();
431 if (conf->selector == NULL)
432 conf->selector = set_default(DEFAULT_SELECTOR);
434 if (conf->udev_dir == NULL)
435 conf->udev_dir = set_default(DEFAULT_UDEVDIR);
437 if (conf->default_getuid == NULL)
438 conf->default_getuid = set_default(DEFAULT_GETUID);
440 if (conf->features == NULL)
441 conf->features = set_default(DEFAULT_FEATURES);
443 if (conf->default_hwhandler == NULL)
444 conf->default_hwhandler = set_default(DEFAULT_HWHANDLER);
446 if (!conf->selector || !conf->udev_dir ||
447 !conf->default_getuid || !conf->features ||
448 !conf->default_hwhandler)
451 if (!conf->default_checker_index)
452 conf->default_checker_index = READSECTOR0;