chiark / gitweb /
journal: move code that checks for network fs to stat-util.[ch]
authorLennart Poettering <lennart@poettering.net>
Thu, 8 Feb 2018 16:14:37 +0000 (17:14 +0100)
committerSven Eden <yamakuzure@gmx.net>
Wed, 30 May 2018 05:54:00 +0000 (07:54 +0200)
We have similar code in stat-util.[ch] and managing this at a central
place almost definitely is the better choice.

(cherry picked from commit 77f9fa3b8ea46c27e5a5e9270f71bf1b4000c3e0)

src/basic/missing.h
src/basic/stat-util.c
src/basic/stat-util.h

index 59f5ebfe0f0b960be3bca1d128614c173fd518ce..0c23f53420ee93708fe05c8226eb8b7fea772739 100644 (file)
@@ -522,6 +522,10 @@ struct btrfs_ioctl_quota_ctl_args {
 #define BPF_FS_MAGIC 0xcafe4a11
 #endif
 
+#ifndef OCFS2_SUPER_MAGIC
+#define OCFS2_SUPER_MAGIC 0x7461636f
+#endif
+
 #ifndef MS_MOVE
 #define MS_MOVE 8192
 #endif
index 964fa91b23c7052416663c69218a2092f57001ee..270e80feec731db7623ceb0ffff2c0721bc772c0 100644 (file)
@@ -224,8 +224,19 @@ int path_is_fs_type(const char *path, statfs_f_type_t magic_value) {
 #endif // 0
 
 bool is_temporary_fs(const struct statfs *s) {
-    return is_fs_type(s, TMPFS_MAGIC) ||
-           is_fs_type(s, RAMFS_MAGIC);
+        return is_fs_type(s, TMPFS_MAGIC) ||
+                is_fs_type(s, RAMFS_MAGIC);
+}
+
+bool is_network_fs(const struct statfs *s) {
+        return is_fs_type(s, CIFS_MAGIC_NUMBER) ||
+                is_fs_type(s, CODA_SUPER_MAGIC) ||
+                is_fs_type(s, NCP_SUPER_MAGIC) ||
+                is_fs_type(s, NFS_SUPER_MAGIC) ||
+                is_fs_type(s, SMB_SUPER_MAGIC) ||
+                is_fs_type(s, V9FS_MAGIC) ||
+                is_fs_type(s, AFS_SUPER_MAGIC) ||
+                is_fs_type(s, OCFS2_SUPER_MAGIC);
 }
 
 #if 0 /// UNNEEDED by elogind
@@ -238,15 +249,25 @@ int fd_is_temporary_fs(int fd) {
         return is_temporary_fs(&s);
 }
 
+int fd_is_network_fs(int fd) {
+        struct statfs s;
+
+        if (fstatfs(fd, &s) < 0)
+                return -errno;
+
+        return is_network_fs(&s);
+}
+
 int fd_is_network_ns(int fd) {
         int r;
 
         r = fd_is_fs_type(fd, NSFS_MAGIC);
         if (r <= 0)
                 return r;
-        r = ioctl(fd, NS_GET_NSTYPE);
-        if (r < 0)
+
+        if (ioctl(fd, NS_GET_NSTYPE) < 0)
                 return -errno;
+
         return r == CLONE_NEWNET;
 }
 
index db9012300f00800473894b7f917224524392f3e2..6e42731d99285223a749e9af9fd12a29ec1554f5 100644 (file)
@@ -71,9 +71,14 @@ int fd_is_fs_type(int fd, statfs_f_type_t magic_value);
 int path_is_fs_type(const char *path, statfs_f_type_t magic_value);
 
 bool is_temporary_fs(const struct statfs *s) _pure_;
+bool is_network_fs(const struct statfs *s) _pure_;
+
 #if 0 /// UNNEEDED by elogind
 int fd_is_temporary_fs(int fd);
+int fd_is_network_fs(int fd);
+
 int fd_is_network_ns(int fd);
+
 int path_is_temporary_fs(const char *path);
 #endif // 0