1fb299fa2Sopenharmony_ci/* 2fb299fa2Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 3fb299fa2Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4fb299fa2Sopenharmony_ci * you may not use this file except in compliance with the License. 5fb299fa2Sopenharmony_ci * You may obtain a copy of the License at 6fb299fa2Sopenharmony_ci * 7fb299fa2Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8fb299fa2Sopenharmony_ci * 9fb299fa2Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10fb299fa2Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11fb299fa2Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12fb299fa2Sopenharmony_ci * See the License for the specific language governing permissions and 13fb299fa2Sopenharmony_ci * limitations under the License. 14fb299fa2Sopenharmony_ci */ 15fb299fa2Sopenharmony_ci 16fb299fa2Sopenharmony_ci#ifndef __UPDATER_FS_MANAGER_PARTITIONS_H 17fb299fa2Sopenharmony_ci#define __UPDATER_FS_MANAGER_PARTITIONS_H 18fb299fa2Sopenharmony_ci 19fb299fa2Sopenharmony_ci#include <fcntl.h> 20fb299fa2Sopenharmony_ci#include <string> 21fb299fa2Sopenharmony_ci#include <vector> 22fb299fa2Sopenharmony_ci#include <sys/types.h> 23fb299fa2Sopenharmony_ci 24fb299fa2Sopenharmony_ci 25fb299fa2Sopenharmony_cinamespace Updater { 26fb299fa2Sopenharmony_ci#define RD_MODE (O_RDONLY) 27fb299fa2Sopenharmony_ci#define WR_MODE (O_WRONLY) 28fb299fa2Sopenharmony_ci#define RW_MODE (O_RDWR) 29fb299fa2Sopenharmony_ci#define EX_MODE (O_EXCL) 30fb299fa2Sopenharmony_ci 31fb299fa2Sopenharmony_citypedef enum { 32fb299fa2Sopenharmony_ci PARTITION_NEW, 33fb299fa2Sopenharmony_ci PARTITION_OLD, 34fb299fa2Sopenharmony_ci} PartitionChange; 35fb299fa2Sopenharmony_ci 36fb299fa2Sopenharmony_citypedef enum { 37fb299fa2Sopenharmony_ci NORMAL_CHANGE, 38fb299fa2Sopenharmony_ci NOT_CHANGE, 39fb299fa2Sopenharmony_ci NEW_PARTITION, 40fb299fa2Sopenharmony_ci START_CHANGE, 41fb299fa2Sopenharmony_ci LENGTH_CHANGE, 42fb299fa2Sopenharmony_ci PARTNUM_CHANGE, 43fb299fa2Sopenharmony_ci PARTNAME_CHANGE, 44fb299fa2Sopenharmony_ci FSTYPE_CHANGE, 45fb299fa2Sopenharmony_ci} PartitionChangeType; 46fb299fa2Sopenharmony_ci 47fb299fa2Sopenharmony_citypedef enum { 48fb299fa2Sopenharmony_ci GPT, 49fb299fa2Sopenharmony_ci MBR, 50fb299fa2Sopenharmony_ci} DiskType; 51fb299fa2Sopenharmony_ci 52fb299fa2Sopenharmony_citypedef enum { 53fb299fa2Sopenharmony_ci NORMAL, 54fb299fa2Sopenharmony_ci LOGICAL, 55fb299fa2Sopenharmony_ci EXTENDED, 56fb299fa2Sopenharmony_ci} PartitionType; 57fb299fa2Sopenharmony_ci 58fb299fa2Sopenharmony_citypedef enum { 59fb299fa2Sopenharmony_ci DEVICE_UNKNOWN = 0, 60fb299fa2Sopenharmony_ci DEVICE_SCSI = 1, 61fb299fa2Sopenharmony_ci DEVICE_EMMC = 2, 62fb299fa2Sopenharmony_ci} DeviceType; 63fb299fa2Sopenharmony_ci 64fb299fa2Sopenharmony_ci/** We can address 2^63 sectors */ 65fb299fa2Sopenharmony_citypedef off64_t updater_sector_t; 66fb299fa2Sopenharmony_ci 67fb299fa2Sopenharmony_cistruct Partition; 68fb299fa2Sopenharmony_ciusing PartitonList = std::vector<struct Partition *>; 69fb299fa2Sopenharmony_ci 70fb299fa2Sopenharmony_cistruct BlockDevice { 71fb299fa2Sopenharmony_ci std::string devPath; 72fb299fa2Sopenharmony_ci std::string model; // description of hardware(manufacturer, model) 73fb299fa2Sopenharmony_ci DeviceType type; // SCSI, MMC, etc 74fb299fa2Sopenharmony_ci size_t sectorSize; // logical sector size 75fb299fa2Sopenharmony_ci size_t physSectorSize; // physical sector size 76fb299fa2Sopenharmony_ci updater_sector_t length; // device length (LBA) */ 77fb299fa2Sopenharmony_ci bool readOnly; 78fb299fa2Sopenharmony_ci int fd; 79fb299fa2Sopenharmony_ci void *specific; 80fb299fa2Sopenharmony_ci}; 81fb299fa2Sopenharmony_ci 82fb299fa2Sopenharmony_cistruct Partition { 83fb299fa2Sopenharmony_ci size_t start; 84fb299fa2Sopenharmony_ci size_t length; 85fb299fa2Sopenharmony_ci int partNum; // Partition number. 86fb299fa2Sopenharmony_ci int partfd; 87fb299fa2Sopenharmony_ci std::string devName; 88fb299fa2Sopenharmony_ci std::string partName; 89fb299fa2Sopenharmony_ci std::string fsType; // File system type, ext4, f2fs etc. 90fb299fa2Sopenharmony_ci PartitionType type; 91fb299fa2Sopenharmony_ci PartitionChangeType changeType; 92fb299fa2Sopenharmony_ci}; 93fb299fa2Sopenharmony_ci 94fb299fa2Sopenharmony_cistruct Disk { 95fb299fa2Sopenharmony_ci struct BlockDevice* dev; 96fb299fa2Sopenharmony_ci PartitonList partList; 97fb299fa2Sopenharmony_ci DiskType type; 98fb299fa2Sopenharmony_ci int partsum; 99fb299fa2Sopenharmony_ci}; 100fb299fa2Sopenharmony_ci 101fb299fa2Sopenharmony_cistruct BlockSpecific { 102fb299fa2Sopenharmony_ci int fd; 103fb299fa2Sopenharmony_ci int major; 104fb299fa2Sopenharmony_ci int minor; 105fb299fa2Sopenharmony_ci}; 106fb299fa2Sopenharmony_ci 107fb299fa2Sopenharmony_ci#define BLOCK_SPECIFIC(dev) ((BlockSpecific*) (dev)->specific) 108fb299fa2Sopenharmony_ciextern int DiskAlloc(const std::string &path); 109fb299fa2Sopenharmony_ciextern int ProbeAllPartitions(); 110fb299fa2Sopenharmony_ciextern Disk *GetRegisterBlockDisk(const std::string &path); 111fb299fa2Sopenharmony_ciextern struct Partition *GetPartition(const Disk &disk, int partn); 112fb299fa2Sopenharmony_ciextern int GetPartitionNumByPartName(const std::string &partname, const PartitonList &plist); 113fb299fa2Sopenharmony_ciextern int DoPartitions(PartitonList &nlist); 114fb299fa2Sopenharmony_ciextern bool SetBlockDeviceMode(BlockDevice &dev); 115fb299fa2Sopenharmony_ci} // Updater 116fb299fa2Sopenharmony_ci#endif // __UPDATER_FS_MANAGER_PARTITIONS_H 117fb299fa2Sopenharmony_ci 118