• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause WITH Linux-syscall-note */
2 /* Copyright (c) 2022 Google LLC */
3 
4 #ifndef _LINUX_ANDROID_FUSE_H
5 #define _LINUX_ANDROID_FUSE_H
6 
7 #ifdef __KERNEL__
8 #include <linux/types.h>
9 #else
10 #include <stdint.h>
11 #endif
12 
13 #define FUSE_ACTION_KEEP	0
14 #define FUSE_ACTION_REMOVE	1
15 #define FUSE_ACTION_REPLACE	2
16 
17 struct fuse_entry_bpf_out {
18 	uint64_t	backing_action;
19 	uint64_t	backing_fd;
20 	uint64_t	bpf_action;
21 	uint64_t	bpf_fd;
22 };
23 
24 struct fuse_entry_bpf {
25 	struct fuse_entry_bpf_out out;
26 	struct file *backing_file;
27 	struct file *bpf_file;
28 };
29 
30 struct fuse_read_out {
31 	uint64_t	offset;
32 	uint32_t	again;
33 	uint32_t	padding;
34 };
35 
36 struct fuse_in_postfilter_header {
37 	uint32_t	len;
38 	uint32_t	opcode;
39 	uint64_t	unique;
40 	uint64_t	nodeid;
41 	uint32_t	uid;
42 	uint32_t	gid;
43 	uint32_t	pid;
44 	uint32_t	error_in;
45 };
46 
47 /*
48  * Fuse BPF Args
49  *
50  * Used to communicate with bpf programs to allow checking or altering certain values.
51  * The end_offset allows the bpf verifier to check boundaries statically. This reflects
52  * the ends of the buffer. size shows the length that was actually used.
53  *
54  */
55 
56 /** One input argument of a request */
57 struct fuse_bpf_in_arg {
58 	uint32_t size;
59 	uint32_t padding;
60 	union {
61 		const void *value;
62 		uint64_t padding2;
63 	};
64 	union {
65 		const void *end_offset;
66 		uint64_t padding3;
67 	};
68 };
69 
70 /** One output argument of a request */
71 struct fuse_bpf_arg {
72 	uint32_t size;
73 	uint32_t padding;
74 	union {
75 		void *value;
76 		uint64_t padding2;
77 	};
78 	union {
79 		void *end_offset;
80 		uint64_t padding3;
81 	};
82 };
83 
84 #define FUSE_MAX_IN_ARGS 5
85 #define FUSE_MAX_OUT_ARGS 3
86 
87 #define FUSE_BPF_FORCE (1 << 0)
88 #define FUSE_BPF_OUT_ARGVAR (1 << 6)
89 
90 struct fuse_bpf_args {
91 	uint64_t nodeid;
92 	uint32_t opcode;
93 	uint32_t error_in;
94 	uint32_t in_numargs;
95 	uint32_t out_numargs;
96 	uint32_t flags;
97 	uint32_t padding;
98 	struct fuse_bpf_in_arg in_args[FUSE_MAX_IN_ARGS];
99 	struct fuse_bpf_arg out_args[FUSE_MAX_OUT_ARGS];
100 };
101 
102 #define FUSE_BPF_USER_FILTER	1
103 #define FUSE_BPF_BACKING	2
104 #define FUSE_BPF_POST_FILTER	4
105 
106 #define FUSE_OPCODE_FILTER	0x0ffff
107 #define FUSE_PREFILTER		0x10000
108 #define FUSE_POSTFILTER		0x20000
109 
110 struct bpf_prog *fuse_get_bpf_prog(struct file *file);
111 
112 #endif  /* _LINUX_ANDROID_FUSE_H */
113