UTM icon indicating copy to clipboard operation
UTM copied to clipboard

Mismatch in drive size during creation (GB vs GiB)

Open pointum opened this issue 1 year ago • 3 comments

When you create a Mac virtualized VM, you specify drive size in GB or MB:

Drive Creation Wizard

But then the VM summary shows a different size:

VM Summary

Same thing when adding a new drive to an existing VM:

New drive pop up New drive result

Throughout the project ByteCountFormatter … countStyle: .file is used:

Specifies display of file or storage byte counts. The actual behavior for this is platform-specific; on OS X 10.8, this uses the decimal style, but that may change over time.

So it’s using .decimal (1000 bytes are shown as 1 KB), but size calculations throughout the project use 1024 bytes in 1 KB (e.g. MiB and GiB, not MB and GB) for disk sizes.

I’ve tried to fix this myself, but there’s just too many places this propagates to. I suggest using Int64 bytes for disk sizes throughout the code. At the moment many places use size in MiB as Int, which can’t be converted to/from decimal MB without rounding errors.

I can make a PR, but I want to get some feedback first to make sure the issue and the effort are worth it.

Configuration

  • UTM Version: 4.0.3
  • macOS Version: 12.5.1
  • Mac Chip: M1

pointum avatar Sep 10 '22 00:09 pointum

It's the difference between megabytes (MB) which is 1000 and mibibytes (MiB) which is 1024. I try to make the distinction when possible but it may be missing in some places. Apple APIs for printing sizes all use MB but I made the decision to make configurations use MiB because that's what drive manufactures like to use as well.

osy avatar Sep 10 '22 15:09 osy

I made the decision to make configurations use MiB because that's what drive manufactures like to use as well

But drive manufacturers use decimal MB, not binary MiB. That’s the reason Apple started doing this too. Users were complaining when they get a drive/product advertised in GB (decimal), but in the OS they were seeing smaller disk size (it said “GB” too but was binary). Only memory manufacturers use binary GiB and say “GB”.

pointum avatar Sep 10 '22 20:09 pointum

Sure I think it shouldn’t be hard to switch. Just have to make sure the block size constraints are met.

osy avatar Sep 10 '22 20:09 osy