libstorage-ng
BlkDevice.h
1 /*
2  * Copyright (c) [2014-2015] Novell, Inc.
3  * Copyright (c) [2016-2021] 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 #include <vector>
28 
29 #include "storage/Utils/Swig.h"
30 #include "storage/Devices/Device.h"
31 #include "storage/Filesystems/BlkFilesystem.h"
32 
33 
34 namespace storage
35 {
36 
37  class Region;
38  class Topology;
39  class Encryption;
40  enum class EncryptionType;
41  class Bcache;
42  class BcacheCset;
43  class RemoveInfo;
44  class SystemInfo;
45 
46 
48  class BlkDevice : public Device
49  {
50  public:
51 
52  const std::string& get_name() const;
53  void set_name(const std::string& name);
54 
55  const Region& get_region() const;
56 
60  void set_region(const Region& region);
61 
65  unsigned long long get_size() const;
66 
73  void set_size(unsigned long long size);
74 
81  std::string get_size_string() const;
82 
86  const Topology& get_topology() const;
87 
91  void set_topology(const Topology& topology);
92 
93  bool is_active() const;
94 
99  bool is_read_only() const;
100 
101  const std::string& get_sysfs_name() const;
102  const std::string& get_sysfs_path() const;
103 
115  const std::vector<std::string>& get_udev_paths() const;
116 
128  const std::vector<std::string>& get_udev_ids() const;
129 
139  bool is_usable_as_blk_device() const;
140 
150 
155  const std::string& get_dm_table_name() const;
156 
162  void set_dm_table_name(const std::string& dm_table_name);
163 
167  static std::vector<BlkDevice*> get_all(Devicegraph* devicegraph);
168 
172  static std::vector<const BlkDevice*> get_all(const Devicegraph* devicegraph);
173 
180  static BlkDevice* find_by_name(Devicegraph* devicegraph, const std::string& name);
181 
185  static const BlkDevice* find_by_name(const Devicegraph* devicegraph, const std::string& name);
186 
195  static bool exists_by_any_name(const Devicegraph* devicegraph, const std::string& name,
196  SystemInfo& system_info);
197 
205  static BlkDevice* find_by_any_name(Devicegraph* devicegraph, const std::string& name) ST_DEPRECATED;
206 
214  static BlkDevice* find_by_any_name(Devicegraph* devicegraph, const std::string& name,
215  SystemInfo& system_info);
216 
220  static const BlkDevice* find_by_any_name(const Devicegraph* devicegraph, const std::string& name) ST_DEPRECATED;
221 
225  static const BlkDevice* find_by_any_name(const Devicegraph* devicegraph, const std::string& name,
226  SystemInfo& system_info);
227 
233  BlkFilesystem* create_blk_filesystem(FsType fs_type);
234 
238  bool has_blk_filesystem() const;
239 
246 
250  const BlkFilesystem* get_blk_filesystem() const;
251 
255  BlkFilesystem* create_filesystem(FsType fs_type) ST_DEPRECATED { return create_blk_filesystem(fs_type); }
256 
260  bool has_filesystem() const ST_DEPRECATED { return has_blk_filesystem(); }
261 
265  BlkFilesystem* get_filesystem() ST_DEPRECATED { return get_blk_filesystem(); }
266 
270  const BlkFilesystem* get_filesystem() const ST_DEPRECATED { return get_blk_filesystem(); }
271 
280  Encryption* create_encryption(const std::string& dm_table_name) ST_DEPRECATED;
281 
294  Encryption* create_encryption(const std::string& dm_table_name, EncryptionType type);
295 
302  void remove_encryption();
303 
307  bool has_encryption() const;
308 
315 
319  const Encryption* get_encryption() const;
320 
325  Bcache* create_bcache(const std::string& name);
326 
330  bool has_bcache() const;
331 
337  Bcache* get_bcache();
338 
342  const Bcache* get_bcache() const;
343 
350 
354  bool has_bcache_cset() const;
355 
362 
366  const BcacheCset* get_bcache_cset() const;
367 
375  static bool compare_by_dm_table_name(const BlkDevice* lhs, const BlkDevice* rhs);
376 
382  std::vector<MountByType> possible_mount_bys() const;
383 
384  public:
385 
386  class Impl;
387 
388  Impl& get_impl();
389  const Impl& get_impl() const;
390 
391  protected:
392 
393  BlkDevice(Impl* impl);
394 
395  };
396 
397 
403  bool is_blk_device(const Device* device);
404 
411  BlkDevice* to_blk_device(Device* device);
412 
416  const BlkDevice* to_blk_device(const Device* device);
417 
418 }
419 
420 #endif
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.
static std::vector< BlkDevice * > get_all(Devicegraph *devicegraph)
Get all BlkDevices.
void set_size(unsigned long long size)
Set the size of the block device.
bool is_usable_as_blk_device() const
Checks whether the blk device is in general usable as a blk device.
Encryption * get_encryption()
Return the Encryption of the block device.
bool has_encryption() const
Return whether the block device has an Encryption.
RemoveInfo detect_remove_info() const
Check whether the device can be removed.
bool has_filesystem() const ST_DEPRECATED
Return whether the block device has a block filesystem.
Definition: BlkDevice.h:260
A bcache device.
Definition: Bcache.h:62
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.
BlkFilesystem * create_filesystem(FsType fs_type) ST_DEPRECATED
Creates a block filesystem on the block device.
Definition: BlkDevice.h:255
A start/length pair with a block size.
Definition: Region.h:84
void set_dm_table_name(const std::string &dm_table_name)
Set the device-mapper table name (dm-table-name for short).
BlkFilesystem * create_blk_filesystem(FsType fs_type)
Creates a block filesystem on the block device.
const std::vector< std::string > & get_udev_paths() const
Return the names of the udev by-path links of 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.
BlkDevice * to_blk_device(Device *device)
Converts pointer to Device to pointer to BlkDevice.
An encryption layer on a blk device.
Definition: Encryption.h:54
const std::string & get_dm_table_name() const
Return device-mapper table name (dm-table-name for short).
The main container of the libstorage-ng.
Definition: Devicegraph.h:169
const Topology & get_topology() const
Get the topology.
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.
Definition: BlkFilesystem.h:42
An abstract Block Device.
Definition: BlkDevice.h:48
Encryption * create_encryption(const std::string &dm_table_name) ST_DEPRECATED
Creates an encryption device on the blk device.
bool has_bcache() const
Return whether the block device has a BCache.
void set_topology(const Topology &topology)
Set the topology.
An abstract base class for storage devices.
Definition: Device.h:81
A bcache cache set.
Definition: BcacheCset.h:41
const BlkFilesystem * get_filesystem() const ST_DEPRECATED
Return the block filesystem of the block device.
Definition: BlkDevice.h:270
static bool compare_by_dm_table_name(const BlkDevice *lhs, const BlkDevice *rhs)
Compare (less than) two BlkDevices by DM table name.
bool is_read_only() const
Return whether the block device is read-only.
void set_region(const Region &region)
The SystemInfo class keeps various system information.
Definition: SystemInfo.h:41
bool has_blk_filesystem() const
Return whether the block device has a block filesystem.
A class to represent hardware alignment information.
Definition: Topology.h:38
The storage namespace.
Definition: Actiongraph.h:39
BcacheCset * create_bcache_cset()
Creates a BcacheCset on the blk device.
std::string get_size_string() const
Returns the size of the block device as a localised string.
bool has_bcache_cset() const
Return whether the block device has a BcacheCset.
Bcache * get_bcache()
Return the Bcache of the block device.
Definition: FreeInfo.h:285
BlkFilesystem * get_filesystem() ST_DEPRECATED
Return the block filesystem of the block device.
Definition: BlkDevice.h:265
bool is_blk_device(const Device *device)
Checks whether device points to an BlkDevice.
void remove_encryption()
Removes an encryption device on the blk device.
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.
static BlkDevice * find_by_name(Devicegraph *devicegraph, const std::string &name)
Find a block device by its name.
std::vector< MountByType > possible_mount_bys() const
Returns the possible mount-by methods to reference the block device.