Changeset 5329


Ignore:
Timestamp:
Mar 22, 2008, 6:10:59 PM (13 years ago)
Author:
charles
Message:

fix bug that caused very large torrents to crash Transmission

Location:
trunk
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/cli/transmissioncli.c

    r5143 r5329  
    179179        if( !tr_torrentParse( h, ctor, &info ) )
    180180        {
     181            tr_file_index_t ff;
     182
    181183            printf( "hash:\t" );
    182184            for( i=0; i<SHA_DIGEST_LENGTH; ++i )
     
    209211
    210212            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 );
    213215
    214216            tr_metainfoFree( &info );
  • trunk/gtk/file-list.c

    r5290 r5329  
    266266    /* update this node */
    267267    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    }
    270272    gtk_tree_store_set( store, iter, FC_ENABLED, enabled, -1 );
    271273
     
    282284                 gboolean         enabled )
    283285{
    284     GArray * indices = g_array_new( FALSE, FALSE, sizeof(int) );
     286    GArray * indices = g_array_new( FALSE, FALSE, sizeof(tr_file_index_t) );
    285287    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 );
    287289    g_array_free( indices, TRUE );
    288290}
     
    319321    GArray * indices = g_array_new( FALSE, FALSE, sizeof(int) );
    320322    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 );
    322324    g_array_free( indices, TRUE );
    323325}
     
    371373    {
    372374        guint64 foo, bar;
    373         int fileCount;
     375        tr_file_index_t fileCount;
    374376        tr_torrent * tor;
    375377        tr_file_stat * fileStats;
     
    425427    if( gtor )
    426428    {
    427         int i;
     429        tr_file_index_t i;
    428430        const tr_info * inf = tr_torrent_info( gtor );
    429431        tr_torrent * tor = tr_torrent_handle( gtor );
  • trunk/gtk/tr-torrent.c

    r5313 r5329  
    333333tr_torrent_delete_files( TrTorrent * gtor )
    334334{
    335     int i;
     335    tr_file_index_t i;
    336336    const tr_info * info = tr_torrent_info( gtor );
    337337    const char * stop = tr_torrentGetFolder( tr_torrent_handle( gtor ) );
  • trunk/gtk/tr-window.c

    r5313 r5329  
    270270                 const char          * text )
    271271{
    272     int i;
     272    tr_file_index_t i;
    273273    int ret = 0;
    274274    char * pch;
  • trunk/libtransmission/completion.c

    r5001 r5329  
    9898    const tr_info * info = &tor->info;
    9999    uint64_t have=0, total=0;
    100     int i;
     100    tr_piece_index_t i;
    101101    tr_completion * cp ;
    102102
     
    138138
    139139int
    140 tr_cpPieceIsComplete( const tr_completion * cp, int piece )
    141 {
    142     assert( piece >= 0 );
     140tr_cpPieceIsComplete( const tr_completion  * cp,
     141                      tr_piece_index_t       piece )
     142{
    143143    assert( piece < cp->tor->info.pieceCount );
    144144    assert( cp->completeBlocks[piece] <= tr_torPieceCountBlocks(cp->tor,piece) );
     
    153153
    154154void
    155 tr_cpPieceAdd( tr_completion * cp, int piece )
     155tr_cpPieceAdd( tr_completion * cp, tr_piece_index_t piece )
    156156{
    157157    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;
    161161
    162162    for( i=start; i<end; ++i )
     
    165165
    166166void
    167 tr_cpPieceRem( tr_completion * cp, int piece )
     167tr_cpPieceRem( tr_completion * cp, tr_piece_index_t piece )
    168168{
    169169    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 );
    176175    assert( piece < tor->info.pieceCount );
    177     assert( 0 <= start );
    178176    assert( start < tor->blockCount );
    179177    assert( start <= end );
     
    198196}
    199197
    200 int tr_cpBlockIsComplete( const tr_completion * cp, int block )
     198int
     199tr_cpBlockIsComplete( const tr_completion * cp, tr_block_index_t block )
    201200{
    202201    return tr_bitfieldHas( cp->blockBitfield, block ) ? 1 : 0;
     
    204203
    205204void
    206 tr_cpBlockAdd( tr_completion * cp, int block )
     205tr_cpBlockAdd( tr_completion * cp, tr_block_index_t block )
    207206{
    208207    const tr_torrent * tor = cp->tor;
     
    210209    if( !tr_cpBlockIsComplete( cp, block ) )
    211210    {
    212         const int piece = tr_torBlockPiece( tor, block );
     211        const tr_piece_index_t piece = tr_torBlockPiece( tor, block );
    213212        const int blockSize = tr_torBlockCountBytes( tor, block );
    214213
     
    241240tr_cpBlockBitfieldSet( tr_completion * cp, tr_bitfield * bitfield )
    242241{
    243     int i;
     242    tr_block_index_t i;
    244243
    245244    assert( cp != NULL );
     
    253252}
    254253
    255 float tr_cpPercentBlocksInPiece( const tr_completion * cp, int piece )
     254float
     255tr_cpPercentBlocksInPiece( const tr_completion * cp, tr_piece_index_t piece )
    256256{
    257257    assert( cp != NULL );
     
    261261
    262262int
    263 tr_cpMissingBlocksInPiece( const tr_completion * cp, int piece )
     263tr_cpMissingBlocksInPiece( const tr_completion * cp, tr_piece_index_t piece )
    264264{
    265265    assert( cp != NULL );
     
    324324    const tr_torrent * tor = cp->tor;
    325325    const tr_info * info = &tor->info;
    326     int i;
     326    tr_piece_index_t i;
    327327
    328328    for( i=0; i<info->pieceCount; ++i )
  • trunk/libtransmission/completion.h

    r5001 r5329  
    4646
    4747/* 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 );
     48int              tr_cpPieceIsComplete( const tr_completion *, tr_piece_index_t piece );
     49void             tr_cpPieceAdd( tr_completion *, tr_piece_index_t piece );
     50void             tr_cpPieceRem( tr_completion *, tr_piece_index_t piece );
    5151
    5252/* Blocks */
    53 int              tr_cpBlockIsComplete( const tr_completion *, int block );
    54 void             tr_cpBlockAdd( tr_completion *, int block );
     53int              tr_cpBlockIsComplete( const tr_completion *, tr_block_index_t block );
     54void             tr_cpBlockAdd( tr_completion *, tr_block_index_t block );
    5555void             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 );
     56float            tr_cpPercentBlocksInPiece( const tr_completion * cp, tr_piece_index_t piece );
     57int              tr_cpMissingBlocksInPiece( const tr_completion * cp, tr_piece_index_t piece );
    5858
    5959
  • trunk/libtransmission/fastresume.c

    r5313 r5329  
    400400               uint32_t         len )
    401401{
    402     int i;
    403402    uint64_t ret = 0;
    404403   
    405404    if( len == FR_PROGRESS_LEN( tor ) )
    406405    {
     406        int i;
    407407        int n;
    408408        tr_bitfield bitfield;
     
    434434    /* the files whose mtimes are wrong,
    435435       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    }
    439442
    440443    return ret;
     
    450453        const size_t n = tor->info.fileCount;
    451454        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;
    454457        size_t i;
    455458        const uint8_t * walk = buf;
     
    468471
    469472        /* 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 );
    472475        for( i=0; i<n; ++i )
    473476            if( *walk++ == 't' ) /* 't' means the DND flag is true */
  • trunk/libtransmission/inout.c

    r5286 r5329  
    4242readOrWriteBytes( const tr_torrent  * tor,
    4343                  int                 ioMode,
    44                   int                 fileIndex,
     44                  tr_file_index_t     fileIndex,
    4545                  uint64_t            fileOffset,
    4646                  void              * buf,
     
    5757    int fileExists;
    5858
    59     assert( 0<=fileIndex && fileIndex<info->fileCount );
     59    assert( fileIndex < info->fileCount );
    6060    assert( !file->length || (fileOffset < file->length));
    6161    assert( fileOffset + buflen <= file->length );
     
    8989static tr_errno
    9090findFileLocation( const tr_torrent * tor,
    91                   int                pieceIndex,
    92                   int                pieceOffset,
    93                   int              * fileIndex,
     91                  tr_piece_index_t   pieceIndex,
     92                  uint32_t           pieceOffset,
     93                  tr_file_index_t  * fileIndex,
    9494                  uint64_t         * fileOffset )
    9595{
    9696    const tr_info * info = &tor->info;
    9797
    98     int i;
     98    tr_file_index_t i;
    9999    uint64_t piecePos = ((uint64_t)pieceIndex * info->pieceSize) + pieceOffset;
    100100
    101     if( pieceIndex < 0 || pieceIndex >= info->pieceCount )
     101    if( pieceIndex >= info->pieceCount )
    102102        return TR_ERROR_ASSERT;
    103103    if( pieceOffset >= tr_torPieceCountBytes( tor, pieceIndex ) )
     
    112112    *fileOffset = piecePos;
    113113
    114     assert( 0<=*fileIndex && *fileIndex<info->fileCount );
     114    assert( *fileIndex < info->fileCount );
    115115    assert( *fileOffset < info->files[i].length );
    116116    return 0;
     
    120120static tr_errno
    121121ensureMinimumFileSize( const tr_torrent  * tor,
    122                        int                 fileIndex,
     122                       tr_file_index_t     fileIndex,
    123123                       uint64_t            minBytes )
    124124{
     
    151151
    152152static tr_errno
    153 readOrWritePiece( tr_torrent  * tor,
    154                   int           ioMode,
    155                   int           pieceIndex,
    156                   int           pieceOffset,
    157                   uint8_t     * buf,
    158                   size_t        buflen )
     153readOrWritePiece( tr_torrent        * tor,
     154                  int                 ioMode,
     155                  tr_piece_index_t    pieceIndex,
     156                  uint32_t            pieceOffset,
     157                  uint8_t           * buf,
     158                  size_t              buflen )
    159159{
    160160    tr_errno err = 0;
    161     int fileIndex;
     161    tr_file_index_t fileIndex;
    162162    uint64_t fileOffset;
    163163    const tr_info * info = &tor->info;
    164164
    165     if( pieceIndex < 0 || pieceIndex >= tor->info.pieceCount )
     165    if( pieceIndex >= tor->info.pieceCount )
    166166        err = TR_ERROR_ASSERT;
    167167    else if( buflen > ( size_t ) tr_torPieceCountBytes( tor, pieceIndex ) )
     
    195195tr_errno
    196196tr_ioRead( const tr_torrent  * tor,
    197            int                 pieceIndex,
    198            int                 begin,
    199            int                 len,
     197           tr_piece_index_t    pieceIndex,
     198           uint32_t            begin,
     199           uint32_t            len,
    200200           uint8_t           * buf )
    201201{
     
    204204
    205205tr_errno
    206 tr_ioWrite( tr_torrent     * tor,
    207             int              pieceIndex,
    208             int              begin,
    209             int              len,
    210             const uint8_t  * buf )
     206tr_ioWrite( tr_torrent        * tor,
     207            tr_piece_index_t    pieceIndex,
     208            uint32_t            begin,
     209            uint32_t            len,
     210            const uint8_t     * buf )
    211211{
    212212    return readOrWritePiece( tor, TR_IO_WRITE, pieceIndex, begin, (uint8_t*)buf, len );
     
    219219static tr_errno
    220220tr_ioRecalculateHash( const tr_torrent  * tor,
    221                       int                 pieceIndex,
     221                      tr_piece_index_t    pieceIndex,
    222222                      uint8_t           * setme )
    223223{
     
    239239    assert( tor != NULL );
    240240    assert( setme != NULL );
    241     assert( 0<=pieceIndex && pieceIndex<tor->info.pieceCount );
     241    assert( pieceIndex < tor->info.pieceCount );
    242242
    243243    info = &tor->info;
  • trunk/libtransmission/inout.h

    r5045 r5329  
    3434 */
    3535int tr_ioRead  ( const struct tr_torrent  * tor,
    36                  int                        pieceIndex,
    37                  int                        offset,
    38                  int                        len,
     36                 tr_piece_index_t           pieceIndex,
     37                 uint32_t                   offset,
     38                 uint32_t                   len,
    3939                 uint8_t                  * setme );
    4040
     
    4545 */
    4646tr_errno tr_ioWrite ( struct tr_torrent  * tor,
    47                       int                  pieceIndex,
    48                       int                  offset,
    49                       int                  len,
     47                      tr_piece_index_t     pieceIndex,
     48                      uint32_t             offset,
     49                      uint32_t             len,
    5050                      const uint8_t      * writeme );
    5151
  • trunk/libtransmission/ipcparse.c

    r5172 r5329  
    503503    tr_benc * dict, * item, * file, * tier;
    504504    int          ii, jj, kk;
     505    tr_file_index_t ff;
    505506
    506507    /* always send torrent id */
     
    568569                    return -1;
    569570                }
    570                 for( jj = 0; inf->fileCount > jj; jj++ )
     571                for( ff = 0; inf->fileCount > ff; ff++ )
    571572                {
    572573                    file = tr_bencListAdd( item );
     
    577578                    }
    578579                    tr_bencInitStr( tr_bencDictAdd( file, "name" ),
    579                                     inf->files[jj].name, -1, 1 );
     580                                    inf->files[ff].name, -1, 1 );
    580581                    tr_bencInitInt( tr_bencDictAdd( file, "size" ),
    581                                     inf->files[jj].length );
     582                                    inf->files[ff].length );
    582583                }
    583584                break;
  • trunk/libtransmission/metainfo.c

    r5313 r5329  
    172172tr_metainfoParse( tr_info * inf, const tr_benc * meta_in, const char * tag )
    173173{
    174     int i;
     174    tr_piece_index_t i;
    175175    tr_benc * beInfo, * val, * val2;
    176176    tr_benc * meta = (tr_benc *) meta_in;
     
    305305void tr_metainfoFree( tr_info * inf )
    306306{
     307    tr_file_index_t ff;
    307308    int i, j;
    308309
    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 );
    311312
    312313    tr_free( inf->pieces );
  • trunk/libtransmission/peer-mgr.c

    r5204 r5329  
    595595static int
    596596isPieceInteresting( const tr_torrent  * tor,
    597                     int                 piece )
     597                    tr_piece_index_t    piece )
    598598{
    599599    if( tor->info.pieces[piece].dnd ) /* we don't want it */
     
    612612    const tr_torrent * tor = t->tor;
    613613    const tr_info * inf = &tor->info;
    614     int i;
     614    tr_piece_index_t i;
    615615    uint32_t poolSize = 0;
    616616    uint32_t * pool = tr_new( uint32_t, inf->pieceCount );
     
    666666
    667667static uint64_t*
    668 getPreferredBlocks( Torrent * t, uint64_t * setmeCount )
     668getPreferredBlocks( Torrent * t, tr_block_index_t * setmeCount )
    669669{
    670670    int s;
     
    704704    for( i=blockCount=0; i<pieceCount; ++i )
    705705    {
    706         const uint32_t index = pieces[i];
     706        const tr_piece_index_t index = pieces[i];
    707707        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;
    711711
    712712        for( block=begin; block<end; ++block )
     
    785785    Torrent * t = vtorrent;
    786786    tr_torrent * tor = t->tor;
    787     uint32_t i;
     787    tr_block_index_t i;
    788788    int peerCount;
    789789    tr_peer ** peers;
    790     uint64_t blockCount;
     790    tr_block_index_t blockCount;
    791791    uint64_t * blocks;
    792792
     
    806806        int j;
    807807
    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 );
    810810        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 );
    812812
    813813        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 ) );
    817817
    818818        /* find a peer who can ask for this block */
  • trunk/libtransmission/peer-msgs.c

    r5300 r5329  
    462462isPeerInteresting( const tr_peermsgs * msgs )
    463463{
    464     int i;
     464    tr_piece_index_t i;
    465465    const tr_torrent * torrent;
    466466    const tr_bitfield * bitfield;
     
    631631sendFastAllowedSet( tr_peermsgs * msgs )
    632632{
    633     int i = 0;
     633    tr_piece_index_t i = 0;
    634634
    635635    while (i <= msgs->torrent->info.pieceCount )
     
    14411441
    14421442static void
    1443 gotBadPiece( tr_peermsgs * msgs, uint32_t pieceIndex )
     1443gotBadPiece( tr_peermsgs * msgs, tr_piece_index_t pieceIndex )
    14441444{
    14451445    const uint32_t byteCount =
    1446         tr_torPieceCountBytes( msgs->torrent, (int)pieceIndex );
     1446        tr_torPieceCountBytes( msgs->torrent, pieceIndex );
    14471447    reassignBytesToCorrupt( msgs, byteCount );
    14481448}
     
    14691469    int err;
    14701470    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 );
    14721472
    14731473    assert( msgs != NULL );
    14741474    assert( req != NULL );
    14751475
    1476     if( req->length != (uint32_t)tr_torBlockCountBytes( msgs->torrent, block ) )
     1476    if( req->length != tr_torBlockCountBytes( msgs->torrent, block ) )
    14771477    {
    14781478        dbgmsg( msgs, "wrong block size -- expected %u, got %d",
  • trunk/libtransmission/torrent.c

    r5313 r5329  
    192192
    193193static void
    194 initFilePieces ( tr_info * info, int fileIndex )
     194initFilePieces ( tr_info * info, tr_file_index_t fileIndex )
    195195{
    196196    tr_file * file = &info->files[fileIndex];
     
    198198
    199199    assert( info != NULL );
    200     assert( 0<=fileIndex && fileIndex<info->fileCount );
     200    assert( fileIndex < info->fileCount );
    201201
    202202    file = &info->files[fileIndex];
     
    208208
    209209static int
    210 pieceHasFile( int piece, const tr_file * file )
     210pieceHasFile( tr_piece_index_t piece, const tr_file * file )
    211211{
    212212    return ( file->firstPiece <= piece ) && ( piece <= file->lastPiece );
     
    215215static tr_priority_t
    216216calculatePiecePriority ( const tr_torrent * tor,
    217                          int                piece,
     217                         tr_piece_index_t   piece,
    218218                         int                fileHint )
    219219{
    220     int i;
     220    tr_file_index_t i;
    221221    int priority = TR_PRI_LOW;
    222222
     
    257257tr_torrentInitFilePieces( tr_torrent * tor )
    258258{
    259     int i;
     259    tr_file_index_t ff;
     260    tr_piece_index_t pp;
    260261    uint64_t offset = 0;
    261262
    262263    assert( tor != NULL );
    263264
    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 );
    272273}
    273274
     
    637638
    638639    {
    639         int i;
     640        tr_piece_index_t i;
    640641        tr_bitfield * availablePieces = tr_peerMgrGetAvailable( tor->handle->peerMgr,
    641642                                                                tor->info.hash );
     
    672673
    673674static uint64_t
    674 fileBytesCompleted ( const tr_torrent * tor, int fileIndex )
     675fileBytesCompleted ( const tr_torrent * tor, tr_file_index_t fileIndex )
    675676{
    676677    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;
    678679    const uint64_t firstBlockOffset =  file->offset % tor->blockSize;
    679680    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;
    681682    const uint64_t lastBlockOffset  = (file->offset + lastOffset) % tor->blockSize;
    682683    uint64_t haveBytes = 0;
    683684
    684685    assert( tor != NULL );
    685     assert( 0<=fileIndex && fileIndex<tor->info.fileCount );
     686    assert( fileIndex < tor->info.fileCount );
    686687    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) );
    689690    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 );
    692693
    693694    if( firstBlock == lastBlock )
     
    698699    else
    699700    {
    700         uint64_t i;
     701        tr_block_index_t i;
    701702
    702703        if( tr_cpBlockIsComplete( tor->completion, firstBlock ) )
     
    715716
    716717tr_file_stat *
    717 tr_torrentFiles( const tr_torrent * tor, int * fileCount )
    718 {
    719     int i;
    720     const int n = tor->info.fileCount;
     718tr_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;
    721722    tr_file_stat * files = tr_new0( tr_file_stat, n );
    722723    tr_file_stat * walk = files;
     
    739740
    740741void
    741 tr_torrentFilesFree( tr_file_stat * files, int fileCount UNUSED )
     742tr_torrentFilesFree( tr_file_stat * files, tr_file_index_t fileCount UNUSED )
    742743{
    743744    tr_free( files );
     
    806807
    807808void
    808 tr_torrentSetHasPiece( tr_torrent * tor, int pieceIndex, int has )
     809tr_torrentSetHasPiece( tr_torrent * tor, tr_piece_index_t pieceIndex, int has )
    809810{
    810811    tr_torrentLock( tor );
    811812
    812813    assert( tor != NULL );
    813     assert( pieceIndex >= 0 );
    814814    assert( pieceIndex < tor->info.pieceCount );
    815815
     
    979979stopTorrent( void * vtor )
    980980{
    981     int i;
     981    tr_file_index_t i;
    982982
    983983    tr_torrent * tor = vtor;
     
    11321132
    11331133void
    1134 tr_torrentInitFilePriority( tr_torrent   * tor,
    1135                             int            fileIndex,
    1136                             tr_priority_t  priority )
    1137 {
    1138     int i;
     1134tr_torrentInitFilePriority( tr_torrent      * tor,
     1135                            tr_file_index_t   fileIndex,
     1136                            tr_priority_t     priority )
     1137{
     1138    tr_piece_index_t i;
    11391139    tr_file * file;
    11401140
    11411141    assert( tor != NULL );
    1142     assert( 0<=fileIndex && fileIndex<tor->info.fileCount );
     1142    assert( fileIndex < tor->info.fileCount );
    11431143    assert( priority==TR_PRI_LOW || priority==TR_PRI_NORMAL || priority==TR_PRI_HIGH );
    11441144
     
    11501150
    11511151void
    1152 tr_torrentSetFilePriorities( tr_torrent     * tor,
    1153                              int            * files,
    1154                              int              fileCount,
    1155                              tr_priority_t    priority )
    1156 {
    1157     int i;
     1152tr_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;
    11581158    tr_torrentLock( tor );
    11591159
     
    11661166
    11671167tr_priority_t
    1168 tr_torrentGetFilePriority( const tr_torrent *  tor, int file )
     1168tr_torrentGetFilePriority( const tr_torrent *  tor, tr_file_index_t file )
    11691169{
    11701170    tr_priority_t ret;
     
    11721172    tr_torrentLock( tor );
    11731173    assert( tor != NULL );
    1174     assert( 0<=file && file<tor->info.fileCount );
     1174    assert( file < tor->info.fileCount );
    11751175    ret = tor->info.files[file].priority;
    11761176    tr_torrentUnlock( tor );
     
    11821182tr_torrentGetFilePriorities( const tr_torrent * tor )
    11831183{
    1184     int i;
     1184    tr_file_index_t i;
    11851185    tr_priority_t * p;
    11861186
     
    12001200int
    12011201tr_torrentGetFileDL( const tr_torrent * tor,
    1202                      int                file )
     1202                     tr_file_index_t    file )
    12031203{
    12041204    int doDownload;
    12051205    tr_torrentLock( tor );
    12061206
    1207     assert( 0<=file && file<tor->info.fileCount );
     1207    assert( file < tor->info.fileCount );
    12081208    doDownload = !tor->info.files[file].dnd;
    12091209
     
    12131213
    12141214static void
    1215 setFileDND( tr_torrent  * tor,
    1216             int           fileIndex,
    1217             int           doDownload )
     1215setFileDND( tr_torrent      * tor,
     1216            tr_file_index_t   fileIndex,
     1217            int               doDownload )
    12181218{
    12191219    tr_file * file;
    12201220    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;
    12241224
    12251225    file = &tor->info.files[fileIndex];
     
    12311231       every file using that piece is DND */
    12321232    firstPieceDND = dnd;
    1233     for( i=fileIndex-1; firstPieceDND && i>=0; --i ) {
     1233    for( i=fileIndex-1; firstPieceDND; --i ) {
    12341234        if( tor->info.files[i].lastPiece != firstPiece )
    12351235            break;
    12361236        firstPieceDND = tor->info.files[i].dnd;
     1237        if( !i )
     1238            break;
    12371239    }
    12381240
     
    12521254    else
    12531255    {
     1256        tr_piece_index_t pp;
    12541257        tor->info.pieces[firstPiece].dnd = firstPieceDND;
    12551258        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                         int            fileCount,
    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
     1264void
     1265tr_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;
    12681271    tr_torrentLock( tor );
    12691272
     
    12761279
    12771280void
    1278 tr_torrentSetFileDLs ( tr_torrent  * tor,
    1279                        int        * files,
    1280                        int           fileCount,
    1281                        int           doDownload )
     1281tr_torrentSetFileDLs ( tr_torrent      * tor,
     1282                       tr_file_index_t * files,
     1283                       tr_file_index_t   fileCount,
     1284                       int               doDownload )
    12821285{
    12831286    tr_torrentLock( tor );
     
    13081311***/
    13091312
    1310 int
    1311 _tr_block( const tr_torrent * tor, int index, int begin )
     1313tr_block_index_t
     1314_tr_block( const tr_torrent  * tor,
     1315           tr_piece_index_t    index,
     1316           uint32_t            offset )
    13121317{
    13131318    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;
    13161324}
    13171325
    13181326int
    13191327tr_torrentReqIsValid( const tr_torrent * tor,
    1320                       uint32_t           index,
     1328                      tr_piece_index_t   index,
    13211329                      uint32_t           offset,
    13221330                      uint32_t           length )
     
    13241332    int err = 0;
    13251333
    1326     if( index >= (uint32_t) tor->info.pieceCount )
     1334    if( index >= tor->info.pieceCount )
    13271335        err = 1;
    1328     else if ( (int)offset >= tr_torPieceCountBytes( tor, (int)index ) )
     1336    else if ( offset >= tr_torPieceCountBytes( tor, index ) )
    13291337        err = 2;
    13301338    else if( length > MAX_BLOCK_SIZE )
     
    13411349        fprintf( stderr, "(ticket #751) tor->info.totalSize is %"PRIu64"\n", tor->info.totalSize );
    13421350        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 ) );
    13441352        fprintf( stderr, "(ticket #751) tr_pieceOffset is %"PRIu64"\n", tr_pieceOffset( tor, index, offset, length ) );
    13451353    }
     
    13501358
    13511359uint64_t
    1352 tr_pieceOffset( const tr_torrent * tor, int index, int begin, int length )
     1360tr_pieceOffset( const tr_torrent * tor,
     1361                tr_piece_index_t   index,
     1362                uint32_t           offset,
     1363                uint32_t           length )
    13531364{
    13541365    uint64_t ret;
    13551366    ret = tor->info.pieceSize;
    13561367    ret *= index;
    1357     ret += begin;
     1368    ret += offset;
    13581369    ret += length;
    13591370    return ret;
     
    13651376
    13661377int
    1367 tr_torrentIsPieceChecked( const tr_torrent * tor, int piece )
     1378tr_torrentIsPieceChecked( const tr_torrent * tor, tr_piece_index_t piece )
    13681379{
    13691380    return tr_bitfieldHas( tor->checkedPieces, piece );
     
    13711382
    13721383void
    1373 tr_torrentSetPieceChecked( tr_torrent * tor, int piece, int isChecked )
     1384tr_torrentSetPieceChecked( tr_torrent * tor, tr_piece_index_t piece, int isChecked )
    13741385{
    13751386    if( isChecked )
     
    13801391
    13811392void
    1382 tr_torrentSetFileChecked( tr_torrent * tor, int fileIndex, int isChecked )
     1393tr_torrentSetFileChecked( tr_torrent * tor, tr_file_index_t fileIndex, int isChecked )
    13831394{
    13841395    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;
    13871398
    13881399    if( isChecked )
     
    13931404
    13941405int
    1395 tr_torrentIsFileChecked( const tr_torrent * tor, int fileIndex )
     1406tr_torrentIsFileChecked( const tr_torrent * tor, tr_file_index_t fileIndex )
    13961407{
    13971408    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;
    14011412    int isChecked = TRUE;
    14021413
  • trunk/libtransmission/torrent.h

    r5204 r5329  
    2727
    2828/* just like tr_torrentSetFileDLs but doesn't trigger a fastresume save */
    29 void tr_torrentInitFileDLs( tr_torrent   * tor,
    30                             int          * files,
    31                             int            fileCount,
    32                             int            do_download );
     29void tr_torrentInitFileDLs( tr_torrent       * tor,
     30                            tr_file_index_t  * files,
     31                            tr_file_index_t    fileCount,
     32                            int                do_download );
    3333
    3434int tr_torrentIsPrivate( const tr_torrent * );
     
    3838void tr_torrentResetTransferStats( tr_torrent * );
    3939
    40 void tr_torrentSetHasPiece( tr_torrent * tor, int pieceIndex, int has );
     40void tr_torrentSetHasPiece( tr_torrent       * tor,
     41                            tr_piece_index_t   pieceIndex,
     42                            int                has );
    4143
    4244void tr_torrentLock    ( const tr_torrent * );
     
    7476
    7577#define tr_block(a,b) _tr_block(tor,a,b)
    76 int _tr_block( const tr_torrent * tor, int index, int begin );
     78tr_block_index_t _tr_block( const tr_torrent * tor,
     79                            tr_piece_index_t   index,
     80                            uint32_t           offset );
    7781
    7882int tr_torrentReqIsValid( const tr_torrent * tor,
    79                           uint32_t           index,
     83                          tr_piece_index_t   index,
    8084                          uint32_t           offset,
    8185                          uint32_t           length );
    8286
    83 uint64_t tr_pieceOffset( const tr_torrent * tor, int index, int begin, int length );
     87uint64_t tr_pieceOffset( const tr_torrent * tor,
     88                         tr_piece_index_t   index,
     89                         uint32_t           offset,
     90                         uint32_t           length );
    8491
    85 void tr_torrentInitFilePriority( tr_torrent   * tor,
    86                                  int            fileIndex,
    87                                  tr_priority_t  priority );
     92void tr_torrentInitFilePriority( tr_torrent       * tor,
     93                                 tr_file_index_t    fileIndex,
     94                                 tr_priority_t      priority );
    8895
    8996
    9097int  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 );
     98int  tr_torrentIsPieceChecked      ( const tr_torrent *, tr_piece_index_t piece );
     99int  tr_torrentIsFileChecked       ( const tr_torrent *, tr_file_index_t file );
     100void tr_torrentSetPieceChecked     ( tr_torrent *, tr_piece_index_t piece, int isChecked );
     101void tr_torrentSetFileChecked      ( tr_torrent *, tr_file_index_t file, int isChecked );
    95102void tr_torrentUncheck             ( tr_torrent * );
    96103
     
    123130   
    124131    /* How many bytes we ask for per request */
    125     int                        blockSize;
    126     int                        blockCount;
     132    uint32_t                   blockSize;
     133    tr_block_index_t           blockCount;
    127134
    128     int                        lastBlockSize;
    129     int                        lastPieceSize;
     135    uint32_t                   lastBlockSize;
     136    uint32_t                   lastPieceSize;
    130137
    131     int                        blockCountInPiece;
    132     int                        blockCountInLastPiece;
     138    uint32_t                   blockCountInPiece;
     139    uint32_t                   blockCountInLastPiece;
    133140   
    134141    struct tr_completion     * completion;
  • trunk/libtransmission/transmission.h

    r5286 r5329  
    5050
    5151#define TR_DEFAULT_PORT   51413
     52
     53typedef uint32_t tr_file_index_t;
     54typedef uint32_t tr_piece_index_t;
     55typedef uint64_t tr_block_index_t;
    5256
    5357enum
     
    304308 * priority must be one of TR_PRI_NORMAL, _HIGH, or _LOW */
    305309void tr_torrentSetFilePriorities( tr_torrent        * tor,
    306                                   int               * files,
    307                                   int                 fileCount,
     310                                  tr_file_index_t   * files,
     311                                  tr_file_index_t     fileCount,
    308312                                  tr_priority_t       priority );
    309313
     
    315319/* single-file form of tr_torrentGetFilePriorities.
    316320 * returns one of TR_PRI_NORMAL, _HIGH, or _LOW. */
    317 tr_priority_t tr_torrentGetFilePriority( const tr_torrent *, int file );
     321tr_priority_t tr_torrentGetFilePriority( const tr_torrent *, tr_file_index_t file );
    318322
    319323/* returns true if the file's `download' flag is set */
    320 int tr_torrentGetFileDL( const tr_torrent *, int file );
     324int tr_torrentGetFileDL( const tr_torrent *, tr_file_index_t file );
    321325
    322326/* set a batch of files to be downloaded or not. */
    323 void tr_torrentSetFileDLs ( tr_torrent   * tor,
    324                             int          * files,
    325                             int            fileCount,
    326                             int            do_download );
     327void tr_torrentSetFileDLs ( tr_torrent      * tor,
     328                            tr_file_index_t * files,
     329                            tr_file_index_t   fileCount,
     330                            int               do_download );
    327331
    328332/***********************************************************************
     
    585589
    586590typedef 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 );
     591tr_file_stat * tr_torrentFiles( const tr_torrent *, tr_file_index_t * fileCount );
     592void tr_torrentFilesFree( tr_file_stat *, tr_file_index_t fileCount );
    589593
    590594
     
    630634typedef struct tr_file
    631635{
    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     int        firstPiece;  /* We need pieces [firstPiece... */
    637     int        lastPiece;   /* ...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 */
    639643}
    640644tr_file;
     
    686690
    687691    /* Pieces info */
    688     int                  pieceSize;
    689     int                  pieceCount;
     692    uint32_t             pieceSize;
     693    tr_piece_index_t     pieceCount;
    690694    uint64_t             totalSize;
    691695    tr_piece           * pieces;
    692696
    693697    /* Files info */
    694     int                  fileCount;
     698    tr_file_index_t      fileCount;
    695699    tr_file            * files;
    696700};
     
    793797    char errorString[128];
    794798
    795 
    796799    float recheckProgress;
    797800    float percentComplete;
  • trunk/libtransmission/verify.c

    r5303 r5329  
    5858
    5959static void
    60 checkFile( tr_torrent   * tor,
    61            int            fileIndex,
    62            int          * abortFlag )
    63 {
    64     int i;
     60checkFile( tr_torrent       * tor,
     61           tr_file_index_t    fileIndex,
     62           int              * abortFlag )
     63{
     64    tr_piece_index_t i;
    6565    int nofile;
    6666    struct stat sb;
     
    106106    for( ;; )
    107107    {
    108         int i;
     108        tr_file_index_t i;
    109109        tr_torrent * tor;
    110110        struct verify_node * node;
Note: See TracChangeset for help on using the changeset viewer.