• 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 #ifndef FLASHING_BLOCKDEVICE_H
17 #define FLASHING_BLOCKDEVICE_H
18 #include <cstdlib>
19 #include <memory>
20 #include "flash_utils.h"
21 
22 namespace flashd {
23 enum class DeviceType {
24     DEVICE_UNKNOWN = 0,
25     DEVICE_SCSI = 1,
26     DEVICE_EMMC = 2,
27 };
28 
29 class BlockDevice {
30 public:
BlockDevice(DeviceType type,const std::string & devPath)31     BlockDevice(DeviceType type, const std::string &devPath) : devPath_(devPath), type_(type) {}
~BlockDevice()32     ~BlockDevice() {};
33 
34     int Load();
35     const std::string GetDeviceName();
GetDeviceType()36     DeviceType GetDeviceType()
37     {
38         return type_;
39     }
40 private:
41     std::string ReadDeviceSysInfo(const std::string &type);
42 
43     std::string devPath_;
44     size_t devSize_ = 0;
45     size_t sectorSize_ = 0;         // logical sector size
46     size_t physSectorSize_ = 0;     // physical sector size
47     DeviceType type_ = DeviceType::DEVICE_UNKNOWN;
48 };
49 using BlockDevicePtr = BlockDevice *;
50 }
51 #endif // FLASHING_BLOCKDEVICE_H