|
|
c62b8e |
From 5d73882b52d92e38b39ec84255e4b44ccbc4b3f8 Mon Sep 17 00:00:00 2001
|
|
|
c62b8e |
From: David Tardon <dtardon@redhat.com>
|
|
|
c62b8e |
Date: Thu, 3 Jan 2019 13:04:10 +0100
|
|
|
c62b8e |
Subject: [PATCH] backport fd_is_fs_type
|
|
|
c62b8e |
|
|
|
c62b8e |
Related: #1663143
|
|
|
c62b8e |
---
|
|
|
c62b8e |
src/shared/util.c | 16 ++++++++++++++++
|
|
|
c62b8e |
src/shared/util.h | 8 ++++++++
|
|
|
c62b8e |
2 files changed, 24 insertions(+)
|
|
|
c62b8e |
|
|
|
c62b8e |
diff --git a/src/shared/util.c b/src/shared/util.c
|
|
|
c62b8e |
index 4ba4693668..2838d50f6f 100644
|
|
|
c62b8e |
--- a/src/shared/util.c
|
|
|
c62b8e |
+++ b/src/shared/util.c
|
|
|
c62b8e |
@@ -9186,3 +9186,19 @@ int wait_for_terminate_with_timeout(pid_t pid, usec_t timeout) {
|
|
|
c62b8e |
|
|
|
c62b8e |
return -EPROTO;
|
|
|
c62b8e |
}
|
|
|
c62b8e |
+
|
|
|
c62b8e |
+bool is_fs_type(const struct statfs *s, statfs_f_type_t magic_value) {
|
|
|
c62b8e |
+ assert(s);
|
|
|
c62b8e |
+ assert_cc(sizeof(statfs_f_type_t) >= sizeof(s->f_type));
|
|
|
c62b8e |
+
|
|
|
c62b8e |
+ return F_TYPE_EQUAL(s->f_type, magic_value);
|
|
|
c62b8e |
+}
|
|
|
c62b8e |
+
|
|
|
c62b8e |
+int fd_is_fs_type(int fd, statfs_f_type_t magic_value) {
|
|
|
c62b8e |
+ struct statfs s;
|
|
|
c62b8e |
+
|
|
|
c62b8e |
+ if (fstatfs(fd, &s) < 0)
|
|
|
c62b8e |
+ return -errno;
|
|
|
c62b8e |
+
|
|
|
c62b8e |
+ return is_fs_type(&s, magic_value);
|
|
|
c62b8e |
+}
|
|
|
c62b8e |
diff --git a/src/shared/util.h b/src/shared/util.h
|
|
|
c62b8e |
index 8fc237495a..f768936ab1 100644
|
|
|
c62b8e |
--- a/src/shared/util.h
|
|
|
c62b8e |
+++ b/src/shared/util.h
|
|
|
c62b8e |
@@ -36,6 +36,7 @@
|
|
|
c62b8e |
#include <limits.h>
|
|
|
c62b8e |
#include <sys/types.h>
|
|
|
c62b8e |
#include <sys/stat.h>
|
|
|
c62b8e |
+#include <sys/statfs.h>
|
|
|
c62b8e |
#include <dirent.h>
|
|
|
c62b8e |
#include <sys/resource.h>
|
|
|
c62b8e |
#include <stddef.h>
|
|
|
c62b8e |
@@ -1147,3 +1148,10 @@ static inline void block_signals_reset(sigset_t *ss) {
|
|
|
c62b8e |
|
|
|
c62b8e |
char* set_iovec_string_field(struct iovec *iovec, unsigned int *n_iovec, const char *field, const char *value);
|
|
|
c62b8e |
char* set_iovec_field_free(struct iovec *iovec, unsigned int *n_iovec, const char *field, char *value);
|
|
|
c62b8e |
+
|
|
|
c62b8e |
+/* The .f_type field of struct statfs is really weird defined on
|
|
|
c62b8e |
+ * different archs. Let's give its type a name. */
|
|
|
c62b8e |
+typedef typeof(((struct statfs*)NULL)->f_type) statfs_f_type_t;
|
|
|
c62b8e |
+
|
|
|
c62b8e |
+bool is_fs_type(const struct statfs *s, statfs_f_type_t magic_value) _pure_;
|
|
|
c62b8e |
+int fd_is_fs_type(int fd, statfs_f_type_t magic_value);
|