/* * fwts_summary_init() * initialise */ int fwts_summary_init(void) { int i; /* initialise list of summary items for all error levels */ for (i = 0; i < SUMMARY_MAX; i++) if ((fwts_summaries[i] = fwts_list_new()) == NULL) { fwts_summary_deinit(); return FWTS_ERROR; } return FWTS_OK; }
/* * fwts_file_read() * read given file and return contents as a list of lines */ fwts_list *fwts_file_read(FILE *fp) { fwts_list *list; char buffer[8192]; if ((list = fwts_list_new()) == NULL) return NULL; while (fgets(buffer, sizeof(buffer), fp) != NULL) { buffer[strlen(buffer) - 1] = '\0'; /* Chop off "\n" */ fwts_text_list_append(list, buffer); } return list; }
static int get_mtrrs(void) { struct mtrr_entry *entry; FILE *fp; char line[4096]; if ((mtrr_list = fwts_list_new()) == NULL) return FWTS_ERROR; if ((fp = fopen("/proc/mtrr", "r")) == NULL) { fwts_list_free(mtrr_list, free); return FWTS_ERROR; } while (!feof(fp)) { char *ptr1, *ptr2; if (fgets(line, sizeof(line), fp) == NULL) break; if ((entry = calloc(1, sizeof(struct mtrr_entry))) == NULL) { fwts_list_free(mtrr_list, free); fclose(fp); return FWTS_ERROR; } /* * Put all text to lower case since the output * from /proc/mtrr is variable upper/lower case * across kernel versions so forcing to lower * saves comparing for upper/lower case variants. */ for (ptr1 = line; *ptr1; ptr1++) *ptr1 = tolower(*ptr1); /* Parse the following: * reg01: base=0x080000000 ( 2048MB), size= 1024MB, count=1: write-back */ /* Get register, in decimal */ if (strncmp(line, "reg", 3)) { free(entry); continue; } entry->reg = strtoul(line + 3, NULL, 10); /* Get base, in hex */ if ((ptr1 = strstr(line, "base=0x")) == NULL) { free(entry); continue; } entry->start = strtoull(ptr1 + 5, NULL, 16); /* Get size, in decimal */ if ((ptr1 = strstr(line, "size=")) == NULL) { free(entry); continue; } entry->size = strtoull(ptr1 + 5, &ptr2, 10); if (ptr2 && (*ptr2 == 'm')) entry->size *= 1024 * 1024; if (ptr2 && (*ptr2 == 'k')) entry->size *= 1024; entry->end = entry->start + entry->size; if (strstr(line, "write-back")) entry->type = WRITE_BACK; else if (strstr(line, "uncachable")) entry->type = UNCACHED; else if (strstr(line, "write-through")) entry->type = WRITE_THROUGH; else if (strstr(line, "write-combining")) entry->type = WRITE_COMBINING; else if (strstr(line, "write-protect")) entry->type = WRITE_PROTECT; else entry->type = UNKNOWN; fwts_list_append(mtrr_list, entry); } fclose(fp); return FWTS_OK; }