Coverage Report

Created: 2026-10-22 07:28

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.23k
{
52
7.23k
  static char *function = "libvslvm_metadata_initialize";
53
54
7.23k
  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.23k
  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.23k
  *metadata = memory_allocate_structure(
77
7.23k
               libvslvm_metadata_t );
78
79
7.23k
  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.23k
  if( memory_set(
91
7.23k
       *metadata,
92
7.23k
       0,
93
7.23k
       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.23k
  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.23k
}
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.23k
{
129
7.23k
  static char *function = "libvslvm_metadata_free";
130
7.23k
  int result            = 1;
131
132
7.23k
  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.23k
  if( *metadata != NULL )
144
7.23k
  {
145
7.23k
    if( ( *metadata )->volume_group != NULL )
146
5.31k
    {
147
5.31k
      if( libvslvm_internal_volume_group_free(
148
5.31k
           (libvslvm_internal_volume_group_t **) &( ( *metadata )->volume_group ),
149
5.31k
           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.31k
    }
161
7.23k
    memory_free(
162
7.23k
     *metadata );
163
164
7.23k
    *metadata = NULL;
165
7.23k
  }
166
7.23k
  return( result );
167
7.23k
}
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
6.92k
{
179
6.92k
  libcsplit_narrow_split_string_t *lines = NULL;
180
6.92k
  static char *function                  = "libvslvm_metadata_read_data";
181
6.92k
  uint32_t calculated_checksum           = 0;
182
6.92k
  int line_index                         = 0;
183
6.92k
  int number_of_lines                    = 0;
184
185
6.92k
  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
6.92k
  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
6.92k
  if( ( data_size == 0 )
208
6.92k
   || ( 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
6.92k
  if( libvslvm_checksum_calculate_weak_crc32(
220
6.92k
       &calculated_checksum,
221
6.92k
       data,
222
6.92k
       data_size,
223
6.92k
       0xf597a6cfUL,
224
6.92k
       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
6.92k
  if( ( stored_checksum != 0 )
236
161
   && ( stored_checksum != calculated_checksum ) )
237
154
  {
238
154
    libcerror_error_set(
239
154
     error,
240
154
     LIBCERROR_ERROR_DOMAIN_INPUT,
241
154
     LIBCERROR_INPUT_ERROR_CHECKSUM_MISMATCH,
242
154
     "%s: mismatch in checksum ( 0x%08" PRIx32 " != 0x%08" PRIx32 " ).",
243
154
     function,
244
154
     stored_checksum,
245
154
     calculated_checksum );
246
247
154
    goto on_error;
248
154
  }
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
6.77k
  if( libcsplit_narrow_string_split(
259
6.77k
       (char *) data,
260
6.77k
       data_size,
261
6.77k
       '\n',
262
6.77k
       &lines,
263
6.77k
       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
6.77k
  if( libcsplit_narrow_split_string_get_number_of_segments(
275
6.77k
       lines,
276
6.77k
       &number_of_lines,
277
6.77k
       error ) != 1 )
278
16
  {
279
16
    libcerror_error_set(
280
16
     error,
281
16
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
282
16
     LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
283
16
     "%s: unable to retrieve number of lines.",
284
16
     function );
285
286
16
    goto on_error;
287
16
  }
288
6.75k
  if( libvslvm_metadata_read_volume_group(
289
6.75k
       metadata,
290
6.75k
       lines,
291
6.75k
       number_of_lines,
292
6.75k
       &line_index,
293
6.75k
       error ) != 1 )
294
1.44k
  {
295
1.44k
    libcerror_error_set(
296
1.44k
     error,
297
1.44k
     LIBCERROR_ERROR_DOMAIN_IO,
298
1.44k
     LIBCERROR_IO_ERROR_READ_FAILED,
299
1.44k
     "%s: unable to read volume group.",
300
1.44k
     function );
301
302
1.44k
    goto on_error;
303
1.44k
  }
304
5.31k
  if( libcsplit_narrow_split_string_free(
305
5.31k
       &lines,
306
5.31k
       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.31k
  return( 1 );
318
319
1.61k
on_error:
320
1.61k
  if( lines != NULL )
321
1.44k
  {
322
1.44k
    libcsplit_narrow_split_string_free(
323
1.44k
     &lines,
324
1.44k
     NULL );
325
1.44k
  }
326
1.61k
  return( -1 );
327
5.31k
}
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.23k
{
340
7.23k
  uint8_t *data         = NULL;
341
7.23k
  static char *function = "libvslvm_metadata_read_file_io_handle";
342
7.23k
  ssize_t read_count    = 0;
343
344
7.23k
  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.23k
  if( ( metadata_size == 0 )
356
7.23k
   || ( metadata_size > (size64_t) MEMORY_MAXIMUM_ALLOCATION_SIZE ) )
357
120
  {
358
120
    libcerror_error_set(
359
120
     error,
360
120
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
361
120
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
362
120
     "%s: invalid metadata size value out of bounds.",
363
120
     function );
364
365
120
    goto on_error;
366
120
  }
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.11k
  data = (uint8_t *) memory_allocate(
378
7.11k
                      (size_t) metadata_size );
379
380
7.11k
  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.11k
  read_count = libbfio_handle_read_buffer_at_offset(
392
7.11k
                file_io_handle,
393
7.11k
                data,
394
7.11k
                (size_t) metadata_size,
395
7.11k
                file_offset,
396
7.11k
                error );
397
398
7.11k
  if( read_count != (ssize_t) metadata_size )
399
191
  {
400
191
    libcerror_error_set(
401
191
     error,
402
191
     LIBCERROR_ERROR_DOMAIN_IO,
403
191
     LIBCERROR_IO_ERROR_READ_FAILED,
404
191
     "%s: unable to read metadata at offset: %" PRIi64 " (0x%08" PRIx64 ").",
405
191
     function,
406
191
     file_offset,
407
191
     file_offset );
408
409
191
    goto on_error;
410
191
  }
411
6.92k
  if( libvslvm_metadata_read_data(
412
6.92k
       metadata,
413
6.92k
       data,
414
6.92k
       (size_t) metadata_size,
415
6.92k
       stored_checksum,
416
6.92k
       error ) != 1 )
417
1.61k
  {
418
1.61k
    libcerror_error_set(
419
1.61k
     error,
420
1.61k
     LIBCERROR_ERROR_DOMAIN_IO,
421
1.61k
     LIBCERROR_IO_ERROR_READ_FAILED,
422
1.61k
     "%s: unable to read metadata.",
423
1.61k
     function );
424
425
1.61k
    goto on_error;
426
1.61k
  }
427
5.31k
  memory_free(
428
5.31k
   data );
429
430
5.31k
  return( 1 );
431
432
1.92k
on_error:
433
1.92k
  if( data != NULL )
434
1.80k
  {
435
1.80k
    memory_free(
436
1.80k
     data );
437
1.80k
  }
438
1.92k
  return( -1 );
439
6.92k
}
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
6.75k
{
451
6.75k
  libvslvm_internal_volume_group_t *internal_volume_group = NULL;
452
6.75k
  char *line_string_segment                               = NULL;
453
6.75k
  char *value                                             = NULL;
454
6.75k
  char *value_identifier                                  = NULL;
455
6.75k
  static char *function                                   = "libvslvm_metadata_read_volume_group";
456
6.75k
  size_t line_string_segment_index                        = 0;
457
6.75k
  size_t line_string_segment_size                         = 0;
458
6.75k
  size_t value_identifier_length                          = 0;
459
6.75k
  size_t value_length                                     = 0;
460
6.75k
  uint64_t value_64bit                                    = 0;
461
462
6.75k
  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
6.75k
  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
6.75k
  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
6.75k
  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
6.75k
  if( ( *line_index < 0 )
507
6.75k
   || ( *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
6.75k
  if( libcsplit_narrow_split_string_get_segment_by_index(
519
6.75k
       lines,
520
6.75k
       *line_index,
521
6.75k
       &line_string_segment,
522
6.75k
       &line_string_segment_size,
523
6.75k
       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
6.75k
  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
6.75k
  if( line_string_segment_size >= 2 )
550
6.74k
  {
551
6.74k
    line_string_segment_index = line_string_segment_size - 2;
552
553
26.8k
    while( line_string_segment_index > 0 )
554
26.8k
    {
555
26.8k
      if( ( line_string_segment[ line_string_segment_index ] != '\t' )
556
24.9k
       && ( line_string_segment[ line_string_segment_index ] != '\n' )
557
21.0k
       && ( line_string_segment[ line_string_segment_index ] != '\f' )
558
19.7k
       && ( line_string_segment[ line_string_segment_index ] != '\v' )
559
14.1k
       && ( line_string_segment[ line_string_segment_index ] != '\r' )
560
13.1k
       && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
561
6.73k
      {
562
6.73k
        break;
563
6.73k
      }
564
20.1k
      line_string_segment_index--;
565
20.1k
      line_string_segment_size--;
566
20.1k
    }
567
6.74k
  }
568
  /* Ignore leading white space
569
   */
570
6.75k
  line_string_segment_index = 0;
571
572
167k
  while( line_string_segment_index < line_string_segment_size )
573
167k
  {
574
167k
    if( ( line_string_segment[ line_string_segment_index ] != '\t' )
575
162k
     && ( line_string_segment[ line_string_segment_index ] != '\n' )
576
162k
     && ( line_string_segment[ line_string_segment_index ] != '\f' )
577
159k
     && ( line_string_segment[ line_string_segment_index ] != '\v' )
578
155k
     && ( line_string_segment[ line_string_segment_index ] != '\r' )
579
146k
     && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
580
6.75k
    {
581
6.75k
      break;
582
6.75k
    }
583
160k
    line_string_segment_index++;
584
160k
  }
585
6.75k
  if( ( line_string_segment_size < 3 )
586
6.73k
   || ( line_string_segment[ line_string_segment_size - 3 ] != ' ' )
587
6.55k
   || ( line_string_segment[ line_string_segment_size - 2 ] != '{' ) )
588
234
  {
589
234
    libcerror_error_set(
590
234
     error,
591
234
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
592
234
     LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE,
593
234
     "%s: unsupported volume group signature.",
594
234
     function );
595
596
234
    goto on_error;
597
234
  }
598
6.52k
  if( libvslvm_volume_group_initialize(
599
6.52k
       &( metadata->volume_group ),
600
6.52k
       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.52k
  internal_volume_group = (libvslvm_internal_volume_group_t *) metadata->volume_group;
612
613
6.52k
  if( ( line_string_segment_size < 2 )
614
6.52k
   || ( line_string_segment_index >= ( line_string_segment_size - 2 ) ) )
615
3
  {
616
3
    libcerror_error_set(
617
3
     error,
618
3
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
619
3
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
620
3
     "%s: invalid line string segment size value out of bounds.",
621
3
     function );
622
623
3
    goto on_error;
624
3
  }
625
6.52k
  if( libvslvm_internal_volume_group_set_name(
626
6.52k
       (libvslvm_internal_volume_group_t *) metadata->volume_group,
627
6.52k
       &( line_string_segment[ line_string_segment_index ] ),
628
6.52k
       line_string_segment_size - ( line_string_segment_index + 2 ),
629
6.52k
       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.52k
  *line_index += 1;
650
651
12.6M
  while( *line_index < number_of_lines )
652
12.6M
  {
653
12.6M
    if( libcsplit_narrow_split_string_get_segment_by_index(
654
12.6M
         lines,
655
12.6M
         *line_index,
656
12.6M
         &line_string_segment,
657
12.6M
         &line_string_segment_size,
658
12.6M
         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
12.6M
    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
12.6M
    if( line_string_segment_size >= 2 )
685
198k
    {
686
198k
      line_string_segment_index = line_string_segment_size - 2;
687
688
602k
      while( line_string_segment_index > 0 )
689
542k
      {
690
542k
        if( ( line_string_segment[ line_string_segment_index ] != '\t' )
691
511k
         && ( line_string_segment[ line_string_segment_index ] != '\n' )
692
499k
         && ( line_string_segment[ line_string_segment_index ] != '\f' )
693
459k
         && ( line_string_segment[ line_string_segment_index ] != '\v' )
694
421k
         && ( line_string_segment[ line_string_segment_index ] != '\r' )
695
399k
         && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
696
139k
        {
697
139k
          break;
698
139k
        }
699
403k
        line_string_segment_index--;
700
403k
        line_string_segment_size--;
701
403k
      }
702
198k
    }
703
    /* Ignore leading white space
704
     */
705
12.6M
    line_string_segment_index = 0;
706
707
14.9M
    while( line_string_segment_index < line_string_segment_size )
708
14.9M
    {
709
14.9M
      if( ( line_string_segment[ line_string_segment_index ] != '\t' )
710
14.8M
       && ( line_string_segment[ line_string_segment_index ] != '\n' )
711
14.8M
       && ( line_string_segment[ line_string_segment_index ] != '\f' )
712
14.8M
       && ( line_string_segment[ line_string_segment_index ] != '\v' )
713
14.8M
       && ( line_string_segment[ line_string_segment_index ] != '\r' )
714
14.7M
       && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
715
12.6M
      {
716
12.6M
        break;
717
12.6M
      }
718
2.24M
      line_string_segment_index++;
719
2.24M
    }
720
    /* Skip an empty line
721
     */
722
12.6M
    if( ( line_string_segment_index >= line_string_segment_size )
723
12.6M
     || ( line_string_segment[ line_string_segment_index ] == 0 ) )
724
12.4M
    {
725
12.4M
      *line_index += 1;
726
727
12.4M
      continue;
728
12.4M
    }
729
    /* Check for the end of section
730
     */
731
186k
    if( ( ( line_string_segment_size - line_string_segment_index ) == 2 )
732
56.7k
     && ( line_string_segment[ line_string_segment_index ] == '}' ) )
733
50
    {
734
50
      *line_index += 1;
735
736
50
      break;
737
50
    }
738
    /* Check for the start of a sub section
739
     */
740
186k
    if( ( line_string_segment_size - line_string_segment_index ) == 18 )
741
9.36k
    {
742
9.36k
      if( narrow_string_compare(
743
9.36k
           &( line_string_segment[ line_string_segment_index ] ),
744
9.36k
           "logical_volumes {",
745
9.36k
           17 ) == 0 )
746
6.19k
      {
747
6.19k
        if( libvslvm_metadata_read_logical_volumes(
748
6.19k
             metadata,
749
6.19k
             metadata->volume_group,
750
6.19k
             lines,
751
6.19k
             number_of_lines,
752
6.19k
             line_index,
753
6.19k
             error ) != 1 )
754
849
        {
755
849
          libcerror_error_set(
756
849
           error,
757
849
           LIBCERROR_ERROR_DOMAIN_IO,
758
849
           LIBCERROR_IO_ERROR_READ_FAILED,
759
849
           "%s: unable to read logical volumes.",
760
849
           function );
761
762
849
          goto on_error;
763
849
        }
764
5.34k
        continue;
765
6.19k
      }
766
9.36k
    }
767
177k
    else if( ( line_string_segment_size - line_string_segment_index ) == 19 )
768
8.36k
    {
769
8.36k
      if( narrow_string_compare(
770
8.36k
           &( line_string_segment[ line_string_segment_index ] ),
771
8.36k
           "physical_volumes {",
772
8.36k
           18 ) == 0 )
773
4.01k
      {
774
4.01k
        if( libvslvm_metadata_read_physical_volumes(
775
4.01k
             metadata,
776
4.01k
             metadata->volume_group,
777
4.01k
             lines,
778
4.01k
             number_of_lines,
779
4.01k
             line_index,
780
4.01k
             error ) != 1 )
781
188
        {
782
188
          libcerror_error_set(
783
188
           error,
784
188
           LIBCERROR_ERROR_DOMAIN_IO,
785
188
           LIBCERROR_IO_ERROR_READ_FAILED,
786
188
           "%s: unable to read physical volumes.",
787
188
           function );
788
789
188
          goto on_error;
790
188
        }
791
3.82k
        continue;
792
4.01k
      }
793
8.36k
    }
794
    /* Determine the value identifier
795
     */
796
176k
    value_identifier        = &( line_string_segment[ line_string_segment_index ] );
797
176k
    value_identifier_length = 0;
798
799
14.5M
    while( line_string_segment_index < line_string_segment_size )
800
14.5M
    {
801
14.5M
      if( ( line_string_segment[ line_string_segment_index ] == '\t' )
802
14.5M
       || ( line_string_segment[ line_string_segment_index ] == '\n' )
803
14.5M
       || ( line_string_segment[ line_string_segment_index ] == '\f' )
804
14.5M
       || ( line_string_segment[ line_string_segment_index ] == '\v' )
805
14.4M
       || ( line_string_segment[ line_string_segment_index ] == '\r' )
806
14.4M
       || ( line_string_segment[ line_string_segment_index ] == ' ' )
807
14.4M
       || ( line_string_segment[ line_string_segment_index ] == '=' ) )
808
115k
      {
809
115k
        break;
810
115k
      }
811
14.4M
      value_identifier_length++;
812
813
14.4M
      line_string_segment_index++;
814
14.4M
    }
815
    /* Skip a line not containing a value
816
     */
817
176k
    if( ( line_string_segment_index >= line_string_segment_size )
818
115k
     || ( line_string_segment[ line_string_segment_index ] == 0 ) )
819
60.8k
    {
820
60.8k
      *line_index += 1;
821
822
60.8k
      continue;
823
60.8k
    }
824
    /* Make sure the value identifier is terminated by an end of string
825
     */
826
115k
    line_string_segment[ line_string_segment_index ] = 0;
827
828
115k
    line_string_segment_index++;
829
830
    /* Ignore whitespace
831
     */
832
249k
    while( line_string_segment_index < line_string_segment_size )
833
223k
    {
834
223k
      if( ( line_string_segment[ line_string_segment_index ] != '\t' )
835
212k
       && ( line_string_segment[ line_string_segment_index ] != '\n' )
836
205k
       && ( line_string_segment[ line_string_segment_index ] != '\f' )
837
177k
       && ( line_string_segment[ line_string_segment_index ] != '\v' )
838
168k
       && ( line_string_segment[ line_string_segment_index ] != '\r' )
839
160k
       && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
840
89.6k
      {
841
89.6k
        break;
842
89.6k
      }
843
133k
      line_string_segment_index++;
844
133k
    }
845
115k
    if( line_string_segment[ line_string_segment_index ] == '=' )
846
24.6k
    {
847
24.6k
      line_string_segment_index++;
848
849
56.3k
      while( line_string_segment_index < line_string_segment_size )
850
53.1k
      {
851
53.1k
        if( ( line_string_segment[ line_string_segment_index ] != '\t' )
852
50.7k
         && ( line_string_segment[ line_string_segment_index ] != '\n' )
853
47.9k
         && ( line_string_segment[ line_string_segment_index ] != '\f' )
854
45.3k
         && ( line_string_segment[ line_string_segment_index ] != '\v' )
855
43.6k
         && ( line_string_segment[ line_string_segment_index ] != '\r' )
856
42.8k
         && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
857
21.4k
        {
858
21.4k
          break;
859
21.4k
        }
860
31.7k
        line_string_segment_index++;
861
31.7k
      }
862
24.6k
    }
863
    /* Skip a line not containing a value
864
     */
865
115k
    if( ( line_string_segment_index >= line_string_segment_size )
866
86.4k
     || ( line_string_segment[ line_string_segment_index ] == 0 ) )
867
36.2k
    {
868
36.2k
      *line_index += 1;
869
870
36.2k
      continue;
871
36.2k
    }
872
    /* Determine the value
873
     */
874
79.1k
    value        = &( line_string_segment[ line_string_segment_index ] );
875
79.1k
    value_length = line_string_segment_size - 1;
876
877
    /* Ingore quotes at the beginning of the value data
878
     */
879
79.1k
    if( ( line_string_segment[ line_string_segment_index ] == '"' )
880
70.4k
     || ( line_string_segment[ line_string_segment_index ] == '\'' ) )
881
12.4k
    {
882
12.4k
      line_string_segment_index++;
883
12.4k
      value++;
884
12.4k
      value_length--;
885
12.4k
    }
886
    /* Ingore quotes at the end of the value data
887
     */
888
79.1k
    if( ( line_string_segment[ value_length - 1 ] == '"' )
889
73.8k
     || ( line_string_segment[ value_length - 1 ] == '\'' ) )
890
7.45k
    {
891
7.45k
      value_length--;
892
7.45k
    }
893
    /* Make sure the value is terminated by an end of string
894
     */
895
79.1k
    line_string_segment[ value_length ] = 0;
896
897
79.1k
    value_length -= line_string_segment_index;
898
899
79.1k
    if( value_identifier_length == 2 )
900
21.6k
    {
901
21.6k
      if( narrow_string_compare(
902
21.6k
           value_identifier,
903
21.6k
           "id",
904
21.6k
           2 ) == 0 )
905
1.34k
      {
906
1.34k
        if( libvslvm_volume_group_set_identifier(
907
1.34k
             metadata->volume_group,
908
1.34k
             value,
909
1.34k
             value_length + 1,
910
1.34k
             error ) != 1 )
911
79
        {
912
79
          libcerror_error_set(
913
79
           error,
914
79
           LIBCERROR_ERROR_DOMAIN_RUNTIME,
915
79
           LIBCERROR_RUNTIME_ERROR_SET_FAILED,
916
79
           "%s: unable to set volume group identifier.",
917
79
           function );
918
919
79
          goto on_error;
920
79
        }
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
1.34k
      }
931
21.6k
    }
932
57.5k
    else if( value_identifier_length == 5 )
933
7.77k
    {
934
7.77k
      if( narrow_string_compare(
935
7.77k
           value_identifier,
936
7.77k
           "flags",
937
7.77k
           5 ) == 0 )
938
2.82k
      {
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.82k
      }
950
4.95k
      else if( narrow_string_compare(
951
4.95k
                value_identifier,
952
4.95k
                "seqno",
953
4.95k
                5 ) == 0 )
954
1.15k
      {
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.15k
        if( libfvalue_utf8_string_copy_to_integer(
965
1.15k
             (uint8_t *) value,
966
1.15k
             value_length + 1,
967
1.15k
             &value_64bit,
968
1.15k
             32,
969
1.15k
             LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED,
970
1.15k
             error ) != 1 )
971
16
        {
972
16
          libcerror_error_set(
973
16
           error,
974
16
           LIBCERROR_ERROR_DOMAIN_MEMORY,
975
16
           LIBCERROR_MEMORY_ERROR_SET_FAILED,
976
16
           "%s: unable to set sequence number.",
977
16
           function );
978
979
16
          goto on_error;
980
16
        }
981
1.13k
        if( value_64bit > (uint64_t) UINT32_MAX )
982
17
        {
983
17
          libcerror_error_set(
984
17
           error,
985
17
           LIBCERROR_ERROR_DOMAIN_RUNTIME,
986
17
           LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
987
17
           "%s: invalid sequence number value exceeds maximum.",
988
17
           function );
989
990
17
          goto on_error;
991
17
        }
992
1.11k
        internal_volume_group->sequence_number = (uint32_t) value_64bit;
993
1.11k
      }
994
7.77k
    }
995
49.7k
    else if( value_identifier_length == 6 )
996
6.53k
    {
997
6.53k
      if( narrow_string_compare(
998
6.53k
           value_identifier,
999
6.53k
           "max_lv",
1000
6.53k
           6 ) == 0 )
1001
1.77k
      {
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.77k
      }
1013
4.76k
      else if( narrow_string_compare(
1014
4.76k
                value_identifier,
1015
4.76k
                "max_pv",
1016
4.76k
                6 ) == 0 )
1017
1.37k
      {
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.37k
      }
1029
3.38k
      else if( narrow_string_compare(
1030
3.38k
                value_identifier,
1031
3.38k
                "status",
1032
3.38k
                6 ) == 0 )
1033
794
      {
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
794
      }
1045
6.53k
    }
1046
43.2k
    else if( value_identifier_length == 11 )
1047
6.76k
    {
1048
6.76k
      if( narrow_string_compare(
1049
6.76k
           value_identifier,
1050
6.76k
           "extent_size",
1051
6.76k
           11 ) == 0 )
1052
5.42k
      {
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
5.42k
        if( libfvalue_utf8_string_copy_to_integer(
1063
5.42k
             (uint8_t *) value,
1064
5.42k
             value_length + 1,
1065
5.42k
             &value_64bit,
1066
5.42k
             64,
1067
5.42k
             LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED,
1068
5.42k
             error ) != 1 )
1069
27
        {
1070
27
          libcerror_error_set(
1071
27
           error,
1072
27
           LIBCERROR_ERROR_DOMAIN_MEMORY,
1073
27
           LIBCERROR_MEMORY_ERROR_SET_FAILED,
1074
27
           "%s: unable to set extent size.",
1075
27
           function );
1076
1077
27
          goto on_error;
1078
27
        }
1079
5.39k
        if( value_64bit > (uint64_t) ( UINT64_MAX / 512 ) )
1080
33
        {
1081
33
          libcerror_error_set(
1082
33
           error,
1083
33
           LIBCERROR_ERROR_DOMAIN_RUNTIME,
1084
33
           LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
1085
33
           "%s: invalid extent size value exceeds maximum.",
1086
33
           function );
1087
1088
33
          goto on_error;
1089
33
        }
1090
5.36k
        value_64bit *= 512;
1091
1092
5.36k
        internal_volume_group->extent_size = value_64bit;
1093
5.36k
      }
1094
6.76k
    }
1095
36.4k
    else if( value_identifier_length == 15 )
1096
1.93k
    {
1097
1.93k
      if( narrow_string_compare(
1098
1.93k
           value_identifier,
1099
1.93k
           "metadata_copies",
1100
1.93k
           15 ) == 0 )
1101
599
      {
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
599
      }
1113
1.93k
    }
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
78.9k
    *line_index += 1;
1126
78.9k
  }
1127
#if defined( HAVE_DEBUG_OUTPUT )
1128
  if( libcnotify_verbose != 0 )
1129
  {
1130
    libcnotify_printf(
1131
     "\n" );
1132
  }
1133
#endif
1134
5.31k
  return( 1 );
1135
1136
1.44k
on_error:
1137
1.44k
  if( metadata->volume_group != NULL )
1138
1.21k
  {
1139
1.21k
    libvslvm_internal_volume_group_free(
1140
1.21k
     (libvslvm_internal_volume_group_t **) &( metadata->volume_group ),
1141
1.21k
     NULL );
1142
1.21k
  }
1143
1.44k
  return( -1 );
1144
6.52k
}
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
4.01k
{
1157
4.01k
  char *line_string_segment        = NULL;
1158
4.01k
  static char *function            = "libvslvm_metadata_read_physical_volumes";
1159
4.01k
  size_t line_string_segment_index = 0;
1160
4.01k
  size_t line_string_segment_size  = 0;
1161
1162
4.01k
  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
4.01k
  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
4.01k
  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
4.01k
  if( ( *line_index < 0 )
1196
4.01k
   || ( *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
4.01k
  if( libcsplit_narrow_split_string_get_segment_by_index(
1208
4.01k
       lines,
1209
4.01k
       *line_index,
1210
4.01k
       &line_string_segment,
1211
4.01k
       &line_string_segment_size,
1212
4.01k
       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
4.01k
  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
4.01k
  if( line_string_segment_size >= 2 )
1239
4.01k
  {
1240
4.01k
    line_string_segment_index = line_string_segment_size - 2;
1241
1242
34.3k
    while( line_string_segment_index > 0 )
1243
34.3k
    {
1244
34.3k
      if( ( line_string_segment[ line_string_segment_index ] != '\t' )
1245
31.8k
       && ( line_string_segment[ line_string_segment_index ] != '\n' )
1246
31.8k
       && ( line_string_segment[ line_string_segment_index ] != '\f' )
1247
28.9k
       && ( line_string_segment[ line_string_segment_index ] != '\v' )
1248
21.5k
       && ( line_string_segment[ line_string_segment_index ] != '\r' )
1249
17.8k
       && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
1250
4.01k
      {
1251
4.01k
        break;
1252
4.01k
      }
1253
30.3k
      line_string_segment_index--;
1254
30.3k
      line_string_segment_size--;
1255
30.3k
    }
1256
4.01k
  }
1257
  /* Ignore leading white space
1258
   */
1259
4.01k
  line_string_segment_index = 0;
1260
1261
834k
  while( line_string_segment_index < line_string_segment_size )
1262
834k
  {
1263
834k
    if( ( line_string_segment[ line_string_segment_index ] != '\t' )
1264
829k
     && ( line_string_segment[ line_string_segment_index ] != '\n' )
1265
829k
     && ( line_string_segment[ line_string_segment_index ] != '\f' )
1266
825k
     && ( line_string_segment[ line_string_segment_index ] != '\v' )
1267
823k
     && ( line_string_segment[ line_string_segment_index ] != '\r' )
1268
754k
     && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
1269
4.01k
    {
1270
4.01k
      break;
1271
4.01k
    }
1272
830k
    line_string_segment_index++;
1273
830k
  }
1274
4.01k
  if( ( ( line_string_segment_size - line_string_segment_index ) != 19 )
1275
4.01k
   || ( narrow_string_compare(
1276
4.01k
         &( line_string_segment[ line_string_segment_index ] ),
1277
4.01k
         "physical_volumes {",
1278
4.01k
         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
4.01k
  *line_index += 1;
1290
1291
1.41M
  while( *line_index < number_of_lines )
1292
1.41M
  {
1293
1.41M
    if( libcsplit_narrow_split_string_get_segment_by_index(
1294
1.41M
         lines,
1295
1.41M
         *line_index,
1296
1.41M
         &line_string_segment,
1297
1.41M
         &line_string_segment_size,
1298
1.41M
         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.41M
    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.41M
    if( line_string_segment_size >= 2 )
1325
112k
    {
1326
112k
      line_string_segment_index = line_string_segment_size - 2;
1327
1328
225k
      while( line_string_segment_index > 0 )
1329
206k
      {
1330
206k
        if( ( line_string_segment[ line_string_segment_index ] != '\t' )
1331
191k
         && ( line_string_segment[ line_string_segment_index ] != '\n' )
1332
181k
         && ( line_string_segment[ line_string_segment_index ] != '\f' )
1333
168k
         && ( line_string_segment[ line_string_segment_index ] != '\v' )
1334
116k
         && ( line_string_segment[ line_string_segment_index ] != '\r' )
1335
111k
         && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
1336
93.3k
        {
1337
93.3k
          break;
1338
93.3k
        }
1339
113k
        line_string_segment_index--;
1340
113k
        line_string_segment_size--;
1341
113k
      }
1342
112k
    }
1343
    /* Ignore leading white space
1344
     */
1345
1.41M
    line_string_segment_index = 0;
1346
1347
1.51M
    while( line_string_segment_index < line_string_segment_size )
1348
1.51M
    {
1349
1.51M
      if( ( line_string_segment[ line_string_segment_index ] != '\t' )
1350
1.50M
       && ( line_string_segment[ line_string_segment_index ] != '\n' )
1351
1.50M
       && ( line_string_segment[ line_string_segment_index ] != '\f' )
1352
1.49M
       && ( line_string_segment[ line_string_segment_index ] != '\v' )
1353
1.44M
       && ( line_string_segment[ line_string_segment_index ] != '\r' )
1354
1.44M
       && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
1355
1.41M
      {
1356
1.41M
        break;
1357
1.41M
      }
1358
105k
      line_string_segment_index++;
1359
105k
    }
1360
    /* Skip an empty line
1361
     */
1362
1.41M
    if( ( line_string_segment_index >= line_string_segment_size )
1363
1.41M
     || ( line_string_segment[ line_string_segment_index ] == 0 ) )
1364
1.30M
    {
1365
1.30M
      *line_index += 1;
1366
1367
1.30M
      continue;
1368
1.30M
    }
1369
    /* Check for the end of section
1370
     */
1371
109k
    if( ( ( line_string_segment_size - line_string_segment_index ) == 2 )
1372
19.5k
     && ( line_string_segment[ line_string_segment_index ] == '}' ) )
1373
2.41k
    {
1374
2.41k
      *line_index += 1;
1375
1376
2.41k
      break;
1377
2.41k
    }
1378
    /* Check for the start of a sub section
1379
     */
1380
107k
    if( ( line_string_segment_size >= 3 )
1381
93.0k
     && ( line_string_segment[ line_string_segment_size - 3 ] == ' ' )
1382
69.7k
     && ( line_string_segment[ line_string_segment_size - 2 ] == '{' ) )
1383
58.0k
    {
1384
58.0k
      if( libvslvm_metadata_read_physical_volume(
1385
58.0k
           metadata,
1386
58.0k
           volume_group,
1387
58.0k
           lines,
1388
58.0k
           number_of_lines,
1389
58.0k
           line_index,
1390
58.0k
           error ) != 1 )
1391
188
      {
1392
188
        libcerror_error_set(
1393
188
         error,
1394
188
         LIBCERROR_ERROR_DOMAIN_IO,
1395
188
         LIBCERROR_IO_ERROR_READ_FAILED,
1396
188
         "%s: unable to read physical volume.",
1397
188
         function );
1398
1399
188
        return( -1 );
1400
188
      }
1401
58.0k
    }
1402
49.3k
    else
1403
49.3k
    {
1404
/* TODO debug print other lines ? */
1405
49.3k
      *line_index += 1;
1406
49.3k
    }
1407
107k
  }
1408
3.82k
  return( 1 );
1409
4.01k
}
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
58.0k
{
1422
58.0k
  libvslvm_physical_volume_t *physical_volume = NULL;
1423
58.0k
  char *line_string_segment                   = NULL;
1424
58.0k
  char *value                                 = NULL;
1425
58.0k
  char *value_identifier                      = NULL;
1426
58.0k
  static char *function                       = "libvslvm_metadata_read_physical_volume";
1427
58.0k
  size_t line_string_segment_index            = 0;
1428
58.0k
  size_t line_string_segment_size             = 0;
1429
58.0k
  size_t value_identifier_length              = 0;
1430
58.0k
  size_t value_length                         = 0;
1431
58.0k
  uint64_t value_64bit                        = 0;
1432
1433
58.0k
  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
58.0k
  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
58.0k
  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
58.0k
  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
58.0k
  if( ( *line_index < 0 )
1478
58.0k
   || ( *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
58.0k
  if( libcsplit_narrow_split_string_get_segment_by_index(
1490
58.0k
       lines,
1491
58.0k
       *line_index,
1492
58.0k
       &line_string_segment,
1493
58.0k
       &line_string_segment_size,
1494
58.0k
       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
58.0k
  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
58.0k
  if( line_string_segment_size >= 2 )
1521
58.0k
  {
1522
58.0k
    line_string_segment_index = line_string_segment_size - 2;
1523
1524
106k
    while( line_string_segment_index > 0 )
1525
106k
    {
1526
106k
      if( ( line_string_segment[ line_string_segment_index ] != '\t' )
1527
103k
       && ( line_string_segment[ line_string_segment_index ] != '\n' )
1528
98.5k
       && ( line_string_segment[ line_string_segment_index ] != '\f' )
1529
95.8k
       && ( line_string_segment[ line_string_segment_index ] != '\v' )
1530
65.2k
       && ( line_string_segment[ line_string_segment_index ] != '\r' )
1531
63.0k
       && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
1532
58.0k
      {
1533
58.0k
        break;
1534
58.0k
      }
1535
47.9k
      line_string_segment_index--;
1536
47.9k
      line_string_segment_size--;
1537
47.9k
    }
1538
58.0k
  }
1539
  /* Ignore leading white space
1540
   */
1541
58.0k
  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
121k
     && ( line_string_segment[ line_string_segment_index ] != '\n' )
1547
121k
     && ( line_string_segment[ line_string_segment_index ] != '\f' )
1548
119k
     && ( line_string_segment[ line_string_segment_index ] != '\v' )
1549
80.4k
     && ( line_string_segment[ line_string_segment_index ] != '\r' )
1550
77.7k
     && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
1551
58.0k
    {
1552
58.0k
      break;
1553
58.0k
    }
1554
71.2k
    line_string_segment_index++;
1555
71.2k
  }
1556
58.0k
  if( ( line_string_segment_size < 3 )
1557
58.0k
   || ( line_string_segment[ line_string_segment_size - 3 ] != ' ' )
1558
58.0k
   || ( 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
58.0k
  if( libvslvm_physical_volume_initialize(
1570
58.0k
       &physical_volume,
1571
58.0k
       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
58.0k
  if( ( line_string_segment_size < 2 )
1583
58.0k
   || ( line_string_segment_index >= ( line_string_segment_size - 2 ) ) )
1584
9
  {
1585
9
    libcerror_error_set(
1586
9
     error,
1587
9
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1588
9
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
1589
9
     "%s: invalid line string segment size value out of bounds.",
1590
9
     function );
1591
1592
9
    goto on_error;
1593
9
  }
1594
58.0k
  if( libvslvm_physical_volume_set_name(
1595
58.0k
       physical_volume,
1596
58.0k
       &( line_string_segment[ line_string_segment_index ] ),
1597
58.0k
       line_string_segment_size - ( line_string_segment_index + 2 ),
1598
58.0k
       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
58.0k
  *line_index += 1;
1622
1623
7.91M
  while( *line_index < number_of_lines )
1624
7.91M
  {
1625
7.91M
    if( libcsplit_narrow_split_string_get_segment_by_index(
1626
7.91M
         lines,
1627
7.91M
         *line_index,
1628
7.91M
         &line_string_segment,
1629
7.91M
         &line_string_segment_size,
1630
7.91M
         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
7.91M
    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
7.91M
    if( line_string_segment_size >= 2 )
1657
245k
    {
1658
245k
      line_string_segment_index = line_string_segment_size - 2;
1659
1660
520k
      while( line_string_segment_index > 0 )
1661
418k
      {
1662
418k
        if( ( line_string_segment[ line_string_segment_index ] != '\t' )
1663
407k
         && ( line_string_segment[ line_string_segment_index ] != '\n' )
1664
374k
         && ( line_string_segment[ line_string_segment_index ] != '\f' )
1665
341k
         && ( line_string_segment[ line_string_segment_index ] != '\v' )
1666
270k
         && ( line_string_segment[ line_string_segment_index ] != '\r' )
1667
255k
         && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
1668
143k
        {
1669
143k
          break;
1670
143k
        }
1671
275k
        line_string_segment_index--;
1672
275k
        line_string_segment_size--;
1673
275k
      }
1674
245k
    }
1675
    /* Ignore leading white space
1676
     */
1677
7.91M
    line_string_segment_index = 0;
1678
1679
8.22M
    while( line_string_segment_index < line_string_segment_size )
1680
8.21M
    {
1681
8.21M
      if( ( line_string_segment[ line_string_segment_index ] != '\t' )
1682
8.20M
       && ( line_string_segment[ line_string_segment_index ] != '\n' )
1683
8.20M
       && ( line_string_segment[ line_string_segment_index ] != '\f' )
1684
8.18M
       && ( line_string_segment[ line_string_segment_index ] != '\v' )
1685
8.07M
       && ( line_string_segment[ line_string_segment_index ] != '\r' )
1686
8.01M
       && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
1687
7.90M
      {
1688
7.90M
        break;
1689
7.90M
      }
1690
311k
      line_string_segment_index++;
1691
311k
    }
1692
    /* Skip an empty line
1693
     */
1694
7.91M
    if( ( line_string_segment_index >= line_string_segment_size )
1695
7.90M
     || ( line_string_segment[ line_string_segment_index ] == 0 ) )
1696
7.68M
    {
1697
7.68M
      *line_index += 1;
1698
1699
7.68M
      continue;
1700
7.68M
    }
1701
    /* Check for the end of section
1702
     */
1703
227k
    if( ( ( line_string_segment_size - line_string_segment_index ) == 2 )
1704
113k
     && ( line_string_segment[ line_string_segment_index ] == '}' ) )
1705
56.6k
    {
1706
56.6k
      *line_index += 1;
1707
1708
56.6k
      break;
1709
56.6k
    }
1710
    /* Determine the value identifier
1711
     */
1712
171k
    value_identifier        = &( line_string_segment[ line_string_segment_index ] );
1713
171k
    value_identifier_length = 0;
1714
1715
10.5M
    while( line_string_segment_index < line_string_segment_size )
1716
10.5M
    {
1717
10.5M
      if( ( line_string_segment[ line_string_segment_index ] == '\t' )
1718
10.5M
       || ( line_string_segment[ line_string_segment_index ] == '\n' )
1719
10.5M
       || ( line_string_segment[ line_string_segment_index ] == '\f' )
1720
10.5M
       || ( line_string_segment[ line_string_segment_index ] == '\v' )
1721
10.5M
       || ( line_string_segment[ line_string_segment_index ] == '\r' )
1722
10.5M
       || ( line_string_segment[ line_string_segment_index ] == ' ' )
1723
10.4M
       || ( line_string_segment[ line_string_segment_index ] == '=' ) )
1724
120k
      {
1725
120k
        break;
1726
120k
      }
1727
10.4M
      value_identifier_length++;
1728
1729
10.4M
      line_string_segment_index++;
1730
10.4M
    }
1731
    /* Skip a line not containing a value
1732
     */
1733
171k
    if( ( line_string_segment_index >= line_string_segment_size )
1734
120k
     || ( line_string_segment[ line_string_segment_index ] == 0 ) )
1735
50.2k
    {
1736
50.2k
      *line_index += 1;
1737
1738
50.2k
      continue;
1739
50.2k
    }
1740
    /* Make sure the value identifier is terminated by an end of string
1741
     */
1742
120k
    line_string_segment[ line_string_segment_index ] = 0;
1743
1744
120k
    line_string_segment_index++;
1745
1746
    /* Ignore whitespace
1747
     */
1748
202k
    while( line_string_segment_index < line_string_segment_size )
1749
163k
    {
1750
163k
      if( ( line_string_segment[ line_string_segment_index ] != '\t' )
1751
149k
       && ( line_string_segment[ line_string_segment_index ] != '\n' )
1752
142k
       && ( line_string_segment[ line_string_segment_index ] != '\f' )
1753
122k
       && ( line_string_segment[ line_string_segment_index ] != '\v' )
1754
110k
       && ( line_string_segment[ line_string_segment_index ] != '\r' )
1755
106k
       && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
1756
81.8k
      {
1757
81.8k
        break;
1758
81.8k
      }
1759
81.6k
      line_string_segment_index++;
1760
81.6k
    }
1761
120k
    if( line_string_segment[ line_string_segment_index ] == '=' )
1762
23.9k
    {
1763
23.9k
      line_string_segment_index++;
1764
1765
61.3k
      while( line_string_segment_index < line_string_segment_size )
1766
59.3k
      {
1767
59.3k
        if( ( line_string_segment[ line_string_segment_index ] != '\t' )
1768
57.0k
         && ( line_string_segment[ line_string_segment_index ] != '\n' )
1769
48.4k
         && ( line_string_segment[ line_string_segment_index ] != '\f' )
1770
46.7k
         && ( line_string_segment[ line_string_segment_index ] != '\v' )
1771
43.7k
         && ( line_string_segment[ line_string_segment_index ] != '\r' )
1772
42.9k
         && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
1773
21.9k
        {
1774
21.9k
          break;
1775
21.9k
        }
1776
37.3k
        line_string_segment_index++;
1777
37.3k
      }
1778
23.9k
    }
1779
    /* Skip a line not containing a value
1780
     */
1781
120k
    if( ( line_string_segment_index >= line_string_segment_size )
1782
79.8k
     || ( line_string_segment[ line_string_segment_index ] == 0 ) )
1783
44.5k
    {
1784
44.5k
      *line_index += 1;
1785
1786
44.5k
      continue;
1787
44.5k
    }
1788
    /* Determine the value
1789
     */
1790
76.1k
    value        = &( line_string_segment[ line_string_segment_index ] );
1791
76.1k
    value_length = line_string_segment_size - 1;
1792
1793
    /* Ingore quotes at the beginning of the value data
1794
     */
1795
76.1k
    if( ( line_string_segment[ line_string_segment_index ] == '"' )
1796
66.8k
     || ( line_string_segment[ line_string_segment_index ] == '\'' ) )
1797
12.3k
    {
1798
12.3k
      line_string_segment_index++;
1799
12.3k
      value++;
1800
12.3k
      value_length--;
1801
12.3k
    }
1802
    /* Ingore quotes at the end of the value data
1803
     */
1804
76.1k
    if( ( line_string_segment[ value_length - 1 ] == '"' )
1805
71.0k
     || ( line_string_segment[ value_length - 1 ] == '\'' ) )
1806
6.62k
    {
1807
6.62k
      value_length--;
1808
6.62k
    }
1809
    /* Make sure the value is terminated by an end of string
1810
     */
1811
76.1k
    line_string_segment[ value_length ] = 0;
1812
1813
76.1k
    value_length -= line_string_segment_index;
1814
1815
76.1k
    if( value_identifier_length == 2 )
1816
13.0k
    {
1817
13.0k
      if( narrow_string_compare(
1818
13.0k
           value_identifier,
1819
13.0k
           "id",
1820
13.0k
           2 ) == 0 )
1821
1.92k
      {
1822
1.92k
        if( libvslvm_physical_volume_set_identifier(
1823
1.92k
             physical_volume,
1824
1.92k
             value,
1825
1.92k
             value_length + 1,
1826
1.92k
             error ) != 1 )
1827
86
        {
1828
86
          libcerror_error_set(
1829
86
           error,
1830
86
           LIBCERROR_ERROR_DOMAIN_RUNTIME,
1831
86
           LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1832
86
           "%s: unable to set physical volume identifier.",
1833
86
           function );
1834
1835
86
          goto on_error;
1836
86
        }
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.92k
      }
1847
13.0k
    }
1848
63.1k
    else if( value_identifier_length == 5 )
1849
5.35k
    {
1850
5.35k
      if( narrow_string_compare(
1851
5.35k
           value_identifier,
1852
5.35k
           "flags",
1853
5.35k
           5 ) == 0 )
1854
2.16k
      {
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
2.16k
      }
1866
5.35k
    }
1867
57.8k
    else if( value_identifier_length == 6 )
1868
7.63k
    {
1869
7.63k
      if( narrow_string_compare(
1870
7.63k
           value_identifier,
1871
7.63k
           "device",
1872
7.63k
           6 ) == 0 )
1873
1.35k
      {
1874
1.35k
        if( libvslvm_physical_volume_set_device_path(
1875
1.35k
             physical_volume,
1876
1.35k
             value,
1877
1.35k
             value_length + 1,
1878
1.35k
             error ) != 1 )
1879
5
        {
1880
5
          libcerror_error_set(
1881
5
           error,
1882
5
           LIBCERROR_ERROR_DOMAIN_RUNTIME,
1883
5
           LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1884
5
           "%s: unable to set physical volume device path.",
1885
5
           function );
1886
1887
5
          goto on_error;
1888
5
        }
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.35k
      }
1899
6.27k
      else if( narrow_string_compare(
1900
6.27k
                value_identifier,
1901
6.27k
                "status",
1902
6.27k
                6 ) == 0 )
1903
1.40k
      {
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.40k
      }
1915
1916
7.63k
    }
1917
50.2k
    else if( value_identifier_length == 8 )
1918
6.24k
    {
1919
6.24k
      if( narrow_string_compare(
1920
6.24k
           value_identifier,
1921
6.24k
           "dev_size",
1922
6.24k
           8 ) == 0 )
1923
1.78k
      {
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.78k
        if( libfvalue_utf8_string_copy_to_integer(
1934
1.78k
             (uint8_t *) value,
1935
1.78k
             value_length + 1,
1936
1.78k
             &value_64bit,
1937
1.78k
             64,
1938
1.78k
             LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED,
1939
1.78k
             error ) != 1 )
1940
21
        {
1941
21
          libcerror_error_set(
1942
21
           error,
1943
21
           LIBCERROR_ERROR_DOMAIN_MEMORY,
1944
21
           LIBCERROR_MEMORY_ERROR_SET_FAILED,
1945
21
           "%s: unable to set volume size.",
1946
21
           function );
1947
1948
21
          goto on_error;
1949
21
        }
1950
1.76k
        if( value_64bit > (uint64_t) ( UINT64_MAX / 512 ) )
1951
67
        {
1952
67
          libcerror_error_set(
1953
67
           error,
1954
67
           LIBCERROR_ERROR_DOMAIN_RUNTIME,
1955
67
           LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
1956
67
           "%s: invalid volume size value exceeds maximum.",
1957
67
           function );
1958
1959
67
          goto on_error;
1960
67
        }
1961
1.69k
        value_64bit *= 512;
1962
1963
1.69k
        ( (libvslvm_internal_physical_volume_t *) physical_volume )->size = value_64bit;
1964
1.69k
      }
1965
4.45k
      else if( narrow_string_compare(
1966
4.45k
                value_identifier,
1967
4.45k
                "pe_count",
1968
4.45k
                8 ) == 0 )
1969
924
      {
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
924
      }
1981
3.53k
      else if( narrow_string_compare(
1982
3.53k
                value_identifier,
1983
3.53k
                "pe_start",
1984
3.53k
                8 ) == 0 )
1985
940
      {
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
940
      }
1997
6.24k
    }
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
76.0k
    *line_index += 1;
2010
76.0k
  }
2011
57.8k
  if( libvslvm_volume_group_append_physical_volume(
2012
57.8k
       volume_group,
2013
57.8k
       physical_volume,
2014
57.8k
       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.8k
  physical_volume = NULL;
2026
2027
57.8k
  return( 1 );
2028
2029
188
on_error:
2030
188
  if( physical_volume != NULL )
2031
188
  {
2032
188
    libvslvm_internal_physical_volume_free(
2033
188
     (libvslvm_internal_physical_volume_t **) &physical_volume,
2034
188
     NULL );
2035
188
  }
2036
188
  return( -1 );
2037
57.8k
}
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
6.19k
{
2050
6.19k
  char *line_string_segment        = NULL;
2051
6.19k
  static char *function            = "libvslvm_metadata_read_logical_volumes";
2052
6.19k
  size_t line_string_segment_index = 0;
2053
6.19k
  size_t line_string_segment_size  = 0;
2054
2055
6.19k
  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
6.19k
  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
6.19k
  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
6.19k
  if( ( *line_index < 0 )
2089
6.19k
   || ( *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
6.19k
  if( libcsplit_narrow_split_string_get_segment_by_index(
2101
6.19k
       lines,
2102
6.19k
       *line_index,
2103
6.19k
       &line_string_segment,
2104
6.19k
       &line_string_segment_size,
2105
6.19k
       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
6.19k
  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
6.19k
  if( line_string_segment_size >= 2 )
2132
6.19k
  {
2133
6.19k
    line_string_segment_index = line_string_segment_size - 2;
2134
2135
20.4k
    while( line_string_segment_index > 0 )
2136
20.4k
    {
2137
20.4k
      if( ( line_string_segment[ line_string_segment_index ] != '\t' )
2138
19.1k
       && ( line_string_segment[ line_string_segment_index ] != '\n' )
2139
19.1k
       && ( line_string_segment[ line_string_segment_index ] != '\f' )
2140
16.8k
       && ( line_string_segment[ line_string_segment_index ] != '\v' )
2141
13.6k
       && ( line_string_segment[ line_string_segment_index ] != '\r' )
2142
12.6k
       && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
2143
6.19k
      {
2144
6.19k
        break;
2145
6.19k
      }
2146
14.2k
      line_string_segment_index--;
2147
14.2k
      line_string_segment_size--;
2148
14.2k
    }
2149
6.19k
  }
2150
  /* Ignore leading white space
2151
   */
2152
6.19k
  line_string_segment_index = 0;
2153
2154
1.15M
  while( line_string_segment_index < line_string_segment_size )
2155
1.15M
  {
2156
1.15M
    if( ( line_string_segment[ line_string_segment_index ] != '\t' )
2157
1.15M
     && ( line_string_segment[ line_string_segment_index ] != '\n' )
2158
1.15M
     && ( line_string_segment[ line_string_segment_index ] != '\f' )
2159
1.14M
     && ( line_string_segment[ line_string_segment_index ] != '\v' )
2160
1.14M
     && ( line_string_segment[ line_string_segment_index ] != '\r' )
2161
1.13M
     && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
2162
6.19k
    {
2163
6.19k
      break;
2164
6.19k
    }
2165
1.14M
    line_string_segment_index++;
2166
1.14M
  }
2167
6.19k
  if( ( ( line_string_segment_size - line_string_segment_index ) != 18 )
2168
6.19k
   || ( narrow_string_compare(
2169
6.19k
         &( line_string_segment[ line_string_segment_index ] ),
2170
6.19k
         "logical_volumes {",
2171
6.19k
         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
6.19k
  *line_index += 1;
2183
2184
2.36M
  while( *line_index < number_of_lines )
2185
2.36M
  {
2186
2.36M
    if( libcsplit_narrow_split_string_get_segment_by_index(
2187
2.36M
         lines,
2188
2.36M
         *line_index,
2189
2.36M
         &line_string_segment,
2190
2.36M
         &line_string_segment_size,
2191
2.36M
         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
2.36M
    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
2.36M
    if( line_string_segment_size >= 2 )
2218
92.4k
    {
2219
92.4k
      line_string_segment_index = line_string_segment_size - 2;
2220
2221
252k
      while( line_string_segment_index > 0 )
2222
230k
      {
2223
230k
        if( ( line_string_segment[ line_string_segment_index ] != '\t' )
2224
215k
         && ( line_string_segment[ line_string_segment_index ] != '\n' )
2225
194k
         && ( line_string_segment[ line_string_segment_index ] != '\f' )
2226
180k
         && ( line_string_segment[ line_string_segment_index ] != '\v' )
2227
112k
         && ( line_string_segment[ line_string_segment_index ] != '\r' )
2228
105k
         && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
2229
70.5k
        {
2230
70.5k
          break;
2231
70.5k
        }
2232
160k
        line_string_segment_index--;
2233
160k
        line_string_segment_size--;
2234
160k
      }
2235
92.4k
    }
2236
    /* Ignore leading white space
2237
     */
2238
2.36M
    line_string_segment_index = 0;
2239
2240
2.45M
    while( line_string_segment_index < line_string_segment_size )
2241
2.45M
    {
2242
2.45M
      if( ( line_string_segment[ line_string_segment_index ] != '\t' )
2243
2.43M
       && ( line_string_segment[ line_string_segment_index ] != '\n' )
2244
2.43M
       && ( line_string_segment[ line_string_segment_index ] != '\f' )
2245
2.43M
       && ( line_string_segment[ line_string_segment_index ] != '\v' )
2246
2.39M
       && ( line_string_segment[ line_string_segment_index ] != '\r' )
2247
2.38M
       && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
2248
2.36M
      {
2249
2.36M
        break;
2250
2.36M
      }
2251
90.0k
      line_string_segment_index++;
2252
90.0k
    }
2253
    /* Skip an empty line
2254
     */
2255
2.36M
    if( ( line_string_segment_index >= line_string_segment_size )
2256
2.36M
     || ( line_string_segment[ line_string_segment_index ] == 0 ) )
2257
2.27M
    {
2258
2.27M
      *line_index += 1;
2259
2260
2.27M
      continue;
2261
2.27M
    }
2262
    /* Check for the end of section
2263
     */
2264
87.7k
    if( ( ( line_string_segment_size - line_string_segment_index ) == 2 )
2265
20.8k
     && ( line_string_segment[ line_string_segment_index ] == '}' ) )
2266
2.45k
    {
2267
2.45k
      *line_index += 1;
2268
2269
2.45k
      break;
2270
2.45k
    }
2271
    /* Check for the start of a sub section
2272
     */
2273
85.3k
    if( ( line_string_segment_size >= 3 )
2274
70.3k
     && ( line_string_segment[ line_string_segment_size - 3 ] == ' ' )
2275
43.7k
     && ( line_string_segment[ line_string_segment_size - 2 ] == '{' ) )
2276
32.5k
    {
2277
32.5k
      if( libvslvm_metadata_read_logical_volume(
2278
32.5k
           metadata,
2279
32.5k
           volume_group,
2280
32.5k
           lines,
2281
32.5k
           number_of_lines,
2282
32.5k
           line_index,
2283
32.5k
           error ) != 1 )
2284
849
      {
2285
849
        libcerror_error_set(
2286
849
         error,
2287
849
         LIBCERROR_ERROR_DOMAIN_IO,
2288
849
         LIBCERROR_IO_ERROR_READ_FAILED,
2289
849
         "%s: unable to read logical volume.",
2290
849
         function );
2291
2292
849
        return( -1 );
2293
849
      }
2294
32.5k
    }
2295
52.7k
    else
2296
52.7k
    {
2297
/* TODO debug print other lines ? */
2298
52.7k
      *line_index += 1;
2299
52.7k
    }
2300
85.3k
  }
2301
5.34k
  return( 1 );
2302
6.19k
}
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
32.5k
{
2315
32.5k
  libvslvm_logical_volume_values_t *logical_volume_values = NULL;
2316
32.5k
  char *line_string_segment                               = NULL;
2317
32.5k
  char *value                                             = NULL;
2318
32.5k
  char *value_identifier                                  = NULL;
2319
32.5k
  static char *function                                   = "libvslvm_metadata_read_logical_volume";
2320
32.5k
  size_t line_string_segment_index                        = 0;
2321
32.5k
  size_t line_string_segment_size                         = 0;
2322
32.5k
  size_t value_identifier_length                          = 0;
2323
32.5k
  size_t value_length                                     = 0;
2324
2325
32.5k
  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
32.5k
  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
32.5k
  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
32.5k
  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
32.5k
  if( ( *line_index < 0 )
2370
32.5k
   || ( *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
32.5k
  if( libcsplit_narrow_split_string_get_segment_by_index(
2382
32.5k
       lines,
2383
32.5k
       *line_index,
2384
32.5k
       &line_string_segment,
2385
32.5k
       &line_string_segment_size,
2386
32.5k
       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
32.5k
  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
32.5k
  if( line_string_segment_size >= 2 )
2413
32.5k
  {
2414
32.5k
    line_string_segment_index = line_string_segment_size - 2;
2415
2416
106k
    while( line_string_segment_index > 0 )
2417
106k
    {
2418
106k
      if( ( line_string_segment[ line_string_segment_index ] != '\t' )
2419
105k
       && ( line_string_segment[ line_string_segment_index ] != '\n' )
2420
90.5k
       && ( line_string_segment[ line_string_segment_index ] != '\f' )
2421
87.4k
       && ( line_string_segment[ line_string_segment_index ] != '\v' )
2422
44.3k
       && ( line_string_segment[ line_string_segment_index ] != '\r' )
2423
42.2k
       && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
2424
32.5k
      {
2425
32.5k
        break;
2426
32.5k
      }
2427
74.2k
      line_string_segment_index--;
2428
74.2k
      line_string_segment_size--;
2429
74.2k
    }
2430
32.5k
  }
2431
  /* Ignore leading white space
2432
   */
2433
32.5k
  line_string_segment_index = 0;
2434
2435
84.2k
  while( line_string_segment_index < line_string_segment_size )
2436
84.2k
  {
2437
84.2k
    if( ( line_string_segment[ line_string_segment_index ] != '\t' )
2438
73.2k
     && ( line_string_segment[ line_string_segment_index ] != '\n' )
2439
73.2k
     && ( line_string_segment[ line_string_segment_index ] != '\f' )
2440
70.7k
     && ( line_string_segment[ line_string_segment_index ] != '\v' )
2441
49.2k
     && ( line_string_segment[ line_string_segment_index ] != '\r' )
2442
38.0k
     && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
2443
32.5k
    {
2444
32.5k
      break;
2445
32.5k
    }
2446
51.6k
    line_string_segment_index++;
2447
51.6k
  }
2448
32.5k
  if( ( line_string_segment_size < 3 )
2449
32.5k
   || ( line_string_segment[ line_string_segment_size - 3 ] != ' ' )
2450
32.5k
   || ( 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
32.5k
  if( libvslvm_logical_volume_values_initialize(
2462
32.5k
       &logical_volume_values,
2463
32.5k
       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
32.5k
  if( ( line_string_segment_size < 2 )
2475
32.5k
   || ( line_string_segment_index >= ( line_string_segment_size - 2 ) ) )
2476
10
  {
2477
10
    libcerror_error_set(
2478
10
     error,
2479
10
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2480
10
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
2481
10
     "%s: invalid line string segment size value out of bounds.",
2482
10
     function );
2483
2484
10
    goto on_error;
2485
10
  }
2486
32.5k
  if( libvslvm_logical_volume_values_set_name(
2487
32.5k
       logical_volume_values,
2488
32.5k
       &( line_string_segment[ line_string_segment_index ] ),
2489
32.5k
       line_string_segment_size - ( line_string_segment_index + 2 ),
2490
32.5k
       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
32.5k
  *line_index += 1;
2514
2515
10.9M
  while( *line_index < number_of_lines )
2516
10.9M
  {
2517
10.9M
    if( libcsplit_narrow_split_string_get_segment_by_index(
2518
10.9M
         lines,
2519
10.9M
         *line_index,
2520
10.9M
         &line_string_segment,
2521
10.9M
         &line_string_segment_size,
2522
10.9M
         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.9M
    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.9M
    if( line_string_segment_size >= 2 )
2549
235k
    {
2550
235k
      line_string_segment_index = line_string_segment_size - 2;
2551
2552
682k
      while( line_string_segment_index > 0 )
2553
604k
      {
2554
604k
        if( ( line_string_segment[ line_string_segment_index ] != '\t' )
2555
586k
         && ( line_string_segment[ line_string_segment_index ] != '\n' )
2556
532k
         && ( line_string_segment[ line_string_segment_index ] != '\f' )
2557
495k
         && ( line_string_segment[ line_string_segment_index ] != '\v' )
2558
431k
         && ( line_string_segment[ line_string_segment_index ] != '\r' )
2559
398k
         && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
2560
156k
        {
2561
156k
          break;
2562
156k
        }
2563
447k
        line_string_segment_index--;
2564
447k
        line_string_segment_size--;
2565
447k
      }
2566
235k
    }
2567
    /* Ignore leading white space
2568
     */
2569
10.9M
    line_string_segment_index = 0;
2570
2571
11.2M
    while( line_string_segment_index < line_string_segment_size )
2572
11.2M
    {
2573
11.2M
      if( ( line_string_segment[ line_string_segment_index ] != '\t' )
2574
11.2M
       && ( line_string_segment[ line_string_segment_index ] != '\n' )
2575
11.2M
       && ( line_string_segment[ line_string_segment_index ] != '\f' )
2576
11.2M
       && ( line_string_segment[ line_string_segment_index ] != '\v' )
2577
11.0M
       && ( line_string_segment[ line_string_segment_index ] != '\r' )
2578
11.0M
       && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
2579
10.9M
      {
2580
10.9M
        break;
2581
10.9M
      }
2582
302k
      line_string_segment_index++;
2583
302k
    }
2584
    /* Skip an empty line
2585
     */
2586
10.9M
    if( ( line_string_segment_index >= line_string_segment_size )
2587
10.9M
     || ( line_string_segment[ line_string_segment_index ] == 0 ) )
2588
10.7M
    {
2589
10.7M
      *line_index += 1;
2590
2591
10.7M
      continue;
2592
10.7M
    }
2593
    /* Check for the end of section
2594
     */
2595
211k
    if( ( ( line_string_segment_size - line_string_segment_index ) == 2 )
2596
91.2k
     && ( line_string_segment[ line_string_segment_index ] == '}' ) )
2597
29.1k
    {
2598
29.1k
      *line_index += 1;
2599
2600
29.1k
      break;
2601
29.1k
    }
2602
    /* Check for the start of a sub section
2603
     */
2604
182k
    if( ( line_string_segment_size >= 3 )
2605
132k
     && ( line_string_segment[ line_string_segment_size - 3 ] == ' ' )
2606
57.4k
     && ( line_string_segment[ line_string_segment_size - 2 ] == '{' )
2607
24.3k
     && ( ( line_string_segment_size - line_string_segment_index ) >= 7 )
2608
18.8k
     && ( narrow_string_compare(
2609
18.8k
           &( line_string_segment[ line_string_segment_index ] ),
2610
18.8k
           "segment",
2611
18.8k
           7 ) == 0 ) )
2612
3.99k
    {
2613
3.99k
      if( libvslvm_metadata_read_segment(
2614
3.99k
           metadata,
2615
3.99k
           logical_volume_values,
2616
3.99k
           lines,
2617
3.99k
           number_of_lines,
2618
3.99k
           line_index,
2619
3.99k
           error ) != 1 )
2620
759
      {
2621
759
        libcerror_error_set(
2622
759
         error,
2623
759
         LIBCERROR_ERROR_DOMAIN_IO,
2624
759
         LIBCERROR_IO_ERROR_READ_FAILED,
2625
759
         "%s: unable to read segment.",
2626
759
         function );
2627
2628
759
        goto on_error;
2629
759
      }
2630
3.23k
      continue;
2631
3.99k
    }
2632
    /* Determine the value identifier
2633
     */
2634
178k
    value_identifier        = &( line_string_segment[ line_string_segment_index ] );
2635
178k
    value_identifier_length = 0;
2636
2637
8.71M
    while( line_string_segment_index < line_string_segment_size )
2638
8.65M
    {
2639
8.65M
      if( ( line_string_segment[ line_string_segment_index ] == '\t' )
2640
8.65M
       || ( line_string_segment[ line_string_segment_index ] == '\n' )
2641
8.65M
       || ( line_string_segment[ line_string_segment_index ] == '\f' )
2642
8.64M
       || ( line_string_segment[ line_string_segment_index ] == '\v' )
2643
8.62M
       || ( line_string_segment[ line_string_segment_index ] == '\r' )
2644
8.62M
       || ( line_string_segment[ line_string_segment_index ] == ' ' )
2645
8.54M
       || ( line_string_segment[ line_string_segment_index ] == '=' ) )
2646
121k
      {
2647
121k
        break;
2648
121k
      }
2649
8.53M
      value_identifier_length++;
2650
2651
8.53M
      line_string_segment_index++;
2652
8.53M
    }
2653
    /* Skip a line not containing a value
2654
     */
2655
178k
    if( ( line_string_segment_index >= line_string_segment_size )
2656
121k
     || ( line_string_segment[ line_string_segment_index ] == 0 ) )
2657
56.4k
    {
2658
56.4k
      *line_index += 1;
2659
2660
56.4k
      continue;
2661
56.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
277k
    while( line_string_segment_index < line_string_segment_size )
2671
232k
    {
2672
232k
      if( ( line_string_segment[ line_string_segment_index ] != '\t' )
2673
215k
       && ( line_string_segment[ line_string_segment_index ] != '\n' )
2674
181k
       && ( line_string_segment[ line_string_segment_index ] != '\f' )
2675
163k
       && ( line_string_segment[ line_string_segment_index ] != '\v' )
2676
157k
       && ( line_string_segment[ line_string_segment_index ] != '\r' )
2677
148k
       && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
2678
76.8k
      {
2679
76.8k
        break;
2680
76.8k
      }
2681
155k
      line_string_segment_index++;
2682
155k
    }
2683
121k
    if( line_string_segment[ line_string_segment_index ] == '=' )
2684
18.0k
    {
2685
18.0k
      line_string_segment_index++;
2686
2687
47.9k
      while( line_string_segment_index < line_string_segment_size )
2688
46.0k
      {
2689
46.0k
        if( ( line_string_segment[ line_string_segment_index ] != '\t' )
2690
42.8k
         && ( line_string_segment[ line_string_segment_index ] != '\n' )
2691
38.1k
         && ( line_string_segment[ line_string_segment_index ] != '\f' )
2692
36.4k
         && ( line_string_segment[ line_string_segment_index ] != '\v' )
2693
34.3k
         && ( line_string_segment[ line_string_segment_index ] != '\r' )
2694
32.2k
         && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
2695
16.2k
        {
2696
16.2k
          break;
2697
16.2k
        }
2698
29.8k
        line_string_segment_index++;
2699
29.8k
      }
2700
18.0k
    }
2701
    /* Skip a line not containing a value
2702
     */
2703
121k
    if( ( line_string_segment_index >= line_string_segment_size )
2704
75.0k
     || ( line_string_segment[ line_string_segment_index ] == 0 ) )
2705
51.2k
    {
2706
51.2k
      *line_index += 1;
2707
2708
51.2k
      continue;
2709
51.2k
    }
2710
    /* Determine the value
2711
     */
2712
70.6k
    value        = &( line_string_segment[ line_string_segment_index ] );
2713
70.6k
    value_length = line_string_segment_size - 1;
2714
2715
    /* Ingore quotes at the beginning of the value data
2716
     */
2717
70.6k
    if( ( line_string_segment[ line_string_segment_index ] == '"' )
2718
63.7k
     || ( line_string_segment[ line_string_segment_index ] == '\'' ) )
2719
9.40k
    {
2720
9.40k
      line_string_segment_index++;
2721
9.40k
      value++;
2722
9.40k
      value_length--;
2723
9.40k
    }
2724
    /* Ingore quotes at the end of the value data
2725
     */
2726
70.6k
    if( ( line_string_segment[ value_length - 1 ] == '"' )
2727
65.8k
     || ( line_string_segment[ value_length - 1 ] == '\'' ) )
2728
5.86k
    {
2729
5.86k
      value_length--;
2730
5.86k
    }
2731
    /* Make sure the value is terminated by an end of string
2732
     */
2733
70.6k
    line_string_segment[ value_length ] = 0;
2734
2735
70.6k
    value_length -= line_string_segment_index;
2736
2737
70.6k
    if( value_identifier_length == 2 )
2738
15.1k
    {
2739
15.1k
      if( narrow_string_compare(
2740
15.1k
           value_identifier,
2741
15.1k
           "id",
2742
15.1k
           2 ) == 0 )
2743
1.35k
      {
2744
1.35k
        if( libvslvm_logical_volume_values_set_identifier(
2745
1.35k
             logical_volume_values,
2746
1.35k
             value,
2747
1.35k
             value_length + 1,
2748
1.35k
             error ) != 1 )
2749
80
        {
2750
80
          libcerror_error_set(
2751
80
           error,
2752
80
           LIBCERROR_ERROR_DOMAIN_RUNTIME,
2753
80
           LIBCERROR_RUNTIME_ERROR_SET_FAILED,
2754
80
           "%s: unable to set logical volume identifier.",
2755
80
           function );
2756
2757
80
          goto on_error;
2758
80
        }
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.35k
      }
2769
15.1k
    }
2770
55.4k
    else if( value_identifier_length == 5 )
2771
3.05k
    {
2772
3.05k
      if( narrow_string_compare(
2773
3.05k
           value_identifier,
2774
3.05k
           "flags",
2775
3.05k
           5 ) == 0 )
2776
871
      {
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
871
      }
2788
3.05k
    }
2789
52.4k
    else if( value_identifier_length == 6 )
2790
5.10k
    {
2791
5.10k
      if( narrow_string_compare(
2792
5.10k
           value_identifier,
2793
5.10k
           "status",
2794
5.10k
           6 ) == 0 )
2795
944
      {
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
944
      }
2807
2808
5.10k
    }
2809
47.3k
    else if( value_identifier_length == 13 )
2810
2.27k
    {
2811
2.27k
      if( narrow_string_compare(
2812
2.27k
           value_identifier,
2813
2.27k
           "segment_count",
2814
2.27k
           13 ) == 0 )
2815
278
      {
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
278
      }
2827
2828
2.27k
    }
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
70.5k
    *line_index += 1;
2841
70.5k
  }
2842
31.7k
  if( libvslvm_volume_group_append_logical_volume(
2843
31.7k
       volume_group,
2844
31.7k
       logical_volume_values,
2845
31.7k
       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.7k
  logical_volume_values = NULL;
2857
2858
31.7k
  return( 1 );
2859
2860
849
on_error:
2861
849
  if( logical_volume_values != NULL )
2862
849
  {
2863
849
    libvslvm_logical_volume_values_free(
2864
849
     &logical_volume_values,
2865
849
     NULL );
2866
849
  }
2867
849
  return( -1 );
2868
31.7k
}
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.99k
{
2881
3.99k
  libvslvm_internal_volume_group_t *internal_volume_group = NULL;
2882
3.99k
  libvslvm_segment_t *segment                             = NULL;
2883
3.99k
  char *line_string_segment                               = NULL;
2884
3.99k
  char *value                                             = NULL;
2885
3.99k
  char *value_identifier                                  = NULL;
2886
3.99k
  static char *function                                   = "libvslvm_metadata_read_segment";
2887
3.99k
  size_t line_string_segment_index                        = 0;
2888
3.99k
  size_t line_string_segment_size                         = 0;
2889
3.99k
  size_t value_identifier_length                          = 0;
2890
3.99k
  size_t value_length                                     = 0;
2891
3.99k
  uint64_t value_64bit                                    = 0;
2892
2893
3.99k
  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.99k
  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.99k
  internal_volume_group = (libvslvm_internal_volume_group_t *) metadata->volume_group;
2916
2917
3.99k
  if( internal_volume_group->extent_size == 0 )
2918
15
  {
2919
15
    libcerror_error_set(
2920
15
     error,
2921
15
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2922
15
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
2923
15
     "%s: invalid volume group - extent size value out of bounds.",
2924
15
     function );
2925
2926
15
    return( -1 );
2927
15
  }
2928
3.98k
  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.98k
  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.98k
  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.98k
  if( ( *line_index < 0 )
2962
3.98k
   || ( *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.98k
  if( libcsplit_narrow_split_string_get_segment_by_index(
2974
3.98k
       lines,
2975
3.98k
       *line_index,
2976
3.98k
       &line_string_segment,
2977
3.98k
       &line_string_segment_size,
2978
3.98k
       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.98k
  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.98k
  if( line_string_segment_size >= 2 )
3005
3.98k
  {
3006
3.98k
    line_string_segment_index = line_string_segment_size - 2;
3007
3008
47.0k
    while( line_string_segment_index > 0 )
3009
47.0k
    {
3010
47.0k
      if( ( line_string_segment[ line_string_segment_index ] != '\t' )
3011
45.6k
       && ( line_string_segment[ line_string_segment_index ] != '\n' )
3012
13.2k
       && ( line_string_segment[ line_string_segment_index ] != '\f' )
3013
11.6k
       && ( line_string_segment[ line_string_segment_index ] != '\v' )
3014
8.72k
       && ( line_string_segment[ line_string_segment_index ] != '\r' )
3015
6.41k
       && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
3016
3.98k
      {
3017
3.98k
        break;
3018
3.98k
      }
3019
43.0k
      line_string_segment_index--;
3020
43.0k
      line_string_segment_size--;
3021
43.0k
    }
3022
3.98k
  }
3023
  /* Ignore leading white space
3024
   */
3025
3.98k
  line_string_segment_index = 0;
3026
3027
50.5k
  while( line_string_segment_index < line_string_segment_size )
3028
50.5k
  {
3029
50.5k
    if( ( line_string_segment[ line_string_segment_index ] != '\t' )
3030
46.1k
     && ( line_string_segment[ line_string_segment_index ] != '\n' )
3031
46.1k
     && ( line_string_segment[ line_string_segment_index ] != '\f' )
3032
42.4k
     && ( line_string_segment[ line_string_segment_index ] != '\v' )
3033
40.2k
     && ( line_string_segment[ line_string_segment_index ] != '\r' )
3034
38.9k
     && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
3035
3.98k
    {
3036
3.98k
      break;
3037
3.98k
    }
3038
46.5k
    line_string_segment_index++;
3039
46.5k
  }
3040
3.98k
  if( ( line_string_segment_size < ( 7 + 3 ) )
3041
3.98k
   || ( line_string_segment[ line_string_segment_size - 3 ] != ' ' )
3042
3.98k
   || ( line_string_segment[ line_string_segment_size - 2 ] != '{' )
3043
3.98k
   || ( narrow_string_compare(
3044
3.98k
         &( line_string_segment[ line_string_segment_index ] ),
3045
3.98k
         "segment",
3046
3.98k
         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.98k
  if( libvslvm_segment_initialize(
3058
3.98k
       &segment,
3059
3.98k
       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.98k
  if( ( line_string_segment_size < 2 )
3071
3.98k
   || ( 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.98k
  if( libvslvm_internal_segment_set_name(
3083
3.98k
       (libvslvm_internal_segment_t *) segment,
3084
3.98k
       &( line_string_segment[ line_string_segment_index ] ),
3085
3.98k
       line_string_segment_size - ( line_string_segment_index + 2 ),
3086
3.98k
       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.98k
  *line_index += 1;
3110
3111
11.3M
  while( *line_index < number_of_lines )
3112
11.3M
  {
3113
11.3M
    if( libcsplit_narrow_split_string_get_segment_by_index(
3114
11.3M
         lines,
3115
11.3M
         *line_index,
3116
11.3M
         &line_string_segment,
3117
11.3M
         &line_string_segment_size,
3118
11.3M
         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.3M
    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.3M
    if( line_string_segment_size >= 2 )
3145
154k
    {
3146
154k
      line_string_segment_index = line_string_segment_size - 2;
3147
3148
391k
      while( line_string_segment_index > 0 )
3149
338k
      {
3150
338k
        if( ( line_string_segment[ line_string_segment_index ] != '\t' )
3151
314k
         && ( line_string_segment[ line_string_segment_index ] != '\n' )
3152
303k
         && ( line_string_segment[ line_string_segment_index ] != '\f' )
3153
276k
         && ( line_string_segment[ line_string_segment_index ] != '\v' )
3154
232k
         && ( line_string_segment[ line_string_segment_index ] != '\r' )
3155
206k
         && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
3156
101k
        {
3157
101k
          break;
3158
101k
        }
3159
236k
        line_string_segment_index--;
3160
236k
        line_string_segment_size--;
3161
236k
      }
3162
154k
    }
3163
    /* Ignore leading white space
3164
     */
3165
11.3M
    line_string_segment_index = 0;
3166
3167
11.8M
    while( line_string_segment_index < line_string_segment_size )
3168
11.7M
    {
3169
11.7M
      if( ( line_string_segment[ line_string_segment_index ] != '\t' )
3170
11.7M
       && ( line_string_segment[ line_string_segment_index ] != '\n' )
3171
11.7M
       && ( line_string_segment[ line_string_segment_index ] != '\f' )
3172
11.7M
       && ( line_string_segment[ line_string_segment_index ] != '\v' )
3173
11.7M
       && ( line_string_segment[ line_string_segment_index ] != '\r' )
3174
11.6M
       && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
3175
11.3M
      {
3176
11.3M
        break;
3177
11.3M
      }
3178
476k
      line_string_segment_index++;
3179
476k
    }
3180
    /* Skip an empty line
3181
     */
3182
11.3M
    if( ( line_string_segment_index >= line_string_segment_size )
3183
11.3M
     || ( line_string_segment[ line_string_segment_index ] == 0 ) )
3184
11.1M
    {
3185
11.1M
      *line_index += 1;
3186
3187
11.1M
      continue;
3188
11.1M
    }
3189
    /* Check for the end of section
3190
     */
3191
139k
    if( ( ( line_string_segment_size - line_string_segment_index ) == 2 )
3192
43.5k
     && ( line_string_segment[ line_string_segment_index ] == '}' ) )
3193
1.51k
    {
3194
1.51k
      *line_index += 1;
3195
3196
1.51k
      break;
3197
1.51k
    }
3198
    /* Determine the value identifier
3199
     */
3200
138k
    value_identifier        = &( line_string_segment[ line_string_segment_index ] );
3201
138k
    value_identifier_length = 0;
3202
3203
10.7M
    while( line_string_segment_index < line_string_segment_size )
3204
10.7M
    {
3205
10.7M
      if( ( line_string_segment[ line_string_segment_index ] == '\t' )
3206
10.7M
       || ( line_string_segment[ line_string_segment_index ] == '\n' )
3207
10.7M
       || ( line_string_segment[ line_string_segment_index ] == '\f' )
3208
10.7M
       || ( line_string_segment[ line_string_segment_index ] == '\v' )
3209
10.7M
       || ( line_string_segment[ line_string_segment_index ] == '\r' )
3210
10.7M
       || ( line_string_segment[ line_string_segment_index ] == ' ' )
3211
10.6M
       || ( line_string_segment[ line_string_segment_index ] == '=' ) )
3212
93.5k
      {
3213
93.5k
        break;
3214
93.5k
      }
3215
10.6M
      value_identifier_length++;
3216
3217
10.6M
      line_string_segment_index++;
3218
10.6M
    }
3219
    /* Skip a line not containing a value
3220
     */
3221
138k
    if( ( line_string_segment_index >= line_string_segment_size )
3222
93.5k
     || ( line_string_segment[ line_string_segment_index ] == 0 ) )
3223
44.4k
    {
3224
44.4k
      *line_index += 1;
3225
3226
44.4k
      continue;
3227
44.4k
    }
3228
    /* Make sure the value identifier is terminated by an end of string
3229
     */
3230
93.5k
    line_string_segment[ line_string_segment_index ] = 0;
3231
3232
93.5k
    line_string_segment_index++;
3233
3234
    /* Ignore whitespace
3235
     */
3236
205k
    while( line_string_segment_index < line_string_segment_size )
3237
183k
    {
3238
183k
      if( ( line_string_segment[ line_string_segment_index ] != '\t' )
3239
171k
       && ( line_string_segment[ line_string_segment_index ] != '\n' )
3240
155k
       && ( line_string_segment[ line_string_segment_index ] != '\f' )
3241
143k
       && ( line_string_segment[ line_string_segment_index ] != '\v' )
3242
135k
       && ( line_string_segment[ line_string_segment_index ] != '\r' )
3243
118k
       && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
3244
72.2k
      {
3245
72.2k
        break;
3246
72.2k
      }
3247
111k
      line_string_segment_index++;
3248
111k
    }
3249
93.5k
    if( line_string_segment[ line_string_segment_index ] == '=' )
3250
17.0k
    {
3251
17.0k
      line_string_segment_index++;
3252
3253
42.1k
      while( line_string_segment_index < line_string_segment_size )
3254
39.6k
      {
3255
39.6k
        if( ( line_string_segment[ line_string_segment_index ] != '\t' )
3256
36.4k
         && ( line_string_segment[ line_string_segment_index ] != '\n' )
3257
34.5k
         && ( line_string_segment[ line_string_segment_index ] != '\f' )
3258
32.5k
         && ( line_string_segment[ line_string_segment_index ] != '\v' )
3259
29.0k
         && ( line_string_segment[ line_string_segment_index ] != '\r' )
3260
28.1k
         && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
3261
14.5k
        {
3262
14.5k
          break;
3263
14.5k
        }
3264
25.1k
        line_string_segment_index++;
3265
25.1k
      }
3266
17.0k
    }
3267
    /* Skip a line not containing a value
3268
     */
3269
93.5k
    if( ( line_string_segment_index >= line_string_segment_size )
3270
69.6k
     || ( line_string_segment[ line_string_segment_index ] == 0 ) )
3271
29.7k
    {
3272
29.7k
      *line_index += 1;
3273
3274
29.7k
      continue;
3275
29.7k
    }
3276
    /* Ingore quotes at the beginning of the value data
3277
     */
3278
63.8k
    if( ( line_string_segment[ line_string_segment_index ] == '"' )
3279
59.8k
     || ( line_string_segment[ line_string_segment_index ] == '\'' ) )
3280
6.37k
    {
3281
6.37k
      line_string_segment_index++;
3282
6.37k
    }
3283
    /* Determine the value
3284
     */
3285
63.8k
    value        = &( line_string_segment[ line_string_segment_index ] );
3286
63.8k
    value_length = 0;
3287
3288
2.08M
    while( line_string_segment_index < line_string_segment_size )
3289
2.07M
    {
3290
2.07M
      if( ( line_string_segment[ line_string_segment_index ] == 0 )
3291
2.02M
       || ( line_string_segment[ line_string_segment_index ] == '\t' )
3292
2.02M
       || ( line_string_segment[ line_string_segment_index ] == '\n' )
3293
2.02M
       || ( line_string_segment[ line_string_segment_index ] == '\f' )
3294
2.02M
       || ( line_string_segment[ line_string_segment_index ] == '\v' )
3295
2.01M
       || ( line_string_segment[ line_string_segment_index ] == '\r' )
3296
2.01M
       || ( line_string_segment[ line_string_segment_index ] == '#' ) )
3297
60.5k
      {
3298
60.5k
        break;
3299
60.5k
      }
3300
2.01M
      line_string_segment_index++;
3301
2.01M
      value_length++;
3302
2.01M
    }
3303
    /* Ingore quotes at the end of the value data
3304
     */
3305
63.8k
    if( ( line_string_segment[ line_string_segment_index - 1 ] == '"' )
3306
61.8k
     || ( line_string_segment[ line_string_segment_index - 1 ] == '\'' ) )
3307
4.42k
    {
3308
4.42k
      line_string_segment_index--;
3309
4.42k
      value_length--;
3310
4.42k
    }
3311
    /* Make sure the value is terminated by an end of string
3312
     */
3313
63.8k
    line_string_segment[ line_string_segment_index ] = 0;
3314
3315
63.8k
    if( value_identifier_length == 4 )
3316
4.74k
    {
3317
4.74k
      if( narrow_string_compare(
3318
4.74k
           value_identifier,
3319
4.74k
           "type",
3320
4.74k
           4 ) == 0 )
3321
288
      {
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
288
      }
3333
4.74k
    }
3334
59.0k
    else if( value_identifier_length == 7 )
3335
8.27k
    {
3336
8.27k
      if( narrow_string_compare(
3337
8.27k
           value_identifier,
3338
8.27k
           "stripes",
3339
8.27k
           7 ) == 0 )
3340
6.43k
      {
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.43k
        if( ( value_length != 1 )
3350
6.39k
         || ( value[ 0 ] != '[' )
3351
6.37k
         || ( libvslvm_metadata_read_stripes_list(
3352
6.37k
               metadata,
3353
6.37k
               segment,
3354
6.37k
               lines,
3355
6.37k
               number_of_lines,
3356
6.37k
               line_index,
3357
6.37k
               error ) != 1 ) )
3358
716
        {
3359
716
          libcerror_error_set(
3360
716
           error,
3361
716
           LIBCERROR_ERROR_DOMAIN_IO,
3362
716
           LIBCERROR_IO_ERROR_READ_FAILED,
3363
716
           "%s: unable to read stripes list.",
3364
716
           function );
3365
3366
716
          goto on_error;
3367
716
        }
3368
/* TODO validate number of stripes */
3369
6.43k
      }
3370
8.27k
    }
3371
50.7k
    else if( value_identifier_length == 12 )
3372
4.71k
    {
3373
4.71k
      if( narrow_string_compare(
3374
4.71k
           value_identifier,
3375
4.71k
           "extent_count",
3376
4.71k
           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
6
        {
3395
6
          libcerror_error_set(
3396
6
           error,
3397
6
           LIBCERROR_ERROR_DOMAIN_MEMORY,
3398
6
           LIBCERROR_MEMORY_ERROR_SET_FAILED,
3399
6
           "%s: unable to set number of extents.",
3400
6
           function );
3401
3402
6
          goto on_error;
3403
6
        }
3404
1.43k
        if( value_64bit > (uint64_t) ( UINT64_MAX / internal_volume_group->extent_size ) )
3405
6
        {
3406
6
          libcerror_error_set(
3407
6
           error,
3408
6
           LIBCERROR_ERROR_DOMAIN_RUNTIME,
3409
6
           LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
3410
6
           "%s: invalid number of extents value exceeds maximum.",
3411
6
           function );
3412
3413
6
          goto on_error;
3414
6
        }
3415
1.42k
        value_64bit *= internal_volume_group->extent_size;
3416
3417
1.42k
        ( (libvslvm_internal_segment_t *) segment )->size = value_64bit;
3418
1.42k
      }
3419
3.27k
      else if( narrow_string_compare(
3420
3.27k
                value_identifier,
3421
3.27k
                "start_extent",
3422
3.27k
                12 ) == 0 )
3423
1.30k
      {
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.30k
        if( libfvalue_utf8_string_copy_to_integer(
3434
1.30k
             (uint8_t *) value,
3435
1.30k
             value_length + 1,
3436
1.30k
             &value_64bit,
3437
1.30k
             64,
3438
1.30k
             LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED,
3439
1.30k
             error ) != 1 )
3440
8
        {
3441
8
          libcerror_error_set(
3442
8
           error,
3443
8
           LIBCERROR_ERROR_DOMAIN_MEMORY,
3444
8
           LIBCERROR_MEMORY_ERROR_SET_FAILED,
3445
8
           "%s: unable to set start extent.",
3446
8
           function );
3447
3448
8
          goto on_error;
3449
8
        }
3450
1.29k
        if( value_64bit > (uint64_t) ( UINT64_MAX / internal_volume_group->extent_size ) )
3451
8
        {
3452
8
          libcerror_error_set(
3453
8
           error,
3454
8
           LIBCERROR_ERROR_DOMAIN_RUNTIME,
3455
8
           LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
3456
8
           "%s: invalid start extent value exceeds maximum.",
3457
8
           function );
3458
3459
8
          goto on_error;
3460
8
        }
3461
1.29k
        value_64bit *= internal_volume_group->extent_size;
3462
3463
1.29k
        ( (libvslvm_internal_segment_t *) segment )->offset = value_64bit;
3464
1.29k
      }
3465
1.96k
      else if( narrow_string_compare(
3466
1.96k
                value_identifier,
3467
1.96k
                "stripe_count",
3468
1.96k
                12 ) == 0 )
3469
23
      {
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
23
      }
3481
4.71k
    }
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
63.0k
    *line_index += 1;
3494
63.0k
  }
3495
3.23k
  if( libvslvm_logical_volume_values_append_segment(
3496
3.23k
       logical_volume_values,
3497
3.23k
       segment,
3498
3.23k
       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
3.23k
  segment = NULL;
3510
3511
3.23k
  return( 1 );
3512
3513
744
on_error:
3514
744
  if( segment != NULL )
3515
744
  {
3516
744
    libvslvm_internal_segment_free(
3517
744
     (libvslvm_internal_segment_t **) &segment,
3518
744
     NULL );
3519
744
  }
3520
744
  return( -1 );
3521
3.23k
}
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.37k
{
3534
6.37k
  libvslvm_internal_volume_group_t *internal_volume_group = NULL;
3535
6.37k
  libvslvm_stripe_t *stripe                               = NULL;
3536
6.37k
  char *line_string_segment                               = NULL;
3537
6.37k
  char *value                                             = NULL;
3538
6.37k
  char *value_identifier                                  = NULL;
3539
6.37k
  static char *function                                   = "libvslvm_metadata_read_stripes_list";
3540
6.37k
  size_t line_string_segment_index                        = 0;
3541
6.37k
  size_t line_string_segment_size                         = 0;
3542
6.37k
  size_t value_identifier_length                          = 0;
3543
6.37k
  size_t value_length                                     = 0;
3544
6.37k
  uint64_t value_64bit                                    = 0;
3545
3546
6.37k
  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.37k
  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.37k
  internal_volume_group = (libvslvm_internal_volume_group_t *) metadata->volume_group;
3569
3570
6.37k
  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.37k
  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.37k
  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.37k
  if( ( *line_index < 0 )
3604
6.37k
   || ( *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.37k
  *line_index += 1;
3616
3617
1.27M
  while( *line_index < number_of_lines )
3618
1.27M
  {
3619
1.27M
    if( libcsplit_narrow_split_string_get_segment_by_index(
3620
1.27M
         lines,
3621
1.27M
         *line_index,
3622
1.27M
         &line_string_segment,
3623
1.27M
         &line_string_segment_size,
3624
1.27M
         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.27M
    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.27M
    if( line_string_segment_size >= 2 )
3651
488k
    {
3652
488k
      line_string_segment_index = line_string_segment_size - 2;
3653
3654
880k
      while( line_string_segment_index > 0 )
3655
788k
      {
3656
788k
        if( ( line_string_segment[ line_string_segment_index ] != '\t' )
3657
668k
         && ( line_string_segment[ line_string_segment_index ] != '\n' )
3658
638k
         && ( line_string_segment[ line_string_segment_index ] != '\f' )
3659
598k
         && ( line_string_segment[ line_string_segment_index ] != '\v' )
3660
562k
         && ( line_string_segment[ line_string_segment_index ] != '\r' )
3661
471k
         && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
3662
396k
        {
3663
396k
          break;
3664
396k
        }
3665
392k
        line_string_segment_index--;
3666
392k
        line_string_segment_size--;
3667
392k
      }
3668
488k
    }
3669
    /* Ignore leading white space
3670
     */
3671
1.27M
    line_string_segment_index = 0;
3672
3673
1.59M
    while( line_string_segment_index < line_string_segment_size )
3674
1.58M
    {
3675
1.58M
      if( ( line_string_segment[ line_string_segment_index ] != '\t' )
3676
1.56M
       && ( line_string_segment[ line_string_segment_index ] != '\n' )
3677
1.56M
       && ( line_string_segment[ line_string_segment_index ] != '\f' )
3678
1.55M
       && ( line_string_segment[ line_string_segment_index ] != '\v' )
3679
1.52M
       && ( line_string_segment[ line_string_segment_index ] != '\r' )
3680
1.45M
       && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
3681
1.26M
      {
3682
1.26M
        break;
3683
1.26M
      }
3684
313k
      line_string_segment_index++;
3685
313k
    }
3686
    /* Skip an empty line
3687
     */
3688
1.27M
    if( ( line_string_segment_index >= line_string_segment_size )
3689
1.26M
     || ( line_string_segment[ line_string_segment_index ] == 0 ) )
3690
810k
    {
3691
810k
      *line_index += 1;
3692
3693
810k
      continue;
3694
810k
    }
3695
    /* Check for the end of section
3696
     */
3697
467k
    if( ( ( line_string_segment_size - line_string_segment_index ) == 2 )
3698
75.6k
     && ( line_string_segment[ line_string_segment_index ] == ']' ) )
3699
5.07k
    {
3700
5.07k
      break;
3701
5.07k
    }
3702
    /* Ingore quotes at the beginning of the value data
3703
     */
3704
462k
    if( ( line_string_segment[ line_string_segment_index ] == '"' )
3705
439k
     || ( line_string_segment[ line_string_segment_index ] == '\'' ) )
3706
27.1k
    {
3707
27.1k
      line_string_segment_index++;
3708
27.1k
    }
3709
    /* Determine the value identifier
3710
     */
3711
462k
    value_identifier        = &( line_string_segment[ line_string_segment_index ] );
3712
462k
    value_identifier_length = 0;
3713
3714
8.07M
    while( line_string_segment_index < line_string_segment_size )
3715
7.98M
    {
3716
7.98M
      if( ( line_string_segment[ line_string_segment_index ] == '\t' )
3717
7.97M
       || ( line_string_segment[ line_string_segment_index ] == '\n' )
3718
7.97M
       || ( line_string_segment[ line_string_segment_index ] == '\f' )
3719
7.96M
       || ( line_string_segment[ line_string_segment_index ] == '\v' )
3720
7.93M
       || ( line_string_segment[ line_string_segment_index ] == '\r' )
3721
7.93M
       || ( line_string_segment[ line_string_segment_index ] == ' ' )
3722
7.86M
       || ( line_string_segment[ line_string_segment_index ] == ',' ) )
3723
370k
      {
3724
370k
        break;
3725
370k
      }
3726
7.61M
      value_identifier_length++;
3727
3728
7.61M
      line_string_segment_index++;
3729
7.61M
    }
3730
    /* Skip a line not containing a value
3731
     */
3732
462k
    if( ( line_string_segment_index >= line_string_segment_size )
3733
370k
     || ( line_string_segment[ line_string_segment_index ] == 0 ) )
3734
91.7k
    {
3735
91.7k
      *line_index += 1;
3736
3737
91.7k
      continue;
3738
91.7k
    }
3739
    /* Ingore quotes at the end of the value identifier
3740
     */
3741
370k
    if( ( line_string_segment[ line_string_segment_index - 1 ] == '"' )
3742
351k
     || ( line_string_segment[ line_string_segment_index - 1 ] == '\'' ) )
3743
27.9k
    {
3744
27.9k
      value_identifier_length--;
3745
3746
      /* Make sure the value identifier is terminated by an end of string
3747
       */
3748
27.9k
      line_string_segment[ line_string_segment_index - 1 ] = 0;
3749
27.9k
    }
3750
342k
    else
3751
342k
    {
3752
      /* Make sure the value identifier is terminated by an end of string
3753
       */
3754
342k
      line_string_segment[ line_string_segment_index ] = 0;
3755
342k
    }
3756
370k
    line_string_segment_index++;
3757
3758
    /* Ignore whitespace
3759
     */
3760
672k
    while( line_string_segment_index < line_string_segment_size )
3761
614k
    {
3762
614k
      if( ( line_string_segment[ line_string_segment_index ] != '\t' )
3763
609k
       && ( line_string_segment[ line_string_segment_index ] != '\n' )
3764
604k
       && ( line_string_segment[ line_string_segment_index ] != '\f' )
3765
600k
       && ( line_string_segment[ line_string_segment_index ] != '\v' )
3766
598k
       && ( line_string_segment[ line_string_segment_index ] != '\r' )
3767
592k
       && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
3768
312k
      {
3769
312k
        break;
3770
312k
      }
3771
301k
      line_string_segment_index++;
3772
301k
    }
3773
370k
    if( line_string_segment[ line_string_segment_index ] == ',' )
3774
24.9k
    {
3775
24.9k
      line_string_segment_index++;
3776
3777
46.2k
      while( line_string_segment_index < line_string_segment_size )
3778
45.0k
      {
3779
45.0k
        if( ( line_string_segment[ line_string_segment_index ] != '\t' )
3780
43.4k
         && ( line_string_segment[ line_string_segment_index ] != '\n' )
3781
42.2k
         && ( line_string_segment[ line_string_segment_index ] != '\f' )
3782
40.9k
         && ( line_string_segment[ line_string_segment_index ] != '\v' )
3783
39.1k
         && ( line_string_segment[ line_string_segment_index ] != '\r' )
3784
37.0k
         && ( line_string_segment[ line_string_segment_index ] != ' ' ) )
3785
23.7k
        {
3786
23.7k
          break;
3787
23.7k
        }
3788
21.2k
        line_string_segment_index++;
3789
21.2k
      }
3790
24.9k
    }
3791
    /* Skip a line not containing a value
3792
     */
3793
370k
    if( ( line_string_segment_index >= line_string_segment_size )
3794
311k
     || ( line_string_segment[ line_string_segment_index ] == 0 ) )
3795
73.3k
    {
3796
73.3k
      *line_index += 1;
3797
3798
73.3k
      continue;
3799
73.3k
    }
3800
    /* Determine the value
3801
     */
3802
297k
    value        = &( line_string_segment[ line_string_segment_index ] );
3803
297k
    value_length = line_string_segment_size - 1;
3804
3805
    /* Make sure the value is terminated by an end of string
3806
     */
3807
297k
    line_string_segment[ value_length ] = 0;
3808
3809
297k
    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
297k
    *line_index += 1;
3823
3824
297k
    if( libfvalue_utf8_string_copy_to_integer(
3825
297k
         (uint8_t *) value,
3826
297k
         value_length + 1,
3827
297k
         &value_64bit,
3828
297k
         64,
3829
297k
         LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED,
3830
297k
         error ) != 1 )
3831
643
    {
3832
643
      libcerror_error_set(
3833
643
       error,
3834
643
       LIBCERROR_ERROR_DOMAIN_MEMORY,
3835
643
       LIBCERROR_MEMORY_ERROR_SET_FAILED,
3836
643
       "%s: unable to set data area offset.",
3837
643
       function );
3838
3839
643
      goto on_error;
3840
643
    }
3841
296k
    if( value_64bit > (uint64_t) ( UINT64_MAX / internal_volume_group->extent_size ) )
3842
15
    {
3843
15
      libcerror_error_set(
3844
15
       error,
3845
15
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3846
15
       LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
3847
15
       "%s: invalid data area offset value exceeds maximum.",
3848
15
       function );
3849
3850
15
      goto on_error;
3851
15
    }
3852
296k
    value_64bit *= internal_volume_group->extent_size;
3853
3854
296k
    if( libvslvm_stripe_initialize(
3855
296k
         &stripe,
3856
296k
         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
296k
    if( libvslvm_internal_stripe_set_physical_volume_name(
3868
296k
         (libvslvm_internal_stripe_t *) stripe,
3869
296k
         value_identifier,
3870
296k
         value_identifier_length + 1,
3871
296k
         error ) != 1 )
3872
4
    {
3873
4
      libcerror_error_set(
3874
4
       error,
3875
4
       LIBCERROR_ERROR_DOMAIN_RUNTIME,
3876
4
       LIBCERROR_RUNTIME_ERROR_SET_FAILED,
3877
4
       "%s: unable to set physical volume name.",
3878
4
       function );
3879
3880
4
      goto on_error;
3881
4
    }
3882
296k
    if( libvslvm_stripe_set_data_area_offset(
3883
296k
         stripe,
3884
296k
         value_64bit,
3885
296k
         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
296k
    if( libvslvm_segment_append_stripe(
3897
296k
         segment,
3898
296k
         stripe,
3899
296k
         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
296k
    stripe = NULL;
3911
296k
  }
3912
5.71k
  return( 1 );
3913
3914
662
on_error:
3915
662
  if( stripe != NULL )
3916
4
  {
3917
4
    libvslvm_internal_stripe_free(
3918
4
     (libvslvm_internal_stripe_t **) &stripe,
3919
4
     NULL );
3920
4
  }
3921
662
  return( -1 );
3922
6.37k
}
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
7.95k
{
3932
7.95k
  static char *function = "libvslvm_metadata_get_volume_group";
3933
3934
7.95k
  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
7.95k
  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
7.95k
  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
7.95k
  if( metadata->volume_group == NULL )
3968
0
  {
3969
0
    return( 0 );
3970
0
  }
3971
7.95k
  *volume_group = metadata->volume_group;
3972
3973
7.95k
  return( 1 );
3974
7.95k
}
3975