pengutronix / genimage

tool to generate multiple filesystem and flash images from a tree
GNU General Public License v2.0
308 stars 110 forks source link

size number precision problems #267

Open learmj opened 1 week ago

learmj commented 1 week ago

Hi. I'm using genimage 16 (Debian) and have run into a spot of trouble with large numbers, eg ERROR: Invalid size suffix '.0G' in '2.0G' I start with a static genimage template containing some tags. After calculating on-disk sizes I run the template through sed to populate the tags with real numbers which are formatted using numfmt --to=si. For example:

image rootA.ext4 {
    exec-post = "<SLOTP> A"
    empty = true
    ext4 {
        use-mke2fs = true
        features = '^64bit,^huge_file'
        label = "ROOTA"
    }
    size = <ROOT_SIZE>
}

..becomes

image rootA.ext4 {
    exec-post = "/path/to/image/post-processing/hook A"
    empty = true
    ext4 {
        use-mke2fs = true
        features = '^64bit,^huge_file'
        label = "ROOTA"
    }
    size = 2.0G
}

Looking at the code, genimage assumes the numerical portion of size will be a single unsigned long long and cannot cope with a decimal point. I imagine this will only be a problem above 1G where the granularity can only be expressed with a decimal point, which is the case when using numfmt with si (or iec or iec-i) output unit specifiers.

I initially thought it was a problem with a 'point zero' rather than a 'point one', but this not the case: ERROR: Invalid size suffix '.1G' in '2.1G'

Is there scope to handle numbers formatted with a decimal point, or should numbers over 1G be specified in M (or K)?

Cheers, -- Matt

learmj commented 1 week ago

fyi, I can work around this by using the following to format the size, instead of numfmt --to=si:

numfmt --to=none --to-unit=1000 --format=%f --suffix=K