[CRIU] [PATCH] util: Update kdev_to_odev to respect BITS_PER_LONG

Cyrill Gorcunov gorcunov at openvz.org
Fri Nov 1 06:07:02 PDT 2013


From: Igor Sukhih <igor at parallels.com>

Depending on BITS_PER_LONG userspace representation of dev_t
may vary, so we need to choose proper encoding.

Signed-off-by: Igor Sukhih <igor at parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---

Igor, are you fine with such changelog?

 include/util.h | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/include/util.h b/include/util.h
index 56f74af1ed7e..273d39f7d9d0 100644
--- a/include/util.h
+++ b/include/util.h
@@ -220,9 +220,17 @@ static inline u32 kdev_minor(u32 kdev)
 static inline dev_t kdev_to_odev(u32 kdev)
 {
 	/*
-	 * New kernels envcode devices in a new form
+	 * New kernels envcode devices in a new form.
+	 * See kernel's fs/stat.c for details, there
+	 * choose_32_64 helpers which are the key.
 	 */
-	return (kdev_major(kdev) << 8) | kdev_minor(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
 }
 
 int copy_file(int fd_in, int fd_out, size_t bytes);
-- 
1.8.3.1



More information about the CRIU mailing list