libstorage-ng
BlkDevice.h
1 /*
2  * Copyright (c) [2014-2015] Novell, Inc.
3  * Copyright (c) [2016-2018] 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 "storage/Utils/Swig.h"
29 #include "storage/Devices/Device.h"
30 #include "storage/Filesystems/BlkFilesystem.h"
31 
32 
33 namespace storage
34 {
35 
36  class Region;
37  class Encryption;
38 
39 
41  class BlkDevice : public Device
42  {
43  public:
44 
45  const std::string& get_name() const;
46  void set_name(const std::string& name);
47 
48  const Region& get_region() const;
49 
53  void set_region(const Region& region);
54 
55  unsigned long long get_size() const;
56 
60  void set_size(unsigned long long size);
61 
62  std::string get_size_string() const;
63 
64  bool is_active() const;
65 
66  const std::string& get_sysfs_name() const;
67  const std::string& get_sysfs_path() const;
68 
69  const std::vector<std::string>& get_udev_paths() const;
70  const std::vector<std::string>& get_udev_ids() const;
71 
80  bool is_usable_as_blk_device() const;
81 
86  const std::string& get_dm_table_name() const;
87 
88  void set_dm_table_name(const std::string& dm_table_name);
89 
93  static std::vector<BlkDevice*> get_all(Devicegraph* devicegraph);
94 
98  static std::vector<const BlkDevice*> get_all(const Devicegraph* devicegraph);
99 
106  static BlkDevice* find_by_name(Devicegraph* devicegraph, const std::string& name);
107 
111  static const BlkDevice* find_by_name(const Devicegraph* devicegraph, const std::string& name);
112 
120  static BlkDevice* find_by_any_name(Devicegraph* devicegraph, const std::string& name);
121 
125  static const BlkDevice* find_by_any_name(const Devicegraph* devicegraph, const std::string& name);
126 
132  BlkFilesystem* create_blk_filesystem(FsType fs_type);
133 
134  bool has_blk_filesystem() const;
135 
140 
144  const BlkFilesystem* get_blk_filesystem() const;
145 
149  BlkFilesystem* create_filesystem(FsType fs_type) ST_DEPRECATED { return create_blk_filesystem(fs_type); }
150 
151  bool has_filesystem() const ST_DEPRECATED { return has_blk_filesystem(); }
152 
156  BlkFilesystem* get_filesystem() ST_DEPRECATED { return get_blk_filesystem(); }
157 
161  const BlkFilesystem* get_filesystem() const ST_DEPRECATED { return get_blk_filesystem(); }
162 
173  Encryption* create_encryption(const std::string& dm_name);
174 
181  void remove_encryption();
182 
183  bool has_encryption() const;
184 
189 
193  const Encryption* get_encryption() const;
194 
198  static bool compare_by_dm_table_name(const BlkDevice* lhs, const BlkDevice* rhs);
199 
200  public:
201 
202  class Impl;
203 
204  Impl& get_impl();
205  const Impl& get_impl() const;
206 
207  protected:
208 
209  BlkDevice(Impl* impl);
210 
211  };
212 
213 
214  bool is_blk_device(const Device* device);
215 
222  BlkDevice* to_blk_device(Device* device);
223 
227  const BlkDevice* to_blk_device(const Device* device);
228 
229 }
230 
231 #endif
static std::vector< BlkDevice * > get_all(Devicegraph *devicegraph)
Get all BlkDevices.
void set_size(unsigned long long size)
bool is_usable_as_blk_device() const
Checks whether the blk device is in general usable as a blk device.
Encryption * get_encryption()
Encryption * create_encryption(const std::string &dm_name)
Creates an encryption device on the blk device.
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.
BlkFilesystem * create_filesystem(FsType fs_type) ST_DEPRECATED
Creates a block filesystem on the block device.
Definition: BlkDevice.h:149
A start/length pair with a block size.
Definition: Region.h:73
BlkFilesystem * create_blk_filesystem(FsType fs_type)
Creates a block filesystem on the block 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:45
const std::string & get_dm_table_name() const
Return device-mapper table name (dm-table-name for short).
The master container of the libstorage.
Definition: Devicegraph.h:153
BlkFilesystem * get_blk_filesystem()
Definition: BlkFilesystem.h:42
An abstract Block Device.
Definition: BlkDevice.h:41
An abstract base class of storage devices, and a vertex in the Devicegraph.
Definition: Device.h:75
const BlkFilesystem * get_filesystem() const ST_DEPRECATED
Definition: BlkDevice.h:161
static bool compare_by_dm_table_name(const BlkDevice *lhs, const BlkDevice *rhs)
Compare (less than) two BlkDevices by DM table name.
void set_region(const Region &region)
The storage namespace.
Definition: Actiongraph.h:37
BlkFilesystem * get_filesystem() ST_DEPRECATED
Definition: BlkDevice.h:156
void remove_encryption()
Removes an encryption device on the blk device.
static BlkDevice * find_by_name(Devicegraph *devicegraph, const std::string &name)
Find a block device by its name.