Coverage Report

Created: 2025-06-13 07:22

/src/libvsapm/libvsapm/libvsapm_partition_map_entry.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * The partition map entry functions
3
 *
4
 * Copyright (C) 2009-2024, Joachim Metz <joachim.metz@gmail.com>
5
 *
6
 * Refer to AUTHORS for acknowledgements.
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Lesser General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public License
19
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
 */
21
22
#include <common.h>
23
#include <byte_stream.h>
24
#include <memory.h>
25
#include <narrow_string.h>
26
#include <types.h>
27
28
#include "libvsapm_debug.h"
29
#include "libvsapm_definitions.h"
30
#include "libvsapm_libcerror.h"
31
#include "libvsapm_libcnotify.h"
32
#include "libvsapm_partition_map_entry.h"
33
34
#include "vsapm_partition_map_entry.h"
35
36
/* Creates a partition map entry
37
 * Make sure the value partition_map_entry is referencing, is set to NULL
38
 * Returns 1 if successful or -1 on error
39
 */
40
int libvsapm_partition_map_entry_initialize(
41
     libvsapm_partition_map_entry_t **partition_map_entry,
42
     libcerror_error_t **error )
43
38.8k
{
44
38.8k
  static char *function = "libvsapm_partition_map_entry_initialize";
45
46
38.8k
  if( partition_map_entry == NULL )
47
0
  {
48
0
    libcerror_error_set(
49
0
     error,
50
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
51
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
52
0
     "%s: invalid partition map entry.",
53
0
     function );
54
55
0
    return( -1 );
56
0
  }
57
38.8k
  if( *partition_map_entry != NULL )
58
0
  {
59
0
    libcerror_error_set(
60
0
     error,
61
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
62
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
63
0
     "%s: invalid partition map entry value already set.",
64
0
     function );
65
66
0
    return( -1 );
67
0
  }
68
38.8k
  *partition_map_entry = memory_allocate_structure(
69
38.8k
                          libvsapm_partition_map_entry_t );
70
71
38.8k
  if( *partition_map_entry == NULL )
72
0
  {
73
0
    libcerror_error_set(
74
0
     error,
75
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
76
0
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
77
0
     "%s: unable to create partition map entry.",
78
0
     function );
79
80
0
    goto on_error;
81
0
  }
82
38.8k
  if( memory_set(
83
38.8k
       *partition_map_entry,
84
38.8k
       0,
85
38.8k
       sizeof( libvsapm_partition_map_entry_t ) ) == NULL )
86
0
  {
87
0
    libcerror_error_set(
88
0
     error,
89
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
90
0
     LIBCERROR_MEMORY_ERROR_SET_FAILED,
91
0
     "%s: unable to clear partition map entry.",
92
0
     function );
93
94
0
    goto on_error;
95
0
  }
96
38.8k
  return( 1 );
97
98
0
on_error:
99
0
  if( *partition_map_entry != NULL )
100
0
  {
101
0
    memory_free(
102
0
     *partition_map_entry );
103
104
0
    *partition_map_entry = NULL;
105
0
  }
106
0
  return( -1 );
107
38.8k
}
108
109
/* Frees a partition map entry
110
 * Returns 1 if successful or -1 on error
111
 */
112
int libvsapm_partition_map_entry_free(
113
     libvsapm_partition_map_entry_t **partition_map_entry,
114
     libcerror_error_t **error )
115
38.8k
{
116
38.8k
  static char *function = "libvsapm_partition_map_entry_free";
117
118
38.8k
  if( partition_map_entry == NULL )
119
0
  {
120
0
    libcerror_error_set(
121
0
     error,
122
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
123
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
124
0
     "%s: invalid partition map entry.",
125
0
     function );
126
127
0
    return( -1 );
128
0
  }
129
38.8k
  if( *partition_map_entry != NULL )
130
38.8k
  {
131
38.8k
    memory_free(
132
38.8k
     *partition_map_entry );
133
134
38.8k
    *partition_map_entry = NULL;
135
38.8k
  }
136
38.8k
  return( 1 );
137
38.8k
}
138
139
/* Reads a partition map entry
140
 * Returns 1 if successful or -1 on error
141
 */
