2 * Copyright (c) International Business Machines Corp., 2006
4 * SPDX-License-Identifier: GPL-2.0+
6 * Author: Artem Bityutskiy (Битюцкий Артём)
10 #define __UBI_SCAN_H__
12 /* The erase counter value for this physical eraseblock is unknown */
13 #define UBI_SCAN_UNKNOWN_EC (-1)
16 * struct ubi_scan_leb - scanning information about a physical eraseblock.
17 * @ec: erase counter (%UBI_SCAN_UNKNOWN_EC if it is unknown)
18 * @pnum: physical eraseblock number
19 * @lnum: logical eraseblock number
20 * @scrub: if this physical eraseblock needs scrubbing
21 * @sqnum: sequence number
22 * @u: unions RB-tree or @list links
23 * @u.rb: link in the per-volume RB-tree of &struct ubi_scan_leb objects
24 * @u.list: link in one of the eraseblock lists
25 * @leb_ver: logical eraseblock version (obsolete)
27 * One object of this type is allocated for each physical eraseblock during
35 unsigned long long sqnum;
38 struct list_head list;
44 * struct ubi_scan_volume - scanning information about a volume.
46 * @highest_lnum: highest logical eraseblock number in this volume
47 * @leb_count: number of logical eraseblocks in this volume
48 * @vol_type: volume type
49 * @used_ebs: number of used logical eraseblocks in this volume (only for
51 * @last_data_size: amount of data in the last logical eraseblock of this
52 * volume (always equivalent to the usable logical eraseblock size in case of
54 * @data_pad: how many bytes at the end of logical eraseblocks of this volume
55 * are not used (due to volume alignment)
56 * @compat: compatibility flags of this volume
57 * @rb: link in the volume RB-tree
58 * @root: root of the RB-tree containing all the eraseblock belonging to this
59 * volume (&struct ubi_scan_leb objects)
61 * One object of this type is allocated for each volume during scanning.
63 struct ubi_scan_volume {
77 * struct ubi_scan_info - UBI scanning information.
78 * @volumes: root of the volume RB-tree
79 * @corr: list of corrupted physical eraseblocks
80 * @free: list of free physical eraseblocks
81 * @erase: list of physical eraseblocks which have to be erased
82 * @alien: list of physical eraseblocks which should not be used by UBI (e.g.,
83 * @bad_peb_count: count of bad physical eraseblocks
84 * those belonging to "preserve"-compatible internal volumes)
85 * @vols_found: number of volumes found during scanning
86 * @highest_vol_id: highest volume ID
87 * @alien_peb_count: count of physical eraseblocks in the @alien list
88 * @is_empty: flag indicating whether the MTD device is empty or not
89 * @min_ec: lowest erase counter value
90 * @max_ec: highest erase counter value
91 * @max_sqnum: highest sequence number value
92 * @mean_ec: mean erase counter value
93 * @ec_sum: a temporary variable used when calculating @mean_ec
94 * @ec_count: a temporary variable used when calculating @mean_ec
96 * This data structure contains the result of scanning and may be used by other
97 * UBI units to build final UBI data structures, further error-recovery and so
100 struct ubi_scan_info {
101 struct rb_root volumes;
102 struct list_head corr;
103 struct list_head free;
104 struct list_head erase;
105 struct list_head alien;
113 unsigned long long max_sqnum;
123 * ubi_scan_move_to_list - move a physical eraseblock from the volume tree to a
126 * @sv: volume scanning information
127 * @seb: scanning eraseblock infprmation
128 * @list: the list to move to
130 static inline void ubi_scan_move_to_list(struct ubi_scan_volume *sv,
131 struct ubi_scan_leb *seb,
132 struct list_head *list)
134 rb_erase(&seb->u.rb, &sv->root);
135 list_add_tail(&seb->u.list, list);
138 int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_scan_info *si,
139 int pnum, int ec, const struct ubi_vid_hdr *vid_hdr,
141 struct ubi_scan_volume *ubi_scan_find_sv(const struct ubi_scan_info *si,
143 struct ubi_scan_leb *ubi_scan_find_seb(const struct ubi_scan_volume *sv,
145 void ubi_scan_rm_volume(struct ubi_scan_info *si, struct ubi_scan_volume *sv);
146 struct ubi_scan_leb *ubi_scan_get_free_peb(struct ubi_device *ubi,
147 struct ubi_scan_info *si);
148 int ubi_scan_erase_peb(struct ubi_device *ubi, const struct ubi_scan_info *si,
150 struct ubi_scan_info *ubi_scan(struct ubi_device *ubi);
151 void ubi_scan_destroy_si(struct ubi_scan_info *si);
153 #endif /* !__UBI_SCAN_H__ */