aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/kdev_t.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /include/linux/kdev_t.h
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'include/linux/kdev_t.h')
-rw-r--r--include/linux/kdev_t.h101
1 files changed, 101 insertions, 0 deletions
diff --git a/include/linux/kdev_t.h b/include/linux/kdev_t.h
new file mode 100644
index 000000000000..bceea527dd37
--- /dev/null
+++ b/include/linux/kdev_t.h
@@ -0,0 +1,101 @@
1#ifndef _LINUX_KDEV_T_H
2#define _LINUX_KDEV_T_H
3#ifdef __KERNEL__
4#define MINORBITS 20
5#define MINORMASK ((1U << MINORBITS) - 1)
6
7#define MAJOR(dev) ((unsigned int) ((dev) >> MINORBITS))
8#define MINOR(dev) ((unsigned int) ((dev) & MINORMASK))
9#define MKDEV(ma,mi) (((ma) << MINORBITS) | (mi))
10
11#define print_dev_t(buffer, dev) \
12 sprintf((buffer), "%u:%u\n", MAJOR(dev), MINOR(dev))
13
14#define format_dev_t(buffer, dev) \
15 ({ \
16 sprintf(buffer, "%u:%u", MAJOR(dev), MINOR(dev)); \
17 buffer; \
18 })
19
20/* acceptable for old filesystems */
21static inline int old_valid_dev(dev_t dev)
22{
23 return MAJOR(dev) < 256 && MINOR(dev) < 256;
24}
25
26static inline u16 old_encode_dev(dev_t dev)
27{
28 return (MAJOR(dev) << 8) | MINOR(dev);
29}
30
31static inline dev_t old_decode_dev(u16 val)
32{
33 return MKDEV((val >> 8) & 255, val & 255);
34}
35
36static inline int new_valid_dev(dev_t dev)
37{
38 return 1;
39}
40
41static inline u32 new_encode_dev(dev_t dev)
42{
43 unsigned major = MAJOR(dev);
44 unsigned minor = MINOR(dev);
45 return (minor & 0xff) | (major << 8) | ((minor & ~0xff) << 12);
46}
47
48static inline dev_t new_decode_dev(u32 dev)
49{
50 unsigned major = (dev & 0xfff00) >> 8;
51 unsigned minor = (dev & 0xff) | ((dev >> 12) & 0xfff00);
52 return MKDEV(major, minor);
53}
54
55static inline int huge_valid_dev(dev_t dev)
56{
57 return 1;
58}
59
60static inline u64 huge_encode_dev(dev_t dev)
61{
62 return new_encode_dev(dev);
63}
64
65static inline dev_t huge_decode_dev(u64 dev)
66{
67 return new_decode_dev(dev);
68}
69
70static inline int sysv_valid_dev(dev_t dev)
71{
72 return MAJOR(dev) < (1<<14) && MINOR(dev) < (1<<18);
73}
74
75static inline u32 sysv_encode_dev(dev_t dev)
76{
77 return MINOR(dev) | (MAJOR(dev) << 18);
78}
79
80static inline unsigned sysv_major(u32 dev)
81{
82 return (dev >> 18) & 0x3fff;
83}
84
85static inline unsigned sysv_minor(u32 dev)
86{
87 return dev & 0x3ffff;
88}
89
90
91#else /* __KERNEL__ */
92
93/*
94Some programs want their definitions of MAJOR and MINOR and MKDEV
95from the kernel sources. These must be the externally visible ones.
96*/
97#define MAJOR(dev) ((dev)>>8)
98#define MINOR(dev) ((dev) & 0xff)
99#define MKDEV(ma,mi) ((ma)<<8 | (mi))
100#endif /* __KERNEL__ */
101#endif