Ticket #2242: mythtv-ftruncate_block_size_and_overflow.patch

File mythtv-ftruncate_block_size_and_overflow.patch, 1.1 KB (added by sphery <mtdean@…>, 15 years ago)
  • programs/mythbackend/mainserver.cpp

     
    16161616            .arg(increment / (1024.0 * 1024.0), 0, 'f', 2)
    16171617            .arg(sleep_time));
    16181618
    1619     // Get the on disk file size and disk block size.
     1619    // Get the on disk file size and preferred I/O block size.
    16201620    struct stat buf;
    16211621    fstat(fd, &buf);
    1622     size_t fsize = buf.st_blksize * buf.st_blocks;
     1622    // Estimate the file size.  Don't use buf.st_blksize * buf.st_blocks
     1623    // The unit for st_blocks is undefined.  See section "RATIONALE" at
     1624    // http://www.opengroup.org/onlinepubs/000095399/basedefs/sys/stat.h.html
     1625    off_t fsize = ((buf.st_size / buf.st_blksize) + 1) * buf.st_blksize;
    16231626
    16241627    // Round truncate increment up to a blocksize, w/min of 1 block.
    16251628    increment = ((increment / buf.st_blksize) + 1) * buf.st_blksize;
    16261629
     1630    // Estimated file size is probably low, so truncate to the estimate first
     1631    fsize += increment;
     1632
    16271633    while (fsize > increment)
    16281634    {
    16291635        fsize -= increment;