scan.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. * @leb_ver: logical eraseblock version (obsolete)
  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. int scrub;
  44. unsigned long long sqnum;
  45. union {
  46. struct rb_node rb;
  47. struct list_head list;
  48. } u;
  49. uint32_t leb_ver;
  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 size in case of
  61. * 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. * @bad_peb_count: count of bad physical eraseblocks
  91. * those belonging to "preserve"-compatible internal volumes)
  92. * @vols_found: number of volumes found during scanning
  93. * @highest_vol_id: highest volume ID
  94. * @alien_peb_count: count of physical eraseblocks in the @alien list
  95. * @is_empty: flag indicating whether the MTD device is empty or not
  96. * @min_ec: lowest erase counter value
  97. * @max_ec: highest erase counter value
  98. * @max_sqnum: highest sequence number value
  99. * @mean_ec: mean erase counter value
  100. * @ec_sum: a temporary variable used when calculating @mean_ec
  101. * @ec_count: a temporary variable used when calculating @mean_ec
  102. *
  103. * This data structure contains the result of scanning and may be used by other
  104. * UBI units to build final UBI data structures, further error-recovery and so
  105. * on.
  106. */
  107. struct ubi_scan_info {
  108. struct rb_root volumes;
  109. struct list_head corr;
  110. struct list_head free;
  111. struct list_head erase;
  112. struct list_head alien;
  113. int bad_peb_count;
  114. int vols_found;
  115. int highest_vol_id;
  116. int alien_peb_count;
  117. int is_empty;
  118. int min_ec;
  119. int max_ec;
  120. unsigned long long max_sqnum;
  121. int mean_ec;
  122. uint64_t ec_sum;
  123. int ec_count;
  124. };
  125. struct ubi_device;
  126. struct ubi_vid_hdr;
  127. /*
  128. * ubi_scan_move_to_list - move a physical eraseblock from the volume tree to a
  129. * list.
  130. *
  131. * @sv: volume scanning information
  132. * @seb: scanning eraseblock infprmation
  133. * @list: the list to move to
  134. */
  135. static inline void ubi_scan_move_to_list(struct ubi_scan_volume *sv,
  136. struct ubi_scan_leb *seb,
  137. struct list_head *list)
  138. {
  139. rb_erase(&seb->u.rb, &sv->root);
  140. list_add_tail(&seb->u.list, list);
  141. }
  142. int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_scan_info *si,
  143. int pnum, int ec, const struct ubi_vid_hdr *vid_hdr,
  144. int bitflips);
  145. struct ubi_scan_volume *ubi_scan_find_sv(const struct ubi_scan_info *si,
  146. int vol_id);
  147. struct ubi_scan_leb *ubi_scan_find_seb(const struct ubi_scan_volume *sv,
  148. int lnum);
  149. void ubi_scan_rm_volume(struct ubi_scan_info *si, struct ubi_scan_volume *sv);
  150. struct ubi_scan_leb *ubi_scan_get_free_peb(struct ubi_device *ubi,
  151. struct ubi_scan_info *si);
  152. int ubi_scan_erase_peb(struct ubi_device *ubi, const struct ubi_scan_info *si,
  153. int pnum, int ec);
  154. struct ubi_scan_info *ubi_scan(struct ubi_device *ubi);
  155. void ubi_scan_destroy_si(struct ubi_scan_info *si);
  156. #endif /* !__UBI_SCAN_H__ */