libscan.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (C) 2008 Nokia Corporation
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  12. * the GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. *
  18. * Author: Artem Bityutskiy
  19. *
  20. * UBI scanning library.
  21. */
  22. #ifndef __LIBSCAN_H__
  23. #define __LIBSCAN_H__
  24. #include <stdint.h>
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. /*
  29. * If an eraseblock does not contain an erase counter, this value is used
  30. * instead of the erase counter.
  31. */
  32. #define NO_EC 0xFFFFFFFF
  33. /*
  34. * If an eraseblock contains a corrupted erase counter, this value is used
  35. * instead of the erase counter.
  36. */
  37. #define CORRUPT_EC 0xFFFFFFFE
  38. /*
  39. * If an eraseblock does not contain an erase counter, one of these values is
  40. * used.
  41. *
  42. * @EB_EMPTY: the eraseblock appeared to be empty
  43. * @EB_CORRUPTED: the eraseblock contains corrupted erase counter header
  44. * @EB_ALIEN: the eraseblock contains some non-UBI data
  45. * @EC_MAX: maximum allowed erase counter value
  46. */
  47. enum
  48. {
  49. EB_EMPTY = 0xFFFFFFFF,
  50. EB_CORRUPTED = 0xFFFFFFFE,
  51. EB_ALIEN = 0xFFFFFFFD,
  52. EB_BAD = 0xFFFFFFFC,
  53. EC_MAX = UBI_MAX_ERASECOUNTER,
  54. };
  55. /**
  56. * struct ubi_scan_info - UBI scanning information.
  57. * @ec: erase counters or eraseblock status for all eraseblocks
  58. * @mean_ec: mean erase counter
  59. * @ok_cnt: count of eraseblock with correct erase counter header
  60. * @empty_cnt: count of supposedly eraseblocks
  61. * @corrupted_cnt: count of eraseblocks with corrupted erase counter header
  62. * @alien_cnt: count of eraseblock containing non-ubi data
  63. * @bad_cnt: count of bad eraseblocks
  64. * @good_cnt: count of non-bad eraseblocks
  65. * @vid_hdr_offs: volume ID header offset from the found EC headers (%-1 means
  66. * undefined)
  67. * @data_offs: data offset from the found EC headers (%-1 means undefined)
  68. */
  69. struct ubi_scan_info
  70. {
  71. uint32_t *ec;
  72. long long mean_ec;
  73. int ok_cnt;
  74. int empty_cnt;
  75. int corrupted_cnt;
  76. int alien_cnt;
  77. int bad_cnt;
  78. int good_cnt;
  79. int vid_hdr_offs;
  80. int data_offs;
  81. };
  82. struct mtd_dev_info;
  83. /**
  84. * ubi_scan - scan an MTD device.
  85. * @mtd: information about the MTD device to scan
  86. * @fd: MTD device node file descriptor
  87. * @info: the result of the scanning is returned here
  88. * @verbose: verbose mode: %0 - be silent, %1 - output progress information,
  89. * 2 - debugging output mode
  90. */
  91. int ubi_scan(struct mtd_dev_info *mtd, int fd, struct ubi_scan_info **info,
  92. int verbose);
  93. /**
  94. * ubi_scan_free - free scanning information.
  95. * @si: scanning information to free
  96. */
  97. void ubi_scan_free(struct ubi_scan_info *si);
  98. #ifdef __cplusplus
  99. }
  100. #endif
  101. #endif /* __LIBSCAN_H__ */