Skip to contentSkip to conversation

kdev_t.h old major/minor numbers

PATCH Corey Richardson 2 participants 2 messages Aug 10, 2011

lore
Share & tools
lore
#0 lore raw

While reading through some of the kernel stuff I noticed that the macros at the end of include/linux/kdev_t.h were out-of-sync with the macros at the top. I'm not certain when/if they would ever be defined and not the other ones (I'm very new to the kernel), but I would assume that they shouldn't be using the old 255-number system.

Was this just an oversight or is there something else going on?

Patch:

include/linux/kdev_t.h. renamed from include/linux/kdev_t.h +6 -3
@@ -93,8 +93,11 @@
 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))
+#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 /* __KERNEL__ */
 #endif
Signature · 3 lines
Corey Richardson
  "Those who deny freedom to others, deserve it not for themselves"
     -- Abraham Lincoln
#1 lore raw
Quoted 8 lines · Corey Richardson

While reading through some of the kernel stuff I noticed that the macros at the end of include/linux/kdev_t.h were out-of-sync with the macros at the top. I'm not certain when/if they would ever be defined and not the other ones (I'm very new to the kernel), but I would assume that they shouldn't be using the old 255-number system.

Was this just an oversight or is there something else going on?

No, it is done this way on purpose, please read the comment right before the code you just changed.

greg k-h