From 625c588c0f1a77bf632f56aa1cf92bb746f6f02a Mon Sep 17 00:00:00 2001 From: xunchang Date: Fri, 22 Mar 2019 09:33:49 -0700 Subject: Move out the code to parse block map in MemMap We will reuse them to implement the fuse provider from block maps. Test: unit tests pass, sideload an OTA Change-Id: Iaa409d19569c4ccc0bb24e12518044fcddb45c69 --- otautil/include/otautil/sysutil.h | 51 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'otautil/include') diff --git a/otautil/include/otautil/sysutil.h b/otautil/include/otautil/sysutil.h index 2eeb7c302..692a99e9d 100644 --- a/otautil/include/otautil/sysutil.h +++ b/otautil/include/otautil/sysutil.h @@ -22,6 +22,57 @@ #include #include +#include "rangeset.h" + +// This class holds the content of a block map file. +class BlockMapData { + public: + // A "block map" which looks like this (from uncrypt/uncrypt.cpp): + // + // /dev/block/platform/msm_sdcc.1/by-name/userdata # block device + // 49652 4096 # file size in bytes, block size + // 3 # count of block ranges + // 1000 1008 # block range 0 + // 2100 2102 # ... block range 1 + // 30 33 # ... block range 2 + // + // Each block range represents a half-open interval; the line "30 33" reprents the blocks + // [30, 31, 32]. + static BlockMapData ParseBlockMapFile(const std::string& block_map_path); + + explicit operator bool() const { + return !path_.empty(); + } + + std::string path() const { + return path_; + } + uint64_t file_size() const { + return file_size_; + } + uint32_t block_size() const { + return block_size_; + } + RangeSet block_ranges() const { + return block_ranges_; + } + + private: + BlockMapData() = default; + + BlockMapData(const std::string& path, uint64_t file_size, uint32_t block_size, + RangeSet block_ranges) + : path_(path), + file_size_(file_size), + block_size_(block_size), + block_ranges_(std::move(block_ranges)) {} + + std::string path_; + uint64_t file_size_ = 0; + uint32_t block_size_ = 0; + RangeSet block_ranges_; +}; + /* * Use this to keep track of mapped segments. */ -- cgit v1.2.3