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