File: disk.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (207 lines) | stat: -rw-r--r-- 5,888 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chromeos/ash/components/disks/disk.h"

#include <utility>

#include "base/files/file_path.h"
#include "base/memory/ptr_util.h"

namespace ash {
namespace disks {

namespace {
constexpr char kStatefulPartition[] = "/mnt/stateful_partition";
}  // namespace

Disk::Disk(const DiskInfo& disk_info,
           bool write_disabled_by_policy,
           const std::string& base_mount_path)
    : device_path_(disk_info.device_path()),
      mount_path_(disk_info.mount_path()),
      write_disabled_by_policy_(write_disabled_by_policy),
      file_path_(disk_info.file_path()),
      device_label_(disk_info.label()),
      drive_label_(disk_info.drive_label()),
      vendor_id_(disk_info.vendor_id()),
      vendor_name_(disk_info.vendor_name()),
      product_id_(disk_info.product_id()),
      product_name_(disk_info.product_name()),
      fs_uuid_(disk_info.uuid()),
      storage_device_path_(disk_info.storage_device_path()),
      device_type_(disk_info.device_type()),
      bus_number_(disk_info.bus_number()),
      device_number_(disk_info.device_number()),
      total_size_in_bytes_(disk_info.total_size_in_bytes()),
      is_parent_(disk_info.is_drive()),
      is_read_only_hardware_(disk_info.is_read_only()),
      has_media_(disk_info.has_media()),
      on_boot_device_(disk_info.on_boot_device()),
      on_removable_device_(disk_info.on_removable_device()),
      is_hidden_(disk_info.is_hidden()),
      is_auto_mountable_(disk_info.is_auto_mountable()),
      // cros-disks only provides mount paths if the disk is actually mounted.
      is_mounted_(!disk_info.mount_path().empty()),
      file_system_type_(disk_info.file_system_type()),
      base_mount_path_(base_mount_path) {}

Disk::Disk() = default;

Disk::Disk(const Disk&) = default;

Disk::~Disk() = default;

void Disk::SetMountPath(const std::string& mount_path) {
  mount_path_ = mount_path;

  if (base_mount_path_.empty())
    base_mount_path_ = mount_path;
}

bool Disk::IsStatefulPartition() const {
  return mount_path_ == kStatefulPartition;
}

Disk::Builder::Builder() : disk_(base::WrapUnique(new Disk())) {}

Disk::Builder::~Builder() = default;

Disk::Builder& Disk::Builder::SetDevicePath(const std::string& device_path) {
  disk_->device_path_ = device_path;
  return *this;
}

Disk::Builder& Disk::Builder::SetMountPath(const std::string& mount_path) {
  disk_->mount_path_ = mount_path;
  return *this;
}

Disk::Builder& Disk::Builder::SetWriteDisabledByPolicy(
    bool write_disabled_by_policy) {
  disk_->write_disabled_by_policy_ = write_disabled_by_policy;
  return *this;
}
Disk::Builder& Disk::Builder::SetFilePath(const std::string& file_path) {
  disk_->file_path_ = file_path;
  return *this;
}
Disk::Builder& Disk::Builder::SetDeviceLabel(const std::string& device_label) {
  disk_->device_label_ = device_label;
  return *this;
}
Disk::Builder& Disk::Builder::SetDriveLabel(const std::string& drive_label) {
  disk_->drive_label_ = drive_label;
  return *this;
}

Disk::Builder& Disk::Builder::SetVendorId(const std::string& vendor_id) {
  disk_->vendor_id_ = vendor_id;
  return *this;
}

Disk::Builder& Disk::Builder::SetVendorName(const std::string& vendor_name) {
  disk_->vendor_name_ = vendor_name;
  return *this;
}

Disk::Builder& Disk::Builder::SetProductId(const std::string& product_id) {
  disk_->product_id_ = product_id;
  return *this;
}

Disk::Builder& Disk::Builder::SetProductName(const std::string& product_name) {
  disk_->product_name_ = product_name;
  return *this;
}

Disk::Builder& Disk::Builder::SetFileSystemUUID(const std::string& fs_uuid) {
  disk_->fs_uuid_ = fs_uuid;
  return *this;
}

Disk::Builder& Disk::Builder::SetStorageDevicePath(
    const std::string& storage_device_path) {
  disk_->storage_device_path_ = storage_device_path;
  return *this;
}

Disk::Builder& Disk::Builder::SetDeviceType(DeviceType device_type) {
  disk_->device_type_ = device_type;
  return *this;
}

Disk::Builder& Disk::Builder::SetBusNumber(int bus_number) {
  disk_->bus_number_ = bus_number;
  return *this;
}

Disk::Builder& Disk::Builder::SetDeviceNumber(int device_number) {
  disk_->device_number_ = device_number;
  return *this;
}

Disk::Builder& Disk::Builder::SetSizeInBytes(uint64_t total_size_in_bytes) {
  disk_->total_size_in_bytes_ = total_size_in_bytes;
  return *this;
}

Disk::Builder& Disk::Builder::SetIsParent(bool is_parent) {
  disk_->is_parent_ = is_parent;
  return *this;
}

Disk::Builder& Disk::Builder::SetIsReadOnlyHardware(
    bool is_read_only_hardware) {
  disk_->is_read_only_hardware_ = is_read_only_hardware;
  return *this;
}

Disk::Builder& Disk::Builder::SetHasMedia(bool has_media) {
  disk_->has_media_ = has_media;
  return *this;
}

Disk::Builder& Disk::Builder::SetOnBootDevice(bool on_boot_device) {
  disk_->on_boot_device_ = on_boot_device;
  return *this;
}

Disk::Builder& Disk::Builder::SetOnRemovableDevice(bool on_removable_device) {
  disk_->on_removable_device_ = on_removable_device;
  return *this;
}

Disk::Builder& Disk::Builder::SetIsHidden(bool is_hidden) {
  disk_->is_hidden_ = is_hidden;
  return *this;
}

Disk::Builder& Disk::Builder::SetFileSystemType(
    const std::string& file_system_type) {
  disk_->file_system_type_ = file_system_type;
  return *this;
}

Disk::Builder& Disk::Builder::SetBaseMountPath(
    const std::string& base_mount_path) {
  disk_->base_mount_path_ = base_mount_path;
  return *this;
}

std::unique_ptr<Disk> Disk::Builder::Build() {
  return std::move(disk_);
}

Disk::Builder& Disk::Builder::SetIsMounted(bool is_mounted) {
  disk_->is_mounted_ = is_mounted;
  return *this;
}

base::FilePath GetStatefulPartitionPath() {
  return base::FilePath(kStatefulPartition);
}

}  // namespace disks
}  // namespace ash