~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/kdev_t.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 #ifndef _LINUX_KDEV_T_H
  3 #define _LINUX_KDEV_T_H
  4 
  5 #include <uapi/linux/kdev_t.h>
  6 
  7 #define MINORBITS       20
  8 #define MINORMASK       ((1U << MINORBITS) - 1)
  9 
 10 #define MAJOR(dev)      ((unsigned int) ((dev) >> MINORBITS))
 11 #define MINOR(dev)      ((unsigned int) ((dev) & MINORMASK))
 12 #define MKDEV(ma,mi)    (((ma) << MINORBITS) | (mi))
 13 
 14 #define print_dev_t(buffer, dev)                                        \
 15         sprintf((buffer), "%u:%u\n", MAJOR(dev), MINOR(dev))
 16 
 17 #define format_dev_t(buffer, dev)                                       \
 18         ({                                                              \
 19                 sprintf(buffer, "%u:%u", MAJOR(dev), MINOR(dev));       \
 20                 buffer;                                                 \
 21         })
 22 
 23 /* acceptable for old filesystems */
 24 static __always_inline bool old_valid_dev(dev_t dev)
 25 {
 26         return MAJOR(dev) < 256 && MINOR(dev) < 256;
 27 }
 28 
 29 static __always_inline u16 old_encode_dev(dev_t dev)
 30 {
 31         return (MAJOR(dev) << 8) | MINOR(dev);
 32 }
 33 
 34 static __always_inline dev_t old_decode_dev(u16 val)
 35 {
 36         return MKDEV((val >> 8) & 255, val & 255);
 37 }
 38 
 39 static __always_inline u32 new_encode_dev(dev_t dev)
 40 {
 41         unsigned major = MAJOR(dev);
 42         unsigned minor = MINOR(dev);
 43         return (minor & 0xff) | (major << 8) | ((minor & ~0xff) << 12);
 44 }
 45 
 46 static __always_inline dev_t new_decode_dev(u32 dev)
 47 {
 48         unsigned major = (dev & 0xfff00) >> 8;
 49         unsigned minor = (dev & 0xff) | ((dev >> 12) & 0xfff00);
 50         return MKDEV(major, minor);
 51 }
 52 
 53 static __always_inline u64 huge_encode_dev(dev_t dev)
 54 {
 55         return new_encode_dev(dev);
 56 }
 57 
 58 static __always_inline dev_t huge_decode_dev(u64 dev)
 59 {
 60         return new_decode_dev(dev);
 61 }
 62 
 63 static __always_inline int sysv_valid_dev(dev_t dev)
 64 {
 65         return MAJOR(dev) < (1<<14) && MINOR(dev) < (1<<18);
 66 }
 67 
 68 static __always_inline u32 sysv_encode_dev(dev_t dev)
 69 {
 70         return MINOR(dev) | (MAJOR(dev) << 18);
 71 }
 72 
 73 static __always_inline unsigned sysv_major(u32 dev)
 74 {
 75         return (dev >> 18) & 0x3fff;
 76 }
 77 
 78 static __always_inline unsigned sysv_minor(u32 dev)
 79 {
 80         return dev & 0x3ffff;
 81 }
 82 
 83 #endif
 84 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php