• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #include "utils/mount_argument_utils.h"
17 
18 #include <sstream>
19 #include <sys/mount.h>
20 
21 namespace OHOS {
22 namespace StorageDaemon {
23 namespace Utils {
24 using namespace std;
25 namespace {
26 static const std::string DATA_POINT = "/data/service/el2/";
27 static const std::string BASE_MOUNT_POINT = "/mnt/hmdfs/";
28 static const std::string COMM_DATA_POINT = "/storage/media/";
29 } // namespace
30 
GetFullSrc() const31 string MountArgument::GetFullSrc() const
32 {
33     stringstream ss;
34     ss << DATA_POINT << userId_ << "/hmdfs/" << relativePath_;
35 
36     return ss.str();
37 }
38 
GetFullDst() const39 string MountArgument::GetFullDst() const
40 {
41     stringstream ss;
42     ss << BASE_MOUNT_POINT << userId_ << "/" << relativePath_;
43 
44     return ss.str();
45 }
46 
GetCommFullPath() const47 string MountArgument::GetCommFullPath() const
48 {
49     stringstream ss;
50     ss << COMM_DATA_POINT << userId_ << "/";
51 
52     return ss.str();
53 }
54 
GetCachePath() const55 string MountArgument::GetCachePath() const
56 {
57     stringstream ss;
58     ss << DATA_POINT << userId_ << "/hmdfs/cache/" << relativePath_ << "_cache/";
59 
60     return ss.str();
61 }
62 
OptionsToString() const63 string MountArgument::OptionsToString() const
64 {
65     stringstream ss;
66     ss << "local_dst=" << GetFullDst() << ",user_id=" << userId_;
67     if (useCache_) {
68         ss << ",cache_dir=" << GetCachePath();
69     }
70     if (caseSensitive_) {
71         ss << ",sensitive";
72     }
73     if (enableMergeView_) {
74         ss << ",merge";
75     }
76     if (!enableOfflineStash_) {
77         ss << ",no_offline_stash";
78     }
79     return ss.str();
80 }
81 
GetFlags() const82 unsigned long MountArgument::GetFlags() const
83 {
84     return MS_NODEV;
85 }
86 
Alpha(int userId,string relativePath)87 MountArgument MountArgumentDescriptors::Alpha(int userId, string relativePath)
88 {
89     MountArgument mountArgument = {
90         .userId_ = userId,
91         .needInitDir_ = true,
92         .useCache_ = true,
93         .enableMergeView_ = true,
94         .enableFixupOwnerShip_ = false,
95         .enableOfflineStash_ = true,
96         .relativePath_ = relativePath,
97     };
98     return mountArgument;
99 }
100 } // namespace Utils
101 } // namespace StorageDaemon
102 } // namespace OHOS
103