Android-cuttlefish cvd tool
util.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <stdlib.h>
20
21#include <string>
22#include <vector>
23
24#include <android-base/unique_fd.h>
25#include <bootimg.h>
26#include <liblp/liblp.h>
27#include <sparse/sparse.h>
28
29using SparsePtr = std::unique_ptr<sparse_file, decltype(&sparse_file_destroy)>;
30
31/* util stuff */
32double now();
33void set_verbose();
34
35// These printf-like functions are implemented in terms of vsnprintf, so they
36// use the same attribute for compile-time format string checking.
37void die(const char* fmt, ...) __attribute__((__noreturn__))
38__attribute__((__format__(__printf__, 1, 2)));
39
40void verbose(const char* fmt, ...) __attribute__((__format__(__printf__, 1, 2)));
41
42void die(const std::string& str) __attribute__((__noreturn__));
43
44bool should_flash_in_userspace(const android::fs_mgr::LpMetadata& metadata,
45 const std::string& partition_name);
46bool is_sparse_file(android::base::borrowed_fd fd);
47int64_t get_file_size(android::base::borrowed_fd fd);
48std::string fb_fix_numeric_var(std::string var);
49bool split_file(int fd, int64_t max_size, std::vector<SparsePtr>* out);
50bool split_file(sparse_file* s, int64_t max_size, std::vector<SparsePtr>* out);
51
53 public:
54 virtual ~ImageSource(){};
55 virtual bool ReadFile(const std::string& name, std::vector<char>* out) const = 0;
56 virtual android::base::unique_fd OpenFile(const std::string& name) const = 0;
57};
android::base::unique_fd unique_fd
Definition: adb_unique_fd.h:32
Definition: util.h:52
virtual bool ReadFile(const std::string &name, std::vector< char > *out) const =0
virtual ~ImageSource()
Definition: util.h:54
virtual android::base::unique_fd OpenFile(const std::string &name) const =0
int64_t get_file_size(android::base::borrowed_fd fd)
double now()
Definition: util.cpp:46
std::unique_ptr< sparse_file, decltype(&sparse_file_destroy)> SparsePtr
Definition: util.h:29
std::string fb_fix_numeric_var(std::string var)
Definition: util.cpp:114
void void verbose(const char *fmt,...) __attribute__((__format__(__printf__
bool split_file(int fd, int64_t max_size, std::vector< SparsePtr > *out)
Definition: util.cpp:123
void die(const char *fmt,...) __attribute__((__noreturn__)) __attribute__((__format__(__printf__
void set_verbose()
Definition: util.cpp:66
bool is_sparse_file(android::base::borrowed_fd fd)
bool should_flash_in_userspace(const android::fs_mgr::LpMetadata &metadata, const std::string &partition_name)
Definition: util.cpp:83
Definition: version.h:22
absl::string_view metadata
Definition: android_composite_disk_config.cc:53
class incremental::File __attribute__