summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTreehugger Robot2016-10-31 01:09:31 -0500
committerGerrit Code Review2016-10-31 01:09:32 -0500
commitb5ce6f02dd11b42c03884dd9531c6c8a80bcecda (patch)
treeebdbb0f298a8ea42a05bbd8776814e3353a1ca50 /libappfuse/FuseBridgeLoop.cc
parentcd368c640a68ac247f2ee32fd433c9522675c187 (diff)
parentc6134762975204ceebcf7949e364484833714345 (diff)
downloadplatform-system-core-b5ce6f02dd11b42c03884dd9531c6c8a80bcecda.tar.gz
platform-system-core-b5ce6f02dd11b42c03884dd9531c6c8a80bcecda.tar.xz
platform-system-core-b5ce6f02dd11b42c03884dd9531c6c8a80bcecda.zip
Merge "Add FuseBridgeLoop to libappfuse."
Diffstat (limited to 'libappfuse/FuseBridgeLoop.cc')
-rw-r--r--libappfuse/FuseBridgeLoop.cc79
1 files changed, 79 insertions, 0 deletions
diff --git a/libappfuse/FuseBridgeLoop.cc b/libappfuse/FuseBridgeLoop.cc
new file mode 100644
index 000000000..332556dd1
--- /dev/null
+++ b/libappfuse/FuseBridgeLoop.cc
@@ -0,0 +1,79 @@
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#include "libappfuse/FuseBridgeLoop.h"
18
19#include <android-base/logging.h>
20#include <android-base/unique_fd.h>
21
22namespace android {
23
24bool FuseBridgeLoop::Start(
25 int raw_dev_fd, int raw_proxy_fd, FuseBridgeLoop::Callback* callback) {
26 base::unique_fd dev_fd(raw_dev_fd);
27 base::unique_fd proxy_fd(raw_proxy_fd);
28
29 LOG(DEBUG) << "Start fuse loop.";
30 while (true) {
31 if (!buffer_.request.Read(dev_fd)) {
32 return false;
33 }
34
35 const uint32_t opcode = buffer_.request.header.opcode;
36 LOG(VERBOSE) << "Read a fuse packet, opcode=" << opcode;
37 switch (opcode) {
38 case FUSE_FORGET:
39 // Do not reply to FUSE_FORGET.
40 continue;
41
42 case FUSE_LOOKUP:
43 case FUSE_GETATTR:
44 case FUSE_OPEN:
45 case FUSE_READ:
46 case FUSE_WRITE:
47 case FUSE_RELEASE:
48 case FUSE_FLUSH:
49 if (!buffer_.request.Write(proxy_fd)) {
50 LOG(ERROR) << "Failed to write a request to the proxy.";
51 return false;
52 }
53 if (!buffer_.response.Read(proxy_fd)) {
54 LOG(ERROR) << "Failed to read a response from the proxy.";
55 return false;
56 }
57 break;
58
59 case FUSE_INIT:
60 buffer_.HandleInit();
61 break;
62
63 default:
64 buffer_.HandleNotImpl();
65 break;
66 }
67
68 if (!buffer_.response.Write(dev_fd)) {
69 LOG(ERROR) << "Failed to write a response to the device.";
70 return false;
71 }
72
73 if (opcode == FUSE_INIT) {
74 callback->OnMount();
75 }
76 }
77}
78
79} // namespace android