142
int libvsapm_partition_map_entry_read_data(
143
     libvsapm_partition_map_entry_t *partition_map_entry,
144
     const uint8_t *data,
145
     size_t data_size,
146
     libcerror_error_t **error )
147
38.7k
{
148
38.7k
  static char *function = "libvsapm_partition_map_entry_read_data";
149
150
#if defined( HAVE_DEBUG_OUTPUT )
151
  uint32_t value_32bit  = 0;
152
  uint16_t value_16bit  = 0;
153
#endif
154
155
38.7k
  if( partition_map_entry == NULL )
156
0
  {
157
0
    libcerror_error_set(
158
0
     error,
159
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
160
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
161
0
     "%s: invalid partition map entry.",
162
0
     function );
163
164
0
    return( -1 );
165
0
  }
166
38.7k
  if( data == NULL )
167
0
  {
168
0
    libcerror_error_set(
169
0
     error,
170
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
171
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
172
0
     "%s: invalid data.",
173
0
     function );
174
175
0
    return( -1 );
176
0
  }
177
38.7k
  if( data_size != sizeof( vsapm_partition_map_entry_t) )
178
0
  {
179
0
    libcerror_error_set(
180
0
     error,
181
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
182
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
183
0
     "%s: invalid data size value out of bounds.",
184
0
     function );
185
186
0
    return( -1 );
187
0
  }
188
#if defined( HAVE_DEBUG_OUTPUT )
189
  if( libcnotify_verbose != 0 )
190
  {
191
    libcnotify_printf(
192
     "%s: partition map entry data:\n",
193
     function );
194
    libcnotify_print_data(
195
     data,
196
     sizeof( vsapm_partition_map_entry_t ),
197
     LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA );
198
  }
199
#endif
200
38.7k
  byte_stream_copy_to_uint32_big_endian(
201
38.7k
   ( (vsapm_partition_map_entry_t *) data )->number_of_entries,
202
38.7k
   partition_map_entry->number_of_entries );
203
204
38.7k
  byte_stream_copy_to_uint32_big_endian(
205
38.7k
   ( (vsapm_partition_map_entry_t *) data )->start_sector,
206
38.7k
   partition_map_entry->sector_number );
207
208
38.7k
  byte_stream_copy_to_uint32_big_endian(
209
38.7k
   ( (vsapm_partition_map_entry_t *) data )->number_of_sectors,
210
38.7k
   partition_map_entry->number_of_sectors );
211
212
38.7k
  if( memory_copy(
213
38.7k
       partition_map_entry->name,
214
38.7k
       ( (vsapm_partition_map_entry_t *) data )->name,
215
38.7k
       32 ) == NULL )
216
0
  {
217
0
    libcerror_error_set(
218
0
     error,
219
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
220
0
     LIBCERROR_MEMORY_ERROR_COPY_FAILED,
221
0
     "%s: unable to copy name.",
222
0
     function );
223
224
0
    return( -1 );
225
0
  }
226
38.7k
  partition_map_entry->name[ 32 ] = 0;
227
228
38.7k
  if( memory_copy(
229
38.7k
       partition_map_entry->type,
230
38.7k
       ( (vsapm_partition_map_entry_t *) data )->type,
231
38.7k
       32 ) == NULL )
232
0
  {
233
0
    libcerror_error_set(
234
0
     error,
235
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
236
0
     LIBCERROR_MEMORY_ERROR_COPY_FAILED,
237
0
     "%s: unable to copy type.",
238
0
     function );
239
240
0
    return( -1 );
241
0
  }
242
38.7k
  partition_map_entry->type[ 32 ] = 0;
243
244
38.7k
  byte_stream_copy_to_uint32_big_endian(
245
38.7k
   ( (vsapm_partition_map_entry_t *) data )->status_flags,
246
38.7k
   partition_map_entry->status_flags );
247
248
#if defined( HAVE_DEBUG_OUTPUT )
249
  if( libcnotify_verbose != 0 )
250
  {
251
    libcnotify_printf(
252
     "%s: signature\t\t\t: %c%c\n",
253
     function,
254
     ( (vsapm_partition_map_entry_t *) data )->signature[ 0 ],
255
     ( (vsapm_partition_map_entry_t *) data )->signature[ 1 ] );
256
257
    byte_stream_copy_to_uint16_big_endian(
258
     ( (vsapm_partition_map_entry_t *) data )->unknown1,
259
     value_16bit );
260
    libcnotify_printf(
261
     "%s: unknown1\t\t\t: %" PRIu16 "\n",
262
     function,
263
     value_16bit );
264
265
    libcnotify_printf(
266
     "%s: number of entries\t\t: %" PRIu32 "\n",
267
     function,
268
     partition_map_entry->number_of_entries );
269
270
    libcnotify_printf(
271
     "%s: start sector number\t\t: %" PRIu32 "\n",
272
     function,
273
     partition_map_entry->sector_number );
274
275
    libcnotify_printf(
276
     "%s: number of sectors\t\t: %" PRIu32 "\n",
277
     function,
278
     partition_map_entry->number_of_sectors );
279
280
    libcnotify_printf(
281
     "%s: name\t\t\t\t: %s\n",
282
     function,
283
     partition_map_entry->name );
284
285
    libcnotify_printf(
286
     "%s: type\t\t\t\t: %s\n",
287
     function,
288
     partition_map_entry->type );
289
290
    byte_stream_copy_to_uint32_big_endian(
291
     ( (vsapm_partition_map_entry_t *) data )->data_area_start_sector,
292
     value_32bit );
293
    libcnotify_printf(
294
     "%s: data area start sector\t\t: %" PRIu32 "\n",
295
     function,
296
     value_32bit );
297
298
    byte_stream_copy_to_uint32_big_endian(
299
     ( (vsapm_partition_map_entry_t *) data )->data_area_number_of_sectors,
300
     value_32bit );
301
    libcnotify_printf(
302
     "%s: data area number of sectors\t: %" PRIu32 "\n",
303
     function,
304
     value_32bit );
305
306
    libcnotify_printf(
307
     "%s: status flags\t\t\t: %" PRIu32 "\n",
308
     function,
309
     partition_map_entry->status_flags );
310
    libvsapm_debug_print_partition_status_flags(
311
     partition_map_entry->status_flags );
312
    libcnotify_printf(
313
     "\n" );
314
315
    byte_stream_copy_to_uint32_big_endian(
316
     ( (vsapm_partition_map_entry_t *) data )->boot_code_start_sector,
317
     value_32bit );
318
    libcnotify_printf(
319
     "%s: boot code start sector\t\t: %" PRIu32 "\n",
320
     function,
321
     value_32bit );
322
323
    byte_stream_copy_to_uint32_big_endian(
324
     ( (vsapm_partition_map_entry_t *) data )->boot_code_number_of_sectors,
325
     value_32bit );
326
    libcnotify_printf(
327
     "%s: boot code number of sectors\t: %" PRIu32 "\n",
328
     function,
329
     value_32bit );
330
331
    byte_stream_copy_to_uint32_big_endian(
332
     ( (vsapm_partition_map_entry_t *) data )->boot_code_address,
333
     value_32bit );
334
    libcnotify_printf(
335
     "%s: boot code address\t\t: %" PRIu32 "\n",
336
     function,
337
     value_32bit );
338
339
    byte_stream_copy_to_uint32_big_endian(
340
     ( (vsapm_partition_map_entry_t *) data )->unknown2,
341
     value_32bit );
342
    libcnotify_printf(
343
     "%s: unknown2\t\t\t: %" PRIu32 "\n",
344
     function,
345
     value_32bit );
346
347
    byte_stream_copy_to_uint32_big_endian(
348
     ( (vsapm_partition_map_entry_t *) data )->boot_code_entry_point,
349
     value_32bit );
350
    libcnotify_printf(
351
     "%s: boot code entry point\t\t: %" PRIu32 "\n",
352
     function,
353
     value_32bit );
354
355
    byte_stream_copy_to_uint32_big_endian(
356
     ( (vsapm_partition_map_entry_t *) data )->unknown3,
357
     value_32bit );
358
    libcnotify_printf(
359
     "%s: unknown3\t\t\t: %" PRIu32 "\n",
360
     function,
361
     value_32bit );
362
363
    libcnotify_printf(
364
     "%s: processor type:\n",
365
     function );
366
    libcnotify_print_data(
367
     ( (vsapm_partition_map_entry_t *) data )->processor_type,
368
     16,
369
     0 );
370
371
    libcnotify_printf(
372
     "%s: unknown4:\n",
373
     function );
374
    libcnotify_print_data(
375
     ( (vsapm_partition_map_entry_t *) data )->unknown4,
376
     376,
377
     LIBCNOTIFY_PRINT_DATA_FLAG_GROUP_DATA );
378
  }
379
#endif /* defined( HAVE_DEBUG_OUTPUT ) */
380
381
/* TODO check for ASCII only */
382
38.7k
  partition_map_entry->name_length = narrow_string_length(
383
38.7k
                                      (char *) partition_map_entry->name );
384
385
38.7k
  if( partition_map_entry->name_length >= 32 )
386
13
  {
387
13
    libcerror_error_set(
388
13
     error,
389
13
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
390
13
     LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
391
13
     "%s: invalid name length value out of bounds.",
392
13
     function );
393
394
13
    return( -1 );
395
13
  }
396
/* TODO check for ASCII only */
397
38.6k
  partition_map_entry->type_length = narrow_string_length(
398
38.6k
                                      (char *) partition_map_entry->type );
399
400
38.6k
  if( ( partition_map_entry->type_length == 0 )
401
38.6k
   || ( partition_map_entry->type_length >= 32 ) )
402
27
  {
403
27
    libcerror_error_set(
404
27
     error,
405
27
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
406
27
     LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
407
27
     "%s: invalid type length value out of bounds.",
408
27
     function );
409
410
27
    return( -1 );
411
27
  }
412
38.6k
  return( 1 );
413
38.6k
}
414
415
/* Reads the partition map entry
416
 * Returns 1 if successful or -1 on error
417
 */
