libstorage-ng
BlkDevice.h
1 /*
2  * Copyright (c) [2014-2015] Novell, Inc.
3  * Copyright (c) [2016-2020] 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 
44 
46  class BlkDevice : public Device
47  {
48  public:
49 
50  const std::string& get_name() const;
51  void set_name(const std::string& name);
52 
53  const Region& get_region() const;
54 
58  void set_region(const Region& region);
59 
63  unsigned long long get_size() const;
64 
71  void set_size(unsigned long long size);
72 
79  std::string get_size_string() const;
80 
84  const Topology& get_topology() const;
85 
89  void set_topology(const Topology& topology);
90 
91  bool is_active() const;
92 
97  bool is_read_only() const;
98 
99  const std::string& get_sysfs_name() const;
100  const std::string& get_sysfs_path() const;
101 
113  const std::vector<std::string>& get_udev_paths() const;
114 
126  const std::vector<std::string>& get_udev_ids() const;
127 
138 
143  const std::string& get_dm_table_name() const;
144 
150  void set_dm_table_name(const std::string& dm_table_name);
151 
155  static std::vector<BlkDevice*> get_all(Devicegraph* devicegraph);
156 
160  static std::vector<const BlkDevice*> get_all(const Devicegraph* devicegraph);
161 
168  static BlkDevice* find_by_name(Devicegraph* devicegraph, const std::string& name);
169 
173  static const BlkDevice* find_by_name(const Devicegraph* devicegraph, const std::string& name);
174 
182  static BlkDevice* find_by_any_name(Devicegraph* devicegraph, const std::string& name);
183 
187  static const BlkDevice* find_by_any_name(const Devicegraph* devicegraph, const std::string& name);
188 
195 
199  bool has_blk_filesystem() const;
200 
207 
212 
216  BlkFilesystem* create_filesystem(FsType fs_type) ST_DEPRECATED { return create_blk_filesystem(fs_type); }
217 
221  bool has_filesystem() const ST_DEPRECATED { return has_blk_filesystem(); }
222 
226  BlkFilesystem* get_filesystem() ST_DEPRECATED { return get_blk_filesystem(); }
227 
231  const BlkFilesystem* get_filesystem() const ST_DEPRECATED { return get_blk_filesystem(); }
232 
241  Encryption* create_encryption(const std::string& dm_name) ST_DEPRECATED;
242 
255  Encryption* create_encryption(const std::string& dm_name, EncryptionType type);
256 
264 
268  bool has_encryption() const;
269 
276 
280  const Encryption* get_encryption() const;
281 
286  Bcache* create_bcache(const std::string& name);
287 
291  bool has_bcache() const;
292 
299 
303  const Bcache* get_bcache() const;
304 
311 
315  bool has_bcache_cset() const;
316 
323 
327  const BcacheCset* get_bcache_cset() const;
328 
336  static bool compare_by_dm_table_name(const BlkDevice* lhs, const BlkDevice* rhs);
337 
341  std::vector<MountByType> possible_mount_bys() const;
342 
343  public:
344 
345  class Impl;
346 
347  Impl& get_impl();
348  const Impl& get_impl() const;
349 
350  protected:
351 
352  BlkDevice(Impl* impl);
353 
354  };
355 
356 
362  bool is_blk_device(const Device* device);
363 
371 
375  const BlkDevice* to_blk_device(const Device* device);
376 
377 }
378 
379 #endif
storage::BlkDevice::get_encryption
Encryption * get_encryption()
Return the Encryption of the block device.
storage::BlkDevice::get_filesystem
BlkFilesystem * get_filesystem() ST_DEPRECATED
Return the block filesystem of the block device.
Definition: BlkDevice.h:226
storage::BlkDevice::find_by_any_name
static const BlkDevice * find_by_any_name(const Devicegraph *devicegraph, const std::string &name)
Find a block device by any name including any symbolic links in /dev.
storage::BlkDevice::create_encryption
Encryption * create_encryption(const std::string &dm_name, EncryptionType type)
Creates an encryption device on the blk device.
storage::Region
A start/length pair with a block size.
Definition: Region.h:74
storage::BlkDevice::get_bcache
const Bcache * get_bcache() const
Return the Bcache of the block device.
storage::BlkDevice::find_by_name
static BlkDevice * find_by_name(Devicegraph *devicegraph, const std::string &name)
Find a block device by its name.
storage::BlkDevice::set_topology
void set_topology(const Topology &topology)
Set the topology.
storage::Topology
A class to represent hardware alignment information.
Definition: Topology.h:39
storage::BlkDevice::has_bcache
bool has_bcache() const
Return whether the block device has a BCache.
storage::BlkDevice::compare_by_dm_table_name
static bool compare_by_dm_table_name(const BlkDevice *lhs, const BlkDevice *rhs)
Compare (less than) two BlkDevices by DM table name.
storage::BlkDevice::get_filesystem
const BlkFilesystem * get_filesystem() const ST_DEPRECATED
Return the block filesystem of the block device.
Definition: BlkDevice.h:231
storage::BlkDevice::create_blk_filesystem
BlkFilesystem * create_blk_filesystem(FsType fs_type)
Creates a block filesystem on the block device.
storage
The storage namespace.
Definition: Actiongraph.h:39
storage::BlkDevice::get_bcache_cset
BcacheCset * get_bcache_cset()
Return the BcacheCset of the block device.
storage::BlkDevice::get_all
static std::vector< BlkDevice * > get_all(Devicegraph *devicegraph)
Get all BlkDevices.
storage::Encryption
An encryption layer on a blk device.
Definition: Encryption.h:46
storage::BlkDevice::create_filesystem
BlkFilesystem * create_filesystem(FsType fs_type) ST_DEPRECATED
Creates a block filesystem on the block device.
Definition: BlkDevice.h:216
storage::BlkDevice::has_bcache_cset
bool has_bcache_cset() const
Return whether the block device has a BcacheCset.
storage::BlkDevice::find_by_name
static const BlkDevice * find_by_name(const Devicegraph *devicegraph, const std::string &name)
Find a block device by its name.
storage::BcacheCset
A bcache cache set.
Definition: BcacheCset.h:42
storage::BlkDevice::get_blk_filesystem
const BlkFilesystem * get_blk_filesystem() const
Return the block filesystem of the block device.
storage::BlkDevice::find_by_any_name
static BlkDevice * find_by_any_name(Devicegraph *devicegraph, const std::string &name)
Find a block device by any name including any symbolic links in /dev.
storage::BlkDevice
An abstract Block Device.
Definition: BlkDevice.h:47
storage::to_blk_device
BlkDevice * to_blk_device(Device *device)
Converts pointer to Device to pointer to BlkDevice.
storage::Devicegraph
The main container of the libstorage-ng.
Definition: Devicegraph.h:170
storage::BlkDevice::get_topology
const Topology & get_topology() const
Get the topology.
storage::BlkDevice::create_encryption
Encryption * create_encryption(const std::string &dm_name) ST_DEPRECATED
Creates an encryption device on the blk device.
storage::BlkDevice::get_blk_filesystem
BlkFilesystem * get_blk_filesystem()
Return the block filesystem of the block device.
storage::BlkDevice::get_encryption
const Encryption * get_encryption() const
Return the Encryption of the block device.
storage::BlkDevice::possible_mount_bys
std::vector< MountByType > possible_mount_bys() const
Returns the possible mount-by methods to reference the block device.
storage::BlkDevice::create_bcache
Bcache * create_bcache(const std::string &name)
Creates a Bcache on the blk device.
storage::BlkDevice::get_dm_table_name
const std::string & get_dm_table_name() const
Return device-mapper table name (dm-table-name for short).
storage::BlkDevice::create_bcache_cset
BcacheCset * create_bcache_cset()
Creates a BcacheCset on the blk device.
storage::BlkDevice::is_read_only
bool is_read_only() const
Return whether the block device is read-only.
storage::Bcache
A bcache device.
Definition: Bcache.h:63
storage::BlkDevice::has_blk_filesystem
bool has_blk_filesystem() const
Return whether the block device has a block filesystem.
storage::BlkDevice::is_usable_as_blk_device
bool is_usable_as_blk_device() const
Checks whether the blk device is in general usable as a blk device.
storage::BlkDevice::get_udev_ids
const std::vector< std::string > & get_udev_ids() const
Return the names of the udev by-id links of the blk device.
storage::BlkDevice::set_dm_table_name
void set_dm_table_name(const std::string &dm_table_name)
Set the device-mapper table name (dm-table-name for short).
storage::BlkDevice::has_filesystem
bool has_filesystem() const ST_DEPRECATED
Return whether the block device has a block filesystem.
Definition: BlkDevice.h:221
storage::Device
An abstract base class for storage devices.
Definition: Device.h:82
storage::BlkDevice::remove_encryption
void remove_encryption()
Removes an encryption device on the blk device.
storage::BlkDevice::set_size
void set_size(unsigned long long size)
Set the size of the block device.
storage::BlkDevice::get_size_string
std::string get_size_string() const
Returns the size of the block device as a localised string.
storage::BlkDevice::set_region
void set_region(const Region &region)
storage::BlkDevice::get_size
unsigned long long get_size() const
Returns the size of the block device.
storage::BlkFilesystem
Definition: BlkFilesystem.h:43
storage::BlkDevice::get_udev_paths
const std::vector< std::string > & get_udev_paths() const
Return the names of the udev by-path links of the blk device.
storage::is_blk_device
bool is_blk_device(const Device *device)
Checks whether device points to an BlkDevice.
storage::BlkDevice::get_bcache
Bcache * get_bcache()
Return the Bcache of the block device.
storage::BlkDevice::get_bcache_cset
const BcacheCset * get_bcache_cset() const
Return the BcacheCset of the block device.
storage::BlkDevice::has_encryption
bool has_encryption() const
Return whether the block device has an Encryption.
storage::BlkDevice::get_all
static std::vector< const BlkDevice * > get_all(const Devicegraph *devicegraph)
Get all BlkDevices.