libstorage-ng
Mountable.h
1 /*
2  * Copyright (c) [2014-2015] Novell, Inc.
3  * Copyright (c) [2016-2026] 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_MOUNTABLE_H
25 #define STORAGE_MOUNTABLE_H
26 
27 
28 #include <vector>
29 
30 #include "storage/Devices/Device.h"
31 #include "storage/Utils/Swig.h"
32 
33 
34 namespace storage
35 {
36 
37  class MountPoint;
38  class Filesystem;
39 
40 
41  enum class FsType {
42  UNKNOWN, AUTO, REISERFS, EXT2, EXT3, EXT4, BTRFS, VFAT, XFS, JFS, HFS, NTFS,
43  SWAP, HFSPLUS, NFS, NFS4, TMPFS, ISO9660, UDF, NILFS2, MINIX, NTFS3G, F2FS,
44  EXFAT, BITLOCKER, VBOXSF, BCACHEFS, SQUASHFS, EROFS1 /* EROFS is a POSIX
45  define */
46  };
47 
48 
54  std::string get_fs_type_name(FsType fs_type);
55 
56 
61  enum class MountByType {
62 
67  DEVICE,
68 
72  UUID,
73 
77  LABEL,
78 
82  ID,
83 
87  PATH,
88 
92  PARTUUID,
93 
97  PARTLABEL,
98 
99  };
100 
101 
107  std::string get_mount_by_name(MountByType mount_by_type);
108 
109 
110  // abstract class
111 
112  class Mountable : public Device
113  {
114  public:
115 
119  static std::vector<Mountable*> get_all(Devicegraph* devicegraph);
120 
124  static std::vector<const Mountable*> get_all(const Devicegraph* devicegraph);
125 
135  bool supports_mount() const;
136 
141  static bool is_valid_path(FsType fs_type, const std::string& path);
142 
148  MountPoint* create_mount_point(const std::string& path);
149 
153  bool has_mount_point() const;
154 
159 
163  const MountPoint* get_mount_point() const;
164 
170  void remove_mount_point();
171 
175  bool has_filesystem() const;
176 
182 
186  const Filesystem* get_filesystem() const;
187 
188  MountByType get_mount_by() const ST_DEPRECATED;
189  void set_mount_by(MountByType mount_by) ST_DEPRECATED;
190 
191  const std::vector<std::string>& get_mount_opts() const ST_DEPRECATED;
192  void set_mount_opts(const std::vector<std::string>& mount_opts) ST_DEPRECATED;
193 
194  const std::vector<std::string>& get_fstab_options() const ST_DEPRECATED;
195  void set_fstab_options(const std::vector<std::string>& mount_opts) ST_DEPRECATED;
196 
197  public:
198 
199  class Impl;
200 
201  Impl& get_impl();
202  const Impl& get_impl() const;
203 
204  protected:
205 
206  Mountable(Impl* impl);
207  ST_NO_SWIG Mountable(std::unique_ptr<Device::Impl>&& impl);
208 
209  };
210 
211 
217  bool is_mountable(const Device* device);
218 
225  Mountable* to_mountable(Device* device);
226 
230  const Mountable* to_mountable(const Device* device);
231 
232 }
233 
234 #endif
Filesystem label.
One of the links in /dev/disk/by-id.
bool has_filesystem() const
Checks whether the mountable has a filesystem.
Filesystem * get_filesystem()
Return the filesystem of the mountable.
MountPoint * create_mount_point(const std::string &path)
Create a new mount point for the mountable with path.
bool has_mount_point() const
Checks whether the mountable has a mount point.
The main container of the libstorage-ng.
Definition: Devicegraph.h:169
Definition: Mountable.h:112
bool supports_mount() const
Checks whether the library supports mounting the mountable.
bool is_mountable(const Device *device)
Checks whether device points to a Mountable.
Class to represent a mount point.
Definition: MountPoint.h:48
static bool is_valid_path(FsType fs_type, const std::string &path)
Checks whether the path is valid.
MountPoint * get_mount_point()
Returns the mount point of the mountable.
One of the links in /dev/disk/by-path.
An abstract base class for storage devices.
Definition: Device.h:81
Partition UUID, only for partitions on GPT.
Partition label, only for partitions on GPT.
std::string get_mount_by_name(MountByType mount_by_type)
Convert the MountByType mount_by_type to a string.
Definition: Filesystem.h:40
static std::vector< Mountable * > get_all(Devicegraph *devicegraph)
Get all Mountables.
The storage namespace.
Definition: Actiongraph.h:39
std::string get_fs_type_name(FsType fs_type)
Convert the FsType fs_type to a string.
The kernel device name or a link in /dev (but not in /dev/disk).
Mountable * to_mountable(Device *device)
Converts pointer to Device to pointer to Mountable.
void remove_mount_point()
Removes the mount point from the mountable.
MountByType
The key by which the mount program identifies a mountable.
Definition: Mountable.h:61