Changeset 7720
- Timestamp:
- Jan 16, 2009, 4:38:16 PM (12 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/fdlimit.c
r7643 r7720 109 109 #endif 110 110 111 static int 112 preallocateFile( const char * filename, uint64_t length ) 113 { 114 int success = 0; 111 static tr_bool 112 preallocateFileSparse( int fd, uint64_t length ) 113 { 114 const char zero = '\0'; 115 116 if( length == 0 ) 117 return TRUE; 118 119 if( lseek( fd, length-1, SEEK_SET ) == -1 ) 120 return FALSE; 121 if( write( fd, &zero, 1 ) == -1 ) 122 return FALSE; 123 if( ftruncate( fd, length ) == -1 ) 124 return FALSE; 125 126 return TRUE; 127 } 128 129 static tr_bool 130 preallocateFileFull( const char * filename, uint64_t length ) 131 { 132 tr_bool success = 0; 115 133 116 134 #ifdef WIN32 … … 171 189 */ 172 190 static int 173 TrOpenFile( int i,174 const char * folder,175 const char * torrentFile,176 intdoWrite,177 int doPreallocate,178 uint64_t desiredFileSize )191 TrOpenFile( int i, 192 const char * folder, 193 const char * torrentFile, 194 tr_bool doWrite, 195 tr_preallocation_mode preallocationMode, 196 uint64_t desiredFileSize ) 179 197 { 180 198 struct tr_openfile * file = &gFd->openFiles[i]; … … 203 221 alreadyExisted = !stat( filename, &sb ) && S_ISREG( sb.st_mode ); 204 222 205 if( doWrite && !alreadyExisted && doPreallocate)206 if( preallocateFile ( filename, desiredFileSize ) )223 if( doWrite && !alreadyExisted && ( preallocationMode == TR_PREALLOCATE_FULL ) ) 224 if( preallocateFileFull( filename, desiredFileSize ) ) 207 225 tr_inf( _( "Preallocated file \"%s\"" ), filename ); 208 226 … … 225 243 } 226 244 245 if( doWrite && !alreadyExisted && ( preallocationMode == TR_PREALLOCATE_SPARSE ) ) 246 preallocateFileSparse( file->fd, desiredFileSize ); 247 227 248 tr_free( filename ); 228 249 return 0; … … 257 278 /* returns an fd on success, or a -1 on failure and sets errno */ 258 279 int 259 tr_fdFileCheckout( const char * folder,260 const char * torrentFile,261 intdoWrite,262 int doPreallocate,263 uint64_t desiredFileSize )280 tr_fdFileCheckout( const char * folder, 281 const char * torrentFile, 282 tr_bool doWrite, 283 tr_preallocation_mode preallocationMode, 284 uint64_t desiredFileSize ) 264 285 { 265 286 int i, winner = -1; … … 359 380 if( !fileIsOpen( o ) ) 360 381 { 361 const int err = TrOpenFile( winner, folder, torrentFile, doWrite, doPreallocate, desiredFileSize );382 const int err = TrOpenFile( winner, folder, torrentFile, doWrite, preallocationMode, desiredFileSize ); 362 383 if( err ) { 363 384 tr_lockUnlock( gFd->lock ); -
trunk/libtransmission/fdlimit.h
r7643 r7720 27 27 #endif 28 28 29 #include "transmission.h" 29 30 #include "net.h" 30 31 … … 51 52 * @see tr_fdFileClose 52 53 */ 53 int tr_fdFileCheckout( const char * folder,54 const char * torrentFile,55 intdoWrite,56 int doPreallocate,57 uint64_t desiredFileSize );54 int tr_fdFileCheckout( const char * folder, 55 const char * torrentFile, 56 tr_bool doWrite, 57 tr_preallocation_mode preallocationMode, 58 uint64_t desiredFileSize ); 58 59 59 60 /** -
trunk/libtransmission/inout.c
r7658 r7720 72 72 const tr_info * info = &tor->info; 73 73 const tr_file * file = &info->files[fileIndex]; 74 tr_preallocation_mode preallocationMode; 74 75 75 76 typedef size_t ( *iofunc )( int, void *, size_t ); … … 94 95 return 0; 95 96 97 if( ( file->dnd ) || ( ioMode != TR_IO_WRITE ) ) 98 preallocationMode = TR_PREALLOCATE_NONE; 99 else 100 preallocationMode = tor->session->preallocationMode; 101 96 102 if( ( ioMode == TR_IO_READ ) && !fileExists ) /* does file exist? */ 97 103 err = errno; 98 else if( ( fd = tr_fdFileCheckout ( tor->downloadDir, file->name, ioMode == TR_IO_WRITE, !file->dnd, file->length ) ) < 0 )104 else if( ( fd = tr_fdFileCheckout ( tor->downloadDir, file->name, ioMode == TR_IO_WRITE, preallocationMode, file->length ) ) < 0 ) 99 105 err = errno; 100 106 else if( tr_lseek( fd, (int64_t)fileOffset, SEEK_SET ) == -1 ) -
trunk/libtransmission/session.c
r7713 r7720 238 238 tr_bencDictAddInt( d, TR_PREFS_KEY_PEX_ENABLED, TRUE ); 239 239 tr_bencDictAddInt( d, TR_PREFS_KEY_PORT_FORWARDING, TRUE ); 240 tr_bencDictAddInt( d, TR_PREFS_KEY_PREALLOCATION, TR_PREALLOCATE_SPARSE ); 240 241 tr_bencDictAddStr( d, TR_PREFS_KEY_PROXY, "" ); 241 242 tr_bencDictAddInt( d, TR_PREFS_KEY_PROXY_AUTH_ENABLED, FALSE ); … … 283 284 tr_bencDictAddInt( d, TR_PREFS_KEY_PEX_ENABLED, s->isPexEnabled ); 284 285 tr_bencDictAddInt( d, TR_PREFS_KEY_PORT_FORWARDING, tr_sessionIsPortForwardingEnabled( s ) ); 286 tr_bencDictAddInt( d, TR_PREFS_KEY_PREALLOCATION, s->preallocationMode ); 285 287 tr_bencDictAddStr( d, TR_PREFS_KEY_PROXY, s->proxy ); 286 288 tr_bencDictAddInt( d, TR_PREFS_KEY_PROXY_AUTH_ENABLED, s->isProxyAuthEnabled ); … … 404 406 found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_ENCRYPTION, &i ); 405 407 assert( found ); 408 assert( tr_isEncryptionMode( i ) ); 406 409 session->encryptionMode = i; 410 411 found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_PREALLOCATION, &i ); 412 assert( found ); 413 assert( tr_isPreallocationMode( i ) ); 414 session->preallocationMode = i; 407 415 408 416 found = tr_bencDictFindInt( &settings, TR_PREFS_KEY_PEER_SOCKET_TOS, &i ); -
trunk/libtransmission/session.h
r7646 r7720 71 71 72 72 tr_encryption_mode encryptionMode; 73 74 tr_preallocation_mode preallocationMode; 73 75 74 76 struct tr_event_handle * events; -
trunk/libtransmission/transmission.h
r7707 r7720 107 107 typedef enum 108 108 { 109 TR_PREALLOCATE_NONE = 0, 110 TR_PREALLOCATE_SPARSE = 1, 111 TR_PREALLOCATE_FULL = 2 112 } 113 tr_preallocation_mode; 114 115 static TR_INLINE tr_bool tr_isPreallocationMode( tr_preallocation_mode m ) 116 { 117 return ( m == TR_PREALLOCATE_NONE ) 118 || ( m == TR_PREALLOCATE_SPARSE ) 119 || ( m == TR_PREALLOCATE_FULL ); 120 } 121 122 typedef enum 123 { 109 124 TR_PROXY_HTTP, 110 125 TR_PROXY_SOCKS4, … … 120 135 } 121 136 tr_encryption_mode; 137 138 static TR_INLINE tr_bool tr_isEncryptionMode( tr_encryption_mode m ) 139 { 140 return ( m == TR_CLEAR_PREFERRED ) 141 || ( m == TR_ENCRYPTION_PREFERRED ) 142 || ( m == TR_ENCRYPTION_REQUIRED ); 143 } 144 122 145 123 146 #define TR_DEFAULT_OPEN_FILE_LIMIT_STR "32" … … 147 170 #define TR_PREFS_KEY_PORT_FORWARDING "port-forwarding-enabled" 148 171 #define TR_PREFS_KEY_PROXY_AUTH_ENABLED "proxy-auth-enabled" 172 #define TR_PREFS_KEY_PREALLOCATION "preallocation" 149 173 #define TR_PREFS_KEY_PROXY_ENABLED "proxy-enabled" 150 174 #define TR_PREFS_KEY_PROXY_PASSWORD "proxy-auth-password"
Note: See TracChangeset
for help on using the changeset viewer.