UBI: rename ubi_scan_get_free_peb
[linux-2.6.git] / drivers / mtd / ubi / scan.h
blob72ba24a13a7238879e1e0e33c65b0607aa1b7af0
1 /*
2 * Copyright (c) International Business Machines Corp., 2006
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.
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.
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
18 * Author: Artem Bityutskiy (Битюцкий Артём)
21 #ifndef __UBI_SCAN_H__
22 #define __UBI_SCAN_H__
24 /* The erase counter value for this physical eraseblock is unknown */
25 #define UBI_SCAN_UNKNOWN_EC (-1)
27 /**
28 * struct ubi_ainf_peb - attach information about a physical eraseblock.
29 * @ec: erase counter (%UBI_SCAN_UNKNOWN_EC if it is unknown)
30 * @pnum: physical eraseblock number
31 * @lnum: logical eraseblock number
32 * @scrub: if this physical eraseblock needs scrubbing
33 * @copy_flag: this LEB is a copy (@copy_flag is set in VID header of this LEB)
34 * @sqnum: sequence number
35 * @u: unions RB-tree or @list links
36 * @u.rb: link in the per-volume RB-tree of &struct ubi_ainf_peb objects
37 * @u.list: link in one of the eraseblock lists
39 * One object of this type is allocated for each physical eraseblock when
40 * attaching an MTD device.
42 struct ubi_ainf_peb {
43 int ec;
44 int pnum;
45 int lnum;
46 unsigned int scrub:1;
47 unsigned int copy_flag:1;
48 unsigned long long sqnum;
49 union {
50 struct rb_node rb;
51 struct list_head list;
52 } u;
55 /**
56 * struct ubi_ainf_volume - attaching information about a volume.
57 * @vol_id: volume ID
58 * @highest_lnum: highest logical eraseblock number in this volume
59 * @leb_count: number of logical eraseblocks in this volume
60 * @vol_type: volume type
61 * @used_ebs: number of used logical eraseblocks in this volume (only for
62 * static volumes)
63 * @last_data_size: amount of data in the last logical eraseblock of this
64 * volume (always equivalent to the usable logical eraseblock
65 * size in case of dynamic volumes)
66 * @data_pad: how many bytes at the end of logical eraseblocks of this volume
67 * are not used (due to volume alignment)
68 * @compat: compatibility flags of this volume
69 * @rb: link in the volume RB-tree
70 * @root: root of the RB-tree containing all the eraseblock belonging to this
71 * volume (&struct ubi_ainf_peb objects)
73 * One object of this type is allocated for each volume when attaching an MTD
74 * device.
76 struct ubi_ainf_volume {
77 int vol_id;
78 int highest_lnum;
79 int leb_count;
80 int vol_type;
81 int used_ebs;
82 int last_data_size;
83 int data_pad;
84 int compat;
85 struct rb_node rb;
86 struct rb_root root;
89 /**
90 * struct ubi_attach_info - MTD device attaching information.
91 * @volumes: root of the volume RB-tree
92 * @corr: list of corrupted physical eraseblocks
93 * @free: list of free physical eraseblocks
94 * @erase: list of physical eraseblocks which have to be erased
95 * @alien: list of physical eraseblocks which should not be used by UBI (e.g.,
96 * those belonging to "preserve"-compatible internal volumes)
97 * @corr_peb_count: count of PEBs in the @corr list
98 * @empty_peb_count: count of PEBs which are presumably empty (contain only
99 * 0xFF bytes)
100 * @alien_peb_count: count of PEBs in the @alien list
101 * @bad_peb_count: count of bad physical eraseblocks
102 * @maybe_bad_peb_count: count of bad physical eraseblocks which are not marked
103 * as bad yet, but which look like bad
104 * @vols_found: number of volumes found
105 * @highest_vol_id: highest volume ID
106 * @is_empty: flag indicating whether the MTD device is empty or not
107 * @min_ec: lowest erase counter value
108 * @max_ec: highest erase counter value
109 * @max_sqnum: highest sequence number value
110 * @mean_ec: mean erase counter value
111 * @ec_sum: a temporary variable used when calculating @mean_ec
112 * @ec_count: a temporary variable used when calculating @mean_ec
113 * @scan_leb_slab: slab cache for &struct ubi_ainf_peb objects
115 * This data structure contains the result of attaching an MTD device and may
116 * be used by other UBI sub-systems to build final UBI data structures, further
117 * error-recovery and so on.
119 struct ubi_attach_info {
120 struct rb_root volumes;
121 struct list_head corr;
122 struct list_head free;
123 struct list_head erase;
124 struct list_head alien;
125 int corr_peb_count;
126 int empty_peb_count;
127 int alien_peb_count;
128 int bad_peb_count;
129 int maybe_bad_peb_count;
130 int vols_found;
131 int highest_vol_id;
132 int is_empty;
133 int min_ec;
134 int max_ec;
135 unsigned long long max_sqnum;
136 int mean_ec;
137 uint64_t ec_sum;
138 int ec_count;
139 struct kmem_cache *scan_leb_slab;
142 struct ubi_device;
143 struct ubi_vid_hdr;
146 * ubi_scan_move_to_list - move a PEB from the volume tree to a list.
148 * @av: volume attaching information
149 * @aeb: scanning eraseblock information
150 * @list: the list to move to
152 static inline void ubi_scan_move_to_list(struct ubi_ainf_volume *av,
153 struct ubi_ainf_peb *aeb,
154 struct list_head *list)
156 rb_erase(&aeb->u.rb, &av->root);
157 list_add_tail(&aeb->u.list, list);
160 int ubi_add_to_av(struct ubi_device *ubi, struct ubi_attach_info *ai, int pnum,
161 int ec, const struct ubi_vid_hdr *vid_hdr, int bitflips);
162 struct ubi_ainf_volume *ubi_find_av(const struct ubi_attach_info *ai,
163 int vol_id);
164 void ubi_remove_av(struct ubi_attach_info *ai, struct ubi_ainf_volume *av);
165 struct ubi_ainf_peb *ubi_early_get_peb(struct ubi_device *ubi,
166 struct ubi_attach_info *ai);
167 struct ubi_attach_info *ubi_scan(struct ubi_device *ubi);
168 void ubi_scan_destroy_ai(struct ubi_attach_info *ai);
170 #endif /* !__UBI_SCAN_H__ */