1
/* -*- mode: c; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ex: set tabstop=2 softtabstop=2 shiftwidth=2 expandtab: */
5
* Intel(R) Enclosure LED Utilities
6
* Copyright (C) 2009, Intel Corporation.
8
* This program is free software; you can redistribute it and/or modify it
9
* under the terms and conditions of the GNU General Public License,
10
* version 2, as published by the Free Software Foundation.
12
* This program is distributed in the hope it will be useful, but WITHOUT
13
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17
* You should have received a copy of the GNU General Public License along with
18
* this program; if not, write to the Free Software Foundation, Inc.,
19
* 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
43
static unsigned char _get_state(const char *path)
46
unsigned char result = SLAVE_STATE_UNKNOWN;
48
s = p = get_text(path, "state");
55
if (strcmp(s, "spare") == 0) {
56
result |= SLAVE_STATE_SPARE;
57
} else if (strcmp(s, "in_sync") == 0) {
58
result |= SLAVE_STATE_IN_SYNC;
59
} else if (strcmp(s, "faulty") == 0) {
60
result |= SLAVE_STATE_FAULTY;
61
} else if (strcmp(s, "write_mostly") == 0) {
62
result |= SLAVE_STATE_WRITE_MOSTLY;
63
} else if (strcmp(s, "blocked") == 0) {
64
result |= SLAVE_STATE_BLOCKED;
75
static unsigned int _get_errors(const char *path)
77
return get_int(path, 0, "errors");
82
static unsigned int _get_slot(const char *path)
84
unsigned int result = -1;
86
char *p = get_text(path, "slot");
88
if (strcmp(p, "none") != 0) {
98
static int _compare(struct block_device *device, const char *path)
100
return (strcmp(device->sysfs_path, path) == 0);
105
static struct block_device *_get_block(const char *path, void *block_list)
109
struct block_device *device = NULL;
111
str_cpy(temp, path, PATH_MAX);
112
str_cat(temp, "/block", PATH_MAX);
114
if (realpath(temp, link)) {
115
device = list_first_that(block_list, _compare, link);
122
struct slave_device * slave_device_init(const char *path, void *block_list)
124
struct slave_device *device = NULL;
125
struct block_device *block;
127
block = _get_block(path, block_list);
129
device = malloc(sizeof(struct slave_device));
132
device->state = _get_state(path);
133
device->slot = _get_slot(path);
134
device->errors = _get_errors(path);
135
device->block = block;
143
void slave_device_fini(struct slave_device *device)
146
/* Function reserved for future improvements. */