Skip to content

Commit

Permalink
fs/adfs: map: fix map scanning
Browse files Browse the repository at this point in the history
When scanning the map for a fragment id, we need to keep track of the
free space links, so we don't inadvertently believe that the freespace
link is a valid fragment id.

Signed-off-by: Russell King <[email protected]>
Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
Russell King authored and Al Viro committed Jan 21, 2020
1 parent f6f14a0 commit f93793f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions fs/adfs/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,22 @@ static int lookup_zone(const struct adfs_discmap *dm, const unsigned int idlen,
const u32 idmask = (1 << idlen) - 1;
unsigned char *map = dm->dm_bh->b_data;
unsigned int start = dm->dm_startbit;
unsigned int fragend;
unsigned int freelink, fragend;
u32 frag;

frag = GET_FRAG_ID(map, 8, idmask & 0x7fff);
freelink = frag ? 8 + frag : 0;

do {
frag = GET_FRAG_ID(map, start, idmask);

fragend = find_next_bit_le(map, endbit, start + idlen);
if (fragend >= endbit)
goto error;

if (frag == frag_id) {
if (start == freelink) {
freelink += frag & 0x7fff;
} else if (frag == frag_id) {
unsigned int length = fragend + 1 - start;

if (*offset < length)
Expand Down

0 comments on commit f93793f

Please sign in to comment.