summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaichi Hirono2016-10-27 00:57:55 -0500
committerDaichi Hirono2016-10-27 01:04:15 -0500
commitc6134762975204ceebcf7949e364484833714345 (patch)
treeed01ec85a5175e2985e5e62986500da138d09d1d /libappfuse/include/libappfuse/FuseBuffer.h
parent7f8e819ded361e963df7aa648ca2c6d49c7b46b6 (diff)
downloadplatform-system-core-c6134762975204ceebcf7949e364484833714345.tar.gz
platform-system-core-c6134762975204ceebcf7949e364484833714345.tar.xz
platform-system-core-c6134762975204ceebcf7949e364484833714345.zip
Add FuseBridgeLoop to libappfuse.
The CL adds FuseBridgeLoop class to libappfuse, which is used in the system service to proxy fuse commands to applications. Bug: 29970149 Test: libappfuse_test Change-Id: I0708f608b3868721ab16ba4028fd2c17a6735af7
Diffstat (limited to 'libappfuse/include/libappfuse/FuseBuffer.h')
-rw-r--r--libappfuse/include/libappfuse/FuseBuffer.h89
1 files changed, 89 insertions, 0 deletions
diff --git a/libappfuse/include/libappfuse/FuseBuffer.h b/libappfuse/include/libappfuse/FuseBuffer.h
new file mode 100644
index 000000000..071b77715
--- /dev/null
+++ b/libappfuse/include/libappfuse/FuseBuffer.h
@@ -0,0 +1,89 @@
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_FUSEBUFFER_H_
18#define ANDROID_LIBAPPFUSE_FUSEBUFFER_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[0];
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
74class FuseProxyLoop {
75 class IFuseProxyLoopCallback {
76 public:
77 virtual void OnMount() = 0;
78 virtual ~IFuseProxyLoopCallback() = default;
79 };
80
81 bool Start(int dev_fd, int proxy_fd, IFuseProxyLoopCallback* callback);
82
83 private:
84 FuseBuffer buffer_;
85};
86
87} // namespace android
88
89#endif // ANDROID_LIBAPPFUSE_FUSEBUFFER_H_