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  const std::string& get_sysfs_name() const;
65  const std::string& get_sysfs_path() const;
66 
67  const std::vector<std::string>& get_udev_paths() const;
68  const std::vector<std::string>& get_udev_ids() const;
69 
78  bool is_usable_as_blk_device() const;
79 
84  const std::string& get_dm_table_name() const;
85 
86  void set_dm_table_name(const std::string& dm_table_name);
87 
91  static std::vector<BlkDevice*> get_all(Devicegraph* devicegraph);
92 
96  static std::vector<const BlkDevice*> get_all(const Devicegraph* devicegraph);
97 
104  static BlkDevice* find_by_name(Devicegraph* devicegraph, const std::string& name);
105 
109  static const BlkDevice* find_by_name(const Devicegraph* devicegraph, const std::string& name);
110 
118  static BlkDevice* find_by_any_name(Devicegraph* devicegraph, const std::string& name);
119 
123  static const BlkDevice* find_by_any_name(const Devicegraph* devicegraph, const std::string& name);
124 
130  BlkFilesystem* create_blk_filesystem(FsType fs_type);
131 
132  bool has_blk_filesystem() const;
133 
138 
142  const BlkFilesystem* get_blk_filesystem() const;
143 
147  BlkFilesystem* create_filesystem(FsType fs_type) ST_DEPRECATED { return create_blk_filesystem(fs_type); }
148 
149  bool has_filesystem() const ST_DEPRECATED { return has_blk_filesystem(); }
150 
154  BlkFilesystem* get_filesystem() ST_DEPRECATED { return get_blk_filesystem(); }
155 
159  const BlkFilesystem* get_filesystem() const ST_DEPRECATED { return get_blk_filesystem(); }
160 
171  Encryption* create_encryption(const std::string& dm_name);
172 
179  void remove_encryption();
180 
181  bool has_encryption() const;
182 
187 
191  const Encryption* get_encryption() const;
192 
196  static bool compare_by_dm_table_name(const BlkDevice* lhs, const BlkDevice* rhs);
197 
198  public:
199 
200  class Impl;
201 
202  Impl& get_impl();
203  const Impl& get_impl() const;
204 
205  protected:
206 
207  BlkDevice(Impl* impl);
208 
209  };
210 
211 
212  bool is_blk_device(const Device* device);
213 
220  BlkDevice* to_blk_device(Device* device);
221 
225  const BlkDevice* to_blk_device(const Device* device);
226 
227 }
228 
229 #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:147
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:159
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:154
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.