struct dqblk dq;
dq.dqb_valid = QIF_BLIMITS | QIF_BTIME;
dq.dqb_bhardlimit = hardLimit;
dq.dqb_bsoftlimit = softLimit;
dq.dqb_btime = gracePeriod;
// get userdata file system path from /proc/mounts
std::ifstream in("/proc/mounts");
if (!in.is_open()) {
return error("Failed to read mounts");
}
std::string source;
std::string target;
std::string ignored;
while (!in.eof()) {
std::getline(in, source, ' ');
std::getline(in, target, ' ');
std::getline(in, ignored);
if (target.compare(0, 5, "/data") == 0) {
LOG(DEBUG) << "Found /data mount " << source << " at " << target;
break;
}
}
if (quotactl(QCMD(Q_SETQUOTA, USRQUOTA), source.c_str(), userId,
reinterpret_cast<char*>(&dq)) != 0) {
PLOG(ERROR) << "Failed to set quota for " << userId;
return error("setQuota failed");
} else {
LOG(DEBUG) << "setQuota for " << userId << ", softLimit: " << softLimit << ", hardLimit: "
<< hardLimit << ", gracePeriod: " << gracePeriod;
}