Changeset 10336


Ignore:
Timestamp:
Mar 9, 2010, 4:19:59 PM (12 years ago)
Author:
charles
Message:

(trunk libT) #2849 "when possible, use fallocate64() for file preallocation" -- do this even when sparse preallocation mode is selected.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/fdlimit.c

    r10332 r10336  
    116116{
    117117    const char zero = '\0';
    118 
    119     if( length == 0 )
    120         return TRUE;
    121 
    122     if( lseek( fd, length-1, SEEK_SET ) == -1 )
    123         return FALSE;
    124     if( write( fd, &zero, 1 ) == -1 )
    125         return FALSE;
    126     if( ftruncate( fd, length ) == -1 )
    127         return FALSE;
    128 
    129     return TRUE;
     118    tr_bool success = 0;
     119
     120    if( !length )
     121        success = TRUE;
     122
     123#ifdef HAVE_FALLOCATE64
     124    if( !success ) /* fallocate64 is always preferred, so try it first */
     125        success = !fallocate64( fd, 0, 0, length );
     126#endif
     127
     128    if( !success ) /* fallback: the old-style seek-and-write */
     129        success = ( lseek( fd, length-1, SEEK_SET ) != -1 )
     130               && ( write( fd, &zero, 1 ) != -1 )
     131               && ( ftruncate( fd, length ) != -1 );
     132
     133    return success;
    130134}
    131135
Note: See TracChangeset for help on using the changeset viewer.