Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 329050
b: refs/heads/master
c: 8089ed7
h: refs/heads/master
v: v3
  • Loading branch information
Artem Bityutskiy committed Aug 31, 2012
1 parent 8b6dfb0 commit b9c4461
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 4b3e58a6d6c62b5457ff876fdfc79f66fff04cd2
refs/heads/master: 8089ed792832e5d3dd219da435c5a08d969662b4
20 changes: 11 additions & 9 deletions trunk/fs/ubifs/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -2646,27 +2646,27 @@ static int power_cut_emulated(struct ubifs_info *c, int lnum, int write)
return 1;
}

static void cut_data(const void *buf, unsigned int len)
static int corrupt_data(const struct ubifs_info *c, const void *buf,
unsigned int len)
{
unsigned int from, to, i, ffs = chance(1, 2);
unsigned char *p = (void *)buf;

from = random32() % (len + 1);
if (chance(1, 2))
to = random32() % (len - from + 1);
else
to = len;
/* Corruption may only span one max. write unit */
to = min(len, ALIGN(from, c->max_write_size));

if (from < to)
ubifs_warn("filled bytes %u-%u with %s", from, to - 1,
ffs ? "0xFFs" : "random data");
ubifs_warn("filled bytes %u-%u with %s", from, to - 1,
ffs ? "0xFFs" : "random data");

if (ffs)
for (i = from; i < to; i++)
p[i] = 0xFF;
else
for (i = from; i < to; i++)
p[i] = random32() % 0x100;

return to;
}

int dbg_leb_write(struct ubifs_info *c, int lnum, const void *buf,
Expand All @@ -2679,7 +2679,9 @@ int dbg_leb_write(struct ubifs_info *c, int lnum, const void *buf,

failing = power_cut_emulated(c, lnum, 1);
if (failing)
cut_data(buf, len);
len = corrupt_data(c, buf, len);
ubifs_warn("actually write %d bytes to LEB %d:%d (the buffer was corrupted)",
len, lnum, offs);
err = ubi_leb_write(c->ubi, lnum, buf, offs, len);
if (err)
return err;
Expand Down

0 comments on commit b9c4461

Please sign in to comment.