Ticket #2196: fill_correct.diff

File fill_correct.diff, 2.9 KB (added by hdfan2, 13 years ago)

Reviewed the patch and noticed that it has one change that wasn't in my original path. Attachet the correct version of the patch (couldn't replace existing - no priveleges)

  • fdlimit.c

    preallocateFileSparse( int fd, uint64_t  
    137137}
    138138
    139139static tr_bool
    140 preallocateFileFull( const char * filename, uint64_t length )
     140preallocateFileFull( const char * filename, uint64_t length, tr_preallocation_mode preallocationMode )
    141141{
    142142    tr_bool success = 0;
    143143
    preallocateFileFull( const char * filena 
    158158    int fd = open( filename, flags, 0666 );
    159159    if( fd >= 0 )
    160160    {
     161      if( preallocationMode == TR_PREALLOCATE_FILL )
     162        {
     163            uint8_t buf[ 4 * 1024 ] = {0};
     164            success = 1;
     165            while ( length > 0 && success )
     166            {
     167                const size_t thisPass = MIN( length, sizeof( buf ) );
     168                success = write( fd, buf, thisPass ) == thisPass;
     169                length -= thisPass;
     170            }
     171         }
     172         else
     173         {
    161174# ifdef HAVE_XFS_XFS_H
    162175        if( !success && platform_test_xfs_fd( fd ) )
    163176        {
    preallocateFileFull( const char * filena 
    192205            success = !posix_fallocate( fd, 0, length );
    193206        }
    194207# endif
    195 
     208 }
     209 
    196210        close( fd );
    197211    }
    198212
    preallocateFileFull( const char * filena 
    204218tr_bool
    205219tr_preallocate_file( const char * filename, uint64_t length )
    206220{
    207     return preallocateFileFull( filename, length );
     221    return preallocateFileFull( filename, length, TR_PREALLOCATE_FULL );
    208222}
    209223
    210224int
    TrOpenFile( int i, 
    314328
    315329    alreadyExisted = !stat( filename, &sb ) && S_ISREG( sb.st_mode );
    316330
    317     if( doWrite && !alreadyExisted && ( preallocationMode == TR_PREALLOCATE_FULL ) )
    318         if( preallocateFileFull( filename, desiredFileSize ) )
     331  if( doWrite && !alreadyExisted && ( preallocationMode >= TR_PREALLOCATE_FULL ) )
     332        if( preallocateFileFull( filename, desiredFileSize, preallocationMode ) )
    319333            tr_inf( _( "Preallocated file \"%s\"" ), filename );
    320334   
    321335    /* open the file */
  • transmission.h

    typedef enum 
    8484{
    8585    TR_PREALLOCATE_NONE   = 0,
    8686    TR_PREALLOCATE_SPARSE = 1,
    87     TR_PREALLOCATE_FULL   = 2
     87    TR_PREALLOCATE_FULL   = 2,
     88    TR_PREALLOCATE_FILL   = 3
    8889}
    8990tr_preallocation_mode;
    9091
  • session.h

    static TR_INLINE tr_bool tr_isPreallocat 
    176183{
    177184    return ( m == TR_PREALLOCATE_NONE )
    178185        || ( m == TR_PREALLOCATE_SPARSE )
    179         || ( m == TR_PREALLOCATE_FULL );
     186        || ( m == TR_PREALLOCATE_FULL )
     187        || ( m == TR_PREALLOCATE_FILL );
    180188}
    181189
    182190static TR_INLINE tr_bool tr_isEncryptionMode( tr_encryption_mode m )