blob: f5ed8dc5f0ff2820cf6a4c7d24f5c72039c59197 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001/* 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
23unsigned int rnd(unsigned int max, unsigned int *seed);
24
25int remove_dir(const char *dir);
26
27int drop_caches(void);
28
29int mount_fs(const char *mount_dir, const char *backing_dir,
30 int read_timeout_ms);
31
32int mount_fs_opt(const char *mount_dir, const char *backing_dir,
33 const char *opt, bool remount);
34
35int get_file_bmap(int cmd_fd, int ino, unsigned char *buf, int buf_size);
36
37int get_file_signature(int fd, unsigned char *buf, int buf_size);
38
39int emit_node(int fd, char *filename, int *ino_out, int parent_ino,
40 size_t size, mode_t mode, char *attr);
41
42int emit_file(int fd, const char *dir, const char *filename,
43 incfs_uuid_t *id_out, size_t size, const char *attr);
44
45int 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
49loff_t get_file_size(const char *name);
50
51int open_commands_file(const char *mount_dir);
52
53int open_log_file(const char *mount_dir);
54
55int open_blocks_written_file(const char *mount_dir);
56
57int wait_for_pending_reads(int fd, int timeout_ms,
58 struct incfs_pending_read_info *prs, int prs_count);
59
60int wait_for_pending_reads2(int fd, int timeout_ms,
61 struct incfs_pending_read_info2 *prs, int prs_count);
62
63char *concat_file_name(const char *dir, const char *file);
64
65void sha256(const char *data, size_t dsize, char *hash);
66
67void md5(const char *data, size_t dsize, char *hash);
68
69int delete_dir_tree(const char *path);