linux/include/linux/kdev_t.h
<<
>>
Prefs
   1#ifndef _LINUX_KDEV_T_H
   2#define _LINUX_KDEV_T_H
   3#ifdef __KERNEL__
   4#define MINORBITS       20
   5#define MINORMASK       ((1U << MINORBITS) - 1)
   6
   7#define MAJOR(dev)      ((unsigned int) ((dev) >> MINORBITS))
   8#define MINOR(dev)      ((unsigned int) ((dev) & MINORMASK))
   9#define MKDEV(ma,mi)    (((ma) << MINORBITS) | (mi))
  10
  11#define print_dev_t(buffer, dev)                                        \
  12        sprintf((buffer), "%u:%u\n", MAJOR(dev), MINOR(dev))
  13
  14#define format_dev_t(buffer, dev)                                       \
  15        ({                                                              \
  16                sprintf(buffer, "%u:%u", MAJOR(dev), MINOR(dev));       \
  17                buffer;                                                 \
  18        })
  19
  20/* acceptable for old filesystems */
  21static inline int old_valid_dev(dev_t dev)
  22{
  23        return MAJOR(dev) < 256 && MINOR(dev) < 256;
  24}
  25
  26static inline u16 old_encode_dev(dev_t dev)
  27{
  28        return (MAJOR(dev) << 8) | MINOR(dev);
  29}
  30
  31static inline dev_t old_decode_dev(u16 val)
  32{
  33        return MKDEV((val >> 8) & 255, val & 255);
  34}
  35
  36static inline int new_valid_dev(dev_t dev)
  37{
  38        return 1;
  39}
  40
  41static inline u32 new_encode_dev(dev_t dev)
  42{
  43        unsigned major = MAJOR(dev);
  44        unsigned minor = MINOR(dev);
  45        return (minor & 0xff) | (major << 8) | ((minor & ~0xff) << 12);
  46}
  47
  48static inline dev_t new_decode_dev(u32 dev)
  49{
  50        unsigned major = (dev & 0xfff00) >> 8;
  51        unsigned minor = (dev & 0xff) | ((dev >> 12) & 0xfff00);
  52        return MKDEV(major, minor);
  53}
  54
  55static inline int huge_valid_dev(dev_t dev)
  56{
  57        return 1;
  58}
  59
  60static inline u64 huge_encode_dev(dev_t dev)
  61{
  62        return new_encode_dev(dev);
  63}
  64
  65static inline dev_t huge_decode_dev(u64 dev)
  66{
  67        return new_decode_dev(dev);
  68}
  69
  70static inline int sysv_valid_dev(dev_t dev)
  71{
  72        return MAJOR(dev) < (1<<14) && MINOR(dev) < (1<<18);
  73}
  74
  75static inline u32 sysv_encode_dev(dev_t dev)
  76{
  77        return MINOR(dev) | (MAJOR(dev) << 18);
  78}
  79
  80static inline unsigned sysv_major(u32 dev)
  81{
  82        return (dev >> 18) & 0x3fff;
  83}
  84
  85static inline unsigned sysv_minor(u32 dev)
  86{
  87        return dev & 0x3ffff;
  88}
  89
  90#else /* __KERNEL__ */
  91
  92/*
  93Some programs want their definitions of MAJOR and MINOR and MKDEV
  94from the kernel sources. These must be the externally visible ones.
  95*/
  96#define MAJOR(dev)      ((dev)>>8)
  97#define MINOR(dev)      ((dev) & 0xff)
  98#define MKDEV(ma,mi)    ((ma)<<8 | (mi))
  99#endif /* __KERNEL__ */
 100#endif
 101
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.