/* * Copyright (C) 2006, Intel Corporation * * This file is part of the Linux-ready Firmware Developer Kit * * This program file is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by the * Free Software Foundation;version 2.1 of the License. * * This library 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 Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program in a file named COPYING; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA */ #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include /* For each fan present, report its current state */ static void do_fan(char *dir, char *name) { FILE *file; char path[PATH_MAX]; /* fan's directory */ char buffer[4096]; /* holds contents of fan's 'state' file */ char *state = NULL; /* current state of the fan */ if (dir==NULL) return; /* Open the fan's 'state' directory */ sprintf(path, "%s/state", dir); file = fopen(path, "r"); if (file == NULL) { report_result("fan", WARN, "Fan present but undersupported - no state present", path, NULL); return; } /* Grep for its current state */ if (fgets(buffer, 4095, file) == NULL) { report_result("fan", WARN, "Fan present but undersupported - no status information in state file", path, NULL); return; } fclose(file); state = strstr(buffer,"status:"); if(state == NULL) { report_result("fan", WARN, "Fan present but undersupported - status format not recognized", path, NULL); return; } state += 8; while((state[0] == ' ') && (state[0] != '\n')) state++; chop_newline(state); sprintf(buffer,"Fan %s status is: %s", name, state); report_result("fan", PASS, buffer, NULL, NULL); } int main(int argc, char **argv) { DIR *dir; struct dirent *entry; int fandir = 0; start_test("fan", "Fan tests", "This test reports how many fans there are in the system. " "It also checks for the current status of the fan(s)."); dir = opendir("/proc/acpi/fan/"); if (!dir) { report_result("fan", WARN, "No fan information present", NULL, NULL); goto out; } /* For each fan listed, print out the result of its current state */ do { char fanpath[2048]; entry = readdir(dir); if (entry && strlen(entry->d_name)>2) { sprintf(fanpath, "/proc/acpi/fan/%s", entry->d_name); do_fan(fanpath, entry->d_name); fandir++; } } while (entry); /* Directory /proc/acpi/fan/. contains no sub-dirs */ if(fandir == 0) report_result("fan", WARN, "No fan information present", NULL, NULL); out: finish_test("fan"); return EXIT_SUCCESS; }