]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
switch_root: improve statfs->f_type portability
authorKarel Zak <kzak@redhat.com>
Thu, 6 Nov 2014 11:50:27 +0000 (12:50 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 6 Nov 2014 11:50:27 +0000 (12:50 +0100)
__SWORD_TYPE is not available everywhere, for example it's not defined
by musl libc. It also seems that __SWORD_TYPE is not used for f_type
on some architectures (s390x).

Reported-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
include/statfs_magic.h
sys-utils/switch_root.c

index b5fde1a238aea82bb464979e0e6f9b11aa3dcc21..d27be1cffb58705836d01488e17c0e355ea522c9 100644 (file)
@@ -1,6 +1,17 @@
 #ifndef UTIL_LINUX_STATFS_MAGIC_H
 #define UTIL_LINUX_STATFS_MAGIC_H
 
+#include <sys/statfs.h>
+
+/*
+ * If possible then don't depend on internal libc __SWORD_TYPE type.
+ */
+#ifdef __GNUC__
+typedef __typeof__( ((struct statfs *)0)->f_type )     ul_statfs_ftype_t;
+#else
+typedef __SWORD_TYPE   ul_statfs_ftype_t;
+#endif
+
 /*
  *  Unfortunately, Linux kernel hedeader file <linux/magic.h> is incomplete
  *  mess and kernel returns by statfs f_type many numbers that are nowhere
index 6822a5d0cebe4379bc266e56241f9fd12fbf5ac4..c6a2eff8e7352efe5283ee9127c439255387b3e6 100644 (file)
@@ -181,8 +181,8 @@ static int switchroot(const char *newroot)
                if (pid <= 0) {
                        struct statfs stfs;
                        if (fstatfs(cfd, &stfs) == 0 &&
-                           (stfs.f_type == (__SWORD_TYPE)STATFS_RAMFS_MAGIC ||
-                            stfs.f_type == (__SWORD_TYPE)STATFS_TMPFS_MAGIC))
+                           (stfs.f_type == (ul_statfs_ftype_t) STATFS_RAMFS_MAGIC ||
+                            stfs.f_type == (ul_statfs_ftype_t) STATFS_TMPFS_MAGIC))
                                recursiveRemove(cfd);
                        else
                                warn(_("old root filesystem is not an initramfs"));