You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.5 KiB

  1. --- a/src/ubi.c
  2. +++ b/src/ubi.c
  3. @@ -35,6 +35,9 @@
  4. #define DEV_BAD_COUNT \
  5. "bad_peb_count" // Count of bad physical eraseblocks on the underlying MTD
  6. // device.
  7. +// Value reserved for bad block
  8. +#define DEV_RESERVED_BAD_BLOCK "reserved_for_bad"
  9. +
  10. #define MAXIMUM_ERASE "max_ec" // Current maximum erase counter value
  11. /*
  12. @@ -140,6 +143,35 @@ static inline int ubi_read_max_ec(const
  13. return 0;
  14. } /* int ubi_read_max_ec */
  15. +static inline int ubi_read_percent(const char *dev_name) {
  16. + int ret;
  17. + int bcount;
  18. + int bblock;
  19. +
  20. + ret = ubi_read_dev_attr(dev_name, DEV_BAD_COUNT, &bcount);
  21. +
  22. + if (ret != 0) {
  23. + ERROR(PLUGIN_NAME " : Unable to read bad_peb_count");
  24. + return -1;
  25. + }
  26. +
  27. + ret = ubi_read_dev_attr(dev_name, DEV_RESERVED_BAD_BLOCK, &bblock);
  28. +
  29. + if (ret != 0) {
  30. + ERROR(PLUGIN_NAME " : Unable to read reserved_for_bad");
  31. + return -1;
  32. + }
  33. +
  34. + if (bblock == 0) {
  35. + ERROR(PLUGIN_NAME " : Percentage value cannot be determined (reserved_for_bad = 0)");
  36. + return -2;
  37. + }
  38. +
  39. + ubi_submit(dev_name, "percent", (gauge_t)((float_t)bcount / (float_t)bblock * 100.0));
  40. +
  41. + return 0;
  42. +} /* int ubi_read_percent */
  43. +
  44. static int ubi_read(void) {
  45. DIR *dir;
  46. struct dirent *dirent;
  47. @@ -155,6 +187,7 @@ static int ubi_read(void) {
  48. ubi_read_dev_bad_count(dirent->d_name);
  49. ubi_read_max_ec(dirent->d_name);
  50. + ubi_read_percent(dirent->d_name);
  51. }
  52. closedir(dir);