Ticket #2242: mythtv-ftruncate_block_size_and_overflow.patch
File mythtv-ftruncate_block_size_and_overflow.patch, 1.1 KB (added by , 18 years ago) |
---|
-
programs/mythbackend/mainserver.cpp
1616 1616 .arg(increment / (1024.0 * 1024.0), 0, 'f', 2) 1617 1617 .arg(sleep_time)); 1618 1618 1619 // Get the on disk file size and diskblock size.1619 // Get the on disk file size and preferred I/O block size. 1620 1620 struct stat buf; 1621 1621 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; 1623 1626 1624 1627 // Round truncate increment up to a blocksize, w/min of 1 block. 1625 1628 increment = ((increment / buf.st_blksize) + 1) * buf.st_blksize; 1626 1629 1630 // Estimated file size is probably low, so truncate to the estimate first 1631 fsize += increment; 1632 1627 1633 while (fsize > increment) 1628 1634 { 1629 1635 fsize -= increment;