/src/libvslvm/libvslvm/libvslvm_volume_group.c
Line | Count | Source |
1 | | /* |
2 | | * Volume group functions |
3 | | * |
4 | | * Copyright (C) 2014-2024, Joachim Metz <joachim.metz@gmail.com> |
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 | | #include <common.h> |
23 | | #include <memory.h> |
24 | | #include <types.h> |
25 | | |
26 | | #include "libvslvm_io_handle.h" |
27 | | #include "libvslvm_libbfio.h" |
28 | | #include "libvslvm_libcdata.h" |
29 | | #include "libvslvm_libcerror.h" |
30 | | #include "libvslvm_logical_volume.h" |
31 | | #include "libvslvm_logical_volume_values.h" |
32 | | #include "libvslvm_physical_volume.h" |
33 | | #include "libvslvm_types.h" |
34 | | #include "libvslvm_volume_group.h" |
35 | | |
36 | | /* Creates a volume group |
37 | | * Make sure the value volume_group is referencing, is set to NULL |
38 | | * Returns 1 if successful or -1 on error |
39 | | */ |
40 | | int libvslvm_volume_group_initialize( |
41 | | libvslvm_volume_group_t **volume_group, |
42 | | libcerror_error_t **error ) |
43 | 4.13k | { |
44 | 4.13k | libvslvm_internal_volume_group_t *internal_volume_group = NULL; |
45 | 4.13k | static char *function = "libvslvm_volume_group_initialize"; |
46 | | |
47 | 4.13k | if( volume_group == NULL ) |
48 | 0 | { |
49 | 0 | libcerror_error_set( |
50 | 0 | error, |
51 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
52 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
53 | 0 | "%s: invalid volume group.", |
54 | 0 | function ); |
55 | |
|
56 | 0 | return( -1 ); |
57 | 0 | } |
58 | 4.13k | if( *volume_group != NULL ) |
59 | 0 | { |
60 | 0 | libcerror_error_set( |
61 | 0 | error, |
62 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
63 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
64 | 0 | "%s: invalid volume group value already set.", |
65 | 0 | function ); |
66 | |
|
67 | 0 | return( -1 ); |
68 | 0 | } |
69 | 4.13k | internal_volume_group = memory_allocate_structure( |
70 | 4.13k | libvslvm_internal_volume_group_t ); |
71 | | |
72 | 4.13k | if( internal_volume_group == NULL ) |
73 | 0 | { |
74 | 0 | libcerror_error_set( |
75 | 0 | error, |
76 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
77 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
78 | 0 | "%s: unable to create volume group.", |
79 | 0 | function ); |
80 | |
|
81 | 0 | goto on_error; |
82 | 0 | } |
83 | 4.13k | if( memory_set( |
84 | 4.13k | internal_volume_group, |
85 | 4.13k | 0, |
86 | 4.13k | sizeof( libvslvm_internal_volume_group_t ) ) == NULL ) |
87 | 0 | { |
88 | 0 | libcerror_error_set( |
89 | 0 | error, |
90 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
91 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
92 | 0 | "%s: unable to clear volume group.", |
93 | 0 | function ); |
94 | |
|
95 | 0 | memory_free( |
96 | 0 | internal_volume_group ); |
97 | |
|
98 | 0 | return( -1 ); |
99 | 0 | } |
100 | 4.13k | if( libcdata_array_initialize( |
101 | 4.13k | &( internal_volume_group->physical_volumes_array ), |
102 | 4.13k | 0, |
103 | 4.13k | error ) != 1 ) |
104 | 0 | { |
105 | 0 | libcerror_error_set( |
106 | 0 | error, |
107 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
108 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
109 | 0 | "%s: unable to create physical volumes array.", |
110 | 0 | function ); |
111 | |
|
112 | 0 | goto on_error; |
113 | 0 | } |
114 | 4.13k | if( libcdata_array_initialize( |
115 | 4.13k | &( internal_volume_group->logical_volumes_array ), |
116 | 4.13k | 0, |
117 | 4.13k | error ) != 1 ) |
118 | 0 | { |
119 | 0 | libcerror_error_set( |
120 | 0 | error, |
121 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
122 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
123 | 0 | "%s: unable to create logical volumes array.", |
124 | 0 | function ); |
125 | |
|
126 | 0 | goto on_error; |
127 | 0 | } |
128 | 4.13k | *volume_group = (libvslvm_volume_group_t *) internal_volume_group; |
129 | | |
130 | 4.13k | return( 1 ); |
131 | | |
132 | 0 | on_error: |
133 | 0 | if( internal_volume_group != NULL ) |
134 | 0 | { |
135 | 0 | if( internal_volume_group->physical_volumes_array != NULL ) |
136 | 0 | { |
137 | 0 | libcdata_array_free( |
138 | 0 | &( internal_volume_group->physical_volumes_array ), |
139 | 0 | NULL, |
140 | 0 | NULL ); |
141 | 0 | } |
142 | 0 | memory_free( |
143 | 0 | internal_volume_group ); |
144 | 0 | } |
145 | 0 | return( -1 ); |
146 | 4.13k | } |
147 | | |
148 | | /* Frees a volume group |
149 | | * Returns 1 if successful or -1 on error |
150 | | */ |
151 | | int libvslvm_volume_group_free( |
152 | | libvslvm_volume_group_t **volume_group, |
153 | | libcerror_error_t **error ) |
154 | 450 | { |
155 | 450 | static char *function = "libvslvm_volume_group_free"; |
156 | | |
157 | 450 | if( volume_group == NULL ) |
158 | 0 | { |
159 | 0 | libcerror_error_set( |
160 | 0 | error, |
161 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
162 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
163 | 0 | "%s: invalid volume group.", |
164 | 0 | function ); |
165 | |
|
166 | 0 | return( -1 ); |
167 | 0 | } |
168 | 450 | if( *volume_group != NULL ) |
169 | 450 | { |
170 | 450 | *volume_group = NULL; |
171 | 450 | } |
172 | 450 | return( 1 ); |
173 | 450 | } |
174 | | |
175 | | /* Frees a volume group |
176 | | * Returns 1 if successful or -1 on error |
177 | | */ |
178 | | int libvslvm_internal_volume_group_free( |
179 | | libvslvm_internal_volume_group_t **internal_volume_group, |
180 | | libcerror_error_t **error ) |
181 | 4.13k | { |
182 | 4.13k | static char *function = "libvslvm_internal_volume_group_free"; |
183 | 4.13k | int result = 1; |
184 | | |
185 | 4.13k | if( internal_volume_group == NULL ) |
186 | 0 | { |
187 | 0 | libcerror_error_set( |
188 | 0 | error, |
189 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
190 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
191 | 0 | "%s: invalid volume group.", |
192 | 0 | function ); |
193 | |
|
194 | 0 | return( -1 ); |
195 | 0 | } |
196 | 4.13k | if( *internal_volume_group != NULL ) |
197 | 4.13k | { |
198 | | /* The io_handle and physical_volume_file_io_pool references are freed elsewhere |
199 | | */ |
200 | 4.13k | if( ( *internal_volume_group )->name != NULL ) |
201 | 4.12k | { |
202 | 4.12k | memory_free( |
203 | 4.12k | ( *internal_volume_group )->name ); |
204 | 4.12k | } |
205 | 4.13k | if( libcdata_array_free( |
206 | 4.13k | &( ( *internal_volume_group )->physical_volumes_array ), |
207 | 4.13k | (int (*)(intptr_t **, libcerror_error_t **)) &libvslvm_internal_physical_volume_free, |
208 | 4.13k | error ) != 1 ) |
209 | 0 | { |
210 | 0 | libcerror_error_set( |
211 | 0 | error, |
212 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
213 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
214 | 0 | "%s: unable to free physical volumes array.", |
215 | 0 | function ); |
216 | |
|
217 | 0 | result = -1; |
218 | 0 | } |
219 | 4.13k | if( libcdata_array_free( |
220 | 4.13k | &( ( *internal_volume_group )->logical_volumes_array ), |
221 | 4.13k | (int (*)(intptr_t **, libcerror_error_t **)) &libvslvm_logical_volume_values_free, |
222 | 4.13k | error ) != 1 ) |
223 | 0 | { |
224 | 0 | libcerror_error_set( |
225 | 0 | error, |
226 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
227 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
228 | 0 | "%s: unable to free logical volumes array.", |
229 | 0 | function ); |
230 | |
|
231 | 0 | result = -1; |
232 | 0 | } |
233 | 4.13k | memory_free( |
234 | 4.13k | *internal_volume_group ); |
235 | | |
236 | 4.13k | *internal_volume_group = NULL; |
237 | 4.13k | } |
238 | 4.13k | return( result ); |
239 | 4.13k | } |
240 | | |
241 | | /* Sets the IO values |
242 | | * Returns 1 if successful or -1 on error |
243 | | */ |
244 | | int libvslvm_volume_group_set_io_values( |
245 | | libvslvm_volume_group_t *volume_group, |
246 | | libvslvm_io_handle_t *io_handle, |
247 | | libbfio_pool_t *physical_volume_file_io_pool, |
248 | | libcerror_error_t **error ) |
249 | 450 | { |
250 | 450 | libvslvm_internal_volume_group_t *internal_volume_group = NULL; |
251 | 450 | static char *function = "libvslvm_volume_group_set_io_values"; |
252 | | |
253 | 450 | if( volume_group == NULL ) |
254 | 0 | { |
255 | 0 | libcerror_error_set( |
256 | 0 | error, |
257 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
258 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
259 | 0 | "%s: invalid volume group.", |
260 | 0 | function ); |
261 | |
|
262 | 0 | return( -1 ); |
263 | 0 | } |
264 | 450 | internal_volume_group = (libvslvm_internal_volume_group_t *) volume_group; |
265 | | |
266 | 450 | if( io_handle == NULL ) |
267 | 0 | { |
268 | 0 | libcerror_error_set( |
269 | 0 | error, |
270 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
271 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
272 | 0 | "%s: invalid IO handle.", |
273 | 0 | function ); |
274 | |
|
275 | 0 | return( -1 ); |
276 | 0 | } |
277 | 450 | internal_volume_group->io_handle = io_handle; |
278 | 450 | internal_volume_group->physical_volume_file_io_pool = physical_volume_file_io_pool; |
279 | | |
280 | 450 | return( 1 ); |
281 | 450 | } |
282 | | |
283 | | /* Retrieves the size of the ASCII formatted name |
284 | | * Returns 1 if successful or -1 on error |
285 | | */ |
286 | | int libvslvm_volume_group_get_name_size( |
287 | | libvslvm_volume_group_t *volume_group, |
288 | | size_t *name_size, |
289 | | libcerror_error_t **error ) |
290 | 0 | { |
291 | 0 | libvslvm_internal_volume_group_t *internal_volume_group = NULL; |
292 | 0 | static char *function = "libvslvm_volume_group_get_name_size"; |
293 | |
|
294 | 0 | if( volume_group == NULL ) |
295 | 0 | { |
296 | 0 | libcerror_error_set( |
297 | 0 | error, |
298 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
299 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
300 | 0 | "%s: invalid volume group.", |
301 | 0 | function ); |
302 | |
|
303 | 0 | return( -1 ); |
304 | 0 | } |
305 | 0 | internal_volume_group = (libvslvm_internal_volume_group_t *) volume_group; |
306 | |
|
307 | 0 | if( name_size == NULL ) |
308 | 0 | { |
309 | 0 | libcerror_error_set( |
310 | 0 | error, |
311 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
312 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
313 | 0 | "%s: invalid name size.", |
314 | 0 | function ); |
315 | |
|
316 | 0 | return( -1 ); |
317 | 0 | } |
318 | 0 | *name_size = internal_volume_group->name_size; |
319 | |
|
320 | 0 | return( 1 ); |
321 | 0 | } |
322 | | |
323 | | /* Retrieves the ASCII formatted name |
324 | | * Returns 1 if successful or -1 on error |
325 | | */ |
326 | | int libvslvm_volume_group_get_name( |
327 | | libvslvm_volume_group_t *volume_group, |
328 | | char *name, |
329 | | size_t name_size, |
330 | | libcerror_error_t **error ) |
331 | 0 | { |
332 | 0 | libvslvm_internal_volume_group_t *internal_volume_group = NULL; |
333 | 0 | static char *function = "libvslvm_volume_group_get_name"; |
334 | |
|
335 | 0 | if( volume_group == NULL ) |
336 | 0 | { |
337 | 0 | libcerror_error_set( |
338 | 0 | error, |
339 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
340 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
341 | 0 | "%s: invalid volume group.", |
342 | 0 | function ); |
343 | |
|
344 | 0 | return( -1 ); |
345 | 0 | } |
346 | 0 | internal_volume_group = (libvslvm_internal_volume_group_t *) volume_group; |
347 | |
|
348 | 0 | if( name == NULL ) |
349 | 0 | { |
350 | 0 | libcerror_error_set( |
351 | 0 | error, |
352 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
353 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
354 | 0 | "%s: invalid name.", |
355 | 0 | function ); |
356 | |
|
357 | 0 | return( -1 ); |
358 | 0 | } |
359 | 0 | if( name_size > (size_t) SSIZE_MAX ) |
360 | 0 | { |
361 | 0 | libcerror_error_set( |
362 | 0 | error, |
363 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
364 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
365 | 0 | "%s: invalid name size value exceeds maximum.", |
366 | 0 | function ); |
367 | |
|
368 | 0 | return( -1 ); |
369 | 0 | } |
370 | 0 | if( name_size < internal_volume_group->name_size ) |
371 | 0 | { |
372 | 0 | libcerror_error_set( |
373 | 0 | error, |
374 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
375 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, |
376 | 0 | "%s: invalid name size value too small.", |
377 | 0 | function ); |
378 | |
|
379 | 0 | return( -1 ); |
380 | 0 | } |
381 | 0 | if( memory_copy( |
382 | 0 | name, |
383 | 0 | internal_volume_group->name, |
384 | 0 | internal_volume_group->name_size ) == NULL ) |
385 | 0 | { |
386 | 0 | libcerror_error_set( |
387 | 0 | error, |
388 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
389 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
390 | 0 | "%s: unable to copy name.", |
391 | 0 | function ); |
392 | |
|
393 | 0 | return( -1 ); |
394 | 0 | } |
395 | 0 | name[ internal_volume_group->name_size - 1 ] = 0; |
396 | |
|
397 | 0 | return( 1 ); |
398 | 0 | } |
399 | | |
400 | | /* Sets the name |
401 | | * Returns 1 if successful or -1 on error |
402 | | */ |
403 | | int libvslvm_internal_volume_group_set_name( |
404 | | libvslvm_internal_volume_group_t *internal_volume_group, |
405 | | const char *name, |
406 | | size_t name_size, |
407 | | libcerror_error_t **error ) |
408 | 4.12k | { |
409 | 4.12k | static char *function = "libvslvm_internal_volume_group_set_name"; |
410 | | |
411 | 4.12k | if( internal_volume_group == NULL ) |
412 | 0 | { |
413 | 0 | libcerror_error_set( |
414 | 0 | error, |
415 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
416 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
417 | 0 | "%s: invalid volume group.", |
418 | 0 | function ); |
419 | |
|
420 | 0 | return( -1 ); |
421 | 0 | } |
422 | 4.12k | if( internal_volume_group->name != NULL ) |
423 | 0 | { |
424 | 0 | libcerror_error_set( |
425 | 0 | error, |
426 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
427 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
428 | 0 | "%s: invalid volume group - name value already set.", |
429 | 0 | function ); |
430 | |
|
431 | 0 | return( -1 ); |
432 | 0 | } |
433 | 4.12k | if( name == NULL ) |
434 | 0 | { |
435 | 0 | libcerror_error_set( |
436 | 0 | error, |
437 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
438 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
439 | 0 | "%s: invalid name.", |
440 | 0 | function ); |
441 | |
|
442 | 0 | return( -1 ); |
443 | 0 | } |
444 | 4.12k | if( ( name_size == 0 ) |
445 | 4.12k | || ( name_size > (size_t) MEMORY_MAXIMUM_ALLOCATION_SIZE ) ) |
446 | 0 | { |
447 | 0 | libcerror_error_set( |
448 | 0 | error, |
449 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
450 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, |
451 | 0 | "%s: invalid name size value out of bounds.", |
452 | 0 | function ); |
453 | |
|
454 | 0 | return( -1 ); |
455 | 0 | } |
456 | 4.12k | internal_volume_group->name = (char *) memory_allocate( |
457 | 4.12k | sizeof( char ) * name_size ); |
458 | | |
459 | 4.12k | if( internal_volume_group->name == NULL ) |
460 | 0 | { |
461 | 0 | libcerror_error_set( |
462 | 0 | error, |
463 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
464 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
465 | 0 | "%s: unable to create name.", |
466 | 0 | function ); |
467 | |
|
468 | 0 | goto on_error; |
469 | 0 | } |
470 | 4.12k | if( memory_copy( |
471 | 4.12k | internal_volume_group->name, |
472 | 4.12k | name, |
473 | 4.12k | name_size ) == NULL ) |
474 | 0 | { |
475 | 0 | libcerror_error_set( |
476 | 0 | error, |
477 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
478 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
479 | 0 | "%s: unable to copy name.", |
480 | 0 | function ); |
481 | |
|
482 | 0 | goto on_error; |
483 | 0 | } |
484 | 4.12k | internal_volume_group->name[ name_size - 1 ] = 0; |
485 | | |
486 | 4.12k | internal_volume_group->name_size = name_size; |
487 | | |
488 | 4.12k | return( 1 ); |
489 | | |
490 | 0 | on_error: |
491 | 0 | if( internal_volume_group->name != NULL ) |
492 | 0 | { |
493 | 0 | memory_free( |
494 | 0 | internal_volume_group->name ); |
495 | |
|
496 | 0 | internal_volume_group->name = NULL; |
497 | 0 | } |
498 | 0 | internal_volume_group->name_size = 0; |
499 | |
|
500 | 0 | return( -1 ); |
501 | 4.12k | } |
502 | | |
503 | | /* Retrieves the size of the ASCII formatted identifier |
504 | | * Returns 1 if successful or -1 on error |
505 | | */ |
506 | | int libvslvm_volume_group_get_identifier_size( |
507 | | libvslvm_volume_group_t *volume_group, |
508 | | size_t *identifier_size, |
509 | | libcerror_error_t **error ) |
510 | 0 | { |
511 | 0 | libvslvm_internal_volume_group_t *internal_volume_group = NULL; |
512 | 0 | static char *function = "libvslvm_volume_group_get_identifier_size"; |
513 | |
|
514 | 0 | if( volume_group == NULL ) |
515 | 0 | { |
516 | 0 | libcerror_error_set( |
517 | 0 | error, |
518 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
519 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
520 | 0 | "%s: invalid volume group.", |
521 | 0 | function ); |
522 | |
|
523 | 0 | return( -1 ); |
524 | 0 | } |
525 | 0 | internal_volume_group = (libvslvm_internal_volume_group_t *) volume_group; |
526 | |
|
527 | 0 | if( identifier_size == NULL ) |
528 | 0 | { |
529 | 0 | libcerror_error_set( |
530 | 0 | error, |
531 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
532 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
533 | 0 | "%s: invalid identifier size.", |
534 | 0 | function ); |
535 | |
|
536 | 0 | return( -1 ); |
537 | 0 | } |
538 | 0 | if( internal_volume_group->identifier[ 0 ] == 0 ) |
539 | 0 | { |
540 | 0 | *identifier_size = 0; |
541 | 0 | } |
542 | 0 | else |
543 | 0 | { |
544 | 0 | *identifier_size = 39; |
545 | 0 | } |
546 | 0 | return( 1 ); |
547 | 0 | } |
548 | | |
549 | | /* Retrieves the ASCII formatted identifier |
550 | | * Returns 1 if successful or -1 on error |
551 | | */ |
552 | | int libvslvm_volume_group_get_identifier( |
553 | | libvslvm_volume_group_t *volume_group, |
554 | | char *identifier, |
555 | | size_t identifier_size, |
556 | | libcerror_error_t **error ) |
557 | 0 | { |
558 | 0 | libvslvm_internal_volume_group_t *internal_volume_group = NULL; |
559 | 0 | static char *function = "libvslvm_volume_group_set_identifier"; |
560 | |
|
561 | 0 | if( volume_group == NULL ) |
562 | 0 | { |
563 | 0 | libcerror_error_set( |
564 | 0 | error, |
565 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
566 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
567 | 0 | "%s: invalid volume group.", |
568 | 0 | function ); |
569 | |
|
570 | 0 | return( -1 ); |
571 | 0 | } |
572 | 0 | internal_volume_group = (libvslvm_internal_volume_group_t *) volume_group; |
573 | |
|
574 | 0 | if( identifier == NULL ) |
575 | 0 | { |
576 | 0 | libcerror_error_set( |
577 | 0 | error, |
578 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
579 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
580 | 0 | "%s: invalid identifier.", |
581 | 0 | function ); |
582 | |
|
583 | 0 | return( -1 ); |
584 | 0 | } |
585 | 0 | if( identifier_size > (size_t) SSIZE_MAX ) |
586 | 0 | { |
587 | 0 | libcerror_error_set( |
588 | 0 | error, |
589 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
590 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
591 | 0 | "%s: invalid identifier size value exceeds maximum.", |
592 | 0 | function ); |
593 | |
|
594 | 0 | return( -1 ); |
595 | 0 | } |
596 | 0 | if( identifier_size < 39 ) |
597 | 0 | { |
598 | 0 | libcerror_error_set( |
599 | 0 | error, |
600 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
601 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, |
602 | 0 | "%s: invalid identifier size value too small.", |
603 | 0 | function ); |
604 | |
|
605 | 0 | return( -1 ); |
606 | 0 | } |
607 | 0 | if( memory_copy( |
608 | 0 | identifier, |
609 | 0 | internal_volume_group->identifier, |
610 | 0 | 39 ) == NULL ) |
611 | 0 | { |
612 | 0 | libcerror_error_set( |
613 | 0 | error, |
614 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
615 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
616 | 0 | "%s: unable to copy identifier.", |
617 | 0 | function ); |
618 | |
|
619 | 0 | return( -1 ); |
620 | 0 | } |
621 | 0 | identifier[ 38 ] = 0; |
622 | |
|
623 | 0 | return( 1 ); |
624 | 0 | } |
625 | | |
626 | | /* Sets the identifier |
627 | | * Returns 1 if successful or -1 on error |
628 | | */ |
629 | | int libvslvm_volume_group_set_identifier( |
630 | | libvslvm_volume_group_t *volume_group, |
631 | | const char *identifier, |
632 | | size_t identifier_size, |
633 | | libcerror_error_t **error ) |
634 | 724 | { |
635 | 724 | libvslvm_internal_volume_group_t *internal_volume_group = NULL; |
636 | 724 | static char *function = "libvslvm_volume_group_set_identifier"; |
637 | | |
638 | 724 | if( volume_group == NULL ) |
639 | 0 | { |
640 | 0 | libcerror_error_set( |
641 | 0 | error, |
642 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
643 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
644 | 0 | "%s: invalid volume group.", |
645 | 0 | function ); |
646 | |
|
647 | 0 | return( -1 ); |
648 | 0 | } |
649 | 724 | internal_volume_group = (libvslvm_internal_volume_group_t *) volume_group; |
650 | | |
651 | 724 | if( identifier == NULL ) |
652 | 0 | { |
653 | 0 | libcerror_error_set( |
654 | 0 | error, |
655 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
656 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
657 | 0 | "%s: invalid identifier.", |
658 | 0 | function ); |
659 | |
|
660 | 0 | return( -1 ); |
661 | 0 | } |
662 | 724 | if( identifier_size != 39 ) |
663 | 55 | { |
664 | 55 | libcerror_error_set( |
665 | 55 | error, |
666 | 55 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
667 | 55 | LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, |
668 | 55 | "%s: identifier size value out of bounds.", |
669 | 55 | function ); |
670 | | |
671 | 55 | return( -1 ); |
672 | 55 | } |
673 | 669 | if( memory_copy( |
674 | 669 | internal_volume_group->identifier, |
675 | 669 | identifier, |
676 | 669 | 39 ) == NULL ) |
677 | 0 | { |
678 | 0 | libcerror_error_set( |
679 | 0 | error, |
680 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
681 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
682 | 0 | "%s: unable to copy identifier.", |
683 | 0 | function ); |
684 | |
|
685 | 0 | return( -1 ); |
686 | 0 | } |
687 | 669 | internal_volume_group->identifier[ 38 ] = 0; |
688 | | |
689 | 669 | return( 1 ); |
690 | 669 | } |
691 | | |
692 | | /* Retrieves the sequence number |
693 | | * Returns 1 if successful or -1 on error |
694 | | */ |
695 | | int libvslvm_volume_group_get_sequence_number( |
696 | | libvslvm_volume_group_t *volume_group, |
697 | | uint32_t *sequence_number, |
698 | | libcerror_error_t **error ) |
699 | 0 | { |
700 | 0 | libvslvm_internal_volume_group_t *internal_volume_group = NULL; |
701 | 0 | static char *function = "libvslvm_volume_group_get_sequence_number"; |
702 | |
|
703 | 0 | if( volume_group == NULL ) |
704 | 0 | { |
705 | 0 | libcerror_error_set( |
706 | 0 | error, |
707 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
708 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
709 | 0 | "%s: invalid volume group.", |
710 | 0 | function ); |
711 | |
|
712 | 0 | return( -1 ); |
713 | 0 | } |
714 | 0 | internal_volume_group = (libvslvm_internal_volume_group_t *) volume_group; |
715 | |
|
716 | 0 | if( sequence_number == NULL ) |
717 | 0 | { |
718 | 0 | libcerror_error_set( |
719 | 0 | error, |
720 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
721 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
722 | 0 | "%s: invalid sequence number.", |
723 | 0 | function ); |
724 | |
|
725 | 0 | return( -1 ); |
726 | 0 | } |
727 | 0 | *sequence_number = internal_volume_group->sequence_number; |
728 | |
|
729 | 0 | return( 1 ); |
730 | 0 | } |
731 | | |
732 | | /* Retrieves the extent size |
733 | | * Returns 1 if successful or -1 on error |
734 | | */ |
735 | | int libvslvm_volume_group_get_extent_size( |
736 | | libvslvm_volume_group_t *volume_group, |
737 | | size64_t *extent_size, |
738 | | libcerror_error_t **error ) |
739 | 0 | { |
740 | 0 | libvslvm_internal_volume_group_t *internal_volume_group = NULL; |
741 | 0 | static char *function = "libvslvm_volume_group_get_extent_size"; |
742 | |
|
743 | 0 | if( volume_group == NULL ) |
744 | 0 | { |
745 | 0 | libcerror_error_set( |
746 | 0 | error, |
747 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
748 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
749 | 0 | "%s: invalid volume group.", |
750 | 0 | function ); |
751 | |
|
752 | 0 | return( -1 ); |
753 | 0 | } |
754 | 0 | internal_volume_group = (libvslvm_internal_volume_group_t *) volume_group; |
755 | |
|
756 | 0 | if( extent_size == NULL ) |
757 | 0 | { |
758 | 0 | libcerror_error_set( |
759 | 0 | error, |
760 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
761 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
762 | 0 | "%s: invalid extent size.", |
763 | 0 | function ); |
764 | |
|
765 | 0 | return( -1 ); |
766 | 0 | } |
767 | 0 | *extent_size = internal_volume_group->extent_size; |
768 | |
|
769 | 0 | return( 1 ); |
770 | 0 | } |
771 | | |
772 | | /* Retrieves the number of physical volumes |
773 | | * Returns 1 if successful or -1 on error |
774 | | */ |
775 | | int libvslvm_volume_group_get_number_of_physical_volumes( |
776 | | libvslvm_volume_group_t *volume_group, |
777 | | int *number_of_physical_volumes, |
778 | | libcerror_error_t **error ) |
779 | 4.35k | { |
780 | 4.35k | libvslvm_internal_volume_group_t *internal_volume_group = NULL; |
781 | 4.35k | static char *function = "libvslvm_volume_group_get_number_of_physical_volumes"; |
782 | | |
783 | 4.35k | if( volume_group == NULL ) |
784 | 0 | { |
785 | 0 | libcerror_error_set( |
786 | 0 | error, |
787 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
788 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
789 | 0 | "%s: invalid volume group.", |
790 | 0 | function ); |
791 | |
|
792 | 0 | return( -1 ); |
793 | 0 | } |
794 | 4.35k | internal_volume_group = (libvslvm_internal_volume_group_t *) volume_group; |
795 | | |
796 | 4.35k | if( libcdata_array_get_number_of_entries( |
797 | 4.35k | internal_volume_group->physical_volumes_array, |
798 | 4.35k | number_of_physical_volumes, |
799 | 4.35k | error ) != 1 ) |
800 | 0 | { |
801 | 0 | libcerror_error_set( |
802 | 0 | error, |
803 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
804 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
805 | 0 | "%s: unable to retrieve number of elements from physical volumes array.", |
806 | 0 | function ); |
807 | |
|
808 | 0 | return( -1 ); |
809 | 0 | } |
810 | 4.35k | return( 1 ); |
811 | 4.35k | } |
812 | | |
813 | | /* Retrieves a specific physical volume |
814 | | * Returns 1 if successful or -1 on error |
815 | | */ |
816 | | int libvslvm_volume_group_get_physical_volume( |
817 | | libvslvm_volume_group_t *volume_group, |
818 | | int volume_index, |
819 | | libvslvm_physical_volume_t **physical_volume, |
820 | | libcerror_error_t **error ) |
821 | 977 | { |
822 | 977 | libvslvm_internal_volume_group_t *internal_volume_group = NULL; |
823 | 977 | static char *function = "libvslvm_volume_group_get_physical_volume"; |
824 | | |
825 | 977 | if( volume_group == NULL ) |
826 | 0 | { |
827 | 0 | libcerror_error_set( |
828 | 0 | error, |
829 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
830 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
831 | 0 | "%s: invalid volume group.", |
832 | 0 | function ); |
833 | |
|
834 | 0 | return( -1 ); |
835 | 0 | } |
836 | 977 | internal_volume_group = (libvslvm_internal_volume_group_t *) volume_group; |
837 | | |
838 | 977 | if( physical_volume == NULL ) |
839 | 0 | { |
840 | 0 | libcerror_error_set( |
841 | 0 | error, |
842 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
843 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
844 | 0 | "%s: invalid physical volume.", |
845 | 0 | function ); |
846 | |
|
847 | 0 | return( -1 ); |
848 | 0 | } |
849 | 977 | if( *physical_volume != NULL ) |
850 | 0 | { |
851 | 0 | libcerror_error_set( |
852 | 0 | error, |
853 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
854 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
855 | 0 | "%s: invalid physical volume value already set.", |
856 | 0 | function ); |
857 | |
|
858 | 0 | return( -1 ); |
859 | 0 | } |
860 | 977 | if( libcdata_array_get_entry_by_index( |
861 | 977 | internal_volume_group->physical_volumes_array, |
862 | 977 | volume_index, |
863 | 977 | (intptr_t **) physical_volume, |
864 | 977 | error ) != 1 ) |
865 | 0 | { |
866 | 0 | libcerror_error_set( |
867 | 0 | error, |
868 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
869 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
870 | 0 | "%s: unable to retrieve physical volume: %d.", |
871 | 0 | function, |
872 | 0 | volume_index ); |
873 | |
|
874 | 0 | return( -1 ); |
875 | 0 | } |
876 | 977 | return( 1 ); |
877 | 977 | } |
878 | | |
879 | | /* Retrieves the physical volume for an ASCII encoded volume name |
880 | | * Returns 1 if successful, 0 if no such physical volume or -1 on error |
881 | | */ |
882 | | int libvslvm_volume_group_get_physical_volume_by_name( |
883 | | libvslvm_volume_group_t *volume_group, |
884 | | const char *volume_name, |
885 | | size_t volume_name_length, |
886 | | libvslvm_physical_volume_t **physical_volume, |
887 | | libcerror_error_t **error ) |
888 | 235 | { |
889 | 235 | libvslvm_internal_volume_group_t *internal_volume_group = NULL; |
890 | 235 | static char *function = "libvslvm_volume_group_get_physical_volume_by_name"; |
891 | 235 | int number_of_volumes = 0; |
892 | 235 | int result = 0; |
893 | 235 | int volume_index = 0; |
894 | | |
895 | 235 | if( volume_group == NULL ) |
896 | 0 | { |
897 | 0 | libcerror_error_set( |
898 | 0 | error, |
899 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
900 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
901 | 0 | "%s: invalid volume group.", |
902 | 0 | function ); |
903 | |
|
904 | 0 | return( -1 ); |
905 | 0 | } |
906 | 235 | internal_volume_group = (libvslvm_internal_volume_group_t *) volume_group; |
907 | | |
908 | 235 | if( physical_volume == NULL ) |
909 | 0 | { |
910 | 0 | libcerror_error_set( |
911 | 0 | error, |
912 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
913 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
914 | 0 | "%s: invalid physical volume.", |
915 | 0 | function ); |
916 | |
|
917 | 0 | return( -1 ); |
918 | 0 | } |
919 | 235 | if( *physical_volume != NULL ) |
920 | 1 | { |
921 | 1 | libcerror_error_set( |
922 | 1 | error, |
923 | 1 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
924 | 1 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
925 | 1 | "%s: invalid physical volume value already set.", |
926 | 1 | function ); |
927 | | |
928 | 1 | return( -1 ); |
929 | 1 | } |
930 | 234 | if( libcdata_array_get_number_of_entries( |
931 | 234 | internal_volume_group->physical_volumes_array, |
932 | 234 | &number_of_volumes, |
933 | 234 | error ) != 1 ) |
934 | 0 | { |
935 | 0 | libcerror_error_set( |
936 | 0 | error, |
937 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
938 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
939 | 0 | "%s: unable to retrieve number of elements from physical volumes array.", |
940 | 0 | function ); |
941 | |
|
942 | 0 | return( -1 ); |
943 | 0 | } |
944 | 234 | for( volume_index = 0; |
945 | 309 | volume_index < number_of_volumes; |
946 | 234 | volume_index++ ) |
947 | 234 | { |
948 | 234 | if( libcdata_array_get_entry_by_index( |
949 | 234 | internal_volume_group->physical_volumes_array, |
950 | 234 | volume_index, |
951 | 234 | (intptr_t **) physical_volume, |
952 | 234 | error ) != 1 ) |
953 | 0 | { |
954 | 0 | libcerror_error_set( |
955 | 0 | error, |
956 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
957 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
958 | 0 | "%s: unable to retrieve physical volume: %d.", |
959 | 0 | function, |
960 | 0 | volume_index ); |
961 | |
|
962 | 0 | return( -1 ); |
963 | 0 | } |
964 | 234 | result = libvslvm_physical_volume_compare_by_name( |
965 | 234 | *physical_volume, |
966 | 234 | volume_name, |
967 | 234 | volume_name_length, |
968 | 234 | error ); |
969 | | |
970 | 234 | if( result == -1 ) |
971 | 0 | { |
972 | 0 | libcerror_error_set( |
973 | 0 | error, |
974 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
975 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
976 | 0 | "%s: unable to compare name of physical volume: %d.", |
977 | 0 | function, |
978 | 0 | volume_index ); |
979 | |
|
980 | 0 | return( -1 ); |
981 | 0 | } |
982 | 234 | else if( result != 0 ) |
983 | 159 | { |
984 | 159 | return( 1 ); |
985 | 159 | } |
986 | 234 | } |
987 | 75 | *physical_volume = NULL; |
988 | | |
989 | 75 | return( 0 ); |
990 | 234 | } |
991 | | |
992 | | /* Appends a physical volume |
993 | | * Returns 1 if successful or -1 on error |
994 | | */ |
995 | | int libvslvm_volume_group_append_physical_volume( |
996 | | libvslvm_volume_group_t *volume_group, |
997 | | libvslvm_physical_volume_t *physical_volume, |
998 | | libcerror_error_t **error ) |
999 | 72.8k | { |
1000 | 72.8k | libvslvm_internal_volume_group_t *internal_volume_group = NULL; |
1001 | 72.8k | static char *function = "libvslvm_volume_group_append_physical_volume"; |
1002 | 72.8k | int entry_index = 0; |
1003 | | |
1004 | 72.8k | if( volume_group == NULL ) |
1005 | 0 | { |
1006 | 0 | libcerror_error_set( |
1007 | 0 | error, |
1008 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1009 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1010 | 0 | "%s: invalid volume group.", |
1011 | 0 | function ); |
1012 | |
|
1013 | 0 | return( -1 ); |
1014 | 0 | } |
1015 | 72.8k | internal_volume_group = (libvslvm_internal_volume_group_t *) volume_group; |
1016 | | |
1017 | 72.8k | if( physical_volume == NULL ) |
1018 | 0 | { |
1019 | 0 | libcerror_error_set( |
1020 | 0 | error, |
1021 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1022 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1023 | 0 | "%s: invalid physical volume.", |
1024 | 0 | function ); |
1025 | |
|
1026 | 0 | return( -1 ); |
1027 | 0 | } |
1028 | 72.8k | if( libcdata_array_append_entry( |
1029 | 72.8k | internal_volume_group->physical_volumes_array, |
1030 | 72.8k | &entry_index, |
1031 | 72.8k | (intptr_t *) physical_volume, |
1032 | 72.8k | error ) != 1 ) |
1033 | 0 | { |
1034 | 0 | libcerror_error_set( |
1035 | 0 | error, |
1036 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1037 | 0 | LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, |
1038 | 0 | "%s: unable to append physical volume to array.", |
1039 | 0 | function ); |
1040 | |
|
1041 | 0 | return( -1 ); |
1042 | 0 | } |
1043 | 72.8k | return( 1 ); |
1044 | 72.8k | } |
1045 | | |
1046 | | /* Retrieves the number of logical volumes |
1047 | | * Returns 1 if successful or -1 on error |
1048 | | */ |
1049 | | int libvslvm_volume_group_get_number_of_logical_volumes( |
1050 | | libvslvm_volume_group_t *volume_group, |
1051 | | int *number_of_logical_volumes, |
1052 | | libcerror_error_t **error ) |
1053 | 450 | { |
1054 | 450 | libvslvm_internal_volume_group_t *internal_volume_group = NULL; |
1055 | 450 | static char *function = "libvslvm_volume_group_get_number_of_logical_volumes"; |
1056 | | |
1057 | 450 | if( volume_group == NULL ) |
1058 | 0 | { |
1059 | 0 | libcerror_error_set( |
1060 | 0 | error, |
1061 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1062 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1063 | 0 | "%s: invalid volume group.", |
1064 | 0 | function ); |
1065 | |
|
1066 | 0 | return( -1 ); |
1067 | 0 | } |
1068 | 450 | internal_volume_group = (libvslvm_internal_volume_group_t *) volume_group; |
1069 | | |
1070 | 450 | if( libcdata_array_get_number_of_entries( |
1071 | 450 | internal_volume_group->logical_volumes_array, |
1072 | 450 | number_of_logical_volumes, |
1073 | 450 | error ) != 1 ) |
1074 | 0 | { |
1075 | 0 | libcerror_error_set( |
1076 | 0 | error, |
1077 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1078 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1079 | 0 | "%s: unable to retrieve number of elements from logical volumes array.", |
1080 | 0 | function ); |
1081 | |
|
1082 | 0 | return( -1 ); |
1083 | 0 | } |
1084 | 450 | return( 1 ); |
1085 | 450 | } |
1086 | | |
1087 | | /* Retrieves a specific logical volume |
1088 | | * Returns 1 if successful or -1 on error |
1089 | | */ |
1090 | | int libvslvm_volume_group_get_logical_volume( |
1091 | | libvslvm_volume_group_t *volume_group, |
1092 | | int volume_index, |
1093 | | libvslvm_logical_volume_t **logical_volume, |
1094 | | libcerror_error_t **error ) |
1095 | 276 | { |
1096 | 276 | libvslvm_internal_volume_group_t *internal_volume_group = NULL; |
1097 | 276 | libvslvm_logical_volume_values_t *logical_volume_values = NULL; |
1098 | 276 | static char *function = "libvslvm_volume_group_get_logical_volume"; |
1099 | | |
1100 | 276 | if( volume_group == NULL ) |
1101 | 0 | { |
1102 | 0 | libcerror_error_set( |
1103 | 0 | error, |
1104 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1105 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1106 | 0 | "%s: invalid volume group.", |
1107 | 0 | function ); |
1108 | |
|
1109 | 0 | return( -1 ); |
1110 | 0 | } |
1111 | 276 | internal_volume_group = (libvslvm_internal_volume_group_t *) volume_group; |
1112 | | |
1113 | 276 | if( logical_volume == NULL ) |
1114 | 0 | { |
1115 | 0 | libcerror_error_set( |
1116 | 0 | error, |
1117 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1118 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1119 | 0 | "%s: invalid logical volume.", |
1120 | 0 | function ); |
1121 | |
|
1122 | 0 | return( -1 ); |
1123 | 0 | } |
1124 | 276 | if( *logical_volume != NULL ) |
1125 | 0 | { |
1126 | 0 | libcerror_error_set( |
1127 | 0 | error, |
1128 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1129 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
1130 | 0 | "%s: invalid logical volume value already set.", |
1131 | 0 | function ); |
1132 | |
|
1133 | 0 | return( -1 ); |
1134 | 0 | } |
1135 | 276 | if( libcdata_array_get_entry_by_index( |
1136 | 276 | internal_volume_group->logical_volumes_array, |
1137 | 276 | volume_index, |
1138 | 276 | (intptr_t **) &logical_volume_values, |
1139 | 276 | error ) != 1 ) |
1140 | 0 | { |
1141 | 0 | libcerror_error_set( |
1142 | 0 | error, |
1143 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1144 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1145 | 0 | "%s: unable to retrieve logical volume: %d.", |
1146 | 0 | function, |
1147 | 0 | volume_index ); |
1148 | |
|
1149 | 0 | return( -1 ); |
1150 | 0 | } |
1151 | 276 | if( libvslvm_logical_volume_initialize( |
1152 | 276 | logical_volume, |
1153 | 276 | internal_volume_group->io_handle, |
1154 | 276 | volume_group, |
1155 | 276 | internal_volume_group->physical_volume_file_io_pool, |
1156 | 276 | logical_volume_values, |
1157 | 276 | error ) != 1 ) |
1158 | 235 | { |
1159 | 235 | libcerror_error_set( |
1160 | 235 | error, |
1161 | 235 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1162 | 235 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1163 | 235 | "%s: unable to create logical volume.", |
1164 | 235 | function ); |
1165 | | |
1166 | 235 | return( -1 ); |
1167 | 235 | } |
1168 | 41 | return( 1 ); |
1169 | 276 | } |
1170 | | |
1171 | | /* Appends a logical volume |
1172 | | * Returns 1 if successful or -1 on error |
1173 | | */ |
1174 | | int libvslvm_volume_group_append_logical_volume( |
1175 | | libvslvm_volume_group_t *volume_group, |
1176 | | libvslvm_logical_volume_values_t *logical_volume_values, |
1177 | | libcerror_error_t **error ) |
1178 | 26.6k | { |
1179 | 26.6k | libvslvm_internal_volume_group_t *internal_volume_group = NULL; |
1180 | 26.6k | static char *function = "libvslvm_volume_group_append_logical_volume"; |
1181 | 26.6k | int entry_index = 0; |
1182 | | |
1183 | 26.6k | if( volume_group == NULL ) |
1184 | 0 | { |
1185 | 0 | libcerror_error_set( |
1186 | 0 | error, |
1187 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1188 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1189 | 0 | "%s: invalid volume group.", |
1190 | 0 | function ); |
1191 | |
|
1192 | 0 | return( -1 ); |
1193 | 0 | } |
1194 | 26.6k | internal_volume_group = (libvslvm_internal_volume_group_t *) volume_group; |
1195 | | |
1196 | 26.6k | if( logical_volume_values == NULL ) |
1197 | 0 | { |
1198 | 0 | libcerror_error_set( |
1199 | 0 | error, |
1200 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1201 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1202 | 0 | "%s: invalid logical volume values.", |
1203 | 0 | function ); |
1204 | |
|
1205 | 0 | return( -1 ); |
1206 | 0 | } |
1207 | 26.6k | if( libcdata_array_append_entry( |
1208 | 26.6k | internal_volume_group->logical_volumes_array, |
1209 | 26.6k | &entry_index, |
1210 | 26.6k | (intptr_t *) logical_volume_values, |
1211 | 26.6k | error ) != 1 ) |
1212 | 0 | { |
1213 | 0 | libcerror_error_set( |
1214 | 0 | error, |
1215 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1216 | 0 | LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, |
1217 | 0 | "%s: unable to append logical volume to array.", |
1218 | 0 | function ); |
1219 | |
|
1220 | 0 | return( -1 ); |
1221 | 0 | } |
1222 | 26.6k | return( 1 ); |
1223 | 26.6k | } |
1224 | | |