scan.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * Copyright (c) International Business Machines Corp., 2006
  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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. *
  18. * Author: Artem Bityutskiy (Битюцкий Артём)
  19. */
  20. #ifndef __UBI_SCAN_H__
  21. #define __UBI_SCAN_H__
  22. /* The erase counter value for this physical eraseblock is unknown */
  23. #define UBI_SCAN_UNKNOWN_EC (-1)
  24. /**
  25. * struct ubi_scan_leb - scanning information about a physical eraseblock.
  26. * @ec: erase counter (%UBI_SCAN_UNKNOWN_EC if it is unknown)
  27. * @pnum: physical eraseblock number
  28. * @lnum: logical eraseblock number
  29. * @scrub: if this physical eraseblock needs scrubbing
  30. * @sqnum: sequence number
  31. * @u: unions RB-tree or @list links
  32. * @u.rb: link in the per-volume RB-tree of &struct ubi_scan_leb objects
  33. * @u.list: link in one of the eraseblock lists
  34. *
  35. * One object of this type is allocated for each physical eraseblock during
  36. * scanning.
  37. */
  38. struct ubi_scan_leb {
  39. int ec;
  40. int pnum;
  41. int lnum;
  42. int scrub;
  43. unsigned long long sqnum;
  44. union {
  45. struct rb_node rb;
  46. struct list_head list;
  47. } u;
  48. };
  49. /**
  50. * struct ubi_scan_volume - scanning information about a volume.
  51. * @vol_id: volume ID
  52. * @highest_lnum: highest logical eraseblock number in this volume
  53. * @leb_count: number of logical eraseblocks in this volume
  54. * @vol_type: volume type
  55. * @used_ebs: number of used logical eraseblocks in this volume (only for
  56. * static volumes)
  57. * @last_data_size: amount of data in the last logical eraseblock of this
  58. * volume (always equivalent to the usable logical eraseblock
  59. * size in case of dynamic volumes)
  60. * @data_pad: how many bytes at the end of logical eraseblocks of this volume
  61. * are not used (due to volume alignment)
  62. * @compat: compatibility flags of this volume
  63. * @rb: link in the volume RB-tree
  64. * @root: root of the RB-tree containing all the eraseblock belonging to this
  65. * volume (&struct ubi_scan_leb objects)
  66. *
  67. * One object of this type is allocated for each volume during scanning.
  68. */
  69. struct ubi_scan_volume {
  70. int vol_id;
  71. int highest_lnum;
  72. int leb_count;
  73. int vol_type;
  74. int used_ebs;
  75. int last_data_size;
  76. int data_pad;
  77. int compat;
  78. struct rb_node rb;
  79. struct rb_root root;
  80. };
  81. /**
  82. * struct ubi_scan_info - UBI scanning information.
  83. * @volumes: root of the volume RB-tree
  84. * @corr: list of corrupted physical eraseblocks
  85. * @free: list of free physical eraseblocks
  86. * @erase: list of physical eraseblocks which have to be erased
  87. * @alien: list of physical eraseblocks which should not be used by UBI (e.g.,
  88. * those belonging to "preserve"-compatible internal volumes)
  89. * @bad_peb_count: count of bad physical eraseblocks
  90. * @vols_found: number of volumes found during scanning
  91. * @highest_vol_id: highest volume ID
  92. * @alien_peb_count: count of physical eraseblocks in the @alien list
  93. * @is_empty: flag indicating whether the MTD device is empty or not
  94. * @min_ec: lowest erase counter value
  95. * @max_ec: highest erase counter value
  96. * @max_sqnum: highest sequence number value
  97. * @mean_ec: mean erase counter value
  98. * @ec_sum: a temporary variable used when calculating @mean_ec
  99. * @ec_count: a temporary variable used when calculating @mean_ec
  100. *
  101. * This data structure contains the result of scanning and may be used by other
  102. * UBI sub-systems to build final UBI data structures, further error-recovery
  103. * and so on.
  104. */
  105. struct ubi_scan_info {
  106. struct rb_root volumes;
  107. struct list_head corr;
  108. struct list_head free;
  109. struct list_head erase;
  110. struct list_head alien;
  111. int bad_peb_count;
  112. int vols_found;
  113. int highest_vol_id;
  114. int alien_peb_count;
  115. int is_empty;
  116. int min_ec;
  117. int max_ec;
  118. unsigned long long max_sqnum;
  119. int mean_ec;
  120. uint64_t ec_sum;
  121. int ec_count;
  122. };
  123. struct ubi_device;
  124. struct ubi_vid_hdr;
  125. /*
  126. * ubi_scan_move_to_list - move a PEB from the volume tree to a list.
  127. *
  128. * @sv: volume scanning information
  129. * @seb: scanning eraseblock infprmation
  130. * @list: the list to move to
  131. */
  132. static inline void ubi_scan_move_to_list(struct ubi_scan_volume *sv,
  133. struct ubi_scan_leb *seb,
  134. struct list_head *list)
  135. {
  136. rb_erase(&seb->u.rb, &sv->root);
  137. list_add_tail(&seb->u.list, list);
  138. }
  139. int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_scan_info *si,
  140. int pnum, int ec, const struct ubi_vid_hdr *vid_hdr,
  141. int bitflips);
  142. struct ubi_scan_volume *ubi_scan_find_sv(const struct ubi_scan_info *si,
  143. int vol_id);
  144. struct ubi_scan_leb *ubi_scan_find_seb(const struct ubi_scan_volume *sv,
  145. int lnum);
  146. void ubi_scan_rm_volume(struct ubi_scan_info *si, struct ubi_scan_volume *sv);
  147. struct ubi_scan_leb *ubi_scan_get_free_peb(struct ubi_device *ubi,
  148. struct ubi_scan_info *si);
  149. int ubi_scan_erase_peb(struct ubi_device *ubi, const struct ubi_scan_info *si,
  150. int pnum, int ec);
  151. struct ubi_scan_info *ubi_scan(struct ubi_device *ubi);
  152. void ubi_scan_destroy_si(struct ubi_scan_info *si);
  153. #endif /* !__UBI_SCAN_H__ */