blob: 252b1f1e8235df331d5aa02950d49d514df3e12c [file] [log] [blame]
Kyungmin Parkf412fef2008-11-19 16:27:23 +01001/*
2 * Copyright (c) International Business Machines Corp., 2006
3 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Kyungmin Parkf412fef2008-11-19 16:27:23 +01005 *
6 * Author: Artem Bityutskiy (Битюцкий Артём)
7 */
8
9#ifndef __UBI_SCAN_H__
10#define __UBI_SCAN_H__
11
12/* The erase counter value for this physical eraseblock is unknown */
13#define UBI_SCAN_UNKNOWN_EC (-1)
14
15/**
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)
26 *
27 * One object of this type is allocated for each physical eraseblock during
28 * scanning.
29 */
30struct ubi_scan_leb {
31 int ec;
32 int pnum;
33 int lnum;
34 int scrub;
35 unsigned long long sqnum;
36 union {
37 struct rb_node rb;
38 struct list_head list;
39 } u;
40 uint32_t leb_ver;
41};
42
43/**
44 * struct ubi_scan_volume - scanning information about a volume.
45 * @vol_id: volume ID
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
50 * static volumes)
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
53 * dynamic volumes)
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)
60 *
61 * One object of this type is allocated for each volume during scanning.
62 */
63struct ubi_scan_volume {
64 int vol_id;
65 int highest_lnum;
66 int leb_count;
67 int vol_type;
68 int used_ebs;
69 int last_data_size;
70 int data_pad;
71 int compat;
72 struct rb_node rb;
73 struct rb_root root;
74};
75
76/**
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
95 *
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
98 * on.
99 */
100struct 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;
106 int bad_peb_count;
107 int vols_found;
108 int highest_vol_id;
109 int alien_peb_count;
110 int is_empty;
111 int min_ec;
112 int max_ec;
113 unsigned long long max_sqnum;
114 int mean_ec;
115 uint64_t ec_sum;
116 int ec_count;
117};
118
119struct ubi_device;
120struct ubi_vid_hdr;
121
122/*
123 * ubi_scan_move_to_list - move a physical eraseblock from the volume tree to a
124 * list.
125 *
126 * @sv: volume scanning information
127 * @seb: scanning eraseblock infprmation
128 * @list: the list to move to
129 */
130static inline void ubi_scan_move_to_list(struct ubi_scan_volume *sv,
131 struct ubi_scan_leb *seb,
132 struct list_head *list)
133{
134 rb_erase(&seb->u.rb, &sv->root);
135 list_add_tail(&seb->u.list, list);
136}
137
138int 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,
140 int bitflips);
141struct ubi_scan_volume *ubi_scan_find_sv(const struct ubi_scan_info *si,
142 int vol_id);
143struct ubi_scan_leb *ubi_scan_find_seb(const struct ubi_scan_volume *sv,
144 int lnum);
145void ubi_scan_rm_volume(struct ubi_scan_info *si, struct ubi_scan_volume *sv);
146struct ubi_scan_leb *ubi_scan_get_free_peb(struct ubi_device *ubi,
147 struct ubi_scan_info *si);
148int ubi_scan_erase_peb(struct ubi_device *ubi, const struct ubi_scan_info *si,
149 int pnum, int ec);
150struct ubi_scan_info *ubi_scan(struct ubi_device *ubi);
151void ubi_scan_destroy_si(struct ubi_scan_info *si);
152
153#endif /* !__UBI_SCAN_H__ */