Add function which allow to remove binding between function and configuration. This functions also remove binding from internal library structures wht means that after this operation all pointers to removed binding are invalid.
Signed-off-by: Krzysztof Opasiak <k.opas...@samsung.com> --- include/usbg/usbg.h | 10 ++++++++++ src/usbg.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h index bf5eafb..bda63a1 100644 --- a/include/usbg/usbg.h +++ b/include/usbg/usbg.h @@ -267,6 +267,16 @@ extern usbg_function *usbg_get_function(usbg_gadget *g, const char *name); */ extern usbg_config *usbg_get_config(usbg_gadget *g, const char *name); +/* USB gadget/config/function/binding removal */ + +/** + * @brief Remove binding between configuration and function + * @details This function frees also the memory allocated for binding + * @param b Binding to be removed + * @return 0 on success, usbg_error if error occurred + */ +extern int usbg_remove_binding(usbg_binding *b); + /* USB gadget allocation and configuration */ /** diff --git a/src/usbg.c b/src/usbg.c index 808e6c6..3a89e3a 100644 --- a/src/usbg.c +++ b/src/usbg.c @@ -143,6 +143,7 @@ static int usbg_translate_error(int error) break; case EACCES: case EROFS: + case EPERM: ret = USBG_ERROR_NO_ACCESS; break; case ENOENT: @@ -569,6 +570,25 @@ static usbg_binding *usbg_allocate_binding(char *path, char *name, return b; } +static int usbg_remove_file(char *path, char *name) +{ + int ret = USBG_SUCCESS; + int nmb; + char buf[PATH_MAX]; + + nmb = snprintf(buf, PATH_MAX, "%s/%s", path, name); + if (nmb < PATH_MAX) { + nmb = unlink(buf); + if (nmb != 0) + ret = usbg_translate_error(errno); + } else { + ret = USBG_ERROR_PATH_TOO_LONG; + } + + return ret; +} + + static int usbg_parse_function_net_attrs(usbg_function *f, usbg_function_attrs *f_attrs) { @@ -1101,6 +1121,25 @@ usbg_binding *usbg_get_link_binding(usbg_config *c, usbg_function *f) return NULL; } +int usbg_remove_binding(usbg_binding *b) +{ + int ret = USBG_SUCCESS; + usbg_config *c; + + if (!b) + return USBG_ERROR_INVALID_PARAM; + + c = b->parent; + + ret = usbg_remove_file(b->path, b->name); + if (ret == USBG_SUCCESS) { + TAILQ_REMOVE(&(c->bindings), b, bnode); + usbg_free_binding(b); + } + + return ret; +} + static int usbg_create_empty_gadget(usbg_state *s, char *name, usbg_gadget **g) { char gpath[PATH_MAX]; -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html