1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-23 08:13:27 +00:00

(trunk libT) use valloc() and st.st_blksize when verifying local data

This commit is contained in:
Charles Kerr 2010-02-12 19:59:30 +00:00
parent 6958386ecd
commit d3ae2cf696
2 changed files with 17 additions and 4 deletions

View file

@ -108,7 +108,7 @@ fi
AC_HEADER_STDC AC_HEADER_STDC
AC_HEADER_TIME AC_HEADER_TIME
AC_CHECK_FUNCS([pread pwrite lrintf strlcpy daemon dirname basename strcasecmp localtime_r fallocate64 posix_fallocate memmem strtold syslog]) AC_CHECK_FUNCS([pread pwrite lrintf strlcpy daemon dirname basename strcasecmp localtime_r fallocate64 posix_fallocate memmem strtold syslog valloc])
AC_PROG_INSTALL AC_PROG_INSTALL
AC_PROG_MAKE_SET AC_PROG_MAKE_SET
ACX_PTHREAD ACX_PTHREAD

View file

@ -19,6 +19,9 @@
#if defined(HAVE_POSIX_FADVISE) || defined(SYS_DARWIN) #if defined(HAVE_POSIX_FADVISE) || defined(SYS_DARWIN)
#include <fcntl.h> /* posix_fadvise() / fcntl() */ #include <fcntl.h> /* posix_fadvise() / fcntl() */
#endif #endif
#if defined(SYS_DARWIN)
#define HAVE_VALLOC
#endif
#include <openssl/sha.h> #include <openssl/sha.h>
@ -57,8 +60,8 @@ verifyTorrent( tr_torrent * tor, tr_bool * stopFlag )
uint32_t pieceBytesRead = 0; uint32_t pieceBytesRead = 0;
tr_file_index_t fileIndex = 0; tr_file_index_t fileIndex = 0;
tr_piece_index_t pieceIndex = 0; tr_piece_index_t pieceIndex = 0;
const int64_t buflen = tor->info.pieceSize; uint8_t * buffer = NULL;
uint8_t * buffer = tr_new( uint8_t, buflen ); int64_t buflen = 0;
const time_t begin = tr_time( ); const time_t begin = tr_time( );
time_t end; time_t end;
@ -84,6 +87,16 @@ verifyTorrent( tr_torrent * tor, tr_bool * stopFlag )
char * filename = tr_torrentFindFile( tor, fileIndex ); char * filename = tr_torrentFindFile( tor, fileIndex );
fd = filename == NULL ? -1 : tr_open_file_for_scanning( filename ); fd = filename == NULL ? -1 : tr_open_file_for_scanning( filename );
/* fprintf( stderr, "opening file #%d (%s) -- %d\n", fileIndex, filename, fd ); */ /* fprintf( stderr, "opening file #%d (%s) -- %d\n", fileIndex, filename, fd ); */
if( ( fd >= 0 ) && ( buffer == NULL ) )
{
struct stat st;
buflen = fstat( fd, &st ) ? 4096 : st.st_blksize;
#ifdef HAVE_VALLOC
buffer = valloc( buflen );
#else
buffer = malloc( buflen );
#endif
}
tr_free( filename ); tr_free( filename );
} }
@ -164,7 +177,7 @@ verifyTorrent( tr_torrent * tor, tr_bool * stopFlag )
/* cleanup */ /* cleanup */
if( fd >= 0 ) if( fd >= 0 )
tr_close_file( fd ); tr_close_file( fd );
tr_free( buffer ); free( buffer );
/* stopwatch */ /* stopwatch */
end = tr_time( ); end = tr_time( );