1 |
199 |
simons |
#ifndef _LINUX_KDEV_T_H
|
2 |
|
|
#define _LINUX_KDEV_T_H
|
3 |
|
|
#ifdef __KERNEL__
|
4 |
|
|
/*
|
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.
|
8 |
|
|
|
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
|
13 |
|
|
|
14 |
|
|
extern kdev_t to_kdev_t(int);
|
15 |
|
|
|
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.
|
21 |
|
|
|
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.]
|
26 |
|
|
|
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.).
|
31 |
|
|
|
32 |
|
|
However, for the time being we let kdev_t be almost the same as dev_t:
|
33 |
|
|
|
34 |
|
|
typedef struct { unsigned short major, minor; } kdev_t;
|
35 |
|
|
|
36 |
|
|
Admissible 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 |
|
|
|
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).
|
47 |
|
|
|
48 |
|
|
Right now the other information mentioned above is usually found
|
49 |
|
|
in static arrays indexed by major or major,minor.
|
50 |
|
|
|
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).
|
56 |
|
|
|
57 |
|
|
aeb - 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 ((1<<MINORBITS) - 1)
|
66 |
|
|
|
67 |
|
|
/* SIMON I won't fuck with this one */
|
68 |
|
|
/*typedef unsigned short kdev_t;*/
|
69 |
|
|
typedef int kdev_t;
|
70 |
|
|
|
71 |
|
|
#define MAJOR(dev) ((dev) >> MINORBITS)
|
72 |
|
|
#define MINOR(dev) ((dev) & MINORMASK)
|
73 |
|
|
#define HASHDEV(dev) (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 |
|
|
static inline unsigned int kdev_t_to_nr(kdev_t dev) {
|
86 |
|
|
return (MAJOR(dev)<<8) | MINOR(dev);
|
87 |
|
|
}
|
88 |
|
|
|
89 |
|
|
static inline kdev_t to_kdev_t(int dev)
|
90 |
|
|
{
|
91 |
|
|
int major, minor;
|
92 |
|
|
#if 0
|
93 |
|
|
major = (dev >> 16);
|
94 |
|
|
if (!major) {
|
95 |
|
|
major = (dev >> 8);
|
96 |
|
|
minor = (dev & 0xff);
|
97 |
|
|
} else
|
98 |
|
|
minor = (dev & 0xffff);
|
99 |
|
|
#else
|
100 |
|
|
major = (dev >> 8);
|
101 |
|
|
minor = (dev & 0xff);
|
102 |
|
|
#endif
|
103 |
|
|
return MKDEV(major, minor);
|
104 |
|
|
}
|
105 |
|
|
|
106 |
|
|
#else /* __KERNEL__ */
|
107 |
|
|
|
108 |
|
|
/*
|
109 |
|
|
Some programs want their definitions of MAJOR and MINOR and MKDEV
|
110 |
|
|
from the kernel sources. These must be the externally visible ones.
|
111 |
|
|
*/
|
112 |
|
|
#define MAJOR(dev) ((dev)>>8)
|
113 |
|
|
#define MINOR(dev) ((dev) & 0xff)
|
114 |
|
|
#define MKDEV(ma,mi) ((ma)<<8 | (mi))
|
115 |
|
|
#endif /* __KERNEL__ */
|
116 |
|
|
#endif
|