418
int libvsapm_partition_map_entry_read_file_io_handle(
419
     libvsapm_partition_map_entry_t *partition_map_entry,
420
     libbfio_handle_t *file_io_handle,
421
     off64_t file_offset,
422
     libcerror_error_t **error )
423
38.8k
{
424
38.8k
  uint8_t partition_map_entry_data[ sizeof( vsapm_partition_map_entry_t ) ];
425
426
38.8k
  static char *function = "libvsapm_partition_map_entry_read_file_io_handle";
427
38.8k
  ssize_t read_count    = 0;
428
429
38.8k
  if( partition_map_entry == NULL )
430
0
  {
431
0
    libcerror_error_set(
432
0
     error,
433
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
434
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
435
0
     "%s: invalid partition map entry.",
436
0
     function );
437
438
0
    return( -1 );
439
0
  }
440
#if defined( HAVE_DEBUG_OUTPUT )
441
  if( libcnotify_verbose != 0 )
442
  {
443
    libcnotify_printf(
444
     "%s: reading partition map entry at offset: %" PRIi64 " (0x%08" PRIx64 ")\n",
445
     function,
446
     file_offset,
447
     file_offset );
448
  }
449
#endif
450
38.8k
  read_count = libbfio_handle_read_buffer_at_offset(
451
38.8k
                file_io_handle,
452
38.8k
                partition_map_entry_data,
453
38.8k
                sizeof( vsapm_partition_map_entry_t ),
454
38.8k
                file_offset,
455
38.8k
                error );
456
457
38.8k
  if( read_count != (ssize_t) sizeof( vsapm_partition_map_entry_t ) )
458
190
  {
459
190
    libcerror_error_set(
460
190
     error,
461
190
     LIBCERROR_ERROR_DOMAIN_IO,
462
190
     LIBCERROR_IO_ERROR_READ_FAILED,
463
190
     "%s: unable to read partition map entry data at offset: %" PRIi64 " (0x%08" PRIx64 ").",
464
190
     function,
465
190
     file_offset,
466
190
     file_offset );
467
468
190
    return( -1 );
469
190
  }
470
38.7k
  if( libvsapm_partition_map_entry_read_data(
471
38.7k
       partition_map_entry,
472
38.7k
       partition_map_entry_data,
473
38.7k
       sizeof( vsapm_partition_map_entry_t ),
474
38.7k
       error ) != 1 )
475
40
  {
476
40
    libcerror_error_set(
477
40
     error,
478
40
     LIBCERROR_ERROR_DOMAIN_IO,
479
40
     LIBCERROR_IO_ERROR_READ_FAILED,
480
40
     "%s: unable to read partition map entry.",
481
40
     function );
482
483
40
    return( -1 );
484
40
  }
485
38.6k
  return( 1 );
486
38.7k
}
487
488
/* Retrieves the partition sector number
489
 * Returns 1 if successful or -1 on error
490
 */
