From: Lennart Poettering Date: Thu, 8 Feb 2018 16:14:37 +0000 (+0100) Subject: journal: move code that checks for network fs to stat-util.[ch] X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=1b6b01c3a07ef32d6c524ae914db7af9a67e4f88;p=elogind.git journal: move code that checks for network fs to stat-util.[ch] 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) --- diff --git a/src/basic/missing.h b/src/basic/missing.h index 59f5ebfe0..0c23f5342 100644 --- a/src/basic/missing.h +++ b/src/basic/missing.h @@ -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 diff --git a/src/basic/stat-util.c b/src/basic/stat-util.c index 964fa91b2..270e80fee 100644 --- a/src/basic/stat-util.c +++ b/src/basic/stat-util.c @@ -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; } diff --git a/src/basic/stat-util.h b/src/basic/stat-util.h index db9012300..6e42731d9 100644 --- a/src/basic/stat-util.h +++ b/src/basic/stat-util.h @@ -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