chiark / gitweb /
Reintroduce f_type comparison macro
authorHarald Hoyer <harald@redhat.com>
Fri, 19 Apr 2013 11:44:56 +0000 (13:44 +0200)
committerHarald Hoyer <harald@redhat.com>
Fri, 19 Apr 2013 11:59:07 +0000 (13:59 +0200)
This reverts commit 4826f0b7b5c0aefa08b8cc7ef64d69027f84da2c.

Because statfs.t_type can be int on some architecures, we have to cast
the const magic to the type, otherwise the compiler warns about
signed/unsigned comparison, because the magic can be 32 bit unsigned.

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

src/journal/sd-journal.c
src/readahead/readahead-collect.c
src/shared/macro.h
src/shared/util.c

index e021d98155e50cacf41bbc6640072e26c557f93c..15239b5688d8bde6743d80d13f3726b50ff6d77b 100644 (file)
@@ -1251,11 +1251,11 @@ static void check_network(sd_journal *j, int fd) {
                 return;
 
         j->on_network =
-                sfs.f_type == (__SWORD_TYPE) CIFS_MAGIC_NUMBER ||
-                sfs.f_type == (__SWORD_TYPE) CODA_SUPER_MAGIC ||
-                sfs.f_type == (__SWORD_TYPE) NCP_SUPER_MAGIC ||
-                sfs.f_type == (__SWORD_TYPE) NFS_SUPER_MAGIC ||
-                sfs.f_type == (__SWORD_TYPE) SMB_SUPER_MAGIC;
+                F_TYPE_CMP(sfs.f_type, CIFS_MAGIC_NUMBER) ||
+                F_TYPE_CMP(sfs.f_type, CODA_SUPER_MAGIC) ||
+                F_TYPE_CMP(sfs.f_type, NCP_SUPER_MAGIC) ||
+                F_TYPE_CMP(sfs.f_type, NFS_SUPER_MAGIC) ||
+                F_TYPE_CMP(sfs.f_type, SMB_SUPER_MAGIC);
 }
 
 static int add_file(sd_journal *j, const char *prefix, const char *filename) {
index 02ecbe56c9be8a03db9d53e38a8574d2aae5d215..75ec5b70c72ab0435dee6430962a8605747c18ad 100644 (file)
@@ -505,7 +505,7 @@ done:
         on_ssd = fs_on_ssd(root) > 0;
         log_debug("On SSD: %s", yes_no(on_ssd));
 
-        on_btrfs = statfs(root, &sfs) >= 0 && sfs.f_type == (__SWORD_TYPE) BTRFS_SUPER_MAGIC;
+        on_btrfs = statfs(root, &sfs) >= 0 && F_TYPE_CMP(sfs.f_type, BTRFS_SUPER_MAGIC);
         log_debug("On btrfs: %s", yes_no(on_btrfs));
 
         if (asprintf(&pack_fn_new, "%s/.readahead.new", root) < 0) {
index 9bf81dc3cc541229bebe333d8d3ee31074ffe68b..ac61b495883dc754f124010428e2b5e36302db78 100644 (file)
@@ -264,6 +264,13 @@ do {                                                                    \
         }                                                               \
 } while(false)
 
+ /* Because statfs.t_type can be int on some architecures, we have to cast
+  * the const magic to the type, otherwise the compiler warns about
+  * signed/unsigned comparison, because the magic can be 32 bit unsigned.
+ */
+#define F_TYPE_CMP(a, b) (a == (typeof(a)) b)
+
+
 /* Returns the number of chars needed to format variables of the
  * specified type as a decimal string. Adds in extra space for a
  * negative '-' prefix. */
index 5d03272619a0831dea4acb2c4a302dc3bdca69a3..1fc6c5aa1adf63476e1c7406b527b51f2896bd1f 100644 (file)
@@ -2779,8 +2779,9 @@ int rm_rf_children_dangerous(int fd, bool only_dirs, bool honour_sticky, struct
 
 static int is_temporary_fs(struct statfs *s) {
         assert(s);
-        return s->f_type == (__SWORD_TYPE) TMPFS_MAGIC ||
-                s->f_type == (__SWORD_TYPE) RAMFS_MAGIC;
+        return
+                F_TYPE_CMP(s->f_type, TMPFS_MAGIC) ||
+                F_TYPE_CMP(s->f_type, RAMFS_MAGIC);
 }
 
 int rm_rf_children(int fd, bool only_dirs, bool honour_sticky, struct stat *root_dev) {