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

Function ntfs_copy

src/ntfs_dir.c:339–456  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

337enum { bufsize = 4096 };
338
339static copy_file_t ntfs_copy(disk_t *disk_car, const partition_t *partition, dir_data_t *dir_data, const file_info_t *file)
340{
341 const unsigned long int first_inode=file->st_ino;
342 ntfs_inode *inode;
343 struct ntfs_dir_struct *ls=(struct ntfs_dir_struct*)dir_data->private_dir_data;
344 copy_file_t res=CP_OK;
345 inode = ntfs_inode_open (ls->vol, first_inode);
346 if (!inode) {
347 log_error("ntfs_copy: ntfs_inode_open failed for %s\n", dir_data->current_directory);
348 return CP_STAT_FAILED;
349 }
350 {
351 char *buffer;
352 char *new_file;
353 ntfs_attr *attr=NULL;
354 FILE *f_out;
355 char *stream_name;
356 s64 offset;
357 u32 block_size;
358 buffer = (char *)MALLOC(bufsize);
359 if (!buffer)
360 {
361 ntfs_inode_close(inode);
362 return CP_NOMEM;
363 }
364 stream_name=strrchr(dir_data->current_directory, ':');
365 if(stream_name)
366 stream_name++;
367 if(stream_name != NULL)
368 {
369 ntfschar *stream_name_ucs=NULL;
370#ifdef NTFS_MBSTOUCS_HAVE_TWO_ARGUMENTS
371 const int len=ntfs_mbstoucs(stream_name, &stream_name_ucs);
372#else
373 const int len=ntfs_mbstoucs(stream_name, &stream_name_ucs, 0);
374#endif
375 if(len < 0)
376 log_error("ntfs_mbstoucs failed\n");
377 else
378 attr = ntfs_attr_open(inode, AT_DATA, stream_name_ucs, len);
379 }
380 else
381 attr = ntfs_attr_open(inode, AT_DATA, NULL, 0);
382 if (!attr)
383 {
384 log_error("Cannot find attribute type 0x%lx.\n", (long) AT_DATA);
385 free(buffer);
386 ntfs_inode_close(inode);
387 return CP_STAT_FAILED;
388 }
389 if ((inode->mft_no < 2) && (attr->type == AT_DATA))
390 block_size = ls->vol->mft_record_size;
391 else if (attr->type == AT_INDEX_ALLOCATION)
392 block_size = index_get_size(inode);
393 else
394 block_size = 0;
395#if defined(__CYGWIN__) || defined(__MINGW32__)
396 if(stream_name)

Callers

nothing calls this directly

Calls 4

MALLOCFunction · 0.85
index_get_sizeFunction · 0.85
fopen_localFunction · 0.85
set_dateFunction · 0.85

Tested by

no test coverage detected