void nffs_crc_disk_block_fill(struct nffs_disk_block *disk_block, const void *data) { uint16_t crc16; crc16 = nffs_crc_disk_block_hdr(disk_block); crc16 = crc16_ccitt(crc16, data, disk_block->ndb_data_len); disk_block->ndb_crc16 = crc16; }
static int nffs_write_fill_crc16_overwrite(struct nffs_disk_block *disk_block, uint8_t src_area_idx, uint32_t src_area_offset, uint16_t left_copy_len, uint16_t right_copy_len, const void *new_data, uint16_t new_data_len) { uint16_t block_off; uint16_t crc16; int rc; block_off = 0; crc16 = nffs_crc_disk_block_hdr(disk_block); block_off += sizeof *disk_block; /* Copy data from the start of the old block, in case the new data starts * at a non-zero offset. */ if (left_copy_len > 0) { rc = nffs_crc_flash(crc16, src_area_idx, src_area_offset + block_off, left_copy_len, &crc16); if (rc != 0) { return rc; } block_off += left_copy_len; } /* Write the new data into the data block. This may extend the block's * length beyond its old value. */ crc16 = crc16_ccitt(crc16, new_data, new_data_len); block_off += new_data_len; /* Copy data from the end of the old block, in case the new data doesn't * extend to the end of the block. */ if (right_copy_len > 0) { rc = nffs_crc_flash(crc16, src_area_idx, src_area_offset + block_off, right_copy_len, &crc16); if (rc != 0) { return rc; } block_off += right_copy_len; } assert(block_off == sizeof *disk_block + disk_block->ndb_data_len); disk_block->ndb_crc16 = crc16; return 0; }
static int nffs_crc_disk_block(const struct nffs_disk_block *disk_block, uint8_t area_idx, uint32_t area_offset, uint16_t *out_crc) { uint16_t crc; int rc; crc = nffs_crc_disk_block_hdr(disk_block); rc = nffs_crc_flash(crc, area_idx, area_offset + sizeof *disk_block, disk_block->ndb_data_len, &crc); if (rc != 0) { return rc; } *out_crc = crc; return 0; }