Thread (4 messages) 4 messages, 3 authors, 2014-03-19

Re: [PATCH 1/1] Work around architectures having statfs.f_type defined as long

From: NeilBrown <hidden>
Date: 2014-03-19 22:24:56

On Wed, 19 Mar 2014 14:26:02 +0100 Jes.Sorensen@redhat.com wrote:
quoted hunk ↗ jump to hunk
From: Jes Sorensen <redacted>

Having RAMFS_MAGIC defined as 0x858458f6 causing problems when trying
to compare it directly against statfs.f_type being cast from long to
unsigned long.

This hack is extremly ugly, but it should at least do the right thing
for every situation.

Thanks to Arnd Bergmann for suggesting the fix.

Signed-off-by: Jes Sorensen <redacted>
---
 util.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/util.c b/util.c
index e32d97a..afb2bb1 100644
--- a/util.c
+++ b/util.c
@@ -1946,9 +1946,13 @@ int in_initrd(void)
 {
 	/* This is based on similar function in systemd. */
 	struct statfs s;
+	/* statfs.f_type is signed long on s390x and MIPS, causing all
+	   sorts of sign extension problems with RAMFS_MAGIC being
+	   defined as 0x858458f6 */
 	return  statfs("/", &s) >= 0 &&
 		((unsigned long)s.f_type == TMPFS_MAGIC ||
-		 (unsigned long)s.f_type == RAMFS_MAGIC);
+		 ((unsigned long)s.f_type & 0xFFFFFFFFUL) ==
+		 ((unsigned long)RAMFS_MAGIC & 0xFFFFFFFFUL));
 }
 
 void reopen_mddev(int mdfd)

Applied, thanks.

NeilBrown

Attachments

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help