1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FUSE_DAEMON_H 17 #define FUSE_DAEMON_H 18 19 #include <condition_variable> 20 #include <fuse_i.h> 21 #include <fuse_lowlevel.h> 22 #include <mutex> 23 #include <string> 24 #include "dlp_link_file.h" 25 #include "rwlock.h" 26 27 namespace OHOS { 28 namespace Security { 29 namespace DlpPermission { 30 typedef struct DirAddParams { 31 fuse_req_t req; 32 char *directBuf; 33 size_t bufLen; 34 std::string entryName; 35 struct stat* entryStat; 36 off_t nextOff; 37 off_t curOff; 38 } DirAddParams; 39 40 enum DaemonStatus { 41 DAEMON_UNDEF, 42 DAEMON_ENABLE, 43 DAEMON_DISABLE, 44 }; 45 46 fuse_ino_t GetFileInode(struct DlpFuseFileNode* node); 47 void UpdateCurrTimeStat(struct timespec* ts); 48 fuse_ino_t GetFileInode(DlpLinkFile* node); 49 50 class FuseDaemon { 51 public: 52 static int InitFuseFs(); 53 static struct stat* GetRootFileStat(); 54 static int WaitDaemonEnable(void); 55 static void NotifyDaemonEnable(void); 56 static void NotifyDaemonDisable(void); 57 static void InitRootFileStat(void); 58 static void FuseFsDaemonThread(int fuseFd); 59 60 static std::condition_variable daemonEnableCv_; 61 static enum DaemonStatus daemonStatus_; 62 static std::mutex daemonEnableMtx_; 63 static struct stat rootFileStat_; 64 static bool init_; 65 static struct fuse_lowlevel_ops fuseDaemonOper_; 66 }; 67 } // namespace DlpPermission 68 } // namespace Security 69 } // namespace OHOS 70 71 #endif 72