Exemplo n.º 1
0
static int write_sysfs_str(char *path, enum cxl_sysfs_attr attr, char *str)
{
	char *attr_name;
	char *attr_path;
	int fd, count;

	if (OUT_OF_RANGE(attr))
		return -1;
	if (path == NULL)
		return -1;
	attr_name = sysfs_attr_name(attr);
	if (attr_name == NULL)
		return -1;
	attr_path = sysfs_get_path(path, attr_name);
	if (attr_path == NULL)
		return -1;
	fd = open(attr_path, O_WRONLY);
	free(attr_path);
	if (fd == -1)
		return -1;
	count = write(fd, str, strlen(str));
	close(fd);
	if (count == -1)
		return -1;
	return 0;
}
Exemplo n.º 2
0
static int read_sysfs(char *sysfs_path, enum cxl_sysfs_attr attr, long *majorp,
		      long *minorp)
{
	char *attr_name;
	char *attr_path;
	char *buf;
	int expected, ret;

	if (OUT_OF_RANGE(attr))
		return -1;
	attr_name = sysfs_attr_name(attr);
	if (attr_name == NULL)
		return -1;
	/*
	 * Hack:
	 *	For configuration record attributes, attr_name is a printf
	 *	format with one parameter, the configuration record number,
	 *	pointed to by minorp.
	 */
	switch (attr) {
	case CR_CLASS:
	case CR_DEVICE:
	case CR_VENDOR:
		if (asprintf(&buf, attr_name, *minorp) == -1)
			return -1;
		attr_path = sysfs_get_path(sysfs_path, buf);
		free(buf);
		break;
	default:
		attr_path = sysfs_get_path(sysfs_path, attr_name);
	}
	if (attr_path == NULL)
		return -1;
	if ((buf = read_sysfs_str(attr_path)) == NULL)
		return -1;
	expected = sysfs_entry[attr].expected_num;
	ret = scan_sysfs_str(attr, buf, majorp, minorp);
	free(buf);
	return (ret == expected) ? 0 : -1;
}
Exemplo n.º 3
0
static char *read_sysfs_str(char *path, enum cxl_sysfs_attr attr)
{
	char *attr_path;
	int fd, count;
	char buf[BUFLEN];

	if (path == NULL)
		return NULL;
	attr_path = sysfs_get_path(path, attr);
	if (attr_path == NULL)
		return NULL;
	fd = open(attr_path, O_RDONLY);
	free(attr_path);
	if (fd == -1)
		return NULL;
	count = read(fd, buf, BUFLEN);
	close(fd);
	if (count == -1)
		return NULL;
	buf[count - 1] = '\0';
	return strdup(buf);
}