Coverage Report

Created: 2026-07-10 07:32

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libvslvm/libvslvm/libvslvm_metadata.c
Line
Count
Source
1
/*
2
 * The metadata functions
3
 *
4
 * Copyright (C) 2014-2026, 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 <byte_stream.h>
24
#include <memory.h>
25
#include <narrow_string.h>
26
#include <types.h>
27
28
#include "libvslvm_checksum.h"
29
#include "libvslvm_definitions.h"
30
#include "libvslvm_libbfio.h"
31
#include "libvslvm_libcdata.h"
32
#include "libvslvm_libcerror.h"
33
#include "libvslvm_libcnotify.h"
34
#include "libvslvm_libcsplit.h"
35
#include "libvslvm_libfvalue.h"
36
#include "libvslvm_logical_volume_values.h"
37
#include "libvslvm_metadata.h"
38
#include "libvslvm_physical_volume.h"
39
#include "libvslvm_raw_location_descriptor.h"
40
#include "libvslvm_segment.h"
41
#include "libvslvm_stripe.h"
42
#include "libvslvm_volume_group.h"
43
44
/* Creates a metadata
45
 * Make sure the value metadata is referencing, is set to NULL
46
 * Returns 1 if successful or -1 on error
47
 */
48
int libvslvm_metadata_initialize(
49
     libvslvm_metadata_t **metadata,
50
     libcerror_error_t **error )
51
7.60k
{
52
7.60k
  static char *function = "libvslvm_metadata_initialize";
53
54
7.60k
  if( metadata == NULL )
55
0
  {
56
0
    libcerror_error_set(
57
0
     error,
58
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
59
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
60
0
     "%s: invalid metadata.",
61
0
     function );
62
63
0
    return( -1 );
64
0
  }
65
7.60k
  if( *metadata != NULL )
66
0
  {
67
0
    libcerror_error_set(
68
0
     error,
69
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
70
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
71
0
     "%s: invalid metadata value already set.",
72
0
     function );
73
74
0
    return( -1 );
75
0
  }
76
7.60k
  *metadata = memory_allocate_structure(
77
7.60k
               libvslvm_metadata_t );
78
79
7.60k
  if( *metadata == NULL )
80
0
  {
81
0
    libcerror_error_set(
82
0
     error,
83
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
84
0
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
85
0
     "%s: unable to create metadata.",
86
0
     function );
87
88
0
    goto on_error;
89
0
  }
90
7.60k
  if( memory_set(
91
7.60k
       *metadata,
92
7.60k
       0,
93
7.60k
       sizeof( libvslvm_metadata_t ) ) == NULL )
94
0
  {
95
0
    libcerror_error_set(
96
0
     error,
97
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
98
0
     LIBCERROR_MEMORY_ERROR_SET_FAILED,
99
0
     "%s: unable to clear metadata.",
100
0
     function );
101
102
0
    memory_free(
103
0
     *metadata );
104
105
0
    *metadata = NULL;
106
107
0
    return( -1 );
108
0
  }
109
7.60k
  return( 1 );
110
111
0
on_error:
112
0
  if( *metadata != NULL )
113
0
  {
114
0
    memory_free(
115
0
     *metadata );
116
117
0
    *metadata = NULL;
118
0
  }
119
0
  return( -1 );
120
7.60k
}
121
122
/* Frees a metadata
123
 * Returns 1 if successful or -1 on error
124
 */
125
int libvslvm_metadata_free(
126
     libvslvm_metadata_t **metadata,
127
     libcerror_error_t **error )
128
7.60k
{
129
7.60k
  static char *function = "libvslvm_metadata_free";
130
7.60k
  int result            = 1;
131
132
7.60k
  if( metadata == NULL )
133
0
  {
134
0
    libcerror_error_set(
135
0
     error,
136
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
137
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
138
0
     "%s: invalid metadata.",
139
0
     function );
140
141
0
    return( -1 );
142
0
  }
143
7.60k
  if( *metadata != NULL )
144
7.60k
  {
145
7.60k
    if( ( *metadata )->volume_group != NULL )
146
5.58k
    {
147
5.58k
      if( libvslvm_internal_volume_group_free(
148
5.58k
           (libvslvm_internal_volume_group_t **) &( ( *metadata )->volume_group ),
149
5.58k
           error ) != 1 )
150
0
      {
151
0
        libcerror_error_set(
152
0
         error,
153
0
         LIBCERROR_ERROR_DOMAIN_RUNTIME,
154
0
         LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
155
0
         "%s: unable to free volume group.",
156
0
         function );
157
158
0
        result = -1;
159
0
      }
160
5.58k
    }
161
7.60k
    memory_free(
162
7.60k
     *metadata );
163
164
7.60k
    *metadata = NULL;
165
7.60k
  }
166
7.60k
  return( result );
167
7.60k
}
168
169
/* Reads the metadata
170
 * Returns 1 if successful or -1 on error
171
 */
172
int libvslvm_metadata_read_data(
173
     libvslvm_metadata_t *metadata,
174
     const uint8_t *data,
175
     size_t data_size,
176
     uint32_t stored_checksum,
177
     libcerror_error_t **error )
178
7.24k
{
179
7.24k
  libcsplit_narrow_split_string_t *lines = NULL;
180
7.24k
  static char *function                  = "libvslvm_metadata_read_data";
181
7.24k
  uint32_t calculated_checksum           = 0;
182
7.24k
  int line_index                         = 0;
183
7.24k
  int number_of_lines                    = 0;
184
185
7.24k
  if( metadata == 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 metadata.",
192
0
     function );
193
194
0
    return( -1 );
195
0
  }
196
7.24k
  if( data == NULL )
197
0
  {
198
0
    libcerror_error_set(
199
0
     error,
200
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
201
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
202
0
     "%s: invalid data.",
203
0
     function );
204
205
0
    return( -1 );
206
0
  }
207
7.24k
  if( ( data_size == 0 )
208
7.24k
   || ( data_size > (size_t) SSIZE_MAX ) )
209
0
  {
210
0
    libcerror_error_set(
211
0
     error,
212
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
213
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
214
0
     "%s: invalid data size value out of bounds.",
215
0
     function );
216
217
0
    return( -1 );
218
0
  }
219
7.24k
  if( libvslvm_checksum_calculate_weak_crc32(
220
7.24k
       &calculated_checksum,
221
7.24k
       data,
222
7.24k
       data_size,
223
7.24k
       0xf597a6cfUL,
224
7.24k
       error ) != 1 )
225
0
  {
226
0
    libcerror_error_set(
227
0
     error,
228
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
229
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
230
0
     "%s: unable to calculate CRC-32.",
231
0
     function );
232
233
0
    goto on_error;
234
0
  }
235
7.24k
  if( ( stored_checksum != 0 )
236
179
   && ( stored_checksum != calculated_checksum ) )
237
170
  {
238
170
    libcerror_error_set(
239
170
     error,
240
170
     LIBCERROR_ERROR_DOMAIN_INPUT,
241
170
     LIBCERROR_INPUT_ERROR_CHECKSUM_MISMATCH,
242
170
     "%s: mismatch in checksum ( 0x%08" PRIx32 " != 0x%08" PRIx32 " ).",
243
170
     function,
244
170
     stored_checksum,
245
170
     calculated_checksum );
246
247
170
    goto on_error;
248
170
  }
249
#if defined( HAVE_DEBUG_OUTPUT )
250
  if( libcnotify_verbose != 0 )
251
  {
252
    libcnotify_printf(
253
     "%s: metadata:\n%s",
254
     function,
255
     data );
256
  }
257
#endif
258
7.07k
  if( libcsplit_narrow_string_split(
259
7.07k
       (char *) data,
260
7.07k
       data_size,
261
7.07k
       '\n',
262
7.07k
       &lines,
263
7.07k
       error ) != 1 )
264
0
  {
265
0
    libcerror_error_set(
266
0
     error,
267
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
268
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
269
0
     "%s: unable to split data into lines.",
270
0
     function );
271
272
0
    goto on_error;
273
0
  }
274
7.07k
  if( libcsplit_narrow_split_string_get_number_of_segments(
275
7.07k
       lines,
276
7.07k
       &number_of_lines,
277
7.07k
       error ) != 1 )
278
14
  {
279
14
    libcerror_error_set(
280
14
     error,
281
14
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
282
14
     LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
283
14
     "%s: unable to retrieve number of lines.",
284
14
     function );
285
286
14
    goto on_error;
287
14
  }
288
7.05k
  if( libvslvm_metadata_read_volume_group(
289
7.05k
       metadata,
290
7.05k
       lines,
291
7.05k
       number_of_lines,
292
7.05k
       &line_index,
293
7.05k
       error ) != 1 )
294
1.47k
  {
295
1.47k
    libcerror_error_set(
296
1.47k
     error,
297
1.47k
     LIBCERROR_ERROR_DOMAIN_IO,
298
1.47k
     LIBCERROR_IO_ERROR_READ_FAILED,
299
1.47k
     "%s: unable to read volume group.",
300
1.47k
     function );
301
302
1.47k
    goto on_error;
303
1.47k
  }
304
5.58k
  if( libcsplit_narrow_split_string_free(
305
5.58k
       &lines,
306
5.58k
       error ) != 1 )
307
0
  {
308
0
    libcerror_error_set(
309
0
     error,
310
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
311
0
     LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
312
0
     "%s: unable to free lines.",
313
0
     function );
314
315
0
    goto on_error;
316
0
  }
317
5.58k
  return( 1 );
318
319
1.65k
on_error:
320
1.65k
  if( lines != NULL )
321
1.47k
  {
322
1.47k
    libcsplit_narrow_split_string_free(
323
1.47k
     &lines,
324
1.47k
     NULL );
325
1.47k
  }
326
1.65k
  return( -1 );
327
5.58k
}
328
329
/* Reads the metadata
330
 * Returns 1 if successful or -1 on error
331
 */
332
int libvslvm_metadata_read_file_io_handle(
333
     libvslvm_metadata_t *metadata,
334
     libbfio_handle_t *file_io_handle,
335
     off64_t file_offset,
336
     size64_t metadata_size,
337
     uint32_t stored_checksum,
338
     libcerror_error_t **error )
339
7.60k
{
340
7.60k
  uint8_t *data         = NULL;
341
7.60k
  static char *function = "libvslvm_metadata_read_file_io_handle";
342
7.60k
  ssize_t read_count    = 0;
343
344
7.60k
  if( metadata == NULL )
345
0
  {
346
0
    libcerror_error_set(
347
0
     error,
348
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
349
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
350
0
     "%s: invalid metadata.",
351
0
     function );
352
353
0
    return( -1 );
354
0
  }
355
7.60k
  if( ( metadata_size == 0 )
356
7.59k
   || ( metadata_size > (size64_t) MEMORY_MAXIMUM_ALLOCATION_SIZE ) )
357
131
  {
358
131
    libcerror_error_set(
359
131
     error,
360
131
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
361
131
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
362
131
     "%s: invalid metadata size value out of bounds.",
363
131
     function );
364
365
131
    goto on_error;
366
131
  }
367
#if defined( HAVE_DEBUG_OUTPUT )
368
  if( libcnotify_verbose != 0 )
369
  {
370
    libcnotify_printf(
371
     "%s: reading metadata at offset: %" PRIi64 " (0x%08" PRIx64 ")\n",
372
     function,
373
     file_offset,
374
     file_offset );
375
  }
376
#endif
377
7.47k
  data = (uint8_t *) memory_allocate(
378
7.47k
                      (size_t) metadata_size );
379
380
7.47k
  if( data == NULL )
381
0
  {
382
0
    libcerror_error_set(
383
0
     error,
384
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
385
0
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
386
0
     "%s: unable to create data.",
387
0
     function );
388
389
0
    goto on_error;
390
0
  }
391
7.47k
  read_count = libbfio_handle_read_buffer_at_offset(
392
7.47k
                file_io_handle,
393
7.47k
                data,
394
7.47k
                (size_t) metadata_size,
395
7.47k
                file_offset,
396
7.47k
                error );
397
398
7.47k
  if( read_count != (ssize_t) metadata_size )
399
229
  {
400
229
    libcerror_error_set(
401
229
     error,
402
229
     LIBCERROR_ERROR_DOMAIN_IO,
403
229
     LIBCERROR_IO_ERROR_READ_FAILED,
404
229
     "%s: unable to read metadata at offset: %" PRIi64 " (0x%08" PRIx64 ").",
405
229
     function,
406
229
     file_offset,
407
229
     file_offset );
408
409
229
    goto on_error;
410
229
  }
411
7.24k
  if( libvslvm_metadata_read_data(
412
7.24k
       metadata,
413
7.24k
       data,
414
7.24k
       (size_t) metadata_size,
415
7.24k
       stored_checksum,
416
7.24k
       error ) != 1 )
417
1.65k
  {
418
1.65k
    libcerror_error_set(
419
1.65k
     error,
420
1.65k
     LIBCERROR_ERROR_DOMAIN_IO,
421
1.65k
     LIBCERROR_IO_ERROR_READ_FAILED,
422
1.65k
     "%s: unable to read metadata.",
423
1.65k
     function );
424
425
1.65k
    goto on_error;
426
1.65k
  }
427
5.58k
  memory_free(
428
5.58k
   data );
429
430
5.58k
  return( 1 );
431
432
2.01k
on_error:
433
2.01k
  if( data != NULL )
434
1.88k
  {
435
1.88k
    memory_free(
436
1.88k
     data );
437
1.88k
  }
438
2.01k
  return( -1 );
439
7.24k
}
440
441
/* Reads the volume group
442
 * Returns the 1 if successful or -1 on error
443
 */
444
int libvslvm_metadata_read_volume_group(
445
     libvslvm_metadata_t *metadata,
446
     libcsplit_narrow_split_string_t *lines,
447
     int number_of_lines,
448
     int *line_index,
449
     libcerror_error_t **error )
