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 #include "volume_external.h" 17 18 namespace OHOS { 19 namespace StorageManager { VolumeExternal()20VolumeExternal::VolumeExternal() {} 21 VolumeExternal(VolumeCore vc)22VolumeExternal::VolumeExternal(VolumeCore vc) 23 : VolumeExternal::VolumeCore(vc.GetId(), vc.GetType(), vc.GetDiskId(), vc.GetState()) {} 24 SetFlags(int32_t flags)25void VolumeExternal::SetFlags(int32_t flags) 26 { 27 flags_ = flags; 28 } 29 SetFsType(int32_t fsType)30void VolumeExternal::SetFsType(int32_t fsType) 31 { 32 fsType_ = fsType; 33 } 34 SetFsUuid(std::string fsUuid)35void VolumeExternal::SetFsUuid(std::string fsUuid) 36 { 37 fsUuid_ = fsUuid; 38 } 39 SetPath(std::string path)40void VolumeExternal::SetPath(std::string path) 41 { 42 path_ = path; 43 } 44 SetDescription(std::string description)45void VolumeExternal::SetDescription(std::string description) 46 { 47 description_ = description; 48 } 49 GetFlags()50int32_t VolumeExternal::GetFlags() 51 { 52 return flags_; 53 } 54 GetFsType()55int32_t VolumeExternal::GetFsType() 56 { 57 return fsType_; 58 } 59 GetFsTypeString()60std::string VolumeExternal::GetFsTypeString() 61 { 62 auto it = FS_TYPE_MAP.find(fsType_); 63 if (it == FS_TYPE_MAP.end()) { 64 return "undefined"; 65 } 66 return FS_TYPE_MAP[fsType_]; 67 } 68 GetUuid()69std::string VolumeExternal::GetUuid() 70 { 71 return fsUuid_; 72 } 73 GetPath()74std::string VolumeExternal::GetPath() 75 { 76 return path_; 77 } 78 GetDescription()79std::string VolumeExternal::GetDescription() 80 { 81 return description_; 82 } 83 GetFsTypeByStr(const std::string & fsTypeStr)84int32_t VolumeExternal::GetFsTypeByStr(const std::string &fsTypeStr) 85 { 86 for (uint32_t i = 0; i < FS_TYPE_MAP.size(); i++) { 87 if (FS_TYPE_MAP[i].compare(fsTypeStr) == 0) { 88 return i; 89 } 90 } 91 return -1; 92 } 93 Reset()94void VolumeExternal::Reset() 95 { 96 path_ = ""; 97 } 98 Marshalling(Parcel & parcel) const99bool VolumeExternal::Marshalling(Parcel &parcel) const 100 { 101 if (!VolumeCore::Marshalling(parcel)) { 102 return false; 103 } 104 105 if (!parcel.WriteInt32(flags_)) { 106 return false; 107 } 108 109 if (!parcel.WriteInt32(fsType_)) { 110 return false; 111 } 112 113 if (!parcel.WriteString(fsUuid_)) { 114 return false; 115 } 116 117 if (!parcel.WriteString(path_)) { 118 return false; 119 } 120 121 if (!parcel.WriteString(description_)) { 122 return false; 123 } 124 125 return true; 126 } 127 Unmarshalling(Parcel & parcel)128VolumeExternal *VolumeExternal::Unmarshalling(Parcel &parcel) 129 { 130 VolumeExternal* obj = new (std::nothrow) VolumeExternal(*VolumeCore::Unmarshalling(parcel)); 131 if (!obj) { 132 return nullptr; 133 } 134 obj->flags_ = parcel.ReadInt32(); 135 obj->fsType_ = parcel.ReadInt32(); 136 obj->fsUuid_ = parcel.ReadString(); 137 obj->path_ = parcel.ReadString(); 138 obj->description_ = parcel.ReadString(); 139 return obj; 140 } 141 } 142 } 143