Coverage Report

Created: 2026-02-19 06:51

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libvslvm/libvslvm/libvslvm_logical_volume_values.c
Line
Count
Source
1
/*
2
 * Logical volume values functions
3
 *
4
 * Copyright (C) 2014-2025, 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_libcdata.h"
27
#include "libvslvm_libcerror.h"
28
#include "libvslvm_logical_volume_values.h"
29
#include "libvslvm_segment.h"
30
31
/* Creates logical volume values
32
 * Make sure the value logical_volume_values is referencing, is set to NULL
33
 * Returns 1 if successful or -1 on error
34
 */
35
int libvslvm_logical_volume_values_initialize(
36
     libvslvm_logical_volume_values_t **logical_volume_values,
37
     libcerror_error_t **error )
38
26.8k
{
39
26.8k
  static char *function = "libvslvm_logical_volume_values_initialize";
40
41
26.8k
  if( logical_volume_values == NULL )
42
0
  {
43
0
    libcerror_error_set(
44
0
     error,
45
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
46
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
47
0
     "%s: invalid logical volume values.",
48
0
     function );
49
50
0
    return( -1 );
51
0
  }
52
26.8k
  if( *logical_volume_values != NULL )
53
0
  {
54
0
    libcerror_error_set(
55
0
     error,
56
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
57
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
58
0
     "%s: invalid logical volume values value already set.",
59
0
     function );
60
61
0
    return( -1 );
62
0
  }
63
26.8k
  *logical_volume_values = memory_allocate_structure(
64
26.8k
                            libvslvm_logical_volume_values_t );
65
66
26.8k
  if( *logical_volume_values == NULL )
67
0
  {
68
0
    libcerror_error_set(
69
0
     error,
70
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
71
0
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
72
0
     "%s: unable to create logical volume values.",
73
0
     function );
74
75
0
    goto on_error;
76
0
  }
77
26.8k
  if( memory_set(
78
26.8k
       *logical_volume_values,
79
26.8k
       0,
80
26.8k
       sizeof( libvslvm_logical_volume_values_t ) ) == NULL )
81
0
  {
82
0
    libcerror_error_set(
83
0
     error,
84
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
85
0
     LIBCERROR_MEMORY_ERROR_SET_FAILED,
86
0
     "%s: unable to clear logical volume values.",
87
0
     function );
88
89
0
    memory_free(
90
0
     *logical_volume_values );
91
92
0
    *logical_volume_values = NULL;
93
94
0
    return( -1 );
95
0
  }
96
26.8k
  if( libcdata_array_initialize(
97
26.8k
       &( ( *logical_volume_values )->segments_array ),
98
26.8k
       0,
99
26.8k
       error ) != 1 )
100
0
  {
101
0
    libcerror_error_set(
102
0
     error,
103
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
104
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
105
0
     "%s: unable to create segments array.",
106
0
     function );
107
108
0
    goto on_error;
109
0
  }
110
26.8k
  return( 1 );
111
112
0
on_error:
113
0
  if( *logical_volume_values != NULL )
114
0
  {
115
0
    memory_free(
116
0
     *logical_volume_values );
117
118
0
    *logical_volume_values = NULL;
119
0
  }
120
0
  return( -1 );
121
26.8k
}
122
123
/* Frees logical volume values
124
 * Returns 1 if successful or -1 on error
125
 */
126
int libvslvm_logical_volume_values_free(
127
     libvslvm_logical_volume_values_t **logical_volume_values,
128
     libcerror_error_t **error )
