From d66ace8121c200e4aede226857c613905277ecb8 Mon Sep 17 00:00:00 2001 From: Vineeth Vijayan Date: Sun, 11 Sep 2022 22:42:40 +0200 Subject: [PATCH] zdev: add functionality to read site-specific settings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modify the dev_get_setting_list function to get the site-specific attributes of the device. The new site_id parameter for this function must be less than SITE_FALLBACK to read the site-specific attributes. As SITE_FALLBACK setting is same as persistent setting, we do not need a separate read function for it. Reviewed-by: Peter Oberparleiter Signed-off-by: Vineeth Vijayan Signed-off-by: Jan Höppner --- zdev/include/device.h | 3 ++- zdev/src/device.c | 9 ++++++++- zdev/src/export.c | 4 ++-- zdev/src/firmware.c | 2 +- zdev/src/lszdev.c | 16 +++++++++++----- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/zdev/include/device.h b/zdev/include/device.h index 06aae41e..fd86afc0 100644 --- a/zdev/include/device.h +++ b/zdev/include/device.h @@ -112,7 +112,8 @@ struct device *device_list_find(struct device_list *, const char *, struct device *); void device_list_print(struct device_list *, int); struct setting_list *device_get_setting_list(struct device *dev, - config_t config); + config_t config, + int site_id); config_t device_get_config(struct device *dev); diff --git a/zdev/src/device.c b/zdev/src/device.c index e65dfef6..baf62f87 100644 --- a/zdev/src/device.c +++ b/zdev/src/device.c @@ -651,10 +651,16 @@ exit_code_t device_check_settings(struct device *dev, config_t config, } struct setting_list *device_get_setting_list(struct device *dev, - config_t config) + config_t config, + int site_id) { struct setting_list *settings = NULL; + if (site_id < SITE_FALLBACK) { + settings = dev->site_specific[site_id].settings; + goto out; + } + if (config == config_active) settings = dev->active.settings; else if (config == config_persistent) @@ -662,6 +668,7 @@ struct setting_list *device_get_setting_list(struct device *dev, else if (config == config_autoconf) settings = dev->autoconf.settings; +out: return settings; } diff --git a/zdev/src/export.c b/zdev/src/export.c index e538c932..a8aaccc1 100644 --- a/zdev/src/export.c +++ b/zdev/src/export.c @@ -154,7 +154,7 @@ static int count_exportable(struct device *dev, config_t config) struct setting *s; int count; - list = device_get_setting_list(dev, config); + list = device_get_setting_list(dev, config, SITE_FALLBACK); if (!list) return 0; count = 0; @@ -462,7 +462,7 @@ static exit_code_t handle_setting(const char *filename, int lineno, } else if (dev) { /* We're inside a device section. */ attribs = dev->subtype->dev_attribs; - list = device_get_setting_list(dev, config); + list = device_get_setting_list(dev, config, SITE_FALLBACK); } else return EXIT_OK; diff --git a/zdev/src/firmware.c b/zdev/src/firmware.c index ae2bb383..69b9fdbc 100644 --- a/zdev/src/firmware.c +++ b/zdev/src/firmware.c @@ -348,7 +348,7 @@ static void _add_setting(const char *filename, struct device *dev, struct attrib *a; struct setting_list *list; - list = device_get_setting_list(dev, config); + list = device_get_setting_list(dev, config, SITE_FALLBACK); a = attrib_find(dev->subtype->dev_attribs, key); if (!a) { warnx("%s: Applying unknown device setting %s=%s", filename, diff --git a/zdev/src/lszdev.c b/zdev/src/lszdev.c index d932c583..7f35eaa9 100644 --- a/zdev/src/lszdev.c +++ b/zdev/src/lszdev.c @@ -883,12 +883,13 @@ static char *dev_table_get_modules(struct device *dev) return str; } -static char *get_attr(struct device *dev, const char *name, config_t config) +static char *get_attr(struct device *dev, const char *name, config_t config, + int site_id) { struct setting_list *list; struct setting *s; - list = device_get_setting_list(dev, config); + list = device_get_setting_list(dev, config, site_id); if (!list) return NULL; s = setting_list_find(list, name); @@ -915,12 +916,17 @@ static char *dev_table_get_attr(struct device *dev, const char *attr, return NULL; name++; + /* To get the default settings on any configuration, make sure that + * the site_id is specified as SITE_FALLBACK. Any value of site_id + * less than SITE_FALLBACK will endup providing site-specific attribute + * settings. + */ if (SCOPE_ACTIVE(config)) - act = get_attr(dev, name, config_active); + act = get_attr(dev, name, config_active, SITE_FALLBACK); if (SCOPE_PERSISTENT(config)) - pers = get_attr(dev, name, config_persistent); + pers = get_attr(dev, name, config_persistent, SITE_FALLBACK); if (SCOPE_AUTOCONF(config)) - ac = get_attr(dev, name, config_autoconf); + ac = get_attr(dev, name, config_autoconf, SITE_FALLBACK); str = merge_str(act, pers, ac, config); free(act);