Skip to contentSkip to conversation

Change userspace MKDEV, MAJOR, MINOR-macros from 8+8 bit, to 12+20 bit layout

PATCH In review Stephan Müller 2 participants 3 messages Sep 14, 2014 ABI/API

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Change userspace MKDEV, MAJOR, MINOR-macros from 8+8 bit, to 12+20 bit layout

Delete old userspace-only versions (8+8 bit). Instead expose the kernel-space definitions (12+20 bit).

---

Browsing some code I found that user-space and kernel-space macros for (un-)packing major/minor device numbers differ. The user-space ones using still the old 16 bit scheme. There was no explaining comment around and most libraries have their own macros anyway so it should not be a problematic UAPI change. So IMHO we could win some coherence in abandon this discrepancy. Please correct me if I am wrong.

 include/linux/kdev_t.h      |  7 -------
 include/uapi/linux/kdev_t.h | 16 +++++++---------
 2 files changed, 7 insertions(+), 16 deletions(-)
include/linux/kdev_t.h +0 -7
index c838abe..0b09c12 100644
@@ -3,13 +3,6 @@
 
 #include <uapi/linux/kdev_t.h>
 
-#define MINORBITS	20
-#define MINORMASK	((1U << MINORBITS) - 1)
-
-#define MAJOR(dev)	((unsigned int) ((dev) >> MINORBITS))
-#define MINOR(dev)	((unsigned int) ((dev) & MINORMASK))
-#define MKDEV(ma,mi)	(((ma) << MINORBITS) | (mi))
-
 #define print_dev_t(buffer, dev)					\
 	sprintf((buffer), "%u:%u\n", MAJOR(dev), MINOR(dev))
 
include/uapi/linux/kdev_t.h +7 -9
index 0d881fa..6a8356b 100644
@@ -1,13 +1,11 @@
 #ifndef _UAPI_LINUX_KDEV_T_H
 #define _UAPI_LINUX_KDEV_T_H
-#ifndef __KERNEL__
 
-/*
-Some programs want their definitions of MAJOR and MINOR and MKDEV
-from the kernel sources. These must be the externally visible ones.
-*/
-#define MAJOR(dev)	((dev)>>8)
-#define MINOR(dev)	((dev) & 0xff)
-#define MKDEV(ma,mi)	((ma)<<8 | (mi))
-#endif /* __KERNEL__ */
+#define MINORBITS	20
+#define MINORMASK	((1U << MINORBITS) - 1)
+
+#define MAJOR(dev)	((unsigned int) ((dev) >> MINORBITS))
+#define MINOR(dev)	((unsigned int) ((dev) & MINORMASK))
+#define MKDEV(ma, mi)	(((ma) << MINORBITS) | (mi))
+
 #endif /* _UAPI_LINUX_KDEV_T_H */
Signature · 1 line
1.9.3
#1 lore raw
Quoted 8 lines · Stephan Müller

Delete old userspace-only versions (8+8 bit). Instead expose the kernel-space definitions (12+20 bit).

---

Browsing some code I found that user-space and kernel-space macros for (un-)packing major/minor device numbers differ. The user-space ones using still the old 16 bit scheme. There was no explaining comment around and most libraries have their own macros anyway so it should not be a problematic UAPI change. So IMHO we could win some coherence in abandon this discrepancy. Please correct me if I am wrong.

You are wrong, we can't change this api, things will break :(

sorry,

greg k-h

#2 lore raw

Am 14.09.2014 19:46, schrieb Greg KH:

Quoted 7 lines · Stephan Müller
Quoted 6 lines

Delete old userspace-only versions (8+8 bit). Instead expose the kernel-space definitions (12+20 bit).

---

Quoted 8 lines
Quoted 2 lines

Browsing some code I found that user-space and kernel-space macros for (un-)packing major/minor device numbers differ. The user-space ones using still the old 16 bit scheme. There was no explaining comment around and most libraries have their own macros anyway so it should not be a problematic UAPI change. So IMHO we could win some coherence in abandon this discrepancy. Please correct me if I am wrong.

You are wrong, we can't change this api, things will break :(

sorry,

greg k-h

I kind of expected this. The #ifndef __KERNEL__ was suspicious..

thanks