UTM
UTM copied to clipboard
Mismatch in drive size during creation (GB vs GiB)
When you create a Mac virtualized VM, you specify drive size in GB or MB:
![Drive Creation Wizard](https://user-images.githubusercontent.com/1675298/189457752-db3b6fa7-76ec-4a41-ba4a-a1c328a1dd62.png)
But then the VM summary shows a different size:
![VM Summary](https://user-images.githubusercontent.com/1675298/189457832-8d6efb5b-072a-461e-8209-3b26bb5631fe.png)
Same thing when adding a new drive to an existing VM:
![New drive pop up](https://user-images.githubusercontent.com/1675298/189458454-9586ef01-cee8-42d5-a11c-700066a80771.png)
![New drive result](https://user-images.githubusercontent.com/1675298/189458460-83d54359-c4a3-4819-bdaf-8afc21878885.png)
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
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.
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”.
Sure I think it shouldn’t be hard to switch. Just have to make sure the block size constraints are met.