Debian Codegraph @

src/lib/plugin_apis/loop.api

raw
1 #include <glib.h>
2 #include <blockdev/utils.h>
3
4 #ifndef BD_LOOP_API
5 #define BD_LOOP_API
6
7 GQuark bd_loop_error_quark (void) {
8 return g_quark_from_static_string ("g-bd-loop-error-quark");
9 }
10
11 #define BD_LOOP_ERROR bd_loop_error_quark ()
12 typedef enum {
13 BD_LOOP_ERROR_TECH_UNAVAIL,
14 BD_LOOP_ERROR_FAIL,
15 BD_LOOP_ERROR_DEVICE,
16 } BDLoopError;
17
18 typedef enum {
19 BD_LOOP_TECH_LOOP = 0,
20 } BDLoopTech;
21
22 typedef enum {
23 BD_LOOP_TECH_MODE_CREATE = 1 << 0,
24 BD_LOOP_TECH_MODE_DESTROY = 1 << 1,
25 BD_LOOP_TECH_MODE_MODIFY = 1 << 2,
26 BD_LOOP_TECH_MODE_QUERY = 1 << 3,
27 } BDLoopTechMode;
28
29 /**
30 * bd_loop_is_tech_avail:
31 * @tech: the queried tech
32 * @mode: a bit mask of queried modes of operation (#BDLoopTechMode) for @tech
33 * @error: (out) (optional): place to store error (details about why the @tech-@mode combination is not available)
34 *
35 * Returns: whether the @tech-@mode combination is available -- supported by the
36 * plugin implementation and having all the runtime dependencies available
37 */
38 gboolean bd_loop_is_tech_avail (BDLoopTech tech, guint64 mode, GError **error);
39
40 #define BD_LOOP_TYPE_INFO (bd_loop_info_get_type ())
41 GType bd_loop_info_get_type();
42
43 /**
44 * BDLoopInfo:
45 * @backing_file: backing file for the give loop device;
46 * @offset: offset of the start of the device (in @backing_file);
47 * @autoclear: whether the autoclear flag is set or not;
48 * @direct_io: whether direct IO is enabled or not;
49 * @part_scan: whether the partition scan is enforced or not;
50 * @read_only: whether the device is read-only or not;
51 */
52 typedef struct BDLoopInfo {
53 gchar *backing_file;
54 guint64 offset;
55 gboolean autoclear;
56 gboolean direct_io;
57 gboolean part_scan;
58 gboolean read_only;
59 } BDLoopInfo;
60
61 /**
62 * bd_loop_info_free: (skip)
63 * @info: (nullable): %BDLoopInfo to free
64 *
65 * Frees @info.
66 */
67 void bd_loop_info_free (BDLoopInfo *info) {
68 if (info == NULL)
69 return;
70
71 g_free (info->backing_file);
72 g_free (info);
73 }
74
75 /**
76 * bd_loop_info_copy: (skip)
77 * @info: (nullable): %BDLoopInfo to copy
78 *
79 * Creates a new copy of @info.
80 */
81 BDLoopInfo* bd_loop_info_copy (BDLoopInfo *info) {
82 if (info == NULL)
83 return NULL;
84
85 BDLoopInfo *new_info = g_new0 (BDLoopInfo, 1);
86
87 new_info->backing_file = g_strdup (info->backing_file);
88 new_info->offset = info->offset;
89 new_info->autoclear = info->autoclear;
90 new_info->direct_io = info->direct_io;
91 new_info->part_scan = info->part_scan;
92 new_info->read_only = info->read_only;
93
94 return new_info;
95 }
96
97 GType bd_loop_info_get_type () {
98 static GType type = 0;
99
100 if (G_UNLIKELY(type == 0)) {
101 type = g_boxed_type_register_static("BDLoopInfo",
102 (GBoxedCopyFunc) bd_loop_info_copy,
103 (GBoxedFreeFunc) bd_loop_info_free);
104 }
105
106 return type;
107 }
108
109 /**
110 * bd_loop_info:
111 * @loop: name of the loop device to get information about (e.g. "loop0")
112 * @error: (out) (optional): place to store error (if any)
113 *
114 * Returns: (transfer full): information about the @loop device or %NULL in case of error
115 *
116 * Tech category: %BD_LOOP_TECH_LOOP-%BD_LOOP_TECH_MODE_QUERY
117 */
118 BDLoopInfo* bd_loop_info (const gchar *loop, GError **error);
119
120 /**
121 * bd_loop_get_loop_name:
122 * @file: path of the backing file to get loop name for
123 * @error: (out) (optional): place to store error (if any)
124 *
125 * Returns: (transfer full): name of the loop device associated with the given
126 * @file or %NULL if failed to determine
127 *
128 * Tech category: %BD_LOOP_TECH_LOOP-%BD_LOOP_TECH_MODE_QUERY
129 */
130 gchar* bd_loop_get_loop_name (const gchar *file, GError **error);
131
132 /**
133 * bd_loop_setup:
134 * @file: file to setup as a loop device
135 * @offset: offset of the start of the device (in @file)
136 * @size: maximum size of the device (or 0 to leave unspecified)
137 * @read_only: whether to setup as read-only (%TRUE) or read-write (%FALSE)
138 * @part_scan: whether to enforce partition scan on the newly created device or not
139 * @sector_size: logical sector size for the loop device in bytes (or 0 for default)
140 * @loop_name: (optional) (out): if not %NULL, it is used to store the name of the loop device
141 * @error: (out) (optional): place to store error (if any)
142 *
143 * Returns: whether the @file was successfully setup as a loop device or not
144 *
145 * Tech category: %BD_LOOP_TECH_LOOP-%BD_LOOP_TECH_MODE_CREATE
146 */
147 gboolean bd_loop_setup (const gchar *file, guint64 offset, guint64 size, gboolean read_only, gboolean part_scan, guint64 sector_size, const gchar **loop_name, GError **error);
148
149 /**
150 * bd_loop_setup_from_fd:
151 * @fd: file descriptor for a file to setup as a new loop device
152 * @offset: offset of the start of the device (in file given by @fd)
153 * @size: maximum size of the device (or 0 to leave unspecified)
154 * @read_only: whether to setup as read-only (%TRUE) or read-write (%FALSE)
155 * @part_scan: whether to enforce partition scan on the newly created device or not
156 * @sector_size: logical sector size for the loop device in bytes (or 0 for default)
157 * @loop_name: (optional) (out): if not %NULL, it is used to store the name of the loop device
158 * @error: (out) (optional): place to store error (if any)
159 *
160 * Returns: whether a new loop device was successfully setup for @fd or not
161 *
162 * Tech category: %BD_LOOP_TECH_LOOP-%BD_LOOP_TECH_MODE_CREATE
163 */
164 gboolean bd_loop_setup_from_fd (gint fd, guint64 offset, guint64 size, gboolean read_only, gboolean part_scan, guint64 sector_size, const gchar **loop_name, GError **error);
165
166 /**
167 * bd_loop_teardown:
168 * @loop: path or name of the loop device to tear down
169 * @error: (out) (optional): place to store error (if any)
170 *
171 * Returns: whether the @loop device was successfully torn down or not
172 *
173 * Tech category: %BD_LOOP_TECH_LOOP-%BD_LOOP_TECH_MODE_DESTROY
174 */
175 gboolean bd_loop_teardown (const gchar *loop, GError **error);
176
177 /**
178 * bd_loop_set_autoclear:
179 * @loop: path or name of the loop device
180 * @autoclear: whether to set or unset the autoclear flag
181 * @error: (out) (optional): place to store error (if any)
182 *
183 * Returns: whether the autoclear flag was successfully set on the @loop device or not
184 *
185 * Tech category: %BD_LOOP_TECH_LOOP-%BD_LOOP_TECH_MODE_MODIFY
186 */
187 gboolean bd_loop_set_autoclear (const gchar *loop, gboolean autoclear, GError **error);
188
189 /**
190 * bd_loop_set_capacity:
191 * @loop: path or name of the loop device
192 * @error: (out) (optional): place to store error (if any)
193 *
194 * Force the loop driver to reread the size of the file associated with the
195 * specified @loop device.
196 *
197 * Returns: whether the LOOP_SET_CAPACITY ioctl was successfully issued or not.
198 *
199 * Tech category: %BD_LOOP_TECH_LOOP-%BD_LOOP_TECH_MODE_MODIFY
200 */
201 gboolean bd_loop_set_capacity (const gchar *loop, GError **error);
202
203 #endif /* BD_LOOP_API */