Debian Codegraph @

include/libvhdi.h.in

raw
1 /*
2 * Library to access the Virtual Hard Disk (VHD) image format
3 *
4 * Copyright (C) 2012-2025, Joachim Metz <[email protected]>
5 *
6 * Refer to AUTHORS for acknowledgements.
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #if !defined( _LIBVHDI_H )
23 #define _LIBVHDI_H
24
25 #include <libvhdi/codepage.h>
26 #include <libvhdi/definitions.h>
27 #include <libvhdi/error.h>
28 #include <libvhdi/extern.h>
29 #include <libvhdi/features.h>
30 #include <libvhdi/types.h>
31
32 #include <stdio.h>
33
34 #if defined( LIBVHDI_HAVE_BFIO )
35 #include <libbfio.h>
36 #endif
37
38 #if defined( __cplusplus )
39 extern "C" {
40 #endif
41
42 /* -------------------------------------------------------------------------
43 * Support functions
44 * ------------------------------------------------------------------------- */
45
46 /* Returns the library version
47 */
48 LIBVHDI_EXTERN \
49 const char *libvhdi_get_version(
50 void );
51
52 /* Returns the access flags for reading
53 */
54 LIBVHDI_EXTERN \
55 int libvhdi_get_access_flags_read(
56 void );
57
58 /* Returns the access flags for reading and writing
59 */
60 LIBVHDI_EXTERN \
61 int libvhdi_get_access_flags_read_write(
62 void );
63
64 /* Returns the access flags for writing
65 */
66 LIBVHDI_EXTERN \
67 int libvhdi_get_access_flags_write(
68 void );
69
70 /* Retrieves the narrow system string codepage
71 * A value of 0 represents no codepage, UTF-8 encoding is used instead
72 * Returns 1 if successful or -1 on error
73 */
74 LIBVHDI_EXTERN \
75 int libvhdi_get_codepage(
76 int *codepage,
77 libvhdi_error_t **error );
78
79 /* Sets the narrow system string codepage
80 * A value of 0 represents no codepage, UTF-8 encoding is used instead
81 * Returns 1 if successful or -1 on error
82 */
83 LIBVHDI_EXTERN \
84 int libvhdi_set_codepage(
85 int codepage,
86 libvhdi_error_t **error );
87
88 /* Determines if a file contains a VHDI file signature
89 * Returns 1 if true, 0 if not or -1 on error
90 */
91 LIBVHDI_EXTERN \
92 int libvhdi_check_file_signature(
93 const char *filename,
94 libvhdi_error_t **error );
95
96 #if defined( LIBVHDI_HAVE_WIDE_CHARACTER_TYPE )
97
98 /* Determines if a file contains a VHDI file signature
99 * Returns 1 if true, 0 if not or -1 on error
100 */
101 LIBVHDI_EXTERN \
102 int libvhdi_check_file_signature_wide(
103 const wchar_t *filename,
104 libvhdi_error_t **error );
105
106 #endif /* defined( LIBVHDI_HAVE_WIDE_CHARACTER_TYPE ) */
107
108 #if defined( LIBVHDI_HAVE_BFIO )
109
110 /* Determines if a file contains a VHDI file signature using a Basic File IO (bfio) handle
111 * Returns 1 if true, 0 if not or -1 on error
112 */
113 LIBVHDI_EXTERN \
114 int libvhdi_check_file_signature_file_io_handle(
115 libbfio_handle_t *file_io_handle,
116 libvhdi_error_t **error );
117
118 #endif /* defined( LIBVHDI_HAVE_BFIO ) */
119
120 /* -------------------------------------------------------------------------
121 * Notify functions
122 * ------------------------------------------------------------------------- */
123
124 /* Sets the verbose notification
125 */
126 LIBVHDI_EXTERN \
127 void libvhdi_notify_set_verbose(
128 int verbose );
129
130 /* Sets the notification stream
131 * Returns 1 if successful or -1 on error
132 */
133 LIBVHDI_EXTERN \
134 int libvhdi_notify_set_stream(
135 FILE *stream,
136 libvhdi_error_t **error );
137
138 /* Opens the notification stream using a filename
139 * The stream is opened in append mode
140 * Returns 1 if successful or -1 on error
141 */
142 LIBVHDI_EXTERN \
143 int libvhdi_notify_stream_open(
144 const char *filename,
145 libvhdi_error_t **error );
146
147 /* Closes the notification stream if opened using a filename
148 * Returns 0 if successful or -1 on error
149 */
150 LIBVHDI_EXTERN \
151 int libvhdi_notify_stream_close(
152 libvhdi_error_t **error );
153
154 /* -------------------------------------------------------------------------
155 * Error functions
156 * ------------------------------------------------------------------------- */
157
158 /* Frees an error
159 */
160 LIBVHDI_EXTERN \
161 void libvhdi_error_free(
162 libvhdi_error_t **error );
163
164 /* Prints a descriptive string of the error to the stream
165 * Returns the number of printed characters if successful or -1 on error
166 */
167 LIBVHDI_EXTERN \
168 int libvhdi_error_fprint(
169 libvhdi_error_t *error,
170 FILE *stream );
171
172 /* Prints a descriptive string of the error to the string
173 * The end-of-string character is not included in the return value
174 * Returns the number of printed characters if successful or -1 on error
175 */
176 LIBVHDI_EXTERN \
177 int libvhdi_error_sprint(
178 libvhdi_error_t *error,
179 char *string,
180 size_t size );
181
182 /* Prints a backtrace of the error to the stream
183 * Returns the number of printed characters if successful or -1 on error
184 */
185 LIBVHDI_EXTERN \
186 int libvhdi_error_backtrace_fprint(
187 libvhdi_error_t *error,
188 FILE *stream );
189
190 /* Prints a backtrace of the error to the string
191 * The end-of-string character is not included in the return value
192 * Returns the number of printed characters if successful or -1 on error
193 */
194 LIBVHDI_EXTERN \
195 int libvhdi_error_backtrace_sprint(
196 libvhdi_error_t *error,
197 char *string,
198 size_t size );
199
200 /* -------------------------------------------------------------------------
201 * File functions
202 * ------------------------------------------------------------------------- */
203
204 /* Creates a file
205 * Make sure the value file is referencing, is set to NULL
206 * Returns 1 if successful or -1 on error
207 */
208 LIBVHDI_EXTERN \
209 int libvhdi_file_initialize(
210 libvhdi_file_t **file,
211 libvhdi_error_t **error );
212
213 /* Frees a file
214 * Returns 1 if successful or -1 on error
215 */
216 LIBVHDI_EXTERN \
217 int libvhdi_file_free(
218 libvhdi_file_t **file,
219 libvhdi_error_t **error );
220
221 /* Signals a file to abort its current activity
222 * Returns 1 if successful or -1 on error
223 */
224 LIBVHDI_EXTERN \
225 int libvhdi_file_signal_abort(
226 libvhdi_file_t *file,
227 libvhdi_error_t **error );
228
229 /* Opens a file
230 * Returns 1 if successful or -1 on error
231 */
232 LIBVHDI_EXTERN \
233 int libvhdi_file_open(
234 libvhdi_file_t *file,
235 const char *filename,
236 int access_flags,
237 libvhdi_error_t **error );
238
239 #if defined( LIBVHDI_HAVE_WIDE_CHARACTER_TYPE )
240
241 /* Opens a file
242 * Returns 1 if successful or -1 on error
243 */
244 LIBVHDI_EXTERN \
245 int libvhdi_file_open_wide(
246 libvhdi_file_t *file,
247 const wchar_t *filename,
248 int access_flags,
249 libvhdi_error_t **error );
250
251 #endif /* defined( LIBVHDI_HAVE_WIDE_CHARACTER_TYPE ) */
252
253 #if defined( LIBVHDI_HAVE_BFIO )
254
255 /* Opens a file using a Basic File IO (bfio) handle
256 * Returns 1 if successful or -1 on error
257 */
258 LIBVHDI_EXTERN \
259 int libvhdi_file_open_file_io_handle(
260 libvhdi_file_t *file,
261 libbfio_handle_t *file_io_handle,
262 int access_flags,
263 libvhdi_error_t **error );
264
265 #endif /* defined( LIBVHDI_HAVE_BFIO ) */
266
267 /* Closes a file
268 * Returns 0 if successful or -1 on error
269 */
270 LIBVHDI_EXTERN \
271 int libvhdi_file_close(
272 libvhdi_file_t *file,
273 libvhdi_error_t **error );
274
275 /* Reads (media) data at the current offset
276 * Returns the number of bytes read or -1 on error
277 */
278 LIBVHDI_EXTERN \
279 ssize_t libvhdi_file_read_buffer(
280 libvhdi_file_t *file,
281 void *buffer,
282 size_t buffer_size,
283 libvhdi_error_t **error );
284
285 /* Reads (media) data at a specific offset
286 * Returns the number of bytes read or -1 on error
287 */
288 LIBVHDI_EXTERN \
289 ssize_t libvhdi_file_read_buffer_at_offset(
290 libvhdi_file_t *file,
291 void *buffer,
292 size_t buffer_size,
293 off64_t offset,
294 libvhdi_error_t **error );
295
296 /* Seeks a certain offset of the (media) data
297 * Returns the offset if seek is successful or -1 on error
298 */
299 LIBVHDI_EXTERN \
300 off64_t libvhdi_file_seek_offset(
301 libvhdi_file_t *file,
302 off64_t offset,
303 int whence,
304 libvhdi_error_t **error );
305
306 /* Retrieves the current offset of the (media) data
307 * Returns the offset if successful or -1 on error
308 */
309 LIBVHDI_EXTERN \
310 int libvhdi_file_get_offset(
311 libvhdi_file_t *file,
312 off64_t *offset,
313 libvhdi_error_t **error );
314
315 /* Sets the parent file of a differential image
316 * Returns 1 if successful or -1 on error
317 */
318 LIBVHDI_EXTERN \
319 int libvhdi_file_set_parent_file(
320 libvhdi_file_t *file,
321 libvhdi_file_t *parent_file,
322 libvhdi_error_t **error );
323
324 /* -------------------------------------------------------------------------
325 * Meta data functions
326 * ------------------------------------------------------------------------- */
327
328 /* Retrieves the file type
329 * Returns 1 if successful or -1 on error
330 */
331 LIBVHDI_EXTERN \
332 int libvhdi_file_get_file_type(
333 libvhdi_file_t *file,
334 int *file_type,
335 libvhdi_error_t **error );
336
337 /* Retrieves the format version
338 * Returns 1 if successful or -1 on error
339 */
340 LIBVHDI_EXTERN \
341 int libvhdi_file_get_format_version(
342 libvhdi_file_t *file,
343 uint16_t *major_version,
344 uint16_t *minor_version,
345 libvhdi_error_t **error );
346
347 /* Retrieves the disk type
348 * Returns 1 if successful or -1 on error
349 */
350 LIBVHDI_EXTERN \
351 int libvhdi_file_get_disk_type(
352 libvhdi_file_t *file,
353 uint32_t *disk_type,
354 libvhdi_error_t **error );
355
356 /* Retrieves the media size
357 * Returns the 1 if succesful or -1 on error
358 */
359 LIBVHDI_EXTERN \
360 int libvhdi_file_get_media_size(
361 libvhdi_file_t *file,
362 size64_t *media_size,
363 libvhdi_error_t **error );
364
365 /* Retrieves the number of bytes per (logical) sector
366 * Returns 1 if successful or -1 on error
367 */
368 LIBVHDI_EXTERN \
369 int libvhdi_file_get_bytes_per_sector(
370 libvhdi_file_t *file,
371 uint32_t *bytes_per_sector,
372 libvhdi_error_t **error );
373
374 /* Retrieves the identifier
375 * The identifier is a big-endian GUID and is 16 bytes of size
376 * For VHDX this value is obtained from the data write identifier
377 * Returns 1 if successful or -1 on error
378 */
379 LIBVHDI_EXTERN \
380 int libvhdi_file_get_identifier(
381 libvhdi_file_t *file,
382 uint8_t *guid_data,
383 size_t guid_data_size,
384 libvhdi_error_t **error );
385
386 /* Retrieves the parent identifier
387 * The identifier is a big-endian GUID and is 16 bytes of size
388 * Returns 1 if successful, 0 if not available or -1 on error
389 */
390 LIBVHDI_EXTERN \
391 int libvhdi_file_get_parent_identifier(
392 libvhdi_file_t *file,
393 uint8_t *guid_data,
394 size_t guid_data_size,
395 libvhdi_error_t **error );
396
397 /* Retrieves the size of the UTF-8 encoded parent filename
398 * The returned size includes the end of string character
399 * Returns 1 if successful, 0 if not available or -1 on error
400 */
401 LIBVHDI_EXTERN \
402 int libvhdi_file_get_utf8_parent_filename_size(
403 libvhdi_file_t *file,
404 size_t *utf8_string_size,
405 libvhdi_error_t **error );
406
407 /* Retrieves the UTF-8 encoded parent filename
408 * The size should include the end of string character
409 * Returns 1 if successful, 0 if not available or -1 on error
410 */
411 LIBVHDI_EXTERN \
412 int libvhdi_file_get_utf8_parent_filename(
413 libvhdi_file_t *file,
414 uint8_t *utf8_string,
415 size_t utf8_string_size,
416 libvhdi_error_t **error );
417
418 /* Retrieves the size of the UTF-16 encoded parent filename
419 * The returned size includes the end of string character
420 * Returns 1 if successful, 0 if not available or -1 on error
421 */
422 LIBVHDI_EXTERN \
423 int libvhdi_file_get_utf16_parent_filename_size(
424 libvhdi_file_t *file,
425 size_t *utf16_string_size,
426 libvhdi_error_t **error );
427
428 /* Retrieves the UTF-16 encoded parent filename
429 * The size should include the end of string character
430 * Returns 1 if successful, 0 if not available or -1 on error
431 */
432 LIBVHDI_EXTERN \
433 int libvhdi_file_get_utf16_parent_filename(
434 libvhdi_file_t *file,
435 uint16_t *utf16_string,
436 size_t utf16_string_size,
437 libvhdi_error_t **error );
438
439 #if defined( __cplusplus )
440 }
441 #endif
442
443 #endif /* !defined( _LIBVHDI_H ) */
444