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/include/libappfuse
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/include/libappfuse')
-rw-r--r--libappfuse/include/libappfuse/FuseAppLoop.h44
-rw-r--r--libappfuse/include/libappfuse/FuseBridgeLoop.h14
-rw-r--r--libappfuse/include/libappfuse/FuseBuffer.h39
3 files changed, 77 insertions, 20 deletions
diff --git a/libappfuse/include/libappfuse/FuseAppLoop.h b/libappfuse/include/libappfuse/FuseAppLoop.h
new file mode 100644
index 000000000..c3edfcc32
--- /dev/null
+++ b/libappfuse/include/libappfuse/FuseAppLoop.h
@@ -0,0 +1,44 @@
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_FUSEAPPLOOP_H_
18#define ANDROID_LIBAPPFUSE_FUSEAPPLOOP_H_
19
20#include "libappfuse/FuseBuffer.h"
21
22namespace android {
23namespace fuse {
24
25class FuseAppLoopCallback {
26 public:
27 virtual bool IsActive() = 0;
28 virtual int64_t OnGetSize(uint64_t inode) = 0;
29 virtual int32_t OnFsync(uint64_t inode) = 0;
30 virtual int32_t OnWrite(
31 uint64_t inode, uint64_t offset, uint32_t size, const void* data) = 0;
32 virtual int32_t OnRead(
33 uint64_t inode, uint64_t offset, uint32_t size, void* data) = 0;
34 virtual int32_t OnOpen(uint64_t inode) = 0;
35 virtual int32_t OnRelease(uint64_t inode) = 0;
36 virtual ~FuseAppLoopCallback() = default;
37};
38
39bool StartFuseAppLoop(int fd, FuseAppLoopCallback* callback);
40
41} // namespace fuse
42} // namespace android
43
44#endif // ANDROID_LIBAPPFUSE_FUSEAPPLOOP_H_
diff --git a/libappfuse/include/libappfuse/FuseBridgeLoop.h b/libappfuse/include/libappfuse/FuseBridgeLoop.h
index 200653252..38043bce7 100644
--- a/libappfuse/include/libappfuse/FuseBridgeLoop.h
+++ b/libappfuse/include/libappfuse/FuseBridgeLoop.h
@@ -21,7 +21,9 @@
21 21
22namespace android { 22namespace android {
23 23
24class FuseBridgeLoop { 24// TODO: Remove the class after switching to StartFuseBridgeLoop in the
25// framework code.
26class FuseBridgeLoop final {
25 public: 27 public:
26 class Callback { 28 class Callback {
27 public: 29 public:
@@ -30,11 +32,15 @@ class FuseBridgeLoop {
30 }; 32 };
31 33
32 bool Start(int dev_fd, int proxy_fd, Callback* callback); 34 bool Start(int dev_fd, int proxy_fd, Callback* callback);
33
34 private:
35 FuseBuffer buffer_;
36}; 35};
37 36
37namespace fuse {
38
39class FuseBridgeLoopCallback : public FuseBridgeLoop::Callback {};
40bool StartFuseBridgeLoop(
41 int dev_fd, int proxy_fd, FuseBridgeLoopCallback* callback);
42
43} // namespace fuse
38} // namespace android 44} // namespace android
39 45
40#endif // ANDROID_LIBAPPFUSE_FUSEBRIDGELOOP_H_ 46#endif // ANDROID_LIBAPPFUSE_FUSEBRIDGELOOP_H_
diff --git a/libappfuse/include/libappfuse/FuseBuffer.h b/libappfuse/include/libappfuse/FuseBuffer.h
index 071b77715..1464142c4 100644
--- a/libappfuse/include/libappfuse/FuseBuffer.h
+++ b/libappfuse/include/libappfuse/FuseBuffer.h
@@ -20,6 +20,7 @@
20#include <linux/fuse.h> 20#include <linux/fuse.h>
21 21
22namespace android { 22namespace android {
23namespace fuse {
23 24
24// The numbers came from sdcard.c. 25// The numbers came from sdcard.c.
25// Maximum number of bytes to write/read in one request/one reply. 26// Maximum number of bytes to write/read in one request/one reply.
@@ -37,33 +38,51 @@ struct FuseMessage {
37 bool CheckResult(int result, const char* operation_name) const; 38 bool CheckResult(int result, const char* operation_name) const;
38}; 39};
39 40
40struct FuseRequest : public FuseMessage<FuseRequest, fuse_in_header> { 41// FuseRequest represents file operation requests from /dev/fuse. It starts
42// from fuse_in_header. The body layout depends on the operation code.
43struct FuseRequest final : public FuseMessage<FuseRequest, fuse_in_header> {
41 union { 44 union {
45 // for FUSE_WRITE
42 struct { 46 struct {
43 fuse_write_in write_in; 47 fuse_write_in write_in;
44 char write_data[kFuseMaxWrite]; 48 char write_data[kFuseMaxWrite];
45 }; 49 };
50 // for FUSE_OPEN
46 fuse_open_in open_in; 51 fuse_open_in open_in;
52 // for FUSE_INIT
47 fuse_init_in init_in; 53 fuse_init_in init_in;
54 // for FUSE_READ
48 fuse_read_in read_in; 55 fuse_read_in read_in;
56 // for FUSE_LOOKUP
49 char lookup_name[0]; 57 char lookup_name[0];
50 }; 58 };
59 void Reset(uint32_t data_length, uint32_t opcode, uint64_t unique);
51}; 60};
52 61
53struct FuseResponse : public FuseMessage<FuseResponse, fuse_out_header> { 62// FuseResponse represents file operation responses to /dev/fuse. It starts
63// from fuse_out_header. The body layout depends on the operation code.
64struct FuseResponse final : public FuseMessage<FuseResponse, fuse_out_header> {
54 union { 65 union {
66 // for FUSE_INIT
55 fuse_init_out init_out; 67 fuse_init_out init_out;
68 // for FUSE_LOOKUP
56 fuse_entry_out entry_out; 69 fuse_entry_out entry_out;
70 // for FUSE_GETATTR
57 fuse_attr_out attr_out; 71 fuse_attr_out attr_out;
72 // for FUSE_OPEN
58 fuse_open_out open_out; 73 fuse_open_out open_out;
74 // for FUSE_READ
59 char read_data[kFuseMaxRead]; 75 char read_data[kFuseMaxRead];
76 // for FUSE_WRITE
60 fuse_write_out write_out; 77 fuse_write_out write_out;
61 }; 78 };
62 void Reset(uint32_t data_length, int32_t error, uint64_t unique); 79 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); 80 void ResetHeader(uint32_t data_length, int32_t error, uint64_t unique);
64}; 81};
65 82
66union FuseBuffer { 83// To reduce memory usage, FuseBuffer shares the memory region for request and
84// response.
85union FuseBuffer final {
67 FuseRequest request; 86 FuseRequest request;
68 FuseResponse response; 87 FuseResponse response;
69 88
@@ -71,19 +90,7 @@ union FuseBuffer {
71 void HandleNotImpl(); 90 void HandleNotImpl();
72}; 91};
73 92
74class FuseProxyLoop { 93} // namespace fuse
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 94} // namespace android
88 95
89#endif // ANDROID_LIBAPPFUSE_FUSEBUFFER_H_ 96#endif // ANDROID_LIBAPPFUSE_FUSEBUFFER_H_