1 // Copyright (C) 2023 The Android Open Source Project 2 // 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 #pragma once 16 17 #include <stddef.h> 18 #include <sys/types.h> 19 20 #include <memory> 21 22 #include <android-base/unique_fd.h> 23 #include <snapuserd/block_server.h> 24 25 namespace android { 26 namespace snapshot { 27 28 // Interface for a "block driver in userspace" device. 29 class IUserDevice { 30 public: ~IUserDevice()31 virtual ~IUserDevice() {} 32 virtual const std::string& GetPath() = 0; 33 virtual bool Destroy() = 0; 34 }; 35 36 // Interface for an fd/temp file that is a block device when possible. 37 class IBackingDevice { 38 public: ~IBackingDevice()39 virtual ~IBackingDevice() {} 40 virtual const std::string& GetPath() = 0; 41 virtual uint64_t GetSize() = 0; 42 }; 43 44 class ITestHarness { 45 public: ~ITestHarness()46 virtual ~ITestHarness() {} 47 virtual std::unique_ptr<IUserDevice> CreateUserDevice(const std::string& dev_name, 48 const std::string& misc_name, 49 uint64_t num_sectors) = 0; 50 virtual IBlockServerFactory* GetBlockServerFactory() = 0; 51 virtual bool HasUserDevice() = 0; 52 virtual std::unique_ptr<IBackingDevice> CreateBackingDevice(uint64_t size); 53 }; 54 55 } // namespace snapshot 56 } // namespace android 57