- Home /
System.IO.DriveInfo returns wrong disk space values on Mac
I am having trouble getting the correct AvailableFreeSpace values from my Mac desktop computer. I am working with Unity3D C#, and am using the following code :
DriveInfo[] drives =DriveInfo.GetDrives();
foreach(DriveInfo drive in drives)
{
if(drive.IsReady)
{
Debug.Log(drive.Name);
Debug.Log(drive.AvailableFreeSpace);
Debug.Log(drive.TotalFreeSpace);
Debug.Log(drive.TotalSize);
}
}
My results are a bit weird. I'm only getting one drive : The name I'm getting is "/", and ythe values are wrong. AvailableFreeSpace returns a higher value than TotalSize, which makes no sense. Also, the DriveType is Unknown and the drive Format is unixfs, if that helps.
Don't know if I'm missing something obvious about the file structure on a Mac computer, maybe?
I have a SATA HDD with 500go divided into two partitions. Shouldn't it give me 2 drives?
EDIT : My Monodevelop version is 4.0.1, so I don't think this is related to the bug reported years ago on version 2.10.0 or something like that.
What am I doing wrong?
Answer by Bunny83 · Mar 04, 2016 at 01:02 PM
Well, i don't have a mac, but Unix based systems (like MacOS / Linux) don't really work with "drives" in the same sense as Windows does. The filesystem only has a root folder and any HDD partition is usually mapped to a "folder" inside the root folder.
Since NTFS such a behaviour can also be used on Windows machines. Instead of giving an HDD partition a drive letter you can map it into a folder of another drive. I would guess that by doing so you would get similar strange results. "TotalSize" is most likely related to the "main" drive while the other two might be calculated from the actual available space.
On windows for example the "windows" folder uses a lot hardlinks inside subfolders. This makes the size of the windows folder to appear way larger than it actually is since some files / folders are counted multiple times.
As far as i can read from the MSDN documentation, "TotalSize" and "TotalFreeSpace" actually belong to the physical drive while "AvailableFreeSpace" might take mapped drives into account as well.
I can't test any of those since i don't have a Mac.
Your answer
![](https://koobas.hobune.stream/wayback/20220613151852im_/https://answers.unity.com/themes/thub/images/avi.jpg)