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

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

Version: ~ [ linux-5.2 ] ~ [ linux-5.1.16 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.57 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.132 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.184 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.184 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.69 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.39.4 ] ~ [ linux-2.6.38.8 ] ~ [ linux-2.6.37.6 ] ~ [ linux-2.6.36.4 ] ~ [ linux-2.6.35.14 ] ~ [ linux-2.6.34.15 ] ~ [ linux-2.6.33.20 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ 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 inline bool old_valid_dev(dev_t dev)
 25 {
 26         return MAJOR(dev) < 256 && MINOR(dev) < 256;
 27 }
 28 
 29 static inline u16 old_encode_dev(dev_t dev)
 30 {
 31         return (MAJOR(dev) << 8) | MINOR(dev);
 32 }
 33 
 34 static inline dev_t old_decode_dev(u16 val)
 35 {
 36         return MKDEV((val >> 8) & 255, val & 255);
 37 }
 38 
 39 static 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 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 inline u64 huge_encode_dev(dev_t dev)
 54 {
 55         return new_encode_dev(dev);
 56 }
 57 
 58 static inline dev_t huge_decode_dev(u64 dev)
 59 {
 60         return new_decode_dev(dev);
 61 }
 62 
 63 static inline int sysv_valid_dev(dev_t dev)
 64 {
 65         return MAJOR(dev) < (1<<14) && MINOR(dev) < (1<<18);
 66 }
 67 
 68 static inline u32 sysv_encode_dev(dev_t dev)
 69 {
 70         return MINOR(dev) | (MAJOR(dev) << 18);
 71 }
 72 
 73 static inline unsigned sysv_major(u32 dev)
 74 {
 75         return (dev >> 18) & 0x3fff;
 76 }
 77 
 78 static 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 | Wiki (Japanese) | Wiki (English) | 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.

osdn.jp