491
int libvsapm_partition_map_entry_get_sector_number(
492
     libvsapm_partition_map_entry_t *partition_map_entry,
493
     uint32_t *sector_number,
494
     libcerror_error_t **error )
495
47
{
496
47
  static char *function = "libvsapm_partition_map_entry_get_sector_number";
497
498
47
  if( partition_map_entry == NULL )
499
0
  {
500
0
    libcerror_error_set(
501
0
     error,
502
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
503
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
504
0
     "%s: invalid partition map entry.",
505
0
     function );
506
507
0
    return( -1 );
508
0
  }
509
47
  if( sector_number == NULL )
510
0
  {
511
0
    libcerror_error_set(
512
0
     error,
513
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
514
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
515
0
     "%s: invalid sector number.",
516
0
     function );
517
518
0
    return( -1 );
519
0
  }
520
47
  *sector_number = partition_map_entry->sector_number;
521
522
47
  return( 1 );
523
47
}
524
525
/* Retrieves the partition number of sectors
526
 * Returns 1 if successful or -1 on error
527
 */
528
int libvsapm_partition_map_entry_get_number_of_sectors(
529
     libvsapm_partition_map_entry_t *partition_map_entry,
530
     uint32_t *number_of_sectors,
531
     libcerror_error_t **error )