129
26.8k
{
130
26.8k
  static char *function = "libvslvm_logical_volume_values_free";
131
26.8k
  int result            = 1;
132
133
26.8k
  if( logical_volume_values == NULL )
134
0
  {
135
0
    libcerror_error_set(
136
0
     error,
137
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
138
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
139
0
     "%s: invalid logical volume values.",
140
0
     function );
141
142
0
    return( -1 );
143
0
  }
144
26.8k
  if( *logical_volume_values != NULL )
145
26.8k
  {
146
26.8k
    if( ( *logical_volume_values )->name != NULL )
147
26.8k
    {
148
26.8k
      memory_free(
149
26.8k
       ( *logical_volume_values )->name );
150
26.8k
    }
151
26.8k
    if( libcdata_array_free(
152
26.8k
         &( ( *logical_volume_values )->segments_array ),
153
26.8k
         (int (*)(intptr_t **, libcerror_error_t **)) &libvslvm_internal_segment_free,
154
26.8k
         error ) != 1 )
155
0
    {
156
0
      libcerror_error_set(
157
0
       error,
158
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
159
0
       LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
160
0
       "%s: unable to free segments array.",
161
0
       function );
162
163
0
      result = -1;
164
0
    }
165
26.8k
    memory_free(
166
26.8k
     *logical_volume_values );
167
168
26.8k
    *logical_volume_values = NULL;
169
26.8k
  }
170
26.8k
  return( result );
171
26.8k
}
172
173
/* Retrieves the size of the ASCII formatted name
174
 * Returns 1 if successful or -1 on error
175
 */
176
int libvslvm_logical_volume_values_get_name_size(
177
     libvslvm_logical_volume_values_t *logical_volume_values,
178
     size_t *name_size,
179
     libcerror_error_t **error )
180
0
{
181
0
  static char *function = "libvslvm_logical_volume_values_get_name_size";
182
183
0
  if( logical_volume_values == NULL )
184
0
  {
185
0
    libcerror_error_set(
186
0
     error,
187
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
188
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
189
0
     "%s: invalid logical volume values.",
190
0
     function );
191
192
0
    return( -1 );
193
0
  }
194
0
  if( name_size == NULL )
195
0
  {
196
0
    libcerror_error_set(
197
0
     error,
198
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
199
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
200
0
     "%s: invalid name size.",
201
0
     function );
202
203
0
    return( -1 );
204
0
  }
205
0
  *name_size = logical_volume_values->name_size;
206
207
0
  return( 1 );
208
0
}
209
210
/* Retrieves the ASCII formatted name
211
 * Returns 1 if successful or -1 on error
212
 */
213
int libvslvm_logical_volume_values_get_name(
214
     libvslvm_logical_volume_values_t *logical_volume_values,
215
     char *name,
216
     size_t name_size,
217
     libcerror_error_t **error )
218
0
{
219
0
  static char *function = "libvslvm_logical_volume_values_set_name";
220
221
0
  if( logical_volume_values == NULL )
222
0
  {
223
0
    libcerror_error_set(
224
0
     error,
225
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
226
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
227
0
     "%s: invalid logical volume values.",
228
0
     function );
229
230
0
    return( -1 );
231
0
  }
232
0
  if( name == NULL )
233
0
  {
234
0
    libcerror_error_set(
235
0
     error,
236
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
237
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
238
0
     "%s: invalid name.",
239
0
     function );
240
241
0
    return( -1 );
242
0
  }
243
0
  if( name_size > (size_t) SSIZE_MAX )
244
0
  {
245
0
    libcerror_error_set(
246
0
     error,
247
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
248
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
249
0
     "%s: invalid name size value exceeds maximum.",
250
0
     function );
251
252
0
    return( -1 );
253
0
  }
254
0
  if( name_size < logical_volume_values->name_size )
255
0
  {
256
0
    libcerror_error_set(
257
0
     error,
258
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
259
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
260
0
     "%s: invalid name size value too small.",
261
0
     function );
262
263
0
    return( -1 );
264
0
  }
265
0
  if( memory_copy(
266
0
       name,
267
0
       logical_volume_values->name,
268
0
       logical_volume_values->name_size ) == NULL )
269
0
  {
270
0
    libcerror_error_set(
271
0
     error,
272
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
273
0
     LIBCERROR_MEMORY_ERROR_COPY_FAILED,
274
0
     "%s: unable to copy name.",
275
0
     function );
276
277
0
    return( -1 );
278
0
  }
279
0
  name[ logical_volume_values->name_size - 1 ] = 0;
280
281
0
  return( 1 );
282
0
}
283
284
/* Sets the name
285
 * Returns 1 if successful or -1 on error
286
 */
287
int libvslvm_logical_volume_values_set_name(
288
     libvslvm_logical_volume_values_t *logical_volume_values,
289
     const char *name,
290
     size_t name_size,
291
     libcerror_error_t **error )
