forked from ish-app/ish
-
Notifications
You must be signed in to change notification settings - Fork 12
/
dev.h
44 lines (34 loc) · 1.01 KB
/
dev.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef DEV_H
#define DEV_H
#include <sys/types.h>
#include <sys/sysmacros.h>
#include "sys/fs.h"
// a dev_t is encoded like this in hex, where M is major and m is minor:
// mmmMMMmm
// (legacy I guess)
typedef uint32_t dev_t_;
static inline dev_t_ dev_make(int major, int minor) {
return ((minor & 0xfff00) << 12) | (major << 8) | (minor & 0xff);
}
static inline int dev_major(dev_t_ dev) {
return (dev & 0xfff00) >> 8;
}
static inline int dev_minor(dev_t_ dev) {
return ((dev & 0xfff00000) >> 12) | (dev & 0xff);
}
static inline dev_t dev_real_from_fake(dev_t_ dev) {
return makedev(dev_major(dev), dev_minor(dev));
}
static inline dev_t_ dev_fake_from_real(dev_t dev) {
return dev_make(major(dev), minor(dev));
}
#define DEV_BLOCK 0
#define DEV_CHAR 1
struct dev_ops {
int (*open)(int major, int minor, int type, struct fd *fd);
struct fd_ops fd;
};
extern struct dev_ops *block_devs[];
extern struct dev_ops *char_devs[];
int dev_open(int major, int minor, int type, struct fd *fd);
#endif