From bdd29249a882e599e5e365536372d08dee398cd4 Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Fri, 19 Apr 2013 13:44:56 +0200 Subject: Reintroduce f_type comparison macro 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/shared/macro.h | 7 +++++++ src/shared/util.c | 5 +++-- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'src/shared') diff --git a/src/shared/macro.h b/src/shared/macro.h index 9bf81dc3cc..ac61b49588 100644 --- a/src/shared/macro.h +++ b/src/shared/macro.h @@ -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. */ diff --git a/src/shared/util.c b/src/shared/util.c index 5d03272619..1fc6c5aa1a 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -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) { -- cgit v1.2.3-54-g00ecf