MCPcopy Create free account
hub / github.com/cgsecurity/testdisk / reiser_copy

Function reiser_copy

src/rfs_dir.c:474–545  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

472}
473
474static copy_file_t reiser_copy(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const file_info_t *file)
475{
476 reiserfs_file_t *in;
477 FILE *f_out;
478 char *new_file;
479 struct rfs_dir_struct *ls=(struct rfs_dir_struct*)dir_data->private_dir_data;
480 copy_file_t error=CP_OK;
481 uint64_t file_size;
482 f_out=fopen_local(&new_file, dir_data->local_dir, dir_data->current_directory);
483 if(!f_out)
484 {
485 log_critical("Can't create file %s: %s\n", new_file, strerror(errno));
486 free(new_file);
487 return CP_CREATE_FAILED;
488 }
489 log_error("Try to open rfs file %s\n", dir_data->current_directory);
490 log_flush();
491 in=reiserfs_file_open(ls->current_fs, dir_data->current_directory, O_RDONLY);
492 if (in==NULL)
493 {
494 log_error("Error while opening rfs file %s\n", dir_data->current_directory);
495 free(new_file);
496 fclose(f_out);
497 return CP_OPEN_FAILED;
498 }
499 log_error("open rfs file %s done\n", dir_data->current_directory);
500 log_flush();
501 file_size = reiserfs_file_size(in);
502#if 0
503 /* TODO: do not use so much memory */
504 {
505 void *buf=MALLOC(file_size+1);
506 if (reiserfs_file_read(in, buf, file_size) != file_size)
507 {
508 log_error("Error while reading rfs file %s\n", dir_data->current_directory);
509 error = CP_READ_FAILED;
510 }
511 else if (fwrite(buf, file_size, 1, f_out) != 1)
512 {
513 log_error("Error while writing file %s\n", new_file);
514 error = CP_NOSPACE;
515 }
516 free(buf);
517 }
518#else
519 {
520 /* require progsreiserfs-file-read.patch */
521 char buf[4096];
522 while(file_size > 0)
523 {
524 int read_size=(file_size < sizeof(buf) ? file_size : sizeof(buf));
525 if (reiserfs_file_read(in, buf, read_size) == 0)
526 {
527 log_error("Error while reading rfs file %s\n", dir_data->current_directory);
528 error = CP_READ_FAILED;
529 }
530 else if (fwrite(buf, read_size, 1, f_out) != 1)
531 {

Callers

nothing calls this directly

Calls 5

fopen_localFunction · 0.85
log_flushFunction · 0.85
MALLOCFunction · 0.85
set_dateFunction · 0.85
set_modeFunction · 0.85

Tested by

no test coverage detected