| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 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 |
#if defined( HAVE_SYS_STAT_H ) |
| 30 |
#include <sys/stat.h> |
| 31 |
#endif |
| 32 |
|
| 33 |
#include "mount_file_entry.h" |
| 34 |
#include "mount_file_system.h" |
| 35 |
#include "vhditools_libcerror.h" |
| 36 |
#include "vhditools_libvhdi.h" |
| 37 |
|
| 38 |
#if !defined( S_IFDIR ) |
| 39 |
#define S_IFDIR 0x4000 |
| 40 |
#endif |
| 41 |
|
| 42 |
#if !defined( S_IFREG ) |
| 43 |
#define S_IFREG 0x8000 |
| 44 |
#endif |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
int mount_file_entry_initialize( |
| 51 |
mount_file_entry_t **file_entry, |
| 52 |
mount_file_system_t *file_system, |
| 53 |
const system_character_t *name, |
| 54 |
size_t name_length, |
| 55 |
libvhdi_file_t *vhdi_file, |
| 56 |
libcerror_error_t **error ) |
| 57 |
{ |
| 58 |
static char *function = "mount_file_entry_initialize"; |
| 59 |
|
| 60 |
if( file_entry == NULL ) |
| 61 |
{ |
| 62 |
libcerror_error_set( |
| 63 |
error, |
| 64 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 65 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 66 |
"%s: invalid file entry.", |
| 67 |
function ); |
| 68 |
|
| 69 |
return( -1 ); |
| 70 |
} |
| 71 |
if( *file_entry != NULL ) |
| 72 |
{ |
| 73 |
libcerror_error_set( |
| 74 |
error, |
| 75 |
LIBCERROR_ERROR_DOMAIN_RUNTIME, |
| 76 |
LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
| 77 |
"%s: invalid file entry value already set.", |
| 78 |
function ); |
| 79 |
|
| 80 |
return( -1 ); |
| 81 |
} |
| 82 |
if( file_system == NULL ) |
| 83 |
{ |
| 84 |
libcerror_error_set( |
| 85 |
error, |
| 86 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 87 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 88 |
"%s: invalid file system.", |
| 89 |
function ); |
| 90 |
|
| 91 |
return( -1 ); |
| 92 |
} |
| 93 |
if( name_length > (size_t) ( SSIZE_MAX - 1 ) ) |
| 94 |
{ |
| 95 |
libcerror_error_set( |
| 96 |
error, |
| 97 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 98 |
LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
| 99 |
"%s: invalid name length value exceeds maximum.", |
| 100 |
function ); |
| 101 |
|
| 102 |
return( -1 ); |
| 103 |
} |
| 104 |
*file_entry = memory_allocate_structure( |
| 105 |
mount_file_entry_t ); |
| 106 |
|
| 107 |
if( *file_entry == NULL ) |
| 108 |
{ |
| 109 |
libcerror_error_set( |
| 110 |
error, |
| 111 |
LIBCERROR_ERROR_DOMAIN_MEMORY, |
| 112 |
LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
| 113 |
"%s: unable to create file entry.", |
| 114 |
function ); |
| 115 |
|
| 116 |
goto on_error; |
| 117 |
} |
| 118 |
if( memory_set( |
| 119 |
*file_entry, |
| 120 |
0, |
| 121 |
sizeof( mount_file_entry_t ) ) == NULL ) |
| 122 |
{ |
| 123 |
libcerror_error_set( |
| 124 |
error, |
| 125 |
LIBCERROR_ERROR_DOMAIN_MEMORY, |
| 126 |
LIBCERROR_MEMORY_ERROR_SET_FAILED, |
| 127 |
"%s: unable to clear file entry.", |
| 128 |
function ); |
| 129 |
|
| 130 |
memory_free( |
| 131 |
*file_entry ); |
| 132 |
|
| 133 |
*file_entry = NULL; |
| 134 |
|
| 135 |
return( -1 ); |
| 136 |
} |
| 137 |
( *file_entry )->file_system = file_system; |
| 138 |
|
| 139 |
if( name != NULL ) |
| 140 |
{ |
| 141 |
( *file_entry )->name = system_string_allocate( |
| 142 |
name_length + 1 ); |
| 143 |
|
| 144 |
if( ( *file_entry )->name == NULL ) |
| 145 |
{ |
| 146 |
libcerror_error_set( |
| 147 |
error, |
| 148 |
LIBCERROR_ERROR_DOMAIN_MEMORY, |
| 149 |
LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
| 150 |
"%s: unable to create name string.", |
| 151 |
function ); |
| 152 |
|
| 153 |
goto on_error; |
| 154 |
} |
| 155 |
if( name_length > 0 ) |
| 156 |
{ |
| 157 |
if( system_string_copy( |
| 158 |
( *file_entry )->name, |
| 159 |
name, |
| 160 |
name_length ) == NULL ) |
| 161 |
{ |
| 162 |
libcerror_error_set( |
| 163 |
error, |
| 164 |
LIBCERROR_ERROR_DOMAIN_RUNTIME, |
| 165 |
LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
| 166 |
"%s: unable to copy name.", |
| 167 |
function ); |
| 168 |
|
| 169 |
goto on_error; |
| 170 |
} |
| 171 |
} |
| 172 |
( *file_entry )->name[ name_length ] = 0; |
| 173 |
|
| 174 |
( *file_entry )->name_size = name_length + 1; |
| 175 |
} |
| 176 |
( *file_entry )->vhdi_file = vhdi_file; |
| 177 |
|
| 178 |
return( 1 ); |
| 179 |
|
| 180 |
on_error: |
| 181 |
if( *file_entry != NULL ) |
| 182 |
{ |
| 183 |
if( ( *file_entry )->name != NULL ) |
| 184 |
{ |
| 185 |
memory_free( |
| 186 |
( *file_entry )->name ); |
| 187 |
} |
| 188 |
memory_free( |
| 189 |
*file_entry ); |
| 190 |
|
| 191 |
*file_entry = NULL; |
| 192 |
} |
| 193 |
return( -1 ); |
| 194 |
} |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
int mount_file_entry_free( |
| 200 |
mount_file_entry_t **file_entry, |
| 201 |
libcerror_error_t **error ) |
| 202 |
{ |
| 203 |
static char *function = "mount_file_entry_free"; |
| 204 |
|
| 205 |
if( file_entry == NULL ) |
| 206 |
{ |
| 207 |
libcerror_error_set( |
| 208 |
error, |
| 209 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 210 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 211 |
"%s: invalid file entry.", |
| 212 |
function ); |
| 213 |
|
| 214 |
return( -1 ); |
| 215 |
} |
| 216 |
if( *file_entry != NULL ) |
| 217 |
{ |
| 218 |
if( ( *file_entry )->name != NULL ) |
| 219 |
{ |
| 220 |
memory_free( |
| 221 |
( *file_entry )->name ); |
| 222 |
} |
| 223 |
memory_free( |
| 224 |
*file_entry ); |
| 225 |
|
| 226 |
*file_entry = NULL; |
| 227 |
} |
| 228 |
return( 1 ); |
| 229 |
} |
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
int mount_file_entry_get_parent_file_entry( |
| 235 |
mount_file_entry_t *file_entry, |
| 236 |
mount_file_entry_t **parent_file_entry, |
| 237 |
libcerror_error_t **error ) |
| 238 |
{ |
| 239 |
static char *function = "mount_file_entry_get_parent_file_entry"; |
| 240 |
|
| 241 |
if( file_entry == NULL ) |
| 242 |
{ |
| 243 |
libcerror_error_set( |
| 244 |
error, |
| 245 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 246 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 247 |
"%s: invalid file entry.", |
| 248 |
function ); |
| 249 |
|
| 250 |
return( -1 ); |
| 251 |
} |
| 252 |
if( parent_file_entry == NULL ) |
| 253 |
{ |
| 254 |
libcerror_error_set( |
| 255 |
error, |
| 256 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 257 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 258 |
"%s: invalid parent file entry.", |
| 259 |
function ); |
| 260 |
|
| 261 |
return( -1 ); |
| 262 |
} |
| 263 |
if( *parent_file_entry != NULL ) |
| 264 |
{ |
| 265 |
libcerror_error_set( |
| 266 |
error, |
| 267 |
LIBCERROR_ERROR_DOMAIN_RUNTIME, |
| 268 |
LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
| 269 |
"%s: invalid parent file entry value already set.", |
| 270 |
function ); |
| 271 |
|
| 272 |
return( -1 ); |
| 273 |
} |
| 274 |
if( file_entry->vhdi_file != NULL ) |
| 275 |
{ |
| 276 |
if( mount_file_entry_initialize( |
| 277 |
parent_file_entry, |
| 278 |
file_entry->file_system, |
| 279 |
_SYSTEM_STRING( "" ), |
| 280 |
0, |
| 281 |
NULL, |
| 282 |
error ) != 1 ) |
| 283 |
{ |
| 284 |
libcerror_error_set( |
| 285 |
error, |
| 286 |
LIBCERROR_ERROR_DOMAIN_RUNTIME, |
| 287 |
LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
| 288 |
"%s: unable to initialize parent file entry.", |
| 289 |
function ); |
| 290 |
|
| 291 |
return( -1 ); |
| 292 |
} |
| 293 |
return( 1 ); |
| 294 |
} |
| 295 |
return( 0 ); |
| 296 |
} |
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
int mount_file_entry_get_creation_time( |
| 304 |
mount_file_entry_t *file_entry, |
| 305 |
uint64_t *creation_time, |
| 306 |
libcerror_error_t **error ) |
| 307 |
{ |
| 308 |
static char *function = "mount_file_entry_get_creation_time"; |
| 309 |
|
| 310 |
if( file_entry == NULL ) |
| 311 |
{ |
| 312 |
libcerror_error_set( |
| 313 |
error, |
| 314 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 315 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 316 |
"%s: invalid file entry.", |
| 317 |
function ); |
| 318 |
|
| 319 |
return( -1 ); |
| 320 |
} |
| 321 |
if( mount_file_system_get_mounted_timestamp( |
| 322 |
file_entry->file_system, |
| 323 |
creation_time, |
| 324 |
error ) != 1 ) |
| 325 |
{ |
| 326 |
libcerror_error_set( |
| 327 |
error, |
| 328 |
LIBCERROR_ERROR_DOMAIN_RUNTIME, |
| 329 |
LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
| 330 |
"%s: unable to retrieve mounted timestamp.", |
| 331 |
function ); |
| 332 |
|
| 333 |
return( -1 ); |
| 334 |
} |
| 335 |
return( 1 ); |
| 336 |
} |
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
int mount_file_entry_get_access_time( |
| 344 |
mount_file_entry_t *file_entry, |
| 345 |
uint64_t *access_time, |
| 346 |
libcerror_error_t **error ) |
| 347 |
{ |
| 348 |
static char *function = "mount_file_entry_get_access_time"; |
| 349 |
|
| 350 |
if( file_entry == NULL ) |
| 351 |
{ |
| 352 |
libcerror_error_set( |
| 353 |
error, |
| 354 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 355 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 356 |
"%s: invalid file entry.", |
| 357 |
function ); |
| 358 |
|
| 359 |
return( -1 ); |
| 360 |
} |
| 361 |
if( mount_file_system_get_mounted_timestamp( |
| 362 |
file_entry->file_system, |
| 363 |
access_time, |
| 364 |
error ) != 1 ) |
| 365 |
{ |
| 366 |
libcerror_error_set( |
| 367 |
error, |
| 368 |
LIBCERROR_ERROR_DOMAIN_RUNTIME, |
| 369 |
LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
| 370 |
"%s: unable to retrieve mounted timestamp.", |
| 371 |
function ); |
| 372 |
|
| 373 |
return( -1 ); |
| 374 |
} |
| 375 |
return( 1 ); |
| 376 |
} |
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
int mount_file_entry_get_modification_time( |
| 384 |
mount_file_entry_t *file_entry, |
| 385 |
uint64_t *modification_time, |
| 386 |
libcerror_error_t **error ) |
| 387 |
{ |
| 388 |
static char *function = "mount_file_entry_get_modification_time"; |
| 389 |
|
| 390 |
if( file_entry == NULL ) |
| 391 |
{ |
| 392 |
libcerror_error_set( |
| 393 |
error, |
| 394 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 395 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 396 |
"%s: invalid file entry.", |
| 397 |
function ); |
| 398 |
|
| 399 |
return( -1 ); |
| 400 |
} |
| 401 |
if( mount_file_system_get_mounted_timestamp( |
| 402 |
file_entry->file_system, |
| 403 |
modification_time, |
| 404 |
error ) != 1 ) |
| 405 |
{ |
| 406 |
libcerror_error_set( |
| 407 |
error, |
| 408 |
LIBCERROR_ERROR_DOMAIN_RUNTIME, |
| 409 |
LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
| 410 |
"%s: unable to retrieve mounted timestamp.", |
| 411 |
function ); |
| 412 |
|
| 413 |
return( -1 ); |
| 414 |
} |
| 415 |
return( 1 ); |
| 416 |
} |
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
int mount_file_entry_get_inode_change_time( |
| 424 |
mount_file_entry_t *file_entry, |
| 425 |
uint64_t *inode_change_time, |
| 426 |
libcerror_error_t **error ) |
| 427 |
{ |
| 428 |
static char *function = "mount_file_entry_get_inode_change_time"; |
| 429 |
|
| 430 |
if( file_entry == NULL ) |
| 431 |
{ |
| 432 |
libcerror_error_set( |
| 433 |
error, |
| 434 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 435 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 436 |
"%s: invalid file entry.", |
| 437 |
function ); |
| 438 |
|
| 439 |
return( -1 ); |
| 440 |
} |
| 441 |
if( mount_file_system_get_mounted_timestamp( |
| 442 |
file_entry->file_system, |
| 443 |
inode_change_time, |
| 444 |
error ) != 1 ) |
| 445 |
{ |
| 446 |
libcerror_error_set( |
| 447 |
error, |
| 448 |
LIBCERROR_ERROR_DOMAIN_RUNTIME, |
| 449 |
LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
| 450 |
"%s: unable to retrieve mounted timestamp.", |
| 451 |
function ); |
| 452 |
|
| 453 |
return( -1 ); |
| 454 |
} |
| 455 |
return( 1 ); |
| 456 |
} |
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
int mount_file_entry_get_file_mode( |
| 462 |
mount_file_entry_t *file_entry, |
| 463 |
uint16_t *file_mode, |
| 464 |
libcerror_error_t **error ) |
| 465 |
{ |
| 466 |
static char *function = "mount_file_entry_get_file_mode"; |
| 467 |
|
| 468 |
if( file_entry == NULL ) |
| 469 |
{ |
| 470 |
libcerror_error_set( |
| 471 |
error, |
| 472 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 473 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 474 |
"%s: invalid file entry.", |
| 475 |
function ); |
| 476 |
|
| 477 |
return( -1 ); |
| 478 |
} |
| 479 |
if( file_mode == NULL ) |
| 480 |
{ |
| 481 |
libcerror_error_set( |
| 482 |
error, |
| 483 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 484 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 485 |
"%s: invalid file mode.", |
| 486 |
function ); |
| 487 |
|
| 488 |
return( -1 ); |
| 489 |
} |
| 490 |
if( file_entry->vhdi_file == NULL ) |
| 491 |
{ |
| 492 |
*file_mode = S_IFDIR | 0555; |
| 493 |
} |
| 494 |
else |
| 495 |
{ |
| 496 |
*file_mode = S_IFREG | 0444; |
| 497 |
} |
| 498 |
return( 1 ); |
| 499 |
} |
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
int mount_file_entry_get_name_size( |
| 506 |
mount_file_entry_t *file_entry, |
| 507 |
size_t *string_size, |
| 508 |
libcerror_error_t **error ) |
| 509 |
{ |
| 510 |
static char *function = "mount_file_entry_get_name_size"; |
| 511 |
|
| 512 |
if( file_entry == NULL ) |
| 513 |
{ |
| 514 |
libcerror_error_set( |
| 515 |
error, |
| 516 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 517 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 518 |
"%s: invalid file entry.", |
| 519 |
function ); |
| 520 |
|
| 521 |
return( -1 ); |
| 522 |
} |
| 523 |
if( string_size == NULL ) |
| 524 |
{ |
| 525 |
libcerror_error_set( |
| 526 |
error, |
| 527 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 528 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 529 |
"%s: invalid string size.", |
| 530 |
function ); |
| 531 |
|
| 532 |
return( -1 ); |
| 533 |
} |
| 534 |
*string_size = file_entry->name_size; |
| 535 |
|
| 536 |
return( 1 ); |
| 537 |
} |
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
int mount_file_entry_get_name( |
| 544 |
mount_file_entry_t *file_entry, |
| 545 |
system_character_t *string, |
| 546 |
size_t string_size, |
| 547 |
libcerror_error_t **error ) |
| 548 |
{ |
| 549 |
static char *function = "mount_file_entry_get_name"; |
| 550 |
|
| 551 |
if( file_entry == NULL ) |
| 552 |
{ |
| 553 |
libcerror_error_set( |
| 554 |
error, |
| 555 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 556 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 557 |
"%s: invalid file entry.", |
| 558 |
function ); |
| 559 |
|
| 560 |
return( -1 ); |
| 561 |
} |
| 562 |
if( file_entry->name == NULL ) |
| 563 |
{ |
| 564 |
libcerror_error_set( |
| 565 |
error, |
| 566 |
LIBCERROR_ERROR_DOMAIN_RUNTIME, |
| 567 |
LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
| 568 |
"%s: invalid file entry - missing name.", |
| 569 |
function ); |
| 570 |
|
| 571 |
return( -1 ); |
| 572 |
} |
| 573 |
if( string == NULL ) |
| 574 |
{ |
| 575 |
libcerror_error_set( |
| 576 |
error, |
| 577 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 578 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 579 |
"%s: invalid string.", |
| 580 |
function ); |
| 581 |
|
| 582 |
return( -1 ); |
| 583 |
} |
| 584 |
if( string_size > (size_t) SSIZE_MAX ) |
| 585 |
{ |
| 586 |
libcerror_error_set( |
| 587 |
error, |
| 588 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 589 |
LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
| 590 |
"%s: invalid string size value exceeds maximum.", |
| 591 |
function ); |
| 592 |
|
| 593 |
return( -1 ); |
| 594 |
} |
| 595 |
if( string_size < file_entry->name_size ) |
| 596 |
{ |
| 597 |
libcerror_error_set( |
| 598 |
error, |
| 599 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 600 |
LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, |
| 601 |
"%s: invalid string size value too small.", |
| 602 |
function ); |
| 603 |
|
| 604 |
return( -1 ); |
| 605 |
} |
| 606 |
if( system_string_copy( |
| 607 |
string, |
| 608 |
file_entry->name, |
| 609 |
file_entry->name_size ) == NULL ) |
| 610 |
{ |
| 611 |
libcerror_error_set( |
| 612 |
error, |
| 613 |
LIBCERROR_ERROR_DOMAIN_RUNTIME, |
| 614 |
LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
| 615 |
"%s: unable to copy name.", |
| 616 |
function ); |
| 617 |
|
| 618 |
return( -1 ); |
| 619 |
} |
| 620 |
string[ file_entry->name_size - 1 ] = 0; |
| 621 |
|
| 622 |
return( 1 ); |
| 623 |
} |
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
int mount_file_entry_get_number_of_sub_file_entries( |
| 629 |
mount_file_entry_t *file_entry, |
| 630 |
int *number_of_sub_file_entries, |
| 631 |
libcerror_error_t **error ) |
| 632 |
{ |
| 633 |
static char *function = "mount_file_entry_get_number_of_sub_file_entries"; |
| 634 |
int number_of_files = 0; |
| 635 |
|
| 636 |
if( file_entry == NULL ) |
| 637 |
{ |
| 638 |
libcerror_error_set( |
| 639 |
error, |
| 640 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 641 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 642 |
"%s: invalid file entry.", |
| 643 |
function ); |
| 644 |
|
| 645 |
return( -1 ); |
| 646 |
} |
| 647 |
if( number_of_sub_file_entries == NULL ) |
| 648 |
{ |
| 649 |
libcerror_error_set( |
| 650 |
error, |
| 651 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 652 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 653 |
"%s: invalid number of sub file entries.", |
| 654 |
function ); |
| 655 |
|
| 656 |
return( -1 ); |
| 657 |
} |
| 658 |
if( file_entry->vhdi_file == NULL ) |
| 659 |
{ |
| 660 |
if( mount_file_system_get_number_of_files( |
| 661 |
file_entry->file_system, |
| 662 |
&number_of_files, |
| 663 |
error ) != 1 ) |
| 664 |
{ |
| 665 |
libcerror_error_set( |
| 666 |
error, |
| 667 |
LIBCERROR_ERROR_DOMAIN_RUNTIME, |
| 668 |
LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
| 669 |
"%s: unable to retrieve number of files.", |
| 670 |
function ); |
| 671 |
|
| 672 |
return( -1 ); |
| 673 |
} |
| 674 |
if( ( number_of_files < 0 ) |
| 675 |
|| ( number_of_files > 999 ) ) |
| 676 |
{ |
| 677 |
libcerror_error_set( |
| 678 |
error, |
| 679 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 680 |
LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
| 681 |
"%s: unsupported number of files.", |
| 682 |
function ); |
| 683 |
|
| 684 |
return( -1 ); |
| 685 |
} |
| 686 |
} |
| 687 |
*number_of_sub_file_entries = number_of_files; |
| 688 |
|
| 689 |
return( 1 ); |
| 690 |
} |
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
int mount_file_entry_get_sub_file_entry_by_index( |
| 696 |
mount_file_entry_t *file_entry, |
| 697 |
int sub_file_entry_index, |
| 698 |
mount_file_entry_t **sub_file_entry, |
| 699 |
libcerror_error_t **error ) |
| 700 |
{ |
| 701 |
system_character_t path[ 32 ]; |
| 702 |
|
| 703 |
libvhdi_file_t *vhdi_file = NULL; |
| 704 |
static char *function = "mount_file_entry_get_sub_file_entry_by_index"; |
| 705 |
size_t path_length = 0; |
| 706 |
int number_of_sub_file_entries = 0; |
| 707 |
|
| 708 |
if( file_entry == NULL ) |
| 709 |
{ |
| 710 |
libcerror_error_set( |
| 711 |
error, |
| 712 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 713 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 714 |
"%s: invalid file entry.", |
| 715 |
function ); |
| 716 |
|
| 717 |
return( -1 ); |
| 718 |
} |
| 719 |
if( sub_file_entry == NULL ) |
| 720 |
{ |
| 721 |
libcerror_error_set( |
| 722 |
error, |
| 723 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 724 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 725 |
"%s: invalid sub file entry.", |
| 726 |
function ); |
| 727 |
|
| 728 |
return( -1 ); |
| 729 |
} |
| 730 |
if( *sub_file_entry != NULL ) |
| 731 |
{ |
| 732 |
libcerror_error_set( |
| 733 |
error, |
| 734 |
LIBCERROR_ERROR_DOMAIN_RUNTIME, |
| 735 |
LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
| 736 |
"%s: invalid sub file entry value already set.", |
| 737 |
function ); |
| 738 |
|
| 739 |
return( -1 ); |
| 740 |
} |
| 741 |
if( mount_file_entry_get_number_of_sub_file_entries( |
| 742 |
file_entry, |
| 743 |
&number_of_sub_file_entries, |
| 744 |
error ) != 1 ) |
| 745 |
{ |
| 746 |
libcerror_error_set( |
| 747 |
error, |
| 748 |
LIBCERROR_ERROR_DOMAIN_RUNTIME, |
| 749 |
LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
| 750 |
"%s: unable to retrieve number of sub file entries.", |
| 751 |
function ); |
| 752 |
|
| 753 |
return( -1 ); |
| 754 |
} |
| 755 |
if( ( sub_file_entry_index < 0 ) |
| 756 |
|| ( sub_file_entry_index >= number_of_sub_file_entries ) ) |
| 757 |
{ |
| 758 |
libcerror_error_set( |
| 759 |
error, |
| 760 |
LIBCERROR_ERROR_DOMAIN_RUNTIME, |
| 761 |
LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
| 762 |
"%s: invalid sub file entry index value out of bounds.", |
| 763 |
function ); |
| 764 |
|
| 765 |
return( -1 ); |
| 766 |
} |
| 767 |
if( mount_file_system_get_path_from_file_index( |
| 768 |
file_entry->file_system, |
| 769 |
sub_file_entry_index, |
| 770 |
path, |
| 771 |
32, |
| 772 |
error ) != 1 ) |
| 773 |
{ |
| 774 |
libcerror_error_set( |
| 775 |
error, |
| 776 |
LIBCERROR_ERROR_DOMAIN_RUNTIME, |
| 777 |
LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
| 778 |
"%s: unable to retrieve path for file entry: %d.", |
| 779 |
function, |
| 780 |
sub_file_entry_index ); |
| 781 |
|
| 782 |
return( -1 ); |
| 783 |
} |
| 784 |
if( mount_file_system_get_file_by_index( |
| 785 |
file_entry->file_system, |
| 786 |
sub_file_entry_index, |
| 787 |
&vhdi_file, |
| 788 |
error ) != 1 ) |
| 789 |
{ |
| 790 |
libcerror_error_set( |
| 791 |
error, |
| 792 |
LIBCERROR_ERROR_DOMAIN_RUNTIME, |
| 793 |
LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
| 794 |
"%s: unable to retrieve file: %d from file system.", |
| 795 |
function, |
| 796 |
sub_file_entry_index ); |
| 797 |
|
| 798 |
return( -1 ); |
| 799 |
} |
| 800 |
if( vhdi_file == NULL ) |
| 801 |
{ |
| 802 |
libcerror_error_set( |
| 803 |
error, |
| 804 |
LIBCERROR_ERROR_DOMAIN_RUNTIME, |
| 805 |
LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
| 806 |
"%s: missing file: %d.", |
| 807 |
function, |
| 808 |
sub_file_entry_index ); |
| 809 |
|
| 810 |
return( -1 ); |
| 811 |
} |
| 812 |
path_length = system_string_length( |
| 813 |
path ); |
| 814 |
|
| 815 |
if( mount_file_entry_initialize( |
| 816 |
sub_file_entry, |
| 817 |
file_entry->file_system, |
| 818 |
&( path[ 1 ] ), |
| 819 |
path_length - 1, |
| 820 |
vhdi_file, |
| 821 |
error ) != 1 ) |
| 822 |
{ |
| 823 |
libcerror_error_set( |
| 824 |
error, |
| 825 |
LIBCERROR_ERROR_DOMAIN_RUNTIME, |
| 826 |
LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
| 827 |
"%s: unable to initialize sub file entry: %d.", |
| 828 |
function, |
| 829 |
sub_file_entry_index ); |
| 830 |
|
| 831 |
return( -1 ); |
| 832 |
} |
| 833 |
return( 1 ); |
| 834 |
} |
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
ssize_t mount_file_entry_read_buffer_at_offset( |
| 840 |
mount_file_entry_t *file_entry, |
| 841 |
void *buffer, |
| 842 |
size_t buffer_size, |
| 843 |
off64_t offset, |
| 844 |
libcerror_error_t **error ) |
| 845 |
{ |
| 846 |
static char *function = "mount_file_entry_read_buffer_at_offset"; |
| 847 |
ssize_t read_count = 0; |
| 848 |
|
| 849 |
if( file_entry == NULL ) |
| 850 |
{ |
| 851 |
libcerror_error_set( |
| 852 |
error, |
| 853 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 854 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 855 |
"%s: invalid file entry.", |
| 856 |
function ); |
| 857 |
|
| 858 |
return( -1 ); |
| 859 |
} |
| 860 |
read_count = libvhdi_file_read_buffer_at_offset( |
| 861 |
file_entry->vhdi_file, |
| 862 |
buffer, |
| 863 |
buffer_size, |
| 864 |
offset, |
| 865 |
error ); |
| 866 |
|
| 867 |
if( read_count < 0 ) |
| 868 |
{ |
| 869 |
libcerror_error_set( |
| 870 |
error, |
| 871 |
LIBCERROR_ERROR_DOMAIN_IO, |
| 872 |
LIBCERROR_IO_ERROR_READ_FAILED, |
| 873 |
"%s: unable to read buffer at offset: %" PRIi64 " (0x%08" PRIx64 ") from file.", |
| 874 |
function, |
| 875 |
offset, |
| 876 |
offset ); |
| 877 |
|
| 878 |
return( -1 ); |
| 879 |
} |
| 880 |
return( read_count ); |
| 881 |
} |
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
int mount_file_entry_get_size( |
| 887 |
mount_file_entry_t *file_entry, |
| 888 |
size64_t *size, |
| 889 |
libcerror_error_t **error ) |
| 890 |
{ |
| 891 |
static char *function = "mount_file_entry_get_size"; |
| 892 |
|
| 893 |
if( file_entry == NULL ) |
| 894 |
{ |
| 895 |
libcerror_error_set( |
| 896 |
error, |
| 897 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 898 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 899 |
"%s: invalid file entry.", |
| 900 |
function ); |
| 901 |
|
| 902 |
return( -1 ); |
| 903 |
} |
| 904 |
if( file_entry->vhdi_file == NULL ) |
| 905 |
{ |
| 906 |
if( size == NULL ) |
| 907 |
{ |
| 908 |
libcerror_error_set( |
| 909 |
error, |
| 910 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 911 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 912 |
"%s: invalid size.", |
| 913 |
function ); |
| 914 |
|
| 915 |
return( -1 ); |
| 916 |
} |
| 917 |
*size = 0; |
| 918 |
} |
| 919 |
else |
| 920 |
{ |
| 921 |
if( libvhdi_file_get_media_size( |
| 922 |
file_entry->vhdi_file, |
| 923 |
size, |
| 924 |
error ) != 1 ) |
| 925 |
{ |
| 926 |
libcerror_error_set( |
| 927 |
error, |
| 928 |
LIBCERROR_ERROR_DOMAIN_RUNTIME, |
| 929 |
LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
| 930 |
"%s: unable to retrieve media size from file.", |
| 931 |
function ); |
| 932 |
|
| 933 |
return( -1 ); |
| 934 |
} |
| 935 |
} |
| 936 |
return( 1 ); |
| 937 |
} |
| 938 |
|