How can I check that quotas have been enabled is XFS?

295 Views Asked by At

I have a filesystem that should be mounted with the prjquota flag. But due to human factors, someone might forget to do that, so I need to check that quota was enabled on application startup. I thought that it's possible to check using quotactl with Q_GETFMT as the subcmd argument. But it always sets the flag to 0. What am I doing wrong?

I've tried device as an absolute path to the file under XFS and as a path to the actual device. But no results.

bool isQuotaEnabled(const std::filesystem::path &device)
{
    uint32_t buff{};
    quotactl(QCMD(Q_GETFMT, PRJQUOTA), device.c_str(), 0, (caddr_t)&buff);
    return buff;
}
1

There are 1 best solutions below

0
On
// The argument is something like "/dev/loop1"
bool isQuotaEnabled(const std::filesystem::device& device)
{
    fs_quota_stat info{};
    if (quotactl(QCMD(Q_XGETQSTAT, PRJQUOTA), device.data(), 0, (caddr_t)&info) == -1) {
        throw std::system_error(errno, std::system_category(), "quotactl");
    }

    return static_cast<bool>(info.qs_flags & (XFS_QUOTA_PDQ_ACCT | XFS_QUOTA_PDQ_ENFD));
}

PRJQUOTA is for project quota. Replace it with the one you need.

       Q_XGETQSTAT
              Returns XFS filesystem-specific quota information in the
              fs_quota_stat structure pointed by addr.
Quota enabling flags (of format XFS_QUOTA_[UGP]DQ_{ACCT,ENFD})
          are defined without a leading "X", as
          FS_QUOTA_[UGP]DQ_{ACCT,ENFD}.
                  XFS_QUOTA_PDQ_ACCT  /* Project quota accounting */
                  XFS_QUOTA_PDQ_ENFD  /* Project quota limits enforcement */