Skip to content

Commit 1f81a5c

Browse files
Boris Brezillonrichardweinberger
authored andcommitted
UBI: provide an helper to query LEB information
This is part of our attempt to hide EBA internals from other part of the implementation in order to easily adapt it to the MLC needs. Here we are creating an ubi_eba_leb_desc struct to hide the way we keep track of the LEB to PEB mapping. Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> Signed-off-by: Richard Weinberger <richard@nod.at>
1 parent 7554769 commit 1f81a5c

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

drivers/mtd/ubi/eba.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,23 @@ static int ubi_get_compat(const struct ubi_device *ubi, int vol_id)
8383
return 0;
8484
}
8585

86+
/**
87+
* ubi_eba_get_ldesc - get information about a LEB
88+
* @vol: volume description object
89+
* @lnum: logical eraseblock number
90+
* @ldesc: the LEB descriptor to fill
91+
*
92+
* Used to query information about a specific LEB.
93+
* It is currently only returning the physical position of the LEB, but will be
94+
* extended to provide more information.
95+
*/
96+
void ubi_eba_get_ldesc(struct ubi_volume *vol, int lnum,
97+
struct ubi_eba_leb_desc *ldesc)
98+
{
99+
ldesc->lnum = lnum;
100+
ldesc->pnum = vol->eba_tbl[lnum];
101+
}
102+
86103
/**
87104
* ltree_lookup - look up the lock tree.
88105
* @ubi: UBI device description object

drivers/mtd/ubi/fastmap.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,8 +1257,12 @@ static int ubi_write_fastmap(struct ubi_device *ubi,
12571257
fm_pos += sizeof(*feba) + (sizeof(__be32) * vol->reserved_pebs);
12581258
ubi_assert(fm_pos <= ubi->fm_size);
12591259

1260-
for (j = 0; j < vol->reserved_pebs; j++)
1261-
feba->pnum[j] = cpu_to_be32(vol->eba_tbl[j]);
1260+
for (j = 0; j < vol->reserved_pebs; j++) {
1261+
struct ubi_eba_leb_desc ldesc;
1262+
1263+
ubi_eba_get_ldesc(vol, j, &ldesc);
1264+
feba->pnum[j] = cpu_to_be32(ldesc.pnum);
1265+
}
12621266

12631267
feba->reserved_pebs = cpu_to_be32(j);
12641268
feba->magic = cpu_to_be32(UBI_FM_EBA_MAGIC);

drivers/mtd/ubi/ubi.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,21 @@ struct ubi_fm_pool {
266266
int max_size;
267267
};
268268

269+
/**
270+
* struct ubi_eba_leb_desc - EBA logical eraseblock descriptor
271+
* @lnum: the logical eraseblock number
272+
* @pnum: the physical eraseblock where the LEB can be found
273+
*
274+
* This structure is here to hide EBA's internal from other part of the
275+
* UBI implementation.
276+
*
277+
* One can query the position of a LEB by calling ubi_eba_get_ldesc().
278+
*/
279+
struct ubi_eba_leb_desc {
280+
int lnum;
281+
int pnum;
282+
};
283+
269284
/**
270285
* struct ubi_volume - UBI volume description data structure.
271286
* @dev: device object to make use of the the Linux device model
@@ -849,6 +864,8 @@ static inline bool ubi_leb_valid(struct ubi_volume *vol, int lnum)
849864
}
850865

851866
/* eba.c */
867+
void ubi_eba_get_ldesc(struct ubi_volume *vol, int lnum,
868+
struct ubi_eba_leb_desc *ldesc);
852869
bool ubi_eba_is_mapped(struct ubi_volume *vol, int lnum);
853870
int ubi_eba_unmap_leb(struct ubi_device *ubi, struct ubi_volume *vol,
854871
int lnum);

0 commit comments

Comments
 (0)