summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'libappfuse/include/libappfuse/AppFuse.h')
-rw-r--r--libappfuse/include/libappfuse/AppFuse.h76
1 files changed, 76 insertions, 0 deletions
diff --git a/libappfuse/include/libappfuse/AppFuse.h b/libappfuse/include/libappfuse/AppFuse.h
new file mode 100644
index 000000000..b6af48d78
--- /dev/null
+++ b/libappfuse/include/libappfuse/AppFuse.h
@@ -0,0 +1,76 @@
1/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specic language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_LIBAPPFUSE_APPFUSE_H_
18#define ANDROID_LIBAPPFUSE_APPFUSE_H_
19
20#include <linux/fuse.h>
21
22namespace android {
23
24// The numbers came from sdcard.c.
25// Maximum number of bytes to write/read in one request/one reply.
26constexpr size_t kFuseMaxWrite = 256 * 1024;
27constexpr size_t kFuseMaxRead = 128 * 1024;
28constexpr int32_t kFuseSuccess = 0;
29
30template<typename T, typename Header>
31struct FuseMessage {
32 Header header;
33 bool Read(int fd);
34 bool Write(int fd) const;
35 private:
36 bool CheckHeaderLength() const;
37 bool CheckResult(int result, const char* operation_name) const;
38};
39
40struct FuseRequest : public FuseMessage<FuseRequest, fuse_in_header> {
41 union {
42 struct {
43 fuse_write_in write_in;
44 char write_data[kFuseMaxWrite];
45 };
46 fuse_open_in open_in;
47 fuse_init_in init_in;
48 fuse_read_in read_in;
49 char lookup_name[];
50 };
51};
52
53struct FuseResponse : public FuseMessage<FuseResponse, fuse_out_header> {
54 union {
55 fuse_init_out init_out;
56 fuse_entry_out entry_out;
57 fuse_attr_out attr_out;
58 fuse_open_out open_out;
59 char read_data[kFuseMaxRead];
60 fuse_write_out write_out;
61 };
62 void Reset(uint32_t data_length, int32_t error, uint64_t unique);
63 void ResetHeader(uint32_t data_length, int32_t error, uint64_t unique);
64};
65
66union FuseBuffer {
67 FuseRequest request;
68 FuseResponse response;
69
70 void HandleInit();
71 void HandleNotImpl();
72};
73
74} // namespace android
75
76#endif // ANDROID_LIBAPPFUSE_APPFUSE_H_