x86: fix platform_export_bootpart() for Xen virtual disks
[openwrt/openwrt.git] / package / utils / util-linux / patches / 0001-switch_root-improve-statfs-f_type-portability.patch
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
5
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).
9
10 Reported-by: Natanael Copa <ncopa@alpinelinux.org>
11 Signed-off-by: Karel Zak <kzak@redhat.com>
12 ---
13 include/statfs_magic.h | 11 +++++++++++
14 sys-utils/switch_root.c | 4 ++--
15 2 files changed, 13 insertions(+), 2 deletions(-)
16
17 --- a/include/statfs_magic.h
18 +++ b/include/statfs_magic.h
19 @@ -1,6 +1,17 @@
20 #ifndef UTIL_LINUX_STATFS_MAGIC_H
21 #define UTIL_LINUX_STATFS_MAGIC_H
22
23 +#include <sys/statfs.h>
24 +
25 +/*
26 + * If possible then don't depend on internal libc __SWORD_TYPE type.
27 + */
28 +#ifdef __GNUC__
29 +typedef __typeof__( ((struct statfs *)0)->f_type ) ul_statfs_ftype_t;
30 +#else
31 +typedef __SWORD_TYPE ul_statfs_ftype_t;
32 +#endif
33 +
34 /*
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
40 if (pid <= 0) {
41 struct statfs stfs;
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))
47 recursiveRemove(cfd);
48 else
49 warn(_("old root filesystem is not an initramfs"));