Add SetQuotaInherit API.
This allows setting the "inherit project ID" flags on directories; in
our case, we want to set this on the root of the lower filesystem, eg
"/data/media/0".
Bug: 146419093
Test: manual invocation works
Change-Id: Ic74588fd972d464e7021bef953da0e5aaafc4286
diff --git a/Utils.cpp b/Utils.cpp
index dc1c593..d5e0ca8 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.