api.c
static char *tcmu_get_wwn(struct tcmu_device *dev)
{
	int fd;
	char path[256];
	char buf[256];
	char *ret_buf;
	int ret;

	snprintf(path, sizeof(path),
		 "/sys/kernel/config/target/core/%s/%s/wwn/vpd_unit_serial",
		 dev->tcm_hba_name, dev->tcm_dev_name);

	fd = open(path, O_RDONLY);
	if (fd == -1) {
		tcmu_err("Could not open configfs to read unit serial\n");
		return NULL;
	}

	ret = read(fd, buf, sizeof(buf));
	close(fd);
	if (ret == -1) {
		tcmu_err("Could not read configfs to read unit serial\n");
		return NULL;
	}

	/* Kill the trailing '\n' */
	buf[ret-1] = '\0';

	/* Skip to the good stuff */
	ret = asprintf(&ret_buf, "%s", &buf[28]);
	if (ret == -1) {
		tcmu_err("could not convert string to value\n");
		return NULL;
	}

	return ret_buf;
}
/*
 * Return a string that contains the device's WWN, or NULL.
 *
 * Callers must free the result with free().
 */
Return a string that contains the device's WWN, or NULL.
Callers must free the result with free().
Return a string that contains the device ' s WWN or NULL . Callers must free the result with free () .
static char *tcmu_get_wwn(struct tcmu_device *dev)
{
	int fd;
	char path[256];
	char buf[256];
	char *ret_buf;
	int ret;
	snprintf(path, sizeof(path),
		 "/sys/kernel/config/target/core/%s/%s/wwn/vpd_unit_serial",
		 dev->tcm_hba_name, dev->tcm_dev_name);
	fd = open(path, O_RDONLY);
	if (fd == -1) {
		tcmu_err("Could not open configfs to read unit serial\n");
		return NULL;
	}
	ret = read(fd, buf, sizeof(buf));
	close(fd);
	if (ret == -1) {
		tcmu_err("Could not read configfs to read unit serial\n");
		return NULL;
	}
	buf[ret-1] = '\0';
	ret = asprintf(&ret_buf, "%s", &buf[28]);
	if (ret == -1) {
		tcmu_err("could not convert string to value\n");
		return NULL;
	}
	return ret_buf;
}
static char * tcmu_get_wwn ( struct tcmu_device * dev ) { int fd ; char path [ 256 ] ; char buf [ 256 ] ; char * ret_buf ; int ret ; snprintf ( path , sizeof ( path ) , " " , dev -> tcm_hba_name , dev -> tcm_dev_name ) ; fd = open ( path , O_RDONLY ) ; if ( fd == -1 ) { tcmu_err ( " \n " ) ; return NULL ; } ret = read ( fd , buf , sizeof ( buf ) ) ; close ( fd ) ; if ( ret == -1 ) { tcmu_err ( " \n " ) ; return NULL ; } buf [ ret - 1 ] = ' \0 ' ; ret = asprintf ( & ret_buf , " " , & buf [ 28 ] ) ; if ( ret == -1 ) { tcmu_err ( " \n " ) ; return NULL ; } return ret_buf ; }
Return a string that contains the device's WWN, or NULL.
Return a string that contains the device ' s WWN or NULL .
/* Kill the trailing '\n' */ /* Skip to the good stuff */