1 // SPDX-License-Identifier: GPL-2.0-only
3 * Intel MIC Platform Software Stack (MPSS)
5 * Copyright(c) 2013 Intel Corporation.
7 * Intel MIC User Space Tools.
12 #define PAGE_SIZE 4096
15 readsysfs(char *dir
, char *entry
)
17 char filename
[PATH_MAX
];
18 char value
[PAGE_SIZE
];
24 snprintf(filename
, PATH_MAX
, "%s/%s", MICSYSFSDIR
, entry
);
26 snprintf(filename
, PATH_MAX
,
27 "%s/%s/%s", MICSYSFSDIR
, dir
, entry
);
29 fd
= open(filename
, O_RDONLY
);
31 mpsslog("Failed to open sysfs entry '%s': %s\n",
32 filename
, strerror(errno
));
36 len
= read(fd
, value
, sizeof(value
));
38 mpsslog("Failed to read sysfs entry '%s': %s\n",
39 filename
, strerror(errno
));
45 value
[len
- 1] = '\0';
47 string
= malloc(strlen(value
) + 1);
49 strcpy(string
, value
);
57 setsysfs(char *dir
, char *entry
, char *value
)
59 char filename
[PATH_MAX
];
64 snprintf(filename
, PATH_MAX
, "%s/%s", MICSYSFSDIR
, entry
);
66 snprintf(filename
, PATH_MAX
, "%s/%s/%s",
67 MICSYSFSDIR
, dir
, entry
);
69 oldvalue
= readsysfs(dir
, entry
);
71 fd
= open(filename
, O_RDWR
);
74 mpsslog("Failed to open sysfs entry '%s': %s\n",
75 filename
, strerror(errno
));
79 if (!oldvalue
|| strcmp(value
, oldvalue
)) {
80 if (write(fd
, value
, strlen(value
)) < 0) {
82 mpsslog("Failed to write new sysfs entry '%s': %s\n",
83 filename
, strerror(errno
));