libstorage-ng
Loading...
Searching...
No Matches
BlkDevice.h
1/*
2 * Copyright (c) [2014-2015] Novell, Inc.
3 * Copyright (c) [2016-2025] SUSE LLC
4 *
5 * All Rights Reserved.
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as published
9 * by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, contact Novell, Inc.
18 *
19 * To contact Novell about this file by physical or electronic mail, you may
20 * find current contact information at www.novell.com.
21 */
22
23
24#ifndef STORAGE_BLK_DEVICE_H
25#define STORAGE_BLK_DEVICE_H
26
27
28#include <vector>
29
30#include "storage/Utils/Swig.h"
31#include "storage/Devices/Device.h"
32#include "storage/Filesystems/BlkFilesystem.h"
33
34
35namespace storage
36{
37
38 class Region;
39 class Topology;
40 class Encryption;
41 enum class EncryptionType;
42 class Bcache;
43 class BcacheCset;
44 class RemoveInfo;
45 class SystemInfo;
46
47
49 class BlkDevice : public Device
50 {
51 public:
52
56 const std::string& get_name() const;
57
63 void set_name(const std::string& name);
64
65 const Region& get_region() const;
66
70 void set_region(const Region& region);
71
75 unsigned long long get_size() const;
76
83 void set_size(unsigned long long size);
84
91 std::string get_size_string() const;
92
96 const Topology& get_topology() const;
97
101 void set_topology(const Topology& topology);
102
103 bool is_active() const;
104
109 bool is_read_only() const;
110
111 const std::string& get_sysfs_name() const;
112 const std::string& get_sysfs_path() const;
113
125 const std::vector<std::string>& get_udev_paths() const;
126
138 const std::vector<std::string>& get_udev_ids() const;
139
150
160
165 const std::string& get_dm_table_name() const;
166
172 void set_dm_table_name(const std::string& dm_table_name);
173
177 static bool is_valid_dm_table_name(const std::string& dm_table_name);
178
182 static std::vector<BlkDevice*> get_all(Devicegraph* devicegraph);
183
187 static std::vector<const BlkDevice*> get_all(const Devicegraph* devicegraph);
188
195 static BlkDevice* find_by_name(Devicegraph* devicegraph, const std::string& name);
196
200 static const BlkDevice* find_by_name(const Devicegraph* devicegraph, const std::string& name);
201
210 static bool exists_by_any_name(const Devicegraph* devicegraph, const std::string& name,
211 SystemInfo& system_info);
212
220 static BlkDevice* find_by_any_name(Devicegraph* devicegraph, const std::string& name) ST_DEPRECATED;
221
229 static BlkDevice* find_by_any_name(Devicegraph* devicegraph, const std::string& name,
230 SystemInfo& system_info);
231
235 static const BlkDevice* find_by_any_name(const Devicegraph* devicegraph, const std::string& name) ST_DEPRECATED;
236
240 static const BlkDevice* find_by_any_name(const Devicegraph* devicegraph, const std::string& name,
241 SystemInfo& system_info);
242
249
253 bool has_blk_filesystem() const;
254
261
266
270 BlkFilesystem* create_filesystem(FsType fs_type) ST_DEPRECATED { return create_blk_filesystem(fs_type); }
271
275 bool has_filesystem() const ST_DEPRECATED { return has_blk_filesystem(); }
276
280 BlkFilesystem* get_filesystem() ST_DEPRECATED { return get_blk_filesystem(); }
281
285 const BlkFilesystem* get_filesystem() const ST_DEPRECATED { return get_blk_filesystem(); }
286
295 Encryption* create_encryption(const std::string& dm_table_name) ST_DEPRECATED;
296
309 Encryption* create_encryption(const std::string& dm_table_name, EncryptionType type);
310
318
322 bool has_encryption() const;
323
330
335
340 Bcache* create_bcache(const std::string& name);
341
345 bool has_bcache() const;
346
353
357 const Bcache* get_bcache() const;
358
365
369 bool has_bcache_cset() const;
370
377
382
390 static bool compare_by_dm_table_name(const BlkDevice* lhs, const BlkDevice* rhs);
391
397 std::vector<MountByType> possible_mount_bys() const;
398
399 public:
400
401 class Impl;
402
403 Impl& get_impl();
404 const Impl& get_impl() const;
405
406 protected:
407
408 BlkDevice(Impl* impl);
409 ST_NO_SWIG BlkDevice(std::unique_ptr<Device::Impl>&& impl);
410
411 };
412
413
419 bool is_blk_device(const Device* device);
420
428
432 const BlkDevice* to_blk_device(const Device* device);
433
434}
435
436#endif
A bcache cache set.
Definition BcacheCset.h:42
A bcache device.
Definition Bcache.h:79
An abstract Block Device.
Definition BlkDevice.h:50
BlkFilesystem * get_blk_filesystem()
Return the block filesystem of the block device.
unsigned long long get_size() const
Returns the size of the block device.
Bcache * create_bcache(const std::string &name)
Creates a Bcache on the blk device.
BcacheCset * get_bcache_cset()
Return the BcacheCset of the block device.
BcacheCset * create_bcache_cset()
Creates a BcacheCset on the blk device.
const std::vector< std::string > & get_udev_ids() const
Return the names of the udev by-id links of the blk device.
BlkFilesystem * get_filesystem() ST_DEPRECATED
Return the block filesystem of the block device.
Definition BlkDevice.h:280
void set_region(const Region &region)
const Topology & get_topology() const
Get the topology.
bool is_read_only() const
Return whether the block device is read-only.
bool has_blk_filesystem() const
Return whether the block device has a block filesystem.
const BlkFilesystem * get_filesystem() const ST_DEPRECATED
Return the block filesystem of the block device.
Definition BlkDevice.h:285
static const BlkDevice * find_by_name(const Devicegraph *devicegraph, const std::string &name)
Find a block device by its name.
bool has_encryption() const
Return whether the block device has an Encryption.
bool is_usable_as_blk_device() const
Checks whether the blk device is in general usable as a blk device.
std::vector< MountByType > possible_mount_bys() const
Returns the possible mount-by methods to reference the block device.
Encryption * get_encryption()
Return the Encryption of the block device.
static bool exists_by_any_name(const Devicegraph *devicegraph, const std::string &name, SystemInfo &system_info)
Check if a block device by any name including any symbolic links in /dev.
static bool compare_by_dm_table_name(const BlkDevice *lhs, const BlkDevice *rhs)
Compare (less than) two BlkDevices by DM table name.
const BcacheCset * get_bcache_cset() const
Return the BcacheCset of the block device.
Bcache * get_bcache()
Return the Bcache of the block device.
bool has_filesystem() const ST_DEPRECATED
Return whether the block device has a block filesystem.
Definition BlkDevice.h:275
const Encryption * get_encryption() const
Return the Encryption of the block device.
const std::string & get_name() const
Get the device name.
static BlkDevice * find_by_any_name(Devicegraph *devicegraph, const std::string &name, SystemInfo &system_info)
Find a block device by any name including any symbolic links in /dev.
void set_name(const std::string &name)
Set the device name.
static std::vector< const BlkDevice * > get_all(const Devicegraph *devicegraph)
Get all BlkDevices.
std::string get_size_string() const
Returns the size of the block device as a localised string.
static bool is_valid_dm_table_name(const std::string &dm_table_name)
Check whether the DM table name is valid.
const std::string & get_dm_table_name() const
Return device-mapper table name (dm-table-name for short).
Encryption * create_encryption(const std::string &dm_table_name) ST_DEPRECATED
Creates an encryption device on the blk device.
const BlkFilesystem * get_blk_filesystem() const
Return the block filesystem of the block device.
static BlkDevice * find_by_name(Devicegraph *devicegraph, const std::string &name)
Find a block device by its name.
BlkFilesystem * create_filesystem(FsType fs_type) ST_DEPRECATED
Creates a block filesystem on the block device.
Definition BlkDevice.h:270
RemoveInfo detect_remove_info() const
Check whether the device can be removed.
const std::vector< std::string > & get_udev_paths() const
Return the names of the udev by-path links of the blk device.
Encryption * create_encryption(const std::string &dm_table_name, EncryptionType type)
Creates an encryption device on the blk device.
static const BlkDevice * find_by_any_name(const Devicegraph *devicegraph, const std::string &name) ST_DEPRECATED
Find a block device by any name including any symbolic links in /dev.
BlkFilesystem * create_blk_filesystem(FsType fs_type)
Creates a block filesystem on the block device.
void set_size(unsigned long long size)
Set the size of the block device.
static std::vector< BlkDevice * > get_all(Devicegraph *devicegraph)
Get all BlkDevices.
void set_dm_table_name(const std::string &dm_table_name)
Set the device-mapper table name (dm-table-name for short).
bool has_bcache_cset() const
Return whether the block device has a BcacheCset.
static const BlkDevice * find_by_any_name(const Devicegraph *devicegraph, const std::string &name, SystemInfo &system_info)
Find a block device by any name including any symbolic links in /dev.
static BlkDevice * find_by_any_name(Devicegraph *devicegraph, const std::string &name) ST_DEPRECATED
Find a block device by any name including any symbolic links in /dev.
void remove_encryption()
Removes an encryption device on the blk device.
bool has_bcache() const
Return whether the block device has a BCache.
const Bcache * get_bcache() const
Return the Bcache of the block device.
void set_topology(const Topology &topology)
Set the topology.
Definition BlkFilesystem.h:43
An abstract base class for storage devices.
Definition Device.h:82
The main container of the libstorage-ng.
Definition Devicegraph.h:170
An encryption layer on a blk device.
Definition Encryption.h:55
A start/length pair with a block size.
Definition Region.h:85
Definition FreeInfo.h:294
The SystemInfo class keeps various system information.
Definition SystemInfo.h:49
A class to represent hardware alignment information.
Definition Topology.h:39
The storage namespace.
Definition Actiongraph.h:40
bool is_blk_device(const Device *device)
Checks whether device points to an BlkDevice.
BlkDevice * to_blk_device(Device *device)
Converts pointer to Device to pointer to BlkDevice.