Changeset 5329
- Timestamp:
- Mar 22, 2008, 6:10:59 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cli/transmissioncli.c
r5143 r5329 179 179 if( !tr_torrentParse( h, ctor, &info ) ) 180 180 { 181 tr_file_index_t ff; 182 181 183 printf( "hash:\t" ); 182 184 for( i=0; i<SHA_DIGEST_LENGTH; ++i ) … … 209 211 210 212 printf( "file(s):\n" ); 211 for( i=0; i<info.fileCount; ++i)212 printf( "\t%s (%"PRIu64")\n", info.files[ i].name, info.files[i].length );213 for( ff=0; ff<info.fileCount; ++ff ) 214 printf( "\t%s (%"PRIu64")\n", info.files[ff].name, info.files[ff].length ); 213 215 214 216 tr_metainfoFree( &info ); -
trunk/gtk/file-list.c
r5290 r5329 266 266 /* update this node */ 267 267 gtk_tree_model_get( GTK_TREE_MODEL(store), iter, FC_INDEX, &index, -1 ); 268 if (index >= 0) 269 g_array_append_val( indices, index ); 268 if (index >= 0) { 269 tr_file_index_t fi = index; 270 g_array_append_val( indices, fi ); 271 } 270 272 gtk_tree_store_set( store, iter, FC_ENABLED, enabled, -1 ); 271 273 … … 282 284 gboolean enabled ) 283 285 { 284 GArray * indices = g_array_new( FALSE, FALSE, sizeof( int) );286 GArray * indices = g_array_new( FALSE, FALSE, sizeof(tr_file_index_t) ); 285 287 subtree_walk_dnd( store, iter, tor, enabled, indices ); 286 tr_torrentSetFileDLs( tor, ( int*)indices->data, (int)indices->len, enabled );288 tr_torrentSetFileDLs( tor, (tr_file_index_t*)indices->data, (tr_file_index_t)indices->len, enabled ); 287 289 g_array_free( indices, TRUE ); 288 290 } … … 319 321 GArray * indices = g_array_new( FALSE, FALSE, sizeof(int) ); 320 322 subtree_walk_priority( store, iter, tor, priority, indices ); 321 tr_torrentSetFilePriorities( tor, ( int*)indices->data, (int)indices->len, priority );323 tr_torrentSetFilePriorities( tor, (tr_file_index_t*)indices->data, (tr_file_index_t)indices->len, priority ); 322 324 g_array_free( indices, TRUE ); 323 325 } … … 371 373 { 372 374 guint64 foo, bar; 373 int fileCount;375 tr_file_index_t fileCount; 374 376 tr_torrent * tor; 375 377 tr_file_stat * fileStats; … … 425 427 if( gtor ) 426 428 { 427 int i;429 tr_file_index_t i; 428 430 const tr_info * inf = tr_torrent_info( gtor ); 429 431 tr_torrent * tor = tr_torrent_handle( gtor ); -
trunk/gtk/tr-torrent.c
r5313 r5329 333 333 tr_torrent_delete_files( TrTorrent * gtor ) 334 334 { 335 int i;335 tr_file_index_t i; 336 336 const tr_info * info = tr_torrent_info( gtor ); 337 337 const char * stop = tr_torrentGetFolder( tr_torrent_handle( gtor ) ); -
trunk/gtk/tr-window.c
r5313 r5329 270 270 const char * text ) 271 271 { 272 int i;272 tr_file_index_t i; 273 273 int ret = 0; 274 274 char * pch; -
trunk/libtransmission/completion.c
r5001 r5329 98 98 const tr_info * info = &tor->info; 99 99 uint64_t have=0, total=0; 100 int i;100 tr_piece_index_t i; 101 101 tr_completion * cp ; 102 102 … … 138 138 139 139 int 140 tr_cpPieceIsComplete( const tr_completion * cp, int piece )141 { 142 assert( piece >= 0 ); 140 tr_cpPieceIsComplete( const tr_completion * cp, 141 tr_piece_index_t piece ) 142 { 143 143 assert( piece < cp->tor->info.pieceCount ); 144 144 assert( cp->completeBlocks[piece] <= tr_torPieceCountBlocks(cp->tor,piece) ); … … 153 153 154 154 void 155 tr_cpPieceAdd( tr_completion * cp, int piece )155 tr_cpPieceAdd( tr_completion * cp, tr_piece_index_t piece ) 156 156 { 157 157 const tr_torrent * tor = cp->tor; 158 const int start = tr_torPieceFirstBlock(tor,piece);159 const int end = start + tr_torPieceCountBlocks(tor,piece);160 int i;158 const tr_block_index_t start = tr_torPieceFirstBlock(tor,piece); 159 const tr_block_index_t end = start + tr_torPieceCountBlocks(tor, piece); 160 tr_block_index_t i; 161 161 162 162 for( i=start; i<end; ++i ) … … 165 165 166 166 void 167 tr_cpPieceRem( tr_completion * cp, int piece )167 tr_cpPieceRem( tr_completion * cp, tr_piece_index_t piece ) 168 168 { 169 169 const tr_torrent * tor = cp->tor; 170 const int start = tr_torPieceFirstBlock(tor,piece); 171 const int end = start + tr_torPieceCountBlocks(tor,piece); 172 int block; 173 174 assert( cp != NULL ); 175 assert( 0 <= piece ); 170 const tr_block_index_t start = tr_torPieceFirstBlock(tor,piece); 171 const tr_block_index_t end = start + tr_torPieceCountBlocks(tor,piece); 172 tr_block_index_t block; 173 174 assert( cp != NULL ); 176 175 assert( piece < tor->info.pieceCount ); 177 assert( 0 <= start );178 176 assert( start < tor->blockCount ); 179 177 assert( start <= end ); … … 198 196 } 199 197 200 int tr_cpBlockIsComplete( const tr_completion * cp, int block ) 198 int 199 tr_cpBlockIsComplete( const tr_completion * cp, tr_block_index_t block ) 201 200 { 202 201 return tr_bitfieldHas( cp->blockBitfield, block ) ? 1 : 0; … … 204 203 205 204 void 206 tr_cpBlockAdd( tr_completion * cp, int block )205 tr_cpBlockAdd( tr_completion * cp, tr_block_index_t block ) 207 206 { 208 207 const tr_torrent * tor = cp->tor; … … 210 209 if( !tr_cpBlockIsComplete( cp, block ) ) 211 210 { 212 const int piece = tr_torBlockPiece( tor, block );211 const tr_piece_index_t piece = tr_torBlockPiece( tor, block ); 213 212 const int blockSize = tr_torBlockCountBytes( tor, block ); 214 213 … … 241 240 tr_cpBlockBitfieldSet( tr_completion * cp, tr_bitfield * bitfield ) 242 241 { 243 int i;242 tr_block_index_t i; 244 243 245 244 assert( cp != NULL ); … … 253 252 } 254 253 255 float tr_cpPercentBlocksInPiece( const tr_completion * cp, int piece ) 254 float 255 tr_cpPercentBlocksInPiece( const tr_completion * cp, tr_piece_index_t piece ) 256 256 { 257 257 assert( cp != NULL ); … … 261 261 262 262 int 263 tr_cpMissingBlocksInPiece( const tr_completion * cp, int piece )263 tr_cpMissingBlocksInPiece( const tr_completion * cp, tr_piece_index_t piece ) 264 264 { 265 265 assert( cp != NULL ); … … 324 324 const tr_torrent * tor = cp->tor; 325 325 const tr_info * info = &tor->info; 326 int i;326 tr_piece_index_t i; 327 327 328 328 for( i=0; i<info->pieceCount; ++i ) -
trunk/libtransmission/completion.h
r5001 r5329 46 46 47 47 /* Pieces */ 48 int tr_cpPieceIsComplete( const tr_completion *, int piece );49 void tr_cpPieceAdd( tr_completion *, int piece );50 void tr_cpPieceRem( tr_completion *, int piece );48 int tr_cpPieceIsComplete( const tr_completion *, tr_piece_index_t piece ); 49 void tr_cpPieceAdd( tr_completion *, tr_piece_index_t piece ); 50 void tr_cpPieceRem( tr_completion *, tr_piece_index_t piece ); 51 51 52 52 /* Blocks */ 53 int tr_cpBlockIsComplete( const tr_completion *, int block );54 void tr_cpBlockAdd( tr_completion *, int block );53 int tr_cpBlockIsComplete( const tr_completion *, tr_block_index_t block ); 54 void tr_cpBlockAdd( tr_completion *, tr_block_index_t block ); 55 55 void tr_cpBlockBitfieldSet( tr_completion *, struct tr_bitfield * ); 56 float tr_cpPercentBlocksInPiece( const tr_completion * cp, int piece );57 int tr_cpMissingBlocksInPiece( const tr_completion * cp, int piece );56 float tr_cpPercentBlocksInPiece( const tr_completion * cp, tr_piece_index_t piece ); 57 int tr_cpMissingBlocksInPiece( const tr_completion * cp, tr_piece_index_t piece ); 58 58 59 59 -
trunk/libtransmission/fastresume.c
r5313 r5329 400 400 uint32_t len ) 401 401 { 402 int i;403 402 uint64_t ret = 0; 404 403 405 404 if( len == FR_PROGRESS_LEN( tor ) ) 406 405 { 406 int i; 407 407 int n; 408 408 tr_bitfield bitfield; … … 434 434 /* the files whose mtimes are wrong, 435 435 remove from completion pending a recheck... */ 436 for( i=0; i<tor->info.pieceCount; ++i ) 437 if( !tr_torrentIsPieceChecked( tor, i ) ) 438 tr_cpPieceRem( tor->completion, i ); 436 { 437 tr_piece_index_t i; 438 for( i=0; i<tor->info.pieceCount; ++i ) 439 if( !tr_torrentIsPieceChecked( tor, i ) ) 440 tr_cpPieceRem( tor->completion, i ); 441 } 439 442 440 443 return ret; … … 450 453 const size_t n = tor->info.fileCount; 451 454 const size_t len = 2 * n; 452 int *dnd = NULL, dndCount = 0;453 int *dl = NULL, dlCount = 0;455 tr_file_index_t *dnd = NULL, dndCount = 0; 456 tr_file_index_t *dl = NULL, dlCount = 0; 454 457 size_t i; 455 458 const uint8_t * walk = buf; … … 468 471 469 472 /* set the dnd flags */ 470 dl = tr_new( int, len );471 dnd = tr_new( int, len );473 dl = tr_new( tr_file_index_t, len ); 474 dnd = tr_new( tr_file_index_t, len ); 472 475 for( i=0; i<n; ++i ) 473 476 if( *walk++ == 't' ) /* 't' means the DND flag is true */ -
trunk/libtransmission/inout.c
r5286 r5329 42 42 readOrWriteBytes( const tr_torrent * tor, 43 43 int ioMode, 44 intfileIndex,44 tr_file_index_t fileIndex, 45 45 uint64_t fileOffset, 46 46 void * buf, … … 57 57 int fileExists; 58 58 59 assert( 0<=fileIndex && fileIndex<info->fileCount );59 assert( fileIndex < info->fileCount ); 60 60 assert( !file->length || (fileOffset < file->length)); 61 61 assert( fileOffset + buflen <= file->length ); … … 89 89 static tr_errno 90 90 findFileLocation( const tr_torrent * tor, 91 intpieceIndex,92 intpieceOffset,93 int* fileIndex,91 tr_piece_index_t pieceIndex, 92 uint32_t pieceOffset, 93 tr_file_index_t * fileIndex, 94 94 uint64_t * fileOffset ) 95 95 { 96 96 const tr_info * info = &tor->info; 97 97 98 int i;98 tr_file_index_t i; 99 99 uint64_t piecePos = ((uint64_t)pieceIndex * info->pieceSize) + pieceOffset; 100 100 101 if( pieceIndex < 0 || pieceIndex>= info->pieceCount )101 if( pieceIndex >= info->pieceCount ) 102 102 return TR_ERROR_ASSERT; 103 103 if( pieceOffset >= tr_torPieceCountBytes( tor, pieceIndex ) ) … … 112 112 *fileOffset = piecePos; 113 113 114 assert( 0<=*fileIndex && *fileIndex<info->fileCount );114 assert( *fileIndex < info->fileCount ); 115 115 assert( *fileOffset < info->files[i].length ); 116 116 return 0; … … 120 120 static tr_errno 121 121 ensureMinimumFileSize( const tr_torrent * tor, 122 intfileIndex,122 tr_file_index_t fileIndex, 123 123 uint64_t minBytes ) 124 124 { … … 151 151 152 152 static tr_errno 153 readOrWritePiece( tr_torrent * tor,154 int ioMode,155 intpieceIndex,156 intpieceOffset,157 uint8_t * buf,158 size_t buflen )153 readOrWritePiece( tr_torrent * tor, 154 int ioMode, 155 tr_piece_index_t pieceIndex, 156 uint32_t pieceOffset, 157 uint8_t * buf, 158 size_t buflen ) 159 159 { 160 160 tr_errno err = 0; 161 int fileIndex;161 tr_file_index_t fileIndex; 162 162 uint64_t fileOffset; 163 163 const tr_info * info = &tor->info; 164 164 165 if( pieceIndex < 0 || pieceIndex>= tor->info.pieceCount )165 if( pieceIndex >= tor->info.pieceCount ) 166 166 err = TR_ERROR_ASSERT; 167 167 else if( buflen > ( size_t ) tr_torPieceCountBytes( tor, pieceIndex ) ) … … 195 195 tr_errno 196 196 tr_ioRead( const tr_torrent * tor, 197 intpieceIndex,198 intbegin,199 intlen,197 tr_piece_index_t pieceIndex, 198 uint32_t begin, 199 uint32_t len, 200 200 uint8_t * buf ) 201 201 { … … 204 204 205 205 tr_errno 206 tr_ioWrite( tr_torrent * tor,207 intpieceIndex,208 intbegin,209 intlen,210 const uint8_t * buf )206 tr_ioWrite( tr_torrent * tor, 207 tr_piece_index_t pieceIndex, 208 uint32_t begin, 209 uint32_t len, 210 const uint8_t * buf ) 211 211 { 212 212 return readOrWritePiece( tor, TR_IO_WRITE, pieceIndex, begin, (uint8_t*)buf, len ); … … 219 219 static tr_errno 220 220 tr_ioRecalculateHash( const tr_torrent * tor, 221 intpieceIndex,221 tr_piece_index_t pieceIndex, 222 222 uint8_t * setme ) 223 223 { … … 239 239 assert( tor != NULL ); 240 240 assert( setme != NULL ); 241 assert( 0<=pieceIndex && pieceIndex<tor->info.pieceCount );241 assert( pieceIndex < tor->info.pieceCount ); 242 242 243 243 info = &tor->info; -
trunk/libtransmission/inout.h
r5045 r5329 34 34 */ 35 35 int tr_ioRead ( const struct tr_torrent * tor, 36 intpieceIndex,37 intoffset,38 intlen,36 tr_piece_index_t pieceIndex, 37 uint32_t offset, 38 uint32_t len, 39 39 uint8_t * setme ); 40 40 … … 45 45 */ 46 46 tr_errno tr_ioWrite ( struct tr_torrent * tor, 47 intpieceIndex,48 intoffset,49 intlen,47 tr_piece_index_t pieceIndex, 48 uint32_t offset, 49 uint32_t len, 50 50 const uint8_t * writeme ); 51 51 -
trunk/libtransmission/ipcparse.c
r5172 r5329 503 503 tr_benc * dict, * item, * file, * tier; 504 504 int ii, jj, kk; 505 tr_file_index_t ff; 505 506 506 507 /* always send torrent id */ … … 568 569 return -1; 569 570 } 570 for( jj = 0; inf->fileCount > jj; jj++ )571 for( ff = 0; inf->fileCount > ff; ff++ ) 571 572 { 572 573 file = tr_bencListAdd( item ); … … 577 578 } 578 579 tr_bencInitStr( tr_bencDictAdd( file, "name" ), 579 inf->files[ jj].name, -1, 1 );580 inf->files[ff].name, -1, 1 ); 580 581 tr_bencInitInt( tr_bencDictAdd( file, "size" ), 581 inf->files[ jj].length );582 inf->files[ff].length ); 582 583 } 583 584 break; -
trunk/libtransmission/metainfo.c
r5313 r5329 172 172 tr_metainfoParse( tr_info * inf, const tr_benc * meta_in, const char * tag ) 173 173 { 174 int i;174 tr_piece_index_t i; 175 175 tr_benc * beInfo, * val, * val2; 176 176 tr_benc * meta = (tr_benc *) meta_in; … … 305 305 void tr_metainfoFree( tr_info * inf ) 306 306 { 307 tr_file_index_t ff; 307 308 int i, j; 308 309 309 for( i=0; i<inf->fileCount; ++i)310 tr_free( inf->files[ i].name );310 for( ff=0; ff<inf->fileCount; ++ff ) 311 tr_free( inf->files[ff].name ); 311 312 312 313 tr_free( inf->pieces ); -
trunk/libtransmission/peer-mgr.c
r5204 r5329 595 595 static int 596 596 isPieceInteresting( const tr_torrent * tor, 597 intpiece )597 tr_piece_index_t piece ) 598 598 { 599 599 if( tor->info.pieces[piece].dnd ) /* we don't want it */ … … 612 612 const tr_torrent * tor = t->tor; 613 613 const tr_info * inf = &tor->info; 614 int i;614 tr_piece_index_t i; 615 615 uint32_t poolSize = 0; 616 616 uint32_t * pool = tr_new( uint32_t, inf->pieceCount ); … … 666 666 667 667 static uint64_t* 668 getPreferredBlocks( Torrent * t, uint64_t * setmeCount )668 getPreferredBlocks( Torrent * t, tr_block_index_t * setmeCount ) 669 669 { 670 670 int s; … … 704 704 for( i=blockCount=0; i<pieceCount; ++i ) 705 705 { 706 const uint32_t index = pieces[i];706 const tr_piece_index_t index = pieces[i]; 707 707 const int priorityIndex = tor->info.pieces[index].priority + 1; 708 const int begin = tr_torPieceFirstBlock( tor, index );709 const int end = begin + tr_torPieceCountBlocks( tor, (int)index );710 int block;708 const tr_block_index_t begin = tr_torPieceFirstBlock( tor, index ); 709 const tr_block_index_t end = begin + tr_torPieceCountBlocks( tor, index ); 710 tr_block_index_t block; 711 711 712 712 for( block=begin; block<end; ++block ) … … 785 785 Torrent * t = vtorrent; 786 786 tr_torrent * tor = t->tor; 787 uint32_t i;787 tr_block_index_t i; 788 788 int peerCount; 789 789 tr_peer ** peers; 790 uint64_t blockCount;790 tr_block_index_t blockCount; 791 791 uint64_t * blocks; 792 792 … … 806 806 int j; 807 807 808 const uint64_t block = blocks[i];809 const uint32_t index = tr_torBlockPiece( tor, block );808 const tr_block_index_t block = blocks[i]; 809 const tr_piece_index_t index = tr_torBlockPiece( tor, block ); 810 810 const uint32_t begin = (block * tor->blockSize) - (index * tor->info.pieceSize); 811 const uint32_t length = tr_torBlockCountBytes( tor, (int)block );811 const uint32_t length = tr_torBlockCountBytes( tor, block ); 812 812 813 813 assert( tr_torrentReqIsValid( tor, index, begin, length ) ); 814 assert( _tr_block( tor, index, begin ) == (int)block );815 assert( begin < (uint32_t)tr_torPieceCountBytes( tor, (int)index ) );816 assert( (begin + length) <= (uint32_t)tr_torPieceCountBytes( tor, (int)index ) );814 assert( _tr_block( tor, index, begin ) == block ); 815 assert( begin < tr_torPieceCountBytes( tor, index ) ); 816 assert( (begin + length) <= tr_torPieceCountBytes( tor, index ) ); 817 817 818 818 /* find a peer who can ask for this block */ -
trunk/libtransmission/peer-msgs.c
r5300 r5329 462 462 isPeerInteresting( const tr_peermsgs * msgs ) 463 463 { 464 int i;464 tr_piece_index_t i; 465 465 const tr_torrent * torrent; 466 466 const tr_bitfield * bitfield; … … 631 631 sendFastAllowedSet( tr_peermsgs * msgs ) 632 632 { 633 int i = 0;633 tr_piece_index_t i = 0; 634 634 635 635 while (i <= msgs->torrent->info.pieceCount ) … … 1441 1441 1442 1442 static void 1443 gotBadPiece( tr_peermsgs * msgs, uint32_t pieceIndex )1443 gotBadPiece( tr_peermsgs * msgs, tr_piece_index_t pieceIndex ) 1444 1444 { 1445 1445 const uint32_t byteCount = 1446 tr_torPieceCountBytes( msgs->torrent, (int)pieceIndex );1446 tr_torPieceCountBytes( msgs->torrent, pieceIndex ); 1447 1447 reassignBytesToCorrupt( msgs, byteCount ); 1448 1448 } … … 1469 1469 int err; 1470 1470 tr_torrent * tor = msgs->torrent; 1471 const int block = _tr_block( tor, req->index, req->offset );1471 const tr_block_index_t block = _tr_block( tor, req->index, req->offset ); 1472 1472 1473 1473 assert( msgs != NULL ); 1474 1474 assert( req != NULL ); 1475 1475 1476 if( req->length != (uint32_t)tr_torBlockCountBytes( msgs->torrent, block ) )1476 if( req->length != tr_torBlockCountBytes( msgs->torrent, block ) ) 1477 1477 { 1478 1478 dbgmsg( msgs, "wrong block size -- expected %u, got %d", -
trunk/libtransmission/torrent.c
r5313 r5329 192 192 193 193 static void 194 initFilePieces ( tr_info * info, int fileIndex )194 initFilePieces ( tr_info * info, tr_file_index_t fileIndex ) 195 195 { 196 196 tr_file * file = &info->files[fileIndex]; … … 198 198 199 199 assert( info != NULL ); 200 assert( 0<=fileIndex && fileIndex<info->fileCount );200 assert( fileIndex < info->fileCount ); 201 201 202 202 file = &info->files[fileIndex]; … … 208 208 209 209 static int 210 pieceHasFile( int piece, const tr_file * file )210 pieceHasFile( tr_piece_index_t piece, const tr_file * file ) 211 211 { 212 212 return ( file->firstPiece <= piece ) && ( piece <= file->lastPiece ); … … 215 215 static tr_priority_t 216 216 calculatePiecePriority ( const tr_torrent * tor, 217 intpiece,217 tr_piece_index_t piece, 218 218 int fileHint ) 219 219 { 220 int i;220 tr_file_index_t i; 221 221 int priority = TR_PRI_LOW; 222 222 … … 257 257 tr_torrentInitFilePieces( tr_torrent * tor ) 258 258 { 259 int i; 259 tr_file_index_t ff; 260 tr_piece_index_t pp; 260 261 uint64_t offset = 0; 261 262 262 263 assert( tor != NULL ); 263 264 264 for( i=0; i<tor->info.fileCount; ++i) {265 tor->info.files[ i].offset = offset;266 offset += tor->info.files[ i].length;267 initFilePieces( &tor->info, i);268 } 269 270 for( i=0; i<tor->info.pieceCount; ++i)271 tor->info.pieces[ i].priority = calculatePiecePriority( tor, i, -1 );265 for( ff=0; ff<tor->info.fileCount; ++ff ) { 266 tor->info.files[ff].offset = offset; 267 offset += tor->info.files[ff].length; 268 initFilePieces( &tor->info, ff ); 269 } 270 271 for( pp=0; pp<tor->info.pieceCount; ++pp ) 272 tor->info.pieces[pp].priority = calculatePiecePriority( tor, pp, -1 ); 272 273 } 273 274 … … 637 638 638 639 { 639 int i;640 tr_piece_index_t i; 640 641 tr_bitfield * availablePieces = tr_peerMgrGetAvailable( tor->handle->peerMgr, 641 642 tor->info.hash ); … … 672 673 673 674 static uint64_t 674 fileBytesCompleted ( const tr_torrent * tor, int fileIndex )675 fileBytesCompleted ( const tr_torrent * tor, tr_file_index_t fileIndex ) 675 676 { 676 677 const tr_file * file = &tor->info.files[fileIndex]; 677 const uint64_t firstBlock = file->offset / tor->blockSize;678 const tr_block_index_t firstBlock = file->offset / tor->blockSize; 678 679 const uint64_t firstBlockOffset = file->offset % tor->blockSize; 679 680 const uint64_t lastOffset = file->length ? (file->length-1) : 0; 680 const uint64_t lastBlock = (file->offset + lastOffset) / tor->blockSize;681 const tr_block_index_t lastBlock = (file->offset + lastOffset) / tor->blockSize; 681 682 const uint64_t lastBlockOffset = (file->offset + lastOffset) % tor->blockSize; 682 683 uint64_t haveBytes = 0; 683 684 684 685 assert( tor != NULL ); 685 assert( 0<=fileIndex && fileIndex<tor->info.fileCount );686 assert( fileIndex < tor->info.fileCount ); 686 687 assert( file->offset + file->length <= tor->info.totalSize ); 687 assert( ( (int)firstBlock < tor->blockCount ) || (!file->length && file->offset==tor->info.totalSize) );688 assert( ( (int)lastBlock < tor->blockCount ) || (!file->length && file->offset==tor->info.totalSize) );688 assert( ( firstBlock < tor->blockCount ) || (!file->length && file->offset==tor->info.totalSize) ); 689 assert( ( lastBlock < tor->blockCount ) || (!file->length && file->offset==tor->info.totalSize) ); 689 690 assert( firstBlock <= lastBlock ); 690 assert( (int)tr_torBlockPiece( tor, firstBlock ) == file->firstPiece );691 assert( (int)tr_torBlockPiece( tor, lastBlock ) == file->lastPiece );691 assert( tr_torBlockPiece( tor, firstBlock ) == file->firstPiece ); 692 assert( tr_torBlockPiece( tor, lastBlock ) == file->lastPiece ); 692 693 693 694 if( firstBlock == lastBlock ) … … 698 699 else 699 700 { 700 uint64_t i;701 tr_block_index_t i; 701 702 702 703 if( tr_cpBlockIsComplete( tor->completion, firstBlock ) ) … … 715 716 716 717 tr_file_stat * 717 tr_torrentFiles( const tr_torrent * tor, int * fileCount )718 { 719 int i;720 const int n = tor->info.fileCount;718 tr_torrentFiles( const tr_torrent * tor, tr_file_index_t * fileCount ) 719 { 720 tr_file_index_t i; 721 const tr_file_index_t n = tor->info.fileCount; 721 722 tr_file_stat * files = tr_new0( tr_file_stat, n ); 722 723 tr_file_stat * walk = files; … … 739 740 740 741 void 741 tr_torrentFilesFree( tr_file_stat * files, int fileCount UNUSED )742 tr_torrentFilesFree( tr_file_stat * files, tr_file_index_t fileCount UNUSED ) 742 743 { 743 744 tr_free( files ); … … 806 807 807 808 void 808 tr_torrentSetHasPiece( tr_torrent * tor, int pieceIndex, int has )809 tr_torrentSetHasPiece( tr_torrent * tor, tr_piece_index_t pieceIndex, int has ) 809 810 { 810 811 tr_torrentLock( tor ); 811 812 812 813 assert( tor != NULL ); 813 assert( pieceIndex >= 0 );814 814 assert( pieceIndex < tor->info.pieceCount ); 815 815 … … 979 979 stopTorrent( void * vtor ) 980 980 { 981 int i;981 tr_file_index_t i; 982 982 983 983 tr_torrent * tor = vtor; … … 1132 1132 1133 1133 void 1134 tr_torrentInitFilePriority( tr_torrent * tor,1135 intfileIndex,1136 tr_priority_t priority )1137 { 1138 int i;1134 tr_torrentInitFilePriority( tr_torrent * tor, 1135 tr_file_index_t fileIndex, 1136 tr_priority_t priority ) 1137 { 1138 tr_piece_index_t i; 1139 1139 tr_file * file; 1140 1140 1141 1141 assert( tor != NULL ); 1142 assert( 0<=fileIndex && fileIndex<tor->info.fileCount );1142 assert( fileIndex < tor->info.fileCount ); 1143 1143 assert( priority==TR_PRI_LOW || priority==TR_PRI_NORMAL || priority==TR_PRI_HIGH ); 1144 1144 … … 1150 1150 1151 1151 void 1152 tr_torrentSetFilePriorities( tr_torrent * tor,1153 int* files,1154 intfileCount,1155 tr_priority_t priority )1156 { 1157 int i;1152 tr_torrentSetFilePriorities( tr_torrent * tor, 1153 tr_file_index_t * files, 1154 tr_file_index_t fileCount, 1155 tr_priority_t priority ) 1156 { 1157 tr_file_index_t i; 1158 1158 tr_torrentLock( tor ); 1159 1159 … … 1166 1166 1167 1167 tr_priority_t 1168 tr_torrentGetFilePriority( const tr_torrent * tor, int file )1168 tr_torrentGetFilePriority( const tr_torrent * tor, tr_file_index_t file ) 1169 1169 { 1170 1170 tr_priority_t ret; … … 1172 1172 tr_torrentLock( tor ); 1173 1173 assert( tor != NULL ); 1174 assert( 0<=file && file<tor->info.fileCount );1174 assert( file < tor->info.fileCount ); 1175 1175 ret = tor->info.files[file].priority; 1176 1176 tr_torrentUnlock( tor ); … … 1182 1182 tr_torrentGetFilePriorities( const tr_torrent * tor ) 1183 1183 { 1184 int i;1184 tr_file_index_t i; 1185 1185 tr_priority_t * p; 1186 1186 … … 1200 1200 int 1201 1201 tr_torrentGetFileDL( const tr_torrent * tor, 1202 intfile )1202 tr_file_index_t file ) 1203 1203 { 1204 1204 int doDownload; 1205 1205 tr_torrentLock( tor ); 1206 1206 1207 assert( 0<=file && file<tor->info.fileCount );1207 assert( file < tor->info.fileCount ); 1208 1208 doDownload = !tor->info.files[file].dnd; 1209 1209 … … 1213 1213 1214 1214 static void 1215 setFileDND( tr_torrent * tor,1216 intfileIndex,1217 int doDownload )1215 setFileDND( tr_torrent * tor, 1216 tr_file_index_t fileIndex, 1217 int doDownload ) 1218 1218 { 1219 1219 tr_file * file; 1220 1220 const int dnd = !doDownload; 1221 int firstPiece, firstPieceDND;1222 int lastPiece, lastPieceDND;1223 int i;1221 tr_piece_index_t firstPiece, firstPieceDND; 1222 tr_piece_index_t lastPiece, lastPieceDND; 1223 tr_file_index_t i; 1224 1224 1225 1225 file = &tor->info.files[fileIndex]; … … 1231 1231 every file using that piece is DND */ 1232 1232 firstPieceDND = dnd; 1233 for( i=fileIndex-1; firstPieceDND && i>=0; --i ) {1233 for( i=fileIndex-1; firstPieceDND; --i ) { 1234 1234 if( tor->info.files[i].lastPiece != firstPiece ) 1235 1235 break; 1236 1236 firstPieceDND = tor->info.files[i].dnd; 1237 if( !i ) 1238 break; 1237 1239 } 1238 1240 … … 1252 1254 else 1253 1255 { 1256 tr_piece_index_t pp; 1254 1257 tor->info.pieces[firstPiece].dnd = firstPieceDND; 1255 1258 tor->info.pieces[lastPiece].dnd = lastPieceDND; 1256 for( i=firstPiece+1; i<lastPiece; ++i)1257 tor->info.pieces[ i].dnd = dnd;1258 } 1259 } 1260 1261 void 1262 tr_torrentInitFileDLs ( tr_torrent * tor,1263 int* files,1264 intfileCount,1265 int doDownload )1266 { 1267 int i;1259 for( pp=firstPiece+1; pp<lastPiece; ++pp ) 1260 tor->info.pieces[pp].dnd = dnd; 1261 } 1262 } 1263 1264 void 1265 tr_torrentInitFileDLs ( tr_torrent * tor, 1266 tr_file_index_t * files, 1267 tr_file_index_t fileCount, 1268 int doDownload ) 1269 { 1270 tr_file_index_t i; 1268 1271 tr_torrentLock( tor ); 1269 1272 … … 1276 1279 1277 1280 void 1278 tr_torrentSetFileDLs ( tr_torrent * tor,1279 int* files,1280 intfileCount,1281 int doDownload )1281 tr_torrentSetFileDLs ( tr_torrent * tor, 1282 tr_file_index_t * files, 1283 tr_file_index_t fileCount, 1284 int doDownload ) 1282 1285 { 1283 1286 tr_torrentLock( tor ); … … 1308 1311 ***/ 1309 1312 1310 int 1311 _tr_block( const tr_torrent * tor, int index, int begin ) 1313 tr_block_index_t 1314 _tr_block( const tr_torrent * tor, 1315 tr_piece_index_t index, 1316 uint32_t offset ) 1312 1317 { 1313 1318 const tr_info * inf = &tor->info; 1314 return index * ( inf->pieceSize / tor->blockSize ) + 1315 begin / tor->blockSize; 1319 tr_block_index_t ret; 1320 ret = index; 1321 ret *= ( inf->pieceSize / tor->blockSize ); 1322 ret += offset / tor->blockSize; 1323 return ret; 1316 1324 } 1317 1325 1318 1326 int 1319 1327 tr_torrentReqIsValid( const tr_torrent * tor, 1320 uint32_tindex,1328 tr_piece_index_t index, 1321 1329 uint32_t offset, 1322 1330 uint32_t length ) … … 1324 1332 int err = 0; 1325 1333 1326 if( index >= (uint32_t)tor->info.pieceCount )1334 if( index >= tor->info.pieceCount ) 1327 1335 err = 1; 1328 else if ( (int)offset >= tr_torPieceCountBytes( tor, (int)index ) )1336 else if ( offset >= tr_torPieceCountBytes( tor, index ) ) 1329 1337 err = 2; 1330 1338 else if( length > MAX_BLOCK_SIZE ) … … 1341 1349 fprintf( stderr, "(ticket #751) tor->info.totalSize is %"PRIu64"\n", tor->info.totalSize ); 1342 1350 fprintf( stderr, "(ticket #751) tor->info.pieceCount is %d\n", tor->info.pieceCount ); 1343 fprintf( stderr, "(ticket #751) tr_torPieceCountBytes is %d\n", tr_torPieceCountBytes( tor, (int)index ) );1351 fprintf( stderr, "(ticket #751) tr_torPieceCountBytes is %d\n", tr_torPieceCountBytes( tor, index ) ); 1344 1352 fprintf( stderr, "(ticket #751) tr_pieceOffset is %"PRIu64"\n", tr_pieceOffset( tor, index, offset, length ) ); 1345 1353 } … … 1350 1358 1351 1359 uint64_t 1352 tr_pieceOffset( const tr_torrent * tor, int index, int begin, int length ) 1360 tr_pieceOffset( const tr_torrent * tor, 1361 tr_piece_index_t index, 1362 uint32_t offset, 1363 uint32_t length ) 1353 1364 { 1354 1365 uint64_t ret; 1355 1366 ret = tor->info.pieceSize; 1356 1367 ret *= index; 1357 ret += begin;1368 ret += offset; 1358 1369 ret += length; 1359 1370 return ret; … … 1365 1376 1366 1377 int 1367 tr_torrentIsPieceChecked( const tr_torrent * tor, int piece )1378 tr_torrentIsPieceChecked( const tr_torrent * tor, tr_piece_index_t piece ) 1368 1379 { 1369 1380 return tr_bitfieldHas( tor->checkedPieces, piece ); … … 1371 1382 1372 1383 void 1373 tr_torrentSetPieceChecked( tr_torrent * tor, int piece, int isChecked )1384 tr_torrentSetPieceChecked( tr_torrent * tor, tr_piece_index_t piece, int isChecked ) 1374 1385 { 1375 1386 if( isChecked ) … … 1380 1391 1381 1392 void 1382 tr_torrentSetFileChecked( tr_torrent * tor, int fileIndex, int isChecked )1393 tr_torrentSetFileChecked( tr_torrent * tor, tr_file_index_t fileIndex, int isChecked ) 1383 1394 { 1384 1395 const tr_file * file = &tor->info.files[fileIndex]; 1385 const size_t begin = file->firstPiece;1386 const size_t end = file->lastPiece + 1;1396 const tr_piece_index_t begin = file->firstPiece; 1397 const tr_piece_index_t end = file->lastPiece + 1; 1387 1398 1388 1399 if( isChecked ) … … 1393 1404 1394 1405 int 1395 tr_torrentIsFileChecked( const tr_torrent * tor, int fileIndex )1406 tr_torrentIsFileChecked( const tr_torrent * tor, tr_file_index_t fileIndex ) 1396 1407 { 1397 1408 const tr_file * file = &tor->info.files[fileIndex]; 1398 const size_t begin = file->firstPiece;1399 const size_t end = file->lastPiece + 1;1400 size_t i;1409 const tr_piece_index_t begin = file->firstPiece; 1410 const tr_piece_index_t end = file->lastPiece + 1; 1411 tr_piece_index_t i; 1401 1412 int isChecked = TRUE; 1402 1413 -
trunk/libtransmission/torrent.h
r5204 r5329 27 27 28 28 /* just like tr_torrentSetFileDLs but doesn't trigger a fastresume save */ 29 void tr_torrentInitFileDLs( tr_torrent * tor,30 int* files,31 intfileCount,32 int do_download );29 void tr_torrentInitFileDLs( tr_torrent * tor, 30 tr_file_index_t * files, 31 tr_file_index_t fileCount, 32 int do_download ); 33 33 34 34 int tr_torrentIsPrivate( const tr_torrent * ); … … 38 38 void tr_torrentResetTransferStats( tr_torrent * ); 39 39 40 void tr_torrentSetHasPiece( tr_torrent * tor, int pieceIndex, int has ); 40 void tr_torrentSetHasPiece( tr_torrent * tor, 41 tr_piece_index_t pieceIndex, 42 int has ); 41 43 42 44 void tr_torrentLock ( const tr_torrent * ); … … 74 76 75 77 #define tr_block(a,b) _tr_block(tor,a,b) 76 int _tr_block( const tr_torrent * tor, int index, int begin ); 78 tr_block_index_t _tr_block( const tr_torrent * tor, 79 tr_piece_index_t index, 80 uint32_t offset ); 77 81 78 82 int tr_torrentReqIsValid( const tr_torrent * tor, 79 uint32_tindex,83 tr_piece_index_t index, 80 84 uint32_t offset, 81 85 uint32_t length ); 82 86 83 uint64_t tr_pieceOffset( const tr_torrent * tor, int index, int begin, int length ); 87 uint64_t tr_pieceOffset( const tr_torrent * tor, 88 tr_piece_index_t index, 89 uint32_t offset, 90 uint32_t length ); 84 91 85 void tr_torrentInitFilePriority( tr_torrent * tor,86 intfileIndex,87 tr_priority_t priority );92 void tr_torrentInitFilePriority( tr_torrent * tor, 93 tr_file_index_t fileIndex, 94 tr_priority_t priority ); 88 95 89 96 90 97 int tr_torrentCountUncheckedPieces( const tr_torrent * ); 91 int tr_torrentIsPieceChecked ( const tr_torrent *, int piece );92 int tr_torrentIsFileChecked ( const tr_torrent *, int file );93 void tr_torrentSetPieceChecked ( tr_torrent *, int piece, int isChecked );94 void tr_torrentSetFileChecked ( tr_torrent *, int file, int isChecked );98 int tr_torrentIsPieceChecked ( const tr_torrent *, tr_piece_index_t piece ); 99 int tr_torrentIsFileChecked ( const tr_torrent *, tr_file_index_t file ); 100 void tr_torrentSetPieceChecked ( tr_torrent *, tr_piece_index_t piece, int isChecked ); 101 void tr_torrentSetFileChecked ( tr_torrent *, tr_file_index_t file, int isChecked ); 95 102 void tr_torrentUncheck ( tr_torrent * ); 96 103 … … 123 130 124 131 /* How many bytes we ask for per request */ 125 intblockSize;126 intblockCount;132 uint32_t blockSize; 133 tr_block_index_t blockCount; 127 134 128 intlastBlockSize;129 intlastPieceSize;135 uint32_t lastBlockSize; 136 uint32_t lastPieceSize; 130 137 131 intblockCountInPiece;132 intblockCountInLastPiece;138 uint32_t blockCountInPiece; 139 uint32_t blockCountInLastPiece; 133 140 134 141 struct tr_completion * completion; -
trunk/libtransmission/transmission.h
r5286 r5329 50 50 51 51 #define TR_DEFAULT_PORT 51413 52 53 typedef uint32_t tr_file_index_t; 54 typedef uint32_t tr_piece_index_t; 55 typedef uint64_t tr_block_index_t; 52 56 53 57 enum … … 304 308 * priority must be one of TR_PRI_NORMAL, _HIGH, or _LOW */ 305 309 void tr_torrentSetFilePriorities( tr_torrent * tor, 306 int* files,307 intfileCount,310 tr_file_index_t * files, 311 tr_file_index_t fileCount, 308 312 tr_priority_t priority ); 309 313 … … 315 319 /* single-file form of tr_torrentGetFilePriorities. 316 320 * returns one of TR_PRI_NORMAL, _HIGH, or _LOW. */ 317 tr_priority_t tr_torrentGetFilePriority( const tr_torrent *, int file );321 tr_priority_t tr_torrentGetFilePriority( const tr_torrent *, tr_file_index_t file ); 318 322 319 323 /* returns true if the file's `download' flag is set */ 320 int tr_torrentGetFileDL( const tr_torrent *, int file );324 int tr_torrentGetFileDL( const tr_torrent *, tr_file_index_t file ); 321 325 322 326 /* set a batch of files to be downloaded or not. */ 323 void tr_torrentSetFileDLs ( tr_torrent * tor,324 int* files,325 intfileCount,326 int do_download );327 void tr_torrentSetFileDLs ( tr_torrent * tor, 328 tr_file_index_t * files, 329 tr_file_index_t fileCount, 330 int do_download ); 327 331 328 332 /*********************************************************************** … … 585 589 586 590 typedef struct tr_file_stat tr_file_stat; 587 tr_file_stat * tr_torrentFiles( const tr_torrent *, int * fileCount );588 void tr_torrentFilesFree( tr_file_stat *, int fileCount );591 tr_file_stat * tr_torrentFiles( const tr_torrent *, tr_file_index_t * fileCount ); 592 void tr_torrentFilesFree( tr_file_stat *, tr_file_index_t fileCount ); 589 593 590 594 … … 630 634 typedef struct tr_file 631 635 { 632 uint64_t length; /* Length of the file, in bytes */633 char * name; /* Path to the file */634 int8_t priority; /* TR_PRI_HIGH, _NORMAL, or _LOW */635 int8_t dnd; /* nonzero if the file shouldn't be downloaded */636 intfirstPiece; /* We need pieces [firstPiece... */637 intlastPiece; /* ...lastPiece] to dl this file */638 uint64_t offset; /* file begins at the torrent's nth byte */636 uint64_t length; /* Length of the file, in bytes */ 637 char * name; /* Path to the file */ 638 int8_t priority; /* TR_PRI_HIGH, _NORMAL, or _LOW */ 639 int8_t dnd; /* nonzero if the file shouldn't be downloaded */ 640 tr_piece_index_t firstPiece; /* We need pieces [firstPiece... */ 641 tr_piece_index_t lastPiece; /* ...lastPiece] to dl this file */ 642 uint64_t offset; /* file begins at the torrent's nth byte */ 639 643 } 640 644 tr_file; … … 686 690 687 691 /* Pieces info */ 688 intpieceSize;689 intpieceCount;692 uint32_t pieceSize; 693 tr_piece_index_t pieceCount; 690 694 uint64_t totalSize; 691 695 tr_piece * pieces; 692 696 693 697 /* Files info */ 694 intfileCount;698 tr_file_index_t fileCount; 695 699 tr_file * files; 696 700 }; … … 793 797 char errorString[128]; 794 798 795 796 799 float recheckProgress; 797 800 float percentComplete; -
trunk/libtransmission/verify.c
r5303 r5329 58 58 59 59 static void 60 checkFile( tr_torrent * tor,61 intfileIndex,62 int * abortFlag )63 { 64 int i;60 checkFile( tr_torrent * tor, 61 tr_file_index_t fileIndex, 62 int * abortFlag ) 63 { 64 tr_piece_index_t i; 65 65 int nofile; 66 66 struct stat sb; … … 106 106 for( ;; ) 107 107 { 108 int i;108 tr_file_index_t i; 109 109 tr_torrent * tor; 110 110 struct verify_node * node;
Note: See TracChangeset
for help on using the changeset viewer.