scan.h 6.1 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_ainf_peb - attach 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_ainf_peb objects
  34. * @u.list: link in one of the eraseblock lists
  35. *
  36. * One object of this type is allocated for each physical eraseblock when
  37. * attaching an MTD device.
  38. */
  39. struct ubi_ainf_peb {
  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_ainf_volume - attaching 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_ainf_peb objects)
  68. *
  69. * One object of this type is allocated for each volume when attaching an MTD
  70. * device.
  71. */
  72. struct ubi_ainf_volume {
  73. int vol_id;
  74. int highest_lnum;
  75. int leb_count;
  76. int vol_type;
  77. int used_ebs;
  78. int last_data_size;
  79. int data_pad;
  80. int compat;
  81. struct rb_node rb;
  82. struct rb_root root;
  83. };
  84. /**
  85. * struct ubi_attach_info - MTD device attaching information.
  86. * @volumes: root of the volume RB-tree
  87. * @corr: list of corrupted physical eraseblocks
  88. * @free: list of free physical eraseblocks
  89. * @erase: list of physical eraseblocks which have to be erased
  90. * @alien: list of physical eraseblocks which should not be used by UBI (e.g.,
  91. * those belonging to "preserve"-compatible internal volumes)
  92. * @corr_peb_count: count of PEBs in the @corr list
  93. * @empty_peb_count: count of PEBs which are presumably empty (contain only
  94. * 0xFF bytes)
  95. * @alien_peb_count: count of PEBs in the @alien list
  96. * @bad_peb_count: count of bad physical eraseblocks
  97. * @maybe_bad_peb_count: count of bad physical eraseblocks which are not marked
  98. * as bad yet, but which look like bad
  99. * @vols_found: number of volumes found
  100. * @highest_vol_id: highest volume ID
  101. * @is_empty: flag indicating whether the MTD device is empty or not
  102. * @min_ec: lowest erase counter value
  103. * @max_ec: highest erase counter value
  104. * @max_sqnum: highest sequence number value
  105. * @mean_ec: mean erase counter value
  106. * @ec_sum: a temporary variable used when calculating @mean_ec
  107. * @ec_count: a temporary variable used when calculating @mean_ec
  108. * @scan_leb_slab: slab cache for &struct ubi_ainf_peb objects
  109. *
  110. * This data structure contains the result of attaching an MTD device and may
  111. * be used by other UBI sub-systems to build final UBI data structures, further
  112. * error-recovery and so on.
  113. */
  114. struct ubi_attach_info {
  115. struct rb_root volumes;
  116. struct list_head corr;
  117. struct list_head free;
  118. struct list_head erase;
  119. struct list_head alien;
  120. int corr_peb_count;
  121. int empty_peb_count;
  122. int alien_peb_count;
  123. int bad_peb_count;
  124. int maybe_bad_peb_count;
  125. int vols_found;
  126. int highest_vol_id;
  127. int is_empty;
  128. int min_ec;
  129. int max_ec;
  130. unsigned long long max_sqnum;
  131. int mean_ec;
  132. uint64_t ec_sum;
  133. int ec_count;
  134. struct kmem_cache *scan_leb_slab;
  135. };
  136. struct ubi_device;
  137. struct ubi_vid_hdr;
  138. /*
  139. * ubi_scan_move_to_list - move a PEB from the volume tree to a list.
  140. *
  141. * @av: volume attaching information
  142. * @aeb: scanning eraseblock information
  143. * @list: the list to move to
  144. */
  145. static inline void ubi_scan_move_to_list(struct ubi_ainf_volume *av,
  146. struct ubi_ainf_peb *aeb,
  147. struct list_head *list)
  148. {
  149. rb_erase(&aeb->u.rb, &av->root);
  150. list_add_tail(&aeb->u.list, list);
  151. }
  152. int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_attach_info *ai,
  153. int pnum, int ec, const struct ubi_vid_hdr *vid_hdr,
  154. int bitflips);
  155. struct ubi_ainf_volume *ubi_scan_find_av(const struct ubi_attach_info *ai,
  156. int vol_id);
  157. struct ubi_ainf_peb *ubi_scan_find_aeb(const struct ubi_ainf_volume *av,
  158. int lnum);
  159. void ubi_scan_rm_volume(struct ubi_attach_info *ai, struct ubi_ainf_volume *av);
  160. struct ubi_ainf_peb *ubi_scan_get_free_peb(struct ubi_device *ubi,
  161. struct ubi_attach_info *ai);
  162. int ubi_scan_erase_peb(struct ubi_device *ubi, const struct ubi_attach_info *ai,
  163. int pnum, int ec);
  164. struct ubi_attach_info *ubi_scan(struct ubi_device *ubi);
  165. void ubi_scan_destroy_ai(struct ubi_attach_info *ai);
  166. #endif /* !__UBI_SCAN_H__ */