aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafał Miłecki <zajec5@gmail.com>2016-05-09 18:10:30 +0000
committerLuka Perkov <luka@openwrt.org>2016-06-19 19:24:14 +0200
commit5a5787d877400eb83809ea5dc9af5e9fccc5b986 (patch)
tree10c6b086e42988abd3382658f9e205a0ff91d9e5
parent0af265171b9ba732ca8b49b4c34289146be7a167 (diff)
downloadmaster-187ad058-5a5787d877400eb83809ea5dc9af5e9fccc5b986.tar.gz
master-187ad058-5a5787d877400eb83809ea5dc9af5e9fccc5b986.tar.bz2
master-187ad058-5a5787d877400eb83809ea5dc9af5e9fccc5b986.zip
mtd: trx: use separated buffer for TRX header
We plan to adjust usage of the main buffer to allow reading custom amount of data for CRC32. This means we need another buffer that will be always block aligned. Signed-off-by: Rafał Miłecki <zajec5@gmail.com> git-svn-id: svn://svn.openwrt.org/openwrt/trunk@49316 3c298f89-4303-0410-b956-a3cf2f4a3e73
-rw-r--r--package/system/mtd/src/trx.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/package/system/mtd/src/trx.c b/package/system/mtd/src/trx.c
index 00c4d6c0b5..f310f51087 100644
--- a/package/system/mtd/src/trx.c
+++ b/package/system/mtd/src/trx.c
@@ -152,6 +152,7 @@ mtd_fixtrx(const char *mtd, size_t offset)
{
int fd;
struct trx_header *trx;
+ char *first_block;
char *buf;
ssize_t res;
size_t block_offset;
@@ -173,19 +174,19 @@ mtd_fixtrx(const char *mtd, size_t offset)
exit(1);
}
- buf = malloc(erasesize);
- if (!buf) {
+ first_block = malloc(erasesize);
+ if (!first_block) {
perror("malloc");
exit(1);
}
- res = pread(fd, buf, erasesize, block_offset);
+ res = pread(fd, first_block, erasesize, block_offset);
if (res != erasesize) {
perror("pread");
exit(1);
}
- trx = (struct trx_header *) (buf + offset);
+ trx = (struct trx_header *)(first_block + offset);
if (trx->magic != STORE32_LE(0x30524448)) {
fprintf(stderr, "No trx magic found\n");
exit(1);
@@ -198,6 +199,18 @@ mtd_fixtrx(const char *mtd, size_t offset)
return 0;
}
+ buf = malloc(erasesize);
+ if (!buf) {
+ perror("malloc");
+ exit(1);
+ }
+
+ res = pread(fd, buf, erasesize, block_offset);
+ if (res != erasesize) {
+ perror("pread");
+ exit(1);
+ }
+
trx->len = STORE32_LE(erasesize - offset);
trx->crc32 = STORE32_LE(crc32buf((char*) &trx->flag_version, erasesize - offset - 3*4));
@@ -209,7 +222,7 @@ mtd_fixtrx(const char *mtd, size_t offset)
if (quiet < 2)
fprintf(stderr, "New crc32: 0x%x, rewriting block\n", trx->crc32);
- if (pwrite(fd, buf, erasesize, block_offset) != erasesize) {
+ if (pwrite(fd, first_block, erasesize, block_offset) != erasesize) {
fprintf(stderr, "Error writing block (%s)\n", strerror(errno));
exit(1);
}