scan.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. * @copy_flag: this LEB is a copy (@copy_flag is set in VID header of this LEB)
  31. * @sqnum: sequence number
  32. * @u: unions RB-tree or @list links
  33. * @u.rb: link in the per-volume RB-tree of &struct ubi_scan_leb objects
  34. * @u.list: link in one of the eraseblock lists
  35. *
  36. * One object of this type is allocated for each physical eraseblock during
  37. * scanning.
  38. */
  39. struct ubi_scan_leb {
  40. int ec;
  41. int pnum;
  42. int lnum;
  43. unsigned int scrub:1;
  44. unsigned int copy_flag:1;
  45. unsigned long long sqnum;
  46. union {
  47. struct rb_node rb;
  48. struct list_head list;
  49. } u;
  50. };
  51. /**
  52. * struct ubi_scan_volume - scanning information about a volume.
  53. * @vol_id: volume ID
  54. * @highest_lnum: highest logical eraseblock number in this volume
  55. * @leb_count: number of logical eraseblocks in this volume
  56. * @vol_type: volume type
  57. * @used_ebs: number of used logical eraseblocks in this volume (only for
  58. * static volumes)
  59. * @last_data_size: amount of data in the last logical eraseblock of this
  60. * volume (always equivalent to the usable logical eraseblock
  61. * size in case of dynamic volumes)
  62. * @data_pad: how many bytes at the end of logical eraseblocks of this volume
  63. * are not used (due to volume alignment)
  64. * @compat: compatibility flags of this volume
  65. * @rb: link in the volume RB-tree
  66. * @root: root of the RB-tree containing all the eraseblock belonging to this
  67. * volume (&struct ubi_scan_leb objects)
  68. *
  69. * One object of this type is allocated for each volume during scanning.
  70. */
  71. struct ubi_scan_volume {
  72. int vol_id;
  73. int highest_lnum;
  74. int leb_count;
  75. int vol_type;
  76. int used_ebs;
  77. int last_data_size;
  78. int data_pad;
  79. int compat;
  80. struct rb_node rb;
  81. struct rb_root root;
  82. };
  83. /**
  84. * struct ubi_scan_info - UBI scanning information.
  85. * @volumes: root of the volume RB-tree
  86. * @corr: list of corrupted physical eraseblocks
  87. * @free: list of free physical eraseblocks
  88. * @erase: list of physical eraseblocks which have to be erased
  89. * @alien: list of physical eraseblocks which should not be used by UBI (e.g.,
  90. * those belonging to "preserve"-compatible internal volumes)
  91. * @corr_peb_count: count of PEBs in the @corr list
  92. * @empty_peb_count: count of PEBs which are presumably empty (contain only
  93. * 0xFF bytes)
  94. * @alien_peb_count: count of PEBs in the @alien list
  95. * @bad_peb_count: count of bad physical eraseblocks
  96. * @maybe_bad_peb_count: count of bad physical eraseblocks which are not marked
  97. * as bad yet, but which look like bad
  98. * @vols_found: number of volumes found during scanning
  99. * @highest_vol_id: highest volume ID
  100. * @is_empty: flag indicating whether the MTD device is empty or not
  101. * @min_ec: lowest erase counter value
  102. * @max_ec: highest erase counter value
  103. * @max_sqnum: highest sequence number value
  104. * @mean_ec: mean erase counter value
  105. * @ec_sum: a temporary variable used when calculating @mean_ec
  106. * @ec_count: a temporary variable used when calculating @mean_ec
  107. * @scan_leb_slab: slab cache for &struct ubi_scan_leb objects
  108. *
  109. * This data structure contains the result of scanning and may be used by other
  110. * UBI sub-systems to build final UBI data structures, further error-recovery
  111. * and so on.
  112. */
  113. struct ubi_scan_info {
  114. struct rb_root volumes;
  115. struct list_head corr;
  116. struct list_head free;
  117. struct list_head erase;
  118. struct list_head alien;
  119. int corr_peb_count;
  120. int empty_peb_count;
  121. int alien_peb_count;
  122. int bad_peb_count;
  123. int maybe_bad_peb_count;
  124. int vols_found;
  125. int highest_vol_id;
  126. int is_empty;
  127. int min_ec;
  128. int max_ec;
  129. unsigned long long max_sqnum;
  130. int mean_ec;
  131. uint64_t ec_sum;
  132. int ec_count;
  133. struct kmem_cache *scan_leb_slab;
  134. };
  135. struct ubi_device;
  136. struct ubi_vid_hdr;
  137. /*
  138. * ubi_scan_move_to_list - move a PEB from the volume tree to a list.
  139. *
  140. * @sv: volume scanning information
  141. * @seb: scanning eraseblock information
  142. * @list: the list to move to
  143. */
  144. static inline void ubi_scan_move_to_list(struct ubi_scan_volume *sv,
  145. struct ubi_scan_leb *seb,
  146. struct list_head *list)
  147. {
  148. rb_erase(&seb->u.rb, &sv->root);
  149. list_add_tail(&seb->u.list, list);
  150. }
  151. int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_scan_info *si,
  152. int pnum, int ec, const struct ubi_vid_hdr *vid_hdr,
  153. int bitflips);
  154. struct ubi_scan_volume *ubi_scan_find_sv(const struct ubi_scan_info *si,
  155. int vol_id);
  156. struct ubi_scan_leb *ubi_scan_find_seb(const struct ubi_scan_volume *sv,
  157. int lnum);
  158. void ubi_scan_rm_volume(struct ubi_scan_info *si, struct ubi_scan_volume *sv);
  159. struct ubi_scan_leb *ubi_scan_get_free_peb(struct ubi_device *ubi,
  160. struct ubi_scan_info *si);
  161. int ubi_scan_erase_peb(struct ubi_device *ubi, const struct ubi_scan_info *si,
  162. int pnum, int ec);
  163. struct ubi_scan_info *ubi_scan(struct ubi_device *ubi);
  164. void ubi_scan_destroy_si(struct ubi_scan_info *si);
  165. #endif /* !__UBI_SCAN_H__ */