macOS 上的 statfs 没有给我完整的磁盘容量。为什么?

问题描述 投票:0回答:0

我正在尝试从我的 macOS 应用程序获取存储驱动器容量和可用空间。

我做以下事情:

struct statfs stStg;

if(statfs(".", &stStg) == 0)
{
    uint64_t total_sz = stStg.f_bsize * stStg.f_blocks;
    uint64_t free_sz = stStg.f_bsize * stStg.f_bfree;

    double fTotal = (double)total_sz / (1024.0 * 1024.0 * 1024.0);
    double fFree = (double)free_sz / (1024.0 * 1024.0 * 1024.0);

    printf(""%.02f GB (%.01f%% free)"
                 ,
                 fTotal,
                 100.0 * fFree / fTotal);
}

它给我:

460.43 GB(66.5% 免费)

但是当我在 Finder 中查看时,我得到了更大的容量:

我做错了什么?

c++ macos bsd
© www.soinside.com 2019 - 2024. All rights reserved.