summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaichi Hirono2017-03-05 23:02:42 -0600
committerDaichi Hirono2017-03-13 19:09:29 -0500
commit57b780fbc3e2c2442c2f58dcb83818e786246b35 (patch)
treecf2426a800b3566d8f65b884831bf75e42cd47e1 /libappfuse/include/libappfuse
parentcc9d94ce04dbb63a745001323213bb667ea2e00f (diff)
downloadplatform-system-core-57b780fbc3e2c2442c2f58dcb83818e786246b35.tar.gz
platform-system-core-57b780fbc3e2c2442c2f58dcb83818e786246b35.tar.xz
platform-system-core-57b780fbc3e2c2442c2f58dcb83818e786246b35.zip
Add ReadOrAgain and WriteOrAgain methods to FuseMessage.
These methods return kAgain if operation cannot be done without blocking the current thread. The CL also introduecs new helper function SetupMessageSockets so that FuseMessages are always transfered via sockets that save message boundaries. Bug: 34903085 Test: libappfuse_test Change-Id: I34544372cc1b0c7bc9622e581ae16c018a123fa9
Diffstat (limited to 'libappfuse/include/libappfuse')
-rw-r--r--libappfuse/include/libappfuse/FuseBuffer.h17
1 files changed, 15 insertions, 2 deletions
diff --git a/libappfuse/include/libappfuse/FuseBuffer.h b/libappfuse/include/libappfuse/FuseBuffer.h
index 7abd2fa40..fbb05d633 100644
--- a/libappfuse/include/libappfuse/FuseBuffer.h
+++ b/libappfuse/include/libappfuse/FuseBuffer.h
@@ -17,6 +17,7 @@
17#ifndef ANDROID_LIBAPPFUSE_FUSEBUFFER_H_ 17#ifndef ANDROID_LIBAPPFUSE_FUSEBUFFER_H_
18#define ANDROID_LIBAPPFUSE_FUSEBUFFER_H_ 18#define ANDROID_LIBAPPFUSE_FUSEBUFFER_H_
19 19
20#include <android-base/unique_fd.h>
20#include <linux/fuse.h> 21#include <linux/fuse.h>
21 22
22namespace android { 23namespace android {
@@ -28,12 +29,24 @@ constexpr size_t kFuseMaxWrite = 256 * 1024;
28constexpr size_t kFuseMaxRead = 128 * 1024; 29constexpr size_t kFuseMaxRead = 128 * 1024;
29constexpr int32_t kFuseSuccess = 0; 30constexpr int32_t kFuseSuccess = 0;
30 31
32// Setup sockets to transfer FuseMessage.
33bool SetupMessageSockets(base::unique_fd (*sockets)[2]);
34
35enum class ResultOrAgain {
36 kSuccess,
37 kFailure,
38 kAgain,
39};
40
31template<typename T> 41template<typename T>
32class FuseMessage { 42class FuseMessage {
33 public: 43 public:
34 bool Read(int fd); 44 bool Read(int fd);
35 bool Write(int fd) const; 45 bool Write(int fd) const;
36 private: 46 ResultOrAgain ReadOrAgain(int fd);
47 ResultOrAgain WriteOrAgain(int fd) const;
48
49private:
37 bool CheckHeaderLength(const char* name) const; 50 bool CheckHeaderLength(const char* name) const;
38}; 51};
39 52
@@ -54,7 +67,7 @@ struct FuseRequest : public FuseMessage<FuseRequest> {
54 // for FUSE_READ 67 // for FUSE_READ
55 fuse_read_in read_in; 68 fuse_read_in read_in;
56 // for FUSE_LOOKUP 69 // for FUSE_LOOKUP
57 char lookup_name[0]; 70 char lookup_name[kFuseMaxWrite];
58 }; 71 };
59 void Reset(uint32_t data_length, uint32_t opcode, uint64_t unique); 72 void Reset(uint32_t data_length, uint32_t opcode, uint64_t unique);
60}; 73};