532
47
{
533
47
  static char *function = "libvsapm_partition_map_entry_get_number_of_sectors";
534
535
47
  if( partition_map_entry == NULL )
536
0
  {
537
0
    libcerror_error_set(
538
0
     error,
539
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
540
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
541
0
     "%s: invalid partition map entry.",
542
0
     function );
543
544
0
    return( -1 );
545
0
  }
546
47
  if( number_of_sectors == NULL )
547
0
  {
548
0
    libcerror_error_set(
549
0
     error,
550
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
551
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
552
0
     "%s: invalid number of sectors.",
553
0
     function );
554
555
0
    return( -1 );
556
0
  }
557
47
  *number_of_sectors = partition_map_entry->number_of_sectors;
558
559
47
  return( 1 );
560
47
}
561
562
/* Retrieves the ASCII encoded string of the partition name
563
 * Returns 1 if successful or -1 on error
564
 */
565
int libvsapm_partition_map_entry_get_name_string(
566
     libvsapm_partition_map_entry_t *partition_map_entry,
567
     char *string,
568
     size_t string_size,
569
     libcerror_error_t **error )
570
0
{
571
0
  static char *function = "libvsapm_partition_map_entry_get_name_string";
572
573
0
  if( partition_map_entry == NULL )
574
0
  {
575
0
    libcerror_error_set(
576
0
     error,
577
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
578
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
579
0
     "%s: invalid partition map entry.",
580
0
     function );
581
582
0
    return( -1 );
583
0
  }
584
0
  if( string == NULL )
585
0
  {
586
0
    libcerror_error_set(
587
0
     error,
588
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
589
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
590
0
     "%s: invalid string.",
591
0
     function );
592
593
0
    return( -1 );
594
0
  }
595
0
  if( ( string_size <= partition_map_entry->name_length )
596
0
   || ( string_size > (size_t) SSIZE_MAX ) )
597
0
  {
598
0
    libcerror_error_set(
599
0
     error,
600
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
601
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
602
0
     "%s: invalid string size value out of bounds.",
603
0
     function );
604
605
0
    return( -1 );
606
0
  }
607
0
  if( memory_copy(
608
0
       string,
609
0
       partition_map_entry->name,
610
0
       partition_map_entry->name_length ) == NULL )
611
0
  {
612
0
    libcerror_error_set(
613
0
     error,
614
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
615
0
     LIBCERROR_MEMORY_ERROR_COPY_FAILED,
616
0
     "%s: unable to copy name string.",
617
0
     function );
618
619
0
    return( -1 );
620
0
  }
621
0
  string[ partition_map_entry->name_length ] = 0;
622
623
0
  return( 1 );
624
0
}
625
626
/* Retrieves the ASCII encoded string of the partition type
627
 * Returns 1 if successful or -1 on error
628
 */
