• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 MEDIAPROVIDER_JNI_FUSEDAEMON_H_
18 #define MEDIAPROVIDER_JNI_FUSEDAEMON_H_
19 
20 #include <memory>
21 #include <string>
22 
23 #include <android-base/unique_fd.h>
24 
25 #include "MediaProviderWrapper.h"
26 #include "jni.h"
27 
28 struct fuse;
29 namespace mediaprovider {
30 namespace fuse {
31 class FuseDaemon final {
32   public:
33     FuseDaemon(JNIEnv* env, jobject mediaProvider);
34 
35     ~FuseDaemon() = default;
36 
37     /**
38      * Start the FUSE daemon loop that will handle filesystem calls.
39      */
40     void Start(android::base::unique_fd fd, const std::string& path);
41 
42     /**
43      * Checks if the FUSE daemon is started.
44      */
45     bool IsStarted() const;
46 
47     /**
48      * Check if file should be opened with FUSE
49      */
50     bool ShouldOpenWithFuse(int fd, bool for_read, const std::string& path);
51 
52     /**
53      * Invalidate FUSE VFS dentry cache entry for path
54      */
55     void InvalidateFuseDentryCache(const std::string& path);
56 
57   private:
58     FuseDaemon(const FuseDaemon&) = delete;
59     void operator=(const FuseDaemon&) = delete;
60     MediaProviderWrapper mp;
61     std::atomic_bool active;
62     struct ::fuse* fuse;
63 };
64 
65 }  // namespace fuse
66 }  // namespace mediaprovider
67 
68 #endif  // MEDIAPROVIDER_JNI_FUSEDAEMON_H_
69