Repository navigation
Commit 8690584
btrfs-progs: fix size formatting for large values
pretty_size_snprintf() converts the size to a float for printing. A float
has a 24 bit mantissa, so values above 16 MiB are rounded to a multiple of
the unit: a 12 TB device is printed as 11718850560.00KiB instead of
11718850304KiB, and -m rounds the value up to a whole MiB.
Print all units with integer arithmetic, including the auto detected unit
used by the human readable output. Bytes and KiB/kB are exact, so they
are printed as plain integers (KiB is divided by 1024). MiB and larger
keep the two decimal digits, computed from the integer remainder. This
removes the float conversion from pretty_size_snprintf() completely.
Fixes: #1212
Signed-off-by: mahailiang <mahailiang@uniontech.com>
[ Remove unnecessary comments, add two short ones explaining the K/B
cases there no fraction digits are needed. ]
Signed-off-by: Qu Wenruo <wqu@suse.com>1 parent 5e64472 commit 8690584
1 file changed
Lines changed: 34 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
49 | 48 | | |
50 | 49 | | |
51 | 50 | | |
52 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
53 | 56 | | |
| 57 | + | |
54 | 58 | | |
55 | 59 | | |
56 | 60 | | |
| |||
139 | 143 | | |
140 | 144 | | |
141 | 145 | | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
146 | 173 | | |
147 | 174 | | |
148 | | - | |
| 175 | + | |
| 176 | + | |
149 | 177 | | |
150 | 178 | | |
151 | 179 | | |
| |||
0 commit comments