* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __UPDATER_FS_MANAGER_PARTITIONS_H
#define __UPDATER_FS_MANAGER_PARTITIONS_H
#include <fcntl.h>
#include <string>
#include <vector>
#include <sys/types.h>
namespace Updater {
#define RD_MODE (O_RDONLY)
#define WR_MODE (O_WRONLY)
#define RW_MODE (O_RDWR)
#define EX_MODE (O_EXCL)
typedef enum {
PARTITION_NEW,
PARTITION_OLD,
} PartitionChange;
typedef enum {
NORMAL_CHANGE,
NOT_CHANGE,
NEW_PARTITION,
START_CHANGE,
LENGTH_CHANGE,
PARTNUM_CHANGE,
PARTNAME_CHANGE,
FSTYPE_CHANGE,
} PartitionChangeType;
typedef enum {
GPT,
MBR,
} DiskType;
typedef enum {
NORMAL,
LOGICAL,
EXTENDED,
} PartitionType;
typedef enum {
DEVICE_UNKNOWN = 0,
DEVICE_SCSI = 1,
DEVICE_EMMC = 2,
} DeviceType;
typedef off64_t updater_sector_t;
struct Partition;
using PartitonList = std::vector<struct Partition *>;
struct BlockDevice {
std::string devPath;
std::string model;
DeviceType type;
size_t sectorSize;
size_t physSectorSize;
updater_sector_t length;
bool readOnly;
int fd;
void *specific;
};
struct Partition {
size_t start;
size_t length;
int partNum;
int partfd;
std::string devName;
std::string partName;
std::string fsType;
PartitionType type;
PartitionChangeType changeType;
};
struct Disk {
struct BlockDevice* dev;
PartitonList partList;
DiskType type;
int partsum;
};
struct BlockSpecific {
int fd;
int major;
int minor;
};
#define BLOCK_SPECIFIC(dev) ((BlockSpecific*) (dev)->specific)
extern int DiskAlloc(const std::string &path);
extern int ProbeAllPartitions();
extern Disk *GetRegisterBlockDisk(const std::string &path);
extern struct Partition *GetPartition(const Disk &disk, int partn);
extern int GetPartitionNumByPartName(const std::string &partname, const PartitonList &plist);
extern int DoPartitions(PartitonList &nlist);
extern bool SetBlockDeviceMode(BlockDevice &dev);
}
#endif