Free disk space wrong on M1

Because my app can fill up a hard disk pretty fast I have been using a check for free space for a longer time. Today I got a disk space warning that less than 10% free space was left. But the numbers are totally wrong:

The Finder shows me that I have 114 of 256 GB left:

Using MBS 21.0 on 11.2.1.

Bug?

What is the folderitem pointing to?

That’s the vdb file in the user folder:

Works just fine on my MacBook Air with M1.

I tried again with a new project and the value I get for free space is 14859243520:

dim f as FolderItem = SpecialFolder.Desktop

dim theVolumeInformation as VolumeInformationMBS = f.VolumeInformationMBS
dim FreeBytes as Int64 = theVolumeInformation.Freebytes

macOS is really confused:

Device Identifier: disk3s3
Device Node: /dev/disk3s3
Whole: No
Part of Whole: disk3

Volume Name: Recovery
Mounted: No

Partition Type: 41504653-0000-11AA-AA11-00306543ECAC
File System Personality: APFS
Type (Bundle): apfs
Name (User Visible): APFS
Owners: Disabled

OS Can Be Installed: No
Booter Disk: disk3s2
Recovery Disk: disk3s3
Media Type: Generic
Protocol: Apple Fabric
SMART Status: Verified
Volume UUID: 74E4D4CF-5397-40E5-9C01-76048AA34864
Disk / Partition UUID: 74E4D4CF-5397-40E5-9C01-76048AA34864

Disk Size: 245.1 GB (245107195904 Bytes) (exactly 478724992 512-Byte-Units)
Device Block Size: 4096 Bytes

Container Total Space: 245.1 GB (245107195904 Bytes) (exactly 478724992 512-Byte-Units)
Container Free Space: 13.8 GB (13794820096 Bytes) (exactly 26943008 512-Byte-Units)

Most of the “free space” isn’t free but macOS stupidity:

So what is the correct free space? The 114 GB that Finder shows me or the 14 GB from MBS??? The computer doesn’t even use TimeMachine.

Ah, you may have some snapshots of the file system.
Or stuff in Caches/Temp folders, which gets deleted sometimes.

Apple calls this purgeable space, the first thing to try “Turn it off and on again”. It will then perform some cleaning duties on shutdown (or it might be startup).

Yes, this is purgeable space. But I can’t expect my users to know that. Is there a method to get the Finder free space value?

Just read this: How to fix your mysterious Mac storage problem

Turn it off and on again.

Everytime I want to run a macBS update, I have to reboot the Mac to free this space otherwise it can’t update (macBS is on a 64GB partition).

I’m not using TimeMachine on the computer. The computer does turning off by kernel panic every week. I also can’t expect my users to know about the internal workings of macOS.

I’ve done a bit of searching on StackOverflow. But there were only questions and no answers. How does DaisyDisk identify the purgeable space.

Instead try using a different check for space available, purging is supposed to be automatic (i.e. it’s lazy). Apple Developer Documentation

It uses NSURL resource keys to obtain volume information. If you use the Ohanaware App Kit, I can provide you with code, but I’m sure Christian will be able to look at this and tell you how it’s done using his plugin.

The below code will return a human readable representation of permanent FREE space on a volume, using the Ohanaware App Kit.

Dim outValue, error as integer
Dim nurl as integer = volume( 0 ).NSURL
if NSURLGetResourceValue( nurl, outvalue, "NSURLVolumeAvailableCapacityForImportantUsageKey", error ) then
  freeSpace = formatBytes( xojoValue( outValue ) )
end if

The below code will return a human readable representation of temporary FREE space on a volume, using the Ohanaware App Kit.

Dim outValue, error as integer
Dim nurl as integer = volume( 0 ).NSURL
if NSURLGetResourceValue( nurl, outvalue, "NSURLVolumeAvailableCapacityForOpportunisticUsageKey", error ) then
  freeSpace = formatBytes( xojoValue( outValue ) )
end if

@Sam_Rowlands : Great.

@Christian_Schmitz : what are the equivalents in the MBS plugin? I only see disk size.

Dim n As New NSURLMBS(SpecialFolder.Desktop)
dim value as Variant 
dim error as NSErrorMBS
Dim result As Boolean = n.getResourceValue(value, n.NSURLVolumeAvailableCapacityKey, error)
1 Like

I’ll add NSURLVolumeAvailableCapacityForImportantUsageKey, NSURLVolumeAvailableCapacityForOpportunisticUsageKey and a few others today for next pre-release.

2 Likes

But are you also shutting the computer off by hand? A clean shut down would not only benefit the shut down process, but may also clean more things when the computer starts next time.

Nope, haven’t shut down the computer manually. I’ll try that in the next days.

hello-it

3 Likes