source: GPL/include/linux/kdev_t.h@ 18

Last change on this file since 18 was 18, checked in by vladest, 20 years ago

initial import

File size: 3.4 KB
Line 
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/*
7As a preparation for the introduction of larger device numbers,
8we introduce a type kdev_t to hold them. No information about
9this type is known outside of this include file.
10
11Objects of type kdev_t designate a device. Outside of the kernel
12the corresponding things are objects of type dev_t - usually an
13integral type with the device major and minor in the high and low
14bits, respectively. Conversion is done by
15
16extern kdev_t to_kdev_t(int);
17
18It is up to the various file systems to decide how objects of type
19dev_t are stored on disk.
20The only other point of contact between kernel and outside world
21are the system calls stat and mknod, new versions of which will
22eventually have to be used in libc.
23
24[Unfortunately, the floppy control ioctls fail to hide the internal
25kernel structures, and the fd_device field of a struct floppy_drive_struct
26is user-visible. So, it remains a dev_t for the moment, with some ugly
27conversions in floppy.c.]
28
29Inside the kernel, we aim for a kdev_t type that is a pointer
30to a structure with information about the device (like major,
31minor, size, blocksize, sectorsize, name, read-only flag,
32struct file_operations etc.).
33
34However, for the time being we let kdev_t be almost the same as dev_t:
35
36typedef struct { unsigned short major, minor; } kdev_t;
37
38Admissible 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
47An object of type kdev_t is created only by the function MKDEV(),
48with the single exception of the constant 0 (no device).
49
50Right now the other information mentioned above is usually found
51in static arrays indexed by major or major,minor.
52
53An obstacle to immediately using
54 typedef struct { ... (* lots of information *) } *kdev_t
55is the case of mknod used to create a block device that the
56kernel doesn't know about at present (but first learns about
57when some module is inserted).
58
59aeb - 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
69typedef 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
78extern char * kdevname(kdev_t); /* note: returns pointer to static data! */
79
80/*
81As long as device numbers in the outside world have 16 bits only,
82we 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/*
91Some programs want their definitions of MAJOR and MINOR and MKDEV
92from 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
Note: See TracBrowser for help on using the repository browser.