Signed-off-by: FUJITA Tomonori <fujita.tomonori@xxxxxxxxxxxxx> --- usr/Makefile | 4 ++-- usr/libssc.c | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/usr/Makefile b/usr/Makefile index b0f3b20..7a3ca96 100644 --- a/usr/Makefile +++ b/usr/Makefile @@ -78,12 +78,12 @@ tgtadm: tgtadm.o -include tgtadm.d -mktape: mktape.o libssc.o +mktape: mktape.o libssc.o libcrc32c.o $(CC) $^ -o $@ -include mktape.d libssc.d -dump_tape: dump_tape.o libssc.o +dump_tape: dump_tape.o libssc.o libcrc32c.o $(CC) $^ -o $@ -include dump_tape.d libssc.d diff --git a/usr/libssc.c b/usr/libssc.c index 6ef9517..e13a9f6 100644 --- a/usr/libssc.c +++ b/usr/libssc.c @@ -22,9 +22,11 @@ #include <stdint.h> #include <string.h> #include <unistd.h> +#include <stdio.h> #include "bs_ssc.h" #include "ssc.h" #include "be_byteshift.h" +#include "crc32c.h" #define SSC_1ST_HDR_OFFSET (sizeof(struct MAM) + SSC_BLK_HDR_SIZE) @@ -183,11 +185,17 @@ int ssc_read_blkhdr(int fd, struct blk_header_info *i, off_t offset) { size_t count; struct blk_header h, *m = &h; + uint32_t crc = ~0; count = pread(fd, m, SSC_BLK_HDR_SIZE, offset); if (count != SSC_BLK_HDR_SIZE) return 1; + crc = crc32c(crc, &m->ondisk_sz, SSC_BLK_HDR_SIZE - sizeof(m->h_csum)); + + if (*(uint32_t *)m->h_csum != ~crc) + fprintf(stderr, "crc error\n"); + SSC_GET_MAM_INFO_VAL(ondisk_sz, 32); SSC_GET_MAM_INFO_VAL(blk_sz, 32); SSC_GET_MAM_INFO_VAL(blk_type, 32); @@ -203,6 +211,7 @@ int ssc_write_blkhdr(int fd, struct blk_header_info *i, off_t offset) { size_t count; struct blk_header h, *m = &h; + uint32_t crc = ~0; SSC_PUT_MAM_INFO_VAL(ondisk_sz, 32); SSC_PUT_MAM_INFO_VAL(blk_sz, 32); @@ -212,6 +221,9 @@ int ssc_write_blkhdr(int fd, struct blk_header_info *i, off_t offset) SSC_PUT_MAM_INFO_VAL(curr, 64); SSC_PUT_MAM_INFO_VAL(next, 64); + crc = crc32c(crc, &m->ondisk_sz, SSC_BLK_HDR_SIZE - sizeof(m->h_csum)); + *(uint32_t *)m->h_csum = ~crc; + count = pwrite(fd, m, SSC_BLK_HDR_SIZE, offset); if (count != SSC_BLK_HDR_SIZE) return 1; -- 1.5.6.5 -- To unsubscribe from this list: send the line "unsubscribe stgt" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html