• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_lowlevel.h>
21 #include <mutex>
22 #include <string>
23 #include "dlp_link_file.h"
24 #include "rwlock.h"
25 
26 namespace OHOS {
27 namespace Security {
28 namespace DlpPermission {
29 typedef struct DirAddParams {
30     fuse_req_t req;
31     char *directBuf;
32     size_t bufLen;
33     std::string entryName;
34     struct stat* entryStat;
35     off_t nextOff;
36     off_t curOff;
37 } DirAddParams;
38 
39 enum DaemonStatus {
40     DAEMON_UNDEF,
41     DAEMON_ENABLE,
42     DAEMON_DISABLE,
43 };
44 
45 fuse_ino_t GetFileInode(struct DlpFuseFileNode* node);
46 void UpdateCurrTimeStat(struct timespec* ts);
47 fuse_ino_t GetFileInode(DlpLinkFile* node);
48 
49 class FuseDaemon {
50 public:
51     static int InitFuseFs(int fuseDevFd);
52     static struct stat* GetRootFileStat();
53     static int WaitDaemonEnable(void);
54     static void NotifyDaemonEnable(void);
55     static void NotifyDaemonDisable(void);
56     static int NotifyKernelNoFlush(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