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