scan.h 6.1 KB
Newer Older
A
Artem B. Bityutskiy 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*
 * Copyright (c) International Business Machines Corp., 2006
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
 * the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 * Author: Artem Bityutskiy (Битюцкий Артём)
 */

#ifndef __UBI_SCAN_H__
#define __UBI_SCAN_H__

/* The erase counter value for this physical eraseblock is unknown */
#define UBI_SCAN_UNKNOWN_EC (-1)

/**
28
 * struct ubi_ainf_peb - attach information about a physical eraseblock.
A
Artem B. Bityutskiy 已提交
29 30 31 32
 * @ec: erase counter (%UBI_SCAN_UNKNOWN_EC if it is unknown)
 * @pnum: physical eraseblock number
 * @lnum: logical eraseblock number
 * @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)
A
Artem B. Bityutskiy 已提交
34 35
 * @sqnum: sequence number
 * @u: unions RB-tree or @list links
36
 * @u.rb: link in the per-volume RB-tree of &struct ubi_ainf_peb objects
A
Artem B. Bityutskiy 已提交
37 38
 * @u.list: link in one of the eraseblock lists
 *
39 40
 * One object of this type is allocated for each physical eraseblock when
 * attaching an MTD device.
A
Artem B. Bityutskiy 已提交
41
 */
42
struct ubi_ainf_peb {
A
Artem B. Bityutskiy 已提交
43 44 45
	int ec;
	int pnum;
	int lnum;
46 47
	unsigned int scrub:1;
	unsigned int copy_flag:1;
A
Artem B. Bityutskiy 已提交
48 49 50 51 52 53 54 55
	unsigned long long sqnum;
	union {
		struct rb_node rb;
		struct list_head list;
	} u;
};

/**
56
 * struct ubi_ainf_volume - attaching information about a volume.
A
Artem B. Bityutskiy 已提交
57 58 59 60 61
 * @vol_id: volume ID
 * @highest_lnum: highest logical eraseblock number in this volume
 * @leb_count: number of logical eraseblocks in this volume
 * @vol_type: volume type
 * @used_ebs: number of used logical eraseblocks in this volume (only for
A
Artem Bityutskiy 已提交
62
 *            static volumes)
A
Artem B. Bityutskiy 已提交
63
 * @last_data_size: amount of data in the last logical eraseblock of this
A
Artem Bityutskiy 已提交
64 65
 *                  volume (always equivalent to the usable logical eraseblock
 *                  size in case of dynamic volumes)
A
Artem B. Bityutskiy 已提交
66
 * @data_pad: how many bytes at the end of logical eraseblocks of this volume
A
Artem Bityutskiy 已提交
67
 *            are not used (due to volume alignment)
A
Artem B. Bityutskiy 已提交
68 69 70
 * @compat: compatibility flags of this volume
 * @rb: link in the volume RB-tree
 * @root: root of the RB-tree containing all the eraseblock belonging to this
71
 *        volume (&struct ubi_ainf_peb objects)
A
Artem B. Bityutskiy 已提交
72
 *
73 74
 * One object of this type is allocated for each volume when attaching an MTD
 * device.
A
Artem B. Bityutskiy 已提交
75
 */
76
struct ubi_ainf_volume {
A
Artem B. Bityutskiy 已提交
77 78 79 80 81 82 83 84 85 86 87 88 89
	int vol_id;
	int highest_lnum;
	int leb_count;
	int vol_type;
	int used_ebs;
	int last_data_size;
	int data_pad;
	int compat;
	struct rb_node rb;
	struct rb_root root;
};

