/* * calc_chksums calculates the checksums for the blocks described in the * descriptor block. */ static int calc_chksums(journal_t *journal, struct buffer_head *bh, unsigned long long *next_log_block, __u32 *crc32_sum) { int i, num_blks, err; unsigned long long io_block; struct buffer_head *obh; num_blks = count_tags(journal, bh); /* Calculate checksum of the descriptor block. */ *crc32_sum = crc32_be(*crc32_sum, (void *)bh->b_data, bh->b_size); for (i = 0; i < num_blks; i++) { io_block = (*next_log_block)++; wrap(journal, *next_log_block); err = jread(&obh, journal, io_block); if (err) { printk(KERN_ERR "JBD: IO error %d recovering block " "%llu in log\n", err, io_block); return 1; } else { *crc32_sum = crc32_be(*crc32_sum, (void *)obh->b_data, obh->b_size); } brelse(obh); } return 0; }
static inline __u32 iov_crc32( __u32 c, struct kvec *iov, unsigned int cnt ) { unsigned int j; for (j = 0; j < cnt; j++) c = crc32_be( c, iov[j].iov_base, iov[j].iov_len ); return c; }
int main(int argc, char *argv[]) { int i; int ch; int fd; struct stat buf; unsigned char *buffer_read; unsigned char *opt; /*wangyu modify :in 32bit system or 64bit system the unsigned int datasize is 4 bytes*/ unsigned int crc; /*wangyu modify end*/ if (argc != 2) { printf("usage: crc file_name\n"); return -1; } buffer_read = (unsigned char *)malloc(BUFFER_SIZE); if (buffer_read == NULL) { printf("malloc buffer error\n"); return -1; } int result = stat(argv[1], &buf); printf("file lenth=%d\n", (int)buf.st_size); fd = open(argv[1], O_RDWR, 0666); if (fd < 0) { printf("open file error\n"); free(buffer_read); return -1; } memset(buffer_read, 0, BUFFER_SIZE); read(fd, buffer_read, BUFFER_SIZE); lseek(fd, 0, SEEK_SET); opt = (unsigned char *)buffer_read; crc = crc32_be(0, opt, buf.st_size); printf("crc=%u\n", crc);//wangyu change uint type print to %u printf("char name=%s\n", argv[1]); free(buffer_read); close(fd); return 0; }
static u32 dvb_dmx_crc32 (struct dvb_demux_feed *f, const u8 *src, size_t len) { return (f->feed.sec.crc_val = crc32_be (f->feed.sec.crc_val, src, len)); }
struct qnx6_super_block *qnx6_mmi_fill_super(struct super_block *s, int silent) { struct buffer_head *bh1, *bh2 = NULL; struct qnx6_mmi_super_block *sb1, *sb2; struct qnx6_super_block *qsb = NULL; struct qnx6_sb_info *sbi; __u64 offset; bh1 = sb_bread(s, 0); if (!bh1) { printk(KERN_ERR "qnx6: Unable to read first mmi superblock\n"); return NULL; } sb1 = (struct qnx6_mmi_super_block *)bh1->b_data; sbi = QNX6_SB(s); if (fs32_to_cpu(sbi, sb1->sb_magic) != QNX6_SUPER_MAGIC) { if (!silent) { printk(KERN_ERR "qnx6: wrong signature (magic) in" " superblock #1.\n"); goto out; } } if (fs32_to_cpu(sbi, sb1->sb_checksum) != crc32_be(0, (char *)(bh1->b_data + 8), 504)) { printk(KERN_ERR "qnx6: superblock #1 checksum error\n"); goto out; } offset = fs32_to_cpu(sbi, sb1->sb_num_blocks) + QNX6_SUPERBLOCK_AREA / fs32_to_cpu(sbi, sb1->sb_blocksize); if (!sb_set_blocksize(s, fs32_to_cpu(sbi, sb1->sb_blocksize))) { printk(KERN_ERR "qnx6: unable to set blocksize\n"); goto out; } brelse(bh1); bh1 = sb_bread(s, 0); if (!bh1) goto out; sb1 = (struct qnx6_mmi_super_block *)bh1->b_data; bh2 = sb_bread(s, offset); if (!bh2) { printk(KERN_ERR "qnx6: unable to read the second superblock\n"); goto out; } sb2 = (struct qnx6_mmi_super_block *)bh2->b_data; if (fs32_to_cpu(sbi, sb2->sb_magic) != QNX6_SUPER_MAGIC) { if (!silent) printk(KERN_ERR "qnx6: wrong signature (magic) in" " superblock #2.\n"); goto out; } if (fs32_to_cpu(sbi, sb2->sb_checksum) != crc32_be(0, (char *)(bh2->b_data + 8), 504)) { printk(KERN_ERR "qnx6: superblock #1 checksum error\n"); goto out; } qsb = kmalloc(sizeof(*qsb), GFP_KERNEL); if (!qsb) { printk(KERN_ERR "qnx6: unable to allocate memory.\n"); goto out; } if (fs64_to_cpu(sbi, sb1->sb_serial) > fs64_to_cpu(sbi, sb2->sb_serial)) { qnx6_mmi_copy_sb(qsb, sb1); #ifdef CONFIG_QNX6FS_DEBUG qnx6_superblock_debug(qsb, s); #endif memcpy(bh1->b_data, qsb, sizeof(struct qnx6_super_block)); sbi->sb_buf = bh1; sbi->sb = (struct qnx6_super_block *)bh1->b_data; brelse(bh2); printk(KERN_INFO "qnx6: superblock #1 active\n"); } else { qnx6_mmi_copy_sb(qsb, sb2); #ifdef CONFIG_QNX6FS_DEBUG qnx6_superblock_debug(qsb, s); #endif memcpy(bh2->b_data, qsb, sizeof(struct qnx6_super_block)); sbi->sb_buf = bh2; sbi->sb = (struct qnx6_super_block *)bh2->b_data; brelse(bh1); printk(KERN_INFO "qnx6: superblock #2 active\n"); } kfree(qsb); sbi->s_blks_off = QNX6_SUPERBLOCK_AREA / s->s_blocksize; return sbi->sb; out: if (bh1 != NULL) brelse(bh1); if (bh2 != NULL) brelse(bh2); return NULL; }