disk-io.c 543 B

12345678910111213141516171819202122
  1. // SPDX-License-Identifier: GPL-2.0+
  2. #include <common.h>
  3. #include <fs_internal.h>
  4. #include "disk-io.h"
  5. #include "crypto/hash.h"
  6. int btrfs_csum_data(u16 csum_type, const u8 *data, u8 *out, size_t len)
  7. {
  8. memset(out, 0, BTRFS_CSUM_SIZE);
  9. switch (csum_type) {
  10. case BTRFS_CSUM_TYPE_CRC32:
  11. return hash_crc32c(data, len, out);
  12. case BTRFS_CSUM_TYPE_XXHASH:
  13. return hash_xxhash(data, len, out);
  14. case BTRFS_CSUM_TYPE_SHA256:
  15. return hash_sha256(data, len, out);
  16. default:
  17. printf("Unknown csum type %d\n", csum_type);
  18. return -EINVAL;
  19. }
  20. }