1 From 8f806bb1ea30f15db7ca36d1cfa79349f8115302 Mon Sep 17 00:00:00 2001
2 From: Karel Zak <kzak@redhat.com>
3 Date: Thu, 6 Nov 2014 12:50:27 +0100
4 Subject: [PATCH] switch_root: improve statfs->f_type portability
6 __SWORD_TYPE is not available everywhere, for example it's not defined
7 by musl libc. It also seems that __SWORD_TYPE is not used for f_type
8 on some architectures (s390x).
10 Reported-by: Natanael Copa <ncopa@alpinelinux.org>
11 Signed-off-by: Karel Zak <kzak@redhat.com>
13 include/statfs_magic.h | 11 +++++++++++
14 sys-utils/switch_root.c | 4 ++--
15 2 files changed, 13 insertions(+), 2 deletions(-)
17 --- a/include/statfs_magic.h
18 +++ b/include/statfs_magic.h
20 #ifndef UTIL_LINUX_STATFS_MAGIC_H
21 #define UTIL_LINUX_STATFS_MAGIC_H
23 +#include <sys/statfs.h>
26 + * If possible then don't depend on internal libc __SWORD_TYPE type.
29 +typedef __typeof__( ((struct statfs *)0)->f_type ) ul_statfs_ftype_t;
31 +typedef __SWORD_TYPE ul_statfs_ftype_t;
35 * Unfortunately, Linux kernel hedeader file <linux/magic.h> is incomplete
36 * mess and kernel returns by statfs f_type many numbers that are nowhere
37 --- a/sys-utils/switch_root.c
38 +++ b/sys-utils/switch_root.c
39 @@ -181,8 +181,8 @@ static int switchroot(const char *newroo
42 if (fstatfs(cfd, &stfs) == 0 &&
43 - (stfs.f_type == (__SWORD_TYPE)STATFS_RAMFS_MAGIC ||
44 - stfs.f_type == (__SWORD_TYPE)STATFS_TMPFS_MAGIC))
45 + (stfs.f_type == (ul_statfs_ftype_t) STATFS_RAMFS_MAGIC ||
46 + stfs.f_type == (ul_statfs_ftype_t) STATFS_TMPFS_MAGIC))
49 warn(_("old root filesystem is not an initramfs"));