1321936Shselasky/* 2321936Shselasky * Copyright (c) 2008 Voltaire Inc. All rights reserved. 3321936Shselasky * 4321936Shselasky * This software is available to you under a choice of one of two 5321936Shselasky * licenses. You may choose to be licensed under the terms of the GNU 6321936Shselasky * General Public License (GPL) Version 2, available from the file 7321936Shselasky * COPYING in the main directory of this source tree, or the 8321936Shselasky * OpenIB.org BSD license below: 9321936Shselasky * 10321936Shselasky * Redistribution and use in source and binary forms, with or 11321936Shselasky * without modification, are permitted provided that the following 12321936Shselasky * conditions are met: 13321936Shselasky * 14321936Shselasky * - Redistributions of source code must retain the above 15321936Shselasky * copyright notice, this list of conditions and the following 16321936Shselasky * disclaimer. 17321936Shselasky * 18321936Shselasky * - Redistributions in binary form must reproduce the above 19321936Shselasky * copyright notice, this list of conditions and the following 20321936Shselasky * disclaimer in the documentation and/or other materials 21321936Shselasky * provided with the distribution. 22321936Shselasky * 23321936Shselasky * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 24321936Shselasky * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25321936Shselasky * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 26321936Shselasky * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 27321936Shselasky * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 28321936Shselasky * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 29321936Shselasky * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30321936Shselasky * SOFTWARE. 31321936Shselasky * 32321936Shselasky */ 33321936Shselasky#ifndef _UMAD_SYSFS_H 34321936Shselasky#define _UMAD_SYSFS_H 35321936Shselasky 36321936Shselasky#include <stdint.h> 37337116Shselasky#include <string.h> 38337116Shselasky#include <stdlib.h> 39321936Shselasky#include <infiniband/types.h> 40321936Shselasky#include <infiniband/umad.h> 41321936Shselasky 42321936Shselaskystruct dirent; 43321936Shselasky 44321936Shselaskyextern int sys_read_string(const char *dir_name, const char *file_name, char *str, int len); 45321936Shselaskyextern int sys_read_guid(const char *dir_name, const char *file_name, __be64 * net_guid); 46321936Shselaskyextern int sys_read_gid(const char *dir_name, const char *file_name, 47321936Shselasky union umad_gid *gid); 48321936Shselaskyextern int sys_read_uint64(const char *dir_name, const char *file_name, uint64_t * u); 49321936Shselaskyextern int sys_read_uint(const char *dir_name, const char *file_name, unsigned *u); 50321936Shselaskyextern int sys_scandir(const char *dirname, struct dirent ***namelist, 51321936Shselasky int (*select)(const struct dirent *), 52321936Shselasky int (*compar)(const struct dirent **, const struct dirent **)); 53321936Shselasky 54337116Shselasky#ifdef __FreeBSD__ 55337116Shselaskystatic inline const char * 56337116Shselaskypath_to_sysctl(const char *path, int out_len, char *out) 57337116Shselasky{ 58337116Shselasky const char *retval = out; 59337116Shselasky 60337116Shselasky /* Validate that out is at least as long as the original path */ 61337116Shselasky if (out_len < (strlen(path) + 1)) 62337116Shselasky return NULL; 63337116Shselasky 64337116Shselasky while (*path == '/') 65337116Shselasky path++; 66337116Shselasky 67337116Shselasky while (*path) { 68337116Shselasky if (*path == '/') { 69337116Shselasky if (*(path + 1) == '/') 70337116Shselasky *out = '.'; 71337116Shselasky else 72337116Shselasky *out++ = '.'; 73337116Shselasky } else 74337116Shselasky *out++ = *path; 75337116Shselasky path++; 76337116Shselasky } 77337116Shselasky *out = 0; 78337116Shselasky return (retval); 79337116Shselasky} 80337116Shselasky 81337116Shselasky#define PATH_TO_SYS(str) \ 82337116Shselasky path_to_sysctl(str, strlen(str) + 1, alloca(strlen(str) + 1)) 83337116Shselasky#else 84337116Shselasky#define PATH_TO_SYS(str) str 85337116Shselasky#endif 86337116Shselasky 87321936Shselasky#endif /* _UMAD_SYSFS_H */ 88