Hello,
I am trying to get space which is consumed by APFS volume. The call getattrlist() works fine on macOS 15 (Apple silicon). However, it returns EINVAL on macOS 11.7.10 (Intel) if ATTR_VOL_SPACEUSED is defined.
struct VolAttrBuf
{
u_int32_t length;
off_t spaceUsed;
} __attribute__((aligned(4), packed));
int64_t GetVolumeSpaceUsed(const std::string& mountPath)
{
struct attrlist attrList;
std::memset(&attrList, 0, sizeof(attrList));
attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_SPACEUSED;
VolAttrBuf attrBuf;
if (getattrlist(mountPath.c_str(), &attrList, &attrBuf, sizeof(attrBuf), 0) ||
attrBuf.length > sizeof(attrBuf))
{
std::cout << "getattrlist() failed with errno (" << errno << ")" << std::endl;
return -1;
}
return attrBuf.spaceUsed;
}
Is it bug or ATTR_VOL_SPACEUSED is unsupported on macOS 11? Are there any other way to get space which is used on an APFS volume? (C++)
Thank you in advance, Pavel
Please see my answer in this thread and ask any followup questions there.
__
Kevin Elliott
DTS Engineer, CoreOS/Hardware