292
26.8k
{
293
26.8k
  static char *function = "libvslvm_logical_volume_values_set_name";
294
295
26.8k
  if( logical_volume_values == NULL )
296
0
  {
297
0
    libcerror_error_set(
298
0
     error,
299
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
300
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
301
0
     "%s: invalid logical volume values.",
302
0
     function );
303
304
0
    return( -1 );
305
0
  }
306
26.8k
  if( logical_volume_values->name != NULL )
307
0
  {
308
0
    libcerror_error_set(
309
0
     error,
310
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
311
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
312
0
     "%s: invalid logical volume values - name value already set.",
313
0
     function );
314
315
0
    return( -1 );
316
0
  }
317
26.8k
  if( name == NULL )
318
0
  {
319
0
    libcerror_error_set(
320
0
     error,
321
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
322
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
323
0
     "%s: invalid name.",
324
0
     function );
325
326
0
    return( -1 );
327
0
  }
328
26.8k
  if( ( name_size == 0 )
329
26.8k
   || ( name_size > (size_t) MEMORY_MAXIMUM_ALLOCATION_SIZE ) )
330
0
  {
331
0
    libcerror_error_set(
332
0
     error,
333
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
334
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
335
0
     "%s: invalid name size value out of bounds.",
336
0
     function );
337
338
0
    return( -1 );
339
0
  }
340
26.8k
  logical_volume_values->name = (char *) memory_allocate(
341
26.8k
                                          sizeof( char ) * name_size );
342
343
26.8k
  if( logical_volume_values->name == NULL )
344
0
  {
345
0
    libcerror_error_set(
346
0
     error,
347
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
348
0
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
349
0
     "%s: unable to create name.",
350
0
     function );
351
352
0
    goto on_error;
353
0
  }
354
26.8k
  if( memory_copy(
355
26.8k
       logical_volume_values->name,
356
26.8k
       name,
357
26.8k
       name_size ) == NULL )
358
0
  {
359
0
    libcerror_error_set(
360
0
     error,
361
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
362
0
     LIBCERROR_MEMORY_ERROR_COPY_FAILED,
363
0
     "%s: unable to copy name.",
364
0
     function );
365
366
0
    goto on_error;
367
0
  }
368
26.8k
  logical_volume_values->name[ name_size - 1 ] = 0;
369
370
26.8k
  logical_volume_values->name_size = name_size;
371
372
26.8k
  return( 1 );
373
374
0
on_error:
375
0
  if( logical_volume_values->name != NULL )
376
0
  {
377
0
    memory_free(
378
0
     logical_volume_values->name );
379
380
0
    logical_volume_values->name = NULL;
381
0
  }
382
0
  logical_volume_values->name_size = 0;
383
384
0
  return( -1 );
385
26.8k
}
386
387
/* Retrieves the size of the ASCII formatted identifier
388
 * Returns 1 if successful or -1 on error
389
 */
390
int libvslvm_logical_volume_values_get_identifier_size(
391
     libvslvm_logical_volume_values_t *logical_volume_values,
392
     size_t *identifier_size,
393
     libcerror_error_t **error )
394
0
{
395
0
  static char *function = "libvslvm_logical_volume_values_get_identifier_size";
396
397
0
  if( logical_volume_values == NULL )
398
0
  {
399
0
    libcerror_error_set(
400
0
     error,
401
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
402
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
403
0
     "%s: invalid logical volume values.",
404
0
     function );
405
406
0
    return( -1 );
407
0
  }
408
0
  if( identifier_size == NULL )
409
0
  {
410
0
    libcerror_error_set(
411
0
     error,
412
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
413
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
414
0
     "%s: invalid identifier size.",
415
0
     function );
416
417
0
    return( -1 );
418
0
  }
419
0
  if( logical_volume_values->identifier[ 0 ] == 0 )
420
0
  {
421
0
    *identifier_size = 0;
422
0
  }
423
0
  else
424
0
  {
425
0
    *identifier_size = 39;
426
0
  }
427
0
  return( 1 );
428
0
}
429
430
/* Retrieves the ASCII formatted identifier
431
 * Returns 1 if successful or -1 on error
432
 */
