2 * Intel MIC Platform Software Stack (MPSS)
4 * Copyright(c) 2013 Intel Corporation.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License, version 2, as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * The full GNU General Public License is included in this distribution in
16 * the file called "COPYING".
18 * Intel MIC User Space Tools.
23 #define PAGE_SIZE 4096
26 readsysfs(char *dir, char *entry)
28 char filename[PATH_MAX];
29 char value[PAGE_SIZE];
35 snprintf(filename, PATH_MAX, "%s/%s", MICSYSFSDIR, entry);
37 snprintf(filename, PATH_MAX,
38 "%s/%s/%s", MICSYSFSDIR, dir, entry);
40 fd = open(filename, O_RDONLY);
42 mpsslog("Failed to open sysfs entry '%s': %s\n",
43 filename, strerror(errno));
47 len = read(fd, value, sizeof(value));
49 mpsslog("Failed to read sysfs entry '%s': %s\n",
50 filename, strerror(errno));
56 value[len - 1] = '\0';
58 string = malloc(strlen(value) + 1);
60 strcpy(string, value);
68 setsysfs(char *dir, char *entry, char *value)
70 char filename[PATH_MAX];
75 snprintf(filename, PATH_MAX, "%s/%s", MICSYSFSDIR, entry);
77 snprintf(filename, PATH_MAX, "%s/%s/%s",
78 MICSYSFSDIR, dir, entry);
80 oldvalue = readsysfs(dir, entry);
82 fd = open(filename, O_RDWR);
85 mpsslog("Failed to open sysfs entry '%s': %s\n",
86 filename, strerror(errno));
90 if (!oldvalue || strcmp(value, oldvalue)) {
91 if (write(fd, value, strlen(value)) < 0) {
93 mpsslog("Failed to write new sysfs entry '%s': %s\n",
94 filename, strerror(errno));