1 //
2 // Copyright (C) 2022 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 #pragma once
17 
18 #include <chrono>
19 #include <string>
20 #include <vector>
21 
22 #include "common/libs/utils/result.h"
23 #include "host/libs/config/cuttlefish_config.h"
24 #include "host/libs/image_aggregator/image_aggregator.h"
25 
26 namespace cuttlefish {
27 
28 class DiskBuilder {
29  public:
30   DiskBuilder& EntireDisk(std::string path) &;
31   DiskBuilder EntireDisk(std::string path) &&;
32 
33   DiskBuilder& Partitions(std::vector<ImagePartition> partitions) &;
34   DiskBuilder Partitions(std::vector<ImagePartition> partitions) &&;
35 
36   DiskBuilder& HeaderPath(std::string header_path) &;
37   DiskBuilder HeaderPath(std::string header_path) &&;
38 
39   DiskBuilder& FooterPath(std::string footer_path) &;
40   DiskBuilder FooterPath(std::string footer_path) &&;
41 
42   DiskBuilder& CrosvmPath(std::string crosvm_path) &;
43   DiskBuilder CrosvmPath(std::string crosvm_path) &&;
44 
45   DiskBuilder& VmManager(VmmMode vm_manager) &;
46   DiskBuilder VmManager(VmmMode vm_manager) &&;
47 
48   DiskBuilder& ConfigPath(std::string config_path) &;
49   DiskBuilder ConfigPath(std::string config_path) &&;
50 
51   DiskBuilder& CompositeDiskPath(std::string composite_disk_path) &;
52   DiskBuilder CompositeDiskPath(std::string composite_disk_path) &&;
53 
54   DiskBuilder& OverlayPath(std::string overlay_path) &;
55   DiskBuilder OverlayPath(std::string overlay_path) &&;
56 
57   DiskBuilder& ResumeIfPossible(bool resume_if_possible) &;
58   DiskBuilder ResumeIfPossible(bool resume_if_possible) &&;
59 
60   Result<bool> WillRebuildCompositeDisk();
61   /** Returns `true` if the file was actually rebuilt. */
62   Result<bool> BuildCompositeDiskIfNecessary();
63   /** Returns `true` if the file was actually rebuilt. */
64   Result<bool> BuildOverlayIfNecessary();
65 
66  private:
67   Result<std::string> TextConfig();
68 
69   std::vector<ImagePartition> partitions_;
70   std::string entire_disk_;
71   std::string header_path_;
72   std::string footer_path_;
73   VmmMode vm_manager_ = VmmMode::kUnknown;
74   std::string crosvm_path_;
75   std::string config_path_;
76   std::string composite_disk_path_;
77   std::string overlay_path_;
78   bool resume_if_possible_;
79 };
80 
81 }  // namespace cuttlefish
82