1*9190c2a8SAndroid Build Coastguard Worker /* 2*9190c2a8SAndroid Build Coastguard Worker * Copyright (C) 2019 The Android Open Source Project 3*9190c2a8SAndroid Build Coastguard Worker * 4*9190c2a8SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*9190c2a8SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*9190c2a8SAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*9190c2a8SAndroid Build Coastguard Worker * 8*9190c2a8SAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*9190c2a8SAndroid Build Coastguard Worker * 10*9190c2a8SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*9190c2a8SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*9190c2a8SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*9190c2a8SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*9190c2a8SAndroid Build Coastguard Worker * limitations under the License. 15*9190c2a8SAndroid Build Coastguard Worker */ 16*9190c2a8SAndroid Build Coastguard Worker #pragma once 17*9190c2a8SAndroid Build Coastguard Worker 18*9190c2a8SAndroid Build Coastguard Worker #include <unistd.h> 19*9190c2a8SAndroid Build Coastguard Worker 20*9190c2a8SAndroid Build Coastguard Worker #include <array> 21*9190c2a8SAndroid Build Coastguard Worker #include <chrono> 22*9190c2a8SAndroid Build Coastguard Worker #include <functional> 23*9190c2a8SAndroid Build Coastguard Worker #include <optional> 24*9190c2a8SAndroid Build Coastguard Worker #include <string> 25*9190c2a8SAndroid Build Coastguard Worker #include <string_view> 26*9190c2a8SAndroid Build Coastguard Worker #include <utility> 27*9190c2a8SAndroid Build Coastguard Worker #include <vector> 28*9190c2a8SAndroid Build Coastguard Worker 29*9190c2a8SAndroid Build Coastguard Worker #include "incfs_ndk.h" 30*9190c2a8SAndroid Build Coastguard Worker 31*9190c2a8SAndroid Build Coastguard Worker namespace android::incfs { 32*9190c2a8SAndroid Build Coastguard Worker 33*9190c2a8SAndroid Build Coastguard Worker using ByteBuffer = std::vector<char>; 34*9190c2a8SAndroid Build Coastguard Worker 35*9190c2a8SAndroid Build Coastguard Worker enum MountFlags { 36*9190c2a8SAndroid Build Coastguard Worker createOnly = INCFS_MOUNT_CREATE_ONLY, 37*9190c2a8SAndroid Build Coastguard Worker truncate = INCFS_MOUNT_TRUNCATE, 38*9190c2a8SAndroid Build Coastguard Worker }; 39*9190c2a8SAndroid Build Coastguard Worker 40*9190c2a8SAndroid Build Coastguard Worker enum Features { 41*9190c2a8SAndroid Build Coastguard Worker none = INCFS_FEATURE_NONE, 42*9190c2a8SAndroid Build Coastguard Worker core = INCFS_FEATURE_CORE, 43*9190c2a8SAndroid Build Coastguard Worker v2 = INCFS_FEATURE_V2, 44*9190c2a8SAndroid Build Coastguard Worker mappingFilesProgressFixed = INCFS_FEATURE_MAPPING_FILES_PROGRESS_FIXED, 45*9190c2a8SAndroid Build Coastguard Worker }; 46*9190c2a8SAndroid Build Coastguard Worker 47*9190c2a8SAndroid Build Coastguard Worker enum class HashAlgorithm { 48*9190c2a8SAndroid Build Coastguard Worker none = INCFS_HASH_NONE, 49*9190c2a8SAndroid Build Coastguard Worker sha256 = INCFS_HASH_SHA256, 50*9190c2a8SAndroid Build Coastguard Worker }; 51*9190c2a8SAndroid Build Coastguard Worker 52*9190c2a8SAndroid Build Coastguard Worker enum class CompressionKind { 53*9190c2a8SAndroid Build Coastguard Worker none = INCFS_COMPRESSION_KIND_NONE, 54*9190c2a8SAndroid Build Coastguard Worker lz4 = INCFS_COMPRESSION_KIND_LZ4, 55*9190c2a8SAndroid Build Coastguard Worker zstd = INCFS_COMPRESSION_KIND_ZSTD, 56*9190c2a8SAndroid Build Coastguard Worker }; 57*9190c2a8SAndroid Build Coastguard Worker 58*9190c2a8SAndroid Build Coastguard Worker enum class BlockKind { 59*9190c2a8SAndroid Build Coastguard Worker data = INCFS_BLOCK_KIND_DATA, 60*9190c2a8SAndroid Build Coastguard Worker hash = INCFS_BLOCK_KIND_HASH, 61*9190c2a8SAndroid Build Coastguard Worker }; 62*9190c2a8SAndroid Build Coastguard Worker 63*9190c2a8SAndroid Build Coastguard Worker class UniqueFd { 64*9190c2a8SAndroid Build Coastguard Worker public: UniqueFd(int fd)65*9190c2a8SAndroid Build Coastguard Worker explicit UniqueFd(int fd) : fd_(fd) {} UniqueFd()66*9190c2a8SAndroid Build Coastguard Worker UniqueFd() : UniqueFd(-1) {} ~UniqueFd()67*9190c2a8SAndroid Build Coastguard Worker ~UniqueFd() { close(); } UniqueFd(UniqueFd && other)68*9190c2a8SAndroid Build Coastguard Worker UniqueFd(UniqueFd&& other) noexcept : fd_(other.release()) {} 69*9190c2a8SAndroid Build Coastguard Worker UniqueFd& operator=(UniqueFd&& other) noexcept { 70*9190c2a8SAndroid Build Coastguard Worker close(); 71*9190c2a8SAndroid Build Coastguard Worker fd_ = other.release(); 72*9190c2a8SAndroid Build Coastguard Worker return *this; 73*9190c2a8SAndroid Build Coastguard Worker } 74*9190c2a8SAndroid Build Coastguard Worker close()75*9190c2a8SAndroid Build Coastguard Worker void close() { 76*9190c2a8SAndroid Build Coastguard Worker if (ok()) { 77*9190c2a8SAndroid Build Coastguard Worker ::close(fd_); 78*9190c2a8SAndroid Build Coastguard Worker fd_ = -1; 79*9190c2a8SAndroid Build Coastguard Worker } 80*9190c2a8SAndroid Build Coastguard Worker } get()81*9190c2a8SAndroid Build Coastguard Worker int get() const { return fd_; } ok()82*9190c2a8SAndroid Build Coastguard Worker [[nodiscard]] bool ok() const { return fd_ >= 0; } release()83*9190c2a8SAndroid Build Coastguard Worker [[nodiscard]] int release() { return std::exchange(fd_, -1); } 84*9190c2a8SAndroid Build Coastguard Worker 85*9190c2a8SAndroid Build Coastguard Worker private: 86*9190c2a8SAndroid Build Coastguard Worker int fd_; 87*9190c2a8SAndroid Build Coastguard Worker }; 88*9190c2a8SAndroid Build Coastguard Worker 89*9190c2a8SAndroid Build Coastguard Worker class UniqueControl { 90*9190c2a8SAndroid Build Coastguard Worker public: mControl(control)91*9190c2a8SAndroid Build Coastguard Worker UniqueControl(IncFsControl* control = nullptr) : mControl(control) {} ~UniqueControl()92*9190c2a8SAndroid Build Coastguard Worker ~UniqueControl() { close(); } UniqueControl(UniqueControl && other)93*9190c2a8SAndroid Build Coastguard Worker UniqueControl(UniqueControl&& other) noexcept 94*9190c2a8SAndroid Build Coastguard Worker : mControl(std::exchange(other.mControl, nullptr)) {} 95*9190c2a8SAndroid Build Coastguard Worker UniqueControl& operator=(UniqueControl&& other) noexcept { 96*9190c2a8SAndroid Build Coastguard Worker close(); 97*9190c2a8SAndroid Build Coastguard Worker mControl = std::exchange(other.mControl, nullptr); 98*9190c2a8SAndroid Build Coastguard Worker return *this; 99*9190c2a8SAndroid Build Coastguard Worker } 100*9190c2a8SAndroid Build Coastguard Worker 101*9190c2a8SAndroid Build Coastguard Worker IncFsFd cmd() const; 102*9190c2a8SAndroid Build Coastguard Worker IncFsFd pendingReads() const; 103*9190c2a8SAndroid Build Coastguard Worker IncFsFd logs() const; 104*9190c2a8SAndroid Build Coastguard Worker IncFsFd blocksWritten() const; 105*9190c2a8SAndroid Build Coastguard Worker 106*9190c2a8SAndroid Build Coastguard Worker void close(); 107*9190c2a8SAndroid Build Coastguard Worker 108*9190c2a8SAndroid Build Coastguard Worker operator IncFsControl*() const { return mControl; } 109*9190c2a8SAndroid Build Coastguard Worker 110*9190c2a8SAndroid Build Coastguard Worker using Fds = std::array<UniqueFd, IncFsFdType::FDS_COUNT>; 111*9190c2a8SAndroid Build Coastguard Worker [[nodiscard]] Fds releaseFds(); 112*9190c2a8SAndroid Build Coastguard Worker 113*9190c2a8SAndroid Build Coastguard Worker private: 114*9190c2a8SAndroid Build Coastguard Worker IncFsControl* mControl; 115*9190c2a8SAndroid Build Coastguard Worker }; 116*9190c2a8SAndroid Build Coastguard Worker 117*9190c2a8SAndroid Build Coastguard Worker // A mini version of std::span 118*9190c2a8SAndroid Build Coastguard Worker template <class T> 119*9190c2a8SAndroid Build Coastguard Worker class Span { 120*9190c2a8SAndroid Build Coastguard Worker public: 121*9190c2a8SAndroid Build Coastguard Worker using iterator = T*; 122*9190c2a8SAndroid Build Coastguard Worker using const_iterator = const T*; 123*9190c2a8SAndroid Build Coastguard Worker Span(T * array,size_t length)124*9190c2a8SAndroid Build Coastguard Worker constexpr Span(T* array, size_t length) : ptr_(array), len_(length) {} 125*9190c2a8SAndroid Build Coastguard Worker template <typename V> Span(const std::vector<V> & x)126*9190c2a8SAndroid Build Coastguard Worker constexpr Span(const std::vector<V>& x) : Span(x.data(), x.size()) {} 127*9190c2a8SAndroid Build Coastguard Worker template <typename V, size_t Size> Span(V (& x)[Size])128*9190c2a8SAndroid Build Coastguard Worker constexpr Span(V (&x)[Size]) : Span(x, Size) {} 129*9190c2a8SAndroid Build Coastguard Worker data()130*9190c2a8SAndroid Build Coastguard Worker constexpr T* data() const { return ptr_; } size()131*9190c2a8SAndroid Build Coastguard Worker constexpr size_t size() const { return len_; } 132*9190c2a8SAndroid Build Coastguard Worker constexpr T& operator[](size_t i) const { return *(data() + i); } begin()133*9190c2a8SAndroid Build Coastguard Worker constexpr iterator begin() const { return data(); } cbegin()134*9190c2a8SAndroid Build Coastguard Worker constexpr const_iterator cbegin() const { return begin(); } end()135*9190c2a8SAndroid Build Coastguard Worker constexpr iterator end() const { return data() + size(); } cend()136*9190c2a8SAndroid Build Coastguard Worker constexpr const_iterator cend() const { return end(); } 137*9190c2a8SAndroid Build Coastguard Worker 138*9190c2a8SAndroid Build Coastguard Worker private: 139*9190c2a8SAndroid Build Coastguard Worker T* ptr_; 140*9190c2a8SAndroid Build Coastguard Worker size_t len_; 141*9190c2a8SAndroid Build Coastguard Worker }; 142*9190c2a8SAndroid Build Coastguard Worker 143*9190c2a8SAndroid Build Coastguard Worker struct BlockRange final : public IncFsBlockRange { sizefinal144*9190c2a8SAndroid Build Coastguard Worker constexpr size_t size() const { return end - begin; } emptyfinal145*9190c2a8SAndroid Build Coastguard Worker constexpr bool empty() const { return end == begin; } 146*9190c2a8SAndroid Build Coastguard Worker }; 147*9190c2a8SAndroid Build Coastguard Worker 148*9190c2a8SAndroid Build Coastguard Worker class FilledRanges final { 149*9190c2a8SAndroid Build Coastguard Worker public: 150*9190c2a8SAndroid Build Coastguard Worker using RangeBuffer = std::vector<BlockRange>; 151*9190c2a8SAndroid Build Coastguard Worker 152*9190c2a8SAndroid Build Coastguard Worker FilledRanges() = default; FilledRanges(RangeBuffer && buffer,IncFsFilledRanges ranges)153*9190c2a8SAndroid Build Coastguard Worker FilledRanges(RangeBuffer&& buffer, IncFsFilledRanges ranges) 154*9190c2a8SAndroid Build Coastguard Worker : buffer_(std::move(buffer)), rawFilledRanges_(ranges) {} 155*9190c2a8SAndroid Build Coastguard Worker dataRanges()156*9190c2a8SAndroid Build Coastguard Worker constexpr Span<BlockRange> dataRanges() const { 157*9190c2a8SAndroid Build Coastguard Worker return {(BlockRange*)rawFilledRanges_.dataRanges, (size_t)rawFilledRanges_.dataRangesCount}; 158*9190c2a8SAndroid Build Coastguard Worker } hashRanges()159*9190c2a8SAndroid Build Coastguard Worker constexpr Span<BlockRange> hashRanges() const { 160*9190c2a8SAndroid Build Coastguard Worker return {(BlockRange*)rawFilledRanges_.hashRanges, (size_t)rawFilledRanges_.hashRangesCount}; 161*9190c2a8SAndroid Build Coastguard Worker } 162*9190c2a8SAndroid Build Coastguard Worker totalSize()163*9190c2a8SAndroid Build Coastguard Worker constexpr size_t totalSize() const { return dataRanges().size() + hashRanges().size(); } 164*9190c2a8SAndroid Build Coastguard Worker extractInternalBufferAndClear()165*9190c2a8SAndroid Build Coastguard Worker RangeBuffer extractInternalBufferAndClear() { 166*9190c2a8SAndroid Build Coastguard Worker rawFilledRanges_ = {}; 167*9190c2a8SAndroid Build Coastguard Worker return std::move(buffer_); 168*9190c2a8SAndroid Build Coastguard Worker } 169*9190c2a8SAndroid Build Coastguard Worker internalBuffer()170*9190c2a8SAndroid Build Coastguard Worker constexpr const RangeBuffer& internalBuffer() const { return buffer_; } internalRawRanges()171*9190c2a8SAndroid Build Coastguard Worker constexpr IncFsFilledRanges internalRawRanges() const { return rawFilledRanges_; } 172*9190c2a8SAndroid Build Coastguard Worker 173*9190c2a8SAndroid Build Coastguard Worker private: 174*9190c2a8SAndroid Build Coastguard Worker RangeBuffer buffer_; 175*9190c2a8SAndroid Build Coastguard Worker IncFsFilledRanges rawFilledRanges_; 176*9190c2a8SAndroid Build Coastguard Worker }; 177*9190c2a8SAndroid Build Coastguard Worker 178*9190c2a8SAndroid Build Coastguard Worker using Control = UniqueControl; 179*9190c2a8SAndroid Build Coastguard Worker 180*9190c2a8SAndroid Build Coastguard Worker using FileId = IncFsFileId; 181*9190c2a8SAndroid Build Coastguard Worker using Size = IncFsSize; 182*9190c2a8SAndroid Build Coastguard Worker using BlockIndex = IncFsBlockIndex; 183*9190c2a8SAndroid Build Coastguard Worker using ErrorCode = IncFsErrorCode; 184*9190c2a8SAndroid Build Coastguard Worker using Fd = IncFsFd; 185*9190c2a8SAndroid Build Coastguard Worker using Uid = IncFsUid; 186*9190c2a8SAndroid Build Coastguard Worker using ReadInfo = IncFsReadInfo; 187*9190c2a8SAndroid Build Coastguard Worker using ReadInfoWithUid = IncFsReadInfoWithUid; 188*9190c2a8SAndroid Build Coastguard Worker using RawMetadata = ByteBuffer; 189*9190c2a8SAndroid Build Coastguard Worker using RawSignature = ByteBuffer; 190*9190c2a8SAndroid Build Coastguard Worker using MountOptions = IncFsMountOptions; 191*9190c2a8SAndroid Build Coastguard Worker using DataBlock = IncFsDataBlock; 192*9190c2a8SAndroid Build Coastguard Worker using NewFileParams = IncFsNewFileParams; 193*9190c2a8SAndroid Build Coastguard Worker using NewMappedFileParams = IncFsNewMappedFileParams; 194*9190c2a8SAndroid Build Coastguard Worker using BlockCounts = IncFsBlockCounts; 195*9190c2a8SAndroid Build Coastguard Worker using UidReadTimeouts = IncFsUidReadTimeouts; 196*9190c2a8SAndroid Build Coastguard Worker using Metrics = IncFsMetrics; 197*9190c2a8SAndroid Build Coastguard Worker using LastReadError = IncFsLastReadError; 198*9190c2a8SAndroid Build Coastguard Worker 199*9190c2a8SAndroid Build Coastguard Worker constexpr auto kDefaultReadTimeout = std::chrono::milliseconds(INCFS_DEFAULT_READ_TIMEOUT_MS); 200*9190c2a8SAndroid Build Coastguard Worker constexpr int kBlockSize = INCFS_DATA_FILE_BLOCK_SIZE; 201*9190c2a8SAndroid Build Coastguard Worker const auto kInvalidFileId = kIncFsInvalidFileId; 202*9190c2a8SAndroid Build Coastguard Worker const auto kNoUid = kIncFsNoUid; 203*9190c2a8SAndroid Build Coastguard Worker 204*9190c2a8SAndroid Build Coastguard Worker bool enabled(); 205*9190c2a8SAndroid Build Coastguard Worker Features features(); 206*9190c2a8SAndroid Build Coastguard Worker bool isValidFileId(FileId fileId); 207*9190c2a8SAndroid Build Coastguard Worker std::string toString(FileId fileId); 208*9190c2a8SAndroid Build Coastguard Worker IncFsFileId toFileId(std::string_view str); 209*9190c2a8SAndroid Build Coastguard Worker bool isIncFsFd(int fd); 210*9190c2a8SAndroid Build Coastguard Worker bool isIncFsPath(std::string_view path); 211*9190c2a8SAndroid Build Coastguard Worker 212*9190c2a8SAndroid Build Coastguard Worker UniqueControl mount(std::string_view backingPath, std::string_view targetDir, 213*9190c2a8SAndroid Build Coastguard Worker IncFsMountOptions options); 214*9190c2a8SAndroid Build Coastguard Worker UniqueControl open(std::string_view dir); 215*9190c2a8SAndroid Build Coastguard Worker UniqueControl createControl(IncFsFd cmd, IncFsFd pendingReads, IncFsFd logs, IncFsFd blocksWritten); 216*9190c2a8SAndroid Build Coastguard Worker 217*9190c2a8SAndroid Build Coastguard Worker ErrorCode setOptions(const Control& control, MountOptions newOptions); 218*9190c2a8SAndroid Build Coastguard Worker 219*9190c2a8SAndroid Build Coastguard Worker ErrorCode bindMount(std::string_view sourceDir, std::string_view targetDir); 220*9190c2a8SAndroid Build Coastguard Worker ErrorCode unmount(std::string_view dir); 221*9190c2a8SAndroid Build Coastguard Worker 222*9190c2a8SAndroid Build Coastguard Worker std::string root(const Control& control); 223*9190c2a8SAndroid Build Coastguard Worker 224*9190c2a8SAndroid Build Coastguard Worker ErrorCode makeFile(const Control& control, std::string_view path, int mode, FileId fileId, 225*9190c2a8SAndroid Build Coastguard Worker NewFileParams params); 226*9190c2a8SAndroid Build Coastguard Worker ErrorCode makeMappedFile(const Control& control, std::string_view path, int mode, 227*9190c2a8SAndroid Build Coastguard Worker NewMappedFileParams params); 228*9190c2a8SAndroid Build Coastguard Worker ErrorCode makeDir(const Control& control, std::string_view path, int mode = 0555); 229*9190c2a8SAndroid Build Coastguard Worker ErrorCode makeDirs(const Control& control, std::string_view path, int mode = 0555); 230*9190c2a8SAndroid Build Coastguard Worker 231*9190c2a8SAndroid Build Coastguard Worker RawMetadata getMetadata(const Control& control, FileId fileId); 232*9190c2a8SAndroid Build Coastguard Worker RawMetadata getMetadata(const Control& control, std::string_view path); 233*9190c2a8SAndroid Build Coastguard Worker FileId getFileId(const Control& control, std::string_view path); 234*9190c2a8SAndroid Build Coastguard Worker 235*9190c2a8SAndroid Build Coastguard Worker RawSignature getSignature(const Control& control, FileId fileId); 236*9190c2a8SAndroid Build Coastguard Worker RawSignature getSignature(const Control& control, std::string_view path); 237*9190c2a8SAndroid Build Coastguard Worker 238*9190c2a8SAndroid Build Coastguard Worker ErrorCode link(const Control& control, std::string_view sourcePath, std::string_view targetPath); 239*9190c2a8SAndroid Build Coastguard Worker ErrorCode unlink(const Control& control, std::string_view path); 240*9190c2a8SAndroid Build Coastguard Worker 241*9190c2a8SAndroid Build Coastguard Worker enum class WaitResult { HaveData, Timeout, Error }; 242*9190c2a8SAndroid Build Coastguard Worker 243*9190c2a8SAndroid Build Coastguard Worker WaitResult waitForPendingReads(const Control& control, std::chrono::milliseconds timeout, 244*9190c2a8SAndroid Build Coastguard Worker std::vector<ReadInfo>* pendingReadsBuffer); 245*9190c2a8SAndroid Build Coastguard Worker WaitResult waitForPageReads(const Control& control, std::chrono::milliseconds timeout, 246*9190c2a8SAndroid Build Coastguard Worker std::vector<ReadInfo>* pageReadsBuffer); 247*9190c2a8SAndroid Build Coastguard Worker WaitResult waitForPendingReads(const Control& control, std::chrono::milliseconds timeout, 248*9190c2a8SAndroid Build Coastguard Worker std::vector<ReadInfoWithUid>* pendingReadsBuffer); 249*9190c2a8SAndroid Build Coastguard Worker WaitResult waitForPageReads(const Control& control, std::chrono::milliseconds timeout, 250*9190c2a8SAndroid Build Coastguard Worker std::vector<ReadInfoWithUid>* pageReadsBuffer); 251*9190c2a8SAndroid Build Coastguard Worker 252*9190c2a8SAndroid Build Coastguard Worker UniqueFd openForSpecialOps(const Control& control, FileId fileId); 253*9190c2a8SAndroid Build Coastguard Worker UniqueFd openForSpecialOps(const Control& control, std::string_view path); 254*9190c2a8SAndroid Build Coastguard Worker ErrorCode writeBlocks(Span<const DataBlock> blocks); 255*9190c2a8SAndroid Build Coastguard Worker 256*9190c2a8SAndroid Build Coastguard Worker std::pair<ErrorCode, FilledRanges> getFilledRanges(int fd); 257*9190c2a8SAndroid Build Coastguard Worker std::pair<ErrorCode, FilledRanges> getFilledRanges(int fd, FilledRanges::RangeBuffer&& buffer); 258*9190c2a8SAndroid Build Coastguard Worker std::pair<ErrorCode, FilledRanges> getFilledRanges(int fd, FilledRanges&& resumeFrom); 259*9190c2a8SAndroid Build Coastguard Worker 260*9190c2a8SAndroid Build Coastguard Worker ErrorCode setUidReadTimeouts(const Control& control, Span<const UidReadTimeouts> timeouts); 261*9190c2a8SAndroid Build Coastguard Worker std::optional<std::vector<UidReadTimeouts>> getUidReadTimeouts(const Control& control); 262*9190c2a8SAndroid Build Coastguard Worker 263*9190c2a8SAndroid Build Coastguard Worker std::optional<BlockCounts> getBlockCount(const Control& control, FileId fileId); 264*9190c2a8SAndroid Build Coastguard Worker std::optional<BlockCounts> getBlockCount(const Control& control, std::string_view path); 265*9190c2a8SAndroid Build Coastguard Worker 266*9190c2a8SAndroid Build Coastguard Worker std::optional<std::vector<FileId>> listIncompleteFiles(const Control& control); 267*9190c2a8SAndroid Build Coastguard Worker 268*9190c2a8SAndroid Build Coastguard Worker template <class Callback> 269*9190c2a8SAndroid Build Coastguard Worker ErrorCode forEachFile(const Control& control, Callback&& cb); 270*9190c2a8SAndroid Build Coastguard Worker template <class Callback> 271*9190c2a8SAndroid Build Coastguard Worker ErrorCode forEachIncompleteFile(const Control& control, Callback&& cb); 272*9190c2a8SAndroid Build Coastguard Worker 273*9190c2a8SAndroid Build Coastguard Worker WaitResult waitForLoadingComplete(const Control& control, std::chrono::milliseconds timeout); 274*9190c2a8SAndroid Build Coastguard Worker 275*9190c2a8SAndroid Build Coastguard Worker enum class LoadingState { Full, MissingBlocks }; 276*9190c2a8SAndroid Build Coastguard Worker LoadingState isFullyLoaded(int fd); 277*9190c2a8SAndroid Build Coastguard Worker LoadingState isFullyLoaded(const Control& control, std::string_view path); 278*9190c2a8SAndroid Build Coastguard Worker LoadingState isFullyLoaded(const Control& control, FileId fileId); 279*9190c2a8SAndroid Build Coastguard Worker LoadingState isEverythingFullyLoaded(const Control& control); 280*9190c2a8SAndroid Build Coastguard Worker 281*9190c2a8SAndroid Build Coastguard Worker static const auto kTrimReservedSpace = kIncFsTrimReservedSpace; 282*9190c2a8SAndroid Build Coastguard Worker ErrorCode reserveSpace(const Control& control, std::string_view path, Size size); 283*9190c2a8SAndroid Build Coastguard Worker ErrorCode reserveSpace(const Control& control, FileId id, Size size); 284*9190c2a8SAndroid Build Coastguard Worker 285*9190c2a8SAndroid Build Coastguard Worker std::optional<Metrics> getMetrics(std::string_view sysfsName); 286*9190c2a8SAndroid Build Coastguard Worker std::optional<LastReadError> getLastReadError(const Control& control); 287*9190c2a8SAndroid Build Coastguard Worker 288*9190c2a8SAndroid Build Coastguard Worker // Some internal secret API as well that's not backed by C API yet. 289*9190c2a8SAndroid Build Coastguard Worker class MountRegistry; 290*9190c2a8SAndroid Build Coastguard Worker MountRegistry& defaultMountRegistry(); 291*9190c2a8SAndroid Build Coastguard Worker 292*9190c2a8SAndroid Build Coastguard Worker } // namespace android::incfs 293*9190c2a8SAndroid Build Coastguard Worker 294*9190c2a8SAndroid Build Coastguard Worker bool operator==(const IncFsFileId& l, const IncFsFileId& r); 295*9190c2a8SAndroid Build Coastguard Worker inline bool operator!=(const IncFsFileId& l, const IncFsFileId& r) { 296*9190c2a8SAndroid Build Coastguard Worker return !(l == r); 297*9190c2a8SAndroid Build Coastguard Worker } 298*9190c2a8SAndroid Build Coastguard Worker 299*9190c2a8SAndroid Build Coastguard Worker namespace std { 300*9190c2a8SAndroid Build Coastguard Worker 301*9190c2a8SAndroid Build Coastguard Worker template <> 302*9190c2a8SAndroid Build Coastguard Worker struct hash<IncFsFileId> { 303*9190c2a8SAndroid Build Coastguard Worker size_t operator()(const IncFsFileId& id) const noexcept { 304*9190c2a8SAndroid Build Coastguard Worker return std::hash<std::string_view>()({&id.data[0], sizeof(id)}); 305*9190c2a8SAndroid Build Coastguard Worker } 306*9190c2a8SAndroid Build Coastguard Worker }; 307*9190c2a8SAndroid Build Coastguard Worker 308*9190c2a8SAndroid Build Coastguard Worker } // namespace std 309*9190c2a8SAndroid Build Coastguard Worker 310*9190c2a8SAndroid Build Coastguard Worker #include "incfs_inline.h" 311