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/FuseBridgeLoop.cc
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/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