diff options
author | 2020-01-06 14:04:39 +0100 | |
---|---|---|
committer | 2020-01-06 14:06:15 +0100 | |
commit | 55c0da3208354ea2a8243c0c6f91aa4e957b8703 (patch) | |
tree | 1defe85618fa42b9a20c30acb35cfe784f6452b7 | |
parent | d17f197e1ce86c0289c4f803374c6fc0d9c3e261 (diff) |
installd: add quota API for project IDs.
Add an API to retrieve quota usage on filesystems that support project
ID quotas.
Bug: 146419093
Test: manual test, more tests coming
Change-Id: Ic997e398f0eb1db85768155a779b3a81a060dff3
-rw-r--r-- | cmds/installd/QuotaUtils.cpp | 20 | ||||
-rw-r--r-- | cmds/installd/QuotaUtils.h | 2 |
2 files changed, 22 insertions, 0 deletions
diff --git a/cmds/installd/QuotaUtils.cpp b/cmds/installd/QuotaUtils.cpp index b238dd36e3..f2abf3aea3 100644 --- a/cmds/installd/QuotaUtils.cpp +++ b/cmds/installd/QuotaUtils.cpp @@ -97,6 +97,26 @@ int64_t GetOccupiedSpaceForUid(const std::string& uuid, uid_t uid) { } } +int64_t GetOccupiedSpaceForProjectId(const std::string& uuid, int projectId) { + const std::string device = FindQuotaDeviceForUuid(uuid); + if (device == "") { + return -1; + } + struct dqblk dq; + if (quotactl(QCMD(Q_GETQUOTA, PRJQUOTA), device.c_str(), projectId, + reinterpret_cast<char*>(&dq)) != 0) { + if (errno != ESRCH) { + PLOG(ERROR) << "Failed to quotactl " << device << " for Project ID " << projectId; + } + return -1; + } else { +#if MEASURE_DEBUG + LOG(DEBUG) << "quotactl() for Project ID " << projectId << " " << dq.dqb_curspace; +#endif + return dq.dqb_curspace; + } +} + int64_t GetOccupiedSpaceForGid(const std::string& uuid, gid_t gid) { const std::string device = FindQuotaDeviceForUuid(uuid); if (device == "") { diff --git a/cmds/installd/QuotaUtils.h b/cmds/installd/QuotaUtils.h index 9ad170fcbb..96aca0448e 100644 --- a/cmds/installd/QuotaUtils.h +++ b/cmds/installd/QuotaUtils.h @@ -35,6 +35,8 @@ int64_t GetOccupiedSpaceForUid(const std::string& uuid, uid_t uid); /* Get the current occupied space in bytes for a gid or -1 if fails */ int64_t GetOccupiedSpaceForGid(const std::string& uuid, gid_t gid); +/* Get the current occupied space in bytes for a project id or -1 if fails */ +int64_t GetOccupiedSpaceForProjectId(const std::string& uuid, int projectId); } // namespace installd } // namespace android |