utils.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright 2019 Google LLC
  4. */
  5. #include <stdbool.h>
  6. #include <sys/stat.h>
  7. #include <include/uapi/linux/incrementalfs.h>
  8. #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
  9. #define __packed __attribute__((__packed__))
  10. #ifdef __LP64__
  11. #define ptr_to_u64(p) ((__u64)p)
  12. #else
  13. #define ptr_to_u64(p) ((__u64)(__u32)p)
  14. #endif
  15. #define SHA256_DIGEST_SIZE 32
  16. #define INCFS_MAX_MTREE_LEVELS 8
  17. unsigned int rnd(unsigned int max, unsigned int *seed);
  18. int remove_dir(const char *dir);
  19. int drop_caches(void);
  20. int mount_fs(const char *mount_dir, const char *backing_dir,
  21. int read_timeout_ms);
  22. int umount_fs(const char *mount_dir);
  23. int mount_fs_opt(const char *mount_dir, const char *backing_dir,
  24. const char *opt, bool remount);
  25. int get_file_bmap(int cmd_fd, int ino, unsigned char *buf, int buf_size);
  26. int get_file_signature(int fd, unsigned char *buf, int buf_size);
  27. int emit_node(int fd, char *filename, int *ino_out, int parent_ino,
  28. size_t size, mode_t mode, char *attr);
  29. int emit_file(int fd, const char *dir, const char *filename,
  30. incfs_uuid_t *id_out, size_t size, const char *attr);
  31. int crypto_emit_file(int fd, const char *dir, const char *filename,
  32. incfs_uuid_t *id_out, size_t size, const char *root_hash,
  33. const char *add_data);
  34. loff_t get_file_size(const char *name);
  35. int open_commands_file(const char *mount_dir);
  36. int open_log_file(const char *mount_dir);
  37. int open_blocks_written_file(const char *mount_dir);
  38. int wait_for_pending_reads(int fd, int timeout_ms,
  39. struct incfs_pending_read_info *prs, int prs_count);
  40. int wait_for_pending_reads2(int fd, int timeout_ms,
  41. struct incfs_pending_read_info2 *prs, int prs_count);
  42. char *concat_file_name(const char *dir, const char *file);
  43. void sha256(const char *data, size_t dsize, char *hash);
  44. void md5(const char *data, size_t dsize, char *hash);
  45. int delete_dir_tree(const char *path);