[PATCH] switch_root: use typeof() instead of __SWORD_TYPE

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <ncopa@xxxxxxxxxxxxxxx>
---
This is similar to what they did in systemd:
http://cgit.freedesktop.org/systemd/systemd/commit/?id=bdd29249a882e599e5e365536372d08dee398cd4

 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

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux