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 #ifndef OHOS_STORAGE_DAEMON_EXTERNAL_VOLUME_INFO_H 17 #define OHOS_STORAGE_DAEMON_EXTERNAL_VOLUME_INFO_H 18 19 #include <vector> 20 #include <sys/types.h> 21 #include <map> 22 #include "volume/volume_info.h" 23 24 namespace OHOS { 25 namespace StorageDaemon { 26 constexpr int UID_FILE_MANAGER = 1006; 27 class ExternalVolumeInfo : public VolumeInfo { 28 public: 29 ExternalVolumeInfo() = default; 30 virtual ~ExternalVolumeInfo() = default; 31 32 int32_t GetFsType(); 33 std::string GetFsUuid(); 34 std::string GetFsLabel(); 35 std::string GetMountPath(); 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 DoCheck() override; 43 virtual int32_t DoFormat(std::string type) override; 44 virtual int32_t DoSetVolDesc(std::string description) override; 45 46 private: 47 std::string devPath_; 48 std::string fsLabel_; 49 std::string fsUuid_; 50 std::string fsType_; 51 std::string mountPath_; 52 53 dev_t device_; 54 55 const std::string devPathDir_ = "/dev/block/%s"; 56 const std::string mountPathDir_ = "/mnt/data/external/%s"; 57 std::vector<std::string> supportMountType_ = { "ext2", "ext3", "ext4", "ntfs", "exfat", "vfat" }; 58 std::map<std::string, std::string> supportFormatType_ = {{"exfat", "mkfs.exfat"}, {"vfat", "newfs_msdos"}}; 59 60 int32_t ReadMetadata(); 61 int32_t DoMount4Ext(uint32_t mountFlags); 62 int32_t DoMount4Ntfs(uint32_t mountFlags); 63 int32_t DoMount4Exfat(uint32_t mountFlags); 64 int32_t DoMount4OtherType(uint32_t mountFlags); 65 int32_t DoMount4Vfat(uint32_t mountFlags); 66 }; 67 } // STORAGE_DAEMON 68 } // OHOS 69 70 #endif // OHOS_STORAGE_DAEMON_EXTERNAL_VOLUME_INFO_H 71