Exemple #1
0
int sys_read_uint(char *dir_name, char *file_name, unsigned *u)
{
	char buf[32];
	int r;

	if ((r = sys_read_string(dir_name, file_name, buf, sizeof(buf))) < 0)
		return r;

	*u = strtoul(buf, 0, 0);

	return 0;
}
Exemple #2
0
int sys_read_uint64(const char *dir_name, const char *file_name, uint64_t * u)
{
	char buf[32];
	int r;

	if ((r = sys_read_string(dir_name, file_name, buf, sizeof(buf))) < 0)
		return r;

	*u = strtoull(buf, NULL, 0);

	return 0;
}
Exemple #3
0
int sys_read_gid(char *dir_name, char *file_name, uint8_t * gid)
{
	char buf[64], *str, *s;
	uint16_t *ugid = (uint16_t *) gid;
	int r, i;

	if ((r = sys_read_string(dir_name, file_name, buf, sizeof(buf))) < 0)
		return r;

	for (s = buf, i = 0; i < 8; i++) {
		if (!(str = strsep(&s, ": \t\n")))
			return -EINVAL;
		ugid[i] = htons(strtoul(str, 0, 16) & 0xffff);
	}

	return 0;
}
Exemple #4
0
int sys_read_gid(const char *dir_name, const char *file_name,
		 union umad_gid *gid)
{
	char buf[64], *str, *s;
	__be16 *ugid = (__be16 *) gid;
	int r, i;

	if ((r = sys_read_string(dir_name, file_name, buf, sizeof(buf))) < 0)
		return r;

	for (s = buf, i = 0; i < 8; i++) {
		if (!(str = strsep(&s, ": \t\n")))
			return -EINVAL;
		ugid[i] = htobe16(strtoul(str, NULL, 16) & 0xffff);
	}

	return 0;
}
Exemple #5
0
int sys_read_guid(char *dir_name, char *file_name, uint64_t * net_guid)
{
	char buf[32], *str, *s;
	uint64_t guid;
	int r, i;

	if ((r = sys_read_string(dir_name, file_name, buf, sizeof(buf))) < 0)
		return r;

	guid = 0;

	for (s = buf, i = 0; i < 4; i++) {
		if (!(str = strsep(&s, ": \t\n")))
			return -EINVAL;
		guid = (guid << 16) | (strtoul(str, 0, 16) & 0xffff);
	}

	*net_guid = htonll(guid);

	return 0;
}
Exemple #6
0
static int is_fdr10(umad_port_t *port)
{
    char port_dir[256];
    char rate[32];
    int len, fdr10 = 0;
    char *p;

    len = snprintf(port_dir, sizeof(port_dir), "%s/%s/%s/%d",
                   SYS_INFINIBAND, port->ca_name, SYS_CA_PORTS_DIR,
                   port->portnum);
    if (len < 0 || len > sizeof(port_dir))
        goto done;

    if (sys_read_string(port_dir, SYS_PORT_RATE, rate, sizeof(rate)) == 0) {
        if ((p = strchr(rate, ')'))) {
            if (!strncasecmp(p - 5, "fdr10", 5))
                fdr10 = 1;
        }
    }

done:
    return fdr10;
}