Merge "Add SetQuotaInherit API."
diff --git a/Utils.cpp b/Utils.cpp
index 5dde4b0..b2a1992 100644
--- a/Utils.cpp
+++ b/Utils.cpp
@@ -116,7 +116,33 @@
}
}
-int SetQuotaProjectId(std::string path, long projectId) {
+int SetQuotaInherit(const std::string& path) {
+ unsigned long flags;
+
+ android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(path.c_str(), O_RDONLY | O_CLOEXEC)));
+ if (fd == -1) {
+ PLOG(ERROR) << "Failed to open " << path << " to set project id inheritance.";
+ return -1;
+ }
+
+ int ret = ioctl(fd, FS_IOC_GETFLAGS, &flags);
+ if (ret == -1) {
+ PLOG(ERROR) << "Failed to get flags for " << path << " to set project id inheritance.";
+ return ret;
+ }
+
+ flags |= FS_PROJINHERIT_FL;
+
+ ret = ioctl(fd, FS_IOC_SETFLAGS, &flags);
+ if (ret == -1) {
+ PLOG(ERROR) << "Failed to set flags for " << path << " to set project id inheritance.";
+ return ret;
+ }
+
+ return 0;
+}
+
+int SetQuotaProjectId(const std::string& path, long projectId) {
struct fsxattr fsx;
android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(path.c_str(), O_RDONLY | O_CLOEXEC)));
diff --git a/Utils.h b/Utils.h
index 90ae8c6..b35250d 100644
--- a/Utils.h
+++ b/Utils.h
@@ -53,7 +53,8 @@
status_t CreateDeviceNode(const std::string& path, dev_t dev);
status_t DestroyDeviceNode(const std::string& path);
-int SetQuotaProjectId(std::string path, long projectId);
+int SetQuotaInherit(const std::string& path);
+int SetQuotaProjectId(const std::string& path, long projectId);
/*
* Recursively calls fs_prepare_dir() on all components in 'path', starting at 'root'.
* 'path' must start with 'root'. Sets up quota project IDs correctly.