util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] switch_root: use typeof() instead of __SWORD_TYPE
@ 2014-10-29  9:09 Natanael Copa
  2014-10-29 19:37 ` Mike Frysinger
  0 siblings, 1 reply; 3+ messages in thread
From: Natanael Copa @ 2014-10-29  9:09 UTC (permalink / raw)
  To: util-linux; +Cc: Natanael Copa

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@alpinelinux.org>
---
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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-11-06 12:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-29  9:09 [PATCH] switch_root: use typeof() instead of __SWORD_TYPE Natanael Copa
2014-10-29 19:37 ` Mike Frysinger
2014-11-06 12:01   ` Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).