diff --git a/src/basic/missing.h b/src/basic/missing.h index 9d4d08e7a9..327e6ea67f 100644 --- a/src/basic/missing.h +++ b/src/basic/missing.h @@ -517,6 +517,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 diff --git a/src/basic/stat-util.c b/src/basic/stat-util.c index 3a54103f1b..0fb6750a07 100644 --- a/src/basic/stat-util.c +++ b/src/basic/stat-util.c @@ -214,8 +214,19 @@ int path_is_fs_type(const char *path, statfs_f_type_t magic_value) { } 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); } int fd_is_temporary_fs(int fd) { @@ -227,15 +238,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; } diff --git a/src/basic/stat-util.h b/src/basic/stat-util.h index d8d3c20496..da33e68db2 100644 --- a/src/basic/stat-util.h +++ b/src/basic/stat-util.h @@ -61,8 +61,13 @@ 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_; + 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); /* Because statfs.t_type can be int on some architectures, we have to cast diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c index a8812c9af8..46e2b47344 100644 --- a/src/journal/sd-journal.c +++ b/src/journal/sd-journal.c @@ -51,6 +51,7 @@ #include "process-util.h" #include "replace-var.h" #include "stat-util.h" +#include "stat-util.h" #include "stdio-util.h" #include "string-util.h" #include "strv.h" @@ -1186,22 +1187,12 @@ _public_ int sd_journal_seek_tail(sd_journal *j) { } static void check_network(sd_journal *j, int fd) { - struct statfs sfs; - assert(j); if (j->on_network) return; - if (fstatfs(fd, &sfs) < 0) - return; - - j->on_network = - F_TYPE_EQUAL(sfs.f_type, CIFS_MAGIC_NUMBER) || - F_TYPE_EQUAL(sfs.f_type, CODA_SUPER_MAGIC) || - F_TYPE_EQUAL(sfs.f_type, NCP_SUPER_MAGIC) || - F_TYPE_EQUAL(sfs.f_type, NFS_SUPER_MAGIC) || - F_TYPE_EQUAL(sfs.f_type, SMB_SUPER_MAGIC); + j->on_network = fd_is_network_fs(fd); } static bool file_has_type_prefix(const char *prefix, const char *filename) {