1 #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 typedef unsigned short kdev_t; 68 69 #define MAJOR(dev) ((dev) >> MINORBITS) 70 #define MINOR(dev) ((dev) & MINORMASK) 71 #define HASHDEV(dev) (dev) 72 #define NODEV 0 73 #define MKDEV(ma,mi) (((ma) << MINORBITS) | (mi)) 74 #define B_FREE 0xffff /* yuk */ 75 76 extern char * kdevname(kdev_t); /* note: returns pointer to static data! */ 77 78 /* 79 As long as device numbers in the outside world have 16 bits only, 80 we use these conversions. 81 */ 82 83 static inline unsigned int kdev_t_to_nr(kdev_t dev) { /* */ 84 return (MAJOR(dev)<<8) | MINOR(dev); 85 } 86 87 static inline kdev_t to_kdev_t(int dev) /* */ 88 { 89 int major, minor; 90 #if 0 91 major = (dev >> 16); 92 if (!major) { 93 major = (dev >> 8); 94 minor = (dev & 0xff); 95 } else 96 minor = (dev & 0xffff); 97 #else 98 major = (dev >> 8); 99 minor = (dev & 0xff); 100 #endif 101 return MKDEV(major, minor); 102 } 103 104 #else /* __KERNEL__ */ 105 106 /* 107 Some programs want their definitions of MAJOR and MINOR and MKDEV 108 from the kernel sources. These must be the externally visible ones. 109 */ 110 #define MAJOR(dev) ((dev)>>8) 111 #define MINOR(dev) ((dev) & 0xff) 112 #define MKDEV(ma,mi) ((ma)<<8 | (mi)) 113 #endif /* __KERNEL__ */ 114 #endif