summaryrefslogtreecommitdiffhomepage
path: root/test/util/fs_util.cc
diff options
context:
space:
mode:
authorNicolas Lacasse <nlacasse@google.com>2020-08-26 10:03:46 -0700
committergVisor bot <gvisor-bot@google.com>2020-08-26 10:05:34 -0700
commit83a8b309e949df4b8f82f26085cd62284f9eeb87 (patch)
tree0c4a80d1db58c46d15c8569359356d387e9db67a /test/util/fs_util.cc
parentebf5293374bc94e01eb58ebe29a1e53aa404d3a7 (diff)
tmpfs: Allow xattrs in the trusted namespace if creds has CAP_SYS_ADMIN.
This is needed to support the overlay opaque attribute. PiperOrigin-RevId: 328552985
Diffstat (limited to 'test/util/fs_util.cc')
-rw-r--r--test/util/fs_util.cc20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/util/fs_util.cc b/test/util/fs_util.cc
index 5418948fe..dffa16183 100644
--- a/test/util/fs_util.cc
+++ b/test/util/fs_util.cc
@@ -15,7 +15,11 @@
#include "test/util/fs_util.h"
#include <dirent.h>
+#ifndef __fuchsia__
+#include <linux/magic.h>
+#endif // __fuchsia__
#include <sys/stat.h>
+#include <sys/statfs.h>
#include <sys/types.h>
#include <unistd.h>
@@ -629,5 +633,21 @@ PosixErrorOr<std::string> ProcessExePath(int pid) {
return ReadLink(absl::StrCat("/proc/", pid, "/exe"));
}
+#ifndef __fuchsia__
+PosixErrorOr<bool> IsTmpfs(const std::string& path) {
+ struct statfs stat;
+ if (statfs(path.c_str(), &stat)) {
+ if (errno == ENOENT) {
+ // Nothing at path, don't raise this as an error. Instead, just report no
+ // tmpfs at path.
+ return false;
+ }
+ return PosixError(errno,
+ absl::StrFormat("statfs(\"%s\", %#p)", path, &stat));
+ }
+ return stat.f_type == TMPFS_MAGIC;
+}
+#endif // __fuchsia__
+
} // namespace testing
} // namespace gvisor