Skip to content
  • Mike Fleetwood's avatar
    Stop using floating point calculations in FS resize() methods (!119) · f098ba1e
    Mike Fleetwood authored and Curtis Gedak's avatar Curtis Gedak committed
    A number of the file system specific resize() methods use floating point
    calculations to convert from the new partition size in sectors to the
    new file system size to be passed to the resize command in bytes or
    kibibytes.  This is bad because there could be rounding errors
    converting from integer to floating point, performing the calculation
    and converting back.  Replace with integer only multiply and divide
    calculations.  Integer division always truncates [1] which is exactly
    what is needed.  The largest integer will be the size of the file system
    in bytes held in a signed 64-bit long long, or Sector or Byte_Value
    typedef of the same type.  This will limit the size that a file system
    can be shrunk to, to 8 EiB - 1 byte.
    
    [1] C++ Arithmetic operators
        https://en.cppreference.com/w/cpp/language/operator_arithmetic
            "the algebraic quotient of integer division is truncated towards
            zero (fractional part is discarded)"
    
    Clos...
    f098ba1e