| diff '--exclude=*~' -Nurp sp-oops-extract-0.0.7.orig/src/oopslog.c sp-oops-extract-0.0.7/src/oopslog.c |
| Index: sp-oops-extract-0.0.7/src/oopslog.c |
| =================================================================== |
| --- sp-oops-extract-0.0.7.orig/src/oopslog.c 2017-04-05 16:31:18.973231119 -0700 |
| +++ sp-oops-extract-0.0.7/src/oopslog.c 2017-04-05 16:31:18.965231155 -0700 |
| @@ -37,11 +37,18 @@ |
| #include <linux/fs.h>
|
| #include <err.h>
|
| #include <stdint.h>
|
| +#include <stdlib.h>
|
| +#include <limits.h>
|
|
|
| -#define OOPS_PAGE_SIZE 4096
|
| +#define DEFAULT_OOPS_PAGE_SIZE 4096
|
| +#define OOPS_PAGE_SIZE_ENV "OOPS_PAGE_SIZE"
|
| +#define OOPS_RECORD_SIZE_PATH "/sys/module/mtdoops/parameters/record_size"
|
| +#define INVALID_OOPS_PAGE_SIZE ULONG_MAX
|
|
|
| #define MEMGETINFO _IOR('M', 1, struct mtd_info_user)
|
|
|
| +unsigned long OOPS_PAGE_SIZE = DEFAULT_OOPS_PAGE_SIZE;
|
| +
|
| struct mtd_info_user {
|
| uint8_t type;
|
| uint32_t flags;
|
| @@ -55,6 +62,72 @@ |
| uint32_t eccsize;
|
| };
|
|
|
| +static unsigned long init_oops_page_size_from_env(void)
|
| +{
|
| + char *from_env = getenv(OOPS_PAGE_SIZE_ENV);
|
| + char *endptr = NULL;
|
| + unsigned long val = INVALID_OOPS_PAGE_SIZE;
|
| +
|
| + if (!from_env) {
|
| + return val;
|
| + }
|
| +
|
| + errno = 0;
|
| + val = strtoul(from_env, &endptr, 0);
|
| + if (from_env == endptr) {
|
| + // invalid value. Ignore it.
|
| + val = INVALID_OOPS_PAGE_SIZE;
|
| + } else if (val == ULONG_MAX && errno == ERANGE) {
|
| + // invalid value. Ignore it.
|
| + val = INVALID_OOPS_PAGE_SIZE;
|
| + } else {
|
| + // good read, using value.
|
| + }
|
| +
|
| + return val;
|
| +}
|
| +
|
| +static unsigned long init_oops_page_size_from_module(void)
|
| +{
|
| + FILE *fp = fopen(OOPS_RECORD_SIZE_PATH, "r");
|
| + unsigned long val = INVALID_OOPS_PAGE_SIZE;
|
| + int items;
|
| +
|
| + if (!fp) {
|
| + return INVALID_OOPS_PAGE_SIZE;
|
| + }
|
| +
|
| + items = fscanf(fp, "%lu", &val);
|
| + fclose(fp);
|
| + if (items != 1) {
|
| + val = INVALID_OOPS_PAGE_SIZE;
|
| + }
|
| +
|
| + return val;
|
| +}
|
| +
|
| +// Set OOPS_PAGE_SIZE value from either environment (OOPS_PAGE_SIZE)
|
| +// or from the kernel module parameter.
|
| +static void init_oops_page_size(void)
|
| +{
|
| + unsigned long val;
|
| +
|
| + val = init_oops_page_size_from_env();
|
| +
|
| + if (val == INVALID_OOPS_PAGE_SIZE) {
|
| + val = init_oops_page_size_from_module();
|
| + }
|
| +
|
| + if (val != INVALID_OOPS_PAGE_SIZE) {
|
| + OOPS_PAGE_SIZE = val;
|
| + }
|
| +
|
| + fprintf(stderr, "Using OOPS_PAGE_SIZE=%lu\n", val);
|
| + if ((OOPS_PAGE_SIZE % 4096) != 0) {
|
| + fprintf(stderr, "Warning: OOPS_PAGE_SIZE is supposed to be a multiple of 4096\n");
|
| + }
|
| +}
|
| +
|
| static int try_to_check_for_bad_blocks(void) {
|
| /* FIXME
|
| * Checking for bad blocks should be implemented here.
|
| @@ -83,6 +156,8 @@ |
|
|
| device = argv[1];
|
|
|
| + init_oops_page_size();
|
| +
|
| buf = malloc(OOPS_PAGE_SIZE);
|
| if (!buf) {
|
| err(-1, "Unable to allocate memory");
|