629
int libvsapm_partition_map_entry_get_type_string(
630
     libvsapm_partition_map_entry_t *partition_map_entry,
631
     char *string,
632
     size_t string_size,
633
     libcerror_error_t **error )
634
0
{
635
0
  static char *function = "libvsapm_partition_map_entry_get_type_string";
636
637
0
  if( partition_map_entry == NULL )
638
0
  {
639
0
    libcerror_error_set(
640
0
     error,
641
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
642
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
643
0
     "%s: invalid partition map entry.",
644
0
     function );
645
646
0
    return( -1 );
647
0
  }
648
0
  if( string == NULL )
649
0
  {
650
0
    libcerror_error_set(
651
0
     error,
652
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
653
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
654
0
     "%s: invalid string.",
655
0
     function );
656
657
0
    return( -1 );
658
0
  }
659
0
  if( ( string_size <= partition_map_entry->type_length )
660
0
   || ( string_size > (size_t) SSIZE_MAX ) )
661
0
  {
662
0
    libcerror_error_set(
663
0
     error,
664
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
665
0
     LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
666
0
     "%s: invalid string size value out of bounds.",
667
0
     function );
668
669
0
    return( -1 );
670
0
  }
671
0
  if( memory_copy(
672
0
       string,
673
0
       partition_map_entry->type,
674
0
       partition_map_entry->type_length ) == NULL )
675
0
  {
676
0
    libcerror_error_set(
677
0
     error,
678
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
679
0
     LIBCERROR_MEMORY_ERROR_COPY_FAILED,
680
0
     "%s: unable to copy type string.",
681
0
     function );
682
683
0
    return( -1 );
684
0
  }
685
0
  string[ partition_map_entry->type_length ] = 0;
686
687
0
  return( 1 );
688
0
}
689
690
/* Retrieves the partition status flags
691
 * Returns 1 if successful or -1 on error
692
 */
693
int libvsapm_partition_map_entry_get_status_flags(
694
     libvsapm_partition_map_entry_t *partition_map_entry,
695
     uint32_t *status_flags,
696
     libcerror_error_t **error )
697
0
{
698
0
  static char *function = "libvsapm_partition_map_entry_get_status_flags";
699
700
0
  if( partition_map_entry == NULL )
701
0
  {
702
0
    libcerror_error_set(
703
0
     error,
704
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
705
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
706
0
     "%s: invalid partition map entry.",
707
0
     function );
708
709
0
    return( -1 );
710
0
  }
711
0
  if( status_flags == NULL )
712
0
  {
713
0
    libcerror_error_set(
714
0
     error,
715
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
716
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
717
0
     "%s: invalid status flags.",
718
0
     function );
719
720
0
    return( -1 );
721
0
  }
722
0
  *status_flags = partition_map_entry->status_flags;
723
724
0
  return( 1 );
725
0
}
726