Aaron Wisner | db51120 | 2018-06-26 15:38:35 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <inttypes.h> |
| 4 | #include <stdlib.h> |
| 5 | |
| 6 | #include <string> |
David Anderson | aa87dc5 | 2023-01-27 20:39:06 -0800 | [diff] [blame] | 7 | #include <vector> |
Aaron Wisner | db51120 | 2018-06-26 15:38:35 -0500 | [diff] [blame] | 8 | |
David Anderson | aa87dc5 | 2023-01-27 20:39:06 -0800 | [diff] [blame] | 9 | #include <android-base/unique_fd.h> |
Aaron Wisner | db51120 | 2018-06-26 15:38:35 -0500 | [diff] [blame] | 10 | #include <bootimg.h> |
David Anderson | aa87dc5 | 2023-01-27 20:39:06 -0800 | [diff] [blame] | 11 | #include <liblp/liblp.h> |
| 12 | #include <sparse/sparse.h> |
| 13 | |
| 14 | using SparsePtr = std::unique_ptr<sparse_file, decltype(&sparse_file_destroy)>; |
Aaron Wisner | db51120 | 2018-06-26 15:38:35 -0500 | [diff] [blame] | 15 | |
| 16 | /* util stuff */ |
| 17 | double now(); |
Aaron Wisner | db51120 | 2018-06-26 15:38:35 -0500 | [diff] [blame] | 18 | void set_verbose(); |
| 19 | |
Aaron Wisner | db51120 | 2018-06-26 15:38:35 -0500 | [diff] [blame] | 20 | // These printf-like functions are implemented in terms of vsnprintf, so they |
| 21 | // use the same attribute for compile-time format string checking. |
| 22 | void die(const char* fmt, ...) __attribute__((__noreturn__)) |
| 23 | __attribute__((__format__(__printf__, 1, 2))); |
David Anderson | 7c84b9f | 2019-06-27 22:15:29 -0700 | [diff] [blame] | 24 | |
Aaron Wisner | db51120 | 2018-06-26 15:38:35 -0500 | [diff] [blame] | 25 | void verbose(const char* fmt, ...) __attribute__((__format__(__printf__, 1, 2))); |
David Anderson | 7c84b9f | 2019-06-27 22:15:29 -0700 | [diff] [blame] | 26 | |
| 27 | void die(const std::string& str) __attribute__((__noreturn__)); |
David Anderson | aa87dc5 | 2023-01-27 20:39:06 -0800 | [diff] [blame] | 28 | |
| 29 | bool should_flash_in_userspace(const android::fs_mgr::LpMetadata& metadata, |
| 30 | const std::string& partition_name); |
| 31 | bool is_sparse_file(android::base::borrowed_fd fd); |
| 32 | int64_t get_file_size(android::base::borrowed_fd fd); |
David Anderson | 74c7807 | 2023-03-16 21:21:28 -0700 | [diff] [blame] | 33 | std::string fb_fix_numeric_var(std::string var); |
David Anderson | aa87dc5 | 2023-01-27 20:39:06 -0800 | [diff] [blame] | 34 | |
| 35 | class ImageSource { |
| 36 | public: |
| 37 | virtual ~ImageSource(){}; |
| 38 | virtual bool ReadFile(const std::string& name, std::vector<char>* out) const = 0; |
| 39 | virtual android::base::unique_fd OpenFile(const std::string& name) const = 0; |
| 40 | }; |