#define USBG_MAX_NAME_LENGTH 40
/* Dev name for ffs is a part of function name, we subtracs 4 char for "ffs." */
#define USBG_MAX_DEV_LENGTH (USBG_MAX_NAME_LENGTH - 4)
+/* ConfigFS just like SysFS uses page size as max size of file content */
+#define USBG_MAX_FILE_SIZE 4096
/**
* @brief Additional option for usbg_rm_* functions.
typedef struct {
struct ether_addr dev_addr;
struct ether_addr host_addr;
- char ifname[USBG_MAX_STR_LENGTH];
+ char *ifname;
int qmult;
} usbg_f_net_attrs;
return ret;
}
+static int usbg_read_string_alloc(const char *path, const char *name,
+ const char *file, char **dest)
+{
+ char buf[USBG_MAX_FILE_SIZE];
+ char *new_buf = NULL;
+ int ret = USBG_SUCCESS;
+
+ ret = usbg_read_string(path, name, file, buf);
+ if (ret != USBG_SUCCESS)
+ goto out;
+
+ new_buf = strdup(buf);
+ if (!new_buf) {
+ ret = USBG_ERROR_NO_MEM;
+ goto out;
+ }
+
+ *dest = new_buf;
+out:
+ return ret;
+}
+
static int usbg_write_buf(const char *path, const char *name, const char *file,
const char *buf)
{
goto out;
}
- ret = usbg_read_string(f->path, f->name, "ifname", f_net_attrs->ifname);
+ ret = usbg_read_dec(f->path, f->name, "qmult", &(f_net_attrs->qmult));
if (ret != USBG_SUCCESS)
goto out;
- ret = usbg_read_dec(f->path, f->name, "qmult", &(f_net_attrs->qmult));
-
+ ret = usbg_read_string_alloc(f->path, f->name, "ifname",
+ &(f_net_attrs->ifname));
out:
return ret;
}
break;
case USBG_F_ATTRS_NET:
+ free(f_attrs->attrs.net.ifname);
+ f_attrs->attrs.net.ifname = NULL;
break;
case USBG_F_ATTRS_PHONET:
char *addr;
/* ifname is read only so we accept only empty string for this param */
- if (attrs->ifname[0]) {
+ if (attrs->ifname && attrs->ifname[0]) {
ret = USBG_ERROR_INVALID_PARAM;
goto out;
}