summaryrefslogtreecommitdiff
path: root/libopeniscsiusr/sysfs.h
blob: e285537655d78715eee979f1b0bab9592f714b7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
 * Copyright (C) 2017 Red Hat, Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Author: Gris Ge <fge@redhat.com>
 */
#ifndef __ISCSI_USR_SYSFS_H__
#define __ISCSI_USR_SYSFS_H__

#include <stdint.h>
#include <stdbool.h>

#include "libopeniscsiusr/libopeniscsiusr_common.h"

#define _ISCSI_SYS_SESSION_DIR		"/sys/class/iscsi_session"
#define _ISCSI_SYS_CONNECTION_DIR	"/sys/class/iscsi_connection"
#define _ISCSI_SYS_HOST_DIR		"/sys/class/iscsi_host"
#define _ISCSI_SYS_IFACE_DIR		"/sys/class/iscsi_iface"
#define _ISCSI_SYS_TRANSPORT_DIR	"/sys/class/iscsi_transport"
#define _SCSI_SYS_HOST_DIR		"/sys/class/scsi_host"

/*
 * When default_value == NULL, treat no such file as LIB_BUG.
 */
__DLL_LOCAL int _sysfs_prop_get_str(struct iscsi_context *ctx,
				    const char *dir_path, const char *prop_name,
				    char *buff, size_t buff_size,
				    const char *default_value);

int _sysfs_prop_get_u8(struct iscsi_context *ctx, const char *dir_path,
		       const char *prop_name, uint8_t *val,
		       uint8_t default_value, bool ignore_error);

int _sysfs_prop_get_u16(struct iscsi_context *ctx, const char *dir_path,
			const char *prop_name, uint16_t *val,
			uint16_t default_value, bool ignore_error);

/*
 * When default_value == UINT32_MAX, treat no such file as LIB_BUG.
 */
__DLL_LOCAL int _sysfs_prop_get_u32(struct iscsi_context *ctx,
				    const char *dir_path, const char *prop_name,
				    uint32_t *val, uint32_t default_value,
				    bool ignore_error);

/*
 * When default_value == INT32_MAX, treat no such file as LIB_BUG.
 */
__DLL_LOCAL int _sysfs_prop_get_i32(struct iscsi_context *ctx,
				    const char *dir_path, const char *prop_name,
				    int32_t *val, int32_t default_value,
				    bool ignore_error);

__DLL_LOCAL int _iscsi_host_id_of_session(struct iscsi_context *ctx,
					  uint32_t sid, uint32_t *host_id);

/*
 * iface_kern_id should be char[PATH_MAX]
 */
__DLL_LOCAL int _iscsi_iface_kern_id_of_host_id(struct iscsi_context *ctx,
						uint32_t host_id,
						char *iface_kern_id);

/*
 * The memory of (uint32_t *sids) should be freed by free().
 */
__DLL_LOCAL int _iscsi_sids_get(struct iscsi_context *ctx,
				uint32_t **sids, uint32_t *sid_count);

/*
 * The memory of (uint32_t *hids) should be freed by free().
 */
__DLL_LOCAL int _iscsi_hids_get(struct iscsi_context *ctx, uint32_t **hids,
				uint32_t *hid_count);

__DLL_LOCAL bool _iscsi_transport_is_loaded(const char *transport_name);

#endif /* End of __ISCSI_USR_SYSFS_H__ */