• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 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 OHOS_STORAGE_DAEMON_EXTERNAL_VOLUME_INFO_H
17 #define OHOS_STORAGE_DAEMON_EXTERNAL_VOLUME_INFO_H
18 
19 #include <map>
20 #include "volume/volume_info.h"
21 
22 namespace OHOS {
23 namespace StorageDaemon {
24 class ExternalVolumeInfo : public VolumeInfo {
25 public:
26     ExternalVolumeInfo() = default;
27     virtual ~ExternalVolumeInfo() = default;
28 
29     virtual int32_t DoTryToFix() override;
30     virtual int32_t DoTryToCheck() override;
31     std::string GetFsType();
32     std::string GetFsUuid();
33     std::string GetFsLabel();
34     std::string GetMountPath();
35     int32_t IsUsbInUse(int fd);
36 
37 protected:
38     virtual int32_t DoCreate(dev_t dev) override;
39     virtual int32_t DoDestroy() override;
40     virtual int32_t DoMount(uint32_t mountFlags) override;
41     virtual int32_t DoUMount(bool force) override;
42     virtual int32_t DoUMountUsbFuse() override;
43     virtual int32_t DoCheck() override;
44     virtual int32_t DoFormat(std::string type) override;
45     virtual int32_t DoSetVolDesc(std::string description) override;
46 
47 private:
48     std::string devPath_;
49     std::string fsLabel_;
50     std::string fsUuid_;
51     std::string fsType_;
52     std::string mountPath_;
53     std::string mountUsbFusePath_;
54     std::string mountBackupPath_;
55 
56     dev_t device_;
57 
58     const std::string devPathDir_ = "/dev/block/%s";
59     const std::string mountPathDir_ = "/mnt/data/external/%s";
60     const std::string mountFusePathDir_ = "/mnt/data/external_fuse/%s";
61     std::vector<std::string> supportMountType_ = { "ntfs", "exfat", "vfat", "hmfs", "f2fs" };
62     std::map<std::string, std::string> supportFormatType_ = {{"exfat", "mkfs.exfat"}, {"vfat", "newfs_msdos"}};
63 
64     int32_t ReadMetadata();
65     int32_t DoMount4Ext(uint32_t mountFlags);
66     int32_t DoMount4Hmfs(uint32_t mountFlags);
67     int32_t DoMount4Ntfs(uint32_t mountFlags);
68     int32_t DoMount4Exfat(uint32_t mountFlags);
69     int32_t DoFix4Ntfs();
70     int32_t DoFix4Exfat();
71     int32_t DoMount4OtherType(uint32_t mountFlags);
72     int32_t DoMount4Vfat(uint32_t mountFlags);
73     int32_t DoCheck4Ntfs();
74     int32_t DoCheck4Exfat();
75     int32_t CreateMountPath();
76     int32_t CreateFuseMountPath();
77 };
78 } // STORAGE_DAEMON
79 } // OHOS
80 
81 #endif // OHOS_STORAGE_DAEMON_EXTERNAL_VOLUME_INFO_H
82