Короче, предыдущий комент неправильный.Однако, данный исходник (и на кой и откуда вы его раскопали?) с элементами кроссплатформенности, но автор его под линуксом компилировать не пробовал.
Путем отделения лишнего он скомпилировался в таком виде:
#include <set>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/time.h>
#include <stdio.h>
#include <string.h>
void tor_copy( char *in_file, char * out_file, int show_data = 8192, int file_structure_size = 4096 );
using namespace std;
int main(int argc, char* argv[])
{
int show_data = 8192;
if( argc < 2 )
{
printf("Usage:\r\ntorcp <input_file> [<output file> show_data]");
return -1;
}
char output_fn[4096];
if( argc < 3 )
{
strcpy( output_fn, "ok_" );
strcat( output_fn, argv[1] );
}
else
{
strcpy( output_fn, argv[2] );
}
if( argc == 4 )
{
char *tmp;
show_data = strtoul( argv[3], &tmp, 10 );
}
tor_copy( argv[1], output_fn, show_data );
return 0;
}
#define u32 unsigned int
#define u64 unsigned long long
#define u16 unsigned short
struct tfs_item{
u32 index;
u32 offset_in_index;
u64 file_offset;
u16 peace_len;
bool operator<(const tfs_item& s) const
{
#define CMP(a, b) if(a < b) return true; if(a > b) return false;
CMP( index, s.index )
CMP( offset_in_index, s.offset_in_index)
#undef CMP
return false;
}
};
typedef multiset<tfs_item> item_list_set;
item_list_set il;
u32 time()
{
struct timeval t;
gettimeofday(&t, 0);
return t.tv_sec * 1000 + t.tv_usec / 1000;
}
void tor_copy( char *in_file, char * out_file, int show_data, int file_structure_size )
{
int hf = -1;
hf = ::open( in_file, O_RDONLY|O_LARGEFILE, 0644);
if( hf == - 1 )
{
printf("can't open in file\r\n");
return;
}
lseek64( hf, show_data, SEEK_SET );
u64 next_offset;
tfs_item tmp;
u64 index_size = 0x8000;
u32 index_count = 0;
u32 last_index_size = 0;
tfs_item *lpBufer = new tfs_item[file_structure_size];
int readx;
u32 tick = time();
while( 1 )
{
readx = read( hf, lpBufer, sizeof( tfs_item ) * file_structure_size );
readx /= sizeof( tfs_item );
for( int c = 0; c < readx; c++ )
{
memcpy( &tmp, &lpBufer[ c ], sizeof( tfs_item ) );
if( tmp.index == -1 )
{
lseek64( hf, tmp.file_offset, SEEK_SET );
break;
}
if( tmp.file_offset == 0 )
{
goto _l1;
}
il.insert( tmp );
if( index_size < ( tmp.offset_in_index + tmp.peace_len ) )
{
index_size = tmp.offset_in_index + tmp.peace_len;
}
if( index_count < tmp.index )
{
index_count = tmp.index;
last_index_size = 0;
}
if( index_count == tmp.index && last_index_size < ( tmp.offset_in_index + tmp.peace_len ) )
{
last_index_size = ( tmp.offset_in_index + tmp.peace_len );
}
}
}
_l1:
int k = il.size();
printf( "Total segments %ld\r\n", k );
printf( "index_size 0x%lX, ", index_size );
printf( "indexes %ld, ", index_count + 1 );
printf( "last_index_size 0x%lX\r\n", last_index_size);
printf( "file size %I64d\r\n", (u64)index_size * index_count + last_index_size);
printf( "process time %ldms\r\n", time() - tick );
tick = time();
int out;
out = ::open( out_file, O_CREAT|O_WRONLY|O_LARGEFILE, 0644);
if( out == -1 )
{
printf("can't open out file\r\n");
}
char buffer[8192];
item_list_set::iterator i = il.begin();
while( i!= il.end() )
{
lseek64( hf, i->file_offset, SEEK_SET );
read( hf, buffer, i->peace_len);
lseek64( out, (u64)i->index * index_size + i->offset_in_index, SEEK_SET );
write( out, buffer, i->peace_len);
i++;
}
close( out );
close( hf );
printf( "Copy time %lds\r\n", ( time() - tick ) / 1000 );
delete lpBufer;
return;
}