/src/libvmdk/libvmdk/libvmdk_extent_values.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Extent values 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 <memory.h> |
24 | | #include <narrow_string.h> |
25 | | #include <system_string.h> |
26 | | #include <types.h> |
27 | | #include <wide_string.h> |
28 | | |
29 | | #include "libvmdk_debug.h" |
30 | | #include "libvmdk_definitions.h" |
31 | | #include "libvmdk_extent_values.h" |
32 | | #include "libvmdk_libcerror.h" |
33 | | #include "libvmdk_libcnotify.h" |
34 | | #include "libvmdk_libcsplit.h" |
35 | | #include "libvmdk_libfvalue.h" |
36 | | #include "libvmdk_libuna.h" |
37 | | #include "libvmdk_system_string.h" |
38 | | |
39 | | /* Creates extent values |
40 | | * Make sure the value extent_values is referencing, is set to NULL |
41 | | * Returns 1 if successful or -1 on error |
42 | | */ |
43 | | int libvmdk_extent_values_initialize( |
44 | | libvmdk_extent_values_t **extent_values, |
45 | | libcerror_error_t **error ) |
46 | 355k | { |
47 | 355k | static char *function = "libvmdk_extent_values_initialize"; |
48 | | |
49 | 355k | if( extent_values == NULL ) |
50 | 0 | { |
51 | 0 | libcerror_error_set( |
52 | 0 | error, |
53 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
54 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
55 | 0 | "%s: invalid extent values.", |
56 | 0 | function ); |
57 | |
|
58 | 0 | return( -1 ); |
59 | 0 | } |
60 | 355k | if( *extent_values != NULL ) |
61 | 0 | { |
62 | 0 | libcerror_error_set( |
63 | 0 | error, |
64 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
65 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
66 | 0 | "%s: invalid extent values value already set.", |
67 | 0 | function ); |
68 | |
|
69 | 0 | return( -1 ); |
70 | 0 | } |
71 | 355k | *extent_values = memory_allocate_structure( |
72 | 355k | libvmdk_extent_values_t ); |
73 | | |
74 | 355k | if( *extent_values == NULL ) |
75 | 0 | { |
76 | 0 | libcerror_error_set( |
77 | 0 | error, |
78 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
79 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
80 | 0 | "%s: unable to create extent values.", |
81 | 0 | function ); |
82 | |
|
83 | 0 | goto on_error; |
84 | 0 | } |
85 | 355k | if( memory_set( |
86 | 355k | *extent_values, |
87 | 355k | 0, |
88 | 355k | sizeof( libvmdk_extent_values_t ) ) == NULL ) |
89 | 0 | { |
90 | 0 | libcerror_error_set( |
91 | 0 | error, |
92 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
93 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
94 | 0 | "%s: unable to clear extent values.", |
95 | 0 | function ); |
96 | |
|
97 | 0 | goto on_error; |
98 | 0 | } |
99 | 355k | return( 1 ); |
100 | | |
101 | 0 | on_error: |
102 | 0 | if( *extent_values != NULL ) |
103 | 0 | { |
104 | 0 | memory_free( |
105 | 0 | *extent_values ); |
106 | |
|
107 | 0 | *extent_values = NULL; |
108 | 0 | } |
109 | 0 | return( -1 ); |
110 | 355k | } |
111 | | |
112 | | /* Frees extent values |
113 | | * Returns 1 if successful or -1 on error |
114 | | */ |
115 | | int libvmdk_extent_values_free( |
116 | | libvmdk_extent_values_t **extent_values, |
117 | | libcerror_error_t **error ) |
118 | 355k | { |
119 | 355k | static char *function = "libvmdk_extent_values_free"; |
120 | | |
121 | 355k | if( extent_values == NULL ) |
122 | 0 | { |
123 | 0 | libcerror_error_set( |
124 | 0 | error, |
125 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
126 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
127 | 0 | "%s: invalid extent values.", |
128 | 0 | function ); |
129 | |
|
130 | 0 | return( -1 ); |
131 | 0 | } |
132 | 355k | if( *extent_values != NULL ) |
133 | 355k | { |
134 | 355k | if( ( *extent_values )->filename != NULL ) |
135 | 347k | { |
136 | 347k | memory_free( |
137 | 347k | ( *extent_values )->filename ); |
138 | 347k | } |
139 | 355k | if( ( *extent_values )->alternate_filename != NULL ) |
140 | 0 | { |
141 | 0 | memory_free( |
142 | 0 | ( *extent_values )->alternate_filename ); |
143 | 0 | } |
144 | 355k | memory_free( |
145 | 355k | *extent_values ); |
146 | | |
147 | 355k | *extent_values = NULL; |
148 | 355k | } |
149 | 355k | return( 1 ); |
150 | 355k | } |
151 | | |
152 | | /* Reads the values header from an extent description string |
153 | | * Returns the number of bytes read if successful, or -1 on error |
154 | | */ |
155 | | int libvmdk_extent_values_read( |
156 | | libvmdk_extent_values_t *extent_values, |
157 | | const char *value_string, |
158 | | size_t value_string_size, |
159 | | int encoding, |
160 | | libcerror_error_t **error ) |
161 | 355k | { |
162 | 355k | libcsplit_narrow_split_string_t *values = NULL; |
163 | 355k | const char *filename = NULL; |
164 | 355k | static char *function = "libvmdk_extent_values_read"; |
165 | 355k | char *value_string_segment = NULL; |
166 | 355k | size_t filename_length = 0; |
167 | 355k | size_t value_string_index = 0; |
168 | 355k | size_t value_string_length = 0; |
169 | 355k | size_t value_string_segment_size = 0; |
170 | 355k | uint64_t value_64bit = 0; |
171 | 355k | int number_of_values = 0; |
172 | | |
173 | 355k | if( extent_values == NULL ) |
174 | 0 | { |
175 | 0 | libcerror_error_set( |
176 | 0 | error, |
177 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
178 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
179 | 0 | "%s: invalid extent values.", |
180 | 0 | function ); |
181 | |
|
182 | 0 | return( -1 ); |
183 | 0 | } |
184 | 355k | if( extent_values->filename != NULL ) |
185 | 0 | { |
186 | 0 | libcerror_error_set( |
187 | 0 | error, |
188 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
189 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
190 | 0 | "%s: invalid extent values - filename value already set.", |
191 | 0 | function ); |
192 | |
|
193 | 0 | return( -1 ); |
194 | 0 | } |
195 | 355k | if( value_string == NULL ) |
196 | 0 | { |
197 | 0 | libcerror_error_set( |
198 | 0 | error, |
199 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
200 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
201 | 0 | "%s: invalid value string.", |
202 | 0 | function ); |
203 | |
|
204 | 0 | return( -1 ); |
205 | 0 | } |
206 | 355k | if( value_string_size < 10 ) |
207 | 107 | { |
208 | 107 | libcerror_error_set( |
209 | 107 | error, |
210 | 107 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
211 | 107 | LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, |
212 | 107 | "%s: value string is too small.", |
213 | 107 | function ); |
214 | | |
215 | 107 | return( -1 ); |
216 | 107 | } |
217 | 355k | if( value_string_size > (size_t) SSIZE_MAX ) |
218 | 0 | { |
219 | 0 | libcerror_error_set( |
220 | 0 | error, |
221 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
222 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, |
223 | 0 | "%s: invalid value string size value exceeds maximum.", |
224 | 0 | function ); |
225 | |
|
226 | 0 | goto on_error; |
227 | 0 | } |
228 | | #if defined( HAVE_DEBUG_OUTPUT ) |
229 | | if( libcnotify_verbose != 0 ) |
230 | | { |
231 | | libcnotify_printf( |
232 | | "%s: value string\t\t\t\t: %s\n", |
233 | | function, |
234 | | value_string ); |
235 | | } |
236 | | #endif |
237 | | /* Look for the start of the filename since this value |
238 | | * can contain spaces, naive split cannot be used for it |
239 | | */ |
240 | 355k | for( value_string_index = 0; |
241 | 17.0M | value_string_index < value_string_size; |
242 | 16.6M | value_string_index++ ) |
243 | 17.0M | { |
244 | 17.0M | if( ( value_string[ value_string_index ] == '"' ) |
245 | 17.0M | || ( value_string[ value_string_index ] == '\'' ) ) |
246 | 348k | { |
247 | 348k | break; |
248 | 348k | } |
249 | 17.0M | } |
250 | 355k | if( value_string_index >= value_string_size ) |
251 | 7.72k | { |
252 | | /* No filename was found in the extent values |
253 | | */ |
254 | 7.72k | value_string_length = value_string_index - 1; |
255 | 7.72k | value_string_size = 0; |
256 | 7.72k | } |
257 | 348k | else |
258 | 348k | { |
259 | 348k | value_string_length = value_string_index - 1; |
260 | | |
261 | 348k | value_string_index++; |
262 | | |
263 | 348k | filename = &( value_string[ value_string_index ] ); |
264 | | |
265 | | /* Look for the end of the filename |
266 | | */ |
267 | 348k | for( filename_length = value_string_size - 1; |
268 | 2.37M | filename_length > value_string_index; |
269 | 2.02M | filename_length-- ) |
270 | 2.37M | { |
271 | 2.37M | if( ( value_string[ filename_length ] == '"' ) |
272 | 2.37M | || ( value_string[ filename_length ] == '\'' ) ) |
273 | 348k | { |
274 | 348k | break; |
275 | 348k | } |
276 | 2.37M | } |
277 | 348k | if( filename_length <= value_string_index ) |
278 | 45 | { |
279 | 45 | libcerror_error_set( |
280 | 45 | error, |
281 | 45 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
282 | 45 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
283 | 45 | "%s: invalid value string missing filename value.", |
284 | 45 | function ); |
285 | | |
286 | 45 | goto on_error; |
287 | 45 | } |
288 | 348k | filename_length -= value_string_index; |
289 | | |
290 | 348k | value_string_index += filename_length + 2; |
291 | 348k | value_string_size -= value_string_index; |
292 | 348k | } |
293 | 355k | if( libcsplit_narrow_string_split( |
294 | 355k | value_string, |
295 | 355k | value_string_length + 1, |
296 | 355k | ' ', |
297 | 355k | &values, |
298 | 355k | error ) != 1 ) |
299 | 0 | { |
300 | 0 | libcerror_error_set( |
301 | 0 | error, |
302 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
303 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
304 | 0 | "%s: unable to get values from string.", |
305 | 0 | function ); |
306 | |
|
307 | 0 | goto on_error; |
308 | 0 | } |
309 | 355k | if( libcsplit_narrow_split_string_get_number_of_segments( |
310 | 355k | values, |
311 | 355k | &number_of_values, |
312 | 355k | error ) != 1 ) |
313 | 3 | { |
314 | 3 | libcerror_error_set( |
315 | 3 | error, |
316 | 3 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
317 | 3 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
318 | 3 | "%s: unable to retrieve number of values.", |
319 | 3 | function ); |
320 | | |
321 | 3 | goto on_error; |
322 | 3 | } |
323 | 355k | if( number_of_values != 3 ) |
324 | 226 | { |
325 | 226 | libcerror_error_set( |
326 | 226 | error, |
327 | 226 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
328 | 226 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
329 | 226 | "%s: unsupported number of extent values: %d.", |
330 | 226 | function, |
331 | 226 | number_of_values ); |
332 | | |
333 | 226 | goto on_error; |
334 | 226 | } |
335 | | /* The extent value: 0 contains the access |
336 | | */ |
337 | 355k | if( libcsplit_narrow_split_string_get_segment_by_index( |
338 | 355k | values, |
339 | 355k | 0, |
340 | 355k | &value_string_segment, |
341 | 355k | &value_string_segment_size, |
342 | 355k | error ) != 1 ) |
343 | 0 | { |
344 | 0 | libcerror_error_set( |
345 | 0 | error, |
346 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
347 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
348 | 0 | "%s: unable to retrieve value: 0.", |
349 | 0 | function ); |
350 | |
|
351 | 0 | goto on_error; |
352 | 0 | } |
353 | 355k | if( value_string_segment == NULL ) |
354 | 0 | { |
355 | 0 | libcerror_error_set( |
356 | 0 | error, |
357 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
358 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
359 | 0 | "%s: missing value string segment: 0.", |
360 | 0 | function ); |
361 | |
|
362 | 0 | goto on_error; |
363 | 0 | } |
364 | | #if defined( HAVE_DEBUG_OUTPUT ) |
365 | | if( libcnotify_verbose != 0 ) |
366 | | { |
367 | | libcnotify_printf( |
368 | | "%s: access\t\t\t\t\t: %s\n", |
369 | | function, |
370 | | value_string_segment ); |
371 | | } |
372 | | #endif |
373 | 355k | if( ( value_string_segment_size == 3 ) |
374 | 355k | && ( narrow_string_compare( |
375 | 354k | value_string_segment, |
376 | 354k | "RW", |
377 | 354k | 2 ) == 0 ) ) |
378 | 354k | { |
379 | 354k | extent_values->access = LIBVMDK_EXTENT_ACCESS_READ_WRITE; |
380 | 354k | } |
381 | 637 | else if( ( value_string_segment_size == 7 ) |
382 | 637 | && ( narrow_string_compare( |
383 | 210 | value_string_segment, |
384 | 210 | "RDONLY", |
385 | 210 | 6 ) == 0 ) ) |
386 | 195 | { |
387 | 195 | extent_values->access = LIBVMDK_EXTENT_ACCESS_READ; |
388 | 195 | } |
389 | 442 | else if( ( value_string_segment_size == 9 ) |
390 | 442 | && ( narrow_string_compare( |
391 | 267 | value_string_segment, |
392 | 267 | "NOACCESS", |
393 | 267 | 8 ) == 0 ) ) |
394 | 254 | { |
395 | 254 | extent_values->access = LIBVMDK_EXTENT_ACCESS_NONE; |
396 | 254 | } |
397 | 188 | else |
398 | 188 | { |
399 | 188 | libcerror_error_set( |
400 | 188 | error, |
401 | 188 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
402 | 188 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
403 | 188 | "%s: unsupported extent access.", |
404 | 188 | function ); |
405 | | |
406 | 188 | goto on_error; |
407 | 188 | } |
408 | | /* The extent value: 1 contains the number of sectors |
409 | | */ |
410 | 355k | if( libcsplit_narrow_split_string_get_segment_by_index( |
411 | 355k | values, |
412 | 355k | 1, |
413 | 355k | &value_string_segment, |
414 | 355k | &value_string_segment_size, |
415 | 355k | error ) != 1 ) |
416 | 0 | { |
417 | 0 | libcerror_error_set( |
418 | 0 | error, |
419 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
420 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
421 | 0 | "%s: unable to retrieve value: 1.", |
422 | 0 | function ); |
423 | |
|
424 | 0 | goto on_error; |
425 | 0 | } |
426 | 355k | if( value_string_segment == NULL ) |
427 | 0 | { |
428 | 0 | libcerror_error_set( |
429 | 0 | error, |
430 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
431 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
432 | 0 | "%s: missing value string segment: 1.", |
433 | 0 | function ); |
434 | |
|
435 | 0 | goto on_error; |
436 | 0 | } |
437 | | #if defined( HAVE_DEBUG_OUTPUT ) |
438 | | if( libcnotify_verbose != 0 ) |
439 | | { |
440 | | libcnotify_printf( |
441 | | "%s: number of sectors\t\t\t\t: %s\n", |
442 | | function, |
443 | | value_string_segment ); |
444 | | } |
445 | | #endif |
446 | 355k | if( libfvalue_utf8_string_copy_to_integer( |
447 | 355k | (uint8_t *) value_string_segment, |
448 | 355k | value_string_segment_size, |
449 | 355k | &value_64bit, |
450 | 355k | 64, |
451 | 355k | LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED, |
452 | 355k | error ) != 1 ) |
453 | 1 | { |
454 | 1 | libcerror_error_set( |
455 | 1 | error, |
456 | 1 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
457 | 1 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
458 | 1 | "%s: unable to determine number of sectors value from string.", |
459 | 1 | function ); |
460 | | |
461 | 1 | goto on_error; |
462 | 1 | } |
463 | 355k | if( value_64bit > (uint64_t) ( INT64_MAX / 512 ) ) |
464 | 16 | { |
465 | 16 | libcerror_error_set( |
466 | 16 | error, |
467 | 16 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
468 | 16 | LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, |
469 | 16 | "%s: invalid extent number of sectors value exceeds maximum.", |
470 | 16 | function ); |
471 | | |
472 | 16 | goto on_error; |
473 | 16 | } |
474 | 355k | extent_values->size = (size64_t) value_64bit * 512; |
475 | | |
476 | | /* The extent value: 2 contains the type |
477 | | */ |
478 | 355k | if( libcsplit_narrow_split_string_get_segment_by_index( |
479 | 355k | values, |
480 | 355k | 2, |
481 | 355k | &value_string_segment, |
482 | 355k | &value_string_segment_size, |
483 | 355k | error ) != 1 ) |
484 | 0 | { |
485 | 0 | libcerror_error_set( |
486 | 0 | error, |
487 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
488 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
489 | 0 | "%s: unable to retrieve value: 2.", |
490 | 0 | function ); |
491 | |
|
492 | 0 | goto on_error; |
493 | 0 | } |
494 | 355k | if( value_string_segment == NULL ) |
495 | 0 | { |
496 | 0 | libcerror_error_set( |
497 | 0 | error, |
498 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
499 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
500 | 0 | "%s: missing value string segment: 2.", |
501 | 0 | function ); |
502 | |
|
503 | 0 | goto on_error; |
504 | 0 | } |
505 | | #if defined( HAVE_DEBUG_OUTPUT ) |
506 | | if( libcnotify_verbose != 0 ) |
507 | | { |
508 | | libcnotify_printf( |
509 | | "%s: type\t\t\t\t\t: %s\n", |
510 | | function, |
511 | | value_string_segment ); |
512 | | } |
513 | | #endif |
514 | 355k | if( ( value_string_segment_size == 5 ) |
515 | 355k | && ( narrow_string_compare( |
516 | 354k | value_string_segment, |
517 | 354k | "FLAT", |
518 | 354k | 4 ) == 0 ) ) |
519 | 345k | { |
520 | 345k | extent_values->type = LIBVMDK_EXTENT_TYPE_FLAT; |
521 | 345k | } |
522 | 9.59k | else if( ( value_string_segment_size == 5 ) |
523 | 9.59k | && ( narrow_string_compare( |
524 | 8.28k | value_string_segment, |
525 | 8.28k | "VMFS", |
526 | 8.28k | 4 ) == 0 ) ) |
527 | 1.21k | { |
528 | 1.21k | extent_values->type = LIBVMDK_EXTENT_TYPE_VMFS_FLAT; |
529 | 1.21k | } |
530 | 8.38k | else if( ( value_string_segment_size == 5 ) |
531 | 8.38k | && ( narrow_string_compare( |
532 | 7.07k | value_string_segment, |
533 | 7.07k | "ZERO", |
534 | 7.07k | 4 ) == 0 ) ) |
535 | 7.07k | { |
536 | 7.07k | extent_values->type = LIBVMDK_EXTENT_TYPE_ZERO; |
537 | 7.07k | } |
538 | 1.30k | else if( ( value_string_segment_size == 7 ) |
539 | 1.30k | && ( narrow_string_compare( |
540 | 429 | value_string_segment, |
541 | 429 | "SPARSE", |
542 | 429 | 6 ) == 0 ) ) |
543 | 427 | { |
544 | 427 | extent_values->type = LIBVMDK_EXTENT_TYPE_SPARSE; |
545 | 427 | } |
546 | 880 | else if( ( value_string_segment_size == 8 ) |
547 | 880 | && ( narrow_string_compare( |
548 | 413 | value_string_segment, |
549 | 413 | "VMFSRAW", |
550 | 413 | 7 ) == 0 ) ) |
551 | 213 | { |
552 | 213 | extent_values->type = LIBVMDK_EXTENT_TYPE_VMFS_RAW; |
553 | 213 | } |
554 | 667 | else if( ( value_string_segment_size == 8 ) |
555 | 667 | && ( narrow_string_compare( |
556 | 200 | value_string_segment, |
557 | 200 | "VMFSRDM", |
558 | 200 | 7 ) == 0 ) ) |
559 | 195 | { |
560 | 195 | extent_values->type = LIBVMDK_EXTENT_TYPE_VMFS_RDM; |
561 | 195 | } |
562 | 472 | else if( ( value_string_segment_size == 11 ) |
563 | 472 | && ( narrow_string_compare( |
564 | 269 | value_string_segment, |
565 | 269 | "VMFSSPARSE", |
566 | 269 | 10 ) == 0 ) ) |
567 | 253 | { |
568 | 253 | extent_values->type = LIBVMDK_EXTENT_TYPE_VMFS_SPARSE; |
569 | 253 | } |
570 | 219 | else |
571 | 219 | { |
572 | 219 | libcerror_error_set( |
573 | 219 | error, |
574 | 219 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
575 | 219 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
576 | 219 | "%s: unsupported extent type.", |
577 | 219 | function ); |
578 | | |
579 | 219 | goto on_error; |
580 | 219 | } |
581 | 355k | if( libcsplit_narrow_split_string_free( |
582 | 355k | &values, |
583 | 355k | error ) != 1 ) |
584 | 0 | { |
585 | 0 | libcerror_error_set( |
586 | 0 | error, |
587 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
588 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
589 | 0 | "%s: unable to free values.", |
590 | 0 | function ); |
591 | |
|
592 | 0 | goto on_error; |
593 | 0 | } |
594 | 355k | if( ( filename_length == 0 ) |
595 | 355k | && ( extent_values->type != LIBVMDK_EXTENT_TYPE_ZERO ) ) |
596 | 38 | { |
597 | 38 | libcerror_error_set( |
598 | 38 | error, |
599 | 38 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
600 | 38 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
601 | 38 | "%s: missing value string segment: 3 filename.", |
602 | 38 | function ); |
603 | | |
604 | 38 | goto on_error; |
605 | 38 | } |
606 | 355k | if( filename_length > 0 ) |
607 | 347k | { |
608 | | /* The extent value: 3 contains the filename |
609 | | */ |
610 | 347k | if( libvmdk_extent_values_set_filename( |
611 | 347k | extent_values, |
612 | 347k | filename, |
613 | 347k | filename_length, |
614 | 347k | encoding, |
615 | 347k | error ) != 1 ) |
616 | 0 | { |
617 | 0 | libcerror_error_set( |
618 | 0 | error, |
619 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
620 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
621 | 0 | "%s: unable to set filename.", |
622 | 0 | function ); |
623 | |
|
624 | 0 | goto on_error; |
625 | 0 | } |
626 | | #if defined( HAVE_DEBUG_OUTPUT ) |
627 | | if( libcnotify_verbose != 0 ) |
628 | | { |
629 | | if( encoding != 0 ) |
630 | | { |
631 | | if( libvmdk_debug_print_string_value( |
632 | | function, |
633 | | "filename\t\t\t\t\t", |
634 | | extent_values->filename, |
635 | | extent_values->filename_size, |
636 | | encoding, |
637 | | error ) != 1 ) |
638 | | { |
639 | | libcerror_error_set( |
640 | | error, |
641 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
642 | | LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, |
643 | | "%s: unable to print string value.", |
644 | | function ); |
645 | | |
646 | | goto on_error; |
647 | | } |
648 | | } |
649 | | else |
650 | | { |
651 | | if( libvmdk_debug_print_utf8_string_value( |
652 | | function, |
653 | | "filename\t\t\t\t\t", |
654 | | extent_values->filename, |
655 | | extent_values->filename_size, |
656 | | error ) != 1 ) |
657 | | { |
658 | | libcerror_error_set( |
659 | | error, |
660 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
661 | | LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, |
662 | | "%s: unable to print UTF-8 string value.", |
663 | | function ); |
664 | | |
665 | | goto on_error; |
666 | | } |
667 | | } |
668 | | } |
669 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
670 | 347k | } |
671 | 355k | if( value_string_size > 0 ) |
672 | 13.4k | { |
673 | 13.4k | if( libcsplit_narrow_string_split( |
674 | 13.4k | &( value_string[ value_string_index ] ), |
675 | 13.4k | value_string_size, |
676 | 13.4k | ' ', |
677 | 13.4k | &values, |
678 | 13.4k | error ) != 1 ) |
679 | 0 | { |
680 | 0 | libcerror_error_set( |
681 | 0 | error, |
682 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
683 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
684 | 0 | "%s: unable to get values from string.", |
685 | 0 | function ); |
686 | |
|
687 | 0 | goto on_error; |
688 | 0 | } |
689 | 13.4k | if( libcsplit_narrow_split_string_get_number_of_segments( |
690 | 13.4k | values, |
691 | 13.4k | &number_of_values, |
692 | 13.4k | error ) != 1 ) |
693 | 6 | { |
694 | 6 | libcerror_error_set( |
695 | 6 | error, |
696 | 6 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
697 | 6 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
698 | 6 | "%s: unable to retrieve number of values.", |
699 | 6 | function ); |
700 | | |
701 | 6 | goto on_error; |
702 | 6 | } |
703 | 13.4k | if( libcsplit_narrow_split_string_get_segment_by_index( |
704 | 13.4k | values, |
705 | 13.4k | 0, |
706 | 13.4k | &value_string_segment, |
707 | 13.4k | &value_string_segment_size, |
708 | 13.4k | error ) != 1 ) |
709 | 0 | { |
710 | 0 | libcerror_error_set( |
711 | 0 | error, |
712 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
713 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
714 | 0 | "%s: unable to retrieve value: 0.", |
715 | 0 | function ); |
716 | |
|
717 | 0 | goto on_error; |
718 | 0 | } |
719 | 13.4k | if( value_string_segment == NULL ) |
720 | 0 | { |
721 | 0 | libcerror_error_set( |
722 | 0 | error, |
723 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
724 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
725 | 0 | "%s: missing value string segment: 4.", |
726 | 0 | function ); |
727 | |
|
728 | 0 | goto on_error; |
729 | 0 | } |
730 | | /* The extent value: 4 contains the offset |
731 | | */ |
732 | | #if defined( HAVE_DEBUG_OUTPUT ) |
733 | | if( libcnotify_verbose != 0 ) |
734 | | { |
735 | | libcnotify_printf( |
736 | | "%s: offset\t\t\t\t\t: %s\n", |
737 | | function, |
738 | | value_string_segment ); |
739 | | } |
740 | | #endif |
741 | 13.4k | if( libfvalue_utf8_string_copy_to_integer( |
742 | 13.4k | (uint8_t *) value_string_segment, |
743 | 13.4k | value_string_segment_size, |
744 | 13.4k | &value_64bit, |
745 | 13.4k | 64, |
746 | 13.4k | LIBFVALUE_INTEGER_FORMAT_TYPE_DECIMAL_UNSIGNED, |
747 | 13.4k | error ) != 1 ) |
748 | 17 | { |
749 | 17 | libcerror_error_set( |
750 | 17 | error, |
751 | 17 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
752 | 17 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
753 | 17 | "%s: unable to determine offset value from string.", |
754 | 17 | function ); |
755 | | |
756 | 17 | goto on_error; |
757 | 17 | } |
758 | 13.4k | if( value_64bit > (uint64_t) INT64_MAX ) |
759 | 50 | { |
760 | 50 | libcerror_error_set( |
761 | 50 | error, |
762 | 50 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
763 | 50 | LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, |
764 | 50 | "%s: invalid extent offset value exceeds maximum.", |
765 | 50 | function ); |
766 | | |
767 | 50 | goto on_error; |
768 | 50 | } |
769 | 13.3k | extent_values->offset = (off64_t) value_64bit; |
770 | | |
771 | | #if defined( HAVE_DEBUG_OUTPUT ) |
772 | | if( libcnotify_verbose != 0 ) |
773 | | { |
774 | | if( number_of_values > 1 ) |
775 | | { |
776 | | if( libcsplit_narrow_split_string_get_segment_by_index( |
777 | | values, |
778 | | 1, |
779 | | &value_string_segment, |
780 | | &value_string_segment_size, |
781 | | error ) != 1 ) |
782 | | { |
783 | | libcerror_error_set( |
784 | | error, |
785 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
786 | | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
787 | | "%s: unable to retrieve value: 1.", |
788 | | function ); |
789 | | |
790 | | goto on_error; |
791 | | } |
792 | | if( value_string_segment == NULL ) |
793 | | { |
794 | | libcerror_error_set( |
795 | | error, |
796 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
797 | | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
798 | | "%s: missing value string segment: 5.", |
799 | | function ); |
800 | | |
801 | | goto on_error; |
802 | | } |
803 | | libcnotify_printf( |
804 | | "%s: string segment 5\t\t\t: %s\n", |
805 | | function, |
806 | | value_string_segment ); |
807 | | } |
808 | | if( number_of_values > 2 ) |
809 | | { |
810 | | if( libcsplit_narrow_split_string_get_segment_by_index( |
811 | | values, |
812 | | 2, |
813 | | &value_string_segment, |
814 | | &value_string_segment_size, |
815 | | error ) != 1 ) |
816 | | { |
817 | | libcerror_error_set( |
818 | | error, |
819 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
820 | | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
821 | | "%s: unable to retrieve value: 1.", |
822 | | function ); |
823 | | |
824 | | goto on_error; |
825 | | } |
826 | | if( value_string_segment == NULL ) |
827 | | { |
828 | | libcerror_error_set( |
829 | | error, |
830 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
831 | | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
832 | | "%s: missing value string segment: 6.", |
833 | | function ); |
834 | | |
835 | | goto on_error; |
836 | | } |
837 | | libcnotify_printf( |
838 | | "%s: string segment 6\t\t\t: %s\n", |
839 | | function, |
840 | | value_string_segment ); |
841 | | } |
842 | | } |
843 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
844 | | |
845 | 13.3k | if( libcsplit_narrow_split_string_free( |
846 | 13.3k | &values, |
847 | 13.3k | error ) != 1 ) |
848 | 0 | { |
849 | 0 | libcerror_error_set( |
850 | 0 | error, |
851 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
852 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
853 | 0 | "%s: unable to free values.", |
854 | 0 | function ); |
855 | |
|
856 | 0 | goto on_error; |
857 | 0 | } |
858 | 13.3k | } |
859 | | #if defined( HAVE_DEBUG_OUTPUT ) |
860 | | if( libcnotify_verbose != 0 ) |
861 | | { |
862 | | libcnotify_printf( |
863 | | "\n" ); |
864 | | } |
865 | | #endif |
866 | 354k | return( 1 ); |
867 | | |
868 | 809 | on_error: |
869 | 809 | if( values != NULL ) |
870 | 717 | { |
871 | 717 | libcsplit_narrow_split_string_free( |
872 | 717 | &values, |
873 | 717 | NULL ); |
874 | 717 | } |
875 | 809 | if( extent_values->filename != NULL ) |
876 | 73 | { |
877 | 73 | memory_free( |
878 | 73 | extent_values->filename ); |
879 | | |
880 | 73 | extent_values->filename = NULL; |
881 | 73 | } |
882 | 809 | extent_values->filename_size = 0; |
883 | | |
884 | 809 | return( -1 ); |
885 | 355k | } |
886 | | |
887 | | /* Sets the filename |
888 | | * Returns 1 if successful or -1 on error |
889 | | */ |
890 | | int libvmdk_extent_values_set_filename( |
891 | | libvmdk_extent_values_t *extent_values, |
892 | | const char *filename, |
893 | | size_t filename_length, |
894 | | int encoding, |
895 | | libcerror_error_t **error ) |
896 | 347k | { |
897 | 347k | static char *function = "libvmdk_extent_values_set_filename"; |
898 | | |
899 | 347k | if( extent_values == NULL ) |
900 | 0 | { |
901 | 0 | libcerror_error_set( |
902 | 0 | error, |
903 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
904 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
905 | 0 | "%s: invalid extent values.", |
906 | 0 | function ); |
907 | |
|
908 | 0 | return( -1 ); |
909 | 0 | } |
910 | 347k | if( extent_values->filename != NULL ) |
911 | 0 | { |
912 | 0 | libcerror_error_set( |
913 | 0 | error, |
914 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
915 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
916 | 0 | "%s: invalid extent values - filename value already set.", |
917 | 0 | function ); |
918 | |
|
919 | 0 | return( -1 ); |
920 | 0 | } |
921 | 347k | if( filename == NULL ) |
922 | 0 | { |
923 | 0 | libcerror_error_set( |
924 | 0 | error, |
925 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
926 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
927 | 0 | "%s: invalid filename.", |
928 | 0 | function ); |
929 | |
|
930 | 0 | return( -1 ); |
931 | 0 | } |
932 | 347k | if( ( filename_length == 0 ) |
933 | 347k | || ( filename_length > ( (size_t) MEMORY_MAXIMUM_ALLOCATION_SIZE - 1 ) ) ) |
934 | 0 | { |
935 | 0 | libcerror_error_set( |
936 | 0 | error, |
937 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
938 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, |
939 | 0 | "%s: invalid filename length value out of bounds.", |
940 | 0 | function ); |
941 | |
|
942 | 0 | return( -1 ); |
943 | 0 | } |
944 | 347k | extent_values->filename_size = filename_length + 1; |
945 | | |
946 | 347k | extent_values->filename = (uint8_t *) memory_allocate( |
947 | 347k | sizeof( uint8_t ) * extent_values->filename_size ); |
948 | | |
949 | 347k | if( extent_values->filename == NULL ) |
950 | 0 | { |
951 | 0 | libcerror_error_set( |
952 | 0 | error, |
953 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
954 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
955 | 0 | "%s: unable to create filename.", |
956 | 0 | function ); |
957 | |
|
958 | 0 | goto on_error; |
959 | 0 | } |
960 | 347k | if( memory_copy( |
961 | 347k | extent_values->filename, |
962 | 347k | filename, |
963 | 347k | filename_length ) == NULL ) |
964 | 0 | { |
965 | 0 | libcerror_error_set( |
966 | 0 | error, |
967 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
968 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
969 | 0 | "%s: unable to copy filename.", |
970 | 0 | function ); |
971 | |
|
972 | 0 | goto on_error; |
973 | 0 | } |
974 | 347k | extent_values->filename[ filename_length ] = 0; |
975 | | |
976 | 347k | extent_values->filename_encoding = encoding; |
977 | | |
978 | 347k | return( 1 ); |
979 | | |
980 | 0 | on_error: |
981 | 0 | if( extent_values->filename != NULL ) |
982 | 0 | { |
983 | 0 | memory_free( |
984 | 0 | extent_values->filename ); |
985 | |
|
986 | 0 | extent_values->filename = NULL; |
987 | 0 | } |
988 | 0 | extent_values->filename_size = 0; |
989 | |
|
990 | 0 | return( -1 ); |
991 | 347k | } |
992 | | |
993 | | /* Sets the alternate filename |
994 | | * Returns 1 if successful or -1 on error |
995 | | */ |
996 | | int libvmdk_extent_values_set_alternate_filename( |
997 | | libvmdk_extent_values_t *extent_values, |
998 | | const char *filename, |
999 | | size_t filename_length, |
1000 | | libcerror_error_t **error ) |
1001 | 0 | { |
1002 | 0 | static char *function = "libvmdk_extent_values_set_alternate_filename"; |
1003 | |
|
1004 | 0 | if( extent_values == NULL ) |
1005 | 0 | { |
1006 | 0 | libcerror_error_set( |
1007 | 0 | error, |
1008 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1009 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1010 | 0 | "%s: invalid extent values.", |
1011 | 0 | function ); |
1012 | |
|
1013 | 0 | return( -1 ); |
1014 | 0 | } |
1015 | 0 | if( extent_values->alternate_filename != NULL ) |
1016 | 0 | { |
1017 | 0 | libcerror_error_set( |
1018 | 0 | error, |
1019 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1020 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
1021 | 0 | "%s: invalid extent values - alternate filename value already set.", |
1022 | 0 | function ); |
1023 | |
|
1024 | 0 | return( -1 ); |
1025 | 0 | } |
1026 | 0 | if( filename == NULL ) |
1027 | 0 | { |
1028 | 0 | libcerror_error_set( |
1029 | 0 | error, |
1030 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1031 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1032 | 0 | "%s: invalid filename.", |
1033 | 0 | function ); |
1034 | |
|
1035 | 0 | return( -1 ); |
1036 | 0 | } |
1037 | 0 | if( ( filename_length == 0 ) |
1038 | 0 | || ( filename_length > ( (size_t) SSIZE_MAX - 1 ) ) ) |
1039 | 0 | { |
1040 | 0 | libcerror_error_set( |
1041 | 0 | error, |
1042 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1043 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, |
1044 | 0 | "%s: invalid filename length value out of bounds.", |
1045 | 0 | function ); |
1046 | |
|
1047 | 0 | return( -1 ); |
1048 | 0 | } |
1049 | 0 | if( libvmdk_system_string_size_from_narrow_string( |
1050 | 0 | filename, |
1051 | 0 | filename_length + 1, |
1052 | 0 | &( extent_values->alternate_filename_size ), |
1053 | 0 | error ) != 1 ) |
1054 | 0 | { |
1055 | 0 | libcerror_error_set( |
1056 | 0 | error, |
1057 | 0 | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
1058 | 0 | LIBCERROR_CONVERSION_ERROR_GENERIC, |
1059 | 0 | "%s: unable to determine alternate filename size.", |
1060 | 0 | function ); |
1061 | |
|
1062 | 0 | goto on_error; |
1063 | 0 | } |
1064 | 0 | if( ( extent_values->alternate_filename_size == 0 ) |
1065 | 0 | || ( extent_values->alternate_filename_size > ( (size_t) SSIZE_MAX / sizeof( system_character_t ) ) ) ) |
1066 | 0 | { |
1067 | 0 | libcerror_error_set( |
1068 | 0 | error, |
1069 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1070 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
1071 | 0 | "%s: invalid file IO handle - alternate filename size value out of bounds.", |
1072 | 0 | function ); |
1073 | |
|
1074 | 0 | goto on_error; |
1075 | 0 | } |
1076 | 0 | extent_values->alternate_filename = system_string_allocate( |
1077 | 0 | extent_values->alternate_filename_size ); |
1078 | |
|
1079 | 0 | if( extent_values->alternate_filename == NULL ) |
1080 | 0 | { |
1081 | 0 | libcerror_error_set( |
1082 | 0 | error, |
1083 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
1084 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
1085 | 0 | "%s: unable to create alternate filename.", |
1086 | 0 | function ); |
1087 | |
|
1088 | 0 | goto on_error; |
1089 | 0 | } |
1090 | 0 | if( libvmdk_system_string_copy_from_narrow_string( |
1091 | 0 | extent_values->alternate_filename, |
1092 | 0 | extent_values->alternate_filename_size, |
1093 | 0 | filename, |
1094 | 0 | filename_length + 1, |
1095 | 0 | error ) != 1 ) |
1096 | 0 | { |
1097 | 0 | libcerror_error_set( |
1098 | 0 | error, |
1099 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1100 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
1101 | 0 | "%s: unable to copy alternate filename.", |
1102 | 0 | function ); |
1103 | |
|
1104 | 0 | goto on_error; |
1105 | 0 | } |
1106 | 0 | return( 1 ); |
1107 | | |
1108 | 0 | on_error: |
1109 | 0 | if( extent_values->alternate_filename != NULL ) |
1110 | 0 | { |
1111 | 0 | memory_free( |
1112 | 0 | extent_values->alternate_filename ); |
1113 | |
|
1114 | 0 | extent_values->alternate_filename = NULL; |
1115 | 0 | } |
1116 | 0 | extent_values->alternate_filename_size = 0; |
1117 | |
|
1118 | 0 | return( -1 ); |
1119 | 0 | } |
1120 | | |
1121 | | #if defined( HAVE_WIDE_CHARACTER_TYPE ) |
1122 | | |
1123 | | /* Sets the alternate filename |
1124 | | * Returns 1 if successful or -1 on error |
1125 | | */ |
1126 | | int libvmdk_extent_values_set_alternate_filename_wide( |
1127 | | libvmdk_extent_values_t *extent_values, |
1128 | | const wchar_t *filename, |
1129 | | size_t filename_length, |
1130 | | libcerror_error_t **error ) |
1131 | | { |
1132 | | static char *function = "libvmdk_extent_values_set_alternate_filename_wide"; |
1133 | | |
1134 | | if( extent_values == NULL ) |
1135 | | { |
1136 | | libcerror_error_set( |
1137 | | error, |
1138 | | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1139 | | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1140 | | "%s: invalid extent values.", |
1141 | | function ); |
1142 | | |
1143 | | return( -1 ); |
1144 | | } |
1145 | | if( extent_values->alternate_filename != NULL ) |
1146 | | { |
1147 | | libcerror_error_set( |
1148 | | error, |
1149 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1150 | | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
1151 | | "%s: invalid extent values - alternate filename value already set.", |
1152 | | function ); |
1153 | | |
1154 | | return( -1 ); |
1155 | | } |
1156 | | if( filename == NULL ) |
1157 | | { |
1158 | | libcerror_error_set( |
1159 | | error, |
1160 | | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1161 | | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1162 | | "%s: invalid filename.", |
1163 | | function ); |
1164 | | |
1165 | | return( -1 ); |
1166 | | } |
1167 | | if( ( filename_length == 0 ) |
1168 | | || ( filename_length > ( (size_t) SSIZE_MAX - 1 ) ) ) |
1169 | | { |
1170 | | libcerror_error_set( |
1171 | | error, |
1172 | | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1173 | | LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, |
1174 | | "%s: invalid filename length value out of bounds.", |
1175 | | function ); |
1176 | | |
1177 | | return( -1 ); |
1178 | | } |
1179 | | if( libvmdk_system_string_size_from_wide_string( |
1180 | | filename, |
1181 | | filename_length + 1, |
1182 | | &( extent_values->alternate_filename_size ), |
1183 | | error ) != 1 ) |
1184 | | { |
1185 | | libcerror_error_set( |
1186 | | error, |
1187 | | LIBCERROR_ERROR_DOMAIN_CONVERSION, |
1188 | | LIBCERROR_CONVERSION_ERROR_GENERIC, |
1189 | | "%s: unable to determine alternate filename size.", |
1190 | | function ); |
1191 | | |
1192 | | goto on_error; |
1193 | | } |
1194 | | if( ( extent_values->alternate_filename_size == 0 ) |
1195 | | || ( extent_values->alternate_filename_size > ( (size_t) SSIZE_MAX / sizeof( system_character_t ) ) ) ) |
1196 | | { |
1197 | | libcerror_error_set( |
1198 | | error, |
1199 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1200 | | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
1201 | | "%s: invalid file IO handle - alternate filename size value out of bounds.", |
1202 | | function ); |
1203 | | |
1204 | | goto on_error; |
1205 | | } |
1206 | | extent_values->alternate_filename = system_string_allocate( |
1207 | | extent_values->alternate_filename_size ); |
1208 | | |
1209 | | if( extent_values->alternate_filename == NULL ) |
1210 | | { |
1211 | | libcerror_error_set( |
1212 | | error, |
1213 | | LIBCERROR_ERROR_DOMAIN_MEMORY, |
1214 | | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
1215 | | "%s: unable to create alternate filename.", |
1216 | | function ); |
1217 | | |
1218 | | goto on_error; |
1219 | | } |
1220 | | if( libvmdk_system_string_copy_from_wide_string( |
1221 | | extent_values->alternate_filename, |
1222 | | extent_values->alternate_filename_size, |
1223 | | filename, |
1224 | | filename_length + 1, |
1225 | | error ) != 1 ) |
1226 | | { |
1227 | | libcerror_error_set( |
1228 | | error, |
1229 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1230 | | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
1231 | | "%s: unable to copy alternate filename.", |
1232 | | function ); |
1233 | | |
1234 | | goto on_error; |
1235 | | } |
1236 | | return( 1 ); |
1237 | | |
1238 | | on_error: |
1239 | | if( extent_values->alternate_filename != NULL ) |
1240 | | { |
1241 | | memory_free( |
1242 | | extent_values->alternate_filename ); |
1243 | | |
1244 | | extent_values->alternate_filename = NULL; |
1245 | | } |
1246 | | extent_values->alternate_filename_size = 0; |
1247 | | |
1248 | | return( -1 ); |
1249 | | } |
1250 | | |
1251 | | #endif /* defined( HAVE_WIDE_CHARACTER_TYPE ) */ |
1252 | | |
1253 | | /* Retrieves the extent type |
1254 | | * Returns 1 if successful or -1 on error |
1255 | | */ |
1256 | | int libvmdk_extent_values_get_type( |
1257 | | libvmdk_extent_values_t *extent_values, |
1258 | | int *type, |
1259 | | libcerror_error_t **error ) |
1260 | 0 | { |
1261 | 0 | static char *function = "libvmdk_extent_values_get_type"; |
1262 | |
|
1263 | 0 | if( extent_values == NULL ) |
1264 | 0 | { |
1265 | 0 | libcerror_error_set( |
1266 | 0 | error, |
1267 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1268 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1269 | 0 | "%s: invalid extent values.", |
1270 | 0 | function ); |
1271 | |
|
1272 | 0 | return( -1 ); |
1273 | 0 | } |
1274 | 0 | if( type == NULL ) |
1275 | 0 | { |
1276 | 0 | libcerror_error_set( |
1277 | 0 | error, |
1278 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1279 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1280 | 0 | "%s: invalid type.", |
1281 | 0 | function ); |
1282 | |
|
1283 | 0 | return( -1 ); |
1284 | 0 | } |
1285 | 0 | *type = extent_values->type; |
1286 | |
|
1287 | 0 | return( 1 ); |
1288 | 0 | } |
1289 | | |
1290 | | /* Retrieves the extent range (offset and size) |
1291 | | * Returns 1 if successful or -1 on error |
1292 | | */ |
1293 | | int libvmdk_extent_values_get_range( |
1294 | | libvmdk_extent_values_t *extent_values, |
1295 | | off64_t *offset, |
1296 | | size64_t *size, |
1297 | | libcerror_error_t **error ) |
1298 | 0 | { |
1299 | 0 | static char *function = "libvmdk_extent_values_get_range"; |
1300 | |
|
1301 | 0 | if( extent_values == NULL ) |
1302 | 0 | { |
1303 | 0 | libcerror_error_set( |
1304 | 0 | error, |
1305 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1306 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1307 | 0 | "%s: invalid extent values.", |
1308 | 0 | function ); |
1309 | |
|
1310 | 0 | return( -1 ); |
1311 | 0 | } |
1312 | 0 | if( offset == NULL ) |
1313 | 0 | { |
1314 | 0 | libcerror_error_set( |
1315 | 0 | error, |
1316 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1317 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1318 | 0 | "%s: invalid offset.", |
1319 | 0 | function ); |
1320 | |
|
1321 | 0 | return( -1 ); |
1322 | 0 | } |
1323 | 0 | if( size == NULL ) |
1324 | 0 | { |
1325 | 0 | libcerror_error_set( |
1326 | 0 | error, |
1327 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1328 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1329 | 0 | "%s: invalid size.", |
1330 | 0 | function ); |
1331 | |
|
1332 | 0 | return( -1 ); |
1333 | 0 | } |
1334 | 0 | *offset = extent_values->offset; |
1335 | 0 | *size = extent_values->size; |
1336 | |
|
1337 | 0 | return( 1 ); |
1338 | 0 | } |
1339 | | |
1340 | | /* Retrieves the size of the UTF-8 encoded filename |
1341 | | * The returned size includes the end of string character |
1342 | | * Returns 1 if successful, 0 if not available or -1 on error |
1343 | | */ |
1344 | | int libvmdk_extent_values_get_utf8_filename_size( |
1345 | | libvmdk_extent_values_t *extent_values, |
1346 | | size_t *utf8_string_size, |
1347 | | libcerror_error_t **error ) |
1348 | 0 | { |
1349 | 0 | static char *function = "libvmdk_extent_values_get_utf8_filename_size"; |
1350 | 0 | int result = 0; |
1351 | |
|
1352 | 0 | if( extent_values == NULL ) |
1353 | 0 | { |
1354 | 0 | libcerror_error_set( |
1355 | 0 | error, |
1356 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1357 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1358 | 0 | "%s: invalid extent values.", |
1359 | 0 | function ); |
1360 | |
|
1361 | 0 | return( -1 ); |
1362 | 0 | } |
1363 | 0 | if( ( extent_values->filename == NULL ) |
1364 | 0 | || ( extent_values->filename_size == 0 ) ) |
1365 | 0 | { |
1366 | 0 | return( 0 ); |
1367 | 0 | } |
1368 | 0 | if( extent_values->filename_encoding != 0 ) |
1369 | 0 | { |
1370 | 0 | result = libuna_utf8_string_size_from_byte_stream( |
1371 | 0 | extent_values->filename, |
1372 | 0 | extent_values->filename_size, |
1373 | 0 | extent_values->filename_encoding, |
1374 | 0 | utf8_string_size, |
1375 | 0 | error ); |
1376 | 0 | } |
1377 | 0 | else |
1378 | 0 | { |
1379 | 0 | result = libuna_utf8_string_size_from_utf8_stream( |
1380 | 0 | extent_values->filename, |
1381 | 0 | extent_values->filename_size, |
1382 | 0 | utf8_string_size, |
1383 | 0 | error ); |
1384 | 0 | } |
1385 | 0 | if( result != 1 ) |
1386 | 0 | { |
1387 | 0 | libcerror_error_set( |
1388 | 0 | error, |
1389 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1390 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1391 | 0 | "%s: unable to retrieve UTF-8 string size.", |
1392 | 0 | function ); |
1393 | |
|
1394 | 0 | return( -1 ); |
1395 | 0 | } |
1396 | 0 | return( 1 ); |
1397 | 0 | } |
1398 | | |
1399 | | /* Retrieves the UTF-8 encoded filename |
1400 | | * The size should include the end of string character |
1401 | | * Returns 1 if successful, 0 if not available or -1 on error |
1402 | | */ |
1403 | | int libvmdk_extent_values_get_utf8_filename( |
1404 | | libvmdk_extent_values_t *extent_values, |
1405 | | uint8_t *utf8_string, |
1406 | | size_t utf8_string_size, |
1407 | | libcerror_error_t **error ) |
1408 | 0 | { |
1409 | 0 | static char *function = "libvmdk_extent_values_get_utf8_filename"; |
1410 | 0 | int result = 0; |
1411 | |
|
1412 | 0 | if( extent_values == NULL ) |
1413 | 0 | { |
1414 | 0 | libcerror_error_set( |
1415 | 0 | error, |
1416 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1417 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1418 | 0 | "%s: invalid extent values.", |
1419 | 0 | function ); |
1420 | |
|
1421 | 0 | return( -1 ); |
1422 | 0 | } |
1423 | 0 | if( ( extent_values->filename == NULL ) |
1424 | 0 | || ( extent_values->filename_size == 0 ) ) |
1425 | 0 | { |
1426 | 0 | return( 0 ); |
1427 | 0 | } |
1428 | 0 | if( extent_values->filename_encoding != 0 ) |
1429 | 0 | { |
1430 | 0 | result = libuna_utf8_string_copy_from_byte_stream( |
1431 | 0 | utf8_string, |
1432 | 0 | utf8_string_size, |
1433 | 0 | extent_values->filename, |
1434 | 0 | extent_values->filename_size, |
1435 | 0 | extent_values->filename_encoding, |
1436 | 0 | error ); |
1437 | 0 | } |
1438 | 0 | else |
1439 | 0 | { |
1440 | 0 | result = libuna_utf8_string_copy_from_utf8_stream( |
1441 | 0 | utf8_string, |
1442 | 0 | utf8_string_size, |
1443 | 0 | extent_values->filename, |
1444 | 0 | extent_values->filename_size, |
1445 | 0 | error ); |
1446 | 0 | } |
1447 | 0 | if( result != 1 ) |
1448 | 0 | { |
1449 | 0 | libcerror_error_set( |
1450 | 0 | error, |
1451 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1452 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1453 | 0 | "%s: unable to retrieve UTF-8 string size.", |
1454 | 0 | function ); |
1455 | |
|
1456 | 0 | return( -1 ); |
1457 | 0 | } |
1458 | 0 | return( 1 ); |
1459 | 0 | } |
1460 | | |
1461 | | /* Retrieves the size of the UTF-16 encoded filename |
1462 | | * The returned size includes the end of string character |
1463 | | * Returns 1 if successful, 0 if not available or -1 on error |
1464 | | */ |
1465 | | int libvmdk_extent_values_get_utf16_filename_size( |
1466 | | libvmdk_extent_values_t *extent_values, |
1467 | | size_t *utf16_string_size, |
1468 | | libcerror_error_t **error ) |
1469 | 0 | { |
1470 | 0 | static char *function = "libvmdk_extent_values_get_utf16_filename_size"; |
1471 | 0 | int result = 0; |
1472 | |
|
1473 | 0 | if( extent_values == NULL ) |
1474 | 0 | { |
1475 | 0 | libcerror_error_set( |
1476 | 0 | error, |
1477 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1478 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1479 | 0 | "%s: invalid extent values.", |
1480 | 0 | function ); |
1481 | |
|
1482 | 0 | return( -1 ); |
1483 | 0 | } |
1484 | 0 | if( ( extent_values->filename == NULL ) |
1485 | 0 | || ( extent_values->filename_size == 0 ) ) |
1486 | 0 | { |
1487 | 0 | return( 0 ); |
1488 | 0 | } |
1489 | 0 | if( extent_values->filename_encoding != 0 ) |
1490 | 0 | { |
1491 | 0 | result = libuna_utf16_string_size_from_byte_stream( |
1492 | 0 | extent_values->filename, |
1493 | 0 | extent_values->filename_size, |
1494 | 0 | extent_values->filename_encoding, |
1495 | 0 | utf16_string_size, |
1496 | 0 | error ); |
1497 | 0 | } |
1498 | 0 | else |
1499 | 0 | { |
1500 | 0 | result = libuna_utf16_string_size_from_utf8_stream( |
1501 | 0 | extent_values->filename, |
1502 | 0 | extent_values->filename_size, |
1503 | 0 | utf16_string_size, |
1504 | 0 | error ); |
1505 | 0 | } |
1506 | 0 | if( result != 1 ) |
1507 | 0 | { |
1508 | 0 | libcerror_error_set( |
1509 | 0 | error, |
1510 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1511 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1512 | 0 | "%s: unable to retrieve UTF-16 string size.", |
1513 | 0 | function ); |
1514 | |
|
1515 | 0 | return( -1 ); |
1516 | 0 | } |
1517 | 0 | return( 1 ); |
1518 | 0 | } |
1519 | | |
1520 | | /* Retrieves the UTF-16 encoded filename |
1521 | | * The size should include the end of string character |
1522 | | * Returns 1 if successful, 0 if not available or -1 on error |
1523 | | */ |
1524 | | int libvmdk_extent_values_get_utf16_filename( |
1525 | | libvmdk_extent_values_t *extent_values, |
1526 | | uint16_t *utf16_string, |
1527 | | size_t utf16_string_size, |
1528 | | libcerror_error_t **error ) |
1529 | 0 | { |
1530 | 0 | static char *function = "libvmdk_extent_values_get_utf16_filename"; |
1531 | 0 | int result = 0; |
1532 | |
|
1533 | 0 | if( extent_values == NULL ) |
1534 | 0 | { |
1535 | 0 | libcerror_error_set( |
1536 | 0 | error, |
1537 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1538 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1539 | 0 | "%s: invalid extent values.", |
1540 | 0 | function ); |
1541 | |
|
1542 | 0 | return( -1 ); |
1543 | 0 | } |
1544 | 0 | if( ( extent_values->filename == NULL ) |
1545 | 0 | || ( extent_values->filename_size == 0 ) ) |
1546 | 0 | { |
1547 | 0 | return( 0 ); |
1548 | 0 | } |
1549 | 0 | if( extent_values->filename_encoding != 0 ) |
1550 | 0 | { |
1551 | 0 | result = libuna_utf16_string_copy_from_byte_stream( |
1552 | 0 | utf16_string, |
1553 | 0 | utf16_string_size, |
1554 | 0 | extent_values->filename, |
1555 | 0 | extent_values->filename_size, |
1556 | 0 | extent_values->filename_encoding, |
1557 | 0 | error ); |
1558 | 0 | } |
1559 | 0 | else |
1560 | 0 | { |
1561 | 0 | result = libuna_utf16_string_copy_from_utf8_stream( |
1562 | 0 | utf16_string, |
1563 | 0 | utf16_string_size, |
1564 | 0 | extent_values->filename, |
1565 | 0 | extent_values->filename_size, |
1566 | 0 | error ); |
1567 | 0 | } |
1568 | 0 | if( result != 1 ) |
1569 | 0 | { |
1570 | 0 | libcerror_error_set( |
1571 | 0 | error, |
1572 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1573 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1574 | 0 | "%s: unable to retrieve UTF-16 string size.", |
1575 | 0 | function ); |
1576 | |
|
1577 | 0 | return( -1 ); |
1578 | 0 | } |
1579 | 0 | return( 1 ); |
1580 | 0 | } |
1581 | | |