433
int libvslvm_logical_volume_values_get_identifier(
434
     libvslvm_logical_volume_values_t *logical_volume_values,
435
     char *identifier,
436
     size_t identifier_size,
437
     libcerror_error_t **error )
438
0
{
439
0
  static char *function = "libvslvm_logical_volume_values_set_identifier";
440
441
0
  if( logical_volume_values == NULL )
442
0
  {
443
0
    libcerror_error_set(
444
0
     error,
445
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
446
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
447
0
     "%s: invalid logical volume values.",
448
0
     function );
449
450
0
    return( -1 );
451
0
  }
452
0
  if( identifier == NULL )
453
0
  {
454
0
    libcerror_error_set(
455
0
     error,
456
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
457
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
458
0
     "%s: invalid identifier.",
459
0
     function );
460
461
0
    return( -1 );
462
0
  }
463
0
  if( identifier_size > (size_t) SSIZE_MAX )
464
0
  {
465
0
    libcerror_error_set(
466
0
     error,
467
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
468
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
469
0
     "%s: invalid identifier size value exceeds maximum.",
470
0
     function );
471
472
0
    return( -1 );
473
0
  }
474
0
  if( identifier_size < 39 )
475
0
  {
476
0
    libcerror_error_set(
477
0
     error,
478
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
479
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
480
0
     "%s: invalid identifier size value too small.",
481
0
     function );
482
483
0
    return( -1 );
484
0
  }
485
0
  if( memory_copy(
486
0
       identifier,
487
0
       logical_volume_values->identifier,
488
0
       39 ) == NULL )
489
0
  {
490
0
    libcerror_error_set(
491
0
     error,
492
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
493
0
     LIBCERROR_MEMORY_ERROR_COPY_FAILED,
494
0
     "%s: unable to copy identifier.",
495
0
     function );
496
497
0
    return( -1 );
498
0
  }
499
0
  identifier[ 38 ] = 0;
500
501
0
  return( 1 );
502
0
}
503
504
/* Sets the identifier
505
 * Returns 1 if successful or -1 on error
506
 */
507
int libvslvm_logical_volume_values_set_identifier(
508
     libvslvm_logical_volume_values_t *logical_volume_values,
509
     const char *identifier,
510
     size_t identifier_size,
511
     libcerror_error_t **error )
512
798
{
513
798
  static char *function = "libvslvm_logical_volume_values_set_identifier";
514
515
798
  if( logical_volume_values == NULL )
516
0
  {
517
0
    libcerror_error_set(
518
0
     error,
519
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
520
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
521
0
     "%s: invalid logical volume values.",
522
0
     function );
523
524
0
    return( -1 );
525
0
  }
526
798
  if( identifier == NULL )
527
0
  {
528
0
    libcerror_error_set(
529
0
     error,
530
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
531
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
532
0
     "%s: invalid identifier.",
533
0
     function );
534
535
0
    return( -1 );
536
0
  }
537
798
  if( identifier_size != 39 )
538
37
  {
539
37
    libcerror_error_set(
540
37
     error,
541
37
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
542
37
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
543
37
     "%s: identifier size value out of bounds.",
544
37
     function );
545
546
37
    return( -1 );
547
37
  }
548
761
  if( memory_copy(
549
761
       logical_volume_values->identifier,
550
761
       identifier,
551
761
       39 ) == NULL )
552
0
  {
553
0
    libcerror_error_set(
554
0
     error,
555
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
556
0
     LIBCERROR_MEMORY_ERROR_COPY_FAILED,
557
0
     "%s: unable to copy identifier.",
558
0
     function );
559
560
0
    return( -1 );
561
0
  }
562
761
  logical_volume_values->identifier[ 38 ] = 0;
563
564
761
  return( 1 );
565
761
}
566
567
/* Retrieves the number of segments
568
 * Returns 1 if successful or -1 on error
569
 */
570
int libvslvm_logical_volume_values_get_number_of_segments(
571
     libvslvm_logical_volume_values_t *logical_volume_values,
572
     int *number_of_segments,
573
     libcerror_error_t **error )
