[CRIU] [PATCH] util: use glibc macros to generate device numbers in the dev_t format

Andrey Vagin avagin at openvz.org
Mon May 5 03:26:50 PDT 2014


Our version of macroses are worng.

Our macros:

Glibc function:
return (__dev & 0xff) | ((unsigned int) (__dev >> 12) & ~0xff);

Reported-by: Amey Deshpande <ameyd at google.com>
Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 arch/aarch64/include/asm/types.h | 3 ---
 include/util.h                   | 7 ++-----
 mount.c                          | 2 +-
 3 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/arch/aarch64/include/asm/types.h b/arch/aarch64/include/asm/types.h
index 73d0fec..8dd336e 100644
--- a/arch/aarch64/include/asm/types.h
+++ b/arch/aarch64/include/asm/types.h
@@ -13,9 +13,6 @@
 #define SIGMAX			64
 #define SIGMAX_OLD		31
 
-#define MAJOR(dev)		((dev)>>8)
-#define MINOR(dev)		((dev) & 0xff)
-
 typedef void rt_signalfn_t(int, siginfo_t *, void *);
 typedef rt_signalfn_t *rt_sighandler_t;
 
diff --git a/include/util.h b/include/util.h
index c4b8e69..d20bfcc 100644
--- a/include/util.h
+++ b/include/util.h
@@ -211,11 +211,8 @@ static inline dev_t kdev_to_odev(u32 kdev)
 	 */
 	unsigned major = kdev_major(kdev);
 	unsigned minor = kdev_minor(kdev);
-#if BITS_PER_LONG == 32
-	return (major << 8) | minor;
-#else
-	return (minor & 0xff) | (major << 8) | ((minor & ~0xff) << 12);
-#endif
+
+	return makedev(major, minor);
 }
 
 extern int copy_file(int fd_in, int fd_out, size_t bytes);
diff --git a/mount.c b/mount.c
index b152d44..1d960ae 100644
--- a/mount.c
+++ b/mount.c
@@ -158,7 +158,7 @@ dev_t phys_stat_resolve_dev(struct mount_info *tree,
 	 * obtained from mountinfo (ie subvolume0).
 	 */
 	return strcmp(m->fstype->name, "btrfs") ?
-		MKKDEV(MAJOR(st_dev), MINOR(st_dev)) : m->s_dev;
+		MKKDEV(major(st_dev), minor(st_dev)) : m->s_dev;
 }
 
 bool phys_stat_dev_match(struct mount_info *tree, dev_t st_dev,
-- 
1.8.5.3



More information about the CRIU mailing list