From d8aa7c8b2b1a5233ce8f3dde19490899bb50e4a2 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Wed, 29 Oct 2014 08:42:09 +0000 Subject: [PATCH] switch_root: use typeof() instead of __SWORD_TYPE for statfs compare Identifiers prefixed with __ are normally for internal use and should normally not be used outside libc. This fixes the following compile error with musl libc: sys-utils/switch_root.c:184:25: error: '__SWORD_TYPE' undeclared (first use in this function) (stfs.f_type == (__SWORD_TYPE)STATFS_RAMFS_MAGIC || ^ Also, statfs(2) man page is also wrong on some systems, because f_type is not __SWORD_TYPE on some architecures. The following program: int main(int argc, char**argv) { struct statfs s; statfs(argv[1], &s); printf("sizeof(f_type) = %d\n", sizeof(s.f_type)); printf("sizeof(__SWORD_TYPE) = %d\n", sizeof(__SWORD_TYPE)); printf("sizeof(long) = %d\n", sizeof(long)); printf("sizeof(int) = %d\n", sizeof(int)); if (sizeof(s.f_type) == sizeof(int)) { printf("f_type = 0x%x\n", s.f_type); } else { printf("f_type = 0x%lx\n", s.f_type); } return 0; } executed on s390x gives for a btrfs: sizeof(f_type) = 4 sizeof(__SWORD_TYPE) = 8 sizeof(long) = 8 sizeof(int) = 4 f_type = 0x9123683e Signed-off-by: Natanael Copa --- sys-utils/switch_root.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys-utils/switch_root.c b/sys-utils/switch_root.c index 6822a5d..3fbecdd 100644 --- a/sys-utils/switch_root.c +++ b/sys-utils/switch_root.c @@ -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 == (typeof(stfs.f_type))STATFS_RAMFS_MAGIC || + stfs.f_type == (typeof(stfs.f_type))STATFS_TMPFS_MAGIC)) recursiveRemove(cfd); else warn(_("old root filesystem is not an initramfs")); -- 2.1.2