574
265
{
575
265
  static char *function = "libvslvm_logical_volume_values_get_number_of_segments";
576
577
265
  if( logical_volume_values == NULL )
578
0
  {
579
0
    libcerror_error_set(
580
0
     error,
581
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
582
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
583
0
     "%s: invalid logical volume values.",
584
0
     function );
585
586
0
    return( -1 );
587
0
  }
588
265
  if( libcdata_array_get_number_of_entries(
589
265
       logical_volume_values->segments_array,
590
265
       number_of_segments,
591
265
       error ) != 1 )
592
0
  {
593
0
    libcerror_error_set(
594
0
     error,
595
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
596
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
597
0
     "%s: unable to retrieve number of elements from segments array.",
598
0
     function );
599
600
0
    return( -1 );
601
0
  }
602
265
  return( 1 );
603
265
}
604
605
/* Retrieves a specific segment
606
 * Returns 1 if successful or -1 on error
607
 */
608
int libvslvm_logical_volume_values_get_segment(
609
     libvslvm_logical_volume_values_t *logical_volume_values,
610
     int segment_index,
611
     libvslvm_segment_t **segment,
612
     libcerror_error_t **error )
613
262
{
614
262
  static char *function = "libvslvm_logical_volume_values_get_segment";
615
616
262
  if( logical_volume_values == NULL )
617
0
  {
618
0
    libcerror_error_set(
619
0
     error,
620
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
621
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
622
0
     "%s: invalid logical volume values.",
623
0
     function );
624
625
0
    return( -1 );
626
0
  }
627
262
  if( segment == NULL )
628
0
  {
629
0
    libcerror_error_set(
630
0
     error,
631
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
632
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
633
0
     "%s: invalid segment.",
634
0
     function );
635
636
0
    return( -1 );
637
0
  }
638
262
  if( *segment != NULL )
639
0
  {
640
0
    libcerror_error_set(
641
0
     error,
642
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
643
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
644
0
     "%s: invalid segment value already set.",
645
0
     function );
646
647
0
    return( -1 );
648
0
  }
649
262
  if( libcdata_array_get_entry_by_index(
650
262
       logical_volume_values->segments_array,
651
262
       segment_index,
652
262
       (intptr_t **) segment,
653
262
       error ) != 1 )
654
0
  {
655
0
    libcerror_error_set(
656
0
     error,
657
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
658
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
659
0
     "%s: unable to retrieve segment: %d.",
660
0
     function,
661
0
     segment_index );
662
663
0
    return( -1 );
664
0
  }
665
262
  return( 1 );
666
262
}
667
668
/* Appends a segment
669
 * Returns 1 if successful or -1 on error
670
 */
671
int libvslvm_logical_volume_values_append_segment(
672
     libvslvm_logical_volume_values_t *logical_volume_values,
673
     libvslvm_segment_t *segment,
674
     libcerror_error_t **error )
675
2.18k
{
676
2.18k
  static char *function = "libvslvm_logical_volume_values_append_segment";
677
2.18k
  int entry_index       = 0;
678
679
2.18k
  if( logical_volume_values == NULL )
680
0
  {
681
0
    libcerror_error_set(
682
0
     error,
683
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
684
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
685
0
     "%s: invalid logical volume values.",
686
0
     function );
687
688
0
    return( -1 );
689
0
  }
690
2.18k
  if( segment == NULL )
691
0
  {
692
0
    libcerror_error_set(
693
0
     error,
694
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
695
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
696
0
     "%s: invalid segment.",
697
0
     function );
698
699
0
    return( -1 );
700
0
  }
701
2.18k
  if( libcdata_array_append_entry(
702
2.18k
       logical_volume_values->segments_array,
703
2.18k
       &entry_index,
704
2.18k
       (intptr_t *) segment,
705
2.18k
       error ) != 1 )
706
0
  {
707
0
    libcerror_error_set(
708
0
     error,
709
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
710
0
     LIBCERROR_RUNTIME_ERROR_APPEND_FAILED,
711
0
     "%s: unable to append segment to logical volume values.",
712
0
     function );
713
714
0
    return( -1 );
715
0
  }
716
2.18k
  return( 1 );
717
2.18k
}