Harald Hoyer 6844c2
From bdd29249a882e599e5e365536372d08dee398cd4 Mon Sep 17 00:00:00 2001
Harald Hoyer 6844c2
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer 6844c2
Date: Fri, 19 Apr 2013 13:44:56 +0200
Harald Hoyer 6844c2
Subject: [PATCH] Reintroduce f_type comparison macro
Harald Hoyer 6844c2
Harald Hoyer 6844c2
This reverts commit 4826f0b7b5c0aefa08b8cc7ef64d69027f84da2c.
Harald Hoyer 6844c2
Harald Hoyer 6844c2
Because statfs.t_type can be int on some architecures, we have to cast
Harald Hoyer 6844c2
the const magic to the type, otherwise the compiler warns about
Harald Hoyer 6844c2
signed/unsigned comparison, because the magic can be 32 bit unsigned.
Harald Hoyer 6844c2
Harald Hoyer 6844c2
statfs(2) man page is also wrong on some systems, because
Harald Hoyer 6844c2
f_type is not __SWORD_TYPE on some architecures.
Harald Hoyer 6844c2
Harald Hoyer 6844c2
The following program:
Harald Hoyer 6844c2
Harald Hoyer 6844c2
int main(int argc, char**argv)
Harald Hoyer 6844c2
{
Harald Hoyer 6844c2
        struct statfs s;
Harald Hoyer 6844c2
        statfs(argv[1], &s);
Harald Hoyer 6844c2
Harald Hoyer 6844c2
	printf("sizeof(f_type) = %d\n", sizeof(s.f_type));
Harald Hoyer 6844c2
	printf("sizeof(__SWORD_TYPE) = %d\n", sizeof(__SWORD_TYPE));
Harald Hoyer 6844c2
	printf("sizeof(long) = %d\n", sizeof(long));
Harald Hoyer 6844c2
	printf("sizeof(int) = %d\n", sizeof(int));
Harald Hoyer 6844c2
	if (sizeof(s.f_type) == sizeof(int)) {
Harald Hoyer 6844c2
		printf("f_type = 0x%x\n", s.f_type);
Harald Hoyer 6844c2
	} else {
Harald Hoyer 6844c2
                printf("f_type = 0x%lx\n", s.f_type);
Harald Hoyer 6844c2
	}
Harald Hoyer 6844c2
        return 0;
Harald Hoyer 6844c2
}
Harald Hoyer 6844c2
Harald Hoyer 6844c2
executed on s390x gives for a btrfs:
Harald Hoyer 6844c2
Harald Hoyer 6844c2
sizeof(f_type) = 4
Harald Hoyer 6844c2
sizeof(__SWORD_TYPE) = 8
Harald Hoyer 6844c2
sizeof(long) = 8
Harald Hoyer 6844c2
sizeof(int) = 4
Harald Hoyer 6844c2
f_type = 0x9123683e
Harald Hoyer 6844c2
---
Harald Hoyer 6844c2
 src/journal/sd-journal.c          | 10 +++++-----
Harald Hoyer 6844c2
 src/readahead/readahead-collect.c |  2 +-
Harald Hoyer 6844c2
 src/shared/macro.h                |  7 +++++++
Harald Hoyer 6844c2
 src/shared/util.c                 |  5 +++--
Harald Hoyer 6844c2
 4 files changed, 16 insertions(+), 8 deletions(-)
Harald Hoyer 6844c2
Harald Hoyer 6844c2
diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
Harald Hoyer 6844c2
index e021d98..15239b5 100644
Harald Hoyer 6844c2
--- a/src/journal/sd-journal.c
Harald Hoyer 6844c2
+++ b/src/journal/sd-journal.c
Harald Hoyer 6844c2
@@ -1251,11 +1251,11 @@ static void check_network(sd_journal *j, int fd) {
Harald Hoyer 6844c2
                 return;
Harald Hoyer 6844c2
 
Harald Hoyer 6844c2
         j->on_network =
Harald Hoyer 6844c2
-                sfs.f_type == (__SWORD_TYPE) CIFS_MAGIC_NUMBER ||
Harald Hoyer 6844c2
-                sfs.f_type == (__SWORD_TYPE) CODA_SUPER_MAGIC ||
Harald Hoyer 6844c2
-                sfs.f_type == (__SWORD_TYPE) NCP_SUPER_MAGIC ||
Harald Hoyer 6844c2
-                sfs.f_type == (__SWORD_TYPE) NFS_SUPER_MAGIC ||
Harald Hoyer 6844c2
-                sfs.f_type == (__SWORD_TYPE) SMB_SUPER_MAGIC;
Harald Hoyer 6844c2
+                F_TYPE_CMP(sfs.f_type, CIFS_MAGIC_NUMBER) ||
Harald Hoyer 6844c2
+                F_TYPE_CMP(sfs.f_type, CODA_SUPER_MAGIC) ||
Harald Hoyer 6844c2
+                F_TYPE_CMP(sfs.f_type, NCP_SUPER_MAGIC) ||
Harald Hoyer 6844c2
+                F_TYPE_CMP(sfs.f_type, NFS_SUPER_MAGIC) ||
Harald Hoyer 6844c2
+                F_TYPE_CMP(sfs.f_type, SMB_SUPER_MAGIC);
Harald Hoyer 6844c2
 }
