summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaichi Hirono2016-11-07 19:17:51 -0600
committerDaichi Hirono2016-11-14 18:47:31 -0600
commita0aecda12b9a76aa15a8c5175e15538574a05af7 (patch)
treeac1e8eda1f03a8922445ae13d6d7a4173158c4ec /libappfuse/FuseBridgeLoop.cc
parentb5ce6f02dd11b42c03884dd9531c6c8a80bcecda (diff)
downloadplatform-system-core-a0aecda12b9a76aa15a8c5175e15538574a05af7.tar.gz
platform-system-core-a0aecda12b9a76aa15a8c5175e15538574a05af7.tar.xz
platform-system-core-a0aecda12b9a76aa15a8c5175e15538574a05af7.zip
Add FuseAppLoop to libappfuse.
The class is used at the app side (StorageManager) to parse FUSE commands. Bug: 32260320 Test: libappfuse_test Change-Id: I1ae2904d3290a041f1efbf8fc10ba032eda5449c
Diffstat (limited to 'libappfuse/FuseBridgeLoop.cc')
-rw-r--r--libappfuse/FuseBridgeLoop.cc25
1 files changed, 17 insertions, 8 deletions
diff --git a/libappfuse/FuseBridgeLoop.cc b/libappfuse/FuseBridgeLoop.cc
index 332556dd1..acb963cfc 100644
--- a/libappfuse/FuseBridgeLoop.cc
+++ b/libappfuse/FuseBridgeLoop.cc
@@ -25,14 +25,15 @@ bool FuseBridgeLoop::Start(
25 int raw_dev_fd, int raw_proxy_fd, FuseBridgeLoop::Callback* callback) { 25 int raw_dev_fd, int raw_proxy_fd, FuseBridgeLoop::Callback* callback) {
26 base::unique_fd dev_fd(raw_dev_fd); 26 base::unique_fd dev_fd(raw_dev_fd);
27 base::unique_fd proxy_fd(raw_proxy_fd); 27 base::unique_fd proxy_fd(raw_proxy_fd);
28 fuse::FuseBuffer buffer;
28 29
29 LOG(DEBUG) << "Start fuse loop."; 30 LOG(DEBUG) << "Start fuse loop.";
30 while (true) { 31 while (true) {
31 if (!buffer_.request.Read(dev_fd)) { 32 if (!buffer.request.Read(dev_fd)) {
32 return false; 33 return false;
33 } 34 }
34 35
35 const uint32_t opcode = buffer_.request.header.opcode; 36 const uint32_t opcode = buffer.request.header.opcode;
36 LOG(VERBOSE) << "Read a fuse packet, opcode=" << opcode; 37 LOG(VERBOSE) << "Read a fuse packet, opcode=" << opcode;
37 switch (opcode) { 38 switch (opcode) {
38 case FUSE_FORGET: 39 case FUSE_FORGET:
@@ -45,27 +46,27 @@ bool FuseBridgeLoop::Start(
45 case FUSE_READ: 46 case FUSE_READ:
46 case FUSE_WRITE: 47 case FUSE_WRITE:
47 case FUSE_RELEASE: 48 case FUSE_RELEASE:
48 case FUSE_FLUSH: 49 case FUSE_FSYNC:
49 if (!buffer_.request.Write(proxy_fd)) { 50 if (!buffer.request.Write(proxy_fd)) {
50 LOG(ERROR) << "Failed to write a request to the proxy."; 51 LOG(ERROR) << "Failed to write a request to the proxy.";
51 return false; 52 return false;
52 } 53 }
53 if (!buffer_.response.Read(proxy_fd)) { 54 if (!buffer.response.Read(proxy_fd)) {
54 LOG(ERROR) << "Failed to read a response from the proxy."; 55 LOG(ERROR) << "Failed to read a response from the proxy.";
55 return false; 56 return false;
56 } 57 }
57 break; 58 break;
58 59
59 case FUSE_INIT: 60 case FUSE_INIT:
60 buffer_.HandleInit(); 61 buffer.HandleInit();
61 break; 62 break;
62 63
63 default: 64 default:
64 buffer_.HandleNotImpl(); 65 buffer.HandleNotImpl();
65 break; 66 break;
66 } 67 }
67 68
68 if (!buffer_.response.Write(dev_fd)) { 69 if (!buffer.response.Write(dev_fd)) {
69 LOG(ERROR) << "Failed to write a response to the device."; 70 LOG(ERROR) << "Failed to write a response to the device.";
70 return false; 71 return false;
71 } 72 }
@@ -76,4 +77,12 @@ bool FuseBridgeLoop::Start(
76 } 77 }
77} 78}
78 79
80namespace fuse {
81
82bool StartFuseBridgeLoop(
83 int raw_dev_fd, int raw_proxy_fd, FuseBridgeLoopCallback* callback) {
84 return FuseBridgeLoop().Start(raw_dev_fd, raw_proxy_fd, callback);
85}
86
87} // namespace fuse
79} // namespace android 88} // namespace android