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 <android-base/unique_fd.h> 21 22 #include <memory> 23 #include <string> 24 25 #include "MediaProviderWrapper.h" 26 #include "jni.h" 27 #include "node-inl.h" 28 29 struct fuse; 30 namespace mediaprovider { 31 namespace fuse { 32 class FuseDaemon final { 33 public: 34 FuseDaemon(JNIEnv* env, jobject mediaProvider); 35 36 ~FuseDaemon() = default; 37 38 /** 39 * Start the FUSE daemon loop that will handle filesystem calls. 40 */ 41 void Start(android::base::unique_fd fd, const std::string& path, const bool uncached_mode, 42 const std::vector<std::string>& supported_transcoding_relative_paths, 43 const std::vector<std::string>& supported_uncached_relative_paths); 44 45 /** 46 * Checks if the FUSE daemon is started. 47 */ 48 bool IsStarted() const; 49 50 /** 51 * Check if file should be opened with FUSE 52 */ 53 bool ShouldOpenWithFuse(int fd, bool for_read, const std::string& path); 54 55 /** 56 * Check if the FUSE daemon uses FUSE passthrough 57 */ 58 bool UsesFusePassthrough() const; 59 60 /** 61 * Invalidate FUSE VFS dentry cache entry for path 62 */ 63 void InvalidateFuseDentryCache(const std::string& path); 64 65 /** 66 * Checks if the given uid has access to the given fd with or without redaction. 67 */ 68 std::unique_ptr<FdAccessResult> CheckFdAccess(int fd, uid_t uid) const; 69 70 /** 71 * Initialize device id for the FUSE daemon with the FUSE device id of the given path. 72 */ 73 void InitializeDeviceId(const std::string& path); 74 75 private: 76 FuseDaemon(const FuseDaemon&) = delete; 77 void operator=(const FuseDaemon&) = delete; 78 MediaProviderWrapper mp; 79 std::atomic_bool active; 80 struct ::fuse* fuse; 81 }; 82 83 } // namespace fuse 84 } // namespace mediaprovider 85 86 #endif // MEDIAPROVIDER_JNI_FUSEDAEMON_H_ 87