Harald Hoyer 6844c2
 
Harald Hoyer 6844c2
 static int add_file(sd_journal *j, const char *prefix, const char *filename) {
Harald Hoyer 6844c2
diff --git a/src/readahead/readahead-collect.c b/src/readahead/readahead-collect.c
Harald Hoyer 6844c2
index 02ecbe5..75ec5b7 100644
Harald Hoyer 6844c2
--- a/src/readahead/readahead-collect.c
Harald Hoyer 6844c2
+++ b/src/readahead/readahead-collect.c
Harald Hoyer 6844c2
@@ -505,7 +505,7 @@ done:
Harald Hoyer 6844c2
         on_ssd = fs_on_ssd(root) > 0;
Harald Hoyer 6844c2
         log_debug("On SSD: %s", yes_no(on_ssd));
Harald Hoyer 6844c2
 
Harald Hoyer 6844c2
-        on_btrfs = statfs(root, &sfs) >= 0 && sfs.f_type == (__SWORD_TYPE) BTRFS_SUPER_MAGIC;
Harald Hoyer 6844c2
+        on_btrfs = statfs(root, &sfs) >= 0 && F_TYPE_CMP(sfs.f_type, BTRFS_SUPER_MAGIC);
Harald Hoyer 6844c2
         log_debug("On btrfs: %s", yes_no(on_btrfs));
Harald Hoyer 6844c2
 
Harald Hoyer 6844c2
         if (asprintf(&pack_fn_new, "%s/.readahead.new", root) < 0) {
Harald Hoyer 6844c2
diff --git a/src/shared/macro.h b/src/shared/macro.h
Harald Hoyer 6844c2
index 9bf81dc..ac61b49 100644
Harald Hoyer 6844c2
--- a/src/shared/macro.h
Harald Hoyer 6844c2
+++ b/src/shared/macro.h
Harald Hoyer 6844c2
@@ -264,6 +264,13 @@ do {                                                                    \
Harald Hoyer 6844c2
         }                                                               \
Harald Hoyer 6844c2
 } while(false)
Harald Hoyer 6844c2
 
Harald Hoyer 6844c2
+ /* Because statfs.t_type can be int on some architecures, we have to cast
Harald Hoyer 6844c2
+  * the const magic to the type, otherwise the compiler warns about
Harald Hoyer 6844c2
+  * signed/unsigned comparison, because the magic can be 32 bit unsigned.
Harald Hoyer 6844c2
+ */
Harald Hoyer 6844c2
+#define F_TYPE_CMP(a, b) (a == (typeof(a)) b)
Harald Hoyer 6844c2
+
Harald Hoyer 6844c2
+
Harald Hoyer 6844c2
 /* Returns the number of chars needed to format variables of the
Harald Hoyer 6844c2
  * specified type as a decimal string. Adds in extra space for a
Harald Hoyer 6844c2
  * negative '-' prefix. */
Harald Hoyer 6844c2
diff --git a/src/shared/util.c b/src/shared/util.c
Harald Hoyer 6844c2
index 5d03272..1fc6c5a 100644
Harald Hoyer 6844c2
--- a/src/shared/util.c
Harald Hoyer 6844c2
+++ b/src/shared/util.c
Harald Hoyer 6844c2
@@ -2779,8 +2779,9 @@ int rm_rf_children_dangerous(int fd, bool only_dirs, bool honour_sticky, struct
Harald Hoyer 6844c2
 
Harald Hoyer 6844c2
 static int is_temporary_fs(struct statfs *s) {
Harald Hoyer 6844c2
         assert(s);
Harald Hoyer 6844c2
-        return s->f_type == (__SWORD_TYPE) TMPFS_MAGIC ||
Harald Hoyer 6844c2
-                s->f_type == (__SWORD_TYPE) RAMFS_MAGIC;
Harald Hoyer 6844c2
+        return
Harald Hoyer 6844c2
+                F_TYPE_CMP(s->f_type, TMPFS_MAGIC) ||
Harald Hoyer 6844c2
+                F_TYPE_CMP(s->f_type, RAMFS_MAGIC);
Harald Hoyer 6844c2
 }
Harald Hoyer 6844c2
 
Harald Hoyer 6844c2
 int rm_rf_children(int fd, bool only_dirs, bool honour_sticky, struct stat *root_dev) {
Harald Hoyer 6844c2
-- 
Harald Hoyer 6844c2
1.8.2
Harald Hoyer 6844c2