/**
90
 * struct ubi_attach_info - MTD device attaching information.
A
Artem B. Bityutskiy 已提交
91 92 93 94 95
 * @volumes: root of the volume RB-tree
 * @corr: list of corrupted physical eraseblocks
 * @free: list of free physical eraseblocks
 * @erase: list of physical eraseblocks which have to be erased
 * @alien: list of physical eraseblocks which should not be used by UBI (e.g.,
A
Artem Bityutskiy 已提交
96
 *         those belonging to "preserve"-compatible internal volumes)
97
 * @corr_peb_count: count of PEBs in the @corr list
98 99
 * @empty_peb_count: count of PEBs which are presumably empty (contain only
 *                   0xFF bytes)
100
 * @alien_peb_count: count of PEBs in the @alien list
A
Artem B. Bityutskiy 已提交
101
 * @bad_peb_count: count of bad physical eraseblocks
102 103
 * @maybe_bad_peb_count: count of bad physical eraseblocks which are not marked
 *                       as bad yet, but which look like bad
104
 * @vols_found: number of volumes found
A
Artem B. Bityutskiy 已提交
105 106 107 108 109 110 111 112
 * @highest_vol_id: highest volume ID
 * @is_empty: flag indicating whether the MTD device is empty or not
 * @min_ec: lowest erase counter value
 * @max_ec: highest erase counter value
 * @max_sqnum: highest sequence number value
 * @mean_ec: mean erase counter value
 * @ec_sum: a temporary variable used when calculating @mean_ec
 * @ec_count: a temporary variable used when calculating @mean_ec
113
 * @scan_leb_slab: slab cache for &struct ubi_ainf_peb objects
A
Artem B. Bityutskiy 已提交
114
 *
115 116 117
 * This data structure contains the result of attaching an MTD device and may
 * be used by other UBI sub-systems to build final UBI data structures, further
 * error-recovery and so on.
A
Artem B. Bityutskiy 已提交
118
 */
119
struct ubi_attach_info {
A
Artem B. Bityutskiy 已提交
120 121 122 123 124
	struct rb_root volumes;
	struct list_head corr;
	struct list_head free;
	struct list_head erase;
	struct list_head alien;
125
	int corr_peb_count;
126
	int empty_peb_count;
127
	int alien_peb_count;
A
Artem B. Bityutskiy 已提交
128
	int bad_peb_count;
129
	int maybe_bad_peb_count;
A
Artem B. Bityutskiy 已提交
130 131 132 133 134 135 136
	int vols_found;
	int highest_vol_id;
	int is_empty;
	int min_ec;
	int max_ec;
	unsigned long long max_sqnum;
	int mean_ec;
A
Artem Bityutskiy 已提交
137
	uint64_t ec_sum;
A
Artem B. Bityutskiy 已提交
138
	int ec_count;
139
	struct kmem_cache *scan_leb_slab;
A
Artem B. Bityutskiy 已提交
140 141 142 143 144 145
};

struct ubi_device;
struct ubi_vid_hdr;

/*
A
Artem Bityutskiy 已提交
146
 * ubi_scan_move_to_list - move a PEB from the volume tree to a list.
A
Artem B. Bityutskiy 已提交
147 148
 *
 * @sv: volume scanning information
149
 * @seb: scanning eraseblock information
A
Artem B. Bityutskiy 已提交
150 151
 * @list: the list to move to
 */
152
static inline void ubi_scan_move_to_list(struct ubi_ainf_volume *sv,
153
					 struct ubi_ainf_peb *seb,
A
Artem B. Bityutskiy 已提交
154 155 156 157 158 159
					 struct list_head *list)
{
		rb_erase(&seb->u.rb, &sv->root);
		list_add_tail(&seb->u.list, list);
}

160
int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_attach_info *si,
A
Artem B. Bityutskiy 已提交
161 162
		      int pnum, int ec, const struct ubi_vid_hdr *vid_hdr,
		      int bitflips);
163
struct ubi_ainf_volume *ubi_scan_find_sv(const struct ubi_attach_info *si,
A
Artem B. Bityutskiy 已提交
164
					 int vol_id);
165
struct ubi_ainf_peb *ubi_scan_find_seb(const struct ubi_ainf_volume *sv,
A
Artem B. Bityutskiy 已提交
166
				       int lnum);
167
void ubi_scan_rm_volume(struct ubi_attach_info *si, struct ubi_ainf_volume *sv);
168
struct ubi_ainf_peb *ubi_scan_get_free_peb(struct ubi_device *ubi,
169 170
					   struct ubi_attach_info *si);
int ubi_scan_erase_peb(struct ubi_device *ubi, const struct ubi_attach_info *si,
171
		       int pnum, int ec);
172 173
struct ubi_attach_info *ubi_scan(struct ubi_device *ubi);
void ubi_scan_destroy_si(struct ubi_attach_info *si);
A
Artem B. Bityutskiy 已提交
174 175

#endif /* !__UBI_SCAN_H__ */