blob: f7c5614e1b4a3082de578b27320223e3c2ca0a90 [file] [log] [blame]
shafik1e3a2672019-08-16 14:51:55 +01001/*
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
Zimedbe69e2019-12-13 18:49:36 +000020#include <memory>
Zim3e45d9b2019-08-19 21:14:14 +010021#include <string>
shafik1e3a2672019-08-16 14:51:55 +010022
Martijn Coenen083eb692020-04-24 09:39:58 +020023#include <android-base/unique_fd.h>
24
shafikc3f62672019-08-30 11:15:48 +010025#include "MediaProviderWrapper.h"
shafik1e3a2672019-08-16 14:51:55 +010026#include "jni.h"
27
Zimedbe69e2019-12-13 18:49:36 +000028struct fuse;
shafik1e3a2672019-08-16 14:51:55 +010029namespace mediaprovider {
30namespace fuse {
shafik1e3a2672019-08-16 14:51:55 +010031class FuseDaemon final {
shafikc3f62672019-08-30 11:15:48 +010032 public:
shafik1e3a2672019-08-16 14:51:55 +010033 FuseDaemon(JNIEnv* env, jobject mediaProvider);
Zim3e45d9b2019-08-19 21:14:14 +010034
Zim7e0d3142019-10-17 21:06:12 +010035 ~FuseDaemon() = default;
36
shafik1e3a2672019-08-16 14:51:55 +010037 /**
38 * Start the FUSE daemon loop that will handle filesystem calls.
39 */
Martijn Coenen083eb692020-04-24 09:39:58 +020040 void Start(android::base::unique_fd fd, const std::string& path);
shafik8b57cd52019-09-06 10:51:29 +010041
Zimedbe69e2019-12-13 18:49:36 +000042 /**
Zimd0435b22020-03-05 13:52:51 +000043 * Checks if the FUSE daemon is started.
44 */
45 bool IsStarted() const;
46
47 /**
Zimedbe69e2019-12-13 18:49:36 +000048 * Check if file should be opened with FUSE
49 */
50 bool ShouldOpenWithFuse(int fd, bool for_read, const std::string& path);
51
Zima76c3492020-02-19 01:23:26 +000052 /**
53 * Invalidate FUSE VFS dentry cache entry for path
54 */
55 void InvalidateFuseDentryCache(const std::string& path);
56
Biswarup Pal93f4ec12021-02-15 13:39:36 +000057 /**
58 * Return path of the original media format file for the given file descriptor.
59 */
60 const std::string GetOriginalMediaFormatFilePath(int fd) const;
61
62 /**
63 * Initialize device id for the FUSE daemon with the FUSE device id of the given path.
64 */
65 void InitializeDeviceId(const std::string& path);
66
shafik8b57cd52019-09-06 10:51:29 +010067 private:
Zim3e45d9b2019-08-19 21:14:14 +010068 FuseDaemon(const FuseDaemon&) = delete;
69 void operator=(const FuseDaemon&) = delete;
shafikc3f62672019-08-30 11:15:48 +010070 MediaProviderWrapper mp;
Zimedbe69e2019-12-13 18:49:36 +000071 std::atomic_bool active;
72 struct ::fuse* fuse;
shafik1e3a2672019-08-16 14:51:55 +010073};
74
75} // namespace fuse
76} // namespace mediaprovider
77
78#endif // MEDIAPROVIDER_JNI_FUSEDAEMON_H_