summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKrzysztof Opasiak <k.opasiak@samsung.com>2016-12-16 12:58:12 +0100
committerKrzysztof Opasiak <k.opasiak@samsung.com>2017-03-03 14:02:27 +0100
commit7b0ef8b934ac7f122a07491f1352608681c37d41 (patch)
tree576d94987dc35001f185677ddab0ade627f76491
parent6bdf0a3b93f2ad465cb8755b68ae1726152a5711 (diff)
downloadlibusbg-7b0ef8b934ac7f122a07491f1352608681c37d41.tar.gz
libusbg-7b0ef8b934ac7f122a07491f1352608681c37d41.tar.bz2
libusbg-7b0ef8b934ac7f122a07491f1352608681c37d41.zip
libusbgx: common: Add function for reading dev_t from ConfigFS
As some of kernel functions expose details about device node which is assigned to this instance in form: <major>:<minor> Let's add a convenient helper which will read those values form file and convert them to dev_t. Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
-rw-r--r--include/usbg/usbg_internal.h4
-rw-r--r--src/usbg_common.c20
2 files changed, 24 insertions, 0 deletions
diff --git a/include/usbg/usbg_internal.h b/include/usbg/usbg_internal.h
index 9ce8033..5eb20b6 100644
--- a/include/usbg/usbg_internal.h
+++ b/include/usbg/usbg_internal.h
@@ -17,6 +17,7 @@
#include <string.h>
#include <usbg/usbg.h>
#include <malloc.h>
+#include <sys/types.h>
#ifdef HAS_LIBCONFIG
#include <libconfig.h>
#endif
@@ -365,6 +366,9 @@ int usbg_get_ether_addr(const char *path, const char *name, const char *attr,
int usbg_set_ether_addr(const char *path, const char *name, const char *attr,
void *val);
+int usbg_get_dev(const char *path, const char *name, const char *attr,
+ void *val);
+
/*
* return:
* 0 - if not found
diff --git a/src/usbg_common.c b/src/usbg_common.c
index 907dbac..99bc99b 100644
--- a/src/usbg_common.c
+++ b/src/usbg_common.c
@@ -339,6 +339,26 @@ int usbg_set_ether_addr(const char *path, const char *name,
return usbg_write_string(path, name, attr, str_addr);
}
+int usbg_get_dev(const char *path, const char *name, const char *attr,
+ void *val)
+{
+ int major, minor;
+ char str_dev[USBG_MAX_STR_LENGTH];
+ int ret;
+
+ ret = usbg_read_string_limited(path, name, attr,
+ str_dev, sizeof(str_dev));
+ if (ret < 0)
+ return ret;
+
+ ret = sscanf(str_dev, "%d:%d", &major, &minor);
+ if (ret < 2)
+ return USBG_ERROR_INVALID_VALUE;
+
+ *(dev_t *)val = makedev(major, minor);
+ return 0;
+}
+
int usbg_get_config_node_int(config_setting_t *root,
const char *node_name, void *val)
{