450
7.05k
{
451
7.05k
  libvslvm_internal_volume_group_t *internal_volume_group = NULL;
452
7.05k
  char *line_string_segment                               = NULL;
453
7.05k
  char *value                                             = NULL;
454
7.05k
  char *value_identifier                                  = NULL;
455
7.05k
  static char *function                                   = "libvslvm_metadata_read_volume_group";
456
7.05k
  size_t line_string_segment_index                        = 0;
457
7.05k
  size_t line_string_segment_size                         = 0;
458
7.05k
  size_t value_identifier_length                          = 0;
459
7.05k
  size_t value_length                                     = 0;
460
7.05k
  uint64_t value_64bit                                    = 0;
461
462
7.05k
  if( metadata == NULL )
463
0
  {
464
0
    libcerror_error_set(
465
0
     error,
466
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
467
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
468
0
     "%s: invalid metadata.",
469
0
     function );
470
471
0
    return( -1 );
472
0
  }
473
7.05k
  if( metadata->volume_group != NULL )
474
0
  {
475
0
    libcerror_error_set(
476
0
     error,
477
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
478
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
479
0
     "%s: invalid metadata - volume group value already set.",
480
0
     function );
481
482
0
    return( -1 );
483
0
  }
484
7.05k
  if( line_index == NULL )
485
0
  {
486
0
    libcerror_error_set(
487
0
     error,
488
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
489
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
490
0
     "%s: invalid line index.",
491
0
     function );
492
493
0
    return( -1 );
494
0
  }
495
7.05k
  if( number_of_lines <= 0 )
496
0
  {
497
0
    libcerror_error_set(
498
0
     error,
499
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
500
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
501
0
     "%s: invalid number of lines value out of bounds.",
502
0
     function );
503
504
0
    return( -1 );
505
0
  }
506
7.05k
  if( ( *line_index < 0 )
507
7.05k
   || ( *line_index >= number_of_lines ) )
508
0
  {
509
0
    libcerror_error_set(
510
0
     error,
511
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
512
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
513
0
     "%s: invalid line index value out of bounds.",
514
0
     function );
515
516
0
    return( -1 );
517
0
  }
518
7.05k
  if( libcsplit_narrow_split_string_get_segment_by_index(
519
7.05k
       lines,
520
7.05k
       *line_index,
521
7.05k
       &line_string_segment,
522
7.05k
       &line_string_segment_size,
523
7.05k
       error ) != 1 )
524
0
  {
525
0
    libcerror_error_set(
526
0
     error,
527
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
528
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
529
0
     "%s: unable to retrieve line: %d.",
530
0
     function,
531
0
     *line_index );
532
533
0
    goto on_error;
534
0
  }
535
7.05k
  if( line_string_segment == NULL )
536
0
  {
537
0
    libcerror_error_set(
538
0
     error,
539
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
540
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
541
0
     "%s: missing line string segment: %d.",
542
0
     function,
543
0
     *line_index );
544
545
0
    goto on_error;
546
0
  }
547
  /* Ignore trailing white space
548
   */
549
7.05k
  if( line_string_segment_size >= 2 )
550
7.05k
  {
551
7.05k
    line_string_segment_index = line_string_segment_size - 2;
552
553
31.6k
    while( line_string_segment_index > 0 )
554
31.5k
    {
555
31.5k
      if( ( line_string_segment[ line_string_segment_index ] != '\t' )
556
29.2k
       && ( line_string_segment[ line_string_segment_index ] != '\n' )
557
25.5k
       && ( line_string_segment[ line_string_segment_index ] != '\f' )
558
23.4k
       && ( line_string_segment[ line_string_segment_index ] != '\v' )
559
14.5k
       && ( line_string_segment[ line_string_segment_index ] != '\r' )
560
13.1k
       && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
561
7.03k
      {
562
7.03k
        break;
563
7.03k
      }
564
24.5k
      line_string_segment_index--;
565
24.5k
      line_string_segment_size--;
566
24.5k
    }
567
7.05k
  }
568
  /* Ignore leading white space
569
   */
570
7.05k
  line_string_segment_index = 0;
571
572
47.4k
  while( line_string_segment_index < line_string_segment_size )
573
47.4k
  {
574
47.4k
    if( ( line_string_segment[ line_string_segment_index ] != '\t' )
575
43.0k
     && ( line_string_segment[ line_string_segment_index ] != '\n' )
576
43.0k
     && ( line_string_segment[ line_string_segment_index ] != '\f' )
577
39.5k
     && ( line_string_segment[ line_string_segment_index ] != '\v' )
578
35.4k
     && ( line_string_segment[ line_string_segment_index ] != '\r' )
579
26.0k
     && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
580
7.04k
    {
581
7.04k
      break;
582
7.04k
    }
583
40.3k
    line_string_segment_index++;
584
40.3k
  }
585
7.05k
  if( ( line_string_segment_size < 3 )
586
7.03k
   || ( line_string_segment[ line_string_segment_size - 3 ] != ' ' )
587
6.81k
   || ( line_string_segment[ line_string_segment_size - 2 ] != '{' ) )
588
276
  {
589
276
    libcerror_error_set(
590
276
     error,
591
276
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
592
276
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
593
276
     "%s: unsupported volume group signature.",
594
276
     function );
595
596
276
    goto on_error;
597
276
  }
598
6.78k
  if( libvslvm_volume_group_initialize(
599
6.78k
       &( metadata->volume_group ),
600
6.78k
       error ) != 1 )
601
0
  {
602
0
    libcerror_error_set(
603
0
     error,
604
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
605
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
606
0
     "%s: unable to create volume group.",
607
0
     function );
608
609
0
    goto on_error;
610
0
  }
611
6.78k
  internal_volume_group = (libvslvm_internal_volume_group_t *) metadata->volume_group;
612
613
6.78k
  if( ( line_string_segment_size < 2 )
614
6.78k
   || ( line_string_segment_index >= ( line_string_segment_size - 2 ) ) )
615
5
  {
616
5
    libcerror_error_set(
617
5
     error,
618
5
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
619
5
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
620
5
     "%s: invalid line string segment size value out of bounds.",
621
5
     function );
622
623
5
    goto on_error;
624
5
  }
625
6.77k
  if( libvslvm_internal_volume_group_set_name(
626
6.77k
       (libvslvm_internal_volume_group_t *) metadata->volume_group,
627
6.77k
       &( line_string_segment[ line_string_segment_index ] ),
628
6.77k
       line_string_segment_size - ( line_string_segment_index + 2 ),
629
6.77k
       error ) != 1 )
630
0
  {
631
0
    libcerror_error_set(
632
0
     error,
633
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
634
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
635
0
     "%s: unable to set volume group name.",
636
0
     function );
637
638
0
    goto on_error;
639
0
  }
640
#if defined( HAVE_DEBUG_OUTPUT )
641
  if( libcnotify_verbose != 0 )
642
  {
643
    libcnotify_printf(
644
     "%s: name\t\t\t\t: %s\n",
645
     function,
646
     internal_volume_group->name );
647
  }
648
#endif
649
6.77k
  *line_index += 1;
650
651
9.44M
  while( *line_index < number_of_lines )
652
9.44M
  {
653
9.44M
    if( libcsplit_narrow_split_string_get_segment_by_index(
654
9.44M
         lines,
655
9.44M
         *line_index,
656
9.44M
         &line_string_segment,
657
9.44M
         &line_string_segment_size,
658
9.44M
         error ) != 1 )
659
0
    {
660
0
      libcerror_error_set(
661
0
       error,
662
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
663
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
664
0
       "%s: unable to retrieve line: %d.",
665
0
       function,
666
0
       *line_index );
667
668
0
      goto on_error;
669
0
    }
670
9.44M
    if( line_string_segment == NULL )
671
0
    {
672
0
      libcerror_error_set(
673
0
       error,
674
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
675
0
       LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
676
0
       "%s: missing line string segment: %d.",
677
0
       function,
678
0
       *line_index );
679
680
0
      goto on_error;
681
0
    }
682
    /* Ignore trailing white space
683
     */
684
9.44M
    if( line_string_segment_size >= 2 )
685
181k
    {
686
181k
      line_string_segment_index = line_string_segment_size - 2;
687
688
606k
      while( line_string_segment_index > 0 )
689
554k
      {
690
554k
        if( ( line_string_segment[ line_string_segment_index ] != '\t' )
691
519k
         && ( line_string_segment[ line_string_segment_index ] != '\n' )
692
513k
         && ( line_string_segment[ line_string_segment_index ] != '\f' )
693
476k
         && ( line_string_segment[ line_string_segment_index ] != '\v' )
694
432k
         && ( line_string_segment[ line_string_segment_index ] != '\r' )
695
410k
         && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
696
128k
        {
697
128k
          break;
698
128k
        }
699
425k
        line_string_segment_index--;
700
425k
        line_string_segment_size--;
701
425k
      }
702
181k
    }
703
    /* Ignore leading white space
704
     */
705
9.44M
    line_string_segment_index = 0;
706
707
11.8M
    while( line_string_segment_index < line_string_segment_size )
708
11.8M
    {
709
11.8M
      if( ( line_string_segment[ line_string_segment_index ] != '\t' )
710
11.8M
       && ( line_string_segment[ line_string_segment_index ] != '\n' )
711
11.8M
       && ( line_string_segment[ line_string_segment_index ] != '\f' )
712
11.8M
       && ( line_string_segment[ line_string_segment_index ] != '\v' )
713
11.7M
       && ( line_string_segment[ line_string_segment_index ] != '\r' )
714
11.6M
       && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
715
9.43M
      {
716
9.43M
        break;
717
9.43M
      }
718
2.40M
      line_string_segment_index++;
719
2.40M
    }
720
    /* Skip an empty line
721
     */
722
9.44M
    if( ( line_string_segment_index >= line_string_segment_size )
723
9.43M
     || ( line_string_segment[ line_string_segment_index ] == 0 ) )
724
9.27M
    {
725
9.27M
      *line_index += 1;
726
727
9.27M
      continue;
728
9.27M
    }
729
    /* Check for the end of section
730
     */
731
171k
    if( ( ( line_string_segment_size - line_string_segment_index ) == 2 )
732
50.3k
     && ( line_string_segment[ line_string_segment_index ] == '}' ) )
733
60
    {
734
60
      *line_index += 1;
735
736
60
      break;
737
60
    }
738
    /* Check for the start of a sub section
739
     */
740
171k
    if( ( line_string_segment_size - line_string_segment_index ) == 18 )
741
8.94k
    {
742
8.94k
      if( narrow_string_compare(
743
8.94k
           &( line_string_segment[ line_string_segment_index ] ),
744
8.94k
           "logical_volumes {",
745
8.94k
           17 ) == 0 )
746
5.89k
      {
747
5.89k
        if( libvslvm_metadata_read_logical_volumes(
748
5.89k
             metadata,
749
5.89k
             metadata->volume_group,
750
5.89k
             lines,
751
5.89k
             number_of_lines,
752
5.89k
             line_index,
753
5.89k
             error ) != 1 )
754
822
        {
755
822
          libcerror_error_set(
756
822
           error,
757
822
           LIBCERROR_ERROR_DOMAIN_IO,
758
822
           LIBCERROR_IO_ERROR_READ_FAILED,
759
822
           "%s: unable to read logical volumes.",
760
822
           function );
761
762
822
          goto on_error;
763
822
        }
764
5.06k
        continue;
765
5.89k
      }
766
8.94k
    }
767
162k
    else if( ( line_string_segment_size - line_string_segment_index ) == 19 )
768
7.31k
    {
769
7.31k
      if( narrow_string_compare(
770
7.31k
           &( line_string_segment[ line_string_segment_index ] ),
771
7.31k
           "physical_volumes {",
772
7.31k
           18 ) == 0 )
773
3.69k
      {
774
3.69k
        if( libvslvm_metadata_read_physical_volumes(
775
3.69k
             metadata,
776
3.69k
             metadata->volume_group,
777
3.69k
             lines,
778
3.69k
             number_of_lines,
779
3.69k
             line_index,
780
3.69k
             error ) != 1 )
781
179
        {
782
179
          libcerror_error_set(
783
179
           error,
784
179
           LIBCERROR_ERROR_DOMAIN_IO,
785
179
           LIBCERROR_IO_ERROR_READ_FAILED,
786
179
           "%s: unable to read physical volumes.",
787
179
           function );
788
789
179
          goto on_error;
790
179
        }
791
3.51k
        continue;
792
3.69k
      }
793
7.31k
    }
794
    /* Determine the value identifier
795
     */
796
161k
    value_identifier        = &( line_string_segment[ line_string_segment_index ] );
797
161k
    value_identifier_length = 0;
798
799
14.0M
    while( line_string_segment_index < line_string_segment_size )
800
13.9M
    {
801
13.9M
      if( ( line_string_segment[ line_string_segment_index ] == '\t' )
802
13.9M
       || ( line_string_segment[ line_string_segment_index ] == '\n' )
803
13.9M
       || ( line_string_segment[ line_string_segment_index ] == '\f' )
804
13.9M
       || ( line_string_segment[ line_string_segment_index ] == '\v' )
805
13.9M
       || ( line_string_segment[ line_string_segment_index ] == '\r' )
806
13.9M
       || ( line_string_segment[ line_string_segment_index ] == ' ' )
807
13.8M
       || ( line_string_segment[ line_string_segment_index ] == '=' ) )
808
108k
      {
809
108k
        break;
810
108k
      }
811
13.8M
      value_identifier_length++;
812
813
13.8M
      line_string_segment_index++;
814
13.8M
    }
815
    /* Skip a line not containing a value
816
     */
817
161k
    if( ( line_string_segment_index >= line_string_segment_size )
818
108k
     || ( line_string_segment[ line_string_segment_index ] == 0 ) )
819
53.5k
    {
820
53.5k
      *line_index += 1;
821
822
53.5k
      continue;
823
53.5k
    }
824
    /* Make sure the value identifier is terminated by an end of string
825
     */
826
108k
    line_string_segment[ line_string_segment_index ] = 0;
827
828
108k
    line_string_segment_index++;
829
830
    /* Ignore whitespace
831
     */
832
300k
    while( line_string_segment_index < line_string_segment_size )
833
277k
    {
834
277k
      if( ( line_string_segment[ line_string_segment_index ] != '\t' )
835
265k
       && ( line_string_segment[ line_string_segment_index ] != '\n' )
836
262k
       && ( line_string_segment[ line_string_segment_index ] != '\f' )
837
236k
       && ( line_string_segment[ line_string_segment_index ] != '\v' )
838
227k
       && ( line_string_segment[ line_string_segment_index ] != '\r' )
839
217k
       && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
840
85.1k
      {
841
85.1k
        break;
842
85.1k
      }
843
192k
      line_string_segment_index++;
844
192k
    }
845
108k
    if( line_string_segment[ line_string_segment_index ] == '=' )
846
25.0k
    {
847
25.0k
      line_string_segment_index++;
848
849
57.6k
      while( line_string_segment_index < line_string_segment_size )
850
54.0k
      {
851
54.0k
        if( ( line_string_segment[ line_string_segment_index ] != '\t' )
852
51.5k
         && ( line_string_segment[ line_string_segment_index ] != '\n' )
853
49.3k
         && ( line_string_segment[ line_string_segment_index ] != '\f' )
854
46.8k
         && ( line_string_segment[ line_string_segment_index ] != '\v' )
855
44.1k
         && ( line_string_segment[ line_string_segment_index ] != '\r' )
856
42.7k
         && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
857
21.5k
        {
858
21.5k
          break;
859
21.5k
        }
860
32.5k
        line_string_segment_index++;
861
32.5k
      }
862
25.0k
    }
863
    /* Skip a line not containing a value
864
     */
865
108k
    if( ( line_string_segment_index >= line_string_segment_size )
866
81.6k
     || ( line_string_segment[ line_string_segment_index ] == 0 ) )
867
33.7k
    {
868
33.7k
      *line_index += 1;
869
870
33.7k
      continue;
871
33.7k
    }
872
    /* Determine the value
873
     */
874
74.4k
    value        = &( line_string_segment[ line_string_segment_index ] );
875
74.4k
    value_length = line_string_segment_size - 1;
876
877
    /* Ingore quotes at the beginning of the value data
878
     */
879
74.4k
    if( ( line_string_segment[ line_string_segment_index ] == '"' )
880
66.2k
     || ( line_string_segment[ line_string_segment_index ] == '\'' ) )
881
11.8k
    {
882
11.8k
      line_string_segment_index++;
883
11.8k
      value++;
884
11.8k
      value_length--;
885
11.8k
    }
886
    /* Ingore quotes at the end of the value data
887
     */
888
74.4k
    if( ( line_string_segment[ value_length - 1 ] == '"' )
889
69.5k
     || ( line_string_segment[ value_length - 1 ] == '\'' ) )
890
7.02k
    {
891
7.02k
      value_length--;
892
7.02k
    }
893
    /* Make sure the value is terminated by an end of string
894
     */
895
74.4k
    line_string_segment[ value_length ] = 0;
896
897
74.4k
    value_length -= line_string_segment_index;
898
899
74.4k
    if( value_identifier_length == 2 )
900
18.7k
    {
901
18.7k
      if( narrow_string_compare(
902
18.7k
           value_identifier,
903
18.7k
           "id",
904
18.7k
           2 ) == 0 )
905
953
      {
906
953
        if( libvslvm_volume_group_set_identifier(
907
953
             metadata->volume_group,
908
953
             value,
909
953
             value_length + 1,
910
953
             error ) != 1 )
911
69
        {
912
69
          libcerror_error_set(
913
69
           error,
914
69
           LIBCERROR_ERROR_DOMAIN_RUNTIME,
915
69
           LIBCERROR_RUNTIME_ERROR_SET_FAILED,
916
69
           "%s: unable to set volume group identifier.",
917
69
           function );
918
919
69
          goto on_error;
920
69
        }
921
#if defined( HAVE_DEBUG_OUTPUT )
922
        if( libcnotify_verbose != 0 )
923
        {
924
          libcnotify_printf(
925
           "%s: identifier\t\t\t\t: %s\n",
926
           function,
927
           internal_volume_group->identifier );
928
        }
929
#endif
930
953
      }
931
18.7k
    }
932
55.7k
    else if( value_identifier_length == 5 )
933
7.58k
    {
934
7.58k
      if( narrow_string_compare(
935
7.58k
           value_identifier,
936
7.58k
           "flags",
937
7.58k
           5 ) == 0 )
938
2.59k
      {
939
#if defined( HAVE_DEBUG_OUTPUT )
940
        if( libcnotify_verbose != 0 )
941
        {
942
          libcnotify_printf(
943
           "%s: flags\t\t\t\t: %s\n",
944
           function,
945
           value );
946
        }
947
#endif
948
/* TODO */
949
2.59k
      }
950
4.98k
      else if( narrow_string_compare(
951
4.98k
                value_identifier,
952
4.98k
                "seqno",
953
4.98k
                5 ) == 0 )
954
1.35k
      {
955
#if defined( HAVE_DEBUG_OUTPUT )
956
        if( libcnotify_verbose != 0 )
957
        {
958
          libcnotify_printf(
959
           "%s: sequence number\t\t\t: %s\n",
960
           function,
961
           value );
962
        }
963
#endif
964
1.35k
        if( libfvalue_utf8_string_copy_to_integer(
965
1.35k
             (uint8_t *) value,
966
1.35k
             value_length + 1,
967
1.35k
             &value_64bit,
968
1.35k
             32,
969
1.35k
             LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED,
970
1.35k
             error ) != 1 )
971
26
        {
972
26
          libcerror_error_set(
973
26
           error,
974
26
           LIBCERROR_ERROR_DOMAIN_MEMORY,
975
26
           LIBCERROR_MEMORY_ERROR_SET_FAILED,
976
26
           "%s: unable to set sequence number.",
977
26
           function );
978
979
26
          goto on_error;
980
26
        }
981
1.32k
        if( value_64bit > (uint64_t) UINT32_MAX )
982
18
        {
983
18
          libcerror_error_set(
984
18
           error,
985
18
           LIBCERROR_ERROR_DOMAIN_RUNTIME,
986
18
           LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
987
18
           "%s: invalid sequence number value exceeds maximum.",
988
18
           function );
989
990
18
          goto on_error;
991
18
        }
992
1.30k
        internal_volume_group->sequence_number = (uint32_t) value_64bit;
993
1.30k
      }
994
7.58k
    }
995
48.1k
    else if( value_identifier_length == 6 )
996
6.66k
    {
997
6.66k
      if( narrow_string_compare(
998
6.66k
           value_identifier,
999
6.66k
           "max_lv",
1000
6.66k
           6 ) == 0 )
1001
1.52k
      {
1002
#if defined( HAVE_DEBUG_OUTPUT )
1003
        if( libcnotify_verbose != 0 )
1004
        {
1005
          libcnotify_printf(
1006
           "%s: max_lv\t\t\t\t: %s\n",
1007
           function,
1008
           value );
1009
        }
1010
#endif
1011
/* TODO */
1012
1.52k
      }
1013
5.14k
      else if( narrow_string_compare(
1014
5.14k
                value_identifier,
1015
5.14k
                "max_pv",
1016
5.14k
                6 ) == 0 )
1017
1.14k
      {
1018
#if defined( HAVE_DEBUG_OUTPUT )
1019
        if( libcnotify_verbose != 0 )
1020
        {
1021
          libcnotify_printf(
1022
           "%s: max_pv\t\t\t\t: %s\n",
1023
           function,
1024
           value );
1025
        }
1026
#endif
1027
/* TODO */
1028
1.14k
      }
1029
4.00k
      else if( narrow_string_compare(
1030
4.00k
                value_identifier,
1031
4.00k
                "status",
1032
4.00k
                6 ) == 0 )
1033
632
      {
1034
#if defined( HAVE_DEBUG_OUTPUT )
1035
        if( libcnotify_verbose != 0 )
1036
        {
1037
          libcnotify_printf(
1038
           "%s: status flags\t\t\t: %s\n",
1039
           function,
1040
           value );
1041
        }
1042
#endif
1043
/* TODO */
1044
632
      }
1045
6.66k
    }
1046
41.4k
    else if( value_identifier_length == 11 )
1047
6.14k
    {
1048
6.14k
      if( narrow_string_compare(
1049
6.14k
           value_identifier,
1050
6.14k
           "extent_size",
1051
6.14k
           11 ) == 0 )
1052
4.91k
      {
1053
#if defined( HAVE_DEBUG_OUTPUT )
1054
        if( libcnotify_verbose != 0 )
1055
        {
1056
          libcnotify_printf(
1057
           "%s: extent size\t\t\t: %s\n",
1058
           function,
1059
           value );
1060
        }
1061
#endif
1062
4.91k
        if( libfvalue_utf8_string_copy_to_integer(
1063
4.91k
             (uint8_t *) value,
1064
4.91k
             value_length + 1,
1065
4.91k
             &value_64bit,
1066
4.91k
             64,
1067
4.91k
             LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED,
1068
4.91k
             error ) != 1 )
1069
28
        {
1070
28
          libcerror_error_set(
1071
28
           error,
1072
28
           LIBCERROR_ERROR_DOMAIN_MEMORY,
1073
28
           LIBCERROR_MEMORY_ERROR_SET_FAILED,
1074
28
           "%s: unable to set extent size.",
1075
28
           function );
1076
1077
28
          goto on_error;
1078
28
        }
1079
4.88k
        if( value_64bit > (uint64_t) ( UINT64_MAX / 512 ) )
1080
47
        {
1081
47
          libcerror_error_set(
1082
47
           error,
1083
47
           LIBCERROR_ERROR_DOMAIN_RUNTIME,
1084
47
           LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
1085
47
           "%s: invalid extent size value exceeds maximum.",
1086
47
           function );
1087
1088
47
          goto on_error;
1089
47
        }
1090
4.84k
        value_64bit *= 512;
1091
1092
4.84k
        internal_volume_group->extent_size = value_64bit;
1093
4.84k
      }
1094
6.14k
    }
1095
35.3k
    else if( value_identifier_length == 15 )
1096
1.92k
    {
1097
1.92k
      if( narrow_string_compare(
1098
1.92k
           value_identifier,
1099
1.92k
           "metadata_copies",
1100
1.92k
           15 ) == 0 )
1101
616
      {
1102
#if defined( HAVE_DEBUG_OUTPUT )
1103
        if( libcnotify_verbose != 0 )
1104
        {
1105
          libcnotify_printf(
1106
           "%s: metadata copies\t\t\t: %s\n",
1107
           function,
1108
           value );
1109
        }
1110
#endif
1111
/* TODO */
1112
616
      }
1113
1.92k
    }
1114
#if defined( HAVE_DEBUG_OUTPUT )
1115
    else if( libcnotify_verbose != 0 )
1116
    {
1117
      libcnotify_printf(
1118
       "%s: value: %d\t\t\t: %s = %s\n",
1119
       function,
1120
       *line_index,
1121
       value_identifier,
1122
       value );
1123
    }
1124
#endif
1125
74.2k
    *line_index += 1;
1126
74.2k
  }
1127
#if defined( HAVE_DEBUG_OUTPUT )
1128
  if( libcnotify_verbose != 0 )
1129
  {
1130
    libcnotify_printf(
1131
     "\n" );
1132
  }
1133
#endif
1134
5.58k
  return( 1 );
1135
1136
1.47k
on_error:
1137
1.47k
  if( metadata->volume_group != NULL )
1138
1.19k
  {
1139
1.19k
    libvslvm_internal_volume_group_free(
1140
1.19k
     (libvslvm_internal_volume_group_t **) &( metadata->volume_group ),
1141
1.19k
     NULL );
1142
1.19k
  }
1143
1.47k
  return( -1 );
1144
6.77k
}
1145
1146
/* Reads the physical volumes
1147
 * Returns the 1 if successful or -1 on error
1148
 */
1149
int libvslvm_metadata_read_physical_volumes(
1150
     libvslvm_metadata_t *metadata,
1151
     libvslvm_volume_group_t *volume_group,
1152
     libcsplit_narrow_split_string_t *lines,
1153
     int number_of_lines,
1154
     int *line_index,
1155
     libcerror_error_t **error )
1156
3.69k
{
1157
3.69k
  char *line_string_segment        = NULL;
1158
3.69k
  static char *function            = "libvslvm_metadata_read_physical_volumes";
1159
3.69k
  size_t line_string_segment_index = 0;
1160
3.69k
  size_t line_string_segment_size  = 0;
1161
1162
3.69k
  if( metadata == NULL )
1163
0
  {
1164
0
    libcerror_error_set(
1165
0
     error,
1166
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1167
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1168
0
     "%s: invalid metadata.",
1169
0
     function );
1170
1171
0
    return( -1 );
1172
0
  }
1173
3.69k
  if( line_index == NULL )
1174
0
  {
1175
0
    libcerror_error_set(
1176
0
     error,
1177
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1178
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1179
0
     "%s: invalid line index.",
1180
0
     function );
1181
1182
0
    return( -1 );
1183
0
  }
1184
3.69k
  if( number_of_lines <= 0 )
1185
0
  {
1186
0
    libcerror_error_set(
1187
0
     error,
1188
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1189
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
1190
0
     "%s: invalid number of lines value out of bounds.",
1191
0
     function );
1192
1193
0
    return( -1 );
1194
0
  }
1195
3.69k
  if( ( *line_index < 0 )
1196
3.69k
   || ( *line_index >= number_of_lines ) )
1197
0
  {
1198
0
    libcerror_error_set(
1199
0
     error,
1200
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1201
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
1202
0
     "%s: invalid line index value out of bounds.",
1203
0
     function );
1204
1205
0
    return( -1 );
1206
0
  }
1207
3.69k
  if( libcsplit_narrow_split_string_get_segment_by_index(
1208
3.69k
       lines,
1209
3.69k
       *line_index,
1210
3.69k
       &line_string_segment,
1211
3.69k
       &line_string_segment_size,
1212
3.69k
       error ) != 1 )
1213
0
  {
1214
0
    libcerror_error_set(
1215
0
     error,
1216
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1217
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1218
0
     "%s: unable to retrieve line: %d.",
1219
0
     function,
1220
0
     *line_index );
1221
1222
0
    return( -1 );
1223
0
  }
1224
3.69k
  if( line_string_segment == NULL )
1225
0
  {
1226
0
    libcerror_error_set(
1227
0
     error,
1228
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1229
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1230
0
     "%s: missing line string segment: %d.",
1231
0
     function,
1232
0
     *line_index );
1233
1234
0
    return( -1 );
1235
0
  }
1236
  /* Ignore trailing white space
1237
   */
1238
3.69k
  if( line_string_segment_size >= 2 )
1239
3.69k
  {
1240
3.69k
    line_string_segment_index = line_string_segment_size - 2;
1241
1242
59.8k
    while( line_string_segment_index > 0 )
1243
59.8k
    {
1244
59.8k
      if( ( line_string_segment[ line_string_segment_index ] != '\t' )
1245
56.9k
       && ( line_string_segment[ line_string_segment_index ] != '\n' )
1246
56.9k
       && ( line_string_segment[ line_string_segment_index ] != '\f' )
1247
53.8k
       && ( line_string_segment[ line_string_segment_index ] != '\v' )
1248
45.1k
       && ( line_string_segment[ line_string_segment_index ] != '\r' )
1249
40.9k
       && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
1250
3.69k
      {
1251
3.69k
        break;
1252
3.69k
      }
1253
56.1k
      line_string_segment_index--;
1254
56.1k
      line_string_segment_size--;
1255
56.1k
    }
1256
3.69k
  }
1257
  /* Ignore leading white space
1258
   */
1259
3.69k
  line_string_segment_index = 0;
1260
1261
910k
  while( line_string_segment_index < line_string_segment_size )
1262
910k
  {
1263
910k
    if( ( line_string_segment[ line_string_segment_index ] != '\t' )
1264
906k
     && ( line_string_segment[ line_string_segment_index ] != '\n' )
1265
906k
     && ( line_string_segment[ line_string_segment_index ] != '\f' )
1266
901k
     && ( line_string_segment[ line_string_segment_index ] != '\v' )
1267
896k
     && ( line_string_segment[ line_string_segment_index ] != '\r' )
1268
826k
     && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
1269
3.69k
    {
1270
3.69k
      break;
1271
3.69k
    }
1272
907k
    line_string_segment_index++;
1273
907k
  }
1274
3.69k
  if( ( ( line_string_segment_size - line_string_segment_index ) != 19 )
1275
3.69k
   || ( narrow_string_compare(
1276
3.69k
         &( line_string_segment[ line_string_segment_index ] ),
1277
3.69k
         "physical_volumes {",
1278
3.69k
         18 ) != 0 ) )
1279
0
  {
1280
0
    libcerror_error_set(
1281
0
     error,
1282
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1283
0
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
1284
0
     "%s: unsupported physical volumes signature.",
1285
0
     function );
1286
1287
0
    return( -1 );
1288
0
  }
1289
3.69k
  *line_index += 1;
1290
1291
1.15M
  while( *line_index < number_of_lines )
1292
1.15M
  {
1293
1.15M
    if( libcsplit_narrow_split_string_get_segment_by_index(
1294
1.15M
         lines,
1295
1.15M
         *line_index,
1296
1.15M
         &line_string_segment,
1297
1.15M
         &line_string_segment_size,
1298
1.15M
         error ) != 1 )
1299
0
    {
1300
0
      libcerror_error_set(
1301
0
       error,
1302
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1303
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1304
0
       "%s: unable to retrieve line: %d.",
1305
0
       function,
1306
0
       *line_index );
1307
1308
0
      return( -1 );
1309
0
    }
1310
1.15M
    if( line_string_segment == NULL )
1311
0
    {
1312
0
      libcerror_error_set(
1313
0
       error,
1314
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1315
0
       LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1316
0
       "%s: missing line string segment: %d.",
1317
0
       function,
1318
0
       *line_index );
1319
1320
0
      return( -1 );
1321
0
    }
1322
    /* Ignore trailing white space
1323
     */
1324
1.15M
    if( line_string_segment_size >= 2 )
1325
109k
    {
1326
109k
      line_string_segment_index = line_string_segment_size - 2;
1327
1328
219k
      while( line_string_segment_index > 0 )
1329
201k
      {
1330
201k
        if( ( line_string_segment[ line_string_segment_index ] != '\t' )
1331
185k
         && ( line_string_segment[ line_string_segment_index ] != '\n' )
1332
179k
         && ( line_string_segment[ line_string_segment_index ] != '\f' )
1333
167k
         && ( line_string_segment[ line_string_segment_index ] != '\v' )
1334
114k
         && ( line_string_segment[ line_string_segment_index ] != '\r' )
1335
108k
         && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
1336
92.0k
        {
1337
92.0k
          break;
1338
92.0k
        }
1339
109k
        line_string_segment_index--;
1340
109k
        line_string_segment_size--;
1341
109k
      }
1342
109k
    }
1343
    /* Ignore leading white space
1344
     */
1345
1.15M
    line_string_segment_index = 0;
1346
1347
1.26M
    while( line_string_segment_index < line_string_segment_size )
1348
1.26M
    {
1349
1.26M
      if( ( line_string_segment[ line_string_segment_index ] != '\t' )
1350
1.24M
       && ( line_string_segment[ line_string_segment_index ] != '\n' )
1351
1.24M
       && ( line_string_segment[ line_string_segment_index ] != '\f' )
1352
1.24M
       && ( line_string_segment[ line_string_segment_index ] != '\v' )
1353
1.19M
       && ( line_string_segment[ line_string_segment_index ] != '\r' )
1354
1.18M
       && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
1355
1.15M
      {
1356
1.15M
        break;
1357
1.15M
      }
1358
108k
      line_string_segment_index++;
1359
108k
    }
1360
    /* Skip an empty line
1361
     */
1362
1.15M
    if( ( line_string_segment_index >= line_string_segment_size )
1363
1.15M
     || ( line_string_segment[ line_string_segment_index ] == 0 ) )
1364
1.05M
    {
1365
1.05M
      *line_index += 1;
1366
1367
1.05M
      continue;
1368
1.05M
    }
1369
    /* Check for the end of section
1370
     */
1371
106k
    if( ( ( line_string_segment_size - line_string_segment_index ) == 2 )
1372
17.6k
     && ( line_string_segment[ line_string_segment_index ] == '}' ) )
1373
1.96k
    {
1374
1.96k
      *line_index += 1;
1375
1376
1.96k
      break;
1377
1.96k
    }
1378
    /* Check for the start of a sub section
1379
     */
1380
104k
    if( ( line_string_segment_size >= 3 )
1381
91.7k
     && ( line_string_segment[ line_string_segment_size - 3 ] == ' ' )
1382
68.9k
     && ( line_string_segment[ line_string_segment_size - 2 ] == '{' ) )
1383
57.5k
    {
1384
57.5k
      if( libvslvm_metadata_read_physical_volume(
1385
57.5k
           metadata,
1386
57.5k
           volume_group,
1387
57.5k
           lines,
1388
57.5k
           number_of_lines,
1389
57.5k
           line_index,
1390
57.5k
           error ) != 1 )
1391
179
      {
1392
179
        libcerror_error_set(
1393
179
         error,
1394
179
         LIBCERROR_ERROR_DOMAIN_IO,
1395
179
         LIBCERROR_IO_ERROR_READ_FAILED,
1396
179
         "%s: unable to read physical volume.",
1397
179
         function );
1398
1399
179
        return( -1 );
1400
179
      }
1401
57.5k
    }
1402
47.0k
    else
1403
47.0k
    {
1404
/* TODO debug print other lines ? */
1405
47.0k
      *line_index += 1;
1406
47.0k
    }
1407
104k
  }
1408
3.51k
  return( 1 );
1409
3.69k
}
1410
1411
/* Reads the physical volume
1412
 * Returns the 1 if successful or -1 on error
1413
 */
1414
int libvslvm_metadata_read_physical_volume(
1415
     libvslvm_metadata_t *metadata,
1416
     libvslvm_volume_group_t *volume_group,
1417
     libcsplit_narrow_split_string_t *lines,
1418
     int number_of_lines,
1419
     int *line_index,
1420
     libcerror_error_t **error )
1421
57.5k
{
1422
57.5k
  libvslvm_physical_volume_t *physical_volume = NULL;
1423
57.5k
  char *line_string_segment                   = NULL;
1424
57.5k
  char *value                                 = NULL;
1425
57.5k
  char *value_identifier                      = NULL;
1426
57.5k
  static char *function                       = "libvslvm_metadata_read_physical_volume";
1427
57.5k
  size_t line_string_segment_index            = 0;
1428
57.5k
  size_t line_string_segment_size             = 0;
1429
57.5k
  size_t value_identifier_length              = 0;
1430
57.5k
  size_t value_length                         = 0;
1431
57.5k
  uint64_t value_64bit                        = 0;
1432
1433
57.5k
  if( metadata == NULL )
1434
0
  {
1435
0
    libcerror_error_set(
1436
0
     error,
1437
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1438
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1439
0
     "%s: invalid metadata.",
1440
0
     function );
1441
1442
0
    return( -1 );
1443
0
  }
1444
57.5k
  if( volume_group == NULL )
1445
0
  {
1446
0
    libcerror_error_set(
1447
0
     error,
1448
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1449
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1450
0
     "%s: invalid volume group.",
1451
0
     function );
1452
1453
0
    return( -1 );
1454
0
  }
1455
57.5k
  if( line_index == NULL )
1456
0
  {
1457
0
    libcerror_error_set(
1458
0
     error,
1459
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1460
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1461
0
     "%s: invalid line index.",
1462
0
     function );
1463
1464
0
    return( -1 );
1465
0
  }
1466
57.5k
  if( number_of_lines <= 0 )
1467
0
  {
1468
0
    libcerror_error_set(
1469
0
     error,
1470
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1471
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
1472
0
     "%s: invalid number of lines value out of bounds.",
1473
0
     function );
1474
1475
0
    return( -1 );
1476
0
  }
1477
57.5k
  if( ( *line_index < 0 )
1478
57.5k
   || ( *line_index >= number_of_lines ) )
1479
0
  {
1480
0
    libcerror_error_set(
1481
0
     error,
1482
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1483
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
1484
0
     "%s: invalid line index value out of bounds.",
1485
0
     function );
1486
1487
0
    return( -1 );
1488
0
  }
1489
57.5k
  if( libcsplit_narrow_split_string_get_segment_by_index(
1490
57.5k
       lines,
1491
57.5k
       *line_index,
1492
57.5k
       &line_string_segment,
1493
57.5k
       &line_string_segment_size,
1494
57.5k
       error ) != 1 )
1495
0
  {
1496
0
    libcerror_error_set(
1497
0
     error,
1498
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1499
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1500
0
     "%s: unable to retrieve line: %d.",
1501
0
     function,
1502
0
     *line_index );
1503
1504
0
    goto on_error;
1505
0
  }
1506
57.5k
  if( line_string_segment == NULL )
1507
0
  {
1508
0
    libcerror_error_set(
1509
0
     error,
1510
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1511
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1512
0
     "%s: missing line string segment: %d.",
1513
0
     function,
1514
0
     *line_index );
1515
1516
0
    goto on_error;
1517
0
  }
1518
  /* Ignore trailing white space
1519
   */
1520
57.5k
  if( line_string_segment_size >= 2 )
1521
57.5k
  {
1522
57.5k
    line_string_segment_index = line_string_segment_size - 2;
1523
1524
104k
    while( line_string_segment_index > 0 )
1525
104k
    {
1526
104k
      if( ( line_string_segment[ line_string_segment_index ] != '\t' )
1527
102k
       && ( line_string_segment[ line_string_segment_index ] != '\n' )
1528
99.0k
       && ( line_string_segment[ line_string_segment_index ] != '\f' )
1529
97.0k
       && ( line_string_segment[ line_string_segment_index ] != '\v' )
1530
65.5k
       && ( line_string_segment[ line_string_segment_index ] != '\r' )
1531
63.0k
       && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
1532
57.5k
      {
1533
57.5k
        break;
1534
57.5k
      }
1535
47.2k
      line_string_segment_index--;
1536
47.2k
      line_string_segment_size--;
1537
47.2k
    }
1538
57.5k
  }
1539
  /* Ignore leading white space
1540
   */
1541
57.5k
  line_string_segment_index = 0;
1542
1543
129k
  while( line_string_segment_index < line_string_segment_size )
1544
129k
  {
1545
129k
    if( ( line_string_segment[ line_string_segment_index ] != '\t' )
1546
122k
     && ( line_string_segment[ line_string_segment_index ] != '\n' )
1547
122k
     && ( line_string_segment[ line_string_segment_index ] != '\f' )
1548
119k
     && ( line_string_segment[ line_string_segment_index ] != '\v' )
1549
80.7k
     && ( line_string_segment[ line_string_segment_index ] != '\r' )
1550
77.9k
     && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
1551
57.5k
    {
1552
57.5k
      break;
1553
57.5k
    }
1554
72.3k
    line_string_segment_index++;
1555
72.3k
  }
1556
57.5k
  if( ( line_string_segment_size < 3 )
1557
57.5k
   || ( line_string_segment[ line_string_segment_size - 3 ] != ' ' )
1558
57.5k
   || ( line_string_segment[ line_string_segment_size - 2 ] != '{' ) )
1559
0
  {
1560
0
    libcerror_error_set(
1561
0
     error,
1562
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1563
0
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
1564
0
     "%s: unsupported physical volume signature.",
1565
0
     function );
1566
1567
0
    goto on_error;
1568
0
  }
1569
57.5k
  if( libvslvm_physical_volume_initialize(
1570
57.5k
       &physical_volume,
1571
57.5k
       error ) != 1 )
1572
0
  {
1573
0
    libcerror_error_set(
1574
0
     error,
1575
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1576
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
1577
0
     "%s: unable to create physical volume.",
1578
0
     function );
1579
1580
0
    goto on_error;
1581
0
  }
1582
57.5k
  if( ( line_string_segment_size < 2 )
1583
57.5k
   || ( line_string_segment_index >= ( line_string_segment_size - 2 ) ) )
1584
10
  {
1585
10
    libcerror_error_set(
1586
10
     error,
1587
10
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1588
10
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
1589
10
     "%s: invalid line string segment size value out of bounds.",
1590
10
     function );
1591
1592
10
    goto on_error;
1593
10
  }
1594
57.5k
  if( libvslvm_physical_volume_set_name(
1595
57.5k
       physical_volume,
1596
57.5k
       &( line_string_segment[ line_string_segment_index ] ),
1597
57.5k
       line_string_segment_size - ( line_string_segment_index + 2 ),
1598
57.5k
       error ) != 1 )
1599
0
  {
1600
0
    libcerror_error_set(
1601
0
     error,
1602
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
1603
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1604
0
     "%s: unable to set physical volume name.",
1605
0
     function );
1606
1607
0
    goto on_error;
1608
0
  }
1609
#if defined( HAVE_DEBUG_OUTPUT )
1610
  if( libcnotify_verbose != 0 )
1611
  {
1612
    libcnotify_printf(
1613
     "\n" );
1614
1615
    libcnotify_printf(
1616
     "%s: name\t\t\t\t: %s\n",
1617
     function,
1618
     ( (libvslvm_internal_physical_volume_t *) physical_volume )->name );
1619
  }
1620
#endif
1621
57.5k
  *line_index += 1;
1622
1623
5.62M
  while( *line_index < number_of_lines )
1624
5.62M
  {
1625
5.62M
    if( libcsplit_narrow_split_string_get_segment_by_index(
1626
5.62M
         lines,
1627
5.62M
         *line_index,
1628
5.62M
         &line_string_segment,
1629
5.62M
         &line_string_segment_size,
1630
5.62M
         error ) != 1 )
1631
0
    {
1632
0
      libcerror_error_set(
1633
0
       error,
1634
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1635
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1636
0
       "%s: unable to retrieve line: %d.",
1637
0
       function,
1638
0
       *line_index );
1639
1640
0
      goto on_error;
1641
0
    }
1642
5.62M
    if( line_string_segment == NULL )
1643
0
    {
1644
0
      libcerror_error_set(
1645
0
       error,
1646
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
1647
0
       LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
1648
0
       "%s: missing line string segment: %d.",
1649
0
       function,
1650
0
       *line_index );
1651
1652
0
      goto on_error;
1653
0
    }
1654
    /* Ignore trailing white space
1655
     */
1656
5.62M
    if( line_string_segment_size >= 2 )
1657
234k
    {
1658
234k
      line_string_segment_index = line_string_segment_size - 2;
1659
1660
490k
      while( line_string_segment_index > 0 )
1661
393k
      {
1662
393k
        if( ( line_string_segment[ line_string_segment_index ] != '\t' )
1663
377k
         && ( line_string_segment[ line_string_segment_index ] != '\n' )
1664
351k
         && ( line_string_segment[ line_string_segment_index ] != '\f' )
1665
323k
         && ( line_string_segment[ line_string_segment_index ] != '\v' )
1666
250k
         && ( line_string_segment[ line_string_segment_index ] != '\r' )
1667
235k
         && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
1668
138k
        {
1669
138k
          break;
1670
138k
        }
1671
255k
        line_string_segment_index--;
1672
255k
        line_string_segment_size--;
1673
255k
      }
1674
234k
    }
1675
    /* Ignore leading white space
1676
     */
1677
5.62M
    line_string_segment_index = 0;
1678
1679
5.91M
    while( line_string_segment_index < line_string_segment_size )
1680
5.90M
    {
1681
5.90M
      if( ( line_string_segment[ line_string_segment_index ] != '\t' )
1682
5.89M
       && ( line_string_segment[ line_string_segment_index ] != '\n' )
1683
5.89M
       && ( line_string_segment[ line_string_segment_index ] != '\f' )
1684
5.88M
       && ( line_string_segment[ line_string_segment_index ] != '\v' )
1685
5.77M
       && ( line_string_segment[ line_string_segment_index ] != '\r' )
1686
5.71M
       && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
1687
5.61M
      {
1688
5.61M
        break;
1689
5.61M
      }
1690
289k
      line_string_segment_index++;
1691
289k
    }
1692
    /* Skip an empty line
1693
     */
1694
5.62M
    if( ( line_string_segment_index >= line_string_segment_size )
1695
5.61M
     || ( line_string_segment[ line_string_segment_index ] == 0 ) )
1696
5.40M
    {
1697
5.40M
      *line_index += 1;
1698
1699
5.40M
      continue;
1700
5.40M
    }
1701
    /* Check for the end of section
1702
     */
1703
218k
    if( ( ( line_string_segment_size - line_string_segment_index ) == 2 )
1704
107k
     && ( line_string_segment[ line_string_segment_index ] == '}' ) )
1705
56.1k
    {
1706
56.1k
      *line_index += 1;
1707
1708
56.1k
      break;
1709
56.1k
    }
1710
    /* Determine the value identifier
1711
     */
1712
162k
    value_identifier        = &( line_string_segment[ line_string_segment_index ] );
1713
162k
    value_identifier_length = 0;
1714
1715
10.2M
    while( line_string_segment_index < line_string_segment_size )
1716
10.2M
    {
1717
10.2M
      if( ( line_string_segment[ line_string_segment_index ] == '\t' )
1718
10.2M
       || ( line_string_segment[ line_string_segment_index ] == '\n' )
1719
10.2M
       || ( line_string_segment[ line_string_segment_index ] == '\f' )
1720
10.2M
       || ( line_string_segment[ line_string_segment_index ] == '\v' )
1721
10.1M
       || ( line_string_segment[ line_string_segment_index ] == '\r' )
1722
10.1M
       || ( line_string_segment[ line_string_segment_index ] == ' ' )
1723
10.1M
       || ( line_string_segment[ line_string_segment_index ] == '=' ) )
1724
114k
      {
1725
114k
        break;
1726
114k
      }
1727
10.0M
      value_identifier_length++;
1728
1729
10.0M
      line_string_segment_index++;
1730
10.0M
    }
1731
    /* Skip a line not containing a value
1732
     */
1733
162k
    if( ( line_string_segment_index >= line_string_segment_size )
1734
114k
     || ( line_string_segment[ line_string_segment_index ] == 0 ) )
1735
48.3k
    {
1736
48.3k
      *line_index += 1;
1737
1738
48.3k
      continue;
1739
48.3k
    }
1740
    /* Make sure the value identifier is terminated by an end of string
1741
     */
1742
114k
    line_string_segment[ line_string_segment_index ] = 0;
1743
1744
114k
    line_string_segment_index++;
1745
1746
    /* Ignore whitespace
1747
     */
1748
184k
    while( line_string_segment_index < line_string_segment_size )
1749
149k
    {
1750
149k
      if( ( line_string_segment[ line_string_segment_index ] != '\t' )
1751
132k
       && ( line_string_segment[ line_string_segment_index ] != '\n' )
1752
128k
       && ( line_string_segment[ line_string_segment_index ] != '\f' )
1753
110k
       && ( line_string_segment[ line_string_segment_index ] != '\v' )
1754
101k
       && ( line_string_segment[ line_string_segment_index ] != '\r' )
1755
97.1k
       && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
1756
78.2k
      {
1757
78.2k
        break;
1758
78.2k
      }
1759
70.7k
      line_string_segment_index++;
1760
70.7k
    }
1761
114k
    if( line_string_segment[ line_string_segment_index ] == '=' )
1762
20.3k
    {
1763
20.3k
      line_string_segment_index++;
1764
1765
46.2k
      while( line_string_segment_index < line_string_segment_size )
1766
43.7k
      {
1767
43.7k
        if( ( line_string_segment[ line_string_segment_index ] != '\t' )
1768
41.5k
         && ( line_string_segment[ line_string_segment_index ] != '\n' )
1769
40.6k
         && ( line_string_segment[ line_string_segment_index ] != '\f' )
1770
38.3k
         && ( line_string_segment[ line_string_segment_index ] != '\v' )
1771
36.0k
         && ( line_string_segment[ line_string_segment_index ] != '\r' )
1772
35.0k
         && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
1773
17.8k
        {
1774
17.8k
          break;
1775
17.8k
        }
1776
25.9k
        line_string_segment_index++;
1777
25.9k
      }
1778
20.3k
    }
1779
    /* Skip a line not containing a value
1780
     */
1781
114k
    if( ( line_string_segment_index >= line_string_segment_size )
1782
75.7k
     || ( line_string_segment[ line_string_segment_index ] == 0 ) )
1783
42.3k
    {
1784
42.3k
      *line_index += 1;
1785
1786
42.3k
      continue;
1787
42.3k
    }
1788
    /* Determine the value
1789
     */
1790
71.9k
    value        = &( line_string_segment[ line_string_segment_index ] );
1791
71.9k
    value_length = line_string_segment_size - 1;
1792
1793
    /* Ingore quotes at the beginning of the value data
1794
     */
1795
71.9k
    if( ( line_string_segment[ line_string_segment_index ] == '"' )
1796
63.8k
     || ( line_string_segment[ line_string_segment_index ] == '\'' ) )
1797
11.2k
    {
1798
11.2k
      line_string_segment_index++;
1799
11.2k
      value++;
1800
11.2k
      value_length--;
1801
11.2k
    }
1802
    /* Ingore quotes at the end of the value data
1803
     */
1804
71.9k
    if( ( line_string_segment[ value_length - 1 ] == '"' )
1805
67.1k
     || ( line_string_segment[ value_length - 1 ] == '\'' ) )
1806
6.64k
    {
1807
6.64k
      value_length--;
1808
6.64k
    }
1809
    /* Make sure the value is terminated by an end of string
1810
     */
1811
71.9k
    line_string_segment[ value_length ] = 0;
1812
1813
71.9k
    value_length -= line_string_segment_index;
1814
1815
71.9k
    if( value_identifier_length == 2 )
1816
13.2k
    {
1817
13.2k
      if( narrow_string_compare(
1818
13.2k
           value_identifier,
1819
13.2k
           "id",
1820
13.2k
           2 ) == 0 )
1821
1.60k
      {
1822
1.60k
        if( libvslvm_physical_volume_set_identifier(
1823
1.60k
             physical_volume,
1824
1.60k
             value,
1825
1.60k
             value_length + 1,
1826
1.60k
             error ) != 1 )
1827
89
        {
1828
89
          libcerror_error_set(
1829
89
           error,
1830
89
           LIBCERROR_ERROR_DOMAIN_RUNTIME,
1831
89
           LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1832
89
           "%s: unable to set physical volume identifier.",
1833
89
           function );
1834
1835
89
          goto on_error;
1836
89
        }
1837
#if defined( HAVE_DEBUG_OUTPUT )
1838
        if( libcnotify_verbose != 0 )
1839
        {
1840
          libcnotify_printf(
1841
           "%s: identifier\t\t\t: %s\n",
1842
           function,
1843
           ( (libvslvm_internal_physical_volume_t *) physical_volume )->identifier );
1844
        }
1845
#endif
1846
1.60k
      }
1847
13.2k
    }
1848
58.6k
    else if( value_identifier_length == 5 )
1849
4.96k
    {
1850
4.96k
      if( narrow_string_compare(
1851
4.96k
           value_identifier,
1852
4.96k
           "flags",
1853
4.96k
           5 ) == 0 )
1854
1.36k
      {
1855
#if defined( HAVE_DEBUG_OUTPUT )
1856
        if( libcnotify_verbose != 0 )
1857
        {
1858
          libcnotify_printf(
1859
           "%s: flags\t\t\t\t: %s\n",
1860
           function,
1861
           value );
1862
        }
1863
#endif
1864
/* TODO */
1865
1.36k
      }
1866
4.96k
    }
1867
53.6k
    else if( value_identifier_length == 6 )
1868
6.82k
    {
1869
6.82k
      if( narrow_string_compare(
1870
6.82k
           value_identifier,
1871
6.82k
           "device",
1872
6.82k
           6 ) == 0 )
1873
1.89k
      {
1874
1.89k
        if( libvslvm_physical_volume_set_device_path(
1875
1.89k
             physical_volume,
1876
1.89k
             value,
1877
1.89k
             value_length + 1,
1878
1.89k
             error ) != 1 )
1879
4
        {
1880
4
          libcerror_error_set(
1881
4
           error,
1882
4
           LIBCERROR_ERROR_DOMAIN_RUNTIME,
1883
4
           LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1884
4
           "%s: unable to set physical volume device path.",
1885
4
           function );
1886
1887
4
          goto on_error;
1888
4
        }
1889
#if defined( HAVE_DEBUG_OUTPUT )
1890
        if( libcnotify_verbose != 0 )
1891
        {
1892
          libcnotify_printf(
1893
           "%s: device path\t\t\t: %s\n",
1894
           function,
1895
           ( (libvslvm_internal_physical_volume_t *) physical_volume )->device_path );
1896
        }
1897
#endif
1898
1.89k
      }
1899
4.93k
      else if( narrow_string_compare(
1900
4.93k
                value_identifier,
1901
4.93k
                "status",
1902
4.93k
                6 ) == 0 )
1903
1.10k
      {
1904
#if defined( HAVE_DEBUG_OUTPUT )
1905
        if( libcnotify_verbose != 0 )
1906
        {
1907
          libcnotify_printf(
1908
           "%s: status flags\t\t\t: %s\n",
1909
           function,
1910
           value );
1911
        }
1912
#endif
1913
/* TODO */
1914
1.10k
      }
1915
1916
6.82k
    }
1917
46.8k
    else if( value_identifier_length == 8 )
1918
5.36k
    {
1919
5.36k
      if( narrow_string_compare(
1920
5.36k
           value_identifier,
1921
5.36k
           "dev_size",
1922
5.36k
           8 ) == 0 )
1923
1.24k
      {
1924
#if defined( HAVE_DEBUG_OUTPUT )
1925
        if( libcnotify_verbose != 0 )
1926
        {
1927
          libcnotify_printf(
1928
           "%s: volume size\t\t\t: %s\n",
1929
           function,
1930
           value );
1931
        }
1932
#endif
1933
1.24k
        if( libfvalue_utf8_string_copy_to_integer(
1934
1.24k
             (uint8_t *) value,
1935
1.24k
             value_length + 1,
1936
1.24k
             &value_64bit,
1937
1.24k
             64,
1938
1.24k
             LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED,
1939
1.24k
             error ) != 1 )
1940
20
        {
1941
20
          libcerror_error_set(
1942
20
           error,
1943
20
           LIBCERROR_ERROR_DOMAIN_MEMORY,
1944
20
           LIBCERROR_MEMORY_ERROR_SET_FAILED,
1945
20
           "%s: unable to set volume size.",
1946
20
           function );
1947
1948
20
          goto on_error;
1949
20
        }
1950
1.22k
        if( value_64bit > (uint64_t) ( UINT64_MAX / 512 ) )
1951
56
        {
1952
56
          libcerror_error_set(
1953
56
           error,
1954
56
           LIBCERROR_ERROR_DOMAIN_RUNTIME,
1955
56
           LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
1956
56
           "%s: invalid volume size value exceeds maximum.",
1957
56
           function );
1958
1959
56
          goto on_error;
1960
56
        }
1961
1.16k
        value_64bit *= 512;
1962
1963
1.16k
        ( (libvslvm_internal_physical_volume_t *) physical_volume )->size = value_64bit;
1964
1.16k
      }
1965
4.12k
      else if( narrow_string_compare(
1966
4.12k
                value_identifier,
1967
4.12k
                "pe_count",
1968
4.12k
                8 ) == 0 )
1969
652
      {
1970
#if defined( HAVE_DEBUG_OUTPUT )
1971
        if( libcnotify_verbose != 0 )
1972
        {
1973
          libcnotify_printf(
1974
           "%s: pe_count\t\t\t: %s\n",
1975
           function,
1976
           value );
1977
        }
1978
#endif
1979
/* TODO */
1980
652
      }
1981
3.47k
      else if( narrow_string_compare(
1982
3.47k
                value_identifier,
1983
3.47k
                "pe_start",
1984
3.47k
                8 ) == 0 )
1985
551
      {
1986
#if defined( HAVE_DEBUG_OUTPUT )
1987
        if( libcnotify_verbose != 0 )
1988
        {
1989
          libcnotify_printf(
1990
           "%s: pe_start\t\t\t: %s\n",
1991
           function,
1992
           value );
1993
        }
1994
#endif
1995
/* TODO */
1996
551
      }
1997
5.36k
    }
1998
#if defined( HAVE_DEBUG_OUTPUT )
1999
    else if( libcnotify_verbose != 0 )
2000
    {
2001
      libcnotify_printf(
2002
       "%s: value: %d\t\t\t: %s = %s\n",
2003
       function,
2004
       *line_index,
2005
       value_identifier,
2006
       value );
2007
    }
2008
#endif
2009
71.7k
    *line_index += 1;
2010
71.7k
  }
2011
57.4k
  if( libvslvm_volume_group_append_physical_volume(
2012
57.4k
       volume_group,
2013
57.4k
       physical_volume,
2014
57.4k
       error ) != 1 )
2015
0
  {
2016
0
    libcerror_error_set(
2017
0
     error,
2018
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2019
0
     LIBCERROR_RUNTIME_ERROR_APPEND_FAILED,
2020
0
     "%s: unable to append physical volume to volume group.",
2021
0
     function );
2022
2023
0
    goto on_error;
2024
0
  }
2025
57.4k
  physical_volume = NULL;
2026
2027
57.4k
  return( 1 );
2028
2029
179
on_error:
2030
179
  if( physical_volume != NULL )
2031
179
  {
2032
179
    libvslvm_internal_physical_volume_free(
2033
179
     (libvslvm_internal_physical_volume_t **) &physical_volume,
2034
179
     NULL );
2035
179
  }
2036
179
  return( -1 );
2037
57.4k
}
2038
2039
/* Reads the logical volumes
2040
 * Returns the 1 if successful or -1 on error
2041
 */
2042
int libvslvm_metadata_read_logical_volumes(
2043
     libvslvm_metadata_t *metadata,
2044
     libvslvm_volume_group_t *volume_group,
2045
     libcsplit_narrow_split_string_t *lines,
2046
     int number_of_lines,
2047
     int *line_index,
2048
     libcerror_error_t **error )
2049
5.89k
{
2050
5.89k
  char *line_string_segment        = NULL;
2051
5.89k
  static char *function            = "libvslvm_metadata_read_logical_volumes";
2052
5.89k
  size_t line_string_segment_index = 0;
2053
5.89k
  size_t line_string_segment_size  = 0;
2054
2055
5.89k
  if( metadata == NULL )
2056
0
  {
2057
0
    libcerror_error_set(
2058
0
     error,
2059
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2060
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2061
0
     "%s: invalid metadata.",
2062
0
     function );
2063
2064
0
    return( -1 );
2065
0
  }
2066
5.89k
  if( line_index == NULL )
2067
0
  {
2068
0
    libcerror_error_set(
2069
0
     error,
2070
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2071
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2072
0
     "%s: invalid line index.",
2073
0
     function );
2074
2075
0
    return( -1 );
2076
0
  }
2077
5.89k
  if( number_of_lines <= 0 )
2078
0
  {
2079
0
    libcerror_error_set(
2080
0
     error,
2081
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2082
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
2083
0
     "%s: invalid number of lines value out of bounds.",
2084
0
     function );
2085
2086
0
    return( -1 );
2087
0
  }
2088
5.89k
  if( ( *line_index < 0 )
2089
5.89k
   || ( *line_index >= number_of_lines ) )
2090
0
  {
2091
0
    libcerror_error_set(
2092
0
     error,
2093
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2094
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
2095
0
     "%s: invalid line index value out of bounds.",
2096
0
     function );
2097
2098
0
    return( -1 );
2099
0
  }
2100
5.89k
  if( libcsplit_narrow_split_string_get_segment_by_index(
2101
5.89k
       lines,
2102
5.89k
       *line_index,
2103
5.89k
       &line_string_segment,
2104
5.89k
       &line_string_segment_size,
2105
5.89k
       error ) != 1 )
2106
0
  {
2107
0
    libcerror_error_set(
2108
0
     error,
2109
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2110
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2111
0
     "%s: unable to retrieve line: %d.",
2112
0
     function,
2113
0
     *line_index );
2114
2115
0
    return( -1 );
2116
0
  }
2117
5.89k
  if( line_string_segment == NULL )
2118
0
  {
2119
0
    libcerror_error_set(
2120
0
     error,
2121
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2122
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2123
0
     "%s: missing line string segment: %d.",
2124
0
     function,
2125
0
     *line_index );
2126
2127
0
    return( -1 );
2128
0
  }
2129
  /* Ignore trailing white space
2130
   */
2131
5.89k
  if( line_string_segment_size >= 2 )
2132
5.89k
  {
2133
5.89k
    line_string_segment_index = line_string_segment_size - 2;
2134
2135
23.7k
    while( line_string_segment_index > 0 )
2136
23.7k
    {
2137
23.7k
      if( ( line_string_segment[ line_string_segment_index ] != '\t' )
2138
22.0k
       && ( line_string_segment[ line_string_segment_index ] != '\n' )
2139
22.0k
       && ( line_string_segment[ line_string_segment_index ] != '\f' )
2140
19.9k
       && ( line_string_segment[ line_string_segment_index ] != '\v' )
2141
16.6k
       && ( line_string_segment[ line_string_segment_index ] != '\r' )
2142
15.7k
       && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
2143
5.89k
      {
2144
5.89k
        break;
2145
5.89k
      }
2146
17.8k
      line_string_segment_index--;
2147
17.8k
      line_string_segment_size--;
2148
17.8k
    }
2149
5.89k
  }
2150
  /* Ignore leading white space
2151
   */
2152
5.89k
  line_string_segment_index = 0;
2153
2154
1.18M
  while( line_string_segment_index < line_string_segment_size )
2155
1.18M
  {
2156
1.18M
    if( ( line_string_segment[ line_string_segment_index ] != '\t' )
2157
1.18M
     && ( line_string_segment[ line_string_segment_index ] != '\n' )
2158
1.18M
     && ( line_string_segment[ line_string_segment_index ] != '\f' )
2159
1.17M
     && ( line_string_segment[ line_string_segment_index ] != '\v' )
2160
1.17M
     && ( line_string_segment[ line_string_segment_index ] != '\r' )
2161
1.16M
     && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
2162
5.89k
    {
2163
5.89k
      break;
2164
5.89k
    }
2165
1.17M
    line_string_segment_index++;
2166
1.17M
  }
2167
5.89k
  if( ( ( line_string_segment_size - line_string_segment_index ) != 18 )
2168
5.89k
   || ( narrow_string_compare(
2169
5.89k
         &( line_string_segment[ line_string_segment_index ] ),
2170
5.89k
         "logical_volumes {",
2171
5.89k
         17 ) != 0 ) )
2172
0
  {
2173
0
    libcerror_error_set(
2174
0
     error,
2175
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2176
0
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
2177
0
     "%s: unsupported logical volumes signature.",
2178
0
     function );
2179
2180
0
    return( -1 );
2181
0
  }
2182
5.89k
  *line_index += 1;
2183
2184
1.58M
  while( *line_index < number_of_lines )
2185
1.58M
  {
2186
1.58M
    if( libcsplit_narrow_split_string_get_segment_by_index(
2187
1.58M
         lines,
2188
1.58M
         *line_index,
2189
1.58M
         &line_string_segment,
2190
1.58M
         &line_string_segment_size,
2191
1.58M
         error ) != 1 )
2192
0
    {
2193
0
      libcerror_error_set(
2194
0
       error,
2195
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
2196
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2197
0
       "%s: unable to retrieve line: %d.",
2198
0
       function,
2199
0
       *line_index );
2200
2201
0
      return( -1 );
2202
0
    }
2203
1.58M
    if( line_string_segment == NULL )
2204
0
    {
2205
0
      libcerror_error_set(
2206
0
       error,
2207
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
2208
0
       LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2209
0
       "%s: missing line string segment: %d.",
2210
0
       function,
2211
0
       *line_index );
2212
2213
0
      return( -1 );
2214
0
    }
2215
    /* Ignore trailing white space
2216
     */
2217
1.58M
    if( line_string_segment_size >= 2 )
2218
85.9k
    {
2219
85.9k
      line_string_segment_index = line_string_segment_size - 2;
2220
2221
233k
      while( line_string_segment_index > 0 )
2222
214k
      {
2223
214k
        if( ( line_string_segment[ line_string_segment_index ] != '\t' )
2224
198k
         && ( line_string_segment[ line_string_segment_index ] != '\n' )
2225
188k
         && ( line_string_segment[ line_string_segment_index ] != '\f' )
2226
175k
         && ( line_string_segment[ line_string_segment_index ] != '\v' )
2227
107k
         && ( line_string_segment[ line_string_segment_index ] != '\r' )
2228
101k
         && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
2229
67.0k
        {
2230
67.0k
          break;
2231
67.0k
        }
2232
147k
        line_string_segment_index--;
2233
147k
        line_string_segment_size--;
2234
147k
      }
2235
85.9k
    }
2236
    /* Ignore leading white space
2237
     */
2238
1.58M
    line_string_segment_index = 0;
2239
2240
1.67M
    while( line_string_segment_index < line_string_segment_size )
2241
1.67M
    {
2242
1.67M
      if( ( line_string_segment[ line_string_segment_index ] != '\t' )
2243
1.65M
       && ( line_string_segment[ line_string_segment_index ] != '\n' )
2244
1.65M
       && ( line_string_segment[ line_string_segment_index ] != '\f' )
2245
1.64M
       && ( line_string_segment[ line_string_segment_index ] != '\v' )
2246
1.61M
       && ( line_string_segment[ line_string_segment_index ] != '\r' )
2247
1.60M
       && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
2248
1.58M
      {
2249
1.58M
        break;
2250
1.58M
      }
2251
89.1k
      line_string_segment_index++;
2252
89.1k
    }
2253
    /* Skip an empty line
2254
     */
2255
1.58M
    if( ( line_string_segment_index >= line_string_segment_size )
2256
1.58M
     || ( line_string_segment[ line_string_segment_index ] == 0 ) )
2257
1.50M
    {
2258
1.50M
      *line_index += 1;
2259
2260
1.50M
      continue;
2261
1.50M
    }
2262
    /* Check for the end of section
2263
     */
2264
81.2k
    if( ( ( line_string_segment_size - line_string_segment_index ) == 2 )
2265
17.5k
     && ( line_string_segment[ line_string_segment_index ] == '}' ) )
2266
2.11k
    {
2267
2.11k
      *line_index += 1;
2268
2269
2.11k
      break;
2270
2.11k
    }
2271
    /* Check for the start of a sub section
2272
     */
2273
79.1k
    if( ( line_string_segment_size >= 3 )
2274
66.8k
     && ( line_string_segment[ line_string_segment_size - 3 ] == ' ' )
2275
41.7k
     && ( line_string_segment[ line_string_segment_size - 2 ] == '{' ) )
2276
31.8k
    {
2277
31.8k
      if( libvslvm_metadata_read_logical_volume(
2278
31.8k
           metadata,
2279
31.8k
           volume_group,
2280
31.8k
           lines,
2281
31.8k
           number_of_lines,
2282
31.8k
           line_index,
2283
31.8k
           error ) != 1 )
2284
822
      {
2285
822
        libcerror_error_set(
2286
822
         error,
2287
822
         LIBCERROR_ERROR_DOMAIN_IO,
2288
822
         LIBCERROR_IO_ERROR_READ_FAILED,
2289
822
         "%s: unable to read logical volume.",
2290
822
         function );
2291
2292
822
        return( -1 );
2293
822
      }
2294
31.8k
    }
2295
47.2k
    else
2296
47.2k
    {
2297
/* TODO debug print other lines ? */
2298
47.2k
      *line_index += 1;
2299
47.2k
    }
2300
79.1k
  }
2301
5.06k
  return( 1 );
2302
5.89k
}
2303
2304
/* Reads the logical volume
2305
 * Returns the 1 if successful or -1 on error
2306
 */
2307
int libvslvm_metadata_read_logical_volume(
2308
     libvslvm_metadata_t *metadata,
2309
     libvslvm_volume_group_t *volume_group,
2310
     libcsplit_narrow_split_string_t *lines,
2311
     int number_of_lines,
2312
     int *line_index,
2313
     libcerror_error_t **error )
2314
31.8k
{
2315
31.8k
  libvslvm_logical_volume_values_t *logical_volume_values = NULL;
2316
31.8k
  char *line_string_segment                               = NULL;
2317
31.8k
  char *value                                             = NULL;
2318
31.8k
  char *value_identifier                                  = NULL;
2319
31.8k
  static char *function                                   = "libvslvm_metadata_read_logical_volume";
2320
31.8k
  size_t line_string_segment_index                        = 0;
2321
31.8k
  size_t line_string_segment_size                         = 0;
2322
31.8k
  size_t value_identifier_length                          = 0;
2323
31.8k
  size_t value_length                                     = 0;
2324
2325
31.8k
  if( metadata == NULL )
2326
0
  {
2327
0
    libcerror_error_set(
2328
0
     error,
2329
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2330
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2331
0
     "%s: invalid metadata.",
2332
0
     function );
2333
2334
0
    return( -1 );
2335
0
  }
2336
31.8k
  if( volume_group == NULL )
2337
0
  {
2338
0
    libcerror_error_set(
2339
0
     error,
2340
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2341
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2342
0
     "%s: invalid volume group.",
2343
0
     function );
2344
2345
0
    return( -1 );
2346
0
  }
2347
31.8k
  if( line_index == NULL )
2348
0
  {
2349
0
    libcerror_error_set(
2350
0
     error,
2351
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2352
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2353
0
     "%s: invalid line index.",
2354
0
     function );
2355
2356
0
    return( -1 );
2357
0
  }
2358
31.8k
  if( number_of_lines <= 0 )
2359
0
  {
2360
0
    libcerror_error_set(
2361
0
     error,
2362
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2363
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
2364
0
     "%s: invalid number of lines value out of bounds.",
2365
0
     function );
2366
2367
0
    return( -1 );
2368
0
  }
2369
31.8k
  if( ( *line_index < 0 )
2370
31.8k
   || ( *line_index >= number_of_lines ) )
2371
0
  {
2372
0
    libcerror_error_set(
2373
0
     error,
2374
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2375
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
2376
0
     "%s: invalid line index value out of bounds.",
2377
0
     function );
2378
2379
0
    return( -1 );
2380
0
  }
2381
31.8k
  if( libcsplit_narrow_split_string_get_segment_by_index(
2382
31.8k
       lines,
2383
31.8k
       *line_index,
2384
31.8k
       &line_string_segment,
2385
31.8k
       &line_string_segment_size,
2386
31.8k
       error ) != 1 )
2387
0
  {
2388
0
    libcerror_error_set(
2389
0
     error,
2390
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2391
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2392
0
     "%s: unable to retrieve line: %d.",
2393
0
     function,
2394
0
     *line_index );
2395
2396
0
    goto on_error;
2397
0
  }
2398
31.8k
  if( line_string_segment == NULL )
2399
0
  {
2400
0
    libcerror_error_set(
2401
0
     error,
2402
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2403
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2404
0
     "%s: missing line string segment: %d.",
2405
0
     function,
2406
0
     *line_index );
2407
2408
0
    goto on_error;
2409
0
  }
2410
  /* Ignore trailing white space
2411
   */
2412
31.8k
  if( line_string_segment_size >= 2 )
2413
31.8k
  {
2414
31.8k
    line_string_segment_index = line_string_segment_size - 2;
2415
2416
92.0k
    while( line_string_segment_index > 0 )
2417
92.0k
    {
2418
92.0k
      if( ( line_string_segment[ line_string_segment_index ] != '\t' )
2419
90.2k
       && ( line_string_segment[ line_string_segment_index ] != '\n' )
2420
83.6k
       && ( line_string_segment[ line_string_segment_index ] != '\f' )
2421
80.0k
       && ( line_string_segment[ line_string_segment_index ] != '\v' )
2422
36.7k
       && ( line_string_segment[ line_string_segment_index ] != '\r' )
2423
34.9k
       && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
2424
31.8k
      {
2425
31.8k
        break;
2426
31.8k
      }
2427
60.1k
      line_string_segment_index--;
2428
60.1k
      line_string_segment_size--;
2429
60.1k
    }
2430
31.8k
  }
2431
  /* Ignore leading white space
2432
   */
2433
31.8k
  line_string_segment_index = 0;
2434
2435
79.2k
  while( line_string_segment_index < line_string_segment_size )
2436
79.2k
  {
2437
79.2k
    if( ( line_string_segment[ line_string_segment_index ] != '\t' )
2438
68.4k
     && ( line_string_segment[ line_string_segment_index ] != '\n' )
2439
68.4k
     && ( line_string_segment[ line_string_segment_index ] != '\f' )
2440
65.6k
     && ( line_string_segment[ line_string_segment_index ] != '\v' )
2441
44.5k
     && ( line_string_segment[ line_string_segment_index ] != '\r' )
2442
37.5k
     && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
2443
31.8k
    {
2444
31.8k
      break;
2445
31.8k
    }
2446
47.3k
    line_string_segment_index++;
2447
47.3k
  }
2448
31.8k
  if( ( line_string_segment_size < 3 )
2449
31.8k
   || ( line_string_segment[ line_string_segment_size - 3 ] != ' ' )
2450
31.8k
   || ( line_string_segment[ line_string_segment_size - 2 ] != '{' ) )
2451
0
  {
2452
0
    libcerror_error_set(
2453
0
     error,
2454
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2455
0
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
2456
0
     "%s: unsupported logical volume signature.",
2457
0
     function );
2458
2459
0
    goto on_error;
2460
0
  }
2461
31.8k
  if( libvslvm_logical_volume_values_initialize(
2462
31.8k
       &logical_volume_values,
2463
31.8k
       error ) != 1 )
2464
0
  {
2465
0
    libcerror_error_set(
2466
0
     error,
2467
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2468
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
2469
0
     "%s: unable to create logical volume values.",
2470
0
     function );
2471
2472
0
    goto on_error;
2473
0
  }
2474
31.8k
  if( ( line_string_segment_size < 2 )
2475
31.8k
   || ( line_string_segment_index >= ( line_string_segment_size - 2 ) ) )
2476
7
  {
2477
7
    libcerror_error_set(
2478
7
     error,
2479
7
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2480
7
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
2481
7
     "%s: invalid line string segment size value out of bounds.",
2482
7
     function );
2483
2484
7
    goto on_error;
2485
7
  }
2486
31.8k
  if( libvslvm_logical_volume_values_set_name(
2487
31.8k
       logical_volume_values,
2488
31.8k
       &( line_string_segment[ line_string_segment_index ] ),
2489
31.8k
       line_string_segment_size - ( line_string_segment_index + 2 ),
2490
31.8k
       error ) != 1 )
2491
0
  {
2492
0
    libcerror_error_set(
2493
0
     error,
2494
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2495
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
2496
0
     "%s: unable to set logical volume name.",
2497
0
     function );
2498
2499
0
    goto on_error;
2500
0
  }
2501
#if defined( HAVE_DEBUG_OUTPUT )
2502
  if( libcnotify_verbose != 0 )
2503
  {
2504
    libcnotify_printf(
2505
     "\n" );
2506
2507
    libcnotify_printf(
2508
     "%s: name\t\t\t\t: %s\n",
2509
     function,
2510
     logical_volume_values->name );
2511
  }
2512
#endif
2513
31.8k
  *line_index += 1;
2514
2515
10.0M
  while( *line_index < number_of_lines )
2516
10.0M
  {
2517
10.0M
    if( libcsplit_narrow_split_string_get_segment_by_index(
2518
10.0M
         lines,
2519
10.0M
         *line_index,
2520
10.0M
         &line_string_segment,
2521
10.0M
         &line_string_segment_size,
2522
10.0M
         error ) != 1 )
2523
0
    {
2524
0
      libcerror_error_set(
2525
0
       error,
2526
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
2527
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2528
0
       "%s: unable to retrieve line: %d.",
2529
0
       function,
2530
0
       *line_index );
2531
2532
0
      goto on_error;
2533
0
    }
2534
10.0M
    if( line_string_segment == NULL )
2535
0
    {
2536
0
      libcerror_error_set(
2537
0
       error,
2538
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
2539
0
       LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2540
0
       "%s: missing line string segment: %d.",
2541
0
       function,
2542
0
       *line_index );
2543
2544
0
      goto on_error;
2545
0
    }
2546
    /* Ignore trailing white space
2547
     */
2548
10.0M
    if( line_string_segment_size >= 2 )
2549
232k
    {
2550
232k
      line_string_segment_index = line_string_segment_size - 2;
2551
2552
656k
      while( line_string_segment_index > 0 )
2553
581k
      {
2554
581k
        if( ( line_string_segment[ line_string_segment_index ] != '\t' )
2555
561k
         && ( line_string_segment[ line_string_segment_index ] != '\n' )
2556
533k
         && ( line_string_segment[ line_string_segment_index ] != '\f' )
2557
500k
         && ( line_string_segment[ line_string_segment_index ] != '\v' )
2558
435k
         && ( line_string_segment[ line_string_segment_index ] != '\r' )
2559
402k
         && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
2560
157k
        {
2561
157k
          break;
2562
157k
        }
2563
424k
        line_string_segment_index--;
2564
424k
        line_string_segment_size--;
2565
424k
      }
2566
232k
    }
2567
    /* Ignore leading white space
2568
     */
2569
10.0M
    line_string_segment_index = 0;
2570
2571
10.3M
    while( line_string_segment_index < line_string_segment_size )
2572
10.3M
    {
2573
10.3M
      if( ( line_string_segment[ line_string_segment_index ] != '\t' )
2574
10.3M
       && ( line_string_segment[ line_string_segment_index ] != '\n' )
2575
10.3M
       && ( line_string_segment[ line_string_segment_index ] != '\f' )
2576
10.3M
       && ( line_string_segment[ line_string_segment_index ] != '\v' )
2577
10.1M
       && ( line_string_segment[ line_string_segment_index ] != '\r' )
2578
10.1M
       && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
2579
10.0M
      {
2580
10.0M
        break;
2581
10.0M
      }
2582
313k
      line_string_segment_index++;
2583
313k
    }
2584
    /* Skip an empty line
2585
     */
2586
10.0M
    if( ( line_string_segment_index >= line_string_segment_size )
2587
10.0M
     || ( line_string_segment[ line_string_segment_index ] == 0 ) )
2588
9.83M
    {
2589
9.83M
      *line_index += 1;
2590
2591
9.83M
      continue;
2592
9.83M
    }
2593
    /* Check for the end of section
2594
     */
2595
209k
    if( ( ( line_string_segment_size - line_string_segment_index ) == 2 )
2596
87.1k
     && ( line_string_segment[ line_string_segment_index ] == '}' ) )
2597
28.3k
    {
2598
28.3k
      *line_index += 1;
2599
2600
28.3k
      break;
2601
28.3k
    }
2602
    /* Check for the start of a sub section
2603
     */
2604
180k
    if( ( line_string_segment_size >= 3 )
2605
133k
     && ( line_string_segment[ line_string_segment_size - 3 ] == ' ' )
2606
54.2k
     && ( line_string_segment[ line_string_segment_size - 2 ] == '{' )
2607
23.5k
     && ( ( line_string_segment_size - line_string_segment_index ) >= 7 )
2608
17.9k
     && ( narrow_string_compare(
2609
17.9k
           &( line_string_segment[ line_string_segment_index ] ),
2610
17.9k
           "segment",
2611
17.9k
           7 ) == 0 ) )
2612
3.70k
    {
2613
3.70k
      if( libvslvm_metadata_read_segment(
2614
3.70k
           metadata,
2615
3.70k
           logical_volume_values,
2616
3.70k
           lines,
2617
3.70k
           number_of_lines,
2618
3.70k
           line_index,
2619
3.70k
           error ) != 1 )
2620
732
      {
2621
732
        libcerror_error_set(
2622
732
         error,
2623
732
         LIBCERROR_ERROR_DOMAIN_IO,
2624
732
         LIBCERROR_IO_ERROR_READ_FAILED,
2625
732
         "%s: unable to read segment.",
2626
732
         function );
2627
2628
732
        goto on_error;
2629
732
      }
2630
2.97k
      continue;
2631
3.70k
    }
2632
    /* Determine the value identifier
2633
     */
2634
177k
    value_identifier        = &( line_string_segment[ line_string_segment_index ] );
2635
177k
    value_identifier_length = 0;
2636
2637
8.52M
    while( line_string_segment_index < line_string_segment_size )
2638
8.46M
    {
2639
8.46M
      if( ( line_string_segment[ line_string_segment_index ] == '\t' )
2640
8.46M
       || ( line_string_segment[ line_string_segment_index ] == '\n' )
2641
8.46M
       || ( line_string_segment[ line_string_segment_index ] == '\f' )
2642
8.45M
       || ( line_string_segment[ line_string_segment_index ] == '\v' )
2643
8.44M
       || ( line_string_segment[ line_string_segment_index ] == '\r' )
2644
8.43M
       || ( line_string_segment[ line_string_segment_index ] == ' ' )
2645
8.35M
       || ( line_string_segment[ line_string_segment_index ] == '=' ) )
2646
121k
      {
2647
121k
        break;
2648
121k
      }
2649
8.34M
      value_identifier_length++;
2650
2651
8.34M
      line_string_segment_index++;
2652
8.34M
    }
2653
    /* Skip a line not containing a value
2654
     */
2655
177k
    if( ( line_string_segment_index >= line_string_segment_size )
2656
121k
     || ( line_string_segment[ line_string_segment_index ] == 0 ) )
2657
55.4k
    {
2658
55.4k
      *line_index += 1;
2659
2660
55.4k
      continue;
2661
55.4k
    }
2662
    /* Make sure the value identifier is terminated by an end of string
2663
     */
2664
121k
    line_string_segment[ line_string_segment_index ] = 0;
2665
2666
121k
    line_string_segment_index++;
2667
2668
    /* Ignore whitespace
2669
     */
2670
250k
    while( line_string_segment_index < line_string_segment_size )
2671
207k
    {
2672
207k
      if( ( line_string_segment[ line_string_segment_index ] != '\t' )
2673
189k
       && ( line_string_segment[ line_string_segment_index ] != '\n' )
2674
183k
       && ( line_string_segment[ line_string_segment_index ] != '\f' )
2675
170k
       && ( line_string_segment[ line_string_segment_index ] != '\v' )
2676
163k
       && ( line_string_segment[ line_string_segment_index ] != '\r' )
2677
152k
       && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
2678
78.3k
      {
2679
78.3k
        break;
2680
78.3k
      }
2681
129k
      line_string_segment_index++;
2682
129k
    }
2683
121k
    if( line_string_segment[ line_string_segment_index ] == '=' )
2684
20.3k
    {
2685
20.3k
      line_string_segment_index++;
2686
2687
52.3k
      while( line_string_segment_index < line_string_segment_size )
2688
50.2k
      {
2689
50.2k
        if( ( line_string_segment[ line_string_segment_index ] != '\t' )
2690
47.9k
         && ( line_string_segment[ line_string_segment_index ] != '\n' )
2691
42.8k
         && ( line_string_segment[ line_string_segment_index ] != '\f' )
2692
41.2k
         && ( line_string_segment[ line_string_segment_index ] != '\v' )
2693
38.5k
         && ( line_string_segment[ line_string_segment_index ] != '\r' )
2694
36.2k
         && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
2695
18.2k
        {
2696
18.2k
          break;
2697
18.2k
        }
2698
31.9k
        line_string_segment_index++;
2699
31.9k
      }
2700
20.3k
    }
2701
    /* Skip a line not containing a value
2702
     */
2703
121k
    if( ( line_string_segment_index >= line_string_segment_size )
2704
76.2k
     || ( line_string_segment[ line_string_segment_index ] == 0 ) )
2705
49.4k
    {
2706
49.4k
      *line_index += 1;
2707
2708
49.4k
      continue;
2709
49.4k
    }
2710
    /* Determine the value
2711
     */
2712
72.2k
    value        = &( line_string_segment[ line_string_segment_index ] );
2713
72.2k
    value_length = line_string_segment_size - 1;
2714
2715
    /* Ingore quotes at the beginning of the value data
2716
     */
2717
72.2k
    if( ( line_string_segment[ line_string_segment_index ] == '"' )
2718
64.7k
     || ( line_string_segment[ line_string_segment_index ] == '\'' ) )
2719
10.1k
    {
2720
10.1k
      line_string_segment_index++;
2721
10.1k
      value++;
2722
10.1k
      value_length--;
2723
10.1k
    }
2724
    /* Ingore quotes at the end of the value data
2725
     */
2726
72.2k
    if( ( line_string_segment[ value_length - 1 ] == '"' )
2727
67.8k
     || ( line_string_segment[ value_length - 1 ] == '\'' ) )
2728
5.77k
    {
2729
5.77k
      value_length--;
2730
5.77k
    }
2731
    /* Make sure the value is terminated by an end of string
2732
     */
2733
72.2k
    line_string_segment[ value_length ] = 0;
2734
2735
72.2k
    value_length -= line_string_segment_index;
2736
2737
72.2k
    if( value_identifier_length == 2 )
2738
14.1k
    {
2739
14.1k
      if( narrow_string_compare(
2740
14.1k
           value_identifier,
2741
14.1k
           "id",
2742
14.1k
           2 ) == 0 )
2743
1.57k
      {
2744
1.57k
        if( libvslvm_logical_volume_values_set_identifier(
2745
1.57k
             logical_volume_values,
2746
1.57k
             value,
2747
1.57k
             value_length + 1,
2748
1.57k
             error ) != 1 )
2749
83
        {
2750
83
          libcerror_error_set(
2751
83
           error,
2752
83
           LIBCERROR_ERROR_DOMAIN_RUNTIME,
2753
83
           LIBCERROR_RUNTIME_ERROR_SET_FAILED,
2754
83
           "%s: unable to set logical volume identifier.",
2755
83
           function );
2756
2757
83
          goto on_error;
2758
83
        }
2759
#if defined( HAVE_DEBUG_OUTPUT )
2760
        if( libcnotify_verbose != 0 )
2761
        {
2762
          libcnotify_printf(
2763
           "%s: identifier\t\t\t: %s\n",
2764
           function,
2765
           logical_volume_values->identifier );
2766
        }
2767
#endif
2768
1.57k
      }
2769
14.1k
    }
2770
58.1k
    else if( value_identifier_length == 5 )
2771
3.83k
    {
2772
3.83k
      if( narrow_string_compare(
2773
3.83k
           value_identifier,
2774
3.83k
           "flags",
2775
3.83k
           5 ) == 0 )
2776
1.35k
      {
2777
#if defined( HAVE_DEBUG_OUTPUT )
2778
        if( libcnotify_verbose != 0 )
2779
        {
2780
          libcnotify_printf(
2781
           "%s: flags\t\t\t\t: %s\n",
2782
           function,
2783
           value );
2784
        }
2785
#endif
2786
/* TODO */
2787
1.35k
      }
2788
3.83k
    }
2789
54.2k
    else if( value_identifier_length == 6 )
2790
5.78k
    {
2791
5.78k
      if( narrow_string_compare(
2792
5.78k
           value_identifier,
2793
5.78k
           "status",
2794
5.78k
           6 ) == 0 )
2795
1.35k
      {
2796
#if defined( HAVE_DEBUG_OUTPUT )
2797
        if( libcnotify_verbose != 0 )
2798
        {
2799
          libcnotify_printf(
2800
           "%s: status flags\t\t\t: %s\n",
2801
           function,
2802
           value );
2803
        }
2804
#endif
2805
/* TODO */
2806
1.35k
      }
2807
2808
5.78k
    }
2809
48.4k
    else if( value_identifier_length == 13 )
2810
3.08k
    {
2811
3.08k
      if( narrow_string_compare(
2812
3.08k
           value_identifier,
2813
3.08k
           "segment_count",
2814
3.08k
           13 ) == 0 )
2815
551
      {
2816
#if defined( HAVE_DEBUG_OUTPUT )
2817
        if( libcnotify_verbose != 0 )
2818
        {
2819
          libcnotify_printf(
2820
           "%s: number of segments\t\t: %s\n",
2821
           function,
2822
           value );
2823
        }
2824
#endif
2825
/* TODO */
2826
551
      }
2827
2828
3.08k
    }
2829
#if defined( HAVE_DEBUG_OUTPUT )
2830
    else if( libcnotify_verbose != 0 )
2831
    {
2832
      libcnotify_printf(
2833
       "%s: value: %d\t\t\t: %s = %s\n",
2834
       function,
2835
       *line_index,
2836
       value_identifier,
2837
       value );
2838
    }
2839
#endif
2840
72.1k
    *line_index += 1;
2841
72.1k
  }
2842
31.0k
  if( libvslvm_volume_group_append_logical_volume(
2843
31.0k
       volume_group,
2844
31.0k
       logical_volume_values,
2845
31.0k
       error ) != 1 )
2846
0
  {
2847
0
    libcerror_error_set(
2848
0
     error,
2849
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2850
0
     LIBCERROR_RUNTIME_ERROR_APPEND_FAILED,
2851
0
     "%s: unable to append logical volume to volume group.",
2852
0
     function );
2853
2854
0
    goto on_error;
2855
0
  }
2856
31.0k
  logical_volume_values = NULL;
2857
2858
31.0k
  return( 1 );
2859
2860
822
on_error:
2861
822
  if( logical_volume_values != NULL )
2862
822
  {
2863
822
    libvslvm_logical_volume_values_free(
2864
822
     &logical_volume_values,
2865
822
     NULL );
2866
822
  }
2867
822
  return( -1 );
2868
31.0k
}
2869
2870
/* Reads the segment
2871
 * Returns the 1 if successful or -1 on error
2872
 */
2873
int libvslvm_metadata_read_segment(
2874
     libvslvm_metadata_t *metadata,
2875
     libvslvm_logical_volume_values_t *logical_volume_values,
2876
     libcsplit_narrow_split_string_t *lines,
2877
     int number_of_lines,
2878
     int *line_index,
2879
     libcerror_error_t **error )
2880
3.70k
{
2881
3.70k
  libvslvm_internal_volume_group_t *internal_volume_group = NULL;
2882
3.70k
  libvslvm_segment_t *segment                             = NULL;
2883
3.70k
  char *line_string_segment                               = NULL;
2884
3.70k
  char *value                                             = NULL;
2885
3.70k
  char *value_identifier                                  = NULL;
2886
3.70k
  static char *function                                   = "libvslvm_metadata_read_segment";
2887
3.70k
  size_t line_string_segment_index                        = 0;
2888
3.70k
  size_t line_string_segment_size                         = 0;
2889
3.70k
  size_t value_identifier_length                          = 0;
2890
3.70k
  size_t value_length                                     = 0;
2891
3.70k
  uint64_t value_64bit                                    = 0;
2892
2893
3.70k
  if( metadata == NULL )
2894
0
  {
2895
0
    libcerror_error_set(
2896
0
     error,
2897
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2898
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2899
0
     "%s: invalid metadata.",
2900
0
     function );
2901
2902
0
    return( -1 );
2903
0
  }
2904
3.70k
  if( metadata->volume_group == NULL )
2905
0
  {
2906
0
    libcerror_error_set(
2907
0
     error,
2908
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2909
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2910
0
     "%s: invalid metadata - missing volume group.",
2911
0
     function );
2912
2913
0
    return( -1 );
2914
0
  }
2915
3.70k
  internal_volume_group = (libvslvm_internal_volume_group_t *) metadata->volume_group;
2916
2917
3.70k
  if( internal_volume_group->extent_size == 0 )
2918
13
  {
2919
13
    libcerror_error_set(
2920
13
     error,
2921
13
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2922
13
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
2923
13
     "%s: invalid volume group - extent size value out of bounds.",
2924
13
     function );
2925
2926
13
    return( -1 );
2927
13
  }
2928
3.69k
  if( logical_volume_values == NULL )
2929
0
  {
2930
0
    libcerror_error_set(
2931
0
     error,
2932
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2933
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2934
0
     "%s: invalid logical volume values.",
2935
0
     function );
2936
2937
0
    return( -1 );
2938
0
  }
2939
3.69k
  if( line_index == NULL )
2940
0
  {
2941
0
    libcerror_error_set(
2942
0
     error,
2943
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2944
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2945
0
     "%s: invalid line index.",
2946
0
     function );
2947
2948
0
    return( -1 );
2949
0
  }
2950
3.69k
  if( number_of_lines <= 0 )
2951
0
  {
2952
0
    libcerror_error_set(
2953
0
     error,
2954
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2955
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
2956
0
     "%s: invalid number of lines value out of bounds.",
2957
0
     function );
2958
2959
0
    return( -1 );
2960
0
  }
2961
3.69k
  if( ( *line_index < 0 )
2962
3.69k
   || ( *line_index >= number_of_lines ) )
2963
0
  {
2964
0
    libcerror_error_set(
2965
0
     error,
2966
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2967
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
2968
0
     "%s: invalid line index value out of bounds.",
2969
0
     function );
2970
2971
0
    return( -1 );
2972
0
  }
2973
3.69k
  if( libcsplit_narrow_split_string_get_segment_by_index(
2974
3.69k
       lines,
2975
3.69k
       *line_index,
2976
3.69k
       &line_string_segment,
2977
3.69k
       &line_string_segment_size,
2978
3.69k
       error ) != 1 )
2979
0
  {
2980
0
    libcerror_error_set(
2981
0
     error,
2982
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2983
0
     LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2984
0
     "%s: unable to retrieve line: %d.",
2985
0
     function,
2986
0
     *line_index );
2987
2988
0
    goto on_error;
2989
0
  }
2990
3.69k
  if( line_string_segment == NULL )
2991
0
  {
2992
0
    libcerror_error_set(
2993
0
     error,
2994
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
2995
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2996
0
     "%s: missing line string segment: %d.",
2997
0
     function,
2998
0
     *line_index );
2999
3000
0
    goto on_error;
3001
0
  }
3002
  /* Ignore trailing white space
3003
   */
3004
3.69k
  if( line_string_segment_size >= 2 )
3005
3.69k
  {
3006
3.69k
    line_string_segment_index = line_string_segment_size - 2;
3007
3008
25.0k
    while( line_string_segment_index > 0 )
3009
25.0k
    {
3010
25.0k
      if( ( line_string_segment[ line_string_segment_index ] != '\t' )
3011
23.4k
       && ( line_string_segment[ line_string_segment_index ] != '\n' )
3012
12.3k
       && ( line_string_segment[ line_string_segment_index ] != '\f' )
3013
10.6k
       && ( line_string_segment[ line_string_segment_index ] != '\v' )
3014
8.14k
       && ( line_string_segment[ line_string_segment_index ] != '\r' )
3015
5.65k
       && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
3016
3.69k
      {
3017
3.69k
        break;
3018
3.69k
      }
3019
21.3k
      line_string_segment_index--;
3020
21.3k
      line_string_segment_size--;
3021
21.3k
    }
3022
3.69k
  }
3023
  /* Ignore leading white space
3024
   */
3025
3.69k
  line_string_segment_index = 0;
3026
3027
60.2k
  while( line_string_segment_index < line_string_segment_size )
3028
60.2k
  {
3029
60.2k
    if( ( line_string_segment[ line_string_segment_index ] != '\t' )
3030
52.9k
     && ( line_string_segment[ line_string_segment_index ] != '\n' )
3031
52.9k
     && ( line_string_segment[ line_string_segment_index ] != '\f' )
3032
47.8k
     && ( line_string_segment[ line_string_segment_index ] != '\v' )
3033
44.2k
     && ( line_string_segment[ line_string_segment_index ] != '\r' )
3034
42.4k
     && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
3035
3.69k
    {
3036
3.69k
      break;
3037
3.69k
    }
3038
56.5k
    line_string_segment_index++;
3039
56.5k
  }
3040
3.69k
  if( ( line_string_segment_size < ( 7 + 3 ) )
3041
3.69k
   || ( line_string_segment[ line_string_segment_size - 3 ] != ' ' )
3042
3.69k
   || ( line_string_segment[ line_string_segment_size - 2 ] != '{' )
3043
3.69k
   || ( narrow_string_compare(
3044
3.69k
         &( line_string_segment[ line_string_segment_index ] ),
3045
3.69k
         "segment",
3046
3.69k
         7 ) != 0 ) )
3047
0
  {
3048
0
    libcerror_error_set(
3049
0
     error,
3050
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
3051
0
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
3052
0
     "%s: unsupported segment signature.",
3053
0
     function );
3054
3055
0
    goto on_error;
3056
0
  }
3057
3.69k
  if( libvslvm_segment_initialize(
3058
3.69k
       &segment,
3059
3.69k
       error ) != 1 )
3060
0
  {
3061
0
    libcerror_error_set(
3062
0
     error,
3063
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
3064
0
     LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
3065
0
     "%s: unable to create segment.",
3066
0
     function );
3067
3068
0
    goto on_error;
3069
0
  }
3070
3.69k
  if( ( line_string_segment_size < 2 )
3071
3.69k
   || ( line_string_segment_index >= ( line_string_segment_size - 2 ) ) )
3072
0
  {
3073
0
    libcerror_error_set(
3074
0
     error,
3075
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3076
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
3077
0
     "%s: invalid line string segment size value out of bounds.",
3078
0
     function );
3079
3080
0
    goto on_error;
3081
0
  }
3082
3.69k
  if( libvslvm_internal_segment_set_name(
3083
3.69k
       (libvslvm_internal_segment_t *) segment,
3084
3.69k
       &( line_string_segment[ line_string_segment_index ] ),
3085
3.69k
       line_string_segment_size - ( line_string_segment_index + 2 ),
3086
3.69k
       error ) != 1 )
3087
0
  {
3088
0
    libcerror_error_set(
3089
0
     error,
3090
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
3091
0
     LIBCERROR_RUNTIME_ERROR_SET_FAILED,
3092
0
     "%s: unable to set segment name.",
3093
0
     function );
3094
3095
0
    goto on_error;
3096
0
  }
3097
#if defined( HAVE_DEBUG_OUTPUT )
3098
  if( libcnotify_verbose != 0 )
3099
  {
3100
    libcnotify_printf(
3101
     "\n" );
3102
3103
    libcnotify_printf(
3104
     "%s: name\t\t\t\t\t: %s\n",
3105
     function,
3106
     ( (libvslvm_internal_segment_t *) segment )->name );
3107
  }
3108
#endif
3109
3.69k
  *line_index += 1;
3110
3111
11.0M
  while( *line_index < number_of_lines )
3112
11.0M
  {
3113
11.0M
    if( libcsplit_narrow_split_string_get_segment_by_index(
3114
11.0M
         lines,
3115
11.0M
         *line_index,
3116
11.0M
         &line_string_segment,
3117
11.0M
         &line_string_segment_size,
3118
11.0M
         error ) != 1 )
3119
0
    {
3120
0
      libcerror_error_set(
3121
0
       error,
3122
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3123
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3124
0
       "%s: unable to retrieve line: %d.",
3125
0
       function,
3126
0
       *line_index );
3127
3128
0
      goto on_error;
3129
0
    }
3130
11.0M
    if( line_string_segment == NULL )
3131
0
    {
3132
0
      libcerror_error_set(
3133
0
       error,
3134
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3135
0
       LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
3136
0
       "%s: missing line string segment: %d.",
3137
0
       function,
3138
0
       *line_index );
3139
3140
0
      goto on_error;
3141
0
    }
3142
    /* Ignore trailing white space
3143
     */
3144
11.0M
    if( line_string_segment_size >= 2 )
3145
163k
    {
3146
163k
      line_string_segment_index = line_string_segment_size - 2;
3147
3148
413k
      while( line_string_segment_index > 0 )
3149
359k
      {
3150
359k
        if( ( line_string_segment[ line_string_segment_index ] != '\t' )
3151
332k
         && ( line_string_segment[ line_string_segment_index ] != '\n' )
3152
324k
         && ( line_string_segment[ line_string_segment_index ] != '\f' )
3153
296k
         && ( line_string_segment[ line_string_segment_index ] != '\v' )
3154
240k
         && ( line_string_segment[ line_string_segment_index ] != '\r' )
3155
216k
         && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
3156
110k
        {
3157
110k
          break;
3158
110k
        }
3159
249k
        line_string_segment_index--;
3160
249k
        line_string_segment_size--;
3161
249k
      }
3162
163k
    }
3163
    /* Ignore leading white space
3164
     */
3165
11.0M
    line_string_segment_index = 0;
3166
3167
11.5M
    while( line_string_segment_index < line_string_segment_size )
3168
11.5M
    {
3169
11.5M
      if( ( line_string_segment[ line_string_segment_index ] != '\t' )
3170
11.5M
       && ( line_string_segment[ line_string_segment_index ] != '\n' )
3171
11.5M
       && ( line_string_segment[ line_string_segment_index ] != '\f' )
3172
11.5M
       && ( line_string_segment[ line_string_segment_index ] != '\v' )
3173
11.4M
       && ( line_string_segment[ line_string_segment_index ] != '\r' )
3174
11.4M
       && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
3175
11.0M
      {
3176
11.0M
        break;
3177
11.0M
      }
3178
497k
      line_string_segment_index++;
3179
497k
    }
3180
    /* Skip an empty line
3181
     */
3182
11.0M
    if( ( line_string_segment_index >= line_string_segment_size )
3183
11.0M
     || ( line_string_segment[ line_string_segment_index ] == 0 ) )
3184
10.9M
    {
3185
10.9M
      *line_index += 1;
3186
3187
10.9M
      continue;
3188
10.9M
    }
3189
    /* Check for the end of section
3190
     */
3191
147k
    if( ( ( line_string_segment_size - line_string_segment_index ) == 2 )
3192
42.7k
     && ( line_string_segment[ line_string_segment_index ] == '}' ) )
3193
1.35k
    {
3194
1.35k
      *line_index += 1;
3195
3196
1.35k
      break;
3197
1.35k
    }
3198
    /* Determine the value identifier
3199
     */
3200
146k
    value_identifier        = &( line_string_segment[ line_string_segment_index ] );
3201
146k
    value_identifier_length = 0;
3202
3203
11.0M
    while( line_string_segment_index < line_string_segment_size )
3204
10.9M
    {
3205
10.9M
      if( ( line_string_segment[ line_string_segment_index ] == '\t' )
3206
10.9M
       || ( line_string_segment[ line_string_segment_index ] == '\n' )
3207
10.9M
       || ( line_string_segment[ line_string_segment_index ] == '\f' )
3208
10.9M
       || ( line_string_segment[ line_string_segment_index ] == '\v' )
3209
10.9M
       || ( line_string_segment[ line_string_segment_index ] == '\r' )
3210
10.9M
       || ( line_string_segment[ line_string_segment_index ] == ' ' )
3211
10.8M
       || ( line_string_segment[ line_string_segment_index ] == '=' ) )
3212
100k
      {
3213
100k
        break;
3214
100k
      }
3215
10.8M
      value_identifier_length++;
3216
3217
10.8M
      line_string_segment_index++;
3218
10.8M
    }
3219
    /* Skip a line not containing a value
3220
     */
3221
146k
    if( ( line_string_segment_index >= line_string_segment_size )
3222
100k
     || ( line_string_segment[ line_string_segment_index ] == 0 ) )
3223
45.7k
    {
3224
45.7k
      *line_index += 1;
3225
3226
45.7k
      continue;
3227
45.7k
    }
3228
    /* Make sure the value identifier is terminated by an end of string
3229
     */
3230
100k
    line_string_segment[ line_string_segment_index ] = 0;
3231
3232
100k
    line_string_segment_index++;
3233
3234
    /* Ignore whitespace
3235
     */
3236
216k
    while( line_string_segment_index < line_string_segment_size )
3237
194k
    {
3238
194k
      if( ( line_string_segment[ line_string_segment_index ] != '\t' )
3239
179k
       && ( line_string_segment[ line_string_segment_index ] != '\n' )
3240
170k
       && ( line_string_segment[ line_string_segment_index ] != '\f' )
3241
159k
       && ( line_string_segment[ line_string_segment_index ] != '\v' )
3242
148k
       && ( line_string_segment[ line_string_segment_index ] != '\r' )
3243
128k
       && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
3244
78.5k
      {
3245
78.5k
        break;
3246
78.5k
      }
3247
115k
      line_string_segment_index++;
3248
115k
    }
3249
100k
    if( line_string_segment[ line_string_segment_index ] == '=' )
3250
18.7k
    {
3251
18.7k
      line_string_segment_index++;
3252
3253
46.2k
      while( line_string_segment_index < line_string_segment_size )
3254
43.3k
      {
3255
43.3k
        if( ( line_string_segment[ line_string_segment_index ] != '\t' )
3256
40.8k
         && ( line_string_segment[ line_string_segment_index ] != '\n' )
3257
38.2k
         && ( line_string_segment[ line_string_segment_index ] != '\f' )
3258
36.1k
         && ( line_string_segment[ line_string_segment_index ] != '\v' )
3259
32.3k
         && ( line_string_segment[ line_string_segment_index ] != '\r' )
3260
31.2k
         && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
3261
15.9k
        {
3262
15.9k
          break;
3263
15.9k
        }
3264
27.4k
        line_string_segment_index++;
3265
27.4k
      }
3266
18.7k
    }
3267
    /* Skip a line not containing a value
3268
     */
3269
100k
    if( ( line_string_segment_index >= line_string_segment_size )
3270
75.6k
     || ( line_string_segment[ line_string_segment_index ] == 0 ) )
3271
30.7k
    {
3272
30.7k
      *line_index += 1;
3273
3274
30.7k
      continue;
3275
30.7k
    }
3276
    /* Ingore quotes at the beginning of the value data
3277
     */
3278
69.5k
    if( ( line_string_segment[ line_string_segment_index ] == '"' )
3279
64.7k
     || ( line_string_segment[ line_string_segment_index ] == '\'' ) )
3280
7.92k
    {
3281
7.92k
      line_string_segment_index++;
3282
7.92k
    }
3283
    /* Determine the value
3284
     */
3285
69.5k
    value        = &( line_string_segment[ line_string_segment_index ] );
3286
69.5k
    value_length = 0;
3287
3288
2.14M
    while( line_string_segment_index < line_string_segment_size )
3289
2.13M
    {
3290
2.13M
      if( ( line_string_segment[ line_string_segment_index ] == 0 )
3291
2.08M
       || ( line_string_segment[ line_string_segment_index ] == '\t' )
3292
2.08M
       || ( line_string_segment[ line_string_segment_index ] == '\n' )
3293
2.08M
       || ( line_string_segment[ line_string_segment_index ] == '\f' )
3294
2.07M
       || ( line_string_segment[ line_string_segment_index ] == '\v' )
3295
2.07M
       || ( line_string_segment[ line_string_segment_index ] == '\r' )
3296
2.07M
       || ( line_string_segment[ line_string_segment_index ] == '#' ) )
3297
66.4k
      {
3298
66.4k
        break;
3299
66.4k
      }
3300
2.07M
      line_string_segment_index++;
3301
2.07M
      value_length++;
3302
2.07M
    }
3303
    /* Ingore quotes at the end of the value data
3304
     */
3305
69.5k
    if( ( line_string_segment[ line_string_segment_index - 1 ] == '"' )
3306
66.5k
     || ( line_string_segment[ line_string_segment_index - 1 ] == '\'' ) )
3307
6.18k
    {
3308
6.18k
      line_string_segment_index--;
3309
6.18k
      value_length--;
3310
6.18k
    }
3311
    /* Make sure the value is terminated by an end of string
3312
     */
3313
69.5k
    line_string_segment[ line_string_segment_index ] = 0;
3314
3315
69.5k
    if( value_identifier_length == 4 )
3316
4.81k
    {
3317
4.81k
      if( narrow_string_compare(
3318
4.81k
           value_identifier,
3319
4.81k
           "type",
3320
4.81k
           4 ) == 0 )
3321
351
      {
3322
#if defined( HAVE_DEBUG_OUTPUT )
3323
        if( libcnotify_verbose != 0 )
3324
        {
3325
          libcnotify_printf(
3326
           "%s: type\t\t\t\t\t: %s\n",
3327
           function,
3328
           value );
3329
        }
3330
#endif
3331
/* TODO */
3332
351
      }
3333
4.81k
    }
3334
64.7k
    else if( value_identifier_length == 7 )
3335
8.68k
    {
3336
8.68k
      if( narrow_string_compare(
3337
8.68k
           value_identifier,
3338
8.68k
           "stripes",
3339
8.68k
           7 ) == 0 )
3340
6.79k
      {
3341
#if defined( HAVE_DEBUG_OUTPUT )
3342
        if( libcnotify_verbose != 0 )
3343
        {
3344
          libcnotify_printf(
3345
           "%s: stripes list:\n",
3346
           function );
3347
        }
3348
#endif
3349
6.79k
        if( ( value_length != 1 )
3350
6.76k
         || ( value[ 0 ] != '[' )
3351
6.74k
         || ( libvslvm_metadata_read_stripes_list(
3352
6.74k
               metadata,
3353
6.74k
               segment,
3354
6.74k
               lines,
3355
6.74k
               number_of_lines,
3356
6.74k
               line_index,
3357
6.74k
               error ) != 1 ) )
3358
674
        {
3359
674
          libcerror_error_set(
3360
674
           error,
3361
674
           LIBCERROR_ERROR_DOMAIN_IO,
3362
674
           LIBCERROR_IO_ERROR_READ_FAILED,
3363
674
           "%s: unable to read stripes list.",
3364
674
           function );
3365
3366
674
          goto on_error;
3367
674
        }
3368
/* TODO validate number of stripes */
3369
6.79k
      }
3370
8.68k
    }
3371
56.0k
    else if( value_identifier_length == 12 )
3372
5.16k
    {
3373
5.16k
      if( narrow_string_compare(
3374
5.16k
           value_identifier,
3375
5.16k
           "extent_count",
3376
5.16k
           12 ) == 0 )
3377
1.43k
      {
3378
#if defined( HAVE_DEBUG_OUTPUT )
3379
        if( libcnotify_verbose != 0 )
3380
        {
3381
          libcnotify_printf(
3382
           "%s: number of extents\t\t\t: %s\n",
3383
           function,
3384
           value );
3385
        }
3386
#endif
3387
1.43k
        if( libfvalue_utf8_string_copy_to_integer(
3388
1.43k
             (uint8_t *) value,
3389
1.43k
             value_length + 1,
3390
1.43k
             &value_64bit,
3391
1.43k
             64,
3392
1.43k
             LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED,
3393
1.43k
             error ) != 1 )
3394
10
        {
3395
10
          libcerror_error_set(
3396
10
           error,
3397
10
           LIBCERROR_ERROR_DOMAIN_MEMORY,
3398
10
           LIBCERROR_MEMORY_ERROR_SET_FAILED,
3399
10
           "%s: unable to set number of extents.",
3400
10
           function );
3401
3402
10
          goto on_error;
3403
10
        }
3404
1.42k
        if( value_64bit > (uint64_t) ( UINT64_MAX / internal_volume_group->extent_size ) )
3405
14
        {
3406
14
          libcerror_error_set(
3407
14
           error,
3408
14
           LIBCERROR_ERROR_DOMAIN_RUNTIME,
3409
14
           LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
3410
14
           "%s: invalid number of extents value exceeds maximum.",
3411
14
           function );
3412
3413
14
          goto on_error;
3414
14
        }
3415
1.41k
        value_64bit *= internal_volume_group->extent_size;
3416
3417
1.41k
        ( (libvslvm_internal_segment_t *) segment )->size = value_64bit;
3418
1.41k
      }
3419
3.72k
      else if( narrow_string_compare(
3420
3.72k
                value_identifier,
3421
3.72k
                "start_extent",
3422
3.72k
                12 ) == 0 )
3423
1.38k
      {
3424
#if defined( HAVE_DEBUG_OUTPUT )
3425
        if( libcnotify_verbose != 0 )
3426
        {
3427
          libcnotify_printf(
3428
           "%s: start extent\t\t\t\t: %s\n",
3429
           function,
3430
           value );
3431
        }
3432
#endif
3433
1.38k
        if( libfvalue_utf8_string_copy_to_integer(
3434
1.38k
             (uint8_t *) value,
3435
1.38k
             value_length + 1,
3436
1.38k
             &value_64bit,
3437
1.38k
             64,
3438
1.38k
             LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED,
3439
1.38k
             error ) != 1 )
3440
12
        {
3441
12
          libcerror_error_set(
3442
12
           error,
3443
12
           LIBCERROR_ERROR_DOMAIN_MEMORY,
3444
12
           LIBCERROR_MEMORY_ERROR_SET_FAILED,
3445
12
           "%s: unable to set start extent.",
3446
12
           function );
3447
3448
12
          goto on_error;
3449
12
        }
3450
1.37k
        if( value_64bit > (uint64_t) ( UINT64_MAX / internal_volume_group->extent_size ) )
3451
9
        {
3452
9
          libcerror_error_set(
3453
9
           error,
3454
9
           LIBCERROR_ERROR_DOMAIN_RUNTIME,
3455
9
           LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
3456
9
           "%s: invalid start extent value exceeds maximum.",
3457
9
           function );
3458
3459
9
          goto on_error;
3460
9
        }
3461
1.36k
        value_64bit *= internal_volume_group->extent_size;
3462
3463
1.36k
        ( (libvslvm_internal_segment_t *) segment )->offset = value_64bit;
3464
1.36k
      }
3465
2.34k
      else if( narrow_string_compare(
3466
2.34k
                value_identifier,
3467
2.34k
                "stripe_count",
3468
2.34k
                12 ) == 0 )
3469
71
      {
3470
#if defined( HAVE_DEBUG_OUTPUT )
3471
        if( libcnotify_verbose != 0 )
3472
        {
3473
          libcnotify_printf(
3474
           "%s: number of stripes\t\t\t: %s\n",
3475
           function,
3476
           value );
3477
        }
3478
#endif
3479
/* TODO */
3480
71
      }
3481
5.16k
    }
3482
#if defined( HAVE_DEBUG_OUTPUT )
3483
    else if( libcnotify_verbose != 0 )
3484
    {
3485
      libcnotify_printf(
3486
       "%s: value: %d\t\t\t\t: %s = %s\n",
3487
       function,
3488
       *line_index,
3489
       value_identifier,
3490
       value );
3491
    }
3492
#endif
3493
68.8k
    *line_index += 1;
3494
68.8k
  }
3495
2.97k
  if( libvslvm_logical_volume_values_append_segment(
3496
2.97k
       logical_volume_values,
3497
2.97k
       segment,
3498
2.97k
       error ) != 1 )
3499
0
  {
3500
0
    libcerror_error_set(
3501
0
     error,
3502
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
3503
0
     LIBCERROR_RUNTIME_ERROR_APPEND_FAILED,
3504
0
     "%s: unable to append segment to logical volume values.",
3505
0
     function );
3506
3507
0
    goto on_error;
3508
0
  }
3509
2.97k
  segment = NULL;
3510
3511
2.97k
  return( 1 );
3512
3513
719
on_error:
3514
719
  if( segment != NULL )
3515
719
  {
3516
719
    libvslvm_internal_segment_free(
3517
719
     (libvslvm_internal_segment_t **) &segment,
3518
719
     NULL );
3519
719
  }
3520
719
  return( -1 );
3521
2.97k
}
3522
3523
/* Reads the stripes list
3524
 * Returns the 1 if successful or -1 on error
3525
 */
3526
int libvslvm_metadata_read_stripes_list(
3527
     libvslvm_metadata_t *metadata,
3528
     libvslvm_segment_t *segment,
3529
     libcsplit_narrow_split_string_t *lines,
3530
     int number_of_lines,
3531
     int *line_index,
3532
     libcerror_error_t **error )
3533
6.74k
{
3534
6.74k
  libvslvm_internal_volume_group_t *internal_volume_group = NULL;
3535
6.74k
  libvslvm_stripe_t *stripe                               = NULL;
3536
6.74k
  char *line_string_segment                               = NULL;
3537
6.74k
  char *value                                             = NULL;
3538
6.74k
  char *value_identifier                                  = NULL;
3539
6.74k
  static char *function                                   = "libvslvm_metadata_read_stripes_list";
3540
6.74k
  size_t line_string_segment_index                        = 0;
3541
6.74k
  size_t line_string_segment_size                         = 0;
3542
6.74k
  size_t value_identifier_length                          = 0;
3543
6.74k
  size_t value_length                                     = 0;
3544
6.74k
  uint64_t value_64bit                                    = 0;
3545
3546
6.74k
  if( metadata == NULL )
3547
0
  {
3548
0
    libcerror_error_set(
3549
0
     error,
3550
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3551
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3552
0
     "%s: invalid metadata.",
3553
0
     function );
3554
3555
0
    return( -1 );
3556
0
  }
3557
6.74k
  if( metadata->volume_group == NULL )
3558
0
  {
3559
0
    libcerror_error_set(
3560
0
     error,
3561
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
3562
0
     LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
3563
0
     "%s: invalid metadata - missing volume group.",
3564
0
     function );
3565
3566
0
    return( -1 );
3567
0
  }
3568
6.74k
  internal_volume_group = (libvslvm_internal_volume_group_t *) metadata->volume_group;
3569
3570
6.74k
  if( internal_volume_group->extent_size == 0 )
3571
0
  {
3572
0
    libcerror_error_set(
3573
0
     error,
3574
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3575
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
3576
0
     "%s: invalid volume group - extent size value out of bounds.",
3577
0
     function );
3578
3579
0
    return( -1 );
3580
0
  }
3581
6.74k
  if( line_index == NULL )
3582
0
  {
3583
0
    libcerror_error_set(
3584
0
     error,
3585
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3586
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3587
0
     "%s: invalid line index.",
3588
0
     function );
3589
3590
0
    return( -1 );
3591
0
  }
3592
6.74k
  if( number_of_lines <= 0 )
3593
0
  {
3594
0
    libcerror_error_set(
3595
0
     error,
3596
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3597
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
3598
0
     "%s: invalid number of lines value out of bounds.",
3599
0
     function );
3600
3601
0
    return( -1 );
3602
0
  }
3603
6.74k
  if( ( *line_index < 0 )
3604
6.74k
   || ( *line_index >= number_of_lines ) )
3605
0
  {
3606
0
    libcerror_error_set(
3607
0
     error,
3608
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3609
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
3610
0
     "%s: invalid line index value out of bounds.",
3611
0
     function );
3612
3613
0
    return( -1 );
3614
0
  }
3615
6.74k
  *line_index += 1;
3616
3617
1.67M
  while( *line_index < number_of_lines )
3618
1.67M
  {
3619
1.67M
    if( libcsplit_narrow_split_string_get_segment_by_index(
3620
1.67M
         lines,
3621
1.67M
         *line_index,
3622
1.67M
         &line_string_segment,
3623
1.67M
         &line_string_segment_size,
3624
1.67M
         error ) != 1 )
3625
0
    {
3626
0
      libcerror_error_set(
3627
0
       error,
3628
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3629
0
       LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3630
0
       "%s: unable to retrieve line: %d.",
3631
0
       function,
3632
0
       *line_index );
3633
3634
0
      goto on_error;
3635
0
    }
3636
1.67M
    if( line_string_segment == NULL )
3637
0
    {
3638
0
      libcerror_error_set(
3639
0
       error,
3640
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3641
0
       LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
3642
0
       "%s: missing line string segment: %d.",
3643
0
       function,
3644
0
       *line_index );
3645
3646
0
      goto on_error;
3647
0
    }
3648
    /* Ignore trailing white space
3649
     */
3650
1.67M
    if( line_string_segment_size >= 2 )
3651
561k
    {
3652
561k
      line_string_segment_index = line_string_segment_size - 2;
3653
3654
1.01M
      while( line_string_segment_index > 0 )
3655
909k
      {
3656
909k
        if( ( line_string_segment[ line_string_segment_index ] != '\t' )
3657
758k
         && ( line_string_segment[ line_string_segment_index ] != '\n' )
3658
734k
         && ( line_string_segment[ line_string_segment_index ] != '\f' )
3659
690k
         && ( line_string_segment[ line_string_segment_index ] != '\v' )
3660
643k
         && ( line_string_segment[ line_string_segment_index ] != '\r' )
3661
541k
         && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
3662
454k
        {
3663
454k
          break;
3664
454k
        }
3665
455k
        line_string_segment_index--;
3666
455k
        line_string_segment_size--;
3667
455k
      }
3668
561k
    }
3669
    /* Ignore leading white space
3670
     */
3671
1.67M
    line_string_segment_index = 0;
3672
3673
2.02M
    while( line_string_segment_index < line_string_segment_size )
3674
2.01M
    {
3675
2.01M
      if( ( line_string_segment[ line_string_segment_index ] != '\t' )
3676
1.99M
       && ( line_string_segment[ line_string_segment_index ] != '\n' )
3677
1.99M
       && ( line_string_segment[ line_string_segment_index ] != '\f' )
3678
1.97M
       && ( line_string_segment[ line_string_segment_index ] != '\v' )
3679
1.93M
       && ( line_string_segment[ line_string_segment_index ] != '\r' )
3680
1.85M
       && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
3681
1.65M
      {
3682
1.65M
        break;
3683
1.65M
      }
3684
351k
      line_string_segment_index++;
3685
351k
    }
3686
    /* Skip an empty line
3687
     */
3688
1.67M
    if( ( line_string_segment_index >= line_string_segment_size )
3689
1.65M
     || ( line_string_segment[ line_string_segment_index ] == 0 ) )
3690
1.13M
    {
3691
1.13M
      *line_index += 1;
3692
3693
1.13M
      continue;
3694
1.13M
    }
3695
    /* Check for the end of section
3696
     */
3697
535k
    if( ( ( line_string_segment_size - line_string_segment_index ) == 2 )
3698
86.3k
     && ( line_string_segment[ line_string_segment_index ] == ']' ) )
3699
5.52k
    {
3700
5.52k
      break;
3701
5.52k
    }
3702
    /* Ingore quotes at the beginning of the value data
3703
     */
3704
530k
    if( ( line_string_segment[ line_string_segment_index ] == '"' )
3705
503k
     || ( line_string_segment[ line_string_segment_index ] == '\'' ) )
3706
29.4k
    {
3707
29.4k
      line_string_segment_index++;
3708
29.4k
    }
3709
    /* Determine the value identifier
3710
     */
3711
530k
    value_identifier        = &( line_string_segment[ line_string_segment_index ] );
3712
530k
    value_identifier_length = 0;
3713
3714
8.39M
    while( line_string_segment_index < line_string_segment_size )
3715
8.28M
    {
3716
8.28M
      if( ( line_string_segment[ line_string_segment_index ] == '\t' )
3717
8.27M
       || ( line_string_segment[ line_string_segment_index ] == '\n' )
3718
8.27M
       || ( line_string_segment[ line_string_segment_index ] == '\f' )
3719
8.26M
       || ( line_string_segment[ line_string_segment_index ] == '\v' )
3720
8.22M
       || ( line_string_segment[ line_string_segment_index ] == '\r' )
3721
8.22M
       || ( line_string_segment[ line_string_segment_index ] == ' ' )
3722
8.15M
       || ( line_string_segment[ line_string_segment_index ] == ',' ) )
3723
423k
      {
3724
423k
        break;
3725
423k
      }
3726
7.86M
      value_identifier_length++;
3727
3728
7.86M
      line_string_segment_index++;
3729
7.86M
    }
3730
    /* Skip a line not containing a value
3731
     */
3732
530k
    if( ( line_string_segment_index >= line_string_segment_size )
3733
423k
     || ( line_string_segment[ line_string_segment_index ] == 0 ) )
3734
106k
    {
3735
106k
      *line_index += 1;
3736
3737
106k
      continue;
3738
106k
    }
3739
    /* Ingore quotes at the end of the value identifier
3740
     */
3741
423k
    if( ( line_string_segment[ line_string_segment_index - 1 ] == '"' )
3742
400k
     || ( line_string_segment[ line_string_segment_index - 1 ] == '\'' ) )
3743
30.2k
    {
3744
30.2k
      value_identifier_length--;
3745
3746
      /* Make sure the value identifier is terminated by an end of string
3747
       */
3748
30.2k
      line_string_segment[ line_string_segment_index - 1 ] = 0;
3749
30.2k
    }
3750
393k
    else
3751
393k
    {
3752
      /* Make sure the value identifier is terminated by an end of string
3753
       */
3754
393k
      line_string_segment[ line_string_segment_index ] = 0;
3755
393k
    }
3756
423k
    line_string_segment_index++;
3757
3758
    /* Ignore whitespace
3759
     */
3760
759k
    while( line_string_segment_index < line_string_segment_size )
3761
692k
    {
3762
692k
      if( ( line_string_segment[ line_string_segment_index ] != '\t' )
3763
685k
       && ( line_string_segment[ line_string_segment_index ] != '\n' )
3764
674k
       && ( line_string_segment[ line_string_segment_index ] != '\f' )
3765
670k
       && ( line_string_segment[ line_string_segment_index ] != '\v' )
3766
667k
       && ( line_string_segment[ line_string_segment_index ] != '\r' )
3767
661k
       && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
3768
356k
      {
3769
356k
        break;
3770
356k
      }
3771
335k
      line_string_segment_index++;
3772
335k
    }
3773
423k
    if( line_string_segment[ line_string_segment_index ] == ',' )
3774
27.9k
    {
3775
27.9k
      line_string_segment_index++;
3776
3777
52.9k
      while( line_string_segment_index < line_string_segment_size )
3778
51.3k
      {
3779
51.3k
        if( ( line_string_segment[ line_string_segment_index ] != '\t' )
3780
49.3k
         && ( line_string_segment[ line_string_segment_index ] != '\n' )
3781
47.3k
         && ( line_string_segment[ line_string_segment_index ] != '\f' )
3782
45.7k
         && ( line_string_segment[ line_string_segment_index ] != '\v' )
3783
43.8k
         && ( line_string_segment[ line_string_segment_index ] != '\r' )
3784
41.3k
         && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
3785
26.3k
        {
3786
26.3k
          break;
3787
26.3k
        }
3788
24.9k
        line_string_segment_index++;
3789
24.9k
      }
3790
27.9k
    }
3791
    /* Skip a line not containing a value
3792
     */
3793
423k
    if( ( line_string_segment_index >= line_string_segment_size )
3794
355k
     || ( line_string_segment[ line_string_segment_index ] == 0 ) )
3795
82.4k
    {
3796
82.4k
      *line_index += 1;
3797
3798
82.4k
      continue;
3799
82.4k
    }
3800
    /* Determine the value
3801
     */
3802
341k
    value        = &( line_string_segment[ line_string_segment_index ] );
3803
341k
    value_length = line_string_segment_size - 1;
3804
3805
    /* Make sure the value is terminated by an end of string
3806
     */
3807
341k
    line_string_segment[ value_length ] = 0;
3808
3809
341k
    value_length -= line_string_segment_index;
3810
3811
#if defined( HAVE_DEBUG_OUTPUT )
3812
    if( libcnotify_verbose != 0 )
3813
    {
3814
      libcnotify_printf(
3815
       "%s: value: %d\t\t\t\t: %s, %s\n",
3816
       function,
3817
       *line_index,
3818
       value_identifier,
3819
       value );
3820
    }
3821
#endif
3822
341k
    *line_index += 1;
3823
3824
341k
    if( libfvalue_utf8_string_copy_to_integer(
3825
341k
         (uint8_t *) value,
3826
341k
         value_length + 1,
3827
341k
         &value_64bit,
3828
341k
         64,
3829
341k
         LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED,
3830
341k
         error ) != 1 )
3831
595
    {
3832
595
      libcerror_error_set(
3833
595
       error,
3834
595
       LIBCERROR_ERROR_DOMAIN_MEMORY,
3835
595
       LIBCERROR_MEMORY_ERROR_SET_FAILED,
3836
595
       "%s: unable to set data area offset.",
3837
595
       function );
3838
3839
595
      goto on_error;
3840
595
    }
3841
340k
    if( value_64bit > (uint64_t) ( UINT64_MAX / internal_volume_group->extent_size ) )
3842
13
    {
3843
13
      libcerror_error_set(
3844
13
       error,
3845
13
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3846
13
       LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
3847
13
       "%s: invalid data area offset value exceeds maximum.",
3848
13
       function );
3849
3850
13
      goto on_error;
3851
13
    }
3852
340k
    value_64bit *= internal_volume_group->extent_size;
3853
3854
340k
    if( libvslvm_stripe_initialize(
3855
340k
         &stripe,
3856
340k
         error ) != 1 )
3857
0
    {
3858
0
      libcerror_error_set(
3859
0
       error,
3860
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3861
0
       LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
3862
0
       "%s: unable to create stripe.",
3863
0
       function );
3864
3865
0
      goto on_error;
3866
0
    }
3867
340k
    if( libvslvm_internal_stripe_set_physical_volume_name(
3868
340k
         (libvslvm_internal_stripe_t *) stripe,
3869
340k
         value_identifier,
3870
340k
         value_identifier_length + 1,
3871
340k
         error ) != 1 )
3872
12
    {
3873
12
      libcerror_error_set(
3874
12
       error,
3875
12
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3876
12
       LIBCERROR_RUNTIME_ERROR_SET_FAILED,
3877
12
       "%s: unable to set physical volume name.",
3878
12
       function );
3879
3880
12
      goto on_error;
3881
12
    }
3882
340k
    if( libvslvm_stripe_set_data_area_offset(
3883
340k
         stripe,
3884
340k
         value_64bit,
3885
340k
         error ) != 1 )
3886
0
    {
3887
0
      libcerror_error_set(
3888
0
       error,
3889
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3890
0
       LIBCERROR_RUNTIME_ERROR_SET_FAILED,
3891
0
       "%s: unable to set data area offset.",
3892
0
       function );
3893
3894
0
      goto on_error;
3895
0
    }
3896
340k
    if( libvslvm_segment_append_stripe(
3897
340k
         segment,
3898
340k
         stripe,
3899
340k
         error ) != 1 )
3900
0
    {
3901
0
      libcerror_error_set(
3902
0
       error,
3903
0
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3904
0
       LIBCERROR_RUNTIME_ERROR_APPEND_FAILED,
3905
0
       "%s: unable to append stripe to segment.",
3906
0
       function );
3907
3908
0
      goto on_error;
3909
0
    }
3910
340k
    stripe = NULL;
3911
340k
  }
3912
6.12k
  return( 1 );
3913
3914
620
on_error:
3915
620
  if( stripe != NULL )
3916
12
  {
3917
12
    libvslvm_internal_stripe_free(
3918
12
     (libvslvm_internal_stripe_t **) &stripe,
3919
12
     NULL );
3920
12
  }
3921
620
  return( -1 );
3922
6.74k
}
3923
3924
/* Retrieves the volume group
3925
 * Returns 1 if successful, 0 if not available or -1 on error
3926
 */
3927
int libvslvm_metadata_get_volume_group(
3928
     libvslvm_metadata_t *metadata,
3929
     libvslvm_volume_group_t **volume_group,
3930
     libcerror_error_t **error )
3931
8.77k
{
3932
8.77k
  static char *function = "libvslvm_metadata_get_volume_group";
3933
3934
8.77k
  if( metadata == NULL )
3935
0
  {
3936
0
    libcerror_error_set(
3937
0
     error,
3938
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3939
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3940
0
     "%s: invalid metadata.",
3941
0
     function );
3942
3943
0
    return( -1 );
3944
0
  }
3945
8.77k
  if( volume_group == NULL )
3946
0
  {
3947
0
    libcerror_error_set(
3948
0
     error,
3949
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3950
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3951
0
     "%s: invalid volume group.",
3952
0
     function );
3953
3954
0
    return( -1 );
3955
0
  }
3956
8.77k
  if( *volume_group != NULL )
3957
0
  {
3958
0
    libcerror_error_set(
3959
0
     error,
3960
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
3961
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
3962
0
     "%s: invalid volume group value already set.",
3963
0
     function );
3964
3965
0
    return( -1 );
3966
0
  }
3967
8.77k
  if( metadata->volume_group == NULL )
3968
0
  {
3969
0
    return( 0 );
3970
0
  }
3971
8.77k
  *volume_group = metadata->volume_group;
3972
3973
8.77k
  return( 1 );
3974
8.77k
}
3975