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 umount_fs(const char *mount_dir); 33 34 int mount_fs_opt(const char *mount_dir, const char *backing_dir, 35 const char *opt, bool remount); 36 37 int get_file_bmap(int cmd_fd, int ino, unsigned char *buf, int buf_size); 38 39 int get_file_signature(int fd, unsigned char *buf, int buf_size); 40 41 int emit_node(int fd, char *filename, int *ino_out, int parent_ino, 42 size_t size, mode_t mode, char *attr); 43 44 int emit_file(int fd, const char *dir, const char *filename, 45 incfs_uuid_t *id_out, size_t size, const char *attr); 46 47 int crypto_emit_file(int fd, const char *dir, const char *filename, 48 incfs_uuid_t *id_out, size_t size, const char *root_hash, 49 const char *add_data); 50 51 loff_t get_file_size(const char *name); 52 53 int open_commands_file(const char *mount_dir); 54 55 int open_log_file(const char *mount_dir); 56 57 int open_blocks_written_file(const char *mount_dir); 58 59 int wait_for_pending_reads(int fd, int timeout_ms, 60 struct incfs_pending_read_info *prs, int prs_count); 61 62 int wait_for_pending_reads2(int fd, int timeout_ms, 63 struct incfs_pending_read_info2 *prs, int prs_count); 64 65 char *concat_file_name(const char *dir, const char *file); 66 67 void sha256(const char *data, size_t dsize, char *hash); 68 69 void md5(const char *data, size_t dsize, char *hash); 70 71 int delete_dir_tree(const char *path); 72