linux-old/include/linux/kdev_t.h
<<
>>
Prefs
   1#ifndef _LINUX_KDEV_T_H
   2#define _LINUX_KDEV_T_H
   3#if defined(__KERNEL__) || defined(_LVM_H_INCLUDE)
   4/*
   5As a preparation for the introduction of larger device numbers,
   6we introduce a type kdev_t to hold them. No information about
   7this type is known outside of this include file.
   8
   9Objects of type kdev_t designate a device. Outside of the kernel
  10the corresponding things are objects of type dev_t - usually an
  11integral type with the device major and minor in the high and low
  12bits, respectively. Conversion is done by
  13
  14extern kdev_t to_kdev_t(int);
  15
  16It is up to the various file systems to decide how objects of type
  17dev_t are stored on disk.
  18The only other point of contact between kernel and outside world
  19are the system calls stat and mknod, new versions of which will
  20eventually have to be used in libc.
  21
  22[Unfortunately, the floppy control ioctls fail to hide the internal
  23kernel structures, and the fd_device field of a struct floppy_drive_struct
  24is user-visible. So, it remains a dev_t for the moment, with some ugly
  25conversions in floppy.c.]
  26
  27Inside the kernel, we aim for a kdev_t type that is a pointer
  28to a structure with information about the device (like major,
  29minor, size, blocksize, sectorsize, name, read-only flag,
  30struct file_operations etc.).
  31
  32However, for the time being we let kdev_t be almost the same as dev_t:
  33
  34typedef struct { unsigned short major, minor; } kdev_t;
  35
  36Admissible operations on an object of type kdev_t:
  37- passing it along
  38- comparing it for equality with another such object
  39- storing it in ROOT_DEV, inode->i_dev, inode->i_rdev, sb->s_dev,
  40  bh->b_dev, req->rq_dev, de->dc_dev, tty->device
  41- using its bit pattern as argument in a hash function
  42- finding its major and minor
  43- complaining about it
  44
  45An object of type kdev_t is created only by the function MKDEV(),
  46with the single exception of the constant 0 (no device).
  47
  48Right now the other information mentioned above is usually found
  49in static arrays indexed by major or major,minor.
  50
  51An obstacle to immediately using
  52    typedef struct { ... (* lots of information *) } *kdev_t
  53is the case of mknod used to create a block device that the
  54kernel doesn't know about at present (but first learns about
  55when some module is inserted).
  56
  57aeb - 950811
  58*/
  59
  60/* Since MINOR(dev) is used as index in static arrays,
  61   the kernel is not quite ready yet for larger minors.
  62   However, everything runs fine with an arbitrary kdev_t type. */
  63
  64#define MINORBITS       8
  65#define MINORMASK       ((1U << MINORBITS) - 1)
  66
  67typedef unsigned short kdev_t;
  68
  69#define MAJOR(dev)      ((unsigned int) ((dev) >> MINORBITS))
  70#define MINOR(dev)      ((unsigned int) ((dev) & MINORMASK))
  71#define HASHDEV(dev)    ((unsigned int) (dev))
  72#define NODEV           0
  73#define MKDEV(ma,mi)    (((ma) << MINORBITS) | (mi))
  74#define B_FREE          0xffff          /* yuk */
  75
  76extern const char * kdevname(kdev_t);   /* note: returns pointer to static data! */
  77
  78/* 2.5.x compatibility */
  79#define mk_kdev(a,b)    MKDEV(a,b)
  80#define major(d)        MAJOR(d)
  81#define minor(d)        MINOR(d)
  82#define kdev_same(a,b)  ((a) == (b))
  83#define kdev_none(d)    (!(d))
  84#define kdev_val(d)     ((unsigned int)(d))
  85#define val_to_kdev(d)  ((kdev_t)(d))
  86
  87/*
  88As long as device numbers in the outside world have 16 bits only,
  89we use these conversions.
  90*/
  91
  92static inline unsigned int kdev_t_to_nr(kdev_t dev) {
  93        return (MAJOR(dev)<<8) | MINOR(dev);
  94}
  95
  96static inline kdev_t to_kdev_t(int dev)
  97{
  98        int major, minor;
  99#if 0
 100        major = (dev >> 16);
 101        if (!major) {
 102                major = (dev >> 8);
 103                minor = (dev & 0xff);
 104        } else
 105                minor = (dev & 0xffff);
 106#else
 107        major = (dev >> 8);
 108        minor = (dev & 0xff);
 109#endif
 110        return MKDEV(major, minor);
 111}
 112
 113#else /* __KERNEL__ || _LVM_H_INCLUDE */
 114
 115/*
 116Some programs want their definitions of MAJOR and MINOR and MKDEV
 117from the kernel sources. These must be the externally visible ones.
 118*/
 119#define MAJOR(dev)      ((dev)>>8)
 120#define MINOR(dev)      ((dev) & 0xff)
 121#define MKDEV(ma,mi)    ((ma)<<8 | (mi))
 122#endif /* __KERNEL__ || _LVM_H_INCLUDE */
 123#endif
 124
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.