1
#ifndef _LINUX_KDEV_T_H
2
#define _LINUX_KDEV_T_H
3
#if defined(__KERNEL__) || defined(_LVM_H_INCLUDE)
5
As a preparation for the introduction of larger device numbers,
6
we introduce a type kdev_t to hold them. No information about
7
this type is known outside of this include file.
9
Objects of type kdev_t designate a device. Outside of the kernel
10
the corresponding things are objects of type dev_t - usually an
11
integral type with the device major and minor in the high and low
12
bits, respectively. Conversion is done by
14
extern kdev_t to_kdev_t(int);
16
It is up to the various file systems to decide how objects of type
17
dev_t are stored on disk.
18
The only other point of contact between kernel and outside world
19
are the system calls stat and mknod, new versions of which will
20
eventually have to be used in libc.
22
[Unfortunately, the floppy control ioctls fail to hide the internal
23
kernel structures, and the fd_device field of a struct floppy_drive_struct
24
is user-visible. So, it remains a dev_t for the moment, with some ugly
25
conversions in floppy.c.]
27
Inside the kernel, we aim for a kdev_t type that is a pointer
28
to a structure with information about the device (like major,
29
minor, size, blocksize, sectorsize, name, read-only flag,
30
struct file_operations etc.).
32
However, for the time being we let kdev_t be almost the same as dev_t:
34
typedef struct { unsigned short major, minor; } kdev_t;
36
Admissible operations on an object of type kdev_t:
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
45
An object of type kdev_t is created only by the function MKDEV(),
46
with the single exception of the constant 0 (no device).
48
Right now the other information mentioned above is usually found
49
in static arrays indexed by major or major,minor.
51
An obstacle to immediately using
52
typedef struct { ... (* lots of information *) } *kdev_t
53
is the case of mknod used to create a block device that the
54
kernel doesn't know about at present (but first learns about
55
when some module is inserted).
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. */
65
#define MINORMASK ((1U << MINORBITS) - 1)
67
typedef unsigned short kdev_t;
69
#define MAJOR(dev) ((unsigned int) ((dev) >> MINORBITS))
70
#define MINOR(dev) ((unsigned int) ((dev) & MINORMASK))
71
#define HASHDEV(dev) ((unsigned int) (dev))
73
#define MKDEV(ma,mi) (((ma) << MINORBITS) | (mi))
74
#define B_FREE 0xffff /* yuk */
76
extern const char * kdevname(kdev_t); /* note: returns pointer to static data! */
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))
88
As long as device numbers in the outside world have 16 bits only,
89
we use these conversions.
92
static inline unsigned int kdev_t_to_nr(kdev_t dev) {
93
return (MAJOR(dev)<<8) | MINOR(dev);
96
static inline kdev_t to_kdev_t(int dev)
103
minor = (dev & 0xff);
105
minor = (dev & 0xffff);
108
minor = (dev & 0xff);
110
return MKDEV(major, minor);
113
#else /* __KERNEL__ || _LVM_H_INCLUDE */
116
Some programs want their definitions of MAJOR and MINOR and MKDEV
117
from the kernel sources. These must be the externally visible ones.
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 */